e5c1c561a76704c59851820541c2212aec6958d2
[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_buttonbox_class_init          (PsppireButtonBoxClass *);
36 static void psppire_buttonbox_init                (PsppireButtonBox      *);
37
38
39 GType
40 psppire_button_box_get_type (void)
41 {
42   static GType buttonbox_type = 0;
43
44   if (!buttonbox_type)
45     {
46       static const GTypeInfo buttonbox_info =
47       {
48         sizeof (PsppireButtonBoxClass),
49         NULL, /* base_init */
50         NULL, /* base_finalize */
51         (GClassInitFunc) psppire_buttonbox_class_init,
52         NULL, /* class_finalize */
53         NULL, /* class_data */
54         sizeof (PsppireButtonBox),
55         0,
56         (GInstanceInitFunc) psppire_buttonbox_init,
57       };
58
59       buttonbox_type = g_type_register_static (GTK_TYPE_VBUTTON_BOX,
60                                             "PsppireButtonBox", &buttonbox_info, 0);
61     }
62
63   return buttonbox_type;
64 }
65
66 static void
67 psppire_buttonbox_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_buttonbox_init (PsppireButtonBox *buttonbox)
122 {
123   GtkWidget *button ;
124
125   button = gtk_button_new_from_stock (GTK_STOCK_OK);
126   gtk_box_pack_start_defaults (GTK_BOX (buttonbox), 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 (buttonbox), 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 (buttonbox), 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 (buttonbox), 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 (buttonbox), button);
148   gtk_widget_show (button);
149
150   gtk_widget_show (GTK_WIDGET (buttonbox));
151 }
152
153
154 GtkWidget*
155 psppire_buttonbox_new (void)
156 {
157   PsppireButtonBox *buttonbox ;
158
159   buttonbox = g_object_new (psppire_button_box_get_type (), NULL);
160
161   return GTK_WIDGET (buttonbox) ;
162 }
163