Commit 910cc0b7 authored by Miguel de Icaza's avatar Miguel de Icaza Committed by Arturo Espinosa

Reorganization. Hanlde VALUE_CELLREF here and make OPER_VAR and

1999-01-10  Miguel de Icaza  <miguel@nuclecu.unam.mx>

	* src/eval.c (add_value_deps): Reorganization.  Hanlde
	VALUE_CELLREF here and make OPER_VAR and OPER_CONSTANT call
	add_value_deps.

	* src/expr.c (do_expr_tree_relocate, expr_tree_relocate): New
	routine that returns an ExprTree relocated.
	(value_copy_to): Handle the VALUE_CELLREF type.

	* src/expr.h: define VALUE_CELLREF

	* src/parser.y (yylex): Type fix.
	When creating values of type VALUE_CELLREF, set this value.

1999-01-09  Miguel de Icaza  <miguel@nuclecu.unam.mx>

	* src/sheet.c (sheet_move_column): Update to new cell_relocate
	semantics.
	(sheet_shift_row): ditto.
	(sheet_insert_row): ditto.
	(sheet_delete_row): ditto.
	(sheet_shift_col): ditto.

	* src/clipboard.c: Update to new cell_relocate semantics.
	Remove the old GTK compatibility code.

	* src/cell.c (cell_relocate): We do not need to reference this
	formula.
	This routine now takes delta-x and delta-y values for the
	relocation, instead of absolute cordinates.  To implement the
	proper semantics of cell movement that other spreadsheets implement
