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