X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-var-store.c;h=aadc585548582fc79629dca6b580e271ad6c7cde;hb=f8b5521cc615eeac897110ee13a44f49d63a21d9;hp=cdb32719eda7fe67888f4185b484d7f7827e2d39;hpb=8af88c0b7ea2fe75df7e45497988ed0371006a86;p=pspp-builds.git diff --git a/src/ui/gui/psppire-var-store.c b/src/ui/gui/psppire-var-store.c index cdb32719..aadc5855 100644 --- a/src/ui/gui/psppire-var-store.c +++ b/src/ui/gui/psppire-var-store.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2006 Free Software Foundation + Copyright (C) 2006, 2009 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 @@ -21,7 +21,7 @@ #define _(msgid) gettext (msgid) #define N_(msgid) msgid - +#include #include @@ -53,9 +53,6 @@ static void psppire_var_store_sheet_model_init (PsppireSheetModelIface * static void psppire_var_store_finalize (GObject *object); -gchar * missing_values_to_string (const struct variable *pv, GError **err); - - static gchar *psppire_var_store_get_string (const PsppireSheetModel *sheet_model, glong row, glong column); static gboolean psppire_var_store_clear (PsppireSheetModel *model, glong row, glong col); @@ -67,7 +64,8 @@ static gboolean psppire_var_store_set_string (PsppireSheetModel *model, static glong psppire_var_store_get_row_count (const PsppireSheetModel * model); static glong psppire_var_store_get_column_count (const PsppireSheetModel * model); -static gchar *text_for_column (const struct variable *pv, gint c, GError **err); +static gchar *text_for_column (PsppireVarStore *vs, const struct variable *pv, + gint c, GError **err); static GObjectClass *parent_class = NULL; @@ -191,7 +189,7 @@ psppire_var_store_class_init (PsppireVarStoreClass *class) "Variable format type", ("Whether variables have input or output " "formats"), - G_TYPE_PSPPIRE_VAR_STORE_FORMAT_TYPE, + PSPPIRE_TYPE_VAR_STORE_FORMAT_TYPE, PSPPIRE_VAR_STORE_OUTPUT_FORMATS, G_PARAM_READWRITE); @@ -301,6 +299,8 @@ psppire_var_store_sheet_model_init (PsppireSheetModelIface *iface) iface->get_row_title = get_row_title; iface->get_row_sensitivity = get_row_sensitivity; + + iface->get_row_overstrike = NULL; } /** @@ -397,7 +397,8 @@ psppire_var_store_finalize (GObject *object) } static gchar * -psppire_var_store_get_string (const PsppireSheetModel *model, glong row, glong column) +psppire_var_store_get_string (const PsppireSheetModel *model, + glong row, glong column) { PsppireVarStore *store = PSPPIRE_VAR_STORE (model); @@ -408,7 +409,7 @@ psppire_var_store_get_string (const PsppireSheetModel *model, glong row, glong c pv = psppire_dict_get_variable (store->dict, row); - return text_for_column (pv, column, 0); + return text_for_column (store, pv, column, 0); } @@ -465,8 +466,17 @@ psppire_var_store_set_string (PsppireSheetModel *model, switch (col) { case PSPPIRE_VAR_STORE_COL_NAME: - return psppire_dict_rename_var (var_store->dict, pv, text); - break; + { + gboolean ok; + char *s = recode_string (psppire_dict_encoding (var_store->dict), + UTF8, + text, -1); + + ok = psppire_dict_rename_var (var_store->dict, pv, s); + + free (s); + return ok; + } case PSPPIRE_VAR_STORE_COL_COLUMNS: if ( ! text) return FALSE; var_set_display_width (pv, atoi (text)); @@ -474,10 +484,19 @@ psppire_var_store_set_string (PsppireSheetModel *model, break; case PSPPIRE_VAR_STORE_COL_WIDTH: { - int width = atoi (text); - if ( ! text) return FALSE; + 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 @@ -520,8 +539,14 @@ psppire_var_store_set_string (PsppireSheetModel *model, } break; case PSPPIRE_VAR_STORE_COL_LABEL: - var_set_label (pv, text); - return TRUE; + { + gchar *s = recode_string (psppire_dict_encoding (var_store->dict), + UTF8, + text, -1); + var_set_label (pv, s); + free (s); + return TRUE; + } break; case PSPPIRE_VAR_STORE_COL_TYPE: case PSPPIRE_VAR_STORE_COL_VALUES: @@ -540,11 +565,13 @@ psppire_var_store_set_string (PsppireSheetModel *model, } -const static gchar none[] = N_("None"); +static const gchar none[] = N_("None"); static gchar * -text_for_column (const struct variable *pv, gint c, GError **err) +text_for_column (PsppireVarStore *vs, + const struct variable *pv, gint c, GError **err) { + PsppireDict *dict = vs->dict; static const gchar *const type_label[] = { N_("Numeric"), @@ -564,7 +591,8 @@ text_for_column (const struct variable *pv, gint c, GError **err) switch (c) { case PSPPIRE_VAR_STORE_COL_NAME: - return pspp_locale_to_utf8 ( var_get_name (pv), -1, err); + return recode_string (UTF8, psppire_dict_encoding (dict), + var_get_name (pv), -1); break; case PSPPIRE_VAR_STORE_COL_TYPE: { @@ -651,12 +679,13 @@ text_for_column (const struct variable *pv, gint c, GError **err) } break; case PSPPIRE_VAR_STORE_COL_LABEL: - return pspp_locale_to_utf8 (var_get_label (pv), -1, err); + return recode_string (UTF8, psppire_dict_encoding (dict), + var_get_label (pv), -1); break; case PSPPIRE_VAR_STORE_COL_MISSING: { - return missing_values_to_string (pv, err); + return missing_values_to_string (dict, pv, err); } break; case PSPPIRE_VAR_STORE_COL_VALUES: @@ -668,21 +697,22 @@ text_for_column (const struct variable *pv, gint c, GError **err) gchar *ss; GString *gstr = g_string_sized_new (10); const struct val_labs *vls = var_get_value_labels (pv); - struct val_labs_iterator *ip = 0; - struct val_lab *vl = val_labs_first_sorted (vls, &ip); + 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, *write_spec); - g_string_printf (gstr, "{%s,\"%s\"}_", vstr, vl->label); + g_string_printf (gstr, "{%s,\"%s\"}_", + vstr, val_lab_get_label (vl)); g_free (vstr); } - val_labs_done (&ip); - - ss = pspp_locale_to_utf8 (gstr->str, gstr->len, err); + ss = recode_string (UTF8, psppire_dict_encoding (dict), + gstr->str, gstr->len); g_string_free (gstr, TRUE); return ss; }