1 /* ///////////////////////////////////////////////////////////////////////////
3 // Purpose: Native GTK+ widget for wxWindows, based on GtkLayout and
4 // GtkFixed. It makes use of the gravity window property and
5 // therefore does not work with GTK 1.0.
6 // Author: Robert Roebling
8 // Copyright: (c) 1998 Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////// */
13 #define gtk_widget_get_child_requisition gtk_widget_get_child_requisitio
14 #define gtk_marshal_NONE__POINTER_POINTER gtk_marshal_NONE__POINTER_POINT
17 #include "wx/gtk/setup.h"
18 #include "wx/gtk/win_gtk.h"
19 #include "gtk/gtksignal.h"
20 #include "gtk/gtkprivate.h"
25 #endif /* __cplusplus */
28 #include <X11/Xutil.h>
29 #include <X11/Xatom.h>
31 #define IS_ONSCREEN(x,y) ((x >= G_MINSHORT) && (x <= G_MAXSHORT) && \
32 (y >= G_MINSHORT) && (y <= G_MAXSHORT))
34 typedef struct _GtkPizzaAdjData GtkPizzaAdjData
;
36 struct _GtkPizzaAdjData
42 static void gtk_pizza_class_init (GtkPizzaClass
*klass
);
43 static void gtk_pizza_init (GtkPizza
*pizza
);
45 static void gtk_pizza_realize (GtkWidget
*widget
);
46 static void gtk_pizza_unrealize (GtkWidget
*widget
);
48 static void gtk_pizza_map (GtkWidget
*widget
);
50 static void gtk_pizza_size_request (GtkWidget
*widget
,
51 GtkRequisition
*requisition
);
52 static void gtk_pizza_size_allocate (GtkWidget
*widget
,
53 GtkAllocation
*allocation
);
54 static void gtk_pizza_draw (GtkWidget
*widget
,
56 static gint
gtk_pizza_expose (GtkWidget
*widget
,
57 GdkEventExpose
*event
);
58 static void gtk_pizza_add (GtkContainer
*container
,
60 static void gtk_pizza_remove (GtkContainer
*container
,
62 static void gtk_pizza_forall (GtkContainer
*container
,
63 gboolean include_internals
,
65 gpointer callback_data
);
67 static void gtk_pizza_position_child (GtkPizza
*pizza
,
68 GtkPizzaChild
*child
);
69 static void gtk_pizza_allocate_child (GtkPizza
*pizza
,
70 GtkPizzaChild
*child
);
71 static void gtk_pizza_position_children (GtkPizza
*pizza
);
73 static void gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
75 static void gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
80 static void gtk_pizza_expose_area (GtkPizza
*pizza
,
87 static void gtk_pizza_adjustment_changed (GtkAdjustment
*adjustment
,
91 static GdkFilterReturn
gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
94 static GdkFilterReturn
gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
99 static GtkType
gtk_pizza_child_type (GtkContainer
*container
);
101 static void gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
103 GtkAdjustment
*vadj
);
106 static GtkContainerClass
*parent_class
= NULL
;
107 static gboolean gravity_works
;
110 gtk_pizza_get_type ()
112 static guint pizza_type
= 0;
116 GtkTypeInfo pizza_info
=
120 sizeof (GtkPizzaClass
),
121 (GtkClassInitFunc
) gtk_pizza_class_init
,
122 (GtkObjectInitFunc
) gtk_pizza_init
,
123 /* reserved_1 */ NULL
,
124 /* reserved_2 */ NULL
,
125 (GtkClassInitFunc
) NULL
,
127 pizza_type
= gtk_type_unique (gtk_container_get_type (), &pizza_info
);
134 gtk_pizza_class_init (GtkPizzaClass
*klass
)
136 GtkObjectClass
*object_class
;
137 GtkWidgetClass
*widget_class
;
138 GtkContainerClass
*container_class
;
140 object_class
= (GtkObjectClass
*) klass
;
141 widget_class
= (GtkWidgetClass
*) klass
;
142 container_class
= (GtkContainerClass
*) klass
;
143 parent_class
= gtk_type_class (GTK_TYPE_CONTAINER
);
145 widget_class
->map
= gtk_pizza_map
;
146 widget_class
->realize
= gtk_pizza_realize
;
147 widget_class
->unrealize
= gtk_pizza_unrealize
;
148 widget_class
->size_request
= gtk_pizza_size_request
;
149 widget_class
->size_allocate
= gtk_pizza_size_allocate
;
150 widget_class
->draw
= gtk_pizza_draw
;
151 widget_class
->expose_event
= gtk_pizza_expose
;
153 container_class
->add
= gtk_pizza_add
;
154 container_class
->remove
= gtk_pizza_remove
;
155 container_class
->forall
= gtk_pizza_forall
;
157 container_class
->child_type
= gtk_pizza_child_type
;
159 klass
->set_scroll_adjustments
= gtk_pizza_scroll_set_adjustments
;
161 widget_class
->set_scroll_adjustments_signal
=
162 gtk_signal_new ("set_scroll_adjustments",
166 GTK_CLASS_TYPE(object_class
),
170 GTK_SIGNAL_OFFSET (GtkPizzaClass
, set_scroll_adjustments
),
171 gtk_marshal_NONE__POINTER_POINTER
,
172 GTK_TYPE_NONE
, 2, GTK_TYPE_ADJUSTMENT
, GTK_TYPE_ADJUSTMENT
);
176 gtk_pizza_child_type (GtkContainer
*container
)
178 return GTK_TYPE_WIDGET
;
182 gtk_pizza_init (GtkPizza
*pizza
)
184 GTK_WIDGET_UNSET_FLAGS (pizza
, GTK_NO_WINDOW
);
186 pizza
->shadow_type
= GTK_MYSHADOW_NONE
;
188 pizza
->children
= NULL
;
193 pizza
->bin_window
= NULL
;
198 pizza
->configure_serial
= 0;
201 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
203 pizza
->clear_on_draw
= TRUE
;
204 pizza
->use_filter
= TRUE
;
205 pizza
->external_expose
= FALSE
;
213 pizza
= gtk_type_new (gtk_pizza_get_type ());
215 return GTK_WIDGET (pizza
);
219 gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
223 /* We handle scrolling in the wxScrolledWindow, not here. */
227 gtk_pizza_set_shadow_type (GtkPizza
*pizza
,
228 GtkMyShadowType type
)
230 g_return_if_fail (pizza
!= NULL
);
231 g_return_if_fail (GTK_IS_PIZZA (pizza
));
233 if ((GtkMyShadowType
) pizza
->shadow_type
!= type
)
235 pizza
->shadow_type
= type
;
237 if (GTK_WIDGET_VISIBLE (pizza
))
239 gtk_widget_size_allocate (GTK_WIDGET (pizza
), &(GTK_WIDGET (pizza
)->allocation
));
240 gtk_widget_queue_draw (GTK_WIDGET (pizza
));
246 gtk_pizza_set_clear (GtkPizza
*pizza
,
249 g_return_if_fail (pizza
!= NULL
);
250 g_return_if_fail (GTK_IS_PIZZA (pizza
));
252 pizza
->clear_on_draw
= clear
;
256 gtk_pizza_set_filter (GtkPizza
*pizza
,
259 g_return_if_fail (pizza
!= NULL
);
260 g_return_if_fail (GTK_IS_PIZZA (pizza
));
262 pizza
->use_filter
= use
;
266 gtk_pizza_set_external (GtkPizza
*pizza
,
269 g_return_if_fail (pizza
!= NULL
);
270 g_return_if_fail (GTK_IS_PIZZA (pizza
));
272 pizza
->external_expose
= expose
;
276 gtk_pizza_put (GtkPizza
*pizza
,
283 GtkPizzaChild
*child_info
;
285 g_return_if_fail (pizza
!= NULL
);
286 g_return_if_fail (GTK_IS_PIZZA (pizza
));
287 g_return_if_fail (widget
!= NULL
);
289 child_info
= g_new (GtkPizzaChild
, 1);
291 child_info
->widget
= widget
;
294 child_info
->width
= width
;
295 child_info
->height
= height
;
297 pizza
->children
= g_list_append (pizza
->children
, child_info
);
299 gtk_widget_set_parent (widget
, GTK_WIDGET (pizza
));
301 if (GTK_WIDGET_REALIZED (pizza
))
302 gtk_widget_set_parent_window (widget
, pizza
->bin_window
);
304 #ifndef __WXGTK20__ /* FIXME? */
305 if (!IS_ONSCREEN (x
, y
))
306 GTK_PRIVATE_SET_FLAG (widget
, GTK_IS_OFFSCREEN
);
310 if (GTK_WIDGET_REALIZED (pizza))
311 gtk_widget_realize (widget);
314 gtk_widget_set_usize (widget
, width
, height
);
317 if (GTK_WIDGET_VISIBLE (pizza) && GTK_WIDGET_VISIBLE (widget))
319 if (GTK_WIDGET_MAPPED (pizza))
320 gtk_widget_map (widget);
322 gtk_widget_queue_resize (widget);
328 gtk_pizza_move (GtkPizza
*pizza
,
333 GtkPizzaChild
*child
;
336 g_return_if_fail (pizza
!= NULL
);
337 g_return_if_fail (GTK_IS_PIZZA (pizza
));
338 g_return_if_fail (widget
!= NULL
);
340 children
= pizza
->children
;
343 child
= children
->data
;
344 children
= children
->next
;
346 if (child
->widget
== widget
)
348 if ((child
->x
== x
) && (child
->y
== y
))
354 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
355 gtk_widget_queue_resize (widget
);
362 gtk_pizza_resize (GtkPizza
*pizza
,
367 GtkPizzaChild
*child
;
370 g_return_if_fail (pizza
!= NULL
);
371 g_return_if_fail (GTK_IS_PIZZA (pizza
));
372 g_return_if_fail (widget
!= NULL
);
374 children
= pizza
->children
;
377 child
= children
->data
;
378 children
= children
->next
;
380 if (child
->widget
== widget
)
382 if ((child
->width
== width
) && (child
->height
== height
))
385 child
->width
= width
;
386 child
->height
= height
;
388 gtk_widget_set_usize (widget
, width
, height
);
390 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
391 gtk_widget_queue_resize (widget
);
398 gtk_pizza_set_size (GtkPizza
*pizza
,
405 GtkPizzaChild
*child
;
408 g_return_if_fail (pizza
!= NULL
);
409 g_return_if_fail (GTK_IS_PIZZA (pizza
));
410 g_return_if_fail (widget
!= NULL
);
412 children
= pizza
->children
;
415 child
= children
->data
;
416 children
= children
->next
;
418 if (child
->widget
== widget
)
420 if ((child
->x
== x
) &&
422 (child
->width
== width
) &&
423 (child
->height
== height
)) return;
427 child
->width
= width
;
428 child
->height
= height
;
430 gtk_widget_set_usize (widget
, width
, height
);
432 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
433 gtk_widget_queue_resize (widget
);
441 gtk_pizza_child_resized (GtkPizza
*pizza
,
444 GtkPizzaChild
*child
;
447 g_return_val_if_fail (pizza
!= NULL
, FALSE
);
448 g_return_val_if_fail (GTK_IS_PIZZA (pizza
), FALSE
);
449 g_return_val_if_fail (widget
!= NULL
, FALSE
);
451 children
= pizza
->children
;
454 child
= children
->data
;
455 children
= children
->next
;
457 if (child
->widget
== widget
)
459 return ((child
->width
== widget
->allocation
.width
) &&
460 (child
->height
== widget
->allocation
.height
));
468 gtk_pizza_map (GtkWidget
*widget
)
471 GtkPizzaChild
*child
;
474 g_return_if_fail (widget
!= NULL
);
475 g_return_if_fail (GTK_IS_PIZZA (widget
));
477 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
478 pizza
= GTK_PIZZA (widget
);
480 children
= pizza
->children
;
483 child
= children
->data
;
484 children
= children
->next
;
486 if ( GTK_WIDGET_VISIBLE (child
->widget
) &&
487 !GTK_WIDGET_MAPPED (child
->widget
) &&
491 !GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
494 gtk_widget_map (child
->widget
);
498 gdk_window_show (widget
->window
);
499 gdk_window_show (pizza
->bin_window
);
503 gtk_pizza_realize (GtkWidget
*widget
)
506 GdkWindowAttr attributes
;
507 gint attributes_mask
;
508 GtkPizzaChild
*child
;
511 g_return_if_fail (widget
!= NULL
);
512 g_return_if_fail (GTK_IS_PIZZA (widget
));
514 pizza
= GTK_PIZZA (widget
);
516 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
518 attributes
.window_type
= GDK_WINDOW_CHILD
;
520 attributes
.x
= widget
->allocation
.x
;
521 attributes
.y
= widget
->allocation
.y
;
522 attributes
.width
= widget
->allocation
.width
;
523 attributes
.height
= widget
->allocation
.height
;
525 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
527 /* no border, no changes to sizes */
529 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
531 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
534 attributes
.width
-= 2;
535 attributes
.height
-= 2;
538 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
539 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
542 attributes
.width
-= 4;
543 attributes
.height
-= 4;
547 if (attributes
.width
< 2) attributes
.width
= 2;
548 if (attributes
.height
< 2) attributes
.height
= 2;
550 attributes
.wclass
= GDK_INPUT_OUTPUT
;
551 attributes
.visual
= gtk_widget_get_visual (widget
);
552 attributes
.colormap
= gtk_widget_get_colormap (widget
);
553 attributes
.event_mask
=
554 GDK_VISIBILITY_NOTIFY_MASK
;
555 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
557 widget
->window
= gdk_window_new(gtk_widget_get_parent_window (widget
),
558 &attributes
, attributes_mask
);
559 gdk_window_set_user_data (widget
->window
, widget
);
564 attributes
.event_mask
= gtk_widget_get_events (widget
);
565 attributes
.event_mask
|=
567 GDK_POINTER_MOTION_MASK
|
568 GDK_POINTER_MOTION_HINT_MASK
|
569 GDK_BUTTON_MOTION_MASK
|
570 GDK_BUTTON1_MOTION_MASK
|
571 GDK_BUTTON2_MOTION_MASK
|
572 GDK_BUTTON3_MOTION_MASK
|
573 GDK_BUTTON_PRESS_MASK
|
574 GDK_BUTTON_RELEASE_MASK
|
576 GDK_KEY_RELEASE_MASK
|
577 GDK_ENTER_NOTIFY_MASK
|
578 GDK_LEAVE_NOTIFY_MASK
|
579 GDK_FOCUS_CHANGE_MASK
;
581 pizza
->bin_window
= gdk_window_new(widget
->window
,
582 &attributes
, attributes_mask
);
583 gdk_window_set_user_data (pizza
->bin_window
, widget
);
585 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
586 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
587 gtk_style_set_background (widget
->style
, pizza
->bin_window
, GTK_STATE_NORMAL
);
589 /* add filters for intercepting visibility and expose events */
590 gdk_window_add_filter (widget
->window
, gtk_pizza_main_filter
, pizza
);
591 gdk_window_add_filter (pizza
->bin_window
, gtk_pizza_filter
, pizza
);
593 /* we NEED gravity or we'll give up */
594 gravity_works
= gdk_window_set_static_gravities (pizza
->bin_window
, TRUE
);
596 /* cannot be done before realisation */
597 children
= pizza
->children
;
600 child
= children
->data
;
601 children
= children
->next
;
603 gtk_widget_set_parent_window (child
->widget
, pizza
->bin_window
);
608 gtk_pizza_unrealize (GtkWidget
*widget
)
612 g_return_if_fail (widget
!= NULL
);
613 g_return_if_fail (GTK_IS_PIZZA (widget
));
615 pizza
= GTK_PIZZA (widget
);
617 gdk_window_set_user_data (pizza
->bin_window
, NULL
);
618 gdk_window_destroy (pizza
->bin_window
);
619 pizza
->bin_window
= NULL
;
621 if (GTK_WIDGET_CLASS (parent_class
)->unrealize
)
622 (* GTK_WIDGET_CLASS (parent_class
)->unrealize
) (widget
);
626 gtk_pizza_size_request (GtkWidget
*widget
,
627 GtkRequisition
*requisition
)
630 GtkPizzaChild
*child
;
632 GtkRequisition child_requisition
;
634 g_return_if_fail (widget
!= NULL
);
635 g_return_if_fail (GTK_IS_PIZZA (widget
));
636 g_return_if_fail (requisition
!= NULL
);
638 pizza
= GTK_PIZZA (widget
);
640 children
= pizza
->children
;
643 child
= children
->data
;
644 children
= children
->next
;
646 if (GTK_WIDGET_VISIBLE (child
->widget
))
648 gtk_widget_size_request (child
->widget
, &child_requisition
);
652 /* request very little, I'm not sure if requesting nothing
653 will always have positive effects on stability... */
654 requisition
->width
= 2;
655 requisition
->height
= 2;
659 gtk_pizza_size_allocate (GtkWidget
*widget
,
660 GtkAllocation
*allocation
)
665 GtkPizzaChild
*child
;
668 g_return_if_fail (widget
!= NULL
);
669 g_return_if_fail (GTK_IS_PIZZA(widget
));
670 g_return_if_fail (allocation
!= NULL
);
672 pizza
= GTK_PIZZA (widget
);
674 widget
->allocation
= *allocation
;
676 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
679 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
684 x
= allocation
->x
+ border
;
685 y
= allocation
->y
+ border
;
686 w
= allocation
->width
- border
*2;
687 h
= allocation
->height
- border
*2;
689 if (GTK_WIDGET_REALIZED (widget
))
691 gdk_window_move_resize( widget
->window
, x
, y
, w
, h
);
692 gdk_window_move_resize( pizza
->bin_window
, 0, 0, w
, h
);
695 children
= pizza
->children
;
698 child
= children
->data
;
699 children
= children
->next
;
701 gtk_pizza_position_child (pizza
, child
);
702 gtk_pizza_allocate_child (pizza
, child
);
707 gtk_pizza_draw (GtkWidget
*widget
,
711 GtkPizzaChild
*child
;
712 GdkRectangle child_area
;
715 g_return_if_fail (widget
!= NULL
);
716 g_return_if_fail (GTK_IS_PIZZA (widget
));
718 pizza
= GTK_PIZZA (widget
);
720 /* Sometimes, We handle all expose events in window.cpp now. */
721 if (pizza
->external_expose
)
724 children
= pizza
->children
;
725 if ( !(GTK_WIDGET_APP_PAINTABLE (widget
)) &&
726 (pizza
->clear_on_draw
))
728 gdk_window_clear_area( pizza
->bin_window
,
729 area
->x
, area
->y
, area
->width
, area
->height
);
734 child
= children
->data
;
735 children
= children
->next
;
737 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
738 gtk_widget_draw (child
->widget
, &child_area
);
743 gtk_pizza_expose (GtkWidget
*widget
,
744 GdkEventExpose
*event
)
747 GtkPizzaChild
*child
;
748 GdkEventExpose child_event
;
751 g_return_val_if_fail (widget
!= NULL
, FALSE
);
752 g_return_val_if_fail (GTK_IS_PIZZA (widget
), FALSE
);
753 g_return_val_if_fail (event
!= NULL
, FALSE
);
755 pizza
= GTK_PIZZA (widget
);
757 /* Sometimes, We handle all expose events in window.cpp now. */
758 if (pizza
->external_expose
)
761 if (event
->window
!= pizza
->bin_window
)
764 children
= pizza
->children
;
767 child
= children
->data
;
768 children
= children
->next
;
770 child_event
= *event
;
772 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
773 GTK_WIDGET_DRAWABLE (child
->widget
) &&
774 gtk_widget_intersect (child
->widget
, &event
->area
, &child_event
.area
))
776 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
784 gtk_pizza_add (GtkContainer
*container
,
787 g_return_if_fail (container
!= NULL
);
788 g_return_if_fail (GTK_IS_PIZZA (container
));
789 g_return_if_fail (widget
!= NULL
);
791 gtk_pizza_put (GTK_PIZZA (container
), widget
, 0, 0, 20, 20 );
795 gtk_pizza_remove (GtkContainer
*container
,
799 GtkPizzaChild
*child
;
802 g_return_if_fail (container
!= NULL
);
803 g_return_if_fail (GTK_IS_PIZZA (container
));
804 g_return_if_fail (widget
!= NULL
);
806 pizza
= GTK_PIZZA (container
);
808 children
= pizza
->children
;
811 child
= children
->data
;
813 if (child
->widget
== widget
)
815 gtk_widget_unparent (widget
);
817 /* security checks */
818 g_return_if_fail (GTK_IS_WIDGET (widget
));
820 pizza
->children
= g_list_remove_link (pizza
->children
, children
);
821 g_list_free (children
);
824 /* security checks */
825 g_return_if_fail (GTK_IS_WIDGET (widget
));
828 GTK_PRIVATE_UNSET_FLAG (widget
, GTK_IS_OFFSCREEN
);
834 children
= children
->next
;
839 gtk_pizza_forall (GtkContainer
*container
,
840 gboolean include_internals
,
841 GtkCallback callback
,
842 gpointer callback_data
)
845 GtkPizzaChild
*child
;
848 g_return_if_fail (container
!= NULL
);
849 g_return_if_fail (GTK_IS_PIZZA (container
));
850 g_return_if_fail (callback
!= NULL
);
852 pizza
= GTK_PIZZA (container
);
854 children
= pizza
->children
;
857 child
= children
->data
;
858 children
= children
->next
;
860 (* callback
) (child
->widget
, callback_data
);
865 /* Operations on children
869 gtk_pizza_position_child (GtkPizza
*pizza
,
870 GtkPizzaChild
*child
)
875 x
= child
->x
- pizza
->xoffset
;
876 y
= child
->y
- pizza
->yoffset
;
878 if (IS_ONSCREEN (x
,y
))
880 if (GTK_WIDGET_MAPPED (pizza
) &&
881 GTK_WIDGET_VISIBLE (child
->widget
))
883 if (!GTK_WIDGET_MAPPED (child
->widget
))
884 gtk_widget_map (child
->widget
);
888 if (GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
889 GTK_PRIVATE_UNSET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
895 if (!GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
896 GTK_PRIVATE_SET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
899 if (GTK_WIDGET_MAPPED (child
->widget
))
900 gtk_widget_unmap (child
->widget
);
905 gtk_pizza_allocate_child (GtkPizza
*pizza
,
906 GtkPizzaChild
*child
)
908 GtkAllocation allocation
;
909 GtkRequisition requisition
;
911 allocation
.x
= child
->x
- pizza
->xoffset
;
912 allocation
.y
= child
->y
- pizza
->yoffset
;
913 gtk_widget_get_child_requisition (child
->widget
, &requisition
);
914 allocation
.width
= requisition
.width
;
915 allocation
.height
= requisition
.height
;
917 gtk_widget_size_allocate (child
->widget
, &allocation
);
921 gtk_pizza_position_children (GtkPizza
*pizza
)
925 tmp_list
= pizza
->children
;
928 GtkPizzaChild
*child
= tmp_list
->data
;
929 tmp_list
= tmp_list
->next
;
931 gtk_pizza_position_child (pizza
, child
);
936 gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
939 GtkPizzaAdjData
*data
= cb_data
;
941 widget
->allocation
.x
+= data
->dx
;
942 widget
->allocation
.y
+= data
->dy
;
944 if (GTK_WIDGET_NO_WINDOW (widget
) && GTK_IS_CONTAINER (widget
))
946 gtk_container_forall (GTK_CONTAINER (widget
),
947 gtk_pizza_adjust_allocations_recurse
,
953 gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
958 GtkPizzaAdjData data
;
963 tmp_list
= pizza
->children
;
966 GtkPizzaChild
*child
= tmp_list
->data
;
967 tmp_list
= tmp_list
->next
;
969 child
->widget
->allocation
.x
+= dx
;
970 child
->widget
->allocation
.y
+= dy
;
972 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
973 GTK_IS_CONTAINER (child
->widget
))
975 gtk_container_forall (GTK_CONTAINER (child
->widget
),
976 gtk_pizza_adjust_allocations_recurse
,
984 /* Send a synthetic expose event to the widget
987 gtk_pizza_expose_area (GtkPizza
*pizza
,
988 gint x
, gint y
, gint width
, gint height
)
990 if (pizza
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
992 GdkEventExpose event
;
994 event
.type
= GDK_EXPOSE
;
995 event
.send_event
= TRUE
;
996 event
.window
= pizza
->bin_window
;
1001 event
.area
.width
= width
;
1002 event
.area
.height
= height
;
1004 gdk_window_ref (event
.window
);
1005 gtk_widget_event (GTK_WIDGET (pizza
), (GdkEvent
*)&event
);
1006 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 */