2 PSPPIRE --- A Graphical User Interface for PSPP
3 Copyright (C) 2007 Free Software Foundation
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 #include <gtk/gtksignal.h>
26 #include "psppire-hbuttonbox.h"
27 #include "psppire-dialog.h"
29 #include <gtk/gtkbbox.h>
33 #define _(msgid) gettext (msgid)
34 #define N_(msgid) msgid
37 static void psppire_hbuttonbox_class_init (PsppireHButtonBoxClass *);
38 static void psppire_hbuttonbox_init (PsppireHButtonBox *);
40 static void gtk_hbutton_box_size_request (GtkWidget *widget,
41 GtkRequisition *requisition);
42 static void gtk_hbutton_box_size_allocate (GtkWidget *widget,
43 GtkAllocation *allocation);
46 static GtkButtonBoxStyle default_layout_style = GTK_BUTTONBOX_EDGE;
49 psppire_hbutton_box_get_type (void)
51 static GType hbuttonbox_type = 0;
55 static const GTypeInfo hbuttonbox_info =
57 sizeof (PsppireHButtonBoxClass),
59 NULL, /* base_finalize */
60 (GClassInitFunc) psppire_hbuttonbox_class_init,
61 NULL, /* class_finalize */
62 NULL, /* class_data */
63 sizeof (PsppireHButtonBox),
65 (GInstanceInitFunc) psppire_hbuttonbox_init,
68 hbuttonbox_type = g_type_register_static (PSPPIRE_BUTTONBOX_TYPE,
69 "PsppireHButtonBox", &hbuttonbox_info, 0);
72 return hbuttonbox_type;
76 psppire_hbuttonbox_class_init (PsppireHButtonBoxClass *class)
78 GtkWidgetClass *widget_class;
80 widget_class = (GtkWidgetClass*) class;
82 widget_class->size_request = gtk_hbutton_box_size_request;
83 widget_class->size_allocate = gtk_hbutton_box_size_allocate;
88 psppire_hbuttonbox_init (PsppireHButtonBox *hbuttonbox)
94 psppire_hbuttonbox_new (void)
96 PsppireHButtonBox *hbuttonbox ;
98 hbuttonbox = g_object_new (psppire_hbutton_box_get_type (), NULL);
100 return GTK_WIDGET (hbuttonbox) ;
105 /* The following two functions are lifted verbatim from
106 the Gtk2.10.6 library */
109 gtk_hbutton_box_size_request (GtkWidget *widget,
110 GtkRequisition *requisition)
118 GtkButtonBoxStyle layout;
120 box = GTK_BOX (widget);
121 bbox = GTK_BUTTON_BOX (widget);
123 spacing = box->spacing;
124 layout = bbox->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
125 ? bbox->layout_style : default_layout_style;
127 _psppire_button_box_child_requisition (widget,
133 if (nvis_children == 0)
135 requisition->width = 0;
136 requisition->height = 0;
142 case GTK_BUTTONBOX_SPREAD:
144 nvis_children*child_width + ((nvis_children+1)*spacing);
146 case GTK_BUTTONBOX_EDGE:
147 case GTK_BUTTONBOX_START:
148 case GTK_BUTTONBOX_END:
149 requisition->width = nvis_children*child_width + ((nvis_children-1)*spacing);
152 g_assert_not_reached();
156 requisition->height = child_height;
159 requisition->width += GTK_CONTAINER (box)->border_width * 2;
160 requisition->height += GTK_CONTAINER (box)->border_width * 2;
166 gtk_hbutton_box_size_allocate (GtkWidget *widget,
167 GtkAllocation *allocation)
173 GtkAllocation child_allocation;
179 gint secondary_x = 0;
183 gint childspacing = 0;
184 GtkButtonBoxStyle layout;
187 base_box = GTK_BOX (widget);
188 box = GTK_BUTTON_BOX (widget);
189 spacing = base_box->spacing;
190 layout = box->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
191 ? box->layout_style : default_layout_style;
192 _psppire_button_box_child_requisition (widget,
197 widget->allocation = *allocation;
198 width = allocation->width - GTK_CONTAINER (box)->border_width*2;
201 case GTK_BUTTONBOX_SPREAD:
202 childspacing = (width - (nvis_children * child_width)) / (nvis_children + 1);
203 x = allocation->x + GTK_CONTAINER (box)->border_width + childspacing;
204 secondary_x = x + ((nvis_children - n_secondaries) * (child_width + childspacing));
206 case GTK_BUTTONBOX_EDGE:
207 if (nvis_children >= 2)
209 childspacing = (width - (nvis_children * child_width)) / (nvis_children - 1);
210 x = allocation->x + GTK_CONTAINER (box)->border_width;
211 secondary_x = x + ((nvis_children - n_secondaries) * (child_width + childspacing));
215 /* one or zero children, just center */
216 childspacing = width;
217 x = secondary_x = allocation->x + (allocation->width - child_width) / 2;
220 case GTK_BUTTONBOX_START:
221 childspacing = spacing;
222 x = allocation->x + GTK_CONTAINER (box)->border_width;
223 secondary_x = allocation->x + allocation->width
224 - child_width * n_secondaries
225 - spacing * (n_secondaries - 1)
226 - GTK_CONTAINER (box)->border_width;
228 case GTK_BUTTONBOX_END:
229 childspacing = spacing;
230 x = allocation->x + allocation->width
231 - child_width * (nvis_children - n_secondaries)
232 - spacing * (nvis_children - n_secondaries - 1)
233 - GTK_CONTAINER (box)->border_width;
234 secondary_x = allocation->x + GTK_CONTAINER (box)->border_width;
237 g_assert_not_reached();
242 y = allocation->y + (allocation->height - child_height) / 2;
243 childspace = child_width + childspacing;
245 children = GTK_BOX (box)->children;
249 child = children->data;
250 children = children->next;
252 if (GTK_WIDGET_VISIBLE (child->widget))
254 child_allocation.width = child_width;
255 child_allocation.height = child_height;
256 child_allocation.y = y;
258 if (child->is_secondary)
260 child_allocation.x = secondary_x;
261 secondary_x += childspace;
265 child_allocation.x = x;
269 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
270 child_allocation.x = (allocation->x + allocation->width) - (child_allocation.x + child_width - allocation->x);
272 gtk_widget_size_allocate (child->widget, &child_allocation);