1 /* ///////////////////////////////////////////////////////////////////////////
3 // Purpose: Native GTK+ widget for wxWidgets, 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: wxWidgets 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_style_set (GtkWidget
*widget
,
64 GtkStyle
*previous_style
);
65 static void gtk_pizza_add (GtkContainer
*container
,
67 static void gtk_pizza_remove (GtkContainer
*container
,
69 static void gtk_pizza_forall (GtkContainer
*container
,
70 gboolean include_internals
,
72 gpointer callback_data
);
74 static void gtk_pizza_allocate_child (GtkPizza
*pizza
,
75 GtkPizzaChild
*child
);
76 static void gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
80 static void gtk_pizza_position_child (GtkPizza
*pizza
,
81 GtkPizzaChild
*child
);
82 static void gtk_pizza_position_children (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
;
169 widget_class
->style_set
= gtk_pizza_style_set
;
171 container_class
->add
= gtk_pizza_add
;
172 container_class
->remove
= gtk_pizza_remove
;
173 container_class
->forall
= gtk_pizza_forall
;
175 container_class
->child_type
= gtk_pizza_child_type
;
177 klass
->set_scroll_adjustments
= gtk_pizza_scroll_set_adjustments
;
179 widget_class
->set_scroll_adjustments_signal
=
180 gtk_signal_new ("set_scroll_adjustments",
183 GTK_CLASS_TYPE(object_class
),
187 GTK_SIGNAL_OFFSET (GtkPizzaClass
, set_scroll_adjustments
),
188 gtk_marshal_NONE__POINTER_POINTER
,
189 GTK_TYPE_NONE
, 2, GTK_TYPE_ADJUSTMENT
, GTK_TYPE_ADJUSTMENT
);
193 gtk_pizza_child_type (GtkContainer
*container
)
195 return GTK_TYPE_WIDGET
;
199 gtk_pizza_init (GtkPizza
*pizza
)
201 GTK_WIDGET_UNSET_FLAGS (pizza
, GTK_NO_WINDOW
);
203 pizza
->shadow_type
= GTK_MYSHADOW_NONE
;
205 pizza
->children
= NULL
;
210 pizza
->bin_window
= NULL
;
215 pizza
->configure_serial
= 0;
218 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
220 pizza
->clear_on_draw
= TRUE
;
221 pizza
->use_filter
= TRUE
;
222 pizza
->external_expose
= FALSE
;
230 pizza
= gtk_type_new (gtk_pizza_get_type ());
232 return GTK_WIDGET (pizza
);
236 gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
240 /* We handle scrolling in the wxScrolledWindow, not here. */
244 gtk_pizza_set_shadow_type (GtkPizza
*pizza
,
245 GtkMyShadowType type
)
247 g_return_if_fail (pizza
!= NULL
);
248 g_return_if_fail (GTK_IS_PIZZA (pizza
));
250 if ((GtkMyShadowType
) pizza
->shadow_type
!= type
)
252 pizza
->shadow_type
= type
;
254 if (GTK_WIDGET_VISIBLE (pizza
))
256 gtk_widget_size_allocate (GTK_WIDGET (pizza
), &(GTK_WIDGET (pizza
)->allocation
));
257 gtk_widget_queue_draw (GTK_WIDGET (pizza
));
263 gtk_pizza_set_clear (GtkPizza
*pizza
,
266 g_return_if_fail (pizza
!= NULL
);
267 g_return_if_fail (GTK_IS_PIZZA (pizza
));
269 pizza
->clear_on_draw
= clear
;
273 gtk_pizza_set_filter (GtkPizza
*pizza
,
276 g_return_if_fail (pizza
!= NULL
);
277 g_return_if_fail (GTK_IS_PIZZA (pizza
));
279 pizza
->use_filter
= use
;
283 gtk_pizza_set_external (GtkPizza
*pizza
,
286 g_return_if_fail (pizza
!= NULL
);
287 g_return_if_fail (GTK_IS_PIZZA (pizza
));
289 pizza
->external_expose
= expose
;
293 gtk_pizza_put (GtkPizza
*pizza
,
300 GtkPizzaChild
*child_info
;
302 g_return_if_fail (pizza
!= NULL
);
303 g_return_if_fail (GTK_IS_PIZZA (pizza
));
304 g_return_if_fail (widget
!= NULL
);
306 child_info
= g_new (GtkPizzaChild
, 1);
308 child_info
->widget
= widget
;
311 child_info
->width
= width
;
312 child_info
->height
= height
;
314 pizza
->children
= g_list_append (pizza
->children
, child_info
);
316 if (GTK_WIDGET_REALIZED (pizza
))
317 gtk_widget_set_parent_window (widget
, pizza
->bin_window
);
319 gtk_widget_set_parent (widget
, GTK_WIDGET (pizza
));
321 #ifndef __WXGTK20__ /* FIXME? */
322 if (!IS_ONSCREEN (x
, y
))
323 GTK_PRIVATE_SET_FLAG (widget
, GTK_IS_OFFSCREEN
);
326 gtk_widget_set_usize (widget
, width
, height
);
330 gtk_pizza_move (GtkPizza
*pizza
,
335 GtkPizzaChild
*child
;
338 g_return_if_fail (pizza
!= NULL
);
339 g_return_if_fail (GTK_IS_PIZZA (pizza
));
340 g_return_if_fail (widget
!= NULL
);
342 children
= pizza
->children
;
345 child
= children
->data
;
346 children
= children
->next
;
348 if (child
->widget
== widget
)
350 if ((child
->x
== x
) && (child
->y
== y
))
356 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
357 gtk_widget_queue_resize (widget
);
364 gtk_pizza_resize (GtkPizza
*pizza
,
369 GtkPizzaChild
*child
;
372 g_return_if_fail (pizza
!= NULL
);
373 g_return_if_fail (GTK_IS_PIZZA (pizza
));
374 g_return_if_fail (widget
!= NULL
);
376 children
= pizza
->children
;
379 child
= children
->data
;
380 children
= children
->next
;
382 if (child
->widget
== widget
)
384 if ((child
->width
== width
) && (child
->height
== height
))
387 child
->width
= width
;
388 child
->height
= height
;
390 gtk_widget_set_usize (widget
, width
, height
);
392 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
393 gtk_widget_queue_resize (widget
);
400 gtk_pizza_set_size (GtkPizza
*pizza
,
407 GtkPizzaChild
*child
;
410 g_return_if_fail (pizza
!= NULL
);
411 g_return_if_fail (GTK_IS_PIZZA (pizza
));
412 g_return_if_fail (widget
!= NULL
);
414 children
= pizza
->children
;
417 child
= children
->data
;
418 children
= children
->next
;
420 if (child
->widget
== widget
)
422 if ((child
->x
== x
) &&
424 (child
->width
== width
) &&
425 (child
->height
== height
)) return;
429 child
->width
= width
;
430 child
->height
= height
;
432 gtk_widget_set_usize (widget
, width
, height
);
434 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
435 gtk_widget_queue_resize (widget
);
443 gtk_pizza_child_resized (GtkPizza
*pizza
,
446 GtkPizzaChild
*child
;
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
);
453 children
= pizza
->children
;
456 child
= children
->data
;
457 children
= children
->next
;
459 if (child
->widget
== widget
)
461 return ((child
->width
== widget
->allocation
.width
) &&
462 (child
->height
== widget
->allocation
.height
));
470 gtk_pizza_map (GtkWidget
*widget
)
473 GtkPizzaChild
*child
;
476 g_return_if_fail (widget
!= NULL
);
477 g_return_if_fail (GTK_IS_PIZZA (widget
));
479 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
480 pizza
= GTK_PIZZA (widget
);
482 children
= pizza
->children
;
485 child
= children
->data
;
486 children
= children
->next
;
488 if ( GTK_WIDGET_VISIBLE (child
->widget
) &&
489 !GTK_WIDGET_MAPPED (child
->widget
) &&
493 !GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
496 gtk_widget_map (child
->widget
);
500 gdk_window_show (widget
->window
);
501 gdk_window_show (pizza
->bin_window
);
505 gtk_pizza_realize (GtkWidget
*widget
)
508 GdkWindowAttr attributes
;
509 gint attributes_mask
;
510 GtkPizzaChild
*child
;
513 g_return_if_fail (widget
!= NULL
);
514 g_return_if_fail (GTK_IS_PIZZA (widget
));
516 pizza
= GTK_PIZZA (widget
);
517 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
519 attributes
.window_type
= GDK_WINDOW_CHILD
;
521 attributes
.x
= widget
->allocation
.x
;
522 attributes
.y
= widget
->allocation
.y
;
523 attributes
.width
= widget
->allocation
.width
;
524 attributes
.height
= widget
->allocation
.height
;
526 #ifndef __WXUNIVERSAL__
527 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
529 /* no border, no changes to sizes */
531 else if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
533 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
536 attributes
.width
-= 2;
537 attributes
.height
-= 2;
541 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
542 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
545 attributes
.width
-= 4;
546 attributes
.height
-= 4;
548 #endif /* __WXUNIVERSAL__ */
551 if (attributes
.width
< 2) attributes
.width
= 2;
552 if (attributes
.height
< 2) attributes
.height
= 2;
554 attributes
.wclass
= GDK_INPUT_OUTPUT
;
555 attributes
.visual
= gtk_widget_get_visual (widget
);
556 attributes
.colormap
= gtk_widget_get_colormap (widget
);
557 attributes
.event_mask
= GDK_VISIBILITY_NOTIFY_MASK
;
558 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
560 widget
->window
= gdk_window_new(gtk_widget_get_parent_window (widget
),
561 &attributes
, attributes_mask
);
562 gdk_window_set_user_data (widget
->window
, widget
);
567 attributes
.event_mask
= gtk_widget_get_events (widget
);
568 attributes
.event_mask
|= GDK_EXPOSURE_MASK
|
572 GDK_POINTER_MOTION_MASK
|
573 GDK_POINTER_MOTION_HINT_MASK
|
574 GDK_BUTTON_MOTION_MASK
|
575 GDK_BUTTON1_MOTION_MASK
|
576 GDK_BUTTON2_MOTION_MASK
|
577 GDK_BUTTON3_MOTION_MASK
|
578 GDK_BUTTON_PRESS_MASK
|
579 GDK_BUTTON_RELEASE_MASK
|
581 GDK_KEY_RELEASE_MASK
|
582 GDK_ENTER_NOTIFY_MASK
|
583 GDK_LEAVE_NOTIFY_MASK
|
584 GDK_FOCUS_CHANGE_MASK
;
586 pizza
->bin_window
= gdk_window_new(widget
->window
,
587 &attributes
, attributes_mask
);
588 gdk_window_set_user_data (pizza
->bin_window
, widget
);
590 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
591 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
592 gtk_style_set_background (widget
->style
, pizza
->bin_window
, GTK_STATE_NORMAL
);
595 gdk_window_set_back_pixmap( widget->window, NULL, FALSE );
596 gdk_window_set_back_pixmap( pizza->bin_window, NULL, FALSE );
600 /* add filters for intercepting visibility and expose events */
601 gdk_window_add_filter (widget
->window
, gtk_pizza_main_filter
, pizza
);
602 gdk_window_add_filter (pizza
->bin_window
, gtk_pizza_filter
, pizza
);
605 /* we NEED gravity or we'll give up */
606 gravity_works
= gdk_window_set_static_gravities (pizza
->bin_window
, TRUE
);
608 /* cannot be done before realisation */
609 children
= pizza
->children
;
612 child
= children
->data
;
613 children
= children
->next
;
615 gtk_widget_set_parent_window (child
->widget
, pizza
->bin_window
);
620 gtk_pizza_unrealize (GtkWidget
*widget
)
624 g_return_if_fail (widget
!= NULL
);
625 g_return_if_fail (GTK_IS_PIZZA (widget
));
627 pizza
= GTK_PIZZA (widget
);
629 gdk_window_set_user_data (pizza
->bin_window
, NULL
);
630 gdk_window_destroy (pizza
->bin_window
);
631 pizza
->bin_window
= NULL
;
633 if (GTK_WIDGET_CLASS (pizza_parent_class
)->unrealize
)
634 (* GTK_WIDGET_CLASS (pizza_parent_class
)->unrealize
) (widget
);
638 gtk_pizza_size_request (GtkWidget
*widget
,
639 GtkRequisition
*requisition
)
642 GtkPizzaChild
*child
;
644 GtkRequisition child_requisition
;
646 g_return_if_fail (widget
!= NULL
);
647 g_return_if_fail (GTK_IS_PIZZA (widget
));
648 g_return_if_fail (requisition
!= NULL
);
650 pizza
= GTK_PIZZA (widget
);
652 children
= pizza
->children
;
655 child
= children
->data
;
656 children
= children
->next
;
658 if (GTK_WIDGET_VISIBLE (child
->widget
))
660 gtk_widget_size_request (child
->widget
, &child_requisition
);
664 /* request very little, I'm not sure if requesting nothing
665 will always have positive effects on stability... */
666 requisition
->width
= 2;
667 requisition
->height
= 2;
671 gtk_pizza_size_allocate (GtkWidget
*widget
,
672 GtkAllocation
*allocation
)
677 GtkPizzaChild
*child
;
680 g_return_if_fail (widget
!= NULL
);
681 g_return_if_fail (GTK_IS_PIZZA(widget
));
682 g_return_if_fail (allocation
!= NULL
);
684 pizza
= GTK_PIZZA (widget
);
686 widget
->allocation
= *allocation
;
688 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
691 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
696 x
= allocation
->x
+ border
;
697 y
= allocation
->y
+ border
;
698 w
= allocation
->width
- border
*2;
699 h
= allocation
->height
- border
*2;
701 if (GTK_WIDGET_REALIZED (widget
))
703 gdk_window_move_resize( widget
->window
, x
, y
, w
, h
);
704 gdk_window_move_resize( pizza
->bin_window
, 0, 0, w
, h
);
707 children
= pizza
->children
;
710 child
= children
->data
;
711 children
= children
->next
;
714 gtk_pizza_position_child (pizza
, child
);
716 gtk_pizza_allocate_child (pizza
, child
);
723 gtk_pizza_draw (GtkWidget
*widget
,
727 GtkPizzaChild
*child
;
728 GdkRectangle child_area
;
731 g_return_if_fail (widget
!= NULL
);
732 g_return_if_fail (GTK_IS_PIZZA (widget
));
734 pizza
= GTK_PIZZA (widget
);
736 /* Sometimes, We handle all expose events in window.cpp now. */
737 if (pizza
->external_expose
)
740 children
= pizza
->children
;
741 if ( !(GTK_WIDGET_APP_PAINTABLE (widget
)) &&
742 (pizza
->clear_on_draw
))
744 gdk_window_clear_area( pizza
->bin_window
,
745 area
->x
, area
->y
, area
->width
, area
->height
);
750 child
= children
->data
;
751 children
= children
->next
;
753 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
754 gtk_widget_draw (child
->widget
, &child_area
);
758 #endif /* __WXGTK20__ */
761 gtk_pizza_expose (GtkWidget
*widget
,
762 GdkEventExpose
*event
)
766 GtkPizzaChild
*child
;
767 GdkEventExpose child_event
;
771 g_return_val_if_fail (widget
!= NULL
, FALSE
);
772 g_return_val_if_fail (GTK_IS_PIZZA (widget
), FALSE
);
773 g_return_val_if_fail (event
!= NULL
, FALSE
);
775 pizza
= GTK_PIZZA (widget
);
777 if (event
->window
!= pizza
->bin_window
)
780 /* We handle all expose events in window.cpp now. */
781 if (pizza
->external_expose
)
786 (* GTK_WIDGET_CLASS (pizza_parent_class
)->expose_event
) (widget
, event
);
792 children
= pizza
->children
;
795 child
= children
->data
;
796 children
= children
->next
;
798 child_event
= *event
;
800 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
801 GTK_WIDGET_DRAWABLE (child
->widget
) &&
802 gtk_widget_intersect (child
->widget
, &event
->area
, &child_event
.area
))
804 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
814 gtk_pizza_style_set(GtkWidget
*widget
, GtkStyle
*previous_style
)
816 if (GTK_WIDGET_REALIZED(widget
))
818 gtk_style_set_background(widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
819 gtk_style_set_background(widget
->style
, GTK_PIZZA(widget
)->bin_window
, GTK_STATE_NORMAL
);
822 (* GTK_WIDGET_CLASS (pizza_parent_class
)->style_set
) (widget
, previous_style
);
826 gtk_pizza_add (GtkContainer
*container
,
829 g_return_if_fail (container
!= NULL
);
830 g_return_if_fail (GTK_IS_PIZZA (container
));
831 g_return_if_fail (widget
!= NULL
);
833 gtk_pizza_put (GTK_PIZZA (container
), widget
, 0, 0, 20, 20 );
837 gtk_pizza_remove (GtkContainer
*container
,
841 GtkPizzaChild
*child
;
844 g_return_if_fail (container
!= NULL
);
845 g_return_if_fail (GTK_IS_PIZZA (container
));
846 g_return_if_fail (widget
!= NULL
);
848 pizza
= GTK_PIZZA (container
);
850 children
= pizza
->children
;
853 child
= children
->data
;
855 if (child
->widget
== widget
)
857 gtk_widget_unparent (widget
);
859 /* security checks */
860 g_return_if_fail (GTK_IS_WIDGET (widget
));
862 pizza
->children
= g_list_remove_link (pizza
->children
, children
);
863 g_list_free (children
);
866 /* security checks */
867 g_return_if_fail (GTK_IS_WIDGET (widget
));
870 GTK_PRIVATE_UNSET_FLAG (widget
, GTK_IS_OFFSCREEN
);
876 children
= children
->next
;
881 gtk_pizza_forall (GtkContainer
*container
,
882 gboolean include_internals
,
883 GtkCallback callback
,
884 gpointer callback_data
)
887 GtkPizzaChild
*child
;
890 g_return_if_fail (container
!= NULL
);
891 g_return_if_fail (GTK_IS_PIZZA (container
));
892 g_return_if_fail (callback
!= (GtkCallback
)NULL
);
894 pizza
= GTK_PIZZA (container
);
896 children
= pizza
->children
;
899 child
= children
->data
;
900 children
= children
->next
;
902 (* callback
) (child
->widget
, callback_data
);
907 gtk_pizza_allocate_child (GtkPizza
*pizza
,
908 GtkPizzaChild
*child
)
910 GtkAllocation allocation
;
911 GtkRequisition requisition
;
913 allocation
.x
= child
->x
- pizza
->xoffset
;
914 allocation
.y
= child
->y
- pizza
->yoffset
;
915 gtk_widget_get_child_requisition (child
->widget
, &requisition
);
916 allocation
.width
= requisition
.width
;
917 allocation
.height
= requisition
.height
;
919 gtk_widget_size_allocate (child
->widget
, &allocation
);
923 gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
926 GtkPizzaAdjData
*data
= cb_data
;
928 widget
->allocation
.x
+= data
->dx
;
929 widget
->allocation
.y
+= data
->dy
;
931 if (GTK_WIDGET_NO_WINDOW (widget
) && GTK_IS_CONTAINER (widget
))
933 gtk_container_forall (GTK_CONTAINER (widget
),
934 gtk_pizza_adjust_allocations_recurse
,
940 gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
945 GtkPizzaAdjData data
;
950 tmp_list
= pizza
->children
;
953 GtkPizzaChild
*child
= tmp_list
->data
;
954 tmp_list
= tmp_list
->next
;
956 child
->widget
->allocation
.x
+= dx
;
957 child
->widget
->allocation
.y
+= dy
;
959 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
960 GTK_IS_CONTAINER (child
->widget
))
962 gtk_container_forall (GTK_CONTAINER (child
->widget
),
963 gtk_pizza_adjust_allocations_recurse
,
971 gtk_pizza_position_child (GtkPizza
*pizza
,
972 GtkPizzaChild
*child
)
977 x
= child
->x
- pizza
->xoffset
;
978 y
= child
->y
- pizza
->yoffset
;
980 if (IS_ONSCREEN (x
,y
))
982 if (GTK_WIDGET_MAPPED (pizza
) &&
983 GTK_WIDGET_VISIBLE (child
->widget
))
985 if (!GTK_WIDGET_MAPPED (child
->widget
))
986 gtk_widget_map (child
->widget
);
989 if (GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
990 GTK_PRIVATE_UNSET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
994 if (!GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
995 GTK_PRIVATE_SET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
997 if (GTK_WIDGET_MAPPED (child
->widget
))
998 gtk_widget_unmap (child
->widget
);
1003 gtk_pizza_position_children (GtkPizza
*pizza
)
1007 tmp_list
= pizza
->children
;
1010 GtkPizzaChild
*child
= tmp_list
->data
;
1011 tmp_list
= tmp_list
->next
;
1013 gtk_pizza_position_child (pizza
, child
);
1017 /* This function is used to find events to process while scrolling */
1019 gtk_pizza_expose_predicate (Display
*display
,
1023 if ((xevent
->type
== Expose
) ||
1024 ((xevent
->xany
.window
== *(Window
*)arg
) &&
1025 (xevent
->type
== ConfigureNotify
)))
1030 #endif /* __WXGTK20__ */
1032 /* This is the main routine to do the scrolling. Scrolling is
1033 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
1034 * a few modifications.
1036 * The main improvement is that we keep track of whether we
1037 * are obscured or not. If not, we ignore the generated expose
1038 * events and instead do the exposes ourself, without having
1039 * to wait for a roundtrip to the server. This also provides
1040 * a limited form of expose-event compression, since we do
1041 * the affected area as one big chunk.
1045 gtk_pizza_scroll (GtkPizza
*pizza
, gint dx
, gint dy
)
1048 pizza
->xoffset
+= dx
;
1049 pizza
->yoffset
+= dy
;
1051 gtk_pizza_adjust_allocations (pizza
, -dx
, -dy
);
1053 if (pizza
->bin_window
)
1054 gdk_window_scroll( pizza
->bin_window
, -dx
, -dy
);
1060 gint x
,y
,w
,h
,border
;
1062 widget
= GTK_WIDGET (pizza
);
1064 pizza
->xoffset
+= dx
;
1065 pizza
->yoffset
+= dy
;
1067 if (!GTK_WIDGET_MAPPED (pizza
))
1069 gtk_pizza_position_children (pizza
);
1073 gtk_pizza_adjust_allocations (pizza
, -dx
, -dy
);
1075 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
1078 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
1085 w
= widget
->allocation
.width
- 2*border
;
1086 h
= widget
->allocation
.height
- 2*border
;
1092 gdk_window_resize (pizza
->bin_window
,
1095 gdk_window_move (pizza
->bin_window
, x
-dx
, y
);
1096 gdk_window_move_resize (pizza
->bin_window
, x
, y
, w
, h
);
1107 gdk_window_move_resize (pizza
->bin_window
,
1112 gdk_window_move (pizza
->bin_window
, x
, y
);
1113 gdk_window_resize (pizza
->bin_window
, w
, h
);
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
,
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
);
1150 gtk_pizza_position_children (pizza
);
1154 win
= GDK_WINDOW_XWINDOW (pizza
->bin_window
);
1155 while (XCheckIfEvent(GDK_WINDOW_XDISPLAY (pizza
->bin_window
),
1157 gtk_pizza_expose_predicate
,
1161 GtkWidget
*event_widget
;
1163 if ((xevent
.xany
.window
== GDK_WINDOW_XWINDOW (pizza
->bin_window
)) )
1164 gtk_pizza_filter (&xevent
, &event
, pizza
);
1166 if (xevent
.type
== Expose
)
1168 event
.expose
.window
= gdk_window_lookup (xevent
.xany
.window
);
1169 gdk_window_get_user_data (event
.expose
.window
,
1170 (gpointer
*)&event_widget
);
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
;
1181 gdk_window_ref (event
.expose
.window
);
1182 gtk_widget_event (event_widget
, &event
);
1183 gdk_window_unref (event
.expose
.window
);
1187 #endif /* __WXGTK20__ */
1192 /* The main event filter. Actually, we probably don't really need
1193 * to install this as a filter at all, since we are calling it
1194 * directly above in the expose-handling hack. But in case scrollbars
1195 * are fixed up in some manner...
1197 * This routine identifies expose events that are generated when
1198 * we've temporarily moved the bin_window_origin, and translates
1199 * them or discards them, depending on whether we are obscured
1202 static GdkFilterReturn
1203 gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
1210 xevent
= (XEvent
*)gdk_xevent
;
1212 pizza
= GTK_PIZZA (data
);
1214 if (!pizza
->use_filter
)
1215 return GDK_FILTER_CONTINUE
;
1217 switch (xevent
->type
)
1220 if (xevent
->xexpose
.serial
== pizza
->configure_serial
)
1222 xevent
->xexpose
.x
+= pizza
->scroll_x
;
1223 xevent
->xexpose
.y
+= pizza
->scroll_y
;
1227 case ConfigureNotify
:
1229 pizza
->configure_serial
= xevent
->xconfigure
.serial
;
1230 pizza
->scroll_x
= xevent
->xconfigure
.x
;
1231 pizza
->scroll_y
= xevent
->xconfigure
.y
;
1236 return GDK_FILTER_CONTINUE
;
1239 /* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
1240 * there is no corresponding event in GTK, so we have
1241 * to get the events from a filter
1243 static GdkFilterReturn
1244 gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
1251 xevent
= (XEvent
*)gdk_xevent
;
1252 pizza
= GTK_PIZZA (data
);
1254 if (!pizza
->use_filter
)
1255 return GDK_FILTER_CONTINUE
;
1257 if (xevent
->type
== VisibilityNotify
)
1259 switch (xevent
->xvisibility
.state
)
1261 case VisibilityFullyObscured
:
1262 pizza
->visibility
= GDK_VISIBILITY_FULLY_OBSCURED
;
1265 case VisibilityPartiallyObscured
:
1266 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
1269 case VisibilityUnobscured
:
1270 pizza
->visibility
= GDK_VISIBILITY_UNOBSCURED
;
1274 return GDK_FILTER_REMOVE
;
1277 return GDK_FILTER_CONTINUE
;
1279 #endif /* __WXGTK20__ */
1284 #endif /* __cplusplus */