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 Library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library 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.
22 static void gtk_vbutton_box_class_init (GtkVButtonBoxClass *klass);
23 static void gtk_vbutton_box_init (GtkVButtonBox *box);
24 static void gtk_vbutton_box_size_request (GtkWidget *widget,
25 GtkRequisition *requisition);
26 static void gtk_vbutton_box_size_allocate (GtkWidget *widget,
27 GtkAllocation *allocation);
29 static gint default_spacing = 10;
30 static GtkButtonBoxStyle default_layout_style = GTK_BUTTONBOX_EDGE;
33 gtk_vbutton_box_get_type (void)
35 static guint vbutton_box_type = 0;
37 if (!vbutton_box_type)
39 GtkTypeInfo vbutton_box_info =
42 sizeof (GtkVButtonBox),
43 sizeof (GtkVButtonBoxClass),
44 (GtkClassInitFunc) gtk_vbutton_box_class_init,
45 (GtkObjectInitFunc) gtk_vbutton_box_init,
46 /* reversed_1 */ NULL,
47 /* reversed_2 */ NULL,
48 (GtkClassInitFunc) NULL,
51 vbutton_box_type = gtk_type_unique (gtk_button_box_get_type (), &vbutton_box_info);
54 return vbutton_box_type;
58 gtk_vbutton_box_class_init (GtkVButtonBoxClass *class)
60 GtkWidgetClass *widget_class;
62 widget_class = (GtkWidgetClass*) class;
64 widget_class->size_request = gtk_vbutton_box_size_request;
65 widget_class->size_allocate = gtk_vbutton_box_size_allocate;
69 gtk_vbutton_box_init (GtkVButtonBox *vbutton_box)
71 /* button_box_init has done everything allready */
75 gtk_vbutton_box_new (void)
77 GtkVButtonBox *vbutton_box;
79 vbutton_box = gtk_type_new (gtk_vbutton_box_get_type ());
80 return GTK_WIDGET (vbutton_box);
85 /* set default value for spacing */
87 void gtk_vbutton_box_set_spacing_default (gint spacing)
89 default_spacing = spacing;
93 /* set default value for layout style */
95 void gtk_vbutton_box_set_layout_default (GtkButtonBoxStyle layout)
97 g_return_if_fail (layout >= GTK_BUTTONBOX_DEFAULT_STYLE &&
98 layout <= GTK_BUTTONBOX_END);
100 default_layout_style = layout;
103 /* get default value for spacing */
105 gint gtk_vbutton_box_get_spacing_default (void)
107 return default_spacing;
112 /* get default value for layout style */
114 GtkButtonBoxStyle gtk_vbutton_box_get_layout_default (void)
116 return default_layout_style;
123 gtk_vbutton_box_size_request (GtkWidget *widget,
124 GtkRequisition *requisition)
132 GtkButtonBoxStyle layout;
134 g_return_if_fail (widget != NULL);
135 g_return_if_fail (GTK_IS_VBUTTON_BOX (widget));
136 g_return_if_fail (requisition != NULL);
138 box = GTK_BOX (widget);
139 bbox = GTK_BUTTON_BOX (widget);
141 spacing = bbox->spacing != GTK_BUTTONBOX_DEFAULT
142 ? bbox->spacing : default_spacing;
143 layout = bbox->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
144 ? bbox->layout_style : default_layout_style;
146 gtk_button_box_child_requisition (widget,
151 if (nvis_children == 0)
153 requisition->width = 0;
154 requisition->height = 0;
160 case GTK_BUTTONBOX_SPREAD:
161 requisition->height =
162 nvis_children*child_height + ((nvis_children+1)*spacing);
164 case GTK_BUTTONBOX_EDGE:
165 case GTK_BUTTONBOX_START:
166 case GTK_BUTTONBOX_END:
167 requisition->height =
168 nvis_children*child_height + ((nvis_children-1)*spacing);
171 g_assert_not_reached();
175 requisition->width = child_width;
178 requisition->width += GTK_CONTAINER (box)->border_width * 2;
179 requisition->height += GTK_CONTAINER (box)->border_width * 2;
185 gtk_vbutton_box_size_allocate (GtkWidget *widget,
186 GtkAllocation *allocation)
192 GtkAllocation child_allocation;
200 gint childspacing = 0;
201 GtkButtonBoxStyle layout;
204 g_return_if_fail (widget != NULL);
205 g_return_if_fail (GTK_IS_VBUTTON_BOX (widget));
206 g_return_if_fail (allocation != NULL);
208 box = GTK_BUTTON_BOX (widget);
209 hbox = GTK_VBUTTON_BOX (widget);
210 spacing = box->spacing != GTK_BUTTONBOX_DEFAULT
211 ? box->spacing : default_spacing;
212 layout = box->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
213 ? box->layout_style : default_layout_style;
214 gtk_button_box_child_requisition (widget,
218 widget->allocation = *allocation;
219 height = allocation->height - GTK_CONTAINER (box)->border_width*2;
222 case GTK_BUTTONBOX_SPREAD:
223 childspacing = (height - (nvis_children*child_height)) / (nvis_children+1);
224 y = allocation->y + GTK_CONTAINER (box)->border_width + childspacing;
226 case GTK_BUTTONBOX_EDGE:
227 if (nvis_children >= 2)
230 (height - (nvis_children*child_height)) / (nvis_children-1);
231 y = allocation->y + GTK_CONTAINER (box)->border_width;
235 /* one or zero children, just center */
236 childspacing = height;
237 y = allocation->y + (allocation->height - child_height) / 2;
240 case GTK_BUTTONBOX_START:
241 childspacing = spacing;
242 y = allocation->y + GTK_CONTAINER (box)->border_width;
244 case GTK_BUTTONBOX_END:
245 childspacing = spacing;
246 y = allocation->x + allocation->height - child_height * nvis_children
247 - spacing * (nvis_children-1)
248 - GTK_CONTAINER (box)->border_width;
251 g_assert_not_reached();
256 x = allocation->x + (allocation->width - child_width) / 2;
257 childspace = child_height + childspacing;
259 children = GTK_BOX (box)->children;
263 child = children->data;
264 children = children->next;
266 if (GTK_WIDGET_VISIBLE (child->widget))
268 child_allocation.width = child_width;
269 child_allocation.height = child_height;
270 child_allocation.x = x;
271 child_allocation.y = y;
272 gtk_widget_size_allocate (child->widget, &child_allocation);