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/setup.h"
18 #include "wx/gtk/win_gtk.h"
19 #include "gtk/gtksignal.h"
20 #include "gtk/gtkprivate.h"
25 #endif /* __cplusplus */
28 #include <X11/Xutil.h>
29 #include <X11/Xatom.h>
31 #define IS_ONSCREEN(x,y) ((x >= G_MINSHORT) && (x <= G_MAXSHORT) && \
32 (y >= G_MINSHORT) && (y <= G_MAXSHORT))
34 typedef struct _GtkPizzaAdjData GtkPizzaAdjData
;
36 struct _GtkPizzaAdjData
42 static void gtk_pizza_class_init (GtkPizzaClass
*klass
);
43 static void gtk_pizza_init (GtkPizza
*pizza
);
45 static void gtk_pizza_realize (GtkWidget
*widget
);
46 static void gtk_pizza_unrealize (GtkWidget
*widget
);
48 static void gtk_pizza_map (GtkWidget
*widget
);
50 static void gtk_pizza_size_request (GtkWidget
*widget
,
51 GtkRequisition
*requisition
);
52 static void gtk_pizza_size_allocate (GtkWidget
*widget
,
53 GtkAllocation
*allocation
);
54 static void gtk_pizza_draw (GtkWidget
*widget
,
56 static gint
gtk_pizza_expose (GtkWidget
*widget
,
57 GdkEventExpose
*event
);
58 static void gtk_pizza_add (GtkContainer
*container
,
60 static void gtk_pizza_remove (GtkContainer
*container
,
62 static void gtk_pizza_forall (GtkContainer
*container
,
63 gboolean include_internals
,
65 gpointer callback_data
);
67 static void gtk_pizza_position_child (GtkPizza
*pizza
,
68 GtkPizzaChild
*child
);
69 static void gtk_pizza_allocate_child (GtkPizza
*pizza
,
70 GtkPizzaChild
*child
);
71 static void gtk_pizza_position_children (GtkPizza
*pizza
);
73 static void gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
75 static void gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
80 static void gtk_pizza_expose_area (GtkPizza
*pizza
,
87 static void gtk_pizza_adjustment_changed (GtkAdjustment
*adjustment
,
91 static GdkFilterReturn
gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
94 static GdkFilterReturn
gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
99 static GtkType
gtk_pizza_child_type (GtkContainer
*container
);
101 static void gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
103 GtkAdjustment
*vadj
);
106 static GtkContainerClass
*parent_class
= NULL
;
107 static gboolean gravity_works
;
110 gtk_pizza_get_type ()
112 static guint pizza_type
= 0;
116 GtkTypeInfo pizza_info
=
120 sizeof (GtkPizzaClass
),
121 (GtkClassInitFunc
) gtk_pizza_class_init
,
122 (GtkObjectInitFunc
) gtk_pizza_init
,
123 /* reserved_1 */ NULL
,
124 /* reserved_2 */ NULL
,
125 (GtkClassInitFunc
) NULL
,
127 pizza_type
= gtk_type_unique (gtk_container_get_type (), &pizza_info
);
134 gtk_pizza_class_init (GtkPizzaClass
*klass
)
136 GtkObjectClass
*object_class
;
137 GtkWidgetClass
*widget_class
;
138 GtkContainerClass
*container_class
;
140 object_class
= (GtkObjectClass
*) klass
;
141 widget_class
= (GtkWidgetClass
*) klass
;
142 container_class
= (GtkContainerClass
*) klass
;
143 parent_class
= gtk_type_class (GTK_TYPE_CONTAINER
);
145 widget_class
->map
= gtk_pizza_map
;
146 widget_class
->realize
= gtk_pizza_realize
;
147 widget_class
->unrealize
= gtk_pizza_unrealize
;
148 widget_class
->size_request
= gtk_pizza_size_request
;
149 widget_class
->size_allocate
= gtk_pizza_size_allocate
;
150 widget_class
->draw
= gtk_pizza_draw
;
151 widget_class
->expose_event
= gtk_pizza_expose
;
153 container_class
->add
= gtk_pizza_add
;
154 container_class
->remove
= gtk_pizza_remove
;
155 container_class
->forall
= gtk_pizza_forall
;
157 container_class
->child_type
= gtk_pizza_child_type
;
159 klass
->set_scroll_adjustments
= gtk_pizza_scroll_set_adjustments
;
161 widget_class
->set_scroll_adjustments_signal
=
162 gtk_signal_new ("set_scroll_adjustments",
164 GTK_CLASS_TYPE(object_class
),
165 GTK_SIGNAL_OFFSET (GtkPizzaClass
, set_scroll_adjustments
),
166 gtk_marshal_NONE__POINTER_POINTER
,
167 GTK_TYPE_NONE
, 2, GTK_TYPE_ADJUSTMENT
, GTK_TYPE_ADJUSTMENT
);
171 gtk_pizza_child_type (GtkContainer
*container
)
173 return GTK_TYPE_WIDGET
;
177 gtk_pizza_init (GtkPizza
*pizza
)
179 GTK_WIDGET_UNSET_FLAGS (pizza
, GTK_NO_WINDOW
);
181 pizza
->shadow_type
= GTK_MYSHADOW_NONE
;
183 pizza
->children
= NULL
;
188 pizza
->bin_window
= NULL
;
193 pizza
->configure_serial
= 0;
196 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
198 pizza
->clear_on_draw
= TRUE
;
199 pizza
->use_filter
= TRUE
;
200 pizza
->external_expose
= FALSE
;
208 pizza
= gtk_type_new (gtk_pizza_get_type ());
210 return GTK_WIDGET (pizza
);
214 gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
218 /* We handle scrolling in the wxScrolledWindow, not here. */
222 gtk_pizza_set_shadow_type (GtkPizza
*pizza
,
223 GtkMyShadowType type
)
225 g_return_if_fail (pizza
!= NULL
);
226 g_return_if_fail (GTK_IS_PIZZA (pizza
));
228 if ((GtkMyShadowType
) pizza
->shadow_type
!= type
)
230 pizza
->shadow_type
= type
;
232 if (GTK_WIDGET_VISIBLE (pizza
))
234 gtk_widget_size_allocate (GTK_WIDGET (pizza
), &(GTK_WIDGET (pizza
)->allocation
));
235 gtk_widget_queue_draw (GTK_WIDGET (pizza
));
241 gtk_pizza_set_clear (GtkPizza
*pizza
,
244 g_return_if_fail (pizza
!= NULL
);
245 g_return_if_fail (GTK_IS_PIZZA (pizza
));
247 pizza
->clear_on_draw
= clear
;
251 gtk_pizza_set_filter (GtkPizza
*pizza
,
254 g_return_if_fail (pizza
!= NULL
);
255 g_return_if_fail (GTK_IS_PIZZA (pizza
));
257 pizza
->use_filter
= use
;
261 gtk_pizza_set_external (GtkPizza
*pizza
,
264 g_return_if_fail (pizza
!= NULL
);
265 g_return_if_fail (GTK_IS_PIZZA (pizza
));
267 pizza
->external_expose
= expose
;
271 gtk_pizza_put (GtkPizza
*pizza
,
278 GtkPizzaChild
*child_info
;
280 g_return_if_fail (pizza
!= NULL
);
281 g_return_if_fail (GTK_IS_PIZZA (pizza
));
282 g_return_if_fail (widget
!= NULL
);
284 child_info
= g_new (GtkPizzaChild
, 1);
286 child_info
->widget
= widget
;
289 child_info
->width
= width
;
290 child_info
->height
= height
;
292 pizza
->children
= g_list_append (pizza
->children
, child_info
);
294 gtk_widget_set_parent (widget
, GTK_WIDGET (pizza
));
296 if (GTK_WIDGET_REALIZED (pizza
))
297 gtk_widget_set_parent_window (widget
, pizza
->bin_window
);
299 #ifndef __WXGTK20__ /* FIXME? */
300 if (!IS_ONSCREEN (x
, y
))
301 GTK_PRIVATE_SET_FLAG (widget
, GTK_IS_OFFSCREEN
);
305 if (GTK_WIDGET_REALIZED (pizza))
306 gtk_widget_realize (widget);
309 gtk_widget_set_usize (widget
, width
, height
);
312 if (GTK_WIDGET_VISIBLE (pizza) && GTK_WIDGET_VISIBLE (widget))
314 if (GTK_WIDGET_MAPPED (pizza))
315 gtk_widget_map (widget);
317 gtk_widget_queue_resize (widget);
323 gtk_pizza_move (GtkPizza
*pizza
,
328 GtkPizzaChild
*child
;
331 g_return_if_fail (pizza
!= NULL
);
332 g_return_if_fail (GTK_IS_PIZZA (pizza
));
333 g_return_if_fail (widget
!= NULL
);
335 children
= pizza
->children
;
338 child
= children
->data
;
339 children
= children
->next
;
341 if (child
->widget
== widget
)
343 if ((child
->x
== x
) && (child
->y
== y
))
349 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
350 gtk_widget_queue_resize (widget
);
357 gtk_pizza_resize (GtkPizza
*pizza
,
362 GtkPizzaChild
*child
;
365 g_return_if_fail (pizza
!= NULL
);
366 g_return_if_fail (GTK_IS_PIZZA (pizza
));
367 g_return_if_fail (widget
!= NULL
);
369 children
= pizza
->children
;
372 child
= children
->data
;
373 children
= children
->next
;
375 if (child
->widget
== widget
)
377 if ((child
->width
== width
) && (child
->height
== height
))
380 child
->width
= width
;
381 child
->height
= height
;
383 gtk_widget_set_usize (widget
, width
, height
);
385 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
386 gtk_widget_queue_resize (widget
);
393 gtk_pizza_set_size (GtkPizza
*pizza
,
400 GtkPizzaChild
*child
;
403 g_return_if_fail (pizza
!= NULL
);
404 g_return_if_fail (GTK_IS_PIZZA (pizza
));
405 g_return_if_fail (widget
!= NULL
);
407 children
= pizza
->children
;
410 child
= children
->data
;
411 children
= children
->next
;
413 if (child
->widget
== widget
)
415 if ((child
->x
== x
) &&
417 (child
->width
== width
) &&
418 (child
->height
== height
)) return;
422 child
->width
= width
;
423 child
->height
= height
;
425 gtk_widget_set_usize (widget
, width
, height
);
427 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
428 gtk_widget_queue_resize (widget
);
436 gtk_pizza_child_resized (GtkPizza
*pizza
,
439 GtkPizzaChild
*child
;
442 g_return_val_if_fail (pizza
!= NULL
, FALSE
);
443 g_return_val_if_fail (GTK_IS_PIZZA (pizza
), FALSE
);
444 g_return_val_if_fail (widget
!= NULL
, FALSE
);
446 children
= pizza
->children
;
449 child
= children
->data
;
450 children
= children
->next
;
452 if (child
->widget
== widget
)
454 return ((child
->width
== widget
->allocation
.width
) &&
455 (child
->height
== widget
->allocation
.height
));
463 gtk_pizza_map (GtkWidget
*widget
)
466 GtkPizzaChild
*child
;
469 g_return_if_fail (widget
!= NULL
);
470 g_return_if_fail (GTK_IS_PIZZA (widget
));
472 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
473 pizza
= GTK_PIZZA (widget
);
475 children
= pizza
->children
;
478 child
= children
->data
;
479 children
= children
->next
;
481 if ( GTK_WIDGET_VISIBLE (child
->widget
) &&
482 !GTK_WIDGET_MAPPED (child
->widget
) &&
486 !GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
489 gtk_widget_map (child
->widget
);
493 gdk_window_show (widget
->window
);
494 gdk_window_show (pizza
->bin_window
);
498 gtk_pizza_realize (GtkWidget
*widget
)
501 GdkWindowAttr attributes
;
502 gint attributes_mask
;
503 GtkPizzaChild
*child
;
506 g_return_if_fail (widget
!= NULL
);
507 g_return_if_fail (GTK_IS_PIZZA (widget
));
509 pizza
= GTK_PIZZA (widget
);
511 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
513 attributes
.window_type
= GDK_WINDOW_CHILD
;
515 attributes
.x
= widget
->allocation
.x
;
516 attributes
.y
= widget
->allocation
.y
;
517 attributes
.width
= widget
->allocation
.width
;
518 attributes
.height
= widget
->allocation
.height
;
520 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
522 /* no border, no changes to sizes */
524 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
526 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
529 attributes
.width
-= 2;
530 attributes
.height
-= 2;
533 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
534 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
537 attributes
.width
-= 4;
538 attributes
.height
-= 4;
542 if (attributes
.width
< 2) attributes
.width
= 2;
543 if (attributes
.height
< 2) attributes
.height
= 2;
545 attributes
.wclass
= GDK_INPUT_OUTPUT
;
546 attributes
.visual
= gtk_widget_get_visual (widget
);
547 attributes
.colormap
= gtk_widget_get_colormap (widget
);
548 attributes
.event_mask
=
549 GDK_VISIBILITY_NOTIFY_MASK
;
550 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
552 widget
->window
= gdk_window_new(gtk_widget_get_parent_window (widget
),
553 &attributes
, attributes_mask
);
554 gdk_window_set_user_data (widget
->window
, widget
);
559 attributes
.event_mask
= gtk_widget_get_events (widget
);
560 attributes
.event_mask
|=
562 GDK_POINTER_MOTION_MASK
|
563 GDK_POINTER_MOTION_HINT_MASK
|
564 GDK_BUTTON_MOTION_MASK
|
565 GDK_BUTTON1_MOTION_MASK
|
566 GDK_BUTTON2_MOTION_MASK
|
567 GDK_BUTTON3_MOTION_MASK
|
568 GDK_BUTTON_PRESS_MASK
|
569 GDK_BUTTON_RELEASE_MASK
|
571 GDK_KEY_RELEASE_MASK
|
572 GDK_ENTER_NOTIFY_MASK
|
573 GDK_LEAVE_NOTIFY_MASK
|
574 GDK_FOCUS_CHANGE_MASK
;
576 pizza
->bin_window
= gdk_window_new(widget
->window
,
577 &attributes
, attributes_mask
);
578 gdk_window_set_user_data (pizza
->bin_window
, widget
);
580 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
581 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
582 gtk_style_set_background (widget
->style
, pizza
->bin_window
, GTK_STATE_NORMAL
);
584 /* add filters for intercepting visibility and expose events */
585 gdk_window_add_filter (widget
->window
, gtk_pizza_main_filter
, pizza
);
586 gdk_window_add_filter (pizza
->bin_window
, gtk_pizza_filter
, pizza
);
588 /* we NEED gravity or we'll give up */
589 gravity_works
= gdk_window_set_static_gravities (pizza
->bin_window
, TRUE
);
591 /* cannot be done before realisation */
592 children
= pizza
->children
;
595 child
= children
->data
;
596 children
= children
->next
;
598 gtk_widget_set_parent_window (child
->widget
, pizza
->bin_window
);
603 gtk_pizza_unrealize (GtkWidget
*widget
)
607 g_return_if_fail (widget
!= NULL
);
608 g_return_if_fail (GTK_IS_PIZZA (widget
));
610 pizza
= GTK_PIZZA (widget
);
612 gdk_window_set_user_data (pizza
->bin_window
, NULL
);
613 gdk_window_destroy (pizza
->bin_window
);
614 pizza
->bin_window
= NULL
;
616 if (GTK_WIDGET_CLASS (parent_class
)->unrealize
)
617 (* GTK_WIDGET_CLASS (parent_class
)->unrealize
) (widget
);
621 gtk_pizza_size_request (GtkWidget
*widget
,
622 GtkRequisition
*requisition
)
625 GtkPizzaChild
*child
;
627 GtkRequisition child_requisition
;
629 g_return_if_fail (widget
!= NULL
);
630 g_return_if_fail (GTK_IS_PIZZA (widget
));
631 g_return_if_fail (requisition
!= NULL
);
633 pizza
= GTK_PIZZA (widget
);
635 children
= pizza
->children
;
638 child
= children
->data
;
639 children
= children
->next
;
641 if (GTK_WIDGET_VISIBLE (child
->widget
))
643 gtk_widget_size_request (child
->widget
, &child_requisition
);
647 /* request very little, I'm not sure if requesting nothing
648 will always have positive effects on stability... */
649 requisition
->width
= 2;
650 requisition
->height
= 2;
654 gtk_pizza_size_allocate (GtkWidget
*widget
,
655 GtkAllocation
*allocation
)
660 GtkPizzaChild
*child
;
663 g_return_if_fail (widget
!= NULL
);
664 g_return_if_fail (GTK_IS_PIZZA(widget
));
665 g_return_if_fail (allocation
!= NULL
);
667 pizza
= GTK_PIZZA (widget
);
669 widget
->allocation
= *allocation
;
671 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
674 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
679 x
= allocation
->x
+ border
;
680 y
= allocation
->y
+ border
;
681 w
= allocation
->width
- border
*2;
682 h
= allocation
->height
- border
*2;
684 if (GTK_WIDGET_REALIZED (widget
))
686 gdk_window_move_resize( widget
->window
, x
, y
, w
, h
);
687 gdk_window_move_resize( pizza
->bin_window
, 0, 0, w
, h
);
690 children
= pizza
->children
;
693 child
= children
->data
;
694 children
= children
->next
;
696 gtk_pizza_position_child (pizza
, child
);
697 gtk_pizza_allocate_child (pizza
, child
);
702 gtk_pizza_draw (GtkWidget
*widget
,
706 GtkPizzaChild
*child
;
707 GdkRectangle child_area
;
710 g_return_if_fail (widget
!= NULL
);
711 g_return_if_fail (GTK_IS_PIZZA (widget
));
713 pizza
= GTK_PIZZA (widget
);
715 /* Sometimes, We handle all expose events in window.cpp now. */
716 if (pizza
->external_expose
)
719 children
= pizza
->children
;
720 if ( !(GTK_WIDGET_APP_PAINTABLE (widget
)) &&
721 (pizza
->clear_on_draw
))
723 gdk_window_clear_area( pizza
->bin_window
,
724 area
->x
, area
->y
, area
->width
, area
->height
);
729 child
= children
->data
;
730 children
= children
->next
;
732 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
733 gtk_widget_draw (child
->widget
, &child_area
);
738 gtk_pizza_expose (GtkWidget
*widget
,
739 GdkEventExpose
*event
)
742 GtkPizzaChild
*child
;
743 GdkEventExpose child_event
;
746 g_return_val_if_fail (widget
!= NULL
, FALSE
);
747 g_return_val_if_fail (GTK_IS_PIZZA (widget
), FALSE
);
748 g_return_val_if_fail (event
!= NULL
, FALSE
);
750 pizza
= GTK_PIZZA (widget
);
752 /* Sometimes, We handle all expose events in window.cpp now. */
753 if (pizza
->external_expose
)
756 if (event
->window
!= pizza
->bin_window
)
759 children
= pizza
->children
;
762 child
= children
->data
;
763 children
= children
->next
;
765 child_event
= *event
;
767 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
768 GTK_WIDGET_DRAWABLE (child
->widget
) &&
769 gtk_widget_intersect (child
->widget
, &event
->area
, &child_event
.area
))
771 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
779 gtk_pizza_add (GtkContainer
*container
,
782 g_return_if_fail (container
!= NULL
);
783 g_return_if_fail (GTK_IS_PIZZA (container
));
784 g_return_if_fail (widget
!= NULL
);
786 gtk_pizza_put (GTK_PIZZA (container
), widget
, 0, 0, 20, 20 );
790 gtk_pizza_remove (GtkContainer
*container
,
794 GtkPizzaChild
*child
;
797 g_return_if_fail (container
!= NULL
);
798 g_return_if_fail (GTK_IS_PIZZA (container
));
799 g_return_if_fail (widget
!= NULL
);
801 pizza
= GTK_PIZZA (container
);
803 children
= pizza
->children
;
806 child
= children
->data
;
808 if (child
->widget
== widget
)
810 gtk_widget_unparent (widget
);
812 /* security checks */
813 g_return_if_fail (GTK_IS_WIDGET (widget
));
815 pizza
->children
= g_list_remove_link (pizza
->children
, children
);
816 g_list_free (children
);
819 /* security checks */
820 g_return_if_fail (GTK_IS_WIDGET (widget
));
823 GTK_PRIVATE_UNSET_FLAG (widget
, GTK_IS_OFFSCREEN
);
829 children
= children
->next
;
834 gtk_pizza_forall (GtkContainer
*container
,
835 gboolean include_internals
,
836 GtkCallback callback
,
837 gpointer callback_data
)
840 GtkPizzaChild
*child
;
843 g_return_if_fail (container
!= NULL
);
844 g_return_if_fail (GTK_IS_PIZZA (container
));
845 g_return_if_fail (callback
!= NULL
);
847 pizza
= GTK_PIZZA (container
);
849 children
= pizza
->children
;
852 child
= children
->data
;
853 children
= children
->next
;
855 (* callback
) (child
->widget
, callback_data
);
860 /* Operations on children
864 gtk_pizza_position_child (GtkPizza
*pizza
,
865 GtkPizzaChild
*child
)
870 x
= child
->x
- pizza
->xoffset
;
871 y
= child
->y
- pizza
->yoffset
;
873 if (IS_ONSCREEN (x
,y
))
875 if (GTK_WIDGET_MAPPED (pizza
) &&
876 GTK_WIDGET_VISIBLE (child
->widget
))
878 if (!GTK_WIDGET_MAPPED (child
->widget
))
879 gtk_widget_map (child
->widget
);
883 if (GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
884 GTK_PRIVATE_UNSET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
890 if (!GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
891 GTK_PRIVATE_SET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
894 if (GTK_WIDGET_MAPPED (child
->widget
))
895 gtk_widget_unmap (child
->widget
);
900 gtk_pizza_allocate_child (GtkPizza
*pizza
,
901 GtkPizzaChild
*child
)
903 GtkAllocation allocation
;
904 GtkRequisition requisition
;
906 allocation
.x
= child
->x
- pizza
->xoffset
;
907 allocation
.y
= child
->y
- pizza
->yoffset
;
908 gtk_widget_get_child_requisition (child
->widget
, &requisition
);
909 allocation
.width
= requisition
.width
;
910 allocation
.height
= requisition
.height
;
912 gtk_widget_size_allocate (child
->widget
, &allocation
);
916 gtk_pizza_position_children (GtkPizza
*pizza
)
920 tmp_list
= pizza
->children
;
923 GtkPizzaChild
*child
= tmp_list
->data
;
924 tmp_list
= tmp_list
->next
;
926 gtk_pizza_position_child (pizza
, child
);
931 gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
934 GtkPizzaAdjData
*data
= cb_data
;
936 widget
->allocation
.x
+= data
->dx
;
937 widget
->allocation
.y
+= data
->dy
;
939 if (GTK_WIDGET_NO_WINDOW (widget
) && GTK_IS_CONTAINER (widget
))
941 gtk_container_forall (GTK_CONTAINER (widget
),
942 gtk_pizza_adjust_allocations_recurse
,
948 gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
953 GtkPizzaAdjData data
;
958 tmp_list
= pizza
->children
;
961 GtkPizzaChild
*child
= tmp_list
->data
;
962 tmp_list
= tmp_list
->next
;
964 child
->widget
->allocation
.x
+= dx
;
965 child
->widget
->allocation
.y
+= dy
;
967 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
968 GTK_IS_CONTAINER (child
->widget
))
970 gtk_container_forall (GTK_CONTAINER (child
->widget
),
971 gtk_pizza_adjust_allocations_recurse
,
979 /* Send a synthetic expose event to the widget
982 gtk_pizza_expose_area (GtkPizza
*pizza
,
983 gint x
, gint y
, gint width
, gint height
)
985 if (pizza
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
987 GdkEventExpose event
;
989 event
.type
= GDK_EXPOSE
;
990 event
.send_event
= TRUE
;
991 event
.window
= pizza
->bin_window
;
996 event
.area
.width
= width
;
997 event
.area
.height
= height
;
999 gdk_window_ref (event
.window
);
1000 gtk_widget_event (GTK_WIDGET (pizza
), (GdkEvent
*)&event
);
1001 gdk_window_unref (event
.window
);
1005 /* This function is used to find events to process while scrolling
1009 gtk_pizza_expose_predicate (Display
*display
,
1013 if ((xevent
->type
== Expose
) ||
1014 ((xevent
->xany
.window
== *(Window
*)arg
) &&
1015 (xevent
->type
== ConfigureNotify
)))
1021 /* This is the main routine to do the scrolling. Scrolling is
1022 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
1023 * a few modifications.
1025 * The main improvement is that we keep track of whether we
1026 * are obscured or not. If not, we ignore the generated expose
1027 * events and instead do the exposes ourself, without having
1028 * to wait for a roundtrip to the server. This also provides
1029 * a limited form of expose-event compression, since we do
1030 * the affected area as one big chunk.
1034 gtk_pizza_scroll (GtkPizza
*pizza
, gint dx
, gint dy
)
1039 gint x
,y
,w
,h
,border
;
1041 widget
= GTK_WIDGET (pizza
);
1043 pizza
->xoffset
+= dx
;
1044 pizza
->yoffset
+= dy
;
1046 if (!GTK_WIDGET_MAPPED (pizza
))
1048 gtk_pizza_position_children (pizza
);
1052 gtk_pizza_adjust_allocations (pizza
, -dx
, -dy
);
1054 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
1057 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
1064 w
= widget
->allocation
.width
- 2*border
;
1065 h
= widget
->allocation
.height
- 2*border
;
1071 gdk_window_resize (pizza
->bin_window
,
1074 gdk_window_move (pizza
->bin_window
, x
-dx
, y
);
1075 gdk_window_move_resize (pizza
->bin_window
, x
, y
, w
, h
);
1086 gdk_window_move_resize (pizza
->bin_window
,
1091 gdk_window_move (pizza
->bin_window
, x
, y
);
1092 gdk_window_resize (pizza
->bin_window
, w
, h
);
1104 gdk_window_resize (pizza
->bin_window
, w
, h
+ dy
);
1105 gdk_window_move (pizza
->bin_window
, x
, y
-dy
);
1106 gdk_window_move_resize (pizza
->bin_window
,
1118 gdk_window_move_resize (pizza
->bin_window
,
1119 x
, y
+dy
, w
, h
- dy
);
1120 gdk_window_move (pizza
->bin_window
, x
, y
);
1121 gdk_window_resize (pizza
->bin_window
, w
, h
);
1129 gtk_pizza_position_children (pizza
);
1132 while (XCheckIfEvent(GDK_WINDOW_XDISPLAY (pizza
->bin_window
),
1134 gtk_pizza_expose_predicate
,
1135 (XPointer
)&GDK_WINDOW_XWINDOW (pizza
->bin_window
)))
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
;
1257 #endif /* __cplusplus */