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 Library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library 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.
22 static void gtk_vbox_class_init (GtkVBoxClass *klass);
23 static void gtk_vbox_init (GtkVBox *box);
24 static void gtk_vbox_size_request (GtkWidget *widget,
25 GtkRequisition *requisition);
26 static void gtk_vbox_size_allocate (GtkWidget *widget,
27 GtkAllocation *allocation);
33 static guint vbox_type = 0;
37 GtkTypeInfo vbox_info =
41 sizeof (GtkVBoxClass),
42 (GtkClassInitFunc) gtk_vbox_class_init,
43 (GtkObjectInitFunc) gtk_vbox_init,
48 vbox_type = gtk_type_unique (gtk_box_get_type (), &vbox_info);
55 gtk_vbox_class_init (GtkVBoxClass *class)
57 GtkWidgetClass *widget_class;
59 widget_class = (GtkWidgetClass*) class;
61 widget_class->size_request = gtk_vbox_size_request;
62 widget_class->size_allocate = gtk_vbox_size_allocate;
66 gtk_vbox_init (GtkVBox *vbox)
71 gtk_vbox_new (gint homogeneous,
76 vbox = gtk_type_new (gtk_vbox_get_type ());
78 GTK_BOX (vbox)->spacing = spacing;
79 GTK_BOX (vbox)->homogeneous = homogeneous ? TRUE : FALSE;
81 return GTK_WIDGET (vbox);
86 gtk_vbox_size_request (GtkWidget *widget,
87 GtkRequisition *requisition)
95 g_return_if_fail (widget != NULL);
96 g_return_if_fail (GTK_IS_VBOX (widget));
97 g_return_if_fail (requisition != NULL);
99 box = GTK_BOX (widget);
100 requisition->width = 0;
101 requisition->height = 0;
104 children = box->children;
107 child = children->data;
108 children = children->next;
110 if (GTK_WIDGET_VISIBLE (child->widget))
112 gtk_widget_size_request (child->widget, &child->widget->requisition);
114 if (box->homogeneous)
116 height = child->widget->requisition.height + child->padding * 2;
117 requisition->height = MAX (requisition->height, height);
121 requisition->height += child->widget->requisition.height + child->padding * 2;
124 requisition->width = MAX (requisition->width, child->widget->requisition.width);
130 if (nvis_children > 0)
132 if (box->homogeneous)
133 requisition->height *= nvis_children;
134 requisition->height += (nvis_children - 1) * box->spacing;
137 requisition->width += GTK_CONTAINER (box)->border_width * 2;
138 requisition->height += GTK_CONTAINER (box)->border_width * 2;
142 gtk_vbox_size_allocate (GtkWidget *widget,
143 GtkAllocation *allocation)
148 GtkAllocation child_allocation;
150 gint nexpand_children;
156 g_return_if_fail (widget != NULL);
157 g_return_if_fail (GTK_IS_VBOX (widget));
158 g_return_if_fail (allocation != NULL);
160 box = GTK_BOX (widget);
161 widget->allocation = *allocation;
164 nexpand_children = 0;
165 children = box->children;
169 child = children->data;
170 children = children->next;
172 if (GTK_WIDGET_VISIBLE (child->widget))
176 nexpand_children += 1;
180 if (nvis_children > 0)
182 if (box->homogeneous)
184 height = (allocation->height -
185 GTK_CONTAINER (box)->border_width * 2 -
186 (nvis_children - 1) * box->spacing);
187 extra = height / nvis_children;
189 else if (nexpand_children > 0)
191 height = (gint)allocation->height - (gint)widget->requisition.height;
192 extra = height / nexpand_children;
200 y = allocation->y + GTK_CONTAINER (box)->border_width;
201 child_allocation.x = allocation->x + GTK_CONTAINER (box)->border_width;
202 child_allocation.width = MAX (1, allocation->width - GTK_CONTAINER (box)->border_width * 2);
204 children = box->children;
207 child = children->data;
208 children = children->next;
210 if ((child->pack == GTK_PACK_START) && GTK_WIDGET_VISIBLE (child->widget))
212 if (box->homogeneous)
214 if (nvis_children == 1)
215 child_height = height;
217 child_height = extra;
224 child_height = child->widget->requisition.height + child->padding * 2;
228 if (nexpand_children == 1)
229 child_height += height;
231 child_height += extra;
233 nexpand_children -= 1;
240 child_allocation.height = MAX (1, child_height - child->padding * 2);
241 child_allocation.y = y + child->padding;
245 child_allocation.height = child->widget->requisition.height;
246 child_allocation.y = y + (child_height - child_allocation.height) / 2;
249 gtk_widget_size_allocate (child->widget, &child_allocation);
251 y += child_height + box->spacing;
255 y = allocation->y + allocation->height - GTK_CONTAINER (box)->border_width;
257 children = box->children;
260 child = children->data;
261 children = children->next;
263 if ((child->pack == GTK_PACK_END) && GTK_WIDGET_VISIBLE (child->widget))
265 if (box->homogeneous)
267 if (nvis_children == 1)
268 child_height = height;
270 child_height = extra;
277 child_height = child->widget->requisition.height + child->padding * 2;
281 if (nexpand_children == 1)
282 child_height += height;
284 child_height += extra;
286 nexpand_children -= 1;
293 child_allocation.height = MAX (1, child_height - child->padding * 2);
294 child_allocation.y = y + child->padding - child_height;
298 child_allocation.height = child->widget->requisition.height;
299 child_allocation.y = y + (child_height - child_allocation.height) / 2 - child_height;
302 gtk_widget_size_allocate (child->widget, &child_allocation);
304 y -= (child_height + box->spacing);