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 */
21 #define IS_ONSCREEN(x,y) ((x >= G_MINSHORT) && (x <= G_MAXSHORT) && \
22 (y >= G_MINSHORT) && (y <= G_MAXSHORT))
24 typedef struct _GtkPizzaAdjData GtkPizzaAdjData
;
25 typedef struct _GtkPizzaChild GtkPizzaChild
;
27 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
,
85 static void gtk_pizza_adjustment_changed (GtkAdjustment
*adjustment
,
87 static GdkFilterReturn
gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
90 static GdkFilterReturn
gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
95 static GtkType
gtk_pizza_child_type (GtkContainer
*container
);
97 static void gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
102 static GtkContainerClass
*parent_class
= NULL
;
103 static gboolean gravity_works
;
106 gtk_pizza_get_type ()
108 static guint pizza_type
= 0;
112 GtkTypeInfo pizza_info
=
116 sizeof (GtkPizzaClass
),
117 (GtkClassInitFunc
) gtk_pizza_class_init
,
118 (GtkObjectInitFunc
) gtk_pizza_init
,
119 /* reserved_1 */ NULL
,
120 /* reserved_2 */ NULL
,
121 (GtkClassInitFunc
) NULL
,
123 pizza_type
= gtk_type_unique (gtk_container_get_type (), &pizza_info
);
130 gtk_pizza_class_init (GtkPizzaClass
*klass
)
132 GtkObjectClass
*object_class
;
133 GtkWidgetClass
*widget_class
;
134 GtkContainerClass
*container_class
;
136 object_class
= (GtkObjectClass
*) klass
;
137 widget_class
= (GtkWidgetClass
*) klass
;
138 container_class
= (GtkContainerClass
*) klass
;
139 parent_class
= gtk_type_class (GTK_TYPE_CONTAINER
);
141 widget_class
->map
= gtk_pizza_map
;
142 widget_class
->realize
= gtk_pizza_realize
;
143 widget_class
->unrealize
= gtk_pizza_unrealize
;
144 widget_class
->size_request
= gtk_pizza_size_request
;
145 widget_class
->size_allocate
= gtk_pizza_size_allocate
;
146 widget_class
->draw
= gtk_pizza_draw
;
147 widget_class
->expose_event
= gtk_pizza_expose
;
149 container_class
->add
= gtk_pizza_add
;
150 container_class
->remove
= gtk_pizza_remove
;
151 container_class
->forall
= gtk_pizza_forall
;
153 container_class
->child_type
= gtk_pizza_child_type
;
155 klass
->set_scroll_adjustments
= gtk_pizza_scroll_set_adjustments
;
157 widget_class
->set_scroll_adjustments_signal
=
158 gtk_signal_new ("set_scroll_adjustments",
161 GTK_SIGNAL_OFFSET (GtkPizzaClass
, set_scroll_adjustments
),
162 gtk_marshal_NONE__POINTER_POINTER
,
163 GTK_TYPE_NONE
, 2, GTK_TYPE_ADJUSTMENT
, GTK_TYPE_ADJUSTMENT
);
167 gtk_pizza_child_type (GtkContainer
*container
)
169 return GTK_TYPE_WIDGET
;
173 gtk_pizza_init (GtkPizza
*pizza
)
175 GTK_WIDGET_UNSET_FLAGS (pizza
, GTK_NO_WINDOW
);
177 pizza
->shadow_type
= GTK_MYSHADOW_NONE
;
179 pizza
->children
= NULL
;
184 pizza
->bin_window
= NULL
;
186 pizza
->configure_serial
= 0;
189 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
191 pizza
->clear_on_draw
= TRUE
;
199 pizza
= gtk_type_new (gtk_pizza_get_type ());
201 return GTK_WIDGET (pizza
);
205 gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
209 /* We handle scrolling in the wxScrolledWindow, not here. */
213 gtk_pizza_set_shadow_type (GtkPizza
*pizza
,
214 GtkMyShadowType type
)
216 g_return_if_fail (pizza
!= NULL
);
217 g_return_if_fail (GTK_IS_PIZZA (pizza
));
219 if ((GtkMyShadowType
) pizza
->shadow_type
!= type
)
221 pizza
->shadow_type
= type
;
223 if (GTK_WIDGET_VISIBLE (pizza
))
225 gtk_widget_size_allocate (GTK_WIDGET (pizza
), &(GTK_WIDGET (pizza
)->allocation
));
226 gtk_widget_queue_draw (GTK_WIDGET (pizza
));
232 gtk_pizza_set_clear (GtkPizza
*pizza
,
235 g_return_if_fail (pizza
!= NULL
);
236 g_return_if_fail (GTK_IS_PIZZA (pizza
));
238 pizza
->clear_on_draw
= clear
;
242 gtk_pizza_put (GtkPizza
*pizza
,
249 GtkPizzaChild
*child_info
;
251 g_return_if_fail (pizza
!= NULL
);
252 g_return_if_fail (GTK_IS_PIZZA (pizza
));
253 g_return_if_fail (widget
!= NULL
);
255 child_info
= g_new (GtkPizzaChild
, 1);
257 child_info
->widget
= widget
;
260 child_info
->width
= width
;
261 child_info
->height
= height
;
263 pizza
->children
= g_list_append (pizza
->children
, child_info
);
265 gtk_widget_set_parent (widget
, GTK_WIDGET (pizza
));
267 if (GTK_WIDGET_REALIZED (pizza
))
268 gtk_widget_set_parent_window (widget
, pizza
->bin_window
);
270 if (!IS_ONSCREEN (x
, y
))
271 GTK_PRIVATE_SET_FLAG (widget
, GTK_IS_OFFSCREEN
);
273 if (GTK_WIDGET_REALIZED (pizza
))
274 gtk_widget_realize (widget
);
276 gtk_widget_set_usize (widget
, width
, height
);
278 if (GTK_WIDGET_VISIBLE (pizza
) && GTK_WIDGET_VISIBLE (widget
))
280 if (GTK_WIDGET_MAPPED (pizza
))
281 gtk_widget_map (widget
);
283 gtk_widget_queue_resize (widget
);
288 gtk_pizza_move (GtkPizza
*pizza
,
293 GtkPizzaChild
*child
;
296 g_return_if_fail (pizza
!= NULL
);
297 g_return_if_fail (GTK_IS_PIZZA (pizza
));
298 g_return_if_fail (widget
!= NULL
);
300 children
= pizza
->children
;
303 child
= children
->data
;
304 children
= children
->next
;
306 if (child
->widget
== widget
)
308 if ((child
->x
== x
) && (child
->y
== y
))
314 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
315 gtk_widget_queue_resize (widget
);
322 gtk_pizza_resize (GtkPizza
*pizza
,
327 GtkPizzaChild
*child
;
330 g_return_if_fail (pizza
!= NULL
);
331 g_return_if_fail (GTK_IS_PIZZA (pizza
));
332 g_return_if_fail (widget
!= NULL
);
334 children
= pizza
->children
;
337 child
= children
->data
;
338 children
= children
->next
;
340 if (child
->widget
== widget
)
342 if ((child
->width
== width
) && (child
->height
== height
))
345 child
->width
= width
;
346 child
->height
= height
;
348 gtk_widget_set_usize (widget
, width
, height
);
350 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
351 gtk_widget_queue_resize (widget
);
358 gtk_pizza_set_size (GtkPizza
*pizza
,
365 GtkPizzaChild
*child
;
368 g_return_if_fail (pizza
!= NULL
);
369 g_return_if_fail (GTK_IS_PIZZA (pizza
));
370 g_return_if_fail (widget
!= NULL
);
372 children
= pizza
->children
;
375 child
= children
->data
;
376 children
= children
->next
;
378 if (child
->widget
== widget
)
380 if ((child
->x
== x
) &&
382 (child
->width
== width
) &&
383 (child
->height
== height
)) return;
387 child
->width
= width
;
388 child
->height
= height
;
390 gtk_widget_set_usize (widget
, width
, height
);
392 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
393 gtk_widget_queue_resize (widget
);
401 gtk_pizza_map (GtkWidget
*widget
)
404 GtkPizzaChild
*child
;
407 g_return_if_fail (widget
!= NULL
);
408 g_return_if_fail (GTK_IS_PIZZA (widget
));
410 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
411 pizza
= GTK_PIZZA (widget
);
413 children
= pizza
->children
;
416 child
= children
->data
;
417 children
= children
->next
;
419 if ( GTK_WIDGET_VISIBLE (child
->widget
) &&
420 !GTK_WIDGET_MAPPED (child
->widget
) &&
421 !GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
423 gtk_widget_map (child
->widget
);
427 gdk_window_show (widget
->window
);
428 gdk_window_show (pizza
->bin_window
);
432 gtk_pizza_realize (GtkWidget
*widget
)
435 GdkWindowAttr attributes
;
436 gint attributes_mask
;
437 GtkPizzaChild
*child
;
440 g_return_if_fail (widget
!= NULL
);
441 g_return_if_fail (GTK_IS_PIZZA (widget
));
443 pizza
= GTK_PIZZA (widget
);
445 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
447 attributes
.window_type
= GDK_WINDOW_CHILD
;
449 attributes
.x
= widget
->allocation
.x
;
450 attributes
.y
= widget
->allocation
.y
;
451 attributes
.width
= widget
->allocation
.width
;
452 attributes
.height
= widget
->allocation
.height
;
454 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
456 /* no border, no changes to sizes */
458 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
460 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
463 attributes
.width
-= 2;
464 attributes
.height
-= 2;
467 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
468 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
471 attributes
.width
-= 4;
472 attributes
.height
-= 4;
476 if (attributes
.width
< 2) attributes
.width
= 2;
477 if (attributes
.height
< 2) attributes
.height
= 2;
479 attributes
.wclass
= GDK_INPUT_OUTPUT
;
480 attributes
.visual
= gtk_widget_get_visual (widget
);
481 attributes
.colormap
= gtk_widget_get_colormap (widget
);
482 attributes
.event_mask
=
483 GDK_VISIBILITY_NOTIFY_MASK
;
484 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
486 widget
->window
= gdk_window_new (gtk_widget_get_parent_window (widget
),
487 &attributes
, attributes_mask
);
488 gdk_window_set_user_data (widget
->window
, widget
);
493 attributes
.event_mask
= gtk_widget_get_events (widget
);
494 attributes
.event_mask
|=
496 GDK_POINTER_MOTION_MASK
|
497 GDK_POINTER_MOTION_HINT_MASK
|
498 GDK_BUTTON_MOTION_MASK
|
499 GDK_BUTTON1_MOTION_MASK
|
500 GDK_BUTTON2_MOTION_MASK
|
501 GDK_BUTTON3_MOTION_MASK
|
502 GDK_BUTTON_PRESS_MASK
|
503 GDK_BUTTON_RELEASE_MASK
|
505 GDK_KEY_RELEASE_MASK
|
506 GDK_ENTER_NOTIFY_MASK
|
507 GDK_LEAVE_NOTIFY_MASK
|
508 GDK_FOCUS_CHANGE_MASK
;
510 pizza
->bin_window
= gdk_window_new (widget
->window
,
511 &attributes
, attributes_mask
);
512 gdk_window_set_user_data (pizza
->bin_window
, widget
);
514 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
515 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
516 gtk_style_set_background (widget
->style
, pizza
->bin_window
, GTK_STATE_NORMAL
);
518 /* add filters for intercepting visibility and expose events */
519 gdk_window_add_filter (widget
->window
, gtk_pizza_main_filter
, pizza
);
520 gdk_window_add_filter (pizza
->bin_window
, gtk_pizza_filter
, pizza
);
522 /* we NEED gravity or we'll give up */
523 gravity_works
= gdk_window_set_static_gravities (pizza
->bin_window
, TRUE
);
525 /* cannot be done before realisation */
526 children
= pizza
->children
;
529 child
= children
->data
;
530 children
= children
->next
;
532 gtk_widget_set_parent_window (child
->widget
, pizza
->bin_window
);
537 gtk_pizza_unrealize (GtkWidget
*widget
)
541 g_return_if_fail (widget
!= NULL
);
542 g_return_if_fail (GTK_IS_PIZZA (widget
));
544 pizza
= GTK_PIZZA (widget
);
546 gdk_window_set_user_data (pizza
->bin_window
, NULL
);
547 gdk_window_destroy (pizza
->bin_window
);
548 pizza
->bin_window
= NULL
;
550 if (GTK_WIDGET_CLASS (parent_class
)->unrealize
)
551 (* GTK_WIDGET_CLASS (parent_class
)->unrealize
) (widget
);
555 gtk_pizza_size_request (GtkWidget
*widget
,
556 GtkRequisition
*requisition
)
559 GtkPizzaChild
*child
;
561 GtkRequisition child_requisition
;
563 g_return_if_fail (widget
!= NULL
);
564 g_return_if_fail (GTK_IS_PIZZA (widget
));
565 g_return_if_fail (requisition
!= NULL
);
567 pizza
= GTK_PIZZA (widget
);
569 children
= pizza
->children
;
572 child
= children
->data
;
573 children
= children
->next
;
575 if (GTK_WIDGET_VISIBLE (child
->widget
))
577 gtk_widget_size_request (child
->widget
, &child_requisition
);
581 /* request very little, I'm not sure if requesting nothing
582 will always have positive effects on stability... */
583 requisition
->width
= 2;
584 requisition
->height
= 2;
588 gtk_pizza_size_allocate (GtkWidget
*widget
,
589 GtkAllocation
*allocation
)
594 GtkPizzaChild
*child
;
597 g_return_if_fail (widget
!= NULL
);
598 g_return_if_fail (GTK_IS_PIZZA(widget
));
599 g_return_if_fail (allocation
!= NULL
);
601 pizza
= GTK_PIZZA (widget
);
603 widget
->allocation
= *allocation
;
605 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
608 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
613 x
= allocation
->x
+ border
;
614 y
= allocation
->y
+ border
;
615 w
= allocation
->width
- border
*2;
616 h
= allocation
->height
- border
*2;
618 if (GTK_WIDGET_REALIZED (widget
))
620 gdk_window_move_resize( widget
->window
, x
, y
, w
, h
);
621 gdk_window_move_resize( pizza
->bin_window
, 0, 0, w
, h
);
624 children
= pizza
->children
;
627 child
= children
->data
;
628 children
= children
->next
;
630 gtk_pizza_position_child (pizza
, child
);
631 gtk_pizza_allocate_child (pizza
, child
);
636 gtk_pizza_draw (GtkWidget
*widget
,
640 GtkPizzaChild
*child
;
641 GdkRectangle child_area
;
644 g_return_if_fail (widget
!= NULL
);
645 g_return_if_fail (GTK_IS_PIZZA (widget
));
647 pizza
= GTK_PIZZA (widget
);
649 children
= pizza
->children
;
650 if ( !(GTK_WIDGET_APP_PAINTABLE (widget
)) &&
651 (pizza
->clear_on_draw
))
653 gdk_window_clear_area( pizza
->bin_window
,
654 area
->x
, area
->y
, area
->width
, area
->height
);
659 child
= children
->data
;
660 children
= children
->next
;
662 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
663 gtk_widget_draw (child
->widget
, &child_area
);
668 gtk_pizza_expose (GtkWidget
*widget
,
669 GdkEventExpose
*event
)
672 GtkPizzaChild
*child
;
673 GdkEventExpose child_event
;
676 g_return_val_if_fail (widget
!= NULL
, FALSE
);
677 g_return_val_if_fail (GTK_IS_PIZZA (widget
), FALSE
);
678 g_return_val_if_fail (event
!= NULL
, FALSE
);
680 pizza
= GTK_PIZZA (widget
);
683 if (event->window == widget->window)
685 gtk_pizza_draw_border( pizza );
690 if (event
->window
!= pizza
->bin_window
)
693 children
= pizza
->children
;
696 child
= children
->data
;
697 children
= children
->next
;
699 child_event
= *event
;
701 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
702 GTK_WIDGET_DRAWABLE (child
->widget
) &&
703 gtk_widget_intersect (child
->widget
, &event
->area
, &child_event
.area
))
705 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
713 gtk_pizza_add (GtkContainer
*container
,
716 g_return_if_fail (container
!= NULL
);
717 g_return_if_fail (GTK_IS_PIZZA (container
));
718 g_return_if_fail (widget
!= NULL
);
720 gtk_pizza_put (GTK_PIZZA (container
), widget
, 0, 0, 20, 20 );
724 gtk_pizza_remove (GtkContainer
*container
,
728 GtkPizzaChild
*child
;
731 g_return_if_fail (container
!= NULL
);
732 g_return_if_fail (GTK_IS_PIZZA (container
));
733 g_return_if_fail (widget
!= NULL
);
735 pizza
= GTK_PIZZA (container
);
737 children
= pizza
->children
;
740 child
= children
->data
;
742 if (child
->widget
== widget
)
744 gtk_widget_unparent (widget
);
746 /* security checks */
747 g_return_if_fail (GTK_IS_WIDGET (widget
));
749 pizza
->children
= g_list_remove_link (pizza
->children
, children
);
750 g_list_free (children
);
753 /* security checks */
754 g_return_if_fail (GTK_IS_WIDGET (widget
));
756 GTK_PRIVATE_UNSET_FLAG (widget
, GTK_IS_OFFSCREEN
);
761 children
= children
->next
;
766 gtk_pizza_forall (GtkContainer
*container
,
767 gboolean include_internals
,
768 GtkCallback callback
,
769 gpointer callback_data
)
772 GtkPizzaChild
*child
;
775 g_return_if_fail (container
!= NULL
);
776 g_return_if_fail (GTK_IS_PIZZA (container
));
777 g_return_if_fail (callback
!= NULL
);
779 pizza
= GTK_PIZZA (container
);
781 children
= pizza
->children
;
784 child
= children
->data
;
785 children
= children
->next
;
787 (* callback
) (child
->widget
, callback_data
);
792 /* Operations on children
796 gtk_pizza_position_child (GtkPizza
*pizza
,
797 GtkPizzaChild
*child
)
802 x
= child
->x
- pizza
->xoffset
;
803 y
= child
->y
- pizza
->yoffset
;
805 if (IS_ONSCREEN (x
,y
))
807 if (GTK_WIDGET_MAPPED (pizza
) &&
808 GTK_WIDGET_VISIBLE (child
->widget
))
810 if (!GTK_WIDGET_MAPPED (child
->widget
))
811 gtk_widget_map (child
->widget
);
814 if (GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
815 GTK_PRIVATE_UNSET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
819 if (!GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
820 GTK_PRIVATE_SET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
822 if (GTK_WIDGET_MAPPED (child
->widget
))
823 gtk_widget_unmap (child
->widget
);
828 gtk_pizza_allocate_child (GtkPizza
*pizza
,
829 GtkPizzaChild
*child
)
831 GtkAllocation allocation
;
832 GtkRequisition requisition
;
834 allocation
.x
= child
->x
- pizza
->xoffset
;
835 allocation
.y
= child
->y
- pizza
->yoffset
;
836 gtk_widget_get_child_requisition (child
->widget
, &requisition
);
837 allocation
.width
= requisition
.width
;
838 allocation
.height
= requisition
.height
;
840 gtk_widget_size_allocate (child
->widget
, &allocation
);
844 gtk_pizza_position_children (GtkPizza
*pizza
)
848 tmp_list
= pizza
->children
;
851 GtkPizzaChild
*child
= tmp_list
->data
;
852 tmp_list
= tmp_list
->next
;
854 gtk_pizza_position_child (pizza
, child
);
859 gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
862 GtkPizzaAdjData
*data
= cb_data
;
864 widget
->allocation
.x
+= data
->dx
;
865 widget
->allocation
.y
+= data
->dy
;
867 if (GTK_WIDGET_NO_WINDOW (widget
) && GTK_IS_CONTAINER (widget
))
869 gtk_container_forall (GTK_CONTAINER (widget
),
870 gtk_pizza_adjust_allocations_recurse
,
876 gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
881 GtkPizzaAdjData data
;
886 tmp_list
= pizza
->children
;
889 GtkPizzaChild
*child
= tmp_list
->data
;
890 tmp_list
= tmp_list
->next
;
892 child
->widget
->allocation
.x
+= dx
;
893 child
->widget
->allocation
.y
+= dy
;
895 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
896 GTK_IS_CONTAINER (child
->widget
))
897 gtk_container_forall (GTK_CONTAINER (child
->widget
),
898 gtk_pizza_adjust_allocations_recurse
,
905 /* Send a synthetic expose event to the widget
908 gtk_pizza_expose_area (GtkPizza
*pizza
,
909 gint x
, gint y
, gint width
, gint height
)
911 if (pizza
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
913 GdkEventExpose event
;
915 event
.type
= GDK_EXPOSE
;
916 event
.send_event
= TRUE
;
917 event
.window
= pizza
->bin_window
;
922 event
.area
.width
= width
;
923 event
.area
.height
= height
;
925 gdk_window_ref (event
.window
);
926 gtk_widget_event (GTK_WIDGET (pizza
), (GdkEvent
*)&event
);
927 gdk_window_unref (event
.window
);
931 /* This function is used to find events to process while scrolling
935 gtk_pizza_expose_predicate (Display
*display
,
939 if ((xevent
->type
== Expose
) ||
940 ((xevent
->xany
.window
== *(Window
*)arg
) &&
941 (xevent
->type
== ConfigureNotify
)))
947 /* This is the main routine to do the scrolling. Scrolling is
948 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
949 * a few modifications.
951 * The main improvement is that we keep track of whether we
952 * are obscured or not. If not, we ignore the generated expose
953 * events and instead do the exposes ourself, without having
954 * to wait for a roundtrip to the server. This also provides
955 * a limited form of expose-event compression, since we do
956 * the affected area as one big chunk.
960 gtk_pizza_scroll (GtkPizza
*pizza
, gint dx
, gint dy
)
967 widget
= GTK_WIDGET (pizza
);
969 pizza
->xoffset
+= dx
;
970 pizza
->yoffset
+= dy
;
972 if (!GTK_WIDGET_MAPPED (pizza
))
974 gtk_pizza_position_children (pizza
);
978 gtk_pizza_adjust_allocations (pizza
, -dx
, -dy
);
980 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
983 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
990 w
= widget
->allocation
.width
- 2*border
;
991 h
= widget
->allocation
.height
- 2*border
;
997 gdk_window_resize (pizza
->bin_window
,
1000 gdk_window_move (pizza
->bin_window
, x
-dx
, y
);
1001 gdk_window_move_resize (pizza
->bin_window
, x
, y
, w
, h
);
1008 gtk_pizza_expose_area (pizza
,
1009 MAX ((gint
)w
- dx
, 0),
1018 gdk_window_move_resize (pizza
->bin_window
,
1023 gdk_window_move (pizza
->bin_window
, x
, y
);
1024 gdk_window_resize (pizza
->bin_window
, w
, h
);
1031 gtk_pizza_expose_area (pizza
,
1042 gdk_window_resize (pizza
->bin_window
, w
, h
+ dy
);
1043 gdk_window_move (pizza
->bin_window
, x
, y
-dy
);
1044 gdk_window_move_resize (pizza
->bin_window
,
1052 gtk_pizza_expose_area (pizza
,
1054 MAX ((gint
)h
- dy
, 0),
1062 gdk_window_move_resize (pizza
->bin_window
,
1063 x
, y
+dy
, w
, h
- dy
);
1064 gdk_window_move (pizza
->bin_window
, x
, y
);
1065 gdk_window_resize (pizza
->bin_window
, w
, h
);
1071 gtk_pizza_expose_area (pizza
,
1075 MIN (-dy
, (gint
)h
));
1078 gtk_pizza_position_children (pizza
);
1080 /* We have to make sure that all exposes from this scroll get
1081 * processed before we scroll again, or the expose events will
1082 * have invalid coordinates.
1084 * We also do expose events for other windows, since otherwise
1085 * their updating will fall behind the scrolling
1087 * This also avoids a problem in pre-1.0 GTK where filters don't
1088 * have access to configure events that were compressed.
1092 while (XCheckIfEvent(GDK_WINDOW_XDISPLAY (pizza
->bin_window
),
1094 gtk_pizza_expose_predicate
,
1095 (XPointer
)&GDK_WINDOW_XWINDOW (pizza
->bin_window
)))
1098 GtkWidget
*event_widget
;
1100 if ((xevent
.xany
.window
== GDK_WINDOW_XWINDOW (pizza
->bin_window
)) &&
1101 (gtk_pizza_filter (&xevent
, &event
, pizza
) == GDK_FILTER_REMOVE
))
1104 if (xevent
.type
== Expose
)
1106 event
.expose
.window
= gdk_window_lookup (xevent
.xany
.window
);
1107 gdk_window_get_user_data (event
.expose
.window
,
1108 (gpointer
*)&event_widget
);
1112 event
.expose
.type
= GDK_EXPOSE
;
1113 event
.expose
.area
.x
= xevent
.xexpose
.x
;
1114 event
.expose
.area
.y
= xevent
.xexpose
.y
;
1115 event
.expose
.area
.width
= xevent
.xexpose
.width
;
1116 event
.expose
.area
.height
= xevent
.xexpose
.height
;
1117 event
.expose
.count
= xevent
.xexpose
.count
;
1119 gdk_window_ref (event
.expose
.window
);
1120 gtk_widget_event (event_widget
, &event
);
1121 gdk_window_unref (event
.expose
.window
);
1127 /* The main event filter. Actually, we probably don't really need
1128 * to install this as a filter at all, since we are calling it
1129 * directly above in the expose-handling hack. But in case scrollbars
1130 * are fixed up in some manner...
1132 * This routine identifies expose events that are generated when
1133 * we've temporarily moved the bin_window_origin, and translates
1134 * them or discards them, depending on whether we are obscured
1137 static GdkFilterReturn
1138 gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
1145 xevent
= (XEvent
*)gdk_xevent
;
1146 pizza
= GTK_PIZZA (data
);
1148 switch (xevent
->type
)
1151 if (xevent
->xexpose
.serial
== pizza
->configure_serial
)
1153 if (pizza
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
1154 return GDK_FILTER_REMOVE
;
1157 xevent
->xexpose
.x
+= pizza
->scroll_x
;
1158 xevent
->xexpose
.y
+= pizza
->scroll_y
;
1165 case ConfigureNotify
:
1166 if ((xevent
->xconfigure
.x
!= 0) || (xevent
->xconfigure
.y
!= 0))
1168 pizza
->configure_serial
= xevent
->xconfigure
.serial
;
1169 pizza
->scroll_x
= xevent
->xconfigure
.x
;
1170 pizza
->scroll_y
= xevent
->xconfigure
.y
;
1175 return GDK_FILTER_CONTINUE
;
1178 /* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
1179 * there is no corresponding event in GTK, so we have
1180 * to get the events from a filter
1182 static GdkFilterReturn
1183 gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
1190 xevent
= (XEvent
*)gdk_xevent
;
1191 pizza
= GTK_PIZZA (data
);
1193 if (xevent
->type
== VisibilityNotify
)
1195 switch (xevent
->xvisibility
.state
)
1197 case VisibilityFullyObscured
:
1198 pizza
->visibility
= GDK_VISIBILITY_FULLY_OBSCURED
;
1201 case VisibilityPartiallyObscured
:
1202 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
1205 case VisibilityUnobscured
:
1206 pizza
->visibility
= GDK_VISIBILITY_UNOBSCURED
;
1210 return GDK_FILTER_REMOVE
;
1214 return GDK_FILTER_CONTINUE
;
1222 #endif /* __cplusplus */