Mercurial > pidgin
comparison console/libgnt/gntbox.c @ 13907:cc60d0861337
[gaim-migrate @ 16402]
This commit has 1234 lines of diff :)
Windows can now be moved (alt+m, then the arrow keys, then escape/enter).
Add a window to enable/disable accounts. But the 'add' etc. buttons don't
have any callbacks yet. I am going to need to do some more widgets (checkbox,
combobox) before I do anything else.
I have also updated the test programs to work with the changes in libgnt.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sun, 02 Jul 2006 22:13:06 +0000 |
parents | a621329e8c85 |
children | fdf2dbed6faa |
comparison
equal
deleted
inserted
replaced
13906:b986b6e2441b | 13907:cc60d0861337 |
---|---|
11 static guint signals[SIGS] = { 0 }; | 11 static guint signals[SIGS] = { 0 }; |
12 | 12 |
13 static GntWidget * find_focusable_widget(GntBox *box); | 13 static GntWidget * find_focusable_widget(GntBox *box); |
14 | 14 |
15 static void | 15 static void |
16 add_to_focus(gpointer value, gpointer data) | |
17 { | |
18 GntBox *box = GNT_BOX(data); | |
19 GntWidget *w = GNT_WIDGET(value); | |
20 | |
21 if (GNT_IS_BOX(w)) | |
22 g_list_foreach(GNT_BOX(w)->list, add_to_focus, box); | |
23 else if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_CAN_TAKE_FOCUS)) | |
24 box->focus = g_list_append(box->focus, w); | |
25 } | |
26 | |
27 static void | |
16 gnt_box_draw(GntWidget *widget) | 28 gnt_box_draw(GntWidget *widget) |
17 { | 29 { |
18 GntBox *box = GNT_BOX(widget); | 30 GntBox *box = GNT_BOX(widget); |
31 | |
32 if (box->focus == NULL && widget->parent == NULL) | |
33 g_list_foreach(box->list, add_to_focus, box); | |
19 | 34 |
20 g_list_foreach(box->list, (GFunc)gnt_widget_draw, NULL); | 35 g_list_foreach(box->list, (GFunc)gnt_widget_draw, NULL); |
21 | 36 |
22 gnt_box_sync_children(box); | 37 gnt_box_sync_children(box); |
23 | 38 |
150 find_focusable_widget(GNT_BOX(widget)); | 165 find_focusable_widget(GNT_BOX(widget)); |
151 } | 166 } |
152 DEBUG; | 167 DEBUG; |
153 } | 168 } |
154 | 169 |
170 #if 0 | |
155 static GntWidget * | 171 static GntWidget * |
156 find_next_focus(GntBox *box) | 172 find_next_focus(GntBox *box) |
157 { | 173 { |
158 GntWidget *w = box->active; | 174 GntWidget *w = box->active; |
159 GList *iter; | 175 GList *iter; |
176 | |
177 if (w == NULL) | |
178 { | |
179 return find_focusable_widget(box); | |
180 } | |
160 | 181 |
161 while (w && !(iter = g_list_find(box->list, w))) | 182 while (w && !(iter = g_list_find(box->list, w))) |
162 w = w->parent; | 183 w = w->parent; |
163 | 184 |
164 if (!w) | 185 if (!w) |
165 box->active = NULL; | 186 box->active = NULL; |
166 else if (iter) | 187 else if (iter) |
167 { | 188 { |
168 GntWidget *next = NULL; | 189 GntWidget *next = NULL; |
169 | 190 |
170 do | 191 while (!next && (iter = iter->next)) |
171 { | 192 { |
172 next = find_next_focus(iter->data); | 193 if (GNT_IS_BOX(iter->data)) |
173 box->active = next; | 194 next = find_next_focus(iter->data); |
174 iter = iter->next; | 195 else |
175 } while (!next && iter); | 196 { |
197 if (GNT_WIDGET_IS_FLAG_SET(iter->data, GNT_WIDGET_CAN_TAKE_FOCUS) && | |
198 GNT_WIDGET_IS_FLAG_SET(iter->data, GNT_WIDGET_HAS_FOCUS)) | |
199 next = iter->data; | |
200 else | |
201 next = NULL; | |
202 } | |
203 } | |
204 box->active = next; | |
176 } | 205 } |
177 | 206 |
178 if (box->active == NULL && GNT_WIDGET(box)->parent == NULL) | 207 if (box->active == NULL && GNT_WIDGET(box)->parent == NULL) |
179 { | 208 { |
180 box->active = find_focusable_widget(box); | 209 box->active = find_focusable_widget(box); |
183 if (box->active) | 212 if (box->active) |
184 GNT_WIDGET_SET_FLAGS(box->active, GNT_WIDGET_HAS_FOCUS); | 213 GNT_WIDGET_SET_FLAGS(box->active, GNT_WIDGET_HAS_FOCUS); |
185 | 214 |
186 return box->active; | 215 return box->active; |
187 } | 216 } |
217 #endif | |
188 | 218 |
189 /* Ensures that the current widget can take focus */ | 219 /* Ensures that the current widget can take focus */ |
190 static GntWidget * | 220 static GntWidget * |
191 find_focusable_widget(GntBox *box) | 221 find_focusable_widget(GntBox *box) |
192 { | 222 { |
193 int investigated = 0; | 223 if (box->focus == NULL && GNT_WIDGET(box)->parent == NULL) |
194 int total; | 224 g_list_foreach(box->list, add_to_focus, box); |
195 GntWidget *w = NULL; | 225 |
196 GList *iter; | 226 if (box->active == NULL && box->focus) |
197 | 227 box->active = box->focus->data; |
228 | |
229 return box->active; | |
230 | |
231 #if 0 | |
198 for (iter = box->list; iter; iter = iter->next) | 232 for (iter = box->list; iter; iter = iter->next) |
199 { | 233 { |
200 w = iter->data; | 234 w = iter->data; |
201 if (GNT_IS_BOX(w)) | 235 if (GNT_IS_BOX(w)) |
202 { | 236 { |
246 if (box->active) | 280 if (box->active) |
247 gnt_widget_set_focus(box->active->data, TRUE); | 281 gnt_widget_set_focus(box->active->data, TRUE); |
248 if (w && w != box->active->data) | 282 if (w && w != box->active->data) |
249 gnt_widget_set_focus(w, FALSE); | 283 gnt_widget_set_focus(w, FALSE); |
250 #endif | 284 #endif |
285 #endif | |
251 } | 286 } |
252 | 287 |
253 static gboolean | 288 static gboolean |
254 gnt_box_key_pressed(GntWidget *widget, const char *text) | 289 gnt_box_key_pressed(GntWidget *widget, const char *text) |
255 { | 290 { |
261 if (gnt_widget_key_pressed(box->active, text)) | 296 if (gnt_widget_key_pressed(box->active, text)) |
262 return TRUE; | 297 return TRUE; |
263 | 298 |
264 if (text[0] == 27) | 299 if (text[0] == 27) |
265 { | 300 { |
301 GntWidget *now = box->active; | |
302 if (strcmp(text+1, GNT_KEY_LEFT) == 0) | |
303 { | |
304 GList *iter = g_list_find(box->focus, box->active); | |
305 if ((!iter || !iter->prev) && box->focus) | |
306 { | |
307 box->active = box->focus->data; | |
308 } | |
309 else | |
310 { | |
311 box->active = iter->prev->data; | |
312 } | |
313 } | |
314 else if (strcmp(text+1, GNT_KEY_RIGHT) == 0) | |
315 { | |
316 GList *iter = g_list_find(box->focus, box->active); | |
317 if (iter && iter->next) | |
318 { | |
319 box->active = iter->next->data; | |
320 } | |
321 else if (box->focus) | |
322 { | |
323 box->active = box->focus->data; | |
324 } | |
325 } | |
326 | |
327 if (now && now != box->active) | |
328 { | |
329 gnt_widget_set_focus(now, FALSE); | |
330 gnt_widget_set_focus(box->active, TRUE); | |
331 return TRUE; | |
332 } | |
333 } | |
334 | |
335 return FALSE; | |
336 } | |
337 | |
266 #if 0 | 338 #if 0 |
267 GList *now = NULL; | |
268 if (strcmp(text+1, GNT_KEY_LEFT) == 0) | |
269 { | |
270 now = box->active->prev; | |
271 if (now == NULL) | |
272 now = g_list_last(box->list); | |
273 } | |
274 else if (strcmp(text+1, GNT_KEY_RIGHT) == 0) | |
275 { | |
276 now = box->active->next; | |
277 if (now == NULL) | |
278 now = box->list; | |
279 } | |
280 | |
281 if (now && now != box->active) | |
282 { | |
283 gnt_widget_set_focus(box->active->data, FALSE); | |
284 box->active = now; | |
285 gnt_widget_set_focus(box->active->data, TRUE); | |
286 | |
287 return TRUE; | |
288 } | |
289 #endif | |
290 } | |
291 | |
292 return FALSE; | |
293 } | |
294 | |
295 static GntWidget *find_focused_widget(GntBox *box) | 339 static GntWidget *find_focused_widget(GntBox *box) |
296 { | 340 { |
297 GList *iter; | 341 GList *iter; |
298 | 342 |
299 for (iter = box->list; iter; iter = iter->next) | 343 for (iter = box->list; iter; iter = iter->next) |
312 return w; | 356 return w; |
313 } | 357 } |
314 } | 358 } |
315 return NULL; | 359 return NULL; |
316 } | 360 } |
361 #endif | |
317 | 362 |
318 #if 0 | 363 #if 0 |
319 static void | 364 static void |
320 gnt_box_set_focus(GntWidget *widget, gboolean set) | 365 gnt_box_set_focus(GntWidget *widget, gboolean set) |
321 { | 366 { |
481 /* XXX: werase first? */ | 526 /* XXX: werase first? */ |
482 | 527 |
483 for (iter = box->list; iter; iter = iter->next) | 528 for (iter = box->list; iter; iter = iter->next) |
484 { | 529 { |
485 GntWidget *w = GNT_WIDGET(iter->data); | 530 GntWidget *w = GNT_WIDGET(iter->data); |
531 | |
532 if (GNT_IS_BOX(w)) | |
533 gnt_box_sync_children(GNT_BOX(w)); | |
534 | |
486 copywin(w->window, widget->window, 0, 0, | 535 copywin(w->window, widget->window, 0, 0, |
487 w->priv.y - widget->priv.y, | 536 w->priv.y - widget->priv.y, |
488 w->priv.x - widget->priv.x, | 537 w->priv.x - widget->priv.x, |
489 w->priv.y - widget->priv.y + w->priv.height - 1, | 538 w->priv.y - widget->priv.y + w->priv.height - 1, |
490 w->priv.x - widget->priv.x + w->priv.width - 1, | 539 w->priv.x - widget->priv.x + w->priv.width - 1, |