finch/libgnt/gnttree.c

Mon, 22 Aug 2011 07:20:49 +0000

author
Mark Doliner <markdoliner@pidgin.im>
date
Mon, 22 Aug 2011 07:20:49 +0000
changeset 32206
a2c62b07ae5a
parent 31294
73607ab89c6f
child 35059
5fd94b14cc49
permissions
-rw-r--r--

Please correct me if I'm wrong, but I don't think we gain anything
from declaring _PurpleBlah versions of enums if we do a typedef
at the same time. I don't think it's necessary.
Fixes #4475

17586
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16646
diff changeset
1 /**
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16646
diff changeset
2 * GNT - The GLib Ncurses Toolkit
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16646
diff changeset
3 *
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16646
diff changeset
4 * GNT is the legal property of its developers, whose names are too numerous
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16646
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16646
diff changeset
6 * source distribution.
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16646
diff changeset
7 *
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16646
diff changeset
8 * This library is free software; you can redistribute it and/or modify
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16646
diff changeset
9 * it under the terms of the GNU General Public License as published by
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16646
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16646
diff changeset
11 * (at your option) any later version.
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16646
diff changeset
12 *
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16646
diff changeset
13 * This program is distributed in the hope that it will be useful,
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16646
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16646
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16646
diff changeset
16 * GNU General Public License for more details.
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16646
diff changeset
17 *
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16646
diff changeset
18 * You should have received a copy of the GNU General Public License
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16646
diff changeset
19 * along with this program; if not, write to the Free Software
19859
71d37b57eff2 The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19551
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
17586
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16646
diff changeset
21 */
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16646
diff changeset
22
28937
5f87e66597d9 Fix showing umlauts etc. on non-utf8 locales.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28822
diff changeset
23 #include "gntinternal.h"
14898
107b971b39f2 [gaim-migrate @ 17605]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14886
diff changeset
24 #include "gntmarshal.h"
107b971b39f2 [gaim-migrate @ 17605]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14886
diff changeset
25 #include "gntstyle.h"
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
26 #include "gnttree.h"
14678
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
27 #include "gntutils.h"
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
28
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
29 #include <string.h>
14277
feec61ac5bae [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14270
diff changeset
30 #include <ctype.h>
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
31
26651
d9f1eeefb89c Save the world.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 26650
diff changeset
32 #define SEARCH_TIMEOUT_S 4 /* 4 secs */
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
33 #define SEARCHING(tree) (tree->priv->search && tree->priv->search->len > 0)
15222
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
34
18558
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
35 #define COLUMN_INVISIBLE(tree, index) (tree->columns[index].flags & GNT_TREE_COLUMN_INVISIBLE)
18598
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
36 #define BINARY_DATA(tree, index) (tree->columns[index].flags & GNT_TREE_COLUMN_BINARY_DATA)
18632
c7a3b70f0ae7 Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18624
diff changeset
37 #define RIGHT_ALIGNED(tree, index) (tree->columns[index].flags & GNT_TREE_COLUMN_RIGHT_ALIGNED)
18558
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
38
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
39 enum
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
40 {
18783
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
41 PROP_0,
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
42 PROP_COLUMNS,
22311
f3b63d7c4601 Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22301
diff changeset
43 PROP_EXPANDER,
18783
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
44 };
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
45
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
46 enum
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
47 {
13922
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
48 SIG_SELECTION_CHANGED,
13927
c2f57a00bc1f [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13926
diff changeset
49 SIG_SCROLLED,
13969
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
50 SIG_TOGGLED,
16165
24ec117bc52c Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents: 16032
diff changeset
51 SIG_COLLAPSED,
13922
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
52 SIGS,
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
53 };
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
54
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
55 struct _GntTreePriv
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
56 {
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
57 GString *search;
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
58 int search_timeout;
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
59 int search_column;
18829
35138e0fbf77 Patch from Javeed Shaikh to make the search function non-braindamaged.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18827
diff changeset
60 gboolean (*search_func)(GntTree *tree, gpointer key, const char *search, const char *current);
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
61
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
62 GCompareFunc compare;
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
63 int lastvisible;
22311
f3b63d7c4601 Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22301
diff changeset
64 int expander_level;
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
65 };
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
66
13920
c51758bc563c [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13919
diff changeset
67 #define TAB_SIZE 3
c51758bc563c [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13919
diff changeset
68
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
69 /* XXX: Make this one into a GObject?
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
70 * ... Probably not */
15991
1efb6bd8ba3f Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15886
diff changeset
71 struct _GntTreeRow
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
72 {
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
73 void *key;
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
74 void *data; /* XXX: unused */
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
75
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
76 gboolean collapsed;
13969
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
77 gboolean choice; /* Is this a choice-box?
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
78 If choice is true, then child will be NULL */
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
79 gboolean isselected;
13993
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
80 GntTextFormatFlags flags;
21804
931ef2cc7cfb Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents: 21273
diff changeset
81 int color;
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
82
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
83 GntTreeRow *parent;
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
84 GntTreeRow *child;
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
85 GntTreeRow *next;
13919
94caf5dc02b4 [gaim-migrate @ 16316]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13918
diff changeset
86 GntTreeRow *prev;
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
87
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
88 GList *columns;
15222
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
89 GntTree *tree;
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
90 };
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
91
15991
1efb6bd8ba3f Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15886
diff changeset
92 struct _GntTreeCol
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
93 {
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
94 char *text;
18598
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
95 gboolean isbinary;
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
96 int span; /* How many columns does it span? */
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
97 };
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
98
16264
03aaf9aae68b emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents: 16185
diff changeset
99 static void tree_selection_changed(GntTree *, GntTreeRow *, GntTreeRow *);
18783
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
100 static void _gnt_tree_init_internals(GntTree *tree, int col);
16264
03aaf9aae68b emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents: 16185
diff changeset
101
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
102 static GntWidgetClass *parent_class = NULL;
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
103 static guint signals[SIGS] = { 0 };
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
104
18558
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
105 static void
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
106 readjust_columns(GntTree *tree)
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
107 {
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
108 int i, col, total;
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
109 int width;
18559
d39d742f54bd Parentheses helps.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18558
diff changeset
110 #define WIDTH(i) (tree->columns[i].width_ratio ? tree->columns[i].width_ratio : tree->columns[i].width)
18558
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
111 gnt_widget_get_size(GNT_WIDGET(tree), &width, NULL);
18624
03d4eb6b6684 Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18598
diff changeset
112 if (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER))
03d4eb6b6684 Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18598
diff changeset
113 width -= 2;
23485
8733da333c8f Fix an off-by-one bug in calculating column widths in trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23221
diff changeset
114 width -= 1; /* Exclude the scrollbar from the calculation */
18558
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
115 for (i = 0, total = 0; i < tree->ncol ; i++) {
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
116 if (tree->columns[i].flags & GNT_TREE_COLUMN_INVISIBLE)
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
117 continue;
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
118 if (tree->columns[i].flags & GNT_TREE_COLUMN_FIXED_SIZE)
23485
8733da333c8f Fix an off-by-one bug in calculating column widths in trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23221
diff changeset
119 width -= WIDTH(i) + (tree->priv->lastvisible != i);
18558
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
120 else
23485
8733da333c8f Fix an off-by-one bug in calculating column widths in trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23221
diff changeset
121 total += WIDTH(i) + (tree->priv->lastvisible != i);
18558
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
122 }
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
123
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
124 if (total == 0)
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
125 return;
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
126
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
127 for (i = 0; i < tree->ncol; i++) {
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
128 if (tree->columns[i].flags & GNT_TREE_COLUMN_INVISIBLE)
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
129 continue;
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
130 if (tree->columns[i].flags & GNT_TREE_COLUMN_FIXED_SIZE)
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
131 col = WIDTH(i);
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
132 else
18559
d39d742f54bd Parentheses helps.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18558
diff changeset
133 col = (WIDTH(i) * width) / total;
18558
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
134 gnt_tree_set_col_width(GNT_TREE(tree), i, col);
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
135 }
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
136 }
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
137
14774
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
138 /* Move the item at position old to position new */
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
139 static GList *
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
140 g_list_reposition_child(GList *list, int old, int new)
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
141 {
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
142 gpointer item = g_list_nth_data(list, old);
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
143 list = g_list_remove(list, item);
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
144 if (old < new)
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
145 new--; /* because the positions would have shifted after removing the item */
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
146 list = g_list_insert(list, item, new);
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
147 return list;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
148 }
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
149
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
150 static GntTreeRow *
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
151 _get_next(GntTreeRow *row, gboolean godeep)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
152 {
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
153 if (row == NULL)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
154 return NULL;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
155 if (godeep && row->child)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
156 return row->child;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
157 if (row->next)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
158 return row->next;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
159 return _get_next(row->parent, FALSE);
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
160 }
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
161
15222
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
162 static gboolean
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
163 row_matches_search(GntTreeRow *row)
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
164 {
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
165 GntTree *t = row->tree;
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
166 if (t->priv->search && t->priv->search->len > 0) {
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
167 GntTreeCol *col = (col = g_list_nth_data(row->columns, t->priv->search_column)) ? col : row->columns->data;
18827
822e004cae0c Allow using custom search functions.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
168 char *one, *two, *z;
822e004cae0c Allow using custom search functions.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
169 if (t->priv->search_func)
18829
35138e0fbf77 Patch from Javeed Shaikh to make the search function non-braindamaged.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18827
diff changeset
170 return t->priv->search_func(t, row->key, t->priv->search->str, col->text);
18827
822e004cae0c Allow using custom search functions.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
171 one = g_utf8_casefold(col->text, -1);
822e004cae0c Allow using custom search functions.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
172 two = g_utf8_casefold(t->priv->search->str, -1);
822e004cae0c Allow using custom search functions.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
173 z = strstr(one, two);
15222
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
174 g_free(one);
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
175 g_free(two);
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
176 if (z == NULL)
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
177 return FALSE;
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
178 }
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
179 return TRUE;
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
180 }
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
181
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
182 static GntTreeRow *
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
183 get_next(GntTreeRow *row)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
184 {
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
185 if (row == NULL)
13950
bd8d39b3a9e2 [gaim-migrate @ 16369]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13944
diff changeset
186 return NULL;
15222
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
187 while ((row = _get_next(row, !row->collapsed)) != NULL) {
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
188 if (row_matches_search(row))
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
189 break;
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
190 }
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
191 return row;
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
192 }
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
193
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
194 /* Returns the n-th next row. If it doesn't exist, returns NULL */
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
195 static GntTreeRow *
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
196 get_next_n(GntTreeRow *row, int n)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
197 {
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
198 while (row && n--)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
199 row = get_next(row);
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
200 return row;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
201 }
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
202
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
203 /* Returns the n-th next row. If it doesn't exist, then the last non-NULL node */
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
204 static GntTreeRow *
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
205 get_next_n_opt(GntTreeRow *row, int n, int *pos)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
206 {
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
207 GntTreeRow *next = row;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
208 int r = 0;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
209
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
210 if (row == NULL)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
211 return NULL;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
212
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
213 while (row && n--)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
214 {
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
215 row = get_next(row);
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
216 if (row)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
217 {
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
218 next = row;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
219 r++;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
220 }
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
221 }
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
222
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
223 if (pos)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
224 *pos = r;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
225
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
226 return next;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
227 }
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
228
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
229 static GntTreeRow *
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
230 get_last_child(GntTreeRow *row)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
231 {
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
232 if (row == NULL)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
233 return NULL;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
234 if (!row->collapsed && row->child)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
235 row = row->child;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
236 else
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
237 return row;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
238
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
239 while(row->next)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
240 row = row->next;
16646
fd3c9b8de3e2 Fix an odd selection issue when moving up.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16362
diff changeset
241 return get_last_child(row);
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
242 }
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
243
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
244 static GntTreeRow *
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
245 get_prev(GntTreeRow *row)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
246 {
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
247 if (row == NULL)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
248 return NULL;
15222
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
249 while (row) {
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
250 if (row->prev)
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
251 row = get_last_child(row->prev);
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
252 else
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
253 row = row->parent;
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
254 if (!row || row_matches_search(row))
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
255 break;
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
256 }
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
257 return row;
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
258 }
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
259
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
260 static GntTreeRow *
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
261 get_prev_n(GntTreeRow *row, int n)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
262 {
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
263 while (row && n--)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
264 row = get_prev(row);
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
265 return row;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
266 }
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
267
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
268 /* Distance of row from the root */
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
269 /* XXX: This is uber-inefficient */
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
270 static int
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
271 get_root_distance(GntTreeRow *row)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
272 {
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
273 if (row == NULL)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
274 return -1;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
275 return get_root_distance(get_prev(row)) + 1;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
276 }
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
277
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30499
diff changeset
278 /* Returns the distance between a and b.
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
279 * If a is 'above' b, then the distance is positive */
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
280 static int
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
281 get_distance(GntTreeRow *a, GntTreeRow *b)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
282 {
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
283 /* First get the distance from a to the root.
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
284 * Then the distance from b to the root.
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
285 * Subtract.
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
286 * It's not that good, but it works. */
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
287 int ha = get_root_distance(a);
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
288 int hb = get_root_distance(b);
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
289
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
290 return (hb - ha);
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
291 }
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
292
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
293 static int
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
294 find_depth(GntTreeRow *row)
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
295 {
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
296 int dep = -1;
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
297
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
298 while (row)
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
299 {
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
300 dep++;
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
301 row = row->parent;
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
302 }
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
303
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
304 return dep;
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
305 }
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
306
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
307 static char *
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
308 update_row_text(GntTree *tree, GntTreeRow *row)
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
309 {
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
310 GString *string = g_string_new(NULL);
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
311 GList *iter;
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
312 int i;
16030
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
313 gboolean notfirst = FALSE;
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
314
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
315 for (i = 0, iter = row->columns; i < tree->ncol && iter; i++, iter = iter->next)
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
316 {
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
317 GntTreeCol *col = iter->data;
14886
9f76d3a61aa7 [gaim-migrate @ 17591]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14885
diff changeset
318 const char *text;
18598
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
319 int len;
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
320 int fl = 0;
14908
0ccb73d4e584 [gaim-migrate @ 17615]
Richard Nelson <wabz@pidgin.im>
parents: 14905
diff changeset
321 gboolean cut = FALSE;
16031
7ca3d73eab52 Fine tune column hiding.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16030
diff changeset
322 int width;
18598
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
323 const char *display;
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
324
18558
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
325 if (COLUMN_INVISIBLE(tree, i))
16030
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
326 continue;
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
327
18598
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
328 if (BINARY_DATA(tree, i))
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
329 display = "";
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
330 else
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
331 display = col->text;
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
332
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
333 len = gnt_util_onscreen_width(display, NULL);
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
334
18632
c7a3b70f0ae7 Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18624
diff changeset
335 width = tree->columns[i].width;
16031
7ca3d73eab52 Fine tune column hiding.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16030
diff changeset
336
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
337 if (i == 0)
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
338 {
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
339 if (row->choice)
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
340 {
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
341 g_string_append_printf(string, "[%c] ",
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
342 row->isselected ? 'X' : ' ');
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
343 fl = 4;
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
344 }
22311
f3b63d7c4601 Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22301
diff changeset
345 else if (find_depth(row) < tree->priv->expander_level && row->child)
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
346 {
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
347 if (row->collapsed)
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
348 {
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
349 string = g_string_append(string, "+ ");
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
350 }
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
351 else
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
352 {
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
353 string = g_string_append(string, "- ");
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
354 }
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
355 fl = 2;
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
356 }
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
357 else
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
358 {
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
359 fl = TAB_SIZE * find_depth(row);
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
360 g_string_append_printf(string, "%*s", fl, "");
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
361 }
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
362 len += fl;
18624
03d4eb6b6684 Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18598
diff changeset
363 } else if (notfirst && tree->show_separator)
16030
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
364 g_string_append_c(string, '|');
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
365 else
16030
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
366 g_string_append_c(string, ' ');
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
367
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
368 notfirst = TRUE;
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
369
18255
f29124ab560e I think this fixes the ellipsization in the trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18190
diff changeset
370 if (len > width) {
21263
0919212f5a8c Do not ellipsize in a column of size 1.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21262
diff changeset
371 len = MAX(1, width - 1);
14908
0ccb73d4e584 [gaim-migrate @ 17615]
Richard Nelson <wabz@pidgin.im>
parents: 14905
diff changeset
372 cut = TRUE;
0ccb73d4e584 [gaim-migrate @ 17615]
Richard Nelson <wabz@pidgin.im>
parents: 14905
diff changeset
373 }
18632
c7a3b70f0ae7 Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18624
diff changeset
374
c7a3b70f0ae7 Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18624
diff changeset
375 if (RIGHT_ALIGNED(tree, i) && len < tree->columns[i].width) {
21262
b1635191fe14 Patch from Josh Davis to correct ellipsization for right-aligned columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21261
diff changeset
376 g_string_append_printf(string, "%*s", width - len - cut, "");
18632
c7a3b70f0ae7 Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18624
diff changeset
377 }
c7a3b70f0ae7 Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18624
diff changeset
378
18598
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
379 text = gnt_util_onscreen_width_to_pointer(display, len - fl, NULL);
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
380 string = g_string_append_len(string, display, text - display);
21263
0919212f5a8c Do not ellipsize in a column of size 1.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21262
diff changeset
381 if (cut && width > 1) { /* ellipsis */
14908
0ccb73d4e584 [gaim-migrate @ 17615]
Richard Nelson <wabz@pidgin.im>
parents: 14905
diff changeset
382 if (gnt_ascii_only())
0ccb73d4e584 [gaim-migrate @ 17615]
Richard Nelson <wabz@pidgin.im>
parents: 14905
diff changeset
383 g_string_append_c(string, '~');
0ccb73d4e584 [gaim-migrate @ 17615]
Richard Nelson <wabz@pidgin.im>
parents: 14905
diff changeset
384 else
0ccb73d4e584 [gaim-migrate @ 17615]
Richard Nelson <wabz@pidgin.im>
parents: 14905
diff changeset
385 string = g_string_append(string, "\342\200\246");
0ccb73d4e584 [gaim-migrate @ 17615]
Richard Nelson <wabz@pidgin.im>
parents: 14905
diff changeset
386 len++;
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
387 }
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
388
18632
c7a3b70f0ae7 Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18624
diff changeset
389 if (!RIGHT_ALIGNED(tree, i) && len < tree->columns[i].width && iter->next)
16031
7ca3d73eab52 Fine tune column hiding.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16030
diff changeset
390 g_string_append_printf(string, "%*s", width - len, "");
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
391 }
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
392 return g_string_free(string, FALSE);
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
393 }
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
394
16030
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
395 #define NEXT_X x += tree->columns[i].width + (i > 0 ? 1 : 0)
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
396
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
397 static void
14033
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
398 tree_mark_columns(GntTree *tree, int pos, int y, chtype type)
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
399 {
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
400 GntWidget *widget = GNT_WIDGET(tree);
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
401 int i;
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
402 int x = pos;
16030
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
403 gboolean notfirst = FALSE;
14033
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
404
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
405 for (i = 0; i < tree->ncol - 1; i++)
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
406 {
18558
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
407 if (!COLUMN_INVISIBLE(tree, i)) {
16030
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
408 notfirst = TRUE;
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
409 NEXT_X;
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
410 }
18558
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
411 if (!COLUMN_INVISIBLE(tree, i+1) && notfirst)
16030
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
412 mvwaddch(widget->window, y, x, type);
14033
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
413 }
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
414 }
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
415
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
416 static void
13915
15a38b312abe [gaim-migrate @ 16312]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13913
diff changeset
417 redraw_tree(GntTree *tree)
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
418 {
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
419 int start, i;
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
420 GntWidget *widget = GNT_WIDGET(tree);
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
421 GntTreeRow *row;
18793
30a5e011f4b3 Fix compile warnings that only shows up with -O3. This may have caused
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18787
diff changeset
422 int pos, up, down = 0;
14193
fcfd3eea2160 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14188
diff changeset
423 int rows, scrcol;
26650
cfa29f8cf9b7 Update hardware cursor correctly.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25351
diff changeset
424 int current = 0;
14167
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
425
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
426 if (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_MAPPED))
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
427 return;
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
428
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
429 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER))
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
430 pos = 0;
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
431 else
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
432 pos = 1;
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
433
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
434 if (tree->top == NULL)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
435 tree->top = tree->root;
26734
509686762673 - Don't bother changing/signalling the selected row from NULL to NULL
Richard Nelson <wabz@pidgin.im>
parents: 26651
diff changeset
436 if (tree->current == NULL && tree->root != NULL) {
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
437 tree->current = tree->root;
16264
03aaf9aae68b emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents: 16185
diff changeset
438 tree_selection_changed(tree, NULL, tree->current);
03aaf9aae68b emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents: 16185
diff changeset
439 }
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
440
21240
b78eaddaae02 Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 20198
diff changeset
441 wbkgd(widget->window, gnt_color_pair(GNT_COLOR_NORMAL));
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
442
14033
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
443 start = 0;
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
444 if (tree->show_title)
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
445 {
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
446 int i;
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
447 int x = pos;
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
448
21240
b78eaddaae02 Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 20198
diff changeset
449 mvwhline(widget->window, pos + 1, pos, ACS_HLINE | gnt_color_pair(GNT_COLOR_NORMAL),
14188
cff503f91616 [gaim-migrate @ 16764]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14185
diff changeset
450 widget->priv.width - pos - 1);
21240
b78eaddaae02 Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 20198
diff changeset
451 mvwhline(widget->window, pos, pos, ' ' | gnt_color_pair(GNT_COLOR_NORMAL),
16030
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
452 widget->priv.width - pos - 1);
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
453
14033
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
454 for (i = 0; i < tree->ncol; i++)
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
455 {
18558
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
456 if (COLUMN_INVISIBLE(tree, i)) {
16030
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
457 continue;
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
458 }
19190
d0b7bf1b250a Make sure long titles remain within their own cell.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19184
diff changeset
459 mvwaddnstr(widget->window, pos, x + (x != pos), tree->columns[i].title, tree->columns[i].width);
16030
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
460 NEXT_X;
14033
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
461 }
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
462 if (pos)
14041
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
463 {
21254
ab6e08037b7c Draw the 'header' correctly when not showing borders.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21244
diff changeset
464 tree_mark_columns(tree, pos, 0,
ab6e08037b7c Draw the 'header' correctly when not showing borders.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21244
diff changeset
465 (tree->show_separator ? ACS_TTEE : ACS_HLINE) | gnt_color_pair(GNT_COLOR_NORMAL));
14041
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
466 tree_mark_columns(tree, pos, widget->priv.height - pos,
21254
ab6e08037b7c Draw the 'header' correctly when not showing borders.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21244
diff changeset
467 (tree->show_separator ? ACS_BTEE : ACS_HLINE) | gnt_color_pair(GNT_COLOR_NORMAL));
14041
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
468 }
14675
be8af28d1980 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14494
diff changeset
469 tree_mark_columns(tree, pos, pos + 1,
21240
b78eaddaae02 Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 20198
diff changeset
470 (tree->show_separator ? ACS_PLUS : ACS_HLINE) | gnt_color_pair(GNT_COLOR_NORMAL));
14675
be8af28d1980 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14494
diff changeset
471 tree_mark_columns(tree, pos, pos,
21240
b78eaddaae02 Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 20198
diff changeset
472 (tree->show_separator ? ACS_VLINE : ' ') | gnt_color_pair(GNT_COLOR_NORMAL));
14033
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
473 start = 2;
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
474 }
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
475
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
476 rows = widget->priv.height - pos * 2 - start - 1;
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
477 tree->bottom = get_next_n_opt(tree->top, rows, &down);
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
478 if (down < rows)
14167
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
479 {
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
480 tree->top = get_prev_n(tree->bottom, rows);
14167
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
481 if (tree->top == NULL)
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
482 tree->top = tree->root;
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
483 }
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
484
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
485 up = get_distance(tree->top, tree->current);
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
486 if (up < 0)
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
487 tree->top = tree->current;
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
488 else if (up >= widget->priv.height - pos)
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
489 tree->top = get_prev_n(tree->current, rows);
14169
90d1d4697e23 [gaim-migrate @ 16741]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14167
diff changeset
490
15222
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
491 if (tree->top && !row_matches_search(tree->top))
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
492 tree->top = get_next(tree->top);
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
493 row = tree->top;
14886
9f76d3a61aa7 [gaim-migrate @ 17591]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14885
diff changeset
494 scrcol = widget->priv.width - 1 - 2 * pos; /* exclude the borders and the scrollbar */
26734
509686762673 - Don't bother changing/signalling the selected row from NULL to NULL
Richard Nelson <wabz@pidgin.im>
parents: 26651
diff changeset
495
509686762673 - Don't bother changing/signalling the selected row from NULL to NULL
Richard Nelson <wabz@pidgin.im>
parents: 26651
diff changeset
496 if (tree->current && !row_matches_search(tree->current)) {
509686762673 - Don't bother changing/signalling the selected row from NULL to NULL
Richard Nelson <wabz@pidgin.im>
parents: 26651
diff changeset
497 GntTreeRow *old = tree->current;
509686762673 - Don't bother changing/signalling the selected row from NULL to NULL
Richard Nelson <wabz@pidgin.im>
parents: 26651
diff changeset
498 tree->current = tree->top;
509686762673 - Don't bother changing/signalling the selected row from NULL to NULL
Richard Nelson <wabz@pidgin.im>
parents: 26651
diff changeset
499 tree_selection_changed(tree, old, tree->current);
509686762673 - Don't bother changing/signalling the selected row from NULL to NULL
Richard Nelson <wabz@pidgin.im>
parents: 26651
diff changeset
500 }
509686762673 - Don't bother changing/signalling the selected row from NULL to NULL
Richard Nelson <wabz@pidgin.im>
parents: 26651
diff changeset
501
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
502 for (i = start + pos; row && i < widget->priv.height - pos;
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
503 i++, row = get_next(row))
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
504 {
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
505 char *str;
13915
15a38b312abe [gaim-migrate @ 16312]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13913
diff changeset
506 int wr;
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
507
13993
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
508 GntTextFormatFlags flags = row->flags;
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
509 int attr = 0;
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
510
15222
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
511 if (!row_matches_search(row))
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
512 continue;
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
513 str = update_row_text(tree, row);
13998
680eb6d0ed40 [gaim-migrate @ 16467]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13997
diff changeset
514
14886
9f76d3a61aa7 [gaim-migrate @ 17591]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14885
diff changeset
515 if ((wr = gnt_util_onscreen_width(str, NULL)) > scrcol)
13913
14dc0af2b33f [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13852
diff changeset
516 {
14886
9f76d3a61aa7 [gaim-migrate @ 17591]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14885
diff changeset
517 char *s = (char*)gnt_util_onscreen_width_to_pointer(str, scrcol, &wr);
13998
680eb6d0ed40 [gaim-migrate @ 16467]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13997
diff changeset
518 *s = '\0';
13913
14dc0af2b33f [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13852
diff changeset
519 }
13993
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
520
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
521 if (flags & GNT_TEXT_FLAG_BOLD)
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
522 attr |= A_BOLD;
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
523 if (flags & GNT_TEXT_FLAG_UNDERLINE)
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
524 attr |= A_UNDERLINE;
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
525 if (flags & GNT_TEXT_FLAG_BLINK)
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
526 attr |= A_BLINK;
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
527
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
528 if (row == tree->current)
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
529 {
26650
cfa29f8cf9b7 Update hardware cursor correctly.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25351
diff changeset
530 current = i;
25351
6a90d6dd2963 Boldify the selected row in the tree. This is helpful when, for example,
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23485
diff changeset
531 attr |= A_BOLD;
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
532 if (gnt_widget_has_focus(widget))
21240
b78eaddaae02 Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 20198
diff changeset
533 attr |= gnt_color_pair(GNT_COLOR_HIGHLIGHT);
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13940
diff changeset
534 else
21240
b78eaddaae02 Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 20198
diff changeset
535 attr |= gnt_color_pair(GNT_COLOR_HIGHLIGHT_D);
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
536 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
537 else
13989
9a647311c9ac [gaim-migrate @ 16447]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13969
diff changeset
538 {
13993
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
539 if (flags & GNT_TEXT_FLAG_DIM)
21804
931ef2cc7cfb Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents: 21273
diff changeset
540 if (row->color)
931ef2cc7cfb Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents: 21273
diff changeset
541 attr |= (A_DIM | gnt_color_pair(row->color));
931ef2cc7cfb Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents: 21273
diff changeset
542 else
931ef2cc7cfb Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents: 21273
diff changeset
543 attr |= (A_DIM | gnt_color_pair(GNT_COLOR_DISABLED));
13993
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
544 else if (flags & GNT_TEXT_FLAG_HIGHLIGHT)
21240
b78eaddaae02 Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 20198
diff changeset
545 attr |= (A_DIM | gnt_color_pair(GNT_COLOR_HIGHLIGHT));
21804
931ef2cc7cfb Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents: 21273
diff changeset
546 else if (row->color)
931ef2cc7cfb Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents: 21273
diff changeset
547 attr |= gnt_color_pair(row->color);
13993
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
548 else
21240
b78eaddaae02 Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 20198
diff changeset
549 attr |= gnt_color_pair(GNT_COLOR_NORMAL);
13989
9a647311c9ac [gaim-migrate @ 16447]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13969
diff changeset
550 }
13993
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
551
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
552 wbkgdset(widget->window, '\0' | attr);
28937
5f87e66597d9 Fix showing umlauts etc. on non-utf8 locales.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28822
diff changeset
553 mvwaddstr(widget->window, i, pos, C_(str));
14886
9f76d3a61aa7 [gaim-migrate @ 17591]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14885
diff changeset
554 whline(widget->window, ' ', scrcol - wr);
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
555 tree->bottom = row;
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
556 g_free(str);
14675
be8af28d1980 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14494
diff changeset
557 tree_mark_columns(tree, pos, i,
be8af28d1980 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14494
diff changeset
558 (tree->show_separator ? ACS_VLINE : ' ') | attr);
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
559 }
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
560
21240
b78eaddaae02 Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 20198
diff changeset
561 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_NORMAL));
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
562 while (i < widget->priv.height - pos)
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
563 {
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
564 mvwhline(widget->window, i, pos, ' ',
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
565 widget->priv.width - pos * 2 - 1);
14675
be8af28d1980 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14494
diff changeset
566 tree_mark_columns(tree, pos, i,
be8af28d1980 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14494
diff changeset
567 (tree->show_separator ? ACS_VLINE : ' '));
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
568 i++;
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
569 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
570
14886
9f76d3a61aa7 [gaim-migrate @ 17591]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14885
diff changeset
571 scrcol = widget->priv.width - pos - 1; /* position of the scrollbar */
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
572 rows--;
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
573 if (rows > 0)
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
574 {
18793
30a5e011f4b3 Fix compile warnings that only shows up with -O3. This may have caused
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18787
diff changeset
575 int total = 0;
14193
fcfd3eea2160 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14188
diff changeset
576 int showing, position;
fcfd3eea2160 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14188
diff changeset
577
fcfd3eea2160 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14188
diff changeset
578 get_next_n_opt(tree->root, g_list_length(tree->list), &total);
fcfd3eea2160 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14188
diff changeset
579 showing = rows * rows / MAX(total, 1) + 1;
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
580 showing = MIN(rows, showing);
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
581
14193
fcfd3eea2160 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14188
diff changeset
582 total -= rows;
fcfd3eea2160 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14188
diff changeset
583 up = get_distance(tree->root, tree->top);
fcfd3eea2160 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14188
diff changeset
584 down = total - up;
fcfd3eea2160 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14188
diff changeset
585
fcfd3eea2160 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14188
diff changeset
586 position = (rows - showing) * up / MAX(1, up + down);
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
587 position = MAX((tree->top != tree->root), position);
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
588
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
589 if (showing + position > rows)
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
590 position = rows - showing;
14169
90d1d4697e23 [gaim-migrate @ 16741]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14167
diff changeset
591
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
592 if (showing + position == rows && row)
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
593 position = MAX(0, rows - 1 - showing);
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
594 else if (showing + position < rows && !row)
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
595 position = rows - showing;
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
596
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
597 position += pos + start + 1;
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
598
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
599 mvwvline(widget->window, pos + start + 1, scrcol,
21240
b78eaddaae02 Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 20198
diff changeset
600 ' ' | gnt_color_pair(GNT_COLOR_NORMAL), rows);
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
601 mvwvline(widget->window, position, scrcol,
21240
b78eaddaae02 Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 20198
diff changeset
602 ACS_CKBOARD | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D), showing);
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
603 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
604
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
605 mvwaddch(widget->window, start + pos, scrcol,
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
606 ((tree->top != tree->root) ? ACS_UARROW : ' ') |
21240
b78eaddaae02 Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 20198
diff changeset
607 gnt_color_pair(GNT_COLOR_HIGHLIGHT_D));
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
608
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
609 mvwaddch(widget->window, widget->priv.height - pos - 1, scrcol,
21240
b78eaddaae02 Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 20198
diff changeset
610 (row ? ACS_DARROW : ' ') | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D));
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
611
16310
9883dbf9bab6 Show the search string in the tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16264
diff changeset
612 /* If there's a search-text, show it in the bottom of the tree */
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
613 if (tree->priv->search && tree->priv->search->len > 0) {
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
614 const char *str = gnt_util_onscreen_width_to_pointer(tree->priv->search->str, scrcol - 1, NULL);
21240
b78eaddaae02 Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 20198
diff changeset
615 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D));
16310
9883dbf9bab6 Show the search string in the tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16264
diff changeset
616 mvwaddnstr(widget->window, widget->priv.height - pos - 1, pos,
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
617 tree->priv->search->str, str - tree->priv->search->str);
16310
9883dbf9bab6 Show the search string in the tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16264
diff changeset
618 }
26650
cfa29f8cf9b7 Update hardware cursor correctly.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25351
diff changeset
619 wmove(widget->window, current, pos);
16310
9883dbf9bab6 Show the search string in the tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16264
diff changeset
620
13940
26ed45b11483 [gaim-migrate @ 16355]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13927
diff changeset
621 gnt_widget_queue_update(widget);
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
622 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
623
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
624 static void
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
625 gnt_tree_draw(GntWidget *widget)
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
626 {
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
627 GntTree *tree = GNT_TREE(widget);
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
628
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
629 redraw_tree(tree);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30499
diff changeset
630
14494
3575eac3a518 [gaim-migrate @ 17146]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14446
diff changeset
631 GNTDEBUG;
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
632 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
633
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
634 static void
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
635 gnt_tree_size_request(GntWidget *widget)
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
636 {
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
637 if (widget->priv.height == 0)
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
638 widget->priv.height = 10; /* XXX: Why?! */
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
639 if (widget->priv.width == 0)
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
640 {
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
641 GntTree *tree = GNT_TREE(widget);
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
642 int i, width = 0;
18624
03d4eb6b6684 Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18598
diff changeset
643 width = 1 + 2 * (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER));
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
644 for (i = 0; i < tree->ncol; i++)
18624
03d4eb6b6684 Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18598
diff changeset
645 if (!COLUMN_INVISIBLE(tree, i)) {
03d4eb6b6684 Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18598
diff changeset
646 width = width + tree->columns[i].width;
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
647 if (tree->priv->lastvisible != i)
18624
03d4eb6b6684 Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18598
diff changeset
648 width++;
03d4eb6b6684 Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18598
diff changeset
649 }
16030
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
650 widget->priv.width = width;
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
651 }
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
652 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
653
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
654 static void
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
655 gnt_tree_map(GntWidget *widget)
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
656 {
14167
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
657 GntTree *tree = GNT_TREE(widget);
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
658 if (widget->priv.width == 0 || widget->priv.height == 0)
14167
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
659 {
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
660 gnt_widget_size_request(widget);
14167
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
661 }
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
662 tree->top = tree->root;
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
663 tree->current = tree->root;
14494
3575eac3a518 [gaim-migrate @ 17146]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14446
diff changeset
664 GNTDEBUG;
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
665 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
666
13922
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
667 static void
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
668 tree_selection_changed(GntTree *tree, GntTreeRow *old, GntTreeRow *current)
13922
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
669 {
15702
111fdd9108cc Patch from Richard 'wabz' Nelson to add file-transfer ui. Amazing stuff\!
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15647
diff changeset
670 g_signal_emit(tree, signals[SIG_SELECTION_CHANGED], 0, old ? old->key : NULL,
111fdd9108cc Patch from Richard 'wabz' Nelson to add file-transfer ui. Amazing stuff\!
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15647
diff changeset
671 current ? current->key : NULL);
13922
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
672 }
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
673
14855
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
674 static gboolean
14962
abfaa2e03ac7 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14938
diff changeset
675 action_down(GntBindable *bind, GList *null)
14405
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
676 {
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
677 int dist;
14962
abfaa2e03ac7 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14938
diff changeset
678 GntTree *tree = GNT_TREE(bind);
14855
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
679 GntTreeRow *old = tree->current;
14405
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
680 GntTreeRow *row = get_next(tree->current);
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
681 if (row == NULL)
14855
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
682 return FALSE;
14405
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
683 tree->current = row;
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
684 if ((dist = get_distance(tree->current, tree->bottom)) < 0)
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
685 gnt_tree_scroll(tree, -dist);
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
686 else
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
687 redraw_tree(tree);
14855
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
688 if (old != tree->current)
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
689 tree_selection_changed(tree, old, tree->current);
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
690 return TRUE;
14405
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
691 }
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
692
14855
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
693 static gboolean
16032
55ba12884571 Backspace to jump to parent.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16031
diff changeset
694 action_move_parent(GntBindable *bind, GList *null)
55ba12884571 Backspace to jump to parent.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16031
diff changeset
695 {
55ba12884571 Backspace to jump to parent.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16031
diff changeset
696 GntTree *tree = GNT_TREE(bind);
55ba12884571 Backspace to jump to parent.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16031
diff changeset
697 GntTreeRow *row = tree->current;
16310
9883dbf9bab6 Show the search string in the tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16264
diff changeset
698 int dist;
9883dbf9bab6 Show the search string in the tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16264
diff changeset
699
22361
1ae443e7fe45 Fix a crash when pressing backspace at a menu
Richard Nelson <wabz@pidgin.im>
parents: 22311
diff changeset
700 if (!row || !row->parent || SEARCHING(tree))
16310
9883dbf9bab6 Show the search string in the tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16264
diff changeset
701 return FALSE;
9883dbf9bab6 Show the search string in the tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16264
diff changeset
702
9883dbf9bab6 Show the search string in the tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16264
diff changeset
703 tree->current = row->parent;
9883dbf9bab6 Show the search string in the tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16264
diff changeset
704 if ((dist = get_distance(tree->current, tree->top)) > 0)
9883dbf9bab6 Show the search string in the tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16264
diff changeset
705 gnt_tree_scroll(tree, -dist);
9883dbf9bab6 Show the search string in the tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16264
diff changeset
706 else
9883dbf9bab6 Show the search string in the tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16264
diff changeset
707 redraw_tree(tree);
9883dbf9bab6 Show the search string in the tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16264
diff changeset
708 tree_selection_changed(tree, row, tree->current);
16032
55ba12884571 Backspace to jump to parent.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16031
diff changeset
709 return TRUE;
55ba12884571 Backspace to jump to parent.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16031
diff changeset
710 }
55ba12884571 Backspace to jump to parent.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16031
diff changeset
711
55ba12884571 Backspace to jump to parent.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16031
diff changeset
712 static gboolean
14962
abfaa2e03ac7 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14938
diff changeset
713 action_up(GntBindable *bind, GList *list)
14405
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
714 {
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
715 int dist;
14962
abfaa2e03ac7 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14938
diff changeset
716 GntTree *tree = GNT_TREE(bind);
14855
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
717 GntTreeRow *old = tree->current;
14405
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
718 GntTreeRow *row = get_prev(tree->current);
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
719 if (!row)
14855
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
720 return FALSE;
14405
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
721 tree->current = row;
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
722 if ((dist = get_distance(tree->current, tree->top)) > 0)
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
723 gnt_tree_scroll(tree, -dist);
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
724 else
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
725 redraw_tree(tree);
14855
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
726 if (old != tree->current)
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
727 tree_selection_changed(tree, old, tree->current);
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
728
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
729 return TRUE;
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
730 }
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
731
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
732 static gboolean
14962
abfaa2e03ac7 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14938
diff changeset
733 action_page_down(GntBindable *bind, GList *null)
14855
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
734 {
14962
abfaa2e03ac7 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14938
diff changeset
735 GntTree *tree = GNT_TREE(bind);
14855
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
736 GntTreeRow *old = tree->current;
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
737 GntTreeRow *row = get_next(tree->bottom);
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
738 if (row)
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
739 {
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
740 int dist = get_distance(tree->top, tree->current);
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
741 tree->top = tree->bottom;
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
742 tree->current = get_next_n_opt(tree->top, dist, NULL);
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
743 redraw_tree(tree);
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
744 }
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
745 else if (tree->current != tree->bottom)
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
746 {
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
747 tree->current = tree->bottom;
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
748 redraw_tree(tree);
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
749 }
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
750
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
751 if (old != tree->current)
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
752 tree_selection_changed(tree, old, tree->current);
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
753 return TRUE;
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
754 }
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
755
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
756 static gboolean
14962
abfaa2e03ac7 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14938
diff changeset
757 action_page_up(GntBindable *bind, GList *null)
14855
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
758 {
14962
abfaa2e03ac7 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14938
diff changeset
759 GntWidget *widget = GNT_WIDGET(bind);
abfaa2e03ac7 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14938
diff changeset
760 GntTree *tree = GNT_TREE(bind);
14855
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
761 GntTreeRow *row;
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
762 GntTreeRow *old = tree->current;
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
763
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
764 if (tree->top != tree->root)
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
765 {
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
766 int dist = get_distance(tree->top, tree->current);
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
767 row = get_prev_n(tree->top, widget->priv.height - 1 -
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
768 tree->show_title * 2 - 2 * (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER) == 0));
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
769 if (row == NULL)
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
770 row = tree->root;
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
771 tree->top = row;
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
772 tree->current = get_next_n_opt(tree->top, dist, NULL);
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
773 redraw_tree(tree);
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
774 }
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
775 else if (tree->current != tree->top)
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
776 {
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
777 tree->current = tree->top;
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
778 redraw_tree(tree);
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
779 }
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
780 if (old != tree->current)
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
781 tree_selection_changed(tree, old, tree->current);
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
782 return TRUE;
14405
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
783 }
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
784
15222
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
785 static void
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
786 end_search(GntTree *tree)
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
787 {
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
788 if (tree->priv->search) {
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
789 g_source_remove(tree->priv->search_timeout);
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
790 g_string_free(tree->priv->search, TRUE);
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
791 tree->priv->search = NULL;
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
792 tree->priv->search_timeout = 0;
19184
72003b472bdc Fix a /-search bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18832
diff changeset
793 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(tree), GNT_WIDGET_DISABLE_ACTIONS);
15222
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
794 }
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
795 }
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
796
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
797 static gboolean
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
798 search_timeout(gpointer data)
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
799 {
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
800 GntTree *tree = data;
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
801
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
802 end_search(tree);
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
803 redraw_tree(tree);
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
804
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
805 return FALSE;
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
806 }
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
807
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
808 static gboolean
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
809 gnt_tree_key_pressed(GntWidget *widget, const char *text)
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
810 {
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
811 GntTree *tree = GNT_TREE(widget);
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
812 GntTreeRow *old = tree->current;
13922
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
813
22421
ccddf3ffaf41 '\n' (ctrl-j) should behave similar to '\r' (ctrl-m). Fixes #4833.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22361
diff changeset
814 if (text[0] == '\r' || text[0] == '\n') {
15222
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
815 end_search(tree);
14855
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
816 gnt_widget_activate(widget);
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
817 } else if (tree->priv->search) {
16310
9883dbf9bab6 Show the search string in the tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16264
diff changeset
818 gboolean changed = TRUE;
28822
a4fe79ebdcfe Allow printable chars when searching the tree
Richard Nelson <wabz@pidgin.im>
parents: 26734
diff changeset
819 if (g_unichar_isprint(*text)) {
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
820 tree->priv->search = g_string_append_c(tree->priv->search, *text);
16310
9883dbf9bab6 Show the search string in the tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16264
diff changeset
821 } else if (g_utf8_collate(text, GNT_KEY_BACKSPACE) == 0) {
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
822 if (tree->priv->search->len)
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
823 tree->priv->search->str[--tree->priv->search->len] = '\0';
16310
9883dbf9bab6 Show the search string in the tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16264
diff changeset
824 } else
9883dbf9bab6 Show the search string in the tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16264
diff changeset
825 changed = FALSE;
9883dbf9bab6 Show the search string in the tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16264
diff changeset
826 if (changed) {
15222
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
827 redraw_tree(tree);
18832
177a16b4b9f3 Allow disabling the widget actions on specific widgets. This allows, for
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18830
diff changeset
828 } else {
177a16b4b9f3 Allow disabling the widget actions on specific widgets. This allows, for
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18830
diff changeset
829 gnt_bindable_perform_action_key(GNT_BINDABLE(tree), text);
15222
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
830 }
23221
b63527bd6e1c Pressing arrow keys should reset the search timer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22421
diff changeset
831 g_source_remove(tree->priv->search_timeout);
26651
d9f1eeefb89c Save the world.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 26650
diff changeset
832 tree->priv->search_timeout = g_timeout_add_seconds(SEARCH_TIMEOUT_S, search_timeout, tree);
15222
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
833 return TRUE;
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
834 } else if (text[0] == ' ' && text[1] == 0) {
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
835 /* Space pressed */
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
836 GntTreeRow *row = tree->current;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
837 if (row && row->child)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
838 {
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
839 row->collapsed = !row->collapsed;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
840 redraw_tree(tree);
16165
24ec117bc52c Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents: 16032
diff changeset
841 g_signal_emit(tree, signals[SIG_COLLAPSED], 0, row->key, row->collapsed);
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
842 }
13969
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
843 else if (row && row->choice)
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
844 {
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
845 row->isselected = !row->isselected;
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
846 g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key);
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
847 redraw_tree(tree);
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
848 }
18171
dd5c73b7a3b8 I am not sure why I made this change. But it looks good.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18132
diff changeset
849 } else {
dd5c73b7a3b8 I am not sure why I made this change. But it looks good.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18132
diff changeset
850 return FALSE;
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
851 }
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
852
13922
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
853 if (old != tree->current)
13969
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
854 {
13922
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
855 tree_selection_changed(tree, old, tree->current);
13969
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
856 }
13922
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
857
18171
dd5c73b7a3b8 I am not sure why I made this change. But it looks good.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18132
diff changeset
858 return TRUE;
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
859 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
860
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
861 static void
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
862 gnt_tree_free_columns(GntTree *tree)
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
863 {
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
864 int i;
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
865 for (i = 0; i < tree->ncol; i++) {
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
866 g_free(tree->columns[i].title);
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
867 }
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
868 g_free(tree->columns);
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
869 }
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
870
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
871 static void
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
872 gnt_tree_destroy(GntWidget *widget)
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
873 {
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
874 GntTree *tree = GNT_TREE(widget);
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
875
15222
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
876 end_search(tree);
15702
111fdd9108cc Patch from Richard 'wabz' Nelson to add file-transfer ui. Amazing stuff\!
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15647
diff changeset
877 if (tree->hash)
111fdd9108cc Patch from Richard 'wabz' Nelson to add file-transfer ui. Amazing stuff\!
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15647
diff changeset
878 g_hash_table_destroy(tree->hash);
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
879 g_list_free(tree->list);
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
880 gnt_tree_free_columns(tree);
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
881 g_free(tree->priv);
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
882 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
883
14405
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
884 static gboolean
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
885 gnt_tree_clicked(GntWidget *widget, GntMouseEvent event, int x, int y)
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
886 {
14441
6c028af7f022 [gaim-migrate @ 17085]
Richard Nelson <wabz@pidgin.im>
parents: 14413
diff changeset
887 GntTree *tree = GNT_TREE(widget);
6c028af7f022 [gaim-migrate @ 17085]
Richard Nelson <wabz@pidgin.im>
parents: 14413
diff changeset
888 GntTreeRow *old = tree->current;
14405
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
889 if (event == GNT_MOUSE_SCROLL_UP) {
14962
abfaa2e03ac7 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14938
diff changeset
890 action_up(GNT_BINDABLE(widget), NULL);
14405
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
891 } else if (event == GNT_MOUSE_SCROLL_DOWN) {
14962
abfaa2e03ac7 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14938
diff changeset
892 action_down(GNT_BINDABLE(widget), NULL);
14405
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
893 } else if (event == GNT_LEFT_MOUSE_DOWN) {
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
894 GntTreeRow *row;
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
895 GntTree *tree = GNT_TREE(widget);
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
896 int pos = 1;
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
897 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER))
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
898 pos = 0;
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
899 if (tree->show_title)
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
900 pos += 2;
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
901 pos = y - widget->priv.y - pos;
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
902 row = get_next_n(tree->top, pos);
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
903 if (row && tree->current != row) {
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
904 GntTreeRow *old = tree->current;
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
905 tree->current = row;
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
906 redraw_tree(tree);
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
907 tree_selection_changed(tree, old, tree->current);
14413
bd998fe17d82 [gaim-migrate @ 17054]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
908 } else if (row && row == tree->current) {
bd998fe17d82 [gaim-migrate @ 17054]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
909 if (row->choice) {
bd998fe17d82 [gaim-migrate @ 17054]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
910 row->isselected = !row->isselected;
bd998fe17d82 [gaim-migrate @ 17054]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
911 g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key);
bd998fe17d82 [gaim-migrate @ 17054]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
912 redraw_tree(tree);
bd998fe17d82 [gaim-migrate @ 17054]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
913 } else {
bd998fe17d82 [gaim-migrate @ 17054]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
914 gnt_widget_activate(widget);
bd998fe17d82 [gaim-migrate @ 17054]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
915 }
14405
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
916 }
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
917 } else {
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
918 return FALSE;
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
919 }
14441
6c028af7f022 [gaim-migrate @ 17085]
Richard Nelson <wabz@pidgin.im>
parents: 14413
diff changeset
920 if (old != tree->current) {
6c028af7f022 [gaim-migrate @ 17085]
Richard Nelson <wabz@pidgin.im>
parents: 14413
diff changeset
921 tree_selection_changed(tree, old, tree->current);
6c028af7f022 [gaim-migrate @ 17085]
Richard Nelson <wabz@pidgin.im>
parents: 14413
diff changeset
922 }
14405
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
923 return TRUE;
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
924 }
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
925
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
926 static void
15113
956d8ac87bf6 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15039
diff changeset
927 gnt_tree_size_changed(GntWidget *widget, int w, int h)
956d8ac87bf6 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15039
diff changeset
928 {
956d8ac87bf6 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15039
diff changeset
929 GntTree *tree = GNT_TREE(widget);
956d8ac87bf6 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15039
diff changeset
930 if (widget->priv.width <= 0)
956d8ac87bf6 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15039
diff changeset
931 return;
18558
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
932
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
933 readjust_columns(tree);
15113
956d8ac87bf6 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15039
diff changeset
934 }
956d8ac87bf6 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15039
diff changeset
935
15222
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
936 static gboolean
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
937 start_search(GntBindable *bindable, GList *list)
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
938 {
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
939 GntTree *tree = GNT_TREE(bindable);
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
940 if (tree->priv->search)
15222
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
941 return FALSE;
18832
177a16b4b9f3 Allow disabling the widget actions on specific widgets. This allows, for
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18830
diff changeset
942 GNT_WIDGET_SET_FLAGS(GNT_WIDGET(tree), GNT_WIDGET_DISABLE_ACTIONS);
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
943 tree->priv->search = g_string_new(NULL);
26651
d9f1eeefb89c Save the world.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 26650
diff changeset
944 tree->priv->search_timeout = g_timeout_add_seconds(SEARCH_TIMEOUT_S, search_timeout, tree);
15222
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
945 return TRUE;
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
946 }
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
947
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
948 static gboolean
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
949 end_search_action(GntBindable *bindable, GList *list)
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
950 {
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
951 GntTree *tree = GNT_TREE(bindable);
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
952 if (tree->priv->search == NULL)
15222
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
953 return FALSE;
18832
177a16b4b9f3 Allow disabling the widget actions on specific widgets. This allows, for
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18830
diff changeset
954 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(tree), GNT_WIDGET_DISABLE_ACTIONS);
15222
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
955 end_search(tree);
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
956 redraw_tree(tree);
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
957 return TRUE;
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
958 }
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
959
29265
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
960 static gboolean
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
961 move_first_action(GntBindable *bind, GList *null)
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
962 {
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
963 GntTree *tree = GNT_TREE(bind);
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
964 GntTreeRow *row = tree->root;
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
965 GntTreeRow *old = tree->current;
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
966 if (row && !row_matches_search(row))
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
967 row = get_next(row);
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
968 if (row) {
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
969 tree->current = row;
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
970 redraw_tree(tree);
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
971 if (old != tree->current)
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
972 tree_selection_changed(tree, old, tree->current);
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
973 }
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
974
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
975 return TRUE;
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
976 }
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
977
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
978 static gboolean
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
979 move_last_action(GntBindable *bind, GList *null)
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
980 {
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
981 GntTree *tree = GNT_TREE(bind);
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
982 GntTreeRow *old = tree->current;
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
983 GntTreeRow *row = tree->bottom;
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
984 GntTreeRow *next;
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
985
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
986 while ((next = get_next(row)))
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
987 row = next;
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
988
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
989 if (row) {
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
990 tree->current = row;
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
991 redraw_tree(tree);
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
992 if (old != tree->current)
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
993 tree_selection_changed(tree, old, tree->current);
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
994 }
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
995
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
996 return TRUE;
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
997 }
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
998
15113
956d8ac87bf6 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15039
diff changeset
999 static void
18783
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1000 gnt_tree_set_property(GObject *obj, guint prop_id, const GValue *value,
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1001 GParamSpec *spec)
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1002 {
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1003 GntTree *tree = GNT_TREE(obj);
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1004 switch (prop_id) {
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1005 case PROP_COLUMNS:
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1006 _gnt_tree_init_internals(tree, g_value_get_int(value));
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1007 break;
22311
f3b63d7c4601 Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22301
diff changeset
1008 case PROP_EXPANDER:
f3b63d7c4601 Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22301
diff changeset
1009 if (tree->priv->expander_level == g_value_get_int(value))
f3b63d7c4601 Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22301
diff changeset
1010 break;
f3b63d7c4601 Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22301
diff changeset
1011 tree->priv->expander_level = g_value_get_int(value);
f3b63d7c4601 Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22301
diff changeset
1012 g_object_notify(obj, "expander-level");
18783
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1013 default:
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1014 break;
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1015 }
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1016 }
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1017
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1018 static void
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1019 gnt_tree_get_property(GObject *obj, guint prop_id, GValue *value,
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1020 GParamSpec *spec)
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1021 {
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1022 GntTree *tree = GNT_TREE(obj);
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1023 switch (prop_id) {
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1024 case PROP_COLUMNS:
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1025 g_value_set_int(value, tree->ncol);
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1026 break;
22311
f3b63d7c4601 Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22301
diff changeset
1027 case PROP_EXPANDER:
f3b63d7c4601 Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22301
diff changeset
1028 g_value_set_int(value, tree->priv->expander_level);
f3b63d7c4601 Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22301
diff changeset
1029 break;
18783
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1030 default:
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1031 break;
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1032 }
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1033 }
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1034
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1035 static void
13922
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
1036 gnt_tree_class_init(GntTreeClass *klass)
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1037 {
14962
abfaa2e03ac7 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14938
diff changeset
1038 GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass);
18783
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1039 GObjectClass *gclass = G_OBJECT_CLASS(klass);
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1040
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1041 parent_class = GNT_WIDGET_CLASS(klass);
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1042 parent_class->destroy = gnt_tree_destroy;
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1043 parent_class->draw = gnt_tree_draw;
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1044 parent_class->map = gnt_tree_map;
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1045 parent_class->size_request = gnt_tree_size_request;
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1046 parent_class->key_pressed = gnt_tree_key_pressed;
14405
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14398
diff changeset
1047 parent_class->clicked = gnt_tree_clicked;
15113
956d8ac87bf6 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15039
diff changeset
1048 parent_class->size_changed = gnt_tree_size_changed;
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1049
18783
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1050 gclass->set_property = gnt_tree_set_property;
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1051 gclass->get_property = gnt_tree_get_property;
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1052 g_object_class_install_property(gclass,
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1053 PROP_COLUMNS,
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1054 g_param_spec_int("columns", "Columns",
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1055 "Number of columns in the tree.",
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1056 1, G_MAXINT, 1,
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1057 G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1058 )
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1059 );
22311
f3b63d7c4601 Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22301
diff changeset
1060 g_object_class_install_property(gclass,
f3b63d7c4601 Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22301
diff changeset
1061 PROP_EXPANDER,
f3b63d7c4601 Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22301
diff changeset
1062 g_param_spec_int("expander-level", "Expander level",
f3b63d7c4601 Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22301
diff changeset
1063 "Number of levels to show expander in the tree.",
f3b63d7c4601 Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22301
diff changeset
1064 0, G_MAXINT, 1,
f3b63d7c4601 Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22301
diff changeset
1065 G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
f3b63d7c4601 Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22301
diff changeset
1066 )
f3b63d7c4601 Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22301
diff changeset
1067 );
18783
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1068
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30499
diff changeset
1069 signals[SIG_SELECTION_CHANGED] =
13922
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
1070 g_signal_new("selection-changed",
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
1071 G_TYPE_FROM_CLASS(klass),
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
1072 G_SIGNAL_RUN_LAST,
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
1073 G_STRUCT_OFFSET(GntTreeClass, selection_changed),
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
1074 NULL, NULL,
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1075 gnt_closure_marshal_VOID__POINTER_POINTER,
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1076 G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30499
diff changeset
1077 signals[SIG_SCROLLED] =
13927
c2f57a00bc1f [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13926
diff changeset
1078 g_signal_new("scrolled",
c2f57a00bc1f [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13926
diff changeset
1079 G_TYPE_FROM_CLASS(klass),
c2f57a00bc1f [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13926
diff changeset
1080 G_SIGNAL_RUN_LAST,
c2f57a00bc1f [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13926
diff changeset
1081 0,
c2f57a00bc1f [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13926
diff changeset
1082 NULL, NULL,
c2f57a00bc1f [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13926
diff changeset
1083 g_cclosure_marshal_VOID__INT,
c2f57a00bc1f [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13926
diff changeset
1084 G_TYPE_NONE, 1, G_TYPE_INT);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30499
diff changeset
1085 signals[SIG_TOGGLED] =
13969
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1086 g_signal_new("toggled",
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1087 G_TYPE_FROM_CLASS(klass),
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1088 G_SIGNAL_RUN_LAST,
14905
23f31a7acc73 [gaim-migrate @ 17612]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14898
diff changeset
1089 G_STRUCT_OFFSET(GntTreeClass, toggled),
13969
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1090 NULL, NULL,
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1091 g_cclosure_marshal_VOID__POINTER,
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1092 G_TYPE_NONE, 1, G_TYPE_POINTER);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30499
diff changeset
1093 signals[SIG_COLLAPSED] =
16165
24ec117bc52c Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents: 16032
diff changeset
1094 g_signal_new("collapse-toggled",
24ec117bc52c Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents: 16032
diff changeset
1095 G_TYPE_FROM_CLASS(klass),
24ec117bc52c Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents: 16032
diff changeset
1096 G_SIGNAL_RUN_LAST,
24ec117bc52c Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents: 16032
diff changeset
1097 0,
24ec117bc52c Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents: 16032
diff changeset
1098 NULL, NULL,
24ec117bc52c Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents: 16032
diff changeset
1099 gnt_closure_marshal_VOID__POINTER_BOOLEAN,
24ec117bc52c Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents: 16032
diff changeset
1100 G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_BOOLEAN);
13922
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
1101
14962
abfaa2e03ac7 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14938
diff changeset
1102 gnt_bindable_class_register_action(bindable, "move-up", action_up,
14938
ee27e45919ef [gaim-migrate @ 17645]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14928
diff changeset
1103 GNT_KEY_UP, NULL);
14962
abfaa2e03ac7 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14938
diff changeset
1104 gnt_bindable_register_binding(bindable, "move-up", GNT_KEY_CTRL_P, NULL);
abfaa2e03ac7 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14938
diff changeset
1105 gnt_bindable_class_register_action(bindable, "move-down", action_down,
14938
ee27e45919ef [gaim-migrate @ 17645]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14928
diff changeset
1106 GNT_KEY_DOWN, NULL);
14962
abfaa2e03ac7 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14938
diff changeset
1107 gnt_bindable_register_binding(bindable, "move-down", GNT_KEY_CTRL_N, NULL);
16032
55ba12884571 Backspace to jump to parent.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16031
diff changeset
1108 gnt_bindable_class_register_action(bindable, "move-parent", action_move_parent,
55ba12884571 Backspace to jump to parent.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16031
diff changeset
1109 GNT_KEY_BACKSPACE, NULL);
14962
abfaa2e03ac7 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14938
diff changeset
1110 gnt_bindable_class_register_action(bindable, "page-up", action_page_up,
14938
ee27e45919ef [gaim-migrate @ 17645]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14928
diff changeset
1111 GNT_KEY_PGUP, NULL);
14962
abfaa2e03ac7 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14938
diff changeset
1112 gnt_bindable_class_register_action(bindable, "page-down", action_page_down,
14938
ee27e45919ef [gaim-migrate @ 17645]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14928
diff changeset
1113 GNT_KEY_PGDOWN, NULL);
15222
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
1114 gnt_bindable_class_register_action(bindable, "start-search", start_search,
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
1115 "/", NULL);
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
1116 gnt_bindable_class_register_action(bindable, "end-search", end_search_action,
7662507d2b35 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15220
diff changeset
1117 "\033", NULL);
29265
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
1118 gnt_bindable_class_register_action(bindable, "move-first", move_first_action,
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
1119 GNT_KEY_HOME, NULL);
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
1120 gnt_bindable_class_register_action(bindable, "move-last", move_last_action,
7461ac2b3467 move-start (home) and move-last (end) actions for trees.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28937
diff changeset
1121 GNT_KEY_END, NULL);
14855
84c869823944 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14817
diff changeset
1122
14962
abfaa2e03ac7 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14938
diff changeset
1123 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), bindable);
14494
3575eac3a518 [gaim-migrate @ 17146]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14446
diff changeset
1124 GNTDEBUG;
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1125 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1126
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1127 static void
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1128 gnt_tree_init(GTypeInstance *instance, gpointer class)
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1129 {
14005
198d1658b390 [gaim-migrate @ 16480]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13999
diff changeset
1130 GntWidget *widget = GNT_WIDGET(instance);
14675
be8af28d1980 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14494
diff changeset
1131 GntTree *tree = GNT_TREE(widget);
be8af28d1980 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14494
diff changeset
1132 tree->show_separator = TRUE;
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1133 tree->priv = g_new0(GntTreePriv, 1);
19184
72003b472bdc Fix a /-search bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18832
diff changeset
1134 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y |
72003b472bdc Fix a /-search bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18832
diff changeset
1135 GNT_WIDGET_CAN_TAKE_FOCUS | GNT_WIDGET_NO_SHADOW);
72003b472bdc Fix a /-search bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18832
diff changeset
1136 gnt_widget_set_take_focus(widget, TRUE);
14005
198d1658b390 [gaim-migrate @ 16480]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13999
diff changeset
1137 widget->priv.minw = 4;
15822
3914c5c41521 gnttree can have a size of 1. This fixes <sadrul> meh. gntcombobox crashes if it has only one item in it
Richard Nelson <wabz@pidgin.im>
parents: 15806
diff changeset
1138 widget->priv.minh = 1;
14494
3575eac3a518 [gaim-migrate @ 17146]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14446
diff changeset
1139 GNTDEBUG;
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1140 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1141
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1142 /******************************************************************************
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1143 * GntTree API
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1144 *****************************************************************************/
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1145 GType
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1146 gnt_tree_get_gtype(void)
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1147 {
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1148 static GType type = 0;
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1149
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1150 if(type == 0)
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1151 {
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1152 static const GTypeInfo info = {
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1153 sizeof(GntTreeClass),
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1154 NULL, /* base_init */
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1155 NULL, /* base_finalize */
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1156 (GClassInitFunc)gnt_tree_class_init,
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1157 NULL, /* class_finalize */
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1158 NULL, /* class_data */
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1159 sizeof(GntTree),
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1160 0, /* n_preallocs */
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1161 gnt_tree_init, /* instance_init */
15874
46df7421a1b5 Enable DEBUG_CFLAGS in libgnt and fix up a number of compile warnings and
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15822
diff changeset
1162 NULL /* value_table */
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1163 };
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1164
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1165 type = g_type_register_static(GNT_TYPE_WIDGET,
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1166 "GntTree",
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1167 &info, 0);
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1168 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1169
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1170 return type;
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1171 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1172
13920
c51758bc563c [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13919
diff changeset
1173 static void
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1174 free_tree_col(gpointer data)
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1175 {
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1176 GntTreeCol *col = data;
19106
b20663268b67 fix typo-leak
Richard Nelson <wabz@pidgin.im>
parents: 19040
diff changeset
1177 if (!col->isbinary)
18598
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
1178 g_free(col->text);
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1179 g_free(col);
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1180 }
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1181
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1182 static void
13920
c51758bc563c [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13919
diff changeset
1183 free_tree_row(gpointer data)
c51758bc563c [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13919
diff changeset
1184 {
c51758bc563c [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13919
diff changeset
1185 GntTreeRow *row = data;
c51758bc563c [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13919
diff changeset
1186
13923
5552f69232b8 [gaim-migrate @ 16322]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13922
diff changeset
1187 if (!row)
5552f69232b8 [gaim-migrate @ 16322]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13922
diff changeset
1188 return;
5552f69232b8 [gaim-migrate @ 16322]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13922
diff changeset
1189
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1190 g_list_foreach(row->columns, (GFunc)free_tree_col, NULL);
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1191 g_list_free(row->columns);
13920
c51758bc563c [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13919
diff changeset
1192 g_free(row);
c51758bc563c [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13919
diff changeset
1193 }
c51758bc563c [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13919
diff changeset
1194
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1195 GntWidget *gnt_tree_new()
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1196 {
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1197 return gnt_tree_new_with_columns(1);
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1198 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1199
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1200 void gnt_tree_set_visible_rows(GntTree *tree, int rows)
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1201 {
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1202 GntWidget *widget = GNT_WIDGET(tree);
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1203 widget->priv.height = rows;
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1204 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER))
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1205 widget->priv.height += 2;
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1206 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1207
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1208 int gnt_tree_get_visible_rows(GntTree *tree)
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1209 {
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1210 GntWidget *widget = GNT_WIDGET(tree);
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1211 int ret = widget->priv.height;
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1212 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER))
13950
bd8d39b3a9e2 [gaim-migrate @ 16369]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13944
diff changeset
1213 ret -= 2;
bd8d39b3a9e2 [gaim-migrate @ 16369]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13944
diff changeset
1214 return ret;
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1215 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1216
18190
bcf28ef7e8ff Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@pidgin.im>
parents: 18171
diff changeset
1217 GList *gnt_tree_get_rows(GntTree *tree)
14817
742ea8c9ffb4 [gaim-migrate @ 17512]
Richard Nelson <wabz@pidgin.im>
parents: 14774
diff changeset
1218 {
742ea8c9ffb4 [gaim-migrate @ 17512]
Richard Nelson <wabz@pidgin.im>
parents: 14774
diff changeset
1219 return tree->list;
742ea8c9ffb4 [gaim-migrate @ 17512]
Richard Nelson <wabz@pidgin.im>
parents: 14774
diff changeset
1220 }
742ea8c9ffb4 [gaim-migrate @ 17512]
Richard Nelson <wabz@pidgin.im>
parents: 14774
diff changeset
1221
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1222 void gnt_tree_scroll(GntTree *tree, int count)
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1223 {
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1224 GntTreeRow *row;
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1225
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1226 if (count < 0)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1227 {
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1228 if (get_root_distance(tree->top) == 0)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1229 return;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1230 row = get_prev_n(tree->top, -count);
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1231 if (row == NULL)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1232 row = tree->root;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1233 tree->top = row;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1234 }
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1235 else
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1236 {
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1237 get_next_n_opt(tree->bottom, count, &count);
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1238 tree->top = get_next_n(tree->top, count);
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1239 }
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1240
13915
15a38b312abe [gaim-migrate @ 16312]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13913
diff changeset
1241 redraw_tree(tree);
13927
c2f57a00bc1f [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13926
diff changeset
1242 g_signal_emit(tree, signals[SIG_SCROLLED], 0, count);
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1243 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1244
14167
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1245 static gpointer
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1246 find_position(GntTree *tree, gpointer key, gpointer parent)
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1247 {
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1248 GntTreeRow *row;
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1249
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1250 if (tree->priv->compare == NULL)
14167
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1251 return NULL;
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1252
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1253 if (parent == NULL)
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1254 row = tree->root;
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1255 else
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1256 row = g_hash_table_lookup(tree->hash, parent);
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1257
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1258 if (!row)
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1259 return NULL;
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1260
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1261 if (parent)
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1262 row = row->child;
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1263
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1264 while (row)
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1265 {
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1266 if (tree->priv->compare(key, row->key) < 0)
14167
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1267 return (row->prev ? row->prev->key : NULL);
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1268 if (row->next)
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1269 row = row->next;
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1270 else
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1271 return row->key;
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1272 }
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1273 return NULL;
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1274 }
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1275
14774
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1276 void gnt_tree_sort_row(GntTree *tree, gpointer key)
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1277 {
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1278 GntTreeRow *row, *q, *s;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1279 int current, newp;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1280
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1281 if (!tree->priv->compare)
14774
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1282 return;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1283
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1284 row = g_hash_table_lookup(tree->hash, key);
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1285 g_return_if_fail(row != NULL);
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1286
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1287 current = g_list_index(tree->list, key);
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1288
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1289 if (row->parent)
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1290 s = row->parent->child;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1291 else
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1292 s = tree->root;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1293
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1294 q = NULL;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1295 while (s) {
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1296 if (tree->priv->compare(row->key, s->key) < 0)
14774
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1297 break;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1298 q = s;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1299 s = s->next;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1300 }
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1301
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1302 /* Move row between q and s */
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1303 if (row == q || row == s)
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1304 return;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1305
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1306 if (q == NULL) {
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1307 /* row becomes the first child of its parent */
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1308 row->prev->next = row->next; /* row->prev cannot be NULL at this point */
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1309 if (row->next)
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1310 row->next->prev = row->prev;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1311 if (row->parent)
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1312 row->parent->child = row;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1313 else
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1314 tree->root = row;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1315 row->next = s;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1316 s->prev = row; /* s cannot be NULL */
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1317 row->prev = NULL;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1318 newp = g_list_index(tree->list, s) - 1;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1319 } else {
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1320 if (row->prev) {
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1321 row->prev->next = row->next;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1322 } else {
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1323 /* row was the first child of its parent */
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1324 if (row->parent)
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1325 row->parent->child = row->next;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1326 else
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1327 tree->top = row->next;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1328 }
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1329
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1330 if (row->next)
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1331 row->next->prev = row->prev;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1332
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1333 q->next = row;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1334 row->prev = q;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1335 if (s)
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1336 s->prev = row;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1337 row->next = s;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1338 newp = g_list_index(tree->list, q) + 1;
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1339 }
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1340 tree->list = g_list_reposition_child(tree->list, current, newp);
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1341
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1342 redraw_tree(tree);
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1343 }
317db0f851e0 [gaim-migrate @ 17466]
Richard Nelson <wabz@pidgin.im>
parents: 14678
diff changeset
1344
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1345 GntTreeRow *gnt_tree_add_row_after(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro)
13920
c51758bc563c [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13919
diff changeset
1346 {
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1347 GntTreeRow *pr = NULL;
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1348
29377
6c8add94b5a4 Fix CVE-2010-0420, a possible remote crash when handling chat room
Mark Doliner <markdoliner@pidgin.im>
parents: 29342
diff changeset
1349 if (g_hash_table_lookup(tree->hash, key)) {
6c8add94b5a4 Fix CVE-2010-0420, a possible remote crash when handling chat room
Mark Doliner <markdoliner@pidgin.im>
parents: 29342
diff changeset
1350 gnt_tree_remove(tree, key);
6c8add94b5a4 Fix CVE-2010-0420, a possible remote crash when handling chat room
Mark Doliner <markdoliner@pidgin.im>
parents: 29342
diff changeset
1351 }
6c8add94b5a4 Fix CVE-2010-0420, a possible remote crash when handling chat room
Mark Doliner <markdoliner@pidgin.im>
parents: 29342
diff changeset
1352
20198
90ae53934c28 applied changes from 88f296b3653b5a7578a7581c1582d37390c9d212
Luke Schierer <lschiere@pidgin.im>
parents: 19859
diff changeset
1353 row->tree = tree;
90ae53934c28 applied changes from 88f296b3653b5a7578a7581c1582d37390c9d212
Luke Schierer <lschiere@pidgin.im>
parents: 19859
diff changeset
1354 row->key = key;
90ae53934c28 applied changes from 88f296b3653b5a7578a7581c1582d37390c9d212
Luke Schierer <lschiere@pidgin.im>
parents: 19859
diff changeset
1355 row->data = NULL;
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1356 g_hash_table_replace(tree->hash, key, row);
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1357
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1358 if (bigbro == NULL && tree->priv->compare)
14167
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1359 {
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1360 bigbro = find_position(tree, key, parent);
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1361 }
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1362
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1363 if (tree->root == NULL)
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1364 {
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1365 tree->root = row;
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1366 tree->list = g_list_prepend(tree->list, key);
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1367 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1368 else
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1369 {
13989
9a647311c9ac [gaim-migrate @ 16447]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13969
diff changeset
1370 int position = 0;
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1371
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1372 if (bigbro)
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1373 {
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1374 pr = g_hash_table_lookup(tree->hash, bigbro);
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1375 if (pr)
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1376 {
13919
94caf5dc02b4 [gaim-migrate @ 16316]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13918
diff changeset
1377 if (pr->next) pr->next->prev = row;
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1378 row->next = pr->next;
13919
94caf5dc02b4 [gaim-migrate @ 16316]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13918
diff changeset
1379 row->prev = pr;
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1380 pr->next = row;
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1381 row->parent = pr->parent;
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1382
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1383 position = g_list_index(tree->list, bigbro);
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1384 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1385 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1386
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30499
diff changeset
1387 if (pr == NULL && parent)
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1388 {
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1389 pr = g_hash_table_lookup(tree->hash, parent);
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1390 if (pr)
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1391 {
13919
94caf5dc02b4 [gaim-migrate @ 16316]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13918
diff changeset
1392 if (pr->child) pr->child->prev = row;
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1393 row->next = pr->child;
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1394 pr->child = row;
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1395 row->parent = pr;
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1396
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1397 position = g_list_index(tree->list, parent);
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1398 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1399 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1400
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1401 if (pr == NULL)
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1402 {
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1403 GntTreeRow *r = tree->root;
14167
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1404 row->next = r;
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1405 if (r) r->prev = row;
15220
fc8b223f4b75 [gaim-migrate @ 17944]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15113
diff changeset
1406 if (tree->current == tree->root)
fc8b223f4b75 [gaim-migrate @ 17944]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15113
diff changeset
1407 tree->current = row;
14167
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1408 tree->root = row;
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1409 tree->list = g_list_prepend(tree->list, key);
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1410 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1411 else
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1412 {
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1413 tree->list = g_list_insert(tree->list, key, position + 1);
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1414 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1415 }
14167
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1416 redraw_tree(tree);
13922
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
1417
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
1418 return row;
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1419 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1420
14167
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1421 GntTreeRow *gnt_tree_add_row_last(GntTree *tree, void *key, GntTreeRow *row, void *parent)
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1422 {
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1423 GntTreeRow *pr = NULL, *br = NULL;
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1424
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1425 if (parent)
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1426 pr = g_hash_table_lookup(tree->hash, parent);
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1427
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1428 if (pr)
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1429 br = pr->child;
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1430 else
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1431 br = tree->root;
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1432
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1433 if (br)
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1434 {
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1435 while (br->next)
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1436 br = br->next;
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1437 }
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1438
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1439 return gnt_tree_add_row_after(tree, key, row, parent, br ? br->key : NULL);
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1440 }
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1441
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1442 gpointer gnt_tree_get_selection_data(GntTree *tree)
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1443 {
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1444 if (tree->current)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1445 return tree->current->key; /* XXX: perhaps we should just get rid of 'data' */
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1446 return NULL;
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1447 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1448
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1449 char *gnt_tree_get_selection_text(GntTree *tree)
13997
546ca912cb25 [gaim-migrate @ 16466]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13996
diff changeset
1450 {
546ca912cb25 [gaim-migrate @ 16466]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13996
diff changeset
1451 if (tree->current)
14041
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1452 return update_row_text(tree, tree->current);
13997
546ca912cb25 [gaim-migrate @ 16466]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13996
diff changeset
1453 return NULL;
546ca912cb25 [gaim-migrate @ 16466]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13996
diff changeset
1454 }
546ca912cb25 [gaim-migrate @ 16466]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13996
diff changeset
1455
18830
7e9784f65d5d Anoter patch from Javeed Shaikh to introduce a utility function for a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18829
diff changeset
1456 GList *gnt_tree_get_row_text_list(GntTree *tree, gpointer key)
14041
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1457 {
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1458 GList *list = NULL, *iter;
18830
7e9784f65d5d Anoter patch from Javeed Shaikh to introduce a utility function for a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18829
diff changeset
1459 GntTreeRow *row = key ? g_hash_table_lookup(tree->hash, key) : tree->current;
14041
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1460 int i;
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1461
18830
7e9784f65d5d Anoter patch from Javeed Shaikh to introduce a utility function for a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18829
diff changeset
1462 if (!row)
14041
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1463 return NULL;
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1464
18830
7e9784f65d5d Anoter patch from Javeed Shaikh to introduce a utility function for a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18829
diff changeset
1465 for (i = 0, iter = row->columns; i < tree->ncol && iter;
14041
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1466 i++, iter = iter->next)
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1467 {
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1468 GntTreeCol *col = iter->data;
18830
7e9784f65d5d Anoter patch from Javeed Shaikh to introduce a utility function for a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18829
diff changeset
1469 list = g_list_append(list, BINARY_DATA(tree, i) ? col->text : g_strdup(col->text));
14041
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1470 }
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1471
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1472 return list;
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1473 }
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1474
18830
7e9784f65d5d Anoter patch from Javeed Shaikh to introduce a utility function for a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18829
diff changeset
1475 GList *gnt_tree_get_selection_text_list(GntTree *tree)
7e9784f65d5d Anoter patch from Javeed Shaikh to introduce a utility function for a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18829
diff changeset
1476 {
7e9784f65d5d Anoter patch from Javeed Shaikh to introduce a utility function for a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18829
diff changeset
1477 return gnt_tree_get_row_text_list(tree, NULL);
7e9784f65d5d Anoter patch from Javeed Shaikh to introduce a utility function for a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18829
diff changeset
1478 }
7e9784f65d5d Anoter patch from Javeed Shaikh to introduce a utility function for a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18829
diff changeset
1479
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1480 void gnt_tree_remove(GntTree *tree, gpointer key)
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1481 {
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1482 GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
15761
3e83050bff0a recursively remove child nodes. This fixes a crash (often caused by going offline)
Richard Nelson <wabz@pidgin.im>
parents: 15702
diff changeset
1483 static int depth = 0; /* Only redraw after all child nodes are removed */
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1484 if (row)
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1485 {
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1486 gboolean redraw = FALSE;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1487
15039
20a0d0117a47 [gaim-migrate @ 17756]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14962
diff changeset
1488 if (row->child) {
15761
3e83050bff0a recursively remove child nodes. This fixes a crash (often caused by going offline)
Richard Nelson <wabz@pidgin.im>
parents: 15702
diff changeset
1489 depth++;
3e83050bff0a recursively remove child nodes. This fixes a crash (often caused by going offline)
Richard Nelson <wabz@pidgin.im>
parents: 15702
diff changeset
1490 while (row->child) {
3e83050bff0a recursively remove child nodes. This fixes a crash (often caused by going offline)
Richard Nelson <wabz@pidgin.im>
parents: 15702
diff changeset
1491 gnt_tree_remove(tree, row->child->key);
15039
20a0d0117a47 [gaim-migrate @ 17756]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14962
diff changeset
1492 }
15761
3e83050bff0a recursively remove child nodes. This fixes a crash (often caused by going offline)
Richard Nelson <wabz@pidgin.im>
parents: 15702
diff changeset
1493 depth--;
15039
20a0d0117a47 [gaim-migrate @ 17756]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14962
diff changeset
1494 }
20a0d0117a47 [gaim-migrate @ 17756]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14962
diff changeset
1495
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1496 if (get_distance(tree->top, row) >= 0 && get_distance(row, tree->bottom) >= 0)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1497 redraw = TRUE;
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1498
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1499 /* Update root/top/current/bottom if necessary */
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1500 if (tree->root == row)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1501 tree->root = get_next(row);
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1502 if (tree->top == row)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1503 {
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1504 if (tree->top != tree->root)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1505 tree->top = get_prev(row);
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1506 else
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1507 tree->top = get_next(row);
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1508 }
15617
f4813fc9b095 Patch from Richard 'wabz' Nelson: Make sure selection-changed signal is emitted if selected item is removed.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15480
diff changeset
1509 if (tree->current == row)
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1510 {
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1511 if (tree->current != tree->root)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1512 tree->current = get_prev(row);
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1513 else
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1514 tree->current = get_next(row);
15617
f4813fc9b095 Patch from Richard 'wabz' Nelson: Make sure selection-changed signal is emitted if selected item is removed.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15480
diff changeset
1515 tree_selection_changed(tree, row, tree->current);
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1516 }
15617
f4813fc9b095 Patch from Richard 'wabz' Nelson: Make sure selection-changed signal is emitted if selected item is removed.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15480
diff changeset
1517 if (tree->bottom == row)
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1518 {
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1519 tree->bottom = get_prev(row);
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1520 }
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1521
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1522 /* Fix the links */
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1523 if (row->next)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1524 row->next->prev = row->prev;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1525 if (row->parent && row->parent->child == row)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1526 row->parent->child = row->next;
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1527 if (row->prev)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1528 row->prev->next = row->next;
15761
3e83050bff0a recursively remove child nodes. This fixes a crash (often caused by going offline)
Richard Nelson <wabz@pidgin.im>
parents: 15702
diff changeset
1529
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1530 g_hash_table_remove(tree->hash, key);
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1531 tree->list = g_list_remove(tree->list, key);
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1532
15761
3e83050bff0a recursively remove child nodes. This fixes a crash (often caused by going offline)
Richard Nelson <wabz@pidgin.im>
parents: 15702
diff changeset
1533 if (redraw && depth == 0)
13852
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1534 {
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1535 redraw_tree(tree);
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1536 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1537 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1538 }
1d3ae9f34d42 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1539
14270
710ef4096bac [gaim-migrate @ 16883]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14193
diff changeset
1540 static gboolean
710ef4096bac [gaim-migrate @ 16883]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14193
diff changeset
1541 return_true(gpointer key, gpointer data, gpointer null)
710ef4096bac [gaim-migrate @ 16883]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14193
diff changeset
1542 {
710ef4096bac [gaim-migrate @ 16883]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14193
diff changeset
1543 return TRUE;
710ef4096bac [gaim-migrate @ 16883]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14193
diff changeset
1544 }
710ef4096bac [gaim-migrate @ 16883]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14193
diff changeset
1545
14153
9da98052a4e1 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
1546 void gnt_tree_remove_all(GntTree *tree)
9da98052a4e1 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
1547 {
9da98052a4e1 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
1548 tree->root = NULL;
15220
fc8b223f4b75 [gaim-migrate @ 17944]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15113
diff changeset
1549 g_hash_table_foreach_remove(tree->hash, (GHRFunc)return_true, tree);
14153
9da98052a4e1 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
1550 g_list_free(tree->list);
9da98052a4e1 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
1551 tree->list = NULL;
9da98052a4e1 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
1552 tree->current = tree->top = tree->bottom = NULL;
9da98052a4e1 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
1553 }
9da98052a4e1 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
1554
13922
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
1555 int gnt_tree_get_selection_visible_line(GntTree *tree)
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
1556 {
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1557 return get_distance(tree->top, tree->current) +
13922
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
1558 !!(GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER));
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
1559 }
7195a6fe2416 [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13920
diff changeset
1560
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1561 void gnt_tree_change_text(GntTree *tree, gpointer key, int colno, const char *text)
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1562 {
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1563 GntTreeRow *row;
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1564 GntTreeCol *col;
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1565
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1566 g_return_if_fail(colno < tree->ncol);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30499
diff changeset
1567
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1568 row = g_hash_table_lookup(tree->hash, key);
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1569 if (row)
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1570 {
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1571 col = g_list_nth_data(row->columns, colno);
18598
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
1572 if (BINARY_DATA(tree, colno)) {
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
1573 col->text = (gpointer)text;
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
1574 } else {
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
1575 g_free(col->text);
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
1576 col->text = g_strdup(text ? text : "");
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
1577 }
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1578
21261
eaf551849532 Do not do unnecessary processing when updating text in a column.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21254
diff changeset
1579 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_MAPPED) &&
eaf551849532 Do not do unnecessary processing when updating text in a column.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21254
diff changeset
1580 get_distance(tree->top, row) >= 0 && get_distance(row, tree->bottom) >= 0)
13926
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1581 redraw_tree(tree);
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1582 }
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1583 }
d2c1522276b3 [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13923
diff changeset
1584
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1585 GntTreeRow *gnt_tree_add_choice(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro)
13969
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1586 {
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1587 GntTreeRow *r;
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1588 r = g_hash_table_lookup(tree->hash, key);
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1589 g_return_val_if_fail(!r || !r->choice, NULL);
14398
351f2af228f1 [gaim-migrate @ 17032]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14278
diff changeset
1590
351f2af228f1 [gaim-migrate @ 17032]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14278
diff changeset
1591 if (bigbro == NULL) {
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1592 if (tree->priv->compare)
15806
1972a83ada1f Sort the plugin list.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15761
diff changeset
1593 bigbro = find_position(tree, key, parent);
1972a83ada1f Sort the plugin list.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15761
diff changeset
1594 else {
1972a83ada1f Sort the plugin list.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15761
diff changeset
1595 r = g_hash_table_lookup(tree->hash, parent);
1972a83ada1f Sort the plugin list.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15761
diff changeset
1596 if (!r)
1972a83ada1f Sort the plugin list.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15761
diff changeset
1597 r = tree->root;
1972a83ada1f Sort the plugin list.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15761
diff changeset
1598 else
1972a83ada1f Sort the plugin list.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15761
diff changeset
1599 r = r->child;
1972a83ada1f Sort the plugin list.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15761
diff changeset
1600 if (r) {
1972a83ada1f Sort the plugin list.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15761
diff changeset
1601 while (r->next)
1972a83ada1f Sort the plugin list.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15761
diff changeset
1602 r = r->next;
1972a83ada1f Sort the plugin list.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15761
diff changeset
1603 bigbro = r->key;
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30499
diff changeset
1604 }
15806
1972a83ada1f Sort the plugin list.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15761
diff changeset
1605 }
14398
351f2af228f1 [gaim-migrate @ 17032]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14278
diff changeset
1606 }
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1607 row = gnt_tree_add_row_after(tree, key, row, parent, bigbro);
13969
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1608 row->choice = TRUE;
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1609
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1610 return row;
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1611 }
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1612
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1613 void gnt_tree_set_choice(GntTree *tree, void *key, gboolean set)
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1614 {
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1615 GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1616
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1617 if (!row)
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1618 return;
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1619 g_return_if_fail(row->choice);
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1620
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1621 row->isselected = set;
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1622 redraw_tree(tree);
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1623 }
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1624
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1625 gboolean gnt_tree_get_choice(GntTree *tree, void *key)
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1626 {
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1627 GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1628
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1629 if (!row)
13989
9a647311c9ac [gaim-migrate @ 16447]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13969
diff changeset
1630 return FALSE;
13969
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1631 g_return_val_if_fail(row->choice, FALSE);
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1632
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1633 return row->isselected;
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1634 }
0541f389442e [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13958
diff changeset
1635
13993
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
1636 void gnt_tree_set_row_flags(GntTree *tree, void *key, GntTextFormatFlags flags)
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
1637 {
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
1638 GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
13996
fa46d71780ff [gaim-migrate @ 16462]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13993
diff changeset
1639 if (!row || row->flags == flags)
13993
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
1640 return;
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
1641
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
1642 row->flags = flags;
13997
546ca912cb25 [gaim-migrate @ 16466]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13996
diff changeset
1643 redraw_tree(tree); /* XXX: It shouldn't be necessary to redraw the whole darned tree */
13993
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
1644 }
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
1645
21804
931ef2cc7cfb Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents: 21273
diff changeset
1646 void gnt_tree_set_row_color(GntTree *tree, void *key, int color)
931ef2cc7cfb Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents: 21273
diff changeset
1647 {
931ef2cc7cfb Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents: 21273
diff changeset
1648 GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
931ef2cc7cfb Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents: 21273
diff changeset
1649 if (!row || row->color == color)
931ef2cc7cfb Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents: 21273
diff changeset
1650 return;
931ef2cc7cfb Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents: 21273
diff changeset
1651
931ef2cc7cfb Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents: 21273
diff changeset
1652 row->color = color;
931ef2cc7cfb Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents: 21273
diff changeset
1653 redraw_tree(tree);
931ef2cc7cfb Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents: 21273
diff changeset
1654 }
931ef2cc7cfb Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
Richard Nelson <wabz@pidgin.im>
parents: 21273
diff changeset
1655
14014
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
1656 void gnt_tree_set_selected(GntTree *tree , void *key)
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
1657 {
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
1658 int dist;
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
1659 GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
16264
03aaf9aae68b emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents: 16185
diff changeset
1660 if (!row || row == tree->current)
14014
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
1661 return;
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
1662
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
1663 if (tree->top == NULL)
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
1664 tree->top = row;
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
1665 if (tree->bottom == NULL)
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
1666 tree->bottom = row;
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
1667
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
1668 tree->current = row;
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
1669 if ((dist = get_distance(tree->current, tree->bottom)) < 0)
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
1670 gnt_tree_scroll(tree, -dist);
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
1671 else if ((dist = get_distance(tree->current, tree->top)) > 0)
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
1672 gnt_tree_scroll(tree, -dist);
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
1673 else
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
1674 redraw_tree(tree);
16264
03aaf9aae68b emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents: 16185
diff changeset
1675 tree_selection_changed(tree, row, tree->current);
14014
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
1676 }
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
1677
18783
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1678 static void _gnt_tree_init_internals(GntTree *tree, int col)
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1679 {
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1680 gnt_tree_free_columns(tree);
18783
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1681
14675
be8af28d1980 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14494
diff changeset
1682 tree->ncol = col;
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1683 tree->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_tree_row);
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1684 tree->columns = g_new0(struct _GntTreeColInfo, col);
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1685 tree->priv->lastvisible = col - 1;
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1686 while (col--)
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1687 {
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1688 tree->columns[col].width = 15;
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1689 }
14678
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1690 tree->list = NULL;
14033
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
1691 tree->show_title = FALSE;
18783
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1692 g_object_notify(G_OBJECT(tree), "columns");
14675
be8af28d1980 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14494
diff changeset
1693 }
be8af28d1980 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14494
diff changeset
1694
be8af28d1980 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14494
diff changeset
1695 GntWidget *gnt_tree_new_with_columns(int col)
be8af28d1980 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14494
diff changeset
1696 {
18783
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1697 GntWidget *widget = g_object_new(GNT_TYPE_TREE,
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1698 "columns", col,
22311
f3b63d7c4601 Allow customizing the expander in the tree. This is mostly a hack ;)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22301
diff changeset
1699 "expander-level", 1,
18783
ca193fb6d9a2 Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18632
diff changeset
1700 NULL);
14675
be8af28d1980 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14494
diff changeset
1701
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1702 return widget;
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1703 }
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1704
14041
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1705 GntTreeRow *gnt_tree_create_row_from_list(GntTree *tree, GList *list)
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1706 {
14041
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1707 GList *iter;
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1708 int i;
14041
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1709 GntTreeRow *row = g_new0(GntTreeRow, 1);
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1710
14041
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1711 for (i = 0, iter = list; i < tree->ncol && iter; iter = iter->next, i++)
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1712 {
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1713 GntTreeCol *col = g_new0(GntTreeCol, 1);
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1714 col->span = 1;
18598
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
1715 if (BINARY_DATA(tree, i)) {
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
1716 col->text = iter->data;
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
1717 col->isbinary = TRUE;
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
1718 } else {
19235
a6b00192295b disapproval of revision '8d049f26f06abbea924dc65289b6edaf4f4adcd0'
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19234
diff changeset
1719 col->text = g_strdup(iter->data ? iter->data : "");
18598
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
1720 col->isbinary = FALSE;
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
1721 }
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1722
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1723 row->columns = g_list_append(row->columns, col);
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1724 }
14041
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1725
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1726 return row;
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1727 }
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1728
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1729 GntTreeRow *gnt_tree_create_row(GntTree *tree, ...)
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1730 {
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1731 int i;
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1732 va_list args;
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1733 GList *list = NULL;
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1734 GntTreeRow *row;
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1735
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1736 va_start(args, tree);
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1737 for (i = 0; i < tree->ncol; i++)
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1738 {
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
1739 list = g_list_append(list, va_arg(args, char *));
14041
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1740 }
14033
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
1741 va_end(args);
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1742
14041
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1743 row = gnt_tree_create_row_from_list(tree, list);
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1744 g_list_free(list);
6afba85cfc30 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
1745
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1746 return row;
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1747 }
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1748
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1749 void gnt_tree_set_col_width(GntTree *tree, int col, int width)
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1750 {
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1751 g_return_if_fail(col < tree->ncol);
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1752
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1753 tree->columns[col].width = width;
18558
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1754 if (tree->columns[col].width_ratio == 0)
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1755 tree->columns[col].width_ratio = width;
14026
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1756 }
ad91ce0effe2 [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
1757
18403
218a6f247a1c Oops. I missed this. This allows setting tree-column titles one by one.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18255
diff changeset
1758 void gnt_tree_set_column_title(GntTree *tree, int index, const char *title)
218a6f247a1c Oops. I missed this. This allows setting tree-column titles one by one.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18255
diff changeset
1759 {
218a6f247a1c Oops. I missed this. This allows setting tree-column titles one by one.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18255
diff changeset
1760 g_free(tree->columns[index].title);
218a6f247a1c Oops. I missed this. This allows setting tree-column titles one by one.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18255
diff changeset
1761 tree->columns[index].title = g_strdup(title);
218a6f247a1c Oops. I missed this. This allows setting tree-column titles one by one.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18255
diff changeset
1762 }
218a6f247a1c Oops. I missed this. This allows setting tree-column titles one by one.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18255
diff changeset
1763
14033
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
1764 void gnt_tree_set_column_titles(GntTree *tree, ...)
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
1765 {
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
1766 int i;
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
1767 va_list args;
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
1768
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
1769 va_start(args, tree);
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
1770 for (i = 0; i < tree->ncol; i++)
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
1771 {
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
1772 const char *title = va_arg(args, const char *);
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
1773 tree->columns[i].title = g_strdup(title);
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
1774 }
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
1775 va_end(args);
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
1776 }
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
1777
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
1778 void gnt_tree_set_show_title(GntTree *tree, gboolean set)
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
1779 {
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
1780 tree->show_title = set;
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
1781 GNT_WIDGET(tree)->priv.minh = (set ? 6 : 4);
14033
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
1782 }
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14026
diff changeset
1783
14167
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1784 void gnt_tree_set_compare_func(GntTree *tree, GCompareFunc func)
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1785 {
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1786 tree->priv->compare = func;
14167
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1787 }
ca6027c33d2c [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14153
diff changeset
1788
14446
5f36f08183e8 [gaim-migrate @ 17090]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14441
diff changeset
1789 void gnt_tree_set_expanded(GntTree *tree, void *key, gboolean expanded)
5f36f08183e8 [gaim-migrate @ 17090]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14441
diff changeset
1790 {
5f36f08183e8 [gaim-migrate @ 17090]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14441
diff changeset
1791 GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
5f36f08183e8 [gaim-migrate @ 17090]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14441
diff changeset
1792 if (row) {
5f36f08183e8 [gaim-migrate @ 17090]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14441
diff changeset
1793 row->collapsed = !expanded;
5f36f08183e8 [gaim-migrate @ 17090]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14441
diff changeset
1794 if (GNT_WIDGET(tree)->window)
5f36f08183e8 [gaim-migrate @ 17090]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14441
diff changeset
1795 gnt_widget_draw(GNT_WIDGET(tree));
16264
03aaf9aae68b emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents: 16185
diff changeset
1796 g_signal_emit(tree, signals[SIG_COLLAPSED], 0, key, row->collapsed);
14446
5f36f08183e8 [gaim-migrate @ 17090]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14441
diff changeset
1797 }
5f36f08183e8 [gaim-migrate @ 17090]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14441
diff changeset
1798 }
14675
be8af28d1980 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14494
diff changeset
1799
be8af28d1980 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14494
diff changeset
1800 void gnt_tree_set_show_separator(GntTree *tree, gboolean set)
be8af28d1980 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14494
diff changeset
1801 {
be8af28d1980 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14494
diff changeset
1802 tree->show_separator = set;
be8af28d1980 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14494
diff changeset
1803 }
be8af28d1980 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14494
diff changeset
1804
14678
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1805 void gnt_tree_adjust_columns(GntTree *tree)
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1806 {
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1807 GntTreeRow *row = tree->root;
16185
b19597267ec1 We don't need to do anything about the heights here.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16165
diff changeset
1808 int *widths, i, twidth;
14678
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1809
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1810 widths = g_new0(int, tree->ncol);
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1811 while (row) {
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1812 GList *iter;
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1813 for (i = 0, iter = row->columns; iter; iter = iter->next, i++) {
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1814 GntTreeCol *col = iter->data;
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1815 int w = gnt_util_onscreen_width(col->text, NULL);
16027
931890920563 check-items are wider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15991
diff changeset
1816 if (i == 0 && row->choice)
931890920563 check-items are wider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15991
diff changeset
1817 w += 4;
16032
55ba12884571 Backspace to jump to parent.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16031
diff changeset
1818 if (i == 0) {
55ba12884571 Backspace to jump to parent.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16031
diff changeset
1819 w += find_depth(row) * TAB_SIZE;
55ba12884571 Backspace to jump to parent.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16031
diff changeset
1820 }
14678
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1821 if (widths[i] < w)
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1822 widths[i] = w;
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1823 }
16032
55ba12884571 Backspace to jump to parent.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16031
diff changeset
1824 row = get_next(row);
14678
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1825 }
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1826
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1827 twidth = 1 + 2 * (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER));
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1828 for (i = 0; i < tree->ncol; i++) {
18624
03d4eb6b6684 Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18598
diff changeset
1829 if (tree->columns[i].flags & GNT_TREE_COLUMN_FIXED_SIZE)
03d4eb6b6684 Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18598
diff changeset
1830 widths[i] = tree->columns[i].width;
14678
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1831 gnt_tree_set_col_width(tree, i, widths[i]);
18624
03d4eb6b6684 Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18598
diff changeset
1832 if (!COLUMN_INVISIBLE(tree, i)) {
03d4eb6b6684 Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18598
diff changeset
1833 twidth = twidth + widths[i];
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1834 if (tree->priv->lastvisible != i)
18624
03d4eb6b6684 Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18598
diff changeset
1835 twidth += 1;
03d4eb6b6684 Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18598
diff changeset
1836 }
14678
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1837 }
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1838 g_free(widths);
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1839
16185
b19597267ec1 We don't need to do anything about the heights here.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16165
diff changeset
1840 gnt_widget_set_size(GNT_WIDGET(tree), twidth, -1);
14678
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1841 }
97f57691faab [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14675
diff changeset
1842
15220
fc8b223f4b75 [gaim-migrate @ 17944]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15113
diff changeset
1843 void gnt_tree_set_hash_fns(GntTree *tree, gpointer hash, gpointer eq, gpointer kd)
fc8b223f4b75 [gaim-migrate @ 17944]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15113
diff changeset
1844 {
fc8b223f4b75 [gaim-migrate @ 17944]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15113
diff changeset
1845 g_hash_table_foreach_remove(tree->hash, return_true, NULL);
fc8b223f4b75 [gaim-migrate @ 17944]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15113
diff changeset
1846 g_hash_table_destroy(tree->hash);
fc8b223f4b75 [gaim-migrate @ 17944]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15113
diff changeset
1847 tree->hash = g_hash_table_new_full(hash, eq, kd, free_tree_row);
fc8b223f4b75 [gaim-migrate @ 17944]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15113
diff changeset
1848 }
fc8b223f4b75 [gaim-migrate @ 17944]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15113
diff changeset
1849
18558
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1850 static void
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1851 set_column_flag(GntTree *tree, int col, GntTreeColumnFlag flag, gboolean set)
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1852 {
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1853 if (set)
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1854 tree->columns[col].flags |= flag;
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1855 else
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1856 tree->columns[col].flags &= ~flag;
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1857 }
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1858
16030
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
1859 void gnt_tree_set_column_visible(GntTree *tree, int col, gboolean vis)
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
1860 {
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
1861 g_return_if_fail(col < tree->ncol);
18558
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1862 set_column_flag(tree, col, GNT_TREE_COLUMN_INVISIBLE, !vis);
18624
03d4eb6b6684 Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18598
diff changeset
1863 if (vis) {
03d4eb6b6684 Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18598
diff changeset
1864 /* the column is visible */
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1865 if (tree->priv->lastvisible < col)
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1866 tree->priv->lastvisible = col;
18624
03d4eb6b6684 Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18598
diff changeset
1867 } else {
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1868 if (tree->priv->lastvisible == col)
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1869 while (tree->priv->lastvisible) {
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1870 tree->priv->lastvisible--;
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1871 if (!COLUMN_INVISIBLE(tree, tree->priv->lastvisible))
18624
03d4eb6b6684 Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18598
diff changeset
1872 break;
03d4eb6b6684 Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18598
diff changeset
1873 }
03d4eb6b6684 Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18598
diff changeset
1874 }
21273
2f91b326b3f0 Minor adjustments to prevent a crash, correct a data type and fix drawing.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21263
diff changeset
1875 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_MAPPED))
2f91b326b3f0 Minor adjustments to prevent a crash, correct a data type and fix drawing.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21263
diff changeset
1876 readjust_columns(tree);
18558
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1877 }
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1878
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1879 void gnt_tree_set_column_resizable(GntTree *tree, int col, gboolean res)
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1880 {
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1881 g_return_if_fail(col < tree->ncol);
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1882 set_column_flag(tree, col, GNT_TREE_COLUMN_FIXED_SIZE, !res);
16030
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
1883 }
fb61f4100934 Allow making some columns invisible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16027
diff changeset
1884
18598
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
1885 void gnt_tree_set_column_is_binary(GntTree *tree, int col, gboolean bin)
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
1886 {
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
1887 g_return_if_fail(col < tree->ncol);
29342
c2e991047d2d Fix typo.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29265
diff changeset
1888 set_column_flag(tree, col, GNT_TREE_COLUMN_BINARY_DATA, bin);
18598
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
1889 }
946f9240fe5c Allow storing non-string binary data in tree columns.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18559
diff changeset
1890
18632
c7a3b70f0ae7 Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18624
diff changeset
1891 void gnt_tree_set_column_is_right_aligned(GntTree *tree, int col, gboolean right)
c7a3b70f0ae7 Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18624
diff changeset
1892 {
c7a3b70f0ae7 Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18624
diff changeset
1893 g_return_if_fail(col < tree->ncol);
c7a3b70f0ae7 Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18624
diff changeset
1894 set_column_flag(tree, col, GNT_TREE_COLUMN_RIGHT_ALIGNED, right);
c7a3b70f0ae7 Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18624
diff changeset
1895 }
c7a3b70f0ae7 Allow showing right-aligned text trees. Right-align the size in the file
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18624
diff changeset
1896
18558
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1897 void gnt_tree_set_column_width_ratio(GntTree *tree, int cols[])
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1898 {
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1899 int i;
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1900 for (i = 0; i < tree->ncol && cols[i]; i++) {
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1901 tree->columns[i].width_ratio = cols[i];
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1902 }
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1903 }
1a90a2b56443 Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18403
diff changeset
1904
18786
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1905 void gnt_tree_set_search_column(GntTree *tree, int col)
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1906 {
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1907 g_return_if_fail(col < tree->ncol);
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1908 g_return_if_fail(!BINARY_DATA(tree, col));
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1909 tree->priv->search_column = col;
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1910 }
87d4f1e609cb Allow setting the search column in a tree to use for typeahead searching.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18783
diff changeset
1911
18787
a96af97dc501 New feature: successful compilation.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18786
diff changeset
1912 gboolean gnt_tree_is_searching(GntTree *tree)
a96af97dc501 New feature: successful compilation.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18786
diff changeset
1913 {
a96af97dc501 New feature: successful compilation.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18786
diff changeset
1914 return (tree->priv->search != NULL);
a96af97dc501 New feature: successful compilation.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18786
diff changeset
1915 }
a96af97dc501 New feature: successful compilation.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18786
diff changeset
1916
18827
822e004cae0c Allow using custom search functions.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
1917 void gnt_tree_set_search_function(GntTree *tree,
18829
35138e0fbf77 Patch from Javeed Shaikh to make the search function non-braindamaged.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18827
diff changeset
1918 gboolean (*func)(GntTree *tree, gpointer key, const char *search, const char *current))
18827
822e004cae0c Allow using custom search functions.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
1919 {
822e004cae0c Allow using custom search functions.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
1920 tree->priv->search_func = func;
822e004cae0c Allow using custom search functions.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
1921 }
822e004cae0c Allow using custom search functions.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
1922
22284
1eaf3526de19 Function to get the parent key.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21804
diff changeset
1923 gpointer gnt_tree_get_parent_key(GntTree *tree, gpointer key)
1eaf3526de19 Function to get the parent key.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21804
diff changeset
1924 {
1eaf3526de19 Function to get the parent key.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21804
diff changeset
1925 GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
22301
75467c2623a0 This is supposed to return the key, not the row itself.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22284
diff changeset
1926 return (row && row->parent) ? row->parent->key : NULL;
22284
1eaf3526de19 Function to get the parent key.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21804
diff changeset
1927 }
1eaf3526de19 Function to get the parent key.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21804
diff changeset
1928
30499
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1929 gpointer gnt_tree_row_get_key(GntTree *tree, GntTreeRow *row)
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1930 {
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1931 g_return_val_if_fail(row && row->tree == tree, NULL);
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1932 return row->key;
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1933 }
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1934
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1935 GntTreeRow * gnt_tree_row_get_next(GntTree *tree, GntTreeRow *row)
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1936 {
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1937 g_return_val_if_fail(row && row->tree == tree, NULL);
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1938 return row->next;
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1939 }
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1940
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1941 GntTreeRow * gnt_tree_row_get_prev(GntTree *tree, GntTreeRow *row)
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1942 {
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1943 g_return_val_if_fail(row && row->tree == tree, NULL);
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1944 return row->prev;
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1945 }
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1946
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1947 GntTreeRow * gnt_tree_row_get_child(GntTree *tree, GntTreeRow *row)
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1948 {
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1949 g_return_val_if_fail(row && row->tree == tree, NULL);
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1950 return row->child;
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1951 }
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1952
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1953 GntTreeRow * gnt_tree_row_get_parent(GntTree *tree, GntTreeRow *row)
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1954 {
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1955 g_return_val_if_fail(row && row->tree == tree, NULL);
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1956 return row->parent;
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1957 }
19e9d4a69086 Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29377
diff changeset
1958

mercurial