Add "dictionary" property to PsppireVarStore and use it.
[pspp-builds.git] / src / ui / gui / psppire-var-sheet.c
index a36bf6f933ddf30c77e83be06dd8d005933283ba..a4f082cca50bddb354b2559ce725896ba9c8c4fe 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008, 2009 Free Software Foundation, Inc.
 
    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
@@ -16,7 +16,7 @@
 
 #include <config.h>
 #include "psppire-var-sheet.h"
-#include <ui/gui/sheet/psppire-axis-impl.h>
+#include <ui/gui/sheet/psppire-axis.h>
 
 #include "helper.h"
 
@@ -31,6 +31,9 @@
 
 static void psppire_var_sheet_class_init  (PsppireVarSheetClass *klass);
 static void psppire_var_sheet_init        (PsppireVarSheet      *vs);
+static void psppire_var_sheet_realize     (GtkWidget *w);
+static void psppire_var_sheet_unrealize   (GtkWidget *w);
+
 
 enum
   {
@@ -121,9 +124,7 @@ create_label_list (const gchar *const *labels)
   gint i = 0;
   GtkTreeIter iter;
 
-  GtkListStore *list_store;
-  list_store = gtk_list_store_new (1, G_TYPE_STRING);
-
+  GtkListStore *list_store = gtk_list_store_new (1, G_TYPE_STRING);
 
   while ( (s = labels[i++]))
     {
@@ -178,17 +179,19 @@ psppire_var_sheet_get_property (GObject      *object,
 }
 
 
-
 static void
 psppire_var_sheet_class_init (PsppireVarSheetClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
   GParamSpec *pspec;
 
   parent_class = g_type_class_peek_parent (klass);
 
   object_class->dispose = psppire_var_sheet_dispose;
   object_class->finalize = psppire_var_sheet_finalize;
+  widget_class->realize = psppire_var_sheet_realize;
+  widget_class->unrealize = psppire_var_sheet_unrealize;
   object_class->set_property = psppire_var_sheet_set_property;
   object_class->get_property = psppire_var_sheet_get_property;
 
@@ -257,10 +260,10 @@ traverse_cell_callback (PsppireSheet *sheet,
 
       const gchar *name = gtk_entry_get_text (entry);
 
-      if (! psppire_dict_check_name (var_store->dict, name, TRUE))
+      if (! psppire_dict_check_name (var_store->dictionary, name, TRUE))
        return TRUE;
 
-      psppire_dict_insert_variable (var_store->dict, existing_cell->row, name);
+      psppire_dict_insert_variable (var_store->dictionary, existing_cell->row, name);
 
       return FALSE;
     }
@@ -275,7 +278,7 @@ traverse_cell_callback (PsppireSheet *sheet,
     {
       gint i;
       for ( i = n_vars ; i <= new_cell->row; ++i )
-       psppire_dict_insert_variable (var_store->dict, i, NULL);
+       psppire_dict_insert_variable (var_store->dictionary, i, NULL);
     }
 
   return FALSE;
@@ -283,7 +286,6 @@ traverse_cell_callback (PsppireSheet *sheet,
 
 
 
-
 /*
    Callback whenever the active cell changes on the var sheet.
 */
@@ -293,7 +295,6 @@ var_sheet_change_active_cell (PsppireVarSheet *vs,
                              gint oldrow, gint oldcolumn,
                              gpointer data)
 {
-  PsppireSheetCellAttr attributes;
   PsppireVarStore *var_store;
   PsppireVarSheetClass *vs_class =
     PSPPIRE_VAR_SHEET_CLASS(G_OBJECT_GET_CLASS (vs));
@@ -310,8 +311,6 @@ var_sheet_change_active_cell (PsppireVarSheet *vs,
   g_return_if_fail (oldcolumn == PSPPIRE_VAR_STORE_COL_NAME ||
                    row < psppire_var_store_get_var_cnt (var_store));
 
-  psppire_sheet_get_attributes (sheet, row, column, &attributes);
-
   var = psppire_var_store_get_var (var_store, row);
 
   switch (column)
@@ -332,7 +331,7 @@ var_sheet_change_active_cell (PsppireVarSheet *vs,
 
        gtk_combo_box_entry_set_text_column (cbe, 0);
 
-       g_signal_connect (G_OBJECT (cbe),"changed",
+       g_signal_connect (cbe, "changed",
                         G_CALLBACK (change_alignment), var);
       }
       break;
@@ -350,7 +349,7 @@ var_sheet_change_active_cell (PsppireVarSheet *vs,
 
        gtk_combo_box_entry_set_text_column (cbe, 0);
 
-       g_signal_connect (G_OBJECT (cbe),"changed",
+       g_signal_connect (cbe, "changed",
                          G_CALLBACK (change_measure), var);
       }
       break;
@@ -364,11 +363,6 @@ var_sheet_change_active_cell (PsppireVarSheet *vs,
        customEntry =
          PSPPIRE_CUSTOM_ENTRY (psppire_sheet_get_entry (sheet));
 
-       if ( var_is_long_string (var))
-         g_object_set (customEntry,
-                       "editable", FALSE,
-                       NULL);
-
        val_labs_dialog_set_target_variable (vs->val_labs_dialog, var);
 
        g_signal_connect_swapped (customEntry,
@@ -387,15 +381,11 @@ var_sheet_change_active_cell (PsppireVarSheet *vs,
        customEntry =
          PSPPIRE_CUSTOM_ENTRY (psppire_sheet_get_entry (sheet));
 
-       if ( var_is_long_string (var))
-         g_object_set (customEntry,
-                       "editable", FALSE,
-                       NULL);
-
-
        vs->missing_val_dialog->pv =
          psppire_var_store_get_var (var_store, row);
 
+       vs->missing_val_dialog->dict = var_store->dictionary;
+
        g_signal_connect_swapped (customEntry,
                                  "clicked",
                                  G_CALLBACK (missing_val_dialog_show),
@@ -427,7 +417,8 @@ var_sheet_change_active_cell (PsppireVarSheet *vs,
     case PSPPIRE_VAR_STORE_COL_DECIMALS:
     case PSPPIRE_VAR_STORE_COL_COLUMNS:
       {
-       if ( attributes.is_editable)
+       if ( psppire_sheet_model_is_editable (PSPPIRE_SHEET_MODEL(var_store),
+                                             row, column))
          {
            gint r_min, r_max;
 
@@ -482,14 +473,44 @@ var_sheet_change_active_cell (PsppireVarSheet *vs,
 }
 
 
+static void
+psppire_var_sheet_realize (GtkWidget *w)
+{
+  PsppireVarSheet *vs = PSPPIRE_VAR_SHEET (w);
+
+  GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (vs));
+
+  vs->val_labs_dialog = val_labs_dialog_create (GTK_WINDOW (toplevel),
+                                               PSPPIRE_VAR_STORE (psppire_sheet_get_model (PSPPIRE_SHEET (vs))));
+
+  vs->missing_val_dialog = missing_val_dialog_create (GTK_WINDOW (toplevel));
+  vs->var_type_dialog = var_type_dialog_create (GTK_WINDOW (toplevel));
+
+  /* Chain up to the parent class */
+  GTK_WIDGET_CLASS (parent_class)->realize (w);
+}
+
+static void
+psppire_var_sheet_unrealize (GtkWidget *w)
+{
+  PsppireVarSheet *vs = PSPPIRE_VAR_SHEET (w);
+
+  g_free (vs->val_labs_dialog);
+  g_free (vs->missing_val_dialog);
+  g_free (vs->var_type_dialog);
+
+  /* Chain up to the parent class */
+  GTK_WIDGET_CLASS (parent_class)->unrealize (w);
+}
+
+
+
 static void
 psppire_var_sheet_init (PsppireVarSheet *vs)
 {
   GtkBuilder *builder = builder_new ("data-editor.ui");
 
-  vs->val_labs_dialog = val_labs_dialog_create (builder);
-  vs->missing_val_dialog = missing_val_dialog_create (builder);
-  vs->var_type_dialog = var_type_dialog_create (builder);
+  connect_help (builder);
 
   g_object_unref (builder);
 
@@ -522,13 +543,13 @@ GtkWidget*
 psppire_var_sheet_new (void)
 {
   gint i;
-  PsppireAxisImpl *ha = psppire_axis_impl_new ();
-  PsppireAxisImpl *va = psppire_axis_impl_new ();
+  PsppireAxis *ha = psppire_axis_new ();
+  PsppireAxis *va = psppire_axis_new ();
 
   GtkWidget *w = g_object_new (psppire_var_sheet_get_type (), NULL);
 
   for (i = 0 ; i < 10 ; ++i)
-    psppire_axis_impl_append (ha, column_def[i].width);
+    psppire_axis_append (ha, column_def[i].width);
 
   g_object_set (va,
                "default-size", 25,