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_updated (GtkWidget *widget);
161 static void gtk_layout_set_hadjustment_values (GtkLayout *layout);
162 static void gtk_layout_set_vadjustment_values (GtkLayout *layout);
164 G_DEFINE_TYPE_WITH_CODE (GtkLayout, gtk_layout, GTK_TYPE_CONTAINER,
165 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
171 * @hadjustment: (allow-none): horizontal scroll adjustment, or %NULL
172 * @vadjustment: (allow-none): vertical scroll adjustment, or %NULL
174 * Creates a new #GtkLayout. Unless you have a specific adjustment
175 * you'd like the layout to use for scrolling, pass %NULL for
176 * @hadjustment and @vadjustment.
178 * Return value: a new #GtkLayout
182 gtk_layout_new (GtkAdjustment *hadjustment,
183 GtkAdjustment *vadjustment)
187 layout = g_object_new (GTK_TYPE_LAYOUT,
188 "hadjustment", hadjustment,
189 "vadjustment", vadjustment,
192 return GTK_WIDGET (layout);
196 * gtk_layout_get_bin_window:
197 * @layout: a #GtkLayout
199 * Retrieve the bin window of the layout used for drawing operations.
201 * Return value: (transfer none): a #GdkWindow
206 gtk_layout_get_bin_window (GtkLayout *layout)
208 g_return_val_if_fail (GTK_IS_LAYOUT (layout), NULL);
210 return layout->priv->bin_window;
214 * gtk_layout_get_hadjustment:
215 * @layout: a #GtkLayout
217 * This function should only be called after the layout has been
218 * placed in a #GtkScrolledWindow or otherwise configured for
219 * scrolling. It returns the #GtkAdjustment used for communication
220 * between the horizontal scrollbar and @layout.
222 * See #GtkScrolledWindow, #GtkScrollbar, #GtkAdjustment for details.
224 * Return value: (transfer none): horizontal scroll adjustment
226 * Deprecated: 3.0: Use gtk_scrollable_get_hadjustment()
229 gtk_layout_get_hadjustment (GtkLayout *layout)
231 g_return_val_if_fail (GTK_IS_LAYOUT (layout), NULL);
233 return layout->priv->hadjustment;
236 * gtk_layout_get_vadjustment:
237 * @layout: a #GtkLayout
239 * This function should only be called after the layout has been
240 * placed in a #GtkScrolledWindow or otherwise configured for
241 * scrolling. It returns the #GtkAdjustment used for communication
242 * between the vertical scrollbar and @layout.
244 * See #GtkScrolledWindow, #GtkScrollbar, #GtkAdjustment for details.
246 * Return value: (transfer none): vertical scroll adjustment
248 * Deprecated: 3.0: Use gtk_scrollable_get_vadjustment()
251 gtk_layout_get_vadjustment (GtkLayout *layout)
253 g_return_val_if_fail (GTK_IS_LAYOUT (layout), NULL);
255 return layout->priv->vadjustment;
259 gtk_layout_set_hadjustment_values (GtkLayout *layout)
261 GtkLayoutPrivate *priv = layout->priv;
262 GtkAllocation allocation;
263 GtkAdjustment *adj = priv->hadjustment;
268 gtk_widget_get_allocation (GTK_WIDGET (layout), &allocation);
270 old_value = gtk_adjustment_get_value (adj);
271 new_upper = MAX (allocation.width, priv->width);
276 "page-size", (gdouble)allocation.width,
277 "step-increment", allocation.width * 0.1,
278 "page-increment", allocation.width * 0.9,
281 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
282 if (new_value != old_value)
283 gtk_adjustment_set_value (adj, new_value);
287 gtk_layout_set_vadjustment_values (GtkLayout *layout)
289 GtkAllocation allocation;
290 GtkAdjustment *adj = layout->priv->vadjustment;
295 gtk_widget_get_allocation (GTK_WIDGET (layout), &allocation);
297 old_value = gtk_adjustment_get_value (adj);
298 new_upper = MAX (allocation.height, layout->priv->height);
303 "page-size", (gdouble)allocation.height,
304 "step-increment", allocation.height * 0.1,
305 "page-increment", allocation.height * 0.9,
308 new_value = CLAMP (old_value, 0, new_upper - allocation.height);
309 if (new_value != old_value)
310 gtk_adjustment_set_value (adj, new_value);
314 gtk_layout_finalize (GObject *object)
316 GtkLayout *layout = GTK_LAYOUT (object);
317 GtkLayoutPrivate *priv = layout->priv;
319 g_object_unref (priv->hadjustment);
320 g_object_unref (priv->vadjustment);
322 G_OBJECT_CLASS (gtk_layout_parent_class)->finalize (object);
326 * gtk_layout_set_hadjustment:
327 * @layout: a #GtkLayout
328 * @adjustment: (allow-none): new scroll adjustment
330 * Sets the horizontal scroll adjustment for the layout.
332 * See #GtkScrolledWindow, #GtkScrollbar, #GtkAdjustment for details.
334 * Deprecated: 3.0: Use gtk_scrollable_set_hadjustment()
337 gtk_layout_set_hadjustment (GtkLayout *layout,
338 GtkAdjustment *adjustment)
340 GtkLayoutPrivate *priv;
342 g_return_if_fail (GTK_IS_LAYOUT (layout));
343 g_return_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment));
347 if (adjustment && priv->hadjustment == adjustment)
350 if (priv->hadjustment != NULL)
352 g_signal_handlers_disconnect_by_func (priv->hadjustment,
353 gtk_layout_adjustment_changed,
355 g_object_unref (priv->hadjustment);
358 if (adjustment == NULL)
359 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
361 g_signal_connect (adjustment, "value-changed",
362 G_CALLBACK (gtk_layout_adjustment_changed), layout);
363 priv->hadjustment = g_object_ref_sink (adjustment);
364 gtk_layout_set_hadjustment_values (layout);
366 g_object_notify (G_OBJECT (layout), "hadjustment");
371 * gtk_layout_set_vadjustment:
372 * @layout: a #GtkLayout
373 * @adjustment: (allow-none): new scroll adjustment
375 * Sets the vertical scroll adjustment for the layout.
377 * See #GtkScrolledWindow, #GtkScrollbar, #GtkAdjustment for details.
379 * Deprecated: 3.0: Use gtk_scrollable_set_vadjustment()
382 gtk_layout_set_vadjustment (GtkLayout *layout,
383 GtkAdjustment *adjustment)
385 GtkLayoutPrivate *priv;
387 g_return_if_fail (GTK_IS_LAYOUT (layout));
388 g_return_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment));
392 if (adjustment && priv->vadjustment == adjustment)
395 if (priv->vadjustment != NULL)
397 g_signal_handlers_disconnect_by_func (priv->vadjustment,
398 gtk_layout_adjustment_changed,
400 g_object_unref (priv->vadjustment);
403 if (adjustment == NULL)
404 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
406 g_signal_connect (adjustment, "value-changed",
407 G_CALLBACK (gtk_layout_adjustment_changed), layout);
408 priv->vadjustment = g_object_ref_sink (adjustment);
409 gtk_layout_set_vadjustment_values (layout);
411 g_object_notify (G_OBJECT (layout), "vadjustment");
414 static GtkLayoutChild*
415 get_child (GtkLayout *layout,
418 GtkLayoutPrivate *priv = layout->priv;
421 children = priv->children;
424 GtkLayoutChild *child;
426 child = children->data;
427 children = children->next;
429 if (child->widget == widget)
438 * @layout: a #GtkLayout
439 * @child_widget: child widget
440 * @x: X position of child widget
441 * @y: Y position of child widget
443 * Adds @child_widget to @layout, at position (@x,@y).
444 * @layout becomes the new parent container of @child_widget.
448 gtk_layout_put (GtkLayout *layout,
449 GtkWidget *child_widget,
453 GtkLayoutPrivate *priv;
454 GtkLayoutChild *child;
456 g_return_if_fail (GTK_IS_LAYOUT (layout));
457 g_return_if_fail (GTK_IS_WIDGET (child_widget));
461 child = g_new (GtkLayoutChild, 1);
463 child->widget = child_widget;
467 priv->children = g_list_append (priv->children, child);
469 if (gtk_widget_get_realized (GTK_WIDGET (layout)))
470 gtk_widget_set_parent_window (child->widget, priv->bin_window);
472 gtk_widget_set_parent (child_widget, GTK_WIDGET (layout));
476 gtk_layout_move_internal (GtkLayout *layout,
483 GtkLayoutChild *child;
485 child = get_child (layout, widget);
489 gtk_widget_freeze_child_notify (widget);
494 gtk_widget_child_notify (widget, "x");
500 gtk_widget_child_notify (widget, "y");
503 gtk_widget_thaw_child_notify (widget);
505 if (gtk_widget_get_visible (widget) &&
506 gtk_widget_get_visible (GTK_WIDGET (layout)))
507 gtk_widget_queue_resize (widget);
512 * @layout: a #GtkLayout
513 * @child_widget: a current child of @layout
514 * @x: X position to move to
515 * @y: Y position to move to
517 * Moves a current child of @layout to a new position.
521 gtk_layout_move (GtkLayout *layout,
522 GtkWidget *child_widget,
526 g_return_if_fail (GTK_IS_LAYOUT (layout));
527 g_return_if_fail (GTK_IS_WIDGET (child_widget));
528 g_return_if_fail (gtk_widget_get_parent (child_widget) == GTK_WIDGET (layout));
530 gtk_layout_move_internal (layout, child_widget, TRUE, x, TRUE, y);
534 * gtk_layout_set_size:
535 * @layout: a #GtkLayout
536 * @width: width of entire scrollable area
537 * @height: height of entire scrollable area
539 * Sets the size of the scrollable area of the layout.
543 gtk_layout_set_size (GtkLayout *layout,
547 GtkLayoutPrivate *priv;
550 g_return_if_fail (GTK_IS_LAYOUT (layout));
553 widget = GTK_WIDGET (layout);
555 g_object_freeze_notify (G_OBJECT (layout));
556 if (width != priv->width)
559 g_object_notify (G_OBJECT (layout), "width");
561 if (height != priv->height)
563 priv->height = height;
564 g_object_notify (G_OBJECT (layout), "height");
566 g_object_thaw_notify (G_OBJECT (layout));
568 if (gtk_widget_get_realized (widget))
570 GtkAllocation allocation;
572 gtk_widget_get_allocation (widget, &allocation);
573 width = MAX (width, allocation.width);
574 height = MAX (height, allocation.height);
575 gdk_window_resize (priv->bin_window, width, height);
578 gtk_layout_set_hadjustment_values (layout);
579 gtk_layout_set_vadjustment_values (layout);
583 * gtk_layout_get_size:
584 * @layout: a #GtkLayout
585 * @width: (allow-none): location to store the width set on @layout, or %NULL
586 * @height: (allow-none): location to store the height set on @layout, or %NULL
588 * Gets the size that has been set on the layout, and that determines
589 * the total extents of the layout's scrollbar area. See
590 * gtk_layout_set_size ().
593 gtk_layout_get_size (GtkLayout *layout,
597 GtkLayoutPrivate *priv;
599 g_return_if_fail (GTK_IS_LAYOUT (layout));
604 *width = priv->width;
606 *height = priv->height;
609 /* Basic Object handling procedures
612 gtk_layout_class_init (GtkLayoutClass *class)
614 GObjectClass *gobject_class;
615 GtkWidgetClass *widget_class;
616 GtkContainerClass *container_class;
618 gobject_class = (GObjectClass*) class;
619 widget_class = (GtkWidgetClass*) class;
620 container_class = (GtkContainerClass*) class;
622 gobject_class->set_property = gtk_layout_set_property;
623 gobject_class->get_property = gtk_layout_get_property;
624 gobject_class->finalize = gtk_layout_finalize;
626 container_class->set_child_property = gtk_layout_set_child_property;
627 container_class->get_child_property = gtk_layout_get_child_property;
629 gtk_container_class_install_child_property (container_class,
631 g_param_spec_int ("x",
633 P_("X position of child widget"),
637 GTK_PARAM_READWRITE));
639 gtk_container_class_install_child_property (container_class,
641 g_param_spec_int ("y",
643 P_("Y position of child widget"),
647 GTK_PARAM_READWRITE));
649 /* Scrollable interface */
650 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
651 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
652 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
653 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
655 g_object_class_install_property (gobject_class,
657 g_param_spec_uint ("width",
659 P_("The width of the layout"),
663 GTK_PARAM_READWRITE));
664 g_object_class_install_property (gobject_class,
666 g_param_spec_uint ("height",
668 P_("The height of the layout"),
672 GTK_PARAM_READWRITE));
673 widget_class->realize = gtk_layout_realize;
674 widget_class->unrealize = gtk_layout_unrealize;
675 widget_class->map = gtk_layout_map;
676 widget_class->get_preferred_width = gtk_layout_get_preferred_width;
677 widget_class->get_preferred_height = gtk_layout_get_preferred_height;
678 widget_class->size_allocate = gtk_layout_size_allocate;
679 widget_class->draw = gtk_layout_draw;
680 widget_class->style_updated = gtk_layout_style_updated;
682 container_class->add = gtk_layout_add;
683 container_class->remove = gtk_layout_remove;
684 container_class->forall = gtk_layout_forall;
686 g_type_class_add_private (class, sizeof (GtkLayoutPrivate));
690 gtk_layout_get_property (GObject *object,
695 GtkLayout *layout = GTK_LAYOUT (object);
696 GtkLayoutPrivate *priv = layout->priv;
700 case PROP_HADJUSTMENT:
701 g_value_set_object (value, priv->hadjustment);
703 case PROP_VADJUSTMENT:
704 g_value_set_object (value, priv->vadjustment);
706 case PROP_HSCROLL_POLICY:
707 g_value_set_enum (value, priv->hscroll_policy);
709 case PROP_VSCROLL_POLICY:
710 g_value_set_enum (value, priv->vscroll_policy);
713 g_value_set_uint (value, priv->width);
716 g_value_set_uint (value, priv->height);
719 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
725 gtk_layout_set_property (GObject *object,
730 GtkLayout *layout = GTK_LAYOUT (object);
731 GtkLayoutPrivate *priv = layout->priv;
735 case PROP_HADJUSTMENT:
736 gtk_layout_set_hadjustment (layout,
737 (GtkAdjustment*) g_value_get_object (value));
739 case PROP_VADJUSTMENT:
740 gtk_layout_set_vadjustment (layout,
741 (GtkAdjustment*) g_value_get_object (value));
743 case PROP_HSCROLL_POLICY:
744 priv->hscroll_policy = g_value_get_enum (value);
745 gtk_widget_queue_resize (GTK_WIDGET (layout));
747 case PROP_VSCROLL_POLICY:
748 priv->vscroll_policy = g_value_get_enum (value);
749 gtk_widget_queue_resize (GTK_WIDGET (layout));
752 gtk_layout_set_size (layout, g_value_get_uint (value),
756 gtk_layout_set_size (layout, priv->width,
757 g_value_get_uint (value));
760 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
766 gtk_layout_set_child_property (GtkContainer *container,
775 gtk_layout_move_internal (GTK_LAYOUT (container),
777 TRUE, g_value_get_int (value),
781 gtk_layout_move_internal (GTK_LAYOUT (container),
784 TRUE, g_value_get_int (value));
787 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
793 gtk_layout_get_child_property (GtkContainer *container,
799 GtkLayoutChild *layout_child;
801 layout_child = get_child (GTK_LAYOUT (container), child);
806 g_value_set_int (value, layout_child->x);
809 g_value_set_int (value, layout_child->y);
812 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
818 gtk_layout_init (GtkLayout *layout)
820 GtkLayoutPrivate *priv;
822 layout->priv = G_TYPE_INSTANCE_GET_PRIVATE (layout,
827 priv->children = NULL;
832 priv->hadjustment = NULL;
833 priv->vadjustment = NULL;
835 priv->bin_window = NULL;
839 priv->visibility = GDK_VISIBILITY_PARTIAL;
841 priv->freeze_count = 0;
848 gtk_layout_realize (GtkWidget *widget)
850 GtkLayout *layout = GTK_LAYOUT (widget);
851 GtkLayoutPrivate *priv = layout->priv;
852 GtkAllocation allocation;
854 GdkWindowAttr attributes;
856 gint attributes_mask;
858 gtk_widget_set_realized (widget, TRUE);
860 gtk_widget_get_allocation (widget, &allocation);
862 attributes.window_type = GDK_WINDOW_CHILD;
863 attributes.x = allocation.x;
864 attributes.y = allocation.y;
865 attributes.width = allocation.width;
866 attributes.height = allocation.height;
867 attributes.wclass = GDK_INPUT_OUTPUT;
868 attributes.visual = gtk_widget_get_visual (widget);
869 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
871 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
873 window = gdk_window_new (gtk_widget_get_parent_window (widget),
874 &attributes, attributes_mask);
875 gtk_widget_set_window (widget, window);
876 gdk_window_set_user_data (window, widget);
878 gtk_widget_get_allocation (widget, &allocation);
880 attributes.x = - gtk_adjustment_get_value (priv->hadjustment),
881 attributes.y = - gtk_adjustment_get_value (priv->vadjustment);
882 attributes.width = MAX (priv->width, allocation.width);
883 attributes.height = MAX (priv->height, allocation.height);
884 attributes.event_mask = GDK_EXPOSURE_MASK | GDK_SCROLL_MASK |
885 gtk_widget_get_events (widget);
887 priv->bin_window = gdk_window_new (window,
888 &attributes, attributes_mask);
889 gdk_window_set_user_data (priv->bin_window, widget);
890 gtk_style_context_set_background (gtk_widget_get_style_context (widget), priv->bin_window);
892 tmp_list = priv->children;
895 GtkLayoutChild *child = tmp_list->data;
896 tmp_list = tmp_list->next;
898 gtk_widget_set_parent_window (child->widget, priv->bin_window);
903 gtk_layout_style_updated (GtkWidget *widget)
905 GtkLayoutPrivate *priv;
907 GTK_WIDGET_CLASS (gtk_layout_parent_class)->style_updated (widget);
909 if (gtk_widget_get_realized (widget))
911 priv = GTK_LAYOUT (widget)->priv;
912 gtk_style_context_set_background (gtk_widget_get_style_context (widget), priv->bin_window);
917 gtk_layout_map (GtkWidget *widget)
919 GtkLayout *layout = GTK_LAYOUT (widget);
920 GtkLayoutPrivate *priv = layout->priv;
923 gtk_widget_set_mapped (widget, TRUE);
925 tmp_list = priv->children;
928 GtkLayoutChild *child = tmp_list->data;
929 tmp_list = tmp_list->next;
931 if (gtk_widget_get_visible (child->widget))
933 if (!gtk_widget_get_mapped (child->widget))
934 gtk_widget_map (child->widget);
938 gdk_window_show (priv->bin_window);
939 gdk_window_show (gtk_widget_get_window (widget));
943 gtk_layout_unrealize (GtkWidget *widget)
945 GtkLayout *layout = GTK_LAYOUT (widget);
946 GtkLayoutPrivate *priv = layout->priv;
948 gdk_window_set_user_data (priv->bin_window, NULL);
949 gdk_window_destroy (priv->bin_window);
950 priv->bin_window = NULL;
952 GTK_WIDGET_CLASS (gtk_layout_parent_class)->unrealize (widget);
956 gtk_layout_get_preferred_width (GtkWidget *widget,
960 *minimum = *natural = 0;
964 gtk_layout_get_preferred_height (GtkWidget *widget,
968 *minimum = *natural = 0;
972 gtk_layout_size_allocate (GtkWidget *widget,
973 GtkAllocation *allocation)
975 GtkLayout *layout = GTK_LAYOUT (widget);
976 GtkLayoutPrivate *priv = layout->priv;
979 gtk_widget_set_allocation (widget, allocation);
981 tmp_list = priv->children;
985 GtkLayoutChild *child = tmp_list->data;
986 tmp_list = tmp_list->next;
988 gtk_layout_allocate_child (layout, child);
991 if (gtk_widget_get_realized (widget))
993 gdk_window_move_resize (gtk_widget_get_window (widget),
994 allocation->x, allocation->y,
995 allocation->width, allocation->height);
997 gdk_window_resize (priv->bin_window,
998 MAX (priv->width, allocation->width),
999 MAX (priv->height, allocation->height));
1002 gtk_layout_set_hadjustment_values (layout);
1003 gtk_layout_set_vadjustment_values (layout);
1007 gtk_layout_draw (GtkWidget *widget,
1010 GtkLayout *layout = GTK_LAYOUT (widget);
1011 GtkLayoutPrivate *priv = layout->priv;
1013 if (gtk_cairo_should_draw_window (cr, priv->bin_window))
1014 GTK_WIDGET_CLASS (gtk_layout_parent_class)->draw (widget, cr);
1019 /* Container methods
1022 gtk_layout_add (GtkContainer *container,
1025 gtk_layout_put (GTK_LAYOUT (container), widget, 0, 0);
1029 gtk_layout_remove (GtkContainer *container,
1032 GtkLayout *layout = GTK_LAYOUT (container);
1033 GtkLayoutPrivate *priv = layout->priv;
1035 GtkLayoutChild *child = NULL;
1037 tmp_list = priv->children;
1040 child = tmp_list->data;
1041 if (child->widget == widget)
1043 tmp_list = tmp_list->next;
1048 gtk_widget_unparent (widget);
1050 priv->children = g_list_remove_link (priv->children, tmp_list);
1051 g_list_free_1 (tmp_list);
1057 gtk_layout_forall (GtkContainer *container,
1058 gboolean include_internals,
1059 GtkCallback callback,
1060 gpointer callback_data)
1062 GtkLayout *layout = GTK_LAYOUT (container);
1063 GtkLayoutPrivate *priv = layout->priv;
1064 GtkLayoutChild *child;
1067 tmp_list = priv->children;
1070 child = tmp_list->data;
1071 tmp_list = tmp_list->next;
1073 (* callback) (child->widget, callback_data);
1077 /* Operations on children
1081 gtk_layout_allocate_child (GtkLayout *layout,
1082 GtkLayoutChild *child)
1084 GtkAllocation allocation;
1085 GtkRequisition requisition;
1087 allocation.x = child->x;
1088 allocation.y = child->y;
1090 gtk_widget_get_preferred_size (child->widget, &requisition, NULL);
1091 allocation.width = requisition.width;
1092 allocation.height = requisition.height;
1094 gtk_widget_size_allocate (child->widget, &allocation);
1100 gtk_layout_adjustment_changed (GtkAdjustment *adjustment,
1103 GtkLayoutPrivate *priv = layout->priv;
1105 if (priv->freeze_count)
1108 if (gtk_widget_get_realized (GTK_WIDGET (layout)))
1110 gdk_window_move (priv->bin_window,
1111 - gtk_adjustment_get_value (priv->hadjustment),
1112 - gtk_adjustment_get_value (priv->vadjustment));
1114 gdk_window_process_updates (priv->bin_window, TRUE);