[gnumeric] code simplification in ODF exporter of conditional formats



commit 031477de03d8aac9cfee75101007739f2f042f18
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Mon May 21 00:54:01 2012 -0600

    code simplification in ODF exporter of conditional formats
    
    2012-05-20  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-write.c (odf_save_style_map_single_f): change arguments
    	(odf_save_style_map_double_f): ditto
    	(odf_determine_base): change arguments and simplify
    	(odf_save_style_map): change the calls to the above

 plugins/openoffice/ChangeLog          |    7 ++
 plugins/openoffice/openoffice-write.c |  126 +++++++++++++++------------------
 2 files changed, 64 insertions(+), 69 deletions(-)
---
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index b96a216..22d0bc5 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,5 +1,12 @@
 2012-05-20  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* openoffice-write.c (odf_save_style_map_single_f): change arguments
+	(odf_save_style_map_double_f): ditto
+	(odf_determine_base): change arguments and simplify
+	(odf_save_style_map): change the calls to the above
+
+2012-05-20  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* openoffice-write.c (odf_save_style_map_single_f): add arguments
 	(odf_save_style_map_double_f): ditto
 	(odf_determine_base): new
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 5cf6b07..5094a29 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -1460,26 +1460,23 @@ odf_find_style (GnmOOExport *state, GnmStyle const *style)
 }
 
 static void
-odf_save_style_map_single_f (GnmOOExport *state, GString *str, GnmExprTop const *texpr, int col, int row)
+odf_save_style_map_single_f (GnmOOExport *state, GString *str, GnmExprTop const *texpr, GnmParsePos *pp)
 {
 	char *formula;
-	GnmParsePos pp;
-
-	parse_pos_init (&pp, WORKBOOK (state->wb), state->sheet, col, row);
 
-	formula = gnm_expr_top_as_string (texpr, &pp, state->conv);
+	formula = gnm_expr_top_as_string (texpr, pp, state->conv);
 	g_string_append (str, formula);
 	g_free (formula);
 }
 
 
 static void
-odf_save_style_map_double_f (GnmOOExport *state, GString *str, GnmStyleCond const *cond, int col, int row)
+odf_save_style_map_double_f (GnmOOExport *state, GString *str, GnmStyleCond const *cond, GnmParsePos *pp)
 {
 	g_string_append_c (str, '(');
-	odf_save_style_map_single_f (state, str, cond->texpr[0], col, row);
+	odf_save_style_map_single_f (state, str, cond->texpr[0], pp);
 	g_string_append_c (str, ',');
-	odf_save_style_map_single_f (state, str, cond->texpr[1], col, row);
+	odf_save_style_map_single_f (state, str, cond->texpr[1], pp);
 	g_string_append_c (str, ')');
 }
 
@@ -1494,27 +1491,20 @@ odf_strip_brackets (char *string)
 }
 
 static void
-odf_determine_base (GnmOOExport *state, GnmExprTop const *texpr1, GnmExprTop const *texpr2, GnmRange *r)
+odf_determine_base (GnmOOExport *state, GnmExprTop const *texpr1, GnmExprTop const *texpr2, GnmParsePos *pp)
 {
-	GnmRange bound1, bound2;
+	GnmRange r;
 
-	if (texpr1 == NULL && texpr2 == NULL)
-		return;
-	if (texpr1) {
-		range_init_full_sheet (&bound1, state->sheet);
-		gnm_expr_top_get_boundingbox (texpr1, state->sheet, &bound1);
-	}
-	if (texpr2) {
-		range_init_full_sheet (&bound2, state->sheet);
-		gnm_expr_top_get_boundingbox (texpr2, state->sheet, &bound2);
-	}
-	if (texpr1 && texpr2) {
-		if (!range_intersection (r, &bound1, &bound2))
-			range_init_full_sheet (r, state->sheet);
-	} else if (texpr1)
-		*r = bound1;
-	else
-		*r = bound2;
+	range_init_full_sheet (&r, state->sheet);
+
+	if (texpr1) 
+		gnm_expr_top_get_boundingbox (texpr1, state->sheet, &r);
+	if (texpr2)
+		gnm_expr_top_get_boundingbox (texpr2, state->sheet, &r);
+
+	/* We should be able to use the following, but it doesn't work in the 'common' situation. */
+	/* parse_pos_init (pp, (Workbook *) state->wb, state->sheet, r.start.col, r.start.row); */
+	parse_pos_init (pp, (Workbook *) state->wb, state->sheet, r.end.col + 1, r.end.row + 1);
 }
 
 static void
@@ -1525,54 +1515,52 @@ odf_save_style_map (GnmOOExport *state, GnmStyleCond const *cond)
 	gchar *address;
 	GnmExprTop const *texpr = NULL;
 	GnmCellRef ref;
-	GnmRange r;
 	GnmParsePos pp;
 
 	g_return_if_fail (name != NULL);
 
