Mercurial > pidgin
annotate finch/libgnt/gntbox.c @ 28680:2ac6d4c56a43
Update a bunch of translations.
Fixes #10842, #10841, #10840, #10838, #10836, #10834, #10806, #10679.
author | John Bailey <rekkanoryo@rekkanoryo.org> |
---|---|
date | Mon, 30 Nov 2009 02:00:13 +0000 |
parents | a18f421696dc |
children | 33a4d72232a7 |
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 |
28604
a18f421696dc
Fix showing umlauts etc. on non-utf8 locales.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28342
diff
changeset
|
23 #include "gntinternal.h" |
15817 | 24 #include "gntbox.h" |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
25 #include "gntstyle.h" |
15817 | 26 #include "gntutils.h" |
27 | |
28 #include <string.h> | |
29 | |
30 enum | |
31 { | |
21261
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_0, |
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_VERTICAL, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
34 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
|
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 |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
37 enum |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
38 { |
15817 | 39 SIGS = 1, |
40 }; | |
41 | |
42 static GntWidgetClass *parent_class = NULL; | |
43 | |
44 static GntWidget * find_focusable_widget(GntBox *box); | |
45 | |
46 static void | |
47 add_to_focus(gpointer value, gpointer data) | |
48 { | |
49 GntBox *box = GNT_BOX(data); | |
50 GntWidget *w = GNT_WIDGET(value); | |
51 | |
52 if (GNT_IS_BOX(w)) | |
53 g_list_foreach(GNT_BOX(w)->list, add_to_focus, box); | |
54 else if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_CAN_TAKE_FOCUS)) | |
55 box->focus = g_list_append(box->focus, w); | |
56 } | |
57 | |
58 static void | |
59 get_title_thingies(GntBox *box, char *title, int *p, int *r) | |
60 { | |
61 GntWidget *widget = GNT_WIDGET(box); | |
62 int len; | |
63 char *end = (char*)gnt_util_onscreen_width_to_pointer(title, widget->priv.width - 4, &len); | |
64 | |
65 if (p) | |
66 *p = (widget->priv.width - len) / 2; | |
67 if (r) | |
68 *r = (widget->priv.width + len) / 2; | |
69 *end = '\0'; | |
70 } | |
71 | |
72 static void | |
73 gnt_box_draw(GntWidget *widget) | |
74 { | |
75 GntBox *box = GNT_BOX(widget); | |
76 | |
77 if (box->focus == NULL && widget->parent == NULL) | |
78 g_list_foreach(box->list, add_to_focus, box); | |
79 | |
80 g_list_foreach(box->list, (GFunc)gnt_widget_draw, NULL); | |
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); | |
26439
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
25322
diff
changeset
|
86 |
15817 | 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)); |
28604
a18f421696dc
Fix showing umlauts etc. on non-utf8 locales.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28342
diff
changeset
|
94 mvwaddstr(widget->window, 0, pos, C_(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 } | |
26439
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
25322
diff
changeset
|
98 |
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
25322
diff
changeset
|
99 gnt_box_sync_children(box); |
15817 | 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); | |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
307 gboolean ret; |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
308 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
309 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
|
310 return FALSE; |
15817 | 311 |
312 if (box->active == NULL && !find_focusable_widget(box)) | |
313 return FALSE; | |
314 | |
315 if (gnt_widget_key_pressed(box->active, text)) | |
316 return TRUE; | |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
317 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
318 /* 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
|
319 to trigger their bindings first */ |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
320 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
|
321 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
|
322 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
|
323 return ret; |
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 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
326 static gboolean |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
327 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
|
328 { |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
329 GntWidget *now; |
15817 | 330 now = box->active; |
331 | |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
332 if (next) { |
15817 | 333 find_next_focus(box); |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
334 } else { |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
335 find_prev_focus(box); |
15817 | 336 } |
337 | |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
338 if (now && now != box->active) { |
15817 | 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 | |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
347 static gboolean |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
348 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
|
349 { |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
350 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
|
351 } |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
352 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
353 static gboolean |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
354 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
|
355 { |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
356 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
|
357 } |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
358 |
15817 | 359 static void |
360 gnt_box_lost_focus(GntWidget *widget) | |
361 { | |
362 GntWidget *w = GNT_BOX(widget)->active; | |
363 if (w) | |
364 gnt_widget_set_focus(w, FALSE); | |
365 gnt_widget_draw(widget); | |
366 } | |
367 | |
368 static void | |
369 gnt_box_gained_focus(GntWidget *widget) | |
370 { | |
371 GntWidget *w = GNT_BOX(widget)->active; | |
372 if (w) | |
373 gnt_widget_set_focus(w, TRUE); | |
374 gnt_widget_draw(widget); | |
375 } | |
376 | |
377 static void | |
378 gnt_box_destroy(GntWidget *w) | |
379 { | |
380 GntBox *box = GNT_BOX(w); | |
381 | |
382 gnt_box_remove_all(box); | |
383 gnt_screen_release(w); | |
384 } | |
385 | |
386 static void | |
387 gnt_box_expose(GntWidget *widget, int x, int y, int width, int height) | |
388 { | |
389 WINDOW *win = newwin(height, width, widget->priv.y + y, widget->priv.x + x); | |
390 copywin(widget->window, win, y, x, 0, 0, height - 1, width - 1, FALSE); | |
391 wrefresh(win); | |
392 delwin(win); | |
393 } | |
394 | |
395 static gboolean | |
396 gnt_box_confirm_size(GntWidget *widget, int width, int height) | |
397 { | |
398 GList *iter; | |
399 GntBox *box = GNT_BOX(widget); | |
400 int wchange, hchange; | |
401 | |
402 if (!box->list) | |
403 return TRUE; | |
404 | |
405 wchange = widget->priv.width - width; | |
406 hchange = widget->priv.height - height; | |
407 | |
408 if (wchange == 0 && hchange == 0) | |
409 return TRUE; /* Quit playing games */ | |
410 | |
411 /* XXX: Right now, I am trying to just apply all the changes to | |
412 * just one widget. It should be possible to distribute the | |
413 * changes to all the widgets in the box. */ | |
414 for (iter = box->list; iter; iter = iter->next) | |
415 { | |
416 GntWidget *wid = iter->data; | |
417 int w, h; | |
418 | |
419 gnt_widget_get_size(wid, &w, &h); | |
420 | |
421 if (gnt_widget_confirm_size(wid, w - wchange, h - hchange)) | |
422 { | |
423 GList *i; | |
424 | |
425 for (i = box->list; i; i = i->next) | |
426 { | |
427 int tw, th; | |
428 if (i == iter) continue; | |
429 gnt_widget_get_size(GNT_WIDGET(i->data), &tw, &th); | |
430 if (box->vertical) | |
431 { | |
15945
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
432 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
|
433 /* 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
|
434 * 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
|
435 * resizing. */ |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
436 if (wchange > 0 && tw >= widget->priv.width) |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
437 return FALSE; |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
438 } |
15817 | 439 } |
440 else | |
441 { | |
15945
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
442 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
|
443 if (hchange > 0 && th >= widget->priv.height) |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
444 return FALSE; |
15817 | 445 return FALSE; |
15945
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
446 } |
15817 | 447 } |
448 } | |
449 #if 0 | |
450 gnt_widget_set_size(wid, w - wchange, h - hchange); | |
451 if (box->vertical) | |
452 hchange = 0; | |
453 else | |
454 wchange = 0; | |
455 | |
456 for (i = box->list; i; i = i->next) | |
457 { | |
458 int tw, th; | |
459 if (i == iter) continue; | |
460 gnt_widget_get_size(GNT_WIDGET(i->data), &tw, &th); | |
461 gnt_widget_set_size(i->data, tw - wchange, th - hchange); | |
462 } | |
463 #endif | |
464 g_object_set_data(G_OBJECT(box), "size-queued", wid); | |
465 return TRUE; | |
466 } | |
467 } | |
468 | |
469 return FALSE; | |
470 } | |
471 | |
472 static void | |
473 gnt_box_size_changed(GntWidget *widget, int oldw, int oldh) | |
474 { | |
475 int wchange, hchange; | |
476 GList *i; | |
477 GntBox *box = GNT_BOX(widget); | |
478 GntWidget *wid; | |
479 int tw, th; | |
480 | |
481 wchange = widget->priv.width - oldw; | |
482 hchange = widget->priv.height - oldh; | |
483 | |
484 wid = g_object_get_data(G_OBJECT(box), "size-queued"); | |
485 if (wid) | |
486 { | |
487 gnt_widget_get_size(wid, &tw, &th); | |
488 gnt_widget_set_size(wid, tw + wchange, th + hchange); | |
489 g_object_set_data(G_OBJECT(box), "size-queued", NULL); | |
490 } | |
491 | |
492 if (box->vertical) | |
493 hchange = 0; | |
494 else | |
495 wchange = 0; | |
496 | |
497 for (i = box->list; i; i = i->next) | |
498 { | |
499 if (wid != i->data) | |
500 { | |
501 gnt_widget_get_size(GNT_WIDGET(i->data), &tw, &th); | |
502 gnt_widget_set_size(i->data, tw + wchange, th + hchange); | |
503 } | |
504 } | |
505 | |
506 reposition_children(widget); | |
507 } | |
508 | |
509 static gboolean | |
510 gnt_box_clicked(GntWidget *widget, GntMouseEvent event, int cx, int cy) | |
511 { | |
512 GList *iter; | |
513 for (iter = GNT_BOX(widget)->list; iter; iter = iter->next) { | |
514 int x, y, w, h; | |
515 GntWidget *wid = iter->data; | |
516 | |
517 gnt_widget_get_position(wid, &x, &y); | |
518 gnt_widget_get_size(wid, &w, &h); | |
519 | |
520 if (cx >= x && cx < x + w && cy >= y && cy < y + h) { | |
521 if (event <= GNT_MIDDLE_MOUSE_DOWN && | |
522 GNT_WIDGET_IS_FLAG_SET(wid, GNT_WIDGET_CAN_TAKE_FOCUS)) { | |
523 while (widget->parent) | |
524 widget = widget->parent; | |
525 gnt_box_give_focus_to_child(GNT_BOX(widget), wid); | |
526 } | |
527 return gnt_widget_clicked(wid, event, cx, cy); | |
528 } | |
529 } | |
530 return FALSE; | |
531 } | |
532 | |
533 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
|
534 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
|
535 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
|
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 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
|
538 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
|
539 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
|
540 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
|
541 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
542 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
|
543 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
|
544 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
545 default: |
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_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
|
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 } |
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 |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
551 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
|
552 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
|
553 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
|
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 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
|
556 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
|
557 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
|
558 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
|
559 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
560 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
|
561 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
|
562 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
563 default: |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
564 break; |
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 |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
568 static void |
15817 | 569 gnt_box_class_init(GntBoxClass *klass) |
570 { | |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
571 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
|
572 GObjectClass *gclass = G_OBJECT_CLASS(klass); |
15817 | 573 parent_class = GNT_WIDGET_CLASS(klass); |
574 parent_class->destroy = gnt_box_destroy; | |
575 parent_class->draw = gnt_box_draw; | |
576 parent_class->expose = gnt_box_expose; | |
577 parent_class->map = gnt_box_map; | |
578 parent_class->size_request = gnt_box_size_request; | |
579 parent_class->set_position = gnt_box_set_position; | |
580 parent_class->key_pressed = gnt_box_key_pressed; | |
581 parent_class->clicked = gnt_box_clicked; | |
582 parent_class->lost_focus = gnt_box_lost_focus; | |
583 parent_class->gained_focus = gnt_box_gained_focus; | |
584 parent_class->confirm_size = gnt_box_confirm_size; | |
585 parent_class->size_changed = gnt_box_size_changed; | |
586 | |
21261
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->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
|
588 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
|
589 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
|
590 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
|
591 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
|
592 "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
|
593 TRUE, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
594 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
|
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 ); |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
597 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
|
598 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
|
599 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
|
600 "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
|
601 TRUE, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
602 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
|
603 ) |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
604 ); |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
605 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
606 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
|
607 "\t", NULL); |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
608 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
|
609 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
|
610 GNT_KEY_BACK_TAB, NULL); |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
611 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
|
612 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
613 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), bindable); |
15817 | 614 } |
615 | |
616 static void | |
617 gnt_box_init(GTypeInstance *instance, gpointer class) | |
618 { | |
619 GntWidget *widget = GNT_WIDGET(instance); | |
620 GntBox *box = GNT_BOX(widget); | |
621 /* Initially make both the height and width resizable. | |
622 * Update the flags as necessary when widgets are added to it. */ | |
623 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
|
624 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS | GNT_WIDGET_DISABLE_ACTIONS); |
15817 | 625 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); |
626 box->pad = 1; | |
627 box->fill = TRUE; | |
628 GNTDEBUG; | |
629 } | |
630 | |
631 /****************************************************************************** | |
632 * GntBox API | |
633 *****************************************************************************/ | |
634 GType | |
635 gnt_box_get_gtype(void) | |
636 { | |
637 static GType type = 0; | |
638 | |
639 if(type == 0) | |
640 { | |
641 static const GTypeInfo info = { | |
642 sizeof(GntBoxClass), | |
643 NULL, /* base_init */ | |
644 NULL, /* base_finalize */ | |
645 (GClassInitFunc)gnt_box_class_init, | |
646 NULL, /* class_finalize */ | |
647 NULL, /* class_data */ | |
648 sizeof(GntBox), | |
649 0, /* n_preallocs */ | |
650 gnt_box_init, /* instance_init */ | |
651 NULL /* value_table */ | |
652 }; | |
653 | |
654 type = g_type_register_static(GNT_TYPE_WIDGET, | |
655 "GntBox", | |
656 &info, 0); | |
657 } | |
658 | |
659 return type; | |
660 } | |
661 | |
662 GntWidget *gnt_box_new(gboolean homo, gboolean vert) | |
663 { | |
664 GntWidget *widget = g_object_new(GNT_TYPE_BOX, NULL); | |
665 GntBox *box = GNT_BOX(widget); | |
666 | |
667 box->homogeneous = homo; | |
668 box->vertical = vert; | |
669 box->alignment = vert ? GNT_ALIGN_LEFT : GNT_ALIGN_MID; | |
670 | |
671 return widget; | |
672 } | |
673 | |
674 void gnt_box_add_widget(GntBox *b, GntWidget *widget) | |
675 { | |
676 b->list = g_list_append(b->list, widget); | |
677 widget->parent = GNT_WIDGET(b); | |
678 } | |
679 | |
680 void gnt_box_set_title(GntBox *b, const char *title) | |
681 { | |
682 char *prev = b->title; | |
683 GntWidget *w = GNT_WIDGET(b); | |
684 b->title = g_strdup(title); | |
685 if (w->window && !GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_NO_BORDER)) { | |
686 /* Erase the old title */ | |
687 int pos, right; | |
688 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
|
689 mvwhline(w->window, 0, pos - 1, ACS_HLINE | gnt_color_pair(GNT_COLOR_NORMAL), |
15817 | 690 right - pos + 2); |
691 } | |
28342 | 692 g_free(prev); |
15817 | 693 } |
694 | |
695 void gnt_box_set_pad(GntBox *box, int pad) | |
696 { | |
697 box->pad = pad; | |
698 /* XXX: Perhaps redraw if already showing? */ | |
699 } | |
700 | |
701 void gnt_box_set_toplevel(GntBox *box, gboolean set) | |
702 { | |
703 GntWidget *widget = GNT_WIDGET(box); | |
704 if (set) | |
705 { | |
706 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); | |
707 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS); | |
708 } | |
709 else | |
710 { | |
711 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); | |
712 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS); | |
713 } | |
714 } | |
715 | |
716 void gnt_box_sync_children(GntBox *box) | |
717 { | |
718 GList *iter; | |
719 GntWidget *widget = GNT_WIDGET(box); | |
720 int pos = 1; | |
721 | |
722 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
723 pos = 0; | |
724 | |
26439
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
25322
diff
changeset
|
725 if (!box->active) |
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
25322
diff
changeset
|
726 find_focusable_widget(box); |
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
25322
diff
changeset
|
727 |
15817 | 728 for (iter = box->list; iter; iter = iter->next) |
729 { | |
730 GntWidget *w = GNT_WIDGET(iter->data); | |
731 int height, width; | |
732 int x, y; | |
733 | |
734 if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_INVISIBLE)) | |
735 continue; | |
736 | |
737 if (GNT_IS_BOX(w)) | |
738 gnt_box_sync_children(GNT_BOX(w)); | |
739 | |
740 gnt_widget_get_size(w, &width, &height); | |
741 | |
742 x = w->priv.x - widget->priv.x; | |
743 y = w->priv.y - widget->priv.y; | |
744 | |
745 if (box->vertical) | |
746 { | |
747 x = pos; | |
748 if (box->alignment == GNT_ALIGN_RIGHT) | |
749 x += widget->priv.width - width; | |
750 else if (box->alignment == GNT_ALIGN_MID) | |
751 x += (widget->priv.width - width)/2; | |
752 if (x + width > widget->priv.width - pos) | |
753 x -= x + width - (widget->priv.width - pos); | |
754 } | |
755 else | |
756 { | |
757 y = pos; | |
758 if (box->alignment == GNT_ALIGN_BOTTOM) | |
759 y += widget->priv.height - height; | |
760 else if (box->alignment == GNT_ALIGN_MID) | |
761 y += (widget->priv.height - height)/2; | |
762 if (y + height >= widget->priv.height - pos) | |
763 y = widget->priv.height - height - pos; | |
764 } | |
765 | |
766 copywin(w->window, widget->window, 0, 0, | |
767 y, x, y + height - 1, x + width - 1, FALSE); | |
768 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
|
769 if (w == box->active) { |
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
25322
diff
changeset
|
770 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
|
771 } |
15817 | 772 } |
773 } | |
774 | |
775 void gnt_box_set_alignment(GntBox *box, GntAlignment alignment) | |
776 { | |
777 box->alignment = alignment; | |
778 } | |
779 | |
780 void gnt_box_remove(GntBox *box, GntWidget *widget) | |
781 { | |
782 box->list = g_list_remove(box->list, widget); | |
783 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_CAN_TAKE_FOCUS) | |
784 && GNT_WIDGET(box)->parent == NULL && box->focus) | |
785 { | |
786 if (widget == box->active) | |
787 { | |
788 find_next_focus(box); | |
789 if (box->active == widget) /* There's only one widget */ | |
790 box->active = NULL; | |
791 } | |
792 box->focus = g_list_remove(box->focus, widget); | |
793 } | |
794 | |
795 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(box), GNT_WIDGET_MAPPED)) | |
796 gnt_widget_draw(GNT_WIDGET(box)); | |
797 } | |
798 | |
799 void gnt_box_remove_all(GntBox *box) | |
800 { | |
801 g_list_foreach(box->list, (GFunc)gnt_widget_destroy, NULL); | |
802 g_list_free(box->list); | |
803 g_list_free(box->focus); | |
804 box->list = NULL; | |
805 box->focus = NULL; | |
806 GNT_WIDGET(box)->priv.width = 0; | |
807 GNT_WIDGET(box)->priv.height = 0; | |
808 } | |
809 | |
810 void gnt_box_readjust(GntBox *box) | |
811 { | |
812 GList *iter; | |
813 GntWidget *wid; | |
814 int width, height; | |
815 | |
816 if (GNT_WIDGET(box)->parent != NULL) | |
817 return; | |
818 | |
819 for (iter = box->list; iter; iter = iter->next) | |
820 { | |
821 GntWidget *w = iter->data; | |
822 if (GNT_IS_BOX(w)) | |
823 gnt_box_readjust(GNT_BOX(w)); | |
824 else | |
825 { | |
826 GNT_WIDGET_UNSET_FLAGS(w, GNT_WIDGET_MAPPED); | |
827 w->priv.width = 0; | |
828 w->priv.height = 0; | |
829 } | |
830 } | |
831 | |
832 wid = GNT_WIDGET(box); | |
833 GNT_WIDGET_UNSET_FLAGS(wid, GNT_WIDGET_MAPPED); | |
834 wid->priv.width = 0; | |
835 wid->priv.height = 0; | |
836 | |
837 if (wid->parent == NULL) | |
838 { | |
839 g_list_free(box->focus); | |
840 box->focus = NULL; | |
841 box->active = NULL; | |
842 gnt_widget_size_request(wid); | |
843 gnt_widget_get_size(wid, &width, &height); | |
844 gnt_screen_resize_widget(wid, width, height); | |
845 find_focusable_widget(box); | |
846 } | |
847 } | |
848 | |
849 void gnt_box_set_fill(GntBox *box, gboolean fill) | |
850 { | |
851 box->fill = fill; | |
852 } | |
853 | |
854 void gnt_box_move_focus(GntBox *box, int dir) | |
855 { | |
856 GntWidget *now; | |
857 | |
858 if (box->active == NULL) | |
859 { | |
860 find_focusable_widget(box); | |
861 return; | |
862 } | |
863 | |
864 now = box->active; | |
865 | |
866 if (dir == 1) | |
867 find_next_focus(box); | |
868 else if (dir == -1) | |
869 find_prev_focus(box); | |
870 | |
871 if (now && now != box->active) | |
872 { | |
873 gnt_widget_set_focus(now, FALSE); | |
874 gnt_widget_set_focus(box->active, TRUE); | |
875 } | |
876 | |
877 if (GNT_WIDGET(box)->window) | |
878 gnt_widget_draw(GNT_WIDGET(box)); | |
879 } | |
880 | |
881 void gnt_box_give_focus_to_child(GntBox *box, GntWidget *widget) | |
882 { | |
21626
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
883 GList *find; |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
884 gpointer now; |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
885 |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
886 while (GNT_WIDGET(box)->parent) |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
887 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
|
888 |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
889 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
|
890 now = box->active; |
15817 | 891 if (find) |
892 box->active = widget; | |
893 if (now && now != box->active) | |
894 { | |
895 gnt_widget_set_focus(now, FALSE); | |
896 gnt_widget_set_focus(box->active, TRUE); | |
897 } | |
898 | |
899 if (GNT_WIDGET(box)->window) | |
900 gnt_widget_draw(GNT_WIDGET(box)); | |
901 } | |
902 |