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/.
31 static void gtk_vbutton_box_class_init (GtkVButtonBoxClass *klass);
32 static void gtk_vbutton_box_init (GtkVButtonBox *box);
33 static void gtk_vbutton_box_size_request (GtkWidget *widget,
34 GtkRequisition *requisition);
35 static void gtk_vbutton_box_size_allocate (GtkWidget *widget,
36 GtkAllocation *allocation);
38 static gint default_spacing = 10;
39 static GtkButtonBoxStyle default_layout_style = GTK_BUTTONBOX_EDGE;
42 gtk_vbutton_box_get_type (void)
44 static GType vbutton_box_type = 0;
46 if (!vbutton_box_type)
48 static const GTypeInfo vbutton_box_info =
50 sizeof (GtkVButtonBoxClass),
52 NULL, /* base_finalize */
53 (GClassInitFunc) gtk_vbutton_box_class_init,
54 NULL, /* class_finalize */
55 NULL, /* class_data */
56 sizeof (GtkVButtonBox),
58 (GInstanceInitFunc) gtk_vbutton_box_init,
62 g_type_register_static (GTK_TYPE_BUTTON_BOX, "GtkVButtonBox",
63 &vbutton_box_info, 0);
66 return vbutton_box_type;
70 gtk_vbutton_box_class_init (GtkVButtonBoxClass *class)
72 GtkWidgetClass *widget_class;
74 widget_class = (GtkWidgetClass*) class;
76 widget_class->size_request = gtk_vbutton_box_size_request;
77 widget_class->size_allocate = gtk_vbutton_box_size_allocate;
81 gtk_vbutton_box_init (GtkVButtonBox *vbutton_box)
83 /* button_box_init has done everything allready */
87 gtk_vbutton_box_new (void)
89 GtkVButtonBox *vbutton_box;
91 vbutton_box = g_object_new (GTK_TYPE_VBUTTON_BOX, NULL);
93 return GTK_WIDGET (vbutton_box);
98 /* set default value for spacing */
101 gtk_vbutton_box_set_spacing_default (gint spacing)
103 default_spacing = spacing;
107 /* set default value for layout style */
110 gtk_vbutton_box_set_layout_default (GtkButtonBoxStyle layout)
112 g_return_if_fail (layout >= GTK_BUTTONBOX_DEFAULT_STYLE &&
113 layout <= GTK_BUTTONBOX_END);
115 default_layout_style = layout;
118 /* get default value for spacing */
121 gtk_vbutton_box_get_spacing_default (void)
123 return default_spacing;
128 /* get default value for layout style */
131 gtk_vbutton_box_get_layout_default (void)
133 return default_layout_style;
140 gtk_vbutton_box_size_request (GtkWidget *widget,
141 GtkRequisition *requisition)
149 GtkButtonBoxStyle layout;
151 box = GTK_BOX (widget);
152 bbox = GTK_BUTTON_BOX (widget);
154 spacing = box->spacing;
155 layout = bbox->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
156 ? bbox->layout_style : default_layout_style;
158 _gtk_button_box_child_requisition (widget,
164 if (nvis_children == 0)
166 requisition->width = 0;
167 requisition->height = 0;
173 case GTK_BUTTONBOX_SPREAD:
174 requisition->height =
175 nvis_children*child_height + ((nvis_children+1)*spacing);
177 case GTK_BUTTONBOX_EDGE:
178 case GTK_BUTTONBOX_START:
179 case GTK_BUTTONBOX_END:
180 requisition->height =
181 nvis_children*child_height + ((nvis_children-1)*spacing);
184 g_assert_not_reached();
188 requisition->width = child_width;
191 requisition->width += GTK_CONTAINER (box)->border_width * 2;
192 requisition->height += GTK_CONTAINER (box)->border_width * 2;
198 gtk_vbutton_box_size_allocate (GtkWidget *widget,
199 GtkAllocation *allocation)
206 GtkAllocation child_allocation;
213 gint secondary_y = 0;
216 gint childspacing = 0;
217 GtkButtonBoxStyle layout;
220 base_box = GTK_BOX (widget);
221 box = GTK_BUTTON_BOX (widget);
222 hbox = GTK_VBUTTON_BOX (widget);
223 spacing = base_box->spacing;
224 layout = box->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
225 ? box->layout_style : default_layout_style;
226 _gtk_button_box_child_requisition (widget,
231 widget->allocation = *allocation;
232 height = allocation->height - GTK_CONTAINER (box)->border_width*2;
235 case GTK_BUTTONBOX_SPREAD:
236 childspacing = (height - (nvis_children * child_height)) / (nvis_children + 1);
237 y = allocation->y + GTK_CONTAINER (box)->border_width + childspacing;
238 secondary_y = y + ((nvis_children - n_secondaries) * (child_height + childspacing));
240 case GTK_BUTTONBOX_EDGE:
241 if (nvis_children >= 2)
243 childspacing = (height - (nvis_children*child_height)) / (nvis_children-1);
244 y = allocation->y + GTK_CONTAINER (box)->border_width;
245 secondary_y = y + ((nvis_children - n_secondaries) * (child_height + childspacing));
249 /* one or zero children, just center */
250 childspacing = height;
251 y = secondary_y = allocation->y + (allocation->height - child_height) / 2;
254 case GTK_BUTTONBOX_START:
255 childspacing = spacing;
256 y = allocation->y + GTK_CONTAINER (box)->border_width;
257 secondary_y = allocation->y + allocation->height
258 - child_height * n_secondaries
259 - spacing * (n_secondaries - 1)
260 - GTK_CONTAINER (box)->border_width;
262 case GTK_BUTTONBOX_END:
263 childspacing = spacing;
264 y = allocation->y + allocation->height
265 - child_height * (nvis_children - n_secondaries)
266 - spacing * (nvis_children - n_secondaries - 1)
267 - GTK_CONTAINER (box)->border_width;
268 secondary_y = allocation->y + GTK_CONTAINER (box)->border_width;
271 g_assert_not_reached();
276 x = allocation->x + (allocation->width - child_width) / 2;
277 childspace = child_height + childspacing;
279 children = GTK_BOX (box)->children;
283 child = children->data;
284 children = children->next;
286 if (GTK_WIDGET_VISIBLE (child->widget))
288 child_allocation.width = child_width;
289 child_allocation.height = child_height;
290 child_allocation.x = x;
292 if (child->is_secondary)
294 child_allocation.y = secondary_y;
295 secondary_y += childspace;
299 child_allocation.y = y;
303 gtk_widget_size_allocate (child->widget, &child_allocation);