-	range_init_full_sheet (&r, state->sheet);
 	str = g_string_new (NULL);
 
 	switch (cond->op) {
 	case GNM_STYLE_COND_BETWEEN:
-		odf_determine_base (state, cond->texpr[0], cond->texpr[1], &r);
+		odf_determine_base (state, cond->texpr[0], cond->texpr[1], &pp);
 		g_string_append (str, "of:cell-content-is-between");
-		odf_save_style_map_double_f (state, str, cond, r.end.col + 1, r.end.row + 1);
+		odf_save_style_map_double_f (state, str, cond, &pp);
 		break;
 	case GNM_STYLE_COND_NOT_BETWEEN:
-		odf_determine_base (state, cond->texpr[0], cond->texpr[1], &r);
+		odf_determine_base (state, cond->texpr[0], cond->texpr[1], &pp);
 		g_string_append (str, "of:cell-content-is-not-between");
-		odf_save_style_map_double_f (state, str, cond, r.end.col + 1, r.end.row + 1);
+		odf_save_style_map_double_f (state, str, cond, &pp);
 		break;
 	case GNM_STYLE_COND_EQUAL:
-		odf_determine_base (state, cond->texpr[0], NULL, &r);
+		odf_determine_base (state, cond->texpr[0], NULL, &pp);
 		g_string_append (str, "of:cell-content()=");
-		odf_save_style_map_single_f (state, str, cond->texpr[0], r.end.col + 1, r.end.row + 1);
+		odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
 		break;
 	case GNM_STYLE_COND_NOT_EQUAL:
-		odf_determine_base (state, cond->texpr[0], NULL, &r);
+		odf_determine_base (state, cond->texpr[0], NULL, &pp);
 		g_string_append (str, "of:cell-content()!=");
-		odf_save_style_map_single_f (state, str, cond->texpr[0], r.end.col + 1, r.end.row + 1);
+		odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
 		break;
 	case GNM_STYLE_COND_GT:
-		odf_determine_base (state, cond->texpr[0], NULL, &r);
+		odf_determine_base (state, cond->texpr[0], NULL, &pp);
 		g_string_append (str, "of:cell-content()>");
-		odf_save_style_map_single_f (state, str, cond->texpr[0], r.end.col + 1, r.end.row + 1);
+		odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
 		break;
 	case GNM_STYLE_COND_LT:
-		odf_determine_base (state, cond->texpr[0], NULL, &r);
+		odf_determine_base (state, cond->texpr[0], NULL, &pp);
 		g_string_append (str, "of:cell-content()<");
-		odf_save_style_map_single_f (state, str, cond->texpr[0], r.end.col + 1, r.end.row + 1);
+		odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
 		break;
 	case GNM_STYLE_COND_GTE:
-		odf_determine_base (state, cond->texpr[0], NULL, &r);
+		odf_determine_base (state, cond->texpr[0], NULL, &pp);
 		g_string_append (str, "of:cell-content()>=");
-		odf_save_style_map_single_f (state, str, cond->texpr[0], r.end.col + 1, r.end.row + 1);
+		odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
 		break;
 	case GNM_STYLE_COND_LTE:
-		odf_determine_base (state, cond->texpr[0], NULL, &r);
+		odf_determine_base (state, cond->texpr[0], NULL, &pp);
 		g_string_append (str, "of:cell-content()<=");
-		odf_save_style_map_single_f (state, str, cond->texpr[0], r.end.col + 1, r.end.row + 1);
+		odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
 		break;
 	case GNM_STYLE_COND_CONTAINS_ERR:
 		g_string_append (str, "of:is-true-formula(ISERROR([.A1]))");
@@ -1581,50 +1569,50 @@ odf_save_style_map (GnmOOExport *state, GnmStyleCond const *cond)
 		g_string_append (str, "of:is-true-formula(NOT(ISERROR([.A1])))");
 		break;
 	case GNM_STYLE_COND_CONTAINS_STR:
-		odf_determine_base (state, cond->texpr[0], NULL, &r);
+		odf_determine_base (state, cond->texpr[0], NULL, &pp);
 		g_string_append (str, "of:is-true-formula(NOT(ISERROR(FIND(");
-		odf_save_style_map_single_f (state, str, cond->texpr[0], r.end.col + 1, r.end.row + 1);
+		odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
 		g_string_append_printf (str, ";[.%s%s]))))", 
-					col_name (r.end.col), row_name (r.end.row));
+					col_name (pp.eval.col), row_name (pp.eval.row));
 		break;
 	case GNM_STYLE_COND_NOT_CONTAINS_STR:
-		odf_determine_base (state, cond->texpr[0], NULL, &r);
+		odf_determine_base (state, cond->texpr[0], NULL, &pp);
 		g_string_append (str, "of:is-true-formula(ISERROR(FIND(");
