From: <sa...@us...> - 2006-08-30 17:34:00
|
Revision: 17088 http://svn.sourceforge.net/gaim/?rev=17088&view=rev Author: sadrul Date: 2006-08-30 10:33:44 -0700 (Wed, 30 Aug 2006) Log Message: ----------- PLUGINS don't need to be defined for WMs. Modified Paths: -------------- trunk/console/libgnt/configure.ac trunk/console/libgnt/wms/Makefile.am Modified: trunk/console/libgnt/configure.ac =================================================================== --- trunk/console/libgnt/configure.ac 2006-08-30 17:09:44 UTC (rev 17087) +++ trunk/console/libgnt/configure.ac 2006-08-30 17:33:44 UTC (rev 17088) @@ -205,5 +205,6 @@ AC_OUTPUT([Makefile gnt.pc + wms/Makefile ]) Modified: trunk/console/libgnt/wms/Makefile.am =================================================================== --- trunk/console/libgnt/wms/Makefile.am 2006-08-30 17:09:44 UTC (rev 17087) +++ trunk/console/libgnt/wms/Makefile.am 2006-08-30 17:33:44 UTC (rev 17088) @@ -1,7 +1,5 @@ s_la_LDFLAGS = -module -avoid-version $(GLIB_LIBS) -if PLUGINS - plugin_LTLIBRARIES = \ s.la @@ -9,8 +7,6 @@ s_la_SOURCES = s.c -endif # PLUGINS - EXTRA_DIST = AM_CPPFLAGS = \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-08-30 23:29:56
|
Revision: 17089 http://svn.sourceforge.net/gaim/?rev=17089&view=rev Author: sadrul Date: 2006-08-30 16:29:42 -0700 (Wed, 30 Aug 2006) Log Message: ----------- This is a little better than before. But resizing the width of a textview with a large buffer still takes too much time. Modified Paths: -------------- trunk/console/libgnt/gnt.pc.in trunk/console/libgnt/gnttextview.c trunk/console/libgnt/gnttextview.h Modified: trunk/console/libgnt/gnt.pc.in =================================================================== --- trunk/console/libgnt/gnt.pc.in 2006-08-30 17:33:44 UTC (rev 17088) +++ trunk/console/libgnt/gnt.pc.in 2006-08-30 23:29:42 UTC (rev 17089) @@ -10,4 +10,4 @@ Version: @VERSION@ Requires: glib-2.0 Cflags: -I${includedir}/gnt -Libs: -L${libdir} -lgnt -lncursesw +Libs: -L${libdir} -lgnt Modified: trunk/console/libgnt/gnttextview.c =================================================================== --- trunk/console/libgnt/gnttextview.c 2006-08-30 17:33:44 UTC (rev 17088) +++ trunk/console/libgnt/gnttextview.c 2006-08-30 23:29:42 UTC (rev 17089) @@ -10,7 +10,8 @@ { GntTextFormatFlags tvflag; chtype flags; - char *text; + int start; + int end; /* This is the next byte of the last character of this segment */ } GntTextSegment; typedef struct @@ -43,10 +44,14 @@ for (iter = line->segments; iter; iter = iter->next) { GntTextSegment *seg = iter->data; + char *end = view->string->str + seg->end; + char back = *end; + *end = '\0'; wattrset(widget->window, seg->flags); - wprintw(widget->window, "%s", seg->text); + wprintw(widget->window, "%s", (view->string->str + seg->start)); if (!iter->next) whline(widget->window, ' ' | seg->flags, widget->priv.width - line->length - 1); + *end = back; } } @@ -115,7 +120,6 @@ free_text_segment(gpointer data, gpointer null) { GntTextSegment *seg = data; - g_free(seg->text); g_free(seg); } @@ -135,6 +139,7 @@ view->list = g_list_first(view->list); g_list_foreach(view->list, free_text_line, NULL); g_list_free(view->list); + g_string_free(view->string, TRUE); } static gboolean @@ -155,6 +160,7 @@ /* This is pretty ugly, and inefficient. Someone do something about it. */ GntTextLine *line; GList *back, *iter, *list; + GString *string; int pos = 0; list = view->list; @@ -167,19 +173,30 @@ back = g_list_last(view->list); view->list = NULL; + + string = view->string; + view->string = NULL; gnt_text_view_clear(view); + view->string = g_string_set_size(view->string, string->len); + GNT_WIDGET_SET_FLAGS(GNT_WIDGET(view), GNT_WIDGET_DRAWING); + for (; back; back = back->prev) { line = back->data; - - if (back->next && !line->soft) - gnt_text_view_next_line(view); - + if (back->next && !line->soft) { + GList *llist = g_list_first(view->list); + llist = g_list_prepend(llist, g_new0(GntTextLine, 1)); + } + for (iter = line->segments; iter; iter = iter->next) { GntTextSegment *seg = iter->data; - gnt_text_view_append_text_with_flags(view, seg->text, seg->tvflag); + char *start = string->str + seg->start; + char *end = string->str + seg->end; + char back = *end; + *end = '\0'; + gnt_text_view_append_text_with_flags(view, start, seg->tvflag); + *end = back; } - free_text_line(line, NULL); } g_list_free(list); @@ -191,7 +208,9 @@ list = list->next; } view->list = list; + GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(view), GNT_WIDGET_DRAWING); gnt_widget_draw(GNT_WIDGET(view)); + g_string_free(string, TRUE); } static void @@ -267,6 +286,7 @@ GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); + view->string = g_string_new(NULL); view->list = g_list_append(view->list, line); return widget; @@ -276,61 +296,53 @@ { GntWidget *widget = GNT_WIDGET(view); int fl = 0; - char **split; - int i; + const char *start, *end; GList *list = view->list; + GntTextLine *line; + int len; if (text == NULL || *text == '\0') return; fl = gnt_text_format_flag_to_chtype(flags); + len = view->string->len; + g_string_append(view->string, text); + view->list = g_list_first(view->list); - split = g_strsplit(text, "\n", -1); - for (i = 0; split[i]; i++) - { - GntTextLine *line; - char *iter = split[i]; - int prev = 0; + start = end = view->string->str + len; - if (i) - { - line = g_new0(GntTextLine, 1); - view->list = g_list_prepend(g_list_first(view->list), line); + while (*start) { + GntTextSegment *seg; + + if (*end == '\n' || *end == '\r') { + end++; + start = end; + gnt_text_view_next_line(view); + continue; } line = view->list->data; + end = gnt_util_onscreen_width_to_pointer(start, + widget->priv.width - line->length - 1, &len); - while (iter && *iter) - { - int len; + seg = g_new0(GntTextSegment, 1); + seg->start = start - view->string->str; + seg->end = end - view->string->str; + seg->tvflag = flags; + seg->flags = fl; + line->segments = g_list_append(line->segments, seg); + line->length += len; - len = gnt_util_onscreen_width_to_pointer(iter, widget->priv.width - line->length - 1, &prev) - iter; - if (len) { - GntTextSegment *seg = g_new0(GntTextSegment, 1); - seg->flags = fl; - seg->tvflag = flags; - seg->text = g_new0(char, len + 1); - g_utf8_strncpy(seg->text, iter, g_utf8_pointer_to_offset(iter, iter + len)); - line->segments = g_list_append(line->segments, seg); - - line->length += prev; - iter += len; - if (line->length >= widget->priv.width - 1 && *iter) { - line = g_new0(GntTextLine, 1); - line->soft = TRUE; - view->list = g_list_prepend(g_list_first(view->list), line); - } - } else { - line = g_new0(GntTextLine, 1); - line->soft = TRUE; - view->list = g_list_prepend(g_list_first(view->list), line); - } + start = end; + if (*end && *end != '\n' && *end != '\r') { + line = g_new0(GntTextLine, 1); + line->soft = TRUE; + view->list = g_list_prepend(view->list, line); } } - g_strfreev(split); view->list = list; gnt_widget_draw(widget); @@ -401,6 +413,9 @@ line = g_new0(GntTextLine, 1); view->list = g_list_append(view->list, line); + if (view->string) + g_string_free(view->string, TRUE); + view->string = g_string_new(NULL); if (GNT_WIDGET(view)->window) gnt_widget_draw(GNT_WIDGET(view)); Modified: trunk/console/libgnt/gnttextview.h =================================================================== --- trunk/console/libgnt/gnttextview.h 2006-08-30 17:33:44 UTC (rev 17088) +++ trunk/console/libgnt/gnttextview.h 2006-08-30 23:29:42 UTC (rev 17089) @@ -25,6 +25,7 @@ { GntWidget parent; + GString *string; GList *list; /* List of GntTextLine */ }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-08-31 03:14:05
|
Revision: 17093 http://svn.sourceforge.net/gaim/?rev=17093&view=rev Author: sadrul Date: 2006-08-30 20:13:54 -0700 (Wed, 30 Aug 2006) Log Message: ----------- Allow different colors for highlighted windows. The name of the pair is "urgent" if you want to change it from ~/.gntrc. The default is green on the active background (or white). Red doesn't look too bad either. Modified Paths: -------------- trunk/console/libgnt/gntcolors.c trunk/console/libgnt/gntcolors.h trunk/console/libgnt/gntmain.c Modified: trunk/console/libgnt/gntcolors.c =================================================================== --- trunk/console/libgnt/gntcolors.c 2006-08-31 03:12:07 UTC (rev 17092) +++ trunk/console/libgnt/gntcolors.c 2006-08-31 03:13:54 UTC (rev 17093) @@ -81,19 +81,22 @@ init_pair(GNT_COLOR_TEXT_NORMAL, GNT_COLOR_WHITE, GNT_COLOR_BLUE); init_pair(GNT_COLOR_HIGHLIGHT_D, GNT_COLOR_BLACK, GNT_COLOR_GRAY); init_pair(GNT_COLOR_DISABLED, GNT_COLOR_GRAY, GNT_COLOR_WHITE); + init_pair(GNT_COLOR_URGENT, GNT_COLOR_WHITE, GNT_COLOR_RED); } else { - if (defaults == OK) - { + int bg; + + if (defaults == OK) { init_pair(GNT_COLOR_NORMAL, -1, -1); - init_pair(GNT_COLOR_DISABLED, COLOR_YELLOW, -1); - } - else - { + bg = -1; + } else { init_pair(GNT_COLOR_NORMAL, COLOR_BLACK, COLOR_WHITE); - init_pair(GNT_COLOR_DISABLED, COLOR_YELLOW, COLOR_WHITE); + bg = COLOR_WHITE; } + init_pair(GNT_COLOR_DISABLED, COLOR_YELLOW, bg); + init_pair(GNT_COLOR_URGENT, COLOR_GREEN, bg); + init_pair(GNT_COLOR_HIGHLIGHT, COLOR_WHITE, COLOR_BLUE); init_pair(GNT_COLOR_SHADOW, COLOR_BLACK, COLOR_BLACK); init_pair(GNT_COLOR_TITLE, COLOR_WHITE, COLOR_BLUE); @@ -231,6 +234,8 @@ type = GNT_COLOR_TEXT_NORMAL; else if (strcmp(key, "disabled") == 0) type = GNT_COLOR_DISABLED; + else if (strcmp(key, "urgent") == 0) + type = GNT_COLOR_URGENT; else continue; Modified: trunk/console/libgnt/gntcolors.h =================================================================== --- trunk/console/libgnt/gntcolors.h 2006-08-31 03:12:07 UTC (rev 17092) +++ trunk/console/libgnt/gntcolors.h 2006-08-31 03:13:54 UTC (rev 17093) @@ -16,6 +16,7 @@ GNT_COLOR_SHADOW, GNT_COLOR_TITLE, GNT_COLOR_TITLE_D, + GNT_COLOR_URGENT, /* this is for the 'urgent' windows */ GNT_COLORS } GntColorType; Modified: trunk/console/libgnt/gntmain.c =================================================================== --- trunk/console/libgnt/gntmain.c 2006-08-31 03:12:07 UTC (rev 17092) +++ trunk/console/libgnt/gntmain.c 2006-08-31 03:13:54 UTC (rev 17093) @@ -225,19 +225,14 @@ int color; const char *title; - if (w == ordered->data) - { + if (w == ordered->data) { /* This is the current window in focus */ color = GNT_COLOR_TITLE; GNT_WIDGET_UNSET_FLAGS(w, GNT_WIDGET_URGENT); - } - else if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_URGENT)) - { + } else if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_URGENT)) { /* This is a window with the URGENT hint set */ - color = GNT_COLOR_TITLE_D; - } - else - { + color = GNT_COLOR_URGENT; + } else { color = GNT_COLOR_NORMAL; } wbkgdset(taskbar, '\0' | COLOR_PAIR(color)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-08-31 06:39:27
|
Revision: 17096 http://svn.sourceforge.net/gaim/?rev=17096&view=rev Author: sadrul Date: 2006-08-30 23:39:20 -0700 (Wed, 30 Aug 2006) Log Message: ----------- Give a bit more control to the window-manager about the size/position of a window. Also, give the WM an opportunity to do its thing when the window changes something (eg. title, 'urgency'). Modified Paths: -------------- trunk/console/libgnt/gntbox.c trunk/console/libgnt/gntmain.c trunk/console/libgnt/gntwm.h trunk/console/libgnt/wms/s.c Modified: trunk/console/libgnt/gntbox.c =================================================================== --- trunk/console/libgnt/gntbox.c 2006-08-31 05:58:32 UTC (rev 17095) +++ trunk/console/libgnt/gntbox.c 2006-08-31 06:39:20 UTC (rev 17096) @@ -67,6 +67,7 @@ int pos, right; char *title = g_strdup(box->title); + mvwhline(widget->window, 0, 1, ACS_HLINE | COLOR_PAIR(GNT_COLOR_NORMAL), widget->priv.width - 2); get_title_thingies(box, title, &pos, &right); if (gnt_widget_has_focus(widget)) Modified: trunk/console/libgnt/gntmain.c =================================================================== --- trunk/console/libgnt/gntmain.c 2006-08-31 05:58:32 UTC (rev 17095) +++ trunk/console/libgnt/gntmain.c 2006-08-31 06:39:20 UTC (rev 17096) @@ -81,7 +81,11 @@ { NULL, /* new_window */ NULL, /* close_window */ + NULL, /* window_resize_confirm */ NULL, /* window_resized */ + NULL, /* window_move_confirm */ + NULL, /* window_moved */ + NULL, /* window_update */ NULL, /* key_pressed */ NULL, /* mouse clicked */ bring_on_top, /* give_focus */ @@ -229,6 +233,10 @@ /* This is the current window in focus */ color = GNT_COLOR_TITLE; GNT_WIDGET_UNSET_FLAGS(w, GNT_WIDGET_URGENT); + if (wm.window_update) { + GntNode *node = g_hash_table_lookup(nodes, w); + wm.window_update(node->panel, w); + } } else if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_URGENT)) { /* This is a window with the URGENT hint set */ color = GNT_COLOR_URGENT; @@ -1145,6 +1153,12 @@ return; GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_URGENT); + + if (wm.window_update) { + GntNode *node = g_hash_table_lookup(nodes, widget); + wm.window_update(node->panel, widget); + } + draw_taskbar(FALSE); } @@ -1168,6 +1182,9 @@ if (!node) return; + if (wm.window_resize_confirm && !wm.window_resize_confirm(widget, &width, &height)) + return; + hide_panel(node->panel); gnt_widget_set_size(widget, width, height); gnt_widget_draw(widget); @@ -1183,8 +1200,16 @@ void gnt_screen_move_widget(GntWidget *widget, int x, int y) { GntNode *node = g_hash_table_lookup(nodes, widget); + + if (wm.window_move_confirm && !wm.window_move_confirm(widget, &x, &y)) + return; + gnt_widget_set_position(widget, x, y); move_panel(node->panel, y, x); + + if (wm.window_moved) + wm.window_moved(node->panel, widget); + update_screen(NULL); } @@ -1192,6 +1217,12 @@ { gnt_box_set_title(GNT_BOX(widget), text); gnt_widget_draw(widget); + + if (wm.window_update) { + GntNode *node = g_hash_table_lookup(nodes, widget); + wm.window_update(node->panel, widget); + } + draw_taskbar(FALSE); } Modified: trunk/console/libgnt/gntwm.h =================================================================== --- trunk/console/libgnt/gntwm.h 2006-08-31 05:58:32 UTC (rev 17095) +++ trunk/console/libgnt/gntwm.h 2006-08-31 06:39:20 UTC (rev 17096) @@ -6,6 +6,8 @@ #include "gntwidget.h" +/* XXX: It might be a good idea to move GntNode from gntmain.c to here. */ + typedef struct _GntWM GntWM; struct _GntWM @@ -16,10 +18,24 @@ /* This is called when a window is being closed */ gboolean (*close_window)(GntWidget *win); + /* The WM may want to confirm a size for a window first */ + gboolean (*window_resize_confirm)(GntWidget *win, int *w, int *h); + /* Can del_panel the old panel and return a new_panel. * Otherwise, this should at least do a replace_panel. */ PANEL *(*window_resized)(PANEL *pan, GntWidget *win); + /* The WM may want to confirm the position of a window */ + gboolean (*window_move_confirm)(GntWidget *win, int *x, int *y); + + void (*window_moved)(PANEL *pan, GntWidget *win); + + /* This gets called when: + * - the title of the window changes + * - the 'urgency' of the window changes + */ + void (*window_update)(PANEL *pan, GntWidget *win); + /* This should usually return NULL if the keys were processed by the WM. * If not, the WM can simply return the original string, which will be * processed by the default WM. The custom WM can also return a different Modified: trunk/console/libgnt/wms/s.c =================================================================== --- trunk/console/libgnt/wms/s.c 2006-08-31 05:58:32 UTC (rev 17095) +++ trunk/console/libgnt/wms/s.c 2006-08-31 06:39:20 UTC (rev 17096) @@ -156,6 +156,14 @@ return FALSE; } +static void +s_window_update(PANEL *panel, GntWidget *window) +{ + const char *name = gnt_widget_get_name(window); + if (name && strcmp(name, "buddylist")) + envelope_normal_window(window); +} + void gntwm_init(GntWM *wm) { gwm = wm; @@ -163,5 +171,6 @@ wm->window_resized = s_resize_window; wm->key_pressed = s_key_pressed; wm->mouse_clicked = s_mouse_clicked; + wm->window_update = s_window_update; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-09-01 02:45:54
|
Revision: 17105 http://svn.sourceforge.net/gaim/?rev=17105&view=rev Author: sadrul Date: 2006-08-31 19:44:46 -0700 (Thu, 31 Aug 2006) Log Message: ----------- fix the bug in textview Modified Paths: -------------- trunk/console/libgnt/gnttextview.c trunk/console/libgnt/gntutils.h trunk/console/libgnt/test/tv.c Modified: trunk/console/libgnt/gnttextview.c =================================================================== --- trunk/console/libgnt/gnttextview.c 2006-09-01 02:07:23 UTC (rev 17104) +++ trunk/console/libgnt/gnttextview.c 2006-09-01 02:44:46 UTC (rev 17105) @@ -324,9 +324,18 @@ } line = view->list->data; - end = gnt_util_onscreen_width_to_pointer(start, - widget->priv.width - line->length - 1, &len); + if ((end = strchr(start, '\n')) != NULL || + (end = strchr(start, '\r')) != NULL) { + int l = gnt_util_onscreen_width(start, end - 1); + if (l >= widget->priv.width - line->length - 1) { + end = NULL; + } + } + if (end == NULL) + end = gnt_util_onscreen_width_to_pointer(start, + widget->priv.width - line->length - 1, &len); + seg = g_new0(GntTextSegment, 1); seg->start = start - view->string->str; seg->end = end - view->string->str; Modified: trunk/console/libgnt/gntutils.h =================================================================== --- trunk/console/libgnt/gntutils.h 2006-09-01 02:07:23 UTC (rev 17104) +++ trunk/console/libgnt/gntutils.h 2006-09-01 02:44:46 UTC (rev 17105) @@ -5,6 +5,7 @@ void gnt_util_get_text_bound(const char *text, int *width, int *height); +/* excluding *end */ int gnt_util_onscreen_width(const char *start, const char *end); char *gnt_util_onscreen_width_to_pointer(const char *str, int len, int *w); Modified: trunk/console/libgnt/test/tv.c =================================================================== --- trunk/console/libgnt/test/tv.c 2006-09-01 02:07:23 UTC (rev 17104) +++ trunk/console/libgnt/test/tv.c 2006-09-01 02:44:46 UTC (rev 17105) @@ -83,6 +83,18 @@ gnt_entry_set_history_length(GNT_ENTRY(entry), -1); g_signal_connect_after(G_OBJECT(entry), "key_pressed", G_CALLBACK(key_pressed), view); + gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "plugins: ", GNT_TEXT_FLAG_BOLD); + gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "this is the 1st line\n", GNT_TEXT_FLAG_NORMAL); + + gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "plugins: ", GNT_TEXT_FLAG_BOLD); + gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "this is the 2nd line\n", GNT_TEXT_FLAG_NORMAL); + + gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "plugins: ", GNT_TEXT_FLAG_BOLD); + gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "this is the 3rd line\n", GNT_TEXT_FLAG_NORMAL); + + gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "plugins: ", GNT_TEXT_FLAG_BOLD); + gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "this is the 4th line\n", GNT_TEXT_FLAG_NORMAL); + #ifdef STANDALONE gnt_main(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ebl...@us...> - 2006-09-02 16:55:47
|
Revision: 17127 http://svn.sourceforge.net/gaim/?rev=17127&view=rev Author: eblanton Date: 2006-09-02 09:55:32 -0700 (Sat, 02 Sep 2006) Log Message: ----------- This fixes titles containing double-column wide characters for me. Editing of double-column characters in gntentry remains a bit bustinated (though it is my recollection that it worked at one time). This additionally does not require wcwidth() and its attendant funkiness. The version of gnt_util_onscreen_width_to_pointer in this commit *appears* to do what the extant version was supposed to do, though I'm not sure I grokked it fully; it does correct the rendering glitches for me. I'm not at all comfortable with the de-constification of the input string and attendant return of the de-constified pointer. Sadrul will have to let me know what is supposed to happen there. Output on non-UTF-8 terminals is not correct, but was not correct before, either. Modified Paths: -------------- trunk/console/libgnt/configure.ac trunk/console/libgnt/gntutils.c Modified: trunk/console/libgnt/configure.ac =================================================================== --- trunk/console/libgnt/configure.ac 2006-09-02 07:38:08 UTC (rev 17126) +++ trunk/console/libgnt/configure.ac 2006-09-02 16:55:32 UTC (rev 17127) @@ -198,7 +198,7 @@ AC_CHECK_HEADERS(sys/file.h sys/filio.h sys/ioctl.h sys/msgbuf.h) AC_CHECK_HEADERS(sys/select.h sys/uio.h sys/utsname.h sys/wait.h) AC_CHECK_HEADERS(termios.h) -AC_CHECK_FUNC(wcwidth, [AC_DEFINE([HAVE_WCWIDTH], [1], [Define to 1 if you have wcwidth function.])]) +#AC_CHECK_FUNC(wcwidth, [AC_DEFINE([HAVE_WCWIDTH], [1], [Define to 1 if you have wcwidth function.])]) #AC_VAR_TIMEZONE_EXTERNALS AC_CHECK_LIB(ncursesw, initscr, , [AC_MSG_ERROR([ Modified: trunk/console/libgnt/gntutils.c =================================================================== --- trunk/console/libgnt/gntutils.c 2006-09-02 07:38:08 UTC (rev 17126) +++ trunk/console/libgnt/gntutils.c 2006-09-02 16:55:32 UTC (rev 17127) @@ -5,14 +5,6 @@ #include "config.h" -#ifndef HAVE_WCWIDTH -#define wcwidth(X) 1 -#else -#define __USE_XOPEN -#endif - -#include <wchar.h> - void gnt_util_get_text_bound(const char *text, int *width, int *height) { const char *s = text, *last; @@ -49,47 +41,30 @@ int gnt_util_onscreen_width(const char *start, const char *end) { - wchar_t wch; - int size; int width = 0; while (start < end) { - if ((size = mbtowc(&wch, start, end - start)) > 0) { - start += size; - width += wcwidth(wch); - } else { - ++width; - ++start; - } + width += g_unichar_iswide(g_utf8_get_char(start)) ? 2 : 1; + start = g_utf8_next_char(start); } return width; } char *gnt_util_onscreen_width_to_pointer(const char *string, int len, int *w) { - wchar_t wch; int size; int width = 0; char *str = (char*)string; - int slen = strlen(string); /* Yeah, no. of bytes */ while (width < len && *str) { - if ((size = mbtowc(&wch, str, slen)) > 0) { - if (width + wcwidth(wch) > len) - break; - str += size; - width += wcwidth(wch); - slen -= size; - } else { - ++str; - ++width; - --slen; - } + size = g_unichar_iswide(g_utf8_get_char(str)) ? 2 : 1; + if (width + size > len) + break; + str = g_utf8_next_char(str); + width += size; } - if (w) *w = width; - return str; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-09-02 18:56:23
|
Revision: 17128 http://svn.sourceforge.net/gaim/?rev=17128&view=rev Author: sadrul Date: 2006-09-02 11:55:27 -0700 (Sat, 02 Sep 2006) Log Message: ----------- Keep things neat and clean in gnt_util_onscreen_width_to_pointer. The only use of this function currently is to truncate a string to make sure it fits in the drawing area, eg, the title of a window, or in the combobox. The function is called on a newly allocated string, which is truncated (if necessary), printed, and freed. Modified Paths: -------------- trunk/console/libgnt/gntbox.c trunk/console/libgnt/gntcombobox.c trunk/console/libgnt/gntutils.c trunk/console/libgnt/gntutils.h trunk/console/libgnt/test/focus.c Modified: trunk/console/libgnt/gntbox.c =================================================================== --- trunk/console/libgnt/gntbox.c 2006-09-02 16:55:32 UTC (rev 17127) +++ trunk/console/libgnt/gntbox.c 2006-09-02 18:55:27 UTC (rev 17128) @@ -30,7 +30,7 @@ { GntWidget *widget = GNT_WIDGET(box); int len; - char *end = gnt_util_onscreen_width_to_pointer(title, widget->priv.width - 4, &len); + char *end = (char*)gnt_util_onscreen_width_to_pointer(title, widget->priv.width - 4, &len); if (p) *p = (widget->priv.width - len) / 2; Modified: trunk/console/libgnt/gntcombobox.c =================================================================== --- trunk/console/libgnt/gntcombobox.c 2006-09-02 16:55:32 UTC (rev 17127) +++ trunk/console/libgnt/gntcombobox.c 2006-09-02 18:55:27 UTC (rev 17128) @@ -36,7 +36,7 @@ gnt_combo_box_draw(GntWidget *widget) { GntComboBox *box = GNT_COMBO_BOX(widget); - char *text = NULL; + char *text = NULL, *s; GntColorType type; int len; @@ -53,12 +53,8 @@ wbkgdset(widget->window, '\0' | COLOR_PAIR(type)); - if ((len = g_utf8_strlen(text, -1)) > widget->priv.width - 4) - { - char *s = gnt_util_onscreen_width_to_pointer(text, widget->priv.width - 4, NULL); - *s = '\0'; - len = widget->priv.width - 4; - } + s = (char*)gnt_util_onscreen_width_to_pointer(text, widget->priv.width - 4, &len); + *s = '\0'; mvwprintw(widget->window, 1, 1, text); whline(widget->window, ' ' | COLOR_PAIR(type), widget->priv.width - 4 - len); Modified: trunk/console/libgnt/gntutils.c =================================================================== --- trunk/console/libgnt/gntutils.c 2006-09-02 16:55:32 UTC (rev 17127) +++ trunk/console/libgnt/gntutils.c 2006-09-02 18:55:27 UTC (rev 17128) @@ -20,15 +20,15 @@ if (*s == '\n' || *s == '\r') { count++; - len = g_utf8_pointer_to_offset(last, s); + len = gnt_util_onscreen_width(last, s); if (max < len) max = len; last = s + 1; } - s++; + s = g_utf8_next_char(s); } - len = g_utf8_pointer_to_offset(last, s); + len = gnt_util_onscreen_width(last, s); if (max < len) max = len; } @@ -50,11 +50,11 @@ return width; } -char *gnt_util_onscreen_width_to_pointer(const char *string, int len, int *w) +const char *gnt_util_onscreen_width_to_pointer(const char *string, int len, int *w) { int size; int width = 0; - char *str = (char*)string; + const char *str = string; while (width < len && *str) { size = g_unichar_iswide(g_utf8_get_char(str)) ? 2 : 1; Modified: trunk/console/libgnt/gntutils.h =================================================================== --- trunk/console/libgnt/gntutils.h 2006-09-02 16:55:32 UTC (rev 17127) +++ trunk/console/libgnt/gntutils.h 2006-09-02 18:55:27 UTC (rev 17128) @@ -8,4 +8,4 @@ /* excluding *end */ int gnt_util_onscreen_width(const char *start, const char *end); -char *gnt_util_onscreen_width_to_pointer(const char *str, int len, int *w); +const char *gnt_util_onscreen_width_to_pointer(const char *str, int len, int *w); Modified: trunk/console/libgnt/test/focus.c =================================================================== --- trunk/console/libgnt/test/focus.c 2006-09-02 16:55:32 UTC (rev 17127) +++ trunk/console/libgnt/test/focus.c 2006-09-02 18:55:27 UTC (rev 17128) @@ -25,7 +25,7 @@ gnt_init(); #endif - GntWidget *label = gnt_label_new("So wassup dudes and dudettes!!\nSo this is, like,\nthe third line!! \\o/"); + GntWidget *label = gnt_label_new("So wassup dudes and dudettes!!\u4e0a1\u6d772\u67003\u4f4e4\u67085\nSo this is, like,\nthe third line!! \\o/"); GntWidget *vbox, *hbox, *tree, *box, *button; WINDOW *test; @@ -61,7 +61,7 @@ gnt_tree_add_choice(GNT_TREE(tree), "b", gnt_tree_create_row(GNT_TREE(tree), "b"), "d", NULL); GNT_WIDGET_UNSET_FLAGS(hbox, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); - gnt_box_set_title(GNT_BOX(hbox), "This is the title …"); + gnt_box_set_title(GNT_BOX(hbox), "\u4e0a\u6d77\u6700\u4f4e\u6708\u5de5 …"); g_signal_connect(G_OBJECT(tree), "toggled", G_CALLBACK(toggled), NULL); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-09-02 23:06:43
|
Revision: 17131 http://svn.sourceforge.net/gaim/?rev=17131&view=rev Author: sadrul Date: 2006-09-02 16:06:25 -0700 (Sat, 02 Sep 2006) Log Message: ----------- Try to make sure the strings are not too long to get out of the range of the screen. Modified Paths: -------------- trunk/console/libgnt/gntlabel.c trunk/console/libgnt/gntutils.c trunk/console/libgnt/gntutils.h Modified: trunk/console/libgnt/gntlabel.c =================================================================== --- trunk/console/libgnt/gntlabel.c 2006-09-02 20:17:43 UTC (rev 17130) +++ trunk/console/libgnt/gntlabel.c 2006-09-02 23:06:25 UTC (rev 17131) @@ -101,7 +101,7 @@ GntWidget *widget = g_object_new(GNT_TYPE_LABEL, NULL); GntLabel *label = GNT_LABEL(widget); - label->text = g_strdup(text); + label->text = gnt_util_onscreen_fit_string(text, -1); label->flags = flags; gnt_widget_set_take_focus(widget, FALSE); GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); @@ -112,7 +112,7 @@ void gnt_label_set_text(GntLabel *label, const char *text) { g_free(label->text); - label->text = g_strdup(text); + label->text = gnt_util_onscreen_fit_string(text, -1); if (GNT_WIDGET(label)->window) { Modified: trunk/console/libgnt/gntutils.c =================================================================== --- trunk/console/libgnt/gntutils.c 2006-09-02 20:17:43 UTC (rev 17130) +++ trunk/console/libgnt/gntutils.c 2006-09-02 23:06:25 UTC (rev 17131) @@ -68,3 +68,32 @@ return str; } +char *gnt_util_onscreen_fit_string(const char *string, int maxw) +{ + const char *start, *end; + GString *str; + + if (maxw <= 0) + maxw = getmaxx(stdscr) - 4; + + start = string; + str = g_string_new(NULL); + + while (*start) { + if ((end = strchr(start, '\n')) != NULL || + (end = strchr(start, '\r')) != NULL) { + if (gnt_util_onscreen_width(start, end) <= maxw) { + ++end; + } else + end = NULL; + } + if (end == NULL) + end = gnt_util_onscreen_width_to_pointer(start, maxw, NULL); + str = g_string_append_len(str, start, end - start); + start = end; + if (*end && *end != '\n' && *end != '\r') + str = g_string_append_c(str, '\n'); + } + return g_string_free(str, FALSE); +} + Modified: trunk/console/libgnt/gntutils.h =================================================================== --- trunk/console/libgnt/gntutils.h 2006-09-02 20:17:43 UTC (rev 17130) +++ trunk/console/libgnt/gntutils.h 2006-09-02 23:06:25 UTC (rev 17131) @@ -9,3 +9,11 @@ int gnt_util_onscreen_width(const char *start, const char *end); const char *gnt_util_onscreen_width_to_pointer(const char *str, int len, int *w); + +/* Inserts newlines in 'string' where necessary so that its onscreen width is + * no more than 'maxw'. + * 'maxw' can be <= 0, in which case the maximum screen width is considered. + * + * Returns a newly allocated string. + */ +char *gnt_util_onscreen_fit_string(const char *string, int maxw); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-09-02 23:23:37
|
Revision: 17132 http://svn.sourceforge.net/gaim/?rev=17132&view=rev Author: sadrul Date: 2006-09-02 16:23:30 -0700 (Sat, 02 Sep 2006) Log Message: ----------- Do the same for the texts in buttons, and minor adjustments. Modified Paths: -------------- trunk/console/libgnt/gntbutton.c trunk/console/libgnt/gntutils.c Modified: trunk/console/libgnt/gntbutton.c =================================================================== --- trunk/console/libgnt/gntbutton.c 2006-09-02 23:06:25 UTC (rev 17131) +++ trunk/console/libgnt/gntbutton.c 2006-09-02 23:23:30 UTC (rev 17132) @@ -128,7 +128,7 @@ GntWidget *widget = g_object_new(GNT_TYPE_BUTTON, NULL); GntButton *button = GNT_BUTTON(widget); - button->priv->text = g_strdup(text); + button->priv->text = gnt_util_onscreen_fit_string(text, -1); gnt_widget_set_take_focus(widget, TRUE); return widget; Modified: trunk/console/libgnt/gntutils.c =================================================================== --- trunk/console/libgnt/gntutils.c 2006-09-02 23:06:25 UTC (rev 17131) +++ trunk/console/libgnt/gntutils.c 2006-09-02 23:23:30 UTC (rev 17132) @@ -82,17 +82,18 @@ while (*start) { if ((end = strchr(start, '\n')) != NULL || (end = strchr(start, '\r')) != NULL) { - if (gnt_util_onscreen_width(start, end) <= maxw) { - ++end; - } else + if (gnt_util_onscreen_width(start, end) > maxw) end = NULL; } if (end == NULL) end = gnt_util_onscreen_width_to_pointer(start, maxw, NULL); str = g_string_append_len(str, start, end - start); + if (*end) { + str = g_string_append_c(str, '\n'); + if (*end == '\n' || *end == '\r') + end++; + } start = end; - if (*end && *end != '\n' && *end != '\r') - str = g_string_append_c(str, '\n'); } return g_string_free(str, FALSE); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-09-03 21:43:12
|
Revision: 17146 http://svn.sourceforge.net/gaim/?rev=17146&view=rev Author: sadrul Date: 2006-09-03 14:42:52 -0700 (Sun, 03 Sep 2006) Log Message: ----------- This will get rid of the compile warnings about redefining DEBUG. I thought about #undef-ing it first. But rekkanoryo suggested renaming to GNTDEBUG, which makes a lot more sense. Modified Paths: -------------- trunk/console/libgnt/gnt-skel.c trunk/console/libgnt/gntbox.c trunk/console/libgnt/gntbutton.c trunk/console/libgnt/gntcheckbox.c trunk/console/libgnt/gntcombobox.c trunk/console/libgnt/gntentry.c trunk/console/libgnt/gntlabel.c trunk/console/libgnt/gntline.c trunk/console/libgnt/gnttextview.c trunk/console/libgnt/gnttree.c trunk/console/libgnt/gntwidget.c trunk/console/libgnt/gntwidget.h Modified: trunk/console/libgnt/gnt-skel.c =================================================================== --- trunk/console/libgnt/gnt-skel.c 2006-09-03 21:22:14 UTC (rev 17145) +++ trunk/console/libgnt/gnt-skel.c 2006-09-03 21:42:52 UTC (rev 17146) @@ -11,7 +11,7 @@ static void gnt_skel_draw(GntWidget *widget) { - DEBUG; + GNTDEBUG; } static void @@ -24,7 +24,7 @@ { if (widget->priv.width == 0 || widget->priv.height == 0) gnt_widget_size_request(widget); - DEBUG; + GNTDEBUG; } static gboolean @@ -50,13 +50,13 @@ parent_class->size_request = gnt_skel_size_request; parent_class->key_pressed = gnt_skel_key_pressed; - DEBUG; + GNTDEBUG; } static void gnt_skel_init(GTypeInstance *instance, gpointer class) { - DEBUG; + GNTDEBUG; } /****************************************************************************** Modified: trunk/console/libgnt/gntbox.c =================================================================== --- trunk/console/libgnt/gntbox.c 2006-09-03 21:22:14 UTC (rev 17145) +++ trunk/console/libgnt/gntbox.c 2006-09-03 21:42:52 UTC (rev 17146) @@ -68,7 +68,7 @@ g_free(title); } - DEBUG; + GNTDEBUG; } static void @@ -215,7 +215,7 @@ gnt_widget_size_request(widget); find_focusable_widget(GNT_BOX(widget)); } - DEBUG; + GNTDEBUG; } /* Ensures that the current widget can take focus */ @@ -498,7 +498,7 @@ parent_class->confirm_size = gnt_box_confirm_size; parent_class->size_changed = gnt_box_size_changed; - DEBUG; + GNTDEBUG; } static void @@ -507,7 +507,7 @@ /* Initially make both the height and width resizable. * Update the flags as necessary when widgets are added to it. */ GNT_WIDGET_SET_FLAGS(GNT_WIDGET(instance), GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y); - DEBUG; + GNTDEBUG; } /****************************************************************************** Modified: trunk/console/libgnt/gntbutton.c =================================================================== --- trunk/console/libgnt/gntbutton.c 2006-09-03 21:22:14 UTC (rev 17145) +++ trunk/console/libgnt/gntbutton.c 2006-09-03 21:42:52 UTC (rev 17146) @@ -25,7 +25,7 @@ wbkgdset(widget->window, '\0' | COLOR_PAIR(type)); mvwprintw(widget->window, 1, 2, button->priv->text); - DEBUG; + GNTDEBUG; } static void @@ -44,7 +44,7 @@ { if (widget->priv.width == 0 || widget->priv.height == 0) gnt_widget_size_request(widget); - DEBUG; + GNTDEBUG; } static gboolean @@ -78,7 +78,7 @@ parent_class->key_pressed = gnt_button_key_pressed; parent_class->clicked = gnt_button_clicked; - DEBUG; + GNTDEBUG; } static void @@ -92,7 +92,7 @@ widget->priv.minw = 4; widget->priv.minh = 3; - DEBUG; + GNTDEBUG; } /****************************************************************************** Modified: trunk/console/libgnt/gntcheckbox.c =================================================================== --- trunk/console/libgnt/gntcheckbox.c 2006-09-03 21:22:14 UTC (rev 17145) +++ trunk/console/libgnt/gntcheckbox.c 2006-09-03 21:42:52 UTC (rev 17146) @@ -30,7 +30,7 @@ wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); mvwprintw(widget->window, 0, 4, GNT_BUTTON(cb)->priv->text); - DEBUG; + GNTDEBUG; } static void @@ -43,7 +43,7 @@ { if (widget->priv.width == 0 || widget->priv.height == 0) gnt_widget_size_request(widget); - DEBUG; + GNTDEBUG; } static void @@ -102,14 +102,14 @@ NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - DEBUG; + GNTDEBUG; } static void gnt_check_box_init(GTypeInstance *instance, gpointer class) { GNT_WIDGET_SET_FLAGS(GNT_WIDGET(instance), GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); - DEBUG; + GNTDEBUG; } /****************************************************************************** Modified: trunk/console/libgnt/gntcombobox.c =================================================================== --- trunk/console/libgnt/gntcombobox.c 2006-09-03 21:22:14 UTC (rev 17145) +++ trunk/console/libgnt/gntcombobox.c 2006-09-03 21:42:52 UTC (rev 17146) @@ -62,7 +62,7 @@ mvwaddch(widget->window, 1, widget->priv.width - 2, ACS_DARROW | COLOR_PAIR(GNT_COLOR_NORMAL)); g_free(text); - DEBUG; + GNTDEBUG; } static void @@ -82,7 +82,7 @@ { if (widget->priv.width == 0 || widget->priv.height == 0) gnt_widget_size_request(widget); - DEBUG; + GNTDEBUG; } static void @@ -208,7 +208,7 @@ gnt_closure_marshal_VOID__POINTER_POINTER, G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER); - DEBUG; + GNTDEBUG; } static void @@ -229,7 +229,7 @@ widget->priv.minw = 4; widget->priv.minh = 3; - DEBUG; + GNTDEBUG; } /****************************************************************************** Modified: trunk/console/libgnt/gntentry.c =================================================================== --- trunk/console/libgnt/gntentry.c 2006-09-03 21:22:14 UTC (rev 17145) +++ trunk/console/libgnt/gntentry.c 2006-09-03 21:42:52 UTC (rev 17146) @@ -129,7 +129,7 @@ mvwchgat(widget->window, 0, gnt_util_onscreen_width(entry->scroll, entry->cursor), 1, A_REVERSE, COLOR_PAIR(GNT_COLOR_TEXT_NORMAL), NULL); - DEBUG; + GNTDEBUG; } static void @@ -147,7 +147,7 @@ { if (widget->priv.width == 0 || widget->priv.height == 0) gnt_widget_size_request(widget); - DEBUG; + GNTDEBUG; } static void @@ -502,7 +502,7 @@ parent_class->key_pressed = gnt_entry_key_pressed; parent_class->lost_focus = gnt_entry_lost_focus; - DEBUG; + GNTDEBUG; } static void @@ -528,7 +528,7 @@ widget->priv.minw = 3; widget->priv.minh = 1; - DEBUG; + GNTDEBUG; } /****************************************************************************** Modified: trunk/console/libgnt/gntlabel.c =================================================================== --- trunk/console/libgnt/gntlabel.c 2006-09-03 21:22:14 UTC (rev 17145) +++ trunk/console/libgnt/gntlabel.c 2006-09-03 21:42:52 UTC (rev 17146) @@ -27,7 +27,7 @@ wbkgdset(widget->window, '\0' | flag); mvwprintw(widget->window, 0, 0, label->text); - DEBUG; + GNTDEBUG; } static void @@ -48,7 +48,7 @@ parent_class->map = NULL; parent_class->size_request = gnt_label_size_request; - DEBUG; + GNTDEBUG; } static void @@ -58,7 +58,7 @@ GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X); widget->priv.minw = 3; widget->priv.minh = 1; - DEBUG; + GNTDEBUG; } /****************************************************************************** Modified: trunk/console/libgnt/gntline.c =================================================================== --- trunk/console/libgnt/gntline.c 2006-09-03 21:22:14 UTC (rev 17145) +++ trunk/console/libgnt/gntline.c 2006-09-03 21:42:52 UTC (rev 17146) @@ -40,7 +40,7 @@ { if (widget->priv.width == 0 || widget->priv.height == 0) gnt_widget_size_request(widget); - DEBUG; + GNTDEBUG; } static void @@ -51,7 +51,7 @@ parent_class->map = gnt_line_map; parent_class->size_request = gnt_line_size_request; - DEBUG; + GNTDEBUG; } static void @@ -61,7 +61,7 @@ GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW | GNT_WIDGET_NO_BORDER); widget->priv.minw = 1; widget->priv.minh = 1; - DEBUG; + GNTDEBUG; } /****************************************************************************** Modified: trunk/console/libgnt/gnttextview.c =================================================================== --- trunk/console/libgnt/gnttextview.c 2006-09-03 21:22:14 UTC (rev 17145) +++ trunk/console/libgnt/gnttextview.c 2006-09-03 21:42:52 UTC (rev 17146) @@ -92,7 +92,7 @@ ((view->list && view->list->prev) ? ACS_DARROW : ' ') | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D)); - DEBUG; + GNTDEBUG; } static void @@ -109,7 +109,7 @@ { if (widget->priv.width == 0 || widget->priv.height == 0) gnt_widget_size_request(widget); - DEBUG; + GNTDEBUG; } static gboolean @@ -235,7 +235,7 @@ parent_class->clicked = gnt_text_view_clicked; parent_class->size_changed = gnt_text_view_size_changed; - DEBUG; + GNTDEBUG; } static void @@ -247,7 +247,7 @@ widget->priv.minw = 5; widget->priv.minh = 2; - DEBUG; + GNTDEBUG; } /****************************************************************************** Modified: trunk/console/libgnt/gnttree.c =================================================================== --- trunk/console/libgnt/gnttree.c 2006-09-03 21:22:14 UTC (rev 17145) +++ trunk/console/libgnt/gnttree.c 2006-09-03 21:42:52 UTC (rev 17146) @@ -419,7 +419,7 @@ redraw_tree(tree); - DEBUG; + GNTDEBUG; } static void @@ -447,7 +447,7 @@ } tree->top = tree->root; tree->current = tree->root; - DEBUG; + GNTDEBUG; } static void @@ -689,7 +689,7 @@ g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); - DEBUG; + GNTDEBUG; } static void @@ -699,7 +699,7 @@ GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y); widget->priv.minw = 4; widget->priv.minh = 4; - DEBUG; + GNTDEBUG; } /****************************************************************************** Modified: trunk/console/libgnt/gntwidget.c =================================================================== --- trunk/console/libgnt/gntwidget.c 2006-09-03 21:22:14 UTC (rev 17145) +++ trunk/console/libgnt/gntwidget.c 2006-09-03 21:42:52 UTC (rev 17146) @@ -33,14 +33,14 @@ { GntWidget *widget = GNT_WIDGET(instance); widget->priv.name = NULL; - DEBUG; + GNTDEBUG; } static void gnt_widget_map(GntWidget *widget) { /* Get some default size for the widget */ - DEBUG; + GNTDEBUG; g_signal_emit(widget, signals[SIG_MAP], 0); GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_MAPPED); } @@ -59,7 +59,7 @@ } parent_class->dispose(obj); - DEBUG; + GNTDEBUG; } static void @@ -225,7 +225,7 @@ gnt_closure_marshal_BOOLEAN__INT_INT_INT, G_TYPE_BOOLEAN, 3, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT); - DEBUG; + GNTDEBUG; } /****************************************************************************** @@ -305,7 +305,7 @@ delwin(obj->window); if(!(GNT_WIDGET_FLAGS(obj) & GNT_WIDGET_DESTROYING)) g_object_run_dispose(G_OBJECT(obj)); - DEBUG; + GNTDEBUG; } void Modified: trunk/console/libgnt/gntwidget.h =================================================================== --- trunk/console/libgnt/gntwidget.h 2006-09-03 21:22:14 UTC (rev 17145) +++ trunk/console/libgnt/gntwidget.h 2006-09-03 21:42:52 UTC (rev 17146) @@ -19,8 +19,9 @@ #define GNT_WIDGET_SET_FLAGS(obj, flags) (GNT_WIDGET_FLAGS(obj) |= flags) #define GNT_WIDGET_UNSET_FLAGS(obj, flags) (GNT_WIDGET_FLAGS(obj) &= ~(flags)) #define GNT_WIDGET_IS_FLAG_SET(obj, flags) (GNT_WIDGET_FLAGS(obj) & (flags)) -#define DEBUG fprintf(stderr, "%s\n", __FUNCTION__) +#define GNTDEBUG fprintf(stderr, "%s\n", __FUNCTION__) + typedef struct _GnWidget GntWidget; typedef struct _GnWidgetPriv GntWidgetPriv; typedef struct _GnWidgetClass GntWidgetClass; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-09-24 07:19:59
|
Revision: 17341 http://svn.sourceforge.net/gaim/?rev=17341&view=rev Author: sadrul Date: 2006-09-24 00:14:26 -0700 (Sun, 24 Sep 2006) Log Message: ----------- Menus and windows. I have added a test-app test/menu.c to show how to use it. Pressing Ctrl+o brings up the menu for the window (if it has one). It should now be possible to add menus for account-actions and all that stuff. Patches are very welcome. Modified Paths: -------------- trunk/console/libgnt/Makefile.am trunk/console/libgnt/gnt.h trunk/console/libgnt/gntbox.c trunk/console/libgnt/gntmain.c trunk/console/libgnt/gnttree.c trunk/console/libgnt/gnttree.h trunk/console/libgnt/gntwidget.c trunk/console/libgnt/gntwidget.h trunk/console/libgnt/test/Makefile trunk/console/libgnt/test/focus.c trunk/console/libgnt/wms/s.c Added Paths: ----------- trunk/console/libgnt/gntmenu.c trunk/console/libgnt/gntmenu.h trunk/console/libgnt/gntmenuitem.c trunk/console/libgnt/gntmenuitem.h trunk/console/libgnt/gntwindow.c trunk/console/libgnt/gntwindow.h trunk/console/libgnt/test/menu.c Modified: trunk/console/libgnt/Makefile.am =================================================================== --- trunk/console/libgnt/Makefile.am 2006-09-23 19:04:03 UTC (rev 17340) +++ trunk/console/libgnt/Makefile.am 2006-09-24 07:14:26 UTC (rev 17341) @@ -16,10 +16,13 @@ gntlabel.c \ gntline.c \ gntmarshal.c \ + gntmenu.c \ + gntmenuitem.c \ gntstyle.c \ gnttextview.c \ gnttree.c \ gntutils.c \ + gntwindow.c \ gntmain.c libgnt_la_headers = \ @@ -34,10 +37,13 @@ gntlabel.h \ gntline.h \ gntmarshal.h \ + gntmenu.h \ + gntmenuitem.h \ gntstyle.h \ gnttextview.h \ gnttree.h \ gntutils.h \ + gntwindow.h \ gntwm.h \ gnt.h Modified: trunk/console/libgnt/gnt.h =================================================================== --- trunk/console/libgnt/gnt.h 2006-09-23 19:04:03 UTC (rev 17340) +++ trunk/console/libgnt/gnt.h 2006-09-24 07:14:26 UTC (rev 17341) @@ -29,5 +29,7 @@ void gnt_register_action(const char *label, void (*callback)()); +gboolean gnt_screen_menu_show(gpointer menu); + void gnt_quit(); Modified: trunk/console/libgnt/gntbox.c =================================================================== --- trunk/console/libgnt/gntbox.c 2006-09-23 19:04:03 UTC (rev 17340) +++ trunk/console/libgnt/gntbox.c 2006-09-24 07:14:26 UTC (rev 17341) @@ -504,9 +504,15 @@ static void gnt_box_init(GTypeInstance *instance, gpointer class) { + GntWidget *widget = GNT_WIDGET(instance); + GntBox *box = GNT_BOX(widget); /* Initially make both the height and width resizable. * Update the flags as necessary when widgets are added to it. */ - GNT_WIDGET_SET_FLAGS(GNT_WIDGET(instance), GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y); + GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y); + GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS); + GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); + box->pad = 1; + box->fill = TRUE; GNTDEBUG; } @@ -547,14 +553,7 @@ box->homogeneous = homo; box->vertical = vert; - box->pad = 1; - box->fill = TRUE; - gnt_widget_set_take_focus(widget, TRUE); - GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); - if (vert) - box->alignment = GNT_ALIGN_LEFT; - else - box->alignment = GNT_ALIGN_MID; + box->alignment = vert ? GNT_ALIGN_LEFT : GNT_ALIGN_MID; return widget; } Modified: trunk/console/libgnt/gntmain.c =================================================================== --- trunk/console/libgnt/gntmain.c 2006-09-23 19:04:03 UTC (rev 17340) +++ trunk/console/libgnt/gntmain.c 2006-09-24 07:14:26 UTC (rev 17341) @@ -8,6 +8,7 @@ #include "gntbox.h" #include "gntcolors.h" #include "gntkeys.h" +#include "gntmenu.h" #include "gntstyle.h" #include "gnttree.h" #include "gntutils.h" @@ -34,6 +35,14 @@ * Need to wattrset for colors to use with PDCurses. */ +/** + * There can be at most one menu at a time on the screen. + * If there is a menu being displayed, then all the keystrokes will be sent to + * the menu until it is closed, either when the user activates a menuitem, or + * presses Escape to cancel the menu. + */ +static GntMenu *menu; + static int lock_focus_list; static GList *focus_list; static GList *ordered; @@ -120,6 +129,15 @@ static gboolean update_screen(gpointer null) { + if (menu) { + GntMenu *top = menu; + while (top) { + GntNode *node = g_hash_table_lookup(nodes, top); + if (node) + top_panel(node->panel); + top = top->submenu; + } + } update_panels(); doupdate(); return TRUE; @@ -685,7 +703,7 @@ static int reverse_char(WINDOW *d, int y, int x, gboolean set) { -#define DECIDE(ch) (set ? ((ch) | WA_REVERSE) : ((ch) & ~WA_REVERSE)) +#define DECIDE(ch) (set ? ((ch) | A_REVERSE) : ((ch) & ~A_REVERSE)) #ifdef NO_WIDECHAR chtype ch; @@ -777,8 +795,9 @@ if (mode == GNT_KP_MODE_NORMAL) { - if (ordered) - { + if (menu) { + ret = gnt_widget_key_pressed(GNT_WIDGET(menu), buffer); + } else if (ordered) { ret = gnt_widget_key_pressed(ordered->data, buffer); } @@ -1209,8 +1228,8 @@ while (widget->parent) widget = widget->parent; - - gnt_box_sync_children(GNT_BOX(widget)); + if (!GNT_IS_MENU(widget)) + gnt_box_sync_children(GNT_BOX(widget)); node = g_hash_table_lookup(nodes, widget); if (node && !node->panel) { @@ -1244,6 +1263,9 @@ GntWidget *w; if (!widget) return FALSE; + + if (GNT_IS_MENU(widget)) + return TRUE; w = widget; @@ -1416,3 +1438,25 @@ lock_focus_list = 0; } +static void +reset_menu(GntWidget *widget, gpointer null) +{ + menu = NULL; +} + +gboolean gnt_screen_menu_show(gpointer newmenu) +{ + if (menu) { + /* For now, if a menu is being displayed, then another menu + * can NOT take over. */ + return FALSE; + } + + menu = newmenu; + gnt_widget_draw(GNT_WIDGET(menu)); + + g_signal_connect(G_OBJECT(menu), "hide", G_CALLBACK(reset_menu), NULL); + + return TRUE; +} + Added: trunk/console/libgnt/gntmenu.c =================================================================== --- trunk/console/libgnt/gntmenu.c (rev 0) +++ trunk/console/libgnt/gntmenu.c 2006-09-24 07:14:26 UTC (rev 17341) @@ -0,0 +1,290 @@ +#include "gntmenu.h" + +#include <string.h> + +enum +{ + SIGS = 1, +}; + +static GntTreeClass *parent_class = NULL; +static guint signals[SIGS] = { 0 }; + +void (*org_draw)(GntWidget *wid); +void (*org_destroy)(GntWidget *wid); +void (*org_map)(GntWidget *wid); +gboolean (*org_key_pressed)(GntWidget *w, const char *t); + +static void +gnt_menu_draw(GntWidget *widget) +{ + GntMenu *menu = GNT_MENU(widget); + GList *iter; + chtype type; + int i; + + if (menu->type == GNT_MENU_TOPLEVEL) { + wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_HIGHLIGHT)); + werase(widget->window); + + for (i = 0, iter = menu->list; iter; iter = iter->next, i++) { + GntMenuItem *item = GNT_MENUITEM(iter->data); + type = ' ' | COLOR_PAIR(GNT_COLOR_HIGHLIGHT); + if (i == menu->selected) + type |= A_REVERSE; + item->priv.x = getcurx(widget->window) + widget->priv.x; + item->priv.y = getcury(widget->window) + widget->priv.y + 1; + wbkgdset(widget->window, type); + wprintw(widget->window, " %s ", item->text); + } + } else { + org_draw(widget); + } + + GNTDEBUG; +} + +static void +gnt_menu_size_request(GntWidget *widget) +{ + GntMenu *menu = GNT_MENU(widget); + + if (menu->type == GNT_MENU_TOPLEVEL) { + widget->priv.height = 1; + widget->priv.width = getmaxx(stdscr); + } else { + widget->priv.height = g_list_length(menu->list) + 2; + widget->priv.width = 25; /* XXX: */ + } +} + +static void +menu_tree_add(GntMenu *menu, GntMenuItem *item, GntMenuItem *parent) +{ + gnt_tree_add_row_last(GNT_TREE(menu), item, + gnt_tree_create_row(GNT_TREE(menu), item->text, item->submenu ? ">" : " "), parent); + if (0 && item->submenu) { + GntMenu *sub = GNT_MENU(item->submenu); + GList *iter; + for (iter = sub->list; iter; iter = iter->next) { + GntMenuItem *it = GNT_MENUITEM(iter->data); + menu_tree_add(menu, it, item); + } + } +} + +static void +gnt_menu_map(GntWidget *widget) +{ + GntMenu *menu = GNT_MENU(widget); + + if (menu->type == GNT_MENU_TOPLEVEL) { + gnt_widget_size_request(widget); + } else { + /* Populate the tree */ + GList *iter; + gnt_tree_remove_all(GNT_TREE(widget)); + for (iter = menu->list; iter; iter = iter->next) { + GntMenuItem *item = GNT_MENUITEM(iter->data); + menu_tree_add(menu, item, NULL); + } + org_map(widget); + } + GNTDEBUG; +} + +static void +menuitem_activate(GntMenu *menu, GntMenuItem *item) +{ + if (item) { + if (item->submenu) { + GntMenu *sub = GNT_MENU(item->submenu); + menu->submenu = sub; + sub->type = GNT_MENU_POPUP; /* Submenus are *never* toplevel */ + sub->parentmenu = menu; + if (menu->type != GNT_MENU_TOPLEVEL) { + GntWidget *widget = GNT_WIDGET(menu); + item->priv.x = widget->priv.x + widget->priv.width - 1; + item->priv.y = widget->priv.y + gnt_tree_get_selection_visible_line(GNT_TREE(menu)); + } + gnt_widget_set_position(GNT_WIDGET(sub), item->priv.x, item->priv.y); + gnt_widget_draw(GNT_WIDGET(sub)); + } else if (item->callback) { + item->callback(item, item->callbackdata); + while (menu) { + gnt_widget_hide(GNT_WIDGET(menu)); + menu = menu->parentmenu; + } + } + } +} + +static gboolean +gnt_menu_key_pressed(GntWidget *widget, const char *text) +{ + GntMenu *menu = GNT_MENU(widget); + int current = menu->selected; + + if (menu->submenu) { + /*if (gnt_widget_key_pressed(GNT_WIDGET(menu->submenu), text))*/ + /*return TRUE;*/ + return (gnt_widget_key_pressed(GNT_WIDGET(menu->submenu), text)); + } + + if (text[0] == 27 && text[1] == 0) { + /* Escape closes menu */ + GntMenu *par = menu->parentmenu; + if (par != NULL) { + par->submenu = NULL; + gnt_widget_hide(widget); + } else + gnt_widget_hide(widget); + return TRUE; + } + + if (menu->type == GNT_MENU_TOPLEVEL) { + if (text[0] == 27) { + if (strcmp(text + 1, GNT_KEY_LEFT) == 0) { + menu->selected--; + if (menu->selected < 0) + menu->selected = g_list_length(menu->list) - 1; + } else if (strcmp(text + 1, GNT_KEY_RIGHT) == 0) { + menu->selected++; + if (menu->selected >= g_list_length(menu->list)) + menu->selected = 0; + } + } else if (text[0] == '\r' && text[1] == 0) { + gnt_widget_activate(widget); + } + + if (current != menu->selected) { + gnt_widget_draw(widget); + return TRUE; + } + } else { + return org_key_pressed(widget, text); + } + + return FALSE; +} + +static void +gnt_menu_destroy(GntWidget *widget) +{ + GntMenu *menu = GNT_MENU(widget); + g_list_foreach(menu->list, (GFunc)g_object_run_dispose, NULL); + g_list_free(menu->list); + org_destroy(widget); +} + +static void +gnt_menu_activate(GntWidget *widget) +{ + GntMenu *menu = GNT_MENU(widget); + GntMenuItem *item; + + if (menu->type == GNT_MENU_TOPLEVEL) { + item = g_list_nth_data(menu->list, menu->selected); + } else { + item = gnt_tree_get_selection_data(GNT_TREE(menu)); + } + + if (item) + menuitem_activate(menu, item); +} + +static void +gnt_menu_hide(GntWidget *widget) +{ + GntMenu *menu = GNT_MENU(widget); + if (menu->parentmenu) + menu->parentmenu->submenu = NULL; +} + +static void +gnt_menu_class_init(GntMenuClass *klass) +{ + GntWidgetClass *wid_class = GNT_WIDGET_CLASS(klass); + parent_class = GNT_TREE_CLASS(klass); + + org_destroy = wid_class->destroy; + org_map = wid_class->map; + org_draw = wid_class->draw; + org_key_pressed = wid_class->key_pressed; + + wid_class->destroy = gnt_menu_destroy; + wid_class->draw = gnt_menu_draw; + wid_class->map = gnt_menu_map; + wid_class->size_request = gnt_menu_size_request; + wid_class->key_pressed = gnt_menu_key_pressed; + wid_class->activate = gnt_menu_activate; + wid_class->hide = gnt_menu_hide; + + GNTDEBUG; +} + +static void +gnt_menu_init(GTypeInstance *instance, gpointer class) +{ + GntWidget *widget = GNT_WIDGET(instance); + GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW | GNT_WIDGET_NO_BORDER | + GNT_WIDGET_CAN_TAKE_FOCUS); + GNTDEBUG; +} + +/****************************************************************************** + * GntMenu API + *****************************************************************************/ +GType +gnt_menu_get_gtype(void) +{ + static GType type = 0; + + if(type == 0) + { + static const GTypeInfo info = { + sizeof(GntMenuClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc)gnt_menu_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof(GntMenu), + 0, /* n_preallocs */ + gnt_menu_init, /* instance_init */ + }; + + type = g_type_register_static(GNT_TYPE_TREE, + "GntMenu", + &info, 0); + } + + return type; +} + +GntWidget *gnt_menu_new(GntMenuType type) +{ + GntWidget *widget = g_object_new(GNT_TYPE_MENU, NULL); + GntMenu *menu = GNT_MENU(widget); + menu->list = NULL; + menu->selected = -1; + menu->type = type; + + if (type == GNT_MENU_TOPLEVEL) { + widget->priv.x = 0; + widget->priv.y = 0; + } else { + GNT_TREE(widget)->show_separator = FALSE; + _gnt_tree_init_internals(GNT_TREE(widget), 2); + gnt_tree_set_col_width(GNT_TREE(widget), 1, 1); /* The second column is to indicate that it has a submenu */ + GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_NO_BORDER); + } + + return widget; +} + +void gnt_menu_add_item(GntMenu *menu, GntMenuItem *item) +{ + menu->list = g_list_append(menu->list, item); +} + Property changes on: trunk/console/libgnt/gntmenu.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: trunk/console/libgnt/gntmenu.h =================================================================== --- trunk/console/libgnt/gntmenu.h (rev 0) +++ trunk/console/libgnt/gntmenu.h 2006-09-24 07:14:26 UTC (rev 17341) @@ -0,0 +1,70 @@ +#ifndef GNT_MENU_H +#define GNT_MENU_H + +#include "gnttree.h" +#include "gntcolors.h" +#include "gntkeys.h" + +#define GNT_TYPE_MENU (gnt_menu_get_gtype()) +#define GNT_MENU(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_MENU, GntMenu)) +#define GNT_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_MENU, GntMenuClass)) +#define GNT_IS_MENU(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_MENU)) +#define GNT_IS_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_MENU)) +#define GNT_MENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_MENU, GntMenuClass)) + +#define GNT_MENU_FLAGS(obj) (GNT_MENU(obj)->priv.flags) +#define GNT_MENU_SET_FLAGS(obj, flags) (GNT_MENU_FLAGS(obj) |= flags) +#define GNT_MENU_UNSET_FLAGS(obj, flags) (GNT_MENU_FLAGS(obj) &= ~(flags)) + +typedef struct _GnMenu GntMenu; +typedef struct _GnMenuPriv GntMenuPriv; +typedef struct _GnMenuClass GntMenuClass; + +#include "gntmenuitem.h" + +/** + * A toplevel-menu is displayed at the top of the screen, and it spans accross + * the entire width of the screen. + * A popup-menu could be displayed, for example, as a context menu for widgets. + */ +typedef enum +{ + GNT_MENU_TOPLEVEL = 1, /* Menu for a toplevel window */ + GNT_MENU_POPUP, /* A popup menu */ +} GntMenuType; + +struct _GnMenu +{ + GntTree parent; + GntMenuType type; + + GList *list; + int selected; + + /* This will keep track of its immediate submenu which is visible so that + * keystrokes can be passed to it. */ + GntMenu *submenu; + GntMenu *parentmenu; +}; + +struct _GnMenuClass +{ + GntTreeClass parent; + + void (*gnt_reserved1)(void); + void (*gnt_reserved2)(void); + void (*gnt_reserved3)(void); + void (*gnt_reserved4)(void); +}; + +G_BEGIN_DECLS + +GType gnt_menu_get_gtype(void); + +GntWidget *gnt_menu_new(GntMenuType type); + +void gnt_menu_add_item(GntMenu *menu, GntMenuItem *item); + +G_END_DECLS + +#endif /* GNT_MENU_H */ Property changes on: trunk/console/libgnt/gntmenu.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: trunk/console/libgnt/gntmenuitem.c =================================================================== --- trunk/console/libgnt/gntmenuitem.c (rev 0) +++ trunk/console/libgnt/gntmenuitem.c 2006-09-24 07:14:26 UTC (rev 17341) @@ -0,0 +1,79 @@ +#include "gntmenu.h" +#include "gntmenuitem.h" + +static GObjectClass *parent_class = NULL; + +static void +gnt_menuitem_destroy(GObject *obj) +{ + GntMenuItem *item = GNT_MENUITEM(obj); + g_free(item->text); + item->text = NULL; + if (item->submenu) + gnt_widget_destroy(GNT_WIDGET(item->submenu)); +} + +static void +gnt_menuitem_class_init(GntMenuItemClass *klass) +{ + parent_class = G_OBJECT_CLASS(klass); + + parent_class->dispose = gnt_menuitem_destroy; +} + +static void +gnt_menuitem_init(GTypeInstance *instance, gpointer class) +{ +} + +/****************************************************************************** + * GntMenuItem API + *****************************************************************************/ +GType +gnt_menuitem_get_gtype(void) +{ + static GType type = 0; + + if(type == 0) + { + static const GTypeInfo info = { + sizeof(GntMenuItemClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc)gnt_menuitem_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof(GntMenuItem), + 0, /* n_preallocs */ + gnt_menuitem_init, /* instance_init */ + }; + + type = g_type_register_static(G_TYPE_OBJECT, + "GntMenuItem", + &info, 0); + } + + return type; +} + +GObject *gnt_menuitem_new(const char *text) +{ + GObject *item = g_object_new(GNT_TYPE_MENUITEM, NULL); + GntMenuItem *menuitem = GNT_MENUITEM(item); + + menuitem->text = g_strdup(text); + + return item; +} + +void gnt_menuitem_set_callback(GntMenuItem *item, GntMenuItemCallback callback, gpointer data) +{ + item->callback = callback; + item->callbackdata = data; +} + +void gnt_menuitem_set_submenu(GntMenuItem *item, GntMenu *menu) +{ + item->submenu = menu; +} + Property changes on: trunk/console/libgnt/gntmenuitem.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: trunk/console/libgnt/gntmenuitem.h =================================================================== --- trunk/console/libgnt/gntmenuitem.h (rev 0) +++ trunk/console/libgnt/gntmenuitem.h 2006-09-24 07:14:26 UTC (rev 17341) @@ -0,0 +1,69 @@ +#ifndef GNT_MENUITEM_H +#define GNT_MENUITEM_H + +#include <glib.h> +#include <glib-object.h> + +#define GNT_TYPE_MENUITEM (gnt_menuitem_get_gtype()) +#define GNT_MENUITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_MENUITEM, GntMenuItem)) +#define GNT_MENUITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_MENUITEM, GntMenuItemClass)) +#define GNT_IS_MENUITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_MENUITEM)) +#define GNT_IS_MENUITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_MENUITEM)) +#define GNT_MENUITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_MENUITEM, GntMenuItemClass)) + +#define GNT_MENUITEM_FLAGS(obj) (GNT_MENUITEM(obj)->priv.flags) +#define GNT_MENUITEM_SET_FLAGS(obj, flags) (GNT_MENUITEM_FLAGS(obj) |= flags) +#define GNT_MENUITEM_UNSET_FLAGS(obj, flags) (GNT_MENUITEM_FLAGS(obj) &= ~(flags)) + +typedef struct _GnMenuItem GntMenuItem; +typedef struct _GnMenuItemPriv GntMenuItemPriv; +typedef struct _GnMenuItemClass GntMenuItemClass; + +struct _GnMenuItemPriv +{ + /* These will be used to determine the position of the submenu */ + int x; + int y; +}; + +typedef void (*GntMenuItemCallback)(GntMenuItem *item, gpointer data); + +struct _GnMenuItem +{ + GObject parent; + GntMenuItemPriv priv; + + char *text; + + /* A GntMenuItem can have a callback associated with it. + * The callback will be activated whenever the suer selects it and presses enter (or clicks). + * However, if the GntMenuItem has some child, then the callback and callbackdata will be ignored. */ + gpointer callbackdata; + GntMenuItemCallback callback; + + GntMenu *submenu; +}; + +struct _GnMenuItemClass +{ + GObjectClass parent; + + void (*gnt_reserved1)(void); + void (*gnt_reserved2)(void); + void (*gnt_reserved3)(void); + void (*gnt_reserved4)(void); +}; + +G_BEGIN_DECLS + +GType gnt_menuitem_get_gtype(void); + +GObject *gnt_menuitem_new(const char *text); + +void gnt_menuitem_set_callback(GntMenuItem *item, GntMenuItemCallback callback, gpointer data); + +void gnt_menuitem_set_submenu(GntMenuItem *item, GntMenu *menu); + +G_END_DECLS + +#endif /* GNT_MENUITEM_H */ Property changes on: trunk/console/libgnt/gntmenuitem.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Modified: trunk/console/libgnt/gnttree.c =================================================================== --- trunk/console/libgnt/gnttree.c 2006-09-23 19:04:03 UTC (rev 17340) +++ trunk/console/libgnt/gnttree.c 2006-09-24 07:14:26 UTC (rev 17341) @@ -288,8 +288,10 @@ tree_mark_columns(tree, pos, widget->priv.height - pos, ACS_BTEE | COLOR_PAIR(GNT_COLOR_NORMAL)); } - tree_mark_columns(tree, pos, pos + 1, ACS_PLUS | COLOR_PAIR(GNT_COLOR_NORMAL)); - tree_mark_columns(tree, pos, pos, ACS_VLINE | COLOR_PAIR(GNT_COLOR_NORMAL)); + tree_mark_columns(tree, pos, pos + 1, + (tree->show_separator ? ACS_PLUS : ACS_HLINE) | COLOR_PAIR(GNT_COLOR_NORMAL)); + tree_mark_columns(tree, pos, pos, + (tree->show_separator ? ACS_VLINE : ' ') | COLOR_PAIR(GNT_COLOR_NORMAL)); start = 2; } @@ -356,7 +358,8 @@ whline(widget->window, ' ', widget->priv.width - pos * 2 - g_utf8_strlen(str, -1) - 1); tree->bottom = row; g_free(str); - tree_mark_columns(tree, pos, i, ACS_VLINE | attr); + tree_mark_columns(tree, pos, i, + (tree->show_separator ? ACS_VLINE : ' ') | attr); } wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); @@ -364,7 +367,8 @@ { mvwhline(widget->window, i, pos, ' ', widget->priv.width - pos * 2 - 1); - tree_mark_columns(tree, pos, i, ACS_VLINE); + tree_mark_columns(tree, pos, i, + (tree->show_separator ? ACS_VLINE : ' ')); i++; } @@ -696,6 +700,8 @@ gnt_tree_init(GTypeInstance *instance, gpointer class) { GntWidget *widget = GNT_WIDGET(instance); + GntTree *tree = GNT_TREE(widget); + tree->show_separator = TRUE; GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y); widget->priv.minw = 4; widget->priv.minh = 4; @@ -1125,19 +1131,24 @@ redraw_tree(tree); } -GntWidget *gnt_tree_new_with_columns(int col) +void _gnt_tree_init_internals(GntTree *tree, int col) { - GntWidget *widget = g_object_new(GNT_TYPE_TREE, NULL); - GntTree *tree = GNT_TREE(widget); - + tree->ncol = col; tree->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_tree_row); - tree->ncol = col; tree->columns = g_new0(struct _GntTreeColInfo, col); while (col--) { tree->columns[col].width = 15; } tree->show_title = FALSE; +} + +GntWidget *gnt_tree_new_with_columns(int col) +{ + GntWidget *widget = g_object_new(GNT_TYPE_TREE, NULL); + GntTree *tree = GNT_TREE(widget); + + _gnt_tree_init_internals(tree, col); GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW); gnt_widget_set_take_focus(widget, TRUE); @@ -1224,3 +1235,9 @@ gnt_widget_draw(GNT_WIDGET(tree)); } } + +void gnt_tree_set_show_separator(GntTree *tree, gboolean set) +{ + tree->show_separator = set; +} + Modified: trunk/console/libgnt/gnttree.h =================================================================== --- trunk/console/libgnt/gnttree.h 2006-09-23 19:04:03 UTC (rev 17340) +++ trunk/console/libgnt/gnttree.h 2006-09-24 07:14:26 UTC (rev 17341) @@ -46,6 +46,7 @@ char *title; } *columns; /* Would a GList be better? */ gboolean show_title; + gboolean show_separator; /* Whether to show column separators */ GCompareFunc compare; }; @@ -54,7 +55,7 @@ { GntWidgetClass parent; - void (*selection_changed)(int old, int current); + void (*selection_changed)(GntTreeRow *old, GntTreeRow * current); void (*gnt_reserved1)(void); void (*gnt_reserved2)(void); @@ -120,6 +121,13 @@ void gnt_tree_set_expanded(GntTree *tree, void *key, gboolean expanded); +void gnt_tree_set_show_separator(GntTree *tree, gboolean set); + G_END_DECLS +/* The following functions should NOT be used by applications. */ + +/* This should be called by the subclasses of GntTree's in their _new function */ +void _gnt_tree_init_internals(GntTree *tree, int col); + #endif /* GNT_TREE_H */ Modified: trunk/console/libgnt/gntwidget.c =================================================================== --- trunk/console/libgnt/gntwidget.c 2006-09-23 19:04:03 UTC (rev 17340) +++ trunk/console/libgnt/gntwidget.c 2006-09-24 07:14:26 UTC (rev 17341) @@ -9,6 +9,7 @@ { SIG_DESTROY, SIG_DRAW, + SIG_HIDE, SIG_GIVE_FOCUS, SIG_LOST_FOCUS, SIG_KEY_PRESSED, @@ -167,6 +168,14 @@ NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + signals[SIG_HIDE] = + g_signal_new("hide", + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(GntWidgetClass, hide), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); signals[SIG_EXPOSE] = g_signal_new("expose", G_TYPE_FROM_CLASS(klass), @@ -403,6 +412,7 @@ void gnt_widget_hide(GntWidget *widget) { + g_signal_emit(widget, signals[SIG_HIDE], 0); wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); #if 0 /* XXX: I have no clue why, but this seemed to be necessary. */ Modified: trunk/console/libgnt/gntwidget.h =================================================================== --- trunk/console/libgnt/gntwidget.h 2006-09-23 19:04:03 UTC (rev 17340) +++ trunk/console/libgnt/gntwidget.h 2006-09-24 07:14:26 UTC (rev 17341) @@ -93,6 +93,7 @@ void (*show)(GntWidget *obj); /* This will call draw() and take focus (if it can take focus) */ void (*destroy)(GntWidget *obj); void (*draw)(GntWidget *obj); /* This will draw the widget */ + void (*hide)(GntWidget *obj); void (*expose)(GntWidget *widget, int x, int y, int width, int height); void (*gained_focus)(GntWidget *widget); void (*lost_focus)(GntWidget *widget); Added: trunk/console/libgnt/gntwindow.c =================================================================== --- trunk/console/libgnt/gntwindow.c (rev 0) +++ trunk/console/libgnt/gntwindow.c 2006-09-24 07:14:26 UTC (rev 17341) @@ -0,0 +1,113 @@ +#include "gntwindow.h" + +#include <string.h> + +enum +{ + SIGS = 1, +}; + +static GntBoxClass *parent_class = NULL; +static guint signals[SIGS] = { 0 }; + +gboolean (*org_keypress)(GntWidget *widget, const char *text); +void (*org_destroy)(GntWidget *widget); + +static gboolean +gnt_window_key_pressed(GntWidget *widget, const char *text) +{ + if (strcmp(text, GNT_KEY_CTRL_O) == 0 && GNT_WINDOW(widget)->menu) { + gnt_screen_menu_show(GNT_WINDOW(widget)->menu); + return TRUE; + } else + return org_keypress(widget, text); + +} + +static void +gnt_window_destroy(GntWidget *widget) +{ + GntWindow *window = GNT_WINDOW(widget); + if (window->menu) + gnt_widget_destroy(GNT_WIDGET(window->menu)); + org_destroy(widget); +} + +static void +gnt_window_class_init(GntWindowClass *klass) +{ + GntWidgetClass *wid_class = GNT_WIDGET_CLASS(klass); + parent_class = GNT_BOX_CLASS(klass); + + org_keypress = wid_class->key_pressed; + wid_class->key_pressed = gnt_window_key_pressed; + + org_destroy = wid_class->destroy; + wid_class->destroy = gnt_window_destroy; + + GNTDEBUG; +} + +static void +gnt_window_init(GTypeInstance *instance, gpointer class) +{ + GntWidget *widget = GNT_WIDGET(instance); + GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); + GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS); + GNTDEBUG; +} + +/****************************************************************************** + * GntWindow API + *****************************************************************************/ +GType +gnt_window_get_gtype(void) +{ + static GType type = 0; + + if(type == 0) + { + static const GTypeInfo info = { + sizeof(GntWindowClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc)gnt_window_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof(GntWindow), + 0, /* n_preallocs */ + gnt_window_init, /* instance_init */ + }; + + type = g_type_register_static(GNT_TYPE_BOX, + "GntWindow", + &info, 0); + } + + return type; +} + +GntWidget *gnt_window_new() +{ + GntWidget *widget = g_object_new(GNT_TYPE_WINDOW, NULL); + + return widget; +} + +GntWidget *gnt_window_box_new(gboolean homo, gboolean vert) +{ + GntWidget *wid = gnt_window_new(); + GntBox *box = GNT_BOX(wid); + + box->homogeneous = homo; + box->vertical = vert; + box->alignment = vert ? GNT_ALIGN_LEFT : GNT_ALIGN_MID; + + return wid; +} + +void gnt_window_set_menu(GntWindow *window, GntMenu *menu) +{ + window->menu = menu; +} + Property changes on: trunk/console/libgnt/gntwindow.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: trunk/console/libgnt/gntwindow.h =================================================================== --- trunk/console/libgnt/gntwindow.h (rev 0) +++ trunk/console/libgnt/gntwindow.h 2006-09-24 07:14:26 UTC (rev 17341) @@ -0,0 +1,56 @@ +#ifndef GNT_WINDOW_H +#define GNT_WINDOW_H + +#include "gnt.h" +#include "gntbox.h" +#include "gntcolors.h" +#include "gntkeys.h" +#include "gntmenu.h" + +#define GNT_TYPE_WINDOW (gnt_window_get_gtype()) +#define GNT_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_WINDOW, GntWindow)) +#define GNT_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_WINDOW, GntWindowClass)) +#define GNT_IS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_WINDOW)) +#define GNT_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_WINDOW)) +#define GNT_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_WINDOW, GntWindowClass)) + +#define GNT_WINDOW_FLAGS(obj) (GNT_WINDOW(obj)->priv.flags) +#define GNT_WINDOW_SET_FLAGS(obj, flags) (GNT_WINDOW_FLAGS(obj) |= flags) +#define GNT_WINDOW_UNSET_FLAGS(obj, flags) (GNT_WINDOW_FLAGS(obj) &= ~(flags)) + +typedef struct _GnWindow GntWindow; +typedef struct _GnWindowPriv GntWindowPriv; +typedef struct _GnWindowClass GntWindowClass; + +struct _GnWindow +{ + GntBox parent; + GntMenu *menu; +}; + +struct _GnWindowClass +{ + GntBoxClass parent; + + void (*gnt_reserved1)(void); + void (*gnt_reserved2)(void); + void (*gnt_reserved3)(void); + void (*gnt_reserved4)(void); +}; + +G_BEGIN_DECLS + +GType gnt_window_get_gtype(void); + +#define gnt_vwindow_new(homo) gnt_window_box_new(homo, TRUE) +#define gnt_hwindow_new(homo) gnt_window_box_new(homo, FALSE) + +GntWidget *gnt_window_new(); + +GntWidget *gnt_window_box_new(gboolean homo, gboolean vert); + +void gnt_window_set_menu(GntWindow *window, GntMenu *menu); + +G_END_DECLS + +#endif /* GNT_WINDOW_H */ Property changes on: trunk/console/libgnt/gntwindow.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Modified: trunk/console/libgnt/test/Makefile =================================================================== --- trunk/console/libgnt/test/Makefile 2006-09-23 19:04:03 UTC (rev 17340) +++ trunk/console/libgnt/test/Makefile 2006-09-24 07:14:26 UTC (rev 17341) @@ -2,7 +2,7 @@ CFLAGS=`pkg-config --cflags gobject-2.0 gmodule-2.0` -g -I../ -DSTANDALONE LDFLAGS=`pkg-config --libs gobject-2.0 gmodule-2.0 gnt` -pg -EXAMPLES=combo focus tv multiwin keys +EXAMPLES=combo focus tv multiwin keys menu all: make examples Modified: trunk/console/libgnt/test/focus.c =================================================================== --- trunk/console/libgnt/test/focus.c 2006-09-23 19:04:03 UTC (rev 17340) +++ trunk/console/libgnt/test/focus.c 2006-09-24 07:14:26 UTC (rev 17341) @@ -61,7 +61,7 @@ gnt_tree_add_choice(GNT_TREE(tree), "b", gnt_tree_create_row(GNT_TREE(tree), "b"), "d", NULL); GNT_WIDGET_UNSET_FLAGS(hbox, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); - gnt_box_set_title(GNT_BOX(hbox), "\u4e0a\u6d77\u6700\u4f4e\u6708\u5de5 …"); + gnt_box_set_title(GNT_BOX(hbox), "\u4e0a\u6d77\u6700\u4f4e\u6708\u5de5 \u4e0a\u6d77\u6700\u4f4e\u6708\u5de5 ……\u4e0a\u6d77\u6700\u4f4e\u6708\u5de5 …"); g_signal_connect(G_OBJECT(tree), "toggled", G_CALLBACK(toggled), NULL); Added: trunk/console/libgnt/test/menu.c =================================================================== --- trunk/console/libgnt/test/menu.c (rev 0) +++ trunk/console/libgnt/test/menu.c 2006-09-24 07:14:26 UTC (rev 17341) @@ -0,0 +1,65 @@ +#include "gnt.h" +#include "gntbox.h" +#include "gntlabel.h" +#include "gntmenu.h" +#include "gntmenuitem.h" +#include "gntwindow.h" + +void dothis(GntMenuItem *item, gpointer null) +{ + GntWidget *w = gnt_vbox_new(FALSE); + gnt_box_set_toplevel(GNT_BOX(w), TRUE); + gnt_box_add_widget(GNT_BOX(w), + gnt_label_new("Callback to a menuitem")); + gnt_widget_show(w); +} + +int main() +{ + freopen(".error", "w", stderr); + gnt_init(); + + GntWidget *menu = gnt_menu_new(GNT_MENU_TOPLEVEL); + GObject *item = gnt_menuitem_new("File"); + + gnt_menu_add_item(GNT_MENU(menu), GNT_MENUITEM(item)); + + item = gnt_menuitem_new("Edit"); + gnt_menu_add_item(GNT_MENU(menu), GNT_MENUITEM(item)); + + item = gnt_menuitem_new("Help"); + gnt_menu_add_item(GNT_MENU(menu), GNT_MENUITEM(item)); + + GntWidget *sub = gnt_menu_new(GNT_MENU_POPUP); + gnt_menuitem_set_submenu(GNT_MENUITEM(item), GNT_MENU(sub)); + + item = gnt_menuitem_new("Online Help"); + gnt_menu_add_item(GNT_MENU(sub), GNT_MENUITEM(item)); + + item = gnt_menuitem_new("About"); + gnt_menu_add_item(GNT_MENU(sub), GNT_MENUITEM(item)); + + sub = gnt_menu_new(GNT_MENU_POPUP); + gnt_menuitem_set_submenu(GNT_MENUITEM(item), GNT_MENU(sub)); + + item = gnt_menuitem_new("Online Help"); + gnt_menu_add_item(GNT_MENU(sub), GNT_MENUITEM(item)); + gnt_menuitem_set_callback(GNT_MENUITEM(item), dothis, NULL); + + gnt_screen_menu_show(menu); + + + GntWidget *win = gnt_window_new(); + gnt_box_add_widget(GNT_BOX(win), + gnt_label_new("...")); + gnt_box_set_title(GNT_BOX(win), "Title"); + gnt_window_set_menu(GNT_WINDOW(win), GNT_MENU(menu)); + gnt_widget_show(win); + + gnt_main(); + + gnt_quit(); + + return 0; +} + Property changes on: trunk/console/libgnt/test/menu.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Modified: trunk/console/libgnt/wms/s.c =================================================================== --- trunk/console/libgnt/wms/s.c 2006-09-23 19:04:03 UTC (rev 17340) +++ trunk/console/libgnt/wms/s.c 2006-09-24 07:14:26 UTC (rev 17341) @@ -1,4 +1,6 @@ +#include "gnt.h" #include "gntbox.h" +#include "gntmenu.h" #include "gntwm.h" #include "gntblist.h" @@ -52,6 +54,8 @@ int maxx, maxy; const char *name; + if (GNT_IS_MENU(win)) + return new_panel(win->window); getmaxyx(stdscr, maxy, maxx); gnt_widget_get_position(win, &x, &y); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-10-27 18:31:06
|
Revision: 17591 http://svn.sourceforge.net/gaim/?rev=17591&view=rev Author: sadrul Date: 2006-10-27 11:30:56 -0700 (Fri, 27 Oct 2006) Log Message: ----------- This fixes at least some issues with wide-characters in the tree-widget. Modified Paths: -------------- trunk/console/libgnt/gnttree.c trunk/console/libgnt/gntutils.c Modified: trunk/console/libgnt/gnttree.c =================================================================== --- trunk/console/libgnt/gnttree.c 2006-10-27 18:19:40 UTC (rev 17590) +++ trunk/console/libgnt/gnttree.c 2006-10-27 18:30:56 UTC (rev 17591) @@ -196,8 +196,8 @@ for (i = 0, iter = row->columns; i < tree->ncol && iter; i++, iter = iter->next) { GntTreeCol *col = iter->data; - char *text; - int len = g_utf8_strlen(col->text, -1); + const char *text; + int len = gnt_util_onscreen_width(col->text, NULL); int fl = 0; if (i == 0) @@ -235,7 +235,7 @@ len = tree->columns[i].width; } - text = g_utf8_offset_to_pointer(col->text, len - fl); + text = gnt_util_onscreen_width_to_pointer(col->text, len - fl, NULL); string = g_string_append_len(string, col->text, text - col->text); if (len < tree->columns[i].width && iter->next) g_string_append_printf(string, "%*s", tree->columns[i].width - len, ""); @@ -324,6 +324,7 @@ tree->top = get_prev_n(tree->current, rows); row = tree->top; + scrcol = widget->priv.width - 1 - 2 * pos; /* exclude the borders and the scrollbar */ for (i = start + pos; row && i < widget->priv.height - pos; i++, row = get_next(row)) { @@ -335,10 +336,10 @@ str = update_row_text(tree, row); - if ((wr = g_utf8_strlen(str, -1)) >= widget->priv.width - 1 - pos) + if ((wr = gnt_util_onscreen_width(str, NULL)) > scrcol) { /* XXX: ellipsize */ - char *s = g_utf8_offset_to_pointer(str, widget->priv.width - 1 - pos); + char *s = (char*)gnt_util_onscreen_width_to_pointer(str, scrcol, &wr); *s = '\0'; } @@ -368,7 +369,7 @@ wbkgdset(widget->window, '\0' | attr); mvwprintw(widget->window, i, pos, str); - whline(widget->window, ' ', widget->priv.width - pos * 2 - g_utf8_strlen(str, -1) - 1); + whline(widget->window, ' ', scrcol - wr); tree->bottom = row; g_free(str); tree_mark_columns(tree, pos, i, @@ -385,7 +386,7 @@ i++; } - scrcol = widget->priv.width - pos - 1; + scrcol = widget->priv.width - pos - 1; /* position of the scrollbar */ rows--; if (rows > 0) { Modified: trunk/console/libgnt/gntutils.c =================================================================== --- trunk/console/libgnt/gntutils.c 2006-10-27 18:19:40 UTC (rev 17590) +++ trunk/console/libgnt/gntutils.c 2006-10-27 18:30:56 UTC (rev 17591) @@ -60,7 +60,7 @@ const char *str = string; if (len <= 0) { - len = g_utf8_strlen(string, -1); + len = gnt_util_onscreen_width(string, NULL); } while (width < len && *str) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-10-28 19:54:02
|
Revision: 17605 http://svn.sourceforge.net/gaim/?rev=17605&view=rev Author: sadrul Date: 2006-10-28 12:52:30 -0700 (Sat, 28 Oct 2006) Log Message: ----------- Do things right and fix the compile warnings. Modified Paths: -------------- trunk/console/libgnt/gntbox.c trunk/console/libgnt/gntbutton.c trunk/console/libgnt/gntcheckbox.c trunk/console/libgnt/gntentry.c trunk/console/libgnt/gntlabel.c trunk/console/libgnt/gntline.c trunk/console/libgnt/gntstyle.c trunk/console/libgnt/gnttree.c trunk/console/libgnt/gntwidget.c trunk/console/libgnt/gntwidget.h Modified: trunk/console/libgnt/gntbox.c =================================================================== --- trunk/console/libgnt/gntbox.c 2006-10-28 19:37:48 UTC (rev 17604) +++ trunk/console/libgnt/gntbox.c 2006-10-28 19:52:30 UTC (rev 17605) @@ -9,7 +9,6 @@ }; static GntWidgetClass *parent_class = NULL; -static guint signals[SIGS] = { 0 }; static GntWidget * find_focusable_widget(GntBox *box); Modified: trunk/console/libgnt/gntbutton.c =================================================================== --- trunk/console/libgnt/gntbutton.c 2006-10-28 19:37:48 UTC (rev 17604) +++ trunk/console/libgnt/gntbutton.c 2006-10-28 19:52:30 UTC (rev 17605) @@ -9,7 +9,6 @@ }; static GntWidgetClass *parent_class = NULL; -static guint signals[SIGS] = { 0 }; static void gnt_button_draw(GntWidget *widget) Modified: trunk/console/libgnt/gntcheckbox.c =================================================================== --- trunk/console/libgnt/gntcheckbox.c 2006-10-28 19:37:48 UTC (rev 17604) +++ trunk/console/libgnt/gntcheckbox.c 2006-10-28 19:52:30 UTC (rev 17605) @@ -34,19 +34,6 @@ } static void -gnt_check_box_size_request(GntWidget *widget) -{ -} - -static void -gnt_check_box_map(GntWidget *widget) -{ - if (widget->priv.width == 0 || widget->priv.height == 0) - gnt_widget_size_request(widget); - GNTDEBUG; -} - -static void toggle_selection(GntWidget *widget) { GNT_CHECK_BOX(widget)->checked = !GNT_CHECK_BOX(widget)->checked; @@ -77,11 +64,6 @@ } static void -gnt_check_box_destroy(GntWidget *widget) -{ -} - -static void gnt_check_box_class_init(GntCheckBoxClass *klass) { GntWidgetClass *wclass = GNT_WIDGET_CLASS(klass); Modified: trunk/console/libgnt/gntentry.c =================================================================== --- trunk/console/libgnt/gntentry.c 2006-10-28 19:37:48 UTC (rev 17604) +++ trunk/console/libgnt/gntentry.c 2006-10-28 19:52:30 UTC (rev 17605) @@ -3,6 +3,7 @@ #include "gntbox.h" #include "gntentry.h" +#include "gntstyle.h" #include "gnttree.h" #include "gntutils.h" @@ -339,7 +340,7 @@ { char ch; ch = *text; -#define SAME(a,b) ((isalpha(a) && isalpha(b)) || (isdigit(a) && isdigit(b)) || (isblank(a) && isblank(b))) +#define SAME(a,b) ((isalpha(a) && isalpha(b)) || (isdigit(a) && isdigit(b)) || (isspace(a) && isspace(b))) while (--text >= begin) { if (!SAME(ch, *text)) break; @@ -354,7 +355,6 @@ { GntEntry *entry = GNT_ENTRY(widget); const char *iter = entry->cursor - 1; - int count; if (iter < entry->start) return TRUE; @@ -586,7 +586,7 @@ gnt_widget_class_register_action(parent_class, "history-next", history_next, "\033" GNT_KEY_CTRL_UP, NULL); - gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), klass); + gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), parent_class); GNTDEBUG; } Modified: trunk/console/libgnt/gntlabel.c =================================================================== --- trunk/console/libgnt/gntlabel.c 2006-10-28 19:37:48 UTC (rev 17604) +++ trunk/console/libgnt/gntlabel.c 2006-10-28 19:52:30 UTC (rev 17605) @@ -9,7 +9,6 @@ }; static GntWidgetClass *parent_class = NULL; -static guint signals[SIGS] = { 0 }; static void gnt_label_destroy(GntWidget *widget) Modified: trunk/console/libgnt/gntline.c =================================================================== --- trunk/console/libgnt/gntline.c 2006-10-28 19:37:48 UTC (rev 17604) +++ trunk/console/libgnt/gntline.c 2006-10-28 19:52:30 UTC (rev 17605) @@ -6,7 +6,6 @@ }; static GntWidgetClass *parent_class = NULL; -static guint signals[SIGS] = { 0 }; static void gnt_line_draw(GntWidget *widget) Modified: trunk/console/libgnt/gntstyle.c =================================================================== --- trunk/console/libgnt/gntstyle.c 2006-10-28 19:37:48 UTC (rev 17604) +++ trunk/console/libgnt/gntstyle.c 2006-10-28 19:52:30 UTC (rev 17605) @@ -1,6 +1,7 @@ #include "gntstyle.h" #include "gntcolors.h" +#include <ctype.h> #include <string.h> #if GLIB_CHECK_VERSION(2,6,0) Modified: trunk/console/libgnt/gnttree.c =================================================================== --- trunk/console/libgnt/gnttree.c 2006-10-28 19:37:48 UTC (rev 17604) +++ trunk/console/libgnt/gnttree.c 2006-10-28 19:52:30 UTC (rev 17605) @@ -1,5 +1,6 @@ -#include "gnttree.h" #include "gntmarshal.h" +#include "gntstyle.h" +#include "gnttree.h" #include "gntutils.h" #include <string.h> @@ -474,13 +475,6 @@ g_signal_emit(tree, signals[SIG_SELECTION_CHANGED], 0, old->key, current->key); } -static GntTreeRow * -get_nth_row(GntTree *tree, int n) -{ - gpointer key = g_list_nth_data(tree->list, n); - return g_hash_table_lookup(tree->hash, key); -} - static gboolean action_down(GntWidget *widget, GList *null) { @@ -577,8 +571,6 @@ { GntTree *tree = GNT_TREE(widget); GntTreeRow *old = tree->current; - GntTreeRow *row; - int dist; if (text[0] == '\r') { @@ -720,7 +712,7 @@ gnt_widget_class_register_action(parent_class, "page-down", action_page_down, "\033" GNT_KEY_PGDOWN, NULL); - gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), klass); + gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), parent_class); GNTDEBUG; } Modified: trunk/console/libgnt/gntwidget.c =================================================================== --- trunk/console/libgnt/gntwidget.c 2006-10-28 19:37:48 UTC (rev 17604) +++ trunk/console/libgnt/gntwidget.c 2006-10-28 19:52:30 UTC (rev 17605) @@ -415,7 +415,6 @@ gboolean gnt_widget_perform_action_named(GntWidget *widget, const char *name, ...) { - GType type = G_OBJECT_TYPE(widget); GntWidgetClass *klass = GNT_WIDGET_CLASS(G_OBJECT_GET_CLASS(widget)); GList *list = NULL; va_list args; @@ -440,7 +439,6 @@ static gboolean gnt_widget_perform_action(GntWidget *widget, const char *keys) { - GType type = G_OBJECT_TYPE(widget); GntWidgetClass *klass = GNT_WIDGET_CLASS(G_OBJECT_GET_CLASS(widget)); GntWidgetActionParam *param = g_hash_table_lookup(klass->bindings, keys); Modified: trunk/console/libgnt/gntwidget.h =================================================================== --- trunk/console/libgnt/gntwidget.h 2006-10-28 19:37:48 UTC (rev 17604) +++ trunk/console/libgnt/gntwidget.h 2006-10-28 19:52:30 UTC (rev 17605) @@ -181,10 +181,14 @@ void gnt_widget_action_free(GntWidgetAction *action); void gnt_widget_action_param_free(GntWidgetActionParam *param); +void gnt_widget_register_binding(GntWidgetClass *klass, const char *name, + const char *trigger, ...); void gnt_widget_class_register_action(GntWidgetClass *klass, const char *name, GntWidgetActionCallback callback, const char *trigger, ...); +gboolean gnt_widget_perform_action_named(GntWidget *widget, const char *name, ...); + G_END_DECLS #endif /* GNT_WIDGET_H */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-10-28 20:08:08
|
Revision: 17608 http://svn.sourceforge.net/gaim/?rev=17608&view=rev Author: sadrul Date: 2006-10-28 13:06:33 -0700 (Sat, 28 Oct 2006) Log Message: ----------- More compile warning fixes Modified Paths: -------------- trunk/console/libgnt/gntstyle.c trunk/console/libgnt/wms/s.c Modified: trunk/console/libgnt/gntstyle.c =================================================================== --- trunk/console/libgnt/gntstyle.c 2006-10-28 20:05:27 UTC (rev 17607) +++ trunk/console/libgnt/gntstyle.c 2006-10-28 20:06:33 UTC (rev 17608) @@ -171,7 +171,7 @@ if (g_key_file_has_group(gkfile, name)) { - unsigned int len = 0; + gsize len = 0; char **keys; keys = g_key_file_get_keys(gkfile, name, &len, &error); @@ -225,7 +225,7 @@ if (g_key_file_has_group(gkfile, name)) { - unsigned int len = 0; + gsize len = 0; char **keys; keys = g_key_file_get_keys(gkfile, name, &len, &error); @@ -304,8 +304,8 @@ void gnt_style_read_configure_file(const char *filename) { #if GLIB_CHECK_VERSION(2,6,0) + GError *error = NULL; gkfile = g_key_file_new(); - GError *error = NULL; if (!g_key_file_load_from_file(gkfile, filename, G_KEY_FILE_NONE, &error)) { Modified: trunk/console/libgnt/wms/s.c =================================================================== --- trunk/console/libgnt/wms/s.c 2006-10-28 20:05:27 UTC (rev 17607) +++ trunk/console/libgnt/wms/s.c 2006-10-28 20:06:33 UTC (rev 17608) @@ -169,6 +169,7 @@ envelope_normal_window(window); } +void gntwm_init(GntWM *wm); void gntwm_init(GntWM *wm) { gwm = wm; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-10-29 00:15:43
|
Revision: 17614 http://svn.sourceforge.net/gaim/?rev=17614&view=rev Author: sadrul Date: 2006-10-28 17:15:32 -0700 (Sat, 28 Oct 2006) Log Message: ----------- a couple of minor fixes Modified Paths: -------------- trunk/console/libgnt/gntbox.c trunk/console/libgnt/gntmenu.c Modified: trunk/console/libgnt/gntbox.c =================================================================== --- trunk/console/libgnt/gntbox.c 2006-10-28 23:55:29 UTC (rev 17613) +++ trunk/console/libgnt/gntbox.c 2006-10-29 00:15:32 UTC (rev 17614) @@ -704,8 +704,6 @@ GntWidget *wid; int width, height; - g_return_if_fail(GNT_WIDGET(box)->parent == NULL); - for (iter = box->list; iter; iter = iter->next) { GntWidget *w = iter->data; Modified: trunk/console/libgnt/gntmenu.c =================================================================== --- trunk/console/libgnt/gntmenu.c 2006-10-28 23:55:29 UTC (rev 17613) +++ trunk/console/libgnt/gntmenu.c 2006-10-29 00:15:32 UTC (rev 17614) @@ -210,7 +210,7 @@ } if (item) { - if (GNT_MENUITEM_CHECK(item)) + if (GNT_IS_MENUITEM_CHECK(item)) gnt_menu_toggled(GNT_TREE(widget), item); else menuitem_activate(menu, item); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-11-01 03:38:43
|
Revision: 17645 http://svn.sourceforge.net/gaim/?rev=17645&view=rev Author: sadrul Date: 2006-10-31 19:38:23 -0800 (Tue, 31 Oct 2006) Log Message: ----------- Use terminfo/termcap information (from ncurses) as much as possible. There still need to be some manual 'refinement' based on $TERM. I'll see if I can get rid of those. Also, I am probably going to allow users to provide information that terminfo can't provide, like the keycode for ctrl+up etc. Let me know if any of the keybinding doesn't work. Modified Paths: -------------- trunk/console/libgnt/gntbox.c trunk/console/libgnt/gntcombobox.c trunk/console/libgnt/gntentry.c trunk/console/libgnt/gntkeys.c trunk/console/libgnt/gntkeys.h trunk/console/libgnt/gntmain.c trunk/console/libgnt/gntmenu.c trunk/console/libgnt/gntstyle.c trunk/console/libgnt/gnttextview.h trunk/console/libgnt/gnttree.c trunk/console/libgnt/gnttree.h trunk/console/libgnt/gntwidget.c Modified: trunk/console/libgnt/gntbox.c =================================================================== --- trunk/console/libgnt/gntbox.c 2006-11-01 02:13:37 UTC (rev 17644) +++ trunk/console/libgnt/gntbox.c 2006-11-01 03:38:23 UTC (rev 17645) @@ -285,11 +285,11 @@ if (text[0] == 27) { - if (strcmp(text+1, GNT_KEY_LEFT) == 0) + if (strcmp(text, GNT_KEY_LEFT) == 0) { find_prev_focus(box); } - else if (strcmp(text+1, GNT_KEY_RIGHT) == 0) + else if (strcmp(text, GNT_KEY_RIGHT) == 0) { find_next_focus(box); } Modified: trunk/console/libgnt/gntcombobox.c =================================================================== --- trunk/console/libgnt/gntcombobox.c 2006-11-01 02:13:37 UTC (rev 17644) +++ trunk/console/libgnt/gntcombobox.c 2006-11-01 03:38:23 UTC (rev 17645) @@ -135,8 +135,8 @@ { if (text[0] == 27) { - if (strcmp(text + 1, GNT_KEY_UP) == 0 || - strcmp(text + 1, GNT_KEY_DOWN) == 0) + if (strcmp(text, GNT_KEY_UP) == 0 || + strcmp(text, GNT_KEY_DOWN) == 0) { popup_dropdown(box); return TRUE; @@ -170,10 +170,10 @@ if (event == GNT_MOUSE_SCROLL_UP) { if (dshowing) - gnt_widget_key_pressed(box->dropdown, "\033" GNT_KEY_UP); + gnt_widget_key_pressed(box->dropdown, GNT_KEY_UP); } else if (event == GNT_MOUSE_SCROLL_DOWN) { if (dshowing) - gnt_widget_key_pressed(box->dropdown, "\033" GNT_KEY_DOWN); + gnt_widget_key_pressed(box->dropdown, GNT_KEY_DOWN); } else if (event == GNT_LEFT_MOUSE_DOWN) { if (dshowing) { set_selection(box, gnt_tree_get_selection_data(GNT_TREE(box->dropdown))); Modified: trunk/console/libgnt/gntentry.c =================================================================== --- trunk/console/libgnt/gntentry.c 2006-11-01 02:13:37 UTC (rev 17644) +++ trunk/console/libgnt/gntentry.c 2006-11-01 03:38:23 UTC (rev 17645) @@ -550,14 +550,14 @@ gnt_widget_class_register_action(parent_class, "cursor-home", move_start, GNT_KEY_CTRL_A, NULL); - gnt_widget_register_binding(parent_class, "cursor-home", "\033" GNT_KEY_HOME, NULL); + gnt_widget_register_binding(parent_class, "cursor-home", GNT_KEY_HOME, NULL); gnt_widget_class_register_action(parent_class, "cursor-end", move_end, GNT_KEY_CTRL_E, NULL); - gnt_widget_register_binding(parent_class, "cursor-end", "\033" GNT_KEY_END, NULL); + gnt_widget_register_binding(parent_class, "cursor-end", GNT_KEY_END, NULL); gnt_widget_class_register_action(parent_class, "delete-prev", backspace, GNT_KEY_BACKSPACE, NULL); gnt_widget_class_register_action(parent_class, "delete-next", delkey, - "\033" GNT_KEY_DEL, NULL); + GNT_KEY_DEL, NULL); gnt_widget_register_binding(parent_class, "delete-next", GNT_KEY_CTRL_D, NULL); gnt_widget_class_register_action(parent_class, "delete-start", del_to_home, GNT_KEY_CTRL_U, NULL); @@ -572,17 +572,17 @@ gnt_widget_class_register_action(parent_class, "cursor-prev-word", move_back_word, NULL, NULL); gnt_widget_class_register_action(parent_class, "cursor-prev", move_back, - "\033" GNT_KEY_LEFT, NULL); + GNT_KEY_LEFT, NULL); gnt_widget_register_binding(parent_class, "cursor-prev", GNT_KEY_CTRL_B, NULL); gnt_widget_class_register_action(parent_class, "cursor-next", move_forward, - "\033" GNT_KEY_RIGHT, NULL); + GNT_KEY_RIGHT, NULL); gnt_widget_register_binding(parent_class, "cursor-next", GNT_KEY_CTRL_F, NULL); gnt_widget_class_register_action(parent_class, "suggest-show", suggest_show, "\t", NULL); gnt_widget_class_register_action(parent_class, "suggest-next", suggest_next, - "\033" GNT_KEY_DOWN, NULL); + GNT_KEY_DOWN, NULL); gnt_widget_class_register_action(parent_class, "suggest-prev", suggest_prev, - "\033" GNT_KEY_UP, NULL); + GNT_KEY_UP, NULL); gnt_widget_class_register_action(parent_class, "history-prev", history_prev, "\033" GNT_KEY_CTRL_DOWN, NULL); gnt_widget_class_register_action(parent_class, "history-next", history_next, Modified: trunk/console/libgnt/gntkeys.c =================================================================== --- trunk/console/libgnt/gntkeys.c 2006-11-01 02:13:37 UTC (rev 17644) +++ trunk/console/libgnt/gntkeys.c 2006-11-01 03:38:23 UTC (rev 17645) @@ -2,28 +2,17 @@ #include <string.h> +const char *term; + void gnt_keys_refine(char *text) { - if (text[0] == 27) - { - /* These are for urxvt */ - if (strcmp(text + 1, "Oa") == 0) - { - strcpy(text + 1, GNT_KEY_CTRL_UP); - } - else if (strcmp(text + 1, "Ob") == 0) - { - strcpy(text + 1, GNT_KEY_CTRL_DOWN); - } + if (*text == 27 && *(text + 1) == '[' && *(text + 3) == '\0' && + (*(text + 2) >= 'A' || *(text + 2) <= 'D')) { + if (term == NULL) + term = getenv("TERM"); + /* Apparently this is necessary for urxvt and screen */ + if (strcmp(term, "screen") == 0 || strcmp(term, "rxvt-unicode") == 0) + *(text + 1) = 'O'; } - else if ((unsigned char)text[0] == 195) - { - /* These for xterm */ - if (text[2] == 0) - { - text[0] = 27; - text[1] -= 64; - } - } } Modified: trunk/console/libgnt/gntkeys.h =================================================================== --- trunk/console/libgnt/gntkeys.h 2006-11-01 02:13:37 UTC (rev 17644) +++ trunk/console/libgnt/gntkeys.h 2006-11-01 03:38:23 UTC (rev 17645) @@ -1,29 +1,34 @@ #ifndef GNT_KEYS_H #define GNT_KEYS_H -#define GNT_KEY_POPUP "[29~" +#include <curses.h> +#include <term.h> +#define SAFE(x) ((x) ? (x) : "") + +#define GNT_KEY_POPUP SAFE(key_f16) /* Apparently */ + /* Arrow keys */ -#define GNT_KEY_LEFT "[D" -#define GNT_KEY_RIGHT "[C" -#define GNT_KEY_UP "[A" -#define GNT_KEY_DOWN "[B" +#define GNT_KEY_LEFT SAFE(key_left) +#define GNT_KEY_RIGHT SAFE(key_right) +#define GNT_KEY_UP SAFE(key_up) +#define GNT_KEY_DOWN SAFE(key_down) #define GNT_KEY_CTRL_UP "[1;5A" #define GNT_KEY_CTRL_DOWN "[1;5B" #define GNT_KEY_CTRL_RIGHT "[1;5C" #define GNT_KEY_CTRL_LEFT "[1;5D" -#define GNT_KEY_PGUP "[5~" -#define GNT_KEY_PGDOWN "[6~" -#define GNT_KEY_HOME "[7~" -#define GNT_KEY_END "[8~" +#define GNT_KEY_PGUP SAFE(key_ppage) +#define GNT_KEY_PGDOWN SAFE(key_npage) +#define GNT_KEY_HOME SAFE(key_home) +#define GNT_KEY_END SAFE(key_end) -#define GNT_KEY_ENTER "\r" +#define GNT_KEY_ENTER carriage_return -#define GNT_KEY_BACKSPACE "\177" -#define GNT_KEY_DEL "[3~" -#define GNT_KEY_INS "[2~" +#define GNT_KEY_BACKSPACE SAFE(key_backspace) +#define GNT_KEY_DEL SAFE(key_dc) +#define GNT_KEY_INS SAFE(key_ic) #define GNT_KEY_CTRL_A "\001" #define GNT_KEY_CTRL_B "\002" @@ -48,18 +53,18 @@ #define GNT_KEY_CTRL_X "\030" #define GNT_KEY_CTRL_Y "\031" -#define GNT_KEY_F1 "[[A" -#define GNT_KEY_F2 "[[B" -#define GNT_KEY_F3 "[[C" -#define GNT_KEY_F4 "[[D" -#define GNT_KEY_F5 "[[E" -#define GNT_KEY_F6 "[17~" -#define GNT_KEY_F7 "[18~" -#define GNT_KEY_F8 "[19~" -#define GNT_KEY_F9 "[20~" -#define GNT_KEY_F10 "[21~" -#define GNT_KEY_F11 "[23~" -#define GNT_KEY_F12 "[24~" +#define GNT_KEY_F1 SAFE(key_f1) +#define GNT_KEY_F2 SAFE(key_f2) +#define GNT_KEY_F3 SAFE(key_f3) +#define GNT_KEY_F4 SAFE(key_f4) +#define GNT_KEY_F5 SAFE(key_f5) +#define GNT_KEY_F6 SAFE(key_f6) +#define GNT_KEY_F7 SAFE(key_f7) +#define GNT_KEY_F8 SAFE(key_f8) +#define GNT_KEY_F9 SAFE(key_f9) +#define GNT_KEY_F10 SAFE(key_f10) +#define GNT_KEY_F11 SAFE(key_f11) +#define GNT_KEY_F12 SAFE(key_f12) /** * This will do stuff with the terminal settings and stuff. Modified: trunk/console/libgnt/gntmain.c =================================================================== --- trunk/console/libgnt/gntmain.c 2006-11-01 02:13:37 UTC (rev 17644) +++ trunk/console/libgnt/gntmain.c 2006-11-01 03:38:23 UTC (rev 17645) @@ -822,7 +822,7 @@ if (buffer[0] == 27) { /* Some special key has been pressed */ - if (strcmp(buffer+1, GNT_KEY_POPUP) == 0) + if (strcmp(buffer, GNT_KEY_POPUP) == 0) {} else if (strcmp(buffer + 1, "c") == 0) { @@ -906,7 +906,7 @@ gnt_widget_get_position(widget, &x, &y); gnt_widget_get_size(widget, &w, &h); - if (strcmp(buffer + 1, GNT_KEY_LEFT) == 0) + if (strcmp(buffer, GNT_KEY_LEFT) == 0) { if (x > X_MIN) { @@ -914,7 +914,7 @@ changed = TRUE; } } - else if (strcmp(buffer + 1, GNT_KEY_RIGHT) == 0) + else if (strcmp(buffer, GNT_KEY_RIGHT) == 0) { if (x + w < X_MAX) { @@ -922,7 +922,7 @@ changed = TRUE; } } - else if (strcmp(buffer + 1, GNT_KEY_UP) == 0) + else if (strcmp(buffer, GNT_KEY_UP) == 0) { if (y > Y_MIN) { @@ -930,7 +930,7 @@ changed = TRUE; } } - else if (strcmp(buffer + 1, GNT_KEY_DOWN) == 0) + else if (strcmp(buffer, GNT_KEY_DOWN) == 0) { if (y + h < Y_MAX) { @@ -983,7 +983,7 @@ gnt_widget_get_size(widget, &width, &height); - if (strcmp(buffer + 1, GNT_KEY_DOWN) == 0) + if (strcmp(buffer, GNT_KEY_DOWN) == 0) { if (widget->priv.y + height < Y_MAX) { @@ -991,17 +991,17 @@ changed = TRUE; } } - else if (strcmp(buffer + 1, GNT_KEY_UP) == 0) + else if (strcmp(buffer, GNT_KEY_UP) == 0) { height--; changed = TRUE; } - else if (strcmp(buffer + 1, GNT_KEY_LEFT) == 0) + else if (strcmp(buffer, GNT_KEY_LEFT) == 0) { width--; changed = TRUE; } - else if (strcmp(buffer + 1, GNT_KEY_RIGHT) == 0) + else if (strcmp(buffer, GNT_KEY_RIGHT) == 0) { if (widget->priv.x + width < X_MAX) { Modified: trunk/console/libgnt/gntmenu.c =================================================================== --- trunk/console/libgnt/gntmenu.c 2006-11-01 02:13:37 UTC (rev 17644) +++ trunk/console/libgnt/gntmenu.c 2006-11-01 03:38:23 UTC (rev 17645) @@ -148,17 +148,15 @@ } if (menu->type == GNT_MENU_TOPLEVEL) { - if (text[0] == 27) { - if (strcmp(text + 1, GNT_KEY_LEFT) == 0) { - menu->selected--; - if (menu->selected < 0) - menu->selected = g_list_length(menu->list) - 1; - } else if (strcmp(text + 1, GNT_KEY_RIGHT) == 0) { - menu->selected++; - if (menu->selected >= g_list_length(menu->list)) - menu->selected = 0; - } - } else if (text[0] == '\r' && text[1] == 0) { + if (strcmp(text, GNT_KEY_LEFT) == 0) { + menu->selected--; + if (menu->selected < 0) + menu->selected = g_list_length(menu->list) - 1; + } else if (strcmp(text, GNT_KEY_RIGHT) == 0) { + menu->selected++; + if (menu->selected >= g_list_length(menu->list)) + menu->selected = 0; + } else if (strcmp(text, GNT_KEY_ENTER) == 0) { gnt_widget_activate(widget); } Modified: trunk/console/libgnt/gntstyle.c =================================================================== --- trunk/console/libgnt/gntstyle.c 2006-11-01 02:13:37 UTC (rev 17644) +++ trunk/console/libgnt/gntstyle.c 2006-11-01 03:38:23 UTC (rev 17645) @@ -94,33 +94,33 @@ return g_strdup(code); \ } while (0) - SPECIAL_KEY("home", "\033" GNT_KEY_HOME); - SPECIAL_KEY("end", "\033" GNT_KEY_END); - SPECIAL_KEY("pageup", "\033" GNT_KEY_PGUP); - SPECIAL_KEY("pagedown", "\033" GNT_KEY_PGDOWN); - SPECIAL_KEY("insert", "\033" GNT_KEY_INS); - SPECIAL_KEY("delete", "\033" GNT_KEY_DEL); + SPECIAL_KEY("home", GNT_KEY_HOME); + SPECIAL_KEY("end", GNT_KEY_END); + SPECIAL_KEY("pageup", GNT_KEY_PGUP); + SPECIAL_KEY("pagedown", GNT_KEY_PGDOWN); + SPECIAL_KEY("insert", GNT_KEY_INS); + SPECIAL_KEY("delete", GNT_KEY_DEL); - SPECIAL_KEY("left", "\033" GNT_KEY_LEFT); - SPECIAL_KEY("right", "\033" GNT_KEY_RIGHT); - SPECIAL_KEY("up", "\033" GNT_KEY_UP); - SPECIAL_KEY("down", "\033" GNT_KEY_DOWN); + SPECIAL_KEY("left", GNT_KEY_LEFT); + SPECIAL_KEY("right", GNT_KEY_RIGHT); + SPECIAL_KEY("up", GNT_KEY_UP); + SPECIAL_KEY("down", GNT_KEY_DOWN); SPECIAL_KEY("tab", "\t"); - SPECIAL_KEY("menu", "\033" GNT_KEY_POPUP); + SPECIAL_KEY("menu", GNT_KEY_POPUP); - SPECIAL_KEY("f1", "\033" GNT_KEY_F1); - SPECIAL_KEY("f2", "\033" GNT_KEY_F2); - SPECIAL_KEY("f3", "\033" GNT_KEY_F3); - SPECIAL_KEY("f4", "\033" GNT_KEY_F4); - SPECIAL_KEY("f5", "\033" GNT_KEY_F5); - SPECIAL_KEY("f6", "\033" GNT_KEY_F6); - SPECIAL_KEY("f7", "\033" GNT_KEY_F7); - SPECIAL_KEY("f8", "\033" GNT_KEY_F8); - SPECIAL_KEY("f9", "\033" GNT_KEY_F9); - SPECIAL_KEY("f10", "\033" GNT_KEY_F10); - SPECIAL_KEY("f11", "\033" GNT_KEY_F11); - SPECIAL_KEY("f12", "\033" GNT_KEY_F12); + SPECIAL_KEY("f1", GNT_KEY_F1); + SPECIAL_KEY("f2", GNT_KEY_F2); + SPECIAL_KEY("f3", GNT_KEY_F3); + SPECIAL_KEY("f4", GNT_KEY_F4); + SPECIAL_KEY("f5", GNT_KEY_F5); + SPECIAL_KEY("f6", GNT_KEY_F6); + SPECIAL_KEY("f7", GNT_KEY_F7); + SPECIAL_KEY("f8", GNT_KEY_F8); + SPECIAL_KEY("f9", GNT_KEY_F9); + SPECIAL_KEY("f10", GNT_KEY_F10); + SPECIAL_KEY("f11", GNT_KEY_F11); + SPECIAL_KEY("f12", GNT_KEY_F12); #undef SPECIAL_KEY Modified: trunk/console/libgnt/gnttextview.h =================================================================== --- trunk/console/libgnt/gnttextview.h 2006-11-01 02:13:37 UTC (rev 17644) +++ trunk/console/libgnt/gnttextview.h 2006-11-01 03:38:23 UTC (rev 17645) @@ -6,6 +6,10 @@ #include "gntcolors.h" #include "gntkeys.h" +#ifdef lines +#undef lines +#endif + #define GNT_TYPE_TEXTVIEW (gnt_text_view_get_gtype()) #define GNT_TEXT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_TEXTVIEW, GntTextView)) #define GNT_TEXT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_TEXTVIEW, GntTextViewClass)) Modified: trunk/console/libgnt/gnttree.c =================================================================== --- trunk/console/libgnt/gnttree.c 2006-11-01 02:13:37 UTC (rev 17644) +++ trunk/console/libgnt/gnttree.c 2006-11-01 03:38:23 UTC (rev 17645) @@ -709,15 +709,15 @@ g_str_equal, g_free, (GDestroyNotify)gnt_widget_action_param_free); gnt_widget_class_register_action(parent_class, "move-up", action_up, - "\033" GNT_KEY_UP, NULL); + GNT_KEY_UP, NULL); gnt_widget_register_binding(parent_class, "move-up", GNT_KEY_CTRL_P, NULL); gnt_widget_class_register_action(parent_class, "move-down", action_down, - "\033" GNT_KEY_DOWN, NULL); + GNT_KEY_DOWN, NULL); gnt_widget_register_binding(parent_class, "move-down", GNT_KEY_CTRL_N, NULL); gnt_widget_class_register_action(parent_class, "page-up", action_page_up, - "\033" GNT_KEY_PGUP, NULL); + GNT_KEY_PGUP, NULL); gnt_widget_class_register_action(parent_class, "page-down", action_page_down, - "\033" GNT_KEY_PGDOWN, NULL); + GNT_KEY_PGDOWN, NULL); gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), parent_class); Modified: trunk/console/libgnt/gnttree.h =================================================================== --- trunk/console/libgnt/gnttree.h 2006-11-01 02:13:37 UTC (rev 17644) +++ trunk/console/libgnt/gnttree.h 2006-11-01 03:38:23 UTC (rev 17645) @@ -7,6 +7,10 @@ #include "gntkeys.h" #include "gnttextview.h" +#ifdef columns +#undef columns +#endif + #define GNT_TYPE_TREE (gnt_tree_get_gtype()) #define GNT_TREE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_TREE, GntTree)) #define GNT_TREE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_TREE, GntTreeClass)) Modified: trunk/console/libgnt/gntwidget.c =================================================================== --- trunk/console/libgnt/gntwidget.c 2006-11-01 02:13:37 UTC (rev 17644) +++ trunk/console/libgnt/gntwidget.c 2006-11-01 03:38:23 UTC (rev 17645) @@ -259,7 +259,7 @@ /* This is relevant for all widgets */ gnt_widget_class_register_action(klass, "context-menu", context_menu, - "\033" GNT_KEY_POPUP, NULL); + GNT_KEY_POPUP, NULL); gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), klass); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-11-01 20:59:35
|
Revision: 17650 http://svn.sourceforge.net/gaim/?rev=17650&view=rev Author: sadrul Date: 2006-11-01 12:59:23 -0800 (Wed, 01 Nov 2006) Log Message: ----------- Print a debug message if someone tries to specify a binding for some non-existent action. Make sure the conversation windows aren't too large to cause a crash. raise(SIGABRT) instead of exit() to force a coredump if something goes wrong with stdin. Modified Paths: -------------- trunk/console/libgnt/gntmain.c trunk/console/libgnt/gnttextview.c trunk/console/libgnt/gntwidget.c Modified: trunk/console/libgnt/gntmain.c =================================================================== --- trunk/console/libgnt/gntmain.c 2006-11-01 19:23:39 UTC (rev 17649) +++ trunk/console/libgnt/gntmain.c 2006-11-01 20:59:23 UTC (rev 17650) @@ -774,16 +774,17 @@ int rd = read(STDIN_FILENO, keys, sizeof(keys) - 1); if (rd < 0) { + int ch = getch(); /* This should return ERR, but let's see what it really returns */ endwin(); printf("ERROR: %s\n", strerror(errno)); - printf("File descriptor is: %d\n\nGIOChannel is: %p", STDIN_FILENO, source); - exit(1); + printf("File descriptor is: %d\n\nGIOChannel is: %p\ngetch() = %d\n", STDIN_FILENO, source, ch); + raise(SIGABRT); } else if (rd == 0) { endwin(); printf("EOF\n"); - exit(1); + raise(SIGABRT); } event_stack = TRUE; @@ -1115,12 +1116,12 @@ (G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI | G_IO_NVAL), io_invoke, NULL, NULL); + g_io_channel_unref(channel); /* Apparently this caused crashes for some people. + But irssi does this, so I am going to assume the + crashes were caused by some other stuff. */ + locale = setlocale(LC_ALL, ""); -#if 0 - g_io_channel_unref(channel); /* Apparently this causes crash for some people */ -#endif - if (locale && (strstr(locale, "UTF") || strstr(locale, "utf"))) ascii_only = FALSE; else Modified: trunk/console/libgnt/gnttextview.c =================================================================== --- trunk/console/libgnt/gnttextview.c 2006-11-01 19:23:39 UTC (rev 17649) +++ trunk/console/libgnt/gnttextview.c 2006-11-01 20:59:23 UTC (rev 17650) @@ -211,7 +211,8 @@ } view->list = list; GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(view), GNT_WIDGET_DRAWING); - gnt_widget_draw(GNT_WIDGET(view)); + if (GNT_WIDGET(view)->window) + gnt_widget_draw(GNT_WIDGET(view)); g_string_free(string, TRUE); } Modified: trunk/console/libgnt/gntwidget.c =================================================================== --- trunk/console/libgnt/gntwidget.c 2006-11-01 19:23:39 UTC (rev 17649) +++ trunk/console/libgnt/gntwidget.c 2006-11-01 20:59:23 UTC (rev 17650) @@ -711,14 +711,24 @@ register_binding(GntWidgetClass *klass, const char *name, const char *trigger, GList *list) { GntWidgetActionParam *param; + GntWidgetAction *action; if (name == NULL || *name == '\0') { g_hash_table_remove(klass->bindings, (char*)trigger); return; } + action = g_hash_table_lookup(klass->actions, name); + if (!action) { + g_printerr("GntWidget: Invalid action name %s for %s\n", + name, g_type_name(G_OBJECT_CLASS_TYPE(klass))); + if (list) + g_list_free(list); + return; + } + param = g_new0(GntWidgetActionParam, 1); - param->action = g_hash_table_lookup(klass->actions, name); + param->action = action; param->list = list; g_hash_table_replace(klass->bindings, g_strdup(trigger), param); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-11-05 17:29:10
|
Revision: 17672 http://svn.sourceforge.net/gaim/?rev=17672&view=rev Author: sadrul Date: 2006-11-05 09:28:33 -0800 (Sun, 05 Nov 2006) Log Message: ----------- Rearranging a bunch of stuff. Users shouldn't notice any change, apart from the added ability to bind keys for the window-manager. I will update the manual in a while. I need to know how to revert a commit in case things go terribly wrong. ... I am going to remind everyone that Dido is AWESOME! Modified Paths: -------------- trunk/console/libgnt/Makefile.am trunk/console/libgnt/gntcombobox.c trunk/console/libgnt/gntentry.c trunk/console/libgnt/gntmain.c trunk/console/libgnt/gntmarshal.c trunk/console/libgnt/gntmarshal.h trunk/console/libgnt/gntmenu.c trunk/console/libgnt/gntmenuitem.c trunk/console/libgnt/gntstyle.c trunk/console/libgnt/gntstyle.h trunk/console/libgnt/gnttree.c trunk/console/libgnt/gntwidget.c trunk/console/libgnt/gntwidget.h trunk/console/libgnt/gntwm.h trunk/console/libgnt/test/multiwin.c trunk/console/libgnt/test/tv.c trunk/console/libgnt/wms/s.c Added Paths: ----------- trunk/console/libgnt/gntbindable.c trunk/console/libgnt/gntbindable.h trunk/console/libgnt/gntwm.c Modified: trunk/console/libgnt/Makefile.am =================================================================== --- trunk/console/libgnt/Makefile.am 2006-11-05 14:57:05 UTC (rev 17671) +++ trunk/console/libgnt/Makefile.am 2006-11-05 17:28:33 UTC (rev 17672) @@ -6,6 +6,7 @@ libgnt_la_SOURCES = \ gntwidget.c \ + gntbindable.c \ gntbox.c \ gntbutton.c \ gntcheckbox.c \ @@ -24,10 +25,12 @@ gnttree.c \ gntutils.c \ gntwindow.c \ + gntwm.c \ gntmain.c libgnt_la_headers = \ gntwidget.h \ + gntbindable.h \ gntbox.h \ gntbutton.h \ gntcheckbox.h \ Added: trunk/console/libgnt/gntbindable.c =================================================================== --- trunk/console/libgnt/gntbindable.c (rev 0) +++ trunk/console/libgnt/gntbindable.c 2006-11-05 17:28:33 UTC (rev 17672) @@ -0,0 +1,212 @@ +#include "gntbindable.h" +#include "gntstyle.h" +#include "gnt.h" +#include "gntutils.h" + +static GObjectClass *parent_class = NULL; + +static void +gnt_bindable_class_init(GntBindableClass *klass) +{ + parent_class = g_type_class_peek_parent(klass); + + klass->actions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, + (GDestroyNotify)gnt_bindable_action_free); + klass->bindings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, + (GDestroyNotify)gnt_bindable_action_param_free); + + gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass)); + GNTDEBUG; +} + +static void +duplicate_hashes(GntBindableClass *klass) +{ + /* Duplicate the bindings from parent class */ + if (klass->actions) { + klass->actions = g_hash_table_duplicate(klass->actions, g_str_hash, + g_str_equal, g_free, (GDestroyNotify)gnt_bindable_action_free); + klass->bindings = g_hash_table_duplicate(klass->bindings, g_str_hash, + g_str_equal, g_free, (GDestroyNotify)gnt_bindable_action_param_free); + } else { + klass->actions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, + (GDestroyNotify)gnt_bindable_action_free); + klass->bindings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, + (GDestroyNotify)gnt_bindable_action_param_free); + } + + GNTDEBUG; +} + +/****************************************************************************** + * GntBindable API + *****************************************************************************/ +GType +gnt_bindable_get_gtype(void) +{ + static GType type = 0; + + if(type == 0) { + static const GTypeInfo info = { + sizeof(GntBindableClass), + (GBaseInitFunc)duplicate_hashes, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc)gnt_bindable_class_init, + NULL, + NULL, /* class_data */ + sizeof(GntBindable), + 0, /* n_preallocs */ + NULL, /* instance_init */ + }; + + type = g_type_register_static(G_TYPE_OBJECT, + "GntBindable", + &info, G_TYPE_FLAG_ABSTRACT); + } + + return type; +} + +/** + * Key Remaps + */ +const char * +gnt_bindable_remap_keys(GntBindable *bindable, const char *text) +{ + const char *remap = NULL; + GType type = G_OBJECT_TYPE(bindable); + GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bindable)); + + if (klass->remaps == NULL) + { + klass->remaps = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + gnt_styles_get_keyremaps(type, klass->remaps); + } + + remap = g_hash_table_lookup(klass->remaps, text); + + return (remap ? remap : text); +} + +/** + * Actions and Bindings + */ +gboolean +gnt_bindable_perform_action_named(GntBindable *bindable, const char *name, ...) +{ + GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bindable)); + GList *list = NULL; + va_list args; + GntBindableAction *action; + void *p; + + va_start(args, name); + while ((p = va_arg(args, void *)) != NULL) + list = g_list_append(list, p); + va_end(args); + + action = g_hash_table_lookup(klass->actions, name); + if (action && action->u.action) { + if (list) + return action->u.action(bindable, list); + else + return action->u.action_noparam(bindable); + } + return FALSE; +} + +gboolean +gnt_bindable_perform_action_key(GntBindable *bindable, const char *keys) +{ + GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bindable)); + GntBindableActionParam *param = g_hash_table_lookup(klass->bindings, keys); + + if (param && param->action) { + if (param->list) + return param->action->u.action(bindable, param->list); + else + return param->action->u.action_noparam(bindable); + } + return FALSE; +} + +static void +register_binding(GntBindableClass *klass, const char *name, const char *trigger, GList *list) +{ + GntBindableActionParam *param; + GntBindableAction *action; + + if (name == NULL || *name == '\0') { + g_hash_table_remove(klass->bindings, (char*)trigger); + return; + } + + action = g_hash_table_lookup(klass->actions, name); + if (!action) { + g_printerr("GntWidget: Invalid action name %s for %s\n", + name, g_type_name(G_OBJECT_CLASS_TYPE(klass))); + if (list) + g_list_free(list); + return; + } + + param = g_new0(GntBindableActionParam, 1); + param->action = action; + param->list = list; + g_hash_table_replace(klass->bindings, g_strdup(trigger), param); +} + +void gnt_bindable_register_binding(GntBindableClass *klass, const char *name, + const char *trigger, ...) +{ + GList *list = NULL; + va_list args; + void *data; + + va_start(args, trigger); + while ((data = va_arg(args, void *))) { + list = g_list_append(list, data); + } + va_end(args); + + register_binding(klass, name, trigger, list); +} + +void gnt_bindable_class_register_action(GntBindableClass *klass, const char *name, + GntBindableActionCallback callback, const char *trigger, ...) +{ + void *data; + va_list args; + GntBindableAction *action = g_new0(GntBindableAction, 1); + GList *list; + + action->name = g_strdup(name); + action->u.action = callback; + + g_hash_table_replace(klass->actions, g_strdup(name), action); + + if (trigger) { + list = NULL; + va_start(args, trigger); + while ((data = va_arg(args, void *))) { + list = g_list_append(list, data); + } + va_end(args); + + register_binding(klass, name, trigger, list); + } +} + +void gnt_bindable_action_free(GntBindableAction *action) +{ + g_free(action->name); + g_free(action); +} + +void gnt_bindable_action_param_free(GntBindableActionParam *param) +{ + g_list_free(param->list); /* XXX: There may be a leak here for string parameters */ + g_free(param); +} + + Property changes on: trunk/console/libgnt/gntbindable.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: trunk/console/libgnt/gntbindable.h =================================================================== --- trunk/console/libgnt/gntbindable.h (rev 0) +++ trunk/console/libgnt/gntbindable.h 2006-11-05 17:28:33 UTC (rev 17672) @@ -0,0 +1,90 @@ +#ifndef GNT_BINDABLE_H +#define GNT_BINDABLE_H + +#include <stdio.h> +#include <glib.h> +#include <glib-object.h> +#include <ncurses.h> + +#define GNT_TYPE_BINDABLE (gnt_bindable_get_gtype()) +#define GNT_BINDABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_BINDABLE, GntBindable)) +#define GNT_BINDABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_BINDABLE, GntBindableClass)) +#define GNT_IS_BINDABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_BINDABLE)) +#define GNT_IS_BINDABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_BINDABLE)) +#define GNT_BINDABLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_BINDABLE, GntBindableClass)) + +#define GNTDEBUG fprintf(stderr, "%s\n", __FUNCTION__) + +typedef struct _GnBindable GntBindable; +typedef struct _GnBindableClass GntBindableClass; + +struct _GnBindable +{ + GObject inherit; +}; + +struct _GnBindableClass +{ + GObjectClass parent; + + GHashTable *remaps; /* Key remaps */ + GHashTable *actions; /* name -> Action */ + GHashTable *bindings; /* key -> ActionParam */ + + void (*gnt_reserved1)(void); + void (*gnt_reserved2)(void); + void (*gnt_reserved3)(void); + void (*gnt_reserved4)(void); +}; + +G_BEGIN_DECLS + +GType gnt_bindable_get_gtype(void); + +/******************/ +/* Key Remaps */ +/******************/ +const char * gnt_bindable_remap_keys(GntBindable *bindable, const char *text); + +/******************/ +/* Bindable Actions */ +/******************/ +typedef gboolean (*GntBindableActionCallback) (GntBindable *bindable, GList *params); +typedef gboolean (*GntBindableActionCallbackNoParam)(GntBindable *bindable); + +typedef struct _GnBindableAction GntBindableAction; +typedef struct _GnBindableActionParam GntBindableActionParam; + +struct _GnBindableAction +{ + char *name; /* The name of the action */ + union { + gboolean (*action)(GntBindable *bindable, GList *params); + gboolean (*action_noparam)(GntBindable *bindable); + } u; +}; + +struct _GnBindableActionParam +{ + GntBindableAction *action; + GList *list; +}; + + +/*GntBindableAction *gnt_bindable_action_parse(const char *name);*/ + +void gnt_bindable_action_free(GntBindableAction *action); +void gnt_bindable_action_param_free(GntBindableActionParam *param); + +void gnt_bindable_class_register_action(GntBindableClass *klass, const char *name, + GntBindableActionCallback callback, const char *trigger, ...); +void gnt_bindable_register_binding(GntBindableClass *klass, const char *name, + const char *trigger, ...); + +gboolean gnt_bindable_perform_action_key(GntBindable *bindable, const char *keys); +gboolean gnt_bindable_perform_action_named(GntBindable *bindable, const char *name, ...); + +G_END_DECLS + +#endif /* GNT_BINDABLE_H */ + Property changes on: trunk/console/libgnt/gntbindable.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Modified: trunk/console/libgnt/gntcombobox.c =================================================================== --- trunk/console/libgnt/gntcombobox.c 2006-11-05 14:57:05 UTC (rev 17671) +++ trunk/console/libgnt/gntcombobox.c 2006-11-05 17:28:33 UTC (rev 17672) @@ -105,6 +105,7 @@ parent->priv.width = widget->priv.width; parent->priv.height = height + 2; + GNT_WIDGET_UNSET_FLAGS(parent, GNT_WIDGET_INVISIBLE); gnt_widget_draw(parent); } Modified: trunk/console/libgnt/gntentry.c =================================================================== --- trunk/console/libgnt/gntentry.c 2006-11-05 14:57:05 UTC (rev 17671) +++ trunk/console/libgnt/gntentry.c 2006-11-05 17:28:33 UTC (rev 17672) @@ -74,8 +74,6 @@ if (y + 10 >= getmaxy(stdscr)) y -= 11; gnt_widget_set_position(box, x, y); - - gnt_widget_draw(box); } else gnt_tree_remove_all(GNT_TREE(entry->ddown)); @@ -99,6 +97,7 @@ return FALSE; } + gnt_widget_draw(entry->ddown->parent); return TRUE; } @@ -159,9 +158,9 @@ } static gboolean -move_back(GntWidget *widget, GList *null) +move_back(GntBindable *bind, GList *null) { - GntEntry *entry = GNT_ENTRY(widget); + GntEntry *entry = GNT_ENTRY(bind); if (entry->cursor <= entry->start) return FALSE; entry->cursor = g_utf8_find_prev_char(entry->start, entry->cursor); @@ -172,9 +171,9 @@ } static gboolean -move_forward(GntWidget *widget, GList *list) +move_forward(GntBindable *bind, GList *list) { - GntEntry *entry = GNT_ENTRY(widget); + GntEntry *entry = GNT_ENTRY(bind); if (entry->cursor >= entry->end) return FALSE; entry->cursor = g_utf8_find_next_char(entry->cursor, NULL); @@ -185,10 +184,10 @@ } static gboolean -backspace(GntWidget *widget, GList *null) +backspace(GntBindable *bind, GList *null) { int len; - GntEntry *entry = GNT_ENTRY(widget); + GntEntry *entry = GNT_ENTRY(bind); if (entry->cursor <= entry->start) return TRUE; @@ -208,10 +207,10 @@ } static gboolean -delkey(GntWidget *widget, GList *null) +delkey(GntBindable *bind, GList *null) { int len; - GntEntry *entry = GNT_ENTRY(widget); + GntEntry *entry = GNT_ENTRY(bind); if (entry->cursor >= entry->end) return FALSE; @@ -227,18 +226,18 @@ } static gboolean -move_start(GntWidget *widget, GList *null) +move_start(GntBindable *bind, GList *null) { - GntEntry *entry = GNT_ENTRY(widget); + GntEntry *entry = GNT_ENTRY(bind); entry->scroll = entry->cursor = entry->start; entry_redraw(GNT_WIDGET(entry)); return TRUE; } static gboolean -move_end(GntWidget *widget, GList *null) +move_end(GntBindable *bind, GList *null) { - GntEntry *entry = GNT_ENTRY(widget); + GntEntry *entry = GNT_ENTRY(bind); entry->cursor = entry->end; /* This should be better than this */ while (gnt_util_onscreen_width(entry->scroll, entry->cursor) >= GNT_WIDGET(entry)->priv.width) @@ -248,9 +247,9 @@ } static gboolean -history_prev(GntWidget *widget, GList *null) +history_prev(GntBindable *bind, GList *null) { - GntEntry *entry = GNT_ENTRY(widget); + GntEntry *entry = GNT_ENTRY(bind); if (entry->histlength && entry->history->prev) { entry->history = entry->history->prev; @@ -263,9 +262,9 @@ } static gboolean -history_next(GntWidget *widget, GList *null) +history_next(GntBindable *bind, GList *null) { - GntEntry *entry = GNT_ENTRY(widget); + GntEntry *entry = GNT_ENTRY(bind); if (entry->histlength && entry->history->next) { if (entry->history->prev == NULL) @@ -286,52 +285,52 @@ } static gboolean -suggest_show(GntWidget *widget, GList *null) +suggest_show(GntBindable *bind, GList *null) { - return show_suggest_dropdown(GNT_ENTRY(widget)); + return show_suggest_dropdown(GNT_ENTRY(bind)); } static gboolean -suggest_next(GntWidget *widget, GList *null) +suggest_next(GntBindable *bind, GList *null) { - GntEntry *entry = GNT_ENTRY(widget); + GntEntry *entry = GNT_ENTRY(bind); if (entry->ddown) { - gnt_widget_perform_action_named(entry->ddown, "move-down", NULL); + gnt_bindable_perform_action_named(GNT_BINDABLE(entry->ddown), "move-down", NULL); return TRUE; } return FALSE; } static gboolean -suggest_prev(GntWidget *widget, GList *null) +suggest_prev(GntBindable *bind, GList *null) { - GntEntry *entry = GNT_ENTRY(widget); + GntEntry *entry = GNT_ENTRY(bind); if (entry->ddown) { - gnt_widget_perform_action_named(entry->ddown, "move-up", NULL); + gnt_bindable_perform_action_named(GNT_BINDABLE(entry->ddown), "move-up", NULL); return TRUE; } return FALSE; } static gboolean -del_to_home(GntWidget *widget, GList *null) +del_to_home(GntBindable *bind, GList *null) { - GntEntry *entry = GNT_ENTRY(widget); + GntEntry *entry = GNT_ENTRY(bind); memmove(entry->start, entry->cursor, entry->end - entry->cursor); entry->end -= (entry->cursor - entry->start); entry->cursor = entry->scroll = entry->start; memset(entry->end, '\0', entry->buffer - (entry->end - entry->start)); - entry_redraw(widget); + entry_redraw(GNT_WIDGET(bind)); return TRUE; } static gboolean -del_to_end(GntWidget *widget, GList *null) +del_to_end(GntBindable *bind, GList *null) { - GntEntry *entry = GNT_ENTRY(widget); + GntEntry *entry = GNT_ENTRY(bind); entry->end = entry->cursor; memset(entry->end, '\0', entry->buffer - (entry->end - entry->start)); - entry_redraw(widget); + entry_redraw(GNT_WIDGET(bind)); return TRUE; } @@ -351,9 +350,9 @@ } static gboolean -move_back_word(GntWidget *widget, GList *null) +move_back_word(GntBindable *bind, GList *null) { - GntEntry *entry = GNT_ENTRY(widget); + GntEntry *entry = GNT_ENTRY(bind); const char *iter = entry->cursor - 1; if (iter < entry->start) @@ -362,14 +361,15 @@ entry->cursor = (char*)iter; if (entry->cursor < entry->scroll) entry->scroll = entry->cursor; - entry_redraw(widget); + entry_redraw(GNT_WIDGET(bind)); return TRUE; } static gboolean -del_prev_word(GntWidget *widget, GList *null) +del_prev_word(GntBindable *bind, GList *null) { - GntEntry *entry = GNT_ENTRY(widget); + GntWidget *widget = GNT_WIDGET(bind); + GntEntry *entry = GNT_ENTRY(bind); char *iter = entry->cursor - 1; int count; @@ -535,6 +535,7 @@ static void gnt_entry_class_init(GntEntryClass *klass) { + GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass); parent_class = GNT_WIDGET_CLASS(klass); parent_class->destroy = gnt_entry_destroy; parent_class->draw = gnt_entry_draw; @@ -543,53 +544,47 @@ parent_class->key_pressed = gnt_entry_key_pressed; parent_class->lost_focus = gnt_entry_lost_focus; - parent_class->actions = g_hash_table_duplicate(parent_class->actions, g_str_hash, - g_str_equal, g_free, (GDestroyNotify)gnt_widget_action_free); - parent_class->bindings = g_hash_table_duplicate(parent_class->bindings, g_str_hash, - g_str_equal, g_free, (GDestroyNotify)gnt_widget_action_param_free); - - gnt_widget_class_register_action(parent_class, "cursor-home", move_start, + gnt_bindable_class_register_action(bindable, "cursor-home", move_start, GNT_KEY_CTRL_A, NULL); - gnt_widget_register_binding(parent_class, "cursor-home", GNT_KEY_HOME, NULL); - gnt_widget_class_register_action(parent_class, "cursor-end", move_end, + gnt_bindable_register_binding(bindable, "cursor-home", GNT_KEY_HOME, NULL); + gnt_bindable_class_register_action(bindable, "cursor-end", move_end, GNT_KEY_CTRL_E, NULL); - gnt_widget_register_binding(parent_class, "cursor-end", GNT_KEY_END, NULL); - gnt_widget_class_register_action(parent_class, "delete-prev", backspace, + gnt_bindable_register_binding(bindable, "cursor-end", GNT_KEY_END, NULL); + gnt_bindable_class_register_action(bindable, "delete-prev", backspace, GNT_KEY_BACKSPACE, NULL); - gnt_widget_class_register_action(parent_class, "delete-next", delkey, + gnt_bindable_class_register_action(bindable, "delete-next", delkey, GNT_KEY_DEL, NULL); - gnt_widget_register_binding(parent_class, "delete-next", GNT_KEY_CTRL_D, NULL); - gnt_widget_class_register_action(parent_class, "delete-start", del_to_home, + gnt_bindable_register_binding(bindable, "delete-next", GNT_KEY_CTRL_D, NULL); + gnt_bindable_class_register_action(bindable, "delete-start", del_to_home, GNT_KEY_CTRL_U, NULL); - gnt_widget_class_register_action(parent_class, "delete-end", del_to_end, + gnt_bindable_class_register_action(bindable, "delete-end", del_to_end, GNT_KEY_CTRL_K, NULL); - gnt_widget_class_register_action(parent_class, "delete-prev-word", del_prev_word, + gnt_bindable_class_register_action(bindable, "delete-prev-word", del_prev_word, NULL, NULL); #if 0 - gnt_widget_class_register_action(parent_class, "delete-next-word", del_next_word, + gnt_bindable_class_register_action(bindable, "delete-next-word", del_next_word, NULL, 1, NULL); #endif - gnt_widget_class_register_action(parent_class, "cursor-prev-word", move_back_word, + gnt_bindable_class_register_action(bindable, "cursor-prev-word", move_back_word, NULL, NULL); - gnt_widget_class_register_action(parent_class, "cursor-prev", move_back, + gnt_bindable_class_register_action(bindable, "cursor-prev", move_back, GNT_KEY_LEFT, NULL); - gnt_widget_register_binding(parent_class, "cursor-prev", GNT_KEY_CTRL_B, NULL); - gnt_widget_class_register_action(parent_class, "cursor-next", move_forward, + gnt_bindable_register_binding(bindable, "cursor-prev", GNT_KEY_CTRL_B, NULL); + gnt_bindable_class_register_action(bindable, "cursor-next", move_forward, GNT_KEY_RIGHT, NULL); - gnt_widget_register_binding(parent_class, "cursor-next", GNT_KEY_CTRL_F, NULL); - gnt_widget_class_register_action(parent_class, "suggest-show", suggest_show, + gnt_bindable_register_binding(bindable, "cursor-next", GNT_KEY_CTRL_F, NULL); + gnt_bindable_class_register_action(bindable, "suggest-show", suggest_show, "\t", NULL); - gnt_widget_class_register_action(parent_class, "suggest-next", suggest_next, + gnt_bindable_class_register_action(bindable, "suggest-next", suggest_next, GNT_KEY_DOWN, NULL); - gnt_widget_class_register_action(parent_class, "suggest-prev", suggest_prev, + gnt_bindable_class_register_action(bindable, "suggest-prev", suggest_prev, GNT_KEY_UP, NULL); - gnt_widget_class_register_action(parent_class, "history-prev", history_prev, + gnt_bindable_class_register_action(bindable, "history-prev", history_prev, "\033" GNT_KEY_CTRL_DOWN, NULL); - gnt_widget_class_register_action(parent_class, "history-next", history_next, + gnt_bindable_class_register_action(bindable, "history-next", history_next, "\033" GNT_KEY_CTRL_UP, NULL); - gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), parent_class); - + gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass)); GNTDEBUG; } Modified: trunk/console/libgnt/gntmain.c =================================================================== --- trunk/console/libgnt/gntmain.c 2006-11-05 14:57:05 UTC (rev 17671) +++ trunk/console/libgnt/gntmain.c 2006-11-05 17:28:33 UTC (rev 17672) @@ -38,544 +38,17 @@ * Need to wattrset for colors to use with PDCurses. */ -/** - * There can be at most one menu at a time on the screen. - * If there is a menu being displayed, then all the keystrokes will be sent to - * the menu until it is closed, either when the user activates a menuitem, or - * presses Escape to cancel the menu. - */ -static GntMenu *menu; +static GIOChannel *channel = NULL; -static int lock_focus_list; -static GList *focus_list; -static GList *ordered; - -static int X_MIN; -static int X_MAX; -static int Y_MIN; -static int Y_MAX; - static gboolean ascii_only; static gboolean mouse_enabled; -/** - * 'event_stack' will be set to TRUE when a user-event, ie. a mouse-click - * or a key-press is being processed. This variable will be used to determine - * whether to give focus to a new window. - */ -static gboolean event_stack; +static void setup_io(); -static GMainLoop *loop; - -static struct -{ - GntWidget *window; - GntWidget *tree; -} _list, *window_list, *action_list; - -typedef struct -{ - GntWidget *me; - - PANEL *panel; -} GntNode; - -typedef enum -{ - GNT_KP_MODE_NORMAL, - GNT_KP_MODE_RESIZE, - GNT_KP_MODE_MOVE, - GNT_KP_MODE_MENU, - GNT_KP_MODE_WINDOW_LIST -} GntKeyPressMode; - -static GHashTable *nodes; - -static void free_node(gpointer data); -static void draw_taskbar(gboolean reposition); -static void bring_on_top(GntWidget *widget); - static gboolean refresh_screen(); -static const GList *list_all_windows(); -static void show_actions_list(); +GntWM *wm; -static GntWM wm = -{ - NULL, /* new_window */ - NULL, /* close_window */ - NULL, /* window_resize_confirm */ - NULL, /* window_resized */ - NULL, /* window_move_confirm */ - NULL, /* window_moved */ - NULL, /* window_update */ - NULL, /* key_pressed */ - NULL, /* mouse clicked */ - bring_on_top, /* give_focus */ - NULL, /* uninit */ - list_all_windows, /* window_list */ -}; - -static const GList *list_all_windows() -{ - return focus_list; -} - -static GList * -g_list_bring_to_front(GList *list, gpointer data) -{ - list = g_list_remove(list, data); - list = g_list_prepend(list, data); - return list; -} - -static gboolean -update_screen(gpointer null) -{ - if (menu) { - GntMenu *top = menu; - while (top) { - GntNode *node = g_hash_table_lookup(nodes, top); - if (node) - top_panel(node->panel); - top = top->submenu; - } - } - update_panels(); - doupdate(); - return TRUE; -} - -void gnt_screen_take_focus(GntWidget *widget) -{ - GntWidget *w = NULL; - - if (lock_focus_list) - return; - if (g_list_find(focus_list, widget)) - return; - - if (ordered) - w = ordered->data; - - focus_list = g_list_append(focus_list, widget); - - if (event_stack) { - ordered = g_list_prepend(ordered, widget); - g_object_set_data(G_OBJECT(widget), "give_focus", GINT_TO_POINTER(event_stack)); - } else - ordered = g_list_append(ordered, widget); - - gnt_widget_set_focus(widget, TRUE); - if (w) - gnt_widget_set_focus(w, FALSE); - draw_taskbar(FALSE); -} - -void gnt_screen_remove_widget(GntWidget *widget) -{ - int pos = g_list_index(focus_list, widget); - - if (lock_focus_list) - return; - - if (pos == -1) - return; - - focus_list = g_list_remove(focus_list, widget); - ordered = g_list_remove(ordered, widget); - - if (ordered) - { - wm.give_focus(ordered->data); - } - draw_taskbar(FALSE); -} - -static void -bring_on_top(GntWidget *widget) -{ - GntNode *node = g_hash_table_lookup(nodes, widget); - - if (!node) - return; - - if (ordered->data != widget) { - GntWidget *w = ordered->data; - ordered = g_list_bring_to_front(ordered, widget); - gnt_widget_set_focus(w, FALSE); - } - - gnt_widget_set_focus(widget, TRUE); - gnt_widget_draw(widget); - top_panel(node->panel); - - if (_list.window) - { - GntNode *nd = g_hash_table_lookup(nodes, _list.window); - top_panel(nd->panel); - } - update_screen(NULL); - draw_taskbar(FALSE); -} - -static void -update_window_in_list(GntWidget *wid) -{ - GntTextFormatFlags flag = 0; - - if (window_list == NULL) - return; - - if (wid == ordered->data) - flag |= GNT_TEXT_FLAG_DIM; - else if (GNT_WIDGET_IS_FLAG_SET(wid, GNT_WIDGET_URGENT)) - flag |= GNT_TEXT_FLAG_BOLD; - - gnt_tree_set_row_flags(GNT_TREE(window_list->tree), wid, flag); -} - -static void -draw_taskbar(gboolean reposition) -{ - static WINDOW *taskbar = NULL; - GList *iter; - int n, width = 0; - int i; - - if (taskbar == NULL) - { - taskbar = newwin(1, getmaxx(stdscr), getmaxy(stdscr) - 1, 0); - } - else if (reposition) - { - mvwin(taskbar, Y_MAX, 0); - } - - wbkgdset(taskbar, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); - werase(taskbar); - - n = g_list_length(focus_list); - if (n) - width = getmaxx(stdscr) / n; - - for (i = 0, iter = focus_list; iter; iter = iter->next, i++) - { - GntWidget *w = iter->data; - int color; - const char *title; - - if (w == ordered->data) { - /* This is the current window in focus */ - color = GNT_COLOR_TITLE; - GNT_WIDGET_UNSET_FLAGS(w, GNT_WIDGET_URGENT); - if (wm.window_update) { - GntNode *node = g_hash_table_lookup(nodes, w); - wm.window_update(node ? node->panel : NULL, w); - } - } else if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_URGENT)) { - /* This is a window with the URGENT hint set */ - color = GNT_COLOR_URGENT; - } else { - color = GNT_COLOR_NORMAL; - } - wbkgdset(taskbar, '\0' | COLOR_PAIR(color)); - mvwhline(taskbar, 0, width * i, ' ' | COLOR_PAIR(color), width); - title = GNT_BOX(w)->title; - mvwprintw(taskbar, 0, width * i, "%s", title ? title : "<gnt>"); - if (i) - mvwaddch(taskbar, 0, width *i - 1, ACS_VLINE | A_STANDOUT | COLOR_PAIR(GNT_COLOR_NORMAL)); - - update_window_in_list(w); - } - - wrefresh(taskbar); -} - -static void -switch_window(int direction) -{ - GntWidget *w = NULL, *wid = NULL; - int pos; - - if (!ordered || !ordered->next) - return; - - w = ordered->data; - pos = g_list_index(focus_list, w); - pos += direction; - - if (pos < 0) - wid = g_list_last(focus_list)->data; - else if (pos >= g_list_length(focus_list)) - wid = focus_list->data; - else if (pos >= 0) - wid = g_list_nth_data(focus_list, pos); - - ordered = g_list_bring_to_front(ordered, wid); - - wm.give_focus(ordered->data); - - if (w != wid) - { - gnt_widget_set_focus(w, FALSE); - } -} - -static void -switch_window_n(int n) -{ - GntWidget *w = NULL; - GList *l; - - if (!ordered) - return; - - w = ordered->data; - - if ((l = g_list_nth(focus_list, n)) != NULL) - { - ordered = g_list_bring_to_front(ordered, l->data); - wm.give_focus(ordered->data); - } - - if (l && w != l->data) - { - gnt_widget_set_focus(w, FALSE); - } -} - -static void -window_list_activate(GntTree *tree, gpointer null) -{ - GntWidget *widget = gnt_tree_get_selection_data(GNT_TREE(tree)); - GntWidget *old = NULL; - - if (!ordered || !widget) - return; - - old = ordered->data; - ordered = g_list_bring_to_front(ordered, widget); - wm.give_focus(widget); - - if (old != widget) - { - gnt_widget_set_focus(old, FALSE); - } -} - -static void -setup__list() -{ - GntWidget *tree, *win; - win = _list.window = gnt_box_new(FALSE, FALSE); - gnt_box_set_toplevel(GNT_BOX(win), TRUE); - gnt_box_set_pad(GNT_BOX(win), 0); - - tree = _list.tree = gnt_tree_new(); - gnt_box_add_widget(GNT_BOX(win), tree); -} - -static void -show_window_list() -{ - GntWidget *tree, *win; - GList *iter; - - if (window_list) - return; - - setup__list(); - - window_list = &_list; - - win = window_list->window; - tree = window_list->tree; - - gnt_box_set_title(GNT_BOX(win), "Window List"); - - for (iter = focus_list; iter; iter = iter->next) - { - GntBox *box = GNT_BOX(iter->data); - - gnt_tree_add_row_last(GNT_TREE(tree), box, - gnt_tree_create_row(GNT_TREE(tree), box->title), NULL); - update_window_in_list(GNT_WIDGET(box)); - } - - gnt_tree_set_selected(GNT_TREE(tree), ordered->data); - g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(window_list_activate), NULL); - - gnt_tree_set_col_width(GNT_TREE(tree), 0, getmaxx(stdscr) / 3); - gnt_widget_set_size(tree, 0, getmaxy(stdscr) / 2); - gnt_widget_set_position(win, getmaxx(stdscr) / 3, getmaxy(stdscr) / 4); - - lock_focus_list = 1; - gnt_widget_show(win); - lock_focus_list = 0; -} - -static void -shift_window(GntWidget *widget, int dir) -{ - GList *all = focus_list; - GList *list = g_list_find(all, widget); - int length, pos; - if (!list) - return; - - length = g_list_length(all); - pos = g_list_position(all, list); - - pos += dir; - if (dir > 0) - pos++; - - if (pos < 0) - pos = length; - else if (pos > length) - pos = 0; - - all = g_list_insert(all, widget, pos); - all = g_list_delete_link(all, list); - focus_list = all; - draw_taskbar(FALSE); -} - -static void -dump_screen() -{ - int x, y; - chtype old = 0, now = 0; - FILE *file = fopen("dump.html", "w"); - - fprintf(file, "<pre>"); - for (y = 0; y < getmaxy(stdscr); y++) - { - for (x = 0; x < getmaxx(stdscr); x++) - { - char ch; - now = mvwinch(curscr, y, x); - ch = now & A_CHARTEXT; - now ^= ch; - -#define CHECK(attr, start, end) \ - do \ - { \ - if (now & attr) \ - { \ - if (!(old & attr)) \ - fprintf(file, start); \ - } \ - else if (old & attr) \ - { \ - fprintf(file, end); \ - } \ - } while (0) - - CHECK(A_BOLD, "<b>", "</b>"); - CHECK(A_UNDERLINE, "<u>", "</u>"); - CHECK(A_BLINK, "<blink>", "</blink>"); - - if ((now & A_COLOR) != (old & A_COLOR) || - (now & A_REVERSE) != (old & A_REVERSE)) - { - int ret; - short fgp, bgp, r, g, b; - struct - { - int r, g, b; - } fg, bg; - - ret = pair_content(PAIR_NUMBER(now & A_COLOR), &fgp, &bgp); - if (fgp == -1) - fgp = COLOR_BLACK; - if (bgp == -1) - bgp = COLOR_WHITE; - if (now & A_REVERSE) - fgp ^= bgp ^= fgp ^= bgp; /* *wink* */ - ret = color_content(fgp, &r, &g, &b); - fg.r = r; fg.b = b; fg.g = g; - ret = color_content(bgp, &r, &g, &b); - bg.r = r; bg.b = b; bg.g = g; -#define ADJUST(x) (x = x * 255 / 1000) - ADJUST(fg.r); - ADJUST(fg.g); - ADJUST(fg.b); - ADJUST(bg.r); - ADJUST(bg.b); - ADJUST(bg.g); - - if (x) fprintf(file, "</span>"); - fprintf(file, "<span style=\"background:#%02x%02x%02x;color:#%02x%02x%02x\">", - bg.r, bg.g, bg.b, fg.r, fg.g, fg.b); - } - if (now & A_ALTCHARSET) - { - switch (ch) - { - case 'q': - ch = '-'; break; - case 't': - case 'u': - case 'x': - ch = '|'; break; - case 'v': - case 'w': - case 'l': - case 'm': - case 'k': - case 'j': - case 'n': - ch = '+'; break; - case '-': - ch = '^'; break; - case '.': - ch = 'v'; break; - case 'a': - ch = '#'; break; - default: - ch = ' '; break; - } - } - if (ch == '&') - fprintf(file, "&"); - else if (ch == '<') - fprintf(file, "<"); - else if (ch == '>') - fprintf(file, ">"); - else - fprintf(file, "%c", ch); - old = now; - } - fprintf(file, "</span>\n"); - old = 0; - } - fprintf(file, "</pre>"); - fclose(file); -} - -static void -refresh_node(GntWidget *widget, GntNode *node, gpointer null) -{ - int x, y, w, h; - int nw, nh; - - gnt_widget_get_position(widget, &x, &y); - gnt_widget_get_size(widget, &w, &h); - - if (x + w >= X_MAX) - x = MAX(0, X_MAX - w); - if (y + h >= Y_MAX) - y = MAX(0, Y_MAX - h); - gnt_screen_move_widget(widget, x, y); - - nw = MIN(w, X_MAX); - nh = MIN(h, Y_MAX); - if (nw != w || nh != h) - gnt_screen_resize_widget(widget, nw, nh); -} - /** * Mouse support: * - bring a window on top if you click on its taskbar @@ -602,7 +75,7 @@ GntWidget *widget = NULL; PANEL *p = NULL; - if (!ordered || buffer[0] != 27) + if (!wm->ordered || buffer[0] != 27) return FALSE; buffer++; @@ -653,16 +126,13 @@ } else return FALSE; - if (wm.mouse_clicked && wm.mouse_clicked(event, x, y, widget)) + if (gnt_wm_process_click(wm, event, x, y, widget)) return TRUE; - if (event == GNT_LEFT_MOUSE_DOWN && widget && widget != _list.window && + if (event == GNT_LEFT_MOUSE_DOWN && widget && widget != wm->_list.window && !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_TRANSIENT)) { - if (widget != ordered->data) { - GntWidget *w = ordered->data; - ordered = g_list_bring_to_front(ordered, widget); - wm.give_focus(ordered->data); - gnt_widget_set_focus(w, FALSE); + if (widget != wm->ordered->data) { + gnt_wm_raise_window(wm, widget); } if (y == widget->priv.y) { offset = x - widget->priv.x; @@ -672,17 +142,16 @@ } else if (event == GNT_MOUSE_UP) { if (button == MOUSE_NONE && y == getmaxy(stdscr) - 1) { /* Clicked on the taskbar */ - int n = g_list_length(focus_list); + int n = g_list_length(wm->list); if (n) { int width = getmaxx(stdscr) / n; - switch_window_n(x / width); + gnt_bindable_perform_action_named(GNT_BINDABLE(wm), "switch-window-n", x/width, NULL); } } else if (button == MOUSE_LEFT && remember) { x -= offset; if (x < 0) x = 0; if (y < 0) y = 0; gnt_screen_move_widget(remember, x, y); - refresh_node(remember, NULL, NULL); } button = MOUSE_NONE; remember = NULL; @@ -690,87 +159,25 @@ } gnt_widget_clicked(widget, event, x, y); - return TRUE; /* XXX: this should be TRUE */ + return TRUE; } -#ifndef NO_WIDECHAR -static int -widestringwidth(wchar_t *wide) +static gboolean +io_invoke_error(GIOChannel *source, GIOCondition cond, gpointer data) { - int len, ret; - char *string; + int id = GPOINTER_TO_INT(data); + g_source_remove(id); + g_io_channel_unref(source); - len = wcstombs(NULL, wide, 0) + 1; - string = g_new0(char, len); - wcstombs(string, wide, len); - ret = gnt_util_onscreen_width(string, NULL); - g_free(string); - return ret; + channel = NULL; + setup_io(); + return TRUE; } -#endif -/* Returns the onscreen width of the character at the position */ -static int -reverse_char(WINDOW *d, int y, int x, gboolean set) -{ -#define DECIDE(ch) (set ? ((ch) | A_REVERSE) : ((ch) & ~A_REVERSE)) - -#ifdef NO_WIDECHAR - chtype ch; - ch = mvwinch(d, y, x); - mvwaddch(d, y, x, DECIDE(ch)); - return 1; -#else - cchar_t ch; - int wc = 1; - if (mvwin_wch(d, y, x, &ch) == OK) { - wc = widestringwidth(ch.chars); - ch.attr = DECIDE(ch.attr); - ch.attr &= WA_ATTRIBUTES; /* XXX: This is a workaround for a bug */ - mvwadd_wch(d, y, x, &ch); - } - - return wc; -#endif -} - -static void -window_reverse(GntWidget *win, gboolean set) -{ - int i; - int w, h; - WINDOW *d; - - if (GNT_WIDGET_IS_FLAG_SET(win, GNT_WIDGET_NO_BORDER)) - return; - - d = win->window; - gnt_widget_get_size(win, &w, &h); - - if (gnt_widget_has_shadow(win)) { - --w; - --h; - } - - /* the top and bottom */ - for (i = 0; i < w; i += reverse_char(d, 0, i, set)); - for (i = 0; i < w; i += reverse_char(d, h-1, i, set)); - - /* the left and right */ - for (i = 0; i < h; i += reverse_char(d, i, 0, set)); - for (i = 0; i < h; i += reverse_char(d, i, w-1, set)); - - wrefresh(win->window); -} - static gboolean io_invoke(GIOChannel *source, GIOCondition cond, gpointer null) { char keys[256]; - gboolean ret = FALSE; - static GntKeyPressMode mode = GNT_KP_MODE_NORMAL; - const char *buffer; - int rd = read(STDIN_FILENO, keys, sizeof(keys) - 1); if (rd < 0) { @@ -787,255 +194,48 @@ raise(SIGABRT); } - event_stack = TRUE; keys[rd] = 0; - - if (keys[0] == 27 && keys[1] == 'd' && keys[2] == 0) - { - /* This dumps the screen contents in an html file */ - dump_screen(); - } - gnt_keys_refine(keys); if (mouse_enabled && detect_mouse_action(keys)) return TRUE; - if (wm.key_pressed) { - buffer = wm.key_pressed(keys); - if (buffer == NULL) { - event_stack = FALSE; - return TRUE; - } - } else - buffer = keys; + gnt_wm_process_input(wm, keys); - if (mode == GNT_KP_MODE_NORMAL) - { - if (menu) { - ret = gnt_widget_key_pressed(GNT_WIDGET(menu), buffer); - } else if (ordered) { - ret = gnt_widget_key_pressed(ordered->data, buffer); - } + return TRUE; +} - if (!ret) - { - if (buffer[0] == 27) - { - /* Some special key has been pressed */ - if (strcmp(buffer, GNT_KEY_POPUP) == 0) - {} - else if (strcmp(buffer + 1, "c") == 0) - { - /* Alt + c was pressed. I am going to use it to close a window. */ - if (ordered) - { - gnt_widget_destroy(ordered->data); - } - } - else if (strcmp(buffer + 1, "q") == 0) - { - /* I am going to use Alt + q to quit. */ - g_main_loop_quit(loop); - } - else if (strcmp(buffer + 1, "n") == 0) - { - /* Alt + n to go to the next window */ - switch_window(1); - } - else if (strcmp(buffer + 1, "p") == 0) - { - /* Alt + p to go to the previous window */ - switch_window(-1); - } - else if (strcmp(buffer + 1, "m") == 0 && focus_list) - { - /* Move a window */ - mode = GNT_KP_MODE_MOVE; - window_reverse(ordered->data, TRUE); - } - else if (strcmp(buffer + 1, "w") == 0 && focus_list) - { - /* Window list */ - mode = GNT_KP_MODE_WINDOW_LIST; - show_window_list(); - } - else if (strcmp(buffer + 1, "a") == 0) - { - mode = GNT_KP_MODE_WINDOW_LIST; - show_actions_list(); - } - else if (strcmp(buffer + 1, "r") == 0 && focus_list) - { - /* Resize window */ - mode = GNT_KP_MODE_RESIZE; - window_reverse(ordered->data, TRUE); - } - else if (strcmp(buffer + 1, ",") == 0 && focus_list) - { - /* Re-order the list of windows */ - shift_window(ordered->data, -1); - } - else if (strcmp(buffer + 1, ".") == 0 && focus_list) - { - shift_window(ordered->data, 1); - } - else if (strcmp(buffer + 1, "l") == 0) - { - refresh_screen(); - } - else if (strlen(buffer) == 2 && isdigit(*(buffer + 1))) - { - int n = *(buffer + 1) - '0'; +static void +setup_io() +{ + int result; + channel = g_io_channel_unix_new(STDIN_FILENO); - if (n == 0) - n = 10; + g_io_channel_set_encoding(channel, NULL, NULL); + g_io_channel_set_buffered(channel, FALSE); +#if 0 + g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL ); +#endif - switch_window_n(n - 1); - } - } - } - } - else if (mode == GNT_KP_MODE_MOVE && focus_list) - { - if (buffer[0] == 27) - { - gboolean changed = FALSE; - int x, y, w, h; - GntWidget *widget = GNT_WIDGET(ordered->data); + result = g_io_add_watch_full(channel, G_PRIORITY_HIGH, + (G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI), + io_invoke, NULL, NULL); + + g_io_add_watch_full(channel, G_PRIORITY_HIGH, + (G_IO_NVAL), + io_invoke_error, GINT_TO_POINTER(result), NULL); + + g_io_channel_unref(channel); /* Apparently this caused crashes for some people. + But irssi does this, so I am going to assume the + crashes were caused by some other stuff. */ - gnt_widget_get_position(widget, &x, &y); - gnt_widget_get_size(widget, &w, &h); - - if (strcmp(buffer, GNT_KEY_LEFT) == 0) - { - if (x > X_MIN) - { - x--; - changed = TRUE; - } - } - else if (strcmp(buffer, GNT_KEY_RIGHT) == 0) - { - if (x + w < X_MAX) - { - x++; - changed = TRUE; - } - } - else if (strcmp(buffer, GNT_KEY_UP) == 0) - { - if (y > Y_MIN) - { - y--; - changed = TRUE; - } - } - else if (strcmp(buffer, GNT_KEY_DOWN) == 0) - { - if (y + h < Y_MAX) - { - y++; - changed = TRUE; - } - } - else if (buffer[1] == 0) - { - mode = GNT_KP_MODE_NORMAL; - window_reverse(widget, FALSE); - } - - if (changed) - { - gnt_screen_move_widget(widget, x, y); - } - } - else if (*buffer == '\r') - { - mode = GNT_KP_MODE_NORMAL; - window_reverse(ordered->data, FALSE); - } - } - else if (mode == GNT_KP_MODE_WINDOW_LIST && _list.window) - { - gnt_widget_key_pressed(_list.window, buffer); - - if (buffer[0] == '\r' || (buffer[0] == 27 && buffer[1] == 0)) - { - mode = GNT_KP_MODE_NORMAL; - lock_focus_list = 1; - gnt_widget_destroy(_list.window); - _list.window = NULL; - _list.tree = NULL; - lock_focus_list = 0; - window_list = NULL; - action_list = NULL; - } - } - else if (mode == GNT_KP_MODE_RESIZE) - { - if (buffer[0] == '\r' || (buffer[0] == 27 && buffer[1] == 0)) { - mode = GNT_KP_MODE_NORMAL; - window_reverse(ordered->data, FALSE); - } else if (buffer[0] == 27) { - GntWidget *widget = ordered->data; - gboolean changed = FALSE; - int width, height; - - gnt_widget_get_size(widget, &width, &height); - - if (strcmp(buffer, GNT_KEY_DOWN) == 0) - { - if (widget->priv.y + height < Y_MAX) - { - height++; - changed = TRUE; - } - } - else if (strcmp(buffer, GNT_KEY_UP) == 0) - { - height--; - changed = TRUE; - } - else if (strcmp(buffer, GNT_KEY_LEFT) == 0) - { - width--; - changed = TRUE; - } - else if (strcmp(buffer, GNT_KEY_RIGHT) == 0) - { - if (widget->priv.x + width < X_MAX) - { - width++; - changed = TRUE; - } - } - - if (changed) - { - gnt_screen_resize_widget(widget, width, height); - window_reverse(widget, TRUE); - } - } - } - - event_stack = FALSE; - return TRUE; + g_printerr("gntmain: setting up IO\n"); } static gboolean refresh_screen() { - endwin(); - refresh(); - - X_MAX = getmaxx(stdscr); - Y_MAX = getmaxy(stdscr) - 1; - - g_hash_table_foreach(nodes, (GHFunc)refresh_node, NULL); - update_screen(NULL); - draw_taskbar(TRUE); - + gnt_bindable_perform_action_named(GNT_BINDABLE(wm), "refresh-screen", NULL); return FALSE; } @@ -1082,44 +282,29 @@ const char *name = gnt_style_get(GNT_STYLE_WM); gpointer handle; - if (!name || !*name) - return; - - handle = g_module_open(name, G_MODULE_BIND_LAZY); - if (handle) { - gboolean (*init)(GntWM *); - if (g_module_symbol(handle, "gntwm_init", (gpointer)&init)) { - init(&wm); + if (name && *name) { + handle = g_module_open(name, G_MODULE_BIND_LAZY); + if (handle) { + gboolean (*init)(GntWM **); + if (g_module_symbol(handle, "gntwm_init", (gpointer)&init)) { + init(&wm); + } } } + if (wm == NULL) + wm = g_object_new(GNT_TYPE_WM, NULL); } void gnt_init() { - static GIOChannel *channel = NULL; char *filename; - int result; const char *locale; if (channel) return; - channel = g_io_channel_unix_new(STDIN_FILENO); + setup_io(); - g_io_channel_set_encoding(channel, NULL, NULL); - g_io_channel_set_buffered(channel, FALSE); -#if 0 - g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL ); -#endif - - result = g_io_add_watch_full(channel, G_PRIORITY_HIGH, - (G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI | G_IO_NVAL), - io_invoke, NULL, NULL); - - g_io_channel_unref(channel); /* Apparently this caused crashes for some people. - But irssi does this, so I am going to assume the - crashes were caused by some other stuff. */ - locale = setlocale(LC_ALL, ""); if (locale && (strstr(locale, "UTF") || strstr(locale, "utf"))) @@ -1139,13 +324,7 @@ g_free(filename); gnt_init_colors(); - X_MIN = 0; - Y_MIN = 0; - X_MAX = getmaxx(stdscr); - Y_MAX = getmaxy(stdscr) - 1; - nodes = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_node); - wbkgdset(stdscr, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); refresh(); @@ -1171,112 +350,27 @@ void gnt_main() { - loop = g_main_loop_new(NULL, FALSE); - g_main_loop_run(loop); + wm->loop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(wm->loop); } /********************************* * Stuff for 'window management' * *********************************/ -static void -free_node(gpointer data) -{ - GntNode *node = data; - hide_panel(node->panel); - del_panel(node->panel); - g_free(node); -} - void gnt_screen_occupy(GntWidget *widget) { - GntNode *node; - - while (widget->parent) - widget = widget->parent; - - if (g_hash_table_lookup(nodes, widget)) - return; /* XXX: perhaps _update instead? */ - - node = g_new0(GntNode, 1); - node->me = widget; - - g_hash_table_replace(nodes, widget, node); - - refresh_node(widget, node, NULL); - - if (window_list) - { - if ((GNT_IS_BOX(widget) && GNT_BOX(widget)->title) && window_list->window != widget - && GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_CAN_TAKE_FOCUS)) - { - gnt_tree_add_row_last(GNT_TREE(window_list->tree), widget, - gnt_tree_create_row(GNT_TREE(window_list->tree), GNT_BOX(widget)->title), - NULL); - update_window_in_list(widget); - } - } - - update_screen(NULL); + gnt_wm_new_window(wm, widget); } void gnt_screen_release(GntWidget *widget) { - GntNode *node; - - gnt_screen_remove_widget(widget); - node = g_hash_table_lookup(nodes, widget); - - if (node == NULL) /* Yay! Nothing to do. */ - return; - - if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_DESTROYING) && wm.close_window) - wm.close_window(widget); - - g_hash_table_remove(nodes, widget); - - if (window_list) - { - gnt_tree_remove(GNT_TREE(window_list->tree), widget); - } - - update_screen(NULL); + gnt_wm_window_close(wm, widget); } void gnt_screen_update(GntWidget *widget) { - GntNode *node; - - while (widget->parent) - widget = widget->parent; - if (!GNT_IS_MENU(widget)) - gnt_box_sync_children(GNT_BOX(widget)); - node = g_hash_table_lookup(nodes, widget); - if (node && !node->panel) - { - if (wm.new_window && node->me != _list.window) - node->panel = wm.new_window(node->me); - else - node->panel = new_panel(node->me->window); - set_panel_userptr(node->panel, node); - if (!GNT_WIDGET_IS_FLAG_SET(node->me, GNT_WIDGET_TRANSIENT)) { - if (!g_object_get_data(G_OBJECT(node->me), "give_focus")) { - bottom_panel(node->panel); /* New windows should not grab focus */ - gnt_widget_set_urgent(node->me); - } - else { - bring_on_top(node->me); - } - } - } - - if (_list.window) - { - GntNode *nd = g_hash_table_lookup(nodes, _list.window); - top_panel(nd->panel); - } - - update_screen(NULL); + gnt_wm_update_window(wm, widget); } gboolean gnt_widget_has_focus(GntWidget *widget) @@ -1293,16 +387,13 @@ while (widget->parent) widget = widget->parent; - if (widget == _list.window) + if (widget == wm->_list.window) return TRUE; - - if (ordered && ordered->data == widget) - { + if (wm->ordered && wm->ordered->data == widget) { if (GNT_IS_BOX(widget) && (GNT_BOX(widget)->active == w || widget == w)) return TRUE; } - return FALSE; } @@ -1311,21 +402,19 @@ while (widget->parent) widget = widget->parent; - if (ordered && ordered->data == widget) + if (wm->ordered && wm->ordered->data == widget) return; GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_URGENT); - if (wm.window_update) { - GntNode *node = g_hash_table_lookup(nodes, widget); - wm.window_update(node ? node->panel : NULL, widget); - } - - draw_taskbar(FALSE); + gnt_wm_update_window(wm, widget); } void gnt_quit() { + g_hash_table_destroy(wm->nodes); /* XXX: */ + update_panels(); + doupdate(); gnt_uninit_colors(); gnt_uninit_styles(); endwin(); @@ -1338,145 +427,48 @@ void gnt_screen_resize_widget(GntWidget *widget, int width, int height) { - if (widget->parent == NULL) - { - GntNode *node = g_hash_table_lookup(nodes, widget); - if (!node) - return; - - if (wm.window_resize_confirm && !wm.window_resize_confirm(widget, &width, &height)) - return; - - hide_panel(node->panel); - gnt_widget_set_size(widget, width, height); - gnt_widget_draw(widget); - if (wm.window_resized) - node->panel = wm.window_resized(node->panel, widget); - else - replace_panel(node->panel, widget->window); - show_panel(node->panel); - update_screen(NULL); - } + gnt_wm_resize_window(wm, widget, width, height); } void gnt_screen_move_widget(GntWidget *widget, int x, int y) { - GntNode *node = g_hash_table_lookup(nodes, widget); - - if (wm.window_move_confirm && !wm.window_move_confirm(widget, &x, &y)) - return; - - gnt_widget_set_position(widget, x, y); - move_panel(node->panel, y, x); - - if (wm.window_moved) - wm.window_moved(node->panel, widget); - - update_screen(NULL); + gnt_wm_move_window(wm, widget, x, y); } void gnt_screen_rename_widget(GntWidget *widget, const char *text) { gnt_box_set_title(GNT_BOX(widget), text); gnt_widget_draw(widget); - - if (wm.window_update) { - GntNode *node = g_hash_table_lookup(nodes, widget); - wm.window_update(node ? node->panel : NULL, widget); - } - - draw_taskbar(FALSE); + gnt_wm_update_window(wm, widget); } -/** - * An application can register actions which will show up in a 'start-menu' like popup - */ -typedef struct _GnAction -{ - const char *label; - void (*callback)(); -} GntAction; - -static GList *actions; - void gnt_register_action(const char *label, void (*callback)()) { GntAction *action = g_new0(GntAction, 1); action->label = g_strdup(label); action->callback = callback; - actions = g_list_append(actions, action); + wm->acts = g_list_append(wm->acts, action); } static void -action_list_activate(GntTree *tree, gpointer null) -{ - GntAction *action = gnt_tree_get_selection_data(tree); - action->callback(); -} - -static int -compare_action(gconstpointer p1, gconstpointer p2) -{ - const GntAction *a1 = p1; - const GntAction *a2 = p2; - - return g_utf8_collate(a1->label, a2->label); -} - -static void -show_actions_list() -{ - GntWidget *tree, *win; - GList *iter; - int h; - - if (action_list) - return; - - setup__list(); - action_list = &_list; - win = action_list->window; - tree = action_list->tree; - - gnt_box_set_title(GNT_BOX(win), "Actions"); - GNT_WIDGET_SET_FLAGS(tree, GNT_WIDGET_NO_BORDER); - /* XXX: Do we really want this? */ - gnt_tree_set_compare_func(GNT_TREE(tree), compare_action); - - for (iter = actions; iter; iter = iter->next) { - GntAction *action = iter->data; - gnt_tree_add_row_last(GNT_TREE(tree), action, - gnt_tree_create_row(GNT_TREE(tree), action->label), NULL); - } - g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(action_list_activate), NULL); - gnt_widget_set_size(tree, 0, g_list_length(actions)); - gnt_widget_get_size(win, NULL, &h); - gnt_widget_set_position(win, 0, getmaxy(stdscr) - 1 - h); - - lock_focus_list = 1; - gnt_widget_show(win); - lock_focus_list = 0; -} - -static void reset_menu(GntWidget *widget, gpointer null) { - menu = NULL; + wm->menu = NULL; } gboolean gnt_screen_menu_show(gpointer newmenu) { - if (menu) { + if (wm->menu) { /* For now, if a menu is being displayed, then another menu * can NOT take over. */ return FALSE; } - menu = newmenu; - gnt_widget_draw(GNT_WIDGET(menu)); + wm->menu = newmenu; + gnt_widget_draw(GNT_WIDGET(wm->menu)); - g_signal_connect(G_OBJECT(menu), "hide", G_CALLBACK(reset_menu), NULL); + g_signal_connect(G_OBJECT(wm->menu), "hide", G_CALLBACK(reset_menu), NULL); return TRUE; } Modified: trunk/console/libgnt/gntmarshal.c =================================================================== --- trunk/console/libgnt/gntmarshal.c 2006-11-05 14:57:05 UTC (rev 17671) +++ trunk/console/libgnt/gntmarshal.c 2006-11-05 17:28:33 UTC (rev 17672) @@ -1,237 +1,427 @@ -#include "gntmarshal.h" -void gnt_closure_marshal_BOOLEAN__VOID(GClosure *closure, - GValue *ret_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data) +#include <glib-object.h> + + +#ifdef G_ENABLE_DEBUG +#define g_marshal_value_peek_boolean(v) g_value_get_boolean (v) +#define g_marshal_value_peek_char(v) g_value_get_char (v) +#define g_marshal_value_peek_uchar(v) g_value_get_uchar (v) +#define g_marshal_value_peek_int(v) g_value_get_int (v) +#define g_marshal_value_peek_uint(v) g_value_get_uint (v) +#define g_marshal_value_peek_long(v) g_value_get_long (v) +#define g_marshal_value_peek_ulong(v) g_value_get_ulong (v) +#define g_marshal_value_peek_int64(v) g_value_get_int64 (v) +#define g_marshal_value_peek_uint64(v) g_value_get_uint64 (v) +#define g_marshal_value_peek_enum(v) g_value_get_enum (v) +#define g_marshal_value_peek_flags(v) g_value_get_flags (v) +#define g_marshal_value_peek_float(v) g_value_get_float (v) +#define g_marshal_value_peek_double(v) g_value_get_double (v) +#define g_marshal_value_peek_string(v) (char*) g_value_get_string (v) +#define g_marshal_value_peek_param(v) g_value_get_param (v) +#define g_marshal_value_peek_boxed(v) g_value_get_boxed (v) +#define g_marshal_value_peek_pointer(v) g_value_get_pointer (v) +#define g_marshal_value_peek_object(v) g_value_get_object (v) +#else /* !G_ENABLE_DEBUG */ +/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API. + * Do not access GValues directly in your code. Instead, use the + * g_value_get_*() functions + */ +#define g_marshal_value_peek_boolean(v) (v)->data[0].v_int +#define g_marshal_value_peek_char(v) (v)->data[0].v_int +#define g_marshal_value_peek_uchar(v) (v)->data[0].v_uint +#define g_marshal_value_peek_int(v) (v)->data[0].v_int +#define g_marshal_value_peek_uint(v) (v)->data[0].v_uint +#define g_marshal_value_peek_long(v) (v)->data[0].v_long +#define g_marshal_value_peek_ulong(v) (v)->data[0].v_ulong +#define g_marshal_value_peek_int64(v) (v)->data[0].v_int64 +#define g_marshal_value_peek_uint64(v) (v)->data[0].v_uint64 +#define g_marshal_value_peek_enum(v) (v)->data[0].v_long +#define g_marshal_value_peek_flags(v) (v)->data[0].v_ulong +#define g_marshal_value_peek_float(v) (v)->data[0].v_float +#define g_marshal_value_peek_double(v) (v)->data[0].v_double +#define g_marshal_value_peek_string(v) (v)->data[0].v_pointer +#define g_marshal_value_peek_param(v) (v)->data[0].v_pointer +#define g_marshal_value_peek_boxed(v) (v)->data[0].v_pointer +#define g_marshal_value_peek_pointer(v) (v)->data[0].v_pointer +#define g_marshal_value_peek_object(v) (v)->data[0].v_pointer +#endif /* !G_ENABLE_DEBUG */ + + +/* BOOLEAN:VOID (/dev/stdin:1) */ +void +gnt_closure_marshal_BOOLEAN__VOID (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data) { - typedef gboolean (*func) (gpointer data1, gpointer data2); - register func callback; - register GCClosure *cc = (GCClosure*)closure; - register gpointer data1, data2; - gboolean ret; + typedef gboolean (*GMarshalFunc_BOOLEAN__VOID) (gpointer data1, + gpointer data2); + register GMarshalFunc_BOOLEAN__VOID callback; + register GCClosure *cc = (GCClosure*) closure; + register gpointer data1, data2; + gboolean v_return; - g_return_if_fail(ret_value != NULL); - g_return_if_fail(n_param_values == 1); + g_return_if_fail (return_value != NULL); + g_return_if_fail (n_param_values == 1); - if (G_CCLOSURE_SWAP_DATA(closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer(param_values + 0); - } - else - { - data1 = g_value_peek_pointer(param_values + 0); - data2 = closure->data; - } + if (G_CCLOSURE_SWAP_DATA (closure)) + { + data1 = closure->data; + data2 = g_value_peek_pointer (param_values + 0); + } + else + { + data1 = g_value_peek_pointer (param_values + 0); + data2 = closure->data; + } + callback = (GMarshalFunc_BOOLEAN__VOID) (marshal_data ? marshal_data : cc->callback); - callback = (func) (marshal_data ? marshal_data : cc->callback); - ret = callback(data1, data2); - g_value_set_boolean(ret_value, ret); + v_return = callback (data1, + data2); + + g_value_set_boolean (return_value, v_return); } -void gnt_closure_marshal_BOOLEAN__STRING(GClosure *closure, - GValue *ret_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data) +/* BOOLEAN:STRING (/dev/stdin:2) */ +void +gnt_closure_marshal_BOOLEAN__STRING (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data) { - typedef gboolean (*func) (gpointer data1, const char *arg1, gpointer data2); - register func callback; - register GCClosure *cc = (GCClosure*)closure; - register gpointer data1, data2; - gboolean ret; + typedef gboolean (*GMarshalFunc_BOOLEAN__STRING) (gpointer data1, + gpointer arg_1, + gpointer data2); + register GMarshalFunc_BOOLEAN__STRING callback; + register GCClosure *cc = (GCClosure*) closure; + register gpointer data1, data2; + gboolean v_return; - g_return_if_fail(ret_value != NULL); - g_return_if_fail(n_param_values == 2); + g_return_if_fail (return_value != NULL); + g_return_if_fail (n_param_values == 2); - if (G_CCLOSURE_SWAP_DATA(closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer(param_values + 0); - } - else - { - data1 = g_value_peek_pointer(param_values + 0); - data2 = closure->data; - } + if (G_CCLOSURE_SWAP_DATA (closure)) + { + data1 = closure->data; + data2 = g_value_peek_pointer (param_values + 0); + } + else + { + data1 = g_value_peek_pointer (param_values + 0); + data2 = closure->data; + } + callback = (GMarshalFunc_BOOLEAN__STRING) (marshal_data ? marshal_data : cc->callback); - callback = (func) (marshal_data ? marshal_data : cc->callback); - ret = callback(data1, g_value_get_string(param_values + 1) , data2); - g_value_set_boolean(ret_value, ret); + v_return = callback (data1, + g_marshal_value_peek_string (param_values + 1), + data2); + + g_value_set_boolean (return_value, v_return); } -void gnt_closure_marshal_VOID__INT_INT_INT_INT(GClosure *closure, - GValue *ret_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data) +/* VOID:INT,INT,INT,INT (/dev/stdin:3) */ +void +gnt_clo... [truncated message content] |
From: <sa...@us...> - 2006-11-06 01:20:11
|
Revision: 17678 http://svn.sourceforge.net/gaim/?rev=17678&view=rev Author: sadrul Date: 2006-11-05 17:11:19 -0800 (Sun, 05 Nov 2006) Log Message: ----------- Make sure the menus show up correctly. Modified Paths: -------------- trunk/console/libgnt/gntmain.c trunk/console/libgnt/gntmenu.c Modified: trunk/console/libgnt/gntmain.c =================================================================== --- trunk/console/libgnt/gntmain.c 2006-11-06 00:14:30 UTC (rev 17677) +++ trunk/console/libgnt/gntmain.c 2006-11-06 01:11:19 UTC (rev 17678) @@ -466,6 +466,7 @@ } wm->menu = newmenu; + GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(wm->menu), GNT_WIDGET_INVISIBLE); gnt_widget_draw(GNT_WIDGET(wm->menu)); g_signal_connect(G_OBJECT(wm->menu), "hide", G_CALLBACK(reset_menu), NULL); Modified: trunk/console/libgnt/gntmenu.c =================================================================== --- trunk/console/libgnt/gntmenu.c 2006-11-06 00:14:30 UTC (rev 17677) +++ trunk/console/libgnt/gntmenu.c 2006-11-06 01:11:19 UTC (rev 17678) @@ -115,6 +115,7 @@ item->priv.y = widget->priv.y + gnt_tree_get_selection_visible_line(GNT_TREE(menu)); } gnt_widget_set_position(GNT_WIDGET(sub), item->priv.x, item->priv.y); + GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(sub), GNT_WIDGET_INVISIBLE); gnt_widget_draw(GNT_WIDGET(sub)); } else if (item->callback) { item->callback(item, item->callbackdata); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-11-15 20:39:54
|
Revision: 17755 http://svn.sourceforge.net/gaim/?rev=17755&view=rev Author: sadrul Date: 2006-11-15 12:39:32 -0800 (Wed, 15 Nov 2006) Log Message: ----------- Decide the values for ctrl-up/down at startup depending on $TERM. Modified Paths: -------------- trunk/console/libgnt/gntbindable.c trunk/console/libgnt/gntentry.c trunk/console/libgnt/gntkeys.c trunk/console/libgnt/gntkeys.h trunk/console/libgnt/gntmain.c Modified: trunk/console/libgnt/gntbindable.c =================================================================== --- trunk/console/libgnt/gntbindable.c 2006-11-15 20:11:01 UTC (rev 17754) +++ trunk/console/libgnt/gntbindable.c 2006-11-15 20:39:32 UTC (rev 17755) @@ -185,7 +185,7 @@ g_hash_table_replace(klass->actions, g_strdup(name), action); - if (trigger) { + if (trigger && *trigger) { list = NULL; va_start(args, trigger); while ((data = va_arg(args, void *))) { Modified: trunk/console/libgnt/gntentry.c =================================================================== --- trunk/console/libgnt/gntentry.c 2006-11-15 20:11:01 UTC (rev 17754) +++ trunk/console/libgnt/gntentry.c 2006-11-15 20:39:32 UTC (rev 17755) @@ -585,9 +585,9 @@ gnt_bindable_class_register_action(bindable, "suggest-prev", suggest_prev, GNT_KEY_UP, NULL); gnt_bindable_class_register_action(bindable, "history-prev", history_prev, - "\033" GNT_KEY_CTRL_DOWN, NULL); + GNT_KEY_CTRL_DOWN, NULL); gnt_bindable_class_register_action(bindable, "history-next", history_next, - "\033" GNT_KEY_CTRL_UP, NULL); + GNT_KEY_CTRL_UP, NULL); gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass)); GNTDEBUG; Modified: trunk/console/libgnt/gntkeys.c =================================================================== --- trunk/console/libgnt/gntkeys.c 2006-11-15 20:11:01 UTC (rev 17754) +++ trunk/console/libgnt/gntkeys.c 2006-11-15 20:39:32 UTC (rev 17755) @@ -5,7 +5,7 @@ static const char *term; -void gnt_keys_refine(char *text) +void gnt_init_keys() { if (term == NULL) { term = getenv("TERM"); @@ -13,6 +13,21 @@ term = ""; /* Just in case */ } + if (strcmp(term, "xterm") == 0 || strcmp(term, "rxvt") == 0) { + gnt_key_cup = "\033" "[1;5A"; + gnt_key_cdown = "\033" "[1;5B"; + gnt_key_cright = "\033" "[1;5C"; + gnt_key_cleft = "\033" "[1;5D"; + } else if (strcmp(term, "screen") == 0 || strcmp(term, "rxvt-unicode") == 0) { + gnt_key_cup = "\033" "Oa"; + gnt_key_cdown = "\033" "Ob"; + gnt_key_cright = "\033" "Oc"; + gnt_key_cleft = "\033" "Od"; + } +} + +void gnt_keys_refine(char *text) +{ if (*text == 27 && *(text + 1) == '[' && *(text + 3) == '\0' && (*(text + 2) >= 'A' && *(text + 2) <= 'D')) { /* Apparently this is necessary for urxvt and screen and xterm */ Modified: trunk/console/libgnt/gntkeys.h =================================================================== --- trunk/console/libgnt/gntkeys.h 2006-11-15 20:11:01 UTC (rev 17754) +++ trunk/console/libgnt/gntkeys.h 2006-11-15 20:39:32 UTC (rev 17755) @@ -4,6 +4,16 @@ #include <curses.h> #include <term.h> +/** + * terminfo/termcap doesn't provide all the information that I want to use, eg. + * ctrl-up, ctrl-down etc. So I am going to hard-code some of the information + * for some popular $TERMs + */ +char *gnt_key_cup; +char *gnt_key_cdown; +char *gnt_key_cleft; +char *gnt_key_cright; + #define SAFE(x) ((x) ? (x) : "") #define GNT_KEY_POPUP SAFE(key_f16) /* Apparently */ @@ -14,10 +24,10 @@ #define GNT_KEY_UP SAFE(key_up) #define GNT_KEY_DOWN SAFE(key_down) -#define GNT_KEY_CTRL_UP "[1;5A" -#define GNT_KEY_CTRL_DOWN "[1;5B" -#define GNT_KEY_CTRL_RIGHT "[1;5C" -#define GNT_KEY_CTRL_LEFT "[1;5D" +#define GNT_KEY_CTRL_UP SAFE(gnt_key_cup) +#define GNT_KEY_CTRL_DOWN SAFE(gnt_key_cdown) +#define GNT_KEY_CTRL_RIGHT SAFE(gnt_key_cright) +#define GNT_KEY_CTRL_LEFT SAFE(gnt_key_cleft) #define GNT_KEY_PGUP SAFE(key_ppage) #define GNT_KEY_PGDOWN SAFE(key_npage) @@ -69,6 +79,7 @@ /** * This will do stuff with the terminal settings and stuff. */ +void gnt_init_keys(); void gnt_keys_refine(char *text); Modified: trunk/console/libgnt/gntmain.c =================================================================== --- trunk/console/libgnt/gntmain.c 2006-11-15 20:11:01 UTC (rev 17754) +++ trunk/console/libgnt/gntmain.c 2006-11-15 20:39:32 UTC (rev 17755) @@ -324,6 +324,7 @@ g_free(filename); gnt_init_colors(); + gnt_init_keys(); wbkgdset(stdscr, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); refresh(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-11-20 04:05:34
|
Revision: 17789 http://svn.sourceforge.net/gaim/?rev=17789&view=rev Author: sadrul Date: 2006-11-19 20:05:33 -0800 (Sun, 19 Nov 2006) Log Message: ----------- F10 to show the menu of a window. F11 to show the context-menu. I would've used shift+F10 if terminfo permitted. Fix a bug where F10 etc. could not be used for rebinding. Modified Paths: -------------- trunk/console/libgnt/gntstyle.c trunk/console/libgnt/gntwidget.c trunk/console/libgnt/gntwindow.c Modified: trunk/console/libgnt/gntstyle.c =================================================================== --- trunk/console/libgnt/gntstyle.c 2006-11-20 03:57:47 UTC (rev 17788) +++ trunk/console/libgnt/gntstyle.c 2006-11-20 04:05:33 UTC (rev 17789) @@ -91,7 +91,7 @@ /* XXX: Need to do something about ctrl/alt+home, end etc. */ #define SPECIAL_KEY(k, code) do { \ - if (strncasecmp(key, k, sizeof(k) - 1) == 0) \ + if (strcasecmp(key, k) == 0) \ return g_strdup(code); \ } while (0) Modified: trunk/console/libgnt/gntwidget.c =================================================================== --- trunk/console/libgnt/gntwidget.c 2006-11-20 03:57:47 UTC (rev 17788) +++ trunk/console/libgnt/gntwidget.c 2006-11-20 04:05:33 UTC (rev 17789) @@ -239,6 +239,7 @@ /* This is relevant for all widgets */ gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "context-menu", context_menu, GNT_KEY_POPUP, NULL); + gnt_bindable_register_binding(GNT_BINDABLE_CLASS(klass), "context-menu", GNT_KEY_F11, NULL); gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass)); GNTDEBUG; Modified: trunk/console/libgnt/gntwindow.c =================================================================== --- trunk/console/libgnt/gntwindow.c 2006-11-20 03:57:47 UTC (rev 17788) +++ trunk/console/libgnt/gntwindow.c 2006-11-20 04:05:33 UTC (rev 17789) @@ -43,6 +43,7 @@ gnt_bindable_class_register_action(bindable, "show-menu", show_menu, GNT_KEY_CTRL_O, NULL); + gnt_bindable_register_binding(bindable, "show-menu", GNT_KEY_F10, NULL); gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), bindable); GNTDEBUG; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tal...@us...> - 2006-11-23 15:22:56
|
Revision: 17816 http://svn.sourceforge.net/gaim/?rev=17816&view=rev Author: taliesein Date: 2006-11-23 07:22:53 -0800 (Thu, 23 Nov 2006) Log Message: ----------- This fixes gnt builds for me (avoiding multiple-definition errors when linking) by marking some declarations as extern in the gntkeys.h and actually defining them in gntkeys.c Modified Paths: -------------- trunk/console/libgnt/gntkeys.c trunk/console/libgnt/gntkeys.h Modified: trunk/console/libgnt/gntkeys.c =================================================================== --- trunk/console/libgnt/gntkeys.c 2006-11-23 08:37:07 UTC (rev 17815) +++ trunk/console/libgnt/gntkeys.c 2006-11-23 15:22:53 UTC (rev 17816) @@ -3,6 +3,12 @@ #include <stdlib.h> #include <string.h> +char *gnt_key_cup; +char *gnt_key_cdown; +char *gnt_key_cleft; +char *gnt_key_cright; + + static const char *term; void gnt_init_keys() Modified: trunk/console/libgnt/gntkeys.h =================================================================== --- trunk/console/libgnt/gntkeys.h 2006-11-23 08:37:07 UTC (rev 17815) +++ trunk/console/libgnt/gntkeys.h 2006-11-23 15:22:53 UTC (rev 17816) @@ -9,10 +9,10 @@ * ctrl-up, ctrl-down etc. So I am going to hard-code some of the information * for some popular $TERMs */ -char *gnt_key_cup; -char *gnt_key_cdown; -char *gnt_key_cleft; -char *gnt_key_cright; +extern char *gnt_key_cup; +extern char *gnt_key_cdown; +extern char *gnt_key_cleft; +extern char *gnt_key_cright; #define SAFE(x) ((x) ? (x) : "") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-11-30 05:52:21
|
Revision: 17851 http://svn.sourceforge.net/gaim/?rev=17851&view=rev Author: sadrul Date: 2006-11-29 21:52:21 -0800 (Wed, 29 Nov 2006) Log Message: ----------- Remember the positions of the windows depending on the titles. Moving all the chat windows to places was getting really really annoying. If you don't want it, turn it off by setting "remember_position" to 0 in .gntrc Modified Paths: -------------- trunk/console/libgnt/gntstyle.c trunk/console/libgnt/gntstyle.h trunk/console/libgnt/gntwm.c trunk/console/libgnt/gntwm.h trunk/console/libgnt/wms/s.c Modified: trunk/console/libgnt/gntstyle.c =================================================================== --- trunk/console/libgnt/gntstyle.c 2006-11-30 02:01:49 UTC (rev 17850) +++ trunk/console/libgnt/gntstyle.c 2006-11-30 05:52:21 UTC (rev 17851) @@ -282,6 +282,7 @@ {"customcolor", GNT_STYLE_COLOR}, {"mouse", GNT_STYLE_MOUSE}, {"wm", GNT_STYLE_WM}, + {"remember_position", GNT_STYLE_REMPOS}, {NULL, 0}}; if (error) Modified: trunk/console/libgnt/gntstyle.h =================================================================== --- trunk/console/libgnt/gntstyle.h 2006-11-30 02:01:49 UTC (rev 17850) +++ trunk/console/libgnt/gntstyle.h 2006-11-30 05:52:21 UTC (rev 17851) @@ -6,6 +6,7 @@ GNT_STYLE_COLOR = 1, GNT_STYLE_MOUSE = 2, GNT_STYLE_WM = 3, + GNT_STYLE_REMPOS = 4, GNT_STYLES } GntStyle; Modified: trunk/console/libgnt/gntwm.c =================================================================== --- trunk/console/libgnt/gntwm.c 2006-11-30 02:01:49 UTC (rev 17850) +++ trunk/console/libgnt/gntwm.c 2006-11-30 05:52:21 UTC (rev 17851) @@ -42,6 +42,9 @@ static void gnt_wm_give_focus(GntWM *wm, GntWidget *widget); static void update_window_in_list(GntWM *wm, GntWidget *wid); +static gboolean write_already(gpointer data); +static int write_timeout; + static GList * g_list_bring_to_front(GList *list, gpointer data) { @@ -124,32 +127,106 @@ doupdate(); return TRUE; } + +static gboolean +sanitize_position(GntWidget *widget, int *x, int *y) +{ + int X_MAX = getmaxx(stdscr); + int Y_MAX = getmaxy(stdscr) - 1; + int w, h; + int nx, ny; + gboolean changed = FALSE; + + gnt_widget_get_size(widget, &w, &h); + if (x) { + if (*x + w > X_MAX) { + nx = MAX(0, X_MAX - w); + if (nx != *x) { + *x = nx; + changed = TRUE; + } + } + } + if (y) { + if (*y + h > Y_MAX) { + ny = MAX(0, Y_MAX - h); + if (ny != *y) { + *y = ny; + changed = TRUE; + } + } + } + return changed; +} + static void refresh_node(GntWidget *widget, GntNode *node, gpointer null) { int x, y, w, h; - int nw, nh, nx, ny; + int nw, nh; int X_MAX = getmaxx(stdscr); int Y_MAX = getmaxy(stdscr) - 1; gnt_widget_get_position(widget, &x, &y); gnt_widget_get_size(widget, &w, &h); - nx = x; ny = y; - if (x + w >= X_MAX) - nx = MAX(0, X_MAX - w); - if (y + h >= Y_MAX) - ny = MAX(0, Y_MAX - h); - if (x != nx || y != ny) - gnt_screen_move_widget(widget, nx, ny); + if (sanitize_position(widget, &x, &y)) + gnt_screen_move_widget(widget, x, y); nw = MIN(w, X_MAX); nh = MIN(h, Y_MAX); if (nw != w || nh != h) gnt_screen_resize_widget(widget, nw, nh); } + static void +read_window_positions(GntWM *wm) +{ +#if GLIB_CHECK_VERSION(2,6,0) + GKeyFile *gfile = g_key_file_new(); + char *filename = g_build_filename(g_get_home_dir(), ".gntpositions", NULL); + GError *error = NULL; + char **keys; + int nk; + + if (!g_key_file_load_from_file(gfile, filename, G_KEY_FILE_NONE, &error)) { + g_printerr("GntWM: %s\n", error->message); + g_error_free(error); + g_free(filename); + return; + } + + keys = g_key_file_get_keys(gfile, "positions", &nk, &error); + if (error) { + g_printerr("GntWM: %s\n", error->message); + g_error_free(error); + error = NULL; + } else { + while (nk--) { + char *title = keys[nk]; + int l; + char **coords = g_key_file_get_string_list(gfile, "positions", title, &l, NULL); + if (l == 2) { + int x = atoi(coords[0]); + int y = atoi(coords[1]); + GntPosition *p = g_new0(GntPosition, 1); + p->x = x; + p->y = y; + g_hash_table_replace(wm->positions, g_strdup(title + 1), p); + } else { + g_printerr("GntWM: Invalid number of arguments for positioing a window.\n"); + } + g_strfreev(coords); + } + g_strfreev(keys); + } + + g_free(filename); +#endif +} + +static void gnt_wm_init(GTypeInstance *instance, gpointer class) { GntWM *wm = GNT_WM(instance); @@ -159,6 +236,9 @@ wm->windows = NULL; wm->actions = NULL; wm->nodes = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_node); + wm->positions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + if (gnt_style_get_bool(GNT_STYLE_REMPOS, TRUE)) + read_window_positions(wm); } static void @@ -645,6 +725,8 @@ wm_quit(GntBindable *bindable, GList *list) { GntWM *wm = GNT_WM(bindable); + if (write_timeout) + write_already(wm); g_main_loop_quit(wm->loop); return TRUE; } @@ -905,6 +987,16 @@ return; } + if (GNT_IS_BOX(widget)) { + const char *title = GNT_BOX(widget)->title; + GntPosition *p = NULL; + if (title && (p = g_hash_table_lookup(wm->positions, title)) != NULL) { + sanitize_position(widget, &p->x, &p->y); + gnt_widget_set_position(widget, p->x, p->y); + mvwin(widget->window, p->y, p->x); + } + } + g_signal_emit(wm, signals[SIG_NEW_WIN], 0, widget); g_signal_emit(wm, signals[SIG_DECORATE_WIN], 0, widget); @@ -1088,6 +1180,46 @@ update_screen(wm); } +static void +write_gdi(gpointer key, gpointer value, gpointer data) +{ + GntPosition *p = value; + fprintf(data, ".%s = %d;%d\n", key, p->x, p->y); +} + +static gboolean +write_already(gpointer data) +{ + GntWM *wm = data; + FILE *file; + char *filename; + + filename = g_build_filename(g_get_home_dir(), ".gntpositions", NULL); + + file = fopen(filename, "wb"); + if (file == NULL) { + g_printerr("GntWM: error opening file to save positions\n"); + } else { + fprintf(file, "[positions]\n"); + g_hash_table_foreach(wm->positions, write_gdi, file); + fclose(file); + } + + g_free(filename); + g_source_remove(write_timeout); + write_timeout = 0; + return FALSE; +} + +static void +write_positions_to_file(GntWM *wm) +{ + if (write_timeout) { + g_source_remove(write_timeout); + } + write_timeout = g_timeout_add(10000, write_already, wm); +} + void gnt_wm_move_window(GntWM *wm, GntWidget *widget, int x, int y) { gboolean ret = TRUE; @@ -1107,6 +1239,17 @@ move_panel(node->panel, y, x); g_signal_emit(wm, signals[SIG_MOVED], 0, node); + if (gnt_style_get_bool(GNT_STYLE_REMPOS, TRUE) && GNT_IS_BOX(widget)) { + const char *title = GNT_BOX(widget)->title; + if (title) { + GntPosition *p = g_new0(GntPosition, 1); + GntWidget *wid = node->me; + p->x = wid->priv.x; + p->y = wid->priv.y; + g_hash_table_replace(wm->positions, g_strdup(title), p); + write_positions_to_file(wm); + } + } update_screen(wm); } Modified: trunk/console/libgnt/gntwm.h =================================================================== --- trunk/console/libgnt/gntwm.h 2006-11-30 02:01:49 UTC (rev 17850) +++ trunk/console/libgnt/gntwm.h 2006-11-30 05:52:21 UTC (rev 17851) @@ -27,6 +27,12 @@ typedef struct _GntWM GntWM; +typedef struct _GnPosition +{ + int x; + int y; +} GntPosition; + /** * An application can register actions which will show up in a 'start-menu' like popup */ @@ -73,6 +79,8 @@ GntKeyPressMode mode; + GHashTable *positions; + void *res1; void *res2; void *res3; Modified: trunk/console/libgnt/wms/s.c =================================================================== --- trunk/console/libgnt/wms/s.c 2006-11-30 02:01:49 UTC (rev 17850) +++ trunk/console/libgnt/wms/s.c 2006-11-30 05:52:21 UTC (rev 17851) @@ -97,19 +97,16 @@ mvwin(win->window, y, x); gnt_widget_set_size(win, -1, h + 2); /* XXX: Why is the +2 needed here? -- sadrul */ - } else if (name && strcmp(name, "conversation-window") == 0) { - /* Put the conversation windows to the far-right */ - x = maxx - w; - y = 0; - gnt_widget_set_position(win, x, y); - mvwin(win->window, y, x); } else if (!GNT_WIDGET_IS_FLAG_SET(win, GNT_WIDGET_TRANSIENT)) { - /* In the middle of the screen */ - x = (maxx - w) / 2; - y = (maxy - h) / 2; + const char *title = GNT_BOX(win)->title; + if (title == NULL || !g_hash_table_lookup(wm->positions, title)) { + /* In the middle of the screen */ + x = (maxx - w) / 2; + y = (maxy - h) / 2; - gnt_widget_set_position(win, x, y); - mvwin(win->window, y, x); + gnt_widget_set_position(win, x, y); + mvwin(win->window, y, x); + } } } org_new_window(wm, win); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-12-10 09:26:59
|
Revision: 17944 http://svn.sourceforge.net/gaim/?rev=17944&view=rev Author: sadrul Date: 2006-12-10 01:26:44 -0800 (Sun, 10 Dec 2006) Log Message: ----------- Generate the marshal-things during make when necessary. Allow specifying the hash-functions for a GntTree. Modified Paths: -------------- trunk/console/libgnt/Makefile.am trunk/console/libgnt/gnttree.c trunk/console/libgnt/gnttree.h trunk/console/libgnt/gntutils.c trunk/console/libgnt/gntutils.h Added Paths: ----------- trunk/console/libgnt/genmarshal Removed Paths: ------------- trunk/console/libgnt/gntmarshal.c trunk/console/libgnt/gntmarshal.h Modified: trunk/console/libgnt/Makefile.am =================================================================== --- trunk/console/libgnt/Makefile.am 2006-12-10 09:09:39 UTC (rev 17943) +++ trunk/console/libgnt/Makefile.am 2006-12-10 09:26:44 UTC (rev 17944) @@ -52,6 +52,16 @@ gntwm.h \ gnt.h +CLEANFILES = \ + gntmarshal.h \ + gntmarshal.c + +gntmarshal.c: genmarshal + cat genmarshal | glib-genmarshal --prefix=gnt_closure_marshal --body > $@ + +gntmarshal.h: genmarshal + cat genmarshal | glib-genmarshal --prefix=gnt_closure_marshal --header > $@ + libgnt_laincludedir=$(includedir)/gnt libgnt_lainclude_HEADERS = \ $(libgnt_la_headers) Added: trunk/console/libgnt/genmarshal =================================================================== --- trunk/console/libgnt/genmarshal (rev 0) +++ trunk/console/libgnt/genmarshal 2006-12-10 09:26:44 UTC (rev 17944) @@ -0,0 +1,10 @@ +BOOLEAN:VOID +BOOLEAN:STRING +VOID:INT,INT,INT,INT +VOID:INT,INT +VOID:POINTER,POINTER +BOOLEAN:INT,INT +BOOLEAN:INT,INT,INT +BOOLEAN:POINTER,POINTER,POINTER +BOOLEAN:INT,INT,INT,POINTER +VOID:STRING,STRING Property changes on: trunk/console/libgnt/genmarshal ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Deleted: trunk/console/libgnt/gntmarshal.c =================================================================== --- trunk/console/libgnt/gntmarshal.c 2006-12-10 09:09:39 UTC (rev 17943) +++ trunk/console/libgnt/gntmarshal.c 2006-12-10 09:26:44 UTC (rev 17944) @@ -1,427 +0,0 @@ - -#include <glib-object.h> - - -#ifdef G_ENABLE_DEBUG -#define g_marshal_value_peek_boolean(v) g_value_get_boolean (v) -#define g_marshal_value_peek_char(v) g_value_get_char (v) -#define g_marshal_value_peek_uchar(v) g_value_get_uchar (v) -#define g_marshal_value_peek_int(v) g_value_get_int (v) -#define g_marshal_value_peek_uint(v) g_value_get_uint (v) -#define g_marshal_value_peek_long(v) g_value_get_long (v) -#define g_marshal_value_peek_ulong(v) g_value_get_ulong (v) -#define g_marshal_value_peek_int64(v) g_value_get_int64 (v) -#define g_marshal_value_peek_uint64(v) g_value_get_uint64 (v) -#define g_marshal_value_peek_enum(v) g_value_get_enum (v) -#define g_marshal_value_peek_flags(v) g_value_get_flags (v) -#define g_marshal_value_peek_float(v) g_value_get_float (v) -#define g_marshal_value_peek_double(v) g_value_get_double (v) -#define g_marshal_value_peek_string(v) (char*) g_value_get_string (v) -#define g_marshal_value_peek_param(v) g_value_get_param (v) -#define g_marshal_value_peek_boxed(v) g_value_get_boxed (v) -#define g_marshal_value_peek_pointer(v) g_value_get_pointer (v) -#define g_marshal_value_peek_object(v) g_value_get_object (v) -#else /* !G_ENABLE_DEBUG */ -/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API. - * Do not access GValues directly in your code. Instead, use the - * g_value_get_*() functions - */ -#define g_marshal_value_peek_boolean(v) (v)->data[0].v_int -#define g_marshal_value_peek_char(v) (v)->data[0].v_int -#define g_marshal_value_peek_uchar(v) (v)->data[0].v_uint -#define g_marshal_value_peek_int(v) (v)->data[0].v_int -#define g_marshal_value_peek_uint(v) (v)->data[0].v_uint -#define g_marshal_value_peek_long(v) (v)->data[0].v_long -#define g_marshal_value_peek_ulong(v) (v)->data[0].v_ulong -#define g_marshal_value_peek_int64(v) (v)->data[0].v_int64 -#define g_marshal_value_peek_uint64(v) (v)->data[0].v_uint64 -#define g_marshal_value_peek_enum(v) (v)->data[0].v_long -#define g_marshal_value_peek_flags(v) (v)->data[0].v_ulong -#define g_marshal_value_peek_float(v) (v)->data[0].v_float -#define g_marshal_value_peek_double(v) (v)->data[0].v_double -#define g_marshal_value_peek_string(v) (v)->data[0].v_pointer -#define g_marshal_value_peek_param(v) (v)->data[0].v_pointer -#define g_marshal_value_peek_boxed(v) (v)->data[0].v_pointer -#define g_marshal_value_peek_pointer(v) (v)->data[0].v_pointer -#define g_marshal_value_peek_object(v) (v)->data[0].v_pointer -#endif /* !G_ENABLE_DEBUG */ - - -/* BOOLEAN:VOID (/dev/stdin:1) */ -void -gnt_closure_marshal_BOOLEAN__VOID (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data) -{ - typedef gboolean (*GMarshalFunc_BOOLEAN__VOID) (gpointer data1, - gpointer data2); - register GMarshalFunc_BOOLEAN__VOID callback; - register GCClosure *cc = (GCClosure*) closure; - register gpointer data1, data2; - gboolean v_return; - - g_return_if_fail (return_value != NULL); - g_return_if_fail (n_param_values == 1); - - if (G_CCLOSURE_SWAP_DATA (closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer (param_values + 0); - } - else - { - data1 = g_value_peek_pointer (param_values + 0); - data2 = closure->data; - } - callback = (GMarshalFunc_BOOLEAN__VOID) (marshal_data ? marshal_data : cc->callback); - - v_return = callback (data1, - data2); - - g_value_set_boolean (return_value, v_return); -} - -/* BOOLEAN:STRING (/dev/stdin:2) */ -void -gnt_closure_marshal_BOOLEAN__STRING (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data) -{ - typedef gboolean (*GMarshalFunc_BOOLEAN__STRING) (gpointer data1, - gpointer arg_1, - gpointer data2); - register GMarshalFunc_BOOLEAN__STRING callback; - register GCClosure *cc = (GCClosure*) closure; - register gpointer data1, data2; - gboolean v_return; - - g_return_if_fail (return_value != NULL); - g_return_if_fail (n_param_values == 2); - - if (G_CCLOSURE_SWAP_DATA (closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer (param_values + 0); - } - else - { - data1 = g_value_peek_pointer (param_values + 0); - data2 = closure->data; - } - callback = (GMarshalFunc_BOOLEAN__STRING) (marshal_data ? marshal_data : cc->callback); - - v_return = callback (data1, - g_marshal_value_peek_string (param_values + 1), - data2); - - g_value_set_boolean (return_value, v_return); -} - -/* VOID:INT,INT,INT,INT (/dev/stdin:3) */ -void -gnt_closure_marshal_VOID__INT_INT_INT_INT (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data) -{ - typedef void (*GMarshalFunc_VOID__INT_INT_INT_INT) (gpointer data1, - gint arg_1, - gint arg_2, - gint arg_3, - gint arg_4, - gpointer data2); - register GMarshalFunc_VOID__INT_INT_INT_INT callback; - register GCClosure *cc = (GCClosure*) closure; - register gpointer data1, data2; - - g_return_if_fail (n_param_values == 5); - - if (G_CCLOSURE_SWAP_DATA (closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer (param_values + 0); - } - else - { - data1 = g_value_peek_pointer (param_values + 0); - data2 = closure->data; - } - callback = (GMarshalFunc_VOID__INT_INT_INT_INT) (marshal_data ? marshal_data : cc->callback); - - callback (data1, - g_marshal_value_peek_int (param_values + 1), - g_marshal_value_peek_int (param_values + 2), - g_marshal_value_peek_int (param_values + 3), - g_marshal_value_peek_int (param_values + 4), - data2); -} - -/* VOID:INT,INT (/dev/stdin:4) */ -void -gnt_closure_marshal_VOID__INT_INT (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data) -{ - typedef void (*GMarshalFunc_VOID__INT_INT) (gpointer data1, - gint arg_1, - gint arg_2, - gpointer data2); - register GMarshalFunc_VOID__INT_INT callback; - register GCClosure *cc = (GCClosure*) closure; - register gpointer data1, data2; - - g_return_if_fail (n_param_values == 3); - - if (G_CCLOSURE_SWAP_DATA (closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer (param_values + 0); - } - else - { - data1 = g_value_peek_pointer (param_values + 0); - data2 = closure->data; - } - callback = (GMarshalFunc_VOID__INT_INT) (marshal_data ? marshal_data : cc->callback); - - callback (data1, - g_marshal_value_peek_int (param_values + 1), - g_marshal_value_peek_int (param_values + 2), - data2); -} - -/* VOID:POINTER,POINTER (/dev/stdin:5) */ -void -gnt_closure_marshal_VOID__POINTER_POINTER (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data) -{ - typedef void (*GMarshalFunc_VOID__POINTER_POINTER) (gpointer data1, - gpointer arg_1, - gpointer arg_2, - gpointer data2); - register GMarshalFunc_VOID__POINTER_POINTER callback; - register GCClosure *cc = (GCClosure*) closure; - register gpointer data1, data2; - - g_return_if_fail (n_param_values == 3); - - if (G_CCLOSURE_SWAP_DATA (closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer (param_values + 0); - } - else - { - data1 = g_value_peek_pointer (param_values + 0); - data2 = closure->data; - } - callback = (GMarshalFunc_VOID__POINTER_POINTER) (marshal_data ? marshal_data : cc->callback); - - callback (data1, - g_marshal_value_peek_pointer (param_values + 1), - g_marshal_value_peek_pointer (param_values + 2), - data2); -} - -/* BOOLEAN:INT,INT (/dev/stdin:6) */ -void -gnt_closure_marshal_BOOLEAN__INT_INT (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data) -{ - typedef gboolean (*GMarshalFunc_BOOLEAN__INT_INT) (gpointer data1, - gint arg_1, - gint arg_2, - gpointer data2); - register GMarshalFunc_BOOLEAN__INT_INT callback; - register GCClosure *cc = (GCClosure*) closure; - register gpointer data1, data2; - gboolean v_return; - - g_return_if_fail (return_value != NULL); - g_return_if_fail (n_param_values == 3); - - if (G_CCLOSURE_SWAP_DATA (closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer (param_values + 0); - } - else - { - data1 = g_value_peek_pointer (param_values + 0); - data2 = closure->data; - } - callback = (GMarshalFunc_BOOLEAN__INT_INT) (marshal_data ? marshal_data : cc->callback); - - v_return = callback (data1, - g_marshal_value_peek_int (param_values + 1), - g_marshal_value_peek_int (param_values + 2), - data2); - - g_value_set_boolean (return_value, v_return); -} - -/* BOOLEAN:INT,INT,INT (/dev/stdin:7) */ -void -gnt_closure_marshal_BOOLEAN__INT_INT_INT (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data) -{ - typedef gboolean (*GMarshalFunc_BOOLEAN__INT_INT_INT) (gpointer data1, - gint arg_1, - gint arg_2, - gint arg_3, - gpointer data2); - register GMarshalFunc_BOOLEAN__INT_INT_INT callback; - register GCClosure *cc = (GCClosure*) closure; - register gpointer data1, data2; - gboolean v_return; - - g_return_if_fail (return_value != NULL); - g_return_if_fail (n_param_values == 4); - - if (G_CCLOSURE_SWAP_DATA (closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer (param_values + 0); - } - else - { - data1 = g_value_peek_pointer (param_values + 0); - data2 = closure->data; - } - callback = (GMarshalFunc_BOOLEAN__INT_INT_INT) (marshal_data ? marshal_data : cc->callback); - - v_return = callback (data1, - g_marshal_value_peek_int (param_values + 1), - g_marshal_value_peek_int (param_values + 2), - g_marshal_value_peek_int (param_values + 3), - data2); - - g_value_set_boolean (return_value, v_return); -} - -/* BOOLEAN:POINTER,POINTER,POINTER (/dev/stdin:8) */ -void -gnt_closure_marshal_BOOLEAN__POINTER_POINTER_POINTER (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data) -{ - typedef gboolean (*GMarshalFunc_BOOLEAN__POINTER_POINTER_POINTER) (gpointer data1, - gpointer arg_1, - gpointer arg_2, - gpointer arg_3, - gpointer data2); - register GMarshalFunc_BOOLEAN__POINTER_POINTER_POINTER callback; - register GCClosure *cc = (GCClosure*) closure; - register gpointer data1, data2; - gboolean v_return; - - g_return_if_fail (return_value != NULL); - g_return_if_fail (n_param_values == 4); - - if (G_CCLOSURE_SWAP_DATA (closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer (param_values + 0); - } - else - { - data1 = g_value_peek_pointer (param_values + 0); - data2 = closure->data; - } - callback = (GMarshalFunc_BOOLEAN__POINTER_POINTER_POINTER) (marshal_data ? marshal_data : cc->callback); - - v_return = callback (data1, - g_marshal_value_peek_pointer (param_values + 1), - g_marshal_value_peek_pointer (param_values + 2), - g_marshal_value_peek_pointer (param_values + 3), - data2); - - g_value_set_boolean (return_value, v_return); -} - -/* BOOLEAN:INT,INT,INT,POINTER (/dev/stdin:9) */ -void -gnt_closure_marshal_BOOLEAN__INT_INT_INT_POINTER (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data) -{ - typedef gboolean (*GMarshalFunc_BOOLEAN__INT_INT_INT_POINTER) (gpointer data1, - gint arg_1, - gint arg_2, - gint arg_3, - gpointer arg_4, - gpointer data2); - register GMarshalFunc_BOOLEAN__INT_INT_INT_POINTER callback; - register GCClosure *cc = (GCClosure*) closure; - register gpointer data1, data2; - gboolean v_return; - - g_return_if_fail (return_value != NULL); - g_return_if_fail (n_param_values == 5); - - if (G_CCLOSURE_SWAP_DATA (closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer (param_values + 0); - } - else - { - data1 = g_value_peek_pointer (param_values + 0); - data2 = closure->data; - } - callback = (GMarshalFunc_BOOLEAN__INT_INT_INT_POINTER) (marshal_data ? marshal_data : cc->callback); - - v_return = callback (data1, - g_marshal_value_peek_int (param_values + 1), - g_marshal_value_peek_int (param_values + 2), - g_marshal_value_peek_int (param_values + 3), - g_marshal_value_peek_pointer (param_values + 4), - data2); - - g_value_set_boolean (return_value, v_return); -} - -gboolean gnt_boolean_handled_accumulator(GSignalInvocationHint *ihint, - GValue *return_accu, - const GValue *handler_return, - gpointer dummy) -{ - gboolean continue_emission; - gboolean signal_handled; - - signal_handled = g_value_get_boolean (handler_return); - g_value_set_boolean (return_accu, signal_handled); - continue_emission = !signal_handled; - - return continue_emission; -} - Deleted: trunk/console/libgnt/gntmarshal.h =================================================================== --- trunk/console/libgnt/gntmarshal.h 2006-12-10 09:09:39 UTC (rev 17943) +++ trunk/console/libgnt/gntmarshal.h 2006-12-10 09:26:44 UTC (rev 17944) @@ -1,91 +0,0 @@ - -#ifndef __gnt_closure_marshal_MARSHAL_H__ -#define __gnt_closure_marshal_MARSHAL_H__ - -#include <glib-object.h> - -G_BEGIN_DECLS - -/* BOOLEAN:VOID (/dev/stdin:1) */ -extern void gnt_closure_marshal_BOOLEAN__VOID (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - -/* BOOLEAN:STRING (/dev/stdin:2) */ -extern void gnt_closure_marshal_BOOLEAN__STRING (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - -/* VOID:INT,INT,INT,INT (/dev/stdin:3) */ -extern void gnt_closure_marshal_VOID__INT_INT_INT_INT (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - -/* VOID:INT,INT (/dev/stdin:4) */ -extern void gnt_closure_marshal_VOID__INT_INT (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - -/* VOID:POINTER,POINTER (/dev/stdin:5) */ -extern void gnt_closure_marshal_VOID__POINTER_POINTER (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - -/* BOOLEAN:INT,INT (/dev/stdin:6) */ -extern void gnt_closure_marshal_BOOLEAN__INT_INT (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - -/* BOOLEAN:INT,INT,INT (/dev/stdin:7) */ -extern void gnt_closure_marshal_BOOLEAN__INT_INT_INT (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - -/* BOOLEAN:POINTER,POINTER,POINTER (/dev/stdin:8) */ -extern void gnt_closure_marshal_BOOLEAN__POINTER_POINTER_POINTER (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - -/* BOOLEAN:INT,INT,INT,POINTER (/dev/stdin:9) */ -extern void gnt_closure_marshal_BOOLEAN__INT_INT_INT_POINTER (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - -G_END_DECLS - -#endif /* __gnt_closure_marshal_MARSHAL_H__ */ - -gboolean gnt_boolean_handled_accumulator(GSignalInvocationHint *ihint, - GValue *return_accu, - const GValue *handler_return, - gpointer dummy); - - - Modified: trunk/console/libgnt/gnttree.c =================================================================== --- trunk/console/libgnt/gnttree.c 2006-12-10 09:09:39 UTC (rev 17943) +++ trunk/console/libgnt/gnttree.c 2006-12-10 09:26:44 UTC (rev 17944) @@ -1005,6 +1005,8 @@ GntTreeRow *r = tree->root; row->next = r; if (r) r->prev = row; + if (tree->current == tree->root) + tree->current = row; tree->root = row; tree->list = g_list_prepend(tree->list, key); } @@ -1146,7 +1148,7 @@ void gnt_tree_remove_all(GntTree *tree) { tree->root = NULL; - g_hash_table_foreach_remove(tree->hash, (GHRFunc)return_true, NULL); + g_hash_table_foreach_remove(tree->hash, (GHRFunc)return_true, tree); g_list_free(tree->list); tree->list = NULL; tree->current = tree->top = tree->bottom = NULL; @@ -1394,3 +1396,10 @@ gnt_widget_set_size(GNT_WIDGET(tree), twidth, height); } +void gnt_tree_set_hash_fns(GntTree *tree, gpointer hash, gpointer eq, gpointer kd) +{ + g_hash_table_foreach_remove(tree->hash, return_true, NULL); + g_hash_table_destroy(tree->hash); + tree->hash = g_hash_table_new_full(hash, eq, kd, free_tree_row); +} + Modified: trunk/console/libgnt/gnttree.h =================================================================== --- trunk/console/libgnt/gnttree.h 2006-12-10 09:09:39 UTC (rev 17943) +++ trunk/console/libgnt/gnttree.h 2006-12-10 09:26:44 UTC (rev 17944) @@ -38,6 +38,10 @@ GList *list; /* List of GntTreeRow s */ GHashTable *hash; /* We need this for quickly referencing the rows */ + guint (*hash_func)(gconstpointer); + gboolean (*hash_eq_func)(gconstpointer, gconstpointer); + GDestroyNotify key_destroy; + GDestroyNotify value_destroy; int ncol; /* No. of columns */ struct _GntTreeColInfo @@ -131,6 +135,8 @@ /* This will try to automatically adjust the width of the columns in the tree */ void gnt_tree_adjust_columns(GntTree *tree); +void gnt_tree_set_hash_fns(GntTree *tree, gpointer hash, gpointer eq, gpointer kd); + G_END_DECLS /* The following functions should NOT be used by applications. */ Modified: trunk/console/libgnt/gntutils.c =================================================================== --- trunk/console/libgnt/gntutils.c 2006-12-10 09:09:39 UTC (rev 17943) +++ trunk/console/libgnt/gntutils.c 2006-12-10 09:26:44 UTC (rev 17944) @@ -119,3 +119,18 @@ return dest; } +gboolean gnt_boolean_handled_accumulator(GSignalInvocationHint *ihint, + GValue *return_accu, + const GValue *handler_return, + gpointer dummy) +{ + gboolean continue_emission; + gboolean signal_handled; + + signal_handled = g_value_get_boolean (handler_return); + g_value_set_boolean (return_accu, signal_handled); + continue_emission = !signal_handled; + + return continue_emission; +} + Modified: trunk/console/libgnt/gntutils.h =================================================================== --- trunk/console/libgnt/gntutils.h 2006-12-10 09:09:39 UTC (rev 17943) +++ trunk/console/libgnt/gntutils.h 2006-12-10 09:26:44 UTC (rev 17944) @@ -20,3 +20,14 @@ GHashTable *g_hash_table_duplicate(GHashTable *src, GHashFunc hash, GEqualFunc equal, GDestroyNotify key_d, GDestroyNotify value_d); + + +/** + * To be used with g_signal_new. Look in the key_pressed signal-definition in + * gntwidget.c for usage. + */ +gboolean gnt_boolean_handled_accumulator(GSignalInvocationHint *ihint, + GValue *return_accu, + const GValue *handler_return, + gpointer dummy); + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-12-15 00:40:59
|
Revision: 18000 http://svn.sourceforge.net/gaim/?rev=18000&view=rev Author: sadrul Date: 2006-12-14 16:40:56 -0800 (Thu, 14 Dec 2006) Log Message: ----------- Clicking the first window on the taskbar didn't give it focus. Fix that. Modified Paths: -------------- trunk/console/libgnt/gntbindable.c trunk/console/libgnt/gntwm.c Modified: trunk/console/libgnt/gntbindable.c =================================================================== --- trunk/console/libgnt/gntbindable.c 2006-12-14 22:25:18 UTC (rev 17999) +++ trunk/console/libgnt/gntbindable.c 2006-12-15 00:40:56 UTC (rev 18000) @@ -107,10 +107,7 @@ action = g_hash_table_lookup(klass->actions, name); if (action && action->u.action) { - if (list) - return action->u.action(bindable, list); - else - return action->u.action_noparam(bindable); + return action->u.action(bindable, list); } return FALSE; } Modified: trunk/console/libgnt/gntwm.c =================================================================== --- trunk/console/libgnt/gntwm.c 2006-12-14 22:25:18 UTC (rev 17999) +++ trunk/console/libgnt/gntwm.c 2006-12-15 00:40:56 UTC (rev 18000) @@ -300,10 +300,13 @@ GList *l; int n; - if (!wm->ordered || !list) + if (!wm->ordered) return TRUE; - n = GPOINTER_TO_INT(list->data); + if (list) + n = GPOINTER_TO_INT(list->data); + else + n = 0; w = wm->ordered->data; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |