[gnumeric] sheet duplicate: fix problem with array expressions.



commit c524767c9643f8712befe2350153a7a40a97deb2
Author: Morten Welinder <terra gnome org>
Date:   Mon May 3 12:50:20 2010 -0400

    sheet duplicate: fix problem with array expressions.

 ChangeLog   |    6 ++++++
 src/expr.c  |   13 +++++++++++--
 src/sheet.c |    7 ++++++-
 3 files changed, 23 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 63f74a2..2873e85 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2010-05-03  Morten Welinder  <terra gnome org>
 
+	* src/sheet.c (cb_sheet_cell_copy): Unwrap the array expression.
+
+	* src/expr.c (gnm_expr_is_array): New function.
+	(gnm_expr_new_array_corner): Complain if subexpression in a array.
+	(gnm_expr_top_is_array): Use gnm_expr_is_array.
+
 	* src/sheet.c (sheet_dup_cells): Queue recalc of the new sheet.
 	(cb_sheet_cell_copy): Don't copy computed values.
 
diff --git a/src/expr.c b/src/expr.c
index c9d8bb4..1e05800 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -261,6 +261,14 @@ gnm_expr_new_cellref (GnmCellRef const *cr)
 
 /***************************************************************************/
 
+static gboolean
+gnm_expr_is_array (GnmExpr const *expr)
+{
+	return expr &&
+		(GNM_EXPR_GET_OPER (expr) == GNM_EXPR_OP_ARRAY_ELEM ||
+		 GNM_EXPR_GET_OPER (expr) == GNM_EXPR_OP_ARRAY_CORNER);
+}
+
 /**
  * gnm_expr_new_array_corner :
  * @cols :
@@ -274,6 +282,8 @@ gnm_expr_new_array_corner(int cols, int rows, GnmExpr const *expr)
 {
 	GnmExprArrayCorner *ans;
 
+	g_return_val_if_fail (!gnm_expr_is_array (expr), NULL);
+
 	ans = CHUNK_ALLOC (GnmExprArrayCorner, expression_pool_big);
 	if (ans == NULL)
 		return NULL;
@@ -3117,8 +3127,7 @@ gboolean
 gnm_expr_top_is_array (GnmExprTop const *texpr)
 {
 	g_return_val_if_fail (IS_GNM_EXPR_TOP (texpr), FALSE);
-	return (GNM_EXPR_GET_OPER (texpr->expr) == GNM_EXPR_OP_ARRAY_ELEM ||
-		GNM_EXPR_GET_OPER (texpr->expr) == GNM_EXPR_OP_ARRAY_CORNER);
+	return gnm_expr_is_array (texpr->expr);
 }
 
 GnmExprTop const *
diff --git a/src/sheet.c b/src/sheet.c
index 4a503cf..0cdc8d6 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -5405,13 +5405,18 @@ cb_sheet_cell_copy (gpointer unused, gpointer key, gpointer new_sheet_param)
 	array = gnm_cell_is_array_corner (cell);
 
 	if (array) {
+		GnmExpr const *aexpr;
+
 		texpr = gnm_expr_top_relocate_sheet (texpr, src, dst);
+		array = gnm_expr_top_get_array_corner (texpr);
 
 		gnm_cell_set_array_formula (dst,
 			cell->pos.col, cell->pos.row,
 			cell->pos.col + array->cols-1,
 			cell->pos.row + array->rows-1,
-			texpr);
+			gnm_expr_top_new (gnm_expr_copy (array->expr)));
+
+		gnm_expr_top_unref (texpr);
 	} else if (texpr && gnm_expr_top_is_array_elem (texpr, NULL, NULL)) {
 		/* Not a corner -- ignore.  */
 	} else {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]