Mercurial > pidgin
annotate finch/libgnt/gntbox.c @ 27782:931bb24c28ab
Fix #9660. Reconnect, in case of error 52.
author | Sulabh Mahajan <sulabh@soc.pidgin.im> |
---|---|
date | Sat, 01 Aug 2009 08:50:19 +0000 |
parents | c67d43408daa |
children | 65e8c39cc5f6 |
rev | line source |
---|---|
18049
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
1 /** |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
3 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
6 * source distribution. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
7 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
11 * (at your option) any later version. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
12 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
16 * GNU General Public License for more details. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
17 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
19681
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18538
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
18049
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
21 */ |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
22 |
15817 | 23 #include "gntbox.h" |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
24 #include "gntstyle.h" |
15817 | 25 #include "gntutils.h" |
26 | |
27 #include <string.h> | |
28 | |
29 enum | |
30 { | |
21261
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
31 PROP_0, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
32 PROP_VERTICAL, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
33 PROP_HOMO /* ... */ |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
34 }; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
35 |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
36 enum |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
37 { |
15817 | 38 SIGS = 1, |
39 }; | |
40 | |
41 static GntWidgetClass *parent_class = NULL; | |
42 | |
43 static GntWidget * find_focusable_widget(GntBox *box); | |
44 | |
45 static void | |
46 add_to_focus(gpointer value, gpointer data) | |
47 { | |
48 GntBox *box = GNT_BOX(data); | |
49 GntWidget *w = GNT_WIDGET(value); | |
50 | |
51 if (GNT_IS_BOX(w)) | |
52 g_list_foreach(GNT_BOX(w)->list, add_to_focus, box); | |
53 else if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_CAN_TAKE_FOCUS)) | |
54 box->focus = g_list_append(box->focus, w); | |
55 } | |
56 | |
57 static void | |
58 get_title_thingies(GntBox *box, char *title, int *p, int *r) | |
59 { | |
60 GntWidget *widget = GNT_WIDGET(box); | |
61 int len; | |
62 char *end = (char*)gnt_util_onscreen_width_to_pointer(title, widget->priv.width - 4, &len); | |
63 | |
64 if (p) | |
65 *p = (widget->priv.width - len) / 2; | |
66 if (r) | |
67 *r = (widget->priv.width + len) / 2; | |
68 *end = '\0'; | |
69 } | |
70 | |
71 static void | |
72 gnt_box_draw(GntWidget *widget) | |
73 { | |
74 GntBox *box = GNT_BOX(widget); | |
75 | |
76 if (box->focus == NULL && widget->parent == NULL) | |
77 g_list_foreach(box->list, add_to_focus, box); | |
78 | |
79 g_list_foreach(box->list, (GFunc)gnt_widget_draw, NULL); | |
80 | |
81 if (box->title && !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
82 { | |
83 int pos, right; | |
84 char *title = g_strdup(box->title); | |
26439
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
25322
diff
changeset
|
85 |
15817 | 86 get_title_thingies(box, title, &pos, &right); |
87 | |
88 if (gnt_widget_has_focus(widget)) | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
89 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_TITLE)); |
15817 | 90 else |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
91 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_TITLE_D)); |
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
92 mvwaddch(widget->window, 0, pos-1, ACS_RTEE | gnt_color_pair(GNT_COLOR_NORMAL)); |
15817 | 93 mvwaddstr(widget->window, 0, pos, title); |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
94 mvwaddch(widget->window, 0, right, ACS_LTEE | gnt_color_pair(GNT_COLOR_NORMAL)); |
15817 | 95 g_free(title); |
96 } | |
26439
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
25322
diff
changeset
|
97 |
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
25322
diff
changeset
|
98 gnt_box_sync_children(box); |
15817 | 99 } |
100 | |
101 static void | |
102 reposition_children(GntWidget *widget) | |
103 { | |
104 GList *iter; | |
105 GntBox *box = GNT_BOX(widget); | |
106 int w, h, curx, cury, max; | |
107 gboolean has_border = FALSE; | |
108 | |
109 w = h = 0; | |
110 max = 0; | |
111 curx = widget->priv.x; | |
112 cury = widget->priv.y; | |
113 if (!(GNT_WIDGET_FLAGS(widget) & GNT_WIDGET_NO_BORDER)) | |
114 { | |
115 has_border = TRUE; | |
116 curx += 1; | |
117 cury += 1; | |
118 } | |
119 | |
120 for (iter = box->list; iter; iter = iter->next) | |
121 { | |
122 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(iter->data), GNT_WIDGET_INVISIBLE)) | |
123 continue; | |
124 gnt_widget_set_position(GNT_WIDGET(iter->data), curx, cury); | |
125 gnt_widget_get_size(GNT_WIDGET(iter->data), &w, &h); | |
126 if (box->vertical) | |
127 { | |
128 if (h) | |
129 { | |
130 cury += h + box->pad; | |
131 if (max < w) | |
132 max = w; | |
133 } | |
134 } | |
135 else | |
136 { | |
137 if (w) | |
138 { | |
139 curx += w + box->pad; | |
140 if (max < h) | |
141 max = h; | |
142 } | |
143 } | |
144 } | |
145 | |
146 if (has_border) | |
147 { | |
148 curx += 1; | |
149 cury += 1; | |
150 max += 2; | |
151 } | |
152 | |
153 if (box->list) | |
154 { | |
155 if (box->vertical) | |
156 cury -= box->pad; | |
157 else | |
158 curx -= box->pad; | |
159 } | |
160 | |
161 if (box->vertical) | |
162 { | |
163 widget->priv.width = max; | |
164 widget->priv.height = cury - widget->priv.y; | |
165 } | |
166 else | |
167 { | |
168 widget->priv.width = curx - widget->priv.x; | |
169 widget->priv.height = max; | |
170 } | |
171 } | |
172 | |
173 static void | |
174 gnt_box_set_position(GntWidget *widget, int x, int y) | |
175 { | |
176 GList *iter; | |
177 int changex, changey; | |
178 | |
179 changex = widget->priv.x - x; | |
180 changey = widget->priv.y - y; | |
181 | |
182 for (iter = GNT_BOX(widget)->list; iter; iter = iter->next) | |
183 { | |
184 GntWidget *w = GNT_WIDGET(iter->data); | |
185 gnt_widget_set_position(w, w->priv.x - changex, | |
186 w->priv.y - changey); | |
187 } | |
188 } | |
189 | |
190 static void | |
191 gnt_box_size_request(GntWidget *widget) | |
192 { | |
193 GntBox *box = GNT_BOX(widget); | |
194 GList *iter; | |
195 int maxw = 0, maxh = 0; | |
196 | |
197 g_list_foreach(box->list, (GFunc)gnt_widget_size_request, NULL); | |
198 | |
199 for (iter = box->list; iter; iter = iter->next) | |
200 { | |
201 int w, h; | |
202 gnt_widget_get_size(GNT_WIDGET(iter->data), &w, &h); | |
203 if (maxh < h) | |
204 maxh = h; | |
205 if (maxw < w) | |
206 maxw = w; | |
207 } | |
208 | |
209 for (iter = box->list; iter; iter = iter->next) | |
210 { | |
211 int w, h; | |
212 GntWidget *wid = GNT_WIDGET(iter->data); | |
213 | |
214 gnt_widget_get_size(wid, &w, &h); | |
215 | |
216 if (box->homogeneous) | |
217 { | |
218 if (box->vertical) | |
219 h = maxh; | |
220 else | |
221 w = maxw; | |
222 } | |
223 if (box->fill) | |
224 { | |
225 if (box->vertical) | |
226 w = maxw; | |
227 else | |
228 h = maxh; | |
229 } | |
230 | |
18538
2e11d73c4ff1
Properly set the initial size of widgets.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
231 gnt_widget_confirm_size(wid, w, h); |
15817 | 232 gnt_widget_set_size(wid, w, h); |
233 } | |
234 | |
235 reposition_children(widget); | |
236 } | |
237 | |
238 static void | |
239 gnt_box_map(GntWidget *widget) | |
240 { | |
241 if (widget->priv.width == 0 || widget->priv.height == 0) | |
242 { | |
243 gnt_widget_size_request(widget); | |
244 find_focusable_widget(GNT_BOX(widget)); | |
245 } | |
246 GNTDEBUG; | |
247 } | |
248 | |
249 /* Ensures that the current widget can take focus */ | |
250 static GntWidget * | |
251 find_focusable_widget(GntBox *box) | |
252 { | |
253 /* XXX: Make sure the widget is visible? */ | |
254 if (box->focus == NULL && GNT_WIDGET(box)->parent == NULL) | |
255 g_list_foreach(box->list, add_to_focus, box); | |
256 | |
257 if (box->active == NULL && box->focus) | |
258 box->active = box->focus->data; | |
259 | |
260 return box->active; | |
261 } | |
262 | |
263 static void | |
264 find_next_focus(GntBox *box) | |
265 { | |
266 gpointer last = box->active; | |
267 do | |
268 { | |
269 GList *iter = g_list_find(box->focus, box->active); | |
270 if (iter && iter->next) | |
271 box->active = iter->next->data; | |
272 else if (box->focus) | |
273 box->active = box->focus->data; | |
22999
d03b32530854
Make sure a widget can receive focus. This is used when some widgets need
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21626
diff
changeset
|
274 if (!GNT_WIDGET_IS_FLAG_SET(box->active, GNT_WIDGET_INVISIBLE) && |
d03b32530854
Make sure a widget can receive focus. This is used when some widgets need
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21626
diff
changeset
|
275 GNT_WIDGET_IS_FLAG_SET(box->active, GNT_WIDGET_CAN_TAKE_FOCUS)) |
15817 | 276 break; |
277 } while (box->active != last); | |
278 } | |
279 | |
280 static void | |
281 find_prev_focus(GntBox *box) | |
282 { | |
283 gpointer last = box->active; | |
284 | |
285 if (!box->focus) | |
286 return; | |
287 | |
288 do | |
289 { | |
290 GList *iter = g_list_find(box->focus, box->active); | |
291 if (!iter) | |
292 box->active = box->focus->data; | |
293 else if (!iter->prev) | |
294 box->active = g_list_last(box->focus)->data; | |
295 else | |
296 box->active = iter->prev->data; | |
297 if (!GNT_WIDGET_IS_FLAG_SET(box->active, GNT_WIDGET_INVISIBLE)) | |
298 break; | |
299 } while (box->active != last); | |
300 } | |
301 | |
302 static gboolean | |
303 gnt_box_key_pressed(GntWidget *widget, const char *text) | |
304 { | |
305 GntBox *box = GNT_BOX(widget); | |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
306 gboolean ret; |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
307 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
308 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_DISABLE_ACTIONS)) |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
309 return FALSE; |
15817 | 310 |
311 if (box->active == NULL && !find_focusable_widget(box)) | |
312 return FALSE; | |
313 | |
314 if (gnt_widget_key_pressed(box->active, text)) | |
315 return TRUE; | |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
316 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
317 /* This dance is necessary to make sure that the child widgets get a chance |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
318 to trigger their bindings first */ |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
319 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_DISABLE_ACTIONS); |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
320 ret = gnt_widget_key_pressed(widget, text); |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
321 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_DISABLE_ACTIONS); |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
322 return ret; |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
323 } |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
324 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
325 static gboolean |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
326 box_focus_change(GntBox *box, gboolean next) |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
327 { |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
328 GntWidget *now; |
15817 | 329 now = box->active; |
330 | |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
331 if (next) { |
15817 | 332 find_next_focus(box); |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
333 } else { |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
334 find_prev_focus(box); |
15817 | 335 } |
336 | |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
337 if (now && now != box->active) { |
15817 | 338 gnt_widget_set_focus(now, FALSE); |
339 gnt_widget_set_focus(box->active, TRUE); | |
340 return TRUE; | |
341 } | |
342 | |
343 return FALSE; | |
344 } | |
345 | |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
346 static gboolean |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
347 action_focus_next(GntBindable *bindable, GList *null) |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
348 { |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
349 return box_focus_change(GNT_BOX(bindable), TRUE); |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
350 } |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
351 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
352 static gboolean |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
353 action_focus_prev(GntBindable *bindable, GList *null) |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
354 { |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
355 return box_focus_change(GNT_BOX(bindable), FALSE); |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
356 } |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
357 |
15817 | 358 static void |
359 gnt_box_lost_focus(GntWidget *widget) | |
360 { | |
361 GntWidget *w = GNT_BOX(widget)->active; | |
362 if (w) | |
363 gnt_widget_set_focus(w, FALSE); | |
364 gnt_widget_draw(widget); | |
365 } | |
366 | |
367 static void | |
368 gnt_box_gained_focus(GntWidget *widget) | |
369 { | |
370 GntWidget *w = GNT_BOX(widget)->active; | |
371 if (w) | |
372 gnt_widget_set_focus(w, TRUE); | |
373 gnt_widget_draw(widget); | |
374 } | |
375 | |
376 static void | |
377 gnt_box_destroy(GntWidget *w) | |
378 { | |
379 GntBox *box = GNT_BOX(w); | |
380 | |
381 gnt_box_remove_all(box); | |
382 gnt_screen_release(w); | |
383 } | |
384 | |
385 static void | |
386 gnt_box_expose(GntWidget *widget, int x, int y, int width, int height) | |
387 { | |
388 WINDOW *win = newwin(height, width, widget->priv.y + y, widget->priv.x + x); | |
389 copywin(widget->window, win, y, x, 0, 0, height - 1, width - 1, FALSE); | |
390 wrefresh(win); | |
391 delwin(win); | |
392 } | |
393 | |
394 static gboolean | |
395 gnt_box_confirm_size(GntWidget *widget, int width, int height) | |
396 { | |
397 GList *iter; | |
398 GntBox *box = GNT_BOX(widget); | |
399 int wchange, hchange; | |
400 | |
401 if (!box->list) | |
402 return TRUE; | |
403 | |
404 wchange = widget->priv.width - width; | |
405 hchange = widget->priv.height - height; | |
406 | |
407 if (wchange == 0 && hchange == 0) | |
408 return TRUE; /* Quit playing games */ | |
409 | |
410 /* XXX: Right now, I am trying to just apply all the changes to | |
411 * just one widget. It should be possible to distribute the | |
412 * changes to all the widgets in the box. */ | |
413 for (iter = box->list; iter; iter = iter->next) | |
414 { | |
415 GntWidget *wid = iter->data; | |
416 int w, h; | |
417 | |
418 gnt_widget_get_size(wid, &w, &h); | |
419 | |
420 if (gnt_widget_confirm_size(wid, w - wchange, h - hchange)) | |
421 { | |
422 GList *i; | |
423 | |
424 for (i = box->list; i; i = i->next) | |
425 { | |
426 int tw, th; | |
427 if (i == iter) continue; | |
428 gnt_widget_get_size(GNT_WIDGET(i->data), &tw, &th); | |
429 if (box->vertical) | |
430 { | |
15945
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
431 if (!gnt_widget_confirm_size(i->data, tw - wchange, th)) { |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
432 /* If we are decreasing the size and the widget is going |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
433 * to be too large to fit into the box, then do not allow |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
434 * resizing. */ |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
435 if (wchange > 0 && tw >= widget->priv.width) |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
436 return FALSE; |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
437 } |
15817 | 438 } |
439 else | |
440 { | |
15945
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
441 if (!gnt_widget_confirm_size(i->data, tw, th - hchange)) { |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
442 if (hchange > 0 && th >= widget->priv.height) |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
443 return FALSE; |
15817 | 444 return FALSE; |
15945
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
445 } |
15817 | 446 } |
447 } | |
448 #if 0 | |
449 gnt_widget_set_size(wid, w - wchange, h - hchange); | |
450 if (box->vertical) | |
451 hchange = 0; | |
452 else | |
453 wchange = 0; | |
454 | |
455 for (i = box->list; i; i = i->next) | |
456 { | |
457 int tw, th; | |
458 if (i == iter) continue; | |
459 gnt_widget_get_size(GNT_WIDGET(i->data), &tw, &th); | |
460 gnt_widget_set_size(i->data, tw - wchange, th - hchange); | |
461 } | |
462 #endif | |
463 g_object_set_data(G_OBJECT(box), "size-queued", wid); | |
464 return TRUE; | |
465 } | |
466 } | |
467 | |
468 return FALSE; | |
469 } | |
470 | |
471 static void | |
472 gnt_box_size_changed(GntWidget *widget, int oldw, int oldh) | |
473 { | |
474 int wchange, hchange; | |
475 GList *i; | |
476 GntBox *box = GNT_BOX(widget); | |
477 GntWidget *wid; | |
478 int tw, th; | |
479 | |
480 wchange = widget->priv.width - oldw; | |
481 hchange = widget->priv.height - oldh; | |
482 | |
483 wid = g_object_get_data(G_OBJECT(box), "size-queued"); | |
484 if (wid) | |
485 { | |
486 gnt_widget_get_size(wid, &tw, &th); | |
487 gnt_widget_set_size(wid, tw + wchange, th + hchange); | |
488 g_object_set_data(G_OBJECT(box), "size-queued", NULL); | |
489 } | |
490 | |
491 if (box->vertical) | |
492 hchange = 0; | |
493 else | |
494 wchange = 0; | |
495 | |
496 for (i = box->list; i; i = i->next) | |
497 { | |
498 if (wid != i->data) | |
499 { | |
500 gnt_widget_get_size(GNT_WIDGET(i->data), &tw, &th); | |
501 gnt_widget_set_size(i->data, tw + wchange, th + hchange); | |
502 } | |
503 } | |
504 | |
505 reposition_children(widget); | |
506 } | |
507 | |
508 static gboolean | |
509 gnt_box_clicked(GntWidget *widget, GntMouseEvent event, int cx, int cy) | |
510 { | |
511 GList *iter; | |
512 for (iter = GNT_BOX(widget)->list; iter; iter = iter->next) { | |
513 int x, y, w, h; | |
514 GntWidget *wid = iter->data; | |
515 | |
516 gnt_widget_get_position(wid, &x, &y); | |
517 gnt_widget_get_size(wid, &w, &h); | |
518 | |
519 if (cx >= x && cx < x + w && cy >= y && cy < y + h) { | |
520 if (event <= GNT_MIDDLE_MOUSE_DOWN && | |
521 GNT_WIDGET_IS_FLAG_SET(wid, GNT_WIDGET_CAN_TAKE_FOCUS)) { | |
522 while (widget->parent) | |
523 widget = widget->parent; | |
524 gnt_box_give_focus_to_child(GNT_BOX(widget), wid); | |
525 } | |
526 return gnt_widget_clicked(wid, event, cx, cy); | |
527 } | |
528 } | |
529 return FALSE; | |
530 } | |
531 | |
532 static void | |
21261
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
533 gnt_box_set_property(GObject *obj, guint prop_id, const GValue *value, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
534 GParamSpec *spec) |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
535 { |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
536 GntBox *box = GNT_BOX(obj); |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
537 switch (prop_id) { |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
538 case PROP_VERTICAL: |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
539 box->vertical = g_value_get_boolean(value); |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
540 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
541 case PROP_HOMO: |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
542 box->homogeneous = g_value_get_boolean(value); |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
543 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
544 default: |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
545 g_return_if_reached(); |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
546 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
547 } |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
548 } |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
549 |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
550 static void |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
551 gnt_box_get_property(GObject *obj, guint prop_id, GValue *value, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
552 GParamSpec *spec) |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
553 { |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
554 GntBox *box = GNT_BOX(obj); |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
555 switch (prop_id) { |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
556 case PROP_VERTICAL: |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
557 g_value_set_boolean(value, box->vertical); |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
558 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
559 case PROP_HOMO: |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
560 g_value_set_boolean(value, box->homogeneous); |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
561 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
562 default: |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
563 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
564 } |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
565 } |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
566 |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
567 static void |
15817 | 568 gnt_box_class_init(GntBoxClass *klass) |
569 { | |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
570 GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass); |
21261
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
571 GObjectClass *gclass = G_OBJECT_CLASS(klass); |
15817 | 572 parent_class = GNT_WIDGET_CLASS(klass); |
573 parent_class->destroy = gnt_box_destroy; | |
574 parent_class->draw = gnt_box_draw; | |
575 parent_class->expose = gnt_box_expose; | |
576 parent_class->map = gnt_box_map; | |
577 parent_class->size_request = gnt_box_size_request; | |
578 parent_class->set_position = gnt_box_set_position; | |
579 parent_class->key_pressed = gnt_box_key_pressed; | |
580 parent_class->clicked = gnt_box_clicked; | |
581 parent_class->lost_focus = gnt_box_lost_focus; | |
582 parent_class->gained_focus = gnt_box_gained_focus; | |
583 parent_class->confirm_size = gnt_box_confirm_size; | |
584 parent_class->size_changed = gnt_box_size_changed; | |
585 | |
21261
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
586 gclass->set_property = gnt_box_set_property; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
587 gclass->get_property = gnt_box_get_property; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
588 g_object_class_install_property(gclass, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
589 PROP_VERTICAL, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
590 g_param_spec_boolean("vertical", "Vertical", |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
591 "Whether the child widgets in the box should be stacked vertically.", |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
592 TRUE, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
593 G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
594 ) |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
595 ); |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
596 g_object_class_install_property(gclass, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
597 PROP_HOMO, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
598 g_param_spec_boolean("homogeneous", "Homogeneous", |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
599 "Whether the child widgets in the box should have the same size.", |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
600 TRUE, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
601 G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
602 ) |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
603 ); |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
604 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
605 gnt_bindable_class_register_action(bindable, "focus-next", action_focus_next, |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
606 "\t", NULL); |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
607 gnt_bindable_register_binding(bindable, "focus-next", GNT_KEY_RIGHT, NULL); |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
608 gnt_bindable_class_register_action(bindable, "focus-prev", action_focus_prev, |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
609 GNT_KEY_BACK_TAB, NULL); |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
610 gnt_bindable_register_binding(bindable, "focus-prev", GNT_KEY_LEFT, NULL); |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
611 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
612 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), bindable); |
15817 | 613 } |
614 | |
615 static void | |
616 gnt_box_init(GTypeInstance *instance, gpointer class) | |
617 { | |
618 GntWidget *widget = GNT_WIDGET(instance); | |
619 GntBox *box = GNT_BOX(widget); | |
620 /* Initially make both the height and width resizable. | |
621 * Update the flags as necessary when widgets are added to it. */ | |
622 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y); | |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
623 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS | GNT_WIDGET_DISABLE_ACTIONS); |
15817 | 624 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); |
625 box->pad = 1; | |
626 box->fill = TRUE; | |
627 GNTDEBUG; | |
628 } | |
629 | |
630 /****************************************************************************** | |
631 * GntBox API | |
632 *****************************************************************************/ | |
633 GType | |
634 gnt_box_get_gtype(void) | |
635 { | |
636 static GType type = 0; | |
637 | |
638 if(type == 0) | |
639 { | |
640 static const GTypeInfo info = { | |
641 sizeof(GntBoxClass), | |
642 NULL, /* base_init */ | |
643 NULL, /* base_finalize */ | |
644 (GClassInitFunc)gnt_box_class_init, | |
645 NULL, /* class_finalize */ | |
646 NULL, /* class_data */ | |
647 sizeof(GntBox), | |
648 0, /* n_preallocs */ | |
649 gnt_box_init, /* instance_init */ | |
650 NULL /* value_table */ | |
651 }; | |
652 | |
653 type = g_type_register_static(GNT_TYPE_WIDGET, | |
654 "GntBox", | |
655 &info, 0); | |
656 } | |
657 | |
658 return type; | |
659 } | |
660 | |
661 GntWidget *gnt_box_new(gboolean homo, gboolean vert) | |
662 { | |
663 GntWidget *widget = g_object_new(GNT_TYPE_BOX, NULL); | |
664 GntBox *box = GNT_BOX(widget); | |
665 | |
666 box->homogeneous = homo; | |
667 box->vertical = vert; | |
668 box->alignment = vert ? GNT_ALIGN_LEFT : GNT_ALIGN_MID; | |
669 | |
670 return widget; | |
671 } | |
672 | |
673 void gnt_box_add_widget(GntBox *b, GntWidget *widget) | |
674 { | |
675 b->list = g_list_append(b->list, widget); | |
676 widget->parent = GNT_WIDGET(b); | |
677 } | |
678 | |
679 void gnt_box_set_title(GntBox *b, const char *title) | |
680 { | |
681 char *prev = b->title; | |
682 GntWidget *w = GNT_WIDGET(b); | |
683 b->title = g_strdup(title); | |
684 if (w->window && !GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_NO_BORDER)) { | |
685 /* Erase the old title */ | |
686 int pos, right; | |
687 get_title_thingies(b, prev, &pos, &right); | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
688 mvwhline(w->window, 0, pos - 1, ACS_HLINE | gnt_color_pair(GNT_COLOR_NORMAL), |
15817 | 689 right - pos + 2); |
690 g_free(prev); | |
691 } | |
692 } | |
693 | |
694 void gnt_box_set_pad(GntBox *box, int pad) | |
695 { | |
696 box->pad = pad; | |
697 /* XXX: Perhaps redraw if already showing? */ | |
698 } | |
699 | |
700 void gnt_box_set_toplevel(GntBox *box, gboolean set) | |
701 { | |
702 GntWidget *widget = GNT_WIDGET(box); | |
703 if (set) | |
704 { | |
705 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); | |
706 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS); | |
707 } | |
708 else | |
709 { | |
710 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); | |
711 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS); | |
712 } | |
713 } | |
714 | |
715 void gnt_box_sync_children(GntBox *box) | |
716 { | |
717 GList *iter; | |
718 GntWidget *widget = GNT_WIDGET(box); | |
719 int pos = 1; | |
720 | |
721 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
722 pos = 0; | |
723 | |
26439
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
25322
diff
changeset
|
724 if (!box->active) |
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
25322
diff
changeset
|
725 find_focusable_widget(box); |
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
25322
diff
changeset
|
726 |
15817 | 727 for (iter = box->list; iter; iter = iter->next) |
728 { | |
729 GntWidget *w = GNT_WIDGET(iter->data); | |
730 int height, width; | |
731 int x, y; | |
732 | |
733 if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_INVISIBLE)) | |
734 continue; | |
735 | |
736 if (GNT_IS_BOX(w)) | |
737 gnt_box_sync_children(GNT_BOX(w)); | |
738 | |
739 gnt_widget_get_size(w, &width, &height); | |
740 | |
741 x = w->priv.x - widget->priv.x; | |
742 y = w->priv.y - widget->priv.y; | |
743 | |
744 if (box->vertical) | |
745 { | |
746 x = pos; | |
747 if (box->alignment == GNT_ALIGN_RIGHT) | |
748 x += widget->priv.width - width; | |
749 else if (box->alignment == GNT_ALIGN_MID) | |
750 x += (widget->priv.width - width)/2; | |
751 if (x + width > widget->priv.width - pos) | |
752 x -= x + width - (widget->priv.width - pos); | |
753 } | |
754 else | |
755 { | |
756 y = pos; | |
757 if (box->alignment == GNT_ALIGN_BOTTOM) | |
758 y += widget->priv.height - height; | |
759 else if (box->alignment == GNT_ALIGN_MID) | |
760 y += (widget->priv.height - height)/2; | |
761 if (y + height >= widget->priv.height - pos) | |
762 y = widget->priv.height - height - pos; | |
763 } | |
764 | |
765 copywin(w->window, widget->window, 0, 0, | |
766 y, x, y + height - 1, x + width - 1, FALSE); | |
767 gnt_widget_set_position(w, x + widget->priv.x, y + widget->priv.y); | |
26439
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
25322
diff
changeset
|
768 if (w == box->active) { |
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
25322
diff
changeset
|
769 wmove(widget->window, y + getcury(w->window), x + getcurx(w->window)); |
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
25322
diff
changeset
|
770 } |
15817 | 771 } |
772 } | |
773 | |
774 void gnt_box_set_alignment(GntBox *box, GntAlignment alignment) | |
775 { | |
776 box->alignment = alignment; | |
777 } | |
778 | |
779 void gnt_box_remove(GntBox *box, GntWidget *widget) | |
780 { | |
781 box->list = g_list_remove(box->list, widget); | |
782 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_CAN_TAKE_FOCUS) | |
783 && GNT_WIDGET(box)->parent == NULL && box->focus) | |
784 { | |
785 if (widget == box->active) | |
786 { | |
787 find_next_focus(box); | |
788 if (box->active == widget) /* There's only one widget */ | |
789 box->active = NULL; | |
790 } | |
791 box->focus = g_list_remove(box->focus, widget); | |
792 } | |
793 | |
794 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(box), GNT_WIDGET_MAPPED)) | |
795 gnt_widget_draw(GNT_WIDGET(box)); | |
796 } | |
797 | |
798 void gnt_box_remove_all(GntBox *box) | |
799 { | |
800 g_list_foreach(box->list, (GFunc)gnt_widget_destroy, NULL); | |
801 g_list_free(box->list); | |
802 g_list_free(box->focus); | |
803 box->list = NULL; | |
804 box->focus = NULL; | |
805 GNT_WIDGET(box)->priv.width = 0; | |
806 GNT_WIDGET(box)->priv.height = 0; | |
807 } | |
808 | |
809 void gnt_box_readjust(GntBox *box) | |
810 { | |
811 GList *iter; | |
812 GntWidget *wid; | |
813 int width, height; | |
814 | |
815 if (GNT_WIDGET(box)->parent != NULL) | |
816 return; | |
817 | |
818 for (iter = box->list; iter; iter = iter->next) | |
819 { | |
820 GntWidget *w = iter->data; | |
821 if (GNT_IS_BOX(w)) | |
822 gnt_box_readjust(GNT_BOX(w)); | |
823 else | |
824 { | |
825 GNT_WIDGET_UNSET_FLAGS(w, GNT_WIDGET_MAPPED); | |
826 w->priv.width = 0; | |
827 w->priv.height = 0; | |
828 } | |
829 } | |
830 | |
831 wid = GNT_WIDGET(box); | |
832 GNT_WIDGET_UNSET_FLAGS(wid, GNT_WIDGET_MAPPED); | |
833 wid->priv.width = 0; | |
834 wid->priv.height = 0; | |
835 | |
836 if (wid->parent == NULL) | |
837 { | |
838 g_list_free(box->focus); | |
839 box->focus = NULL; | |
840 box->active = NULL; | |
841 gnt_widget_size_request(wid); | |
842 gnt_widget_get_size(wid, &width, &height); | |
843 gnt_screen_resize_widget(wid, width, height); | |
844 find_focusable_widget(box); | |
845 } | |
846 } | |
847 | |
848 void gnt_box_set_fill(GntBox *box, gboolean fill) | |
849 { | |
850 box->fill = fill; | |
851 } | |
852 | |
853 void gnt_box_move_focus(GntBox *box, int dir) | |
854 { | |
855 GntWidget *now; | |
856 | |
857 if (box->active == NULL) | |
858 { | |
859 find_focusable_widget(box); | |
860 return; | |
861 } | |
862 | |
863 now = box->active; | |
864 | |
865 if (dir == 1) | |
866 find_next_focus(box); | |
867 else if (dir == -1) | |
868 find_prev_focus(box); | |
869 | |
870 if (now && now != box->active) | |
871 { | |
872 gnt_widget_set_focus(now, FALSE); | |
873 gnt_widget_set_focus(box->active, TRUE); | |
874 } | |
875 | |
876 if (GNT_WIDGET(box)->window) | |
877 gnt_widget_draw(GNT_WIDGET(box)); | |
878 } | |
879 | |
880 void gnt_box_give_focus_to_child(GntBox *box, GntWidget *widget) | |
881 { | |
21626
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
882 GList *find; |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
883 gpointer now; |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
884 |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
885 while (GNT_WIDGET(box)->parent) |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
886 box = GNT_BOX(GNT_WIDGET(box)->parent); |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
887 |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
888 find = g_list_find(box->focus, widget); |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
889 now = box->active; |
15817 | 890 if (find) |
891 box->active = widget; | |
892 if (now && now != box->active) | |
893 { | |
894 gnt_widget_set_focus(now, FALSE); | |
895 gnt_widget_set_focus(box->active, TRUE); | |
896 } | |
897 | |
898 if (GNT_WIDGET(box)->window) | |
899 gnt_widget_draw(GNT_WIDGET(box)); | |
900 } | |
901 |