annotate console/libgnt/gnttree.c @ 14836:bfcdd361357e

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