[gnumeric] Conditional formats: store expression in managed dependents.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Conditional formats: store expression in managed dependents.
- Date: Thu, 31 May 2012 15:21:42 +0000 (UTC)
commit a3def7bf94a9a2feb8641d6c08f3b87c18735d68
Author: Morten Welinder <terra gnome org>
Date: Thu May 31 11:20:52 2012 -0400
Conditional formats: store expression in managed dependents.
This makes things behave right when rows/columns are inserted or deleted.
ChangeLog | 12 +++
NEWS | 1 +
plugins/excel/ms-excel-read.c | 4 +-
plugins/excel/ms-excel-write.c | 16 ++--
plugins/excel/xlsx-read.c | 4 +-
plugins/openoffice/openoffice-read.c | 54 +++++++-----
plugins/openoffice/openoffice-write.c | 34 ++++----
src/dialogs/dialog-cell-format-cond.c | 42 +++++-----
src/mstyle.c | 6 +-
src/style-conditions.c | 160 ++++++++++++++++++++++++++------
src/style-conditions.h | 24 ++++--
src/xml-sax-read.c | 7 +-
src/xml-sax-write.c | 23 +++--
13 files changed, 262 insertions(+), 125 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 62faa37..72d6799 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2012-05-31 Morten Welinder <terra gnome org>
+
+ * src/style-conditions.c (gnm_style_conditions_new): Add new sheet
+ argument. All callers changed.
+ (gnm_style_conditions_insert): Verify that sheets match between
+ objects.
+ (gnm_style_cond_new): Add new sheet argument. All callers
+ changed. Initialize managed dependent.
+
+ * src/style-conditions.h (GnmStyleCond): Store expressions as
+ managed dependents.
+
2012-05-25 Morten Welinder <terra gnome org>
* src/style-conditions.c (gnm_style_conditions_insert): Change
diff --git a/NEWS b/NEWS
index 9fc9c57..0b365e3 100644
--- a/NEWS
+++ b/NEWS
@@ -27,6 +27,7 @@ Morten:
* Minor doc improvement for non-C locales. [Part of #675000]
* Fix fullscreen criticals.
* Improve handling of expressions in validations. [#674914]
+ * Improve handling of expressions in conditional formats. [#674954]
* Fix problems with style hash and equality. [#675955]
--------------------------------------------------------------------------
diff --git a/plugins/excel/ms-excel-read.c b/plugins/excel/ms-excel-read.c
index 516a825..15cbaa0 100644
--- a/plugins/excel/ms-excel-read.c
+++ b/plugins/excel/ms-excel-read.c
@@ -5171,7 +5171,7 @@ excel_read_CF (BiffQuery *q, ExcelReadSheet *esheet, GnmStyleConditions *sc)
return;
}
- cond = gnm_style_cond_new (cop);
+ cond = gnm_style_cond_new (cop, esheet->sheet);
if (expr0_len > 0) {
GnmExprTop const *texpr =
@@ -5374,7 +5374,7 @@ excel_read_CONDFMT (BiffQuery *q, ExcelReadSheet *esheet)
XL_CHECK_CONDITION (data == q->data + q->length);
- sc = gnm_style_conditions_new ();
+ sc = gnm_style_conditions_new (esheet->sheet);
for (i = 0 ; i < num_fmts ; i++) {
guint16 next;
if (!ms_biff_query_peek_next (q, &next) || next != BIFF_CF) {
diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c
index c499650..6f10608 100644
--- a/plugins/excel/ms-excel-write.c
+++ b/plugins/excel/ms-excel-write.c
@@ -1091,16 +1091,16 @@ cb_write_condition (GnmStyleConditions const *sc, CondDetails *cd,
} else
flags |= 0x70000;
- expr0_len = (cond->texpr[0] == NULL)
+ expr0_len = (gnm_style_cond_get_expr (cond, 0) == NULL)
? 0
: excel_write_formula (esheet->ewb,
- cond->texpr[0],
+ gnm_style_cond_get_expr (cond, 0),
esheet->gnum_sheet, 0, 0,
EXCEL_CALLED_FROM_CONDITION);
- expr1_len = (cond->texpr[1] == NULL)
+ expr1_len = (gnm_style_cond_get_expr (cond, 1) == NULL)
? 0
: excel_write_formula (esheet->ewb,
- cond->texpr[1],
+ gnm_style_cond_get_expr (cond, 1),
esheet->gnum_sheet, 0, 0,
EXCEL_CALLED_FROM_CONDITION);
@@ -1507,10 +1507,10 @@ excel_write_prep_conditions (ExcelWriteSheet *esheet)
gnm_style_get_conditions (sr->style));
for (i = 0 ; i < (conds ? conds->len : 0) ; i++) {
GnmStyleCond const *cond = g_ptr_array_index (conds, i);
- if (cond->texpr[0] != NULL)
- excel_write_prep_expr (esheet->ewb, cond->texpr[0]);
- if (cond->texpr[1] != NULL)
- excel_write_prep_expr (esheet->ewb, cond->texpr[1]);
+ if (gnm_style_cond_get_expr (cond, 0) != NULL)
+ excel_write_prep_expr (esheet->ewb, gnm_style_cond_get_expr (cond, 0));
+ if (gnm_style_cond_get_expr (cond, 1) != NULL)
+ excel_write_prep_expr (esheet->ewb, gnm_style_cond_get_expr (cond, 1));
}
}
}
diff --git a/plugins/excel/xlsx-read.c b/plugins/excel/xlsx-read.c
index 873309b..d4969f8 100644
--- a/plugins/excel/xlsx-read.c
+++ b/plugins/excel/xlsx-read.c
@@ -2229,7 +2229,7 @@ xlsx_cond_fmt_rule_begin (GsfXMLIn *xin, xmlChar const **attrs)
xlsx_warning (xin, _("Ignoring unhandled conditional format of type '%s'"), type_str);
}
- state->cond = gnm_style_cond_new (op);
+ state->cond = gnm_style_cond_new (op, state->sheet);
gnm_style_cond_set_overlay (state->cond, overlay);
state->count = 0;
@@ -2242,7 +2242,7 @@ xlsx_cond_fmt_rule_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
if (state->cond) {
if (gnm_style_cond_is_valid (state->cond)) {
if (NULL == state->conditions)
- state->conditions = gnm_style_conditions_new ();
+ state->conditions = gnm_style_conditions_new (state->sheet);
gnm_style_conditions_insert (state->conditions,
state->cond, -1);
}
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 423c29b..18462b1 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -2992,7 +2992,8 @@ odf_style_load_two_values (GsfXMLIn *xin, char *condition, GnmStyleCond *cond, g
guint len = strlen (condition);
char *end = condition + len - 1;
if (*end == ')') {
- GnmParsePos pp;
+ GnmParsePos pp;
+ GnmExprTop const *texpr;
odf_init_pp (&pp, xin, base);
len -= 1;
@@ -3008,17 +3009,22 @@ odf_style_load_two_values (GsfXMLIn *xin, char *condition, GnmStyleCond *cond, g
GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES,
f_type);
if (texpr != NULL) {
- cond->texpr[1] = texpr;
+ gnm_style_cond_set_expr (cond, texpr, 1);
+ gnm_expr_top_unref (texpr);
*try = '\0';
break;
}
len = try - condition - 1;
}
- cond->texpr[0] = oo_expr_parse_str
+ texpr = oo_expr_parse_str
(xin, condition, &pp,
GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES,
f_type);
- return ((cond->texpr[0] != NULL) && (cond->texpr[1] != NULL));
+ gnm_style_cond_set_expr (cond, texpr, 0);
+ if (texpr) gnm_expr_top_unref (texpr);
+
+ return (gnm_style_cond_get_expr (cond, 0) &&
+ gnm_style_cond_get_expr (cond, 1));
}
}
return FALSE;
@@ -3027,27 +3033,31 @@ odf_style_load_two_values (GsfXMLIn *xin, char *condition, GnmStyleCond *cond, g
static gboolean
odf_style_load_one_value (GsfXMLIn *xin, char *condition, GnmStyleCond *cond, gchar const *base, OOFormula f_type)
{
- GnmParsePos pp;
+ GnmParsePos pp;
+ GnmExprTop const *texpr;
odf_init_pp (&pp, xin, base);
- cond->texpr[0] = oo_expr_parse_str
+ texpr = oo_expr_parse_str
(xin, condition, &pp,
GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES,
f_type);
- return (cond->texpr[0] != NULL);
+ gnm_style_cond_set_expr (cond, texpr, 0);
+ if (texpr) gnm_expr_top_unref (texpr);
+ return (gnm_style_cond_get_expr (cond, 0) != NULL);
}
static void
odf_style_add_condition (GsfXMLIn *xin, GnmStyle *style, GnmStyle *cstyle,
gchar const *condition, gchar const *base)
{
- /* OOParseState *state = (OOParseState *)xin->user_state; */
+ OOParseState *state = (OOParseState *)xin->user_state;
gchar const *full_condition = condition;
GnmStyleCond *cond = NULL;
GnmStyleConditions *sc;
gboolean success = FALSE;
OOFormula f_type;
+ Sheet *sheet = state->pos.sheet;
g_return_if_fail (style != NULL);
g_return_if_fail (cstyle != NULL);
@@ -3063,28 +3073,28 @@ odf_style_add_condition (GsfXMLIn *xin, GnmStyle *style, GnmStyle *cstyle,
case '<':
if (*condition == '=') {
condition++;
- cond = gnm_style_cond_new (GNM_STYLE_COND_LTE);
+ cond = gnm_style_cond_new (GNM_STYLE_COND_LTE, sheet);
} else
- cond = gnm_style_cond_new (GNM_STYLE_COND_LT);
+ cond = gnm_style_cond_new (GNM_STYLE_COND_LT, sheet);
success = TRUE;
break;
case '>':
if (*condition == '=') {
condition++;
- cond = gnm_style_cond_new (GNM_STYLE_COND_GTE);
+ cond = gnm_style_cond_new (GNM_STYLE_COND_GTE, sheet);
} else
- cond = gnm_style_cond_new (GNM_STYLE_COND_GT);
+ cond = gnm_style_cond_new (GNM_STYLE_COND_GT, sheet);
success = TRUE;
break;
break;
case '=':
- cond = gnm_style_cond_new (GNM_STYLE_COND_EQUAL);
+ cond = gnm_style_cond_new (GNM_STYLE_COND_EQUAL, sheet);
success = TRUE;
break;
case '!':
if (*condition == '=') {
condition++;
- cond = gnm_style_cond_new (GNM_STYLE_COND_NOT_EQUAL);
+ cond = gnm_style_cond_new (GNM_STYLE_COND_NOT_EQUAL, sheet);
success = TRUE;
}
break;
@@ -3099,14 +3109,14 @@ odf_style_add_condition (GsfXMLIn *xin, GnmStyle *style, GnmStyle *cstyle,
} else if (g_str_has_prefix (condition, "cell-content-is-between")) {
char *text;
- cond = gnm_style_cond_new (GNM_STYLE_COND_BETWEEN);
+ cond = gnm_style_cond_new (GNM_STYLE_COND_BETWEEN, sheet);
condition += strlen ("cell-content-is-between");
text = g_strdup (condition);
success = odf_style_load_two_values (xin, text, cond, base, f_type);
g_free (text);
} else if (g_str_has_prefix (condition, "cell-content-is-not-between")) {
char *text;
- cond = gnm_style_cond_new (GNM_STYLE_COND_NOT_BETWEEN);
+ cond = gnm_style_cond_new (GNM_STYLE_COND_NOT_BETWEEN, sheet);
condition += strlen ("cell-content-is-not-between");
text = g_strdup (condition);
success = odf_style_load_two_values (xin, text, cond, base, f_type);
@@ -3114,23 +3124,23 @@ odf_style_add_condition (GsfXMLIn *xin, GnmStyle *style, GnmStyle *cstyle,
} else if (g_str_has_prefix (condition, "is-true-formula")) {
if (0 == strcmp (full_condition, "of:is-true-formula(ISERROR([.A1]))") &&
g_str_has_suffix (base, ".$A$1")) {
- cond = gnm_style_cond_new (GNM_STYLE_COND_CONTAINS_ERR);
+ cond = gnm_style_cond_new (GNM_STYLE_COND_CONTAINS_ERR, sheet);
success = TRUE;
} else if (0 == strcmp (full_condition, "of:is-true-formula(NOT(ISERROR([.A1])))") &&
g_str_has_suffix (base, ".$A$1")) {
- cond = gnm_style_cond_new (GNM_STYLE_COND_NOT_CONTAINS_ERR);
+ cond = gnm_style_cond_new (GNM_STYLE_COND_NOT_CONTAINS_ERR, sheet);
success = TRUE;
} else if (0 == strcmp (full_condition, "of:is-true-formula(NOT(ISERROR(FIND(\" \";[.A1]))))") &&
g_str_has_suffix (base, ".$A$1")) {
- cond = gnm_style_cond_new (GNM_STYLE_COND_CONTAINS_BLANKS);
+ cond = gnm_style_cond_new (GNM_STYLE_COND_CONTAINS_BLANKS, sheet);
success = TRUE;
} else if (0 == strcmp (full_condition, "of:is-true-formula(ISERROR(FIND(\" \";[.A1])))") &&
g_str_has_suffix (base, ".$A$1")) {
- cond = gnm_style_cond_new (GNM_STYLE_COND_NOT_CONTAINS_BLANKS);
+ cond = gnm_style_cond_new (GNM_STYLE_COND_NOT_CONTAINS_BLANKS, sheet);
success = TRUE;
} else {
char *text;
- cond = gnm_style_cond_new (GNM_STYLE_COND_CUSTOM);
+ cond = gnm_style_cond_new (GNM_STYLE_COND_CUSTOM, sheet);
condition += strlen ("is-true-formula");
text = g_strdup (condition);
success = odf_style_load_one_value (xin, text, cond, base, f_type);
@@ -3153,7 +3163,7 @@ odf_style_add_condition (GsfXMLIn *xin, GnmStyle *style, GnmStyle *cstyle,
(sc = gnm_style_get_conditions (style)) != NULL)
gnm_style_conditions_insert (sc, cond, -1);
else {
- sc = gnm_style_conditions_new ();
+ sc = gnm_style_conditions_new (sheet);
gnm_style_conditions_insert (sc, cond, -1);
gnm_style_set_conditions (style, sc);
}
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 73f658a..7f6fbee 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -1475,9 +1475,9 @@ static void
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], pp);
+ odf_save_style_map_single_f (state, str, gnm_style_cond_get_expr (cond, 0), pp);
g_string_append_c (str, ',');
- odf_save_style_map_single_f (state, str, cond->texpr[1], pp);
+ odf_save_style_map_single_f (state, str, gnm_style_cond_get_expr (cond, 1), pp);
g_string_append_c (str, ')');
}
@@ -1530,32 +1530,32 @@ odf_save_style_map (GnmOOExport *state, GnmStyleCond const *cond, GnmRange *r)
case GNM_STYLE_COND_EQUAL:
odf_determine_base (state, r, &pp);
g_string_append (str, "of:cell-content()=");
- odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
+ odf_save_style_map_single_f (state, str, gnm_style_cond_get_expr (cond, 0), &pp);
break;
case GNM_STYLE_COND_NOT_EQUAL:
odf_determine_base (state, r, &pp);
g_string_append (str, "of:cell-content()!=");
- odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
+ odf_save_style_map_single_f (state, str, gnm_style_cond_get_expr (cond, 0), &pp);
break;
case GNM_STYLE_COND_GT:
odf_determine_base (state, r, &pp);
g_string_append (str, "of:cell-content()>");
- odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
+ odf_save_style_map_single_f (state, str, gnm_style_cond_get_expr (cond, 0), &pp);
break;
case GNM_STYLE_COND_LT:
odf_determine_base (state, r, &pp);
g_string_append (str, "of:cell-content()<");
- odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
+ odf_save_style_map_single_f (state, str, gnm_style_cond_get_expr (cond, 0), &pp);
break;
case GNM_STYLE_COND_GTE:
odf_determine_base (state, r, &pp);
g_string_append (str, "of:cell-content()>=");
- odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
+ odf_save_style_map_single_f (state, str, gnm_style_cond_get_expr (cond, 0), &pp);
break;
case GNM_STYLE_COND_LTE:
odf_determine_base (state, r, &pp);
g_string_append (str, "of:cell-content()<=");
- odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
+ odf_save_style_map_single_f (state, str, gnm_style_cond_get_expr (cond, 0), &pp);
break;
case GNM_STYLE_COND_CONTAINS_ERR:
parse_pos_init (&pp, (Workbook *) state->wb, state->sheet, 0, 0);
@@ -1568,47 +1568,47 @@ odf_save_style_map (GnmOOExport *state, GnmStyleCond const *cond, GnmRange *r)
case GNM_STYLE_COND_CONTAINS_STR:
odf_determine_base (state, r, &pp);
g_string_append (str, "of:is-true-formula(NOT(ISERROR(FIND(");
- odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
+ odf_save_style_map_single_f (state, str, gnm_style_cond_get_expr (cond, 0), &pp);
g_string_append_printf (str, ";[.%s%s]))))",
col_name (pp.eval.col), row_name (pp.eval.row));
break;
case GNM_STYLE_COND_NOT_CONTAINS_STR:
odf_determine_base (state, r, &pp);
g_string_append (str, "of:is-true-formula(ISERROR(FIND(");
- odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
+ odf_save_style_map_single_f (state, str, gnm_style_cond_get_expr (cond, 0), &pp);
g_string_append_printf (str, ";[.%s%s])))",
col_name (pp.eval.col), row_name (pp.eval.row));
break;
case GNM_STYLE_COND_BEGINS_WITH_STR:
odf_determine_base (state, r, &pp);
g_string_append (str, "of:is-true-formula(IFERROR(FIND(");
- odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
+ odf_save_style_map_single_f (state, str, gnm_style_cond_get_expr (cond, 0), &pp);
g_string_append_printf (str, ";[.%s%s]);2)=1)",
col_name (pp.eval.col), row_name (pp.eval.row));
break;
case GNM_STYLE_COND_NOT_BEGINS_WITH_STR:
odf_determine_base (state, r, &pp);
g_string_append (str, "of:is-true-formula(NOT(IFERROR(FIND(");
- odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
+ odf_save_style_map_single_f (state, str, gnm_style_cond_get_expr (cond, 0), &pp);
g_string_append_printf (str, ";[.%s%s]);2)=1))",
col_name (pp.eval.col), row_name (pp.eval.row));
break;
case GNM_STYLE_COND_ENDS_WITH_STR:
odf_determine_base (state, r, &pp);
g_string_append (str, "of:is-true-formula(EXACT(");
- odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
+ odf_save_style_map_single_f (state, str, gnm_style_cond_get_expr (cond, 0), &pp);
g_string_append_printf (str, ";RIGHT([.%s%s];LEN(",
col_name (pp.eval.col), row_name (pp.eval.row));
- odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
+ odf_save_style_map_single_f (state, str, gnm_style_cond_get_expr (cond, 0), &pp);
g_string_append (str, ")))");
break;
case GNM_STYLE_COND_NOT_ENDS_WITH_STR:
odf_determine_base (state, r, &pp);
g_string_append (str, "of:is-true-formula(NOT(EXACT(");
- odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
+ odf_save_style_map_single_f (state, str, gnm_style_cond_get_expr (cond, 0), &pp);
g_string_append_printf (str, ";RIGHT([.%s%s];LEN(",
col_name (pp.eval.col), row_name (pp.eval.row));
- odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
+ odf_save_style_map_single_f (state, str, gnm_style_cond_get_expr (cond, 0), &pp);
g_string_append (str, "))))");
break;
case GNM_STYLE_COND_CONTAINS_BLANKS:
@@ -1622,7 +1622,7 @@ odf_save_style_map (GnmOOExport *state, GnmStyleCond const *cond, GnmRange *r)
case GNM_STYLE_COND_CUSTOM:
odf_determine_base (state, r, &pp);
g_string_append (str, "of:is-true-formula(");
- odf_save_style_map_single_f (state, str, cond->texpr[0], &pp);
+ odf_save_style_map_single_f (state, str, gnm_style_cond_get_expr (cond, 0), &pp);
g_string_append (str, ")");
break;
default:
diff --git a/src/dialogs/dialog-cell-format-cond.c b/src/dialogs/dialog-cell-format-cond.c
index e8d3671..aaf32ec 100644
--- a/src/dialogs/dialog-cell-format-cond.c
+++ b/src/dialogs/dialog-cell-format-cond.c
@@ -379,7 +379,7 @@ c_fmt_dialog_get_condition (CFormatState *state)
else
op = GNM_STYLE_COND_CONTAINS_ERR;
- cond = gnm_style_cond_new (op);
+ cond = gnm_style_cond_new (op, state->sheet);
gnm_style_cond_set_overlay (cond, overlay);
gnm_style_unref (overlay);
@@ -452,16 +452,16 @@ cb_c_fmt_dialog_copy_button (G_GNUC_UNUSED GtkWidget *btn, CFormatState *state)
}
/* Set the expressions */
parse_pos_init_editpos (&pp, state->sv);
- if (gsc->texpr[0])
+ if (gnm_style_cond_get_expr (gsc, 0))
gnm_expr_entry_load_from_expr (GNM_EXPR_ENTRY (state->editor.expr_x),
- gsc->texpr[0],
+ gnm_style_cond_get_expr (gsc, 0),
&pp);
else
gnm_expr_entry_load_from_text (GNM_EXPR_ENTRY (state->editor.expr_x),
"");
- if (gsc->texpr[1])
+ if (gnm_style_cond_get_expr (gsc, 1))
gnm_expr_entry_load_from_expr (GNM_EXPR_ENTRY (state->editor.expr_y),
- gsc->texpr[1],
+ gnm_style_cond_get_expr (gsc, 1),
&pp);
else
gnm_expr_entry_load_from_text (GNM_EXPR_ENTRY (state->editor.expr_y),
@@ -679,7 +679,7 @@ c_fmt_dialog_apply_add_choice (CFormatState *state, GnmStyleCond *cond, gboolean
int index = -1;
sc = gnm_style_conditions_dup (gnm_style_get_conditions (state->style));
if (sc == NULL)
- sc = gnm_style_conditions_new ();
+ sc = gnm_style_conditions_new (state->sheet);
if (!add) {
GtkTreeIter iter;
if (gtk_tree_selection_get_selected (state->selection, NULL, &iter)) {
@@ -811,8 +811,8 @@ static void
c_fmt_dialog_conditions_page_load_cond_double_f (CFormatState *state,
GnmStyleCond const *cond, GtkTreeIter *iter1)
{
- c_fmt_dialog_conditions_page_load_cond_single_f (state, cond->texpr[0], iter1);
- c_fmt_dialog_conditions_page_load_cond_single_f (state, cond->texpr[1], iter1);
+ c_fmt_dialog_conditions_page_load_cond_single_f (state, gnm_style_cond_get_expr (cond, 0), iter1);
+ c_fmt_dialog_conditions_page_load_cond_single_f (state, gnm_style_cond_get_expr (cond, 1), iter1);
}
static void
@@ -846,7 +846,7 @@ c_fmt_dialog_conditions_page_load_cond (CFormatState *state, GnmStyleCond const
_("If the cell content is equal to this value"
", a special style is used."),
CONDITIONS_REFERENCE, NULL, -1);
- c_fmt_dialog_conditions_page_load_cond_single_f (state, cond->texpr[0], &iter1);
+ c_fmt_dialog_conditions_page_load_cond_single_f (state, gnm_style_cond_get_expr (cond, 0), &iter1);
break;
case GNM_STYLE_COND_NOT_EQUAL:
gtk_tree_store_set (state->model, &iter1, CONDITIONS_RANGE, NULL,
@@ -854,14 +854,14 @@ c_fmt_dialog_conditions_page_load_cond (CFormatState *state, GnmStyleCond const
_("If the cell content is not equal to this value"
", a special style is used."),
CONDITIONS_REFERENCE, NULL, -1);
- c_fmt_dialog_conditions_page_load_cond_single_f (state, cond->texpr[0], &iter1);
+ c_fmt_dialog_conditions_page_load_cond_single_f (state, gnm_style_cond_get_expr (cond, 0), &iter1);
break;
case GNM_STYLE_COND_GT:
gtk_tree_store_set (state->model, &iter1, CONDITIONS_RANGE, NULL,
CONDITIONS_COND,
_("If the cell content is > this value, a "
"special style is used."), -1);
- c_fmt_dialog_conditions_page_load_cond_single_f (state, cond->texpr[0], &iter1);
+ c_fmt_dialog_conditions_page_load_cond_single_f (state, gnm_style_cond_get_expr (cond, 0), &iter1);
break;
case GNM_STYLE_COND_LT:
gtk_tree_store_set (state->model, &iter1, CONDITIONS_RANGE, NULL,
@@ -869,7 +869,7 @@ c_fmt_dialog_conditions_page_load_cond (CFormatState *state, GnmStyleCond const
_("If the cell content is < this value, a "
"special style is used."),
CONDITIONS_REFERENCE, NULL, -1);
- c_fmt_dialog_conditions_page_load_cond_single_f (state, cond->texpr[0], &iter1);
+ c_fmt_dialog_conditions_page_load_cond_single_f (state, gnm_style_cond_get_expr (cond, 0), &iter1);
break;
case GNM_STYLE_COND_GTE:
gtk_tree_store_set (state->model, &iter1, CONDITIONS_RANGE, NULL,
@@ -878,7 +878,7 @@ c_fmt_dialog_conditions_page_load_cond (CFormatState *state, GnmStyleCond const
"value, a special style is used."),
CONDITIONS_REFERENCE, NULL, -1);
- c_fmt_dialog_conditions_page_load_cond_single_f (state, cond->texpr[0], &iter1);
+ c_fmt_dialog_conditions_page_load_cond_single_f (state, gnm_style_cond_get_expr (cond, 0), &iter1);
break;
case GNM_STYLE_COND_LTE:
gtk_tree_store_set (state->model, &iter1, CONDITIONS_RANGE, NULL,
@@ -886,7 +886,7 @@ c_fmt_dialog_conditions_page_load_cond (CFormatState *state, GnmStyleCond const
_("If the cell content is \xe2\x89\xa6 this "
"value, a special style is used."),
CONDITIONS_REFERENCE, NULL, -1);
- c_fmt_dialog_conditions_page_load_cond_single_f (state, cond->texpr[0], &iter1);
+ c_fmt_dialog_conditions_page_load_cond_single_f (state, gnm_style_cond_get_expr (cond, 0), &iter1);
break;
case GNM_STYLE_COND_CUSTOM:
@@ -894,7 +894,7 @@ c_fmt_dialog_conditions_page_load_cond (CFormatState *state, GnmStyleCond const
CONDITIONS_COND,
_("If this formula evaluates to TRUE, a special style is used."),
CONDITIONS_REFERENCE, NULL, -1);
- c_fmt_dialog_conditions_page_load_cond_single_f (state, cond->texpr[0], &iter1);
+ c_fmt_dialog_conditions_page_load_cond_single_f (state, gnm_style_cond_get_expr (cond, 0), &iter1);
break;
case GNM_STYLE_COND_CONTAINS_STR:
gtk_tree_store_set (state->model, &iter1, CONDITIONS_RANGE, NULL,
@@ -902,7 +902,7 @@ c_fmt_dialog_conditions_page_load_cond (CFormatState *state, GnmStyleCond const
_("If the cell content contains this string"
", a special style is used."),
CONDITIONS_REFERENCE, NULL, -1);
- c_fmt_dialog_conditions_page_load_cond_single_f (state, cond->texpr[0], &iter1);
+ c_fmt_dialog_conditions_page_load_cond_single_f (state, gnm_style_cond_get_expr (cond, 0), &iter1);
break;
case GNM_STYLE_COND_NOT_CONTAINS_STR:
gtk_tree_store_set (state->model, &iter1, CONDITIONS_RANGE, NULL,
@@ -910,7 +910,7 @@ c_fmt_dialog_conditions_page_load_cond (CFormatState *state, GnmStyleCond const
_("If the cell content does not contain this string"
", a special style is used."),
CONDITIONS_REFERENCE, NULL, -1);
- c_fmt_dialog_conditions_page_load_cond_single_f (state, cond->texpr[0], &iter1);
+ c_fmt_dialog_conditions_page_load_cond_single_f (state, gnm_style_cond_get_expr (cond, 0), &iter1);
break;
case GNM_STYLE_COND_BEGINS_WITH_STR:
gtk_tree_store_set (state->model, &iter1, CONDITIONS_RANGE, NULL,
@@ -918,14 +918,14 @@ c_fmt_dialog_conditions_page_load_cond (CFormatState *state, GnmStyleCond const
_("If the cell content begins with this string"
", a special style is used."),
CONDITIONS_REFERENCE, NULL, -1);
- c_fmt_dialog_conditions_page_load_cond_single_f (state, cond->texpr[0], &iter1);
+ c_fmt_dialog_conditions_page_load_cond_single_f (state, gnm_style_cond_get_expr (cond, 0), &iter1);
break;
case GNM_STYLE_COND_NOT_BEGINS_WITH_STR:
gtk_tree_store_set (state->model, &iter1, CONDITIONS_RANGE, NULL,
CONDITIONS_COND,
_("If the cell content does not begin with this string,"
" a special style is used."), -1);
- c_fmt_dialog_conditions_page_load_cond_single_f (state, cond->texpr[0], &iter1);
+ c_fmt_dialog_conditions_page_load_cond_single_f (state, gnm_style_cond_get_expr (cond, 0), &iter1);
break;
case GNM_STYLE_COND_ENDS_WITH_STR:
gtk_tree_store_set (state->model, &iter1, CONDITIONS_RANGE, NULL,
@@ -933,7 +933,7 @@ c_fmt_dialog_conditions_page_load_cond (CFormatState *state, GnmStyleCond const
_("If the cell content ends with this string"
", a special style is used."),
CONDITIONS_REFERENCE, NULL, -1);
- c_fmt_dialog_conditions_page_load_cond_single_f (state, cond->texpr[0], &iter1);
+ c_fmt_dialog_conditions_page_load_cond_single_f (state, gnm_style_cond_get_expr (cond, 0), &iter1);
break;
case GNM_STYLE_COND_NOT_ENDS_WITH_STR:
gtk_tree_store_set (state->model, &iter1, CONDITIONS_RANGE, NULL,
@@ -941,7 +941,7 @@ c_fmt_dialog_conditions_page_load_cond (CFormatState *state, GnmStyleCond const
_("If the cell content does not end "
"with this string, a special style is used."),
CONDITIONS_REFERENCE, NULL, -1);
- c_fmt_dialog_conditions_page_load_cond_single_f (state, cond->texpr[0], &iter1);
+ c_fmt_dialog_conditions_page_load_cond_single_f (state, gnm_style_cond_get_expr (cond, 0), &iter1);
break;
case GNM_STYLE_COND_CONTAINS_ERR:
gtk_tree_store_set (state->model, &iter1, CONDITIONS_RANGE, NULL,
diff --git a/src/mstyle.c b/src/mstyle.c
index e93a3d9..daec476 100644
--- a/src/mstyle.c
+++ b/src/mstyle.c
@@ -829,11 +829,11 @@ gnm_style_linked_sheet_changed (GnmStyle *style)
if (elem_is_set (style, MSTYLE_CONDITIONS) &&
style->conditions
-#if 0
&& gnm_style_conditions_get_sheet (style->conditions) != sheet
-#endif
) {
- /* Something goes here. */
+ GnmStyleConditions *new_c = gnm_style_conditions_dup (style->conditions);
+ gnm_style_conditions_set_sheet (new_c, sheet);
+ gnm_style_set_conditions (style, new_c);
}
}
diff --git a/src/style-conditions.c b/src/style-conditions.c
index 4035b02..95a6d2c 100644
--- a/src/style-conditions.c
+++ b/src/style-conditions.c
@@ -40,10 +40,44 @@ typedef GObjectClass GnmStyleConditionsClass;
struct _GnmStyleConditions {
GObject base;
GPtrArray *conditions;
+ Sheet *sheet;
};
static GObjectClass *parent_class;
+static unsigned
+gnm_style_cond_op_operands (GnmStyleCondOp op)
+{
+ switch (op) {
+ case GNM_STYLE_COND_BETWEEN:
+ case GNM_STYLE_COND_NOT_BETWEEN:
+ return 2;
+
+ case GNM_STYLE_COND_EQUAL:
+ case GNM_STYLE_COND_NOT_EQUAL:
+ case GNM_STYLE_COND_GT:
+ case GNM_STYLE_COND_LT:
+ case GNM_STYLE_COND_GTE:
+ case GNM_STYLE_COND_LTE:
+ case GNM_STYLE_COND_CUSTOM:
+ case GNM_STYLE_COND_CONTAINS_STR:
+ case GNM_STYLE_COND_NOT_CONTAINS_STR:
+ case GNM_STYLE_COND_BEGINS_WITH_STR:
+ case GNM_STYLE_COND_NOT_BEGINS_WITH_STR:
+ case GNM_STYLE_COND_ENDS_WITH_STR:
+ case GNM_STYLE_COND_NOT_ENDS_WITH_STR:
+ return 1;
+
+ case GNM_STYLE_COND_CONTAINS_ERR:
+ case GNM_STYLE_COND_NOT_CONTAINS_ERR:
+ case GNM_STYLE_COND_CONTAINS_BLANKS:
+ case GNM_STYLE_COND_NOT_CONTAINS_BLANKS:
+ return 0;
+ }
+ g_assert_not_reached ();
+}
+
+
/**
* gnm_style_cond_is_valid :
* @cond : #GnmStyleCond
@@ -53,26 +87,35 @@ static GObjectClass *parent_class;
gboolean
gnm_style_cond_is_valid (GnmStyleCond const *cond)
{
+ unsigned ui, N;
+
g_return_val_if_fail (cond != NULL, FALSE);
if (cond->overlay == NULL) return FALSE;
- if ((cond->texpr[0] != NULL) ^
- (cond->op != GNM_STYLE_COND_CONTAINS_ERR &&
- cond->op != GNM_STYLE_COND_NOT_CONTAINS_ERR &&
- cond->op != GNM_STYLE_COND_CONTAINS_BLANKS &&
- cond->op != GNM_STYLE_COND_NOT_CONTAINS_BLANKS)) return FALSE;
- if ((cond->texpr[1] != NULL) ^
- (cond->op == GNM_STYLE_COND_BETWEEN ||
- cond->op == GNM_STYLE_COND_NOT_BETWEEN))
- return FALSE;
+
+ N = gnm_style_cond_op_operands (cond->op);
+ for (ui = 0; ui < G_N_ELEMENTS (cond->deps); ui++) {
+ gboolean need = (ui < N);
+ gboolean have = (cond->deps[ui].texpr != NULL);
+ if (have != need)
+ return FALSE;
+ }
+
return TRUE;
}
GnmStyleCond *
-gnm_style_cond_new (GnmStyleCondOp op)
+gnm_style_cond_new (GnmStyleCondOp op, Sheet *sheet)
{
- GnmStyleCond *res = g_new0 (GnmStyleCond, 1);
+ GnmStyleCond *res;
+ unsigned ui;
+
+ g_return_val_if_fail (IS_SHEET (sheet), NULL);
+
+ res = g_new0 (GnmStyleCond, 1);
res->op = op;
+ for (ui = 0; ui < 2; ui++)
+ dependent_managed_init (&res->deps[ui], sheet);
return res;
}
@@ -84,10 +127,10 @@ gnm_style_cond_dup (GnmStyleCond const *src)
g_return_val_if_fail (src != NULL, NULL);
- dst = gnm_style_cond_new (src->op);
+ dst = gnm_style_cond_new (src->op, gnm_style_cond_get_sheet (src));
gnm_style_cond_set_overlay (dst, src->overlay);
for (ui = 0; ui < 2; ui++)
- gnm_style_cond_set_expr (dst, src->texpr[ui], ui);
+ gnm_style_cond_set_expr (dst, src->deps[ui].texpr, ui);
return dst;
}
@@ -103,23 +146,48 @@ gnm_style_cond_free (GnmStyleCond *cond)
if (cond->overlay)
gnm_style_unref (cond->overlay);
for (ui = 0; ui < 2; ui++)
- if (cond->texpr[ui])
- gnm_expr_top_unref (cond->texpr[ui]);
+ gnm_style_cond_set_expr (cond, NULL, ui);
g_free (cond);
}
+Sheet *
+gnm_style_cond_get_sheet (GnmStyleCond const *cond)
+{
+ g_return_val_if_fail (cond != NULL, NULL);
+ return cond->deps[0].sheet;
+}
+
+void
+gnm_style_cond_set_sheet (GnmStyleCond *cond, Sheet *sheet)
+{
+ int ui;
+
+ g_return_if_fail (cond != NULL);
+ g_return_if_fail (IS_SHEET (sheet));
+
+ for (ui = 0; ui < 2; ui++)
+ dependent_managed_set_sheet (&cond->deps[ui], sheet);
+}
+
+GnmExprTop const *
+gnm_style_cond_get_expr (GnmStyleCond const *cond, unsigned idx)
+{
+ g_return_val_if_fail (cond != NULL, NULL);
+ g_return_val_if_fail (idx < G_N_ELEMENTS (cond->deps), NULL);
+
+ return cond->deps[idx].texpr;
+}
+
void
gnm_style_cond_set_expr (GnmStyleCond *cond,
GnmExprTop const *texpr,
unsigned idx)
{
g_return_if_fail (cond != NULL);
- g_return_if_fail (idx < G_N_ELEMENTS (cond->texpr));
+ g_return_if_fail (idx < G_N_ELEMENTS (cond->deps));
- if (texpr) gnm_expr_top_ref (texpr);
- if (cond->texpr[idx]) gnm_expr_top_unref (cond->texpr[idx]);
- cond->texpr[idx] = texpr;
+ dependent_managed_set_expr (&cond->deps[idx], texpr);
}
void
@@ -169,21 +237,26 @@ static GSF_CLASS (GnmStyleConditions, gnm_style_conditions,
* Returns a GnmStyleConditions that the caller is resoinsible for.
**/
GnmStyleConditions *
-gnm_style_conditions_new (void)
+gnm_style_conditions_new (Sheet *sheet)
{
- return g_object_new (gnm_style_conditions_get_type (), NULL);
+ GnmStyleConditions *res;
+ g_return_val_if_fail (IS_SHEET (sheet), NULL);
+
+ res = g_object_new (gnm_style_conditions_get_type (), NULL);
+ res->sheet = sheet;
+ return res;
}
GnmStyleConditions *
-gnm_style_conditions_dup (GnmStyleConditions const *cond)
+gnm_style_conditions_dup (GnmStyleConditions const *sc)
{
GnmStyleConditions *dup;
GPtrArray const *ga;
- if (cond == NULL)
+ if (sc == NULL)
return NULL;
- dup = gnm_style_conditions_new ();
- ga = gnm_style_conditions_details (cond);
+ dup = gnm_style_conditions_new (gnm_style_conditions_get_sheet (sc));
+ ga = gnm_style_conditions_details (sc);
if (ga != NULL) {
guint i;
GPtrArray *ga_dup = g_ptr_array_sized_new (ga->len);
@@ -196,6 +269,30 @@ gnm_style_conditions_dup (GnmStyleConditions const *cond)
return dup;
}
+Sheet *
+gnm_style_conditions_get_sheet (GnmStyleConditions const *sc)
+{
+ g_return_val_if_fail (sc != NULL, NULL);
+ return sc->sheet;
+}
+
+void
+gnm_style_conditions_set_sheet (GnmStyleConditions *sc, Sheet *sheet)
+{
+ GPtrArray const *ga;
+ unsigned ui;
+
+ g_return_if_fail (sc != NULL);
+ g_return_if_fail (IS_SHEET (sheet));
+
+ sc->sheet = sheet;
+ ga = gnm_style_conditions_details (sc);
+ for (ui = 0; ga && ui < ga->len; ui++) {
+ GnmStyleCond *cond = g_ptr_array_index (ga, ui);
+ gnm_style_cond_set_sheet (cond, sheet);
+ }
+}
+
/**
* gnm_style_conditions_details :
@@ -225,10 +322,13 @@ gnm_style_conditions_insert (GnmStyleConditions *sc,
{
GnmStyleCond *cond;
+ g_return_if_fail (sc != NULL);
g_return_if_fail (cond_ != NULL);
- if (sc == NULL || !gnm_style_cond_is_valid (cond_))
- return;
+ g_return_if_fail (gnm_style_cond_is_valid (cond_));
+
+ g_return_if_fail (gnm_style_conditions_get_sheet (sc) ==
+ gnm_style_cond_get_sheet (cond_));
if (sc->conditions == NULL)
sc->conditions = g_ptr_array_new ();
@@ -336,7 +436,7 @@ gnm_style_conditions_eval (GnmStyleConditions const *sc, GnmEvalPos const *ep)
}
}
} else {
- val = gnm_expr_top_eval (cond->texpr[0], ep, GNM_EXPR_EVAL_SCALAR_NON_EMPTY);
+ val = gnm_expr_top_eval (cond->deps[0].texpr, ep, GNM_EXPR_EVAL_SCALAR_NON_EMPTY);
if (cond->op == GNM_STYLE_COND_CUSTOM) {
use_this = value_get_as_bool (val, NULL);
#if 0
@@ -358,7 +458,7 @@ gnm_style_conditions_eval (GnmStyleConditions const *sc, GnmEvalPos const *ep)
break;
}
value_release (val);
- val = gnm_expr_top_eval (cond->texpr[1], ep, GNM_EXPR_EVAL_SCALAR_NON_EMPTY);
+ val = gnm_expr_top_eval (cond->deps[1].texpr, ep, GNM_EXPR_EVAL_SCALAR_NON_EMPTY);
diff = value_compare (cv, val, TRUE);
/* fall through */
@@ -369,7 +469,7 @@ gnm_style_conditions_eval (GnmStyleConditions const *sc, GnmEvalPos const *ep)
if (diff == IS_LESS)
break;
value_release (val);
- val = gnm_expr_top_eval (cond->texpr[1], ep, GNM_EXPR_EVAL_SCALAR_NON_EMPTY);
+ val = gnm_expr_top_eval (cond->deps[1].texpr, ep, GNM_EXPR_EVAL_SCALAR_NON_EMPTY);
diff = value_compare (cv, val, TRUE);
/* fall through */
case GNM_STYLE_COND_LTE: use_this = (diff == IS_LESS || diff == IS_EQUAL); break;
diff --git a/src/style-conditions.h b/src/style-conditions.h
index 029b097..6dbf1d1 100644
--- a/src/style-conditions.h
+++ b/src/style-conditions.h
@@ -3,6 +3,7 @@
# define _GNM_STYLE_CONDITIONS_H_
#include "gnumeric.h"
+#include <dependent.h>
G_BEGIN_DECLS
@@ -38,22 +39,29 @@ typedef enum {
typedef struct {
GnmStyle *overlay;
- GnmExprTop const *texpr[2];
+ GnmDependent deps[2];
GnmStyleCondOp op;
} GnmStyleCond;
-GnmStyleCond *gnm_style_cond_new (GnmStyleCondOp op);
+GnmStyleCond *gnm_style_cond_new (GnmStyleCondOp op, Sheet *sheet);
void gnm_style_cond_free (GnmStyleCond *cond);
GnmStyleCond *gnm_style_cond_dup (GnmStyleCond const *src);
gboolean gnm_style_cond_is_valid (GnmStyleCond const *cond);
+
+void gnm_style_cond_set_overlay (GnmStyleCond *cond,
+ GnmStyle *overlay);
+
+GnmExprTop const *gnm_style_cond_get_expr (GnmStyleCond const *cond,
+ unsigned idx);
void gnm_style_cond_set_expr (GnmStyleCond *cond,
GnmExprTop const *texpr,
unsigned idx);
-void gnm_style_cond_set_overlay (GnmStyleCond *cond,
- GnmStyle *overlay);
-GnmStyleConditions *gnm_style_conditions_new (void);
-GnmStyleConditions *gnm_style_conditions_dup (GnmStyleConditions const *cond);
+Sheet *gnm_style_cond_get_sheet (GnmStyleCond const *cond);
+void gnm_style_cond_set_sheet (GnmStyleCond *cond, Sheet *sheet);
+
+GnmStyleConditions *gnm_style_conditions_new (Sheet *sheet);
+GnmStyleConditions *gnm_style_conditions_dup (GnmStyleConditions const *sc);
GPtrArray const *gnm_style_conditions_details (GnmStyleConditions const *sc);
void gnm_style_conditions_insert (GnmStyleConditions *sc,
GnmStyleCond const *cond,
@@ -65,6 +73,10 @@ GPtrArray *gnm_style_conditions_overlay (GnmStyleConditions const *sc,
int gnm_style_conditions_eval (GnmStyleConditions const *sc,
GnmEvalPos const *pos);
+Sheet *gnm_style_conditions_get_sheet (GnmStyleConditions const *sc);
+void gnm_style_conditions_set_sheet (GnmStyleConditions *sc,
+ Sheet *sheet);
+
G_END_DECLS
#endif /* _GNM_STYLE_CONDITIONS_H_ */
diff --git a/src/xml-sax-read.c b/src/xml-sax-read.c
index 0841596..cd03fe0 100644
--- a/src/xml-sax-read.c
+++ b/src/xml-sax-read.c
@@ -1690,7 +1690,7 @@ xml_sax_condition (GsfXMLIn *xin, xmlChar const **attrs)
unknown_attr (xin, attrs);
}
- state->cond = gnm_style_cond_new (op);
+ state->cond = gnm_style_cond_new (op, state->sheet);
}
static void
@@ -1711,7 +1711,7 @@ xml_sax_condition_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
if (!gnm_style_is_element_set (state->style, MSTYLE_CONDITIONS) ||
NULL == (sc = gnm_style_get_conditions (state->style)))
gnm_style_set_conditions (state->style,
- (sc = gnm_style_conditions_new ()));
+ (sc = gnm_style_conditions_new (state->sheet)));
gnm_style_conditions_insert (sc, state->cond, -1);
gnm_style_cond_free (state->cond);
@@ -1727,8 +1727,7 @@ xml_sax_condition_expr_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
GnmExprTop const *texpr;
GnmParsePos pos;
- g_return_if_fail (state->cond != NULL);
- g_return_if_fail (state->cond->texpr[i] == NULL);
+ g_return_if_fail (gnm_style_cond_get_expr (state->cond, i) == NULL);
texpr = gnm_expr_parse_str (xin->content->str,
parse_pos_init_sheet (&pos, state->sheet),
diff --git a/src/xml-sax-write.c b/src/xml-sax-write.c
index 9978695..d1a4467 100644
--- a/src/xml-sax-write.c
+++ b/src/xml-sax-write.c
@@ -606,24 +606,27 @@ xml_write_style (GnmOutputXML *state, GnmStyle const *style)
NULL != (sc = gnm_style_get_conditions (style))) {
GPtrArray const *conds = gnm_style_conditions_details (sc);
if (conds != NULL) {
- char *tmp;
GnmParsePos pp;
parse_pos_init_sheet (&pp, (Sheet *)state->sheet);
for (i = 0 ; i < conds->len ; i++) {
+ unsigned ui;
GnmStyleCond const *cond =
g_ptr_array_index (conds, i);
gsf_xml_out_start_element (state->output, GNM "Condition");
gsf_xml_out_add_int (state->output, "Operator", cond->op);
- if (cond->texpr[0] != NULL &&
- (tmp = gnm_expr_top_as_string (cond->texpr[0], &pp, state->convs)) != NULL) {
- gsf_xml_out_simple_element (state->output, GNM "Expression0", tmp);
- g_free (tmp);
- }
- if (cond->texpr[1] != NULL &&
- (tmp = gnm_expr_top_as_string (cond->texpr[1], &pp, state->convs)) != NULL) {
- gsf_xml_out_simple_element (state->output, GNM "Expression1", tmp);
- g_free (tmp);
+ for (ui = 0; ui < 2; ui++) {
+ GnmExprTop const *texpr = gnm_style_cond_get_expr (cond, ui);
+ char *tmp = texpr
+ ? gnm_expr_top_as_string (texpr, &pp, state->convs)
+ : NULL;
+ const char *attr = (ui == 0)
+ ? GNM "Expression0"
+ : GNM "Expression1";
+ if (tmp) {
+ gsf_xml_out_simple_element (state->output, attr, tmp);
+ g_free (tmp);
+ }
}
xml_write_style (state, cond->overlay);
gsf_xml_out_end_element (state->output); /* </Condition> */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]