annotate console/libgnt/gnttree.c @ 15418:16cd6fd20e6f

Prevent tree from crashing when NULL text is added in some column.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Fri, 26 Jan 2007 03:39:39 +0000
parents c6b79e535eb8
children feee34cfff5f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14836
bfcdd361357e [gaim-migrate @ 17605]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14824
diff changeset
1 #include "gntmarshal.h"
bfcdd361357e [gaim-migrate @ 17605]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14824
diff changeset
2 #include "gntstyle.h"
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
3 #include "gnttree.h"
14616
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
4 #include "gntutils.h"
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
5
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
6 #include <string.h>
14215
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
7 #include <ctype.h>
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
8
15160
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
9 #define SEARCH_TIMEOUT 4000 /* 4 secs */
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
10
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
11 enum
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
12 {
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
13 SIG_SELECTION_CHANGED,
13865
d78ab363e02d [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13864
diff changeset
14 SIG_SCROLLED,
13907
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
15 SIG_TOGGLED,
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
16 SIGS,
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
17 };
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
18
13858
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
19 #define TAB_SIZE 3
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
20
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
21 /* XXX: Make this one into a GObject?
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
22 * ... Probably not */
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
23 struct _GnTreeRow
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
24 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
25 void *key;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
26 void *data; /* XXX: unused */
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
27
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
28 gboolean collapsed;
13907
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
29 gboolean choice; /* Is this a choice-box?
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
30 If choice is true, then child will be NULL */
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
31 gboolean isselected;
13931
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
32 GntTextFormatFlags flags;
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
33
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
34 GntTreeRow *parent;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
35 GntTreeRow *child;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
36 GntTreeRow *next;
13857
d341b5ac1a78 [gaim-migrate @ 16316]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13856
diff changeset
37 GntTreeRow *prev;
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
38
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
39 GList *columns;
15160
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
40 GntTree *tree;
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
41 };
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
42
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
43 struct _GnTreeCol
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
44 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
45 char *text;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
46 int span; /* How many columns does it span? */
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
47 };
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
48
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
49 static GntWidgetClass *parent_class = NULL;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
50 static guint signals[SIGS] = { 0 };
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
51
14712
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
52 /* Move the item at position old to position new */
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
53 static GList *
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
54 g_list_reposition_child(GList *list, int old, int new)
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
55 {
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
56 gpointer item = g_list_nth_data(list, old);
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
57 list = g_list_remove(list, item);
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
58 if (old < new)
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
59 new--; /* because the positions would have shifted after removing the item */
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
60 list = g_list_insert(list, item, new);
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
61 return list;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
62 }
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
63
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
64 static GntTreeRow *
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
65 _get_next(GntTreeRow *row, gboolean godeep)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
66 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
67 if (row == NULL)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
68 return NULL;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
69 if (godeep && row->child)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
70 return row->child;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
71 if (row->next)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
72 return row->next;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
73 return _get_next(row->parent, FALSE);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
74 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
75
15160
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
76 static gboolean
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
77 row_matches_search(GntTreeRow *row)
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
78 {
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
79 GntTree *t = row->tree;
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
80 if (t->search && t->search->len > 0) {
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
81 char *one = g_utf8_casefold(((GntTreeCol*)row->columns->data)->text, -1);
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
82 char *two = g_utf8_casefold(t->search->str, -1);
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
83 char *z = strstr(one, two);
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
84 g_free(one);
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
85 g_free(two);
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
86 if (z == NULL)
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
87 return FALSE;
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
88 }
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
89 return TRUE;
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
90 }
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
91
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
92 static GntTreeRow *
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
93 get_next(GntTreeRow *row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
94 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
95 if (row == NULL)
13888
9d66969a2e32 [gaim-migrate @ 16369]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13882
diff changeset
96 return NULL;
15160
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
97 while ((row = _get_next(row, !row->collapsed)) != NULL) {
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
98 if (row_matches_search(row))
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
99 break;
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
100 }
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
101 return row;
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
102 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
103
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
104 /* Returns the n-th next row. If it doesn't exist, returns NULL */
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
105 static GntTreeRow *
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
106 get_next_n(GntTreeRow *row, int n)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
107 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
108 while (row && n--)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
109 row = get_next(row);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
110 return row;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
111 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
112
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
113 /* Returns the n-th next row. If it doesn't exist, then the last non-NULL node */
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
114 static GntTreeRow *
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
115 get_next_n_opt(GntTreeRow *row, int n, int *pos)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
116 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
117 GntTreeRow *next = row;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
118 int r = 0;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
119
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
120 if (row == NULL)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
121 return NULL;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
122
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
123 while (row && n--)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
124 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
125 row = get_next(row);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
126 if (row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
127 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
128 next = row;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
129 r++;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
130 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
131 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
132
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
133 if (pos)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
134 *pos = r;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
135
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
136 return next;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
137 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
138
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
139 static GntTreeRow *
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
140 get_last_child(GntTreeRow *row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
141 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
142 if (row == NULL)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
143 return NULL;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
144 if (!row->collapsed && row->child)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
145 row = row->child;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
146 else
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
147 return row;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
148
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
149 while(row->next)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
150 row = row->next;
14384
4a901f5d1312 [gaim-migrate @ 17090]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14379
diff changeset
151 if (!row->collapsed && row->child)
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
152 row = get_last_child(row->child);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
153 return row;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
154 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
155
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
156 static GntTreeRow *
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
157 get_prev(GntTreeRow *row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
158 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
159 if (row == NULL)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
160 return NULL;
15160
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
161 while (row) {
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
162 if (row->prev)
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
163 row = get_last_child(row->prev);
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
164 else
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
165 row = row->parent;
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
166 if (!row || row_matches_search(row))
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
167 break;
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
168 }
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
169 return row;
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
170 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
171
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
172 static GntTreeRow *
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
173 get_prev_n(GntTreeRow *row, int n)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
174 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
175 while (row && n--)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
176 row = get_prev(row);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
177 return row;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
178 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
179
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
180 /* Distance of row from the root */
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
181 /* XXX: This is uber-inefficient */
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
182 static int
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
183 get_root_distance(GntTreeRow *row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
184 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
185 if (row == NULL)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
186 return -1;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
187 return get_root_distance(get_prev(row)) + 1;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
188 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
189
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
190 /* Returns the distance between a and b.
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
191 * If a is 'above' b, then the distance is positive */
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
192 static int
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
193 get_distance(GntTreeRow *a, GntTreeRow *b)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
194 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
195 /* First get the distance from a to the root.
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
196 * Then the distance from b to the root.
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
197 * Subtract.
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
198 * It's not that good, but it works. */
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
199 int ha = get_root_distance(a);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
200 int hb = get_root_distance(b);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
201
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
202 return (hb - ha);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
203 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
204
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
205 static int
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
206 find_depth(GntTreeRow *row)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
207 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
208 int dep = -1;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
209
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
210 while (row)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
211 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
212 dep++;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
213 row = row->parent;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
214 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
215
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
216 return dep;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
217 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
218
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
219 static char *
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
220 update_row_text(GntTree *tree, GntTreeRow *row)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
221 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
222 GString *string = g_string_new(NULL);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
223 GList *iter;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
224 int i;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
225
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
226 for (i = 0, iter = row->columns; i < tree->ncol && iter; i++, iter = iter->next)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
227 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
228 GntTreeCol *col = iter->data;
14824
6ec7e963d186 [gaim-migrate @ 17591]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14823
diff changeset
229 const char *text;
6ec7e963d186 [gaim-migrate @ 17591]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14823
diff changeset
230 int len = gnt_util_onscreen_width(col->text, NULL);
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
231 int fl = 0;
14846
c7651586e27b [gaim-migrate @ 17615]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14843
diff changeset
232 gboolean cut = FALSE;
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
233
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
234 if (i == 0)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
235 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
236 if (row->choice)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
237 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
238 g_string_append_printf(string, "[%c] ",
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
239 row->isselected ? 'X' : ' ');
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
240 fl = 4;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
241 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
242 else if (row->parent == NULL && row->child)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
243 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
244 if (row->collapsed)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
245 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
246 string = g_string_append(string, "+ ");
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
247 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
248 else
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
249 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
250 string = g_string_append(string, "- ");
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
251 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
252 fl = 2;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
253 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
254 else
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
255 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
256 fl = TAB_SIZE * find_depth(row);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
257 g_string_append_printf(string, "%*s", fl, "");
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
258 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
259 len += fl;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
260 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
261 else
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
262 g_string_append_c(string, '|');
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
263
14846
c7651586e27b [gaim-migrate @ 17615]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14843
diff changeset
264 if (len > tree->columns[i].width) {
c7651586e27b [gaim-migrate @ 17615]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14843
diff changeset
265 len = tree->columns[i].width - 1;
c7651586e27b [gaim-migrate @ 17615]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14843
diff changeset
266 cut = TRUE;
c7651586e27b [gaim-migrate @ 17615]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14843
diff changeset
267 }
c7651586e27b [gaim-migrate @ 17615]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14843
diff changeset
268 text = gnt_util_onscreen_width_to_pointer(col->text, len - fl, NULL);
c7651586e27b [gaim-migrate @ 17615]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14843
diff changeset
269 string = g_string_append_len(string, col->text, text - col->text);
c7651586e27b [gaim-migrate @ 17615]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14843
diff changeset
270 if (cut) { /* ellipsis */
c7651586e27b [gaim-migrate @ 17615]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14843
diff changeset
271 if (gnt_ascii_only())
c7651586e27b [gaim-migrate @ 17615]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14843
diff changeset
272 g_string_append_c(string, '~');
c7651586e27b [gaim-migrate @ 17615]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14843
diff changeset
273 else
c7651586e27b [gaim-migrate @ 17615]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14843
diff changeset
274 string = g_string_append(string, "\342\200\246");
c7651586e27b [gaim-migrate @ 17615]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14843
diff changeset
275 len++;
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
276 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
277
14107
c0ee28af3ca2 [gaim-migrate @ 16741]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14105
diff changeset
278 if (len < tree->columns[i].width && iter->next)
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
279 g_string_append_printf(string, "%*s", tree->columns[i].width - len, "");
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
280 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
281 return g_string_free(string, FALSE);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
282 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
283
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
284 static void
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
285 tree_mark_columns(GntTree *tree, int pos, int y, chtype type)
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
286 {
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
287 GntWidget *widget = GNT_WIDGET(tree);
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
288 int i;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
289 int x = pos;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
290
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
291 for (i = 0; i < tree->ncol - 1; i++)
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
292 {
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
293 x += tree->columns[i].width;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
294 mvwaddch(widget->window, y, x + i, type);
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
295 }
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
296 }
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
297
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
298 static void
13853
bbf0470cb348 [gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13851
diff changeset
299 redraw_tree(GntTree *tree)
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
300 {
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
301 int start, i;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
302 GntWidget *widget = GNT_WIDGET(tree);
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
303 GntTreeRow *row;
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
304 int pos, up, down;
14131
db2311999862 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14126
diff changeset
305 int rows, scrcol;
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
306
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
307 if (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_MAPPED))
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
308 return;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
309
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
310 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER))
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
311 pos = 0;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
312 else
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
313 pos = 1;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
314
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
315 if (tree->top == NULL)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
316 tree->top = tree->root;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
317 if (tree->current == NULL)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
318 tree->current = tree->root;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
319
13854
a4c30c1d9de8 [gaim-migrate @ 16313]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13853
diff changeset
320 wbkgd(widget->window, COLOR_PAIR(GNT_COLOR_NORMAL));
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
321
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
322 start = 0;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
323 if (tree->show_title)
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
324 {
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
325 int i;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
326 int x = pos;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
327
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
328 mvwhline(widget->window, pos + 1, pos, ACS_HLINE | COLOR_PAIR(GNT_COLOR_NORMAL),
14126
b71bfeaaed58 [gaim-migrate @ 16764]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14123
diff changeset
329 widget->priv.width - pos - 1);
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
330
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
331 for (i = 0; i < tree->ncol; i++)
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
332 {
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
333 mvwprintw(widget->window, pos, x + i, tree->columns[i].title);
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
334 x += tree->columns[i].width;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
335 }
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
336 if (pos)
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
337 {
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
338 tree_mark_columns(tree, pos, 0, ACS_TTEE | COLOR_PAIR(GNT_COLOR_NORMAL));
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
339 tree_mark_columns(tree, pos, widget->priv.height - pos,
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
340 ACS_BTEE | COLOR_PAIR(GNT_COLOR_NORMAL));
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
341 }
14613
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
342 tree_mark_columns(tree, pos, pos + 1,
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
343 (tree->show_separator ? ACS_PLUS : ACS_HLINE) | COLOR_PAIR(GNT_COLOR_NORMAL));
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
344 tree_mark_columns(tree, pos, pos,
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
345 (tree->show_separator ? ACS_VLINE : ' ') | COLOR_PAIR(GNT_COLOR_NORMAL));
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
346 start = 2;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
347 }
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
348
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
349 rows = widget->priv.height - pos * 2 - start - 1;
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
350 tree->bottom = get_next_n_opt(tree->top, rows, &down);
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
351 if (down < rows)
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
352 {
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
353 tree->top = get_prev_n(tree->bottom, rows);
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
354 if (tree->top == NULL)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
355 tree->top = tree->root;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
356 }
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
357
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
358 up = get_distance(tree->top, tree->current);
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
359 if (up < 0)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
360 tree->top = tree->current;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
361 else if (up >= widget->priv.height - pos)
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
362 tree->top = get_prev_n(tree->current, rows);
14107
c0ee28af3ca2 [gaim-migrate @ 16741]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14105
diff changeset
363
15160
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
364 if (tree->top && !row_matches_search(tree->top))
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
365 tree->top = get_next(tree->top);
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
366 row = tree->top;
14824
6ec7e963d186 [gaim-migrate @ 17591]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14823
diff changeset
367 scrcol = widget->priv.width - 1 - 2 * pos; /* exclude the borders and the scrollbar */
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
368 for (i = start + pos; row && i < widget->priv.height - pos;
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
369 i++, row = get_next(row))
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
370 {
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
371 char *str;
13853
bbf0470cb348 [gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13851
diff changeset
372 int wr;
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
373
13931
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
374 GntTextFormatFlags flags = row->flags;
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
375 int attr = 0;
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
376
15160
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
377 if (!row_matches_search(row))
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
378 continue;
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
379 str = update_row_text(tree, row);
13936
669898e6aa11 [gaim-migrate @ 16467]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13935
diff changeset
380
14824
6ec7e963d186 [gaim-migrate @ 17591]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14823
diff changeset
381 if ((wr = gnt_util_onscreen_width(str, NULL)) > scrcol)
13851
41753203a94d [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13850
diff changeset
382 {
14824
6ec7e963d186 [gaim-migrate @ 17591]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14823
diff changeset
383 char *s = (char*)gnt_util_onscreen_width_to_pointer(str, scrcol, &wr);
13936
669898e6aa11 [gaim-migrate @ 16467]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13935
diff changeset
384 *s = '\0';
13851
41753203a94d [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13850
diff changeset
385 }
13931
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
386
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
387 if (flags & GNT_TEXT_FLAG_BOLD)
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
388 attr |= A_BOLD;
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
389 if (flags & GNT_TEXT_FLAG_UNDERLINE)
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
390 attr |= A_UNDERLINE;
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
391 if (flags & GNT_TEXT_FLAG_BLINK)
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
392 attr |= A_BLINK;
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
393
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
394 if (row == tree->current)
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
395 {
13896
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
396 if (gnt_widget_has_focus(widget))
13931
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
397 attr |= COLOR_PAIR(GNT_COLOR_HIGHLIGHT);
13882
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13878
diff changeset
398 else
13931
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
399 attr |= COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
400 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
401 else
13927
9309d27d780c [gaim-migrate @ 16447]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13907
diff changeset
402 {
13931
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
403 if (flags & GNT_TEXT_FLAG_DIM)
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
404 attr |= (A_DIM | COLOR_PAIR(GNT_COLOR_DISABLED));
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
405 else if (flags & GNT_TEXT_FLAG_HIGHLIGHT)
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
406 attr |= (A_DIM | COLOR_PAIR(GNT_COLOR_HIGHLIGHT));
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
407 else
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
408 attr |= COLOR_PAIR(GNT_COLOR_NORMAL);
13927
9309d27d780c [gaim-migrate @ 16447]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13907
diff changeset
409 }
13931
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
410
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
411 wbkgdset(widget->window, '\0' | attr);
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
412 mvwprintw(widget->window, i, pos, str);
14824
6ec7e963d186 [gaim-migrate @ 17591]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14823
diff changeset
413 whline(widget->window, ' ', scrcol - wr);
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
414 tree->bottom = row;
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
415 g_free(str);
14613
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
416 tree_mark_columns(tree, pos, i,
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
417 (tree->show_separator ? ACS_VLINE : ' ') | attr);
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
418 }
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
419
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
420 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL));
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
421 while (i < widget->priv.height - pos)
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
422 {
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
423 mvwhline(widget->window, i, pos, ' ',
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
424 widget->priv.width - pos * 2 - 1);
14613
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
425 tree_mark_columns(tree, pos, i,
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
426 (tree->show_separator ? ACS_VLINE : ' '));
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
427 i++;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
428 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
429
14824
6ec7e963d186 [gaim-migrate @ 17591]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14823
diff changeset
430 scrcol = widget->priv.width - pos - 1; /* position of the scrollbar */
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
431 rows--;
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
432 if (rows > 0)
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
433 {
14131
db2311999862 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14126
diff changeset
434 int total;
db2311999862 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14126
diff changeset
435 int showing, position;
db2311999862 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14126
diff changeset
436
db2311999862 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14126
diff changeset
437 get_next_n_opt(tree->root, g_list_length(tree->list), &total);
db2311999862 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14126
diff changeset
438 showing = rows * rows / MAX(total, 1) + 1;
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
439 showing = MIN(rows, showing);
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
440
14131
db2311999862 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14126
diff changeset
441 total -= rows;
db2311999862 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14126
diff changeset
442 up = get_distance(tree->root, tree->top);
db2311999862 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14126
diff changeset
443 down = total - up;
db2311999862 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14126
diff changeset
444
db2311999862 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14126
diff changeset
445 position = (rows - showing) * up / MAX(1, up + down);
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
446 position = MAX((tree->top != tree->root), position);
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
447
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
448 if (showing + position > rows)
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
449 position = rows - showing;
14107
c0ee28af3ca2 [gaim-migrate @ 16741]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14105
diff changeset
450
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
451 if (showing + position == rows && row)
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
452 position = MAX(0, rows - 1 - showing);
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
453 else if (showing + position < rows && !row)
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
454 position = rows - showing;
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
455
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
456 position += pos + start + 1;
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
457
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
458 mvwvline(widget->window, pos + start + 1, scrcol,
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
459 ' ' | COLOR_PAIR(GNT_COLOR_NORMAL), rows);
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
460 mvwvline(widget->window, position, scrcol,
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
461 ACS_CKBOARD | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D), showing);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
462 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
463
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
464 mvwaddch(widget->window, start + pos, scrcol,
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
465 ((tree->top != tree->root) ? ACS_UARROW : ' ') |
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
466 COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D));
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
467
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
468 mvwaddch(widget->window, widget->priv.height - pos - 1, scrcol,
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
469 (row ? ACS_DARROW : ' ') | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D));
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
470
13878
0d0ab1e39d0a [gaim-migrate @ 16355]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13865
diff changeset
471 gnt_widget_queue_update(widget);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
472 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
473
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
474 static void
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
475 gnt_tree_draw(GntWidget *widget)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
476 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
477 GntTree *tree = GNT_TREE(widget);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
478
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
479 redraw_tree(tree);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
480
14432
3ac156db9cb6 [gaim-migrate @ 17146]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14384
diff changeset
481 GNTDEBUG;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
482 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
483
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
484 static void
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
485 gnt_tree_size_request(GntWidget *widget)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
486 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
487 if (widget->priv.height == 0)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
488 widget->priv.height = 10; /* XXX: Why?! */
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
489 if (widget->priv.width == 0)
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
490 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
491 GntTree *tree = GNT_TREE(widget);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
492 int i, width = 0;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
493 for (i = 0; i < tree->ncol; i++)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
494 width += tree->columns[i].width;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
495 widget->priv.width = width + i;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
496 }
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
497 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
498
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
499 static void
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
500 gnt_tree_map(GntWidget *widget)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
501 {
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
502 GntTree *tree = GNT_TREE(widget);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
503 if (widget->priv.width == 0 || widget->priv.height == 0)
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
504 {
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
505 gnt_widget_size_request(widget);
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
506 }
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
507 tree->top = tree->root;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
508 tree->current = tree->root;
14432
3ac156db9cb6 [gaim-migrate @ 17146]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14384
diff changeset
509 GNTDEBUG;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
510 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
511
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
512 static void
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
513 tree_selection_changed(GntTree *tree, GntTreeRow *old, GntTreeRow *current)
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
514 {
14010
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13979
diff changeset
515 g_signal_emit(tree, signals[SIG_SELECTION_CHANGED], 0, old->key, current->key);
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
516 }
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
517
14793
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
518 static gboolean
14900
065e7ac30338 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14876
diff changeset
519 action_down(GntBindable *bind, GList *null)
14343
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
520 {
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
521 int dist;
14900
065e7ac30338 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14876
diff changeset
522 GntTree *tree = GNT_TREE(bind);
14793
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
523 GntTreeRow *old = tree->current;
14343
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
524 GntTreeRow *row = get_next(tree->current);
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
525 if (row == NULL)
14793
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
526 return FALSE;
14343
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
527 tree->current = row;
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
528 if ((dist = get_distance(tree->current, tree->bottom)) < 0)
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
529 gnt_tree_scroll(tree, -dist);
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
530 else
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
531 redraw_tree(tree);
14793
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
532 if (old != tree->current)
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
533 tree_selection_changed(tree, old, tree->current);
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
534 return TRUE;
14343
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
535 }
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
536
14793
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
537 static gboolean
14900
065e7ac30338 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14876
diff changeset
538 action_up(GntBindable *bind, GList *list)
14343
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
539 {
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
540 int dist;
14900
065e7ac30338 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14876
diff changeset
541 GntTree *tree = GNT_TREE(bind);
14793
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
542 GntTreeRow *old = tree->current;
14343
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
543 GntTreeRow *row = get_prev(tree->current);
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
544 if (!row)
14793
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
545 return FALSE;
14343
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
546 tree->current = row;
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
547 if ((dist = get_distance(tree->current, tree->top)) > 0)
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
548 gnt_tree_scroll(tree, -dist);
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
549 else
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
550 redraw_tree(tree);
14793
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
551 if (old != tree->current)
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
552 tree_selection_changed(tree, old, tree->current);
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
553
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
554 return TRUE;
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
555 }
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
556
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
557 static gboolean
14900
065e7ac30338 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14876
diff changeset
558 action_page_down(GntBindable *bind, GList *null)
14793
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
559 {
14900
065e7ac30338 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14876
diff changeset
560 GntTree *tree = GNT_TREE(bind);
14793
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
561 GntTreeRow *old = tree->current;
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
562 GntTreeRow *row = get_next(tree->bottom);
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
563 if (row)
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
564 {
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
565 int dist = get_distance(tree->top, tree->current);
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
566 tree->top = tree->bottom;
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
567 tree->current = get_next_n_opt(tree->top, dist, NULL);
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
568 redraw_tree(tree);
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
569 }
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
570 else if (tree->current != tree->bottom)
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
571 {
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
572 tree->current = tree->bottom;
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
573 redraw_tree(tree);
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
574 }
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
575
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
576 if (old != tree->current)
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
577 tree_selection_changed(tree, old, tree->current);
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
578 return TRUE;
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
579 }
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
580
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
581 static gboolean
14900
065e7ac30338 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14876
diff changeset
582 action_page_up(GntBindable *bind, GList *null)
14793
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
583 {
14900
065e7ac30338 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14876
diff changeset
584 GntWidget *widget = GNT_WIDGET(bind);
065e7ac30338 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14876
diff changeset
585 GntTree *tree = GNT_TREE(bind);
14793
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
586 GntTreeRow *row;
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
587 GntTreeRow *old = tree->current;
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
588
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
589 if (tree->top != tree->root)
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
590 {
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
591 int dist = get_distance(tree->top, tree->current);
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
592 row = get_prev_n(tree->top, widget->priv.height - 1 -
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
593 tree->show_title * 2 - 2 * (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER) == 0));
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
594 if (row == NULL)
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
595 row = tree->root;
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
596 tree->top = row;
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
597 tree->current = get_next_n_opt(tree->top, dist, NULL);
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
598 redraw_tree(tree);
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
599 }
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
600 else if (tree->current != tree->top)
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
601 {
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
602 tree->current = tree->top;
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
603 redraw_tree(tree);
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
604 }
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
605 if (old != tree->current)
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
606 tree_selection_changed(tree, old, tree->current);
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
607 return TRUE;
14343
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
608 }
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
609
15160
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
610 static void
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
611 end_search(GntTree *tree)
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
612 {
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
613 if (tree->search) {
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
614 g_source_remove(tree->search_timeout);
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
615 g_string_free(tree->search, TRUE);
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
616 tree->search = NULL;
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
617 tree->search_timeout = 0;
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
618 }
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
619 }
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
620
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
621 static gboolean
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
622 search_timeout(gpointer data)
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
623 {
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
624 GntTree *tree = data;
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
625
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
626 end_search(tree);
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
627 redraw_tree(tree);
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
628
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
629 return FALSE;
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
630 }
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
631
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
632 static gboolean
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
633 gnt_tree_key_pressed(GntWidget *widget, const char *text)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
634 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
635 GntTree *tree = GNT_TREE(widget);
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
636 GntTreeRow *old = tree->current;
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
637
15160
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
638 if (text[0] == '\r') {
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
639 end_search(tree);
14793
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
640 gnt_widget_activate(widget);
15160
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
641 } else if (tree->search) {
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
642 if (isalnum(*text)) {
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
643 tree->search = g_string_append_c(tree->search, *text);
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
644 redraw_tree(tree);
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
645 g_source_remove(tree->search_timeout);
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
646 tree->search_timeout = g_timeout_add(SEARCH_TIMEOUT, search_timeout, tree);
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
647 }
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
648 return TRUE;
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
649 } else if (text[0] == ' ' && text[1] == 0) {
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
650 /* Space pressed */
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
651 GntTreeRow *row = tree->current;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
652 if (row && row->child)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
653 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
654 row->collapsed = !row->collapsed;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
655 redraw_tree(tree);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
656 }
13907
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
657 else if (row && row->choice)
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
658 {
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
659 row->isselected = !row->isselected;
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
660 g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key);
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
661 redraw_tree(tree);
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
662 }
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
663 }
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
664
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
665 if (old != tree->current)
13907
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
666 {
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
667 tree_selection_changed(tree, old, tree->current);
13907
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
668 return TRUE;
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
669 }
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
670
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
671 return FALSE;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
672 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
673
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
674 static void
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
675 gnt_tree_destroy(GntWidget *widget)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
676 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
677 GntTree *tree = GNT_TREE(widget);
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
678 int i;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
679
15160
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
680 end_search(tree);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
681 g_hash_table_destroy(tree->hash);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
682 g_list_free(tree->list);
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
683
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
684 for (i = 0; i < tree->ncol; i++)
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
685 {
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
686 g_free(tree->columns[i].title);
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
687 }
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
688 g_free(tree->columns);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
689 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
690
14343
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
691 static gboolean
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
692 gnt_tree_clicked(GntWidget *widget, GntMouseEvent event, int x, int y)
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
693 {
14379
a7e29c0b51f4 [gaim-migrate @ 17085]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14351
diff changeset
694 GntTree *tree = GNT_TREE(widget);
a7e29c0b51f4 [gaim-migrate @ 17085]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14351
diff changeset
695 GntTreeRow *old = tree->current;
14343
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
696 if (event == GNT_MOUSE_SCROLL_UP) {
14900
065e7ac30338 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14876
diff changeset
697 action_up(GNT_BINDABLE(widget), NULL);
14343
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
698 } else if (event == GNT_MOUSE_SCROLL_DOWN) {
14900
065e7ac30338 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14876
diff changeset
699 action_down(GNT_BINDABLE(widget), NULL);
14343
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
700 } else if (event == GNT_LEFT_MOUSE_DOWN) {
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
701 GntTreeRow *row;
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
702 GntTree *tree = GNT_TREE(widget);
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
703 int pos = 1;
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
704 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER))
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
705 pos = 0;
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
706 if (tree->show_title)
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
707 pos += 2;
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
708 pos = y - widget->priv.y - pos;
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
709 row = get_next_n(tree->top, pos);
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
710 if (row && tree->current != row) {
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
711 GntTreeRow *old = tree->current;
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
712 tree->current = row;
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
713 redraw_tree(tree);
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
714 tree_selection_changed(tree, old, tree->current);
14351
1bd09d355f9e [gaim-migrate @ 17054]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
715 } else if (row && row == tree->current) {
1bd09d355f9e [gaim-migrate @ 17054]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
716 if (row->choice) {
1bd09d355f9e [gaim-migrate @ 17054]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
717 row->isselected = !row->isselected;
1bd09d355f9e [gaim-migrate @ 17054]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
718 g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key);
1bd09d355f9e [gaim-migrate @ 17054]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
719 redraw_tree(tree);
1bd09d355f9e [gaim-migrate @ 17054]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
720 } else {
1bd09d355f9e [gaim-migrate @ 17054]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
721 gnt_widget_activate(widget);
1bd09d355f9e [gaim-migrate @ 17054]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
722 }
14343
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
723 }
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
724 } else {
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
725 return FALSE;
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
726 }
14379
a7e29c0b51f4 [gaim-migrate @ 17085]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14351
diff changeset
727 if (old != tree->current) {
a7e29c0b51f4 [gaim-migrate @ 17085]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14351
diff changeset
728 tree_selection_changed(tree, old, tree->current);
a7e29c0b51f4 [gaim-migrate @ 17085]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14351
diff changeset
729 }
14343
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
730 return TRUE;
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
731 }
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
732
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
733 static void
15051
34e049e6ce10 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14977
diff changeset
734 gnt_tree_size_changed(GntWidget *widget, int w, int h)
34e049e6ce10 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14977
diff changeset
735 {
34e049e6ce10 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14977
diff changeset
736 GntTree *tree = GNT_TREE(widget);
34e049e6ce10 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14977
diff changeset
737 int i;
34e049e6ce10 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14977
diff changeset
738 int n = 0;
34e049e6ce10 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14977
diff changeset
739 if (widget->priv.width <= 0)
34e049e6ce10 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14977
diff changeset
740 return;
34e049e6ce10 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14977
diff changeset
741 for (i = 0; i < tree->ncol; ++i)
34e049e6ce10 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14977
diff changeset
742 n += tree->columns[i].width;
34e049e6ce10 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14977
diff changeset
743 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER))
34e049e6ce10 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14977
diff changeset
744 tree->columns[tree->ncol - 1].width += widget->priv.width - n - 1 * tree->ncol;
34e049e6ce10 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14977
diff changeset
745 else
34e049e6ce10 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14977
diff changeset
746 tree->columns[tree->ncol - 1].width += widget->priv.width - n - 2 - 1 * tree->ncol;
34e049e6ce10 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14977
diff changeset
747 }
34e049e6ce10 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14977
diff changeset
748
15160
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
749 static gboolean
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
750 start_search(GntBindable *bindable, GList *list)
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
751 {
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
752 GntTree *tree = GNT_TREE(bindable);
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
753 if (tree->search)
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
754 return FALSE;
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
755 tree->search = g_string_new(NULL);
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
756 tree->search_timeout = g_timeout_add(SEARCH_TIMEOUT, search_timeout, tree);
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
757 return TRUE;
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
758 }
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
759
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
760 static gboolean
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
761 end_search_action(GntBindable *bindable, GList *list)
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
762 {
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
763 GntTree *tree = GNT_TREE(bindable);
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
764 if (tree->search == NULL)
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
765 return FALSE;
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
766 end_search(tree);
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
767 redraw_tree(tree);
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
768 return TRUE;
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
769 }
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
770
15051
34e049e6ce10 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14977
diff changeset
771 static void
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
772 gnt_tree_class_init(GntTreeClass *klass)
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
773 {
14900
065e7ac30338 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14876
diff changeset
774 GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
775 parent_class = GNT_WIDGET_CLASS(klass);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
776 parent_class->destroy = gnt_tree_destroy;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
777 parent_class->draw = gnt_tree_draw;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
778 parent_class->map = gnt_tree_map;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
779 parent_class->size_request = gnt_tree_size_request;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
780 parent_class->key_pressed = gnt_tree_key_pressed;
14343
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14336
diff changeset
781 parent_class->clicked = gnt_tree_clicked;
15051
34e049e6ce10 [gaim-migrate @ 17835]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14977
diff changeset
782 parent_class->size_changed = gnt_tree_size_changed;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
783
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
784 signals[SIG_SELECTION_CHANGED] =
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
785 g_signal_new("selection-changed",
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
786 G_TYPE_FROM_CLASS(klass),
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
787 G_SIGNAL_RUN_LAST,
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
788 G_STRUCT_OFFSET(GntTreeClass, selection_changed),
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
789 NULL, NULL,
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
790 gnt_closure_marshal_VOID__POINTER_POINTER,
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
791 G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER);
13865
d78ab363e02d [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13864
diff changeset
792 signals[SIG_SCROLLED] =
d78ab363e02d [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13864
diff changeset
793 g_signal_new("scrolled",
d78ab363e02d [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13864
diff changeset
794 G_TYPE_FROM_CLASS(klass),
d78ab363e02d [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13864
diff changeset
795 G_SIGNAL_RUN_LAST,
d78ab363e02d [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13864
diff changeset
796 0,
d78ab363e02d [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13864
diff changeset
797 NULL, NULL,
d78ab363e02d [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13864
diff changeset
798 g_cclosure_marshal_VOID__INT,
d78ab363e02d [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13864
diff changeset
799 G_TYPE_NONE, 1, G_TYPE_INT);
13907
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
800 signals[SIG_TOGGLED] =
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
801 g_signal_new("toggled",
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
802 G_TYPE_FROM_CLASS(klass),
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
803 G_SIGNAL_RUN_LAST,
14843
97977138cf29 [gaim-migrate @ 17612]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14836
diff changeset
804 G_STRUCT_OFFSET(GntTreeClass, toggled),
13907
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
805 NULL, NULL,
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
806 g_cclosure_marshal_VOID__POINTER,
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
807 G_TYPE_NONE, 1, G_TYPE_POINTER);
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
808
14900
065e7ac30338 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14876
diff changeset
809 gnt_bindable_class_register_action(bindable, "move-up", action_up,
14876
70623f0d5cdc [gaim-migrate @ 17645]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14866
diff changeset
810 GNT_KEY_UP, NULL);
14900
065e7ac30338 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14876
diff changeset
811 gnt_bindable_register_binding(bindable, "move-up", GNT_KEY_CTRL_P, NULL);
065e7ac30338 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14876
diff changeset
812 gnt_bindable_class_register_action(bindable, "move-down", action_down,
14876
70623f0d5cdc [gaim-migrate @ 17645]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14866
diff changeset
813 GNT_KEY_DOWN, NULL);
14900
065e7ac30338 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14876
diff changeset
814 gnt_bindable_register_binding(bindable, "move-down", GNT_KEY_CTRL_N, NULL);
065e7ac30338 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14876
diff changeset
815 gnt_bindable_class_register_action(bindable, "page-up", action_page_up,
14876
70623f0d5cdc [gaim-migrate @ 17645]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14866
diff changeset
816 GNT_KEY_PGUP, NULL);
14900
065e7ac30338 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14876
diff changeset
817 gnt_bindable_class_register_action(bindable, "page-down", action_page_down,
14876
70623f0d5cdc [gaim-migrate @ 17645]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14866
diff changeset
818 GNT_KEY_PGDOWN, NULL);
15160
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
819 gnt_bindable_class_register_action(bindable, "start-search", start_search,
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
820 "/", NULL);
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
821 gnt_bindable_class_register_action(bindable, "end-search", end_search_action,
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
822 "\033", NULL);
14793
8a0cfee11af8 [gaim-migrate @ 17558]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14755
diff changeset
823
14900
065e7ac30338 [gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14876
diff changeset
824 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), bindable);
14432
3ac156db9cb6 [gaim-migrate @ 17146]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14384
diff changeset
825 GNTDEBUG;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
826 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
827
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
828 static void
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
829 gnt_tree_init(GTypeInstance *instance, gpointer class)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
830 {
13943
25be562aaca8 [gaim-migrate @ 16480]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13937
diff changeset
831 GntWidget *widget = GNT_WIDGET(instance);
14613
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
832 GntTree *tree = GNT_TREE(widget);
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
833 tree->show_separator = TRUE;
13943
25be562aaca8 [gaim-migrate @ 16480]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13937
diff changeset
834 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y);
25be562aaca8 [gaim-migrate @ 16480]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13937
diff changeset
835 widget->priv.minw = 4;
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
836 widget->priv.minh = 4;
14432
3ac156db9cb6 [gaim-migrate @ 17146]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14384
diff changeset
837 GNTDEBUG;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
838 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
839
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
840 /******************************************************************************
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
841 * GntTree API
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
842 *****************************************************************************/
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
843 GType
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
844 gnt_tree_get_gtype(void)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
845 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
846 static GType type = 0;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
847
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
848 if(type == 0)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
849 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
850 static const GTypeInfo info = {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
851 sizeof(GntTreeClass),
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
852 NULL, /* base_init */
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
853 NULL, /* base_finalize */
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
854 (GClassInitFunc)gnt_tree_class_init,
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
855 NULL, /* class_finalize */
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
856 NULL, /* class_data */
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
857 sizeof(GntTree),
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
858 0, /* n_preallocs */
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
859 gnt_tree_init, /* instance_init */
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
860 };
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
861
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
862 type = g_type_register_static(GNT_TYPE_WIDGET,
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
863 "GntTree",
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
864 &info, 0);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
865 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
866
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
867 return type;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
868 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
869
13858
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
870 static void
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
871 free_tree_col(gpointer data)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
872 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
873 GntTreeCol *col = data;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
874
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
875 g_free(col->text);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
876 g_free(col);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
877 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
878
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
879 static void
13858
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
880 free_tree_row(gpointer data)
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
881 {
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
882 GntTreeRow *row = data;
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
883
13861
55fb5cd9bac9 [gaim-migrate @ 16322]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13860
diff changeset
884 if (!row)
55fb5cd9bac9 [gaim-migrate @ 16322]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13860
diff changeset
885 return;
55fb5cd9bac9 [gaim-migrate @ 16322]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13860
diff changeset
886
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
887 g_list_foreach(row->columns, (GFunc)free_tree_col, NULL);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
888 g_list_free(row->columns);
13858
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
889 g_free(row);
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
890 }
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
891
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
892 GntWidget *gnt_tree_new()
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
893 {
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
894 return gnt_tree_new_with_columns(1);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
895 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
896
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
897 void gnt_tree_set_visible_rows(GntTree *tree, int rows)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
898 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
899 GntWidget *widget = GNT_WIDGET(tree);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
900 widget->priv.height = rows;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
901 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER))
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
902 widget->priv.height += 2;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
903 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
904
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
905 int gnt_tree_get_visible_rows(GntTree *tree)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
906 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
907 GntWidget *widget = GNT_WIDGET(tree);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
908 int ret = widget->priv.height;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
909 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER))
13888
9d66969a2e32 [gaim-migrate @ 16369]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13882
diff changeset
910 ret -= 2;
9d66969a2e32 [gaim-migrate @ 16369]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13882
diff changeset
911 return ret;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
912 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
913
14755
811464ba52de [gaim-migrate @ 17512]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14712
diff changeset
914 const GList *gnt_tree_get_rows(GntTree *tree)
811464ba52de [gaim-migrate @ 17512]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14712
diff changeset
915 {
811464ba52de [gaim-migrate @ 17512]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14712
diff changeset
916 return tree->list;
811464ba52de [gaim-migrate @ 17512]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14712
diff changeset
917 }
811464ba52de [gaim-migrate @ 17512]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14712
diff changeset
918
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
919 void gnt_tree_scroll(GntTree *tree, int count)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
920 {
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
921 GntTreeRow *row;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
922
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
923 if (count < 0)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
924 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
925 if (get_root_distance(tree->top) == 0)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
926 return;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
927 row = get_prev_n(tree->top, -count);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
928 if (row == NULL)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
929 row = tree->root;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
930 tree->top = row;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
931 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
932 else
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
933 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
934 get_next_n_opt(tree->bottom, count, &count);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
935 tree->top = get_next_n(tree->top, count);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
936 }
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
937
13853
bbf0470cb348 [gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13851
diff changeset
938 redraw_tree(tree);
13865
d78ab363e02d [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13864
diff changeset
939 g_signal_emit(tree, signals[SIG_SCROLLED], 0, count);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
940 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
941
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
942 static gpointer
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
943 find_position(GntTree *tree, gpointer key, gpointer parent)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
944 {
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
945 GntTreeRow *row;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
946
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
947 if (tree->compare == NULL)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
948 return NULL;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
949
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
950 if (parent == NULL)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
951 row = tree->root;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
952 else
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
953 row = g_hash_table_lookup(tree->hash, parent);
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
954
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
955 if (!row)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
956 return NULL;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
957
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
958 if (parent)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
959 row = row->child;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
960
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
961 while (row)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
962 {
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
963 if (tree->compare(key, row->key) < 0)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
964 return (row->prev ? row->prev->key : NULL);
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
965 if (row->next)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
966 row = row->next;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
967 else
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
968 return row->key;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
969 }
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
970 return NULL;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
971 }
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
972
14712
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
973 void gnt_tree_sort_row(GntTree *tree, gpointer key)
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
974 {
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
975 GntTreeRow *row, *q, *s;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
976 int current, newp;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
977
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
978 if (!tree->compare)
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
979 return;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
980
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
981 row = g_hash_table_lookup(tree->hash, key);
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
982 g_return_if_fail(row != NULL);
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
983
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
984 current = g_list_index(tree->list, key);
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
985
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
986 if (row->parent)
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
987 s = row->parent->child;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
988 else
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
989 s = tree->root;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
990
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
991 q = NULL;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
992 while (s) {
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
993 if (tree->compare(row->key, s->key) < 0)
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
994 break;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
995 q = s;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
996 s = s->next;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
997 }
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
998
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
999 /* Move row between q and s */
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1000 if (row == q || row == s)
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1001 return;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1002
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1003 if (q == NULL) {
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1004 /* row becomes the first child of its parent */
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1005 row->prev->next = row->next; /* row->prev cannot be NULL at this point */
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1006 if (row->next)
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1007 row->next->prev = row->prev;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1008 if (row->parent)
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1009 row->parent->child = row;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1010 else
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1011 tree->root = row;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1012 row->next = s;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1013 s->prev = row; /* s cannot be NULL */
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1014 row->prev = NULL;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1015 newp = g_list_index(tree->list, s) - 1;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1016 } else {
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1017 if (row->prev) {
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1018 row->prev->next = row->next;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1019 } else {
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1020 /* row was the first child of its parent */
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1021 if (row->parent)
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1022 row->parent->child = row->next;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1023 else
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1024 tree->top = row->next;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1025 }
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1026
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1027 if (row->next)
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1028 row->next->prev = row->prev;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1029
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1030 q->next = row;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1031 row->prev = q;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1032 if (s)
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1033 s->prev = row;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1034 row->next = s;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1035 newp = g_list_index(tree->list, q) + 1;
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1036 }
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1037 tree->list = g_list_reposition_child(tree->list, current, newp);
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1038
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1039 redraw_tree(tree);
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1040 }
b15c2eaeb67f [gaim-migrate @ 17466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14616
diff changeset
1041
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1042 GntTreeRow *gnt_tree_add_row_after(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro)
13858
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
1043 {
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1044 GntTreeRow *pr = NULL;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1045
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1046 g_hash_table_replace(tree->hash, key, row);
15160
c6b79e535eb8 [gaim-migrate @ 17946]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15158
diff changeset
1047 row->tree = tree;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1048
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1049 if (bigbro == NULL && tree->compare)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1050 {
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1051 bigbro = find_position(tree, key, parent);
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1052 }
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1053
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1054 if (tree->root == NULL)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1055 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1056 tree->root = row;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1057 tree->list = g_list_prepend(tree->list, key);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1058 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1059 else
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1060 {
13927
9309d27d780c [gaim-migrate @ 16447]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13907
diff changeset
1061 int position = 0;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1062
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1063 if (bigbro)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1064 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1065 pr = g_hash_table_lookup(tree->hash, bigbro);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1066 if (pr)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1067 {
13857
d341b5ac1a78 [gaim-migrate @ 16316]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13856
diff changeset
1068 if (pr->next) pr->next->prev = row;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1069 row->next = pr->next;
13857
d341b5ac1a78 [gaim-migrate @ 16316]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13856
diff changeset
1070 row->prev = pr;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1071 pr->next = row;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1072 row->parent = pr->parent;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1073
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1074 position = g_list_index(tree->list, bigbro);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1075 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1076 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1077
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1078 if (pr == NULL && parent)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1079 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1080 pr = g_hash_table_lookup(tree->hash, parent);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1081 if (pr)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1082 {
13857
d341b5ac1a78 [gaim-migrate @ 16316]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13856
diff changeset
1083 if (pr->child) pr->child->prev = row;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1084 row->next = pr->child;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1085 pr->child = row;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1086 row->parent = pr;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1087
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1088 position = g_list_index(tree->list, parent);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1089 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1090 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1091
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1092 if (pr == NULL)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1093 {
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1094 GntTreeRow *r = tree->root;
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1095 row->next = r;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1096 if (r) r->prev = row;
15158
68385f5bbd61 [gaim-migrate @ 17944]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15051
diff changeset
1097 if (tree->current == tree->root)
68385f5bbd61 [gaim-migrate @ 17944]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15051
diff changeset
1098 tree->current = row;
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1099 tree->root = row;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1100 tree->list = g_list_prepend(tree->list, key);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1101 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1102 else
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1103 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1104 tree->list = g_list_insert(tree->list, key, position + 1);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1105 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1106 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1107
13858
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
1108 row->key = key;
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
1109 row->data = NULL;
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
1110
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1111 redraw_tree(tree);
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
1112
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
1113 return row;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1114 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1115
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1116 GntTreeRow *gnt_tree_add_row_last(GntTree *tree, void *key, GntTreeRow *row, void *parent)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1117 {
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1118 GntTreeRow *pr = NULL, *br = NULL;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1119
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1120 if (parent)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1121 pr = g_hash_table_lookup(tree->hash, parent);
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1122
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1123 if (pr)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1124 br = pr->child;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1125 else
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1126 br = tree->root;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1127
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1128 if (br)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1129 {
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1130 while (br->next)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1131 br = br->next;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1132 }
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1133
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1134 return gnt_tree_add_row_after(tree, key, row, parent, br ? br->key : NULL);
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1135 }
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1136
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1137 gpointer gnt_tree_get_selection_data(GntTree *tree)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1138 {
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1139 if (tree->current)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1140 return tree->current->key; /* XXX: perhaps we should just get rid of 'data' */
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1141 return NULL;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1142 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1143
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1144 char *gnt_tree_get_selection_text(GntTree *tree)
13935
cd2da4b079cf [gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13934
diff changeset
1145 {
cd2da4b079cf [gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13934
diff changeset
1146 if (tree->current)
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1147 return update_row_text(tree, tree->current);
13935
cd2da4b079cf [gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13934
diff changeset
1148 return NULL;
cd2da4b079cf [gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13934
diff changeset
1149 }
cd2da4b079cf [gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13934
diff changeset
1150
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1151 GList *gnt_tree_get_selection_text_list(GntTree *tree)
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1152 {
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1153 GList *list = NULL, *iter;
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1154 int i;
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1155
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1156 if (!tree->current)
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1157 return NULL;
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1158
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1159 for (i = 0, iter = tree->current->columns; i < tree->ncol && iter;
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1160 i++, iter = iter->next)
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1161 {
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1162 GntTreeCol *col = iter->data;
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1163 list = g_list_append(list, g_strdup(col->text));
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1164 }
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1165
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1166 return list;
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1167 }
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1168
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1169 void gnt_tree_remove(GntTree *tree, gpointer key)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1170 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1171 GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1172 if (row)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1173 {
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1174 gboolean redraw = FALSE;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1175
14977
e601bc7880a6 [gaim-migrate @ 17756]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14900
diff changeset
1176 if (row->child) {
e601bc7880a6 [gaim-migrate @ 17756]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14900
diff changeset
1177 GntTreeRow *ch = row->child;
e601bc7880a6 [gaim-migrate @ 17756]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14900
diff changeset
1178 while (ch) {
e601bc7880a6 [gaim-migrate @ 17756]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14900
diff changeset
1179 GntTreeRow *n = ch->next;
e601bc7880a6 [gaim-migrate @ 17756]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14900
diff changeset
1180 tree->list = g_list_remove(tree->list, ch->key);
e601bc7880a6 [gaim-migrate @ 17756]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14900
diff changeset
1181 g_hash_table_remove(tree->hash, ch->key);
e601bc7880a6 [gaim-migrate @ 17756]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14900
diff changeset
1182 ch = n;
e601bc7880a6 [gaim-migrate @ 17756]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14900
diff changeset
1183 }
e601bc7880a6 [gaim-migrate @ 17756]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14900
diff changeset
1184 }
e601bc7880a6 [gaim-migrate @ 17756]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14900
diff changeset
1185
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1186 if (get_distance(tree->top, row) >= 0 && get_distance(row, tree->bottom) >= 0)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1187 redraw = TRUE;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1188
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1189 /* Update root/top/current/bottom if necessary */
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1190 if (tree->root == row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1191 tree->root = get_next(row);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1192 if (tree->top == row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1193 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1194 if (tree->top != tree->root)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1195 tree->top = get_prev(row);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1196 else
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1197 tree->top = get_next(row);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1198 if (tree->current == row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1199 tree->current = tree->top;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1200 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1201 else if (tree->current == row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1202 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1203 if (tree->current != tree->root)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1204 tree->current = get_prev(row);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1205 else
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1206 tree->current = get_next(row);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1207 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1208 else if (tree->bottom == row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1209 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1210 tree->bottom = get_prev(row);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1211 }
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1212
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1213 /* Fix the links */
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1214 if (row->next)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1215 row->next->prev = row->prev;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1216 if (row->parent && row->parent->child == row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1217 row->parent->child = row->next;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1218 if (row->prev)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1219 row->prev->next = row->next;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1220
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1221 g_hash_table_remove(tree->hash, key);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1222 tree->list = g_list_remove(tree->list, key);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1223
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1224 if (redraw)
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1225 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1226 redraw_tree(tree);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1227 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1228 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1229 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1230
14208
7d708210e317 [gaim-migrate @ 16883]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14131
diff changeset
1231 static gboolean
7d708210e317 [gaim-migrate @ 16883]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14131
diff changeset
1232 return_true(gpointer key, gpointer data, gpointer null)
7d708210e317 [gaim-migrate @ 16883]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14131
diff changeset
1233 {
7d708210e317 [gaim-migrate @ 16883]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14131
diff changeset
1234 return TRUE;
7d708210e317 [gaim-migrate @ 16883]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14131
diff changeset
1235 }
7d708210e317 [gaim-migrate @ 16883]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14131
diff changeset
1236
14091
ae4cbed1b309 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
1237 void gnt_tree_remove_all(GntTree *tree)
ae4cbed1b309 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
1238 {
ae4cbed1b309 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
1239 tree->root = NULL;
15158
68385f5bbd61 [gaim-migrate @ 17944]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15051
diff changeset
1240 g_hash_table_foreach_remove(tree->hash, (GHRFunc)return_true, tree);
14091
ae4cbed1b309 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
1241 g_list_free(tree->list);
ae4cbed1b309 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
1242 tree->list = NULL;
ae4cbed1b309 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
1243 tree->current = tree->top = tree->bottom = NULL;
ae4cbed1b309 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
1244 }
ae4cbed1b309 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
1245
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
1246 int gnt_tree_get_selection_visible_line(GntTree *tree)
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
1247 {
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1248 return get_distance(tree->top, tree->current) +
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
1249 !!(GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER));
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
1250 }
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
1251
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1252 void gnt_tree_change_text(GntTree *tree, gpointer key, int colno, const char *text)
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1253 {
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1254 GntTreeRow *row;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1255 GntTreeCol *col;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1256
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1257 g_return_if_fail(colno < tree->ncol);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1258
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1259 row = g_hash_table_lookup(tree->hash, key);
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1260 if (row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1261 {
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1262 col = g_list_nth_data(row->columns, colno);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1263 g_free(col->text);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1264 col->text = g_strdup(text);
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1265
14977
e601bc7880a6 [gaim-migrate @ 17756]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14900
diff changeset
1266 if (get_distance(tree->top, row) >= 0 && get_distance(row, tree->bottom) >= 0)
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1267 redraw_tree(tree);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1268 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1269 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
1270
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1271 GntTreeRow *gnt_tree_add_choice(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro)
13907
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1272 {
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1273 GntTreeRow *r;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1274 r = g_hash_table_lookup(tree->hash, key);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1275 g_return_val_if_fail(!r || !r->choice, NULL);
14336
f3ef96e8428f [gaim-migrate @ 17032]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14216
diff changeset
1276
f3ef96e8428f [gaim-migrate @ 17032]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14216
diff changeset
1277 if (bigbro == NULL) {
f3ef96e8428f [gaim-migrate @ 17032]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14216
diff changeset
1278 r = g_hash_table_lookup(tree->hash, parent);
f3ef96e8428f [gaim-migrate @ 17032]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14216
diff changeset
1279 if (!r)
f3ef96e8428f [gaim-migrate @ 17032]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14216
diff changeset
1280 r = tree->root;
f3ef96e8428f [gaim-migrate @ 17032]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14216
diff changeset
1281 else
f3ef96e8428f [gaim-migrate @ 17032]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14216
diff changeset
1282 r = r->child;
f3ef96e8428f [gaim-migrate @ 17032]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14216
diff changeset
1283 if (r) {
f3ef96e8428f [gaim-migrate @ 17032]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14216
diff changeset
1284 while (r->next)
f3ef96e8428f [gaim-migrate @ 17032]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14216
diff changeset
1285 r = r->next;
f3ef96e8428f [gaim-migrate @ 17032]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14216
diff changeset
1286 bigbro = r->key;
f3ef96e8428f [gaim-migrate @ 17032]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14216
diff changeset
1287 }
f3ef96e8428f [gaim-migrate @ 17032]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14216
diff changeset
1288 }
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1289 row = gnt_tree_add_row_after(tree, key, row, parent, bigbro);
13907
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1290 row->choice = TRUE;
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1291
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1292 return row;
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1293 }
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1294
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1295 void gnt_tree_set_choice(GntTree *tree, void *key, gboolean set)
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1296 {
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1297 GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1298
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1299 if (!row)
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1300 return;
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1301 g_return_if_fail(row->choice);
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1302
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1303 row->isselected = set;
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1304 redraw_tree(tree);
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1305 }
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1306
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1307 gboolean gnt_tree_get_choice(GntTree *tree, void *key)
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1308 {
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1309 GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1310
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1311 if (!row)
13927
9309d27d780c [gaim-migrate @ 16447]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13907
diff changeset
1312 return FALSE;
13907
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1313 g_return_val_if_fail(row->choice, FALSE);
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1314
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1315 return row->isselected;
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1316 }
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1317
13931
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
1318 void gnt_tree_set_row_flags(GntTree *tree, void *key, GntTextFormatFlags flags)
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
1319 {
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
1320 GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
13934
ef0d515b9f97 [gaim-migrate @ 16462]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13931
diff changeset
1321 if (!row || row->flags == flags)
13931
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
1322 return;
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
1323
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
1324 row->flags = flags;
13935
cd2da4b079cf [gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13934
diff changeset
1325 redraw_tree(tree); /* XXX: It shouldn't be necessary to redraw the whole darned tree */
13931
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
1326 }
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
1327
13952
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1328 void gnt_tree_set_selected(GntTree *tree , void *key)
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1329 {
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1330 int dist;
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1331 GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1332 if (!row)
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1333 return;
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1334
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1335 if (tree->top == NULL)
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1336 tree->top = row;
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1337 if (tree->bottom == NULL)
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1338 tree->bottom = row;
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1339
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1340 tree->current = row;
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1341 if ((dist = get_distance(tree->current, tree->bottom)) < 0)
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1342 gnt_tree_scroll(tree, -dist);
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1343 else if ((dist = get_distance(tree->current, tree->top)) > 0)
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1344 gnt_tree_scroll(tree, -dist);
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1345 else
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1346 redraw_tree(tree);
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1347 }
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1348
14613
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
1349 void _gnt_tree_init_internals(GntTree *tree, int col)
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1350 {
14613
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
1351 tree->ncol = col;
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1352 tree->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_tree_row);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1353 tree->columns = g_new0(struct _GntTreeColInfo, col);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1354 while (col--)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1355 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1356 tree->columns[col].width = 15;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1357 }
14616
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1358 tree->list = NULL;
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1359 tree->show_title = FALSE;
14613
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
1360 }
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
1361
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
1362 GntWidget *gnt_tree_new_with_columns(int col)
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
1363 {
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
1364 GntWidget *widget = g_object_new(GNT_TYPE_TREE, NULL);
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
1365 GntTree *tree = GNT_TREE(widget);
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
1366
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
1367 _gnt_tree_init_internals(tree, col);
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1368
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1369 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1370 gnt_widget_set_take_focus(widget, TRUE);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1371
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1372 return widget;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1373 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1374
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1375 GntTreeRow *gnt_tree_create_row_from_list(GntTree *tree, GList *list)
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1376 {
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1377 GList *iter;
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1378 int i;
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1379 GntTreeRow *row = g_new0(GntTreeRow, 1);
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1380
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1381 for (i = 0, iter = list; i < tree->ncol && iter; iter = iter->next, i++)
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1382 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1383 GntTreeCol *col = g_new0(GntTreeCol, 1);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1384 col->span = 1;
15418
16cd6fd20e6f Prevent tree from crashing when NULL text is added in some column.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15160
diff changeset
1385 col->text = g_strdup(iter->data ? iter->data : "");
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1386
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1387 row->columns = g_list_append(row->columns, col);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1388 }
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1389
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1390 return row;
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1391 }
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1392
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1393 GntTreeRow *gnt_tree_create_row(GntTree *tree, ...)
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1394 {
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1395 int i;
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1396 va_list args;
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1397 GList *list = NULL;
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1398 GntTreeRow *row;
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1399
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1400 va_start(args, tree);
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1401 for (i = 0; i < tree->ncol; i++)
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1402 {
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
1403 list = g_list_append(list, va_arg(args, char *));
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1404 }
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1405 va_end(args);
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1406
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1407 row = gnt_tree_create_row_from_list(tree, list);
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1408 g_list_free(list);
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1409
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1410 return row;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1411 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1412
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1413 void gnt_tree_set_col_width(GntTree *tree, int col, int width)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1414 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1415 g_return_if_fail(col < tree->ncol);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1416
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1417 tree->columns[col].width = width;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1418 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1419
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1420 void gnt_tree_set_column_titles(GntTree *tree, ...)
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1421 {
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1422 int i;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1423 va_list args;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1424
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1425 va_start(args, tree);
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1426 for (i = 0; i < tree->ncol; i++)
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1427 {
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1428 const char *title = va_arg(args, const char *);
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1429 tree->columns[i].title = g_strdup(title);
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1430 }
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1431 va_end(args);
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1432 }
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1433
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1434 void gnt_tree_set_show_title(GntTree *tree, gboolean set)
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1435 {
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1436 tree->show_title = set;
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
1437 GNT_WIDGET(tree)->priv.minh = (set ? 6 : 4);
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1438 }
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1439
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1440 void gnt_tree_set_compare_func(GntTree *tree, GCompareFunc func)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1441 {
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1442 tree->compare = func;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1443 }
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1444
14384
4a901f5d1312 [gaim-migrate @ 17090]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14379
diff changeset
1445 void gnt_tree_set_expanded(GntTree *tree, void *key, gboolean expanded)
4a901f5d1312 [gaim-migrate @ 17090]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14379
diff changeset
1446 {
4a901f5d1312 [gaim-migrate @ 17090]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14379
diff changeset
1447 GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
4a901f5d1312 [gaim-migrate @ 17090]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14379
diff changeset
1448 if (row) {
4a901f5d1312 [gaim-migrate @ 17090]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14379
diff changeset
1449 row->collapsed = !expanded;
4a901f5d1312 [gaim-migrate @ 17090]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14379
diff changeset
1450 if (GNT_WIDGET(tree)->window)
4a901f5d1312 [gaim-migrate @ 17090]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14379
diff changeset
1451 gnt_widget_draw(GNT_WIDGET(tree));
4a901f5d1312 [gaim-migrate @ 17090]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14379
diff changeset
1452 }
4a901f5d1312 [gaim-migrate @ 17090]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14379
diff changeset
1453 }
14613
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
1454
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
1455 void gnt_tree_set_show_separator(GntTree *tree, gboolean set)
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
1456 {
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
1457 tree->show_separator = set;
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
1458 }
62bb53609a36 [gaim-migrate @ 17341]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14432
diff changeset
1459
14616
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1460 void gnt_tree_adjust_columns(GntTree *tree)
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1461 {
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1462 GntTreeRow *row = tree->root;
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1463 int *widths, i, twidth, height;
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1464
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1465 widths = g_new0(int, tree->ncol);
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1466 while (row) {
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1467 GList *iter;
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1468 for (i = 0, iter = row->columns; iter; iter = iter->next, i++) {
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1469 GntTreeCol *col = iter->data;
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1470 int w = gnt_util_onscreen_width(col->text, NULL);
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1471 if (widths[i] < w)
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1472 widths[i] = w;
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1473 }
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1474 row = row->next;
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1475 }
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1476
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1477 twidth = 1 + 2 * (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER));
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1478 for (i = 0; i < tree->ncol; i++) {
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1479 gnt_tree_set_col_width(tree, i, widths[i]);
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1480 twidth += widths[i] + (tree->show_separator ? 1 : 0) + 1;
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1481 }
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1482 g_free(widths);
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1483
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1484 gnt_widget_get_size(GNT_WIDGET(tree), NULL, &height);
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1485 gnt_widget_set_size(GNT_WIDGET(tree), twidth, height);
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1486 }
f1f1dcb26d89 [gaim-migrate @ 17344]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14613
diff changeset
1487
15158
68385f5bbd61 [gaim-migrate @ 17944]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15051
diff changeset
1488 void gnt_tree_set_hash_fns(GntTree *tree, gpointer hash, gpointer eq, gpointer kd)
68385f5bbd61 [gaim-migrate @ 17944]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15051
diff changeset
1489 {
68385f5bbd61 [gaim-migrate @ 17944]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15051
diff changeset
1490 g_hash_table_foreach_remove(tree->hash, return_true, NULL);
68385f5bbd61 [gaim-migrate @ 17944]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15051
diff changeset
1491 g_hash_table_destroy(tree->hash);
68385f5bbd61 [gaim-migrate @ 17944]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15051
diff changeset
1492 tree->hash = g_hash_table_new_full(hash, eq, kd, free_tree_row);
68385f5bbd61 [gaim-migrate @ 17944]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15051
diff changeset
1493 }
68385f5bbd61 [gaim-migrate @ 17944]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15051
diff changeset
1494