Mercurial > pidgin
annotate finch/libgnt/gntbox.c @ 24963:33fa549f2399
Move variables to PurpleMediaStream.
author | Mike Ruprecht <maiku@soc.pidgin.im> |
---|---|
date | Sun, 16 Nov 2008 05:22:17 +0000 |
parents | d03b32530854 |
children | 73e88188a7d4 |
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" |
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 { |
15817 | 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:
19681
diff
changeset
|
90 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_TITLE)); |
15817 | 91 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
|
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:
19681
diff
changeset
|
93 mvwaddch(widget->window, 0, pos-1, ACS_RTEE | gnt_color_pair(GNT_COLOR_NORMAL)); |
15817 | 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:
19681
diff
changeset
|
95 mvwaddch(widget->window, 0, right, ACS_LTEE | gnt_color_pair(GNT_COLOR_NORMAL)); |
15817 | 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); |
15817 | 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; | |
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
|
275 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
|
276 GNT_WIDGET_IS_FLAG_SET(box->active, GNT_WIDGET_CAN_TAKE_FOCUS)) |
15817 | 277 break; |
278 } while (box->active != last); | |
279 } | |
280 | |
281 static void | |
282 find_prev_focus(GntBox *box) | |
283 { | |
284 gpointer last = box->active; | |
285 | |
286 if (!box->focus) | |
287 return; | |
288 | |
289 do | |
290 { | |
291 GList *iter = g_list_find(box->focus, box->active); | |
292 if (!iter) | |
293 box->active = box->focus->data; | |
294 else if (!iter->prev) | |
295 box->active = g_list_last(box->focus)->data; | |
296 else | |
297 box->active = iter->prev->data; | |
298 if (!GNT_WIDGET_IS_FLAG_SET(box->active, GNT_WIDGET_INVISIBLE)) | |
299 break; | |
300 } while (box->active != last); | |
301 } | |
302 | |
303 static gboolean | |
304 gnt_box_key_pressed(GntWidget *widget, const char *text) | |
305 { | |
306 GntBox *box = GNT_BOX(widget); | |
307 GntWidget *now; | |
308 | |
309 if (box->active == NULL && !find_focusable_widget(box)) | |
310 return FALSE; | |
311 | |
312 if (gnt_widget_key_pressed(box->active, text)) | |
313 return TRUE; | |
314 | |
315 now = box->active; | |
316 | |
317 if (text[0] == 27) | |
318 { | |
319 if (strcmp(text, GNT_KEY_LEFT) == 0) | |
320 { | |
321 find_prev_focus(box); | |
322 } | |
323 else if (strcmp(text, GNT_KEY_RIGHT) == 0) | |
324 { | |
325 find_next_focus(box); | |
326 } | |
18000
05d7fe2320a9
(16:39:44) rekkanoryo: i have a feature request
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
327 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
|
328 { |
05d7fe2320a9
(16:39:44) rekkanoryo: i have a feature request
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
329 find_prev_focus(box); |
05d7fe2320a9
(16:39:44) rekkanoryo: i have a feature request
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15945
diff
changeset
|
330 } |
15817 | 331 } |
332 else if (text[0] == '\t') | |
333 { | |
334 find_next_focus(box); | |
335 } | |
336 | |
337 if (now && now != box->active) | |
338 { | |
339 gnt_widget_set_focus(now, FALSE); | |
340 gnt_widget_set_focus(box->active, TRUE); | |
341 return TRUE; | |
342 } | |
343 | |
344 return FALSE; | |
345 } | |
346 | |
347 static void | |
348 gnt_box_lost_focus(GntWidget *widget) | |
349 { | |
350 GntWidget *w = GNT_BOX(widget)->active; | |
351 if (w) | |
352 gnt_widget_set_focus(w, FALSE); | |
353 gnt_widget_draw(widget); | |
354 } | |
355 | |
356 static void | |
357 gnt_box_gained_focus(GntWidget *widget) | |
358 { | |
359 GntWidget *w = GNT_BOX(widget)->active; | |
360 if (w) | |
361 gnt_widget_set_focus(w, TRUE); | |
362 gnt_widget_draw(widget); | |
363 } | |
364 | |
365 static void | |
366 gnt_box_destroy(GntWidget *w) | |
367 { | |
368 GntBox *box = GNT_BOX(w); | |
369 | |
370 gnt_box_remove_all(box); | |
371 gnt_screen_release(w); | |
372 } | |
373 | |
374 static void | |
375 gnt_box_expose(GntWidget *widget, int x, int y, int width, int height) | |
376 { | |
377 WINDOW *win = newwin(height, width, widget->priv.y + y, widget->priv.x + x); | |
378 copywin(widget->window, win, y, x, 0, 0, height - 1, width - 1, FALSE); | |
379 wrefresh(win); | |
380 delwin(win); | |
381 } | |
382 | |
383 static gboolean | |
384 gnt_box_confirm_size(GntWidget *widget, int width, int height) | |
385 { | |
386 GList *iter; | |
387 GntBox *box = GNT_BOX(widget); | |
388 int wchange, hchange; | |
389 | |
390 if (!box->list) | |
391 return TRUE; | |
392 | |
393 wchange = widget->priv.width - width; | |
394 hchange = widget->priv.height - height; | |
395 | |
396 if (wchange == 0 && hchange == 0) | |
397 return TRUE; /* Quit playing games */ | |
398 | |
399 /* XXX: Right now, I am trying to just apply all the changes to | |
400 * just one widget. It should be possible to distribute the | |
401 * changes to all the widgets in the box. */ | |
402 for (iter = box->list; iter; iter = iter->next) | |
403 { | |
404 GntWidget *wid = iter->data; | |
405 int w, h; | |
406 | |
407 gnt_widget_get_size(wid, &w, &h); | |
408 | |
409 if (gnt_widget_confirm_size(wid, w - wchange, h - hchange)) | |
410 { | |
411 GList *i; | |
412 | |
413 for (i = box->list; i; i = i->next) | |
414 { | |
415 int tw, th; | |
416 if (i == iter) continue; | |
417 gnt_widget_get_size(GNT_WIDGET(i->data), &tw, &th); | |
418 if (box->vertical) | |
419 { | |
15945
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
420 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
|
421 /* 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
|
422 * 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
|
423 * resizing. */ |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
424 if (wchange > 0 && tw >= widget->priv.width) |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
425 return FALSE; |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
426 } |
15817 | 427 } |
428 else | |
429 { | |
15945
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
430 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
|
431 if (hchange > 0 && th >= widget->priv.height) |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
432 return FALSE; |
15817 | 433 return FALSE; |
15945
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
434 } |
15817 | 435 } |
436 } | |
437 #if 0 | |
438 gnt_widget_set_size(wid, w - wchange, h - hchange); | |
439 if (box->vertical) | |
440 hchange = 0; | |
441 else | |
442 wchange = 0; | |
443 | |
444 for (i = box->list; i; i = i->next) | |
445 { | |
446 int tw, th; | |
447 if (i == iter) continue; | |
448 gnt_widget_get_size(GNT_WIDGET(i->data), &tw, &th); | |
449 gnt_widget_set_size(i->data, tw - wchange, th - hchange); | |
450 } | |
451 #endif | |
452 g_object_set_data(G_OBJECT(box), "size-queued", wid); | |
453 return TRUE; | |
454 } | |
455 } | |
456 | |
457 return FALSE; | |
458 } | |
459 | |
460 static void | |
461 gnt_box_size_changed(GntWidget *widget, int oldw, int oldh) | |
462 { | |
463 int wchange, hchange; | |
464 GList *i; | |
465 GntBox *box = GNT_BOX(widget); | |
466 GntWidget *wid; | |
467 int tw, th; | |
468 | |
469 wchange = widget->priv.width - oldw; | |
470 hchange = widget->priv.height - oldh; | |
471 | |
472 wid = g_object_get_data(G_OBJECT(box), "size-queued"); | |
473 if (wid) | |
474 { | |
475 gnt_widget_get_size(wid, &tw, &th); | |
476 gnt_widget_set_size(wid, tw + wchange, th + hchange); | |
477 g_object_set_data(G_OBJECT(box), "size-queued", NULL); | |
478 } | |
479 | |
480 if (box->vertical) | |
481 hchange = 0; | |
482 else | |
483 wchange = 0; | |
484 | |
485 for (i = box->list; i; i = i->next) | |
486 { | |
487 if (wid != i->data) | |
488 { | |
489 gnt_widget_get_size(GNT_WIDGET(i->data), &tw, &th); | |
490 gnt_widget_set_size(i->data, tw + wchange, th + hchange); | |
491 } | |
492 } | |
493 | |
494 reposition_children(widget); | |
495 } | |
496 | |
497 static gboolean | |
498 gnt_box_clicked(GntWidget *widget, GntMouseEvent event, int cx, int cy) | |
499 { | |
500 GList *iter; | |
501 for (iter = GNT_BOX(widget)->list; iter; iter = iter->next) { | |
502 int x, y, w, h; | |
503 GntWidget *wid = iter->data; | |
504 | |
505 gnt_widget_get_position(wid, &x, &y); | |
506 gnt_widget_get_size(wid, &w, &h); | |
507 | |
508 if (cx >= x && cx < x + w && cy >= y && cy < y + h) { | |
509 if (event <= GNT_MIDDLE_MOUSE_DOWN && | |
510 GNT_WIDGET_IS_FLAG_SET(wid, GNT_WIDGET_CAN_TAKE_FOCUS)) { | |
511 while (widget->parent) | |
512 widget = widget->parent; | |
513 gnt_box_give_focus_to_child(GNT_BOX(widget), wid); | |
514 } | |
515 return gnt_widget_clicked(wid, event, cx, cy); | |
516 } | |
517 } | |
518 return FALSE; | |
519 } | |
520 | |
521 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
|
522 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
|
523 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
|
524 { |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
525 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
|
526 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
|
527 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
|
528 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
|
529 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
530 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
|
531 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
|
532 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
533 default: |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
534 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
|
535 break; |
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 |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
539 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
|
540 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
|
541 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
|
542 { |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
543 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
|
544 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
|
545 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
|
546 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
|
547 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
548 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
|
549 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
|
550 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
551 default: |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
552 break; |
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 |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
556 static void |
15817 | 557 gnt_box_class_init(GntBoxClass *klass) |
558 { | |
21261
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
559 GObjectClass *gclass = G_OBJECT_CLASS(klass); |
15817 | 560 parent_class = GNT_WIDGET_CLASS(klass); |
561 parent_class->destroy = gnt_box_destroy; | |
562 parent_class->draw = gnt_box_draw; | |
563 parent_class->expose = gnt_box_expose; | |
564 parent_class->map = gnt_box_map; | |
565 parent_class->size_request = gnt_box_size_request; | |
566 parent_class->set_position = gnt_box_set_position; | |
567 parent_class->key_pressed = gnt_box_key_pressed; | |
568 parent_class->clicked = gnt_box_clicked; | |
569 parent_class->lost_focus = gnt_box_lost_focus; | |
570 parent_class->gained_focus = gnt_box_gained_focus; | |
571 parent_class->confirm_size = gnt_box_confirm_size; | |
572 parent_class->size_changed = gnt_box_size_changed; | |
573 | |
21261
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->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
|
575 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
|
576 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
|
577 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
|
578 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
|
579 "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
|
580 TRUE, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
581 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
|
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 ); |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
584 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
|
585 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
|
586 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
|
587 "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
|
588 TRUE, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
589 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
|
590 ) |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
591 ); |
15817 | 592 } |
593 | |
594 static void | |
595 gnt_box_init(GTypeInstance *instance, gpointer class) | |
596 { | |
597 GntWidget *widget = GNT_WIDGET(instance); | |
598 GntBox *box = GNT_BOX(widget); | |
599 /* Initially make both the height and width resizable. | |
600 * Update the flags as necessary when widgets are added to it. */ | |
601 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y); | |
602 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS); | |
603 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); | |
604 box->pad = 1; | |
605 box->fill = TRUE; | |
606 GNTDEBUG; | |
607 } | |
608 | |
609 /****************************************************************************** | |
610 * GntBox API | |
611 *****************************************************************************/ | |
612 GType | |
613 gnt_box_get_gtype(void) | |
614 { | |
615 static GType type = 0; | |
616 | |
617 if(type == 0) | |
618 { | |
619 static const GTypeInfo info = { | |
620 sizeof(GntBoxClass), | |
621 NULL, /* base_init */ | |
622 NULL, /* base_finalize */ | |
623 (GClassInitFunc)gnt_box_class_init, | |
624 NULL, /* class_finalize */ | |
625 NULL, /* class_data */ | |
626 sizeof(GntBox), | |
627 0, /* n_preallocs */ | |
628 gnt_box_init, /* instance_init */ | |
629 NULL /* value_table */ | |
630 }; | |
631 | |
632 type = g_type_register_static(GNT_TYPE_WIDGET, | |
633 "GntBox", | |
634 &info, 0); | |
635 } | |
636 | |
637 return type; | |
638 } | |
639 | |
640 GntWidget *gnt_box_new(gboolean homo, gboolean vert) | |
641 { | |
642 GntWidget *widget = g_object_new(GNT_TYPE_BOX, NULL); | |
643 GntBox *box = GNT_BOX(widget); | |
644 | |
645 box->homogeneous = homo; | |
646 box->vertical = vert; | |
647 box->alignment = vert ? GNT_ALIGN_LEFT : GNT_ALIGN_MID; | |
648 | |
649 return widget; | |
650 } | |
651 | |
652 void gnt_box_add_widget(GntBox *b, GntWidget *widget) | |
653 { | |
654 b->list = g_list_append(b->list, widget); | |
655 widget->parent = GNT_WIDGET(b); | |
656 } | |
657 | |
658 void gnt_box_set_title(GntBox *b, const char *title) | |
659 { | |
660 char *prev = b->title; | |
661 GntWidget *w = GNT_WIDGET(b); | |
662 b->title = g_strdup(title); | |
663 if (w->window && !GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_NO_BORDER)) { | |
664 /* Erase the old title */ | |
665 int pos, right; | |
666 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
|
667 mvwhline(w->window, 0, pos - 1, ACS_HLINE | gnt_color_pair(GNT_COLOR_NORMAL), |
15817 | 668 right - pos + 2); |
669 g_free(prev); | |
670 } | |
671 } | |
672 | |
673 void gnt_box_set_pad(GntBox *box, int pad) | |
674 { | |
675 box->pad = pad; | |
676 /* XXX: Perhaps redraw if already showing? */ | |
677 } | |
678 | |
679 void gnt_box_set_toplevel(GntBox *box, gboolean set) | |
680 { | |
681 GntWidget *widget = GNT_WIDGET(box); | |
682 if (set) | |
683 { | |
684 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); | |
685 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS); | |
686 } | |
687 else | |
688 { | |
689 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); | |
690 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS); | |
691 } | |
692 } | |
693 | |
694 void gnt_box_sync_children(GntBox *box) | |
695 { | |
696 GList *iter; | |
697 GntWidget *widget = GNT_WIDGET(box); | |
698 int pos = 1; | |
699 | |
700 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
701 pos = 0; | |
702 | |
703 for (iter = box->list; iter; iter = iter->next) | |
704 { | |
705 GntWidget *w = GNT_WIDGET(iter->data); | |
706 int height, width; | |
707 int x, y; | |
708 | |
709 if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_INVISIBLE)) | |
710 continue; | |
711 | |
712 if (GNT_IS_BOX(w)) | |
713 gnt_box_sync_children(GNT_BOX(w)); | |
714 | |
715 gnt_widget_get_size(w, &width, &height); | |
716 | |
717 x = w->priv.x - widget->priv.x; | |
718 y = w->priv.y - widget->priv.y; | |
719 | |
720 if (box->vertical) | |
721 { | |
722 x = pos; | |
723 if (box->alignment == GNT_ALIGN_RIGHT) | |
724 x += widget->priv.width - width; | |
725 else if (box->alignment == GNT_ALIGN_MID) | |
726 x += (widget->priv.width - width)/2; | |
727 if (x + width > widget->priv.width - pos) | |
728 x -= x + width - (widget->priv.width - pos); | |
729 } | |
730 else | |
731 { | |
732 y = pos; | |
733 if (box->alignment == GNT_ALIGN_BOTTOM) | |
734 y += widget->priv.height - height; | |
735 else if (box->alignment == GNT_ALIGN_MID) | |
736 y += (widget->priv.height - height)/2; | |
737 if (y + height >= widget->priv.height - pos) | |
738 y = widget->priv.height - height - pos; | |
739 } | |
740 | |
741 copywin(w->window, widget->window, 0, 0, | |
742 y, x, y + height - 1, x + width - 1, FALSE); | |
743 gnt_widget_set_position(w, x + widget->priv.x, y + widget->priv.y); | |
744 } | |
745 } | |
746 | |
747 void gnt_box_set_alignment(GntBox *box, GntAlignment alignment) | |
748 { | |
749 box->alignment = alignment; | |
750 } | |
751 | |
752 void gnt_box_remove(GntBox *box, GntWidget *widget) | |
753 { | |
754 box->list = g_list_remove(box->list, widget); | |
755 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_CAN_TAKE_FOCUS) | |
756 && GNT_WIDGET(box)->parent == NULL && box->focus) | |
757 { | |
758 if (widget == box->active) | |
759 { | |
760 find_next_focus(box); | |
761 if (box->active == widget) /* There's only one widget */ | |
762 box->active = NULL; | |
763 } | |
764 box->focus = g_list_remove(box->focus, widget); | |
765 } | |
766 | |
767 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(box), GNT_WIDGET_MAPPED)) | |
768 gnt_widget_draw(GNT_WIDGET(box)); | |
769 } | |
770 | |
771 void gnt_box_remove_all(GntBox *box) | |
772 { | |
773 g_list_foreach(box->list, (GFunc)gnt_widget_destroy, NULL); | |
774 g_list_free(box->list); | |
775 g_list_free(box->focus); | |
776 box->list = NULL; | |
777 box->focus = NULL; | |
778 GNT_WIDGET(box)->priv.width = 0; | |
779 GNT_WIDGET(box)->priv.height = 0; | |
780 } | |
781 | |
782 void gnt_box_readjust(GntBox *box) | |
783 { | |
784 GList *iter; | |
785 GntWidget *wid; | |
786 int width, height; | |
787 | |
788 if (GNT_WIDGET(box)->parent != NULL) | |
789 return; | |
790 | |
791 for (iter = box->list; iter; iter = iter->next) | |
792 { | |
793 GntWidget *w = iter->data; | |
794 if (GNT_IS_BOX(w)) | |
795 gnt_box_readjust(GNT_BOX(w)); | |
796 else | |
797 { | |
798 GNT_WIDGET_UNSET_FLAGS(w, GNT_WIDGET_MAPPED); | |
799 w->priv.width = 0; | |
800 w->priv.height = 0; | |
801 } | |
802 } | |
803 | |
804 wid = GNT_WIDGET(box); | |
805 GNT_WIDGET_UNSET_FLAGS(wid, GNT_WIDGET_MAPPED); | |
806 wid->priv.width = 0; | |
807 wid->priv.height = 0; | |
808 | |
809 if (wid->parent == NULL) | |
810 { | |
811 g_list_free(box->focus); | |
812 box->focus = NULL; | |
813 box->active = NULL; | |
814 gnt_widget_size_request(wid); | |
815 gnt_widget_get_size(wid, &width, &height); | |
816 gnt_screen_resize_widget(wid, width, height); | |
817 find_focusable_widget(box); | |
818 } | |
819 } | |
820 | |
821 void gnt_box_set_fill(GntBox *box, gboolean fill) | |
822 { | |
823 box->fill = fill; | |
824 } | |
825 | |
826 void gnt_box_move_focus(GntBox *box, int dir) | |
827 { | |
828 GntWidget *now; | |
829 | |
830 if (box->active == NULL) | |
831 { | |
832 find_focusable_widget(box); | |
833 return; | |
834 } | |
835 | |
836 now = box->active; | |
837 | |
838 if (dir == 1) | |
839 find_next_focus(box); | |
840 else if (dir == -1) | |
841 find_prev_focus(box); | |
842 | |
843 if (now && now != box->active) | |
844 { | |
845 gnt_widget_set_focus(now, FALSE); | |
846 gnt_widget_set_focus(box->active, TRUE); | |
847 } | |
848 | |
849 if (GNT_WIDGET(box)->window) | |
850 gnt_widget_draw(GNT_WIDGET(box)); | |
851 } | |
852 | |
853 void gnt_box_give_focus_to_child(GntBox *box, GntWidget *widget) | |
854 { | |
21626
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
855 GList *find; |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
856 gpointer now; |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
857 |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
858 while (GNT_WIDGET(box)->parent) |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
859 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
|
860 |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
861 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
|
862 now = box->active; |
15817 | 863 if (find) |
864 box->active = widget; | |
865 if (now && now != box->active) | |
866 { | |
867 gnt_widget_set_focus(now, FALSE); | |
868 gnt_widget_set_focus(box->active, TRUE); | |
869 } | |
870 | |
871 if (GNT_WIDGET(box)->window) | |
872 gnt_widget_draw(GNT_WIDGET(box)); | |
873 } | |
874 |