X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-data-store.c;h=8832e5175e73160989175ff255be8c9dc73af7c7;hb=870b099b7272c4440f9df2a0741902f035af3f51;hp=f3543f13f1c65551bb3fae638daff4be93903e1e;hpb=1641c5707278765ec595bda341378aa7c6bec152;p=pspp diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index f3543f13f1..8832e5175e 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2006, 2008, 2009, 2010, 2011, 2012 Free Software Foundation + Copyright (C) 2006, 2008, 2009, 2010, 2011, 2012, 2013 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 @@ -205,6 +205,7 @@ delete_variable_callback (GObject *obj, const struct variable *var UNUSED, { PsppireDataStore *store = PSPPIRE_DATA_STORE (data); + g_return_if_fail (store->datasheet); datasheet_delete_columns (store->datasheet, case_index, 1); datasheet_insert_column (store->datasheet, NULL, -1, case_index); @@ -212,27 +213,24 @@ delete_variable_callback (GObject *obj, const struct variable *var UNUSED, struct resize_datum_aux { - int old_width; - int new_width; + const struct dictionary *dict; + const struct variable *new_variable; + const struct variable *old_variable; }; static void -resize_datum (const union value *old, union value *new, void *aux_) +resize_datum (const union value *old, union value *new, const void *aux_) { - struct resize_datum_aux *aux = aux_; - - if (aux->new_width == 0) - { - /* FIXME: try to parse string as number. */ - new->f = SYSMIS; - } - else if (aux->old_width == 0) - { - /* FIXME: format number as string. */ - value_set_missing (new, aux->new_width); - } - else - value_copy_rpad (new, aux->new_width, old, aux->old_width, ' '); + const struct resize_datum_aux *aux = aux_; + int new_width = var_get_width (aux->new_variable); + const char *enc = dict_get_encoding (aux->dict); + const struct fmt_spec *newfmt = var_get_print_format (aux->new_variable); + char *s = data_out (old, enc, var_get_print_format (aux->old_variable)); + enum fmt_type type = (fmt_usable_for_input (newfmt->type) + ? newfmt->type + : FMT_DOLLAR); + free (data_in (ss_cstr (s), enc, type, new, new_width, enc)); + free (s); } static void @@ -246,9 +244,10 @@ variable_changed_callback (GObject *obj, gint var_num, guint what, const struct { int posn = var_get_case_index (variable); struct resize_datum_aux aux; - aux.old_width = var_get_width (oldvar); - aux.new_width = var_get_width (variable); - datasheet_resize_column (store->datasheet, posn, aux.new_width, + aux.old_variable = oldvar; + aux.new_variable = variable; + aux.dict = store->dict->dict; + datasheet_resize_column (store->datasheet, posn, var_get_width (variable), resize_datum, &aux); } } @@ -394,6 +393,7 @@ psppire_data_store_dispose (GObject *object) if (ds->dispose_has_run) return; + psppire_data_store_set_dictionary (ds, NULL); /* must chain up */ (* parent_class->dispose) (object); @@ -436,6 +436,7 @@ psppire_data_store_get_string (PsppireDataStore *store, int width; g_return_val_if_fail (store != NULL, NULL); + g_return_val_if_fail (store->datasheet != NULL, NULL); g_return_val_if_fail (var != NULL, NULL); if (row < 0 || row >= datasheet_get_n_rows (store->datasheet))