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