1 /* ///////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/win_gtk.c
3 // Purpose: Native GTK+ widget for wxWidgets, 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
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////// */
12 #define XCheckIfEvent XCHECKIFEVENT
15 #include "wx/platform.h"
16 #include "wx/gtk1/win_gtk.h"
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))
33 typedef struct _GtkPizzaAdjData GtkPizzaAdjData
;
35 struct _GtkPizzaAdjData
41 static void gtk_pizza_class_init (GtkPizzaClass
*klass
);
42 static void gtk_pizza_init (GtkPizza
*pizza
);
44 static void gtk_pizza_realize (GtkWidget
*widget
);
45 static void gtk_pizza_unrealize (GtkWidget
*widget
);
47 static void gtk_pizza_map (GtkWidget
*widget
);
49 static void gtk_pizza_size_request (GtkWidget
*widget
,
50 GtkRequisition
*requisition
);
51 static void gtk_pizza_size_allocate (GtkWidget
*widget
,
52 GtkAllocation
*allocation
);
53 static void gtk_pizza_draw (GtkWidget
*widget
,
55 static gint
gtk_pizza_expose (GtkWidget
*widget
,
56 GdkEventExpose
*event
);
57 static void gtk_pizza_style_set (GtkWidget
*widget
,
58 GtkStyle
*previous_style
);
59 static void gtk_pizza_add (GtkContainer
*container
,
61 static void gtk_pizza_remove (GtkContainer
*container
,
63 static void gtk_pizza_forall (GtkContainer
*container
,
64 gboolean include_internals
,
66 gpointer callback_data
);
68 static void gtk_pizza_allocate_child (GtkPizza
*pizza
,
69 GtkPizzaChild
*child
);
70 static void gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
73 static void gtk_pizza_position_child (GtkPizza
*pizza
,
74 GtkPizzaChild
*child
);
75 static void gtk_pizza_position_children (GtkPizza
*pizza
);
77 static GdkFilterReturn
gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
80 static GdkFilterReturn
gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
84 static GtkType
gtk_pizza_child_type (GtkContainer
*container
);
86 static void gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
91 static GtkContainerClass
*pizza_parent_class
= NULL
;
93 static gboolean gravity_works
;
98 static GtkType pizza_type
= 0;
102 GtkTypeInfo pizza_info
=
106 sizeof (GtkPizzaClass
),
107 (GtkClassInitFunc
) gtk_pizza_class_init
,
108 (GtkObjectInitFunc
) gtk_pizza_init
,
109 /* reserved_1 */ NULL
,
110 /* reserved_2 */ NULL
,
111 (GtkClassInitFunc
) NULL
,
113 pizza_type
= gtk_type_unique (gtk_container_get_type (), &pizza_info
);
120 gtk_pizza_class_init (GtkPizzaClass
*klass
)
122 GtkObjectClass
*object_class
;
123 GtkWidgetClass
*widget_class
;
124 GtkContainerClass
*container_class
;
126 object_class
= (GtkObjectClass
*) klass
;
127 widget_class
= (GtkWidgetClass
*) klass
;
128 container_class
= (GtkContainerClass
*) klass
;
129 pizza_parent_class
= gtk_type_class (GTK_TYPE_CONTAINER
);
131 widget_class
->map
= gtk_pizza_map
;
132 widget_class
->realize
= gtk_pizza_realize
;
133 widget_class
->unrealize
= gtk_pizza_unrealize
;
134 widget_class
->size_request
= gtk_pizza_size_request
;
135 widget_class
->size_allocate
= gtk_pizza_size_allocate
;
136 widget_class
->draw
= gtk_pizza_draw
;
137 widget_class
->expose_event
= gtk_pizza_expose
;
138 widget_class
->style_set
= gtk_pizza_style_set
;
140 container_class
->add
= gtk_pizza_add
;
141 container_class
->remove
= gtk_pizza_remove
;
142 container_class
->forall
= gtk_pizza_forall
;
144 container_class
->child_type
= gtk_pizza_child_type
;
146 klass
->set_scroll_adjustments
= gtk_pizza_scroll_set_adjustments
;
148 widget_class
->set_scroll_adjustments_signal
=
149 gtk_signal_new ("set_scroll_adjustments",
152 GTK_SIGNAL_OFFSET (GtkPizzaClass
, set_scroll_adjustments
),
153 gtk_marshal_NONE__POINTER_POINTER
,
154 GTK_TYPE_NONE
, 2, GTK_TYPE_ADJUSTMENT
, GTK_TYPE_ADJUSTMENT
);
158 gtk_pizza_child_type (GtkContainer
*container
)
160 return GTK_TYPE_WIDGET
;
164 gtk_pizza_init (GtkPizza
*pizza
)
166 GTK_WIDGET_UNSET_FLAGS (pizza
, GTK_NO_WINDOW
);
168 pizza
->shadow_type
= GTK_MYSHADOW_NONE
;
170 pizza
->children
= NULL
;
175 pizza
->bin_window
= NULL
;
180 pizza
->configure_serial
= 0;
183 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
185 pizza
->clear_on_draw
= TRUE
;
186 pizza
->use_filter
= TRUE
;
187 pizza
->external_expose
= FALSE
;
195 pizza
= gtk_type_new (gtk_pizza_get_type ());
197 return GTK_WIDGET (pizza
);
201 gtk_pizza_scroll_set_adjustments (GtkPizza
*pizza
,
205 /* We handle scrolling in the wxScrolledWindow, not here. */
209 gtk_pizza_set_shadow_type (GtkPizza
*pizza
,
210 GtkMyShadowType type
)
212 g_return_if_fail (pizza
!= NULL
);
213 g_return_if_fail (GTK_IS_PIZZA (pizza
));
215 if ((GtkMyShadowType
) pizza
->shadow_type
!= type
)
217 pizza
->shadow_type
= type
;
219 if (GTK_WIDGET_VISIBLE (pizza
))
221 gtk_widget_size_allocate (GTK_WIDGET (pizza
), &(GTK_WIDGET (pizza
)->allocation
));
222 gtk_widget_queue_draw (GTK_WIDGET (pizza
));
228 gtk_pizza_set_clear (GtkPizza
*pizza
,
231 g_return_if_fail (pizza
!= NULL
);
232 g_return_if_fail (GTK_IS_PIZZA (pizza
));
234 pizza
->clear_on_draw
= clear
;
238 gtk_pizza_set_filter (GtkPizza
*pizza
,
241 g_return_if_fail (pizza
!= NULL
);
242 g_return_if_fail (GTK_IS_PIZZA (pizza
));
244 pizza
->use_filter
= use
;
248 gtk_pizza_set_external (GtkPizza
*pizza
,
251 g_return_if_fail (pizza
!= NULL
);
252 g_return_if_fail (GTK_IS_PIZZA (pizza
));
254 pizza
->external_expose
= expose
;
258 gtk_pizza_put (GtkPizza
*pizza
,
265 GtkPizzaChild
*child_info
;
267 g_return_if_fail (pizza
!= NULL
);
268 g_return_if_fail (GTK_IS_PIZZA (pizza
));
269 g_return_if_fail (widget
!= NULL
);
271 child_info
= g_new (GtkPizzaChild
, 1);
273 child_info
->widget
= widget
;
276 child_info
->width
= width
;
277 child_info
->height
= height
;
279 pizza
->children
= g_list_append (pizza
->children
, child_info
);
281 if (GTK_WIDGET_REALIZED (pizza
))
282 gtk_widget_set_parent_window (widget
, pizza
->bin_window
);
284 gtk_widget_set_parent (widget
, GTK_WIDGET (pizza
));
286 if (!IS_ONSCREEN (x
, y
))
287 GTK_PRIVATE_SET_FLAG (widget
, GTK_IS_OFFSCREEN
);
289 gtk_widget_set_usize (widget
, width
, height
);
293 gtk_pizza_move (GtkPizza
*pizza
,
298 GtkPizzaChild
*child
;
301 g_return_if_fail (pizza
!= NULL
);
302 g_return_if_fail (GTK_IS_PIZZA (pizza
));
303 g_return_if_fail (widget
!= NULL
);
305 children
= pizza
->children
;
308 child
= children
->data
;
309 children
= children
->next
;
311 if (child
->widget
== widget
)
313 if ((child
->x
== x
) && (child
->y
== y
))
319 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
320 gtk_widget_queue_resize (widget
);
327 gtk_pizza_resize (GtkPizza
*pizza
,
332 GtkPizzaChild
*child
;
335 g_return_if_fail (pizza
!= NULL
);
336 g_return_if_fail (GTK_IS_PIZZA (pizza
));
337 g_return_if_fail (widget
!= NULL
);
339 children
= pizza
->children
;
342 child
= children
->data
;
343 children
= children
->next
;
345 if (child
->widget
== widget
)
347 if ((child
->width
== width
) && (child
->height
== height
))
350 child
->width
= width
;
351 child
->height
= height
;
353 gtk_widget_set_usize (widget
, width
, height
);
355 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
356 gtk_widget_queue_resize (widget
);
363 gtk_pizza_set_size (GtkPizza
*pizza
,
370 GtkPizzaChild
*child
;
373 g_return_if_fail (pizza
!= NULL
);
374 g_return_if_fail (GTK_IS_PIZZA (pizza
));
375 g_return_if_fail (widget
!= NULL
);
377 children
= pizza
->children
;
380 child
= children
->data
;
381 children
= children
->next
;
383 if (child
->widget
== widget
)
385 if ((child
->x
== x
) &&
387 (child
->width
== width
) &&
388 (child
->height
== height
)) return;
392 child
->width
= width
;
393 child
->height
= height
;
395 gtk_widget_set_usize (widget
, width
, height
);
397 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (pizza
))
398 gtk_widget_queue_resize (widget
);
406 gtk_pizza_child_resized (GtkPizza
*pizza
,
409 GtkPizzaChild
*child
;
412 g_return_val_if_fail (pizza
!= NULL
, FALSE
);
413 g_return_val_if_fail (GTK_IS_PIZZA (pizza
), FALSE
);
414 g_return_val_if_fail (widget
!= NULL
, FALSE
);
416 children
= pizza
->children
;
419 child
= children
->data
;
420 children
= children
->next
;
422 if (child
->widget
== widget
)
424 return ((child
->width
== widget
->allocation
.width
) &&
425 (child
->height
== widget
->allocation
.height
));
433 gtk_pizza_map (GtkWidget
*widget
)
436 GtkPizzaChild
*child
;
439 g_return_if_fail (widget
!= NULL
);
440 g_return_if_fail (GTK_IS_PIZZA (widget
));
442 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
443 pizza
= GTK_PIZZA (widget
);
445 children
= pizza
->children
;
448 child
= children
->data
;
449 children
= children
->next
;
451 if ( GTK_WIDGET_VISIBLE (child
->widget
) &&
452 !GTK_WIDGET_MAPPED (child
->widget
) &&
453 !GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
455 gtk_widget_map (child
->widget
);
459 gdk_window_show (widget
->window
);
460 gdk_window_show (pizza
->bin_window
);
464 gtk_pizza_realize (GtkWidget
*widget
)
467 GdkWindowAttr attributes
;
468 gint attributes_mask
;
469 GtkPizzaChild
*child
;
472 g_return_if_fail (widget
!= NULL
);
473 g_return_if_fail (GTK_IS_PIZZA (widget
));
475 pizza
= GTK_PIZZA (widget
);
476 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
478 attributes
.window_type
= GDK_WINDOW_CHILD
;
480 attributes
.x
= widget
->allocation
.x
;
481 attributes
.y
= widget
->allocation
.y
;
482 attributes
.width
= widget
->allocation
.width
;
483 attributes
.height
= widget
->allocation
.height
;
485 #ifndef __WXUNIVERSAL__
486 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
488 /* no border, no changes to sizes */
490 else if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
492 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
495 attributes
.width
-= 2;
496 attributes
.height
-= 2;
500 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
501 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
504 attributes
.width
-= 4;
505 attributes
.height
-= 4;
507 #endif /* __WXUNIVERSAL__ */
510 if (attributes
.width
< 2) attributes
.width
= 2;
511 if (attributes
.height
< 2) attributes
.height
= 2;
513 attributes
.wclass
= GDK_INPUT_OUTPUT
;
514 attributes
.visual
= gtk_widget_get_visual (widget
);
515 attributes
.colormap
= gtk_widget_get_colormap (widget
);
516 attributes
.event_mask
= GDK_VISIBILITY_NOTIFY_MASK
;
517 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
519 widget
->window
= gdk_window_new(gtk_widget_get_parent_window (widget
),
520 &attributes
, attributes_mask
);
521 gdk_window_set_user_data (widget
->window
, widget
);
526 attributes
.event_mask
= gtk_widget_get_events (widget
);
527 attributes
.event_mask
|= GDK_EXPOSURE_MASK
|
528 GDK_POINTER_MOTION_MASK
|
529 GDK_POINTER_MOTION_HINT_MASK
|
530 GDK_BUTTON_MOTION_MASK
|
531 GDK_BUTTON1_MOTION_MASK
|
532 GDK_BUTTON2_MOTION_MASK
|
533 GDK_BUTTON3_MOTION_MASK
|
534 GDK_BUTTON_PRESS_MASK
|
535 GDK_BUTTON_RELEASE_MASK
|
537 GDK_KEY_RELEASE_MASK
|
538 GDK_ENTER_NOTIFY_MASK
|
539 GDK_LEAVE_NOTIFY_MASK
|
540 GDK_FOCUS_CHANGE_MASK
;
542 pizza
->bin_window
= gdk_window_new(widget
->window
,
543 &attributes
, attributes_mask
);
544 gdk_window_set_user_data (pizza
->bin_window
, widget
);
546 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
547 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
548 gtk_style_set_background (widget
->style
, pizza
->bin_window
, GTK_STATE_NORMAL
);
551 gdk_window_set_back_pixmap( widget->window, NULL, FALSE );
552 gdk_window_set_back_pixmap( pizza->bin_window, NULL, FALSE );
555 /* add filters for intercepting visibility and expose events */
556 gdk_window_add_filter (widget
->window
, gtk_pizza_main_filter
, pizza
);
557 gdk_window_add_filter (pizza
->bin_window
, gtk_pizza_filter
, pizza
);
559 /* we NEED gravity or we'll give up */
560 gravity_works
= gdk_window_set_static_gravities (pizza
->bin_window
, TRUE
);
562 /* cannot be done before realisation */
563 children
= pizza
->children
;
566 child
= children
->data
;
567 children
= children
->next
;
569 gtk_widget_set_parent_window (child
->widget
, pizza
->bin_window
);
574 gtk_pizza_unrealize (GtkWidget
*widget
)
578 g_return_if_fail (widget
!= NULL
);
579 g_return_if_fail (GTK_IS_PIZZA (widget
));
581 pizza
= GTK_PIZZA (widget
);
583 gdk_window_set_user_data (pizza
->bin_window
, NULL
);
584 gdk_window_destroy (pizza
->bin_window
);
585 pizza
->bin_window
= NULL
;
587 if (GTK_WIDGET_CLASS (pizza_parent_class
)->unrealize
)
588 (* GTK_WIDGET_CLASS (pizza_parent_class
)->unrealize
) (widget
);
592 gtk_pizza_size_request (GtkWidget
*widget
,
593 GtkRequisition
*requisition
)
596 GtkPizzaChild
*child
;
598 GtkRequisition child_requisition
;
600 g_return_if_fail (widget
!= NULL
);
601 g_return_if_fail (GTK_IS_PIZZA (widget
));
602 g_return_if_fail (requisition
!= NULL
);
604 pizza
= GTK_PIZZA (widget
);
606 children
= pizza
->children
;
609 child
= children
->data
;
610 children
= children
->next
;
612 if (GTK_WIDGET_VISIBLE (child
->widget
))
614 gtk_widget_size_request (child
->widget
, &child_requisition
);
618 /* request very little, I'm not sure if requesting nothing
619 will always have positive effects on stability... */
620 requisition
->width
= 2;
621 requisition
->height
= 2;
625 gtk_pizza_size_allocate (GtkWidget
*widget
,
626 GtkAllocation
*allocation
)
631 GtkPizzaChild
*child
;
634 g_return_if_fail (widget
!= NULL
);
635 g_return_if_fail (GTK_IS_PIZZA(widget
));
636 g_return_if_fail (allocation
!= NULL
);
638 pizza
= GTK_PIZZA (widget
);
640 widget
->allocation
= *allocation
;
642 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
645 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
650 x
= allocation
->x
+ border
;
651 y
= allocation
->y
+ border
;
652 w
= allocation
->width
- border
*2;
653 h
= allocation
->height
- border
*2;
655 if (GTK_WIDGET_REALIZED (widget
))
657 gdk_window_move_resize( widget
->window
, x
, y
, w
, h
);
658 gdk_window_move_resize( pizza
->bin_window
, 0, 0, w
, h
);
661 children
= pizza
->children
;
664 child
= children
->data
;
665 children
= children
->next
;
667 gtk_pizza_position_child (pizza
, child
);
668 gtk_pizza_allocate_child (pizza
, child
);
673 gtk_pizza_draw (GtkWidget
*widget
,
677 GtkPizzaChild
*child
;
678 GdkRectangle child_area
;
681 g_return_if_fail (widget
!= NULL
);
682 g_return_if_fail (GTK_IS_PIZZA (widget
));
684 pizza
= GTK_PIZZA (widget
);
686 /* Sometimes, We handle all expose events in window.cpp now. */
687 if (pizza
->external_expose
)
690 children
= pizza
->children
;
691 if ( !(GTK_WIDGET_APP_PAINTABLE (widget
)) &&
692 (pizza
->clear_on_draw
))
694 gdk_window_clear_area( pizza
->bin_window
,
695 area
->x
, area
->y
, area
->width
, area
->height
);
700 child
= children
->data
;
701 children
= children
->next
;
703 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
704 gtk_widget_draw (child
->widget
, &child_area
);
709 gtk_pizza_expose (GtkWidget
*widget
,
710 GdkEventExpose
*event
)
713 GtkPizzaChild
*child
;
714 GdkEventExpose child_event
;
717 g_return_val_if_fail (widget
!= NULL
, FALSE
);
718 g_return_val_if_fail (GTK_IS_PIZZA (widget
), FALSE
);
719 g_return_val_if_fail (event
!= NULL
, FALSE
);
721 pizza
= GTK_PIZZA (widget
);
723 if (event
->window
!= pizza
->bin_window
)
726 /* We handle all expose events in window.cpp now. */
727 if (pizza
->external_expose
)
730 children
= pizza
->children
;
733 child
= children
->data
;
734 children
= children
->next
;
736 child_event
= *event
;
738 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
739 GTK_WIDGET_DRAWABLE (child
->widget
) &&
740 gtk_widget_intersect (child
->widget
, &event
->area
, &child_event
.area
))
742 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
750 gtk_pizza_style_set(GtkWidget
*widget
, GtkStyle
*previous_style
)
752 if (GTK_WIDGET_REALIZED(widget
))
754 gtk_style_set_background(widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
755 gtk_style_set_background(widget
->style
, GTK_PIZZA(widget
)->bin_window
, GTK_STATE_NORMAL
);
758 (* GTK_WIDGET_CLASS (pizza_parent_class
)->style_set
) (widget
, previous_style
);
762 gtk_pizza_add (GtkContainer
*container
,
765 g_return_if_fail (container
!= NULL
);
766 g_return_if_fail (GTK_IS_PIZZA (container
));
767 g_return_if_fail (widget
!= NULL
);
769 gtk_pizza_put (GTK_PIZZA (container
), widget
, 0, 0, 20, 20 );
773 gtk_pizza_remove (GtkContainer
*container
,
777 GtkPizzaChild
*child
;
780 g_return_if_fail (container
!= NULL
);
781 g_return_if_fail (GTK_IS_PIZZA (container
));
782 g_return_if_fail (widget
!= NULL
);
784 pizza
= GTK_PIZZA (container
);
786 children
= pizza
->children
;
789 child
= children
->data
;
791 if (child
->widget
== widget
)
793 gtk_widget_unparent (widget
);
795 /* security checks */
796 g_return_if_fail (GTK_IS_WIDGET (widget
));
798 pizza
->children
= g_list_remove_link (pizza
->children
, children
);
799 g_list_free (children
);
802 /* security checks */
803 g_return_if_fail (GTK_IS_WIDGET (widget
));
805 GTK_PRIVATE_UNSET_FLAG (widget
, GTK_IS_OFFSCREEN
);
810 children
= children
->next
;
815 gtk_pizza_forall (GtkContainer
*container
,
816 gboolean include_internals
,
817 GtkCallback callback
,
818 gpointer callback_data
)
821 GtkPizzaChild
*child
;
824 g_return_if_fail (container
!= NULL
);
825 g_return_if_fail (GTK_IS_PIZZA (container
));
826 g_return_if_fail (callback
!= (GtkCallback
)NULL
);
828 pizza
= GTK_PIZZA (container
);
830 children
= pizza
->children
;
833 child
= children
->data
;
834 children
= children
->next
;
836 (* callback
) (child
->widget
, callback_data
);
841 gtk_pizza_allocate_child (GtkPizza
*pizza
,
842 GtkPizzaChild
*child
)
844 GtkAllocation allocation
;
845 GtkRequisition requisition
;
847 allocation
.x
= child
->x
- pizza
->xoffset
;
848 allocation
.y
= child
->y
- pizza
->yoffset
;
849 gtk_widget_get_child_requisition (child
->widget
, &requisition
);
850 allocation
.width
= requisition
.width
;
851 allocation
.height
= requisition
.height
;
853 gtk_widget_size_allocate (child
->widget
, &allocation
);
857 gtk_pizza_adjust_allocations_recurse (GtkWidget
*widget
,
860 GtkPizzaAdjData
*data
= cb_data
;
862 widget
->allocation
.x
+= data
->dx
;
863 widget
->allocation
.y
+= data
->dy
;
865 if (GTK_WIDGET_NO_WINDOW (widget
) && GTK_IS_CONTAINER (widget
))
867 gtk_container_forall (GTK_CONTAINER (widget
),
868 gtk_pizza_adjust_allocations_recurse
,
874 gtk_pizza_adjust_allocations (GtkPizza
*pizza
,
879 GtkPizzaAdjData data
;
884 tmp_list
= pizza
->children
;
887 GtkPizzaChild
*child
= tmp_list
->data
;
888 tmp_list
= tmp_list
->next
;
890 child
->widget
->allocation
.x
+= dx
;
891 child
->widget
->allocation
.y
+= dy
;
893 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
894 GTK_IS_CONTAINER (child
->widget
))
896 gtk_container_forall (GTK_CONTAINER (child
->widget
),
897 gtk_pizza_adjust_allocations_recurse
,
904 gtk_pizza_position_child (GtkPizza
*pizza
,
905 GtkPizzaChild
*child
)
910 x
= child
->x
- pizza
->xoffset
;
911 y
= child
->y
- pizza
->yoffset
;
913 if (IS_ONSCREEN (x
,y
))
915 if (GTK_WIDGET_MAPPED (pizza
) &&
916 GTK_WIDGET_VISIBLE (child
->widget
))
918 if (!GTK_WIDGET_MAPPED (child
->widget
))
919 gtk_widget_map (child
->widget
);
922 if (GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
923 GTK_PRIVATE_UNSET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
927 if (!GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
928 GTK_PRIVATE_SET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
930 if (GTK_WIDGET_MAPPED (child
->widget
))
931 gtk_widget_unmap (child
->widget
);
936 gtk_pizza_position_children (GtkPizza
*pizza
)
940 tmp_list
= pizza
->children
;
943 GtkPizzaChild
*child
= tmp_list
->data
;
944 tmp_list
= tmp_list
->next
;
946 gtk_pizza_position_child (pizza
, child
);
950 /* This function is used to find events to process while scrolling */
952 gtk_pizza_expose_predicate (Display
*display
,
956 if ((xevent
->type
== Expose
) ||
957 ((xevent
->xany
.window
== *(Window
*)arg
) &&
958 (xevent
->type
== ConfigureNotify
)))
964 /* This is the main routine to do the scrolling. Scrolling is
965 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
966 * a few modifications.
968 * The main improvement is that we keep track of whether we
969 * are obscured or not. If not, we ignore the generated expose
970 * events and instead do the exposes ourself, without having
971 * to wait for a roundtrip to the server. This also provides
972 * a limited form of expose-event compression, since we do
973 * the affected area as one big chunk.
977 gtk_pizza_scroll (GtkPizza
*pizza
, gint dx
, gint dy
)
985 widget
= GTK_WIDGET (pizza
);
987 pizza
->xoffset
+= dx
;
988 pizza
->yoffset
+= dy
;
990 if (!GTK_WIDGET_MAPPED (pizza
))
992 gtk_pizza_position_children (pizza
);
996 gtk_pizza_adjust_allocations (pizza
, -dx
, -dy
);
998 if (pizza
->shadow_type
== GTK_MYSHADOW_NONE
)
1001 if (pizza
->shadow_type
== GTK_MYSHADOW_THIN
)
1008 w
= widget
->allocation
.width
- 2*border
;
1009 h
= widget
->allocation
.height
- 2*border
;
1015 gdk_window_resize (pizza
->bin_window
,
1018 gdk_window_move (pizza
->bin_window
, x
-dx
, y
);
1019 gdk_window_move_resize (pizza
->bin_window
, x
, y
, w
, h
);
1030 gdk_window_move_resize (pizza
->bin_window
,
1035 gdk_window_move (pizza
->bin_window
, x
, y
);
1036 gdk_window_resize (pizza
->bin_window
, w
, h
);
1048 gdk_window_resize (pizza
->bin_window
, w
, h
+ dy
);
1049 gdk_window_move (pizza
->bin_window
, x
, y
-dy
);
1050 gdk_window_move_resize (pizza
->bin_window
,
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
);
1073 gtk_pizza_position_children (pizza
);
1077 win
= GDK_WINDOW_XWINDOW (pizza
->bin_window
);
1078 while (XCheckIfEvent(GDK_WINDOW_XDISPLAY (pizza
->bin_window
),
1080 gtk_pizza_expose_predicate
,
1084 GtkWidget
*event_widget
;
1086 if ((xevent
.xany
.window
== GDK_WINDOW_XWINDOW (pizza
->bin_window
)) )
1087 gtk_pizza_filter (&xevent
, &event
, pizza
);
1089 if (xevent
.type
== Expose
)
1091 event
.expose
.window
= gdk_window_lookup (xevent
.xany
.window
);
1092 gdk_window_get_user_data (event
.expose
.window
,
1093 (gpointer
*)&event_widget
);
1097 event
.expose
.type
= GDK_EXPOSE
;
1098 event
.expose
.area
.x
= xevent
.xexpose
.x
;
1099 event
.expose
.area
.y
= xevent
.xexpose
.y
;
1100 event
.expose
.area
.width
= xevent
.xexpose
.width
;
1101 event
.expose
.area
.height
= xevent
.xexpose
.height
;
1102 event
.expose
.count
= xevent
.xexpose
.count
;
1104 gdk_window_ref (event
.expose
.window
);
1105 gtk_widget_event (event_widget
, &event
);
1106 gdk_window_unref (event
.expose
.window
);
1113 /* The main event filter. Actually, we probably don't really need
1114 * to install this as a filter at all, since we are calling it
1115 * directly above in the expose-handling hack. But in case scrollbars
1116 * are fixed up in some manner...
1118 * This routine identifies expose events that are generated when
1119 * we've temporarily moved the bin_window_origin, and translates
1120 * them or discards them, depending on whether we are obscured
1123 static GdkFilterReturn
1124 gtk_pizza_filter (GdkXEvent
*gdk_xevent
,
1131 xevent
= (XEvent
*)gdk_xevent
;
1133 pizza
= GTK_PIZZA (data
);
1135 if (!pizza
->use_filter
)
1136 return GDK_FILTER_CONTINUE
;
1138 switch (xevent
->type
)
1141 if (xevent
->xexpose
.serial
== pizza
->configure_serial
)
1143 xevent
->xexpose
.x
+= pizza
->scroll_x
;
1144 xevent
->xexpose
.y
+= pizza
->scroll_y
;
1148 case ConfigureNotify
:
1150 pizza
->configure_serial
= xevent
->xconfigure
.serial
;
1151 pizza
->scroll_x
= xevent
->xconfigure
.x
;
1152 pizza
->scroll_y
= xevent
->xconfigure
.y
;
1157 return GDK_FILTER_CONTINUE
;
1160 /* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
1161 * there is no corresponding event in GTK, so we have
1162 * to get the events from a filter
1164 static GdkFilterReturn
1165 gtk_pizza_main_filter (GdkXEvent
*gdk_xevent
,
1172 xevent
= (XEvent
*)gdk_xevent
;
1173 pizza
= GTK_PIZZA (data
);
1175 if (!pizza
->use_filter
)
1176 return GDK_FILTER_CONTINUE
;
1178 if (xevent
->type
== VisibilityNotify
)
1180 switch (xevent
->xvisibility
.state
)
1182 case VisibilityFullyObscured
:
1183 pizza
->visibility
= GDK_VISIBILITY_FULLY_OBSCURED
;
1186 case VisibilityPartiallyObscured
:
1187 pizza
->visibility
= GDK_VISIBILITY_PARTIAL
;
1190 case VisibilityUnobscured
:
1191 pizza
->visibility
= GDK_VISIBILITY_UNOBSCURED
;
1195 return GDK_FILTER_REMOVE
;
1198 return GDK_FILTER_CONTINUE
;
1203 #endif /* __cplusplus */