annotate finch/libgnt/gnttree.c @ 21696:fded60f269bc

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