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
|
|
119 child = g_new(GtkFormChild, 1);
|
|
120
|
|
121 child->widget = child_widget;
|
|
122 child->window = NULL;
|
|
123 child->x = x;
|
|
124 child->y = y;
|
|
125 child->widget->requisition.width = 0;
|
|
126 child->widget->requisition.height = 0;
|
|
127 child->mapped = FALSE;
|
|
128
|
|
129 form->children = g_list_append(form->children, child);
|
|
130
|
|
131 /* child->window must be created and attached to the widget _before_
|
|
132 * it has been realized, or else things will break with GTK2. Note
|
|
133 * that gtk_widget_set_parent() realizes the widget if it's visible
|
|
134 * and its parent is mapped.
|
|
135 */
|
|
136 if (GTK_WIDGET_REALIZED(form))
|
|
137 gtk_form_attach_child_window(form, child);
|
|
138
|
|
139 gtk_widget_set_parent(child_widget, GTK_WIDGET(form));
|
|
140 gtk_widget_size_request(child->widget, NULL);
|
|
141
|
|
142 if (GTK_WIDGET_REALIZED(form) && !GTK_WIDGET_REALIZED(child_widget))
|
|
143 gtk_form_realize_child(form, child);
|
|
144
|
|
145 gtk_form_position_child(form, child, TRUE);
|
|
146 }
|
|
147
|
|
148 void
|
|
149 gtk_form_move(GtkForm *form,
|
|
150 GtkWidget *child_widget,
|
|
151 gint x,
|
|
152 gint y)
|
|
153 {
|
|
154 GList *tmp_list;
|
|
155 GtkFormChild *child;
|
|
156
|
|
157 g_return_if_fail(GTK_IS_FORM(form));
|
|
158
|
|
159 for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next)
|
|
160 {
|
|
161 child = tmp_list->data;
|
|
162 if (child->widget == child_widget)
|
|
163 {
|
|
164 child->x = x;
|
|
165 child->y = y;
|
|
166
|
|
167 gtk_form_position_child(form, child, TRUE);
|
|
168 return;
|
|
169 }
|
|
170 }
|
|
171 }
|
|
172
|
|
173 void
|
|
174 gtk_form_set_size(GtkForm *form, guint width, guint height)
|
|
175 {
|
|
176 g_return_if_fail(GTK_IS_FORM(form));
|
|
177
|
|
178 /* prevent unneccessary calls */
|
|
179 if (form->width == width && form->height == height)
|
|
180 return;
|
|
181 form->width = width;
|
|
182 form->height = height;
|
|
183
|
|
184 /* signal the change */
|
|
185 #ifdef HAVE_GTK2
|
|
186 gtk_widget_queue_resize(gtk_widget_get_parent(GTK_WIDGET(form)));
|
|
187 #else
|
|
188 gtk_container_queue_resize(GTK_CONTAINER(GTK_WIDGET(form)->parent));
|
|
189 #endif
|
|
190 }
|
|
191
|
|
192 void
|
|
193 gtk_form_freeze(GtkForm *form)
|
|
194 {
|
|
195 g_return_if_fail(GTK_IS_FORM(form));
|
|
196
|
|
197 ++form->freeze_count;
|
|
198 }
|
|
199
|
|
200 void
|
|
201 gtk_form_thaw(GtkForm *form)
|
|
202 {
|
|
203 g_return_if_fail(GTK_IS_FORM(form));
|
|
204
|
|
205 if (form->freeze_count)
|
|
206 {
|
|
207 if (!(--form->freeze_count))
|
|
208 {
|
|
209 gtk_form_position_children(form);
|
|
210 #ifdef HAVE_GTK2
|
|
211 gtk_widget_queue_draw(GTK_WIDGET(form));
|
|
212 #else
|
|
213 gtk_widget_draw(GTK_WIDGET(form), NULL);
|
|
214 #endif
|
|
215 }
|
|
216 }
|
|
217 }
|
|
218
|
|
219 /* Basic Object handling procedures
|
|
220 */
|
|
221 GtkType
|
|
222 gtk_form_get_type(void)
|
|
223 {
|
|
224 static GtkType form_type = 0;
|
|
225
|
|
226 if (!form_type)
|
|
227 {
|
|
228 GtkTypeInfo form_info =
|
|
229 {
|
|
230 "GtkForm",
|
|
231 sizeof(GtkForm),
|
|
232 sizeof(GtkFormClass),
|
|
233 (GtkClassInitFunc) gtk_form_class_init,
|
|
234 (GtkObjectInitFunc) gtk_form_init
|
|
235 };
|
|
236
|
|
237 form_type = gtk_type_unique(GTK_TYPE_CONTAINER, &form_info);
|
|
238 }
|
|
239 return form_type;
|
|
240 }
|
|
241
|
|
242 static void
|
|
243 gtk_form_class_init(GtkFormClass *klass)
|
|
244 {
|
|
245 GtkWidgetClass *widget_class;
|
|
246 GtkContainerClass *container_class;
|
|
247
|
|
248 widget_class = (GtkWidgetClass *) klass;
|
|
249 container_class = (GtkContainerClass *) klass;
|
|
250
|
|
251 parent_class = gtk_type_class(gtk_container_get_type());
|
|
252
|
|
253 widget_class->realize = gtk_form_realize;
|
|
254 widget_class->unrealize = gtk_form_unrealize;
|
|
255 widget_class->map = gtk_form_map;
|
|
256 widget_class->size_request = gtk_form_size_request;
|
|
257 widget_class->size_allocate = gtk_form_size_allocate;
|
|
258 #ifndef HAVE_GTK2 /* not needed for GTK2 */
|
|
259 widget_class->draw = gtk_form_draw;
|
|
260 #endif
|
|
261 widget_class->expose_event = gtk_form_expose;
|
|
262
|
|
263 container_class->remove = gtk_form_remove;
|
|
264 container_class->forall = gtk_form_forall;
|
|
265 }
|
|
266
|
|
267 static void
|
|
268 gtk_form_init(GtkForm *form)
|
|
269 {
|
|
270 form->children = NULL;
|
|
271
|
|
272 form->width = 1;
|
|
273 form->height = 1;
|
|
274
|
|
275 form->bin_window = NULL;
|
|
276
|
|
277 form->configure_serial = 0;
|
|
278 form->visibility = GDK_VISIBILITY_PARTIAL;
|
|
279
|
|
280 form->freeze_count = 0;
|
|
281 }
|
|
282
|
|
283 /*
|
|
284 * Widget methods
|
|
285 */
|
|
286
|
|
287 static void
|
|
288 gtk_form_realize(GtkWidget *widget)
|
|
289 {
|
|
290 GList *tmp_list;
|
|
291 GtkForm *form;
|
|
292 GdkWindowAttr attributes;
|
|
293 gint attributes_mask;
|
|
294
|
|
295 g_return_if_fail(GTK_IS_FORM(widget));
|
|
296
|
|
297 form = GTK_FORM(widget);
|
|
298 GTK_WIDGET_SET_FLAGS(form, GTK_REALIZED);
|
|
299
|
|
300 attributes.window_type = GDK_WINDOW_CHILD;
|
|
301 attributes.x = widget->allocation.x;
|
|
302 attributes.y = widget->allocation.y;
|
|
303 attributes.width = widget->allocation.width;
|
|
304 attributes.height = widget->allocation.height;
|
|
305 attributes.wclass = GDK_INPUT_OUTPUT;
|
|
306 attributes.visual = gtk_widget_get_visual(widget);
|
|
307 attributes.colormap = gtk_widget_get_colormap(widget);
|
|
308 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
|
|
309
|
|
310 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
|
|
311
|
|
312 widget->window = gdk_window_new(gtk_widget_get_parent_window(widget),
|
|
313 &attributes, attributes_mask);
|
|
314 gdk_window_set_user_data(widget->window, widget);
|
|
315
|
|
316 attributes.x = 0;
|
|
317 attributes.y = 0;
|
|
318 attributes.event_mask = gtk_widget_get_events(widget);
|
|
319
|
|
320 form->bin_window = gdk_window_new(widget->window,
|
|
321 &attributes, attributes_mask);
|
|
322 gdk_window_set_user_data(form->bin_window, widget);
|
|
323
|
|
324 gtk_form_set_static_gravity(form->bin_window, TRUE);
|
|
325
|
|
326 widget->style = gtk_style_attach(widget->style, widget->window);
|
|
327 gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL);
|
|
328 gtk_style_set_background(widget->style, form->bin_window, GTK_STATE_NORMAL);
|
|
329
|
|
330 gdk_window_add_filter(widget->window, gtk_form_main_filter, form);
|
|
331 gdk_window_add_filter(form->bin_window, gtk_form_filter, form);
|
|
332
|
|
333 for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next)
|
|
334 {
|
|
335 GtkFormChild *child = tmp_list->data;
|
|
336
|
|
337 gtk_form_attach_child_window(form, child);
|
|
338
|
|
339 if (GTK_WIDGET_VISIBLE(child->widget))
|
|
340 gtk_form_realize_child(form, child);
|
|
341 }
|
|
342 }
|
|
343
|
|
344
|
|
345 /* After reading the documentation at
|
|
346 * http://developer.gnome.org/doc/API/2.0/gtk/gtk-changes-2-0.html
|
|
347 * I think it should be possible to remove this function when compiling
|
|
348 * against gtk-2.0. It doesn't seem to cause problems, though.
|
|
349 *
|
|
350 * Well, I reckon at least the gdk_window_show(form->bin_window)
|
|
351 * is necessary. GtkForm is anything but a usual container widget.
|
|
352 */
|
|
353 static void
|
|
354 gtk_form_map(GtkWidget *widget)
|
|
355 {
|
|
356 GList *tmp_list;
|
|
357 GtkForm *form;
|
|
358
|
|
359 g_return_if_fail(GTK_IS_FORM(widget));
|
|
360
|
|
361 form = GTK_FORM(widget);
|
|
362
|
|
363 GTK_WIDGET_SET_FLAGS(widget, GTK_MAPPED);
|
|
364
|
|
365 gdk_window_show(widget->window);
|
|
366 gdk_window_show(form->bin_window);
|
|
367
|
|
368 for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next)
|
|
369 {
|
|
370 GtkFormChild *child = tmp_list->data;
|
|
371
|
|
372 if (GTK_WIDGET_VISIBLE(child->widget)
|
|
373 && !GTK_WIDGET_MAPPED(child->widget))
|
|
374 gtk_widget_map(child->widget);
|
|
375 }
|
|
376 }
|
|
377
|
|
378 static void
|
|
379 gtk_form_unrealize(GtkWidget *widget)
|
|
380 {
|
|
381 GList *tmp_list;
|
|
382 GtkForm *form;
|
|
383
|
|
384 g_return_if_fail(GTK_IS_FORM(widget));
|
|
385
|
|
386 form = GTK_FORM(widget);
|
|
387
|
|
388 tmp_list = form->children;
|
|
389
|
|
390 gdk_window_set_user_data(form->bin_window, NULL);
|
|
391 gdk_window_destroy(form->bin_window);
|
|
392 form->bin_window = NULL;
|
|
393
|
|
394 while (tmp_list)
|
|
395 {
|
|
396 GtkFormChild *child = tmp_list->data;
|
|
397
|
|
398 if (child->window != NULL)
|
|
399 {
|
|
400 gtk_signal_disconnect_by_func(GTK_OBJECT(child->widget),
|
|
401 GTK_SIGNAL_FUNC(gtk_form_child_map),
|
|
402 child);
|
|
403 gtk_signal_disconnect_by_func(GTK_OBJECT(child->widget),
|
|
404 GTK_SIGNAL_FUNC(gtk_form_child_unmap),
|
|
405 child);
|
|
406
|
|
407 gdk_window_set_user_data(child->window, NULL);
|
|
408 gdk_window_destroy(child->window);
|
|
409
|
|
410 child->window = NULL;
|
|
411 }
|
|
412
|
|
413 tmp_list = tmp_list->next;
|
|
414 }
|
|
415
|
|
416 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
|
|
417 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
|
|
418 }
|
|
419
|
|
420 #ifndef HAVE_GTK2
|
|
421 static void
|
|
422 gtk_form_draw(GtkWidget *widget, GdkRectangle *area)
|
|
423 {
|
|
424 GtkForm *form;
|
|
425 GList *children;
|
|
426 GtkFormChild *child;
|
|
427 GdkRectangle child_area;
|
|
428
|
|
429 g_return_if_fail(GTK_IS_FORM(widget));
|
|
430
|
|
431 if (GTK_WIDGET_DRAWABLE(widget))
|
|
432 {
|
|
433 form = GTK_FORM(widget);
|
|
434
|
|
435 children = form->children;
|
|
436
|
|
437 while (children)
|
|
438 {
|
|
439 child = children->data;
|
|
440
|
|
441 if (GTK_WIDGET_DRAWABLE(child->widget)
|
|
442 && gtk_widget_intersect(child->widget, area, &child_area))
|
|
443 gtk_widget_draw(child->widget, &child_area);
|
|
444
|
|
445 children = children->next;
|
|
446 }
|
|
447 }
|
|
448 }
|
|
449 #endif /* !HAVE_GTK2 */
|
|
450
|
|
451 static void
|
|
452 gtk_form_size_request(GtkWidget *widget, GtkRequisition *requisition)
|
|
453 {
|
|
454 GList *tmp_list;
|
|
455 GtkForm *form;
|
|
456
|
|
457 g_return_if_fail(GTK_IS_FORM(widget));
|
|
458
|
|
459 form = GTK_FORM(widget);
|
|
460
|
|
461 requisition->width = form->width;
|
|
462 requisition->height = form->height;
|
|
463
|
|
464 tmp_list = form->children;
|
|
465
|
|
466 while (tmp_list)
|
|
467 {
|
|
468 GtkFormChild *child = tmp_list->data;
|
|
469 gtk_widget_size_request(child->widget, NULL);
|
|
470 tmp_list = tmp_list->next;
|
|
471 }
|
|
472 }
|
|
473
|
|
474 static void
|
|
475 gtk_form_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
|
|
476 {
|
|
477 GList *tmp_list;
|
|
478 GtkForm *form;
|
|
479 gboolean need_reposition;
|
|
480
|
|
481 g_return_if_fail(GTK_IS_FORM(widget));
|
|
482
|
|
483 if (widget->allocation.x == allocation->x
|
|
484 && widget->allocation.y == allocation->y
|
|
485 && widget->allocation.width == allocation->width
|
|
486 && widget->allocation.height == allocation->height)
|
|
487 return;
|
|
488
|
|
489 need_reposition = widget->allocation.width != allocation->width
|
|
490 || widget->allocation.height != allocation->height;
|
|
491 form = GTK_FORM(widget);
|
|
492
|
|
493 if (need_reposition)
|
|
494 {
|
|
495 tmp_list = form->children;
|
|
496
|
|
497 while (tmp_list)
|
|
498 {
|
|
499 GtkFormChild *child = tmp_list->data;
|
|
500 gtk_form_position_child(form, child, TRUE);
|
|
501
|
|
502 tmp_list = tmp_list->next;
|
|
503 }
|
|
504 }
|
|
505
|
|
506 if (GTK_WIDGET_REALIZED(widget))
|
|
507 {
|
|
508 gdk_window_move_resize(widget->window,
|
|
509 allocation->x, allocation->y,
|
|
510 allocation->width, allocation->height);
|
|
511 gdk_window_move_resize(GTK_FORM(widget)->bin_window,
|
|
512 0, 0,
|
|
513 allocation->width, allocation->height);
|
|
514 }
|
|
515 widget->allocation = *allocation;
|
|
516 if (need_reposition)
|
|
517 gtk_form_send_configure(form);
|
|
518 }
|
|
519
|
|
520 static gint
|
|
521 gtk_form_expose(GtkWidget *widget, GdkEventExpose *event)
|
|
522 {
|
|
523 GList *tmp_list;
|
|
524 GtkForm *form;
|
|
525
|
|
526 g_return_val_if_fail(GTK_IS_FORM(widget), FALSE);
|
|
527
|
|
528 form = GTK_FORM(widget);
|
|
529
|
|
530 if (event->window == form->bin_window)
|
|
531 return FALSE;
|
|
532
|
|
533 for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next)
|
|
534 {
|
|
535 #ifdef HAVE_GTK2
|
|
536 GtkFormChild *formchild = tmp_list->data;
|
|
537 GtkWidget *child = formchild->widget;
|
|
538 /*
|
|
539 * The following chunk of code is taken from gtkcontainer.c. The
|
|
540 * gtk1.x code synthesized expose events directly on the child widgets,
|
|
541 * which can't be done in gtk2
|
|
542 */
|
|
543 if (GTK_WIDGET_DRAWABLE(child) && GTK_WIDGET_NO_WINDOW(child)
|
|
544 && child->window == event->window)
|
|
545 {
|
|
546 GdkEventExpose child_event;
|
|
547 child_event = *event;
|
|
548
|
|
549 child_event.region = gtk_widget_region_intersect(child, event->region);
|
|
550 if (!gdk_region_empty(child_event.region))
|
|
551 {
|
|
552 gdk_region_get_clipbox(child_event.region, &child_event.area);
|
|
553 gtk_widget_send_expose(child, (GdkEvent *)&child_event);
|
|
554 }
|
|
555 }
|
|
556 #else /* !HAVE_GTK2 */
|
|
557 GtkFormChild *child = tmp_list->data;
|
|
558
|
|
559 if (event->window == child->window)
|
|
560 return gtk_widget_event(child->widget, (GdkEvent *) event);
|
|
561 #endif /* !HAVE_GTK2 */
|
|
562 }
|
|
563
|
|
564 return FALSE;
|
|
565 }
|
|
566
|
|
567 /* Container method
|
|
568 */
|
|
569 static void
|
|
570 gtk_form_remove(GtkContainer *container, GtkWidget *widget)
|
|
571 {
|
|
572 GList *tmp_list;
|
|
573 GtkForm *form;
|
|
574 GtkFormChild *child = NULL; /* init for gcc */
|
|
575
|
|
576 g_return_if_fail(GTK_IS_FORM(container));
|
|
577
|
|
578 form = GTK_FORM(container);
|
|
579
|
|
580 tmp_list = form->children;
|
|
581 while (tmp_list)
|
|
582 {
|
|
583 child = tmp_list->data;
|
|
584 if (child->widget == widget)
|
|
585 break;
|
|
586 tmp_list = tmp_list->next;
|
|
587 }
|
|
588
|
|
589 if (tmp_list)
|
|
590 {
|
|
591 if (child->window)
|
|
592 {
|
|
593 gtk_signal_disconnect_by_func(GTK_OBJECT(child->widget),
|
|
594 GTK_SIGNAL_FUNC(>k_form_child_map), child);
|
|
595 gtk_signal_disconnect_by_func(GTK_OBJECT(child->widget),
|
|
596 GTK_SIGNAL_FUNC(>k_form_child_unmap), child);
|
|
597
|
|
598 /* FIXME: This will cause problems for reparenting NO_WINDOW
|
|
599 * widgets out of a GtkForm
|
|
600 */
|
|
601 gdk_window_set_user_data(child->window, NULL);
|
|
602 gdk_window_destroy(child->window);
|
|
603 }
|
|
604 gtk_widget_unparent(widget);
|
|
605
|
|
606 form->children = g_list_remove_link(form->children, tmp_list);
|
|
607 g_list_free_1(tmp_list);
|
|
608 g_free(child);
|
|
609 }
|
|
610 }
|
|
611
|
|
612 /*ARGSUSED1*/
|
|
613 static void
|
|
614 gtk_form_forall(GtkContainer *container,
|
|
615 gboolean include_internals,
|
|
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 /*ARGSUSED1*/
|
|
788 static GdkFilterReturn
|
|
789 gtk_form_filter(GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
|
|
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 /*ARGSUSED1*/
|
|
823 static GdkFilterReturn
|
|
824 gtk_form_main_filter(GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
|
|
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 /*ARGSUSED0*/
|
|
913 static void
|
|
914 gtk_form_child_map(GtkWidget *widget, gpointer user_data)
|
|
915 {
|
|
916 GtkFormChild *child;
|
|
917
|
|
918 child = (GtkFormChild *)user_data;
|
|
919
|
|
920 child->mapped = TRUE;
|
|
921 gdk_window_show(child->window);
|
|
922 }
|
|
923
|
|
924 /*ARGSUSED0*/
|
|
925 static void
|
|
926 gtk_form_child_unmap(GtkWidget *widget, gpointer user_data)
|
|
927 {
|
|
928 GtkFormChild *child;
|
|
929
|
|
930 child = (GtkFormChild *)user_data;
|
|
931
|
|
932 child->mapped = FALSE;
|
|
933 gdk_window_hide(child->window);
|
|
934 }
|
|
935
|