-static gchar *
-psppire_var_store_get_string (const PsppireSheetModel *model,
- glong row, glong column)
-{
- PsppireVarStore *store = PSPPIRE_VAR_STORE (model);
-
- struct variable *pv;
-
- if ( row >= psppire_dict_get_var_cnt (store->dictionary))
- return 0;
-
- pv = psppire_dict_get_variable (store->dictionary, row);
-
- return text_for_column (store, pv, column, 0);
-}
-
-
-/* Clears that part of the variable store, if possible, which corresponds
- to ROW, COL.
- Returns true if anything was updated, false otherwise.
-*/
-static gboolean
-psppire_var_store_clear (PsppireSheetModel *model, glong row, glong col)
-{
- struct variable *pv ;
-
- PsppireVarStore *var_store = PSPPIRE_VAR_STORE (model);
-
- if ( row >= psppire_dict_get_var_cnt (var_store->dictionary))
- return FALSE;
-
- pv = psppire_var_store_get_var (var_store, row);
-
- if ( !pv )
- return FALSE;
-
- switch (col)
- {
- case PSPPIRE_VAR_STORE_COL_LABEL:
- var_clear_label (pv);
- return TRUE;
- break;
- }
-
- return FALSE;
-}
-
-/* Attempts to update that part of the variable store which corresponds
- to ROW, COL with the value TEXT.
- Returns true if anything was updated, false otherwise.
-*/
-static gboolean
-psppire_var_store_set_string (PsppireSheetModel *model,
- const gchar *text, glong row, glong col)
-{
- struct variable *pv ;
-
- PsppireVarStore *var_store = PSPPIRE_VAR_STORE (model);
-
- if ( row >= psppire_dict_get_var_cnt (var_store->dictionary))
- return FALSE;
-
- pv = psppire_var_store_get_var (var_store, row);
-
- if ( !pv )
- return FALSE;
-
- switch (col)
- {
- case PSPPIRE_VAR_STORE_COL_NAME:
- {
- gboolean ok;
- ok = psppire_dict_rename_var (var_store->dictionary, pv, text);
- return ok;
- }
- case PSPPIRE_VAR_STORE_COL_COLUMNS:
- if ( ! text) return FALSE;
- var_set_display_width (pv, atoi (text));
- return TRUE;
- break;
- case PSPPIRE_VAR_STORE_COL_WIDTH:
- {
- const int width = atoi (text);
- if ( ! text)
- return FALSE;
-
- if (width < 0)
- return FALSE;
-
- if ( var_is_alpha (pv))
- {
- if ( width > MAX_STRING )
- return FALSE;
- var_set_width (pv, width);
- }
- else
- {
- bool for_input
- = var_store->format_type == PSPPIRE_VAR_STORE_INPUT_FORMATS;
- struct fmt_spec fmt ;
- fmt = *var_get_print_format (pv);
- if ( width < fmt_min_width (fmt.type, for_input)
- ||
- width > fmt_max_width (fmt.type, for_input))
- return FALSE;
-
- fmt.w = width;
- fmt.d = MIN (fmt_max_decimals (fmt.type, width, for_input), fmt.d);
-
- var_set_both_formats (pv, &fmt);
- }
-
- return TRUE;
- }
- break;
- case PSPPIRE_VAR_STORE_COL_DECIMALS:
- {
- bool for_input
- = var_store->format_type == PSPPIRE_VAR_STORE_INPUT_FORMATS;
- int decimals;
- struct fmt_spec fmt;
- if ( ! text) return FALSE;
- decimals = atoi (text);
- fmt = *var_get_print_format (pv);
- if ( decimals >
- fmt_max_decimals (fmt.type,
- fmt.w,
- for_input
- ))
- return FALSE;
-
- fmt.d = decimals;
- var_set_both_formats (pv, &fmt);
- return TRUE;
- }
- break;
- case PSPPIRE_VAR_STORE_COL_LABEL:
- {
- var_set_label (pv, text, true);
- return TRUE;
- }
- break;
- case PSPPIRE_VAR_STORE_COL_TYPE:
- case PSPPIRE_VAR_STORE_COL_VALUES:
- case PSPPIRE_VAR_STORE_COL_MISSING:
- case PSPPIRE_VAR_STORE_COL_ALIGN:
- case PSPPIRE_VAR_STORE_COL_MEASURE:
- /* These can be modified only by their respective dialog boxes */
- return FALSE;
- break;
- default:
- g_assert_not_reached ();
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-static const gchar none[] = N_("None");
-
-static gchar *
-text_for_column (PsppireVarStore *vs,
- const struct variable *pv, gint c, GError **err)
-{
- PsppireDict *dict = vs->dictionary;
-
- const struct fmt_spec *format = var_get_print_format (pv);
-
- switch (c)
- {
- case PSPPIRE_VAR_STORE_COL_NAME:
- return xstrdup (var_get_name (pv));
- break;
- case PSPPIRE_VAR_STORE_COL_TYPE:
- return xstrdup (fmt_gui_name (format->type));
- break;
- case PSPPIRE_VAR_STORE_COL_WIDTH:
- {
- gchar *s;
- GString *gstr = g_string_sized_new (10);
- g_string_printf (gstr, _("%d"), format->w);
- s = g_locale_to_utf8 (gstr->str, gstr->len, 0, 0, err);
- g_string_free (gstr, TRUE);
- return s;
- }
- break;
- case PSPPIRE_VAR_STORE_COL_DECIMALS:
- {
- gchar *s;
- GString *gstr = g_string_sized_new (10);
- g_string_printf (gstr, _("%d"), format->d);
- s = g_locale_to_utf8 (gstr->str, gstr->len, 0, 0, err);
- g_string_free (gstr, TRUE);
- return s;
- }
- break;
- case PSPPIRE_VAR_STORE_COL_COLUMNS:
- {
- gchar *s;
- GString *gstr = g_string_sized_new (10);
- g_string_printf (gstr, _("%d"), var_get_display_width (pv));
- s = g_locale_to_utf8 (gstr->str, gstr->len, 0, 0, err);
- g_string_free (gstr, TRUE);
- return s;
- }
- break;
- case PSPPIRE_VAR_STORE_COL_LABEL:
- {
- const char *label = var_get_label (pv);
- if (label)
- return xstrdup (label);
- return NULL;
- }
- break;
-
- case PSPPIRE_VAR_STORE_COL_MISSING:
- {
- return missing_values_to_string (dict, pv, err);
- }
- break;
- case PSPPIRE_VAR_STORE_COL_VALUES:
- {
- if ( ! var_has_value_labels (pv))
- return xstrdup (gettext (none));
- else
- {
- const struct val_labs *vls = var_get_value_labels (pv);
- const struct val_lab **labels = val_labs_sorted (vls);
- const struct val_lab *vl = labels[0];
- free (labels);
-
- g_assert (vl);
-
- {
- gchar *const vstr = value_to_text (vl->value, pv);
-
- return g_strdup_printf (_("{%s,`%s'}_"), vstr,
- val_lab_get_escaped_label (vl));
- }
- }
- }
- break;
- case PSPPIRE_VAR_STORE_COL_ALIGN:
- {
- const gint align = var_get_alignment (pv);
-
- g_assert (align < n_ALIGNMENTS);
- return xstrdup (alignment_to_string (align));
- }
- break;
- case PSPPIRE_VAR_STORE_COL_MEASURE:
- {
- return xstrdup (measure_to_string (var_get_measure (pv)));
- }
- break;
- }
- return 0;
-}
-
-
-