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.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30 #include "gtkorientable.h"
31 #include "gtkextendedlayout.h"
32 #include "gtkprivate.h"
53 typedef struct _GtkBoxPrivate GtkBoxPrivate;
57 GtkOrientation orientation;
58 guint default_expand : 1;
59 guint spacing_set : 1;
62 #define GTK_BOX_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_BOX, GtkBoxPrivate))
64 typedef struct _GtkBoxDesiredSizes GtkBoxDesiredSizes;
65 typedef struct _GtkBoxSpreading GtkBoxSpreading;
67 struct _GtkBoxDesiredSizes
73 struct _GtkBoxSpreading
79 static void gtk_box_get_desired_size (GtkExtendedLayout *layout,
80 GtkRequisition *minimum_size,
81 GtkRequisition *natural_size);
82 static void gtk_box_size_allocate (GtkWidget *widget,
83 GtkAllocation *allocation);
84 static void gtk_box_layout_interface_init (GtkExtendedLayoutIface *iface);
86 static void gtk_box_set_property (GObject *object,
90 static void gtk_box_get_property (GObject *object,
95 static void gtk_box_add (GtkContainer *container,
97 static void gtk_box_remove (GtkContainer *container,
99 static void gtk_box_forall (GtkContainer *container,
100 gboolean include_internals,
101 GtkCallback callback,
102 gpointer callback_data);
103 static void gtk_box_set_child_property (GtkContainer *container,
108 static void gtk_box_get_child_property (GtkContainer *container,
113 static GType gtk_box_child_type (GtkContainer *container);
116 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GtkBox, gtk_box, GTK_TYPE_CONTAINER,
117 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
119 G_IMPLEMENT_INTERFACE (GTK_TYPE_EXTENDED_LAYOUT,
120 gtk_box_layout_interface_init));
123 gtk_box_class_init (GtkBoxClass *class)
125 GObjectClass *object_class = G_OBJECT_CLASS (class);
126 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
127 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
129 object_class->set_property = gtk_box_set_property;
130 object_class->get_property = gtk_box_get_property;
132 widget_class->size_allocate = gtk_box_size_allocate;
134 container_class->add = gtk_box_add;
135 container_class->remove = gtk_box_remove;
136 container_class->forall = gtk_box_forall;
137 container_class->child_type = gtk_box_child_type;
138 container_class->set_child_property = gtk_box_set_child_property;
139 container_class->get_child_property = gtk_box_get_child_property;
141 g_object_class_override_property (object_class,
145 g_object_class_install_property (object_class,
147 g_param_spec_int ("spacing",
149 P_("The amount of space between children"),
153 GTK_PARAM_READWRITE));
155 g_object_class_install_property (object_class,
157 g_param_spec_boolean ("homogeneous",
159 P_("Whether the children should all be the same size"),
161 GTK_PARAM_READWRITE));
163 gtk_container_class_install_child_property (container_class,
165 g_param_spec_boolean ("expand",
167 P_("Whether the child should receive extra space when the parent grows"),
169 GTK_PARAM_READWRITE));
170 gtk_container_class_install_child_property (container_class,
172 g_param_spec_boolean ("fill",
174 P_("Whether extra space given to the child should be allocated to the child or used as padding"),
176 GTK_PARAM_READWRITE));
177 gtk_container_class_install_child_property (container_class,
179 g_param_spec_uint ("padding",
181 P_("Extra space to put between the child and its neighbors, in pixels"),
183 GTK_PARAM_READWRITE));
184 gtk_container_class_install_child_property (container_class,
185 CHILD_PROP_PACK_TYPE,
186 g_param_spec_enum ("pack-type",
188 P_("A GtkPackType indicating whether the child is packed with reference to the start or end of the parent"),
189 GTK_TYPE_PACK_TYPE, GTK_PACK_START,
190 GTK_PARAM_READWRITE));
191 gtk_container_class_install_child_property (container_class,
193 g_param_spec_int ("position",
195 P_("The index of the child in the parent"),
197 GTK_PARAM_READWRITE));
199 g_type_class_add_private (object_class, sizeof (GtkBoxPrivate));
203 gtk_box_layout_interface_init (GtkExtendedLayoutIface *iface)
205 iface->get_desired_size = gtk_box_get_desired_size;
209 gtk_box_init (GtkBox *box)
211 GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
213 gtk_widget_set_has_window (GTK_WIDGET (box), FALSE);
214 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (box), FALSE);
216 box->children = NULL;
218 box->homogeneous = FALSE;
220 private->orientation = GTK_ORIENTATION_HORIZONTAL;
221 private->default_expand = FALSE;
222 private->spacing_set = FALSE;
226 gtk_box_set_property (GObject *object,
231 GtkBox *box = GTK_BOX (object);
232 GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
236 case PROP_ORIENTATION:
237 private->orientation = g_value_get_enum (value);
238 gtk_widget_queue_resize (GTK_WIDGET (box));
241 gtk_box_set_spacing (box, g_value_get_int (value));
243 case PROP_HOMOGENEOUS:
244 gtk_box_set_homogeneous (box, g_value_get_boolean (value));
247 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
253 gtk_box_get_property (GObject *object,
258 GtkBox *box = GTK_BOX (object);
259 GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
263 case PROP_ORIENTATION:
264 g_value_set_enum (value, private->orientation);
267 g_value_set_int (value, box->spacing);
269 case PROP_HOMOGENEOUS:
270 g_value_set_boolean (value, box->homogeneous);
273 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
279 gtk_box_get_desired_size (GtkExtendedLayout *layout,
280 GtkRequisition *minimum_size,
281 GtkRequisition *natural_size)
284 GtkBoxPrivate *private;
289 box = GTK_BOX (layout);
290 private = GTK_BOX_GET_PRIVATE (box);
291 border_width = GTK_CONTAINER (box)->border_width;
293 minimum_size->width = minimum_size->height = 0;
294 natural_size->width = natural_size->height = 0;
297 children = box->children;
302 child = children->data;
303 children = children->next;
305 if (gtk_widget_get_visible (child->widget))
307 GtkRequisition child_minimum_size;
308 GtkRequisition child_natural_size;
310 gtk_extended_layout_get_desired_size (GTK_EXTENDED_LAYOUT (child->widget),
312 &child_natural_size);
314 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
316 if (box->homogeneous)
320 width = child_minimum_size.width + child->padding * 2;
321 minimum_size->width = MAX (minimum_size->width, width);
323 width = child_natural_size.width + child->padding * 2;
324 natural_size->width = MAX (natural_size->width, width);
328 minimum_size->width += child_minimum_size.width + child->padding * 2;
329 natural_size->width += child_natural_size.width + child->padding * 2;
332 minimum_size->height = MAX (minimum_size->height, child_minimum_size.height);
333 natural_size->height = MAX (natural_size->height, child_natural_size.height);
337 if (box->homogeneous)
341 height = child_minimum_size.height + child->padding * 2;
342 minimum_size->height = MAX (minimum_size->height, height);
344 height = child_natural_size.height + child->padding * 2;
345 natural_size->height = MAX (natural_size->height, height);
349 minimum_size->height += child_minimum_size.height + child->padding * 2;
350 natural_size->height += child_natural_size.height + child->padding * 2;
353 minimum_size->width = MAX (minimum_size->width, child_minimum_size.width);
354 natural_size->width = MAX (natural_size->width, child_natural_size.width);
361 if (nvis_children > 0)
363 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
365 if (box->homogeneous)
367 minimum_size->width *= nvis_children;
368 natural_size->width *= nvis_children;
371 minimum_size->width += (nvis_children - 1) * box->spacing;
372 natural_size->width += (nvis_children - 1) * box->spacing;
376 if (box->homogeneous)
378 minimum_size->height *= nvis_children;
379 natural_size->height *= nvis_children;
382 minimum_size->height += (nvis_children - 1) * box->spacing;
383 natural_size->height += (nvis_children - 1) * box->spacing;
387 minimum_size->width += border_width * 2;
388 minimum_size->height += border_width * 2;
390 natural_size->width += border_width * 2;
391 natural_size->height += border_width * 2;
395 gtk_box_compare_gap (gconstpointer p1,
399 GtkBoxDesiredSizes *sizes = data;
400 const GtkBoxSpreading *c1 = p1;
401 const GtkBoxSpreading *c2 = p2;
403 const gint d1 = MAX (sizes[c1->index].natural_size -
404 sizes[c1->index].minimum_size,
406 const gint d2 = MAX (sizes[c2->index].natural_size -
407 sizes[c2->index].minimum_size,
410 gint delta = (d2 - d1);
413 delta = (c2->index - c1->index);
419 gtk_box_size_allocate (GtkWidget *widget,
420 GtkAllocation *allocation)
422 GtkBox *box = GTK_BOX (widget);
423 GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
427 gint nexpand_children;
429 widget->allocation = *allocation;
432 nexpand_children = 0;
434 for (children = box->children; children; children = children->next)
436 child = children->data;
438 if (gtk_widget_get_visible (child->widget))
442 nexpand_children += 1;
446 if (nvis_children > 0)
448 gint border_width = GTK_CONTAINER (box)->border_width;
449 GtkTextDirection direction = gtk_widget_get_direction (widget);
450 GtkAllocation child_allocation;
451 GtkBoxSpreading *spreading = g_newa (GtkBoxSpreading, nvis_children);
452 GtkBoxDesiredSizes *sizes = g_newa (GtkBoxDesiredSizes, nvis_children);
461 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
462 size = allocation->width - border_width * 2 - (nvis_children - 1) * box->spacing;
464 size = allocation->height - border_width * 2 - (nvis_children - 1) * box->spacing;
466 if (box->homogeneous)
468 extra = size / nvis_children;
472 /* Retrieve desired size for visible children */
474 children = box->children;
477 child = children->data;
478 children = children->next;
480 if (gtk_widget_get_visible (child->widget))
482 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
483 gtk_extended_layout_get_width_for_height (GTK_EXTENDED_LAYOUT (child->widget),
485 &sizes[i].minimum_size,
486 &sizes[i].natural_size);
488 gtk_extended_layout_get_height_for_width (GTK_EXTENDED_LAYOUT (child->widget),
490 &sizes[i].minimum_size,
491 &sizes[i].natural_size);
493 size -= sizes[i].minimum_size;
494 size -= child->padding * 2;
496 spreading[i].index = i;
497 spreading[i].child = child;
503 /* Distribute the container's extra space c_gap. We want to assign
504 * this space such that the sum of extra space assigned to children
505 * (c^i_gap) is equal to c_cap. The case that there's not enough
506 * space for all children to take their natural size needs some
507 * attention. The goals we want to achieve are:
509 * a) Maximize number of children taking their natural size.
510 * b) The allocated size of children should be a continuous
511 * function of c_gap. That is, increasing the container size by
512 * one pixel should never make drastic changes in the distribution.
513 * c) If child i takes its natural size and child j doesn't,
514 * child j should have received at least as much gap as child i.
516 * The following code distributes the additional space by following
520 /* Sort descending by gap and position. */
522 g_qsort_with_data (spreading,
523 nvis_children, sizeof (GtkBoxSpreading),
524 gtk_box_compare_gap, sizes);
526 /* Distribute available space.
527 * This master piece of a loop was conceived by Behdad Esfahbod.
529 for (i = nvis_children - 1; i >= 0; --i)
531 /* Divide remaining space by number of remaining children.
532 * Sort order and reducing remaining space by assigned space
533 * ensures that space is distributed equally.
535 gint glue = (size + i) / (i + 1);
536 gint gap = sizes[spreading[i].index].natural_size
537 - sizes[spreading[i].index].minimum_size;
539 extra = MIN (glue, gap);
540 sizes[spreading[i].index].minimum_size += extra;
545 /* Calculate space which hasn't distributed yet,
546 * and is available for expanding children.
548 if (nexpand_children > 0)
549 extra = size / nexpand_children;
554 /* Allocate child positions. */
556 for (packing = GTK_PACK_START; packing <= GTK_PACK_END; ++packing)
558 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
560 child_allocation.y = allocation->y + border_width;
561 child_allocation.height = MAX (1, allocation->height - border_width * 2);
562 if (packing == GTK_PACK_START)
563 x = allocation->x + border_width;
565 x = allocation->x + allocation->width - border_width;
569 child_allocation.x = allocation->x + border_width;
570 child_allocation.width = MAX (1, allocation->width - border_width * 2);
571 if (packing == GTK_PACK_START)
572 y = allocation->y + border_width;
574 y = allocation->y + allocation->height - border_width;
578 children = box->children;
581 child = children->data;
582 children = children->next;
584 if (gtk_widget_get_visible (child->widget))
586 if (child->pack == packing)
588 /* Assign the child's size. */
590 if (box->homogeneous)
592 if (nvis_children == 1)
602 child_size = sizes[i].minimum_size + child->padding * 2;
606 if (nexpand_children == 1)
611 nexpand_children -= 1;
616 /* Assign the child's position. */
618 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
622 child_allocation.width = MAX (1, child_size - child->padding * 2);
623 child_allocation.x = x + child->padding;
627 child_allocation.width = sizes[i].minimum_size;
628 child_allocation.x = x + (child_size - child_allocation.width) / 2;
631 if (direction == GTK_TEXT_DIR_RTL)
632 child_allocation.x = allocation->x + allocation->width - (child_allocation.x - allocation->x) - child_allocation.width;
634 if (packing == GTK_PACK_START)
636 x += child_size + box->spacing;
640 x -= child_size + box->spacing;
642 child_allocation.x -= child_allocation.width;
649 child_allocation.height = MAX (1, child_size - child->padding * 2);
650 child_allocation.y = y + child->padding;
654 child_allocation.height = sizes[i].minimum_size;
655 child_allocation.y = y + (child_size - child_allocation.height) / 2;
658 if (packing == GTK_PACK_START)
660 y += child_size + box->spacing;
664 y -= child_size + box->spacing;
666 child_allocation.y -= child_allocation.height;
670 gtk_widget_size_allocate (child->widget, &child_allocation);
680 gtk_box_child_type (GtkContainer *container)
682 return GTK_TYPE_WIDGET;
686 gtk_box_set_child_property (GtkContainer *container,
695 GtkPackType pack_type = 0;
697 if (property_id != CHILD_PROP_POSITION)
698 gtk_box_query_child_packing (GTK_BOX (container),
706 case CHILD_PROP_EXPAND:
707 gtk_box_set_child_packing (GTK_BOX (container),
709 g_value_get_boolean (value),
714 case CHILD_PROP_FILL:
715 gtk_box_set_child_packing (GTK_BOX (container),
718 g_value_get_boolean (value),
722 case CHILD_PROP_PADDING:
723 gtk_box_set_child_packing (GTK_BOX (container),
727 g_value_get_uint (value),
730 case CHILD_PROP_PACK_TYPE:
731 gtk_box_set_child_packing (GTK_BOX (container),
736 g_value_get_enum (value));
738 case CHILD_PROP_POSITION:
739 gtk_box_reorder_child (GTK_BOX (container),
741 g_value_get_int (value));
744 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
750 gtk_box_get_child_property (GtkContainer *container,
759 GtkPackType pack_type = 0;
762 if (property_id != CHILD_PROP_POSITION)
763 gtk_box_query_child_packing (GTK_BOX (container),
772 case CHILD_PROP_EXPAND:
773 g_value_set_boolean (value, expand);
775 case CHILD_PROP_FILL:
776 g_value_set_boolean (value, fill);
778 case CHILD_PROP_PADDING:
779 g_value_set_uint (value, padding);
781 case CHILD_PROP_PACK_TYPE:
782 g_value_set_enum (value, pack_type);
784 case CHILD_PROP_POSITION:
786 for (list = GTK_BOX (container)->children; list; list = list->next)
788 GtkBoxChild *child_entry;
790 child_entry = list->data;
791 if (child_entry->widget == child)
795 g_value_set_int (value, list ? i : -1);
798 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
804 gtk_box_pack (GtkBox *box,
809 GtkPackType pack_type)
811 GtkBoxChild *child_info;
813 g_return_if_fail (GTK_IS_BOX (box));
814 g_return_if_fail (GTK_IS_WIDGET (child));
815 g_return_if_fail (child->parent == NULL);
817 child_info = g_new (GtkBoxChild, 1);
818 child_info->widget = child;
819 child_info->padding = padding;
820 child_info->expand = expand ? TRUE : FALSE;
821 child_info->fill = fill ? TRUE : FALSE;
822 child_info->pack = pack_type;
823 child_info->is_secondary = FALSE;
825 box->children = g_list_append (box->children, child_info);
827 gtk_widget_freeze_child_notify (child);
829 gtk_widget_set_parent (child, GTK_WIDGET (box));
831 gtk_widget_child_notify (child, "expand");
832 gtk_widget_child_notify (child, "fill");
833 gtk_widget_child_notify (child, "padding");
834 gtk_widget_child_notify (child, "pack-type");
835 gtk_widget_child_notify (child, "position");
836 gtk_widget_thaw_child_notify (child);
841 * @orientation: the box' orientation.
842 * @homogeneous: %TRUE if all children are to be given equal space allocations.
843 * @spacing: the number of pixels to place by default between children.
845 * Creates a new #GtkHBox.
847 * Return value: a new #GtkHBox.
852 _gtk_box_new (GtkOrientation orientation,
853 gboolean homogeneous,
856 return g_object_new (GTK_TYPE_BOX,
857 "orientation", orientation,
859 "homogeneous", homogeneous ? TRUE : FALSE,
864 * gtk_box_pack_start:
866 * @child: the #GtkWidget to be added to @box
867 * @expand: %TRUE if the new child is to be given extra space allocated to
868 * @box. The extra space will be divided evenly between all children of
869 * @box that use this option
870 * @fill: %TRUE if space given to @child by the @expand option is
871 * actually allocated to @child, rather than just padding it. This
872 * parameter has no effect if @expand is set to %FALSE. A child is
873 * always allocated the full height of a #GtkHBox and the full width
874 * of a #GtkVBox. This option affects the other dimension
875 * @padding: extra space in pixels to put between this child and its
876 * neighbors, over and above the global amount specified by
877 * #GtkBox:spacing property. If @child is a widget at one of the
878 * reference ends of @box, then @padding pixels are also put between
879 * @child and the reference edge of @box
881 * Adds @child to @box, packed with reference to the start of @box.
882 * The @child is packed after any other child packed with reference
883 * to the start of @box.
886 gtk_box_pack_start (GtkBox *box,
892 gtk_box_pack (box, child, expand, fill, padding, GTK_PACK_START);
898 * @child: the #GtkWidget to be added to @box
899 * @expand: %TRUE if the new child is to be given extra space allocated
900 * to @box. The extra space will be divided evenly between all children
901 * of @box that use this option
902 * @fill: %TRUE if space given to @child by the @expand option is
903 * actually allocated to @child, rather than just padding it. This
904 * parameter has no effect if @expand is set to %FALSE. A child is
905 * always allocated the full height of a #GtkHBox and the full width
906 * of a #GtkVBox. This option affects the other dimension
907 * @padding: extra space in pixels to put between this child and its
908 * neighbors, over and above the global amount specified by
909 * #GtkBox:spacing property. If @child is a widget at one of the
910 * reference ends of @box, then @padding pixels are also put between
911 * @child and the reference edge of @box
913 * Adds @child to @box, packed with reference to the end of @box.
914 * The @child is packed after (away from end of) any other child
915 * packed with reference to the end of @box.
918 gtk_box_pack_end (GtkBox *box,
924 gtk_box_pack (box, child, expand, fill, padding, GTK_PACK_END);
928 * gtk_box_pack_start_defaults:
930 * @widget: the #GtkWidget to be added to @box
932 * Adds @widget to @box, packed with reference to the start of @box.
933 * The child is packed after any other child packed with reference
934 * to the start of @box.
936 * Parameters for how to pack the child @widget, #GtkBox:expand,
937 * #GtkBox:fill and #GtkBox:padding, are given their default
938 * values, %TRUE, %TRUE, and 0, respectively.
940 * Deprecated: 2.14: Use gtk_box_pack_start()
943 gtk_box_pack_start_defaults (GtkBox *box,
946 gtk_box_pack_start (box, child, TRUE, TRUE, 0);
950 * gtk_box_pack_end_defaults:
952 * @widget: the #GtkWidget to be added to @box
954 * Adds @widget to @box, packed with reference to the end of @box.
955 * The child is packed after any other child packed with reference
956 * to the start of @box.
958 * Parameters for how to pack the child @widget, #GtkBox:expand,
959 * #GtkBox:fill and #GtkBox:padding, are given their default
960 * values, %TRUE, %TRUE, and 0, respectively.
962 * Deprecated: 2.14: Use gtk_box_pack_end()
965 gtk_box_pack_end_defaults (GtkBox *box,
968 gtk_box_pack_end (box, child, TRUE, TRUE, 0);
972 * gtk_box_set_homogeneous:
974 * @homogeneous: a boolean value, %TRUE to create equal allotments,
975 * %FALSE for variable allotments
977 * Sets the #GtkBox:homogeneous property of @box, controlling
978 * whether or not all children of @box are given equal space
982 gtk_box_set_homogeneous (GtkBox *box,
983 gboolean homogeneous)
985 g_return_if_fail (GTK_IS_BOX (box));
987 if ((homogeneous ? TRUE : FALSE) != box->homogeneous)
989 box->homogeneous = homogeneous ? TRUE : FALSE;
990 g_object_notify (G_OBJECT (box), "homogeneous");
991 gtk_widget_queue_resize (GTK_WIDGET (box));
996 * gtk_box_get_homogeneous:
999 * Returns whether the box is homogeneous (all children are the
1000 * same size). See gtk_box_set_homogeneous().
1002 * Return value: %TRUE if the box is homogeneous.
1005 gtk_box_get_homogeneous (GtkBox *box)
1007 g_return_val_if_fail (GTK_IS_BOX (box), FALSE);
1009 return box->homogeneous;
1013 * gtk_box_set_spacing:
1015 * @spacing: the number of pixels to put between children
1017 * Sets the #GtkBox:spacing property of @box, which is the
1018 * number of pixels to place between children of @box.
1021 gtk_box_set_spacing (GtkBox *box,
1024 g_return_if_fail (GTK_IS_BOX (box));
1026 if (spacing != box->spacing)
1028 box->spacing = spacing;
1029 _gtk_box_set_spacing_set (box, TRUE);
1031 g_object_notify (G_OBJECT (box), "spacing");
1033 gtk_widget_queue_resize (GTK_WIDGET (box));
1038 * gtk_box_get_spacing:
1041 * Gets the value set by gtk_box_set_spacing().
1043 * Return value: spacing between children
1046 gtk_box_get_spacing (GtkBox *box)
1048 g_return_val_if_fail (GTK_IS_BOX (box), 0);
1050 return box->spacing;
1054 _gtk_box_set_spacing_set (GtkBox *box,
1055 gboolean spacing_set)
1057 GtkBoxPrivate *private;
1059 g_return_if_fail (GTK_IS_BOX (box));
1061 private = GTK_BOX_GET_PRIVATE (box);
1063 private->spacing_set = spacing_set ? TRUE : FALSE;
1067 _gtk_box_get_spacing_set (GtkBox *box)
1069 GtkBoxPrivate *private;
1071 g_return_val_if_fail (GTK_IS_BOX (box), FALSE);
1073 private = GTK_BOX_GET_PRIVATE (box);
1075 return private->spacing_set;
1079 * gtk_box_reorder_child:
1081 * @child: the #GtkWidget to move
1082 * @position: the new position for @child in the list of children
1083 * of @box, starting from 0. If negative, indicates the end of
1086 * Moves @child to a new @position in the list of @box children.
1087 * The list is the <structfield>children</structfield> field of
1088 * #GtkBox-struct, and contains both widgets packed #GTK_PACK_START
1089 * as well as widgets packed #GTK_PACK_END, in the order that these
1090 * widgets were added to @box.
1092 * A widget's position in the @box children list determines where
1093 * the widget is packed into @box. A child widget at some position
1094 * in the list will be packed just after all other widgets of the
1095 * same packing type that appear earlier in the list.
1098 gtk_box_reorder_child (GtkBox *box,
1104 GtkBoxChild *child_info = NULL;
1107 g_return_if_fail (GTK_IS_BOX (box));
1108 g_return_if_fail (GTK_IS_WIDGET (child));
1110 old_link = box->children;
1114 child_info = old_link->data;
1115 if (child_info->widget == child)
1118 old_link = old_link->next;
1122 g_return_if_fail (old_link != NULL);
1124 if (position == old_position)
1127 box->children = g_list_delete_link (box->children, old_link);
1132 new_link = g_list_nth (box->children, position);
1134 box->children = g_list_insert_before (box->children, new_link, child_info);
1136 gtk_widget_child_notify (child, "position");
1137 if (gtk_widget_get_visible (child)
1138 && gtk_widget_get_visible (GTK_WIDGET (box)))
1139 gtk_widget_queue_resize (child);
1143 * gtk_box_query_child_packing:
1145 * @child: the #GtkWidget of the child to query
1146 * @expand: pointer to return location for #GtkBox:expand child property
1147 * @fill: pointer to return location for #GtkBox:fill child property
1148 * @padding: pointer to return location for #GtkBox:padding child property
1149 * @pack_type: pointer to return location for #GtkBox:pack-type child property
1151 * Obtains information about how @child is packed into @box.
1154 gtk_box_query_child_packing (GtkBox *box,
1159 GtkPackType *pack_type)
1162 GtkBoxChild *child_info = NULL;
1164 g_return_if_fail (GTK_IS_BOX (box));
1165 g_return_if_fail (GTK_IS_WIDGET (child));
1167 list = box->children;
1170 child_info = list->data;
1171 if (child_info->widget == child)
1180 *expand = child_info->expand;
1182 *fill = child_info->fill;
1184 *padding = child_info->padding;
1186 *pack_type = child_info->pack;
1191 * gtk_box_set_child_packing:
1193 * @child: the #GtkWidget of the child to set
1194 * @expand: the new value of the #GtkBox:expand child property
1195 * @fill: the new value of the #GtkBox:fill child property
1196 * @padding: the new value of the #GtkBox:padding child property
1197 * @pack_type: the new value of the #GtkBox:pack-type child property
1199 * Sets the way @child is packed into @box.
1202 gtk_box_set_child_packing (GtkBox *box,
1207 GtkPackType pack_type)
1210 GtkBoxChild *child_info = NULL;
1212 g_return_if_fail (GTK_IS_BOX (box));
1213 g_return_if_fail (GTK_IS_WIDGET (child));
1215 list = box->children;
1218 child_info = list->data;
1219 if (child_info->widget == child)
1225 gtk_widget_freeze_child_notify (child);
1228 child_info->expand = expand != FALSE;
1229 gtk_widget_child_notify (child, "expand");
1230 child_info->fill = fill != FALSE;
1231 gtk_widget_child_notify (child, "fill");
1232 child_info->padding = padding;
1233 gtk_widget_child_notify (child, "padding");
1234 if (pack_type == GTK_PACK_END)
1235 child_info->pack = GTK_PACK_END;
1237 child_info->pack = GTK_PACK_START;
1238 gtk_widget_child_notify (child, "pack-type");
1240 if (gtk_widget_get_visible (child)
1241 && gtk_widget_get_visible (GTK_WIDGET (box)))
1242 gtk_widget_queue_resize (child);
1244 gtk_widget_thaw_child_notify (child);
1248 _gtk_box_set_old_defaults (GtkBox *box)
1250 GtkBoxPrivate *private;
1252 g_return_if_fail (GTK_IS_BOX (box));
1254 private = GTK_BOX_GET_PRIVATE (box);
1256 private->default_expand = TRUE;
1260 gtk_box_add (GtkContainer *container,
1263 GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (container);
1265 gtk_box_pack_start (GTK_BOX (container), widget,
1266 private->default_expand,
1267 private->default_expand,
1272 gtk_box_remove (GtkContainer *container,
1275 GtkBox *box = GTK_BOX (container);
1279 children = box->children;
1282 child = children->data;
1284 if (child->widget == widget)
1286 gboolean was_visible;
1288 was_visible = gtk_widget_get_visible (widget);
1289 gtk_widget_unparent (widget);
1291 box->children = g_list_remove_link (box->children, children);
1292 g_list_free (children);
1295 /* queue resize regardless of gtk_widget_get_visible (container),
1296 * since that's what is needed by toplevels.
1299 gtk_widget_queue_resize (GTK_WIDGET (container));
1304 children = children->next;
1309 gtk_box_forall (GtkContainer *container,
1310 gboolean include_internals,
1311 GtkCallback callback,
1312 gpointer callback_data)
1314 GtkBox *box = GTK_BOX (container);
1318 children = box->children;
1321 child = children->data;
1322 children = children->next;
1324 if (child->pack == GTK_PACK_START)
1325 (* callback) (child->widget, callback_data);
1328 children = g_list_last (box->children);
1331 child = children->data;
1332 children = children->prev;
1334 if (child->pack == GTK_PACK_END)
1335 (* callback) (child->widget, callback_data);
1339 #define __GTK_BOX_C__
1340 #include "gtkaliasdef.c"