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_vbutton_box_class_init (GtkVButtonBoxClass *klass);
34 static void gtk_vbutton_box_init (GtkVButtonBox *box);
35 static void gtk_vbutton_box_size_request (GtkWidget *widget,
36 GtkRequisition *requisition);
37 static void gtk_vbutton_box_size_allocate (GtkWidget *widget,
38 GtkAllocation *allocation);
40 static gint default_spacing = 10;
41 static GtkButtonBoxStyle default_layout_style = GTK_BUTTONBOX_EDGE;
44 gtk_vbutton_box_get_type (void)
46 static GType vbutton_box_type = 0;
48 if (!vbutton_box_type)
50 static const GTypeInfo vbutton_box_info =
52 sizeof (GtkVButtonBoxClass),
54 NULL, /* base_finalize */
55 (GClassInitFunc) gtk_vbutton_box_class_init,
56 NULL, /* class_finalize */
57 NULL, /* class_data */
58 sizeof (GtkVButtonBox),
60 (GInstanceInitFunc) gtk_vbutton_box_init,
64 g_type_register_static (GTK_TYPE_BUTTON_BOX, I_("GtkVButtonBox"),
65 &vbutton_box_info, 0);
68 return vbutton_box_type;
72 gtk_vbutton_box_class_init (GtkVButtonBoxClass *class)
74 GtkWidgetClass *widget_class;
76 widget_class = (GtkWidgetClass*) class;
78 widget_class->size_request = gtk_vbutton_box_size_request;
79 widget_class->size_allocate = gtk_vbutton_box_size_allocate;
83 gtk_vbutton_box_init (GtkVButtonBox *vbutton_box)
85 /* button_box_init has done everything allready */
89 gtk_vbutton_box_new (void)
91 GtkVButtonBox *vbutton_box;
93 vbutton_box = g_object_new (GTK_TYPE_VBUTTON_BOX, NULL);
95 return GTK_WIDGET (vbutton_box);
100 /* set default value for spacing */
103 gtk_vbutton_box_set_spacing_default (gint spacing)
105 default_spacing = spacing;
109 /* set default value for layout style */
112 gtk_vbutton_box_set_layout_default (GtkButtonBoxStyle layout)
114 g_return_if_fail (layout >= GTK_BUTTONBOX_DEFAULT_STYLE &&
115 layout <= GTK_BUTTONBOX_END);
117 default_layout_style = layout;
120 /* get default value for spacing */
123 gtk_vbutton_box_get_spacing_default (void)
125 return default_spacing;
130 /* get default value for layout style */
133 gtk_vbutton_box_get_layout_default (void)
135 return default_layout_style;
142 gtk_vbutton_box_size_request (GtkWidget *widget,
143 GtkRequisition *requisition)
151 GtkButtonBoxStyle layout;
153 box = GTK_BOX (widget);
154 bbox = GTK_BUTTON_BOX (widget);
156 spacing = box->spacing;
157 layout = bbox->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
158 ? bbox->layout_style : default_layout_style;
160 _gtk_button_box_child_requisition (widget,
166 if (nvis_children == 0)
168 requisition->width = 0;
169 requisition->height = 0;
175 case GTK_BUTTONBOX_SPREAD:
176 requisition->height =
177 nvis_children*child_height + ((nvis_children+1)*spacing);
179 case GTK_BUTTONBOX_EDGE:
180 case GTK_BUTTONBOX_START:
181 case GTK_BUTTONBOX_END:
182 requisition->height =
183 nvis_children*child_height + ((nvis_children-1)*spacing);
186 g_assert_not_reached();
190 requisition->width = child_width;
193 requisition->width += GTK_CONTAINER (box)->border_width * 2;
194 requisition->height += GTK_CONTAINER (box)->border_width * 2;
200 gtk_vbutton_box_size_allocate (GtkWidget *widget,
201 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 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);
308 #define __GTK_VBBOX_C__
309 #include "gtkaliasdef.c"