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_vbutton_box_class_init (GtkVButtonBoxClass *klass);
31 static void gtk_vbutton_box_init (GtkVButtonBox *box);
32 static void gtk_vbutton_box_size_request (GtkWidget *widget,
33 GtkRequisition *requisition);
34 static void gtk_vbutton_box_size_allocate (GtkWidget *widget,
35 GtkAllocation *allocation);
37 static gint default_spacing = 10;
38 static GtkButtonBoxStyle default_layout_style = GTK_BUTTONBOX_EDGE;
41 gtk_vbutton_box_get_type (void)
43 static GType vbutton_box_type = 0;
45 if (!vbutton_box_type)
47 static const GTypeInfo vbutton_box_info =
49 sizeof (GtkVButtonBoxClass),
51 NULL, /* base_finalize */
52 (GClassInitFunc) gtk_vbutton_box_class_init,
53 NULL, /* class_finalize */
54 NULL, /* class_data */
55 sizeof (GtkVButtonBox),
57 (GInstanceInitFunc) gtk_vbutton_box_init,
61 g_type_register_static (GTK_TYPE_BUTTON_BOX, "GtkVButtonBox",
62 &vbutton_box_info, 0);
65 return vbutton_box_type;
69 gtk_vbutton_box_class_init (GtkVButtonBoxClass *class)
71 GtkWidgetClass *widget_class;
73 widget_class = (GtkWidgetClass*) class;
75 widget_class->size_request = gtk_vbutton_box_size_request;
76 widget_class->size_allocate = gtk_vbutton_box_size_allocate;
80 gtk_vbutton_box_init (GtkVButtonBox *vbutton_box)
82 /* button_box_init has done everything allready */
86 gtk_vbutton_box_new (void)
88 GtkVButtonBox *vbutton_box;
90 vbutton_box = g_object_new (GTK_TYPE_VBUTTON_BOX, NULL);
92 return GTK_WIDGET (vbutton_box);
97 /* set default value for spacing */
100 gtk_vbutton_box_set_spacing_default (gint spacing)
102 default_spacing = spacing;
106 /* set default value for layout style */
109 gtk_vbutton_box_set_layout_default (GtkButtonBoxStyle layout)
111 g_return_if_fail (layout >= GTK_BUTTONBOX_DEFAULT_STYLE &&
112 layout <= GTK_BUTTONBOX_END);
114 default_layout_style = layout;
117 /* get default value for spacing */
120 gtk_vbutton_box_get_spacing_default (void)
122 return default_spacing;
127 /* get default value for layout style */
130 gtk_vbutton_box_get_layout_default (void)
132 return default_layout_style;
139 gtk_vbutton_box_size_request (GtkWidget *widget,
140 GtkRequisition *requisition)
148 GtkButtonBoxStyle layout;
150 box = GTK_BOX (widget);
151 bbox = GTK_BUTTON_BOX (widget);
153 spacing = box->spacing;
154 layout = bbox->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
155 ? bbox->layout_style : default_layout_style;
157 _gtk_button_box_child_requisition (widget,
163 if (nvis_children == 0)
165 requisition->width = 0;
166 requisition->height = 0;
172 case GTK_BUTTONBOX_SPREAD:
173 requisition->height =
174 nvis_children*child_height + ((nvis_children+1)*spacing);
176 case GTK_BUTTONBOX_EDGE:
177 case GTK_BUTTONBOX_START:
178 case GTK_BUTTONBOX_END:
179 requisition->height =
180 nvis_children*child_height + ((nvis_children-1)*spacing);
183 g_assert_not_reached();
187 requisition->width = child_width;
190 requisition->width += GTK_CONTAINER (box)->border_width * 2;
191 requisition->height += GTK_CONTAINER (box)->border_width * 2;
197 gtk_vbutton_box_size_allocate (GtkWidget *widget,
198 GtkAllocation *allocation)
205 GtkAllocation child_allocation;
212 gint secondary_y = 0;
215 gint childspacing = 0;
216 GtkButtonBoxStyle layout;
219 base_box = GTK_BOX (widget);
220 box = GTK_BUTTON_BOX (widget);
221 hbox = GTK_VBUTTON_BOX (widget);
222 spacing = base_box->spacing;
223 layout = box->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
224 ? box->layout_style : default_layout_style;
225 _gtk_button_box_child_requisition (widget,
230 widget->allocation = *allocation;
231 height = allocation->height - GTK_CONTAINER (box)->border_width*2;
234 case GTK_BUTTONBOX_SPREAD:
235 childspacing = (height - (nvis_children * child_height)) / (nvis_children + 1);
236 y = allocation->y + GTK_CONTAINER (box)->border_width + childspacing;
237 secondary_y = y + ((nvis_children - n_secondaries) * (child_height + childspacing));
239 case GTK_BUTTONBOX_EDGE:
240 if (nvis_children >= 2)
242 childspacing = (height - (nvis_children*child_height)) / (nvis_children-1);
243 y = allocation->y + GTK_CONTAINER (box)->border_width;
244 secondary_y = y + ((nvis_children - n_secondaries) * (child_height + childspacing));
248 /* one or zero children, just center */
249 childspacing = height;
250 y = secondary_y = allocation->y + (allocation->height - child_height) / 2;
253 case GTK_BUTTONBOX_START:
254 childspacing = spacing;
255 y = allocation->y + GTK_CONTAINER (box)->border_width;
256 secondary_y = allocation->y + allocation->height
257 - child_height * n_secondaries
258 - spacing * (n_secondaries - 1)
259 - GTK_CONTAINER (box)->border_width;
261 case GTK_BUTTONBOX_END:
262 childspacing = spacing;
263 y = allocation->y + allocation->height
264 - child_height * (nvis_children - n_secondaries)
265 - spacing * (nvis_children - n_secondaries - 1)
266 - GTK_CONTAINER (box)->border_width;
267 secondary_y = allocation->y + GTK_CONTAINER (box)->border_width;
270 g_assert_not_reached();
275 x = allocation->x + (allocation->width - child_width) / 2;
276 childspace = child_height + childspacing;
278 children = GTK_BOX (box)->children;
282 child = children->data;
283 children = children->next;
285 if (GTK_WIDGET_VISIBLE (child->widget))
287 child_allocation.width = child_width;
288 child_allocation.height = child_height;
289 child_allocation.x = x;
291 if (child->is_secondary)
293 child_allocation.y = secondary_y;
294 secondary_y += childspace;
298 child_allocation.y = y;
302 gtk_widget_size_allocate (child->widget, &child_allocation);