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_size_request (GtkWidget *widget,
34 GtkRequisition *requisition);
35 static void gtk_vbutton_box_size_allocate (GtkWidget *widget,
36 GtkAllocation *allocation);
38 static gint default_spacing = 10;
39 static GtkButtonBoxStyle default_layout_style = GTK_BUTTONBOX_EDGE;
41 G_DEFINE_TYPE (GtkVButtonBox, gtk_vbutton_box, GTK_TYPE_BUTTON_BOX)
44 gtk_vbutton_box_class_init (GtkVButtonBoxClass *class)
46 GtkWidgetClass *widget_class;
48 widget_class = (GtkWidgetClass*) class;
50 widget_class->size_request = gtk_vbutton_box_size_request;
51 widget_class->size_allocate = gtk_vbutton_box_size_allocate;
55 gtk_vbutton_box_init (GtkVButtonBox *vbutton_box)
57 /* button_box_init has done everything allready */
61 gtk_vbutton_box_new (void)
63 GtkVButtonBox *vbutton_box;
65 vbutton_box = g_object_new (GTK_TYPE_VBUTTON_BOX, NULL);
67 return GTK_WIDGET (vbutton_box);
72 /* set default value for spacing */
75 gtk_vbutton_box_set_spacing_default (gint spacing)
77 default_spacing = spacing;
81 /* set default value for layout style */
84 gtk_vbutton_box_set_layout_default (GtkButtonBoxStyle layout)
86 g_return_if_fail (layout >= GTK_BUTTONBOX_DEFAULT_STYLE &&
87 layout <= GTK_BUTTONBOX_CENTER);
89 default_layout_style = layout;
92 /* get default value for spacing */
95 gtk_vbutton_box_get_spacing_default (void)
97 return default_spacing;
102 /* get default value for layout style */
105 gtk_vbutton_box_get_layout_default (void)
107 return default_layout_style;
114 gtk_vbutton_box_size_request (GtkWidget *widget,
115 GtkRequisition *requisition)
123 GtkButtonBoxStyle layout;
125 box = GTK_BOX (widget);
126 bbox = GTK_BUTTON_BOX (widget);
128 spacing = box->spacing;
129 layout = bbox->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
130 ? bbox->layout_style : default_layout_style;
132 _gtk_button_box_child_requisition (widget,
138 if (nvis_children == 0)
140 requisition->width = 0;
141 requisition->height = 0;
147 case GTK_BUTTONBOX_SPREAD:
148 requisition->height =
149 nvis_children*child_height + ((nvis_children+1)*spacing);
151 case GTK_BUTTONBOX_EDGE:
152 case GTK_BUTTONBOX_START:
153 case GTK_BUTTONBOX_END:
154 case GTK_BUTTONBOX_CENTER:
155 requisition->height =
156 nvis_children*child_height + ((nvis_children-1)*spacing);
159 g_assert_not_reached();
163 requisition->width = child_width;
166 requisition->width += GTK_CONTAINER (box)->border_width * 2;
167 requisition->height += GTK_CONTAINER (box)->border_width * 2;
173 gtk_vbutton_box_size_allocate (GtkWidget *widget,
174 GtkAllocation *allocation)
180 GtkAllocation child_allocation;
187 gint secondary_y = 0;
190 gint childspacing = 0;
191 GtkButtonBoxStyle layout;
194 base_box = GTK_BOX (widget);
195 box = GTK_BUTTON_BOX (widget);
196 spacing = base_box->spacing;
197 layout = box->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
198 ? box->layout_style : default_layout_style;
199 _gtk_button_box_child_requisition (widget,
204 widget->allocation = *allocation;
205 height = allocation->height - GTK_CONTAINER (box)->border_width*2;
208 case GTK_BUTTONBOX_SPREAD:
209 childspacing = (height - (nvis_children * child_height)) / (nvis_children + 1);
210 y = allocation->y + GTK_CONTAINER (box)->border_width + childspacing;
211 secondary_y = y + ((nvis_children - n_secondaries) * (child_height + childspacing));
213 case GTK_BUTTONBOX_EDGE:
214 if (nvis_children >= 2)
216 childspacing = (height - (nvis_children*child_height)) / (nvis_children-1);
217 y = allocation->y + GTK_CONTAINER (box)->border_width;
218 secondary_y = y + ((nvis_children - n_secondaries) * (child_height + childspacing));
222 /* one or zero children, just center */
223 childspacing = height;
224 y = secondary_y = allocation->y + (allocation->height - child_height) / 2;
227 case GTK_BUTTONBOX_START:
228 childspacing = spacing;
229 y = allocation->y + GTK_CONTAINER (box)->border_width;
230 secondary_y = allocation->y + allocation->height
231 - child_height * n_secondaries
232 - spacing * (n_secondaries - 1)
233 - GTK_CONTAINER (box)->border_width;
235 case GTK_BUTTONBOX_END:
236 childspacing = spacing;
237 y = allocation->y + allocation->height
238 - child_height * (nvis_children - n_secondaries)
239 - spacing * (nvis_children - n_secondaries - 1)
240 - GTK_CONTAINER (box)->border_width;
241 secondary_y = allocation->y + GTK_CONTAINER (box)->border_width;
243 case GTK_BUTTONBOX_CENTER:
244 childspacing = spacing;
247 - (child_height * (nvis_children - n_secondaries)
248 + spacing * (nvis_children - n_secondaries - 1)))/2
249 + (n_secondaries * child_height + n_secondaries * spacing)/2;
250 secondary_y = allocation->y + GTK_CONTAINER (box)->border_width;
253 g_assert_not_reached();
258 x = allocation->x + (allocation->width - child_width) / 2;
259 childspace = child_height + childspacing;
261 children = GTK_BOX (box)->children;
265 child = children->data;
266 children = children->next;
268 if (GTK_WIDGET_VISIBLE (child->widget))
270 child_allocation.width = child_width;
271 child_allocation.height = child_height;
272 child_allocation.x = x;
274 if (child->is_secondary)
276 child_allocation.y = secondary_y;
277 secondary_y += childspace;
281 child_allocation.y = y;
285 gtk_widget_size_allocate (child->widget, &child_allocation);
290 #define __GTK_VBBOX_C__
291 #include "gtkaliasdef.c"