1 /* ///////////////////////////////////////////////////////////////////////////
3 // Purpose: Native GTK+ widget for wxWindows, based on GtkLayout and
4 // GtkFixed. It makes use of the gravity window property and
5 // therefore does not work with GTK 1.0.
6 // Author: Robert Roebling
8 // Copyright: (c) 1998 Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////// */
13 #define XCheckIfEvent XCHECKIFEVENT
17 #include "wx/gtk/win_gtk.h"
18 #include "gtk/gtksignal.h"
19 #include "gtk/gtkprivate.h"
24 #endif /* __cplusplus */
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
,
81 static void gtk_pizza_expose_area (GtkPizza
*pizza
,
86 static void gtk_pizza_adjustment_changed (GtkAdjustment
*adjustment
,
90 static GdkFilterReturn
gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
93 static GdkFilterReturn
gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
98 static GtkType
gtk_pizza_child_type (GtkContainer
*container
);
100 static void gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
102 GtkAdjustment
*vadj
);
105 static GtkContainerClass
*parent_class
= NULL
;
106 static gboolean gravity_works
;
109 gtk_pizza_get_type ()
111 static guint pizza_type
= 0;
115 GtkTypeInfo pizza_info
=
119 sizeof (GtkPizzaClass
),
120 (GtkClassInitFunc
) gtk_pizza_class_init
,
121 (GtkObjectInitFunc
) gtk_pizza_init
,
122 /* reserved_1 */ NULL
,
123 /* reserved_2 */ NULL
,
124 (GtkClassInitFunc
) NULL
,
126 pizza_type
= gtk_type_unique (gtk_container_get_type (), &pizza_info
);
133 gtk_pizza_class_init (GtkPizzaClass
*klass
)
135 GtkObjectClass
*object_class
;
136 GtkWidgetClass
*widget_class
;
137 GtkContainerClass
*container_class
;
139 object_class
= (GtkObjectClass
*) klass
;
140 widget_class
= (GtkWidgetClass
*) klass
;
141 container_class
= (GtkContainerClass
*) klass
;
142 parent_class
= gtk_type_class (GTK_TYPE_CONTAINER
);
144 widget_class
->map
= gtk_pizza_map
;
145 widget_class
->realize
= gtk_pizza_realize
;
146 widget_class
->unrealize
= gtk_pizza_unrealize
;
147 widget_class
->size_request
= gtk_pizza_size_request
;
148 widget_class
->size_allocate
= gtk_pizza_size_allocate
;
149 widget_class
->draw
= gtk_pizza_draw
;
150 widget_class
->expose_event
= gtk_pizza_expose
;
152 container_class
->add
= gtk_pizza_add
;
153 container_class
->remove
= gtk_pizza_remove
;
154 container_class
->forall
= gtk_pizza_forall
;
156 container_class
->child_type
= gtk_pizza_child_type
;
158 klass
->set_scroll_adjustments
= gtk_pizza_scroll_set_adjustments
;
160 widget_class
->set_scroll_adjustments_signal
=
161 gtk_signal_new ("set_scroll_adjustments",
165 GTK_CLASS_TYPE(object_class
),
169 GTK_SIGNAL_OFFSET (GtkPizzaClass
, set_scroll_adjustments
),
170 gtk_marshal_NONE__POINTER_POINTER
,
171 GTK_TYPE_NONE
, 2, GTK_TYPE_ADJUSTMENT
, GTK_TYPE_ADJUSTMENT
);
175 gtk_pizza_child_type (GtkContainer
*container
)
177 return GTK_TYPE_WIDGET
;
181 gtk_pizza_init (GtkPizza
*pizza
)
183 GTK_WIDGET_UNSET_FLAGS (pizza
, GTK_NO_WINDOW
);
185 pizza
->shadow_type
= GTK_MYSHADOW_NONE
;
187 pizza
->children
= NULL
;
192 pizza
->bin_window
= NULL
;
197 pizza
->configure_serial
= 0;
200 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
202 pizza
->clear_on_draw
= TRUE
;
203 pizza
->use_filter
= TRUE
;
204 pizza
->external_expose
= FALSE
;
212 pizza
= gtk_type_new (gtk_pizza_get_type ());
214 return GTK_WIDGET (pizza
);
218 gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
222 /* We handle scrolling in the wxScrolledWindow, not here. */
226 gtk_pizza_set_shadow_type (GtkPizza
*pizza
,
227 GtkMyShadowType type
)
229 g_return_if_fail (pizza
!= NULL
);
230 g_return_if_fail (GTK_IS_PIZZA (pizza
));
232 if ((GtkMyShadowType
) pizza
->shadow_type
!= type
)
234 pizza
->shadow_type
= type
;
236 if (GTK_WIDGET_VISIBLE (pizza
))
238 gtk_widget_size_allocate (GTK_WIDGET (pizza
), &(GTK_WIDGET (pizza
)->allocation
));
239 gtk_widget_queue_draw (GTK_WIDGET (pizza
));
245 gtk_pizza_set_clear (GtkPizza
*pizza
,
248 g_return_if_fail (pizza
!= NULL
);
249 g_return_if_fail (GTK_IS_PIZZA (pizza
));
251 pizza
->clear_on_draw
= clear
;
255 gtk_pizza_set_filter (GtkPizza
*pizza
,
258 g_return_if_fail (pizza
!= NULL
);
259 g_return_if_fail (GTK_IS_PIZZA (pizza
));
261 pizza
->use_filter
= use
;
265 gtk_pizza_set_external (GtkPizza
*pizza
,
268 g_return_if_fail (pizza
!= NULL
);
269 g_return_if_fail (GTK_IS_PIZZA (pizza
));
271 pizza
->external_expose
= expose
;
275 gtk_pizza_put (GtkPizza
*pizza
,
282 GtkPizzaChild
*child_info
;
284 g_return_if_fail (pizza
!= NULL
);
285 g_return_if_fail (GTK_IS_PIZZA (pizza
));
286 g_return_if_fail (widget
!= NULL
);
288 child_info
= g_new (GtkPizzaChild
, 1);
290 child_info
->widget
= widget
;
293 child_info
->width
= width
;
294 child_info
->height
= height
;
296 pizza
->children
= g_list_append (pizza
->children
, child_info
);
298 gtk_widget_set_parent (widget
, GTK_WIDGET (pizza
));
300 if (GTK_WIDGET_REALIZED (pizza
))
301 gtk_widget_set_parent_window (widget
, pizza
->bin_window
);
303 #ifndef __WXGTK20__ /* FIXME? */
304 if (!IS_ONSCREEN (x
, y
))
305 GTK_PRIVATE_SET_FLAG (widget
, GTK_IS_OFFSCREEN
);
309 if (GTK_WIDGET_REALIZED (pizza))
310 gtk_widget_realize (widget);
313 gtk_widget_set_usize (widget
, width
, height
);
316 if (GTK_WIDGET_VISIBLE (pizza) && GTK_WIDGET_VISIBLE (widget))
318 if (GTK_WIDGET_MAPPED (pizza))
319 gtk_widget_map (widget);
321 gtk_widget_queue_resize (widget);
327 gtk_pizza_move (GtkPizza
*pizza
,
332 GtkPizzaChild
*child
;
335 g_return_if_fail (pizza
!= NULL
);
336 g_return_if_fail (GTK_IS_PIZZA (pizza
));
337 g_return_if_fail (widget
!= NULL
);
339 children
= pizza
->children
;
342 child
= children
->data
;
343 children
= children
->next
;
345 if (child
->widget
== widget
)
347 if ((child
->x
== x
) && (child
->y
== y
))
353 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
354 gtk_widget_queue_resize (widget
);
361 gtk_pizza_resize (GtkPizza
*pizza
,
366 GtkPizzaChild
*child
;
369 g_return_if_fail (pizza
!= NULL
);
370 g_return_if_fail (GTK_IS_PIZZA (pizza
));
371 g_return_if_fail (widget
!= NULL
);
373 children
= pizza
->children
;
376 child
= children
->data
;
377 children
= children
->next
;
379 if (child
->widget
== widget
)
381 if ((child
->width
== width
) && (child
->height
== height
))
384 child
->width
= width
;
385 child
->height
= height
;
387 gtk_widget_set_usize (widget
, width
, height
);
389 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
390 gtk_widget_queue_resize (widget
);
397 gtk_pizza_set_size (GtkPizza
*pizza
,
404 GtkPizzaChild
*child
;
407 g_return_if_fail (pizza
!= NULL
);
408 g_return_if_fail (GTK_IS_PIZZA (pizza
));
409 g_return_if_fail (widget
!= NULL
);
411 children
= pizza
->children
;
414 child
= children
->data
;
415 children
= children
->next
;
417 if (child
->widget
== widget
)
419 if ((child
->x
== x
) &&
421 (child
->width
== width
) &&
422 (child
->height
== height
)) return;
426 child
->width
= width
;
427 child
->height
= height
;
429 gtk_widget_set_usize (widget
, width
, height
);
431 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
432 gtk_widget_queue_resize (widget
);
440 gtk_pizza_child_resized (GtkPizza
*pizza
,
443 GtkPizzaChild
*child
;
446 g_return_val_if_fail (pizza
!= NULL
, FALSE
);
447 g_return_val_if_fail (GTK_IS_PIZZA (pizza
), FALSE
);
448 g_return_val_if_fail (widget
!= NULL
, FALSE
);
450 children
= pizza
->children
;
453 child
= children
->data
;
454 children
= children
->next
;
456 if (child
->widget
== widget
)
458 return ((child
->width
== widget
->allocation
.width
) &&
459 (child
->height
== widget
->allocation
.height
));
467 gtk_pizza_map (GtkWidget
*widget
)
470 GtkPizzaChild
*child
;
473 g_return_if_fail (widget
!= NULL
);
474 g_return_if_fail (GTK_IS_PIZZA (widget
));
476 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
477 pizza
= GTK_PIZZA (widget
);
479 children
= pizza
->children
;
482 child
= children
->data
;
483 children
= children
->next
;
485 if ( GTK_WIDGET_VISIBLE (child
->widget
) &&
486 !GTK_WIDGET_MAPPED (child
->widget
) &&
490 !GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
493 gtk_widget_map (child
->widget
);
497 gdk_window_show (widget
->window
);
498 gdk_window_show (pizza
->bin_window
);
502 gtk_pizza_realize (GtkWidget
*widget
)
505 GdkWindowAttr attributes
;
506 gint attributes_mask
;
507 GtkPizzaChild
*child
;
510 g_return_if_fail (widget
!= NULL
);
511 g_return_if_fail (GTK_IS_PIZZA (widget
));
513 pizza
= GTK_PIZZA (widget
);
515 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
517 attributes
.window_type
= GDK_WINDOW_CHILD
;
519 attributes
.x
= widget
->allocation
.x
;
520 attributes
.y
= widget
->allocation
.y
;
521 attributes
.width
= widget
->allocation
.width
;
522 attributes
.height
= widget
->allocation
.height
;
524 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
526 /* no border, no changes to sizes */
528 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
530 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
533 attributes
.width
-= 2;
534 attributes
.height
-= 2;
537 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
538 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
541 attributes
.width
-= 4;
542 attributes
.height
-= 4;
546 if (attributes
.width
< 2) attributes
.width
= 2;
547 if (attributes
.height
< 2) attributes
.height
= 2;
549 attributes
.wclass
= GDK_INPUT_OUTPUT
;
550 attributes
.visual
= gtk_widget_get_visual (widget
);
551 attributes
.colormap
= gtk_widget_get_colormap (widget
);
552 attributes
.event_mask
= GDK_VISIBILITY_NOTIFY_MASK
;
553 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
555 widget
->window
= gdk_window_new(gtk_widget_get_parent_window (widget
),
556 &attributes
, attributes_mask
);
557 gdk_window_set_user_data (widget
->window
, widget
);
562 attributes
.event_mask
= gtk_widget_get_events (widget
);
563 attributes
.event_mask
|= GDK_EXPOSURE_MASK
|
564 GDK_POINTER_MOTION_MASK
|
565 GDK_POINTER_MOTION_HINT_MASK
|
566 GDK_BUTTON_MOTION_MASK
|
567 GDK_BUTTON1_MOTION_MASK
|
568 GDK_BUTTON2_MOTION_MASK
|
569 GDK_BUTTON3_MOTION_MASK
|
570 GDK_BUTTON_PRESS_MASK
|
571 GDK_BUTTON_RELEASE_MASK
|
573 GDK_KEY_RELEASE_MASK
|
574 GDK_ENTER_NOTIFY_MASK
|
575 GDK_LEAVE_NOTIFY_MASK
|
576 GDK_FOCUS_CHANGE_MASK
;
578 pizza
->bin_window
= gdk_window_new(widget
->window
,
579 &attributes
, attributes_mask
);
580 gdk_window_set_user_data (pizza
->bin_window
, widget
);
582 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
583 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
584 gtk_style_set_background (widget
->style
, pizza
->bin_window
, GTK_STATE_NORMAL
);
586 /* add filters for intercepting visibility and expose events */
587 gdk_window_add_filter (widget
->window
, gtk_pizza_main_filter
, pizza
);
588 gdk_window_add_filter (pizza
->bin_window
, gtk_pizza_filter
, pizza
);
590 /* we NEED gravity or we'll give up */
591 gravity_works
= gdk_window_set_static_gravities (pizza
->bin_window
, TRUE
);
593 /* cannot be done before realisation */
594 children
= pizza
->children
;
597 child
= children
->data
;
598 children
= children
->next
;
600 gtk_widget_set_parent_window (child
->widget
, pizza
->bin_window
);
605 gtk_pizza_unrealize (GtkWidget
*widget
)
609 g_return_if_fail (widget
!= NULL
);
610 g_return_if_fail (GTK_IS_PIZZA (widget
));
612 pizza
= GTK_PIZZA (widget
);
614 gdk_window_set_user_data (pizza
->bin_window
, NULL
);
615 gdk_window_destroy (pizza
->bin_window
);
616 pizza
->bin_window
= NULL
;
618 if (GTK_WIDGET_CLASS (parent_class
)->unrealize
)
619 (* GTK_WIDGET_CLASS (parent_class
)->unrealize
) (widget
);
623 gtk_pizza_size_request (GtkWidget
*widget
,
624 GtkRequisition
*requisition
)
627 GtkPizzaChild
*child
;
629 GtkRequisition child_requisition
;
631 g_return_if_fail (widget
!= NULL
);
632 g_return_if_fail (GTK_IS_PIZZA (widget
));
633 g_return_if_fail (requisition
!= NULL
);
635 pizza
= GTK_PIZZA (widget
);
637 children
= pizza
->children
;
640 child
= children
->data
;
641 children
= children
->next
;
643 if (GTK_WIDGET_VISIBLE (child
->widget
))
645 gtk_widget_size_request (child
->widget
, &child_requisition
);
649 /* request very little, I'm not sure if requesting nothing
650 will always have positive effects on stability... */
651 requisition
->width
= 2;
652 requisition
->height
= 2;
656 gtk_pizza_size_allocate (GtkWidget
*widget
,
657 GtkAllocation
*allocation
)
662 GtkPizzaChild
*child
;
665 g_return_if_fail (widget
!= NULL
);
666 g_return_if_fail (GTK_IS_PIZZA(widget
));
667 g_return_if_fail (allocation
!= NULL
);
669 pizza
= GTK_PIZZA (widget
);
671 widget
->allocation
= *allocation
;
673 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
676 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
681 x
= allocation
->x
+ border
;
682 y
= allocation
->y
+ border
;
683 w
= allocation
->width
- border
*2;
684 h
= allocation
->height
- border
*2;
686 if (GTK_WIDGET_REALIZED (widget
))
688 gdk_window_move_resize( widget
->window
, x
, y
, w
, h
);
689 gdk_window_move_resize( pizza
->bin_window
, 0, 0, w
, h
);
692 children
= pizza
->children
;
695 child
= children
->data
;
696 children
= children
->next
;
698 gtk_pizza_position_child (pizza
, child
);
699 gtk_pizza_allocate_child (pizza
, child
);
704 gtk_pizza_draw (GtkWidget
*widget
,
708 GtkPizzaChild
*child
;
709 GdkRectangle child_area
;
712 g_return_if_fail (widget
!= NULL
);
713 g_return_if_fail (GTK_IS_PIZZA (widget
));
715 pizza
= GTK_PIZZA (widget
);
717 /* Sometimes, We handle all expose events in window.cpp now. */
718 if (pizza
->external_expose
)
721 children
= pizza
->children
;
722 if ( !(GTK_WIDGET_APP_PAINTABLE (widget
)) &&
723 (pizza
->clear_on_draw
))
725 gdk_window_clear_area( pizza
->bin_window
,
726 area
->x
, area
->y
, area
->width
, area
->height
);
731 child
= children
->data
;
732 children
= children
->next
;
734 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
735 gtk_widget_draw (child
->widget
, &child_area
);
740 gtk_pizza_expose (GtkWidget
*widget
,
741 GdkEventExpose
*event
)
744 GtkPizzaChild
*child
;
745 GdkEventExpose child_event
;
748 g_return_val_if_fail (widget
!= NULL
, FALSE
);
749 g_return_val_if_fail (GTK_IS_PIZZA (widget
), FALSE
);
750 g_return_val_if_fail (event
!= NULL
, FALSE
);
752 pizza
= GTK_PIZZA (widget
);
754 /* Sometimes, We handle all expose events in window.cpp now. */
755 if (pizza
->external_expose
)
758 if (event
->window
!= pizza
->bin_window
)
761 children
= pizza
->children
;
764 child
= children
->data
;
765 children
= children
->next
;
767 child_event
= *event
;
769 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
770 GTK_WIDGET_DRAWABLE (child
->widget
) &&
771 gtk_widget_intersect (child
->widget
, &event
->area
, &child_event
.area
))
773 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
781 gtk_pizza_add (GtkContainer
*container
,
784 g_return_if_fail (container
!= NULL
);
785 g_return_if_fail (GTK_IS_PIZZA (container
));
786 g_return_if_fail (widget
!= NULL
);
788 gtk_pizza_put (GTK_PIZZA (container
), widget
, 0, 0, 20, 20 );
792 gtk_pizza_remove (GtkContainer
*container
,
796 GtkPizzaChild
*child
;
799 g_return_if_fail (container
!= NULL
);
800 g_return_if_fail (GTK_IS_PIZZA (container
));
801 g_return_if_fail (widget
!= NULL
);
803 pizza
= GTK_PIZZA (container
);
805 children
= pizza
->children
;
808 child
= children
->data
;
810 if (child
->widget
== widget
)
812 gtk_widget_unparent (widget
);
814 /* security checks */
815 g_return_if_fail (GTK_IS_WIDGET (widget
));
817 pizza
->children
= g_list_remove_link (pizza
->children
, children
);
818 g_list_free (children
);
821 /* security checks */
822 g_return_if_fail (GTK_IS_WIDGET (widget
));
825 GTK_PRIVATE_UNSET_FLAG (widget
, GTK_IS_OFFSCREEN
);
831 children
= children
->next
;
836 gtk_pizza_forall (GtkContainer
*container
,
837 gboolean include_internals
,
838 GtkCallback callback
,
839 gpointer callback_data
)
842 GtkPizzaChild
*child
;
845 g_return_if_fail (container
!= NULL
);
846 g_return_if_fail (GTK_IS_PIZZA (container
));
847 g_return_if_fail (callback
!= NULL
);
849 pizza
= GTK_PIZZA (container
);
851 children
= pizza
->children
;
854 child
= children
->data
;
855 children
= children
->next
;
857 (* callback
) (child
->widget
, callback_data
);
862 /* Operations on children
866 gtk_pizza_position_child (GtkPizza
*pizza
,
867 GtkPizzaChild
*child
)
872 x
= child
->x
- pizza
->xoffset
;
873 y
= child
->y
- pizza
->yoffset
;
875 if (IS_ONSCREEN (x
,y
))
877 if (GTK_WIDGET_MAPPED (pizza
) &&
878 GTK_WIDGET_VISIBLE (child
->widget
))
880 if (!GTK_WIDGET_MAPPED (child
->widget
))
881 gtk_widget_map (child
->widget
);
885 if (GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
886 GTK_PRIVATE_UNSET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
892 if (!GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
893 GTK_PRIVATE_SET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
896 if (GTK_WIDGET_MAPPED (child
->widget
))
897 gtk_widget_unmap (child
->widget
);
902 gtk_pizza_allocate_child (GtkPizza
*pizza
,
903 GtkPizzaChild
*child
)
905 GtkAllocation allocation
;
906 GtkRequisition requisition
;
908 allocation
.x
= child
->x
- pizza
->xoffset
;
909 allocation
.y
= child
->y
- pizza
->yoffset
;
910 gtk_widget_get_child_requisition (child
->widget
, &requisition
);
911 allocation
.width
= requisition
.width
;
912 allocation
.height
= requisition
.height
;
914 gtk_widget_size_allocate (child
->widget
, &allocation
);
918 gtk_pizza_position_children (GtkPizza
*pizza
)
922 tmp_list
= pizza
->children
;
925 GtkPizzaChild
*child
= tmp_list
->data
;
926 tmp_list
= tmp_list
->next
;
928 gtk_pizza_position_child (pizza
, child
);
933 gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
936 GtkPizzaAdjData
*data
= cb_data
;
938 widget
->allocation
.x
+= data
->dx
;
939 widget
->allocation
.y
+= data
->dy
;
941 if (GTK_WIDGET_NO_WINDOW (widget
) && GTK_IS_CONTAINER (widget
))
943 gtk_container_forall (GTK_CONTAINER (widget
),
944 gtk_pizza_adjust_allocations_recurse
,
950 gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
955 GtkPizzaAdjData data
;
960 tmp_list
= pizza
->children
;
963 GtkPizzaChild
*child
= tmp_list
->data
;
964 tmp_list
= tmp_list
->next
;
966 child
->widget
->allocation
.x
+= dx
;
967 child
->widget
->allocation
.y
+= dy
;
969 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
970 GTK_IS_CONTAINER (child
->widget
))
972 gtk_container_forall (GTK_CONTAINER (child
->widget
),
973 gtk_pizza_adjust_allocations_recurse
,
983 /* Send a synthetic expose event to the widget
986 gtk_pizza_expose_area (GtkPizza
*pizza
,
987 gint x
, gint y
, gint width
, gint height
)
989 if (pizza
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
991 GdkEventExpose event
;
993 event
.type
= GDK_EXPOSE
;
994 event
.send_event
= TRUE
;
995 event
.window
= pizza
->bin_window
;
1000 event
.area
.width
= width
;
1001 event
.area
.height
= height
;
1003 gdk_window_ref (event
.window
);
1004 gtk_widget_event (GTK_WIDGET (pizza
), (GdkEvent
*)&event
);
1005 gdk_window_unref (event
.window
);
1010 /* This function is used to find events to process while scrolling
1014 gtk_pizza_expose_predicate (Display
*display
,
1018 if ((xevent
->type
== Expose
) ||
1019 ((xevent
->xany
.window
== *(Window
*)arg
) &&
1020 (xevent
->type
== ConfigureNotify
)))
1026 /* This is the main routine to do the scrolling. Scrolling is
1027 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
1028 * a few modifications.
1030 * The main improvement is that we keep track of whether we
1031 * are obscured or not. If not, we ignore the generated expose
1032 * events and instead do the exposes ourself, without having
1033 * to wait for a roundtrip to the server. This also provides
1034 * a limited form of expose-event compression, since we do
1035 * the affected area as one big chunk.
1039 gtk_pizza_scroll (GtkPizza
*pizza
, gint dx
, gint dy
)
1044 gint x
,y
,w
,h
,border
;
1046 widget
= GTK_WIDGET (pizza
);
1048 pizza
->xoffset
+= dx
;
1049 pizza
->yoffset
+= dy
;
1051 if (!GTK_WIDGET_MAPPED (pizza
))
1053 gtk_pizza_position_children (pizza
);
1057 gtk_pizza_adjust_allocations (pizza
, -dx
, -dy
);
1059 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
1062 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
1069 w
= widget
->allocation
.width
- 2*border
;
1070 h
= widget
->allocation
.height
- 2*border
;
1076 gdk_window_resize (pizza
->bin_window
,
1079 gdk_window_move (pizza
->bin_window
, x
-dx
, y
);
1080 gdk_window_move_resize (pizza
->bin_window
, x
, y
, w
, h
);
1091 gdk_window_move_resize (pizza
->bin_window
,
1096 gdk_window_move (pizza
->bin_window
, x
, y
);
1097 gdk_window_resize (pizza
->bin_window
, w
, h
);
1109 gdk_window_resize (pizza
->bin_window
, w
, h
+ dy
);
1110 gdk_window_move (pizza
->bin_window
, x
, y
-dy
);
1111 gdk_window_move_resize (pizza
->bin_window
,
1123 gdk_window_move_resize (pizza
->bin_window
,
1124 x
, y
+dy
, w
, h
- dy
);
1125 gdk_window_move (pizza
->bin_window
, x
, y
);
1126 gdk_window_resize (pizza
->bin_window
, w
, h
);
1134 gtk_pizza_position_children (pizza
);
1137 while (XCheckIfEvent(GDK_WINDOW_XDISPLAY (pizza
->bin_window
),
1139 gtk_pizza_expose_predicate
,
1140 (XPointer
)&GDK_WINDOW_XWINDOW (pizza
->bin_window
)))
1143 GtkWidget
*event_widget
;
1145 if ((xevent
.xany
.window
== GDK_WINDOW_XWINDOW (pizza
->bin_window
)) )
1146 gtk_pizza_filter (&xevent
, &event
, pizza
);
1148 if (xevent
.type
== Expose
)
1150 event
.expose
.window
= gdk_window_lookup (xevent
.xany
.window
);
1151 gdk_window_get_user_data (event
.expose
.window
,
1152 (gpointer
*)&event_widget
);
1156 event
.expose
.type
= GDK_EXPOSE
;
1157 event
.expose
.area
.x
= xevent
.xexpose
.x
;
1158 event
.expose
.area
.y
= xevent
.xexpose
.y
;
1159 event
.expose
.area
.width
= xevent
.xexpose
.width
;
1160 event
.expose
.area
.height
= xevent
.xexpose
.height
;
1161 event
.expose
.count
= xevent
.xexpose
.count
;
1163 gdk_window_ref (event
.expose
.window
);
1164 gtk_widget_event (event_widget
, &event
);
1165 gdk_window_unref (event
.expose
.window
);
1171 /* The main event filter. Actually, we probably don't really need
1172 * to install this as a filter at all, since we are calling it
1173 * directly above in the expose-handling hack. But in case scrollbars
1174 * are fixed up in some manner...
1176 * This routine identifies expose events that are generated when
1177 * we've temporarily moved the bin_window_origin, and translates
1178 * them or discards them, depending on whether we are obscured
1181 static GdkFilterReturn
1182 gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
1189 xevent
= (XEvent
*)gdk_xevent
;
1191 pizza
= GTK_PIZZA (data
);
1193 if (!pizza
->use_filter
)
1194 return GDK_FILTER_CONTINUE
;
1196 switch (xevent
->type
)
1199 if (xevent
->xexpose
.serial
== pizza
->configure_serial
)
1201 xevent
->xexpose
.x
+= pizza
->scroll_x
;
1202 xevent
->xexpose
.y
+= pizza
->scroll_y
;
1206 case ConfigureNotify
:
1208 pizza
->configure_serial
= xevent
->xconfigure
.serial
;
1209 pizza
->scroll_x
= xevent
->xconfigure
.x
;
1210 pizza
->scroll_y
= xevent
->xconfigure
.y
;
1215 return GDK_FILTER_CONTINUE
;
1218 /* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
1219 * there is no corresponding event in GTK, so we have
1220 * to get the events from a filter
1222 static GdkFilterReturn
1223 gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
1230 xevent
= (XEvent
*)gdk_xevent
;
1231 pizza
= GTK_PIZZA (data
);
1233 if (!pizza
->use_filter
)
1234 return GDK_FILTER_CONTINUE
;
1236 if (xevent
->type
== VisibilityNotify
)
1238 switch (xevent
->xvisibility
.state
)
1240 case VisibilityFullyObscured
:
1241 pizza
->visibility
= GDK_VISIBILITY_FULLY_OBSCURED
;
1244 case VisibilityPartiallyObscured
:
1245 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
1248 case VisibilityUnobscured
:
1249 pizza
->visibility
= GDK_VISIBILITY_UNOBSCURED
;
1253 return GDK_FILTER_REMOVE
;
1256 return GDK_FILTER_CONTINUE
;
1262 #endif /* __cplusplus */