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
;
197 myfixed
= gtk_type_new (gtk_myfixed_get_type ());
199 return GTK_WIDGET (myfixed
);
203 gtk_myfixed_scroll_set_adjustments (GtkMyFixed
*myfixed
,
207 /* We handle scrolling in the wxScrolledWindow, not here. */
211 gtk_myfixed_set_shadow_type (GtkMyFixed
*myfixed
,
212 GtkMyShadowType type
)
214 g_return_if_fail (myfixed
!= NULL
);
215 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
217 if ((GtkMyShadowType
) myfixed
->shadow_type
!= type
)
219 myfixed
->shadow_type
= type
;
221 if (GTK_WIDGET_VISIBLE (myfixed
))
223 gtk_widget_size_allocate (GTK_WIDGET (myfixed
), &(GTK_WIDGET (myfixed
)->allocation
));
224 gtk_widget_queue_draw (GTK_WIDGET (myfixed
));
230 gtk_myfixed_put (GtkMyFixed
*myfixed
,
237 GtkMyFixedChild
*child_info
;
239 g_return_if_fail (myfixed
!= NULL
);
240 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
241 g_return_if_fail (widget
!= NULL
);
243 child_info
= g_new (GtkMyFixedChild
, 1);
245 child_info
->widget
= widget
;
248 child_info
->width
= width
;
249 child_info
->height
= height
;
251 myfixed
->children
= g_list_append (myfixed
->children
, child_info
);
253 gtk_widget_set_parent (widget
, GTK_WIDGET (myfixed
));
255 if (GTK_WIDGET_REALIZED (myfixed
))
256 gtk_widget_set_parent_window (widget
, myfixed
->bin_window
);
258 if (!IS_ONSCREEN (x
, y
))
259 GTK_PRIVATE_SET_FLAG (widget
, GTK_IS_OFFSCREEN
);
261 if (GTK_WIDGET_REALIZED (myfixed
))
262 gtk_widget_realize (widget
);
264 gtk_widget_set_usize (widget
, width
, height
);
266 if (GTK_WIDGET_VISIBLE (myfixed
) && GTK_WIDGET_VISIBLE (widget
))
268 if (GTK_WIDGET_MAPPED (myfixed
))
269 gtk_widget_map (widget
);
271 gtk_widget_queue_resize (widget
);
276 gtk_myfixed_move (GtkMyFixed
*myfixed
,
281 GtkMyFixedChild
*child
;
284 g_return_if_fail (myfixed
!= NULL
);
285 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
286 g_return_if_fail (widget
!= NULL
);
288 children
= myfixed
->children
;
291 child
= children
->data
;
292 children
= children
->next
;
294 if (child
->widget
== widget
)
296 if ((child
->x
== x
) && (child
->y
== y
))
302 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
303 gtk_widget_queue_resize (widget
);
310 gtk_myfixed_resize (GtkMyFixed
*myfixed
,
315 GtkMyFixedChild
*child
;
318 g_return_if_fail (myfixed
!= NULL
);
319 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
320 g_return_if_fail (widget
!= NULL
);
322 children
= myfixed
->children
;
325 child
= children
->data
;
326 children
= children
->next
;
328 if (child
->widget
== widget
)
330 if ((child
->width
== width
) && (child
->height
== height
))
333 child
->width
= width
;
334 child
->height
= height
;
336 gtk_widget_set_usize (widget
, width
, height
);
338 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
339 gtk_widget_queue_resize (widget
);
346 gtk_myfixed_set_size (GtkMyFixed
*myfixed
,
353 GtkMyFixedChild
*child
;
355 GtkAllocation child_allocation
;
357 g_return_if_fail (myfixed
!= NULL
);
358 g_return_if_fail (GTK_IS_MYFIXED (myfixed
));
359 g_return_if_fail (widget
!= NULL
);
361 children
= myfixed
->children
;
364 child
= children
->data
;
365 children
= children
->next
;
367 if (child
->widget
== widget
)
369 if ((child
->x
== x
) &&
371 (child
->width
== width
) &&
372 (child
->height
== height
)) return;
376 child
->width
= width
;
377 child
->height
= height
;
379 gtk_widget_set_usize (widget
, width
, height
);
381 if (GTK_WIDGET_VISIBLE (widget
) && GTK_WIDGET_VISIBLE (myfixed
))
382 gtk_widget_queue_resize (widget
);
390 gtk_myfixed_map (GtkWidget
*widget
)
393 GtkMyFixedChild
*child
;
396 g_return_if_fail (widget
!= NULL
);
397 g_return_if_fail (GTK_IS_MYFIXED (widget
));
399 GTK_WIDGET_SET_FLAGS (widget
, GTK_MAPPED
);
400 myfixed
= GTK_MYFIXED (widget
);
402 children
= myfixed
->children
;
405 child
= children
->data
;
406 children
= children
->next
;
408 if ( GTK_WIDGET_VISIBLE (child
->widget
) &&
409 !GTK_WIDGET_MAPPED (child
->widget
) &&
410 !GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
412 gtk_widget_map (child
->widget
);
416 gdk_window_show (widget
->window
);
417 gdk_window_show (myfixed
->bin_window
);
421 gtk_myfixed_realize (GtkWidget
*widget
)
424 GdkWindowAttr attributes
;
425 gint attributes_mask
;
426 GtkMyFixedChild
*child
;
429 g_return_if_fail (widget
!= NULL
);
430 g_return_if_fail (GTK_IS_MYFIXED (widget
));
432 myfixed
= GTK_MYFIXED (widget
);
434 GTK_WIDGET_SET_FLAGS (widget
, GTK_REALIZED
);
436 attributes
.window_type
= GDK_WINDOW_CHILD
;
438 attributes
.x
= widget
->allocation
.x
;
439 attributes
.y
= widget
->allocation
.y
;
440 attributes
.width
= widget
->allocation
.width
;
441 attributes
.height
= widget
->allocation
.height
;
443 if (myfixed
->shadow_type
== GTK_MYSHADOW_NONE
)
445 /* no border, no changes to sizes */
447 if (myfixed
->shadow_type
== GTK_MYSHADOW_THIN
)
449 /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
452 attributes
.width
-= 2;
453 attributes
.height
-= 2;
456 /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
457 /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
460 attributes
.width
-= 4;
461 attributes
.height
-= 4;
465 if (attributes
.width
< 2) attributes
.width
= 2;
466 if (attributes
.height
< 2) attributes
.height
= 2;
468 attributes
.wclass
= GDK_INPUT_OUTPUT
;
469 attributes
.visual
= gtk_widget_get_visual (widget
);
470 attributes
.colormap
= gtk_widget_get_colormap (widget
);
471 attributes
.event_mask
=
472 GDK_VISIBILITY_NOTIFY_MASK
;
473 attributes_mask
= GDK_WA_X
| GDK_WA_Y
| GDK_WA_VISUAL
| GDK_WA_COLORMAP
;
475 widget
->window
= gdk_window_new (gtk_widget_get_parent_window (widget
),
476 &attributes
, attributes_mask
);
477 gdk_window_set_user_data (widget
->window
, widget
);
482 attributes
.event_mask
= gtk_widget_get_events (widget
);
483 attributes
.event_mask
|=
485 GDK_POINTER_MOTION_MASK
|
486 GDK_POINTER_MOTION_HINT_MASK
|
487 GDK_BUTTON_MOTION_MASK
|
488 GDK_BUTTON1_MOTION_MASK
|
489 GDK_BUTTON2_MOTION_MASK
|
490 GDK_BUTTON3_MOTION_MASK
|
491 GDK_BUTTON_PRESS_MASK
|
492 GDK_BUTTON_RELEASE_MASK
|
494 GDK_KEY_RELEASE_MASK
|
495 GDK_ENTER_NOTIFY_MASK
|
496 GDK_LEAVE_NOTIFY_MASK
|
497 GDK_FOCUS_CHANGE_MASK
;
499 myfixed
->bin_window
= gdk_window_new (widget
->window
,
500 &attributes
, attributes_mask
);
501 gdk_window_set_user_data (myfixed
->bin_window
, widget
);
503 widget
->style
= gtk_style_attach (widget
->style
, widget
->window
);
504 gtk_style_set_background (widget
->style
, widget
->window
, GTK_STATE_NORMAL
);
505 gtk_style_set_background (widget
->style
, myfixed
->bin_window
, GTK_STATE_NORMAL
);
507 /* add filters for intercepting visibility and expose events */
508 gdk_window_add_filter (widget
->window
, gtk_myfixed_main_filter
, myfixed
);
509 gdk_window_add_filter (myfixed
->bin_window
, gtk_myfixed_filter
, myfixed
);
511 /* we NEED gravity or we'll give up */
512 gravity_works
= gdk_window_set_static_gravities (myfixed
->bin_window
, TRUE
);
514 /* cannot be done before realisation */
515 children
= myfixed
->children
;
518 child
= children
->data
;
519 children
= children
->next
;
521 gtk_widget_set_parent_window (child
->widget
, myfixed
->bin_window
);
526 gtk_myfixed_unrealize (GtkWidget
*widget
)
530 g_return_if_fail (widget
!= NULL
);
531 g_return_if_fail (GTK_IS_MYFIXED (widget
));
533 myfixed
= GTK_MYFIXED (widget
);
535 gdk_window_set_user_data (myfixed
->bin_window
, NULL
);
536 gdk_window_destroy (myfixed
->bin_window
);
537 myfixed
->bin_window
= NULL
;
539 if (GTK_WIDGET_CLASS (parent_class
)->unrealize
)
540 (* GTK_WIDGET_CLASS (parent_class
)->unrealize
) (widget
);
544 gtk_myfixed_size_request (GtkWidget
*widget
,
545 GtkRequisition
*requisition
)
548 GtkMyFixedChild
*child
;
550 GtkRequisition child_requisition
;
552 g_return_if_fail (widget
!= NULL
);
553 g_return_if_fail (GTK_IS_MYFIXED (widget
));
554 g_return_if_fail (requisition
!= NULL
);
556 myfixed
= GTK_MYFIXED (widget
);
558 children
= myfixed
->children
;
561 child
= children
->data
;
562 children
= children
->next
;
564 if (GTK_WIDGET_VISIBLE (child
->widget
))
566 gtk_widget_size_request (child
->widget
, &child_requisition
);
570 /* request very little, I'm not sure if requesting nothing
571 will always have positive effects on stability... */
572 requisition
->width
= 2;
573 requisition
->height
= 2;
577 gtk_myfixed_size_allocate (GtkWidget
*widget
,
578 GtkAllocation
*allocation
)
583 GtkMyFixedChild
*child
;
584 GtkAllocation child_allocation
;
587 g_return_if_fail (widget
!= NULL
);
588 g_return_if_fail (GTK_IS_MYFIXED(widget
));
589 g_return_if_fail (allocation
!= NULL
);
591 myfixed
= GTK_MYFIXED (widget
);
593 children
= myfixed
->children
;
596 child
= children
->data
;
597 children
= children
->next
;
599 gtk_myfixed_position_child (myfixed
, child
);
600 gtk_myfixed_allocate_child (myfixed
, child
);
603 widget
->allocation
= *allocation
;
605 if (myfixed
->shadow_type
== GTK_MYSHADOW_NONE
)
608 if (myfixed
->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( myfixed
->bin_window
, 0, 0, w
, h
);
626 gtk_myfixed_draw (GtkWidget
*widget
,
630 GtkMyFixedChild
*child
;
631 GdkRectangle child_area
;
634 g_return_if_fail (widget
!= NULL
);
635 g_return_if_fail (GTK_IS_MYFIXED (widget
));
637 myfixed
= GTK_MYFIXED (widget
);
639 children
= myfixed
->children
;
640 if ( !(GTK_WIDGET_APP_PAINTABLE (widget
)) )
642 gdk_window_clear_area( myfixed
->bin_window
,
643 area
->x
, area
->y
, area
->width
, area
->height
);
648 child
= children
->data
;
649 children
= children
->next
;
651 if (gtk_widget_intersect (child
->widget
, area
, &child_area
))
652 gtk_widget_draw (child
->widget
, &child_area
);
658 gtk_myfixed_draw_border (GtkMyFixed *myfixed)
662 widget = GTK_WIDGET(myfixed);
664 if (myfixed->shadow_type == GTK_MYSHADOW_NONE)
667 if (myfixed->shadow_type == GTK_MYSHADOW_OUT)
669 gtk_draw_shadow( widget->style,
674 widget->allocation.width,
675 widget->allocation.height );
679 if (myfixed->shadow_type == GTK_MYSHADOW_IN)
681 gtk_draw_shadow( widget->style,
686 widget->allocation.width,
687 widget->allocation.height );
691 if (myfixed->shadow_type == GTK_MYSHADOW_THIN)
694 gc = gdk_gc_new( widget->window );
695 gdk_gc_set_foreground( gc, &widget->style->black );
696 gdk_draw_rectangle( widget->window, gc, FALSE,
698 widget->allocation.width-1,
699 widget->allocation.height-1 );
707 gtk_myfixed_expose (GtkWidget
*widget
,
708 GdkEventExpose
*event
)
711 GtkMyFixedChild
*child
;
712 GdkEventExpose child_event
;
715 g_return_val_if_fail (widget
!= NULL
, FALSE
);
716 g_return_val_if_fail (GTK_IS_MYFIXED (widget
), FALSE
);
717 g_return_val_if_fail (event
!= NULL
, FALSE
);
719 myfixed
= GTK_MYFIXED (widget
);
722 if (event->window == widget->window)
724 gtk_myfixed_draw_border( myfixed );
729 if (event
->window
!= myfixed
->bin_window
)
732 children
= myfixed
->children
;
735 child
= children
->data
;
736 children
= children
->next
;
738 child_event
= *event
;
740 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
741 GTK_WIDGET_DRAWABLE (child
->widget
) &&
742 gtk_widget_intersect (child
->widget
, &event
->area
, &child_event
.area
))
744 gtk_widget_event (child
->widget
, (GdkEvent
*) &child_event
);
752 gtk_myfixed_add (GtkContainer
*container
,
755 g_return_if_fail (container
!= NULL
);
756 g_return_if_fail (GTK_IS_MYFIXED (container
));
757 g_return_if_fail (widget
!= NULL
);
759 gtk_myfixed_put (GTK_MYFIXED (container
), widget
, 0, 0, 20, 20 );
763 gtk_myfixed_remove (GtkContainer
*container
,
767 GtkMyFixedChild
*child
;
770 g_return_if_fail (container
!= NULL
);
771 g_return_if_fail (GTK_IS_MYFIXED (container
));
772 g_return_if_fail (widget
!= NULL
);
774 myfixed
= GTK_MYFIXED (container
);
776 children
= myfixed
->children
;
779 child
= children
->data
;
781 if (child
->widget
== widget
)
783 gtk_widget_unparent (widget
);
785 /* security checks */
786 g_return_if_fail (GTK_IS_WIDGET (widget
));
788 myfixed
->children
= g_list_remove_link (myfixed
->children
, children
);
789 g_list_free (children
);
792 /* security checks */
793 g_return_if_fail (GTK_IS_WIDGET (widget
));
795 GTK_PRIVATE_UNSET_FLAG (widget
, GTK_IS_OFFSCREEN
);
800 children
= children
->next
;
805 gtk_myfixed_forall (GtkContainer
*container
,
806 gboolean include_internals
,
807 GtkCallback callback
,
808 gpointer callback_data
)
811 GtkMyFixedChild
*child
;
814 g_return_if_fail (container
!= NULL
);
815 g_return_if_fail (GTK_IS_MYFIXED (container
));
816 g_return_if_fail (callback
!= NULL
);
818 myfixed
= GTK_MYFIXED (container
);
820 children
= myfixed
->children
;
823 child
= children
->data
;
824 children
= children
->next
;
826 (* callback
) (child
->widget
, callback_data
);
831 /* Operations on children
835 gtk_myfixed_position_child (GtkMyFixed
*myfixed
,
836 GtkMyFixedChild
*child
)
841 x
= child
->x
- myfixed
->xoffset
;
842 y
= child
->y
- myfixed
->yoffset
;
844 if (IS_ONSCREEN (x
,y
))
846 if (GTK_WIDGET_MAPPED (myfixed
) &&
847 GTK_WIDGET_VISIBLE (child
->widget
))
849 if (!GTK_WIDGET_MAPPED (child
->widget
))
850 gtk_widget_map (child
->widget
);
853 if (GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
854 GTK_PRIVATE_UNSET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
858 if (!GTK_WIDGET_IS_OFFSCREEN (child
->widget
))
859 GTK_PRIVATE_SET_FLAG (child
->widget
, GTK_IS_OFFSCREEN
);
861 if (GTK_WIDGET_MAPPED (child
->widget
))
862 gtk_widget_unmap (child
->widget
);
867 gtk_myfixed_allocate_child (GtkMyFixed
*myfixed
,
868 GtkMyFixedChild
*child
)
870 GtkAllocation allocation
;
871 GtkRequisition requisition
;
873 allocation
.x
= child
->x
- myfixed
->xoffset
;
874 allocation
.y
= child
->y
- myfixed
->yoffset
;
875 gtk_widget_get_child_requisition (child
->widget
, &requisition
);
876 allocation
.width
= requisition
.width
;
877 allocation
.height
= requisition
.height
;
879 gtk_widget_size_allocate (child
->widget
, &allocation
);
883 gtk_myfixed_position_children (GtkMyFixed
*myfixed
)
887 tmp_list
= myfixed
->children
;
890 GtkMyFixedChild
*child
= tmp_list
->data
;
891 tmp_list
= tmp_list
->next
;
893 gtk_myfixed_position_child (myfixed
, child
);
898 gtk_myfixed_adjust_allocations_recurse (GtkWidget
*widget
,
901 GtkMyFixedAdjData
*data
= cb_data
;
903 widget
->allocation
.x
+= data
->dx
;
904 widget
->allocation
.y
+= data
->dy
;
906 if (GTK_WIDGET_NO_WINDOW (widget
) &&
907 GTK_IS_CONTAINER (widget
))
908 gtk_container_forall (GTK_CONTAINER (widget
),
909 gtk_myfixed_adjust_allocations_recurse
,
914 gtk_myfixed_adjust_allocations (GtkMyFixed
*myfixed
,
919 GtkMyFixedAdjData data
;
924 tmp_list
= myfixed
->children
;
927 GtkMyFixedChild
*child
= tmp_list
->data
;
928 tmp_list
= tmp_list
->next
;
930 child
->widget
->allocation
.x
+= dx
;
931 child
->widget
->allocation
.y
+= dy
;
933 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
934 GTK_IS_CONTAINER (child
->widget
))
935 gtk_container_forall (GTK_CONTAINER (child
->widget
),
936 gtk_myfixed_adjust_allocations_recurse
,
943 /* Send a synthetic expose event to the widget
946 gtk_myfixed_expose_area (GtkMyFixed
*myfixed
,
947 gint x
, gint y
, gint width
, gint height
)
949 if (myfixed
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
951 GdkEventExpose event
;
953 event
.type
= GDK_EXPOSE
;
954 event
.send_event
= TRUE
;
955 event
.window
= myfixed
->bin_window
;
960 event
.area
.width
= width
;
961 event
.area
.height
= height
;
963 gdk_window_ref (event
.window
);
964 gtk_widget_event (GTK_WIDGET (myfixed
), (GdkEvent
*)&event
);
965 gdk_window_unref (event
.window
);
969 /* This function is used to find events to process while scrolling
973 gtk_myfixed_expose_predicate (Display
*display
,
977 if ((xevent
->type
== Expose
) ||
978 ((xevent
->xany
.window
== *(Window
*)arg
) &&
979 (xevent
->type
== ConfigureNotify
)))
985 /* This is the main routine to do the scrolling. Scrolling is
986 * done by "Guffaw" scrolling, as in the Mozilla XFE, with
987 * a few modifications.
989 * The main improvement is that we keep track of whether we
990 * are obscured or not. If not, we ignore the generated expose
991 * events and instead do the exposes ourself, without having
992 * to wait for a roundtrip to the server. This also provides
993 * a limited form of expose-event compression, since we do
994 * the affected area as one big chunk.
998 gtk_myfixed_scroll (GtkMyFixed
*myfixed
, gint dx
, gint dy
)
1003 gint x
,y
,w
,h
,border
;
1005 widget
= GTK_WIDGET (myfixed
);
1007 myfixed
->xoffset
+= dx
;
1008 myfixed
->yoffset
+= dy
;
1010 if (!GTK_WIDGET_MAPPED (myfixed
))
1012 gtk_myfixed_position_children (myfixed
);
1016 gtk_myfixed_adjust_allocations (myfixed
, -dx
, -dy
);
1018 if (myfixed
->shadow_type
== GTK_MYSHADOW_NONE
)
1021 if (myfixed
->shadow_type
== GTK_MYSHADOW_THIN
)
1028 w
= widget
->allocation
.width
- 2*border
;
1029 h
= widget
->allocation
.height
- 2*border
;
1035 gdk_window_resize (myfixed
->bin_window
,
1038 gdk_window_move (myfixed
->bin_window
, x
-dx
, y
);
1039 gdk_window_move_resize (myfixed
->bin_window
, x
, y
, w
, h
);
1046 gtk_myfixed_expose_area (myfixed
,
1047 MAX ((gint
)w
- dx
, 0),
1056 gdk_window_move_resize (myfixed
->bin_window
,
1061 gdk_window_move (myfixed
->bin_window
, x
, y
);
1062 gdk_window_resize (myfixed
->bin_window
, w
, h
);
1069 gtk_myfixed_expose_area (myfixed
,
1080 gdk_window_resize (myfixed
->bin_window
, w
, h
+ dy
);
1081 gdk_window_move (myfixed
->bin_window
, x
, y
-dy
);
1082 gdk_window_move_resize (myfixed
->bin_window
,
1090 gtk_myfixed_expose_area (myfixed
,
1092 MAX ((gint
)h
- dy
, 0),
1100 gdk_window_move_resize (myfixed
->bin_window
,
1101 x
, y
+dy
, w
, h
- dy
);
1102 gdk_window_move (myfixed
->bin_window
, x
, y
);
1103 gdk_window_resize (myfixed
->bin_window
, w
, h
);
1109 gtk_myfixed_expose_area (myfixed
,
1113 MIN (-dy
, (gint
)h
));
1116 gtk_myfixed_position_children (myfixed
);
1118 /* We have to make sure that all exposes from this scroll get
1119 * processed before we scroll again, or the expose events will
1120 * have invalid coordinates.
1122 * We also do expose events for other windows, since otherwise
1123 * their updating will fall behind the scrolling
1125 * This also avoids a problem in pre-1.0 GTK where filters don't
1126 * have access to configure events that were compressed.
1130 while (XCheckIfEvent(GDK_WINDOW_XDISPLAY (myfixed
->bin_window
),
1132 gtk_myfixed_expose_predicate
,
1133 (XPointer
)&GDK_WINDOW_XWINDOW (myfixed
->bin_window
)))
1136 GtkWidget
*event_widget
;
1138 if ((xevent
.xany
.window
== GDK_WINDOW_XWINDOW (myfixed
->bin_window
)) &&
1139 (gtk_myfixed_filter (&xevent
, &event
, myfixed
) == GDK_FILTER_REMOVE
))
1142 if (xevent
.type
== Expose
)
1144 event
.expose
.window
= gdk_window_lookup (xevent
.xany
.window
);
1145 gdk_window_get_user_data (event
.expose
.window
,
1146 (gpointer
*)&event_widget
);
1150 event
.expose
.type
= GDK_EXPOSE
;
1151 event
.expose
.area
.x
= xevent
.xexpose
.x
;
1152 event
.expose
.area
.y
= xevent
.xexpose
.y
;
1153 event
.expose
.area
.width
= xevent
.xexpose
.width
;
1154 event
.expose
.area
.height
= xevent
.xexpose
.height
;
1155 event
.expose
.count
= xevent
.xexpose
.count
;
1157 gdk_window_ref (event
.expose
.window
);
1158 gtk_widget_event (event_widget
, &event
);
1159 gdk_window_unref (event
.expose
.window
);
1165 /* The main event filter. Actually, we probably don't really need
1166 * to install this as a filter at all, since we are calling it
1167 * directly above in the expose-handling hack. But in case scrollbars
1168 * are fixed up in some manner...
1170 * This routine identifies expose events that are generated when
1171 * we've temporarily moved the bin_window_origin, and translates
1172 * them or discards them, depending on whether we are obscured
1175 static GdkFilterReturn
1176 gtk_myfixed_filter (GdkXEvent
*gdk_xevent
,
1181 GtkMyFixed
*myfixed
;
1183 xevent
= (XEvent
*)gdk_xevent
;
1184 myfixed
= GTK_MYFIXED (data
);
1186 switch (xevent
->type
)
1189 if (xevent
->xexpose
.serial
== myfixed
->configure_serial
)
1191 if (myfixed
->visibility
== GDK_VISIBILITY_UNOBSCURED
)
1192 return GDK_FILTER_REMOVE
;
1195 xevent
->xexpose
.x
+= myfixed
->scroll_x
;
1196 xevent
->xexpose
.y
+= myfixed
->scroll_y
;
1203 case ConfigureNotify
:
1204 if ((xevent
->xconfigure
.x
!= 0) || (xevent
->xconfigure
.y
!= 0))
1206 myfixed
->configure_serial
= xevent
->xconfigure
.serial
;
1207 myfixed
->scroll_x
= xevent
->xconfigure
.x
;
1208 myfixed
->scroll_y
= xevent
->xconfigure
.y
;
1213 return GDK_FILTER_CONTINUE
;
1216 /* Although GDK does have a GDK_VISIBILITY_NOTIFY event,
1217 * there is no corresponding event in GTK, so we have
1218 * to get the events from a filter
1220 static GdkFilterReturn
1221 gtk_myfixed_main_filter (GdkXEvent
*gdk_xevent
,
1226 GtkMyFixed
*myfixed
;
1228 xevent
= (XEvent
*)gdk_xevent
;
1229 myfixed
= GTK_MYFIXED (data
);
1231 if (xevent
->type
== VisibilityNotify
)
1233 switch (xevent
->xvisibility
.state
)
1235 case VisibilityFullyObscured
:
1236 myfixed
->visibility
= GDK_VISIBILITY_FULLY_OBSCURED
;
1239 case VisibilityPartiallyObscured
:
1240 myfixed
->visibility
= GDK_VISIBILITY_PARTIAL
;
1243 case VisibilityUnobscured
:
1244 myfixed
->visibility
= GDK_VISIBILITY_UNOBSCURED
;
1248 return GDK_FILTER_REMOVE
;
1252 return GDK_FILTER_CONTINUE
;
1260 #endif /* __cplusplus */