summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--src/gui/curses/gui-curses-chat.c58
-rw-r--r--src/gui/curses/gui-curses-window.c85
-rw-r--r--src/gui/gtk/gui-gtk-window.c64
-rw-r--r--src/gui/gui-bar-item.c4
-rw-r--r--src/gui/gui-buffer.c9
-rw-r--r--src/gui/gui-input.c16
-rw-r--r--src/gui/gui-line.c15
-rw-r--r--src/gui/gui-window.c304
-rw-r--r--src/gui/gui-window.h29
10 files changed, 402 insertions, 185 deletions
diff --git a/ChangeLog b/ChangeLog
index 224d302da..bc1e331a1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,12 +1,13 @@
WeeChat ChangeLog
=================
Sébastien Helleu <flashcode@flashtux.org>
-v0.3.5-dev, 2011-02-24
+v0.3.5-dev, 2011-03-01
Version 0.3.5 (under dev!)
--------------------------
+* core: remember scroll position for all buffers in windows (bug #25555)
* core: fix crash when using column filling in bars with some empty items
(bug #32565)
* core: allow relative size for command /window resize
diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c
index bca6ffb83..13508be85 100644
--- a/src/gui/curses/gui-curses-chat.c
+++ b/src/gui/curses/gui-curses-chat.c
@@ -1013,7 +1013,8 @@ gui_chat_draw (struct t_gui_buffer *buffer, int erase)
struct t_gui_window *ptr_win;
struct t_gui_line *ptr_line;
char format_empty[32];
- int i, line_pos, count, old_scroll, old_scroll_lines_after, y_start, y_end;
+ int i, line_pos, count, old_scrolling, old_lines_after;
+ int y_start, y_end;
if (!gui_ok)
return;
@@ -1045,10 +1046,10 @@ gui_chat_draw (struct t_gui_buffer *buffer, int erase)
{
case GUI_BUFFER_TYPE_FORMATTED:
/* display at position of scrolling */
- if (ptr_win->start_line)
+ if (ptr_win->scroll->start_line)
{
- ptr_line = ptr_win->start_line;
- line_pos = ptr_win->start_line_pos;
+ ptr_line = ptr_win->scroll->start_line;
+ line_pos = ptr_win->scroll->start_line_pos;
}
else
{
@@ -1070,10 +1071,10 @@ gui_chat_draw (struct t_gui_buffer *buffer, int erase)
0, 1) -
line_pos, 0);
ptr_line = gui_line_get_next_displayed (ptr_line);
- ptr_win->first_line_displayed = 0;
+ ptr_win->scroll->first_line_displayed = 0;
}
else
- ptr_win->first_line_displayed =
+ ptr_win->scroll->first_line_displayed =
(ptr_line == gui_line_get_first_displayed (ptr_win->buffer));
/* display lines */
@@ -1083,51 +1084,52 @@ gui_chat_draw (struct t_gui_buffer *buffer, int erase)
ptr_line = gui_line_get_next_displayed (ptr_line);
}
- old_scroll = ptr_win->scroll;
- old_scroll_lines_after = ptr_win->scroll_lines_after;
+ old_scrolling = ptr_win->scroll->scrolling;
+ old_lines_after = ptr_win->scroll->lines_after;
- ptr_win->scroll = (ptr_win->win_chat_cursor_y > ptr_win->win_chat_height - 1);
+ ptr_win->scroll->scrolling = (ptr_win->win_chat_cursor_y > ptr_win->win_chat_height - 1);
/* check if last line of buffer is entirely displayed and scrolling */
/* if so, disable scroll indicator */
- if (!ptr_line && ptr_win->scroll)
+ if (!ptr_line && ptr_win->scroll->scrolling)
{
if ((count == gui_chat_display_line (ptr_win, gui_line_get_last_displayed (ptr_win->buffer), 0, 1))
|| (count == ptr_win->win_chat_height))
- ptr_win->scroll = 0;
+ ptr_win->scroll->scrolling = 0;
}
- if (!ptr_win->scroll
- && (ptr_win->start_line == gui_line_get_first_displayed (ptr_win->buffer)))
+ if (!ptr_win->scroll->scrolling
+ && (ptr_win->scroll->start_line == gui_line_get_first_displayed (ptr_win->buffer)))
{
- ptr_win->start_line = NULL;
- ptr_win->start_line_pos = 0;
+ ptr_win->scroll->start_line = NULL;
+ ptr_win->scroll->start_line_pos = 0;
}
- ptr_win->scroll_lines_after = 0;
- if (ptr_win->scroll && ptr_line)
+ ptr_win->scroll->lines_after = 0;
+ if (ptr_win->scroll->scrolling && ptr_line)
{
/* count number of lines after last line displayed */
while (ptr_line)
{
ptr_line = gui_line_get_next_displayed (ptr_line);
if (ptr_line)
- ptr_win->scroll_lines_after++;
+ ptr_win->scroll->lines_after++;
}
- ptr_win->scroll_lines_after++;
+ ptr_win->scroll->lines_after++;
}
- if ((ptr_win->scroll != old_scroll)
- || (ptr_win->scroll_lines_after != old_scroll_lines_after))
+ if ((ptr_win->scroll->scrolling != old_scrolling)
+ || (ptr_win->scroll->lines_after != old_lines_after))
{
hook_signal_send ("window_scrolled",
WEECHAT_HOOK_SIGNAL_POINTER, ptr_win);
}
- if (!ptr_win->scroll && ptr_win->scroll_reset_allowed)
+ if (!ptr_win->scroll->scrolling
+ && ptr_win->scroll->reset_allowed)
{
- ptr_win->start_line = NULL;
- ptr_win->start_line_pos = 0;
+ ptr_win->scroll->start_line = NULL;
+ ptr_win->scroll->start_line_pos = 0;
gui_hotlist_remove_buffer (ptr_win->buffer);
}
@@ -1138,20 +1140,20 @@ gui_chat_draw (struct t_gui_buffer *buffer, int erase)
ptr_win->win_chat_cursor_y = ptr_win->win_chat_height - 1;
}
- ptr_win->scroll_reset_allowed = 0;
+ ptr_win->scroll->reset_allowed = 0;
break;
case GUI_BUFFER_TYPE_FREE:
/* display at position of scrolling */
- ptr_line = (ptr_win->start_line) ?
- ptr_win->start_line : buffer->lines->first_line;
+ ptr_line = (ptr_win->scroll->start_line) ?
+ ptr_win->scroll->start_line : buffer->lines->first_line;
if (ptr_line)
{
if (!ptr_line->data->displayed)
ptr_line = gui_line_get_next_displayed (ptr_line);
if (ptr_line)
{
- y_start = (ptr_win->start_line) ? ptr_line->data->y : 0;
+ y_start = (ptr_win->scroll->start_line) ? ptr_line->data->y : 0;
y_end = y_start + ptr_win->win_chat_height - 1;
while (ptr_line && (ptr_line->data->y <= y_end))
{
diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c
index 7d7cdf41a..d250bf1db 100644
--- a/src/gui/curses/gui-curses-window.c
+++ b/src/gui/curses/gui-curses-window.c
@@ -1015,8 +1015,7 @@ gui_window_switch_to_buffer (struct t_gui_window *window,
if (window->buffer->number != buffer->number)
{
- window->start_line = NULL;
- window->start_line_pos = 0;
+ gui_window_scroll_switch (window, buffer);
if (!gui_buffers_visited_frozen)
{
gui_buffer_visited_add (window->buffer);
@@ -1074,8 +1073,8 @@ gui_window_switch_to_buffer (struct t_gui_window *window,
if (window->buffer->type == GUI_BUFFER_TYPE_FREE)
{
- window->scroll = 0;
- window->scroll_lines_after = 0;
+ window->scroll->scrolling = 0;
+ window->scroll->lines_after = 0;
}
gui_buffer_set_active_buffer (buffer);
@@ -1153,19 +1152,19 @@ gui_window_page_up (struct t_gui_window *window)
switch (window->buffer->type)
{
case GUI_BUFFER_TYPE_FORMATTED:
- if (!window->first_line_displayed)
+ if (!window->scroll->first_line_displayed)
{
- gui_chat_calculate_line_diff (window, &window->start_line,
- &window->start_line_pos,
- (window->start_line) ?
+ gui_chat_calculate_line_diff (window, &window->scroll->start_line,
+ &window->scroll->start_line_pos,
+ (window->scroll->start_line) ?
(-1) * (num_lines) :
(-1) * (num_lines + window->win_chat_height - 1));
- window->scroll_reset_allowed = 1;
+ window->scroll->reset_allowed = 1;
gui_buffer_ask_chat_refresh (window->buffer, 2);
}
break;
case GUI_BUFFER_TYPE_FREE:
- if (window->start_line)
+ if (window->scroll->start_line)
{
snprintf (scroll, sizeof (scroll), "-%d",
num_lines + 1);
@@ -1203,24 +1202,24 @@ gui_window_page_down (struct t_gui_window *window)
switch (window->buffer->type)
{
case GUI_BUFFER_TYPE_FORMATTED:
- if (window->start_line)
+ if (window->scroll->start_line)
{
- gui_chat_calculate_line_diff (window, &window->start_line,
- &window->start_line_pos,
+ gui_chat_calculate_line_diff (window, &window->scroll->start_line,
+ &window->scroll->start_line_pos,
num_lines);
/* check if we can display all */
- ptr_line = window->start_line;
- line_pos = window->start_line_pos;
+ ptr_line = window->scroll->start_line;
+ line_pos = window->scroll->start_line_pos;
gui_chat_calculate_line_diff (window, &ptr_line,
&line_pos,
num_lines);
if (!ptr_line)
{
- window->start_line = NULL;
- window->start_line_pos = 0;
+ window->scroll->start_line = NULL;
+ window->scroll->start_line_pos = 0;
}
- window->scroll_reset_allowed = 1;
+ window->scroll->reset_allowed = 1;
gui_buffer_ask_chat_refresh (window->buffer, 2);
}
break;
@@ -1251,20 +1250,20 @@ gui_window_scroll_up (struct t_gui_window *window)
switch (window->buffer->type)
{
case GUI_BUFFER_TYPE_FORMATTED:
- if (!window->first_line_displayed)
+ if (!window->scroll->first_line_displayed)
{
- gui_chat_calculate_line_diff (window, &window->start_line,
- &window->start_line_pos,
- (window->start_line) ?
+ gui_chat_calculate_line_diff (window, &window->scroll->start_line,
+ &window->scroll->start_line_pos,
+ (window->scroll->start_line) ?
(-1) * CONFIG_INTEGER(config_look_scroll_amount) :
(-1) * ( (window->win_chat_height - 1) +
CONFIG_INTEGER(config_look_scroll_amount)));
- window->scroll_reset_allowed = 1;
+ window->scroll->reset_allowed = 1;
gui_buffer_ask_chat_refresh (window->buffer, 2);
}
break;
case GUI_BUFFER_TYPE_FREE:
- if (window->start_line)
+ if (window->scroll->start_line)
{
snprintf (scroll, sizeof (scroll), "-%d",
CONFIG_INTEGER(config_look_scroll_amount));
@@ -1295,25 +1294,25 @@ gui_window_scroll_down (struct t_gui_window *window)
switch (window->buffer->type)
{
case GUI_BUFFER_TYPE_FORMATTED:
- if (window->start_line)
+ if (window->scroll->start_line)
{
- gui_chat_calculate_line_diff (window, &window->start_line,
- &window->start_line_pos,
+ gui_chat_calculate_line_diff (window, &window->scroll->start_line,
+ &window->scroll->start_line_pos,
CONFIG_INTEGER(config_look_scroll_amount));
/* check if we can display all */
- ptr_line = window->start_line;
- line_pos = window->start_line_pos;
+ ptr_line = window->scroll->start_line;
+ line_pos = window->scroll->start_line_pos;
gui_chat_calculate_line_diff (window, &ptr_line,
&line_pos,
window->win_chat_height - 1);
if (!ptr_line)
{
- window->start_line = NULL;
- window->start_line_pos = 0;
+ window->scroll->start_line = NULL;
+ window->scroll->start_line_pos = 0;
}
- window->scroll_reset_allowed = 1;
+ window->scroll->reset_allowed = 1;
gui_buffer_ask_chat_refresh (window->buffer, 2);
}
break;
@@ -1342,18 +1341,18 @@ gui_window_scroll_top (struct t_gui_window *window)
switch (window->buffer->type)
{
case GUI_BUFFER_TYPE_FORMATTED:
- if (!window->first_line_displayed)
+ if (!window->scroll->first_line_displayed)
{
- window->start_line = gui_line_get_first_displayed (window->buffer);
- window->start_line_pos = 0;
- window->scroll_reset_allowed = 1;
+ window->scroll->start_line = gui_line_get_first_displayed (window->buffer);
+ window->scroll->start_line_pos = 0;
+ window->scroll->reset_allowed = 1;
gui_buffer_ask_chat_refresh (window->buffer, 2);
}
break;
case GUI_BUFFER_TYPE_FREE:
- if (window->start_line)
+ if (window->scroll->start_line)
{
- window->start_line = NULL;
+ window->scroll->start_line = NULL;
gui_buffer_ask_chat_refresh (window->buffer, 2);
hook_signal_send ("window_scrolled",
WEECHAT_HOOK_SIGNAL_POINTER, window);
@@ -1379,16 +1378,16 @@ gui_window_scroll_bottom (struct t_gui_window *window)
switch (window->buffer->type)
{
case GUI_BUFFER_TYPE_FORMATTED:
- if (window->start_line)
+ if (window->scroll->start_line)
{
- window->start_line = NULL;
- window->start_line_pos = 0;
- window->scroll_reset_allowed = 1;
+ window->scroll->start_line = NULL;
+ window->scroll->start_line_pos = 0;
+ window->scroll->reset_allowed = 1;
gui_buffer_ask_chat_refresh (window->buffer, 2);
}
break;
case GUI_BUFFER_TYPE_FREE:
- window->start_line = NULL;
+ window->scroll->start_line = NULL;
if (window->buffer->lines->lines_count > window->win_chat_height)
{
snprintf (scroll, sizeof (scroll), "-%d",
diff --git a/src/gui/gtk/gui-gtk-window.c b/src/gui/gtk/gui-gtk-window.c
index 9623e6475..1603f286e 100644
--- a/src/gui/gtk/gui-gtk-window.c
+++ b/src/gui/gtk/gui-gtk-window.c
@@ -202,8 +202,8 @@ gui_window_switch_to_buffer (struct t_gui_window *window,
if (window->buffer != buffer)
{
- window->start_line = NULL;
- window->start_line_pos = 0;
+ window->scroll->start_line = NULL;
+ window->scroll->start_line_pos = 0;
if (!gui_buffers_visited_frozen)
{
gui_buffer_visited_add (window->buffer);
@@ -244,8 +244,8 @@ gui_window_switch_to_buffer (struct t_gui_window *window,
gtk_text_buffer_apply_tag (GUI_WINDOW_OBJECTS(window)->textbuffer_chat, GUI_WINDOW_OBJECTS(window)->texttag_chat, &start, &end);
}
- window->start_line = NULL;
- window->start_line_pos = 0;
+ window->scroll->start_line = NULL;
+ window->scroll->start_line_pos = 0;
gui_buffer_add_value_num_displayed (buffer, 1);
@@ -262,11 +262,11 @@ gui_window_page_up (struct t_gui_window *window)
if (!gui_ok)
return;
- if (!window->first_line_displayed)
+ if (!window->scroll->first_line_displayed)
{
- gui_chat_calculate_line_diff (window, &window->start_line,
- &window->start_line_pos,
- (window->start_line) ?
+ gui_chat_calculate_line_diff (window, &window->scroll->start_line,
+ &window->scroll->start_line_pos,
+ (window->scroll->start_line) ?
(-1) * (window->win_chat_height - 1) :
(-1) * ((window->win_chat_height - 1) * 2));
gui_chat_draw (window->buffer, 0);
@@ -286,22 +286,22 @@ gui_window_page_down (struct t_gui_window *window)
if (!gui_ok)
return;
- if (window->start_line)
+ if (window->scroll->start_line)
{
- gui_chat_calculate_line_diff (window, &window->start_line,
- &window->start_line_pos,
+ gui_chat_calculate_line_diff (window, &window->scroll->start_line,
+ &window->scroll->start_line_pos,
window->win_chat_height - 1);
/* check if we can display all */
- ptr_line = window->start_line;
- line_pos = window->start_line_pos;
+ ptr_line = window->scroll->start_line;
+ line_pos = window->scroll->start_line_pos;
gui_chat_calculate_line_diff (window, &ptr_line,
&line_pos,
window->win_chat_height - 1);
if (!ptr_line)
{
- window->start_line = NULL;
- window->start_line_pos = 0;
+ window->scroll->start_line = NULL;
+ window->scroll->start_line_pos = 0;
}
gui_chat_draw (window->buffer, 0);
@@ -318,11 +318,11 @@ gui_window_scroll_up (struct t_gui_window *window)
if (!gui_ok)
return;
- if (!window->first_line_displayed)
+ if (!window->scroll->first_line_displayed)
{
- gui_chat_calculate_line_diff (window, &window->start_line,
- &window->start_line_pos,
- (window->start_line) ?
+ gui_chat_calculate_line_diff (window, &window->scroll->start_line,
+ &window->scroll->start_line_pos,
+ (window->scroll->start_line) ?
(-1) * CONFIG_INTEGER(config_look_scroll_amount) :
(-1) * ( (window->win_chat_height - 1) +
CONFIG_INTEGER(config_look_scroll_amount)));
@@ -343,23 +343,23 @@ gui_window_scroll_down (struct t_gui_window *window)
if (!gui_ok)
return;
- if (window->start_line)
+ if (window->scroll->start_line)
{
- gui_chat_calculate_line_diff (window, &window->start_line,
- &window->start_line_pos,
+ gui_chat_calculate_line_diff (window, &window->scroll->start_line,
+ &window->scroll->start_line_pos,
CONFIG_INTEGER(config_look_scroll_amount));
/* check if we can display all */
- ptr_line = window->start_line;
- line_pos = window->start_line_pos;
+ ptr_line = window->scroll->start_line;
+ line_pos = window->scroll->start_line_pos;
gui_chat_calculate_line_diff (window, &ptr_line,
&line_pos,
window->win_chat_height - 1);
if (!ptr_line)
{
- window->start_line = NULL;
- window->start_line_pos = 0;
+ window->scroll->start_line = NULL;
+ window->scroll->start_line_pos = 0;
}
gui_chat_draw (window->buffer, 0);
@@ -376,10 +376,10 @@ gui_window_scroll_top (struct t_gui_window *window)
if (!gui_ok)
return;
- if (!window->first_line_displayed)
+ if (!window->scroll->first_line_displayed)
{
- window->start_line = window->buffer->lines->first_line;
- window->start_line_pos = 0;
+ window->scroll->start_line = window->buffer->lines->first_line;
+ window->scroll->start_line_pos = 0;
gui_chat_draw (window->buffer, 0);
}
}
@@ -394,10 +394,10 @@ gui_window_scroll_bottom (struct t_gui_window *window)
if (!gui_ok)
return;
- if (window->start_line)
+ if (window->scroll->start_line)
{
- window->start_line = NULL;
- window->start_line_pos = 0;
+ window->scroll->start_line = NULL;
+ window->scroll->start_line_pos = 0;
gui_chat_draw (window->buffer, 0);
}
}
diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c
index 996a04c33..e3c589872 100644
--- a/src/gui/gui-bar-item.c
+++ b/src/gui/gui-bar-item.c
@@ -1013,12 +1013,12 @@ gui_bar_item_default_scroll (void *data, struct t_gui_bar_item *item,
if (!window)
window = gui_current_window;
- if (!window->scroll)
+ if (!window->scroll->scrolling)
return NULL;
snprintf (buf, sizeof (buf), _("%s-MORE(%d)-"),
gui_color_get_custom (gui_color_get_name (CONFIG_COLOR(config_color_status_more))),
- window->scroll_lines_after);
+ window->scroll->lines_after);
return strdup (buf);
}
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c
index 061cb1b8f..8e0f7cf08 100644
--- a/src/gui/gui-buffer.c
+++ b/src/gui/gui-buffer.c
@@ -1806,7 +1806,7 @@ gui_buffer_is_scrolled (struct t_gui_buffer *buffer)
{
buffer_found = 1;
/* buffer found and not scrolled, exit immediately */
- if (!ptr_win->scroll)
+ if (!ptr_win->scroll->scrolling)
return 0;
}
}
@@ -1839,9 +1839,9 @@ gui_buffer_clear (struct t_gui_buffer *buffer)
{
if (ptr_win->buffer == buffer)
{
- ptr_win->first_line_displayed = 1;
- ptr_win->start_line = NULL;
- ptr_win->start_line_pos = 0;
+ ptr_win->scroll->first_line_displayed = 1;
+ ptr_win->scroll->start_line = NULL;
+ ptr_win->scroll->start_line_pos = 0;
}
}
@@ -1950,6 +1950,7 @@ gui_buffer_close (struct t_gui_buffer *buffer)
1);
}
}
+ gui_window_scroll_remove_buffer (ptr_window, buffer);
}
}
}
diff --git a/src/gui/gui-input.c b/src/gui/gui-input.c
index c0d8a531e..8662a8218 100644
--- a/src/gui/gui-input.c
+++ b/src/gui/gui-input.c
@@ -1300,17 +1300,17 @@ gui_input_scroll_unread (struct t_gui_window *window)
window->buffer->lines->last_read_line != window->buffer->lines->last_line)))
{
if (window->buffer->lines->first_line_not_read)
- window->start_line = window->buffer->lines->first_line;
+ window->scroll->start_line = window->buffer->lines->first_line;
else
- window->start_line = window->buffer->lines->last_read_line->next_line;
- if (window->start_line)
+ window->scroll->start_line = window->buffer->lines->last_read_line->next_line;
+ if (window->scroll->start_line)
{
- if (!gui_line_is_displayed (window->start_line))
- window->start_line = gui_line_get_next_displayed (window->start_line);
+ if (!gui_line_is_displayed (window->scroll->start_line))
+ window->scroll->start_line = gui_line_get_next_displayed (window->scroll->start_line);
}
- window->start_line_pos = 0;
- window->first_line_displayed =
- (window->start_line == gui_line_get_first_displayed (window->buffer));
+ window->scroll->start_line_pos = 0;
+ window->scroll->first_line_displayed =
+ (window->scroll->start_line == gui_line_get_first_displayed (window->buffer));
gui_buffer_ask_chat_refresh (window->buffer, 2);
}
}
diff --git a/src/gui/gui-line.c b/src/gui/gui-line.c
index bc060dfb9..cbdd7ef0a 100644
--- a/src/gui/gui-line.c
+++ b/src/gui/gui-line.c
@@ -550,16 +550,21 @@ gui_line_remove_from_list (struct t_gui_buffer *buffer,
int free_data)
{
struct t_gui_window *ptr_win;
+ struct t_gui_window_scroll *ptr_scroll;
int update_prefix_max_length;
- /* reset scroll for any window starting with this line */
+ /* reset scroll for any window scroll starting with this line */
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
{
- if (ptr_win->start_line == line)
+ for (ptr_scroll = ptr_win->scroll; ptr_scroll;
+ ptr_scroll = ptr_scroll->next_scroll)
{
- ptr_win->start_line = ptr_win->start_line->next_line;
- ptr_win->start_line_pos = 0;
- gui_buffer_ask_chat_refresh (buffer, 2);
+ if (ptr_scroll->start_line == line)
+ {
+ ptr_scroll->start_line = ptr_scroll->start_line->next_line;
+ ptr_scroll->start_line_pos = 0;
+ gui_buffer_ask_chat_refresh (buffer, 2);
+ }
}
}
diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c
index 3c3d4d618..8048ecac5 100644
--- a/src/gui/gui-window.c
+++ b/src/gui/gui-window.c
@@ -144,6 +144,180 @@ gui_window_tree_free (struct t_gui_window_tree **tree)
}
/*
+ * gui_window_scroll_search: search a scroll with buffer pointer
+ */
+
+struct t_gui_window_scroll *
+gui_window_scroll_search (struct t_gui_window *window,
+ struct t_gui_buffer *buffer)
+{
+ struct t_gui_window_scroll *ptr_scroll;
+
+ if (!window || !buffer)
+ return NULL;
+
+ for (ptr_scroll = window->scroll; ptr_scroll;
+ ptr_scroll = ptr_scroll->next_scroll)
+ {
+ if (ptr_scroll->buffer == buffer)
+ return ptr_scroll;
+ }
+
+ /* scroll not found for buffer */
+ return NULL;
+}
+
+/*
+ * gui_window_scroll_init: initialize a window scroll structure
+ */
+
+void
+gui_window_scroll_init (struct t_gui_window_scroll *window_scroll,
+ struct t_gui_buffer *buffer)
+{
+ window_scroll->buffer = buffer;
+ window_scroll->first_line_displayed = 0;
+ window_scroll->start_line = NULL;
+ window_scroll->start_line_pos = 0;
+ window_scroll->scrolling = 0;
+ window_scroll->lines_after = 0;
+ window_scroll->reset_allowed = 0;
+ window_scroll->prev_scroll = NULL;
+ window_scroll->next_scroll = NULL;
+}
+
+/*
+ * gui_window_scroll_free: free a scroll structure in a window
+ */
+
+void
+gui_window_scroll_free (struct t_gui_window *window,
+ struct t_gui_window_scroll *scroll)
+{
+ if (scroll->prev_scroll)
+ (scroll->prev_scroll)->next_scroll = scroll->next_scroll;
+ if (scroll->next_scroll)
+ (scroll->next_scroll)->prev_scroll = scroll->prev_scroll;
+ if (window->scroll == scroll)
+ window->scroll = scroll->next_scroll;
+
+ free (scroll);
+}
+
+/*
+ * gui_window_scroll_free_all: free all scroll structures in a window
+ */
+
+void
+gui_window_scroll_free_all (struct t_gui_window *window)
+{
+ while (window->scroll)
+ {
+ gui_window_scroll_free (window, window->scroll);
+ }
+}
+
+/*
+ * gui_window_scroll_remove_not_scrolled: remove all scroll structures which
+ * are empty (not scrolled)
+ * Note: the first scroll in list
+ * (current buffer) is NOT removed by
+ * this function.
+ */
+
+void
+gui_window_scroll_remove_not_scrolled (struct t_gui_window *window)
+{
+ struct t_gui_window_scroll *ptr_scroll, *next_scroll;
+
+ if (window)
+ {
+ ptr_scroll = window->scroll->next_scroll;
+ while (ptr_scroll)
+ {
+ next_scroll = ptr_scroll->next_scroll;
+
+ if ((ptr_scroll->first_line_displayed == 0)
+ && (ptr_scroll->start_line == NULL)
+ && (ptr_scroll->start_line_pos == 0)
+ && (ptr_scroll->scrolling == 0)
+ && (ptr_scroll->lines_after == 0)
+ && (ptr_scroll->reset_allowed == 0))
+ {
+ gui_window_scroll_free (window, ptr_scroll);
+ }
+
+ ptr_scroll = next_scroll;
+ }
+ }
+}
+
+/*
+ * gui_window_scroll_switch: switch scroll to a buffer
+ */
+
+void
+gui_window_scroll_switch (struct t_gui_window *window,
+ struct t_gui_buffer *buffer)
+{
+ struct t_gui_window_scroll *ptr_scroll, *new_scroll;
+
+ if (window && buffer)
+ {
+ ptr_scroll = gui_window_scroll_search (window, buffer);
+
+ /* scroll is already selected (first in list)? */
+ if (ptr_scroll && (ptr_scroll == window->scroll))
+ return;
+
+ if (ptr_scroll)
+ {
+ /* scroll found, move it in first position */
+ if (ptr_scroll->prev_scroll)
+ (ptr_scroll->prev_scroll)->next_scroll = ptr_scroll->next_scroll;
+ if (ptr_scroll->next_scroll)
+ (ptr_scroll->next_scroll)->prev_scroll = ptr_scroll->prev_scroll;
+ (window->scroll)->prev_scroll = ptr_scroll;
+ ptr_scroll->prev_scroll = NULL;
+ ptr_scroll->next_scroll = window->scroll;
+ window->scroll = ptr_scroll;
+ }
+ else
+ {
+ /* scroll not found, create one and add it at first position */
+ new_scroll = malloc (sizeof (*new_scroll));
+ if (new_scroll)
+ {
+ gui_window_scroll_init (new_scroll, buffer);
+ new_scroll->next_scroll = window->scroll;
+ (window->scroll)->prev_scroll = new_scroll;
+ window->scroll = new_scroll;
+ }
+ }
+
+ gui_window_scroll_remove_not_scrolled (window);
+ }
+}
+
+/*
+ * gui_window_scroll_remove_buffer: remove buffer from scroll list in a window
+ */
+
+void
+gui_window_scroll_remove_buffer (struct t_gui_window *window,
+ struct t_gui_buffer *buffer)
+{
+ struct t_gui_window_scroll *ptr_scroll;
+
+ if (window && buffer)
+ {
+ ptr_scroll = gui_window_scroll_search (window, buffer);
+ if (ptr_scroll)
+ gui_window_scroll_free (window, ptr_scroll);
+ }
+}
+
+/*
* gui_window_new: create a new window
*/
@@ -211,9 +385,18 @@ gui_window_new (struct t_gui_window *parent_window, struct t_gui_buffer *buffer,
if ((new_window = (malloc (sizeof (*new_window)))))
{
+ /* create scroll structure */
+ new_window->scroll = malloc (sizeof (*new_window->scroll));
+ if (!new_window->scroll)
+ {
+ free (new_window);
+ return NULL;
+ }
+
/* create window objects */
if (!gui_window_objects_init (new_window))
{
+ free (new_window->scroll);
free (new_window);
return NULL;
}
@@ -247,13 +430,9 @@ gui_window_new (struct t_gui_window *parent_window, struct t_gui_buffer *buffer,
new_window->layout_buffer_name = NULL;
/* scroll */
- new_window->first_line_displayed = 0;
- new_window->start_line = NULL;
- new_window->start_line_pos = 0;
- new_window->scroll = 0;
- new_window->scroll_lines_after = 0;
- new_window->scroll_reset_allowed = 0;
+ gui_window_scroll_init (new_window->scroll, buffer);
+ /* tree */
new_window->ptr_tree = ptr_leaf;
ptr_leaf->window = new_window;
@@ -334,11 +513,11 @@ gui_window_get_integer (struct t_gui_window *window, const char *property)
if (string_strcasecmp (property, "win_chat_height") == 0)
return window->win_chat_height;
if (string_strcasecmp (property, "first_line_displayed") == 0)
- return window->first_line_displayed;
- if (string_strcasecmp (property, "scroll") == 0)
- return window->scroll;
- if (string_strcasecmp (property, "scroll_lines_after") == 0)
- return window->scroll_lines_after;
+ return window->scroll->first_line_displayed;
+ if (string_strcasecmp (property, "scrolling") == 0)
+ return window->scroll->scrolling;
+ if (string_strcasecmp (property, "lines_after") == 0)
+ return window->scroll->lines_after;
}
return 0;
@@ -445,6 +624,9 @@ gui_window_free (struct t_gui_window *window)
if (window->layout_buffer_name)
free (window->layout_buffer_name);
+ /* remove scroll list */
+ gui_window_scroll_free_all (window);
+
/* remove window from windows list */
if (window->prev_window)
(window->prev_window)->next_window = window->next_window;
@@ -582,8 +764,8 @@ gui_window_scroll (struct t_gui_window *window, char *scroll)
count_msg = 0;
if (direction < 0)
{
- ptr_line = (window->start_line) ?
- window->start_line : window->buffer->lines->last_line;
+ ptr_line = (window->scroll->start_line) ?
+ window->scroll->start_line : window->buffer->lines->last_line;
while (ptr_line && !gui_line_is_displayed (ptr_line))
{
ptr_line = ptr_line->prev_line;
@@ -591,8 +773,8 @@ gui_window_scroll (struct t_gui_window *window, char *scroll)
}
else
{
- ptr_line = (window->start_line) ?
- window->start_line : window->buffer->lines->first_line;
+ ptr_line = (window->scroll->start_line) ?
+ window->scroll->start_line : window->buffer->lines->first_line;
while (ptr_line && !gui_line_is_displayed (ptr_line))
{
ptr_line = ptr_line->next_line;
@@ -717,10 +899,10 @@ gui_window_scroll (struct t_gui_window *window, char *scroll)
}
if (stop)
{
- window->start_line = ptr_line;
- window->start_line_pos = 0;
- window->first_line_displayed =
- (window->start_line == gui_line_get_first_displayed (window->buffer));
+ window->scroll->start_line = ptr_line;
+ window->scroll->start_line_pos = 0;
+ window->scroll->first_line_displayed =
+ (window->scroll->start_line == gui_line_get_first_displayed (window->buffer));
gui_buffer_ask_chat_refresh (window->buffer, 2);
return;
}
@@ -750,16 +932,16 @@ gui_window_scroll_previous_highlight (struct t_gui_window *window)
{
if (window->buffer->lines->first_line)
{
- ptr_line = (window->start_line) ?
- window->start_line->prev_line : window->buffer->lines->last_line;
+ ptr_line = (window->scroll->start_line) ?
+ window->scroll->start_line->prev_line : window->buffer->lines->last_line;
while (ptr_line)
{
if (ptr_line->data->highlight)
{
- window->start_line = ptr_line;
- window->start_line_pos = 0;
- window->first_line_displayed =
- (window->start_line == window->buffer->lines->first_line);
+ window->scroll->start_line = ptr_line;
+ window->scroll->start_line_pos = 0;
+ window->scroll->first_line_displayed =
+ (window->scroll->start_line == window->buffer->lines->first_line);
gui_buffer_ask_chat_refresh (window->buffer, 2);
return;
}
@@ -783,16 +965,16 @@ gui_window_scroll_next_highlight (struct t_gui_window *window)
{
if (window->buffer->lines->first_line)
{
- ptr_line = (window->start_line) ?
- window->start_line->next_line : window->buffer->lines->first_line->next_line;
+ ptr_line = (window->scroll->start_line) ?
+ window->scroll->start_line->next_line : window->buffer->lines->first_line->next_line;
while (ptr_line)
{
if (ptr_line->data->highlight)
{
- window->start_line = ptr_line;
- window->start_line_pos = 0;
- window->first_line_displayed =
- (window->start_line == window->buffer->lines->first_line);
+ window->scroll->start_line = ptr_line;
+ window->scroll->start_line_pos = 0;
+ window->scroll->first_line_displayed =
+ (window->scroll->start_line == window->buffer->lines->first_line);
gui_buffer_ask_chat_refresh (window->buffer, 2);
return;
}
@@ -816,8 +998,8 @@ gui_window_search_text (struct t_gui_window *window)
if (window->buffer->lines->first_line
&& window->buffer->input_buffer && window->buffer->input_buffer[0])
{
- ptr_line = (window->start_line) ?
- gui_line_get_prev_displayed (window->start_line) :
+ ptr_line = (window->scroll->start_line) ?
+ gui_line_get_prev_displayed (window->scroll->start_line) :
gui_line_get_last_displayed (window->buffer);
while (ptr_line)
{
@@ -825,10 +1007,10 @@ gui_window_search_text (struct t_gui_window *window)
window->buffer->input_buffer,
window->buffer->text_search_exact))
{
- window->start_line = ptr_line;
- window->start_line_pos = 0;
- window->first_line_displayed =
- (window->start_line == gui_line_get_first_displayed (window->buffer));
+ window->scroll->start_line = ptr_line;
+ window->scroll->start_line_pos = 0;
+ window->scroll->first_line_displayed =
+ (window->scroll->start_line == gui_line_get_first_displayed (window->buffer));
gui_buffer_ask_chat_refresh (window->buffer, 2);
return 1;
}
@@ -841,8 +1023,8 @@ gui_window_search_text (struct t_gui_window *window)
if (window->buffer->lines->first_line
&& window->buffer->input_buffer && window->buffer->input_buffer[0])
{
- ptr_line = (window->start_line) ?
- gui_line_get_next_displayed (window->start_line) :
+ ptr_line = (window->scroll->start_line) ?
+ gui_line_get_next_displayed (window->scroll->start_line) :
gui_line_get_first_displayed (window->buffer);
while (ptr_line)
{
@@ -850,10 +1032,10 @@ gui_window_search_text (struct t_gui_window *window)
window->buffer->input_buffer,
window->buffer->text_search_exact))
{
- window->start_line = ptr_line;
- window->start_line_pos = 0;
- window->first_line_displayed =
- (window->start_line == window->buffer->lines->first_line);
+ window->scroll->start_line = ptr_line;
+ window->scroll->start_line_pos = 0;
+ window->scroll->first_line_displayed =
+ (window->scroll->start_line == window->buffer->lines->first_line);
gui_buffer_ask_chat_refresh (window->buffer, 2);
return 1;
}
@@ -893,8 +1075,8 @@ gui_window_search_start (struct t_gui_window *window)
void
gui_window_search_restart (struct t_gui_window *window)
{
- window->start_line = NULL;
- window->start_line_pos = 0;
+ window->scroll->start_line = NULL;
+ window->scroll->start_line_pos = 0;
window->buffer->text_search = GUI_TEXT_SEARCH_BACKWARD;
window->buffer->text_search_found = 0;
if (gui_window_search_text (window))
@@ -928,8 +1110,8 @@ gui_window_search_stop (struct t_gui_window *window)
free (window->buffer->text_search_input);
window->buffer->text_search_input = NULL;
}
- window->start_line = NULL;
- window->start_line_pos = 0;
+ window->scroll->start_line = NULL;
+ window->scroll->start_line_pos = 0;
gui_hotlist_remove_buffer (window->buffer);
gui_buffer_ask_chat_refresh (window->buffer, 2);
}
@@ -1014,8 +1196,8 @@ gui_window_add_to_infolist (struct t_infolist *infolist,
return 0;
if (!infolist_new_var_integer (ptr_item, "start_line_y",
((window->buffer->type == GUI_BUFFER_TYPE_FREE)
- && (window->start_line)) ?
- window->start_line->data->y : 0))
+ && (window->scroll->start_line)) ?
+ window->scroll->start_line->data->y : 0))
return 0;
return 1;
@@ -1029,6 +1211,7 @@ void
gui_window_print_log ()
{
struct t_gui_window *ptr_window;
+ struct t_gui_window_scroll *ptr_scroll;
struct t_gui_bar_window *ptr_bar_win;
log_printf ("");
@@ -1060,16 +1243,27 @@ gui_window_print_log ()
log_printf (" buffer. . . . . . . : 0x%lx", ptr_window->buffer);
log_printf (" layout_plugin_name. : '%s'", ptr_window->layout_plugin_name);
log_printf (" layout_buffer_name. : '%s'", ptr_window->layout_buffer_name);
- log_printf (" first_line_displayed: %d", ptr_window->first_line_displayed);
- log_printf (" start_line. . . . . : 0x%lx", ptr_window->start_line);
- log_printf (" start_line_pos. . . : %d", ptr_window->start_line_pos);
- log_printf (" scroll. . . . . . . : %d", ptr_window->scroll);
- log_printf (" scroll_lines_after. : %d", ptr_window->scroll_lines_after);
- log_printf (" scroll_reset_allowed: %d", ptr_window->scroll_reset_allowed);
+ log_printf (" scroll. . . . . . . : 0x%lx", ptr_window->scroll);
log_printf (" ptr_tree. . . . . . : 0x%lx", ptr_window->ptr_tree);
log_printf (" prev_window . . . . : 0x%lx", ptr_window->prev_window);
log_printf (" next_window . . . . : 0x%lx", ptr_window->next_window);
+ for (ptr_scroll = ptr_window->scroll; ptr_scroll;
+ ptr_scroll = ptr_scroll->next_scroll)
+ {
+ log_printf ("");
+ log_printf (" [scroll (addr:0x%lx)]", ptr_scroll);
+ log_printf (" buffer. . . . . . . : 0x%lx", ptr_scroll->buffer);
+ log_printf (" first_line_displayed: %d", ptr_scroll->first_line_displayed);
+ 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 (" 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);
+ log_printf (" next_scroll . . . . : 0x%lx", ptr_scroll->next_scroll);
+ }
+
for (ptr_bar_win = ptr_window->bar_windows; ptr_bar_win;
ptr_bar_win = ptr_bar_win->next_bar_window)
{
diff --git a/src/gui/gui-window.h b/src/gui/gui-window.h
index 98f3dcf65..1e7920d49 100644
--- a/src/gui/gui-window.h
+++ b/src/gui/gui-window.h
@@ -67,18 +67,29 @@ struct t_gui_window
/* be assigned later) */
/* scroll */
+ struct t_gui_window_scroll *scroll; /* scroll infos for each buffer */
+ /* scrolled in this window */
+
+ /* tree */
+ struct t_gui_window_tree *ptr_tree;/* pointer to leaf in windows tree */
+
+ struct t_gui_window *prev_window; /* link to previous window */
+ struct t_gui_window *next_window; /* link to next window */
+};
+
+struct t_gui_window_scroll
+{
+ struct t_gui_buffer *buffer; /* buffer scrolled in window */
int first_line_displayed; /* = 1 if first line is displayed */
struct t_gui_line *start_line; /* pointer to line if scrolling */
int start_line_pos; /* position in first line displayed */
- int scroll; /* = 1 if "MORE" should be displayed */
- int scroll_lines_after; /* number of lines after last line */
+ int scrolling; /* = 1 if "MORE" should be displayed */
+ int lines_after; /* number of lines after last line */
/* displayed (with scrolling) */
- int scroll_reset_allowed; /* reset scroll allowed (when using */
+ int reset_allowed; /* reset scroll allowed (when using */
/* keys like page_up/down, end, ..) */
- struct t_gui_window_tree *ptr_tree;/* pointer to leaf in windows tree */
-
- struct t_gui_window *prev_window; /* link to previous window */
- struct t_gui_window *next_window; /* link to next window */
+ struct t_gui_window_scroll *prev_scroll; /* link to prev. buf. scrolled */
+ struct t_gui_window_scroll *next_scroll; /* link to next buf. scrolled */
};
struct t_gui_window_tree
@@ -108,6 +119,10 @@ extern int gui_window_tree_init (struct t_gui_window *window);
extern void gui_window_tree_node_to_leaf (struct t_gui_window_tree *node,
struct t_gui_window *window);
extern void gui_window_tree_free (struct t_gui_window_tree **tree);
+extern void gui_window_scroll_switch (struct t_gui_window *window,
+ struct t_gui_buffer *buffer);
+extern void gui_window_scroll_remove_buffer (struct t_gui_window *window,
+ struct t_gui_buffer *buffer);
extern struct t_gui_window *gui_window_new (struct t_gui_window *parent_window,
struct t_gui_buffer *buffer,
int x, int y, int width, int height,