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 Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 static void gtk_vbox_class_init (GtkVBoxClass *klass);
22 static void gtk_vbox_init (GtkVBox *box);
23 static void gtk_vbox_size_request (GtkWidget *widget,
24 GtkRequisition *requisition);
25 static void gtk_vbox_size_allocate (GtkWidget *widget,
26 GtkAllocation *allocation);
32 static guint vbox_type = 0;
36 GtkTypeInfo vbox_info =
40 sizeof (GtkVBoxClass),
41 (GtkClassInitFunc) gtk_vbox_class_init,
42 (GtkObjectInitFunc) gtk_vbox_init,
47 vbox_type = gtk_type_unique (gtk_box_get_type (), &vbox_info);
54 gtk_vbox_class_init (GtkVBoxClass *class)
56 GtkWidgetClass *widget_class;
58 widget_class = (GtkWidgetClass*) class;
60 widget_class->size_request = gtk_vbox_size_request;
61 widget_class->size_allocate = gtk_vbox_size_allocate;
65 gtk_vbox_init (GtkVBox *vbox)
70 gtk_vbox_new (gint homogeneous,
75 vbox = gtk_type_new (gtk_vbox_get_type ());
77 GTK_BOX (vbox)->spacing = spacing;
78 GTK_BOX (vbox)->homogeneous = homogeneous ? TRUE : FALSE;
80 return GTK_WIDGET (vbox);
85 gtk_vbox_size_request (GtkWidget *widget,
86 GtkRequisition *requisition)
94 g_return_if_fail (widget != NULL);
95 g_return_if_fail (GTK_IS_VBOX (widget));
96 g_return_if_fail (requisition != NULL);
98 box = GTK_BOX (widget);
99 requisition->width = 0;
100 requisition->height = 0;
103 children = box->children;
106 child = children->data;
107 children = children->next;
109 if (GTK_WIDGET_VISIBLE (child->widget))
111 gtk_widget_size_request (child->widget, &child->widget->requisition);
113 if (box->homogeneous)
115 height = child->widget->requisition.height + child->padding * 2;
116 requisition->height = MAX (requisition->height, height);
120 requisition->height += child->widget->requisition.height + child->padding * 2;
123 requisition->width = MAX (requisition->width, child->widget->requisition.width);
129 if (nvis_children > 0)
131 if (box->homogeneous)
132 requisition->height *= nvis_children;
133 requisition->height += (nvis_children - 1) * box->spacing;
136 requisition->width += GTK_CONTAINER (box)->border_width * 2;
137 requisition->height += GTK_CONTAINER (box)->border_width * 2;
141 gtk_vbox_size_allocate (GtkWidget *widget,
142 GtkAllocation *allocation)
147 GtkAllocation child_allocation;
149 gint nexpand_children;
155 g_return_if_fail (widget != NULL);
156 g_return_if_fail (GTK_IS_VBOX (widget));
157 g_return_if_fail (allocation != NULL);
159 box = GTK_BOX (widget);
160 widget->allocation = *allocation;
163 nexpand_children = 0;
164 children = box->children;
168 child = children->data;
169 children = children->next;
171 if (GTK_WIDGET_VISIBLE (child->widget))
175 nexpand_children += 1;
179 if (nvis_children > 0)
181 if (box->homogeneous)
183 height = (allocation->height -
184 GTK_CONTAINER (box)->border_width * 2 -
185 (nvis_children - 1) * box->spacing);
186 extra = height / nvis_children;
188 else if (nexpand_children > 0)
190 height = (gint)allocation->height - (gint)widget->requisition.height;
191 extra = height / nexpand_children;
199 y = allocation->y + GTK_CONTAINER (box)->border_width;
200 child_allocation.x = allocation->x + GTK_CONTAINER (box)->border_width;
201 child_allocation.width = MAX (1, allocation->width - GTK_CONTAINER (box)->border_width * 2);
203 children = box->children;
206 child = children->data;
207 children = children->next;
209 if ((child->pack == GTK_PACK_START) && GTK_WIDGET_VISIBLE (child->widget))
211 if (box->homogeneous)
213 if (nvis_children == 1)
214 child_height = height;
216 child_height = extra;
223 child_height = child->widget->requisition.height + child->padding * 2;
227 if (nexpand_children == 1)
228 child_height += height;
230 child_height += extra;
232 nexpand_children -= 1;
239 child_allocation.height = MAX (1, child_height - child->padding * 2);
240 child_allocation.y = y + child->padding;
244 child_allocation.height = child->widget->requisition.height;
245 child_allocation.y = y + (child_height - child_allocation.height) / 2;
248 gtk_widget_size_allocate (child->widget, &child_allocation);
250 y += child_height + box->spacing;
254 y = allocation->y + allocation->height - GTK_CONTAINER (box)->border_width;
256 children = box->children;
259 child = children->data;
260 children = children->next;
262 if ((child->pack == GTK_PACK_END) && GTK_WIDGET_VISIBLE (child->widget))
264 if (box->homogeneous)
266 if (nvis_children == 1)
267 child_height = height;
269 child_height = extra;
276 child_height = child->widget->requisition.height + child->padding * 2;
280 if (nexpand_children == 1)
281 child_height += height;
283 child_height += extra;
285 nexpand_children -= 1;
292 child_allocation.height = MAX (1, child_height - child->padding * 2);
293 child_allocation.y = y + child->padding - child_height;
297 child_allocation.height = child->widget->requisition.height;
298 child_allocation.y = y + (child_height - child_allocation.height) / 2 - child_height;
301 gtk_widget_size_allocate (child->widget, &child_allocation);
303 y -= (child_height + box->spacing);