[gnumeric] Fix validation for array and range entry. [#622511]



commit 8b53afdf3c522a026c409683c15a993f43648f26
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Wed Jun 23 21:37:35 2010 -0600

    Fix validation for array and range entry. [#622511]
    
    2010-06-23  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* src/validation.h (validation_eval_range): new
    	* src/validation.c (validation_eval_range): new
    	(validation_eval_range_cb): new
    	* src/wbc-gtk-edit.c (wbcg_edit_finish): use validation_eval_range

 ChangeLog          |    7 +++++
 NEWS               |    1 +
 src/validation.c   |   63 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/validation.h   |    3 ++
 src/wbc-gtk-edit.c |   14 ++++++++---
 5 files changed, 84 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index af36690..d52482f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2010-06-23  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* src/validation.h (validation_eval_range): new
+	* src/validation.c (validation_eval_range): new
+	(validation_eval_range_cb): new
+	* src/wbc-gtk-edit.c (wbcg_edit_finish): use validation_eval_range
+
+2010-06-23  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* src/wbc-gtk-edit.c (wbcg_edit_finish): only call a cmd_...
 	  when we have validated.
 	
diff --git a/NEWS b/NEWS
index b30c4a3..64158ac 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ Gnumeric 1.10.7
 Andreas:
 	* Improve function syntax and formula guru tooltips.
 	* Avoid superfluous redo items under validation failure. [#622509]
+	* Fix validation for array and range entry. [#622511]
 
 Jean:
 	* Fixed autofilter (and other) combo positions. [#621817]
diff --git a/src/validation.c b/src/validation.c
index 64367af..a71ee0e 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -33,11 +33,13 @@
 #include "sheet.h"
 #include "cell.h"
 #include "value.h"
+#include "workbook.h"
 #include "workbook-control.h"
 #include "parse-util.h"
 
 #include "sheet-view.h"
 #include "sheet-object.h"
+#include "sheet-style.h"
 #include "gnm-validation-combo-view.h"
 #include "gnm-cell-combo-view.h"
 #include <gsf/gsf-impl-utils.h>
@@ -506,3 +508,64 @@ validation_eval (WorkbookControl *wbc, GnmStyle const *mstyle,
 }
 
 #undef BARF
+
+typedef struct {
+	WorkbookControl *wbc; 
+	Sheet *sheet;
+	GnmCellPos const *pos;
+	gboolean *showed_dialog;
+	ValidationStatus status;
+} validation_eval_t;
+
+static GnmValue *
+validation_eval_range_cb (GnmCellIter const *iter, validation_eval_t *closure)
+{
+	ValidationStatus status;
+	gboolean showed_dialog;
+	GnmStyle const *mstyle = sheet_style_get 
+		(closure->sheet, iter->pp.eval.col, iter->pp.eval.row);
+
+	if (mstyle != NULL) {
+		status = validation_eval (closure->wbc, mstyle,
+					  closure->sheet, &iter->pp.eval, 
+					  &showed_dialog);
+		if (closure->showed_dialog)
+			*closure->showed_dialog = *closure->showed_dialog || showed_dialog;
+		
+		if (status != VALIDATION_STATUS_VALID) {
+			closure->status = status;
+			return VALUE_TERMINATE;
+		}
+	}
+
+	return NULL;
+}
+
+ValidationStatus 
+validation_eval_range (WorkbookControl *wbc,
+		       Sheet *sheet, GnmCellPos const *pos, GnmRange const *r,
+		       gboolean *showed_dialog)
+{
+	GnmValue *result;
+	validation_eval_t closure;
+	GnmEvalPos ep;
+	GnmValue *cell_range = value_new_cellrange_r (sheet, r);
+
+	closure.wbc = wbc;
+	closure.sheet = sheet;
+	closure.pos = pos;
+	closure.showed_dialog = showed_dialog;
+	closure.status = VALIDATION_STATUS_VALID;
+
+	eval_pos_init_pos (&ep, sheet, pos);
+
+	result = workbook_foreach_cell_in_range (&ep, cell_range, CELL_ITER_ALL,
+						 (CellIterFunc) validation_eval_range_cb,
+						 &closure);
+
+	value_release (cell_range);
+
+	if (result == NULL)
+		return VALIDATION_STATUS_VALID;
+	return closure.status;
+}
diff --git a/src/validation.h b/src/validation.h
index 4237ec2..6cdf410 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -69,6 +69,9 @@ GError	   *validation_is_ok    (GnmValidation const *v);
 ValidationStatus validation_eval (WorkbookControl *wbc, GnmStyle const *mstyle,
 				  Sheet *sheet, GnmCellPos const *pos,
 				  gboolean *showed_dialog);
+ValidationStatus validation_eval_range (WorkbookControl *wbc,
+					Sheet *sheet, GnmCellPos const *pos, GnmRange const *r,
+					gboolean *showed_dialog);
 
 G_END_DECLS
 
diff --git a/src/wbc-gtk-edit.c b/src/wbc-gtk-edit.c
index a8b4431..7d2a0ad 100644
--- a/src/wbc-gtk-edit.c
+++ b/src/wbc-gtk-edit.c
@@ -275,6 +275,7 @@ wbcg_edit_finish (WBCGtk *wbcg, WBCEditResult result,
 
 		/* We need to save the information that we will temporarily overwrite */
 		/* We then assign the information. No need to worry about formatting */
+		/* Finally we can check the validation! */
 
 		switch (result) {
 		case (WBC_EDIT_ACCEPT_RANGE): {
@@ -288,8 +289,11 @@ wbcg_edit_finish (WBCGtk *wbcg, WBCEditResult result,
 				GnmRange *r = l->data;
 				/* We do this separately since there may be overlap between ranges */
 				sheet_range_set_text (&pp, r, txt);
+				valid =	validation_eval_range (wbc, sheet, &sv->edit_pos, r,
+							       showed_dialog);
+				if (valid != VALIDATION_STATUS_VALID)
+					break;
 			}
-			
 			break;
 		}
 		case (WBC_EDIT_ACCEPT_ARRAY): {
@@ -302,7 +306,9 @@ wbcg_edit_finish (WBCGtk *wbcg, WBCEditResult result,
 							    r->end.col, r->end.row,
 							    texpr);
 				sheet_region_queue_recalc (sheet, r);
-			}
+			}			
+			valid =	validation_eval_range (wbc, sheet, &sv->edit_pos, r,
+						       showed_dialog);
 			break;
 		}
 		case (WBC_EDIT_ACCEPT): {
@@ -316,6 +322,7 @@ wbcg_edit_finish (WBCGtk *wbcg, WBCEditResult result,
 						 sv->edit_pos.col,
 						 sv->edit_pos.row);
 			sheet_cell_set_text (cell, txt, NULL);
+			valid = validation_eval (wbc, mstyle, sheet, &sv->edit_pos, showed_dialog);
 			break;
 		}
 		case (WBC_EDIT_REJECT):
@@ -327,9 +334,8 @@ wbcg_edit_finish (WBCGtk *wbcg, WBCEditResult result,
 		range_fragment_free (selection);
 		g_free (free_txt);
 
-		/* Now we can check the validation! */
 
-		valid = validation_eval (wbc, mstyle, sheet, &sv->edit_pos, showed_dialog);
+	
 
 
 		/* We need to rebuild the original info first. */



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