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 _GtkMyFixedAdjData GtkMyFixedAdjData
;
25 typedef struct _GtkMyFixedChild GtkMyFixedChild
;
27 struct _GtkMyFixedAdjData
33 struct _GtkMyFixedChild
42 static void gtk_myfixed_class_init (GtkMyFixedClass
*klass
);
43 static void gtk_myfixed_init (GtkMyFixed
*myfixed
);
45 static void gtk_myfixed_realize (GtkWidget
*widget
);
46 static void gtk_myfixed_unrealize (GtkWidget
*widget
);
48 static void gtk_myfixed_map (GtkWidget
*widget
);
50 static void gtk_myfixed_size_request (GtkWidget
*widget
,
51 GtkRequisition
*requisition
);
52 static void gtk_myfixed_size_allocate (GtkWidget
*widget
,
53 GtkAllocation
*allocation
);
54 static void gtk_myfixed_draw (GtkWidget
*widget
,
56 static gint
gtk_myfixed_expose (GtkWidget
*widget
,
57 GdkEventExpose
*event
);
58 static void gtk_myfixed_add (GtkContainer
*container
,
60 static void gtk_myfixed_remove (GtkContainer
*container
,
62 static void gtk_myfixed_forall (GtkContainer
*container
,
63 gboolean include_internals
,
65 gpointer callback_data
);
67 static void gtk_myfixed_position_child (GtkMyFixed
*myfixed
,
68 GtkMyFixedChild
*child
);
69 static void gtk_myfixed_allocate_child (GtkMyFixed
*myfixed
,
70 GtkMyFixedChild
*child
);
71 static void gtk_myfixed_position_children (GtkMyFixed
*myfixed
);
73 static void gtk_myfixed_adjust_allocations_recurse (GtkWidget
*widget
,
75 static void gtk_myfixed_adjust_allocations (GtkMyFixed
*myfixed
,
80 static void gtk_myfixed_expose_area (GtkMyFixed
*myfixed
,
85 static void gtk_myfixed_adjustment_changed (GtkAdjustment
*adjustment
,
87 static GdkFilterReturn
gtk_myfixed_filter (GdkXEvent
*gdk_xevent
,
90 static GdkFilterReturn
gtk_myfixed_main_filter (GdkXEvent
*gdk_xevent
,
95 static GtkType
gtk_myfixed_child_type (GtkContainer
*container
);
97 static void gtk_myfixed_scroll_set_adjustments (GtkMyFixed
*myfixed
,
102 static GtkContainerClass
*parent_class
= NULL
;
103 static gboolean gravity_works
;
106 gtk_myfixed_get_type ()
108 static guint myfixed_type
= 0;
112 GtkTypeInfo myfixed_info
=
116 sizeof (GtkMyFixedClass
),
117 (GtkClassInitFunc
) gtk_myfixed_class_init
,
118 (GtkObjectInitFunc
) gtk_myfixed_init
,
119 /* reserved_1 */ NULL
,
120 /* reserved_2 */ NULL
,
121 (GtkClassInitFunc
) NULL
,
123 myfixed_type
= gtk_type_unique (gtk_container_get_type (), &myfixed_info
);
130 gtk_myfixed_class_init (GtkMyFixedClass
*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_myfixed_map
;
142 widget_class
->realize
= gtk_myfixed_realize
;
143 widget_class
->unrealize
= gtk_myfixed_unrealize
;
144 widget_class
->size_request
= gtk_myfixed_size_request
;
145 widget_class
->size_allocate
= gtk_myfixed_size_allocate
;
146 widget_class
->draw
= gtk_myfixed_draw
;
147 widget_class
->expose_event
= gtk_myfixed_expose
;
149 container_class
->add
= gtk_myfixed_add
;
150 container_class
->remove
= gtk_myfixed_remove
;
151 container_class
->forall
= gtk_myfixed_forall
;
153 container_class
->child_type
= gtk_myfixed_child_type
;
155 klass
->set_scroll_adjustments
= gtk_myfixed_scroll_set_adjustments
;
157 widget_class
->set_scroll_adjustments_signal
=
158 gtk_signal_new ("set_scroll_adjustments",
161 GTK_SIGNAL_OFFSET (GtkMyFixedClass
, set_scroll_adjustments
),
162 gtk_marshal_NONE__POINTER_POINTER
,
163 GTK_TYPE_NONE
, 2, GTK_TYPE_ADJUSTMENT
, GTK_TYPE_ADJUSTMENT
);
167 gtk_myfixed_child_type (GtkContainer
*container
)
169 return GTK_TYPE_WIDGET
;
173 gtk_myfixed_init (GtkMyFixed
*myfixed
)
175 GTK_WIDGET_UNSET_FLAGS (myfixed
, GTK_NO_WINDOW
);
177 myfixed
->shadow_type
= GTK_MYSHADOW_NONE
;
179 myfixed
->children
= NULL
;
182 myfixed
->height
= 20;
184 myfixed
->bin_window
= NULL
;
186 myfixed
->configure_serial
= 0;
187 myfixed
->scroll_x
= 0;
188 myfixed
->scroll_y
= 0;
189 myfixed
->visibility
= GDK_VISIBILITY_PARTIAL
;
191 myfixed
->clear_on_draw
= TRUE
;
199 myfixed
= gtk_type_new (gtk_myfixed_get_type ());
201 return GTK_WIDGET (myfixed
);
205 gtk_myfixed_scroll_set_adjustments (GtkMyFixed
*myfixed
,
209 /* We handle scrolling in the wxScrolledWindow, not here. */
213 gtk_myfixed_set_shadow_type (GtkMyFixed
*myfixed
,
214 GtkMyShadowType type
)
216 g_return_if_fail (myfixed
!= NULL
);
217 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
219 if ((GtkMyShadowType
) myfixed
->shadow_type
!= type
)
221 myfixed
->shadow_type
= type
;
223 if (GTK_WIDGET_VISIBLE (myfixed
))
225 gtk_widget_size_allocate (GTK_WIDGET (myfixed
), &(GTK_WIDGET (myfixed
)->allocation
));
226 gtk_widget_queue_draw (GTK_WIDGET (myfixed
));
232 gtk_my_fixed_set_clear (GtkMyFixed
*myfixed
,
235 g_return_if_fail (myfixed
!= NULL
);
236 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
238 myfixed
->clear_on_draw
= clear
;
242 gtk_myfixed_put (GtkMyFixed
*myfixed
,
249 GtkMyFixedChild
*child_info
;
251 g_return_if_fail (myfixed
!= NULL
);
252 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
253 g_return_if_fail (widget
!= NULL
);
255 child_info
= g_new (GtkMyFixedChild
, 1);
257 child_info
->widget
= widget
;
260 child_info
->width
= width
;
261 child_info
->height
= height
;
263 myfixed
->children
= g_list_append (myfixed
->children
, child_info
);
265 gtk_widget_set_parent (widget
, GTK_WIDGET (myfixed
));
267 if (GTK_WIDGET_REALIZED (myfixed
))
268 gtk_widget_set_parent_window (widget
, myfixed
->bin_window
);
270 if (!IS_ONSCREEN (x
, y
))
271 GTK_PRIVATE_SET_FLAG (widget
, GTK_IS_OFFSCREEN
);
273 if (GTK_WIDGET_REALIZED (myfixed
))
274 gtk_widget_realize (widget
);
276 gtk_widget_set_usize (widget
, width
, height
);
278 if (GTK_WIDGET_VISIBLE (myfixed
) && GTK_WIDGET_VISIBLE (widget
))
280 if (GTK_WIDGET_MAPPED (myfixed
))
281 gtk_widget_map (widget
);
283 gtk_widget_queue_resize (widget
);
288 gtk_myfixed_move (GtkMyFixed
*myfixed
,
293 GtkMyFixedChild
*child
;
296 g_return_if_fail (myfixed
!= NULL
);
297 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
298 g_return_if_fail (widget
!= NULL
);
300 children
= myfixed
->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 (myfixed
))
315 gtk_widget_queue_resize (widget
);
322 gtk_myfixed_resize (GtkMyFixed
*myfixed
,
327 GtkMyFixedChild
*child
;
330 g_return_if_fail (myfixed
!= NULL
);
331 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
332 g_return_if_fail (widget
!= NULL
);
334 children
= myfixed
->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 (myfixed
))
351 gtk_widget_queue_resize (widget
);
358 gtk_myfixed_set_size (GtkMyFixed
*myfixed
,
365 GtkMyFixedChild
*child
;
367 GtkAllocation child_allocation
;
369 g_return_if_fail (myfixed
!= NULL
);
370 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
371 g_return_if_fail (widget
!= NULL
);
373 children
= myfixed
->children
;
376 child
= children
->data
;
377 children
= children
->next
;
379 if (child
->widget
== widget
)
381 if ((child
->x
== x
) &&
383 (child
->width
== width
) &&
384 (child
->height
== height
)) return;
388 child
->width
= width
;
389 child
->height
= height
;
391 gtk_widget_set_usize (widget
, width
, height
);
393 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
394 gtk_widget_queue_resize (widget
);
402 gtk_myfixed_map (GtkWidget
*widget
)
405 GtkMyFixedChild
*child
;
408 g_return_if_fail (widget
!= NULL
);
409 g_return_if_fail (GTK_IS_MYFIXED (widget
));
411 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
412 myfixed
= GTK_MYFIXED (widget
);
414 children
= myfixed
->children
;
417 child
= children
->data
;
418 children
= children
->next
;
420 if ( GTK_WIDGET_VISIBLE (child
->widget
) &&
421 !GTK_WIDGET_MAPPED (child
->widget
) &&
422 !GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
424 gtk_widget_map (child
->widget
);
428 gdk_window_show (widget
->window
);
429 gdk_window_show (myfixed
->bin_window
);
433 gtk_myfixed_realize (GtkWidget
*widget
)
436 GdkWindowAttr attributes
;
437 gint attributes_mask
;
438 GtkMyFixedChild
*child
;
441 g_return_if_fail (widget
!= NULL
);
442 g_return_if_fail (GTK_IS_MYFIXED (widget
));
444 myfixed
= GTK_MYFIXED (widget
);
446 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
448 attributes
.window_type
= GDK_WINDOW_CHILD
;
450 attributes
.x
= widget
->allocation
.x
;
451 attributes
.y
= widget
->allocation
.y
;
452 attributes
.width
= widget
->allocation
.width
;
453 attributes
.height
= widget
->allocation
.height
;
455 if (myfixed
->shadow_type
== GTK_MYSHADOW_NONE
)
457 /* no border, no changes to sizes */
459 if (myfixed
->shadow_type
== GTK_MYSHADOW_THIN
)
461 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
464 attributes
.width
-= 2;
465 attributes
.height
-= 2;
468 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
469 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
472 attributes
.width
-= 4;
473 attributes
.height
-= 4;
477 if (attributes
.width
< 2) attributes
.width
= 2;
478 if (attributes
.height
< 2) attributes
.height
= 2;
480 attributes
.wclass
= GDK_INPUT_OUTPUT
;
481 attributes
.visual
= gtk_widget_get_visual (widget
);
482 attributes
.colormap
= gtk_widget_get_colormap (widget
);
483 attributes
.event_mask
=
484 GDK_VISIBILITY_NOTIFY_MASK
;
485 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
487 widget
->window
= gdk_window_new (gtk_widget_get_parent_window (widget
),
488 &attributes
, attributes_mask
);
489 gdk_window_set_user_data (widget
->window
, widget
);
494 attributes
.event_mask
= gtk_widget_get_events (widget
);
495 attributes
.event_mask
|=
497 GDK_POINTER_MOTION_MASK
|
498 GDK_POINTER_MOTION_HINT_MASK
|
499 GDK_BUTTON_MOTION_MASK
|
500 GDK_BUTTON1_MOTION_MASK
|
501 GDK_BUTTON2_MOTION_MASK
|
502 GDK_BUTTON3_MOTION_MASK
|
503 GDK_BUTTON_PRESS_MASK
|
504 GDK_BUTTON_RELEASE_MASK
|
506 GDK_KEY_RELEASE_MASK
|
507 GDK_ENTER_NOTIFY_MASK
|
508 GDK_LEAVE_NOTIFY_MASK
|
509 GDK_FOCUS_CHANGE_MASK
;
511 myfixed
->bin_window
= gdk_window_new (widget
->window
,
512 &attributes
, attributes_mask
);
513 gdk_window_set_user_data (myfixed
->bin_window
, widget
);
515 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
516 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
517 gtk_style_set_background (widget
->style
, myfixed
->bin_window
, GTK_STATE_NORMAL
);
519 /* add filters for intercepting visibility and expose events */
520 gdk_window_add_filter (widget
->window
, gtk_myfixed_main_filter
, myfixed
);
521 gdk_window_add_filter (myfixed
->bin_window
, gtk_myfixed_filter
, myfixed
);
523 /* we NEED gravity or we'll give up */
524 gravity_works
= gdk_window_set_static_gravities (myfixed
->bin_window
, TRUE
);
526 /* cannot be done before realisation */
527 children
= myfixed
->children
;
530 child
= children
->data
;
531 children
= children
->next
;
533 gtk_widget_set_parent_window (child
->widget
, myfixed
->bin_window
);
538 gtk_myfixed_unrealize (GtkWidget
*widget
)
542 g_return_if_fail (widget
!= NULL
);
543 g_return_if_fail (GTK_IS_MYFIXED (widget
));
545 myfixed
= GTK_MYFIXED (widget
);
547 gdk_window_set_user_data (myfixed
->bin_window
, NULL
);
548 gdk_window_destroy (myfixed
->bin_window
);
549 myfixed
->bin_window
= NULL
;
551 if (GTK_WIDGET_CLASS (parent_class
)->unrealize
)
552 (* GTK_WIDGET_CLASS (parent_class
)->unrealize
) (widget
);
556 gtk_myfixed_size_request (GtkWidget
*widget
,
557 GtkRequisition
*requisition
)
560 GtkMyFixedChild
*child
;
562 GtkRequisition child_requisition
;
564 g_return_if_fail (widget
!= NULL
);
565 g_return_if_fail (GTK_IS_MYFIXED (widget
));
566 g_return_if_fail (requisition
!= NULL
);
568 myfixed
= GTK_MYFIXED (widget
);
570 children
= myfixed
->children
;
573 child
= children
->data
;
574 children
= children
->next
;
576 if (GTK_WIDGET_VISIBLE (child
->widget
))
578 gtk_widget_size_request (child
->widget
, &child_requisition
);
582 /* request very little, I'm not sure if requesting nothing
583 will always have positive effects on stability... */
584 requisition
->width
= 2;
585 requisition
->height
= 2;
589 gtk_myfixed_size_allocate (GtkWidget
*widget
,
590 GtkAllocation
*allocation
)
595 GtkMyFixedChild
*child
;
596 GtkAllocation child_allocation
;
599 g_return_if_fail (widget
!= NULL
);
600 g_return_if_fail (GTK_IS_MYFIXED(widget
));
601 g_return_if_fail (allocation
!= NULL
);
603 myfixed
= GTK_MYFIXED (widget
);
605 widget
->allocation
= *allocation
;
607 if (myfixed
->shadow_type
== GTK_MYSHADOW_NONE
)
610 if (myfixed
->shadow_type
== GTK_MYSHADOW_THIN
)
615 x
= allocation
->x
+ border
;
616 y
= allocation
->y
+ border
;
617 w
= allocation
->width
- border
*2;
618 h
= allocation
->height
- border
*2;
620 if (GTK_WIDGET_REALIZED (widget
))
622 gdk_window_move_resize( widget
->window
, x
, y
, w
, h
);
623 gdk_window_move_resize( myfixed
->bin_window
, 0, 0, w
, h
);
626 children
= myfixed
->children
;
629 child
= children
->data
;
630 children
= children
->next
;
632 gtk_myfixed_position_child (myfixed
, child
);
633 gtk_myfixed_allocate_child (myfixed
, child
);
638 gtk_myfixed_draw (GtkWidget
*widget
,
642 GtkMyFixedChild
*child
;
643 GdkRectangle child_area
;
646 g_return_if_fail (widget
!= NULL
);
647 g_return_if_fail (GTK_IS_MYFIXED (widget
));
649 myfixed
= GTK_MYFIXED (widget
);
651 children
= myfixed
->children
;
652 if ( !(GTK_WIDGET_APP_PAINTABLE (widget
)) &&
653 (myfixed
->clear_on_draw
))
655 gdk_window_clear_area( myfixed
->bin_window
,
656 area
->x
, area
->y
, area
->width
, area
->height
);
661 child
= children
->data
;
662 children
= children
->next
;
664 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
665 gtk_widget_draw (child
->widget
, &child_area
);
670 gtk_myfixed_expose (GtkWidget
*widget
,
671 GdkEventExpose
*event
)
674 GtkMyFixedChild
*child
;
675 GdkEventExpose child_event
;
678 g_return_val_if_fail (widget
!= NULL
, FALSE
);
679 g_return_val_if_fail (GTK_IS_MYFIXED (widget
), FALSE
);
680 g_return_val_if_fail (event
!= NULL
, FALSE
);
682 myfixed
= GTK_MYFIXED (widget
);
685 if (event->window == widget->window)
687 gtk_myfixed_draw_border( myfixed );
692 if (event
->window
!= myfixed
->bin_window
)
695 children
= myfixed
->children
;
698 child
= children
->data
;
699 children
= children
->next
;
701 child_event
= *event
;
703 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
704 GTK_WIDGET_DRAWABLE (child
->widget
) &&
705 gtk_widget_intersect (child
->widget
, &event
->area
, &child_event
.area
))
707 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
715 gtk_myfixed_add (GtkContainer
*container
,
718 g_return_if_fail (container
!= NULL
);
719 g_return_if_fail (GTK_IS_MYFIXED (container
));
720 g_return_if_fail (widget
!= NULL
);
722 gtk_myfixed_put (GTK_MYFIXED (container
), widget
, 0, 0, 20, 20 );
726 gtk_myfixed_remove (GtkContainer
*container
,
730 GtkMyFixedChild
*child
;
733 g_return_if_fail (container
!= NULL
);
734 g_return_if_fail (GTK_IS_MYFIXED (container
));
735 g_return_if_fail (widget
!= NULL
);
737 myfixed
= GTK_MYFIXED (container
);
739 children
= myfixed
->children
;
742 child
= children
->data
;
744 if (child
->widget
== widget
)
746 gtk_widget_unparent (widget
);
748 /* security checks */
749 g_return_if_fail (GTK_IS_WIDGET (widget
));
751 myfixed
->children
= g_list_remove_link (myfixed
->children
, children
);
752 g_list_free (children
);
755 /* security checks */
756 g_return_if_fail (GTK_IS_WIDGET (widget
));
758 GTK_PRIVATE_UNSET_FLAG (widget
, GTK_IS_OFFSCREEN
);
763 children
= children
->next
;
768 gtk_myfixed_forall (GtkContainer
*container
,
769 gboolean include_internals
,
770 GtkCallback callback
,
771 gpointer callback_data
)
774 GtkMyFixedChild
*child
;
777 g_return_if_fail (container
!= NULL
);
778 g_return_if_fail (GTK_IS_MYFIXED (container
));
779 g_return_if_fail (callback
!= NULL
);
781 myfixed
= GTK_MYFIXED (container
);
783 children
= myfixed
->children
;
786 child
= children
->data
;
787 children
= children
->next
;
789 (* callback
) (child
->widget
, callback_data
);
794 /* Operations on children
798 gtk_myfixed_position_child (GtkMyFixed
*myfixed
,
799 GtkMyFixedChild
*child
)
804 x
= child
->x
- myfixed
->xoffset
;
805 y
= child
->y
- myfixed
->yoffset
;
807 if (IS_ONSCREEN (x
,y
))
809 if (GTK_WIDGET_MAPPED (myfixed
) &&
810 GTK_WIDGET_VISIBLE (child
->widget
))
812 if (!GTK_WIDGET_MAPPED (child
->widget
))
813 gtk_widget_map (child
->widget
);
816 if (GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
817 GTK_PRIVATE_UNSET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
821 if (!GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
822 GTK_PRIVATE_SET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
824 if (GTK_WIDGET_MAPPED (child
->widget
))
825 gtk_widget_unmap (child
->widget
);
830 gtk_myfixed_allocate_child (GtkMyFixed
*myfixed
,
831 GtkMyFixedChild
*child
)
833 GtkAllocation allocation
;
834 GtkRequisition requisition
;
836 allocation
.x
= child
->x
- myfixed
->xoffset
;
837 allocation
.y
= child
->y
- myfixed
->yoffset
;
838 gtk_widget_get_child_requisition (child
->widget
, &requisition
);
839 allocation
.width
= requisition
.width
;
840 allocation
.height
= requisition
.height
;
842 gtk_widget_size_allocate (child
->widget
, &allocation
);
846 gtk_myfixed_position_children (GtkMyFixed
*myfixed
)
850 tmp_list
= myfixed
->children
;
853 GtkMyFixedChild
*child
= tmp_list
->data
;
854 tmp_list
= tmp_list
->next
;
856 gtk_myfixed_position_child (myfixed
, child
);
861 gtk_myfixed_adjust_allocations_recurse (GtkWidget
*widget
,
864 GtkMyFixedAdjData
*data
= cb_data
;
866 widget
->allocation
.x
+= data
->dx
;
867 widget
->allocation
.y
+= data
->dy
;
869 if (GTK_WIDGET_NO_WINDOW (widget
) && GTK_IS_CONTAINER (widget
))
871 gtk_container_forall (GTK_CONTAINER (widget
),
872 gtk_myfixed_adjust_allocations_recurse
,
878 gtk_myfixed_adjust_allocations (GtkMyFixed
*myfixed
,
883 GtkMyFixedAdjData data
;
888 tmp_list
= myfixed
->children
;
891 GtkMyFixedChild
*child
= tmp_list
->data
;
892 tmp_list
= tmp_list
->next
;
894 child
->widget
->allocation
.x
+= dx
;
895 child
->widget
->allocation
.y
+= dy
;
897 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
898 GTK_IS_CONTAINER (child
->widget
))
899 gtk_container_forall (GTK_CONTAINER (child
->widget
),
900 gtk_myfixed_adjust_allocations_recurse
,
907 /* Send a synthetic expose event to the widget
910 gtk_myfixed_expose_area (GtkMyFixed
*myfixed
,
911 gint x
, gint y
, gint width
, gint height
)
913 if (myfixed
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
915 GdkEventExpose event
;
917 event
.type
= GDK_EXPOSE
;
918 event
.send_event
= TRUE
;
919 event
.window
= myfixed
->bin_window
;
924 event
.area
.width
= width
;
925 event
.area
.height
= height
;
927 gdk_window_ref (event
.window
);
928 gtk_widget_event (GTK_WIDGET (myfixed
), (GdkEvent
*)&event
);
929 gdk_window_unref (event
.window
);
933 /* This function is used to find events to process while scrolling
937 gtk_myfixed_expose_predicate (Display
*display
,
941 if ((xevent
->type
== Expose
) ||
942 ((xevent
->xany
.window
== *(Window
*)arg
) &&
943 (xevent
->type
== ConfigureNotify
)))
949 /* This is the main routine to do the scrolling. Scrolling is
950 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
951 * a few modifications.
953 * The main improvement is that we keep track of whether we
954 * are obscured or not. If not, we ignore the generated expose
955 * events and instead do the exposes ourself, without having
956 * to wait for a roundtrip to the server. This also provides
957 * a limited form of expose-event compression, since we do
958 * the affected area as one big chunk.
962 gtk_myfixed_scroll (GtkMyFixed
*myfixed
, gint dx
, gint dy
)
969 widget
= GTK_WIDGET (myfixed
);
971 myfixed
->xoffset
+= dx
;
972 myfixed
->yoffset
+= dy
;
974 if (!GTK_WIDGET_MAPPED (myfixed
))
976 gtk_myfixed_position_children (myfixed
);
980 gtk_myfixed_adjust_allocations (myfixed
, -dx
, -dy
);
982 if (myfixed
->shadow_type
== GTK_MYSHADOW_NONE
)
985 if (myfixed
->shadow_type
== GTK_MYSHADOW_THIN
)
992 w
= widget
->allocation
.width
- 2*border
;
993 h
= widget
->allocation
.height
- 2*border
;
999 gdk_window_resize (myfixed
->bin_window
,
1002 gdk_window_move (myfixed
->bin_window
, x
-dx
, y
);
1003 gdk_window_move_resize (myfixed
->bin_window
, x
, y
, w
, h
);
1010 gtk_myfixed_expose_area (myfixed
,
1011 MAX ((gint
)w
- dx
, 0),
1020 gdk_window_move_resize (myfixed
->bin_window
,
1025 gdk_window_move (myfixed
->bin_window
, x
, y
);
1026 gdk_window_resize (myfixed
->bin_window
, w
, h
);
1033 gtk_myfixed_expose_area (myfixed
,
1044 gdk_window_resize (myfixed
->bin_window
, w
, h
+ dy
);
1045 gdk_window_move (myfixed
->bin_window
, x
, y
-dy
);
1046 gdk_window_move_resize (myfixed
->bin_window
,
1054 gtk_myfixed_expose_area (myfixed
,
1056 MAX ((gint
)h
- dy
, 0),
1064 gdk_window_move_resize (myfixed
->bin_window
,
1065 x
, y
+dy
, w
, h
- dy
);
1066 gdk_window_move (myfixed
->bin_window
, x
, y
);
1067 gdk_window_resize (myfixed
->bin_window
, w
, h
);
1073 gtk_myfixed_expose_area (myfixed
,
1077 MIN (-dy
, (gint
)h
));
1080 gtk_myfixed_position_children (myfixed
);
1082 /* We have to make sure that all exposes from this scroll get
1083 * processed before we scroll again, or the expose events will
1084 * have invalid coordinates.
1086 * We also do expose events for other windows, since otherwise
1087 * their updating will fall behind the scrolling
1089 * This also avoids a problem in pre-1.0 GTK where filters don't
1090 * have access to configure events that were compressed.
1094 while (XCheckIfEvent(GDK_WINDOW_XDISPLAY (myfixed
->bin_window
),
1096 gtk_myfixed_expose_predicate
,
1097 (XPointer
)&GDK_WINDOW_XWINDOW (myfixed
->bin_window
)))
1100 GtkWidget
*event_widget
;
1102 if ((xevent
.xany
.window
== GDK_WINDOW_XWINDOW (myfixed
->bin_window
)) &&
1103 (gtk_myfixed_filter (&xevent
, &event
, myfixed
) == GDK_FILTER_REMOVE
))
1106 if (xevent
.type
== Expose
)
1108 event
.expose
.window
= gdk_window_lookup (xevent
.xany
.window
);
1109 gdk_window_get_user_data (event
.expose
.window
,
1110 (gpointer
*)&event_widget
);
1114 event
.expose
.type
= GDK_EXPOSE
;
1115 event
.expose
.area
.x
= xevent
.xexpose
.x
;
1116 event
.expose
.area
.y
= xevent
.xexpose
.y
;
1117 event
.expose
.area
.width
= xevent
.xexpose
.width
;
1118 event
.expose
.area
.height
= xevent
.xexpose
.height
;
1119 event
.expose
.count
= xevent
.xexpose
.count
;
1121 gdk_window_ref (event
.expose
.window
);
1122 gtk_widget_event (event_widget
, &event
);
1123 gdk_window_unref (event
.expose
.window
);
1129 /* The main event filter. Actually, we probably don't really need
1130 * to install this as a filter at all, since we are calling it
1131 * directly above in the expose-handling hack. But in case scrollbars
1132 * are fixed up in some manner...
1134 * This routine identifies expose events that are generated when
1135 * we've temporarily moved the bin_window_origin, and translates
1136 * them or discards them, depending on whether we are obscured
1139 static GdkFilterReturn
1140 gtk_myfixed_filter (GdkXEvent
*gdk_xevent
,
1145 GtkMyFixed
*myfixed
;
1147 xevent
= (XEvent
*)gdk_xevent
;
1148 myfixed
= GTK_MYFIXED (data
);
1150 switch (xevent
->type
)
1153 if (xevent
->xexpose
.serial
== myfixed
->configure_serial
)
1155 if (myfixed
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
1156 return GDK_FILTER_REMOVE
;
1159 xevent
->xexpose
.x
+= myfixed
->scroll_x
;
1160 xevent
->xexpose
.y
+= myfixed
->scroll_y
;
1167 case ConfigureNotify
:
1168 if ((xevent
->xconfigure
.x
!= 0) || (xevent
->xconfigure
.y
!= 0))
1170 myfixed
->configure_serial
= xevent
->xconfigure
.serial
;
1171 myfixed
->scroll_x
= xevent
->xconfigure
.x
;
1172 myfixed
->scroll_y
= xevent
->xconfigure
.y
;
1177 return GDK_FILTER_CONTINUE
;
1180 /* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
1181 * there is no corresponding event in GTK, so we have
1182 * to get the events from a filter
1184 static GdkFilterReturn
1185 gtk_myfixed_main_filter (GdkXEvent
*gdk_xevent
,
1190 GtkMyFixed
*myfixed
;
1192 xevent
= (XEvent
*)gdk_xevent
;
1193 myfixed
= GTK_MYFIXED (data
);
1195 if (xevent
->type
== VisibilityNotify
)
1197 switch (xevent
->xvisibility
.state
)
1199 case VisibilityFullyObscured
:
1200 myfixed
->visibility
= GDK_VISIBILITY_FULLY_OBSCURED
;
1203 case VisibilityPartiallyObscured
:
1204 myfixed
->visibility
= GDK_VISIBILITY_PARTIAL
;
1207 case VisibilityUnobscured
:
1208 myfixed
->visibility
= GDK_VISIBILITY_UNOBSCURED
;
1212 return GDK_FILTER_REMOVE
;
1216 return GDK_FILTER_CONTINUE
;
1224 #endif /* __cplusplus */