bfa10c940955051dc45483f49981eec4742827de
[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 <glib.h>
22 #include <gtk/gtk.h>
23 #include <gtk/gtksignal.h>
24 #include "psppire-buttonbox.h"
25 #include "psppire-dialog.h"
26
27 #include <gettext.h>
28
29 #define _(msgid) gettext (msgid)
30 #define N_(msgid) msgid
31
32
33 static void psppire_buttonbox_class_init          (PsppireButtonBoxClass *);
34 static void psppire_buttonbox_init                (PsppireButtonBox      *);
35
36
37 GType
38 psppire_button_box_get_type (void)
39 {
40   static GType buttonbox_type = 0;
41
42   if (!buttonbox_type)
43     {
44       static const GTypeInfo buttonbox_info =
45       {
46         sizeof (PsppireButtonBoxClass),
47         NULL, /* base_init */
48         NULL, /* base_finalize */
49         (GClassInitFunc) psppire_buttonbox_class_init,
50         NULL, /* class_finalize */
51         NULL, /* class_data */
52         sizeof (PsppireButtonBox),
53         0,
54         (GInstanceInitFunc) psppire_buttonbox_init,
55       };
56
57       buttonbox_type = g_type_register_static (GTK_TYPE_VBUTTON_BOX,
58                                             "PsppireButtonBox", &buttonbox_info, 0);
59     }
60
61   return buttonbox_type;
62 }
63
64 static void
65 psppire_buttonbox_class_init (PsppireButtonBoxClass *class)
66 {
67 }
68
69 static void
70 close_dialog (GtkWidget *w, gpointer data)
71 {
72   PsppireDialog *dialog;
73
74   dialog = PSPPIRE_DIALOG (gtk_widget_get_toplevel (w));
75
76   dialog->response = GTK_RESPONSE_CANCEL;
77
78   psppire_dialog_close (dialog);
79 }
80
81 static void
82 ok_button_clicked (GtkWidget *w, gpointer data)
83 {
84   PsppireDialog *dialog;
85
86   dialog = PSPPIRE_DIALOG (gtk_widget_get_toplevel (w));
87
88   dialog->response = GTK_RESPONSE_OK;
89
90   psppire_dialog_close (dialog);
91 }
92
93
94 static void
95 paste_button_clicked (GtkWidget *w, gpointer data)
96 {
97   PsppireDialog *dialog;
98
99   dialog = PSPPIRE_DIALOG (gtk_widget_get_toplevel (w));
100
101   dialog->response = PSPPIRE_RESPONSE_PASTE;
102
103   psppire_dialog_close (dialog);
104 }
105
106
107 static void
108 refresh_clicked (GtkWidget *w, gpointer data)
109 {
110   PsppireDialog *dialog;
111
112   dialog = PSPPIRE_DIALOG (gtk_widget_get_toplevel (w));
113
114   psppire_dialog_reload (dialog, data);
115 }
116
117
118 static void
119 psppire_buttonbox_init (PsppireButtonBox *buttonbox)
120 {
121   GtkWidget *button ;
122
123   button = gtk_button_new_from_stock (GTK_STOCK_OK);
124   gtk_box_pack_start_defaults (GTK_BOX (buttonbox), button);
125   g_signal_connect (button, "clicked", G_CALLBACK (ok_button_clicked), NULL);
126   gtk_widget_show (button);
127
128   button = gtk_button_new_with_mnemonic (_("_Paste"));
129   g_signal_connect (button, "clicked", G_CALLBACK (paste_button_clicked),
130                     NULL);
131   gtk_box_pack_start_defaults (GTK_BOX (buttonbox), button);
132   gtk_widget_show (button);
133
134   button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
135   g_signal_connect (button, "clicked", G_CALLBACK (close_dialog), NULL);
136   gtk_box_pack_start_defaults (GTK_BOX (buttonbox), button);
137   gtk_widget_show (button);
138
139   button = gtk_button_new_from_stock (GTK_STOCK_REFRESH);
140   g_signal_connect (button, "clicked", G_CALLBACK (refresh_clicked), NULL);
141   gtk_box_pack_start_defaults (GTK_BOX (buttonbox), button);
142   gtk_widget_show (button);
143
144   button = gtk_button_new_from_stock (GTK_STOCK_HELP);
145   gtk_box_pack_start_defaults (GTK_BOX (buttonbox), button);
146   gtk_widget_show (button);
147
148   gtk_widget_show (GTK_WIDGET (buttonbox));
149 }
150
151
152 GtkWidget*
153 psppire_buttonbox_new (void)
154 {
155   PsppireButtonBox *buttonbox ;
156
157   buttonbox = g_object_new (psppire_button_box_get_type (), NULL);
158
159   return GTK_WIDGET (buttonbox) ;
160 }
161