Mercurial > pidgin
annotate console/libgnt/gnttree.c @ 13936:669898e6aa11
[gaim-migrate @ 16467]
Minor enhancements for the combobox.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sun, 09 Jul 2006 00:54:31 +0000 |
parents | cd2da4b079cf |
children | af23525bcb31 |
rev | line source |
---|---|
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
1 #include "gnttree.h" |
13935
cd2da4b079cf
[gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13934
diff
changeset
|
2 #include "gntmarshal.h" |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
3 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
4 #include <string.h> |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
5 |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
6 enum |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
7 { |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
8 SIG_SELECTION_CHANGED, |
13865
d78ab363e02d
[gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13864
diff
changeset
|
9 SIG_SCROLLED, |
13907
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
10 SIG_TOGGLED, |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
11 SIGS, |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
12 }; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
13 |
13858
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
14 #define TAB_SIZE 3 |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
15 |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
16 /* XXX: Make this one into a GObject? |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
17 * ... Probably not */ |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
18 struct _GnTreeRow |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
19 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
20 void *key; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
21 char *text; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
22 void *data; /* XXX: unused */ |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
23 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
24 gboolean collapsed; |
13907
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
25 gboolean choice; /* Is this a choice-box? |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
26 If choice is true, then child will be NULL */ |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
27 gboolean isselected; |
13931
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
28 GntTextFormatFlags flags; |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
29 |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
30 GntTreeRow *parent; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
31 GntTreeRow *child; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
32 GntTreeRow *next; |
13857
d341b5ac1a78
[gaim-migrate @ 16316]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13856
diff
changeset
|
33 GntTreeRow *prev; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
34 }; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
35 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
36 static GntWidgetClass *parent_class = NULL; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
37 static guint signals[SIGS] = { 0 }; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
38 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
39 static GntTreeRow * |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
40 _get_next(GntTreeRow *row, gboolean godeep) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
41 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
42 if (row == NULL) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
43 return NULL; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
44 if (godeep && row->child) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
45 return row->child; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
46 if (row->next) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
47 return row->next; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
48 return _get_next(row->parent, FALSE); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
49 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
50 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
51 static GntTreeRow * |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
52 get_next(GntTreeRow *row) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
53 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
54 if (row == NULL) |
13888
9d66969a2e32
[gaim-migrate @ 16369]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13882
diff
changeset
|
55 return NULL; |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
56 return _get_next(row, !row->collapsed); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
57 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
58 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
59 /* 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
|
60 static GntTreeRow * |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
61 get_next_n(GntTreeRow *row, int n) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
62 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
63 while (row && n--) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
64 row = get_next(row); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
65 return row; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
66 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
67 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
68 /* 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
|
69 static GntTreeRow * |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
70 get_next_n_opt(GntTreeRow *row, int n, int *pos) |
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 GntTreeRow *next = row; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
73 int r = 0; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
74 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
75 if (row == NULL) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
76 return NULL; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
77 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
78 while (row && n--) |
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 row = get_next(row); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
81 if (row) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
82 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
83 next = row; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
84 r++; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
85 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
86 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
87 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
88 if (pos) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
89 *pos = r; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
90 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
91 return next; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
92 } |
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 static GntTreeRow * |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
95 get_last_child(GntTreeRow *row) |
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 if (!row->collapsed && row->child) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
100 row = row->child; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
101 else |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
102 return row; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
103 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
104 while(row->next) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
105 row = row->next; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
106 if (row->child) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
107 row = get_last_child(row->child); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
108 return row; |
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 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
111 static GntTreeRow * |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
112 get_prev(GntTreeRow *row) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
113 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
114 if (row == NULL) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
115 return NULL; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
116 if (row->prev) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
117 return get_last_child(row->prev); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
118 return row->parent; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
119 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
120 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
121 static GntTreeRow * |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
122 get_prev_n(GntTreeRow *row, int n) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
123 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
124 while (row && n--) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
125 row = get_prev(row); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
126 return row; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
127 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
128 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
129 /* Distance of row from the root */ |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
130 /* XXX: This is uber-inefficient */ |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
131 static int |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
132 get_root_distance(GntTreeRow *row) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
133 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
134 if (row == NULL) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
135 return -1; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
136 return get_root_distance(get_prev(row)) + 1; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
137 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
138 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
139 /* Returns the distance between a and b. |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
140 * If a is 'above' b, then the distance is positive */ |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
141 static int |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
142 get_distance(GntTreeRow *a, GntTreeRow *b) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
143 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
144 /* First get the distance from a to the root. |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
145 * Then the distance from b to the root. |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
146 * Subtract. |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
147 * It's not that good, but it works. */ |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
148 int ha = get_root_distance(a); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
149 int hb = get_root_distance(b); |
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 return (hb - ha); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
152 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
153 |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
154 static void |
13853
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
155 redraw_tree(GntTree *tree) |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
156 { |
13853
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
157 int start; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
158 GntWidget *widget = GNT_WIDGET(tree); |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
159 GntTreeRow *row; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
160 int pos; |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
161 gboolean deep; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
162 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
163 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
164 pos = 0; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
165 else |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
166 pos = 1; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
167 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
168 if (tree->top == NULL) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
169 tree->top = tree->root; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
170 if (tree->current == NULL) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
171 tree->current = tree->root; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
172 |
13854
a4c30c1d9de8
[gaim-migrate @ 16313]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13853
diff
changeset
|
173 wbkgd(widget->window, COLOR_PAIR(GNT_COLOR_NORMAL)); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
174 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
175 deep = TRUE; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
176 row = tree->top; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
177 for (start = pos; row && start < widget->priv.height - pos; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
178 start++, row = get_next(row)) |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
179 { |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
180 char str[2048]; |
13853
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
181 int wr; |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
182 char format[16] = ""; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
183 |
13931
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
184 GntTextFormatFlags flags = row->flags; |
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
185 int attr = 0; |
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
186 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
187 deep = TRUE; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
188 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
189 if (row->parent == NULL && row->child) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
190 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
191 if (row->collapsed) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
192 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
193 strcpy(format, "+ "); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
194 deep = FALSE; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
195 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
196 else |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
197 strcpy(format, "- "); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
198 } |
13907
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
199 else if (row->choice) |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
200 { |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
201 g_snprintf(format, sizeof(format) - 1, "[%c] ", row->isselected ? 'X' : ' '); |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
202 } |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
203 |
13936
669898e6aa11
[gaim-migrate @ 16467]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13935
diff
changeset
|
204 g_snprintf(str, sizeof(str) - 1, "%s%s", format, row->text); |
669898e6aa11
[gaim-migrate @ 16467]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13935
diff
changeset
|
205 |
669898e6aa11
[gaim-migrate @ 16467]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13935
diff
changeset
|
206 if ((wr = g_utf8_strlen(str, -1)) >= widget->priv.width - 1 - pos) |
13851
41753203a94d
[gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13850
diff
changeset
|
207 { |
41753203a94d
[gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13850
diff
changeset
|
208 /* XXX: ellipsize */ |
13936
669898e6aa11
[gaim-migrate @ 16467]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13935
diff
changeset
|
209 char *s = g_utf8_offset_to_pointer(str, widget->priv.width - 1 - pos); |
669898e6aa11
[gaim-migrate @ 16467]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13935
diff
changeset
|
210 *s = '\0'; |
13851
41753203a94d
[gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13850
diff
changeset
|
211 } |
13853
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
212 else |
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
213 { |
13855
5b288502a382
[gaim-migrate @ 16314]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13854
diff
changeset
|
214 while (wr < widget->priv.width - 1 - pos) |
13853
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
215 str[wr++] = ' '; |
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
216 str[wr] = 0; |
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
217 } |
13931
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
218 |
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
219 if (flags & GNT_TEXT_FLAG_BOLD) |
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
220 attr |= A_BOLD; |
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
221 if (flags & GNT_TEXT_FLAG_UNDERLINE) |
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
222 attr |= A_UNDERLINE; |
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
223 if (flags & GNT_TEXT_FLAG_BLINK) |
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
224 attr |= A_BLINK; |
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
225 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
226 if (row == tree->current) |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
227 { |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
228 if (gnt_widget_has_focus(widget)) |
13931
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
229 attr |= COLOR_PAIR(GNT_COLOR_HIGHLIGHT); |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13878
diff
changeset
|
230 else |
13931
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
231 attr |= COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
232 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
233 else |
13927
9309d27d780c
[gaim-migrate @ 16447]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13907
diff
changeset
|
234 { |
13931
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
235 if (flags & GNT_TEXT_FLAG_DIM) |
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
236 attr |= (A_DIM | COLOR_PAIR(GNT_COLOR_DISABLED)); |
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
237 else if (flags & GNT_TEXT_FLAG_HIGHLIGHT) |
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
238 attr |= (A_DIM | COLOR_PAIR(GNT_COLOR_HIGHLIGHT)); |
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
239 else |
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
240 attr |= COLOR_PAIR(GNT_COLOR_NORMAL); |
13927
9309d27d780c
[gaim-migrate @ 16447]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13907
diff
changeset
|
241 } |
13931
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
242 |
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
243 wbkgdset(widget->window, '\0' | attr); |
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
244 mvwprintw(widget->window, start, pos, str); |
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
245 whline(widget->window, ' ', widget->priv.width - pos * 2 - g_utf8_strlen(str, -1)); |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
246 tree->bottom = row; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
247 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
248 |
13931
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
249 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
250 while (start < widget->priv.height - pos) |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
251 { |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
252 mvwhline(widget->window, start, pos, ' ', |
13855
5b288502a382
[gaim-migrate @ 16314]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13854
diff
changeset
|
253 widget->priv.width - pos * 2); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
254 start++; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
255 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
256 |
13878
0d0ab1e39d0a
[gaim-migrate @ 16355]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13865
diff
changeset
|
257 gnt_widget_queue_update(widget); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
258 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
259 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
260 static void |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
261 gnt_tree_draw(GntWidget *widget) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
262 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
263 GntTree *tree = GNT_TREE(widget); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
264 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
265 redraw_tree(tree); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
266 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
267 DEBUG; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
268 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
269 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
270 static void |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
271 gnt_tree_size_request(GntWidget *widget) |
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 (widget->priv.height == 0) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
274 widget->priv.height = 10; /* XXX: Why?! */ |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
275 if (widget->priv.width == 0) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
276 widget->priv.width = 20; /* YYY: 'cuz ... */ |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
277 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
278 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
279 static void |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
280 gnt_tree_map(GntWidget *widget) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
281 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
282 if (widget->priv.width == 0 || widget->priv.height == 0) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
283 gnt_widget_size_request(widget); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
284 DEBUG; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
285 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
286 |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
287 static void |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
288 tree_selection_changed(GntTree *tree, GntTreeRow *old, GntTreeRow *current) |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
289 { |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
290 g_signal_emit(tree, signals[SIG_SELECTION_CHANGED], 0, old, current); |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
291 } |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
292 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
293 static GntTreeRow * |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
294 get_nth_row(GntTree *tree, int n) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
295 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
296 gpointer key = g_list_nth_data(tree->list, n); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
297 return g_hash_table_lookup(tree->hash, key); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
298 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
299 |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
300 static gboolean |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
301 gnt_tree_key_pressed(GntWidget *widget, const char *text) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
302 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
303 GntTree *tree = GNT_TREE(widget); |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
304 GntTreeRow *old = tree->current; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
305 GntTreeRow *row; |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
306 |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
307 if (text[0] == 27) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
308 { |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
309 int dist; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
310 if (strcmp(text+1, GNT_KEY_DOWN) == 0 && (row = get_next(tree->current)) != NULL) |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
311 { |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
312 tree->current = row; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
313 if ((dist = get_distance(tree->current, tree->bottom)) < 0) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
314 gnt_tree_scroll(tree, -dist); |
13853
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
315 else |
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
316 redraw_tree(tree); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
317 } |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
318 else if (strcmp(text+1, GNT_KEY_UP) == 0 && (row = get_prev(tree->current)) != NULL) |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
319 { |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
320 tree->current = row; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
321 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
322 if ((dist = get_distance(tree->current, tree->top)) > 0) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
323 gnt_tree_scroll(tree, -dist); |
13853
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
324 else |
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
325 redraw_tree(tree); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
326 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
327 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
328 else if (text[0] == '\r') |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
329 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
330 gnt_widget_activate(widget); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
331 } |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
332 else if (text[0] == ' ' && text[1] == 0) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
333 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
334 /* Space pressed */ |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
335 GntTreeRow *row = tree->current; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
336 if (row && row->child) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
337 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
338 row->collapsed = !row->collapsed; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
339 redraw_tree(tree); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
340 } |
13907
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
341 else if (row && row->choice) |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
342 { |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
343 row->isselected = !row->isselected; |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
344 g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key); |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
345 redraw_tree(tree); |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
346 } |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
347 } |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
348 |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
349 if (old != tree->current) |
13907
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
350 { |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
351 tree_selection_changed(tree, old, tree->current); |
13907
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
352 return TRUE; |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
353 } |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
354 |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
355 return FALSE; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
356 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
357 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
358 static void |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
359 gnt_tree_destroy(GntWidget *widget) |
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 GntTree *tree = GNT_TREE(widget); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
362 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
363 g_hash_table_destroy(tree->hash); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
364 g_list_free(tree->list); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
365 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
366 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
367 static void |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
368 gnt_tree_class_init(GntTreeClass *klass) |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
369 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
370 parent_class = GNT_WIDGET_CLASS(klass); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
371 parent_class->destroy = gnt_tree_destroy; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
372 parent_class->draw = gnt_tree_draw; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
373 parent_class->map = gnt_tree_map; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
374 parent_class->size_request = gnt_tree_size_request; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
375 parent_class->key_pressed = gnt_tree_key_pressed; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
376 |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
377 signals[SIG_SELECTION_CHANGED] = |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
378 g_signal_new("selection-changed", |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
379 G_TYPE_FROM_CLASS(klass), |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
380 G_SIGNAL_RUN_LAST, |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
381 G_STRUCT_OFFSET(GntTreeClass, selection_changed), |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
382 NULL, NULL, |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
383 gnt_closure_marshal_VOID__POINTER_POINTER, |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
384 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
|
385 signals[SIG_SCROLLED] = |
d78ab363e02d
[gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13864
diff
changeset
|
386 g_signal_new("scrolled", |
d78ab363e02d
[gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13864
diff
changeset
|
387 G_TYPE_FROM_CLASS(klass), |
d78ab363e02d
[gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13864
diff
changeset
|
388 G_SIGNAL_RUN_LAST, |
d78ab363e02d
[gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13864
diff
changeset
|
389 0, |
d78ab363e02d
[gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13864
diff
changeset
|
390 NULL, NULL, |
d78ab363e02d
[gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13864
diff
changeset
|
391 g_cclosure_marshal_VOID__INT, |
d78ab363e02d
[gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13864
diff
changeset
|
392 G_TYPE_NONE, 1, G_TYPE_INT); |
13907
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
393 signals[SIG_TOGGLED] = |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
394 g_signal_new("toggled", |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
395 G_TYPE_FROM_CLASS(klass), |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
396 G_SIGNAL_RUN_LAST, |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
397 0, |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
398 NULL, NULL, |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
399 g_cclosure_marshal_VOID__POINTER, |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
400 G_TYPE_NONE, 1, G_TYPE_POINTER); |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
401 |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
402 DEBUG; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
403 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
404 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
405 static void |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
406 gnt_tree_init(GTypeInstance *instance, gpointer class) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
407 { |
13930
3dbcbc5e57e1
[gaim-migrate @ 16457]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13927
diff
changeset
|
408 GNT_WIDGET_SET_FLAGS(GNT_WIDGET(instance), GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
409 DEBUG; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
410 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
411 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
412 /****************************************************************************** |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
413 * GntTree API |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
414 *****************************************************************************/ |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
415 GType |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
416 gnt_tree_get_gtype(void) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
417 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
418 static GType type = 0; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
419 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
420 if(type == 0) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
421 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
422 static const GTypeInfo info = { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
423 sizeof(GntTreeClass), |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
424 NULL, /* base_init */ |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
425 NULL, /* base_finalize */ |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
426 (GClassInitFunc)gnt_tree_class_init, |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
427 NULL, /* class_finalize */ |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
428 NULL, /* class_data */ |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
429 sizeof(GntTree), |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
430 0, /* n_preallocs */ |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
431 gnt_tree_init, /* instance_init */ |
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 type = g_type_register_static(GNT_TYPE_WIDGET, |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
435 "GntTree", |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
436 &info, 0); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
437 } |
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 return type; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
440 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
441 |
13858
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
442 static void |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
443 free_tree_row(gpointer data) |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
444 { |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
445 GntTreeRow *row = data; |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
446 |
13861
55fb5cd9bac9
[gaim-migrate @ 16322]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13860
diff
changeset
|
447 if (!row) |
55fb5cd9bac9
[gaim-migrate @ 16322]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13860
diff
changeset
|
448 return; |
55fb5cd9bac9
[gaim-migrate @ 16322]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13860
diff
changeset
|
449 |
13858
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
450 g_free(row->text); |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
451 g_free(row); |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
452 } |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
453 |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
454 GntWidget *gnt_tree_new() |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
455 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
456 GntWidget *widget = g_object_new(GNT_TYPE_TREE, NULL); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
457 GntTree *tree = GNT_TREE(widget); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
458 |
13858
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
459 tree->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_tree_row); |
13853
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
460 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW); |
13856
3cdd05b9830a
[gaim-migrate @ 16315]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13855
diff
changeset
|
461 gnt_widget_set_take_focus(widget, TRUE); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
462 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
463 return widget; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
464 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
465 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
466 void gnt_tree_set_visible_rows(GntTree *tree, int rows) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
467 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
468 GntWidget *widget = GNT_WIDGET(tree); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
469 widget->priv.height = rows; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
470 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
471 widget->priv.height += 2; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
472 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
473 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
474 int gnt_tree_get_visible_rows(GntTree *tree) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
475 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
476 GntWidget *widget = GNT_WIDGET(tree); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
477 int ret = widget->priv.height; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
478 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
|
479 ret -= 2; |
9d66969a2e32
[gaim-migrate @ 16369]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13882
diff
changeset
|
480 return ret; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
481 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
482 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
483 void gnt_tree_scroll(GntTree *tree, int count) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
484 { |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
485 GntTreeRow *row; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
486 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
487 if (count < 0) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
488 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
489 if (get_root_distance(tree->top) == 0) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
490 return; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
491 row = get_prev_n(tree->top, -count); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
492 if (row == NULL) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
493 row = tree->root; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
494 tree->top = row; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
495 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
496 else |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
497 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
498 get_next_n_opt(tree->bottom, count, &count); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
499 tree->top = get_next_n(tree->top, count); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
500 } |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
501 |
13853
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
502 redraw_tree(tree); |
13865
d78ab363e02d
[gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13864
diff
changeset
|
503 g_signal_emit(tree, signals[SIG_SCROLLED], 0, count); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
504 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
505 |
13858
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
506 static int |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
507 find_depth(GntTreeRow *row) |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
508 { |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
509 int dep = -1; |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
510 |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
511 while (row) |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
512 { |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
513 dep++; |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
514 row = row->parent; |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
515 } |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
516 |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
517 return dep; |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
518 } |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
519 |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
520 GntTreeRow *gnt_tree_add_row_after(GntTree *tree, void *key, const char *text, void *parent, void *bigbro) |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
521 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
522 GntTreeRow *row = g_new0(GntTreeRow, 1), *pr = NULL; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
523 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
524 g_hash_table_replace(tree->hash, key, row); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
525 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
526 if (tree->root == NULL) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
527 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
528 tree->root = row; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
529 tree->list = g_list_prepend(tree->list, key); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
530 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
531 else |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
532 { |
13927
9309d27d780c
[gaim-migrate @ 16447]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13907
diff
changeset
|
533 int position = 0; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
534 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
535 if (bigbro) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
536 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
537 pr = g_hash_table_lookup(tree->hash, bigbro); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
538 if (pr) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
539 { |
13857
d341b5ac1a78
[gaim-migrate @ 16316]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13856
diff
changeset
|
540 if (pr->next) pr->next->prev = row; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
541 row->next = pr->next; |
13857
d341b5ac1a78
[gaim-migrate @ 16316]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13856
diff
changeset
|
542 row->prev = pr; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
543 pr->next = row; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
544 row->parent = pr->parent; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
545 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
546 position = g_list_index(tree->list, bigbro); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
547 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
548 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
549 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
550 if (pr == NULL && parent) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
551 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
552 pr = g_hash_table_lookup(tree->hash, parent); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
553 if (pr) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
554 { |
13857
d341b5ac1a78
[gaim-migrate @ 16316]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13856
diff
changeset
|
555 if (pr->child) pr->child->prev = row; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
556 row->next = pr->child; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
557 pr->child = row; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
558 row->parent = pr; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
559 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
560 position = g_list_index(tree->list, parent); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
561 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
562 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
563 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
564 if (pr == NULL) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
565 { |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
566 GntTreeRow *r = tree->root; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
567 while (r->next) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
568 r = r->next; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
569 r->next = row; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
570 row->prev = r; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
571 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
572 tree->list = g_list_append(tree->list, key); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
573 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
574 else |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
575 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
576 tree->list = g_list_insert(tree->list, key, position + 1); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
577 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
578 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
579 |
13858
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
580 row->key = key; |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
581 row->text = g_strdup_printf("%*s%s", TAB_SIZE * find_depth(row), "", text); |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
582 row->data = NULL; |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
583 |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
584 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_MAPPED)) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
585 redraw_tree(tree); |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
586 |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
587 return row; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
588 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
589 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
590 gpointer gnt_tree_get_selection_data(GntTree *tree) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
591 { |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
592 if (tree->current) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
593 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
|
594 return NULL; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
595 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
596 |
13935
cd2da4b079cf
[gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13934
diff
changeset
|
597 const char *gnt_tree_get_selection_text(GntTree *tree) |
cd2da4b079cf
[gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13934
diff
changeset
|
598 { |
cd2da4b079cf
[gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13934
diff
changeset
|
599 if (tree->current) |
cd2da4b079cf
[gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13934
diff
changeset
|
600 return tree->current->text; |
cd2da4b079cf
[gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13934
diff
changeset
|
601 return NULL; |
cd2da4b079cf
[gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13934
diff
changeset
|
602 } |
cd2da4b079cf
[gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13934
diff
changeset
|
603 |
13857
d341b5ac1a78
[gaim-migrate @ 16316]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13856
diff
changeset
|
604 /* 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
|
605 void gnt_tree_remove(GntTree *tree, gpointer key) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
606 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
607 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
608 if (row) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
609 { |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
610 gboolean redraw = FALSE; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
611 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
612 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
|
613 redraw = TRUE; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
614 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
615 /* Update root/top/current/bottom if necessary */ |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
616 if (tree->root == row) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
617 tree->root = get_next(row); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
618 if (tree->top == row) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
619 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
620 if (tree->top != tree->root) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
621 tree->top = get_prev(row); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
622 else |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
623 tree->top = get_next(row); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
624 if (tree->current == row) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
625 tree->current = tree->top; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
626 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
627 else if (tree->current == row) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
628 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
629 if (tree->current != tree->root) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
630 tree->current = get_prev(row); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
631 else |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
632 tree->current = get_next(row); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
633 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
634 else if (tree->bottom == row) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
635 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
636 tree->bottom = get_prev(row); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
637 } |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
638 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
639 /* Fix the links */ |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
640 if (row->next) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
641 row->next->prev = row->prev; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
642 if (row->parent && row->parent->child == row) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
643 row->parent->child = row->next; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
644 if (row->prev) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
645 row->prev->next = row->next; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
646 |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
647 g_hash_table_remove(tree->hash, key); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
648 tree->list = g_list_remove(tree->list, key); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
649 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
650 if (redraw) |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
651 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
652 redraw_tree(tree); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
653 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
654 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
655 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
656 |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
657 int gnt_tree_get_selection_visible_line(GntTree *tree) |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
658 { |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
659 return get_distance(tree->top, tree->current) + |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
660 !!(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
|
661 } |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
662 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
663 void gnt_tree_change_text(GntTree *tree, gpointer key, const char *text) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
664 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
665 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
666 if (row) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
667 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
668 g_free(row->text); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
669 row->text = g_strdup_printf("%*s%s", TAB_SIZE * find_depth(row), "", text); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
670 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
671 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
|
672 redraw_tree(tree); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
673 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
674 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
675 |
13907
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
676 GntTreeRow *gnt_tree_add_choice(GntTree *tree, void *key, const char *text, void *parent, void *bigbro) |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
677 { |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
678 GntTreeRow *row; |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
679 |
13907
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
680 row = g_hash_table_lookup(tree->hash, key); |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
681 g_return_val_if_fail(!row || !row->choice, NULL); |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
682 |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
683 row = gnt_tree_add_row_after(tree, key, text, parent, bigbro); |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
684 row->choice = TRUE; |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
685 |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
686 return row; |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
687 } |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
688 |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
689 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
|
690 { |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
691 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
692 |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
693 if (!row) |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
694 return; |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
695 g_return_if_fail(row->choice); |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
696 |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
697 row->isselected = set; |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
698 redraw_tree(tree); |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
699 } |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
700 |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
701 gboolean gnt_tree_get_choice(GntTree *tree, void *key) |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
702 { |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
703 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
704 |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
705 if (!row) |
13927
9309d27d780c
[gaim-migrate @ 16447]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13907
diff
changeset
|
706 return FALSE; |
13907
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
707 g_return_val_if_fail(row->choice, FALSE); |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
708 |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
709 return row->isselected; |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
710 } |
cc60d0861337
[gaim-migrate @ 16402]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
711 |
13931
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
712 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
|
713 { |
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
714 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); |
13934
ef0d515b9f97
[gaim-migrate @ 16462]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13931
diff
changeset
|
715 if (!row || row->flags == flags) |
13931
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
716 return; |
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
717 |
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
718 row->flags = flags; |
13935
cd2da4b079cf
[gaim-migrate @ 16466]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13934
diff
changeset
|
719 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
|
720 } |
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
721 |