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 GtkType vbutton_box_type = 0;
45 if (!vbutton_box_type)
47 static const GtkTypeInfo vbutton_box_info =
50 sizeof (GtkVButtonBox),
51 sizeof (GtkVButtonBoxClass),
52 (GtkClassInitFunc) gtk_vbutton_box_class_init,
53 (GtkObjectInitFunc) gtk_vbutton_box_init,
54 /* reserved_1 */ NULL,
55 /* reserved_2 */ NULL,
56 (GtkClassInitFunc) NULL,
59 vbutton_box_type = gtk_type_unique (GTK_TYPE_BUTTON_BOX, &vbutton_box_info);
62 return vbutton_box_type;
66 gtk_vbutton_box_class_init (GtkVButtonBoxClass *class)
68 GtkWidgetClass *widget_class;
70 widget_class = (GtkWidgetClass*) class;
72 widget_class->size_request = gtk_vbutton_box_size_request;
73 widget_class->size_allocate = gtk_vbutton_box_size_allocate;
77 gtk_vbutton_box_init (GtkVButtonBox *vbutton_box)
79 /* button_box_init has done everything allready */
83 gtk_vbutton_box_new (void)
85 GtkVButtonBox *vbutton_box;
87 vbutton_box = gtk_type_new (GTK_TYPE_VBUTTON_BOX);
88 return GTK_WIDGET (vbutton_box);
93 /* set default value for spacing */
95 void gtk_vbutton_box_set_spacing_default (gint spacing)
97 default_spacing = spacing;
101 /* set default value for layout style */
103 void gtk_vbutton_box_set_layout_default (GtkButtonBoxStyle layout)
105 g_return_if_fail (layout >= GTK_BUTTONBOX_DEFAULT_STYLE &&
106 layout <= GTK_BUTTONBOX_END);
108 default_layout_style = layout;
111 /* get default value for spacing */
113 gint gtk_vbutton_box_get_spacing_default (void)
115 return default_spacing;
120 /* get default value for layout style */
122 GtkButtonBoxStyle gtk_vbutton_box_get_layout_default (void)
124 return default_layout_style;
131 gtk_vbutton_box_size_request (GtkWidget *widget,
132 GtkRequisition *requisition)
140 GtkButtonBoxStyle layout;
142 g_return_if_fail (widget != NULL);
143 g_return_if_fail (GTK_IS_VBUTTON_BOX (widget));
144 g_return_if_fail (requisition != NULL);
146 box = GTK_BOX (widget);
147 bbox = GTK_BUTTON_BOX (widget);
149 spacing = bbox->spacing != GTK_BUTTONBOX_DEFAULT
150 ? bbox->spacing : default_spacing;
151 layout = bbox->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
152 ? bbox->layout_style : default_layout_style;
154 gtk_button_box_child_requisition (widget,
159 if (nvis_children == 0)
161 requisition->width = 0;
162 requisition->height = 0;
168 case GTK_BUTTONBOX_SPREAD:
169 requisition->height =
170 nvis_children*child_height + ((nvis_children+1)*spacing);
172 case GTK_BUTTONBOX_EDGE:
173 case GTK_BUTTONBOX_START:
174 case GTK_BUTTONBOX_END:
175 requisition->height =
176 nvis_children*child_height + ((nvis_children-1)*spacing);
179 g_assert_not_reached();
183 requisition->width = child_width;
186 requisition->width += GTK_CONTAINER (box)->border_width * 2;
187 requisition->height += GTK_CONTAINER (box)->border_width * 2;
193 gtk_vbutton_box_size_allocate (GtkWidget *widget,
194 GtkAllocation *allocation)
200 GtkAllocation child_allocation;
208 gint childspacing = 0;
209 GtkButtonBoxStyle layout;
212 g_return_if_fail (widget != NULL);
213 g_return_if_fail (GTK_IS_VBUTTON_BOX (widget));
214 g_return_if_fail (allocation != NULL);
216 box = GTK_BUTTON_BOX (widget);
217 hbox = GTK_VBUTTON_BOX (widget);
218 spacing = box->spacing != GTK_BUTTONBOX_DEFAULT
219 ? box->spacing : default_spacing;
220 layout = box->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
221 ? box->layout_style : default_layout_style;
222 gtk_button_box_child_requisition (widget,
226 widget->allocation = *allocation;
227 height = allocation->height - GTK_CONTAINER (box)->border_width*2;
230 case GTK_BUTTONBOX_SPREAD:
231 childspacing = (height - (nvis_children*child_height)) / (nvis_children+1);
232 y = allocation->y + GTK_CONTAINER (box)->border_width + childspacing;
234 case GTK_BUTTONBOX_EDGE:
235 if (nvis_children >= 2)
238 (height - (nvis_children*child_height)) / (nvis_children-1);
239 y = allocation->y + GTK_CONTAINER (box)->border_width;
243 /* one or zero children, just center */
244 childspacing = height;
245 y = allocation->y + (allocation->height - child_height) / 2;
248 case GTK_BUTTONBOX_START:
249 childspacing = spacing;
250 y = allocation->y + GTK_CONTAINER (box)->border_width;
252 case GTK_BUTTONBOX_END:
253 childspacing = spacing;
254 y = allocation->y + allocation->height - child_height * nvis_children
255 - spacing * (nvis_children-1)
256 - GTK_CONTAINER (box)->border_width;
259 g_assert_not_reached();
264 x = allocation->x + (allocation->width - child_width) / 2;
265 childspace = child_height + childspacing;
267 children = GTK_BOX (box)->children;
271 child = children->data;
272 children = children->next;
274 if (GTK_WIDGET_VISIBLE (child->widget))
276 child_allocation.width = child_width;
277 child_allocation.height = child_height;
278 child_allocation.x = x;
279 child_allocation.y = y;
280 gtk_widget_size_allocate (child->widget, &child_allocation);