[gnumeric] Import "between" conditional formats from ODF
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnumeric] Import "between" conditional formats from ODF
- Date: Wed, 24 Jun 2009 05:59:30 +0000 (UTC)
commit 168b88bb42145a80444c1bc851e9c9a457e0f0e5
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date: Tue Jun 23 23:58:31 2009 -0600
Import "between" conditional formats from ODF
2009-06-24 Andreas J. Guelzow <aguelzow pyrshep ca>
* openoffice-read.c (odf_style_map_load_two_values): new
(oo_style_map): handle cell-content-is-between and try to
handle cell-content-is-not-between
plugins/openoffice/ChangeLog | 8 +++-
plugins/openoffice/openoffice-read.c | 84 +++++++++++++++++++++++++++++----
2 files changed, 80 insertions(+), 12 deletions(-)
---
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 86d7fb2..8679b33 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,6 +1,12 @@
+2009-06-24 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * openoffice-read.c (odf_style_map_load_two_values): new
+ (oo_style_map): handle cell-content-is-between and try to
+ handle cell-content-is-not-between
+
2009-06-23 Andreas J. Guelzow <aguelzow pyrshep ca>
- * openoffice-read.c (oo_table_end): keep the styles for also
+ * openoffice-read.c (oo_table_end): keep the styles also
for the whole data extent.
2009-06-23 Andreas J. Guelzow <aguelzow pyrshep ca>
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 72e296a..144c654 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -2522,6 +2522,47 @@ oo_style_prop_table (GsfXMLIn *xin, xmlChar const **attrs)
style->is_rtl = tmp_i;
}
+static gboolean
+odf_style_map_load_two_values (GsfXMLIn *xin, char *condition, GnmStyleCond *cond)
+{
+ OOParseState *state = (OOParseState *)xin->user_state;
+
+ condition = g_strstrip (condition);
+ if (*(condition++) == '(') {
+ guint len = strlen (condition);
+ char *end = condition + len - 1;
+ if (*end == ')') {
+ GnmParsePos pp;
+
+ parse_pos_init (&pp, state->pos.wb, NULL, 0, 0);
+ len -= 1;
+ *end = '\0';
+ while (1) {
+ gchar * try = g_strrstr_len (condition, len, ",");
+ GnmExprTop const *texpr;
+
+ if (try == NULL || try == condition) return FALSE;
+
+ texpr = oo_expr_parse_str
+ (xin, try + 1, &pp,
+ GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES,
+ FORMULA_OPENFORMULA);
+ if (texpr != NULL) {
+ cond->texpr[1] = texpr;
+ *try = '\0';
+ break;
+ }
+ len = try - condition - 1;
+ }
+ cond->texpr[0] = oo_expr_parse_str
+ (xin, condition, &pp,
+ GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES,
+ FORMULA_OPENFORMULA);
+ return (cond->texpr[0] != NULL) && (cond->texpr[1] != NULL);
+ }
+ }
+ return FALSE;
+}
static void
@@ -2536,7 +2577,7 @@ oo_style_map (GsfXMLIn *xin, xmlChar const **attrs)
gboolean success = FALSE;
for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2)
- if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), OO_NS_STYLE, "condition")) /* "cell-content()=1" */
+ if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), OO_NS_STYLE, "condition"))
condition = attrs[1];
else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), OO_NS_STYLE, "apply-style-name"))
style_name = attrs[1];
@@ -2551,6 +2592,8 @@ oo_style_map (GsfXMLIn *xin, xmlChar const **attrs)
g_return_if_fail (state->cur_style.cells != NULL);
full_condition = condition;
+ cond.texpr[0] = NULL;
+ cond.texpr[1] = NULL;
if (g_str_has_prefix (condition, "cell-content()")) {
condition += strlen ("cell-content()") - 1;
@@ -2587,25 +2630,44 @@ oo_style_map (GsfXMLIn *xin, xmlChar const **attrs)
default:
break;
}
- }
- if (success) {
- GnmParsePos pp;
- while (*condition == ' ') condition++;
- parse_pos_init (&pp, state->pos.wb, NULL, 0, 0);
- cond.texpr[0] = oo_expr_parse_str (xin, condition, &pp,
- GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES,
- FORMULA_OPENFORMULA);
+ if (success) {
+ GnmParsePos pp;
+ while (*condition == ' ') condition++;
+ parse_pos_init (&pp, state->pos.wb, NULL, 0, 0);
+ cond.texpr[0] = oo_expr_parse_str (xin, condition, &pp,
+ GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES,
+ FORMULA_OPENFORMULA);
+ success = (cond.texpr[0] != NULL);
+ }
+
+ } else if (g_str_has_prefix (condition, "cell-content-is-between")) {
+ char *text;
+ cond.op = GNM_STYLE_COND_BETWEEN;
+ condition += strlen ("cell-content-is-between");
+ text = g_strdup (condition);
+ success = odf_style_map_load_two_values (xin, text, &cond);
+ g_free (text);
+ } else if (g_str_has_prefix (condition, "cell-content-is-not-between")) {
+ char *text;
+ cond.op = GNM_STYLE_COND_NOT_BETWEEN;
+ condition += strlen ("cell-content-is-not-between");
+ text = g_strdup (condition);
+ success = odf_style_map_load_two_values (xin, text, &cond);
+ g_free (text);
}
- if (!success || cond.texpr[0] == NULL)
+ if (!success)
{
+ if (cond.texpr[0] != NULL)
+ gnm_expr_top_unref (cond.texpr[0]);
+ if (cond.texpr[1] != NULL)
+ gnm_expr_top_unref (cond.texpr[1]);
oo_warning (xin,
_("Unknown condition '%s' encountered, ignoring."),
full_condition);
return;
}
- cond.texpr[1] = NULL;
cond.overlay = style;
gnm_style_ref (style);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]