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/.
32 static void gtk_vbox_class_init (GtkVBoxClass *klass);
33 static void gtk_vbox_init (GtkVBox *box);
34 static void gtk_vbox_size_request (GtkWidget *widget,
35 GtkRequisition *requisition);
36 static void gtk_vbox_size_allocate (GtkWidget *widget,
37 GtkAllocation *allocation);
41 gtk_vbox_get_type (void)
43 static GType vbox_type = 0;
47 static const GTypeInfo vbox_info =
49 sizeof (GtkVBoxClass),
51 NULL, /* base_finalize */
52 (GClassInitFunc) gtk_vbox_class_init,
53 NULL, /* class_finalize */
54 NULL, /* class_data */
57 (GInstanceInitFunc) gtk_vbox_init,
60 vbox_type = g_type_register_static (GTK_TYPE_BOX, g_intern_static_string ("GtkVBox"),
68 gtk_vbox_class_init (GtkVBoxClass *class)
70 GtkWidgetClass *widget_class;
72 widget_class = (GtkWidgetClass*) class;
74 widget_class->size_request = gtk_vbox_size_request;
75 widget_class->size_allocate = gtk_vbox_size_allocate;
79 gtk_vbox_init (GtkVBox *vbox)
84 gtk_vbox_new (gboolean homogeneous,
89 vbox = g_object_new (GTK_TYPE_VBOX, NULL);
91 GTK_BOX (vbox)->spacing = spacing;
92 GTK_BOX (vbox)->homogeneous = homogeneous ? TRUE : FALSE;
94 return GTK_WIDGET (vbox);
99 gtk_vbox_size_request (GtkWidget *widget,
100 GtkRequisition *requisition)
104 GtkRequisition child_requisition;
109 box = GTK_BOX (widget);
110 requisition->width = 0;
111 requisition->height = 0;
114 children = box->children;
117 child = children->data;
118 children = children->next;
120 if (GTK_WIDGET_VISIBLE (child->widget))
122 gtk_widget_size_request (child->widget, &child_requisition);
124 if (box->homogeneous)
126 height = child_requisition.height + child->padding * 2;
127 requisition->height = MAX (requisition->height, height);
131 requisition->height += child_requisition.height + child->padding * 2;
134 requisition->width = MAX (requisition->width, child_requisition.width);
140 if (nvis_children > 0)
142 if (box->homogeneous)
143 requisition->height *= nvis_children;
144 requisition->height += (nvis_children - 1) * box->spacing;
147 requisition->width += GTK_CONTAINER (box)->border_width * 2;
148 requisition->height += GTK_CONTAINER (box)->border_width * 2;
152 gtk_vbox_size_allocate (GtkWidget *widget,
153 GtkAllocation *allocation)
158 GtkAllocation child_allocation;
160 gint nexpand_children;
166 box = GTK_BOX (widget);
167 widget->allocation = *allocation;
170 nexpand_children = 0;
171 children = box->children;
175 child = children->data;
176 children = children->next;
178 if (GTK_WIDGET_VISIBLE (child->widget))
182 nexpand_children += 1;
186 if (nvis_children > 0)
188 if (box->homogeneous)
190 height = (allocation->height -
191 GTK_CONTAINER (box)->border_width * 2 -
192 (nvis_children - 1) * box->spacing);
193 extra = height / nvis_children;
195 else if (nexpand_children > 0)
197 height = (gint) allocation->height - (gint) widget->requisition.height;
198 extra = height / nexpand_children;
206 y = allocation->y + GTK_CONTAINER (box)->border_width;
207 child_allocation.x = allocation->x + GTK_CONTAINER (box)->border_width;
208 child_allocation.width = MAX (1, (gint) allocation->width - (gint) GTK_CONTAINER (box)->border_width * 2);
210 children = box->children;
213 child = children->data;
214 children = children->next;
216 if ((child->pack == GTK_PACK_START) && GTK_WIDGET_VISIBLE (child->widget))
218 if (box->homogeneous)
220 if (nvis_children == 1)
221 child_height = height;
223 child_height = extra;
230 GtkRequisition child_requisition;
232 gtk_widget_get_child_requisition (child->widget, &child_requisition);
233 child_height = child_requisition.height + child->padding * 2;
237 if (nexpand_children == 1)
238 child_height += height;
240 child_height += extra;
242 nexpand_children -= 1;
249 child_allocation.height = MAX (1, child_height - (gint)child->padding * 2);
250 child_allocation.y = y + child->padding;
254 GtkRequisition child_requisition;
256 gtk_widget_get_child_requisition (child->widget, &child_requisition);
257 child_allocation.height = child_requisition.height;
258 child_allocation.y = y + (child_height - child_allocation.height) / 2;
261 gtk_widget_size_allocate (child->widget, &child_allocation);
263 y += child_height + box->spacing;
267 y = allocation->y + allocation->height - GTK_CONTAINER (box)->border_width;
269 children = box->children;
272 child = children->data;
273 children = children->next;
275 if ((child->pack == GTK_PACK_END) && GTK_WIDGET_VISIBLE (child->widget))
277 GtkRequisition child_requisition;
278 gtk_widget_get_child_requisition (child->widget, &child_requisition);
280 if (box->homogeneous)
282 if (nvis_children == 1)
283 child_height = height;
285 child_height = extra;
292 child_height = child_requisition.height + child->padding * 2;
296 if (nexpand_children == 1)
297 child_height += height;
299 child_height += extra;
301 nexpand_children -= 1;
308 child_allocation.height = MAX (1, child_height - (gint)child->padding * 2);
309 child_allocation.y = y + child->padding - child_height;
313 child_allocation.height = child_requisition.height;
314 child_allocation.y = y + (child_height - child_allocation.height) / 2 - child_height;
317 gtk_widget_size_allocate (child->widget, &child_allocation);
319 y -= (child_height + box->spacing);
325 #define __GTK_VBOX_C__
326 #include "gtkaliasdef.c"