X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fui%2Fgui%2Fpsppire-data-editor.c;h=094a4f6988ada771e840e81b037be42e9b5203db;hb=refs%2Fbuilds%2F20101211030502%2Fpspp;hp=aa511e937b69de617bcb4151a827dc971a53ce1e;hpb=66153a44d861ccddf6a176ec5a94ffb959232ad6;p=pspp diff --git a/src/ui/gui/psppire-data-editor.c b/src/ui/gui/psppire-data-editor.c index aa511e937b..094a4f6988 100644 --- a/src/ui/gui/psppire-data-editor.c +++ b/src/ui/gui/psppire-data-editor.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2008, 2009 Free Software Foundation, Inc. + Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc. 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,6 @@ #include "psppire-data-editor.h" #include "psppire-var-sheet.h" -#include #include "psppire-data-store.h" #include #include @@ -1249,21 +1248,13 @@ popup_cases_menu (PsppireSheet *sheet, gint row, static void do_sort (PsppireDataStore *ds, int var, gboolean descend) { - GString *string = g_string_new ("SORT CASES BY "); - const struct variable *v = psppire_dict_get_variable (ds->dict, var); + gchar *syntax; - g_string_append_printf (string, "%s", var_get_name (v)); - - if ( descend ) - g_string_append (string, " (D)"); - - g_string_append (string, "."); - - execute_syntax (create_syntax_string_source (string->str)); - - g_string_free (string, TRUE); + syntax = g_strdup_printf ("SORT CASES BY %s%s.", + var_get_name (v), descend ? " (D)" : ""); + g_free (execute_syntax_string (syntax)); } @@ -1568,43 +1559,45 @@ data_sheet_set_clip (PsppireSheet *sheet) struct case_map *map = NULL; casenumber max_rows; size_t max_columns; + gint row0, rowi; + gint col0, coli; ds = PSPPIRE_DATA_STORE (psppire_sheet_get_model (sheet)); psppire_sheet_get_selected_range (sheet, &range); + col0 = MIN (range.col0, range.coli); + coli = MAX (range.col0, range.coli); + row0 = MIN (range.row0, range.rowi); + rowi = MAX (range.row0, range.rowi); + /* If nothing selected, then use active cell */ - if ( range.row0 < 0 || range.col0 < 0 ) + if ( row0 < 0 || col0 < 0 ) { gint row, col; psppire_sheet_get_active_cell (sheet, &row, &col); - range.row0 = range.rowi = row; - range.col0 = range.coli = col; + row0 = rowi = row; + col0 = coli = col; } /* The sheet range can include cells that do not include data. Exclude them from the range. */ max_rows = psppire_data_store_get_case_count (ds); - if (range.rowi >= max_rows) + if (rowi >= max_rows) { if (max_rows == 0) return; - range.rowi = max_rows - 1; + rowi = max_rows - 1; } max_columns = dict_get_var_cnt (ds->dict->dict); - if (range.coli >= max_columns) + if (coli >= max_columns) { if (max_columns == 0) return; - range.coli = max_columns - 1; + coli = max_columns - 1; } - g_return_if_fail (range.rowi >= range.row0); - g_return_if_fail (range.row0 >= 0); - g_return_if_fail (range.coli >= range.col0); - g_return_if_fail (range.col0 >= 0); - /* Destroy any existing clip */ if ( clip_datasheet ) { @@ -1620,16 +1613,14 @@ data_sheet_set_clip (PsppireSheet *sheet) /* Construct clip dictionary. */ clip_dict = dict_create (); - for (i = range.col0; i <= range.coli; i++) - { - const struct variable *old = dict_get_var (ds->dict->dict, i); - dict_clone_var_assert (clip_dict, old, var_get_name (old)); - } + dict_set_encoding (clip_dict, dict_get_encoding (ds->dict->dict)); + for (i = col0; i <= coli; i++) + dict_clone_var_assert (clip_dict, dict_get_var (ds->dict->dict, i)); /* Construct clip data. */ map = case_map_by_name (ds->dict->dict, clip_dict); writer = autopaging_writer_create (dict_get_proto (clip_dict)); - for (i = range.row0; i <= range.rowi ; ++i ) + for (i = row0; i <= rowi ; ++i ) { struct ccase *old = psppire_data_store_get_case (ds, i); if (old != NULL) @@ -1653,14 +1644,13 @@ enum { /* Perform data_out for case CC, variable V, appending to STRING */ static void -data_out_g_string (GString *string, const struct dictionary *dict, - const struct variable *v, +data_out_g_string (GString *string, const struct variable *v, const struct ccase *cc) { const struct fmt_spec *fs = var_get_print_format (v); const union value *val = case_data (cc, v); - char *s = data_out (val, dict_get_encoding (dict), fs); + char *s = data_out (val, var_get_encoding (v), fs); g_string_append (string, s); @@ -1694,7 +1684,7 @@ clip_to_text (void) for (c = 0 ; c < var_cnt ; ++c) { const struct variable *v = dict_get_var (clip_dict, c); - data_out_g_string (string, clip_dict, v, cc); + data_out_g_string (string, v, cc); if ( c < val_cnt - 1 ) g_string_append (string, "\t"); } @@ -1719,9 +1709,11 @@ clip_to_html (void) const casenumber case_cnt = casereader_get_case_cnt (clip_datasheet); const size_t var_cnt = dict_get_var_cnt (clip_dict); - /* Guestimate the size needed */ - string = g_string_sized_new (20 * val_cnt * case_cnt); + string = g_string_sized_new (80 + 20 * val_cnt * case_cnt); + + g_string_append (string, + "\n"); g_string_append (string, "\n"); for (r = 0 ; r < case_cnt ; ++r ) @@ -1739,7 +1731,7 @@ clip_to_html (void) { const struct variable *v = dict_get_var (clip_dict, c); g_string_append (string, "\n"); }
"); - data_out_g_string (string, clip_dict, v, cc); + data_out_g_string (string, v, cc); g_string_append (string, "