1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007 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 <gtk/gtksignal.h>
23 #include "psppire-vbuttonbox.h"
24 #include "psppire-dialog.h"
26 #include <gtk/gtkbbox.h>
30 #define _(msgid) gettext (msgid)
31 #define N_(msgid) msgid
34 static void psppire_vbuttonbox_class_init (PsppireVButtonBoxClass *);
35 static void psppire_vbuttonbox_init (PsppireVButtonBox *);
37 static void gtk_vbutton_box_size_request (GtkWidget *widget,
38 GtkRequisition *requisition);
39 static void gtk_vbutton_box_size_allocate (GtkWidget *widget,
40 GtkAllocation *allocation);
43 static const GtkButtonBoxStyle default_layout_style = GTK_BUTTONBOX_EDGE;
46 psppire_vbutton_box_get_type (void)
48 static GType vbuttonbox_type = 0;
52 static const GTypeInfo vbuttonbox_info =
54 sizeof (PsppireVButtonBoxClass),
56 NULL, /* base_finalize */
57 (GClassInitFunc) psppire_vbuttonbox_class_init,
58 NULL, /* class_finalize */
59 NULL, /* class_data */
60 sizeof (PsppireVButtonBox),
62 (GInstanceInitFunc) psppire_vbuttonbox_init,
65 vbuttonbox_type = g_type_register_static (PSPPIRE_BUTTONBOX_TYPE,
66 "PsppireVButtonBox", &vbuttonbox_info, 0);
69 return vbuttonbox_type;
73 psppire_vbuttonbox_class_init (PsppireVButtonBoxClass *class)
75 GtkWidgetClass *widget_class;
77 widget_class = (GtkWidgetClass*) class;
79 widget_class->size_request = gtk_vbutton_box_size_request;
80 widget_class->size_allocate = gtk_vbutton_box_size_allocate;
85 psppire_vbuttonbox_init (PsppireVButtonBox *vbuttonbox)
91 psppire_vbuttonbox_new (void)
93 PsppireVButtonBox *vbuttonbox ;
95 vbuttonbox = g_object_new (psppire_vbutton_box_get_type (), NULL);
97 return GTK_WIDGET (vbuttonbox) ;
102 /* The following two functions are lifted verbatim from
103 the Gtk2.10.6 library */
106 gtk_vbutton_box_size_request (GtkWidget *widget,
107 GtkRequisition *requisition)
115 GtkButtonBoxStyle layout;
117 box = GTK_BOX (widget);
118 bbox = GTK_BUTTON_BOX (widget);
120 spacing = box->spacing;
121 layout = bbox->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
122 ? bbox->layout_style : default_layout_style;
124 _psppire_button_box_child_requisition (widget,
130 if (nvis_children == 0)
132 requisition->width = 0;
133 requisition->height = 0;
139 case GTK_BUTTONBOX_SPREAD:
140 requisition->height =
141 nvis_children*child_height + ((nvis_children+1)*spacing);
143 case GTK_BUTTONBOX_EDGE:
144 case GTK_BUTTONBOX_START:
145 case GTK_BUTTONBOX_END:
146 requisition->height =
147 nvis_children*child_height + ((nvis_children-1)*spacing);
150 g_assert_not_reached();
153 requisition->width = child_width;
156 requisition->width += GTK_CONTAINER (box)->border_width * 2;
157 requisition->height += GTK_CONTAINER (box)->border_width * 2;
163 gtk_vbutton_box_size_allocate (GtkWidget *widget,
164 GtkAllocation *allocation)
170 GtkAllocation child_allocation;
177 gint secondary_y = 0;
180 gint childspacing = 0;
181 GtkButtonBoxStyle layout;
184 base_box = GTK_BOX (widget);
185 box = GTK_BUTTON_BOX (widget);
186 spacing = base_box->spacing;
187 layout = box->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
188 ? box->layout_style : default_layout_style;
189 _psppire_button_box_child_requisition (widget,
194 widget->allocation = *allocation;
195 height = allocation->height - GTK_CONTAINER (box)->border_width*2;
198 case GTK_BUTTONBOX_SPREAD:
199 childspacing = (height - (nvis_children * child_height)) / (nvis_children + 1);
200 y = allocation->y + GTK_CONTAINER (box)->border_width + childspacing;
201 secondary_y = y + ((nvis_children - n_secondaries) * (child_height + childspacing));
203 case GTK_BUTTONBOX_EDGE:
204 if (nvis_children >= 2)
206 childspacing = (height - (nvis_children*child_height)) / (nvis_children-1);
207 y = allocation->y + GTK_CONTAINER (box)->border_width;
208 secondary_y = y + ((nvis_children - n_secondaries) * (child_height + childspacing));
212 /* one or zero children, just center */
213 childspacing = height;
214 y = secondary_y = allocation->y + (allocation->height - child_height) / 2;
217 case GTK_BUTTONBOX_START:
218 childspacing = spacing;
219 y = allocation->y + GTK_CONTAINER (box)->border_width;
220 secondary_y = allocation->y + allocation->height
221 - child_height * n_secondaries
222 - spacing * (n_secondaries - 1)
223 - GTK_CONTAINER (box)->border_width;
225 case GTK_BUTTONBOX_END:
226 childspacing = spacing;
227 y = allocation->y + allocation->height
228 - child_height * (nvis_children - n_secondaries)
229 - spacing * (nvis_children - n_secondaries - 1)
230 - GTK_CONTAINER (box)->border_width;
231 secondary_y = allocation->y + GTK_CONTAINER (box)->border_width;
234 g_assert_not_reached();
238 x = allocation->x + (allocation->width - child_width) / 2;
239 childspace = child_height + childspacing;
241 children = GTK_BOX (box)->children;
245 child = children->data;
246 children = children->next;
248 if (GTK_WIDGET_VISIBLE (child->widget))
250 child_allocation.width = child_width;
251 child_allocation.height = child_height;
252 child_allocation.x = x;
254 if (child->is_secondary)
256 child_allocation.y = secondary_y;
257 secondary_y += childspace;
261 child_allocation.y = y;
265 gtk_widget_size_allocate (child->widget, &child_allocation);