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