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 "gtkprivate.h"
52 typedef struct _GtkBoxPrivate GtkBoxPrivate;
56 GtkOrientation orientation;
57 guint default_expand : 1;
58 guint spacing_set : 1;
61 #define GTK_BOX_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_BOX, GtkBoxPrivate))
64 static void gtk_box_set_property (GObject *object,
68 static void gtk_box_get_property (GObject *object,
73 static void gtk_box_size_request (GtkWidget *widget,
74 GtkRequisition *requisition);
75 static void gtk_box_size_allocate (GtkWidget *widget,
76 GtkAllocation *allocation);
78 static void gtk_box_add (GtkContainer *container,
80 static void gtk_box_remove (GtkContainer *container,
82 static void gtk_box_forall (GtkContainer *container,
83 gboolean include_internals,
85 gpointer callback_data);
86 static void gtk_box_set_child_property (GtkContainer *container,
91 static void gtk_box_get_child_property (GtkContainer *container,
96 static GType gtk_box_child_type (GtkContainer *container);
99 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GtkBox, gtk_box, GTK_TYPE_CONTAINER,
100 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
104 gtk_box_class_init (GtkBoxClass *class)
106 GObjectClass *object_class = G_OBJECT_CLASS (class);
107 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
108 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
110 object_class->set_property = gtk_box_set_property;
111 object_class->get_property = gtk_box_get_property;
113 widget_class->size_request = gtk_box_size_request;
114 widget_class->size_allocate = gtk_box_size_allocate;
116 container_class->add = gtk_box_add;
117 container_class->remove = gtk_box_remove;
118 container_class->forall = gtk_box_forall;
119 container_class->child_type = gtk_box_child_type;
120 container_class->set_child_property = gtk_box_set_child_property;
121 container_class->get_child_property = gtk_box_get_child_property;
123 g_object_class_override_property (object_class,
127 g_object_class_install_property (object_class,
129 g_param_spec_int ("spacing",
131 P_("The amount of space between children"),
135 GTK_PARAM_READWRITE));
137 g_object_class_install_property (object_class,
139 g_param_spec_boolean ("homogeneous",
141 P_("Whether the children should all be the same size"),
143 GTK_PARAM_READWRITE));
145 gtk_container_class_install_child_property (container_class,
147 g_param_spec_boolean ("expand",
149 P_("Whether the child should receive extra space when the parent grows"),
151 GTK_PARAM_READWRITE));
152 gtk_container_class_install_child_property (container_class,
154 g_param_spec_boolean ("fill",
156 P_("Whether extra space given to the child should be allocated to the child or used as padding"),
158 GTK_PARAM_READWRITE));
159 gtk_container_class_install_child_property (container_class,
161 g_param_spec_uint ("padding",
163 P_("Extra space to put between the child and its neighbors, in pixels"),
165 GTK_PARAM_READWRITE));
166 gtk_container_class_install_child_property (container_class,
167 CHILD_PROP_PACK_TYPE,
168 g_param_spec_enum ("pack-type",
170 P_("A GtkPackType indicating whether the child is packed with reference to the start or end of the parent"),
171 GTK_TYPE_PACK_TYPE, GTK_PACK_START,
172 GTK_PARAM_READWRITE));
173 gtk_container_class_install_child_property (container_class,
175 g_param_spec_int ("position",
177 P_("The index of the child in the parent"),
179 GTK_PARAM_READWRITE));
181 g_type_class_add_private (object_class, sizeof (GtkBoxPrivate));
185 gtk_box_init (GtkBox *box)
187 GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
189 GTK_WIDGET_SET_FLAGS (box, GTK_NO_WINDOW);
190 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (box), FALSE);
192 box->children = NULL;
194 box->homogeneous = FALSE;
196 private->orientation = GTK_ORIENTATION_HORIZONTAL;
197 private->default_expand = FALSE;
198 private->spacing_set = FALSE;
202 gtk_box_set_property (GObject *object,
207 GtkBox *box = GTK_BOX (object);
208 GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
212 case PROP_ORIENTATION:
213 private->orientation = g_value_get_enum (value);
214 gtk_widget_queue_resize (GTK_WIDGET (box));
217 gtk_box_set_spacing (box, g_value_get_int (value));
219 case PROP_HOMOGENEOUS:
220 gtk_box_set_homogeneous (box, g_value_get_boolean (value));
223 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
229 gtk_box_get_property (GObject *object,
234 GtkBox *box = GTK_BOX (object);
235 GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
239 case PROP_ORIENTATION:
240 g_value_set_enum (value, private->orientation);
243 g_value_set_int (value, box->spacing);
245 case PROP_HOMOGENEOUS:
246 g_value_set_boolean (value, box->homogeneous);
249 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
255 gtk_box_size_request (GtkWidget *widget,
256 GtkRequisition *requisition)
258 GtkBox *box = GTK_BOX (widget);
259 GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
266 requisition->width = 0;
267 requisition->height = 0;
270 children = box->children;
273 child = children->data;
274 children = children->next;
276 if (GTK_WIDGET_VISIBLE (child->widget))
278 GtkRequisition child_requisition;
280 gtk_widget_size_request (child->widget, &child_requisition);
282 if (box->homogeneous)
284 width = child_requisition.width + child->padding * 2;
285 height = child_requisition.height + child->padding * 2;
287 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
288 requisition->width = MAX (requisition->width, width);
290 requisition->height = MAX (requisition->height, height);
294 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
295 requisition->width += child_requisition.width + child->padding * 2;
297 requisition->height += child_requisition.height + child->padding * 2;
300 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
301 requisition->height = MAX (requisition->height, child_requisition.height);
303 requisition->width = MAX (requisition->width, child_requisition.width);
309 if (nvis_children > 0)
311 if (box->homogeneous)
313 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
314 requisition->width *= nvis_children;
316 requisition->height *= nvis_children;
319 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
320 requisition->width += (nvis_children - 1) * box->spacing;
322 requisition->height += (nvis_children - 1) * box->spacing;
325 requisition->width += GTK_CONTAINER (box)->border_width * 2;
326 requisition->height += GTK_CONTAINER (box)->border_width * 2;
330 gtk_box_size_allocate (GtkWidget *widget,
331 GtkAllocation *allocation)
333 GtkBox *box = GTK_BOX (widget);
334 GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
337 GtkAllocation child_allocation;
338 gint nvis_children = 0;
339 gint nexpand_children = 0;
340 gint child_width = 0;
341 gint child_height = 0;
347 GtkTextDirection direction;
349 widget->allocation = *allocation;
351 direction = gtk_widget_get_direction (widget);
353 for (children = box->children; children; children = children->next)
355 child = children->data;
357 if (GTK_WIDGET_VISIBLE (child->widget))
361 nexpand_children += 1;
365 if (nvis_children > 0)
367 if (box->homogeneous)
369 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
371 width = (allocation->width -
372 GTK_CONTAINER (box)->border_width * 2 -
373 (nvis_children - 1) * box->spacing);
374 extra = width / nvis_children;
378 height = (allocation->height -
379 GTK_CONTAINER (box)->border_width * 2 -
380 (nvis_children - 1) * box->spacing);
381 extra = height / nvis_children;
384 else if (nexpand_children > 0)
386 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
388 width = (gint) allocation->width - (gint) widget->requisition.width;
389 extra = width / nexpand_children;
393 height = (gint) allocation->height - (gint) widget->requisition.height;
394 extra = height / nexpand_children;
398 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
400 x = allocation->x + GTK_CONTAINER (box)->border_width;
401 child_allocation.y = allocation->y + GTK_CONTAINER (box)->border_width;
402 child_allocation.height = MAX (1, (gint) allocation->height - (gint) GTK_CONTAINER (box)->border_width * 2);
406 y = allocation->y + GTK_CONTAINER (box)->border_width;
407 child_allocation.x = allocation->x + GTK_CONTAINER (box)->border_width;
408 child_allocation.width = MAX (1, (gint) allocation->width - (gint) GTK_CONTAINER (box)->border_width * 2);
411 children = box->children;
414 child = children->data;
415 children = children->next;
417 if ((child->pack == GTK_PACK_START) && GTK_WIDGET_VISIBLE (child->widget))
419 if (box->homogeneous)
421 if (nvis_children == 1)
424 child_height = height;
429 child_height = extra;
438 GtkRequisition child_requisition;
440 gtk_widget_get_child_requisition (child->widget, &child_requisition);
442 child_width = child_requisition.width + child->padding * 2;
443 child_height = child_requisition.height + child->padding * 2;
447 if (nexpand_children == 1)
449 child_width += width;
450 child_height += height;
454 child_width += extra;
455 child_height += extra;
458 nexpand_children -= 1;
466 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
468 child_allocation.width = MAX (1, (gint) child_width - (gint) child->padding * 2);
469 child_allocation.x = x + child->padding;
473 child_allocation.height = MAX (1, child_height - (gint)child->padding * 2);
474 child_allocation.y = y + child->padding;
479 GtkRequisition child_requisition;
481 gtk_widget_get_child_requisition (child->widget, &child_requisition);
482 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
484 child_allocation.width = child_requisition.width;
485 child_allocation.x = x + (child_width - child_allocation.width) / 2;
489 child_allocation.height = child_requisition.height;
490 child_allocation.y = y + (child_height - child_allocation.height) / 2;
494 if (direction == GTK_TEXT_DIR_RTL &&
495 private->orientation == GTK_ORIENTATION_HORIZONTAL)
497 child_allocation.x = allocation->x + allocation->width - (child_allocation.x - allocation->x) - child_allocation.width;
500 gtk_widget_size_allocate (child->widget, &child_allocation);
502 x += child_width + box->spacing;
503 y += child_height + box->spacing;
507 x = allocation->x + allocation->width - GTK_CONTAINER (box)->border_width;
508 y = allocation->y + allocation->height - GTK_CONTAINER (box)->border_width;
510 children = box->children;
513 child = children->data;
514 children = children->next;
516 if ((child->pack == GTK_PACK_END) && GTK_WIDGET_VISIBLE (child->widget))
518 GtkRequisition child_requisition;
520 gtk_widget_get_child_requisition (child->widget, &child_requisition);
522 if (box->homogeneous)
524 if (nvis_children == 1)
527 child_height = height;
532 child_height = extra;
541 child_width = child_requisition.width + child->padding * 2;
542 child_height = child_requisition.height + child->padding * 2;
546 if (nexpand_children == 1)
548 child_width += width;
549 child_height += height;
553 child_width += extra;
554 child_height += extra;
557 nexpand_children -= 1;
565 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
567 child_allocation.width = MAX (1, (gint)child_width - (gint)child->padding * 2);
568 child_allocation.x = x + child->padding - child_width;
572 child_allocation.height = MAX (1, child_height - (gint)child->padding * 2);
573 child_allocation.y = y + child->padding - child_height;
578 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
580 child_allocation.width = child_requisition.width;
581 child_allocation.x = x + (child_width - child_allocation.width) / 2 - child_width;
585 child_allocation.height = child_requisition.height;
586 child_allocation.y = y + (child_height - child_allocation.height) / 2 - child_height;
590 if (direction == GTK_TEXT_DIR_RTL &&
591 private->orientation == GTK_ORIENTATION_HORIZONTAL)
593 child_allocation.x = allocation->x + allocation->width - (child_allocation.x - allocation->x) - child_allocation.width;
596 gtk_widget_size_allocate (child->widget, &child_allocation);
598 x -= (child_width + box->spacing);
599 y -= (child_height + box->spacing);
606 gtk_box_child_type (GtkContainer *container)
608 return GTK_TYPE_WIDGET;
612 gtk_box_set_child_property (GtkContainer *container,
621 GtkPackType pack_type = 0;
623 if (property_id != CHILD_PROP_POSITION)
624 gtk_box_query_child_packing (GTK_BOX (container),
632 case CHILD_PROP_EXPAND:
633 gtk_box_set_child_packing (GTK_BOX (container),
635 g_value_get_boolean (value),
640 case CHILD_PROP_FILL:
641 gtk_box_set_child_packing (GTK_BOX (container),
644 g_value_get_boolean (value),
648 case CHILD_PROP_PADDING:
649 gtk_box_set_child_packing (GTK_BOX (container),
653 g_value_get_uint (value),
656 case CHILD_PROP_PACK_TYPE:
657 gtk_box_set_child_packing (GTK_BOX (container),
662 g_value_get_enum (value));
664 case CHILD_PROP_POSITION:
665 gtk_box_reorder_child (GTK_BOX (container),
667 g_value_get_int (value));
670 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
676 gtk_box_get_child_property (GtkContainer *container,
685 GtkPackType pack_type = 0;
688 if (property_id != CHILD_PROP_POSITION)
689 gtk_box_query_child_packing (GTK_BOX (container),
698 case CHILD_PROP_EXPAND:
699 g_value_set_boolean (value, expand);
701 case CHILD_PROP_FILL:
702 g_value_set_boolean (value, fill);
704 case CHILD_PROP_PADDING:
705 g_value_set_uint (value, padding);
707 case CHILD_PROP_PACK_TYPE:
708 g_value_set_enum (value, pack_type);
710 case CHILD_PROP_POSITION:
712 for (list = GTK_BOX (container)->children; list; list = list->next)
714 GtkBoxChild *child_entry;
716 child_entry = list->data;
717 if (child_entry->widget == child)
721 g_value_set_int (value, list ? i : -1);
724 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
730 gtk_box_pack (GtkBox *box,
735 GtkPackType pack_type)
737 GtkBoxChild *child_info;
739 g_return_if_fail (GTK_IS_BOX (box));
740 g_return_if_fail (GTK_IS_WIDGET (child));
741 g_return_if_fail (child->parent == NULL);
743 child_info = g_new (GtkBoxChild, 1);
744 child_info->widget = child;
745 child_info->padding = padding;
746 child_info->expand = expand ? TRUE : FALSE;
747 child_info->fill = fill ? TRUE : FALSE;
748 child_info->pack = pack_type;
749 child_info->is_secondary = FALSE;
751 box->children = g_list_append (box->children, child_info);
753 gtk_widget_freeze_child_notify (child);
755 gtk_widget_set_parent (child, GTK_WIDGET (box));
757 gtk_widget_child_notify (child, "expand");
758 gtk_widget_child_notify (child, "fill");
759 gtk_widget_child_notify (child, "padding");
760 gtk_widget_child_notify (child, "pack-type");
761 gtk_widget_child_notify (child, "position");
762 gtk_widget_thaw_child_notify (child);
767 * @orientation: the box' orientation.
768 * @homogeneous: %TRUE if all children are to be given equal space allocations.
769 * @spacing: the number of pixels to place by default between children.
771 * Creates a new #GtkHBox.
773 * Return value: a new #GtkHBox.
778 _gtk_box_new (GtkOrientation orientation,
779 gboolean homogeneous,
782 return g_object_new (GTK_TYPE_BOX,
783 "orientation", orientation,
785 "homogeneous", homogeneous ? TRUE : FALSE,
790 * gtk_box_pack_start:
792 * @child: the #GtkWidget to be added to @box
793 * @expand: %TRUE if the new child is to be given extra space allocated to
794 * @box. The extra space will be divided evenly between all children of
795 * @box that use this option
796 * @fill: %TRUE if space given to @child by the @expand option is
797 * actually allocated to @child, rather than just padding it. This
798 * parameter has no effect if @expand is set to %FALSE. A child is
799 * always allocated the full height of a #GtkHBox and the full width
800 * of a #GtkVBox. This option affects the other dimension
801 * @padding: extra space in pixels to put between this child and its
802 * neighbors, over and above the global amount specified by
803 * #GtkBox:spacing property. If @child is a widget at one of the
804 * reference ends of @box, then @padding pixels are also put between
805 * @child and the reference edge of @box
807 * Adds @child to @box, packed with reference to the start of @box.
808 * The @child is packed after any other child packed with reference
809 * to the start of @box.
812 gtk_box_pack_start (GtkBox *box,
818 gtk_box_pack (box, child, expand, fill, padding, GTK_PACK_START);
824 * @child: the #GtkWidget to be added to @box
825 * @expand: %TRUE if the new child is to be given extra space allocated
826 * to @box. The extra space will be divided evenly between all children
827 * of @box that use this option
828 * @fill: %TRUE if space given to @child by the @expand option is
829 * actually allocated to @child, rather than just padding it. This
830 * parameter has no effect if @expand is set to %FALSE. A child is
831 * always allocated the full height of a #GtkHBox and the full width
832 * of a #GtkVBox. This option affects the other dimension
833 * @padding: extra space in pixels to put between this child and its
834 * neighbors, over and above the global amount specified by
835 * #GtkBox:spacing property. If @child is a widget at one of the
836 * reference ends of @box, then @padding pixels are also put between
837 * @child and the reference edge of @box
839 * Adds @child to @box, packed with reference to the end of @box.
840 * The @child is packed after (away from end of) any other child
841 * packed with reference to the end of @box.
844 gtk_box_pack_end (GtkBox *box,
850 gtk_box_pack (box, child, expand, fill, padding, GTK_PACK_END);
854 * gtk_box_pack_start_defaults:
856 * @widget: the #GtkWidget to be added to @box
858 * Adds @widget to @box, packed with reference to the start of @box.
859 * The child is packed after any other child packed with reference
860 * to the start of @box.
862 * Parameters for how to pack the child @widget, #GtkBox:expand,
863 * #GtkBox:fill and #GtkBox:padding, are given their default
864 * values, %TRUE, %TRUE, and 0, respectively.
866 * Deprecated: 2.14: Use gtk_box_pack_start()
869 gtk_box_pack_start_defaults (GtkBox *box,
872 gtk_box_pack_start (box, child, TRUE, TRUE, 0);
876 * gtk_box_pack_end_defaults:
878 * @widget: the #GtkWidget to be added to @box
880 * Adds @widget to @box, packed with reference to the end of @box.
881 * The child is packed after any other child packed with reference
882 * to the start of @box.
884 * Parameters for how to pack the child @widget, #GtkBox:expand,
885 * #GtkBox:fill and #GtkBox:padding, are given their default
886 * values, %TRUE, %TRUE, and 0, respectively.
888 * Deprecated: 2.14: Use gtk_box_pack_end()
891 gtk_box_pack_end_defaults (GtkBox *box,
894 gtk_box_pack_end (box, child, TRUE, TRUE, 0);
898 * gtk_box_set_homogeneous:
900 * @homogeneous: a boolean value, %TRUE to create equal allotments,
901 * %FALSE for variable allotments
903 * Sets the #GtkBox:homogeneous property of @box, controlling
904 * whether or not all children of @box are given equal space
908 gtk_box_set_homogeneous (GtkBox *box,
909 gboolean homogeneous)
911 g_return_if_fail (GTK_IS_BOX (box));
913 if ((homogeneous ? TRUE : FALSE) != box->homogeneous)
915 box->homogeneous = homogeneous ? TRUE : FALSE;
916 g_object_notify (G_OBJECT (box), "homogeneous");
917 gtk_widget_queue_resize (GTK_WIDGET (box));
922 * gtk_box_get_homogeneous:
925 * Returns whether the box is homogeneous (all children are the
926 * same size). See gtk_box_set_homogeneous().
928 * Return value: %TRUE if the box is homogeneous.
931 gtk_box_get_homogeneous (GtkBox *box)
933 g_return_val_if_fail (GTK_IS_BOX (box), FALSE);
935 return box->homogeneous;
939 * gtk_box_set_spacing:
941 * @spacing: the number of pixels to put between children
943 * Sets the #GtkBox:spacing property of @box, which is the
944 * number of pixels to place between children of @box.
947 gtk_box_set_spacing (GtkBox *box,
950 g_return_if_fail (GTK_IS_BOX (box));
952 if (spacing != box->spacing)
954 box->spacing = spacing;
955 _gtk_box_set_spacing_set (box, TRUE);
957 g_object_notify (G_OBJECT (box), "spacing");
959 gtk_widget_queue_resize (GTK_WIDGET (box));
964 * gtk_box_get_spacing:
967 * Gets the value set by gtk_box_set_spacing().
969 * Return value: spacing between children
972 gtk_box_get_spacing (GtkBox *box)
974 g_return_val_if_fail (GTK_IS_BOX (box), 0);
980 _gtk_box_set_spacing_set (GtkBox *box,
981 gboolean spacing_set)
983 GtkBoxPrivate *private;
985 g_return_if_fail (GTK_IS_BOX (box));
987 private = GTK_BOX_GET_PRIVATE (box);
989 private->spacing_set = spacing_set ? TRUE : FALSE;
993 _gtk_box_get_spacing_set (GtkBox *box)
995 GtkBoxPrivate *private;
997 g_return_val_if_fail (GTK_IS_BOX (box), FALSE);
999 private = GTK_BOX_GET_PRIVATE (box);
1001 return private->spacing_set;
1005 * gtk_box_reorder_child:
1007 * @child: the #GtkWidget to move
1008 * @position: the new position for @child in the list of children
1009 * of @box, starting from 0. If negative, indicates the end of
1012 * Moves @child to a new @position in the list of @box children.
1013 * The list is the <structfield>children</structfield> field of
1014 * #GtkBox-struct, and contains both widgets packed #GTK_PACK_START
1015 * as well as widgets packed #GTK_PACK_END, in the order that these
1016 * widgets were added to @box.
1018 * A widget's position in the @box children list determines where
1019 * the widget is packed into @box. A child widget at some position
1020 * in the list will be packed just after all other widgets of the
1021 * same packing type that appear earlier in the list.
1024 gtk_box_reorder_child (GtkBox *box,
1030 GtkBoxChild *child_info = NULL;
1033 g_return_if_fail (GTK_IS_BOX (box));
1034 g_return_if_fail (GTK_IS_WIDGET (child));
1036 old_link = box->children;
1040 child_info = old_link->data;
1041 if (child_info->widget == child)
1044 old_link = old_link->next;
1048 g_return_if_fail (old_link != NULL);
1050 if (position == old_position)
1053 box->children = g_list_delete_link (box->children, old_link);
1058 new_link = g_list_nth (box->children, position);
1060 box->children = g_list_insert_before (box->children, new_link, child_info);
1062 gtk_widget_child_notify (child, "position");
1063 if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (box))
1064 gtk_widget_queue_resize (child);
1068 * gtk_box_query_child_packing:
1070 * @child: the #GtkWidget of the child to query
1071 * @expand: pointer to return location for #GtkBox:expand child property
1072 * @fill: pointer to return location for #GtkBox:fill child property
1073 * @padding: pointer to return location for #GtkBox:padding child property
1074 * @pack_type: pointer to return location for #GtkBox:pack-type child property
1076 * Obtains information about how @child is packed into @box.
1079 gtk_box_query_child_packing (GtkBox *box,
1084 GtkPackType *pack_type)
1087 GtkBoxChild *child_info = NULL;
1089 g_return_if_fail (GTK_IS_BOX (box));
1090 g_return_if_fail (GTK_IS_WIDGET (child));
1092 list = box->children;
1095 child_info = list->data;
1096 if (child_info->widget == child)
1105 *expand = child_info->expand;
1107 *fill = child_info->fill;
1109 *padding = child_info->padding;
1111 *pack_type = child_info->pack;
1116 * gtk_box_set_child_packing:
1118 * @child: the #GtkWidget of the child to set
1119 * @expand: the new value of the #GtkBox:expand child property
1120 * @fill: the new value of the #GtkBox:fill child property
1121 * @padding: the new value of the #GtkBox:padding child property
1122 * @pack_type: the new value of the #GtkBox:pack-type child property
1124 * Sets the way @child is packed into @box.
1127 gtk_box_set_child_packing (GtkBox *box,
1132 GtkPackType pack_type)
1135 GtkBoxChild *child_info = NULL;
1137 g_return_if_fail (GTK_IS_BOX (box));
1138 g_return_if_fail (GTK_IS_WIDGET (child));
1140 list = box->children;
1143 child_info = list->data;
1144 if (child_info->widget == child)
1150 gtk_widget_freeze_child_notify (child);
1153 child_info->expand = expand != FALSE;
1154 gtk_widget_child_notify (child, "expand");
1155 child_info->fill = fill != FALSE;
1156 gtk_widget_child_notify (child, "fill");
1157 child_info->padding = padding;
1158 gtk_widget_child_notify (child, "padding");
1159 if (pack_type == GTK_PACK_END)
1160 child_info->pack = GTK_PACK_END;
1162 child_info->pack = GTK_PACK_START;
1163 gtk_widget_child_notify (child, "pack-type");
1165 if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (box))
1166 gtk_widget_queue_resize (child);
1168 gtk_widget_thaw_child_notify (child);
1172 _gtk_box_set_old_defaults (GtkBox *box)
1174 GtkBoxPrivate *private;
1176 g_return_if_fail (GTK_IS_BOX (box));
1178 private = GTK_BOX_GET_PRIVATE (box);
1180 private->default_expand = TRUE;
1184 gtk_box_add (GtkContainer *container,
1187 GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (container);
1189 gtk_box_pack_start (GTK_BOX (container), widget,
1190 private->default_expand,
1191 private->default_expand,
1196 gtk_box_remove (GtkContainer *container,
1199 GtkBox *box = GTK_BOX (container);
1203 children = box->children;
1206 child = children->data;
1208 if (child->widget == widget)
1210 gboolean was_visible;
1212 was_visible = GTK_WIDGET_VISIBLE (widget);
1213 gtk_widget_unparent (widget);
1215 box->children = g_list_remove_link (box->children, children);
1216 g_list_free (children);
1219 /* queue resize regardless of GTK_WIDGET_VISIBLE (container),
1220 * since that's what is needed by toplevels.
1223 gtk_widget_queue_resize (GTK_WIDGET (container));
1228 children = children->next;
1233 gtk_box_forall (GtkContainer *container,
1234 gboolean include_internals,
1235 GtkCallback callback,
1236 gpointer callback_data)
1238 GtkBox *box = GTK_BOX (container);
1242 children = box->children;
1245 child = children->data;
1246 children = children->next;
1248 if (child->pack == GTK_PACK_START)
1249 (* callback) (child->widget, callback_data);
1252 children = g_list_last (box->children);
1255 child = children->data;
1256 children = children->prev;
1258 if (child->pack == GTK_PACK_END)
1259 (* callback) (child->widget, callback_data);
1263 #define __GTK_BOX_C__
1264 #include "gtkaliasdef.c"