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.
21 * Modified by the GTK+ Team and others 1997-1999. 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_hbutton_box_class_init (GtkHButtonBoxClass *klass);
31 static void gtk_hbutton_box_init (GtkHButtonBox *box);
32 static void gtk_hbutton_box_size_request (GtkWidget *widget,
33 GtkRequisition *requisition);
34 static void gtk_hbutton_box_size_allocate (GtkWidget *widget,
35 GtkAllocation *allocation);
37 static gint default_spacing = 30;
38 static gint default_layout_style = GTK_BUTTONBOX_EDGE;
41 gtk_hbutton_box_get_type (void)
43 static GtkType hbutton_box_type = 0;
45 if (!hbutton_box_type)
47 static const GtkTypeInfo hbutton_box_info =
50 sizeof (GtkHButtonBox),
51 sizeof (GtkHButtonBoxClass),
52 (GtkClassInitFunc) gtk_hbutton_box_class_init,
53 (GtkObjectInitFunc) gtk_hbutton_box_init,
54 /* reserved_1 */ NULL,
55 /* reserved_2 */ NULL,
56 (GtkClassInitFunc) NULL,
59 hbutton_box_type = gtk_type_unique (GTK_TYPE_BUTTON_BOX, &hbutton_box_info);
62 return hbutton_box_type;
66 gtk_hbutton_box_class_init (GtkHButtonBoxClass *class)
68 GtkWidgetClass *widget_class;
70 widget_class = (GtkWidgetClass*) class;
72 widget_class->size_request = gtk_hbutton_box_size_request;
73 widget_class->size_allocate = gtk_hbutton_box_size_allocate;
77 gtk_hbutton_box_init (GtkHButtonBox *hbutton_box)
79 /* button_box_init has done everything allready */
83 gtk_hbutton_box_new (void)
85 GtkHButtonBox *hbutton_box;
87 hbutton_box = gtk_type_new (GTK_TYPE_HBUTTON_BOX);
89 return GTK_WIDGET (hbutton_box);
93 /* set default value for spacing */
95 void gtk_hbutton_box_set_spacing_default (gint spacing)
97 default_spacing = spacing;
101 /* set default value for layout style */
103 void gtk_hbutton_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_hbutton_box_get_spacing_default (void)
115 return default_spacing;
119 /* get default value for layout style */
121 GtkButtonBoxStyle gtk_hbutton_box_get_layout_default (void)
123 return default_layout_style;
129 gtk_hbutton_box_size_request (GtkWidget *widget,
130 GtkRequisition *requisition)
138 GtkButtonBoxStyle layout;
140 g_return_if_fail (widget != NULL);
141 g_return_if_fail (GTK_IS_HBUTTON_BOX (widget));
142 g_return_if_fail (requisition != NULL);
144 box = GTK_BOX (widget);
145 bbox = GTK_BUTTON_BOX (widget);
147 spacing = bbox->spacing != GTK_BUTTONBOX_DEFAULT
148 ? bbox->spacing : default_spacing;
149 layout = bbox->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
150 ? bbox->layout_style : default_layout_style;
152 gtk_button_box_child_requisition (widget,
157 if (nvis_children == 0)
159 requisition->width = 0;
160 requisition->height = 0;
166 case GTK_BUTTONBOX_SPREAD:
168 nvis_children*child_width + ((nvis_children+1)*spacing);
170 case GTK_BUTTONBOX_EDGE:
171 case GTK_BUTTONBOX_START:
172 case GTK_BUTTONBOX_END:
173 requisition->width = nvis_children*child_width + ((nvis_children-1)*spacing);
176 g_assert_not_reached();
180 requisition->height = child_height;
183 requisition->width += GTK_CONTAINER (box)->border_width * 2;
184 requisition->height += GTK_CONTAINER (box)->border_width * 2;
190 gtk_hbutton_box_size_allocate (GtkWidget *widget,
191 GtkAllocation *allocation)
197 GtkAllocation child_allocation;
205 gint childspacing = 0;
206 GtkButtonBoxStyle layout;
209 g_return_if_fail (widget != NULL);
210 g_return_if_fail (GTK_IS_HBUTTON_BOX (widget));
211 g_return_if_fail (allocation != NULL);
213 box = GTK_BUTTON_BOX (widget);
214 hbox = GTK_HBUTTON_BOX (widget);
215 spacing = box->spacing != GTK_BUTTONBOX_DEFAULT
216 ? box->spacing : default_spacing;
217 layout = box->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
218 ? box->layout_style : default_layout_style;
219 gtk_button_box_child_requisition (widget,
223 widget->allocation = *allocation;
224 width = allocation->width - GTK_CONTAINER (box)->border_width*2;
227 case GTK_BUTTONBOX_SPREAD:
228 childspacing = (width - (nvis_children*child_width)) / (nvis_children+1);
229 x = allocation->x + GTK_CONTAINER (box)->border_width + childspacing;
231 case GTK_BUTTONBOX_EDGE:
232 if (nvis_children >= 2)
235 (width - (nvis_children*child_width)) / (nvis_children-1);
236 x = allocation->x + GTK_CONTAINER (box)->border_width;
240 /* one or zero children, just center */
241 childspacing = width;
242 x = allocation->x + (allocation->width - child_width) / 2;
245 case GTK_BUTTONBOX_START:
246 childspacing = spacing;
247 x = allocation->x + GTK_CONTAINER (box)->border_width;
249 case GTK_BUTTONBOX_END:
250 childspacing = spacing;
251 x = allocation->x + allocation->width - child_width * nvis_children
252 - spacing *(nvis_children-1)
253 - GTK_CONTAINER (box)->border_width;
256 g_assert_not_reached();
261 y = allocation->y + (allocation->height - child_height) / 2;
262 childspace = child_width + childspacing;
264 children = GTK_BOX (box)->children;
268 child = children->data;
269 children = children->next;
271 if (GTK_WIDGET_VISIBLE (child->widget))
273 child_allocation.width = child_width;
274 child_allocation.height = child_height;
275 child_allocation.x = x;
276 child_allocation.y = y;
277 gtk_widget_size_allocate (child->widget, &child_allocation);