From: John Darrington Date: Tue, 28 Jul 2009 10:55:23 +0000 (+0200) Subject: Allow ranges with left to right and bottom to top sense to be selected. X-Git-Tag: build37~22 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77ce797fbee4ea815123f46f2dbdad589fd608a2;p=pspp-builds.git Allow ranges with left to right and bottom to top sense to be selected. --- diff --git a/lib/gtk-contrib/psppire-sheet.c b/lib/gtk-contrib/psppire-sheet.c index 8122eba9..63307d8f 100644 --- a/lib/gtk-contrib/psppire-sheet.c +++ b/lib/gtk-contrib/psppire-sheet.c @@ -388,29 +388,32 @@ POSSIBLE_RESIZE (const PsppireSheet *sheet, gint x, gint y, static gboolean -rectangle_from_range (PsppireSheet *sheet, const PsppireSheetRange *input, +rectangle_from_range (PsppireSheet *sheet, const PsppireSheetRange *range, GdkRectangle *r) { - PsppireSheetRange range = *input; + gint col0 = MIN (range->col0, range->coli); + gint coli = MAX (range->col0, range->coli); + gint row0 = MIN (range->row0, range->rowi); + gint rowi = MAX (range->row0, range->rowi); - if ( range.row0 == -1 ) range.row0 = min_visible_row (sheet); - if ( range.rowi == -1 ) range.rowi = max_visible_row (sheet); - if ( range.col0 == -1 ) range.col0 = min_visible_column (sheet); - if ( range.coli == -1 ) range.coli = max_visible_column (sheet); + if ( row0 == -1 ) row0 = min_visible_row (sheet); + if ( rowi == -1 ) rowi = max_visible_row (sheet); + if ( col0 == -1 ) col0 = min_visible_column (sheet); + if ( coli == -1 ) coli = max_visible_column (sheet); - r->x = psppire_axis_start_pixel (sheet->haxis, range.col0); + r->x = psppire_axis_start_pixel (sheet->haxis, col0); r->x -= round (sheet->hadjustment->value); - r->y = psppire_axis_start_pixel (sheet->vaxis, range.row0); + r->y = psppire_axis_start_pixel (sheet->vaxis, row0); r->y -= round (sheet->vadjustment->value); - r->width = psppire_axis_start_pixel (sheet->haxis, range.coli) - - psppire_axis_start_pixel (sheet->haxis, range.col0) + - psppire_axis_unit_size (sheet->haxis, range.coli); + r->width = psppire_axis_start_pixel (sheet->haxis, coli) - + psppire_axis_start_pixel (sheet->haxis, col0) + + psppire_axis_unit_size (sheet->haxis, coli); - r->height = psppire_axis_start_pixel (sheet->vaxis, range.rowi) - - psppire_axis_start_pixel (sheet->vaxis, range.row0) + - psppire_axis_unit_size (sheet->vaxis, range.rowi); + r->height = psppire_axis_start_pixel (sheet->vaxis, rowi) - + psppire_axis_start_pixel (sheet->vaxis, row0) + + psppire_axis_unit_size (sheet->vaxis, rowi); if ( sheet->column_titles_visible) { diff --git a/src/ui/gui/psppire-data-editor.c b/src/ui/gui/psppire-data-editor.c index ec7263af..58aa0b8f 100644 --- a/src/ui/gui/psppire-data-editor.c +++ b/src/ui/gui/psppire-data-editor.c @@ -1568,43 +1568,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 ) { @@ -1621,7 +1623,7 @@ data_sheet_set_clip (PsppireSheet *sheet) /* Construct clip dictionary. */ clip_dict = dict_create (); dict_set_encoding (clip_dict, dict_get_encoding (ds->dict->dict)); - for (i = range.col0; i <= range.coli; i++) + for (i = col0; i <= coli; i++) { const struct variable *old = dict_get_var (ds->dict->dict, i); dict_clone_var_assert (clip_dict, old, var_get_name (old)); @@ -1630,7 +1632,7 @@ data_sheet_set_clip (PsppireSheet *sheet) /* 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)