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 gtk_widget_get_child_requisition gtk_widget_get_child_requisitio
14 #define gtk_marshal_NONE__POINTER_POINTER gtk_marshal_NONE__POINTER_POINT
17 #include "wx/gtk/win_gtk.h"
18 #include "gtk/gtksignal.h"
19 #include "gtk/gtkprivate.h"
24 #endif /* __cplusplus */
27 #include <X11/Xutil.h>
28 #include <X11/Xatom.h>
30 #define IS_ONSCREEN(x,y) ((x >= G_MINSHORT) && (x <= G_MAXSHORT) && \
31 (y >= G_MINSHORT) && (y <= G_MAXSHORT))
33 typedef struct _GtkPizzaAdjData GtkPizzaAdjData
;
35 struct _GtkPizzaAdjData
41 static void gtk_pizza_class_init (GtkPizzaClass
*klass
);
42 static void gtk_pizza_init (GtkPizza
*pizza
);
44 static void gtk_pizza_realize (GtkWidget
*widget
);
45 static void gtk_pizza_unrealize (GtkWidget
*widget
);
47 static void gtk_pizza_map (GtkWidget
*widget
);
49 static void gtk_pizza_size_request (GtkWidget
*widget
,
50 GtkRequisition
*requisition
);
51 static void gtk_pizza_size_allocate (GtkWidget
*widget
,
52 GtkAllocation
*allocation
);
53 static void gtk_pizza_draw (GtkWidget
*widget
,
55 static gint
gtk_pizza_expose (GtkWidget
*widget
,
56 GdkEventExpose
*event
);
57 static void gtk_pizza_add (GtkContainer
*container
,
59 static void gtk_pizza_remove (GtkContainer
*container
,
61 static void gtk_pizza_forall (GtkContainer
*container
,
62 gboolean include_internals
,
64 gpointer callback_data
);
66 static void gtk_pizza_position_child (GtkPizza
*pizza
,
67 GtkPizzaChild
*child
);
68 static void gtk_pizza_allocate_child (GtkPizza
*pizza
,
69 GtkPizzaChild
*child
);
70 static void gtk_pizza_position_children (GtkPizza
*pizza
);
72 static void gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
74 static void gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
79 static void gtk_pizza_expose_area (GtkPizza
*pizza
,
84 static void gtk_pizza_adjustment_changed (GtkAdjustment
*adjustment
,
86 static GdkFilterReturn
gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
89 static GdkFilterReturn
gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
94 static GtkType
gtk_pizza_child_type (GtkContainer
*container
);
96 static void gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
101 static GtkContainerClass
*parent_class
= NULL
;
102 static gboolean gravity_works
;
105 gtk_pizza_get_type ()
107 static guint pizza_type
= 0;
111 GtkTypeInfo pizza_info
=
115 sizeof (GtkPizzaClass
),
116 (GtkClassInitFunc
) gtk_pizza_class_init
,
117 (GtkObjectInitFunc
) gtk_pizza_init
,
118 /* reserved_1 */ NULL
,
119 /* reserved_2 */ NULL
,
120 (GtkClassInitFunc
) NULL
,
122 pizza_type
= gtk_type_unique (gtk_container_get_type (), &pizza_info
);
129 gtk_pizza_class_init (GtkPizzaClass
*klass
)
131 GtkObjectClass
*object_class
;
132 GtkWidgetClass
*widget_class
;
133 GtkContainerClass
*container_class
;
135 object_class
= (GtkObjectClass
*) klass
;
136 widget_class
= (GtkWidgetClass
*) klass
;
137 container_class
= (GtkContainerClass
*) klass
;
138 parent_class
= gtk_type_class (GTK_TYPE_CONTAINER
);
140 widget_class
->map
= gtk_pizza_map
;
141 widget_class
->realize
= gtk_pizza_realize
;
142 widget_class
->unrealize
= gtk_pizza_unrealize
;
143 widget_class
->size_request
= gtk_pizza_size_request
;
144 widget_class
->size_allocate
= gtk_pizza_size_allocate
;
145 widget_class
->draw
= gtk_pizza_draw
;
146 widget_class
->expose_event
= gtk_pizza_expose
;
148 container_class
->add
= gtk_pizza_add
;
149 container_class
->remove
= gtk_pizza_remove
;
150 container_class
->forall
= gtk_pizza_forall
;
152 container_class
->child_type
= gtk_pizza_child_type
;
154 klass
->set_scroll_adjustments
= gtk_pizza_scroll_set_adjustments
;
156 widget_class
->set_scroll_adjustments_signal
=
157 gtk_signal_new ("set_scroll_adjustments",
160 GTK_SIGNAL_OFFSET (GtkPizzaClass
, set_scroll_adjustments
),
161 gtk_marshal_NONE__POINTER_POINTER
,
162 GTK_TYPE_NONE
, 2, GTK_TYPE_ADJUSTMENT
, GTK_TYPE_ADJUSTMENT
);
166 gtk_pizza_child_type (GtkContainer
*container
)
168 return GTK_TYPE_WIDGET
;
172 gtk_pizza_init (GtkPizza
*pizza
)
174 GTK_WIDGET_UNSET_FLAGS (pizza
, GTK_NO_WINDOW
);
176 pizza
->shadow_type
= GTK_MYSHADOW_NONE
;
178 pizza
->children
= NULL
;
183 pizza
->bin_window
= NULL
;
188 pizza
->configure_serial
= 0;
191 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
193 pizza
->clear_on_draw
= TRUE
;
194 pizza
->use_filter
= TRUE
;
195 pizza
->external_expose
= FALSE
;
203 pizza
= gtk_type_new (gtk_pizza_get_type ());
205 return GTK_WIDGET (pizza
);
209 gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
213 /* We handle scrolling in the wxScrolledWindow, not here. */
217 gtk_pizza_set_shadow_type (GtkPizza
*pizza
,
218 GtkMyShadowType type
)
220 g_return_if_fail (pizza
!= NULL
);
221 g_return_if_fail (GTK_IS_PIZZA (pizza
));
223 if ((GtkMyShadowType
) pizza
->shadow_type
!= type
)
225 pizza
->shadow_type
= type
;
227 if (GTK_WIDGET_VISIBLE (pizza
))
229 gtk_widget_size_allocate (GTK_WIDGET (pizza
), &(GTK_WIDGET (pizza
)->allocation
));
230 gtk_widget_queue_draw (GTK_WIDGET (pizza
));
236 gtk_pizza_set_clear (GtkPizza
*pizza
,
239 g_return_if_fail (pizza
!= NULL
);
240 g_return_if_fail (GTK_IS_PIZZA (pizza
));
242 pizza
->clear_on_draw
= clear
;
246 gtk_pizza_set_filter (GtkPizza
*pizza
,
249 g_return_if_fail (pizza
!= NULL
);
250 g_return_if_fail (GTK_IS_PIZZA (pizza
));
252 pizza
->use_filter
= use
;
256 gtk_pizza_set_external (GtkPizza
*pizza
,
259 g_return_if_fail (pizza
!= NULL
);
260 g_return_if_fail (GTK_IS_PIZZA (pizza
));
262 pizza
->external_expose
= expose
;
266 gtk_pizza_put (GtkPizza
*pizza
,
273 GtkPizzaChild
*child_info
;
275 g_return_if_fail (pizza
!= NULL
);
276 g_return_if_fail (GTK_IS_PIZZA (pizza
));
277 g_return_if_fail (widget
!= NULL
);
279 child_info
= g_new (GtkPizzaChild
, 1);
281 child_info
->widget
= widget
;
284 child_info
->width
= width
;
285 child_info
->height
= height
;
287 pizza
->children
= g_list_append (pizza
->children
, child_info
);
289 gtk_widget_set_parent (widget
, GTK_WIDGET (pizza
));
291 if (GTK_WIDGET_REALIZED (pizza
))
292 gtk_widget_set_parent_window (widget
, pizza
->bin_window
);
294 if (!IS_ONSCREEN (x
, y
))
295 GTK_PRIVATE_SET_FLAG (widget
, GTK_IS_OFFSCREEN
);
298 if (GTK_WIDGET_REALIZED (pizza))
299 gtk_widget_realize (widget);
302 gtk_widget_set_usize (widget
, width
, height
);
305 if (GTK_WIDGET_VISIBLE (pizza) && GTK_WIDGET_VISIBLE (widget))
307 if (GTK_WIDGET_MAPPED (pizza))
308 gtk_widget_map (widget);
310 gtk_widget_queue_resize (widget);
316 gtk_pizza_move (GtkPizza
*pizza
,
321 GtkPizzaChild
*child
;
324 g_return_if_fail (pizza
!= NULL
);
325 g_return_if_fail (GTK_IS_PIZZA (pizza
));
326 g_return_if_fail (widget
!= NULL
);
328 children
= pizza
->children
;
331 child
= children
->data
;
332 children
= children
->next
;
334 if (child
->widget
== widget
)
336 if ((child
->x
== x
) && (child
->y
== y
))
342 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
343 gtk_widget_queue_resize (widget
);
350 gtk_pizza_resize (GtkPizza
*pizza
,
355 GtkPizzaChild
*child
;
358 g_return_if_fail (pizza
!= NULL
);
359 g_return_if_fail (GTK_IS_PIZZA (pizza
));
360 g_return_if_fail (widget
!= NULL
);
362 children
= pizza
->children
;
365 child
= children
->data
;
366 children
= children
->next
;
368 if (child
->widget
== widget
)
370 if ((child
->width
== width
) && (child
->height
== height
))
373 child
->width
= width
;
374 child
->height
= height
;
376 gtk_widget_set_usize (widget
, width
, height
);
378 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
379 gtk_widget_queue_resize (widget
);
386 gtk_pizza_set_size (GtkPizza
*pizza
,
393 GtkPizzaChild
*child
;
396 g_return_if_fail (pizza
!= NULL
);
397 g_return_if_fail (GTK_IS_PIZZA (pizza
));
398 g_return_if_fail (widget
!= NULL
);
400 children
= pizza
->children
;
403 child
= children
->data
;
404 children
= children
->next
;
406 if (child
->widget
== widget
)
408 if ((child
->x
== x
) &&
410 (child
->width
== width
) &&
411 (child
->height
== height
)) return;
415 child
->width
= width
;
416 child
->height
= height
;
418 gtk_widget_set_usize (widget
, width
, height
);
420 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
421 gtk_widget_queue_resize (widget
);
429 gtk_pizza_child_resized (GtkPizza
*pizza
,
432 GtkPizzaChild
*child
;
435 g_return_val_if_fail (pizza
!= NULL
, FALSE
);
436 g_return_val_if_fail (GTK_IS_PIZZA (pizza
), FALSE
);
437 g_return_val_if_fail (widget
!= NULL
, FALSE
);
439 children
= pizza
->children
;
442 child
= children
->data
;
443 children
= children
->next
;
445 if (child
->widget
== widget
)
447 return ((child
->width
== widget
->allocation
.width
) &&
448 (child
->height
== widget
->allocation
.height
));
456 gtk_pizza_map (GtkWidget
*widget
)
459 GtkPizzaChild
*child
;
462 g_return_if_fail (widget
!= NULL
);
463 g_return_if_fail (GTK_IS_PIZZA (widget
));
465 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
466 pizza
= GTK_PIZZA (widget
);
468 children
= pizza
->children
;
471 child
= children
->data
;
472 children
= children
->next
;
474 if ( GTK_WIDGET_VISIBLE (child
->widget
) &&
475 !GTK_WIDGET_MAPPED (child
->widget
) &&
476 !GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
478 gtk_widget_map (child
->widget
);
482 gdk_window_show (widget
->window
);
483 gdk_window_show (pizza
->bin_window
);
487 gtk_pizza_realize (GtkWidget
*widget
)
490 GdkWindowAttr attributes
;
491 gint attributes_mask
;
492 GtkPizzaChild
*child
;
495 g_return_if_fail (widget
!= NULL
);
496 g_return_if_fail (GTK_IS_PIZZA (widget
));
498 pizza
= GTK_PIZZA (widget
);
500 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
502 attributes
.window_type
= GDK_WINDOW_CHILD
;
504 attributes
.x
= widget
->allocation
.x
;
505 attributes
.y
= widget
->allocation
.y
;
506 attributes
.width
= widget
->allocation
.width
;
507 attributes
.height
= widget
->allocation
.height
;
509 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
511 /* no border, no changes to sizes */
513 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
515 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
518 attributes
.width
-= 2;
519 attributes
.height
-= 2;
522 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
523 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
526 attributes
.width
-= 4;
527 attributes
.height
-= 4;
531 if (attributes
.width
< 2) attributes
.width
= 2;
532 if (attributes
.height
< 2) attributes
.height
= 2;
534 attributes
.wclass
= GDK_INPUT_OUTPUT
;
535 attributes
.visual
= gtk_widget_get_visual (widget
);
536 attributes
.colormap
= gtk_widget_get_colormap (widget
);
537 attributes
.event_mask
=
538 GDK_VISIBILITY_NOTIFY_MASK
;
539 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
541 widget
->window
= gdk_window_new(gtk_widget_get_parent_window (widget
),
542 &attributes
, attributes_mask
);
543 gdk_window_set_user_data (widget
->window
, widget
);
548 attributes
.event_mask
= gtk_widget_get_events (widget
);
549 attributes
.event_mask
|=
551 GDK_POINTER_MOTION_MASK
|
552 GDK_POINTER_MOTION_HINT_MASK
|
553 GDK_BUTTON_MOTION_MASK
|
554 GDK_BUTTON1_MOTION_MASK
|
555 GDK_BUTTON2_MOTION_MASK
|
556 GDK_BUTTON3_MOTION_MASK
|
557 GDK_BUTTON_PRESS_MASK
|
558 GDK_BUTTON_RELEASE_MASK
|
560 GDK_KEY_RELEASE_MASK
|
561 GDK_ENTER_NOTIFY_MASK
|
562 GDK_LEAVE_NOTIFY_MASK
|
563 GDK_FOCUS_CHANGE_MASK
;
565 pizza
->bin_window
= gdk_window_new(widget
->window
,
566 &attributes
, attributes_mask
);
567 gdk_window_set_user_data (pizza
->bin_window
, widget
);
569 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
570 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
571 gtk_style_set_background (widget
->style
, pizza
->bin_window
, GTK_STATE_NORMAL
);
573 /* add filters for intercepting visibility and expose events */
574 gdk_window_add_filter (widget
->window
, gtk_pizza_main_filter
, pizza
);
575 gdk_window_add_filter (pizza
->bin_window
, gtk_pizza_filter
, pizza
);
577 /* we NEED gravity or we'll give up */
578 gravity_works
= gdk_window_set_static_gravities (pizza
->bin_window
, TRUE
);
580 /* cannot be done before realisation */
581 children
= pizza
->children
;
584 child
= children
->data
;
585 children
= children
->next
;
587 gtk_widget_set_parent_window (child
->widget
, pizza
->bin_window
);
592 gtk_pizza_unrealize (GtkWidget
*widget
)
596 g_return_if_fail (widget
!= NULL
);
597 g_return_if_fail (GTK_IS_PIZZA (widget
));
599 pizza
= GTK_PIZZA (widget
);
601 gdk_window_set_user_data (pizza
->bin_window
, NULL
);
602 gdk_window_destroy (pizza
->bin_window
);
603 pizza
->bin_window
= NULL
;
605 if (GTK_WIDGET_CLASS (parent_class
)->unrealize
)
606 (* GTK_WIDGET_CLASS (parent_class
)->unrealize
) (widget
);
610 gtk_pizza_size_request (GtkWidget
*widget
,
611 GtkRequisition
*requisition
)
614 GtkPizzaChild
*child
;
616 GtkRequisition child_requisition
;
618 g_return_if_fail (widget
!= NULL
);
619 g_return_if_fail (GTK_IS_PIZZA (widget
));
620 g_return_if_fail (requisition
!= NULL
);
622 pizza
= GTK_PIZZA (widget
);
624 children
= pizza
->children
;
627 child
= children
->data
;
628 children
= children
->next
;
630 if (GTK_WIDGET_VISIBLE (child
->widget
))
632 gtk_widget_size_request (child
->widget
, &child_requisition
);
636 /* request very little, I'm not sure if requesting nothing
637 will always have positive effects on stability... */
638 requisition
->width
= 2;
639 requisition
->height
= 2;
643 gtk_pizza_size_allocate (GtkWidget
*widget
,
644 GtkAllocation
*allocation
)
649 GtkPizzaChild
*child
;
652 g_return_if_fail (widget
!= NULL
);
653 g_return_if_fail (GTK_IS_PIZZA(widget
));
654 g_return_if_fail (allocation
!= NULL
);
656 pizza
= GTK_PIZZA (widget
);
658 widget
->allocation
= *allocation
;
660 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
663 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
668 x
= allocation
->x
+ border
;
669 y
= allocation
->y
+ border
;
670 w
= allocation
->width
- border
*2;
671 h
= allocation
->height
- border
*2;
673 if (GTK_WIDGET_REALIZED (widget
))
675 gdk_window_move_resize( widget
->window
, x
, y
, w
, h
);
676 gdk_window_move_resize( pizza
->bin_window
, 0, 0, w
, h
);
679 children
= pizza
->children
;
682 child
= children
->data
;
683 children
= children
->next
;
685 gtk_pizza_position_child (pizza
, child
);
686 gtk_pizza_allocate_child (pizza
, child
);
691 gtk_pizza_draw (GtkWidget
*widget
,
695 GtkPizzaChild
*child
;
696 GdkRectangle child_area
;
699 g_return_if_fail (widget
!= NULL
);
700 g_return_if_fail (GTK_IS_PIZZA (widget
));
702 pizza
= GTK_PIZZA (widget
);
704 /* Sometimes, We handle all expose events in window.cpp now. */
705 if (pizza
->external_expose
)
708 children
= pizza
->children
;
709 if ( !(GTK_WIDGET_APP_PAINTABLE (widget
)) &&
710 (pizza
->clear_on_draw
))
712 gdk_window_clear_area( pizza
->bin_window
,
713 area
->x
, area
->y
, area
->width
, area
->height
);
718 child
= children
->data
;
719 children
= children
->next
;
721 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
722 gtk_widget_draw (child
->widget
, &child_area
);
727 gtk_pizza_expose (GtkWidget
*widget
,
728 GdkEventExpose
*event
)
731 GtkPizzaChild
*child
;
732 GdkEventExpose child_event
;
735 g_return_val_if_fail (widget
!= NULL
, FALSE
);
736 g_return_val_if_fail (GTK_IS_PIZZA (widget
), FALSE
);
737 g_return_val_if_fail (event
!= NULL
, FALSE
);
739 pizza
= GTK_PIZZA (widget
);
741 /* Sometimes, We handle all expose events in window.cpp now. */
742 if (pizza
->external_expose
)
745 if (event
->window
!= pizza
->bin_window
)
748 children
= pizza
->children
;
751 child
= children
->data
;
752 children
= children
->next
;
754 child_event
= *event
;
756 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
757 GTK_WIDGET_DRAWABLE (child
->widget
) &&
758 gtk_widget_intersect (child
->widget
, &event
->area
, &child_event
.area
))
760 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
768 gtk_pizza_add (GtkContainer
*container
,
771 g_return_if_fail (container
!= NULL
);
772 g_return_if_fail (GTK_IS_PIZZA (container
));
773 g_return_if_fail (widget
!= NULL
);
775 gtk_pizza_put (GTK_PIZZA (container
), widget
, 0, 0, 20, 20 );
779 gtk_pizza_remove (GtkContainer
*container
,
783 GtkPizzaChild
*child
;
786 g_return_if_fail (container
!= NULL
);
787 g_return_if_fail (GTK_IS_PIZZA (container
));
788 g_return_if_fail (widget
!= NULL
);
790 pizza
= GTK_PIZZA (container
);
792 children
= pizza
->children
;
795 child
= children
->data
;
797 if (child
->widget
== widget
)
799 gtk_widget_unparent (widget
);
801 /* security checks */
802 g_return_if_fail (GTK_IS_WIDGET (widget
));
804 pizza
->children
= g_list_remove_link (pizza
->children
, children
);
805 g_list_free (children
);
808 /* security checks */
809 g_return_if_fail (GTK_IS_WIDGET (widget
));
811 GTK_PRIVATE_UNSET_FLAG (widget
, GTK_IS_OFFSCREEN
);
816 children
= children
->next
;
821 gtk_pizza_forall (GtkContainer
*container
,
822 gboolean include_internals
,
823 GtkCallback callback
,
824 gpointer callback_data
)
827 GtkPizzaChild
*child
;
830 g_return_if_fail (container
!= NULL
);
831 g_return_if_fail (GTK_IS_PIZZA (container
));
832 g_return_if_fail (callback
!= NULL
);
834 pizza
= GTK_PIZZA (container
);
836 children
= pizza
->children
;
839 child
= children
->data
;
840 children
= children
->next
;
842 (* callback
) (child
->widget
, callback_data
);
847 /* Operations on children
851 gtk_pizza_position_child (GtkPizza
*pizza
,
852 GtkPizzaChild
*child
)
857 x
= child
->x
- pizza
->xoffset
;
858 y
= child
->y
- pizza
->yoffset
;
860 if (IS_ONSCREEN (x
,y
))
862 if (GTK_WIDGET_MAPPED (pizza
) &&
863 GTK_WIDGET_VISIBLE (child
->widget
))
865 if (!GTK_WIDGET_MAPPED (child
->widget
))
866 gtk_widget_map (child
->widget
);
869 if (GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
870 GTK_PRIVATE_UNSET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
874 if (!GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
875 GTK_PRIVATE_SET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
877 if (GTK_WIDGET_MAPPED (child
->widget
))
878 gtk_widget_unmap (child
->widget
);
883 gtk_pizza_allocate_child (GtkPizza
*pizza
,
884 GtkPizzaChild
*child
)
886 GtkAllocation allocation
;
887 GtkRequisition requisition
;
889 allocation
.x
= child
->x
- pizza
->xoffset
;
890 allocation
.y
= child
->y
- pizza
->yoffset
;
891 gtk_widget_get_child_requisition (child
->widget
, &requisition
);
892 allocation
.width
= requisition
.width
;
893 allocation
.height
= requisition
.height
;
895 gtk_widget_size_allocate (child
->widget
, &allocation
);
899 gtk_pizza_position_children (GtkPizza
*pizza
)
903 tmp_list
= pizza
->children
;
906 GtkPizzaChild
*child
= tmp_list
->data
;
907 tmp_list
= tmp_list
->next
;
909 gtk_pizza_position_child (pizza
, child
);
914 gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
917 GtkPizzaAdjData
*data
= cb_data
;
919 widget
->allocation
.x
+= data
->dx
;
920 widget
->allocation
.y
+= data
->dy
;
922 if (GTK_WIDGET_NO_WINDOW (widget
) && GTK_IS_CONTAINER (widget
))
924 gtk_container_forall (GTK_CONTAINER (widget
),
925 gtk_pizza_adjust_allocations_recurse
,
931 gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
936 GtkPizzaAdjData data
;
941 tmp_list
= pizza
->children
;
944 GtkPizzaChild
*child
= tmp_list
->data
;
945 tmp_list
= tmp_list
->next
;
947 child
->widget
->allocation
.x
+= dx
;
948 child
->widget
->allocation
.y
+= dy
;
950 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
951 GTK_IS_CONTAINER (child
->widget
))
953 gtk_container_forall (GTK_CONTAINER (child
->widget
),
954 gtk_pizza_adjust_allocations_recurse
,
962 /* Send a synthetic expose event to the widget
965 gtk_pizza_expose_area (GtkPizza
*pizza
,
966 gint x
, gint y
, gint width
, gint height
)
968 if (pizza
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
970 GdkEventExpose event
;
972 event
.type
= GDK_EXPOSE
;
973 event
.send_event
= TRUE
;
974 event
.window
= pizza
->bin_window
;
979 event
.area
.width
= width
;
980 event
.area
.height
= height
;
982 gdk_window_ref (event
.window
);
983 gtk_widget_event (GTK_WIDGET (pizza
), (GdkEvent
*)&event
);
984 gdk_window_unref (event
.window
);
988 /* This function is used to find events to process while scrolling
992 gtk_pizza_expose_predicate (Display
*display
,
996 if ((xevent
->type
== Expose
) ||
997 ((xevent
->xany
.window
== *(Window
*)arg
) &&
998 (xevent
->type
== ConfigureNotify
)))
1004 /* This is the main routine to do the scrolling. Scrolling is
1005 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
1006 * a few modifications.
1008 * The main improvement is that we keep track of whether we
1009 * are obscured or not. If not, we ignore the generated expose
1010 * events and instead do the exposes ourself, without having
1011 * to wait for a roundtrip to the server. This also provides
1012 * a limited form of expose-event compression, since we do
1013 * the affected area as one big chunk.
1017 gtk_pizza_scroll (GtkPizza
*pizza
, gint dx
, gint dy
)
1022 gint x
,y
,w
,h
,border
;
1024 widget
= GTK_WIDGET (pizza
);
1026 pizza
->xoffset
+= dx
;
1027 pizza
->yoffset
+= dy
;
1029 if (!GTK_WIDGET_MAPPED (pizza
))
1031 gtk_pizza_position_children (pizza
);
1035 gtk_pizza_adjust_allocations (pizza
, -dx
, -dy
);
1037 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
1040 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
1047 w
= widget
->allocation
.width
- 2*border
;
1048 h
= widget
->allocation
.height
- 2*border
;
1054 gdk_window_resize (pizza
->bin_window
,
1057 gdk_window_move (pizza
->bin_window
, x
-dx
, y
);
1058 gdk_window_move_resize (pizza
->bin_window
, x
, y
, w
, h
);
1065 gtk_pizza_expose_area (pizza
,
1066 MAX ((gint
)w
- dx
, 0),
1075 gdk_window_move_resize (pizza
->bin_window
,
1080 gdk_window_move (pizza
->bin_window
, x
, y
);
1081 gdk_window_resize (pizza
->bin_window
, w
, h
);
1088 gtk_pizza_expose_area (pizza
,
1099 gdk_window_resize (pizza
->bin_window
, w
, h
+ dy
);
1100 gdk_window_move (pizza
->bin_window
, x
, y
-dy
);
1101 gdk_window_move_resize (pizza
->bin_window
,
1109 gtk_pizza_expose_area (pizza
,
1111 MAX ((gint
)h
- dy
, 0),
1119 gdk_window_move_resize (pizza
->bin_window
,
1120 x
, y
+dy
, w
, h
- dy
);
1121 gdk_window_move (pizza
->bin_window
, x
, y
);
1122 gdk_window_resize (pizza
->bin_window
, w
, h
);
1128 gtk_pizza_expose_area (pizza
,
1132 MIN (-dy
, (gint
)h
));
1135 gtk_pizza_position_children (pizza
);
1137 /* We have to make sure that all exposes from this scroll get
1138 * processed before we scroll again, or the expose events will
1139 * have invalid coordinates.
1141 * We also do expose events for other windows, since otherwise
1142 * their updating will fall behind the scrolling
1144 * This also avoids a problem in pre-1.0 GTK where filters don't
1145 * have access to configure events that were compressed.
1149 while (XCheckIfEvent(GDK_WINDOW_XDISPLAY (pizza
->bin_window
),
1151 gtk_pizza_expose_predicate
,
1152 (XPointer
)&GDK_WINDOW_XWINDOW (pizza
->bin_window
)))
1155 GtkWidget
*event_widget
;
1157 if ((xevent
.xany
.window
== GDK_WINDOW_XWINDOW (pizza
->bin_window
)) &&
1158 (gtk_pizza_filter (&xevent
, &event
, pizza
) == GDK_FILTER_REMOVE
))
1161 if (xevent
.type
== Expose
)
1163 event
.expose
.window
= gdk_window_lookup (xevent
.xany
.window
);
1164 gdk_window_get_user_data (event
.expose
.window
,
1165 (gpointer
*)&event_widget
);
1169 event
.expose
.type
= GDK_EXPOSE
;
1170 event
.expose
.area
.x
= xevent
.xexpose
.x
;
1171 event
.expose
.area
.y
= xevent
.xexpose
.y
;
1172 event
.expose
.area
.width
= xevent
.xexpose
.width
;
1173 event
.expose
.area
.height
= xevent
.xexpose
.height
;
1174 event
.expose
.count
= xevent
.xexpose
.count
;
1176 gdk_window_ref (event
.expose
.window
);
1177 gtk_widget_event (event_widget
, &event
);
1178 gdk_window_unref (event
.expose
.window
);
1184 /* The main event filter. Actually, we probably don't really need
1185 * to install this as a filter at all, since we are calling it
1186 * directly above in the expose-handling hack. But in case scrollbars
1187 * are fixed up in some manner...
1189 * This routine identifies expose events that are generated when
1190 * we've temporarily moved the bin_window_origin, and translates
1191 * them or discards them, depending on whether we are obscured
1194 static GdkFilterReturn
1195 gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
1202 xevent
= (XEvent
*)gdk_xevent
;
1204 pizza
= GTK_PIZZA (data
);
1206 if (!pizza
->use_filter
)
1207 return GDK_FILTER_CONTINUE
;
1209 switch (xevent
->type
)
1212 if (xevent
->xexpose
.serial
== pizza
->configure_serial
)
1214 if (pizza
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
1215 return GDK_FILTER_REMOVE
;
1218 xevent
->xexpose
.x
+= pizza
->scroll_x
;
1219 xevent
->xexpose
.y
+= pizza
->scroll_y
;
1226 case ConfigureNotify
:
1227 if ((xevent
->xconfigure
.x
!= 0) || (xevent
->xconfigure
.y
!= 0))
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
;
1285 #endif /* __cplusplus */