Added psppire-dialog and psppire-buttonbox widgets.
[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 static void psppire_buttonbox_class_init          (PsppireButtonBoxClass *);
28 static void psppire_buttonbox_init                (PsppireButtonBox      *);
29
30
31 GType
32 psppire_button_box_get_type (void)
33 {
34   static GType buttonbox_type = 0;
35
36   if (!buttonbox_type)
37     {
38       static const GTypeInfo buttonbox_info =
39       {
40         sizeof (PsppireButtonBoxClass),
41         NULL, /* base_init */
42         NULL, /* base_finalize */
43         (GClassInitFunc) psppire_buttonbox_class_init,
44         NULL, /* class_finalize */
45         NULL, /* class_data */
46         sizeof (PsppireButtonBox),
47         0,
48         (GInstanceInitFunc) psppire_buttonbox_init,
49       };
50
51       buttonbox_type = g_type_register_static (GTK_TYPE_VBUTTON_BOX,
52                                             "PsppireButtonBox", &buttonbox_info, 0);
53     }
54
55   return buttonbox_type;
56 }
57
58 static GObjectClass     *parent_class = NULL;
59
60
61 static void
62 psppire_buttonbox_class_init (PsppireButtonBoxClass *class)
63 {
64 }
65
66 static void
67 close_dialog (GtkWidget *w, gpointer data)
68 {
69   PsppireDialog *dialog;
70
71   dialog = PSPPIRE_DIALOG (gtk_widget_get_toplevel (w));
72
73   dialog->response = GTK_RESPONSE_CANCEL;
74
75   psppire_dialog_close (dialog);
76 }
77
78 static void
79 ok_button_clicked (GtkWidget *w, gpointer data)
80 {
81   PsppireDialog *dialog;
82
83   dialog = PSPPIRE_DIALOG (gtk_widget_get_toplevel (w));
84
85   dialog->response = GTK_RESPONSE_OK;
86
87   psppire_dialog_close (dialog);
88 }
89
90
91 static void
92 refresh_clicked (GtkWidget *w, gpointer data)
93 {
94   PsppireDialog *dialog;
95
96   dialog = PSPPIRE_DIALOG (gtk_widget_get_toplevel (w));
97
98   psppire_dialog_reload (dialog, data);
99 }
100
101
102 static void
103 psppire_buttonbox_init (PsppireButtonBox *buttonbox)
104 {
105   GtkWidget *button ;
106
107   button = gtk_button_new_from_stock (GTK_STOCK_OK);
108   gtk_box_pack_start_defaults (GTK_BOX (buttonbox), button);
109   g_signal_connect (button, "clicked", G_CALLBACK (ok_button_clicked), NULL);
110   gtk_widget_show (button);
111
112   button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
113   g_signal_connect (button, "clicked", G_CALLBACK (close_dialog), NULL);
114   gtk_box_pack_start_defaults (GTK_BOX (buttonbox), button);
115   gtk_widget_show (button);
116
117   button = gtk_button_new_from_stock (GTK_STOCK_REFRESH);
118   g_signal_connect (button, "clicked", G_CALLBACK (refresh_clicked), NULL);
119   gtk_box_pack_start_defaults (GTK_BOX (buttonbox), button);
120   gtk_widget_show (button);
121
122   button = gtk_button_new_from_stock (GTK_STOCK_HELP);
123   gtk_box_pack_start_defaults (GTK_BOX (buttonbox), button);
124   gtk_widget_show (button);
125
126   gtk_widget_show (buttonbox);
127 }
128
129
130 GtkWidget*
131 psppire_buttonbox_new (void)
132 {
133   PsppireButtonBox *buttonbox ;
134
135   buttonbox = g_object_new (psppire_button_box_get_type (), NULL);
136
137   return GTK_WIDGET (buttonbox) ;
138 }
139