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;
38 static GObjectClass *parent_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 g_hash_table_remove (class->name_table, window->name);
187 if (G_OBJECT_CLASS (parent_class)->finalize)
188 G_OBJECT_CLASS (parent_class)->finalize (object);
193 psppire_window_class_init (PsppireWindowClass *class)
195 GObjectClass *object_class = G_OBJECT_CLASS (class);
199 GParamSpec *use_class_spec =
200 g_param_spec_enum ("usage",
202 "What the window is used for",
203 G_TYPE_PSPPIRE_WINDOW_USAGE,
204 PSPPIRE_WINDOW_USAGE_SYNTAX /* default value */,
205 G_PARAM_CONSTRUCT_ONLY |G_PARAM_READABLE | G_PARAM_WRITABLE);
208 GParamSpec *filename_spec =
209 g_param_spec_string ("filename",
211 "The name of the file associated with this window, if any",
213 G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT
217 object_class->set_property = psppire_window_set_property;
218 object_class->get_property = psppire_window_get_property;
220 g_object_class_install_property (object_class,
224 g_object_class_install_property (object_class,
229 class->name_table = g_hash_table_new (g_str_hash, g_str_equal);
231 g_hash_table_insert (class->name_table, "Untitled", NULL);
234 parent_class = g_type_class_peek_parent (class);
239 psppire_window_base_init (PsppireWindowClass *class)
241 GObjectClass *object_class = G_OBJECT_CLASS (class);
243 object_class->finalize = psppire_window_finalize;
249 psppire_window_base_finalize (PsppireWindowClass *class,
252 g_hash_table_destroy (class->name_table);
258 psppire_window_init (PsppireWindow *window)
261 window->finalized = FALSE;
266 psppire_window_new (PsppireWindowUsage usage)
268 return GTK_WIDGET (g_object_new (psppire_window_get_type (),
269 "type", GTK_WINDOW_TOPLEVEL,
276 psppire_window_get_filename (PsppireWindow *w)
278 const gchar *name = NULL;
279 g_object_get (w, "filename", name, NULL);
285 psppire_window_set_filename (PsppireWindow *w, const gchar *filename)
287 g_object_set (w, "filename", filename, NULL);
292 minimise_all (gpointer key,
296 PsppireWindow *w = PSPPIRE_WINDOW (value);
298 gtk_window_iconify (GTK_WINDOW (w));
304 psppire_window_minimise_all (void)
306 g_hash_table_foreach (the_class->name_table, minimise_all, NULL);
314 psppire_window_usage_get_type (void)
316 static GType etype = 0;
319 static const GEnumValue values[] = {
320 { PSPPIRE_WINDOW_USAGE_SYNTAX, "PSPPIRE_WINDOW_USAGE_SYNTAX",
323 { PSPPIRE_WINDOW_USAGE_OUTPUT, "PSPPIRE_WINDOW_USAGE_OUTPUT",
326 { PSPPIRE_WINDOW_USAGE_DATA, "PSPPIRE_WINDOW_USAGE_DATA",
332 etype = g_enum_register_static
333 (g_intern_static_string ("PsppireWindowUsage"), values);