Mercurial > pidgin.yaz
comparison console/libgnt/gnttree.c @ 13860:c1e3f7c75c3f
[gaim-migrate @ 16321]
Sean suggested displaying a tooltip in the buddylist (http://gaim.sourceforge.net/sean/gntmock.png).
This (http://img157.imageshack.us/img157/1793/q4jb.png) is close.
You can press Escape to hide the tooltip.
I haven't yet managed to refresh widgets when other widgets covering it are destroyed. So
some parts of the border around the buddylist gets erased. I am going to try to fix it.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Fri, 23 Jun 2006 19:41:31 +0000 |
parents | aa1c97f5e6eb |
children | 55fb5cd9bac9 |
comparison
equal
deleted
inserted
replaced
13859:60278852c20c | 13860:c1e3f7c75c3f |
---|---|
1 #include "gnttree.h" | 1 #include "gnttree.h" |
2 #include "gntutils.h" | |
2 | 3 |
3 enum | 4 enum |
4 { | 5 { |
5 SIGS = 1, | 6 SIG_SELECTION_CHANGED, |
7 SIGS, | |
6 }; | 8 }; |
7 | 9 |
8 #define TAB_SIZE 3 | 10 #define TAB_SIZE 3 |
9 | 11 |
10 /* XXX: Make this one into a GObject? | 12 /* XXX: Make this one into a GObject? |
111 if (widget->priv.width == 0 || widget->priv.height == 0) | 113 if (widget->priv.width == 0 || widget->priv.height == 0) |
112 gnt_widget_size_request(widget); | 114 gnt_widget_size_request(widget); |
113 DEBUG; | 115 DEBUG; |
114 } | 116 } |
115 | 117 |
118 static void | |
119 tree_selection_changed(GntTree *tree, int old, int current) | |
120 { | |
121 g_signal_emit(tree, signals[SIG_SELECTION_CHANGED], 0, old, current); | |
122 } | |
123 | |
116 static gboolean | 124 static gboolean |
117 gnt_tree_key_pressed(GntWidget *widget, const char *text) | 125 gnt_tree_key_pressed(GntWidget *widget, const char *text) |
118 { | 126 { |
119 GntTree *tree = GNT_TREE(widget); | 127 GntTree *tree = GNT_TREE(widget); |
128 int old = tree->current; | |
129 | |
120 if (text[0] == 27) | 130 if (text[0] == 27) |
121 { | 131 { |
122 if (strcmp(text+1, GNT_KEY_DOWN) == 0 && tree->current < g_list_length(tree->list) - 1) | 132 if (strcmp(text+1, GNT_KEY_DOWN) == 0 && tree->current < g_list_length(tree->list) - 1) |
123 { | 133 { |
124 tree->current++; | 134 tree->current++; |
139 else if (text[0] == '\r') | 149 else if (text[0] == '\r') |
140 { | 150 { |
141 gnt_widget_activate(widget); | 151 gnt_widget_activate(widget); |
142 } | 152 } |
143 | 153 |
154 if (old != tree->current) | |
155 tree_selection_changed(tree, old, tree->current); | |
156 | |
144 return FALSE; | 157 return FALSE; |
145 } | 158 } |
146 | 159 |
147 static void | 160 static void |
148 gnt_tree_destroy(GntWidget *widget) | 161 gnt_tree_destroy(GntWidget *widget) |
152 g_hash_table_destroy(tree->hash); | 165 g_hash_table_destroy(tree->hash); |
153 g_list_free(tree->list); | 166 g_list_free(tree->list); |
154 } | 167 } |
155 | 168 |
156 static void | 169 static void |
157 gnt_tree_class_init(GntWidgetClass *klass) | 170 gnt_tree_class_init(GntTreeClass *klass) |
158 { | 171 { |
159 GObjectClass *obj_class = G_OBJECT_CLASS(klass); | 172 GObjectClass *obj_class = G_OBJECT_CLASS(klass); |
160 | 173 |
161 parent_class = GNT_WIDGET_CLASS(klass); | 174 parent_class = GNT_WIDGET_CLASS(klass); |
162 parent_class->destroy = gnt_tree_destroy; | 175 parent_class->destroy = gnt_tree_destroy; |
163 parent_class->draw = gnt_tree_draw; | 176 parent_class->draw = gnt_tree_draw; |
164 parent_class->map = gnt_tree_map; | 177 parent_class->map = gnt_tree_map; |
165 parent_class->size_request = gnt_tree_size_request; | 178 parent_class->size_request = gnt_tree_size_request; |
166 parent_class->key_pressed = gnt_tree_key_pressed; | 179 parent_class->key_pressed = gnt_tree_key_pressed; |
180 | |
181 signals[SIG_SELECTION_CHANGED] = | |
182 g_signal_new("selection-changed", | |
183 G_TYPE_FROM_CLASS(klass), | |
184 G_SIGNAL_RUN_LAST, | |
185 G_STRUCT_OFFSET(GntTreeClass, selection_changed), | |
186 NULL, NULL, | |
187 gnt_closure_marshal_VOID__INT_INT, | |
188 G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT); | |
167 | 189 |
168 DEBUG; | 190 DEBUG; |
169 } | 191 } |
170 | 192 |
171 static void | 193 static void |
269 } | 291 } |
270 | 292 |
271 return dep; | 293 return dep; |
272 } | 294 } |
273 | 295 |
274 void gnt_tree_add_row_after(GntTree *tree, void *key, const char *text, void *parent, void *bigbro) | 296 GntTreeRow *gnt_tree_add_row_after(GntTree *tree, void *key, const char *text, void *parent, void *bigbro) |
275 { | 297 { |
276 GntTreeRow *row = g_new0(GntTreeRow, 1), *pr = NULL; | 298 GntTreeRow *row = g_new0(GntTreeRow, 1), *pr = NULL; |
277 | 299 |
278 g_hash_table_insert(tree->hash, key, row); | 300 g_hash_table_insert(tree->hash, key, row); |
279 | 301 |
333 row->text = g_strdup_printf("%*s%s", TAB_SIZE * find_depth(row), "", text); | 355 row->text = g_strdup_printf("%*s%s", TAB_SIZE * find_depth(row), "", text); |
334 row->data = NULL; | 356 row->data = NULL; |
335 | 357 |
336 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_MAPPED)) | 358 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_MAPPED)) |
337 redraw_tree(tree); | 359 redraw_tree(tree); |
360 | |
361 return row; | |
338 } | 362 } |
339 | 363 |
340 gpointer gnt_tree_get_selection_data(GntTree *tree) | 364 gpointer gnt_tree_get_selection_data(GntTree *tree) |
341 { | 365 { |
342 return g_list_nth(tree->list, tree->current); | 366 return g_list_nth_data(tree->list, tree->current); |
343 } | 367 } |
344 | 368 |
345 int gnt_tree_get_selection_index(GntTree *tree) | 369 int gnt_tree_get_selection_index(GntTree *tree) |
346 { | 370 { |
347 return tree->current; | 371 return tree->current; |
353 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | 377 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); |
354 if (row) | 378 if (row) |
355 { | 379 { |
356 int len, pos; | 380 int len, pos; |
357 | 381 |
358 g_free(row->text); | |
359 g_free(row); | |
360 | |
361 pos = g_list_index(tree->list, key); | 382 pos = g_list_index(tree->list, key); |
362 | 383 |
363 g_hash_table_remove(tree->hash, key); | 384 g_hash_table_remove(tree->hash, key); |
364 tree->list = g_list_remove(tree->list, key); | 385 tree->list = g_list_remove(tree->list, key); |
365 | 386 |
366 if (pos >= tree->top && pos < tree->bottom) | 387 if (pos >= tree->top && pos < tree->bottom) |
367 { | 388 { |
368 redraw_tree(tree); | 389 redraw_tree(tree); |
369 } | 390 } |
370 } | 391 g_hash_table_replace(tree->hash, key, NULL); |
371 } | 392 } |
372 | 393 } |
394 | |
395 int gnt_tree_get_selection_visible_line(GntTree *tree) | |
396 { | |
397 return (tree->current - tree->top) + | |
398 !!(GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER)); | |
399 } | |
400 |