[gnumeric] GnmDepManaged: new type.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] GnmDepManaged: new type.
- Date: Sun, 12 Jul 2020 01:38:10 +0000 (UTC)
commit a94104badf27b40f30bef953d71bb8e925f84e2b
Author: Morten Welinder <terra gnome org>
Date: Sat Jul 11 21:36:37 2020 -0400
GnmDepManaged: new type.
This introduces a specific type for managed dependents instead of simply
using GnmDependent.
At the same time, a position-aware variant is introduced. It is not yet
used.
plugins/excel/ms-excel-write.c | 16 ++++-----
plugins/excel/xlsx-write.c | 4 +--
plugins/openoffice/openoffice-write.c | 44 ++++++++++++------------
src/dependent.c | 59 +++++++++++++++++++++++++--------
src/dependent.h | 20 ++++++++---
src/dialogs/dialog-cell-format.c | 4 +--
src/hlink.c | 9 +++--
src/style-conditions.c | 18 +++++-----
src/style-conditions.h | 2 +-
src/tools/gnm-solver.c | 32 +++++++++---------
src/tools/gnm-solver.h | 8 ++---
src/tools/scenarios.c | 10 +++---
src/tools/scenarios.h | 2 +-
src/validation.c | 14 ++++----
src/validation.h | 2 +-
src/wbc-gtk.c | 2 +-
src/widgets/gnm-validation-combo-view.c | 4 +--
src/workbook-view.c | 10 +++---
src/workbook-view.h | 2 +-
src/xml-sax-write.c | 27 ++++++++-------
20 files changed, 167 insertions(+), 122 deletions(-)
---
diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c
index 9fe642534..03fad2ccf 100644
--- a/plugins/excel/ms-excel-write.c
+++ b/plugins/excel/ms-excel-write.c
@@ -1549,10 +1549,10 @@ excel_write_DV (XLValInputPair const *vip, gpointer dummy, ExcelWriteSheet *eshe
GSF_LE_SET_GUINT16 (data+2, 0); /* Undocumented, use 0 for now */
ms_biff_put_var_write (bp, data, 4);
- if (vip->v != NULL && vip->v->deps[0].texpr != NULL) {
+ if (vip->v != NULL && vip->v->deps[0].base.texpr != NULL) {
unsigned pos = bp->curpos;
guint16 len = excel_write_formula (esheet->ewb,
- vip->v->deps[0].texpr,
+ vip->v->deps[0].base.texpr,
esheet->gnum_sheet, col, row,
context);
unsigned end_pos = bp->curpos;
@@ -1565,10 +1565,10 @@ excel_write_DV (XLValInputPair const *vip, gpointer dummy, ExcelWriteSheet *eshe
GSF_LE_SET_GUINT16 (data , 0); /* bogus len fill in later */
GSF_LE_SET_GUINT16 (data+2, 0); /* Undocumented, use 0 for now */
ms_biff_put_var_write (bp, data, 4);
- if (vip->v != NULL && vip->v->deps[1].texpr != NULL) {
+ if (vip->v != NULL && vip->v->deps[1].base.texpr != NULL) {
unsigned pos = bp->curpos;
guint16 len = excel_write_formula (esheet->ewb,
- vip->v->deps[1].texpr,
+ vip->v->deps[1].base.texpr,
esheet->gnum_sheet, col, row,
context);
unsigned end_pos = bp->curpos;
@@ -1839,10 +1839,10 @@ excel_write_prep_validations (ExcelWriteSheet *esheet)
GnmValidation const *v = gnm_style_get_validation (sr->style);
if (!v)
continue;
- if (v->deps[0].texpr != NULL)
- excel_write_prep_expr (esheet->ewb, v->deps[0].texpr);
- if (v->deps[1].texpr != NULL)
- excel_write_prep_expr (esheet->ewb, v->deps[1].texpr);
+ if (v->deps[0].base.texpr != NULL)
+ excel_write_prep_expr (esheet->ewb, v->deps[0].base.texpr);
+ if (v->deps[1].base.texpr != NULL)
+ excel_write_prep_expr (esheet->ewb, v->deps[1].base.texpr);
}
}
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index de3daddfb..68f365bf5 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -2042,9 +2042,9 @@ xlsx_write_validation (XLValInputPair const *vip, G_GNUC_UNUSED gpointer dummy,
if (NULL != vip->v) {
GnmRange const *first = vip->ranges->data;
xlsx_write_validation_expr (info, &first->start,
- "formula1", vip->v->deps[0].texpr);
+ "formula1", vip->v->deps[0].base.texpr);
xlsx_write_validation_expr (info, &first->start,
- "formula2", vip->v->deps[1].texpr);
+ "formula2", vip->v->deps[1].base.texpr);
}
gsf_xml_out_end_element (info->xml); /* </dataValidation> */
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 8c571ce86..a2a12c0b2 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -4528,13 +4528,13 @@ odf_validation_append_expression_pair (GnmOOExport *state, GString *str,
GnmValidation const *val,
GnmParsePos *pp)
{
- g_string_append_c (str, '(');
- odf_validation_append_expression (state, str,
- val->deps[0].texpr, pp);
- g_string_append_c (str, ',');
- odf_validation_append_expression (state, str,
- val->deps[1].texpr, pp);
- g_string_append_c (str, ')');
+ g_string_append_c (str, '(');
+ odf_validation_append_expression (state, str,
+ val->deps[0].base.texpr, pp);
+ g_string_append_c (str, ',');
+ odf_validation_append_expression (state, str,
+ val->deps[1].base.texpr, pp);
+ g_string_append_c (str, ')');
}
@@ -4545,6 +4545,7 @@ odf_validation_general (GnmOOExport *state, GnmValidation const *val,
char const *prefix, GnmParsePos *pp)
{
GString *str = g_string_new ("of:");
+ GnmExprTop const *texpr0 = val->deps[0].base.texpr;
g_string_append (str, prefix);
@@ -4562,27 +4563,27 @@ odf_validation_general (GnmOOExport *state, GnmValidation const *val,
break;
case GNM_VALIDATION_OP_EQUAL:
g_string_append (str, "cell-content() = ");
- odf_validation_append_expression (state, str, val->deps[0].texpr, pp);
+ odf_validation_append_expression (state, str, texpr0, pp);
break;
case GNM_VALIDATION_OP_NOT_EQUAL:
g_string_append (str, "cell-content() != ");
- odf_validation_append_expression (state, str, val->deps[0].texpr, pp);
+ odf_validation_append_expression (state, str, texpr0, pp);
break;
case GNM_VALIDATION_OP_GT:
g_string_append (str, "cell-content() > ");
- odf_validation_append_expression (state, str, val->deps[0].texpr, pp);
+ odf_validation_append_expression (state, str, texpr0, pp);
break;
case GNM_VALIDATION_OP_LT:
g_string_append (str, "cell-content() < ");
- odf_validation_append_expression (state, str, val->deps[0].texpr, pp);
+ odf_validation_append_expression (state, str, texpr0, pp);
break;
case GNM_VALIDATION_OP_GTE:
g_string_append (str, "cell-content() >= ");
- odf_validation_append_expression (state, str, val->deps[0].texpr, pp);
+ odf_validation_append_expression (state, str, texpr0, pp);
break;
case GNM_VALIDATION_OP_LTE:
g_string_append (str, "cell-content() <= ");
- odf_validation_append_expression (state, str, val->deps[0].texpr, pp);
+ odf_validation_append_expression (state, str, texpr0, pp);
break;
}
@@ -4596,6 +4597,7 @@ odf_validation_length (GnmOOExport *state, GnmValidation const *val,
G_GNUC_UNUSED GnmStyleRegion const *sr, GnmParsePos *pp)
{
GString *str = g_string_new ("of:");
+ GnmExprTop const *texpr0 = val->deps[0].base.texpr;
switch (val->op) {
case GNM_VALIDATION_OP_NONE:
@@ -4611,27 +4613,27 @@ odf_validation_length (GnmOOExport *state, GnmValidation const *val,
break;
case GNM_VALIDATION_OP_EQUAL:
g_string_append (str, "cell-content-text-length() = ");
- odf_validation_append_expression (state, str, val->deps[0].texpr, pp);
+ odf_validation_append_expression (state, str, texpr0, pp);
break;
case GNM_VALIDATION_OP_NOT_EQUAL:
g_string_append (str, "cell-content-text-length() != ");
- odf_validation_append_expression (state, str, val->deps[0].texpr, pp);
+ odf_validation_append_expression (state, str, texpr0, pp);
break;
case GNM_VALIDATION_OP_GT:
g_string_append (str, "cell-content-text-length() > ");
- odf_validation_append_expression (state, str, val->deps[0].texpr, pp);
+ odf_validation_append_expression (state, str, texpr0, pp);
break;
case GNM_VALIDATION_OP_LT:
g_string_append (str, "cell-content-text-length() < ");
- odf_validation_append_expression (state, str, val->deps[0].texpr, pp);
+ odf_validation_append_expression (state, str, texpr0, pp);
break;
case GNM_VALIDATION_OP_GTE:
g_string_append (str, "of:cell-content-text-length() >= ");
- odf_validation_append_expression (state, str, val->deps[0].texpr, pp);
+ odf_validation_append_expression (state, str, texpr0, pp);
break;
case GNM_VALIDATION_OP_LTE:
g_string_append (str, "cell-content-text-length() <= ");
- odf_validation_append_expression (state, str, val->deps[0].texpr, pp);
+ odf_validation_append_expression (state, str, texpr0, pp);
break;
}
@@ -4647,7 +4649,7 @@ odf_validation_custom (GnmOOExport *state, GnmValidation const *val,
GString *str = g_string_new (NULL);
g_string_append (str, "of:is-true-formula(");
- odf_validation_append_expression (state, str, val->deps[0].texpr, pp);
+ odf_validation_append_expression (state, str, val->deps[0].base.texpr, pp);
g_string_append_c (str, ')');
gsf_xml_out_add_cstr (state->xml, TABLE "condition", str->str);
@@ -4662,7 +4664,7 @@ odf_validation_in_list (GnmOOExport *state, GnmValidation const *val,
GString *str;
str = g_string_new ("of:cell-content-is-in-list(");
- odf_validation_append_expression (state, str, val->deps[0].texpr, pp);
+ odf_validation_append_expression (state, str, val->deps[0].base.texpr, pp);
g_string_append_c (str, ')');
gsf_xml_out_add_cstr (state->xml, TABLE "condition", str->str);
diff --git a/src/dependent.c b/src/dependent.c
index 935ac97aa..c365ab89c 100644
--- a/src/dependent.c
+++ b/src/dependent.c
@@ -339,6 +339,15 @@ static const GnmDependentClass managed_dep_class = {
managed_dep_debug_name,
};
+static GnmCellPos *managed_dep_pos (GnmDependent const *dep);
+static const GnmDependentClass managed_pos_dep_class = {
+ dummy_dep_eval,
+ NULL,
+ NULL,
+ managed_dep_pos,
+ managed_dep_debug_name,
+};
+
static void style_dep_eval (GnmDependent *dep);
static GSList *style_dep_changed (GnmDependent *dep);
static GnmCellPos *style_dep_pos (GnmDependent const *dep);
@@ -370,6 +379,7 @@ dependent_types_init (void)
g_ptr_array_add (dep_classes, (gpointer)&dynamic_dep_class);
g_ptr_array_add (dep_classes, (gpointer)&name_dep_class);
g_ptr_array_add (dep_classes, (gpointer)&managed_dep_class);
+ g_ptr_array_add (dep_classes, (gpointer)&managed_pos_dep_class);
g_ptr_array_add (dep_classes, (gpointer)&style_dep_class);
#if USE_POOLS
@@ -1450,19 +1460,36 @@ cell_dep_debug_name (GnmDependent const *dep, GString *target)
* the dependency system so it follows row/column insert/delete nicely.
*
* The expression being managed is typically a cell range, but can be any
- * expression. Everything is interpreted relative to A1 in the sheet.
+ * expression. There are two versions: only with a position and one without.
+ * In the no-position version, everything is interpreted relative to A1 in the
+ * sheet.
*/
void
-dependent_managed_init (GnmDependent *dep, Sheet *sheet)
+dependent_managed_init (GnmDepManaged *dep, Sheet *sheet)
{
memset (dep, 0, sizeof (*dep));
- dep->flags = DEPENDENT_MANAGED;
- dep->sheet = sheet;
+ dep->base.flags = DEPENDENT_MANAGED;
+ dep->base.sheet = sheet;
}
void
-dependent_managed_set_expr (GnmDependent *dep, GnmExprTop const *texpr)
+dependent_managed_pos_init (GnmDepManaged *dep, Sheet *sheet, GnmCellPos const *pos)
+{
+ dependent_managed_init (dep, sheet);
+ dep->base.flags = DEPENDENT_MANAGED_POS;
+ dep->pos = *pos;
+}
+
+GnmExprTop const *
+dependent_managed_get_expr (GnmDepManaged const *dep)
+{
+ g_return_val_if_fail (dep != NULL, NULL);
+ return dep->base.texpr;
+}
+
+void
+dependent_managed_set_expr (GnmDepManaged *dep, GnmExprTop const *texpr)
{
g_return_if_fail (dep != NULL);
#if 0
@@ -1470,13 +1497,13 @@ dependent_managed_set_expr (GnmDependent *dep, GnmExprTop const *texpr)
g_return_if_fail (dependent_type (dep) == DEPENDENT_MANAGED);
#endif
- dependent_set_expr (dep, texpr);
- if (texpr && dep->sheet)
- dependent_link (dep);
+ dependent_set_expr (&dep->base, texpr);
+ if (texpr && dep->base.sheet)
+ dependent_link (&dep->base);
}
void
-dependent_managed_set_sheet (GnmDependent *dep, Sheet *sheet)
+dependent_managed_set_sheet (GnmDepManaged *dep, Sheet *sheet)
{
GnmExprTop const *texpr;
@@ -1486,14 +1513,14 @@ dependent_managed_set_sheet (GnmDependent *dep, Sheet *sheet)
g_return_if_fail (dependent_type (dep) == DEPENDENT_MANAGED);
#endif
- if (dep->sheet == sheet)
+ if (dep->base.sheet == sheet)
return;
- texpr = dep->texpr;
+ texpr = dep->base.texpr;
if (texpr) gnm_expr_top_ref (texpr);
- dependent_set_expr (dep, NULL);
+ dependent_set_expr (&dep->base, NULL);
/* We're now unlinked from everything. */
- dep->sheet = sheet;
+ dep->base.sheet = sheet;
dependent_managed_set_expr (dep, texpr);
if (texpr) gnm_expr_top_unref (texpr);
}
@@ -1504,6 +1531,12 @@ managed_dep_debug_name (GnmDependent const *dep, GString *target)
g_string_append_printf (target, "Managed%p", (void *)dep);
}
+static GnmCellPos *
+managed_dep_pos (GnmDependent const *dep)
+{
+ return &((GnmDepManaged*)dep)->pos;
+}
+
/*****************************************************************************/
static gboolean
diff --git a/src/dependent.h b/src/dependent.h
index 75feaef31..7a5917cb2 100644
--- a/src/dependent.h
+++ b/src/dependent.h
@@ -31,7 +31,8 @@ typedef enum {
DEPENDENT_DYNAMIC_DEP = 0x00000002, /* builtin type */
DEPENDENT_NAME = 0x00000003, /* builtin pseudo type */
DEPENDENT_MANAGED = 0x00000004, /* builtin type */
- DEPENDENT_STYLE = 0x00000005, /* builtin type */
+ DEPENDENT_MANAGED_POS = 0x00000005, /* builtin type */
+ DEPENDENT_STYLE = 0x00000006, /* builtin type */
DEPENDENT_TYPE_MASK = 0x00000fff,
/* Linked into the workbook wide expression list */
@@ -127,9 +128,20 @@ void dependents_dump (Workbook *wb);
void gnm_dep_container_sanity_check (GnmDepContainer const *deps);
void gnm_dep_container_resize (GnmDepContainer *deps, int rows);
-void dependent_managed_init (GnmDependent *dep, Sheet *sheet);
-void dependent_managed_set_expr (GnmDependent *dep, GnmExprTop const *texpr);
-void dependent_managed_set_sheet (GnmDependent *dep, Sheet *sheet);
+// ----------------------------------------------------------------------------
+
+typedef struct {
+ GnmDependent base;
+ GnmCellPos pos;
+} GnmDepManaged;
+
+void dependent_managed_init (GnmDepManaged *dep, Sheet *sheet);
+void dependent_managed_pos_init (GnmDepManaged *dep, Sheet *sheet, GnmCellPos const *pos);
+void dependent_managed_set_expr (GnmDepManaged *dep, GnmExprTop const *texpr);
+GnmExprTop const *dependent_managed_get_expr (GnmDepManaged const *dep);
+void dependent_managed_set_sheet (GnmDepManaged *dep, Sheet *sheet);
+
+
#define DEPENDENT_CONTAINER_FOREACH_DEPENDENT(dc, dep, code) \
do { \
diff --git a/src/dialogs/dialog-cell-format.c b/src/dialogs/dialog-cell-format.c
index 779d5aa16..a4f54f8b4 100644
--- a/src/dialogs/dialog-cell-format.c
+++ b/src/dialogs/dialog-cell-format.c
@@ -1945,9 +1945,9 @@ fmt_dialog_init_validation_page (FormatState *state)
parse_pos_init (&pp, state->sheet->workbook, state->sheet,
state->sv->edit_pos.col, state->sv->edit_pos.row);
gnm_expr_entry_load_from_expr (state->validation.expr0.entry,
- v->deps[0].texpr, &pp);
+ v->deps[0].base.texpr, &pp);
gnm_expr_entry_load_from_expr (state->validation.expr1.entry,
- v->deps[1].texpr, &pp);
+ v->deps[1].base.texpr, &pp);
}
cb_validation_sensitivity (NULL, state);
diff --git a/src/hlink.c b/src/hlink.c
index 582fa4641..5a298313d 100644
--- a/src/hlink.c
+++ b/src/hlink.c
@@ -1,4 +1,3 @@
-
/*
* hlink.c: hyperlink support
*
@@ -267,7 +266,7 @@ typedef struct { GnmHLinkClass hlink; } GnmHLinkCurWBClass;
typedef struct {
GnmHLink hlink;
- GnmDependent dep;
+ GnmDepManaged dep;
} GnmHLinkCurWB;
#define GNM_HLINK_CUR_WB(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), gnm_hlink_cur_wb_get_type (), GnmHLinkCurWB))
@@ -349,7 +348,7 @@ static const char *
gnm_hlink_cur_wb_get_target (GnmHLink const *lnk)
{
GnmHLinkCurWB *hlcwb = (GnmHLinkCurWB *)lnk;
- GnmExprTop const *texpr = hlcwb->dep.texpr;
+ GnmExprTop const *texpr = dependent_managed_get_expr (&hlcwb->dep);
char *tgt = NULL;
Sheet *sheet = lnk->sheet;
@@ -436,7 +435,7 @@ gnm_hlink_get_range_target (GnmHLink const *lnk, GnmSheetRange *sr)
return FALSE;
hlcwb = (GnmHLinkCurWB *)lnk;
- texpr = hlcwb->dep.texpr;
+ texpr = dependent_managed_get_expr (&hlcwb->dep);
if (!texpr)
return FALSE;
vr = gnm_expr_top_get_range (texpr);
@@ -474,7 +473,7 @@ gnm_hlink_get_target_expr (GnmHLink const *lnk)
return NULL;
hlcwb = (GnmHLinkCurWB *)lnk;
- return hlcwb->dep.texpr;
+ return dependent_managed_get_expr (&hlcwb->dep);
}
diff --git a/src/style-conditions.c b/src/style-conditions.c
index 417548c3e..13e796ad5 100644
--- a/src/style-conditions.c
+++ b/src/style-conditions.c
@@ -107,7 +107,7 @@ gnm_style_cond_is_valid (GnmStyleCond const *cond)
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);
+ gboolean have = (dependent_managed_get_expr (&cond->deps[ui]) != NULL);
if (have != need)
return FALSE;
}
@@ -147,7 +147,7 @@ gnm_style_cond_dup (GnmStyleCond const *src)
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->deps[ui].texpr, ui);
+ gnm_style_cond_set_expr (dst, dependent_managed_get_expr (&src->deps[ui]), ui);
return dst;
}
@@ -191,7 +191,7 @@ Sheet *
gnm_style_cond_get_sheet (GnmStyleCond const *cond)
{
g_return_val_if_fail (cond != NULL, NULL);
- return cond->deps[0].sheet;
+ return cond->deps[0].base.sheet;
}
void
@@ -219,7 +219,7 @@ 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;
+ return dependent_managed_get_expr (&cond->deps[idx]);
}
void
@@ -566,11 +566,11 @@ gnm_style_cond_eval (GnmStyleCond const *cond, GnmValue const *cv,
switch (gnm_style_cond_op_operands (cond->op)) {
case 2:
- val1 = gnm_expr_top_eval (cond->deps[1].texpr, ep,
+ val1 = gnm_expr_top_eval (cond->deps[1].base.texpr, ep,
GNM_EXPR_EVAL_SCALAR_NON_EMPTY);
/* Fall through */
case 1:
- val0 = gnm_expr_top_eval (cond->deps[0].texpr, ep,
+ val0 = gnm_expr_top_eval (cond->deps[0].base.texpr, ep,
GNM_EXPR_EVAL_SCALAR_NON_EMPTY);
/* Fall through */
case 0:
@@ -674,10 +674,10 @@ gnm_style_cond_equal (GnmStyleCond const *ca, GnmStyleCond const *cb,
N = gnm_style_cond_op_operands (ca->op);
for (oi = 0; oi < N; oi++) {
- if (!relax_sheet && ca->deps[oi].sheet != cb->deps[oi].sheet)
+ if (!relax_sheet && ca->deps[oi].base.sheet != cb->deps[oi].base.sheet)
return FALSE;
- if (!gnm_expr_top_equal (ca->deps[oi].texpr,
- cb->deps[oi].texpr))
+ if (!gnm_expr_top_equal (ca->deps[oi].base.texpr,
+ cb->deps[oi].base.texpr))
return FALSE;
}
diff --git a/src/style-conditions.h b/src/style-conditions.h
index 7971c58d0..3a71ab244 100644
--- a/src/style-conditions.h
+++ b/src/style-conditions.h
@@ -38,7 +38,7 @@ typedef enum {
typedef struct {
GnmStyle *overlay;
- GnmDependent deps[2];
+ GnmDepManaged deps[2];
GnmStyleCondOp op;
} GnmStyleCond;
diff --git a/src/tools/gnm-solver.c b/src/tools/gnm-solver.c
index d19141aaa..9bcab0f96 100644
--- a/src/tools/gnm-solver.c
+++ b/src/tools/gnm-solver.c
@@ -157,15 +157,15 @@ gnm_solver_constraint_dup (GnmSolverConstraint *c, Sheet *sheet)
{
GnmSolverConstraint *res = gnm_solver_constraint_new (sheet);
res->type = c->type;
- dependent_managed_set_expr (&res->lhs, c->lhs.texpr);
- dependent_managed_set_expr (&res->rhs, c->rhs.texpr);
+ dependent_managed_set_expr (&res->lhs, c->lhs.base.texpr);
+ dependent_managed_set_expr (&res->rhs, c->rhs.base.texpr);
return res;
}
static GnmSolverConstraint *
gnm_solver_constraint_dup1 (GnmSolverConstraint *c)
{
- return gnm_solver_constraint_dup (c, c->lhs.sheet);
+ return gnm_solver_constraint_dup (c, c->lhs.base.sheet);
}
GType
@@ -185,9 +185,9 @@ gnm_solver_constraint_equal (GnmSolverConstraint const *a,
GnmSolverConstraint const *b)
{
return (a->type == b->type &&
- gnm_expr_top_equal (a->lhs.texpr, b->lhs.texpr) &&
+ gnm_expr_top_equal (a->lhs.base.texpr, b->lhs.base.texpr) &&
(!gnm_solver_constraint_has_rhs (a) ||
- gnm_expr_top_equal (a->rhs.texpr, b->rhs.texpr)));
+ gnm_expr_top_equal (a->rhs.base.texpr, b->rhs.base.texpr)));
}
gboolean
@@ -273,7 +273,7 @@ gnm_solver_constraint_valid (GnmSolverConstraint const *c,
GnmValue const *
gnm_solver_constraint_get_lhs (GnmSolverConstraint const *c)
{
- GnmExprTop const *texpr = c->lhs.texpr;
+ GnmExprTop const *texpr = c->lhs.base.texpr;
return texpr ? gnm_expr_top_get_constant (texpr) : NULL;
}
@@ -299,7 +299,7 @@ gnm_solver_constraint_set_lhs (GnmSolverConstraint *c, GnmValue *v)
GnmValue const *
gnm_solver_constraint_get_rhs (GnmSolverConstraint const *c)
{
- GnmExprTop const *texpr = c->rhs.texpr;
+ GnmExprTop const *texpr = c->rhs.base.texpr;
return texpr ? gnm_expr_top_get_constant (texpr) : NULL;
}
@@ -416,7 +416,7 @@ gnm_solver_constraint_side_as_str (GnmSolverConstraint const *c,
{
GnmExprTop const *texpr;
- texpr = lhs ? c->lhs.texpr : c->rhs.texpr;
+ texpr = lhs ? c->lhs.base.texpr : c->rhs.base.texpr;
if (texpr) {
GnmConventionsOut out;
GnmParsePos pp;
@@ -521,8 +521,8 @@ gnm_solver_param_dup (GnmSolverParameters *src, Sheet *new_sheet)
GSList *l;
dst->problem_type = src->problem_type;
- dependent_managed_set_expr (&dst->target, src->target.texpr);
- dependent_managed_set_expr (&dst->input, src->input.texpr);
+ dependent_managed_set_expr (&dst->target, src->target.base.texpr);
+ dependent_managed_set_expr (&dst->input, src->input.base.texpr);
g_free (dst->options.scenario_name);
dst->options = src->options;
@@ -551,8 +551,8 @@ gnm_solver_param_equal (GnmSolverParameters const *a,
if (a->sheet != b->sheet ||
a->problem_type != b->problem_type ||
- !gnm_expr_top_equal (a->target.texpr, b->target.texpr) ||
- !gnm_expr_top_equal (a->input.texpr, b->input.texpr) ||
+ !gnm_expr_top_equal (a->target.base.texpr, b->target.base.texpr) ||
+ !gnm_expr_top_equal (a->input.base.texpr, b->input.base.texpr) ||
a->options.max_time_sec != b->options.max_time_sec ||
a->options.max_iter != b->options.max_iter ||
a->options.algorithm != b->options.algorithm ||
@@ -587,8 +587,8 @@ gnm_solver_param_equal (GnmSolverParameters const *a,
GnmValue const *
gnm_solver_param_get_input (GnmSolverParameters const *sp)
{
- return sp->input.texpr
- ? gnm_expr_top_get_constant (sp->input.texpr)
+ return sp->input.base.texpr
+ ? gnm_expr_top_get_constant (sp->input.base.texpr)
: NULL;
}
@@ -662,8 +662,8 @@ gnm_solver_param_set_target (GnmSolverParameters *sp, GnmCellRef const *cr)
const GnmCellRef *
gnm_solver_param_get_target (GnmSolverParameters const *sp)
{
- return sp->target.texpr
- ? gnm_expr_top_get_cellref (sp->target.texpr)
+ return sp->target.base.texpr
+ ? gnm_expr_top_get_cellref (sp->target.base.texpr)
: NULL;
}
diff --git a/src/tools/gnm-solver.h b/src/tools/gnm-solver.h
index 802acf60c..c2f1d2fb6 100644
--- a/src/tools/gnm-solver.h
+++ b/src/tools/gnm-solver.h
@@ -61,10 +61,10 @@ struct GnmSolverConstraint_ {
GnmSolverConstraintType type;
/* Must be a range. */
- GnmDependent lhs;
+ GnmDepManaged lhs;
/* Must be a constant or a range. */
- GnmDependent rhs;
+ GnmDepManaged rhs;
};
GType gnm_solver_constraint_get_type (void);
@@ -131,8 +131,8 @@ struct GnmSolverParameters_ {
Sheet *sheet;
GnmSolverProblemType problem_type;
- GnmDependent target;
- GnmDependent input;
+ GnmDepManaged target;
+ GnmDepManaged input;
GSList *constraints;
GnmSolverOptions options;
};
diff --git a/src/tools/scenarios.c b/src/tools/scenarios.c
index a37e143c9..a94d17e35 100644
--- a/src/tools/scenarios.c
+++ b/src/tools/scenarios.c
@@ -59,8 +59,8 @@ gnm_scenario_item_free (GnmScenarioItem *sci)
static GnmScenarioItem *
gnm_scenario_item_dup (GnmScenarioItem *src)
{
- GnmScenarioItem *dst = gnm_scenario_item_new (src->dep.sheet);
- dependent_managed_set_expr (&dst->dep, src->dep.texpr);
+ GnmScenarioItem *dst = gnm_scenario_item_new (src->dep.base.sheet);
+ dependent_managed_set_expr (&dst->dep, src->dep.base.texpr);
dst->value = value_dup (src->value);
return dst;
}
@@ -83,7 +83,7 @@ gnm_scenario_item_set_range (GnmScenarioItem *sci, const GnmSheetRange *sr)
{
if (sr) {
GnmValue *v = value_new_cellrange_r
- (sr->sheet != sci->dep.sheet ? sr->sheet : NULL,
+ (sr->sheet != sci->dep.base.sheet ? sr->sheet : NULL,
&sr->range);
GnmExprTop const *texpr = gnm_expr_top_new_constant (v);
dependent_managed_set_expr (&sci->dep, texpr);
@@ -105,7 +105,7 @@ gnm_scenario_item_valid (const GnmScenarioItem *sci, GnmSheetRange *sr)
GnmExprTop const *texpr;
GnmValue const *vr;
- if (!sci || !((texpr = sci->dep.texpr)))
+ if (!sci || !((texpr = sci->dep.base.texpr)))
return FALSE;
vr = gnm_expr_top_get_constant (texpr);
@@ -291,7 +291,7 @@ gnm_scenario_get_range_str (const GnmScenario *sc)
continue;
if (str->len)
g_string_append_c (str, ',');
- vrange = gnm_expr_top_get_constant (sci->dep.texpr);
+ vrange = gnm_expr_top_get_constant (sci->dep.base.texpr);
g_string_append (str, value_peek_string (vrange));
}
diff --git a/src/tools/scenarios.h b/src/tools/scenarios.h
index fb03b2480..c5fd578f8 100644
--- a/src/tools/scenarios.h
+++ b/src/tools/scenarios.h
@@ -7,7 +7,7 @@
/* ------------------------------------------------------------------------- */
typedef struct {
- GnmDependent dep;
+ GnmDepManaged dep;
GnmValue *value;
} GnmScenarioItem;
diff --git a/src/validation.c b/src/validation.c
index 5e4544344..9933a7230 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -326,7 +326,7 @@ gnm_validation_dup (GnmValidation *v)
NULL, NULL,
v->allow_blank, v->use_dropdown);
for (i = 0; i < 2; i++)
- gnm_validation_set_expr (dst, v->deps[i].texpr, i);
+ gnm_validation_set_expr (dst, v->deps[i].base.texpr, i);
return dst;
}
@@ -358,7 +358,7 @@ gnm_validation_equal (GnmValidation const *a, GnmValidation const *b,
return FALSE;
for (i = 0; i < 2; i++)
- if (!gnm_expr_top_equal (a->deps[i].texpr, b->deps[i].texpr))
+ if (!gnm_expr_top_equal (a->deps[i].base.texpr, b->deps[i].base.texpr))
return FALSE;
return TRUE;
@@ -420,7 +420,7 @@ Sheet *
gnm_validation_get_sheet (GnmValidation const *v)
{
g_return_val_if_fail (v != NULL, NULL);
- return v->deps[0].sheet;
+ return v->deps[0].base.sheet;
}
void
@@ -471,7 +471,7 @@ gnm_validation_is_ok (GnmValidation const *v)
}
for (i = 0 ; i < 2 ; i++)
- if (v->deps[i].texpr == NULL) {
+ if (v->deps[i].base.texpr == NULL) {
if (i < nops)
return g_error_new (1, 0, N_("Missing formula for validation"));
} else {
@@ -609,7 +609,7 @@ gnm_validation_eval (WorkbookControl *wbc, GnmStyle const *mstyle,
break;
case GNM_VALIDATION_TYPE_IN_LIST: {
- GnmExprTop const *texpr = v->deps[0].texpr;
+ GnmExprTop const *texpr = v->deps[0].base.texpr;
if (texpr) {
GnmValue *list = gnm_expr_top_eval
(texpr, &ep,
@@ -642,7 +642,7 @@ gnm_validation_eval (WorkbookControl *wbc, GnmStyle const *mstyle,
case GNM_VALIDATION_TYPE_CUSTOM: {
gboolean valid;
- GnmExprTop const *texpr = v->deps[0].texpr;
+ GnmExprTop const *texpr = v->deps[0].base.texpr;
if (!texpr)
return GNM_VALIDATION_STATUS_VALID;
@@ -675,7 +675,7 @@ gnm_validation_eval (WorkbookControl *wbc, GnmStyle const *mstyle,
nok = 0;
for (i = 0; i < opinfo[v->op].nops; i++) {
- GnmExprTop const *texpr_i = v->deps[i].texpr;
+ GnmExprTop const *texpr_i = v->deps[i].base.texpr;
GnmExprTop const *texpr;
GnmValue *cres;
diff --git a/src/validation.h b/src/validation.h
index 7e86b52fe..aab4b2db3 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -45,7 +45,7 @@ struct _GnmValidation {
GOString *title;
GOString *msg;
- GnmDependent deps[2];
+ GnmDepManaged deps[2];
ValidationStyle style;
ValidationType type;
ValidationOp op;
diff --git a/src/wbc-gtk.c b/src/wbc-gtk.c
index ec0cbe53d..0dcaa9d4e 100644
--- a/src/wbc-gtk.c
+++ b/src/wbc-gtk.c
@@ -3904,7 +3904,7 @@ cb_auto_expr_cell_changed (GtkWidget *item, WBCGtk *wbcg)
NULL);
/* Now we have the expression set. */
- texpr = wbv->auto_expr.dep.texpr;
+ texpr = wbv->auto_expr.dep.base.texpr;
v = gnm_expr_top_get_constant (texpr);
if (v)
g_object_set (wbv,
diff --git a/src/widgets/gnm-validation-combo-view.c b/src/widgets/gnm-validation-combo-view.c
index 485acc0d9..0e60aae05 100644
--- a/src/widgets/gnm-validation-combo-view.c
+++ b/src/widgets/gnm-validation-combo-view.c
@@ -104,11 +104,11 @@ vcombo_create_list (SheetObject *so,
g_return_val_if_fail (val != NULL, NULL);
g_return_val_if_fail (val->type == GNM_VALIDATION_TYPE_IN_LIST, NULL);
- g_return_val_if_fail (val->deps[0].texpr != NULL, NULL);
+ g_return_val_if_fail (val->deps[0].base.texpr != NULL, NULL);
g_return_val_if_fail (sv != NULL, NULL);
eval_pos_init_editpos (&ep, sv);
- v = gnm_expr_top_eval_fake_array (val->deps[0].texpr, &ep,
+ v = gnm_expr_top_eval_fake_array (val->deps[0].base.texpr, &ep,
GNM_EXPR_EVAL_PERMIT_NON_SCALAR |
GNM_EXPR_EVAL_PERMIT_EMPTY);
if (NULL == v)
diff --git a/src/workbook-view.c b/src/workbook-view.c
index 69d0fa0f1..91a759529 100644
--- a/src/workbook-view.c
+++ b/src/workbook-view.c
@@ -539,9 +539,9 @@ wb_view_auto_expr_recalc (WorkbookView *wbv)
sv == NULL)
return;
- if (wbv->auto_expr.dep.sheet != NULL &&
- wbv->auto_expr.dep.texpr != NULL) {
- texpr = wbv->auto_expr.dep.texpr;
+ if (wbv->auto_expr.dep.base.sheet != NULL &&
+ wbv->auto_expr.dep.base.texpr != NULL) {
+ texpr = wbv->auto_expr.dep.base.texpr;
gnm_expr_top_ref (texpr);
} else if (wbv->auto_expr.func != NULL) {
sv_selection_apply (sv, &accumulate_regions, FALSE, &selection);
@@ -672,12 +672,12 @@ wb_view_auto_expr_eval_pos (WorkbookView *wbv, GnmEvalPos const *ep)
Sheet *sheet = ep ? ep->sheet : NULL;
if (wbv->auto_expr.sheet_detached_sig) {
- g_signal_handler_disconnect (wbv->auto_expr.dep.sheet,
+ g_signal_handler_disconnect (wbv->auto_expr.dep.base.sheet,
wbv->auto_expr.sheet_detached_sig);
wbv->auto_expr.sheet_detached_sig = 0;
}
- dependent_set_expr (&wbv->auto_expr.dep, NULL);
+ dependent_managed_set_expr (&wbv->auto_expr.dep, NULL);
dependent_managed_set_sheet (&wbv->auto_expr.dep, sheet);
if (sheet) {
diff --git a/src/workbook-view.h b/src/workbook-view.h
index 5cb980d0f..a18ad8989 100644
--- a/src/workbook-view.h
+++ b/src/workbook-view.h
@@ -34,7 +34,7 @@ struct _WorkbookView {
char *descr;
GnmValue *value;
gboolean use_max_precision;
- GnmDependent dep;
+ GnmDepManaged dep;
gulong sheet_detached_sig;
} auto_expr;
diff --git a/src/xml-sax-write.c b/src/xml-sax-write.c
index 31d845b8d..f512c36f5 100644
--- a/src/xml-sax-write.c
+++ b/src/xml-sax-write.c
@@ -570,8 +570,7 @@ xml_write_style (GnmOutputXML *state, GnmStyle const *style)
if (gnm_style_is_element_set (style, MSTYLE_VALIDATION) &&
NULL != (v = gnm_style_get_validation (style))) {
- GnmParsePos pp;
- char *tmp;
+ unsigned ui;
gsf_xml_out_start_element (state->output, GNM "Validation");
gsf_xml_out_add_enum (state->output, "Style",
@@ -600,17 +599,17 @@ xml_write_style (GnmOutputXML *state, GnmStyle const *style)
if (v->msg != NULL && v->msg->str[0] != '\0')
gsf_xml_out_add_cstr (state->output, "Message", v->msg->str);
- parse_pos_init_sheet (&pp, (Sheet *)state->sheet);
-
- if (v->deps[0].texpr != NULL &&
- (tmp = gnm_expr_top_as_string (v->deps[0].texpr, &pp, state->convs)) != NULL) {
- gsf_xml_out_simple_element (state->output, GNM "Expression0", tmp);
- g_free (tmp);
- }
- if (v->deps[1].texpr != NULL &&
- (tmp = gnm_expr_top_as_string (v->deps[1].texpr, &pp, state->convs)) != NULL) {
- gsf_xml_out_simple_element (state->output, GNM "Expression1", tmp);
- g_free (tmp);
+ for (ui = 0; ui < G_N_ELEMENTS (v->deps); ui++) {
+ GnmExprTop const *texpr = dependent_managed_get_expr (&v->deps[ui]);
+ if (texpr) {
+ const char *elem = ui == 0 ? GNM "Expression0" : GNM "Expression1";
+ char *tmp;
+ GnmParsePos pp;
+ parse_pos_init_sheet (&pp, (Sheet *)state->sheet);
+ tmp = gnm_expr_top_as_string (texpr, &pp, state->convs);
+ gsf_xml_out_simple_element (state->output, elem, tmp);
+ g_free (tmp);
+ }
}
gsf_xml_out_end_element (state->output); /* </Validation> */
}
@@ -1178,7 +1177,7 @@ xml_write_scenario (GnmOutputXML *state, GnmScenario const *sc)
out.pp = &pp;
out.convs = state->convs;
- gnm_expr_top_as_gstring (sci->dep.texpr, &out);
+ gnm_expr_top_as_gstring (dependent_managed_get_expr (&sci->dep), &out);
gsf_xml_out_add_cstr (state->output, "Range", str->str);
if (val) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]