diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2008-04-03 15:54:21 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2008-04-03 15:54:21 +0200 |
commit | 8509f777b43f0a44414ddcb7e8fc0b7c240bd1f9 (patch) | |
tree | 2c51be47c506c7b7aabe624a01289b7584b7e7a6 /src/gui/gtk | |
parent | ad199b41aea0fba54287512e248bb4b29c935abb (diff) | |
download | weechat-8509f777b43f0a44414ddcb7e8fc0b7c240bd1f9.zip |
New features and bug fixes with bars
Diffstat (limited to 'src/gui/gtk')
-rw-r--r-- | src/gui/gtk/gui-gtk-bar.c | 232 | ||||
-rw-r--r-- | src/gui/gtk/gui-gtk-color.c | 23 | ||||
-rw-r--r-- | src/gui/gtk/gui-gtk-main.c | 3 | ||||
-rw-r--r-- | src/gui/gtk/gui-gtk-window.c | 37 | ||||
-rw-r--r-- | src/gui/gtk/gui-gtk.h | 11 |
5 files changed, 281 insertions, 25 deletions
diff --git a/src/gui/gtk/gui-gtk-bar.c b/src/gui/gtk/gui-gtk-bar.c index 6c726bc8a..570cbed10 100644 --- a/src/gui/gtk/gui-gtk-bar.c +++ b/src/gui/gtk/gui-gtk-bar.c @@ -35,14 +35,34 @@ /* - * gui_bar_windows_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 + * 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_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, - int position) + enum t_gui_bar_position position) { (void) bar; (void) window; @@ -53,6 +73,69 @@ gui_bar_window_get_size (struct t_gui_bar *bar, struct t_gui_window *window, } /* + * 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 (ptr_bar_window->bar->number > bar->number) + 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 */ @@ -68,28 +151,151 @@ gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window) } /* - * gui_bar_draw: draw a bar + * gui_bar_window_free: free a bar window */ void -gui_bar_draw (struct t_gui_bar *bar) +gui_bar_window_free (struct t_gui_bar_window *bar_window, + struct t_gui_window *window) { - (void) bar; + (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 (((ptr_bar_win->bar->type == GUI_BAR_TYPE_WINDOW_ACTIVE) + && (window != gui_current_window)) + || ((ptr_bar_win->bar->type == GUI_BAR_TYPE_WINDOW_INACTIVE) + && (window == gui_current_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 (((ptr_bar->type == GUI_BAR_TYPE_WINDOW_ACTIVE) + && (window == gui_current_window)) + || ((ptr_bar->type == GUI_BAR_TYPE_WINDOW_INACTIVE) + && (window != gui_current_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, + char *string, int max_chars) +{ + (void) bar_window; + (void) string; + (void) max_chars; + /* TODO: write this function for Gtk */ + return 0; } /* - * gui_bar_window_free: delete an bar window + * gui_bar_window_draw: draw a bar for a window */ void -gui_bar_window_free (struct t_gui_bar_window *bar_window) +gui_bar_window_draw (struct t_gui_bar_window *bar_window, + struct t_gui_window *window) { - /* TODO: complete this function for Gtk */ + (void) bar_window; + (void) window; - /* free bar window */ - free (bar_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 */ } /* @@ -106,4 +312,6 @@ gui_bar_window_print_log (struct t_gui_bar_window *bar_window) log_printf (" y . . . . . . . . : %d", bar_window->y); log_printf (" width . . . . . . : %d", bar_window->width); log_printf (" height. . . . . . : %d", bar_window->height); + log_printf (" prev_bar_window . : 0x%x", bar_window->prev_bar_window); + log_printf (" next_bar_window . : 0x%x", bar_window->next_bar_window); } diff --git a/src/gui/gtk/gui-gtk-color.c b/src/gui/gtk/gui-gtk-color.c index 77d3dcbf8..cb04d3d1a 100644 --- a/src/gui/gtk/gui-gtk-color.c +++ b/src/gui/gtk/gui-gtk-color.c @@ -54,8 +54,6 @@ struct t_gui_color gui_weechat_colors[] = { 0, 0, 0, NULL } }; -struct t_gui_color *gui_color[GUI_NUM_COLORS]; - /* * gui_color_search: search a color by name @@ -121,7 +119,7 @@ gui_color_get_pair (int num_color) { int fg, bg; - if ((num_color < 0) || (num_color > GUI_NUM_COLORS - 1)) + if ((num_color < 0) || (num_color > GUI_COLOR_NUM_COLORS - 1)) return WEECHAT_COLOR_WHITE; fg = gui_color[num_color]->foreground; @@ -167,7 +165,7 @@ gui_color_rebuild_weechat () { int i; - for (i = 0; i < GUI_NUM_COLORS; i++) + for (i = 0; i < GUI_COLOR_NUM_COLORS; i++) { if (gui_color[i]) { @@ -181,6 +179,21 @@ gui_color_rebuild_weechat () } /* + * gui_color_pre_init: pre-init colors + */ + +void +gui_color_pre_init () +{ + int i; + + for (i = 0; i < GUI_COLOR_NUM_COLORS; i++) + { + gui_color[i] = NULL; + } +} + +/* * gui_color_init: init GUI colors */ @@ -200,7 +213,7 @@ gui_color_end () { int i; - for (i = 0; i < GUI_NUM_COLORS; i++) + for (i = 0; i < GUI_COLOR_NUM_COLORS; i++) { gui_color_free (gui_color[i]); } diff --git a/src/gui/gtk/gui-gtk-main.c b/src/gui/gtk/gui-gtk-main.c index b00ce369f..d2f216e02 100644 --- a/src/gui/gtk/gui-gtk-main.c +++ b/src/gui/gtk/gui-gtk-main.c @@ -63,6 +63,9 @@ GtkWidget *gui_gtk_label1; void gui_main_pre_init (int *argc, char **argv[]) { + /* pre-init colors */ + gui_color_pre_init (); + /* build empty prefixes (before reading config) */ gui_chat_prefix_build_empty (); diff --git a/src/gui/gtk/gui-gtk-window.c b/src/gui/gtk/gui-gtk-window.c index 0c34d1815..5db023317 100644 --- a/src/gui/gtk/gui-gtk-window.c +++ b/src/gui/gtk/gui-gtk-window.c @@ -30,6 +30,7 @@ #include "../../core/wee-config.h" #include "../../core/wee-log.h" #include "../gui-window.h" +#include "../gui-bar.h" #include "../gui-buffer.h" #include "../gui-chat.h" #include "../gui-hotlist.h" @@ -67,7 +68,7 @@ int gui_window_objects_init (struct t_gui_window *window) { struct t_gui_gtk_objects *new_objects; - + if ((new_objects = malloc (sizeof (*new_objects)))) { window->gui_objects = new_objects; @@ -77,10 +78,10 @@ gui_window_objects_init (struct t_gui_window *window) GUI_GTK(window)->textview_nicklist = NULL; GUI_GTK(window)->textbuffer_nicklist = NULL; GUI_GTK(window)->bar_windows = NULL; + GUI_GTK(window)->last_bar_window = NULL; return 1; } - else - return 0; + return 0; } /* @@ -88,11 +89,13 @@ gui_window_objects_init (struct t_gui_window *window) */ void -gui_window_objects_free (struct t_gui_window *window, int free_separator) +gui_window_objects_free (struct t_gui_window *window, int free_separator, + int free_bar_windows) { /* TODO: write this function for Gtk */ (void) window; (void) free_separator; + (void) free_bar_windows; } /* @@ -172,6 +175,26 @@ gui_window_redraw_all_buffers () } /* + * gui_window_switch: switch to another window + */ + +void +gui_window_switch (struct t_gui_window *window) +{ + if (gui_current_window == window) + return; + + /* remove unused bars from current window */ + /* ... */ + + gui_current_window = window; + + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + + gui_window_redraw_buffer (gui_current_window->buffer); +} + +/* * gui_window_switch_to_buffer: switch to another buffer */ @@ -927,6 +950,12 @@ gui_window_objects_print_log (struct t_gui_window *window) log_printf (" texttag_chat. . . . : 0x%x", GUI_GTK(window)->texttag_chat); log_printf (" textview_nicklist . : 0x%x", GUI_GTK(window)->textview_nicklist); log_printf (" textbuffer_nicklist : 0x%x", GUI_GTK(window)->textbuffer_nicklist); + log_printf (" bar_windows . . . . : 0x%x", GUI_GTK(window)->bar_windows); + log_printf (" last_bar_windows. . : 0x%x", 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) diff --git a/src/gui/gtk/gui-gtk.h b/src/gui/gtk/gui-gtk.h index ffe8ef707..6aaba6840 100644 --- a/src/gui/gtk/gui-gtk.h +++ b/src/gui/gtk/gui-gtk.h @@ -59,9 +59,10 @@ struct t_gui_bar_window struct t_gui_bar *bar; /* pointer to bar */ int x, y; /* position of window */ int width, height; /* window size */ - struct t_gui_bar_window *next_bar_window; - /* link to next bar window */ - /* (only used if bar is in windows) */ + 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 @@ -71,7 +72,8 @@ struct t_gui_gtk_objects GtkTextTag *texttag_chat; /* texttag widget for chat */ GtkWidget *textview_nicklist; /* textview widget for nicklist */ GtkTextBuffer *textbuffer_nicklist; /* textbuffer widget for nicklist */ - struct t_gui_bar_window *bar_windows; /* bar windows */ + struct t_gui_bar_window *bar_windows; /* bar windows */ + struct t_gui_bar_window *last_bar_window; /* last bar window */ int current_style_fg; /* current foreground color */ int current_style_bg; /* current background color */ int current_style_attr; /* current attributes (bold, ..) */ @@ -95,6 +97,7 @@ extern GtkWidget *gui_gtk_label1; /* color functions */ extern int gui_color_get_pair (int num_color); +extern void gui_color_pre_init (); extern void gui_color_init (); extern void gui_color_end (); |