7
|
1 /* vi:set ts=8 sts=4 sw=4:
|
|
2 *
|
|
3 * VIM - Vi IMproved by Bram Moolenaar
|
|
4 *
|
|
5 * Do ":help uganda" in Vim to read copying and usage conditions.
|
|
6 * Do ":help credits" in Vim to see a list of people who contributed.
|
|
7 * See README.txt for an overview of the Vim source code.
|
|
8 */
|
|
9
|
|
10 /*
|
66
|
11 * (C) 1998,1999 by Marcin Dalecki <martin@dalecki.de>
|
7
|
12 *
|
|
13 * Support for GTK+ 2 was added by:
|
|
14 *
|
|
15 * (C) 2002,2003 Jason Hildebrand <jason@peaceworks.ca>
|
|
16 * Daniel Elstner <daniel.elstner@gmx.net>
|
|
17 *
|
1207
|
18 * This is a special purpose container widget, which manages arbitrary
|
|
19 * children at arbitrary positions width arbitrary sizes. This finally puts
|
|
20 * an end on our resize problems with which we where struggling for such a
|
|
21 * long time.
|
7
|
22 */
|
|
23
|
|
24 #include "vim.h"
|
|
25 #include <gtk/gtk.h> /* without this it compiles, but gives errors at
|
|
26 runtime! */
|
|
27 #include "gui_gtk_f.h"
|
|
28 #include <gtk/gtksignal.h>
|
|
29 #ifdef WIN3264
|
|
30 # include <gdk/gdkwin32.h>
|
|
31 #else
|
|
32 # include <gdk/gdkx.h>
|
|
33 #endif
|
|
34
|
|
35 typedef struct _GtkFormChild GtkFormChild;
|
|
36
|
|
37 struct _GtkFormChild
|
|
38 {
|
|
39 GtkWidget *widget;
|
|
40 GdkWindow *window;
|
|
41 gint x; /* relative subwidget x position */
|
|
42 gint y; /* relative subwidget y position */
|
|
43 gint mapped;
|
|
44 };
|
|
45
|
|
46
|
|
47 static void gtk_form_class_init(GtkFormClass *klass);
|
|
48 static void gtk_form_init(GtkForm *form);
|
|
49
|
|
50 static void gtk_form_realize(GtkWidget *widget);
|
|
51 static void gtk_form_unrealize(GtkWidget *widget);
|
|
52 static void gtk_form_map(GtkWidget *widget);
|
|
53 static void gtk_form_size_request(GtkWidget *widget,
|
|
54 GtkRequisition *requisition);
|
|
55 static void gtk_form_size_allocate(GtkWidget *widget,
|
|
56 GtkAllocation *allocation);
|
|
57 #ifndef HAVE_GTK2 /* this isn't needed in gtk2 */
|
|
58 static void gtk_form_draw(GtkWidget *widget,
|
|
59 GdkRectangle *area);
|
|
60 #endif
|
|
61 static gint gtk_form_expose(GtkWidget *widget,
|
|
62 GdkEventExpose *event);
|
|
63
|
|
64 static void gtk_form_remove(GtkContainer *container,
|
|
65 GtkWidget *widget);
|
|
66 static void gtk_form_forall(GtkContainer *container,
|
|
67 gboolean include_internals,
|
|
68 GtkCallback callback,
|
|
69 gpointer callback_data);
|
|
70
|
|
71 static void gtk_form_attach_child_window(GtkForm *form,
|
|
72 GtkFormChild *child);
|
|
73 static void gtk_form_realize_child(GtkForm *form,
|
|
74 GtkFormChild *child);
|
|
75 static void gtk_form_position_child(GtkForm *form,
|
|
76 GtkFormChild *child,
|
|
77 gboolean force_allocate);
|
|
78 static void gtk_form_position_children(GtkForm *form);
|
|
79
|
|
80 static GdkFilterReturn gtk_form_filter(GdkXEvent *gdk_xevent,
|
|
81 GdkEvent *event,
|
|
82 gpointer data);
|
|
83 static GdkFilterReturn gtk_form_main_filter(GdkXEvent *gdk_xevent,
|
|
84 GdkEvent *event,
|
|
85 gpointer data);
|
|
86
|
|
87 static void gtk_form_set_static_gravity(GdkWindow *window,
|
|
88 gboolean use_static);
|
|
89
|
|
90 static void gtk_form_send_configure(GtkForm *form);
|
|
91
|
|
92 static void gtk_form_child_map(GtkWidget *widget, gpointer user_data);
|
|
93 static void gtk_form_child_unmap(GtkWidget *widget, gpointer user_data);
|
|
94
|
|
95 static GtkWidgetClass *parent_class = NULL;
|
|
96
|
|
97 /* Public interface
|
|
98 */
|
|
99
|
|
100 GtkWidget *
|
|
101 gtk_form_new(void)
|
|
102 {
|
|
103 GtkForm *form;
|
|
104
|
|
105 form = gtk_type_new(gtk_form_get_type());
|
|
106
|
|
107 return GTK_WIDGET(form);
|
|
108 }
|
|
109
|
|
110 void
|
|
111 gtk_form_put(GtkForm *form,
|
|
112 GtkWidget *child_widget,
|
|
113 gint x,
|
|
114 gint y)
|
|
115 {
|
|
116 GtkFormChild *child;
|
|
117
|
|
118 g_return_if_fail(GTK_IS_FORM(form));
|
|
119
|
129
|
120 /* LINTED: avoid warning: conversion to 'unsigned long' */
|
7
|
121 child = g_new(GtkFormChild, 1);
|
|
122
|
|
123 child->widget = child_widget;
|
|
124 child->window = NULL;
|
|
125 child->x = x;
|
|
126 child->y = y;
|
|
127 child->widget->requisition.width = 0;
|
|
128 child->widget->requisition.height = 0;
|
|
129 child->mapped = FALSE;
|
|
130
|
|
131 form->children = g_list_append(form->children, child);
|
|
132
|
|
133 /* child->window must be created and attached to the widget _before_
|
|
134 * it has been realized, or else things will break with GTK2. Note
|
|
135 * that gtk_widget_set_parent() realizes the widget if it's visible
|
|
136 * and its parent is mapped.
|
|
137 */
|
|
138 if (GTK_WIDGET_REALIZED(form))
|
|
139 gtk_form_attach_child_window(form, child);
|
|
140
|
|
141 gtk_widget_set_parent(child_widget, GTK_WIDGET(form));
|
|
142 gtk_widget_size_request(child->widget, NULL);
|
|
143
|
|
144 if (GTK_WIDGET_REALIZED(form) && !GTK_WIDGET_REALIZED(child_widget))
|
|
145 gtk_form_realize_child(form, child);
|
|
146
|
|
147 gtk_form_position_child(form, child, TRUE);
|
|
148 }
|
|
149
|
|
150 void
|
|
151 gtk_form_move(GtkForm *form,
|
|
152 GtkWidget *child_widget,
|
|
153 gint x,
|
|
154 gint y)
|
|
155 {
|
|
156 GList *tmp_list;
|
|
157 GtkFormChild *child;
|
|
158
|
|
159 g_return_if_fail(GTK_IS_FORM(form));
|
|
160
|
|
161 for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next)
|
|
162 {
|
|
163 child = tmp_list->data;
|
|
164 if (child->widget == child_widget)
|
|
165 {
|
|
166 child->x = x;
|
|
167 child->y = y;
|
|
168
|
|
169 gtk_form_position_child(form, child, TRUE);
|
|
170 return;
|
|
171 }
|
|
172 }
|
|
173 }
|
|
174
|
|
175 void
|
|
176 gtk_form_set_size(GtkForm *form, guint width, guint height)
|
|
177 {
|
|
178 g_return_if_fail(GTK_IS_FORM(form));
|
|
179
|
|
180 /* prevent unneccessary calls */
|
|
181 if (form->width == width && form->height == height)
|
|
182 return;
|
|
183 form->width = width;
|
|
184 form->height = height;
|
|
185
|
|
186 /* signal the change */
|
|
187 #ifdef HAVE_GTK2
|
|
188 gtk_widget_queue_resize(gtk_widget_get_parent(GTK_WIDGET(form)));
|
|
189 #else
|
|
190 gtk_container_queue_resize(GTK_CONTAINER(GTK_WIDGET(form)->parent));
|
|
191 #endif
|
|
192 }
|
|
193
|
|
194 void
|
|
195 gtk_form_freeze(GtkForm *form)
|
|
196 {
|
|
197 g_return_if_fail(GTK_IS_FORM(form));
|
|
198
|
|
199 ++form->freeze_count;
|
|
200 }
|
|
201
|
|
202 void
|
|
203 gtk_form_thaw(GtkForm *form)
|
|
204 {
|
|
205 g_return_if_fail(GTK_IS_FORM(form));
|
|
206
|
|
207 if (form->freeze_count)
|
|
208 {
|
|
209 if (!(--form->freeze_count))
|
|
210 {
|
|
211 gtk_form_position_children(form);
|
|
212 #ifdef HAVE_GTK2
|
|
213 gtk_widget_queue_draw(GTK_WIDGET(form));
|
|
214 #else
|
|
215 gtk_widget_draw(GTK_WIDGET(form), NULL);
|
|
216 #endif
|
|
217 }
|
|
218 }
|
|
219 }
|
|
220
|
|
221 /* Basic Object handling procedures
|
|
222 */
|
|
223 GtkType
|
|
224 gtk_form_get_type(void)
|
|
225 {
|
|
226 static GtkType form_type = 0;
|
|
227
|
|
228 if (!form_type)
|
|
229 {
|
1884
|
230 GtkTypeInfo form_info;
|
|
231
|
|
232 form_info.type_name = "GtkForm";
|
|
233 form_info.object_size = sizeof(GtkForm);
|
|
234 form_info.class_size = sizeof(GtkFormClass);
|
|
235 form_info.class_init_func = (GtkClassInitFunc)gtk_form_class_init;
|
|
236 form_info.object_init_func = (GtkObjectInitFunc)gtk_form_init;
|
7
|
237
|
|
238 form_type = gtk_type_unique(GTK_TYPE_CONTAINER, &form_info);
|
|
239 }
|
|
240 return form_type;
|
|
241 }
|
|
242
|
|
243 static void
|
|
244 gtk_form_class_init(GtkFormClass *klass)
|
|
245 {
|
|
246 GtkWidgetClass *widget_class;
|
|
247 GtkContainerClass *container_class;
|
|
248
|
|
249 widget_class = (GtkWidgetClass *) klass;
|
|
250 container_class = (GtkContainerClass *) klass;
|
|
251
|
|
252 parent_class = gtk_type_class(gtk_container_get_type());
|
|
253
|
|
254 widget_class->realize = gtk_form_realize;
|
|
255 widget_class->unrealize = gtk_form_unrealize;
|
|
256 widget_class->map = gtk_form_map;
|
|
257 widget_class->size_request = gtk_form_size_request;
|
|
258 widget_class->size_allocate = gtk_form_size_allocate;
|
|
259 #ifndef HAVE_GTK2 /* not needed for GTK2 */
|
|
260 widget_class->draw = gtk_form_draw;
|
|
261 #endif
|
|
262 widget_class->expose_event = gtk_form_expose;
|
|
263
|
|
264 container_class->remove = gtk_form_remove;
|
|
265 container_class->forall = gtk_form_forall;
|
|
266 }
|
|
267
|
|
268 static void
|
|
269 gtk_form_init(GtkForm *form)
|
|
270 {
|
|
271 form->children = NULL;
|
|
272
|
|
273 form->width = 1;
|
|
274 form->height = 1;
|
|
275
|
|
276 form->bin_window = NULL;
|
|
277
|
|
278 form->configure_serial = 0;
|
|
279 form->visibility = GDK_VISIBILITY_PARTIAL;
|
|
280
|
|
281 form->freeze_count = 0;
|
|
282 }
|
|
283
|
|
284 /*
|
|
285 * Widget methods
|
|
286 */
|
|
287
|
|
288 static void
|
|
289 gtk_form_realize(GtkWidget *widget)
|
|
290 {
|
|
291 GList *tmp_list;
|
|
292 GtkForm *form;
|
|
293 GdkWindowAttr attributes;
|
|
294 gint attributes_mask;
|
|
295
|
|
296 g_return_if_fail(GTK_IS_FORM(widget));
|
|
297
|
|
298 form = GTK_FORM(widget);
|
|
299 GTK_WIDGET_SET_FLAGS(form, GTK_REALIZED);
|
|
300
|
|
301 attributes.window_type = GDK_WINDOW_CHILD;
|
|
302 attributes.x = widget->allocation.x;
|
|
303 attributes.y = widget->allocation.y;
|
|
304 attributes.width = widget->allocation.width;
|
|
305 attributes.height = widget->allocation.height;
|
|
306 attributes.wclass = GDK_INPUT_OUTPUT;
|
|
307 attributes.visual = gtk_widget_get_visual(widget);
|
|
308 attributes.colormap = gtk_widget_get_colormap(widget);
|
|
309 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
|
|
310
|
|
311 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
|
|
312
|
|
313 widget->window = gdk_window_new(gtk_widget_get_parent_window(widget),
|
|
314 &attributes, attributes_mask);
|
|
315 gdk_window_set_user_data(widget->window, widget);
|
|
316
|
|
317 attributes.x = 0;
|
|
318 attributes.y = 0;
|
|
319 attributes.event_mask = gtk_widget_get_events(widget);
|
|
320
|
|
321 form->bin_window = gdk_window_new(widget->window,
|
|
322 &attributes, attributes_mask);
|
|
323 gdk_window_set_user_data(form->bin_window, widget);
|
|
324
|
|
325 gtk_form_set_static_gravity(form->bin_window, TRUE);
|
|
326
|
|
327 widget->style = gtk_style_attach(widget->style, widget->window);
|
|
328 gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL);
|
|
329 gtk_style_set_background(widget->style, form->bin_window, GTK_STATE_NORMAL);
|
|
330
|
|
331 gdk_window_add_filter(widget->window, gtk_form_main_filter, form);
|
|
332 gdk_window_add_filter(form->bin_window, gtk_form_filter, form);
|
|
333
|
|
334 for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next)
|
|
335 {
|
|
336 GtkFormChild *child = tmp_list->data;
|
|
337
|
|
338 gtk_form_attach_child_window(form, child);
|
|
339
|
|
340 if (GTK_WIDGET_VISIBLE(child->widget))
|
|
341 gtk_form_realize_child(form, child);
|
|
342 }
|
|
343 }
|
|
344
|
|
345
|
|
346 /* After reading the documentation at
|
|
347 * http://developer.gnome.org/doc/API/2.0/gtk/gtk-changes-2-0.html
|
|
348 * I think it should be possible to remove this function when compiling
|
|
349 * against gtk-2.0. It doesn't seem to cause problems, though.
|
|
350 *
|
|
351 * Well, I reckon at least the gdk_window_show(form->bin_window)
|
|
352 * is necessary. GtkForm is anything but a usual container widget.
|
|
353 */
|
|
354 static void
|
|
355 gtk_form_map(GtkWidget *widget)
|
|
356 {
|
|
357 GList *tmp_list;
|
|
358 GtkForm *form;
|
|
359
|
|
360 g_return_if_fail(GTK_IS_FORM(widget));
|
|
361
|
|
362 form = GTK_FORM(widget);
|
|
363
|
|
364 GTK_WIDGET_SET_FLAGS(widget, GTK_MAPPED);
|
|
365
|
|
366 gdk_window_show(widget->window);
|
|
367 gdk_window_show(form->bin_window);
|
|
368
|
|
369 for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next)
|
|
370 {
|
|
371 GtkFormChild *child = tmp_list->data;
|
|
372
|
|
373 if (GTK_WIDGET_VISIBLE(child->widget)
|
|
374 && !GTK_WIDGET_MAPPED(child->widget))
|
|
375 gtk_widget_map(child->widget);
|
|
376 }
|
|
377 }
|
|
378
|
|
379 static void
|
|
380 gtk_form_unrealize(GtkWidget *widget)
|
|
381 {
|
|
382 GList *tmp_list;
|
|
383 GtkForm *form;
|
|
384
|
|
385 g_return_if_fail(GTK_IS_FORM(widget));
|
|
386
|
|
387 form = GTK_FORM(widget);
|
|
388
|
|
389 tmp_list = form->children;
|
|
390
|
|
391 gdk_window_set_user_data(form->bin_window, NULL);
|
|
392 gdk_window_destroy(form->bin_window);
|
|
393 form->bin_window = NULL;
|
|
394
|
|
395 while (tmp_list)
|
|
396 {
|
|
397 GtkFormChild *child = tmp_list->data;
|
|
398
|
|
399 if (child->window != NULL)
|
|
400 {
|
|
401 gtk_signal_disconnect_by_func(GTK_OBJECT(child->widget),
|
|
402 GTK_SIGNAL_FUNC(gtk_form_child_map),
|
|
403 child);
|
|
404 gtk_signal_disconnect_by_func(GTK_OBJECT(child->widget),
|
|
405 GTK_SIGNAL_FUNC(gtk_form_child_unmap),
|
|
406 child);
|
|
407
|
|
408 gdk_window_set_user_data(child->window, NULL);
|
|
409 gdk_window_destroy(child->window);
|
|
410
|
|
411 child->window = NULL;
|
|
412 }
|
|
413
|
|
414 tmp_list = tmp_list->next;
|
|
415 }
|
|
416
|
|
417 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
|
|
418 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
|
|
419 }
|
|
420
|
|
421 #ifndef HAVE_GTK2
|
|
422 static void
|
|
423 gtk_form_draw(GtkWidget *widget, GdkRectangle *area)
|
|
424 {
|
|
425 GtkForm *form;
|
|
426 GList *children;
|
|
427 GtkFormChild *child;
|
|
428 GdkRectangle child_area;
|
|
429
|
|
430 g_return_if_fail(GTK_IS_FORM(widget));
|
|
431
|
|
432 if (GTK_WIDGET_DRAWABLE(widget))
|
|
433 {
|
|
434 form = GTK_FORM(widget);
|
|
435
|
|
436 children = form->children;
|
|
437
|
|
438 while (children)
|
|
439 {
|
|
440 child = children->data;
|
|
441
|
|
442 if (GTK_WIDGET_DRAWABLE(child->widget)
|
|
443 && gtk_widget_intersect(child->widget, area, &child_area))
|
|
444 gtk_widget_draw(child->widget, &child_area);
|
|
445
|
|
446 children = children->next;
|
|
447 }
|
|
448 }
|
|
449 }
|
|
450 #endif /* !HAVE_GTK2 */
|
|
451
|
|
452 static void
|
|
453 gtk_form_size_request(GtkWidget *widget, GtkRequisition *requisition)
|
|
454 {
|
|
455 GList *tmp_list;
|
|
456 GtkForm *form;
|
|
457
|
|
458 g_return_if_fail(GTK_IS_FORM(widget));
|
|
459
|
|
460 form = GTK_FORM(widget);
|
|
461
|
|
462 requisition->width = form->width;
|
|
463 requisition->height = form->height;
|
|
464
|
|
465 tmp_list = form->children;
|
|
466
|
|
467 while (tmp_list)
|
|
468 {
|
|
469 GtkFormChild *child = tmp_list->data;
|
|
470 gtk_widget_size_request(child->widget, NULL);
|
|
471 tmp_list = tmp_list->next;
|
|
472 }
|
|
473 }
|
|
474
|
|
475 static void
|
|
476 gtk_form_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
|
|
477 {
|
|
478 GList *tmp_list;
|
|
479 GtkForm *form;
|
|
480 gboolean need_reposition;
|
|
481
|
|
482 g_return_if_fail(GTK_IS_FORM(widget));
|
|
483
|
|
484 if (widget->allocation.x == allocation->x
|
|
485 && widget->allocation.y == allocation->y
|
|
486 && widget->allocation.width == allocation->width
|
|
487 && widget->allocation.height == allocation->height)
|
|
488 return;
|
|
489
|
|
490 need_reposition = widget->allocation.width != allocation->width
|
|
491 || widget->allocation.height != allocation->height;
|
|
492 form = GTK_FORM(widget);
|
|
493
|
|
494 if (need_reposition)
|
|
495 {
|
|
496 tmp_list = form->children;
|
|
497
|
|
498 while (tmp_list)
|
|
499 {
|
|
500 GtkFormChild *child = tmp_list->data;
|
|
501 gtk_form_position_child(form, child, TRUE);
|
|
502
|
|
503 tmp_list = tmp_list->next;
|
|
504 }
|
|
505 }
|
|
506
|
|
507 if (GTK_WIDGET_REALIZED(widget))
|
|
508 {
|
|
509 gdk_window_move_resize(widget->window,
|
|
510 allocation->x, allocation->y,
|
|
511 allocation->width, allocation->height);
|
|
512 gdk_window_move_resize(GTK_FORM(widget)->bin_window,
|
|
513 0, 0,
|
|
514 allocation->width, allocation->height);
|
|
515 }
|
|
516 widget->allocation = *allocation;
|
|
517 if (need_reposition)
|
|
518 gtk_form_send_configure(form);
|
|
519 }
|
|
520
|
|
521 static gint
|
|
522 gtk_form_expose(GtkWidget *widget, GdkEventExpose *event)
|
|
523 {
|
|
524 GList *tmp_list;
|
|
525 GtkForm *form;
|
|
526
|
|
527 g_return_val_if_fail(GTK_IS_FORM(widget), FALSE);
|
|
528
|
|
529 form = GTK_FORM(widget);
|
|
530
|
|
531 if (event->window == form->bin_window)
|
|
532 return FALSE;
|
|
533
|
|
534 for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next)
|
|
535 {
|
|
536 #ifdef HAVE_GTK2
|
|
537 GtkFormChild *formchild = tmp_list->data;
|
|
538 GtkWidget *child = formchild->widget;
|
|
539 /*
|
|
540 * The following chunk of code is taken from gtkcontainer.c. The
|
|
541 * gtk1.x code synthesized expose events directly on the child widgets,
|
|
542 * which can't be done in gtk2
|
|
543 */
|
|
544 if (GTK_WIDGET_DRAWABLE(child) && GTK_WIDGET_NO_WINDOW(child)
|
|
545 && child->window == event->window)
|
|
546 {
|
|
547 GdkEventExpose child_event;
|
|
548 child_event = *event;
|
|
549
|
|
550 child_event.region = gtk_widget_region_intersect(child, event->region);
|
|
551 if (!gdk_region_empty(child_event.region))
|
|
552 {
|
|
553 gdk_region_get_clipbox(child_event.region, &child_event.area);
|
|
554 gtk_widget_send_expose(child, (GdkEvent *)&child_event);
|
|
555 }
|
|
556 }
|
|
557 #else /* !HAVE_GTK2 */
|
|
558 GtkFormChild *child = tmp_list->data;
|
|
559
|
|
560 if (event->window == child->window)
|
|
561 return gtk_widget_event(child->widget, (GdkEvent *) event);
|
|
562 #endif /* !HAVE_GTK2 */
|
|
563 }
|
|
564
|
|
565 return FALSE;
|
|
566 }
|
|
567
|
|
568 /* Container method
|
|
569 */
|
|
570 static void
|
|
571 gtk_form_remove(GtkContainer *container, GtkWidget *widget)
|
|
572 {
|
|
573 GList *tmp_list;
|
|
574 GtkForm *form;
|
|
575 GtkFormChild *child = NULL; /* init for gcc */
|
|
576
|
|
577 g_return_if_fail(GTK_IS_FORM(container));
|
|
578
|
|
579 form = GTK_FORM(container);
|
|
580
|
|
581 tmp_list = form->children;
|
|
582 while (tmp_list)
|
|
583 {
|
|
584 child = tmp_list->data;
|
|
585 if (child->widget == widget)
|
|
586 break;
|
|
587 tmp_list = tmp_list->next;
|
|
588 }
|
|
589
|
|
590 if (tmp_list)
|
|
591 {
|
|
592 if (child->window)
|
|
593 {
|
|
594 gtk_signal_disconnect_by_func(GTK_OBJECT(child->widget),
|
|
595 GTK_SIGNAL_FUNC(>k_form_child_map), child);
|
|
596 gtk_signal_disconnect_by_func(GTK_OBJECT(child->widget),
|
|
597 GTK_SIGNAL_FUNC(>k_form_child_unmap), child);
|
|
598
|
|
599 /* FIXME: This will cause problems for reparenting NO_WINDOW
|
|
600 * widgets out of a GtkForm
|
|
601 */
|
|
602 gdk_window_set_user_data(child->window, NULL);
|
|
603 gdk_window_destroy(child->window);
|
|
604 }
|
|
605 gtk_widget_unparent(widget);
|
|
606
|
|
607 form->children = g_list_remove_link(form->children, tmp_list);
|
|
608 g_list_free_1(tmp_list);
|
|
609 g_free(child);
|
|
610 }
|
|
611 }
|
|
612
|
|
613 static void
|
|
614 gtk_form_forall(GtkContainer *container,
|
1884
|
615 gboolean include_internals UNUSED,
|
7
|
616 GtkCallback callback,
|
|
617 gpointer callback_data)
|
|
618 {
|
|
619 GtkForm *form;
|
|
620 GtkFormChild *child;
|
|
621 GList *tmp_list;
|
|
622
|
|
623 g_return_if_fail(GTK_IS_FORM(container));
|
|
624 g_return_if_fail(callback != NULL);
|
|
625
|
|
626 form = GTK_FORM(container);
|
|
627
|
|
628 tmp_list = form->children;
|
|
629 while (tmp_list)
|
|
630 {
|
|
631 child = tmp_list->data;
|
|
632 tmp_list = tmp_list->next;
|
|
633
|
|
634 (*callback) (child->widget, callback_data);
|
|
635 }
|
|
636 }
|
|
637
|
|
638 /* Operations on children
|
|
639 */
|
|
640
|
|
641 static void
|
|
642 gtk_form_attach_child_window(GtkForm *form, GtkFormChild *child)
|
|
643 {
|
|
644 if (child->window != NULL)
|
|
645 return; /* been there, done that */
|
|
646
|
|
647 if (GTK_WIDGET_NO_WINDOW(child->widget))
|
|
648 {
|
|
649 GtkWidget *widget;
|
|
650 GdkWindowAttr attributes;
|
|
651 gint attributes_mask;
|
|
652
|
|
653 widget = GTK_WIDGET(form);
|
|
654
|
|
655 attributes.window_type = GDK_WINDOW_CHILD;
|
|
656 attributes.x = child->x;
|
|
657 attributes.y = child->y;
|
|
658 attributes.width = child->widget->requisition.width;
|
|
659 attributes.height = child->widget->requisition.height;
|
|
660 attributes.wclass = GDK_INPUT_OUTPUT;
|
|
661 attributes.visual = gtk_widget_get_visual(widget);
|
|
662 attributes.colormap = gtk_widget_get_colormap(widget);
|
|
663 attributes.event_mask = GDK_EXPOSURE_MASK;
|
|
664
|
|
665 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
|
|
666 child->window = gdk_window_new(form->bin_window,
|
|
667 &attributes, attributes_mask);
|
|
668 gdk_window_set_user_data(child->window, widget);
|
|
669
|
|
670 gtk_style_set_background(widget->style,
|
|
671 child->window,
|
|
672 GTK_STATE_NORMAL);
|
|
673
|
|
674 gtk_widget_set_parent_window(child->widget, child->window);
|
|
675 gtk_form_set_static_gravity(child->window, TRUE);
|
|
676 /*
|
|
677 * Install signal handlers to map/unmap child->window
|
|
678 * alongside with the actual widget.
|
|
679 */
|
|
680 gtk_signal_connect(GTK_OBJECT(child->widget), "map",
|
|
681 GTK_SIGNAL_FUNC(>k_form_child_map), child);
|
|
682 gtk_signal_connect(GTK_OBJECT(child->widget), "unmap",
|
|
683 GTK_SIGNAL_FUNC(>k_form_child_unmap), child);
|
|
684 }
|
|
685 else if (!GTK_WIDGET_REALIZED(child->widget))
|
|
686 {
|
|
687 gtk_widget_set_parent_window(child->widget, form->bin_window);
|
|
688 }
|
|
689 }
|
|
690
|
|
691 static void
|
|
692 gtk_form_realize_child(GtkForm *form, GtkFormChild *child)
|
|
693 {
|
|
694 gtk_form_attach_child_window(form, child);
|
|
695 gtk_widget_realize(child->widget);
|
|
696
|
|
697 if (child->window == NULL) /* might be already set, see above */
|
|
698 gtk_form_set_static_gravity(child->widget->window, TRUE);
|
|
699 }
|
|
700
|
|
701 static void
|
|
702 gtk_form_position_child(GtkForm *form, GtkFormChild *child,
|
|
703 gboolean force_allocate)
|
|
704 {
|
|
705 gint x;
|
|
706 gint y;
|
|
707
|
|
708 x = child->x;
|
|
709 y = child->y;
|
|
710
|
|
711 if ((x >= G_MINSHORT) && (x <= G_MAXSHORT) &&
|
|
712 (y >= G_MINSHORT) && (y <= G_MAXSHORT))
|
|
713 {
|
|
714 if (!child->mapped)
|
|
715 {
|
|
716 if (GTK_WIDGET_MAPPED(form) && GTK_WIDGET_VISIBLE(child->widget))
|
|
717 {
|
|
718 if (!GTK_WIDGET_MAPPED(child->widget))
|
|
719 gtk_widget_map(child->widget);
|
|
720
|
|
721 child->mapped = TRUE;
|
|
722 force_allocate = TRUE;
|
|
723 }
|
|
724 }
|
|
725
|
|
726 if (force_allocate)
|
|
727 {
|
|
728 GtkAllocation allocation;
|
|
729
|
|
730 if (GTK_WIDGET_NO_WINDOW(child->widget))
|
|
731 {
|
|
732 if (child->window)
|
|
733 {
|
|
734 gdk_window_move_resize(child->window,
|
|
735 x, y,
|
|
736 child->widget->requisition.width,
|
|
737 child->widget->requisition.height);
|
|
738 }
|
|
739
|
|
740 allocation.x = 0;
|
|
741 allocation.y = 0;
|
|
742 }
|
|
743 else
|
|
744 {
|
|
745 allocation.x = x;
|
|
746 allocation.y = y;
|
|
747 }
|
|
748
|
|
749 allocation.width = child->widget->requisition.width;
|
|
750 allocation.height = child->widget->requisition.height;
|
|
751
|
|
752 gtk_widget_size_allocate(child->widget, &allocation);
|
|
753 }
|
|
754 }
|
|
755 else
|
|
756 {
|
|
757 if (child->mapped)
|
|
758 {
|
|
759 child->mapped = FALSE;
|
|
760
|
|
761 if (GTK_WIDGET_MAPPED(child->widget))
|
|
762 gtk_widget_unmap(child->widget);
|
|
763 }
|
|
764 }
|
|
765 }
|
|
766
|
|
767 static void
|
|
768 gtk_form_position_children(GtkForm *form)
|
|
769 {
|
|
770 GList *tmp_list;
|
|
771
|
|
772 for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next)
|
|
773 gtk_form_position_child(form, tmp_list->data, FALSE);
|
|
774 }
|
|
775
|
|
776 /* Callbacks */
|
|
777
|
|
778 /* The main event filter. Actually, we probably don't really need
|
|
779 * to install this as a filter at all, since we are calling it
|
|
780 * directly above in the expose-handling hack.
|
|
781 *
|
|
782 * This routine identifies expose events that are generated when
|
|
783 * we've temporarily moved the bin_window_origin, and translates
|
|
784 * them or discards them, depending on whether we are obscured
|
|
785 * or not.
|
|
786 */
|
|
787 static GdkFilterReturn
|
1884
|
788 gtk_form_filter(GdkXEvent *gdk_xevent, GdkEvent *event UNUSED, gpointer data)
|
7
|
789 {
|
|
790 XEvent *xevent;
|
|
791 GtkForm *form;
|
|
792
|
|
793 xevent = (XEvent *) gdk_xevent;
|
|
794 form = GTK_FORM(data);
|
|
795
|
|
796 switch (xevent->type)
|
|
797 {
|
|
798 case Expose:
|
|
799 if (xevent->xexpose.serial == form->configure_serial)
|
|
800 {
|
|
801 if (form->visibility == GDK_VISIBILITY_UNOBSCURED)
|
|
802 return GDK_FILTER_REMOVE;
|
|
803 else
|
|
804 break;
|
|
805 }
|
|
806 break;
|
|
807
|
|
808 case ConfigureNotify:
|
|
809 if ((xevent->xconfigure.x != 0) || (xevent->xconfigure.y != 0))
|
|
810 form->configure_serial = xevent->xconfigure.serial;
|
|
811 break;
|
|
812 }
|
|
813
|
|
814 return GDK_FILTER_CONTINUE;
|
|
815 }
|
|
816
|
|
817 /* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
|
|
818 * there is no corresponding event in GTK, so we have
|
|
819 * to get the events from a filter
|
|
820 */
|
|
821 static GdkFilterReturn
|
1884
|
822 gtk_form_main_filter(GdkXEvent *gdk_xevent,
|
|
823 GdkEvent *event UNUSED,
|
|
824 gpointer data)
|
7
|
825 {
|
|
826 XEvent *xevent;
|
|
827 GtkForm *form;
|
|
828
|
|
829 xevent = (XEvent *) gdk_xevent;
|
|
830 form = GTK_FORM(data);
|
|
831
|
|
832 if (xevent->type == VisibilityNotify)
|
|
833 {
|
|
834 switch (xevent->xvisibility.state)
|
|
835 {
|
|
836 case VisibilityFullyObscured:
|
|
837 form->visibility = GDK_VISIBILITY_FULLY_OBSCURED;
|
|
838 break;
|
|
839
|
|
840 case VisibilityPartiallyObscured:
|
|
841 form->visibility = GDK_VISIBILITY_PARTIAL;
|
|
842 break;
|
|
843
|
|
844 case VisibilityUnobscured:
|
|
845 form->visibility = GDK_VISIBILITY_UNOBSCURED;
|
|
846 break;
|
|
847 }
|
|
848
|
|
849 return GDK_FILTER_REMOVE;
|
|
850 }
|
|
851 return GDK_FILTER_CONTINUE;
|
|
852 }
|
|
853
|
|
854 /* Routines to set the window gravity, and check whether it is
|
|
855 * functional. Extra capabilities need to be added to GDK, so
|
|
856 * we don't have to use Xlib here.
|
|
857 */
|
|
858 static void
|
|
859 gtk_form_set_static_gravity(GdkWindow *window, gboolean use_static)
|
|
860 {
|
|
861 #ifdef HAVE_GTK2
|
|
862 gboolean static_gravity_supported;
|
|
863
|
|
864 static_gravity_supported = gdk_window_set_static_gravities(window,
|
|
865 use_static);
|
|
866 g_return_if_fail(static_gravity_supported);
|
|
867 #else
|
|
868 XSetWindowAttributes xattributes;
|
|
869
|
|
870 xattributes.win_gravity = (use_static) ? StaticGravity : NorthWestGravity;
|
|
871 xattributes.bit_gravity = (use_static) ? StaticGravity : NorthWestGravity;
|
|
872
|
|
873 XChangeWindowAttributes(GDK_WINDOW_XDISPLAY(window),
|
|
874 GDK_WINDOW_XWINDOW(window),
|
|
875 CWBitGravity | CWWinGravity,
|
|
876 &xattributes);
|
|
877 #endif
|
|
878 }
|
|
879
|
|
880 void
|
|
881 gtk_form_move_resize(GtkForm *form, GtkWidget *widget,
|
|
882 gint x, gint y, gint w, gint h)
|
|
883 {
|
|
884 widget->requisition.width = w;
|
|
885 widget->requisition.height = h;
|
|
886
|
|
887 gtk_form_move(form, widget, x, y);
|
|
888 }
|
|
889
|
|
890 static void
|
|
891 gtk_form_send_configure(GtkForm *form)
|
|
892 {
|
|
893 GtkWidget *widget;
|
|
894 GdkEventConfigure event;
|
|
895
|
|
896 widget = GTK_WIDGET(form);
|
|
897
|
|
898 event.type = GDK_CONFIGURE;
|
|
899 event.window = widget->window;
|
|
900 event.x = widget->allocation.x;
|
|
901 event.y = widget->allocation.y;
|
|
902 event.width = widget->allocation.width;
|
|
903 event.height = widget->allocation.height;
|
|
904
|
|
905 #ifdef HAVE_GTK2
|
|
906 gtk_main_do_event((GdkEvent*)&event);
|
|
907 #else
|
|
908 gtk_widget_event(widget, (GdkEvent*)&event);
|
|
909 #endif
|
|
910 }
|
|
911
|
|
912 static void
|
1884
|
913 gtk_form_child_map(GtkWidget *widget UNUSED, gpointer user_data)
|
7
|
914 {
|
|
915 GtkFormChild *child;
|
|
916
|
|
917 child = (GtkFormChild *)user_data;
|
|
918
|
|
919 child->mapped = TRUE;
|
|
920 gdk_window_show(child->window);
|
|
921 }
|
|
922
|
|
923 static void
|
1884
|
924 gtk_form_child_unmap(GtkWidget *widget UNUSED, gpointer user_data)
|
7
|
925 {
|
|
926 GtkFormChild *child;
|
|
927
|
|
928 child = (GtkFormChild *)user_data;
|
|
929
|
|
930 child->mapped = FALSE;
|
|
931 gdk_window_hide(child->window);
|
|
932 }
|
|
933
|