Made cell reference label take proper offset.
[pspp-builds.git] / src / ui / gui / data-editor.c
index 63a19a63a1ce2a8c19b8e8b338885136f95bb927..30e587ef5cb2dbafabf2e12fd481bc9850c58fcc 100644 (file)
@@ -1,21 +1,18 @@
-/*
-    PSPPIRE --- A Graphical User Interface for PSPP
-    Copyright (C) 2006, 2007  Free Software Foundation
+/* 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 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/>. */
 
 #include <config.h>
 #include <stdlib.h>
@@ -1287,7 +1284,8 @@ update_data_ref_entry (const GtkSheet *sheet, gint row, gint col, gpointer data)
 {
   GladeXML *data_editor_xml = data;
 
-  PsppireDataStore *data_store = PSPPIRE_DATA_STORE (gtk_sheet_get_model (sheet));
+  PsppireDataStore *data_store =
+    PSPPIRE_DATA_STORE (gtk_sheet_get_model (sheet));
 
   g_return_val_if_fail (data_editor_xml, FALSE);
 
@@ -1296,38 +1294,44 @@ update_data_ref_entry (const GtkSheet *sheet, gint row, gint col, gpointer data)
       const struct variable *var =
        psppire_dict_get_variable (data_store->dict, col);
 
-      {
-       /* The entry where the reference to the current cell is displayed */
-       GtkEntry *cell_ref_entry =
-         GTK_ENTRY (get_widget_assert (data_editor_xml,
-                                       "cell_ref_entry"));
+      /* The entry where the reference to the current cell is displayed */
+      GtkEntry *cell_ref_entry =
+       GTK_ENTRY (get_widget_assert (data_editor_xml,
+                                     "cell_ref_entry"));
+      GtkEntry *datum_entry =
+       GTK_ENTRY (get_widget_assert (data_editor_xml,
+                                     "datum_entry"));
 
-       gchar *text = g_strdup_printf ("%d: %s", row,
-                                      var ? var_get_name (var) : "");
+      if ( var )
+       {
+         gchar *text = g_strdup_printf ("%d: %s", row + FIRST_CASE_NUMBER,
+                                        var_get_name (var));
 
-       gchar *s = pspp_locale_to_utf8 (text, -1, 0);
+         gchar *s = pspp_locale_to_utf8 (text, -1, 0);
 
-       g_free (text);
+         g_free (text);
 
-       gtk_entry_set_text (cell_ref_entry, s);
+         gtk_entry_set_text (cell_ref_entry, s);
 
-       g_free (s);
-      }
+         g_free (s);
+       }
+      else
+       gtk_entry_set_text (cell_ref_entry, "");
 
-      {
-       GtkEntry *datum_entry =
-         GTK_ENTRY (get_widget_assert (data_editor_xml,
-                                       "datum_entry"));
 
-       gchar *text =
-         psppire_data_store_get_string (data_store, row,
-                                        var_get_dict_index(var));
-       g_strchug (text);
+      if ( var )
+       {
+         gchar *text =
+           psppire_data_store_get_string (data_store, row,
+                                          var_get_dict_index(var));
+         g_strchug (text);
 
-       gtk_entry_set_text (datum_entry, text);
+         gtk_entry_set_text (datum_entry, text);
 
-       free (text);
-      }
+         free (text);
+       }
+      else
+       gtk_entry_set_text (datum_entry, "");
     }
 
   return FALSE;