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)
{
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 )
{
/* 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));
/* 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)