[gnumeric] More work on variable-sized sheets.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnumeric] More work on variable-sized sheets.
- Date: Fri, 17 Apr 2009 15:25:03 -0400 (EDT)
commit beda0685908d8f67e15638f2afc023f64002ee44
Author: Morten Welinder <terra gnome org>
Date: Fri Apr 17 15:24:20 2009 -0400
More work on variable-sized sheets.
* src/position.c (gnm_cellpos_init_cellref): Take extra base_sheet
argument. All callers changed.
* src/parse-util.c (cellref_abs_col, cellref_abs_row): Eliminate
in favour of gnm_cellpos_init_cellref.
---
ChangeLog | 6 +++++
src/auto-format.c | 2 +-
src/dependent.c | 33 +++++++++++++++--------------
src/expr.c | 3 +-
src/func-builtin.c | 4 +-
src/parse-util.c | 42 ++++++++----------------------------
src/position.c | 39 +++++++++++++++++++++-------------
src/position.h | 4 +-
src/widgets/gnumeric-expr-entry.c | 4 +-
9 files changed, 66 insertions(+), 71 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e448218..3949a13 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2009-04-17 Morten Welinder <terra gnome org>
+ * src/position.c (gnm_cellpos_init_cellref): Take extra base_sheet
+ argument. All callers changed.
+
+ * src/parse-util.c (cellref_abs_col, cellref_abs_row): Eliminate
+ in favour of gnm_cellpos_init_cellref.
+
* src/commands.c (cmd_so_set_frame_label_finalize,
cmd_so_set_checkbox_finalize): Don't NULL-check before g_free.
Test suite passes again.
diff --git a/src/auto-format.c b/src/auto-format.c
index d7dadec..12127d2 100644
--- a/src/auto-format.c
+++ b/src/auto-format.c
@@ -206,7 +206,7 @@ do_af_suggest (GnmExpr const *expr, GnmEvalPos const *epos, GOFormat **explicit)
if (sheet == NULL)
return GNM_FUNC_AUTO_UNKNOWN;
- gnm_cellpos_init_cellref (&pos, ref, &epos->eval);
+ gnm_cellpos_init_cellref (&pos, ref, &epos->eval, sheet);
cell = sheet_cell_get (sheet, pos.col, pos.row);
if (cell == NULL)
return GNM_FUNC_AUTO_UNKNOWN;
diff --git a/src/dependent.c b/src/dependent.c
index 30312d4..c9d5742 100644
--- a/src/dependent.c
+++ b/src/dependent.c
@@ -849,17 +849,17 @@ link_single_dep (GnmDependent *dep, GnmCellPos const *pos, GnmCellRef const *ref
DependencySingle *single;
GnmDepContainer *deps;
DependentFlags flag = DEPENDENT_NO_FLAG;
+ Sheet const *sheet = eval_sheet (ref->sheet, dep->sheet);
- if (ref->sheet != NULL) {
- if (ref->sheet != dep->sheet)
- flag = (ref->sheet->workbook != dep->sheet->workbook)
- ? DEPENDENT_GOES_INTERBOOK : DEPENDENT_GOES_INTERSHEET;
- deps = ref->sheet->deps;
- } else
- deps = dep->sheet->deps;
+ if (sheet != dep->sheet)
+ flag = (sheet->workbook != dep->sheet->workbook)
+ ? DEPENDENT_GOES_INTERBOOK
+ : DEPENDENT_GOES_INTERSHEET;
+
+ deps = sheet->deps;
/* Inserts if it is not already there */
- gnm_cellpos_init_cellref (&lookup.pos, ref, pos);
+ gnm_cellpos_init_cellref (&lookup.pos, ref, pos, sheet);
single = g_hash_table_lookup (deps->single_hash, &lookup);
if (single == NULL) {
single = go_mem_chunk_alloc (deps->single_pool);
@@ -877,12 +877,13 @@ unlink_single_dep (GnmDependent *dep, GnmCellPos const *pos, GnmCellRef const *a
{
DependencySingle lookup;
DependencySingle *single;
- GnmDepContainer *deps = eval_sheet (a->sheet, dep->sheet)->deps;
+ Sheet const *sheet = eval_sheet (a->sheet, dep->sheet);
+ GnmDepContainer *deps = sheet->deps;
if (!deps)
return;
- gnm_cellpos_init_cellref (&lookup.pos, a, pos);
+ gnm_cellpos_init_cellref (&lookup.pos, a, pos, sheet);
single = g_hash_table_lookup (deps->single_hash, &lookup);
if (single != NULL) {
micro_hash_remove (&single->deps, dep);
@@ -967,8 +968,8 @@ link_cellrange_dep (GnmDependent *dep, GnmCellPos const *pos,
DependencyRange range;
DependentFlags flag = DEPENDENT_NO_FLAG;
- gnm_cellpos_init_cellref (&range.range.start, a, pos);
- gnm_cellpos_init_cellref (&range.range.end, b, pos);
+ gnm_cellpos_init_cellref (&range.range.start, a, pos, dep->sheet);
+ gnm_cellpos_init_cellref (&range.range.end, b, pos, dep->sheet);
range_normalize (&range.range);
if (a->sheet != NULL) {
@@ -1004,8 +1005,8 @@ unlink_cellrange_dep (GnmDependent *dep, GnmCellPos const *pos,
{
DependencyRange range;
- gnm_cellpos_init_cellref (&range.range.start, a, pos);
- gnm_cellpos_init_cellref (&range.range.end, b, pos);
+ gnm_cellpos_init_cellref (&range.range.start, a, pos, dep->sheet);
+ gnm_cellpos_init_cellref (&range.range.end, b, pos, dep->sheet);
range_normalize (&range.range);
if (a->sheet != NULL) {
@@ -1282,8 +1283,8 @@ dependent_add_dynamic_dep (GnmDependent *dep, GnmRangeRef const *rr)
g_hash_table_insert (dep->sheet->deps->dynamic_deps, dep, dyn);
}
- gnm_cellpos_init_cellref (&range.range.start, &rr->a, pos);
- gnm_cellpos_init_cellref (&range.range.end, &rr->b, pos);
+ gnm_cellpos_init_cellref (&range.range.start, &rr->a, pos, dep->sheet);
+ gnm_cellpos_init_cellref (&range.range.end, &rr->b, pos, dep->sheet);
if (range_is_singleton (&range.range)) {
flags = link_single_dep (&dyn->base, pos, &rr->a);
dyn->singles = g_slist_prepend (dyn->singles, gnm_rangeref_dup (rr));
diff --git a/src/expr.c b/src/expr.c
index 481e623..993ff6c 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -1419,7 +1419,8 @@ gnm_expr_eval (GnmExpr const *expr, GnmEvalPos const *pos,
GnmCell *cell;
GnmCellPos dest;
- gnm_cellpos_init_cellref (&dest, &expr->cellref.ref, &pos->eval);
+ gnm_cellpos_init_cellref (&dest, &expr->cellref.ref,
+ &pos->eval, pos->sheet);
cell = sheet_cell_get (eval_sheet (expr->cellref.ref.sheet, pos->sheet),
dest.col, dest.row);
diff --git a/src/func-builtin.c b/src/func-builtin.c
index 4534ef4..7438bd7 100644
--- a/src/func-builtin.c
+++ b/src/func-builtin.c
@@ -180,8 +180,8 @@ gnumeric_table (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
GnmExpr const *arg = argv[x];
val[x] = NULL;
if (NULL != arg && GNM_EXPR_GET_OPER (arg) == GNM_EXPR_OP_CELLREF) {
- gnm_cellpos_init_cellref (&pos,
- &arg->cellref.ref, &ei->pos->eval);
+ gnm_cellpos_init_cellref (&pos, &arg->cellref.ref,
+ &ei->pos->eval, ei->pos->sheet);
in[x] = sheet_cell_get (ei->pos->sheet, pos.col, pos.row);
if (NULL == in[x])
in[x] = sheet_cell_fetch (ei->pos->sheet, pos.col, pos.row);
diff --git a/src/parse-util.c b/src/parse-util.c
index b741d6f..01e1083 100644
--- a/src/parse-util.c
+++ b/src/parse-util.c
@@ -213,30 +213,6 @@ row_parse (char const *str, Sheet const *sheet,
/***************************************************************************/
-inline static int
-cellref_abs_col (GnmCellRef const *ref, GnmParsePos const *pp)
-{
- int col = (ref->col_relative) ? pp->eval.col + ref->col : ref->col;
-
- /* ICK! XL compatibility kludge */
- col %= gnm_sheet_get_max_cols (ref->sheet);
- if (col < 0)
- return col + gnm_sheet_get_max_cols (ref->sheet);
- return col;
-}
-
-inline static int
-cellref_abs_row (GnmCellRef const *ref, GnmParsePos const *pp)
-{
- int row = (ref->row_relative) ? pp->eval.row + ref->row : ref->row;
-
- /* ICK! XL compatibility kludge */
- row %= gnm_sheet_get_max_rows (ref->sheet);
- if (row < 0)
- return row + gnm_sheet_get_max_rows (ref->sheet);
- return row;
-}
-
static void
r1c1_add_index (GString *target, char type, int num, unsigned char relative)
{
@@ -345,10 +321,11 @@ rangeref_as_string (GnmConventionsOut *out, GnmRangeRef const *ref)
GnmRange r;
GString *target = out->accum;
- r.start.col = cellref_abs_col (&ref->a, out->pp);
- r.end.col = cellref_abs_col (&ref->b, out->pp);
- r.start.row = cellref_abs_row (&ref->a, out->pp);
- r.end.row = cellref_abs_row (&ref->b, out->pp);
+ gnm_cellpos_init_cellref (&r.start, &ref->a,
+ &out->pp->eval, out->pp->sheet);
+ /* FIXME: This the following sheet right? */
+ gnm_cellpos_init_cellref (&r.end, &ref->b,
+ &out->pp->eval, out->pp->sheet);
if (ref->a.sheet) {
if (NULL != out->pp->wb && ref->a.sheet->workbook != out->pp->wb) {
@@ -458,10 +435,11 @@ gnm_1_0_rangeref_as_string (GnmConventionsOut *out, GnmRangeRef const *ref)
GnmRange r;
GString *target = out->accum;
- r.start.col = cellref_abs_col (&ref->a, out->pp);
- r.end.col = cellref_abs_col (&ref->b, out->pp);
- r.start.row = cellref_abs_row (&ref->a, out->pp);
- r.end.row = cellref_abs_row (&ref->b, out->pp);
+ gnm_cellpos_init_cellref (&r.start, &ref->a,
+ &out->pp->eval, out->pp->sheet);
+ /* FIXME: This the following sheet right? */
+ gnm_cellpos_init_cellref (&r.end, &ref->b,
+ &out->pp->eval, out->pp->sheet);
if (ref->a.sheet) {
if (NULL != out->pp->wb && ref->a.sheet->workbook != out->pp->wb) {
diff --git a/src/position.c b/src/position.c
index bb2e454..e2aff34 100644
--- a/src/position.c
+++ b/src/position.c
@@ -289,23 +289,35 @@ gnm_cellref_get_row (GnmCellRef const *ref, GnmEvalPos const *ep)
}
void
-gnm_cellpos_init_cellref (GnmCellPos *res,
- GnmCellRef const *cell_ref, GnmCellPos const *pos)
+gnm_cellpos_init_cellref (GnmCellPos *res, GnmCellRef const *cell_ref,
+ GnmCellPos const *pos, Sheet const *base_sheet)
{
+ Sheet const *sheet;
+
g_return_if_fail (cell_ref != NULL);
g_return_if_fail (res != NULL);
+ sheet = eval_sheet (cell_ref->sheet, base_sheet);
+
if (cell_ref->col_relative) {
- res->col = (cell_ref->col + pos->col) % gnm_sheet_get_max_cols (cell_ref->sheet);
- if (res->col < 0)
- res->col += gnm_sheet_get_max_cols (cell_ref->sheet);
+ int col = cell_ref->col + pos->col;
+ int max = gnm_sheet_get_max_cols (sheet);
+ if (col < 0)
+ col += max;
+ else if (col >= max)
+ col -= max;
+ res->col = col;
} else
res->col = cell_ref->col;
if (cell_ref->row_relative) {
- res->row = (cell_ref->row + pos->row) % gnm_sheet_get_max_rows (cell_ref->sheet);
- if (res->row < 0)
- res->row += gnm_sheet_get_max_rows (cell_ref->sheet);
+ int row = cell_ref->row + pos->row;
+ int max = gnm_sheet_get_max_rows (sheet);
+ if (row < 0)
+ row += max;
+ else if (row >= max)
+ row -= max;
+ res->row = row;
} else
res->row = cell_ref->row;
}
@@ -393,17 +405,14 @@ void
gnm_rangeref_normalize (GnmRangeRef const *ref, GnmEvalPos const *ep,
Sheet **start_sheet, Sheet **end_sheet, GnmRange *dest)
{
- GnmRangeRef r;
-
g_return_if_fail (ref != NULL);
g_return_if_fail (ep != NULL);
- r = *ref;
- r.a.sheet = *start_sheet = eval_sheet (r.a.sheet, ep->sheet);
- r.b.sheet = *end_sheet = eval_sheet (r.b.sheet, *start_sheet);
+ *start_sheet = eval_sheet (ref->a.sheet, ep->sheet);
+ *end_sheet = eval_sheet (ref->b.sheet, *start_sheet);
- gnm_cellpos_init_cellref (&dest->start, &r.a, &ep->eval);
- gnm_cellpos_init_cellref (&dest->end, &r.b, &ep->eval);
+ gnm_cellpos_init_cellref (&dest->start, &ref->a, &ep->eval, *start_sheet);
+ gnm_cellpos_init_cellref (&dest->end, &ref->b, &ep->eval, *end_sheet);
range_normalize (dest);
}
diff --git a/src/position.h b/src/position.h
index 1c4f0ad..a17b898 100644
--- a/src/position.h
+++ b/src/position.h
@@ -77,8 +77,8 @@ void gnm_rangeref_normalize(GnmRangeRef const *rr, GnmEvalPos const *ep,
guint gnm_cellpos_hash (GnmCellPos const *key);
gint gnm_cellpos_equal (GnmCellPos const *a, GnmCellPos const *b);
-void gnm_cellpos_init_cellref (GnmCellPos *cp,
- GnmCellRef const *cr, GnmCellPos const *pos);
+void gnm_cellpos_init_cellref (GnmCellPos *cp, GnmCellRef const *cr,
+ GnmCellPos const *pos, Sheet const *base_sheet);
G_END_DECLS
diff --git a/src/widgets/gnumeric-expr-entry.c b/src/widgets/gnumeric-expr-entry.c
index afa777c..2bf5f44 100644
--- a/src/widgets/gnumeric-expr-entry.c
+++ b/src/widgets/gnumeric-expr-entry.c
@@ -1373,8 +1373,8 @@ gnm_expr_entry_get_rangesel (GnmExprEntry const *gee,
*sheet = ref.a.sheet;
if (r != NULL) {
- gnm_cellpos_init_cellref (&r->start, &ref.a, &gee->pp.eval);
- gnm_cellpos_init_cellref (&r->end, &ref.b, &gee->pp.eval);
+ gnm_cellpos_init_cellref (&r->start, &ref.a, &gee->pp.eval, ref.a.sheet);
+ gnm_cellpos_init_cellref (&r->end, &ref.b, &gee->pp.eval, ref.b.sheet);
range_normalize (r);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]