1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
19 * GtkLayout: Widget for scrolling of arbitrary-sized areas.
21 * Copyright Owen Taylor, 1998
25 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
33 #include "gtklayout.h"
37 #include "gtkprivate.h"
39 #include "gtkmarshalers.h"
40 #include "gtkscrollable.h"
45 * @Short_description: Infinite scrollable area containing child widgets
46 * and/or custom drawing
48 * @See_also: #GtkDrawingArea, #GtkScrolledWindow
50 * #GtkLayout is similar to #GtkDrawingArea in that it's a "blank slate"
51 * and doesn't do anything but paint a blank background by default. It's
52 * different in that it supports scrolling natively (you can add it to a
53 * #GtkScrolledWindow), and it can contain child widgets, since it's a
54 * #GtkContainer. However if you're just going to draw, a #GtkDrawingArea
55 * is a better choice since it has lower overhead.
57 * When handling expose events on a #GtkLayout, you must draw to
58 * GTK_LAYOUT (layout)->bin_window, rather than to
59 * GTK_WIDGET (layout)->window, as you would for a drawing
64 typedef struct _GtkLayoutChild GtkLayoutChild;
66 struct _GtkLayoutPrivate
72 GtkAdjustment *hadjustment;
73 GtkAdjustment *vadjustment;
75 /* GtkScrollablePolicy needs to be checked when
76 * driving the scrollable adjustment values */
77 guint hscroll_policy : 1;
78 guint vscroll_policy : 1;
82 GdkVisibilityState visibility;
83 GdkWindow *bin_window;
93 struct _GtkLayoutChild {
115 static void gtk_layout_get_property (GObject *object,
119 static void gtk_layout_set_property (GObject *object,
123 static void gtk_layout_finalize (GObject *object);
124 static void gtk_layout_realize (GtkWidget *widget);
125 static void gtk_layout_unrealize (GtkWidget *widget);
126 static void gtk_layout_map (GtkWidget *widget);
127 static void gtk_layout_get_preferred_width (GtkWidget *widget,
130 static void gtk_layout_get_preferred_height (GtkWidget *widget,
133 static void gtk_layout_size_allocate (GtkWidget *widget,
134 GtkAllocation *allocation);
135 static gint gtk_layout_draw (GtkWidget *widget,
137 static void gtk_layout_add (GtkContainer *container,
139 static void gtk_layout_remove (GtkContainer *container,
141 static void gtk_layout_forall (GtkContainer *container,
142 gboolean include_internals,
143 GtkCallback callback,
144 gpointer callback_data);
145 static void gtk_layout_set_child_property (GtkContainer *container,
150 static void gtk_layout_get_child_property (GtkContainer *container,
155 static void gtk_layout_allocate_child (GtkLayout *layout,
156 GtkLayoutChild *child);
157 static void gtk_layout_adjustment_changed (GtkAdjustment *adjustment,
159 static void gtk_layout_style_set (GtkWidget *widget,
160 GtkStyle *old_style);
162 static void gtk_layout_set_hadjustment_values (GtkLayout *layout);
163 static void gtk_layout_set_vadjustment_values (GtkLayout *layout);
165 G_DEFINE_TYPE_WITH_CODE (GtkLayout, gtk_layout, GTK_TYPE_CONTAINER,
166 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
172 * @hadjustment: (allow-none): horizontal scroll adjustment, or %NULL
173 * @vadjustment: (allow-none): vertical scroll adjustment, or %NULL
175 * Creates a new #GtkLayout. Unless you have a specific adjustment
176 * you'd like the layout to use for scrolling, pass %NULL for
177 * @hadjustment and @vadjustment.
179 * Return value: a new #GtkLayout
183 gtk_layout_new (GtkAdjustment *hadjustment,
184 GtkAdjustment *vadjustment)
188 layout = g_object_new (GTK_TYPE_LAYOUT,
189 "hadjustment", hadjustment,
190 "vadjustment", vadjustment,
193 return GTK_WIDGET (layout);
197 * gtk_layout_get_bin_window:
198 * @layout: a #GtkLayout
200 * Retrieve the bin window of the layout used for drawing operations.
202 * Return value: (transfer none): a #GdkWindow
207 gtk_layout_get_bin_window (GtkLayout *layout)
209 g_return_val_if_fail (GTK_IS_LAYOUT (layout), NULL);
211 return layout->priv->bin_window;
215 * gtk_layout_get_hadjustment:
216 * @layout: a #GtkLayout
218 * This function should only be called after the layout has been
219 * placed in a #GtkScrolledWindow or otherwise configured for
220 * scrolling. It returns the #GtkAdjustment used for communication
221 * between the horizontal scrollbar and @layout.
223 * See #GtkScrolledWindow, #GtkScrollbar, #GtkAdjustment for details.
225 * Return value: (transfer none): horizontal scroll adjustment
227 * Deprecated: 3.0: Use gtk_scrollable_get_hadjustment()
230 gtk_layout_get_hadjustment (GtkLayout *layout)
232 g_return_val_if_fail (GTK_IS_LAYOUT (layout), NULL);
234 return layout->priv->hadjustment;
237 * gtk_layout_get_vadjustment:
238 * @layout: a #GtkLayout
240 * This function should only be called after the layout has been
241 * placed in a #GtkScrolledWindow or otherwise configured for
242 * scrolling. It returns the #GtkAdjustment used for communication
243 * between the vertical scrollbar and @layout.
245 * See #GtkScrolledWindow, #GtkScrollbar, #GtkAdjustment for details.
247 * Return value: (transfer none): vertical scroll adjustment
249 * Deprecated: 3.0: Use gtk_scrollable_get_vadjustment()
252 gtk_layout_get_vadjustment (GtkLayout *layout)
254 g_return_val_if_fail (GTK_IS_LAYOUT (layout), NULL);
256 return layout->priv->vadjustment;
260 gtk_layout_set_hadjustment_values (GtkLayout *layout)
262 GtkLayoutPrivate *priv = layout->priv;
263 GtkAllocation allocation;
264 GtkAdjustment *adj = priv->hadjustment;
269 gtk_widget_get_allocation (GTK_WIDGET (layout), &allocation);
271 old_value = gtk_adjustment_get_value (adj);
272 new_upper = MAX (allocation.width, priv->width);
277 "page-size", (gdouble)allocation.width,
278 "step-increment", allocation.width * 0.1,
279 "page-increment", allocation.width * 0.9,
282 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
283 if (new_value != old_value)
284 gtk_adjustment_set_value (adj, new_value);
288 gtk_layout_set_vadjustment_values (GtkLayout *layout)
290 GtkAllocation allocation;
291 GtkAdjustment *adj = layout->priv->vadjustment;
296 gtk_widget_get_allocation (GTK_WIDGET (layout), &allocation);
298 old_value = gtk_adjustment_get_value (adj);
299 new_upper = MAX (allocation.height, layout->priv->height);
304 "page-size", (gdouble)allocation.height,
305 "step-increment", allocation.height * 0.1,
306 "page-increment", allocation.height * 0.9,
309 new_value = CLAMP (old_value, 0, new_upper - allocation.height);
310 if (new_value != old_value)
311 gtk_adjustment_set_value (adj, new_value);
315 gtk_layout_finalize (GObject *object)
317 GtkLayout *layout = GTK_LAYOUT (object);
318 GtkLayoutPrivate *priv = layout->priv;
320 g_object_unref (priv->hadjustment);
321 g_object_unref (priv->vadjustment);
323 G_OBJECT_CLASS (gtk_layout_parent_class)->finalize (object);
327 * gtk_layout_set_hadjustment:
328 * @layout: a #GtkLayout
329 * @adjustment: (allow-none): new scroll adjustment
331 * Sets the horizontal scroll adjustment for the layout.
333 * See #GtkScrolledWindow, #GtkScrollbar, #GtkAdjustment for details.
335 * Deprecated: 3.0: Use gtk_scrollable_set_hadjustment()
338 gtk_layout_set_hadjustment (GtkLayout *layout,
339 GtkAdjustment *adjustment)
341 GtkLayoutPrivate *priv;
343 g_return_if_fail (GTK_IS_LAYOUT (layout));
344 g_return_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment));
348 if (adjustment && priv->hadjustment == adjustment)
351 if (priv->hadjustment != NULL)
353 g_signal_handlers_disconnect_by_func (priv->hadjustment,
354 gtk_layout_adjustment_changed,
356 g_object_unref (priv->hadjustment);
359 if (adjustment == NULL)
360 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
362 g_signal_connect (adjustment, "value-changed",
363 G_CALLBACK (gtk_layout_adjustment_changed), layout);
364 priv->hadjustment = g_object_ref_sink (adjustment);
365 gtk_layout_set_hadjustment_values (layout);
367 g_object_notify (G_OBJECT (layout), "hadjustment");
372 * gtk_layout_set_vadjustment:
373 * @layout: a #GtkLayout
374 * @adjustment: (allow-none): new scroll adjustment
376 * Sets the vertical scroll adjustment for the layout.
378 * See #GtkScrolledWindow, #GtkScrollbar, #GtkAdjustment for details.
380 * Deprecated: 3.0: Use gtk_scrollable_set_vadjustment()
383 gtk_layout_set_vadjustment (GtkLayout *layout,
384 GtkAdjustment *adjustment)
386 GtkLayoutPrivate *priv;
388 g_return_if_fail (GTK_IS_LAYOUT (layout));
389 g_return_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment));
393 if (adjustment && priv->vadjustment == adjustment)
396 if (priv->vadjustment != NULL)
398 g_signal_handlers_disconnect_by_func (priv->vadjustment,
399 gtk_layout_adjustment_changed,
401 g_object_unref (priv->vadjustment);
404 if (adjustment == NULL)
405 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
407 g_signal_connect (adjustment, "value-changed",
408 G_CALLBACK (gtk_layout_adjustment_changed), layout);
409 priv->vadjustment = g_object_ref_sink (adjustment);
410 gtk_layout_set_vadjustment_values (layout);
412 g_object_notify (G_OBJECT (layout), "vadjustment");
415 static GtkLayoutChild*
416 get_child (GtkLayout *layout,
419 GtkLayoutPrivate *priv = layout->priv;
422 children = priv->children;
425 GtkLayoutChild *child;
427 child = children->data;
428 children = children->next;
430 if (child->widget == widget)
439 * @layout: a #GtkLayout
440 * @child_widget: child widget
441 * @x: X position of child widget
442 * @y: Y position of child widget
444 * Adds @child_widget to @layout, at position (@x,@y).
445 * @layout becomes the new parent container of @child_widget.
449 gtk_layout_put (GtkLayout *layout,
450 GtkWidget *child_widget,
454 GtkLayoutPrivate *priv;
455 GtkLayoutChild *child;
457 g_return_if_fail (GTK_IS_LAYOUT (layout));
458 g_return_if_fail (GTK_IS_WIDGET (child_widget));
462 child = g_new (GtkLayoutChild, 1);
464 child->widget = child_widget;
468 priv->children = g_list_append (priv->children, child);
470 if (gtk_widget_get_realized (GTK_WIDGET (layout)))
471 gtk_widget_set_parent_window (child->widget, priv->bin_window);
473 gtk_widget_set_parent (child_widget, GTK_WIDGET (layout));
477 gtk_layout_move_internal (GtkLayout *layout,
484 GtkLayoutChild *child;
486 child = get_child (layout, widget);
490 gtk_widget_freeze_child_notify (widget);
495 gtk_widget_child_notify (widget, "x");
501 gtk_widget_child_notify (widget, "y");
504 gtk_widget_thaw_child_notify (widget);
506 if (gtk_widget_get_visible (widget) &&
507 gtk_widget_get_visible (GTK_WIDGET (layout)))
508 gtk_widget_queue_resize (widget);
513 * @layout: a #GtkLayout
514 * @child_widget: a current child of @layout
515 * @x: X position to move to
516 * @y: Y position to move to
518 * Moves a current child of @layout to a new position.
522 gtk_layout_move (GtkLayout *layout,
523 GtkWidget *child_widget,
527 g_return_if_fail (GTK_IS_LAYOUT (layout));
528 g_return_if_fail (GTK_IS_WIDGET (child_widget));
529 g_return_if_fail (gtk_widget_get_parent (child_widget) == GTK_WIDGET (layout));
531 gtk_layout_move_internal (layout, child_widget, TRUE, x, TRUE, y);
535 * gtk_layout_set_size:
536 * @layout: a #GtkLayout
537 * @width: width of entire scrollable area
538 * @height: height of entire scrollable area
540 * Sets the size of the scrollable area of the layout.
544 gtk_layout_set_size (GtkLayout *layout,
548 GtkLayoutPrivate *priv;
551 g_return_if_fail (GTK_IS_LAYOUT (layout));
554 widget = GTK_WIDGET (layout);
556 g_object_freeze_notify (G_OBJECT (layout));
557 if (width != priv->width)
560 g_object_notify (G_OBJECT (layout), "width");
562 if (height != priv->height)
564 priv->height = height;
565 g_object_notify (G_OBJECT (layout), "height");
567 g_object_thaw_notify (G_OBJECT (layout));
569 if (gtk_widget_get_realized (widget))
571 GtkAllocation allocation;
573 gtk_widget_get_allocation (widget, &allocation);
574 width = MAX (width, allocation.width);
575 height = MAX (height, allocation.height);
576 gdk_window_resize (priv->bin_window, width, height);
579 gtk_layout_set_hadjustment_values (layout);
580 gtk_layout_set_vadjustment_values (layout);
584 * gtk_layout_get_size:
585 * @layout: a #GtkLayout
586 * @width: (allow-none): location to store the width set on @layout, or %NULL
587 * @height: (allow-none): location to store the height set on @layout, or %NULL
589 * Gets the size that has been set on the layout, and that determines
590 * the total extents of the layout's scrollbar area. See
591 * gtk_layout_set_size ().
594 gtk_layout_get_size (GtkLayout *layout,
598 GtkLayoutPrivate *priv;
600 g_return_if_fail (GTK_IS_LAYOUT (layout));
605 *width = priv->width;
607 *height = priv->height;
610 /* Basic Object handling procedures
613 gtk_layout_class_init (GtkLayoutClass *class)
615 GObjectClass *gobject_class;
616 GtkWidgetClass *widget_class;
617 GtkContainerClass *container_class;
619 gobject_class = (GObjectClass*) class;
620 widget_class = (GtkWidgetClass*) class;
621 container_class = (GtkContainerClass*) class;
623 gobject_class->set_property = gtk_layout_set_property;
624 gobject_class->get_property = gtk_layout_get_property;
625 gobject_class->finalize = gtk_layout_finalize;
627 container_class->set_child_property = gtk_layout_set_child_property;
628 container_class->get_child_property = gtk_layout_get_child_property;
630 gtk_container_class_install_child_property (container_class,
632 g_param_spec_int ("x",
634 P_("X position of child widget"),
638 GTK_PARAM_READWRITE));
640 gtk_container_class_install_child_property (container_class,
642 g_param_spec_int ("y",
644 P_("Y position of child widget"),
648 GTK_PARAM_READWRITE));
650 /* Scrollable interface */
651 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
652 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
653 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
654 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
656 g_object_class_install_property (gobject_class,
658 g_param_spec_uint ("width",
660 P_("The width of the layout"),
664 GTK_PARAM_READWRITE));
665 g_object_class_install_property (gobject_class,
667 g_param_spec_uint ("height",
669 P_("The height of the layout"),
673 GTK_PARAM_READWRITE));
674 widget_class->realize = gtk_layout_realize;
675 widget_class->unrealize = gtk_layout_unrealize;
676 widget_class->map = gtk_layout_map;
677 widget_class->get_preferred_width = gtk_layout_get_preferred_width;
678 widget_class->get_preferred_height = gtk_layout_get_preferred_height;
679 widget_class->size_allocate = gtk_layout_size_allocate;
680 widget_class->draw = gtk_layout_draw;
681 widget_class->style_set = gtk_layout_style_set;
683 container_class->add = gtk_layout_add;
684 container_class->remove = gtk_layout_remove;
685 container_class->forall = gtk_layout_forall;
687 g_type_class_add_private (class, sizeof (GtkLayoutPrivate));
691 gtk_layout_get_property (GObject *object,
696 GtkLayout *layout = GTK_LAYOUT (object);
697 GtkLayoutPrivate *priv = layout->priv;
701 case PROP_HADJUSTMENT:
702 g_value_set_object (value, priv->hadjustment);
704 case PROP_VADJUSTMENT:
705 g_value_set_object (value, priv->vadjustment);
707 case PROP_HSCROLL_POLICY:
708 g_value_set_enum (value, priv->hscroll_policy);
710 case PROP_VSCROLL_POLICY:
711 g_value_set_enum (value, priv->vscroll_policy);
714 g_value_set_uint (value, priv->width);
717 g_value_set_uint (value, priv->height);
720 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
726 gtk_layout_set_property (GObject *object,
731 GtkLayout *layout = GTK_LAYOUT (object);
732 GtkLayoutPrivate *priv = layout->priv;
736 case PROP_HADJUSTMENT:
737 gtk_layout_set_hadjustment (layout,
738 (GtkAdjustment*) g_value_get_object (value));
740 case PROP_VADJUSTMENT:
741 gtk_layout_set_vadjustment (layout,
742 (GtkAdjustment*) g_value_get_object (value));
744 case PROP_HSCROLL_POLICY:
745 priv->hscroll_policy = g_value_get_enum (value);
746 gtk_widget_queue_resize (GTK_WIDGET (layout));
748 case PROP_VSCROLL_POLICY:
749 priv->vscroll_policy = g_value_get_enum (value);
750 gtk_widget_queue_resize (GTK_WIDGET (layout));
753 gtk_layout_set_size (layout, g_value_get_uint (value),
757 gtk_layout_set_size (layout, priv->width,
758 g_value_get_uint (value));
761 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
767 gtk_layout_set_child_property (GtkContainer *container,
776 gtk_layout_move_internal (GTK_LAYOUT (container),
778 TRUE, g_value_get_int (value),
782 gtk_layout_move_internal (GTK_LAYOUT (container),
785 TRUE, g_value_get_int (value));
788 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
794 gtk_layout_get_child_property (GtkContainer *container,
800 GtkLayoutChild *layout_child;
802 layout_child = get_child (GTK_LAYOUT (container), child);
807 g_value_set_int (value, layout_child->x);
810 g_value_set_int (value, layout_child->y);
813 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
819 gtk_layout_init (GtkLayout *layout)
821 GtkLayoutPrivate *priv;
823 layout->priv = G_TYPE_INSTANCE_GET_PRIVATE (layout,
828 priv->children = NULL;
833 priv->hadjustment = NULL;
834 priv->vadjustment = NULL;
836 priv->bin_window = NULL;
840 priv->visibility = GDK_VISIBILITY_PARTIAL;
842 priv->freeze_count = 0;
849 gtk_layout_realize (GtkWidget *widget)
851 GtkLayout *layout = GTK_LAYOUT (widget);
852 GtkLayoutPrivate *priv = layout->priv;
853 GtkAllocation allocation;
855 GdkWindowAttr attributes;
857 gint attributes_mask;
859 gtk_widget_set_realized (widget, TRUE);
861 gtk_widget_get_allocation (widget, &allocation);
863 attributes.window_type = GDK_WINDOW_CHILD;
864 attributes.x = allocation.x;
865 attributes.y = allocation.y;
866 attributes.width = allocation.width;
867 attributes.height = allocation.height;
868 attributes.wclass = GDK_INPUT_OUTPUT;
869 attributes.visual = gtk_widget_get_visual (widget);
870 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
872 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
874 window = gdk_window_new (gtk_widget_get_parent_window (widget),
875 &attributes, attributes_mask);
876 gtk_widget_set_window (widget, window);
877 gdk_window_set_user_data (window, widget);
879 gtk_widget_get_allocation (widget, &allocation);
881 attributes.x = - priv->hadjustment->value,
882 attributes.y = - priv->vadjustment->value;
883 attributes.width = MAX (priv->width, allocation.width);
884 attributes.height = MAX (priv->height, allocation.height);
885 attributes.event_mask = GDK_EXPOSURE_MASK | GDK_SCROLL_MASK |
886 gtk_widget_get_events (widget);
888 priv->bin_window = gdk_window_new (window,
889 &attributes, attributes_mask);
890 gdk_window_set_user_data (priv->bin_window, widget);
892 gtk_widget_style_attach (widget);
893 gtk_style_set_background (gtk_widget_get_style (widget), priv->bin_window, GTK_STATE_NORMAL);
895 tmp_list = priv->children;
898 GtkLayoutChild *child = tmp_list->data;
899 tmp_list = tmp_list->next;
901 gtk_widget_set_parent_window (child->widget, priv->bin_window);
906 gtk_layout_style_set (GtkWidget *widget,
909 GtkLayoutPrivate *priv;
911 GTK_WIDGET_CLASS (gtk_layout_parent_class)->style_set (widget, old_style);
913 if (gtk_widget_get_realized (widget))
915 priv = GTK_LAYOUT (widget)->priv;
916 gtk_style_set_background (gtk_widget_get_style (widget), priv->bin_window, GTK_STATE_NORMAL);
921 gtk_layout_map (GtkWidget *widget)
923 GtkLayout *layout = GTK_LAYOUT (widget);
924 GtkLayoutPrivate *priv = layout->priv;
927 gtk_widget_set_mapped (widget, TRUE);
929 tmp_list = priv->children;
932 GtkLayoutChild *child = tmp_list->data;
933 tmp_list = tmp_list->next;
935 if (gtk_widget_get_visible (child->widget))
937 if (!gtk_widget_get_mapped (child->widget))
938 gtk_widget_map (child->widget);
942 gdk_window_show (priv->bin_window);
943 gdk_window_show (gtk_widget_get_window (widget));
947 gtk_layout_unrealize (GtkWidget *widget)
949 GtkLayout *layout = GTK_LAYOUT (widget);
950 GtkLayoutPrivate *priv = layout->priv;
952 gdk_window_set_user_data (priv->bin_window, NULL);
953 gdk_window_destroy (priv->bin_window);
954 priv->bin_window = NULL;
956 GTK_WIDGET_CLASS (gtk_layout_parent_class)->unrealize (widget);
960 gtk_layout_get_preferred_width (GtkWidget *widget,
964 *minimum = *natural = 0;
968 gtk_layout_get_preferred_height (GtkWidget *widget,
972 *minimum = *natural = 0;
976 gtk_layout_size_allocate (GtkWidget *widget,
977 GtkAllocation *allocation)
979 GtkLayout *layout = GTK_LAYOUT (widget);
980 GtkLayoutPrivate *priv = layout->priv;
983 gtk_widget_set_allocation (widget, allocation);
985 tmp_list = priv->children;
989 GtkLayoutChild *child = tmp_list->data;
990 tmp_list = tmp_list->next;
992 gtk_layout_allocate_child (layout, child);
995 if (gtk_widget_get_realized (widget))
997 gdk_window_move_resize (gtk_widget_get_window (widget),
998 allocation->x, allocation->y,
999 allocation->width, allocation->height);
1001 gdk_window_resize (priv->bin_window,
1002 MAX (priv->width, allocation->width),
1003 MAX (priv->height, allocation->height));
1006 gtk_layout_set_hadjustment_values (layout);
1007 gtk_layout_set_vadjustment_values (layout);
1011 gtk_layout_draw (GtkWidget *widget,
1014 GtkLayout *layout = GTK_LAYOUT (widget);
1015 GtkLayoutPrivate *priv = layout->priv;
1017 if (gtk_cairo_should_draw_window (cr, priv->bin_window))
1018 GTK_WIDGET_CLASS (gtk_layout_parent_class)->draw (widget, cr);
1023 /* Container methods
1026 gtk_layout_add (GtkContainer *container,
1029 gtk_layout_put (GTK_LAYOUT (container), widget, 0, 0);
1033 gtk_layout_remove (GtkContainer *container,
1036 GtkLayout *layout = GTK_LAYOUT (container);
1037 GtkLayoutPrivate *priv = layout->priv;
1039 GtkLayoutChild *child = NULL;
1041 tmp_list = priv->children;
1044 child = tmp_list->data;
1045 if (child->widget == widget)
1047 tmp_list = tmp_list->next;
1052 gtk_widget_unparent (widget);
1054 priv->children = g_list_remove_link (priv->children, tmp_list);
1055 g_list_free_1 (tmp_list);
1061 gtk_layout_forall (GtkContainer *container,
1062 gboolean include_internals,
1063 GtkCallback callback,
1064 gpointer callback_data)
1066 GtkLayout *layout = GTK_LAYOUT (container);
1067 GtkLayoutPrivate *priv = layout->priv;
1068 GtkLayoutChild *child;
1071 tmp_list = priv->children;
1074 child = tmp_list->data;
1075 tmp_list = tmp_list->next;
1077 (* callback) (child->widget, callback_data);
1081 /* Operations on children
1085 gtk_layout_allocate_child (GtkLayout *layout,
1086 GtkLayoutChild *child)
1088 GtkAllocation allocation;
1089 GtkRequisition requisition;
1091 allocation.x = child->x;
1092 allocation.y = child->y;
1094 gtk_widget_get_preferred_size (child->widget, &requisition, NULL);
1095 allocation.width = requisition.width;
1096 allocation.height = requisition.height;
1098 gtk_widget_size_allocate (child->widget, &allocation);
1104 gtk_layout_adjustment_changed (GtkAdjustment *adjustment,
1107 GtkLayoutPrivate *priv = layout->priv;
1109 if (priv->freeze_count)
1112 if (gtk_widget_get_realized (GTK_WIDGET (layout)))
1114 gdk_window_move (priv->bin_window,
1115 - priv->hadjustment->value,
1116 - priv->vadjustment->value);
1118 gdk_window_process_updates (priv->bin_window, TRUE);