Mercurial > pidgin
annotate finch/libgnt/gntbox.c @ 26167:4cbe258db067
fix a bug in libpurple that prevented receiving file transfers to be marked completed (in case the protocol uses an xfer->ops.read function)
author | Sulabh Mahajan <sulabh@soc.pidgin.im> |
---|---|
date | Wed, 28 Jan 2009 07:34:18 +0000 |
parents | 73e88188a7d4 |
children | c67d43408daa |
rev | line source |
---|---|
18049
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
1 /** |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
3 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
6 * source distribution. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
7 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
11 * (at your option) any later version. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
12 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
16 * GNU General Public License for more details. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
17 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
19681
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18538
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
18049
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
21 */ |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
22 |
15817 | 23 #include "gntbox.h" |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
24 #include "gntstyle.h" |
15817 | 25 #include "gntutils.h" |
26 | |
27 #include <string.h> | |
28 | |
29 enum | |
30 { | |
21261
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
31 PROP_0, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
32 PROP_VERTICAL, |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
33 PROP_HOMO /* ... */ |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
34 }; |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
35 |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
36 enum |
7f1910f62246
Add properties to boxes. This is the Right Way of doing things.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
37 { |
15817 | 38 SIGS = 1, |
39 }; | |
40 | |
41 static GntWidgetClass *parent_class = NULL; | |
42 | |
43 static GntWidget * find_focusable_widget(GntBox *box); | |
44 | |
45 static void | |
46 add_to_focus(gpointer value, gpointer data) | |
47 { | |
48 GntBox *box = GNT_BOX(data); | |
49 GntWidget *w = GNT_WIDGET(value); | |
50 | |
51 if (GNT_IS_BOX(w)) | |
52 g_list_foreach(GNT_BOX(w)->list, add_to_focus, box); | |
53 else if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_CAN_TAKE_FOCUS)) | |
54 box->focus = g_list_append(box->focus, w); | |
55 } | |
56 | |
57 static void | |
58 get_title_thingies(GntBox *box, char *title, int *p, int *r) | |
59 { | |
60 GntWidget *widget = GNT_WIDGET(box); | |
61 int len; | |
62 char *end = (char*)gnt_util_onscreen_width_to_pointer(title, widget->priv.width - 4, &len); | |
63 | |
64 if (p) | |
65 *p = (widget->priv.width - len) / 2; | |
66 if (r) | |
67 *r = (widget->priv.width + len) / 2; | |
68 *end = '\0'; | |
69 } | |
70 | |
71 static void | |
72 gnt_box_draw(GntWidget *widget) | |
73 { | |
74 GntBox *box = GNT_BOX(widget); | |
75 | |
76 if (box->focus == NULL && widget->parent == NULL) | |
77 g_list_foreach(box->list, add_to_focus, box); | |
78 | |
79 g_list_foreach(box->list, (GFunc)gnt_widget_draw, NULL); | |
80 | |
81 gnt_box_sync_children(box); | |
82 | |
83 if (box->title && !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
84 { | |
85 int pos, right; | |
86 char *title = g_strdup(box->title); | |
87 | |
88 get_title_thingies(box, title, &pos, &right); | |
89 | |
90 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
|
91 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_TITLE)); |
15817 | 92 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
|
93 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
|
94 mvwaddch(widget->window, 0, pos-1, ACS_RTEE | gnt_color_pair(GNT_COLOR_NORMAL)); |
15817 | 95 mvwaddstr(widget->window, 0, pos, title); |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
96 mvwaddch(widget->window, 0, right, ACS_LTEE | gnt_color_pair(GNT_COLOR_NORMAL)); |
15817 | 97 g_free(title); |
98 } | |
99 | |
100 GNTDEBUG; | |
101 } | |
102 | |
103 static void | |
104 reposition_children(GntWidget *widget) | |
105 { | |
106 GList *iter; | |
107 GntBox *box = GNT_BOX(widget); | |
108 int w, h, curx, cury, max; | |
109 gboolean has_border = FALSE; | |
110 | |
111 w = h = 0; | |
112 max = 0; | |
113 curx = widget->priv.x; | |
114 cury = widget->priv.y; | |
115 if (!(GNT_WIDGET_FLAGS(widget) & GNT_WIDGET_NO_BORDER)) | |
116 { | |
117 has_border = TRUE; | |
118 curx += 1; | |
119 cury += 1; | |
120 } | |
121 | |
122 for (iter = box->list; iter; iter = iter->next) | |
123 { | |
124 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(iter->data), GNT_WIDGET_INVISIBLE)) | |
125 continue; | |
126 gnt_widget_set_position(GNT_WIDGET(iter->data), curx, cury); | |
127 gnt_widget_get_size(GNT_WIDGET(iter->data), &w, &h); | |
128 if (box->vertical) | |
129 { | |
130 if (h) | |
131 { | |
132 cury += h + box->pad; | |
133 if (max < w) | |
134 max = w; | |
135 } | |
136 } | |
137 else | |
138 { | |
139 if (w) | |
140 { | |
141 curx += w + box->pad; | |
142 if (max < h) | |
143 max = h; | |
144 } | |
145 } | |
146 } | |
147 | |
148 if (has_border) | |
149 { | |
150 curx += 1; | |
151 cury += 1; | |
152 max += 2; | |
153 } | |
154 | |
155 if (box->list) | |
156 { | |
157 if (box->vertical) | |
158 cury -= box->pad; | |
159 else | |
160 curx -= box->pad; | |
161 } | |
162 | |
163 if (box->vertical) | |
164 { | |
165 widget->priv.width = max; | |
166 widget->priv.height = cury - widget->priv.y; | |
167 } | |
168 else | |
169 { | |
170 widget->priv.width = curx - widget->priv.x; | |
171 widget->priv.height = max; | |
172 } | |
173 } | |
174 | |
175 static void | |
176 gnt_box_set_position(GntWidget *widget, int x, int y) | |
177 { | |
178 GList *iter; | |
179 int changex, changey; | |
180 | |
181 changex = widget->priv.x - x; | |
182 changey = widget->priv.y - y; | |
183 | |
184 for (iter = GNT_BOX(widget)->list; iter; iter = iter->next) | |
185 { | |
186 GntWidget *w = GNT_WIDGET(iter->data); | |
187 gnt_widget_set_position(w, w->priv.x - changex, | |
188 w->priv.y - changey); | |
189 } | |
190 } | |
191 | |
192 static void | |
193 gnt_box_size_request(GntWidget *widget) | |
194 { | |
195 GntBox *box = GNT_BOX(widget); | |
196 GList *iter; | |
197 int maxw = 0, maxh = 0; | |
198 | |
199 g_list_foreach(box->list, (GFunc)gnt_widget_size_request, NULL); | |
200 | |
201 for (iter = box->list; iter; iter = iter->next) | |
202 { | |
203 int w, h; | |
204 gnt_widget_get_size(GNT_WIDGET(iter->data), &w, &h); | |
205 if (maxh < h) | |
206 maxh = h; | |
207 if (maxw < w) | |
208 maxw = w; | |
209 } | |
210 | |
211 for (iter = box->list; iter; iter = iter->next) | |
212 { | |
213 int w, h; | |
214 GntWidget *wid = GNT_WIDGET(iter->data); | |
215 | |
216 gnt_widget_get_size(wid, &w, &h); | |
217 | |
218 if (box->homogeneous) | |
219 { | |
220 if (box->vertical) | |
221 h = maxh; | |
222 else | |
223 w = maxw; | |
224 } | |
225 if (box->fill) | |
226 { | |
227 if (box->vertical) | |
228 w = maxw; | |
229 else | |
230 h = maxh; | |
231 } | |
232 | |
18538
2e11d73c4ff1
Properly set the initial size of widgets.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
233 gnt_widget_confirm_size(wid, w, h); |
15817 | 234 gnt_widget_set_size(wid, w, h); |
235 } | |
236 | |
237 reposition_children(widget); | |
238 } | |
239 | |
240 static void | |
241 gnt_box_map(GntWidget *widget) | |
242 { | |
243 if (widget->priv.width == 0 || widget->priv.height == 0) | |
244 { | |
245 gnt_widget_size_request(widget); | |
246 find_focusable_widget(GNT_BOX(widget)); | |
247 } | |
248 GNTDEBUG; | |
249 } | |
250 | |
251 /* Ensures that the current widget can take focus */ | |
252 static GntWidget * | |
253 find_focusable_widget(GntBox *box) | |
254 { | |
255 /* XXX: Make sure the widget is visible? */ | |
256 if (box->focus == NULL && GNT_WIDGET(box)->parent == NULL) | |
257 g_list_foreach(box->list, add_to_focus, box); | |
258 | |
259 if (box->active == NULL && box->focus) | |
260 box->active = box->focus->data; | |
261 | |
262 return box->active; | |
263 } | |
264 | |
265 static void | |
266 find_next_focus(GntBox *box) | |
267 { | |
268 gpointer last = box->active; | |
269 do | |
270 { | |
271 GList *iter = g_list_find(box->focus, box->active); | |
272 if (iter && iter->next) | |
273 box->active = iter->next->data; | |
274 else if (box->focus) | |
275 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
|
276 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
|
277 GNT_WIDGET_IS_FLAG_SET(box->active, GNT_WIDGET_CAN_TAKE_FOCUS)) |
15817 | 278 break; |
279 } while (box->active != last); | |
280 } | |
281 | |
282 static void | |
283 find_prev_focus(GntBox *box) | |
284 { | |
285 gpointer last = box->active; | |
286 | |
287 if (!box->focus) | |
288 return; | |
289 | |
290 do | |
291 { | |
292 GList *iter = g_list_find(box->focus, box->active); | |
293 if (!iter) | |
294 box->active = box->focus->data; | |
295 else if (!iter->prev) | |
296 box->active = g_list_last(box->focus)->data; | |
297 else | |
298 box->active = iter->prev->data; | |
299 if (!GNT_WIDGET_IS_FLAG_SET(box->active, GNT_WIDGET_INVISIBLE)) | |
300 break; | |
301 } while (box->active != last); | |
302 } | |
303 | |
304 static gboolean | |
305 gnt_box_key_pressed(GntWidget *widget, const char *text) | |
306 { | |
307 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
|
308 gboolean ret; |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
309 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
310 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
|
311 return FALSE; |
15817 | 312 |
313 if (box->active == NULL && !find_focusable_widget(box)) | |
314 return FALSE; | |
315 | |
316 if (gnt_widget_key_pressed(box->active, text)) | |
317 return TRUE; | |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
318 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
319 /* 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
|
320 to trigger their bindings first */ |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
321 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
|
322 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
|
323 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
|
324 return ret; |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
325 } |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
326 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
327 static gboolean |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
328 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
|
329 { |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
330 GntWidget *now; |
15817 | 331 now = box->active; |
332 | |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
333 if (next) { |
15817 | 334 find_next_focus(box); |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
335 } else { |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
336 find_prev_focus(box); |
15817 | 337 } |
338 | |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
339 if (now && now != box->active) { |
15817 | 340 gnt_widget_set_focus(now, FALSE); |
341 gnt_widget_set_focus(box->active, TRUE); | |
342 return TRUE; | |
343 } | |
344 | |
345 return FALSE; | |
346 } | |
347 | |
25322
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
348 static gboolean |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
349 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
|
350 { |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
351 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
|
352 } |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
353 |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
354 static gboolean |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
355 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
|
356 { |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
357 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
|
358 } |
73e88188a7d4
Allow rebinding keys to change the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22999
diff
changeset
|
359 |
15817 | 360 static void |
361 gnt_box_lost_focus(GntWidget *widget) | |
362 { | |
363 GntWidget *w = GNT_BOX(widget)->active; | |
364 if (w) | |
365 gnt_widget_set_focus(w, FALSE); | |
366 gnt_widget_draw(widget); | |
367 } | |
368 | |
369 static void | |
370 gnt_box_gained_focus(GntWidget *widget) | |
371 { | |
372 GntWidget *w = GNT_BOX(widget)->active; | |
373 if (w) | |
374 gnt_widget_set_focus(w, TRUE); | |
375 gnt_widget_draw(widget); | |
376 } | |
377 | |
378 static void | |
379 gnt_box_destroy(GntWidget *w) | |
380 { | |
381 GntBox *box = GNT_BOX(w); | |
382 | |
383 gnt_box_remove_all(box); | |
384 gnt_screen_release(w); | |
385 } | |
386 | |
387 static void | |
388 gnt_box_expose(GntWidget *widget, int x, int y, int width, int height) | |
389 { | |
390 WINDOW *win = newwin(height, width, widget->priv.y + y, widget->priv.x + x); | |
391 copywin(widget->window, win, y, x, 0, 0, height - 1, width - 1, FALSE); | |
392 wrefresh(win); | |
393 delwin(win); | |
394 } | |
395 | |
396 static gboolean | |
397 gnt_box_confirm_size(GntWidget *widget, int width, int height) | |
398 { | |
399 GList *iter; | |
400 GntBox *box = GNT_BOX(widget); | |
401 int wchange, hchange; | |
402 | |
403 if (!box->list) | |
404 return TRUE; | |
405 | |
406 wchange = widget->priv.width - width; | |
407 hchange = widget->priv.height - height; | |
408 | |
409 if (wchange == 0 && hchange == 0) | |
410 return TRUE; /* Quit playing games */ | |
411 | |
412 /* XXX: Right now, I am trying to just apply all the changes to | |
413 * just one widget. It should be possible to distribute the | |
414 * changes to all the widgets in the box. */ | |
415 for (iter = box->list; iter; iter = iter->next) | |
416 { | |
417 GntWidget *wid = iter->data; | |
418 int w, h; | |
419 | |
420 gnt_widget_get_size(wid, &w, &h); | |
421 | |
422 if (gnt_widget_confirm_size(wid, w - wchange, h - hchange)) | |
423 { | |
424 GList *i; | |
425 | |
426 for (i = box->list; i; i = i->next) | |
427 { | |
428 int tw, th; | |
429 if (i == iter) continue; | |
430 gnt_widget_get_size(GNT_WIDGET(i->data), &tw, &th); | |
431 if (box->vertical) | |
432 { | |
15945
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
433 if (!gnt_widget_confirm_size(i->data, tw - wchange, th)) { |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
434 /* If we are decreasing the size and the widget is going |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
435 * to be too large to fit into the box, then do not allow |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
436 * resizing. */ |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
437 if (wchange > 0 && tw >= widget->priv.width) |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
438 return FALSE; |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
439 } |
15817 | 440 } |
441 else | |
442 { | |
15945
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
443 if (!gnt_widget_confirm_size(i->data, tw, th - hchange)) { |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
444 if (hchange > 0 && th >= widget->priv.height) |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
445 return FALSE; |
15817 | 446 return FALSE; |
15945
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
447 } |
15817 | 448 } |
449 } | |
450 #if 0 | |
451 gnt_widget_set_size(wid, w - wchange, h - hchange); | |
452 if (box->vertical) | |
453 hchange = 0; | |
454 else | |
455 wchange = 0; | |
456 | |
457 for (i = box->list; i; i = i->next) | |
458 { | |
459 int tw, th; | |
460 if (i == iter) continue; | |
461 gnt_widget_get_size(GNT_WIDGET(i->data), &tw, &th); | |
462 gnt_widget_set_size(i->data, tw - wchange, th - hchange); | |
463 } | |
464 #endif | |
465 g_object_set_data(G_OBJECT(box), "size-queued", wid); | |
466 return TRUE; | |
467 } | |
468 } | |
469 | |
470 return FALSE; | |
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; | |
481 | |
482 wchange = widget->priv.width - oldw; | |
483 hchange = widget->priv.height - oldh; | |
484 | |
485 wid = g_object_get_data(G_OBJECT(box), "size-queued"); | |
486 if (wid) | |
487 { | |
488 gnt_widget_get_size(wid, &tw, &th); | |
489 gnt_widget_set_size(wid, tw + wchange, th + hchange); | |
490 g_object_set_data(G_OBJECT(box), "size-queued", NULL); | |
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 g_free(prev); | |
693 } | |
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 | |
726 for (iter = box->list; iter; iter = iter->next) | |
727 { | |
728 GntWidget *w = GNT_WIDGET(iter->data); | |
729 int height, width; | |
730 int x, y; | |
731 | |
732 if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_INVISIBLE)) | |
733 continue; | |
734 | |
735 if (GNT_IS_BOX(w)) | |
736 gnt_box_sync_children(GNT_BOX(w)); | |
737 | |
738 gnt_widget_get_size(w, &width, &height); | |
739 | |
740 x = w->priv.x - widget->priv.x; | |
741 y = w->priv.y - widget->priv.y; | |
742 | |
743 if (box->vertical) | |
744 { | |
745 x = pos; | |
746 if (box->alignment == GNT_ALIGN_RIGHT) | |
747 x += widget->priv.width - width; | |
748 else if (box->alignment == GNT_ALIGN_MID) | |
749 x += (widget->priv.width - width)/2; | |
750 if (x + width > widget->priv.width - pos) | |
751 x -= x + width - (widget->priv.width - pos); | |
752 } | |
753 else | |
754 { | |
755 y = pos; | |
756 if (box->alignment == GNT_ALIGN_BOTTOM) | |
757 y += widget->priv.height - height; | |
758 else if (box->alignment == GNT_ALIGN_MID) | |
759 y += (widget->priv.height - height)/2; | |
760 if (y + height >= widget->priv.height - pos) | |
761 y = widget->priv.height - height - pos; | |
762 } | |
763 | |
764 copywin(w->window, widget->window, 0, 0, | |
765 y, x, y + height - 1, x + width - 1, FALSE); | |
766 gnt_widget_set_position(w, x + widget->priv.x, y + widget->priv.y); | |
767 } | |
768 } | |
769 | |
770 void gnt_box_set_alignment(GntBox *box, GntAlignment alignment) | |
771 { | |
772 box->alignment = alignment; | |
773 } | |
774 | |
775 void gnt_box_remove(GntBox *box, GntWidget *widget) | |
776 { | |
777 box->list = g_list_remove(box->list, widget); | |
778 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_CAN_TAKE_FOCUS) | |
779 && GNT_WIDGET(box)->parent == NULL && box->focus) | |
780 { | |
781 if (widget == box->active) | |
782 { | |
783 find_next_focus(box); | |
784 if (box->active == widget) /* There's only one widget */ | |
785 box->active = NULL; | |
786 } | |
787 box->focus = g_list_remove(box->focus, widget); | |
788 } | |
789 | |
790 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(box), GNT_WIDGET_MAPPED)) | |
791 gnt_widget_draw(GNT_WIDGET(box)); | |
792 } | |
793 | |
794 void gnt_box_remove_all(GntBox *box) | |
795 { | |
796 g_list_foreach(box->list, (GFunc)gnt_widget_destroy, NULL); | |
797 g_list_free(box->list); | |
798 g_list_free(box->focus); | |
799 box->list = NULL; | |
800 box->focus = NULL; | |
801 GNT_WIDGET(box)->priv.width = 0; | |
802 GNT_WIDGET(box)->priv.height = 0; | |
803 } | |
804 | |
805 void gnt_box_readjust(GntBox *box) | |
806 { | |
807 GList *iter; | |
808 GntWidget *wid; | |
809 int width, height; | |
810 | |
811 if (GNT_WIDGET(box)->parent != NULL) | |
812 return; | |
813 | |
814 for (iter = box->list; iter; iter = iter->next) | |
815 { | |
816 GntWidget *w = iter->data; | |
817 if (GNT_IS_BOX(w)) | |
818 gnt_box_readjust(GNT_BOX(w)); | |
819 else | |
820 { | |
821 GNT_WIDGET_UNSET_FLAGS(w, GNT_WIDGET_MAPPED); | |
822 w->priv.width = 0; | |
823 w->priv.height = 0; | |
824 } | |
825 } | |
826 | |
827 wid = GNT_WIDGET(box); | |
828 GNT_WIDGET_UNSET_FLAGS(wid, GNT_WIDGET_MAPPED); | |
829 wid->priv.width = 0; | |
830 wid->priv.height = 0; | |
831 | |
832 if (wid->parent == NULL) | |
833 { | |
834 g_list_free(box->focus); | |
835 box->focus = NULL; | |
836 box->active = NULL; | |
837 gnt_widget_size_request(wid); | |
838 gnt_widget_get_size(wid, &width, &height); | |
839 gnt_screen_resize_widget(wid, width, height); | |
840 find_focusable_widget(box); | |
841 } | |
842 } | |
843 | |
844 void gnt_box_set_fill(GntBox *box, gboolean fill) | |
845 { | |
846 box->fill = fill; | |
847 } | |
848 | |
849 void gnt_box_move_focus(GntBox *box, int dir) | |
850 { | |
851 GntWidget *now; | |
852 | |
853 if (box->active == NULL) | |
854 { | |
855 find_focusable_widget(box); | |
856 return; | |
857 } | |
858 | |
859 now = box->active; | |
860 | |
861 if (dir == 1) | |
862 find_next_focus(box); | |
863 else if (dir == -1) | |
864 find_prev_focus(box); | |
865 | |
866 if (now && now != box->active) | |
867 { | |
868 gnt_widget_set_focus(now, FALSE); | |
869 gnt_widget_set_focus(box->active, TRUE); | |
870 } | |
871 | |
872 if (GNT_WIDGET(box)->window) | |
873 gnt_widget_draw(GNT_WIDGET(box)); | |
874 } | |
875 | |
876 void gnt_box_give_focus_to_child(GntBox *box, GntWidget *widget) | |
877 { | |
21626
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
878 GList *find; |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
879 gpointer now; |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
880 |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
881 while (GNT_WIDGET(box)->parent) |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
882 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
|
883 |
4c03275346a9
Fix moving focus in an internal box.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21261
diff
changeset
|
884 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
|
885 now = box->active; |
15817 | 886 if (find) |
887 box->active = widget; | |
888 if (now && now != box->active) | |
889 { | |
890 gnt_widget_set_focus(now, FALSE); | |
891 gnt_widget_set_focus(box->active, TRUE); | |
892 } | |
893 | |
894 if (GNT_WIDGET(box)->window) | |
895 gnt_widget_draw(GNT_WIDGET(box)); | |
896 } | |
897 |