Commit dafaeb02 authored by Jody Goldberg's avatar Jody Goldberg
Browse files

Bounds check copied expressions.

parent f53be0c0
1999-11-19 Jody Goldberg <jgoldberg@home.com>
* src/cell.c (cell_relocate) : optionally do a bounds check on
relocated expressions. Do this by 'moving' the expression from its
new location to its new location. Some extra work is performed but
the expression is checked for boundedness.
* src/sheet.c (sheet_move_range) : Use new interface for
cell_relocate.
(colrow_move) : Ditto.
* src/clipboard.c (paste_cell) : Ditto.
* src/item-bar.c (item_bar_fonts_init) : Use the sheet's zoom factor.
(item_bar_realize) : Adjust to new item_bar_fonts_init interface.
......
1999-11-19 Jody Goldberg <jgoldberg@home.com>
* src/cell.c (cell_relocate) : optionally do a bounds check on
relocated expressions. Do this by 'moving' the expression from its
new location to its new location. Some extra work is performed but
the expression is checked for boundedness.
* src/sheet.c (sheet_move_range) : Use new interface for
cell_relocate.
(colrow_move) : Ditto.
* src/clipboard.c (paste_cell) : Ditto.
* src/item-bar.c (item_bar_fonts_init) : Use the sheet's zoom factor.
(item_bar_realize) : Adjust to new item_bar_fonts_init interface.
......
......@@ -112,7 +112,7 @@ cell_set_formula (Cell *cell, const char *text)
return;
}
/*
/*
* NOTE : The wrapper supplied by the parser will be released
* and recreated. new_expr will NOT be valid on exit
* from cell_set_array_formula.
......@@ -360,7 +360,7 @@ cell_get_formatted_val (Cell *cell, StyleColor **col)
{
MStyle *mstyle;
char *txt;
mstyle = sheet_style_compute (cell->sheet, cell->col->pos,
cell->row->pos);
if (mstyle_is_element_set (mstyle, MSTYLE_FORMAT))
......@@ -489,7 +489,7 @@ cell_set_text_simple (Cell *cell, const char *text)
set = 1;
}
}
if (!set) {
double d;
d = strtod (text, &end);
......@@ -593,7 +593,7 @@ cell_set_formula_tree_simple (Cell *cell, ExprTree *formula)
* @col_b: The right column in the destination region.
* @formula: an expression tree with the formula
*
* Uses cell_set_formula_tree_simple to store the formula as an
* Uses cell_set_formula_tree_simple to store the formula as an
* 'array-formula'. The supplied expression is wrapped in an array
* operator for each cell in the range and scheduled for recalc. The
* upper left corner is handled as a special case and care is taken to
......@@ -856,14 +856,15 @@ cell_comment_reposition (Cell *cell)
/*
* cell_relocate:
* @cell: The cell that is changing position
* @cell: The cell that is changing position
* @check_bonunds : Should expressions be bounds checked.
*
* 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)
cell_relocate (Cell *cell, gboolean const check_bounds)
{
g_return_if_fail (cell != NULL);
......@@ -893,6 +894,30 @@ cell_relocate (Cell *cell)
cell->row->pos - y);
}
/* We do not actually need to change any references
* the move is from its current location to its current
* location. All the move is doing is a bounds check.
*/
if (check_bounds) {
struct expr_relocate_info rinfo;
EvalPosition pos;
ExprTree *expr = cell->parsed_node;
rinfo.origin.start.col =
rinfo.origin.end.col = cell->col->pos;
rinfo.origin.start.row =
rinfo.origin.end.row = cell->row->pos;
rinfo.origin_sheet = rinfo.target_sheet = cell->sheet;
rinfo.col_offset = 0;
rinfo.row_offset = 0;
expr = expr_relocate (expr, eval_pos_cell (&pos, cell), &rinfo);
if (expr != NULL) {
expr_tree_unref (cell->parsed_node);
cell->parsed_node = expr;
}
}
/* The following call also relinks the cell. */
cell_formula_changed (cell);
}
......@@ -1406,8 +1431,8 @@ cell_set_mstyle (const Cell *cell, MStyle *mstyle)
/**
* cell_style_changed:
* @cell:
*
* @cell:
*
* Re-draws as neccessary on a cells span, and re-calcs dimensions.
* to test, enter a long string in a cell & alter
* the horizontal alignment.
......
......@@ -151,7 +151,7 @@ void cell_set_rendered_text (Cell *cell, const char *rendered_text)
MStyle *cell_get_mstyle (const Cell *cell);
void cell_set_mstyle (const Cell *cell, MStyle *mstyle);
void cell_style_changed (Cell *cell);
void cell_relocate (Cell *cell);
void cell_relocate (Cell *cell, gboolean const check_bounds);
void cell_get_span (Cell *cell, int *col1, int *col2);
char *cell_get_text (Cell *cell);
......
......@@ -45,28 +45,28 @@ paste_cell (Sheet *dest_sheet, Cell *new_cell,
{
g_return_val_if_fail (target_col < SHEET_MAX_COLS, 0);
g_return_val_if_fail (target_row < SHEET_MAX_ROWS, 0);
sheet_cell_add (dest_sheet, new_cell, target_col, target_row);
if (!(paste_flags & PASTE_FORMULAS)){
if (new_cell->parsed_node){
expr_tree_unref (new_cell->parsed_node);
new_cell->parsed_node = NULL;
}
}
if (new_cell->parsed_node){
if (paste_flags & PASTE_FORMULAS){
cell_relocate (new_cell);
cell_relocate (new_cell, TRUE);
cell_content_changed (new_cell);
}
else
else
cell_make_value (new_cell);
}
if (new_cell->value)
cell_render_value (new_cell);
sheet_redraw_cell_region (dest_sheet,
target_col, target_row,
target_col, target_row);
......@@ -91,12 +91,12 @@ paste_cell_flags (Sheet *dest_sheet, int target_col, int target_row,
}
} else {
Cell *new_cell;
if (c_copy->type != CELL_COPY_TYPE_TEXT) {
Range r;
new_cell = cell_copy (c_copy->u.cell.cell);
r.start.col = target_col;
r.start.row = target_row;
r.end.col = target_col;
......@@ -106,7 +106,7 @@ paste_cell_flags (Sheet *dest_sheet, int target_col, int target_row,
sheet_style_attach (dest_sheet, r,
c_copy->u.cell.mstyle);
}
return paste_cell (
dest_sheet, new_cell,
target_col, target_row, paste_flags);
......@@ -155,7 +155,7 @@ do_clipboard_paste_cell_region (CellRegion *region, Sheet *dest_sheet,
dest_col, dest_row,
dest_col + paste_width - 1,
dest_row + paste_height - 1);
/* Paste each element */
if (paste_flags & PASTE_TRANSPOSE) {
col_inc = region->rows;
......@@ -178,7 +178,7 @@ do_clipboard_paste_cell_region (CellRegion *region, Sheet *dest_sheet,
target_col = col + dest_col + c_copy->col_offset;
target_row = row + dest_row + c_copy->row_offset;
}
if (target_col > dest_col + paste_width - 1)
continue;
......@@ -191,7 +191,7 @@ do_clipboard_paste_cell_region (CellRegion *region, Sheet *dest_sheet,
}
}
}
deps = region_get_dependencies (
dest_sheet,
dest_col, dest_row,
......@@ -217,24 +217,24 @@ new_node (GList *list, char *data, char *p, int col, int row)
/* Eliminate spaces */
while (*data == ' ' && *data)
data++;
text = g_malloc (p-data+1);
text = strncpy (text, data, p-data);
text [p-data] = 0;
c_copy = g_new (CellCopy, 1);
c_copy->type = CELL_COPY_TYPE_TEXT;
c_copy->col_offset = col;
c_copy->row_offset = row;
c_copy->u.text = text;
return g_list_prepend (list, c_copy);
}
/**
* x_selection_to_cell_region:
* @data: points to an array of chars are received.
* @len: The length of the @data buffer as received.
* @len: The length of the @data buffer as received.
*
* Creates a CellRegion based on the X selection
*
......@@ -254,7 +254,7 @@ x_selection_to_cell_region (char *data, int len)
if (*p == '\t' || *p == ';' || *p == ',' || *p == '\n'){
if (p != data)
list = new_node (list, data, p, cur_col, rows);
if (*p == '\n'){
rows++;
cur_col = 0;
......@@ -275,9 +275,9 @@ x_selection_to_cell_region (char *data, int len)
if (cur_col > cols)
cols = cur_col;
}
/* Return the CellRegion */
cr = g_new (CellRegion, 1);
cr = g_new (CellRegion, 1);
cr->list = list;
cr->cols = cols ? cols : 1;
cr->rows = rows + 1;
......@@ -310,10 +310,10 @@ sheet_paste_selection (Sheet *sheet, CellRegion *content, SheetSelection *ss, cl
paste_width = SHEET_MAX_COLS - pc->dest_col;
if (pc->dest_row + paste_height > SHEET_MAX_ROWS)
paste_height = SHEET_MAX_ROWS - pc->dest_row;
if (pc->paste_flags & PASTE_TRANSPOSE){
int t;
end_col = pc->dest_col + paste_height - 1;
end_row = pc->dest_row + paste_width - 1;
......@@ -368,7 +368,7 @@ x_selection_received (GtkWidget *widget, GtkSelectionData *sel, guint time, gpoi
CellRegion *content;
ss = pc->dest_sheet->selections->data;
/* Did X provide any selection? */
if (sel->length < 0){
content = pc->region;
......@@ -378,7 +378,7 @@ x_selection_received (GtkWidget *widget, GtkSelectionData *sel, guint time, gpoi
content = x_selection_to_cell_region (sel->data, sel->length);
sheet_paste_selection (pc->dest_sheet, content, ss, pc);
/* Release the resources we used */
if (sel->length >= 0)
clipboard_release (content);
......@@ -401,7 +401,7 @@ x_selection_handler (GtkWidget *widget, GtkSelectionData *selection_data, guint
gboolean content_needs_free = FALSE;
CellRegion *clipboard = application_clipboard_contents_get ();
char *rendered_selection;
if (clipboard == NULL) {
Sheet *sheet = application_clipboard_sheet_get ();
Range const *a = application_clipboard_area_get ();
......@@ -415,7 +415,7 @@ x_selection_handler (GtkWidget *widget, GtkSelectionData *selection_data, guint
g_return_if_fail (clipboard != NULL);
rendered_selection = cell_region_render_ascii (clipboard);
gtk_selection_data_set (
selection_data, GDK_SELECTION_TYPE_STRING, 8,
rendered_selection, strlen (rendered_selection));
......@@ -449,7 +449,7 @@ x_clipboard_bind_workbook (Workbook *wb)
{
wb->have_x_selection = FALSE;
wb->clipboard_paste_callback_data = NULL;
gtk_signal_connect (
GTK_OBJECT (wb->toplevel), "selection_clear_event",
GTK_SIGNAL_FUNC (x_selection_clear), wb);
......@@ -501,7 +501,7 @@ clipboard_prepend_cell (Sheet *sheet, int col, int row, Cell *cell, void *user_d
copy->u.cell.mstyle = sheet_style_compute (sheet, col, row);
copy->col_offset = col - c->base_col;
copy->row_offset = row - c->base_row;
c->r->list = g_list_prepend (c->r->list, copy);
return NULL;
......@@ -518,7 +518,7 @@ clipboard_copy_cell_range (Sheet *sheet,
int end_col, int end_row)
{
append_cell_closure_t c;
g_return_val_if_fail (sheet != NULL, NULL);
g_return_val_if_fail (IS_SHEET (sheet), NULL);
g_return_val_if_fail (start_col <= end_col, NULL);
......@@ -530,7 +530,7 @@ clipboard_copy_cell_range (Sheet *sheet,
c.base_row = start_row;
c.r->cols = end_col - start_col + 1;
c.r->rows = end_row - start_row + 1;
sheet_cell_foreach_range (
sheet, TRUE, start_col, start_row, end_col, end_row,
clipboard_prepend_cell, &c);
......@@ -539,7 +539,7 @@ clipboard_copy_cell_range (Sheet *sheet,
c.r->list = g_list_reverse (c.r->list);
clipboard_export_cell_region (sheet->workbook);
return c.r;
}
......@@ -547,7 +547,7 @@ static gboolean
workbook_selection_locator (Workbook *wb, gpointer data)
{
Workbook **target = data;
if (wb->have_x_selection)
*target = wb;
......@@ -558,7 +558,7 @@ static Workbook *
find_local_workbook_with_selection (void)
{
Workbook *result = NULL;
workbook_foreach (workbook_selection_locator, &result);
return result;
......@@ -582,12 +582,12 @@ clipboard_paste_region (CellRegion *region, Sheet *dest_sheet,
{
clipboard_paste_closure_t *data;
Workbook *workbook_holding_selection;
g_return_if_fail (dest_sheet != NULL);
g_return_if_fail (IS_SHEET (dest_sheet));
if (dest_sheet->workbook->clipboard_paste_callback_data != NULL) {
g_free (dest_sheet->workbook->clipboard_paste_callback_data);
g_free (dest_sheet->workbook->clipboard_paste_callback_data);
dest_sheet->workbook->clipboard_paste_callback_data = NULL;
}
......@@ -618,11 +618,11 @@ clipboard_paste_region (CellRegion *region, Sheet *dest_sheet,
workbook_holding_selection = find_local_workbook_with_selection ();
if (workbook_holding_selection && region){
CellRegion *content;
content = region;
sheet_paste_selection (dest_sheet, content, dest_sheet->selections->data, data);
/* Check that this has not already been freed */
if (workbook_holding_selection->clipboard_paste_callback_data != NULL) {
workbook_holding_selection->clipboard_paste_callback_data = NULL;
......@@ -646,10 +646,10 @@ clipboard_release (CellRegion *region)
CellCopyList *l;
g_return_if_fail (region != NULL);
for (l = region->list; l; l = l->next){
CellCopy *this_cell = l->data;
if (this_cell->type != CELL_COPY_TYPE_TEXT) {
/* The cell is not really in the rows or columns */
this_cell->u.cell.cell->sheet = NULL;
......@@ -667,4 +667,3 @@ clipboard_release (CellRegion *region)
g_free (region);
}
......@@ -3109,7 +3109,7 @@ colrow_move (Sheet *sheet,
cell = cells->data;
sheet_cell_add_to_hash (sheet, cell);
cell_relocate (cell);
cell_relocate (cell, FALSE);
}
}
......@@ -3463,7 +3463,7 @@ sheet_move_range (struct expr_relocate_info const * rinfo)
sheet_cell_formula_link (cell);
/* Move comments */
cell_relocate (cell);
cell_relocate (cell, FALSE);
}
/* 5. Slide styles */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment