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