Mercurial > pidgin
annotate finch/libgnt/gnttree.c @ 21520:f3e3c604ea0e
merge of '61d876a57f30f4e29a91a8411d259e8aaa4355ea'
and '8f4c83ded385e01c8c6b04edd91d02dac0c09571'
author | Will Thompson <will.thompson@collabora.co.uk> |
---|---|
date | Thu, 15 Nov 2007 12:55:17 +0000 |
parents | 406aa3be6b32 |
children | 3ed9b027479d |
rev | line source |
---|---|
17928
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16577
diff
changeset
|
1 /** |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16577
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16577
diff
changeset
|
3 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16577
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16577
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16577
diff
changeset
|
6 * source distribution. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16577
diff
changeset
|
7 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16577
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16577
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16577
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16577
diff
changeset
|
11 * (at your option) any later version. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16577
diff
changeset
|
12 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16577
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16577
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16577
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16577
diff
changeset
|
16 * GNU General Public License for more details. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16577
diff
changeset
|
17 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16577
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16577
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
19681
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19371
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
17928
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16577
diff
changeset
|
21 */ |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
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) { |
21273
6e666ae6f68e
Do not ellipsize in a column of size 1.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21272
diff
changeset
|
366 len = MAX(1, 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) { |
21272
f869796bf505
Patch from Josh Davis to correct ellipsization for right-aligned columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21271
diff
changeset
|
371 g_string_append_printf(string, "%*s", width - len - cut, ""); |
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
|
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); |
21273
6e666ae6f68e
Do not ellipsize in a column of size 1.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21272
diff
changeset
|
376 if (cut && width > 1) { /* ellipsis */ |
15817 | 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 |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20751
diff
changeset
|
435 wbkgd(widget->window, gnt_color_pair(GNT_COLOR_NORMAL)); |
15817 | 436 |
437 start = 0; | |
438 if (tree->show_title) | |
439 { | |
440 int i; | |
441 int x = pos; | |
442 | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20751
diff
changeset
|
443 mvwhline(widget->window, pos + 1, pos, ACS_HLINE | gnt_color_pair(GNT_COLOR_NORMAL), |
15817 | 444 widget->priv.width - pos - 1); |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20751
diff
changeset
|
445 mvwhline(widget->window, pos, pos, ' ' | gnt_color_pair(GNT_COLOR_NORMAL), |
15970
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 } |
18726
68fec9f954dd
Make sure long titles remain within their own cell.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18720
diff
changeset
|
453 mvwaddnstr(widget->window, pos, x + (x != pos), tree->columns[i].title, tree->columns[i].width); |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
454 NEXT_X; |
15817 | 455 } |
456 if (pos) | |
457 { | |
21264
ad49d9dace9f
Draw the 'header' correctly when not showing borders.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21254
diff
changeset
|
458 tree_mark_columns(tree, pos, 0, |
ad49d9dace9f
Draw the 'header' correctly when not showing borders.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21254
diff
changeset
|
459 (tree->show_separator ? ACS_TTEE : ACS_HLINE) | gnt_color_pair(GNT_COLOR_NORMAL)); |
15817 | 460 tree_mark_columns(tree, pos, widget->priv.height - pos, |
21264
ad49d9dace9f
Draw the 'header' correctly when not showing borders.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21254
diff
changeset
|
461 (tree->show_separator ? ACS_BTEE : ACS_HLINE) | gnt_color_pair(GNT_COLOR_NORMAL)); |
15817 | 462 } |
463 tree_mark_columns(tree, pos, pos + 1, | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20751
diff
changeset
|
464 (tree->show_separator ? ACS_PLUS : ACS_HLINE) | gnt_color_pair(GNT_COLOR_NORMAL)); |
15817 | 465 tree_mark_columns(tree, pos, pos, |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20751
diff
changeset
|
466 (tree->show_separator ? ACS_VLINE : ' ') | gnt_color_pair(GNT_COLOR_NORMAL)); |
15817 | 467 start = 2; |
468 } | |
469 | |
470 rows = widget->priv.height - pos * 2 - start - 1; | |
471 tree->bottom = get_next_n_opt(tree->top, rows, &down); | |
472 if (down < rows) | |
473 { | |
474 tree->top = get_prev_n(tree->bottom, rows); | |
475 if (tree->top == NULL) | |
476 tree->top = tree->root; | |
477 } | |
478 | |
479 up = get_distance(tree->top, tree->current); | |
480 if (up < 0) | |
481 tree->top = tree->current; | |
482 else if (up >= widget->priv.height - pos) | |
483 tree->top = get_prev_n(tree->current, rows); | |
484 | |
485 if (tree->top && !row_matches_search(tree->top)) | |
486 tree->top = get_next(tree->top); | |
487 row = tree->top; | |
488 scrcol = widget->priv.width - 1 - 2 * pos; /* exclude the borders and the scrollbar */ | |
489 for (i = start + pos; row && i < widget->priv.height - pos; | |
490 i++, row = get_next(row)) | |
491 { | |
492 char *str; | |
493 int wr; | |
494 | |
495 GntTextFormatFlags flags = row->flags; | |
496 int attr = 0; | |
497 | |
498 if (!row_matches_search(row)) | |
499 continue; | |
500 str = update_row_text(tree, row); | |
501 | |
502 if ((wr = gnt_util_onscreen_width(str, NULL)) > scrcol) | |
503 { | |
504 char *s = (char*)gnt_util_onscreen_width_to_pointer(str, scrcol, &wr); | |
505 *s = '\0'; | |
506 } | |
507 | |
508 if (flags & GNT_TEXT_FLAG_BOLD) | |
509 attr |= A_BOLD; | |
510 if (flags & GNT_TEXT_FLAG_UNDERLINE) | |
511 attr |= A_UNDERLINE; | |
512 if (flags & GNT_TEXT_FLAG_BLINK) | |
513 attr |= A_BLINK; | |
514 | |
515 if (row == tree->current) | |
516 { | |
517 if (gnt_widget_has_focus(widget)) | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20751
diff
changeset
|
518 attr |= gnt_color_pair(GNT_COLOR_HIGHLIGHT); |
15817 | 519 else |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20751
diff
changeset
|
520 attr |= gnt_color_pair(GNT_COLOR_HIGHLIGHT_D); |
15817 | 521 } |
522 else | |
523 { | |
524 if (flags & GNT_TEXT_FLAG_DIM) | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20751
diff
changeset
|
525 attr |= (A_DIM | gnt_color_pair(GNT_COLOR_DISABLED)); |
15817 | 526 else if (flags & GNT_TEXT_FLAG_HIGHLIGHT) |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20751
diff
changeset
|
527 attr |= (A_DIM | gnt_color_pair(GNT_COLOR_HIGHLIGHT)); |
15817 | 528 else |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20751
diff
changeset
|
529 attr |= gnt_color_pair(GNT_COLOR_NORMAL); |
15817 | 530 } |
531 | |
532 wbkgdset(widget->window, '\0' | attr); | |
533 mvwaddstr(widget->window, i, pos, str); | |
534 whline(widget->window, ' ', scrcol - wr); | |
535 tree->bottom = row; | |
536 g_free(str); | |
537 tree_mark_columns(tree, pos, i, | |
538 (tree->show_separator ? ACS_VLINE : ' ') | attr); | |
539 } | |
540 | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20751
diff
changeset
|
541 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_NORMAL)); |
15817 | 542 while (i < widget->priv.height - pos) |
543 { | |
544 mvwhline(widget->window, i, pos, ' ', | |
545 widget->priv.width - pos * 2 - 1); | |
546 tree_mark_columns(tree, pos, i, | |
547 (tree->show_separator ? ACS_VLINE : ' ')); | |
548 i++; | |
549 } | |
550 | |
551 scrcol = widget->priv.width - pos - 1; /* position of the scrollbar */ | |
552 rows--; | |
553 if (rows > 0) | |
554 { | |
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
|
555 int total = 0; |
15817 | 556 int showing, position; |
557 | |
558 get_next_n_opt(tree->root, g_list_length(tree->list), &total); | |
559 showing = rows * rows / MAX(total, 1) + 1; | |
560 showing = MIN(rows, showing); | |
561 | |
562 total -= rows; | |
563 up = get_distance(tree->root, tree->top); | |
564 down = total - up; | |
565 | |
566 position = (rows - showing) * up / MAX(1, up + down); | |
567 position = MAX((tree->top != tree->root), position); | |
568 | |
569 if (showing + position > rows) | |
570 position = rows - showing; | |
571 | |
572 if (showing + position == rows && row) | |
573 position = MAX(0, rows - 1 - showing); | |
574 else if (showing + position < rows && !row) | |
575 position = rows - showing; | |
576 | |
577 position += pos + start + 1; | |
578 | |
579 mvwvline(widget->window, pos + start + 1, scrcol, | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20751
diff
changeset
|
580 ' ' | gnt_color_pair(GNT_COLOR_NORMAL), rows); |
15817 | 581 mvwvline(widget->window, position, scrcol, |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20751
diff
changeset
|
582 ACS_CKBOARD | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D), showing); |
15817 | 583 } |
584 | |
585 mvwaddch(widget->window, start + pos, scrcol, | |
586 ((tree->top != tree->root) ? ACS_UARROW : ' ') | | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20751
diff
changeset
|
587 gnt_color_pair(GNT_COLOR_HIGHLIGHT_D)); |
15817 | 588 |
589 mvwaddch(widget->window, widget->priv.height - pos - 1, scrcol, | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20751
diff
changeset
|
590 (row ? ACS_DARROW : ' ') | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D)); |
15817 | 591 |
16249
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
592 /* 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
|
593 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
|
594 const char *str = gnt_util_onscreen_width_to_pointer(tree->priv->search->str, scrcol - 1, NULL); |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20751
diff
changeset
|
595 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D)); |
16249
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
596 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
|
597 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
|
598 } |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
599 |
15817 | 600 gnt_widget_queue_update(widget); |
601 } | |
602 | |
603 static void | |
604 gnt_tree_draw(GntWidget *widget) | |
605 { | |
606 GntTree *tree = GNT_TREE(widget); | |
607 | |
608 redraw_tree(tree); | |
609 | |
610 GNTDEBUG; | |
611 } | |
612 | |
613 static void | |
614 gnt_tree_size_request(GntWidget *widget) | |
615 { | |
616 if (widget->priv.height == 0) | |
617 widget->priv.height = 10; /* XXX: Why?! */ | |
618 if (widget->priv.width == 0) | |
619 { | |
620 GntTree *tree = GNT_TREE(widget); | |
621 int i, width = 0; | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
622 width = 1 + 2 * (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER)); |
15817 | 623 for (i = 0; i < tree->ncol; i++) |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
624 if (!COLUMN_INVISIBLE(tree, i)) { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
625 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
|
626 if (tree->priv->lastvisible != i) |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
627 width++; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
628 } |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
629 widget->priv.width = width; |
15817 | 630 } |
631 } | |
632 | |
633 static void | |
634 gnt_tree_map(GntWidget *widget) | |
635 { | |
636 GntTree *tree = GNT_TREE(widget); | |
637 if (widget->priv.width == 0 || widget->priv.height == 0) | |
638 { | |
639 gnt_widget_size_request(widget); | |
640 } | |
641 tree->top = tree->root; | |
642 tree->current = tree->root; | |
643 GNTDEBUG; | |
644 } | |
645 | |
646 static void | |
647 tree_selection_changed(GntTree *tree, GntTreeRow *old, GntTreeRow *current) | |
648 { | |
649 g_signal_emit(tree, signals[SIG_SELECTION_CHANGED], 0, old ? old->key : NULL, | |
650 current ? current->key : NULL); | |
651 } | |
652 | |
653 static gboolean | |
654 action_down(GntBindable *bind, GList *null) | |
655 { | |
656 int dist; | |
657 GntTree *tree = GNT_TREE(bind); | |
658 GntTreeRow *old = tree->current; | |
659 GntTreeRow *row = get_next(tree->current); | |
660 if (row == NULL) | |
661 return FALSE; | |
662 tree->current = row; | |
663 if ((dist = get_distance(tree->current, tree->bottom)) < 0) | |
664 gnt_tree_scroll(tree, -dist); | |
665 else | |
666 redraw_tree(tree); | |
667 if (old != tree->current) | |
668 tree_selection_changed(tree, old, tree->current); | |
669 return TRUE; | |
670 } | |
671 | |
672 static gboolean | |
15972
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
673 action_move_parent(GntBindable *bind, GList *null) |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
674 { |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
675 GntTree *tree = GNT_TREE(bind); |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
676 GntTreeRow *row = tree->current; |
16249
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
677 int dist; |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
678 |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
679 if (!row->parent || SEARCHING(tree)) |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
680 return FALSE; |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
681 |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
682 tree->current = row->parent; |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
683 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
|
684 gnt_tree_scroll(tree, -dist); |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
685 else |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
686 redraw_tree(tree); |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
687 tree_selection_changed(tree, row, tree->current); |
15972
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
688 return TRUE; |
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 |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
691 static gboolean |
15817 | 692 action_up(GntBindable *bind, GList *list) |
693 { | |
694 int dist; | |
695 GntTree *tree = GNT_TREE(bind); | |
696 GntTreeRow *old = tree->current; | |
697 GntTreeRow *row = get_prev(tree->current); | |
698 if (!row) | |
699 return FALSE; | |
700 tree->current = row; | |
701 if ((dist = get_distance(tree->current, tree->top)) > 0) | |
702 gnt_tree_scroll(tree, -dist); | |
703 else | |
704 redraw_tree(tree); | |
705 if (old != tree->current) | |
706 tree_selection_changed(tree, old, tree->current); | |
707 | |
708 return TRUE; | |
709 } | |
710 | |
711 static gboolean | |
712 action_page_down(GntBindable *bind, GList *null) | |
713 { | |
714 GntTree *tree = GNT_TREE(bind); | |
715 GntTreeRow *old = tree->current; | |
716 GntTreeRow *row = get_next(tree->bottom); | |
717 if (row) | |
718 { | |
719 int dist = get_distance(tree->top, tree->current); | |
720 tree->top = tree->bottom; | |
721 tree->current = get_next_n_opt(tree->top, dist, NULL); | |
722 redraw_tree(tree); | |
723 } | |
724 else if (tree->current != tree->bottom) | |
725 { | |
726 tree->current = tree->bottom; | |
727 redraw_tree(tree); | |
728 } | |
729 | |
730 if (old != tree->current) | |
731 tree_selection_changed(tree, old, tree->current); | |
732 return TRUE; | |
733 } | |
734 | |
735 static gboolean | |
736 action_page_up(GntBindable *bind, GList *null) | |
737 { | |
738 GntWidget *widget = GNT_WIDGET(bind); | |
739 GntTree *tree = GNT_TREE(bind); | |
740 GntTreeRow *row; | |
741 GntTreeRow *old = tree->current; | |
742 | |
743 if (tree->top != tree->root) | |
744 { | |
745 int dist = get_distance(tree->top, tree->current); | |
746 row = get_prev_n(tree->top, widget->priv.height - 1 - | |
747 tree->show_title * 2 - 2 * (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER) == 0)); | |
748 if (row == NULL) | |
749 row = tree->root; | |
750 tree->top = row; | |
751 tree->current = get_next_n_opt(tree->top, dist, NULL); | |
752 redraw_tree(tree); | |
753 } | |
754 else if (tree->current != tree->top) | |
755 { | |
756 tree->current = tree->top; | |
757 redraw_tree(tree); | |
758 } | |
759 if (old != tree->current) | |
760 tree_selection_changed(tree, old, tree->current); | |
761 return TRUE; | |
762 } | |
763 | |
764 static void | |
765 end_search(GntTree *tree) | |
766 { | |
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
|
767 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
|
768 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
|
769 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
|
770 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
|
771 tree->priv->search_timeout = 0; |
18720
a69ab280147b
Fix a /-search bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18566
diff
changeset
|
772 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(tree), GNT_WIDGET_DISABLE_ACTIONS); |
15817 | 773 } |
774 } | |
775 | |
776 static gboolean | |
777 search_timeout(gpointer data) | |
778 { | |
779 GntTree *tree = data; | |
780 | |
781 end_search(tree); | |
782 redraw_tree(tree); | |
783 | |
784 return FALSE; | |
785 } | |
786 | |
787 static gboolean | |
788 gnt_tree_key_pressed(GntWidget *widget, const char *text) | |
789 { | |
790 GntTree *tree = GNT_TREE(widget); | |
791 GntTreeRow *old = tree->current; | |
792 | |
793 if (text[0] == '\r') { | |
794 end_search(tree); | |
795 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
|
796 } else if (tree->priv->search) { |
16249
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
797 gboolean changed = TRUE; |
15817 | 798 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
|
799 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
|
800 } 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
|
801 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
|
802 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
|
803 } else |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
804 changed = FALSE; |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
805 if (changed) { |
15817 | 806 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
|
807 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
|
808 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
|
809 } else { |
3c634117a7ef
Allow disabling the widget actions on specific widgets. This allows, for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18564
diff
changeset
|
810 gnt_bindable_perform_action_key(GNT_BINDABLE(tree), text); |
15817 | 811 } |
812 return TRUE; | |
813 } else if (text[0] == ' ' && text[1] == 0) { | |
814 /* Space pressed */ | |
815 GntTreeRow *row = tree->current; | |
816 if (row && row->child) | |
817 { | |
818 row->collapsed = !row->collapsed; | |
819 redraw_tree(tree); | |
16105
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
820 g_signal_emit(tree, signals[SIG_COLLAPSED], 0, row->key, row->collapsed); |
15817 | 821 } |
822 else if (row && row->choice) | |
823 { | |
824 row->isselected = !row->isselected; | |
825 g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key); | |
826 redraw_tree(tree); | |
827 } | |
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
|
828 } 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
|
829 return FALSE; |
15817 | 830 } |
831 | |
832 if (old != tree->current) | |
833 { | |
834 tree_selection_changed(tree, old, tree->current); | |
835 } | |
836 | |
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
|
837 return TRUE; |
15817 | 838 } |
839 | |
840 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
|
841 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
|
842 { |
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 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
|
844 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
|
845 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
|
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 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
|
848 } |
ffa46a399f3c
Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
849 |
ffa46a399f3c
Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
850 static void |
15817 | 851 gnt_tree_destroy(GntWidget *widget) |
852 { | |
853 GntTree *tree = GNT_TREE(widget); | |
854 | |
855 end_search(tree); | |
856 if (tree->hash) | |
857 g_hash_table_destroy(tree->hash); | |
858 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
|
859 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
|
860 g_free(tree->priv); |
15817 | 861 } |
862 | |
863 static gboolean | |
864 gnt_tree_clicked(GntWidget *widget, GntMouseEvent event, int x, int y) | |
865 { | |
866 GntTree *tree = GNT_TREE(widget); | |
867 GntTreeRow *old = tree->current; | |
868 if (event == GNT_MOUSE_SCROLL_UP) { | |
869 action_up(GNT_BINDABLE(widget), NULL); | |
870 } else if (event == GNT_MOUSE_SCROLL_DOWN) { | |
871 action_down(GNT_BINDABLE(widget), NULL); | |
872 } else if (event == GNT_LEFT_MOUSE_DOWN) { | |
873 GntTreeRow *row; | |
874 GntTree *tree = GNT_TREE(widget); | |
875 int pos = 1; | |
876 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
877 pos = 0; | |
878 if (tree->show_title) | |
879 pos += 2; | |
880 pos = y - widget->priv.y - pos; | |
881 row = get_next_n(tree->top, pos); | |
882 if (row && tree->current != row) { | |
883 GntTreeRow *old = tree->current; | |
884 tree->current = row; | |
885 redraw_tree(tree); | |
886 tree_selection_changed(tree, old, tree->current); | |
887 } else if (row && row == tree->current) { | |
888 if (row->choice) { | |
889 row->isselected = !row->isselected; | |
890 g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key); | |
891 redraw_tree(tree); | |
892 } else { | |
893 gnt_widget_activate(widget); | |
894 } | |
895 } | |
896 } else { | |
897 return FALSE; | |
898 } | |
899 if (old != tree->current) { | |
900 tree_selection_changed(tree, old, tree->current); | |
901 } | |
902 return TRUE; | |
903 } | |
904 | |
905 static void | |
906 gnt_tree_size_changed(GntWidget *widget, int w, int h) | |
907 { | |
908 GntTree *tree = GNT_TREE(widget); | |
909 if (widget->priv.width <= 0) | |
910 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
|
911 |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
912 readjust_columns(tree); |
15817 | 913 } |
914 | |
915 static gboolean | |
916 start_search(GntBindable *bindable, GList *list) | |
917 { | |
918 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
|
919 if (tree->priv->search) |
15817 | 920 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
|
921 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
|
922 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
|
923 tree->priv->search_timeout = g_timeout_add(SEARCH_TIMEOUT, search_timeout, tree); |
15817 | 924 return TRUE; |
925 } | |
926 | |
927 static gboolean | |
928 end_search_action(GntBindable *bindable, GList *list) | |
929 { | |
930 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
|
931 if (tree->priv->search == NULL) |
15817 | 932 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
|
933 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(tree), GNT_WIDGET_DISABLE_ACTIONS); |
15817 | 934 end_search(tree); |
935 redraw_tree(tree); | |
936 return TRUE; | |
937 } | |
938 | |
939 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
|
940 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
|
941 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
|
942 { |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
943 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
|
944 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
|
945 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
|
946 _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
|
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 default: |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
949 break; |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
950 } |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
951 } |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
952 |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
953 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
|
954 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
|
955 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
|
956 { |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
957 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
|
958 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
|
959 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
|
960 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
|
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 default: |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
963 break; |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
964 } |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
965 } |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
966 |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
967 static void |
15817 | 968 gnt_tree_class_init(GntTreeClass *klass) |
969 { | |
970 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
|
971 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
|
972 |
15817 | 973 parent_class = GNT_WIDGET_CLASS(klass); |
974 parent_class->destroy = gnt_tree_destroy; | |
975 parent_class->draw = gnt_tree_draw; | |
976 parent_class->map = gnt_tree_map; | |
977 parent_class->size_request = gnt_tree_size_request; | |
978 parent_class->key_pressed = gnt_tree_key_pressed; | |
979 parent_class->clicked = gnt_tree_clicked; | |
980 parent_class->size_changed = gnt_tree_size_changed; | |
981 | |
18531
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
982 gclass->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
|
983 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
|
984 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
|
985 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
|
986 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
|
987 "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
|
988 1, G_MAXINT, 1, |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
989 G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
990 ) |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
991 ); |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
992 |
15817 | 993 signals[SIG_SELECTION_CHANGED] = |
994 g_signal_new("selection-changed", | |
995 G_TYPE_FROM_CLASS(klass), | |
996 G_SIGNAL_RUN_LAST, | |
997 G_STRUCT_OFFSET(GntTreeClass, selection_changed), | |
998 NULL, NULL, | |
999 gnt_closure_marshal_VOID__POINTER_POINTER, | |
1000 G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER); | |
1001 signals[SIG_SCROLLED] = | |
1002 g_signal_new("scrolled", | |
1003 G_TYPE_FROM_CLASS(klass), | |
1004 G_SIGNAL_RUN_LAST, | |
1005 0, | |
1006 NULL, NULL, | |
1007 g_cclosure_marshal_VOID__INT, | |
1008 G_TYPE_NONE, 1, G_TYPE_INT); | |
1009 signals[SIG_TOGGLED] = | |
1010 g_signal_new("toggled", | |
1011 G_TYPE_FROM_CLASS(klass), | |
1012 G_SIGNAL_RUN_LAST, | |
1013 G_STRUCT_OFFSET(GntTreeClass, toggled), | |
1014 NULL, NULL, | |
1015 g_cclosure_marshal_VOID__POINTER, | |
1016 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
|
1017 signals[SIG_COLLAPSED] = |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
1018 g_signal_new("collapse-toggled", |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
1019 G_TYPE_FROM_CLASS(klass), |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
1020 G_SIGNAL_RUN_LAST, |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
1021 0, |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
1022 NULL, NULL, |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
1023 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
|
1024 G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_BOOLEAN); |
15817 | 1025 |
1026 gnt_bindable_class_register_action(bindable, "move-up", action_up, | |
1027 GNT_KEY_UP, NULL); | |
1028 gnt_bindable_register_binding(bindable, "move-up", GNT_KEY_CTRL_P, NULL); | |
1029 gnt_bindable_class_register_action(bindable, "move-down", action_down, | |
1030 GNT_KEY_DOWN, NULL); | |
1031 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
|
1032 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
|
1033 GNT_KEY_BACKSPACE, NULL); |
15817 | 1034 gnt_bindable_class_register_action(bindable, "page-up", action_page_up, |
1035 GNT_KEY_PGUP, NULL); | |
1036 gnt_bindable_class_register_action(bindable, "page-down", action_page_down, | |
1037 GNT_KEY_PGDOWN, NULL); | |
1038 gnt_bindable_class_register_action(bindable, "start-search", start_search, | |
1039 "/", NULL); | |
1040 gnt_bindable_class_register_action(bindable, "end-search", end_search_action, | |
1041 "\033", NULL); | |
1042 | |
1043 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), bindable); | |
1044 GNTDEBUG; | |
1045 } | |
1046 | |
1047 static void | |
1048 gnt_tree_init(GTypeInstance *instance, gpointer class) | |
1049 { | |
1050 GntWidget *widget = GNT_WIDGET(instance); | |
1051 GntTree *tree = GNT_TREE(widget); | |
1052 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
|
1053 tree->priv = g_new0(GntTreePriv, 1); |
18720
a69ab280147b
Fix a /-search bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18566
diff
changeset
|
1054 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y | |
a69ab280147b
Fix a /-search bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18566
diff
changeset
|
1055 GNT_WIDGET_CAN_TAKE_FOCUS | GNT_WIDGET_NO_SHADOW); |
a69ab280147b
Fix a /-search bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18566
diff
changeset
|
1056 gnt_widget_set_take_focus(widget, TRUE); |
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 | |
20751
fe77cc691f78
Some doxygen stuff.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
1269 row->tree = tree; |
fe77cc691f78
Some doxygen stuff.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
1270 row->key = key; |
fe77cc691f78
Some doxygen stuff.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
1271 row->data = NULL; |
15817 | 1272 g_hash_table_replace(tree->hash, key, row); |
1273 | |
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
|
1274 if (bigbro == NULL && tree->priv->compare) |
15817 | 1275 { |
1276 bigbro = find_position(tree, key, parent); | |
1277 } | |
1278 | |
1279 if (tree->root == NULL) | |
1280 { | |
1281 tree->root = row; | |
1282 tree->list = g_list_prepend(tree->list, key); | |
1283 } | |
1284 else | |
1285 { | |
1286 int position = 0; | |
1287 | |
1288 if (bigbro) | |
1289 { | |
1290 pr = g_hash_table_lookup(tree->hash, bigbro); | |
1291 if (pr) | |
1292 { | |
1293 if (pr->next) pr->next->prev = row; | |
1294 row->next = pr->next; | |
1295 row->prev = pr; | |
1296 pr->next = row; | |
1297 row->parent = pr->parent; | |
1298 | |
1299 position = g_list_index(tree->list, bigbro); | |
1300 } | |
1301 } | |
1302 | |
1303 if (pr == NULL && parent) | |
1304 { | |
1305 pr = g_hash_table_lookup(tree->hash, parent); | |
1306 if (pr) | |
1307 { | |
1308 if (pr->child) pr->child->prev = row; | |
1309 row->next = pr->child; | |
1310 pr->child = row; | |
1311 row->parent = pr; | |
1312 | |
1313 position = g_list_index(tree->list, parent); | |
1314 } | |
1315 } | |
1316 | |
1317 if (pr == NULL) | |
1318 { | |
1319 GntTreeRow *r = tree->root; | |
1320 row->next = r; | |
1321 if (r) r->prev = row; | |
1322 if (tree->current == tree->root) | |
1323 tree->current = row; | |
1324 tree->root = row; | |
1325 tree->list = g_list_prepend(tree->list, key); | |
1326 } | |
1327 else | |
1328 { | |
1329 tree->list = g_list_insert(tree->list, key, position + 1); | |
1330 } | |
1331 } | |
1332 redraw_tree(tree); | |
1333 | |
1334 return row; | |
1335 } | |
1336 | |
1337 GntTreeRow *gnt_tree_add_row_last(GntTree *tree, void *key, GntTreeRow *row, void *parent) | |
1338 { | |
1339 GntTreeRow *pr = NULL, *br = NULL; | |
1340 | |
1341 if (parent) | |
1342 pr = g_hash_table_lookup(tree->hash, parent); | |
1343 | |
1344 if (pr) | |
1345 br = pr->child; | |
1346 else | |
1347 br = tree->root; | |
1348 | |
1349 if (br) | |
1350 { | |
1351 while (br->next) | |
1352 br = br->next; | |
1353 } | |
1354 | |
1355 return gnt_tree_add_row_after(tree, key, row, parent, br ? br->key : NULL); | |
1356 } | |
1357 | |
1358 gpointer gnt_tree_get_selection_data(GntTree *tree) | |
1359 { | |
1360 if (tree->current) | |
1361 return tree->current->key; /* XXX: perhaps we should just get rid of 'data' */ | |
1362 return NULL; | |
1363 } | |
1364 | |
1365 char *gnt_tree_get_selection_text(GntTree *tree) | |
1366 { | |
1367 if (tree->current) | |
1368 return update_row_text(tree, tree->current); | |
1369 return NULL; | |
1370 } | |
1371 | |
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
|
1372 GList *gnt_tree_get_row_text_list(GntTree *tree, gpointer key) |
15817 | 1373 { |
1374 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
|
1375 GntTreeRow *row = key ? g_hash_table_lookup(tree->hash, key) : tree->current; |
15817 | 1376 int i; |
1377 | |
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
|
1378 if (!row) |
15817 | 1379 return NULL; |
1380 | |
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
|
1381 for (i = 0, iter = row->columns; i < tree->ncol && iter; |
15817 | 1382 i++, iter = iter->next) |
1383 { | |
1384 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
|
1385 list = g_list_append(list, BINARY_DATA(tree, i) ? col->text : g_strdup(col->text)); |
15817 | 1386 } |
1387 | |
1388 return list; | |
1389 } | |
1390 | |
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
|
1391 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
|
1392 { |
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 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
|
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 |
15817 | 1396 void gnt_tree_remove(GntTree *tree, gpointer key) |
1397 { | |
1398 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1399 static int depth = 0; /* Only redraw after all child nodes are removed */ | |
1400 if (row) | |
1401 { | |
1402 gboolean redraw = FALSE; | |
1403 | |
1404 if (row->child) { | |
1405 depth++; | |
1406 while (row->child) { | |
1407 gnt_tree_remove(tree, row->child->key); | |
1408 } | |
1409 depth--; | |
1410 } | |
1411 | |
1412 if (get_distance(tree->top, row) >= 0 && get_distance(row, tree->bottom) >= 0) | |
1413 redraw = TRUE; | |
1414 | |
1415 /* Update root/top/current/bottom if necessary */ | |
1416 if (tree->root == row) | |
1417 tree->root = get_next(row); | |
1418 if (tree->top == row) | |
1419 { | |
1420 if (tree->top != tree->root) | |
1421 tree->top = get_prev(row); | |
1422 else | |
1423 tree->top = get_next(row); | |
1424 } | |
1425 if (tree->current == row) | |
1426 { | |
1427 if (tree->current != tree->root) | |
1428 tree->current = get_prev(row); | |
1429 else | |
1430 tree->current = get_next(row); | |
1431 tree_selection_changed(tree, row, tree->current); | |
1432 } | |
1433 if (tree->bottom == row) | |
1434 { | |
1435 tree->bottom = get_prev(row); | |
1436 } | |
1437 | |
1438 /* Fix the links */ | |
1439 if (row->next) | |
1440 row->next->prev = row->prev; | |
1441 if (row->parent && row->parent->child == row) | |
1442 row->parent->child = row->next; | |
1443 if (row->prev) | |
1444 row->prev->next = row->next; | |
1445 | |
1446 g_hash_table_remove(tree->hash, key); | |
1447 tree->list = g_list_remove(tree->list, key); | |
1448 | |
1449 if (redraw && depth == 0) | |
1450 { | |
1451 redraw_tree(tree); | |
1452 } | |
1453 } | |
1454 } | |
1455 | |
1456 static gboolean | |
1457 return_true(gpointer key, gpointer data, gpointer null) | |
1458 { | |
1459 return TRUE; | |
1460 } | |
1461 | |
1462 void gnt_tree_remove_all(GntTree *tree) | |
1463 { | |
1464 tree->root = NULL; | |
1465 g_hash_table_foreach_remove(tree->hash, (GHRFunc)return_true, tree); | |
1466 g_list_free(tree->list); | |
1467 tree->list = NULL; | |
1468 tree->current = tree->top = tree->bottom = NULL; | |
1469 } | |
1470 | |
1471 int gnt_tree_get_selection_visible_line(GntTree *tree) | |
1472 { | |
1473 return get_distance(tree->top, tree->current) + | |
1474 !!(GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER)); | |
1475 } | |
1476 | |
1477 void gnt_tree_change_text(GntTree *tree, gpointer key, int colno, const char *text) | |
1478 { | |
1479 GntTreeRow *row; | |
1480 GntTreeCol *col; | |
1481 | |
1482 g_return_if_fail(colno < tree->ncol); | |
1483 | |
1484 row = g_hash_table_lookup(tree->hash, key); | |
1485 if (row) | |
1486 { | |
1487 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
|
1488 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
|
1489 col->text = (gpointer)text; |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1490 } else { |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1491 g_free(col->text); |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1492 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
|
1493 } |
15817 | 1494 |
21271
ca16de222b76
Do not do unnecessary processing when updating text in a column.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21264
diff
changeset
|
1495 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_MAPPED) && |
ca16de222b76
Do not do unnecessary processing when updating text in a column.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21264
diff
changeset
|
1496 get_distance(tree->top, row) >= 0 && get_distance(row, tree->bottom) >= 0) |
15817 | 1497 redraw_tree(tree); |
1498 } | |
1499 } | |
1500 | |
1501 GntTreeRow *gnt_tree_add_choice(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro) | |
1502 { | |
1503 GntTreeRow *r; | |
1504 r = g_hash_table_lookup(tree->hash, key); | |
1505 g_return_val_if_fail(!r || !r->choice, NULL); | |
1506 | |
1507 if (bigbro == NULL) { | |
18534
ffa46a399f3c
Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
1508 if (tree->priv->compare) |
15817 | 1509 bigbro = find_position(tree, key, parent); |
1510 else { | |
1511 r = g_hash_table_lookup(tree->hash, parent); | |
1512 if (!r) | |
1513 r = tree->root; | |
1514 else | |
1515 r = r->child; | |
1516 if (r) { | |
1517 while (r->next) | |
1518 r = r->next; | |
1519 bigbro = r->key; | |
1520 } | |
1521 } | |
1522 } | |
1523 row = gnt_tree_add_row_after(tree, key, row, parent, bigbro); | |
1524 row->choice = TRUE; | |
1525 | |
1526 return row; | |
1527 } | |
1528 | |
1529 void gnt_tree_set_choice(GntTree *tree, void *key, gboolean set) | |
1530 { | |
1531 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1532 | |
1533 if (!row) | |
1534 return; | |
1535 g_return_if_fail(row->choice); | |
1536 | |
1537 row->isselected = set; | |
1538 redraw_tree(tree); | |
1539 } | |
1540 | |
1541 gboolean gnt_tree_get_choice(GntTree *tree, void *key) | |
1542 { | |
1543 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1544 | |
1545 if (!row) | |
1546 return FALSE; | |
1547 g_return_val_if_fail(row->choice, FALSE); | |
1548 | |
1549 return row->isselected; | |
1550 } | |
1551 | |
1552 void gnt_tree_set_row_flags(GntTree *tree, void *key, GntTextFormatFlags flags) | |
1553 { | |
1554 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1555 if (!row || row->flags == flags) | |
1556 return; | |
1557 | |
1558 row->flags = flags; | |
1559 redraw_tree(tree); /* XXX: It shouldn't be necessary to redraw the whole darned tree */ | |
1560 } | |
1561 | |
1562 void gnt_tree_set_selected(GntTree *tree , void *key) | |
1563 { | |
1564 int dist; | |
1565 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
16203
4f6a6443a1e3
emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents:
16123
diff
changeset
|
1566 if (!row || row == tree->current) |
15817 | 1567 return; |
1568 | |
1569 if (tree->top == NULL) | |
1570 tree->top = row; | |
1571 if (tree->bottom == NULL) | |
1572 tree->bottom = row; | |
1573 | |
1574 tree->current = row; | |
1575 if ((dist = get_distance(tree->current, tree->bottom)) < 0) | |
1576 gnt_tree_scroll(tree, -dist); | |
1577 else if ((dist = get_distance(tree->current, tree->top)) > 0) | |
1578 gnt_tree_scroll(tree, -dist); | |
1579 else | |
1580 redraw_tree(tree); | |
16203
4f6a6443a1e3
emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents:
16123
diff
changeset
|
1581 tree_selection_changed(tree, row, tree->current); |
15817 | 1582 } |
1583 | |
18531
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
1584 static void _gnt_tree_init_internals(GntTree *tree, int col) |
15817 | 1585 { |
18534
ffa46a399f3c
Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
1586 gnt_tree_free_columns(tree); |
18531
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
1587 |
15817 | 1588 tree->ncol = col; |
1589 tree->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_tree_row); | |
1590 tree->columns = g_new0(struct _GntTreeColInfo, col); | |
18534
ffa46a399f3c
Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
1591 tree->priv->lastvisible = col - 1; |
15817 | 1592 while (col--) |
1593 { | |
1594 tree->columns[col].width = 15; | |
1595 } | |
1596 tree->list = NULL; | |
1597 tree->show_title = FALSE; | |
18531
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
1598 g_object_notify(G_OBJECT(tree), "columns"); |
15817 | 1599 } |
1600 | |
1601 GntWidget *gnt_tree_new_with_columns(int col) | |
1602 { | |
18531
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
1603 GntWidget *widget = g_object_new(GNT_TYPE_TREE, |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
1604 "columns", col, |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
1605 NULL); |
15817 | 1606 |
1607 return widget; | |
1608 } | |
1609 | |
1610 GntTreeRow *gnt_tree_create_row_from_list(GntTree *tree, GList *list) | |
1611 { | |
1612 GList *iter; | |
1613 int i; | |
1614 GntTreeRow *row = g_new0(GntTreeRow, 1); | |
1615 | |
1616 for (i = 0, iter = list; i < tree->ncol && iter; iter = iter->next, i++) | |
1617 { | |
1618 GntTreeCol *col = g_new0(GntTreeCol, 1); | |
1619 col->span = 1; | |
18420
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1620 if (BINARY_DATA(tree, i)) { |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1621 col->text = iter->data; |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1622 col->isbinary = TRUE; |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1623 } else { |
18873
7066896f6628
disapproval of revision 'a4ce7b8adf2db74d531c35278fe83247d90ce4b1'
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18872
diff
changeset
|
1624 col->text = g_strdup(iter->data ? iter->data : ""); |
18420
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1625 col->isbinary = FALSE; |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1626 } |
15817 | 1627 |
1628 row->columns = g_list_append(row->columns, col); | |
1629 } | |
1630 | |
1631 return row; | |
1632 } | |
1633 | |
1634 GntTreeRow *gnt_tree_create_row(GntTree *tree, ...) | |
1635 { | |
1636 int i; | |
1637 va_list args; | |
1638 GList *list = NULL; | |
1639 GntTreeRow *row; | |
1640 | |
1641 va_start(args, tree); | |
1642 for (i = 0; i < tree->ncol; i++) | |
1643 { | |
1644 list = g_list_append(list, va_arg(args, char *)); | |
1645 } | |
1646 va_end(args); | |
1647 | |
1648 row = gnt_tree_create_row_from_list(tree, list); | |
1649 g_list_free(list); | |
1650 | |
1651 return row; | |
1652 } | |
1653 | |
1654 void gnt_tree_set_col_width(GntTree *tree, int col, int width) | |
1655 { | |
1656 g_return_if_fail(col < tree->ncol); | |
1657 | |
1658 tree->columns[col].width = width; | |
18404
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1659 if (tree->columns[col].width_ratio == 0) |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1660 tree->columns[col].width_ratio = width; |
15817 | 1661 } |
1662 | |
18348
1f9db757efc2
Oops. I missed this. This allows setting tree-column titles one by one.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18183
diff
changeset
|
1663 void gnt_tree_set_column_title(GntTree *tree, int index, const char *title) |
1f9db757efc2
Oops. I missed this. This allows setting tree-column titles one by one.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18183
diff
changeset
|
1664 { |
1f9db757efc2
Oops. I missed this. This allows setting tree-column titles one by one.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18183
diff
changeset
|
1665 g_free(tree->columns[index].title); |
1f9db757efc2
Oops. I missed this. This allows setting tree-column titles one by one.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18183
diff
changeset
|
1666 tree->columns[index].title = g_strdup(title); |
1f9db757efc2
Oops. I missed this. This allows setting tree-column titles one by one.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18183
diff
changeset
|
1667 } |
1f9db757efc2
Oops. I missed this. This allows setting tree-column titles one by one.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18183
diff
changeset
|
1668 |
15817 | 1669 void gnt_tree_set_column_titles(GntTree *tree, ...) |
1670 { | |
1671 int i; | |
1672 va_list args; | |
1673 | |
1674 va_start(args, tree); | |
1675 for (i = 0; i < tree->ncol; i++) | |
1676 { | |
1677 const char *title = va_arg(args, const char *); | |
1678 tree->columns[i].title = g_strdup(title); | |
1679 } | |
1680 va_end(args); | |
1681 } | |
1682 | |
1683 void gnt_tree_set_show_title(GntTree *tree, gboolean set) | |
1684 { | |
1685 tree->show_title = set; | |
1686 GNT_WIDGET(tree)->priv.minh = (set ? 6 : 4); | |
1687 } | |
1688 | |
1689 void gnt_tree_set_compare_func(GntTree *tree, GCompareFunc func) | |
1690 { | |
18534
ffa46a399f3c
Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
1691 tree->priv->compare = func; |
15817 | 1692 } |
1693 | |
1694 void gnt_tree_set_expanded(GntTree *tree, void *key, gboolean expanded) | |
1695 { | |
1696 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1697 if (row) { | |
1698 row->collapsed = !expanded; | |
1699 if (GNT_WIDGET(tree)->window) | |
1700 gnt_widget_draw(GNT_WIDGET(tree)); | |
16203
4f6a6443a1e3
emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents:
16123
diff
changeset
|
1701 g_signal_emit(tree, signals[SIG_COLLAPSED], 0, key, row->collapsed); |
15817 | 1702 } |
1703 } | |
1704 | |
1705 void gnt_tree_set_show_separator(GntTree *tree, gboolean set) | |
1706 { | |
1707 tree->show_separator = set; | |
1708 } | |
1709 | |
1710 void gnt_tree_adjust_columns(GntTree *tree) | |
1711 { | |
1712 GntTreeRow *row = tree->root; | |
16123
bc280c341679
We don't need to do anything about the heights here.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16105
diff
changeset
|
1713 int *widths, i, twidth; |
15817 | 1714 |
1715 widths = g_new0(int, tree->ncol); | |
1716 while (row) { | |
1717 GList *iter; | |
1718 for (i = 0, iter = row->columns; iter; iter = iter->next, i++) { | |
1719 GntTreeCol *col = iter->data; | |
1720 int w = gnt_util_onscreen_width(col->text, NULL); | |
15968
0ab73bf1fef1
check-items are wider.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15928
diff
changeset
|
1721 if (i == 0 && row->choice) |
0ab73bf1fef1
check-items are wider.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15928
diff
changeset
|
1722 w += 4; |
15972
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
1723 if (i == 0) { |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
1724 w += find_depth(row) * TAB_SIZE; |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
1725 } |
15817 | 1726 if (widths[i] < w) |
1727 widths[i] = w; | |
1728 } | |
15972
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
1729 row = get_next(row); |
15817 | 1730 } |
1731 | |
1732 twidth = 1 + 2 * (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER)); | |
1733 for (i = 0; i < tree->ncol; i++) { | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1734 if (tree->columns[i].flags & GNT_TREE_COLUMN_FIXED_SIZE) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1735 widths[i] = tree->columns[i].width; |
15817 | 1736 gnt_tree_set_col_width(tree, i, widths[i]); |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1737 if (!COLUMN_INVISIBLE(tree, i)) { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1738 twidth = twidth + widths[i]; |
18534
ffa46a399f3c
Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
1739 if (tree->priv->lastvisible != i) |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1740 twidth += 1; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1741 } |
15817 | 1742 } |
1743 g_free(widths); | |
1744 | |
16123
bc280c341679
We don't need to do anything about the heights here.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16105
diff
changeset
|
1745 gnt_widget_set_size(GNT_WIDGET(tree), twidth, -1); |
15817 | 1746 } |
1747 | |
1748 void gnt_tree_set_hash_fns(GntTree *tree, gpointer hash, gpointer eq, gpointer kd) | |
1749 { | |
1750 g_hash_table_foreach_remove(tree->hash, return_true, NULL); | |
1751 g_hash_table_destroy(tree->hash); | |
1752 tree->hash = g_hash_table_new_full(hash, eq, kd, free_tree_row); | |
1753 } | |
1754 | |
18404
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1755 static void |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1756 set_column_flag(GntTree *tree, int col, GntTreeColumnFlag flag, gboolean set) |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1757 { |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1758 if (set) |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1759 tree->columns[col].flags |= flag; |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1760 else |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1761 tree->columns[col].flags &= ~flag; |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1762 } |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1763 |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
1764 void gnt_tree_set_column_visible(GntTree *tree, int col, gboolean vis) |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
1765 { |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
1766 g_return_if_fail(col < tree->ncol); |
18404
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1767 set_column_flag(tree, col, GNT_TREE_COLUMN_INVISIBLE, !vis); |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1768 if (vis) { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1769 /* the column is visible */ |
18534
ffa46a399f3c
Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
1770 if (tree->priv->lastvisible < col) |
ffa46a399f3c
Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
1771 tree->priv->lastvisible = col; |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1772 } else { |
18534
ffa46a399f3c
Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
1773 if (tree->priv->lastvisible == col) |
ffa46a399f3c
Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
1774 while (tree->priv->lastvisible) { |
ffa46a399f3c
Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
1775 tree->priv->lastvisible--; |
ffa46a399f3c
Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
1776 if (!COLUMN_INVISIBLE(tree, tree->priv->lastvisible)) |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1777 break; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1778 } |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1779 } |
21283
406aa3be6b32
Minor adjustments to prevent a crash, correct a data type and fix drawing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21273
diff
changeset
|
1780 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_MAPPED)) |
406aa3be6b32
Minor adjustments to prevent a crash, correct a data type and fix drawing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21273
diff
changeset
|
1781 readjust_columns(tree); |
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
|
1782 } |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1783 |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1784 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
|
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 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
|
1787 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
|
1788 } |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
1789 |
18420
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1790 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
|
1791 { |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1792 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
|
1793 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
|
1794 } |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1795 |
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
|
1796 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
|
1797 { |
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 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
|
1799 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
|
1800 } |
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 |
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
|
1802 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
|
1803 { |
9a0f99ea664d
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 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
|
1805 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
|
1806 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
|
1807 } |
9a0f99ea664d
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 } |
9a0f99ea664d
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 |
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
|
1810 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
|
1811 { |
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 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
|
1813 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
|
1814 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
|
1815 } |
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 |
18535
fad459189cc5
New feature: successful compilation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18534
diff
changeset
|
1817 gboolean gnt_tree_is_searching(GntTree *tree) |
fad459189cc5
New feature: successful compilation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18534
diff
changeset
|
1818 { |
fad459189cc5
New feature: successful compilation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18534
diff
changeset
|
1819 return (tree->priv->search != NULL); |
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 |
18557
212c2bec5c97
Allow using custom search functions.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18556
diff
changeset
|
1822 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
|
1823 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
|
1824 { |
212c2bec5c97
Allow using custom search functions.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18556
diff
changeset
|
1825 tree->priv->search_func = func; |
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 |