2 PSPPIRE --- A Graphical User Interface for PSPP
3 Copyright (C) 2007 Free Software Foundation
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.
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.
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
24 #include <gtk/gtksignal.h>
25 #include "psppire-dialog.h"
27 static void psppire_dialog_class_init (PsppireDialogClass *);
28 static void psppire_dialog_init (PsppireDialog *);
34 static guint signals [n_SIGNALS];
38 psppire_dialog_get_type (void)
40 static GType dialog_type = 0;
44 static const GTypeInfo dialog_info =
46 sizeof (PsppireDialogClass),
48 NULL, /* base_finalize */
49 (GClassInitFunc) psppire_dialog_class_init,
50 NULL, /* class_finalize */
51 NULL, /* class_data */
52 sizeof (PsppireDialog),
54 (GInstanceInitFunc) psppire_dialog_init,
57 dialog_type = g_type_register_static (GTK_TYPE_WINDOW,
58 "PsppireDialog", &dialog_info, 0);
66 static GObjectClass *parent_class = NULL;
70 psppire_dialog_finalize (GObject *object)
72 PsppireDialog *dialog ;
74 g_return_if_fail (object != NULL);
75 g_return_if_fail (PSPPIRE_IS_DIALOG (object));
77 dialog = PSPPIRE_DIALOG (object);
79 if (G_OBJECT_CLASS (parent_class)->finalize)
80 G_OBJECT_CLASS (parent_class)->finalize (object);
94 psppire_dialog_get_property (GObject *object,
99 PsppireDialog *dialog = PSPPIRE_DIALOG (object);
103 case PROP_ORIENTATION:
105 if ( GTK_IS_VBOX (dialog->box) )
106 g_value_set_enum (value, PSPPIRE_VERTICAL);
107 else if ( GTK_IS_HBOX (dialog->box))
108 g_value_set_enum (value, PSPPIRE_HORIZONTAL);
112 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
119 dialog_set_orientation (PsppireDialog *dialog, const GValue *orval)
121 PsppireOrientation orientation = g_value_get_enum (orval);
123 if ( dialog->box != NULL)
125 gtk_container_remove (GTK_CONTAINER (dialog), dialog->box);
128 if ( orientation == PSPPIRE_HORIZONTAL)
130 dialog->box = gtk_hbox_new (FALSE, 5);
134 dialog->box = gtk_vbox_new (FALSE, 5);
137 gtk_container_add (GTK_CONTAINER (dialog), dialog->box);
142 psppire_dialog_set_property (GObject *object,
148 PsppireDialog *dialog = PSPPIRE_DIALOG (object);
152 case PROP_ORIENTATION:
153 dialog_set_orientation (dialog, value);
156 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
162 static GParamSpec *orientation_spec ;
165 psppire_dialog_class_init (PsppireDialogClass *class)
167 GObjectClass *object_class = (GObjectClass *) class;
171 g_param_spec_enum ("orientation",
173 "Which way widgets are packed",
174 G_TYPE_PSPPIRE_ORIENTATION,
175 PSPPIRE_HORIZONTAL /* default value */,
176 G_PARAM_CONSTRUCT_ONLY |G_PARAM_READWRITE);
179 object_class->set_property = psppire_dialog_set_property;
180 object_class->get_property = psppire_dialog_get_property;
182 g_object_class_install_property (object_class,
188 signals [DIALOG_REFRESH] =
189 g_signal_new ("refresh",
190 G_TYPE_FROM_CLASS (class),
194 g_cclosure_marshal_VOID__VOID,
199 object_class->finalize = psppire_dialog_finalize;
206 close_dialog (GtkWidget *w, gpointer data)
208 PsppireDialog *dialog = data;
210 psppire_dialog_close (dialog);
214 psppire_dialog_close (PsppireDialog *dialog)
216 g_main_loop_quit (dialog->loop);
217 gtk_widget_hide (GTK_WIDGET (dialog));
222 delete_event_callback (GtkWidget *w, GdkEvent *e, gpointer data)
224 close_dialog (w, data);
229 psppire_dialog_init (PsppireDialog *dialog)
234 g_value_init (&value, orientation_spec->value_type);
235 g_param_value_set_default (orientation_spec, &value);
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_widget_show_all (dialog->box);
250 psppire_dialog_new (void)
252 PsppireDialog *dialog ;
254 dialog = g_object_new (psppire_dialog_get_type (), NULL);
256 return GTK_WIDGET (dialog) ;
260 psppire_dialog_run (PsppireDialog *dialog)
262 dialog->loop = g_main_loop_new (NULL, FALSE);
264 gtk_widget_show (GTK_WIDGET (dialog));
266 g_signal_emit (dialog, signals [DIALOG_REFRESH], 0);
268 g_main_loop_run (dialog->loop);
270 return dialog->response;
275 psppire_dialog_reload (PsppireDialog *dialog)
277 g_signal_emit (dialog, signals [DIALOG_REFRESH], 0);
284 psppire_orientation_get_type (void)
286 static GType etype = 0;
289 static const GEnumValue values[] =
291 { PSPPIRE_HORIZONTAL, "PSPPIRE_HORIZONTAL", "Horizontal" },
292 { PSPPIRE_VERTICAL, "PSPPIRE_VERTICAL", "Vertical" },
296 etype = g_enum_register_static
297 (g_intern_static_string ("PsppireOrientation"), values);