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-hbuttonbox.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_hbuttonbox_class_init (PsppireHButtonBoxClass *);
35 static void psppire_hbuttonbox_init (PsppireHButtonBox *);
37 static void gtk_hbutton_box_size_request (GtkWidget *widget,
38 GtkRequisition *requisition);
39 static void gtk_hbutton_box_size_allocate (GtkWidget *widget,
40 GtkAllocation *allocation);
43 static const GtkButtonBoxStyle default_layout_style = GTK_BUTTONBOX_EDGE;
46 psppire_hbutton_box_get_type (void)
48 static GType hbuttonbox_type = 0;
52 static const GTypeInfo hbuttonbox_info =
54 sizeof (PsppireHButtonBoxClass),
56 NULL, /* base_finalize */
57 (GClassInitFunc) psppire_hbuttonbox_class_init,
58 NULL, /* class_finalize */
59 NULL, /* class_data */
60 sizeof (PsppireHButtonBox),
62 (GInstanceInitFunc) psppire_hbuttonbox_init,
65 hbuttonbox_type = g_type_register_static (PSPPIRE_BUTTONBOX_TYPE,
66 "PsppireHButtonBox", &hbuttonbox_info, 0);
69 return hbuttonbox_type;
73 psppire_hbuttonbox_class_init (PsppireHButtonBoxClass *class)
75 GtkWidgetClass *widget_class;
77 widget_class = (GtkWidgetClass*) class;
79 widget_class->size_request = gtk_hbutton_box_size_request;
80 widget_class->size_allocate = gtk_hbutton_box_size_allocate;
85 psppire_hbuttonbox_init (PsppireHButtonBox *hbuttonbox)
91 psppire_hbuttonbox_new (void)
93 PsppireHButtonBox *hbuttonbox ;
95 hbuttonbox = g_object_new (psppire_hbutton_box_get_type (), NULL);
97 return GTK_WIDGET (hbuttonbox) ;
102 /* The following two functions are lifted verbatim from
103 the Gtk2.10.6 library */
106 gtk_hbutton_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:
141 nvis_children*child_width + ((nvis_children+1)*spacing);
143 case GTK_BUTTONBOX_EDGE:
144 case GTK_BUTTONBOX_START:
145 case GTK_BUTTONBOX_END:
146 requisition->width = nvis_children*child_width + ((nvis_children-1)*spacing);
149 g_assert_not_reached();
153 requisition->height = child_height;
156 requisition->width += GTK_CONTAINER (box)->border_width * 2;
157 requisition->height += GTK_CONTAINER (box)->border_width * 2;
163 gtk_hbutton_box_size_allocate (GtkWidget *widget,
164 GtkAllocation *allocation)
170 GtkAllocation child_allocation;
176 gint secondary_x = 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 width = allocation->width - GTK_CONTAINER (box)->border_width*2;
198 case GTK_BUTTONBOX_SPREAD:
199 childspacing = (width - (nvis_children * child_width)) / (nvis_children + 1);
200 x = allocation->x + GTK_CONTAINER (box)->border_width + childspacing;
201 secondary_x = x + ((nvis_children - n_secondaries) * (child_width + childspacing));
203 case GTK_BUTTONBOX_EDGE:
204 if (nvis_children >= 2)
206 childspacing = (width - (nvis_children * child_width)) / (nvis_children - 1);
207 x = allocation->x + GTK_CONTAINER (box)->border_width;
208 secondary_x = x + ((nvis_children - n_secondaries) * (child_width + childspacing));
212 /* one or zero children, just center */
213 childspacing = width;
214 x = secondary_x = allocation->x + (allocation->width - child_width) / 2;
217 case GTK_BUTTONBOX_START:
218 childspacing = spacing;
219 x = allocation->x + GTK_CONTAINER (box)->border_width;
220 secondary_x = allocation->x + allocation->width
221 - child_width * n_secondaries
222 - spacing * (n_secondaries - 1)
223 - GTK_CONTAINER (box)->border_width;
225 case GTK_BUTTONBOX_END:
226 childspacing = spacing;
227 x = allocation->x + allocation->width
228 - child_width * (nvis_children - n_secondaries)
229 - spacing * (nvis_children - n_secondaries - 1)
230 - GTK_CONTAINER (box)->border_width;
231 secondary_x = allocation->x + GTK_CONTAINER (box)->border_width;
234 g_assert_not_reached();
239 y = allocation->y + (allocation->height - child_height) / 2;
240 childspace = child_width + childspacing;
242 children = GTK_BOX (box)->children;
246 child = children->data;
247 children = children->next;
249 if (GTK_WIDGET_VISIBLE (child->widget))
251 child_allocation.width = child_width;
252 child_allocation.height = child_height;
253 child_allocation.y = y;
255 if (child->is_secondary)
257 child_allocation.x = secondary_x;
258 secondary_x += childspace;
262 child_allocation.x = x;
266 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
267 child_allocation.x = (allocation->x + allocation->width) - (child_allocation.x + child_width - allocation->x);
269 gtk_widget_size_allocate (child->widget, &child_allocation);