Mercurial > pidgin
annotate finch/libgnt/gnttree.c @ 17700:e0f7da938ad3
propagate from branch 'im.pidgin.pidgin' (head 234d50fbd0d7227e39d68d9dd3c21afc02b4fd01)
to branch 'im.pidgin.finch.workspaces' (head 1c8dc02b27984381f3c5c0c6c1f8c4bedfd8dd86)
author | Richard Nelson <wabz@pidgin.im> |
---|---|
date | Fri, 27 Apr 2007 01:57:41 +0000 |
parents | 5187395d6b78 |
children | 467698ab6bf0 |
rev | line source |
---|---|
15817 | 1 #include "gntmarshal.h" |
2 #include "gntstyle.h" | |
3 #include "gnttree.h" | |
4 #include "gntutils.h" | |
5 | |
6 #include <string.h> | |
7 #include <ctype.h> | |
8 | |
9 #define SEARCH_TIMEOUT 4000 /* 4 secs */ | |
16249
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
10 #define SEARCHING(tree) (tree->search && tree->search->len > 0) |
15817 | 11 |
12 enum | |
13 { | |
14 SIG_SELECTION_CHANGED, | |
15 SIG_SCROLLED, | |
16 SIG_TOGGLED, | |
16105
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
17 SIG_COLLAPSED, |
15817 | 18 SIGS, |
19 }; | |
20 | |
21 #define TAB_SIZE 3 | |
22 | |
23 /* XXX: Make this one into a GObject? | |
24 * ... Probably not */ | |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
25 struct _GntTreeRow |
15817 | 26 { |
27 void *key; | |
28 void *data; /* XXX: unused */ | |
29 | |
30 gboolean collapsed; | |
31 gboolean choice; /* Is this a choice-box? | |
32 If choice is true, then child will be NULL */ | |
33 gboolean isselected; | |
34 GntTextFormatFlags flags; | |
35 | |
36 GntTreeRow *parent; | |
37 GntTreeRow *child; | |
38 GntTreeRow *next; | |
39 GntTreeRow *prev; | |
40 | |
41 GList *columns; | |
42 GntTree *tree; | |
43 }; | |
44 | |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
45 struct _GntTreeCol |
15817 | 46 { |
47 char *text; | |
48 int span; /* How many columns does it span? */ | |
49 }; | |
50 | |
16203
4f6a6443a1e3
emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents:
16123
diff
changeset
|
51 static void tree_selection_changed(GntTree *, GntTreeRow *, GntTreeRow *); |
4f6a6443a1e3
emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents:
16123
diff
changeset
|
52 |
15817 | 53 static GntWidgetClass *parent_class = NULL; |
54 static guint signals[SIGS] = { 0 }; | |
55 | |
56 /* Move the item at position old to position new */ | |
57 static GList * | |
58 g_list_reposition_child(GList *list, int old, int new) | |
59 { | |
60 gpointer item = g_list_nth_data(list, old); | |
61 list = g_list_remove(list, item); | |
62 if (old < new) | |
63 new--; /* because the positions would have shifted after removing the item */ | |
64 list = g_list_insert(list, item, new); | |
65 return list; | |
66 } | |
67 | |
68 static GntTreeRow * | |
69 _get_next(GntTreeRow *row, gboolean godeep) | |
70 { | |
71 if (row == NULL) | |
72 return NULL; | |
73 if (godeep && row->child) | |
74 return row->child; | |
75 if (row->next) | |
76 return row->next; | |
77 return _get_next(row->parent, FALSE); | |
78 } | |
79 | |
80 static gboolean | |
81 row_matches_search(GntTreeRow *row) | |
82 { | |
83 GntTree *t = row->tree; | |
84 if (t->search && t->search->len > 0) { | |
85 char *one = g_utf8_casefold(((GntTreeCol*)row->columns->data)->text, -1); | |
86 char *two = g_utf8_casefold(t->search->str, -1); | |
87 char *z = strstr(one, two); | |
88 g_free(one); | |
89 g_free(two); | |
90 if (z == NULL) | |
91 return FALSE; | |
92 } | |
93 return TRUE; | |
94 } | |
95 | |
96 static GntTreeRow * | |
97 get_next(GntTreeRow *row) | |
98 { | |
99 if (row == NULL) | |
100 return NULL; | |
101 while ((row = _get_next(row, !row->collapsed)) != NULL) { | |
102 if (row_matches_search(row)) | |
103 break; | |
104 } | |
105 return row; | |
106 } | |
107 | |
108 /* Returns the n-th next row. If it doesn't exist, returns NULL */ | |
109 static GntTreeRow * | |
110 get_next_n(GntTreeRow *row, int n) | |
111 { | |
112 while (row && n--) | |
113 row = get_next(row); | |
114 return row; | |
115 } | |
116 | |
117 /* Returns the n-th next row. If it doesn't exist, then the last non-NULL node */ | |
118 static GntTreeRow * | |
119 get_next_n_opt(GntTreeRow *row, int n, int *pos) | |
120 { | |
121 GntTreeRow *next = row; | |
122 int r = 0; | |
123 | |
124 if (row == NULL) | |
125 return NULL; | |
126 | |
127 while (row && n--) | |
128 { | |
129 row = get_next(row); | |
130 if (row) | |
131 { | |
132 next = row; | |
133 r++; | |
134 } | |
135 } | |
136 | |
137 if (pos) | |
138 *pos = r; | |
139 | |
140 return next; | |
141 } | |
142 | |
143 static GntTreeRow * | |
144 get_last_child(GntTreeRow *row) | |
145 { | |
146 if (row == NULL) | |
147 return NULL; | |
148 if (!row->collapsed && row->child) | |
149 row = row->child; | |
150 else | |
151 return row; | |
152 | |
153 while(row->next) | |
154 row = row->next; | |
155 if (!row->collapsed && row->child) | |
156 row = get_last_child(row->child); | |
157 return row; | |
158 } | |
159 | |
160 static GntTreeRow * | |
161 get_prev(GntTreeRow *row) | |
162 { | |
163 if (row == NULL) | |
164 return NULL; | |
165 while (row) { | |
166 if (row->prev) | |
167 row = get_last_child(row->prev); | |
168 else | |
169 row = row->parent; | |
170 if (!row || row_matches_search(row)) | |
171 break; | |
172 } | |
173 return row; | |
174 } | |
175 | |
176 static GntTreeRow * | |
177 get_prev_n(GntTreeRow *row, int n) | |
178 { | |
179 while (row && n--) | |
180 row = get_prev(row); | |
181 return row; | |
182 } | |
183 | |
184 /* Distance of row from the root */ | |
185 /* XXX: This is uber-inefficient */ | |
186 static int | |
187 get_root_distance(GntTreeRow *row) | |
188 { | |
189 if (row == NULL) | |
190 return -1; | |
191 return get_root_distance(get_prev(row)) + 1; | |
192 } | |
193 | |
194 /* Returns the distance between a and b. | |
195 * If a is 'above' b, then the distance is positive */ | |
196 static int | |
197 get_distance(GntTreeRow *a, GntTreeRow *b) | |
198 { | |
199 /* First get the distance from a to the root. | |
200 * Then the distance from b to the root. | |
201 * Subtract. | |
202 * It's not that good, but it works. */ | |
203 int ha = get_root_distance(a); | |
204 int hb = get_root_distance(b); | |
205 | |
206 return (hb - ha); | |
207 } | |
208 | |
209 static int | |
210 find_depth(GntTreeRow *row) | |
211 { | |
212 int dep = -1; | |
213 | |
214 while (row) | |
215 { | |
216 dep++; | |
217 row = row->parent; | |
218 } | |
219 | |
220 return dep; | |
221 } | |
222 | |
223 static char * | |
224 update_row_text(GntTree *tree, GntTreeRow *row) | |
225 { | |
226 GString *string = g_string_new(NULL); | |
227 GList *iter; | |
228 int i; | |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
229 gboolean notfirst = FALSE; |
15971
05d347516fcd
Fine tune column hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15970
diff
changeset
|
230 int lastvisible = tree->ncol; |
05d347516fcd
Fine tune column hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15970
diff
changeset
|
231 |
05d347516fcd
Fine tune column hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15970
diff
changeset
|
232 while (lastvisible && tree->columns[lastvisible].invisible) |
05d347516fcd
Fine tune column hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15970
diff
changeset
|
233 lastvisible--; |
15817 | 234 |
235 for (i = 0, iter = row->columns; i < tree->ncol && iter; i++, iter = iter->next) | |
236 { | |
237 GntTreeCol *col = iter->data; | |
238 const char *text; | |
239 int len = gnt_util_onscreen_width(col->text, NULL); | |
240 int fl = 0; | |
241 gboolean cut = FALSE; | |
15971
05d347516fcd
Fine tune column hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15970
diff
changeset
|
242 int width; |
15817 | 243 |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
244 if (tree->columns[i].invisible) |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
245 continue; |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
246 |
15971
05d347516fcd
Fine tune column hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15970
diff
changeset
|
247 if (i == lastvisible) |
05d347516fcd
Fine tune column hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15970
diff
changeset
|
248 width = GNT_WIDGET(tree)->priv.width - gnt_util_onscreen_width(string->str, NULL); |
05d347516fcd
Fine tune column hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15970
diff
changeset
|
249 else |
05d347516fcd
Fine tune column hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15970
diff
changeset
|
250 width = tree->columns[i].width; |
05d347516fcd
Fine tune column hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15970
diff
changeset
|
251 |
15817 | 252 if (i == 0) |
253 { | |
254 if (row->choice) | |
255 { | |
256 g_string_append_printf(string, "[%c] ", | |
257 row->isselected ? 'X' : ' '); | |
258 fl = 4; | |
259 } | |
260 else if (row->parent == NULL && row->child) | |
261 { | |
262 if (row->collapsed) | |
263 { | |
264 string = g_string_append(string, "+ "); | |
265 } | |
266 else | |
267 { | |
268 string = g_string_append(string, "- "); | |
269 } | |
270 fl = 2; | |
271 } | |
272 else | |
273 { | |
274 fl = TAB_SIZE * find_depth(row); | |
275 g_string_append_printf(string, "%*s", fl, ""); | |
276 } | |
277 len += fl; | |
278 } | |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
279 else if (notfirst) |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
280 g_string_append_c(string, '|'); |
15817 | 281 else |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
282 g_string_append_c(string, ' '); |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
283 |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
284 notfirst = TRUE; |
15817 | 285 |
15971
05d347516fcd
Fine tune column hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15970
diff
changeset
|
286 if (len > width) { |
05d347516fcd
Fine tune column hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15970
diff
changeset
|
287 len = width - 1; |
15817 | 288 cut = TRUE; |
289 } | |
290 text = gnt_util_onscreen_width_to_pointer(col->text, len - fl, NULL); | |
291 string = g_string_append_len(string, col->text, text - col->text); | |
292 if (cut) { /* ellipsis */ | |
293 if (gnt_ascii_only()) | |
294 g_string_append_c(string, '~'); | |
295 else | |
296 string = g_string_append(string, "\342\200\246"); | |
297 len++; | |
298 } | |
299 | |
300 if (len < tree->columns[i].width && iter->next) | |
15971
05d347516fcd
Fine tune column hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15970
diff
changeset
|
301 g_string_append_printf(string, "%*s", width - len, ""); |
15817 | 302 } |
303 return g_string_free(string, FALSE); | |
304 } | |
305 | |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
306 #define NEXT_X x += tree->columns[i].width + (i > 0 ? 1 : 0) |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
307 |
15817 | 308 static void |
309 tree_mark_columns(GntTree *tree, int pos, int y, chtype type) | |
310 { | |
311 GntWidget *widget = GNT_WIDGET(tree); | |
312 int i; | |
313 int x = pos; | |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
314 gboolean notfirst = FALSE; |
15817 | 315 |
316 for (i = 0; i < tree->ncol - 1; i++) | |
317 { | |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
318 if (!tree->columns[i].invisible) { |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
319 notfirst = TRUE; |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
320 NEXT_X; |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
321 } |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
322 if (!tree->columns[i+1].invisible && notfirst) |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
323 mvwaddch(widget->window, y, x, type); |
15817 | 324 } |
325 } | |
326 | |
327 static void | |
328 redraw_tree(GntTree *tree) | |
329 { | |
330 int start, i; | |
331 GntWidget *widget = GNT_WIDGET(tree); | |
332 GntTreeRow *row; | |
333 int pos, up, down; | |
334 int rows, scrcol; | |
335 | |
336 if (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_MAPPED)) | |
337 return; | |
338 | |
339 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
340 pos = 0; | |
341 else | |
342 pos = 1; | |
343 | |
344 if (tree->top == NULL) | |
345 tree->top = tree->root; | |
16203
4f6a6443a1e3
emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents:
16123
diff
changeset
|
346 if (tree->current == NULL) { |
15817 | 347 tree->current = tree->root; |
16203
4f6a6443a1e3
emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents:
16123
diff
changeset
|
348 tree_selection_changed(tree, NULL, tree->current); |
4f6a6443a1e3
emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents:
16123
diff
changeset
|
349 } |
15817 | 350 |
351 wbkgd(widget->window, COLOR_PAIR(GNT_COLOR_NORMAL)); | |
352 | |
353 start = 0; | |
354 if (tree->show_title) | |
355 { | |
356 int i; | |
357 int x = pos; | |
358 | |
359 mvwhline(widget->window, pos + 1, pos, ACS_HLINE | COLOR_PAIR(GNT_COLOR_NORMAL), | |
360 widget->priv.width - pos - 1); | |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
361 mvwhline(widget->window, pos, pos, ' ' | COLOR_PAIR(GNT_COLOR_NORMAL), |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
362 widget->priv.width - pos - 1); |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
363 |
15817 | 364 for (i = 0; i < tree->ncol; i++) |
365 { | |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
366 if (tree->columns[i].invisible) { |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
367 continue; |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
368 } |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
369 mvwaddstr(widget->window, pos, x + 1, tree->columns[i].title); |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
370 NEXT_X; |
15817 | 371 } |
372 if (pos) | |
373 { | |
374 tree_mark_columns(tree, pos, 0, ACS_TTEE | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
375 tree_mark_columns(tree, pos, widget->priv.height - pos, | |
376 ACS_BTEE | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
377 } | |
378 tree_mark_columns(tree, pos, pos + 1, | |
379 (tree->show_separator ? ACS_PLUS : ACS_HLINE) | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
380 tree_mark_columns(tree, pos, pos, | |
381 (tree->show_separator ? ACS_VLINE : ' ') | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
382 start = 2; | |
383 } | |
384 | |
385 rows = widget->priv.height - pos * 2 - start - 1; | |
386 tree->bottom = get_next_n_opt(tree->top, rows, &down); | |
387 if (down < rows) | |
388 { | |
389 tree->top = get_prev_n(tree->bottom, rows); | |
390 if (tree->top == NULL) | |
391 tree->top = tree->root; | |
392 } | |
393 | |
394 up = get_distance(tree->top, tree->current); | |
395 if (up < 0) | |
396 tree->top = tree->current; | |
397 else if (up >= widget->priv.height - pos) | |
398 tree->top = get_prev_n(tree->current, rows); | |
399 | |
400 if (tree->top && !row_matches_search(tree->top)) | |
401 tree->top = get_next(tree->top); | |
402 row = tree->top; | |
403 scrcol = widget->priv.width - 1 - 2 * pos; /* exclude the borders and the scrollbar */ | |
404 for (i = start + pos; row && i < widget->priv.height - pos; | |
405 i++, row = get_next(row)) | |
406 { | |
407 char *str; | |
408 int wr; | |
409 | |
410 GntTextFormatFlags flags = row->flags; | |
411 int attr = 0; | |
412 | |
413 if (!row_matches_search(row)) | |
414 continue; | |
415 str = update_row_text(tree, row); | |
416 | |
417 if ((wr = gnt_util_onscreen_width(str, NULL)) > scrcol) | |
418 { | |
419 char *s = (char*)gnt_util_onscreen_width_to_pointer(str, scrcol, &wr); | |
420 *s = '\0'; | |
421 } | |
422 | |
423 if (flags & GNT_TEXT_FLAG_BOLD) | |
424 attr |= A_BOLD; | |
425 if (flags & GNT_TEXT_FLAG_UNDERLINE) | |
426 attr |= A_UNDERLINE; | |
427 if (flags & GNT_TEXT_FLAG_BLINK) | |
428 attr |= A_BLINK; | |
429 | |
430 if (row == tree->current) | |
431 { | |
432 if (gnt_widget_has_focus(widget)) | |
433 attr |= COLOR_PAIR(GNT_COLOR_HIGHLIGHT); | |
434 else | |
435 attr |= COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D); | |
436 } | |
437 else | |
438 { | |
439 if (flags & GNT_TEXT_FLAG_DIM) | |
440 attr |= (A_DIM | COLOR_PAIR(GNT_COLOR_DISABLED)); | |
441 else if (flags & GNT_TEXT_FLAG_HIGHLIGHT) | |
442 attr |= (A_DIM | COLOR_PAIR(GNT_COLOR_HIGHLIGHT)); | |
443 else | |
444 attr |= COLOR_PAIR(GNT_COLOR_NORMAL); | |
445 } | |
446 | |
447 wbkgdset(widget->window, '\0' | attr); | |
448 mvwaddstr(widget->window, i, pos, str); | |
449 whline(widget->window, ' ', scrcol - wr); | |
450 tree->bottom = row; | |
451 g_free(str); | |
452 tree_mark_columns(tree, pos, i, | |
453 (tree->show_separator ? ACS_VLINE : ' ') | attr); | |
454 } | |
455 | |
456 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
457 while (i < widget->priv.height - pos) | |
458 { | |
459 mvwhline(widget->window, i, pos, ' ', | |
460 widget->priv.width - pos * 2 - 1); | |
461 tree_mark_columns(tree, pos, i, | |
462 (tree->show_separator ? ACS_VLINE : ' ')); | |
463 i++; | |
464 } | |
465 | |
466 scrcol = widget->priv.width - pos - 1; /* position of the scrollbar */ | |
467 rows--; | |
468 if (rows > 0) | |
469 { | |
470 int total; | |
471 int showing, position; | |
472 | |
473 get_next_n_opt(tree->root, g_list_length(tree->list), &total); | |
474 showing = rows * rows / MAX(total, 1) + 1; | |
475 showing = MIN(rows, showing); | |
476 | |
477 total -= rows; | |
478 up = get_distance(tree->root, tree->top); | |
479 down = total - up; | |
480 | |
481 position = (rows - showing) * up / MAX(1, up + down); | |
482 position = MAX((tree->top != tree->root), position); | |
483 | |
484 if (showing + position > rows) | |
485 position = rows - showing; | |
486 | |
487 if (showing + position == rows && row) | |
488 position = MAX(0, rows - 1 - showing); | |
489 else if (showing + position < rows && !row) | |
490 position = rows - showing; | |
491 | |
492 position += pos + start + 1; | |
493 | |
494 mvwvline(widget->window, pos + start + 1, scrcol, | |
495 ' ' | COLOR_PAIR(GNT_COLOR_NORMAL), rows); | |
496 mvwvline(widget->window, position, scrcol, | |
497 ACS_CKBOARD | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D), showing); | |
498 } | |
499 | |
500 mvwaddch(widget->window, start + pos, scrcol, | |
501 ((tree->top != tree->root) ? ACS_UARROW : ' ') | | |
502 COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D)); | |
503 | |
504 mvwaddch(widget->window, widget->priv.height - pos - 1, scrcol, | |
505 (row ? ACS_DARROW : ' ') | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D)); | |
506 | |
16249
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
507 /* If there's a search-text, show it in the bottom of the tree */ |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
508 if (tree->search && tree->search->len > 0) { |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
509 const char *str = gnt_util_onscreen_width_to_pointer(tree->search->str, scrcol - 1, NULL); |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
510 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D)); |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
511 mvwaddnstr(widget->window, widget->priv.height - pos - 1, pos, |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
512 tree->search->str, str - tree->search->str); |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
513 } |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
514 |
15817 | 515 gnt_widget_queue_update(widget); |
516 } | |
517 | |
518 static void | |
519 gnt_tree_draw(GntWidget *widget) | |
520 { | |
521 GntTree *tree = GNT_TREE(widget); | |
522 | |
523 redraw_tree(tree); | |
524 | |
525 GNTDEBUG; | |
526 } | |
527 | |
528 static void | |
529 gnt_tree_size_request(GntWidget *widget) | |
530 { | |
531 if (widget->priv.height == 0) | |
532 widget->priv.height = 10; /* XXX: Why?! */ | |
533 if (widget->priv.width == 0) | |
534 { | |
535 GntTree *tree = GNT_TREE(widget); | |
536 int i, width = 0; | |
537 for (i = 0; i < tree->ncol; i++) | |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
538 if (!tree->columns[i].invisible) |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
539 width += tree->columns[i].width + 1; |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
540 widget->priv.width = width; |
15817 | 541 } |
542 } | |
543 | |
544 static void | |
545 gnt_tree_map(GntWidget *widget) | |
546 { | |
547 GntTree *tree = GNT_TREE(widget); | |
548 if (widget->priv.width == 0 || widget->priv.height == 0) | |
549 { | |
550 gnt_widget_size_request(widget); | |
551 } | |
552 tree->top = tree->root; | |
553 tree->current = tree->root; | |
554 GNTDEBUG; | |
555 } | |
556 | |
557 static void | |
558 tree_selection_changed(GntTree *tree, GntTreeRow *old, GntTreeRow *current) | |
559 { | |
560 g_signal_emit(tree, signals[SIG_SELECTION_CHANGED], 0, old ? old->key : NULL, | |
561 current ? current->key : NULL); | |
562 } | |
563 | |
564 static gboolean | |
565 action_down(GntBindable *bind, GList *null) | |
566 { | |
567 int dist; | |
568 GntTree *tree = GNT_TREE(bind); | |
569 GntTreeRow *old = tree->current; | |
570 GntTreeRow *row = get_next(tree->current); | |
571 if (row == NULL) | |
572 return FALSE; | |
573 tree->current = row; | |
574 if ((dist = get_distance(tree->current, tree->bottom)) < 0) | |
575 gnt_tree_scroll(tree, -dist); | |
576 else | |
577 redraw_tree(tree); | |
578 if (old != tree->current) | |
579 tree_selection_changed(tree, old, tree->current); | |
580 return TRUE; | |
581 } | |
582 | |
583 static gboolean | |
15972
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
584 action_move_parent(GntBindable *bind, GList *null) |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
585 { |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
586 GntTree *tree = GNT_TREE(bind); |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
587 GntTreeRow *row = tree->current; |
16249
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
588 int dist; |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
589 |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
590 if (!row->parent || SEARCHING(tree)) |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
591 return FALSE; |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
592 |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
593 tree->current = row->parent; |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
594 if ((dist = get_distance(tree->current, tree->top)) > 0) |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
595 gnt_tree_scroll(tree, -dist); |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
596 else |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
597 redraw_tree(tree); |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
598 tree_selection_changed(tree, row, tree->current); |
15972
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
599 return TRUE; |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
600 } |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
601 |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
602 static gboolean |
15817 | 603 action_up(GntBindable *bind, GList *list) |
604 { | |
605 int dist; | |
606 GntTree *tree = GNT_TREE(bind); | |
607 GntTreeRow *old = tree->current; | |
608 GntTreeRow *row = get_prev(tree->current); | |
609 if (!row) | |
610 return FALSE; | |
611 tree->current = row; | |
612 if ((dist = get_distance(tree->current, tree->top)) > 0) | |
613 gnt_tree_scroll(tree, -dist); | |
614 else | |
615 redraw_tree(tree); | |
616 if (old != tree->current) | |
617 tree_selection_changed(tree, old, tree->current); | |
618 | |
619 return TRUE; | |
620 } | |
621 | |
622 static gboolean | |
623 action_page_down(GntBindable *bind, GList *null) | |
624 { | |
625 GntTree *tree = GNT_TREE(bind); | |
626 GntTreeRow *old = tree->current; | |
627 GntTreeRow *row = get_next(tree->bottom); | |
628 if (row) | |
629 { | |
630 int dist = get_distance(tree->top, tree->current); | |
631 tree->top = tree->bottom; | |
632 tree->current = get_next_n_opt(tree->top, dist, NULL); | |
633 redraw_tree(tree); | |
634 } | |
635 else if (tree->current != tree->bottom) | |
636 { | |
637 tree->current = tree->bottom; | |
638 redraw_tree(tree); | |
639 } | |
640 | |
641 if (old != tree->current) | |
642 tree_selection_changed(tree, old, tree->current); | |
643 return TRUE; | |
644 } | |
645 | |
646 static gboolean | |
647 action_page_up(GntBindable *bind, GList *null) | |
648 { | |
649 GntWidget *widget = GNT_WIDGET(bind); | |
650 GntTree *tree = GNT_TREE(bind); | |
651 GntTreeRow *row; | |
652 GntTreeRow *old = tree->current; | |
653 | |
654 if (tree->top != tree->root) | |
655 { | |
656 int dist = get_distance(tree->top, tree->current); | |
657 row = get_prev_n(tree->top, widget->priv.height - 1 - | |
658 tree->show_title * 2 - 2 * (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER) == 0)); | |
659 if (row == NULL) | |
660 row = tree->root; | |
661 tree->top = row; | |
662 tree->current = get_next_n_opt(tree->top, dist, NULL); | |
663 redraw_tree(tree); | |
664 } | |
665 else if (tree->current != tree->top) | |
666 { | |
667 tree->current = tree->top; | |
668 redraw_tree(tree); | |
669 } | |
670 if (old != tree->current) | |
671 tree_selection_changed(tree, old, tree->current); | |
672 return TRUE; | |
673 } | |
674 | |
675 static void | |
676 end_search(GntTree *tree) | |
677 { | |
678 if (tree->search) { | |
679 g_source_remove(tree->search_timeout); | |
680 g_string_free(tree->search, TRUE); | |
681 tree->search = NULL; | |
682 tree->search_timeout = 0; | |
683 } | |
684 } | |
685 | |
686 static gboolean | |
687 search_timeout(gpointer data) | |
688 { | |
689 GntTree *tree = data; | |
690 | |
691 end_search(tree); | |
692 redraw_tree(tree); | |
693 | |
694 return FALSE; | |
695 } | |
696 | |
697 static gboolean | |
698 gnt_tree_key_pressed(GntWidget *widget, const char *text) | |
699 { | |
700 GntTree *tree = GNT_TREE(widget); | |
701 GntTreeRow *old = tree->current; | |
702 | |
703 if (text[0] == '\r') { | |
704 end_search(tree); | |
705 gnt_widget_activate(widget); | |
706 } else if (tree->search) { | |
16249
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
707 gboolean changed = TRUE; |
15817 | 708 if (isalnum(*text)) { |
709 tree->search = g_string_append_c(tree->search, *text); | |
16249
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
710 } else if (g_utf8_collate(text, GNT_KEY_BACKSPACE) == 0) { |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
711 if (tree->search->len) |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
712 tree->search->str[--tree->search->len] = '\0'; |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
713 } else |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
714 changed = FALSE; |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
715 if (changed) { |
15817 | 716 redraw_tree(tree); |
717 g_source_remove(tree->search_timeout); | |
718 tree->search_timeout = g_timeout_add(SEARCH_TIMEOUT, search_timeout, tree); | |
719 } | |
720 return TRUE; | |
721 } else if (text[0] == ' ' && text[1] == 0) { | |
722 /* Space pressed */ | |
723 GntTreeRow *row = tree->current; | |
724 if (row && row->child) | |
725 { | |
726 row->collapsed = !row->collapsed; | |
727 redraw_tree(tree); | |
16105
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
728 g_signal_emit(tree, signals[SIG_COLLAPSED], 0, row->key, row->collapsed); |
15817 | 729 } |
730 else if (row && row->choice) | |
731 { | |
732 row->isselected = !row->isselected; | |
733 g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key); | |
734 redraw_tree(tree); | |
735 } | |
736 } | |
737 | |
738 if (old != tree->current) | |
739 { | |
740 tree_selection_changed(tree, old, tree->current); | |
741 return TRUE; | |
742 } | |
743 | |
744 return FALSE; | |
745 } | |
746 | |
747 static void | |
748 gnt_tree_destroy(GntWidget *widget) | |
749 { | |
750 GntTree *tree = GNT_TREE(widget); | |
751 int i; | |
752 | |
753 end_search(tree); | |
754 if (tree->hash) | |
755 g_hash_table_destroy(tree->hash); | |
756 g_list_free(tree->list); | |
757 | |
758 for (i = 0; i < tree->ncol; i++) | |
759 { | |
760 g_free(tree->columns[i].title); | |
761 } | |
762 g_free(tree->columns); | |
763 } | |
764 | |
765 static gboolean | |
766 gnt_tree_clicked(GntWidget *widget, GntMouseEvent event, int x, int y) | |
767 { | |
768 GntTree *tree = GNT_TREE(widget); | |
769 GntTreeRow *old = tree->current; | |
770 if (event == GNT_MOUSE_SCROLL_UP) { | |
771 action_up(GNT_BINDABLE(widget), NULL); | |
772 } else if (event == GNT_MOUSE_SCROLL_DOWN) { | |
773 action_down(GNT_BINDABLE(widget), NULL); | |
774 } else if (event == GNT_LEFT_MOUSE_DOWN) { | |
775 GntTreeRow *row; | |
776 GntTree *tree = GNT_TREE(widget); | |
777 int pos = 1; | |
778 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
779 pos = 0; | |
780 if (tree->show_title) | |
781 pos += 2; | |
782 pos = y - widget->priv.y - pos; | |
783 row = get_next_n(tree->top, pos); | |
784 if (row && tree->current != row) { | |
785 GntTreeRow *old = tree->current; | |
786 tree->current = row; | |
787 redraw_tree(tree); | |
788 tree_selection_changed(tree, old, tree->current); | |
789 } else if (row && row == tree->current) { | |
790 if (row->choice) { | |
791 row->isselected = !row->isselected; | |
792 g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key); | |
793 redraw_tree(tree); | |
794 } else { | |
795 gnt_widget_activate(widget); | |
796 } | |
797 } | |
798 } else { | |
799 return FALSE; | |
800 } | |
801 if (old != tree->current) { | |
802 tree_selection_changed(tree, old, tree->current); | |
803 } | |
804 return TRUE; | |
805 } | |
806 | |
807 static void | |
808 gnt_tree_size_changed(GntWidget *widget, int w, int h) | |
809 { | |
810 GntTree *tree = GNT_TREE(widget); | |
811 int i; | |
812 int n = 0; | |
813 if (widget->priv.width <= 0) | |
814 return; | |
815 for (i = 0; i < tree->ncol; ++i) | |
816 n += tree->columns[i].width; | |
817 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
818 tree->columns[tree->ncol - 1].width += widget->priv.width - n - 1 * tree->ncol; | |
819 else | |
820 tree->columns[tree->ncol - 1].width += widget->priv.width - n - 2 - 1 * tree->ncol; | |
821 } | |
822 | |
823 static gboolean | |
824 start_search(GntBindable *bindable, GList *list) | |
825 { | |
826 GntTree *tree = GNT_TREE(bindable); | |
827 if (tree->search) | |
828 return FALSE; | |
829 tree->search = g_string_new(NULL); | |
830 tree->search_timeout = g_timeout_add(SEARCH_TIMEOUT, search_timeout, tree); | |
831 return TRUE; | |
832 } | |
833 | |
834 static gboolean | |
835 end_search_action(GntBindable *bindable, GList *list) | |
836 { | |
837 GntTree *tree = GNT_TREE(bindable); | |
838 if (tree->search == NULL) | |
839 return FALSE; | |
840 end_search(tree); | |
841 redraw_tree(tree); | |
842 return TRUE; | |
843 } | |
844 | |
845 static void | |
846 gnt_tree_class_init(GntTreeClass *klass) | |
847 { | |
848 GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass); | |
849 parent_class = GNT_WIDGET_CLASS(klass); | |
850 parent_class->destroy = gnt_tree_destroy; | |
851 parent_class->draw = gnt_tree_draw; | |
852 parent_class->map = gnt_tree_map; | |
853 parent_class->size_request = gnt_tree_size_request; | |
854 parent_class->key_pressed = gnt_tree_key_pressed; | |
855 parent_class->clicked = gnt_tree_clicked; | |
856 parent_class->size_changed = gnt_tree_size_changed; | |
857 | |
858 signals[SIG_SELECTION_CHANGED] = | |
859 g_signal_new("selection-changed", | |
860 G_TYPE_FROM_CLASS(klass), | |
861 G_SIGNAL_RUN_LAST, | |
862 G_STRUCT_OFFSET(GntTreeClass, selection_changed), | |
863 NULL, NULL, | |
864 gnt_closure_marshal_VOID__POINTER_POINTER, | |
865 G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER); | |
866 signals[SIG_SCROLLED] = | |
867 g_signal_new("scrolled", | |
868 G_TYPE_FROM_CLASS(klass), | |
869 G_SIGNAL_RUN_LAST, | |
870 0, | |
871 NULL, NULL, | |
872 g_cclosure_marshal_VOID__INT, | |
873 G_TYPE_NONE, 1, G_TYPE_INT); | |
874 signals[SIG_TOGGLED] = | |
875 g_signal_new("toggled", | |
876 G_TYPE_FROM_CLASS(klass), | |
877 G_SIGNAL_RUN_LAST, | |
878 G_STRUCT_OFFSET(GntTreeClass, toggled), | |
879 NULL, NULL, | |
880 g_cclosure_marshal_VOID__POINTER, | |
881 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
16105
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
882 signals[SIG_COLLAPSED] = |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
883 g_signal_new("collapse-toggled", |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
884 G_TYPE_FROM_CLASS(klass), |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
885 G_SIGNAL_RUN_LAST, |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
886 0, |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
887 NULL, NULL, |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
888 gnt_closure_marshal_VOID__POINTER_BOOLEAN, |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
889 G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_BOOLEAN); |
15817 | 890 |
891 gnt_bindable_class_register_action(bindable, "move-up", action_up, | |
892 GNT_KEY_UP, NULL); | |
893 gnt_bindable_register_binding(bindable, "move-up", GNT_KEY_CTRL_P, NULL); | |
894 gnt_bindable_class_register_action(bindable, "move-down", action_down, | |
895 GNT_KEY_DOWN, NULL); | |
896 gnt_bindable_register_binding(bindable, "move-down", GNT_KEY_CTRL_N, NULL); | |
15972
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
897 gnt_bindable_class_register_action(bindable, "move-parent", action_move_parent, |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
898 GNT_KEY_BACKSPACE, NULL); |
15817 | 899 gnt_bindable_class_register_action(bindable, "page-up", action_page_up, |
900 GNT_KEY_PGUP, NULL); | |
901 gnt_bindable_class_register_action(bindable, "page-down", action_page_down, | |
902 GNT_KEY_PGDOWN, NULL); | |
903 gnt_bindable_class_register_action(bindable, "start-search", start_search, | |
904 "/", NULL); | |
905 gnt_bindable_class_register_action(bindable, "end-search", end_search_action, | |
906 "\033", NULL); | |
907 | |
908 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), bindable); | |
909 GNTDEBUG; | |
910 } | |
911 | |
912 static void | |
913 gnt_tree_init(GTypeInstance *instance, gpointer class) | |
914 { | |
915 GntWidget *widget = GNT_WIDGET(instance); | |
916 GntTree *tree = GNT_TREE(widget); | |
917 tree->show_separator = TRUE; | |
918 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y); | |
919 widget->priv.minw = 4; | |
920 widget->priv.minh = 1; | |
921 GNTDEBUG; | |
922 } | |
923 | |
924 /****************************************************************************** | |
925 * GntTree API | |
926 *****************************************************************************/ | |
927 GType | |
928 gnt_tree_get_gtype(void) | |
929 { | |
930 static GType type = 0; | |
931 | |
932 if(type == 0) | |
933 { | |
934 static const GTypeInfo info = { | |
935 sizeof(GntTreeClass), | |
936 NULL, /* base_init */ | |
937 NULL, /* base_finalize */ | |
938 (GClassInitFunc)gnt_tree_class_init, | |
939 NULL, /* class_finalize */ | |
940 NULL, /* class_data */ | |
941 sizeof(GntTree), | |
942 0, /* n_preallocs */ | |
943 gnt_tree_init, /* instance_init */ | |
944 NULL /* value_table */ | |
945 }; | |
946 | |
947 type = g_type_register_static(GNT_TYPE_WIDGET, | |
948 "GntTree", | |
949 &info, 0); | |
950 } | |
951 | |
952 return type; | |
953 } | |
954 | |
955 static void | |
956 free_tree_col(gpointer data) | |
957 { | |
958 GntTreeCol *col = data; | |
959 | |
960 g_free(col->text); | |
961 g_free(col); | |
962 } | |
963 | |
964 static void | |
965 free_tree_row(gpointer data) | |
966 { | |
967 GntTreeRow *row = data; | |
968 | |
969 if (!row) | |
970 return; | |
971 | |
972 g_list_foreach(row->columns, (GFunc)free_tree_col, NULL); | |
973 g_list_free(row->columns); | |
974 g_free(row); | |
975 } | |
976 | |
977 GntWidget *gnt_tree_new() | |
978 { | |
979 return gnt_tree_new_with_columns(1); | |
980 } | |
981 | |
982 void gnt_tree_set_visible_rows(GntTree *tree, int rows) | |
983 { | |
984 GntWidget *widget = GNT_WIDGET(tree); | |
985 widget->priv.height = rows; | |
986 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
987 widget->priv.height += 2; | |
988 } | |
989 | |
990 int gnt_tree_get_visible_rows(GntTree *tree) | |
991 { | |
992 GntWidget *widget = GNT_WIDGET(tree); | |
993 int ret = widget->priv.height; | |
994 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
995 ret -= 2; | |
996 return ret; | |
997 } | |
998 | |
999 const GList *gnt_tree_get_rows(GntTree *tree) | |
1000 { | |
1001 return tree->list; | |
1002 } | |
1003 | |
1004 void gnt_tree_scroll(GntTree *tree, int count) | |
1005 { | |
1006 GntTreeRow *row; | |
1007 | |
1008 if (count < 0) | |
1009 { | |
1010 if (get_root_distance(tree->top) == 0) | |
1011 return; | |
1012 row = get_prev_n(tree->top, -count); | |
1013 if (row == NULL) | |
1014 row = tree->root; | |
1015 tree->top = row; | |
1016 } | |
1017 else | |
1018 { | |
1019 get_next_n_opt(tree->bottom, count, &count); | |
1020 tree->top = get_next_n(tree->top, count); | |
1021 } | |
1022 | |
1023 redraw_tree(tree); | |
1024 g_signal_emit(tree, signals[SIG_SCROLLED], 0, count); | |
1025 } | |
1026 | |
1027 static gpointer | |
1028 find_position(GntTree *tree, gpointer key, gpointer parent) | |
1029 { | |
1030 GntTreeRow *row; | |
1031 | |
1032 if (tree->compare == NULL) | |
1033 return NULL; | |
1034 | |
1035 if (parent == NULL) | |
1036 row = tree->root; | |
1037 else | |
1038 row = g_hash_table_lookup(tree->hash, parent); | |
1039 | |
1040 if (!row) | |
1041 return NULL; | |
1042 | |
1043 if (parent) | |
1044 row = row->child; | |
1045 | |
1046 while (row) | |
1047 { | |
1048 if (tree->compare(key, row->key) < 0) | |
1049 return (row->prev ? row->prev->key : NULL); | |
1050 if (row->next) | |
1051 row = row->next; | |
1052 else | |
1053 return row->key; | |
1054 } | |
1055 return NULL; | |
1056 } | |
1057 | |
1058 void gnt_tree_sort_row(GntTree *tree, gpointer key) | |
1059 { | |
1060 GntTreeRow *row, *q, *s; | |
1061 int current, newp; | |
1062 | |
1063 if (!tree->compare) | |
1064 return; | |
1065 | |
1066 row = g_hash_table_lookup(tree->hash, key); | |
1067 g_return_if_fail(row != NULL); | |
1068 | |
1069 current = g_list_index(tree->list, key); | |
1070 | |
1071 if (row->parent) | |
1072 s = row->parent->child; | |
1073 else | |
1074 s = tree->root; | |
1075 | |
1076 q = NULL; | |
1077 while (s) { | |
1078 if (tree->compare(row->key, s->key) < 0) | |
1079 break; | |
1080 q = s; | |
1081 s = s->next; | |
1082 } | |
1083 | |
1084 /* Move row between q and s */ | |
1085 if (row == q || row == s) | |
1086 return; | |
1087 | |
1088 if (q == NULL) { | |
1089 /* row becomes the first child of its parent */ | |
1090 row->prev->next = row->next; /* row->prev cannot be NULL at this point */ | |
1091 if (row->next) | |
1092 row->next->prev = row->prev; | |
1093 if (row->parent) | |
1094 row->parent->child = row; | |
1095 else | |
1096 tree->root = row; | |
1097 row->next = s; | |
1098 s->prev = row; /* s cannot be NULL */ | |
1099 row->prev = NULL; | |
1100 newp = g_list_index(tree->list, s) - 1; | |
1101 } else { | |
1102 if (row->prev) { | |
1103 row->prev->next = row->next; | |
1104 } else { | |
1105 /* row was the first child of its parent */ | |
1106 if (row->parent) | |
1107 row->parent->child = row->next; | |
1108 else | |
1109 tree->top = row->next; | |
1110 } | |
1111 | |
1112 if (row->next) | |
1113 row->next->prev = row->prev; | |
1114 | |
1115 q->next = row; | |
1116 row->prev = q; | |
1117 if (s) | |
1118 s->prev = row; | |
1119 row->next = s; | |
1120 newp = g_list_index(tree->list, q) + 1; | |
1121 } | |
1122 tree->list = g_list_reposition_child(tree->list, current, newp); | |
1123 | |
1124 redraw_tree(tree); | |
1125 } | |
1126 | |
1127 GntTreeRow *gnt_tree_add_row_after(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro) | |
1128 { | |
1129 GntTreeRow *pr = NULL; | |
1130 | |
1131 g_hash_table_replace(tree->hash, key, row); | |
1132 row->tree = tree; | |
1133 | |
1134 if (bigbro == NULL && tree->compare) | |
1135 { | |
1136 bigbro = find_position(tree, key, parent); | |
1137 } | |
1138 | |
1139 if (tree->root == NULL) | |
1140 { | |
1141 tree->root = row; | |
1142 tree->list = g_list_prepend(tree->list, key); | |
1143 } | |
1144 else | |
1145 { | |
1146 int position = 0; | |
1147 | |
1148 if (bigbro) | |
1149 { | |
1150 pr = g_hash_table_lookup(tree->hash, bigbro); | |
1151 if (pr) | |
1152 { | |
1153 if (pr->next) pr->next->prev = row; | |
1154 row->next = pr->next; | |
1155 row->prev = pr; | |
1156 pr->next = row; | |
1157 row->parent = pr->parent; | |
1158 | |
1159 position = g_list_index(tree->list, bigbro); | |
1160 } | |
1161 } | |
1162 | |
1163 if (pr == NULL && parent) | |
1164 { | |
1165 pr = g_hash_table_lookup(tree->hash, parent); | |
1166 if (pr) | |
1167 { | |
1168 if (pr->child) pr->child->prev = row; | |
1169 row->next = pr->child; | |
1170 pr->child = row; | |
1171 row->parent = pr; | |
1172 | |
1173 position = g_list_index(tree->list, parent); | |
1174 } | |
1175 } | |
1176 | |
1177 if (pr == NULL) | |
1178 { | |
1179 GntTreeRow *r = tree->root; | |
1180 row->next = r; | |
1181 if (r) r->prev = row; | |
1182 if (tree->current == tree->root) | |
1183 tree->current = row; | |
1184 tree->root = row; | |
1185 tree->list = g_list_prepend(tree->list, key); | |
1186 } | |
1187 else | |
1188 { | |
1189 tree->list = g_list_insert(tree->list, key, position + 1); | |
1190 } | |
1191 } | |
1192 | |
1193 row->key = key; | |
1194 row->data = NULL; | |
1195 | |
1196 redraw_tree(tree); | |
1197 | |
1198 return row; | |
1199 } | |
1200 | |
1201 GntTreeRow *gnt_tree_add_row_last(GntTree *tree, void *key, GntTreeRow *row, void *parent) | |
1202 { | |
1203 GntTreeRow *pr = NULL, *br = NULL; | |
1204 | |
1205 if (parent) | |
1206 pr = g_hash_table_lookup(tree->hash, parent); | |
1207 | |
1208 if (pr) | |
1209 br = pr->child; | |
1210 else | |
1211 br = tree->root; | |
1212 | |
1213 if (br) | |
1214 { | |
1215 while (br->next) | |
1216 br = br->next; | |
1217 } | |
1218 | |
1219 return gnt_tree_add_row_after(tree, key, row, parent, br ? br->key : NULL); | |
1220 } | |
1221 | |
1222 gpointer gnt_tree_get_selection_data(GntTree *tree) | |
1223 { | |
1224 if (tree->current) | |
1225 return tree->current->key; /* XXX: perhaps we should just get rid of 'data' */ | |
1226 return NULL; | |
1227 } | |
1228 | |
1229 char *gnt_tree_get_selection_text(GntTree *tree) | |
1230 { | |
1231 if (tree->current) | |
1232 return update_row_text(tree, tree->current); | |
1233 return NULL; | |
1234 } | |
1235 | |
1236 GList *gnt_tree_get_selection_text_list(GntTree *tree) | |
1237 { | |
1238 GList *list = NULL, *iter; | |
1239 int i; | |
1240 | |
1241 if (!tree->current) | |
1242 return NULL; | |
1243 | |
1244 for (i = 0, iter = tree->current->columns; i < tree->ncol && iter; | |
1245 i++, iter = iter->next) | |
1246 { | |
1247 GntTreeCol *col = iter->data; | |
1248 list = g_list_append(list, g_strdup(col->text)); | |
1249 } | |
1250 | |
1251 return list; | |
1252 } | |
1253 | |
1254 void gnt_tree_remove(GntTree *tree, gpointer key) | |
1255 { | |
1256 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1257 static int depth = 0; /* Only redraw after all child nodes are removed */ | |
1258 if (row) | |
1259 { | |
1260 gboolean redraw = FALSE; | |
1261 | |
1262 if (row->child) { | |
1263 depth++; | |
1264 while (row->child) { | |
1265 gnt_tree_remove(tree, row->child->key); | |
1266 } | |
1267 depth--; | |
1268 } | |
1269 | |
1270 if (get_distance(tree->top, row) >= 0 && get_distance(row, tree->bottom) >= 0) | |
1271 redraw = TRUE; | |
1272 | |
1273 /* Update root/top/current/bottom if necessary */ | |
1274 if (tree->root == row) | |
1275 tree->root = get_next(row); | |
1276 if (tree->top == row) | |
1277 { | |
1278 if (tree->top != tree->root) | |
1279 tree->top = get_prev(row); | |
1280 else | |
1281 tree->top = get_next(row); | |
1282 } | |
1283 if (tree->current == row) | |
1284 { | |
1285 if (tree->current != tree->root) | |
1286 tree->current = get_prev(row); | |
1287 else | |
1288 tree->current = get_next(row); | |
1289 tree_selection_changed(tree, row, tree->current); | |
1290 } | |
1291 if (tree->bottom == row) | |
1292 { | |
1293 tree->bottom = get_prev(row); | |
1294 } | |
1295 | |
1296 /* Fix the links */ | |
1297 if (row->next) | |
1298 row->next->prev = row->prev; | |
1299 if (row->parent && row->parent->child == row) | |
1300 row->parent->child = row->next; | |
1301 if (row->prev) | |
1302 row->prev->next = row->next; | |
1303 | |
1304 g_hash_table_remove(tree->hash, key); | |
1305 tree->list = g_list_remove(tree->list, key); | |
1306 | |
1307 if (redraw && depth == 0) | |
1308 { | |
1309 redraw_tree(tree); | |
1310 } | |
1311 } | |
1312 } | |
1313 | |
1314 static gboolean | |
1315 return_true(gpointer key, gpointer data, gpointer null) | |
1316 { | |
1317 return TRUE; | |
1318 } | |
1319 | |
1320 void gnt_tree_remove_all(GntTree *tree) | |
1321 { | |
1322 tree->root = NULL; | |
1323 g_hash_table_foreach_remove(tree->hash, (GHRFunc)return_true, tree); | |
1324 g_list_free(tree->list); | |
1325 tree->list = NULL; | |
1326 tree->current = tree->top = tree->bottom = NULL; | |
1327 } | |
1328 | |
1329 int gnt_tree_get_selection_visible_line(GntTree *tree) | |
1330 { | |
1331 return get_distance(tree->top, tree->current) + | |
1332 !!(GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER)); | |
1333 } | |
1334 | |
1335 void gnt_tree_change_text(GntTree *tree, gpointer key, int colno, const char *text) | |
1336 { | |
1337 GntTreeRow *row; | |
1338 GntTreeCol *col; | |
1339 | |
1340 g_return_if_fail(colno < tree->ncol); | |
1341 | |
1342 row = g_hash_table_lookup(tree->hash, key); | |
1343 if (row) | |
1344 { | |
1345 col = g_list_nth_data(row->columns, colno); | |
1346 g_free(col->text); | |
16283
5187395d6b78
Debug is not necessary anymore, and don't crash on null text.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16249
diff
changeset
|
1347 col->text = g_strdup(text ? text : ""); |
15817 | 1348 |
1349 if (get_distance(tree->top, row) >= 0 && get_distance(row, tree->bottom) >= 0) | |
1350 redraw_tree(tree); | |
1351 } | |
1352 } | |
1353 | |
1354 GntTreeRow *gnt_tree_add_choice(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro) | |
1355 { | |
1356 GntTreeRow *r; | |
1357 r = g_hash_table_lookup(tree->hash, key); | |
1358 g_return_val_if_fail(!r || !r->choice, NULL); | |
1359 | |
1360 if (bigbro == NULL) { | |
1361 if (tree->compare) | |
1362 bigbro = find_position(tree, key, parent); | |
1363 else { | |
1364 r = g_hash_table_lookup(tree->hash, parent); | |
1365 if (!r) | |
1366 r = tree->root; | |
1367 else | |
1368 r = r->child; | |
1369 if (r) { | |
1370 while (r->next) | |
1371 r = r->next; | |
1372 bigbro = r->key; | |
1373 } | |
1374 } | |
1375 } | |
1376 row = gnt_tree_add_row_after(tree, key, row, parent, bigbro); | |
1377 row->choice = TRUE; | |
1378 | |
1379 return row; | |
1380 } | |
1381 | |
1382 void gnt_tree_set_choice(GntTree *tree, void *key, gboolean set) | |
1383 { | |
1384 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1385 | |
1386 if (!row) | |
1387 return; | |
1388 g_return_if_fail(row->choice); | |
1389 | |
1390 row->isselected = set; | |
1391 redraw_tree(tree); | |
1392 } | |
1393 | |
1394 gboolean gnt_tree_get_choice(GntTree *tree, void *key) | |
1395 { | |
1396 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1397 | |
1398 if (!row) | |
1399 return FALSE; | |
1400 g_return_val_if_fail(row->choice, FALSE); | |
1401 | |
1402 return row->isselected; | |
1403 } | |
1404 | |
1405 void gnt_tree_set_row_flags(GntTree *tree, void *key, GntTextFormatFlags flags) | |
1406 { | |
1407 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1408 if (!row || row->flags == flags) | |
1409 return; | |
1410 | |
1411 row->flags = flags; | |
1412 redraw_tree(tree); /* XXX: It shouldn't be necessary to redraw the whole darned tree */ | |
1413 } | |
1414 | |
1415 void gnt_tree_set_selected(GntTree *tree , void *key) | |
1416 { | |
1417 int dist; | |
1418 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
16203
4f6a6443a1e3
emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents:
16123
diff
changeset
|
1419 if (!row || row == tree->current) |
15817 | 1420 return; |
1421 | |
1422 if (tree->top == NULL) | |
1423 tree->top = row; | |
1424 if (tree->bottom == NULL) | |
1425 tree->bottom = row; | |
1426 | |
1427 tree->current = row; | |
1428 if ((dist = get_distance(tree->current, tree->bottom)) < 0) | |
1429 gnt_tree_scroll(tree, -dist); | |
1430 else if ((dist = get_distance(tree->current, tree->top)) > 0) | |
1431 gnt_tree_scroll(tree, -dist); | |
1432 else | |
1433 redraw_tree(tree); | |
16203
4f6a6443a1e3
emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents:
16123
diff
changeset
|
1434 tree_selection_changed(tree, row, tree->current); |
15817 | 1435 } |
1436 | |
1437 void _gnt_tree_init_internals(GntTree *tree, int col) | |
1438 { | |
1439 tree->ncol = col; | |
1440 tree->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_tree_row); | |
1441 tree->columns = g_new0(struct _GntTreeColInfo, col); | |
1442 while (col--) | |
1443 { | |
1444 tree->columns[col].width = 15; | |
1445 } | |
1446 tree->list = NULL; | |
1447 tree->show_title = FALSE; | |
1448 } | |
1449 | |
1450 GntWidget *gnt_tree_new_with_columns(int col) | |
1451 { | |
1452 GntWidget *widget = g_object_new(GNT_TYPE_TREE, NULL); | |
1453 GntTree *tree = GNT_TREE(widget); | |
1454 | |
1455 _gnt_tree_init_internals(tree, col); | |
1456 | |
1457 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW); | |
1458 gnt_widget_set_take_focus(widget, TRUE); | |
1459 | |
1460 return widget; | |
1461 } | |
1462 | |
1463 GntTreeRow *gnt_tree_create_row_from_list(GntTree *tree, GList *list) | |
1464 { | |
1465 GList *iter; | |
1466 int i; | |
1467 GntTreeRow *row = g_new0(GntTreeRow, 1); | |
1468 | |
1469 for (i = 0, iter = list; i < tree->ncol && iter; iter = iter->next, i++) | |
1470 { | |
1471 GntTreeCol *col = g_new0(GntTreeCol, 1); | |
1472 col->span = 1; | |
1473 col->text = g_strdup(iter->data ? iter->data : ""); | |
1474 | |
1475 row->columns = g_list_append(row->columns, col); | |
1476 } | |
1477 | |
1478 return row; | |
1479 } | |
1480 | |
1481 GntTreeRow *gnt_tree_create_row(GntTree *tree, ...) | |
1482 { | |
1483 int i; | |
1484 va_list args; | |
1485 GList *list = NULL; | |
1486 GntTreeRow *row; | |
1487 | |
1488 va_start(args, tree); | |
1489 for (i = 0; i < tree->ncol; i++) | |
1490 { | |
1491 list = g_list_append(list, va_arg(args, char *)); | |
1492 } | |
1493 va_end(args); | |
1494 | |
1495 row = gnt_tree_create_row_from_list(tree, list); | |
1496 g_list_free(list); | |
1497 | |
1498 return row; | |
1499 } | |
1500 | |
1501 void gnt_tree_set_col_width(GntTree *tree, int col, int width) | |
1502 { | |
1503 g_return_if_fail(col < tree->ncol); | |
1504 | |
1505 tree->columns[col].width = width; | |
1506 } | |
1507 | |
1508 void gnt_tree_set_column_titles(GntTree *tree, ...) | |
1509 { | |
1510 int i; | |
1511 va_list args; | |
1512 | |
1513 va_start(args, tree); | |
1514 for (i = 0; i < tree->ncol; i++) | |
1515 { | |
1516 const char *title = va_arg(args, const char *); | |
1517 tree->columns[i].title = g_strdup(title); | |
1518 } | |
1519 va_end(args); | |
1520 } | |
1521 | |
1522 void gnt_tree_set_show_title(GntTree *tree, gboolean set) | |
1523 { | |
1524 tree->show_title = set; | |
1525 GNT_WIDGET(tree)->priv.minh = (set ? 6 : 4); | |
1526 } | |
1527 | |
1528 void gnt_tree_set_compare_func(GntTree *tree, GCompareFunc func) | |
1529 { | |
1530 tree->compare = func; | |
1531 } | |
1532 | |
1533 void gnt_tree_set_expanded(GntTree *tree, void *key, gboolean expanded) | |
1534 { | |
1535 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1536 if (row) { | |
1537 row->collapsed = !expanded; | |
1538 if (GNT_WIDGET(tree)->window) | |
1539 gnt_widget_draw(GNT_WIDGET(tree)); | |
16203
4f6a6443a1e3
emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents:
16123
diff
changeset
|
1540 g_signal_emit(tree, signals[SIG_COLLAPSED], 0, key, row->collapsed); |
15817 | 1541 } |
1542 } | |
1543 | |
1544 void gnt_tree_set_show_separator(GntTree *tree, gboolean set) | |
1545 { | |
1546 tree->show_separator = set; | |
1547 } | |
1548 | |
1549 void gnt_tree_adjust_columns(GntTree *tree) | |
1550 { | |
1551 GntTreeRow *row = tree->root; | |
16123
bc280c341679
We don't need to do anything about the heights here.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16105
diff
changeset
|
1552 int *widths, i, twidth; |
15817 | 1553 |
1554 widths = g_new0(int, tree->ncol); | |
1555 while (row) { | |
1556 GList *iter; | |
1557 for (i = 0, iter = row->columns; iter; iter = iter->next, i++) { | |
1558 GntTreeCol *col = iter->data; | |
1559 int w = gnt_util_onscreen_width(col->text, NULL); | |
15968
0ab73bf1fef1
check-items are wider.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15928
diff
changeset
|
1560 if (i == 0 && row->choice) |
0ab73bf1fef1
check-items are wider.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15928
diff
changeset
|
1561 w += 4; |
15972
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
1562 if (i == 0) { |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
1563 w += find_depth(row) * TAB_SIZE; |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
1564 } |
15817 | 1565 if (widths[i] < w) |
1566 widths[i] = w; | |
1567 } | |
15972
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
1568 row = get_next(row); |
15817 | 1569 } |
1570 | |
1571 twidth = 1 + 2 * (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER)); | |
1572 for (i = 0; i < tree->ncol; i++) { | |
1573 gnt_tree_set_col_width(tree, i, widths[i]); | |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
1574 if (!tree->columns[i].invisible) |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
1575 twidth += widths[i] + (tree->show_separator ? 1 : 0) + 1; |
15817 | 1576 } |
1577 g_free(widths); | |
1578 | |
16123
bc280c341679
We don't need to do anything about the heights here.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16105
diff
changeset
|
1579 gnt_widget_set_size(GNT_WIDGET(tree), twidth, -1); |
15817 | 1580 } |
1581 | |
1582 void gnt_tree_set_hash_fns(GntTree *tree, gpointer hash, gpointer eq, gpointer kd) | |
1583 { | |
1584 g_hash_table_foreach_remove(tree->hash, return_true, NULL); | |
1585 g_hash_table_destroy(tree->hash); | |
1586 tree->hash = g_hash_table_new_full(hash, eq, kd, free_tree_row); | |
1587 } | |
1588 | |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
1589 void gnt_tree_set_column_visible(GntTree *tree, int col, gboolean vis) |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
1590 { |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
1591 g_return_if_fail(col < tree->ncol); |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
1592 tree->columns[col].invisible = !vis; |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
1593 } |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
1594 |