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-buttonbox.h"
27 #include "psppire-dialog.h"
31 #define _(msgid) gettext (msgid)
32 #define N_(msgid) msgid
35 static void psppire_button_box_class_init (PsppireButtonBoxClass *);
36 static void psppire_button_box_init (PsppireButtonBox *);
40 psppire_button_box_get_type (void)
42 static GType button_box_type = 0;
46 static const GTypeInfo button_box_info =
48 sizeof (PsppireButtonBoxClass),
50 NULL, /* base_finalize */
51 (GClassInitFunc) psppire_button_box_class_init,
52 NULL, /* class_finalize */
53 NULL, /* class_data */
54 sizeof (PsppireButtonBox),
56 (GInstanceInitFunc) psppire_button_box_init,
59 button_box_type = g_type_register_static (GTK_TYPE_BUTTON_BOX,
60 "PsppireButtonBox", &button_box_info, 0);
63 return button_box_type;
67 psppire_button_box_class_init (PsppireButtonBoxClass *class)
72 close_dialog (GtkWidget *w, gpointer data)
74 PsppireDialog *dialog;
76 dialog = PSPPIRE_DIALOG (gtk_widget_get_toplevel (w));
78 dialog->response = GTK_RESPONSE_CANCEL;
80 psppire_dialog_close (dialog);
84 ok_button_clicked (GtkWidget *w, gpointer data)
86 PsppireDialog *dialog;
88 dialog = PSPPIRE_DIALOG (gtk_widget_get_toplevel (w));
90 dialog->response = GTK_RESPONSE_OK;
92 psppire_dialog_close (dialog);
97 paste_button_clicked (GtkWidget *w, gpointer data)
99 PsppireDialog *dialog;
101 dialog = PSPPIRE_DIALOG (gtk_widget_get_toplevel (w));
103 dialog->response = PSPPIRE_RESPONSE_PASTE;
105 psppire_dialog_close (dialog);
110 refresh_clicked (GtkWidget *w, gpointer data)
112 PsppireDialog *dialog;
114 dialog = PSPPIRE_DIALOG (gtk_widget_get_toplevel (w));
116 psppire_dialog_reload (dialog);
121 psppire_button_box_init (PsppireButtonBox *button_box)
125 button = gtk_button_new_from_stock (GTK_STOCK_OK);
126 gtk_box_pack_start_defaults (GTK_BOX (button_box), button);
127 g_signal_connect (button, "clicked", G_CALLBACK (ok_button_clicked), NULL);
128 gtk_widget_show (button);
130 button = gtk_button_new_with_mnemonic (_("_Paste"));
131 g_signal_connect (button, "clicked", G_CALLBACK (paste_button_clicked),
133 gtk_box_pack_start_defaults (GTK_BOX (button_box), button);
134 gtk_widget_show (button);
136 button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
137 g_signal_connect (button, "clicked", G_CALLBACK (close_dialog), NULL);
138 gtk_box_pack_start_defaults (GTK_BOX (button_box), button);
139 gtk_widget_show (button);
141 button = gtk_button_new_from_stock (GTK_STOCK_REFRESH);
142 g_signal_connect (button, "clicked", G_CALLBACK (refresh_clicked), NULL);
143 gtk_box_pack_start_defaults (GTK_BOX (button_box), button);
144 gtk_widget_show (button);
146 button = gtk_button_new_from_stock (GTK_STOCK_HELP);
147 gtk_box_pack_start_defaults (GTK_BOX (button_box), button);
148 gtk_widget_show (button);
153 /* This function is lifted verbatim from the Gtk2.10.6 library */
156 _psppire_button_box_child_requisition (GtkWidget *widget,
158 int *nvis_secondaries,
169 GtkRequisition child_requisition;
177 gint child_min_width;
178 gint child_min_height;
182 g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
184 bbox = GTK_BUTTON_BOX (widget);
186 gtk_widget_style_get (widget,
187 "child-min-width", &width_default,
188 "child-min-height", &height_default,
189 "child-internal-pad-x", &ipad_x_default,
190 "child-internal-pad-y", &ipad_y_default,
193 child_min_width = bbox->child_min_width != GTK_BUTTONBOX_DEFAULT
194 ? bbox->child_min_width : width_default;
195 child_min_height = bbox->child_min_height !=GTK_BUTTONBOX_DEFAULT
196 ? bbox->child_min_height : height_default;
197 ipad_x = bbox->child_ipad_x != GTK_BUTTONBOX_DEFAULT
198 ? bbox->child_ipad_x : ipad_x_default;
199 ipad_y = bbox->child_ipad_y != GTK_BUTTONBOX_DEFAULT
200 ? bbox->child_ipad_y : ipad_y_default;
204 children = GTK_BOX(bbox)->children;
205 needed_width = child_min_width;
206 needed_height = child_min_height;
212 child = children->data;
213 children = children->next;
215 if (GTK_WIDGET_VISIBLE (child->widget))
218 gtk_widget_size_request (child->widget, &child_requisition);
220 if (child_requisition.width + ipad_w > needed_width)
221 needed_width = child_requisition.width + ipad_w;
222 if (child_requisition.height + ipad_h > needed_height)
223 needed_height = child_requisition.height + ipad_h;
224 if (child->is_secondary)
230 *nvis_children = nchildren;
231 if (nvis_secondaries)
232 *nvis_secondaries = nsecondaries;
234 *width = needed_width;
236 *height = needed_height;