Added psppire-dialog and psppire-buttonbox widgets.
[pspp-builds.git] / src / ui / gui / window-manager.c
index 8ecce98c7c1a2e3581341aac7be78fd216fe1e62..51fc95a91de9df69f0f26b000a25c4a75f0880a2 100644 (file)
@@ -1,3 +1,24 @@
+/*
+    PSPPIRE --- A Graphical User Interface for PSPP
+    Copyright (C) 2006, 2007  Free Software Foundation
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+    02110-1301, USA. */
+
+
+#include <glib.h>
 #include "syntax-editor.h"
 #include "data-editor.h"
 
 #include "window-manager.h"
 
 
-static int window_count = 0;
+
+/* A list of struct editor_windows */
+static GSList *window_list = NULL;
+
 
 static void
-deregister (GtkObject *o, gpointer data)
+deregister_window (GtkWindow *w, gpointer data)
 {
-  window_count --;
+  struct editor_window *e = data;
+
+  window_list = g_slist_remove (window_list, e);
 
-  if ( 0 == window_count )
+  if ( g_slist_length (window_list) == 0 )
     gtk_main_quit ();
 };
 
+
+static void
+register_window (struct editor_window *e)
+{
+  window_list = g_slist_prepend (window_list, e);
+}
+
+
+static gint
+next_window_id (void)
+{
+  return g_slist_length (window_list);
+}
+
+void
+minimise_all_windows (void)
+{
+  const GSList *i = NULL;
+
+  for (i = window_list; i != NULL ; i = i->next)
+    {
+      struct editor_window *e = i->data;
+      gtk_window_iconify (e->window);
+    }
+}
+
 static void set_window_name (struct editor_window *e, const gchar *name );
 
 
@@ -48,11 +100,12 @@ window_create (enum window_type type, const gchar *name)
   gtk_window_set_icon_from_file (GTK_WINDOW (e->window),
                                 PKGDATADIR "/psppicon.png", 0);
 
-  g_signal_connect (e->window, "destroy", G_CALLBACK (deregister), NULL);
+  g_signal_connect (e->window, "destroy",
+                   G_CALLBACK (deregister_window), e);
 
-  gtk_widget_show (e->window);
+  register_window (e);
 
-  window_count ++;
+  gtk_widget_show (e->window);
 
   return e;
 }
@@ -75,11 +128,11 @@ set_window_name (struct editor_window *e,
   switch (e->type )
     {
     case WINDOW_SYNTAX:
-      e->name = g_strdup_printf (_("Syntax%d"), window_count);
+      e->name = g_strdup_printf (_("Syntax%d"), next_window_id () );
       title = g_strdup_printf (_("%s --- PSPP Syntax Editor"), e->name);
       break;
     case WINDOW_DATA:
-      e->name = g_strdup_printf (_("Untitled%d"), window_count);
+      e->name = g_strdup_printf (_("Untitled%d"), next_window_id () );
       title = g_strdup_printf (_("%s --- PSPP Data Editor"), e->name);
       break;
     default:
@@ -119,13 +172,6 @@ window_set_name_from_filename (struct editor_window *e,
   g_free (title);
 }
 
-
-GtkWindow *
-window_toplevel (const struct editor_window *e)
-{
-  return GTK_WINDOW (e->window);
-}
-
 const gchar *
 window_name (const struct editor_window *e)
 {