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/.
41 static void gtk_button_box_class_init (GtkButtonBoxClass *klass);
42 static void gtk_button_box_init (GtkButtonBox *box);
43 static void gtk_button_box_set_property (GObject *object,
47 static void gtk_button_box_get_property (GObject *object,
51 static void gtk_button_box_set_child_property (GtkContainer *container,
56 static void gtk_button_box_get_child_property (GtkContainer *container,
62 #define DEFAULT_CHILD_MIN_WIDTH 85
63 #define DEFAULT_CHILD_MIN_HEIGHT 27
64 #define DEFAULT_CHILD_IPAD_X 4
65 #define DEFAULT_CHILD_IPAD_Y 0
68 gtk_button_box_get_type (void)
70 static GtkType button_box_type = 0;
74 static const GtkTypeInfo button_box_info =
77 sizeof (GtkButtonBox),
78 sizeof (GtkButtonBoxClass),
79 (GtkClassInitFunc) gtk_button_box_class_init,
80 (GtkObjectInitFunc) gtk_button_box_init,
81 /* reserved_1 */ NULL,
82 /* reserved_2 */ NULL,
83 (GtkClassInitFunc) NULL,
86 button_box_type = gtk_type_unique (gtk_box_get_type (), &button_box_info);
89 return button_box_type;
93 gtk_button_box_class_init (GtkButtonBoxClass *class)
95 GtkWidgetClass *widget_class;
96 GObjectClass *gobject_class;
97 GtkContainerClass *container_class;
99 gobject_class = G_OBJECT_CLASS (class);
100 widget_class = (GtkWidgetClass*) class;
101 container_class = (GtkContainerClass*) class;
103 gobject_class->set_property = gtk_button_box_set_property;
104 gobject_class->get_property = gtk_button_box_get_property;
106 container_class->set_child_property = gtk_button_box_set_child_property;
107 container_class->get_child_property = gtk_button_box_get_child_property;
109 /* FIXME we need to override the "spacing" property on GtkBox once
110 * libgobject allows that.
113 gtk_widget_class_install_style_property (widget_class,
114 g_param_spec_int ("child_min_width",
115 _("Minimum child width"),
116 _("Minimum width of buttons inside the box"),
119 DEFAULT_CHILD_MIN_WIDTH,
122 gtk_widget_class_install_style_property (widget_class,
123 g_param_spec_int ("child_min_height",
124 _("Minimum child height"),
125 _("Minimum height of buttons inside the box"),
128 DEFAULT_CHILD_MIN_HEIGHT,
131 gtk_widget_class_install_style_property (widget_class,
132 g_param_spec_int ("child_internal_pad_x",
133 _("Child internal width padding"),
134 _("Amount to increase child's size on either side"),
137 DEFAULT_CHILD_IPAD_X,
140 gtk_widget_class_install_style_property (widget_class,
141 g_param_spec_int ("child_internal_pad_y",
142 _("Child internal height padding"),
143 _("Amount to increase child's size on the top and bottom"),
146 DEFAULT_CHILD_IPAD_Y,
148 g_object_class_install_property (gobject_class,
150 g_param_spec_enum ("layout_style",
152 _("How to layout the buttons in the box. Possible values are default, spread, edge, start and end"),
153 GTK_TYPE_BUTTON_BOX_STYLE,
154 GTK_BUTTONBOX_DEFAULT_STYLE,
157 gtk_container_class_install_child_property (container_class,
158 CHILD_PROP_SECONDARY,
159 g_param_spec_boolean ("secondary",
161 _("If TRUE, the child appears in a secondary group of children, suitable for, e.g., help buttons."),
167 gtk_button_box_init (GtkButtonBox *button_box)
169 GTK_BOX (button_box)->spacing = 0;
170 button_box->child_min_width = GTK_BUTTONBOX_DEFAULT;
171 button_box->child_min_height = GTK_BUTTONBOX_DEFAULT;
172 button_box->child_ipad_x = GTK_BUTTONBOX_DEFAULT;
173 button_box->child_ipad_y = GTK_BUTTONBOX_DEFAULT;
174 button_box->layout_style = GTK_BUTTONBOX_DEFAULT_STYLE;
178 gtk_button_box_set_property (GObject *object,
185 case PROP_LAYOUT_STYLE:
186 gtk_button_box_set_layout (GTK_BUTTON_BOX (object),
187 g_value_get_enum (value));
190 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
196 gtk_button_box_get_property (GObject *object,
203 case PROP_LAYOUT_STYLE:
204 g_value_set_enum (value, GTK_BUTTON_BOX (object)->layout_style);
207 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
213 gtk_button_box_set_child_property (GtkContainer *container,
221 case CHILD_PROP_SECONDARY:
222 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (container), child,
223 g_value_get_boolean (value));
226 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
232 gtk_button_box_get_child_property (GtkContainer *container,
239 GtkBoxChild *child_info = NULL;
241 list = GTK_BOX (container)->children;
244 child_info = list->data;
245 if (child_info->widget == child)
251 g_assert (list != NULL);
255 case CHILD_PROP_SECONDARY:
256 g_value_set_boolean (value, child_info->is_secondary);
259 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
264 /* set per widget values for spacing, child size and child internal padding */
267 gtk_button_box_set_child_size (GtkButtonBox *widget,
268 gint width, gint height)
270 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
272 widget->child_min_width = width;
273 widget->child_min_height = height;
277 gtk_button_box_set_child_ipadding (GtkButtonBox *widget,
278 gint ipad_x, gint ipad_y)
280 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
282 widget->child_ipad_x = ipad_x;
283 widget->child_ipad_y = ipad_y;
287 gtk_button_box_set_layout (GtkButtonBox *widget,
288 GtkButtonBoxStyle layout_style)
290 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
291 g_return_if_fail (layout_style >= GTK_BUTTONBOX_DEFAULT_STYLE &&
292 layout_style <= GTK_BUTTONBOX_END);
294 if (widget->layout_style != layout_style)
296 widget->layout_style = layout_style;
297 g_object_notify (G_OBJECT (widget), "layout_style");
298 gtk_widget_queue_resize (GTK_WIDGET (widget));
303 /* get per widget values for spacing, child size and child internal padding */
306 gtk_button_box_get_child_size (GtkButtonBox *widget,
307 gint *width, gint *height)
309 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
310 g_return_if_fail (width != NULL);
311 g_return_if_fail (height != NULL);
313 *width = widget->child_min_width;
314 *height = widget->child_min_height;
318 gtk_button_box_get_child_ipadding (GtkButtonBox *widget,
319 gint* ipad_x, gint *ipad_y)
321 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
322 g_return_if_fail (ipad_x != NULL);
323 g_return_if_fail (ipad_y != NULL);
325 *ipad_x = widget->child_ipad_x;
326 *ipad_y = widget->child_ipad_y;
330 gtk_button_box_get_layout (GtkButtonBox *widget)
332 g_return_val_if_fail (GTK_IS_BUTTON_BOX (widget), GTK_BUTTONBOX_SPREAD);
334 return widget->layout_style;
338 * gtk_button_box_set_child_secondary
339 * @widget: a #GtkButtonBox
340 * @child: a child of @widget
341 * @is_secondary: if %TRUE, the @child appears in a secondary group of the
344 * Sets whether @child should appear in a secondary group of children.
345 * A typical use of a secondary child is the help button in a dialog.
347 * This group appears after the other children if the style
348 * is %GTK_BUTTONBOX_START, %GTK_BUTTONBOX_SPREAD or
349 * %GTK_BUTTONBOX_EDGE, and before the the other children if the style
350 * is %GTK_BUTTONBOX_END. For horizontal button boxes, the definition
351 * of before/after depends on direction of the widget (see
352 * gtk_widget_set_direction()). If the style is %GTK_BUTTONBOX_START
353 * or %GTK_BUTTONBOX_END, then the secondary children are aligned at
354 * the other end of the button box from the main children. For the
355 * other styles, they appear immediately next to the main children.
358 gtk_button_box_set_child_secondary (GtkButtonBox *widget,
360 gboolean is_secondary)
364 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
365 g_return_if_fail (GTK_IS_WIDGET (child));
366 g_return_if_fail (child->parent == GTK_WIDGET (widget));
368 list = GTK_BOX (widget)->children;
371 GtkBoxChild *child_info = list->data;
372 if (child_info->widget == child)
374 child_info->is_secondary = is_secondary;
381 gtk_widget_child_notify (child, "secondary");
383 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (child))
384 gtk_widget_queue_resize (child);
387 /* Ask children how much space they require and round up
388 to match minimum size and internal padding.
389 Returns the size each single child should have. */
391 _gtk_button_box_child_requisition (GtkWidget *widget,
393 int *nvis_secondaries,
404 GtkRequisition child_requisition;
412 gint child_min_width;
413 gint child_min_height;
417 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
419 bbox = GTK_BUTTON_BOX (widget);
421 gtk_widget_style_get (widget,
426 "child_internal_pad_x",
428 "child_internal_pad_y",
429 &ipad_y_default, NULL);
431 child_min_width = bbox->child_min_width != GTK_BUTTONBOX_DEFAULT
432 ? bbox->child_min_width : width_default;
433 child_min_height = bbox->child_min_height !=GTK_BUTTONBOX_DEFAULT
434 ? bbox->child_min_height : height_default;
435 ipad_x = bbox->child_ipad_x != GTK_BUTTONBOX_DEFAULT
436 ? bbox->child_ipad_x : ipad_x_default;
437 ipad_y = bbox->child_ipad_y != GTK_BUTTONBOX_DEFAULT
438 ? bbox->child_ipad_y : ipad_y_default;
442 children = GTK_BOX(bbox)->children;
443 needed_width = child_min_width;
444 needed_height = child_min_height;
450 child = children->data;
451 children = children->next;
453 if (GTK_WIDGET_VISIBLE (child->widget))
456 gtk_widget_size_request (child->widget, &child_requisition);
458 if (child_requisition.width + ipad_w > needed_width)
459 needed_width = child_requisition.width + ipad_w;
460 if (child_requisition.height + ipad_h > needed_height)
461 needed_height = child_requisition.height + ipad_h;
462 if (child->is_secondary)
468 *nvis_children = nchildren;
469 if (nvis_secondaries)
470 *nvis_secondaries = nsecondaries;
472 *width = needed_width;
474 *height = needed_height;