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