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"
44 static void gtk_button_box_set_property (GObject *object,
48 static void gtk_button_box_get_property (GObject *object,
52 static void gtk_button_box_set_child_property (GtkContainer *container,
57 static void gtk_button_box_get_child_property (GtkContainer *container,
63 #define DEFAULT_CHILD_MIN_WIDTH 85
64 #define DEFAULT_CHILD_MIN_HEIGHT 27
65 #define DEFAULT_CHILD_IPAD_X 4
66 #define DEFAULT_CHILD_IPAD_Y 0
68 G_DEFINE_ABSTRACT_TYPE (GtkButtonBox, gtk_button_box, GTK_TYPE_BOX)
71 gtk_button_box_class_init (GtkButtonBoxClass *class)
73 GtkWidgetClass *widget_class;
74 GObjectClass *gobject_class;
75 GtkContainerClass *container_class;
77 gobject_class = G_OBJECT_CLASS (class);
78 widget_class = (GtkWidgetClass*) class;
79 container_class = (GtkContainerClass*) class;
81 gobject_class->set_property = gtk_button_box_set_property;
82 gobject_class->get_property = gtk_button_box_get_property;
84 container_class->set_child_property = gtk_button_box_set_child_property;
85 container_class->get_child_property = gtk_button_box_get_child_property;
87 /* FIXME we need to override the "spacing" property on GtkBox once
88 * libgobject allows that.
90 gtk_widget_class_install_style_property (widget_class,
91 g_param_spec_int ("child-min-width",
92 P_("Minimum child width"),
93 P_("Minimum width of buttons inside the box"),
96 DEFAULT_CHILD_MIN_WIDTH,
99 gtk_widget_class_install_style_property (widget_class,
100 g_param_spec_int ("child-min-height",
101 P_("Minimum child height"),
102 P_("Minimum height of buttons inside the box"),
105 DEFAULT_CHILD_MIN_HEIGHT,
106 GTK_PARAM_READABLE));
108 gtk_widget_class_install_style_property (widget_class,
109 g_param_spec_int ("child-internal-pad-x",
110 P_("Child internal width padding"),
111 P_("Amount to increase child's size on either side"),
114 DEFAULT_CHILD_IPAD_X,
115 GTK_PARAM_READABLE));
117 gtk_widget_class_install_style_property (widget_class,
118 g_param_spec_int ("child-internal-pad-y",
119 P_("Child internal height padding"),
120 P_("Amount to increase child's size on the top and bottom"),
123 DEFAULT_CHILD_IPAD_Y,
124 GTK_PARAM_READABLE));
125 g_object_class_install_property (gobject_class,
127 g_param_spec_enum ("layout-style",
129 P_("How to layout the buttons in the box. Possible values are default, spread, edge, start and end"),
130 GTK_TYPE_BUTTON_BOX_STYLE,
131 GTK_BUTTONBOX_DEFAULT_STYLE,
132 GTK_PARAM_READWRITE));
134 gtk_container_class_install_child_property (container_class,
135 CHILD_PROP_SECONDARY,
136 g_param_spec_boolean ("secondary",
138 P_("If TRUE, the child appears in a secondary group of children, suitable for, e.g., help buttons"),
140 GTK_PARAM_READWRITE));
144 gtk_button_box_init (GtkButtonBox *button_box)
146 GTK_BOX (button_box)->spacing = 0;
147 button_box->child_min_width = GTK_BUTTONBOX_DEFAULT;
148 button_box->child_min_height = GTK_BUTTONBOX_DEFAULT;
149 button_box->child_ipad_x = GTK_BUTTONBOX_DEFAULT;
150 button_box->child_ipad_y = GTK_BUTTONBOX_DEFAULT;
151 button_box->layout_style = GTK_BUTTONBOX_DEFAULT_STYLE;
155 gtk_button_box_set_property (GObject *object,
162 case PROP_LAYOUT_STYLE:
163 gtk_button_box_set_layout (GTK_BUTTON_BOX (object),
164 g_value_get_enum (value));
167 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
173 gtk_button_box_get_property (GObject *object,
180 case PROP_LAYOUT_STYLE:
181 g_value_set_enum (value, GTK_BUTTON_BOX (object)->layout_style);
184 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
190 gtk_button_box_set_child_property (GtkContainer *container,
198 case CHILD_PROP_SECONDARY:
199 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (container), child,
200 g_value_get_boolean (value));
203 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
209 gtk_button_box_get_child_property (GtkContainer *container,
217 case CHILD_PROP_SECONDARY:
218 g_value_set_boolean (value,
219 gtk_button_box_get_child_secondary (GTK_BUTTON_BOX (container),
223 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
228 /* set per widget values for spacing, child size and child internal padding */
231 gtk_button_box_set_child_size (GtkButtonBox *widget,
232 gint width, gint height)
234 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
236 widget->child_min_width = width;
237 widget->child_min_height = height;
241 gtk_button_box_set_child_ipadding (GtkButtonBox *widget,
242 gint ipad_x, gint ipad_y)
244 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
246 widget->child_ipad_x = ipad_x;
247 widget->child_ipad_y = ipad_y;
251 gtk_button_box_set_layout (GtkButtonBox *widget,
252 GtkButtonBoxStyle layout_style)
254 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
255 g_return_if_fail (layout_style >= GTK_BUTTONBOX_DEFAULT_STYLE &&
256 layout_style <= GTK_BUTTONBOX_CENTER);
258 if (widget->layout_style != layout_style)
260 widget->layout_style = layout_style;
261 g_object_notify (G_OBJECT (widget), "layout-style");
262 gtk_widget_queue_resize (GTK_WIDGET (widget));
267 /* get per widget values for spacing, child size and child internal padding */
270 gtk_button_box_get_child_size (GtkButtonBox *widget,
271 gint *width, gint *height)
273 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
274 g_return_if_fail (width != NULL);
275 g_return_if_fail (height != NULL);
277 *width = widget->child_min_width;
278 *height = widget->child_min_height;
282 gtk_button_box_get_child_ipadding (GtkButtonBox *widget,
283 gint* ipad_x, gint *ipad_y)
285 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
286 g_return_if_fail (ipad_x != NULL);
287 g_return_if_fail (ipad_y != NULL);
289 *ipad_x = widget->child_ipad_x;
290 *ipad_y = widget->child_ipad_y;
294 gtk_button_box_get_layout (GtkButtonBox *widget)
296 g_return_val_if_fail (GTK_IS_BUTTON_BOX (widget), GTK_BUTTONBOX_SPREAD);
298 return widget->layout_style;
302 * gtk_button_box_get_child_secondary:
303 * @widget: a #GtkButtonBox
304 * @child: a child of @widget
306 * Returns whether @child should appear in a secondary group of children.
308 * Return value: whether @child should appear in a secondary group of children.
313 gtk_button_box_get_child_secondary (GtkButtonBox *widget,
317 GtkBoxChild *child_info;
319 g_return_val_if_fail (GTK_IS_BUTTON_BOX (widget), FALSE);
320 g_return_val_if_fail (GTK_IS_WIDGET (child), FALSE);
323 list = GTK_BOX (widget)->children;
326 child_info = list->data;
327 if (child_info->widget == child)
333 g_return_val_if_fail (list != NULL, FALSE);
335 return child_info->is_secondary;
339 * gtk_button_box_set_child_secondary
340 * @widget: a #GtkButtonBox
341 * @child: a child of @widget
342 * @is_secondary: if %TRUE, the @child appears in a secondary group of the
345 * Sets whether @child should appear in a secondary group of children.
346 * A typical use of a secondary child is the help button in a dialog.
348 * This group appears after the other children if the style
349 * is %GTK_BUTTONBOX_START, %GTK_BUTTONBOX_SPREAD or
350 * %GTK_BUTTONBOX_EDGE, and before the other children if the style
351 * is %GTK_BUTTONBOX_END. For horizontal button boxes, the definition
352 * of before/after depends on direction of the widget (see
353 * gtk_widget_set_direction()). If the style is %GTK_BUTTONBOX_START
354 * or %GTK_BUTTONBOX_END, then the secondary children are aligned at
355 * the other end of the button box from the main children. For the
356 * other styles, they appear immediately next to the main children.
359 gtk_button_box_set_child_secondary (GtkButtonBox *widget,
361 gboolean is_secondary)
365 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
366 g_return_if_fail (GTK_IS_WIDGET (child));
367 g_return_if_fail (child->parent == GTK_WIDGET (widget));
369 list = GTK_BOX (widget)->children;
372 GtkBoxChild *child_info = list->data;
373 if (child_info->widget == child)
375 child_info->is_secondary = is_secondary;
382 gtk_widget_child_notify (child, "secondary");
384 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (child))
385 gtk_widget_queue_resize (child);
388 /* Ask children how much space they require and round up
389 to match minimum size and internal padding.
390 Returns the size each single child should have. */
392 _gtk_button_box_child_requisition (GtkWidget *widget,
394 int *nvis_secondaries,
405 GtkRequisition child_requisition;
413 gint child_min_width;
414 gint child_min_height;
418 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
420 bbox = GTK_BUTTON_BOX (widget);
422 gtk_widget_style_get (widget,
423 "child-min-width", &width_default,
424 "child-min-height", &height_default,
425 "child-internal-pad-x", &ipad_x_default,
426 "child-internal-pad-y", &ipad_y_default,
429 child_min_width = bbox->child_min_width != GTK_BUTTONBOX_DEFAULT
430 ? bbox->child_min_width : width_default;
431 child_min_height = bbox->child_min_height !=GTK_BUTTONBOX_DEFAULT
432 ? bbox->child_min_height : height_default;
433 ipad_x = bbox->child_ipad_x != GTK_BUTTONBOX_DEFAULT
434 ? bbox->child_ipad_x : ipad_x_default;
435 ipad_y = bbox->child_ipad_y != GTK_BUTTONBOX_DEFAULT
436 ? bbox->child_ipad_y : ipad_y_default;
440 children = GTK_BOX(bbox)->children;
441 needed_width = child_min_width;
442 needed_height = child_min_height;
448 child = children->data;
449 children = children->next;
451 if (GTK_WIDGET_VISIBLE (child->widget))
454 gtk_widget_size_request (child->widget, &child_requisition);
456 if (child_requisition.width + ipad_w > needed_width)
457 needed_width = child_requisition.width + ipad_w;
458 if (child_requisition.height + ipad_h > needed_height)
459 needed_height = child_requisition.height + ipad_h;
460 if (child->is_secondary)
466 *nvis_children = nchildren;
467 if (nvis_secondaries)
468 *nvis_secondaries = nsecondaries;
470 *width = needed_width;
472 *height = needed_height;
475 #define __GTK_BUTTON_BOX_C__
476 #include "gtkaliasdef.c"