Commit 2bfb51ca authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

Add some gnm_ to the api. (gnm_cellref_set_col_ar) : new



2005-09-20  Jody Goldberg <jody@gnome.org>

	* src/position.c : Add some gnm_ to the api.
	(gnm_cellref_set_col_ar) : new
	(gnm_cellref_set_row_ar) : new.

2005-09-20  Jody Goldberg <jody@gnome.org>

	* gnumeric-expr-entry.c (cb_gee_key_press_event) : Use
	  gnm_cellref_set_{col,row}_ar to compress the code and to handle
	  mixed mode references (eg $A1:B2)
parent 9c43356e
......@@ -8,6 +8,7 @@ release, and longer term bugs.
Release Critical
----------------
- autopackage patches
- Patches for Maemo {partially done}
- autoformat template array bound reads
- Finish Data -> Table
......
......@@ -1246,7 +1246,7 @@ gnumeric_countblank (FunctionEvalInfo *ei, GnmValue const * const *argv)
GnmRange r;
int count;
rangeref_normalize (&argv[0]->v_range.cell, ei->pos,
gnm_rangeref_normalize (&argv[0]->v_range.cell, ei->pos,
&start_sheet, &end_sheet, &r);
count = range_width (&r) * range_height (&r);
if (start_sheet != end_sheet && end_sheet != NULL)
......
......@@ -964,7 +964,7 @@ gnumeric_column (FunctionEvalInfo *ei, GnmValue const * const *args)
Sheet *tmp;
GnmRange r;
rangeref_normalize (&ref->v_range.cell, ei->pos, &tmp, &tmp, &r);
gnm_rangeref_normalize (&ref->v_range.cell, ei->pos, &tmp, &tmp, &r);
col = r.start.col + 1;
width = range_width (&r);
height = range_height (&r);
......@@ -1142,7 +1142,7 @@ gnumeric_row (FunctionEvalInfo *ei, GnmValue const * const *args)
Sheet *tmp;
GnmRange r;
rangeref_normalize (&ref->v_range.cell, ei->pos, &tmp, &tmp, &r);
gnm_rangeref_normalize (&ref->v_range.cell, ei->pos, &tmp, &tmp, &r);
row = r.start.row + 1;
width = range_width (&r);
height = range_height (&r);
......
......@@ -5546,12 +5546,10 @@ function_marshal_arg (FunctionEvalInfo *ei,
}
if (v->type == VALUE_CELLRANGE) {
cellref_make_abs (&v->v_range.cell.a,
&v->v_range.cell.a,
ei->pos);
cellref_make_abs (&v->v_range.cell.b,
&v->v_range.cell.b,
ei->pos);
gnm_cellref_make_abs (&v->v_range.cell.a, &v->v_range.cell.a,
ei->pos);
gnm_cellref_make_abs (&v->v_range.cell.b, &v->v_range.cell.b,
ei->pos);
}
return v;
......
......@@ -387,8 +387,8 @@ mps_write_coefficients (MpsInputContext *ctxt, Sheet *sh,
cell_queue_recalc (cell);
/* Add Slack calculation */
cellref_init (&ref1, sh, ecol + 1, r, FALSE);
cellref_init (&ref2, sh, ecol + 3, r, FALSE);
gnm_cellref_init (&ref1, sh, ecol + 1, r, FALSE);
gnm_cellref_init (&ref2, sh, ecol + 3, r, FALSE);
expr = (GnmExpr *) gnm_expr_new_binary
(gnm_expr_new_cellref (&ref1),
GNM_EXPR_OP_SUB,
......
......@@ -154,7 +154,7 @@ oleo_get_gnumeric_expr (char const *o_expr,
cellref_as_string (gres, gnm_expr_conventions_default,
&start, cur_pos, TRUE);
if (!cellref_equal (&start, &end)) {
if (!gnm_cellref_equal (&start, &end)) {
g_string_append_c (gres, ':');
cellref_as_string (gres, gnm_expr_conventions_default,
&end, cur_pos, TRUE);
......
......@@ -208,7 +208,7 @@ do_af_suggest (GnmExpr const *expr, const GnmEvalPos *epos, GOFormat **explicit)
if (sheet == NULL)
return GNM_FUNC_AUTO_UNKNOWN;
cellref_get_abs_pos (ref, &epos->eval, &pos);
gnm_cellpos_init_cellref (&pos, ref, &epos->eval);
cell = sheet_cell_get (sheet, pos.col, pos.row);
if (cell == NULL)
return GNM_FUNC_AUTO_UNKNOWN;
......
......@@ -274,12 +274,12 @@ sv_select_cur_inputs (SheetView *sv)
continue;
sv_selection_add_range (sv,
cellref_get_abs_col (&r->a, &ep),
cellref_get_abs_row (&r->a, &ep),
cellref_get_abs_col (&r->a, &ep),
cellref_get_abs_row (&r->a, &ep),
cellref_get_abs_col (&r->b, &ep),
cellref_get_abs_row (&r->b, &ep));
gnm_cellref_get_col (&r->a, &ep),
gnm_cellref_get_row (&r->a, &ep),
gnm_cellref_get_col (&r->a, &ep),
gnm_cellref_get_row (&r->a, &ep),
gnm_cellref_get_col (&r->b, &ep),
gnm_cellref_get_row (&r->b, &ep));
value_release (v);
}
g_slist_free (ranges);
......
......@@ -551,7 +551,7 @@ link_single_dep (GnmDependent *dep, GnmCellPos const *pos, GnmCellRef const *ref
deps = dep->sheet->deps;
/* Inserts if it is not already there */
cellref_get_abs_pos (ref, pos, &lookup.pos);
gnm_cellpos_init_cellref (&lookup.pos, ref, pos);
single = g_hash_table_lookup (deps->single_hash, &lookup);
if (single == NULL) {
single = go_mem_chunk_alloc (deps->single_pool);
......@@ -574,7 +574,7 @@ unlink_single_dep (GnmDependent *dep, GnmCellPos const *pos, GnmCellRef const *a
if (!deps)
return;
cellref_get_abs_pos (a, pos, &lookup.pos);
gnm_cellpos_init_cellref (&lookup.pos, a, pos);
single = g_hash_table_lookup (deps->single_hash, &lookup);
if (single != NULL) {
micro_hash_remove (&single->deps, dep);
......@@ -649,8 +649,8 @@ link_cellrange_dep (GnmDependent *dep, GnmCellPos const *pos,
DependencyRange range;
DependentFlags flag = DEPENDENT_NO_FLAG;
cellref_get_abs_pos (a, pos, &range.range.start);
cellref_get_abs_pos (b, pos, &range.range.end);
gnm_cellpos_init_cellref (&range.range.start, a, pos);
gnm_cellpos_init_cellref (&range.range.end, b, pos);
range_normalize (&range.range);
if (a->sheet != NULL) {
......@@ -686,8 +686,8 @@ unlink_cellrange_dep (GnmDependent *dep, GnmCellPos const *pos,
{
DependencyRange range;
cellref_get_abs_pos (a, pos, &range.range.start);
cellref_get_abs_pos (b, pos, &range.range.end);
gnm_cellpos_init_cellref (&range.range.start, a, pos);
gnm_cellpos_init_cellref (&range.range.end, b, pos);
range_normalize (&range.range);
if (a->sheet != NULL) {
......@@ -966,8 +966,8 @@ dependent_add_dynamic_dep (GnmDependent *dep, GnmValueRange const *v)
g_hash_table_insert (dep->sheet->deps->dynamic_deps, dep, dyn);
}
cellref_get_abs_pos (&v->cell.a, pos, &range.range.start);
cellref_get_abs_pos (&v->cell.b, pos, &range.range.end);
gnm_cellpos_init_cellref (&range.range.start, &v->cell.a, pos);
gnm_cellpos_init_cellref (&range.range.end, &v->cell.b, pos);
if (range_is_singleton (&range.range)) {
flags = link_single_dep (&dyn->base, pos, &v->cell.a);
dyn->singles = g_slist_prepend (dyn->singles, value_dup ((GnmValue *)v));
......
......@@ -109,8 +109,8 @@ prepare_ranges (simulation_t *sim)
sim->outputs->type != VALUE_CELLRANGE)
return TRUE;
sim->ref_inputs = rangeref_dup (value_get_rangeref (sim->inputs));
sim->ref_outputs = rangeref_dup (value_get_rangeref (sim->outputs));
sim->ref_inputs = gnm_rangeref_dup (value_get_rangeref (sim->inputs));
sim->ref_outputs = gnm_rangeref_dup (value_get_rangeref (sim->outputs));
sim->n_input_vars =
(abs (sim->ref_inputs->a.col - sim->ref_inputs->b.col) + 1) *
......
......@@ -461,7 +461,7 @@ gnm_expr_equal (GnmExpr const *a, GnmExpr const *b)
a->name.optional_wb_scope == b->name.optional_wb_scope;
case GNM_EXPR_OP_CELLREF:
return cellref_equal (&a->cellref.ref, &b->cellref.ref);
return gnm_cellref_equal (&a->cellref.ref, &b->cellref.ref);
case GNM_EXPR_OP_CONSTANT:
return value_equal (a->constant.value, b->constant.value);
......@@ -598,7 +598,7 @@ value_intersection (GnmValue *v, GnmEvalPos const *pos)
}
/* inverted ranges */
rangeref_normalize (&v->v_range.cell, pos, &start_sheet, &end_sheet, &r);
gnm_rangeref_normalize (&v->v_range.cell, pos, &start_sheet, &end_sheet, &r);
value_release (v);
if (start_sheet == end_sheet || end_sheet == NULL) {
......@@ -1007,8 +1007,8 @@ gnm_expr_range_op (GnmExpr const *expr, GnmEvalPos const *ep,
gnm_expr_extract_ref (&b_ref, expr->binary.value_b, ep, flags))
return value_new_error_REF (ep);
rangeref_normalize (&a_ref, ep, &a_start, &a_end, &a_range);
rangeref_normalize (&b_ref, ep, &b_start, &b_end, &b_range);
gnm_rangeref_normalize (&a_ref, ep, &a_start, &a_end, &a_range);
gnm_rangeref_normalize (&b_ref, ep, &b_start, &b_end, &b_range);
if (expr->any.oper != GNM_EXPR_OP_INTERSECT)
res_range = range_union (&a_range, &b_range);
......@@ -1287,7 +1287,7 @@ gnm_expr_eval (GnmExpr const *expr, GnmEvalPos const *pos,
GnmCell *cell;
GnmCellPos dest;
cellref_get_abs_pos (&expr->cellref.ref, &pos->eval, &dest);
gnm_cellpos_init_cellref (&dest, &expr->cellref.ref, &pos->eval);
cell = sheet_cell_get (eval_sheet (expr->cellref.ref.sheet, pos->sheet),
dest.col, dest.row);
......@@ -2597,7 +2597,7 @@ ets_hash (gconstpointer key)
return (guint)(expr->name.name);
case GNM_EXPR_OP_CELLREF:
return cellref_hash (&expr->cellref.ref);
return gnm_cellref_hash (&expr->cellref.ref);
case GNM_EXPR_OP_ARRAY:
break;
......
......@@ -177,7 +177,8 @@ gnumeric_table (FunctionEvalInfo *ei, GnmExprList const *args)
arg = gnm_expr_list_nth (args, x);
val[x] = NULL;
if (NULL != arg && arg->any.oper == GNM_EXPR_OP_CELLREF) {
cellref_get_abs_pos (&arg->cellref.ref, &ei->pos->eval, &pos);
gnm_cellpos_init_cellref (&pos,
&arg->cellref.ref, &ei->pos->eval);
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);
......
......@@ -982,7 +982,7 @@ function_call_with_list (FunctionEvalInfo *ei, GnmExprList *l,
if (arg_type == 'A' || arg_type == 'r') {
if (expr->any.oper == GNM_EXPR_OP_CELLREF) {
GnmCellRef r;
cellref_make_abs (&r, &expr->cellref.ref, ei->pos);
gnm_cellref_make_abs (&r, &expr->cellref.ref, ei->pos);
args[i] = value_new_cellrange_unsafe (&r, &r);
/* TODO decide on the semantics of these argument types */
#warning do we need to force an eval here ?
......@@ -990,12 +990,12 @@ function_call_with_list (FunctionEvalInfo *ei, GnmExprList *l,
tmp = args[i] = gnm_expr_eval (expr, ei->pos,
GNM_EXPR_EVAL_PERMIT_NON_SCALAR);
if (tmp->type == VALUE_CELLRANGE) {
cellref_make_abs (&tmp->v_range.cell.a,
&tmp->v_range.cell.a,
ei->pos);
cellref_make_abs (&tmp->v_range.cell.b,
&tmp->v_range.cell.b,
ei->pos);
gnm_cellref_make_abs (&tmp->v_range.cell.a,
&tmp->v_range.cell.a,
ei->pos);
gnm_cellref_make_abs (&tmp->v_range.cell.b,
&tmp->v_range.cell.b,
ei->pos);
/* Array args accept scalars */
} else if (arg_type != 'A' && tmp->type != VALUE_ARRAY) {
......
......@@ -366,7 +366,7 @@ gnm_go_data_vector_load_len (GODataVector *dat)
if (vec->val != NULL) {
switch (vec->val->type) {
case VALUE_CELLRANGE:
rangeref_normalize (&vec->val->v_range.cell, &ep,
gnm_rangeref_normalize (&vec->val->v_range.cell, &ep,
&start_sheet, &end_sheet, &r);
if (r.end.col > start_sheet->cols.max_used)
......@@ -474,7 +474,7 @@ gnm_go_data_vector_load_values (GODataVector *dat)
vals = dat->values;
switch (vec->val->type) {
case VALUE_CELLRANGE:
rangeref_normalize (&vec->val->v_range.cell,
gnm_rangeref_normalize (&vec->val->v_range.cell,
eval_pos_init_dep (&ep, &vec->dep),
&start_sheet, &end_sheet, &r);
......@@ -608,8 +608,8 @@ gnm_go_data_vector_get_str (GODataVector *dat, unsigned i)
GnmCell *cell;
GnmRange r;
rangeref_normalize (&v->v_range.cell, &ep,
&start_sheet, &end_sheet, &r);
gnm_rangeref_normalize (&v->v_range.cell, &ep,
&start_sheet, &end_sheet, &r);
if (vec->as_col)
r.start.row += i;
else
......@@ -752,7 +752,7 @@ gnm_go_data_matrix_load_size (GODataMatrix *dat)
if (mat->val != NULL) {
switch (mat->val->type) {
case VALUE_CELLRANGE:
rangeref_normalize (&mat->val->v_range.cell, &ep,
gnm_rangeref_normalize (&mat->val->v_range.cell, &ep,
&start_sheet, &end_sheet, &r);
if (r.end.col > start_sheet->cols.max_used)
r.end.col = start_sheet->cols.max_used;
......@@ -884,7 +884,7 @@ gnm_go_data_matrix_load_values (GODataMatrix *dat)
vals = dat->values;
switch (mat->val->type) {
case VALUE_CELLRANGE:
rangeref_normalize (&mat->val->v_range.cell,
gnm_rangeref_normalize (&mat->val->v_range.cell,
eval_pos_init_dep (&ep, &mat->dep),
&start_sheet, &end_sheet, &r);
......@@ -1013,8 +1013,8 @@ gnm_go_data_matrix_get_str (GODataMatrix *dat, unsigned i, unsigned j)
GnmCell *cell;
GnmRange r;
rangeref_normalize (&v->v_range.cell, &ep,
&start_sheet, &end_sheet, &r);
gnm_rangeref_normalize (&v->v_range.cell, &ep,
&start_sheet, &end_sheet, &r);
r.start.row += i;
r.start.col += j;
cell = sheet_cell_get (start_sheet, r.start.col, r.start.row);
......
/* vim: set sw=8: */
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* position.c: Utility routines for various types of positional
* coordinates.
*
* Copyright (C) 2000-2002 Jody Goldberg (jody@gnome.org)
* Copyright (C) 2000-2005 Jody Goldberg (jody@gnome.org)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -193,7 +192,7 @@ parse_pos_init_sheet (GnmParsePos *pp, Sheet *sheet)
/********************************************************************************/
GnmCellRef *
cellref_init (GnmCellRef *ref, Sheet *sheet, int col, int row, gboolean relative)
gnm_cellref_init (GnmCellRef *ref, Sheet *sheet, int col, int row, gboolean relative)
{
ref->sheet = sheet;
ref->col = col;
......@@ -204,7 +203,7 @@ cellref_init (GnmCellRef *ref, Sheet *sheet, int col, int row, gboolean relative
}
gboolean
cellref_equal (GnmCellRef const *a, GnmCellRef const *b)
gnm_cellref_equal (GnmCellRef const *a, GnmCellRef const *b)
{
return (a->col == b->col) &&
(a->col_relative == b->col_relative) &&
......@@ -214,7 +213,7 @@ cellref_equal (GnmCellRef const *a, GnmCellRef const *b)
}
guint
cellref_hash (GnmCellRef const *cr)
gnm_cellref_hash (GnmCellRef const *cr)
{
guint h = ((cr->row << 8) ^ cr->col) * 4;
if (cr->col_relative) h |= 1;
......@@ -223,7 +222,7 @@ cellref_hash (GnmCellRef const *cr)
}
int
cellref_get_abs_col (GnmCellRef const *ref, GnmEvalPos const *ep)
gnm_cellref_get_col (GnmCellRef const *ref, GnmEvalPos const *ep)
{
g_return_val_if_fail (ref != NULL, 0);
g_return_val_if_fail (ep != NULL, 0);
......@@ -238,7 +237,7 @@ cellref_get_abs_col (GnmCellRef const *ref, GnmEvalPos const *ep)
}
int
cellref_get_abs_row (GnmCellRef const *ref, GnmEvalPos const *ep)
gnm_cellref_get_row (GnmCellRef const *ref, GnmEvalPos const *ep)
{
g_return_val_if_fail (ref != NULL, 0);
g_return_val_if_fail (ep != NULL, 0);
......@@ -253,9 +252,8 @@ cellref_get_abs_row (GnmCellRef const *ref, GnmEvalPos const *ep)
}
void
cellref_get_abs_pos (GnmCellRef const *cell_ref,
GnmCellPos const *pos,
GnmCellPos *res)
gnm_cellpos_init_cellref (GnmCellPos *res,
GnmCellRef const *cell_ref, GnmCellPos const *pos)
{
g_return_if_fail (cell_ref != NULL);
g_return_if_fail (res != NULL);
......@@ -276,7 +274,7 @@ cellref_get_abs_pos (GnmCellRef const *cell_ref,
}
void
cellref_make_abs (GnmCellRef *dest, GnmCellRef const *src, GnmEvalPos const *ep)
gnm_cellref_make_abs (GnmCellRef *dest, GnmCellRef const *src, GnmEvalPos const *ep)
{
g_return_if_fail (dest != NULL);
g_return_if_fail (src != NULL);
......@@ -298,20 +296,45 @@ cellref_make_abs (GnmCellRef *dest, GnmCellRef const *src, GnmEvalPos const *ep)
dest->row_relative = dest->col_relative = FALSE;
}
void
gnm_cellref_set_col_ar (GnmCellRef *cr, GnmParsePos const *pp, gboolean abs_rel)
{
if (cr->col_relative ^ abs_rel) {
if (cr->col_relative)
cr->col += pp->eval.col;
else
cr->col -= pp->eval.col;
cr->col_relative = abs_rel;
}
}
void
gnm_cellref_set_row_ar (GnmCellRef *cr, GnmParsePos const *pp, gboolean abs_rel)
{
if (cr->row_relative ^ abs_rel) {
if (cr->row_relative)
cr->row += pp->eval.row;
else
cr->row -= pp->eval.row;
cr->row_relative = abs_rel;
}
}
gboolean
rangeref_equal (GnmRangeRef const *a, GnmRangeRef const *b)
gnm_rangeref_equal (GnmRangeRef const *a, GnmRangeRef const *b)
{
return cellref_equal (&a->a, &b->a) && cellref_equal (&a->b, &b->b);
return gnm_cellref_equal (&a->a, &b->a) &&
gnm_cellref_equal (&a->b, &b->b);
}
guint
rangeref_hash (GnmRangeRef const *rr)
gnm_rangeref_hash (GnmRangeRef const *rr)
{
return cellref_hash (&rr->a) << 16 | cellref_hash (&rr->b);
return gnm_cellref_hash (&rr->a) << 16 | gnm_cellref_hash (&rr->b);
}
GnmRangeRef *
rangeref_dup (GnmRangeRef const *rr)
gnm_rangeref_dup (GnmRangeRef const *rr)
{
GnmRangeRef *res;
......@@ -323,32 +346,32 @@ rangeref_dup (GnmRangeRef const *rr)
}
/**
* range_ref_normalize : Take a range_ref and normalize it
* gnm_rangeref_normalize : Take a range_ref and normalize it
* by converting to absolute coords and handling inversions.
*/
void
rangeref_normalize (GnmRangeRef const *ref, GnmEvalPos const *ep,
Sheet **start_sheet, Sheet **end_sheet, GnmRange *dest)
gnm_rangeref_normalize (GnmRangeRef const *ref, GnmEvalPos const *ep,
Sheet **start_sheet, Sheet **end_sheet, GnmRange *dest)
{
g_return_if_fail (ref != NULL);
g_return_if_fail (ep != NULL);
cellref_get_abs_pos (&ref->a, &ep->eval, &dest->start);
cellref_get_abs_pos (&ref->b, &ep->eval, &dest->end);
gnm_cellpos_init_cellref (&dest->start, &ref->a, &ep->eval);
gnm_cellpos_init_cellref (&dest->end, &ref->b, &ep->eval);
range_normalize (dest);
*start_sheet = eval_sheet (ref->a.sheet, ep->sheet);
*end_sheet = eval_sheet (ref->b.sheet, *start_sheet);
*end_sheet = eval_sheet (ref->b.sheet, *start_sheet);
}
guint
cellpos_hash (GnmCellPos const *key)
gnm_cellpos_hash (GnmCellPos const *key)
{
return (key->row << 8) | key->col;
}
gint
cellpos_equal (GnmCellPos const *a, GnmCellPos const *b)
gnm_cellpos_equal (GnmCellPos const *a, GnmCellPos const *b)
{
return (a->row == b->row && a->col == b->col);
}
......
......@@ -51,29 +51,29 @@ struct _GnmRangeRef {
GnmCellRef a, b;
};
GnmCellRef *cellref_init (GnmCellRef *ref, Sheet *sheet, int col, int row,
gboolean rel);
gboolean cellref_equal (GnmCellRef const *a, GnmCellRef const *b);
guint cellref_hash (GnmCellRef const *cr);
void cellref_make_abs (GnmCellRef *dest,
GnmCellRef const *src,
GnmEvalPos const *ep);
int cellref_get_abs_col (GnmCellRef const *ref,
GnmEvalPos const *pos);
int cellref_get_abs_row (GnmCellRef const *cell_ref,
GnmEvalPos const *src_fp);
void cellref_get_abs_pos (GnmCellRef const *cell_ref,
GnmCellPos const *pos,
GnmCellPos *res);
GnmCellRef *gnm_cellref_init (GnmCellRef *ref, Sheet *sheet,
int col, int row, gboolean rel);
gboolean gnm_cellref_equal (GnmCellRef const *a, GnmCellRef const *b);
guint gnm_cellref_hash (GnmCellRef const *cr);
void gnm_cellref_make_abs (GnmCellRef *dest, GnmCellRef const *src,
GnmEvalPos const *ep);
void gnm_cellref_set_col_ar (GnmCellRef *cr, GnmParsePos const *pp,
gboolean abs_rel);
void gnm_cellref_set_row_ar (GnmCellRef *cr, GnmParsePos const *pp,
gboolean abs_rel);
int gnm_cellref_get_col (GnmCellRef const *cr, GnmEvalPos const *ep);
int gnm_cellref_get_row (GnmCellRef const *cr, GnmEvalPos const *ep);
gboolean rangeref_equal (GnmRangeRef const *a, GnmRangeRef const *b);
guint rangeref_hash (GnmRangeRef const *cr);
GnmRangeRef *rangeref_dup (GnmRangeRef const *cr);
void rangeref_normalize (GnmRangeRef const *ref, GnmEvalPos const *ep,
Sheet **start_sheet, Sheet **end_sheet,
GnmRange *dest);
gboolean gnm_rangeref_equal (GnmRangeRef const *a, GnmRangeRef const *b);
guint gnm_rangeref_hash (GnmRangeRef const *cr);
GnmRangeRef *gnm_rangeref_dup (GnmRangeRef const *cr);
void gnm_rangeref_normalize(GnmRangeRef const *rr, GnmEvalPos const *ep,
Sheet **start_sheet, Sheet **end_sheet,
GnmRange *dest);
guint cellpos_hash (GnmCellPos const *key);
gint cellpos_equal (GnmCellPos const *a, GnmCellPos const *b);
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);
#endif /* GNUMERIC_POSITION_H */
......@@ -2015,8 +2015,8 @@ sheet_style_get_list (Sheet const *sheet, GnmRange const *r)
StyleListMerge mi;
mi.style_equal = gnm_style_equal;
mi.cache = g_hash_table_new ((GHashFunc)&cellpos_hash,
(GCompareFunc)&cellpos_equal);
mi.cache = g_hash_table_new ((GHashFunc)&gnm_cellpos_hash,
(GCompareFunc)&gnm_cellpos_equal);
foreach_tile (sheet->style_data->styles,
TILE_TOP_LEVEL, 0, 0, r,
......@@ -2065,8 +2065,8 @@ sheet_style_collect_conditions (Sheet const *sheet, GnmRange const *r)
GnmStyleList *res = NULL;
StyleListMerge mi;
mi.style_equal = style_conditions_equal;
mi.cache = g_hash_table_new ((GHashFunc)&cellpos_hash,
(GCompareFunc)&cellpos_equal);
mi.cache = g_hash_table_new ((GHashFunc)&gnm_cellpos_hash,
(GCompareFunc)&gnm_cellpos_equal);
foreach_tile (sheet->style_data->styles,
TILE_TOP_LEVEL, 0, 0, r,
......@@ -2117,8 +2117,8 @@ sheet_style_collect_validations (Sheet const *sheet, GnmRange const *r)
StyleListMerge mi;
mi.style_equal = style_validation_equal;
mi.cache = g_hash_table_new ((GHashFunc)&cellpos_hash,
(GCompareFunc)&cellpos_equal);
mi.cache = g_hash_table_new ((GHashFunc)&gnm_cellpos_hash,
(GCompareFunc)&gnm_cellpos_equal);
foreach_tile (sheet->style_data->styles,
TILE_TOP_LEVEL, 0, 0, r,
......
......@@ -479,12 +479,12 @@ gnm_sheet_init (Sheet *sheet)
sheet->pivottables = NULL;
sheet->scenarios = NULL;
sheet->list_merged = NULL;
sheet->hash_merged = g_hash_table_new ((GHashFunc)&cellpos_hash,
(GCompareFunc)&cellpos_equal);
sheet->hash_merged = g_hash_table_new ((GHashFunc)&gnm_cellpos_hash,
(GCompareFunc)&gnm_cellpos_equal);
sheet->deps = gnm_dep_container_new ();
sheet->cell_hash = g_hash_table_new ((GHashFunc)&cellpos_hash,
(GCompareFunc)&cellpos_equal);
sheet->cell_hash = g_hash_table_new ((GHashFunc)&gnm_cellpos_hash,
(GCompareFunc)&gnm_cellpos_equal);
sheet->pristine = TRUE;
sheet->modified = FALSE;
......
......@@ -270,7 +270,7 @@ value_area_foreach (GnmValue const *v, GnmEvalPos const *ep,
GnmRange r;
Sheet *start_sheet, *end_sheet;
rangeref_normalize (&v->v_range.cell, ep, &start_sheet, &end_sheet, &r);
gnm_rangeref_normalize (&v->v_range.cell, ep, &start_sheet, &end_sheet, &r);
wrap.callback = callback;
wrap.ep = ep;
......
......@@ -709,8 +709,8 @@ value_equal (GnmValue const *a, GnmValue const *b)
return TRUE;
case VALUE_CELLRANGE:
return cellref_equal (&a->v_range.cell.a, &b->v_range.cell.a) &&
cellref_equal (&a->v_range.cell.b, &b->v_range.cell.b);
return gnm_cellref_equal (&a->v_range.cell.a, &b->v_range.cell.a) &&
gnm_cellref_equal (&a->v_range.cell.b, &b->v_range.cell.b);
case VALUE_ARRAY:
if (a->v_array.x == b->v_array.x && a->v_array.y == b->v_array.y) {
......@@ -763,8 +763,8 @@ value_hash (GnmValue const *v)
case VALUE_CELLRANGE:
/* FIXME: take sheet into account? */
return (cellref_hash (&v->v_range.cell.a) * 3) ^
cellref_hash (&v->v_range.cell.b);
return (gnm_cellref_hash (&v->v_range.cell.a) * 3) ^
gnm_cellref_hash (&v->v_range.cell.b);
case VALUE_ARRAY: {
int i;
......
2005-09-20 Jody Goldberg <jody@gnome.org>
* gnumeric-expr-entry.c (cb_gee_key_press_event) : Use
gnm_cellref_set_{col,row}_ar to compress the code and to handle
mixed mode references (eg $A1:B2)
2005-09-08 Jody Goldberg <jody@gnome.org>
* Release 1.5.90
......
......@@ -260,6 +260,7 @@ cb_gee_key_press_event (GtkEntry *entry,
Rangesel *rs = &gee->rangesel;
gboolean abs_cols = (gee->flags & GNM_EE_ABS_COL);
gboolean abs_rows = (gee->flags & GNM_EE_ABS_ROW);
gboolean c, r;
/* FIXME: since the range can't have changed we should just be able to */
/* look it up rather than reparse */
......@@ -272,46 +273,21 @@ cb_gee_key_press_event (GtkEntry *entry,
if (!rs->is_valid || rs->text_start >= rs->text_end)
return TRUE;
c = rs->ref.a.col_relative;
r = rs->ref.a.row_relative;
if (abs_rows) {
if (abs_cols)
return TRUE;
if ((rs->ref.b.col_relative = rs->ref.a.col_relative =
!rs->ref.a.col_relative)) {
rs->ref.a.col -= gee->pp.eval.col;
rs->ref.b.col -= gee->pp.eval.col;
} else {
rs->ref.a.col += gee->pp.eval.col;
rs->ref.b.col += gee->pp.eval.col;
}
gnm_cellref_set_row_ar (&rs->ref.a, &gee->pp, !c);
gnm_cellref_set_col_ar (&rs->ref.b, &gee->pp, !c);
} else if (abs_cols) {
if ((rs->ref.b.row_relative = rs->ref.a.row_relative =
!rs->ref.a.row_relative)) {
rs->ref.a.row -= gee->pp.eval.row;
rs->ref.b.row -= gee->pp.eval.row;
} else {
rs->ref.a.row += gee->pp.eval.row;
rs->ref.b.row += gee->pp.eval.row;
}
gnm_cellref_set_row_ar (&rs->ref.a, &gee->pp, !r);
gnm_cellref_set_row_ar (&rs->ref.b, &gee->pp, !r);
} else {
gboolean const c = rs->ref.a.col_relative;
gboolean const r = rs->ref.a.row_relative;
rs->ref.b.row_relative = rs->ref.a.row_relative = (c ^ r);
if (rs->ref.a.row_relative ^ r) {
rs->ref.a.row -= gee->pp.eval.row;
rs->ref.b.row -= gee->pp.eval.row;
} else {
rs->ref.a.row += gee->pp.eval.row;
rs->ref.b.row += gee->pp.eval.row;
}
if ((rs->ref.b.col_relative = rs->ref.a.col_relative = !c)) {
rs->ref.a.col -= gee->pp.eval.col;
rs->ref.b.col -= gee->pp.eval.col;
} else {
rs->ref.a.col += gee->pp.eval.col;
rs->ref.b.col += gee->pp.eval.col;
}
gnm_cellref_set_col_ar (&rs->ref.a, &gee->pp, !c);
gnm_cellref_set_col_ar (&rs->ref.b, &gee->pp, !c);
gnm_cellref_set_row_ar (&rs->ref.a, &gee->pp, c^r);
gnm_cellref_set_row_ar (&rs->ref.b, &gee->pp, c^r);
}
gee_rangesel_update_text (gee);
......@@ -1148,8 +1124,8 @@ gnm_expr_entry_get_rangesel (GnmExprEntry const *gee,
gee_prepare_range (gee, &ref);
if (r != NULL) {
cellref_get_abs_pos (&ref.a, &gee->pp.eval, &r->start);
cellref_get_abs_pos (&ref.b, &gee->pp.eval, &r->end);
gnm_cellpos_init_cellref (&r->start, &ref.a, &gee->pp.eval);
gnm_cellpos_init_cellref (&r->end, &ref.b, &gee->pp.eval);
range_normalize (r);
}
......