Mercurial > pidgin.yaz
annotate finch/libgnt/gnttree.c @ 18521:c36b62c6e0b3
Convert portable winpidgin launcher executable to be the same binary as pidgin.exe and determine which behavior to use at runtime. Running "pidgin.exe --portable-mode" or renaming "pidgin.exe" to "pidgin-portable.exe" will cause the portable mode to be used.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Fri, 13 Jul 2007 18:03:45 +0000 |
parents | ed17f5530300 |
children | da550279d390 |
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) |
18449
ed17f5530300
Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
36 #define RIGHT_ALIGNED(tree, index) (tree->columns[index].flags & GNT_TREE_COLUMN_RIGHT_ALIGNED) |
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
|
37 |
15818 | 38 enum |
39 { | |
40 SIG_SELECTION_CHANGED, | |
41 SIG_SCROLLED, | |
42 SIG_TOGGLED, | |
16105
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
43 SIG_COLLAPSED, |
15818 | 44 SIGS, |
45 }; | |
46 | |
47 #define TAB_SIZE 3 | |
48 | |
49 /* XXX: Make this one into a GObject? | |
50 * ... Probably not */ | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
51 struct _GntTreeRow |
15818 | 52 { |
53 void *key; | |
54 void *data; /* XXX: unused */ | |
55 | |
56 gboolean collapsed; | |
57 gboolean choice; /* Is this a choice-box? | |
58 If choice is true, then child will be NULL */ | |
59 gboolean isselected; | |
60 GntTextFormatFlags flags; | |
61 | |
62 GntTreeRow *parent; | |
63 GntTreeRow *child; | |
64 GntTreeRow *next; | |
65 GntTreeRow *prev; | |
66 | |
67 GList *columns; | |
68 GntTree *tree; | |
69 }; | |
70 | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
71 struct _GntTreeCol |
15818 | 72 { |
73 char *text; | |
18420
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
74 gboolean isbinary; |
15818 | 75 int span; /* How many columns does it span? */ |
76 }; | |
77 | |
16203
4f6a6443a1e3
emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents:
16123
diff
changeset
|
78 static void tree_selection_changed(GntTree *, GntTreeRow *, GntTreeRow *); |
4f6a6443a1e3
emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents:
16123
diff
changeset
|
79 |
15818 | 80 static GntWidgetClass *parent_class = NULL; |
81 static guint signals[SIGS] = { 0 }; | |
82 | |
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
|
83 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
|
84 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
|
85 { |
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 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
|
87 int width; |
18405
69cc1a4ef6ab
Parentheses helps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
88 #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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 else |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
98 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
|
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 |
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 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
|
102 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
|
103 |
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 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 else |
18405
69cc1a4ef6ab
Parentheses helps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
110 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
|
111 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
|
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 } |
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
|
114 |
15818 | 115 /* Move the item at position old to position new */ |
116 static GList * | |
117 g_list_reposition_child(GList *list, int old, int new) | |
118 { | |
119 gpointer item = g_list_nth_data(list, old); | |
120 list = g_list_remove(list, item); | |
121 if (old < new) | |
122 new--; /* because the positions would have shifted after removing the item */ | |
123 list = g_list_insert(list, item, new); | |
124 return list; | |
125 } | |
126 | |
127 static GntTreeRow * | |
128 _get_next(GntTreeRow *row, gboolean godeep) | |
129 { | |
130 if (row == NULL) | |
131 return NULL; | |
132 if (godeep && row->child) | |
133 return row->child; | |
134 if (row->next) | |
135 return row->next; | |
136 return _get_next(row->parent, FALSE); | |
137 } | |
138 | |
139 static gboolean | |
140 row_matches_search(GntTreeRow *row) | |
141 { | |
142 GntTree *t = row->tree; | |
143 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
|
144 /* 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
|
145 * doesn't contain binary data. */ |
15818 | 146 char *one = g_utf8_casefold(((GntTreeCol*)row->columns->data)->text, -1); |
147 char *two = g_utf8_casefold(t->search->str, -1); | |
148 char *z = strstr(one, two); | |
149 g_free(one); | |
150 g_free(two); | |
151 if (z == NULL) | |
152 return FALSE; | |
153 } | |
154 return TRUE; | |
155 } | |
156 | |
157 static GntTreeRow * | |
158 get_next(GntTreeRow *row) | |
159 { | |
160 if (row == NULL) | |
161 return NULL; | |
162 while ((row = _get_next(row, !row->collapsed)) != NULL) { | |
163 if (row_matches_search(row)) | |
164 break; | |
165 } | |
166 return row; | |
167 } | |
168 | |
169 /* Returns the n-th next row. If it doesn't exist, returns NULL */ | |
170 static GntTreeRow * | |
171 get_next_n(GntTreeRow *row, int n) | |
172 { | |
173 while (row && n--) | |
174 row = get_next(row); | |
175 return row; | |
176 } | |
177 | |
178 /* Returns the n-th next row. If it doesn't exist, then the last non-NULL node */ | |
179 static GntTreeRow * | |
180 get_next_n_opt(GntTreeRow *row, int n, int *pos) | |
181 { | |
182 GntTreeRow *next = row; | |
183 int r = 0; | |
184 | |
185 if (row == NULL) | |
186 return NULL; | |
187 | |
188 while (row && n--) | |
189 { | |
190 row = get_next(row); | |
191 if (row) | |
192 { | |
193 next = row; | |
194 r++; | |
195 } | |
196 } | |
197 | |
198 if (pos) | |
199 *pos = r; | |
200 | |
201 return next; | |
202 } | |
203 | |
204 static GntTreeRow * | |
205 get_last_child(GntTreeRow *row) | |
206 { | |
207 if (row == NULL) | |
208 return NULL; | |
209 if (!row->collapsed && row->child) | |
210 row = row->child; | |
211 else | |
212 return row; | |
213 | |
214 while(row->next) | |
215 row = row->next; | |
16585
467698ab6bf0
Fix an odd selection issue when moving up.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16283
diff
changeset
|
216 return get_last_child(row); |
15818 | 217 } |
218 | |
219 static GntTreeRow * | |
220 get_prev(GntTreeRow *row) | |
221 { | |
222 if (row == NULL) | |
223 return NULL; | |
224 while (row) { | |
225 if (row->prev) | |
226 row = get_last_child(row->prev); | |
227 else | |
228 row = row->parent; | |
229 if (!row || row_matches_search(row)) | |
230 break; | |
231 } | |
232 return row; | |
233 } | |
234 | |
235 static GntTreeRow * | |
236 get_prev_n(GntTreeRow *row, int n) | |
237 { | |
238 while (row && n--) | |
239 row = get_prev(row); | |
240 return row; | |
241 } | |
242 | |
243 /* Distance of row from the root */ | |
244 /* XXX: This is uber-inefficient */ | |
245 static int | |
246 get_root_distance(GntTreeRow *row) | |
247 { | |
248 if (row == NULL) | |
249 return -1; | |
250 return get_root_distance(get_prev(row)) + 1; | |
251 } | |
252 | |
253 /* Returns the distance between a and b. | |
254 * If a is 'above' b, then the distance is positive */ | |
255 static int | |
256 get_distance(GntTreeRow *a, GntTreeRow *b) | |
257 { | |
258 /* First get the distance from a to the root. | |
259 * Then the distance from b to the root. | |
260 * Subtract. | |
261 * It's not that good, but it works. */ | |
262 int ha = get_root_distance(a); | |
263 int hb = get_root_distance(b); | |
264 | |
265 return (hb - ha); | |
266 } | |
267 | |
268 static int | |
269 find_depth(GntTreeRow *row) | |
270 { | |
271 int dep = -1; | |
272 | |
273 while (row) | |
274 { | |
275 dep++; | |
276 row = row->parent; | |
277 } | |
278 | |
279 return dep; | |
280 } | |
281 | |
282 static char * | |
283 update_row_text(GntTree *tree, GntTreeRow *row) | |
284 { | |
285 GString *string = g_string_new(NULL); | |
286 GList *iter; | |
287 int i; | |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
288 gboolean notfirst = FALSE; |
15818 | 289 |
290 for (i = 0, iter = row->columns; i < tree->ncol && iter; i++, iter = iter->next) | |
291 { | |
292 GntTreeCol *col = iter->data; | |
293 const char *text; | |
18420
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
294 int len; |
15818 | 295 int fl = 0; |
296 gboolean cut = FALSE; | |
15971
05d347516fcd
Fine tune column hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15970
diff
changeset
|
297 int width; |
18420
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
298 const char *display; |
15818 | 299 |
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
|
300 if (COLUMN_INVISIBLE(tree, i)) |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
301 continue; |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
302 |
18420
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
303 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
|
304 display = ""; |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
305 else |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
306 display = col->text; |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
307 |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
308 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
|
309 |
18449
ed17f5530300
Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
310 width = tree->columns[i].width; |
15971
05d347516fcd
Fine tune column hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15970
diff
changeset
|
311 |
15818 | 312 if (i == 0) |
313 { | |
314 if (row->choice) | |
315 { | |
316 g_string_append_printf(string, "[%c] ", | |
317 row->isselected ? 'X' : ' '); | |
318 fl = 4; | |
319 } | |
320 else if (row->parent == NULL && row->child) | |
321 { | |
322 if (row->collapsed) | |
323 { | |
324 string = g_string_append(string, "+ "); | |
325 } | |
326 else | |
327 { | |
328 string = g_string_append(string, "- "); | |
329 } | |
330 fl = 2; | |
331 } | |
332 else | |
333 { | |
334 fl = TAB_SIZE * find_depth(row); | |
335 g_string_append_printf(string, "%*s", fl, ""); | |
336 } | |
337 len += fl; | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
338 } else if (notfirst && tree->show_separator) |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
339 g_string_append_c(string, '|'); |
15818 | 340 else |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
341 g_string_append_c(string, ' '); |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
342 |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
343 notfirst = TRUE; |
15818 | 344 |
18183
99969affedf5
I think this fixes the ellipsization in the trees.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18118
diff
changeset
|
345 if (len > width) { |
15971
05d347516fcd
Fine tune column hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15970
diff
changeset
|
346 len = width - 1; |
15818 | 347 cut = TRUE; |
348 } | |
18449
ed17f5530300
Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
349 |
ed17f5530300
Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
350 if (RIGHT_ALIGNED(tree, i) && len < tree->columns[i].width) { |
ed17f5530300
Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
351 g_string_append_printf(string, "%*s", width - len, ""); |
ed17f5530300
Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
352 } |
ed17f5530300
Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
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); |
15818 | 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 | |
18449
ed17f5530300
Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
364 if (!RIGHT_ALIGNED(tree, i) && 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, ""); |
15818 | 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 |
15818 | 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; |
15818 | 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); |
15818 | 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) { |
15818 | 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 } |
15818 | 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 |
15818 | 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; |
15818 | 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 |
15818 | 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; | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
601 width = 1 + 2 * (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER)); |
15818 | 602 for (i = 0; i < tree->ncol; i++) |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
603 if (!COLUMN_INVISIBLE(tree, i)) { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
604 width = width + tree->columns[i].width; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
605 if (tree->lastvisible != i) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
606 width++; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
607 } |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
608 widget->priv.width = width; |
15818 | 609 } |
610 } | |
611 | |
612 static void | |
613 gnt_tree_map(GntWidget *widget) | |
614 { | |
615 GntTree *tree = GNT_TREE(widget); | |
616 if (widget->priv.width == 0 || widget->priv.height == 0) | |
617 { | |
618 gnt_widget_size_request(widget); | |
619 } | |
620 tree->top = tree->root; | |
621 tree->current = tree->root; | |
622 GNTDEBUG; | |
623 } | |
624 | |
625 static void | |
626 tree_selection_changed(GntTree *tree, GntTreeRow *old, GntTreeRow *current) | |
627 { | |
628 g_signal_emit(tree, signals[SIG_SELECTION_CHANGED], 0, old ? old->key : NULL, | |
629 current ? current->key : NULL); | |
630 } | |
631 | |
632 static gboolean | |
633 action_down(GntBindable *bind, GList *null) | |
634 { | |
635 int dist; | |
636 GntTree *tree = GNT_TREE(bind); | |
637 GntTreeRow *old = tree->current; | |
638 GntTreeRow *row = get_next(tree->current); | |
639 if (row == NULL) | |
640 return FALSE; | |
641 tree->current = row; | |
642 if ((dist = get_distance(tree->current, tree->bottom)) < 0) | |
643 gnt_tree_scroll(tree, -dist); | |
644 else | |
645 redraw_tree(tree); | |
646 if (old != tree->current) | |
647 tree_selection_changed(tree, old, tree->current); | |
648 return TRUE; | |
649 } | |
650 | |
651 static gboolean | |
15972
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
652 action_move_parent(GntBindable *bind, GList *null) |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
653 { |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
654 GntTree *tree = GNT_TREE(bind); |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
655 GntTreeRow *row = tree->current; |
16249
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
656 int dist; |
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 if (!row->parent || SEARCHING(tree)) |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
659 return FALSE; |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
660 |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
661 tree->current = row->parent; |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
662 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
|
663 gnt_tree_scroll(tree, -dist); |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
664 else |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
665 redraw_tree(tree); |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
666 tree_selection_changed(tree, row, tree->current); |
15972
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
667 return TRUE; |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
668 } |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
669 |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
670 static gboolean |
15818 | 671 action_up(GntBindable *bind, GList *list) |
672 { | |
673 int dist; | |
674 GntTree *tree = GNT_TREE(bind); | |
675 GntTreeRow *old = tree->current; | |
676 GntTreeRow *row = get_prev(tree->current); | |
677 if (!row) | |
678 return FALSE; | |
679 tree->current = row; | |
680 if ((dist = get_distance(tree->current, tree->top)) > 0) | |
681 gnt_tree_scroll(tree, -dist); | |
682 else | |
683 redraw_tree(tree); | |
684 if (old != tree->current) | |
685 tree_selection_changed(tree, old, tree->current); | |
686 | |
687 return TRUE; | |
688 } | |
689 | |
690 static gboolean | |
691 action_page_down(GntBindable *bind, GList *null) | |
692 { | |
693 GntTree *tree = GNT_TREE(bind); | |
694 GntTreeRow *old = tree->current; | |
695 GntTreeRow *row = get_next(tree->bottom); | |
696 if (row) | |
697 { | |
698 int dist = get_distance(tree->top, tree->current); | |
699 tree->top = tree->bottom; | |
700 tree->current = get_next_n_opt(tree->top, dist, NULL); | |
701 redraw_tree(tree); | |
702 } | |
703 else if (tree->current != tree->bottom) | |
704 { | |
705 tree->current = tree->bottom; | |
706 redraw_tree(tree); | |
707 } | |
708 | |
709 if (old != tree->current) | |
710 tree_selection_changed(tree, old, tree->current); | |
711 return TRUE; | |
712 } | |
713 | |
714 static gboolean | |
715 action_page_up(GntBindable *bind, GList *null) | |
716 { | |
717 GntWidget *widget = GNT_WIDGET(bind); | |
718 GntTree *tree = GNT_TREE(bind); | |
719 GntTreeRow *row; | |
720 GntTreeRow *old = tree->current; | |
721 | |
722 if (tree->top != tree->root) | |
723 { | |
724 int dist = get_distance(tree->top, tree->current); | |
725 row = get_prev_n(tree->top, widget->priv.height - 1 - | |
726 tree->show_title * 2 - 2 * (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER) == 0)); | |
727 if (row == NULL) | |
728 row = tree->root; | |
729 tree->top = row; | |
730 tree->current = get_next_n_opt(tree->top, dist, NULL); | |
731 redraw_tree(tree); | |
732 } | |
733 else if (tree->current != tree->top) | |
734 { | |
735 tree->current = tree->top; | |
736 redraw_tree(tree); | |
737 } | |
738 if (old != tree->current) | |
739 tree_selection_changed(tree, old, tree->current); | |
740 return TRUE; | |
741 } | |
742 | |
743 static void | |
744 end_search(GntTree *tree) | |
745 { | |
746 if (tree->search) { | |
747 g_source_remove(tree->search_timeout); | |
748 g_string_free(tree->search, TRUE); | |
749 tree->search = NULL; | |
750 tree->search_timeout = 0; | |
751 } | |
752 } | |
753 | |
754 static gboolean | |
755 search_timeout(gpointer data) | |
756 { | |
757 GntTree *tree = data; | |
758 | |
759 end_search(tree); | |
760 redraw_tree(tree); | |
761 | |
762 return FALSE; | |
763 } | |
764 | |
765 static gboolean | |
766 gnt_tree_key_pressed(GntWidget *widget, const char *text) | |
767 { | |
768 GntTree *tree = GNT_TREE(widget); | |
769 GntTreeRow *old = tree->current; | |
770 | |
771 if (text[0] == '\r') { | |
772 end_search(tree); | |
773 gnt_widget_activate(widget); | |
774 } else if (tree->search) { | |
16249
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
775 gboolean changed = TRUE; |
15818 | 776 if (isalnum(*text)) { |
777 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
|
778 } 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
|
779 if (tree->search->len) |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
780 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
|
781 } else |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
782 changed = FALSE; |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
783 if (changed) { |
15818 | 784 redraw_tree(tree); |
785 g_source_remove(tree->search_timeout); | |
786 tree->search_timeout = g_timeout_add(SEARCH_TIMEOUT, search_timeout, tree); | |
787 } | |
788 return TRUE; | |
789 } else if (text[0] == ' ' && text[1] == 0) { | |
790 /* Space pressed */ | |
791 GntTreeRow *row = tree->current; | |
792 if (row && row->child) | |
793 { | |
794 row->collapsed = !row->collapsed; | |
795 redraw_tree(tree); | |
16105
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
796 g_signal_emit(tree, signals[SIG_COLLAPSED], 0, row->key, row->collapsed); |
15818 | 797 } |
798 else if (row && row->choice) | |
799 { | |
800 row->isselected = !row->isselected; | |
801 g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key); | |
802 redraw_tree(tree); | |
803 } | |
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
|
804 } 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
|
805 return FALSE; |
15818 | 806 } |
807 | |
808 if (old != tree->current) | |
809 { | |
810 tree_selection_changed(tree, old, tree->current); | |
811 } | |
812 | |
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
|
813 return TRUE; |
15818 | 814 } |
815 | |
816 static void | |
817 gnt_tree_destroy(GntWidget *widget) | |
818 { | |
819 GntTree *tree = GNT_TREE(widget); | |
820 int i; | |
821 | |
822 end_search(tree); | |
823 if (tree->hash) | |
824 g_hash_table_destroy(tree->hash); | |
825 g_list_free(tree->list); | |
826 | |
827 for (i = 0; i < tree->ncol; i++) | |
828 { | |
829 g_free(tree->columns[i].title); | |
830 } | |
831 g_free(tree->columns); | |
832 } | |
833 | |
834 static gboolean | |
835 gnt_tree_clicked(GntWidget *widget, GntMouseEvent event, int x, int y) | |
836 { | |
837 GntTree *tree = GNT_TREE(widget); | |
838 GntTreeRow *old = tree->current; | |
839 if (event == GNT_MOUSE_SCROLL_UP) { | |
840 action_up(GNT_BINDABLE(widget), NULL); | |
841 } else if (event == GNT_MOUSE_SCROLL_DOWN) { | |
842 action_down(GNT_BINDABLE(widget), NULL); | |
843 } else if (event == GNT_LEFT_MOUSE_DOWN) { | |
844 GntTreeRow *row; | |
845 GntTree *tree = GNT_TREE(widget); | |
846 int pos = 1; | |
847 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
848 pos = 0; | |
849 if (tree->show_title) | |
850 pos += 2; | |
851 pos = y - widget->priv.y - pos; | |
852 row = get_next_n(tree->top, pos); | |
853 if (row && tree->current != row) { | |
854 GntTreeRow *old = tree->current; | |
855 tree->current = row; | |
856 redraw_tree(tree); | |
857 tree_selection_changed(tree, old, tree->current); | |
858 } else if (row && row == tree->current) { | |
859 if (row->choice) { | |
860 row->isselected = !row->isselected; | |
861 g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key); | |
862 redraw_tree(tree); | |
863 } else { | |
864 gnt_widget_activate(widget); | |
865 } | |
866 } | |
867 } else { | |
868 return FALSE; | |
869 } | |
870 if (old != tree->current) { | |
871 tree_selection_changed(tree, old, tree->current); | |
872 } | |
873 return TRUE; | |
874 } | |
875 | |
876 static void | |
877 gnt_tree_size_changed(GntWidget *widget, int w, int h) | |
878 { | |
879 GntTree *tree = GNT_TREE(widget); | |
880 if (widget->priv.width <= 0) | |
881 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
|
882 |
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
|
883 readjust_columns(tree); |
15818 | 884 } |
885 | |
886 static gboolean | |
887 start_search(GntBindable *bindable, GList *list) | |
888 { | |
889 GntTree *tree = GNT_TREE(bindable); | |
890 if (tree->search) | |
891 return FALSE; | |
892 tree->search = g_string_new(NULL); | |
893 tree->search_timeout = g_timeout_add(SEARCH_TIMEOUT, search_timeout, tree); | |
894 return TRUE; | |
895 } | |
896 | |
897 static gboolean | |
898 end_search_action(GntBindable *bindable, GList *list) | |
899 { | |
900 GntTree *tree = GNT_TREE(bindable); | |
901 if (tree->search == NULL) | |
902 return FALSE; | |
903 end_search(tree); | |
904 redraw_tree(tree); | |
905 return TRUE; | |
906 } | |
907 | |
908 static void | |
909 gnt_tree_class_init(GntTreeClass *klass) | |
910 { | |
911 GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass); | |
912 parent_class = GNT_WIDGET_CLASS(klass); | |
913 parent_class->destroy = gnt_tree_destroy; | |
914 parent_class->draw = gnt_tree_draw; | |
915 parent_class->map = gnt_tree_map; | |
916 parent_class->size_request = gnt_tree_size_request; | |
917 parent_class->key_pressed = gnt_tree_key_pressed; | |
918 parent_class->clicked = gnt_tree_clicked; | |
919 parent_class->size_changed = gnt_tree_size_changed; | |
920 | |
921 signals[SIG_SELECTION_CHANGED] = | |
922 g_signal_new("selection-changed", | |
923 G_TYPE_FROM_CLASS(klass), | |
924 G_SIGNAL_RUN_LAST, | |
925 G_STRUCT_OFFSET(GntTreeClass, selection_changed), | |
926 NULL, NULL, | |
927 gnt_closure_marshal_VOID__POINTER_POINTER, | |
928 G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER); | |
929 signals[SIG_SCROLLED] = | |
930 g_signal_new("scrolled", | |
931 G_TYPE_FROM_CLASS(klass), | |
932 G_SIGNAL_RUN_LAST, | |
933 0, | |
934 NULL, NULL, | |
935 g_cclosure_marshal_VOID__INT, | |
936 G_TYPE_NONE, 1, G_TYPE_INT); | |
937 signals[SIG_TOGGLED] = | |
938 g_signal_new("toggled", | |
939 G_TYPE_FROM_CLASS(klass), | |
940 G_SIGNAL_RUN_LAST, | |
941 G_STRUCT_OFFSET(GntTreeClass, toggled), | |
942 NULL, NULL, | |
943 g_cclosure_marshal_VOID__POINTER, | |
944 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
|
945 signals[SIG_COLLAPSED] = |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
946 g_signal_new("collapse-toggled", |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
947 G_TYPE_FROM_CLASS(klass), |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
948 G_SIGNAL_RUN_LAST, |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
949 0, |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
950 NULL, NULL, |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
951 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
|
952 G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_BOOLEAN); |
15818 | 953 |
954 gnt_bindable_class_register_action(bindable, "move-up", action_up, | |
955 GNT_KEY_UP, NULL); | |
956 gnt_bindable_register_binding(bindable, "move-up", GNT_KEY_CTRL_P, NULL); | |
957 gnt_bindable_class_register_action(bindable, "move-down", action_down, | |
958 GNT_KEY_DOWN, NULL); | |
959 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
|
960 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
|
961 GNT_KEY_BACKSPACE, NULL); |
15818 | 962 gnt_bindable_class_register_action(bindable, "page-up", action_page_up, |
963 GNT_KEY_PGUP, NULL); | |
964 gnt_bindable_class_register_action(bindable, "page-down", action_page_down, | |
965 GNT_KEY_PGDOWN, NULL); | |
966 gnt_bindable_class_register_action(bindable, "start-search", start_search, | |
967 "/", NULL); | |
968 gnt_bindable_class_register_action(bindable, "end-search", end_search_action, | |
969 "\033", NULL); | |
970 | |
971 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), bindable); | |
972 GNTDEBUG; | |
973 } | |
974 | |
975 static void | |
976 gnt_tree_init(GTypeInstance *instance, gpointer class) | |
977 { | |
978 GntWidget *widget = GNT_WIDGET(instance); | |
979 GntTree *tree = GNT_TREE(widget); | |
980 tree->show_separator = TRUE; | |
981 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y); | |
982 widget->priv.minw = 4; | |
983 widget->priv.minh = 1; | |
984 GNTDEBUG; | |
985 } | |
986 | |
987 /****************************************************************************** | |
988 * GntTree API | |
989 *****************************************************************************/ | |
990 GType | |
991 gnt_tree_get_gtype(void) | |
992 { | |
993 static GType type = 0; | |
994 | |
995 if(type == 0) | |
996 { | |
997 static const GTypeInfo info = { | |
998 sizeof(GntTreeClass), | |
999 NULL, /* base_init */ | |
1000 NULL, /* base_finalize */ | |
1001 (GClassInitFunc)gnt_tree_class_init, | |
1002 NULL, /* class_finalize */ | |
1003 NULL, /* class_data */ | |
1004 sizeof(GntTree), | |
1005 0, /* n_preallocs */ | |
1006 gnt_tree_init, /* instance_init */ | |
1007 NULL /* value_table */ | |
1008 }; | |
1009 | |
1010 type = g_type_register_static(GNT_TYPE_WIDGET, | |
1011 "GntTree", | |
1012 &info, 0); | |
1013 } | |
1014 | |
1015 return type; | |
1016 } | |
1017 | |
1018 static void | |
1019 free_tree_col(gpointer data) | |
1020 { | |
1021 GntTreeCol *col = data; | |
18420
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1022 if (col->isbinary) |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1023 g_free(col->text); |
15818 | 1024 g_free(col); |
1025 } | |
1026 | |
1027 static void | |
1028 free_tree_row(gpointer data) | |
1029 { | |
1030 GntTreeRow *row = data; | |
1031 | |
1032 if (!row) | |
1033 return; | |
1034 | |
1035 g_list_foreach(row->columns, (GFunc)free_tree_col, NULL); | |
1036 g_list_free(row->columns); | |
1037 g_free(row); | |
1038 } | |
1039 | |
1040 GntWidget *gnt_tree_new() | |
1041 { | |
1042 return gnt_tree_new_with_columns(1); | |
1043 } | |
1044 | |
1045 void gnt_tree_set_visible_rows(GntTree *tree, int rows) | |
1046 { | |
1047 GntWidget *widget = GNT_WIDGET(tree); | |
1048 widget->priv.height = rows; | |
1049 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
1050 widget->priv.height += 2; | |
1051 } | |
1052 | |
1053 int gnt_tree_get_visible_rows(GntTree *tree) | |
1054 { | |
1055 GntWidget *widget = GNT_WIDGET(tree); | |
1056 int ret = widget->priv.height; | |
1057 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
1058 ret -= 2; | |
1059 return ret; | |
1060 } | |
1061 | |
18118
ab6d2763b8d8
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@wiktel.com>
parents:
18098
diff
changeset
|
1062 GList *gnt_tree_get_rows(GntTree *tree) |
15818 | 1063 { |
1064 return tree->list; | |
1065 } | |
1066 | |
1067 void gnt_tree_scroll(GntTree *tree, int count) | |
1068 { | |
1069 GntTreeRow *row; | |
1070 | |
1071 if (count < 0) | |
1072 { | |
1073 if (get_root_distance(tree->top) == 0) | |
1074 return; | |
1075 row = get_prev_n(tree->top, -count); | |
1076 if (row == NULL) | |
1077 row = tree->root; | |
1078 tree->top = row; | |
1079 } | |
1080 else | |
1081 { | |
1082 get_next_n_opt(tree->bottom, count, &count); | |
1083 tree->top = get_next_n(tree->top, count); | |
1084 } | |
1085 | |
1086 redraw_tree(tree); | |
1087 g_signal_emit(tree, signals[SIG_SCROLLED], 0, count); | |
1088 } | |
1089 | |
1090 static gpointer | |
1091 find_position(GntTree *tree, gpointer key, gpointer parent) | |
1092 { | |
1093 GntTreeRow *row; | |
1094 | |
1095 if (tree->compare == NULL) | |
1096 return NULL; | |
1097 | |
1098 if (parent == NULL) | |
1099 row = tree->root; | |
1100 else | |
1101 row = g_hash_table_lookup(tree->hash, parent); | |
1102 | |
1103 if (!row) | |
1104 return NULL; | |
1105 | |
1106 if (parent) | |
1107 row = row->child; | |
1108 | |
1109 while (row) | |
1110 { | |
1111 if (tree->compare(key, row->key) < 0) | |
1112 return (row->prev ? row->prev->key : NULL); | |
1113 if (row->next) | |
1114 row = row->next; | |
1115 else | |
1116 return row->key; | |
1117 } | |
1118 return NULL; | |
1119 } | |
1120 | |
1121 void gnt_tree_sort_row(GntTree *tree, gpointer key) | |
1122 { | |
1123 GntTreeRow *row, *q, *s; | |
1124 int current, newp; | |
1125 | |
1126 if (!tree->compare) | |
1127 return; | |
1128 | |
1129 row = g_hash_table_lookup(tree->hash, key); | |
1130 g_return_if_fail(row != NULL); | |
1131 | |
1132 current = g_list_index(tree->list, key); | |
1133 | |
1134 if (row->parent) | |
1135 s = row->parent->child; | |
1136 else | |
1137 s = tree->root; | |
1138 | |
1139 q = NULL; | |
1140 while (s) { | |
1141 if (tree->compare(row->key, s->key) < 0) | |
1142 break; | |
1143 q = s; | |
1144 s = s->next; | |
1145 } | |
1146 | |
1147 /* Move row between q and s */ | |
1148 if (row == q || row == s) | |
1149 return; | |
1150 | |
1151 if (q == NULL) { | |
1152 /* row becomes the first child of its parent */ | |
1153 row->prev->next = row->next; /* row->prev cannot be NULL at this point */ | |
1154 if (row->next) | |
1155 row->next->prev = row->prev; | |
1156 if (row->parent) | |
1157 row->parent->child = row; | |
1158 else | |
1159 tree->root = row; | |
1160 row->next = s; | |
1161 s->prev = row; /* s cannot be NULL */ | |
1162 row->prev = NULL; | |
1163 newp = g_list_index(tree->list, s) - 1; | |
1164 } else { | |
1165 if (row->prev) { | |
1166 row->prev->next = row->next; | |
1167 } else { | |
1168 /* row was the first child of its parent */ | |
1169 if (row->parent) | |
1170 row->parent->child = row->next; | |
1171 else | |
1172 tree->top = row->next; | |
1173 } | |
1174 | |
1175 if (row->next) | |
1176 row->next->prev = row->prev; | |
1177 | |
1178 q->next = row; | |
1179 row->prev = q; | |
1180 if (s) | |
1181 s->prev = row; | |
1182 row->next = s; | |
1183 newp = g_list_index(tree->list, q) + 1; | |
1184 } | |
1185 tree->list = g_list_reposition_child(tree->list, current, newp); | |
1186 | |
1187 redraw_tree(tree); | |
1188 } | |
1189 | |
1190 GntTreeRow *gnt_tree_add_row_after(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro) | |
1191 { | |
1192 GntTreeRow *pr = NULL; | |
1193 | |
1194 g_hash_table_replace(tree->hash, key, row); | |
1195 row->tree = tree; | |
1196 | |
1197 if (bigbro == NULL && tree->compare) | |
1198 { | |
1199 bigbro = find_position(tree, key, parent); | |
1200 } | |
1201 | |
1202 if (tree->root == NULL) | |
1203 { | |
1204 tree->root = row; | |
1205 tree->list = g_list_prepend(tree->list, key); | |
1206 } | |
1207 else | |
1208 { | |
1209 int position = 0; | |
1210 | |
1211 if (bigbro) | |
1212 { | |
1213 pr = g_hash_table_lookup(tree->hash, bigbro); | |
1214 if (pr) | |
1215 { | |
1216 if (pr->next) pr->next->prev = row; | |
1217 row->next = pr->next; | |
1218 row->prev = pr; | |
1219 pr->next = row; | |
1220 row->parent = pr->parent; | |
1221 | |
1222 position = g_list_index(tree->list, bigbro); | |
1223 } | |
1224 } | |
1225 | |
1226 if (pr == NULL && parent) | |
1227 { | |
1228 pr = g_hash_table_lookup(tree->hash, parent); | |
1229 if (pr) | |
1230 { | |
1231 if (pr->child) pr->child->prev = row; | |
1232 row->next = pr->child; | |
1233 pr->child = row; | |
1234 row->parent = pr; | |
1235 | |
1236 position = g_list_index(tree->list, parent); | |
1237 } | |
1238 } | |
1239 | |
1240 if (pr == NULL) | |
1241 { | |
1242 GntTreeRow *r = tree->root; | |
1243 row->next = r; | |
1244 if (r) r->prev = row; | |
1245 if (tree->current == tree->root) | |
1246 tree->current = row; | |
1247 tree->root = row; | |
1248 tree->list = g_list_prepend(tree->list, key); | |
1249 } | |
1250 else | |
1251 { | |
1252 tree->list = g_list_insert(tree->list, key, position + 1); | |
1253 } | |
1254 } | |
1255 | |
1256 row->key = key; | |
1257 row->data = NULL; | |
1258 | |
1259 redraw_tree(tree); | |
1260 | |
1261 return row; | |
1262 } | |
1263 | |
1264 GntTreeRow *gnt_tree_add_row_last(GntTree *tree, void *key, GntTreeRow *row, void *parent) | |
1265 { | |
1266 GntTreeRow *pr = NULL, *br = NULL; | |
1267 | |
1268 if (parent) | |
1269 pr = g_hash_table_lookup(tree->hash, parent); | |
1270 | |
1271 if (pr) | |
1272 br = pr->child; | |
1273 else | |
1274 br = tree->root; | |
1275 | |
1276 if (br) | |
1277 { | |
1278 while (br->next) | |
1279 br = br->next; | |
1280 } | |
1281 | |
1282 return gnt_tree_add_row_after(tree, key, row, parent, br ? br->key : NULL); | |
1283 } | |
1284 | |
1285 gpointer gnt_tree_get_selection_data(GntTree *tree) | |
1286 { | |
1287 if (tree->current) | |
1288 return tree->current->key; /* XXX: perhaps we should just get rid of 'data' */ | |
1289 return NULL; | |
1290 } | |
1291 | |
1292 char *gnt_tree_get_selection_text(GntTree *tree) | |
1293 { | |
1294 if (tree->current) | |
1295 return update_row_text(tree, tree->current); | |
1296 return NULL; | |
1297 } | |
1298 | |
1299 GList *gnt_tree_get_selection_text_list(GntTree *tree) | |
1300 { | |
1301 GList *list = NULL, *iter; | |
1302 int i; | |
1303 | |
1304 if (!tree->current) | |
1305 return NULL; | |
1306 | |
1307 for (i = 0, iter = tree->current->columns; i < tree->ncol && iter; | |
1308 i++, iter = iter->next) | |
1309 { | |
1310 GntTreeCol *col = iter->data; | |
1311 list = g_list_append(list, g_strdup(col->text)); | |
1312 } | |
1313 | |
1314 return list; | |
1315 } | |
1316 | |
1317 void gnt_tree_remove(GntTree *tree, gpointer key) | |
1318 { | |
1319 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1320 static int depth = 0; /* Only redraw after all child nodes are removed */ | |
1321 if (row) | |
1322 { | |
1323 gboolean redraw = FALSE; | |
1324 | |
1325 if (row->child) { | |
1326 depth++; | |
1327 while (row->child) { | |
1328 gnt_tree_remove(tree, row->child->key); | |
1329 } | |
1330 depth--; | |
1331 } | |
1332 | |
1333 if (get_distance(tree->top, row) >= 0 && get_distance(row, tree->bottom) >= 0) | |
1334 redraw = TRUE; | |
1335 | |
1336 /* Update root/top/current/bottom if necessary */ | |
1337 if (tree->root == row) | |
1338 tree->root = get_next(row); | |
1339 if (tree->top == row) | |
1340 { | |
1341 if (tree->top != tree->root) | |
1342 tree->top = get_prev(row); | |
1343 else | |
1344 tree->top = get_next(row); | |
1345 } | |
1346 if (tree->current == row) | |
1347 { | |
1348 if (tree->current != tree->root) | |
1349 tree->current = get_prev(row); | |
1350 else | |
1351 tree->current = get_next(row); | |
1352 tree_selection_changed(tree, row, tree->current); | |
1353 } | |
1354 if (tree->bottom == row) | |
1355 { | |
1356 tree->bottom = get_prev(row); | |
1357 } | |
1358 | |
1359 /* Fix the links */ | |
1360 if (row->next) | |
1361 row->next->prev = row->prev; | |
1362 if (row->parent && row->parent->child == row) | |
1363 row->parent->child = row->next; | |
1364 if (row->prev) | |
1365 row->prev->next = row->next; | |
1366 | |
1367 g_hash_table_remove(tree->hash, key); | |
1368 tree->list = g_list_remove(tree->list, key); | |
1369 | |
1370 if (redraw && depth == 0) | |
1371 { | |
1372 redraw_tree(tree); | |
1373 } | |
1374 } | |
1375 } | |
1376 | |
1377 static gboolean | |
1378 return_true(gpointer key, gpointer data, gpointer null) | |
1379 { | |
1380 return TRUE; | |
1381 } | |
1382 | |
1383 void gnt_tree_remove_all(GntTree *tree) | |
1384 { | |
1385 tree->root = NULL; | |
1386 g_hash_table_foreach_remove(tree->hash, (GHRFunc)return_true, tree); | |
1387 g_list_free(tree->list); | |
1388 tree->list = NULL; | |
1389 tree->current = tree->top = tree->bottom = NULL; | |
1390 } | |
1391 | |
1392 int gnt_tree_get_selection_visible_line(GntTree *tree) | |
1393 { | |
1394 return get_distance(tree->top, tree->current) + | |
1395 !!(GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER)); | |
1396 } | |
1397 | |
1398 void gnt_tree_change_text(GntTree *tree, gpointer key, int colno, const char *text) | |
1399 { | |
1400 GntTreeRow *row; | |
1401 GntTreeCol *col; | |
1402 | |
1403 g_return_if_fail(colno < tree->ncol); | |
1404 | |
1405 row = g_hash_table_lookup(tree->hash, key); | |
1406 if (row) | |
1407 { | |
1408 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
|
1409 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
|
1410 col->text = (gpointer)text; |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1411 } else { |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1412 g_free(col->text); |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1413 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
|
1414 } |
15818 | 1415 |
1416 if (get_distance(tree->top, row) >= 0 && get_distance(row, tree->bottom) >= 0) | |
1417 redraw_tree(tree); | |
1418 } | |
1419 } | |
1420 | |
1421 GntTreeRow *gnt_tree_add_choice(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro) | |
1422 { | |
1423 GntTreeRow *r; | |
1424 r = g_hash_table_lookup(tree->hash, key); | |
1425 g_return_val_if_fail(!r || !r->choice, NULL); | |
1426 | |
1427 if (bigbro == NULL) { | |
1428 if (tree->compare) | |
1429 bigbro = find_position(tree, key, parent); | |
1430 else { | |
1431 r = g_hash_table_lookup(tree->hash, parent); | |
1432 if (!r) | |
1433 r = tree->root; | |
1434 else | |
1435 r = r->child; | |
1436 if (r) { | |
1437 while (r->next) | |
1438 r = r->next; | |
1439 bigbro = r->key; | |
1440 } | |
1441 } | |
1442 } | |
1443 row = gnt_tree_add_row_after(tree, key, row, parent, bigbro); | |
1444 row->choice = TRUE; | |
1445 | |
1446 return row; | |
1447 } | |
1448 | |
1449 void gnt_tree_set_choice(GntTree *tree, void *key, gboolean set) | |
1450 { | |
1451 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1452 | |
1453 if (!row) | |
1454 return; | |
1455 g_return_if_fail(row->choice); | |
1456 | |
1457 row->isselected = set; | |
1458 redraw_tree(tree); | |
1459 } | |
1460 | |
1461 gboolean gnt_tree_get_choice(GntTree *tree, void *key) | |
1462 { | |
1463 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1464 | |
1465 if (!row) | |
1466 return FALSE; | |
1467 g_return_val_if_fail(row->choice, FALSE); | |
1468 | |
1469 return row->isselected; | |
1470 } | |
1471 | |
1472 void gnt_tree_set_row_flags(GntTree *tree, void *key, GntTextFormatFlags flags) | |
1473 { | |
1474 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1475 if (!row || row->flags == flags) | |
1476 return; | |
1477 | |
1478 row->flags = flags; | |
1479 redraw_tree(tree); /* XXX: It shouldn't be necessary to redraw the whole darned tree */ | |
1480 } | |
1481 | |
1482 void gnt_tree_set_selected(GntTree *tree , void *key) | |
1483 { | |
1484 int dist; | |
1485 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
|
1486 if (!row || row == tree->current) |
15818 | 1487 return; |
1488 | |
1489 if (tree->top == NULL) | |
1490 tree->top = row; | |
1491 if (tree->bottom == NULL) | |
1492 tree->bottom = row; | |
1493 | |
1494 tree->current = row; | |
1495 if ((dist = get_distance(tree->current, tree->bottom)) < 0) | |
1496 gnt_tree_scroll(tree, -dist); | |
1497 else if ((dist = get_distance(tree->current, tree->top)) > 0) | |
1498 gnt_tree_scroll(tree, -dist); | |
1499 else | |
1500 redraw_tree(tree); | |
16203
4f6a6443a1e3
emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents:
16123
diff
changeset
|
1501 tree_selection_changed(tree, row, tree->current); |
15818 | 1502 } |
1503 | |
1504 void _gnt_tree_init_internals(GntTree *tree, int col) | |
1505 { | |
1506 tree->ncol = col; | |
1507 tree->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_tree_row); | |
1508 tree->columns = g_new0(struct _GntTreeColInfo, col); | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1509 tree->lastvisible = col - 1; |
15818 | 1510 while (col--) |
1511 { | |
1512 tree->columns[col].width = 15; | |
1513 } | |
1514 tree->list = NULL; | |
1515 tree->show_title = FALSE; | |
1516 } | |
1517 | |
1518 GntWidget *gnt_tree_new_with_columns(int col) | |
1519 { | |
1520 GntWidget *widget = g_object_new(GNT_TYPE_TREE, NULL); | |
1521 GntTree *tree = GNT_TREE(widget); | |
1522 | |
1523 _gnt_tree_init_internals(tree, col); | |
1524 | |
1525 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW); | |
1526 gnt_widget_set_take_focus(widget, TRUE); | |
1527 | |
1528 return widget; | |
1529 } | |
1530 | |
1531 GntTreeRow *gnt_tree_create_row_from_list(GntTree *tree, GList *list) | |
1532 { | |
1533 GList *iter; | |
1534 int i; | |
1535 GntTreeRow *row = g_new0(GntTreeRow, 1); | |
1536 | |
1537 for (i = 0, iter = list; i < tree->ncol && iter; iter = iter->next, i++) | |
1538 { | |
1539 GntTreeCol *col = g_new0(GntTreeCol, 1); | |
1540 col->span = 1; | |
18420
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1541 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
|
1542 col->text = 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 = TRUE; |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1544 } else { |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1545 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
|
1546 col->isbinary = FALSE; |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1547 } |
15818 | 1548 |
1549 row->columns = g_list_append(row->columns, col); | |
1550 } | |
1551 | |
1552 return row; | |
1553 } | |
1554 | |
1555 GntTreeRow *gnt_tree_create_row(GntTree *tree, ...) | |
1556 { | |
1557 int i; | |
1558 va_list args; | |
1559 GList *list = NULL; | |
1560 GntTreeRow *row; | |
1561 | |
1562 va_start(args, tree); | |
1563 for (i = 0; i < tree->ncol; i++) | |
1564 { | |
1565 list = g_list_append(list, va_arg(args, char *)); | |
1566 } | |
1567 va_end(args); | |
1568 | |
1569 row = gnt_tree_create_row_from_list(tree, list); | |
1570 g_list_free(list); | |
1571 | |
1572 return row; | |
1573 } | |
1574 | |
1575 void gnt_tree_set_col_width(GntTree *tree, int col, int width) | |
1576 { | |
1577 g_return_if_fail(col < tree->ncol); | |
1578 | |
1579 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
|
1580 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
|
1581 tree->columns[col].width_ratio = width; |
15818 | 1582 } |
1583 | |
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
|
1584 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
|
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 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
|
1587 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
|
1588 } |
1f9db757efc2
Oops. I missed this. This allows setting tree-column titles one by one.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18183
diff
changeset
|
1589 |
15818 | 1590 void gnt_tree_set_column_titles(GntTree *tree, ...) |
1591 { | |
1592 int i; | |
1593 va_list args; | |
1594 | |
1595 va_start(args, tree); | |
1596 for (i = 0; i < tree->ncol; i++) | |
1597 { | |
1598 const char *title = va_arg(args, const char *); | |
1599 tree->columns[i].title = g_strdup(title); | |
1600 } | |
1601 va_end(args); | |
1602 } | |
1603 | |
1604 void gnt_tree_set_show_title(GntTree *tree, gboolean set) | |
1605 { | |
1606 tree->show_title = set; | |
1607 GNT_WIDGET(tree)->priv.minh = (set ? 6 : 4); | |
1608 } | |
1609 | |
1610 void gnt_tree_set_compare_func(GntTree *tree, GCompareFunc func) | |
1611 { | |
1612 tree->compare = func; | |
1613 } | |
1614 | |
1615 void gnt_tree_set_expanded(GntTree *tree, void *key, gboolean expanded) | |
1616 { | |
1617 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1618 if (row) { | |
1619 row->collapsed = !expanded; | |
1620 if (GNT_WIDGET(tree)->window) | |
1621 gnt_widget_draw(GNT_WIDGET(tree)); | |
16203
4f6a6443a1e3
emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents:
16123
diff
changeset
|
1622 g_signal_emit(tree, signals[SIG_COLLAPSED], 0, key, row->collapsed); |
15818 | 1623 } |
1624 } | |
1625 | |
1626 void gnt_tree_set_show_separator(GntTree *tree, gboolean set) | |
1627 { | |
1628 tree->show_separator = set; | |
1629 } | |
1630 | |
1631 void gnt_tree_adjust_columns(GntTree *tree) | |
1632 { | |
1633 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
|
1634 int *widths, i, twidth; |
15818 | 1635 |
1636 widths = g_new0(int, tree->ncol); | |
1637 while (row) { | |
1638 GList *iter; | |
1639 for (i = 0, iter = row->columns; iter; iter = iter->next, i++) { | |
1640 GntTreeCol *col = iter->data; | |
1641 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
|
1642 if (i == 0 && row->choice) |
0ab73bf1fef1
check-items are wider.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15931
diff
changeset
|
1643 w += 4; |
15972
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
1644 if (i == 0) { |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
1645 w += find_depth(row) * TAB_SIZE; |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
1646 } |
15818 | 1647 if (widths[i] < w) |
1648 widths[i] = w; | |
1649 } | |
15972
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
1650 row = get_next(row); |
15818 | 1651 } |
1652 | |
1653 twidth = 1 + 2 * (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER)); | |
1654 for (i = 0; i < tree->ncol; i++) { | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1655 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
|
1656 widths[i] = tree->columns[i].width; |
15818 | 1657 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
|
1658 if (!COLUMN_INVISIBLE(tree, i)) { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1659 twidth = twidth + widths[i]; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1660 if (tree->lastvisible != i) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1661 twidth += 1; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1662 } |
15818 | 1663 } |
1664 g_free(widths); | |
1665 | |
16123
bc280c341679
We don't need to do anything about the heights here.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16105
diff
changeset
|
1666 gnt_widget_set_size(GNT_WIDGET(tree), twidth, -1); |
15818 | 1667 } |
1668 | |
1669 void gnt_tree_set_hash_fns(GntTree *tree, gpointer hash, gpointer eq, gpointer kd) | |
1670 { | |
1671 g_hash_table_foreach_remove(tree->hash, return_true, NULL); | |
1672 g_hash_table_destroy(tree->hash); | |
1673 tree->hash = g_hash_table_new_full(hash, eq, kd, free_tree_row); | |
1674 } | |
1675 | |
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
|
1676 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
|
1677 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
|
1678 { |
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 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
|
1680 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
|
1681 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
|
1682 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
|
1683 } |
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 |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
1685 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
|
1686 { |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
1687 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
|
1688 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
|
1689 if (vis) { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1690 /* the column is visible */ |
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 tree->lastvisible = col; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1693 } else { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1694 if (tree->lastvisible == col) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1695 while (tree->lastvisible) { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1696 tree->lastvisible--; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1697 if (!COLUMN_INVISIBLE(tree, tree->lastvisible)) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1698 break; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1699 } |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1700 } |
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
|
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 |
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 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
|
1704 { |
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
|
1705 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
|
1706 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
|
1707 } |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
1708 |
18420
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1709 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
|
1710 { |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1711 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
|
1712 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
|
1713 } |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1714 |
18449
ed17f5530300
Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
1715 void gnt_tree_set_column_is_right_aligned(GntTree *tree, int col, gboolean right) |
ed17f5530300
Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
1716 { |
ed17f5530300
Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
1717 g_return_if_fail(col < tree->ncol); |
ed17f5530300
Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
1718 set_column_flag(tree, col, GNT_TREE_COLUMN_RIGHT_ALIGNED, right); |
ed17f5530300
Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
1719 } |
ed17f5530300
Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
1720 |
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
|
1721 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
|
1722 { |
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
|
1723 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
|
1724 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
|
1725 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
|
1726 } |
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
|
1727 } |
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
|
1728 |