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/.
30 static void gtk_button_box_class_init (GtkButtonBoxClass *klass);
31 static void gtk_button_box_init (GtkButtonBox *box);
34 static gint default_child_min_width = 85;
35 static gint default_child_min_height = 27;
36 static gint default_child_ipad_x = 7;
37 static gint default_child_ipad_y = 0;
41 gtk_button_box_get_type (void)
43 static GtkType button_box_type = 0;
47 static const GtkTypeInfo button_box_info =
50 sizeof (GtkButtonBox),
51 sizeof (GtkButtonBoxClass),
52 (GtkClassInitFunc) gtk_button_box_class_init,
53 (GtkObjectInitFunc) gtk_button_box_init,
54 /* reserved_1 */ NULL,
55 /* reserved_2 */ NULL,
56 (GtkClassInitFunc) NULL,
59 button_box_type = gtk_type_unique (gtk_box_get_type (), &button_box_info);
62 return button_box_type;
66 gtk_button_box_class_init (GtkButtonBoxClass *class)
68 GtkWidgetClass *widget_class;
70 widget_class = (GtkWidgetClass*) class;
72 /* FIXME we need to override the "spacing" property on GtkBox once
73 * libgobject allows that.
78 gtk_button_box_init (GtkButtonBox *button_box)
80 GTK_BOX (button_box)->spacing = 0;
81 button_box->child_min_width = GTK_BUTTONBOX_DEFAULT;
82 button_box->child_min_height = GTK_BUTTONBOX_DEFAULT;
83 button_box->child_ipad_x = GTK_BUTTONBOX_DEFAULT;
84 button_box->child_ipad_y = GTK_BUTTONBOX_DEFAULT;
85 button_box->layout_style = GTK_BUTTONBOX_DEFAULT_STYLE;
88 /* set per widget values for spacing, child size and child internal padding */
90 void gtk_button_box_set_child_size (GtkButtonBox *widget, gint width, gint height)
92 widget->child_min_width = width;
93 widget->child_min_height = height;
96 void gtk_button_box_set_child_ipadding (GtkButtonBox *widget,
97 gint ipad_x, gint ipad_y)
99 widget->child_ipad_x = ipad_x;
100 widget->child_ipad_y = ipad_y;
103 void gtk_button_box_set_layout (GtkButtonBox *widget,
104 GtkButtonBoxStyle layout_style)
106 g_return_if_fail (layout_style >= GTK_BUTTONBOX_DEFAULT_STYLE &&
107 layout_style <= GTK_BUTTONBOX_END);
109 widget->layout_style = layout_style;
113 /* get per widget values for spacing, child size and child internal padding */
115 void gtk_button_box_get_child_size (GtkButtonBox *widget,
116 gint *width, gint *height)
118 *width = widget->child_min_width;
119 *height = widget->child_min_height;
122 void gtk_button_box_get_child_ipadding (GtkButtonBox *widget,
123 gint* ipad_x, gint *ipad_y)
125 *ipad_x = widget->child_ipad_x;
126 *ipad_y = widget->child_ipad_y;
129 GtkButtonBoxStyle gtk_button_box_get_layout (GtkButtonBox *widget)
131 return widget->layout_style;
136 /* Ask children how much space they require and round up
137 to match minimum size and internal padding.
138 Returns the size each single child should have. */
140 _gtk_button_box_child_requisition (GtkWidget *widget,
151 GtkRequisition child_requisition;
159 gint child_min_width;
160 gint child_min_height;
164 g_return_if_fail (widget != NULL);
165 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
167 bbox = GTK_BUTTON_BOX (widget);
169 width_default = default_child_min_width;
170 height_default = default_child_min_height;
171 ipad_x_default = default_child_ipad_x;
172 ipad_y_default = default_child_ipad_y;
174 child_min_width = bbox->child_min_width != GTK_BUTTONBOX_DEFAULT
175 ? bbox->child_min_width : width_default;
176 child_min_height = bbox->child_min_height !=GTK_BUTTONBOX_DEFAULT
177 ? bbox->child_min_height : height_default;
178 ipad_x = bbox->child_ipad_x != GTK_BUTTONBOX_DEFAULT
179 ? bbox->child_ipad_x : ipad_x_default;
180 ipad_y = bbox->child_ipad_y != GTK_BUTTONBOX_DEFAULT
181 ? bbox->child_ipad_y : ipad_y_default;
184 children = GTK_BOX(bbox)->children;
185 needed_width = child_min_width;
186 needed_height = child_min_height;
192 child = children->data;
193 children = children->next;
195 if (GTK_WIDGET_VISIBLE (child->widget))
198 gtk_widget_size_request (child->widget, &child_requisition);
199 if (child_requisition.width + ipad_w > needed_width)
200 needed_width = child_requisition.width + ipad_w;
201 if (child_requisition.height + ipad_h > needed_height)
202 needed_height = child_requisition.height + ipad_h;
206 *nvis_children = nchildren;
207 *width = needed_width;
208 *height = needed_height;