1 /* ///////////////////////////////////////////////////////////////////////////
3 // Purpose: Native GTK+ widget for wxWindows, based on GtkLayout and
4 // GtkFixed. It makes use of the gravity window property and
5 // therefore does not work with GTK 1.0.
6 // Author: Robert Roebling
8 // Copyright: (c) 1998 Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////// */
12 #include "wx/gtk/win_gtk.h"
14 #define gtk_widget_get_child_requisition gtk_widget_get_child_requisitio
15 #define gtk_marshal_NONE__POINTER_POINTER gtk_marshal_NONE__POINTER_POINT
17 #include "gtk/gtksignal.h"
18 #include "gtk/gtkprivate.h"
23 #endif /* __cplusplus */
26 #include <X11/Xutil.h>
27 #include <X11/Xatom.h>
29 #define IS_ONSCREEN(x,y) ((x >= G_MINSHORT) && (x <= G_MAXSHORT) && \
30 (y >= G_MINSHORT) && (y <= G_MAXSHORT))
32 typedef struct _GtkPizzaAdjData GtkPizzaAdjData
;
34 struct _GtkPizzaAdjData
40 static void gtk_pizza_class_init (GtkPizzaClass
*klass
);
41 static void gtk_pizza_init (GtkPizza
*pizza
);
43 static void gtk_pizza_realize (GtkWidget
*widget
);
44 static void gtk_pizza_unrealize (GtkWidget
*widget
);
46 static void gtk_pizza_map (GtkWidget
*widget
);
48 static void gtk_pizza_size_request (GtkWidget
*widget
,
49 GtkRequisition
*requisition
);
50 static void gtk_pizza_size_allocate (GtkWidget
*widget
,
51 GtkAllocation
*allocation
);
52 static void gtk_pizza_draw (GtkWidget
*widget
,
54 static gint
gtk_pizza_expose (GtkWidget
*widget
,
55 GdkEventExpose
*event
);
56 static void gtk_pizza_add (GtkContainer
*container
,
58 static void gtk_pizza_remove (GtkContainer
*container
,
60 static void gtk_pizza_forall (GtkContainer
*container
,
61 gboolean include_internals
,
63 gpointer callback_data
);
65 static void gtk_pizza_position_child (GtkPizza
*pizza
,
66 GtkPizzaChild
*child
);
67 static void gtk_pizza_allocate_child (GtkPizza
*pizza
,
68 GtkPizzaChild
*child
);
69 static void gtk_pizza_position_children (GtkPizza
*pizza
);
71 static void gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
73 static void gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
78 static void gtk_pizza_expose_area (GtkPizza
*pizza
,
83 static void gtk_pizza_adjustment_changed (GtkAdjustment
*adjustment
,
85 static GdkFilterReturn
gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
88 static GdkFilterReturn
gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
93 static GtkType
gtk_pizza_child_type (GtkContainer
*container
);
95 static void gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
100 static GtkContainerClass
*parent_class
= NULL
;
101 static gboolean gravity_works
;
104 gtk_pizza_get_type ()
106 static guint pizza_type
= 0;
110 GtkTypeInfo pizza_info
=
114 sizeof (GtkPizzaClass
),
115 (GtkClassInitFunc
) gtk_pizza_class_init
,
116 (GtkObjectInitFunc
) gtk_pizza_init
,
117 /* reserved_1 */ NULL
,
118 /* reserved_2 */ NULL
,
119 (GtkClassInitFunc
) NULL
,
121 pizza_type
= gtk_type_unique (gtk_container_get_type (), &pizza_info
);
128 gtk_pizza_class_init (GtkPizzaClass
*klass
)
130 GtkObjectClass
*object_class
;
131 GtkWidgetClass
*widget_class
;
132 GtkContainerClass
*container_class
;
134 object_class
= (GtkObjectClass
*) klass
;
135 widget_class
= (GtkWidgetClass
*) klass
;
136 container_class
= (GtkContainerClass
*) klass
;
137 parent_class
= gtk_type_class (GTK_TYPE_CONTAINER
);
139 widget_class
->map
= gtk_pizza_map
;
140 widget_class
->realize
= gtk_pizza_realize
;
141 widget_class
->unrealize
= gtk_pizza_unrealize
;
142 widget_class
->size_request
= gtk_pizza_size_request
;
143 widget_class
->size_allocate
= gtk_pizza_size_allocate
;
144 widget_class
->draw
= gtk_pizza_draw
;
145 widget_class
->expose_event
= gtk_pizza_expose
;
147 container_class
->add
= gtk_pizza_add
;
148 container_class
->remove
= gtk_pizza_remove
;
149 container_class
->forall
= gtk_pizza_forall
;
151 container_class
->child_type
= gtk_pizza_child_type
;
153 klass
->set_scroll_adjustments
= gtk_pizza_scroll_set_adjustments
;
155 widget_class
->set_scroll_adjustments_signal
=
156 gtk_signal_new ("set_scroll_adjustments",
159 GTK_SIGNAL_OFFSET (GtkPizzaClass
, set_scroll_adjustments
),
160 gtk_marshal_NONE__POINTER_POINTER
,
161 GTK_TYPE_NONE
, 2, GTK_TYPE_ADJUSTMENT
, GTK_TYPE_ADJUSTMENT
);
165 gtk_pizza_child_type (GtkContainer
*container
)
167 return GTK_TYPE_WIDGET
;
171 gtk_pizza_init (GtkPizza
*pizza
)
173 GTK_WIDGET_UNSET_FLAGS (pizza
, GTK_NO_WINDOW
);
175 pizza
->shadow_type
= GTK_MYSHADOW_NONE
;
177 pizza
->children
= NULL
;
182 pizza
->bin_window
= NULL
;
187 pizza
->configure_serial
= 0;
190 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
192 pizza
->clear_on_draw
= TRUE
;
193 pizza
->use_filter
= TRUE
;
201 pizza
= gtk_type_new (gtk_pizza_get_type ());
203 return GTK_WIDGET (pizza
);
207 gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
211 /* We handle scrolling in the wxScrolledWindow, not here. */
215 gtk_pizza_set_shadow_type (GtkPizza
*pizza
,
216 GtkMyShadowType type
)
218 g_return_if_fail (pizza
!= NULL
);
219 g_return_if_fail (GTK_IS_PIZZA (pizza
));
221 if ((GtkMyShadowType
) pizza
->shadow_type
!= type
)
223 pizza
->shadow_type
= type
;
225 if (GTK_WIDGET_VISIBLE (pizza
))
227 gtk_widget_size_allocate (GTK_WIDGET (pizza
), &(GTK_WIDGET (pizza
)->allocation
));
228 gtk_widget_queue_draw (GTK_WIDGET (pizza
));
234 gtk_pizza_set_clear (GtkPizza
*pizza
,
237 g_return_if_fail (pizza
!= NULL
);
238 g_return_if_fail (GTK_IS_PIZZA (pizza
));
240 pizza
->clear_on_draw
= clear
;
244 gtk_pizza_set_filter (GtkPizza
*pizza
,
247 g_return_if_fail (pizza
!= NULL
);
248 g_return_if_fail (GTK_IS_PIZZA (pizza
));
250 pizza
->use_filter
= use
;
254 gtk_pizza_put (GtkPizza
*pizza
,
261 GtkPizzaChild
*child_info
;
263 g_return_if_fail (pizza
!= NULL
);
264 g_return_if_fail (GTK_IS_PIZZA (pizza
));
265 g_return_if_fail (widget
!= NULL
);
267 child_info
= g_new (GtkPizzaChild
, 1);
269 child_info
->widget
= widget
;
272 child_info
->width
= width
;
273 child_info
->height
= height
;
275 pizza
->children
= g_list_append (pizza
->children
, child_info
);
277 gtk_widget_set_parent (widget
, GTK_WIDGET (pizza
));
279 if (GTK_WIDGET_REALIZED (pizza
))
280 gtk_widget_set_parent_window (widget
, pizza
->bin_window
);
282 if (!IS_ONSCREEN (x
, y
))
283 GTK_PRIVATE_SET_FLAG (widget
, GTK_IS_OFFSCREEN
);
286 if (GTK_WIDGET_REALIZED (pizza))
287 gtk_widget_realize (widget);
290 gtk_widget_set_usize (widget
, width
, height
);
293 if (GTK_WIDGET_VISIBLE (pizza) && GTK_WIDGET_VISIBLE (widget))
295 if (GTK_WIDGET_MAPPED (pizza))
296 gtk_widget_map (widget);
298 gtk_widget_queue_resize (widget);
304 gtk_pizza_move (GtkPizza
*pizza
,
309 GtkPizzaChild
*child
;
312 g_return_if_fail (pizza
!= NULL
);
313 g_return_if_fail (GTK_IS_PIZZA (pizza
));
314 g_return_if_fail (widget
!= NULL
);
316 children
= pizza
->children
;
319 child
= children
->data
;
320 children
= children
->next
;
322 if (child
->widget
== widget
)
324 if ((child
->x
== x
) && (child
->y
== y
))
330 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
331 gtk_widget_queue_resize (widget
);
338 gtk_pizza_resize (GtkPizza
*pizza
,
343 GtkPizzaChild
*child
;
346 g_return_if_fail (pizza
!= NULL
);
347 g_return_if_fail (GTK_IS_PIZZA (pizza
));
348 g_return_if_fail (widget
!= NULL
);
350 children
= pizza
->children
;
353 child
= children
->data
;
354 children
= children
->next
;
356 if (child
->widget
== widget
)
358 if ((child
->width
== width
) && (child
->height
== height
))
361 child
->width
= width
;
362 child
->height
= height
;
364 gtk_widget_set_usize (widget
, width
, height
);
366 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
367 gtk_widget_queue_resize (widget
);
374 gtk_pizza_set_size (GtkPizza
*pizza
,
381 GtkPizzaChild
*child
;
384 g_return_if_fail (pizza
!= NULL
);
385 g_return_if_fail (GTK_IS_PIZZA (pizza
));
386 g_return_if_fail (widget
!= NULL
);
388 children
= pizza
->children
;
391 child
= children
->data
;
392 children
= children
->next
;
394 if (child
->widget
== widget
)
396 if ((child
->x
== x
) &&
398 (child
->width
== width
) &&
399 (child
->height
== height
)) return;
403 child
->width
= width
;
404 child
->height
= height
;
406 gtk_widget_set_usize (widget
, width
, height
);
408 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
409 gtk_widget_queue_resize (widget
);
417 gtk_pizza_map (GtkWidget
*widget
)
420 GtkPizzaChild
*child
;
423 g_return_if_fail (widget
!= NULL
);
424 g_return_if_fail (GTK_IS_PIZZA (widget
));
426 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
427 pizza
= GTK_PIZZA (widget
);
429 children
= pizza
->children
;
432 child
= children
->data
;
433 children
= children
->next
;
435 if ( GTK_WIDGET_VISIBLE (child
->widget
) &&
436 !GTK_WIDGET_MAPPED (child
->widget
) &&
437 !GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
439 gtk_widget_map (child
->widget
);
443 gdk_window_show (widget
->window
);
444 gdk_window_show (pizza
->bin_window
);
448 gtk_pizza_realize (GtkWidget
*widget
)
451 GdkWindowAttr attributes
;
452 gint attributes_mask
;
453 GtkPizzaChild
*child
;
456 g_return_if_fail (widget
!= NULL
);
457 g_return_if_fail (GTK_IS_PIZZA (widget
));
459 pizza
= GTK_PIZZA (widget
);
461 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
463 attributes
.window_type
= GDK_WINDOW_CHILD
;
465 attributes
.x
= widget
->allocation
.x
;
466 attributes
.y
= widget
->allocation
.y
;
467 attributes
.width
= widget
->allocation
.width
;
468 attributes
.height
= widget
->allocation
.height
;
470 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
472 /* no border, no changes to sizes */
474 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
476 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
479 attributes
.width
-= 2;
480 attributes
.height
-= 2;
483 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
484 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
487 attributes
.width
-= 4;
488 attributes
.height
-= 4;
492 if (attributes
.width
< 2) attributes
.width
= 2;
493 if (attributes
.height
< 2) attributes
.height
= 2;
495 attributes
.wclass
= GDK_INPUT_OUTPUT
;
496 attributes
.visual
= gtk_widget_get_visual (widget
);
497 attributes
.colormap
= gtk_widget_get_colormap (widget
);
498 attributes
.event_mask
=
499 GDK_VISIBILITY_NOTIFY_MASK
;
500 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
502 widget
->window
= gdk_window_new(gtk_widget_get_parent_window (widget
),
503 &attributes
, attributes_mask
);
504 gdk_window_set_user_data (widget
->window
, widget
);
509 attributes
.event_mask
= gtk_widget_get_events (widget
);
510 attributes
.event_mask
|=
512 GDK_POINTER_MOTION_MASK
|
513 GDK_POINTER_MOTION_HINT_MASK
|
514 GDK_BUTTON_MOTION_MASK
|
515 GDK_BUTTON1_MOTION_MASK
|
516 GDK_BUTTON2_MOTION_MASK
|
517 GDK_BUTTON3_MOTION_MASK
|
518 GDK_BUTTON_PRESS_MASK
|
519 GDK_BUTTON_RELEASE_MASK
|
521 GDK_KEY_RELEASE_MASK
|
522 GDK_ENTER_NOTIFY_MASK
|
523 GDK_LEAVE_NOTIFY_MASK
|
524 GDK_FOCUS_CHANGE_MASK
;
526 pizza
->bin_window
= gdk_window_new(widget
->window
,
527 &attributes
, attributes_mask
);
528 gdk_window_set_user_data (pizza
->bin_window
, widget
);
530 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
531 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
532 gtk_style_set_background (widget
->style
, pizza
->bin_window
, GTK_STATE_NORMAL
);
534 /* add filters for intercepting visibility and expose events */
535 gdk_window_add_filter (widget
->window
, gtk_pizza_main_filter
, pizza
);
536 gdk_window_add_filter (pizza
->bin_window
, gtk_pizza_filter
, pizza
);
538 /* we NEED gravity or we'll give up */
539 gravity_works
= gdk_window_set_static_gravities (pizza
->bin_window
, TRUE
);
541 /* cannot be done before realisation */
542 children
= pizza
->children
;
545 child
= children
->data
;
546 children
= children
->next
;
548 gtk_widget_set_parent_window (child
->widget
, pizza
->bin_window
);
553 gtk_pizza_unrealize (GtkWidget
*widget
)
557 g_return_if_fail (widget
!= NULL
);
558 g_return_if_fail (GTK_IS_PIZZA (widget
));
560 pizza
= GTK_PIZZA (widget
);
562 gdk_window_set_user_data (pizza
->bin_window
, NULL
);
563 gdk_window_destroy (pizza
->bin_window
);
564 pizza
->bin_window
= NULL
;
566 if (GTK_WIDGET_CLASS (parent_class
)->unrealize
)
567 (* GTK_WIDGET_CLASS (parent_class
)->unrealize
) (widget
);
571 gtk_pizza_size_request (GtkWidget
*widget
,
572 GtkRequisition
*requisition
)
575 GtkPizzaChild
*child
;
577 GtkRequisition child_requisition
;
579 g_return_if_fail (widget
!= NULL
);
580 g_return_if_fail (GTK_IS_PIZZA (widget
));
581 g_return_if_fail (requisition
!= NULL
);
583 pizza
= GTK_PIZZA (widget
);
585 children
= pizza
->children
;
588 child
= children
->data
;
589 children
= children
->next
;
591 if (GTK_WIDGET_VISIBLE (child
->widget
))
593 gtk_widget_size_request (child
->widget
, &child_requisition
);
597 /* request very little, I'm not sure if requesting nothing
598 will always have positive effects on stability... */
599 requisition
->width
= 2;
600 requisition
->height
= 2;
604 gtk_pizza_size_allocate (GtkWidget
*widget
,
605 GtkAllocation
*allocation
)
610 GtkPizzaChild
*child
;
613 g_return_if_fail (widget
!= NULL
);
614 g_return_if_fail (GTK_IS_PIZZA(widget
));
615 g_return_if_fail (allocation
!= NULL
);
617 pizza
= GTK_PIZZA (widget
);
619 widget
->allocation
= *allocation
;
621 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
624 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
629 x
= allocation
->x
+ border
;
630 y
= allocation
->y
+ border
;
631 w
= allocation
->width
- border
*2;
632 h
= allocation
->height
- border
*2;
634 if (GTK_WIDGET_REALIZED (widget
))
636 gdk_window_move_resize( widget
->window
, x
, y
, w
, h
);
637 gdk_window_move_resize( pizza
->bin_window
, 0, 0, w
, h
);
640 children
= pizza
->children
;
643 child
= children
->data
;
644 children
= children
->next
;
646 gtk_pizza_position_child (pizza
, child
);
647 gtk_pizza_allocate_child (pizza
, child
);
652 gtk_pizza_draw (GtkWidget
*widget
,
655 /* We handle all draws events in window.cpp now. */
660 gtk_pizza_expose (GtkWidget
*widget
,
661 GdkEventExpose
*event
)
663 /* We handle all expose events in window.cpp now. */
668 gtk_pizza_add (GtkContainer
*container
,
671 g_return_if_fail (container
!= NULL
);
672 g_return_if_fail (GTK_IS_PIZZA (container
));
673 g_return_if_fail (widget
!= NULL
);
675 gtk_pizza_put (GTK_PIZZA (container
), widget
, 0, 0, 20, 20 );
679 gtk_pizza_remove (GtkContainer
*container
,
683 GtkPizzaChild
*child
;
686 g_return_if_fail (container
!= NULL
);
687 g_return_if_fail (GTK_IS_PIZZA (container
));
688 g_return_if_fail (widget
!= NULL
);
690 pizza
= GTK_PIZZA (container
);
692 children
= pizza
->children
;
695 child
= children
->data
;
697 if (child
->widget
== widget
)
699 gtk_widget_unparent (widget
);
701 /* security checks */
702 g_return_if_fail (GTK_IS_WIDGET (widget
));
704 pizza
->children
= g_list_remove_link (pizza
->children
, children
);
705 g_list_free (children
);
708 /* security checks */
709 g_return_if_fail (GTK_IS_WIDGET (widget
));
711 GTK_PRIVATE_UNSET_FLAG (widget
, GTK_IS_OFFSCREEN
);
716 children
= children
->next
;
721 gtk_pizza_forall (GtkContainer
*container
,
722 gboolean include_internals
,
723 GtkCallback callback
,
724 gpointer callback_data
)
727 GtkPizzaChild
*child
;
730 g_return_if_fail (container
!= NULL
);
731 g_return_if_fail (GTK_IS_PIZZA (container
));
732 g_return_if_fail (callback
!= NULL
);
734 pizza
= GTK_PIZZA (container
);
736 children
= pizza
->children
;
739 child
= children
->data
;
740 children
= children
->next
;
742 (* callback
) (child
->widget
, callback_data
);
747 /* Operations on children
751 gtk_pizza_position_child (GtkPizza
*pizza
,
752 GtkPizzaChild
*child
)
757 x
= child
->x
- pizza
->xoffset
;
758 y
= child
->y
- pizza
->yoffset
;
760 if (IS_ONSCREEN (x
,y
))
762 if (GTK_WIDGET_MAPPED (pizza
) &&
763 GTK_WIDGET_VISIBLE (child
->widget
))
765 if (!GTK_WIDGET_MAPPED (child
->widget
))
766 gtk_widget_map (child
->widget
);
769 if (GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
770 GTK_PRIVATE_UNSET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
774 if (!GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
775 GTK_PRIVATE_SET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
777 if (GTK_WIDGET_MAPPED (child
->widget
))
778 gtk_widget_unmap (child
->widget
);
783 gtk_pizza_allocate_child (GtkPizza
*pizza
,
784 GtkPizzaChild
*child
)
786 GtkAllocation allocation
;
787 GtkRequisition requisition
;
789 allocation
.x
= child
->x
- pizza
->xoffset
;
790 allocation
.y
= child
->y
- pizza
->yoffset
;
791 gtk_widget_get_child_requisition (child
->widget
, &requisition
);
792 allocation
.width
= requisition
.width
;
793 allocation
.height
= requisition
.height
;
795 gtk_widget_size_allocate (child
->widget
, &allocation
);
799 gtk_pizza_position_children (GtkPizza
*pizza
)
803 tmp_list
= pizza
->children
;
806 GtkPizzaChild
*child
= tmp_list
->data
;
807 tmp_list
= tmp_list
->next
;
809 gtk_pizza_position_child (pizza
, child
);
814 gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
817 GtkPizzaAdjData
*data
= cb_data
;
819 widget
->allocation
.x
+= data
->dx
;
820 widget
->allocation
.y
+= data
->dy
;
822 if (GTK_WIDGET_NO_WINDOW (widget
) && GTK_IS_CONTAINER (widget
))
824 gtk_container_forall (GTK_CONTAINER (widget
),
825 gtk_pizza_adjust_allocations_recurse
,
831 gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
836 GtkPizzaAdjData data
;
841 tmp_list
= pizza
->children
;
844 GtkPizzaChild
*child
= tmp_list
->data
;
845 tmp_list
= tmp_list
->next
;
847 child
->widget
->allocation
.x
+= dx
;
848 child
->widget
->allocation
.y
+= dy
;
850 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
851 GTK_IS_CONTAINER (child
->widget
))
853 gtk_container_forall (GTK_CONTAINER (child
->widget
),
854 gtk_pizza_adjust_allocations_recurse
,
862 /* Send a synthetic expose event to the widget
865 gtk_pizza_expose_area (GtkPizza
*pizza
,
866 gint x
, gint y
, gint width
, gint height
)
868 if (pizza
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
870 GdkEventExpose event
;
872 event
.type
= GDK_EXPOSE
;
873 event
.send_event
= TRUE
;
874 event
.window
= pizza
->bin_window
;
879 event
.area
.width
= width
;
880 event
.area
.height
= height
;
882 gdk_window_ref (event
.window
);
883 gtk_widget_event (GTK_WIDGET (pizza
), (GdkEvent
*)&event
);
884 gdk_window_unref (event
.window
);
888 /* This function is used to find events to process while scrolling
892 gtk_pizza_expose_predicate (Display
*display
,
896 if ((xevent
->type
== Expose
) ||
897 ((xevent
->xany
.window
== *(Window
*)arg
) &&
898 (xevent
->type
== ConfigureNotify
)))
904 /* This is the main routine to do the scrolling. Scrolling is
905 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
906 * a few modifications.
908 * The main improvement is that we keep track of whether we
909 * are obscured or not. If not, we ignore the generated expose
910 * events and instead do the exposes ourself, without having
911 * to wait for a roundtrip to the server. This also provides
912 * a limited form of expose-event compression, since we do
913 * the affected area as one big chunk.
917 gtk_pizza_scroll (GtkPizza
*pizza
, gint dx
, gint dy
)
924 widget
= GTK_WIDGET (pizza
);
926 pizza
->xoffset
+= dx
;
927 pizza
->yoffset
+= dy
;
929 if (!GTK_WIDGET_MAPPED (pizza
))
931 gtk_pizza_position_children (pizza
);
935 gtk_pizza_adjust_allocations (pizza
, -dx
, -dy
);
937 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
940 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
947 w
= widget
->allocation
.width
- 2*border
;
948 h
= widget
->allocation
.height
- 2*border
;
954 gdk_window_resize (pizza
->bin_window
,
957 gdk_window_move (pizza
->bin_window
, x
-dx
, y
);
958 gdk_window_move_resize (pizza
->bin_window
, x
, y
, w
, h
);
965 gtk_pizza_expose_area (pizza
,
966 MAX ((gint
)w
- dx
, 0),
975 gdk_window_move_resize (pizza
->bin_window
,
980 gdk_window_move (pizza
->bin_window
, x
, y
);
981 gdk_window_resize (pizza
->bin_window
, w
, h
);
988 gtk_pizza_expose_area (pizza
,
999 gdk_window_resize (pizza
->bin_window
, w
, h
+ dy
);
1000 gdk_window_move (pizza
->bin_window
, x
, y
-dy
);
1001 gdk_window_move_resize (pizza
->bin_window
,
1009 gtk_pizza_expose_area (pizza
,
1011 MAX ((gint
)h
- dy
, 0),
1019 gdk_window_move_resize (pizza
->bin_window
,
1020 x
, y
+dy
, w
, h
- dy
);
1021 gdk_window_move (pizza
->bin_window
, x
, y
);
1022 gdk_window_resize (pizza
->bin_window
, w
, h
);
1028 gtk_pizza_expose_area (pizza
,
1032 MIN (-dy
, (gint
)h
));
1035 gtk_pizza_position_children (pizza
);
1037 /* We have to make sure that all exposes from this scroll get
1038 * processed before we scroll again, or the expose events will
1039 * have invalid coordinates.
1041 * We also do expose events for other windows, since otherwise
1042 * their updating will fall behind the scrolling
1044 * This also avoids a problem in pre-1.0 GTK where filters don't
1045 * have access to configure events that were compressed.
1049 while (XCheckIfEvent(GDK_WINDOW_XDISPLAY (pizza
->bin_window
),
1051 gtk_pizza_expose_predicate
,
1052 (XPointer
)&GDK_WINDOW_XWINDOW (pizza
->bin_window
)))
1055 GtkWidget
*event_widget
;
1057 if ((xevent
.xany
.window
== GDK_WINDOW_XWINDOW (pizza
->bin_window
)) &&
1058 (gtk_pizza_filter (&xevent
, &event
, pizza
) == GDK_FILTER_REMOVE
))
1061 if (xevent
.type
== Expose
)
1063 event
.expose
.window
= gdk_window_lookup (xevent
.xany
.window
);
1064 gdk_window_get_user_data (event
.expose
.window
,
1065 (gpointer
*)&event_widget
);
1069 event
.expose
.type
= GDK_EXPOSE
;
1070 event
.expose
.area
.x
= xevent
.xexpose
.x
;
1071 event
.expose
.area
.y
= xevent
.xexpose
.y
;
1072 event
.expose
.area
.width
= xevent
.xexpose
.width
;
1073 event
.expose
.area
.height
= xevent
.xexpose
.height
;
1074 event
.expose
.count
= xevent
.xexpose
.count
;
1076 gdk_window_ref (event
.expose
.window
);
1077 gtk_widget_event (event_widget
, &event
);
1078 gdk_window_unref (event
.expose
.window
);
1084 /* The main event filter. Actually, we probably don't really need
1085 * to install this as a filter at all, since we are calling it
1086 * directly above in the expose-handling hack. But in case scrollbars
1087 * are fixed up in some manner...
1089 * This routine identifies expose events that are generated when
1090 * we've temporarily moved the bin_window_origin, and translates
1091 * them or discards them, depending on whether we are obscured
1094 static GdkFilterReturn
1095 gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
1102 xevent
= (XEvent
*)gdk_xevent
;
1104 pizza
= GTK_PIZZA (data
);
1106 if (!pizza
->use_filter
)
1107 return GDK_FILTER_CONTINUE
;
1109 switch (xevent
->type
)
1112 if (xevent
->xexpose
.serial
== pizza
->configure_serial
)
1114 if (pizza
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
1115 return GDK_FILTER_REMOVE
;
1118 xevent
->xexpose
.x
+= pizza
->scroll_x
;
1119 xevent
->xexpose
.y
+= pizza
->scroll_y
;
1126 case ConfigureNotify
:
1127 if ((xevent
->xconfigure
.x
!= 0) || (xevent
->xconfigure
.y
!= 0))
1129 pizza
->configure_serial
= xevent
->xconfigure
.serial
;
1130 pizza
->scroll_x
= xevent
->xconfigure
.x
;
1131 pizza
->scroll_y
= xevent
->xconfigure
.y
;
1136 return GDK_FILTER_CONTINUE
;
1139 /* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
1140 * there is no corresponding event in GTK, so we have
1141 * to get the events from a filter
1143 static GdkFilterReturn
1144 gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
1151 xevent
= (XEvent
*)gdk_xevent
;
1152 pizza
= GTK_PIZZA (data
);
1154 if (!pizza
->use_filter
)
1155 return GDK_FILTER_CONTINUE
;
1157 if (xevent
->type
== VisibilityNotify
)
1159 switch (xevent
->xvisibility
.state
)
1161 case VisibilityFullyObscured
:
1162 pizza
->visibility
= GDK_VISIBILITY_FULLY_OBSCURED
;
1165 case VisibilityPartiallyObscured
:
1166 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
1169 case VisibilityUnobscured
:
1170 pizza
->visibility
= GDK_VISIBILITY_UNOBSCURED
;
1174 return GDK_FILTER_REMOVE
;
1177 return GDK_FILTER_CONTINUE
;
1185 #endif /* __cplusplus */