]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/win_gtk.c
minor fix to wxDC::SetClippingRegion
[wxWidgets.git] / src / gtk / win_gtk.c
... / ...
CommitLineData
1/* ///////////////////////////////////////////////////////////////////////////
2// Name: win_gtk.c
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.
6// Author: Robert Roebling
7// Id: $Id$
8// Copyright: (c) 1998 Robert Roebling
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////// */
11
12#ifdef VMS
13#define XCheckIfEvent XCHECKIFEVENT
14#endif
15
16#include "wx/setup.h"
17#include "wx/gtk/win_gtk.h"
18#include "gtk/gtksignal.h"
19#include "gtk/gtkprivate.h"
20#include "gdk/gdkx.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif /* __cplusplus */
25
26#include <X11/Xlib.h>
27#include <X11/Xutil.h>
28#include <X11/Xatom.h>
29
30#define IS_ONSCREEN(x,y) ((x >= G_MINSHORT) && (x <= G_MAXSHORT) && \
31 (y >= G_MINSHORT) && (y <= G_MAXSHORT))
32
33typedef struct _GtkPizzaAdjData GtkPizzaAdjData;
34
35struct _GtkPizzaAdjData
36{
37 gint dx;
38 gint dy;
39};
40
41static void gtk_pizza_class_init (GtkPizzaClass *klass);
42static void gtk_pizza_init (GtkPizza *pizza);
43
44static void gtk_pizza_realize (GtkWidget *widget);
45static void gtk_pizza_unrealize (GtkWidget *widget);
46
47static void gtk_pizza_map (GtkWidget *widget);
48
49static void gtk_pizza_size_request (GtkWidget *widget,
50 GtkRequisition *requisition);
51static void gtk_pizza_size_allocate (GtkWidget *widget,
52 GtkAllocation *allocation);
53#ifndef __WXGTK20__
54static void gtk_pizza_draw (GtkWidget *widget,
55 GdkRectangle *area);
56#endif /* __WXGTK20__ */
57static gint gtk_pizza_expose (GtkWidget *widget,
58 GdkEventExpose *event);
59static void gtk_pizza_add (GtkContainer *container,
60 GtkWidget *widget);
61static void gtk_pizza_remove (GtkContainer *container,
62 GtkWidget *widget);
63static void gtk_pizza_forall (GtkContainer *container,
64 gboolean include_internals,
65 GtkCallback callback,
66 gpointer callback_data);
67
68static void gtk_pizza_position_child (GtkPizza *pizza,
69 GtkPizzaChild *child);
70static void gtk_pizza_allocate_child (GtkPizza *pizza,
71 GtkPizzaChild *child);
72static void gtk_pizza_position_children (GtkPizza *pizza);
73
74static void gtk_pizza_adjust_allocations_recurse (GtkWidget *widget,
75 gpointer cb_data);
76static void gtk_pizza_adjust_allocations (GtkPizza *pizza,
77 gint dx,
78 gint dy);
79
80
81/* unused */
82#if 0
83static void gtk_pizza_expose_area (GtkPizza *pizza,
84 gint x,
85 gint y,
86 gint width,
87 gint height);
88static void gtk_pizza_adjustment_changed (GtkAdjustment *adjustment,
89 GtkPizza *pizza);
90#endif
91
92static GdkFilterReturn gtk_pizza_filter (GdkXEvent *gdk_xevent,
93 GdkEvent *event,
94 gpointer data);
95static GdkFilterReturn gtk_pizza_main_filter (GdkXEvent *gdk_xevent,
96 GdkEvent *event,
97 gpointer data);
98
99
100static GtkType gtk_pizza_child_type (GtkContainer *container);
101
102static void gtk_pizza_scroll_set_adjustments (GtkPizza *pizza,
103 GtkAdjustment *hadj,
104 GtkAdjustment *vadj);
105
106
107static GtkContainerClass *parent_class = NULL;
108static gboolean gravity_works;
109
110guint
111gtk_pizza_get_type ()
112{
113 static guint pizza_type = 0;
114
115 if (!pizza_type)
116 {
117 GtkTypeInfo pizza_info =
118 {
119 "GtkPizza",
120 sizeof (GtkPizza),
121 sizeof (GtkPizzaClass),
122 (GtkClassInitFunc) gtk_pizza_class_init,
123 (GtkObjectInitFunc) gtk_pizza_init,
124 /* reserved_1 */ NULL,
125 /* reserved_2 */ NULL,
126 (GtkClassInitFunc) NULL,
127 };
128 pizza_type = gtk_type_unique (gtk_container_get_type (), &pizza_info);
129 }
130
131 return pizza_type;
132}
133
134static void
135gtk_pizza_class_init (GtkPizzaClass *klass)
136{
137 GtkObjectClass *object_class;
138 GtkWidgetClass *widget_class;
139 GtkContainerClass *container_class;
140
141 object_class = (GtkObjectClass*) klass;
142 widget_class = (GtkWidgetClass*) klass;
143 container_class = (GtkContainerClass*) klass;
144 parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
145
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;
151#ifndef __WXGTK20__
152 widget_class->draw = gtk_pizza_draw;
153#endif
154 widget_class->expose_event = gtk_pizza_expose;
155
156 container_class->add = gtk_pizza_add;
157 container_class->remove = gtk_pizza_remove;
158 container_class->forall = gtk_pizza_forall;
159
160 container_class->child_type = gtk_pizza_child_type;
161
162 klass->set_scroll_adjustments = gtk_pizza_scroll_set_adjustments;
163
164 widget_class->set_scroll_adjustments_signal =
165 gtk_signal_new ("set_scroll_adjustments",
166 GTK_RUN_LAST,
167#ifdef __WXGTK20__
168 GTK_CLASS_TYPE(object_class),
169#else
170 object_class->type,
171#endif
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);
175}
176
177static GtkType
178gtk_pizza_child_type (GtkContainer *container)
179{
180 return GTK_TYPE_WIDGET;
181}
182
183static void
184gtk_pizza_init (GtkPizza *pizza)
185{
186 GTK_WIDGET_UNSET_FLAGS (pizza, GTK_NO_WINDOW);
187
188 pizza->shadow_type = GTK_MYSHADOW_NONE;
189
190 pizza->children = NULL;
191
192 pizza->width = 20;
193 pizza->height = 20;
194
195 pizza->bin_window = NULL;
196
197 pizza->xoffset = 0;
198 pizza->yoffset = 0;
199
200 pizza->configure_serial = 0;
201 pizza->scroll_x = 0;
202 pizza->scroll_y = 0;
203 pizza->visibility = GDK_VISIBILITY_PARTIAL;
204
205 pizza->clear_on_draw = TRUE;
206 pizza->use_filter = TRUE;
207 pizza->external_expose = FALSE;
208}
209
210GtkWidget*
211gtk_pizza_new ()
212{
213 GtkPizza *pizza;
214
215 pizza = gtk_type_new (gtk_pizza_get_type ());
216
217 return GTK_WIDGET (pizza);
218}
219
220static void
221gtk_pizza_scroll_set_adjustments (GtkPizza *pizza,
222 GtkAdjustment *hadj,
223 GtkAdjustment *vadj)
224{
225 /* We handle scrolling in the wxScrolledWindow, not here. */
226}
227
228void
229gtk_pizza_set_shadow_type (GtkPizza *pizza,
230 GtkMyShadowType type)
231{
232 g_return_if_fail (pizza != NULL);
233 g_return_if_fail (GTK_IS_PIZZA (pizza));
234
235 if ((GtkMyShadowType) pizza->shadow_type != type)
236 {
237 pizza->shadow_type = type;
238
239 if (GTK_WIDGET_VISIBLE (pizza))
240 {
241 gtk_widget_size_allocate (GTK_WIDGET (pizza), &(GTK_WIDGET (pizza)->allocation));
242 gtk_widget_queue_draw (GTK_WIDGET (pizza));
243 }
244 }
245}
246
247void
248gtk_pizza_set_clear (GtkPizza *pizza,
249 gboolean clear)
250{
251 g_return_if_fail (pizza != NULL);
252 g_return_if_fail (GTK_IS_PIZZA (pizza));
253
254 pizza->clear_on_draw = clear;
255}
256
257void
258gtk_pizza_set_filter (GtkPizza *pizza,
259 gboolean use)
260{
261 g_return_if_fail (pizza != NULL);
262 g_return_if_fail (GTK_IS_PIZZA (pizza));
263
264 pizza->use_filter = use;
265}
266
267void
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
277void
278gtk_pizza_put (GtkPizza *pizza,
279 GtkWidget *widget,
280 gint x,
281 gint y,
282 gint width,
283 gint height)
284{
285 GtkPizzaChild *child_info;
286
287 g_return_if_fail (pizza != NULL);
288 g_return_if_fail (GTK_IS_PIZZA (pizza));
289 g_return_if_fail (widget != NULL);
290
291 child_info = g_new (GtkPizzaChild, 1);
292
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;
298
299 pizza->children = g_list_append (pizza->children, child_info);
300
301 gtk_widget_set_parent (widget, GTK_WIDGET (pizza));
302
303 if (GTK_WIDGET_REALIZED (pizza))
304 gtk_widget_set_parent_window (widget, pizza->bin_window);
305
306#ifndef __WXGTK20__ /* FIXME? */
307 if (!IS_ONSCREEN (x, y))
308 GTK_PRIVATE_SET_FLAG (widget, GTK_IS_OFFSCREEN);
309#endif
310
311/*
312 if (GTK_WIDGET_REALIZED (pizza))
313 gtk_widget_realize (widget);
314*/
315
316 gtk_widget_set_usize (widget, width, height);
317
318/*
319 if (GTK_WIDGET_VISIBLE (pizza) && GTK_WIDGET_VISIBLE (widget))
320 {
321 if (GTK_WIDGET_MAPPED (pizza))
322 gtk_widget_map (widget);
323
324 gtk_widget_queue_resize (widget);
325 }
326*/
327}
328
329void
330gtk_pizza_move (GtkPizza *pizza,
331 GtkWidget *widget,
332 gint x,
333 gint y)
334{
335 GtkPizzaChild *child;
336 GList *children;
337
338 g_return_if_fail (pizza != NULL);
339 g_return_if_fail (GTK_IS_PIZZA (pizza));
340 g_return_if_fail (widget != NULL);
341
342 children = pizza->children;
343 while (children)
344 {
345 child = children->data;
346 children = children->next;
347
348 if (child->widget == widget)
349 {
350 if ((child->x == x) && (child->y == y))
351 break;
352
353 child->x = x;
354 child->y = y;
355
356 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (pizza))
357 gtk_widget_queue_resize (widget);
358 break;
359 }
360 }
361}
362
363void
364gtk_pizza_resize (GtkPizza *pizza,
365 GtkWidget *widget,
366 gint width,
367 gint height)
368{
369 GtkPizzaChild *child;
370 GList *children;
371
372 g_return_if_fail (pizza != NULL);
373 g_return_if_fail (GTK_IS_PIZZA (pizza));
374 g_return_if_fail (widget != NULL);
375
376 children = pizza->children;
377 while (children)
378 {
379 child = children->data;
380 children = children->next;
381
382 if (child->widget == widget)
383 {
384 if ((child->width == width) && (child->height == height))
385 break;
386
387 child->width = width;
388 child->height = height;
389
390 gtk_widget_set_usize (widget, width, height);
391
392 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (pizza))
393 gtk_widget_queue_resize (widget);
394 break;
395 }
396 }
397}
398
399void
400gtk_pizza_set_size (GtkPizza *pizza,
401 GtkWidget *widget,
402 gint x,
403 gint y,
404 gint width,
405 gint height)
406{
407 GtkPizzaChild *child;
408 GList *children;
409
410 g_return_if_fail (pizza != NULL);
411 g_return_if_fail (GTK_IS_PIZZA (pizza));
412 g_return_if_fail (widget != NULL);
413
414 children = pizza->children;
415 while (children)
416 {
417 child = children->data;
418 children = children->next;
419
420 if (child->widget == widget)
421 {
422 if ((child->x == x) &&
423 (child->y == y) &&
424 (child->width == width) &&
425 (child->height == height)) return;
426
427 child->x = x;
428 child->y = y;
429 child->width = width;
430 child->height = height;
431
432 gtk_widget_set_usize (widget, width, height);
433
434 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (pizza))
435 gtk_widget_queue_resize (widget);
436
437 return;
438 }
439 }
440}
441
442gint
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 }
465
466 return FALSE;
467}
468
469static void
470gtk_pizza_map (GtkWidget *widget)
471{
472 GtkPizza *pizza;
473 GtkPizzaChild *child;
474 GList *children;
475
476 g_return_if_fail (widget != NULL);
477 g_return_if_fail (GTK_IS_PIZZA (widget));
478
479 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
480 pizza = GTK_PIZZA (widget);
481
482 children = pizza->children;
483 while (children)
484 {
485 child = children->data;
486 children = children->next;
487
488 if ( GTK_WIDGET_VISIBLE (child->widget) &&
489 !GTK_WIDGET_MAPPED (child->widget) &&
490#ifdef __WXGTK20__
491 TRUE)
492#else
493 !GTK_WIDGET_IS_OFFSCREEN (child->widget))
494#endif
495 {
496 gtk_widget_map (child->widget);
497 }
498 }
499
500 gdk_window_show (widget->window);
501 gdk_window_show (pizza->bin_window);
502}
503
504static void
505gtk_pizza_realize (GtkWidget *widget)
506{
507 GtkPizza *pizza;
508 GdkWindowAttr attributes;
509 gint attributes_mask;
510 GtkPizzaChild *child;
511 GList *children;
512
513 g_return_if_fail (widget != NULL);
514 g_return_if_fail (GTK_IS_PIZZA (widget));
515
516 pizza = GTK_PIZZA (widget);
517
518 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
519
520 attributes.window_type = GDK_WINDOW_CHILD;
521
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
527#ifndef __WXUNIVERSAL__
528 if (pizza->shadow_type == GTK_MYSHADOW_NONE)
529 {
530 /* no border, no changes to sizes */
531 }
532 else if (pizza->shadow_type == GTK_MYSHADOW_THIN)
533 {
534 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
535 attributes.x += 1;
536 attributes.y += 1;
537 attributes.width -= 2;
538 attributes.height -= 2;
539 }
540 else
541 {
542 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
543 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
544 attributes.x += 2;
545 attributes.y += 2;
546 attributes.width -= 4;
547 attributes.height -= 4;
548 }
549#endif /* __WXUNIVERSAL__ */
550
551 /* minimal size */
552 if (attributes.width < 2) attributes.width = 2;
553 if (attributes.height < 2) attributes.height = 2;
554
555 attributes.wclass = GDK_INPUT_OUTPUT;
556 attributes.visual = gtk_widget_get_visual (widget);
557 attributes.colormap = gtk_widget_get_colormap (widget);
558 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
559 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
560
561 widget->window = gdk_window_new(gtk_widget_get_parent_window (widget),
562 &attributes, attributes_mask);
563 gdk_window_set_user_data (widget->window, widget);
564
565 attributes.x = 0;
566 attributes.y = 0;
567
568 attributes.event_mask = gtk_widget_get_events (widget);
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;
583
584 pizza->bin_window = gdk_window_new(widget->window,
585 &attributes, attributes_mask);
586 gdk_window_set_user_data (pizza->bin_window, widget);
587
588 widget->style = gtk_style_attach (widget->style, widget->window);
589 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
590 gtk_style_set_background (widget->style, pizza->bin_window, GTK_STATE_NORMAL );
591
592/*
593 gdk_window_set_back_pixmap( widget->window, NULL, FALSE );
594 gdk_window_set_back_pixmap( pizza->bin_window, NULL, FALSE );
595*/
596
597 /* add filters for intercepting visibility and expose events */
598 gdk_window_add_filter (widget->window, gtk_pizza_main_filter, pizza);
599 gdk_window_add_filter (pizza->bin_window, gtk_pizza_filter, pizza);
600
601 /* we NEED gravity or we'll give up */
602 gravity_works = gdk_window_set_static_gravities (pizza->bin_window, TRUE);
603
604 /* cannot be done before realisation */
605 children = pizza->children;
606 while (children)
607 {
608 child = children->data;
609 children = children->next;
610
611 gtk_widget_set_parent_window (child->widget, pizza->bin_window);
612 }
613}
614
615static void
616gtk_pizza_unrealize (GtkWidget *widget)
617{
618 GtkPizza *pizza;
619
620 g_return_if_fail (widget != NULL);
621 g_return_if_fail (GTK_IS_PIZZA (widget));
622
623 pizza = GTK_PIZZA (widget);
624
625 gdk_window_set_user_data (pizza->bin_window, NULL);
626 gdk_window_destroy (pizza->bin_window);
627 pizza->bin_window = NULL;
628
629 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
630 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
631}
632
633static void
634gtk_pizza_size_request (GtkWidget *widget,
635 GtkRequisition *requisition)
636{
637 GtkPizza *pizza;
638 GtkPizzaChild *child;
639 GList *children;
640 GtkRequisition child_requisition;
641
642 g_return_if_fail (widget != NULL);
643 g_return_if_fail (GTK_IS_PIZZA (widget));
644 g_return_if_fail (requisition != NULL);
645
646 pizza = GTK_PIZZA (widget);
647
648 children = pizza->children;
649 while (children)
650 {
651 child = children->data;
652 children = children->next;
653
654 if (GTK_WIDGET_VISIBLE (child->widget))
655 {
656 gtk_widget_size_request (child->widget, &child_requisition);
657 }
658 }
659
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;
664}
665
666static void
667gtk_pizza_size_allocate (GtkWidget *widget,
668 GtkAllocation *allocation)
669{
670 GtkPizza *pizza;
671 gint border;
672 gint x,y,w,h;
673 GtkPizzaChild *child;
674 GList *children;
675
676 g_return_if_fail (widget != NULL);
677 g_return_if_fail (GTK_IS_PIZZA(widget));
678 g_return_if_fail (allocation != NULL);
679
680 pizza = GTK_PIZZA (widget);
681
682 widget->allocation = *allocation;
683
684 if (pizza->shadow_type == GTK_MYSHADOW_NONE)
685 border = 0;
686 else
687 if (pizza->shadow_type == GTK_MYSHADOW_THIN)
688 border = 1;
689 else
690 border = 2;
691
692 x = allocation->x + border;
693 y = allocation->y + border;
694 w = allocation->width - border*2;
695 h = allocation->height - border*2;
696
697 if (GTK_WIDGET_REALIZED (widget))
698 {
699 gdk_window_move_resize( widget->window, x, y, w, h );
700 gdk_window_move_resize( pizza->bin_window, 0, 0, w, h );
701 }
702
703 children = pizza->children;
704 while (children)
705 {
706 child = children->data;
707 children = children->next;
708
709 gtk_pizza_position_child (pizza, child);
710 gtk_pizza_allocate_child (pizza, child);
711 }
712}
713
714#ifndef __WXGTK20__
715
716static void
717gtk_pizza_draw (GtkWidget *widget,
718 GdkRectangle *area)
719{
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 }
750}
751
752#endif /* __WXGTK20__ */
753
754static gint
755gtk_pizza_expose (GtkWidget *widget,
756 GdkEventExpose *event)
757{
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)
771 return FALSE;
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 }
791
792 return TRUE;
793}
794
795static void
796gtk_pizza_add (GtkContainer *container,
797 GtkWidget *widget)
798{
799 g_return_if_fail (container != NULL);
800 g_return_if_fail (GTK_IS_PIZZA (container));
801 g_return_if_fail (widget != NULL);
802
803 gtk_pizza_put (GTK_PIZZA (container), widget, 0, 0, 20, 20 );
804}
805
806static void
807gtk_pizza_remove (GtkContainer *container,
808 GtkWidget *widget)
809{
810 GtkPizza *pizza;
811 GtkPizzaChild *child;
812 GList *children;
813
814 g_return_if_fail (container != NULL);
815 g_return_if_fail (GTK_IS_PIZZA (container));
816 g_return_if_fail (widget != NULL);
817
818 pizza = GTK_PIZZA (container);
819
820 children = pizza->children;
821 while (children)
822 {
823 child = children->data;
824
825 if (child->widget == widget)
826 {
827 gtk_widget_unparent (widget);
828
829 /* security checks */
830 g_return_if_fail (GTK_IS_WIDGET (widget));
831
832 pizza->children = g_list_remove_link (pizza->children, children);
833 g_list_free (children);
834 g_free (child);
835
836 /* security checks */
837 g_return_if_fail (GTK_IS_WIDGET (widget));
838
839#ifndef __WXGTK20__
840 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IS_OFFSCREEN);
841#endif
842
843 break;
844 }
845
846 children = children->next;
847 }
848}
849
850static void
851gtk_pizza_forall (GtkContainer *container,
852 gboolean include_internals,
853 GtkCallback callback,
854 gpointer callback_data)
855{
856 GtkPizza *pizza;
857 GtkPizzaChild *child;
858 GList *children;
859
860 g_return_if_fail (container != NULL);
861 g_return_if_fail (GTK_IS_PIZZA (container));
862 g_return_if_fail (callback != (GtkCallback)NULL);
863
864 pizza = GTK_PIZZA (container);
865
866 children = pizza->children;
867 while (children)
868 {
869 child = children->data;
870 children = children->next;
871
872 (* callback) (child->widget, callback_data);
873 }
874}
875
876
877/* Operations on children
878 */
879
880static void
881gtk_pizza_position_child (GtkPizza *pizza,
882 GtkPizzaChild *child)
883{
884 gint x;
885 gint y;
886
887 x = child->x - pizza->xoffset;
888 y = child->y - pizza->yoffset;
889
890 if (IS_ONSCREEN (x,y))
891 {
892 if (GTK_WIDGET_MAPPED (pizza) &&
893 GTK_WIDGET_VISIBLE (child->widget))
894 {
895 if (!GTK_WIDGET_MAPPED (child->widget))
896 gtk_widget_map (child->widget);
897 }
898
899#ifndef __WXGTK20__
900 if (GTK_WIDGET_IS_OFFSCREEN (child->widget))
901 GTK_PRIVATE_UNSET_FLAG (child->widget, GTK_IS_OFFSCREEN);
902#endif
903 }
904 else
905 {
906#ifndef __WXGTK20__
907 if (!GTK_WIDGET_IS_OFFSCREEN (child->widget))
908 GTK_PRIVATE_SET_FLAG (child->widget, GTK_IS_OFFSCREEN);
909#endif
910
911 if (GTK_WIDGET_MAPPED (child->widget))
912 gtk_widget_unmap (child->widget);
913 }
914}
915
916static void
917gtk_pizza_allocate_child (GtkPizza *pizza,
918 GtkPizzaChild *child)
919{
920 GtkAllocation allocation;
921 GtkRequisition requisition;
922
923 allocation.x = child->x - pizza->xoffset;
924 allocation.y = child->y - pizza->yoffset;
925 gtk_widget_get_child_requisition (child->widget, &requisition);
926 allocation.width = requisition.width;
927 allocation.height = requisition.height;
928
929 gtk_widget_size_allocate (child->widget, &allocation);
930}
931
932static void
933gtk_pizza_position_children (GtkPizza *pizza)
934{
935 GList *tmp_list;
936
937 tmp_list = pizza->children;
938 while (tmp_list)
939 {
940 GtkPizzaChild *child = tmp_list->data;
941 tmp_list = tmp_list->next;
942
943 gtk_pizza_position_child (pizza, child);
944 }
945}
946
947static void
948gtk_pizza_adjust_allocations_recurse (GtkWidget *widget,
949 gpointer cb_data)
950{
951 GtkPizzaAdjData *data = cb_data;
952
953 widget->allocation.x += data->dx;
954 widget->allocation.y += data->dy;
955
956 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_IS_CONTAINER (widget))
957 {
958 gtk_container_forall (GTK_CONTAINER (widget),
959 gtk_pizza_adjust_allocations_recurse,
960 cb_data);
961 }
962}
963
964static void
965gtk_pizza_adjust_allocations (GtkPizza *pizza,
966 gint dx,
967 gint dy)
968{
969 GList *tmp_list;
970 GtkPizzaAdjData data;
971
972 data.dx = dx;
973 data.dy = dy;
974
975 tmp_list = pizza->children;
976 while (tmp_list)
977 {
978 GtkPizzaChild *child = tmp_list->data;
979 tmp_list = tmp_list->next;
980
981 child->widget->allocation.x += dx;
982 child->widget->allocation.y += dy;
983
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 }
991 }
992}
993
994/* Callbacks */
995
996/* unused */
997#if 0
998/* Send a synthetic expose event to the widget
999 */
1000static void
1001gtk_pizza_expose_area (GtkPizza *pizza,
1002 gint x, gint y, gint width, gint height)
1003{
1004 if (pizza->visibility == GDK_VISIBILITY_UNOBSCURED)
1005 {
1006 GdkEventExpose event;
1007
1008 event.type = GDK_EXPOSE;
1009 event.send_event = TRUE;
1010 event.window = pizza->bin_window;
1011 event.count = 0;
1012
1013 event.area.x = x;
1014 event.area.y = y;
1015 event.area.width = width;
1016 event.area.height = height;
1017
1018 gdk_window_ref (event.window);
1019 gtk_widget_event (GTK_WIDGET (pizza), (GdkEvent *)&event);
1020 gdk_window_unref (event.window);
1021 }
1022}
1023#endif /* unused */
1024
1025/* This function is used to find events to process while scrolling
1026 */
1027
1028static Bool
1029gtk_pizza_expose_predicate (Display *display,
1030 XEvent *xevent,
1031 XPointer arg)
1032{
1033 if ((xevent->type == Expose) ||
1034 ((xevent->xany.window == *(Window *)arg) &&
1035 (xevent->type == ConfigureNotify)))
1036 return True;
1037 else
1038 return False;
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.
1044 *
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
1054gtk_pizza_scroll (GtkPizza *pizza, gint dx, gint dy)
1055{
1056 GtkWidget *widget;
1057 XEvent xevent;
1058 XID win;
1059
1060 gint x,y,w,h,border;
1061
1062 widget = GTK_WIDGET (pizza);
1063
1064 pizza->xoffset += dx;
1065 pizza->yoffset += dy;
1066
1067 if (!GTK_WIDGET_MAPPED (pizza))
1068 {
1069 gtk_pizza_position_children (pizza);
1070 return;
1071 }
1072
1073 gtk_pizza_adjust_allocations (pizza, -dx, -dy);
1074
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;
1082
1083 x = 0;
1084 y = 0;
1085 w = widget->allocation.width - 2*border;
1086 h = widget->allocation.height - 2*border;
1087
1088 if (dx > 0)
1089 {
1090 if (gravity_works)
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 }
1098 else
1099 {
1100 /* FIXME */
1101 }
1102 }
1103 else if (dx < 0)
1104 {
1105 if (gravity_works)
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 }
1115 else
1116 {
1117 /* FIXME */
1118 }
1119 }
1120
1121 if (dy > 0)
1122 {
1123 if (gravity_works)
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 }
1130 else
1131 {
1132 /* FIXME */
1133 }
1134 }
1135 else if (dy < 0)
1136 {
1137 if (gravity_works)
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 }
1144 else
1145 {
1146 /* FIXME */
1147 }
1148 }
1149
1150 gtk_pizza_position_children (pizza);
1151
1152 gdk_flush();
1153
1154 win = GDK_WINDOW_XWINDOW (pizza->bin_window);
1155 while (XCheckIfEvent(GDK_WINDOW_XDISPLAY (pizza->bin_window),
1156 &xevent,
1157 gtk_pizza_expose_predicate,
1158 (XPointer)&win))
1159 {
1160 GdkEvent event;
1161 GtkWidget *event_widget;
1162
1163 if ((xevent.xany.window == GDK_WINDOW_XWINDOW (pizza->bin_window)) )
1164 gtk_pizza_filter (&xevent, &event, pizza);
1165
1166 if (xevent.type == Expose)
1167 {
1168 event.expose.window = gdk_window_lookup (xevent.xany.window);
1169 gdk_window_get_user_data (event.expose.window,
1170 (gpointer *)&event_widget);
1171
1172 if (event_widget)
1173 {
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);
1184 }
1185 }
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 */
1199static GdkFilterReturn
1200gtk_pizza_filter (GdkXEvent *gdk_xevent,
1201 GdkEvent *event,
1202 gpointer data)
1203{
1204 XEvent *xevent;
1205 GtkPizza *pizza;
1206
1207 xevent = (XEvent *)gdk_xevent;
1208
1209 pizza = GTK_PIZZA (data);
1210
1211 if (!pizza->use_filter)
1212 return GDK_FILTER_CONTINUE;
1213
1214 switch (xevent->type)
1215 {
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;
1223
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;
1231 }
1232
1233 return GDK_FILTER_CONTINUE;
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 */
1240static GdkFilterReturn
1241gtk_pizza_main_filter (GdkXEvent *gdk_xevent,
1242 GdkEvent *event,
1243 gpointer data)
1244{
1245 XEvent *xevent;
1246 GtkPizza *pizza;
1247
1248 xevent = (XEvent *)gdk_xevent;
1249 pizza = GTK_PIZZA (data);
1250
1251 if (!pizza->use_filter)
1252 return GDK_FILTER_CONTINUE;
1253
1254 if (xevent->type == VisibilityNotify)
1255 {
1256 switch (xevent->xvisibility.state)
1257 {
1258 case VisibilityFullyObscured:
1259 pizza->visibility = GDK_VISIBILITY_FULLY_OBSCURED;
1260 break;
1261
1262 case VisibilityPartiallyObscured:
1263 pizza->visibility = GDK_VISIBILITY_PARTIAL;
1264 break;
1265
1266 case VisibilityUnobscured:
1267 pizza->visibility = GDK_VISIBILITY_UNOBSCURED;
1268 break;
1269 }
1270
1271 return GDK_FILTER_REMOVE;
1272 }
1273
1274 return GDK_FILTER_CONTINUE;
1275}
1276
1277
1278#ifdef __cplusplus
1279}
1280#endif /* __cplusplus */
1281