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