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 "gtkadjustment.h"
37 #include "gtkmarshalers.h"
38 #include "gtkprivate.h"
39 #include "gtkscrollable.h"
44 * @Short_description: Infinite scrollable area containing child widgets
45 * and/or custom drawing
47 * @See_also: #GtkDrawingArea, #GtkScrolledWindow
49 * #GtkLayout is similar to #GtkDrawingArea in that it's a "blank slate"
50 * and doesn't do anything but paint a blank background by default. It's
51 * different in that it supports scrolling natively (you can add it to a
52 * #GtkScrolledWindow), and it can contain child widgets, since it's a
53 * #GtkContainer. However if you're just going to draw, a #GtkDrawingArea
54 * is a better choice since it has lower overhead.
56 * When handling expose events on a #GtkLayout, you must draw to
57 * GTK_LAYOUT (layout)->bin_window, rather than to
58 * GTK_WIDGET (layout)->window, as you would for a drawing
63 typedef struct _GtkLayoutChild GtkLayoutChild;
65 struct _GtkLayoutPrivate
71 GtkAdjustment *hadjustment;
72 GtkAdjustment *vadjustment;
74 /* GtkScrollablePolicy needs to be checked when
75 * driving the scrollable adjustment values */
76 guint hscroll_policy : 1;
77 guint vscroll_policy : 1;
81 GdkVisibilityState visibility;
82 GdkWindow *bin_window;
92 struct _GtkLayoutChild {
114 static void gtk_layout_get_property (GObject *object,
118 static void gtk_layout_set_property (GObject *object,
122 static void gtk_layout_finalize (GObject *object);
123 static void gtk_layout_realize (GtkWidget *widget);
124 static void gtk_layout_unrealize (GtkWidget *widget);
125 static void gtk_layout_map (GtkWidget *widget);
126 static void gtk_layout_get_preferred_width (GtkWidget *widget,
129 static void gtk_layout_get_preferred_height (GtkWidget *widget,
132 static void gtk_layout_size_allocate (GtkWidget *widget,
133 GtkAllocation *allocation);
134 static gint gtk_layout_draw (GtkWidget *widget,
136 static void gtk_layout_add (GtkContainer *container,
138 static void gtk_layout_remove (GtkContainer *container,
140 static void gtk_layout_forall (GtkContainer *container,
141 gboolean include_internals,
142 GtkCallback callback,
143 gpointer callback_data);
144 static void gtk_layout_set_child_property (GtkContainer *container,
149 static void gtk_layout_get_child_property (GtkContainer *container,
154 static void gtk_layout_allocate_child (GtkLayout *layout,
155 GtkLayoutChild *child);
156 static void gtk_layout_adjustment_changed (GtkAdjustment *adjustment,
158 static void gtk_layout_style_updated (GtkWidget *widget);
160 static void gtk_layout_set_hadjustment_values (GtkLayout *layout);
161 static void gtk_layout_set_vadjustment_values (GtkLayout *layout);
163 G_DEFINE_TYPE_WITH_CODE (GtkLayout, gtk_layout, GTK_TYPE_CONTAINER,
164 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
170 * @hadjustment: (allow-none): horizontal scroll adjustment, or %NULL
171 * @vadjustment: (allow-none): vertical scroll adjustment, or %NULL
173 * Creates a new #GtkLayout. Unless you have a specific adjustment
174 * you'd like the layout to use for scrolling, pass %NULL for
175 * @hadjustment and @vadjustment.
177 * Return value: a new #GtkLayout
181 gtk_layout_new (GtkAdjustment *hadjustment,
182 GtkAdjustment *vadjustment)
186 layout = g_object_new (GTK_TYPE_LAYOUT,
187 "hadjustment", hadjustment,
188 "vadjustment", vadjustment,
191 return GTK_WIDGET (layout);
195 * gtk_layout_get_bin_window:
196 * @layout: a #GtkLayout
198 * Retrieve the bin window of the layout used for drawing operations.
200 * Return value: (transfer none): a #GdkWindow
205 gtk_layout_get_bin_window (GtkLayout *layout)
207 g_return_val_if_fail (GTK_IS_LAYOUT (layout), NULL);
209 return layout->priv->bin_window;
213 * gtk_layout_get_hadjustment:
214 * @layout: a #GtkLayout
216 * This function should only be called after the layout has been
217 * placed in a #GtkScrolledWindow or otherwise configured for
218 * scrolling. It returns the #GtkAdjustment used for communication
219 * between the horizontal scrollbar and @layout.
221 * See #GtkScrolledWindow, #GtkScrollbar, #GtkAdjustment for details.
223 * Return value: (transfer none): horizontal scroll adjustment
225 * Deprecated: 3.0: Use gtk_scrollable_get_hadjustment()
228 gtk_layout_get_hadjustment (GtkLayout *layout)
230 g_return_val_if_fail (GTK_IS_LAYOUT (layout), NULL);
232 return layout->priv->hadjustment;
235 * gtk_layout_get_vadjustment:
236 * @layout: a #GtkLayout
238 * This function should only be called after the layout has been
239 * placed in a #GtkScrolledWindow or otherwise configured for
240 * scrolling. It returns the #GtkAdjustment used for communication
241 * between the vertical scrollbar and @layout.
243 * See #GtkScrolledWindow, #GtkScrollbar, #GtkAdjustment for details.
245 * Return value: (transfer none): vertical scroll adjustment
247 * Deprecated: 3.0: Use gtk_scrollable_get_vadjustment()
250 gtk_layout_get_vadjustment (GtkLayout *layout)
252 g_return_val_if_fail (GTK_IS_LAYOUT (layout), NULL);
254 return layout->priv->vadjustment;
258 gtk_layout_set_hadjustment_values (GtkLayout *layout)
260 GtkLayoutPrivate *priv = layout->priv;
261 GtkAllocation allocation;
262 GtkAdjustment *adj = priv->hadjustment;
267 gtk_widget_get_allocation (GTK_WIDGET (layout), &allocation);
269 old_value = gtk_adjustment_get_value (adj);
270 new_upper = MAX (allocation.width, priv->width);
275 "page-size", (gdouble)allocation.width,
276 "step-increment", allocation.width * 0.1,
277 "page-increment", allocation.width * 0.9,
280 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
281 if (new_value != old_value)
282 gtk_adjustment_set_value (adj, new_value);
286 gtk_layout_set_vadjustment_values (GtkLayout *layout)
288 GtkAllocation allocation;
289 GtkAdjustment *adj = layout->priv->vadjustment;
294 gtk_widget_get_allocation (GTK_WIDGET (layout), &allocation);
296 old_value = gtk_adjustment_get_value (adj);
297 new_upper = MAX (allocation.height, layout->priv->height);
302 "page-size", (gdouble)allocation.height,
303 "step-increment", allocation.height * 0.1,
304 "page-increment", allocation.height * 0.9,
307 new_value = CLAMP (old_value, 0, new_upper - allocation.height);
308 if (new_value != old_value)
309 gtk_adjustment_set_value (adj, new_value);
313 gtk_layout_finalize (GObject *object)
315 GtkLayout *layout = GTK_LAYOUT (object);
316 GtkLayoutPrivate *priv = layout->priv;
318 g_object_unref (priv->hadjustment);
319 g_object_unref (priv->vadjustment);
321 G_OBJECT_CLASS (gtk_layout_parent_class)->finalize (object);
325 gtk_layout_do_set_hadjustment (GtkLayout *layout,
326 GtkAdjustment *adjustment)
328 GtkLayoutPrivate *priv;
332 if (adjustment && priv->hadjustment == adjustment)
335 if (priv->hadjustment != NULL)
337 g_signal_handlers_disconnect_by_func (priv->hadjustment,
338 gtk_layout_adjustment_changed,
340 g_object_unref (priv->hadjustment);
343 if (adjustment == NULL)
344 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
346 g_signal_connect (adjustment, "value-changed",
347 G_CALLBACK (gtk_layout_adjustment_changed), layout);
348 priv->hadjustment = g_object_ref_sink (adjustment);
349 gtk_layout_set_hadjustment_values (layout);
351 g_object_notify (G_OBJECT (layout), "hadjustment");
355 * gtk_layout_set_hadjustment:
356 * @layout: a #GtkLayout
357 * @adjustment: (allow-none): new scroll adjustment
359 * Sets the horizontal scroll adjustment for the layout.
361 * See #GtkScrolledWindow, #GtkScrollbar, #GtkAdjustment for details.
363 * Deprecated: 3.0: Use gtk_scrollable_set_hadjustment()
366 gtk_layout_set_hadjustment (GtkLayout *layout,
367 GtkAdjustment *adjustment)
369 g_return_if_fail (GTK_IS_LAYOUT (layout));
370 g_return_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment));
372 gtk_layout_do_set_hadjustment (layout, adjustment);
376 gtk_layout_do_set_vadjustment (GtkLayout *layout,
377 GtkAdjustment *adjustment)
379 GtkLayoutPrivate *priv;
383 if (adjustment && priv->vadjustment == adjustment)
386 if (priv->vadjustment != NULL)
388 g_signal_handlers_disconnect_by_func (priv->vadjustment,
389 gtk_layout_adjustment_changed,
391 g_object_unref (priv->vadjustment);
394 if (adjustment == NULL)
395 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
397 g_signal_connect (adjustment, "value-changed",
398 G_CALLBACK (gtk_layout_adjustment_changed), layout);
399 priv->vadjustment = g_object_ref_sink (adjustment);
400 gtk_layout_set_vadjustment_values (layout);
402 g_object_notify (G_OBJECT (layout), "vadjustment");
406 * gtk_layout_set_vadjustment:
407 * @layout: a #GtkLayout
408 * @adjustment: (allow-none): new scroll adjustment
410 * Sets the vertical scroll adjustment for the layout.
412 * See #GtkScrolledWindow, #GtkScrollbar, #GtkAdjustment for details.
414 * Deprecated: 3.0: Use gtk_scrollable_set_vadjustment()
417 gtk_layout_set_vadjustment (GtkLayout *layout,
418 GtkAdjustment *adjustment)
420 g_return_if_fail (GTK_IS_LAYOUT (layout));
421 g_return_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment));
423 gtk_layout_do_set_vadjustment (layout, adjustment);
426 static GtkLayoutChild*
427 get_child (GtkLayout *layout,
430 GtkLayoutPrivate *priv = layout->priv;
433 children = priv->children;
436 GtkLayoutChild *child;
438 child = children->data;
439 children = children->next;
441 if (child->widget == widget)
450 * @layout: a #GtkLayout
451 * @child_widget: child widget
452 * @x: X position of child widget
453 * @y: Y position of child widget
455 * Adds @child_widget to @layout, at position (@x,@y).
456 * @layout becomes the new parent container of @child_widget.
460 gtk_layout_put (GtkLayout *layout,
461 GtkWidget *child_widget,
465 GtkLayoutPrivate *priv;
466 GtkLayoutChild *child;
468 g_return_if_fail (GTK_IS_LAYOUT (layout));
469 g_return_if_fail (GTK_IS_WIDGET (child_widget));
473 child = g_new (GtkLayoutChild, 1);
475 child->widget = child_widget;
479 priv->children = g_list_append (priv->children, child);
481 if (gtk_widget_get_realized (GTK_WIDGET (layout)))
482 gtk_widget_set_parent_window (child->widget, priv->bin_window);
484 gtk_widget_set_parent (child_widget, GTK_WIDGET (layout));
488 gtk_layout_move_internal (GtkLayout *layout,
495 GtkLayoutChild *child;
497 child = get_child (layout, widget);
501 gtk_widget_freeze_child_notify (widget);
506 gtk_widget_child_notify (widget, "x");
512 gtk_widget_child_notify (widget, "y");
515 gtk_widget_thaw_child_notify (widget);
517 if (gtk_widget_get_visible (widget) &&
518 gtk_widget_get_visible (GTK_WIDGET (layout)))
519 gtk_widget_queue_resize (widget);
524 * @layout: a #GtkLayout
525 * @child_widget: a current child of @layout
526 * @x: X position to move to
527 * @y: Y position to move to
529 * Moves a current child of @layout to a new position.
533 gtk_layout_move (GtkLayout *layout,
534 GtkWidget *child_widget,
538 g_return_if_fail (GTK_IS_LAYOUT (layout));
539 g_return_if_fail (GTK_IS_WIDGET (child_widget));
540 g_return_if_fail (gtk_widget_get_parent (child_widget) == GTK_WIDGET (layout));
542 gtk_layout_move_internal (layout, child_widget, TRUE, x, TRUE, y);
546 * gtk_layout_set_size:
547 * @layout: a #GtkLayout
548 * @width: width of entire scrollable area
549 * @height: height of entire scrollable area
551 * Sets the size of the scrollable area of the layout.
555 gtk_layout_set_size (GtkLayout *layout,
559 GtkLayoutPrivate *priv;
562 g_return_if_fail (GTK_IS_LAYOUT (layout));
565 widget = GTK_WIDGET (layout);
567 g_object_freeze_notify (G_OBJECT (layout));
568 if (width != priv->width)
571 g_object_notify (G_OBJECT (layout), "width");
573 if (height != priv->height)
575 priv->height = height;
576 g_object_notify (G_OBJECT (layout), "height");
578 g_object_thaw_notify (G_OBJECT (layout));
580 if (gtk_widget_get_realized (widget))
582 GtkAllocation allocation;
584 gtk_widget_get_allocation (widget, &allocation);
585 width = MAX (width, allocation.width);
586 height = MAX (height, allocation.height);
587 gdk_window_resize (priv->bin_window, width, height);
590 gtk_layout_set_hadjustment_values (layout);
591 gtk_layout_set_vadjustment_values (layout);
595 * gtk_layout_get_size:
596 * @layout: a #GtkLayout
597 * @width: (out) (allow-none): location to store the width set on
599 * @height: (out) (allow-none): location to store the height set on
602 * Gets the size that has been set on the layout, and that determines
603 * the total extents of the layout's scrollbar area. See
604 * gtk_layout_set_size ().
607 gtk_layout_get_size (GtkLayout *layout,
611 GtkLayoutPrivate *priv;
613 g_return_if_fail (GTK_IS_LAYOUT (layout));
618 *width = priv->width;
620 *height = priv->height;
623 /* Basic Object handling procedures
626 gtk_layout_class_init (GtkLayoutClass *class)
628 GObjectClass *gobject_class;
629 GtkWidgetClass *widget_class;
630 GtkContainerClass *container_class;
632 gobject_class = (GObjectClass*) class;
633 widget_class = (GtkWidgetClass*) class;
634 container_class = (GtkContainerClass*) class;
636 gobject_class->set_property = gtk_layout_set_property;
637 gobject_class->get_property = gtk_layout_get_property;
638 gobject_class->finalize = gtk_layout_finalize;
640 container_class->set_child_property = gtk_layout_set_child_property;
641 container_class->get_child_property = gtk_layout_get_child_property;
643 gtk_container_class_install_child_property (container_class,
645 g_param_spec_int ("x",
647 P_("X position of child widget"),
651 GTK_PARAM_READWRITE));
653 gtk_container_class_install_child_property (container_class,
655 g_param_spec_int ("y",
657 P_("Y position of child widget"),
661 GTK_PARAM_READWRITE));
663 /* Scrollable interface */
664 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
665 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
666 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
667 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
669 g_object_class_install_property (gobject_class,
671 g_param_spec_uint ("width",
673 P_("The width of the layout"),
677 GTK_PARAM_READWRITE));
678 g_object_class_install_property (gobject_class,
680 g_param_spec_uint ("height",
682 P_("The height of the layout"),
686 GTK_PARAM_READWRITE));
687 widget_class->realize = gtk_layout_realize;
688 widget_class->unrealize = gtk_layout_unrealize;
689 widget_class->map = gtk_layout_map;
690 widget_class->get_preferred_width = gtk_layout_get_preferred_width;
691 widget_class->get_preferred_height = gtk_layout_get_preferred_height;
692 widget_class->size_allocate = gtk_layout_size_allocate;
693 widget_class->draw = gtk_layout_draw;
694 widget_class->style_updated = gtk_layout_style_updated;
696 container_class->add = gtk_layout_add;
697 container_class->remove = gtk_layout_remove;
698 container_class->forall = gtk_layout_forall;
700 g_type_class_add_private (class, sizeof (GtkLayoutPrivate));
704 gtk_layout_get_property (GObject *object,
709 GtkLayout *layout = GTK_LAYOUT (object);
710 GtkLayoutPrivate *priv = layout->priv;
714 case PROP_HADJUSTMENT:
715 g_value_set_object (value, priv->hadjustment);
717 case PROP_VADJUSTMENT:
718 g_value_set_object (value, priv->vadjustment);
720 case PROP_HSCROLL_POLICY:
721 g_value_set_enum (value, priv->hscroll_policy);
723 case PROP_VSCROLL_POLICY:
724 g_value_set_enum (value, priv->vscroll_policy);
727 g_value_set_uint (value, priv->width);
730 g_value_set_uint (value, priv->height);
733 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
739 gtk_layout_set_property (GObject *object,
744 GtkLayout *layout = GTK_LAYOUT (object);
745 GtkLayoutPrivate *priv = layout->priv;
749 case PROP_HADJUSTMENT:
750 gtk_layout_do_set_hadjustment (layout, g_value_get_object (value));
752 case PROP_VADJUSTMENT:
753 gtk_layout_do_set_vadjustment (layout, g_value_get_object (value));
755 case PROP_HSCROLL_POLICY:
756 priv->hscroll_policy = g_value_get_enum (value);
757 gtk_widget_queue_resize (GTK_WIDGET (layout));
759 case PROP_VSCROLL_POLICY:
760 priv->vscroll_policy = g_value_get_enum (value);
761 gtk_widget_queue_resize (GTK_WIDGET (layout));
764 gtk_layout_set_size (layout, g_value_get_uint (value),
768 gtk_layout_set_size (layout, priv->width,
769 g_value_get_uint (value));
772 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
778 gtk_layout_set_child_property (GtkContainer *container,
787 gtk_layout_move_internal (GTK_LAYOUT (container),
789 TRUE, g_value_get_int (value),
793 gtk_layout_move_internal (GTK_LAYOUT (container),
796 TRUE, g_value_get_int (value));
799 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
805 gtk_layout_get_child_property (GtkContainer *container,
811 GtkLayoutChild *layout_child;
813 layout_child = get_child (GTK_LAYOUT (container), child);
818 g_value_set_int (value, layout_child->x);
821 g_value_set_int (value, layout_child->y);
824 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
830 gtk_layout_init (GtkLayout *layout)
832 GtkLayoutPrivate *priv;
834 layout->priv = G_TYPE_INSTANCE_GET_PRIVATE (layout,
839 priv->children = NULL;
844 priv->hadjustment = NULL;
845 priv->vadjustment = NULL;
847 priv->bin_window = NULL;
851 priv->visibility = GDK_VISIBILITY_PARTIAL;
853 priv->freeze_count = 0;
860 gtk_layout_realize (GtkWidget *widget)
862 GtkLayout *layout = GTK_LAYOUT (widget);
863 GtkLayoutPrivate *priv = layout->priv;
864 GtkAllocation allocation;
866 GdkWindowAttr attributes;
868 gint attributes_mask;
870 gtk_widget_set_realized (widget, TRUE);
872 gtk_widget_get_allocation (widget, &allocation);
874 attributes.window_type = GDK_WINDOW_CHILD;
875 attributes.x = allocation.x;
876 attributes.y = allocation.y;
877 attributes.width = allocation.width;
878 attributes.height = allocation.height;
879 attributes.wclass = GDK_INPUT_OUTPUT;
880 attributes.visual = gtk_widget_get_visual (widget);
881 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
883 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
885 window = gdk_window_new (gtk_widget_get_parent_window (widget),
886 &attributes, attributes_mask);
887 gtk_widget_set_window (widget, window);
888 gtk_widget_register_window (widget, window);
890 gtk_widget_get_allocation (widget, &allocation);
892 attributes.x = - gtk_adjustment_get_value (priv->hadjustment),
893 attributes.y = - gtk_adjustment_get_value (priv->vadjustment);
894 attributes.width = MAX (priv->width, allocation.width);
895 attributes.height = MAX (priv->height, allocation.height);
896 attributes.event_mask = GDK_EXPOSURE_MASK | GDK_SCROLL_MASK |
897 GDK_SMOOTH_SCROLL_MASK |
898 gtk_widget_get_events (widget);
900 priv->bin_window = gdk_window_new (window,
901 &attributes, attributes_mask);
902 gtk_widget_register_window (widget, priv->bin_window);
903 gtk_style_context_set_background (gtk_widget_get_style_context (widget), priv->bin_window);
905 tmp_list = priv->children;
908 GtkLayoutChild *child = tmp_list->data;
909 tmp_list = tmp_list->next;
911 gtk_widget_set_parent_window (child->widget, priv->bin_window);
916 gtk_layout_style_updated (GtkWidget *widget)
918 GtkLayoutPrivate *priv;
920 GTK_WIDGET_CLASS (gtk_layout_parent_class)->style_updated (widget);
922 if (gtk_widget_get_realized (widget))
924 priv = GTK_LAYOUT (widget)->priv;
925 gtk_style_context_set_background (gtk_widget_get_style_context (widget), priv->bin_window);
930 gtk_layout_map (GtkWidget *widget)
932 GtkLayout *layout = GTK_LAYOUT (widget);
933 GtkLayoutPrivate *priv = layout->priv;
936 gtk_widget_set_mapped (widget, TRUE);
938 tmp_list = priv->children;
941 GtkLayoutChild *child = tmp_list->data;
942 tmp_list = tmp_list->next;
944 if (gtk_widget_get_visible (child->widget))
946 if (!gtk_widget_get_mapped (child->widget))
947 gtk_widget_map (child->widget);
951 gdk_window_show (priv->bin_window);
952 gdk_window_show (gtk_widget_get_window (widget));
956 gtk_layout_unrealize (GtkWidget *widget)
958 GtkLayout *layout = GTK_LAYOUT (widget);
959 GtkLayoutPrivate *priv = layout->priv;
961 gtk_widget_unregister_window (widget, priv->bin_window);
962 gdk_window_destroy (priv->bin_window);
963 priv->bin_window = NULL;
965 GTK_WIDGET_CLASS (gtk_layout_parent_class)->unrealize (widget);
969 gtk_layout_get_preferred_width (GtkWidget *widget,
973 *minimum = *natural = 0;
977 gtk_layout_get_preferred_height (GtkWidget *widget,
981 *minimum = *natural = 0;
985 gtk_layout_size_allocate (GtkWidget *widget,
986 GtkAllocation *allocation)
988 GtkLayout *layout = GTK_LAYOUT (widget);
989 GtkLayoutPrivate *priv = layout->priv;
992 gtk_widget_set_allocation (widget, allocation);
994 tmp_list = priv->children;
998 GtkLayoutChild *child = tmp_list->data;
999 tmp_list = tmp_list->next;
1001 gtk_layout_allocate_child (layout, child);
1004 if (gtk_widget_get_realized (widget))
1006 gdk_window_move_resize (gtk_widget_get_window (widget),
1007 allocation->x, allocation->y,
1008 allocation->width, allocation->height);
1010 gdk_window_resize (priv->bin_window,
1011 MAX (priv->width, allocation->width),
1012 MAX (priv->height, allocation->height));
1015 gtk_layout_set_hadjustment_values (layout);
1016 gtk_layout_set_vadjustment_values (layout);
1020 gtk_layout_draw (GtkWidget *widget,
1023 GtkLayout *layout = GTK_LAYOUT (widget);
1024 GtkLayoutPrivate *priv = layout->priv;
1026 if (gtk_cairo_should_draw_window (cr, priv->bin_window))
1027 GTK_WIDGET_CLASS (gtk_layout_parent_class)->draw (widget, cr);
1032 /* Container methods
1035 gtk_layout_add (GtkContainer *container,
1038 gtk_layout_put (GTK_LAYOUT (container), widget, 0, 0);
1042 gtk_layout_remove (GtkContainer *container,
1045 GtkLayout *layout = GTK_LAYOUT (container);
1046 GtkLayoutPrivate *priv = layout->priv;
1048 GtkLayoutChild *child = NULL;
1050 tmp_list = priv->children;
1053 child = tmp_list->data;
1054 if (child->widget == widget)
1056 tmp_list = tmp_list->next;
1061 gtk_widget_unparent (widget);
1063 priv->children = g_list_remove_link (priv->children, tmp_list);
1064 g_list_free_1 (tmp_list);
1070 gtk_layout_forall (GtkContainer *container,
1071 gboolean include_internals,
1072 GtkCallback callback,
1073 gpointer callback_data)
1075 GtkLayout *layout = GTK_LAYOUT (container);
1076 GtkLayoutPrivate *priv = layout->priv;
1077 GtkLayoutChild *child;
1080 tmp_list = priv->children;
1083 child = tmp_list->data;
1084 tmp_list = tmp_list->next;
1086 (* callback) (child->widget, callback_data);
1090 /* Operations on children
1094 gtk_layout_allocate_child (GtkLayout *layout,
1095 GtkLayoutChild *child)
1097 GtkAllocation allocation;
1098 GtkRequisition requisition;
1100 allocation.x = child->x;
1101 allocation.y = child->y;
1103 gtk_widget_get_preferred_size (child->widget, &requisition, NULL);
1104 allocation.width = requisition.width;
1105 allocation.height = requisition.height;
1107 gtk_widget_size_allocate (child->widget, &allocation);
1113 gtk_layout_adjustment_changed (GtkAdjustment *adjustment,
1116 GtkLayoutPrivate *priv = layout->priv;
1118 if (priv->freeze_count)
1121 if (gtk_widget_get_realized (GTK_WIDGET (layout)))
1123 gdk_window_move (priv->bin_window,
1124 - gtk_adjustment_get_value (priv->hadjustment),
1125 - gtk_adjustment_get_value (priv->vadjustment));