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
;
193 pizza
->configure_serial
= 0;
196 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
198 pizza
->clear_on_draw
= TRUE
;
199 pizza
->use_filter
= FALSE
;
207 pizza
= gtk_type_new (gtk_pizza_get_type ());
209 return GTK_WIDGET (pizza
);
213 gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
217 /* We handle scrolling in the wxScrolledWindow, not here. */
221 gtk_pizza_set_shadow_type (GtkPizza
*pizza
,
222 GtkMyShadowType type
)
224 g_return_if_fail (pizza
!= NULL
);
225 g_return_if_fail (GTK_IS_PIZZA (pizza
));
227 if ((GtkMyShadowType
) pizza
->shadow_type
!= type
)
229 pizza
->shadow_type
= type
;
231 if (GTK_WIDGET_VISIBLE (pizza
))
233 gtk_widget_size_allocate (GTK_WIDGET (pizza
), &(GTK_WIDGET (pizza
)->allocation
));
234 gtk_widget_queue_draw (GTK_WIDGET (pizza
));
240 gtk_pizza_set_clear (GtkPizza
*pizza
,
243 g_return_if_fail (pizza
!= NULL
);
244 g_return_if_fail (GTK_IS_PIZZA (pizza
));
246 pizza
->clear_on_draw
= clear
;
250 gtk_pizza_set_filter (GtkPizza
*pizza
,
253 g_return_if_fail (pizza
!= NULL
);
254 g_return_if_fail (GTK_IS_PIZZA (pizza
));
256 pizza
->use_filter
= use
;
260 gtk_pizza_put (GtkPizza
*pizza
,
267 GtkPizzaChild
*child_info
;
269 g_return_if_fail (pizza
!= NULL
);
270 g_return_if_fail (GTK_IS_PIZZA (pizza
));
271 g_return_if_fail (widget
!= NULL
);
273 child_info
= g_new (GtkPizzaChild
, 1);
275 child_info
->widget
= widget
;
278 child_info
->width
= width
;
279 child_info
->height
= height
;
281 pizza
->children
= g_list_append (pizza
->children
, child_info
);
283 gtk_widget_set_parent (widget
, GTK_WIDGET (pizza
));
285 if (GTK_WIDGET_REALIZED (pizza
))
286 gtk_widget_set_parent_window (widget
, pizza
->bin_window
);
288 if (!IS_ONSCREEN (x
, y
))
289 GTK_PRIVATE_SET_FLAG (widget
, GTK_IS_OFFSCREEN
);
292 if (GTK_WIDGET_REALIZED (pizza))
293 gtk_widget_realize (widget);
296 gtk_widget_set_usize (widget
, width
, height
);
299 if (GTK_WIDGET_VISIBLE (pizza) && GTK_WIDGET_VISIBLE (widget))
301 if (GTK_WIDGET_MAPPED (pizza))
302 gtk_widget_map (widget);
304 gtk_widget_queue_resize (widget);
310 gtk_pizza_move (GtkPizza
*pizza
,
315 GtkPizzaChild
*child
;
318 g_return_if_fail (pizza
!= NULL
);
319 g_return_if_fail (GTK_IS_PIZZA (pizza
));
320 g_return_if_fail (widget
!= NULL
);
322 children
= pizza
->children
;
325 child
= children
->data
;
326 children
= children
->next
;
328 if (child
->widget
== widget
)
330 if ((child
->x
== x
) && (child
->y
== y
))
336 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
337 gtk_widget_queue_resize (widget
);
344 gtk_pizza_resize (GtkPizza
*pizza
,
349 GtkPizzaChild
*child
;
352 g_return_if_fail (pizza
!= NULL
);
353 g_return_if_fail (GTK_IS_PIZZA (pizza
));
354 g_return_if_fail (widget
!= NULL
);
356 children
= pizza
->children
;
359 child
= children
->data
;
360 children
= children
->next
;
362 if (child
->widget
== widget
)
364 if ((child
->width
== width
) && (child
->height
== height
))
367 child
->width
= width
;
368 child
->height
= height
;
370 gtk_widget_set_usize (widget
, width
, height
);
372 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
373 gtk_widget_queue_resize (widget
);
380 gtk_pizza_set_size (GtkPizza
*pizza
,
387 GtkPizzaChild
*child
;
390 g_return_if_fail (pizza
!= NULL
);
391 g_return_if_fail (GTK_IS_PIZZA (pizza
));
392 g_return_if_fail (widget
!= NULL
);
394 children
= pizza
->children
;
397 child
= children
->data
;
398 children
= children
->next
;
400 if (child
->widget
== widget
)
402 if ((child
->x
== x
) &&
404 (child
->width
== width
) &&
405 (child
->height
== height
)) return;
409 child
->width
= width
;
410 child
->height
= height
;
412 gtk_widget_set_usize (widget
, width
, height
);
414 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
415 gtk_widget_queue_resize (widget
);
423 gtk_pizza_map (GtkWidget
*widget
)
426 GtkPizzaChild
*child
;
429 g_return_if_fail (widget
!= NULL
);
430 g_return_if_fail (GTK_IS_PIZZA (widget
));
432 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
433 pizza
= GTK_PIZZA (widget
);
435 children
= pizza
->children
;
438 child
= children
->data
;
439 children
= children
->next
;
441 if ( GTK_WIDGET_VISIBLE (child
->widget
) &&
442 !GTK_WIDGET_MAPPED (child
->widget
) &&
443 !GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
445 gtk_widget_map (child
->widget
);
449 gdk_window_show (widget
->window
);
450 gdk_window_show (pizza
->bin_window
);
454 gtk_pizza_realize (GtkWidget
*widget
)
457 GdkWindowAttr attributes
;
458 gint attributes_mask
;
459 GtkPizzaChild
*child
;
462 g_return_if_fail (widget
!= NULL
);
463 g_return_if_fail (GTK_IS_PIZZA (widget
));
465 pizza
= GTK_PIZZA (widget
);
467 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
469 attributes
.window_type
= GDK_WINDOW_CHILD
;
471 attributes
.x
= widget
->allocation
.x
;
472 attributes
.y
= widget
->allocation
.y
;
473 attributes
.width
= widget
->allocation
.width
;
474 attributes
.height
= widget
->allocation
.height
;
476 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
478 /* no border, no changes to sizes */
480 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
482 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
485 attributes
.width
-= 2;
486 attributes
.height
-= 2;
489 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
490 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
493 attributes
.width
-= 4;
494 attributes
.height
-= 4;
498 if (attributes
.width
< 2) attributes
.width
= 2;
499 if (attributes
.height
< 2) attributes
.height
= 2;
501 attributes
.wclass
= GDK_INPUT_OUTPUT
;
502 attributes
.visual
= gtk_widget_get_visual (widget
);
503 attributes
.colormap
= gtk_widget_get_colormap (widget
);
504 attributes
.event_mask
=
505 GDK_VISIBILITY_NOTIFY_MASK
;
506 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
508 widget
->window
= gdk_window_new(gtk_widget_get_parent_window (widget
),
509 &attributes
, attributes_mask
);
510 gdk_window_set_user_data (widget
->window
, widget
);
515 attributes
.event_mask
= gtk_widget_get_events (widget
);
516 attributes
.event_mask
|=
518 GDK_POINTER_MOTION_MASK
|
519 GDK_POINTER_MOTION_HINT_MASK
|
520 GDK_BUTTON_MOTION_MASK
|
521 GDK_BUTTON1_MOTION_MASK
|
522 GDK_BUTTON2_MOTION_MASK
|
523 GDK_BUTTON3_MOTION_MASK
|
524 GDK_BUTTON_PRESS_MASK
|
525 GDK_BUTTON_RELEASE_MASK
|
527 GDK_KEY_RELEASE_MASK
|
528 GDK_ENTER_NOTIFY_MASK
|
529 GDK_LEAVE_NOTIFY_MASK
|
530 GDK_FOCUS_CHANGE_MASK
;
532 pizza
->bin_window
= gdk_window_new(widget
->window
,
533 &attributes
, attributes_mask
);
534 gdk_window_set_user_data (pizza
->bin_window
, widget
);
536 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
537 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
538 gtk_style_set_background (widget
->style
, pizza
->bin_window
, GTK_STATE_NORMAL
);
540 /* add filters for intercepting visibility and expose events */
541 gdk_window_add_filter (widget
->window
, gtk_pizza_main_filter
, pizza
);
542 gdk_window_add_filter (pizza
->bin_window
, gtk_pizza_filter
, pizza
);
544 /* we NEED gravity or we'll give up */
545 gravity_works
= gdk_window_set_static_gravities (pizza
->bin_window
, TRUE
);
547 /* cannot be done before realisation */
548 children
= pizza
->children
;
551 child
= children
->data
;
552 children
= children
->next
;
554 gtk_widget_set_parent_window (child
->widget
, pizza
->bin_window
);
559 gtk_pizza_unrealize (GtkWidget
*widget
)
563 g_return_if_fail (widget
!= NULL
);
564 g_return_if_fail (GTK_IS_PIZZA (widget
));
566 pizza
= GTK_PIZZA (widget
);
568 gdk_window_set_user_data (pizza
->bin_window
, NULL
);
569 gdk_window_destroy (pizza
->bin_window
);
570 pizza
->bin_window
= NULL
;
572 if (GTK_WIDGET_CLASS (parent_class
)->unrealize
)
573 (* GTK_WIDGET_CLASS (parent_class
)->unrealize
) (widget
);
577 gtk_pizza_size_request (GtkWidget
*widget
,
578 GtkRequisition
*requisition
)
581 GtkPizzaChild
*child
;
583 GtkRequisition child_requisition
;
585 g_return_if_fail (widget
!= NULL
);
586 g_return_if_fail (GTK_IS_PIZZA (widget
));
587 g_return_if_fail (requisition
!= NULL
);
589 pizza
= GTK_PIZZA (widget
);
591 children
= pizza
->children
;
594 child
= children
->data
;
595 children
= children
->next
;
597 if (GTK_WIDGET_VISIBLE (child
->widget
))
599 gtk_widget_size_request (child
->widget
, &child_requisition
);
603 /* request very little, I'm not sure if requesting nothing
604 will always have positive effects on stability... */
605 requisition
->width
= 2;
606 requisition
->height
= 2;
610 gtk_pizza_size_allocate (GtkWidget
*widget
,
611 GtkAllocation
*allocation
)
616 GtkPizzaChild
*child
;
619 g_return_if_fail (widget
!= NULL
);
620 g_return_if_fail (GTK_IS_PIZZA(widget
));
621 g_return_if_fail (allocation
!= NULL
);
623 pizza
= GTK_PIZZA (widget
);
625 widget
->allocation
= *allocation
;
627 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
630 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
635 x
= allocation
->x
+ border
;
636 y
= allocation
->y
+ border
;
637 w
= allocation
->width
- border
*2;
638 h
= allocation
->height
- border
*2;
640 if (GTK_WIDGET_REALIZED (widget
))
642 gdk_window_move_resize( widget
->window
, x
, y
, w
, h
);
643 gdk_window_move_resize( pizza
->bin_window
, 0, 0, w
, h
);
646 children
= pizza
->children
;
649 child
= children
->data
;
650 children
= children
->next
;
652 gtk_pizza_position_child (pizza
, child
);
653 gtk_pizza_allocate_child (pizza
, child
);
658 gtk_pizza_draw (GtkWidget
*widget
,
662 GtkPizzaChild
*child
;
663 GdkRectangle child_area
;
666 g_return_if_fail (widget
!= NULL
);
667 g_return_if_fail (GTK_IS_PIZZA (widget
));
669 pizza
= GTK_PIZZA (widget
);
671 children
= pizza
->children
;
672 if ( !(GTK_WIDGET_APP_PAINTABLE (widget
)) &&
673 (pizza
->clear_on_draw
))
675 gdk_window_clear_area( pizza
->bin_window
,
676 area
->x
, area
->y
, area
->width
, area
->height
);
681 child
= children
->data
;
682 children
= children
->next
;
684 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
685 gtk_widget_draw (child
->widget
, &child_area
);
690 gtk_pizza_expose (GtkWidget
*widget
,
691 GdkEventExpose
*event
)
694 GtkPizzaChild
*child
;
695 GdkEventExpose child_event
;
698 g_return_val_if_fail (widget
!= NULL
, FALSE
);
699 g_return_val_if_fail (GTK_IS_PIZZA (widget
), FALSE
);
700 g_return_val_if_fail (event
!= NULL
, FALSE
);
702 pizza
= GTK_PIZZA (widget
);
704 if (event
->window
!= pizza
->bin_window
)
707 children
= pizza
->children
;
710 child
= children
->data
;
711 children
= children
->next
;
713 child_event
= *event
;
715 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
716 GTK_WIDGET_DRAWABLE (child
->widget
) &&
717 gtk_widget_intersect (child
->widget
, &event
->area
, &child_event
.area
))
719 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
727 gtk_pizza_add (GtkContainer
*container
,
730 g_return_if_fail (container
!= NULL
);
731 g_return_if_fail (GTK_IS_PIZZA (container
));
732 g_return_if_fail (widget
!= NULL
);
734 gtk_pizza_put (GTK_PIZZA (container
), widget
, 0, 0, 20, 20 );
738 gtk_pizza_remove (GtkContainer
*container
,
742 GtkPizzaChild
*child
;
745 g_return_if_fail (container
!= NULL
);
746 g_return_if_fail (GTK_IS_PIZZA (container
));
747 g_return_if_fail (widget
!= NULL
);
749 pizza
= GTK_PIZZA (container
);
751 children
= pizza
->children
;
754 child
= children
->data
;
756 if (child
->widget
== widget
)
758 gtk_widget_unparent (widget
);
760 /* security checks */
761 g_return_if_fail (GTK_IS_WIDGET (widget
));
763 pizza
->children
= g_list_remove_link (pizza
->children
, children
);
764 g_list_free (children
);
767 /* security checks */
768 g_return_if_fail (GTK_IS_WIDGET (widget
));
770 GTK_PRIVATE_UNSET_FLAG (widget
, GTK_IS_OFFSCREEN
);
775 children
= children
->next
;
780 gtk_pizza_forall (GtkContainer
*container
,
781 gboolean include_internals
,
782 GtkCallback callback
,
783 gpointer callback_data
)
786 GtkPizzaChild
*child
;
789 g_return_if_fail (container
!= NULL
);
790 g_return_if_fail (GTK_IS_PIZZA (container
));
791 g_return_if_fail (callback
!= NULL
);
793 pizza
= GTK_PIZZA (container
);
795 children
= pizza
->children
;
798 child
= children
->data
;
799 children
= children
->next
;
801 (* callback
) (child
->widget
, callback_data
);
806 /* Operations on children
810 gtk_pizza_position_child (GtkPizza
*pizza
,
811 GtkPizzaChild
*child
)
816 x
= child
->x
- pizza
->xoffset
;
817 y
= child
->y
- pizza
->yoffset
;
819 if (IS_ONSCREEN (x
,y
))
821 if (GTK_WIDGET_MAPPED (pizza
) &&
822 GTK_WIDGET_VISIBLE (child
->widget
))
824 if (!GTK_WIDGET_MAPPED (child
->widget
))
825 gtk_widget_map (child
->widget
);
828 if (GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
829 GTK_PRIVATE_UNSET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
833 if (!GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
834 GTK_PRIVATE_SET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
836 if (GTK_WIDGET_MAPPED (child
->widget
))
837 gtk_widget_unmap (child
->widget
);
842 gtk_pizza_allocate_child (GtkPizza
*pizza
,
843 GtkPizzaChild
*child
)
845 GtkAllocation allocation
;
846 GtkRequisition requisition
;
848 allocation
.x
= child
->x
- pizza
->xoffset
;
849 allocation
.y
= child
->y
- pizza
->yoffset
;
850 gtk_widget_get_child_requisition (child
->widget
, &requisition
);
851 allocation
.width
= requisition
.width
;
852 allocation
.height
= requisition
.height
;
854 gtk_widget_size_allocate (child
->widget
, &allocation
);
858 gtk_pizza_position_children (GtkPizza
*pizza
)
862 tmp_list
= pizza
->children
;
865 GtkPizzaChild
*child
= tmp_list
->data
;
866 tmp_list
= tmp_list
->next
;
868 gtk_pizza_position_child (pizza
, child
);
873 gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
876 GtkPizzaAdjData
*data
= cb_data
;
878 widget
->allocation
.x
+= data
->dx
;
879 widget
->allocation
.y
+= data
->dy
;
881 if (GTK_WIDGET_NO_WINDOW (widget
) && GTK_IS_CONTAINER (widget
))
883 gtk_container_forall (GTK_CONTAINER (widget
),
884 gtk_pizza_adjust_allocations_recurse
,
890 gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
895 GtkPizzaAdjData data
;
900 tmp_list
= pizza
->children
;
903 GtkPizzaChild
*child
= tmp_list
->data
;
904 tmp_list
= tmp_list
->next
;
906 child
->widget
->allocation
.x
+= dx
;
907 child
->widget
->allocation
.y
+= dy
;
909 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
910 GTK_IS_CONTAINER (child
->widget
))
912 gtk_container_forall (GTK_CONTAINER (child
->widget
),
913 gtk_pizza_adjust_allocations_recurse
,
921 /* Send a synthetic expose event to the widget
924 gtk_pizza_expose_area (GtkPizza
*pizza
,
925 gint x
, gint y
, gint width
, gint height
)
927 if (pizza
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
929 GdkEventExpose event
;
931 event
.type
= GDK_EXPOSE
;
932 event
.send_event
= TRUE
;
933 event
.window
= pizza
->bin_window
;
938 event
.area
.width
= width
;
939 event
.area
.height
= height
;
941 gdk_window_ref (event
.window
);
942 gtk_widget_event (GTK_WIDGET (pizza
), (GdkEvent
*)&event
);
943 gdk_window_unref (event
.window
);
947 /* This function is used to find events to process while scrolling
951 gtk_pizza_expose_predicate (Display
*display
,
955 if ((xevent
->type
== Expose
) ||
956 ((xevent
->xany
.window
== *(Window
*)arg
) &&
957 (xevent
->type
== ConfigureNotify
)))
963 /* This is the main routine to do the scrolling. Scrolling is
964 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
965 * a few modifications.
967 * The main improvement is that we keep track of whether we
968 * are obscured or not. If not, we ignore the generated expose
969 * events and instead do the exposes ourself, without having
970 * to wait for a roundtrip to the server. This also provides
971 * a limited form of expose-event compression, since we do
972 * the affected area as one big chunk.
976 gtk_pizza_scroll (GtkPizza
*pizza
, gint dx
, gint dy
)
983 widget
= GTK_WIDGET (pizza
);
985 pizza
->xoffset
+= dx
;
986 pizza
->yoffset
+= dy
;
988 if (!GTK_WIDGET_MAPPED (pizza
))
990 gtk_pizza_position_children (pizza
);
994 gtk_pizza_adjust_allocations (pizza
, -dx
, -dy
);
996 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
999 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
1006 w
= widget
->allocation
.width
- 2*border
;
1007 h
= widget
->allocation
.height
- 2*border
;
1013 gdk_window_resize (pizza
->bin_window
,
1016 gdk_window_move (pizza
->bin_window
, x
-dx
, y
);
1017 gdk_window_move_resize (pizza
->bin_window
, x
, y
, w
, h
);
1024 gtk_pizza_expose_area (pizza
,
1025 MAX ((gint
)w
- dx
, 0),
1034 gdk_window_move_resize (pizza
->bin_window
,
1039 gdk_window_move (pizza
->bin_window
, x
, y
);
1040 gdk_window_resize (pizza
->bin_window
, w
, h
);
1047 gtk_pizza_expose_area (pizza
,
1058 gdk_window_resize (pizza
->bin_window
, w
, h
+ dy
);
1059 gdk_window_move (pizza
->bin_window
, x
, y
-dy
);
1060 gdk_window_move_resize (pizza
->bin_window
,
1068 gtk_pizza_expose_area (pizza
,
1070 MAX ((gint
)h
- dy
, 0),
1078 gdk_window_move_resize (pizza
->bin_window
,
1079 x
, y
+dy
, w
, h
- dy
);
1080 gdk_window_move (pizza
->bin_window
, x
, y
);
1081 gdk_window_resize (pizza
->bin_window
, w
, h
);
1087 gtk_pizza_expose_area (pizza
,
1091 MIN (-dy
, (gint
)h
));
1094 gtk_pizza_position_children (pizza
);
1096 /* We have to make sure that all exposes from this scroll get
1097 * processed before we scroll again, or the expose events will
1098 * have invalid coordinates.
1100 * We also do expose events for other windows, since otherwise
1101 * their updating will fall behind the scrolling
1103 * This also avoids a problem in pre-1.0 GTK where filters don't
1104 * have access to configure events that were compressed.
1108 while (XCheckIfEvent(GDK_WINDOW_XDISPLAY (pizza
->bin_window
),
1110 gtk_pizza_expose_predicate
,
1111 (XPointer
)&GDK_WINDOW_XWINDOW (pizza
->bin_window
)))
1114 GtkWidget
*event_widget
;
1116 if ((xevent
.xany
.window
== GDK_WINDOW_XWINDOW (pizza
->bin_window
)) &&
1117 (gtk_pizza_filter (&xevent
, &event
, pizza
) == GDK_FILTER_REMOVE
))
1120 if (xevent
.type
== Expose
)
1122 event
.expose
.window
= gdk_window_lookup (xevent
.xany
.window
);
1123 gdk_window_get_user_data (event
.expose
.window
,
1124 (gpointer
*)&event_widget
);
1128 event
.expose
.type
= GDK_EXPOSE
;
1129 event
.expose
.area
.x
= xevent
.xexpose
.x
;
1130 event
.expose
.area
.y
= xevent
.xexpose
.y
;
1131 event
.expose
.area
.width
= xevent
.xexpose
.width
;
1132 event
.expose
.area
.height
= xevent
.xexpose
.height
;
1133 event
.expose
.count
= xevent
.xexpose
.count
;
1135 gdk_window_ref (event
.expose
.window
);
1136 gtk_widget_event (event_widget
, &event
);
1137 gdk_window_unref (event
.expose
.window
);
1143 /* The main event filter. Actually, we probably don't really need
1144 * to install this as a filter at all, since we are calling it
1145 * directly above in the expose-handling hack. But in case scrollbars
1146 * are fixed up in some manner...
1148 * This routine identifies expose events that are generated when
1149 * we've temporarily moved the bin_window_origin, and translates
1150 * them or discards them, depending on whether we are obscured
1153 static GdkFilterReturn
1154 gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
1161 xevent
= (XEvent
*)gdk_xevent
;
1163 pizza
= GTK_PIZZA (data
);
1165 switch (xevent
->type
)
1168 if (xevent
->xexpose
.serial
== pizza
->configure_serial
)
1170 if (pizza
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
1171 return GDK_FILTER_REMOVE
;
1174 xevent
->xexpose
.x
+= pizza
->scroll_x
;
1175 xevent
->xexpose
.y
+= pizza
->scroll_y
;
1182 case ConfigureNotify
:
1183 if ((xevent
->xconfigure
.x
!= 0) || (xevent
->xconfigure
.y
!= 0))
1185 pizza
->configure_serial
= xevent
->xconfigure
.serial
;
1186 pizza
->scroll_x
= xevent
->xconfigure
.x
;
1187 pizza
->scroll_y
= xevent
->xconfigure
.y
;
1192 return GDK_FILTER_CONTINUE
;
1195 /* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
1196 * there is no corresponding event in GTK, so we have
1197 * to get the events from a filter
1199 static GdkFilterReturn
1200 gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
1207 xevent
= (XEvent
*)gdk_xevent
;
1208 pizza
= GTK_PIZZA (data
);
1210 if (xevent
->type
== VisibilityNotify
)
1212 switch (xevent
->xvisibility
.state
)
1214 case VisibilityFullyObscured
:
1215 pizza
->visibility
= GDK_VISIBILITY_FULLY_OBSCURED
;
1218 case VisibilityPartiallyObscured
:
1219 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
1222 case VisibilityUnobscured
:
1223 pizza
->visibility
= GDK_VISIBILITY_UNOBSCURED
;
1227 return GDK_FILTER_REMOVE
;
1230 return GDK_FILTER_CONTINUE
;
1238 #endif /* __cplusplus */