1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007, 2010, 2011 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program 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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "psppire-vbuttonbox.h"
23 #include "psppire-dialog.h"
27 #define _(msgid) gettext (msgid)
28 #define N_(msgid) msgid
31 static void psppire_vbuttonbox_class_init (PsppireVButtonBoxClass *);
32 static void psppire_vbuttonbox_init (PsppireVButtonBox *);
34 static void gtk_vbutton_box_size_request (GtkWidget *widget,
35 GtkRequisition *requisition);
36 static void gtk_vbutton_box_size_allocate (GtkWidget *widget,
37 GtkAllocation *allocation);
41 psppire_vbutton_box_get_preferred_height (GtkWidget *widget,
45 GtkRequisition requisition;
47 gtk_vbutton_box_size_request (widget, &requisition);
49 *minimal_height = *natural_height = requisition.height;
54 psppire_vbutton_box_get_preferred_width (GtkWidget *widget,
58 GtkRequisition requisition;
60 gtk_vbutton_box_size_request (widget, &requisition);
62 *minimal_width = *natural_width = requisition.width;
67 psppire_vbutton_box_get_type (void)
69 static GType vbuttonbox_type = 0;
73 static const GTypeInfo vbuttonbox_info =
75 sizeof (PsppireVButtonBoxClass),
77 NULL, /* base_finalize */
78 (GClassInitFunc) psppire_vbuttonbox_class_init,
79 NULL, /* class_finalize */
80 NULL, /* class_data */
81 sizeof (PsppireVButtonBox),
83 (GInstanceInitFunc) psppire_vbuttonbox_init,
86 vbuttonbox_type = g_type_register_static (PSPPIRE_BUTTONBOX_TYPE,
87 "PsppireVButtonBox", &vbuttonbox_info, 0);
90 return vbuttonbox_type;
94 psppire_vbuttonbox_class_init (PsppireVButtonBoxClass *class)
96 GtkWidgetClass *widget_class;
98 widget_class = (GtkWidgetClass*) class;
100 widget_class->get_preferred_width = psppire_vbutton_box_get_preferred_width;
101 widget_class->get_preferred_height = psppire_vbutton_box_get_preferred_height;
102 widget_class->size_allocate = gtk_vbutton_box_size_allocate;
107 psppire_vbuttonbox_init (PsppireVButtonBox *vbuttonbox)
113 psppire_vbuttonbox_new (void)
115 PsppireVButtonBox *vbuttonbox ;
117 vbuttonbox = g_object_new (psppire_vbutton_box_get_type (), NULL);
119 return GTK_WIDGET (vbuttonbox) ;
124 /* The following two functions are lifted verbatim from
125 the Gtk2.10.6 library */
128 gtk_vbutton_box_size_request (GtkWidget *widget,
129 GtkRequisition *requisition)
137 GtkButtonBoxStyle layout;
139 box = GTK_BOX (widget);
140 bbox = GTK_BUTTON_BOX (widget);
142 spacing = gtk_box_get_spacing (box);
143 layout = gtk_button_box_get_layout (bbox);
145 _psppire_button_box_child_requisition (widget,
151 if (nvis_children == 0)
153 requisition->width = 0;
154 requisition->height = 0;
160 case GTK_BUTTONBOX_SPREAD:
161 requisition->height =
162 nvis_children*child_height + ((nvis_children+1)*spacing);
164 case GTK_BUTTONBOX_EDGE:
165 case GTK_BUTTONBOX_START:
166 case GTK_BUTTONBOX_END:
168 requisition->height =
169 nvis_children*child_height + ((nvis_children-1)*spacing);
172 requisition->width = child_width;
175 requisition->width += gtk_container_get_border_width (GTK_CONTAINER (box)) * 2;
176 requisition->height += gtk_container_get_border_width (GTK_CONTAINER (box)) * 2;
182 gtk_vbutton_box_size_allocate (GtkWidget *widget,
183 GtkAllocation *allocation)
188 GtkAllocation child_allocation;
195 gint secondary_y = 0;
198 gint childspacing = 0;
199 GtkButtonBoxStyle layout;
202 base_box = GTK_BOX (widget);
203 box = GTK_BUTTON_BOX (widget);
204 spacing = gtk_box_get_spacing (base_box);
205 layout = gtk_button_box_get_layout (box) ;
206 _psppire_button_box_child_requisition (widget,
211 gtk_widget_set_allocation (widget, allocation);
212 height = allocation->height - gtk_container_get_border_width (GTK_CONTAINER (box))*2;
215 case GTK_BUTTONBOX_SPREAD:
216 childspacing = (height - (nvis_children * child_height)) / (nvis_children + 1);
217 y = allocation->y + gtk_container_get_border_width (GTK_CONTAINER (box)) + childspacing;
218 secondary_y = y + ((nvis_children - n_secondaries) * (child_height + childspacing));
220 case GTK_BUTTONBOX_EDGE:
222 if (nvis_children >= 2)
224 childspacing = (height - (nvis_children*child_height)) / (nvis_children-1);
225 y = allocation->y + gtk_container_get_border_width (GTK_CONTAINER (box));
226 secondary_y = y + ((nvis_children - n_secondaries) * (child_height + childspacing));
230 /* one or zero children, just center */
231 childspacing = height;
232 y = secondary_y = allocation->y + (allocation->height - child_height) / 2;
235 case GTK_BUTTONBOX_START:
236 childspacing = spacing;
237 y = allocation->y + gtk_container_get_border_width (GTK_CONTAINER (box));
238 secondary_y = allocation->y + allocation->height
239 - child_height * n_secondaries
240 - spacing * (n_secondaries - 1)
241 - gtk_container_get_border_width (GTK_CONTAINER (box));
243 case GTK_BUTTONBOX_END:
244 childspacing = spacing;
245 y = allocation->y + allocation->height
246 - child_height * (nvis_children - n_secondaries)
247 - spacing * (nvis_children - n_secondaries - 1)
248 - gtk_container_get_border_width (GTK_CONTAINER (box));
249 secondary_y = allocation->y + gtk_container_get_border_width (GTK_CONTAINER (box));
253 x = allocation->x + (allocation->width - child_width) / 2;
254 childspace = child_height + childspacing;
256 children = gtk_container_get_children (GTK_CONTAINER (box));
259 GtkWidget *child = children->data;
260 children = children->next;
262 if (gtk_widget_get_visible (child))
264 gboolean is_secondary = FALSE;
265 gtk_container_child_get (GTK_CONTAINER (box), child, "secondary", &is_secondary, NULL);
267 child_allocation.width = child_width;
268 child_allocation.height = child_height;
269 child_allocation.x = x;
273 child_allocation.y = secondary_y;
274 secondary_y += childspace;
278 child_allocation.y = y;
282 gtk_widget_size_allocate (child, &child_allocation);