1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include <gtk/gtksignal.h>
22 #include "psppire-dialog.h"
24 static void psppire_dialog_class_init (PsppireDialogClass *);
25 static void psppire_dialog_init (PsppireDialog *);
31 static guint signals [n_SIGNALS];
35 psppire_dialog_get_type (void)
37 static GType dialog_type = 0;
41 static const GTypeInfo dialog_info =
43 sizeof (PsppireDialogClass),
45 NULL, /* base_finalize */
46 (GClassInitFunc) psppire_dialog_class_init,
47 NULL, /* class_finalize */
48 NULL, /* class_data */
49 sizeof (PsppireDialog),
51 (GInstanceInitFunc) psppire_dialog_init,
54 dialog_type = g_type_register_static (GTK_TYPE_WINDOW,
55 "PsppireDialog", &dialog_info, 0);
63 static GObjectClass *parent_class = NULL;
67 psppire_dialog_finalize (GObject *object)
69 PsppireDialog *dialog ;
71 g_return_if_fail (object != NULL);
72 g_return_if_fail (PSPPIRE_IS_DIALOG (object));
74 dialog = PSPPIRE_DIALOG (object);
76 if (G_OBJECT_CLASS (parent_class)->finalize)
77 G_OBJECT_CLASS (parent_class)->finalize (object);
91 psppire_dialog_get_property (GObject *object,
96 PsppireDialog *dialog = PSPPIRE_DIALOG (object);
100 case PROP_ORIENTATION:
102 if ( GTK_IS_VBOX (dialog->box) )
103 g_value_set_enum (value, PSPPIRE_VERTICAL);
104 else if ( GTK_IS_HBOX (dialog->box))
105 g_value_set_enum (value, PSPPIRE_HORIZONTAL);
109 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
116 dialog_set_orientation (PsppireDialog *dialog, const GValue *orval)
118 PsppireOrientation orientation = g_value_get_enum (orval);
120 if ( dialog->box != NULL)
122 gtk_container_remove (GTK_CONTAINER (dialog), dialog->box);
125 if ( orientation == PSPPIRE_HORIZONTAL)
127 dialog->box = gtk_hbox_new (FALSE, 5);
131 dialog->box = gtk_vbox_new (FALSE, 5);
134 gtk_container_add (GTK_CONTAINER (dialog), dialog->box);
139 psppire_dialog_set_property (GObject *object,
145 PsppireDialog *dialog = PSPPIRE_DIALOG (object);
149 case PROP_ORIENTATION:
150 dialog_set_orientation (dialog, value);
153 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
159 static GParamSpec *orientation_spec ;
162 psppire_dialog_class_init (PsppireDialogClass *class)
164 GObjectClass *object_class = (GObjectClass *) class;
168 g_param_spec_enum ("orientation",
170 "Which way widgets are packed",
171 G_TYPE_PSPPIRE_ORIENTATION,
172 PSPPIRE_HORIZONTAL /* default value */,
173 G_PARAM_CONSTRUCT_ONLY |G_PARAM_READWRITE);
176 object_class->set_property = psppire_dialog_set_property;
177 object_class->get_property = psppire_dialog_get_property;
179 g_object_class_install_property (object_class,
185 signals [DIALOG_REFRESH] =
186 g_signal_new ("refresh",
187 G_TYPE_FROM_CLASS (class),
191 g_cclosure_marshal_VOID__VOID,
196 object_class->finalize = psppire_dialog_finalize;
203 close_dialog (GtkWidget *w, gpointer data)
205 PsppireDialog *dialog = data;
207 psppire_dialog_close (dialog);
211 psppire_dialog_close (PsppireDialog *dialog)
213 g_main_loop_quit (dialog->loop);
214 gtk_widget_hide (GTK_WIDGET (dialog));
219 delete_event_callback (GtkWidget *w, GdkEvent *e, gpointer data)
221 close_dialog (w, data);
226 psppire_dialog_init (PsppireDialog *dialog)
231 g_value_init (&value, orientation_spec->value_type);
232 g_param_value_set_default (orientation_spec, &value);
234 gtk_window_set_type_hint (GTK_WINDOW (dialog),
235 GDK_WINDOW_TYPE_HINT_DIALOG);
237 dialog_set_orientation (dialog, &value);
239 g_value_unset (&value);
241 g_signal_connect (G_OBJECT (dialog), "delete-event",
242 G_CALLBACK (delete_event_callback),
245 gtk_window_set_type_hint (GTK_WINDOW (dialog),
246 GDK_WINDOW_TYPE_HINT_DIALOG);
248 gtk_widget_show_all (dialog->box);
253 psppire_dialog_new (void)
255 PsppireDialog *dialog ;
257 dialog = g_object_new (psppire_dialog_get_type (), NULL);
259 return GTK_WIDGET (dialog) ;
263 psppire_dialog_run (PsppireDialog *dialog)
265 dialog->loop = g_main_loop_new (NULL, FALSE);
267 gtk_widget_show (GTK_WIDGET (dialog));
269 g_signal_emit (dialog, signals [DIALOG_REFRESH], 0);
271 g_main_loop_run (dialog->loop);
273 return dialog->response;
278 psppire_dialog_reload (PsppireDialog *dialog)
280 g_signal_emit (dialog, signals [DIALOG_REFRESH], 0);
287 psppire_orientation_get_type (void)
289 static GType etype = 0;
292 static const GEnumValue values[] =
294 { PSPPIRE_HORIZONTAL, "PSPPIRE_HORIZONTAL", "Horizontal" },
295 { PSPPIRE_VERTICAL, "PSPPIRE_VERTICAL", "Vertical" },
299 etype = g_enum_register_static
300 (g_intern_static_string ("PsppireOrientation"), values);