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_type (void)
43 static GType vbuttonbox_type = 0;
47 static const GTypeInfo vbuttonbox_info =
49 sizeof (PsppireVButtonBoxClass),
51 NULL, /* base_finalize */
52 (GClassInitFunc) psppire_vbuttonbox_class_init,
53 NULL, /* class_finalize */
54 NULL, /* class_data */
55 sizeof (PsppireVButtonBox),
57 (GInstanceInitFunc) psppire_vbuttonbox_init,
60 vbuttonbox_type = g_type_register_static (PSPPIRE_BUTTONBOX_TYPE,
61 "PsppireVButtonBox", &vbuttonbox_info, 0);
64 return vbuttonbox_type;
68 psppire_vbuttonbox_class_init (PsppireVButtonBoxClass *class)
70 GtkWidgetClass *widget_class;
72 widget_class = (GtkWidgetClass*) class;
74 widget_class->size_request = gtk_vbutton_box_size_request;
75 widget_class->size_allocate = gtk_vbutton_box_size_allocate;
80 psppire_vbuttonbox_init (PsppireVButtonBox *vbuttonbox)
86 psppire_vbuttonbox_new (void)
88 PsppireVButtonBox *vbuttonbox ;
90 vbuttonbox = g_object_new (psppire_vbutton_box_get_type (), NULL);
92 return GTK_WIDGET (vbuttonbox) ;
97 /* The following two functions are lifted verbatim from
98 the Gtk2.10.6 library */
101 gtk_vbutton_box_size_request (GtkWidget *widget,
102 GtkRequisition *requisition)
110 GtkButtonBoxStyle layout;
112 box = GTK_BOX (widget);
113 bbox = GTK_BUTTON_BOX (widget);
115 spacing = gtk_box_get_spacing (box);
116 layout = gtk_button_box_get_layout (bbox);
118 _psppire_button_box_child_requisition (widget,
124 if (nvis_children == 0)
126 requisition->width = 0;
127 requisition->height = 0;
133 case GTK_BUTTONBOX_SPREAD:
134 requisition->height =
135 nvis_children*child_height + ((nvis_children+1)*spacing);
137 case GTK_BUTTONBOX_EDGE:
138 case GTK_BUTTONBOX_START:
139 case GTK_BUTTONBOX_END:
141 requisition->height =
142 nvis_children*child_height + ((nvis_children-1)*spacing);
145 requisition->width = child_width;
148 requisition->width += gtk_container_get_border_width (GTK_CONTAINER (box)) * 2;
149 requisition->height += gtk_container_get_border_width (GTK_CONTAINER (box)) * 2;
155 gtk_vbutton_box_size_allocate (GtkWidget *widget,
156 GtkAllocation *allocation)
161 GtkAllocation child_allocation;
168 gint secondary_y = 0;
171 gint childspacing = 0;
172 GtkButtonBoxStyle layout;
175 base_box = GTK_BOX (widget);
176 box = GTK_BUTTON_BOX (widget);
177 spacing = gtk_box_get_spacing (base_box);
178 layout = gtk_button_box_get_layout (box) ;
179 _psppire_button_box_child_requisition (widget,
184 gtk_widget_set_allocation (widget, allocation);
185 height = allocation->height - gtk_container_get_border_width (GTK_CONTAINER (box))*2;
188 case GTK_BUTTONBOX_SPREAD:
189 childspacing = (height - (nvis_children * child_height)) / (nvis_children + 1);
190 y = allocation->y + gtk_container_get_border_width (GTK_CONTAINER (box)) + childspacing;
191 secondary_y = y + ((nvis_children - n_secondaries) * (child_height + childspacing));
193 case GTK_BUTTONBOX_EDGE:
195 if (nvis_children >= 2)
197 childspacing = (height - (nvis_children*child_height)) / (nvis_children-1);
198 y = allocation->y + gtk_container_get_border_width (GTK_CONTAINER (box));
199 secondary_y = y + ((nvis_children - n_secondaries) * (child_height + childspacing));
203 /* one or zero children, just center */
204 childspacing = height;
205 y = secondary_y = allocation->y + (allocation->height - child_height) / 2;
208 case GTK_BUTTONBOX_START:
209 childspacing = spacing;
210 y = allocation->y + gtk_container_get_border_width (GTK_CONTAINER (box));
211 secondary_y = allocation->y + allocation->height
212 - child_height * n_secondaries
213 - spacing * (n_secondaries - 1)
214 - gtk_container_get_border_width (GTK_CONTAINER (box));
216 case GTK_BUTTONBOX_END:
217 childspacing = spacing;
218 y = allocation->y + allocation->height
219 - child_height * (nvis_children - n_secondaries)
220 - spacing * (nvis_children - n_secondaries - 1)
221 - gtk_container_get_border_width (GTK_CONTAINER (box));
222 secondary_y = allocation->y + gtk_container_get_border_width (GTK_CONTAINER (box));
226 x = allocation->x + (allocation->width - child_width) / 2;
227 childspace = child_height + childspacing;
229 children = gtk_container_get_children (GTK_CONTAINER (box));
232 GtkWidget *child = children->data;
233 children = children->next;
235 if (gtk_widget_get_visible (child))
237 gboolean is_secondary = FALSE;
238 gtk_container_child_get (GTK_CONTAINER (box), child, "secondary", &is_secondary, NULL);
240 child_allocation.width = child_width;
241 child_allocation.height = child_height;
242 child_allocation.x = x;
246 child_allocation.y = secondary_y;
247 secondary_y += childspace;
251 child_allocation.y = y;
255 gtk_widget_size_allocate (child, &child_allocation);