Fixed bug reporting the significance of paired value t-test.
[pspp-builds.git] / src / ui / gui / window-manager.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2006, 2007  Free Software Foundation
3
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.
8
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.
13
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/>. */
16
17
18 #include <config.h>
19
20 #include "relocatable.h"
21
22 #include <glib.h>
23 #include "syntax-editor.h"
24 #include "data-editor.h"
25 #include "output-viewer.h"
26
27 #include <gettext.h>
28 #define _(msgid) gettext (msgid)
29 #define N_(msgid) msgid
30
31
32 #include "window-manager.h"
33
34
35
36 /* A list of struct editor_windows */
37 static GSList *window_list = NULL;
38
39
40 static void
41 deregister_window (GtkWindow *w, gpointer data)
42 {
43   struct editor_window *e = data;
44
45   window_list = g_slist_remove (window_list, e);
46
47   if ( g_slist_length (window_list) == 0 )
48     gtk_main_quit ();
49 };
50
51
52 static void
53 register_window (struct editor_window *e)
54 {
55   window_list = g_slist_prepend (window_list, e);
56 }
57
58
59 static gint
60 next_window_id (void)
61 {
62   return g_slist_length (window_list);
63 }
64
65 void
66 minimise_all_windows (void)
67 {
68   const GSList *i = NULL;
69
70   for (i = window_list; i != NULL ; i = i->next)
71     {
72       struct editor_window *e = i->data;
73       gtk_window_iconify (e->window);
74     }
75 }
76
77 static void set_window_name (struct editor_window *e, const gchar *name );
78
79
80 struct editor_window *
81 window_create (enum window_type type, const gchar *name)
82 {
83   struct editor_window *e;
84   switch (type)
85     {
86     case WINDOW_SYNTAX:
87       e = (struct editor_window *) new_syntax_editor ();
88       break;
89     case WINDOW_DATA:
90       e = (struct editor_window *) new_data_editor ();
91       break;
92     case WINDOW_OUTPUT:
93       e = (struct editor_window *) new_output_viewer ();
94       break;
95     default:
96       g_assert_not_reached ();
97     };
98
99   e->type = type;
100   e->name = NULL;
101
102   set_window_name (e, name);
103
104
105   gtk_window_set_icon_from_file (GTK_WINDOW (e->window),
106                                  relocate (PKGDATADIR "/psppicon.png"), 0);
107
108   g_signal_connect (e->window, "destroy",
109                     G_CALLBACK (deregister_window), e);
110
111   register_window (e);
112
113   gtk_widget_show (GTK_WIDGET (e->window));
114
115   return e;
116 }
117
118 void
119 default_window_name (struct editor_window *w)
120 {
121   set_window_name (w, NULL);
122 }
123
124 static void
125 set_window_name (struct editor_window *e,
126                  const gchar *name )
127 {
128   gchar *title ;
129   g_free (e->name);
130
131   e->name = NULL;
132
133   if ( name )
134     {
135       e->name =  g_strdup (name);
136       return;
137     }
138
139   switch (e->type )
140     {
141     case WINDOW_SYNTAX:
142       e->name = g_strdup_printf (_("Syntax%d"), next_window_id () );
143       title = g_strdup_printf (_("%s --- PSPP Syntax Editor"), e->name);
144       break;
145     case WINDOW_DATA:
146       e->name = g_strdup_printf (_("Untitled%d"), next_window_id () );
147       title = g_strdup_printf (_("%s --- PSPP Data Editor"), e->name);
148       break;
149     case WINDOW_OUTPUT:
150       e->name = g_strdup_printf (_("Output%d"), next_window_id () );
151       title = g_strdup_printf (_("%s --- PSPP Output"), e->name);
152       break;
153     default:
154       g_assert_not_reached ();
155     }
156
157   gtk_window_set_title (GTK_WINDOW (e->window), title);
158
159   g_free (title);
160 }
161
162
163 /* Set the name of this window based on FILENAME.
164    FILENAME is in "filename encoding" */
165 void
166 window_set_name_from_filename (struct editor_window *e,
167                                const gchar *fn)
168 {
169   gchar *title;
170   gchar *filename = g_filename_to_utf8 (fn, -1, NULL, NULL, NULL);
171   gchar *basename = g_path_get_basename (filename);
172
173   set_window_name (e, filename);
174
175   switch (e->type)
176     {
177     case WINDOW_SYNTAX:
178       title = g_strdup_printf (_("%s --- PSPP Syntax Editor"), basename);
179       break;
180     case WINDOW_DATA:
181       title = g_strdup_printf (_("%s --- PSPP Data Editor"), basename);
182       break;
183     default:
184       g_assert_not_reached ();
185     }
186   g_free (basename);
187
188   gtk_window_set_title (GTK_WINDOW (e->window), title);
189
190   g_free (title);
191   g_free (filename);
192 }
193
194 const gchar *
195 window_name (const struct editor_window *e)
196 {
197   return e->name;
198 }