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/.
32 static void gtk_vbutton_box_class_init (GtkVButtonBoxClass *klass);
33 static void gtk_vbutton_box_init (GtkVButtonBox *box);
34 static void gtk_vbutton_box_size_request (GtkWidget *widget,
35 GtkRequisition *requisition);
36 static void gtk_vbutton_box_size_allocate (GtkWidget *widget,
37 GtkAllocation *allocation);
39 static gint default_spacing = 10;
40 static GtkButtonBoxStyle default_layout_style = GTK_BUTTONBOX_EDGE;
43 gtk_vbutton_box_get_type (void)
45 static GType vbutton_box_type = 0;
47 if (!vbutton_box_type)
49 static const GTypeInfo vbutton_box_info =
51 sizeof (GtkVButtonBoxClass),
53 NULL, /* base_finalize */
54 (GClassInitFunc) gtk_vbutton_box_class_init,
55 NULL, /* class_finalize */
56 NULL, /* class_data */
57 sizeof (GtkVButtonBox),
59 (GInstanceInitFunc) gtk_vbutton_box_init,
63 g_type_register_static (GTK_TYPE_BUTTON_BOX, "GtkVButtonBox",
64 &vbutton_box_info, 0);
67 return vbutton_box_type;
71 gtk_vbutton_box_class_init (GtkVButtonBoxClass *class)
73 GtkWidgetClass *widget_class;
75 widget_class = (GtkWidgetClass*) class;
77 widget_class->size_request = gtk_vbutton_box_size_request;
78 widget_class->size_allocate = gtk_vbutton_box_size_allocate;
82 gtk_vbutton_box_init (GtkVButtonBox *vbutton_box)
84 /* button_box_init has done everything allready */
88 gtk_vbutton_box_new (void)
90 GtkVButtonBox *vbutton_box;
92 vbutton_box = g_object_new (GTK_TYPE_VBUTTON_BOX, NULL);
94 return GTK_WIDGET (vbutton_box);
99 /* set default value for spacing */
102 gtk_vbutton_box_set_spacing_default (gint spacing)
104 default_spacing = spacing;
108 /* set default value for layout style */
111 gtk_vbutton_box_set_layout_default (GtkButtonBoxStyle layout)
113 g_return_if_fail (layout >= GTK_BUTTONBOX_DEFAULT_STYLE &&
114 layout <= GTK_BUTTONBOX_END);
116 default_layout_style = layout;
119 /* get default value for spacing */
122 gtk_vbutton_box_get_spacing_default (void)
124 return default_spacing;
129 /* get default value for layout style */
132 gtk_vbutton_box_get_layout_default (void)
134 return default_layout_style;
141 gtk_vbutton_box_size_request (GtkWidget *widget,
142 GtkRequisition *requisition)
150 GtkButtonBoxStyle layout;
152 box = GTK_BOX (widget);
153 bbox = GTK_BUTTON_BOX (widget);
155 spacing = box->spacing;
156 layout = bbox->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
157 ? bbox->layout_style : default_layout_style;
159 _gtk_button_box_child_requisition (widget,
165 if (nvis_children == 0)
167 requisition->width = 0;
168 requisition->height = 0;
174 case GTK_BUTTONBOX_SPREAD:
175 requisition->height =
176 nvis_children*child_height + ((nvis_children+1)*spacing);
178 case GTK_BUTTONBOX_EDGE:
179 case GTK_BUTTONBOX_START:
180 case GTK_BUTTONBOX_END:
181 requisition->height =
182 nvis_children*child_height + ((nvis_children-1)*spacing);
185 g_assert_not_reached();
189 requisition->width = child_width;
192 requisition->width += GTK_CONTAINER (box)->border_width * 2;
193 requisition->height += GTK_CONTAINER (box)->border_width * 2;
199 gtk_vbutton_box_size_allocate (GtkWidget *widget,
200 GtkAllocation *allocation)
207 GtkAllocation child_allocation;
214 gint secondary_y = 0;
217 gint childspacing = 0;
218 GtkButtonBoxStyle layout;
221 base_box = GTK_BOX (widget);
222 box = GTK_BUTTON_BOX (widget);
223 hbox = GTK_VBUTTON_BOX (widget);
224 spacing = base_box->spacing;
225 layout = box->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
226 ? box->layout_style : default_layout_style;
227 _gtk_button_box_child_requisition (widget,
232 widget->allocation = *allocation;
233 height = allocation->height - GTK_CONTAINER (box)->border_width*2;
236 case GTK_BUTTONBOX_SPREAD:
237 childspacing = (height - (nvis_children * child_height)) / (nvis_children + 1);
238 y = allocation->y + GTK_CONTAINER (box)->border_width + childspacing;
239 secondary_y = y + ((nvis_children - n_secondaries) * (child_height + childspacing));
241 case GTK_BUTTONBOX_EDGE:
242 if (nvis_children >= 2)
244 childspacing = (height - (nvis_children*child_height)) / (nvis_children-1);
245 y = allocation->y + GTK_CONTAINER (box)->border_width;
246 secondary_y = y + ((nvis_children - n_secondaries) * (child_height + childspacing));
250 /* one or zero children, just center */
251 childspacing = height;
252 y = secondary_y = allocation->y + (allocation->height - child_height) / 2;
255 case GTK_BUTTONBOX_START:
256 childspacing = spacing;
257 y = allocation->y + GTK_CONTAINER (box)->border_width;
258 secondary_y = allocation->y + allocation->height
259 - child_height * n_secondaries
260 - spacing * (n_secondaries - 1)
261 - GTK_CONTAINER (box)->border_width;
263 case GTK_BUTTONBOX_END:
264 childspacing = spacing;
265 y = allocation->y + allocation->height
266 - child_height * (nvis_children - n_secondaries)
267 - spacing * (nvis_children - n_secondaries - 1)
268 - GTK_CONTAINER (box)->border_width;
269 secondary_y = allocation->y + GTK_CONTAINER (box)->border_width;
272 g_assert_not_reached();
277 x = allocation->x + (allocation->width - child_width) / 2;
278 childspace = child_height + childspacing;
280 children = GTK_BOX (box)->children;
284 child = children->data;
285 children = children->next;
287 if (GTK_WIDGET_VISIBLE (child->widget))
289 child_allocation.width = child_width;
290 child_allocation.height = child_height;
291 child_allocation.x = x;
293 if (child->is_secondary)
295 child_allocation.y = secondary_y;
296 secondary_y += childspace;
300 child_allocation.y = y;
304 gtk_widget_size_allocate (child->widget, &child_allocation);
309 #define __GTK_VBBOX_C__
310 #include "gtkaliasdef.c"