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
);
54 static void gtk_pizza_draw (GtkWidget
*widget
,
56 #endif /* __WXGTK20__ */
57 static gint
gtk_pizza_expose (GtkWidget
*widget
,
58 GdkEventExpose
*event
);
59 static void gtk_pizza_add (GtkContainer
*container
,
61 static void gtk_pizza_remove (GtkContainer
*container
,
63 static void gtk_pizza_forall (GtkContainer
*container
,
64 gboolean include_internals
,
66 gpointer callback_data
);
68 static void gtk_pizza_position_child (GtkPizza
*pizza
,
69 GtkPizzaChild
*child
);
70 static void gtk_pizza_allocate_child (GtkPizza
*pizza
,
71 GtkPizzaChild
*child
);
72 static void gtk_pizza_position_children (GtkPizza
*pizza
);
74 static void gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
76 static void gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
83 static void gtk_pizza_expose_area (GtkPizza
*pizza
,
88 static void gtk_pizza_adjustment_changed (GtkAdjustment
*adjustment
,
92 static GdkFilterReturn
gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
95 static GdkFilterReturn
gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
100 static GtkType
gtk_pizza_child_type (GtkContainer
*container
);
102 static void gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
104 GtkAdjustment
*vadj
);
107 static GtkContainerClass
*parent_class
= NULL
;
108 static gboolean gravity_works
;
111 gtk_pizza_get_type ()
113 static guint pizza_type
= 0;
117 GtkTypeInfo pizza_info
=
121 sizeof (GtkPizzaClass
),
122 (GtkClassInitFunc
) gtk_pizza_class_init
,
123 (GtkObjectInitFunc
) gtk_pizza_init
,
124 /* reserved_1 */ NULL
,
125 /* reserved_2 */ NULL
,
126 (GtkClassInitFunc
) NULL
,
128 pizza_type
= gtk_type_unique (gtk_container_get_type (), &pizza_info
);
135 gtk_pizza_class_init (GtkPizzaClass
*klass
)
137 GtkObjectClass
*object_class
;
138 GtkWidgetClass
*widget_class
;
139 GtkContainerClass
*container_class
;
141 object_class
= (GtkObjectClass
*) klass
;
142 widget_class
= (GtkWidgetClass
*) klass
;
143 container_class
= (GtkContainerClass
*) klass
;
144 parent_class
= gtk_type_class (GTK_TYPE_CONTAINER
);
146 widget_class
->map
= gtk_pizza_map
;
147 widget_class
->realize
= gtk_pizza_realize
;
148 widget_class
->unrealize
= gtk_pizza_unrealize
;
149 widget_class
->size_request
= gtk_pizza_size_request
;
150 widget_class
->size_allocate
= gtk_pizza_size_allocate
;
152 widget_class
->draw
= gtk_pizza_draw
;
154 widget_class
->expose_event
= gtk_pizza_expose
;
156 container_class
->add
= gtk_pizza_add
;
157 container_class
->remove
= gtk_pizza_remove
;
158 container_class
->forall
= gtk_pizza_forall
;
160 container_class
->child_type
= gtk_pizza_child_type
;
162 klass
->set_scroll_adjustments
= gtk_pizza_scroll_set_adjustments
;
164 widget_class
->set_scroll_adjustments_signal
=
165 gtk_signal_new ("set_scroll_adjustments",
168 GTK_CLASS_TYPE(object_class
),
172 GTK_SIGNAL_OFFSET (GtkPizzaClass
, set_scroll_adjustments
),
173 gtk_marshal_NONE__POINTER_POINTER
,
174 GTK_TYPE_NONE
, 2, GTK_TYPE_ADJUSTMENT
, GTK_TYPE_ADJUSTMENT
);
178 gtk_pizza_child_type (GtkContainer
*container
)
180 return GTK_TYPE_WIDGET
;
184 gtk_pizza_init (GtkPizza
*pizza
)
186 GTK_WIDGET_UNSET_FLAGS (pizza
, GTK_NO_WINDOW
);
188 pizza
->shadow_type
= GTK_MYSHADOW_NONE
;
190 pizza
->children
= NULL
;
195 pizza
->bin_window
= NULL
;
200 pizza
->configure_serial
= 0;
203 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
205 pizza
->clear_on_draw
= TRUE
;
206 pizza
->use_filter
= TRUE
;
207 pizza
->external_expose
= FALSE
;
215 pizza
= gtk_type_new (gtk_pizza_get_type ());
217 return GTK_WIDGET (pizza
);
221 gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
225 /* We handle scrolling in the wxScrolledWindow, not here. */
229 gtk_pizza_set_shadow_type (GtkPizza
*pizza
,
230 GtkMyShadowType type
)
232 g_return_if_fail (pizza
!= NULL
);
233 g_return_if_fail (GTK_IS_PIZZA (pizza
));
235 if ((GtkMyShadowType
) pizza
->shadow_type
!= type
)
237 pizza
->shadow_type
= type
;
239 if (GTK_WIDGET_VISIBLE (pizza
))
241 gtk_widget_size_allocate (GTK_WIDGET (pizza
), &(GTK_WIDGET (pizza
)->allocation
));
242 gtk_widget_queue_draw (GTK_WIDGET (pizza
));
248 gtk_pizza_set_clear (GtkPizza
*pizza
,
251 g_return_if_fail (pizza
!= NULL
);
252 g_return_if_fail (GTK_IS_PIZZA (pizza
));
254 pizza
->clear_on_draw
= clear
;
258 gtk_pizza_set_filter (GtkPizza
*pizza
,
261 g_return_if_fail (pizza
!= NULL
);
262 g_return_if_fail (GTK_IS_PIZZA (pizza
));
264 pizza
->use_filter
= use
;
268 gtk_pizza_set_external (GtkPizza
*pizza
,
271 g_return_if_fail (pizza
!= NULL
);
272 g_return_if_fail (GTK_IS_PIZZA (pizza
));
274 pizza
->external_expose
= expose
;
278 gtk_pizza_put (GtkPizza
*pizza
,
285 GtkPizzaChild
*child_info
;
287 g_return_if_fail (pizza
!= NULL
);
288 g_return_if_fail (GTK_IS_PIZZA (pizza
));
289 g_return_if_fail (widget
!= NULL
);
291 child_info
= g_new (GtkPizzaChild
, 1);
293 child_info
->widget
= widget
;
296 child_info
->width
= width
;
297 child_info
->height
= height
;
299 pizza
->children
= g_list_append (pizza
->children
, child_info
);
301 gtk_widget_set_parent (widget
, GTK_WIDGET (pizza
));
303 if (GTK_WIDGET_REALIZED (pizza
))
304 gtk_widget_set_parent_window (widget
, pizza
->bin_window
);
306 #ifndef __WXGTK20__ /* FIXME? */
307 if (!IS_ONSCREEN (x
, y
))
308 GTK_PRIVATE_SET_FLAG (widget
, GTK_IS_OFFSCREEN
);
312 if (GTK_WIDGET_REALIZED (pizza))
313 gtk_widget_realize (widget);
316 gtk_widget_set_usize (widget
, width
, height
);
319 if (GTK_WIDGET_VISIBLE (pizza) && GTK_WIDGET_VISIBLE (widget))
321 if (GTK_WIDGET_MAPPED (pizza))
322 gtk_widget_map (widget);
324 gtk_widget_queue_resize (widget);
330 gtk_pizza_move (GtkPizza
*pizza
,
335 GtkPizzaChild
*child
;
338 g_return_if_fail (pizza
!= NULL
);
339 g_return_if_fail (GTK_IS_PIZZA (pizza
));
340 g_return_if_fail (widget
!= NULL
);
342 children
= pizza
->children
;
345 child
= children
->data
;
346 children
= children
->next
;
348 if (child
->widget
== widget
)
350 if ((child
->x
== x
) && (child
->y
== y
))
356 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
357 gtk_widget_queue_resize (widget
);
364 gtk_pizza_resize (GtkPizza
*pizza
,
369 GtkPizzaChild
*child
;
372 g_return_if_fail (pizza
!= NULL
);
373 g_return_if_fail (GTK_IS_PIZZA (pizza
));
374 g_return_if_fail (widget
!= NULL
);
376 children
= pizza
->children
;
379 child
= children
->data
;
380 children
= children
->next
;
382 if (child
->widget
== widget
)
384 if ((child
->width
== width
) && (child
->height
== height
))
387 child
->width
= width
;
388 child
->height
= height
;
390 gtk_widget_set_usize (widget
, width
, height
);
392 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
393 gtk_widget_queue_resize (widget
);
400 gtk_pizza_set_size (GtkPizza
*pizza
,
407 GtkPizzaChild
*child
;
410 g_return_if_fail (pizza
!= NULL
);
411 g_return_if_fail (GTK_IS_PIZZA (pizza
));
412 g_return_if_fail (widget
!= NULL
);
414 children
= pizza
->children
;
417 child
= children
->data
;
418 children
= children
->next
;
420 if (child
->widget
== widget
)
422 if ((child
->x
== x
) &&
424 (child
->width
== width
) &&
425 (child
->height
== height
)) return;
429 child
->width
= width
;
430 child
->height
= height
;
432 gtk_widget_set_usize (widget
, width
, height
);
434 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
435 gtk_widget_queue_resize (widget
);
443 gtk_pizza_child_resized (GtkPizza
*pizza
,
446 GtkPizzaChild
*child
;
449 g_return_val_if_fail (pizza
!= NULL
, FALSE
);
450 g_return_val_if_fail (GTK_IS_PIZZA (pizza
), FALSE
);
451 g_return_val_if_fail (widget
!= NULL
, FALSE
);
453 children
= pizza
->children
;
456 child
= children
->data
;
457 children
= children
->next
;
459 if (child
->widget
== widget
)
461 return ((child
->width
== widget
->allocation
.width
) &&
462 (child
->height
== widget
->allocation
.height
));
470 gtk_pizza_map (GtkWidget
*widget
)
473 GtkPizzaChild
*child
;
476 g_return_if_fail (widget
!= NULL
);
477 g_return_if_fail (GTK_IS_PIZZA (widget
));
479 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
480 pizza
= GTK_PIZZA (widget
);
482 children
= pizza
->children
;
485 child
= children
->data
;
486 children
= children
->next
;
488 if ( GTK_WIDGET_VISIBLE (child
->widget
) &&
489 !GTK_WIDGET_MAPPED (child
->widget
) &&
493 !GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
496 gtk_widget_map (child
->widget
);
500 gdk_window_show (widget
->window
);
501 gdk_window_show (pizza
->bin_window
);
505 gtk_pizza_realize (GtkWidget
*widget
)
508 GdkWindowAttr attributes
;
509 gint attributes_mask
;
510 GtkPizzaChild
*child
;
513 g_return_if_fail (widget
!= NULL
);
514 g_return_if_fail (GTK_IS_PIZZA (widget
));
516 pizza
= GTK_PIZZA (widget
);
518 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
520 attributes
.window_type
= GDK_WINDOW_CHILD
;
522 attributes
.x
= widget
->allocation
.x
;
523 attributes
.y
= widget
->allocation
.y
;
524 attributes
.width
= widget
->allocation
.width
;
525 attributes
.height
= widget
->allocation
.height
;
527 #ifndef __WXUNIVERSAL__
528 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
530 /* no border, no changes to sizes */
532 else if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
534 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
537 attributes
.width
-= 2;
538 attributes
.height
-= 2;
542 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
543 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
546 attributes
.width
-= 4;
547 attributes
.height
-= 4;
549 #endif /* __WXUNIVERSAL__ */
552 if (attributes
.width
< 2) attributes
.width
= 2;
553 if (attributes
.height
< 2) attributes
.height
= 2;
555 attributes
.wclass
= GDK_INPUT_OUTPUT
;
556 attributes
.visual
= gtk_widget_get_visual (widget
);
557 attributes
.colormap
= gtk_widget_get_colormap (widget
);
558 attributes
.event_mask
= GDK_VISIBILITY_NOTIFY_MASK
;
559 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
561 widget
->window
= gdk_window_new(gtk_widget_get_parent_window (widget
),
562 &attributes
, attributes_mask
);
563 gdk_window_set_user_data (widget
->window
, widget
);
568 attributes
.event_mask
= gtk_widget_get_events (widget
);
569 attributes
.event_mask
|= GDK_EXPOSURE_MASK
|
570 GDK_POINTER_MOTION_MASK
|
571 GDK_POINTER_MOTION_HINT_MASK
|
572 GDK_BUTTON_MOTION_MASK
|
573 GDK_BUTTON1_MOTION_MASK
|
574 GDK_BUTTON2_MOTION_MASK
|
575 GDK_BUTTON3_MOTION_MASK
|
576 GDK_BUTTON_PRESS_MASK
|
577 GDK_BUTTON_RELEASE_MASK
|
579 GDK_KEY_RELEASE_MASK
|
580 GDK_ENTER_NOTIFY_MASK
|
581 GDK_LEAVE_NOTIFY_MASK
|
582 GDK_FOCUS_CHANGE_MASK
;
584 pizza
->bin_window
= gdk_window_new(widget
->window
,
585 &attributes
, attributes_mask
);
586 gdk_window_set_user_data (pizza
->bin_window
, widget
);
588 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
589 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
590 gtk_style_set_background (widget
->style
, pizza
->bin_window
, GTK_STATE_NORMAL
);
593 gdk_window_set_back_pixmap( widget->window, NULL, FALSE );
594 gdk_window_set_back_pixmap( pizza->bin_window, NULL, FALSE );
597 /* add filters for intercepting visibility and expose events */
598 gdk_window_add_filter (widget
->window
, gtk_pizza_main_filter
, pizza
);
599 gdk_window_add_filter (pizza
->bin_window
, gtk_pizza_filter
, pizza
);
601 /* we NEED gravity or we'll give up */
602 gravity_works
= gdk_window_set_static_gravities (pizza
->bin_window
, TRUE
);
604 /* cannot be done before realisation */
605 children
= pizza
->children
;
608 child
= children
->data
;
609 children
= children
->next
;
611 gtk_widget_set_parent_window (child
->widget
, pizza
->bin_window
);
616 gtk_pizza_unrealize (GtkWidget
*widget
)
620 g_return_if_fail (widget
!= NULL
);
621 g_return_if_fail (GTK_IS_PIZZA (widget
));
623 pizza
= GTK_PIZZA (widget
);
625 gdk_window_set_user_data (pizza
->bin_window
, NULL
);
626 gdk_window_destroy (pizza
->bin_window
);
627 pizza
->bin_window
= NULL
;
629 if (GTK_WIDGET_CLASS (parent_class
)->unrealize
)
630 (* GTK_WIDGET_CLASS (parent_class
)->unrealize
) (widget
);
634 gtk_pizza_size_request (GtkWidget
*widget
,
635 GtkRequisition
*requisition
)
638 GtkPizzaChild
*child
;
640 GtkRequisition child_requisition
;
642 g_return_if_fail (widget
!= NULL
);
643 g_return_if_fail (GTK_IS_PIZZA (widget
));
644 g_return_if_fail (requisition
!= NULL
);
646 pizza
= GTK_PIZZA (widget
);
648 children
= pizza
->children
;
651 child
= children
->data
;
652 children
= children
->next
;
654 if (GTK_WIDGET_VISIBLE (child
->widget
))
656 gtk_widget_size_request (child
->widget
, &child_requisition
);
660 /* request very little, I'm not sure if requesting nothing
661 will always have positive effects on stability... */
662 requisition
->width
= 2;
663 requisition
->height
= 2;
667 gtk_pizza_size_allocate (GtkWidget
*widget
,
668 GtkAllocation
*allocation
)
673 GtkPizzaChild
*child
;
676 g_return_if_fail (widget
!= NULL
);
677 g_return_if_fail (GTK_IS_PIZZA(widget
));
678 g_return_if_fail (allocation
!= NULL
);
680 pizza
= GTK_PIZZA (widget
);
682 widget
->allocation
= *allocation
;
684 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
687 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
692 x
= allocation
->x
+ border
;
693 y
= allocation
->y
+ border
;
694 w
= allocation
->width
- border
*2;
695 h
= allocation
->height
- border
*2;
697 if (GTK_WIDGET_REALIZED (widget
))
699 gdk_window_move_resize( widget
->window
, x
, y
, w
, h
);
700 gdk_window_move_resize( pizza
->bin_window
, 0, 0, w
, h
);
703 children
= pizza
->children
;
706 child
= children
->data
;
707 children
= children
->next
;
709 gtk_pizza_position_child (pizza
, child
);
710 gtk_pizza_allocate_child (pizza
, child
);
717 gtk_pizza_draw (GtkWidget
*widget
,
721 GtkPizzaChild
*child
;
722 GdkRectangle child_area
;
725 g_return_if_fail (widget
!= NULL
);
726 g_return_if_fail (GTK_IS_PIZZA (widget
));
728 pizza
= GTK_PIZZA (widget
);
730 /* Sometimes, We handle all expose events in window.cpp now. */
731 if (pizza
->external_expose
)
734 children
= pizza
->children
;
735 if ( !(GTK_WIDGET_APP_PAINTABLE (widget
)) &&
736 (pizza
->clear_on_draw
))
738 gdk_window_clear_area( pizza
->bin_window
,
739 area
->x
, area
->y
, area
->width
, area
->height
);
744 child
= children
->data
;
745 children
= children
->next
;
747 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
748 gtk_widget_draw (child
->widget
, &child_area
);
752 #endif /* __WXGTK20__ */
755 gtk_pizza_expose (GtkWidget
*widget
,
756 GdkEventExpose
*event
)
759 GtkPizzaChild
*child
;
760 GdkEventExpose child_event
;
763 g_return_val_if_fail (widget
!= NULL
, FALSE
);
764 g_return_val_if_fail (GTK_IS_PIZZA (widget
), FALSE
);
765 g_return_val_if_fail (event
!= NULL
, FALSE
);
767 pizza
= GTK_PIZZA (widget
);
769 /* Sometimes, We handle all expose events in window.cpp now. */
770 if (pizza
->external_expose
)
773 if (event
->window
!= pizza
->bin_window
)
776 children
= pizza
->children
;
779 child
= children
->data
;
780 children
= children
->next
;
782 child_event
= *event
;
784 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
785 GTK_WIDGET_DRAWABLE (child
->widget
) &&
786 gtk_widget_intersect (child
->widget
, &event
->area
, &child_event
.area
))
788 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
796 gtk_pizza_add (GtkContainer
*container
,
799 g_return_if_fail (container
!= NULL
);
800 g_return_if_fail (GTK_IS_PIZZA (container
));
801 g_return_if_fail (widget
!= NULL
);
803 gtk_pizza_put (GTK_PIZZA (container
), widget
, 0, 0, 20, 20 );
807 gtk_pizza_remove (GtkContainer
*container
,
811 GtkPizzaChild
*child
;
814 g_return_if_fail (container
!= NULL
);
815 g_return_if_fail (GTK_IS_PIZZA (container
));
816 g_return_if_fail (widget
!= NULL
);
818 pizza
= GTK_PIZZA (container
);
820 children
= pizza
->children
;
823 child
= children
->data
;
825 if (child
->widget
== widget
)
827 gtk_widget_unparent (widget
);
829 /* security checks */
830 g_return_if_fail (GTK_IS_WIDGET (widget
));
832 pizza
->children
= g_list_remove_link (pizza
->children
, children
);
833 g_list_free (children
);
836 /* security checks */
837 g_return_if_fail (GTK_IS_WIDGET (widget
));
840 GTK_PRIVATE_UNSET_FLAG (widget
, GTK_IS_OFFSCREEN
);
846 children
= children
->next
;
851 gtk_pizza_forall (GtkContainer
*container
,
852 gboolean include_internals
,
853 GtkCallback callback
,
854 gpointer callback_data
)
857 GtkPizzaChild
*child
;
860 g_return_if_fail (container
!= NULL
);
861 g_return_if_fail (GTK_IS_PIZZA (container
));
862 g_return_if_fail (callback
!= (GtkCallback
)NULL
);
864 pizza
= GTK_PIZZA (container
);
866 children
= pizza
->children
;
869 child
= children
->data
;
870 children
= children
->next
;
872 (* callback
) (child
->widget
, callback_data
);
877 /* Operations on children
881 gtk_pizza_position_child (GtkPizza
*pizza
,
882 GtkPizzaChild
*child
)
887 x
= child
->x
- pizza
->xoffset
;
888 y
= child
->y
- pizza
->yoffset
;
890 if (IS_ONSCREEN (x
,y
))
892 if (GTK_WIDGET_MAPPED (pizza
) &&
893 GTK_WIDGET_VISIBLE (child
->widget
))
895 if (!GTK_WIDGET_MAPPED (child
->widget
))
896 gtk_widget_map (child
->widget
);
900 if (GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
901 GTK_PRIVATE_UNSET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
907 if (!GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
908 GTK_PRIVATE_SET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
911 if (GTK_WIDGET_MAPPED (child
->widget
))
912 gtk_widget_unmap (child
->widget
);
917 gtk_pizza_allocate_child (GtkPizza
*pizza
,
918 GtkPizzaChild
*child
)
920 GtkAllocation allocation
;
921 GtkRequisition requisition
;
923 allocation
.x
= child
->x
- pizza
->xoffset
;
924 allocation
.y
= child
->y
- pizza
->yoffset
;
925 gtk_widget_get_child_requisition (child
->widget
, &requisition
);
926 allocation
.width
= requisition
.width
;
927 allocation
.height
= requisition
.height
;
929 gtk_widget_size_allocate (child
->widget
, &allocation
);
933 gtk_pizza_position_children (GtkPizza
*pizza
)
937 tmp_list
= pizza
->children
;
940 GtkPizzaChild
*child
= tmp_list
->data
;
941 tmp_list
= tmp_list
->next
;
943 gtk_pizza_position_child (pizza
, child
);
948 gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
951 GtkPizzaAdjData
*data
= cb_data
;
953 widget
->allocation
.x
+= data
->dx
;
954 widget
->allocation
.y
+= data
->dy
;
956 if (GTK_WIDGET_NO_WINDOW (widget
) && GTK_IS_CONTAINER (widget
))
958 gtk_container_forall (GTK_CONTAINER (widget
),
959 gtk_pizza_adjust_allocations_recurse
,
965 gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
970 GtkPizzaAdjData data
;
975 tmp_list
= pizza
->children
;
978 GtkPizzaChild
*child
= tmp_list
->data
;
979 tmp_list
= tmp_list
->next
;
981 child
->widget
->allocation
.x
+= dx
;
982 child
->widget
->allocation
.y
+= dy
;
984 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
985 GTK_IS_CONTAINER (child
->widget
))
987 gtk_container_forall (GTK_CONTAINER (child
->widget
),
988 gtk_pizza_adjust_allocations_recurse
,
998 /* Send a synthetic expose event to the widget
1001 gtk_pizza_expose_area (GtkPizza
*pizza
,
1002 gint x
, gint y
, gint width
, gint height
)
1004 if (pizza
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
1006 GdkEventExpose event
;
1008 event
.type
= GDK_EXPOSE
;
1009 event
.send_event
= TRUE
;
1010 event
.window
= pizza
->bin_window
;
1015 event
.area
.width
= width
;
1016 event
.area
.height
= height
;
1018 gdk_window_ref (event
.window
);
1019 gtk_widget_event (GTK_WIDGET (pizza
), (GdkEvent
*)&event
);
1020 gdk_window_unref (event
.window
);
1025 /* This function is used to find events to process while scrolling
1029 gtk_pizza_expose_predicate (Display
*display
,
1033 if ((xevent
->type
== Expose
) ||
1034 ((xevent
->xany
.window
== *(Window
*)arg
) &&
1035 (xevent
->type
== ConfigureNotify
)))
1041 /* This is the main routine to do the scrolling. Scrolling is
1042 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
1043 * a few modifications.
1045 * The main improvement is that we keep track of whether we
1046 * are obscured or not. If not, we ignore the generated expose
1047 * events and instead do the exposes ourself, without having
1048 * to wait for a roundtrip to the server. This also provides
1049 * a limited form of expose-event compression, since we do
1050 * the affected area as one big chunk.
1054 gtk_pizza_scroll (GtkPizza
*pizza
, gint dx
, gint dy
)
1060 gint x
,y
,w
,h
,border
;
1062 widget
= GTK_WIDGET (pizza
);
1064 pizza
->xoffset
+= dx
;
1065 pizza
->yoffset
+= dy
;
1067 if (!GTK_WIDGET_MAPPED (pizza
))
1069 gtk_pizza_position_children (pizza
);
1073 gtk_pizza_adjust_allocations (pizza
, -dx
, -dy
);
1075 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
1078 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
1085 w
= widget
->allocation
.width
- 2*border
;
1086 h
= widget
->allocation
.height
- 2*border
;
1092 gdk_window_resize (pizza
->bin_window
,
1095 gdk_window_move (pizza
->bin_window
, x
-dx
, y
);
1096 gdk_window_move_resize (pizza
->bin_window
, x
, y
, w
, h
);
1107 gdk_window_move_resize (pizza
->bin_window
,
1112 gdk_window_move (pizza
->bin_window
, x
, y
);
1113 gdk_window_resize (pizza
->bin_window
, w
, h
);
1125 gdk_window_resize (pizza
->bin_window
, w
, h
+ dy
);
1126 gdk_window_move (pizza
->bin_window
, x
, y
-dy
);
1127 gdk_window_move_resize (pizza
->bin_window
,
1139 gdk_window_move_resize (pizza
->bin_window
,
1140 x
, y
+dy
, w
, h
- dy
);
1141 gdk_window_move (pizza
->bin_window
, x
, y
);
1142 gdk_window_resize (pizza
->bin_window
, w
, h
);
1150 gtk_pizza_position_children (pizza
);
1154 win
= GDK_WINDOW_XWINDOW (pizza
->bin_window
);
1155 while (XCheckIfEvent(GDK_WINDOW_XDISPLAY (pizza
->bin_window
),
1157 gtk_pizza_expose_predicate
,
1161 GtkWidget
*event_widget
;
1163 if ((xevent
.xany
.window
== GDK_WINDOW_XWINDOW (pizza
->bin_window
)) )
1164 gtk_pizza_filter (&xevent
, &event
, pizza
);
1166 if (xevent
.type
== Expose
)
1168 event
.expose
.window
= gdk_window_lookup (xevent
.xany
.window
);
1169 gdk_window_get_user_data (event
.expose
.window
,
1170 (gpointer
*)&event_widget
);
1174 event
.expose
.type
= GDK_EXPOSE
;
1175 event
.expose
.area
.x
= xevent
.xexpose
.x
;
1176 event
.expose
.area
.y
= xevent
.xexpose
.y
;
1177 event
.expose
.area
.width
= xevent
.xexpose
.width
;
1178 event
.expose
.area
.height
= xevent
.xexpose
.height
;
1179 event
.expose
.count
= xevent
.xexpose
.count
;
1181 gdk_window_ref (event
.expose
.window
);
1182 gtk_widget_event (event_widget
, &event
);
1183 gdk_window_unref (event
.expose
.window
);
1189 /* The main event filter. Actually, we probably don't really need
1190 * to install this as a filter at all, since we are calling it
1191 * directly above in the expose-handling hack. But in case scrollbars
1192 * are fixed up in some manner...
1194 * This routine identifies expose events that are generated when
1195 * we've temporarily moved the bin_window_origin, and translates
1196 * them or discards them, depending on whether we are obscured
1199 static GdkFilterReturn
1200 gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
1207 xevent
= (XEvent
*)gdk_xevent
;
1209 pizza
= GTK_PIZZA (data
);
1211 if (!pizza
->use_filter
)
1212 return GDK_FILTER_CONTINUE
;
1214 switch (xevent
->type
)
1217 if (xevent
->xexpose
.serial
== pizza
->configure_serial
)
1219 xevent
->xexpose
.x
+= pizza
->scroll_x
;
1220 xevent
->xexpose
.y
+= pizza
->scroll_y
;
1224 case ConfigureNotify
:
1226 pizza
->configure_serial
= xevent
->xconfigure
.serial
;
1227 pizza
->scroll_x
= xevent
->xconfigure
.x
;
1228 pizza
->scroll_y
= xevent
->xconfigure
.y
;
1233 return GDK_FILTER_CONTINUE
;
1236 /* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
1237 * there is no corresponding event in GTK, so we have
1238 * to get the events from a filter
1240 static GdkFilterReturn
1241 gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
1248 xevent
= (XEvent
*)gdk_xevent
;
1249 pizza
= GTK_PIZZA (data
);
1251 if (!pizza
->use_filter
)
1252 return GDK_FILTER_CONTINUE
;
1254 if (xevent
->type
== VisibilityNotify
)
1256 switch (xevent
->xvisibility
.state
)
1258 case VisibilityFullyObscured
:
1259 pizza
->visibility
= GDK_VISIBILITY_FULLY_OBSCURED
;
1262 case VisibilityPartiallyObscured
:
1263 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
1266 case VisibilityUnobscured
:
1267 pizza
->visibility
= GDK_VISIBILITY_UNOBSCURED
;
1271 return GDK_FILTER_REMOVE
;
1274 return GDK_FILTER_CONTINUE
;
1280 #endif /* __cplusplus */