annotate console/libgnt/gnttree.c @ 15101:ded621e635e4

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