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"
13 #include "gtk/gtksignal.h"
14 #include "gtk/gtkprivate.h"
19 #endif /* __cplusplus */
22 #include <X11/Xutil.h>
23 #include <X11/Xatom.h>
25 #define IS_ONSCREEN(x,y) ((x >= G_MINSHORT) && (x <= G_MAXSHORT) && \
26 (y >= G_MINSHORT) && (y <= G_MAXSHORT))
28 typedef struct _GtkPizzaAdjData GtkPizzaAdjData
;
29 typedef struct _GtkPizzaChild GtkPizzaChild
;
31 struct _GtkPizzaAdjData
46 static void gtk_pizza_class_init (GtkPizzaClass
*klass
);
47 static void gtk_pizza_init (GtkPizza
*pizza
);
49 static void gtk_pizza_realize (GtkWidget
*widget
);
50 static void gtk_pizza_unrealize (GtkWidget
*widget
);
52 static void gtk_pizza_map (GtkWidget
*widget
);
54 static void gtk_pizza_size_request (GtkWidget
*widget
,
55 GtkRequisition
*requisition
);
56 static void gtk_pizza_size_allocate (GtkWidget
*widget
,
57 GtkAllocation
*allocation
);
58 static void gtk_pizza_draw (GtkWidget
*widget
,
60 static gint
gtk_pizza_expose (GtkWidget
*widget
,
61 GdkEventExpose
*event
);
62 static void gtk_pizza_add (GtkContainer
*container
,
64 static void gtk_pizza_remove (GtkContainer
*container
,
66 static void gtk_pizza_forall (GtkContainer
*container
,
67 gboolean include_internals
,
69 gpointer callback_data
);
71 static void gtk_pizza_position_child (GtkPizza
*pizza
,
72 GtkPizzaChild
*child
);
73 static void gtk_pizza_allocate_child (GtkPizza
*pizza
,
74 GtkPizzaChild
*child
);
75 static void gtk_pizza_position_children (GtkPizza
*pizza
);
77 static void gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
79 static void gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
84 static void gtk_pizza_expose_area (GtkPizza
*pizza
,
89 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",
165 GTK_SIGNAL_OFFSET (GtkPizzaClass
, set_scroll_adjustments
),
166 gtk_marshal_NONE__POINTER_POINTER
,
167 GTK_TYPE_NONE
, 2, GTK_TYPE_ADJUSTMENT
, GTK_TYPE_ADJUSTMENT
);
171 gtk_pizza_child_type (GtkContainer
*container
)
173 return GTK_TYPE_WIDGET
;
177 gtk_pizza_init (GtkPizza
*pizza
)
179 GTK_WIDGET_UNSET_FLAGS (pizza
, GTK_NO_WINDOW
);
181 pizza
->shadow_type
= GTK_MYSHADOW_NONE
;
183 pizza
->children
= NULL
;
188 pizza
->bin_window
= NULL
;
190 pizza
->configure_serial
= 0;
193 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
195 pizza
->clear_on_draw
= TRUE
;
203 pizza
= gtk_type_new (gtk_pizza_get_type ());
205 return GTK_WIDGET (pizza
);
209 gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
213 /* We handle scrolling in the wxScrolledWindow, not here. */
217 gtk_pizza_set_shadow_type (GtkPizza
*pizza
,
218 GtkMyShadowType type
)
220 g_return_if_fail (pizza
!= NULL
);
221 g_return_if_fail (GTK_IS_PIZZA (pizza
));
223 if ((GtkMyShadowType
) pizza
->shadow_type
!= type
)
225 pizza
->shadow_type
= type
;
227 if (GTK_WIDGET_VISIBLE (pizza
))
229 gtk_widget_size_allocate (GTK_WIDGET (pizza
), &(GTK_WIDGET (pizza
)->allocation
));
230 gtk_widget_queue_draw (GTK_WIDGET (pizza
));
236 gtk_pizza_set_clear (GtkPizza
*pizza
,
239 g_return_if_fail (pizza
!= NULL
);
240 g_return_if_fail (GTK_IS_PIZZA (pizza
));
242 pizza
->clear_on_draw
= clear
;
246 gtk_pizza_put (GtkPizza
*pizza
,
253 GtkPizzaChild
*child_info
;
255 g_return_if_fail (pizza
!= NULL
);
256 g_return_if_fail (GTK_IS_PIZZA (pizza
));
257 g_return_if_fail (widget
!= NULL
);
259 child_info
= g_new (GtkPizzaChild
, 1);
261 child_info
->widget
= widget
;
264 child_info
->width
= width
;
265 child_info
->height
= height
;
267 pizza
->children
= g_list_append (pizza
->children
, child_info
);
269 gtk_widget_set_parent (widget
, GTK_WIDGET (pizza
));
271 if (GTK_WIDGET_REALIZED (pizza
))
272 gtk_widget_set_parent_window (widget
, pizza
->bin_window
);
274 if (!IS_ONSCREEN (x
, y
))
275 GTK_PRIVATE_SET_FLAG (widget
, GTK_IS_OFFSCREEN
);
277 if (GTK_WIDGET_REALIZED (pizza
))
278 gtk_widget_realize (widget
);
280 gtk_widget_set_usize (widget
, width
, height
);
282 if (GTK_WIDGET_VISIBLE (pizza
) && GTK_WIDGET_VISIBLE (widget
))
284 if (GTK_WIDGET_MAPPED (pizza
))
285 gtk_widget_map (widget
);
287 gtk_widget_queue_resize (widget
);
292 gtk_pizza_move (GtkPizza
*pizza
,
297 GtkPizzaChild
*child
;
300 g_return_if_fail (pizza
!= NULL
);
301 g_return_if_fail (GTK_IS_PIZZA (pizza
));
302 g_return_if_fail (widget
!= NULL
);
304 children
= pizza
->children
;
307 child
= children
->data
;
308 children
= children
->next
;
310 if (child
->widget
== widget
)
312 if ((child
->x
== x
) && (child
->y
== y
))
318 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
319 gtk_widget_queue_resize (widget
);
326 gtk_pizza_resize (GtkPizza
*pizza
,
331 GtkPizzaChild
*child
;
334 g_return_if_fail (pizza
!= NULL
);
335 g_return_if_fail (GTK_IS_PIZZA (pizza
));
336 g_return_if_fail (widget
!= NULL
);
338 children
= pizza
->children
;
341 child
= children
->data
;
342 children
= children
->next
;
344 if (child
->widget
== widget
)
346 if ((child
->width
== width
) && (child
->height
== height
))
349 child
->width
= width
;
350 child
->height
= height
;
352 gtk_widget_set_usize (widget
, width
, height
);
354 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
355 gtk_widget_queue_resize (widget
);
362 gtk_pizza_set_size (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
->x
== x
) &&
386 (child
->width
== width
) &&
387 (child
->height
== height
)) return;
391 child
->width
= width
;
392 child
->height
= height
;
394 gtk_widget_set_usize (widget
, width
, height
);
396 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
397 gtk_widget_queue_resize (widget
);
405 gtk_pizza_map (GtkWidget
*widget
)
408 GtkPizzaChild
*child
;
411 g_return_if_fail (widget
!= NULL
);
412 g_return_if_fail (GTK_IS_PIZZA (widget
));
414 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
415 pizza
= GTK_PIZZA (widget
);
417 children
= pizza
->children
;
420 child
= children
->data
;
421 children
= children
->next
;
423 if ( GTK_WIDGET_VISIBLE (child
->widget
) &&
424 !GTK_WIDGET_MAPPED (child
->widget
) &&
425 !GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
427 gtk_widget_map (child
->widget
);
431 gdk_window_show (widget
->window
);
432 gdk_window_show (pizza
->bin_window
);
436 gtk_pizza_realize (GtkWidget
*widget
)
439 GdkWindowAttr attributes
;
440 gint attributes_mask
;
441 GtkPizzaChild
*child
;
444 g_return_if_fail (widget
!= NULL
);
445 g_return_if_fail (GTK_IS_PIZZA (widget
));
447 pizza
= GTK_PIZZA (widget
);
449 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
451 attributes
.window_type
= GDK_WINDOW_CHILD
;
453 attributes
.x
= widget
->allocation
.x
;
454 attributes
.y
= widget
->allocation
.y
;
455 attributes
.width
= widget
->allocation
.width
;
456 attributes
.height
= widget
->allocation
.height
;
458 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
460 /* no border, no changes to sizes */
462 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
464 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
467 attributes
.width
-= 2;
468 attributes
.height
-= 2;
471 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
472 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
475 attributes
.width
-= 4;
476 attributes
.height
-= 4;
480 if (attributes
.width
< 2) attributes
.width
= 2;
481 if (attributes
.height
< 2) attributes
.height
= 2;
483 attributes
.wclass
= GDK_INPUT_OUTPUT
;
484 attributes
.visual
= gtk_widget_get_visual (widget
);
485 attributes
.colormap
= gtk_widget_get_colormap (widget
);
486 attributes
.event_mask
=
487 GDK_VISIBILITY_NOTIFY_MASK
;
488 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
490 widget
->window
= gdk_window_new(gtk_widget_get_parent_window (widget
),
491 &attributes
, attributes_mask
);
492 gdk_window_set_user_data (widget
->window
, widget
);
497 attributes
.event_mask
= gtk_widget_get_events (widget
);
498 attributes
.event_mask
|=
500 GDK_POINTER_MOTION_MASK
|
501 GDK_POINTER_MOTION_HINT_MASK
|
502 GDK_BUTTON_MOTION_MASK
|
503 GDK_BUTTON1_MOTION_MASK
|
504 GDK_BUTTON2_MOTION_MASK
|
505 GDK_BUTTON3_MOTION_MASK
|
506 GDK_BUTTON_PRESS_MASK
|
507 GDK_BUTTON_RELEASE_MASK
|
509 GDK_KEY_RELEASE_MASK
|
510 GDK_ENTER_NOTIFY_MASK
|
511 GDK_LEAVE_NOTIFY_MASK
|
512 GDK_FOCUS_CHANGE_MASK
;
514 pizza
->bin_window
= gdk_window_new(widget
->window
,
515 &attributes
, attributes_mask
);
516 gdk_window_set_user_data (pizza
->bin_window
, widget
);
518 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
519 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
520 gtk_style_set_background (widget
->style
, pizza
->bin_window
, GTK_STATE_NORMAL
);
522 /* add filters for intercepting visibility and expose events */
523 gdk_window_add_filter (widget
->window
, gtk_pizza_main_filter
, pizza
);
524 gdk_window_add_filter (pizza
->bin_window
, gtk_pizza_filter
, pizza
);
526 /* we NEED gravity or we'll give up */
527 gravity_works
= gdk_window_set_static_gravities (pizza
->bin_window
, TRUE
);
529 /* cannot be done before realisation */
530 children
= pizza
->children
;
533 child
= children
->data
;
534 children
= children
->next
;
536 gtk_widget_set_parent_window (child
->widget
, pizza
->bin_window
);
541 gtk_pizza_unrealize (GtkWidget
*widget
)
545 g_return_if_fail (widget
!= NULL
);
546 g_return_if_fail (GTK_IS_PIZZA (widget
));
548 pizza
= GTK_PIZZA (widget
);
550 gdk_window_set_user_data (pizza
->bin_window
, NULL
);
551 gdk_window_destroy (pizza
->bin_window
);
552 pizza
->bin_window
= NULL
;
554 if (GTK_WIDGET_CLASS (parent_class
)->unrealize
)
555 (* GTK_WIDGET_CLASS (parent_class
)->unrealize
) (widget
);
559 gtk_pizza_size_request (GtkWidget
*widget
,
560 GtkRequisition
*requisition
)
563 GtkPizzaChild
*child
;
565 GtkRequisition child_requisition
;
567 g_return_if_fail (widget
!= NULL
);
568 g_return_if_fail (GTK_IS_PIZZA (widget
));
569 g_return_if_fail (requisition
!= NULL
);
571 pizza
= GTK_PIZZA (widget
);
573 children
= pizza
->children
;
576 child
= children
->data
;
577 children
= children
->next
;
579 if (GTK_WIDGET_VISIBLE (child
->widget
))
581 gtk_widget_size_request (child
->widget
, &child_requisition
);
585 /* request very little, I'm not sure if requesting nothing
586 will always have positive effects on stability... */
587 requisition
->width
= 2;
588 requisition
->height
= 2;
592 gtk_pizza_size_allocate (GtkWidget
*widget
,
593 GtkAllocation
*allocation
)
598 GtkPizzaChild
*child
;
601 g_return_if_fail (widget
!= NULL
);
602 g_return_if_fail (GTK_IS_PIZZA(widget
));
603 g_return_if_fail (allocation
!= NULL
);
605 pizza
= GTK_PIZZA (widget
);
607 widget
->allocation
= *allocation
;
609 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
612 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
617 x
= allocation
->x
+ border
;
618 y
= allocation
->y
+ border
;
619 w
= allocation
->width
- border
*2;
620 h
= allocation
->height
- border
*2;
622 if (GTK_WIDGET_REALIZED (widget
))
624 gdk_window_move_resize( widget
->window
, x
, y
, w
, h
);
625 gdk_window_move_resize( pizza
->bin_window
, 0, 0, w
, h
);
628 children
= pizza
->children
;
631 child
= children
->data
;
632 children
= children
->next
;
634 gtk_pizza_position_child (pizza
, child
);
635 gtk_pizza_allocate_child (pizza
, child
);
640 gtk_pizza_draw (GtkWidget
*widget
,
644 GtkPizzaChild
*child
;
645 GdkRectangle child_area
;
648 g_return_if_fail (widget
!= NULL
);
649 g_return_if_fail (GTK_IS_PIZZA (widget
));
651 pizza
= GTK_PIZZA (widget
);
653 children
= pizza
->children
;
654 if ( !(GTK_WIDGET_APP_PAINTABLE (widget
)) &&
655 (pizza
->clear_on_draw
))
657 gdk_window_clear_area( pizza
->bin_window
,
658 area
->x
, area
->y
, area
->width
, area
->height
);
663 child
= children
->data
;
664 children
= children
->next
;
666 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
667 gtk_widget_draw (child
->widget
, &child_area
);
672 gtk_pizza_expose (GtkWidget
*widget
,
673 GdkEventExpose
*event
)
676 GtkPizzaChild
*child
;
677 GdkEventExpose child_event
;
680 g_return_val_if_fail (widget
!= NULL
, FALSE
);
681 g_return_val_if_fail (GTK_IS_PIZZA (widget
), FALSE
);
682 g_return_val_if_fail (event
!= NULL
, FALSE
);
684 pizza
= GTK_PIZZA (widget
);
687 if (event->window == widget->window)
689 gtk_pizza_draw_border( pizza );
694 if (event
->window
!= pizza
->bin_window
)
697 children
= pizza
->children
;
700 child
= children
->data
;
701 children
= children
->next
;
703 child_event
= *event
;
705 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
706 GTK_WIDGET_DRAWABLE (child
->widget
) &&
707 gtk_widget_intersect (child
->widget
, &event
->area
, &child_event
.area
))
709 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
717 gtk_pizza_add (GtkContainer
*container
,
720 g_return_if_fail (container
!= NULL
);
721 g_return_if_fail (GTK_IS_PIZZA (container
));
722 g_return_if_fail (widget
!= NULL
);
724 gtk_pizza_put (GTK_PIZZA (container
), widget
, 0, 0, 20, 20 );
728 gtk_pizza_remove (GtkContainer
*container
,
732 GtkPizzaChild
*child
;
735 g_return_if_fail (container
!= NULL
);
736 g_return_if_fail (GTK_IS_PIZZA (container
));
737 g_return_if_fail (widget
!= NULL
);
739 pizza
= GTK_PIZZA (container
);
741 children
= pizza
->children
;
744 child
= children
->data
;
746 if (child
->widget
== widget
)
748 gtk_widget_unparent (widget
);
750 /* security checks */
751 g_return_if_fail (GTK_IS_WIDGET (widget
));
753 pizza
->children
= g_list_remove_link (pizza
->children
, children
);
754 g_list_free (children
);
757 /* security checks */
758 g_return_if_fail (GTK_IS_WIDGET (widget
));
760 GTK_PRIVATE_UNSET_FLAG (widget
, GTK_IS_OFFSCREEN
);
765 children
= children
->next
;
770 gtk_pizza_forall (GtkContainer
*container
,
771 gboolean include_internals
,
772 GtkCallback callback
,
773 gpointer callback_data
)
776 GtkPizzaChild
*child
;
779 g_return_if_fail (container
!= NULL
);
780 g_return_if_fail (GTK_IS_PIZZA (container
));
781 g_return_if_fail (callback
!= NULL
);
783 pizza
= GTK_PIZZA (container
);
785 children
= pizza
->children
;
788 child
= children
->data
;
789 children
= children
->next
;
791 (* callback
) (child
->widget
, callback_data
);
796 /* Operations on children
800 gtk_pizza_position_child (GtkPizza
*pizza
,
801 GtkPizzaChild
*child
)
806 x
= child
->x
- pizza
->xoffset
;
807 y
= child
->y
- pizza
->yoffset
;
809 if (IS_ONSCREEN (x
,y
))
811 if (GTK_WIDGET_MAPPED (pizza
) &&
812 GTK_WIDGET_VISIBLE (child
->widget
))
814 if (!GTK_WIDGET_MAPPED (child
->widget
))
815 gtk_widget_map (child
->widget
);
818 if (GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
819 GTK_PRIVATE_UNSET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
823 if (!GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
824 GTK_PRIVATE_SET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
826 if (GTK_WIDGET_MAPPED (child
->widget
))
827 gtk_widget_unmap (child
->widget
);
832 gtk_pizza_allocate_child (GtkPizza
*pizza
,
833 GtkPizzaChild
*child
)
835 GtkAllocation allocation
;
836 GtkRequisition requisition
;
838 allocation
.x
= child
->x
- pizza
->xoffset
;
839 allocation
.y
= child
->y
- pizza
->yoffset
;
840 gtk_widget_get_child_requisition (child
->widget
, &requisition
);
841 allocation
.width
= requisition
.width
;
842 allocation
.height
= requisition
.height
;
844 gtk_widget_size_allocate (child
->widget
, &allocation
);
848 gtk_pizza_position_children (GtkPizza
*pizza
)
852 tmp_list
= pizza
->children
;
855 GtkPizzaChild
*child
= tmp_list
->data
;
856 tmp_list
= tmp_list
->next
;
858 gtk_pizza_position_child (pizza
, child
);
863 gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
866 GtkPizzaAdjData
*data
= cb_data
;
868 widget
->allocation
.x
+= data
->dx
;
869 widget
->allocation
.y
+= data
->dy
;
871 if (GTK_WIDGET_NO_WINDOW (widget
) && GTK_IS_CONTAINER (widget
))
873 gtk_container_forall (GTK_CONTAINER (widget
),
874 gtk_pizza_adjust_allocations_recurse
,
880 gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
885 GtkPizzaAdjData data
;
890 tmp_list
= pizza
->children
;
893 GtkPizzaChild
*child
= tmp_list
->data
;
894 tmp_list
= tmp_list
->next
;
896 child
->widget
->allocation
.x
+= dx
;
897 child
->widget
->allocation
.y
+= dy
;
899 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
900 GTK_IS_CONTAINER (child
->widget
))
901 gtk_container_forall (GTK_CONTAINER (child
->widget
),
902 gtk_pizza_adjust_allocations_recurse
,
909 /* Send a synthetic expose event to the widget
912 gtk_pizza_expose_area (GtkPizza
*pizza
,
913 gint x
, gint y
, gint width
, gint height
)
915 if (pizza
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
917 GdkEventExpose event
;
919 event
.type
= GDK_EXPOSE
;
920 event
.send_event
= TRUE
;
921 event
.window
= pizza
->bin_window
;
926 event
.area
.width
= width
;
927 event
.area
.height
= height
;
929 gdk_window_ref (event
.window
);
930 gtk_widget_event (GTK_WIDGET (pizza
), (GdkEvent
*)&event
);
931 gdk_window_unref (event
.window
);
935 /* This function is used to find events to process while scrolling
939 gtk_pizza_expose_predicate (Display
*display
,
943 if ((xevent
->type
== Expose
) ||
944 ((xevent
->xany
.window
== *(Window
*)arg
) &&
945 (xevent
->type
== ConfigureNotify
)))
951 /* This is the main routine to do the scrolling. Scrolling is
952 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
953 * a few modifications.
955 * The main improvement is that we keep track of whether we
956 * are obscured or not. If not, we ignore the generated expose
957 * events and instead do the exposes ourself, without having
958 * to wait for a roundtrip to the server. This also provides
959 * a limited form of expose-event compression, since we do
960 * the affected area as one big chunk.
964 gtk_pizza_scroll (GtkPizza
*pizza
, gint dx
, gint dy
)
971 widget
= GTK_WIDGET (pizza
);
973 pizza
->xoffset
+= dx
;
974 pizza
->yoffset
+= dy
;
976 if (!GTK_WIDGET_MAPPED (pizza
))
978 gtk_pizza_position_children (pizza
);
982 gtk_pizza_adjust_allocations (pizza
, -dx
, -dy
);
984 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
987 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
994 w
= widget
->allocation
.width
- 2*border
;
995 h
= widget
->allocation
.height
- 2*border
;
1001 gdk_window_resize (pizza
->bin_window
,
1004 gdk_window_move (pizza
->bin_window
, x
-dx
, y
);
1005 gdk_window_move_resize (pizza
->bin_window
, x
, y
, w
, h
);
1012 gtk_pizza_expose_area (pizza
,
1013 MAX ((gint
)w
- dx
, 0),
1022 gdk_window_move_resize (pizza
->bin_window
,
1027 gdk_window_move (pizza
->bin_window
, x
, y
);
1028 gdk_window_resize (pizza
->bin_window
, w
, h
);
1035 gtk_pizza_expose_area (pizza
,
1046 gdk_window_resize (pizza
->bin_window
, w
, h
+ dy
);
1047 gdk_window_move (pizza
->bin_window
, x
, y
-dy
);
1048 gdk_window_move_resize (pizza
->bin_window
,
1056 gtk_pizza_expose_area (pizza
,
1058 MAX ((gint
)h
- dy
, 0),
1066 gdk_window_move_resize (pizza
->bin_window
,
1067 x
, y
+dy
, w
, h
- dy
);
1068 gdk_window_move (pizza
->bin_window
, x
, y
);
1069 gdk_window_resize (pizza
->bin_window
, w
, h
);
1075 gtk_pizza_expose_area (pizza
,
1079 MIN (-dy
, (gint
)h
));
1082 gtk_pizza_position_children (pizza
);
1084 /* We have to make sure that all exposes from this scroll get
1085 * processed before we scroll again, or the expose events will
1086 * have invalid coordinates.
1088 * We also do expose events for other windows, since otherwise
1089 * their updating will fall behind the scrolling
1091 * This also avoids a problem in pre-1.0 GTK where filters don't
1092 * have access to configure events that were compressed.
1096 while (XCheckIfEvent(GDK_WINDOW_XDISPLAY (pizza
->bin_window
),
1098 gtk_pizza_expose_predicate
,
1099 (XPointer
)&GDK_WINDOW_XWINDOW (pizza
->bin_window
)))
1102 GtkWidget
*event_widget
;
1104 if ((xevent
.xany
.window
== GDK_WINDOW_XWINDOW (pizza
->bin_window
)) &&
1105 (gtk_pizza_filter (&xevent
, &event
, pizza
) == GDK_FILTER_REMOVE
))
1108 if (xevent
.type
== Expose
)
1110 event
.expose
.window
= gdk_window_lookup (xevent
.xany
.window
);
1111 gdk_window_get_user_data (event
.expose
.window
,
1112 (gpointer
*)&event_widget
);
1116 event
.expose
.type
= GDK_EXPOSE
;
1117 event
.expose
.area
.x
= xevent
.xexpose
.x
;
1118 event
.expose
.area
.y
= xevent
.xexpose
.y
;
1119 event
.expose
.area
.width
= xevent
.xexpose
.width
;
1120 event
.expose
.area
.height
= xevent
.xexpose
.height
;
1121 event
.expose
.count
= xevent
.xexpose
.count
;
1123 gdk_window_ref (event
.expose
.window
);
1124 gtk_widget_event (event_widget
, &event
);
1125 gdk_window_unref (event
.expose
.window
);
1131 /* The main event filter. Actually, we probably don't really need
1132 * to install this as a filter at all, since we are calling it
1133 * directly above in the expose-handling hack. But in case scrollbars
1134 * are fixed up in some manner...
1136 * This routine identifies expose events that are generated when
1137 * we've temporarily moved the bin_window_origin, and translates
1138 * them or discards them, depending on whether we are obscured
1141 static GdkFilterReturn
1142 gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
1149 xevent
= (XEvent
*)gdk_xevent
;
1150 pizza
= GTK_PIZZA (data
);
1152 switch (xevent
->type
)
1155 if (xevent
->xexpose
.serial
== pizza
->configure_serial
)
1157 if (pizza
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
1158 return GDK_FILTER_REMOVE
;
1161 xevent
->xexpose
.x
+= pizza
->scroll_x
;
1162 xevent
->xexpose
.y
+= pizza
->scroll_y
;
1169 case ConfigureNotify
:
1170 if ((xevent
->xconfigure
.x
!= 0) || (xevent
->xconfigure
.y
!= 0))
1172 pizza
->configure_serial
= xevent
->xconfigure
.serial
;
1173 pizza
->scroll_x
= xevent
->xconfigure
.x
;
1174 pizza
->scroll_y
= xevent
->xconfigure
.y
;
1179 return GDK_FILTER_CONTINUE
;
1182 /* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
1183 * there is no corresponding event in GTK, so we have
1184 * to get the events from a filter
1186 static GdkFilterReturn
1187 gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
1194 xevent
= (XEvent
*)gdk_xevent
;
1195 pizza
= GTK_PIZZA (data
);
1197 if (xevent
->type
== VisibilityNotify
)
1199 switch (xevent
->xvisibility
.state
)
1201 case VisibilityFullyObscured
:
1202 pizza
->visibility
= GDK_VISIBILITY_FULLY_OBSCURED
;
1205 case VisibilityPartiallyObscured
:
1206 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
1209 case VisibilityUnobscured
:
1210 pizza
->visibility
= GDK_VISIBILITY_UNOBSCURED
;
1214 return GDK_FILTER_REMOVE
;
1218 return GDK_FILTER_CONTINUE
;
1226 #endif /* __cplusplus */