comparison 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
comparison
equal deleted inserted replaced
13906:b986b6e2441b 13907:cc60d0861337
5 5
6 enum 6 enum
7 { 7 {
8 SIG_SELECTION_CHANGED, 8 SIG_SELECTION_CHANGED,
9 SIG_SCROLLED, 9 SIG_SCROLLED,
10 SIG_TOGGLED,
10 SIGS, 11 SIGS,
11 }; 12 };
12 13
13 #define TAB_SIZE 3 14 #define TAB_SIZE 3
14 15
19 void *key; 20 void *key;
20 char *text; 21 char *text;
21 void *data; /* XXX: unused */ 22 void *data; /* XXX: unused */
22 23
23 gboolean collapsed; 24 gboolean collapsed;
25 gboolean choice; /* Is this a choice-box?
26 If choice is true, then child will be NULL */
27 gboolean isselected;
24 28
25 GntTreeRow *parent; 29 GntTreeRow *parent;
26 GntTreeRow *child; 30 GntTreeRow *child;
27 GntTreeRow *next; 31 GntTreeRow *next;
28 GntTreeRow *prev; 32 GntTreeRow *prev;
186 deep = FALSE; 190 deep = FALSE;
187 } 191 }
188 else 192 else
189 strcpy(format, "- "); 193 strcpy(format, "- ");
190 } 194 }
195 else if (row->choice)
196 {
197 g_snprintf(format, sizeof(format) - 1, "[%c] ", row->isselected ? 'X' : ' ');
198 }
191 199
192 if ((wr = g_snprintf(str, widget->priv.width, "%s%s", format, row->text)) >= widget->priv.width) 200 if ((wr = g_snprintf(str, widget->priv.width, "%s%s", format, row->text)) >= widget->priv.width)
193 { 201 {
194 /* XXX: ellipsize */ 202 /* XXX: ellipsize */
195 str[widget->priv.width - 1 - pos] = 0; 203 str[widget->priv.width - 1 - pos] = 0;
204 if (row == tree->current) 212 if (row == tree->current)
205 { 213 {
206 if (gnt_widget_has_focus(widget)) 214 if (gnt_widget_has_focus(widget))
207 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_HIGHLIGHT)); 215 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_HIGHLIGHT));
208 else 216 else
209 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D)); /* XXX: This, somehow, doesn't work */ 217 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D));
210 mvwprintw(widget->window, start, pos, str); 218 mvwprintw(widget->window, start, pos, str);
211 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); 219 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL));
212 } 220 }
213 else 221 else
214 mvwprintw(widget->window, start, pos, str); 222 mvwprintw(widget->window, start, pos, str);
304 if (row && row->child) 312 if (row && row->child)
305 { 313 {
306 row->collapsed = !row->collapsed; 314 row->collapsed = !row->collapsed;
307 redraw_tree(tree); 315 redraw_tree(tree);
308 } 316 }
317 else if (row && row->choice)
318 {
319 row->isselected = !row->isselected;
320 g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key);
321 redraw_tree(tree);
322 }
309 } 323 }
310 324
311 if (old != tree->current) 325 if (old != tree->current)
326 {
312 tree_selection_changed(tree, old, tree->current); 327 tree_selection_changed(tree, old, tree->current);
328 return TRUE;
329 }
313 330
314 return FALSE; 331 return FALSE;
315 } 332 }
316 333
317 static void 334 static void
347 G_SIGNAL_RUN_LAST, 364 G_SIGNAL_RUN_LAST,
348 0, 365 0,
349 NULL, NULL, 366 NULL, NULL,
350 g_cclosure_marshal_VOID__INT, 367 g_cclosure_marshal_VOID__INT,
351 G_TYPE_NONE, 1, G_TYPE_INT); 368 G_TYPE_NONE, 1, G_TYPE_INT);
369 signals[SIG_TOGGLED] =
370 g_signal_new("toggled",
371 G_TYPE_FROM_CLASS(klass),
372 G_SIGNAL_RUN_LAST,
373 0,
374 NULL, NULL,
375 g_cclosure_marshal_VOID__POINTER,
376 G_TYPE_NONE, 1, G_TYPE_POINTER);
352 377
353 DEBUG; 378 DEBUG;
354 } 379 }
355 380
356 static void 381 static void
614 if (get_distance(tree->top, row) >= 0 && get_distance(row, tree->bottom) > 0) 639 if (get_distance(tree->top, row) >= 0 && get_distance(row, tree->bottom) > 0)
615 redraw_tree(tree); 640 redraw_tree(tree);
616 } 641 }
617 } 642 }
618 643
619 644 GntTreeRow *gnt_tree_add_choice(GntTree *tree, void *key, const char *text, void *parent, void *bigbro)
645 {
646 GntTreeRow *row;
647
648 row = g_hash_table_lookup(tree->hash, key);
649 g_return_val_if_fail(!row || !row->choice, NULL);
650
651 row = gnt_tree_add_row_after(tree, key, text, parent, bigbro);
652 row->choice = TRUE;
653
654 return row;
655 }
656
657 void gnt_tree_set_choice(GntTree *tree, void *key, gboolean set)
658 {
659 GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
660
661 if (!row)
662 return;
663 g_return_if_fail(row->choice);
664
665 row->isselected = set;
666 redraw_tree(tree);
667 }
668
669 gboolean gnt_tree_get_choice(GntTree *tree, void *key)
670 {
671 GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
672
673 if (!row)
674 return;
675 g_return_val_if_fail(row->choice, FALSE);
676
677 return row->isselected;
678 }
679