-		odf_save_style_map_single_f (state, str, cond->texpr[0], r.end.col + 1, r.end.row + 1);
+		odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
 		g_string_append_printf (str, ";[.%s%s])))", 
-					col_name (r.end.col), row_name (r.end.row));
+					col_name (pp.eval.col), row_name (pp.eval.row));
 		break;
 	case GNM_STYLE_COND_BEGINS_WITH_STR:
-		odf_determine_base (state, cond->texpr[0], NULL, &r);
+		odf_determine_base (state, cond->texpr[0], NULL, &pp);
 
 		g_string_append (str, "of:is-true-formula(IFERROR(FIND(");
-		odf_save_style_map_single_f (state, str, cond->texpr[0], r.end.col + 1, r.end.row + 1);
+		odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
 		g_string_append_printf (str, ";[.%s%s]);2)=1)", 
-					col_name (r.end.col), row_name (r.end.row));
+					col_name (pp.eval.col), row_name (pp.eval.row));
 		break;
 	case GNM_STYLE_COND_NOT_BEGINS_WITH_STR:
-		odf_determine_base (state, cond->texpr[0], NULL, &r);
+		odf_determine_base (state, cond->texpr[0], NULL, &pp);
 		g_string_append (str, "of:is-true-formula(NOT(IFERROR(FIND(");
-		odf_save_style_map_single_f (state, str, cond->texpr[0], r.end.col + 1, r.end.row + 1);
+		odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
 		g_string_append_printf (str, ";[.%s%s]);2)=1))", 
-					col_name (r.end.col), row_name (r.end.row));
+					col_name (pp.eval.col), row_name (pp.eval.row));
 		break;
 	case GNM_STYLE_COND_ENDS_WITH_STR:
-		odf_determine_base (state, cond->texpr[0], NULL, &r);
+		odf_determine_base (state, cond->texpr[0], NULL, &pp);
 		g_string_append (str, "of:is-true-formula(EXACT(");
-		odf_save_style_map_single_f (state, str, cond->texpr[0], r.end.col + 1, r.end.row + 1);
+		odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
 		g_string_append_printf (str, ";RIGHT([.%s%s];LEN(", 
-					col_name (r.end.col), row_name (r.end.row));
-		odf_save_style_map_single_f (state, str, cond->texpr[0], r.end.col + 1, r.end.row + 1);
+					col_name (pp.eval.col), row_name (pp.eval.row));
+		odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
 		g_string_append (str, ")))");
 		break;
 	case GNM_STYLE_COND_NOT_ENDS_WITH_STR:
-		odf_determine_base (state, cond->texpr[0], NULL, &r);
+		odf_determine_base (state, cond->texpr[0], NULL, &pp);
 		g_string_append (str, "of:is-true-formula(NOT(EXACT(");
-		odf_save_style_map_single_f (state, str, cond->texpr[0], r.end.col + 1, r.end.row + 1);
+		odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
 		g_string_append_printf (str, ";RIGHT([.%s%s];LEN(", 
-					col_name (r.end.col), row_name (r.end.row));
-		odf_save_style_map_single_f (state, str, cond->texpr[0], r.end.col + 1, r.end.row + 1);
+					col_name (pp.eval.col), row_name (pp.eval.row));
+		odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
 		g_string_append (str, "))))");
 		break;
 	case GNM_STYLE_COND_CONTAINS_BLANKS:
@@ -1634,9 +1622,9 @@ odf_save_style_map (GnmOOExport *state, GnmStyleCond const *cond)
 		g_string_append (str, "of:is-true-formula(ISERROR(FIND(\" \";[.A1])))");
 		break;
 	case GNM_STYLE_COND_CUSTOM:
-		odf_determine_base (state, cond->texpr[0], NULL, &r);
+		odf_determine_base (state, cond->texpr[0], NULL, &pp);
 		g_string_append (str, "of:is-true-formula(");
-		odf_save_style_map_single_f (state, str, cond->texpr[0], r.end.col + 1, r.end.row + 1);
+		odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
 		g_string_append (str, ")");
 		break;
 	default:
@@ -1652,9 +1640,9 @@ odf_save_style_map (GnmOOExport *state, GnmStyleCond const *cond)
 	/* ODF 1.2 requires a sheet name for the base-cell-address */
 	/* This is really only needed if we included a formula      */
 	gnm_cellref_init (&ref, (Sheet *)state->sheet,
-			  r.end.col + 1, r.end.row + 1, FALSE);
+			  pp.eval.col, pp.eval.row, FALSE);
 	texpr =  gnm_expr_top_new (gnm_expr_new_cellref (&ref));
-	parse_pos_init (&pp, (Workbook *)state->wb, state->sheet,0,0);
+	parse_pos_init_sheet (&pp, state->sheet);
 	address = gnm_expr_top_as_string (texpr, &pp, state->conv);
 	gsf_xml_out_add_cstr (state->xml, STYLE "base-cell-address", odf_strip_brackets (address));
 	g_free (address);



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