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, see <http://www.gnu.org/licenses/>.
17 * GtkLayout: Widget for scrolling of arbitrary-sized areas.
19 * Copyright Owen Taylor, 1998
23 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
24 * file for a list of people on the GTK+ Team. See the ChangeLog
25 * files for a list of changes. These files are distributed with
26 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include "gtklayout.h"
35 #include "gtkprivate.h"
37 #include "gtkmarshalers.h"
38 #include "gtkscrollable.h"
43 * @Short_description: Infinite scrollable area containing child widgets
44 * and/or custom drawing
46 * @See_also: #GtkDrawingArea, #GtkScrolledWindow
48 * #GtkLayout is similar to #GtkDrawingArea in that it's a "blank slate"
49 * and doesn't do anything but paint a blank background by default. It's
50 * different in that it supports scrolling natively (you can add it to a
51 * #GtkScrolledWindow), and it can contain child widgets, since it's a
52 * #GtkContainer. However if you're just going to draw, a #GtkDrawingArea
53 * is a better choice since it has lower overhead.
55 * When handling expose events on a #GtkLayout, you must draw to
56 * GTK_LAYOUT (layout)->bin_window, rather than to
57 * GTK_WIDGET (layout)->window, as you would for a drawing
62 typedef struct _GtkLayoutChild GtkLayoutChild;
64 struct _GtkLayoutPrivate
70 GtkAdjustment *hadjustment;
71 GtkAdjustment *vadjustment;
73 /* GtkScrollablePolicy needs to be checked when
74 * driving the scrollable adjustment values */
75 guint hscroll_policy : 1;
76 guint vscroll_policy : 1;
80 GdkVisibilityState visibility;
81 GdkWindow *bin_window;
91 struct _GtkLayoutChild {
113 static void gtk_layout_get_property (GObject *object,
117 static void gtk_layout_set_property (GObject *object,
121 static void gtk_layout_finalize (GObject *object);
122 static void gtk_layout_realize (GtkWidget *widget);
123 static void gtk_layout_unrealize (GtkWidget *widget);
124 static void gtk_layout_map (GtkWidget *widget);
125 static void gtk_layout_get_preferred_width (GtkWidget *widget,
128 static void gtk_layout_get_preferred_height (GtkWidget *widget,
131 static void gtk_layout_size_allocate (GtkWidget *widget,
132 GtkAllocation *allocation);
133 static gint gtk_layout_draw (GtkWidget *widget,
135 static void gtk_layout_add (GtkContainer *container,
137 static void gtk_layout_remove (GtkContainer *container,
139 static void gtk_layout_forall (GtkContainer *container,
140 gboolean include_internals,
141 GtkCallback callback,
142 gpointer callback_data);
143 static void gtk_layout_set_child_property (GtkContainer *container,
148 static void gtk_layout_get_child_property (GtkContainer *container,
153 static void gtk_layout_allocate_child (GtkLayout *layout,
154 GtkLayoutChild *child);
155 static void gtk_layout_adjustment_changed (GtkAdjustment *adjustment,
157 static void gtk_layout_style_updated (GtkWidget *widget);
159 static void gtk_layout_set_hadjustment_values (GtkLayout *layout);
160 static void gtk_layout_set_vadjustment_values (GtkLayout *layout);
162 G_DEFINE_TYPE_WITH_CODE (GtkLayout, gtk_layout, GTK_TYPE_CONTAINER,
163 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
169 * @hadjustment: (allow-none): horizontal scroll adjustment, or %NULL
170 * @vadjustment: (allow-none): vertical scroll adjustment, or %NULL
172 * Creates a new #GtkLayout. Unless you have a specific adjustment
173 * you'd like the layout to use for scrolling, pass %NULL for
174 * @hadjustment and @vadjustment.
176 * Return value: a new #GtkLayout
180 gtk_layout_new (GtkAdjustment *hadjustment,
181 GtkAdjustment *vadjustment)
185 layout = g_object_new (GTK_TYPE_LAYOUT,
186 "hadjustment", hadjustment,
187 "vadjustment", vadjustment,
190 return GTK_WIDGET (layout);
194 * gtk_layout_get_bin_window:
195 * @layout: a #GtkLayout
197 * Retrieve the bin window of the layout used for drawing operations.
199 * Return value: (transfer none): a #GdkWindow
204 gtk_layout_get_bin_window (GtkLayout *layout)
206 g_return_val_if_fail (GTK_IS_LAYOUT (layout), NULL);
208 return layout->priv->bin_window;
212 * gtk_layout_get_hadjustment:
213 * @layout: a #GtkLayout
215 * This function should only be called after the layout has been
216 * placed in a #GtkScrolledWindow or otherwise configured for
217 * scrolling. It returns the #GtkAdjustment used for communication
218 * between the horizontal scrollbar and @layout.
220 * See #GtkScrolledWindow, #GtkScrollbar, #GtkAdjustment for details.
222 * Return value: (transfer none): horizontal scroll adjustment
224 * Deprecated: 3.0: Use gtk_scrollable_get_hadjustment()
227 gtk_layout_get_hadjustment (GtkLayout *layout)
229 g_return_val_if_fail (GTK_IS_LAYOUT (layout), NULL);
231 return layout->priv->hadjustment;
234 * gtk_layout_get_vadjustment:
235 * @layout: a #GtkLayout
237 * This function should only be called after the layout has been
238 * placed in a #GtkScrolledWindow or otherwise configured for
239 * scrolling. It returns the #GtkAdjustment used for communication
240 * between the vertical scrollbar and @layout.
242 * See #GtkScrolledWindow, #GtkScrollbar, #GtkAdjustment for details.
244 * Return value: (transfer none): vertical scroll adjustment
246 * Deprecated: 3.0: Use gtk_scrollable_get_vadjustment()
249 gtk_layout_get_vadjustment (GtkLayout *layout)
251 g_return_val_if_fail (GTK_IS_LAYOUT (layout), NULL);
253 return layout->priv->vadjustment;
257 gtk_layout_set_hadjustment_values (GtkLayout *layout)
259 GtkLayoutPrivate *priv = layout->priv;
260 GtkAllocation allocation;
261 GtkAdjustment *adj = priv->hadjustment;
266 gtk_widget_get_allocation (GTK_WIDGET (layout), &allocation);
268 old_value = gtk_adjustment_get_value (adj);
269 new_upper = MAX (allocation.width, priv->width);
274 "page-size", (gdouble)allocation.width,
275 "step-increment", allocation.width * 0.1,
276 "page-increment", allocation.width * 0.9,
279 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
280 if (new_value != old_value)
281 gtk_adjustment_set_value (adj, new_value);
285 gtk_layout_set_vadjustment_values (GtkLayout *layout)
287 GtkAllocation allocation;
288 GtkAdjustment *adj = layout->priv->vadjustment;
293 gtk_widget_get_allocation (GTK_WIDGET (layout), &allocation);
295 old_value = gtk_adjustment_get_value (adj);
296 new_upper = MAX (allocation.height, layout->priv->height);
301 "page-size", (gdouble)allocation.height,
302 "step-increment", allocation.height * 0.1,
303 "page-increment", allocation.height * 0.9,
306 new_value = CLAMP (old_value, 0, new_upper - allocation.height);
307 if (new_value != old_value)
308 gtk_adjustment_set_value (adj, new_value);
312 gtk_layout_finalize (GObject *object)
314 GtkLayout *layout = GTK_LAYOUT (object);
315 GtkLayoutPrivate *priv = layout->priv;
317 g_object_unref (priv->hadjustment);
318 g_object_unref (priv->vadjustment);
320 G_OBJECT_CLASS (gtk_layout_parent_class)->finalize (object);
324 gtk_layout_do_set_hadjustment (GtkLayout *layout,
325 GtkAdjustment *adjustment)
327 GtkLayoutPrivate *priv;
331 if (adjustment && priv->hadjustment == adjustment)
334 if (priv->hadjustment != NULL)
336 g_signal_handlers_disconnect_by_func (priv->hadjustment,
337 gtk_layout_adjustment_changed,
339 g_object_unref (priv->hadjustment);
342 if (adjustment == NULL)
343 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
345 g_signal_connect (adjustment, "value-changed",
346 G_CALLBACK (gtk_layout_adjustment_changed), layout);
347 priv->hadjustment = g_object_ref_sink (adjustment);
348 gtk_layout_set_hadjustment_values (layout);
350 g_object_notify (G_OBJECT (layout), "hadjustment");
354 * gtk_layout_set_hadjustment:
355 * @layout: a #GtkLayout
356 * @adjustment: (allow-none): new scroll adjustment
358 * Sets the horizontal scroll adjustment for the layout.
360 * See #GtkScrolledWindow, #GtkScrollbar, #GtkAdjustment for details.
362 * Deprecated: 3.0: Use gtk_scrollable_set_hadjustment()
365 gtk_layout_set_hadjustment (GtkLayout *layout,
366 GtkAdjustment *adjustment)
368 g_return_if_fail (GTK_IS_LAYOUT (layout));
369 g_return_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment));
371 gtk_layout_do_set_hadjustment (layout, adjustment);
375 gtk_layout_do_set_vadjustment (GtkLayout *layout,
376 GtkAdjustment *adjustment)
378 GtkLayoutPrivate *priv;
382 if (adjustment && priv->vadjustment == adjustment)
385 if (priv->vadjustment != NULL)
387 g_signal_handlers_disconnect_by_func (priv->vadjustment,
388 gtk_layout_adjustment_changed,
390 g_object_unref (priv->vadjustment);
393 if (adjustment == NULL)
394 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
396 g_signal_connect (adjustment, "value-changed",
397 G_CALLBACK (gtk_layout_adjustment_changed), layout);
398 priv->vadjustment = g_object_ref_sink (adjustment);
399 gtk_layout_set_vadjustment_values (layout);
401 g_object_notify (G_OBJECT (layout), "vadjustment");
405 * gtk_layout_set_vadjustment:
406 * @layout: a #GtkLayout
407 * @adjustment: (allow-none): new scroll adjustment
409 * Sets the vertical scroll adjustment for the layout.
411 * See #GtkScrolledWindow, #GtkScrollbar, #GtkAdjustment for details.
413 * Deprecated: 3.0: Use gtk_scrollable_set_vadjustment()
416 gtk_layout_set_vadjustment (GtkLayout *layout,
417 GtkAdjustment *adjustment)
419 g_return_if_fail (GTK_IS_LAYOUT (layout));
420 g_return_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment));
422 gtk_layout_do_set_vadjustment (layout, adjustment);
425 static GtkLayoutChild*
426 get_child (GtkLayout *layout,
429 GtkLayoutPrivate *priv = layout->priv;
432 children = priv->children;
435 GtkLayoutChild *child;
437 child = children->data;
438 children = children->next;
440 if (child->widget == widget)
449 * @layout: a #GtkLayout
450 * @child_widget: child widget
451 * @x: X position of child widget
452 * @y: Y position of child widget
454 * Adds @child_widget to @layout, at position (@x,@y).
455 * @layout becomes the new parent container of @child_widget.
459 gtk_layout_put (GtkLayout *layout,
460 GtkWidget *child_widget,
464 GtkLayoutPrivate *priv;
465 GtkLayoutChild *child;
467 g_return_if_fail (GTK_IS_LAYOUT (layout));
468 g_return_if_fail (GTK_IS_WIDGET (child_widget));
472 child = g_new (GtkLayoutChild, 1);
474 child->widget = child_widget;
478 priv->children = g_list_append (priv->children, child);
480 if (gtk_widget_get_realized (GTK_WIDGET (layout)))
481 gtk_widget_set_parent_window (child->widget, priv->bin_window);
483 gtk_widget_set_parent (child_widget, GTK_WIDGET (layout));
487 gtk_layout_move_internal (GtkLayout *layout,
494 GtkLayoutChild *child;
496 child = get_child (layout, widget);
500 gtk_widget_freeze_child_notify (widget);
505 gtk_widget_child_notify (widget, "x");
511 gtk_widget_child_notify (widget, "y");
514 gtk_widget_thaw_child_notify (widget);
516 if (gtk_widget_get_visible (widget) &&
517 gtk_widget_get_visible (GTK_WIDGET (layout)))
518 gtk_widget_queue_resize (widget);
523 * @layout: a #GtkLayout
524 * @child_widget: a current child of @layout
525 * @x: X position to move to
526 * @y: Y position to move to
528 * Moves a current child of @layout to a new position.
532 gtk_layout_move (GtkLayout *layout,
533 GtkWidget *child_widget,
537 g_return_if_fail (GTK_IS_LAYOUT (layout));
538 g_return_if_fail (GTK_IS_WIDGET (child_widget));
539 g_return_if_fail (gtk_widget_get_parent (child_widget) == GTK_WIDGET (layout));
541 gtk_layout_move_internal (layout, child_widget, TRUE, x, TRUE, y);
545 * gtk_layout_set_size:
546 * @layout: a #GtkLayout
547 * @width: width of entire scrollable area
548 * @height: height of entire scrollable area
550 * Sets the size of the scrollable area of the layout.
554 gtk_layout_set_size (GtkLayout *layout,
558 GtkLayoutPrivate *priv;
561 g_return_if_fail (GTK_IS_LAYOUT (layout));
564 widget = GTK_WIDGET (layout);
566 g_object_freeze_notify (G_OBJECT (layout));
567 if (width != priv->width)
570 g_object_notify (G_OBJECT (layout), "width");
572 if (height != priv->height)
574 priv->height = height;
575 g_object_notify (G_OBJECT (layout), "height");
577 g_object_thaw_notify (G_OBJECT (layout));
579 if (gtk_widget_get_realized (widget))
581 GtkAllocation allocation;
583 gtk_widget_get_allocation (widget, &allocation);
584 width = MAX (width, allocation.width);
585 height = MAX (height, allocation.height);
586 gdk_window_resize (priv->bin_window, width, height);
589 gtk_layout_set_hadjustment_values (layout);
590 gtk_layout_set_vadjustment_values (layout);
594 * gtk_layout_get_size:
595 * @layout: a #GtkLayout
596 * @width: (out) (allow-none): location to store the width set on
598 * @height: (out) (allow-none): location to store the height set on
601 * Gets the size that has been set on the layout, and that determines
602 * the total extents of the layout's scrollbar area. See
603 * gtk_layout_set_size ().
606 gtk_layout_get_size (GtkLayout *layout,
610 GtkLayoutPrivate *priv;
612 g_return_if_fail (GTK_IS_LAYOUT (layout));
617 *width = priv->width;
619 *height = priv->height;
622 /* Basic Object handling procedures
625 gtk_layout_class_init (GtkLayoutClass *class)
627 GObjectClass *gobject_class;
628 GtkWidgetClass *widget_class;
629 GtkContainerClass *container_class;
631 gobject_class = (GObjectClass*) class;
632 widget_class = (GtkWidgetClass*) class;
633 container_class = (GtkContainerClass*) class;
635 gobject_class->set_property = gtk_layout_set_property;
636 gobject_class->get_property = gtk_layout_get_property;
637 gobject_class->finalize = gtk_layout_finalize;
639 container_class->set_child_property = gtk_layout_set_child_property;
640 container_class->get_child_property = gtk_layout_get_child_property;
642 gtk_container_class_install_child_property (container_class,
644 g_param_spec_int ("x",
646 P_("X position of child widget"),
650 GTK_PARAM_READWRITE));
652 gtk_container_class_install_child_property (container_class,
654 g_param_spec_int ("y",
656 P_("Y position of child widget"),
660 GTK_PARAM_READWRITE));
662 /* Scrollable interface */
663 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
664 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
665 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
666 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
668 g_object_class_install_property (gobject_class,
670 g_param_spec_uint ("width",
672 P_("The width of the layout"),
676 GTK_PARAM_READWRITE));
677 g_object_class_install_property (gobject_class,
679 g_param_spec_uint ("height",
681 P_("The height of the layout"),
685 GTK_PARAM_READWRITE));
686 widget_class->realize = gtk_layout_realize;
687 widget_class->unrealize = gtk_layout_unrealize;
688 widget_class->map = gtk_layout_map;
689 widget_class->get_preferred_width = gtk_layout_get_preferred_width;
690 widget_class->get_preferred_height = gtk_layout_get_preferred_height;
691 widget_class->size_allocate = gtk_layout_size_allocate;
692 widget_class->draw = gtk_layout_draw;
693 widget_class->style_updated = gtk_layout_style_updated;
695 container_class->add = gtk_layout_add;
696 container_class->remove = gtk_layout_remove;
697 container_class->forall = gtk_layout_forall;
699 g_type_class_add_private (class, sizeof (GtkLayoutPrivate));
703 gtk_layout_get_property (GObject *object,
708 GtkLayout *layout = GTK_LAYOUT (object);
709 GtkLayoutPrivate *priv = layout->priv;
713 case PROP_HADJUSTMENT:
714 g_value_set_object (value, priv->hadjustment);
716 case PROP_VADJUSTMENT:
717 g_value_set_object (value, priv->vadjustment);
719 case PROP_HSCROLL_POLICY:
720 g_value_set_enum (value, priv->hscroll_policy);
722 case PROP_VSCROLL_POLICY:
723 g_value_set_enum (value, priv->vscroll_policy);
726 g_value_set_uint (value, priv->width);
729 g_value_set_uint (value, priv->height);
732 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
738 gtk_layout_set_property (GObject *object,
743 GtkLayout *layout = GTK_LAYOUT (object);
744 GtkLayoutPrivate *priv = layout->priv;
748 case PROP_HADJUSTMENT:
749 gtk_layout_do_set_hadjustment (layout, g_value_get_object (value));
751 case PROP_VADJUSTMENT:
752 gtk_layout_do_set_vadjustment (layout, g_value_get_object (value));
754 case PROP_HSCROLL_POLICY:
755 priv->hscroll_policy = g_value_get_enum (value);
756 gtk_widget_queue_resize (GTK_WIDGET (layout));
758 case PROP_VSCROLL_POLICY:
759 priv->vscroll_policy = g_value_get_enum (value);
760 gtk_widget_queue_resize (GTK_WIDGET (layout));
763 gtk_layout_set_size (layout, g_value_get_uint (value),
767 gtk_layout_set_size (layout, priv->width,
768 g_value_get_uint (value));
771 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
777 gtk_layout_set_child_property (GtkContainer *container,
786 gtk_layout_move_internal (GTK_LAYOUT (container),
788 TRUE, g_value_get_int (value),
792 gtk_layout_move_internal (GTK_LAYOUT (container),
795 TRUE, g_value_get_int (value));
798 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
804 gtk_layout_get_child_property (GtkContainer *container,
810 GtkLayoutChild *layout_child;
812 layout_child = get_child (GTK_LAYOUT (container), child);
817 g_value_set_int (value, layout_child->x);
820 g_value_set_int (value, layout_child->y);
823 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
829 gtk_layout_init (GtkLayout *layout)
831 GtkLayoutPrivate *priv;
833 layout->priv = G_TYPE_INSTANCE_GET_PRIVATE (layout,
838 priv->children = NULL;
843 priv->hadjustment = NULL;
844 priv->vadjustment = NULL;
846 priv->bin_window = NULL;
850 priv->visibility = GDK_VISIBILITY_PARTIAL;
852 priv->freeze_count = 0;
859 gtk_layout_realize (GtkWidget *widget)
861 GtkLayout *layout = GTK_LAYOUT (widget);
862 GtkLayoutPrivate *priv = layout->priv;
863 GtkAllocation allocation;
865 GdkWindowAttr attributes;
867 gint attributes_mask;
869 gtk_widget_set_realized (widget, TRUE);
871 gtk_widget_get_allocation (widget, &allocation);
873 attributes.window_type = GDK_WINDOW_CHILD;
874 attributes.x = allocation.x;
875 attributes.y = allocation.y;
876 attributes.width = allocation.width;
877 attributes.height = allocation.height;
878 attributes.wclass = GDK_INPUT_OUTPUT;
879 attributes.visual = gtk_widget_get_visual (widget);
880 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
882 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
884 window = gdk_window_new (gtk_widget_get_parent_window (widget),
885 &attributes, attributes_mask);
886 gtk_widget_set_window (widget, window);
887 gdk_window_set_user_data (window, widget);
889 gtk_widget_get_allocation (widget, &allocation);
891 attributes.x = - gtk_adjustment_get_value (priv->hadjustment),
892 attributes.y = - gtk_adjustment_get_value (priv->vadjustment);
893 attributes.width = MAX (priv->width, allocation.width);
894 attributes.height = MAX (priv->height, allocation.height);
895 attributes.event_mask = GDK_EXPOSURE_MASK | GDK_SCROLL_MASK |
896 gtk_widget_get_events (widget);
898 priv->bin_window = gdk_window_new (window,
899 &attributes, attributes_mask);
900 gdk_window_set_user_data (priv->bin_window, widget);
901 gtk_style_context_set_background (gtk_widget_get_style_context (widget), priv->bin_window);
903 tmp_list = priv->children;
906 GtkLayoutChild *child = tmp_list->data;
907 tmp_list = tmp_list->next;
909 gtk_widget_set_parent_window (child->widget, priv->bin_window);
914 gtk_layout_style_updated (GtkWidget *widget)
916 GtkLayoutPrivate *priv;
918 GTK_WIDGET_CLASS (gtk_layout_parent_class)->style_updated (widget);
920 if (gtk_widget_get_realized (widget))
922 priv = GTK_LAYOUT (widget)->priv;
923 gtk_style_context_set_background (gtk_widget_get_style_context (widget), priv->bin_window);
928 gtk_layout_map (GtkWidget *widget)
930 GtkLayout *layout = GTK_LAYOUT (widget);
931 GtkLayoutPrivate *priv = layout->priv;
934 gtk_widget_set_mapped (widget, TRUE);
936 tmp_list = priv->children;
939 GtkLayoutChild *child = tmp_list->data;
940 tmp_list = tmp_list->next;
942 if (gtk_widget_get_visible (child->widget))
944 if (!gtk_widget_get_mapped (child->widget))
945 gtk_widget_map (child->widget);
949 gdk_window_show (priv->bin_window);
950 gdk_window_show (gtk_widget_get_window (widget));
954 gtk_layout_unrealize (GtkWidget *widget)
956 GtkLayout *layout = GTK_LAYOUT (widget);
957 GtkLayoutPrivate *priv = layout->priv;
959 gdk_window_set_user_data (priv->bin_window, NULL);
960 gdk_window_destroy (priv->bin_window);
961 priv->bin_window = NULL;
963 GTK_WIDGET_CLASS (gtk_layout_parent_class)->unrealize (widget);
967 gtk_layout_get_preferred_width (GtkWidget *widget,
971 *minimum = *natural = 0;
975 gtk_layout_get_preferred_height (GtkWidget *widget,
979 *minimum = *natural = 0;
983 gtk_layout_size_allocate (GtkWidget *widget,
984 GtkAllocation *allocation)
986 GtkLayout *layout = GTK_LAYOUT (widget);
987 GtkLayoutPrivate *priv = layout->priv;
990 gtk_widget_set_allocation (widget, allocation);
992 tmp_list = priv->children;
996 GtkLayoutChild *child = tmp_list->data;
997 tmp_list = tmp_list->next;
999 gtk_layout_allocate_child (layout, child);
1002 if (gtk_widget_get_realized (widget))
1004 gdk_window_move_resize (gtk_widget_get_window (widget),
1005 allocation->x, allocation->y,
1006 allocation->width, allocation->height);
1008 gdk_window_resize (priv->bin_window,
1009 MAX (priv->width, allocation->width),
1010 MAX (priv->height, allocation->height));
1013 gtk_layout_set_hadjustment_values (layout);
1014 gtk_layout_set_vadjustment_values (layout);
1018 gtk_layout_draw (GtkWidget *widget,
1021 GtkLayout *layout = GTK_LAYOUT (widget);
1022 GtkLayoutPrivate *priv = layout->priv;
1024 if (gtk_cairo_should_draw_window (cr, priv->bin_window))
1025 GTK_WIDGET_CLASS (gtk_layout_parent_class)->draw (widget, cr);
1030 /* Container methods
1033 gtk_layout_add (GtkContainer *container,
1036 gtk_layout_put (GTK_LAYOUT (container), widget, 0, 0);
1040 gtk_layout_remove (GtkContainer *container,
1043 GtkLayout *layout = GTK_LAYOUT (container);
1044 GtkLayoutPrivate *priv = layout->priv;
1046 GtkLayoutChild *child = NULL;
1048 tmp_list = priv->children;
1051 child = tmp_list->data;
1052 if (child->widget == widget)
1054 tmp_list = tmp_list->next;
1059 gtk_widget_unparent (widget);
1061 priv->children = g_list_remove_link (priv->children, tmp_list);
1062 g_list_free_1 (tmp_list);
1068 gtk_layout_forall (GtkContainer *container,
1069 gboolean include_internals,
1070 GtkCallback callback,
1071 gpointer callback_data)
1073 GtkLayout *layout = GTK_LAYOUT (container);
1074 GtkLayoutPrivate *priv = layout->priv;
1075 GtkLayoutChild *child;
1078 tmp_list = priv->children;
1081 child = tmp_list->data;
1082 tmp_list = tmp_list->next;
1084 (* callback) (child->widget, callback_data);
1088 /* Operations on children
1092 gtk_layout_allocate_child (GtkLayout *layout,
1093 GtkLayoutChild *child)
1095 GtkAllocation allocation;
1096 GtkRequisition requisition;
1098 allocation.x = child->x;
1099 allocation.y = child->y;
1101 gtk_widget_get_preferred_size (child->widget, &requisition, NULL);
1102 allocation.width = requisition.width;
1103 allocation.height = requisition.height;
1105 gtk_widget_size_allocate (child->widget, &allocation);
1111 gtk_layout_adjustment_changed (GtkAdjustment *adjustment,
1114 GtkLayoutPrivate *priv = layout->priv;
1116 if (priv->freeze_count)
1119 if (gtk_widget_get_realized (GTK_WIDGET (layout)))
1121 gdk_window_move (priv->bin_window,
1122 - gtk_adjustment_get_value (priv->hadjustment),
1123 - gtk_adjustment_get_value (priv->vadjustment));
1125 gdk_window_process_updates (priv->bin_window, TRUE);