]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/win_gtk.c
Needed to add #include "wx/statusbr.h" to know that wxStatusBar is derived
[wxWidgets.git] / src / gtk1 / win_gtk.c
CommitLineData
c67daf87 1/* ///////////////////////////////////////////////////////////////////////////
c67d8618 2// Name: win_gtk.c
77ffb593 3// Purpose: Native GTK+ widget for wxWidgets, based on GtkLayout and
ed673c6a
RR
4// GtkFixed. It makes use of the gravity window property and
5// therefore does not work with GTK 1.0.
c801d85f 6// Author: Robert Roebling
c67d8618 7// Id: $Id$
01111366 8// Copyright: (c) 1998 Robert Roebling
77ffb593 9// Licence: wxWidgets licence
c67daf87 10/////////////////////////////////////////////////////////////////////////// */
c801d85f 11
d02af7bb
JJ
12#ifdef VMS
13#define XCheckIfEvent XCHECKIFEVENT
3fa056ab 14#endif
27df579a 15
d02af7bb 16#include "wx/setup.h"
27df579a 17#include "wx/gtk/win_gtk.h"
034be888 18#include "gtk/gtksignal.h"
ed673c6a
RR
19#include "gtk/gtkprivate.h"
20#include "gdk/gdkx.h"
38c7b3d3 21
c801d85f
KB
22#ifdef __cplusplus
23extern "C" {
24#endif /* __cplusplus */
25
67d78217
RR
26#ifndef __WXGTK20__
27
c916e13b
RR
28#include <X11/Xlib.h>
29#include <X11/Xutil.h>
30#include <X11/Xatom.h>
31
ed673c6a
RR
32#define IS_ONSCREEN(x,y) ((x >= G_MINSHORT) && (x <= G_MAXSHORT) && \
33 (y >= G_MINSHORT) && (y <= G_MAXSHORT))
34
67d78217
RR
35#endif
36
da048e3d 37typedef struct _GtkPizzaAdjData GtkPizzaAdjData;
ed673c6a 38
bf3dab48 39struct _GtkPizzaAdjData
ed673c6a
RR
40{
41 gint dx;
42 gint dy;
43};
44
b6fa52db
RR
45static void gtk_pizza_class_init (GtkPizzaClass *klass);
46static void gtk_pizza_init (GtkPizza *pizza);
ed673c6a 47
b6fa52db
RR
48static void gtk_pizza_realize (GtkWidget *widget);
49static void gtk_pizza_unrealize (GtkWidget *widget);
ed673c6a 50
b6fa52db 51static void gtk_pizza_map (GtkWidget *widget);
ed673c6a 52
da048e3d 53static void gtk_pizza_size_request (GtkWidget *widget,
bf3dab48 54 GtkRequisition *requisition);
da048e3d 55static void gtk_pizza_size_allocate (GtkWidget *widget,
bf3dab48 56 GtkAllocation *allocation);
9e691f46 57#ifndef __WXGTK20__
da048e3d 58static void gtk_pizza_draw (GtkWidget *widget,
bf3dab48 59 GdkRectangle *area);
9e691f46 60#endif /* __WXGTK20__ */
da048e3d 61static gint gtk_pizza_expose (GtkWidget *widget,
bf3dab48 62 GdkEventExpose *event);
22aff579
VS
63static void gtk_pizza_style_set (GtkWidget *widget,
64 GtkStyle *previous_style);
da048e3d 65static void gtk_pizza_add (GtkContainer *container,
bf3dab48 66 GtkWidget *widget);
da048e3d 67static void gtk_pizza_remove (GtkContainer *container,
bf3dab48 68 GtkWidget *widget);
b6fa52db
RR
69static void gtk_pizza_forall (GtkContainer *container,
70 gboolean include_internals,
71 GtkCallback callback,
72 gpointer callback_data);
17a1ebd1 73
67d78217
RR
74static void gtk_pizza_allocate_child (GtkPizza *pizza,
75 GtkPizzaChild *child);
3fc6e5fa
RR
76static void gtk_pizza_adjust_allocations_recurse (GtkWidget *widget,
77 gpointer cb_data);
ed673c6a 78
3fc6e5fa 79#ifndef __WXGTK20__
da048e3d 80static void gtk_pizza_position_child (GtkPizza *pizza,
b6fa52db 81 GtkPizzaChild *child);
da048e3d 82static void gtk_pizza_position_children (GtkPizza *pizza);
ed673c6a 83
da048e3d 84static GdkFilterReturn gtk_pizza_filter (GdkXEvent *gdk_xevent,
b6fa52db
RR
85 GdkEvent *event,
86 gpointer data);
da048e3d 87static GdkFilterReturn gtk_pizza_main_filter (GdkXEvent *gdk_xevent,
b6fa52db
RR
88 GdkEvent *event,
89 gpointer data);
67d78217 90#endif /* __WXGTK20__ */
ed673c6a 91
da048e3d 92static GtkType gtk_pizza_child_type (GtkContainer *container);
c801d85f 93
b6fa52db 94static void gtk_pizza_scroll_set_adjustments (GtkPizza *pizza,
bf3dab48
VZ
95 GtkAdjustment *hadj,
96 GtkAdjustment *vadj);
c801d85f
KB
97
98
67d78217
RR
99#ifdef __WXGTK20__
100 GtkContainerClass *pizza_parent_class = NULL;
101#else
102static GtkContainerClass *pizza_parent_class = NULL;
103#endif
104
17a1ebd1 105#ifndef __WXGTK20__
ed673c6a 106static gboolean gravity_works;
17a1ebd1 107#endif
034be888 108
e1ff9329 109GtkType
da048e3d 110gtk_pizza_get_type ()
c801d85f 111{
e1ff9329 112 static GtkType pizza_type = 0;
c801d85f 113
da048e3d 114 if (!pizza_type)
c801d85f 115 {
17a1ebd1 116
67d78217
RR
117#ifdef __WXGTK20__
118 static const GTypeInfo pizza_info =
119 {
120 sizeof (GtkPizzaClass),
121 NULL, /* base_init */
122 NULL, /* base_finalize */
123 (GClassInitFunc) gtk_pizza_class_init,
124 NULL, /* class_finalize */
125 NULL, /* class_data */
126 sizeof (GtkPizza),
127 16, /* n_preallocs */
128 (GInstanceInitFunc) gtk_pizza_init,
129 };
17a1ebd1 130 pizza_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkPizza", &pizza_info, (GTypeFlags)0);
67d78217 131#else
da048e3d 132 GtkTypeInfo pizza_info =
053f9cc1 133 {
67d78217
RR
134 "GtkPizza",
135 sizeof (GtkPizza),
136 sizeof (GtkPizzaClass),
137 (GtkClassInitFunc) gtk_pizza_class_init,
138 (GtkObjectInitFunc) gtk_pizza_init,
139 /* reserved_1 */ NULL,
140 /* reserved_2 */ NULL,
141 (GtkClassInitFunc) NULL,
053f9cc1 142 };
da048e3d 143 pizza_type = gtk_type_unique (gtk_container_get_type (), &pizza_info);
67d78217 144#endif
c801d85f 145 }
bf3dab48 146
da048e3d 147 return pizza_type;
c801d85f
KB
148}
149
3dc786e0 150#ifdef __WXGTK20__
02a525b3
VZ
151/* Marshaller needed for set_scroll_adjustments signal,
152 generated with GLib-2.4.6 glib-genmarshal */
143318dd
RR
153#define g_marshal_value_peek_object(v) g_value_get_object (v)
154static void
155g_cclosure_user_marshal_VOID__OBJECT_OBJECT (GClosure *closure,
156 GValue *return_value,
157 guint n_param_values,
158 const GValue *param_values,
159 gpointer invocation_hint,
160 gpointer marshal_data)
161{
162 typedef void (*GMarshalFunc_VOID__OBJECT_OBJECT) (gpointer data1,
163 gpointer arg_1,
164 gpointer arg_2,
165 gpointer data2);
166 register GMarshalFunc_VOID__OBJECT_OBJECT callback;
167 register GCClosure *cc = (GCClosure*) closure;
168 register gpointer data1, data2;
169
170 g_return_if_fail (n_param_values == 3);
171
172 if (G_CCLOSURE_SWAP_DATA (closure))
173 {
174 data1 = closure->data;
175 data2 = g_value_peek_pointer (param_values + 0);
176 }
177 else
178 {
179 data1 = g_value_peek_pointer (param_values + 0);
180 data2 = closure->data;
181 }
182 callback = (GMarshalFunc_VOID__OBJECT_OBJECT) (marshal_data ? marshal_data : cc->callback);
183
184 callback (data1,
185 g_marshal_value_peek_object (param_values + 1),
186 g_marshal_value_peek_object (param_values + 2),
187 data2);
188}
02a525b3 189#endif /* __WXGTK20__ */
143318dd 190
c801d85f 191static void
da048e3d 192gtk_pizza_class_init (GtkPizzaClass *klass)
c801d85f 193{
053f9cc1
RR
194 GtkObjectClass *object_class;
195 GtkWidgetClass *widget_class;
196 GtkContainerClass *container_class;
c801d85f 197
053f9cc1
RR
198 object_class = (GtkObjectClass*) klass;
199 widget_class = (GtkWidgetClass*) klass;
200 container_class = (GtkContainerClass*) klass;
67d78217 201 pizza_parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
c801d85f 202
da048e3d
RR
203 widget_class->map = gtk_pizza_map;
204 widget_class->realize = gtk_pizza_realize;
205 widget_class->unrealize = gtk_pizza_unrealize;
206 widget_class->size_request = gtk_pizza_size_request;
207 widget_class->size_allocate = gtk_pizza_size_allocate;
9e691f46 208#ifndef __WXGTK20__
da048e3d 209 widget_class->draw = gtk_pizza_draw;
9e691f46 210#endif
da048e3d 211 widget_class->expose_event = gtk_pizza_expose;
22aff579 212 widget_class->style_set = gtk_pizza_style_set;
053f9cc1 213
da048e3d
RR
214 container_class->add = gtk_pizza_add;
215 container_class->remove = gtk_pizza_remove;
216 container_class->forall = gtk_pizza_forall;
38c7b3d3 217
da048e3d 218 container_class->child_type = gtk_pizza_child_type;
034be888 219
da048e3d 220 klass->set_scroll_adjustments = gtk_pizza_scroll_set_adjustments;
034be888 221
053f9cc1 222 widget_class->set_scroll_adjustments_signal =
3dc786e0 223#ifdef __WXGTK20__
143318dd
RR
224 g_signal_new(
225 "set_scroll_adjustments",
226 G_TYPE_FROM_CLASS(object_class),
227 G_SIGNAL_RUN_LAST,
228 G_STRUCT_OFFSET(GtkPizzaClass, set_scroll_adjustments),
229 NULL,
230 NULL,
231 g_cclosure_user_marshal_VOID__OBJECT_OBJECT,
232 G_TYPE_NONE,
233 2,
234 GTK_TYPE_ADJUSTMENT,
235 GTK_TYPE_ADJUSTMENT);
236#else
034be888 237 gtk_signal_new ("set_scroll_adjustments",
bf3dab48 238 GTK_RUN_LAST,
31124903 239 object_class->type,
bf3dab48
VZ
240 GTK_SIGNAL_OFFSET (GtkPizzaClass, set_scroll_adjustments),
241 gtk_marshal_NONE__POINTER_POINTER,
242 GTK_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
02a525b3 243#endif /* __WXGTK20__ */
38c7b3d3
RR
244}
245
38c7b3d3 246static GtkType
da048e3d 247gtk_pizza_child_type (GtkContainer *container)
38c7b3d3 248{
053f9cc1 249 return GTK_TYPE_WIDGET;
c801d85f
KB
250}
251
252static void
da048e3d 253gtk_pizza_init (GtkPizza *pizza)
c801d85f 254{
da048e3d 255 GTK_WIDGET_UNSET_FLAGS (pizza, GTK_NO_WINDOW);
bf3dab48 256
da048e3d 257 pizza->shadow_type = GTK_MYSHADOW_NONE;
034be888 258
da048e3d 259 pizza->children = NULL;
bf3dab48 260
da048e3d
RR
261 pizza->width = 20;
262 pizza->height = 20;
ed673c6a 263
da048e3d 264 pizza->bin_window = NULL;
3dd9b88a 265
8e217128
RR
266 pizza->xoffset = 0;
267 pizza->yoffset = 0;
ed673c6a 268
da048e3d
RR
269 pizza->configure_serial = 0;
270 pizza->scroll_x = 0;
271 pizza->scroll_y = 0;
272 pizza->visibility = GDK_VISIBILITY_PARTIAL;
bf3dab48 273
da048e3d 274 pizza->clear_on_draw = TRUE;
b6fa52db 275 pizza->use_filter = TRUE;
b420fb6a 276 pizza->external_expose = FALSE;
c801d85f
KB
277}
278
279GtkWidget*
da048e3d 280gtk_pizza_new ()
c801d85f 281{
da048e3d 282 GtkPizza *pizza;
c801d85f 283
da048e3d 284 pizza = gtk_type_new (gtk_pizza_get_type ());
bf3dab48 285
da048e3d 286 return GTK_WIDGET (pizza);
c801d85f
KB
287}
288
bf3dab48 289static void
da048e3d 290gtk_pizza_scroll_set_adjustments (GtkPizza *pizza,
bf3dab48
VZ
291 GtkAdjustment *hadj,
292 GtkAdjustment *vadj)
034be888 293{
ed673c6a 294 /* We handle scrolling in the wxScrolledWindow, not here. */
034be888
RR
295}
296
bf3dab48 297void
b6fa52db 298gtk_pizza_set_shadow_type (GtkPizza *pizza,
0e09f76e 299 GtkMyShadowType type)
034be888 300{
da048e3d
RR
301 g_return_if_fail (pizza != NULL);
302 g_return_if_fail (GTK_IS_PIZZA (pizza));
034be888 303
da048e3d 304 if ((GtkMyShadowType) pizza->shadow_type != type)
034be888 305 {
da048e3d 306 pizza->shadow_type = type;
034be888 307
da048e3d 308 if (GTK_WIDGET_VISIBLE (pizza))
bf3dab48
VZ
309 {
310 gtk_widget_size_allocate (GTK_WIDGET (pizza), &(GTK_WIDGET (pizza)->allocation));
311 gtk_widget_queue_draw (GTK_WIDGET (pizza));
312 }
034be888
RR
313 }
314}
034be888 315
bf3dab48 316void
b6fa52db
RR
317gtk_pizza_set_clear (GtkPizza *pizza,
318 gboolean clear)
147bc491 319{
da048e3d
RR
320 g_return_if_fail (pizza != NULL);
321 g_return_if_fail (GTK_IS_PIZZA (pizza));
bf3dab48 322
da048e3d 323 pizza->clear_on_draw = clear;
bf3dab48
VZ
324}
325
3dd9b88a 326void
b6fa52db
RR
327gtk_pizza_set_filter (GtkPizza *pizza,
328 gboolean use)
0e09f76e
RR
329{
330 g_return_if_fail (pizza != NULL);
331 g_return_if_fail (GTK_IS_PIZZA (pizza));
332
333 pizza->use_filter = use;
3dd9b88a
VZ
334}
335
336void
b420fb6a
RR
337gtk_pizza_set_external (GtkPizza *pizza,
338 gboolean expose)
339{
340 g_return_if_fail (pizza != NULL);
341 g_return_if_fail (GTK_IS_PIZZA (pizza));
342
343 pizza->external_expose = expose;
344}
345
c801d85f 346void
b6fa52db
RR
347gtk_pizza_put (GtkPizza *pizza,
348 GtkWidget *widget,
349 gint x,
350 gint y,
351 gint width,
352 gint height)
c801d85f 353{
da048e3d 354 GtkPizzaChild *child_info;
053f9cc1 355
da048e3d
RR
356 g_return_if_fail (pizza != NULL);
357 g_return_if_fail (GTK_IS_PIZZA (pizza));
053f9cc1
RR
358 g_return_if_fail (widget != NULL);
359
da048e3d 360 child_info = g_new (GtkPizzaChild, 1);
bf3dab48 361
053f9cc1
RR
362 child_info->widget = widget;
363 child_info->x = x;
364 child_info->y = y;
365 child_info->width = width;
366 child_info->height = height;
bf3dab48
VZ
367
368 pizza->children = g_list_append (pizza->children, child_info);
ed673c6a 369
da048e3d
RR
370 if (GTK_WIDGET_REALIZED (pizza))
371 gtk_widget_set_parent_window (widget, pizza->bin_window);
bf3dab48 372
2b5f62a0
VZ
373 gtk_widget_set_parent (widget, GTK_WIDGET (pizza));
374
a2d8ce85 375#ifndef __WXGTK20__ /* FIXME? */
ed673c6a
RR
376 if (!IS_ONSCREEN (x, y))
377 GTK_PRIVATE_SET_FLAG (widget, GTK_IS_OFFSCREEN);
a2d8ce85 378#endif
c801d85f 379
ed673c6a 380 gtk_widget_set_usize (widget, width, height);
c801d85f
KB
381}
382
383void
b6fa52db
RR
384gtk_pizza_move (GtkPizza *pizza,
385 GtkWidget *widget,
386 gint x,
387 gint y)
c801d85f 388{
da048e3d 389 GtkPizzaChild *child;
053f9cc1 390 GList *children;
c801d85f 391
da048e3d
RR
392 g_return_if_fail (pizza != NULL);
393 g_return_if_fail (GTK_IS_PIZZA (pizza));
053f9cc1 394 g_return_if_fail (widget != NULL);
c801d85f 395
da048e3d 396 children = pizza->children;
053f9cc1 397 while (children)
fdd3ed7a 398 {
053f9cc1
RR
399 child = children->data;
400 children = children->next;
bf3dab48 401
053f9cc1 402 if (child->widget == widget)
fdd3ed7a 403 {
bf3dab48
VZ
404 if ((child->x == x) && (child->y == y))
405 break;
406
ed673c6a
RR
407 child->x = x;
408 child->y = y;
17a1ebd1 409
bf3dab48
VZ
410 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (pizza))
411 gtk_widget_queue_resize (widget);
412 break;
413 }
fdd3ed7a
RR
414 }
415}
416
417void
b6fa52db
RR
418gtk_pizza_resize (GtkPizza *pizza,
419 GtkWidget *widget,
420 gint width,
421 gint height)
fdd3ed7a 422{
da048e3d 423 GtkPizzaChild *child;
053f9cc1 424 GList *children;
fdd3ed7a 425
da048e3d
RR
426 g_return_if_fail (pizza != NULL);
427 g_return_if_fail (GTK_IS_PIZZA (pizza));
053f9cc1 428 g_return_if_fail (widget != NULL);
fdd3ed7a 429
da048e3d 430 children = pizza->children;
053f9cc1 431 while (children)
fdd3ed7a 432 {
053f9cc1
RR
433 child = children->data;
434 children = children->next;
bf3dab48 435
053f9cc1 436 if (child->widget == widget)
fdd3ed7a 437 {
bf3dab48
VZ
438 if ((child->width == width) && (child->height == height))
439 break;
440
ed673c6a
RR
441 child->width = width;
442 child->height = height;
bf3dab48
VZ
443
444 gtk_widget_set_usize (widget, width, height);
445
da048e3d 446 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (pizza))
bf3dab48
VZ
447 gtk_widget_queue_resize (widget);
448 break;
449 }
fdd3ed7a
RR
450 }
451}
452
453void
b6fa52db
RR
454gtk_pizza_set_size (GtkPizza *pizza,
455 GtkWidget *widget,
456 gint x,
457 gint y,
458 gint width,
459 gint height)
fdd3ed7a 460{
da048e3d 461 GtkPizzaChild *child;
053f9cc1 462 GList *children;
fdd3ed7a 463
da048e3d
RR
464 g_return_if_fail (pizza != NULL);
465 g_return_if_fail (GTK_IS_PIZZA (pizza));
053f9cc1 466 g_return_if_fail (widget != NULL);
fdd3ed7a 467
da048e3d 468 children = pizza->children;
053f9cc1 469 while (children)
c801d85f 470 {
053f9cc1
RR
471 child = children->data;
472 children = children->next;
c801d85f 473
053f9cc1 474 if (child->widget == widget)
c801d85f 475 {
bf3dab48
VZ
476 if ((child->x == x) &&
477 (child->y == y) &&
478 (child->width == width) &&
479 (child->height == height)) return;
480
053f9cc1
RR
481 child->x = x;
482 child->y = y;
483 child->width = width;
484 child->height = height;
bf3dab48
VZ
485
486 gtk_widget_set_usize (widget, width, height);
487
da048e3d 488 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (pizza))
bf3dab48
VZ
489 gtk_widget_queue_resize (widget);
490
6d693bb4 491 return;
c801d85f
KB
492 }
493 }
494}
495
3dd9b88a 496gint
8cb9f0d0
RR
497gtk_pizza_child_resized (GtkPizza *pizza,
498 GtkWidget *widget)
499{
500 GtkPizzaChild *child;
501 GList *children;
502
503 g_return_val_if_fail (pizza != NULL, FALSE);
504 g_return_val_if_fail (GTK_IS_PIZZA (pizza), FALSE);
505 g_return_val_if_fail (widget != NULL, FALSE);
506
507 children = pizza->children;
508 while (children)
509 {
510 child = children->data;
511 children = children->next;
512
513 if (child->widget == widget)
514 {
515 return ((child->width == widget->allocation.width) &&
516 (child->height == widget->allocation.height));
517 }
518 }
3dd9b88a 519
8cb9f0d0
RR
520 return FALSE;
521}
3dd9b88a 522
c801d85f 523static void
da048e3d 524gtk_pizza_map (GtkWidget *widget)
c801d85f 525{
da048e3d
RR
526 GtkPizza *pizza;
527 GtkPizzaChild *child;
053f9cc1 528 GList *children;
c801d85f 529
053f9cc1 530 g_return_if_fail (widget != NULL);
da048e3d 531 g_return_if_fail (GTK_IS_PIZZA (widget));
c801d85f 532
053f9cc1 533 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
da048e3d 534 pizza = GTK_PIZZA (widget);
c801d85f 535
da048e3d 536 children = pizza->children;
053f9cc1 537 while (children)
c801d85f 538 {
053f9cc1
RR
539 child = children->data;
540 children = children->next;
c801d85f 541
bf3dab48
VZ
542 if ( GTK_WIDGET_VISIBLE (child->widget) &&
543 !GTK_WIDGET_MAPPED (child->widget) &&
a2d8ce85
OK
544#ifdef __WXGTK20__
545 TRUE)
546#else
bf3dab48 547 !GTK_WIDGET_IS_OFFSCREEN (child->widget))
a2d8ce85 548#endif
bf3dab48
VZ
549 {
550 gtk_widget_map (child->widget);
551 }
c801d85f 552 }
bf3dab48 553
053f9cc1 554 gdk_window_show (widget->window);
da048e3d 555 gdk_window_show (pizza->bin_window);
c801d85f
KB
556}
557
c801d85f 558static void
da048e3d 559gtk_pizza_realize (GtkWidget *widget)
c801d85f 560{
da048e3d 561 GtkPizza *pizza;
053f9cc1
RR
562 GdkWindowAttr attributes;
563 gint attributes_mask;
da048e3d 564 GtkPizzaChild *child;
ed673c6a 565 GList *children;
c801d85f 566
053f9cc1 567 g_return_if_fail (widget != NULL);
da048e3d 568 g_return_if_fail (GTK_IS_PIZZA (widget));
c801d85f 569
da048e3d 570 pizza = GTK_PIZZA (widget);
053f9cc1 571 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
c801d85f 572
053f9cc1 573 attributes.window_type = GDK_WINDOW_CHILD;
bf3dab48 574
053f9cc1
RR
575 attributes.x = widget->allocation.x;
576 attributes.y = widget->allocation.y;
577 attributes.width = widget->allocation.width;
578 attributes.height = widget->allocation.height;
579
1e6feb95 580#ifndef __WXUNIVERSAL__
da048e3d 581 if (pizza->shadow_type == GTK_MYSHADOW_NONE)
053f9cc1 582 {
5e014a0c 583 /* no border, no changes to sizes */
1e6feb95
VZ
584 }
585 else if (pizza->shadow_type == GTK_MYSHADOW_THIN)
5e014a0c
RR
586 {
587 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
588 attributes.x += 1;
589 attributes.y += 1;
590 attributes.width -= 2;
591 attributes.height -= 2;
1e6feb95
VZ
592 }
593 else
5e014a0c
RR
594 {
595 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
596 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
053f9cc1
RR
597 attributes.x += 2;
598 attributes.y += 2;
599 attributes.width -= 4;
600 attributes.height -= 4;
601 }
1e6feb95 602#endif /* __WXUNIVERSAL__ */
bf3dab48 603
ed673c6a 604 /* minimal size */
053f9cc1
RR
605 if (attributes.width < 2) attributes.width = 2;
606 if (attributes.height < 2) attributes.height = 2;
bf3dab48 607
053f9cc1
RR
608 attributes.wclass = GDK_INPUT_OUTPUT;
609 attributes.visual = gtk_widget_get_visual (widget);
610 attributes.colormap = gtk_widget_get_colormap (widget);
3dd9b88a 611 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
ed673c6a 612 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
bf3dab48 613
c916e13b 614 widget->window = gdk_window_new(gtk_widget_get_parent_window (widget),
bf3dab48 615 &attributes, attributes_mask);
ed673c6a
RR
616 gdk_window_set_user_data (widget->window, widget);
617
618 attributes.x = 0;
619 attributes.y = 0;
bf3dab48 620
053f9cc1 621 attributes.event_mask = gtk_widget_get_events (widget);
3dd9b88a 622 attributes.event_mask |= GDK_EXPOSURE_MASK |
67d78217
RR
623#ifdef __WXGTK20__
624 GDK_SCROLL_MASK |
625#endif
3dd9b88a
VZ
626 GDK_POINTER_MOTION_MASK |
627 GDK_POINTER_MOTION_HINT_MASK |
628 GDK_BUTTON_MOTION_MASK |
629 GDK_BUTTON1_MOTION_MASK |
630 GDK_BUTTON2_MOTION_MASK |
631 GDK_BUTTON3_MOTION_MASK |
632 GDK_BUTTON_PRESS_MASK |
633 GDK_BUTTON_RELEASE_MASK |
634 GDK_KEY_PRESS_MASK |
635 GDK_KEY_RELEASE_MASK |
636 GDK_ENTER_NOTIFY_MASK |
637 GDK_LEAVE_NOTIFY_MASK |
638 GDK_FOCUS_CHANGE_MASK;
053f9cc1 639
c916e13b 640 pizza->bin_window = gdk_window_new(widget->window,
bf3dab48 641 &attributes, attributes_mask);
da048e3d 642 gdk_window_set_user_data (pizza->bin_window, widget);
bf3dab48 643
053f9cc1
RR
644 widget->style = gtk_style_attach (widget->style, widget->window);
645 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
b6fa52db 646 gtk_style_set_background (widget->style, pizza->bin_window, GTK_STATE_NORMAL );
17a1ebd1 647
33611ebb
RR
648/*
649 gdk_window_set_back_pixmap( widget->window, NULL, FALSE );
650 gdk_window_set_back_pixmap( pizza->bin_window, NULL, FALSE );
651*/
bf3dab48 652
67d78217 653#ifndef __WXGTK20__
ed673c6a 654 /* add filters for intercepting visibility and expose events */
da048e3d
RR
655 gdk_window_add_filter (widget->window, gtk_pizza_main_filter, pizza);
656 gdk_window_add_filter (pizza->bin_window, gtk_pizza_filter, pizza);
ed673c6a
RR
657
658 /* we NEED gravity or we'll give up */
da048e3d 659 gravity_works = gdk_window_set_static_gravities (pizza->bin_window, TRUE);
17a1ebd1 660#endif // !__WXGTK20__
ed673c6a
RR
661
662 /* cannot be done before realisation */
da048e3d 663 children = pizza->children;
ed673c6a
RR
664 while (children)
665 {
666 child = children->data;
667 children = children->next;
668
da048e3d 669 gtk_widget_set_parent_window (child->widget, pizza->bin_window);
ed673c6a
RR
670 }
671}
672
bf3dab48 673static void
da048e3d 674gtk_pizza_unrealize (GtkWidget *widget)
ed673c6a 675{
d5ab387d 676 GtkPizza *pizza;
ed673c6a 677
d5ab387d
RR
678 g_return_if_fail (widget != NULL);
679 g_return_if_fail (GTK_IS_PIZZA (widget));
ed673c6a 680
d5ab387d 681 pizza = GTK_PIZZA (widget);
ed673c6a 682
d5ab387d
RR
683 gdk_window_set_user_data (pizza->bin_window, NULL);
684 gdk_window_destroy (pizza->bin_window);
685 pizza->bin_window = NULL;
ed673c6a 686
67d78217
RR
687 if (GTK_WIDGET_CLASS (pizza_parent_class)->unrealize)
688 (* GTK_WIDGET_CLASS (pizza_parent_class)->unrealize) (widget);
c801d85f
KB
689}
690
691static void
da048e3d 692gtk_pizza_size_request (GtkWidget *widget,
b6fa52db 693 GtkRequisition *requisition)
c801d85f 694{
da048e3d
RR
695 GtkPizza *pizza;
696 GtkPizzaChild *child;
053f9cc1
RR
697 GList *children;
698 GtkRequisition child_requisition;
bf3dab48 699
053f9cc1 700 g_return_if_fail (widget != NULL);
da048e3d 701 g_return_if_fail (GTK_IS_PIZZA (widget));
053f9cc1 702 g_return_if_fail (requisition != NULL);
c801d85f 703
da048e3d 704 pizza = GTK_PIZZA (widget);
bf3dab48 705
da048e3d 706 children = pizza->children;
053f9cc1 707 while (children)
c801d85f 708 {
053f9cc1
RR
709 child = children->data;
710 children = children->next;
c801d85f 711
053f9cc1 712 if (GTK_WIDGET_VISIBLE (child->widget))
bf3dab48 713 {
053f9cc1 714 gtk_widget_size_request (child->widget, &child_requisition);
bf3dab48 715 }
c801d85f 716 }
bf3dab48 717
053f9cc1
RR
718 /* request very little, I'm not sure if requesting nothing
719 will always have positive effects on stability... */
720 requisition->width = 2;
721 requisition->height = 2;
c801d85f
KB
722}
723
724static void
da048e3d 725gtk_pizza_size_allocate (GtkWidget *widget,
b6fa52db 726 GtkAllocation *allocation)
c801d85f 727{
da048e3d 728 GtkPizza *pizza;
053f9cc1 729 gint border;
ed673c6a 730 gint x,y,w,h;
da048e3d 731 GtkPizzaChild *child;
ed673c6a 732 GList *children;
c801d85f 733
053f9cc1 734 g_return_if_fail (widget != NULL);
da048e3d 735 g_return_if_fail (GTK_IS_PIZZA(widget));
053f9cc1 736 g_return_if_fail (allocation != NULL);
c801d85f 737
da048e3d 738 pizza = GTK_PIZZA (widget);
bf3dab48 739
227e5e99 740 widget->allocation = *allocation;
bf3dab48 741
da048e3d 742 if (pizza->shadow_type == GTK_MYSHADOW_NONE)
053f9cc1 743 border = 0;
5e014a0c 744 else
da048e3d 745 if (pizza->shadow_type == GTK_MYSHADOW_THIN)
5e014a0c 746 border = 1;
053f9cc1
RR
747 else
748 border = 2;
bf3dab48 749
ed673c6a
RR
750 x = allocation->x + border;
751 y = allocation->y + border;
752 w = allocation->width - border*2;
753 h = allocation->height - border*2;
034be888 754
053f9cc1
RR
755 if (GTK_WIDGET_REALIZED (widget))
756 {
ed673c6a 757 gdk_window_move_resize( widget->window, x, y, w, h );
da048e3d 758 gdk_window_move_resize( pizza->bin_window, 0, 0, w, h );
053f9cc1 759 }
bf3dab48 760
da048e3d 761 children = pizza->children;
6d693bb4
RR
762 while (children)
763 {
764 child = children->data;
765 children = children->next;
bf3dab48 766
3fc6e5fa 767#ifndef __WXGTK20__
da048e3d 768 gtk_pizza_position_child (pizza, child);
3fc6e5fa 769#endif
da048e3d 770 gtk_pizza_allocate_child (pizza, child);
6d693bb4 771 }
c801d85f
KB
772}
773
9e691f46
VZ
774#ifndef __WXGTK20__
775
c801d85f 776static void
da048e3d 777gtk_pizza_draw (GtkWidget *widget,
b6fa52db 778 GdkRectangle *area)
c801d85f 779{
b420fb6a
RR
780 GtkPizza *pizza;
781 GtkPizzaChild *child;
782 GdkRectangle child_area;
783 GList *children;
784
785 g_return_if_fail (widget != NULL);
786 g_return_if_fail (GTK_IS_PIZZA (widget));
787
788 pizza = GTK_PIZZA (widget);
789
790 /* Sometimes, We handle all expose events in window.cpp now. */
791 if (pizza->external_expose)
792 return;
793
794 children = pizza->children;
795 if ( !(GTK_WIDGET_APP_PAINTABLE (widget)) &&
796 (pizza->clear_on_draw))
797 {
798 gdk_window_clear_area( pizza->bin_window,
799 area->x, area->y, area->width, area->height);
800 }
801
802 while (children)
803 {
804 child = children->data;
805 children = children->next;
806
807 if (gtk_widget_intersect (child->widget, area, &child_area))
808 gtk_widget_draw (child->widget, &child_area);
809 }
c801d85f
KB
810}
811
9e691f46
VZ
812#endif /* __WXGTK20__ */
813
c801d85f 814static gint
da048e3d 815gtk_pizza_expose (GtkWidget *widget,
b6fa52db 816 GdkEventExpose *event)
c801d85f 817{
b420fb6a 818 GtkPizza *pizza;
3fc6e5fa 819#ifndef __WXGTK20__
b420fb6a
RR
820 GtkPizzaChild *child;
821 GdkEventExpose child_event;
822 GList *children;
3fc6e5fa 823#endif
b420fb6a
RR
824
825 g_return_val_if_fail (widget != NULL, FALSE);
826 g_return_val_if_fail (GTK_IS_PIZZA (widget), FALSE);
827 g_return_val_if_fail (event != NULL, FALSE);
828
829 pizza = GTK_PIZZA (widget);
830
67d78217
RR
831 if (event->window != pizza->bin_window)
832 return FALSE;
4e5a4c69 833
67d78217 834 /* We handle all expose events in window.cpp now. */
b420fb6a 835 if (pizza->external_expose)
d5ab387d 836 return FALSE;
b420fb6a 837
67d78217
RR
838#ifdef __WXGTK20__
839
840 (* GTK_WIDGET_CLASS (pizza_parent_class)->expose_event) (widget, event);
17a1ebd1 841
67d78217 842 return FALSE;
17a1ebd1 843
67d78217 844#else
b420fb6a
RR
845
846 children = pizza->children;
847 while (children)
848 {
849 child = children->data;
850 children = children->next;
851
852 child_event = *event;
853
854 if (GTK_WIDGET_NO_WINDOW (child->widget) &&
855 GTK_WIDGET_DRAWABLE (child->widget) &&
856 gtk_widget_intersect (child->widget, &event->area, &child_event.area))
857 {
858 gtk_widget_event (child->widget, (GdkEvent*) &child_event);
859 }
860 }
17a1ebd1 861
b420fb6a 862 return TRUE;
17a1ebd1 863
67d78217 864#endif
c801d85f
KB
865}
866
22aff579
VS
867static void
868gtk_pizza_style_set(GtkWidget *widget, GtkStyle *previous_style)
869{
870 if (GTK_WIDGET_REALIZED(widget))
871 {
872 gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL);
873 gtk_style_set_background(widget->style, GTK_PIZZA(widget)->bin_window, GTK_STATE_NORMAL );
874 }
875
876 (* GTK_WIDGET_CLASS (pizza_parent_class)->style_set) (widget, previous_style);
877}
878
c801d85f 879static void
da048e3d 880gtk_pizza_add (GtkContainer *container,
bf3dab48 881 GtkWidget *widget)
c801d85f 882{
ed673c6a 883 g_return_if_fail (container != NULL);
da048e3d 884 g_return_if_fail (GTK_IS_PIZZA (container));
ed673c6a 885 g_return_if_fail (widget != NULL);
c801d85f 886
da048e3d 887 gtk_pizza_put (GTK_PIZZA (container), widget, 0, 0, 20, 20 );
c801d85f
KB
888}
889
890static void
da048e3d 891gtk_pizza_remove (GtkContainer *container,
b6fa52db 892 GtkWidget *widget)
c801d85f 893{
da048e3d
RR
894 GtkPizza *pizza;
895 GtkPizzaChild *child;
ed673c6a 896 GList *children;
c801d85f 897
ed673c6a 898 g_return_if_fail (container != NULL);
da048e3d 899 g_return_if_fail (GTK_IS_PIZZA (container));
ed673c6a 900 g_return_if_fail (widget != NULL);
c801d85f 901
da048e3d 902 pizza = GTK_PIZZA (container);
c801d85f 903
da048e3d 904 children = pizza->children;
ed673c6a 905 while (children)
c801d85f 906 {
ed673c6a 907 child = children->data;
c801d85f 908
ed673c6a 909 if (child->widget == widget)
bf3dab48
VZ
910 {
911 gtk_widget_unparent (widget);
c801d85f 912
ed673c6a
RR
913 /* security checks */
914 g_return_if_fail (GTK_IS_WIDGET (widget));
bf3dab48
VZ
915
916 pizza->children = g_list_remove_link (pizza->children, children);
917 g_list_free (children);
918 g_free (child);
c801d85f 919
ed673c6a 920 /* security checks */
bf3dab48
VZ
921 g_return_if_fail (GTK_IS_WIDGET (widget));
922
a2d8ce85 923#ifndef __WXGTK20__
ed673c6a 924 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IS_OFFSCREEN);
a2d8ce85 925#endif
bf3dab48
VZ
926
927 break;
928 }
c801d85f 929
ed673c6a 930 children = children->next;
c801d85f
KB
931 }
932}
933
934static void
da048e3d 935gtk_pizza_forall (GtkContainer *container,
b6fa52db
RR
936 gboolean include_internals,
937 GtkCallback callback,
938 gpointer callback_data)
c801d85f 939{
da048e3d
RR
940 GtkPizza *pizza;
941 GtkPizzaChild *child;
6d693bb4 942 GList *children;
c801d85f 943
6d693bb4 944 g_return_if_fail (container != NULL);
da048e3d 945 g_return_if_fail (GTK_IS_PIZZA (container));
90350682 946 g_return_if_fail (callback != (GtkCallback)NULL);
c801d85f 947
da048e3d 948 pizza = GTK_PIZZA (container);
c801d85f 949
da048e3d 950 children = pizza->children;
6d693bb4 951 while (children)
c801d85f 952 {
6d693bb4
RR
953 child = children->data;
954 children = children->next;
c801d85f 955
6d693bb4 956 (* callback) (child->widget, callback_data);
c801d85f
KB
957 }
958}
959
67d78217
RR
960static void
961gtk_pizza_allocate_child (GtkPizza *pizza,
962 GtkPizzaChild *child)
963{
964 GtkAllocation allocation;
965 GtkRequisition requisition;
c801d85f 966
67d78217
RR
967 allocation.x = child->x - pizza->xoffset;
968 allocation.y = child->y - pizza->yoffset;
969 gtk_widget_get_child_requisition (child->widget, &requisition);
970 allocation.width = requisition.width;
971 allocation.height = requisition.height;
972
973 gtk_widget_size_allocate (child->widget, &allocation);
974}
ed673c6a 975
ed673c6a 976static void
da048e3d 977gtk_pizza_adjust_allocations_recurse (GtkWidget *widget,
bf3dab48 978 gpointer cb_data)
ed673c6a 979{
da048e3d 980 GtkPizzaAdjData *data = cb_data;
ed673c6a 981
6d693bb4
RR
982 widget->allocation.x += data->dx;
983 widget->allocation.y += data->dy;
ed673c6a 984
6d693bb4
RR
985 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_IS_CONTAINER (widget))
986 {
bf3dab48
VZ
987 gtk_container_forall (GTK_CONTAINER (widget),
988 gtk_pizza_adjust_allocations_recurse,
989 cb_data);
6d693bb4 990 }
ed673c6a
RR
991}
992
993static void
da048e3d 994gtk_pizza_adjust_allocations (GtkPizza *pizza,
bf3dab48
VZ
995 gint dx,
996 gint dy)
ed673c6a 997{
0e09f76e
RR
998 GList *tmp_list;
999 GtkPizzaAdjData data;
ed673c6a 1000
0e09f76e
RR
1001 data.dx = dx;
1002 data.dy = dy;
ed673c6a 1003
0e09f76e
RR
1004 tmp_list = pizza->children;
1005 while (tmp_list)
ed673c6a 1006 {
0e09f76e
RR
1007 GtkPizzaChild *child = tmp_list->data;
1008 tmp_list = tmp_list->next;
bf3dab48 1009
0e09f76e
RR
1010 child->widget->allocation.x += dx;
1011 child->widget->allocation.y += dy;
ed673c6a 1012
0e09f76e
RR
1013 if (GTK_WIDGET_NO_WINDOW (child->widget) &&
1014 GTK_IS_CONTAINER (child->widget))
1015 {
1016 gtk_container_forall (GTK_CONTAINER (child->widget),
1017 gtk_pizza_adjust_allocations_recurse,
1018 &data);
1019 }
ed673c6a
RR
1020 }
1021}
bf3dab48 1022
3fc6e5fa
RR
1023#ifndef __WXGTK20__
1024static void
1025gtk_pizza_position_child (GtkPizza *pizza,
1026 GtkPizzaChild *child)
1027{
1028 gint x;
1029 gint y;
ed673c6a 1030
3fc6e5fa
RR
1031 x = child->x - pizza->xoffset;
1032 y = child->y - pizza->yoffset;
1033
1034 if (IS_ONSCREEN (x,y))
1035 {
1036 if (GTK_WIDGET_MAPPED (pizza) &&
1037 GTK_WIDGET_VISIBLE (child->widget))
1038 {
1039 if (!GTK_WIDGET_MAPPED (child->widget))
1040 gtk_widget_map (child->widget);
1041 }
1042
1043 if (GTK_WIDGET_IS_OFFSCREEN (child->widget))
1044 GTK_PRIVATE_UNSET_FLAG (child->widget, GTK_IS_OFFSCREEN);
1045 }
1046 else
1047 {
1048 if (!GTK_WIDGET_IS_OFFSCREEN (child->widget))
1049 GTK_PRIVATE_SET_FLAG (child->widget, GTK_IS_OFFSCREEN);
1050
1051 if (GTK_WIDGET_MAPPED (child->widget))
1052 gtk_widget_unmap (child->widget);
1053 }
1054}
1055
1056static void
1057gtk_pizza_position_children (GtkPizza *pizza)
1058{
1059 GList *tmp_list;
1060
1061 tmp_list = pizza->children;
1062 while (tmp_list)
1063 {
1064 GtkPizzaChild *child = tmp_list->data;
1065 tmp_list = tmp_list->next;
1066
1067 gtk_pizza_position_child (pizza, child);
1068 }
1069}
1070
1071/* This function is used to find events to process while scrolling */
bf3dab48
VZ
1072static Bool
1073gtk_pizza_expose_predicate (Display *display,
1074 XEvent *xevent,
1075 XPointer arg)
ed673c6a 1076{
f6bcfd97
BP
1077 if ((xevent->type == Expose) ||
1078 ((xevent->xany.window == *(Window *)arg) &&
ed673c6a 1079 (xevent->type == ConfigureNotify)))
f6bcfd97
BP
1080 return True;
1081 else
1082 return False;
ed673c6a 1083}
3fc6e5fa 1084#endif /* __WXGTK20__ */
ed673c6a
RR
1085
1086/* This is the main routine to do the scrolling. Scrolling is
1087 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
1088 * a few modifications.
bf3dab48 1089 *
ed673c6a
RR
1090 * The main improvement is that we keep track of whether we
1091 * are obscured or not. If not, we ignore the generated expose
1092 * events and instead do the exposes ourself, without having
1093 * to wait for a roundtrip to the server. This also provides
1094 * a limited form of expose-event compression, since we do
1095 * the affected area as one big chunk.
1096 */
1097
1098void
da048e3d 1099gtk_pizza_scroll (GtkPizza *pizza, gint dx, gint dy)
ed673c6a 1100{
3fc6e5fa
RR
1101#ifdef __WXGTK20__
1102 pizza->xoffset += dx;
1103 pizza->yoffset += dy;
1104
1105 gtk_pizza_adjust_allocations (pizza, -dx, -dy);
1106
1107 if (pizza->bin_window)
1108 gdk_window_scroll( pizza->bin_window, -dx, -dy );
17a1ebd1 1109#else // !__WXGTK20__
f6bcfd97
BP
1110 GtkWidget *widget;
1111 XEvent xevent;
9e691f46 1112 XID win;
ed673c6a 1113
f6bcfd97 1114 gint x,y,w,h,border;
bf3dab48 1115
f6bcfd97 1116 widget = GTK_WIDGET (pizza);
ed673c6a 1117
f6bcfd97
BP
1118 pizza->xoffset += dx;
1119 pizza->yoffset += dy;
ed673c6a 1120
f6bcfd97 1121 if (!GTK_WIDGET_MAPPED (pizza))
ed673c6a 1122 {
f6bcfd97
BP
1123 gtk_pizza_position_children (pizza);
1124 return;
ed673c6a
RR
1125 }
1126
f6bcfd97 1127 gtk_pizza_adjust_allocations (pizza, -dx, -dy);
ed673c6a 1128
f6bcfd97
BP
1129 if (pizza->shadow_type == GTK_MYSHADOW_NONE)
1130 border = 0;
1131 else
1132 if (pizza->shadow_type == GTK_MYSHADOW_THIN)
1133 border = 1;
1134 else
1135 border = 2;
bf3dab48 1136
f6bcfd97
BP
1137 x = 0;
1138 y = 0;
1139 w = widget->allocation.width - 2*border;
1140 h = widget->allocation.height - 2*border;
bf3dab48 1141
f6bcfd97 1142 if (dx > 0)
ed673c6a 1143 {
f6bcfd97 1144 if (gravity_works)
bf3dab48
VZ
1145 {
1146 gdk_window_resize (pizza->bin_window,
1147 w + dx,
1148 h);
1149 gdk_window_move (pizza->bin_window, x-dx, y);
1150 gdk_window_move_resize (pizza->bin_window, x, y, w, h );
1151 }
f6bcfd97 1152 else
bf3dab48
VZ
1153 {
1154 /* FIXME */
1155 }
ed673c6a 1156 }
f6bcfd97 1157 else if (dx < 0)
ed673c6a 1158 {
f6bcfd97 1159 if (gravity_works)
bf3dab48
VZ
1160 {
1161 gdk_window_move_resize (pizza->bin_window,
1162 x + dx,
1163 y,
1164 w - dx,
1165 h);
1166 gdk_window_move (pizza->bin_window, x, y);
1167 gdk_window_resize (pizza->bin_window, w, h );
1168 }
f6bcfd97 1169 else
bf3dab48
VZ
1170 {
1171 /* FIXME */
1172 }
ed673c6a
RR
1173 }
1174
f6bcfd97 1175 if (dy > 0)
ed673c6a 1176 {
f6bcfd97 1177 if (gravity_works)
bf3dab48
VZ
1178 {
1179 gdk_window_resize (pizza->bin_window, w, h + dy);
1180 gdk_window_move (pizza->bin_window, x, y-dy);
1181 gdk_window_move_resize (pizza->bin_window,
1182 x, y, w, h );
1183 }
f6bcfd97 1184 else
bf3dab48
VZ
1185 {
1186 /* FIXME */
1187 }
ed673c6a 1188 }
f6bcfd97 1189 else if (dy < 0)
ed673c6a 1190 {
f6bcfd97 1191 if (gravity_works)
bf3dab48
VZ
1192 {
1193 gdk_window_move_resize (pizza->bin_window,
1194 x, y+dy, w, h - dy );
1195 gdk_window_move (pizza->bin_window, x, y);
1196 gdk_window_resize (pizza->bin_window, w, h );
1197 }
f6bcfd97 1198 else
bf3dab48
VZ
1199 {
1200 /* FIXME */
1201 }
ed673c6a
RR
1202 }
1203
f6bcfd97
BP
1204 gtk_pizza_position_children (pizza);
1205
1206 gdk_flush();
9e691f46
VZ
1207
1208 win = GDK_WINDOW_XWINDOW (pizza->bin_window);
f6bcfd97
BP
1209 while (XCheckIfEvent(GDK_WINDOW_XDISPLAY (pizza->bin_window),
1210 &xevent,
1211 gtk_pizza_expose_predicate,
9e691f46 1212 (XPointer)&win))
ed673c6a 1213 {
f6bcfd97
BP
1214 GdkEvent event;
1215 GtkWidget *event_widget;
ed673c6a 1216
f6bcfd97
BP
1217 if ((xevent.xany.window == GDK_WINDOW_XWINDOW (pizza->bin_window)) )
1218 gtk_pizza_filter (&xevent, &event, pizza);
bf3dab48 1219
f6bcfd97 1220 if (xevent.type == Expose)
bf3dab48 1221 {
f6bcfd97
BP
1222 event.expose.window = gdk_window_lookup (xevent.xany.window);
1223 gdk_window_get_user_data (event.expose.window,
bf3dab48
VZ
1224 (gpointer *)&event_widget);
1225
f6bcfd97 1226 if (event_widget)
bf3dab48 1227 {
f6bcfd97
BP
1228 event.expose.type = GDK_EXPOSE;
1229 event.expose.area.x = xevent.xexpose.x;
1230 event.expose.area.y = xevent.xexpose.y;
1231 event.expose.area.width = xevent.xexpose.width;
1232 event.expose.area.height = xevent.xexpose.height;
1233 event.expose.count = xevent.xexpose.count;
1234
1235 gdk_window_ref (event.expose.window);
1236 gtk_widget_event (event_widget, &event);
1237 gdk_window_unref (event.expose.window);
bf3dab48
VZ
1238 }
1239 }
ed673c6a 1240 }
17a1ebd1 1241#endif /* __WXGTK20__/!__WXGTK20__ */
ed673c6a
RR
1242}
1243
3fc6e5fa
RR
1244
1245#ifndef __WXGTK20__
ed673c6a
RR
1246/* The main event filter. Actually, we probably don't really need
1247 * to install this as a filter at all, since we are calling it
1248 * directly above in the expose-handling hack. But in case scrollbars
1249 * are fixed up in some manner...
1250 *
1251 * This routine identifies expose events that are generated when
1252 * we've temporarily moved the bin_window_origin, and translates
1253 * them or discards them, depending on whether we are obscured
1254 * or not.
1255 */
bf3dab48 1256static GdkFilterReturn
da048e3d 1257gtk_pizza_filter (GdkXEvent *gdk_xevent,
bf3dab48
VZ
1258 GdkEvent *event,
1259 gpointer data)
ed673c6a 1260{
0e09f76e
RR
1261 XEvent *xevent;
1262 GtkPizza *pizza;
ed673c6a 1263
0e09f76e 1264 xevent = (XEvent *)gdk_xevent;
3dd9b88a 1265
0e09f76e 1266 pizza = GTK_PIZZA (data);
3dd9b88a 1267
b6fa52db
RR
1268 if (!pizza->use_filter)
1269 return GDK_FILTER_CONTINUE;
1270
f6bcfd97 1271 switch (xevent->type)
ed673c6a 1272 {
3dd9b88a
VZ
1273 case Expose:
1274 if (xevent->xexpose.serial == pizza->configure_serial)
1275 {
1276 xevent->xexpose.x += pizza->scroll_x;
1277 xevent->xexpose.y += pizza->scroll_y;
1278 }
1279 break;
bf3dab48 1280
3dd9b88a
VZ
1281 case ConfigureNotify:
1282 {
1283 pizza->configure_serial = xevent->xconfigure.serial;
1284 pizza->scroll_x = xevent->xconfigure.x;
1285 pizza->scroll_y = xevent->xconfigure.y;
1286 }
1287 break;
ed673c6a 1288 }
bf3dab48 1289
0e09f76e 1290 return GDK_FILTER_CONTINUE;
ed673c6a
RR
1291}
1292
1293/* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
1294 * there is no corresponding event in GTK, so we have
1295 * to get the events from a filter
1296 */
bf3dab48 1297static GdkFilterReturn
da048e3d 1298gtk_pizza_main_filter (GdkXEvent *gdk_xevent,
bf3dab48
VZ
1299 GdkEvent *event,
1300 gpointer data)
ed673c6a 1301{
0e09f76e
RR
1302 XEvent *xevent;
1303 GtkPizza *pizza;
ed673c6a 1304
0e09f76e
RR
1305 xevent = (XEvent *)gdk_xevent;
1306 pizza = GTK_PIZZA (data);
3dd9b88a 1307
b6fa52db
RR
1308 if (!pizza->use_filter)
1309 return GDK_FILTER_CONTINUE;
ed673c6a 1310
0e09f76e 1311 if (xevent->type == VisibilityNotify)
ed673c6a 1312 {
0e09f76e 1313 switch (xevent->xvisibility.state)
bf3dab48 1314 {
0e09f76e
RR
1315 case VisibilityFullyObscured:
1316 pizza->visibility = GDK_VISIBILITY_FULLY_OBSCURED;
1317 break;
ed673c6a 1318
0e09f76e
RR
1319 case VisibilityPartiallyObscured:
1320 pizza->visibility = GDK_VISIBILITY_PARTIAL;
1321 break;
ed673c6a 1322
0e09f76e
RR
1323 case VisibilityUnobscured:
1324 pizza->visibility = GDK_VISIBILITY_UNOBSCURED;
1325 break;
bf3dab48 1326 }
3dd9b88a 1327
0e09f76e 1328 return GDK_FILTER_REMOVE;
ed673c6a
RR
1329 }
1330
0e09f76e 1331 return GDK_FILTER_CONTINUE;
ed673c6a 1332}
67d78217
RR
1333#endif /* __WXGTK20__ */
1334
ed673c6a 1335
c801d85f
KB
1336#ifdef __cplusplus
1337}
1338#endif /* __cplusplus */
1339