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