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 /////////////////////////////////////////////////////////////////////////// */
12 #include "wx/gtk/win_gtk.h"
14 #define gtk_widget_get_child_requisition gtk_widget_get_child_requisitio
15 #define gtk_marshal_NONE__POINTER_POINTER gtk_marshal_NONE__POINTER_POINT
17 #include "gtk/gtksignal.h"
18 #include "gtk/gtkprivate.h"
23 #endif /* __cplusplus */
26 #include <X11/Xutil.h>
27 #include <X11/Xatom.h>
29 #define IS_ONSCREEN(x,y) ((x >= G_MINSHORT) && (x <= G_MAXSHORT) && \
30 (y >= G_MINSHORT) && (y <= G_MAXSHORT))
32 typedef struct _GtkPizzaAdjData GtkPizzaAdjData
;
34 struct _GtkPizzaAdjData
40 static void gtk_pizza_class_init (GtkPizzaClass
*klass
);
41 static void gtk_pizza_init (GtkPizza
*pizza
);
43 static void gtk_pizza_realize (GtkWidget
*widget
);
44 static void gtk_pizza_unrealize (GtkWidget
*widget
);
46 static void gtk_pizza_map (GtkWidget
*widget
);
48 static void gtk_pizza_size_request (GtkWidget
*widget
,
49 GtkRequisition
*requisition
);
50 static void gtk_pizza_size_allocate (GtkWidget
*widget
,
51 GtkAllocation
*allocation
);
52 static void gtk_pizza_draw (GtkWidget
*widget
,
54 static gint
gtk_pizza_expose (GtkWidget
*widget
,
55 GdkEventExpose
*event
);
56 static void gtk_pizza_add (GtkContainer
*container
,
58 static void gtk_pizza_remove (GtkContainer
*container
,
60 static void gtk_pizza_forall (GtkContainer
*container
,
61 gboolean include_internals
,
63 gpointer callback_data
);
65 static void gtk_pizza_position_child (GtkPizza
*pizza
,
66 GtkPizzaChild
*child
);
67 static void gtk_pizza_allocate_child (GtkPizza
*pizza
,
68 GtkPizzaChild
*child
);
69 static void gtk_pizza_position_children (GtkPizza
*pizza
);
71 static void gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
73 static void gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
78 static void gtk_pizza_expose_area (GtkPizza
*pizza
,
83 static void gtk_pizza_adjustment_changed (GtkAdjustment
*adjustment
,
85 static GdkFilterReturn
gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
88 static GdkFilterReturn
gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
93 static GtkType
gtk_pizza_child_type (GtkContainer
*container
);
95 static void gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
100 static GtkContainerClass
*parent_class
= NULL
;
101 static gboolean gravity_works
;
104 gtk_pizza_get_type ()
106 static guint pizza_type
= 0;
110 GtkTypeInfo pizza_info
=
114 sizeof (GtkPizzaClass
),
115 (GtkClassInitFunc
) gtk_pizza_class_init
,
116 (GtkObjectInitFunc
) gtk_pizza_init
,
117 /* reserved_1 */ NULL
,
118 /* reserved_2 */ NULL
,
119 (GtkClassInitFunc
) NULL
,
121 pizza_type
= gtk_type_unique (gtk_container_get_type (), &pizza_info
);
128 gtk_pizza_class_init (GtkPizzaClass
*klass
)
130 GtkObjectClass
*object_class
;
131 GtkWidgetClass
*widget_class
;
132 GtkContainerClass
*container_class
;
134 object_class
= (GtkObjectClass
*) klass
;
135 widget_class
= (GtkWidgetClass
*) klass
;
136 container_class
= (GtkContainerClass
*) klass
;
137 parent_class
= gtk_type_class (GTK_TYPE_CONTAINER
);
139 widget_class
->map
= gtk_pizza_map
;
140 widget_class
->realize
= gtk_pizza_realize
;
141 widget_class
->unrealize
= gtk_pizza_unrealize
;
142 widget_class
->size_request
= gtk_pizza_size_request
;
143 widget_class
->size_allocate
= gtk_pizza_size_allocate
;
144 widget_class
->draw
= gtk_pizza_draw
;
145 widget_class
->expose_event
= gtk_pizza_expose
;
147 container_class
->add
= gtk_pizza_add
;
148 container_class
->remove
= gtk_pizza_remove
;
149 container_class
->forall
= gtk_pizza_forall
;
151 container_class
->child_type
= gtk_pizza_child_type
;
153 klass
->set_scroll_adjustments
= gtk_pizza_scroll_set_adjustments
;
155 widget_class
->set_scroll_adjustments_signal
=
156 gtk_signal_new ("set_scroll_adjustments",
159 GTK_SIGNAL_OFFSET (GtkPizzaClass
, set_scroll_adjustments
),
160 gtk_marshal_NONE__POINTER_POINTER
,
161 GTK_TYPE_NONE
, 2, GTK_TYPE_ADJUSTMENT
, GTK_TYPE_ADJUSTMENT
);
165 gtk_pizza_child_type (GtkContainer
*container
)
167 return GTK_TYPE_WIDGET
;
171 gtk_pizza_init (GtkPizza
*pizza
)
173 GTK_WIDGET_UNSET_FLAGS (pizza
, GTK_NO_WINDOW
);
175 pizza
->shadow_type
= GTK_MYSHADOW_NONE
;
177 pizza
->children
= NULL
;
182 pizza
->bin_window
= NULL
;
187 pizza
->configure_serial
= 0;
190 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
192 pizza
->clear_on_draw
= TRUE
;
193 pizza
->use_filter
= TRUE
;
194 pizza
->external_expose
= FALSE
;
202 pizza
= gtk_type_new (gtk_pizza_get_type ());
204 return GTK_WIDGET (pizza
);
208 gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
212 /* We handle scrolling in the wxScrolledWindow, not here. */
216 gtk_pizza_set_shadow_type (GtkPizza
*pizza
,
217 GtkMyShadowType type
)
219 g_return_if_fail (pizza
!= NULL
);
220 g_return_if_fail (GTK_IS_PIZZA (pizza
));
222 if ((GtkMyShadowType
) pizza
->shadow_type
!= type
)
224 pizza
->shadow_type
= type
;
226 if (GTK_WIDGET_VISIBLE (pizza
))
228 gtk_widget_size_allocate (GTK_WIDGET (pizza
), &(GTK_WIDGET (pizza
)->allocation
));
229 gtk_widget_queue_draw (GTK_WIDGET (pizza
));
235 gtk_pizza_set_clear (GtkPizza
*pizza
,
238 g_return_if_fail (pizza
!= NULL
);
239 g_return_if_fail (GTK_IS_PIZZA (pizza
));
241 pizza
->clear_on_draw
= clear
;
245 gtk_pizza_set_filter (GtkPizza
*pizza
,
248 g_return_if_fail (pizza
!= NULL
);
249 g_return_if_fail (GTK_IS_PIZZA (pizza
));
251 pizza
->use_filter
= use
;
255 gtk_pizza_set_external (GtkPizza
*pizza
,
258 g_return_if_fail (pizza
!= NULL
);
259 g_return_if_fail (GTK_IS_PIZZA (pizza
));
261 pizza
->external_expose
= expose
;
265 gtk_pizza_put (GtkPizza
*pizza
,
272 GtkPizzaChild
*child_info
;
274 g_return_if_fail (pizza
!= NULL
);
275 g_return_if_fail (GTK_IS_PIZZA (pizza
));
276 g_return_if_fail (widget
!= NULL
);
278 child_info
= g_new (GtkPizzaChild
, 1);
280 child_info
->widget
= widget
;
283 child_info
->width
= width
;
284 child_info
->height
= height
;
286 pizza
->children
= g_list_append (pizza
->children
, child_info
);
288 gtk_widget_set_parent (widget
, GTK_WIDGET (pizza
));
290 if (GTK_WIDGET_REALIZED (pizza
))
291 gtk_widget_set_parent_window (widget
, pizza
->bin_window
);
293 if (!IS_ONSCREEN (x
, y
))
294 GTK_PRIVATE_SET_FLAG (widget
, GTK_IS_OFFSCREEN
);
297 if (GTK_WIDGET_REALIZED (pizza))
298 gtk_widget_realize (widget);
301 gtk_widget_set_usize (widget
, width
, height
);
304 if (GTK_WIDGET_VISIBLE (pizza) && GTK_WIDGET_VISIBLE (widget))
306 if (GTK_WIDGET_MAPPED (pizza))
307 gtk_widget_map (widget);
309 gtk_widget_queue_resize (widget);
315 gtk_pizza_move (GtkPizza
*pizza
,
320 GtkPizzaChild
*child
;
323 g_return_if_fail (pizza
!= NULL
);
324 g_return_if_fail (GTK_IS_PIZZA (pizza
));
325 g_return_if_fail (widget
!= NULL
);
327 children
= pizza
->children
;
330 child
= children
->data
;
331 children
= children
->next
;
333 if (child
->widget
== widget
)
335 if ((child
->x
== x
) && (child
->y
== y
))
341 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
342 gtk_widget_queue_resize (widget
);
349 gtk_pizza_resize (GtkPizza
*pizza
,
354 GtkPizzaChild
*child
;
357 g_return_if_fail (pizza
!= NULL
);
358 g_return_if_fail (GTK_IS_PIZZA (pizza
));
359 g_return_if_fail (widget
!= NULL
);
361 children
= pizza
->children
;
364 child
= children
->data
;
365 children
= children
->next
;
367 if (child
->widget
== widget
)
369 if ((child
->width
== width
) && (child
->height
== height
))
372 child
->width
= width
;
373 child
->height
= height
;
375 gtk_widget_set_usize (widget
, width
, height
);
377 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
378 gtk_widget_queue_resize (widget
);
385 gtk_pizza_set_size (GtkPizza
*pizza
,
392 GtkPizzaChild
*child
;
395 g_return_if_fail (pizza
!= NULL
);
396 g_return_if_fail (GTK_IS_PIZZA (pizza
));
397 g_return_if_fail (widget
!= NULL
);
399 children
= pizza
->children
;
402 child
= children
->data
;
403 children
= children
->next
;
405 if (child
->widget
== widget
)
407 if ((child
->x
== x
) &&
409 (child
->width
== width
) &&
410 (child
->height
== height
)) return;
414 child
->width
= width
;
415 child
->height
= height
;
417 gtk_widget_set_usize (widget
, width
, height
);
419 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
420 gtk_widget_queue_resize (widget
);
428 gtk_pizza_child_resized (GtkPizza
*pizza
,
431 GtkPizzaChild
*child
;
434 g_return_val_if_fail (pizza
!= NULL
, FALSE
);
435 g_return_val_if_fail (GTK_IS_PIZZA (pizza
), FALSE
);
436 g_return_val_if_fail (widget
!= NULL
, FALSE
);
438 children
= pizza
->children
;
441 child
= children
->data
;
442 children
= children
->next
;
444 if (child
->widget
== widget
)
446 return ((child
->width
== widget
->allocation
.width
) &&
447 (child
->height
== widget
->allocation
.height
));
455 gtk_pizza_map (GtkWidget
*widget
)
458 GtkPizzaChild
*child
;
461 g_return_if_fail (widget
!= NULL
);
462 g_return_if_fail (GTK_IS_PIZZA (widget
));
464 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
465 pizza
= GTK_PIZZA (widget
);
467 children
= pizza
->children
;
470 child
= children
->data
;
471 children
= children
->next
;
473 if ( GTK_WIDGET_VISIBLE (child
->widget
) &&
474 !GTK_WIDGET_MAPPED (child
->widget
) &&
475 !GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
477 gtk_widget_map (child
->widget
);
481 gdk_window_show (widget
->window
);
482 gdk_window_show (pizza
->bin_window
);
486 gtk_pizza_realize (GtkWidget
*widget
)
489 GdkWindowAttr attributes
;
490 gint attributes_mask
;
491 GtkPizzaChild
*child
;
494 g_return_if_fail (widget
!= NULL
);
495 g_return_if_fail (GTK_IS_PIZZA (widget
));
497 pizza
= GTK_PIZZA (widget
);
499 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
501 attributes
.window_type
= GDK_WINDOW_CHILD
;
503 attributes
.x
= widget
->allocation
.x
;
504 attributes
.y
= widget
->allocation
.y
;
505 attributes
.width
= widget
->allocation
.width
;
506 attributes
.height
= widget
->allocation
.height
;
508 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
510 /* no border, no changes to sizes */
512 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
514 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
517 attributes
.width
-= 2;
518 attributes
.height
-= 2;
521 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
522 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
525 attributes
.width
-= 4;
526 attributes
.height
-= 4;
530 if (attributes
.width
< 2) attributes
.width
= 2;
531 if (attributes
.height
< 2) attributes
.height
= 2;
533 attributes
.wclass
= GDK_INPUT_OUTPUT
;
534 attributes
.visual
= gtk_widget_get_visual (widget
);
535 attributes
.colormap
= gtk_widget_get_colormap (widget
);
536 attributes
.event_mask
=
537 GDK_VISIBILITY_NOTIFY_MASK
;
538 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
540 widget
->window
= gdk_window_new(gtk_widget_get_parent_window (widget
),
541 &attributes
, attributes_mask
);
542 gdk_window_set_user_data (widget
->window
, widget
);
547 attributes
.event_mask
= gtk_widget_get_events (widget
);
548 attributes
.event_mask
|=
550 GDK_POINTER_MOTION_MASK
|
551 GDK_POINTER_MOTION_HINT_MASK
|
552 GDK_BUTTON_MOTION_MASK
|
553 GDK_BUTTON1_MOTION_MASK
|
554 GDK_BUTTON2_MOTION_MASK
|
555 GDK_BUTTON3_MOTION_MASK
|
556 GDK_BUTTON_PRESS_MASK
|
557 GDK_BUTTON_RELEASE_MASK
|
559 GDK_KEY_RELEASE_MASK
|
560 GDK_ENTER_NOTIFY_MASK
|
561 GDK_LEAVE_NOTIFY_MASK
|
562 GDK_FOCUS_CHANGE_MASK
;
564 pizza
->bin_window
= gdk_window_new(widget
->window
,
565 &attributes
, attributes_mask
);
566 gdk_window_set_user_data (pizza
->bin_window
, widget
);
568 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
569 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
570 gtk_style_set_background (widget
->style
, pizza
->bin_window
, GTK_STATE_NORMAL
);
572 /* add filters for intercepting visibility and expose events */
573 gdk_window_add_filter (widget
->window
, gtk_pizza_main_filter
, pizza
);
574 gdk_window_add_filter (pizza
->bin_window
, gtk_pizza_filter
, pizza
);
576 /* we NEED gravity or we'll give up */
577 gravity_works
= gdk_window_set_static_gravities (pizza
->bin_window
, TRUE
);
579 /* cannot be done before realisation */
580 children
= pizza
->children
;
583 child
= children
->data
;
584 children
= children
->next
;
586 gtk_widget_set_parent_window (child
->widget
, pizza
->bin_window
);
591 gtk_pizza_unrealize (GtkWidget
*widget
)
595 g_return_if_fail (widget
!= NULL
);
596 g_return_if_fail (GTK_IS_PIZZA (widget
));
598 pizza
= GTK_PIZZA (widget
);
600 gdk_window_set_user_data (pizza
->bin_window
, NULL
);
601 gdk_window_destroy (pizza
->bin_window
);
602 pizza
->bin_window
= NULL
;
604 if (GTK_WIDGET_CLASS (parent_class
)->unrealize
)
605 (* GTK_WIDGET_CLASS (parent_class
)->unrealize
) (widget
);
609 gtk_pizza_size_request (GtkWidget
*widget
,
610 GtkRequisition
*requisition
)
613 GtkPizzaChild
*child
;
615 GtkRequisition child_requisition
;
617 g_return_if_fail (widget
!= NULL
);
618 g_return_if_fail (GTK_IS_PIZZA (widget
));
619 g_return_if_fail (requisition
!= NULL
);
621 pizza
= GTK_PIZZA (widget
);
623 children
= pizza
->children
;
626 child
= children
->data
;
627 children
= children
->next
;
629 if (GTK_WIDGET_VISIBLE (child
->widget
))
631 gtk_widget_size_request (child
->widget
, &child_requisition
);
635 /* request very little, I'm not sure if requesting nothing
636 will always have positive effects on stability... */
637 requisition
->width
= 2;
638 requisition
->height
= 2;
642 gtk_pizza_size_allocate (GtkWidget
*widget
,
643 GtkAllocation
*allocation
)
648 GtkPizzaChild
*child
;
651 g_return_if_fail (widget
!= NULL
);
652 g_return_if_fail (GTK_IS_PIZZA(widget
));
653 g_return_if_fail (allocation
!= NULL
);
655 pizza
= GTK_PIZZA (widget
);
657 widget
->allocation
= *allocation
;
659 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
662 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
667 x
= allocation
->x
+ border
;
668 y
= allocation
->y
+ border
;
669 w
= allocation
->width
- border
*2;
670 h
= allocation
->height
- border
*2;
672 if (GTK_WIDGET_REALIZED (widget
))
674 gdk_window_move_resize( widget
->window
, x
, y
, w
, h
);
675 gdk_window_move_resize( pizza
->bin_window
, 0, 0, w
, h
);
678 children
= pizza
->children
;
681 child
= children
->data
;
682 children
= children
->next
;
684 gtk_pizza_position_child (pizza
, child
);
685 gtk_pizza_allocate_child (pizza
, child
);
690 gtk_pizza_draw (GtkWidget
*widget
,
694 GtkPizzaChild
*child
;
695 GdkRectangle child_area
;
698 g_return_if_fail (widget
!= NULL
);
699 g_return_if_fail (GTK_IS_PIZZA (widget
));
701 pizza
= GTK_PIZZA (widget
);
703 /* Sometimes, We handle all expose events in window.cpp now. */
704 if (pizza
->external_expose
)
707 children
= pizza
->children
;
708 if ( !(GTK_WIDGET_APP_PAINTABLE (widget
)) &&
709 (pizza
->clear_on_draw
))
711 gdk_window_clear_area( pizza
->bin_window
,
712 area
->x
, area
->y
, area
->width
, area
->height
);
717 child
= children
->data
;
718 children
= children
->next
;
720 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
721 gtk_widget_draw (child
->widget
, &child_area
);
726 gtk_pizza_expose (GtkWidget
*widget
,
727 GdkEventExpose
*event
)
730 GtkPizzaChild
*child
;
731 GdkEventExpose child_event
;
734 g_return_val_if_fail (widget
!= NULL
, FALSE
);
735 g_return_val_if_fail (GTK_IS_PIZZA (widget
), FALSE
);
736 g_return_val_if_fail (event
!= NULL
, FALSE
);
738 pizza
= GTK_PIZZA (widget
);
740 /* Sometimes, We handle all expose events in window.cpp now. */
741 if (pizza
->external_expose
)
744 if (event
->window
!= pizza
->bin_window
)
747 children
= pizza
->children
;
750 child
= children
->data
;
751 children
= children
->next
;
753 child_event
= *event
;
755 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
756 GTK_WIDGET_DRAWABLE (child
->widget
) &&
757 gtk_widget_intersect (child
->widget
, &event
->area
, &child_event
.area
))
759 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
767 gtk_pizza_add (GtkContainer
*container
,
770 g_return_if_fail (container
!= NULL
);
771 g_return_if_fail (GTK_IS_PIZZA (container
));
772 g_return_if_fail (widget
!= NULL
);
774 gtk_pizza_put (GTK_PIZZA (container
), widget
, 0, 0, 20, 20 );
778 gtk_pizza_remove (GtkContainer
*container
,
782 GtkPizzaChild
*child
;
785 g_return_if_fail (container
!= NULL
);
786 g_return_if_fail (GTK_IS_PIZZA (container
));
787 g_return_if_fail (widget
!= NULL
);
789 pizza
= GTK_PIZZA (container
);
791 children
= pizza
->children
;
794 child
= children
->data
;
796 if (child
->widget
== widget
)
798 gtk_widget_unparent (widget
);
800 /* security checks */
801 g_return_if_fail (GTK_IS_WIDGET (widget
));
803 pizza
->children
= g_list_remove_link (pizza
->children
, children
);
804 g_list_free (children
);
807 /* security checks */
808 g_return_if_fail (GTK_IS_WIDGET (widget
));
810 GTK_PRIVATE_UNSET_FLAG (widget
, GTK_IS_OFFSCREEN
);
815 children
= children
->next
;
820 gtk_pizza_forall (GtkContainer
*container
,
821 gboolean include_internals
,
822 GtkCallback callback
,
823 gpointer callback_data
)
826 GtkPizzaChild
*child
;
829 g_return_if_fail (container
!= NULL
);
830 g_return_if_fail (GTK_IS_PIZZA (container
));
831 g_return_if_fail (callback
!= NULL
);
833 pizza
= GTK_PIZZA (container
);
835 children
= pizza
->children
;
838 child
= children
->data
;
839 children
= children
->next
;
841 (* callback
) (child
->widget
, callback_data
);
846 /* Operations on children
850 gtk_pizza_position_child (GtkPizza
*pizza
,
851 GtkPizzaChild
*child
)
856 x
= child
->x
- pizza
->xoffset
;
857 y
= child
->y
- pizza
->yoffset
;
859 if (IS_ONSCREEN (x
,y
))
861 if (GTK_WIDGET_MAPPED (pizza
) &&
862 GTK_WIDGET_VISIBLE (child
->widget
))
864 if (!GTK_WIDGET_MAPPED (child
->widget
))
865 gtk_widget_map (child
->widget
);
868 if (GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
869 GTK_PRIVATE_UNSET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
873 if (!GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
874 GTK_PRIVATE_SET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
876 if (GTK_WIDGET_MAPPED (child
->widget
))
877 gtk_widget_unmap (child
->widget
);
882 gtk_pizza_allocate_child (GtkPizza
*pizza
,
883 GtkPizzaChild
*child
)
885 GtkAllocation allocation
;
886 GtkRequisition requisition
;
888 allocation
.x
= child
->x
- pizza
->xoffset
;
889 allocation
.y
= child
->y
- pizza
->yoffset
;
890 gtk_widget_get_child_requisition (child
->widget
, &requisition
);
891 allocation
.width
= requisition
.width
;
892 allocation
.height
= requisition
.height
;
894 gtk_widget_size_allocate (child
->widget
, &allocation
);
898 gtk_pizza_position_children (GtkPizza
*pizza
)
902 tmp_list
= pizza
->children
;
905 GtkPizzaChild
*child
= tmp_list
->data
;
906 tmp_list
= tmp_list
->next
;
908 gtk_pizza_position_child (pizza
, child
);
913 gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
916 GtkPizzaAdjData
*data
= cb_data
;
918 widget
->allocation
.x
+= data
->dx
;
919 widget
->allocation
.y
+= data
->dy
;
921 if (GTK_WIDGET_NO_WINDOW (widget
) && GTK_IS_CONTAINER (widget
))
923 gtk_container_forall (GTK_CONTAINER (widget
),
924 gtk_pizza_adjust_allocations_recurse
,
930 gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
935 GtkPizzaAdjData data
;
940 tmp_list
= pizza
->children
;
943 GtkPizzaChild
*child
= tmp_list
->data
;
944 tmp_list
= tmp_list
->next
;
946 child
->widget
->allocation
.x
+= dx
;
947 child
->widget
->allocation
.y
+= dy
;
949 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
950 GTK_IS_CONTAINER (child
->widget
))
952 gtk_container_forall (GTK_CONTAINER (child
->widget
),
953 gtk_pizza_adjust_allocations_recurse
,
961 /* Send a synthetic expose event to the widget
964 gtk_pizza_expose_area (GtkPizza
*pizza
,
965 gint x
, gint y
, gint width
, gint height
)
967 if (pizza
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
969 GdkEventExpose event
;
971 event
.type
= GDK_EXPOSE
;
972 event
.send_event
= TRUE
;
973 event
.window
= pizza
->bin_window
;
978 event
.area
.width
= width
;
979 event
.area
.height
= height
;
981 gdk_window_ref (event
.window
);
982 gtk_widget_event (GTK_WIDGET (pizza
), (GdkEvent
*)&event
);
983 gdk_window_unref (event
.window
);
987 /* This function is used to find events to process while scrolling
991 gtk_pizza_expose_predicate (Display
*display
,
995 if ((xevent
->type
== Expose
) ||
996 ((xevent
->xany
.window
== *(Window
*)arg
) &&
997 (xevent
->type
== ConfigureNotify
)))
1003 /* This is the main routine to do the scrolling. Scrolling is
1004 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
1005 * a few modifications.
1007 * The main improvement is that we keep track of whether we
1008 * are obscured or not. If not, we ignore the generated expose
1009 * events and instead do the exposes ourself, without having
1010 * to wait for a roundtrip to the server. This also provides
1011 * a limited form of expose-event compression, since we do
1012 * the affected area as one big chunk.
1016 gtk_pizza_scroll (GtkPizza
*pizza
, gint dx
, gint dy
)
1021 gint x
,y
,w
,h
,border
;
1023 widget
= GTK_WIDGET (pizza
);
1025 pizza
->xoffset
+= dx
;
1026 pizza
->yoffset
+= dy
;
1028 if (!GTK_WIDGET_MAPPED (pizza
))
1030 gtk_pizza_position_children (pizza
);
1034 gtk_pizza_adjust_allocations (pizza
, -dx
, -dy
);
1036 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
1039 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
1046 w
= widget
->allocation
.width
- 2*border
;
1047 h
= widget
->allocation
.height
- 2*border
;
1053 gdk_window_resize (pizza
->bin_window
,
1056 gdk_window_move (pizza
->bin_window
, x
-dx
, y
);
1057 gdk_window_move_resize (pizza
->bin_window
, x
, y
, w
, h
);
1064 gtk_pizza_expose_area (pizza
,
1065 MAX ((gint
)w
- dx
, 0),
1074 gdk_window_move_resize (pizza
->bin_window
,
1079 gdk_window_move (pizza
->bin_window
, x
, y
);
1080 gdk_window_resize (pizza
->bin_window
, w
, h
);
1087 gtk_pizza_expose_area (pizza
,
1098 gdk_window_resize (pizza
->bin_window
, w
, h
+ dy
);
1099 gdk_window_move (pizza
->bin_window
, x
, y
-dy
);
1100 gdk_window_move_resize (pizza
->bin_window
,
1108 gtk_pizza_expose_area (pizza
,
1110 MAX ((gint
)h
- dy
, 0),
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
);
1127 gtk_pizza_expose_area (pizza
,
1131 MIN (-dy
, (gint
)h
));
1134 gtk_pizza_position_children (pizza
);
1136 /* We have to make sure that all exposes from this scroll get
1137 * processed before we scroll again, or the expose events will
1138 * have invalid coordinates.
1140 * We also do expose events for other windows, since otherwise
1141 * their updating will fall behind the scrolling
1143 * This also avoids a problem in pre-1.0 GTK where filters don't
1144 * have access to configure events that were compressed.
1148 while (XCheckIfEvent(GDK_WINDOW_XDISPLAY (pizza
->bin_window
),
1150 gtk_pizza_expose_predicate
,
1151 (XPointer
)&GDK_WINDOW_XWINDOW (pizza
->bin_window
)))
1154 GtkWidget
*event_widget
;
1156 if ((xevent
.xany
.window
== GDK_WINDOW_XWINDOW (pizza
->bin_window
)) &&
1157 (gtk_pizza_filter (&xevent
, &event
, pizza
) == GDK_FILTER_REMOVE
))
1160 if (xevent
.type
== Expose
)
1162 event
.expose
.window
= gdk_window_lookup (xevent
.xany
.window
);
1163 gdk_window_get_user_data (event
.expose
.window
,
1164 (gpointer
*)&event_widget
);
1168 event
.expose
.type
= GDK_EXPOSE
;
1169 event
.expose
.area
.x
= xevent
.xexpose
.x
;
1170 event
.expose
.area
.y
= xevent
.xexpose
.y
;
1171 event
.expose
.area
.width
= xevent
.xexpose
.width
;
1172 event
.expose
.area
.height
= xevent
.xexpose
.height
;
1173 event
.expose
.count
= xevent
.xexpose
.count
;
1175 gdk_window_ref (event
.expose
.window
);
1176 gtk_widget_event (event_widget
, &event
);
1177 gdk_window_unref (event
.expose
.window
);
1183 /* The main event filter. Actually, we probably don't really need
1184 * to install this as a filter at all, since we are calling it
1185 * directly above in the expose-handling hack. But in case scrollbars
1186 * are fixed up in some manner...
1188 * This routine identifies expose events that are generated when
1189 * we've temporarily moved the bin_window_origin, and translates
1190 * them or discards them, depending on whether we are obscured
1193 static GdkFilterReturn
1194 gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
1201 xevent
= (XEvent
*)gdk_xevent
;
1203 pizza
= GTK_PIZZA (data
);
1205 if (!pizza
->use_filter
)
1206 return GDK_FILTER_CONTINUE
;
1208 switch (xevent
->type
)
1211 if (xevent
->xexpose
.serial
== pizza
->configure_serial
)
1213 if (pizza
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
1214 return GDK_FILTER_REMOVE
;
1217 xevent
->xexpose
.x
+= pizza
->scroll_x
;
1218 xevent
->xexpose
.y
+= pizza
->scroll_y
;
1225 case ConfigureNotify
:
1226 if ((xevent
->xconfigure
.x
!= 0) || (xevent
->xconfigure
.y
!= 0))
1228 pizza
->configure_serial
= xevent
->xconfigure
.serial
;
1229 pizza
->scroll_x
= xevent
->xconfigure
.x
;
1230 pizza
->scroll_y
= xevent
->xconfigure
.y
;
1235 return GDK_FILTER_CONTINUE
;
1238 /* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
1239 * there is no corresponding event in GTK, so we have
1240 * to get the events from a filter
1242 static GdkFilterReturn
1243 gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
1250 xevent
= (XEvent
*)gdk_xevent
;
1251 pizza
= GTK_PIZZA (data
);
1253 if (!pizza
->use_filter
)
1254 return GDK_FILTER_CONTINUE
;
1256 if (xevent
->type
== VisibilityNotify
)
1258 switch (xevent
->xvisibility
.state
)
1260 case VisibilityFullyObscured
:
1261 pizza
->visibility
= GDK_VISIBILITY_FULLY_OBSCURED
;
1264 case VisibilityPartiallyObscured
:
1265 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
1268 case VisibilityUnobscured
:
1269 pizza
->visibility
= GDK_VISIBILITY_UNOBSCURED
;
1273 return GDK_FILTER_REMOVE
;
1276 return GDK_FILTER_CONTINUE
;
1284 #endif /* __cplusplus */