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