1 /* ///////////////////////////////////////////////////////////////////////////
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
8 // Copyright: (c) 1998 Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////// */
13 #define XCheckIfEvent XCHECKIFEVENT
17 #include "wx/gtk/win_gtk.h"
18 #include "gtk/gtksignal.h"
19 #include "gtk/gtkprivate.h"
24 #endif /* __cplusplus */
29 #include <X11/Xutil.h>
30 #include <X11/Xatom.h>
32 #define IS_ONSCREEN(x,y) ((x >= G_MINSHORT) && (x <= G_MAXSHORT) && \
33 (y >= G_MINSHORT) && (y <= G_MAXSHORT))
37 typedef struct _GtkPizzaAdjData GtkPizzaAdjData
;
39 struct _GtkPizzaAdjData
45 static void gtk_pizza_class_init (GtkPizzaClass
*klass
);
46 static void gtk_pizza_init (GtkPizza
*pizza
);
48 static void gtk_pizza_realize (GtkWidget
*widget
);
49 static void gtk_pizza_unrealize (GtkWidget
*widget
);
51 static void gtk_pizza_map (GtkWidget
*widget
);
53 static void gtk_pizza_size_request (GtkWidget
*widget
,
54 GtkRequisition
*requisition
);
55 static void gtk_pizza_size_allocate (GtkWidget
*widget
,
56 GtkAllocation
*allocation
);
58 static void gtk_pizza_draw (GtkWidget
*widget
,
60 #endif /* __WXGTK20__ */
61 static gint
gtk_pizza_expose (GtkWidget
*widget
,
62 GdkEventExpose
*event
);
63 static void gtk_pizza_add (GtkContainer
*container
,
65 static void gtk_pizza_remove (GtkContainer
*container
,
67 static void gtk_pizza_forall (GtkContainer
*container
,
68 gboolean include_internals
,
70 gpointer callback_data
);
72 static void gtk_pizza_allocate_child (GtkPizza
*pizza
,
73 GtkPizzaChild
*child
);
74 static void gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
78 static void gtk_pizza_position_child (GtkPizza
*pizza
,
79 GtkPizzaChild
*child
);
80 static void gtk_pizza_position_children (GtkPizza
*pizza
);
82 static GdkFilterReturn
gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
85 static GdkFilterReturn
gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
88 #endif /* __WXGTK20__ */
90 static GtkType
gtk_pizza_child_type (GtkContainer
*container
);
92 static void gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
98 GtkContainerClass
*pizza_parent_class
= NULL
;
100 static GtkContainerClass
*pizza_parent_class
= NULL
;
103 static gboolean gravity_works
;
106 gtk_pizza_get_type ()
108 static guint pizza_type
= 0;
114 static const GTypeInfo pizza_info
=
116 sizeof (GtkPizzaClass
),
117 NULL
, /* base_init */
118 NULL
, /* base_finalize */
119 (GClassInitFunc
) gtk_pizza_class_init
,
120 NULL
, /* class_finalize */
121 NULL
, /* class_data */
123 16, /* n_preallocs */
124 (GInstanceInitFunc
) gtk_pizza_init
,
126 pizza_type
= g_type_register_static (GTK_TYPE_CONTAINER
, "GtkPizza", &pizza_info
, 0);
128 GtkTypeInfo pizza_info
=
132 sizeof (GtkPizzaClass
),
133 (GtkClassInitFunc
) gtk_pizza_class_init
,
134 (GtkObjectInitFunc
) gtk_pizza_init
,
135 /* reserved_1 */ NULL
,
136 /* reserved_2 */ NULL
,
137 (GtkClassInitFunc
) NULL
,
139 pizza_type
= gtk_type_unique (gtk_container_get_type (), &pizza_info
);
147 gtk_pizza_class_init (GtkPizzaClass
*klass
)
149 GtkObjectClass
*object_class
;
150 GtkWidgetClass
*widget_class
;
151 GtkContainerClass
*container_class
;
153 object_class
= (GtkObjectClass
*) klass
;
154 widget_class
= (GtkWidgetClass
*) klass
;
155 container_class
= (GtkContainerClass
*) klass
;
156 pizza_parent_class
= gtk_type_class (GTK_TYPE_CONTAINER
);
158 widget_class
->map
= gtk_pizza_map
;
159 widget_class
->realize
= gtk_pizza_realize
;
160 widget_class
->unrealize
= gtk_pizza_unrealize
;
161 widget_class
->size_request
= gtk_pizza_size_request
;
162 widget_class
->size_allocate
= gtk_pizza_size_allocate
;
164 widget_class
->draw
= gtk_pizza_draw
;
166 widget_class
->expose_event
= gtk_pizza_expose
;
168 container_class
->add
= gtk_pizza_add
;
169 container_class
->remove
= gtk_pizza_remove
;
170 container_class
->forall
= gtk_pizza_forall
;
172 container_class
->child_type
= gtk_pizza_child_type
;
174 klass
->set_scroll_adjustments
= gtk_pizza_scroll_set_adjustments
;
176 widget_class
->set_scroll_adjustments_signal
=
177 gtk_signal_new ("set_scroll_adjustments",
180 GTK_CLASS_TYPE(object_class
),
184 GTK_SIGNAL_OFFSET (GtkPizzaClass
, set_scroll_adjustments
),
185 gtk_marshal_NONE__POINTER_POINTER
,
186 GTK_TYPE_NONE
, 2, GTK_TYPE_ADJUSTMENT
, GTK_TYPE_ADJUSTMENT
);
190 gtk_pizza_child_type (GtkContainer
*container
)
192 return GTK_TYPE_WIDGET
;
196 gtk_pizza_init (GtkPizza
*pizza
)
198 GTK_WIDGET_UNSET_FLAGS (pizza
, GTK_NO_WINDOW
);
200 pizza
->shadow_type
= GTK_MYSHADOW_NONE
;
202 pizza
->children
= NULL
;
207 pizza
->bin_window
= NULL
;
212 pizza
->configure_serial
= 0;
215 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
217 pizza
->clear_on_draw
= TRUE
;
218 pizza
->use_filter
= TRUE
;
219 pizza
->external_expose
= FALSE
;
227 pizza
= gtk_type_new (gtk_pizza_get_type ());
229 return GTK_WIDGET (pizza
);
233 gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
237 /* We handle scrolling in the wxScrolledWindow, not here. */
241 gtk_pizza_set_shadow_type (GtkPizza
*pizza
,
242 GtkMyShadowType type
)
244 g_return_if_fail (pizza
!= NULL
);
245 g_return_if_fail (GTK_IS_PIZZA (pizza
));
247 if ((GtkMyShadowType
) pizza
->shadow_type
!= type
)
249 pizza
->shadow_type
= type
;
251 if (GTK_WIDGET_VISIBLE (pizza
))
253 gtk_widget_size_allocate (GTK_WIDGET (pizza
), &(GTK_WIDGET (pizza
)->allocation
));
254 gtk_widget_queue_draw (GTK_WIDGET (pizza
));
260 gtk_pizza_set_clear (GtkPizza
*pizza
,
263 g_return_if_fail (pizza
!= NULL
);
264 g_return_if_fail (GTK_IS_PIZZA (pizza
));
266 pizza
->clear_on_draw
= clear
;
270 gtk_pizza_set_filter (GtkPizza
*pizza
,
273 g_return_if_fail (pizza
!= NULL
);
274 g_return_if_fail (GTK_IS_PIZZA (pizza
));
276 pizza
->use_filter
= use
;
280 gtk_pizza_set_external (GtkPizza
*pizza
,
283 g_return_if_fail (pizza
!= NULL
);
284 g_return_if_fail (GTK_IS_PIZZA (pizza
));
286 pizza
->external_expose
= expose
;
290 gtk_pizza_put (GtkPizza
*pizza
,
297 GtkPizzaChild
*child_info
;
299 g_return_if_fail (pizza
!= NULL
);
300 g_return_if_fail (GTK_IS_PIZZA (pizza
));
301 g_return_if_fail (widget
!= NULL
);
303 child_info
= g_new (GtkPizzaChild
, 1);
305 child_info
->widget
= widget
;
308 child_info
->width
= width
;
309 child_info
->height
= height
;
311 pizza
->children
= g_list_append (pizza
->children
, child_info
);
313 if (GTK_WIDGET_REALIZED (pizza
))
314 gtk_widget_set_parent_window (widget
, pizza
->bin_window
);
316 gtk_widget_set_parent (widget
, GTK_WIDGET (pizza
));
318 #ifndef __WXGTK20__ /* FIXME? */
319 if (!IS_ONSCREEN (x
, y
))
320 GTK_PRIVATE_SET_FLAG (widget
, GTK_IS_OFFSCREEN
);
323 gtk_widget_set_usize (widget
, width
, height
);
327 gtk_pizza_move (GtkPizza
*pizza
,
332 GtkPizzaChild
*child
;
335 g_return_if_fail (pizza
!= NULL
);
336 g_return_if_fail (GTK_IS_PIZZA (pizza
));
337 g_return_if_fail (widget
!= NULL
);
339 children
= pizza
->children
;
342 child
= children
->data
;
343 children
= children
->next
;
345 if (child
->widget
== widget
)
347 if ((child
->x
== x
) && (child
->y
== y
))
353 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
354 gtk_widget_queue_resize (widget
);
361 gtk_pizza_resize (GtkPizza
*pizza
,
366 GtkPizzaChild
*child
;
369 g_return_if_fail (pizza
!= NULL
);
370 g_return_if_fail (GTK_IS_PIZZA (pizza
));
371 g_return_if_fail (widget
!= NULL
);
373 children
= pizza
->children
;
376 child
= children
->data
;
377 children
= children
->next
;
379 if (child
->widget
== widget
)
381 if ((child
->width
== width
) && (child
->height
== height
))
384 child
->width
= width
;
385 child
->height
= height
;
387 gtk_widget_set_usize (widget
, width
, height
);
389 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
390 gtk_widget_queue_resize (widget
);
397 gtk_pizza_set_size (GtkPizza
*pizza
,
404 GtkPizzaChild
*child
;
407 g_return_if_fail (pizza
!= NULL
);
408 g_return_if_fail (GTK_IS_PIZZA (pizza
));
409 g_return_if_fail (widget
!= NULL
);
411 children
= pizza
->children
;
414 child
= children
->data
;
415 children
= children
->next
;
417 if (child
->widget
== widget
)
419 if ((child
->x
== x
) &&
421 (child
->width
== width
) &&
422 (child
->height
== height
)) return;
426 child
->width
= width
;
427 child
->height
= height
;
429 gtk_widget_set_usize (widget
, width
, height
);
431 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
432 gtk_widget_queue_resize (widget
);
440 gtk_pizza_child_resized (GtkPizza
*pizza
,
443 GtkPizzaChild
*child
;
446 g_return_val_if_fail (pizza
!= NULL
, FALSE
);
447 g_return_val_if_fail (GTK_IS_PIZZA (pizza
), FALSE
);
448 g_return_val_if_fail (widget
!= NULL
, FALSE
);
450 children
= pizza
->children
;
453 child
= children
->data
;
454 children
= children
->next
;
456 if (child
->widget
== widget
)
458 return ((child
->width
== widget
->allocation
.width
) &&
459 (child
->height
== widget
->allocation
.height
));
467 gtk_pizza_map (GtkWidget
*widget
)
470 GtkPizzaChild
*child
;
473 g_return_if_fail (widget
!= NULL
);
474 g_return_if_fail (GTK_IS_PIZZA (widget
));
476 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
477 pizza
= GTK_PIZZA (widget
);
479 children
= pizza
->children
;
482 child
= children
->data
;
483 children
= children
->next
;
485 if ( GTK_WIDGET_VISIBLE (child
->widget
) &&
486 !GTK_WIDGET_MAPPED (child
->widget
) &&
490 !GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
493 gtk_widget_map (child
->widget
);
497 gdk_window_show (widget
->window
);
498 gdk_window_show (pizza
->bin_window
);
502 gtk_pizza_realize (GtkWidget
*widget
)
505 GdkWindowAttr attributes
;
506 gint attributes_mask
;
507 GtkPizzaChild
*child
;
510 g_return_if_fail (widget
!= NULL
);
511 g_return_if_fail (GTK_IS_PIZZA (widget
));
513 pizza
= GTK_PIZZA (widget
);
514 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
516 attributes
.window_type
= GDK_WINDOW_CHILD
;
518 attributes
.x
= widget
->allocation
.x
;
519 attributes
.y
= widget
->allocation
.y
;
520 attributes
.width
= widget
->allocation
.width
;
521 attributes
.height
= widget
->allocation
.height
;
523 #ifndef __WXUNIVERSAL__
524 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
526 /* no border, no changes to sizes */
528 else if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
530 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
533 attributes
.width
-= 2;
534 attributes
.height
-= 2;
538 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
539 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
542 attributes
.width
-= 4;
543 attributes
.height
-= 4;
545 #endif /* __WXUNIVERSAL__ */
548 if (attributes
.width
< 2) attributes
.width
= 2;
549 if (attributes
.height
< 2) attributes
.height
= 2;
551 attributes
.wclass
= GDK_INPUT_OUTPUT
;
552 attributes
.visual
= gtk_widget_get_visual (widget
);
553 attributes
.colormap
= gtk_widget_get_colormap (widget
);
554 attributes
.event_mask
= GDK_VISIBILITY_NOTIFY_MASK
;
555 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
557 widget
->window
= gdk_window_new(gtk_widget_get_parent_window (widget
),
558 &attributes
, attributes_mask
);
559 gdk_window_set_user_data (widget
->window
, widget
);
564 attributes
.event_mask
= gtk_widget_get_events (widget
);
565 attributes
.event_mask
|= GDK_EXPOSURE_MASK
|
569 GDK_POINTER_MOTION_MASK
|
570 GDK_POINTER_MOTION_HINT_MASK
|
571 GDK_BUTTON_MOTION_MASK
|
572 GDK_BUTTON1_MOTION_MASK
|
573 GDK_BUTTON2_MOTION_MASK
|
574 GDK_BUTTON3_MOTION_MASK
|
575 GDK_BUTTON_PRESS_MASK
|
576 GDK_BUTTON_RELEASE_MASK
|
578 GDK_KEY_RELEASE_MASK
|
579 GDK_ENTER_NOTIFY_MASK
|
580 GDK_LEAVE_NOTIFY_MASK
|
581 GDK_FOCUS_CHANGE_MASK
;
583 pizza
->bin_window
= gdk_window_new(widget
->window
,
584 &attributes
, attributes_mask
);
585 gdk_window_set_user_data (pizza
->bin_window
, widget
);
587 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
588 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
589 gtk_style_set_background (widget
->style
, pizza
->bin_window
, GTK_STATE_NORMAL
);
592 gdk_window_set_back_pixmap( widget->window, NULL, FALSE );
593 gdk_window_set_back_pixmap( pizza->bin_window, NULL, FALSE );
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
);
602 /* we NEED gravity or we'll give up */
603 gravity_works
= gdk_window_set_static_gravities (pizza
->bin_window
, TRUE
);
605 /* cannot be done before realisation */
606 children
= pizza
->children
;
609 child
= children
->data
;
610 children
= children
->next
;
612 gtk_widget_set_parent_window (child
->widget
, pizza
->bin_window
);
617 gtk_pizza_unrealize (GtkWidget
*widget
)
621 g_return_if_fail (widget
!= NULL
);
622 g_return_if_fail (GTK_IS_PIZZA (widget
));
624 pizza
= GTK_PIZZA (widget
);
626 gdk_window_set_user_data (pizza
->bin_window
, NULL
);
627 gdk_window_destroy (pizza
->bin_window
);
628 pizza
->bin_window
= NULL
;
630 if (GTK_WIDGET_CLASS (pizza_parent_class
)->unrealize
)
631 (* GTK_WIDGET_CLASS (pizza_parent_class
)->unrealize
) (widget
);
635 gtk_pizza_size_request (GtkWidget
*widget
,
636 GtkRequisition
*requisition
)
639 GtkPizzaChild
*child
;
641 GtkRequisition child_requisition
;
643 g_return_if_fail (widget
!= NULL
);
644 g_return_if_fail (GTK_IS_PIZZA (widget
));
645 g_return_if_fail (requisition
!= NULL
);
647 pizza
= GTK_PIZZA (widget
);
649 children
= pizza
->children
;
652 child
= children
->data
;
653 children
= children
->next
;
655 if (GTK_WIDGET_VISIBLE (child
->widget
))
657 gtk_widget_size_request (child
->widget
, &child_requisition
);
661 /* request very little, I'm not sure if requesting nothing
662 will always have positive effects on stability... */
663 requisition
->width
= 2;
664 requisition
->height
= 2;
668 gtk_pizza_size_allocate (GtkWidget
*widget
,
669 GtkAllocation
*allocation
)
674 GtkPizzaChild
*child
;
677 g_return_if_fail (widget
!= NULL
);
678 g_return_if_fail (GTK_IS_PIZZA(widget
));
679 g_return_if_fail (allocation
!= NULL
);
681 pizza
= GTK_PIZZA (widget
);
683 widget
->allocation
= *allocation
;
685 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
688 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
693 x
= allocation
->x
+ border
;
694 y
= allocation
->y
+ border
;
695 w
= allocation
->width
- border
*2;
696 h
= allocation
->height
- border
*2;
698 if (GTK_WIDGET_REALIZED (widget
))
700 gdk_window_move_resize( widget
->window
, x
, y
, w
, h
);
701 gdk_window_move_resize( pizza
->bin_window
, 0, 0, w
, h
);
704 children
= pizza
->children
;
707 child
= children
->data
;
708 children
= children
->next
;
711 gtk_pizza_position_child (pizza
, child
);
713 gtk_pizza_allocate_child (pizza
, child
);
720 gtk_pizza_draw (GtkWidget
*widget
,
724 GtkPizzaChild
*child
;
725 GdkRectangle child_area
;
728 g_return_if_fail (widget
!= NULL
);
729 g_return_if_fail (GTK_IS_PIZZA (widget
));
731 pizza
= GTK_PIZZA (widget
);
733 /* Sometimes, We handle all expose events in window.cpp now. */
734 if (pizza
->external_expose
)
737 children
= pizza
->children
;
738 if ( !(GTK_WIDGET_APP_PAINTABLE (widget
)) &&
739 (pizza
->clear_on_draw
))
741 gdk_window_clear_area( pizza
->bin_window
,
742 area
->x
, area
->y
, area
->width
, area
->height
);
747 child
= children
->data
;
748 children
= children
->next
;
750 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
751 gtk_widget_draw (child
->widget
, &child_area
);
755 #endif /* __WXGTK20__ */
758 gtk_pizza_expose (GtkWidget
*widget
,
759 GdkEventExpose
*event
)
763 GtkPizzaChild
*child
;
764 GdkEventExpose child_event
;
768 g_return_val_if_fail (widget
!= NULL
, FALSE
);
769 g_return_val_if_fail (GTK_IS_PIZZA (widget
), FALSE
);
770 g_return_val_if_fail (event
!= NULL
, FALSE
);
772 pizza
= GTK_PIZZA (widget
);
774 if (event
->window
!= pizza
->bin_window
)
777 /* We handle all expose events in window.cpp now. */
778 if (pizza
->external_expose
)
783 (* GTK_WIDGET_CLASS (pizza_parent_class
)->expose_event
) (widget
, event
);
789 children
= pizza
->children
;
792 child
= children
->data
;
793 children
= children
->next
;
795 child_event
= *event
;
797 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
798 GTK_WIDGET_DRAWABLE (child
->widget
) &&
799 gtk_widget_intersect (child
->widget
, &event
->area
, &child_event
.area
))
801 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
811 gtk_pizza_add (GtkContainer
*container
,
814 g_return_if_fail (container
!= NULL
);
815 g_return_if_fail (GTK_IS_PIZZA (container
));
816 g_return_if_fail (widget
!= NULL
);
818 gtk_pizza_put (GTK_PIZZA (container
), widget
, 0, 0, 20, 20 );
822 gtk_pizza_remove (GtkContainer
*container
,
826 GtkPizzaChild
*child
;
829 g_return_if_fail (container
!= NULL
);
830 g_return_if_fail (GTK_IS_PIZZA (container
));
831 g_return_if_fail (widget
!= NULL
);
833 pizza
= GTK_PIZZA (container
);
835 children
= pizza
->children
;
838 child
= children
->data
;
840 if (child
->widget
== widget
)
842 gtk_widget_unparent (widget
);
844 /* security checks */
845 g_return_if_fail (GTK_IS_WIDGET (widget
));
847 pizza
->children
= g_list_remove_link (pizza
->children
, children
);
848 g_list_free (children
);
851 /* security checks */
852 g_return_if_fail (GTK_IS_WIDGET (widget
));
855 GTK_PRIVATE_UNSET_FLAG (widget
, GTK_IS_OFFSCREEN
);
861 children
= children
->next
;
866 gtk_pizza_forall (GtkContainer
*container
,
867 gboolean include_internals
,
868 GtkCallback callback
,
869 gpointer callback_data
)
872 GtkPizzaChild
*child
;
875 g_return_if_fail (container
!= NULL
);
876 g_return_if_fail (GTK_IS_PIZZA (container
));
877 g_return_if_fail (callback
!= (GtkCallback
)NULL
);
879 pizza
= GTK_PIZZA (container
);
881 children
= pizza
->children
;
884 child
= children
->data
;
885 children
= children
->next
;
887 (* callback
) (child
->widget
, callback_data
);
892 gtk_pizza_allocate_child (GtkPizza
*pizza
,
893 GtkPizzaChild
*child
)
895 GtkAllocation allocation
;
896 GtkRequisition requisition
;
898 allocation
.x
= child
->x
- pizza
->xoffset
;
899 allocation
.y
= child
->y
- pizza
->yoffset
;
900 gtk_widget_get_child_requisition (child
->widget
, &requisition
);
901 allocation
.width
= requisition
.width
;
902 allocation
.height
= requisition
.height
;
904 gtk_widget_size_allocate (child
->widget
, &allocation
);
908 gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
911 GtkPizzaAdjData
*data
= cb_data
;
913 widget
->allocation
.x
+= data
->dx
;
914 widget
->allocation
.y
+= data
->dy
;
916 if (GTK_WIDGET_NO_WINDOW (widget
) && GTK_IS_CONTAINER (widget
))
918 gtk_container_forall (GTK_CONTAINER (widget
),
919 gtk_pizza_adjust_allocations_recurse
,
925 gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
930 GtkPizzaAdjData data
;
935 tmp_list
= pizza
->children
;
938 GtkPizzaChild
*child
= tmp_list
->data
;
939 tmp_list
= tmp_list
->next
;
941 child
->widget
->allocation
.x
+= dx
;
942 child
->widget
->allocation
.y
+= dy
;
944 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
945 GTK_IS_CONTAINER (child
->widget
))
947 gtk_container_forall (GTK_CONTAINER (child
->widget
),
948 gtk_pizza_adjust_allocations_recurse
,
956 gtk_pizza_position_child (GtkPizza
*pizza
,
957 GtkPizzaChild
*child
)
962 x
= child
->x
- pizza
->xoffset
;
963 y
= child
->y
- pizza
->yoffset
;
965 if (IS_ONSCREEN (x
,y
))
967 if (GTK_WIDGET_MAPPED (pizza
) &&
968 GTK_WIDGET_VISIBLE (child
->widget
))
970 if (!GTK_WIDGET_MAPPED (child
->widget
))
971 gtk_widget_map (child
->widget
);
974 if (GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
975 GTK_PRIVATE_UNSET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
979 if (!GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
980 GTK_PRIVATE_SET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
982 if (GTK_WIDGET_MAPPED (child
->widget
))
983 gtk_widget_unmap (child
->widget
);
988 gtk_pizza_position_children (GtkPizza
*pizza
)
992 tmp_list
= pizza
->children
;
995 GtkPizzaChild
*child
= tmp_list
->data
;
996 tmp_list
= tmp_list
->next
;
998 gtk_pizza_position_child (pizza
, child
);
1002 /* This function is used to find events to process while scrolling */
1004 gtk_pizza_expose_predicate (Display
*display
,
1008 if ((xevent
->type
== Expose
) ||
1009 ((xevent
->xany
.window
== *(Window
*)arg
) &&
1010 (xevent
->type
== ConfigureNotify
)))
1015 #endif /* __WXGTK20__ */
1017 /* This is the main routine to do the scrolling. Scrolling is
1018 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
1019 * a few modifications.
1021 * The main improvement is that we keep track of whether we
1022 * are obscured or not. If not, we ignore the generated expose
1023 * events and instead do the exposes ourself, without having
1024 * to wait for a roundtrip to the server. This also provides
1025 * a limited form of expose-event compression, since we do
1026 * the affected area as one big chunk.
1030 gtk_pizza_scroll (GtkPizza
*pizza
, gint dx
, gint dy
)
1033 pizza
->xoffset
+= dx
;
1034 pizza
->yoffset
+= dy
;
1036 gtk_pizza_adjust_allocations (pizza
, -dx
, -dy
);
1038 if (pizza
->bin_window
)
1039 gdk_window_scroll( pizza
->bin_window
, -dx
, -dy
);
1045 gint x
,y
,w
,h
,border
;
1047 widget
= GTK_WIDGET (pizza
);
1049 pizza
->xoffset
+= dx
;
1050 pizza
->yoffset
+= dy
;
1052 if (!GTK_WIDGET_MAPPED (pizza
))
1054 gtk_pizza_position_children (pizza
);
1058 gtk_pizza_adjust_allocations (pizza
, -dx
, -dy
);
1060 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
1063 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
1070 w
= widget
->allocation
.width
- 2*border
;
1071 h
= widget
->allocation
.height
- 2*border
;
1077 gdk_window_resize (pizza
->bin_window
,
1080 gdk_window_move (pizza
->bin_window
, x
-dx
, y
);
1081 gdk_window_move_resize (pizza
->bin_window
, x
, y
, w
, h
);
1092 gdk_window_move_resize (pizza
->bin_window
,
1097 gdk_window_move (pizza
->bin_window
, x
, y
);
1098 gdk_window_resize (pizza
->bin_window
, w
, h
);
1110 gdk_window_resize (pizza
->bin_window
, w
, h
+ dy
);
1111 gdk_window_move (pizza
->bin_window
, x
, y
-dy
);
1112 gdk_window_move_resize (pizza
->bin_window
,
1124 gdk_window_move_resize (pizza
->bin_window
,
1125 x
, y
+dy
, w
, h
- dy
);
1126 gdk_window_move (pizza
->bin_window
, x
, y
);
1127 gdk_window_resize (pizza
->bin_window
, w
, h
);
1135 gtk_pizza_position_children (pizza
);
1139 win
= GDK_WINDOW_XWINDOW (pizza
->bin_window
);
1140 while (XCheckIfEvent(GDK_WINDOW_XDISPLAY (pizza
->bin_window
),
1142 gtk_pizza_expose_predicate
,
1146 GtkWidget
*event_widget
;
1148 if ((xevent
.xany
.window
== GDK_WINDOW_XWINDOW (pizza
->bin_window
)) )
1149 gtk_pizza_filter (&xevent
, &event
, pizza
);
1151 if (xevent
.type
== Expose
)
1153 event
.expose
.window
= gdk_window_lookup (xevent
.xany
.window
);
1154 gdk_window_get_user_data (event
.expose
.window
,
1155 (gpointer
*)&event_widget
);
1159 event
.expose
.type
= GDK_EXPOSE
;
1160 event
.expose
.area
.x
= xevent
.xexpose
.x
;
1161 event
.expose
.area
.y
= xevent
.xexpose
.y
;
1162 event
.expose
.area
.width
= xevent
.xexpose
.width
;
1163 event
.expose
.area
.height
= xevent
.xexpose
.height
;
1164 event
.expose
.count
= xevent
.xexpose
.count
;
1166 gdk_window_ref (event
.expose
.window
);
1167 gtk_widget_event (event_widget
, &event
);
1168 gdk_window_unref (event
.expose
.window
);
1172 #endif /* __WXGTK20__ */
1177 /* The main event filter. Actually, we probably don't really need
1178 * to install this as a filter at all, since we are calling it
1179 * directly above in the expose-handling hack. But in case scrollbars
1180 * are fixed up in some manner...
1182 * This routine identifies expose events that are generated when
1183 * we've temporarily moved the bin_window_origin, and translates
1184 * them or discards them, depending on whether we are obscured
1187 static GdkFilterReturn
1188 gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
1195 xevent
= (XEvent
*)gdk_xevent
;
1197 pizza
= GTK_PIZZA (data
);
1199 if (!pizza
->use_filter
)
1200 return GDK_FILTER_CONTINUE
;
1202 switch (xevent
->type
)
1205 if (xevent
->xexpose
.serial
== pizza
->configure_serial
)
1207 xevent
->xexpose
.x
+= pizza
->scroll_x
;
1208 xevent
->xexpose
.y
+= pizza
->scroll_y
;
1212 case ConfigureNotify
:
1214 pizza
->configure_serial
= xevent
->xconfigure
.serial
;
1215 pizza
->scroll_x
= xevent
->xconfigure
.x
;
1216 pizza
->scroll_y
= xevent
->xconfigure
.y
;
1221 return GDK_FILTER_CONTINUE
;
1224 /* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
1225 * there is no corresponding event in GTK, so we have
1226 * to get the events from a filter
1228 static GdkFilterReturn
1229 gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
1236 xevent
= (XEvent
*)gdk_xevent
;
1237 pizza
= GTK_PIZZA (data
);
1239 if (!pizza
->use_filter
)
1240 return GDK_FILTER_CONTINUE
;
1242 if (xevent
->type
== VisibilityNotify
)
1244 switch (xevent
->xvisibility
.state
)
1246 case VisibilityFullyObscured
:
1247 pizza
->visibility
= GDK_VISIBILITY_FULLY_OBSCURED
;
1250 case VisibilityPartiallyObscured
:
1251 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
1254 case VisibilityUnobscured
:
1255 pizza
->visibility
= GDK_VISIBILITY_UNOBSCURED
;
1259 return GDK_FILTER_REMOVE
;
1262 return GDK_FILTER_CONTINUE
;
1264 #endif /* __WXGTK20__ */
1269 #endif /* __cplusplus */