+static gint
+__tree_model_iter_n_children (GtkTreeModel *tree_model,
+ GtkTreeIter *iter)
+{
+ PsppireDataStore *store = PSPPIRE_DATA_STORE (tree_model);
+
+ if (store->datasheet == NULL)
+ return 0;
+
+ gint n = datasheet_get_n_rows (store->datasheet);
+
+ return n;
+}
+
+static GtkTreeModelFlags
+__tree_model_get_flags (GtkTreeModel *model)
+{
+ g_return_val_if_fail (PSPPIRE_IS_DATA_STORE (model), (GtkTreeModelFlags) 0);
+
+ return GTK_TREE_MODEL_LIST_ONLY;
+}
+
+static gint
+__tree_model_get_n_columns (GtkTreeModel *tree_model)
+{
+ PsppireDataStore *store = PSPPIRE_DATA_STORE (tree_model);
+
+ return psppire_dict_get_var_cnt (store->dict);
+}
+
+
+static gboolean
+__iter_nth_child (GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ GtkTreeIter *parent,
+ gint n)
+{
+ PsppireDataStore *store = PSPPIRE_DATA_STORE (tree_model);
+
+ g_assert (parent == NULL);
+ g_return_val_if_fail (store, FALSE);
+
+ if (!store->datasheet || n >= datasheet_get_n_rows (store->datasheet))
+ {
+ iter->stamp = -1;
+ iter->user_data = NULL;
+ return FALSE;
+ }
+
+ iter->user_data = GINT_TO_POINTER (n);
+ iter->stamp = store->stamp;
+
+ return TRUE;
+}
+
+/* Set the contents of OUT to reflect the information provided by IN, COL, and
+ ROW, for MODEL. Returns TRUE if successful. */
+gboolean
+psppire_data_store_string_to_value (GtkTreeModel *model, gint col, gint row,
+ const gchar *in, GValue *out)
+{
+ PsppireDataStore *store = PSPPIRE_DATA_STORE (model);
+
+ while (col >= psppire_dict_get_var_cnt (store->dict))
+ {
+ const struct variable *var =
+ psppire_dict_insert_variable (store->dict,
+ psppire_dict_get_var_cnt (store->dict),
+ NULL);
+ g_return_val_if_fail (var, FALSE);
+ }
+
+ const struct variable *variable = psppire_dict_get_variable (store->dict, col);
+ g_return_val_if_fail (variable, FALSE);
+
+ const struct fmt_spec *fmt = var_get_print_format (variable);
+
+ int width = var_get_width (variable);
+
+ union value val;
+ value_init (&val, width);
+ char *xx =
+ data_in (ss_cstr (in), psppire_dict_encoding (store->dict),
+ fmt->type, &val, width, "UTF-8");
+
+ GVariant *vrnt = value_variant_new (&val, width);
+ value_destroy (&val, width);
+
+ g_value_init (out, G_TYPE_VARIANT);
+ g_value_set_variant (out, vrnt);
+ free (xx);
+ return TRUE;
+}
+
+static char *
+unlabeled_value (PsppireDataStore *store, const struct variable *variable, const union value *val)
+{
+ const struct fmt_spec *fmt = var_get_print_format (variable);
+ return data_out (val, psppire_dict_encoding (store->dict), fmt);
+}
+
+gchar *
+psppire_data_store_value_to_string (gpointer unused, PsppireDataStore *store, gint col, gint row, const GValue *v)
+{
+ const struct variable *variable = psppire_dict_get_variable (store->dict, col);
+ g_return_val_if_fail (variable, g_strdup ("???"));
+
+ GVariant *vrnt = g_value_get_variant (v);
+ union value val;
+ value_variant_get (&val, vrnt);
+
+ char *out = unlabeled_value (store, variable, &val);
+
+ value_destroy_from_variant (&val, vrnt);
+
+ return out;
+}
+
+gchar *
+psppire_data_store_value_to_string_with_labels (gpointer unused, PsppireDataStore *store, gint col, gint row, const GValue *v)
+{
+ const struct variable *variable = psppire_dict_get_variable (store->dict, col);
+ g_return_val_if_fail (variable, g_strdup ("???"));
+
+ GVariant *vrnt = g_value_get_variant (v);
+ union value val;
+ value_variant_get (&val, vrnt);
+
+ char *out = NULL;
+
+ const struct val_labs *vls = var_get_value_labels (variable);
+ struct val_lab *vl = val_labs_lookup (vls, &val);
+ if (vl != NULL)
+ out = strdup (val_lab_get_label (vl));
+ else
+ out = unlabeled_value (store, variable, &val);
+
+ value_destroy_from_variant (&val, vrnt);
+
+ return out;
+}
+
+static void
+__get_value (GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ gint column,
+ GValue *value)
+{
+ PsppireDataStore *store = PSPPIRE_DATA_STORE (tree_model);
+
+ g_return_if_fail (iter->stamp == store->stamp);
+
+ const struct variable *variable = psppire_dict_get_variable (store->dict, column);
+ if (NULL == variable)
+ return;
+
+ g_value_init (value, G_TYPE_VARIANT);
+
+ gint row = GPOINTER_TO_INT (iter->user_data);
+
+ struct ccase *cc = datasheet_get_row (store->datasheet, row);
+
+ const union value *val = case_data_idx (cc, var_get_case_index (variable));
+
+ GVariant *vv = value_variant_new (val, var_get_width (variable));
+
+ g_value_set_variant (value, vv);