parent 772d27cf
1999-01-10 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/eval.c (add_value_deps): Reorganization. Hanlde
VALUE_CELLREF here and make OPER_VAR and OPER_CONSTANT call
add_value_deps.
* src/expr.c (do_expr_tree_relocate, expr_tree_relocate): New
routine that returns an ExprTree relocated.
(value_copy_to): Handle the VALUE_CELLREF type.
* src/expr.h: define VALUE_CELLREF
* src/parser.y (yylex): Type fix.
When creating values of type VALUE_CELLREF, set this value.
1999-01-09 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_move_column): Update to new cell_relocate
semantics.
(sheet_shift_row): ditto.
(sheet_insert_row): ditto.
(sheet_delete_row): ditto.
(sheet_shift_col): ditto.
* src/clipboard.c: Update to new cell_relocate semantics.
Remove the old GTK compatibility code.
* src/cell.c (cell_relocate): We do not need to reference this
formula.
This routine now takes delta-x and delta-y values for the
relocation, instead of absolute cordinates. To implement the
proper semantics of cell movement that other spreadsheets implement
1999-01-09 Federico Mena Quintero <federico@nuclecu.unam.mx>
* src/gnumeric-sheet.c (gnumeric_sheet_key_mode_sheet): Return the
......
1999-01-10 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/eval.c (add_value_deps): Reorganization. Hanlde
VALUE_CELLREF here and make OPER_VAR and OPER_CONSTANT call
add_value_deps.
* src/expr.c (do_expr_tree_relocate, expr_tree_relocate): New
routine that returns an ExprTree relocated.
(value_copy_to): Handle the VALUE_CELLREF type.
* src/expr.h: define VALUE_CELLREF
* src/parser.y (yylex): Type fix.
When creating values of type VALUE_CELLREF, set this value.
1999-01-09 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_move_column): Update to new cell_relocate
semantics.
(sheet_shift_row): ditto.
(sheet_insert_row): ditto.
(sheet_delete_row): ditto.
(sheet_shift_col): ditto.
* src/clipboard.c: Update to new cell_relocate semantics.
Remove the old GTK compatibility code.
* src/cell.c (cell_relocate): We do not need to reference this
formula.
This routine now takes delta-x and delta-y values for the
relocation, instead of absolute cordinates. To implement the
proper semantics of cell movement that other spreadsheets implement
1999-01-09 Federico Mena Quintero <federico@nuclecu.unam.mx>
* src/gnumeric-sheet.c (gnumeric_sheet_key_mode_sheet): Return the
......
1999-01-10 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/eval.c (add_value_deps): Reorganization. Hanlde
VALUE_CELLREF here and make OPER_VAR and OPER_CONSTANT call
add_value_deps.
* src/expr.c (do_expr_tree_relocate, expr_tree_relocate): New
routine that returns an ExprTree relocated.
(value_copy_to): Handle the VALUE_CELLREF type.
* src/expr.h: define VALUE_CELLREF
* src/parser.y (yylex): Type fix.
When creating values of type VALUE_CELLREF, set this value.
1999-01-09 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_move_column): Update to new cell_relocate
semantics.
(sheet_shift_row): ditto.
(sheet_insert_row): ditto.
(sheet_delete_row): ditto.
(sheet_shift_col): ditto.
* src/clipboard.c: Update to new cell_relocate semantics.
Remove the old GTK compatibility code.
* src/cell.c (cell_relocate): We do not need to reference this
formula.
This routine now takes delta-x and delta-y values for the
relocation, instead of absolute cordinates. To implement the
proper semantics of cell movement that other spreadsheets implement
1999-01-09 Federico Mena Quintero <federico@nuclecu.unam.mx>
* src/gnumeric-sheet.c (gnumeric_sheet_key_mode_sheet): Return the
......
1999-01-10 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/eval.c (add_value_deps): Reorganization. Hanlde
VALUE_CELLREF here and make OPER_VAR and OPER_CONSTANT call
add_value_deps.
* src/expr.c (do_expr_tree_relocate, expr_tree_relocate): New
routine that returns an ExprTree relocated.
(value_copy_to): Handle the VALUE_CELLREF type.
* src/expr.h: define VALUE_CELLREF
* src/parser.y (yylex): Type fix.
When creating values of type VALUE_CELLREF, set this value.
1999-01-09 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_move_column): Update to new cell_relocate
semantics.
(sheet_shift_row): ditto.
(sheet_insert_row): ditto.
(sheet_delete_row): ditto.
(sheet_shift_col): ditto.
* src/clipboard.c: Update to new cell_relocate semantics.
Remove the old GTK compatibility code.
* src/cell.c (cell_relocate): We do not need to reference this
formula.
This routine now takes delta-x and delta-y values for the
relocation, instead of absolute cordinates. To implement the
proper semantics of cell movement that other spreadsheets implement
1999-01-09 Federico Mena Quintero <federico@nuclecu.unam.mx>
* src/gnumeric-sheet.c (gnumeric_sheet_key_mode_sheet): Return the
......
......@@ -15,6 +15,7 @@ GNOME Spread Sheet task list
account to render the number as well as possible given the space so
that for small regions, numbers in scientific notation are displayed.
*
* Sheet
* Auditing
......
......@@ -44,16 +44,6 @@ GNOMEGNORBA_LIBS="$GNOMEGNORBA_LIBS"
AC_SUBST(GNOMEGNORBA_LIBS)
dnl
dnl Compatibility with old Gtk+ (will be removed when new Gtk+ and gnome-libs go out).
dnl
OLD_LIBS="$LIBS"
LIBS="$LIBS $GTK_LIBS"
AC_CHECK_FUNC(gtk_selection_add_target, AC_DEFINE(HAVE_GTK_SELECTION_ADD_TARGET))
LIBS="$OLD_LIBS"
dnl **************************************************
dnl * Check for Perl
dnl **************************************************
......
......@@ -845,16 +845,16 @@ cell_comment_reposition (Cell *cell)
/*
* cell_relocate:
* @cell: The cell that is changing position
* @target_col: The new column
* @target_row: The new row.
* @cell: The cell that is changing position
* @col_diff: The column delta.
* @row_diff: The row delta .
*
* This routine is used to move a cell to a different location:
*
* Auxiliary items canvas items attached to the cell are moved.
*/
void
cell_relocate (Cell *cell, int target_col, int target_row)
cell_relocate (Cell *cell, int col_diff, int row_diff)
{
g_return_if_fail (cell != NULL);
......@@ -862,13 +862,19 @@ cell_relocate (Cell *cell, int target_col, int target_row)
cell_modified (cell);
/* 2. If the cell contains a formula, relocate the formula */
if (cell->parsed_node){
char *text, *formula;
if (col_diff != 0 || row_diff != 0){
if (cell->parsed_node){
ExprTree *new_tree;
char *text, *formula;
new_tree = expr_tree_relocate (cell->parsed_node, col_diff, row_diff);
expr_tree_ref (cell->parsed_node);
cell_formula_changed (cell);
expr_tree_unref (cell->parsed_node);
cell->parsed_node = new_tree;
cell_formula_changed (cell);
}
}
/* 3. Move any auxiliary canvas items */
if (cell->comment)
cell_comment_reposition (cell);
......
......@@ -121,7 +121,7 @@ void cell_set_alignment (Cell *cell, int halign, int valign,
void cell_set_halign (Cell *cell, StyleHAlignFlags halign);
void cell_set_rendered_text (Cell *cell, char *rendered_text);
void cell_relocate (Cell *cell,
int target_col, int target_row);
int col_diff, int row_diff);
void cell_get_span (Cell *cell, int *col1, int *col2);
char *cell_get_text (Cell *cell);
char *cell_get_content (Cell *cell);
......
......@@ -30,7 +30,14 @@ typedef struct {
int paste_flags;
} clipboard_paste_closure_t;
/*
/**
* paste_cell:
* @dest_sheet: The sheet where the pasting will be done
* @new_cell: The cell to paste.
* @target_col: Column to put the cell into
* @target_row: Row to put the cell into.
* @paste_flags: Bit mask that describes the paste options.
*
* Pastes a cell in the spreadsheet
*/
static int
......@@ -47,7 +54,7 @@ paste_cell (Sheet *dest_sheet, Cell *new_cell, int target_col, int target_row, i
if (new_cell->parsed_node){
if (paste_flags & PASTE_FORMULAS)
cell_relocate (new_cell, target_col, target_row);
cell_relocate (new_cell, 0, 0);
else
cell_make_value (new_cell);
}
......@@ -92,7 +99,7 @@ paste_cell_flags (Sheet *dest_sheet, int target_col, int target_row,
return 0;
}
/*
/**
* do_clipboard_paste_cell_region:
*
* region: a Cell Region that contains information to be pasted
......@@ -185,7 +192,11 @@ new_node (GList *list, char *data, char *p, int col, int row)
return g_list_prepend (list, c_copy);
}
/*
/**
* x_selection_to_cell_region:
* @data: points to an array of chars are received.
* @len: The lenght of the @data buffer as received.
*
* Creates a CellRegion based on the X selection
*
* We use \t, ; and "," as cell separators
......@@ -238,11 +249,7 @@ x_selection_to_cell_region (char *data, int len)
* This is triggered by a call we do to gtk_selection_convert.
*/
static void
#ifdef HAVE_GTK_SELECTION_ADD_TARGET
x_selection_received (GtkWidget *widget, GtkSelectionData *sel, guint time, gpointer data)
#else
x_selection_received (GtkWidget *widget, GtkSelectionData *sel, gpointer data)
#endif
{
SheetSelection *ss;
Workbook *wb = data;
......@@ -306,11 +313,7 @@ x_selection_received (GtkWidget *widget, GtkSelectionData *sel, gpointer data)
* Callback invoked when another application requests we render the selection.
*/
static void
#ifdef HAVE_GTK_SELECTION_ADD_TARGET
x_selection_handler (GtkWidget *widget, GtkSelectionData *selection_data, guint info, guint time, gpointer data)
#else
x_selection_handler (GtkWidget *widget, GtkSelectionData *selection_data, gpointer data)
#endif
{
Workbook *wb = (Workbook *) data;
char *rendered_selection;
......@@ -359,16 +362,9 @@ x_clipboard_bind_workbook (Workbook *wb)
GTK_OBJECT (wb->toplevel), "selection_get",
GTK_SIGNAL_FUNC(x_selection_handler), wb);
#ifdef HAVE_GTK_SELECTION_ADD_TARGET
gtk_selection_add_target (
wb->toplevel,
GDK_SELECTION_PRIMARY, GDK_SELECTION_TYPE_STRING, 0);
#else
gtk_selection_add_handler (
wb->toplevel,
GDK_SELECTION_PRIMARY, GDK_SELECTION_TYPE_STRING,
x_selection_handler, wb);
#endif
}
/**
......@@ -493,13 +489,8 @@ clipboard_paste_region (CellRegion *region, Sheet *dest_sheet,
GtkSelectionData sel;
sel.length = -1;
#ifdef HAVE_GTK_SELECTION_ADD_TARGET
x_selection_received (dest_sheet->workbook->toplevel, &sel,
0, dest_sheet->workbook);
#else
x_selection_received (dest_sheet->workbook->toplevel, &sel,
dest_sheet->workbook);
#endif
return;
}
......
......@@ -164,6 +164,14 @@ add_value_deps (Cell *cell, Value *value)
&value->v.cell_range.cell_a,
&value->v.cell_range.cell_b);
break;
case VALUE_CELLREF:
add_cell_range_deps (
cell,
&value->v.cell,
&value->v.cell);
return;
}
}
......@@ -193,6 +201,7 @@ add_tree_deps (Cell *cell, ExprTree *tree)
add_tree_deps (cell, tree->u.binary.value_b);
return;
case OPER_VAR:
case OPER_CONSTANT:
add_value_deps (cell, tree->u.constant);
return;
......@@ -202,13 +211,6 @@ add_tree_deps (Cell *cell, ExprTree *tree)
add_tree_deps (cell, l->data);
return;
case OPER_VAR:
add_cell_range_deps (
cell,
&tree->u.constant->v.cell,
&tree->u.constant->v.cell);
return;
case OPER_NEG:
add_tree_deps (cell, tree->u.value);
return;
......
......@@ -164,6 +164,14 @@ add_value_deps (Cell *cell, Value *value)
&value->v.cell_range.cell_a,
&value->v.cell_range.cell_b);
break;
case VALUE_CELLREF:
add_cell_range_deps (
cell,
&value->v.cell,
&value->v.cell);
return;
}
}
......@@ -193,6 +201,7 @@ add_tree_deps (Cell *cell, ExprTree *tree)
add_tree_deps (cell, tree->u.binary.value_b);
return;
case OPER_VAR:
case OPER_CONSTANT:
add_value_deps (cell, tree->u.constant);
return;
......@@ -202,13 +211,6 @@ add_tree_deps (Cell *cell, ExprTree *tree)
add_tree_deps (cell, l->data);
return;
case OPER_VAR:
add_cell_range_deps (
cell,
&tree->u.constant->v.cell,
&tree->u.constant->v.cell);
return;
case OPER_NEG:
add_tree_deps (cell, tree->u.value);
return;
......
......@@ -192,6 +192,9 @@ value_string (Value *value)
case VALUE_CELLRANGE:
return g_strdup ("Internal problem");
case VALUE_CELLREF:
g_assert_not_reached ();
}
return g_strdup (buffer);
}
......@@ -224,6 +227,9 @@ value_release (Value *value)
case VALUE_CELLRANGE:
break;
case VALUE_CELLREF:
break;
}
g_free (value);
......@@ -270,6 +276,10 @@ value_copy_to (Value *dest, Value *source)
case VALUE_CELLRANGE:
dest->v.cell_range = source->v.cell_range;
break;
case VALUE_CELLREF:
dest->v.cell = source->v.cell;
break;
}
}
......@@ -443,6 +453,14 @@ eval_cell_value (Sheet *sheet, Value *value)
case VALUE_CELLRANGE:
res->v.cell_range = value->v.cell_range;
break;
case VALUE_CELLREF:
/*
* This case shoudl be handled as part of the OPER_VAR
* case in the ExprTree, not here
*/
g_assert_not_reached ();
}
return res;
}
......@@ -873,10 +891,7 @@ eval_expr (void *asheet, ExprTree *tree, int eval_col, int eval_row, char **erro
case OPER_FUNCALL:
return eval_funcall (sheet, tree, eval_col, eval_row, error_string);
case OPER_CONSTANT:
return eval_cell_value (sheet, tree->u.constant);
case OPER_VAR:{
case OPER_VAR: {
Sheet *cell_sheet;
CellRef *ref;
Cell *cell;
......@@ -916,6 +931,10 @@ eval_expr (void *asheet, ExprTree *tree, int eval_col, int eval_row, char **erro
res->v.v_int = 0;
return res;
}
case OPER_CONSTANT:
return eval_cell_value (sheet, tree->u.constant);
case OPER_NEG:
a = eval_expr (sheet, tree->u.value,
eval_col, eval_row, error_string);
......@@ -1083,6 +1102,13 @@ do_expr_decode_tree (ExprTree *tree, void *sheet, int col, int row, Operation pa
return g_strconcat (fd->name, "()", NULL);
}
case OPER_VAR: {
CellRef *cell_ref;
cell_ref = &tree->u.constant->v.cell;
return cellref_name (cell_ref, sheet, col, row);
}
case OPER_CONSTANT: {
Value *v = tree->u.constant;
......@@ -1105,13 +1131,6 @@ do_expr_decode_tree (ExprTree *tree, void *sheet, int col, int row, Operation pa
return value_string (v);
}
}
case OPER_VAR: {
CellRef *cell_ref;
cell_ref = &tree->u.constant->v.cell;
return cellref_name (cell_ref, sheet, col, row);
}
}
g_warning ("ExprTree: This should not happen\n");
......@@ -1128,3 +1147,101 @@ expr_decode_tree (ExprTree *tree, void *sheet, int col, int row)
return do_expr_decode_tree (tree, sheet, col, row, OPER_CONSTANT);
}
static ExprTree *
do_expr_tree_relocate (ExprTree *tree, int coldiff, int rowdiff)
{
ExprTree *new_tree;
new_tree = g_new (ExprTree, 1);
*new_tree = *tree;
new_tree->ref_count = 1;
switch (tree->oper){
/* The binary operations */
case OPER_EQUAL:
case OPER_NOT_EQUAL:
case OPER_GT:
case OPER_GTE:
case OPER_LT:
case OPER_LTE:
case OPER_ADD:
case OPER_SUB:
case OPER_MULT:
case OPER_DIV:
case OPER_EXP:
case OPER_CONCAT: {
ExprTree *a, *b;
a = do_expr_tree_relocate (tree->u.binary.value_a, coldiff, rowdiff);
b = do_expr_tree_relocate (tree->u.binary.value_b, coldiff, rowdiff);
new_tree->u.binary.value_a = a;
new_tree->u.binary.value_b = b;
break;
}
case OPER_FUNCALL: {
GList *l, *arg_list;
GList *new_list = NULL;
tree->ref_count++;
arg_list = tree->u.function.arg_list;
for (l = arg_list; l; l = l->next){
ExprTree *tree = l->data;
new_list = g_list_append (
new_list,
do_expr_tree_relocate (tree, coldiff, rowdiff));
new_tree->u.function.arg_list = new_list;
}
symbol_ref (tree->u.function.symbol);
break;
}
case OPER_VAR:
case OPER_CONSTANT: {
CellRef *ref;
new_tree->u.constant = value_duplicate (tree->u.constant);
switch (new_tree->u.constant->type){
case VALUE_CELLREF:
ref = &new_tree->u.constant->v.cell;
ref->col -= coldiff;
ref->row -= rowdiff;
break;
case VALUE_CELLRANGE:
ref = &new_tree->u.constant->v.cell_range.cell_a;
ref->col -= coldiff;
ref->row -= rowdiff;
ref = &new_tree->u.constant->v.cell_range.cell_b;
ref->col -= coldiff;
ref->row -= rowdiff;
break;
default:
}
break;
}
case OPER_NEG:
new_tree->u.value = do_expr_tree_relocate (tree->u.value, coldiff, rowdiff);
break;
}
return new_tree;
}
ExprTree *
expr_tree_relocate (ExprTree *tree, int coldiff, int rowdiff)
{
g_return_val_if_fail (tree != NULL, NULL);
return do_expr_tree_relocate (tree, coldiff, rowdiff);
}
......@@ -29,6 +29,7 @@ typedef enum {
VALUE_FLOAT,
VALUE_CELLRANGE,
VALUE_ARRAY,
VALUE_CELLREF,
} ValueType;
typedef struct {
......@@ -135,7 +136,8 @@ void cell_get_abs_col_row (CellRef *cell_ref,
ExprTree *expr_parse_string (char *expr, void *sheet, int col, int row,
char **desired_format, char **error_msg);
ExprTree *expr_tree_duplicate (ExprTree *expr);
ExprTree *expr_tree_relocate (ExprTree *expr, int col_diff, int row_diff);
char *expr_decode_tree (ExprTree *tree, void *sheet,
int col, int row);
......
......@@ -82,7 +82,15 @@ function_iterate_do_value (Sheet *sheet,
return FALSE;
}
break;
case VALUE_CELLREF:
/*
* eval_expr will never return a value of
* type VALUE_CELLREF
*/
g_assert_not_reached ();
break;
case VALUE_CELLRANGE: {
IterateCallbackClosure data;
int start_col, start_row, end_col, end_row;
......
......@@ -209,7 +209,8 @@ return_cellref (char *p)
e = p_new (ExprTree);
e->ref_count = 1;
v = v_new ();
v->type = VALUE_CELLREF;
e->oper = OPER_VAR;
ref = &v->v.cell;
......@@ -243,77 +244,6 @@ return_sheetref (Sheet *sheet)
return SHEETREF;
}
static int
old_return_symbol (char *string)
{
ExprTree *e = p_new (ExprTree);
Symbol *sym;
int type;
#warning remove me after testing the new code.
e->ref_count = 1;
sym = symbol_lookup (global_symbol_table, string);
type = STRING;
if (!sym)
{
Value *v = v_new ();
double fv;
char *format;
/*
* Try to match the entered text against any
* of the known number formating codes, if this
* succeeds, we store this as a float + format,
* otherwise, we return a string.
*/
if (format_match (string, &fv, &format)){
v->type = VALUE_FLOAT;
v->v.v_float = fv;
if (!parser_desired_format)
parser_desired_format = format;
} else {
v->v.str = string_get (string);
v->type = VALUE_STRING;
}
e->oper = OPER_CONSTANT;
e->u.constant = v;
}
else
{
symbol_ref (sym);
switch (sym->type){
case SYMBOL_FUNCTION:
e->oper = OPER_FUNCALL;
type = FUNCALL;
e->u.function.symbol = sym;
e->u.function.arg_list = NULL;
break;
case SYMBOL_VALUE:
case SYMBOL_STRING: {
Value *v, *dv;
/* Make a copy of the value */
dv = (Value *) sym->data;
v = v_new ();
value_copy_to (v, dv);
e->oper = OPER_CONSTANT;
e->u.constant = v;
type = CONSTANT;
break;
}
} /* switch */
register_symbol (sym);
}
yylval.tree = e;
return type;
}
static int
make_string_return (char *string)
{
......@@ -483,7 +413,7 @@ int yylex (void)
case '"': {
char *string, *s;
int v;
char *quotes_end = c;
char quotes_end = c;
p = parser_expr;
while(*parser_expr && *parser_expr != quotes_end) {
......
......@@ -615,7 +615,9 @@ col_row_distance (GList *list, int from, int to, int default_pixels)
return pixels;
}
/*
/**
* sheet_col_get_distance:
*
* Return the number of pixels between from_col to to_col
*/
int
......@@ -627,7 +629,9 @@ sheet_col_get_distance (Sheet *sheet, int from_col, int to_col)
return col_row_distance (sheet->cols_info, from_col, to_col, sheet->default_col_style.pixels);
}
/*
/**
* sheet_row_get_distance:
*
* Return the number of pixels between from_row to to_row
*/
int
......@@ -885,7 +889,7 @@ sheet_start_editing_at_cursor (Sheet *sheet)
}
}
/*
/**
* sheet_update_controls:
*
* This routine is ran every time the seleciton has changed. It checks
......@@ -1011,8 +1015,8 @@ sheet_selection_append (Sheet *sheet, int col, int row)
sheet_selection_append_range (sheet, col, row, col, row, col, row);
}
/*
* sheet_selection_extend_to
/**
* sheet_selection_extend_to:
* @sheet: the sheet
* @col: column that gets covered
* @row: row that gets covered
......@@ -1076,7 +1080,8 @@ sheet_selection_extend_to (Sheet *sheet, int col, int row)
sheet_redraw_rows (sheet);
}