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