]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/win_gtk.c
1. implemented radio menu items for wxGTK
[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
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
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);
9e691f46 53#ifndef __WXGTK20__
da048e3d 54static void gtk_pizza_draw (GtkWidget *widget,
bf3dab48 55 GdkRectangle *area);
9e691f46 56#endif /* __WXGTK20__ */
da048e3d 57static gint gtk_pizza_expose (GtkWidget *widget,
bf3dab48 58 GdkEventExpose *event);
da048e3d 59static void gtk_pizza_add (GtkContainer *container,
bf3dab48 60 GtkWidget *widget);
da048e3d 61static void gtk_pizza_remove (GtkContainer *container,
bf3dab48 62 GtkWidget *widget);
b6fa52db
RR
63static void gtk_pizza_forall (GtkContainer *container,
64 gboolean include_internals,
65 GtkCallback callback,
66 gpointer callback_data);
ed673c6a 67
da048e3d 68static void gtk_pizza_position_child (GtkPizza *pizza,
b6fa52db 69 GtkPizzaChild *child);
da048e3d 70static void gtk_pizza_allocate_child (GtkPizza *pizza,
b6fa52db 71 GtkPizzaChild *child);
da048e3d 72static void gtk_pizza_position_children (GtkPizza *pizza);
ed673c6a 73
da048e3d 74static void gtk_pizza_adjust_allocations_recurse (GtkWidget *widget,
b6fa52db
RR
75 gpointer cb_data);
76static void gtk_pizza_adjust_allocations (GtkPizza *pizza,
77 gint dx,
78 gint dy);
ed673c6a
RR
79
80
3ca6a5f0
BP
81/* unused */
82#if 0
b6fa52db
RR
83static void gtk_pizza_expose_area (GtkPizza *pizza,
84 gint x,
85 gint y,
86 gint width,
87 gint height);
da048e3d 88static void gtk_pizza_adjustment_changed (GtkAdjustment *adjustment,
b6fa52db 89 GtkPizza *pizza);
f6bcfd97
BP
90#endif
91
da048e3d 92static GdkFilterReturn gtk_pizza_filter (GdkXEvent *gdk_xevent,
b6fa52db
RR
93 GdkEvent *event,
94 gpointer data);
da048e3d 95static GdkFilterReturn gtk_pizza_main_filter (GdkXEvent *gdk_xevent,
b6fa52db
RR
96 GdkEvent *event,
97 gpointer data);
ed673c6a
RR
98
99
da048e3d 100static GtkType gtk_pizza_child_type (GtkContainer *container);
c801d85f 101
b6fa52db 102static void gtk_pizza_scroll_set_adjustments (GtkPizza *pizza,
bf3dab48
VZ
103 GtkAdjustment *hadj,
104 GtkAdjustment *vadj);
c801d85f
KB
105
106
034be888 107static GtkContainerClass *parent_class = NULL;
ed673c6a 108static gboolean gravity_works;
034be888 109
c801d85f 110guint
da048e3d 111gtk_pizza_get_type ()
c801d85f 112{
da048e3d 113 static guint pizza_type = 0;
c801d85f 114
da048e3d 115 if (!pizza_type)
c801d85f 116 {
da048e3d 117 GtkTypeInfo pizza_info =
053f9cc1 118 {
bf3dab48
VZ
119 "GtkPizza",
120 sizeof (GtkPizza),
121 sizeof (GtkPizzaClass),
122 (GtkClassInitFunc) gtk_pizza_class_init,
123 (GtkObjectInitFunc) gtk_pizza_init,
124 /* reserved_1 */ NULL,
053f9cc1
RR
125 /* reserved_2 */ NULL,
126 (GtkClassInitFunc) NULL,
053f9cc1 127 };
da048e3d 128 pizza_type = gtk_type_unique (gtk_container_get_type (), &pizza_info);
c801d85f 129 }
bf3dab48 130
da048e3d 131 return pizza_type;
c801d85f
KB
132}
133
134static void
da048e3d 135gtk_pizza_class_init (GtkPizzaClass *klass)
c801d85f 136{
053f9cc1
RR
137 GtkObjectClass *object_class;
138 GtkWidgetClass *widget_class;
139 GtkContainerClass *container_class;
c801d85f 140
053f9cc1
RR
141 object_class = (GtkObjectClass*) klass;
142 widget_class = (GtkWidgetClass*) klass;
143 container_class = (GtkContainerClass*) klass;
053f9cc1 144 parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
c801d85f 145
da048e3d
RR
146 widget_class->map = gtk_pizza_map;
147 widget_class->realize = gtk_pizza_realize;
148 widget_class->unrealize = gtk_pizza_unrealize;
149 widget_class->size_request = gtk_pizza_size_request;
150 widget_class->size_allocate = gtk_pizza_size_allocate;
9e691f46 151#ifndef __WXGTK20__
da048e3d 152 widget_class->draw = gtk_pizza_draw;
9e691f46 153#endif
da048e3d 154 widget_class->expose_event = gtk_pizza_expose;
053f9cc1 155
da048e3d
RR
156 container_class->add = gtk_pizza_add;
157 container_class->remove = gtk_pizza_remove;
158 container_class->forall = gtk_pizza_forall;
38c7b3d3 159
da048e3d 160 container_class->child_type = gtk_pizza_child_type;
034be888 161
da048e3d 162 klass->set_scroll_adjustments = gtk_pizza_scroll_set_adjustments;
034be888 163
053f9cc1 164 widget_class->set_scroll_adjustments_signal =
034be888 165 gtk_signal_new ("set_scroll_adjustments",
bf3dab48 166 GTK_RUN_LAST,
31124903 167#ifdef __WXGTK20__
a2d8ce85 168 GTK_CLASS_TYPE(object_class),
31124903
VS
169#else
170 object_class->type,
171#endif
bf3dab48
VZ
172 GTK_SIGNAL_OFFSET (GtkPizzaClass, set_scroll_adjustments),
173 gtk_marshal_NONE__POINTER_POINTER,
174 GTK_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
38c7b3d3
RR
175}
176
38c7b3d3 177static GtkType
da048e3d 178gtk_pizza_child_type (GtkContainer *container)
38c7b3d3 179{
053f9cc1 180 return GTK_TYPE_WIDGET;
c801d85f
KB
181}
182
183static void
da048e3d 184gtk_pizza_init (GtkPizza *pizza)
c801d85f 185{
da048e3d 186 GTK_WIDGET_UNSET_FLAGS (pizza, GTK_NO_WINDOW);
bf3dab48 187
da048e3d 188 pizza->shadow_type = GTK_MYSHADOW_NONE;
034be888 189
da048e3d 190 pizza->children = NULL;
bf3dab48 191
da048e3d
RR
192 pizza->width = 20;
193 pizza->height = 20;
ed673c6a 194
da048e3d 195 pizza->bin_window = NULL;
3dd9b88a 196
8e217128
RR
197 pizza->xoffset = 0;
198 pizza->yoffset = 0;
ed673c6a 199
da048e3d
RR
200 pizza->configure_serial = 0;
201 pizza->scroll_x = 0;
202 pizza->scroll_y = 0;
203 pizza->visibility = GDK_VISIBILITY_PARTIAL;
bf3dab48 204
da048e3d 205 pizza->clear_on_draw = TRUE;
b6fa52db 206 pizza->use_filter = TRUE;
b420fb6a 207 pizza->external_expose = FALSE;
c801d85f
KB
208}
209
210GtkWidget*
da048e3d 211gtk_pizza_new ()
c801d85f 212{
da048e3d 213 GtkPizza *pizza;
c801d85f 214
da048e3d 215 pizza = gtk_type_new (gtk_pizza_get_type ());
bf3dab48 216
da048e3d 217 return GTK_WIDGET (pizza);
c801d85f
KB
218}
219
bf3dab48 220static void
da048e3d 221gtk_pizza_scroll_set_adjustments (GtkPizza *pizza,
bf3dab48
VZ
222 GtkAdjustment *hadj,
223 GtkAdjustment *vadj)
034be888 224{
ed673c6a 225 /* We handle scrolling in the wxScrolledWindow, not here. */
034be888
RR
226}
227
bf3dab48 228void
b6fa52db 229gtk_pizza_set_shadow_type (GtkPizza *pizza,
0e09f76e 230 GtkMyShadowType type)
034be888 231{
da048e3d
RR
232 g_return_if_fail (pizza != NULL);
233 g_return_if_fail (GTK_IS_PIZZA (pizza));
034be888 234
da048e3d 235 if ((GtkMyShadowType) pizza->shadow_type != type)
034be888 236 {
da048e3d 237 pizza->shadow_type = type;
034be888 238
da048e3d 239 if (GTK_WIDGET_VISIBLE (pizza))
bf3dab48
VZ
240 {
241 gtk_widget_size_allocate (GTK_WIDGET (pizza), &(GTK_WIDGET (pizza)->allocation));
242 gtk_widget_queue_draw (GTK_WIDGET (pizza));
243 }
034be888
RR
244 }
245}
034be888 246
bf3dab48 247void
b6fa52db
RR
248gtk_pizza_set_clear (GtkPizza *pizza,
249 gboolean clear)
147bc491 250{
da048e3d
RR
251 g_return_if_fail (pizza != NULL);
252 g_return_if_fail (GTK_IS_PIZZA (pizza));
bf3dab48 253
da048e3d 254 pizza->clear_on_draw = clear;
bf3dab48
VZ
255}
256
3dd9b88a 257void
b6fa52db
RR
258gtk_pizza_set_filter (GtkPizza *pizza,
259 gboolean use)
0e09f76e
RR
260{
261 g_return_if_fail (pizza != NULL);
262 g_return_if_fail (GTK_IS_PIZZA (pizza));
263
264 pizza->use_filter = use;
3dd9b88a
VZ
265}
266
267void
b420fb6a
RR
268gtk_pizza_set_external (GtkPizza *pizza,
269 gboolean expose)
270{
271 g_return_if_fail (pizza != NULL);
272 g_return_if_fail (GTK_IS_PIZZA (pizza));
273
274 pizza->external_expose = expose;
275}
276
c801d85f 277void
b6fa52db
RR
278gtk_pizza_put (GtkPizza *pizza,
279 GtkWidget *widget,
280 gint x,
281 gint y,
282 gint width,
283 gint height)
c801d85f 284{
da048e3d 285 GtkPizzaChild *child_info;
053f9cc1 286
da048e3d
RR
287 g_return_if_fail (pizza != NULL);
288 g_return_if_fail (GTK_IS_PIZZA (pizza));
053f9cc1
RR
289 g_return_if_fail (widget != NULL);
290
da048e3d 291 child_info = g_new (GtkPizzaChild, 1);
bf3dab48 292
053f9cc1
RR
293 child_info->widget = widget;
294 child_info->x = x;
295 child_info->y = y;
296 child_info->width = width;
297 child_info->height = height;
bf3dab48
VZ
298
299 pizza->children = g_list_append (pizza->children, child_info);
ed673c6a 300
da048e3d 301 gtk_widget_set_parent (widget, GTK_WIDGET (pizza));
c801d85f 302
da048e3d
RR
303 if (GTK_WIDGET_REALIZED (pizza))
304 gtk_widget_set_parent_window (widget, pizza->bin_window);
bf3dab48 305
a2d8ce85 306#ifndef __WXGTK20__ /* FIXME? */
ed673c6a
RR
307 if (!IS_ONSCREEN (x, y))
308 GTK_PRIVATE_SET_FLAG (widget, GTK_IS_OFFSCREEN);
a2d8ce85 309#endif
c801d85f 310
0e09f76e 311/*
da048e3d 312 if (GTK_WIDGET_REALIZED (pizza))
053f9cc1 313 gtk_widget_realize (widget);
0e09f76e 314*/
c801d85f 315
ed673c6a 316 gtk_widget_set_usize (widget, width, height);
bf3dab48 317
0e09f76e 318/*
da048e3d 319 if (GTK_WIDGET_VISIBLE (pizza) && GTK_WIDGET_VISIBLE (widget))
326f9654 320 {
da048e3d 321 if (GTK_WIDGET_MAPPED (pizza))
bf3dab48
VZ
322 gtk_widget_map (widget);
323
ed673c6a 324 gtk_widget_queue_resize (widget);
326f9654 325 }
0e09f76e 326*/
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;
bf3dab48
VZ
355
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);
bf3dab48 517
053f9cc1 518 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
c801d85f 519
053f9cc1 520 attributes.window_type = GDK_WINDOW_CHILD;
bf3dab48 521
053f9cc1
RR
522 attributes.x = widget->allocation.x;
523 attributes.y = widget->allocation.y;
524 attributes.width = widget->allocation.width;
525 attributes.height = widget->allocation.height;
526
1e6feb95 527#ifndef __WXUNIVERSAL__
da048e3d 528 if (pizza->shadow_type == GTK_MYSHADOW_NONE)
053f9cc1 529 {
5e014a0c 530 /* no border, no changes to sizes */
1e6feb95
VZ
531 }
532 else if (pizza->shadow_type == GTK_MYSHADOW_THIN)
5e014a0c
RR
533 {
534 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
535 attributes.x += 1;
536 attributes.y += 1;
537 attributes.width -= 2;
538 attributes.height -= 2;
1e6feb95
VZ
539 }
540 else
5e014a0c
RR
541 {
542 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
543 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
053f9cc1
RR
544 attributes.x += 2;
545 attributes.y += 2;
546 attributes.width -= 4;
547 attributes.height -= 4;
548 }
1e6feb95 549#endif /* __WXUNIVERSAL__ */
bf3dab48 550
ed673c6a 551 /* minimal size */
053f9cc1
RR
552 if (attributes.width < 2) attributes.width = 2;
553 if (attributes.height < 2) attributes.height = 2;
bf3dab48 554
053f9cc1
RR
555 attributes.wclass = GDK_INPUT_OUTPUT;
556 attributes.visual = gtk_widget_get_visual (widget);
557 attributes.colormap = gtk_widget_get_colormap (widget);
3dd9b88a 558 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
ed673c6a 559 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
bf3dab48 560
c916e13b 561 widget->window = gdk_window_new(gtk_widget_get_parent_window (widget),
bf3dab48 562 &attributes, attributes_mask);
ed673c6a
RR
563 gdk_window_set_user_data (widget->window, widget);
564
565 attributes.x = 0;
566 attributes.y = 0;
bf3dab48 567
053f9cc1 568 attributes.event_mask = gtk_widget_get_events (widget);
3dd9b88a
VZ
569 attributes.event_mask |= GDK_EXPOSURE_MASK |
570 GDK_POINTER_MOTION_MASK |
571 GDK_POINTER_MOTION_HINT_MASK |
572 GDK_BUTTON_MOTION_MASK |
573 GDK_BUTTON1_MOTION_MASK |
574 GDK_BUTTON2_MOTION_MASK |
575 GDK_BUTTON3_MOTION_MASK |
576 GDK_BUTTON_PRESS_MASK |
577 GDK_BUTTON_RELEASE_MASK |
578 GDK_KEY_PRESS_MASK |
579 GDK_KEY_RELEASE_MASK |
580 GDK_ENTER_NOTIFY_MASK |
581 GDK_LEAVE_NOTIFY_MASK |
582 GDK_FOCUS_CHANGE_MASK;
053f9cc1 583
c916e13b 584 pizza->bin_window = gdk_window_new(widget->window,
bf3dab48 585 &attributes, attributes_mask);
da048e3d 586 gdk_window_set_user_data (pizza->bin_window, widget);
bf3dab48 587
053f9cc1
RR
588 widget->style = gtk_style_attach (widget->style, widget->window);
589 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
b6fa52db 590 gtk_style_set_background (widget->style, pizza->bin_window, GTK_STATE_NORMAL );
33611ebb
RR
591
592/*
593 gdk_window_set_back_pixmap( widget->window, NULL, FALSE );
594 gdk_window_set_back_pixmap( pizza->bin_window, NULL, FALSE );
595*/
bf3dab48 596
ed673c6a 597 /* add filters for intercepting visibility and expose events */
da048e3d
RR
598 gdk_window_add_filter (widget->window, gtk_pizza_main_filter, pizza);
599 gdk_window_add_filter (pizza->bin_window, gtk_pizza_filter, pizza);
ed673c6a
RR
600
601 /* we NEED gravity or we'll give up */
da048e3d 602 gravity_works = gdk_window_set_static_gravities (pizza->bin_window, TRUE);
ed673c6a
RR
603
604 /* cannot be done before realisation */
da048e3d 605 children = pizza->children;
ed673c6a
RR
606 while (children)
607 {
608 child = children->data;
609 children = children->next;
610
da048e3d 611 gtk_widget_set_parent_window (child->widget, pizza->bin_window);
ed673c6a
RR
612 }
613}
614
bf3dab48 615static void
da048e3d 616gtk_pizza_unrealize (GtkWidget *widget)
ed673c6a 617{
d5ab387d 618 GtkPizza *pizza;
ed673c6a 619
d5ab387d
RR
620 g_return_if_fail (widget != NULL);
621 g_return_if_fail (GTK_IS_PIZZA (widget));
ed673c6a 622
d5ab387d 623 pizza = GTK_PIZZA (widget);
ed673c6a 624
d5ab387d
RR
625 gdk_window_set_user_data (pizza->bin_window, NULL);
626 gdk_window_destroy (pizza->bin_window);
627 pizza->bin_window = NULL;
ed673c6a 628
d5ab387d
RR
629 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
630 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
c801d85f
KB
631}
632
633static void
da048e3d 634gtk_pizza_size_request (GtkWidget *widget,
b6fa52db 635 GtkRequisition *requisition)
c801d85f 636{
da048e3d
RR
637 GtkPizza *pizza;
638 GtkPizzaChild *child;
053f9cc1
RR
639 GList *children;
640 GtkRequisition child_requisition;
bf3dab48 641
053f9cc1 642 g_return_if_fail (widget != NULL);
da048e3d 643 g_return_if_fail (GTK_IS_PIZZA (widget));
053f9cc1 644 g_return_if_fail (requisition != NULL);
c801d85f 645
da048e3d 646 pizza = GTK_PIZZA (widget);
bf3dab48 647
da048e3d 648 children = pizza->children;
053f9cc1 649 while (children)
c801d85f 650 {
053f9cc1
RR
651 child = children->data;
652 children = children->next;
c801d85f 653
053f9cc1 654 if (GTK_WIDGET_VISIBLE (child->widget))
bf3dab48 655 {
053f9cc1 656 gtk_widget_size_request (child->widget, &child_requisition);
bf3dab48 657 }
c801d85f 658 }
bf3dab48 659
053f9cc1
RR
660 /* request very little, I'm not sure if requesting nothing
661 will always have positive effects on stability... */
662 requisition->width = 2;
663 requisition->height = 2;
c801d85f
KB
664}
665
666static void
da048e3d 667gtk_pizza_size_allocate (GtkWidget *widget,
b6fa52db 668 GtkAllocation *allocation)
c801d85f 669{
da048e3d 670 GtkPizza *pizza;
053f9cc1 671 gint border;
ed673c6a 672 gint x,y,w,h;
da048e3d 673 GtkPizzaChild *child;
ed673c6a 674 GList *children;
c801d85f 675
053f9cc1 676 g_return_if_fail (widget != NULL);
da048e3d 677 g_return_if_fail (GTK_IS_PIZZA(widget));
053f9cc1 678 g_return_if_fail (allocation != NULL);
c801d85f 679
da048e3d 680 pizza = GTK_PIZZA (widget);
bf3dab48 681
227e5e99 682 widget->allocation = *allocation;
bf3dab48 683
da048e3d 684 if (pizza->shadow_type == GTK_MYSHADOW_NONE)
053f9cc1 685 border = 0;
5e014a0c 686 else
da048e3d 687 if (pizza->shadow_type == GTK_MYSHADOW_THIN)
5e014a0c 688 border = 1;
053f9cc1
RR
689 else
690 border = 2;
bf3dab48 691
ed673c6a
RR
692 x = allocation->x + border;
693 y = allocation->y + border;
694 w = allocation->width - border*2;
695 h = allocation->height - border*2;
034be888 696
053f9cc1
RR
697 if (GTK_WIDGET_REALIZED (widget))
698 {
ed673c6a 699 gdk_window_move_resize( widget->window, x, y, w, h );
da048e3d 700 gdk_window_move_resize( pizza->bin_window, 0, 0, w, h );
053f9cc1 701 }
bf3dab48 702
da048e3d 703 children = pizza->children;
6d693bb4
RR
704 while (children)
705 {
706 child = children->data;
707 children = children->next;
bf3dab48 708
da048e3d
RR
709 gtk_pizza_position_child (pizza, child);
710 gtk_pizza_allocate_child (pizza, child);
6d693bb4 711 }
c801d85f
KB
712}
713
9e691f46
VZ
714#ifndef __WXGTK20__
715
c801d85f 716static void
da048e3d 717gtk_pizza_draw (GtkWidget *widget,
b6fa52db 718 GdkRectangle *area)
c801d85f 719{
b420fb6a
RR
720 GtkPizza *pizza;
721 GtkPizzaChild *child;
722 GdkRectangle child_area;
723 GList *children;
724
725 g_return_if_fail (widget != NULL);
726 g_return_if_fail (GTK_IS_PIZZA (widget));
727
728 pizza = GTK_PIZZA (widget);
729
730 /* Sometimes, We handle all expose events in window.cpp now. */
731 if (pizza->external_expose)
732 return;
733
734 children = pizza->children;
735 if ( !(GTK_WIDGET_APP_PAINTABLE (widget)) &&
736 (pizza->clear_on_draw))
737 {
738 gdk_window_clear_area( pizza->bin_window,
739 area->x, area->y, area->width, area->height);
740 }
741
742 while (children)
743 {
744 child = children->data;
745 children = children->next;
746
747 if (gtk_widget_intersect (child->widget, area, &child_area))
748 gtk_widget_draw (child->widget, &child_area);
749 }
c801d85f
KB
750}
751
9e691f46
VZ
752#endif /* __WXGTK20__ */
753
c801d85f 754static gint
da048e3d 755gtk_pizza_expose (GtkWidget *widget,
b6fa52db 756 GdkEventExpose *event)
c801d85f 757{
b420fb6a
RR
758 GtkPizza *pizza;
759 GtkPizzaChild *child;
760 GdkEventExpose child_event;
761 GList *children;
762
763 g_return_val_if_fail (widget != NULL, FALSE);
764 g_return_val_if_fail (GTK_IS_PIZZA (widget), FALSE);
765 g_return_val_if_fail (event != NULL, FALSE);
766
767 pizza = GTK_PIZZA (widget);
768
769 /* Sometimes, We handle all expose events in window.cpp now. */
770 if (pizza->external_expose)
d5ab387d 771 return FALSE;
b420fb6a
RR
772
773 if (event->window != pizza->bin_window)
774 return FALSE;
775
776 children = pizza->children;
777 while (children)
778 {
779 child = children->data;
780 children = children->next;
781
782 child_event = *event;
783
784 if (GTK_WIDGET_NO_WINDOW (child->widget) &&
785 GTK_WIDGET_DRAWABLE (child->widget) &&
786 gtk_widget_intersect (child->widget, &event->area, &child_event.area))
787 {
788 gtk_widget_event (child->widget, (GdkEvent*) &child_event);
789 }
790 }
3dd9b88a 791
b420fb6a 792 return TRUE;
c801d85f
KB
793}
794
795static void
da048e3d 796gtk_pizza_add (GtkContainer *container,
bf3dab48 797 GtkWidget *widget)
c801d85f 798{
ed673c6a 799 g_return_if_fail (container != NULL);
da048e3d 800 g_return_if_fail (GTK_IS_PIZZA (container));
ed673c6a 801 g_return_if_fail (widget != NULL);
c801d85f 802
da048e3d 803 gtk_pizza_put (GTK_PIZZA (container), widget, 0, 0, 20, 20 );
c801d85f
KB
804}
805
806static void
da048e3d 807gtk_pizza_remove (GtkContainer *container,
b6fa52db 808 GtkWidget *widget)
c801d85f 809{
da048e3d
RR
810 GtkPizza *pizza;
811 GtkPizzaChild *child;
ed673c6a 812 GList *children;
c801d85f 813
ed673c6a 814 g_return_if_fail (container != NULL);
da048e3d 815 g_return_if_fail (GTK_IS_PIZZA (container));
ed673c6a 816 g_return_if_fail (widget != NULL);
c801d85f 817
da048e3d 818 pizza = GTK_PIZZA (container);
c801d85f 819
da048e3d 820 children = pizza->children;
ed673c6a 821 while (children)
c801d85f 822 {
ed673c6a 823 child = children->data;
c801d85f 824
ed673c6a 825 if (child->widget == widget)
bf3dab48
VZ
826 {
827 gtk_widget_unparent (widget);
c801d85f 828
ed673c6a
RR
829 /* security checks */
830 g_return_if_fail (GTK_IS_WIDGET (widget));
bf3dab48
VZ
831
832 pizza->children = g_list_remove_link (pizza->children, children);
833 g_list_free (children);
834 g_free (child);
c801d85f 835
ed673c6a 836 /* security checks */
bf3dab48
VZ
837 g_return_if_fail (GTK_IS_WIDGET (widget));
838
a2d8ce85 839#ifndef __WXGTK20__
ed673c6a 840 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IS_OFFSCREEN);
a2d8ce85 841#endif
bf3dab48
VZ
842
843 break;
844 }
c801d85f 845
ed673c6a 846 children = children->next;
c801d85f
KB
847 }
848}
849
850static void
da048e3d 851gtk_pizza_forall (GtkContainer *container,
b6fa52db
RR
852 gboolean include_internals,
853 GtkCallback callback,
854 gpointer callback_data)
c801d85f 855{
da048e3d
RR
856 GtkPizza *pizza;
857 GtkPizzaChild *child;
6d693bb4 858 GList *children;
c801d85f 859
6d693bb4 860 g_return_if_fail (container != NULL);
da048e3d 861 g_return_if_fail (GTK_IS_PIZZA (container));
90350682 862 g_return_if_fail (callback != (GtkCallback)NULL);
c801d85f 863
da048e3d 864 pizza = GTK_PIZZA (container);
c801d85f 865
da048e3d 866 children = pizza->children;
6d693bb4 867 while (children)
c801d85f 868 {
6d693bb4
RR
869 child = children->data;
870 children = children->next;
c801d85f 871
6d693bb4 872 (* callback) (child->widget, callback_data);
c801d85f
KB
873 }
874}
875
876
ed673c6a
RR
877/* Operations on children
878 */
879
880static void
da048e3d 881gtk_pizza_position_child (GtkPizza *pizza,
b6fa52db 882 GtkPizzaChild *child)
ed673c6a 883{
6d693bb4
RR
884 gint x;
885 gint y;
ed673c6a 886
da048e3d
RR
887 x = child->x - pizza->xoffset;
888 y = child->y - pizza->yoffset;
ed673c6a 889
6d693bb4 890 if (IS_ONSCREEN (x,y))
ed673c6a 891 {
da048e3d 892 if (GTK_WIDGET_MAPPED (pizza) &&
bf3dab48
VZ
893 GTK_WIDGET_VISIBLE (child->widget))
894 {
895 if (!GTK_WIDGET_MAPPED (child->widget))
896 gtk_widget_map (child->widget);
897 }
ed673c6a 898
a2d8ce85 899#ifndef __WXGTK20__
6d693bb4 900 if (GTK_WIDGET_IS_OFFSCREEN (child->widget))
bf3dab48 901 GTK_PRIVATE_UNSET_FLAG (child->widget, GTK_IS_OFFSCREEN);
a2d8ce85 902#endif
ed673c6a 903 }
6d693bb4 904 else
ed673c6a 905 {
a2d8ce85 906#ifndef __WXGTK20__
6d693bb4 907 if (!GTK_WIDGET_IS_OFFSCREEN (child->widget))
bf3dab48 908 GTK_PRIVATE_SET_FLAG (child->widget, GTK_IS_OFFSCREEN);
a2d8ce85 909#endif
ed673c6a 910
6d693bb4 911 if (GTK_WIDGET_MAPPED (child->widget))
bf3dab48 912 gtk_widget_unmap (child->widget);
ed673c6a
RR
913 }
914}
915
916static void
da048e3d 917gtk_pizza_allocate_child (GtkPizza *pizza,
b6fa52db 918 GtkPizzaChild *child)
ed673c6a 919{
6d693bb4
RR
920 GtkAllocation allocation;
921 GtkRequisition requisition;
922
da048e3d
RR
923 allocation.x = child->x - pizza->xoffset;
924 allocation.y = child->y - pizza->yoffset;
6d693bb4
RR
925 gtk_widget_get_child_requisition (child->widget, &requisition);
926 allocation.width = requisition.width;
927 allocation.height = requisition.height;
bf3dab48 928
6d693bb4 929 gtk_widget_size_allocate (child->widget, &allocation);
ed673c6a
RR
930}
931
932static void
da048e3d 933gtk_pizza_position_children (GtkPizza *pizza)
ed673c6a 934{
6d693bb4 935 GList *tmp_list;
ed673c6a 936
da048e3d 937 tmp_list = pizza->children;
6d693bb4 938 while (tmp_list)
ed673c6a 939 {
da048e3d 940 GtkPizzaChild *child = tmp_list->data;
6d693bb4 941 tmp_list = tmp_list->next;
bf3dab48 942
da048e3d 943 gtk_pizza_position_child (pizza, child);
ed673c6a
RR
944 }
945}
946
947static void
da048e3d 948gtk_pizza_adjust_allocations_recurse (GtkWidget *widget,
bf3dab48 949 gpointer cb_data)
ed673c6a 950{
da048e3d 951 GtkPizzaAdjData *data = cb_data;
ed673c6a 952
6d693bb4
RR
953 widget->allocation.x += data->dx;
954 widget->allocation.y += data->dy;
ed673c6a 955
6d693bb4
RR
956 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_IS_CONTAINER (widget))
957 {
bf3dab48
VZ
958 gtk_container_forall (GTK_CONTAINER (widget),
959 gtk_pizza_adjust_allocations_recurse,
960 cb_data);
6d693bb4 961 }
ed673c6a
RR
962}
963
964static void
da048e3d 965gtk_pizza_adjust_allocations (GtkPizza *pizza,
bf3dab48
VZ
966 gint dx,
967 gint dy)
ed673c6a 968{
0e09f76e
RR
969 GList *tmp_list;
970 GtkPizzaAdjData data;
ed673c6a 971
0e09f76e
RR
972 data.dx = dx;
973 data.dy = dy;
ed673c6a 974
0e09f76e
RR
975 tmp_list = pizza->children;
976 while (tmp_list)
ed673c6a 977 {
0e09f76e
RR
978 GtkPizzaChild *child = tmp_list->data;
979 tmp_list = tmp_list->next;
bf3dab48 980
0e09f76e
RR
981 child->widget->allocation.x += dx;
982 child->widget->allocation.y += dy;
ed673c6a 983
0e09f76e
RR
984 if (GTK_WIDGET_NO_WINDOW (child->widget) &&
985 GTK_IS_CONTAINER (child->widget))
986 {
987 gtk_container_forall (GTK_CONTAINER (child->widget),
988 gtk_pizza_adjust_allocations_recurse,
989 &data);
990 }
ed673c6a
RR
991 }
992}
bf3dab48 993
ed673c6a
RR
994/* Callbacks */
995
3ca6a5f0
BP
996/* unused */
997#if 0
ed673c6a
RR
998/* Send a synthetic expose event to the widget
999 */
1000static void
da048e3d 1001gtk_pizza_expose_area (GtkPizza *pizza,
bf3dab48 1002 gint x, gint y, gint width, gint height)
ed673c6a 1003{
0e09f76e 1004 if (pizza->visibility == GDK_VISIBILITY_UNOBSCURED)
ed673c6a 1005 {
0e09f76e 1006 GdkEventExpose event;
bf3dab48 1007
0e09f76e
RR
1008 event.type = GDK_EXPOSE;
1009 event.send_event = TRUE;
1010 event.window = pizza->bin_window;
1011 event.count = 0;
bf3dab48 1012
0e09f76e
RR
1013 event.area.x = x;
1014 event.area.y = y;
1015 event.area.width = width;
1016 event.area.height = height;
bf3dab48 1017
0e09f76e
RR
1018 gdk_window_ref (event.window);
1019 gtk_widget_event (GTK_WIDGET (pizza), (GdkEvent *)&event);
1020 gdk_window_unref (event.window);
ed673c6a
RR
1021 }
1022}
3ca6a5f0 1023#endif /* unused */
ed673c6a
RR
1024
1025/* This function is used to find events to process while scrolling
1026 */
1027
bf3dab48
VZ
1028static Bool
1029gtk_pizza_expose_predicate (Display *display,
1030 XEvent *xevent,
1031 XPointer arg)
ed673c6a 1032{
f6bcfd97
BP
1033 if ((xevent->type == Expose) ||
1034 ((xevent->xany.window == *(Window *)arg) &&
ed673c6a 1035 (xevent->type == ConfigureNotify)))
f6bcfd97
BP
1036 return True;
1037 else
1038 return False;
ed673c6a
RR
1039}
1040
1041/* This is the main routine to do the scrolling. Scrolling is
1042 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
1043 * a few modifications.
bf3dab48 1044 *
ed673c6a
RR
1045 * The main improvement is that we keep track of whether we
1046 * are obscured or not. If not, we ignore the generated expose
1047 * events and instead do the exposes ourself, without having
1048 * to wait for a roundtrip to the server. This also provides
1049 * a limited form of expose-event compression, since we do
1050 * the affected area as one big chunk.
1051 */
1052
1053void
da048e3d 1054gtk_pizza_scroll (GtkPizza *pizza, gint dx, gint dy)
ed673c6a 1055{
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
RR
1186 }
1187}
1188
1189/* The main event filter. Actually, we probably don't really need
1190 * to install this as a filter at all, since we are calling it
1191 * directly above in the expose-handling hack. But in case scrollbars
1192 * are fixed up in some manner...
1193 *
1194 * This routine identifies expose events that are generated when
1195 * we've temporarily moved the bin_window_origin, and translates
1196 * them or discards them, depending on whether we are obscured
1197 * or not.
1198 */
bf3dab48 1199static GdkFilterReturn
da048e3d 1200gtk_pizza_filter (GdkXEvent *gdk_xevent,
bf3dab48
VZ
1201 GdkEvent *event,
1202 gpointer data)
ed673c6a 1203{
0e09f76e
RR
1204 XEvent *xevent;
1205 GtkPizza *pizza;
ed673c6a 1206
0e09f76e 1207 xevent = (XEvent *)gdk_xevent;
3dd9b88a 1208
0e09f76e 1209 pizza = GTK_PIZZA (data);
3dd9b88a 1210
b6fa52db
RR
1211 if (!pizza->use_filter)
1212 return GDK_FILTER_CONTINUE;
1213
f6bcfd97 1214 switch (xevent->type)
ed673c6a 1215 {
3dd9b88a
VZ
1216 case Expose:
1217 if (xevent->xexpose.serial == pizza->configure_serial)
1218 {
1219 xevent->xexpose.x += pizza->scroll_x;
1220 xevent->xexpose.y += pizza->scroll_y;
1221 }
1222 break;
bf3dab48 1223
3dd9b88a
VZ
1224 case ConfigureNotify:
1225 {
1226 pizza->configure_serial = xevent->xconfigure.serial;
1227 pizza->scroll_x = xevent->xconfigure.x;
1228 pizza->scroll_y = xevent->xconfigure.y;
1229 }
1230 break;
ed673c6a 1231 }
bf3dab48 1232
0e09f76e 1233 return GDK_FILTER_CONTINUE;
ed673c6a
RR
1234}
1235
1236/* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
1237 * there is no corresponding event in GTK, so we have
1238 * to get the events from a filter
1239 */
bf3dab48 1240static GdkFilterReturn
da048e3d 1241gtk_pizza_main_filter (GdkXEvent *gdk_xevent,
bf3dab48
VZ
1242 GdkEvent *event,
1243 gpointer data)
ed673c6a 1244{
0e09f76e
RR
1245 XEvent *xevent;
1246 GtkPizza *pizza;
ed673c6a 1247
0e09f76e
RR
1248 xevent = (XEvent *)gdk_xevent;
1249 pizza = GTK_PIZZA (data);
3dd9b88a 1250
b6fa52db
RR
1251 if (!pizza->use_filter)
1252 return GDK_FILTER_CONTINUE;
ed673c6a 1253
0e09f76e 1254 if (xevent->type == VisibilityNotify)
ed673c6a 1255 {
0e09f76e 1256 switch (xevent->xvisibility.state)
bf3dab48 1257 {
0e09f76e
RR
1258 case VisibilityFullyObscured:
1259 pizza->visibility = GDK_VISIBILITY_FULLY_OBSCURED;
1260 break;
ed673c6a 1261
0e09f76e
RR
1262 case VisibilityPartiallyObscured:
1263 pizza->visibility = GDK_VISIBILITY_PARTIAL;
1264 break;
ed673c6a 1265
0e09f76e
RR
1266 case VisibilityUnobscured:
1267 pizza->visibility = GDK_VISIBILITY_UNOBSCURED;
1268 break;
bf3dab48 1269 }
3dd9b88a 1270
0e09f76e 1271 return GDK_FILTER_REMOVE;
ed673c6a
RR
1272 }
1273
0e09f76e 1274 return GDK_FILTER_CONTINUE;
ed673c6a
RR
1275}
1276
1277
c801d85f
KB
1278#ifdef __cplusplus
1279}
1280#endif /* __cplusplus */
1281