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/.
29 #include "gtkprivate.h"
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
67 G_DEFINE_ABSTRACT_TYPE (GtkButtonBox, gtk_button_box, GTK_TYPE_BOX)
70 gtk_button_box_class_init (GtkButtonBoxClass *class)
72 GtkWidgetClass *widget_class;
73 GObjectClass *gobject_class;
74 GtkContainerClass *container_class;
76 gobject_class = G_OBJECT_CLASS (class);
77 widget_class = (GtkWidgetClass*) class;
78 container_class = (GtkContainerClass*) class;
80 gobject_class->set_property = gtk_button_box_set_property;
81 gobject_class->get_property = gtk_button_box_get_property;
83 container_class->set_child_property = gtk_button_box_set_child_property;
84 container_class->get_child_property = gtk_button_box_get_child_property;
86 /* FIXME we need to override the "spacing" property on GtkBox once
87 * libgobject allows that.
89 gtk_widget_class_install_style_property (widget_class,
90 g_param_spec_int ("child-min-width",
91 P_("Minimum child width"),
92 P_("Minimum width of buttons inside the box"),
95 DEFAULT_CHILD_MIN_WIDTH,
98 gtk_widget_class_install_style_property (widget_class,
99 g_param_spec_int ("child-min-height",
100 P_("Minimum child height"),
101 P_("Minimum height of buttons inside the box"),
104 DEFAULT_CHILD_MIN_HEIGHT,
105 GTK_PARAM_READABLE));
107 gtk_widget_class_install_style_property (widget_class,
108 g_param_spec_int ("child-internal-pad-x",
109 P_("Child internal width padding"),
110 P_("Amount to increase child's size on either side"),
113 DEFAULT_CHILD_IPAD_X,
114 GTK_PARAM_READABLE));
116 gtk_widget_class_install_style_property (widget_class,
117 g_param_spec_int ("child-internal-pad-y",
118 P_("Child internal height padding"),
119 P_("Amount to increase child's size on the top and bottom"),
122 DEFAULT_CHILD_IPAD_Y,
123 GTK_PARAM_READABLE));
124 g_object_class_install_property (gobject_class,
126 g_param_spec_enum ("layout-style",
128 P_("How to layout the buttons in the box. Possible values are default, spread, edge, start and end"),
129 GTK_TYPE_BUTTON_BOX_STYLE,
130 GTK_BUTTONBOX_DEFAULT_STYLE,
131 GTK_PARAM_READWRITE));
133 gtk_container_class_install_child_property (container_class,
134 CHILD_PROP_SECONDARY,
135 g_param_spec_boolean ("secondary",
137 P_("If TRUE, the child appears in a secondary group of children, suitable for, e.g., help buttons"),
139 GTK_PARAM_READWRITE));
143 gtk_button_box_init (GtkButtonBox *button_box)
145 GTK_BOX (button_box)->spacing = 0;
146 button_box->child_min_width = GTK_BUTTONBOX_DEFAULT;
147 button_box->child_min_height = GTK_BUTTONBOX_DEFAULT;
148 button_box->child_ipad_x = GTK_BUTTONBOX_DEFAULT;
149 button_box->child_ipad_y = GTK_BUTTONBOX_DEFAULT;
150 button_box->layout_style = GTK_BUTTONBOX_DEFAULT_STYLE;
154 gtk_button_box_set_property (GObject *object,
161 case PROP_LAYOUT_STYLE:
162 gtk_button_box_set_layout (GTK_BUTTON_BOX (object),
163 g_value_get_enum (value));
166 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
172 gtk_button_box_get_property (GObject *object,
179 case PROP_LAYOUT_STYLE:
180 g_value_set_enum (value, GTK_BUTTON_BOX (object)->layout_style);
183 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
189 gtk_button_box_set_child_property (GtkContainer *container,
197 case CHILD_PROP_SECONDARY:
198 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (container), child,
199 g_value_get_boolean (value));
202 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
208 gtk_button_box_get_child_property (GtkContainer *container,
216 case CHILD_PROP_SECONDARY:
217 g_value_set_boolean (value,
218 gtk_button_box_get_child_secondary (GTK_BUTTON_BOX (container),
222 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
227 /* set per widget values for spacing, child size and child internal padding */
230 gtk_button_box_set_child_size (GtkButtonBox *widget,
231 gint width, gint height)
233 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
235 widget->child_min_width = width;
236 widget->child_min_height = height;
240 gtk_button_box_set_child_ipadding (GtkButtonBox *widget,
241 gint ipad_x, gint ipad_y)
243 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
245 widget->child_ipad_x = ipad_x;
246 widget->child_ipad_y = ipad_y;
250 gtk_button_box_set_layout (GtkButtonBox *widget,
251 GtkButtonBoxStyle layout_style)
253 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
254 g_return_if_fail (layout_style >= GTK_BUTTONBOX_DEFAULT_STYLE &&
255 layout_style <= GTK_BUTTONBOX_CENTER);
257 if (widget->layout_style != layout_style)
259 widget->layout_style = layout_style;
260 g_object_notify (G_OBJECT (widget), "layout-style");
261 gtk_widget_queue_resize (GTK_WIDGET (widget));
266 /* get per widget values for spacing, child size and child internal padding */
269 gtk_button_box_get_child_size (GtkButtonBox *widget,
270 gint *width, gint *height)
272 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
273 g_return_if_fail (width != NULL);
274 g_return_if_fail (height != NULL);
276 *width = widget->child_min_width;
277 *height = widget->child_min_height;
281 gtk_button_box_get_child_ipadding (GtkButtonBox *widget,
282 gint* ipad_x, gint *ipad_y)
284 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
285 g_return_if_fail (ipad_x != NULL);
286 g_return_if_fail (ipad_y != NULL);
288 *ipad_x = widget->child_ipad_x;
289 *ipad_y = widget->child_ipad_y;
293 gtk_button_box_get_layout (GtkButtonBox *widget)
295 g_return_val_if_fail (GTK_IS_BUTTON_BOX (widget), GTK_BUTTONBOX_SPREAD);
297 return widget->layout_style;
301 * gtk_button_box_get_child_secondary:
302 * @widget: a #GtkButtonBox
303 * @child: a child of @widget
305 * Returns whether @child should appear in a secondary group of children.
307 * Return value: whether @child should appear in a secondary group of children.
312 gtk_button_box_get_child_secondary (GtkButtonBox *widget,
316 GtkBoxChild *child_info;
318 g_return_val_if_fail (GTK_IS_BUTTON_BOX (widget), FALSE);
319 g_return_val_if_fail (GTK_IS_WIDGET (child), FALSE);
322 list = GTK_BOX (widget)->children;
325 child_info = list->data;
326 if (child_info->widget == child)
332 g_return_val_if_fail (list != NULL, FALSE);
334 return child_info->is_secondary;
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 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,
422 "child-min-width", &width_default,
423 "child-min-height", &height_default,
424 "child-internal-pad-x", &ipad_x_default,
425 "child-internal-pad-y", &ipad_y_default,
428 child_min_width = bbox->child_min_width != GTK_BUTTONBOX_DEFAULT
429 ? bbox->child_min_width : width_default;
430 child_min_height = bbox->child_min_height !=GTK_BUTTONBOX_DEFAULT
431 ? bbox->child_min_height : height_default;
432 ipad_x = bbox->child_ipad_x != GTK_BUTTONBOX_DEFAULT
433 ? bbox->child_ipad_x : ipad_x_default;
434 ipad_y = bbox->child_ipad_y != GTK_BUTTONBOX_DEFAULT
435 ? bbox->child_ipad_y : ipad_y_default;
439 children = GTK_BOX(bbox)->children;
440 needed_width = child_min_width;
441 needed_height = child_min_height;
447 child = children->data;
448 children = children->next;
450 if (GTK_WIDGET_VISIBLE (child->widget))
453 gtk_widget_size_request (child->widget, &child_requisition);
455 if (child_requisition.width + ipad_w > needed_width)
456 needed_width = child_requisition.width + ipad_w;
457 if (child_requisition.height + ipad_h > needed_height)
458 needed_height = child_requisition.height + ipad_h;
459 if (child->is_secondary)
465 *nvis_children = nchildren;
466 if (nvis_secondaries)
467 *nvis_secondaries = nsecondaries;
469 *width = needed_width;
471 *height = needed_height;
474 #define __GTK_BUTTON_BOX_C__
475 #include "gtkaliasdef.c"