[gnumeric] Validations: fix problems with sheet duplications.



commit ad72c7ab86aa4be5b4bf69aebdf1a437088f152a
Author: Morten Welinder <terra gnome org>
Date:   Thu May 17 13:52:35 2012 -0400

    Validations: fix problems with sheet duplications.
    
    Things didn't work right when a mstyle from one sheet was used on
    another.

 ChangeLog        |   15 ++++++++++++++-
 src/dependent.c  |    3 +--
 src/mstyle.c     |   25 +++++++++++++++++++++++++
 src/validation.c |   39 +++++++++++++++++++++++++++++++++++++++
 src/validation.h |    6 ++++++
 5 files changed, 85 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 97fee09..70ea2e6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,17 @@
-2012-05-18  Andreas J. Guelzow <aguelzow pyrshep ca>
+2012-05-17  Morten Welinder  <terra gnome org>
+
+	* src/validation.c (gnm_validation_dup, gnm_validation_get_sheet)
+	(gnm_validation_set_sheet): New functions.
+
+	* src/mstyle.c (gnm_style_link_sheet): Call
+	gnm_style_linked_sheet_changed.  Fixes duplication of sheets with
+	validation and similar cases.
+	(gnm_style_linked_sheet_changed): New function.
+
+	* src/dependent.c (dependent_managed_set_sheet): We don't own a
+	sheet ref, so don't mess with it.
+
+2012-05-17  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* configure.in: push gofffice requirement
 
diff --git a/src/dependent.c b/src/dependent.c
index c357227..dfdcf3c 100644
--- a/src/dependent.c
+++ b/src/dependent.c
@@ -1277,8 +1277,7 @@ dependent_managed_set_sheet (GnmDependent *dep, Sheet *sheet)
 	if (texpr) gnm_expr_top_ref (texpr);
 	dependent_set_expr (dep, NULL);
 	/* We're now unlinked from everything. */
-	if (dep->sheet) g_object_unref (dep->sheet);
-	dep->sheet = sheet ? g_object_ref (sheet) : NULL;
+	dep->sheet = sheet;
 	dependent_managed_set_expr (dep, texpr);
 	if (texpr) gnm_expr_top_unref (texpr);
 }
diff --git a/src/mstyle.c b/src/mstyle.c
index 844d6e0..69eec06 100644
--- a/src/mstyle.c
+++ b/src/mstyle.c
@@ -814,6 +814,29 @@ link_border_colors (GnmStyle *style, GnmColor *auto_color, gboolean make_copy)
 	return style;
 }
 
+static void
+gnm_style_linked_sheet_changed (GnmStyle *style)
+{
+	Sheet *sheet = style->linked_sheet;
+
+	if (elem_is_set (style, MSTYLE_VALIDATION) &&
+	    style->validation &&
+	    gnm_validation_get_sheet (style->validation) != sheet) {
+		GnmValidation *new_v = gnm_validation_dup (style->validation);
+		gnm_validation_set_sheet (new_v, sheet);
+		gnm_style_set_validation (style, new_v);
+	}
+
+	if (elem_is_set (style, MSTYLE_CONDITIONS) &&
+	    style->conditions
+#if 0
+	    && gnm_style_conditions_get_sheet (style->conditions) != sheet
+#endif
+		) {
+		/* Something goes here.  */
+	}
+}
+
 /**
  * gnm_style_link_sheet :
  * @style :
@@ -855,6 +878,8 @@ gnm_style_link_sheet (GnmStyle *style, Sheet *sheet)
 	style->linked_sheet = sheet;
 	style->link_count = 1;
 
+	gnm_style_linked_sheet_changed (style);
+
 	d(("link sheet %p = 1\n", style));
 	return style;
 }
diff --git a/src/validation.c b/src/validation.c
index 8da03ee..740b8d9 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -308,6 +308,25 @@ validation_new (ValidationStyle style,
 	return v;
 }
 
+GnmValidation *
+gnm_validation_dup (GnmValidation *v)
+{
+	GnmValidation *dst;
+	int i;
+
+	g_return_val_if_fail (v != NULL, NULL);
+
+	dst = validation_new (v->style, v->type, v->op,
+			      gnm_validation_get_sheet (v),
+			      v->title ? v->title->str : NULL,
+			      v->msg ? v->msg->str : NULL,
+			      NULL, NULL,
+			      v->allow_blank, v->use_dropdown);
+	for (i = 0; i < 2; i++)
+		validation_set_expr (dst, v->deps[i].texpr, i);
+	return dst;
+}
+
 void
 validation_ref (GnmValidation const *v)
 {
@@ -341,6 +360,26 @@ validation_unref (GnmValidation const *val)
 	}
 }
 
+Sheet *
+gnm_validation_get_sheet (GnmValidation *v)
+{
+	g_return_val_if_fail (v != NULL, NULL);
+	return v->deps[0].sheet;
+}
+
+void
+gnm_validation_set_sheet (GnmValidation *v, Sheet *sheet)
+{
+	int i;
+
+	g_return_if_fail (v != NULL);
+	g_return_if_fail (IS_SHEET (sheet));
+
+	for (i = 0; i < 2; i++)
+		dependent_managed_set_sheet (&v->deps[i], sheet);
+}
+
+
 /**
  * validation_set_expr :
  * @v : #GnmValidation
diff --git a/src/validation.h b/src/validation.h
index e88604d..67bb133 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -72,12 +72,18 @@ GnmValidation *validation_new   (ValidationStyle style,
 				 GnmExprTop const *texpr0,
 				 GnmExprTop const *texpr1,
 				 gboolean allow_blank, gboolean use_dropdown);
+GnmValidation *gnm_validation_dup (GnmValidation *v);
 
 void        validation_ref      (GnmValidation const *v);
 void        validation_unref    (GnmValidation const *v);
+
 void	    validation_set_expr (GnmValidation *v,
 				 GnmExprTop const *texpr, unsigned indx);
 GError	   *validation_is_ok    (GnmValidation const *v);
+
+Sheet      *gnm_validation_get_sheet (GnmValidation *v);
+void        gnm_validation_set_sheet (GnmValidation *v, Sheet *sheet);
+
 ValidationStatus validation_eval (WorkbookControl *wbc, GnmStyle const *mstyle,
 				  Sheet *sheet, GnmCellPos const *pos,
 				  gboolean *showed_dialog);



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