[gnumeric] Import more validations from ODF.



commit afaf2e675fff0dc890c94c6f3b70277ce0455624
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Thu May 12 01:58:41 2011 -0600

    Import more validations from ODF.
    
    2011-05-12  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-read.c (odf_validation_new_general): new
    	(odf_validation_new_tlength): new
    	(odf_validations_translate): connect odf_validation_new_tlength

 NEWS                                 |    1 +
 plugins/openoffice/ChangeLog         |    6 ++
 plugins/openoffice/openoffice-read.c |   92 +++++++++++++++++++++++++++++++++-
 3 files changed, 98 insertions(+), 1 deletions(-)
---
diff --git a/NEWS b/NEWS
index b2c0be1..aec7b99 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,7 @@ Andreas:
 	* Some ODF 1.2 export fixes including [#649906] and [#649914].
 	* Export external references to ODF.
 	* Fix ODF style handling on import. [#649851]
+	* Import more validations from ODF.
 
 Morten:
 	* Fix problems with localized function docs.
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index c166c0d..f26d9dd 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,9 @@
+2011-05-12  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* openoffice-read.c (odf_validation_new_general): new
+	(odf_validation_new_tlength): new
+	(odf_validations_translate): connect odf_validation_new_tlength
+
 2011-05-11  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* openoffice-read.c: change all styles into partial style and use
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index ff878e2..0a2007a 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -1496,6 +1496,96 @@ odf_validation_new_list (GsfXMLIn *xin, odf_validation_t *val)
 }
 
 static GnmValidation *
+odf_validation_new_general (GsfXMLIn *xin, odf_validation_t *val, 
+				    char * start, ValidationType val_type, 
+				    ValidationOp val_op)
+{
+	OOParseState *state = (OOParseState *)xin->user_state;
+	GnmValidation *validation = NULL;
+	GnmExprTop const *texpr = NULL;
+	GnmParsePos   pp;
+
+	pp = state->pos;
+	if (val->base_cell_address != NULL) {
+		char *tmp = g_strconcat ("[", val->base_cell_address, "]", NULL);
+		texpr = oo_expr_parse_str
+			(xin, tmp, &pp,
+			 GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES,
+			 FORMULA_OPENFORMULA);
+		g_free (tmp);
+		if (texpr != NULL) {
+			if (GNM_EXPR_GET_OPER (texpr->expr) ==
+			    GNM_EXPR_OP_CELLREF) {
+				GnmCellRef const *ref = &texpr->expr->cellref.ref;
+				parse_pos_init (&pp, state->pos.wb, ref->sheet,
+						ref->col, ref->row);
+			}
+			gnm_expr_top_unref (texpr);
+		}
+	}
+
+	texpr = oo_expr_parse_str (xin, start, &pp,
+				   GNM_EXPR_PARSE_DEFAULT,
+				   val->f_type);
+
+	if (texpr != NULL)
+		validation = validation_new (VALIDATION_STYLE_WARNING,
+					     val_type,
+					     val_op,
+					     NULL, NULL,
+					     texpr,
+					     NULL,
+					     val->allow_blank,
+					     val->use_dropdown);
+	return validation;
+}
+
+static GnmValidation *
+odf_validation_new_tlength (GsfXMLIn *xin, odf_validation_t *val)
+{
+	/*"cell-content-text-length() op value"*/
+
+	char *start;
+	ValidationOp val_op = VALIDATION_OP_NONE;
+
+	start = val->condition + strlen ("cell-content-text-length()");
+
+	while (*start == ' ')
+		start++;
+
+	/*â??<â??,â??>â??, â??<=â??, â??>=â??, â??=â?? or â??!=â??*/
+
+	if (g_str_has_prefix (start, ">=")) {
+		val_op = VALIDATION_OP_GTE;
+		start += 2;
+	} else if (g_str_has_prefix (start, "<=")) {
+		val_op = VALIDATION_OP_LTE;
+		start += 2;
+	} else if (g_str_has_prefix (start, "!=")) {
+		val_op = VALIDATION_OP_NOT_EQUAL;
+		start += 2;
+	} else if (g_str_has_prefix (start, "=")) {
+		val_op = VALIDATION_OP_EQUAL;
+		start += 1;
+	} else if (g_str_has_prefix (start, ">")) {
+		val_op = VALIDATION_OP_GT;
+		start += 1;
+	} else if (g_str_has_prefix (start, "<")) {
+		val_op = VALIDATION_OP_LT;
+		start += 1;
+	} else 
+
+	if (val_op == VALIDATION_OP_NONE)
+		return NULL;
+
+	while (*start == ' ')
+		start++;
+
+	return odf_validation_new_general 
+		(xin, val, start, VALIDATION_TYPE_TEXT_LENGTH, val_op);
+}
+
+static GnmValidation *
 odf_validations_translate (GsfXMLIn *xin, char const *name)
 {
 	OOParseState *state = (OOParseState *)xin->user_state;
@@ -1515,7 +1605,7 @@ odf_validations_translate (GsfXMLIn *xin, char const *name)
 			validation = odf_validation_new_list (xin, val);
 		else if (g_str_has_prefix (val->condition,
 					   "cell-content-text-length()"))
-			/* validation = odf_validation_new_ (xin, val) */;
+			validation = odf_validation_new_tlength (xin, val);
 		else if (g_str_has_prefix (val->condition,
 					   "cell-content-text-length-is-between"))
 			/* validation = odf_validation_new_ (xin, val) */;



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