1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2008 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/>. */
19 #include <gtk/gtksignal.h>
20 #include <gtk/gtkwindow.h>
25 #define _(msgid) gettext (msgid)
26 #define N_(msgid) msgid
28 #include "psppire-window.h"
31 static void psppire_window_base_finalize (PsppireWindowClass *, gpointer);
32 static void psppire_window_base_init (PsppireWindowClass *class);
33 static void psppire_window_class_init (PsppireWindowClass *class);
34 static void psppire_window_init (PsppireWindow *window);
37 static PsppireWindowClass *the_class;
41 psppire_window_get_type (void)
43 static GType psppire_window_type = 0;
45 if (!psppire_window_type)
47 static const GTypeInfo psppire_window_info =
49 sizeof (PsppireWindowClass),
50 (GBaseInitFunc) psppire_window_base_init,
51 (GBaseFinalizeFunc) psppire_window_base_finalize,
52 (GClassInitFunc)psppire_window_class_init,
53 (GClassFinalizeFunc) NULL,
55 sizeof (PsppireWindow),
57 (GInstanceInitFunc) psppire_window_init,
61 g_type_register_static (GTK_TYPE_WINDOW, "PsppireWindow",
62 &psppire_window_info, 0);
65 return psppire_window_type;
79 uniquify (const gchar *str, int *x)
81 return g_strdup_printf ("%s%d", str, (*x)++);
87 psppire_window_set_property (GObject *object,
92 PsppireWindow *window = PSPPIRE_WINDOW (object);
94 PsppireWindowClass *class = PSPPIRE_WINDOW_CLASS (G_OBJECT_GET_CLASS (object));
98 window->usage = g_value_get_enum (value);
102 gchar mdash[6] = {0,0,0,0,0,0};
103 gchar *basename, *title;
104 const gchar *name = g_value_get_string (value);
105 gchar *candidate_name = strdup (name);
108 while ( g_hash_table_lookup (class->name_table, candidate_name))
110 free (candidate_name);
111 candidate_name = uniquify (name, &x);
114 basename = g_path_get_basename (candidate_name);
115 g_unichar_to_utf8 (0x2014, mdash);
117 switch (window->usage)
119 case PSPPIRE_WINDOW_USAGE_SYNTAX:
120 title = g_strdup_printf ( _("%s %s PSPPIRE Syntax Editor"),
123 case PSPPIRE_WINDOW_USAGE_OUTPUT:
124 title = g_strdup_printf ( _("%s %s PSPPIRE Output"),
126 case PSPPIRE_WINDOW_USAGE_DATA:
127 title = g_strdup_printf ( _("%s %s PSPPIRE Data Editor"),
131 g_assert_not_reached ();
135 gtk_window_set_title (GTK_WINDOW (window), title);
138 window->name = candidate_name;
141 g_hash_table_insert (class->name_table, window->name, window);
148 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
155 psppire_window_get_property (GObject *object,
160 PsppireWindow *window = PSPPIRE_WINDOW (object);
165 g_value_set_enum (value, window->usage);
168 g_value_set_string (value, window->name);
171 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
179 psppire_window_finalize (GObject *object)
181 PsppireWindow *window = PSPPIRE_WINDOW (object);
182 PsppireWindowClass *class = PSPPIRE_WINDOW_CLASS (G_OBJECT_GET_CLASS (object));
184 GtkWindowClass *parent_class = g_type_class_peek_parent (class);
186 if ( window->finalized )
189 window->finalized = TRUE;
191 g_debug ("%s %p", __FUNCTION__, object);
193 g_hash_table_remove (class->name_table, window->name);
196 if (G_OBJECT_CLASS (parent_class)->finalize)
197 (*G_OBJECT_CLASS (parent_class)->finalize) (object);
202 psppire_window_class_init (PsppireWindowClass *class)
204 GObjectClass *object_class = G_OBJECT_CLASS (class);
206 GParamSpec *use_class_spec =
207 g_param_spec_enum ("usage",
209 "What the window is used for",
210 G_TYPE_PSPPIRE_WINDOW_USAGE,
211 PSPPIRE_WINDOW_USAGE_SYNTAX /* default value */,
212 G_PARAM_CONSTRUCT_ONLY |G_PARAM_READABLE | G_PARAM_WRITABLE);
215 GParamSpec *filename_spec =
216 g_param_spec_string ("filename",
218 "The name of the file associated with this window, if any",
220 G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT
224 object_class->set_property = psppire_window_set_property;
225 object_class->get_property = psppire_window_get_property;
227 g_object_class_install_property (object_class,
231 g_object_class_install_property (object_class,
236 class->name_table = g_hash_table_new (g_str_hash, g_str_equal);
238 g_hash_table_insert (class->name_table, "Untitled", NULL);
245 psppire_window_base_init (PsppireWindowClass *class)
247 GObjectClass *object_class = G_OBJECT_CLASS (class);
249 object_class->finalize = psppire_window_finalize;
255 psppire_window_base_finalize (PsppireWindowClass *class,
258 g_hash_table_destroy (class->name_table);
264 psppire_window_init (PsppireWindow *window)
267 window->finalized = FALSE;
272 psppire_window_new (PsppireWindowUsage usage)
274 return GTK_WIDGET (g_object_new (psppire_window_get_type (),
275 "type", GTK_WINDOW_TOPLEVEL,
282 psppire_window_get_filename (PsppireWindow *w)
284 const gchar *name = NULL;
285 g_object_get (w, "filename", name, NULL);
291 psppire_window_set_filename (PsppireWindow *w, const gchar *filename)
293 g_object_set (w, "filename", filename, NULL);
298 minimise_all (gpointer key,
302 PsppireWindow *w = PSPPIRE_WINDOW (value);
304 gtk_window_iconify (GTK_WINDOW (w));
310 psppire_window_minimise_all (void)
312 g_hash_table_foreach (the_class->name_table, minimise_all, NULL);
320 psppire_window_usage_get_type (void)
322 static GType etype = 0;
325 static const GEnumValue values[] = {
326 { PSPPIRE_WINDOW_USAGE_SYNTAX, "PSPPIRE_WINDOW_USAGE_SYNTAX",
329 { PSPPIRE_WINDOW_USAGE_OUTPUT, "PSPPIRE_WINDOW_USAGE_OUTPUT",
332 { PSPPIRE_WINDOW_USAGE_DATA, "PSPPIRE_WINDOW_USAGE_DATA",
338 etype = g_enum_register_static
339 (g_intern_static_string ("PsppireWindowUsage"), values);