Mercurial > pidgin
annotate finch/libgnt/gnttree.c @ 18910:2115910c5746
Update for 0.14.
author | Jeffrey Connelly <jaconnel@calpoly.edu> |
---|---|
date | Sun, 12 Aug 2007 20:22:18 +0000 |
parents | b68ced0ab472 |
children | b5d6e360eca0 |
rev | line source |
---|---|
18049
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
1 /** |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
3 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
6 * source distribution. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
7 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
11 * (at your option) any later version. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
12 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
16 * GNU General Public License for more details. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
17 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
21 */ |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16577
diff
changeset
|
22 |
15817 | 23 #include "gntmarshal.h" |
24 #include "gntstyle.h" | |
25 #include "gnttree.h" | |
26 #include "gntutils.h" | |
27 | |
28 #include <string.h> | |
29 #include <ctype.h> | |
30 | |
31 #define SEARCH_TIMEOUT 4000 /* 4 secs */ | |
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) |
15817 | 33 |
18404
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
34 #define COLUMN_INVISIBLE(tree, index) (tree->columns[index].flags & GNT_TREE_COLUMN_INVISIBLE) |
18420
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
35 #define BINARY_DATA(tree, index) (tree->columns[index].flags & GNT_TREE_COLUMN_BINARY_DATA) |
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 |
15817 | 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 { |
15817 | 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, |
15817 | 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 |
15817 | 64 #define TAB_SIZE 3 |
65 | |
66 /* XXX: Make this one into a GObject? | |
67 * ... Probably not */ | |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
68 struct _GntTreeRow |
15817 | 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 | |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
88 struct _GntTreeCol |
15817 | 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; |
15817 | 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 |
15817 | 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 |
15817 | 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); |
15817 | 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; | |
16577
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); |
15817 | 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; |
15817 | 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; |
15817 | 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; |
15817 | 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 |
15817 | 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, '|'); |
15817 | 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; |
15817 | 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; |
15817 | 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); |
15817 | 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, ""); |
15817 | 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 |
15817 | 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; |
15817 | 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); |
15817 | 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; |
15817 | 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) { |
15817 | 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 } |
15817 | 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 |
15817 | 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 } |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
453 mvwaddstr(widget->window, pos, x + 1, tree->columns[i].title); |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
454 NEXT_X; |
15817 | 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; |
15817 | 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 |
15817 | 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)); |
15817 | 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; |
15817 | 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 |
15817 | 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; |
15817 | 771 } |
772 } | |
773 | |
774 static gboolean | |
775 search_timeout(gpointer data) | |
776 { | |
777 GntTree *tree = data; | |
778 | |
779 end_search(tree); | |
780 redraw_tree(tree); | |
781 | |
782 return FALSE; | |
783 } | |
784 | |
785 static gboolean | |
786 gnt_tree_key_pressed(GntWidget *widget, const char *text) | |
787 { | |
788 GntTree *tree = GNT_TREE(widget); | |
789 GntTreeRow *old = tree->current; | |
790 | |
791 if (text[0] == '\r') { | |
792 end_search(tree); | |
793 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
|
794 } else if (tree->priv->search) { |
16249
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
795 gboolean changed = TRUE; |
15817 | 796 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
|
797 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
|
798 } 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
|
799 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
|
800 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
|
801 } else |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
802 changed = FALSE; |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
803 if (changed) { |
15817 | 804 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
|
805 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
|
806 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
|
807 } else { |
3c634117a7ef
Allow disabling the widget actions on specific widgets. This allows, for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18564
diff
changeset
|
808 gnt_bindable_perform_action_key(GNT_BINDABLE(tree), text); |
15817 | 809 } |
810 return TRUE; | |
811 } else if (text[0] == ' ' && text[1] == 0) { | |
812 /* Space pressed */ | |
813 GntTreeRow *row = tree->current; | |
814 if (row && row->child) | |
815 { | |
816 row->collapsed = !row->collapsed; | |
817 redraw_tree(tree); | |
16105
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
818 g_signal_emit(tree, signals[SIG_COLLAPSED], 0, row->key, row->collapsed); |
15817 | 819 } |
820 else if (row && row->choice) | |
821 { | |
822 row->isselected = !row->isselected; | |
823 g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key); | |
824 redraw_tree(tree); | |
825 } | |
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
|
826 } 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
|
827 return FALSE; |
15817 | 828 } |
829 | |
830 if (old != tree->current) | |
831 { | |
832 tree_selection_changed(tree, old, tree->current); | |
833 } | |
834 | |
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
|
835 return TRUE; |
15817 | 836 } |
837 | |
838 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
|
839 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
|
840 { |
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 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
|
842 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
|
843 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
|
844 } |
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 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
|
846 } |
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 static void |
15817 | 849 gnt_tree_destroy(GntWidget *widget) |
850 { | |
851 GntTree *tree = GNT_TREE(widget); | |
852 | |
853 end_search(tree); | |
854 if (tree->hash) | |
855 g_hash_table_destroy(tree->hash); | |
856 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
|
857 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
|
858 g_free(tree->priv); |
15817 | 859 } |
860 | |
861 static gboolean | |
862 gnt_tree_clicked(GntWidget *widget, GntMouseEvent event, int x, int y) | |
863 { | |
864 GntTree *tree = GNT_TREE(widget); | |
865 GntTreeRow *old = tree->current; | |
866 if (event == GNT_MOUSE_SCROLL_UP) { | |
867 action_up(GNT_BINDABLE(widget), NULL); | |
868 } else if (event == GNT_MOUSE_SCROLL_DOWN) { | |
869 action_down(GNT_BINDABLE(widget), NULL); | |
870 } else if (event == GNT_LEFT_MOUSE_DOWN) { | |
871 GntTreeRow *row; | |
872 GntTree *tree = GNT_TREE(widget); | |
873 int pos = 1; | |
874 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
875 pos = 0; | |
876 if (tree->show_title) | |
877 pos += 2; | |
878 pos = y - widget->priv.y - pos; | |
879 row = get_next_n(tree->top, pos); | |
880 if (row && tree->current != row) { | |
881 GntTreeRow *old = tree->current; | |
882 tree->current = row; | |
883 redraw_tree(tree); | |
884 tree_selection_changed(tree, old, tree->current); | |
885 } else if (row && row == tree->current) { | |
886 if (row->choice) { | |
887 row->isselected = !row->isselected; | |
888 g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key); | |
889 redraw_tree(tree); | |
890 } else { | |
891 gnt_widget_activate(widget); | |
892 } | |
893 } | |
894 } else { | |
895 return FALSE; | |
896 } | |
897 if (old != tree->current) { | |
898 tree_selection_changed(tree, old, tree->current); | |
899 } | |
900 return TRUE; | |
901 } | |
902 | |
903 static void | |
904 gnt_tree_size_changed(GntWidget *widget, int w, int h) | |
905 { | |
906 GntTree *tree = GNT_TREE(widget); | |
907 if (widget->priv.width <= 0) | |
908 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
|
909 |
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 readjust_columns(tree); |
15817 | 911 } |
912 | |
913 static gboolean | |
914 start_search(GntBindable *bindable, GList *list) | |
915 { | |
916 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
|
917 if (tree->priv->search) |
15817 | 918 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
|
919 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
|
920 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
|
921 tree->priv->search_timeout = g_timeout_add(SEARCH_TIMEOUT, search_timeout, tree); |
15817 | 922 return TRUE; |
923 } | |
924 | |
925 static gboolean | |
926 end_search_action(GntBindable *bindable, GList *list) | |
927 { | |
928 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
|
929 if (tree->priv->search == NULL) |
15817 | 930 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
|
931 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(tree), GNT_WIDGET_DISABLE_ACTIONS); |
15817 | 932 end_search(tree); |
933 redraw_tree(tree); | |
934 return TRUE; | |
935 } | |
936 | |
937 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
|
938 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
|
939 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
|
940 { |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
941 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
|
942 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
|
943 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
|
944 _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
|
945 break; |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
946 default: |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
947 break; |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
948 } |
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 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
|
952 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
|
953 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
|
954 { |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
955 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
|
956 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
|
957 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
|
958 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
|
959 break; |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
960 default: |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
961 break; |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
962 } |
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 static void |
15817 | 966 gnt_tree_class_init(GntTreeClass *klass) |
967 { | |
968 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
|
969 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
|
970 |
15817 | 971 parent_class = GNT_WIDGET_CLASS(klass); |
972 parent_class->destroy = gnt_tree_destroy; | |
973 parent_class->draw = gnt_tree_draw; | |
974 parent_class->map = gnt_tree_map; | |
975 parent_class->size_request = gnt_tree_size_request; | |
976 parent_class->key_pressed = gnt_tree_key_pressed; | |
977 parent_class->clicked = gnt_tree_clicked; | |
978 parent_class->size_changed = gnt_tree_size_changed; | |
979 | |
18531
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
980 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
|
981 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
|
982 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
|
983 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
|
984 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
|
985 "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
|
986 1, G_MAXINT, 1, |
18745
221461ade6c9
These are new in Glib 2.8:
Stu Tomlinson <stu@nosnilmot.com>
parents:
18566
diff
changeset
|
987 #if GLIB_CHECK_VERSION(2,8,0) |
18531
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 |
18745
221461ade6c9
These are new in Glib 2.8:
Stu Tomlinson <stu@nosnilmot.com>
parents:
18566
diff
changeset
|
989 #else |
221461ade6c9
These are new in Glib 2.8:
Stu Tomlinson <stu@nosnilmot.com>
parents:
18566
diff
changeset
|
990 G_PARAM_READWRITE|G_PARAM_PRIVATE |
221461ade6c9
These are new in Glib 2.8:
Stu Tomlinson <stu@nosnilmot.com>
parents:
18566
diff
changeset
|
991 #endif |
18531
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
992 ) |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
993 ); |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
994 |
15817 | 995 signals[SIG_SELECTION_CHANGED] = |
996 g_signal_new("selection-changed", | |
997 G_TYPE_FROM_CLASS(klass), | |
998 G_SIGNAL_RUN_LAST, | |
999 G_STRUCT_OFFSET(GntTreeClass, selection_changed), | |
1000 NULL, NULL, | |
1001 gnt_closure_marshal_VOID__POINTER_POINTER, | |
1002 G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER); | |
1003 signals[SIG_SCROLLED] = | |
1004 g_signal_new("scrolled", | |
1005 G_TYPE_FROM_CLASS(klass), | |
1006 G_SIGNAL_RUN_LAST, | |
1007 0, | |
1008 NULL, NULL, | |
1009 g_cclosure_marshal_VOID__INT, | |
1010 G_TYPE_NONE, 1, G_TYPE_INT); | |
1011 signals[SIG_TOGGLED] = | |
1012 g_signal_new("toggled", | |
1013 G_TYPE_FROM_CLASS(klass), | |
1014 G_SIGNAL_RUN_LAST, | |
1015 G_STRUCT_OFFSET(GntTreeClass, toggled), | |
1016 NULL, NULL, | |
1017 g_cclosure_marshal_VOID__POINTER, | |
1018 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
|
1019 signals[SIG_COLLAPSED] = |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
1020 g_signal_new("collapse-toggled", |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
1021 G_TYPE_FROM_CLASS(klass), |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
1022 G_SIGNAL_RUN_LAST, |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
1023 0, |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
1024 NULL, NULL, |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
1025 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
|
1026 G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_BOOLEAN); |
15817 | 1027 |
1028 gnt_bindable_class_register_action(bindable, "move-up", action_up, | |
1029 GNT_KEY_UP, NULL); | |
1030 gnt_bindable_register_binding(bindable, "move-up", GNT_KEY_CTRL_P, NULL); | |
1031 gnt_bindable_class_register_action(bindable, "move-down", action_down, | |
1032 GNT_KEY_DOWN, NULL); | |
1033 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
|
1034 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
|
1035 GNT_KEY_BACKSPACE, NULL); |
15817 | 1036 gnt_bindable_class_register_action(bindable, "page-up", action_page_up, |
1037 GNT_KEY_PGUP, NULL); | |
1038 gnt_bindable_class_register_action(bindable, "page-down", action_page_down, | |
1039 GNT_KEY_PGDOWN, NULL); | |
1040 gnt_bindable_class_register_action(bindable, "start-search", start_search, | |
1041 "/", NULL); | |
1042 gnt_bindable_class_register_action(bindable, "end-search", end_search_action, | |
1043 "\033", NULL); | |
1044 | |
1045 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), bindable); | |
1046 GNTDEBUG; | |
1047 } | |
1048 | |
1049 static void | |
1050 gnt_tree_init(GTypeInstance *instance, gpointer class) | |
1051 { | |
1052 GntWidget *widget = GNT_WIDGET(instance); | |
1053 GntTree *tree = GNT_TREE(widget); | |
1054 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
|
1055 tree->priv = g_new0(GntTreePriv, 1); |
18556
5e1412f4e67a
Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18541
diff
changeset
|
1056 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y | GNT_WIDGET_CAN_TAKE_FOCUS); |
15817 | 1057 widget->priv.minw = 4; |
1058 widget->priv.minh = 1; | |
1059 GNTDEBUG; | |
1060 } | |
1061 | |
1062 /****************************************************************************** | |
1063 * GntTree API | |
1064 *****************************************************************************/ | |
1065 GType | |
1066 gnt_tree_get_gtype(void) | |
1067 { | |
1068 static GType type = 0; | |
1069 | |
1070 if(type == 0) | |
1071 { | |
1072 static const GTypeInfo info = { | |
1073 sizeof(GntTreeClass), | |
1074 NULL, /* base_init */ | |
1075 NULL, /* base_finalize */ | |
1076 (GClassInitFunc)gnt_tree_class_init, | |
1077 NULL, /* class_finalize */ | |
1078 NULL, /* class_data */ | |
1079 sizeof(GntTree), | |
1080 0, /* n_preallocs */ | |
1081 gnt_tree_init, /* instance_init */ | |
1082 NULL /* value_table */ | |
1083 }; | |
1084 | |
1085 type = g_type_register_static(GNT_TYPE_WIDGET, | |
1086 "GntTree", | |
1087 &info, 0); | |
1088 } | |
1089 | |
1090 return type; | |
1091 } | |
1092 | |
1093 static void | |
1094 free_tree_col(gpointer data) | |
1095 { | |
1096 GntTreeCol *col = data; | |
18811 | 1097 if (!col->isbinary) |
18420
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1098 g_free(col->text); |
15817 | 1099 g_free(col); |
1100 } | |
1101 | |
1102 static void | |
1103 free_tree_row(gpointer data) | |
1104 { | |
1105 GntTreeRow *row = data; | |
1106 | |
1107 if (!row) | |
1108 return; | |
1109 | |
1110 g_list_foreach(row->columns, (GFunc)free_tree_col, NULL); | |
1111 g_list_free(row->columns); | |
1112 g_free(row); | |
1113 } | |
1114 | |
1115 GntWidget *gnt_tree_new() | |
1116 { | |
1117 return gnt_tree_new_with_columns(1); | |
1118 } | |
1119 | |
1120 void gnt_tree_set_visible_rows(GntTree *tree, int rows) | |
1121 { | |
1122 GntWidget *widget = GNT_WIDGET(tree); | |
1123 widget->priv.height = rows; | |
1124 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
1125 widget->priv.height += 2; | |
1126 } | |
1127 | |
1128 int gnt_tree_get_visible_rows(GntTree *tree) | |
1129 { | |
1130 GntWidget *widget = GNT_WIDGET(tree); | |
1131 int ret = widget->priv.height; | |
1132 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
1133 ret -= 2; | |
1134 return ret; | |
1135 } | |
1136 | |
18118
ab6d2763b8d8
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@wiktel.com>
parents:
18098
diff
changeset
|
1137 GList *gnt_tree_get_rows(GntTree *tree) |
15817 | 1138 { |
1139 return tree->list; | |
1140 } | |
1141 | |
1142 void gnt_tree_scroll(GntTree *tree, int count) | |
1143 { | |
1144 GntTreeRow *row; | |
1145 | |
1146 if (count < 0) | |
1147 { | |
1148 if (get_root_distance(tree->top) == 0) | |
1149 return; | |
1150 row = get_prev_n(tree->top, -count); | |
1151 if (row == NULL) | |
1152 row = tree->root; | |
1153 tree->top = row; | |
1154 } | |
1155 else | |
1156 { | |
1157 get_next_n_opt(tree->bottom, count, &count); | |
1158 tree->top = get_next_n(tree->top, count); | |
1159 } | |
1160 | |
1161 redraw_tree(tree); | |
1162 g_signal_emit(tree, signals[SIG_SCROLLED], 0, count); | |
1163 } | |
1164 | |
1165 static gpointer | |
1166 find_position(GntTree *tree, gpointer key, gpointer parent) | |
1167 { | |
1168 GntTreeRow *row; | |
1169 | |
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
|
1170 if (tree->priv->compare == NULL) |
15817 | 1171 return NULL; |
1172 | |
1173 if (parent == NULL) | |
1174 row = tree->root; | |
1175 else | |
1176 row = g_hash_table_lookup(tree->hash, parent); | |
1177 | |
1178 if (!row) | |
1179 return NULL; | |
1180 | |
1181 if (parent) | |
1182 row = row->child; | |
1183 | |
1184 while (row) | |
1185 { | |
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
|
1186 if (tree->priv->compare(key, row->key) < 0) |
15817 | 1187 return (row->prev ? row->prev->key : NULL); |
1188 if (row->next) | |
1189 row = row->next; | |
1190 else | |
1191 return row->key; | |
1192 } | |
1193 return NULL; | |
1194 } | |
1195 | |
1196 void gnt_tree_sort_row(GntTree *tree, gpointer key) | |
1197 { | |
1198 GntTreeRow *row, *q, *s; | |
1199 int current, newp; | |
1200 | |
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
|
1201 if (!tree->priv->compare) |
15817 | 1202 return; |
1203 | |
1204 row = g_hash_table_lookup(tree->hash, key); | |
1205 g_return_if_fail(row != NULL); | |
1206 | |
1207 current = g_list_index(tree->list, key); | |
1208 | |
1209 if (row->parent) | |
1210 s = row->parent->child; | |
1211 else | |
1212 s = tree->root; | |
1213 | |
1214 q = NULL; | |
1215 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
|
1216 if (tree->priv->compare(row->key, s->key) < 0) |
15817 | 1217 break; |
1218 q = s; | |
1219 s = s->next; | |
1220 } | |
1221 | |
1222 /* Move row between q and s */ | |
1223 if (row == q || row == s) | |
1224 return; | |
1225 | |
1226 if (q == NULL) { | |
1227 /* row becomes the first child of its parent */ | |
1228 row->prev->next = row->next; /* row->prev cannot be NULL at this point */ | |
1229 if (row->next) | |
1230 row->next->prev = row->prev; | |
1231 if (row->parent) | |
1232 row->parent->child = row; | |
1233 else | |
1234 tree->root = row; | |
1235 row->next = s; | |
1236 s->prev = row; /* s cannot be NULL */ | |
1237 row->prev = NULL; | |
1238 newp = g_list_index(tree->list, s) - 1; | |
1239 } else { | |
1240 if (row->prev) { | |
1241 row->prev->next = row->next; | |
1242 } else { | |
1243 /* row was the first child of its parent */ | |
1244 if (row->parent) | |
1245 row->parent->child = row->next; | |
1246 else | |
1247 tree->top = row->next; | |
1248 } | |
1249 | |
1250 if (row->next) | |
1251 row->next->prev = row->prev; | |
1252 | |
1253 q->next = row; | |
1254 row->prev = q; | |
1255 if (s) | |
1256 s->prev = row; | |
1257 row->next = s; | |
1258 newp = g_list_index(tree->list, q) + 1; | |
1259 } | |
1260 tree->list = g_list_reposition_child(tree->list, current, newp); | |
1261 | |
1262 redraw_tree(tree); | |
1263 } | |
1264 | |
1265 GntTreeRow *gnt_tree_add_row_after(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro) | |
1266 { | |
1267 GntTreeRow *pr = NULL; | |
1268 | |
1269 g_hash_table_replace(tree->hash, key, row); | |
1270 row->tree = tree; | |
1271 | |
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
|
1272 if (bigbro == NULL && tree->priv->compare) |
15817 | 1273 { |
1274 bigbro = find_position(tree, key, parent); | |
1275 } | |
1276 | |
1277 if (tree->root == NULL) | |
1278 { | |
1279 tree->root = row; | |
1280 tree->list = g_list_prepend(tree->list, key); | |
1281 } | |
1282 else | |
1283 { | |
1284 int position = 0; | |
1285 | |
1286 if (bigbro) | |
1287 { | |
1288 pr = g_hash_table_lookup(tree->hash, bigbro); | |
1289 if (pr) | |
1290 { | |
1291 if (pr->next) pr->next->prev = row; | |
1292 row->next = pr->next; | |
1293 row->prev = pr; | |
1294 pr->next = row; | |
1295 row->parent = pr->parent; | |
1296 | |
1297 position = g_list_index(tree->list, bigbro); | |
1298 } | |
1299 } | |
1300 | |
1301 if (pr == NULL && parent) | |
1302 { | |
1303 pr = g_hash_table_lookup(tree->hash, parent); | |
1304 if (pr) | |
1305 { | |
1306 if (pr->child) pr->child->prev = row; | |
1307 row->next = pr->child; | |
1308 pr->child = row; | |
1309 row->parent = pr; | |
1310 | |
1311 position = g_list_index(tree->list, parent); | |
1312 } | |
1313 } | |
1314 | |
1315 if (pr == NULL) | |
1316 { | |
1317 GntTreeRow *r = tree->root; | |
1318 row->next = r; | |
1319 if (r) r->prev = row; | |
1320 if (tree->current == tree->root) | |
1321 tree->current = row; | |
1322 tree->root = row; | |
1323 tree->list = g_list_prepend(tree->list, key); | |
1324 } | |
1325 else | |
1326 { | |
1327 tree->list = g_list_insert(tree->list, key, position + 1); | |
1328 } | |
1329 } | |
1330 | |
1331 row->key = key; | |
1332 row->data = NULL; | |
1333 | |
1334 redraw_tree(tree); | |
1335 | |
1336 return row; | |
1337 } | |
1338 | |
1339 GntTreeRow *gnt_tree_add_row_last(GntTree *tree, void *key, GntTreeRow *row, void *parent) | |
1340 { | |
1341 GntTreeRow *pr = NULL, *br = NULL; | |
1342 | |
1343 if (parent) | |
1344 pr = g_hash_table_lookup(tree->hash, parent); | |
1345 | |
1346 if (pr) | |
1347 br = pr->child; | |
1348 else | |
1349 br = tree->root; | |
1350 | |
1351 if (br) | |
1352 { | |
1353 while (br->next) | |
1354 br = br->next; | |
1355 } | |
1356 | |
1357 return gnt_tree_add_row_after(tree, key, row, parent, br ? br->key : NULL); | |
1358 } | |
1359 | |
1360 gpointer gnt_tree_get_selection_data(GntTree *tree) | |
1361 { | |
1362 if (tree->current) | |
1363 return tree->current->key; /* XXX: perhaps we should just get rid of 'data' */ | |
1364 return NULL; | |
1365 } | |
1366 | |
1367 char *gnt_tree_get_selection_text(GntTree *tree) | |
1368 { | |
1369 if (tree->current) | |
1370 return update_row_text(tree, tree->current); | |
1371 return NULL; | |
1372 } | |
1373 | |
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
|
1374 GList *gnt_tree_get_row_text_list(GntTree *tree, gpointer key) |
15817 | 1375 { |
1376 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
|
1377 GntTreeRow *row = key ? g_hash_table_lookup(tree->hash, key) : tree->current; |
15817 | 1378 int i; |
1379 | |
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
|
1380 if (!row) |
15817 | 1381 return NULL; |
1382 | |
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
|
1383 for (i = 0, iter = row->columns; i < tree->ncol && iter; |
15817 | 1384 i++, iter = iter->next) |
1385 { | |
1386 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
|
1387 list = g_list_append(list, BINARY_DATA(tree, i) ? col->text : g_strdup(col->text)); |
15817 | 1388 } |
1389 | |
1390 return list; | |
1391 } | |
1392 | |
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
|
1393 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
|
1394 { |
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 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
|
1396 } |
36257cac2b11
Anoter patch from Javeed Shaikh to introduce a utility function for a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18563
diff
changeset
|
1397 |
15817 | 1398 void gnt_tree_remove(GntTree *tree, gpointer key) |
1399 { | |
1400 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1401 static int depth = 0; /* Only redraw after all child nodes are removed */ | |
1402 if (row) | |
1403 { | |
1404 gboolean redraw = FALSE; | |
1405 | |
1406 if (row->child) { | |
1407 depth++; | |
1408 while (row->child) { | |
1409 gnt_tree_remove(tree, row->child->key); | |
1410 } | |
1411 depth--; | |
1412 } | |
1413 | |
1414 if (get_distance(tree->top, row) >= 0 && get_distance(row, tree->bottom) >= 0) | |
1415 redraw = TRUE; | |
1416 | |
1417 /* Update root/top/current/bottom if necessary */ | |
1418 if (tree->root == row) | |
1419 tree->root = get_next(row); | |
1420 if (tree->top == row) | |
1421 { | |
1422 if (tree->top != tree->root) | |
1423 tree->top = get_prev(row); | |
1424 else | |
1425 tree->top = get_next(row); | |
1426 } | |
1427 if (tree->current == row) | |
1428 { | |
1429 if (tree->current != tree->root) | |
1430 tree->current = get_prev(row); | |
1431 else | |
1432 tree->current = get_next(row); | |
1433 tree_selection_changed(tree, row, tree->current); | |
1434 } | |
1435 if (tree->bottom == row) | |
1436 { | |
1437 tree->bottom = get_prev(row); | |
1438 } | |
1439 | |
1440 /* Fix the links */ | |
1441 if (row->next) | |
1442 row->next->prev = row->prev; | |
1443 if (row->parent && row->parent->child == row) | |
1444 row->parent->child = row->next; | |
1445 if (row->prev) | |
1446 row->prev->next = row->next; | |
1447 | |
1448 g_hash_table_remove(tree->hash, key); | |
1449 tree->list = g_list_remove(tree->list, key); | |
1450 | |
1451 if (redraw && depth == 0) | |
1452 { | |
1453 redraw_tree(tree); | |
1454 } | |
1455 } | |
1456 } | |
1457 | |
1458 static gboolean | |
1459 return_true(gpointer key, gpointer data, gpointer null) | |
1460 { | |
1461 return TRUE; | |
1462 } | |
1463 | |
1464 void gnt_tree_remove_all(GntTree *tree) | |
1465 { | |
1466 tree->root = NULL; | |
1467 g_hash_table_foreach_remove(tree->hash, (GHRFunc)return_true, tree); | |
1468 g_list_free(tree->list); | |
1469 tree->list = NULL; | |
1470 tree->current = tree->top = tree->bottom = NULL; | |
1471 } | |
1472 | |
1473 int gnt_tree_get_selection_visible_line(GntTree *tree) | |
1474 { | |
1475 return get_distance(tree->top, tree->current) + | |
1476 !!(GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER)); | |
1477 } | |
1478 | |
1479 void gnt_tree_change_text(GntTree *tree, gpointer key, int colno, const char *text) | |
1480 { | |
1481 GntTreeRow *row; | |
1482 GntTreeCol *col; | |
1483 | |
1484 g_return_if_fail(colno < tree->ncol); | |
1485 | |
1486 row = g_hash_table_lookup(tree->hash, key); | |
1487 if (row) | |
1488 { | |
1489 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
|
1490 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
|
1491 col->text = (gpointer)text; |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1492 } else { |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1493 g_free(col->text); |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1494 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
|
1495 } |
15817 | 1496 |
1497 if (get_distance(tree->top, row) >= 0 && get_distance(row, tree->bottom) >= 0) | |
1498 redraw_tree(tree); | |
1499 } | |
1500 } | |
1501 | |
1502 GntTreeRow *gnt_tree_add_choice(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro) | |
1503 { | |
1504 GntTreeRow *r; | |
1505 r = g_hash_table_lookup(tree->hash, key); | |
1506 g_return_val_if_fail(!r || !r->choice, NULL); | |
1507 | |
1508 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
|
1509 if (tree->priv->compare) |
15817 | 1510 bigbro = find_position(tree, key, parent); |
1511 else { | |
1512 r = g_hash_table_lookup(tree->hash, parent); | |
1513 if (!r) | |
1514 r = tree->root; | |
1515 else | |
1516 r = r->child; | |
1517 if (r) { | |
1518 while (r->next) | |
1519 r = r->next; | |
1520 bigbro = r->key; | |
1521 } | |
1522 } | |
1523 } | |
1524 row = gnt_tree_add_row_after(tree, key, row, parent, bigbro); | |
1525 row->choice = TRUE; | |
1526 | |
1527 return row; | |
1528 } | |
1529 | |
1530 void gnt_tree_set_choice(GntTree *tree, void *key, gboolean set) | |
1531 { | |
1532 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1533 | |
1534 if (!row) | |
1535 return; | |
1536 g_return_if_fail(row->choice); | |
1537 | |
1538 row->isselected = set; | |
1539 redraw_tree(tree); | |
1540 } | |
1541 | |
1542 gboolean gnt_tree_get_choice(GntTree *tree, void *key) | |
1543 { | |
1544 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1545 | |
1546 if (!row) | |
1547 return FALSE; | |
1548 g_return_val_if_fail(row->choice, FALSE); | |
1549 | |
1550 return row->isselected; | |
1551 } | |
1552 | |
1553 void gnt_tree_set_row_flags(GntTree *tree, void *key, GntTextFormatFlags flags) | |
1554 { | |
1555 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1556 if (!row || row->flags == flags) | |
1557 return; | |
1558 | |
1559 row->flags = flags; | |
1560 redraw_tree(tree); /* XXX: It shouldn't be necessary to redraw the whole darned tree */ | |
1561 } | |
1562 | |
1563 void gnt_tree_set_selected(GntTree *tree , void *key) | |
1564 { | |
1565 int dist; | |
1566 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
|
1567 if (!row || row == tree->current) |
15817 | 1568 return; |
1569 | |
1570 if (tree->top == NULL) | |
1571 tree->top = row; | |
1572 if (tree->bottom == NULL) | |
1573 tree->bottom = row; | |
1574 | |
1575 tree->current = row; | |
1576 if ((dist = get_distance(tree->current, tree->bottom)) < 0) | |
1577 gnt_tree_scroll(tree, -dist); | |
1578 else if ((dist = get_distance(tree->current, tree->top)) > 0) | |
1579 gnt_tree_scroll(tree, -dist); | |
1580 else | |
1581 redraw_tree(tree); | |
16203
4f6a6443a1e3
emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents:
16123
diff
changeset
|
1582 tree_selection_changed(tree, row, tree->current); |
15817 | 1583 } |
1584 | |
18531
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
1585 static void _gnt_tree_init_internals(GntTree *tree, int col) |
15817 | 1586 { |
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
|
1587 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
|
1588 |
15817 | 1589 tree->ncol = col; |
1590 tree->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_tree_row); | |
1591 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
|
1592 tree->priv->lastvisible = col - 1; |
15817 | 1593 while (col--) |
1594 { | |
1595 tree->columns[col].width = 15; | |
1596 } | |
1597 tree->list = NULL; | |
1598 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
|
1599 g_object_notify(G_OBJECT(tree), "columns"); |
15817 | 1600 } |
1601 | |
1602 GntWidget *gnt_tree_new_with_columns(int col) | |
1603 { | |
18531
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
1604 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
|
1605 "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
|
1606 NULL); |
15817 | 1607 |
1608 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW); | |
1609 gnt_widget_set_take_focus(widget, TRUE); | |
1610 | |
1611 return widget; | |
1612 } | |
1613 | |
1614 GntTreeRow *gnt_tree_create_row_from_list(GntTree *tree, GList *list) | |
1615 { | |
1616 GList *iter; | |
1617 int i; | |
1618 GntTreeRow *row = g_new0(GntTreeRow, 1); | |
1619 | |
1620 for (i = 0, iter = list; i < tree->ncol && iter; iter = iter->next, i++) | |
1621 { | |
1622 GntTreeCol *col = g_new0(GntTreeCol, 1); | |
1623 col->span = 1; | |
18420
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1624 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
|
1625 col->text = iter->data; |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1626 col->isbinary = TRUE; |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1627 } else { |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1628 col->text = g_strdup(iter->data ? iter->data : ""); |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1629 col->isbinary = FALSE; |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1630 } |
15817 | 1631 |
1632 row->columns = g_list_append(row->columns, col); | |
1633 } | |
1634 | |
1635 return row; | |
1636 } | |
1637 | |
1638 GntTreeRow *gnt_tree_create_row(GntTree *tree, ...) | |
1639 { | |
1640 int i; | |
1641 va_list args; | |
1642 GList *list = NULL; | |
1643 GntTreeRow *row; | |
1644 | |
1645 va_start(args, tree); | |
1646 for (i = 0; i < tree->ncol; i++) | |
1647 { | |
1648 list = g_list_append(list, va_arg(args, char *)); | |
1649 } | |
1650 va_end(args); | |
1651 | |
1652 row = gnt_tree_create_row_from_list(tree, list); | |
1653 g_list_free(list); | |
1654 | |
1655 return row; | |
1656 } | |
1657 | |
1658 void gnt_tree_set_col_width(GntTree *tree, int col, int width) | |
1659 { | |
1660 g_return_if_fail(col < tree->ncol); | |
1661 | |
1662 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
|
1663 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
|
1664 tree->columns[col].width_ratio = width; |
15817 | 1665 } |
1666 | |
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
|
1667 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
|
1668 { |
1f9db757efc2
Oops. I missed this. This allows setting tree-column titles one by one.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18183
diff
changeset
|
1669 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
|
1670 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
|
1671 } |
1f9db757efc2
Oops. I missed this. This allows setting tree-column titles one by one.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18183
diff
changeset
|
1672 |
15817 | 1673 void gnt_tree_set_column_titles(GntTree *tree, ...) |
1674 { | |
1675 int i; | |
1676 va_list args; | |
1677 | |
1678 va_start(args, tree); | |
1679 for (i = 0; i < tree->ncol; i++) | |
1680 { | |
1681 const char *title = va_arg(args, const char *); | |
1682 tree->columns[i].title = g_strdup(title); | |
1683 } | |
1684 va_end(args); | |
1685 } | |
1686 | |
1687 void gnt_tree_set_show_title(GntTree *tree, gboolean set) | |
1688 { | |
1689 tree->show_title = set; | |
1690 GNT_WIDGET(tree)->priv.minh = (set ? 6 : 4); | |
1691 } | |
1692 | |
1693 void gnt_tree_set_compare_func(GntTree *tree, GCompareFunc func) | |
1694 { | |
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
|
1695 tree->priv->compare = func; |
15817 | 1696 } |
1697 | |
1698 void gnt_tree_set_expanded(GntTree *tree, void *key, gboolean expanded) | |
1699 { | |
1700 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1701 if (row) { | |
1702 row->collapsed = !expanded; | |
1703 if (GNT_WIDGET(tree)->window) | |
1704 gnt_widget_draw(GNT_WIDGET(tree)); | |
16203
4f6a6443a1e3
emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents:
16123
diff
changeset
|
1705 g_signal_emit(tree, signals[SIG_COLLAPSED], 0, key, row->collapsed); |
15817 | 1706 } |
1707 } | |
1708 | |
1709 void gnt_tree_set_show_separator(GntTree *tree, gboolean set) | |
1710 { | |
1711 tree->show_separator = set; | |
1712 } | |
1713 | |
1714 void gnt_tree_adjust_columns(GntTree *tree) | |
1715 { | |
1716 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
|
1717 int *widths, i, twidth; |
15817 | 1718 |
1719 widths = g_new0(int, tree->ncol); | |
1720 while (row) { | |
1721 GList *iter; | |
1722 for (i = 0, iter = row->columns; iter; iter = iter->next, i++) { | |
1723 GntTreeCol *col = iter->data; | |
1724 int w = gnt_util_onscreen_width(col->text, NULL); | |
15968
0ab73bf1fef1
check-items are wider.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15928
diff
changeset
|
1725 if (i == 0 && row->choice) |
0ab73bf1fef1
check-items are wider.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15928
diff
changeset
|
1726 w += 4; |
15972
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
1727 if (i == 0) { |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
1728 w += find_depth(row) * TAB_SIZE; |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
1729 } |
15817 | 1730 if (widths[i] < w) |
1731 widths[i] = w; | |
1732 } | |
15972
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
1733 row = get_next(row); |
15817 | 1734 } |
1735 | |
1736 twidth = 1 + 2 * (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER)); | |
1737 for (i = 0; i < tree->ncol; i++) { | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1738 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
|
1739 widths[i] = tree->columns[i].width; |
15817 | 1740 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
|
1741 if (!COLUMN_INVISIBLE(tree, i)) { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1742 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
|
1743 if (tree->priv->lastvisible != i) |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1744 twidth += 1; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1745 } |
15817 | 1746 } |
1747 g_free(widths); | |
1748 | |
16123
bc280c341679
We don't need to do anything about the heights here.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16105
diff
changeset
|
1749 gnt_widget_set_size(GNT_WIDGET(tree), twidth, -1); |
15817 | 1750 } |
1751 | |
1752 void gnt_tree_set_hash_fns(GntTree *tree, gpointer hash, gpointer eq, gpointer kd) | |
1753 { | |
1754 g_hash_table_foreach_remove(tree->hash, return_true, NULL); | |
1755 g_hash_table_destroy(tree->hash); | |
1756 tree->hash = g_hash_table_new_full(hash, eq, kd, free_tree_row); | |
1757 } | |
1758 | |
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
|
1759 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
|
1760 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
|
1761 { |
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 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
|
1763 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
|
1764 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
|
1765 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
|
1766 } |
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 |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
1768 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
|
1769 { |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
1770 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
|
1771 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
|
1772 if (vis) { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1773 /* 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
|
1774 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
|
1775 tree->priv->lastvisible = col; |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1776 } 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
|
1777 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
|
1778 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
|
1779 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
|
1780 if (!COLUMN_INVISIBLE(tree, tree->priv->lastvisible)) |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1781 break; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1782 } |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1783 } |
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
|
1784 } |
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 |
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
|
1786 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
|
1787 { |
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
|
1788 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
|
1789 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
|
1790 } |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
1791 |
18420
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1792 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
|
1793 { |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1794 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
|
1795 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
|
1796 } |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1797 |
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
|
1798 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
|
1799 { |
ed17f5530300
Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
1800 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
|
1801 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
|
1802 } |
ed17f5530300
Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
1803 |
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
|
1804 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
|
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 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
|
1807 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
|
1808 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
|
1809 } |
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
|
1810 } |
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
|
1811 |
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
|
1812 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
|
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 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
|
1815 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
|
1816 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
|
1817 } |
ffa46a399f3c
Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
1818 |
18535
fad459189cc5
New feature: successful compilation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18534
diff
changeset
|
1819 gboolean gnt_tree_is_searching(GntTree *tree) |
fad459189cc5
New feature: successful compilation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18534
diff
changeset
|
1820 { |
fad459189cc5
New feature: successful compilation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18534
diff
changeset
|
1821 return (tree->priv->search != NULL); |
fad459189cc5
New feature: successful compilation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18534
diff
changeset
|
1822 } |
fad459189cc5
New feature: successful compilation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18534
diff
changeset
|
1823 |
18557
212c2bec5c97
Allow using custom search functions.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18556
diff
changeset
|
1824 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
|
1825 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
|
1826 { |
212c2bec5c97
Allow using custom search functions.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18556
diff
changeset
|
1827 tree->priv->search_func = func; |
212c2bec5c97
Allow using custom search functions.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18556
diff
changeset
|
1828 } |
212c2bec5c97
Allow using custom search functions.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18556
diff
changeset
|
1829 |