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_hbutton_box_class_init (GtkHButtonBoxClass *klass);
34 static void gtk_hbutton_box_init (GtkHButtonBox *box);
35 static void gtk_hbutton_box_size_request (GtkWidget *widget,
36 GtkRequisition *requisition);
37 static void gtk_hbutton_box_size_allocate (GtkWidget *widget,
38 GtkAllocation *allocation);
40 static gint default_spacing = 30;
41 static gint default_layout_style = GTK_BUTTONBOX_EDGE;
44 gtk_hbutton_box_get_type (void)
46 static GType hbutton_box_type = 0;
48 if (!hbutton_box_type)
50 static const GTypeInfo hbutton_box_info =
52 sizeof (GtkHButtonBoxClass),
54 NULL, /* base_finalize */
55 (GClassInitFunc) gtk_hbutton_box_class_init,
56 NULL, /* class_finalize */
57 NULL, /* class_data */
58 sizeof (GtkHButtonBox),
60 (GInstanceInitFunc) gtk_hbutton_box_init,
64 g_type_register_static (GTK_TYPE_BUTTON_BOX, I_("GtkHButtonBox"),
65 &hbutton_box_info, 0);
68 return hbutton_box_type;
72 gtk_hbutton_box_class_init (GtkHButtonBoxClass *class)
74 GtkWidgetClass *widget_class;
76 widget_class = (GtkWidgetClass*) class;
78 widget_class->size_request = gtk_hbutton_box_size_request;
79 widget_class->size_allocate = gtk_hbutton_box_size_allocate;
83 gtk_hbutton_box_init (GtkHButtonBox *hbutton_box)
85 /* button_box_init has done everything allready */
89 gtk_hbutton_box_new (void)
91 GtkHButtonBox *hbutton_box;
93 hbutton_box = g_object_new (GTK_TYPE_HBUTTON_BOX, NULL);
95 return GTK_WIDGET (hbutton_box);
99 /* set default value for spacing */
102 gtk_hbutton_box_set_spacing_default (gint spacing)
104 default_spacing = spacing;
108 /* set default value for layout style */
111 gtk_hbutton_box_set_layout_default (GtkButtonBoxStyle layout)
113 g_return_if_fail (layout >= GTK_BUTTONBOX_DEFAULT_STYLE &&
114 layout <= GTK_BUTTONBOX_END);
116 default_layout_style = layout;
119 /* get default value for spacing */
122 gtk_hbutton_box_get_spacing_default (void)
124 return default_spacing;
128 /* get default value for layout style */
131 gtk_hbutton_box_get_layout_default (void)
133 return default_layout_style;
139 gtk_hbutton_box_size_request (GtkWidget *widget,
140 GtkRequisition *requisition)
148 GtkButtonBoxStyle layout;
150 box = GTK_BOX (widget);
151 bbox = GTK_BUTTON_BOX (widget);
153 spacing = box->spacing;
154 layout = bbox->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
155 ? bbox->layout_style : default_layout_style;
157 _gtk_button_box_child_requisition (widget,
163 if (nvis_children == 0)
165 requisition->width = 0;
166 requisition->height = 0;
172 case GTK_BUTTONBOX_SPREAD:
174 nvis_children*child_width + ((nvis_children+1)*spacing);
176 case GTK_BUTTONBOX_EDGE:
177 case GTK_BUTTONBOX_START:
178 case GTK_BUTTONBOX_END:
179 requisition->width = nvis_children*child_width + ((nvis_children-1)*spacing);
182 g_assert_not_reached();
186 requisition->height = child_height;
189 requisition->width += GTK_CONTAINER (box)->border_width * 2;
190 requisition->height += GTK_CONTAINER (box)->border_width * 2;
196 gtk_hbutton_box_size_allocate (GtkWidget *widget,
197 GtkAllocation *allocation)
203 GtkAllocation child_allocation;
209 gint secondary_x = 0;
213 gint childspacing = 0;
214 GtkButtonBoxStyle layout;
217 base_box = GTK_BOX (widget);
218 box = GTK_BUTTON_BOX (widget);
219 spacing = base_box->spacing;
220 layout = box->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
221 ? box->layout_style : default_layout_style;
222 _gtk_button_box_child_requisition (widget,
227 widget->allocation = *allocation;
228 width = allocation->width - GTK_CONTAINER (box)->border_width*2;
231 case GTK_BUTTONBOX_SPREAD:
232 childspacing = (width - (nvis_children * child_width)) / (nvis_children + 1);
233 x = allocation->x + GTK_CONTAINER (box)->border_width + childspacing;
234 secondary_x = x + ((nvis_children - n_secondaries) * (child_width + childspacing));
236 case GTK_BUTTONBOX_EDGE:
237 if (nvis_children >= 2)
239 childspacing = (width - (nvis_children * child_width)) / (nvis_children - 1);
240 x = allocation->x + GTK_CONTAINER (box)->border_width;
241 secondary_x = x + ((nvis_children - n_secondaries) * (child_width + childspacing));
245 /* one or zero children, just center */
246 childspacing = width;
247 x = secondary_x = allocation->x + (allocation->width - child_width) / 2;
250 case GTK_BUTTONBOX_START:
251 childspacing = spacing;
252 x = allocation->x + GTK_CONTAINER (box)->border_width;
253 secondary_x = allocation->x + allocation->width
254 - child_width * n_secondaries
255 - spacing * (n_secondaries - 1)
256 - GTK_CONTAINER (box)->border_width;
258 case GTK_BUTTONBOX_END:
259 childspacing = spacing;
260 x = allocation->x + allocation->width
261 - child_width * (nvis_children - n_secondaries)
262 - spacing * (nvis_children - n_secondaries - 1)
263 - GTK_CONTAINER (box)->border_width;
264 secondary_x = allocation->x + GTK_CONTAINER (box)->border_width;
267 g_assert_not_reached();
272 y = allocation->y + (allocation->height - child_height) / 2;
273 childspace = child_width + childspacing;
275 children = GTK_BOX (box)->children;
279 child = children->data;
280 children = children->next;
282 if (GTK_WIDGET_VISIBLE (child->widget))
284 child_allocation.width = child_width;
285 child_allocation.height = child_height;
286 child_allocation.y = y;
288 if (child->is_secondary)
290 child_allocation.x = secondary_x;
291 secondary_x += childspace;
295 child_allocation.x = x;
299 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
300 child_allocation.x = (allocation->x + allocation->width) - (child_allocation.x + child_width - allocation->x);
302 gtk_widget_size_allocate (child->widget, &child_allocation);
307 #define __GTK_HBUTTON_BOX_C__
308 #include "gtkaliasdef.c"