Mercurial > pidgin
annotate finch/libgnt/gnttree.c @ 29792:8b452039c329
propagate from branch 'im.pidgin.pidgin' (head 53abc38e3dfd2e9f8ae8c3e6532379d4b0dc333b)
to branch 'im.pidgin.cpw.malu.ft_thumbnails' (head 4d135ac4918d2e985a66786a6c07473911498c4f)
author | Marcus Lundblad <ml@update.uu.se> |
---|---|
date | Sun, 12 Jul 2009 20:47:45 +0000 |
parents | 28795b39d745 |
children | f769367cccd0 |
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 | |
26440
8df78c06d10e
Save the world.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26439
diff
changeset
|
31 #define SEARCH_TIMEOUT_S 4 /* 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; |
26439
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
24918
diff
changeset
|
423 int current = 0; |
15817 | 424 |
425 if (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_MAPPED)) | |
426 return; | |
427 | |
428 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
429 pos = 0; | |
430 else | |
431 pos = 1; | |
432 | |
433 if (tree->top == NULL) | |
434 tree->top = tree->root; | |
26509
28795b39d745
- Don't bother changing/signalling the selected row from NULL to NULL
Richard Nelson <wabz@pidgin.im>
parents:
26440
diff
changeset
|
435 if (tree->current == NULL && tree->root != NULL) { |
15817 | 436 tree->current = tree->root; |
16203
4f6a6443a1e3
emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents:
16123
diff
changeset
|
437 tree_selection_changed(tree, NULL, tree->current); |
4f6a6443a1e3
emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents:
16123
diff
changeset
|
438 } |
15817 | 439 |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20306
diff
changeset
|
440 wbkgd(widget->window, gnt_color_pair(GNT_COLOR_NORMAL)); |
15817 | 441 |
442 start = 0; | |
443 if (tree->show_title) | |
444 { | |
445 int i; | |
446 int x = pos; | |
447 | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20306
diff
changeset
|
448 mvwhline(widget->window, pos + 1, pos, ACS_HLINE | gnt_color_pair(GNT_COLOR_NORMAL), |
15817 | 449 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
|
450 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
|
451 widget->priv.width - pos - 1); |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
452 |
15817 | 453 for (i = 0; i < tree->ncol; i++) |
454 { | |
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
|
455 if (COLUMN_INVISIBLE(tree, i)) { |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
456 continue; |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
457 } |
18726
68fec9f954dd
Make sure long titles remain within their own cell.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18720
diff
changeset
|
458 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
|
459 NEXT_X; |
15817 | 460 } |
461 if (pos) | |
462 { | |
21264
ad49d9dace9f
Draw the 'header' correctly when not showing borders.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21254
diff
changeset
|
463 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
|
464 (tree->show_separator ? ACS_TTEE : ACS_HLINE) | gnt_color_pair(GNT_COLOR_NORMAL)); |
15817 | 465 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
|
466 (tree->show_separator ? ACS_BTEE : ACS_HLINE) | gnt_color_pair(GNT_COLOR_NORMAL)); |
15817 | 467 } |
468 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
|
469 (tree->show_separator ? ACS_PLUS : ACS_HLINE) | gnt_color_pair(GNT_COLOR_NORMAL)); |
15817 | 470 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
|
471 (tree->show_separator ? ACS_VLINE : ' ') | gnt_color_pair(GNT_COLOR_NORMAL)); |
15817 | 472 start = 2; |
473 } | |
474 | |
475 rows = widget->priv.height - pos * 2 - start - 1; | |
476 tree->bottom = get_next_n_opt(tree->top, rows, &down); | |
477 if (down < rows) | |
478 { | |
479 tree->top = get_prev_n(tree->bottom, rows); | |
480 if (tree->top == NULL) | |
481 tree->top = tree->root; | |
482 } | |
483 | |
484 up = get_distance(tree->top, tree->current); | |
485 if (up < 0) | |
486 tree->top = tree->current; | |
487 else if (up >= widget->priv.height - pos) | |
488 tree->top = get_prev_n(tree->current, rows); | |
489 | |
490 if (tree->top && !row_matches_search(tree->top)) | |
491 tree->top = get_next(tree->top); | |
492 row = tree->top; | |
493 scrcol = widget->priv.width - 1 - 2 * pos; /* exclude the borders and the scrollbar */ | |
26509
28795b39d745
- Don't bother changing/signalling the selected row from NULL to NULL
Richard Nelson <wabz@pidgin.im>
parents:
26440
diff
changeset
|
494 |
28795b39d745
- Don't bother changing/signalling the selected row from NULL to NULL
Richard Nelson <wabz@pidgin.im>
parents:
26440
diff
changeset
|
495 if (tree->current && !row_matches_search(tree->current)) { |
28795b39d745
- Don't bother changing/signalling the selected row from NULL to NULL
Richard Nelson <wabz@pidgin.im>
parents:
26440
diff
changeset
|
496 GntTreeRow *old = tree->current; |
28795b39d745
- Don't bother changing/signalling the selected row from NULL to NULL
Richard Nelson <wabz@pidgin.im>
parents:
26440
diff
changeset
|
497 tree->current = tree->top; |
28795b39d745
- Don't bother changing/signalling the selected row from NULL to NULL
Richard Nelson <wabz@pidgin.im>
parents:
26440
diff
changeset
|
498 tree_selection_changed(tree, old, tree->current); |
28795b39d745
- Don't bother changing/signalling the selected row from NULL to NULL
Richard Nelson <wabz@pidgin.im>
parents:
26440
diff
changeset
|
499 } |
28795b39d745
- Don't bother changing/signalling the selected row from NULL to NULL
Richard Nelson <wabz@pidgin.im>
parents:
26440
diff
changeset
|
500 |
15817 | 501 for (i = start + pos; row && i < widget->priv.height - pos; |
502 i++, row = get_next(row)) | |
503 { | |
504 char *str; | |
505 int wr; | |
506 | |
507 GntTextFormatFlags flags = row->flags; | |
508 int attr = 0; | |
509 | |
510 if (!row_matches_search(row)) | |
511 continue; | |
512 str = update_row_text(tree, row); | |
513 | |
514 if ((wr = gnt_util_onscreen_width(str, NULL)) > scrcol) | |
515 { | |
516 char *s = (char*)gnt_util_onscreen_width_to_pointer(str, scrcol, &wr); | |
517 *s = '\0'; | |
518 } | |
519 | |
520 if (flags & GNT_TEXT_FLAG_BOLD) | |
521 attr |= A_BOLD; | |
522 if (flags & GNT_TEXT_FLAG_UNDERLINE) | |
523 attr |= A_UNDERLINE; | |
524 if (flags & GNT_TEXT_FLAG_BLINK) | |
525 attr |= A_BLINK; | |
526 | |
527 if (row == tree->current) | |
528 { | |
26439
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
24918
diff
changeset
|
529 current = i; |
24918
55f4261e1358
Boldify the selected row in the tree. This is helpful when, for example,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23342
diff
changeset
|
530 attr |= A_BOLD; |
15817 | 531 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
|
532 attr |= gnt_color_pair(GNT_COLOR_HIGHLIGHT); |
15817 | 533 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
|
534 attr |= gnt_color_pair(GNT_COLOR_HIGHLIGHT_D); |
15817 | 535 } |
536 else | |
537 { | |
538 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
|
539 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
|
540 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
|
541 else |
3ed9b027479d
Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents:
21283
diff
changeset
|
542 attr |= (A_DIM | gnt_color_pair(GNT_COLOR_DISABLED)); |
15817 | 543 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
|
544 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
|
545 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
|
546 attr |= gnt_color_pair(row->color); |
15817 | 547 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
|
548 attr |= gnt_color_pair(GNT_COLOR_NORMAL); |
15817 | 549 } |
550 | |
551 wbkgdset(widget->window, '\0' | attr); | |
552 mvwaddstr(widget->window, i, pos, str); | |
553 whline(widget->window, ' ', scrcol - wr); | |
554 tree->bottom = row; | |
555 g_free(str); | |
556 tree_mark_columns(tree, pos, i, | |
557 (tree->show_separator ? ACS_VLINE : ' ') | attr); | |
558 } | |
559 | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20306
diff
changeset
|
560 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_NORMAL)); |
15817 | 561 while (i < widget->priv.height - pos) |
562 { | |
563 mvwhline(widget->window, i, pos, ' ', | |
564 widget->priv.width - pos * 2 - 1); | |
565 tree_mark_columns(tree, pos, i, | |
566 (tree->show_separator ? ACS_VLINE : ' ')); | |
567 i++; | |
568 } | |
569 | |
570 scrcol = widget->priv.width - pos - 1; /* position of the scrollbar */ | |
571 rows--; | |
572 if (rows > 0) | |
573 { | |
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
|
574 int total = 0; |
15817 | 575 int showing, position; |
576 | |
577 get_next_n_opt(tree->root, g_list_length(tree->list), &total); | |
578 showing = rows * rows / MAX(total, 1) + 1; | |
579 showing = MIN(rows, showing); | |
580 | |
581 total -= rows; | |
582 up = get_distance(tree->root, tree->top); | |
583 down = total - up; | |
584 | |
585 position = (rows - showing) * up / MAX(1, up + down); | |
586 position = MAX((tree->top != tree->root), position); | |
587 | |
588 if (showing + position > rows) | |
589 position = rows - showing; | |
590 | |
591 if (showing + position == rows && row) | |
592 position = MAX(0, rows - 1 - showing); | |
593 else if (showing + position < rows && !row) | |
594 position = rows - showing; | |
595 | |
596 position += pos + start + 1; | |
597 | |
598 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
|
599 ' ' | gnt_color_pair(GNT_COLOR_NORMAL), rows); |
15817 | 600 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
|
601 ACS_CKBOARD | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D), showing); |
15817 | 602 } |
603 | |
604 mvwaddch(widget->window, start + pos, scrcol, | |
605 ((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
|
606 gnt_color_pair(GNT_COLOR_HIGHLIGHT_D)); |
15817 | 607 |
608 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
|
609 (row ? ACS_DARROW : ' ') | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D)); |
15817 | 610 |
16249
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
611 /* 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
|
612 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
|
613 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
|
614 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
|
615 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
|
616 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
|
617 } |
26439
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
24918
diff
changeset
|
618 wmove(widget->window, current, pos); |
16249
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
619 |
15817 | 620 gnt_widget_queue_update(widget); |
621 } | |
622 | |
623 static void | |
624 gnt_tree_draw(GntWidget *widget) | |
625 { | |
626 GntTree *tree = GNT_TREE(widget); | |
627 | |
628 redraw_tree(tree); | |
629 | |
630 GNTDEBUG; | |
631 } | |
632 | |
633 static void | |
634 gnt_tree_size_request(GntWidget *widget) | |
635 { | |
636 if (widget->priv.height == 0) | |
637 widget->priv.height = 10; /* XXX: Why?! */ | |
638 if (widget->priv.width == 0) | |
639 { | |
640 GntTree *tree = GNT_TREE(widget); | |
641 int i, width = 0; | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
642 width = 1 + 2 * (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER)); |
15817 | 643 for (i = 0; i < tree->ncol; i++) |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
644 if (!COLUMN_INVISIBLE(tree, i)) { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
645 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
|
646 if (tree->priv->lastvisible != i) |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
647 width++; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
648 } |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
649 widget->priv.width = width; |
15817 | 650 } |
651 } | |
652 | |
653 static void | |
654 gnt_tree_map(GntWidget *widget) | |
655 { | |
656 GntTree *tree = GNT_TREE(widget); | |
657 if (widget->priv.width == 0 || widget->priv.height == 0) | |
658 { | |
659 gnt_widget_size_request(widget); | |
660 } | |
661 tree->top = tree->root; | |
662 tree->current = tree->root; | |
663 GNTDEBUG; | |
664 } | |
665 | |
666 static void | |
667 tree_selection_changed(GntTree *tree, GntTreeRow *old, GntTreeRow *current) | |
668 { | |
669 g_signal_emit(tree, signals[SIG_SELECTION_CHANGED], 0, old ? old->key : NULL, | |
670 current ? current->key : NULL); | |
671 } | |
672 | |
673 static gboolean | |
674 action_down(GntBindable *bind, GList *null) | |
675 { | |
676 int dist; | |
677 GntTree *tree = GNT_TREE(bind); | |
678 GntTreeRow *old = tree->current; | |
679 GntTreeRow *row = get_next(tree->current); | |
680 if (row == NULL) | |
681 return FALSE; | |
682 tree->current = row; | |
683 if ((dist = get_distance(tree->current, tree->bottom)) < 0) | |
684 gnt_tree_scroll(tree, -dist); | |
685 else | |
686 redraw_tree(tree); | |
687 if (old != tree->current) | |
688 tree_selection_changed(tree, old, tree->current); | |
689 return TRUE; | |
690 } | |
691 | |
692 static gboolean | |
15972
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
693 action_move_parent(GntBindable *bind, GList *null) |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
694 { |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
695 GntTree *tree = GNT_TREE(bind); |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
696 GntTreeRow *row = tree->current; |
16249
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
697 int dist; |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
698 |
22233
782df0fd9e5e
Fix a crash when pressing backspace at a menu
Richard Nelson <wabz@pidgin.im>
parents:
22189
diff
changeset
|
699 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
|
700 return FALSE; |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
701 |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
702 tree->current = row->parent; |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
703 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
|
704 gnt_tree_scroll(tree, -dist); |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
705 else |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
706 redraw_tree(tree); |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
707 tree_selection_changed(tree, row, tree->current); |
15972
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
708 return TRUE; |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
709 } |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
710 |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
711 static gboolean |
15817 | 712 action_up(GntBindable *bind, GList *list) |
713 { | |
714 int dist; | |
715 GntTree *tree = GNT_TREE(bind); | |
716 GntTreeRow *old = tree->current; | |
717 GntTreeRow *row = get_prev(tree->current); | |
718 if (!row) | |
719 return FALSE; | |
720 tree->current = row; | |
721 if ((dist = get_distance(tree->current, tree->top)) > 0) | |
722 gnt_tree_scroll(tree, -dist); | |
723 else | |
724 redraw_tree(tree); | |
725 if (old != tree->current) | |
726 tree_selection_changed(tree, old, tree->current); | |
727 | |
728 return TRUE; | |
729 } | |
730 | |
731 static gboolean | |
732 action_page_down(GntBindable *bind, GList *null) | |
733 { | |
734 GntTree *tree = GNT_TREE(bind); | |
735 GntTreeRow *old = tree->current; | |
736 GntTreeRow *row = get_next(tree->bottom); | |
737 if (row) | |
738 { | |
739 int dist = get_distance(tree->top, tree->current); | |
740 tree->top = tree->bottom; | |
741 tree->current = get_next_n_opt(tree->top, dist, NULL); | |
742 redraw_tree(tree); | |
743 } | |
744 else if (tree->current != tree->bottom) | |
745 { | |
746 tree->current = tree->bottom; | |
747 redraw_tree(tree); | |
748 } | |
749 | |
750 if (old != tree->current) | |
751 tree_selection_changed(tree, old, tree->current); | |
752 return TRUE; | |
753 } | |
754 | |
755 static gboolean | |
756 action_page_up(GntBindable *bind, GList *null) | |
757 { | |
758 GntWidget *widget = GNT_WIDGET(bind); | |
759 GntTree *tree = GNT_TREE(bind); | |
760 GntTreeRow *row; | |
761 GntTreeRow *old = tree->current; | |
762 | |
763 if (tree->top != tree->root) | |
764 { | |
765 int dist = get_distance(tree->top, tree->current); | |
766 row = get_prev_n(tree->top, widget->priv.height - 1 - | |
767 tree->show_title * 2 - 2 * (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER) == 0)); | |
768 if (row == NULL) | |
769 row = tree->root; | |
770 tree->top = row; | |
771 tree->current = get_next_n_opt(tree->top, dist, NULL); | |
772 redraw_tree(tree); | |
773 } | |
774 else if (tree->current != tree->top) | |
775 { | |
776 tree->current = tree->top; | |
777 redraw_tree(tree); | |
778 } | |
779 if (old != tree->current) | |
780 tree_selection_changed(tree, old, tree->current); | |
781 return TRUE; | |
782 } | |
783 | |
784 static void | |
785 end_search(GntTree *tree) | |
786 { | |
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
|
787 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
|
788 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
|
789 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
|
790 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
|
791 tree->priv->search_timeout = 0; |
18720
a69ab280147b
Fix a /-search bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18566
diff
changeset
|
792 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(tree), GNT_WIDGET_DISABLE_ACTIONS); |
15817 | 793 } |
794 } | |
795 | |
796 static gboolean | |
797 search_timeout(gpointer data) | |
798 { | |
799 GntTree *tree = data; | |
800 | |
801 end_search(tree); | |
802 redraw_tree(tree); | |
803 | |
804 return FALSE; | |
805 } | |
806 | |
807 static gboolean | |
808 gnt_tree_key_pressed(GntWidget *widget, const char *text) | |
809 { | |
810 GntTree *tree = GNT_TREE(widget); | |
811 GntTreeRow *old = tree->current; | |
812 | |
22289
0ba0f2804299
'\n' (ctrl-j) should behave similar to '\r' (ctrl-m). Fixes #4833.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22233
diff
changeset
|
813 if (text[0] == '\r' || text[0] == '\n') { |
15817 | 814 end_search(tree); |
815 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
|
816 } else if (tree->priv->search) { |
16249
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
817 gboolean changed = TRUE; |
15817 | 818 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
|
819 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
|
820 } 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
|
821 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
|
822 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
|
823 } else |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
824 changed = FALSE; |
f02e611bdb6b
Show the search string in the tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16203
diff
changeset
|
825 if (changed) { |
15817 | 826 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
|
827 } else { |
3c634117a7ef
Allow disabling the widget actions on specific widgets. This allows, for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18564
diff
changeset
|
828 gnt_bindable_perform_action_key(GNT_BINDABLE(tree), text); |
15817 | 829 } |
22997
6843c06f5c6a
Pressing arrow keys should reset the search timer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22289
diff
changeset
|
830 g_source_remove(tree->priv->search_timeout); |
26440
8df78c06d10e
Save the world.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26439
diff
changeset
|
831 tree->priv->search_timeout = g_timeout_add_seconds(SEARCH_TIMEOUT_S, search_timeout, tree); |
15817 | 832 return TRUE; |
833 } else if (text[0] == ' ' && text[1] == 0) { | |
834 /* Space pressed */ | |
835 GntTreeRow *row = tree->current; | |
836 if (row && row->child) | |
837 { | |
838 row->collapsed = !row->collapsed; | |
839 redraw_tree(tree); | |
16105
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
840 g_signal_emit(tree, signals[SIG_COLLAPSED], 0, row->key, row->collapsed); |
15817 | 841 } |
842 else if (row && row->choice) | |
843 { | |
844 row->isselected = !row->isselected; | |
845 g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key); | |
846 redraw_tree(tree); | |
847 } | |
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
|
848 } 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
|
849 return FALSE; |
15817 | 850 } |
851 | |
852 if (old != tree->current) | |
853 { | |
854 tree_selection_changed(tree, old, tree->current); | |
855 } | |
856 | |
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
|
857 return TRUE; |
15817 | 858 } |
859 | |
860 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
|
861 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
|
862 { |
ffa46a399f3c
Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
863 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
|
864 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
|
865 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
|
866 } |
ffa46a399f3c
Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
867 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
|
868 } |
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 |
ffa46a399f3c
Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
870 static void |
15817 | 871 gnt_tree_destroy(GntWidget *widget) |
872 { | |
873 GntTree *tree = GNT_TREE(widget); | |
874 | |
875 end_search(tree); | |
876 if (tree->hash) | |
877 g_hash_table_destroy(tree->hash); | |
878 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
|
879 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
|
880 g_free(tree->priv); |
15817 | 881 } |
882 | |
883 static gboolean | |
884 gnt_tree_clicked(GntWidget *widget, GntMouseEvent event, int x, int y) | |
885 { | |
886 GntTree *tree = GNT_TREE(widget); | |
887 GntTreeRow *old = tree->current; | |
888 if (event == GNT_MOUSE_SCROLL_UP) { | |
889 action_up(GNT_BINDABLE(widget), NULL); | |
890 } else if (event == GNT_MOUSE_SCROLL_DOWN) { | |
891 action_down(GNT_BINDABLE(widget), NULL); | |
892 } else if (event == GNT_LEFT_MOUSE_DOWN) { | |
893 GntTreeRow *row; | |
894 GntTree *tree = GNT_TREE(widget); | |
895 int pos = 1; | |
896 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
897 pos = 0; | |
898 if (tree->show_title) | |
899 pos += 2; | |
900 pos = y - widget->priv.y - pos; | |
901 row = get_next_n(tree->top, pos); | |
902 if (row && tree->current != row) { | |
903 GntTreeRow *old = tree->current; | |
904 tree->current = row; | |
905 redraw_tree(tree); | |
906 tree_selection_changed(tree, old, tree->current); | |
907 } else if (row && row == tree->current) { | |
908 if (row->choice) { | |
909 row->isselected = !row->isselected; | |
910 g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key); | |
911 redraw_tree(tree); | |
912 } else { | |
913 gnt_widget_activate(widget); | |
914 } | |
915 } | |
916 } else { | |
917 return FALSE; | |
918 } | |
919 if (old != tree->current) { | |
920 tree_selection_changed(tree, old, tree->current); | |
921 } | |
922 return TRUE; | |
923 } | |
924 | |
925 static void | |
926 gnt_tree_size_changed(GntWidget *widget, int w, int h) | |
927 { | |
928 GntTree *tree = GNT_TREE(widget); | |
929 if (widget->priv.width <= 0) | |
930 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
|
931 |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
932 readjust_columns(tree); |
15817 | 933 } |
934 | |
935 static gboolean | |
936 start_search(GntBindable *bindable, GList *list) | |
937 { | |
938 GntTree *tree = GNT_TREE(bindable); | |
18534
ffa46a399f3c
Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
939 if (tree->priv->search) |
15817 | 940 return FALSE; |
18566
3c634117a7ef
Allow disabling the widget actions on specific widgets. This allows, for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18564
diff
changeset
|
941 GNT_WIDGET_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
|
942 tree->priv->search = g_string_new(NULL); |
26440
8df78c06d10e
Save the world.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26439
diff
changeset
|
943 tree->priv->search_timeout = g_timeout_add_seconds(SEARCH_TIMEOUT_S, search_timeout, tree); |
15817 | 944 return TRUE; |
945 } | |
946 | |
947 static gboolean | |
948 end_search_action(GntBindable *bindable, GList *list) | |
949 { | |
950 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
|
951 if (tree->priv->search == NULL) |
15817 | 952 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
|
953 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(tree), GNT_WIDGET_DISABLE_ACTIONS); |
15817 | 954 end_search(tree); |
955 redraw_tree(tree); | |
956 return TRUE; | |
957 } | |
958 | |
959 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
|
960 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
|
961 GParamSpec *spec) |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
962 { |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
963 GntTree *tree = GNT_TREE(obj); |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
964 switch (prop_id) { |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
965 case PROP_COLUMNS: |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
966 _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
|
967 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
|
968 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
|
969 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
|
970 break; |
4165bcd57486
Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22179
diff
changeset
|
971 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
|
972 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
|
973 default: |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
974 break; |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
975 } |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
976 } |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
977 |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
978 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
|
979 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
|
980 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
|
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 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
|
983 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
|
984 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
|
985 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
|
986 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
|
987 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
|
988 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
|
989 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
|
990 default: |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
991 break; |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
992 } |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
993 } |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
994 |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
995 static void |
15817 | 996 gnt_tree_class_init(GntTreeClass *klass) |
997 { | |
998 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
|
999 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
|
1000 |
15817 | 1001 parent_class = GNT_WIDGET_CLASS(klass); |
1002 parent_class->destroy = gnt_tree_destroy; | |
1003 parent_class->draw = gnt_tree_draw; | |
1004 parent_class->map = gnt_tree_map; | |
1005 parent_class->size_request = gnt_tree_size_request; | |
1006 parent_class->key_pressed = gnt_tree_key_pressed; | |
1007 parent_class->clicked = gnt_tree_clicked; | |
1008 parent_class->size_changed = gnt_tree_size_changed; | |
1009 | |
18531
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
1010 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
|
1011 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
|
1012 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
|
1013 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
|
1014 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
|
1015 "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
|
1016 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
|
1017 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
|
1018 ) |
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
1019 ); |
22189
4165bcd57486
Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22179
diff
changeset
|
1020 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
|
1021 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
|
1022 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
|
1023 "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
|
1024 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
|
1025 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
|
1026 ) |
4165bcd57486
Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22179
diff
changeset
|
1027 ); |
18531
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
1028 |
15817 | 1029 signals[SIG_SELECTION_CHANGED] = |
1030 g_signal_new("selection-changed", | |
1031 G_TYPE_FROM_CLASS(klass), | |
1032 G_SIGNAL_RUN_LAST, | |
1033 G_STRUCT_OFFSET(GntTreeClass, selection_changed), | |
1034 NULL, NULL, | |
1035 gnt_closure_marshal_VOID__POINTER_POINTER, | |
1036 G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER); | |
1037 signals[SIG_SCROLLED] = | |
1038 g_signal_new("scrolled", | |
1039 G_TYPE_FROM_CLASS(klass), | |
1040 G_SIGNAL_RUN_LAST, | |
1041 0, | |
1042 NULL, NULL, | |
1043 g_cclosure_marshal_VOID__INT, | |
1044 G_TYPE_NONE, 1, G_TYPE_INT); | |
1045 signals[SIG_TOGGLED] = | |
1046 g_signal_new("toggled", | |
1047 G_TYPE_FROM_CLASS(klass), | |
1048 G_SIGNAL_RUN_LAST, | |
1049 G_STRUCT_OFFSET(GntTreeClass, toggled), | |
1050 NULL, NULL, | |
1051 g_cclosure_marshal_VOID__POINTER, | |
1052 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
|
1053 signals[SIG_COLLAPSED] = |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
1054 g_signal_new("collapse-toggled", |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
1055 G_TYPE_FROM_CLASS(klass), |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
1056 G_SIGNAL_RUN_LAST, |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
1057 0, |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
1058 NULL, NULL, |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15972
diff
changeset
|
1059 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
|
1060 G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_BOOLEAN); |
15817 | 1061 |
1062 gnt_bindable_class_register_action(bindable, "move-up", action_up, | |
1063 GNT_KEY_UP, NULL); | |
1064 gnt_bindable_register_binding(bindable, "move-up", GNT_KEY_CTRL_P, NULL); | |
1065 gnt_bindable_class_register_action(bindable, "move-down", action_down, | |
1066 GNT_KEY_DOWN, NULL); | |
1067 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
|
1068 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
|
1069 GNT_KEY_BACKSPACE, NULL); |
15817 | 1070 gnt_bindable_class_register_action(bindable, "page-up", action_page_up, |
1071 GNT_KEY_PGUP, NULL); | |
1072 gnt_bindable_class_register_action(bindable, "page-down", action_page_down, | |
1073 GNT_KEY_PGDOWN, NULL); | |
1074 gnt_bindable_class_register_action(bindable, "start-search", start_search, | |
1075 "/", NULL); | |
1076 gnt_bindable_class_register_action(bindable, "end-search", end_search_action, | |
1077 "\033", NULL); | |
1078 | |
1079 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), bindable); | |
1080 GNTDEBUG; | |
1081 } | |
1082 | |
1083 static void | |
1084 gnt_tree_init(GTypeInstance *instance, gpointer class) | |
1085 { | |
1086 GntWidget *widget = GNT_WIDGET(instance); | |
1087 GntTree *tree = GNT_TREE(widget); | |
1088 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
|
1089 tree->priv = g_new0(GntTreePriv, 1); |
18720
a69ab280147b
Fix a /-search bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18566
diff
changeset
|
1090 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
|
1091 GNT_WIDGET_CAN_TAKE_FOCUS | GNT_WIDGET_NO_SHADOW); |
a69ab280147b
Fix a /-search bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18566
diff
changeset
|
1092 gnt_widget_set_take_focus(widget, TRUE); |
15817 | 1093 widget->priv.minw = 4; |
1094 widget->priv.minh = 1; | |
1095 GNTDEBUG; | |
1096 } | |
1097 | |
1098 /****************************************************************************** | |
1099 * GntTree API | |
1100 *****************************************************************************/ | |
1101 GType | |
1102 gnt_tree_get_gtype(void) | |
1103 { | |
1104 static GType type = 0; | |
1105 | |
1106 if(type == 0) | |
1107 { | |
1108 static const GTypeInfo info = { | |
1109 sizeof(GntTreeClass), | |
1110 NULL, /* base_init */ | |
1111 NULL, /* base_finalize */ | |
1112 (GClassInitFunc)gnt_tree_class_init, | |
1113 NULL, /* class_finalize */ | |
1114 NULL, /* class_data */ | |
1115 sizeof(GntTree), | |
1116 0, /* n_preallocs */ | |
1117 gnt_tree_init, /* instance_init */ | |
1118 NULL /* value_table */ | |
1119 }; | |
1120 | |
1121 type = g_type_register_static(GNT_TYPE_WIDGET, | |
1122 "GntTree", | |
1123 &info, 0); | |
1124 } | |
1125 | |
1126 return type; | |
1127 } | |
1128 | |
1129 static void | |
1130 free_tree_col(gpointer data) | |
1131 { | |
1132 GntTreeCol *col = data; | |
18811 | 1133 if (!col->isbinary) |
18420
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1134 g_free(col->text); |
15817 | 1135 g_free(col); |
1136 } | |
1137 | |
1138 static void | |
1139 free_tree_row(gpointer data) | |
1140 { | |
1141 GntTreeRow *row = data; | |
1142 | |
1143 if (!row) | |
1144 return; | |
1145 | |
1146 g_list_foreach(row->columns, (GFunc)free_tree_col, NULL); | |
1147 g_list_free(row->columns); | |
1148 g_free(row); | |
1149 } | |
1150 | |
1151 GntWidget *gnt_tree_new() | |
1152 { | |
1153 return gnt_tree_new_with_columns(1); | |
1154 } | |
1155 | |
1156 void gnt_tree_set_visible_rows(GntTree *tree, int rows) | |
1157 { | |
1158 GntWidget *widget = GNT_WIDGET(tree); | |
1159 widget->priv.height = rows; | |
1160 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
1161 widget->priv.height += 2; | |
1162 } | |
1163 | |
1164 int gnt_tree_get_visible_rows(GntTree *tree) | |
1165 { | |
1166 GntWidget *widget = GNT_WIDGET(tree); | |
1167 int ret = widget->priv.height; | |
1168 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
1169 ret -= 2; | |
1170 return ret; | |
1171 } | |
1172 | |
18118
ab6d2763b8d8
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@wiktel.com>
parents:
18098
diff
changeset
|
1173 GList *gnt_tree_get_rows(GntTree *tree) |
15817 | 1174 { |
1175 return tree->list; | |
1176 } | |
1177 | |
1178 void gnt_tree_scroll(GntTree *tree, int count) | |
1179 { | |
1180 GntTreeRow *row; | |
1181 | |
1182 if (count < 0) | |
1183 { | |
1184 if (get_root_distance(tree->top) == 0) | |
1185 return; | |
1186 row = get_prev_n(tree->top, -count); | |
1187 if (row == NULL) | |
1188 row = tree->root; | |
1189 tree->top = row; | |
1190 } | |
1191 else | |
1192 { | |
1193 get_next_n_opt(tree->bottom, count, &count); | |
1194 tree->top = get_next_n(tree->top, count); | |
1195 } | |
1196 | |
1197 redraw_tree(tree); | |
1198 g_signal_emit(tree, signals[SIG_SCROLLED], 0, count); | |
1199 } | |
1200 | |
1201 static gpointer | |
1202 find_position(GntTree *tree, gpointer key, gpointer parent) | |
1203 { | |
1204 GntTreeRow *row; | |
1205 | |
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
|
1206 if (tree->priv->compare == NULL) |
15817 | 1207 return NULL; |
1208 | |
1209 if (parent == NULL) | |
1210 row = tree->root; | |
1211 else | |
1212 row = g_hash_table_lookup(tree->hash, parent); | |
1213 | |
1214 if (!row) | |
1215 return NULL; | |
1216 | |
1217 if (parent) | |
1218 row = row->child; | |
1219 | |
1220 while (row) | |
1221 { | |
18534
ffa46a399f3c
Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
1222 if (tree->priv->compare(key, row->key) < 0) |
15817 | 1223 return (row->prev ? row->prev->key : NULL); |
1224 if (row->next) | |
1225 row = row->next; | |
1226 else | |
1227 return row->key; | |
1228 } | |
1229 return NULL; | |
1230 } | |
1231 | |
1232 void gnt_tree_sort_row(GntTree *tree, gpointer key) | |
1233 { | |
1234 GntTreeRow *row, *q, *s; | |
1235 int current, newp; | |
1236 | |
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
|
1237 if (!tree->priv->compare) |
15817 | 1238 return; |
1239 | |
1240 row = g_hash_table_lookup(tree->hash, key); | |
1241 g_return_if_fail(row != NULL); | |
1242 | |
1243 current = g_list_index(tree->list, key); | |
1244 | |
1245 if (row->parent) | |
1246 s = row->parent->child; | |
1247 else | |
1248 s = tree->root; | |
1249 | |
1250 q = NULL; | |
1251 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
|
1252 if (tree->priv->compare(row->key, s->key) < 0) |
15817 | 1253 break; |
1254 q = s; | |
1255 s = s->next; | |
1256 } | |
1257 | |
1258 /* Move row between q and s */ | |
1259 if (row == q || row == s) | |
1260 return; | |
1261 | |
1262 if (q == NULL) { | |
1263 /* row becomes the first child of its parent */ | |
1264 row->prev->next = row->next; /* row->prev cannot be NULL at this point */ | |
1265 if (row->next) | |
1266 row->next->prev = row->prev; | |
1267 if (row->parent) | |
1268 row->parent->child = row; | |
1269 else | |
1270 tree->root = row; | |
1271 row->next = s; | |
1272 s->prev = row; /* s cannot be NULL */ | |
1273 row->prev = NULL; | |
1274 newp = g_list_index(tree->list, s) - 1; | |
1275 } else { | |
1276 if (row->prev) { | |
1277 row->prev->next = row->next; | |
1278 } else { | |
1279 /* row was the first child of its parent */ | |
1280 if (row->parent) | |
1281 row->parent->child = row->next; | |
1282 else | |
1283 tree->top = row->next; | |
1284 } | |
1285 | |
1286 if (row->next) | |
1287 row->next->prev = row->prev; | |
1288 | |
1289 q->next = row; | |
1290 row->prev = q; | |
1291 if (s) | |
1292 s->prev = row; | |
1293 row->next = s; | |
1294 newp = g_list_index(tree->list, q) + 1; | |
1295 } | |
1296 tree->list = g_list_reposition_child(tree->list, current, newp); | |
1297 | |
1298 redraw_tree(tree); | |
1299 } | |
1300 | |
1301 GntTreeRow *gnt_tree_add_row_after(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro) | |
1302 { | |
1303 GntTreeRow *pr = NULL; | |
1304 | |
20306
665d6d7eea83
applied changes from 88f296b3653b5a7578a7581c1582d37390c9d212
Luke Schierer <lschiere@pidgin.im>
parents:
19681
diff
changeset
|
1305 row->tree = tree; |
665d6d7eea83
applied changes from 88f296b3653b5a7578a7581c1582d37390c9d212
Luke Schierer <lschiere@pidgin.im>
parents:
19681
diff
changeset
|
1306 row->key = key; |
665d6d7eea83
applied changes from 88f296b3653b5a7578a7581c1582d37390c9d212
Luke Schierer <lschiere@pidgin.im>
parents:
19681
diff
changeset
|
1307 row->data = NULL; |
15817 | 1308 g_hash_table_replace(tree->hash, key, row); |
1309 | |
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
|
1310 if (bigbro == NULL && tree->priv->compare) |
15817 | 1311 { |
1312 bigbro = find_position(tree, key, parent); | |
1313 } | |
1314 | |
1315 if (tree->root == NULL) | |
1316 { | |
1317 tree->root = row; | |
1318 tree->list = g_list_prepend(tree->list, key); | |
1319 } | |
1320 else | |
1321 { | |
1322 int position = 0; | |
1323 | |
1324 if (bigbro) | |
1325 { | |
1326 pr = g_hash_table_lookup(tree->hash, bigbro); | |
1327 if (pr) | |
1328 { | |
1329 if (pr->next) pr->next->prev = row; | |
1330 row->next = pr->next; | |
1331 row->prev = pr; | |
1332 pr->next = row; | |
1333 row->parent = pr->parent; | |
1334 | |
1335 position = g_list_index(tree->list, bigbro); | |
1336 } | |
1337 } | |
1338 | |
1339 if (pr == NULL && parent) | |
1340 { | |
1341 pr = g_hash_table_lookup(tree->hash, parent); | |
1342 if (pr) | |
1343 { | |
1344 if (pr->child) pr->child->prev = row; | |
1345 row->next = pr->child; | |
1346 pr->child = row; | |
1347 row->parent = pr; | |
1348 | |
1349 position = g_list_index(tree->list, parent); | |
1350 } | |
1351 } | |
1352 | |
1353 if (pr == NULL) | |
1354 { | |
1355 GntTreeRow *r = tree->root; | |
1356 row->next = r; | |
1357 if (r) r->prev = row; | |
1358 if (tree->current == tree->root) | |
1359 tree->current = row; | |
1360 tree->root = row; | |
1361 tree->list = g_list_prepend(tree->list, key); | |
1362 } | |
1363 else | |
1364 { | |
1365 tree->list = g_list_insert(tree->list, key, position + 1); | |
1366 } | |
1367 } | |
1368 redraw_tree(tree); | |
1369 | |
1370 return row; | |
1371 } | |
1372 | |
1373 GntTreeRow *gnt_tree_add_row_last(GntTree *tree, void *key, GntTreeRow *row, void *parent) | |
1374 { | |
1375 GntTreeRow *pr = NULL, *br = NULL; | |
1376 | |
1377 if (parent) | |
1378 pr = g_hash_table_lookup(tree->hash, parent); | |
1379 | |
1380 if (pr) | |
1381 br = pr->child; | |
1382 else | |
1383 br = tree->root; | |
1384 | |
1385 if (br) | |
1386 { | |
1387 while (br->next) | |
1388 br = br->next; | |
1389 } | |
1390 | |
1391 return gnt_tree_add_row_after(tree, key, row, parent, br ? br->key : NULL); | |
1392 } | |
1393 | |
1394 gpointer gnt_tree_get_selection_data(GntTree *tree) | |
1395 { | |
1396 if (tree->current) | |
1397 return tree->current->key; /* XXX: perhaps we should just get rid of 'data' */ | |
1398 return NULL; | |
1399 } | |
1400 | |
1401 char *gnt_tree_get_selection_text(GntTree *tree) | |
1402 { | |
1403 if (tree->current) | |
1404 return update_row_text(tree, tree->current); | |
1405 return NULL; | |
1406 } | |
1407 | |
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
|
1408 GList *gnt_tree_get_row_text_list(GntTree *tree, gpointer key) |
15817 | 1409 { |
1410 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
|
1411 GntTreeRow *row = key ? g_hash_table_lookup(tree->hash, key) : tree->current; |
15817 | 1412 int i; |
1413 | |
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
|
1414 if (!row) |
15817 | 1415 return NULL; |
1416 | |
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
|
1417 for (i = 0, iter = row->columns; i < tree->ncol && iter; |
15817 | 1418 i++, iter = iter->next) |
1419 { | |
1420 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
|
1421 list = g_list_append(list, BINARY_DATA(tree, i) ? col->text : g_strdup(col->text)); |
15817 | 1422 } |
1423 | |
1424 return list; | |
1425 } | |
1426 | |
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
|
1427 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
|
1428 { |
36257cac2b11
Anoter patch from Javeed Shaikh to introduce a utility function for a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18563
diff
changeset
|
1429 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
|
1430 } |
36257cac2b11
Anoter patch from Javeed Shaikh to introduce a utility function for a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18563
diff
changeset
|
1431 |
15817 | 1432 void gnt_tree_remove(GntTree *tree, gpointer key) |
1433 { | |
1434 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1435 static int depth = 0; /* Only redraw after all child nodes are removed */ | |
1436 if (row) | |
1437 { | |
1438 gboolean redraw = FALSE; | |
1439 | |
1440 if (row->child) { | |
1441 depth++; | |
1442 while (row->child) { | |
1443 gnt_tree_remove(tree, row->child->key); | |
1444 } | |
1445 depth--; | |
1446 } | |
1447 | |
1448 if (get_distance(tree->top, row) >= 0 && get_distance(row, tree->bottom) >= 0) | |
1449 redraw = TRUE; | |
1450 | |
1451 /* Update root/top/current/bottom if necessary */ | |
1452 if (tree->root == row) | |
1453 tree->root = get_next(row); | |
1454 if (tree->top == row) | |
1455 { | |
1456 if (tree->top != tree->root) | |
1457 tree->top = get_prev(row); | |
1458 else | |
1459 tree->top = get_next(row); | |
1460 } | |
1461 if (tree->current == row) | |
1462 { | |
1463 if (tree->current != tree->root) | |
1464 tree->current = get_prev(row); | |
1465 else | |
1466 tree->current = get_next(row); | |
1467 tree_selection_changed(tree, row, tree->current); | |
1468 } | |
1469 if (tree->bottom == row) | |
1470 { | |
1471 tree->bottom = get_prev(row); | |
1472 } | |
1473 | |
1474 /* Fix the links */ | |
1475 if (row->next) | |
1476 row->next->prev = row->prev; | |
1477 if (row->parent && row->parent->child == row) | |
1478 row->parent->child = row->next; | |
1479 if (row->prev) | |
1480 row->prev->next = row->next; | |
1481 | |
1482 g_hash_table_remove(tree->hash, key); | |
1483 tree->list = g_list_remove(tree->list, key); | |
1484 | |
1485 if (redraw && depth == 0) | |
1486 { | |
1487 redraw_tree(tree); | |
1488 } | |
1489 } | |
1490 } | |
1491 | |
1492 static gboolean | |
1493 return_true(gpointer key, gpointer data, gpointer null) | |
1494 { | |
1495 return TRUE; | |
1496 } | |
1497 | |
1498 void gnt_tree_remove_all(GntTree *tree) | |
1499 { | |
1500 tree->root = NULL; | |
1501 g_hash_table_foreach_remove(tree->hash, (GHRFunc)return_true, tree); | |
1502 g_list_free(tree->list); | |
1503 tree->list = NULL; | |
1504 tree->current = tree->top = tree->bottom = NULL; | |
1505 } | |
1506 | |
1507 int gnt_tree_get_selection_visible_line(GntTree *tree) | |
1508 { | |
1509 return get_distance(tree->top, tree->current) + | |
1510 !!(GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER)); | |
1511 } | |
1512 | |
1513 void gnt_tree_change_text(GntTree *tree, gpointer key, int colno, const char *text) | |
1514 { | |
1515 GntTreeRow *row; | |
1516 GntTreeCol *col; | |
1517 | |
1518 g_return_if_fail(colno < tree->ncol); | |
1519 | |
1520 row = g_hash_table_lookup(tree->hash, key); | |
1521 if (row) | |
1522 { | |
1523 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
|
1524 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
|
1525 col->text = (gpointer)text; |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1526 } else { |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1527 g_free(col->text); |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1528 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
|
1529 } |
15817 | 1530 |
21271
ca16de222b76
Do not do unnecessary processing when updating text in a column.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21264
diff
changeset
|
1531 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
|
1532 get_distance(tree->top, row) >= 0 && get_distance(row, tree->bottom) >= 0) |
15817 | 1533 redraw_tree(tree); |
1534 } | |
1535 } | |
1536 | |
1537 GntTreeRow *gnt_tree_add_choice(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro) | |
1538 { | |
1539 GntTreeRow *r; | |
1540 r = g_hash_table_lookup(tree->hash, key); | |
1541 g_return_val_if_fail(!r || !r->choice, NULL); | |
1542 | |
1543 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
|
1544 if (tree->priv->compare) |
15817 | 1545 bigbro = find_position(tree, key, parent); |
1546 else { | |
1547 r = g_hash_table_lookup(tree->hash, parent); | |
1548 if (!r) | |
1549 r = tree->root; | |
1550 else | |
1551 r = r->child; | |
1552 if (r) { | |
1553 while (r->next) | |
1554 r = r->next; | |
1555 bigbro = r->key; | |
1556 } | |
1557 } | |
1558 } | |
1559 row = gnt_tree_add_row_after(tree, key, row, parent, bigbro); | |
1560 row->choice = TRUE; | |
1561 | |
1562 return row; | |
1563 } | |
1564 | |
1565 void gnt_tree_set_choice(GntTree *tree, void *key, gboolean set) | |
1566 { | |
1567 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1568 | |
1569 if (!row) | |
1570 return; | |
1571 g_return_if_fail(row->choice); | |
1572 | |
1573 row->isselected = set; | |
1574 redraw_tree(tree); | |
1575 } | |
1576 | |
1577 gboolean gnt_tree_get_choice(GntTree *tree, void *key) | |
1578 { | |
1579 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1580 | |
1581 if (!row) | |
1582 return FALSE; | |
1583 g_return_val_if_fail(row->choice, FALSE); | |
1584 | |
1585 return row->isselected; | |
1586 } | |
1587 | |
1588 void gnt_tree_set_row_flags(GntTree *tree, void *key, GntTextFormatFlags flags) | |
1589 { | |
1590 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1591 if (!row || row->flags == flags) | |
1592 return; | |
1593 | |
1594 row->flags = flags; | |
1595 redraw_tree(tree); /* XXX: It shouldn't be necessary to redraw the whole darned tree */ | |
1596 } | |
1597 | |
21691
3ed9b027479d
Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents:
21283
diff
changeset
|
1598 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
|
1599 { |
3ed9b027479d
Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents:
21283
diff
changeset
|
1600 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
|
1601 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
|
1602 return; |
3ed9b027479d
Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents:
21283
diff
changeset
|
1603 |
3ed9b027479d
Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents:
21283
diff
changeset
|
1604 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
|
1605 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
|
1606 } |
3ed9b027479d
Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents:
21283
diff
changeset
|
1607 |
15817 | 1608 void gnt_tree_set_selected(GntTree *tree , void *key) |
1609 { | |
1610 int dist; | |
1611 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
|
1612 if (!row || row == tree->current) |
15817 | 1613 return; |
1614 | |
1615 if (tree->top == NULL) | |
1616 tree->top = row; | |
1617 if (tree->bottom == NULL) | |
1618 tree->bottom = row; | |
1619 | |
1620 tree->current = row; | |
1621 if ((dist = get_distance(tree->current, tree->bottom)) < 0) | |
1622 gnt_tree_scroll(tree, -dist); | |
1623 else if ((dist = get_distance(tree->current, tree->top)) > 0) | |
1624 gnt_tree_scroll(tree, -dist); | |
1625 else | |
1626 redraw_tree(tree); | |
16203
4f6a6443a1e3
emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents:
16123
diff
changeset
|
1627 tree_selection_changed(tree, row, tree->current); |
15817 | 1628 } |
1629 | |
18531
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
1630 static void _gnt_tree_init_internals(GntTree *tree, int col) |
15817 | 1631 { |
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
|
1632 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
|
1633 |
15817 | 1634 tree->ncol = col; |
1635 tree->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_tree_row); | |
1636 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
|
1637 tree->priv->lastvisible = col - 1; |
15817 | 1638 while (col--) |
1639 { | |
1640 tree->columns[col].width = 15; | |
1641 } | |
1642 tree->list = NULL; | |
1643 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
|
1644 g_object_notify(G_OBJECT(tree), "columns"); |
15817 | 1645 } |
1646 | |
1647 GntWidget *gnt_tree_new_with_columns(int col) | |
1648 { | |
18531
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18449
diff
changeset
|
1649 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
|
1650 "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
|
1651 "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
|
1652 NULL); |
15817 | 1653 |
1654 return widget; | |
1655 } | |
1656 | |
1657 GntTreeRow *gnt_tree_create_row_from_list(GntTree *tree, GList *list) | |
1658 { | |
1659 GList *iter; | |
1660 int i; | |
1661 GntTreeRow *row = g_new0(GntTreeRow, 1); | |
1662 | |
1663 for (i = 0, iter = list; i < tree->ncol && iter; iter = iter->next, i++) | |
1664 { | |
1665 GntTreeCol *col = g_new0(GntTreeCol, 1); | |
1666 col->span = 1; | |
18420
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1667 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
|
1668 col->text = iter->data; |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1669 col->isbinary = TRUE; |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1670 } else { |
18873
7066896f6628
disapproval of revision 'a4ce7b8adf2db74d531c35278fe83247d90ce4b1'
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18872
diff
changeset
|
1671 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
|
1672 col->isbinary = FALSE; |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1673 } |
15817 | 1674 |
1675 row->columns = g_list_append(row->columns, col); | |
1676 } | |
1677 | |
1678 return row; | |
1679 } | |
1680 | |
1681 GntTreeRow *gnt_tree_create_row(GntTree *tree, ...) | |
1682 { | |
1683 int i; | |
1684 va_list args; | |
1685 GList *list = NULL; | |
1686 GntTreeRow *row; | |
1687 | |
1688 va_start(args, tree); | |
1689 for (i = 0; i < tree->ncol; i++) | |
1690 { | |
1691 list = g_list_append(list, va_arg(args, char *)); | |
1692 } | |
1693 va_end(args); | |
1694 | |
1695 row = gnt_tree_create_row_from_list(tree, list); | |
1696 g_list_free(list); | |
1697 | |
1698 return row; | |
1699 } | |
1700 | |
1701 void gnt_tree_set_col_width(GntTree *tree, int col, int width) | |
1702 { | |
1703 g_return_if_fail(col < tree->ncol); | |
1704 | |
1705 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
|
1706 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
|
1707 tree->columns[col].width_ratio = width; |
15817 | 1708 } |
1709 | |
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
|
1710 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
|
1711 { |
1f9db757efc2
Oops. I missed this. This allows setting tree-column titles one by one.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18183
diff
changeset
|
1712 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
|
1713 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
|
1714 } |
1f9db757efc2
Oops. I missed this. This allows setting tree-column titles one by one.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18183
diff
changeset
|
1715 |
15817 | 1716 void gnt_tree_set_column_titles(GntTree *tree, ...) |
1717 { | |
1718 int i; | |
1719 va_list args; | |
1720 | |
1721 va_start(args, tree); | |
1722 for (i = 0; i < tree->ncol; i++) | |
1723 { | |
1724 const char *title = va_arg(args, const char *); | |
1725 tree->columns[i].title = g_strdup(title); | |
1726 } | |
1727 va_end(args); | |
1728 } | |
1729 | |
1730 void gnt_tree_set_show_title(GntTree *tree, gboolean set) | |
1731 { | |
1732 tree->show_title = set; | |
1733 GNT_WIDGET(tree)->priv.minh = (set ? 6 : 4); | |
1734 } | |
1735 | |
1736 void gnt_tree_set_compare_func(GntTree *tree, GCompareFunc func) | |
1737 { | |
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
|
1738 tree->priv->compare = func; |
15817 | 1739 } |
1740 | |
1741 void gnt_tree_set_expanded(GntTree *tree, void *key, gboolean expanded) | |
1742 { | |
1743 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); | |
1744 if (row) { | |
1745 row->collapsed = !expanded; | |
1746 if (GNT_WIDGET(tree)->window) | |
1747 gnt_widget_draw(GNT_WIDGET(tree)); | |
16203
4f6a6443a1e3
emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents:
16123
diff
changeset
|
1748 g_signal_emit(tree, signals[SIG_COLLAPSED], 0, key, row->collapsed); |
15817 | 1749 } |
1750 } | |
1751 | |
1752 void gnt_tree_set_show_separator(GntTree *tree, gboolean set) | |
1753 { | |
1754 tree->show_separator = set; | |
1755 } | |
1756 | |
1757 void gnt_tree_adjust_columns(GntTree *tree) | |
1758 { | |
1759 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
|
1760 int *widths, i, twidth; |
15817 | 1761 |
1762 widths = g_new0(int, tree->ncol); | |
1763 while (row) { | |
1764 GList *iter; | |
1765 for (i = 0, iter = row->columns; iter; iter = iter->next, i++) { | |
1766 GntTreeCol *col = iter->data; | |
1767 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
|
1768 if (i == 0 && row->choice) |
0ab73bf1fef1
check-items are wider.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15928
diff
changeset
|
1769 w += 4; |
15972
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
1770 if (i == 0) { |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
1771 w += find_depth(row) * TAB_SIZE; |
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
1772 } |
15817 | 1773 if (widths[i] < w) |
1774 widths[i] = w; | |
1775 } | |
15972
5eb0621e0760
Backspace to jump to parent.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15971
diff
changeset
|
1776 row = get_next(row); |
15817 | 1777 } |
1778 | |
1779 twidth = 1 + 2 * (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER)); | |
1780 for (i = 0; i < tree->ncol; i++) { | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1781 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
|
1782 widths[i] = tree->columns[i].width; |
15817 | 1783 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
|
1784 if (!COLUMN_INVISIBLE(tree, i)) { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1785 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
|
1786 if (tree->priv->lastvisible != i) |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1787 twidth += 1; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1788 } |
15817 | 1789 } |
1790 g_free(widths); | |
1791 | |
16123
bc280c341679
We don't need to do anything about the heights here.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16105
diff
changeset
|
1792 gnt_widget_set_size(GNT_WIDGET(tree), twidth, -1); |
15817 | 1793 } |
1794 | |
1795 void gnt_tree_set_hash_fns(GntTree *tree, gpointer hash, gpointer eq, gpointer kd) | |
1796 { | |
1797 g_hash_table_foreach_remove(tree->hash, return_true, NULL); | |
1798 g_hash_table_destroy(tree->hash); | |
1799 tree->hash = g_hash_table_new_full(hash, eq, kd, free_tree_row); | |
1800 } | |
1801 | |
18404
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1802 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
|
1803 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
|
1804 { |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1805 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
|
1806 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
|
1807 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
|
1808 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
|
1809 } |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1810 |
15970
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
1811 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
|
1812 { |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
1813 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
|
1814 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
|
1815 if (vis) { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1816 /* 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
|
1817 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
|
1818 tree->priv->lastvisible = col; |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1819 } 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
|
1820 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
|
1821 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
|
1822 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
|
1823 if (!COLUMN_INVISIBLE(tree, tree->priv->lastvisible)) |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1824 break; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1825 } |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18420
diff
changeset
|
1826 } |
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
|
1827 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
|
1828 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
|
1829 } |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1830 |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1831 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
|
1832 { |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1833 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
|
1834 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
|
1835 } |
790d1d003825
Allow making some columns invisible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15968
diff
changeset
|
1836 |
18420
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1837 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
|
1838 { |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1839 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
|
1840 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
|
1841 } |
e2b8b17fc62c
Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18405
diff
changeset
|
1842 |
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
|
1843 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
|
1844 { |
ed17f5530300
Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
1845 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
|
1846 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
|
1847 } |
ed17f5530300
Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
1848 |
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
|
1849 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
|
1850 { |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1851 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
|
1852 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
|
1853 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
|
1854 } |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1855 } |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18348
diff
changeset
|
1856 |
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
|
1857 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
|
1858 { |
ffa46a399f3c
Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
1859 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
|
1860 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
|
1861 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
|
1862 } |
ffa46a399f3c
Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
1863 |
18535
fad459189cc5
New feature: successful compilation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18534
diff
changeset
|
1864 gboolean gnt_tree_is_searching(GntTree *tree) |
fad459189cc5
New feature: successful compilation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18534
diff
changeset
|
1865 { |
fad459189cc5
New feature: successful compilation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18534
diff
changeset
|
1866 return (tree->priv->search != NULL); |
fad459189cc5
New feature: successful compilation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18534
diff
changeset
|
1867 } |
fad459189cc5
New feature: successful compilation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18534
diff
changeset
|
1868 |
18557
212c2bec5c97
Allow using custom search functions.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18556
diff
changeset
|
1869 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
|
1870 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
|
1871 { |
212c2bec5c97
Allow using custom search functions.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18556
diff
changeset
|
1872 tree->priv->search_func = func; |
212c2bec5c97
Allow using custom search functions.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18556
diff
changeset
|
1873 } |
212c2bec5c97
Allow using custom search functions.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18556
diff
changeset
|
1874 |
22170
364e67f1a429
Function to get the parent key.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21691
diff
changeset
|
1875 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
|
1876 { |
364e67f1a429
Function to get the parent key.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21691
diff
changeset
|
1877 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
|
1878 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
|
1879 } |
364e67f1a429
Function to get the parent key.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21691
diff
changeset
|
1880 |