X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-data-store.c;h=116092fd77a139193f10e5f3d9b7b76b63d4d3cb;hb=c21a0f82e238fe80b61d8ab00e21ec32c753ca2f;hp=0cb719046eab964b9a78dc584c628735019979da;hpb=a55b554c0479168ef3e4879fe0fa517f7ca4def7;p=pspp-builds.git diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index 0cb71904..116092fd 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -29,6 +29,7 @@ #include "psppire-variable.h" #include "psppire-data-store.h" +#include "helper.h" #include #include @@ -48,7 +49,7 @@ static void psppire_data_store_sheet_model_init (GSheetModelIface *iface); static void psppire_data_store_sheet_column_init (GSheetColumnIface *iface); static void psppire_data_store_finalize (GObject *object); -static const gchar *const psppire_data_store_get_string(GSheetModel *sheet_model, gint row, gint column); +static const gchar *psppire_data_store_get_string(GSheetModel *sheet_model, gint row, gint column); static gboolean psppire_data_store_set_string(GSheetModel *model, const gchar *text, gint row, gint column); @@ -147,6 +148,7 @@ psppire_data_store_get_font_desc(GSheetModel *model, static void psppire_data_store_sheet_model_init (GSheetModelIface *iface) { + iface->free_strings = TRUE; iface->get_string = psppire_data_store_get_string; iface->set_string = psppire_data_store_set_string; iface->clear_datum = psppire_data_store_clear_datum; @@ -185,14 +187,15 @@ static void insert_case_callback(GtkWidget *w, gint casenum, gpointer data) { PsppireDataStore *store ; + g_return_if_fail (data); store = PSPPIRE_DATA_STORE(data); g_sheet_model_range_changed (G_SHEET_MODEL(store), - casenum, -1, - psppire_case_array_get_n_cases(store->cases), - -1); + casenum, -1, + psppire_case_array_get_n_cases(store->cases), + -1); } @@ -326,10 +329,10 @@ psppire_data_store_finalize (GObject *object) } -static const gchar *const +static const gchar * psppire_data_store_get_string(GSheetModel *model, gint row, gint column) { - + const char *text; const struct fmt_spec *fp ; const struct PsppireVariable *pv ; const union value *v ; @@ -358,40 +361,29 @@ psppire_data_store_get_string(GSheetModel *model, gint row, gint column) const gchar *label; if ( (label = val_labs_find(vl, *v)) ) { - return label; + return pspp_locale_to_utf8(label, -1, 0); } } fp = psppire_variable_get_write_spec(pv); - s = g_string_sized_new (fp->w); + s = g_string_sized_new (fp->w + 1); + g_string_set_size(s, fp->w); + + memset(s->str, 0, fp->w); + + g_assert(fp->w == s->len); /* Converts binary value V into printable form in the exactly FP->W character in buffer S according to format specification FP. No null terminator is appended to the buffer. */ data_out (s->str, fp, v); - return g_string_free(s, FALSE); -#if 0 - { - static gchar buf[255]; - GError *err = NULL; - gchar *text = g_locale_to_utf8(s, fp->w, 0, 0, &err); - if ( !err ) - { - g_snprintf(buf, 255, text); - g_free(text); - } - else - { - g_warning("Cannot convert string \"%s\" to utf-8: %s\n", s, err->message); - g_error_free(err); - return NULL; - } + + text = pspp_locale_to_utf8(s->str, fp->w, 0); + g_string_free(s, TRUE); - return buf ; - } -#endif + return text; } @@ -462,7 +454,7 @@ psppire_data_store_set_string(GSheetModel *model, for(r = psppire_case_array_get_n_cases(store->cases) ; r <= row ; ++r ) { gint c; - psppire_case_array_insert_case(store->cases, r); + psppire_case_array_insert_case(store->cases, r, 0, 0); for (c = 0 ; c < psppire_dict_get_var_cnt(store->dict); ++c ) psppire_data_store_clear_datum(model, r, c); @@ -653,15 +645,18 @@ static const gchar null_var_name[]=_("var"); static const gchar * geometry_get_button_label(const GSheetColumn *geom, gint unit) { + const gchar *text; struct PsppireVariable *pv ; PsppireDataStore *ds = PSPPIRE_DATA_STORE(geom); if ( unit >= psppire_dict_get_var_cnt(ds->dict) ) - return null_var_name; + return pspp_locale_to_utf8(null_var_name, -1, 0); pv = psppire_dict_get_variable(ds->dict, unit); - return psppire_variable_get_name(pv); + text = pspp_locale_to_utf8(psppire_variable_get_name(pv), -1, 0); + + return text; }