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