Added the Compute dialog box.
[pspp-builds.git] / src / ui / gui / psppire-buttonbox.c
1 /*
2     PSPPIRE --- A Graphical User Interface for PSPP
3     Copyright (C) 2007  Free Software Foundation
4
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.
9
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.
14
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
18     02110-1301, USA. */
19
20
21 #include <config.h>
22
23 #include <glib.h>
24 #include <gtk/gtk.h>
25 #include <gtk/gtksignal.h>
26 #include "psppire-buttonbox.h"
27 #include "psppire-dialog.h"
28
29 #include <gettext.h>
30
31 #define _(msgid) gettext (msgid)
32 #define N_(msgid) msgid
33
34
35 static void psppire_button_box_class_init          (PsppireButtonBoxClass *);
36 static void psppire_button_box_init                (PsppireButtonBox      *);
37
38
39 GType
40 psppire_button_box_get_type (void)
41 {
42   static GType button_box_type = 0;
43
44   if (!button_box_type)
45     {
46       static const GTypeInfo button_box_info =
47       {
48         sizeof (PsppireButtonBoxClass),
49         NULL, /* base_init */
50         NULL, /* base_finalize */
51         (GClassInitFunc) psppire_button_box_class_init,
52         NULL, /* class_finalize */
53         NULL, /* class_data */
54         sizeof (PsppireButtonBox),
55         0,
56         (GInstanceInitFunc) psppire_button_box_init,
57       };
58
59       button_box_type = g_type_register_static (GTK_TYPE_BUTTON_BOX,
60                                             "PsppireButtonBox", &button_box_info, 0);
61     }
62
63   return button_box_type;
64 }
65
66 static void
67 psppire_button_box_class_init (PsppireButtonBoxClass *class)
68 {
69 }
70
71 static void
72 close_dialog (GtkWidget *w, gpointer data)
73 {
74   PsppireDialog *dialog;
75
76   dialog = PSPPIRE_DIALOG (gtk_widget_get_toplevel (w));
77
78   dialog->response = GTK_RESPONSE_CANCEL;
79
80   psppire_dialog_close (dialog);
81 }
82
83 static void
84 ok_button_clicked (GtkWidget *w, gpointer data)
85 {
86   PsppireDialog *dialog;
87
88   dialog = PSPPIRE_DIALOG (gtk_widget_get_toplevel (w));
89
90   dialog->response = GTK_RESPONSE_OK;
91
92   psppire_dialog_close (dialog);
93 }
94
95
96 static void
97 paste_button_clicked (GtkWidget *w, gpointer data)
98 {
99   PsppireDialog *dialog;
100
101   dialog = PSPPIRE_DIALOG (gtk_widget_get_toplevel (w));
102
103   dialog->response = PSPPIRE_RESPONSE_PASTE;
104
105   psppire_dialog_close (dialog);
106 }
107
108
109 static void
110 refresh_clicked (GtkWidget *w, gpointer data)
111 {
112   PsppireDialog *dialog;
113
114   dialog = PSPPIRE_DIALOG (gtk_widget_get_toplevel (w));
115
116   psppire_dialog_reload (dialog);
117 }
118
119
120 static void
121 psppire_button_box_init (PsppireButtonBox *button_box)
122 {
123   GtkWidget *button ;
124
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);
129
130   button = gtk_button_new_with_mnemonic (_("_Paste"));
131   g_signal_connect (button, "clicked", G_CALLBACK (paste_button_clicked),
132                     NULL);
133   gtk_box_pack_start_defaults (GTK_BOX (button_box), button);
134   gtk_widget_show (button);
135
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);
140
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);
145
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);
149
150 }
151
152
153 /* This function is lifted verbatim from the Gtk2.10.6 library */
154
155 void
156 _psppire_button_box_child_requisition (GtkWidget *widget,
157                                        int       *nvis_children,
158                                        int       *nvis_secondaries,
159                                        int       *width,
160                                        int       *height)
161 {
162   GtkButtonBox *bbox;
163   GtkBoxChild *child;
164   GList *children;
165   gint nchildren;
166   gint nsecondaries;
167   gint needed_width;
168   gint needed_height;
169   GtkRequisition child_requisition;
170   gint ipad_w;
171   gint ipad_h;
172   gint width_default;
173   gint height_default;
174   gint ipad_x_default;
175   gint ipad_y_default;
176
177   gint child_min_width;
178   gint child_min_height;
179   gint ipad_x;
180   gint ipad_y;
181
182   g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
183
184   bbox = GTK_BUTTON_BOX (widget);
185
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,
191                         NULL);
192
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;
201
202   nchildren = 0;
203   nsecondaries = 0;
204   children = GTK_BOX(bbox)->children;
205   needed_width = child_min_width;
206   needed_height = child_min_height;
207   ipad_w = ipad_x * 2;
208   ipad_h = ipad_y * 2;
209
210   while (children)
211     {
212       child = children->data;
213       children = children->next;
214
215       if (GTK_WIDGET_VISIBLE (child->widget))
216         {
217           nchildren += 1;
218           gtk_widget_size_request (child->widget, &child_requisition);
219
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)
225             nsecondaries++;
226         }
227     }
228
229   if (nvis_children)
230     *nvis_children = nchildren;
231   if (nvis_secondaries)
232     *nvis_secondaries = nsecondaries;
233   if (width)
234     *width = needed_width;
235   if (height)
236     *height = needed_height;
237 }