summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/curses/gui-curses-main.c40
-rw-r--r--src/gui/curses/gui-curses-window.c6
-rw-r--r--src/gui/curses/gui-curses.h7
-rw-r--r--src/gui/gtk/gui-gtk-main.c50
-rw-r--r--src/gui/gtk/gui-gtk-window.c6
-rw-r--r--src/gui/gui-bar-item.c119
-rw-r--r--src/gui/gui-bar-item.h5
-rw-r--r--src/gui/gui-bar-window.c208
-rw-r--r--src/gui/gui-bar-window.h14
-rw-r--r--src/gui/gui-bar.c169
-rw-r--r--src/gui/gui-bar.h11
-rw-r--r--src/gui/gui-buffer.c21
-rw-r--r--src/gui/gui-window.c11
-rw-r--r--src/gui/gui-window.h3
14 files changed, 532 insertions, 138 deletions
diff --git a/src/gui/curses/gui-curses-main.c b/src/gui/curses/gui-curses-main.c
index 897511722..ba13a4ba8 100644
--- a/src/gui/curses/gui-curses-main.c
+++ b/src/gui/curses/gui-curses-main.c
@@ -112,33 +112,37 @@ gui_main_init ()
/* init bar items */
gui_bar_item_init ();
- /* create new window/buffer */
- if (gui_window_new (NULL, 0, 0, COLS, LINES, 100, 100))
+ gui_init_ok = 0;
+
+ /* create core buffer */
+ ptr_buffer = gui_buffer_new (NULL, "weechat", NULL, NULL, NULL, NULL);
+ if (ptr_buffer)
{
- gui_current_window = gui_windows;
- ptr_buffer = gui_buffer_new (NULL, "weechat", NULL, NULL, NULL, NULL);
- if (ptr_buffer)
+ gui_init_ok = 1;
+
+ /* set title for core buffer */
+ gui_buffer_set_title (ptr_buffer,
+ "WeeChat " WEECHAT_COPYRIGHT_DATE
+ " - " WEECHAT_WEBSITE);
+
+ /* create main window (using full space) */
+ if (gui_window_new (NULL, ptr_buffer, 0, 0, COLS, LINES, 100, 100))
{
- gui_init_ok = 1;
- gui_buffer_set_title (ptr_buffer,
- "WeeChat " WEECHAT_COPYRIGHT_DATE
- " - " WEECHAT_WEBSITE);
+ gui_current_window = gui_windows;
+
+ if (CONFIG_BOOLEAN(config_look_set_title))
+ gui_window_title_set ();
}
- else
- gui_init_ok = 0;
- if (CONFIG_BOOLEAN(config_look_set_title))
- gui_window_title_set ();
- }
-
- if (gui_init_ok)
- {
/* create bar windows for root bars (they were read from config,
but no window was created (GUI was not initialized) */
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
{
- if ((CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_ROOT) && (!ptr_bar->bar_window))
+ if ((CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_ROOT)
+ && (!ptr_bar->bar_window))
+ {
gui_bar_window_new (ptr_bar, NULL);
+ }
}
for (ptr_bar_win = gui_windows->bar_windows;
ptr_bar_win; ptr_bar_win = ptr_bar_win->next_bar_window)
diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c
index ff26a9173..6c19c206b 100644
--- a/src/gui/curses/gui-curses-window.c
+++ b/src/gui/curses/gui-curses-window.c
@@ -980,7 +980,7 @@ gui_window_split_horiz (struct t_gui_window *window, int percentage)
if ((height1 >= GUI_WINDOW_MIN_HEIGHT) && (height2 >= GUI_WINDOW_MIN_HEIGHT)
&& (percentage > 0) && (percentage <= 100))
{
- new_window = gui_window_new (window,
+ new_window = gui_window_new (window, window->buffer,
window->win_x, window->win_y,
window->win_width, height1,
100, percentage);
@@ -992,7 +992,6 @@ gui_window_split_horiz (struct t_gui_window *window, int percentage)
window->win_height_pct = 100 - percentage;
/* assign same buffer for new window (top window) */
- new_window->buffer = window->buffer;
new_window->buffer->num_displayed++;
gui_window_switch_to_buffer (window, window->buffer, 1);
@@ -1025,7 +1024,7 @@ gui_window_split_vertic (struct t_gui_window *window, int percentage)
if ((width1 >= GUI_WINDOW_MIN_WIDTH) && (width2 >= GUI_WINDOW_MIN_WIDTH)
&& (percentage > 0) && (percentage <= 100))
{
- new_window = gui_window_new (window,
+ new_window = gui_window_new (window, window->buffer,
window->win_x + width1 + 1, window->win_y,
width2, window->win_height,
percentage, 100);
@@ -1036,7 +1035,6 @@ gui_window_split_vertic (struct t_gui_window *window, int percentage)
window->win_width_pct = 100 - percentage;
/* assign same buffer for new window (right window) */
- new_window->buffer = window->buffer;
new_window->buffer->num_displayed++;
gui_window_switch_to_buffer (window, window->buffer, 1);
diff --git a/src/gui/curses/gui-curses.h b/src/gui/curses/gui-curses.h
index dfb76466c..91923f1b5 100644
--- a/src/gui/curses/gui-curses.h
+++ b/src/gui/curses/gui-curses.h
@@ -59,13 +59,6 @@ extern void gui_color_pre_init ();
extern void gui_color_init ();
extern void gui_color_end ();
-/* bar functions */
-extern void gui_bar_window_calculate_pos_size (struct t_gui_bar_window *bar_window,
- struct t_gui_window *window);
-extern void gui_bar_window_create_win (struct t_gui_bar_window *bar_window);
-extern int gui_bar_window_remove_unused_bars (struct t_gui_window *window);
-extern int gui_bar_window_add_missing_bars (struct t_gui_window *window);
-
/* chat functions */
extern void gui_chat_calculate_line_diff (struct t_gui_window *window,
struct t_gui_line **line,
diff --git a/src/gui/gtk/gui-gtk-main.c b/src/gui/gtk/gui-gtk-main.c
index 8b12876aa..9633c49f2 100644
--- a/src/gui/gtk/gui-gtk-main.c
+++ b/src/gui/gtk/gui-gtk-main.c
@@ -35,6 +35,7 @@
#include "../../plugins/plugin.h"
#include "../gui-bar.h"
#include "../gui-bar-item.h"
+#include "../gui-bar-window.h"
#include "../gui-chat.h"
#include "../gui-main.h"
#include "../gui-buffer.h"
@@ -84,6 +85,8 @@ void
gui_main_init ()
{
struct t_gui_buffer *ptr_buffer;
+ struct t_gui_bar *ptr_bar;
+ struct t_gui_bar_window *ptr_bar_win;
GdkColor color_fg, color_bg;
gui_color_init ();
@@ -170,23 +173,44 @@ gui_main_init ()
gtk_widget_show_all (gui_gtk_main_window);
- /* create new window/buffer */
- if (gui_window_new (NULL, 0, 0, 0, 0, 100, 100))
+ gui_init_ok = 0;
+
+ /* create core buffer */
+ ptr_buffer = gui_buffer_new (NULL, "weechat", NULL, NULL, NULL, NULL);
+ if (ptr_buffer)
{
- gui_current_window = gui_windows;
- ptr_buffer = gui_buffer_new (NULL, "weechat", NULL, NULL, NULL, NULL);
- if (ptr_buffer)
+ gui_init_ok = 1;
+
+ /* set title for core buffer */
+ gui_buffer_set_title (ptr_buffer,
+ "WeeChat " WEECHAT_COPYRIGHT_DATE
+ " - " WEECHAT_WEBSITE);
+
+ /* create main window (using full space) */
+ if (gui_window_new (NULL, ptr_buffer, 0, 0, 0, 0, 100, 100))
{
- gui_init_ok = 1;
- gui_buffer_set_title (ptr_buffer,
- PACKAGE_STRING " " WEECHAT_COPYRIGHT_DATE
- " - " WEECHAT_WEBSITE);
+ gui_current_window = gui_windows;
+
+ if (CONFIG_BOOLEAN(config_look_set_title))
+ gui_window_title_set ();
}
- else
- gui_init_ok = 0;
- if (CONFIG_BOOLEAN(config_look_set_title))
- gui_window_title_set ();
+ /* create bar windows for root bars (they were read from config,
+ but no window was created (GUI was not initialized) */
+ for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
+ {
+ if ((CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_ROOT)
+ && (!ptr_bar->bar_window))
+ {
+ gui_bar_window_new (ptr_bar, NULL);
+ }
+ }
+ for (ptr_bar_win = gui_windows->bar_windows;
+ ptr_bar_win; ptr_bar_win = ptr_bar_win->next_bar_window)
+ {
+ gui_bar_window_calculate_pos_size (ptr_bar_win, gui_windows);
+ gui_bar_window_create_win (ptr_bar_win);
+ }
}
}
diff --git a/src/gui/gtk/gui-gtk-window.c b/src/gui/gtk/gui-gtk-window.c
index 81515d560..11c06479b 100644
--- a/src/gui/gtk/gui-gtk-window.c
+++ b/src/gui/gtk/gui-gtk-window.c
@@ -480,7 +480,7 @@ gui_window_split_horiz (struct t_gui_window *window, int percentage)
if ((percentage > 0) && (percentage <= 100))
{
- new_window = gui_window_new (window,
+ new_window = gui_window_new (window, window->buffer,
window->win_x, window->win_y,
window->win_width, height1,
100, percentage);
@@ -492,7 +492,6 @@ gui_window_split_horiz (struct t_gui_window *window, int percentage)
window->win_height_pct = 100 - percentage;
/* assign same buffer for new window (top window) */
- new_window->buffer = window->buffer;
new_window->buffer->num_displayed++;
gui_window_switch_to_buffer (window, window->buffer, 1);
@@ -526,7 +525,7 @@ gui_window_split_vertic (struct t_gui_window *window, int percentage)
if ((percentage > 0) && (percentage <= 100))
{
- new_window = gui_window_new (window,
+ new_window = gui_window_new (window, window->buffer,
window->win_x + width1 + 1, window->win_y,
width2, window->win_height,
percentage, 100);
@@ -537,7 +536,6 @@ gui_window_split_vertic (struct t_gui_window *window, int percentage)
window->win_width_pct = 100 - percentage;
/* assign same buffer for new window (right window) */
- new_window->buffer = window->buffer;
new_window->buffer->num_displayed++;
gui_window_switch_to_buffer (window, window->buffer, 1);
diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c
index 72c9f7f68..9d75c523b 100644
--- a/src/gui/gui-bar-item.c
+++ b/src/gui/gui-bar-item.c
@@ -30,12 +30,14 @@
#include "../core/weechat.h"
#include "../core/wee-config.h"
#include "../core/wee-hook.h"
+#include "../core/wee-infolist.h"
#include "../core/wee-log.h"
#include "../core/wee-string.h"
#include "../core/wee-utf8.h"
#include "../plugins/plugin.h"
#include "gui-bar-item.h"
#include "gui-bar.h"
+#include "gui-bar-window.h"
#include "gui-buffer.h"
#include "gui-chat.h"
#include "gui-color.h"
@@ -60,6 +62,31 @@ struct t_hook *gui_bar_item_timer = NULL;
/*
+ * gui_bar_item_valid: check if a bar item pointer exists
+ * return 1 if bar item exists
+ * 0 if bar item is not found
+ */
+
+int
+gui_bar_item_valid (struct t_gui_bar_item *bar_item)
+{
+ struct t_gui_bar_item *ptr_bar_item;
+
+ if (!bar_item)
+ return 0;
+
+ for (ptr_bar_item = gui_bar_items; ptr_bar_item;
+ ptr_bar_item = ptr_bar_item->next_item)
+ {
+ if (ptr_bar_item == bar_item)
+ return 1;
+ }
+
+ /* bar item not found */
+ return 0;
+}
+
+/*
* gui_bar_item_search: search a bar item
*/
@@ -190,29 +217,6 @@ gui_bar_item_search_with_plugin (struct t_weechat_plugin *plugin,
}
/*
- * gui_bar_contains_item: return 1 if a bar contains item, O otherwise
- */
-
-int
-gui_bar_contains_item (struct t_gui_bar *bar, const char *item_name)
-{
- int i;
-
- if (!bar || !item_name || !item_name[0])
- return 0;
-
- for (i = 0; i < bar->items_count; i++)
- {
- /* skip non letters chars at beginning (prefix) */
- if (gui_bar_item_string_is_item (bar->items_array[i], item_name))
- return 1;
- }
-
- /* item is not in bar */
- return 0;
-}
-
-/*
* gui_bar_item_used_in_a_bar: return 1 if an item is used in at least one bar
* if partial_name == 1, then search a bar that
* contains item beginning with "item_name"
@@ -396,7 +400,8 @@ gui_bar_item_get_value (const char *name, struct t_gui_bar *bar,
item_value = NULL;
if (item_name)
{
- ptr_item = gui_bar_item_search_with_plugin ((window) ? window->buffer->plugin : NULL,
+ ptr_item = gui_bar_item_search_with_plugin ((window && window->buffer) ?
+ window->buffer->plugin : NULL,
0,
item_name);
if (ptr_item)
@@ -550,13 +555,43 @@ void
gui_bar_item_update (const char *item_name)
{
struct t_gui_bar *ptr_bar;
+ struct t_gui_window *ptr_window;
+ struct t_gui_bar_window *ptr_bar_window;
+ int item_index;
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
{
- if (!CONFIG_BOOLEAN(ptr_bar->hidden)
- && gui_bar_contains_item (ptr_bar, item_name))
+ if (!CONFIG_BOOLEAN(ptr_bar->hidden))
{
- gui_bar_ask_refresh (ptr_bar);
+ item_index = gui_bar_get_item_index (ptr_bar, item_name);
+ if (item_index >= 0)
+ {
+ if (ptr_bar->bar_window)
+ {
+ gui_bar_window_content_build_item (ptr_bar->bar_window,
+ NULL,
+ item_index);
+ }
+ else
+ {
+ for (ptr_window = gui_windows; ptr_window;
+ ptr_window = ptr_window->next_window)
+ {
+ for (ptr_bar_window = ptr_window->bar_windows;
+ ptr_bar_window;
+ ptr_bar_window = ptr_bar_window->next_bar_window)
+ {
+ if (ptr_bar_window->bar == ptr_bar)
+ {
+ gui_bar_window_content_build_item (ptr_bar_window,
+ ptr_window,
+ item_index);
+ }
+ }
+ }
+ }
+ gui_bar_ask_refresh (ptr_bar);
+ }
}
}
}
@@ -1468,6 +1503,36 @@ gui_bar_item_end ()
}
/*
+ * gui_bar_item_add_to_infolist: add a bar item in an infolist
+ * return 1 if ok, 0 if error
+ */
+
+int
+gui_bar_item_add_to_infolist (struct t_infolist *infolist,
+ struct t_gui_bar_item *bar_item)
+{
+ struct t_infolist_item *ptr_item;
+
+ if (!infolist || !bar_item)
+ return 0;
+
+ ptr_item = infolist_new_item (infolist);
+ if (!ptr_item)
+ return 0;
+
+ if (!infolist_new_var_pointer (ptr_item, "plugin", bar_item->plugin))
+ return 0;
+ if (!infolist_new_var_string (ptr_item, "name", bar_item->name))
+ return 0;
+ if (!infolist_new_var_pointer (ptr_item, "build_callback", bar_item->build_callback))
+ return 0;
+ if (!infolist_new_var_pointer (ptr_item, "build_callback_data", bar_item->build_callback_data))
+ return 0;
+
+ return 1;
+}
+
+/*
* gui_bar_item_print_log: print bar items infos in log (usually for crash dump)
*/
diff --git a/src/gui/gui-bar-item.h b/src/gui/gui-bar-item.h
index bd522c4a2..007257779 100644
--- a/src/gui/gui-bar-item.h
+++ b/src/gui/gui-bar-item.h
@@ -71,7 +71,10 @@ extern char *gui_bar_item_names[];
/* functions */
+extern int gui_bar_item_valid (struct t_gui_bar_item *bar_item);
extern struct t_gui_bar_item *gui_bar_item_search (const char *name);
+extern int gui_bar_item_string_is_item (const char *string,
+ const char *item_name);
extern int gui_bar_item_used_in_a_bar (const char *item_name,
int partial_name);
extern char *gui_bar_item_get_value (const char *name,
@@ -93,6 +96,8 @@ extern void gui_bar_item_free_all ();
extern void gui_bar_item_free_all_plugin (struct t_weechat_plugin *plugin);
extern void gui_bar_item_init ();
extern void gui_bar_item_end ();
+extern int gui_bar_item_add_to_infolist (struct t_infolist *infolist,
+ struct t_gui_bar_item *bar_item);
extern void gui_bar_item_print_log ();
#endif /* gui-bar-item.h */
diff --git a/src/gui/gui-bar-window.c b/src/gui/gui-bar-window.c
index a2bfbb268..96b878fa6 100644
--- a/src/gui/gui-bar-window.c
+++ b/src/gui/gui-bar-window.c
@@ -29,14 +29,56 @@
#include "../core/weechat.h"
#include "../core/wee-config.h"
+#include "../core/wee-infolist.h"
#include "../core/wee-log.h"
#include "../core/wee-string.h"
#include "gui-bar-window.h"
#include "gui-bar.h"
+#include "gui-bar-item.h"
+#include "gui-color.h"
#include "gui-window.h"
/*
+ * gui_bar_window_valid: check if a bar window pointer exists
+ * return 1 if bar window exists
+ * 0 if bar window is not found
+ */
+
+int
+gui_bar_window_valid (struct t_gui_bar_window *bar_window)
+{
+ struct t_gui_bar *ptr_bar;
+ struct t_gui_window *ptr_window;
+ struct t_gui_bar_window *ptr_bar_window;
+
+ if (!bar_window)
+ return 0;
+
+ /* check root bars */
+ for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
+ {
+ if (ptr_bar->bar_window && (ptr_bar->bar_window == bar_window))
+ return 1;
+ }
+
+ /* check window bars */
+ for (ptr_window = gui_windows; ptr_window;
+ ptr_window = ptr_window->next_window)
+ {
+ for (ptr_bar_window = ptr_window->bar_windows; ptr_bar_window;
+ ptr_bar_window = ptr_bar_window->next_bar_window)
+ {
+ if (ptr_bar_window == bar_window)
+ return 1;
+ }
+ }
+
+ /* bar window not found */
+ return 0;
+}
+
+/*
* gui_bar_window_search_bar: search a reference to a bar in a window
*/
@@ -190,6 +232,97 @@ gui_bar_window_find_pos (struct t_gui_bar *bar, struct t_gui_window *window)
}
/*
+ * gui_bar_window_content_alloc: allocate content for a bar window
+ */
+
+void
+gui_bar_window_content_alloc (struct t_gui_bar_window *bar_window)
+{
+ int i;
+
+ bar_window->items_count = bar_window->bar->items_count;
+ bar_window->items_content = malloc((bar_window->items_count) *
+ sizeof (bar_window->items_content[0]));
+ if (bar_window->items_content)
+ {
+ for (i = 0; i < bar_window->items_count; i++)
+ {
+ bar_window->items_content[i] = NULL;
+ }
+ }
+ else
+ bar_window->items_count = 0;
+}
+
+/*
+ * gui_bar_window_content_free: free content of a bar window
+ */
+
+void
+gui_bar_window_content_free (struct t_gui_bar_window *bar_window)
+{
+ int i;
+
+ if (bar_window->items_content)
+ {
+ for (i = 0; i < bar_window->items_count; i++)
+ {
+ if (bar_window->items_content[i])
+ free (bar_window->items_content[i]);
+ }
+ free (bar_window->items_content);
+ bar_window->items_content = NULL;
+ }
+}
+
+/*
+ * gui_bar_window_content_build_item: build content of an item for a bar window,
+ * by calling callback for each item, then
+ * concat values (according to bar position
+ * and filling)
+ */
+
+void
+gui_bar_window_content_build_item (struct t_gui_bar_window *bar_window,
+ struct t_gui_window *window,
+ int item_index)
+{
+ log_printf ("bar_window: build item '%s'", bar_window->bar->items_array[item_index]);
+ if (bar_window->items_content[item_index])
+ free (bar_window->items_content[item_index]);
+
+ bar_window->items_content[item_index] =
+ gui_bar_item_get_value (bar_window->bar->items_array[item_index],
+ bar_window->bar, window,
+ 0, 0, 0);
+}
+
+/*
+ * gui_bar_window_content_build: build content of a bar window, by calling
+ * callback for each item, then concat values
+ * (according to bar position and filling)
+ */
+
+void
+gui_bar_window_content_build (struct t_gui_bar_window *bar_window,
+ struct t_gui_window *window)
+{
+ int i;
+
+ if (bar_window->items_count != bar_window->bar->items_count)
+ {
+ gui_bar_window_content_free (bar_window);
+ gui_bar_window_content_alloc (bar_window);
+ }
+
+ for (i = 0; i < bar_window->items_count; i++)
+ {
+ gui_bar_window_content_build_item (bar_window, window, i);
+
+ }
+}
+
+/*
* gui_bar_window_new: create a new "window bar" for a bar, in screen or a window
* if window is not NULL, bar window will be in this window
* return 1 if ok, 0 if error
@@ -262,8 +395,10 @@ gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window)
new_bar_window->cursor_y = -1;
new_bar_window->current_size = (CONFIG_INTEGER(bar->size) == 0) ?
1 : CONFIG_INTEGER(bar->size);
- new_bar_window->content = NULL;
+ new_bar_window->items_content = NULL;
+ new_bar_window->items_count = 0;
gui_bar_window_objects_init (new_bar_window);
+ gui_bar_window_content_build (new_bar_window, window);
if (gui_init_ok)
{
@@ -404,8 +539,7 @@ gui_bar_window_free (struct t_gui_bar_window *bar_window,
}
/* free data */
- if (bar_window->content)
- free (bar_window->content);
+ gui_bar_window_content_free (bar_window);
gui_bar_window_objects_free (bar_window);
free (bar_window->gui_objects);
@@ -548,14 +682,71 @@ gui_bar_window_scroll (struct t_gui_bar_window *bar_window,
}
/*
+ * gui_bar_window_add_to_infolist: add a bar window in an infolist
+ * return 1 if ok, 0 if error
+ */
+
+int
+gui_bar_window_add_to_infolist (struct t_infolist *infolist,
+ struct t_gui_bar_window *bar_window)
+{
+ struct t_infolist_item *ptr_item;
+ int i;
+ char option_name[64];
+
+ if (!infolist || !bar_window)
+ return 0;
+
+ ptr_item = infolist_new_item (infolist);
+ if (!ptr_item)
+ return 0;
+
+ if (!infolist_new_var_pointer (ptr_item, "bar", bar_window->bar))
+ return 0;
+ if (!infolist_new_var_integer (ptr_item, "x", bar_window->x))
+ return 0;
+ if (!infolist_new_var_integer (ptr_item, "y", bar_window->y))
+ return 0;
+ if (!infolist_new_var_integer (ptr_item, "width", bar_window->width))
+ return 0;
+ if (!infolist_new_var_integer (ptr_item, "height", bar_window->height))
+ return 0;
+ if (!infolist_new_var_integer (ptr_item, "scroll_x", bar_window->scroll_x))
+ return 0;
+ if (!infolist_new_var_integer (ptr_item, "scroll_y", bar_window->scroll_y))
+ return 0;
+ if (!infolist_new_var_integer (ptr_item, "cursor_x", bar_window->cursor_x))
+ return 0;
+ if (!infolist_new_var_integer (ptr_item, "cursor_y", bar_window->cursor_y))
+ return 0;
+ if (!infolist_new_var_integer (ptr_item, "current_size", bar_window->current_size))
+ return 0;
+ if (!infolist_new_var_integer (ptr_item, "items_count", bar_window->current_size))
+ return 0;
+ for (i = 0; i < bar_window->items_count; i++)
+ {
+ snprintf (option_name, sizeof (option_name), "items_content_%05d", i + 1);
+ if (!infolist_new_var_string (ptr_item, option_name,
+ bar_window->items_content[i]))
+ return 0;
+ }
+ if (!infolist_new_var_pointer (ptr_item, "gui_objects", bar_window->gui_objects))
+ return 0;
+
+ return 1;
+}
+
+/*
* gui_bar_window_print_log: print bar window infos in log (usually for crash dump)
*/
void
gui_bar_window_print_log (struct t_gui_bar_window *bar_window)
{
+ int i;
+
log_printf ("");
- log_printf (" [window bar (addr:0x%lx)]", bar_window);
+ log_printf (" [window bar (addr:0x%lx)]", bar_window);
log_printf (" bar . . . . . . . : 0x%lx ('%s')",
bar_window->bar,
(bar_window->bar) ? bar_window->bar->name : "");
@@ -568,6 +759,15 @@ gui_bar_window_print_log (struct t_gui_bar_window *bar_window)
log_printf (" cursor_x. . . . . . : %d", bar_window->cursor_x);
log_printf (" cursor_y. . . . . . : %d", bar_window->cursor_y);
log_printf (" current_size. . . . : %d", bar_window->current_size);
+ log_printf (" items_count . . . . : %d", bar_window->items_count);
+ for (i = 0; i < bar_window->items_count; i++)
+ {
+ log_printf (" items_content[%03d]. : '%s' (item: '%s')",
+ i,
+ bar_window->items_content[i],
+ (bar_window->bar->items_count >= i + 1) ?
+ bar_window->bar->items_array[i] : "?");
+ }
log_printf (" gui_objects . . . . : 0x%lx", bar_window->gui_objects);
gui_bar_window_objects_print_log (bar_window);
log_printf (" prev_bar_window . . : 0x%lx", bar_window->prev_bar_window);
diff --git a/src/gui/gui-bar-window.h b/src/gui/gui-bar-window.h
index d8d7c89d1..2b716dfc4 100644
--- a/src/gui/gui-bar-window.h
+++ b/src/gui/gui-bar-window.h
@@ -32,7 +32,8 @@ struct t_gui_bar_window
int cursor_x, cursor_y; /* use to move cursor on screen (for */
/* input_text item) */
int current_size; /* current size (width or height) */
- char *content; /* bar window content (data displayed) */
+ int items_count; /* number of items */
+ char **items_content; /* content for each item of bar */
void *gui_objects; /* pointer to a GUI specific struct */
struct t_gui_bar_window *prev_bar_window; /* link to previous bar win */
/* (only for non-root bars) */
@@ -42,6 +43,12 @@ struct t_gui_bar_window
/* functions */
+extern int gui_bar_window_valid (struct t_gui_bar_window *bar_window);
+extern void gui_bar_window_calculate_pos_size (struct t_gui_bar_window *bar_window,
+ struct t_gui_window *window);
+extern void gui_bar_window_content_build_item (struct t_gui_bar_window *bar_window,
+ struct t_gui_window *window,
+ int item_index);
extern struct t_gui_bar_window *gui_bar_window_search_bar (struct t_gui_window *window,
struct t_gui_bar *bar);
extern int gui_bar_window_get_current_size (struct t_gui_bar_window *bar_window);
@@ -53,11 +60,16 @@ extern int gui_bar_window_new (struct t_gui_bar *bar,
struct t_gui_window *window);
extern void gui_bar_window_free (struct t_gui_bar_window *bar_window,
struct t_gui_window *window);
+extern int gui_bar_window_remove_unused_bars (struct t_gui_window *window);
+extern int gui_bar_window_add_missing_bars (struct t_gui_window *window);
extern void gui_bar_window_scroll (struct t_gui_bar_window *bar_window,
struct t_gui_window *window,
int add_x, int scroll_beginning,
int scroll_end, int add, int percent,
int value);
+extern int gui_bar_window_add_to_infolist (struct t_infolist *infolist,
+ struct t_gui_bar_window *bar_window);
+extern void gui_bar_window_print_log (struct t_gui_bar_window *bar_window);
/* functions (GUI dependent) */
diff --git a/src/gui/gui-bar.c b/src/gui/gui-bar.c
index 1030ec59d..129fabe35 100644
--- a/src/gui/gui-bar.c
+++ b/src/gui/gui-bar.c
@@ -29,6 +29,7 @@
#include "../core/weechat.h"
#include "../core/wee-config.h"
+#include "../core/wee-infolist.h"
#include "../core/wee-log.h"
#include "../core/wee-string.h"
#include "../plugins/plugin.h"
@@ -60,6 +61,30 @@ struct t_gui_bar *last_gui_temp_bar = NULL;
/*
+ * gui_bar_valid: check if a bar pointer exists
+ * return 1 if bar exists
+ * 0 if bar is not found
+ */
+
+int
+gui_bar_valid (struct t_gui_bar *bar)
+{
+ struct t_gui_bar *ptr_bar;
+
+ if (!bar)
+ return 0;
+
+ for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
+ {
+ if (ptr_bar == bar)
+ return 1;
+ }
+
+ /* bar not found */
+ return 0;
+}
+
+/*
* gui_bar_search_option search a bar option name
* return index of option in array
* "gui_bar_option_string", or -1 if not found
@@ -266,6 +291,31 @@ gui_bar_get_option_filling (struct t_gui_bar *bar)
}
/*
+ * gui_bar_get_item_index: return index of item in bar (position of item in
+ * items list)
+ * return -1 if item is not in bar
+ */
+
+int
+gui_bar_get_item_index (struct t_gui_bar *bar, const char *item_name)
+{
+ int i;
+
+ if (!bar || !item_name || !item_name[0])
+ return -1;
+
+ for (i = 0; i < bar->items_count; i++)
+ {
+ /* skip non letters chars at beginning (prefix) */
+ if (gui_bar_item_string_is_item (bar->items_array[i], item_name))
+ return i;
+ }
+
+ /* item is not in bar */
+ return -1;
+}
+
+/*
* gui_bar_find_pos: find position for a bar in list (keeping list sorted
* by priority)
*/
@@ -1367,7 +1417,6 @@ gui_bar_alloc (const char *name)
new_bar = malloc (sizeof (*new_bar));
if (new_bar)
{
- new_bar->plugin = NULL;
new_bar->name = strdup (name);
new_bar->hidden = NULL;
new_bar->priority = NULL;
@@ -1401,7 +1450,7 @@ gui_bar_alloc (const char *name)
*/
struct t_gui_bar *
-gui_bar_new_with_options (struct t_weechat_plugin *plugin, const char *name,
+gui_bar_new_with_options (const char *name,
struct t_config_option *hidden,
struct t_config_option *priority,
struct t_config_option *type,
@@ -1424,7 +1473,6 @@ gui_bar_new_with_options (struct t_weechat_plugin *plugin, const char *name,
new_bar = gui_bar_alloc (name);
if (new_bar)
{
- new_bar->plugin = plugin;
new_bar->hidden = hidden;
new_bar->priority = priority;
new_bar->type = type;
@@ -1493,9 +1541,8 @@ gui_bar_new_with_options (struct t_weechat_plugin *plugin, const char *name,
*/
struct t_gui_bar *
-gui_bar_new (struct t_weechat_plugin *plugin, const char *name,
- const char *hidden, const char *priority, const char *type,
- const char *conditions, const char *position,
+gui_bar_new (const char *name, const char *hidden, const char *priority,
+ const char *type, const char *conditions, const char *position,
const char *filling_top_bottom, const char *filling_left_right,
const char *size, const char *size_max,
const char *color_fg, const char *color_delim,
@@ -1554,7 +1601,7 @@ gui_bar_new (struct t_weechat_plugin *plugin, const char *name,
"on" : "off");
option_items = gui_bar_create_option (name, GUI_BAR_OPTION_ITEMS,
items);
- new_bar = gui_bar_new_with_options (plugin, name, option_hidden,
+ new_bar = gui_bar_new_with_options (name, option_hidden,
option_priority, option_type,
option_conditions, option_position,
option_filling_top_bottom,
@@ -1686,8 +1733,7 @@ gui_bar_use_temp_bars ()
&& ptr_temp_bar->color_bg && ptr_temp_bar->separator
&& ptr_temp_bar->items)
{
- gui_bar_new_with_options (NULL,
- ptr_temp_bar->name,
+ gui_bar_new_with_options (ptr_temp_bar->name,
ptr_temp_bar->hidden,
ptr_temp_bar->priority,
ptr_temp_bar->type,
@@ -1849,7 +1895,7 @@ gui_bar_create_default_input ()
gui_bar_item_names[GUI_BAR_ITEM_INPUT_PROMPT],
gui_bar_item_names[GUI_BAR_ITEM_INPUT_SEARCH],
gui_bar_item_names[GUI_BAR_ITEM_INPUT_TEXT]);
- if (gui_bar_new (NULL, GUI_BAR_DEFAULT_NAME_INPUT,
+ if (gui_bar_new (GUI_BAR_DEFAULT_NAME_INPUT,
"0", /* hidden */
"1000", /* priority */
"window", /* type */
@@ -1888,7 +1934,7 @@ gui_bar_create_default_title ()
if (!ptr_bar)
{
/* create title bar */
- if (gui_bar_new (NULL, GUI_BAR_DEFAULT_NAME_TITLE,
+ if (gui_bar_new (GUI_BAR_DEFAULT_NAME_TITLE,
"0", /* hidden */
"500", /* priority */
"window", /* type */
@@ -1949,7 +1995,7 @@ gui_bar_create_default_status ()
gui_bar_item_names[GUI_BAR_ITEM_BUFFER_FILTER],
gui_bar_item_names[GUI_BAR_ITEM_COMPLETION],
gui_bar_item_names[GUI_BAR_ITEM_SCROLL]);
- if (gui_bar_new (NULL, GUI_BAR_DEFAULT_NAME_STATUS,
+ if (gui_bar_new (GUI_BAR_DEFAULT_NAME_STATUS,
"0", /* hidden */
"500", /* priority */
"window", /* type */
@@ -1987,7 +2033,7 @@ gui_bar_create_default_nicklist ()
if (!ptr_bar)
{
/* create nicklist bar */
- if (gui_bar_new (NULL, GUI_BAR_DEFAULT_NAME_NICKLIST,
+ if (gui_bar_new (GUI_BAR_DEFAULT_NAME_NICKLIST,
"0", /* hidden */
"200", /* priority */
"window", /* type */
@@ -2230,27 +2276,6 @@ gui_bar_free_all ()
}
/*
- * gui_bar_free_all_plugin: delete all bars for a plugin
- */
-
-void
-gui_bar_free_all_plugin (struct t_weechat_plugin *plugin)
-{
- struct t_gui_bar *ptr_bar, *next_bar;
-
- ptr_bar = gui_bars;
- while (ptr_bar)
- {
- next_bar = ptr_bar->next_bar;
-
- if (ptr_bar->plugin == plugin)
- gui_bar_free (ptr_bar);
-
- ptr_bar = next_bar;
- }
-}
-
-/*
* gui_bar_free_bar_windows: free bar windows for a bar
*/
@@ -2276,6 +2301,80 @@ gui_bar_free_bar_windows (struct t_gui_bar *bar)
}
/*
+ * gui_bar_add_to_infolist: add a bar in an infolist
+ * return 1 if ok, 0 if error
+ */
+
+int
+gui_bar_add_to_infolist (struct t_infolist *infolist,
+ struct t_gui_bar *bar)
+{
+ struct t_infolist_item *ptr_item;
+ int i;
+ char option_name[64];
+
+ if (!infolist || !bar)
+ return 0;
+
+ ptr_item = infolist_new_item (infolist);
+ if (!ptr_item)
+ return 0;
+
+ if (!infolist_new_var_integer (ptr_item, "hidden", CONFIG_INTEGER(bar->hidden)))
+ return 0;
+ if (!infolist_new_var_integer (ptr_item, "priority", CONFIG_INTEGER(bar->priority)))
+ return 0;
+ if (!infolist_new_var_integer (ptr_item, "type", CONFIG_INTEGER(bar->type)))
+ return 0;
+ if (!infolist_new_var_string (ptr_item, "conditions", CONFIG_STRING(bar->conditions)))
+ return 0;
+ if (!infolist_new_var_integer (ptr_item, "conditions_count", bar->conditions_count))
+ return 0;
+ for (i = 0; i < bar->conditions_count; i++)
+ {
+ snprintf (option_name, sizeof (option_name),
+ "conditions_array_%05d", i + 1);
+ if (!infolist_new_var_string (ptr_item, option_name,
+ bar->conditions_array[i]))
+ return 0;
+ }
+ if (!infolist_new_var_integer (ptr_item, "position", CONFIG_INTEGER(bar->position)))
+ return 0;
+ if (!infolist_new_var_integer (ptr_item, "filling_top_bottom", CONFIG_INTEGER(bar->filling_top_bottom)))
+ return 0;
+ if (!infolist_new_var_integer (ptr_item, "filling_left_right", CONFIG_INTEGER(bar->filling_left_right)))
+ return 0;
+ if (!infolist_new_var_integer (ptr_item, "size", CONFIG_INTEGER(bar->size)))
+ return 0;
+ if (!infolist_new_var_integer (ptr_item, "size_max", CONFIG_INTEGER(bar->size_max)))
+ return 0;
+ if (!infolist_new_var_string (ptr_item, "color_fg", gui_color_get_name (CONFIG_COLOR(bar->color_fg))))
+ return 0;
+ if (!infolist_new_var_string (ptr_item, "color_delim", gui_color_get_name (CONFIG_COLOR(bar->color_delim))))
+ return 0;
+ if (!infolist_new_var_string (ptr_item, "color_bg", gui_color_get_name (CONFIG_COLOR(bar->color_bg))))
+ return 0;
+ if (!infolist_new_var_integer (ptr_item, "separator", CONFIG_INTEGER(bar->separator)))
+ return 0;
+ if (!infolist_new_var_string (ptr_item, "items", CONFIG_STRING(bar->items)))
+ return 0;
+ if (!infolist_new_var_integer (ptr_item, "items_count", bar->items_count))
+ return 0;
+ for (i = 0; i < bar->items_count; i++)
+ {
+ snprintf (option_name, sizeof (option_name),
+ "items_array_%05d", i + 1);
+ if (!infolist_new_var_string (ptr_item, option_name,
+ bar->items_array[i]))
+ return 0;
+ }
+ if (!infolist_new_var_pointer (ptr_item, "bar_window", bar->bar_window))
+ return 0;
+
+ return 1;
+}
+
+/*
* gui_bar_print_log: print bar infos in log (usually for crash dump)
*/
@@ -2288,8 +2387,6 @@ gui_bar_print_log ()
{
log_printf ("");
log_printf ("[bar (addr:0x%lx)]", ptr_bar);
- log_printf (" plugin . . . . . . . . : 0x%lx ('%s')",
- ptr_bar->plugin, plugin_get_name (ptr_bar->plugin));
log_printf (" name . . . . . . . . . : '%s'", ptr_bar->name);
log_printf (" hidden . . . . . . . . : %d", CONFIG_INTEGER(ptr_bar->hidden));
log_printf (" priority . . . . . . . : %d", CONFIG_INTEGER(ptr_bar->priority));
diff --git a/src/gui/gui-bar.h b/src/gui/gui-bar.h
index a197b8778..38fe5865f 100644
--- a/src/gui/gui-bar.h
+++ b/src/gui/gui-bar.h
@@ -78,7 +78,6 @@ enum t_gui_bar_filling
struct t_gui_bar
{
/* user choices */
- struct t_weechat_plugin *plugin; /* plugin */
char *name; /* bar name */
struct t_config_option *hidden; /* true if bar is hidden */
struct t_config_option *priority; /* bar priority */
@@ -121,10 +120,13 @@ extern struct t_gui_bar *last_gui_temp_bar;
/* functions */
+extern int gui_bar_valid (struct t_gui_bar *bar);
extern int gui_bar_search_option (const char *option_name);
extern int gui_bar_search_type (const char *type);
extern int gui_bar_search_position (const char *position);
extern struct t_config_option *gui_bar_get_option_filling (struct t_gui_bar *bar);
+extern int gui_bar_get_item_index (struct t_gui_bar *bar,
+ const char *item_name);
extern int gui_bar_check_conditions_for_window (struct t_gui_bar *bar,
struct t_gui_window *window);
extern int gui_bar_root_get_size (struct t_gui_bar *bar,
@@ -136,8 +138,7 @@ extern int gui_bar_set (struct t_gui_bar *bar, const char *property, const char
extern void gui_bar_create_option_temp (struct t_gui_bar *temp_bar,
int index_option, const char *value);
extern struct t_gui_bar *gui_bar_alloc (const char *name);
-extern struct t_gui_bar *gui_bar_new (struct t_weechat_plugin *plugin,
- const char *name,
+extern struct t_gui_bar *gui_bar_new (const char *name,
const char *hidden,
const char *priority,
const char *type,
@@ -163,9 +164,9 @@ extern int gui_bar_scroll (struct t_gui_bar *bar, struct t_gui_buffer *buffer,
const char *scroll);
extern void gui_bar_free (struct t_gui_bar *bar);
extern void gui_bar_free_all ();
-extern void gui_bar_free_all_plugin (struct t_weechat_plugin *plugin);
extern void gui_bar_free_bar_windows (struct t_gui_bar *bar);
-extern void gui_bar_window_print_log (struct t_gui_bar_window *bar_window);
+extern int gui_bar_add_to_infolist (struct t_infolist *infolist,
+ struct t_gui_bar *bar);
extern void gui_bar_print_log ();
#endif /* gui-bar.h */
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c
index 70079814c..a3ce05be3 100644
--- a/src/gui/gui-buffer.c
+++ b/src/gui/gui-buffer.c
@@ -257,6 +257,7 @@ gui_buffer_new (struct t_weechat_plugin *plugin,
{
struct t_gui_buffer *new_buffer;
struct t_gui_completion *new_completion;
+ int first_buffer_creation;
if (!name)
return NULL;
@@ -363,24 +364,18 @@ gui_buffer_new (struct t_weechat_plugin *plugin,
gui_buffer_local_var_add (new_buffer, "name", name);
/* add buffer to buffers list */
+ first_buffer_creation = (gui_buffers == NULL);
gui_buffer_insert (new_buffer);
- /* first buffer creation ? */
- if (!gui_current_window->buffer)
- {
- gui_current_window->buffer = new_buffer;
- gui_current_window->first_line_displayed = 1;
- gui_current_window->start_line = NULL;
- gui_current_window->start_line_pos = 0;
- gui_window_switch_to_buffer (gui_current_window, new_buffer, 0);
- }
-
/* check if this buffer should be assigned to a window,
according to windows layout saved */
gui_layout_window_check_buffer (new_buffer);
-
- hook_signal_send ("buffer_open",
- WEECHAT_HOOK_SIGNAL_POINTER, new_buffer);
+
+ if (!first_buffer_creation)
+ {
+ hook_signal_send ("buffer_open",
+ WEECHAT_HOOK_SIGNAL_POINTER, new_buffer);
+ }
}
else
return NULL;
diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c
index 0c707903b..21d220775 100644
--- a/src/gui/gui-window.c
+++ b/src/gui/gui-window.c
@@ -129,7 +129,8 @@ gui_window_tree_free (struct t_gui_window_tree **tree)
*/
struct t_gui_window *
-gui_window_new (struct t_gui_window *parent, int x, int y, int width, int height,
+gui_window_new (struct t_gui_window *parent_window, struct t_gui_buffer *buffer,
+ int x, int y, int width, int height,
int width_pct, int height_pct)
{
struct t_gui_window *new_window;
@@ -141,7 +142,7 @@ gui_window_new (struct t_gui_window *parent, int x, int y, int width, int height
x, y, width, height);
#endif
- if (parent)
+ if (parent_window)
{
child1 = malloc (sizeof (*child1));
if (!child1)
@@ -152,7 +153,7 @@ gui_window_new (struct t_gui_window *parent, int x, int y, int width, int height
free (child1);
return NULL;
}
- ptr_tree = parent->ptr_tree;
+ ptr_tree = parent_window->ptr_tree;
if (width_pct == 100)
{
@@ -168,7 +169,7 @@ gui_window_new (struct t_gui_window *parent, int x, int y, int width, int height
/* parent window leaf becomes node and we add 2 leafs below
(#1 is parent win, #2 is new win) */
- parent->ptr_tree = child1;
+ parent_window->ptr_tree = child1;
child1->parent_node = ptr_tree;
child1->child1 = NULL;
child1->child2 = NULL;
@@ -225,7 +226,7 @@ gui_window_new (struct t_gui_window *parent, int x, int y, int width, int height
new_window->refresh_needed = 0;
/* buffer and layout infos */
- new_window->buffer = NULL;
+ new_window->buffer = buffer;
new_window->layout_plugin_name = NULL;
new_window->layout_buffer_name = NULL;
diff --git a/src/gui/gui-window.h b/src/gui/gui-window.h
index 37ad3da65..cee9340db 100644
--- a/src/gui/gui-window.h
+++ b/src/gui/gui-window.h
@@ -107,7 +107,8 @@ 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 struct t_gui_window *gui_window_new (struct t_gui_window *parent,
+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,
int width_pct, int height_pct);
extern int gui_window_valid (struct t_gui_window *window);