Mercurial > pidgin
annotate console/libgnt/gnttree.c @ 13893:ab671b76fb96
[gaim-migrate @ 16376]
I may have done it (window-redrawing thing) right this time.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Fri, 30 Jun 2006 03:57:22 +0000 |
parents | 9d66969a2e32 |
children | a621329e8c85 |
rev | line source |
---|---|
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
1 #include "gnttree.h" |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
2 #include "gntutils.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, |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
10 SIGS, |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
11 }; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
12 |
13858
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
13 #define TAB_SIZE 3 |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
14 |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
15 /* XXX: Make this one into a GObject? |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
16 * ... Probably not */ |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
17 struct _GnTreeRow |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
18 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
19 void *key; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
20 char *text; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
21 void *data; /* XXX: unused */ |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
22 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
23 gboolean collapsed; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
24 |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
25 GntTreeRow *parent; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
26 GntTreeRow *child; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
27 GntTreeRow *next; |
13857
d341b5ac1a78
[gaim-migrate @ 16316]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13856
diff
changeset
|
28 GntTreeRow *prev; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
29 }; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
30 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
31 static GntWidgetClass *parent_class = NULL; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
32 static guint signals[SIGS] = { 0 }; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
33 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
34 static GntTreeRow * |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
35 _get_next(GntTreeRow *row, gboolean godeep) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
36 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
37 if (row == NULL) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
38 return NULL; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
39 if (godeep && row->child) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
40 return row->child; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
41 if (row->next) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
42 return row->next; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
43 return _get_next(row->parent, FALSE); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
44 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
45 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
46 static GntTreeRow * |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
47 get_next(GntTreeRow *row) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
48 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
49 if (row == NULL) |
13888
9d66969a2e32
[gaim-migrate @ 16369]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13882
diff
changeset
|
50 return NULL; |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
51 return _get_next(row, !row->collapsed); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
52 } |
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 /* 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
|
55 static GntTreeRow * |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
56 get_next_n(GntTreeRow *row, int n) |
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 while (row && n--) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
59 row = get_next(row); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
60 return row; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
61 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
62 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
63 /* 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
|
64 static GntTreeRow * |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
65 get_next_n_opt(GntTreeRow *row, int n, int *pos) |
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 GntTreeRow *next = row; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
68 int r = 0; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
69 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
70 if (row == NULL) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
71 return NULL; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
72 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
73 while (row && n--) |
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 row = get_next(row); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
76 if (row) |
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 next = row; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
79 r++; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
80 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
81 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
82 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
83 if (pos) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
84 *pos = 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 return next; |
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 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
89 static GntTreeRow * |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
90 get_last_child(GntTreeRow *row) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
91 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
92 if (row == NULL) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
93 return NULL; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
94 if (!row->collapsed && row->child) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
95 row = row->child; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
96 else |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
97 return row; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
98 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
99 while(row->next) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
100 row = row->next; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
101 if (row->child) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
102 row = get_last_child(row->child); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
103 return row; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
104 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
105 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
106 static GntTreeRow * |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
107 get_prev(GntTreeRow *row) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
108 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
109 if (row == NULL) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
110 return NULL; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
111 if (row->prev) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
112 return get_last_child(row->prev); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
113 return row->parent; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
114 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
115 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
116 static GntTreeRow * |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
117 get_prev_n(GntTreeRow *row, int n) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
118 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
119 while (row && n--) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
120 row = get_prev(row); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
121 return row; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
122 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
123 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
124 /* Distance of row from the root */ |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
125 /* XXX: This is uber-inefficient */ |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
126 static int |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
127 get_root_distance(GntTreeRow *row) |
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 if (row == NULL) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
130 return -1; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
131 return get_root_distance(get_prev(row)) + 1; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
132 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
133 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
134 /* Returns the distance between a and b. |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
135 * If a is 'above' b, then the distance is positive */ |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
136 static int |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
137 get_distance(GntTreeRow *a, GntTreeRow *b) |
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 /* First get the distance from a to the root. |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
140 * Then the distance from b to the root. |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
141 * Subtract. |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
142 * It's not that good, but it works. */ |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
143 int ha = get_root_distance(a); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
144 int hb = get_root_distance(b); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
145 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
146 return (hb - ha); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
147 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
148 |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
149 static void |
13853
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
150 redraw_tree(GntTree *tree) |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
151 { |
13853
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
152 int start; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
153 GntWidget *widget = GNT_WIDGET(tree); |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
154 GntTreeRow *row; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
155 int pos; |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
156 gboolean deep; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
157 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
158 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
159 pos = 0; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
160 else |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
161 pos = 1; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
162 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
163 if (tree->top == NULL) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
164 tree->top = tree->root; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
165 if (tree->current == NULL) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
166 tree->current = tree->root; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
167 |
13854
a4c30c1d9de8
[gaim-migrate @ 16313]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13853
diff
changeset
|
168 wbkgd(widget->window, COLOR_PAIR(GNT_COLOR_NORMAL)); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
169 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
170 deep = TRUE; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
171 row = tree->top; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
172 for (start = pos; row && start < widget->priv.height - pos; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
173 start++, row = get_next(row)) |
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 char str[2048]; |
13853
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
176 int wr; |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
177 char format[16] = ""; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
178 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
179 deep = TRUE; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
180 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
181 if (row->parent == NULL && row->child) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
182 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
183 if (row->collapsed) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
184 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
185 strcpy(format, "+ "); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
186 deep = FALSE; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
187 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
188 else |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
189 strcpy(format, "- "); |
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 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
192 if ((wr = g_snprintf(str, widget->priv.width, "%s%s", format, row->text)) >= widget->priv.width) |
13851
41753203a94d
[gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13850
diff
changeset
|
193 { |
41753203a94d
[gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13850
diff
changeset
|
194 /* XXX: ellipsize */ |
13855
5b288502a382
[gaim-migrate @ 16314]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13854
diff
changeset
|
195 str[widget->priv.width - 1 - pos] = 0; |
13851
41753203a94d
[gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13850
diff
changeset
|
196 } |
13853
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
197 else |
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
198 { |
13855
5b288502a382
[gaim-migrate @ 16314]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13854
diff
changeset
|
199 while (wr < widget->priv.width - 1 - pos) |
13853
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
200 str[wr++] = ' '; |
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
201 str[wr] = 0; |
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
202 } |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
203 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
204 if (row == tree->current) |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
205 { |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13878
diff
changeset
|
206 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_HAS_FOCUS)) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13878
diff
changeset
|
207 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_HIGHLIGHT)); |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13878
diff
changeset
|
208 else |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13878
diff
changeset
|
209 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D)); /* XXX: This, somehow, doesn't work */ |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
210 mvwprintw(widget->window, start, pos, str); |
13854
a4c30c1d9de8
[gaim-migrate @ 16313]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13853
diff
changeset
|
211 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
212 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
213 else |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
214 mvwprintw(widget->window, start, pos, str); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
215 tree->bottom = row; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
216 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
217 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
218 while (start < widget->priv.height - pos) |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
219 { |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
220 mvwhline(widget->window, start, pos, ' ', |
13855
5b288502a382
[gaim-migrate @ 16314]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13854
diff
changeset
|
221 widget->priv.width - pos * 2); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
222 start++; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
223 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
224 |
13878
0d0ab1e39d0a
[gaim-migrate @ 16355]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13865
diff
changeset
|
225 gnt_widget_queue_update(widget); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
226 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
227 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
228 static void |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
229 gnt_tree_draw(GntWidget *widget) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
230 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
231 GntTree *tree = GNT_TREE(widget); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
232 |
13854
a4c30c1d9de8
[gaim-migrate @ 16313]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13853
diff
changeset
|
233 scrollok(widget->window, TRUE); |
a4c30c1d9de8
[gaim-migrate @ 16313]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13853
diff
changeset
|
234 wsetscrreg(widget->window, 0, widget->priv.height - 1); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
235 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
236 redraw_tree(tree); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
237 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
238 DEBUG; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
239 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
240 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
241 static void |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
242 gnt_tree_size_request(GntWidget *widget) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
243 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
244 if (widget->priv.height == 0) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
245 widget->priv.height = 10; /* XXX: Why?! */ |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
246 if (widget->priv.width == 0) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
247 widget->priv.width = 20; /* YYY: 'cuz ... */ |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
248 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
249 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
250 static void |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
251 gnt_tree_map(GntWidget *widget) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
252 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
253 if (widget->priv.width == 0 || widget->priv.height == 0) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
254 gnt_widget_size_request(widget); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
255 DEBUG; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
256 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
257 |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
258 static void |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
259 tree_selection_changed(GntTree *tree, GntTreeRow *old, GntTreeRow *current) |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
260 { |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
261 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
|
262 } |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
263 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
264 static GntTreeRow * |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
265 get_nth_row(GntTree *tree, int n) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
266 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
267 gpointer key = g_list_nth_data(tree->list, n); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
268 return g_hash_table_lookup(tree->hash, key); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
269 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
270 |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
271 static gboolean |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
272 gnt_tree_key_pressed(GntWidget *widget, const char *text) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
273 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
274 GntTree *tree = GNT_TREE(widget); |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
275 GntTreeRow *old = tree->current; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
276 GntTreeRow *row; |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
277 |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
278 if (text[0] == 27) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
279 { |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
280 int dist; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
281 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
|
282 { |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
283 tree->current = row; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
284 if ((dist = get_distance(tree->current, tree->bottom)) < 0) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
285 gnt_tree_scroll(tree, -dist); |
13853
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
286 else |
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
287 redraw_tree(tree); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
288 } |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
289 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
|
290 { |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
291 tree->current = row; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
292 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
293 if ((dist = get_distance(tree->current, tree->top)) > 0) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
294 gnt_tree_scroll(tree, -dist); |
13853
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
295 else |
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
296 redraw_tree(tree); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
297 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
298 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
299 else if (text[0] == '\r') |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
300 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
301 gnt_widget_activate(widget); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
302 } |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
303 else if (text[0] == ' ' && text[1] == 0) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
304 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
305 /* Space pressed */ |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
306 GntTreeRow *row = tree->current; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
307 if (row && row->child) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
308 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
309 row->collapsed = !row->collapsed; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
310 redraw_tree(tree); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
311 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
312 } |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
313 |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
314 if (old != tree->current) |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
315 tree_selection_changed(tree, old, tree->current); |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
316 |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
317 return FALSE; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
318 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
319 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
320 static void |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
321 gnt_tree_destroy(GntWidget *widget) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
322 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
323 GntTree *tree = GNT_TREE(widget); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
324 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
325 g_hash_table_destroy(tree->hash); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
326 g_list_free(tree->list); |
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 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
329 static void |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
330 gnt_tree_class_init(GntTreeClass *klass) |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
331 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
332 parent_class = GNT_WIDGET_CLASS(klass); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
333 parent_class->destroy = gnt_tree_destroy; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
334 parent_class->draw = gnt_tree_draw; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
335 parent_class->map = gnt_tree_map; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
336 parent_class->size_request = gnt_tree_size_request; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
337 parent_class->key_pressed = gnt_tree_key_pressed; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
338 |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
339 signals[SIG_SELECTION_CHANGED] = |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
340 g_signal_new("selection-changed", |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
341 G_TYPE_FROM_CLASS(klass), |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
342 G_SIGNAL_RUN_LAST, |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
343 G_STRUCT_OFFSET(GntTreeClass, selection_changed), |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
344 NULL, NULL, |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
345 gnt_closure_marshal_VOID__POINTER_POINTER, |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
346 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
|
347 signals[SIG_SCROLLED] = |
d78ab363e02d
[gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13864
diff
changeset
|
348 g_signal_new("scrolled", |
d78ab363e02d
[gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13864
diff
changeset
|
349 G_TYPE_FROM_CLASS(klass), |
d78ab363e02d
[gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13864
diff
changeset
|
350 G_SIGNAL_RUN_LAST, |
d78ab363e02d
[gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13864
diff
changeset
|
351 0, |
d78ab363e02d
[gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13864
diff
changeset
|
352 NULL, NULL, |
d78ab363e02d
[gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13864
diff
changeset
|
353 g_cclosure_marshal_VOID__INT, |
d78ab363e02d
[gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13864
diff
changeset
|
354 G_TYPE_NONE, 1, G_TYPE_INT); |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
355 |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
356 DEBUG; |
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 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
359 static void |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
360 gnt_tree_init(GTypeInstance *instance, gpointer class) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
361 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
362 DEBUG; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
363 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
364 |
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 * GntTree API |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
367 *****************************************************************************/ |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
368 GType |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
369 gnt_tree_get_gtype(void) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
370 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
371 static GType type = 0; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
372 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
373 if(type == 0) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
374 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
375 static const GTypeInfo info = { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
376 sizeof(GntTreeClass), |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
377 NULL, /* base_init */ |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
378 NULL, /* base_finalize */ |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
379 (GClassInitFunc)gnt_tree_class_init, |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
380 NULL, /* class_finalize */ |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
381 NULL, /* class_data */ |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
382 sizeof(GntTree), |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
383 0, /* n_preallocs */ |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
384 gnt_tree_init, /* instance_init */ |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
385 }; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
386 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
387 type = g_type_register_static(GNT_TYPE_WIDGET, |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
388 "GntTree", |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
389 &info, 0); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
390 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
391 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
392 return type; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
393 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
394 |
13858
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
395 static void |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
396 free_tree_row(gpointer data) |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
397 { |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
398 GntTreeRow *row = data; |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
399 |
13861
55fb5cd9bac9
[gaim-migrate @ 16322]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13860
diff
changeset
|
400 if (!row) |
55fb5cd9bac9
[gaim-migrate @ 16322]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13860
diff
changeset
|
401 return; |
55fb5cd9bac9
[gaim-migrate @ 16322]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13860
diff
changeset
|
402 |
13858
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
403 g_free(row->text); |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
404 g_free(row); |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
405 } |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
406 |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
407 GntWidget *gnt_tree_new() |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
408 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
409 GntWidget *widget = g_object_new(GNT_TYPE_TREE, NULL); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
410 GntTree *tree = GNT_TREE(widget); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
411 |
13858
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
412 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
|
413 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW); |
13856
3cdd05b9830a
[gaim-migrate @ 16315]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13855
diff
changeset
|
414 gnt_widget_set_take_focus(widget, TRUE); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
415 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
416 return widget; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
417 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
418 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
419 void gnt_tree_set_visible_rows(GntTree *tree, int rows) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
420 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
421 GntWidget *widget = GNT_WIDGET(tree); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
422 widget->priv.height = rows; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
423 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
424 widget->priv.height += 2; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
425 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
426 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
427 int gnt_tree_get_visible_rows(GntTree *tree) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
428 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
429 GntWidget *widget = GNT_WIDGET(tree); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
430 int ret = widget->priv.height; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
431 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
|
432 ret -= 2; |
9d66969a2e32
[gaim-migrate @ 16369]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13882
diff
changeset
|
433 return ret; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
434 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
435 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
436 void gnt_tree_scroll(GntTree *tree, int count) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
437 { |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
438 GntTreeRow *row; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
439 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
440 if (count < 0) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
441 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
442 if (get_root_distance(tree->top) == 0) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
443 return; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
444 row = get_prev_n(tree->top, -count); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
445 if (row == NULL) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
446 row = tree->root; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
447 tree->top = row; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
448 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
449 else |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
450 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
451 get_next_n_opt(tree->bottom, count, &count); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
452 tree->top = get_next_n(tree->top, count); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
453 } |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
454 |
13853
bbf0470cb348
[gaim-migrate @ 16312]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13851
diff
changeset
|
455 redraw_tree(tree); |
13865
d78ab363e02d
[gaim-migrate @ 16331]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13864
diff
changeset
|
456 g_signal_emit(tree, signals[SIG_SCROLLED], 0, count); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
457 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
458 |
13858
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
459 static int |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
460 find_depth(GntTreeRow *row) |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
461 { |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
462 int dep = -1; |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
463 |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
464 while (row) |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
465 { |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
466 dep++; |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
467 row = row->parent; |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
468 } |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
469 |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
470 return dep; |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
471 } |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
472 |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
473 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
|
474 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
475 GntTreeRow *row = g_new0(GntTreeRow, 1), *pr = NULL; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
476 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
477 g_hash_table_replace(tree->hash, key, row); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
478 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
479 if (tree->root == NULL) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
480 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
481 tree->root = row; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
482 tree->list = g_list_prepend(tree->list, key); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
483 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
484 else |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
485 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
486 int position; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
487 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
488 if (bigbro) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
489 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
490 pr = g_hash_table_lookup(tree->hash, bigbro); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
491 if (pr) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
492 { |
13857
d341b5ac1a78
[gaim-migrate @ 16316]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13856
diff
changeset
|
493 if (pr->next) pr->next->prev = row; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
494 row->next = pr->next; |
13857
d341b5ac1a78
[gaim-migrate @ 16316]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13856
diff
changeset
|
495 row->prev = pr; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
496 pr->next = row; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
497 row->parent = pr->parent; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
498 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
499 position = g_list_index(tree->list, bigbro); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
500 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
501 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
502 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
503 if (pr == NULL && parent) |
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 pr = g_hash_table_lookup(tree->hash, parent); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
506 if (pr) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
507 { |
13857
d341b5ac1a78
[gaim-migrate @ 16316]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13856
diff
changeset
|
508 if (pr->child) pr->child->prev = row; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
509 row->next = pr->child; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
510 pr->child = row; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
511 row->parent = pr; |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
512 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
513 position = g_list_index(tree->list, parent); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
514 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
515 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
516 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
517 if (pr == NULL) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
518 { |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
519 GntTreeRow *r = tree->root; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
520 while (r->next) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
521 r = r->next; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
522 r->next = row; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
523 row->prev = r; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
524 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
525 tree->list = g_list_append(tree->list, key); |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
526 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
527 else |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
528 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
529 tree->list = g_list_insert(tree->list, key, position + 1); |
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 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
532 |
13858
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
533 row->key = key; |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
534 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
|
535 row->data = NULL; |
aa1c97f5e6eb
[gaim-migrate @ 16317]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13857
diff
changeset
|
536 |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
537 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
|
538 redraw_tree(tree); |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
539 |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
540 return row; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
541 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
542 |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
543 gpointer gnt_tree_get_selection_data(GntTree *tree) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
544 { |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
545 if (tree->current) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
546 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
|
547 return NULL; |
13850
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 |
13857
d341b5ac1a78
[gaim-migrate @ 16316]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13856
diff
changeset
|
550 /* 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
|
551 void gnt_tree_remove(GntTree *tree, gpointer key) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
552 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
553 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
554 if (row) |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
555 { |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
556 gboolean redraw = FALSE; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
557 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
558 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
|
559 redraw = TRUE; |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
560 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
561 /* Update root/top/current/bottom if necessary */ |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
562 if (tree->root == row) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
563 tree->root = get_next(row); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
564 if (tree->top == row) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
565 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
566 if (tree->top != tree->root) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
567 tree->top = get_prev(row); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
568 else |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
569 tree->top = get_next(row); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
570 if (tree->current == row) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
571 tree->current = tree->top; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
572 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
573 else if (tree->current == row) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
574 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
575 if (tree->current != tree->root) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
576 tree->current = get_prev(row); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
577 else |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
578 tree->current = get_next(row); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
579 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
580 else if (tree->bottom == row) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
581 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
582 tree->bottom = get_prev(row); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
583 } |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
584 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
585 /* Fix the links */ |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
586 if (row->next) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
587 row->next->prev = row->prev; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
588 if (row->parent && row->parent->child == row) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
589 row->parent->child = row->next; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
590 if (row->prev) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
591 row->prev->next = row->next; |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
592 |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
593 g_hash_table_remove(tree->hash, key); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
594 tree->list = g_list_remove(tree->list, key); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
595 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
596 if (redraw) |
13850
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
597 { |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
598 redraw_tree(tree); |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
599 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
600 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
601 } |
0e1e59770cb0
[gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
602 |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
603 int gnt_tree_get_selection_visible_line(GntTree *tree) |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
604 { |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
605 return get_distance(tree->top, tree->current) + |
13860
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
606 !!(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
|
607 } |
c1e3f7c75c3f
[gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13858
diff
changeset
|
608 |
13864
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
609 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
|
610 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
611 GntTreeRow *row = g_hash_table_lookup(tree->hash, key); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
612 if (row) |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
613 { |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
614 g_free(row->text); |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
615 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
|
616 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
617 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
|
618 redraw_tree(tree); |
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 } |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
621 |
c7d84d4c5afa
[gaim-migrate @ 16328]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13861
diff
changeset
|
622 |