Mercurial > pidgin
annotate finch/libgnt/gntwidget.c @ 17957:3bd88cbdd204
Add support for sending emoticons.
author | Jeffrey Connelly <jaconnel@calpoly.edu> |
---|---|
date | Fri, 20 Jul 2007 05:50:03 +0000 |
parents | 92fa7d6e75b0 |
children | 223a4fca43a1 1cedd520cd18 |
rev | line source |
---|---|
15817 | 1 /* Stuff brutally ripped from Gflib */ |
2 | |
3 #include "gntwidget.h" | |
4 #include "gntstyle.h" | |
5 #include "gntmarshal.h" | |
6 #include "gntutils.h" | |
7 #include "gnt.h" | |
8 | |
9 enum | |
10 { | |
11 SIG_DESTROY, | |
12 SIG_DRAW, | |
13 SIG_HIDE, | |
14 SIG_GIVE_FOCUS, | |
15 SIG_LOST_FOCUS, | |
16 SIG_KEY_PRESSED, | |
17 SIG_MAP, | |
18 SIG_ACTIVATE, | |
19 SIG_EXPOSE, | |
20 SIG_SIZE_REQUEST, | |
21 SIG_CONFIRM_SIZE, | |
22 SIG_SIZE_CHANGED, | |
23 SIG_POSITION, | |
24 SIG_CLICKED, | |
25 SIG_CONTEXT_MENU, | |
26 SIGS | |
27 }; | |
28 | |
29 static GObjectClass *parent_class = NULL; | |
30 static guint signals[SIGS] = { 0 }; | |
31 | |
32 static void init_widget(GntWidget *widget); | |
33 | |
34 static void | |
35 gnt_widget_init(GTypeInstance *instance, gpointer class) | |
36 { | |
37 GntWidget *widget = GNT_WIDGET(instance); | |
38 widget->priv.name = NULL; | |
39 GNTDEBUG; | |
40 } | |
41 | |
42 static void | |
43 gnt_widget_map(GntWidget *widget) | |
44 { | |
45 /* Get some default size for the widget */ | |
46 GNTDEBUG; | |
47 g_signal_emit(widget, signals[SIG_MAP], 0); | |
48 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_MAPPED); | |
49 } | |
50 | |
51 static void | |
52 gnt_widget_dispose(GObject *obj) | |
53 { | |
54 GntWidget *self = GNT_WIDGET(obj); | |
55 | |
56 if(!(GNT_WIDGET_FLAGS(self) & GNT_WIDGET_DESTROYING)) { | |
57 GNT_WIDGET_SET_FLAGS(self, GNT_WIDGET_DESTROYING); | |
58 | |
59 g_signal_emit(self, signals[SIG_DESTROY], 0); | |
60 | |
61 GNT_WIDGET_UNSET_FLAGS(self, GNT_WIDGET_DESTROYING); | |
62 } | |
63 | |
64 parent_class->dispose(obj); | |
65 GNTDEBUG; | |
66 } | |
67 | |
68 static void | |
69 gnt_widget_focus_change(GntWidget *widget) | |
70 { | |
71 if (GNT_WIDGET_FLAGS(widget) & GNT_WIDGET_MAPPED) | |
72 gnt_widget_draw(widget); | |
73 } | |
74 | |
75 static gboolean | |
76 gnt_widget_dummy_confirm_size(GntWidget *widget, int width, int height) | |
77 { | |
15945
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15943
diff
changeset
|
78 gboolean shadow; |
15817 | 79 if (width < widget->priv.minw || height < widget->priv.minh) |
80 return FALSE; | |
15945
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15943
diff
changeset
|
81 shadow = gnt_widget_has_shadow(widget); |
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15943
diff
changeset
|
82 if (widget->priv.width + shadow != width && !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_GROW_X)) |
15817 | 83 return FALSE; |
15945
92fa7d6e75b0
A few more fixes for resizing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15943
diff
changeset
|
84 if (widget->priv.height + shadow != height && !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_GROW_Y)) |
15817 | 85 return FALSE; |
86 return TRUE; | |
87 } | |
88 | |
89 static gboolean | |
90 context_menu(GntBindable *bind, GList *null) | |
91 { | |
92 gboolean ret = FALSE; | |
93 g_signal_emit(bind, signals[SIG_CONTEXT_MENU], 0, &ret); | |
94 return ret; | |
95 } | |
96 | |
97 static void | |
98 gnt_widget_class_init(GntWidgetClass *klass) | |
99 { | |
100 GObjectClass *obj_class = G_OBJECT_CLASS(klass); | |
101 | |
102 parent_class = g_type_class_peek_parent(klass); | |
103 | |
104 obj_class->dispose = gnt_widget_dispose; | |
105 | |
106 klass->destroy = gnt_widget_destroy; | |
107 klass->show = gnt_widget_show; | |
108 klass->draw = gnt_widget_draw; | |
109 klass->expose = gnt_widget_expose; | |
110 klass->map = gnt_widget_map; | |
111 klass->lost_focus = gnt_widget_focus_change; | |
112 klass->gained_focus = gnt_widget_focus_change; | |
113 klass->confirm_size = gnt_widget_dummy_confirm_size; | |
114 | |
115 klass->key_pressed = NULL; | |
116 klass->activate = NULL; | |
117 klass->clicked = NULL; | |
118 | |
119 signals[SIG_DESTROY] = | |
120 g_signal_new("destroy", | |
121 G_TYPE_FROM_CLASS(klass), | |
122 G_SIGNAL_RUN_LAST, | |
123 G_STRUCT_OFFSET(GntWidgetClass, destroy), | |
124 NULL, NULL, | |
125 g_cclosure_marshal_VOID__VOID, | |
126 G_TYPE_NONE, 0); | |
127 signals[SIG_GIVE_FOCUS] = | |
128 g_signal_new("gained-focus", | |
129 G_TYPE_FROM_CLASS(klass), | |
130 G_SIGNAL_RUN_LAST, | |
131 G_STRUCT_OFFSET(GntWidgetClass, gained_focus), | |
132 NULL, NULL, | |
133 g_cclosure_marshal_VOID__VOID, | |
134 G_TYPE_NONE, 0); | |
135 signals[SIG_LOST_FOCUS] = | |
136 g_signal_new("lost-focus", | |
137 G_TYPE_FROM_CLASS(klass), | |
138 G_SIGNAL_RUN_LAST, | |
139 G_STRUCT_OFFSET(GntWidgetClass, lost_focus), | |
140 NULL, NULL, | |
141 g_cclosure_marshal_VOID__VOID, | |
142 G_TYPE_NONE, 0); | |
143 signals[SIG_ACTIVATE] = | |
144 g_signal_new("activate", | |
145 G_TYPE_FROM_CLASS(klass), | |
146 G_SIGNAL_RUN_LAST, | |
147 G_STRUCT_OFFSET(GntWidgetClass, activate), | |
148 NULL, NULL, | |
149 g_cclosure_marshal_VOID__VOID, | |
150 G_TYPE_NONE, 0); | |
151 signals[SIG_MAP] = | |
152 g_signal_new("map", | |
153 G_TYPE_FROM_CLASS(klass), | |
154 G_SIGNAL_RUN_LAST, | |
155 G_STRUCT_OFFSET(GntWidgetClass, map), | |
156 NULL, NULL, | |
157 g_cclosure_marshal_VOID__VOID, | |
158 G_TYPE_NONE, 0); | |
159 signals[SIG_DRAW] = | |
160 g_signal_new("draw", | |
161 G_TYPE_FROM_CLASS(klass), | |
162 G_SIGNAL_RUN_LAST, | |
163 G_STRUCT_OFFSET(GntWidgetClass, draw), | |
164 NULL, NULL, | |
165 g_cclosure_marshal_VOID__VOID, | |
166 G_TYPE_NONE, 0); | |
167 signals[SIG_HIDE] = | |
168 g_signal_new("hide", | |
169 G_TYPE_FROM_CLASS(klass), | |
170 G_SIGNAL_RUN_LAST, | |
171 G_STRUCT_OFFSET(GntWidgetClass, hide), | |
172 NULL, NULL, | |
173 g_cclosure_marshal_VOID__VOID, | |
174 G_TYPE_NONE, 0); | |
175 signals[SIG_EXPOSE] = | |
176 g_signal_new("expose", | |
177 G_TYPE_FROM_CLASS(klass), | |
178 G_SIGNAL_RUN_LAST, | |
179 G_STRUCT_OFFSET(GntWidgetClass, expose), | |
180 NULL, NULL, | |
181 gnt_closure_marshal_VOID__INT_INT_INT_INT, | |
182 G_TYPE_NONE, 4, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT); | |
183 signals[SIG_POSITION] = | |
184 g_signal_new("position-set", | |
185 G_TYPE_FROM_CLASS(klass), | |
186 G_SIGNAL_RUN_LAST, | |
187 G_STRUCT_OFFSET(GntWidgetClass, set_position), | |
188 NULL, NULL, | |
189 gnt_closure_marshal_VOID__INT_INT, | |
190 G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT); | |
191 signals[SIG_SIZE_REQUEST] = | |
192 g_signal_new("size_request", | |
193 G_TYPE_FROM_CLASS(klass), | |
194 G_SIGNAL_RUN_LAST, | |
195 G_STRUCT_OFFSET(GntWidgetClass, size_request), | |
196 NULL, NULL, | |
197 g_cclosure_marshal_VOID__VOID, | |
198 G_TYPE_NONE, 0); | |
199 signals[SIG_SIZE_CHANGED] = | |
200 g_signal_new("size_changed", | |
201 G_TYPE_FROM_CLASS(klass), | |
202 G_SIGNAL_RUN_LAST, | |
203 G_STRUCT_OFFSET(GntWidgetClass, size_changed), | |
204 NULL, NULL, | |
205 gnt_closure_marshal_VOID__INT_INT, | |
206 G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT); | |
207 signals[SIG_CONFIRM_SIZE] = | |
208 g_signal_new("confirm_size", | |
209 G_TYPE_FROM_CLASS(klass), | |
210 G_SIGNAL_RUN_LAST, | |
211 G_STRUCT_OFFSET(GntWidgetClass, confirm_size), | |
212 NULL, NULL, | |
213 gnt_closure_marshal_BOOLEAN__INT_INT, | |
214 G_TYPE_BOOLEAN, 2, G_TYPE_INT, G_TYPE_INT); | |
215 signals[SIG_KEY_PRESSED] = | |
216 g_signal_new("key_pressed", | |
217 G_TYPE_FROM_CLASS(klass), | |
218 G_SIGNAL_RUN_LAST, | |
219 G_STRUCT_OFFSET(GntWidgetClass, key_pressed), | |
220 gnt_boolean_handled_accumulator, NULL, | |
221 gnt_closure_marshal_BOOLEAN__STRING, | |
222 G_TYPE_BOOLEAN, 1, G_TYPE_STRING); | |
223 | |
224 signals[SIG_CLICKED] = | |
225 g_signal_new("clicked", | |
226 G_TYPE_FROM_CLASS(klass), | |
227 G_SIGNAL_RUN_LAST, | |
228 G_STRUCT_OFFSET(GntWidgetClass, clicked), | |
229 gnt_boolean_handled_accumulator, NULL, | |
230 gnt_closure_marshal_BOOLEAN__INT_INT_INT, | |
231 G_TYPE_BOOLEAN, 3, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT); | |
232 | |
233 signals[SIG_CONTEXT_MENU] = | |
234 g_signal_new("context-menu", | |
235 G_TYPE_FROM_CLASS(klass), | |
236 G_SIGNAL_RUN_LAST, | |
237 0, | |
238 gnt_boolean_handled_accumulator, NULL, | |
239 gnt_closure_marshal_BOOLEAN__VOID, | |
240 G_TYPE_BOOLEAN, 0); | |
241 | |
242 /* This is relevant for all widgets */ | |
243 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "context-menu", context_menu, | |
244 GNT_KEY_POPUP, NULL); | |
245 gnt_bindable_register_binding(GNT_BINDABLE_CLASS(klass), "context-menu", GNT_KEY_F11, NULL); | |
246 | |
247 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass)); | |
248 GNTDEBUG; | |
249 } | |
250 | |
251 /****************************************************************************** | |
252 * GntWidget API | |
253 *****************************************************************************/ | |
254 GType | |
255 gnt_widget_get_gtype(void) | |
256 { | |
257 static GType type = 0; | |
258 | |
259 if(type == 0) { | |
260 static const GTypeInfo info = { | |
261 sizeof(GntWidgetClass), | |
262 NULL, /* base_init */ | |
263 NULL, /* base_finalize */ | |
264 (GClassInitFunc)gnt_widget_class_init, | |
265 NULL, | |
266 NULL, /* class_data */ | |
267 sizeof(GntWidget), | |
268 0, /* n_preallocs */ | |
269 gnt_widget_init, /* instance_init */ | |
270 NULL /* value_table */ | |
271 }; | |
272 | |
273 type = g_type_register_static(GNT_TYPE_BINDABLE, | |
274 "GntWidget", | |
275 &info, G_TYPE_FLAG_ABSTRACT); | |
276 } | |
277 | |
278 return type; | |
279 } | |
280 | |
281 void gnt_widget_set_take_focus(GntWidget *widget, gboolean can) | |
282 { | |
283 if (can) | |
284 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS); | |
285 else | |
286 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS); | |
287 } | |
288 | |
289 /** | |
290 * gnt_widget_destroy: | |
291 * @obj: The #GntWidget instance. | |
292 * | |
293 * Emits the "destroy" signal notifying all reference holders that they | |
294 * should release @obj. | |
295 */ | |
296 void | |
297 gnt_widget_destroy(GntWidget *obj) | |
298 { | |
299 g_return_if_fail(GNT_IS_WIDGET(obj)); | |
300 | |
301 gnt_widget_hide(obj); | |
302 delwin(obj->window); | |
303 if(!(GNT_WIDGET_FLAGS(obj) & GNT_WIDGET_DESTROYING)) | |
304 g_object_run_dispose(G_OBJECT(obj)); | |
305 GNTDEBUG; | |
306 } | |
307 | |
308 void | |
309 gnt_widget_show(GntWidget *widget) | |
310 { | |
311 gnt_widget_draw(widget); | |
312 gnt_screen_occupy(widget); | |
313 } | |
314 | |
315 void | |
316 gnt_widget_draw(GntWidget *widget) | |
317 { | |
318 /* Draw the widget */ | |
319 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_DRAWING)) | |
320 return; | |
321 | |
322 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_DRAWING); | |
323 if (!(GNT_WIDGET_FLAGS(widget) & GNT_WIDGET_MAPPED)) { | |
324 gnt_widget_map(widget); | |
325 } | |
326 | |
327 if (widget->window == NULL) | |
328 { | |
329 #if 0 | |
330 int x, y, maxx, maxy, w, h; | |
331 int oldw, oldh; | |
332 gboolean shadow = TRUE; | |
333 | |
334 if (!gnt_widget_has_shadow(widget)) | |
335 shadow = FALSE; | |
336 | |
337 x = widget->priv.x; | |
338 y = widget->priv.y; | |
339 w = oldw = widget->priv.width + shadow; | |
340 h = oldh = widget->priv.height + shadow; | |
341 | |
342 getmaxyx(stdscr, maxy, maxx); | |
343 maxy -= 1; /* room for the taskbar */ | |
344 | |
345 x = MAX(0, x); | |
346 y = MAX(0, y); | |
347 if (x + w >= maxx) | |
348 x = MAX(0, maxx - w); | |
349 if (y + h >= maxy) | |
350 y = MAX(0, maxy - h); | |
351 | |
352 w = MIN(w, maxx); | |
353 h = MIN(h, maxy); | |
354 | |
355 widget->priv.x = x; | |
356 widget->priv.y = y; | |
357 if (w != oldw || h != oldh) { | |
358 widget->priv.width = w - shadow; | |
359 widget->priv.height = h - shadow; | |
360 g_signal_emit(widget, signals[SIG_SIZE_CHANGED], 0, oldw, oldh); | |
361 } | |
362 #else | |
363 widget->window = newpad(widget->priv.height + 20, widget->priv.width + 20); /* XXX: */ | |
364 #endif | |
365 init_widget(widget); | |
366 } | |
367 | |
368 g_signal_emit(widget, signals[SIG_DRAW], 0); | |
369 gnt_widget_queue_update(widget); | |
370 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_DRAWING); | |
371 } | |
372 | |
373 gboolean | |
374 gnt_widget_key_pressed(GntWidget *widget, const char *keys) | |
375 { | |
376 gboolean ret; | |
377 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_CAN_TAKE_FOCUS)) | |
378 return FALSE; | |
379 | |
380 if (gnt_bindable_perform_action_key(GNT_BINDABLE(widget), keys)) | |
381 return TRUE; | |
382 | |
383 keys = gnt_bindable_remap_keys(GNT_BINDABLE(widget), keys); | |
384 g_signal_emit(widget, signals[SIG_KEY_PRESSED], 0, keys, &ret); | |
385 return ret; | |
386 } | |
387 | |
388 gboolean | |
389 gnt_widget_clicked(GntWidget *widget, GntMouseEvent event, int x, int y) | |
390 { | |
391 gboolean ret; | |
392 g_signal_emit(widget, signals[SIG_CLICKED], 0, event, x, y, &ret); | |
393 return ret; | |
394 } | |
395 | |
396 void | |
397 gnt_widget_expose(GntWidget *widget, int x, int y, int width, int height) | |
398 { | |
399 g_signal_emit(widget, signals[SIG_EXPOSE], 0, x, y, width, height); | |
400 } | |
401 | |
402 void | |
403 gnt_widget_hide(GntWidget *widget) | |
404 { | |
405 g_signal_emit(widget, signals[SIG_HIDE], 0); | |
406 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
407 #if 0 | |
408 /* XXX: I have no clue why, but this seemed to be necessary. */ | |
409 if (gnt_widget_has_shadow(widget)) | |
410 mvwvline(widget->window, 1, widget->priv.width, ' ', widget->priv.height); | |
411 #endif | |
412 gnt_screen_release(widget); | |
413 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_INVISIBLE); | |
414 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_MAPPED); | |
415 } | |
416 | |
417 void | |
418 gnt_widget_set_position(GntWidget *wid, int x, int y) | |
419 { | |
420 g_signal_emit(wid, signals[SIG_POSITION], 0, x, y); | |
421 /* XXX: Need to install properties for these and g_object_notify */ | |
422 wid->priv.x = x; | |
423 wid->priv.y = y; | |
424 } | |
425 | |
426 void | |
427 gnt_widget_get_position(GntWidget *wid, int *x, int *y) | |
428 { | |
429 if (x) | |
430 *x = wid->priv.x; | |
431 if (y) | |
432 *y = wid->priv.y; | |
433 } | |
434 | |
435 void | |
436 gnt_widget_size_request(GntWidget *widget) | |
437 { | |
438 g_signal_emit(widget, signals[SIG_SIZE_REQUEST], 0); | |
439 } | |
440 | |
441 void | |
442 gnt_widget_get_size(GntWidget *wid, int *width, int *height) | |
443 { | |
444 gboolean shadow = TRUE; | |
445 if (!gnt_widget_has_shadow(wid)) | |
446 shadow = FALSE; | |
447 | |
448 if (width) | |
449 *width = wid->priv.width + shadow; | |
450 if (height) | |
451 *height = wid->priv.height + shadow; | |
452 | |
453 } | |
454 | |
455 static void | |
456 init_widget(GntWidget *widget) | |
457 { | |
458 gboolean shadow = TRUE; | |
459 | |
460 if (!gnt_widget_has_shadow(widget)) | |
461 shadow = FALSE; | |
462 | |
463 wbkgd(widget->window, COLOR_PAIR(GNT_COLOR_NORMAL)); | |
464 werase(widget->window); | |
465 | |
466 if (!(GNT_WIDGET_FLAGS(widget) & GNT_WIDGET_NO_BORDER)) | |
467 { | |
468 /* - This is ugly. */ | |
469 /* - What's your point? */ | |
470 mvwvline(widget->window, 0, 0, ACS_VLINE | COLOR_PAIR(GNT_COLOR_NORMAL), widget->priv.height); | |
471 mvwvline(widget->window, 0, widget->priv.width - 1, | |
472 ACS_VLINE | COLOR_PAIR(GNT_COLOR_NORMAL), widget->priv.height); | |
473 mvwhline(widget->window, widget->priv.height - 1, 0, | |
474 ACS_HLINE | COLOR_PAIR(GNT_COLOR_NORMAL), widget->priv.width); | |
475 mvwhline(widget->window, 0, 0, ACS_HLINE | COLOR_PAIR(GNT_COLOR_NORMAL), widget->priv.width); | |
476 mvwaddch(widget->window, 0, 0, ACS_ULCORNER | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
477 mvwaddch(widget->window, 0, widget->priv.width - 1, | |
478 ACS_URCORNER | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
479 mvwaddch(widget->window, widget->priv.height - 1, 0, | |
480 ACS_LLCORNER | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
481 mvwaddch(widget->window, widget->priv.height - 1, widget->priv.width - 1, | |
482 ACS_LRCORNER | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
483 } | |
484 | |
485 if (shadow) | |
486 { | |
487 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_SHADOW)); | |
488 mvwvline(widget->window, 1, widget->priv.width, ' ', widget->priv.height); | |
489 mvwhline(widget->window, widget->priv.height, 1, ' ', widget->priv.width); | |
490 } | |
491 } | |
492 | |
493 gboolean | |
494 gnt_widget_set_size(GntWidget *widget, int width, int height) | |
495 { | |
496 gboolean ret = TRUE; | |
497 | |
498 if (gnt_widget_has_shadow(widget)) | |
499 { | |
500 width--; | |
501 height--; | |
502 } | |
503 if (width <= 0) | |
504 width = widget->priv.width; | |
505 if (height <= 0) | |
506 height = widget->priv.height; | |
507 | |
508 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED)) | |
509 { | |
510 ret = gnt_widget_confirm_size(widget, width, height); | |
511 } | |
512 | |
513 if (ret) | |
514 { | |
515 gboolean shadow = TRUE; | |
516 int oldw, oldh; | |
517 | |
518 if (!gnt_widget_has_shadow(widget)) | |
519 shadow = FALSE; | |
520 | |
521 oldw = widget->priv.width; | |
522 oldh = widget->priv.height; | |
523 | |
524 widget->priv.width = width; | |
525 widget->priv.height = height; | |
15943
7db39d873d52
Do not crash when resizing with shadows turned on.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
526 if (width + shadow >= getmaxx(widget->window) || height + shadow >= getmaxy(widget->window)) { |
15817 | 527 delwin(widget->window); |
528 widget->window = newpad(height + 20, width + 20); | |
529 } | |
530 | |
531 g_signal_emit(widget, signals[SIG_SIZE_CHANGED], 0, oldw, oldh); | |
532 | |
533 if (widget->window) | |
534 { | |
535 init_widget(widget); | |
536 } | |
537 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED)) | |
538 init_widget(widget); | |
539 else | |
540 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_MAPPED); | |
541 } | |
542 | |
543 return ret; | |
544 } | |
545 | |
546 gboolean | |
547 gnt_widget_set_focus(GntWidget *widget, gboolean set) | |
548 { | |
549 if (!(GNT_WIDGET_FLAGS(widget) & GNT_WIDGET_CAN_TAKE_FOCUS)) | |
550 return FALSE; | |
551 | |
552 if (set && !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_HAS_FOCUS)) | |
553 { | |
554 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_HAS_FOCUS); | |
555 g_signal_emit(widget, signals[SIG_GIVE_FOCUS], 0); | |
556 } | |
557 else if (!set) | |
558 { | |
559 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_HAS_FOCUS); | |
560 g_signal_emit(widget, signals[SIG_LOST_FOCUS], 0); | |
561 } | |
562 else | |
563 return FALSE; | |
564 | |
565 return TRUE; | |
566 } | |
567 | |
568 void gnt_widget_set_name(GntWidget *widget, const char *name) | |
569 { | |
570 g_free(widget->priv.name); | |
571 widget->priv.name = g_strdup(name); | |
572 } | |
573 | |
574 const char *gnt_widget_get_name(GntWidget *widget) | |
575 { | |
576 return widget->priv.name; | |
577 } | |
578 | |
579 void gnt_widget_activate(GntWidget *widget) | |
580 { | |
581 g_signal_emit(widget, signals[SIG_ACTIVATE], 0); | |
582 } | |
583 | |
584 static gboolean | |
585 update_queue_callback(gpointer data) | |
586 { | |
587 GntWidget *widget = GNT_WIDGET(data); | |
588 | |
589 if (!g_object_get_data(G_OBJECT(widget), "gnt:queue_update")) | |
590 return FALSE; | |
591 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED)) | |
592 gnt_screen_update(widget); | |
593 g_object_set_data(G_OBJECT(widget), "gnt:queue_update", NULL); | |
594 return FALSE; | |
595 } | |
596 | |
597 void gnt_widget_queue_update(GntWidget *widget) | |
598 { | |
599 if (widget->window == NULL) | |
600 return; | |
601 while (widget->parent) | |
602 widget = widget->parent; | |
603 | |
604 if (!g_object_get_data(G_OBJECT(widget), "gnt:queue_update")) | |
605 { | |
606 int id = g_timeout_add(0, update_queue_callback, widget); | |
607 g_object_set_data_full(G_OBJECT(widget), "gnt:queue_update", GINT_TO_POINTER(id), | |
608 (GDestroyNotify)g_source_remove); | |
609 } | |
610 } | |
611 | |
612 gboolean gnt_widget_confirm_size(GntWidget *widget, int width, int height) | |
613 { | |
614 gboolean ret = FALSE; | |
615 g_signal_emit(widget, signals[SIG_CONFIRM_SIZE], 0, width, height, &ret); | |
616 return ret; | |
617 } | |
618 | |
619 void gnt_widget_set_visible(GntWidget *widget, gboolean set) | |
620 { | |
621 if (set) | |
622 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_INVISIBLE); | |
623 else | |
624 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_INVISIBLE); | |
625 } | |
626 | |
627 gboolean gnt_widget_has_shadow(GntWidget *widget) | |
628 { | |
629 return (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_SHADOW) && | |
630 gnt_style_get_bool(GNT_STYLE_SHADOW, FALSE)); | |
631 } | |
632 |