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 Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 static void gtk_hbutton_box_class_init (GtkHButtonBoxClass *klass);
23 static void gtk_hbutton_box_init (GtkHButtonBox *box);
24 static void gtk_hbutton_box_size_request (GtkWidget *widget,
25 GtkRequisition *requisition);
26 static void gtk_hbutton_box_size_allocate (GtkWidget *widget,
27 GtkAllocation *allocation);
29 static gint default_spacing = 30;
30 static gint default_layout_style = GTK_BUTTONBOX_EDGE;
33 gtk_hbutton_box_get_type ()
35 static guint hbutton_box_type = 0;
37 if (!hbutton_box_type)
39 GtkTypeInfo hbutton_box_info =
42 sizeof (GtkHButtonBox),
43 sizeof (GtkHButtonBoxClass),
44 (GtkClassInitFunc) gtk_hbutton_box_class_init,
45 (GtkObjectInitFunc) gtk_hbutton_box_init,
49 hbutton_box_type = gtk_type_unique (gtk_button_box_get_type (), &hbutton_box_info);
52 return hbutton_box_type;
56 gtk_hbutton_box_class_init (GtkHButtonBoxClass *class)
58 GtkWidgetClass *widget_class;
60 widget_class = (GtkWidgetClass*) class;
62 widget_class->size_request = gtk_hbutton_box_size_request;
63 widget_class->size_allocate = gtk_hbutton_box_size_allocate;
67 gtk_hbutton_box_init (GtkHButtonBox *hbutton_box)
69 /* button_box_init has done everything allready */
73 gtk_hbutton_box_new ()
75 GtkHButtonBox *hbutton_box;
77 hbutton_box = gtk_type_new (gtk_hbutton_box_get_type ());
79 return GTK_WIDGET (hbutton_box);
83 /* set default value for spacing */
85 void gtk_hbutton_box_set_spacing_default (gint spacing)
87 default_spacing = spacing;
91 /* set default value for layout style */
93 void gtk_hbutton_box_set_layout_default (gint layout)
95 default_layout_style = layout;
98 /* get default value for spacing */
100 gint gtk_hbutton_box_get_spacing_default (void)
102 return default_spacing;
106 /* get default value for layout style */
108 gint gtk_hbutton_box_get_layout_default (void)
110 return default_layout_style;
116 gtk_hbutton_box_size_request (GtkWidget *widget,
117 GtkRequisition *requisition)
127 g_return_if_fail (widget != NULL);
128 g_return_if_fail (GTK_IS_HBUTTON_BOX (widget));
129 g_return_if_fail (requisition != NULL);
131 box = GTK_BOX (widget);
132 bbox = GTK_BUTTON_BOX (widget);
134 spacing = bbox->spacing != GTK_BUTTONBOX_DEFAULT
135 ? bbox->spacing : default_spacing;
136 layout = bbox->layout_style != GTK_BUTTONBOX_DEFAULT
137 ? bbox->layout_style : default_layout_style;
139 gtk_button_box_child_requisition (widget,
144 if (nvis_children == 0)
146 requisition->width = 0;
147 requisition->height = 0;
153 case GTK_BUTTONBOX_SPREAD:
155 nvis_children*child_width + ((nvis_children+1)*spacing);
157 case GTK_BUTTONBOX_EDGE:
158 case GTK_BUTTONBOX_START:
159 case GTK_BUTTONBOX_END:
160 requisition->width = nvis_children*child_width + ((nvis_children-1)*spacing);
163 g_assert_not_reached();
167 requisition->height = child_height;
170 requisition->width += GTK_CONTAINER (box)->border_width * 2;
171 requisition->height += GTK_CONTAINER (box)->border_width * 2;
177 gtk_hbutton_box_size_allocate (GtkWidget *widget,
178 GtkAllocation *allocation)
184 GtkAllocation child_allocation;
192 gint childspacing = 0;
196 g_return_if_fail (widget != NULL);
197 g_return_if_fail (GTK_IS_HBUTTON_BOX (widget));
198 g_return_if_fail (allocation != NULL);
200 box = GTK_BUTTON_BOX (widget);
201 hbox = GTK_HBUTTON_BOX (widget);
202 spacing = box->spacing != GTK_BUTTONBOX_DEFAULT
203 ? box->spacing : default_spacing;
204 layout = box->layout_style != GTK_BUTTONBOX_DEFAULT
205 ? box->layout_style : default_layout_style;
206 gtk_button_box_child_requisition (widget,
210 widget->allocation = *allocation;
211 width = allocation->width - GTK_CONTAINER (box)->border_width*2;
214 case GTK_BUTTONBOX_SPREAD:
215 childspacing = (width - (nvis_children*child_width)) / (nvis_children+1);
216 x = allocation->x + GTK_CONTAINER (box)->border_width + childspacing;
218 case GTK_BUTTONBOX_EDGE:
219 if (nvis_children >= 2)
222 (width - (nvis_children*child_width)) / (nvis_children-1);
223 x = allocation->x + GTK_CONTAINER (box)->border_width;
227 /* one or zero children, just center */
228 childspacing = width;
229 x = allocation->x + (allocation->width - child_width) / 2;
232 case GTK_BUTTONBOX_START:
233 childspacing = spacing;
234 x = allocation->x + GTK_CONTAINER (box)->border_width;
236 case GTK_BUTTONBOX_END:
237 childspacing = spacing;
238 x = allocation->x + allocation->width - child_width * nvis_children
239 - spacing *(nvis_children-1)
240 - GTK_CONTAINER (box)->border_width;
243 g_assert_not_reached();
248 y = allocation->y + (allocation->height - child_height) / 2;
249 childspace = child_width + childspacing;
251 children = GTK_BOX (box)->children;
255 child = children->data;
256 children = children->next;
258 if (GTK_WIDGET_VISIBLE (child->widget))
260 child_allocation.width = child_width;
261 child_allocation.height = child_height;
262 child_allocation.x = x;
263 child_allocation.y = y;
264 gtk_widget_size_allocate (child->widget, &child_allocation);