gui: Include only <gtk/gtk.h> to use GTK+.
[pspp-builds.git] / src / ui / gui / psppire-window.c
index a02edb289a90c7987d5b5ef1d031ecaaec244831..369ece50257566a6e420d081118f62701fe05288 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2009  Free Software Foundation
+   Copyright (C) 2009, 2010, 2011  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
 #include <config.h>
 
 
-#include <gtk/gtkstock.h>
-#include <gtk/gtkmessagedialog.h>
-#include <gtk/gtksignal.h>
-#include <gtk/gtkwindow.h>
-#include <gtk/gtkcheckmenuitem.h>
-#include <gtk/gtkmain.h>
+#include <gtk/gtk.h>
 
 #include <stdlib.h>
+#include <xalloc.h>
 
 #include <gettext.h>
 #define _(msgid) gettext (msgid)
@@ -86,16 +82,14 @@ uniquify (const gchar *str, int *x)
   return g_strdup_printf ("%s%d", str, (*x)++);
 }
 
-static gchar mdash[6] = {0,0,0,0,0,0};
-
 static void
 psppire_window_set_title (PsppireWindow *window)
 {
   GString *title = g_string_sized_new (80);
 
-  g_string_printf (title, _("%s %s PSPPIRE %s"),
-                  window->basename ? window->basename : "",
-                  mdash, window->description);
+  g_string_printf (title, "%s ", window->basename ? window->basename : "");
+  g_string_append_unichar (title, 0x2014); /* em dash */
+  g_string_printf (title, " PSPPIRE %s", window->description);
 
   if (window->dirty)
     g_string_prepend_c (title, '*');
@@ -137,7 +131,7 @@ psppire_window_set_property (GObject         *object,
              name = g_value_get_string (&def);
            }
 
-         candidate_name = strdup (name);
+         candidate_name = xstrdup (name);
 
          while ( psppire_window_register_lookup (reg, candidate_name))
            {
@@ -202,19 +196,6 @@ on_realize (GtkWindow *window, gpointer data)
 }
 
 
-static gboolean
-save_geometry (GtkWidget *window, GdkEvent *event, gpointer data)
-{
-  const gchar *base = G_OBJECT_TYPE_NAME (window);
-
-  PsppireConf *conf = psppire_conf_new ();
-
-  psppire_conf_save_window_geometry (conf, base, event);
-
-  return FALSE;
-}
-
-
 static void
 psppire_window_finalize (GObject *object)
 {
@@ -255,11 +236,10 @@ psppire_window_class_init (PsppireWindowClass *class)
     g_param_spec_string ("filename",
                       "File name",
                       "The name of the file associated with this window, if any",
-                        "Untitled",
+                        /* TRANSLATORS: This will form a filename.  Please avoid whitespace. */
+                        _("Untitled"),
                         G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
 
-  g_unichar_to_utf8 (0x2014, mdash);
-
   object_class->set_property = psppire_window_set_property;
   object_class->get_property = psppire_window_get_property;
 
@@ -315,9 +295,20 @@ menu_activate (GtkMenuItem *mi, gpointer data)
 static void
 insert_menuitem_into_menu (PsppireWindow *window, gpointer key)
 {
-  gchar *filename = g_filename_display_name (key);
-  GtkWidget *item = gtk_check_menu_item_new_with_label (filename);
+  gchar *filename;
+  GtkWidget *item;
+
+  /* Add a separator before adding the first real item.  If we add a separator
+     at any other time, sometimes GtkUIManager removes it. */
+  if (g_hash_table_size (window->menuitem_table) == 0)
+    {
+      GtkWidget *separator = gtk_separator_menu_item_new ();
+      gtk_widget_show (separator);
+      gtk_menu_shell_append (window->menu, separator);
+    }
 
+  filename = g_filename_display_name (key);
+  item = gtk_check_menu_item_new_with_label (filename);
   g_free (filename);
 
   g_signal_connect (item, "toggled", G_CALLBACK (menu_toggled), NULL);
@@ -381,6 +372,13 @@ on_delete (PsppireWindow *w, GdkEvent *event, gpointer user_data)
 {
   PsppireWindowRegister *reg = psppire_window_register_new ();
 
+  const gchar *base = G_OBJECT_TYPE_NAME (w);
+
+  PsppireConf *conf = psppire_conf_new ();
+
+  psppire_conf_save_window_geometry (conf, base, GTK_WINDOW (w));
+
+
   if ( w->dirty )
     {
       gint response = psppire_window_query_save (w);
@@ -411,7 +409,7 @@ psppire_window_init (PsppireWindow *window)
 {
   window->name = NULL;
   window->menu = NULL;
-  window->description = strdup ("");
+  window->description = xstrdup ("");
 
   window->menuitem_table  = g_hash_table_new (g_str_hash, g_str_equal);
 
@@ -434,12 +432,6 @@ psppire_window_init (PsppireWindow *window)
 
   g_object_set (window, "icon-name", "psppicon", NULL);
 
-  g_signal_connect (window, "configure-event",
-                   G_CALLBACK (save_geometry), window);
-
-  g_signal_connect (window, "window-state-event",
-                   G_CALLBACK (save_geometry), window);
-
   g_signal_connect (window, "realize",
                    G_CALLBACK (on_realize), window);
 
@@ -476,7 +468,7 @@ psppire_window_query_save (PsppireWindow *se)
                            GTK_DIALOG_MODAL,
                            GTK_MESSAGE_WARNING,
                            GTK_BUTTONS_NONE,
-                           _("Save the changes to \"%s\" before closing?"),
+                           _("Save the changes to `%s' before closing?"),
                            fn);
   g_free (fn);