Mercurial > pidgin.yaz
annotate finch/libgnt/gntbox.c @ 30291:5c639069557d
disapproval of revision '5f410e729e7a8a2e46752d46b37a7c11e17d5ed7'
In favor of Evan's changes
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Tue, 04 May 2010 02:22:26 +0000 |
parents | 5d3f64f8e7b5 |
children | b3c4f33643a6 |
rev | line source |
---|---|
18049
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
1 /** |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
3 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
6 * source distribution. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
7 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
11 * (at your option) any later version. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
12 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
16 * GNU General Public License for more details. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
17 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
19680
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18538
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
18049
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
21 */ |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
22 |
28984
a18f421696dc
Fix showing umlauts etc. on non-utf8 locales.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28709
diff
changeset
|
23 #include "gntinternal.h" |
15818 | 24 #include "gntbox.h" |
24958
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
25 #include "gntstyle.h" |
15818 | 26 #include "gntutils.h" |
27 | |
28 #include <string.h> | |
29 | |
30036
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
30 #define PROP_LAST_RESIZE_S "last-resize" |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
31 #define PROP_SIZE_QUEUED_S "size-queued" |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
32 |
15818 | 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 { |
15818 | 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); | |
67 | |
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); | |
26521
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
24958
diff
changeset
|
89 |
15818 | 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:
19680
diff
changeset
|
93 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_TITLE)); |
15818 | 94 else |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
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:
19680
diff
changeset
|
96 mvwaddch(widget->window, 0, pos-1, ACS_RTEE | gnt_color_pair(GNT_COLOR_NORMAL)); |
28984
a18f421696dc
Fix showing umlauts etc. on non-utf8 locales.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28709
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:
19680
diff
changeset
|
98 mvwaddch(widget->window, 0, right, ACS_LTEE | gnt_color_pair(GNT_COLOR_NORMAL)); |
15818 | 99 g_free(title); |
100 } | |
26521
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
24958
diff
changeset
|
101 |
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
24958
diff
changeset
|
102 gnt_box_sync_children(box); |
15818 | 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; | |
30036
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
200 |
15818 | 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); |
15818 | 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; | |
23001
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)) |
15818 | 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); | |
24958
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
310 gboolean ret; |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
311 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
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:
23001
diff
changeset
|
313 return FALSE; |
15818 | 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; | |
24958
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
320 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
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:
23001
diff
changeset
|
322 to trigger their bindings first */ |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
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:
23001
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:
23001
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:
23001
diff
changeset
|
326 return ret; |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
327 } |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
328 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
329 static gboolean |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
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:
23001
diff
changeset
|
331 { |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
332 GntWidget *now; |
15818 | 333 now = box->active; |
334 | |
24958
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
335 if (next) { |
15818 | 336 find_next_focus(box); |
24958
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
337 } else { |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
338 find_prev_focus(box); |
15818 | 339 } |
340 | |
24958
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
341 if (now && now != box->active) { |
15818 | 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 | |
24958
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
350 static gboolean |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
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:
23001
diff
changeset
|
352 { |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
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:
23001
diff
changeset
|
354 } |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
355 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
356 static gboolean |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
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:
23001
diff
changeset
|
358 { |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
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:
23001
diff
changeset
|
360 } |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
361 |
15818 | 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; | |
30036
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
404 GntWidget *child, *last; |
15818 | 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) | |
30036
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
413 return TRUE; /* Quit playing games with my size */ |
15818 | 414 |
30036
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
415 child = NULL; |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
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:
28984
diff
changeset
|
417 |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
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:
28984
diff
changeset
|
419 for (iter = box->list; iter; iter = iter->next) { |
15818 | 420 GntWidget *wid = iter->data; |
421 int w, h; | |
422 | |
423 gnt_widget_get_size(wid, &w, &h); | |
424 | |
30067
5d3f64f8e7b5
Tweak the box-resizing a bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30036
diff
changeset
|
425 if (wid != last && !child && w > 0 && h > 0 && gnt_widget_confirm_size(wid, w - wchange, h - hchange)) { |
30036
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
426 child = wid; |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
427 break; |
15818 | 428 } |
429 } | |
430 | |
30036
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
431 if (!child && (child = last)) { |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
432 int w, h; |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
433 gnt_widget_get_size(child, &w, &h); |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
434 if (!gnt_widget_confirm_size(child, w - wchange, h - hchange)) |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
435 child = NULL; |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
436 } |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
437 |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
438 g_object_set_data(G_OBJECT(box), PROP_SIZE_QUEUED_S, child); |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
439 |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
440 if (child) { |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
441 for (iter = box->list; iter; iter = iter->next) { |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
442 GntWidget *wid = iter->data; |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
443 int w, h; |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
444 |
30067
5d3f64f8e7b5
Tweak the box-resizing a bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30036
diff
changeset
|
445 if (wid == child) |
5d3f64f8e7b5
Tweak the box-resizing a bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30036
diff
changeset
|
446 continue; |
5d3f64f8e7b5
Tweak the box-resizing a bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30036
diff
changeset
|
447 |
30036
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
448 gnt_widget_get_size(wid, &w, &h); |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
449 if (box->vertical) { |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
450 /* 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:
28984
diff
changeset
|
451 * in the box will fit after resizing the width. */ |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
452 if (wchange > 0 && |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
453 w >= child->priv.width && |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
454 !gnt_widget_confirm_size(wid, w - wchange, h)) |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
455 return FALSE; |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
456 } else { |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
457 /* 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:
28984
diff
changeset
|
458 * the resize. */ |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
459 if (hchange > 0 && |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
460 h >= child->priv.height && |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
461 !gnt_widget_confirm_size(wid, w, h - hchange)) |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
462 return FALSE; |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
463 } |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
464 |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
465 } |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
466 } |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
467 |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
468 return (child != NULL); |
15818 | 469 } |
470 | |
471 static void | |
472 gnt_box_size_changed(GntWidget *widget, int oldw, int oldh) | |
473 { | |
474 int wchange, hchange; | |
475 GList *i; | |
476 GntBox *box = GNT_BOX(widget); | |
477 GntWidget *wid; | |
478 int tw, th; | |
30036
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
479 |
15818 | 480 wchange = widget->priv.width - oldw; |
481 hchange = widget->priv.height - oldh; | |
30036
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
482 |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
483 wid = g_object_get_data(G_OBJECT(box), PROP_SIZE_QUEUED_S); |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
484 if (wid) { |
15818 | 485 gnt_widget_get_size(wid, &tw, &th); |
486 gnt_widget_set_size(wid, tw + wchange, th + hchange); | |
30036
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
487 g_object_set_data(G_OBJECT(box), PROP_SIZE_QUEUED_S, NULL); |
33a4d72232a7
Improve resizing a box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
488 g_object_set_data(G_OBJECT(box), PROP_LAST_RESIZE_S, wid); |
15818 | 489 } |
490 | |
491 if (box->vertical) | |
492 hchange = 0; | |
493 else | |
494 wchange = 0; | |
495 | |
496 for (i = box->list; i; i = i->next) | |
497 { | |
498 if (wid != i->data) | |
499 { | |
500 gnt_widget_get_size(GNT_WIDGET(i->data), &tw, &th); | |
501 gnt_widget_set_size(i->data, tw + wchange, th + hchange); | |
502 } | |
503 } | |
504 | |
505 reposition_children(widget); | |
506 } | |
507 | |
508 static gboolean | |
509 gnt_box_clicked(GntWidget *widget, GntMouseEvent event, int cx, int cy) | |
510 { | |
511 GList *iter; | |
512 for (iter = GNT_BOX(widget)->list; iter; iter = iter->next) { | |
513 int x, y, w, h; | |
514 GntWidget *wid = iter->data; | |
515 | |
516 gnt_widget_get_position(wid, &x, &y); | |
517 gnt_widget_get_size(wid, &w, &h); | |
518 | |
519 if (cx >= x && cx < x + w && cy >= y && cy < y + h) { | |
520 if (event <= GNT_MIDDLE_MOUSE_DOWN && | |
521 GNT_WIDGET_IS_FLAG_SET(wid, GNT_WIDGET_CAN_TAKE_FOCUS)) { | |
522 while (widget->parent) | |
523 widget = widget->parent; | |
524 gnt_box_give_focus_to_child(GNT_BOX(widget), wid); | |
525 } | |
526 return gnt_widget_clicked(wid, event, cx, cy); | |
527 } | |
528 } | |
529 return FALSE; | |
530 } | |
531 | |
532 static void | |
21261
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
533 gnt_box_set_property(GObject *obj, guint prop_id, const GValue *value, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
534 GParamSpec *spec) |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
535 { |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
536 GntBox *box = GNT_BOX(obj); |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
537 switch (prop_id) { |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
538 case PROP_VERTICAL: |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
539 box->vertical = g_value_get_boolean(value); |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
540 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
541 case PROP_HOMO: |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
542 box->homogeneous = g_value_get_boolean(value); |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
543 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
544 default: |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
545 g_return_if_reached(); |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
546 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
547 } |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
548 } |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
549 |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
550 static void |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
551 gnt_box_get_property(GObject *obj, guint prop_id, GValue *value, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
552 GParamSpec *spec) |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
553 { |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
554 GntBox *box = GNT_BOX(obj); |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
555 switch (prop_id) { |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
556 case PROP_VERTICAL: |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
557 g_value_set_boolean(value, box->vertical); |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
558 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
559 case PROP_HOMO: |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
560 g_value_set_boolean(value, box->homogeneous); |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
561 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
562 default: |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
563 break; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
564 } |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
565 } |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
566 |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
567 static void |
15818 | 568 gnt_box_class_init(GntBoxClass *klass) |
569 { | |
24958
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
570 GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass); |
21261
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
571 GObjectClass *gclass = G_OBJECT_CLASS(klass); |
15818 | 572 parent_class = GNT_WIDGET_CLASS(klass); |
573 parent_class->destroy = gnt_box_destroy; | |
574 parent_class->draw = gnt_box_draw; | |
575 parent_class->expose = gnt_box_expose; | |
576 parent_class->map = gnt_box_map; | |
577 parent_class->size_request = gnt_box_size_request; | |
578 parent_class->set_position = gnt_box_set_position; | |
579 parent_class->key_pressed = gnt_box_key_pressed; | |
580 parent_class->clicked = gnt_box_clicked; | |
581 parent_class->lost_focus = gnt_box_lost_focus; | |
582 parent_class->gained_focus = gnt_box_gained_focus; | |
583 parent_class->confirm_size = gnt_box_confirm_size; | |
584 parent_class->size_changed = gnt_box_size_changed; | |
585 | |
21261
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
586 gclass->set_property = gnt_box_set_property; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
587 gclass->get_property = gnt_box_get_property; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
588 g_object_class_install_property(gclass, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
589 PROP_VERTICAL, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
590 g_param_spec_boolean("vertical", "Vertical", |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
591 "Whether the child widgets in the box should be stacked vertically.", |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
592 TRUE, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
593 G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
594 ) |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
595 ); |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
596 g_object_class_install_property(gclass, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
597 PROP_HOMO, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
598 g_param_spec_boolean("homogeneous", "Homogeneous", |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
599 "Whether the child widgets in the box should have the same size.", |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
600 TRUE, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
601 G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
602 ) |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
603 ); |
24958
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
604 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
605 gnt_bindable_class_register_action(bindable, "focus-next", action_focus_next, |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
606 "\t", NULL); |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
607 gnt_bindable_register_binding(bindable, "focus-next", GNT_KEY_RIGHT, NULL); |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
608 gnt_bindable_class_register_action(bindable, "focus-prev", action_focus_prev, |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
609 GNT_KEY_BACK_TAB, NULL); |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
610 gnt_bindable_register_binding(bindable, "focus-prev", GNT_KEY_LEFT, NULL); |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
611 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
612 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), bindable); |
15818 | 613 } |
614 | |
615 static void | |
616 gnt_box_init(GTypeInstance *instance, gpointer class) | |
617 { | |
618 GntWidget *widget = GNT_WIDGET(instance); | |
619 GntBox *box = GNT_BOX(widget); | |
620 /* Initially make both the height and width resizable. | |
621 * Update the flags as necessary when widgets are added to it. */ | |
622 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y); | |
24958
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23001
diff
changeset
|
623 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS | GNT_WIDGET_DISABLE_ACTIONS); |
15818 | 624 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); |
625 box->pad = 1; | |
626 box->fill = TRUE; | |
627 GNTDEBUG; | |
628 } | |
629 | |
630 /****************************************************************************** | |
631 * GntBox API | |
632 *****************************************************************************/ | |
633 GType | |
634 gnt_box_get_gtype(void) | |
635 { | |
636 static GType type = 0; | |
637 | |
638 if(type == 0) | |
639 { | |
640 static const GTypeInfo info = { | |
641 sizeof(GntBoxClass), | |
642 NULL, /* base_init */ | |
643 NULL, /* base_finalize */ | |
644 (GClassInitFunc)gnt_box_class_init, | |
645 NULL, /* class_finalize */ | |
646 NULL, /* class_data */ | |
647 sizeof(GntBox), | |
648 0, /* n_preallocs */ | |
649 gnt_box_init, /* instance_init */ | |
650 NULL /* value_table */ | |
651 }; | |
652 | |
653 type = g_type_register_static(GNT_TYPE_WIDGET, | |
654 "GntBox", | |
655 &info, 0); | |
656 } | |
657 | |
658 return type; | |
659 } | |
660 | |
661 GntWidget *gnt_box_new(gboolean homo, gboolean vert) | |
662 { | |
663 GntWidget *widget = g_object_new(GNT_TYPE_BOX, NULL); | |
664 GntBox *box = GNT_BOX(widget); | |
665 | |
666 box->homogeneous = homo; | |
667 box->vertical = vert; | |
668 box->alignment = vert ? GNT_ALIGN_LEFT : GNT_ALIGN_MID; | |
669 | |
670 return widget; | |
671 } | |
672 | |
673 void gnt_box_add_widget(GntBox *b, GntWidget *widget) | |
674 { | |
675 b->list = g_list_append(b->list, widget); | |
676 widget->parent = GNT_WIDGET(b); | |
677 } | |
678 | |
679 void gnt_box_set_title(GntBox *b, const char *title) | |
680 { | |
681 char *prev = b->title; | |
682 GntWidget *w = GNT_WIDGET(b); | |
683 b->title = g_strdup(title); | |
684 if (w->window && !GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_NO_BORDER)) { | |
685 /* Erase the old title */ | |
686 int pos, right; | |
687 get_title_thingies(b, prev, &pos, &right); | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
688 mvwhline(w->window, 0, pos - 1, ACS_HLINE | gnt_color_pair(GNT_COLOR_NORMAL), |
15818 | 689 right - pos + 2); |
690 } | |
28709 | 691 g_free(prev); |
15818 | 692 } |
693 | |
694 void gnt_box_set_pad(GntBox *box, int pad) | |
695 { | |
696 box->pad = pad; | |
697 /* XXX: Perhaps redraw if already showing? */ | |
698 } | |
699 | |
700 void gnt_box_set_toplevel(GntBox *box, gboolean set) | |
701 { | |
702 GntWidget *widget = GNT_WIDGET(box); | |
703 if (set) | |
704 { | |
705 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); | |
706 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS); | |
707 } | |
708 else | |
709 { | |
710 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); | |
711 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS); | |
712 } | |
713 } | |
714 | |
715 void gnt_box_sync_children(GntBox *box) | |
716 { | |
717 GList *iter; | |
718 GntWidget *widget = GNT_WIDGET(box); | |
719 int pos = 1; | |
720 | |
721 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
722 pos = 0; | |
723 | |
26521
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
24958
diff
changeset
|
724 if (!box->active) |
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
24958
diff
changeset
|
725 find_focusable_widget(box); |
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
24958
diff
changeset
|
726 |
15818 | 727 for (iter = box->list; iter; iter = iter->next) |
728 { | |
729 GntWidget *w = GNT_WIDGET(iter->data); | |
730 int height, width; | |
731 int x, y; | |
732 | |
733 if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_INVISIBLE)) | |
734 continue; | |
735 | |
736 if (GNT_IS_BOX(w)) | |
737 gnt_box_sync_children(GNT_BOX(w)); | |
738 | |
739 gnt_widget_get_size(w, &width, &height); | |
740 | |
741 x = w->priv.x - widget->priv.x; | |
742 y = w->priv.y - widget->priv.y; | |
743 | |
744 if (box->vertical) | |
745 { | |
746 x = pos; | |
747 if (box->alignment == GNT_ALIGN_RIGHT) | |
748 x += widget->priv.width - width; | |
749 else if (box->alignment == GNT_ALIGN_MID) | |
750 x += (widget->priv.width - width)/2; | |
751 if (x + width > widget->priv.width - pos) | |
752 x -= x + width - (widget->priv.width - pos); | |
753 } | |
754 else | |
755 { | |
756 y = pos; | |
757 if (box->alignment == GNT_ALIGN_BOTTOM) | |
758 y += widget->priv.height - height; | |
759 else if (box->alignment == GNT_ALIGN_MID) | |
760 y += (widget->priv.height - height)/2; | |
761 if (y + height >= widget->priv.height - pos) | |
762 y = widget->priv.height - height - pos; | |
763 } | |
764 | |
765 copywin(w->window, widget->window, 0, 0, | |
766 y, x, y + height - 1, x + width - 1, FALSE); | |
767 gnt_widget_set_position(w, x + widget->priv.x, y + widget->priv.y); | |
26521
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
24958
diff
changeset
|
768 if (w == box->active) { |
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
24958
diff
changeset
|
769 wmove(widget->window, y + getcury(w->window), x + getcurx(w->window)); |
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
24958
diff
changeset
|
770 } |
15818 | 771 } |
772 } | |
773 | |
774 void gnt_box_set_alignment(GntBox *box, GntAlignment alignment) | |
775 { | |
776 box->alignment = alignment; | |
777 } | |
778 | |
779 void gnt_box_remove(GntBox *box, GntWidget *widget) | |
780 { | |
781 box->list = g_list_remove(box->list, widget); | |
782 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_CAN_TAKE_FOCUS) | |
783 && GNT_WIDGET(box)->parent == NULL && box->focus) | |
784 { | |
785 if (widget == box->active) | |
786 { | |
787 find_next_focus(box); | |
788 if (box->active == widget) /* There's only one widget */ | |
789 box->active = NULL; | |
790 } | |
791 box->focus = g_list_remove(box->focus, widget); | |
792 } | |
793 | |
794 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(box), GNT_WIDGET_MAPPED)) | |
795 gnt_widget_draw(GNT_WIDGET(box)); | |
796 } | |
797 | |
798 void gnt_box_remove_all(GntBox *box) | |
799 { | |
800 g_list_foreach(box->list, (GFunc)gnt_widget_destroy, NULL); | |
801 g_list_free(box->list); | |
802 g_list_free(box->focus); | |
803 box->list = NULL; | |
804 box->focus = NULL; | |
805 GNT_WIDGET(box)->priv.width = 0; | |
806 GNT_WIDGET(box)->priv.height = 0; | |
807 } | |
808 | |
809 void gnt_box_readjust(GntBox *box) | |
810 { | |
811 GList *iter; | |
812 GntWidget *wid; | |
813 int width, height; | |
814 | |
815 if (GNT_WIDGET(box)->parent != NULL) | |
816 return; | |
817 | |
818 for (iter = box->list; iter; iter = iter->next) | |
819 { | |
820 GntWidget *w = iter->data; | |
821 if (GNT_IS_BOX(w)) | |
822 gnt_box_readjust(GNT_BOX(w)); | |
823 else | |
824 { | |
825 GNT_WIDGET_UNSET_FLAGS(w, GNT_WIDGET_MAPPED); | |
826 w->priv.width = 0; | |
827 w->priv.height = 0; | |
828 } | |
829 } | |
830 | |
831 wid = GNT_WIDGET(box); | |
832 GNT_WIDGET_UNSET_FLAGS(wid, GNT_WIDGET_MAPPED); | |
833 wid->priv.width = 0; | |
834 wid->priv.height = 0; | |
835 | |
836 if (wid->parent == NULL) | |
837 { | |
838 g_list_free(box->focus); | |
839 box->focus = NULL; | |
840 box->active = NULL; | |
841 gnt_widget_size_request(wid); | |
842 gnt_widget_get_size(wid, &width, &height); | |
843 gnt_screen_resize_widget(wid, width, height); | |
844 find_focusable_widget(box); | |
845 } | |
846 } | |
847 | |
848 void gnt_box_set_fill(GntBox *box, gboolean fill) | |
849 { | |
850 box->fill = fill; | |
851 } | |
852 | |
853 void gnt_box_move_focus(GntBox *box, int dir) | |
854 { | |
855 GntWidget *now; | |
856 | |
857 if (box->active == NULL) | |
858 { | |
859 find_focusable_widget(box); | |
860 return; | |
861 } | |
862 | |
863 now = box->active; | |
864 | |
865 if (dir == 1) | |
866 find_next_focus(box); | |
867 else if (dir == -1) | |
868 find_prev_focus(box); | |
869 | |
870 if (now && now != box->active) | |
871 { | |
872 gnt_widget_set_focus(now, FALSE); | |
873 gnt_widget_set_focus(box->active, TRUE); | |
874 } | |
875 | |
876 if (GNT_WIDGET(box)->window) | |
877 gnt_widget_draw(GNT_WIDGET(box)); | |
878 } | |
879 | |
880 void gnt_box_give_focus_to_child(GntBox *box, GntWidget *widget) | |
881 { | |
21626
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
882 GList *find; |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
883 gpointer now; |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
884 |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
885 while (GNT_WIDGET(box)->parent) |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
886 box = GNT_BOX(GNT_WIDGET(box)->parent); |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
887 |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
888 find = g_list_find(box->focus, widget); |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
889 now = box->active; |
15818 | 890 if (find) |
891 box->active = widget; | |
892 if (now && now != box->active) | |
893 { | |
894 gnt_widget_set_focus(now, FALSE); | |
895 gnt_widget_set_focus(box->active, TRUE); | |
896 } | |
897 | |
898 if (GNT_WIDGET(box)->window) | |
899 gnt_widget_draw(GNT_WIDGET(box)); | |
900 } | |
901 |