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