summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--po/POTFILES.in6
-rw-r--r--po/srcfiles.cmake6
-rw-r--r--src/gui/CMakeLists.txt1
-rw-r--r--src/gui/Makefile.am2
-rw-r--r--src/gui/curses/CMakeLists.txt10
-rw-r--r--src/gui/curses/Makefile.am2
-rw-r--r--src/gui/curses/gui-curses-bar-window.c706
-rw-r--r--src/gui/curses/gui-curses-bar.c1482
-rw-r--r--src/gui/curses/gui-curses-chat.c92
-rw-r--r--src/gui/curses/gui-curses-main.c5
-rw-r--r--src/gui/curses/gui-curses-window.c93
-rw-r--r--src/gui/curses/gui-curses.h38
-rw-r--r--src/gui/gtk/CMakeLists.txt10
-rw-r--r--src/gui/gtk/Makefile.am2
-rw-r--r--src/gui/gtk/gui-gtk-bar-window.c122
-rw-r--r--src/gui/gtk/gui-gtk-bar.c444
-rw-r--r--src/gui/gtk/gui-gtk-chat.c24
-rw-r--r--src/gui/gtk/gui-gtk-window.c71
-rw-r--r--src/gui/gtk/gui-gtk.h24
-rw-r--r--src/gui/gui-bar-window.c575
-rw-r--r--src/gui/gui-bar-window.h71
-rw-r--r--src/gui/gui-bar.c291
-rw-r--r--src/gui/gui-bar.h25
-rw-r--r--src/gui/gui-window.c22
-rw-r--r--src/gui/gui-window.h15
25 files changed, 1974 insertions, 2165 deletions
diff --git a/po/POTFILES.in b/po/POTFILES.in
index b4e0587f1..95a6f6a4b 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -34,14 +34,14 @@
./src/core/wee-utf8.h
./src/core/wee-util.c
./src/core/wee-util.h
-./src/gui/curses/gui-curses-bar.c
+./src/gui/curses/gui-curses-bar-window.c
./src/gui/curses/gui-curses-chat.c
./src/gui/curses/gui-curses-color.c
./src/gui/curses/gui-curses.h
./src/gui/curses/gui-curses-keyboard.c
./src/gui/curses/gui-curses-main.c
./src/gui/curses/gui-curses-window.c
-./src/gui/gtk/gui-gtk-bar.c
+./src/gui/gtk/gui-gtk-bar-window.c
./src/gui/gtk/gui-gtk-chat.c
./src/gui/gtk/gui-gtk-color.c
./src/gui/gtk/gui-gtk.h
@@ -52,6 +52,8 @@
./src/gui/gui-bar.h
./src/gui/gui-bar-item.c
./src/gui/gui-bar-item.h
+./src/gui/gui-bar-window.c
+./src/gui/gui-bar-window.h
./src/gui/gui-buffer.c
./src/gui/gui-buffer.h
./src/gui/gui-chat.c
diff --git a/po/srcfiles.cmake b/po/srcfiles.cmake
index 55d082d04..f482a6aa7 100644
--- a/po/srcfiles.cmake
+++ b/po/srcfiles.cmake
@@ -35,14 +35,14 @@ SET(WEECHAT_SOURCES
./src/core/wee-utf8.h
./src/core/wee-util.c
./src/core/wee-util.h
-./src/gui/curses/gui-curses-bar.c
+./src/gui/curses/gui-curses-bar-window.c
./src/gui/curses/gui-curses-chat.c
./src/gui/curses/gui-curses-color.c
./src/gui/curses/gui-curses.h
./src/gui/curses/gui-curses-keyboard.c
./src/gui/curses/gui-curses-main.c
./src/gui/curses/gui-curses-window.c
-./src/gui/gtk/gui-gtk-bar.c
+./src/gui/gtk/gui-gtk-bar-window.c
./src/gui/gtk/gui-gtk-chat.c
./src/gui/gtk/gui-gtk-color.c
./src/gui/gtk/gui-gtk.h
@@ -53,6 +53,8 @@ SET(WEECHAT_SOURCES
./src/gui/gui-bar.h
./src/gui/gui-bar-item.c
./src/gui/gui-bar-item.h
+./src/gui/gui-bar-window.c
+./src/gui/gui-bar-window.h
./src/gui/gui-buffer.c
./src/gui/gui-buffer.h
./src/gui/gui-chat.c
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt
index b2c7ea39e..3eee91224 100644
--- a/src/gui/CMakeLists.txt
+++ b/src/gui/CMakeLists.txt
@@ -17,6 +17,7 @@
SET(LIB_GUI_COMMON_SRC
gui-bar.c gui-bar.h
gui-bar-item.c gui-bar-item.h
+gui-bar-window.c gui-bar-window.h
gui-buffer.c gui-buffer.h
gui-chat.c gui-chat.h
gui-color.c gui-color.h
diff --git a/src/gui/Makefile.am b/src/gui/Makefile.am
index 203b85ff9..ddf960ae3 100644
--- a/src/gui/Makefile.am
+++ b/src/gui/Makefile.am
@@ -22,6 +22,8 @@ lib_weechat_gui_common_a_SOURCES = gui-bar.c \
gui-bar.h \
gui-bar-item.c \
gui-bar-item.h \
+ gui-bar-window.c \
+ gui-bar-window.h \
gui-buffer.c \
gui-buffer.h \
gui-chat.c \
diff --git a/src/gui/curses/CMakeLists.txt b/src/gui/curses/CMakeLists.txt
index d6be04071..22468b657 100644
--- a/src/gui/curses/CMakeLists.txt
+++ b/src/gui/curses/CMakeLists.txt
@@ -18,8 +18,14 @@ if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
-SET(WEECHAT_CURSES_SRC gui-curses-bar.c gui-curses-chat.c gui-curses-color.c
-gui-curses-keyboard.c gui-curses-main.c gui-curses-window.c gui-curses.h)
+SET(WEECHAT_CURSES_SRC
+gui-curses.h
+gui-curses-bar-window.c
+gui-curses-chat.c
+gui-curses-color.c
+gui-curses-keyboard.c
+gui-curses-main.c
+gui-curses-window.c)
SET(EXECUTABLE weechat-curses)
diff --git a/src/gui/curses/Makefile.am b/src/gui/curses/Makefile.am
index 8ea78e799..7cc33426f 100644
--- a/src/gui/curses/Makefile.am
+++ b/src/gui/curses/Makefile.am
@@ -28,7 +28,7 @@ weechat_curses_LDADD = ./../../core/lib_weechat_core.a \
$(NCURSES_LFLAGS) \
$(GNUTLS_LFLAGS)
-weechat_curses_SOURCES = gui-curses-bar.c \
+weechat_curses_SOURCES = gui-curses-bar-window.c \
gui-curses-chat.c \
gui-curses-color.c \
gui-curses-keyboard.c \
diff --git a/src/gui/curses/gui-curses-bar-window.c b/src/gui/curses/gui-curses-bar-window.c
new file mode 100644
index 000000000..dc95050e1
--- /dev/null
+++ b/src/gui/curses/gui-curses-bar-window.c
@@ -0,0 +1,706 @@
+/*
+ * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* gui-curses-bar-window.c: bar window functions for Curses GUI */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <limits.h>
+
+#include "../../core/weechat.h"
+#include "../../core/wee-config.h"
+#include "../../core/wee-log.h"
+#include "../../core/wee-string.h"
+#include "../../core/wee-utf8.h"
+#include "../gui-bar.h"
+#include "../gui-bar-item.h"
+#include "../gui-bar-window.h"
+#include "../gui-chat.h"
+#include "../gui-color.h"
+#include "../gui-window.h"
+#include "gui-curses.h"
+
+
+/*
+ * gui_bar_window_objects_init: init Curses windows for bar window
+ */
+
+int
+gui_bar_window_objects_init (struct t_gui_bar_window *bar_window)
+{
+ struct t_gui_bar_window_curses_objects *new_objects;
+
+ new_objects = malloc (sizeof (*new_objects));
+ if (new_objects)
+ {
+ bar_window->gui_objects = new_objects;
+ GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar = NULL;
+ GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator = NULL;
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ * gui_window_objects_free: free Curses windows for a bar window
+ */
+
+void
+gui_bar_window_objects_free (struct t_gui_bar_window *bar_window)
+{
+ if (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar)
+ {
+ delwin (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar);
+ GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar = NULL;
+ }
+ if (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator)
+ {
+ delwin (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator);
+ GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator = NULL;
+ }
+}
+
+/*
+ * gui_bar_window_create_win: create curses window for bar
+ */
+
+void
+gui_bar_window_create_win (struct t_gui_bar_window *bar_window)
+{
+ if (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar)
+ {
+ delwin (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar);
+ GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar = NULL;
+ }
+ if (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator)
+ {
+ delwin (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator);
+ GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator = NULL;
+ }
+
+ GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar = newwin (bar_window->height,
+ bar_window->width,
+ bar_window->y,
+ bar_window->x);
+
+ if (CONFIG_INTEGER(bar_window->bar->separator))
+ {
+ switch (CONFIG_INTEGER(bar_window->bar->position))
+ {
+ case GUI_BAR_POSITION_BOTTOM:
+ GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator = newwin (1,
+ bar_window->width,
+ bar_window->y - 1,
+ bar_window->x);
+ break;
+ case GUI_BAR_POSITION_TOP:
+ GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator = newwin (1,
+ bar_window->width,
+ bar_window->y + bar_window->height,
+ bar_window->x);
+ break;
+ case GUI_BAR_POSITION_LEFT:
+ GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator = newwin (bar_window->height,
+ 1,
+ bar_window->y,
+ bar_window->x + bar_window->width);
+ break;
+ case GUI_BAR_POSITION_RIGHT:
+ GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator = newwin (bar_window->height,
+ 1,
+ bar_window->y,
+ bar_window->x - 1);
+ break;
+ case GUI_BAR_NUM_POSITIONS:
+ break;
+ }
+ }
+}
+
+/*
+ * gui_bar_window_print_string: print a string text on a bar window
+ * return 1 if all was printed, 0 if some text
+ * was not displayed (wrapped due to bar window
+ * width)
+ */
+
+int
+gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
+ int *x, int *y,
+ const char *string,
+ int reset_color_before_display)
+{
+ int weechat_color, x_with_hidden, size_on_screen, fg, bg, low_char;
+ char str_fg[3], str_bg[3], utf_char[16], *next_char, *output;
+
+ if (!string || !string[0])
+ return 1;
+
+ wmove (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, *y, *x);
+
+ if (reset_color_before_display)
+ {
+ gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ CONFIG_COLOR(bar_window->bar->color_fg),
+ CONFIG_COLOR(bar_window->bar->color_bg));
+ }
+
+ x_with_hidden = *x;
+
+ while (string && string[0])
+ {
+ if (string[0] == GUI_COLOR_COLOR_CHAR)
+ {
+ string++;
+ switch (string[0])
+ {
+ case GUI_COLOR_FG_CHAR: /* fg color */
+ if (string[1] && string[2])
+ {
+ str_fg[0] = string[1];
+ str_fg[1] = string[2];
+ str_fg[2] = '\0';
+ sscanf (str_fg, "%d", &fg);
+ gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ fg);
+ string += 3;
+ }
+ break;
+ case GUI_COLOR_BG_CHAR: /* bg color */
+ if (string[1] && string[2])
+ {
+ str_bg[0] = string[1];
+ str_bg[1] = string[2];
+ str_bg[2] = '\0';
+ sscanf (str_bg, "%d", &bg);
+ gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ bg);
+ string += 3;
+ }
+ break;
+ case GUI_COLOR_FG_BG_CHAR: /* fg + bg color */
+ if (string[1] && string[2] && (string[3] == ',')
+ && string[4] && string[5])
+ {
+ str_fg[0] = string[1];
+ str_fg[1] = string[2];
+ str_fg[2] = '\0';
+ str_bg[0] = string[4];
+ str_bg[1] = string[5];
+ str_bg[2] = '\0';
+ sscanf (str_fg, "%d", &fg);
+ sscanf (str_bg, "%d", &bg);
+ gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ fg, bg);
+ string += 6;
+ }
+ break;
+ case GUI_COLOR_BAR_CHAR: /* bar color */
+ switch (string[1])
+ {
+ case GUI_COLOR_BAR_FG_CHAR:
+ /* bar foreground */
+ gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ CONFIG_INTEGER(bar_window->bar->color_fg));
+ string += 2;
+ break;
+ case GUI_COLOR_BAR_DELIM_CHAR:
+ /* bar delimiter */
+ gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ CONFIG_INTEGER(bar_window->bar->color_delim));
+ string += 2;
+ break;
+ case GUI_COLOR_BAR_BG_CHAR:
+ /* bar background */
+ gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ CONFIG_INTEGER(bar_window->bar->color_bg));
+ string += 2;
+ break;
+ case GUI_COLOR_BAR_MOVE_CURSOR_CHAR:
+ /* move cursor to current position on screen */
+ getyx (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ bar_window->cursor_y, bar_window->cursor_x);
+ bar_window->cursor_x += bar_window->x;
+ bar_window->cursor_y += bar_window->y;
+ string += 2;
+ break;
+ default:
+ string++;
+ break;
+ }
+ break;
+ default:
+ if (isdigit (string[0]) && isdigit (string[1]))
+ {
+ str_fg[0] = string[0];
+ str_fg[1] = string[1];
+ str_fg[2] = '\0';
+ sscanf (str_fg, "%d", &weechat_color);
+ gui_window_set_weechat_color (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ weechat_color);
+ string += 2;
+ }
+ break;
+ }
+ }
+ else
+ {
+ next_char = utf8_next_char (string);
+ if (!next_char)
+ break;
+
+ memcpy (utf_char, string, next_char - string);
+ utf_char[next_char - string] = '\0';
+
+ if ((((unsigned char)utf_char[0]) < 32) && (!utf_char[1]))
+ {
+ low_char = 1;
+ snprintf (utf_char, sizeof (utf_char), "%c",
+ 'A' + ((unsigned char)utf_char[0]) - 1);
+ }
+ else
+ {
+ low_char = 0;
+ if (!gui_window_utf_char_valid (utf_char))
+ snprintf (utf_char, sizeof (utf_char), ".");
+ }
+
+ size_on_screen = utf8_char_size_screen (utf_char);
+ if (size_on_screen > 0)
+ {
+ if (x_with_hidden < bar_window->scroll_x)
+ {
+ /* hidden char (before scroll_x value) */
+ x_with_hidden++;
+ }
+ else
+ {
+ if (*x + size_on_screen > bar_window->width)
+ {
+ if (CONFIG_INTEGER(gui_bar_get_option_filling (bar_window->bar)) == GUI_BAR_FILLING_VERTICAL)
+ return 0;
+ if (*y >= bar_window->height - 1)
+ return 0;
+ *x = 0;
+ (*y)++;
+ wmove (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, *y, *x);
+ }
+
+ output = string_iconv_from_internal (NULL, utf_char);
+ if (low_char)
+ wattron (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, A_REVERSE);
+ wprintw (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, "%s",
+ (output) ? output : utf_char);
+ if (low_char)
+ wattroff (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, A_REVERSE);
+ if (output)
+ free (output);
+
+ *x += size_on_screen;
+ }
+ }
+
+ string = next_char;
+ }
+ }
+ return 1;
+}
+
+/*
+ * gui_bar_window_draw: draw a bar for a window
+ */
+
+void
+gui_bar_window_draw (struct t_gui_bar_window *bar_window,
+ struct t_gui_window *window)
+{
+ int x, y, i, items_count, num_lines, line;
+ char *content, *item_value, *item_value2, **items;
+ char space_with_reinit_color[32];
+ int length_reinit_color, content_length, length, length_on_screen;
+ int max_length, optimal_number_of_lines, chars_available;
+ int some_data_not_displayed;
+
+ if (!gui_init_ok)
+ return;
+
+ snprintf (space_with_reinit_color,
+ sizeof (space_with_reinit_color),
+ "%c%c%02d,%02d ",
+ GUI_COLOR_COLOR_CHAR,
+ GUI_COLOR_FG_BG_CHAR,
+ CONFIG_COLOR(bar_window->bar->color_fg),
+ CONFIG_COLOR(bar_window->bar->color_bg));
+ length_reinit_color = strlen (space_with_reinit_color);
+
+ /* these values will be overwritten later (by gui_bar_window_print_string)
+ if cursor has to move somewhere in bar window */
+ bar_window->cursor_x = -1;
+ bar_window->cursor_y = -1;
+
+ if (CONFIG_INTEGER(bar_window->bar->size) == 0)
+ {
+ content = NULL;
+ content_length = 1;
+ for (i = 0; i < bar_window->bar->items_count; i++)
+ {
+ item_value = gui_bar_item_get_value (bar_window->bar->items_array[i],
+ bar_window->bar, window,
+ 0, 0, 0);
+ if (item_value)
+ {
+ if (item_value[0])
+ {
+ if (CONFIG_INTEGER(gui_bar_get_option_filling (bar_window->bar)) == GUI_BAR_FILLING_HORIZONTAL)
+ {
+ item_value2 = string_replace (item_value, "\n",
+ space_with_reinit_color);
+ }
+ else
+ item_value2 = NULL;
+ if (!content)
+ {
+ content_length += strlen ((item_value2) ?
+ item_value2 : item_value);
+ content = strdup ((item_value2) ?
+ item_value2 : item_value);
+ }
+ else
+ {
+ content_length += length_reinit_color +
+ strlen ((item_value2) ? item_value2 : item_value);
+ content = realloc (content, content_length);
+ if (CONFIG_INTEGER(gui_bar_get_option_filling (bar_window->bar)) == GUI_BAR_FILLING_HORIZONTAL)
+ strcat (content, space_with_reinit_color);
+ else
+ strcat (content, "\n");
+ strcat (content,
+ (item_value2) ? item_value2 : item_value);
+ }
+ if (item_value2)
+ free (item_value2);
+ }
+ free (item_value);
+ }
+ }
+ if (content)
+ {
+ items = string_explode (content, "\n", 0, 0, &items_count);
+ if (items_count == 0)
+ {
+ gui_bar_window_set_current_size (bar_window->bar, 1);
+ gui_window_clear (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ CONFIG_COLOR(bar_window->bar->color_bg));
+ }
+ else
+ {
+ /* search longer line and optimal number of lines */
+ max_length = 0;
+ optimal_number_of_lines = 0;
+ for (line = 0; line < items_count; line++)
+ {
+ length_on_screen = gui_chat_strlen_screen (items[line]);
+
+ length = strlen (items[line]);
+ if ((length >= 3)
+ && (items[line][length - 3] == GUI_COLOR_COLOR_CHAR)
+ && (items[line][length - 2] == GUI_COLOR_BAR_CHAR)
+ && (items[line][length - 1] == GUI_COLOR_BAR_MOVE_CURSOR_CHAR))
+ length_on_screen++;
+
+ if (length_on_screen > max_length)
+ max_length = length_on_screen;
+
+ if (length_on_screen % bar_window->width == 0)
+ num_lines = length_on_screen / bar_window->width;
+ else
+ num_lines = (length_on_screen / bar_window->width) + 1;
+ if (num_lines == 0)
+ num_lines = 1;
+ optimal_number_of_lines += num_lines;
+ }
+ if (max_length == 0)
+ max_length = 1;
+
+ switch (CONFIG_INTEGER(bar_window->bar->position))
+ {
+ case GUI_BAR_POSITION_BOTTOM:
+ case GUI_BAR_POSITION_TOP:
+ if (CONFIG_INTEGER(gui_bar_get_option_filling (bar_window->bar)) == GUI_BAR_FILLING_HORIZONTAL)
+ num_lines = optimal_number_of_lines;
+ else
+ num_lines = items_count;
+ gui_bar_window_set_current_size (bar_window->bar,
+ num_lines);
+ break;
+ case GUI_BAR_POSITION_LEFT:
+ case GUI_BAR_POSITION_RIGHT:
+ gui_bar_window_set_current_size (bar_window->bar,
+ max_length);
+ break;
+ case GUI_BAR_NUM_POSITIONS:
+ break;
+ }
+ gui_window_clear (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ CONFIG_COLOR(bar_window->bar->color_bg));
+ x = 0;
+ y = 0;
+ some_data_not_displayed = 0;
+ if ((bar_window->scroll_y > 0)
+ && (bar_window->scroll_y >= items_count))
+ {
+ bar_window->scroll_y = items_count - bar_window->height;
+ if (bar_window->scroll_y < 0)
+ bar_window->scroll_y = 0;
+ }
+ for (line = 0;
+ (line < items_count) && (y < bar_window->height);
+ line++)
+ {
+ if ((bar_window->scroll_y == 0)
+ || (line >= bar_window->scroll_y))
+ {
+ if (!gui_bar_window_print_string (bar_window, &x, &y,
+ items[line], 1))
+ {
+ some_data_not_displayed = 1;
+ }
+ if (CONFIG_INTEGER(gui_bar_get_option_filling (bar_window->bar)) == GUI_BAR_FILLING_VERTICAL)
+ {
+ while (x < bar_window->width)
+ {
+ gui_bar_window_print_string (bar_window,
+ &x, &y,
+ " ", 0);
+ }
+ x = 0;
+ y++;
+ }
+ else
+ {
+ gui_bar_window_print_string (bar_window, &x, &y,
+ space_with_reinit_color, 0);
+ }
+ }
+ }
+ if ((bar_window->cursor_x < 0) && (bar_window->cursor_y < 0)
+ && ((bar_window->scroll_x > 0) || (bar_window->scroll_y > 0)))
+ {
+ x = (bar_window->height > 1) ? bar_window->width - 2 : 0;
+ if (x < 0)
+ x = 0;
+ y = 0;
+ gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ CONFIG_COLOR(config_color_bar_more),
+ CONFIG_INTEGER(bar_window->bar->color_bg));
+ mvwprintw (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, y, x, "--");
+ }
+ if ((bar_window->cursor_x < 0) && (bar_window->cursor_y < 0)
+ && (some_data_not_displayed || (line < items_count)))
+ {
+ x = bar_window->width - 2;
+ if (x < 0)
+ x = 0;
+ y = (bar_window->height > 1) ? bar_window->height - 1 : 0;
+ gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ CONFIG_COLOR(config_color_bar_more),
+ CONFIG_INTEGER(bar_window->bar->color_bg));
+ mvwprintw (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, y, x, "++");
+ }
+ }
+ if (items)
+ string_free_exploded (items);
+ free (content);
+ }
+ else
+ {
+ gui_bar_window_set_current_size (bar_window->bar, 1);
+ gui_window_clear (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ CONFIG_COLOR(bar_window->bar->color_bg));
+ }
+ }
+ else
+ {
+ gui_window_clear (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ CONFIG_COLOR(bar_window->bar->color_bg));
+
+ x = 0;
+ y = 0;
+
+ for (i = 0; i < bar_window->bar->items_count; i++)
+ {
+ chars_available =
+ ((bar_window->height - y - 1) * bar_window->width) + /* next lines */
+ (bar_window->width - x - 1); /* chars on current line */
+
+ item_value = gui_bar_item_get_value (bar_window->bar->items_array[i],
+ bar_window->bar, window,
+ bar_window->width,
+ bar_window->height,
+ chars_available);
+ if (item_value)
+ {
+ if (item_value[0])
+ {
+ if (CONFIG_INTEGER(gui_bar_get_option_filling (bar_window->bar)) == GUI_BAR_FILLING_HORIZONTAL)
+ {
+ item_value2 = string_replace (item_value, "\n",
+ space_with_reinit_color);
+ }
+ else
+ item_value2 = NULL;
+ items = string_explode ((item_value2) ?
+ item_value2 : item_value,
+ "\n", 0, 0,
+ &items_count);
+ some_data_not_displayed = 0;
+ if ((bar_window->scroll_y > 0)
+ && (bar_window->scroll_y >= items_count))
+ {
+ bar_window->scroll_y = items_count - bar_window->height;
+ if (bar_window->scroll_y < 0)
+ bar_window->scroll_y = 0;
+ }
+ for (line = 0;
+ (line < items_count) && (y < bar_window->height);
+ line++)
+ {
+ if ((bar_window->scroll_y == 0)
+ || (line >= bar_window->scroll_y))
+ {
+ if (!gui_bar_window_print_string (bar_window, &x, &y,
+ items[line], 1))
+ {
+ some_data_not_displayed = 1;
+ }
+ if (CONFIG_INTEGER(gui_bar_get_option_filling (bar_window->bar)) == GUI_BAR_FILLING_VERTICAL)
+ {
+ while (x < bar_window->width)
+ {
+ gui_bar_window_print_string (bar_window,
+ &x, &y,
+ " ", 0);
+ }
+ x = 0;
+ y++;
+ }
+ else
+ {
+ gui_bar_window_print_string (bar_window, &x, &y,
+ space_with_reinit_color, 0);
+ }
+ }
+ }
+ if ((bar_window->cursor_x < 0) && (bar_window->cursor_y < 0)
+ && ((bar_window->scroll_x > 0) || (bar_window->scroll_y > 0)))
+ {
+ x = (bar_window->height > 1) ? bar_window->width - 2 : 0;
+ if (x < 0)
+ x = 0;
+ y = 0;
+ gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ CONFIG_COLOR(config_color_bar_more),
+ CONFIG_INTEGER(bar_window->bar->color_bg));
+ mvwprintw (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, y, x, "--");
+ }
+ if ((bar_window->cursor_x < 0) && (bar_window->cursor_y < 0)
+ && (some_data_not_displayed || (line < items_count)))
+ {
+ x = bar_window->width - 2;
+ if (x < 0)
+ x = 0;
+ y = (bar_window->height > 1) ? bar_window->height - 1 : 0;
+ gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ CONFIG_COLOR(config_color_bar_more),
+ CONFIG_INTEGER(bar_window->bar->color_bg));
+ mvwprintw (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, y, x, "++");
+ }
+ if (item_value2)
+ free (item_value2);
+ if (items)
+ string_free_exploded (items);
+ }
+ free (item_value);
+ }
+ }
+ }
+
+ /* move cursor if it was asked in an item content (input_text does that
+ to move cursor in user input text) */
+ if (window && (gui_current_window == window)
+ && (bar_window->cursor_x >= 0) && (bar_window->cursor_y >= 0))
+ {
+ move (bar_window->cursor_y, bar_window->cursor_x);
+ }
+
+ wnoutrefresh (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar);
+
+ if (CONFIG_INTEGER(bar_window->bar->separator))
+ {
+ switch (CONFIG_INTEGER(bar_window->bar->position))
+ {
+ case GUI_BAR_POSITION_BOTTOM:
+ gui_window_set_weechat_color (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
+ GUI_COLOR_SEPARATOR);
+ mvwhline (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator, 0, 0, ACS_HLINE,
+ bar_window->width);
+ break;
+ case GUI_BAR_POSITION_TOP:
+ gui_window_set_weechat_color (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
+ GUI_COLOR_SEPARATOR);
+ mvwhline (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
+ 0, 0, ACS_HLINE, bar_window->width);
+ break;
+ case GUI_BAR_POSITION_LEFT:
+ gui_window_set_weechat_color (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
+ GUI_COLOR_SEPARATOR);
+ mvwvline (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
+ 0, 0, ACS_VLINE, bar_window->height);
+ break;
+ case GUI_BAR_POSITION_RIGHT:
+ gui_window_set_weechat_color (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
+ GUI_COLOR_SEPARATOR);
+ mvwvline (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
+ 0, 0, ACS_VLINE, bar_window->height);
+ break;
+ case GUI_BAR_NUM_POSITIONS:
+ break;
+ }
+ wnoutrefresh (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator);
+ }
+
+ refresh ();
+}
+
+/*
+ * gui_bar_window_objects_print_log: print bar window infos in log (usually for crash dump)
+ */
+
+void
+gui_bar_window_objects_print_log (struct t_gui_bar_window *bar_window)
+{
+ log_printf (" bar window specific objects for Curses:");
+ log_printf (" win_bar . . . . . . : 0x%lx", GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar);
+ log_printf (" win_separator . . . : 0x%lx", GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator);
+}
diff --git a/src/gui/curses/gui-curses-bar.c b/src/gui/curses/gui-curses-bar.c
deleted file mode 100644
index 98032984f..000000000
--- a/src/gui/curses/gui-curses-bar.c
+++ /dev/null
@@ -1,1482 +0,0 @@
-/*
- * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org>
- * See README for License detail, AUTHORS for developers list.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* gui-curses-bar.c: bar functions for Curses GUI */
-
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <limits.h>
-
-#include "../../core/weechat.h"
-#include "../../core/wee-config.h"
-#include "../../core/wee-log.h"
-#include "../../core/wee-string.h"
-#include "../../core/wee-utf8.h"
-#include "../gui-bar.h"
-#include "../gui-bar-item.h"
-#include "../gui-chat.h"
-#include "../gui-color.h"
-#include "../gui-window.h"
-#include "gui-curses.h"
-
-
-/*
- * gui_bar_window_search_bar: search a reference to a bar in a window
- */
-
-struct t_gui_bar_window *
-gui_bar_window_search_bar (struct t_gui_window *window, struct t_gui_bar *bar)
-{
- struct t_gui_bar_window *ptr_bar_win;
-
- for (ptr_bar_win = GUI_CURSES(window)->bar_windows; ptr_bar_win;
- ptr_bar_win = ptr_bar_win->next_bar_window)
- {
- if (ptr_bar_win->bar == bar)
- return ptr_bar_win;
- }
-
- /* bar window not found for window */
- return NULL;
-}
-
-/*
- * gui_bar_window_get_size: get total bar size (window bars) for a position
- * bar is optional, if not NULL, size is computed
- * from bar 1 to bar # - 1
- */
-
-int
-gui_bar_window_get_size (struct t_gui_bar *bar, struct t_gui_window *window,
- enum t_gui_bar_position position)
-{
- struct t_gui_bar_window *ptr_bar_window;
- int total_size;
-
- total_size = 0;
- for (ptr_bar_window = GUI_CURSES(window)->bar_windows; ptr_bar_window;
- ptr_bar_window = ptr_bar_window->next_bar_window)
- {
- /* stop before bar */
- if (bar && (ptr_bar_window->bar == bar))
- return total_size;
-
- if (!CONFIG_BOOLEAN(ptr_bar_window->bar->hidden))
- {
- if ((CONFIG_INTEGER(ptr_bar_window->bar->type) != GUI_BAR_TYPE_ROOT)
- && (CONFIG_INTEGER(ptr_bar_window->bar->position) == (int)position))
- {
- switch (position)
- {
- case GUI_BAR_POSITION_BOTTOM:
- case GUI_BAR_POSITION_TOP:
- total_size += ptr_bar_window->height;
- break;
- case GUI_BAR_POSITION_LEFT:
- case GUI_BAR_POSITION_RIGHT:
- total_size += ptr_bar_window->width;
- break;
- case GUI_BAR_NUM_POSITIONS:
- break;
- }
- if (CONFIG_INTEGER(ptr_bar_window->bar->separator))
- total_size++;
- }
- }
- }
- return total_size;
-}
-
-/*
- * gui_bar_get_min_width: return minimum width of a bar window displayed for
- * a bar
- * for example, if a bar is displayed in 3 windows,
- * this function return min width of these 3 bar windows
- */
-
-int
-gui_bar_get_min_width (struct t_gui_bar *bar)
-{
- struct t_gui_window *ptr_win;
- struct t_gui_bar_window *ptr_bar_win;
- int min_width;
-
- if (CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_ROOT)
- return bar->bar_window->width;
-
- min_width = INT_MAX;
- for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
- {
- for (ptr_bar_win = GUI_CURSES(ptr_win)->bar_windows;
- ptr_bar_win; ptr_bar_win = ptr_bar_win->next_bar_window)
- {
- if (ptr_bar_win->bar == bar)
- {
- if (ptr_bar_win->width < min_width)
- min_width = ptr_bar_win->width;
- }
- }
- }
-
- if (min_width == INT_MAX)
- return 0;
-
- return min_width;
-}
-
-/*
- * gui_bar_get_min_height: return minimum height of a bar window displayed for
- * a bar
- * for example, if a bar is displayed in 3 windows,
- * this function return min width of these 3 bar windows
- */
-
-int
-gui_bar_get_min_height (struct t_gui_bar *bar)
-{
- struct t_gui_window *ptr_win;
- struct t_gui_bar_window *ptr_bar_win;
- int min_height;
-
- if (CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_ROOT)
- return bar->bar_window->height;
-
- min_height = INT_MAX;
- for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
- {
- for (ptr_bar_win = GUI_CURSES(ptr_win)->bar_windows;
- ptr_bar_win; ptr_bar_win = ptr_bar_win->next_bar_window)
- {
- if (ptr_bar_win->bar == bar)
- {
- if (ptr_bar_win->height < min_height)
- min_height = ptr_bar_win->height;
- }
- }
- }
-
- if (min_height == INT_MAX)
- return 0;
-
- return min_height;
-}
-
-/*
- * gui_bar_check_size_add: check if "add_size" is ok for bar
- * return 1 if new size is ok
- * 0 if new size is too big
- */
-
-int
-gui_bar_check_size_add (struct t_gui_bar *bar, int add_size)
-{
- struct t_gui_window *ptr_win;
- int sub_width, sub_height;
-
- sub_width = 0;
- sub_height = 0;
-
- switch (CONFIG_INTEGER(bar->position))
- {
- case GUI_BAR_POSITION_BOTTOM:
- case GUI_BAR_POSITION_TOP:
- sub_height = add_size;
- break;
- case GUI_BAR_POSITION_LEFT:
- case GUI_BAR_POSITION_RIGHT:
- sub_width = add_size;
- break;
- case GUI_BAR_NUM_POSITIONS:
- break;
- }
-
- for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
- {
- if ((CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_ROOT)
- || (gui_bar_window_search_bar (ptr_win, bar)))
- {
- if ((ptr_win->win_chat_width - sub_width < GUI_WINDOW_CHAT_MIN_WIDTH)
- || (ptr_win->win_chat_height - sub_height < GUI_WINDOW_CHAT_MIN_HEIGHT))
- return 0;
- }
- }
-
- /* new size ok */
- return 1;
-}
-
-/*
- * gui_bar_window_calculate_pos_size: calculate position and size of a bar
- */
-
-void
-gui_bar_window_calculate_pos_size (struct t_gui_bar_window *bar_window,
- struct t_gui_window *window)
-{
- int x1, y1, x2, y2;
- int add_bottom, add_top, add_left, add_right;
-
- if (window)
- {
- x1 = window->win_x;
- y1 = window->win_y;
- x2 = x1 + window->win_width - 1;
- y2 = y1 + window->win_height - 1;
- add_bottom = gui_bar_window_get_size (bar_window->bar, window, GUI_BAR_POSITION_BOTTOM);
- add_top = gui_bar_window_get_size (bar_window->bar, window, GUI_BAR_POSITION_TOP);
- add_left = gui_bar_window_get_size (bar_window->bar, window, GUI_BAR_POSITION_LEFT);
- add_right = gui_bar_window_get_size (bar_window->bar, window, GUI_BAR_POSITION_RIGHT);
- }
- else
- {
- x1 = 0;
- y1 = 0;
- x2 = gui_window_get_width () - 1;
- y2 = gui_window_get_height () - 1;
- add_bottom = gui_bar_root_get_size (bar_window->bar, GUI_BAR_POSITION_BOTTOM);
- add_top = gui_bar_root_get_size (bar_window->bar, GUI_BAR_POSITION_TOP);
- add_left = gui_bar_root_get_size (bar_window->bar, GUI_BAR_POSITION_LEFT);
- add_right = gui_bar_root_get_size (bar_window->bar, GUI_BAR_POSITION_RIGHT);
- }
-
- switch (CONFIG_INTEGER(bar_window->bar->position))
- {
- case GUI_BAR_POSITION_BOTTOM:
- bar_window->x = x1 + add_left;
- bar_window->y = y2 - add_bottom - bar_window->current_size + 1;
- bar_window->width = x2 - x1 + 1 - add_left - add_right;
- bar_window->height = bar_window->current_size;
- break;
- case GUI_BAR_POSITION_TOP:
- bar_window->x = x1 + add_left;
- bar_window->y = y1 + add_top;
- bar_window->width = x2 - x1 + 1 - add_left - add_right;
- bar_window->height = bar_window->current_size;
- break;
- case GUI_BAR_POSITION_LEFT:
- bar_window->x = x1 + add_left;
- bar_window->y = y1 + add_top;
- bar_window->width = bar_window->current_size;
- bar_window->height = y2 - y1 + 1 - add_top - add_bottom;
- break;
- case GUI_BAR_POSITION_RIGHT:
- bar_window->x = x2 - add_right - bar_window->current_size + 1;
- bar_window->y = y1 + add_top;
- bar_window->width = bar_window->current_size;
- bar_window->height = y2 - y1 + 1 - add_top - add_bottom;
- break;
- case GUI_BAR_NUM_POSITIONS:
- break;
- }
-}
-
-/*
- * gui_bar_window_create_win: create curses window for bar
- */
-
-void
-gui_bar_window_create_win (struct t_gui_bar_window *bar_window)
-{
- if (bar_window->win_bar)
- {
- delwin (bar_window->win_bar);
- bar_window->win_bar = NULL;
- }
- if (bar_window->win_separator)
- {
- delwin (bar_window->win_separator);
- bar_window->win_separator = NULL;
- }
-
- bar_window->win_bar = newwin (bar_window->height,
- bar_window->width,
- bar_window->y,
- bar_window->x);
-
- if (CONFIG_INTEGER(bar_window->bar->separator))
- {
- switch (CONFIG_INTEGER(bar_window->bar->position))
- {
- case GUI_BAR_POSITION_BOTTOM:
- bar_window->win_separator = newwin (1,
- bar_window->width,
- bar_window->y - 1,
- bar_window->x);
- break;
- case GUI_BAR_POSITION_TOP:
- bar_window->win_separator = newwin (1,
- bar_window->width,
- bar_window->y + bar_window->height,
- bar_window->x);
- break;
- case GUI_BAR_POSITION_LEFT:
- bar_window->win_separator = newwin (bar_window->height,
- 1,
- bar_window->y,
- bar_window->x + bar_window->width);
- break;
- case GUI_BAR_POSITION_RIGHT:
- bar_window->win_separator = newwin (bar_window->height,
- 1,
- bar_window->y,
- bar_window->x - 1);
- break;
- case GUI_BAR_NUM_POSITIONS:
- break;
- }
- }
-}
-
-/*
- * gui_bar_window_find_pos: find position for bar window (keeping list sorted
- * by bar priority)
- */
-
-struct t_gui_bar_window *
-gui_bar_window_find_pos (struct t_gui_bar *bar, struct t_gui_window *window)
-{
- struct t_gui_bar_window *ptr_bar_window;
-
- for (ptr_bar_window = GUI_CURSES(window)->bar_windows; ptr_bar_window;
- ptr_bar_window = ptr_bar_window->next_bar_window)
- {
- if (CONFIG_INTEGER(bar->priority) >= CONFIG_INTEGER(ptr_bar_window->bar->priority))
- return ptr_bar_window;
- }
-
- /* position not found, best position is at the end */
- return NULL;
-}
-
-/*
- * 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
- */
-
-int
-gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window)
-{
- struct t_gui_bar_window *new_bar_window, *pos_bar_window;
-
- if (window)
- {
- if ((CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_WINDOW)
- && (!gui_bar_check_conditions_for_window (bar, window)))
- return 1;
- }
-
- new_bar_window = malloc (sizeof (*new_bar_window));
- if (new_bar_window)
- {
- new_bar_window->bar = bar;
- if (window)
- {
- bar->bar_window = NULL;
- if (GUI_CURSES(window)->bar_windows)
- {
- pos_bar_window = gui_bar_window_find_pos (bar, window);
- if (pos_bar_window)
- {
- /* insert before bar window found */
- new_bar_window->prev_bar_window = pos_bar_window->prev_bar_window;
- new_bar_window->next_bar_window = pos_bar_window;
- if (pos_bar_window->prev_bar_window)
- (pos_bar_window->prev_bar_window)->next_bar_window = new_bar_window;
- else
- GUI_CURSES(window)->bar_windows = new_bar_window;
- pos_bar_window->prev_bar_window = new_bar_window;
- }
- else
- {
- /* add to end of list for window */
- new_bar_window->prev_bar_window = GUI_CURSES(window)->last_bar_window;
- new_bar_window->next_bar_window = NULL;
- (GUI_CURSES(window)->last_bar_window)->next_bar_window = new_bar_window;
- GUI_CURSES(window)->last_bar_window = new_bar_window;
- }
- }
- else
- {
- new_bar_window->prev_bar_window = NULL;
- new_bar_window->next_bar_window = NULL;
- GUI_CURSES(window)->bar_windows = new_bar_window;
- GUI_CURSES(window)->last_bar_window = new_bar_window;
- }
- }
- else
- {
- bar->bar_window = new_bar_window;
- new_bar_window->prev_bar_window = NULL;
- new_bar_window->next_bar_window = NULL;
- }
- new_bar_window->win_bar = NULL;
- new_bar_window->win_separator = NULL;
-
- new_bar_window->x = 0;
- new_bar_window->y = 0;
- new_bar_window->width = 1;
- new_bar_window->height = 1;
- new_bar_window->scroll_x = 0;
- new_bar_window->scroll_y = 0;
- new_bar_window->cursor_x = -1;
- new_bar_window->cursor_y = -1;
- new_bar_window->current_size = (CONFIG_INTEGER(bar->size) == 0) ?
- 1 : CONFIG_INTEGER(bar->size);
-
- if (gui_init_ok)
- {
- gui_bar_window_calculate_pos_size (new_bar_window, window);
- gui_bar_window_create_win (new_bar_window);
- if (window)
- window->refresh_needed = 1;
- }
-
- return 1;
- }
-
- /* failed to create bar window */
- return 0;
-}
-
-/*
- * gui_bar_window_recreate_bar_windows: recreate bar windows for all windows
- */
-
-void
-gui_bar_window_recreate_bar_windows (struct t_gui_bar *bar)
-{
- struct t_gui_window *ptr_win;
- struct t_gui_bar_window *ptr_bar_win;
-
- if (CONFIG_BOOLEAN(bar->hidden))
- return;
-
- if (CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_ROOT)
- {
- gui_bar_window_calculate_pos_size (bar->bar_window, NULL);
- gui_bar_window_create_win (bar->bar_window);
- gui_window_refresh_needed = 1;
- }
- else
- {
- for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
- {
- for (ptr_bar_win = GUI_CURSES(ptr_win)->bar_windows;
- ptr_bar_win; ptr_bar_win = ptr_bar_win->next_bar_window)
- {
- if (ptr_bar_win->bar == bar)
- {
- gui_bar_window_calculate_pos_size (ptr_bar_win, ptr_win);
- gui_bar_window_create_win (ptr_bar_win);
- ptr_win->refresh_needed = 1;
- }
- }
- }
- }
-}
-
-/*
- * gui_bar_window_get_current_size: get current size of bar window
- * return width or height, depending on bar
- * position
- */
-
-int
-gui_bar_window_get_current_size (struct t_gui_bar_window *bar_window)
-{
- return bar_window->current_size;
-}
-
-/*
- * gui_bar_window_set_current_size: set current size of all bar windows for a bar
- */
-
-void
-gui_bar_window_set_current_size (struct t_gui_bar *bar, int size)
-{
- struct t_gui_window *ptr_win;
- struct t_gui_bar_window *ptr_bar_win;
- int new_size;
-
- if (size == 0)
- new_size = 1;
- else
- {
- new_size = size;
- if ((size != 0) && (CONFIG_INTEGER(bar->size_max) > 0)
- && (size > CONFIG_INTEGER(bar->size_max)))
- {
- new_size = CONFIG_INTEGER(bar->size_max);
- if (new_size < 1)
- new_size = 1;
- }
- }
-
- if (CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_ROOT)
- {
- if (bar->bar_window->current_size != new_size)
- {
- bar->bar_window->current_size = new_size;
- gui_bar_window_recreate_bar_windows (bar);
- }
- }
- else
- {
- for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
- {
- for (ptr_bar_win = GUI_CURSES(ptr_win)->bar_windows;
- ptr_bar_win; ptr_bar_win = ptr_bar_win->next_bar_window)
- {
- if ((ptr_bar_win->bar == bar)
- && (ptr_bar_win->current_size != new_size))
- {
- ptr_bar_win->current_size = new_size;
- gui_bar_window_recreate_bar_windows (bar);
- }
- }
- }
- }
-}
-
-/*
- * gui_bar_window_free: free a bar window
- */
-
-void
-gui_bar_window_free (struct t_gui_bar_window *bar_window,
- struct t_gui_window *window)
-{
- /* remove window bar from list */
- if (window)
- {
- if (bar_window->prev_bar_window)
- (bar_window->prev_bar_window)->next_bar_window = bar_window->next_bar_window;
- if (bar_window->next_bar_window)
- (bar_window->next_bar_window)->prev_bar_window = bar_window->prev_bar_window;
- if (GUI_CURSES(window)->bar_windows == bar_window)
- GUI_CURSES(window)->bar_windows = bar_window->next_bar_window;
- if (GUI_CURSES(window)->last_bar_window == bar_window)
- GUI_CURSES(window)->last_bar_window = bar_window->prev_bar_window;
-
- window->refresh_needed = 1;
- }
-
- /* free data */
- if (bar_window->win_bar)
- delwin (bar_window->win_bar);
- if (bar_window->win_separator)
- delwin (bar_window->win_separator);
-
- free (bar_window);
-}
-
-/*
- * gui_bar_free_bar_windows: free bar windows for a bar
- */
-
-void
-gui_bar_free_bar_windows (struct t_gui_bar *bar)
-{
- struct t_gui_window *ptr_win;
- struct t_gui_bar_window *ptr_bar_win, *next_bar_win;
-
- for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
- {
- ptr_bar_win = GUI_CURSES(ptr_win)->bar_windows;
- while (ptr_bar_win)
- {
- next_bar_win = ptr_bar_win->next_bar_window;
-
- if (ptr_bar_win->bar == bar)
- gui_bar_window_free (ptr_bar_win, ptr_win);
-
- ptr_bar_win = next_bar_win;
- }
- }
-}
-
-/*
- * gui_bar_window_remove_unused_bars: remove unused bars for a window
- * return 1 if at least one bar was removed
- * 0 if no bar was removed
- */
-
-int
-gui_bar_window_remove_unused_bars (struct t_gui_window *window)
-{
- int rc;
- struct t_gui_bar_window *ptr_bar_win, *next_bar_win;
-
- rc = 0;
-
- ptr_bar_win = GUI_CURSES(window)->bar_windows;
- while (ptr_bar_win)
- {
- next_bar_win = ptr_bar_win->next_bar_window;
-
- if ((CONFIG_INTEGER(ptr_bar_win->bar->type) == GUI_BAR_TYPE_WINDOW)
- && (!gui_bar_check_conditions_for_window (ptr_bar_win->bar, window)))
- {
- gui_bar_window_free (ptr_bar_win, window);
- rc = 1;
- }
-
- ptr_bar_win = next_bar_win;
- }
-
- return rc;
-}
-
-/*
- * gui_bar_window_add_missing_bars: add missing bars for a window
- * return 1 if at least one bar was created
- * 0 if no bar was created
- */
-
-int
-gui_bar_window_add_missing_bars (struct t_gui_window *window)
-{
- int rc;
- struct t_gui_bar *ptr_bar;
-
- rc = 0;
-
- for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
- {
- if ((CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_WINDOW)
- && gui_bar_check_conditions_for_window (ptr_bar, window))
- {
- if (!gui_bar_window_search_bar (window, ptr_bar))
- {
- gui_bar_window_new (ptr_bar, window);
- rc = 1;
- }
- }
- }
-
- return rc;
-}
-
-/*
- * gui_bar_window_print_string: print a string text on a bar window
- * return 1 if all was printed, 0 if some text
- * was not displayed (wrapped due to bar window
- * width)
- */
-
-int
-gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
- int *x, int *y,
- const char *string,
- int reset_color_before_display)
-{
- int weechat_color, x_with_hidden, size_on_screen, fg, bg, low_char;
- char str_fg[3], str_bg[3], utf_char[16], *next_char, *output;
-
- if (!string || !string[0])
- return 1;
-
- wmove (bar_window->win_bar, *y, *x);
-
- if (reset_color_before_display)
- {
- gui_window_set_custom_color_fg_bg (bar_window->win_bar,
- CONFIG_COLOR(bar_window->bar->color_fg),
- CONFIG_COLOR(bar_window->bar->color_bg));
- }
-
- x_with_hidden = *x;
-
- while (string && string[0])
- {
- if (string[0] == GUI_COLOR_COLOR_CHAR)
- {
- string++;
- switch (string[0])
- {
- case GUI_COLOR_FG_CHAR: /* fg color */
- if (string[1] && string[2])
- {
- str_fg[0] = string[1];
- str_fg[1] = string[2];
- str_fg[2] = '\0';
- sscanf (str_fg, "%d", &fg);
- gui_window_set_custom_color_fg (bar_window->win_bar,
- fg);
- string += 3;
- }
- break;
- case GUI_COLOR_BG_CHAR: /* bg color */
- if (string[1] && string[2])
- {
- str_bg[0] = string[1];
- str_bg[1] = string[2];
- str_bg[2] = '\0';
- sscanf (str_bg, "%d", &bg);
- gui_window_set_custom_color_bg (bar_window->win_bar,
- bg);
- string += 3;
- }
- break;
- case GUI_COLOR_FG_BG_CHAR: /* fg + bg color */
- if (string[1] && string[2] && (string[3] == ',')
- && string[4] && string[5])
- {
- str_fg[0] = string[1];
- str_fg[1] = string[2];
- str_fg[2] = '\0';
- str_bg[0] = string[4];
- str_bg[1] = string[5];
- str_bg[2] = '\0';
- sscanf (str_fg, "%d", &fg);
- sscanf (str_bg, "%d", &bg);
- gui_window_set_custom_color_fg_bg (bar_window->win_bar,
- fg, bg);
- string += 6;
- }
- break;
- case GUI_COLOR_BAR_CHAR: /* bar color */
- switch (string[1])
- {
- case GUI_COLOR_BAR_FG_CHAR:
- /* bar foreground */
- gui_window_set_custom_color_fg (bar_window->win_bar,
- CONFIG_INTEGER(bar_window->bar->color_fg));
- string += 2;
- break;
- case GUI_COLOR_BAR_DELIM_CHAR:
- /* bar delimiter */
- gui_window_set_custom_color_fg (bar_window->win_bar,
- CONFIG_INTEGER(bar_window->bar->color_delim));
- string += 2;
- break;
- case GUI_COLOR_BAR_BG_CHAR:
- /* bar background */
- gui_window_set_custom_color_bg (bar_window->win_bar,
- CONFIG_INTEGER(bar_window->bar->color_bg));
- string += 2;
- break;
- case GUI_COLOR_BAR_MOVE_CURSOR_CHAR:
- /* move cursor to current position on screen */
- getyx (bar_window->win_bar,
- bar_window->cursor_y, bar_window->cursor_x);
- bar_window->cursor_x += bar_window->x;
- bar_window->cursor_y += bar_window->y;
- string += 2;
- break;
- default:
- string++;
- break;
- }
- break;
- default:
- if (isdigit (string[0]) && isdigit (string[1]))
- {
- str_fg[0] = string[0];
- str_fg[1] = string[1];
- str_fg[2] = '\0';
- sscanf (str_fg, "%d", &weechat_color);
- gui_window_set_weechat_color (bar_window->win_bar,
- weechat_color);
- string += 2;
- }
- break;
- }
- }
- else
- {
- next_char = utf8_next_char (string);
- if (!next_char)
- break;
-
- memcpy (utf_char, string, next_char - string);
- utf_char[next_char - string] = '\0';
-
- if ((((unsigned char)utf_char[0]) < 32) && (!utf_char[1]))
- {
- low_char = 1;
- snprintf (utf_char, sizeof (utf_char), "%c",
- 'A' + ((unsigned char)utf_char[0]) - 1);
- }
- else
- {
- low_char = 0;
- if (!gui_window_utf_char_valid (utf_char))
- snprintf (utf_char, sizeof (utf_char), ".");
- }
-
- size_on_screen = utf8_char_size_screen (utf_char);
- if (size_on_screen > 0)
- {
- if (x_with_hidden < bar_window->scroll_x)
- {
- /* hidden char (before scroll_x value) */
- x_with_hidden++;
- }
- else
- {
- if (*x + size_on_screen > bar_window->width)
- {
- if (CONFIG_INTEGER(gui_bar_get_option_filling (bar_window->bar)) == GUI_BAR_FILLING_VERTICAL)
- return 0;
- if (*y >= bar_window->height - 1)
- return 0;
- *x = 0;
- (*y)++;
- wmove (bar_window->win_bar, *y, *x);
- }
-
- output = string_iconv_from_internal (NULL, utf_char);
- if (low_char)
- wattron (bar_window->win_bar, A_REVERSE);
- wprintw (bar_window->win_bar, "%s",
- (output) ? output : utf_char);
- if (low_char)
- wattroff (bar_window->win_bar, A_REVERSE);
- if (output)
- free (output);
-
- *x += size_on_screen;
- }
- }
-
- string = next_char;
- }
- }
- return 1;
-}
-
-/*
- * gui_bar_window_draw: draw a bar for a window
- */
-
-void
-gui_bar_window_draw (struct t_gui_bar_window *bar_window,
- struct t_gui_window *window)
-{
- int x, y, i, items_count, num_lines, line;
- char *content, *item_value, *item_value2, **items;
- char space_with_reinit_color[32];
- int length_reinit_color, content_length, length, length_on_screen;
- int max_length, optimal_number_of_lines, chars_available;
- int some_data_not_displayed;
-
- if (!gui_init_ok)
- return;
-
- snprintf (space_with_reinit_color,
- sizeof (space_with_reinit_color),
- "%c%c%02d,%02d ",
- GUI_COLOR_COLOR_CHAR,
- GUI_COLOR_FG_BG_CHAR,
- CONFIG_COLOR(bar_window->bar->color_fg),
- CONFIG_COLOR(bar_window->bar->color_bg));
- length_reinit_color = strlen (space_with_reinit_color);
-
- /* these values will be overwritten later (by gui_bar_window_print_string)
- if cursor has to move somewhere in bar window */
- bar_window->cursor_x = -1;
- bar_window->cursor_y = -1;
-
- if (CONFIG_INTEGER(bar_window->bar->size) == 0)
- {
- content = NULL;
- content_length = 1;
- for (i = 0; i < bar_window->bar->items_count; i++)
- {
- item_value = gui_bar_item_get_value (bar_window->bar->items_array[i],
- bar_window->bar, window,
- 0, 0, 0);
- if (item_value)
- {
- if (item_value[0])
- {
- if (CONFIG_INTEGER(gui_bar_get_option_filling (bar_window->bar)) == GUI_BAR_FILLING_HORIZONTAL)
- {
- item_value2 = string_replace (item_value, "\n",
- space_with_reinit_color);
- }
- else
- item_value2 = NULL;
- if (!content)
- {
- content_length += strlen ((item_value2) ?
- item_value2 : item_value);
- content = strdup ((item_value2) ?
- item_value2 : item_value);
- }
- else
- {
- content_length += length_reinit_color +
- strlen ((item_value2) ? item_value2 : item_value);
- content = realloc (content, content_length);
- if (CONFIG_INTEGER(gui_bar_get_option_filling (bar_window->bar)) == GUI_BAR_FILLING_HORIZONTAL)
- strcat (content, space_with_reinit_color);
- else
- strcat (content, "\n");
- strcat (content,
- (item_value2) ? item_value2 : item_value);
- }
- if (item_value2)
- free (item_value2);
- }
- free (item_value);
- }
- }
- if (content)
- {
- items = string_explode (content, "\n", 0, 0, &items_count);
- if (items_count == 0)
- {
- gui_bar_window_set_current_size (bar_window->bar, 1);
- gui_window_clear (bar_window->win_bar,
- CONFIG_COLOR(bar_window->bar->color_bg));
- }
- else
- {
- /* search longer line and optimal number of lines */
- max_length = 0;
- optimal_number_of_lines = 0;
- for (line = 0; line < items_count; line++)
- {
- length_on_screen = gui_chat_strlen_screen (items[line]);
-
- length = strlen (items[line]);
- if ((length >= 3)
- && (items[line][length - 3] == GUI_COLOR_COLOR_CHAR)
- && (items[line][length - 2] == GUI_COLOR_BAR_CHAR)
- && (items[line][length - 1] == GUI_COLOR_BAR_MOVE_CURSOR_CHAR))
- length_on_screen++;
-
- if (length_on_screen > max_length)
- max_length = length_on_screen;
-
- if (length_on_screen % bar_window->width == 0)
- num_lines = length_on_screen / bar_window->width;
- else
- num_lines = (length_on_screen / bar_window->width) + 1;
- if (num_lines == 0)
- num_lines = 1;
- optimal_number_of_lines += num_lines;
- }
- if (max_length == 0)
- max_length = 1;
-
- switch (CONFIG_INTEGER(bar_window->bar->position))
- {
- case GUI_BAR_POSITION_BOTTOM:
- case GUI_BAR_POSITION_TOP:
- if (CONFIG_INTEGER(gui_bar_get_option_filling (bar_window->bar)) == GUI_BAR_FILLING_HORIZONTAL)
- num_lines = optimal_number_of_lines;
- else
- num_lines = items_count;
- gui_bar_window_set_current_size (bar_window->bar,
- num_lines);
- break;
- case GUI_BAR_POSITION_LEFT:
- case GUI_BAR_POSITION_RIGHT:
- gui_bar_window_set_current_size (bar_window->bar,
- max_length);
- break;
- case GUI_BAR_NUM_POSITIONS:
- break;
- }
- gui_window_clear (bar_window->win_bar,
- CONFIG_COLOR(bar_window->bar->color_bg));
- x = 0;
- y = 0;
- some_data_not_displayed = 0;
- if ((bar_window->scroll_y > 0)
- && (bar_window->scroll_y >= items_count))
- {
- bar_window->scroll_y = items_count - bar_window->height;
- if (bar_window->scroll_y < 0)
- bar_window->scroll_y = 0;
- }
- for (line = 0;
- (line < items_count) && (y < bar_window->height);
- line++)
- {
- if ((bar_window->scroll_y == 0)
- || (line >= bar_window->scroll_y))
- {
- if (!gui_bar_window_print_string (bar_window, &x, &y,
- items[line], 1))
- {
- some_data_not_displayed = 1;
- }
- if (CONFIG_INTEGER(gui_bar_get_option_filling (bar_window->bar)) == GUI_BAR_FILLING_VERTICAL)
- {
- while (x < bar_window->width)
- {
- gui_bar_window_print_string (bar_window,
- &x, &y,
- " ", 0);
- }
- x = 0;
- y++;
- }
- else
- {
- gui_bar_window_print_string (bar_window, &x, &y,
- space_with_reinit_color, 0);
- }
- }
- }
- if ((bar_window->cursor_x < 0) && (bar_window->cursor_y < 0)
- && ((bar_window->scroll_x > 0) || (bar_window->scroll_y > 0)))
- {
- x = (bar_window->height > 1) ? bar_window->width - 2 : 0;
- if (x < 0)
- x = 0;
- y = 0;
- gui_window_set_custom_color_fg_bg (bar_window->win_bar,
- CONFIG_COLOR(config_color_bar_more),
- CONFIG_INTEGER(bar_window->bar->color_bg));
- mvwprintw (bar_window->win_bar, y, x, "--");
- }
- if ((bar_window->cursor_x < 0) && (bar_window->cursor_y < 0)
- && (some_data_not_displayed || (line < items_count)))
- {
- x = bar_window->width - 2;
- if (x < 0)
- x = 0;
- y = (bar_window->height > 1) ? bar_window->height - 1 : 0;
- gui_window_set_custom_color_fg_bg (bar_window->win_bar,
- CONFIG_COLOR(config_color_bar_more),
- CONFIG_INTEGER(bar_window->bar->color_bg));
- mvwprintw (bar_window->win_bar, y, x, "++");
- }
- }
- if (items)
- string_free_exploded (items);
- free (content);
- }
- else
- {
- gui_bar_window_set_current_size (bar_window->bar, 1);
- gui_window_clear (bar_window->win_bar,
- CONFIG_COLOR(bar_window->bar->color_bg));
- }
- }
- else
- {
- gui_window_clear (bar_window->win_bar,
- CONFIG_COLOR(bar_window->bar->color_bg));
-
- x = 0;
- y = 0;
-
- for (i = 0; i < bar_window->bar->items_count; i++)
- {
- chars_available =
- ((bar_window->height - y - 1) * bar_window->width) + /* next lines */
- (bar_window->width - x - 1); /* chars on current line */
-
- item_value = gui_bar_item_get_value (bar_window->bar->items_array[i],
- bar_window->bar, window,
- bar_window->width,
- bar_window->height,
- chars_available);
- if (item_value)
- {
- if (item_value[0])
- {
- if (CONFIG_INTEGER(gui_bar_get_option_filling (bar_window->bar)) == GUI_BAR_FILLING_HORIZONTAL)
- {
- item_value2 = string_replace (item_value, "\n",
- space_with_reinit_color);
- }
- else
- item_value2 = NULL;
- items = string_explode ((item_value2) ?
- item_value2 : item_value,
- "\n", 0, 0,
- &items_count);
- some_data_not_displayed = 0;
- if ((bar_window->scroll_y > 0)
- && (bar_window->scroll_y >= items_count))
- {
- bar_window->scroll_y = items_count - bar_window->height;
- if (bar_window->scroll_y < 0)
- bar_window->scroll_y = 0;
- }
- for (line = 0;
- (line < items_count) && (y < bar_window->height);
- line++)
- {
- if ((bar_window->scroll_y == 0)
- || (line >= bar_window->scroll_y))
- {
- if (!gui_bar_window_print_string (bar_window, &x, &y,
- items[line], 1))
- {
- some_data_not_displayed = 1;
- }
- if (CONFIG_INTEGER(gui_bar_get_option_filling (bar_window->bar)) == GUI_BAR_FILLING_VERTICAL)
- {
- while (x < bar_window->width)
- {
- gui_bar_window_print_string (bar_window,
- &x, &y,
- " ", 0);
- }
- x = 0;
- y++;
- }
- else
- {
- gui_bar_window_print_string (bar_window, &x, &y,
- space_with_reinit_color, 0);
- }
- }
- }
- if ((bar_window->cursor_x < 0) && (bar_window->cursor_y < 0)
- && ((bar_window->scroll_x > 0) || (bar_window->scroll_y > 0)))
- {
- x = (bar_window->height > 1) ? bar_window->width - 2 : 0;
- if (x < 0)
- x = 0;
- y = 0;
- gui_window_set_custom_color_fg_bg (bar_window->win_bar,
- CONFIG_COLOR(config_color_bar_more),
- CONFIG_INTEGER(bar_window->bar->color_bg));
- mvwprintw (bar_window->win_bar, y, x, "--");
- }
- if ((bar_window->cursor_x < 0) && (bar_window->cursor_y < 0)
- && (some_data_not_displayed || (line < items_count)))
- {
- x = bar_window->width - 2;
- if (x < 0)
- x = 0;
- y = (bar_window->height > 1) ? bar_window->height - 1 : 0;
- gui_window_set_custom_color_fg_bg (bar_window->win_bar,
- CONFIG_COLOR(config_color_bar_more),
- CONFIG_INTEGER(bar_window->bar->color_bg));
- mvwprintw (bar_window->win_bar, y, x, "++");
- }
- if (item_value2)
- free (item_value2);
- if (items)
- string_free_exploded (items);
- }
- free (item_value);
- }
- }
- }
-
- /* move cursor if it was asked in an item content (input_text does that
- to move cursor in user input text) */
- if (window && (gui_current_window == window)
- && (bar_window->cursor_x >= 0) && (bar_window->cursor_y >= 0))
- {
- move (bar_window->cursor_y, bar_window->cursor_x);
- }
-
- wnoutrefresh (bar_window->win_bar);
-
- if (CONFIG_INTEGER(bar_window->bar->separator))
- {
- switch (CONFIG_INTEGER(bar_window->bar->position))
- {
- case GUI_BAR_POSITION_BOTTOM:
- gui_window_set_weechat_color (bar_window->win_separator,
- GUI_COLOR_SEPARATOR);
- mvwhline (bar_window->win_separator, 0, 0, ACS_HLINE,
- bar_window->width);
- break;
- case GUI_BAR_POSITION_TOP:
- gui_window_set_weechat_color (bar_window->win_separator,
- GUI_COLOR_SEPARATOR);
- mvwhline (bar_window->win_separator, 0, 0, ACS_HLINE,
- bar_window->width);
- break;
- case GUI_BAR_POSITION_LEFT:
- gui_window_set_weechat_color (bar_window->win_separator,
- GUI_COLOR_SEPARATOR);
- mvwvline (bar_window->win_separator, 0, 0, ACS_VLINE,
- bar_window->height);
- break;
- case GUI_BAR_POSITION_RIGHT:
- gui_window_set_weechat_color (bar_window->win_separator,
- GUI_COLOR_SEPARATOR);
- mvwvline (bar_window->win_separator, 0, 0, ACS_VLINE,
- bar_window->height);
- break;
- case GUI_BAR_NUM_POSITIONS:
- break;
- }
- wnoutrefresh (bar_window->win_separator);
- }
-
- refresh ();
-}
-
-/*
- * gui_bar_draw: draw a bar
- */
-
-void
-gui_bar_draw (struct t_gui_bar *bar)
-{
- struct t_gui_window *ptr_win;
- struct t_gui_bar_window *ptr_bar_win;
-
- if (CONFIG_BOOLEAN(bar->hidden))
- return;
-
- if (bar->bar_window)
- {
- /* root bar */
- gui_bar_window_draw (bar->bar_window, NULL);
- }
- else
- {
- /* bar on each window */
- for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
- {
- for (ptr_bar_win = GUI_CURSES(ptr_win)->bar_windows; ptr_bar_win;
- ptr_bar_win = ptr_bar_win->next_bar_window)
- {
- if (ptr_bar_win->bar == bar)
- {
- gui_bar_window_draw (ptr_bar_win, ptr_win);
- }
- }
- }
- }
-
- bar->bar_refresh_needed = 0;
-}
-
-/*
- * gui_bar_window_scroll: scroll a bar window with a value
- * if add == 1, then value is added (otherwise subtracted)
- * if add_x == 1, then value is added to scroll_x (otherwise scroll_y)
- * if percent == 1, then value is a percentage (otherwise number of chars)
- */
-
-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)
-{
- int old_scroll_x, old_scroll_y;
-
- old_scroll_x = bar_window->scroll_x;
- old_scroll_y = bar_window->scroll_y;
-
- if (scroll_beginning)
- {
- if (add_x)
- bar_window->scroll_x = 0;
- else
- bar_window->scroll_y = 0;
- }
- else if (scroll_end)
- {
- if (add_x)
- bar_window->scroll_x = INT_MAX;
- else
- bar_window->scroll_y = INT_MAX;
- }
- else
- {
- if (percent)
- {
- if (add_x)
- value = (bar_window->width * value) / 100;
- else
- value = (bar_window->height * value) / 100;
- if (value == 0)
- value = 1;
- }
- if (add)
- {
- if (add_x)
- bar_window->scroll_x += value;
- else
- bar_window->scroll_y += value;
- }
- else
- {
- if (add_x)
- bar_window->scroll_x -= value;
- else
- bar_window->scroll_y -= value;
- }
- }
-
- if (bar_window->scroll_x < 0)
- bar_window->scroll_x = 0;
-
- if (bar_window->scroll_y < 0)
- bar_window->scroll_y = 0;
-
- /* refresh only if scroll has changed (X and/or Y) */
- if ((old_scroll_x != bar_window->scroll_x)
- || (old_scroll_y != bar_window->scroll_y))
- {
- gui_bar_window_draw (bar_window, window);
- }
-}
-
-/*
- * gui_bar_scroll: scroll a bar for a buffer
- * return 1 if scroll is ok, 0 if error
- */
-
-int
-gui_bar_scroll (struct t_gui_bar *bar, struct t_gui_buffer *buffer,
- const char *scroll)
-{
- struct t_gui_window *ptr_win;
- struct t_gui_bar_window *ptr_bar_win;
- long number;
- char *str, *error;
- int length, add_x, add, percent, scroll_beginning, scroll_end;
-
- add_x = 0;
- str = NULL;
- number = 0;
- add = 0;
- percent = 0;
- scroll_beginning = 0;
- scroll_end = 0;
-
- if ((scroll[0] == 'x') || (scroll[0] == 'X'))
- {
- add_x = 1;
- scroll++;
- }
- else if ((scroll[0] == 'y') || (scroll[0] == 'Y'))
- {
- scroll++;
- }
- else
- return 0;
-
- if ((scroll[0] == 'b') || (scroll[0] == 'B'))
- {
- scroll_beginning = 1;
- }
- else if ((scroll[0] == 'e') || (scroll[0] == 'E'))
- {
- scroll_end = 1;
- }
- else
- {
- if (scroll[0] == '+')
- {
- add = 1;
- scroll++;
- }
- else if (scroll[0] == '-')
- {
- scroll++;
- }
- else
- return 0;
-
- length = strlen (scroll);
- if (length == 0)
- return 0;
-
- if (scroll[length - 1] == '%')
- {
- str = string_strndup (scroll, length - 1);
- percent = 1;
- }
- else
- str = strdup (scroll);
- if (!str)
- return 0;
-
- error = NULL;
- number = strtol (str, &error, 10);
-
- if (!error || error[0] || (number <= 0))
- {
- free (str);
- return 0;
- }
- }
-
- if (CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_ROOT)
- gui_bar_window_scroll (bar->bar_window, NULL,
- add_x, scroll_beginning, scroll_end,
- add, percent, number);
- else
- {
- for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
- {
- if (ptr_win->buffer == buffer)
- {
- for (ptr_bar_win = GUI_CURSES(ptr_win)->bar_windows;
- ptr_bar_win; ptr_bar_win = ptr_bar_win->next_bar_window)
- {
- if (ptr_bar_win->bar == bar)
- {
- gui_bar_window_scroll (ptr_bar_win, ptr_win,
- add_x, scroll_beginning, scroll_end,
- add, percent, number);
- }
- }
- }
- }
- }
-
- free (str);
-
- 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)
-{
- log_printf ("");
- 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 : "");
- log_printf (" x . . . . . . . . : %d", bar_window->x);
- log_printf (" y . . . . . . . . : %d", bar_window->y);
- log_printf (" width . . . . . . : %d", bar_window->width);
- log_printf (" height. . . . . . : %d", bar_window->height);
- log_printf (" scroll_x. . . . . : %d", bar_window->scroll_x);
- log_printf (" scroll_y. . . . . : %d", bar_window->scroll_y);
- 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 (" win_bar . . . . . : 0x%lx", bar_window->win_bar);
- log_printf (" win_separator . . : 0x%lx", bar_window->win_separator);
- log_printf (" prev_bar_window . : 0x%lx", bar_window->prev_bar_window);
- log_printf (" next_bar_window . : 0x%lx", bar_window->next_bar_window);
-}
diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c
index cd9e37bea..c1fbae67a 100644
--- a/src/gui/curses/gui-curses-chat.c
+++ b/src/gui/curses/gui-curses-chat.c
@@ -100,10 +100,10 @@ gui_chat_display_new_line (struct t_gui_window *window, int num_lines, int count
if ((!simulate)
&& (window->win_chat_cursor_x <= gui_chat_get_real_width (window) - 1))
{
- wmove (GUI_CURSES(window)->win_chat,
+ wmove (GUI_WINDOW_OBJECTS(window)->win_chat,
window->win_chat_cursor_y,
window->win_chat_cursor_x);
- wclrtoeol (GUI_CURSES(window)->win_chat);
+ wclrtoeol (GUI_WINDOW_OBJECTS(window)->win_chat);
}
window->win_chat_cursor_y++;
}
@@ -123,24 +123,24 @@ gui_chat_display_horizontal_line (struct t_gui_window *window, int simulate)
if (!simulate)
{
- gui_window_set_weechat_color (GUI_CURSES(window)->win_chat,
+ gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat,
GUI_COLOR_CHAT_READ_MARKER);
switch (CONFIG_INTEGER(config_look_read_marker))
{
case CONFIG_LOOK_READ_MARKER_LINE:
- mvwhline (GUI_CURSES(window)->win_chat,
+ mvwhline (GUI_WINDOW_OBJECTS(window)->win_chat,
window->win_chat_cursor_y, window->win_chat_cursor_x,
ACS_HLINE,
window->win_chat_width);
break;
case CONFIG_LOOK_READ_MARKER_DOTTED_LINE:
- wmove (GUI_CURSES(window)->win_chat,
+ wmove (GUI_WINDOW_OBJECTS(window)->win_chat,
window->win_chat_cursor_y, window->win_chat_cursor_x);
- wclrtoeol (GUI_CURSES(window)->win_chat);
+ wclrtoeol (GUI_WINDOW_OBJECTS(window)->win_chat);
for (i = 0; i < window->win_chat_width; i++)
{
if (i % 2 != 0)
- mvwhline (GUI_CURSES(window)->win_chat,
+ mvwhline (GUI_WINDOW_OBJECTS(window)->win_chat,
window->win_chat_cursor_y, i,
ACS_HLINE, 1);
}
@@ -172,7 +172,7 @@ gui_chat_string_next_char (struct t_gui_window *window,
case GUI_COLOR_RESET_CHAR:
string++;
if (apply_style)
- gui_window_reset_style (GUI_CURSES(window)->win_chat, GUI_COLOR_CHAT);
+ gui_window_reset_style (GUI_WINDOW_OBJECTS(window)->win_chat, GUI_COLOR_CHAT);
break;
case GUI_COLOR_COLOR_CHAR:
string++;
@@ -187,7 +187,7 @@ gui_chat_string_next_char (struct t_gui_window *window,
str_fg[1] = string[2];
str_fg[2] = '\0';
sscanf (str_fg, "%d", &fg);
- gui_window_set_custom_color_fg (GUI_CURSES(window)->win_chat,
+ gui_window_set_custom_color_fg (GUI_WINDOW_OBJECTS(window)->win_chat,
fg);
}
string += 3;
@@ -202,7 +202,7 @@ gui_chat_string_next_char (struct t_gui_window *window,
str_bg[1] = string[2];
str_bg[2] = '\0';
sscanf (str_bg, "%d", &bg);
- gui_window_set_custom_color_bg (GUI_CURSES(window)->win_chat,
+ gui_window_set_custom_color_bg (GUI_WINDOW_OBJECTS(window)->win_chat,
bg);
}
string += 3;
@@ -222,7 +222,7 @@ gui_chat_string_next_char (struct t_gui_window *window,
str_bg[2] = '\0';
sscanf (str_fg, "%d", &fg);
sscanf (str_bg, "%d", &bg);
- gui_window_set_custom_color_fg_bg (GUI_CURSES(window)->win_chat,
+ gui_window_set_custom_color_fg_bg (GUI_WINDOW_OBJECTS(window)->win_chat,
fg, bg);
}
string += 6;
@@ -251,7 +251,7 @@ gui_chat_string_next_char (struct t_gui_window *window,
str_fg[1] = string[1];
str_fg[2] = '\0';
sscanf (str_fg, "%d", &weechat_color);
- gui_window_set_weechat_color (GUI_CURSES(window)->win_chat,
+ gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat,
weechat_color);
}
string += 2;
@@ -266,13 +266,13 @@ gui_chat_string_next_char (struct t_gui_window *window,
case GUI_COLOR_ATTR_BOLD_CHAR:
string++;
if (apply_style)
- gui_window_set_color_style (GUI_CURSES(window)->win_chat,
+ gui_window_set_color_style (GUI_WINDOW_OBJECTS(window)->win_chat,
A_BOLD);
break;
case GUI_COLOR_ATTR_REVERSE_CHAR:
string++;
if (apply_style)
- gui_window_set_color_style (GUI_CURSES(window)->win_chat,
+ gui_window_set_color_style (GUI_WINDOW_OBJECTS(window)->win_chat,
A_REVERSE);
break;
case GUI_COLOR_ATTR_ITALIC_CHAR:
@@ -282,7 +282,7 @@ gui_chat_string_next_char (struct t_gui_window *window,
case GUI_COLOR_ATTR_UNDERLINE_CHAR:
string++;
if (apply_style)
- gui_window_set_color_style (GUI_CURSES(window)->win_chat,
+ gui_window_set_color_style (GUI_WINDOW_OBJECTS(window)->win_chat,
A_UNDERLINE);
break;
}
@@ -294,13 +294,13 @@ gui_chat_string_next_char (struct t_gui_window *window,
case GUI_COLOR_ATTR_BOLD_CHAR:
string++;
if (apply_style)
- gui_window_remove_color_style (GUI_CURSES(window)->win_chat,
+ gui_window_remove_color_style (GUI_WINDOW_OBJECTS(window)->win_chat,
A_BOLD);
break;
case GUI_COLOR_ATTR_REVERSE_CHAR:
string++;
if (apply_style)
- gui_window_remove_color_style (GUI_CURSES(window)->win_chat,
+ gui_window_remove_color_style (GUI_WINDOW_OBJECTS(window)->win_chat,
A_REVERSE);
break;
case GUI_COLOR_ATTR_ITALIC_CHAR:
@@ -310,7 +310,7 @@ gui_chat_string_next_char (struct t_gui_window *window,
case GUI_COLOR_ATTR_UNDERLINE_CHAR:
string++;
if (apply_style)
- gui_window_remove_color_style (GUI_CURSES(window)->win_chat,
+ gui_window_remove_color_style (GUI_WINDOW_OBJECTS(window)->win_chat,
A_UNDERLINE);
break;
}
@@ -340,7 +340,7 @@ gui_chat_display_word_raw (struct t_gui_window *window, const char *string,
int chars_displayed, size_on_screen;
if (display)
- wmove (GUI_CURSES(window)->win_chat,
+ wmove (GUI_WINDOW_OBJECTS(window)->win_chat,
window->win_chat_cursor_y,
window->win_chat_cursor_x);
@@ -370,7 +370,7 @@ gui_chat_display_word_raw (struct t_gui_window *window, const char *string,
if (size_on_screen > 0)
{
output = string_iconv_from_internal (NULL, utf_char);
- wprintw (GUI_CURSES(window)->win_chat,
+ wprintw (GUI_WINDOW_OBJECTS(window)->win_chat,
"%s", (output) ? output : utf_char);
if (output)
free (output);
@@ -384,7 +384,7 @@ gui_chat_display_word_raw (struct t_gui_window *window, const char *string,
return chars_displayed;
chars_displayed++;
}
- wprintw (GUI_CURSES(window)->win_chat, ".");
+ wprintw (GUI_WINDOW_OBJECTS(window)->win_chat, ".");
}
}
@@ -440,10 +440,10 @@ gui_chat_display_word (struct t_gui_window *window,
{
if (!simulate)
{
- wmove (GUI_CURSES(window)->win_chat,
+ wmove (GUI_WINDOW_OBJECTS(window)->win_chat,
window->win_chat_cursor_y,
window->win_chat_cursor_x);
- wclrtoeol (GUI_CURSES(window)->win_chat);
+ wclrtoeol (GUI_WINDOW_OBJECTS(window)->win_chat);
}
window->win_chat_cursor_x += length_align;
if ((CONFIG_INTEGER(config_look_prefix_align) != CONFIG_LOOK_PREFIX_ALIGN_NONE)
@@ -452,8 +452,8 @@ gui_chat_display_word (struct t_gui_window *window,
{
if (!simulate)
{
- wattr_get (GUI_CURSES(window)->win_chat, &attrs, &pair, NULL);
- gui_window_set_weechat_color (GUI_CURSES(window)->win_chat,
+ wattr_get (GUI_WINDOW_OBJECTS(window)->win_chat, &attrs, &pair, NULL);
+ gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat,
GUI_COLOR_CHAT_PREFIX_SUFFIX);
gui_chat_display_word_raw (window,
CONFIG_STRING(config_look_prefix_suffix),
@@ -464,7 +464,7 @@ gui_chat_display_word (struct t_gui_window *window,
gui_chat_display_word_raw (window, str_space, 0, 1);
window->win_chat_cursor_x += gui_chat_strlen_screen (str_space);
if (!simulate)
- wattr_set (GUI_CURSES(window)->win_chat, attrs, pair, NULL);
+ wattr_set (GUI_WINDOW_OBJECTS(window)->win_chat, attrs, pair, NULL);
}
}
@@ -537,7 +537,7 @@ gui_chat_display_time_and_prefix (struct t_gui_window *window,
if (line->str_time && line->str_time[0])
{
if (!simulate)
- gui_window_reset_style (GUI_CURSES(window)->win_chat, GUI_COLOR_CHAT);
+ gui_window_reset_style (GUI_WINDOW_OBJECTS(window)->win_chat, GUI_COLOR_CHAT);
gui_chat_display_word (window, line, line->str_time,
NULL, 1, num_lines, count, lines_displayed,
@@ -549,7 +549,7 @@ gui_chat_display_time_and_prefix (struct t_gui_window *window,
else
{
if (!simulate)
- gui_window_reset_style (GUI_CURSES(window)->win_chat, GUI_COLOR_CHAT);
+ gui_window_reset_style (GUI_WINDOW_OBJECTS(window)->win_chat, GUI_COLOR_CHAT);
gui_chat_display_word (window, line, str_space,
NULL, 1, num_lines, count, lines_displayed,
@@ -562,7 +562,7 @@ gui_chat_display_time_and_prefix (struct t_gui_window *window,
|| (CONFIG_INTEGER(config_look_prefix_align) != CONFIG_LOOK_PREFIX_ALIGN_NONE)))
{
if (!simulate)
- gui_window_reset_style (GUI_CURSES(window)->win_chat, GUI_COLOR_CHAT);
+ gui_window_reset_style (GUI_WINDOW_OBJECTS(window)->win_chat, GUI_COLOR_CHAT);
if (CONFIG_INTEGER(config_look_prefix_align_max) > 0)
{
@@ -591,7 +591,7 @@ gui_chat_display_time_and_prefix (struct t_gui_window *window,
prefix_highlighted = (char *)gui_color_decode ((unsigned char *)line->prefix);
if (!simulate)
{
- gui_window_set_weechat_color (GUI_CURSES(window)->win_chat,
+ gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat,
GUI_COLOR_CHAT_HIGHLIGHT);
}
}
@@ -622,7 +622,7 @@ gui_chat_display_time_and_prefix (struct t_gui_window *window,
free (prefix_highlighted);
if (!simulate)
- gui_window_reset_style (GUI_CURSES(window)->win_chat, GUI_COLOR_CHAT);
+ gui_window_reset_style (GUI_WINDOW_OBJECTS(window)->win_chat, GUI_COLOR_CHAT);
if (CONFIG_INTEGER(config_look_prefix_align) == CONFIG_LOOK_PREFIX_ALIGN_LEFT)
{
@@ -638,7 +638,7 @@ gui_chat_display_time_and_prefix (struct t_gui_window *window,
{
if (!simulate)
{
- gui_window_set_weechat_color (GUI_CURSES(window)->win_chat,
+ gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat,
GUI_COLOR_CHAT_PREFIX_MORE);
}
gui_chat_display_word (window, line, str_plus,
@@ -660,7 +660,7 @@ gui_chat_display_time_and_prefix (struct t_gui_window *window,
{
if (!simulate)
{
- gui_window_set_weechat_color (GUI_CURSES(window)->win_chat,
+ gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat,
GUI_COLOR_CHAT_PREFIX_SUFFIX);
}
gui_chat_display_word (window, line,
@@ -735,7 +735,7 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line,
/* reset color & style for a new line */
if (!simulate)
- gui_window_reset_style (GUI_CURSES(window)->win_chat, GUI_COLOR_CHAT);
+ gui_window_reset_style (GUI_WINDOW_OBJECTS(window)->win_chat, GUI_COLOR_CHAT);
if (!line->message || !line->message[0])
{
@@ -841,9 +841,9 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line,
if (gui_chat_line_search (line, window->buffer->input_buffer,
window->buffer->text_search_exact))
{
- gui_window_set_weechat_color (GUI_CURSES(window)->win_chat,
+ gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat,
GUI_COLOR_CHAT_TEXT_FOUND);
- mvwprintw (GUI_CURSES(window)->win_chat,
+ mvwprintw (GUI_WINDOW_OBJECTS(window)->win_chat,
read_marker_y, read_marker_x,
"*");
}
@@ -855,9 +855,9 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line,
&& window->buffer->last_read_line
&& (window->buffer->last_read_line == gui_chat_get_prev_line_displayed (line)))
{
- gui_window_set_weechat_color (GUI_CURSES(window)->win_chat,
+ gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat,
GUI_COLOR_CHAT_READ_MARKER);
- mvwprintw (GUI_CURSES(window)->win_chat,
+ mvwprintw (GUI_WINDOW_OBJECTS(window)->win_chat,
read_marker_y, read_marker_x,
"*");
}
@@ -877,20 +877,20 @@ gui_chat_display_line_y (struct t_gui_window *window, struct t_gui_line *line,
int y)
{
/* reset color & style for a new line */
- gui_window_reset_style (GUI_CURSES(window)->win_chat, GUI_COLOR_CHAT);
+ gui_window_reset_style (GUI_WINDOW_OBJECTS(window)->win_chat, GUI_COLOR_CHAT);
window->win_chat_cursor_x = 0;
window->win_chat_cursor_y = y;
- wmove (GUI_CURSES(window)->win_chat,
+ wmove (GUI_WINDOW_OBJECTS(window)->win_chat,
window->win_chat_cursor_y,
window->win_chat_cursor_x);
- wclrtoeol (GUI_CURSES(window)->win_chat);
+ wclrtoeol (GUI_WINDOW_OBJECTS(window)->win_chat);
if (gui_chat_display_word_raw (window, line->message,
window->win_chat_width, 1) < window->win_chat_width)
{
- gui_window_clrtoeol_with_current_bg (GUI_CURSES(window)->win_chat);
+ gui_window_clrtoeol_with_current_bg (GUI_WINDOW_OBJECTS(window)->win_chat);
}
}
@@ -1015,18 +1015,18 @@ gui_chat_draw (struct t_gui_buffer *buffer, int erase)
{
if (erase)
{
- gui_window_set_weechat_color (GUI_CURSES(ptr_win)->win_chat,
+ gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(ptr_win)->win_chat,
GUI_COLOR_CHAT);
snprintf (format_empty, 32, "%%-%ds", ptr_win->win_chat_width);
for (i = 0; i < ptr_win->win_chat_height; i++)
{
- mvwprintw (GUI_CURSES(ptr_win)->win_chat, i, 0,
+ mvwprintw (GUI_WINDOW_OBJECTS(ptr_win)->win_chat, i, 0,
format_empty, " ");
}
}
- gui_window_set_weechat_color (GUI_CURSES(ptr_win)->win_chat,
+ gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(ptr_win)->win_chat,
GUI_COLOR_CHAT);
ptr_win->win_chat_cursor_x = 0;
@@ -1157,7 +1157,7 @@ gui_chat_draw (struct t_gui_buffer *buffer, int erase)
case GUI_BUFFER_NUM_TYPES:
break;
}
- wnoutrefresh (GUI_CURSES(ptr_win)->win_chat);
+ wnoutrefresh (GUI_WINDOW_OBJECTS(ptr_win)->win_chat);
}
}
diff --git a/src/gui/curses/gui-curses-main.c b/src/gui/curses/gui-curses-main.c
index 026f1289c..897511722 100644
--- a/src/gui/curses/gui-curses-main.c
+++ b/src/gui/curses/gui-curses-main.c
@@ -41,6 +41,7 @@
#include "../gui-main.h"
#include "../gui-bar.h"
#include "../gui-bar-item.h"
+#include "../gui-bar-window.h"
#include "../gui-buffer.h"
#include "../gui-chat.h"
#include "../gui-color.h"
@@ -93,7 +94,7 @@ gui_main_init ()
raw ();
gui_color_init ();
-
+
/* build prefixes according to config */
gui_chat_prefix_build ();
@@ -139,7 +140,7 @@ gui_main_init ()
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_CURSES(gui_windows)->bar_windows;
+ 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);
diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c
index 6321c77d0..ff26a9173 100644
--- a/src/gui/curses/gui-curses-window.c
+++ b/src/gui/curses/gui-curses-window.c
@@ -35,6 +35,7 @@
#include "../../plugins/plugin.h"
#include "../gui-window.h"
#include "../gui-bar.h"
+#include "../gui-bar-window.h"
#include "../gui-buffer.h"
#include "../gui-chat.h"
#include "../gui-color.h"
@@ -78,16 +79,14 @@ gui_window_get_height ()
int
gui_window_objects_init (struct t_gui_window *window)
{
- struct t_gui_curses_objects *new_objects;
+ struct t_gui_window_curses_objects *new_objects;
new_objects = malloc (sizeof (*new_objects));
if (new_objects)
{
window->gui_objects = new_objects;
- GUI_CURSES(window)->win_chat = NULL;
- GUI_CURSES(window)->win_separator = NULL;
- GUI_CURSES(window)->bar_windows = NULL;
- GUI_CURSES(window)->last_bar_window = NULL;
+ GUI_WINDOW_OBJECTS(window)->win_chat = NULL;
+ GUI_WINDOW_OBJECTS(window)->win_separator = NULL;
return 1;
}
return 0;
@@ -98,25 +97,17 @@ gui_window_objects_init (struct t_gui_window *window)
*/
void
-gui_window_objects_free (struct t_gui_window *window, int free_separator,
- int free_bar_windows)
+gui_window_objects_free (struct t_gui_window *window, int free_separator)
{
- if (GUI_CURSES(window)->win_chat)
+ if (GUI_WINDOW_OBJECTS(window)->win_chat)
{
- delwin (GUI_CURSES(window)->win_chat);
- GUI_CURSES(window)->win_chat = NULL;
+ delwin (GUI_WINDOW_OBJECTS(window)->win_chat);
+ GUI_WINDOW_OBJECTS(window)->win_chat = NULL;
}
- if (free_separator && GUI_CURSES(window)->win_separator)
+ if (free_separator && GUI_WINDOW_OBJECTS(window)->win_separator)
{
- delwin (GUI_CURSES(window)->win_separator);
- GUI_CURSES(window)->win_separator = NULL;
- }
- if (free_bar_windows)
- {
- while (GUI_CURSES(window)->bar_windows)
- {
- gui_bar_window_free (GUI_CURSES(window)->bar_windows, window);
- }
+ delwin (GUI_WINDOW_OBJECTS(window)->win_separator);
+ GUI_WINDOW_OBJECTS(window)->win_separator = NULL;
}
}
@@ -372,7 +363,7 @@ gui_window_calculate_pos_size (struct t_gui_window *window)
return;
}
- for (ptr_bar_win = GUI_CURSES(window)->bar_windows; ptr_bar_win;
+ for (ptr_bar_win = window->bar_windows; ptr_bar_win;
ptr_bar_win = ptr_bar_win->next_bar_window)
{
gui_bar_window_calculate_pos_size (ptr_bar_win, window);
@@ -401,20 +392,20 @@ gui_window_calculate_pos_size (struct t_gui_window *window)
void
gui_window_draw_separator (struct t_gui_window *window)
{
- if (GUI_CURSES(window)->win_separator)
- delwin (GUI_CURSES(window)->win_separator);
+ if (GUI_WINDOW_OBJECTS(window)->win_separator)
+ delwin (GUI_WINDOW_OBJECTS(window)->win_separator);
if (window->win_x > gui_bar_root_get_size (NULL, GUI_BAR_POSITION_LEFT))
{
- GUI_CURSES(window)->win_separator = newwin (window->win_height,
- 1,
- window->win_y,
- window->win_x - 1);
- gui_window_set_weechat_color (GUI_CURSES(window)->win_separator,
+ GUI_WINDOW_OBJECTS(window)->win_separator = newwin (window->win_height,
+ 1,
+ window->win_y,
+ window->win_x - 1);
+ gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_separator,
GUI_COLOR_SEPARATOR);
- mvwvline (GUI_CURSES(window)->win_separator, 0, 0, ACS_VLINE,
+ mvwvline (GUI_WINDOW_OBJECTS(window)->win_separator, 0, 0, ACS_VLINE,
window->win_height);
- wnoutrefresh (GUI_CURSES(window)->win_separator);
+ wnoutrefresh (GUI_WINDOW_OBJECTS(window)->win_separator);
refresh ();
}
}
@@ -487,33 +478,33 @@ gui_window_switch_to_buffer (struct t_gui_window *window,
window->buffer = buffer;
- if (old_buffer == buffer)
+ if (gui_ok && (old_buffer == buffer))
{
gui_bar_window_remove_unused_bars (window);
gui_bar_window_add_missing_bars (window);
}
gui_window_calculate_pos_size (window);
-
+
if (gui_ok)
{
/* create bar windows */
- for (ptr_bar_win = GUI_CURSES(window)->bar_windows; ptr_bar_win;
+ for (ptr_bar_win = window->bar_windows; ptr_bar_win;
ptr_bar_win = ptr_bar_win->next_bar_window)
{
gui_bar_window_create_win (ptr_bar_win);
}
/* destroy Curses windows */
- gui_window_objects_free (window, 0, 0);
+ gui_window_objects_free (window, 0);
/* create Curses windows */
- if (GUI_CURSES(window)->win_chat)
- delwin (GUI_CURSES(window)->win_chat);
- GUI_CURSES(window)->win_chat = newwin (window->win_chat_height,
- window->win_chat_width,
- window->win_chat_y,
- window->win_chat_x);
+ if (GUI_WINDOW_OBJECTS(window)->win_chat)
+ delwin (GUI_WINDOW_OBJECTS(window)->win_chat);
+ GUI_WINDOW_OBJECTS(window)->win_chat = newwin (window->win_chat_height,
+ window->win_chat_width,
+ window->win_chat_y,
+ window->win_chat_x);
}
buffer->num_displayed++;
@@ -527,7 +518,7 @@ gui_window_switch_to_buffer (struct t_gui_window *window,
}
/* redraw bars in window */
- for (ptr_bar_win = GUI_CURSES(window)->bar_windows; ptr_bar_win;
+ for (ptr_bar_win = window->bar_windows; ptr_bar_win;
ptr_bar_win = ptr_bar_win->next_bar_window)
{
ptr_bar_win->bar->bar_refresh_needed = 1;
@@ -573,8 +564,6 @@ gui_window_switch (struct t_gui_window *window)
gui_window_switch_to_buffer (gui_current_window,
gui_current_window->buffer, 1);
-
- gui_current_window->refresh_needed = 1;
}
/*
@@ -1187,7 +1176,6 @@ gui_window_merge_all (struct t_gui_window *window)
gui_current_window = window;
gui_window_switch_to_buffer (window, window->buffer, 1);
- window->refresh_needed = 1;
}
}
@@ -1459,18 +1447,7 @@ gui_window_title_reset ()
void
gui_window_objects_print_log (struct t_gui_window *window)
{
- struct t_gui_bar_window *ptr_bar_win;
-
- log_printf ("");
- log_printf (" window specific objects:");
- log_printf (" win_chat. . . . . . : 0x%lx", GUI_CURSES(window)->win_chat);
- log_printf (" win_separator . . . : 0x%lx", GUI_CURSES(window)->win_separator);
- log_printf (" bar_windows . . . . : 0x%lx", GUI_CURSES(window)->bar_windows);
- log_printf (" last_bar_windows. . : 0x%lx", GUI_CURSES(window)->last_bar_window);
-
- for (ptr_bar_win = GUI_CURSES(window)->bar_windows; ptr_bar_win;
- ptr_bar_win = ptr_bar_win->next_bar_window)
- {
- gui_bar_window_print_log (ptr_bar_win);
- }
+ log_printf (" window specific objects for Curses:");
+ log_printf (" win_chat. . . . . . : 0x%lx", GUI_WINDOW_OBJECTS(window)->win_chat);
+ log_printf (" win_separator . . . : 0x%lx", GUI_WINDOW_OBJECTS(window)->win_separator);
}
diff --git a/src/gui/curses/gui-curses.h b/src/gui/curses/gui-curses.h
index 56f1ba597..dfb76466c 100644
--- a/src/gui/curses/gui-curses.h
+++ b/src/gui/curses/gui-curses.h
@@ -29,40 +29,26 @@
#endif
struct t_gui_buffer;
-
-#define GUI_WINDOW_MIN_WIDTH 10
-#define GUI_WINDOW_MIN_HEIGHT 5
-
-#define GUI_WINDOW_CHAT_MIN_WIDTH 5
-#define GUI_WINDOW_CHAT_MIN_HEIGHT 2
+struct t_gui_window;
+struct t_gui_bar_window;
#define GUI_CURSES_NUM_WEECHAT_COLORS 15
-#define GUI_CURSES(window) ((struct t_gui_curses_objects *)(window->gui_objects))
+#define GUI_WINDOW_OBJECTS(window) \
+ ((struct t_gui_window_curses_objects *)(window->gui_objects))
+#define GUI_BAR_WINDOW_OBJECTS(bar_window) \
+ ((struct t_gui_bar_window_curses_objects *)(bar_window->gui_objects))
-struct t_gui_bar_window
+struct t_gui_window_curses_objects
{
- struct t_gui_bar *bar; /* pointer to bar */
- int x, y; /* position of window */
- int width, height; /* window size */
- int scroll_x, scroll_y; /* X-Y scroll in bar */
- int cursor_x, cursor_y; /* use to move cursor on screen (for */
- /* input_text item) */
- WINDOW *win_bar; /* bar Curses window */
- int current_size; /* current size (width or height) */
- WINDOW *win_separator; /* separator (optional) */
- struct t_gui_bar_window *prev_bar_window; /* link to previous bar win */
- /* (only for non-root bars) */
- struct t_gui_bar_window *next_bar_window; /* link to next bar win */
- /* (only for non-root bars) */
+ WINDOW *win_chat; /* chat window (example: channel) */
+ WINDOW *win_separator; /* separation between 2 splited (V) win */
};
-struct t_gui_curses_objects
+struct t_gui_bar_window_curses_objects
{
- WINDOW *win_chat; /* chat window (example: channel) */
- WINDOW *win_separator; /* separation between 2 splited (V) win */
- struct t_gui_bar_window *bar_windows; /* bar windows */
- struct t_gui_bar_window *last_bar_window; /* last bar window */
+ WINDOW *win_bar; /* bar Curses window */
+ WINDOW *win_separator; /* separator (optional) */
};
extern struct t_gui_color gui_weechat_colors[];
diff --git a/src/gui/gtk/CMakeLists.txt b/src/gui/gtk/CMakeLists.txt
index bc255f51a..20d072068 100644
--- a/src/gui/gtk/CMakeLists.txt
+++ b/src/gui/gtk/CMakeLists.txt
@@ -14,8 +14,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-SET(WEECHAT_GTK_SRC gui-gtk-bar.c gui-gtk-chat.c gui-gtk-color.c
-gui-gtk-keyboard.c gui-gtk-main.c gui-gtk-window.c gui-gtk.h)
+SET(WEECHAT_GTK_SRC
+gui-gtk.h
+gui-gtk-bar-window.c
+gui-gtk-chat.c
+gui-gtk-color.c
+gui-gtk-keyboard.c
+gui-gtk-main.c
+gui-gtk-window.c)
SET(EXECUTABLE weechat-gtk)
diff --git a/src/gui/gtk/Makefile.am b/src/gui/gtk/Makefile.am
index a6c1d9f9b..462810d78 100644
--- a/src/gui/gtk/Makefile.am
+++ b/src/gui/gtk/Makefile.am
@@ -28,7 +28,7 @@ weechat_gtk_LDADD = ./../../core/lib_weechat_core.a \
$(GTK_LFLAGS) \
$(GNUTLS_LFLAGS)
-weechat_gtk_SOURCES = gui-gtk-bar.c \
+weechat_gtk_SOURCES = gui-gtk-bar-window.c \
gui-gtk-chat.c \
gui-gtk-color.c \
gui-gtk-keyboard.c \
diff --git a/src/gui/gtk/gui-gtk-bar-window.c b/src/gui/gtk/gui-gtk-bar-window.c
new file mode 100644
index 000000000..e89d0845c
--- /dev/null
+++ b/src/gui/gtk/gui-gtk-bar-window.c
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* gui-gtk-bar-window.c: bar window functions for Gtk GUI */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+
+#include "../../core/weechat.h"
+#include "../../core/wee-config.h"
+#include "../../core/wee-log.h"
+#include "../gui-bar.h"
+#include "../gui-bar-window.h"
+#include "../gui-chat.h"
+#include "../gui-color.h"
+#include "../gui-window.h"
+#include "gui-gtk.h"
+
+
+/*
+ * gui_bar_window_objects_init: init Gtk windows for bar window
+ */
+
+int
+gui_bar_window_objects_init (struct t_gui_bar_window *bar_window)
+{
+ struct t_gui_bar_window_gtk_objects *new_objects;
+
+ new_objects = malloc (sizeof (*new_objects));
+ if (new_objects)
+ {
+ bar_window->gui_objects = new_objects;
+ /* TODO: init Gtk windows */
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ * gui_window_objects_free: free Gtk windows for a bar window
+ */
+
+void
+gui_bar_window_objects_free (struct t_gui_bar_window *bar_window)
+{
+ /* TODO: free Gtk windows */
+ (void) bar_window;
+}
+
+/*
+ * gui_bar_window_create_win: create curses window for bar
+ */
+
+void
+gui_bar_window_create_win (struct t_gui_bar_window *bar_window)
+{
+ (void) bar_window;
+
+ /* TODO: write this function for Gtk */
+}
+
+/*
+ * gui_bar_window_print_string: print a string text on a bar window
+ * return number of chars displayed on screen
+ */
+
+int
+gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
+ const char *string, int max_chars)
+{
+ (void) bar_window;
+ (void) string;
+ (void) max_chars;
+
+ /* TODO: write this function for Gtk */
+ return 0;
+}
+
+/*
+ * gui_bar_window_draw: draw a bar for a window
+ */
+
+void
+gui_bar_window_draw (struct t_gui_bar_window *bar_window,
+ struct t_gui_window *window)
+{
+ (void) bar_window;
+ (void) window;
+
+ /* TODO: write this function for Gtk */
+}
+
+/*
+ * gui_bar_window_objects_print_log: print bar window infos in log (usually for crash dump)
+ */
+
+void
+gui_bar_window_objects_print_log (struct t_gui_bar_window *bar_window)
+{
+ log_printf (" bar window specific objects for Gtk:");
+ /* TODO: add specific objects */
+ (void) bar_window;
+}
diff --git a/src/gui/gtk/gui-gtk-bar.c b/src/gui/gtk/gui-gtk-bar.c
deleted file mode 100644
index bab0c2a2e..000000000
--- a/src/gui/gtk/gui-gtk-bar.c
+++ /dev/null
@@ -1,444 +0,0 @@
-/*
- * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org>
- * See README for License detail, AUTHORS for developers list.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* gui-gtk-bar.c: bar functions for Gtk GUI */
-
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdlib.h>
-
-#include "../../core/weechat.h"
-#include "../../core/wee-config.h"
-#include "../../core/wee-log.h"
-#include "../gui-bar.h"
-#include "../gui-chat.h"
-#include "../gui-color.h"
-#include "../gui-window.h"
-#include "gui-gtk.h"
-
-
-/*
- * gui_bar_window_search_bar: search a reference to a bar in a window
- */
-
-struct t_gui_bar_window *
-gui_bar_window_search_bar (struct t_gui_window *window, struct t_gui_bar *bar)
-{
- struct t_gui_bar_window *ptr_bar_win;
-
- for (ptr_bar_win = GUI_GTK(window)->bar_windows; ptr_bar_win;
- ptr_bar_win = ptr_bar_win->next_bar_window)
- {
- if (ptr_bar_win->bar == bar)
- return ptr_bar_win;
- }
-
- /* bar window not found for window */
- return NULL;
-}
-
-/*
- * gui_bar_window_get_current_size: get current size of bar window
- * return width or height, depending on bar
- * position
- */
-
-int
-gui_bar_window_get_current_size (struct t_gui_bar_window *bar_window)
-{
- return bar_window->current_size;
-}
-
-/*
- * gui_bar_window_set_current_size: set current size of all bar windows for a bar
- */
-
-void
-gui_bar_window_set_current_size (struct t_gui_bar *bar, int size)
-{
- struct t_gui_window *ptr_win;
- struct t_gui_bar_window *ptr_bar_win;
-
- if (CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_ROOT)
- bar->bar_window->current_size = (size == 0) ? 1 : size;
- else
- {
- for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
- {
- for (ptr_bar_win = GUI_GTK(ptr_win)->bar_windows;
- ptr_bar_win; ptr_bar_win = ptr_bar_win->next_bar_window)
- {
- ptr_bar_win->current_size = (size == 0) ? 1 : size;
- }
- }
- }
-}
-
-/*
- * gui_bar_window_get_size: get total bar size (window bars) for a position
- * bar is optional, if not NULL, size is computed
- * from bar 1 to bar # - 1
- */
-
-int
-gui_bar_window_get_size (struct t_gui_bar *bar, struct t_gui_window *window,
- enum t_gui_bar_position position)
-{
- (void) bar;
- (void) window;
- (void) position;
-
- /* TODO: write this function for Gtk */
- return 0;
-}
-
-/*
- * gui_bar_get_min_width: return minimum width of a bar window displayed for
- * a bar
- * for example, if a bar is displayed in 3 windows,
- * this function return min width of these 3 bar windows
- */
-
-int
-gui_bar_get_min_width (struct t_gui_bar *bar)
-{
- struct t_gui_window *ptr_win;
- struct t_gui_bar_window *ptr_bar_win;
- int min_width;
-
- if (CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_ROOT)
- return bar->bar_window->width;
-
- min_width = INT_MAX;
- for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
- {
- for (ptr_bar_win = GUI_GTK(ptr_win)->bar_windows;
- ptr_bar_win; ptr_bar_win = ptr_bar_win->next_bar_window)
- {
- if (ptr_bar_win->bar == bar)
- {
- if (ptr_bar_win->width < min_width)
- min_width = ptr_bar_win->width;
- }
- }
- }
-
- if (min_width == INT_MAX)
- return 0;
-
- return min_width;
-}
-
-/*
- * gui_bar_get_min_height: return minimum height of a bar window displayed for
- * a bar
- * for example, if a bar is displayed in 3 windows,
- * this function return min width of these 3 bar windows
- */
-
-int
-gui_bar_get_min_height (struct t_gui_bar *bar)
-{
- struct t_gui_window *ptr_win;
- struct t_gui_bar_window *ptr_bar_win;
- int min_height;
-
- if (CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_ROOT)
- return bar->bar_window->height;
-
- min_height = INT_MAX;
- for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
- {
- for (ptr_bar_win = GUI_GTK(ptr_win)->bar_windows;
- ptr_bar_win; ptr_bar_win = ptr_bar_win->next_bar_window)
- {
- if (ptr_bar_win->bar == bar)
- {
- if (ptr_bar_win->height < min_height)
- min_height = ptr_bar_win->height;
- }
- }
- }
-
- if (min_height == INT_MAX)
- return 0;
-
- return min_height;
-}
-
-/*
- * gui_bar_check_size_add: check if "add_size" is ok for bar
- * return 1 if new size is ok
- * 0 if new size is too big
- */
-
-int
-gui_bar_check_size_add (struct t_gui_bar *bar, int add_size)
-{
- (void) bar;
- (void) add_size;
-
- /* TODO: write this function for Gtk */
- return 1;
-}
-
-/*
- * gui_bar_window_calculate_pos_size: calculate position and size of a bar
- */
-
-void
-gui_bar_window_calculate_pos_size (struct t_gui_bar_window *bar_window,
- struct t_gui_window *window)
-{
- (void) bar_window;
- (void) window;
-
- /* TODO: write this function for Gtk */
-}
-
-/*
- * gui_bar_window_create_win: create curses window for bar
- */
-
-void
-gui_bar_window_create_win (struct t_gui_bar_window *bar_window)
-{
- (void) bar_window;
-
- /* TODO: write this function for Gtk */
-}
-
-/*
- * gui_bar_window_find_pos: find position for bar window (keeping list sorted
- * by bar number)
- */
-
-struct t_gui_bar_window *
-gui_bar_window_find_pos (struct t_gui_bar *bar, struct t_gui_window *window)
-{
- struct t_gui_bar_window *ptr_bar_window;
-
- for (ptr_bar_window = GUI_GTK(window)->bar_windows; ptr_bar_window;
- ptr_bar_window = ptr_bar_window->next_bar_window)
- {
- if (CONFIG_INTEGER(bar->priority) >= CONFIG_INTEGER(ptr_bar_window->bar->priority))
- return ptr_bar_window;
- }
-
- /* position not found, best position is at the end */
- return NULL;
-}
-
-/*
- * 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
- */
-
-int
-gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window)
-{
- (void) bar;
- (void) window;
-
- /* TODO: write this function for Gtk */
- return 0;
-}
-
-/*
- * gui_bar_window_free: free a bar window
- */
-
-void
-gui_bar_window_free (struct t_gui_bar_window *bar_window,
- struct t_gui_window *window)
-{
- (void) bar_window;
- (void) window;
-
- /* TODO: write this function for Gtk */
-}
-
-/*
- * gui_bar_free_bar_windows: free bar windows for a bar
- */
-
-void
-gui_bar_free_bar_windows (struct t_gui_bar *bar)
-{
- struct t_gui_window *ptr_win;
- struct t_gui_bar_window *ptr_bar_win, *next_bar_win;
-
- for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
- {
- ptr_bar_win = GUI_GTK(gui_windows)->bar_windows;
- while (ptr_bar_win)
- {
- next_bar_win = ptr_bar_win->next_bar_window;
-
- if (ptr_bar_win->bar == bar)
- gui_bar_window_free (ptr_bar_win, ptr_win);
-
- ptr_bar_win = next_bar_win;
- }
- }
-}
-
-/*
- * gui_bar_window_remove_unused_bars: remove unused bars for a window
- * return 1 if at least one bar was removed
- * 0 if no bar was removed
- */
-
-int
-gui_bar_window_remove_unused_bars (struct t_gui_window *window)
-{
- int rc;
- struct t_gui_bar_window *ptr_bar_win, *next_bar_win;
-
- rc = 0;
-
- ptr_bar_win = GUI_GTK(window)->bar_windows;
- while (ptr_bar_win)
- {
- next_bar_win = ptr_bar_win->next_bar_window;
-
- if ((CONFIG_INTEGER(ptr_bar_win->bar->type) == GUI_BAR_TYPE_WINDOW)
- && (!gui_bar_check_conditions_for_window (ptr_bar_win->bar, window)))
- {
- gui_bar_window_free (ptr_bar_win, window);
- rc = 1;
- }
-
- ptr_bar_win = next_bar_win;
- }
-
- return rc;
-}
-
-/*
- * gui_bar_window_add_missing_bars: add missing bars for a window
- * return 1 if at least one bar was created
- * 0 if no bar was created
- */
-
-int
-gui_bar_window_add_missing_bars (struct t_gui_window *window)
-{
- int rc;
- struct t_gui_bar *ptr_bar;
-
- rc = 0;
-
- for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
- {
- if ((CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_WINDOW)
- && gui_bar_check_conditions_for_window (ptr_bar, window))
- {
- if (!gui_bar_window_search_bar (window, ptr_bar))
- {
- gui_bar_window_new (ptr_bar, window);
- rc = 1;
- }
- }
- }
-
- return rc;
-}
-
-/*
- * gui_bar_window_print_string: print a string text on a bar window
- * return number of chars displayed on screen
- */
-
-int
-gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
- const char *string, int max_chars)
-{
- (void) bar_window;
- (void) string;
- (void) max_chars;
-
- /* TODO: write this function for Gtk */
- return 0;
-}
-
-/*
- * gui_bar_window_draw: draw a bar for a window
- */
-
-void
-gui_bar_window_draw (struct t_gui_bar_window *bar_window,
- struct t_gui_window *window)
-{
- (void) bar_window;
- (void) window;
-
- /* TODO: write this function for Gtk */
-}
-
-/*
- * gui_bar_draw: draw a bar
- */
-
-void
-gui_bar_draw (struct t_gui_bar *bar)
-{
- (void) bar;
-
- /* TODO: write this function for Gtk */
-}
-
-/*
- * gui_bar_scroll: scroll a bar for a buffer
- * return 1 if scroll is ok, 0 if error
- */
-
-int
-gui_bar_scroll (struct t_gui_bar *bar, struct t_gui_buffer *buffer,
- const char *scroll)
-{
- (void) bar;
- (void) buffer;
- (void) scroll;
-
- /* TODO: write this function for Gtk */
- return 0;
-}
-
-/*
- * 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)
-{
- log_printf ("");
- log_printf (" [window bar (addr:0x%lx)]", bar_window);
- log_printf (" bar . . . . . . . : 0x%lx", bar_window->bar);
- log_printf (" x . . . . . . . . : %d", bar_window->x);
- log_printf (" y . . . . . . . . : %d", bar_window->y);
- log_printf (" width . . . . . . : %d", bar_window->width);
- log_printf (" height. . . . . . : %d", bar_window->height);
- log_printf (" scroll_x. . . . . : %d", bar_window->scroll_x);
- log_printf (" scroll_y. . . . . : %d", bar_window->scroll_y);
- log_printf (" prev_bar_window . : 0x%lx", bar_window->prev_bar_window);
- log_printf (" next_bar_window . : 0x%lx", bar_window->next_bar_window);
-}
diff --git a/src/gui/gtk/gui-gtk-chat.c b/src/gui/gtk/gui-gtk-chat.c
index 6899fb2b5..1040957fa 100644
--- a/src/gui/gtk/gui-gtk-chat.c
+++ b/src/gui/gtk/gui-gtk-chat.c
@@ -74,8 +74,8 @@ gui_chat_remove_style (struct t_gui_window *window, int style)
void
gui_chat_toggle_style (struct t_gui_window *window, int style)
{
- GUI_GTK(window)->current_style_attr ^= style;
- if (GUI_GTK(window)->current_style_attr & style)
+ GUI_WINDOW_OBJECTS(window)->current_style_attr ^= style;
+ if (GUI_WINDOW_OBJECTS(window)->current_style_attr & style)
gui_chat_set_style (window, style);
else
gui_chat_remove_style (window, style);
@@ -89,10 +89,10 @@ gui_chat_toggle_style (struct t_gui_window *window, int style)
void
gui_chat_reset_style (struct t_gui_window *window)
{
- GUI_GTK(window)->current_style_fg = -1;
- GUI_GTK(window)->current_style_bg = -1;
- GUI_GTK(window)->current_style_attr = 0;
- GUI_GTK(window)->current_color_attr = 0;
+ GUI_WINDOW_OBJECTS(window)->current_style_fg = -1;
+ GUI_WINDOW_OBJECTS(window)->current_style_bg = -1;
+ GUI_WINDOW_OBJECTS(window)->current_style_attr = 0;
+ GUI_WINDOW_OBJECTS(window)->current_color_attr = 0;
/* TODO: change following function call */
/*gui_window_set_weechat_color (window->win_chat, COLOR_WIN_CHAT);*/
@@ -107,7 +107,7 @@ gui_chat_reset_style (struct t_gui_window *window)
void
gui_chat_set_color_style (struct t_gui_window *window, int style)
{
- GUI_GTK(window)->current_color_attr |= style;
+ GUI_WINDOW_OBJECTS(window)->current_color_attr |= style;
/* TODO: change following function call */
/*wattron (window->win_chat, style);*/
}
@@ -119,7 +119,7 @@ gui_chat_set_color_style (struct t_gui_window *window, int style)
void
gui_chat_remove_color_style (struct t_gui_window *window, int style)
{
- GUI_GTK(window)->current_color_attr &= !style;
+ GUI_WINDOW_OBJECTS(window)->current_color_attr &= !style;
/* TODO: change following function call */
/*wattroff (window->win_chat, style);*/
}
@@ -133,7 +133,7 @@ gui_chat_reset_color_style (struct t_gui_window *window)
{
/* TODO: change following function call */
/*wattroff (window->win_chat, window->current_color_attr);*/
- GUI_GTK(window)->current_color_attr = 0;
+ GUI_WINDOW_OBJECTS(window)->current_color_attr = 0;
}
/*
@@ -480,11 +480,11 @@ gui_chat_draw_line (struct t_gui_buffer *buffer, struct t_gui_line *line)
message_without_color = gui_color_decode ((unsigned char *)(line->message));
if (message_without_color)
{
- gtk_text_buffer_insert_at_cursor (GUI_GTK(ptr_win)->textbuffer_chat,
+ gtk_text_buffer_insert_at_cursor (GUI_WINDOW_OBJECTS(ptr_win)->textbuffer_chat,
(char *)message_without_color, -1);
- gtk_text_buffer_insert_at_cursor (GUI_GTK(ptr_win)->textbuffer_chat,
+ gtk_text_buffer_insert_at_cursor (GUI_WINDOW_OBJECTS(ptr_win)->textbuffer_chat,
"\n", -1);
- gtk_text_buffer_get_bounds (GUI_GTK(ptr_win)->textbuffer_chat,
+ gtk_text_buffer_get_bounds (GUI_WINDOW_OBJECTS(ptr_win)->textbuffer_chat,
&start, &end);
/* TODO */
/*gtk_text_buffer_apply_tag (ptr_win->textbuffer_chat, ptr_win->texttag_chat, &start, &end);*/
diff --git a/src/gui/gtk/gui-gtk-window.c b/src/gui/gtk/gui-gtk-window.c
index 01a2fa31f..81515d560 100644
--- a/src/gui/gtk/gui-gtk-window.c
+++ b/src/gui/gtk/gui-gtk-window.c
@@ -66,16 +66,14 @@ gui_window_get_height ()
int
gui_window_objects_init (struct t_gui_window *window)
{
- struct t_gui_gtk_objects *new_objects;
+ struct t_gui_window_gtk_objects *new_objects;
if ((new_objects = malloc (sizeof (*new_objects))))
{
window->gui_objects = new_objects;
- GUI_GTK(window)->textview_chat = NULL;
- GUI_GTK(window)->textbuffer_chat = NULL;
- GUI_GTK(window)->texttag_chat = NULL;
- GUI_GTK(window)->bar_windows = NULL;
- GUI_GTK(window)->last_bar_window = NULL;
+ GUI_WINDOW_OBJECTS(window)->textview_chat = NULL;
+ GUI_WINDOW_OBJECTS(window)->textbuffer_chat = NULL;
+ GUI_WINDOW_OBJECTS(window)->texttag_chat = NULL;
return 1;
}
return 0;
@@ -86,13 +84,11 @@ gui_window_objects_init (struct t_gui_window *window)
*/
void
-gui_window_objects_free (struct t_gui_window *window, int free_separator,
- int free_bar_windows)
+gui_window_objects_free (struct t_gui_window *window, int free_separator)
{
/* TODO: write this function for Gtk */
(void) window;
(void) free_separator;
- (void) free_bar_windows;
}
/*
@@ -219,21 +215,21 @@ gui_window_switch_to_buffer (struct t_gui_window *window,
window->buffer = buffer;
gui_window_calculate_pos_size (window);
- if (!GUI_GTK(window)->textview_chat)
+ if (!GUI_WINDOW_OBJECTS(window)->textview_chat)
{
- GUI_GTK(window)->textview_chat = gtk_text_view_new ();
- gtk_widget_show (GUI_GTK(window)->textview_chat);
- gtk_container_add (GTK_CONTAINER (gui_gtk_scrolledwindow_chat), GUI_GTK(window)->textview_chat);
- gtk_widget_set_size_request (GUI_GTK(window)->textview_chat, 300, -1);
- gtk_text_view_set_editable (GTK_TEXT_VIEW (GUI_GTK(window)->textview_chat), FALSE);
- gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (GUI_GTK(window)->textview_chat), FALSE);
+ GUI_WINDOW_OBJECTS(window)->textview_chat = gtk_text_view_new ();
+ gtk_widget_show (GUI_WINDOW_OBJECTS(window)->textview_chat);
+ gtk_container_add (GTK_CONTAINER (gui_gtk_scrolledwindow_chat), GUI_WINDOW_OBJECTS(window)->textview_chat);
+ gtk_widget_set_size_request (GUI_WINDOW_OBJECTS(window)->textview_chat, 300, -1);
+ gtk_text_view_set_editable (GTK_TEXT_VIEW (GUI_WINDOW_OBJECTS(window)->textview_chat), FALSE);
+ gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (GUI_WINDOW_OBJECTS(window)->textview_chat), FALSE);
- GUI_GTK(window)->textbuffer_chat = gtk_text_buffer_new (NULL);
- gtk_text_view_set_buffer (GTK_TEXT_VIEW (GUI_GTK(window)->textview_chat), GUI_GTK(window)->textbuffer_chat);
+ GUI_WINDOW_OBJECTS(window)->textbuffer_chat = gtk_text_buffer_new (NULL);
+ gtk_text_view_set_buffer (GTK_TEXT_VIEW (GUI_WINDOW_OBJECTS(window)->textview_chat), GUI_WINDOW_OBJECTS(window)->textbuffer_chat);
- /*GUI_GTK(window)->texttag_chat = gtk_text_buffer_create_tag(GUI_GTK(window)->textbuffer_chat, "courier", "font_family", "lucida");*/
- gtk_text_buffer_get_bounds (GUI_GTK(window)->textbuffer_chat, &start, &end);
- gtk_text_buffer_apply_tag (GUI_GTK(window)->textbuffer_chat, GUI_GTK(window)->texttag_chat, &start, &end);
+ /*GUI_WINDOW_OBJECTS(window)->texttag_chat = gtk_text_buffer_create_tag(GUI_WINDOW_OBJECTS(window)->textbuffer_chat, "courier", "font_family", "lucida");*/
+ gtk_text_buffer_get_bounds (GUI_WINDOW_OBJECTS(window)->textbuffer_chat, &start, &end);
+ gtk_text_buffer_apply_tag (GUI_WINDOW_OBJECTS(window)->textbuffer_chat, GUI_WINDOW_OBJECTS(window)->texttag_chat, &start, &end);
}
window->start_line = NULL;
@@ -811,27 +807,14 @@ gui_window_title_reset ()
void
gui_window_objects_print_log (struct t_gui_window *window)
{
- struct t_gui_bar_window *ptr_bar_win;
-
- log_printf (" textview_chat . . . : 0x%lx", GUI_GTK(window)->textview_chat);
- log_printf (" textbuffer_chat . . : 0x%lx", GUI_GTK(window)->textbuffer_chat);
- log_printf (" texttag_chat. . . . : 0x%lx", GUI_GTK(window)->texttag_chat);
- log_printf (" bar_windows . . . . : 0x%lx", GUI_GTK(window)->bar_windows);
- log_printf (" last_bar_windows. . : 0x%lx", GUI_GTK(window)->last_bar_window);
- log_printf (" current_style_fg. . : %d", GUI_GTK(window)->current_style_fg);
- log_printf (" current_style_bg. . : %d", GUI_GTK(window)->current_style_bg);
- log_printf (" current_style_attr. : %d", GUI_GTK(window)->current_style_attr);
- log_printf (" current_color_attr. : %d", GUI_GTK(window)->current_color_attr);
-
- for (ptr_bar_win = GUI_GTK(window)->bar_windows; ptr_bar_win;
- ptr_bar_win = ptr_bar_win->next_bar_window)
- {
- log_printf ("");
- log_printf (" [window bar (addr:0x%lx)]", ptr_bar_win);
- log_printf (" bar . . . . . . . : 0x%lx", ptr_bar_win->bar);
- log_printf (" x . . . . . . . . : %d", ptr_bar_win->x);
- log_printf (" y . . . . . . . . : %d", ptr_bar_win->y);
- log_printf (" width . . . . . . : %d", ptr_bar_win->width);
- log_printf (" height. . . . . . : %d", ptr_bar_win->height);
- }
+ log_printf (" window specific objects for Gtk:");
+ log_printf (" textview_chat . . . : 0x%lx", GUI_WINDOW_OBJECTS(window)->textview_chat);
+ log_printf (" textbuffer_chat . . : 0x%lx", GUI_WINDOW_OBJECTS(window)->textbuffer_chat);
+ log_printf (" texttag_chat. . . . : 0x%lx", GUI_WINDOW_OBJECTS(window)->texttag_chat);
+ log_printf (" bar_windows . . . . : 0x%lx", GUI_WINDOW_OBJECTS(window)->bar_windows);
+ log_printf (" last_bar_windows. . : 0x%lx", GUI_WINDOW_OBJECTS(window)->last_bar_window);
+ log_printf (" current_style_fg. . : %d", GUI_WINDOW_OBJECTS(window)->current_style_fg);
+ log_printf (" current_style_bg. . : %d", GUI_WINDOW_OBJECTS(window)->current_style_bg);
+ log_printf (" current_style_attr. : %d", GUI_WINDOW_OBJECTS(window)->current_style_attr);
+ log_printf (" current_color_attr. : %d", GUI_WINDOW_OBJECTS(window)->current_color_attr);
}
diff --git a/src/gui/gtk/gui-gtk.h b/src/gui/gtk/gui-gtk.h
index 7665a725d..0ed1ac3aa 100644
--- a/src/gui/gtk/gui-gtk.h
+++ b/src/gui/gtk/gui-gtk.h
@@ -53,22 +53,12 @@ struct t_gui_line;
#define WEECHAT_COLOR_CYAN COLOR_YELLOW
#define WEECHAT_COLOR_WHITE COLOR_WHITE
-#define GUI_GTK(window) ((struct t_gui_gtk_objects *)(window->gui_objects))
+#define GUI_WINDOW_OBJECTS(window) \
+ ((struct t_gui_window_gtk_objects *)(window->gui_objects))
+#define GUI_BAR_WINDOW_OBJECTS(bar_window) \
+ ((struct t_gui_bar_window_gtk_objects *)(bar_window->gui_objects))
-struct t_gui_bar_window
-{
- struct t_gui_bar *bar; /* pointer to bar */
- int x, y; /* position of window */
- int width, height; /* window size */
- int scroll_x, scroll_y; /* X-Y scroll in bar */
- int current_size; /* current size (width or height) */
- struct t_gui_bar_window *prev_bar_window; /* link to previous bar win */
- /* (only for non-root bars) */
- struct t_gui_bar_window *next_bar_window; /* link to next bar win */
- /* (only for non-root bars) */
-};
-
-struct t_gui_gtk_objects
+struct t_gui_window_gtk_objects
{
GtkWidget *textview_chat; /* textview widget for chat */
GtkTextBuffer *textbuffer_chat; /* textbuffer widget for chat */
@@ -81,6 +71,10 @@ struct t_gui_gtk_objects
int current_color_attr; /* attr sum of last color(s) used */
};
+struct t_gui_bar_window_gtk_objects
+{
+};
+
extern GtkWidget *gui_gtk_main_window;
extern GtkWidget *gui_gtk_vbox1;
extern GtkWidget *gui_gtk_notebook1;
diff --git a/src/gui/gui-bar-window.c b/src/gui/gui-bar-window.c
new file mode 100644
index 000000000..a2bfbb268
--- /dev/null
+++ b/src/gui/gui-bar-window.c
@@ -0,0 +1,575 @@
+/*
+ * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* gui-bar-window.c: bar window functions, used by all GUI */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <limits.h>
+#include <string.h>
+
+#include "../core/weechat.h"
+#include "../core/wee-config.h"
+#include "../core/wee-log.h"
+#include "../core/wee-string.h"
+#include "gui-bar-window.h"
+#include "gui-bar.h"
+#include "gui-window.h"
+
+
+/*
+ * gui_bar_window_search_bar: search a reference to a bar in a window
+ */
+
+struct t_gui_bar_window *
+gui_bar_window_search_bar (struct t_gui_window *window, struct t_gui_bar *bar)
+{
+ struct t_gui_bar_window *ptr_bar_win;
+
+ for (ptr_bar_win = window->bar_windows; ptr_bar_win;
+ ptr_bar_win = ptr_bar_win->next_bar_window)
+ {
+ if (ptr_bar_win->bar == bar)
+ return ptr_bar_win;
+ }
+
+ /* bar window not found for window */
+ return NULL;
+}
+
+/*
+ * gui_bar_window_get_size: get total bar size (window bars) for a position
+ * bar is optional, if not NULL, size is computed
+ * from bar 1 to bar # - 1
+ */
+
+int
+gui_bar_window_get_size (struct t_gui_bar *bar, struct t_gui_window *window,
+ enum t_gui_bar_position position)
+{
+ struct t_gui_bar_window *ptr_bar_window;
+ int total_size;
+
+ total_size = 0;
+ for (ptr_bar_window = window->bar_windows; ptr_bar_window;
+ ptr_bar_window = ptr_bar_window->next_bar_window)
+ {
+ /* stop before bar */
+ if (bar && (ptr_bar_window->bar == bar))
+ return total_size;
+
+ if (!CONFIG_BOOLEAN(ptr_bar_window->bar->hidden))
+ {
+ if ((CONFIG_INTEGER(ptr_bar_window->bar->type) != GUI_BAR_TYPE_ROOT)
+ && (CONFIG_INTEGER(ptr_bar_window->bar->position) == (int)position))
+ {
+ switch (position)
+ {
+ case GUI_BAR_POSITION_BOTTOM:
+ case GUI_BAR_POSITION_TOP:
+ total_size += ptr_bar_window->height;
+ break;
+ case GUI_BAR_POSITION_LEFT:
+ case GUI_BAR_POSITION_RIGHT:
+ total_size += ptr_bar_window->width;
+ break;
+ case GUI_BAR_NUM_POSITIONS:
+ break;
+ }
+ if (CONFIG_INTEGER(ptr_bar_window->bar->separator))
+ total_size++;
+ }
+ }
+ }
+ return total_size;
+}
+
+/*
+ * gui_bar_window_calculate_pos_size: calculate position and size of a bar
+ */
+
+void
+gui_bar_window_calculate_pos_size (struct t_gui_bar_window *bar_window,
+ struct t_gui_window *window)
+{
+ int x1, y1, x2, y2;
+ int add_bottom, add_top, add_left, add_right;
+
+ if (window)
+ {
+ x1 = window->win_x;
+ y1 = window->win_y;
+ x2 = x1 + window->win_width - 1;
+ y2 = y1 + window->win_height - 1;
+ add_bottom = gui_bar_window_get_size (bar_window->bar, window, GUI_BAR_POSITION_BOTTOM);
+ add_top = gui_bar_window_get_size (bar_window->bar, window, GUI_BAR_POSITION_TOP);
+ add_left = gui_bar_window_get_size (bar_window->bar, window, GUI_BAR_POSITION_LEFT);
+ add_right = gui_bar_window_get_size (bar_window->bar, window, GUI_BAR_POSITION_RIGHT);
+ }
+ else
+ {
+ x1 = 0;
+ y1 = 0;
+ x2 = gui_window_get_width () - 1;
+ y2 = gui_window_get_height () - 1;
+ add_bottom = gui_bar_root_get_size (bar_window->bar, GUI_BAR_POSITION_BOTTOM);
+ add_top = gui_bar_root_get_size (bar_window->bar, GUI_BAR_POSITION_TOP);
+ add_left = gui_bar_root_get_size (bar_window->bar, GUI_BAR_POSITION_LEFT);
+ add_right = gui_bar_root_get_size (bar_window->bar, GUI_BAR_POSITION_RIGHT);
+ }
+
+ switch (CONFIG_INTEGER(bar_window->bar->position))
+ {
+ case GUI_BAR_POSITION_BOTTOM:
+ bar_window->x = x1 + add_left;
+ bar_window->y = y2 - add_bottom - bar_window->current_size + 1;
+ bar_window->width = x2 - x1 + 1 - add_left - add_right;
+ bar_window->height = bar_window->current_size;
+ break;
+ case GUI_BAR_POSITION_TOP:
+ bar_window->x = x1 + add_left;
+ bar_window->y = y1 + add_top;
+ bar_window->width = x2 - x1 + 1 - add_left - add_right;
+ bar_window->height = bar_window->current_size;
+ break;
+ case GUI_BAR_POSITION_LEFT:
+ bar_window->x = x1 + add_left;
+ bar_window->y = y1 + add_top;
+ bar_window->width = bar_window->current_size;
+ bar_window->height = y2 - y1 + 1 - add_top - add_bottom;
+ break;
+ case GUI_BAR_POSITION_RIGHT:
+ bar_window->x = x2 - add_right - bar_window->current_size + 1;
+ bar_window->y = y1 + add_top;
+ bar_window->width = bar_window->current_size;
+ bar_window->height = y2 - y1 + 1 - add_top - add_bottom;
+ break;
+ case GUI_BAR_NUM_POSITIONS:
+ break;
+ }
+}
+
+/*
+ * gui_bar_window_find_pos: find position for bar window (keeping list sorted
+ * by bar priority)
+ */
+
+struct t_gui_bar_window *
+gui_bar_window_find_pos (struct t_gui_bar *bar, struct t_gui_window *window)
+{
+ struct t_gui_bar_window *ptr_bar_window;
+
+ for (ptr_bar_window = window->bar_windows; ptr_bar_window;
+ ptr_bar_window = ptr_bar_window->next_bar_window)
+ {
+ if (CONFIG_INTEGER(bar->priority) >= CONFIG_INTEGER(ptr_bar_window->bar->priority))
+ return ptr_bar_window;
+ }
+
+ /* position not found, best position is at the end */
+ return NULL;
+}
+
+/*
+ * 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
+ */
+
+int
+gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window)
+{
+ struct t_gui_bar_window *new_bar_window, *pos_bar_window;
+
+ if (window)
+ {
+ if ((CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_WINDOW)
+ && (!gui_bar_check_conditions_for_window (bar, window)))
+ return 1;
+ }
+
+ new_bar_window = malloc (sizeof (*new_bar_window));
+ if (new_bar_window)
+ {
+ new_bar_window->bar = bar;
+ if (window)
+ {
+ bar->bar_window = NULL;
+ if (window->bar_windows)
+ {
+ pos_bar_window = gui_bar_window_find_pos (bar, window);
+ if (pos_bar_window)
+ {
+ /* insert before bar window found */
+ new_bar_window->prev_bar_window = pos_bar_window->prev_bar_window;
+ new_bar_window->next_bar_window = pos_bar_window;
+ if (pos_bar_window->prev_bar_window)
+ (pos_bar_window->prev_bar_window)->next_bar_window = new_bar_window;
+ else
+ window->bar_windows = new_bar_window;
+ pos_bar_window->prev_bar_window = new_bar_window;
+ }
+ else
+ {
+ /* add to end of list for window */
+ new_bar_window->prev_bar_window = window->last_bar_window;
+ new_bar_window->next_bar_window = NULL;
+ (window->last_bar_window)->next_bar_window = new_bar_window;
+ window->last_bar_window = new_bar_window;
+ }
+ }
+ else
+ {
+ new_bar_window->prev_bar_window = NULL;
+ new_bar_window->next_bar_window = NULL;
+ window->bar_windows = new_bar_window;
+ window->last_bar_window = new_bar_window;
+ }
+ }
+ else
+ {
+ bar->bar_window = new_bar_window;
+ new_bar_window->prev_bar_window = NULL;
+ new_bar_window->next_bar_window = NULL;
+ }
+
+ new_bar_window->x = 0;
+ new_bar_window->y = 0;
+ new_bar_window->width = 1;
+ new_bar_window->height = 1;
+ new_bar_window->scroll_x = 0;
+ new_bar_window->scroll_y = 0;
+ new_bar_window->cursor_x = -1;
+ 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;
+ gui_bar_window_objects_init (new_bar_window);
+
+ if (gui_init_ok)
+ {
+ gui_bar_window_calculate_pos_size (new_bar_window, window);
+ gui_bar_window_create_win (new_bar_window);
+ if (window)
+ window->refresh_needed = 1;
+ }
+
+ return 1;
+ }
+
+ /* failed to create bar window */
+ return 0;
+}
+
+/*
+ * gui_bar_window_recreate_bar_windows: recreate bar windows for all windows
+ */
+
+void
+gui_bar_window_recreate_bar_windows (struct t_gui_bar *bar)
+{
+ struct t_gui_window *ptr_win;
+ struct t_gui_bar_window *ptr_bar_win;
+
+ if (CONFIG_BOOLEAN(bar->hidden))
+ return;
+
+ if (CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_ROOT)
+ {
+ gui_bar_window_calculate_pos_size (bar->bar_window, NULL);
+ gui_bar_window_create_win (bar->bar_window);
+ gui_window_refresh_needed = 1;
+ }
+ else
+ {
+ for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
+ {
+ for (ptr_bar_win = ptr_win->bar_windows; ptr_bar_win;
+ ptr_bar_win = ptr_bar_win->next_bar_window)
+ {
+ if (ptr_bar_win->bar == bar)
+ {
+ gui_bar_window_calculate_pos_size (ptr_bar_win, ptr_win);
+ gui_bar_window_create_win (ptr_bar_win);
+ ptr_win->refresh_needed = 1;
+ }
+ }
+ }
+ }
+}
+
+/*
+ * gui_bar_window_get_current_size: get current size of bar window
+ * return width or height, depending on bar
+ * position
+ */
+
+int
+gui_bar_window_get_current_size (struct t_gui_bar_window *bar_window)
+{
+ return bar_window->current_size;
+}
+
+/*
+ * gui_bar_window_set_current_size: set current size of all bar windows for a bar
+ */
+
+void
+gui_bar_window_set_current_size (struct t_gui_bar *bar, int size)
+{
+ struct t_gui_window *ptr_win;
+ struct t_gui_bar_window *ptr_bar_win;
+ int new_size;
+
+ if (size == 0)
+ new_size = 1;
+ else
+ {
+ new_size = size;
+ if ((size != 0) && (CONFIG_INTEGER(bar->size_max) > 0)
+ && (size > CONFIG_INTEGER(bar->size_max)))
+ {
+ new_size = CONFIG_INTEGER(bar->size_max);
+ if (new_size < 1)
+ new_size = 1;
+ }
+ }
+
+ if (CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_ROOT)
+ {
+ if (bar->bar_window->current_size != new_size)
+ {
+ bar->bar_window->current_size = new_size;
+ gui_bar_window_recreate_bar_windows (bar);
+ }
+ }
+ else
+ {
+ for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
+ {
+ for (ptr_bar_win = ptr_win->bar_windows; ptr_bar_win;
+ ptr_bar_win = ptr_bar_win->next_bar_window)
+ {
+ if ((ptr_bar_win->bar == bar)
+ && (ptr_bar_win->current_size != new_size))
+ {
+ ptr_bar_win->current_size = new_size;
+ gui_bar_window_recreate_bar_windows (bar);
+ }
+ }
+ }
+ }
+}
+
+/*
+ * gui_bar_window_free: free a bar window
+ */
+
+void
+gui_bar_window_free (struct t_gui_bar_window *bar_window,
+ struct t_gui_window *window)
+{
+ /* remove window bar from list */
+ if (window)
+ {
+ if (bar_window->prev_bar_window)
+ (bar_window->prev_bar_window)->next_bar_window = bar_window->next_bar_window;
+ if (bar_window->next_bar_window)
+ (bar_window->next_bar_window)->prev_bar_window = bar_window->prev_bar_window;
+ if (window->bar_windows == bar_window)
+ window->bar_windows = bar_window->next_bar_window;
+ if (window->last_bar_window == bar_window)
+ window->last_bar_window = bar_window->prev_bar_window;
+
+ window->refresh_needed = 1;
+ }
+
+ /* free data */
+ if (bar_window->content)
+ free (bar_window->content);
+ gui_bar_window_objects_free (bar_window);
+ free (bar_window->gui_objects);
+
+ free (bar_window);
+}
+
+/*
+ * gui_bar_window_remove_unused_bars: remove unused bars for a window
+ * return 1 if at least one bar was removed
+ * 0 if no bar was removed
+ */
+
+int
+gui_bar_window_remove_unused_bars (struct t_gui_window *window)
+{
+ int rc;
+ struct t_gui_bar_window *ptr_bar_win, *next_bar_win;
+
+ rc = 0;
+
+ ptr_bar_win = window->bar_windows;
+ while (ptr_bar_win)
+ {
+ next_bar_win = ptr_bar_win->next_bar_window;
+
+ if ((CONFIG_INTEGER(ptr_bar_win->bar->type) == GUI_BAR_TYPE_WINDOW)
+ && (!gui_bar_check_conditions_for_window (ptr_bar_win->bar, window)))
+ {
+ gui_bar_window_free (ptr_bar_win, window);
+ rc = 1;
+ }
+
+ ptr_bar_win = next_bar_win;
+ }
+
+ return rc;
+}
+
+/*
+ * gui_bar_window_add_missing_bars: add missing bars for a window
+ * return 1 if at least one bar was created
+ * 0 if no bar was created
+ */
+
+int
+gui_bar_window_add_missing_bars (struct t_gui_window *window)
+{
+ int rc;
+ struct t_gui_bar *ptr_bar;
+
+ rc = 0;
+
+ for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
+ {
+ if ((CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_WINDOW)
+ && gui_bar_check_conditions_for_window (ptr_bar, window))
+ {
+ if (!gui_bar_window_search_bar (window, ptr_bar))
+ {
+ gui_bar_window_new (ptr_bar, window);
+ rc = 1;
+ }
+ }
+ }
+
+ return rc;
+}
+
+/*
+ * gui_bar_window_scroll: scroll a bar window with a value
+ * if add == 1, then value is added (otherwise subtracted)
+ * if add_x == 1, then value is added to scroll_x (otherwise scroll_y)
+ * if percent == 1, then value is a percentage (otherwise number of chars)
+ */
+
+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)
+{
+ int old_scroll_x, old_scroll_y;
+
+ old_scroll_x = bar_window->scroll_x;
+ old_scroll_y = bar_window->scroll_y;
+
+ if (scroll_beginning)
+ {
+ if (add_x)
+ bar_window->scroll_x = 0;
+ else
+ bar_window->scroll_y = 0;
+ }
+ else if (scroll_end)
+ {
+ if (add_x)
+ bar_window->scroll_x = INT_MAX;
+ else
+ bar_window->scroll_y = INT_MAX;
+ }
+ else
+ {
+ if (percent)
+ {
+ if (add_x)
+ value = (bar_window->width * value) / 100;
+ else
+ value = (bar_window->height * value) / 100;
+ if (value == 0)
+ value = 1;
+ }
+ if (add)
+ {
+ if (add_x)
+ bar_window->scroll_x += value;
+ else
+ bar_window->scroll_y += value;
+ }
+ else
+ {
+ if (add_x)
+ bar_window->scroll_x -= value;
+ else
+ bar_window->scroll_y -= value;
+ }
+ }
+
+ if (bar_window->scroll_x < 0)
+ bar_window->scroll_x = 0;
+
+ if (bar_window->scroll_y < 0)
+ bar_window->scroll_y = 0;
+
+ /* refresh only if scroll has changed (X and/or Y) */
+ if ((old_scroll_x != bar_window->scroll_x)
+ || (old_scroll_y != bar_window->scroll_y))
+ {
+ gui_bar_window_draw (bar_window, window);
+ }
+}
+
+/*
+ * 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)
+{
+ log_printf ("");
+ 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 : "");
+ log_printf (" x . . . . . . . . . : %d", bar_window->x);
+ log_printf (" y . . . . . . . . . : %d", bar_window->y);
+ log_printf (" width . . . . . . . : %d", bar_window->width);
+ log_printf (" height. . . . . . . : %d", bar_window->height);
+ log_printf (" scroll_x. . . . . . : %d", bar_window->scroll_x);
+ log_printf (" scroll_y. . . . . . : %d", bar_window->scroll_y);
+ 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 (" 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);
+ log_printf (" next_bar_window . . : 0x%lx", bar_window->next_bar_window);
+}
diff --git a/src/gui/gui-bar-window.h b/src/gui/gui-bar-window.h
new file mode 100644
index 000000000..d8d7c89d1
--- /dev/null
+++ b/src/gui/gui-bar-window.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __WEECHAT_GUI_BAR_WINDOW_H
+#define __WEECHAT_GUI_BAR_WINDOW_H 1
+
+struct t_gui_window;
+enum t_gui_bar_position position;
+
+struct t_gui_bar_window
+{
+ struct t_gui_bar *bar; /* pointer to bar */
+ int x, y; /* position of window */
+ int width, height; /* window size */
+ int scroll_x, scroll_y; /* X-Y scroll in bar */
+ 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) */
+ 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) */
+ struct t_gui_bar_window *next_bar_window; /* link to next bar win */
+ /* (only for non-root bars) */
+};
+
+/* functions */
+
+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);
+extern void gui_bar_window_set_current_size (struct t_gui_bar *bar, int size);
+extern int gui_bar_window_get_size (struct t_gui_bar *bar,
+ struct t_gui_window *window,
+ enum t_gui_bar_position position);
+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 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);
+
+/* functions (GUI dependent) */
+
+extern int gui_bar_window_objects_init (struct t_gui_bar_window *bar_window);
+extern void gui_bar_window_objects_free (struct t_gui_bar_window *bar_window);
+extern void gui_bar_window_create_win (struct t_gui_bar_window *bar_window);
+extern void gui_bar_window_draw (struct t_gui_bar_window *bar_window,
+ struct t_gui_window *window);
+extern void gui_bar_window_objects_print_log (struct t_gui_bar_window *bar_window);
+
+#endif /* gui-bar-window.h */
diff --git a/src/gui/gui-bar.c b/src/gui/gui-bar.c
index ac299dc3e..1030ec59d 100644
--- a/src/gui/gui-bar.c
+++ b/src/gui/gui-bar.c
@@ -34,6 +34,7 @@
#include "../plugins/plugin.h"
#include "gui-bar.h"
#include "gui-bar-item.h"
+#include "gui-bar-window.h"
#include "gui-buffer.h"
#include "gui-chat.h"
#include "gui-color.h"
@@ -129,6 +130,124 @@ gui_bar_search_position (const char *position)
}
/*
+ * gui_bar_get_min_width: return minimum width of a bar window displayed for
+ * a bar
+ * for example, if a bar is displayed in 3 windows,
+ * this function return min width of these 3 bar windows
+ */
+
+int
+gui_bar_get_min_width (struct t_gui_bar *bar)
+{
+ struct t_gui_window *ptr_win;
+ struct t_gui_bar_window *ptr_bar_win;
+ int min_width;
+
+ if (CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_ROOT)
+ return bar->bar_window->width;
+
+ min_width = INT_MAX;
+ for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
+ {
+ for (ptr_bar_win = ptr_win->bar_windows; ptr_bar_win;
+ ptr_bar_win = ptr_bar_win->next_bar_window)
+ {
+ if (ptr_bar_win->bar == bar)
+ {
+ if (ptr_bar_win->width < min_width)
+ min_width = ptr_bar_win->width;
+ }
+ }
+ }
+
+ if (min_width == INT_MAX)
+ return 0;
+
+ return min_width;
+}
+
+/*
+ * gui_bar_get_min_height: return minimum height of a bar window displayed for
+ * a bar
+ * for example, if a bar is displayed in 3 windows,
+ * this function return min width of these 3 bar windows
+ */
+
+int
+gui_bar_get_min_height (struct t_gui_bar *bar)
+{
+ struct t_gui_window *ptr_win;
+ struct t_gui_bar_window *ptr_bar_win;
+ int min_height;
+
+ if (CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_ROOT)
+ return bar->bar_window->height;
+
+ min_height = INT_MAX;
+ for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
+ {
+ for (ptr_bar_win = ptr_win->bar_windows; ptr_bar_win;
+ ptr_bar_win = ptr_bar_win->next_bar_window)
+ {
+ if (ptr_bar_win->bar == bar)
+ {
+ if (ptr_bar_win->height < min_height)
+ min_height = ptr_bar_win->height;
+ }
+ }
+ }
+
+ if (min_height == INT_MAX)
+ return 0;
+
+ return min_height;
+}
+
+/*
+ * gui_bar_check_size_add: check if "add_size" is ok for bar
+ * return 1 if new size is ok
+ * 0 if new size is too big
+ */
+
+int
+gui_bar_check_size_add (struct t_gui_bar *bar, int add_size)
+{
+ struct t_gui_window *ptr_win;
+ int sub_width, sub_height;
+
+ sub_width = 0;
+ sub_height = 0;
+
+ switch (CONFIG_INTEGER(bar->position))
+ {
+ case GUI_BAR_POSITION_BOTTOM:
+ case GUI_BAR_POSITION_TOP:
+ sub_height = add_size;
+ break;
+ case GUI_BAR_POSITION_LEFT:
+ case GUI_BAR_POSITION_RIGHT:
+ sub_width = add_size;
+ break;
+ case GUI_BAR_NUM_POSITIONS:
+ break;
+ }
+
+ for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
+ {
+ if ((CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_ROOT)
+ || (gui_bar_window_search_bar (ptr_win, bar)))
+ {
+ if ((ptr_win->win_chat_width - sub_width < GUI_WINDOW_CHAT_MIN_WIDTH)
+ || (ptr_win->win_chat_height - sub_height < GUI_WINDOW_CHAT_MIN_HEIGHT))
+ return 0;
+ }
+ }
+
+ /* new size ok */
+ return 1;
+}
+
+/*
* gui_bar_get_option_filling: return pointer to filling option
* if position is top/bottom, then return pointer
* on option "filling_top_bottom"
@@ -357,6 +476,43 @@ gui_bar_refresh (struct t_gui_bar *bar)
}
/*
+ * gui_bar_draw: draw a bar
+ */
+
+void
+gui_bar_draw (struct t_gui_bar *bar)
+{
+ struct t_gui_window *ptr_win;
+ struct t_gui_bar_window *ptr_bar_win;
+
+ if (CONFIG_BOOLEAN(bar->hidden))
+ return;
+
+ if (bar->bar_window)
+ {
+ /* root bar */
+ gui_bar_window_draw (bar->bar_window, NULL);
+ }
+ else
+ {
+ /* bar on each window */
+ for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
+ {
+ for (ptr_bar_win = ptr_win->bar_windows; ptr_bar_win;
+ ptr_bar_win = ptr_bar_win->next_bar_window)
+ {
+ if (ptr_bar_win->bar == bar)
+ {
+ gui_bar_window_draw (ptr_bar_win, ptr_win);
+ }
+ }
+ }
+ }
+
+ bar->bar_refresh_needed = 0;
+}
+
+/*
* gui_bar_config_check_type: callback for checking bar type before changing it
*/
@@ -1883,6 +2039,116 @@ gui_bar_update (const char *name)
}
/*
+ * gui_bar_scroll: scroll a bar for a buffer
+ * return 1 if scroll is ok, 0 if error
+ */
+
+int
+gui_bar_scroll (struct t_gui_bar *bar, struct t_gui_buffer *buffer,
+ const char *scroll)
+{
+ struct t_gui_window *ptr_win;
+ struct t_gui_bar_window *ptr_bar_win;
+ long number;
+ char *str, *error;
+ int length, add_x, add, percent, scroll_beginning, scroll_end;
+
+ add_x = 0;
+ str = NULL;
+ number = 0;
+ add = 0;
+ percent = 0;
+ scroll_beginning = 0;
+ scroll_end = 0;
+
+ if ((scroll[0] == 'x') || (scroll[0] == 'X'))
+ {
+ add_x = 1;
+ scroll++;
+ }
+ else if ((scroll[0] == 'y') || (scroll[0] == 'Y'))
+ {
+ scroll++;
+ }
+ else
+ return 0;
+
+ if ((scroll[0] == 'b') || (scroll[0] == 'B'))
+ {
+ scroll_beginning = 1;
+ }
+ else if ((scroll[0] == 'e') || (scroll[0] == 'E'))
+ {
+ scroll_end = 1;
+ }
+ else
+ {
+ if (scroll[0] == '+')
+ {
+ add = 1;
+ scroll++;
+ }
+ else if (scroll[0] == '-')
+ {
+ scroll++;
+ }
+ else
+ return 0;
+
+ length = strlen (scroll);
+ if (length == 0)
+ return 0;
+
+ if (scroll[length - 1] == '%')
+ {
+ str = string_strndup (scroll, length - 1);
+ percent = 1;
+ }
+ else
+ str = strdup (scroll);
+ if (!str)
+ return 0;
+
+ error = NULL;
+ number = strtol (str, &error, 10);
+
+ if (!error || error[0] || (number <= 0))
+ {
+ free (str);
+ return 0;
+ }
+ }
+
+ if (CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_ROOT)
+ gui_bar_window_scroll (bar->bar_window, NULL,
+ add_x, scroll_beginning, scroll_end,
+ add, percent, number);
+ else
+ {
+ for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
+ {
+ if (ptr_win->buffer == buffer)
+ {
+ for (ptr_bar_win = ptr_win->bar_windows; ptr_bar_win;
+ ptr_bar_win = ptr_bar_win->next_bar_window)
+ {
+ if (ptr_bar_win->bar == bar)
+ {
+ gui_bar_window_scroll (ptr_bar_win, ptr_win,
+ add_x, scroll_beginning, scroll_end,
+ add, percent, number);
+ }
+ }
+ }
+ }
+ }
+
+ free (str);
+
+ return 1;
+}
+
+/*
* gui_bar_free: delete a bar
*/
@@ -1985,6 +2251,31 @@ gui_bar_free_all_plugin (struct t_weechat_plugin *plugin)
}
/*
+ * gui_bar_free_bar_windows: free bar windows for a bar
+ */
+
+void
+gui_bar_free_bar_windows (struct t_gui_bar *bar)
+{
+ struct t_gui_window *ptr_win;
+ struct t_gui_bar_window *ptr_bar_win, *next_bar_win;
+
+ for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
+ {
+ ptr_bar_win = ptr_win->bar_windows;
+ while (ptr_bar_win)
+ {
+ next_bar_win = ptr_bar_win->next_bar_window;
+
+ if (ptr_bar_win->bar == bar)
+ gui_bar_window_free (ptr_bar_win, ptr_win);
+
+ ptr_bar_win = next_bar_win;
+ }
+ }
+}
+
+/*
* gui_bar_print_log: print bar infos in log (usually for crash dump)
*/
diff --git a/src/gui/gui-bar.h b/src/gui/gui-bar.h
index 7338afc85..a197b8778 100644
--- a/src/gui/gui-bar.h
+++ b/src/gui/gui-bar.h
@@ -131,6 +131,7 @@ extern int gui_bar_root_get_size (struct t_gui_bar *bar,
enum t_gui_bar_position position);
extern struct t_gui_bar *gui_bar_search (const char *name);
extern void gui_bar_ask_refresh (struct t_gui_bar *bar);
+extern void gui_bar_draw (struct t_gui_bar *bar);
extern int gui_bar_set (struct t_gui_bar *bar, const char *property, const char *value);
extern void gui_bar_create_option_temp (struct t_gui_bar *temp_bar,
int index_option, const char *value);
@@ -158,31 +159,13 @@ extern void gui_bar_create_default_status ();
extern void gui_bar_create_default_nicklist ();
extern void gui_bar_create_default ();
extern void gui_bar_update (const char *name);
+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_print_log ();
-
-/* functions (GUI dependent) */
-
-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);
-extern void gui_bar_window_set_current_size (struct t_gui_bar *bar, int size);
-extern int gui_bar_window_get_size (struct t_gui_bar *bar,
- struct t_gui_window *window,
- enum t_gui_bar_position position);
-extern int gui_bar_get_min_width (struct t_gui_bar *bar);
-extern int gui_bar_get_min_height (struct t_gui_bar *bar);
-extern int gui_bar_check_size_add (struct t_gui_bar *bar, int add_size);
-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 void gui_bar_free_bar_windows (struct t_gui_bar *bar);
-extern void gui_bar_draw (struct t_gui_bar *bar);
-extern int gui_bar_scroll (struct t_gui_bar *bar, struct t_gui_buffer *buffer,
- const char *scroll);
extern void gui_bar_window_print_log (struct t_gui_bar_window *bar_window);
+extern void gui_bar_print_log ();
#endif /* gui-bar.h */
diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c
index c4eb1be7a..0c707903b 100644
--- a/src/gui/gui-window.c
+++ b/src/gui/gui-window.c
@@ -42,6 +42,7 @@
#include "../plugins/plugin.h"
#include "gui-window.h"
#include "gui-bar.h"
+#include "gui-bar-window.h"
#include "gui-buffer.h"
#include "gui-chat.h"
#include "gui-filter.h"
@@ -215,6 +216,10 @@ gui_window_new (struct t_gui_window *parent, int x, int y, int width, int height
new_window->win_chat_height = 0;
new_window->win_chat_cursor_x = 0;
new_window->win_chat_cursor_y = 0;
+
+ /* bar windows */
+ new_window->bar_windows = NULL;
+ new_window->last_bar_window = NULL;
/* refresh */
new_window->refresh_needed = 0;
@@ -407,10 +412,16 @@ gui_window_free (struct t_gui_window *window)
/* free data */
if (window->gui_objects)
{
- gui_window_objects_free (window, 1, 1);
+ gui_window_objects_free (window, 1);
free (window->gui_objects);
}
+ /* remove bar windows */
+ while (window->bar_windows)
+ {
+ gui_bar_window_free (window->bar_windows, window);
+ }
+
/* remove window from windows list */
if (window->prev_window)
(window->prev_window)->next_window = window->next_window;
@@ -973,6 +984,7 @@ void
gui_window_print_log ()
{
struct t_gui_window *ptr_window;
+ struct t_gui_bar_window *ptr_bar_win;
log_printf ("");
log_printf ("current window = 0x%lx", gui_current_window);
@@ -995,6 +1007,7 @@ gui_window_print_log ()
log_printf (" win_chat_cursor_y . : %d", ptr_window->win_chat_cursor_y);
log_printf (" refresh_needed. . . : %d", ptr_window->refresh_needed);
log_printf (" gui_objects . . . . : 0x%lx", ptr_window->gui_objects);
+ gui_window_objects_print_log (ptr_window);
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);
@@ -1007,6 +1020,11 @@ gui_window_print_log ()
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);
- gui_window_objects_print_log (ptr_window);
+
+ for (ptr_bar_win = ptr_window->bar_windows; ptr_bar_win;
+ ptr_bar_win = ptr_bar_win->next_bar_window)
+ {
+ gui_bar_window_print_log (ptr_bar_win);
+ }
}
}
diff --git a/src/gui/gui-window.h b/src/gui/gui-window.h
index aa215d970..37ad3da65 100644
--- a/src/gui/gui-window.h
+++ b/src/gui/gui-window.h
@@ -20,6 +20,12 @@
#ifndef __WEECHAT_GUI_WINDOW_H
#define __WEECHAT_GUI_WINDOW_H 1
+#define GUI_WINDOW_MIN_WIDTH 10
+#define GUI_WINDOW_MIN_HEIGHT 5
+
+#define GUI_WINDOW_CHAT_MIN_WIDTH 5
+#define GUI_WINDOW_CHAT_MIN_HEIGHT 2
+
struct t_infolist;
extern int gui_init_ok;
@@ -43,12 +49,16 @@ struct t_gui_window
int win_chat_cursor_x; /* position of cursor in chat window */
int win_chat_cursor_y; /* position of cursor in chat window */
+ /* bar windows */
+ struct t_gui_bar_window *bar_windows; /* bar windows */
+ struct t_gui_bar_window *last_bar_window; /* last bar window */
+
/* refresh */
int refresh_needed; /* 1 if refresh needed for window */
/* GUI specific objects */
void *gui_objects; /* pointer to a GUI specific struct */
-
+
/* buffer and layout infos */
struct t_gui_buffer *buffer; /* buffer currently displayed */
char *layout_plugin_name; /* plugin and buffer that should be */
@@ -135,8 +145,7 @@ extern int gui_window_get_width ();
extern int gui_window_get_height ();
extern int gui_window_objects_init (struct t_gui_window *window);
extern void gui_window_objects_free (struct t_gui_window *window,
- int free_separator,
- int free_bar_windows);
+ int free_separator);
extern void gui_window_calculate_pos_size (struct t_gui_window *window);
extern void gui_window_switch_to_buffer (struct t_gui_window *window,
struct t_gui_buffer *buffer,