Added psppire-dialog and psppire-buttonbox widgets.
[pspp-builds.git] / src / ui / gui / psppire-dialog.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 <gtk/gtk.h>
22 #include <gtk/gtksignal.h>
23 #include "psppire-dialog.h"
24
25 static void psppire_dialog_class_init          (PsppireDialogClass *);
26 static void psppire_dialog_init                (PsppireDialog      *);
27
28
29 enum  {DIALOG_REFRESH,
30        n_SIGNALS};
31
32 static guint signal [n_SIGNALS];
33
34
35 GType
36 psppire_dialog_get_type (void)
37 {
38   static GType dialog_type = 0;
39
40   if (!dialog_type)
41     {
42       static const GTypeInfo dialog_info =
43       {
44         sizeof (PsppireDialogClass),
45         NULL, /* base_init */
46         NULL, /* base_finalize */
47         (GClassInitFunc) psppire_dialog_class_init,
48         NULL, /* class_finalize */
49         NULL, /* class_data */
50         sizeof (PsppireDialog),
51         0,
52         (GInstanceInitFunc) psppire_dialog_init,
53       };
54
55       dialog_type = g_type_register_static (GTK_TYPE_WINDOW,
56                                             "PsppireDialog", &dialog_info, 0);
57     }
58
59   return dialog_type;
60 }
61
62
63
64 static GObjectClass     *parent_class = NULL;
65
66
67 static void
68 psppire_dialog_finalize (GObject *object)
69 {
70   PsppireDialog *dialog ;
71
72   g_return_if_fail (object != NULL);
73   g_return_if_fail (PSPPIRE_IS_DIALOG (object));
74
75   dialog = PSPPIRE_DIALOG (object);
76
77   if (G_OBJECT_CLASS (parent_class)->finalize)
78     G_OBJECT_CLASS (parent_class)->finalize (object);
79 }
80
81
82 static void
83 psppire_dialog_class_init (PsppireDialogClass *class)
84 {
85   GObjectClass *object_class = (GObjectClass *) class;
86
87   signal [DIALOG_REFRESH] =
88     g_signal_new ("refresh",
89                   G_TYPE_FROM_CLASS (class),
90                   G_SIGNAL_RUN_FIRST,
91                   0,
92                   NULL, NULL,
93                   g_cclosure_marshal_VOID__VOID,
94                   G_TYPE_NONE,
95                   0);
96
97
98   object_class->finalize = psppire_dialog_finalize;
99 }
100
101
102
103
104 static void
105 close_dialog (GtkWidget *w, gpointer data)
106 {
107   PsppireDialog *dialog = data;
108
109   psppire_dialog_close (dialog);
110 }
111
112 void
113 psppire_dialog_close (PsppireDialog *dialog)
114 {
115   g_main_loop_quit (dialog->loop);
116   gtk_widget_hide (GTK_WIDGET (dialog));
117 }
118
119
120 static void
121 delete_event_callback (GtkWidget *w, GdkEvent *e, gpointer data)
122 {
123   close_dialog (w, data);
124 }
125
126
127 static void
128 psppire_dialog_init (PsppireDialog *dialog)
129 {
130   dialog->box = gtk_hbox_new (FALSE, 5);
131
132
133   gtk_container_add (GTK_CONTAINER (dialog), dialog->box);
134
135
136   g_signal_connect (G_OBJECT (dialog), "delete-event",
137                     G_CALLBACK (delete_event_callback),
138                     dialog);
139
140   gtk_widget_show_all (dialog->box);
141 }
142
143
144 GtkWidget*
145 psppire_dialog_new (void)
146 {
147   PsppireDialog *dialog ;
148
149   dialog = g_object_new (psppire_dialog_get_type (), NULL);
150
151   return GTK_WIDGET (dialog) ;
152 }
153
154 gint
155 psppire_dialog_run (PsppireDialog *dialog)
156 {
157   dialog->loop = g_main_loop_new (NULL, FALSE);
158
159   gtk_widget_show (GTK_WIDGET (dialog));
160
161   g_main_loop_run (dialog->loop);
162
163   return dialog->response;
164 }
165
166
167 void
168 psppire_dialog_reload (PsppireDialog *dialog, gpointer data)
169 {
170   g_signal_emit (dialog, signal [DIALOG_REFRESH], 0, data);
171 }