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
;
33 typedef struct _GtkPizzaChild GtkPizzaChild
;
35 struct _GtkPizzaAdjData
50 static void gtk_pizza_class_init (GtkPizzaClass
*klass
);
51 static void gtk_pizza_init (GtkPizza
*pizza
);
53 static void gtk_pizza_realize (GtkWidget
*widget
);
54 static void gtk_pizza_unrealize (GtkWidget
*widget
);
56 static void gtk_pizza_map (GtkWidget
*widget
);
58 static void gtk_pizza_size_request (GtkWidget
*widget
,
59 GtkRequisition
*requisition
);
60 static void gtk_pizza_size_allocate (GtkWidget
*widget
,
61 GtkAllocation
*allocation
);
62 static void gtk_pizza_draw (GtkWidget
*widget
,
64 static gint
gtk_pizza_expose (GtkWidget
*widget
,
65 GdkEventExpose
*event
);
66 static void gtk_pizza_add (GtkContainer
*container
,
68 static void gtk_pizza_remove (GtkContainer
*container
,
70 static void gtk_pizza_forall (GtkContainer
*container
,
71 gboolean include_internals
,
73 gpointer callback_data
);
75 static void gtk_pizza_position_child (GtkPizza
*pizza
,
76 GtkPizzaChild
*child
);
77 static void gtk_pizza_allocate_child (GtkPizza
*pizza
,
78 GtkPizzaChild
*child
);
79 static void gtk_pizza_position_children (GtkPizza
*pizza
);
81 static void gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
83 static void gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
88 static void gtk_pizza_expose_area (GtkPizza
*pizza
,
93 static void gtk_pizza_adjustment_changed (GtkAdjustment
*adjustment
,
95 static GdkFilterReturn
gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
98 static GdkFilterReturn
gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
103 static GtkType
gtk_pizza_child_type (GtkContainer
*container
);
105 static void gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
107 GtkAdjustment
*vadj
);
110 static GtkContainerClass
*parent_class
= NULL
;
111 static gboolean gravity_works
;
114 gtk_pizza_get_type ()
116 static guint pizza_type
= 0;
120 GtkTypeInfo pizza_info
=
124 sizeof (GtkPizzaClass
),
125 (GtkClassInitFunc
) gtk_pizza_class_init
,
126 (GtkObjectInitFunc
) gtk_pizza_init
,
127 /* reserved_1 */ NULL
,
128 /* reserved_2 */ NULL
,
129 (GtkClassInitFunc
) NULL
,
131 pizza_type
= gtk_type_unique (gtk_container_get_type (), &pizza_info
);
138 gtk_pizza_class_init (GtkPizzaClass
*klass
)
140 GtkObjectClass
*object_class
;
141 GtkWidgetClass
*widget_class
;
142 GtkContainerClass
*container_class
;
144 object_class
= (GtkObjectClass
*) klass
;
145 widget_class
= (GtkWidgetClass
*) klass
;
146 container_class
= (GtkContainerClass
*) klass
;
147 parent_class
= gtk_type_class (GTK_TYPE_CONTAINER
);
149 widget_class
->map
= gtk_pizza_map
;
150 widget_class
->realize
= gtk_pizza_realize
;
151 widget_class
->unrealize
= gtk_pizza_unrealize
;
152 widget_class
->size_request
= gtk_pizza_size_request
;
153 widget_class
->size_allocate
= gtk_pizza_size_allocate
;
154 widget_class
->draw
= gtk_pizza_draw
;
155 widget_class
->expose_event
= gtk_pizza_expose
;
157 container_class
->add
= gtk_pizza_add
;
158 container_class
->remove
= gtk_pizza_remove
;
159 container_class
->forall
= gtk_pizza_forall
;
161 container_class
->child_type
= gtk_pizza_child_type
;
163 klass
->set_scroll_adjustments
= gtk_pizza_scroll_set_adjustments
;
165 widget_class
->set_scroll_adjustments_signal
=
166 gtk_signal_new ("set_scroll_adjustments",
169 GTK_SIGNAL_OFFSET (GtkPizzaClass
, set_scroll_adjustments
),
170 gtk_marshal_NONE__POINTER_POINTER
,
171 GTK_TYPE_NONE
, 2, GTK_TYPE_ADJUSTMENT
, GTK_TYPE_ADJUSTMENT
);
175 gtk_pizza_child_type (GtkContainer
*container
)
177 return GTK_TYPE_WIDGET
;
181 gtk_pizza_init (GtkPizza
*pizza
)
183 GTK_WIDGET_UNSET_FLAGS (pizza
, GTK_NO_WINDOW
);
185 pizza
->shadow_type
= GTK_MYSHADOW_NONE
;
187 pizza
->children
= NULL
;
192 pizza
->bin_window
= NULL
;
197 pizza
->configure_serial
= 0;
200 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
202 pizza
->clear_on_draw
= TRUE
;
203 pizza
->use_filter
= FALSE
;
211 pizza
= gtk_type_new (gtk_pizza_get_type ());
213 return GTK_WIDGET (pizza
);
217 gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
221 /* We handle scrolling in the wxScrolledWindow, not here. */
225 gtk_pizza_set_shadow_type (GtkPizza
*pizza
,
226 GtkMyShadowType type
)
228 g_return_if_fail (pizza
!= NULL
);
229 g_return_if_fail (GTK_IS_PIZZA (pizza
));
231 if ((GtkMyShadowType
) pizza
->shadow_type
!= type
)
233 pizza
->shadow_type
= type
;
235 if (GTK_WIDGET_VISIBLE (pizza
))
237 gtk_widget_size_allocate (GTK_WIDGET (pizza
), &(GTK_WIDGET (pizza
)->allocation
));
238 gtk_widget_queue_draw (GTK_WIDGET (pizza
));
244 gtk_pizza_set_clear (GtkPizza
*pizza
,
247 g_return_if_fail (pizza
!= NULL
);
248 g_return_if_fail (GTK_IS_PIZZA (pizza
));
250 pizza
->clear_on_draw
= clear
;
254 gtk_pizza_set_filter (GtkPizza
*pizza
,
257 g_return_if_fail (pizza
!= NULL
);
258 g_return_if_fail (GTK_IS_PIZZA (pizza
));
260 pizza
->use_filter
= use
;
264 gtk_pizza_put (GtkPizza
*pizza
,
271 GtkPizzaChild
*child_info
;
273 g_return_if_fail (pizza
!= NULL
);
274 g_return_if_fail (GTK_IS_PIZZA (pizza
));
275 g_return_if_fail (widget
!= NULL
);
277 child_info
= g_new (GtkPizzaChild
, 1);
279 child_info
->widget
= widget
;
282 child_info
->width
= width
;
283 child_info
->height
= height
;
285 pizza
->children
= g_list_append (pizza
->children
, child_info
);
287 gtk_widget_set_parent (widget
, GTK_WIDGET (pizza
));
289 if (GTK_WIDGET_REALIZED (pizza
))
290 gtk_widget_set_parent_window (widget
, pizza
->bin_window
);
292 if (!IS_ONSCREEN (x
, y
))
293 GTK_PRIVATE_SET_FLAG (widget
, GTK_IS_OFFSCREEN
);
296 if (GTK_WIDGET_REALIZED (pizza))
297 gtk_widget_realize (widget);
300 gtk_widget_set_usize (widget
, width
, height
);
303 if (GTK_WIDGET_VISIBLE (pizza) && GTK_WIDGET_VISIBLE (widget))
305 if (GTK_WIDGET_MAPPED (pizza))
306 gtk_widget_map (widget);
308 gtk_widget_queue_resize (widget);
314 gtk_pizza_move (GtkPizza
*pizza
,
319 GtkPizzaChild
*child
;
322 g_return_if_fail (pizza
!= NULL
);
323 g_return_if_fail (GTK_IS_PIZZA (pizza
));
324 g_return_if_fail (widget
!= NULL
);
326 children
= pizza
->children
;
329 child
= children
->data
;
330 children
= children
->next
;
332 if (child
->widget
== widget
)
334 if ((child
->x
== x
) && (child
->y
== y
))
340 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
341 gtk_widget_queue_resize (widget
);
348 gtk_pizza_resize (GtkPizza
*pizza
,
353 GtkPizzaChild
*child
;
356 g_return_if_fail (pizza
!= NULL
);
357 g_return_if_fail (GTK_IS_PIZZA (pizza
));
358 g_return_if_fail (widget
!= NULL
);
360 children
= pizza
->children
;
363 child
= children
->data
;
364 children
= children
->next
;
366 if (child
->widget
== widget
)
368 if ((child
->width
== width
) && (child
->height
== height
))
371 child
->width
= width
;
372 child
->height
= height
;
374 gtk_widget_set_usize (widget
, width
, height
);
376 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
377 gtk_widget_queue_resize (widget
);
384 gtk_pizza_set_size (GtkPizza
*pizza
,
391 GtkPizzaChild
*child
;
394 g_return_if_fail (pizza
!= NULL
);
395 g_return_if_fail (GTK_IS_PIZZA (pizza
));
396 g_return_if_fail (widget
!= NULL
);
398 children
= pizza
->children
;
401 child
= children
->data
;
402 children
= children
->next
;
404 if (child
->widget
== widget
)
406 if ((child
->x
== x
) &&
408 (child
->width
== width
) &&
409 (child
->height
== height
)) return;
413 child
->width
= width
;
414 child
->height
= height
;
416 gtk_widget_set_usize (widget
, width
, height
);
418 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
419 gtk_widget_queue_resize (widget
);
427 gtk_pizza_map (GtkWidget
*widget
)
430 GtkPizzaChild
*child
;
433 g_return_if_fail (widget
!= NULL
);
434 g_return_if_fail (GTK_IS_PIZZA (widget
));
436 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
437 pizza
= GTK_PIZZA (widget
);
439 children
= pizza
->children
;
442 child
= children
->data
;
443 children
= children
->next
;
445 if ( GTK_WIDGET_VISIBLE (child
->widget
) &&
446 !GTK_WIDGET_MAPPED (child
->widget
) &&
447 !GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
449 gtk_widget_map (child
->widget
);
453 gdk_window_show (widget
->window
);
454 gdk_window_show (pizza
->bin_window
);
458 gtk_pizza_realize (GtkWidget
*widget
)
461 GdkWindowAttr attributes
;
462 gint attributes_mask
;
463 GtkPizzaChild
*child
;
466 g_return_if_fail (widget
!= NULL
);
467 g_return_if_fail (GTK_IS_PIZZA (widget
));
469 pizza
= GTK_PIZZA (widget
);
471 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
473 attributes
.window_type
= GDK_WINDOW_CHILD
;
475 attributes
.x
= widget
->allocation
.x
;
476 attributes
.y
= widget
->allocation
.y
;
477 attributes
.width
= widget
->allocation
.width
;
478 attributes
.height
= widget
->allocation
.height
;
480 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
482 /* no border, no changes to sizes */
484 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
486 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
489 attributes
.width
-= 2;
490 attributes
.height
-= 2;
493 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
494 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
497 attributes
.width
-= 4;
498 attributes
.height
-= 4;
502 if (attributes
.width
< 2) attributes
.width
= 2;
503 if (attributes
.height
< 2) attributes
.height
= 2;
505 attributes
.wclass
= GDK_INPUT_OUTPUT
;
506 attributes
.visual
= gtk_widget_get_visual (widget
);
507 attributes
.colormap
= gtk_widget_get_colormap (widget
);
508 attributes
.event_mask
=
509 GDK_VISIBILITY_NOTIFY_MASK
;
510 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
512 widget
->window
= gdk_window_new(gtk_widget_get_parent_window (widget
),
513 &attributes
, attributes_mask
);
514 gdk_window_set_user_data (widget
->window
, widget
);
519 attributes
.event_mask
= gtk_widget_get_events (widget
);
520 attributes
.event_mask
|=
522 GDK_POINTER_MOTION_MASK
|
523 GDK_POINTER_MOTION_HINT_MASK
|
524 GDK_BUTTON_MOTION_MASK
|
525 GDK_BUTTON1_MOTION_MASK
|
526 GDK_BUTTON2_MOTION_MASK
|
527 GDK_BUTTON3_MOTION_MASK
|
528 GDK_BUTTON_PRESS_MASK
|
529 GDK_BUTTON_RELEASE_MASK
|
531 GDK_KEY_RELEASE_MASK
|
532 GDK_ENTER_NOTIFY_MASK
|
533 GDK_LEAVE_NOTIFY_MASK
|
534 GDK_FOCUS_CHANGE_MASK
;
536 pizza
->bin_window
= gdk_window_new(widget
->window
,
537 &attributes
, attributes_mask
);
538 gdk_window_set_user_data (pizza
->bin_window
, widget
);
540 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
541 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
542 gtk_style_set_background (widget
->style
, pizza
->bin_window
, GTK_STATE_NORMAL
);
544 /* add filters for intercepting visibility and expose events */
545 gdk_window_add_filter (widget
->window
, gtk_pizza_main_filter
, pizza
);
546 gdk_window_add_filter (pizza
->bin_window
, gtk_pizza_filter
, pizza
);
548 /* we NEED gravity or we'll give up */
549 gravity_works
= gdk_window_set_static_gravities (pizza
->bin_window
, TRUE
);
551 /* cannot be done before realisation */
552 children
= pizza
->children
;
555 child
= children
->data
;
556 children
= children
->next
;
558 gtk_widget_set_parent_window (child
->widget
, pizza
->bin_window
);
563 gtk_pizza_unrealize (GtkWidget
*widget
)
567 g_return_if_fail (widget
!= NULL
);
568 g_return_if_fail (GTK_IS_PIZZA (widget
));
570 pizza
= GTK_PIZZA (widget
);
572 gdk_window_set_user_data (pizza
->bin_window
, NULL
);
573 gdk_window_destroy (pizza
->bin_window
);
574 pizza
->bin_window
= NULL
;
576 if (GTK_WIDGET_CLASS (parent_class
)->unrealize
)
577 (* GTK_WIDGET_CLASS (parent_class
)->unrealize
) (widget
);
581 gtk_pizza_size_request (GtkWidget
*widget
,
582 GtkRequisition
*requisition
)
585 GtkPizzaChild
*child
;
587 GtkRequisition child_requisition
;
589 g_return_if_fail (widget
!= NULL
);
590 g_return_if_fail (GTK_IS_PIZZA (widget
));
591 g_return_if_fail (requisition
!= NULL
);
593 pizza
= GTK_PIZZA (widget
);
595 children
= pizza
->children
;
598 child
= children
->data
;
599 children
= children
->next
;
601 if (GTK_WIDGET_VISIBLE (child
->widget
))
603 gtk_widget_size_request (child
->widget
, &child_requisition
);
607 /* request very little, I'm not sure if requesting nothing
608 will always have positive effects on stability... */
609 requisition
->width
= 2;
610 requisition
->height
= 2;
614 gtk_pizza_size_allocate (GtkWidget
*widget
,
615 GtkAllocation
*allocation
)
620 GtkPizzaChild
*child
;
623 g_return_if_fail (widget
!= NULL
);
624 g_return_if_fail (GTK_IS_PIZZA(widget
));
625 g_return_if_fail (allocation
!= NULL
);
627 pizza
= GTK_PIZZA (widget
);
629 widget
->allocation
= *allocation
;
631 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
634 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
639 x
= allocation
->x
+ border
;
640 y
= allocation
->y
+ border
;
641 w
= allocation
->width
- border
*2;
642 h
= allocation
->height
- border
*2;
644 if (GTK_WIDGET_REALIZED (widget
))
646 gdk_window_move_resize( widget
->window
, x
, y
, w
, h
);
647 gdk_window_move_resize( pizza
->bin_window
, 0, 0, w
, h
);
650 children
= pizza
->children
;
653 child
= children
->data
;
654 children
= children
->next
;
656 gtk_pizza_position_child (pizza
, child
);
657 gtk_pizza_allocate_child (pizza
, child
);
662 gtk_pizza_draw (GtkWidget
*widget
,
666 GtkPizzaChild
*child
;
667 GdkRectangle child_area
;
670 g_return_if_fail (widget
!= NULL
);
671 g_return_if_fail (GTK_IS_PIZZA (widget
));
673 pizza
= GTK_PIZZA (widget
);
675 children
= pizza
->children
;
676 if ( !(GTK_WIDGET_APP_PAINTABLE (widget
)) &&
677 (pizza
->clear_on_draw
))
679 gdk_window_clear_area( pizza
->bin_window
,
680 area
->x
, area
->y
, area
->width
, area
->height
);
685 child
= children
->data
;
686 children
= children
->next
;
688 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
689 gtk_widget_draw (child
->widget
, &child_area
);
694 gtk_pizza_expose (GtkWidget
*widget
,
695 GdkEventExpose
*event
)
698 GtkPizzaChild
*child
;
699 GdkEventExpose child_event
;
702 g_return_val_if_fail (widget
!= NULL
, FALSE
);
703 g_return_val_if_fail (GTK_IS_PIZZA (widget
), FALSE
);
704 g_return_val_if_fail (event
!= NULL
, FALSE
);
706 pizza
= GTK_PIZZA (widget
);
708 if (event
->window
!= pizza
->bin_window
)
711 children
= pizza
->children
;
714 child
= children
->data
;
715 children
= children
->next
;
717 child_event
= *event
;
719 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
720 GTK_WIDGET_DRAWABLE (child
->widget
) &&
721 gtk_widget_intersect (child
->widget
, &event
->area
, &child_event
.area
))
723 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
731 gtk_pizza_add (GtkContainer
*container
,
734 g_return_if_fail (container
!= NULL
);
735 g_return_if_fail (GTK_IS_PIZZA (container
));
736 g_return_if_fail (widget
!= NULL
);
738 gtk_pizza_put (GTK_PIZZA (container
), widget
, 0, 0, 20, 20 );
742 gtk_pizza_remove (GtkContainer
*container
,
746 GtkPizzaChild
*child
;
749 g_return_if_fail (container
!= NULL
);
750 g_return_if_fail (GTK_IS_PIZZA (container
));
751 g_return_if_fail (widget
!= NULL
);
753 pizza
= GTK_PIZZA (container
);
755 children
= pizza
->children
;
758 child
= children
->data
;
760 if (child
->widget
== widget
)
762 gtk_widget_unparent (widget
);
764 /* security checks */
765 g_return_if_fail (GTK_IS_WIDGET (widget
));
767 pizza
->children
= g_list_remove_link (pizza
->children
, children
);
768 g_list_free (children
);
771 /* security checks */
772 g_return_if_fail (GTK_IS_WIDGET (widget
));
774 GTK_PRIVATE_UNSET_FLAG (widget
, GTK_IS_OFFSCREEN
);
779 children
= children
->next
;
784 gtk_pizza_forall (GtkContainer
*container
,
785 gboolean include_internals
,
786 GtkCallback callback
,
787 gpointer callback_data
)
790 GtkPizzaChild
*child
;
793 g_return_if_fail (container
!= NULL
);
794 g_return_if_fail (GTK_IS_PIZZA (container
));
795 g_return_if_fail (callback
!= NULL
);
797 pizza
= GTK_PIZZA (container
);
799 children
= pizza
->children
;
802 child
= children
->data
;
803 children
= children
->next
;
805 (* callback
) (child
->widget
, callback_data
);
810 /* Operations on children
814 gtk_pizza_position_child (GtkPizza
*pizza
,
815 GtkPizzaChild
*child
)
820 x
= child
->x
- pizza
->xoffset
;
821 y
= child
->y
- pizza
->yoffset
;
823 if (IS_ONSCREEN (x
,y
))
825 if (GTK_WIDGET_MAPPED (pizza
) &&
826 GTK_WIDGET_VISIBLE (child
->widget
))
828 if (!GTK_WIDGET_MAPPED (child
->widget
))
829 gtk_widget_map (child
->widget
);
832 if (GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
833 GTK_PRIVATE_UNSET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
837 if (!GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
838 GTK_PRIVATE_SET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
840 if (GTK_WIDGET_MAPPED (child
->widget
))
841 gtk_widget_unmap (child
->widget
);
846 gtk_pizza_allocate_child (GtkPizza
*pizza
,
847 GtkPizzaChild
*child
)
849 GtkAllocation allocation
;
850 GtkRequisition requisition
;
852 allocation
.x
= child
->x
- pizza
->xoffset
;
853 allocation
.y
= child
->y
- pizza
->yoffset
;
854 gtk_widget_get_child_requisition (child
->widget
, &requisition
);
855 allocation
.width
= requisition
.width
;
856 allocation
.height
= requisition
.height
;
858 gtk_widget_size_allocate (child
->widget
, &allocation
);
862 gtk_pizza_position_children (GtkPizza
*pizza
)
866 tmp_list
= pizza
->children
;
869 GtkPizzaChild
*child
= tmp_list
->data
;
870 tmp_list
= tmp_list
->next
;
872 gtk_pizza_position_child (pizza
, child
);
877 gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
880 GtkPizzaAdjData
*data
= cb_data
;
882 widget
->allocation
.x
+= data
->dx
;
883 widget
->allocation
.y
+= data
->dy
;
885 if (GTK_WIDGET_NO_WINDOW (widget
) && GTK_IS_CONTAINER (widget
))
887 gtk_container_forall (GTK_CONTAINER (widget
),
888 gtk_pizza_adjust_allocations_recurse
,
894 gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
899 GtkPizzaAdjData data
;
904 tmp_list
= pizza
->children
;
907 GtkPizzaChild
*child
= tmp_list
->data
;
908 tmp_list
= tmp_list
->next
;
910 child
->widget
->allocation
.x
+= dx
;
911 child
->widget
->allocation
.y
+= dy
;
913 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
914 GTK_IS_CONTAINER (child
->widget
))
916 gtk_container_forall (GTK_CONTAINER (child
->widget
),
917 gtk_pizza_adjust_allocations_recurse
,
925 /* Send a synthetic expose event to the widget
928 gtk_pizza_expose_area (GtkPizza
*pizza
,
929 gint x
, gint y
, gint width
, gint height
)
931 if (pizza
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
933 GdkEventExpose event
;
935 event
.type
= GDK_EXPOSE
;
936 event
.send_event
= TRUE
;
937 event
.window
= pizza
->bin_window
;
942 event
.area
.width
= width
;
943 event
.area
.height
= height
;
945 gdk_window_ref (event
.window
);
946 gtk_widget_event (GTK_WIDGET (pizza
), (GdkEvent
*)&event
);
947 gdk_window_unref (event
.window
);
951 /* This function is used to find events to process while scrolling
955 gtk_pizza_expose_predicate (Display
*display
,
959 if ((xevent
->type
== Expose
) ||
960 ((xevent
->xany
.window
== *(Window
*)arg
) &&
961 (xevent
->type
== ConfigureNotify
)))
967 /* This is the main routine to do the scrolling. Scrolling is
968 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
969 * a few modifications.
971 * The main improvement is that we keep track of whether we
972 * are obscured or not. If not, we ignore the generated expose
973 * events and instead do the exposes ourself, without having
974 * to wait for a roundtrip to the server. This also provides
975 * a limited form of expose-event compression, since we do
976 * the affected area as one big chunk.
980 gtk_pizza_scroll (GtkPizza
*pizza
, gint dx
, gint dy
)
987 widget
= GTK_WIDGET (pizza
);
989 pizza
->xoffset
+= dx
;
990 pizza
->yoffset
+= dy
;
992 if (!GTK_WIDGET_MAPPED (pizza
))
994 gtk_pizza_position_children (pizza
);
998 gtk_pizza_adjust_allocations (pizza
, -dx
, -dy
);
1000 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
1003 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
1010 w
= widget
->allocation
.width
- 2*border
;
1011 h
= widget
->allocation
.height
- 2*border
;
1017 gdk_window_resize (pizza
->bin_window
,
1020 gdk_window_move (pizza
->bin_window
, x
-dx
, y
);
1021 gdk_window_move_resize (pizza
->bin_window
, x
, y
, w
, h
);
1028 gtk_pizza_expose_area (pizza
,
1029 MAX ((gint
)w
- dx
, 0),
1038 gdk_window_move_resize (pizza
->bin_window
,
1043 gdk_window_move (pizza
->bin_window
, x
, y
);
1044 gdk_window_resize (pizza
->bin_window
, w
, h
);
1051 gtk_pizza_expose_area (pizza
,
1062 gdk_window_resize (pizza
->bin_window
, w
, h
+ dy
);
1063 gdk_window_move (pizza
->bin_window
, x
, y
-dy
);
1064 gdk_window_move_resize (pizza
->bin_window
,
1072 gtk_pizza_expose_area (pizza
,
1074 MAX ((gint
)h
- dy
, 0),
1082 gdk_window_move_resize (pizza
->bin_window
,
1083 x
, y
+dy
, w
, h
- dy
);
1084 gdk_window_move (pizza
->bin_window
, x
, y
);
1085 gdk_window_resize (pizza
->bin_window
, w
, h
);
1091 gtk_pizza_expose_area (pizza
,
1095 MIN (-dy
, (gint
)h
));
1098 gtk_pizza_position_children (pizza
);
1100 /* We have to make sure that all exposes from this scroll get
1101 * processed before we scroll again, or the expose events will
1102 * have invalid coordinates.
1104 * We also do expose events for other windows, since otherwise
1105 * their updating will fall behind the scrolling
1107 * This also avoids a problem in pre-1.0 GTK where filters don't
1108 * have access to configure events that were compressed.
1112 while (XCheckIfEvent(GDK_WINDOW_XDISPLAY (pizza
->bin_window
),
1114 gtk_pizza_expose_predicate
,
1115 (XPointer
)&GDK_WINDOW_XWINDOW (pizza
->bin_window
)))
1118 GtkWidget
*event_widget
;
1120 if ((xevent
.xany
.window
== GDK_WINDOW_XWINDOW (pizza
->bin_window
)) &&
1121 (gtk_pizza_filter (&xevent
, &event
, pizza
) == GDK_FILTER_REMOVE
))
1124 if (xevent
.type
== Expose
)
1126 event
.expose
.window
= gdk_window_lookup (xevent
.xany
.window
);
1127 gdk_window_get_user_data (event
.expose
.window
,
1128 (gpointer
*)&event_widget
);
1132 event
.expose
.type
= GDK_EXPOSE
;
1133 event
.expose
.area
.x
= xevent
.xexpose
.x
;
1134 event
.expose
.area
.y
= xevent
.xexpose
.y
;
1135 event
.expose
.area
.width
= xevent
.xexpose
.width
;
1136 event
.expose
.area
.height
= xevent
.xexpose
.height
;
1137 event
.expose
.count
= xevent
.xexpose
.count
;
1139 gdk_window_ref (event
.expose
.window
);
1140 gtk_widget_event (event_widget
, &event
);
1141 gdk_window_unref (event
.expose
.window
);
1147 /* The main event filter. Actually, we probably don't really need
1148 * to install this as a filter at all, since we are calling it
1149 * directly above in the expose-handling hack. But in case scrollbars
1150 * are fixed up in some manner...
1152 * This routine identifies expose events that are generated when
1153 * we've temporarily moved the bin_window_origin, and translates
1154 * them or discards them, depending on whether we are obscured
1157 static GdkFilterReturn
1158 gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
1165 xevent
= (XEvent
*)gdk_xevent
;
1167 pizza
= GTK_PIZZA (data
);
1169 switch (xevent
->type
)
1172 if (xevent
->xexpose
.serial
== pizza
->configure_serial
)
1174 if (pizza
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
1175 return GDK_FILTER_REMOVE
;
1178 xevent
->xexpose
.x
+= pizza
->scroll_x
;
1179 xevent
->xexpose
.y
+= pizza
->scroll_y
;
1186 case ConfigureNotify
:
1187 if ((xevent
->xconfigure
.x
!= 0) || (xevent
->xconfigure
.y
!= 0))
1189 pizza
->configure_serial
= xevent
->xconfigure
.serial
;
1190 pizza
->scroll_x
= xevent
->xconfigure
.x
;
1191 pizza
->scroll_y
= xevent
->xconfigure
.y
;
1196 return GDK_FILTER_CONTINUE
;
1199 /* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
1200 * there is no corresponding event in GTK, so we have
1201 * to get the events from a filter
1203 static GdkFilterReturn
1204 gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
1211 xevent
= (XEvent
*)gdk_xevent
;
1212 pizza
= GTK_PIZZA (data
);
1214 if (xevent
->type
== VisibilityNotify
)
1216 switch (xevent
->xvisibility
.state
)
1218 case VisibilityFullyObscured
:
1219 pizza
->visibility
= GDK_VISIBILITY_FULLY_OBSCURED
;
1222 case VisibilityPartiallyObscured
:
1223 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
1226 case VisibilityUnobscured
:
1227 pizza
->visibility
= GDK_VISIBILITY_UNOBSCURED
;
1231 return GDK_FILTER_REMOVE
;
1234 return GDK_FILTER_CONTINUE
;
1242 #endif /* __cplusplus */