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