diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2011-05-16 15:33:44 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2011-05-16 15:33:44 +0200 |
commit | e3e20f2b60972bcaa845d1000fe615498dd2cef5 (patch) | |
tree | f6ee65eeaa3d5a9b0f9694c10b7ad538870d0da0 /src/gui/gui-window.c | |
parent | bd1db541f782c8ec9a5545bb9ba7f49870c43574 (diff) | |
download | weechat-e3e20f2b60972bcaa845d1000fe615498dd2cef5.zip |
core: add horizontal scrolling for buffers with free content (command /window scroll_horiz) (task #11112)
Diffstat (limited to 'src/gui/gui-window.c')
-rw-r--r-- | src/gui/gui-window.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c index f8deb1af6..6a7d94245 100644 --- a/src/gui/gui-window.c +++ b/src/gui/gui-window.c @@ -180,6 +180,7 @@ gui_window_scroll_init (struct t_gui_window_scroll *window_scroll, window_scroll->start_line = NULL; window_scroll->start_line_pos = 0; window_scroll->scrolling = 0; + window_scroll->start_col = 0; window_scroll->lines_after = 0; window_scroll->reset_allowed = 0; window_scroll->prev_scroll = NULL; @@ -241,6 +242,7 @@ gui_window_scroll_remove_not_scrolled (struct t_gui_window *window) && (ptr_scroll->start_line == NULL) && (ptr_scroll->start_line_pos == 0) && (ptr_scroll->scrolling == 0) + && (ptr_scroll->start_col == 0) && (ptr_scroll->lines_after == 0) && (ptr_scroll->reset_allowed == 0)) { @@ -959,6 +961,75 @@ gui_window_scroll (struct t_gui_window *window, char *scroll) } /* + * gui_window_scroll_horiz: horizontal scroll window + */ + +void +gui_window_scroll_horiz (struct t_gui_window *window, char *scroll) +{ + int direction, percentage, start_col; + char saved_char, *pos, *error; + long number; + + if (window->buffer->lines->first_line) + { + direction = 1; + number = 0; + percentage = 0; + + /* search direction */ + if (scroll[0] == '-') + { + direction = -1; + scroll++; + } + else if (scroll[0] == '+') + { + direction = +1; + scroll++; + } + + /* search number and percentage */ + pos = scroll; + while (pos && pos[0] && isdigit (pos[0])) + { + pos++; + } + if (pos && (pos > scroll)) + { + percentage = (pos[0] == '%') ? 1 : 0; + saved_char = pos[0]; + pos[0] = '\0'; + error = NULL; + number = strtol (scroll, &error, 10); + if (!error || error[0]) + number = 0; + pos[0] = saved_char; + } + + /* for percentage, compute number of columns */ + if (percentage) + { + number = (window->win_chat_width * number) / 100; + } + + /* number must be different from 0 */ + if (number == 0) + return; + + /* do the horizontal scroll! */ + start_col = window->scroll->start_col + (number * direction); + if (start_col < 0) + start_col = 0; + if (start_col != window->scroll->start_col) + { + window->scroll->start_col = start_col; + gui_buffer_ask_chat_refresh (window->buffer, 2); + } + } +} + +/* * gui_window_scroll_previous_highlight: scroll to previous highlight */ @@ -1298,6 +1369,7 @@ gui_window_print_log () log_printf (" start_line. . . . . : 0x%lx", ptr_scroll->start_line); log_printf (" start_line_pos. . . : %d", ptr_scroll->start_line_pos); log_printf (" scrolling . . . . . : %d", ptr_scroll->scrolling); + log_printf (" start_col . . . . . : %d", ptr_scroll->start_col); log_printf (" lines_after . . . . : %d", ptr_scroll->lines_after); log_printf (" reset_allowed . . . : %d", ptr_scroll->reset_allowed); log_printf (" prev_scroll . . . . : 0x%lx", ptr_scroll->prev_scroll); |