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
);
71 static void gtk_pizza_allocate_child (GtkPizza
*pizza
,
72 GtkPizzaChild
*child
);
74 static void gtk_pizza_position_child (GtkPizza
*pizza
,
75 GtkPizzaChild
*child
);
77 static void gtk_pizza_position_children (GtkPizza
*pizza
);
79 static void gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
81 static void gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
84 static GdkFilterReturn
gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
87 static GdkFilterReturn
gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
90 #endif /* __WXGTK20__ */
92 static GtkType
gtk_pizza_child_type (GtkContainer
*container
);
94 static void gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
100 GtkContainerClass
*pizza_parent_class
= NULL
;
102 static GtkContainerClass
*pizza_parent_class
= NULL
;
105 static gboolean gravity_works
;
108 gtk_pizza_get_type ()
110 static guint pizza_type
= 0;
116 static const GTypeInfo pizza_info
=
118 sizeof (GtkPizzaClass
),
119 NULL
, /* base_init */
120 NULL
, /* base_finalize */
121 (GClassInitFunc
) gtk_pizza_class_init
,
122 NULL
, /* class_finalize */
123 NULL
, /* class_data */
125 16, /* n_preallocs */
126 (GInstanceInitFunc
) gtk_pizza_init
,
128 pizza_type
= g_type_register_static (GTK_TYPE_CONTAINER
, "GtkPizza", &pizza_info
, 0);
130 GtkTypeInfo pizza_info
=
134 sizeof (GtkPizzaClass
),
135 (GtkClassInitFunc
) gtk_pizza_class_init
,
136 (GtkObjectInitFunc
) gtk_pizza_init
,
137 /* reserved_1 */ NULL
,
138 /* reserved_2 */ NULL
,
139 (GtkClassInitFunc
) NULL
,
141 pizza_type
= gtk_type_unique (gtk_container_get_type (), &pizza_info
);
149 gtk_pizza_class_init (GtkPizzaClass
*klass
)
151 GtkObjectClass
*object_class
;
152 GtkWidgetClass
*widget_class
;
153 GtkContainerClass
*container_class
;
155 object_class
= (GtkObjectClass
*) klass
;
156 widget_class
= (GtkWidgetClass
*) klass
;
157 container_class
= (GtkContainerClass
*) klass
;
158 pizza_parent_class
= gtk_type_class (GTK_TYPE_CONTAINER
);
160 widget_class
->map
= gtk_pizza_map
;
161 widget_class
->realize
= gtk_pizza_realize
;
162 widget_class
->unrealize
= gtk_pizza_unrealize
;
163 widget_class
->size_request
= gtk_pizza_size_request
;
164 widget_class
->size_allocate
= gtk_pizza_size_allocate
;
166 widget_class
->draw
= gtk_pizza_draw
;
168 widget_class
->expose_event
= gtk_pizza_expose
;
170 container_class
->add
= gtk_pizza_add
;
171 container_class
->remove
= gtk_pizza_remove
;
172 container_class
->forall
= gtk_pizza_forall
;
174 container_class
->child_type
= gtk_pizza_child_type
;
176 klass
->set_scroll_adjustments
= gtk_pizza_scroll_set_adjustments
;
178 widget_class
->set_scroll_adjustments_signal
=
179 gtk_signal_new ("set_scroll_adjustments",
182 GTK_CLASS_TYPE(object_class
),
186 GTK_SIGNAL_OFFSET (GtkPizzaClass
, set_scroll_adjustments
),
187 gtk_marshal_NONE__POINTER_POINTER
,
188 GTK_TYPE_NONE
, 2, GTK_TYPE_ADJUSTMENT
, GTK_TYPE_ADJUSTMENT
);
192 gtk_pizza_child_type (GtkContainer
*container
)
194 return GTK_TYPE_WIDGET
;
198 gtk_pizza_init (GtkPizza
*pizza
)
200 GTK_WIDGET_UNSET_FLAGS (pizza
, GTK_NO_WINDOW
);
202 pizza
->shadow_type
= GTK_MYSHADOW_NONE
;
204 pizza
->children
= NULL
;
209 pizza
->bin_window
= NULL
;
214 pizza
->configure_serial
= 0;
217 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
219 pizza
->clear_on_draw
= TRUE
;
220 pizza
->use_filter
= TRUE
;
221 pizza
->external_expose
= FALSE
;
229 pizza
= gtk_type_new (gtk_pizza_get_type ());
231 return GTK_WIDGET (pizza
);
235 gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
239 /* We handle scrolling in the wxScrolledWindow, not here. */
243 gtk_pizza_set_shadow_type (GtkPizza
*pizza
,
244 GtkMyShadowType type
)
246 g_return_if_fail (pizza
!= NULL
);
247 g_return_if_fail (GTK_IS_PIZZA (pizza
));
249 if ((GtkMyShadowType
) pizza
->shadow_type
!= type
)
251 pizza
->shadow_type
= type
;
253 if (GTK_WIDGET_VISIBLE (pizza
))
255 gtk_widget_size_allocate (GTK_WIDGET (pizza
), &(GTK_WIDGET (pizza
)->allocation
));
256 gtk_widget_queue_draw (GTK_WIDGET (pizza
));
262 gtk_pizza_set_clear (GtkPizza
*pizza
,
265 g_return_if_fail (pizza
!= NULL
);
266 g_return_if_fail (GTK_IS_PIZZA (pizza
));
268 pizza
->clear_on_draw
= clear
;
272 gtk_pizza_set_filter (GtkPizza
*pizza
,
275 g_return_if_fail (pizza
!= NULL
);
276 g_return_if_fail (GTK_IS_PIZZA (pizza
));
278 pizza
->use_filter
= use
;
282 gtk_pizza_set_external (GtkPizza
*pizza
,
285 g_return_if_fail (pizza
!= NULL
);
286 g_return_if_fail (GTK_IS_PIZZA (pizza
));
288 pizza
->external_expose
= expose
;
292 gtk_pizza_put (GtkPizza
*pizza
,
299 GtkPizzaChild
*child_info
;
301 g_return_if_fail (pizza
!= NULL
);
302 g_return_if_fail (GTK_IS_PIZZA (pizza
));
303 g_return_if_fail (widget
!= NULL
);
305 child_info
= g_new (GtkPizzaChild
, 1);
307 child_info
->widget
= widget
;
310 child_info
->width
= width
;
311 child_info
->height
= height
;
313 pizza
->children
= g_list_append (pizza
->children
, child_info
);
315 gtk_widget_set_parent (widget
, GTK_WIDGET (pizza
));
317 if (GTK_WIDGET_REALIZED (pizza
))
318 gtk_widget_set_parent_window (widget
, pizza
->bin_window
);
320 #ifndef __WXGTK20__ /* FIXME? */
321 if (!IS_ONSCREEN (x
, y
))
322 GTK_PRIVATE_SET_FLAG (widget
, GTK_IS_OFFSCREEN
);
325 gtk_widget_set_usize (widget
, width
, height
);
329 gtk_pizza_move (GtkPizza
*pizza
,
334 GtkPizzaChild
*child
;
337 g_return_if_fail (pizza
!= NULL
);
338 g_return_if_fail (GTK_IS_PIZZA (pizza
));
339 g_return_if_fail (widget
!= NULL
);
341 children
= pizza
->children
;
344 child
= children
->data
;
345 children
= children
->next
;
347 if (child
->widget
== widget
)
349 if ((child
->x
== x
) && (child
->y
== y
))
355 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
356 gtk_widget_queue_resize (widget
);
363 gtk_pizza_resize (GtkPizza
*pizza
,
368 GtkPizzaChild
*child
;
371 g_return_if_fail (pizza
!= NULL
);
372 g_return_if_fail (GTK_IS_PIZZA (pizza
));
373 g_return_if_fail (widget
!= NULL
);
375 children
= pizza
->children
;
378 child
= children
->data
;
379 children
= children
->next
;
381 if (child
->widget
== widget
)
383 if ((child
->width
== width
) && (child
->height
== height
))
386 child
->width
= width
;
387 child
->height
= height
;
389 gtk_widget_set_usize (widget
, width
, height
);
391 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
392 gtk_widget_queue_resize (widget
);
399 gtk_pizza_set_size (GtkPizza
*pizza
,
406 GtkPizzaChild
*child
;
409 g_return_if_fail (pizza
!= NULL
);
410 g_return_if_fail (GTK_IS_PIZZA (pizza
));
411 g_return_if_fail (widget
!= NULL
);
413 children
= pizza
->children
;
416 child
= children
->data
;
417 children
= children
->next
;
419 if (child
->widget
== widget
)
421 if ((child
->x
== x
) &&
423 (child
->width
== width
) &&
424 (child
->height
== height
)) return;
428 child
->width
= width
;
429 child
->height
= height
;
431 gtk_widget_set_usize (widget
, width
, height
);
433 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
434 gtk_widget_queue_resize (widget
);
442 gtk_pizza_child_resized (GtkPizza
*pizza
,
445 GtkPizzaChild
*child
;
448 g_return_val_if_fail (pizza
!= NULL
, FALSE
);
449 g_return_val_if_fail (GTK_IS_PIZZA (pizza
), FALSE
);
450 g_return_val_if_fail (widget
!= NULL
, FALSE
);
452 children
= pizza
->children
;
455 child
= children
->data
;
456 children
= children
->next
;
458 if (child
->widget
== widget
)
460 return ((child
->width
== widget
->allocation
.width
) &&
461 (child
->height
== widget
->allocation
.height
));
469 gtk_pizza_map (GtkWidget
*widget
)
472 GtkPizzaChild
*child
;
475 g_return_if_fail (widget
!= NULL
);
476 g_return_if_fail (GTK_IS_PIZZA (widget
));
478 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
479 pizza
= GTK_PIZZA (widget
);
481 children
= pizza
->children
;
484 child
= children
->data
;
485 children
= children
->next
;
487 if ( GTK_WIDGET_VISIBLE (child
->widget
) &&
488 !GTK_WIDGET_MAPPED (child
->widget
) &&
492 !GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
495 gtk_widget_map (child
->widget
);
499 gdk_window_show (widget
->window
);
500 gdk_window_show (pizza
->bin_window
);
504 gtk_pizza_realize (GtkWidget
*widget
)
507 GdkWindowAttr attributes
;
508 gint attributes_mask
;
509 GtkPizzaChild
*child
;
512 g_return_if_fail (widget
!= NULL
);
513 g_return_if_fail (GTK_IS_PIZZA (widget
));
515 pizza
= GTK_PIZZA (widget
);
516 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
518 attributes
.window_type
= GDK_WINDOW_CHILD
;
520 attributes
.x
= widget
->allocation
.x
;
521 attributes
.y
= widget
->allocation
.y
;
522 attributes
.width
= widget
->allocation
.width
;
523 attributes
.height
= widget
->allocation
.height
;
525 #ifndef __WXUNIVERSAL__
526 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
528 /* no border, no changes to sizes */
530 else if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
532 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
535 attributes
.width
-= 2;
536 attributes
.height
-= 2;
540 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
541 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
544 attributes
.width
-= 4;
545 attributes
.height
-= 4;
547 #endif /* __WXUNIVERSAL__ */
550 if (attributes
.width
< 2) attributes
.width
= 2;
551 if (attributes
.height
< 2) attributes
.height
= 2;
553 attributes
.wclass
= GDK_INPUT_OUTPUT
;
554 attributes
.visual
= gtk_widget_get_visual (widget
);
555 attributes
.colormap
= gtk_widget_get_colormap (widget
);
556 attributes
.event_mask
= GDK_VISIBILITY_NOTIFY_MASK
;
557 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
559 widget
->window
= gdk_window_new(gtk_widget_get_parent_window (widget
),
560 &attributes
, attributes_mask
);
561 gdk_window_set_user_data (widget
->window
, widget
);
566 attributes
.event_mask
= gtk_widget_get_events (widget
);
567 attributes
.event_mask
|= GDK_EXPOSURE_MASK
|
571 GDK_POINTER_MOTION_MASK
|
572 GDK_POINTER_MOTION_HINT_MASK
|
573 GDK_BUTTON_MOTION_MASK
|
574 GDK_BUTTON1_MOTION_MASK
|
575 GDK_BUTTON2_MOTION_MASK
|
576 GDK_BUTTON3_MOTION_MASK
|
577 GDK_BUTTON_PRESS_MASK
|
578 GDK_BUTTON_RELEASE_MASK
|
580 GDK_KEY_RELEASE_MASK
|
581 GDK_ENTER_NOTIFY_MASK
|
582 GDK_LEAVE_NOTIFY_MASK
|
583 GDK_FOCUS_CHANGE_MASK
;
585 pizza
->bin_window
= gdk_window_new(widget
->window
,
586 &attributes
, attributes_mask
);
587 gdk_window_set_user_data (pizza
->bin_window
, widget
);
589 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
590 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
591 gtk_style_set_background (widget
->style
, pizza
->bin_window
, GTK_STATE_NORMAL
);
594 gdk_window_set_back_pixmap( widget->window, NULL, FALSE );
595 gdk_window_set_back_pixmap( pizza->bin_window, NULL, FALSE );
599 /* add filters for intercepting visibility and expose events */
600 gdk_window_add_filter (widget
->window
, gtk_pizza_main_filter
, pizza
);
601 gdk_window_add_filter (pizza
->bin_window
, gtk_pizza_filter
, pizza
);
604 /* we NEED gravity or we'll give up */
605 gravity_works
= gdk_window_set_static_gravities (pizza
->bin_window
, TRUE
);
607 /* cannot be done before realisation */
608 children
= pizza
->children
;
611 child
= children
->data
;
612 children
= children
->next
;
614 gtk_widget_set_parent_window (child
->widget
, pizza
->bin_window
);
619 gtk_pizza_unrealize (GtkWidget
*widget
)
623 g_return_if_fail (widget
!= NULL
);
624 g_return_if_fail (GTK_IS_PIZZA (widget
));
626 pizza
= GTK_PIZZA (widget
);
628 gdk_window_set_user_data (pizza
->bin_window
, NULL
);
629 gdk_window_destroy (pizza
->bin_window
);
630 pizza
->bin_window
= NULL
;
632 if (GTK_WIDGET_CLASS (pizza_parent_class
)->unrealize
)
633 (* GTK_WIDGET_CLASS (pizza_parent_class
)->unrealize
) (widget
);
637 gtk_pizza_size_request (GtkWidget
*widget
,
638 GtkRequisition
*requisition
)
641 GtkPizzaChild
*child
;
643 GtkRequisition child_requisition
;
645 g_return_if_fail (widget
!= NULL
);
646 g_return_if_fail (GTK_IS_PIZZA (widget
));
647 g_return_if_fail (requisition
!= NULL
);
649 pizza
= GTK_PIZZA (widget
);
651 children
= pizza
->children
;
654 child
= children
->data
;
655 children
= children
->next
;
657 if (GTK_WIDGET_VISIBLE (child
->widget
))
659 gtk_widget_size_request (child
->widget
, &child_requisition
);
663 /* request very little, I'm not sure if requesting nothing
664 will always have positive effects on stability... */
665 requisition
->width
= 2;
666 requisition
->height
= 2;
670 gtk_pizza_size_allocate (GtkWidget
*widget
,
671 GtkAllocation
*allocation
)
676 GtkPizzaChild
*child
;
679 g_return_if_fail (widget
!= NULL
);
680 g_return_if_fail (GTK_IS_PIZZA(widget
));
681 g_return_if_fail (allocation
!= NULL
);
683 pizza
= GTK_PIZZA (widget
);
685 widget
->allocation
= *allocation
;
687 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
690 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
695 x
= allocation
->x
+ border
;
696 y
= allocation
->y
+ border
;
697 w
= allocation
->width
- border
*2;
698 h
= allocation
->height
- border
*2;
700 if (GTK_WIDGET_REALIZED (widget
))
702 gdk_window_move_resize( widget
->window
, x
, y
, w
, h
);
703 gdk_window_move_resize( pizza
->bin_window
, 0, 0, w
, h
);
706 children
= pizza
->children
;
709 child
= children
->data
;
710 children
= children
->next
;
712 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
)
762 GtkPizzaChild
*child
;
763 GdkEventExpose child_event
;
766 g_return_val_if_fail (widget
!= NULL
, FALSE
);
767 g_return_val_if_fail (GTK_IS_PIZZA (widget
), FALSE
);
768 g_return_val_if_fail (event
!= NULL
, FALSE
);
770 pizza
= GTK_PIZZA (widget
);
772 if (event
->window
!= pizza
->bin_window
)
775 /* We handle all expose events in window.cpp now. */
776 if (pizza
->external_expose
)
781 (* GTK_WIDGET_CLASS (pizza_parent_class
)->expose_event
) (widget
, event
);
787 children
= pizza
->children
;
790 child
= children
->data
;
791 children
= children
->next
;
793 child_event
= *event
;
795 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
796 GTK_WIDGET_DRAWABLE (child
->widget
) &&
797 gtk_widget_intersect (child
->widget
, &event
->area
, &child_event
.area
))
799 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
809 gtk_pizza_add (GtkContainer
*container
,
812 g_return_if_fail (container
!= NULL
);
813 g_return_if_fail (GTK_IS_PIZZA (container
));
814 g_return_if_fail (widget
!= NULL
);
816 gtk_pizza_put (GTK_PIZZA (container
), widget
, 0, 0, 20, 20 );
820 gtk_pizza_remove (GtkContainer
*container
,
824 GtkPizzaChild
*child
;
827 g_return_if_fail (container
!= NULL
);
828 g_return_if_fail (GTK_IS_PIZZA (container
));
829 g_return_if_fail (widget
!= NULL
);
831 pizza
= GTK_PIZZA (container
);
833 children
= pizza
->children
;
836 child
= children
->data
;
838 if (child
->widget
== widget
)
840 gtk_widget_unparent (widget
);
842 /* security checks */
843 g_return_if_fail (GTK_IS_WIDGET (widget
));
845 pizza
->children
= g_list_remove_link (pizza
->children
, children
);
846 g_list_free (children
);
849 /* security checks */
850 g_return_if_fail (GTK_IS_WIDGET (widget
));
853 GTK_PRIVATE_UNSET_FLAG (widget
, GTK_IS_OFFSCREEN
);
859 children
= children
->next
;
864 gtk_pizza_forall (GtkContainer
*container
,
865 gboolean include_internals
,
866 GtkCallback callback
,
867 gpointer callback_data
)
870 GtkPizzaChild
*child
;
873 g_return_if_fail (container
!= NULL
);
874 g_return_if_fail (GTK_IS_PIZZA (container
));
875 g_return_if_fail (callback
!= (GtkCallback
)NULL
);
877 pizza
= GTK_PIZZA (container
);
879 children
= pizza
->children
;
882 child
= children
->data
;
883 children
= children
->next
;
885 (* callback
) (child
->widget
, callback_data
);
890 gtk_pizza_allocate_child (GtkPizza
*pizza
,
891 GtkPizzaChild
*child
)
893 GtkAllocation allocation
;
894 GtkRequisition requisition
;
896 allocation
.x
= child
->x
- pizza
->xoffset
;
897 allocation
.y
= child
->y
- pizza
->yoffset
;
898 gtk_widget_get_child_requisition (child
->widget
, &requisition
);
899 allocation
.width
= requisition
.width
;
900 allocation
.height
= requisition
.height
;
902 gtk_widget_size_allocate (child
->widget
, &allocation
);
906 gtk_pizza_position_child (GtkPizza
*pizza
,
907 GtkPizzaChild
*child
)
912 x
= child
->x
- pizza
->xoffset
;
913 y
= child
->y
- pizza
->yoffset
;
916 if (IS_ONSCREEN (x
,y
))
918 if (GTK_WIDGET_MAPPED (pizza
) &&
919 GTK_WIDGET_VISIBLE (child
->widget
))
921 if (!GTK_WIDGET_MAPPED (child
->widget
))
922 gtk_widget_map (child
->widget
);
925 if (GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
926 GTK_PRIVATE_UNSET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
930 if (!GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
931 GTK_PRIVATE_SET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
933 if (GTK_WIDGET_MAPPED (child
->widget
))
934 gtk_widget_unmap (child
->widget
);
942 gtk_pizza_position_children (GtkPizza
*pizza
)
946 tmp_list
= pizza
->children
;
949 GtkPizzaChild
*child
= tmp_list
->data
;
950 tmp_list
= tmp_list
->next
;
952 gtk_pizza_position_child (pizza
, child
);
957 gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
960 GtkPizzaAdjData
*data
= cb_data
;
962 widget
->allocation
.x
+= data
->dx
;
963 widget
->allocation
.y
+= data
->dy
;
965 if (GTK_WIDGET_NO_WINDOW (widget
) && GTK_IS_CONTAINER (widget
))
967 gtk_container_forall (GTK_CONTAINER (widget
),
968 gtk_pizza_adjust_allocations_recurse
,
974 gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
979 GtkPizzaAdjData data
;
984 tmp_list
= pizza
->children
;
987 GtkPizzaChild
*child
= tmp_list
->data
;
988 tmp_list
= tmp_list
->next
;
990 child
->widget
->allocation
.x
+= dx
;
991 child
->widget
->allocation
.y
+= dy
;
993 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
994 GTK_IS_CONTAINER (child
->widget
))
996 gtk_container_forall (GTK_CONTAINER (child
->widget
),
997 gtk_pizza_adjust_allocations_recurse
,
1003 /* This function is used to find events to process while scrolling */
1006 gtk_pizza_expose_predicate (Display
*display
,
1010 if ((xevent
->type
== Expose
) ||
1011 ((xevent
->xany
.window
== *(Window
*)arg
) &&
1012 (xevent
->type
== ConfigureNotify
)))
1018 /* This is the main routine to do the scrolling. Scrolling is
1019 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
1020 * a few modifications.
1022 * The main improvement is that we keep track of whether we
1023 * are obscured or not. If not, we ignore the generated expose
1024 * events and instead do the exposes ourself, without having
1025 * to wait for a roundtrip to the server. This also provides
1026 * a limited form of expose-event compression, since we do
1027 * the affected area as one big chunk.
1031 gtk_pizza_scroll (GtkPizza
*pizza
, gint dx
, gint dy
)
1037 gint x
,y
,w
,h
,border
;
1039 widget
= GTK_WIDGET (pizza
);
1041 pizza
->xoffset
+= dx
;
1042 pizza
->yoffset
+= dy
;
1044 if (!GTK_WIDGET_MAPPED (pizza
))
1046 gtk_pizza_position_children (pizza
);
1050 gtk_pizza_adjust_allocations (pizza
, -dx
, -dy
);
1052 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
1055 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
1062 w
= widget
->allocation
.width
- 2*border
;
1063 h
= widget
->allocation
.height
- 2*border
;
1069 gdk_window_resize (pizza
->bin_window
,
1072 gdk_window_move (pizza
->bin_window
, x
-dx
, y
);
1073 gdk_window_move_resize (pizza
->bin_window
, x
, y
, w
, h
);
1084 gdk_window_move_resize (pizza
->bin_window
,
1089 gdk_window_move (pizza
->bin_window
, x
, y
);
1090 gdk_window_resize (pizza
->bin_window
, w
, h
);
1102 gdk_window_resize (pizza
->bin_window
, w
, h
+ dy
);
1103 gdk_window_move (pizza
->bin_window
, x
, y
-dy
);
1104 gdk_window_move_resize (pizza
->bin_window
,
1116 gdk_window_move_resize (pizza
->bin_window
,
1117 x
, y
+dy
, w
, h
- dy
);
1118 gdk_window_move (pizza
->bin_window
, x
, y
);
1119 gdk_window_resize (pizza
->bin_window
, w
, h
);
1127 gtk_pizza_position_children (pizza
);
1131 win
= GDK_WINDOW_XWINDOW (pizza
->bin_window
);
1132 while (XCheckIfEvent(GDK_WINDOW_XDISPLAY (pizza
->bin_window
),
1134 gtk_pizza_expose_predicate
,
1138 GtkWidget
*event_widget
;
1140 if ((xevent
.xany
.window
== GDK_WINDOW_XWINDOW (pizza
->bin_window
)) )
1141 gtk_pizza_filter (&xevent
, &event
, pizza
);
1143 if (xevent
.type
== Expose
)
1145 event
.expose
.window
= gdk_window_lookup (xevent
.xany
.window
);
1146 gdk_window_get_user_data (event
.expose
.window
,
1147 (gpointer
*)&event_widget
);
1151 event
.expose
.type
= GDK_EXPOSE
;
1152 event
.expose
.area
.x
= xevent
.xexpose
.x
;
1153 event
.expose
.area
.y
= xevent
.xexpose
.y
;
1154 event
.expose
.area
.width
= xevent
.xexpose
.width
;
1155 event
.expose
.area
.height
= xevent
.xexpose
.height
;
1156 event
.expose
.count
= xevent
.xexpose
.count
;
1158 gdk_window_ref (event
.expose
.window
);
1159 gtk_widget_event (event_widget
, &event
);
1160 gdk_window_unref (event
.expose
.window
);
1166 /* The main event filter. Actually, we probably don't really need
1167 * to install this as a filter at all, since we are calling it
1168 * directly above in the expose-handling hack. But in case scrollbars
1169 * are fixed up in some manner...
1171 * This routine identifies expose events that are generated when
1172 * we've temporarily moved the bin_window_origin, and translates
1173 * them or discards them, depending on whether we are obscured
1176 static GdkFilterReturn
1177 gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
1184 xevent
= (XEvent
*)gdk_xevent
;
1186 pizza
= GTK_PIZZA (data
);
1188 if (!pizza
->use_filter
)
1189 return GDK_FILTER_CONTINUE
;
1191 switch (xevent
->type
)
1194 if (xevent
->xexpose
.serial
== pizza
->configure_serial
)
1196 xevent
->xexpose
.x
+= pizza
->scroll_x
;
1197 xevent
->xexpose
.y
+= pizza
->scroll_y
;
1201 case ConfigureNotify
:
1203 pizza
->configure_serial
= xevent
->xconfigure
.serial
;
1204 pizza
->scroll_x
= xevent
->xconfigure
.x
;
1205 pizza
->scroll_y
= xevent
->xconfigure
.y
;
1210 return GDK_FILTER_CONTINUE
;
1213 /* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
1214 * there is no corresponding event in GTK, so we have
1215 * to get the events from a filter
1217 static GdkFilterReturn
1218 gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
1225 xevent
= (XEvent
*)gdk_xevent
;
1226 pizza
= GTK_PIZZA (data
);
1228 if (!pizza
->use_filter
)
1229 return GDK_FILTER_CONTINUE
;
1231 if (xevent
->type
== VisibilityNotify
)
1233 switch (xevent
->xvisibility
.state
)
1235 case VisibilityFullyObscured
:
1236 pizza
->visibility
= GDK_VISIBILITY_FULLY_OBSCURED
;
1239 case VisibilityPartiallyObscured
:
1240 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
1243 case VisibilityUnobscured
:
1244 pizza
->visibility
= GDK_VISIBILITY_UNOBSCURED
;
1248 return GDK_FILTER_REMOVE
;
1251 return GDK_FILTER_CONTINUE
;
1254 #endif /* __WXGTK20__ */
1259 #endif /* __cplusplus */