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_map (GtkWidget
*widget
)
431 GtkPizzaChild
*child
;
434 g_return_if_fail (widget
!= NULL
);
435 g_return_if_fail (GTK_IS_PIZZA (widget
));
437 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
438 pizza
= GTK_PIZZA (widget
);
440 children
= pizza
->children
;
443 child
= children
->data
;
444 children
= children
->next
;
446 if ( GTK_WIDGET_VISIBLE (child
->widget
) &&
447 !GTK_WIDGET_MAPPED (child
->widget
) &&
448 !GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
450 gtk_widget_map (child
->widget
);
454 gdk_window_show (widget
->window
);
455 gdk_window_show (pizza
->bin_window
);
459 gtk_pizza_realize (GtkWidget
*widget
)
462 GdkWindowAttr attributes
;
463 gint attributes_mask
;
464 GtkPizzaChild
*child
;
467 g_return_if_fail (widget
!= NULL
);
468 g_return_if_fail (GTK_IS_PIZZA (widget
));
470 pizza
= GTK_PIZZA (widget
);
472 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
474 attributes
.window_type
= GDK_WINDOW_CHILD
;
476 attributes
.x
= widget
->allocation
.x
;
477 attributes
.y
= widget
->allocation
.y
;
478 attributes
.width
= widget
->allocation
.width
;
479 attributes
.height
= widget
->allocation
.height
;
481 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
483 /* no border, no changes to sizes */
485 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
487 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
490 attributes
.width
-= 2;
491 attributes
.height
-= 2;
494 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
495 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
498 attributes
.width
-= 4;
499 attributes
.height
-= 4;
503 if (attributes
.width
< 2) attributes
.width
= 2;
504 if (attributes
.height
< 2) attributes
.height
= 2;
506 attributes
.wclass
= GDK_INPUT_OUTPUT
;
507 attributes
.visual
= gtk_widget_get_visual (widget
);
508 attributes
.colormap
= gtk_widget_get_colormap (widget
);
509 attributes
.event_mask
=
510 GDK_VISIBILITY_NOTIFY_MASK
;
511 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
513 widget
->window
= gdk_window_new(gtk_widget_get_parent_window (widget
),
514 &attributes
, attributes_mask
);
515 gdk_window_set_user_data (widget
->window
, widget
);
520 attributes
.event_mask
= gtk_widget_get_events (widget
);
521 attributes
.event_mask
|=
523 GDK_POINTER_MOTION_MASK
|
524 GDK_POINTER_MOTION_HINT_MASK
|
525 GDK_BUTTON_MOTION_MASK
|
526 GDK_BUTTON1_MOTION_MASK
|
527 GDK_BUTTON2_MOTION_MASK
|
528 GDK_BUTTON3_MOTION_MASK
|
529 GDK_BUTTON_PRESS_MASK
|
530 GDK_BUTTON_RELEASE_MASK
|
532 GDK_KEY_RELEASE_MASK
|
533 GDK_ENTER_NOTIFY_MASK
|
534 GDK_LEAVE_NOTIFY_MASK
|
535 GDK_FOCUS_CHANGE_MASK
;
537 pizza
->bin_window
= gdk_window_new(widget
->window
,
538 &attributes
, attributes_mask
);
539 gdk_window_set_user_data (pizza
->bin_window
, widget
);
541 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
542 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
543 gtk_style_set_background (widget
->style
, pizza
->bin_window
, GTK_STATE_NORMAL
);
545 /* add filters for intercepting visibility and expose events */
546 gdk_window_add_filter (widget
->window
, gtk_pizza_main_filter
, pizza
);
547 gdk_window_add_filter (pizza
->bin_window
, gtk_pizza_filter
, pizza
);
549 /* we NEED gravity or we'll give up */
550 gravity_works
= gdk_window_set_static_gravities (pizza
->bin_window
, TRUE
);
552 /* cannot be done before realisation */
553 children
= pizza
->children
;
556 child
= children
->data
;
557 children
= children
->next
;
559 gtk_widget_set_parent_window (child
->widget
, pizza
->bin_window
);
564 gtk_pizza_unrealize (GtkWidget
*widget
)
568 g_return_if_fail (widget
!= NULL
);
569 g_return_if_fail (GTK_IS_PIZZA (widget
));
571 pizza
= GTK_PIZZA (widget
);
573 gdk_window_set_user_data (pizza
->bin_window
, NULL
);
574 gdk_window_destroy (pizza
->bin_window
);
575 pizza
->bin_window
= NULL
;
577 if (GTK_WIDGET_CLASS (parent_class
)->unrealize
)
578 (* GTK_WIDGET_CLASS (parent_class
)->unrealize
) (widget
);
582 gtk_pizza_size_request (GtkWidget
*widget
,
583 GtkRequisition
*requisition
)
586 GtkPizzaChild
*child
;
588 GtkRequisition child_requisition
;
590 g_return_if_fail (widget
!= NULL
);
591 g_return_if_fail (GTK_IS_PIZZA (widget
));
592 g_return_if_fail (requisition
!= NULL
);
594 pizza
= GTK_PIZZA (widget
);
596 children
= pizza
->children
;
599 child
= children
->data
;
600 children
= children
->next
;
602 if (GTK_WIDGET_VISIBLE (child
->widget
))
604 gtk_widget_size_request (child
->widget
, &child_requisition
);
608 /* request very little, I'm not sure if requesting nothing
609 will always have positive effects on stability... */
610 requisition
->width
= 2;
611 requisition
->height
= 2;
615 gtk_pizza_size_allocate (GtkWidget
*widget
,
616 GtkAllocation
*allocation
)
621 GtkPizzaChild
*child
;
624 g_return_if_fail (widget
!= NULL
);
625 g_return_if_fail (GTK_IS_PIZZA(widget
));
626 g_return_if_fail (allocation
!= NULL
);
628 pizza
= GTK_PIZZA (widget
);
630 widget
->allocation
= *allocation
;
632 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
635 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
640 x
= allocation
->x
+ border
;
641 y
= allocation
->y
+ border
;
642 w
= allocation
->width
- border
*2;
643 h
= allocation
->height
- border
*2;
645 if (GTK_WIDGET_REALIZED (widget
))
647 gdk_window_move_resize( widget
->window
, x
, y
, w
, h
);
648 gdk_window_move_resize( pizza
->bin_window
, 0, 0, w
, h
);
651 children
= pizza
->children
;
654 child
= children
->data
;
655 children
= children
->next
;
657 gtk_pizza_position_child (pizza
, child
);
658 gtk_pizza_allocate_child (pizza
, child
);
663 gtk_pizza_draw (GtkWidget
*widget
,
667 GtkPizzaChild
*child
;
668 GdkRectangle child_area
;
671 g_return_if_fail (widget
!= NULL
);
672 g_return_if_fail (GTK_IS_PIZZA (widget
));
674 pizza
= GTK_PIZZA (widget
);
676 /* Sometimes, We handle all expose events in window.cpp now. */
677 if (pizza
->external_expose
)
680 children
= pizza
->children
;
681 if ( !(GTK_WIDGET_APP_PAINTABLE (widget
)) &&
682 (pizza
->clear_on_draw
))
684 gdk_window_clear_area( pizza
->bin_window
,
685 area
->x
, area
->y
, area
->width
, area
->height
);
690 child
= children
->data
;
691 children
= children
->next
;
693 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
694 gtk_widget_draw (child
->widget
, &child_area
);
699 gtk_pizza_expose (GtkWidget
*widget
,
700 GdkEventExpose
*event
)
703 GtkPizzaChild
*child
;
704 GdkEventExpose child_event
;
707 g_return_val_if_fail (widget
!= NULL
, FALSE
);
708 g_return_val_if_fail (GTK_IS_PIZZA (widget
), FALSE
);
709 g_return_val_if_fail (event
!= NULL
, FALSE
);
711 pizza
= GTK_PIZZA (widget
);
713 /* Sometimes, We handle all expose events in window.cpp now. */
714 if (pizza
->external_expose
)
717 if (event
->window
!= pizza
->bin_window
)
720 children
= pizza
->children
;
723 child
= children
->data
;
724 children
= children
->next
;
726 child_event
= *event
;
728 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
729 GTK_WIDGET_DRAWABLE (child
->widget
) &&
730 gtk_widget_intersect (child
->widget
, &event
->area
, &child_event
.area
))
732 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
740 gtk_pizza_add (GtkContainer
*container
,
743 g_return_if_fail (container
!= NULL
);
744 g_return_if_fail (GTK_IS_PIZZA (container
));
745 g_return_if_fail (widget
!= NULL
);
747 gtk_pizza_put (GTK_PIZZA (container
), widget
, 0, 0, 20, 20 );
751 gtk_pizza_remove (GtkContainer
*container
,
755 GtkPizzaChild
*child
;
758 g_return_if_fail (container
!= NULL
);
759 g_return_if_fail (GTK_IS_PIZZA (container
));
760 g_return_if_fail (widget
!= NULL
);
762 pizza
= GTK_PIZZA (container
);
764 children
= pizza
->children
;
767 child
= children
->data
;
769 if (child
->widget
== widget
)
771 gtk_widget_unparent (widget
);
773 /* security checks */
774 g_return_if_fail (GTK_IS_WIDGET (widget
));
776 pizza
->children
= g_list_remove_link (pizza
->children
, children
);
777 g_list_free (children
);
780 /* security checks */
781 g_return_if_fail (GTK_IS_WIDGET (widget
));
783 GTK_PRIVATE_UNSET_FLAG (widget
, GTK_IS_OFFSCREEN
);
788 children
= children
->next
;
793 gtk_pizza_forall (GtkContainer
*container
,
794 gboolean include_internals
,
795 GtkCallback callback
,
796 gpointer callback_data
)
799 GtkPizzaChild
*child
;
802 g_return_if_fail (container
!= NULL
);
803 g_return_if_fail (GTK_IS_PIZZA (container
));
804 g_return_if_fail (callback
!= NULL
);
806 pizza
= GTK_PIZZA (container
);
808 children
= pizza
->children
;
811 child
= children
->data
;
812 children
= children
->next
;
814 (* callback
) (child
->widget
, callback_data
);
819 /* Operations on children
823 gtk_pizza_position_child (GtkPizza
*pizza
,
824 GtkPizzaChild
*child
)
829 x
= child
->x
- pizza
->xoffset
;
830 y
= child
->y
- pizza
->yoffset
;
832 if (IS_ONSCREEN (x
,y
))
834 if (GTK_WIDGET_MAPPED (pizza
) &&
835 GTK_WIDGET_VISIBLE (child
->widget
))
837 if (!GTK_WIDGET_MAPPED (child
->widget
))
838 gtk_widget_map (child
->widget
);
841 if (GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
842 GTK_PRIVATE_UNSET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
846 if (!GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
847 GTK_PRIVATE_SET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
849 if (GTK_WIDGET_MAPPED (child
->widget
))
850 gtk_widget_unmap (child
->widget
);
855 gtk_pizza_allocate_child (GtkPizza
*pizza
,
856 GtkPizzaChild
*child
)
858 GtkAllocation allocation
;
859 GtkRequisition requisition
;
861 allocation
.x
= child
->x
- pizza
->xoffset
;
862 allocation
.y
= child
->y
- pizza
->yoffset
;
863 gtk_widget_get_child_requisition (child
->widget
, &requisition
);
864 allocation
.width
= requisition
.width
;
865 allocation
.height
= requisition
.height
;
867 gtk_widget_size_allocate (child
->widget
, &allocation
);
871 gtk_pizza_position_children (GtkPizza
*pizza
)
875 tmp_list
= pizza
->children
;
878 GtkPizzaChild
*child
= tmp_list
->data
;
879 tmp_list
= tmp_list
->next
;
881 gtk_pizza_position_child (pizza
, child
);
886 gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
889 GtkPizzaAdjData
*data
= cb_data
;
891 widget
->allocation
.x
+= data
->dx
;
892 widget
->allocation
.y
+= data
->dy
;
894 if (GTK_WIDGET_NO_WINDOW (widget
) && GTK_IS_CONTAINER (widget
))
896 gtk_container_forall (GTK_CONTAINER (widget
),
897 gtk_pizza_adjust_allocations_recurse
,
903 gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
908 GtkPizzaAdjData data
;
913 tmp_list
= pizza
->children
;
916 GtkPizzaChild
*child
= tmp_list
->data
;
917 tmp_list
= tmp_list
->next
;
919 child
->widget
->allocation
.x
+= dx
;
920 child
->widget
->allocation
.y
+= dy
;
922 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
923 GTK_IS_CONTAINER (child
->widget
))
925 gtk_container_forall (GTK_CONTAINER (child
->widget
),
926 gtk_pizza_adjust_allocations_recurse
,
934 /* Send a synthetic expose event to the widget
937 gtk_pizza_expose_area (GtkPizza
*pizza
,
938 gint x
, gint y
, gint width
, gint height
)
940 if (pizza
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
942 GdkEventExpose event
;
944 event
.type
= GDK_EXPOSE
;
945 event
.send_event
= TRUE
;
946 event
.window
= pizza
->bin_window
;
951 event
.area
.width
= width
;
952 event
.area
.height
= height
;
954 gdk_window_ref (event
.window
);
955 gtk_widget_event (GTK_WIDGET (pizza
), (GdkEvent
*)&event
);
956 gdk_window_unref (event
.window
);
960 /* This function is used to find events to process while scrolling
964 gtk_pizza_expose_predicate (Display
*display
,
968 if ((xevent
->type
== Expose
) ||
969 ((xevent
->xany
.window
== *(Window
*)arg
) &&
970 (xevent
->type
== ConfigureNotify
)))
976 /* This is the main routine to do the scrolling. Scrolling is
977 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
978 * a few modifications.
980 * The main improvement is that we keep track of whether we
981 * are obscured or not. If not, we ignore the generated expose
982 * events and instead do the exposes ourself, without having
983 * to wait for a roundtrip to the server. This also provides
984 * a limited form of expose-event compression, since we do
985 * the affected area as one big chunk.
989 gtk_pizza_scroll (GtkPizza
*pizza
, gint dx
, gint dy
)
996 widget
= GTK_WIDGET (pizza
);
998 pizza
->xoffset
+= dx
;
999 pizza
->yoffset
+= dy
;
1001 if (!GTK_WIDGET_MAPPED (pizza
))
1003 gtk_pizza_position_children (pizza
);
1007 gtk_pizza_adjust_allocations (pizza
, -dx
, -dy
);
1009 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
1012 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
1019 w
= widget
->allocation
.width
- 2*border
;
1020 h
= widget
->allocation
.height
- 2*border
;
1026 gdk_window_resize (pizza
->bin_window
,
1029 gdk_window_move (pizza
->bin_window
, x
-dx
, y
);
1030 gdk_window_move_resize (pizza
->bin_window
, x
, y
, w
, h
);
1037 gtk_pizza_expose_area (pizza
,
1038 MAX ((gint
)w
- dx
, 0),
1047 gdk_window_move_resize (pizza
->bin_window
,
1052 gdk_window_move (pizza
->bin_window
, x
, y
);
1053 gdk_window_resize (pizza
->bin_window
, w
, h
);
1060 gtk_pizza_expose_area (pizza
,
1071 gdk_window_resize (pizza
->bin_window
, w
, h
+ dy
);
1072 gdk_window_move (pizza
->bin_window
, x
, y
-dy
);
1073 gdk_window_move_resize (pizza
->bin_window
,
1081 gtk_pizza_expose_area (pizza
,
1083 MAX ((gint
)h
- dy
, 0),
1091 gdk_window_move_resize (pizza
->bin_window
,
1092 x
, y
+dy
, w
, h
- dy
);
1093 gdk_window_move (pizza
->bin_window
, x
, y
);
1094 gdk_window_resize (pizza
->bin_window
, w
, h
);
1100 gtk_pizza_expose_area (pizza
,
1104 MIN (-dy
, (gint
)h
));
1107 gtk_pizza_position_children (pizza
);
1109 /* We have to make sure that all exposes from this scroll get
1110 * processed before we scroll again, or the expose events will
1111 * have invalid coordinates.
1113 * We also do expose events for other windows, since otherwise
1114 * their updating will fall behind the scrolling
1116 * This also avoids a problem in pre-1.0 GTK where filters don't
1117 * have access to configure events that were compressed.
1121 while (XCheckIfEvent(GDK_WINDOW_XDISPLAY (pizza
->bin_window
),
1123 gtk_pizza_expose_predicate
,
1124 (XPointer
)&GDK_WINDOW_XWINDOW (pizza
->bin_window
)))
1127 GtkWidget
*event_widget
;
1129 if ((xevent
.xany
.window
== GDK_WINDOW_XWINDOW (pizza
->bin_window
)) &&
1130 (gtk_pizza_filter (&xevent
, &event
, pizza
) == GDK_FILTER_REMOVE
))
1133 if (xevent
.type
== Expose
)
1135 event
.expose
.window
= gdk_window_lookup (xevent
.xany
.window
);
1136 gdk_window_get_user_data (event
.expose
.window
,
1137 (gpointer
*)&event_widget
);
1141 event
.expose
.type
= GDK_EXPOSE
;
1142 event
.expose
.area
.x
= xevent
.xexpose
.x
;
1143 event
.expose
.area
.y
= xevent
.xexpose
.y
;
1144 event
.expose
.area
.width
= xevent
.xexpose
.width
;
1145 event
.expose
.area
.height
= xevent
.xexpose
.height
;
1146 event
.expose
.count
= xevent
.xexpose
.count
;
1148 gdk_window_ref (event
.expose
.window
);
1149 gtk_widget_event (event_widget
, &event
);
1150 gdk_window_unref (event
.expose
.window
);
1156 /* The main event filter. Actually, we probably don't really need
1157 * to install this as a filter at all, since we are calling it
1158 * directly above in the expose-handling hack. But in case scrollbars
1159 * are fixed up in some manner...
1161 * This routine identifies expose events that are generated when
1162 * we've temporarily moved the bin_window_origin, and translates
1163 * them or discards them, depending on whether we are obscured
1166 static GdkFilterReturn
1167 gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
1174 xevent
= (XEvent
*)gdk_xevent
;
1176 pizza
= GTK_PIZZA (data
);
1178 if (!pizza
->use_filter
)
1179 return GDK_FILTER_CONTINUE
;
1181 switch (xevent
->type
)
1184 if (xevent
->xexpose
.serial
== pizza
->configure_serial
)
1186 if (pizza
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
1187 return GDK_FILTER_REMOVE
;
1190 xevent
->xexpose
.x
+= pizza
->scroll_x
;
1191 xevent
->xexpose
.y
+= pizza
->scroll_y
;
1198 case ConfigureNotify
:
1199 if ((xevent
->xconfigure
.x
!= 0) || (xevent
->xconfigure
.y
!= 0))
1201 pizza
->configure_serial
= xevent
->xconfigure
.serial
;
1202 pizza
->scroll_x
= xevent
->xconfigure
.x
;
1203 pizza
->scroll_y
= xevent
->xconfigure
.y
;
1208 return GDK_FILTER_CONTINUE
;
1211 /* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
1212 * there is no corresponding event in GTK, so we have
1213 * to get the events from a filter
1215 static GdkFilterReturn
1216 gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
1223 xevent
= (XEvent
*)gdk_xevent
;
1224 pizza
= GTK_PIZZA (data
);
1226 if (!pizza
->use_filter
)
1227 return GDK_FILTER_CONTINUE
;
1229 if (xevent
->type
== VisibilityNotify
)
1231 switch (xevent
->xvisibility
.state
)
1233 case VisibilityFullyObscured
:
1234 pizza
->visibility
= GDK_VISIBILITY_FULLY_OBSCURED
;
1237 case VisibilityPartiallyObscured
:
1238 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
1241 case VisibilityUnobscured
:
1242 pizza
->visibility
= GDK_VISIBILITY_UNOBSCURED
;
1246 return GDK_FILTER_REMOVE
;
1249 return GDK_FILTER_CONTINUE
;
1257 #endif /* __cplusplus */