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/.
36 static void gtk_button_box_class_init (GtkButtonBoxClass *klass);
37 static void gtk_button_box_init (GtkButtonBox *box);
38 static void gtk_button_box_set_property (GObject *object,
42 static void gtk_button_box_get_property (GObject *object,
47 #define DEFAULT_CHILD_MIN_WIDTH 85
48 #define DEFAULT_CHILD_MIN_HEIGHT 27
49 #define DEFAULT_CHILD_IPAD_X 4
50 #define DEFAULT_CHILD_IPAD_Y 0
53 gtk_button_box_get_type (void)
55 static GtkType button_box_type = 0;
59 static const GtkTypeInfo button_box_info =
62 sizeof (GtkButtonBox),
63 sizeof (GtkButtonBoxClass),
64 (GtkClassInitFunc) gtk_button_box_class_init,
65 (GtkObjectInitFunc) gtk_button_box_init,
66 /* reserved_1 */ NULL,
67 /* reserved_2 */ NULL,
68 (GtkClassInitFunc) NULL,
71 button_box_type = gtk_type_unique (gtk_box_get_type (), &button_box_info);
74 return button_box_type;
78 gtk_button_box_class_init (GtkButtonBoxClass *class)
80 GtkWidgetClass *widget_class;
81 GObjectClass *gobject_class;
83 gobject_class = G_OBJECT_CLASS (class);
84 widget_class = (GtkWidgetClass*) class;
86 gobject_class->set_property = gtk_button_box_set_property;
87 gobject_class->get_property = gtk_button_box_get_property;
89 /* FIXME we need to override the "spacing" property on GtkBox once
90 * libgobject allows that.
93 gtk_widget_class_install_style_property (widget_class,
94 g_param_spec_int ("child_min_width",
95 _("Minimum child width"),
96 _("Minimum width of buttons inside the box"),
99 DEFAULT_CHILD_MIN_WIDTH,
102 gtk_widget_class_install_style_property (widget_class,
103 g_param_spec_int ("child_min_height",
104 _("Minimum child height"),
105 _("Minimum height of buttons inside the box"),
108 DEFAULT_CHILD_MIN_HEIGHT,
111 gtk_widget_class_install_style_property (widget_class,
112 g_param_spec_int ("child_internal_pad_x",
113 _("Child internal width padding"),
114 _("Amount to increase child's size on either side"),
117 DEFAULT_CHILD_IPAD_X,
120 gtk_widget_class_install_style_property (widget_class,
121 g_param_spec_int ("child_internal_pad_y",
122 _("Child internal height padding"),
123 _("Amount to increase child's size on the top and bottom"),
126 DEFAULT_CHILD_IPAD_Y,
128 g_object_class_install_property (gobject_class,
130 g_param_spec_enum ("layout_style",
132 _("How to layout the buttons in the box. Possible values are default, spread, edge, start and end"),
133 GTK_TYPE_BUTTON_BOX_STYLE,
134 GTK_BUTTONBOX_DEFAULT_STYLE,
139 gtk_button_box_init (GtkButtonBox *button_box)
141 GTK_BOX (button_box)->spacing = 0;
142 button_box->child_min_width = GTK_BUTTONBOX_DEFAULT;
143 button_box->child_min_height = GTK_BUTTONBOX_DEFAULT;
144 button_box->child_ipad_x = GTK_BUTTONBOX_DEFAULT;
145 button_box->child_ipad_y = GTK_BUTTONBOX_DEFAULT;
146 button_box->layout_style = GTK_BUTTONBOX_DEFAULT_STYLE;
150 gtk_button_box_set_property (GObject *object,
157 case PROP_LAYOUT_STYLE:
158 gtk_button_box_set_layout (GTK_BUTTON_BOX (object),
159 g_value_get_enum (value));
162 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
168 gtk_button_box_get_property (GObject *object,
175 case PROP_LAYOUT_STYLE:
176 g_value_set_enum (value, GTK_BUTTON_BOX (object)->layout_style);
179 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
186 /* set per widget values for spacing, child size and child internal padding */
188 void gtk_button_box_set_child_size (GtkButtonBox *widget, gint width, gint height)
190 widget->child_min_width = width;
191 widget->child_min_height = height;
194 void gtk_button_box_set_child_ipadding (GtkButtonBox *widget,
195 gint ipad_x, gint ipad_y)
197 widget->child_ipad_x = ipad_x;
198 widget->child_ipad_y = ipad_y;
201 void gtk_button_box_set_layout (GtkButtonBox *widget,
202 GtkButtonBoxStyle layout_style)
204 g_return_if_fail (layout_style >= GTK_BUTTONBOX_DEFAULT_STYLE &&
205 layout_style <= GTK_BUTTONBOX_END);
207 if (widget->layout_style != layout_style)
209 widget->layout_style = layout_style;
210 g_object_notify (G_OBJECT (widget), "layout_style");
211 gtk_widget_queue_resize (GTK_WIDGET (widget));
216 /* get per widget values for spacing, child size and child internal padding */
218 void gtk_button_box_get_child_size (GtkButtonBox *widget,
219 gint *width, gint *height)
221 *width = widget->child_min_width;
222 *height = widget->child_min_height;
225 void gtk_button_box_get_child_ipadding (GtkButtonBox *widget,
226 gint* ipad_x, gint *ipad_y)
228 *ipad_x = widget->child_ipad_x;
229 *ipad_y = widget->child_ipad_y;
232 GtkButtonBoxStyle gtk_button_box_get_layout (GtkButtonBox *widget)
234 return widget->layout_style;
239 /* Ask children how much space they require and round up
240 to match minimum size and internal padding.
241 Returns the size each single child should have. */
243 _gtk_button_box_child_requisition (GtkWidget *widget,
254 GtkRequisition child_requisition;
262 gint child_min_width;
263 gint child_min_height;
267 g_return_if_fail (widget != NULL);
268 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
270 bbox = GTK_BUTTON_BOX (widget);
272 gtk_widget_style_get (widget,
277 "child_internal_pad_x",
279 "child_internal_pad_y",
280 &ipad_y_default, NULL);
282 child_min_width = bbox->child_min_width != GTK_BUTTONBOX_DEFAULT
283 ? bbox->child_min_width : width_default;
284 child_min_height = bbox->child_min_height !=GTK_BUTTONBOX_DEFAULT
285 ? bbox->child_min_height : height_default;
286 ipad_x = bbox->child_ipad_x != GTK_BUTTONBOX_DEFAULT
287 ? bbox->child_ipad_x : ipad_x_default;
288 ipad_y = bbox->child_ipad_y != GTK_BUTTONBOX_DEFAULT
289 ? bbox->child_ipad_y : ipad_y_default;
292 children = GTK_BOX(bbox)->children;
293 needed_width = child_min_width;
294 needed_height = child_min_height;
300 child = children->data;
301 children = children->next;
303 if (GTK_WIDGET_VISIBLE (child->widget))
306 gtk_widget_size_request (child->widget, &child_requisition);
307 if (child_requisition.width + ipad_w > needed_width)
308 needed_width = child_requisition.width + ipad_w;
309 if (child_requisition.height + ipad_h > needed_height)
310 needed_height = child_requisition.height + ipad_h;
314 *nvis_children = nchildren;
315 *width = needed_width;
316 *height = needed_height;