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/.
33 static void gtk_vbox_size_request (GtkWidget *widget,
34 GtkRequisition *requisition);
35 static void gtk_vbox_size_allocate (GtkWidget *widget,
36 GtkAllocation *allocation);
38 G_DEFINE_TYPE (GtkVBox, gtk_vbox, GTK_TYPE_BOX)
41 gtk_vbox_class_init (GtkVBoxClass *class)
43 GtkWidgetClass *widget_class;
45 widget_class = (GtkWidgetClass*) class;
47 widget_class->size_request = gtk_vbox_size_request;
48 widget_class->size_allocate = gtk_vbox_size_allocate;
52 gtk_vbox_init (GtkVBox *vbox)
57 gtk_vbox_new (gboolean homogeneous,
62 vbox = g_object_new (GTK_TYPE_VBOX, NULL);
64 GTK_BOX (vbox)->spacing = spacing;
65 GTK_BOX (vbox)->homogeneous = homogeneous ? TRUE : FALSE;
67 return GTK_WIDGET (vbox);
72 gtk_vbox_size_request (GtkWidget *widget,
73 GtkRequisition *requisition)
77 GtkRequisition child_requisition;
82 box = GTK_BOX (widget);
83 requisition->width = 0;
84 requisition->height = 0;
87 children = box->children;
90 child = children->data;
91 children = children->next;
93 if (GTK_WIDGET_VISIBLE (child->widget))
95 gtk_widget_size_request (child->widget, &child_requisition);
99 height = child_requisition.height + child->padding * 2;
100 requisition->height = MAX (requisition->height, height);
104 requisition->height += child_requisition.height + child->padding * 2;
107 requisition->width = MAX (requisition->width, child_requisition.width);
113 if (nvis_children > 0)
115 if (box->homogeneous)
116 requisition->height *= nvis_children;
117 requisition->height += (nvis_children - 1) * box->spacing;
120 requisition->width += GTK_CONTAINER (box)->border_width * 2;
121 requisition->height += GTK_CONTAINER (box)->border_width * 2;
125 gtk_vbox_size_allocate (GtkWidget *widget,
126 GtkAllocation *allocation)
131 GtkAllocation child_allocation;
133 gint nexpand_children;
139 box = GTK_BOX (widget);
140 widget->allocation = *allocation;
143 nexpand_children = 0;
144 children = box->children;
148 child = children->data;
149 children = children->next;
151 if (GTK_WIDGET_VISIBLE (child->widget))
155 nexpand_children += 1;
159 if (nvis_children > 0)
161 if (box->homogeneous)
163 height = (allocation->height -
164 GTK_CONTAINER (box)->border_width * 2 -
165 (nvis_children - 1) * box->spacing);
166 extra = height / nvis_children;
168 else if (nexpand_children > 0)
170 height = (gint) allocation->height - (gint) widget->requisition.height;
171 extra = height / nexpand_children;
179 y = allocation->y + GTK_CONTAINER (box)->border_width;
180 child_allocation.x = allocation->x + GTK_CONTAINER (box)->border_width;
181 child_allocation.width = MAX (1, (gint) allocation->width - (gint) GTK_CONTAINER (box)->border_width * 2);
183 children = box->children;
186 child = children->data;
187 children = children->next;
189 if ((child->pack == GTK_PACK_START) && GTK_WIDGET_VISIBLE (child->widget))
191 if (box->homogeneous)
193 if (nvis_children == 1)
194 child_height = height;
196 child_height = extra;
203 GtkRequisition child_requisition;
205 gtk_widget_get_child_requisition (child->widget, &child_requisition);
206 child_height = child_requisition.height + child->padding * 2;
210 if (nexpand_children == 1)
211 child_height += height;
213 child_height += extra;
215 nexpand_children -= 1;
222 child_allocation.height = MAX (1, child_height - (gint)child->padding * 2);
223 child_allocation.y = y + child->padding;
227 GtkRequisition child_requisition;
229 gtk_widget_get_child_requisition (child->widget, &child_requisition);
230 child_allocation.height = child_requisition.height;
231 child_allocation.y = y + (child_height - child_allocation.height) / 2;
234 gtk_widget_size_allocate (child->widget, &child_allocation);
236 y += child_height + box->spacing;
240 y = allocation->y + allocation->height - GTK_CONTAINER (box)->border_width;
242 children = box->children;
245 child = children->data;
246 children = children->next;
248 if ((child->pack == GTK_PACK_END) && GTK_WIDGET_VISIBLE (child->widget))
250 GtkRequisition child_requisition;
251 gtk_widget_get_child_requisition (child->widget, &child_requisition);
253 if (box->homogeneous)
255 if (nvis_children == 1)
256 child_height = height;
258 child_height = extra;
265 child_height = child_requisition.height + child->padding * 2;
269 if (nexpand_children == 1)
270 child_height += height;
272 child_height += extra;
274 nexpand_children -= 1;
281 child_allocation.height = MAX (1, child_height - (gint)child->padding * 2);
282 child_allocation.y = y + child->padding - child_height;
286 child_allocation.height = child_requisition.height;
287 child_allocation.y = y + (child_height - child_allocation.height) / 2 - child_height;
290 gtk_widget_size_allocate (child->widget, &child_allocation);
292 y -= (child_height + box->spacing);
298 #define __GTK_VBOX_C__
299 #include "gtkaliasdef.c"