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);
31 gtk_vbox_get_type (void)
33 static GtkType vbox_type = 0;
37 static const GtkTypeInfo vbox_info =
41 sizeof (GtkVBoxClass),
42 (GtkClassInitFunc) gtk_vbox_class_init,
43 (GtkObjectInitFunc) gtk_vbox_init,
44 /* reserved_1 */ NULL,
45 /* reserved_2 */ NULL,
46 (GtkClassInitFunc) NULL,
49 vbox_type = gtk_type_unique (GTK_TYPE_BOX, &vbox_info);
56 gtk_vbox_class_init (GtkVBoxClass *class)
58 GtkWidgetClass *widget_class;
60 widget_class = (GtkWidgetClass*) class;
62 widget_class->size_request = gtk_vbox_size_request;
63 widget_class->size_allocate = gtk_vbox_size_allocate;
67 gtk_vbox_init (GtkVBox *vbox)
72 gtk_vbox_new (gint homogeneous,
77 vbox = gtk_type_new (gtk_vbox_get_type ());
79 GTK_BOX (vbox)->spacing = spacing;
80 GTK_BOX (vbox)->homogeneous = homogeneous ? TRUE : FALSE;
82 return GTK_WIDGET (vbox);
87 gtk_vbox_size_request (GtkWidget *widget,
88 GtkRequisition *requisition)
96 g_return_if_fail (widget != NULL);
97 g_return_if_fail (GTK_IS_VBOX (widget));
98 g_return_if_fail (requisition != NULL);
100 box = GTK_BOX (widget);
101 requisition->width = 0;
102 requisition->height = 0;
105 children = box->children;
108 child = children->data;
109 children = children->next;
111 if (GTK_WIDGET_VISIBLE (child->widget))
113 gtk_widget_size_request (child->widget, &child->widget->requisition);
115 if (box->homogeneous)
117 height = child->widget->requisition.height + child->padding * 2;
118 requisition->height = MAX (requisition->height, height);
122 requisition->height += child->widget->requisition.height + child->padding * 2;
125 requisition->width = MAX (requisition->width, child->widget->requisition.width);
131 if (nvis_children > 0)
133 if (box->homogeneous)
134 requisition->height *= nvis_children;
135 requisition->height += (nvis_children - 1) * box->spacing;
138 requisition->width += GTK_CONTAINER (box)->border_width * 2;
139 requisition->height += GTK_CONTAINER (box)->border_width * 2;
143 gtk_vbox_size_allocate (GtkWidget *widget,
144 GtkAllocation *allocation)
149 GtkAllocation child_allocation;
151 gint nexpand_children;
157 g_return_if_fail (widget != NULL);
158 g_return_if_fail (GTK_IS_VBOX (widget));
159 g_return_if_fail (allocation != NULL);
161 box = GTK_BOX (widget);
162 widget->allocation = *allocation;
165 nexpand_children = 0;
166 children = box->children;
170 child = children->data;
171 children = children->next;
173 if (GTK_WIDGET_VISIBLE (child->widget))
177 nexpand_children += 1;
181 if (nvis_children > 0)
183 if (box->homogeneous)
185 height = (allocation->height -
186 GTK_CONTAINER (box)->border_width * 2 -
187 (nvis_children - 1) * box->spacing);
188 extra = height / nvis_children;
190 else if (nexpand_children > 0)
192 height = (gint)allocation->height - (gint)widget->requisition.height;
193 extra = height / nexpand_children;
201 y = allocation->y + GTK_CONTAINER (box)->border_width;
202 child_allocation.x = allocation->x + GTK_CONTAINER (box)->border_width;
203 child_allocation.width = MAX (1, allocation->width - GTK_CONTAINER (box)->border_width * 2);
205 children = box->children;
208 child = children->data;
209 children = children->next;
211 if ((child->pack == GTK_PACK_START) && GTK_WIDGET_VISIBLE (child->widget))
213 if (box->homogeneous)
215 if (nvis_children == 1)
216 child_height = height;
218 child_height = extra;
225 child_height = child->widget->requisition.height + child->padding * 2;
229 if (nexpand_children == 1)
230 child_height += height;
232 child_height += extra;
234 nexpand_children -= 1;
241 child_allocation.height = MAX (1, child_height - child->padding * 2);
242 child_allocation.y = y + child->padding;
246 child_allocation.height = child->widget->requisition.height;
247 child_allocation.y = y + (child_height - child_allocation.height) / 2;
250 gtk_widget_size_allocate (child->widget, &child_allocation);
252 y += child_height + box->spacing;
256 y = allocation->y + allocation->height - GTK_CONTAINER (box)->border_width;
258 children = box->children;
261 child = children->data;
262 children = children->next;
264 if ((child->pack == GTK_PACK_END) && GTK_WIDGET_VISIBLE (child->widget))
266 if (box->homogeneous)
268 if (nvis_children == 1)
269 child_height = height;
271 child_height = extra;
278 child_height = child->widget->requisition.height + child->padding * 2;
282 if (nexpand_children == 1)
283 child_height += height;
285 child_height += extra;
287 nexpand_children -= 1;
294 child_allocation.height = MAX (1, child_height - child->padding * 2);
295 child_allocation.y = y + child->padding - child_height;
299 child_allocation.height = child->widget->requisition.height;
300 child_allocation.y = y + (child_height - child_allocation.height) / 2 - child_height;
303 gtk_widget_size_allocate (child->widget, &child_allocation);
305 y -= (child_height + box->spacing);