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/.
42 static void gtk_button_box_class_init (GtkButtonBoxClass *klass);
43 static void gtk_button_box_init (GtkButtonBox *box);
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
69 gtk_button_box_get_type (void)
71 static GType button_box_type = 0;
75 static const GTypeInfo button_box_info =
77 sizeof (GtkButtonBoxClass),
79 NULL, /* base_finalize */
80 (GClassInitFunc) gtk_button_box_class_init,
81 NULL, /* class_finalize */
82 NULL, /* class_data */
83 sizeof (GtkButtonBox),
85 (GInstanceInitFunc) gtk_button_box_init,
86 NULL, /* value_table */
90 g_type_register_static (GTK_TYPE_BOX, "GtkButtonBox",
91 &button_box_info, G_TYPE_FLAG_ABSTRACT);
94 return button_box_type;
98 gtk_button_box_class_init (GtkButtonBoxClass *class)
100 GtkWidgetClass *widget_class;
101 GObjectClass *gobject_class;
102 GtkContainerClass *container_class;
104 gobject_class = G_OBJECT_CLASS (class);
105 widget_class = (GtkWidgetClass*) class;
106 container_class = (GtkContainerClass*) class;
108 gobject_class->set_property = gtk_button_box_set_property;
109 gobject_class->get_property = gtk_button_box_get_property;
111 container_class->set_child_property = gtk_button_box_set_child_property;
112 container_class->get_child_property = gtk_button_box_get_child_property;
114 /* FIXME we need to override the "spacing" property on GtkBox once
115 * libgobject allows that.
118 gtk_widget_class_install_style_property (widget_class,
119 g_param_spec_int ("child_min_width",
120 P_("Minimum child width"),
121 P_("Minimum width of buttons inside the box"),
124 DEFAULT_CHILD_MIN_WIDTH,
127 gtk_widget_class_install_style_property (widget_class,
128 g_param_spec_int ("child_min_height",
129 P_("Minimum child height"),
130 P_("Minimum height of buttons inside the box"),
133 DEFAULT_CHILD_MIN_HEIGHT,
136 gtk_widget_class_install_style_property (widget_class,
137 g_param_spec_int ("child_internal_pad_x",
138 P_("Child internal width padding"),
139 P_("Amount to increase child's size on either side"),
142 DEFAULT_CHILD_IPAD_X,
145 gtk_widget_class_install_style_property (widget_class,
146 g_param_spec_int ("child_internal_pad_y",
147 P_("Child internal height padding"),
148 P_("Amount to increase child's size on the top and bottom"),
151 DEFAULT_CHILD_IPAD_Y,
153 g_object_class_install_property (gobject_class,
155 g_param_spec_enum ("layout_style",
157 P_("How to layout the buttons in the box. Possible values are default, spread, edge, start and end"),
158 GTK_TYPE_BUTTON_BOX_STYLE,
159 GTK_BUTTONBOX_DEFAULT_STYLE,
162 gtk_container_class_install_child_property (container_class,
163 CHILD_PROP_SECONDARY,
164 g_param_spec_boolean ("secondary",
166 P_("If TRUE, the child appears in a secondary group of children, suitable for, e.g., help buttons"),
172 gtk_button_box_init (GtkButtonBox *button_box)
174 GTK_BOX (button_box)->spacing = 0;
175 button_box->child_min_width = GTK_BUTTONBOX_DEFAULT;
176 button_box->child_min_height = GTK_BUTTONBOX_DEFAULT;
177 button_box->child_ipad_x = GTK_BUTTONBOX_DEFAULT;
178 button_box->child_ipad_y = GTK_BUTTONBOX_DEFAULT;
179 button_box->layout_style = GTK_BUTTONBOX_DEFAULT_STYLE;
183 gtk_button_box_set_property (GObject *object,
190 case PROP_LAYOUT_STYLE:
191 gtk_button_box_set_layout (GTK_BUTTON_BOX (object),
192 g_value_get_enum (value));
195 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
201 gtk_button_box_get_property (GObject *object,
208 case PROP_LAYOUT_STYLE:
209 g_value_set_enum (value, GTK_BUTTON_BOX (object)->layout_style);
212 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
218 gtk_button_box_set_child_property (GtkContainer *container,
226 case CHILD_PROP_SECONDARY:
227 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (container), child,
228 g_value_get_boolean (value));
231 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
237 gtk_button_box_get_child_property (GtkContainer *container,
245 case CHILD_PROP_SECONDARY:
246 g_value_set_boolean (value,
247 gtk_button_box_get_child_secondary (GTK_BUTTON_BOX (container),
251 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
256 /* set per widget values for spacing, child size and child internal padding */
259 gtk_button_box_set_child_size (GtkButtonBox *widget,
260 gint width, gint height)
262 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
264 widget->child_min_width = width;
265 widget->child_min_height = height;
269 gtk_button_box_set_child_ipadding (GtkButtonBox *widget,
270 gint ipad_x, gint ipad_y)
272 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
274 widget->child_ipad_x = ipad_x;
275 widget->child_ipad_y = ipad_y;
279 gtk_button_box_set_layout (GtkButtonBox *widget,
280 GtkButtonBoxStyle layout_style)
282 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
283 g_return_if_fail (layout_style >= GTK_BUTTONBOX_DEFAULT_STYLE &&
284 layout_style <= GTK_BUTTONBOX_END);
286 if (widget->layout_style != layout_style)
288 widget->layout_style = layout_style;
289 g_object_notify (G_OBJECT (widget), "layout_style");
290 gtk_widget_queue_resize (GTK_WIDGET (widget));
295 /* get per widget values for spacing, child size and child internal padding */
298 gtk_button_box_get_child_size (GtkButtonBox *widget,
299 gint *width, gint *height)
301 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
302 g_return_if_fail (width != NULL);
303 g_return_if_fail (height != NULL);
305 *width = widget->child_min_width;
306 *height = widget->child_min_height;
310 gtk_button_box_get_child_ipadding (GtkButtonBox *widget,
311 gint* ipad_x, gint *ipad_y)
313 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
314 g_return_if_fail (ipad_x != NULL);
315 g_return_if_fail (ipad_y != NULL);
317 *ipad_x = widget->child_ipad_x;
318 *ipad_y = widget->child_ipad_y;
322 gtk_button_box_get_layout (GtkButtonBox *widget)
324 g_return_val_if_fail (GTK_IS_BUTTON_BOX (widget), GTK_BUTTONBOX_SPREAD);
326 return widget->layout_style;
330 * gtk_button_box_get_child_secondary:
331 * @widget: a #GtkButtonBox
332 * @child: a child of @widget
334 * Returns whether @child should appear in a secondary group of children.
336 * Return value: whether @child should appear in a secondary group of children.
341 gtk_button_box_get_child_secondary (GtkButtonBox *widget,
345 GtkBoxChild *child_info;
347 g_return_val_if_fail (GTK_IS_BUTTON_BOX (widget), FALSE);
348 g_return_val_if_fail (GTK_IS_WIDGET (child), FALSE);
351 list = GTK_BOX (widget)->children;
354 child_info = list->data;
355 if (child_info->widget == child)
361 g_return_val_if_fail (list != NULL, FALSE);
363 return child_info->is_secondary;
367 * gtk_button_box_set_child_secondary
368 * @widget: a #GtkButtonBox
369 * @child: a child of @widget
370 * @is_secondary: if %TRUE, the @child appears in a secondary group of the
373 * Sets whether @child should appear in a secondary group of children.
374 * A typical use of a secondary child is the help button in a dialog.
376 * This group appears after the other children if the style
377 * is %GTK_BUTTONBOX_START, %GTK_BUTTONBOX_SPREAD or
378 * %GTK_BUTTONBOX_EDGE, and before the the other children if the style
379 * is %GTK_BUTTONBOX_END. For horizontal button boxes, the definition
380 * of before/after depends on direction of the widget (see
381 * gtk_widget_set_direction()). If the style is %GTK_BUTTONBOX_START
382 * or %GTK_BUTTONBOX_END, then the secondary children are aligned at
383 * the other end of the button box from the main children. For the
384 * other styles, they appear immediately next to the main children.
387 gtk_button_box_set_child_secondary (GtkButtonBox *widget,
389 gboolean is_secondary)
393 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
394 g_return_if_fail (GTK_IS_WIDGET (child));
395 g_return_if_fail (child->parent == GTK_WIDGET (widget));
397 list = GTK_BOX (widget)->children;
400 GtkBoxChild *child_info = list->data;
401 if (child_info->widget == child)
403 child_info->is_secondary = is_secondary;
410 gtk_widget_child_notify (child, "secondary");
412 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (child))
413 gtk_widget_queue_resize (child);
416 /* Ask children how much space they require and round up
417 to match minimum size and internal padding.
418 Returns the size each single child should have. */
420 _gtk_button_box_child_requisition (GtkWidget *widget,
422 int *nvis_secondaries,
433 GtkRequisition child_requisition;
441 gint child_min_width;
442 gint child_min_height;
446 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
448 bbox = GTK_BUTTON_BOX (widget);
450 gtk_widget_style_get (widget,
455 "child_internal_pad_x",
457 "child_internal_pad_y",
458 &ipad_y_default, NULL);
460 child_min_width = bbox->child_min_width != GTK_BUTTONBOX_DEFAULT
461 ? bbox->child_min_width : width_default;
462 child_min_height = bbox->child_min_height !=GTK_BUTTONBOX_DEFAULT
463 ? bbox->child_min_height : height_default;
464 ipad_x = bbox->child_ipad_x != GTK_BUTTONBOX_DEFAULT
465 ? bbox->child_ipad_x : ipad_x_default;
466 ipad_y = bbox->child_ipad_y != GTK_BUTTONBOX_DEFAULT
467 ? bbox->child_ipad_y : ipad_y_default;
471 children = GTK_BOX(bbox)->children;
472 needed_width = child_min_width;
473 needed_height = child_min_height;
479 child = children->data;
480 children = children->next;
482 if (GTK_WIDGET_VISIBLE (child->widget))
485 gtk_widget_size_request (child->widget, &child_requisition);
487 if (child_requisition.width + ipad_w > needed_width)
488 needed_width = child_requisition.width + ipad_w;
489 if (child_requisition.height + ipad_h > needed_height)
490 needed_height = child_requisition.height + ipad_h;
491 if (child->is_secondary)
497 *nvis_children = nchildren;
498 if (nvis_secondaries)
499 *nvis_secondaries = nsecondaries;
501 *width = needed_width;
503 *height = needed_height;