annotate console/libgnt/gnttree.c @ 14303:d9aa45c10588

[gaim-migrate @ 16993] Patch from wabz (Richard Nelson): Do not crash when there are too many popups. Move the new ones to a different column instead. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 23 Aug 2006 04:22:04 +0000
parents e9dd2f76e61b
children f3ef96e8428f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1 #include "gnttree.h"
13935
cd2da4b079cf [gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13934
diff changeset
2 #include "gntmarshal.h"
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
3
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
4 #include <string.h>
14215
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
5 #include <ctype.h>
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
6
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
7 enum
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
8 {
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
9 SIG_SELECTION_CHANGED,
13865
d78ab363e02d [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13864
diff changeset
10 SIG_SCROLLED,
13907
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
11 SIG_TOGGLED,
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
12 SIGS,
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
13 };
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
14
13858
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
15 #define TAB_SIZE 3
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
16
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
17 /* XXX: Make this one into a GObject?
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
18 * ... Probably not */
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
19 struct _GnTreeRow
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
20 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
21 void *key;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
22 void *data; /* XXX: unused */
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
23
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
24 gboolean collapsed;
13907
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
25 gboolean choice; /* Is this a choice-box?
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
26 If choice is true, then child will be NULL */
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
27 gboolean isselected;
13931
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
28 GntTextFormatFlags flags;
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
29
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
30 GntTreeRow *parent;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
31 GntTreeRow *child;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
32 GntTreeRow *next;
13857
d341b5ac1a78 [gaim-migrate @ 16316]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13856
diff changeset
33 GntTreeRow *prev;
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
34
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
35 GList *columns;
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
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
38 struct _GnTreeCol
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 char *text;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
41 int span; /* How many columns does it span? */
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
42 };
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
43
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
44 static GntWidgetClass *parent_class = NULL;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
45 static guint signals[SIGS] = { 0 };
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
46
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
47 static GntTreeRow *
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
48 _get_next(GntTreeRow *row, gboolean godeep)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
49 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
50 if (row == NULL)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
51 return NULL;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
52 if (godeep && row->child)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
53 return row->child;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
54 if (row->next)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
55 return row->next;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
56 return _get_next(row->parent, FALSE);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
57 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
58
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
59 static GntTreeRow *
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
60 get_next(GntTreeRow *row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
61 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
62 if (row == NULL)
13888
9d66969a2e32 [gaim-migrate @ 16369]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13882
diff changeset
63 return NULL;
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
64 return _get_next(row, !row->collapsed);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
65 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
66
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
67 /* 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
68 static GntTreeRow *
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
69 get_next_n(GntTreeRow *row, int n)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
70 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
71 while (row && n--)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
72 row = get_next(row);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
73 return row;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
74 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
75
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
76 /* 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
77 static GntTreeRow *
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
78 get_next_n_opt(GntTreeRow *row, int n, int *pos)
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 GntTreeRow *next = row;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
81 int r = 0;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
82
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
83 if (row == NULL)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
84 return NULL;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
85
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
86 while (row && n--)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
87 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
88 row = get_next(row);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
89 if (row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
90 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
91 next = row;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
92 r++;
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 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
95
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
96 if (pos)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
97 *pos = r;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
98
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
99 return next;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
100 }
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 static GntTreeRow *
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
103 get_last_child(GntTreeRow *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 if (row == NULL)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
106 return NULL;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
107 if (!row->collapsed && row->child)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
108 row = row->child;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
109 else
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
110 return row;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
111
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
112 while(row->next)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
113 row = row->next;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
114 if (row->child)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
115 row = get_last_child(row->child);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
116 return row;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
117 }
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 static GntTreeRow *
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
120 get_prev(GntTreeRow *row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
121 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
122 if (row == NULL)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
123 return NULL;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
124 if (row->prev)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
125 return get_last_child(row->prev);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
126 return row->parent;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
127 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
128
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
129 static GntTreeRow *
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
130 get_prev_n(GntTreeRow *row, int n)
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 while (row && n--)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
133 row = get_prev(row);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
134 return 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
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
137 /* Distance of row from the root */
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
138 /* XXX: This is uber-inefficient */
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
139 static int
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
140 get_root_distance(GntTreeRow *row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
141 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
142 if (row == NULL)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
143 return -1;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
144 return get_root_distance(get_prev(row)) + 1;
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
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
147 /* Returns the distance between a and b.
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
148 * If a is 'above' b, then the distance is positive */
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
149 static int
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
150 get_distance(GntTreeRow *a, GntTreeRow *b)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
151 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
152 /* First get the distance from a to the root.
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
153 * Then the distance from b to the root.
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
154 * Subtract.
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
155 * It's not that good, but it works. */
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
156 int ha = get_root_distance(a);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
157 int hb = get_root_distance(b);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
158
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
159 return (hb - ha);
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
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
162 static int
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
163 find_depth(GntTreeRow *row)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
164 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
165 int dep = -1;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
166
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
167 while (row)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
168 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
169 dep++;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
170 row = row->parent;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
171 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
172
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
173 return dep;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
174 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
175
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
176 static char *
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
177 update_row_text(GntTree *tree, 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 GString *string = g_string_new(NULL);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
180 GList *iter;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
181 int i;
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 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
184 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
185 GntTreeCol *col = iter->data;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
186 char *text;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
187 int len = g_utf8_strlen(col->text, -1);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
188 int fl = 0;
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 if (i == 0)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
191 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
192 if (row->choice)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
193 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
194 g_string_append_printf(string, "[%c] ",
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
195 row->isselected ? 'X' : ' ');
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
196 fl = 4;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
197 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
198 else if (row->parent == NULL && row->child)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
199 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
200 if (row->collapsed)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
201 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
202 string = g_string_append(string, "+ ");
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
203 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
204 else
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
205 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
206 string = g_string_append(string, "- ");
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
207 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
208 fl = 2;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
209 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
210 else
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
211 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
212 fl = TAB_SIZE * find_depth(row);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
213 g_string_append_printf(string, "%*s", fl, "");
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 len += fl;
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 else
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
218 g_string_append_c(string, '|');
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
219
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
220 if (len > tree->columns[i].width)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
221 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
222 len = tree->columns[i].width;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
223 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
224
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
225 text = g_utf8_offset_to_pointer(col->text, len - fl);
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
226 string = g_string_append_len(string, col->text, text - col->text);
14107
c0ee28af3ca2 [gaim-migrate @ 16741]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14105
diff changeset
227 if (len < tree->columns[i].width && iter->next)
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
228 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
229 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
230 return g_string_free(string, FALSE);
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
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
233 static void
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
234 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
235 {
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
236 GntWidget *widget = GNT_WIDGET(tree);
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
237 int i;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
238 int x = pos;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
239
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
240 for (i = 0; i < tree->ncol - 1; i++)
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
241 {
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
242 x += tree->columns[i].width;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
243 mvwaddch(widget->window, y, x + i, type);
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
244 }
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
245 }
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
246
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
247 static void
13853
bbf0470cb348 [gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13851
diff changeset
248 redraw_tree(GntTree *tree)
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
249 {
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
250 int start, i;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
251 GntWidget *widget = GNT_WIDGET(tree);
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
252 GntTreeRow *row;
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
253 int pos, up, down;
14131
db2311999862 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14126
diff changeset
254 int rows, scrcol;
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
255
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
256 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
257 return;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
258
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
259 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER))
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
260 pos = 0;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
261 else
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
262 pos = 1;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
263
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
264 if (tree->top == NULL)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
265 tree->top = tree->root;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
266 if (tree->current == NULL)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
267 tree->current = tree->root;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
268
13854
a4c30c1d9de8 [gaim-migrate @ 16313]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13853
diff changeset
269 wbkgd(widget->window, COLOR_PAIR(GNT_COLOR_NORMAL));
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
270
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
271 start = 0;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
272 if (tree->show_title)
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
273 {
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
274 int i;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
275 int x = pos;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
276
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
277 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
278 widget->priv.width - pos - 1);
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
279
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
280 for (i = 0; i < tree->ncol; i++)
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
281 {
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
282 mvwprintw(widget->window, pos, x + i, tree->columns[i].title);
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
283 x += tree->columns[i].width;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
284 }
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
285 if (pos)
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
286 {
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
287 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
288 tree_mark_columns(tree, pos, widget->priv.height - pos,
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
289 ACS_BTEE | COLOR_PAIR(GNT_COLOR_NORMAL));
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
290 }
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
291 tree_mark_columns(tree, pos, pos + 1, ACS_PLUS | COLOR_PAIR(GNT_COLOR_NORMAL));
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
292 tree_mark_columns(tree, pos, pos, ACS_VLINE | COLOR_PAIR(GNT_COLOR_NORMAL));
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
293 start = 2;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
294 }
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
295
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
296 rows = widget->priv.height - pos * 2 - start - 1;
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
297 tree->bottom = get_next_n_opt(tree->top, rows, &down);
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
298 if (down < rows)
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
299 {
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
300 tree->top = get_prev_n(tree->bottom, rows);
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
301 if (tree->top == NULL)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
302 tree->top = tree->root;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
303 }
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
304
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
305 up = get_distance(tree->top, tree->current);
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
306 if (up < 0)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
307 tree->top = tree->current;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
308 else if (up >= widget->priv.height - pos)
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
309 tree->top = get_prev_n(tree->current, rows);
14107
c0ee28af3ca2 [gaim-migrate @ 16741]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14105
diff changeset
310
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
311 row = tree->top;
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
312 for (i = start + pos; row && i < widget->priv.height - pos;
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
313 i++, row = get_next(row))
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
314 {
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
315 char *str;
13853
bbf0470cb348 [gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13851
diff changeset
316 int wr;
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
317
13931
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
318 GntTextFormatFlags flags = row->flags;
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
319 int attr = 0;
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
320
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
321 str = update_row_text(tree, row);
13936
669898e6aa11 [gaim-migrate @ 16467]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13935
diff changeset
322
669898e6aa11 [gaim-migrate @ 16467]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13935
diff changeset
323 if ((wr = g_utf8_strlen(str, -1)) >= widget->priv.width - 1 - pos)
13851
41753203a94d [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13850
diff changeset
324 {
41753203a94d [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13850
diff changeset
325 /* XXX: ellipsize */
13936
669898e6aa11 [gaim-migrate @ 16467]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13935
diff changeset
326 char *s = g_utf8_offset_to_pointer(str, widget->priv.width - 1 - pos);
669898e6aa11 [gaim-migrate @ 16467]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13935
diff changeset
327 *s = '\0';
13851
41753203a94d [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13850
diff changeset
328 }
13931
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
329
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
330 if (flags & GNT_TEXT_FLAG_BOLD)
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
331 attr |= A_BOLD;
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
332 if (flags & GNT_TEXT_FLAG_UNDERLINE)
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
333 attr |= A_UNDERLINE;
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
334 if (flags & GNT_TEXT_FLAG_BLINK)
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
335 attr |= A_BLINK;
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
336
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
337 if (row == tree->current)
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
338 {
13896
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
339 if (gnt_widget_has_focus(widget))
13931
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
340 attr |= COLOR_PAIR(GNT_COLOR_HIGHLIGHT);
13882
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13878
diff changeset
341 else
13931
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
342 attr |= COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
343 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
344 else
13927
9309d27d780c [gaim-migrate @ 16447]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13907
diff changeset
345 {
13931
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
346 if (flags & GNT_TEXT_FLAG_DIM)
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
347 attr |= (A_DIM | COLOR_PAIR(GNT_COLOR_DISABLED));
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
348 else if (flags & GNT_TEXT_FLAG_HIGHLIGHT)
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
349 attr |= (A_DIM | COLOR_PAIR(GNT_COLOR_HIGHLIGHT));
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
350 else
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
351 attr |= COLOR_PAIR(GNT_COLOR_NORMAL);
13927
9309d27d780c [gaim-migrate @ 16447]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13907
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 wbkgdset(widget->window, '\0' | attr);
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
355 mvwprintw(widget->window, i, pos, str);
14107
c0ee28af3ca2 [gaim-migrate @ 16741]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14105
diff changeset
356 whline(widget->window, ' ', widget->priv.width - pos * 2 - g_utf8_strlen(str, -1) - 1);
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
357 tree->bottom = row;
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
358 g_free(str);
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
359 tree_mark_columns(tree, pos, i, ACS_VLINE | attr);
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
360 }
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
361
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
362 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL));
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
363 while (i < widget->priv.height - pos)
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
364 {
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
365 mvwhline(widget->window, i, pos, ' ',
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
366 widget->priv.width - pos * 2 - 1);
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
367 tree_mark_columns(tree, pos, i, ACS_VLINE);
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
368 i++;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
369 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
370
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
371 scrcol = widget->priv.width - pos - 1;
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
372 rows--;
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
373 if (rows > 0)
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
374 {
14131
db2311999862 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14126
diff changeset
375 int total;
db2311999862 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14126
diff changeset
376 int showing, position;
db2311999862 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14126
diff changeset
377
db2311999862 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14126
diff changeset
378 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
379 showing = rows * rows / MAX(total, 1) + 1;
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
380 showing = MIN(rows, showing);
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
381
14131
db2311999862 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14126
diff changeset
382 total -= rows;
db2311999862 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14126
diff changeset
383 up = get_distance(tree->root, tree->top);
db2311999862 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14126
diff changeset
384 down = total - up;
db2311999862 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14126
diff changeset
385
db2311999862 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14126
diff changeset
386 position = (rows - showing) * up / MAX(1, up + down);
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
387 position = MAX((tree->top != tree->root), position);
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
388
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
389 if (showing + position > rows)
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
390 position = rows - showing;
14107
c0ee28af3ca2 [gaim-migrate @ 16741]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14105
diff changeset
391
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
392 if (showing + position == rows && row)
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
393 position = MAX(0, rows - 1 - showing);
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
394 else if (showing + position < rows && !row)
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
395 position = rows - showing;
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
396
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
397 position += pos + start + 1;
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
398
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
399 mvwvline(widget->window, pos + start + 1, scrcol,
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
400 ' ' | COLOR_PAIR(GNT_COLOR_NORMAL), rows);
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
401 mvwvline(widget->window, position, scrcol,
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
402 ACS_CKBOARD | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D), showing);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
403 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
404
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
405 mvwaddch(widget->window, start + pos, scrcol,
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
406 ((tree->top != tree->root) ? ACS_UARROW : ' ') |
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
407 COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D));
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
408
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
409 mvwaddch(widget->window, widget->priv.height - pos - 1, scrcol,
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
410 (row ? ACS_DARROW : ' ') | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D));
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
411
13878
0d0ab1e39d0a [gaim-migrate @ 16355]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13865
diff changeset
412 gnt_widget_queue_update(widget);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
413 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
414
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
415 static void
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
416 gnt_tree_draw(GntWidget *widget)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
417 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
418 GntTree *tree = GNT_TREE(widget);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
419
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
420 redraw_tree(tree);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
421
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
422 DEBUG;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
423 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
424
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
425 static void
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
426 gnt_tree_size_request(GntWidget *widget)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
427 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
428 if (widget->priv.height == 0)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
429 widget->priv.height = 10; /* XXX: Why?! */
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
430 if (widget->priv.width == 0)
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
431 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
432 GntTree *tree = GNT_TREE(widget);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
433 int i, width = 0;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
434 for (i = 0; i < tree->ncol; i++)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
435 width += tree->columns[i].width;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
436 widget->priv.width = width + i;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
437 }
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
438 }
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 static void
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
441 gnt_tree_map(GntWidget *widget)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
442 {
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
443 GntTree *tree = GNT_TREE(widget);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
444 if (widget->priv.width == 0 || widget->priv.height == 0)
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
445 {
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
446 gnt_widget_size_request(widget);
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
447 }
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
448 tree->top = tree->root;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
449 tree->current = tree->root;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
450 DEBUG;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
451 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
452
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
453 static void
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
454 tree_selection_changed(GntTree *tree, GntTreeRow *old, GntTreeRow *current)
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
455 {
14010
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13979
diff changeset
456 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
457 }
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
458
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
459 static GntTreeRow *
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
460 get_nth_row(GntTree *tree, int n)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
461 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
462 gpointer key = g_list_nth_data(tree->list, n);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
463 return g_hash_table_lookup(tree->hash, key);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
464 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
465
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
466 static gboolean
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
467 gnt_tree_key_pressed(GntWidget *widget, const char *text)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
468 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
469 GntTree *tree = GNT_TREE(widget);
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
470 GntTreeRow *old = tree->current;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
471 GntTreeRow *row;
14215
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
472 int dist;
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
473
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
474 if (text[0] == 27)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
475 {
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
476 if (strcmp(text+1, GNT_KEY_DOWN) == 0 && (row = get_next(tree->current)) != NULL)
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
477 {
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
478 tree->current = row;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
479 if ((dist = get_distance(tree->current, tree->bottom)) < 0)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
480 gnt_tree_scroll(tree, -dist);
13853
bbf0470cb348 [gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13851
diff changeset
481 else
bbf0470cb348 [gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13851
diff changeset
482 redraw_tree(tree);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
483 }
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
484 else if (strcmp(text+1, GNT_KEY_UP) == 0 && (row = get_prev(tree->current)) != NULL)
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
485 {
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
486 tree->current = row;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
487
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
488 if ((dist = get_distance(tree->current, tree->top)) > 0)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
489 gnt_tree_scroll(tree, -dist);
13853
bbf0470cb348 [gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13851
diff changeset
490 else
bbf0470cb348 [gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13851
diff changeset
491 redraw_tree(tree);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
492 }
14216
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
493 else if (strcmp(text+1, GNT_KEY_PGDOWN) == 0)
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
494 {
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
495 row = get_next(tree->bottom);
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
496 if (row)
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
497 {
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
498 int dist = get_distance(tree->top, tree->current);
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
499 tree->top = tree->bottom;
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
500 tree->current = get_next_n_opt(tree->top, dist, NULL);
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
501 redraw_tree(tree);
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
502 }
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
503 else if (tree->current != tree->bottom)
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
504 {
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
505 tree->current = tree->bottom;
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
506 redraw_tree(tree);
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
507 }
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
508 }
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
509 else if (strcmp(text+1, GNT_KEY_PGUP) == 0)
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
510 {
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
511 if (tree->top != tree->root)
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
512 {
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
513 int dist = get_distance(tree->top, tree->current);
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
514 row = get_prev_n(tree->top, widget->priv.height - 1 -
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
515 tree->show_title * 2 - 2 * (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER) == 0));
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
516 if (row == NULL)
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
517 row = tree->root;
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
518 tree->top = row;
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
519 tree->current = get_next_n_opt(tree->top, dist, NULL);
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
520 redraw_tree(tree);
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
521 }
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
522 else if (tree->current != tree->top)
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
523 {
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
524 tree->current = tree->top;
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
525 redraw_tree(tree);
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
526 }
e9dd2f76e61b [gaim-migrate @ 16897]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14215
diff changeset
527 }
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
528 }
14215
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
529 else if (iscntrl(text[0]))
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
530 {
14215
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
531 if (strcmp(text, GNT_KEY_CTRL_N) == 0 && (row = get_next(tree->current)) != NULL)
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
532 {
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
533 tree->current = row;
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
534 if ((dist = get_distance(tree->current, tree->bottom)) < 0)
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
535 gnt_tree_scroll(tree, -dist);
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
536 else
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
537 redraw_tree(tree);
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
538 }
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
539 else if (strcmp(text, GNT_KEY_CTRL_P) == 0 && (row = get_prev(tree->current)) != NULL)
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
540 {
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
541 tree->current = row;
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
542
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
543 if ((dist = get_distance(tree->current, tree->top)) > 0)
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
544 gnt_tree_scroll(tree, -dist);
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
545 else
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
546 redraw_tree(tree);
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
547 }
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
548 else if (text[0] == '\r')
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
549 {
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
550 gnt_widget_activate(widget);
e9304dd00992 [gaim-migrate @ 16896]
Ethan Blanton <elb@pidgin.im>
parents: 14208
diff changeset
551 }
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
552 }
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
553 else if (text[0] == ' ' && text[1] == 0)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
554 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
555 /* Space pressed */
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
556 GntTreeRow *row = tree->current;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
557 if (row && row->child)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
558 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
559 row->collapsed = !row->collapsed;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
560 redraw_tree(tree);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
561 }
13907
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
562 else if (row && row->choice)
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
563 {
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
564 row->isselected = !row->isselected;
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
565 g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key);
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
566 redraw_tree(tree);
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
567 }
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
568 }
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
569
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
570 if (old != tree->current)
13907
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
571 {
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
572 tree_selection_changed(tree, old, tree->current);
13907
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
573 return TRUE;
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
574 }
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
575
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
576 return FALSE;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
577 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
578
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
579 static void
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
580 gnt_tree_destroy(GntWidget *widget)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
581 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
582 GntTree *tree = GNT_TREE(widget);
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
583 int i;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
584
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
585 g_hash_table_destroy(tree->hash);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
586 g_list_free(tree->list);
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
587
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
588 for (i = 0; i < tree->ncol; i++)
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
589 {
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
590 g_free(tree->columns[i].title);
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
591 }
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
592 g_free(tree->columns);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
593 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
594
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
595 static void
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
596 gnt_tree_class_init(GntTreeClass *klass)
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
597 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
598 parent_class = GNT_WIDGET_CLASS(klass);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
599 parent_class->destroy = gnt_tree_destroy;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
600 parent_class->draw = gnt_tree_draw;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
601 parent_class->map = gnt_tree_map;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
602 parent_class->size_request = gnt_tree_size_request;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
603 parent_class->key_pressed = gnt_tree_key_pressed;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
604
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
605 signals[SIG_SELECTION_CHANGED] =
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
606 g_signal_new("selection-changed",
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
607 G_TYPE_FROM_CLASS(klass),
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
608 G_SIGNAL_RUN_LAST,
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
609 G_STRUCT_OFFSET(GntTreeClass, selection_changed),
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
610 NULL, NULL,
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
611 gnt_closure_marshal_VOID__POINTER_POINTER,
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
612 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
613 signals[SIG_SCROLLED] =
d78ab363e02d [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13864
diff changeset
614 g_signal_new("scrolled",
d78ab363e02d [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13864
diff changeset
615 G_TYPE_FROM_CLASS(klass),
d78ab363e02d [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13864
diff changeset
616 G_SIGNAL_RUN_LAST,
d78ab363e02d [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13864
diff changeset
617 0,
d78ab363e02d [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13864
diff changeset
618 NULL, NULL,
d78ab363e02d [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13864
diff changeset
619 g_cclosure_marshal_VOID__INT,
d78ab363e02d [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13864
diff changeset
620 G_TYPE_NONE, 1, G_TYPE_INT);
13907
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
621 signals[SIG_TOGGLED] =
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
622 g_signal_new("toggled",
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
623 G_TYPE_FROM_CLASS(klass),
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
624 G_SIGNAL_RUN_LAST,
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
625 0,
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
626 NULL, NULL,
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
627 g_cclosure_marshal_VOID__POINTER,
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
628 G_TYPE_NONE, 1, G_TYPE_POINTER);
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
629
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
630 DEBUG;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
631 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
632
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
633 static void
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
634 gnt_tree_init(GTypeInstance *instance, gpointer class)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
635 {
13943
25be562aaca8 [gaim-migrate @ 16480]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13937
diff changeset
636 GntWidget *widget = GNT_WIDGET(instance);
25be562aaca8 [gaim-migrate @ 16480]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13937
diff changeset
637 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
638 widget->priv.minw = 4;
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
639 widget->priv.minh = 4;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
640 DEBUG;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
641 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
642
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
643 /******************************************************************************
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
644 * GntTree API
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
645 *****************************************************************************/
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
646 GType
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
647 gnt_tree_get_gtype(void)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
648 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
649 static GType type = 0;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
650
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
651 if(type == 0)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
652 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
653 static const GTypeInfo info = {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
654 sizeof(GntTreeClass),
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
655 NULL, /* base_init */
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
656 NULL, /* base_finalize */
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
657 (GClassInitFunc)gnt_tree_class_init,
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
658 NULL, /* class_finalize */
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
659 NULL, /* class_data */
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
660 sizeof(GntTree),
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
661 0, /* n_preallocs */
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
662 gnt_tree_init, /* instance_init */
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
663 };
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
664
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
665 type = g_type_register_static(GNT_TYPE_WIDGET,
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
666 "GntTree",
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
667 &info, 0);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
668 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
669
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
670 return type;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
671 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
672
13858
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
673 static void
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
674 free_tree_col(gpointer data)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
675 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
676 GntTreeCol *col = data;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
677
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
678 g_free(col->text);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
679 g_free(col);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
680 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
681
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
682 static void
13858
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
683 free_tree_row(gpointer data)
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
684 {
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
685 GntTreeRow *row = data;
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
686
13861
55fb5cd9bac9 [gaim-migrate @ 16322]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13860
diff changeset
687 if (!row)
55fb5cd9bac9 [gaim-migrate @ 16322]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13860
diff changeset
688 return;
55fb5cd9bac9 [gaim-migrate @ 16322]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13860
diff changeset
689
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
690 g_list_foreach(row->columns, (GFunc)free_tree_col, NULL);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
691 g_list_free(row->columns);
13858
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
692 g_free(row);
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
693 }
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
694
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
695 GntWidget *gnt_tree_new()
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
696 {
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
697 return gnt_tree_new_with_columns(1);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
698 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
699
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
700 void gnt_tree_set_visible_rows(GntTree *tree, int rows)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
701 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
702 GntWidget *widget = GNT_WIDGET(tree);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
703 widget->priv.height = rows;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
704 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER))
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
705 widget->priv.height += 2;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
706 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
707
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
708 int gnt_tree_get_visible_rows(GntTree *tree)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
709 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
710 GntWidget *widget = GNT_WIDGET(tree);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
711 int ret = widget->priv.height;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
712 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
713 ret -= 2;
9d66969a2e32 [gaim-migrate @ 16369]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13882
diff changeset
714 return ret;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
715 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
716
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
717 void gnt_tree_scroll(GntTree *tree, int count)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
718 {
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
719 GntTreeRow *row;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
720
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
721 if (count < 0)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
722 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
723 if (get_root_distance(tree->top) == 0)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
724 return;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
725 row = get_prev_n(tree->top, -count);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
726 if (row == NULL)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
727 row = tree->root;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
728 tree->top = row;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
729 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
730 else
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
731 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
732 get_next_n_opt(tree->bottom, count, &count);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
733 tree->top = get_next_n(tree->top, count);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
734 }
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
735
13853
bbf0470cb348 [gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13851
diff changeset
736 redraw_tree(tree);
13865
d78ab363e02d [gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13864
diff changeset
737 g_signal_emit(tree, signals[SIG_SCROLLED], 0, count);
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
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
740 static gpointer
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
741 find_position(GntTree *tree, gpointer key, gpointer parent)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
742 {
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
743 GntTreeRow *row;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
744
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
745 if (tree->compare == NULL)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
746 return NULL;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
747
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
748 if (parent == NULL)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
749 row = tree->root;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
750 else
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
751 row = g_hash_table_lookup(tree->hash, parent);
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
752
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
753 if (!row)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
754 return NULL;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
755
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
756 if (parent)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
757 row = row->child;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
758
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
759 while (row)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
760 {
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
761 if (tree->compare(key, row->key) < 0)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
762 return (row->prev ? row->prev->key : NULL);
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
763 if (row->next)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
764 row = row->next;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
765 else
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
766 return row->key;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
767 }
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
768 return NULL;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
769 }
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
770
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
771 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
772 {
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
773 GntTreeRow *pr = NULL;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
774
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
775 g_hash_table_replace(tree->hash, key, row);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
776
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
777 if (bigbro == NULL && tree->compare)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
778 {
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
779 bigbro = find_position(tree, key, parent);
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
780 }
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
781
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
782 if (tree->root == NULL)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
783 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
784 tree->root = row;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
785 tree->list = g_list_prepend(tree->list, key);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
786 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
787 else
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
788 {
13927
9309d27d780c [gaim-migrate @ 16447]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13907
diff changeset
789 int position = 0;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
790
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
791 if (bigbro)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
792 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
793 pr = g_hash_table_lookup(tree->hash, bigbro);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
794 if (pr)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
795 {
13857
d341b5ac1a78 [gaim-migrate @ 16316]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13856
diff changeset
796 if (pr->next) pr->next->prev = row;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
797 row->next = pr->next;
13857
d341b5ac1a78 [gaim-migrate @ 16316]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13856
diff changeset
798 row->prev = pr;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
799 pr->next = row;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
800 row->parent = pr->parent;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
801
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
802 position = g_list_index(tree->list, bigbro);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
803 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
804 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
805
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
806 if (pr == NULL && parent)
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 pr = g_hash_table_lookup(tree->hash, parent);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
809 if (pr)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
810 {
13857
d341b5ac1a78 [gaim-migrate @ 16316]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13856
diff changeset
811 if (pr->child) pr->child->prev = row;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
812 row->next = pr->child;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
813 pr->child = row;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
814 row->parent = pr;
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 position = g_list_index(tree->list, parent);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
817 }
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
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
820 if (pr == NULL)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
821 {
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
822 GntTreeRow *r = tree->root;
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
823 row->next = r;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
824 if (r) r->prev = row;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
825 tree->root = row;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
826 tree->list = g_list_prepend(tree->list, key);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
827 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
828 else
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
829 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
830 tree->list = g_list_insert(tree->list, key, position + 1);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
831 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
832 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
833
13858
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
834 row->key = key;
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
835 row->data = NULL;
aa1c97f5e6eb [gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13857
diff changeset
836
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
837 redraw_tree(tree);
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
838
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
839 return row;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
840 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
841
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
842 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
843 {
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
844 GntTreeRow *pr = NULL, *br = NULL;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
845
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
846 if (parent)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
847 pr = g_hash_table_lookup(tree->hash, parent);
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
848
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
849 if (pr)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
850 br = pr->child;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
851 else
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
852 br = tree->root;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
853
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
854 if (br)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
855 {
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
856 while (br->next)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
857 br = br->next;
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
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
860 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
861 }
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
862
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
863 gpointer gnt_tree_get_selection_data(GntTree *tree)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
864 {
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
865 if (tree->current)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
866 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
867 return NULL;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
868 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
869
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
870 char *gnt_tree_get_selection_text(GntTree *tree)
13935
cd2da4b079cf [gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13934
diff changeset
871 {
cd2da4b079cf [gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13934
diff changeset
872 if (tree->current)
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
873 return update_row_text(tree, tree->current);
13935
cd2da4b079cf [gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13934
diff changeset
874 return NULL;
cd2da4b079cf [gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13934
diff changeset
875 }
cd2da4b079cf [gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13934
diff changeset
876
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
877 GList *gnt_tree_get_selection_text_list(GntTree *tree)
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
878 {
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
879 GList *list = NULL, *iter;
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
880 int i;
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
881
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
882 if (!tree->current)
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
883 return NULL;
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
884
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
885 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
886 i++, iter = iter->next)
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
887 {
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
888 GntTreeCol *col = iter->data;
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
889 list = g_list_append(list, g_strdup(col->text));
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
890 }
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
891
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
892 return list;
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
893 }
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
894
13857
d341b5ac1a78 [gaim-migrate @ 16316]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13856
diff changeset
895 /* XXX: Should this also remove all the children of the row being removed? */
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
896 void gnt_tree_remove(GntTree *tree, gpointer key)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
897 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
898 GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
899 if (row)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
900 {
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
901 gboolean redraw = FALSE;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
902
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
903 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
904 redraw = TRUE;
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
905
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
906 /* Update root/top/current/bottom if necessary */
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
907 if (tree->root == row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
908 tree->root = get_next(row);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
909 if (tree->top == row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
910 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
911 if (tree->top != tree->root)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
912 tree->top = get_prev(row);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
913 else
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
914 tree->top = get_next(row);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
915 if (tree->current == row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
916 tree->current = tree->top;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
917 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
918 else if (tree->current == row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
919 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
920 if (tree->current != tree->root)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
921 tree->current = get_prev(row);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
922 else
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
923 tree->current = get_next(row);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
924 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
925 else if (tree->bottom == row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
926 {
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
927 tree->bottom = get_prev(row);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
928 }
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
929
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
930 /* Fix the links */
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
931 if (row->next)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
932 row->next->prev = row->prev;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
933 if (row->parent && row->parent->child == row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
934 row->parent->child = row->next;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
935 if (row->prev)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
936 row->prev->next = row->next;
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
937
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
938 g_hash_table_remove(tree->hash, key);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
939 tree->list = g_list_remove(tree->list, key);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
940
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
941 if (redraw)
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
942 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
943 redraw_tree(tree);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
944 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
945 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
946 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
947
14208
7d708210e317 [gaim-migrate @ 16883]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14131
diff changeset
948 static gboolean
7d708210e317 [gaim-migrate @ 16883]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14131
diff changeset
949 return_true(gpointer key, gpointer data, gpointer null)
7d708210e317 [gaim-migrate @ 16883]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14131
diff changeset
950 {
7d708210e317 [gaim-migrate @ 16883]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14131
diff changeset
951 return TRUE;
7d708210e317 [gaim-migrate @ 16883]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14131
diff changeset
952 }
7d708210e317 [gaim-migrate @ 16883]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14131
diff changeset
953
14091
ae4cbed1b309 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
954 void gnt_tree_remove_all(GntTree *tree)
ae4cbed1b309 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
955 {
ae4cbed1b309 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
956 tree->root = NULL;
14208
7d708210e317 [gaim-migrate @ 16883]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14131
diff changeset
957 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
958 g_list_free(tree->list);
ae4cbed1b309 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
959 tree->list = NULL;
ae4cbed1b309 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
960 tree->current = tree->top = tree->bottom = NULL;
ae4cbed1b309 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
961 }
ae4cbed1b309 [gaim-migrate @ 16715]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
962
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
963 int gnt_tree_get_selection_visible_line(GntTree *tree)
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
964 {
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
965 return get_distance(tree->top, tree->current) +
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
966 !!(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
967 }
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13858
diff changeset
968
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
969 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
970 {
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
971 GntTreeRow *row;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
972 GntTreeCol *col;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
973
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
974 g_return_if_fail(colno < tree->ncol);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
975
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
976 row = g_hash_table_lookup(tree->hash, key);
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
977 if (row)
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
978 {
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
979 col = g_list_nth_data(row->columns, colno);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
980 g_free(col->text);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
981 col->text = g_strdup(text);
13864
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
982
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
983 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
984 redraw_tree(tree);
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
985 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
986 }
c7d84d4c5afa [gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13861
diff changeset
987
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
988 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
989 {
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
990 GntTreeRow *r;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
991 r = g_hash_table_lookup(tree->hash, key);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
992 g_return_val_if_fail(!r || !r->choice, NULL);
13907
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
993
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
994 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
995 row->choice = TRUE;
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
996
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
997 return row;
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
998 }
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
999
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1000 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
1001 {
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1002 GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1003
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1004 if (!row)
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1005 return;
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1006 g_return_if_fail(row->choice);
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1007
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1008 row->isselected = set;
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1009 redraw_tree(tree);
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1010 }
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1011
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1012 gboolean gnt_tree_get_choice(GntTree *tree, void *key)
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1013 {
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1014 GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1015
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1016 if (!row)
13927
9309d27d780c [gaim-migrate @ 16447]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13907
diff changeset
1017 return FALSE;
13907
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1018 g_return_val_if_fail(row->choice, FALSE);
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1019
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1020 return row->isselected;
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1021 }
cc60d0861337 [gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
1022
13931
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
1023 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
1024 {
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
1025 GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
13934
ef0d515b9f97 [gaim-migrate @ 16462]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13931
diff changeset
1026 if (!row || row->flags == flags)
13931
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
1027 return;
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
1028
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
1029 row->flags = flags;
13935
cd2da4b079cf [gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13934
diff changeset
1030 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
1031 }
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
1032
13952
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1033 void gnt_tree_set_selected(GntTree *tree , void *key)
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1034 {
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1035 int dist;
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1036 GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1037 if (!row)
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1038 return;
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1039
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1040 if (tree->top == NULL)
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1041 tree->top = row;
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1042 if (tree->bottom == NULL)
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1043 tree->bottom = row;
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1044
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1045 tree->current = row;
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1046 if ((dist = get_distance(tree->current, tree->bottom)) < 0)
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1047 gnt_tree_scroll(tree, -dist);
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1048 else if ((dist = get_distance(tree->current, tree->top)) > 0)
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1049 gnt_tree_scroll(tree, -dist);
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1050 else
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1051 redraw_tree(tree);
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1052 }
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
1053
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1054 GntWidget *gnt_tree_new_with_columns(int col)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1055 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1056 GntWidget *widget = g_object_new(GNT_TYPE_TREE, NULL);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1057 GntTree *tree = GNT_TREE(widget);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1058
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1059 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
1060 tree->ncol = col;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1061 tree->columns = g_new0(struct _GntTreeColInfo, col);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1062 while (col--)
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1063 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1064 tree->columns[col].width = 15;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1065 }
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1066 tree->show_title = FALSE;
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1067
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1068 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1069 gnt_widget_set_take_focus(widget, TRUE);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1070
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1071 return widget;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1072 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1073
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1074 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
1075 {
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1076 GList *iter;
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1077 int i;
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1078 GntTreeRow *row = g_new0(GntTreeRow, 1);
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1079
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1080 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
1081 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1082 GntTreeCol *col = g_new0(GntTreeCol, 1);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1083 col->span = 1;
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1084 col->text = g_strdup(iter->data);
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1085
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1086 row->columns = g_list_append(row->columns, col);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1087 }
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1088
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1089 return row;
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1090 }
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1091
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1092 GntTreeRow *gnt_tree_create_row(GntTree *tree, ...)
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1093 {
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1094 int i;
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1095 va_list args;
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1096 GList *list = NULL;
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1097 GntTreeRow *row;
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1098
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1099 va_start(args, tree);
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1100 for (i = 0; i < tree->ncol; i++)
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1101 {
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
1102 list = g_list_append(list, va_arg(args, char *));
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1103 }
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1104 va_end(args);
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1105
13979
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1106 row = gnt_tree_create_row_from_list(tree, list);
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1107 g_list_free(list);
a71678d2da16 [gaim-migrate @ 16540]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
1108
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1109 return row;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1110 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1111
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1112 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
1113 {
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1114 g_return_if_fail(col < tree->ncol);
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1115
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1116 tree->columns[col].width = width;
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1117 }
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
1118
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1119 void gnt_tree_set_column_titles(GntTree *tree, ...)
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1120 {
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1121 int i;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1122 va_list args;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1123
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1124 va_start(args, tree);
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1125 for (i = 0; i < tree->ncol; i++)
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1126 {
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1127 const char *title = va_arg(args, const char *);
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1128 tree->columns[i].title = g_strdup(title);
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1129 }
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1130 va_end(args);
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1131 }
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1132
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1133 void gnt_tree_set_show_title(GntTree *tree, gboolean set)
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1134 {
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1135 tree->show_title = set;
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
1136 GNT_WIDGET(tree)->priv.minh = (set ? 6 : 4);
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1137 }
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13964
diff changeset
1138
14105
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1139 void gnt_tree_set_compare_func(GntTree *tree, GCompareFunc func)
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1140 {
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1141 tree->compare = func;
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1142 }
eaf7f35635bc [gaim-migrate @ 16739]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14091
diff changeset
1143