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 GtkType 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 // Marshaller needed for set_scroll_adjustments signal,
150 // generated with GLib-2.4.6 glib-genmarshal
151 #define g_marshal_value_peek_object(v) g_value_get_object (v)
153 g_cclosure_user_marshal_VOID__OBJECT_OBJECT (GClosure
*closure
,
154 GValue
*return_value
,
155 guint n_param_values
,
156 const GValue
*param_values
,
157 gpointer invocation_hint
,
158 gpointer marshal_data
)
160 typedef void (*GMarshalFunc_VOID__OBJECT_OBJECT
) (gpointer data1
,
164 register GMarshalFunc_VOID__OBJECT_OBJECT callback
;
165 register GCClosure
*cc
= (GCClosure
*) closure
;
166 register gpointer data1
, data2
;
168 g_return_if_fail (n_param_values
== 3);
170 if (G_CCLOSURE_SWAP_DATA (closure
))
172 data1
= closure
->data
;
173 data2
= g_value_peek_pointer (param_values
+ 0);
177 data1
= g_value_peek_pointer (param_values
+ 0);
178 data2
= closure
->data
;
180 callback
= (GMarshalFunc_VOID__OBJECT_OBJECT
) (marshal_data
? marshal_data
: cc
->callback
);
183 g_marshal_value_peek_object (param_values
+ 1),
184 g_marshal_value_peek_object (param_values
+ 2),
187 #endif // __WXGTK20__
190 gtk_pizza_class_init (GtkPizzaClass
*klass
)
192 GtkObjectClass
*object_class
;
193 GtkWidgetClass
*widget_class
;
194 GtkContainerClass
*container_class
;
196 object_class
= (GtkObjectClass
*) klass
;
197 widget_class
= (GtkWidgetClass
*) klass
;
198 container_class
= (GtkContainerClass
*) klass
;
199 pizza_parent_class
= gtk_type_class (GTK_TYPE_CONTAINER
);
201 widget_class
->map
= gtk_pizza_map
;
202 widget_class
->realize
= gtk_pizza_realize
;
203 widget_class
->unrealize
= gtk_pizza_unrealize
;
204 widget_class
->size_request
= gtk_pizza_size_request
;
205 widget_class
->size_allocate
= gtk_pizza_size_allocate
;
207 widget_class
->draw
= gtk_pizza_draw
;
209 widget_class
->expose_event
= gtk_pizza_expose
;
210 widget_class
->style_set
= gtk_pizza_style_set
;
212 container_class
->add
= gtk_pizza_add
;
213 container_class
->remove
= gtk_pizza_remove
;
214 container_class
->forall
= gtk_pizza_forall
;
216 container_class
->child_type
= gtk_pizza_child_type
;
218 klass
->set_scroll_adjustments
= gtk_pizza_scroll_set_adjustments
;
220 widget_class
->set_scroll_adjustments_signal
=
223 "set_scroll_adjustments",
224 G_TYPE_FROM_CLASS(object_class
),
226 G_STRUCT_OFFSET(GtkPizzaClass
, set_scroll_adjustments
),
229 g_cclosure_user_marshal_VOID__OBJECT_OBJECT
,
233 GTK_TYPE_ADJUSTMENT
);
235 gtk_signal_new ("set_scroll_adjustments",
238 GTK_SIGNAL_OFFSET (GtkPizzaClass
, set_scroll_adjustments
),
239 gtk_marshal_NONE__POINTER_POINTER
,
240 GTK_TYPE_NONE
, 2, GTK_TYPE_ADJUSTMENT
, GTK_TYPE_ADJUSTMENT
);
241 #endif // __WXGTK20__
245 gtk_pizza_child_type (GtkContainer
*container
)
247 return GTK_TYPE_WIDGET
;
251 gtk_pizza_init (GtkPizza
*pizza
)
253 GTK_WIDGET_UNSET_FLAGS (pizza
, GTK_NO_WINDOW
);
255 pizza
->shadow_type
= GTK_MYSHADOW_NONE
;
257 pizza
->children
= NULL
;
262 pizza
->bin_window
= NULL
;
267 pizza
->configure_serial
= 0;
270 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
272 pizza
->clear_on_draw
= TRUE
;
273 pizza
->use_filter
= TRUE
;
274 pizza
->external_expose
= FALSE
;
282 pizza
= gtk_type_new (gtk_pizza_get_type ());
284 return GTK_WIDGET (pizza
);
288 gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
292 /* We handle scrolling in the wxScrolledWindow, not here. */
296 gtk_pizza_set_shadow_type (GtkPizza
*pizza
,
297 GtkMyShadowType type
)
299 g_return_if_fail (pizza
!= NULL
);
300 g_return_if_fail (GTK_IS_PIZZA (pizza
));
302 if ((GtkMyShadowType
) pizza
->shadow_type
!= type
)
304 pizza
->shadow_type
= type
;
306 if (GTK_WIDGET_VISIBLE (pizza
))
308 gtk_widget_size_allocate (GTK_WIDGET (pizza
), &(GTK_WIDGET (pizza
)->allocation
));
309 gtk_widget_queue_draw (GTK_WIDGET (pizza
));
315 gtk_pizza_set_clear (GtkPizza
*pizza
,
318 g_return_if_fail (pizza
!= NULL
);
319 g_return_if_fail (GTK_IS_PIZZA (pizza
));
321 pizza
->clear_on_draw
= clear
;
325 gtk_pizza_set_filter (GtkPizza
*pizza
,
328 g_return_if_fail (pizza
!= NULL
);
329 g_return_if_fail (GTK_IS_PIZZA (pizza
));
331 pizza
->use_filter
= use
;
335 gtk_pizza_set_external (GtkPizza
*pizza
,
338 g_return_if_fail (pizza
!= NULL
);
339 g_return_if_fail (GTK_IS_PIZZA (pizza
));
341 pizza
->external_expose
= expose
;
345 gtk_pizza_put (GtkPizza
*pizza
,
352 GtkPizzaChild
*child_info
;
354 g_return_if_fail (pizza
!= NULL
);
355 g_return_if_fail (GTK_IS_PIZZA (pizza
));
356 g_return_if_fail (widget
!= NULL
);
358 child_info
= g_new (GtkPizzaChild
, 1);
360 child_info
->widget
= widget
;
363 child_info
->width
= width
;
364 child_info
->height
= height
;
366 pizza
->children
= g_list_append (pizza
->children
, child_info
);
368 if (GTK_WIDGET_REALIZED (pizza
))
369 gtk_widget_set_parent_window (widget
, pizza
->bin_window
);
371 gtk_widget_set_parent (widget
, GTK_WIDGET (pizza
));
373 #ifndef __WXGTK20__ /* FIXME? */
374 if (!IS_ONSCREEN (x
, y
))
375 GTK_PRIVATE_SET_FLAG (widget
, GTK_IS_OFFSCREEN
);
378 gtk_widget_set_usize (widget
, width
, height
);
382 gtk_pizza_move (GtkPizza
*pizza
,
387 GtkPizzaChild
*child
;
390 g_return_if_fail (pizza
!= NULL
);
391 g_return_if_fail (GTK_IS_PIZZA (pizza
));
392 g_return_if_fail (widget
!= NULL
);
394 children
= pizza
->children
;
397 child
= children
->data
;
398 children
= children
->next
;
400 if (child
->widget
== widget
)
402 if ((child
->x
== x
) && (child
->y
== y
))
408 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
409 gtk_widget_queue_resize (widget
);
416 gtk_pizza_resize (GtkPizza
*pizza
,
421 GtkPizzaChild
*child
;
424 g_return_if_fail (pizza
!= NULL
);
425 g_return_if_fail (GTK_IS_PIZZA (pizza
));
426 g_return_if_fail (widget
!= NULL
);
428 children
= pizza
->children
;
431 child
= children
->data
;
432 children
= children
->next
;
434 if (child
->widget
== widget
)
436 if ((child
->width
== width
) && (child
->height
== height
))
439 child
->width
= width
;
440 child
->height
= height
;
442 gtk_widget_set_usize (widget
, width
, height
);
444 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
445 gtk_widget_queue_resize (widget
);
452 gtk_pizza_set_size (GtkPizza
*pizza
,
459 GtkPizzaChild
*child
;
462 g_return_if_fail (pizza
!= NULL
);
463 g_return_if_fail (GTK_IS_PIZZA (pizza
));
464 g_return_if_fail (widget
!= NULL
);
466 children
= pizza
->children
;
469 child
= children
->data
;
470 children
= children
->next
;
472 if (child
->widget
== widget
)
474 if ((child
->x
== x
) &&
476 (child
->width
== width
) &&
477 (child
->height
== height
)) return;
481 child
->width
= width
;
482 child
->height
= height
;
484 gtk_widget_set_usize (widget
, width
, height
);
486 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
487 gtk_widget_queue_resize (widget
);
495 gtk_pizza_child_resized (GtkPizza
*pizza
,
498 GtkPizzaChild
*child
;
501 g_return_val_if_fail (pizza
!= NULL
, FALSE
);
502 g_return_val_if_fail (GTK_IS_PIZZA (pizza
), FALSE
);
503 g_return_val_if_fail (widget
!= NULL
, FALSE
);
505 children
= pizza
->children
;
508 child
= children
->data
;
509 children
= children
->next
;
511 if (child
->widget
== widget
)
513 return ((child
->width
== widget
->allocation
.width
) &&
514 (child
->height
== widget
->allocation
.height
));
522 gtk_pizza_map (GtkWidget
*widget
)
525 GtkPizzaChild
*child
;
528 g_return_if_fail (widget
!= NULL
);
529 g_return_if_fail (GTK_IS_PIZZA (widget
));
531 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
532 pizza
= GTK_PIZZA (widget
);
534 children
= pizza
->children
;
537 child
= children
->data
;
538 children
= children
->next
;
540 if ( GTK_WIDGET_VISIBLE (child
->widget
) &&
541 !GTK_WIDGET_MAPPED (child
->widget
) &&
545 !GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
548 gtk_widget_map (child
->widget
);
552 gdk_window_show (widget
->window
);
553 gdk_window_show (pizza
->bin_window
);
557 gtk_pizza_realize (GtkWidget
*widget
)
560 GdkWindowAttr attributes
;
561 gint attributes_mask
;
562 GtkPizzaChild
*child
;
565 g_return_if_fail (widget
!= NULL
);
566 g_return_if_fail (GTK_IS_PIZZA (widget
));
568 pizza
= GTK_PIZZA (widget
);
569 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
571 attributes
.window_type
= GDK_WINDOW_CHILD
;
573 attributes
.x
= widget
->allocation
.x
;
574 attributes
.y
= widget
->allocation
.y
;
575 attributes
.width
= widget
->allocation
.width
;
576 attributes
.height
= widget
->allocation
.height
;
578 #ifndef __WXUNIVERSAL__
579 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
581 /* no border, no changes to sizes */
583 else if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
585 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
588 attributes
.width
-= 2;
589 attributes
.height
-= 2;
593 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
594 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
597 attributes
.width
-= 4;
598 attributes
.height
-= 4;
600 #endif /* __WXUNIVERSAL__ */
603 if (attributes
.width
< 2) attributes
.width
= 2;
604 if (attributes
.height
< 2) attributes
.height
= 2;
606 attributes
.wclass
= GDK_INPUT_OUTPUT
;
607 attributes
.visual
= gtk_widget_get_visual (widget
);
608 attributes
.colormap
= gtk_widget_get_colormap (widget
);
609 attributes
.event_mask
= GDK_VISIBILITY_NOTIFY_MASK
;
610 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
612 widget
->window
= gdk_window_new(gtk_widget_get_parent_window (widget
),
613 &attributes
, attributes_mask
);
614 gdk_window_set_user_data (widget
->window
, widget
);
619 attributes
.event_mask
= gtk_widget_get_events (widget
);
620 attributes
.event_mask
|= GDK_EXPOSURE_MASK
|
624 GDK_POINTER_MOTION_MASK
|
625 GDK_POINTER_MOTION_HINT_MASK
|
626 GDK_BUTTON_MOTION_MASK
|
627 GDK_BUTTON1_MOTION_MASK
|
628 GDK_BUTTON2_MOTION_MASK
|
629 GDK_BUTTON3_MOTION_MASK
|
630 GDK_BUTTON_PRESS_MASK
|
631 GDK_BUTTON_RELEASE_MASK
|
633 GDK_KEY_RELEASE_MASK
|
634 GDK_ENTER_NOTIFY_MASK
|
635 GDK_LEAVE_NOTIFY_MASK
|
636 GDK_FOCUS_CHANGE_MASK
;
638 pizza
->bin_window
= gdk_window_new(widget
->window
,
639 &attributes
, attributes_mask
);
640 gdk_window_set_user_data (pizza
->bin_window
, widget
);
642 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
643 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
644 gtk_style_set_background (widget
->style
, pizza
->bin_window
, GTK_STATE_NORMAL
);
647 gdk_window_set_back_pixmap( widget->window, NULL, FALSE );
648 gdk_window_set_back_pixmap( pizza->bin_window, NULL, FALSE );
652 /* add filters for intercepting visibility and expose events */
653 gdk_window_add_filter (widget
->window
, gtk_pizza_main_filter
, pizza
);
654 gdk_window_add_filter (pizza
->bin_window
, gtk_pizza_filter
, pizza
);
657 /* we NEED gravity or we'll give up */
658 gravity_works
= gdk_window_set_static_gravities (pizza
->bin_window
, TRUE
);
660 /* cannot be done before realisation */
661 children
= pizza
->children
;
664 child
= children
->data
;
665 children
= children
->next
;
667 gtk_widget_set_parent_window (child
->widget
, pizza
->bin_window
);
672 gtk_pizza_unrealize (GtkWidget
*widget
)
676 g_return_if_fail (widget
!= NULL
);
677 g_return_if_fail (GTK_IS_PIZZA (widget
));
679 pizza
= GTK_PIZZA (widget
);
681 gdk_window_set_user_data (pizza
->bin_window
, NULL
);
682 gdk_window_destroy (pizza
->bin_window
);
683 pizza
->bin_window
= NULL
;
685 if (GTK_WIDGET_CLASS (pizza_parent_class
)->unrealize
)
686 (* GTK_WIDGET_CLASS (pizza_parent_class
)->unrealize
) (widget
);
690 gtk_pizza_size_request (GtkWidget
*widget
,
691 GtkRequisition
*requisition
)
694 GtkPizzaChild
*child
;
696 GtkRequisition child_requisition
;
698 g_return_if_fail (widget
!= NULL
);
699 g_return_if_fail (GTK_IS_PIZZA (widget
));
700 g_return_if_fail (requisition
!= NULL
);
702 pizza
= GTK_PIZZA (widget
);
704 children
= pizza
->children
;
707 child
= children
->data
;
708 children
= children
->next
;
710 if (GTK_WIDGET_VISIBLE (child
->widget
))
712 gtk_widget_size_request (child
->widget
, &child_requisition
);
716 /* request very little, I'm not sure if requesting nothing
717 will always have positive effects on stability... */
718 requisition
->width
= 2;
719 requisition
->height
= 2;
723 gtk_pizza_size_allocate (GtkWidget
*widget
,
724 GtkAllocation
*allocation
)
729 GtkPizzaChild
*child
;
732 g_return_if_fail (widget
!= NULL
);
733 g_return_if_fail (GTK_IS_PIZZA(widget
));
734 g_return_if_fail (allocation
!= NULL
);
736 pizza
= GTK_PIZZA (widget
);
738 widget
->allocation
= *allocation
;
740 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
743 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
748 x
= allocation
->x
+ border
;
749 y
= allocation
->y
+ border
;
750 w
= allocation
->width
- border
*2;
751 h
= allocation
->height
- border
*2;
753 if (GTK_WIDGET_REALIZED (widget
))
755 gdk_window_move_resize( widget
->window
, x
, y
, w
, h
);
756 gdk_window_move_resize( pizza
->bin_window
, 0, 0, w
, h
);
759 children
= pizza
->children
;
762 child
= children
->data
;
763 children
= children
->next
;
766 gtk_pizza_position_child (pizza
, child
);
768 gtk_pizza_allocate_child (pizza
, child
);
775 gtk_pizza_draw (GtkWidget
*widget
,
779 GtkPizzaChild
*child
;
780 GdkRectangle child_area
;
783 g_return_if_fail (widget
!= NULL
);
784 g_return_if_fail (GTK_IS_PIZZA (widget
));
786 pizza
= GTK_PIZZA (widget
);
788 /* Sometimes, We handle all expose events in window.cpp now. */
789 if (pizza
->external_expose
)
792 children
= pizza
->children
;
793 if ( !(GTK_WIDGET_APP_PAINTABLE (widget
)) &&
794 (pizza
->clear_on_draw
))
796 gdk_window_clear_area( pizza
->bin_window
,
797 area
->x
, area
->y
, area
->width
, area
->height
);
802 child
= children
->data
;
803 children
= children
->next
;
805 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
806 gtk_widget_draw (child
->widget
, &child_area
);
810 #endif /* __WXGTK20__ */
813 gtk_pizza_expose (GtkWidget
*widget
,
814 GdkEventExpose
*event
)
818 GtkPizzaChild
*child
;
819 GdkEventExpose child_event
;
823 g_return_val_if_fail (widget
!= NULL
, FALSE
);
824 g_return_val_if_fail (GTK_IS_PIZZA (widget
), FALSE
);
825 g_return_val_if_fail (event
!= NULL
, FALSE
);
827 pizza
= GTK_PIZZA (widget
);
829 if (event
->window
!= pizza
->bin_window
)
832 /* We handle all expose events in window.cpp now. */
833 if (pizza
->external_expose
)
838 (* GTK_WIDGET_CLASS (pizza_parent_class
)->expose_event
) (widget
, event
);
844 children
= pizza
->children
;
847 child
= children
->data
;
848 children
= children
->next
;
850 child_event
= *event
;
852 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
853 GTK_WIDGET_DRAWABLE (child
->widget
) &&
854 gtk_widget_intersect (child
->widget
, &event
->area
, &child_event
.area
))
856 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
866 gtk_pizza_style_set(GtkWidget
*widget
, GtkStyle
*previous_style
)
868 if (GTK_WIDGET_REALIZED(widget
))
870 gtk_style_set_background(widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
871 gtk_style_set_background(widget
->style
, GTK_PIZZA(widget
)->bin_window
, GTK_STATE_NORMAL
);
874 (* GTK_WIDGET_CLASS (pizza_parent_class
)->style_set
) (widget
, previous_style
);
878 gtk_pizza_add (GtkContainer
*container
,
881 g_return_if_fail (container
!= NULL
);
882 g_return_if_fail (GTK_IS_PIZZA (container
));
883 g_return_if_fail (widget
!= NULL
);
885 gtk_pizza_put (GTK_PIZZA (container
), widget
, 0, 0, 20, 20 );
889 gtk_pizza_remove (GtkContainer
*container
,
893 GtkPizzaChild
*child
;
896 g_return_if_fail (container
!= NULL
);
897 g_return_if_fail (GTK_IS_PIZZA (container
));
898 g_return_if_fail (widget
!= NULL
);
900 pizza
= GTK_PIZZA (container
);
902 children
= pizza
->children
;
905 child
= children
->data
;
907 if (child
->widget
== widget
)
909 gtk_widget_unparent (widget
);
911 /* security checks */
912 g_return_if_fail (GTK_IS_WIDGET (widget
));
914 pizza
->children
= g_list_remove_link (pizza
->children
, children
);
915 g_list_free (children
);
918 /* security checks */
919 g_return_if_fail (GTK_IS_WIDGET (widget
));
922 GTK_PRIVATE_UNSET_FLAG (widget
, GTK_IS_OFFSCREEN
);
928 children
= children
->next
;
933 gtk_pizza_forall (GtkContainer
*container
,
934 gboolean include_internals
,
935 GtkCallback callback
,
936 gpointer callback_data
)
939 GtkPizzaChild
*child
;
942 g_return_if_fail (container
!= NULL
);
943 g_return_if_fail (GTK_IS_PIZZA (container
));
944 g_return_if_fail (callback
!= (GtkCallback
)NULL
);
946 pizza
= GTK_PIZZA (container
);
948 children
= pizza
->children
;
951 child
= children
->data
;
952 children
= children
->next
;
954 (* callback
) (child
->widget
, callback_data
);
959 gtk_pizza_allocate_child (GtkPizza
*pizza
,
960 GtkPizzaChild
*child
)
962 GtkAllocation allocation
;
963 GtkRequisition requisition
;
965 allocation
.x
= child
->x
- pizza
->xoffset
;
966 allocation
.y
= child
->y
- pizza
->yoffset
;
967 gtk_widget_get_child_requisition (child
->widget
, &requisition
);
968 allocation
.width
= requisition
.width
;
969 allocation
.height
= requisition
.height
;
971 gtk_widget_size_allocate (child
->widget
, &allocation
);
975 gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
978 GtkPizzaAdjData
*data
= cb_data
;
980 widget
->allocation
.x
+= data
->dx
;
981 widget
->allocation
.y
+= data
->dy
;
983 if (GTK_WIDGET_NO_WINDOW (widget
) && GTK_IS_CONTAINER (widget
))
985 gtk_container_forall (GTK_CONTAINER (widget
),
986 gtk_pizza_adjust_allocations_recurse
,
992 gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
997 GtkPizzaAdjData data
;
1002 tmp_list
= pizza
->children
;
1005 GtkPizzaChild
*child
= tmp_list
->data
;
1006 tmp_list
= tmp_list
->next
;
1008 child
->widget
->allocation
.x
+= dx
;
1009 child
->widget
->allocation
.y
+= dy
;
1011 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
1012 GTK_IS_CONTAINER (child
->widget
))
1014 gtk_container_forall (GTK_CONTAINER (child
->widget
),
1015 gtk_pizza_adjust_allocations_recurse
,
1023 gtk_pizza_position_child (GtkPizza
*pizza
,
1024 GtkPizzaChild
*child
)
1029 x
= child
->x
- pizza
->xoffset
;
1030 y
= child
->y
- pizza
->yoffset
;
1032 if (IS_ONSCREEN (x
,y
))
1034 if (GTK_WIDGET_MAPPED (pizza
) &&
1035 GTK_WIDGET_VISIBLE (child
->widget
))
1037 if (!GTK_WIDGET_MAPPED (child
->widget
))
1038 gtk_widget_map (child
->widget
);
1041 if (GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
1042 GTK_PRIVATE_UNSET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
1046 if (!GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
1047 GTK_PRIVATE_SET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
1049 if (GTK_WIDGET_MAPPED (child
->widget
))
1050 gtk_widget_unmap (child
->widget
);
1055 gtk_pizza_position_children (GtkPizza
*pizza
)
1059 tmp_list
= pizza
->children
;
1062 GtkPizzaChild
*child
= tmp_list
->data
;
1063 tmp_list
= tmp_list
->next
;
1065 gtk_pizza_position_child (pizza
, child
);
1069 /* This function is used to find events to process while scrolling */
1071 gtk_pizza_expose_predicate (Display
*display
,
1075 if ((xevent
->type
== Expose
) ||
1076 ((xevent
->xany
.window
== *(Window
*)arg
) &&
1077 (xevent
->type
== ConfigureNotify
)))
1082 #endif /* __WXGTK20__ */
1084 /* This is the main routine to do the scrolling. Scrolling is
1085 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
1086 * a few modifications.
1088 * The main improvement is that we keep track of whether we
1089 * are obscured or not. If not, we ignore the generated expose
1090 * events and instead do the exposes ourself, without having
1091 * to wait for a roundtrip to the server. This also provides
1092 * a limited form of expose-event compression, since we do
1093 * the affected area as one big chunk.
1097 gtk_pizza_scroll (GtkPizza
*pizza
, gint dx
, gint dy
)
1100 pizza
->xoffset
+= dx
;
1101 pizza
->yoffset
+= dy
;
1103 gtk_pizza_adjust_allocations (pizza
, -dx
, -dy
);
1105 if (pizza
->bin_window
)
1106 gdk_window_scroll( pizza
->bin_window
, -dx
, -dy
);
1112 gint x
,y
,w
,h
,border
;
1114 widget
= GTK_WIDGET (pizza
);
1116 pizza
->xoffset
+= dx
;
1117 pizza
->yoffset
+= dy
;
1119 if (!GTK_WIDGET_MAPPED (pizza
))
1121 gtk_pizza_position_children (pizza
);
1125 gtk_pizza_adjust_allocations (pizza
, -dx
, -dy
);
1127 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
1130 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
1137 w
= widget
->allocation
.width
- 2*border
;
1138 h
= widget
->allocation
.height
- 2*border
;
1144 gdk_window_resize (pizza
->bin_window
,
1147 gdk_window_move (pizza
->bin_window
, x
-dx
, y
);
1148 gdk_window_move_resize (pizza
->bin_window
, x
, y
, w
, h
);
1159 gdk_window_move_resize (pizza
->bin_window
,
1164 gdk_window_move (pizza
->bin_window
, x
, y
);
1165 gdk_window_resize (pizza
->bin_window
, w
, h
);
1177 gdk_window_resize (pizza
->bin_window
, w
, h
+ dy
);
1178 gdk_window_move (pizza
->bin_window
, x
, y
-dy
);
1179 gdk_window_move_resize (pizza
->bin_window
,
1191 gdk_window_move_resize (pizza
->bin_window
,
1192 x
, y
+dy
, w
, h
- dy
);
1193 gdk_window_move (pizza
->bin_window
, x
, y
);
1194 gdk_window_resize (pizza
->bin_window
, w
, h
);
1202 gtk_pizza_position_children (pizza
);
1206 win
= GDK_WINDOW_XWINDOW (pizza
->bin_window
);
1207 while (XCheckIfEvent(GDK_WINDOW_XDISPLAY (pizza
->bin_window
),
1209 gtk_pizza_expose_predicate
,
1213 GtkWidget
*event_widget
;
1215 if ((xevent
.xany
.window
== GDK_WINDOW_XWINDOW (pizza
->bin_window
)) )
1216 gtk_pizza_filter (&xevent
, &event
, pizza
);
1218 if (xevent
.type
== Expose
)
1220 event
.expose
.window
= gdk_window_lookup (xevent
.xany
.window
);
1221 gdk_window_get_user_data (event
.expose
.window
,
1222 (gpointer
*)&event_widget
);
1226 event
.expose
.type
= GDK_EXPOSE
;
1227 event
.expose
.area
.x
= xevent
.xexpose
.x
;
1228 event
.expose
.area
.y
= xevent
.xexpose
.y
;
1229 event
.expose
.area
.width
= xevent
.xexpose
.width
;
1230 event
.expose
.area
.height
= xevent
.xexpose
.height
;
1231 event
.expose
.count
= xevent
.xexpose
.count
;
1233 gdk_window_ref (event
.expose
.window
);
1234 gtk_widget_event (event_widget
, &event
);
1235 gdk_window_unref (event
.expose
.window
);
1239 #endif /* __WXGTK20__ */
1244 /* The main event filter. Actually, we probably don't really need
1245 * to install this as a filter at all, since we are calling it
1246 * directly above in the expose-handling hack. But in case scrollbars
1247 * are fixed up in some manner...
1249 * This routine identifies expose events that are generated when
1250 * we've temporarily moved the bin_window_origin, and translates
1251 * them or discards them, depending on whether we are obscured
1254 static GdkFilterReturn
1255 gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
1262 xevent
= (XEvent
*)gdk_xevent
;
1264 pizza
= GTK_PIZZA (data
);
1266 if (!pizza
->use_filter
)
1267 return GDK_FILTER_CONTINUE
;
1269 switch (xevent
->type
)
1272 if (xevent
->xexpose
.serial
== pizza
->configure_serial
)
1274 xevent
->xexpose
.x
+= pizza
->scroll_x
;
1275 xevent
->xexpose
.y
+= pizza
->scroll_y
;
1279 case ConfigureNotify
:
1281 pizza
->configure_serial
= xevent
->xconfigure
.serial
;
1282 pizza
->scroll_x
= xevent
->xconfigure
.x
;
1283 pizza
->scroll_y
= xevent
->xconfigure
.y
;
1288 return GDK_FILTER_CONTINUE
;
1291 /* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
1292 * there is no corresponding event in GTK, so we have
1293 * to get the events from a filter
1295 static GdkFilterReturn
1296 gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
1303 xevent
= (XEvent
*)gdk_xevent
;
1304 pizza
= GTK_PIZZA (data
);
1306 if (!pizza
->use_filter
)
1307 return GDK_FILTER_CONTINUE
;
1309 if (xevent
->type
== VisibilityNotify
)
1311 switch (xevent
->xvisibility
.state
)
1313 case VisibilityFullyObscured
:
1314 pizza
->visibility
= GDK_VISIBILITY_FULLY_OBSCURED
;
1317 case VisibilityPartiallyObscured
:
1318 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
1321 case VisibilityUnobscured
:
1322 pizza
->visibility
= GDK_VISIBILITY_UNOBSCURED
;
1326 return GDK_FILTER_REMOVE
;
1329 return GDK_FILTER_CONTINUE
;
1331 #endif /* __WXGTK20__ */
1336 #endif /* __cplusplus */