Mercurial > pidgin
diff console/libgnt/gnttree.c @ 13907:cc60d0861337
[gaim-migrate @ 16402]
This commit has 1234 lines of diff :)
Windows can now be moved (alt+m, then the arrow keys, then escape/enter).
Add a window to enable/disable accounts. But the 'add' etc. buttons don't
have any callbacks yet. I am going to need to do some more widgets (checkbox,
combobox) before I do anything else.
I have also updated the test programs to work with the changes in libgnt.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sun, 02 Jul 2006 22:13:06 +0000 |
parents | a621329e8c85 |
children | 9309d27d780c |
line wrap: on
line diff
--- a/console/libgnt/gnttree.c Sun Jul 02 21:52:06 2006 +0000 +++ b/console/libgnt/gnttree.c Sun Jul 02 22:13:06 2006 +0000 @@ -7,6 +7,7 @@ { SIG_SELECTION_CHANGED, SIG_SCROLLED, + SIG_TOGGLED, SIGS, }; @@ -21,6 +22,9 @@ void *data; /* XXX: unused */ gboolean collapsed; + gboolean choice; /* Is this a choice-box? + If choice is true, then child will be NULL */ + gboolean isselected; GntTreeRow *parent; GntTreeRow *child; @@ -188,6 +192,10 @@ else strcpy(format, "- "); } + else if (row->choice) + { + g_snprintf(format, sizeof(format) - 1, "[%c] ", row->isselected ? 'X' : ' '); + } if ((wr = g_snprintf(str, widget->priv.width, "%s%s", format, row->text)) >= widget->priv.width) { @@ -206,7 +214,7 @@ if (gnt_widget_has_focus(widget)) wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_HIGHLIGHT)); else - wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D)); /* XXX: This, somehow, doesn't work */ + wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D)); mvwprintw(widget->window, start, pos, str); wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); } @@ -306,10 +314,19 @@ row->collapsed = !row->collapsed; redraw_tree(tree); } + else if (row && row->choice) + { + row->isselected = !row->isselected; + g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key); + redraw_tree(tree); + } } if (old != tree->current) + { tree_selection_changed(tree, old, tree->current); + return TRUE; + } return FALSE; } @@ -349,6 +366,14 @@ NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); + signals[SIG_TOGGLED] = + g_signal_new("toggled", + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, G_TYPE_POINTER); DEBUG; } @@ -616,4 +641,39 @@ } } +GntTreeRow *gnt_tree_add_choice(GntTree *tree, void *key, const char *text, void *parent, void *bigbro) +{ + GntTreeRow *row; + row = g_hash_table_lookup(tree->hash, key); + g_return_val_if_fail(!row || !row->choice, NULL); + + row = gnt_tree_add_row_after(tree, key, text, parent, bigbro); + row->choice = TRUE; + + return row; +} + +void gnt_tree_set_choice(GntTree *tree, void *key, gboolean set) +{ + GntTreeRow *row = g_hash_table_lookup(tree->hash, key); + + if (!row) + return; + g_return_if_fail(row->choice); + + row->isselected = set; + redraw_tree(tree); +} + +gboolean gnt_tree_get_choice(GntTree *tree, void *key) +{ + GntTreeRow *row = g_hash_table_lookup(tree->hash, key); + + if (!row) + return; + g_return_val_if_fail(row->choice, FALSE); + + return row->isselected; +} +