Change license from GPLv2+ to GPLv3+.
[pspp-builds.git] / src / ui / gui / val-labs-dialog.c
index 3918f2f2553314be3cc03686d10e24cafe8a10da..05068d0f964523a91df558a58230c8c928ebcb56 100644 (file)
@@ -1,21 +1,18 @@
-/*
-    PSPPIRE --- A Graphical User Interface for PSPP
-    Copyright (C) 2005  Free Software Foundation
+/* PSPPIRE - a graphical user interface for PSPP.
+   Copyright (C) 2005  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 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 3 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.
+   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. */
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 
 /*  This module describes the behaviour of the Value Labels dialog box,
 #include "val-labs-dialog.h"
 #include <data/value-labels.h>
 
+
+struct val_labs_dialog
+{
+  GtkWidget *window;
+
+  /* The variable to be updated */
+  struct variable *pv;
+
+  /* Local copy of labels */
+  struct val_labs *labs;
+
+  /* Actions */
+  GtkWidget *add_button;
+  GtkWidget *remove_button;
+  GtkWidget *change_button;
+
+  /* Entry Boxes */
+  GtkWidget *value_entry;
+  GtkWidget *label_entry;
+
+  /* Signal handler ids */
+  gint change_handler_id;
+  gint value_handler_id;
+
+  GtkWidget *treeview;
+};
+
+
 /* This callback occurs when the text in the label entry box
    is changed */
 static void
@@ -152,23 +177,50 @@ val_labs_ok (GtkWidget *w, gpointer data)
 
   dialog->labs = 0;
 
+  gtk_widget_hide (dialog->window);
+
   return FALSE;
 }
 
+/* Callback for when the Value Labels dialog is closed using
+   the Cancel button.*/
+static void
+val_labs_cancel (struct val_labs_dialog *dialog)
+{
+  val_labs_destroy (dialog->labs);
+
+  dialog->labs = 0;
+
+  gtk_widget_hide (dialog->window);
+}
+
+
 /* Callback for when the Value Labels dialog is closed using
    the Cancel button.*/
 static gint
-val_labs_cancel (GtkWidget *w, gpointer data)
+on_cancel (GtkWidget *w, gpointer data)
 {
   struct val_labs_dialog *dialog = data;
 
-  val_labs_destroy (dialog->labs);
-  dialog->labs = 0;
+  val_labs_cancel (dialog);
 
   return FALSE;
 }
 
 
+/* Callback for when the Value Labels dialog is closed using
+   the window delete button.*/
+static gint
+on_delete (GtkWidget *w, GdkEvent *e, gpointer data)
+{
+  struct val_labs_dialog *dialog = data;
+
+  val_labs_cancel (dialog);
+
+  return TRUE;
+}
+
+
 /* Return the value-label pair currently selected in the dialog box  */
 static struct val_lab *
 get_selected_tuple (struct val_labs_dialog *dialog)
@@ -316,6 +368,8 @@ val_labs_dialog_create (GladeXML *xml)
 
   struct val_labs_dialog *dialog = g_malloc (sizeof (*dialog));
 
+  connect_help (xml);
+
   dialog->window = get_widget_assert (xml,"val_labs_dialog");
   dialog->value_entry = get_widget_assert (xml,"value_entry");
   dialog->label_entry = get_widget_assert (xml,"label_entry");
@@ -324,7 +378,6 @@ val_labs_dialog_create (GladeXML *xml)
     (GTK_WINDOW (dialog->window),
      GTK_WINDOW (get_widget_assert (xml, "data_editor")));
 
-  dialog->ok = get_widget_assert (xml, "val_labs_ok");
   dialog->add_button = get_widget_assert (xml, "val_labs_add");
   dialog->remove_button = get_widget_assert (xml, "val_labs_remove");
   dialog->change_button = get_widget_assert (xml, "val_labs_change");
@@ -345,7 +398,14 @@ val_labs_dialog_create (GladeXML *xml)
 
   g_signal_connect (GTK_OBJECT (get_widget_assert (xml, "val_labs_cancel")),
                   "clicked",
-                  GTK_SIGNAL_FUNC (val_labs_cancel), dialog);
+                  GTK_SIGNAL_FUNC (on_cancel), dialog);
+
+  g_signal_connect (GTK_OBJECT (dialog->window), "delete-event",
+                   GTK_SIGNAL_FUNC (on_delete), dialog);
+
+  g_signal_connect (GTK_OBJECT (get_widget_assert (xml, "val_labs_ok")),
+                  "clicked",
+                  GTK_SIGNAL_FUNC (val_labs_ok), dialog);
 
   dialog->change_handler_id =
     g_signal_connect (GTK_OBJECT (dialog->label_entry),
@@ -362,19 +422,12 @@ val_labs_dialog_create (GladeXML *xml)
                   GTK_SIGNAL_FUNC (on_change), dialog);
 
 
-  g_signal_connect (GTK_OBJECT (get_widget_assert (xml, "val_labs_ok")),
-                  "clicked",
-                  GTK_SIGNAL_FUNC (val_labs_ok), dialog);
-
-
   g_signal_connect (GTK_OBJECT (dialog->treeview), "cursor-changed",
                   GTK_SIGNAL_FUNC (on_select_row), dialog);
 
-
   g_signal_connect (GTK_OBJECT (dialog->remove_button), "clicked",
                   GTK_SIGNAL_FUNC (on_remove), dialog);
 
-
   g_signal_connect (GTK_OBJECT (dialog->add_button), "clicked",
                   GTK_SIGNAL_FUNC (on_add), dialog);
 
@@ -384,6 +437,15 @@ val_labs_dialog_create (GladeXML *xml)
 }
 
 
+void
+val_labs_dialog_set_target_variable (struct val_labs_dialog *dialog,
+                                    struct variable *var)
+{
+  dialog->pv = var;
+}
+
+
+
 /* Populate the components of the dialog box, from the 'labs' member
    variable */
 static void