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 *
|
|
18 * This is a special purspose container widget, which manages arbitrary childs
|
|
19 * at arbitrary positions width arbitrary sizes. This finally puts an end on
|
|
20 * our resizement problems with which we where struggling for such a long time.
|
|
21 */
|
|
22
|
|
23 #include "vim.h"
|
|
24 #include <gtk/gtk.h> /* without this it compiles, but gives errors at
|
|
25 runtime! */
|
|
26 #include "gui_gtk_f.h"
|
|
27 #include <gtk/gtksignal.h>
|
|
28 #ifdef WIN3264
|
|
29 # include <gdk/gdkwin32.h>
|
|
30 #else
|
|
31 # include <gdk/gdkx.h>
|
|
32 #endif
|
|
33
|
|
34 typedef struct _GtkFormChild GtkFormChild;
|
|
35
|
|
36 struct _GtkFormChild
|
|
37 {
|
|
38 GtkWidget *widget;
|
|
39 GdkWindow *window;
|
|
40 gint x; /* relative subwidget x position */
|
|
41 gint y; /* relative subwidget y position */
|
|
42 gint mapped;
|
|
43 };
|
|
44
|
|
45
|
|
46 static void gtk_form_class_init(GtkFormClass *klass);
|
|
47 static void gtk_form_init(GtkForm *form);
|
|
48
|
|
49 static void gtk_form_realize(GtkWidget *widget);
|
|
50 static void gtk_form_unrealize(GtkWidget *widget);
|
|
51 static void gtk_form_map(GtkWidget *widget);
|
|
52 static void gtk_form_size_request(GtkWidget *widget,
|
|
53 GtkRequisition *requisition);
|
|
54 static void gtk_form_size_allocate(GtkWidget *widget,
|
|
55 GtkAllocation *allocation);
|
|
56 #ifndef HAVE_GTK2 /* this isn't needed in gtk2 */
|
|
57 static void gtk_form_draw(GtkWidget *widget,
|
|
58 GdkRectangle *area);
|
|
59 #endif
|
|
60 static gint gtk_form_expose(GtkWidget *widget,
|
|
61 GdkEventExpose *event);
|
|
62
|
|
63 static void gtk_form_remove(GtkContainer *container,
|
|
64 GtkWidget *widget);
|
|
65 static void gtk_form_forall(GtkContainer *container,
|
|
66 gboolean include_internals,
|
|
67 GtkCallback callback,
|
|
68 gpointer callback_data);
|
|
69
|
|
70 static void gtk_form_attach_child_window(GtkForm *form,
|
|
71 GtkFormChild *child);
|
|
72 static void gtk_form_realize_child(GtkForm *form,
|
|
73 GtkFormChild *child);
|
|
74 static void gtk_form_position_child(GtkForm *form,
|
|
75 GtkFormChild *child,
|
|
76 gboolean force_allocate);
|
|
77 static void gtk_form_position_children(GtkForm *form);
|
|
78
|
|
79 static GdkFilterReturn gtk_form_filter(GdkXEvent *gdk_xevent,
|
|
80 GdkEvent *event,
|
|
81 gpointer data);
|
|
82 static GdkFilterReturn gtk_form_main_filter(GdkXEvent *gdk_xevent,
|
|
83 GdkEvent *event,
|
|
84 gpointer data);
|
|
85
|
|
86 static void gtk_form_set_static_gravity(GdkWindow *window,
|
|
87 gboolean use_static);
|
|
88
|
|
89 static void gtk_form_send_configure(GtkForm *form);
|
|
90
|
|
91 static void gtk_form_child_map(GtkWidget *widget, gpointer user_data);
|
|
92 static void gtk_form_child_unmap(GtkWidget *widget, gpointer user_data);
|
|
93
|
|
94 static GtkWidgetClass *parent_class = NULL;
|
|
95
|
|
96 /* Public interface
|
|
97 */
|
|
98
|
|
99 GtkWidget *
|
|
100 gtk_form_new(void)
|
|
101 {
|
|
102 GtkForm *form;
|
|
103
|
|
104 form = gtk_type_new(gtk_form_get_type());
|
|
105
|
|
106 return GTK_WIDGET(form);
|
|
107 }
|
|
108
|
|
109 void
|
|
110 gtk_form_put(GtkForm *form,
|
|
111 GtkWidget *child_widget,
|
|
112 gint x,
|
|
113 gint y)
|
|
114 {
|
|
115 GtkFormChild *child;
|
|
116
|
|
117 g_return_if_fail(GTK_IS_FORM(form));
|
|
118
|
129
|
119 /* LINTED: avoid warning: conversion to 'unsigned long' */
|
7
|
120 child = g_new(GtkFormChild, 1);
|
|
121
|
|
122 child->widget = child_widget;
|
|
123 child->window = NULL;
|
|
124 child->x = x;
|
|
125 child->y = y;
|
|
126 child->widget->requisition.width = 0;
|
|
127 child->widget->requisition.height = 0;
|
|
128 child->mapped = FALSE;
|
|
129
|
|
130 form->children = g_list_append(form->children, child);
|
|
131
|
|
132 /* child->window must be created and attached to the widget _before_
|
|
133 * it has been realized, or else things will break with GTK2. Note
|
|
134 * that gtk_widget_set_parent() realizes the widget if it's visible
|
|
135 * and its parent is mapped.
|
|
136 */
|
|
137 if (GTK_WIDGET_REALIZED(form))
|
|
138 gtk_form_attach_child_window(form, child);
|
|
139
|
|
140 gtk_widget_set_parent(child_widget, GTK_WIDGET(form));
|
|
141 gtk_widget_size_request(child->widget, NULL);
|
|
142
|
|
143 if (GTK_WIDGET_REALIZED(form) && !GTK_WIDGET_REALIZED(child_widget))
|
|
144 gtk_form_realize_child(form, child);
|
|
145
|
|
146 gtk_form_position_child(form, child, TRUE);
|
|
147 }
|
|
148
|
|
149 void
|
|
150 gtk_form_move(GtkForm *form,
|
|
151 GtkWidget *child_widget,
|
|
152 gint x,
|
|
153 gint y)
|
|
154 {
|
|
155 GList *tmp_list;
|
|
156 GtkFormChild *child;
|
|
157
|
|
158 g_return_if_fail(GTK_IS_FORM(form));
|
|
159
|
|
160 for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next)
|
|
161 {
|
|
162 child = tmp_list->data;
|
|
163 if (child->widget == child_widget)
|
|
164 {
|
|
165 child->x = x;
|
|
166 child->y = y;
|
|
167
|
|
168 gtk_form_position_child(form, child, TRUE);
|
|
169 return;
|
|
170 }
|
|
171 }
|
|
172 }
|
|
173
|
|
174 void
|
|
175 gtk_form_set_size(GtkForm *form, guint width, guint height)
|
|
176 {
|
|
177 g_return_if_fail(GTK_IS_FORM(form));
|
|
178
|
|
179 /* prevent unneccessary calls */
|
|
180 if (form->width == width && form->height == height)
|
|
181 return;
|
|
182 form->width = width;
|
|
183 form->height = height;
|
|
184
|
|
185 /* signal the change */
|
|
186 #ifdef HAVE_GTK2
|
|
187 gtk_widget_queue_resize(gtk_widget_get_parent(GTK_WIDGET(form)));
|
|
188 #else
|
|
189 gtk_container_queue_resize(GTK_CONTAINER(GTK_WIDGET(form)->parent));
|
|
190 #endif
|
|
191 }
|
|
192
|
|
193 void
|
|
194 gtk_form_freeze(GtkForm *form)
|
|
195 {
|
|
196 g_return_if_fail(GTK_IS_FORM(form));
|
|
197
|
|
198 ++form->freeze_count;
|
|
199 }
|
|
200
|
|
201 void
|
|
202 gtk_form_thaw(GtkForm *form)
|
|
203 {
|
|
204 g_return_if_fail(GTK_IS_FORM(form));
|
|
205
|
|
206 if (form->freeze_count)
|
|
207 {
|
|
208 if (!(--form->freeze_count))
|
|
209 {
|
|
210 gtk_form_position_children(form);
|
|
211 #ifdef HAVE_GTK2
|
|
212 gtk_widget_queue_draw(GTK_WIDGET(form));
|
|
213 #else
|
|
214 gtk_widget_draw(GTK_WIDGET(form), NULL);
|
|
215 #endif
|
|
216 }
|
|
217 }
|
|
218 }
|
|
219
|
|
220 /* Basic Object handling procedures
|
|
221 */
|
|
222 GtkType
|
|
223 gtk_form_get_type(void)
|
|
224 {
|
|
225 static GtkType form_type = 0;
|
|
226
|
|
227 if (!form_type)
|
|
228 {
|
|
229 GtkTypeInfo form_info =
|
|
230 {
|
|
231 "GtkForm",
|
|
232 sizeof(GtkForm),
|
|
233 sizeof(GtkFormClass),
|
|
234 (GtkClassInitFunc) gtk_form_class_init,
|
|
235 (GtkObjectInitFunc) gtk_form_init
|
|
236 };
|
|
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 /*ARGSUSED1*/
|
|
614 static void
|
|
615 gtk_form_forall(GtkContainer *container,
|
|
616 gboolean include_internals,
|
|
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 /*ARGSUSED1*/
|
|
789 static GdkFilterReturn
|
|
790 gtk_form_filter(GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
|
|
791 {
|
|
792 XEvent *xevent;
|
|
793 GtkForm *form;
|
|
794
|
|
795 xevent = (XEvent *) gdk_xevent;
|
|
796 form = GTK_FORM(data);
|
|
797
|
|
798 switch (xevent->type)
|
|
799 {
|
|
800 case Expose:
|
|
801 if (xevent->xexpose.serial == form->configure_serial)
|
|
802 {
|
|
803 if (form->visibility == GDK_VISIBILITY_UNOBSCURED)
|
|
804 return GDK_FILTER_REMOVE;
|
|
805 else
|
|
806 break;
|
|
807 }
|
|
808 break;
|
|
809
|
|
810 case ConfigureNotify:
|
|
811 if ((xevent->xconfigure.x != 0) || (xevent->xconfigure.y != 0))
|
|
812 form->configure_serial = xevent->xconfigure.serial;
|
|
813 break;
|
|
814 }
|
|
815
|
|
816 return GDK_FILTER_CONTINUE;
|
|
817 }
|
|
818
|
|
819 /* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
|
|
820 * there is no corresponding event in GTK, so we have
|
|
821 * to get the events from a filter
|
|
822 */
|
|
823 /*ARGSUSED1*/
|
|
824 static GdkFilterReturn
|
|
825 gtk_form_main_filter(GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
|
|
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
|
|
863 gboolean static_gravity_supported;
|
|
864
|
|
865 static_gravity_supported = gdk_window_set_static_gravities(window,
|
|
866 use_static);
|
|
867 g_return_if_fail(static_gravity_supported);
|
|
868 #else
|
|
869 XSetWindowAttributes xattributes;
|
|
870
|
|
871 xattributes.win_gravity = (use_static) ? StaticGravity : NorthWestGravity;
|
|
872 xattributes.bit_gravity = (use_static) ? StaticGravity : NorthWestGravity;
|
|
873
|
|
874 XChangeWindowAttributes(GDK_WINDOW_XDISPLAY(window),
|
|
875 GDK_WINDOW_XWINDOW(window),
|
|
876 CWBitGravity | CWWinGravity,
|
|
877 &xattributes);
|
|
878 #endif
|
|
879 }
|
|
880
|
|
881 void
|
|
882 gtk_form_move_resize(GtkForm *form, GtkWidget *widget,
|
|
883 gint x, gint y, gint w, gint h)
|
|
884 {
|
|
885 widget->requisition.width = w;
|
|
886 widget->requisition.height = h;
|
|
887
|
|
888 gtk_form_move(form, widget, x, y);
|
|
889 }
|
|
890
|
|
891 static void
|
|
892 gtk_form_send_configure(GtkForm *form)
|
|
893 {
|
|
894 GtkWidget *widget;
|
|
895 GdkEventConfigure event;
|
|
896
|
|
897 widget = GTK_WIDGET(form);
|
|
898
|
|
899 event.type = GDK_CONFIGURE;
|
|
900 event.window = widget->window;
|
|
901 event.x = widget->allocation.x;
|
|
902 event.y = widget->allocation.y;
|
|
903 event.width = widget->allocation.width;
|
|
904 event.height = widget->allocation.height;
|
|
905
|
|
906 #ifdef HAVE_GTK2
|
|
907 gtk_main_do_event((GdkEvent*)&event);
|
|
908 #else
|
|
909 gtk_widget_event(widget, (GdkEvent*)&event);
|
|
910 #endif
|
|
911 }
|
|
912
|
|
913 /*ARGSUSED0*/
|
|
914 static void
|
|
915 gtk_form_child_map(GtkWidget *widget, gpointer user_data)
|
|
916 {
|
|
917 GtkFormChild *child;
|
|
918
|
|
919 child = (GtkFormChild *)user_data;
|
|
920
|
|
921 child->mapped = TRUE;
|
|
922 gdk_window_show(child->window);
|
|
923 }
|
|
924
|
|
925 /*ARGSUSED0*/
|
|
926 static void
|
|
927 gtk_form_child_unmap(GtkWidget *widget, gpointer user_data)
|
|
928 {
|
|
929 GtkFormChild *child;
|
|
930
|
|
931 child = (GtkFormChild *)user_data;
|
|
932
|
|
933 child->mapped = FALSE;
|
|
934 gdk_window_hide(child->window);
|
|
935 }
|
|
936
|