Mercurial > pidgin.yaz
changeset 13853:bbf0470cb348
[gaim-migrate @ 16312]
Improvement/fixing of GntTree. Do the scrolling and stuff without 'reliably'.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Fri, 23 Jun 2006 00:45:45 +0000 |
parents | d95e5e0e29b9 |
children | a4c30c1d9de8 |
files | console/gntblist.c console/libgnt/gntbox.c console/libgnt/gntbox.h console/libgnt/gnttree.c |
diffstat | 4 files changed, 98 insertions(+), 61 deletions(-) [+] |
line wrap: on
line diff
--- a/console/gntblist.c Thu Jun 22 23:08:05 2006 +0000 +++ b/console/gntblist.c Fri Jun 23 00:45:45 2006 +0000 @@ -8,30 +8,9 @@ #include "gntbox.h" #include "gnttree.h" -#define TAB_SIZE 3 - -/** - * NOTES: - * - * 1. signal-callbacks should check for module_in_focus() before redrawing anything. - * 2. call module_lost_focus() before opening a new window, and module_gained_focus() when - * the new window is closed. This is to make sure the signal callbacks don't screw up - * the display. - */ +#include "gntblist.h" -static GaimBlistUiOps blist_ui_ops = -{ - NULL, - NULL, - NULL, - NULL, /* This doesn't do crap */ - NULL, - NULL, - NULL, - NULL, - NULL, - NULL -}; +#define TAB_SIZE 3 typedef struct { @@ -41,6 +20,43 @@ GGBlist *ggblist; +static void +new_node(GaimBlistNode *node) +{ +} + +static void +node_update(GaimBuddyList *list, GaimBlistNode *node) +{ +} + +static void +node_remove(GaimBuddyList *list, GaimBlistNode *node) +{ +} + +static void +new_list(GaimBuddyList *list) +{ + if (ggblist == NULL) + gg_blist_init(); + list->ui_data = ggblist; +} + +static GaimBlistUiOps blist_ui_ops = +{ + new_list, + new_node, + NULL, + node_update, /* This doesn't do crap */ + node_remove, + NULL, + NULL, + NULL, + NULL, + NULL +}; + static gpointer gg_blist_get_handle() { @@ -61,11 +77,15 @@ } static void -buddy_signed_on(GaimBuddy *buddy, GGBlist *ggblist) +add_buddy(GaimBuddy *buddy, GGBlist *ggblist) { - GaimGroup *group = gaim_buddy_get_group(buddy); char *text; + GaimGroup *group; + GaimBlistNode *node = (GaimBlistNode *)buddy; + if (node->ui_data) + return; + group = gaim_buddy_get_group(buddy); add_group(group, ggblist); text = g_strdup_printf("%*s%s", TAB_SIZE, "", gaim_buddy_get_alias(buddy)); @@ -74,6 +94,12 @@ } static void +buddy_signed_on(GaimBuddy *buddy, GGBlist *ggblist) +{ + add_buddy(buddy, ggblist); +} + +static void buddy_signed_off(GaimBuddy *buddy, GGBlist *ggblist) { gnt_tree_remove(GNT_TREE(ggblist->tree), buddy); @@ -92,13 +118,17 @@ void gg_blist_init() { - ggblist = g_new0(GGBlist, 1); + if (ggblist == NULL) + ggblist = g_new0(GGBlist, 1); ggblist->window = gnt_box_new(FALSE, FALSE); + GNT_WIDGET_UNSET_FLAGS(ggblist->window, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); gnt_box_set_title(GNT_BOX(ggblist->window), _("Buddy List")); + gnt_box_set_pad(GNT_BOX(ggblist->window), 0); ggblist->tree = gnt_tree_new(); - gnt_widget_set_size(ggblist->tree, 25, getmaxy(stdscr)); + GNT_WIDGET_SET_FLAGS(ggblist->tree, GNT_WIDGET_NO_BORDER); + gnt_widget_set_size(ggblist->tree, 25, getmaxy(stdscr) - 2); gnt_box_add_widget(GNT_BOX(ggblist->window), ggblist->tree); gnt_widget_show(ggblist->window);
--- a/console/libgnt/gntbox.c Thu Jun 22 23:08:05 2006 +0000 +++ b/console/libgnt/gntbox.c Fri Jun 23 00:45:45 2006 +0000 @@ -31,8 +31,8 @@ } else { + /* XXX: Position of the title might be configurable */ pos = (widget->priv.width - pos - 2) / 2; - /*pos = 2;*/ } wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_TITLE)); mvwprintw(widget->window, 0, pos, title); @@ -52,17 +52,15 @@ gboolean has_border = FALSE; int x, y; - x = widget->priv.x; - y = widget->priv.y; w = h = 0; max = -1; - curx = widget->priv.x; - cury = widget->priv.y; + curx = widget->priv.x + 1; + cury = widget->priv.y + 1; if (!(GNT_WIDGET_FLAGS(widget) & GNT_WIDGET_NO_BORDER)) { has_border = TRUE; - curx += 1; - cury += 1; + curx += box->pad; + cury += box->pad; if (!box->vertical) curx++; } @@ -73,13 +71,13 @@ gnt_widget_get_size(GNT_WIDGET(iter->data), &w, &h); if (box->vertical) { - cury += h + 1; + cury += h + box->pad; if (max < w) max = w; } else { - curx += w + 2; + curx += w + box->pad; if (max < h) max = h; } @@ -303,6 +301,7 @@ box->homogeneous = homo; box->vertical = vert; + box->pad = 1; gnt_widget_set_take_focus(widget, TRUE); GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); @@ -321,3 +320,9 @@ b->title = g_strdup(title); } +void gnt_box_set_pad(GntBox *box, int pad) +{ + box->pad = pad; + /* XXX: Perhaps redraw if already showing? */ +} +
--- a/console/libgnt/gntbox.h Thu Jun 22 23:08:05 2006 +0000 +++ b/console/libgnt/gntbox.h Fri Jun 23 00:45:45 2006 +0000 @@ -23,6 +23,7 @@ GList *list; /* List of widgets */ GList *active; + int pad; /* Number of spaces to use between widgets */ char *title; @@ -52,6 +53,8 @@ void gnt_box_set_title(GntBox *box, const char *title); +void gnt_box_set_pad(GntBox *box, int pad); + G_END_DECLS #endif /* GNT_BOX_H */
--- a/console/libgnt/gnttree.c Thu Jun 22 23:08:05 2006 +0000 +++ b/console/libgnt/gnttree.c Fri Jun 23 00:45:45 2006 +0000 @@ -21,11 +21,12 @@ static GntWidgetClass *parent_class = NULL; static guint signals[SIGS] = { 0 }; -/* XXX: This is ugly, but what can you do ... */ static void -gnt_tree_refresh(GntTree *tree) +redraw_tree(GntTree *tree) { + int start; GntWidget *widget = GNT_WIDGET(tree); + GList *iter; int pos; if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) @@ -33,50 +34,45 @@ else pos = 1; - copywin(tree->scroll, widget->window, tree->top, 0, - pos, pos, widget->priv.height - pos - 1, widget->priv.width - pos - 1, FALSE); - wrefresh(widget->window); -} - -static void -redraw_tree(GntTree *tree) -{ - int start; - GntWidget *widget = GNT_WIDGET(tree); - GList *iter; - wbkgd(tree->scroll, COLOR_PAIR(GNT_COLOR_NORMAL)); for (start = tree->top, iter = g_list_nth(tree->list, tree->top); iter && start < tree->bottom; start++, iter = iter->next) { char str[2096]; /* XXX: This should be safe for any terminal */ + int wr; GntTreeRow *row = g_hash_table_lookup(tree->hash, iter->data); - if (snprintf(str, widget->priv.width, "%s\n", row->text) >= widget->priv.width) + if ((wr = snprintf(str, widget->priv.width, "%s", row->text)) >= widget->priv.width) { /* XXX: ellipsize */ str[widget->priv.width - 1] = 0; } + else + { + while (wr < widget->priv.width - 1) + str[wr++] = ' '; + str[wr] = 0; + } if (start == tree->current) { wbkgdset(tree->scroll, '\0' | COLOR_PAIR(GNT_COLOR_HIGHLIGHT)); - mvwprintw(tree->scroll, start, 0, str); + mvwprintw(tree->scroll, start - tree->top + pos, pos, str); wbkgdset(tree->scroll, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); } else - mvwprintw(tree->scroll, start, 0, str); + mvwprintw(tree->scroll, start - tree->top + pos, pos, str); } while (start < tree->bottom) { - wmove(tree->scroll, start, 0); + wmove(tree->scroll, start - tree->top + pos, pos); wclrtoeol(tree->scroll); start++; } - gnt_tree_refresh(tree); + wrefresh(widget->window); } static void @@ -90,9 +86,10 @@ if (tree->scroll == NULL) { - tree->scroll = newwin(SCROLL_HEIGHT, widget->priv.width, widget->priv.y, widget->priv.x); + tree->scroll = widget->window; /* newwin(SCROLL_HEIGHT, widget->priv.width, 0, 0); */ scrollok(tree->scroll, TRUE); - wsetscrreg(tree->scroll, 0, SCROLL_HEIGHT - 1); + /*wsetscrreg(tree->scroll, 0, SCROLL_HEIGHT - 1);*/ + wsetscrreg(tree->scroll, 0, widget->priv.height - 1); tree->top = 0; tree->bottom = widget->priv.height - @@ -132,14 +129,16 @@ tree->current++; if (tree->current >= tree->bottom) gnt_tree_scroll(tree, 1 + tree->current - tree->bottom); - redraw_tree(tree); + else + redraw_tree(tree); } else if (strcmp(text+1, GNT_KEY_UP) == 0 && tree->current > 0) { tree->current--; if (tree->current < tree->top) gnt_tree_scroll(tree, tree->current - tree->top); - redraw_tree(tree); + else + redraw_tree(tree); } } else if (text[0] == '\r') @@ -216,6 +215,7 @@ GntTree *tree = GNT_TREE(widget); tree->hash = g_hash_table_new(g_direct_hash, g_direct_equal); + GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW); return widget; } @@ -249,8 +249,7 @@ tree->top += count; tree->bottom += count; - /*wscrl(tree->scroll, count);*/ - gnt_tree_refresh(tree); + redraw_tree(tree); } void gnt_tree_add_row_after(GntTree *tree, void *key, const char *text, void *parent, void *bigbro)