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
|
1885
|
232 vim_memset(&form_info, 0, sizeof(form_info));
|
1884
|
233 form_info.type_name = "GtkForm";
|
|
234 form_info.object_size = sizeof(GtkForm);
|
|
235 form_info.class_size = sizeof(GtkFormClass);
|
|
236 form_info.class_init_func = (GtkClassInitFunc)gtk_form_class_init;
|
|
237 form_info.object_init_func = (GtkObjectInitFunc)gtk_form_init;
|
7
|
238
|
|
239 form_type = gtk_type_unique(GTK_TYPE_CONTAINER, &form_info);
|
|
240 }
|
|
241 return form_type;
|
|
242 }
|
|
243
|
|
244 static void
|
|
245 gtk_form_class_init(GtkFormClass *klass)
|
|
246 {
|
|
247 GtkWidgetClass *widget_class;
|
|
248 GtkContainerClass *container_class;
|
|
249
|
|
250 widget_class = (GtkWidgetClass *) klass;
|
|
251 container_class = (GtkContainerClass *) klass;
|
|
252
|
|
253 parent_class = gtk_type_class(gtk_container_get_type());
|
|
254
|
|
255 widget_class->realize = gtk_form_realize;
|
|
256 widget_class->unrealize = gtk_form_unrealize;
|
|
257 widget_class->map = gtk_form_map;
|
|
258 widget_class->size_request = gtk_form_size_request;
|
|
259 widget_class->size_allocate = gtk_form_size_allocate;
|
|
260 #ifndef HAVE_GTK2 /* not needed for GTK2 */
|
|
261 widget_class->draw = gtk_form_draw;
|
|
262 #endif
|
|
263 widget_class->expose_event = gtk_form_expose;
|
|
264
|
|
265 container_class->remove = gtk_form_remove;
|
|
266 container_class->forall = gtk_form_forall;
|
|
267 }
|
|
268
|
|
269 static void
|
|
270 gtk_form_init(GtkForm *form)
|
|
271 {
|
|
272 form->children = NULL;
|
|
273
|
|
274 form->width = 1;
|
|
275 form->height = 1;
|
|
276
|
|
277 form->bin_window = NULL;
|
|
278
|
|
279 form->configure_serial = 0;
|
|
280 form->visibility = GDK_VISIBILITY_PARTIAL;
|
|
281
|
|
282 form->freeze_count = 0;
|
|
283 }
|
|
284
|
|
285 /*
|
|
286 * Widget methods
|
|
287 */
|
|
288
|
|
289 static void
|
|
290 gtk_form_realize(GtkWidget *widget)
|
|
291 {
|
|
292 GList *tmp_list;
|
|
293 GtkForm *form;
|
|
294 GdkWindowAttr attributes;
|
|
295 gint attributes_mask;
|
|
296
|
|
297 g_return_if_fail(GTK_IS_FORM(widget));
|
|
298
|
|
299 form = GTK_FORM(widget);
|
|
300 GTK_WIDGET_SET_FLAGS(form, GTK_REALIZED);
|
|
301
|
|
302 attributes.window_type = GDK_WINDOW_CHILD;
|
|
303 attributes.x = widget->allocation.x;
|
|
304 attributes.y = widget->allocation.y;
|
|
305 attributes.width = widget->allocation.width;
|
|
306 attributes.height = widget->allocation.height;
|
|
307 attributes.wclass = GDK_INPUT_OUTPUT;
|
|
308 attributes.visual = gtk_widget_get_visual(widget);
|
|
309 attributes.colormap = gtk_widget_get_colormap(widget);
|
|
310 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
|
|
311
|
|
312 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
|
|
313
|
|
314 widget->window = gdk_window_new(gtk_widget_get_parent_window(widget),
|
|
315 &attributes, attributes_mask);
|
|
316 gdk_window_set_user_data(widget->window, widget);
|
|
317
|
|
318 attributes.x = 0;
|
|
319 attributes.y = 0;
|
|
320 attributes.event_mask = gtk_widget_get_events(widget);
|
|
321
|
|
322 form->bin_window = gdk_window_new(widget->window,
|
|
323 &attributes, attributes_mask);
|
|
324 gdk_window_set_user_data(form->bin_window, widget);
|
|
325
|
|
326 gtk_form_set_static_gravity(form->bin_window, TRUE);
|
|
327
|
|
328 widget->style = gtk_style_attach(widget->style, widget->window);
|
|
329 gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL);
|
|
330 gtk_style_set_background(widget->style, form->bin_window, GTK_STATE_NORMAL);
|
|
331
|
|
332 gdk_window_add_filter(widget->window, gtk_form_main_filter, form);
|
|
333 gdk_window_add_filter(form->bin_window, gtk_form_filter, form);
|
|
334
|
|
335 for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next)
|
|
336 {
|
|
337 GtkFormChild *child = tmp_list->data;
|
|
338
|
|
339 gtk_form_attach_child_window(form, child);
|
|
340
|
|
341 if (GTK_WIDGET_VISIBLE(child->widget))
|
|
342 gtk_form_realize_child(form, child);
|
|
343 }
|
|
344 }
|
|
345
|
|
346
|
|
347 /* After reading the documentation at
|
|
348 * http://developer.gnome.org/doc/API/2.0/gtk/gtk-changes-2-0.html
|
|
349 * I think it should be possible to remove this function when compiling
|
|
350 * against gtk-2.0. It doesn't seem to cause problems, though.
|
|
351 *
|
|
352 * Well, I reckon at least the gdk_window_show(form->bin_window)
|
|
353 * is necessary. GtkForm is anything but a usual container widget.
|
|
354 */
|
|
355 static void
|
|
356 gtk_form_map(GtkWidget *widget)
|
|
357 {
|
|
358 GList *tmp_list;
|
|
359 GtkForm *form;
|
|
360
|
|
361 g_return_if_fail(GTK_IS_FORM(widget));
|
|
362
|
|
363 form = GTK_FORM(widget);
|
|
364
|
|
365 GTK_WIDGET_SET_FLAGS(widget, GTK_MAPPED);
|
|
366
|
|
367 gdk_window_show(widget->window);
|
|
368 gdk_window_show(form->bin_window);
|
|
369
|
|
370 for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next)
|
|
371 {
|
|
372 GtkFormChild *child = tmp_list->data;
|
|
373
|
|
374 if (GTK_WIDGET_VISIBLE(child->widget)
|
|
375 && !GTK_WIDGET_MAPPED(child->widget))
|
|
376 gtk_widget_map(child->widget);
|
|
377 }
|
|
378 }
|
|
379
|
|
380 static void
|
|
381 gtk_form_unrealize(GtkWidget *widget)
|
|
382 {
|
|
383 GList *tmp_list;
|
|
384 GtkForm *form;
|
|
385
|
|
386 g_return_if_fail(GTK_IS_FORM(widget));
|
|
387
|
|
388 form = GTK_FORM(widget);
|
|
389
|
|
390 tmp_list = form->children;
|
|
391
|
|
392 gdk_window_set_user_data(form->bin_window, NULL);
|
|
393 gdk_window_destroy(form->bin_window);
|
|
394 form->bin_window = NULL;
|
|
395
|
|
396 while (tmp_list)
|
|
397 {
|
|
398 GtkFormChild *child = tmp_list->data;
|
|
399
|
|
400 if (child->window != NULL)
|
|
401 {
|
|
402 gtk_signal_disconnect_by_func(GTK_OBJECT(child->widget),
|
|
403 GTK_SIGNAL_FUNC(gtk_form_child_map),
|
|
404 child);
|
|
405 gtk_signal_disconnect_by_func(GTK_OBJECT(child->widget),
|
|
406 GTK_SIGNAL_FUNC(gtk_form_child_unmap),
|
|
407 child);
|
|
408
|
|
409 gdk_window_set_user_data(child->window, NULL);
|
|
410 gdk_window_destroy(child->window);
|
|
411
|
|
412 child->window = NULL;
|
|
413 }
|
|
414
|
|
415 tmp_list = tmp_list->next;
|
|
416 }
|
|
417
|
|
418 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
|
|
419 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
|
|
420 }
|
|
421
|
|
422 #ifndef HAVE_GTK2
|
|
423 static void
|
|
424 gtk_form_draw(GtkWidget *widget, GdkRectangle *area)
|
|
425 {
|
|
426 GtkForm *form;
|
|
427 GList *children;
|
|
428 GtkFormChild *child;
|
|
429 GdkRectangle child_area;
|
|
430
|
|
431 g_return_if_fail(GTK_IS_FORM(widget));
|
|
432
|
|
433 if (GTK_WIDGET_DRAWABLE(widget))
|
|
434 {
|
|
435 form = GTK_FORM(widget);
|
|
436
|
|
437 children = form->children;
|
|
438
|
|
439 while (children)
|
|
440 {
|
|
441 child = children->data;
|
|
442
|
|
443 if (GTK_WIDGET_DRAWABLE(child->widget)
|
|
444 && gtk_widget_intersect(child->widget, area, &child_area))
|
|
445 gtk_widget_draw(child->widget, &child_area);
|
|
446
|
|
447 children = children->next;
|
|
448 }
|
|
449 }
|
|
450 }
|
|
451 #endif /* !HAVE_GTK2 */
|
|
452
|
|
453 static void
|
|
454 gtk_form_size_request(GtkWidget *widget, GtkRequisition *requisition)
|
|
455 {
|
|
456 GList *tmp_list;
|
|
457 GtkForm *form;
|
|
458
|
|
459 g_return_if_fail(GTK_IS_FORM(widget));
|
|
460
|
|
461 form = GTK_FORM(widget);
|
|
462
|
|
463 requisition->width = form->width;
|
|
464 requisition->height = form->height;
|
|
465
|
|
466 tmp_list = form->children;
|
|
467
|
|
468 while (tmp_list)
|
|
469 {
|
|
470 GtkFormChild *child = tmp_list->data;
|
|
471 gtk_widget_size_request(child->widget, NULL);
|
|
472 tmp_list = tmp_list->next;
|
|
473 }
|
|
474 }
|
|
475
|
|
476 static void
|
|
477 gtk_form_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
|
|
478 {
|
|
479 GList *tmp_list;
|
|
480 GtkForm *form;
|
|
481 gboolean need_reposition;
|
|
482
|
|
483 g_return_if_fail(GTK_IS_FORM(widget));
|
|
484
|
|
485 if (widget->allocation.x == allocation->x
|
|
486 && widget->allocation.y == allocation->y
|
|
487 && widget->allocation.width == allocation->width
|
|
488 && widget->allocation.height == allocation->height)
|
|
489 return;
|
|
490
|
|
491 need_reposition = widget->allocation.width != allocation->width
|
|
492 || widget->allocation.height != allocation->height;
|
|
493 form = GTK_FORM(widget);
|
|
494
|
|
495 if (need_reposition)
|
|
496 {
|
|
497 tmp_list = form->children;
|
|
498
|
|
499 while (tmp_list)
|
|
500 {
|
|
501 GtkFormChild *child = tmp_list->data;
|
|
502 gtk_form_position_child(form, child, TRUE);
|
|
503
|
|
504 tmp_list = tmp_list->next;
|
|
505 }
|
|
506 }
|
|
507
|
|
508 if (GTK_WIDGET_REALIZED(widget))
|
|
509 {
|
|
510 gdk_window_move_resize(widget->window,
|
|
511 allocation->x, allocation->y,
|
|
512 allocation->width, allocation->height);
|
|
513 gdk_window_move_resize(GTK_FORM(widget)->bin_window,
|
|
514 0, 0,
|
|
515 allocation->width, allocation->height);
|
|
516 }
|
|
517 widget->allocation = *allocation;
|
|
518 if (need_reposition)
|
|
519 gtk_form_send_configure(form);
|
|
520 }
|
|
521
|
|
522 static gint
|
|
523 gtk_form_expose(GtkWidget *widget, GdkEventExpose *event)
|
|
524 {
|
|
525 GList *tmp_list;
|
|
526 GtkForm *form;
|
|
527
|
|
528 g_return_val_if_fail(GTK_IS_FORM(widget), FALSE);
|
|
529
|
|
530 form = GTK_FORM(widget);
|
|
531
|
|
532 if (event->window == form->bin_window)
|
|
533 return FALSE;
|
|
534
|
|
535 for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next)
|
|
536 {
|
|
537 #ifdef HAVE_GTK2
|
|
538 GtkFormChild *formchild = tmp_list->data;
|
|
539 GtkWidget *child = formchild->widget;
|
|
540 /*
|
|
541 * The following chunk of code is taken from gtkcontainer.c. The
|
|
542 * gtk1.x code synthesized expose events directly on the child widgets,
|
|
543 * which can't be done in gtk2
|
|
544 */
|
|
545 if (GTK_WIDGET_DRAWABLE(child) && GTK_WIDGET_NO_WINDOW(child)
|
|
546 && child->window == event->window)
|
|
547 {
|
|
548 GdkEventExpose child_event;
|
|
549 child_event = *event;
|
|
550
|
|
551 child_event.region = gtk_widget_region_intersect(child, event->region);
|
|
552 if (!gdk_region_empty(child_event.region))
|
|
553 {
|
|
554 gdk_region_get_clipbox(child_event.region, &child_event.area);
|
|
555 gtk_widget_send_expose(child, (GdkEvent *)&child_event);
|
|
556 }
|
|
557 }
|
|
558 #else /* !HAVE_GTK2 */
|
|
559 GtkFormChild *child = tmp_list->data;
|
|
560
|
|
561 if (event->window == child->window)
|
|
562 return gtk_widget_event(child->widget, (GdkEvent *) event);
|
|
563 #endif /* !HAVE_GTK2 */
|
|
564 }
|
|
565
|
|
566 return FALSE;
|
|
567 }
|
|
568
|
|
569 /* Container method
|
|
570 */
|
|
571 static void
|
|
572 gtk_form_remove(GtkContainer *container, GtkWidget *widget)
|
|
573 {
|
|
574 GList *tmp_list;
|
|
575 GtkForm *form;
|
|
576 GtkFormChild *child = NULL; /* init for gcc */
|
|
577
|
|
578 g_return_if_fail(GTK_IS_FORM(container));
|
|
579
|
|
580 form = GTK_FORM(container);
|
|
581
|
|
582 tmp_list = form->children;
|
|
583 while (tmp_list)
|
|
584 {
|
|
585 child = tmp_list->data;
|
|
586 if (child->widget == widget)
|
|
587 break;
|
|
588 tmp_list = tmp_list->next;
|
|
589 }
|
|
590
|
|
591 if (tmp_list)
|
|
592 {
|
|
593 if (child->window)
|
|
594 {
|
|
595 gtk_signal_disconnect_by_func(GTK_OBJECT(child->widget),
|
|
596 GTK_SIGNAL_FUNC(>k_form_child_map), child);
|
|
597 gtk_signal_disconnect_by_func(GTK_OBJECT(child->widget),
|
|
598 GTK_SIGNAL_FUNC(>k_form_child_unmap), child);
|
|
599
|
|
600 /* FIXME: This will cause problems for reparenting NO_WINDOW
|
|
601 * widgets out of a GtkForm
|
|
602 */
|
|
603 gdk_window_set_user_data(child->window, NULL);
|
|
604 gdk_window_destroy(child->window);
|
|
605 }
|
|
606 gtk_widget_unparent(widget);
|
|
607
|
|
608 form->children = g_list_remove_link(form->children, tmp_list);
|
|
609 g_list_free_1(tmp_list);
|
|
610 g_free(child);
|
|
611 }
|
|
612 }
|
|
613
|
|
614 static void
|
|
615 gtk_form_forall(GtkContainer *container,
|
1884
|
616 gboolean include_internals UNUSED,
|
7
|
617 GtkCallback callback,
|
|
618 gpointer callback_data)
|
|
619 {
|
|
620 GtkForm *form;
|
|
621 GtkFormChild *child;
|
|
622 GList *tmp_list;
|
|
623
|
|
624 g_return_if_fail(GTK_IS_FORM(container));
|
|
625 g_return_if_fail(callback != NULL);
|
|
626
|
|
627 form = GTK_FORM(container);
|
|
628
|
|
629 tmp_list = form->children;
|
|
630 while (tmp_list)
|
|
631 {
|
|
632 child = tmp_list->data;
|
|
633 tmp_list = tmp_list->next;
|
|
634
|
|
635 (*callback) (child->widget, callback_data);
|
|
636 }
|
|
637 }
|
|
638
|
|
639 /* Operations on children
|
|
640 */
|
|
641
|
|
642 static void
|
|
643 gtk_form_attach_child_window(GtkForm *form, GtkFormChild *child)
|
|
644 {
|
|
645 if (child->window != NULL)
|
|
646 return; /* been there, done that */
|
|
647
|
|
648 if (GTK_WIDGET_NO_WINDOW(child->widget))
|
|
649 {
|
|
650 GtkWidget *widget;
|
|
651 GdkWindowAttr attributes;
|
|
652 gint attributes_mask;
|
|
653
|
|
654 widget = GTK_WIDGET(form);
|
|
655
|
|
656 attributes.window_type = GDK_WINDOW_CHILD;
|
|
657 attributes.x = child->x;
|
|
658 attributes.y = child->y;
|
|
659 attributes.width = child->widget->requisition.width;
|
|
660 attributes.height = child->widget->requisition.height;
|
|
661 attributes.wclass = GDK_INPUT_OUTPUT;
|
|
662 attributes.visual = gtk_widget_get_visual(widget);
|
|
663 attributes.colormap = gtk_widget_get_colormap(widget);
|
|
664 attributes.event_mask = GDK_EXPOSURE_MASK;
|
|
665
|
|
666 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
|
|
667 child->window = gdk_window_new(form->bin_window,
|
|
668 &attributes, attributes_mask);
|
|
669 gdk_window_set_user_data(child->window, widget);
|
|
670
|
|
671 gtk_style_set_background(widget->style,
|
|
672 child->window,
|
|
673 GTK_STATE_NORMAL);
|
|
674
|
|
675 gtk_widget_set_parent_window(child->widget, child->window);
|
|
676 gtk_form_set_static_gravity(child->window, TRUE);
|
|
677 /*
|
|
678 * Install signal handlers to map/unmap child->window
|
|
679 * alongside with the actual widget.
|
|
680 */
|
|
681 gtk_signal_connect(GTK_OBJECT(child->widget), "map",
|
|
682 GTK_SIGNAL_FUNC(>k_form_child_map), child);
|
|
683 gtk_signal_connect(GTK_OBJECT(child->widget), "unmap",
|
|
684 GTK_SIGNAL_FUNC(>k_form_child_unmap), child);
|
|
685 }
|
|
686 else if (!GTK_WIDGET_REALIZED(child->widget))
|
|
687 {
|
|
688 gtk_widget_set_parent_window(child->widget, form->bin_window);
|
|
689 }
|
|
690 }
|
|
691
|
|
692 static void
|
|
693 gtk_form_realize_child(GtkForm *form, GtkFormChild *child)
|
|
694 {
|
|
695 gtk_form_attach_child_window(form, child);
|
|
696 gtk_widget_realize(child->widget);
|
|
697
|
|
698 if (child->window == NULL) /* might be already set, see above */
|
|
699 gtk_form_set_static_gravity(child->widget->window, TRUE);
|
|
700 }
|
|
701
|
|
702 static void
|
|
703 gtk_form_position_child(GtkForm *form, GtkFormChild *child,
|
|
704 gboolean force_allocate)
|
|
705 {
|
|
706 gint x;
|
|
707 gint y;
|
|
708
|
|
709 x = child->x;
|
|
710 y = child->y;
|
|
711
|
|
712 if ((x >= G_MINSHORT) && (x <= G_MAXSHORT) &&
|
|
713 (y >= G_MINSHORT) && (y <= G_MAXSHORT))
|
|
714 {
|
|
715 if (!child->mapped)
|
|
716 {
|
|
717 if (GTK_WIDGET_MAPPED(form) && GTK_WIDGET_VISIBLE(child->widget))
|
|
718 {
|
|
719 if (!GTK_WIDGET_MAPPED(child->widget))
|
|
720 gtk_widget_map(child->widget);
|
|
721
|
|
722 child->mapped = TRUE;
|
|
723 force_allocate = TRUE;
|
|
724 }
|
|
725 }
|
|
726
|
|
727 if (force_allocate)
|
|
728 {
|
|
729 GtkAllocation allocation;
|
|
730
|
|
731 if (GTK_WIDGET_NO_WINDOW(child->widget))
|
|
732 {
|
|
733 if (child->window)
|
|
734 {
|
|
735 gdk_window_move_resize(child->window,
|
|
736 x, y,
|
|
737 child->widget->requisition.width,
|
|
738 child->widget->requisition.height);
|
|
739 }
|
|
740
|
|
741 allocation.x = 0;
|
|
742 allocation.y = 0;
|
|
743 }
|
|
744 else
|
|
745 {
|
|
746 allocation.x = x;
|
|
747 allocation.y = y;
|
|
748 }
|
|
749
|
|
750 allocation.width = child->widget->requisition.width;
|
|
751 allocation.height = child->widget->requisition.height;
|
|
752
|
|
753 gtk_widget_size_allocate(child->widget, &allocation);
|
|
754 }
|
|
755 }
|
|
756 else
|
|
757 {
|
|
758 if (child->mapped)
|
|
759 {
|
|
760 child->mapped = FALSE;
|
|
761
|
|
762 if (GTK_WIDGET_MAPPED(child->widget))
|
|
763 gtk_widget_unmap(child->widget);
|
|
764 }
|
|
765 }
|
|
766 }
|
|
767
|
|
768 static void
|
|
769 gtk_form_position_children(GtkForm *form)
|
|
770 {
|
|
771 GList *tmp_list;
|
|
772
|
|
773 for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next)
|
|
774 gtk_form_position_child(form, tmp_list->data, FALSE);
|
|
775 }
|
|
776
|
|
777 /* Callbacks */
|
|
778
|
|
779 /* The main event filter. Actually, we probably don't really need
|
|
780 * to install this as a filter at all, since we are calling it
|
|
781 * directly above in the expose-handling hack.
|
|
782 *
|
|
783 * This routine identifies expose events that are generated when
|
|
784 * we've temporarily moved the bin_window_origin, and translates
|
|
785 * them or discards them, depending on whether we are obscured
|
|
786 * or not.
|
|
787 */
|
|
788 static GdkFilterReturn
|
1884
|
789 gtk_form_filter(GdkXEvent *gdk_xevent, GdkEvent *event UNUSED, gpointer data)
|
7
|
790 {
|
|
791 XEvent *xevent;
|
|
792 GtkForm *form;
|
|
793
|
|
794 xevent = (XEvent *) gdk_xevent;
|
|
795 form = GTK_FORM(data);
|
|
796
|
|
797 switch (xevent->type)
|
|
798 {
|
|
799 case Expose:
|
|
800 if (xevent->xexpose.serial == form->configure_serial)
|
|
801 {
|
|
802 if (form->visibility == GDK_VISIBILITY_UNOBSCURED)
|
|
803 return GDK_FILTER_REMOVE;
|
|
804 else
|
|
805 break;
|
|
806 }
|
|
807 break;
|
|
808
|
|
809 case ConfigureNotify:
|
|
810 if ((xevent->xconfigure.x != 0) || (xevent->xconfigure.y != 0))
|
|
811 form->configure_serial = xevent->xconfigure.serial;
|
|
812 break;
|
|
813 }
|
|
814
|
|
815 return GDK_FILTER_CONTINUE;
|
|
816 }
|
|
817
|
|
818 /* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
|
|
819 * there is no corresponding event in GTK, so we have
|
|
820 * to get the events from a filter
|
|
821 */
|
|
822 static GdkFilterReturn
|
1884
|
823 gtk_form_main_filter(GdkXEvent *gdk_xevent,
|
|
824 GdkEvent *event UNUSED,
|
|
825 gpointer data)
|
7
|
826 {
|
|
827 XEvent *xevent;
|
|
828 GtkForm *form;
|
|
829
|
|
830 xevent = (XEvent *) gdk_xevent;
|
|
831 form = GTK_FORM(data);
|
|
832
|
|
833 if (xevent->type == VisibilityNotify)
|
|
834 {
|
|
835 switch (xevent->xvisibility.state)
|
|
836 {
|
|
837 case VisibilityFullyObscured:
|
|
838 form->visibility = GDK_VISIBILITY_FULLY_OBSCURED;
|
|
839 break;
|
|
840
|
|
841 case VisibilityPartiallyObscured:
|
|
842 form->visibility = GDK_VISIBILITY_PARTIAL;
|
|
843 break;
|
|
844
|
|
845 case VisibilityUnobscured:
|
|
846 form->visibility = GDK_VISIBILITY_UNOBSCURED;
|
|
847 break;
|
|
848 }
|
|
849
|
|
850 return GDK_FILTER_REMOVE;
|
|
851 }
|
|
852 return GDK_FILTER_CONTINUE;
|
|
853 }
|
|
854
|
|
855 /* Routines to set the window gravity, and check whether it is
|
|
856 * functional. Extra capabilities need to be added to GDK, so
|
|
857 * we don't have to use Xlib here.
|
|
858 */
|
|
859 static void
|
|
860 gtk_form_set_static_gravity(GdkWindow *window, gboolean use_static)
|
|
861 {
|
|
862 #ifdef HAVE_GTK2
|
1960
|
863 /* We don't check if static gravity is actually supported, because it
|
|
864 * results in an annoying assertion error message. */
|
|
865 gdk_window_set_static_gravities(window, use_static);
|
7
|
866 #else
|
|
867 XSetWindowAttributes xattributes;
|
|
868
|
|
869 xattributes.win_gravity = (use_static) ? StaticGravity : NorthWestGravity;
|
|
870 xattributes.bit_gravity = (use_static) ? StaticGravity : NorthWestGravity;
|
|
871
|
|
872 XChangeWindowAttributes(GDK_WINDOW_XDISPLAY(window),
|
|
873 GDK_WINDOW_XWINDOW(window),
|
|
874 CWBitGravity | CWWinGravity,
|
|
875 &xattributes);
|
|
876 #endif
|
|
877 }
|
|
878
|
|
879 void
|
|
880 gtk_form_move_resize(GtkForm *form, GtkWidget *widget,
|
|
881 gint x, gint y, gint w, gint h)
|
|
882 {
|
|
883 widget->requisition.width = w;
|
|
884 widget->requisition.height = h;
|
|
885
|
|
886 gtk_form_move(form, widget, x, y);
|
|
887 }
|
|
888
|
|
889 static void
|
|
890 gtk_form_send_configure(GtkForm *form)
|
|
891 {
|
|
892 GtkWidget *widget;
|
|
893 GdkEventConfigure event;
|
|
894
|
|
895 widget = GTK_WIDGET(form);
|
|
896
|
|
897 event.type = GDK_CONFIGURE;
|
|
898 event.window = widget->window;
|
|
899 event.x = widget->allocation.x;
|
|
900 event.y = widget->allocation.y;
|
|
901 event.width = widget->allocation.width;
|
|
902 event.height = widget->allocation.height;
|
|
903
|
|
904 #ifdef HAVE_GTK2
|
|
905 gtk_main_do_event((GdkEvent*)&event);
|
|
906 #else
|
|
907 gtk_widget_event(widget, (GdkEvent*)&event);
|
|
908 #endif
|
|
909 }
|
|
910
|
|
911 static void
|
1884
|
912 gtk_form_child_map(GtkWidget *widget UNUSED, gpointer user_data)
|
7
|
913 {
|
|
914 GtkFormChild *child;
|
|
915
|
|
916 child = (GtkFormChild *)user_data;
|
|
917
|
|
918 child->mapped = TRUE;
|
|
919 gdk_window_show(child->window);
|
|
920 }
|
|
921
|
|
922 static void
|
1884
|
923 gtk_form_child_unmap(GtkWidget *widget UNUSED, gpointer user_data)
|
7
|
924 {
|
|
925 GtkFormChild *child;
|
|
926
|
|
927 child = (GtkFormChild *)user_data;
|
|
928
|
|
929 child->mapped = FALSE;
|
|
930 gdk_window_hide(child->window);
|
|
931 }
|
|
932
|