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