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 static void gtk_vbox_class_init (GtkVBoxClass *klass);
31 static void gtk_vbox_init (GtkVBox *box);
32 static void gtk_vbox_size_request (GtkWidget *widget,
33 GtkRequisition *requisition);
34 static void gtk_vbox_size_allocate (GtkWidget *widget,
35 GtkAllocation *allocation);
39 gtk_vbox_get_type (void)
41 static GType vbox_type = 0;
45 static const GTypeInfo vbox_info =
47 sizeof (GtkVBoxClass),
49 NULL, /* base_finalize */
50 (GClassInitFunc) gtk_vbox_class_init,
51 NULL, /* class_finalize */
52 NULL, /* class_data */
55 (GInstanceInitFunc) gtk_vbox_init,
58 vbox_type = g_type_register_static (GTK_TYPE_BOX, "GtkVBox",
66 gtk_vbox_class_init (GtkVBoxClass *class)
68 GtkWidgetClass *widget_class;
70 widget_class = (GtkWidgetClass*) class;
72 widget_class->size_request = gtk_vbox_size_request;
73 widget_class->size_allocate = gtk_vbox_size_allocate;
77 gtk_vbox_init (GtkVBox *vbox)
82 gtk_vbox_new (gboolean homogeneous,
87 vbox = g_object_new (GTK_TYPE_VBOX, NULL);
89 GTK_BOX (vbox)->spacing = spacing;
90 GTK_BOX (vbox)->homogeneous = homogeneous ? TRUE : FALSE;
92 return GTK_WIDGET (vbox);
97 gtk_vbox_size_request (GtkWidget *widget,
98 GtkRequisition *requisition)
102 GtkRequisition child_requisition;
107 box = GTK_BOX (widget);
108 requisition->width = 0;
109 requisition->height = 0;
112 children = box->children;
115 child = children->data;
116 children = children->next;
118 if (GTK_WIDGET_VISIBLE (child->widget))
120 gtk_widget_size_request (child->widget, &child_requisition);
122 if (box->homogeneous)
124 height = child_requisition.height + child->padding * 2;
125 requisition->height = MAX (requisition->height, height);
129 requisition->height += child_requisition.height + child->padding * 2;
132 requisition->width = MAX (requisition->width, child_requisition.width);
138 if (nvis_children > 0)
140 if (box->homogeneous)
141 requisition->height *= nvis_children;
142 requisition->height += (nvis_children - 1) * box->spacing;
145 requisition->width += GTK_CONTAINER (box)->border_width * 2;
146 requisition->height += GTK_CONTAINER (box)->border_width * 2;
150 gtk_vbox_size_allocate (GtkWidget *widget,
151 GtkAllocation *allocation)
156 GtkAllocation child_allocation;
158 gint nexpand_children;
164 box = GTK_BOX (widget);
165 widget->allocation = *allocation;
168 nexpand_children = 0;
169 children = box->children;
173 child = children->data;
174 children = children->next;
176 if (GTK_WIDGET_VISIBLE (child->widget))
180 nexpand_children += 1;
184 if (nvis_children > 0)
186 if (box->homogeneous)
188 height = (allocation->height -
189 GTK_CONTAINER (box)->border_width * 2 -
190 (nvis_children - 1) * box->spacing);
191 extra = height / nvis_children;
193 else if (nexpand_children > 0)
195 height = (gint) allocation->height - (gint) widget->requisition.height;
196 extra = height / nexpand_children;
204 y = allocation->y + GTK_CONTAINER (box)->border_width;
205 child_allocation.x = allocation->x + GTK_CONTAINER (box)->border_width;
206 child_allocation.width = MAX (1, (gint) allocation->width - (gint) GTK_CONTAINER (box)->border_width * 2);
208 children = box->children;
211 child = children->data;
212 children = children->next;
214 if ((child->pack == GTK_PACK_START) && GTK_WIDGET_VISIBLE (child->widget))
216 if (box->homogeneous)
218 if (nvis_children == 1)
219 child_height = height;
221 child_height = extra;
228 GtkRequisition child_requisition;
230 gtk_widget_get_child_requisition (child->widget, &child_requisition);
231 child_height = child_requisition.height + child->padding * 2;
235 if (nexpand_children == 1)
236 child_height += height;
238 child_height += extra;
240 nexpand_children -= 1;
247 child_allocation.height = MAX (1, child_height - (gint)child->padding * 2);
248 child_allocation.y = y + child->padding;
252 GtkRequisition child_requisition;
254 gtk_widget_get_child_requisition (child->widget, &child_requisition);
255 child_allocation.height = child_requisition.height;
256 child_allocation.y = y + (child_height - child_allocation.height) / 2;
259 gtk_widget_size_allocate (child->widget, &child_allocation);
261 y += child_height + box->spacing;
265 y = allocation->y + allocation->height - GTK_CONTAINER (box)->border_width;
267 children = box->children;
270 child = children->data;
271 children = children->next;
273 if ((child->pack == GTK_PACK_END) && GTK_WIDGET_VISIBLE (child->widget))
275 GtkRequisition child_requisition;
276 gtk_widget_get_child_requisition (child->widget, &child_requisition);
278 if (box->homogeneous)
280 if (nvis_children == 1)
281 child_height = height;
283 child_height = extra;
290 child_height = child_requisition.height + child->padding * 2;
294 if (nexpand_children == 1)
295 child_height += height;
297 child_height += extra;
299 nexpand_children -= 1;
306 child_allocation.height = MAX (1, child_height - (gint)child->padding * 2);
307 child_allocation.y = y + child->padding - child_height;
311 child_allocation.height = child_requisition.height;
312 child_allocation.y = y + (child_height - child_allocation.height) / 2 - child_height;
315 gtk_widget_size_allocate (child->widget, &child_allocation);
317 y -= (child_height + box->spacing);