Mercurial > pidgin.yaz
annotate finch/libgnt/gntbox.c @ 22495:2ded253bcdbb
Uninitialize the python interpreter only if gnt started it. This fixes a crash when quitting pygnt apps.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Tue, 18 Mar 2008 02:13:24 +0000 |
parents | 4c03275346a9 |
children | d03b32530854 |
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 |
19680
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 |
15818 | 23 #include "gntbox.h" |
24 #include "gntutils.h" | |
25 | |
26 #include <string.h> | |
27 | |
28 enum | |
29 { | |
21261
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
30 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
|
31 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
|
32 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
|
33 }; |
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 enum |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
36 { |
15818 | 37 SIGS = 1, |
38 }; | |
39 | |
40 static GntWidgetClass *parent_class = NULL; | |
41 | |
42 static GntWidget * find_focusable_widget(GntBox *box); | |
43 | |
44 static void | |
45 add_to_focus(gpointer value, gpointer data) | |
46 { | |
47 GntBox *box = GNT_BOX(data); | |
48 GntWidget *w = GNT_WIDGET(value); | |
49 | |
50 if (GNT_IS_BOX(w)) | |
51 g_list_foreach(GNT_BOX(w)->list, add_to_focus, box); | |
52 else if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_CAN_TAKE_FOCUS)) | |
53 box->focus = g_list_append(box->focus, w); | |
54 } | |
55 | |
56 static void | |
57 get_title_thingies(GntBox *box, char *title, int *p, int *r) | |
58 { | |
59 GntWidget *widget = GNT_WIDGET(box); | |
60 int len; | |
61 char *end = (char*)gnt_util_onscreen_width_to_pointer(title, widget->priv.width - 4, &len); | |
62 | |
63 if (p) | |
64 *p = (widget->priv.width - len) / 2; | |
65 if (r) | |
66 *r = (widget->priv.width + len) / 2; | |
67 *end = '\0'; | |
68 } | |
69 | |
70 static void | |
71 gnt_box_draw(GntWidget *widget) | |
72 { | |
73 GntBox *box = GNT_BOX(widget); | |
74 | |
75 if (box->focus == NULL && widget->parent == NULL) | |
76 g_list_foreach(box->list, add_to_focus, box); | |
77 | |
78 g_list_foreach(box->list, (GFunc)gnt_widget_draw, NULL); | |
79 | |
80 gnt_box_sync_children(box); | |
81 | |
82 if (box->title && !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
83 { | |
84 int pos, right; | |
85 char *title = g_strdup(box->title); | |
86 | |
87 get_title_thingies(box, title, &pos, &right); | |
88 | |
89 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:
19680
diff
changeset
|
90 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_TITLE)); |
15818 | 91 else |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
92 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:
19680
diff
changeset
|
93 mvwaddch(widget->window, 0, pos-1, ACS_RTEE | gnt_color_pair(GNT_COLOR_NORMAL)); |
15818 | 94 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:
19680
diff
changeset
|
95 mvwaddch(widget->window, 0, right, ACS_LTEE | gnt_color_pair(GNT_COLOR_NORMAL)); |
15818 | 96 g_free(title); |
97 } | |
98 | |
99 GNTDEBUG; | |
100 } | |
101 | |
102 static void | |
103 reposition_children(GntWidget *widget) | |
104 { | |
105 GList *iter; | |
106 GntBox *box = GNT_BOX(widget); | |
107 int w, h, curx, cury, max; | |
108 gboolean has_border = FALSE; | |
109 | |
110 w = h = 0; | |
111 max = 0; | |
112 curx = widget->priv.x; | |
113 cury = widget->priv.y; | |
114 if (!(GNT_WIDGET_FLAGS(widget) & GNT_WIDGET_NO_BORDER)) | |
115 { | |
116 has_border = TRUE; | |
117 curx += 1; | |
118 cury += 1; | |
119 } | |
120 | |
121 for (iter = box->list; iter; iter = iter->next) | |
122 { | |
123 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(iter->data), GNT_WIDGET_INVISIBLE)) | |
124 continue; | |
125 gnt_widget_set_position(GNT_WIDGET(iter->data), curx, cury); | |
126 gnt_widget_get_size(GNT_WIDGET(iter->data), &w, &h); | |
127 if (box->vertical) | |
128 { | |
129 if (h) | |
130 { | |
131 cury += h + box->pad; | |
132 if (max < w) | |
133 max = w; | |
134 } | |
135 } | |
136 else | |
137 { | |
138 if (w) | |
139 { | |
140 curx += w + box->pad; | |
141 if (max < h) | |
142 max = h; | |
143 } | |
144 } | |
145 } | |
146 | |
147 if (has_border) | |
148 { | |
149 curx += 1; | |
150 cury += 1; | |
151 max += 2; | |
152 } | |
153 | |
154 if (box->list) | |
155 { | |
156 if (box->vertical) | |
157 cury -= box->pad; | |
158 else | |
159 curx -= box->pad; | |
160 } | |
161 | |
162 if (box->vertical) | |
163 { | |
164 widget->priv.width = max; | |
165 widget->priv.height = cury - widget->priv.y; | |
166 } | |
167 else | |
168 { | |
169 widget->priv.width = curx - widget->priv.x; | |
170 widget->priv.height = max; | |
171 } | |
172 } | |
173 | |
174 static void | |
175 gnt_box_set_position(GntWidget *widget, int x, int y) | |
176 { | |
177 GList *iter; | |
178 int changex, changey; | |
179 | |
180 changex = widget->priv.x - x; | |
181 changey = widget->priv.y - y; | |
182 | |
183 for (iter = GNT_BOX(widget)->list; iter; iter = iter->next) | |
184 { | |
185 GntWidget *w = GNT_WIDGET(iter->data); | |
186 gnt_widget_set_position(w, w->priv.x - changex, | |
187 w->priv.y - changey); | |
188 } | |
189 } | |
190 | |
191 static void | |
192 gnt_box_size_request(GntWidget *widget) | |
193 { | |
194 GntBox *box = GNT_BOX(widget); | |
195 GList *iter; | |
196 int maxw = 0, maxh = 0; | |
197 | |
198 g_list_foreach(box->list, (GFunc)gnt_widget_size_request, NULL); | |
199 | |
200 for (iter = box->list; iter; iter = iter->next) | |
201 { | |
202 int w, h; | |
203 gnt_widget_get_size(GNT_WIDGET(iter->data), &w, &h); | |
204 if (maxh < h) | |
205 maxh = h; | |
206 if (maxw < w) | |
207 maxw = w; | |
208 } | |
209 | |
210 for (iter = box->list; iter; iter = iter->next) | |
211 { | |
212 int w, h; | |
213 GntWidget *wid = GNT_WIDGET(iter->data); | |
214 | |
215 gnt_widget_get_size(wid, &w, &h); | |
216 | |
217 if (box->homogeneous) | |
218 { | |
219 if (box->vertical) | |
220 h = maxh; | |
221 else | |
222 w = maxw; | |
223 } | |
224 if (box->fill) | |
225 { | |
226 if (box->vertical) | |
227 w = maxw; | |
228 else | |
229 h = maxh; | |
230 } | |
231 | |
18538
2e11d73c4ff1
Properly set the initial size of widgets.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
232 gnt_widget_confirm_size(wid, w, h); |
15818 | 233 gnt_widget_set_size(wid, w, h); |
234 } | |
235 | |
236 reposition_children(widget); | |
237 } | |
238 | |
239 static void | |
240 gnt_box_map(GntWidget *widget) | |
241 { | |
242 if (widget->priv.width == 0 || widget->priv.height == 0) | |
243 { | |
244 gnt_widget_size_request(widget); | |
245 find_focusable_widget(GNT_BOX(widget)); | |
246 } | |
247 GNTDEBUG; | |
248 } | |
249 | |
250 /* Ensures that the current widget can take focus */ | |
251 static GntWidget * | |
252 find_focusable_widget(GntBox *box) | |
253 { | |
254 /* XXX: Make sure the widget is visible? */ | |
255 if (box->focus == NULL && GNT_WIDGET(box)->parent == NULL) | |
256 g_list_foreach(box->list, add_to_focus, box); | |
257 | |
258 if (box->active == NULL && box->focus) | |
259 box->active = box->focus->data; | |
260 | |
261 return box->active; | |
262 } | |
263 | |
264 static void | |
265 find_next_focus(GntBox *box) | |
266 { | |
267 gpointer last = box->active; | |
268 do | |
269 { | |
270 GList *iter = g_list_find(box->focus, box->active); | |
271 if (iter && iter->next) | |
272 box->active = iter->next->data; | |
273 else if (box->focus) | |
274 box->active = box->focus->data; | |
275 if (!GNT_WIDGET_IS_FLAG_SET(box->active, GNT_WIDGET_INVISIBLE)) | |
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); | |
306 GntWidget *now; | |
307 | |
308 if (box->active == NULL && !find_focusable_widget(box)) | |
309 return FALSE; | |
310 | |
311 if (gnt_widget_key_pressed(box->active, text)) | |
312 return TRUE; | |
313 | |
314 now = box->active; | |
315 | |
316 if (text[0] == 27) | |
317 { | |
318 if (strcmp(text, GNT_KEY_LEFT) == 0) | |
319 { | |
320 find_prev_focus(box); | |
321 } | |
322 else if (strcmp(text, GNT_KEY_RIGHT) == 0) | |
323 { | |
324 find_next_focus(box); | |
325 } | |
18000
05d7fe2320a9
(16:39:44) rekkanoryo: i have a feature request
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
326 else if (strcmp(text, GNT_KEY_BACK_TAB) == 0) |
05d7fe2320a9
(16:39:44) rekkanoryo: i have a feature request
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
327 { |
05d7fe2320a9
(16:39:44) rekkanoryo: i have a feature request
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
328 find_prev_focus(box); |
05d7fe2320a9
(16:39:44) rekkanoryo: i have a feature request
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
329 } |
15818 | 330 } |
331 else if (text[0] == '\t') | |
332 { | |
333 find_next_focus(box); | |
334 } | |
335 | |
336 if (now && now != box->active) | |
337 { | |
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 | |
346 static void | |
347 gnt_box_lost_focus(GntWidget *widget) | |
348 { | |
349 GntWidget *w = GNT_BOX(widget)->active; | |
350 if (w) | |
351 gnt_widget_set_focus(w, FALSE); | |
352 gnt_widget_draw(widget); | |
353 } | |
354 | |
355 static void | |
356 gnt_box_gained_focus(GntWidget *widget) | |
357 { | |
358 GntWidget *w = GNT_BOX(widget)->active; | |
359 if (w) | |
360 gnt_widget_set_focus(w, TRUE); | |
361 gnt_widget_draw(widget); | |
362 } | |
363 | |
364 static void | |
365 gnt_box_destroy(GntWidget *w) | |
366 { | |
367 GntBox *box = GNT_BOX(w); | |
368 | |
369 gnt_box_remove_all(box); | |
370 gnt_screen_release(w); | |
371 } | |
372 | |
373 static void | |
374 gnt_box_expose(GntWidget *widget, int x, int y, int width, int height) | |
375 { | |
376 WINDOW *win = newwin(height, width, widget->priv.y + y, widget->priv.x + x); | |
377 copywin(widget->window, win, y, x, 0, 0, height - 1, width - 1, FALSE); | |
378 wrefresh(win); | |
379 delwin(win); | |
380 } | |
381 | |
382 static gboolean | |
383 gnt_box_confirm_size(GntWidget *widget, int width, int height) | |
384 { | |
385 GList *iter; | |
386 GntBox *box = GNT_BOX(widget); | |
387 int wchange, hchange; | |
388 | |
389 if (!box->list) | |
390 return TRUE; | |
391 | |
392 wchange = widget->priv.width - width; | |
393 hchange = widget->priv.height - height; | |
394 | |
395 if (wchange == 0 && hchange == 0) | |
396 return TRUE; /* Quit playing games */ | |
397 | |
398 /* XXX: Right now, I am trying to just apply all the changes to | |
399 * just one widget. It should be possible to distribute the | |
400 * changes to all the widgets in the box. */ | |
401 for (iter = box->list; iter; iter = iter->next) | |
402 { | |
403 GntWidget *wid = iter->data; | |
404 int w, h; | |
405 | |
406 gnt_widget_get_size(wid, &w, &h); | |
407 | |
408 if (gnt_widget_confirm_size(wid, w - wchange, h - hchange)) | |
409 { | |
410 GList *i; | |
411 | |
412 for (i = box->list; i; i = i->next) | |
413 { | |
414 int tw, th; | |
415 if (i == iter) continue; | |
416 gnt_widget_get_size(GNT_WIDGET(i->data), &tw, &th); | |
417 if (box->vertical) | |
418 { | |
15945
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
419 if (!gnt_widget_confirm_size(i->data, tw - wchange, th)) { |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
420 /* 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:
15818
diff
changeset
|
421 * 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:
15818
diff
changeset
|
422 * resizing. */ |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
423 if (wchange > 0 && tw >= widget->priv.width) |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
424 return FALSE; |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
425 } |
15818 | 426 } |
427 else | |
428 { | |
15945
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
429 if (!gnt_widget_confirm_size(i->data, tw, th - hchange)) { |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
430 if (hchange > 0 && th >= widget->priv.height) |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
431 return FALSE; |
15818 | 432 return FALSE; |
15945
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
433 } |
15818 | 434 } |
435 } | |
436 #if 0 | |
437 gnt_widget_set_size(wid, w - wchange, h - hchange); | |
438 if (box->vertical) | |
439 hchange = 0; | |
440 else | |
441 wchange = 0; | |
442 | |
443 for (i = box->list; i; i = i->next) | |
444 { | |
445 int tw, th; | |
446 if (i == iter) continue; | |
447 gnt_widget_get_size(GNT_WIDGET(i->data), &tw, &th); | |
448 gnt_widget_set_size(i->data, tw - wchange, th - hchange); | |
449 } | |
450 #endif | |
451 g_object_set_data(G_OBJECT(box), "size-queued", wid); | |
452 return TRUE; | |
453 } | |
454 } | |
455 | |
456 return FALSE; | |
457 } | |
458 | |
459 static void | |
460 gnt_box_size_changed(GntWidget *widget, int oldw, int oldh) | |
461 { | |
462 int wchange, hchange; | |
463 GList *i; | |
464 GntBox *box = GNT_BOX(widget); | |
465 GntWidget *wid; | |
466 int tw, th; | |
467 | |
468 wchange = widget->priv.width - oldw; | |
469 hchange = widget->priv.height - oldh; | |
470 | |
471 wid = g_object_get_data(G_OBJECT(box), "size-queued"); | |
472 if (wid) | |
473 { | |
474 gnt_widget_get_size(wid, &tw, &th); | |
475 gnt_widget_set_size(wid, tw + wchange, th + hchange); | |
476 g_object_set_data(G_OBJECT(box), "size-queued", NULL); | |
477 } | |
478 | |
479 if (box->vertical) | |
480 hchange = 0; | |
481 else | |
482 wchange = 0; | |
483 | |
484 for (i = box->list; i; i = i->next) | |
485 { | |
486 if (wid != i->data) | |
487 { | |
488 gnt_widget_get_size(GNT_WIDGET(i->data), &tw, &th); | |
489 gnt_widget_set_size(i->data, tw + wchange, th + hchange); | |
490 } | |
491 } | |
492 | |
493 reposition_children(widget); | |
494 } | |
495 | |
496 static gboolean | |
497 gnt_box_clicked(GntWidget *widget, GntMouseEvent event, int cx, int cy) | |
498 { | |
499 GList *iter; | |
500 for (iter = GNT_BOX(widget)->list; iter; iter = iter->next) { | |
501 int x, y, w, h; | |
502 GntWidget *wid = iter->data; | |
503 | |
504 gnt_widget_get_position(wid, &x, &y); | |
505 gnt_widget_get_size(wid, &w, &h); | |
506 | |
507 if (cx >= x && cx < x + w && cy >= y && cy < y + h) { | |
508 if (event <= GNT_MIDDLE_MOUSE_DOWN && | |
509 GNT_WIDGET_IS_FLAG_SET(wid, GNT_WIDGET_CAN_TAKE_FOCUS)) { | |
510 while (widget->parent) | |
511 widget = widget->parent; | |
512 gnt_box_give_focus_to_child(GNT_BOX(widget), wid); | |
513 } | |
514 return gnt_widget_clicked(wid, event, cx, cy); | |
515 } | |
516 } | |
517 return FALSE; | |
518 } | |
519 | |
520 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
|
521 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
|
522 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
|
523 { |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
524 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
|
525 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
|
526 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
|
527 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
|
528 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
529 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
|
530 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
|
531 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
532 default: |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
533 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
|
534 break; |
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 } |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
537 |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
538 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
|
539 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
|
540 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
|
541 { |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
542 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
|
543 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
|
544 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
|
545 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
|
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 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
|
548 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
|
549 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
550 default: |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
551 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
552 } |
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 |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
555 static void |
15818 | 556 gnt_box_class_init(GntBoxClass *klass) |
557 { | |
21261
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
558 GObjectClass *gclass = G_OBJECT_CLASS(klass); |
15818 | 559 parent_class = GNT_WIDGET_CLASS(klass); |
560 parent_class->destroy = gnt_box_destroy; | |
561 parent_class->draw = gnt_box_draw; | |
562 parent_class->expose = gnt_box_expose; | |
563 parent_class->map = gnt_box_map; | |
564 parent_class->size_request = gnt_box_size_request; | |
565 parent_class->set_position = gnt_box_set_position; | |
566 parent_class->key_pressed = gnt_box_key_pressed; | |
567 parent_class->clicked = gnt_box_clicked; | |
568 parent_class->lost_focus = gnt_box_lost_focus; | |
569 parent_class->gained_focus = gnt_box_gained_focus; | |
570 parent_class->confirm_size = gnt_box_confirm_size; | |
571 parent_class->size_changed = gnt_box_size_changed; | |
572 | |
21261
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
573 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
|
574 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
|
575 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
|
576 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
|
577 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
|
578 "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
|
579 TRUE, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
580 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
|
581 ) |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
582 ); |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
583 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
|
584 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
|
585 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
|
586 "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
|
587 TRUE, |
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_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
|
589 ) |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
590 ); |
15818 | 591 } |
592 | |
593 static void | |
594 gnt_box_init(GTypeInstance *instance, gpointer class) | |
595 { | |
596 GntWidget *widget = GNT_WIDGET(instance); | |
597 GntBox *box = GNT_BOX(widget); | |
598 /* Initially make both the height and width resizable. | |
599 * Update the flags as necessary when widgets are added to it. */ | |
600 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y); | |
601 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS); | |
602 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); | |
603 box->pad = 1; | |
604 box->fill = TRUE; | |
605 GNTDEBUG; | |
606 } | |
607 | |
608 /****************************************************************************** | |
609 * GntBox API | |
610 *****************************************************************************/ | |
611 GType | |
612 gnt_box_get_gtype(void) | |
613 { | |
614 static GType type = 0; | |
615 | |
616 if(type == 0) | |
617 { | |
618 static const GTypeInfo info = { | |
619 sizeof(GntBoxClass), | |
620 NULL, /* base_init */ | |
621 NULL, /* base_finalize */ | |
622 (GClassInitFunc)gnt_box_class_init, | |
623 NULL, /* class_finalize */ | |
624 NULL, /* class_data */ | |
625 sizeof(GntBox), | |
626 0, /* n_preallocs */ | |
627 gnt_box_init, /* instance_init */ | |
628 NULL /* value_table */ | |
629 }; | |
630 | |
631 type = g_type_register_static(GNT_TYPE_WIDGET, | |
632 "GntBox", | |
633 &info, 0); | |
634 } | |
635 | |
636 return type; | |
637 } | |
638 | |
639 GntWidget *gnt_box_new(gboolean homo, gboolean vert) | |
640 { | |
641 GntWidget *widget = g_object_new(GNT_TYPE_BOX, NULL); | |
642 GntBox *box = GNT_BOX(widget); | |
643 | |
644 box->homogeneous = homo; | |
645 box->vertical = vert; | |
646 box->alignment = vert ? GNT_ALIGN_LEFT : GNT_ALIGN_MID; | |
647 | |
648 return widget; | |
649 } | |
650 | |
651 void gnt_box_add_widget(GntBox *b, GntWidget *widget) | |
652 { | |
653 b->list = g_list_append(b->list, widget); | |
654 widget->parent = GNT_WIDGET(b); | |
655 } | |
656 | |
657 void gnt_box_set_title(GntBox *b, const char *title) | |
658 { | |
659 char *prev = b->title; | |
660 GntWidget *w = GNT_WIDGET(b); | |
661 b->title = g_strdup(title); | |
662 if (w->window && !GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_NO_BORDER)) { | |
663 /* Erase the old title */ | |
664 int pos, right; | |
665 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:
19680
diff
changeset
|
666 mvwhline(w->window, 0, pos - 1, ACS_HLINE | gnt_color_pair(GNT_COLOR_NORMAL), |
15818 | 667 right - pos + 2); |
668 g_free(prev); | |
669 } | |
670 } | |
671 | |
672 void gnt_box_set_pad(GntBox *box, int pad) | |
673 { | |
674 box->pad = pad; | |
675 /* XXX: Perhaps redraw if already showing? */ | |
676 } | |
677 | |
678 void gnt_box_set_toplevel(GntBox *box, gboolean set) | |
679 { | |
680 GntWidget *widget = GNT_WIDGET(box); | |
681 if (set) | |
682 { | |
683 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); | |
684 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS); | |
685 } | |
686 else | |
687 { | |
688 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); | |
689 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS); | |
690 } | |
691 } | |
692 | |
693 void gnt_box_sync_children(GntBox *box) | |
694 { | |
695 GList *iter; | |
696 GntWidget *widget = GNT_WIDGET(box); | |
697 int pos = 1; | |
698 | |
699 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
700 pos = 0; | |
701 | |
702 for (iter = box->list; iter; iter = iter->next) | |
703 { | |
704 GntWidget *w = GNT_WIDGET(iter->data); | |
705 int height, width; | |
706 int x, y; | |
707 | |
708 if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_INVISIBLE)) | |
709 continue; | |
710 | |
711 if (GNT_IS_BOX(w)) | |
712 gnt_box_sync_children(GNT_BOX(w)); | |
713 | |
714 gnt_widget_get_size(w, &width, &height); | |
715 | |
716 x = w->priv.x - widget->priv.x; | |
717 y = w->priv.y - widget->priv.y; | |
718 | |
719 if (box->vertical) | |
720 { | |
721 x = pos; | |
722 if (box->alignment == GNT_ALIGN_RIGHT) | |
723 x += widget->priv.width - width; | |
724 else if (box->alignment == GNT_ALIGN_MID) | |
725 x += (widget->priv.width - width)/2; | |
726 if (x + width > widget->priv.width - pos) | |
727 x -= x + width - (widget->priv.width - pos); | |
728 } | |
729 else | |
730 { | |
731 y = pos; | |
732 if (box->alignment == GNT_ALIGN_BOTTOM) | |
733 y += widget->priv.height - height; | |
734 else if (box->alignment == GNT_ALIGN_MID) | |
735 y += (widget->priv.height - height)/2; | |
736 if (y + height >= widget->priv.height - pos) | |
737 y = widget->priv.height - height - pos; | |
738 } | |
739 | |
740 copywin(w->window, widget->window, 0, 0, | |
741 y, x, y + height - 1, x + width - 1, FALSE); | |
742 gnt_widget_set_position(w, x + widget->priv.x, y + widget->priv.y); | |
743 } | |
744 } | |
745 | |
746 void gnt_box_set_alignment(GntBox *box, GntAlignment alignment) | |
747 { | |
748 box->alignment = alignment; | |
749 } | |
750 | |
751 void gnt_box_remove(GntBox *box, GntWidget *widget) | |
752 { | |
753 box->list = g_list_remove(box->list, widget); | |
754 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_CAN_TAKE_FOCUS) | |
755 && GNT_WIDGET(box)->parent == NULL && box->focus) | |
756 { | |
757 if (widget == box->active) | |
758 { | |
759 find_next_focus(box); | |
760 if (box->active == widget) /* There's only one widget */ | |
761 box->active = NULL; | |
762 } | |
763 box->focus = g_list_remove(box->focus, widget); | |
764 } | |
765 | |
766 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(box), GNT_WIDGET_MAPPED)) | |
767 gnt_widget_draw(GNT_WIDGET(box)); | |
768 } | |
769 | |
770 void gnt_box_remove_all(GntBox *box) | |
771 { | |
772 g_list_foreach(box->list, (GFunc)gnt_widget_destroy, NULL); | |
773 g_list_free(box->list); | |
774 g_list_free(box->focus); | |
775 box->list = NULL; | |
776 box->focus = NULL; | |
777 GNT_WIDGET(box)->priv.width = 0; | |
778 GNT_WIDGET(box)->priv.height = 0; | |
779 } | |
780 | |
781 void gnt_box_readjust(GntBox *box) | |
782 { | |
783 GList *iter; | |
784 GntWidget *wid; | |
785 int width, height; | |
786 | |
787 if (GNT_WIDGET(box)->parent != NULL) | |
788 return; | |
789 | |
790 for (iter = box->list; iter; iter = iter->next) | |
791 { | |
792 GntWidget *w = iter->data; | |
793 if (GNT_IS_BOX(w)) | |
794 gnt_box_readjust(GNT_BOX(w)); | |
795 else | |
796 { | |
797 GNT_WIDGET_UNSET_FLAGS(w, GNT_WIDGET_MAPPED); | |
798 w->priv.width = 0; | |
799 w->priv.height = 0; | |
800 } | |
801 } | |
802 | |
803 wid = GNT_WIDGET(box); | |
804 GNT_WIDGET_UNSET_FLAGS(wid, GNT_WIDGET_MAPPED); | |
805 wid->priv.width = 0; | |
806 wid->priv.height = 0; | |
807 | |
808 if (wid->parent == NULL) | |
809 { | |
810 g_list_free(box->focus); | |
811 box->focus = NULL; | |
812 box->active = NULL; | |
813 gnt_widget_size_request(wid); | |
814 gnt_widget_get_size(wid, &width, &height); | |
815 gnt_screen_resize_widget(wid, width, height); | |
816 find_focusable_widget(box); | |
817 } | |
818 } | |
819 | |
820 void gnt_box_set_fill(GntBox *box, gboolean fill) | |
821 { | |
822 box->fill = fill; | |
823 } | |
824 | |
825 void gnt_box_move_focus(GntBox *box, int dir) | |
826 { | |
827 GntWidget *now; | |
828 | |
829 if (box->active == NULL) | |
830 { | |
831 find_focusable_widget(box); | |
832 return; | |
833 } | |
834 | |
835 now = box->active; | |
836 | |
837 if (dir == 1) | |
838 find_next_focus(box); | |
839 else if (dir == -1) | |
840 find_prev_focus(box); | |
841 | |
842 if (now && now != box->active) | |
843 { | |
844 gnt_widget_set_focus(now, FALSE); | |
845 gnt_widget_set_focus(box->active, TRUE); | |
846 } | |
847 | |
848 if (GNT_WIDGET(box)->window) | |
849 gnt_widget_draw(GNT_WIDGET(box)); | |
850 } | |
851 | |
852 void gnt_box_give_focus_to_child(GntBox *box, GntWidget *widget) | |
853 { | |
21626
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
854 GList *find; |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
855 gpointer now; |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
856 |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
857 while (GNT_WIDGET(box)->parent) |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
858 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
|
859 |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
860 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
|
861 now = box->active; |
15818 | 862 if (find) |
863 box->active = widget; | |
864 if (now && now != box->active) | |
865 { | |
866 gnt_widget_set_focus(now, FALSE); | |
867 gnt_widget_set_focus(box->active, TRUE); | |
868 } | |
869 | |
870 if (GNT_WIDGET(box)->window) | |
871 gnt_widget_draw(GNT_WIDGET(box)); | |
872 } | |
873 |