gnumeric r16807 - in trunk: . src src/tools



Author: guelzow
Date: Fri Sep 19 04:18:19 2008
New Revision: 16807
URL: http://svn.gnome.org/viewvc/gnumeric?rev=16807&view=rev

Log:
2008-09-18  Andreas J. Guelzow <aguelzow pyrshep ca>

	* src/commands.c (CmdAnalysis_Tool): add field
	(cmd_analysis_tool_undo): delete associated sheet objects
	(cmd_analysis_tool_draw_old_so): new
	(cmd_analysis_tool_redo): use the above
	(cmd_analysis_tool_finalize): handle new fields

2008-09-18  Andreas J. Guelzow <aguelzow pyrshep ca>

	* analysis-histogram.c (analysis_tool_histogram_engine_run): we need to 
	keep the values around for potential redos.
	(analysis_tool_histogram_engine): clean up when asked to do so.
	* analysis-tools.h (analysis_tool_generic_clean): needs to be non-static
	* analysis-tools.c (analysis_tool_generic_clean): make non-static
	  and remove unneeded argument. Change all callers.
	* dao.h (data_analysis_output_t): add fields
	(dao_free): new
	(dao_surrender_so): new
	(dao_set_omit_so): new
	* dao.c (dao_free): new
	(dao_surrender_so): new
	(dao_set_omit_so): new
	(dao_init): handle new fields
	(dao_set_sheet_object): don't write sheet objects when omit_so is true.



Modified:
   trunk/BUGS
   trunk/ChangeLog
   trunk/src/commands.c
   trunk/src/tools/ChangeLog
   trunk/src/tools/analysis-histogram.c
   trunk/src/tools/analysis-tools.c
   trunk/src/tools/analysis-tools.h
   trunk/src/tools/dao.c
   trunk/src/tools/dao.h

Modified: trunk/BUGS
==============================================================================
--- trunk/BUGS	(original)
+++ trunk/BUGS	Fri Sep 19 04:18:19 2008
@@ -758,7 +758,7 @@
 
 38) Printing
     38.1) cell text wraps differently when printing than
-	  displaying due to scaling differences in font size.
+	  displaying due to scaling differences in font size.   (DONE)
     38.2) explicit page breaks
     38.3) PI:comment_placement
     38.4) PI:display_errors

Modified: trunk/src/commands.c
==============================================================================
--- trunk/src/commands.c	(original)
+++ trunk/src/commands.c	Fri Sep 19 04:18:19 2008
@@ -4942,8 +4942,9 @@
 
 	ColRowStateList         *col_info;
 	ColRowStateList         *row_info;
-	GnmRange                   old_range;
-	GnmCellRegion              *old_contents;
+	GnmRange                old_range;
+	GnmCellRegion           *old_contents;
+	GSList                  *newSheetObjects;
 } CmdAnalysis_Tool;
 
 MAKE_GNM_COMMAND (CmdAnalysis_Tool, cmd_analysis_tool, NULL)
@@ -4987,6 +4988,9 @@
 			dao_set_colrow_state_list (me->dao, FALSE, me->row_info);
 			me->row_info = colrow_state_list_destroy (me->row_info);
 		}
+		if (me->newSheetObjects == NULL)
+			me->newSheetObjects = dao_surrender_so (me->dao);
+		g_slist_foreach (me->newSheetObjects, (GFunc)sheet_object_clear_sheet, NULL);
 		workbook_recalc (me->dao->sheet->workbook);
 		sheet_update (me->dao->sheet);
 	}
@@ -4994,6 +4998,13 @@
 	return FALSE;
 }
 
+static void
+cmd_analysis_tool_draw_old_so (SheetObject *so, data_analysis_output_t *dao)
+{
+	g_object_ref (G_OBJECT (so));
+	dao_set_sheet_object (dao, 0, 1, so);
+}
+
 static gboolean
 cmd_analysis_tool_redo (GnmCommand *cmd, WorkbookControl *wbc)
 {
@@ -5033,6 +5044,9 @@
 		break;
 	}
 
+	if (me->newSheetObjects != NULL)
+		dao_set_omit_so (me->dao, TRUE);
+
 	if (me->engine (me->dao, me->specs, TOOL_ENGINE_FORMAT_OUTPUT_RANGE, NULL))
 		return TRUE;
 
@@ -5043,6 +5057,18 @@
 		} else
 			return TRUE;
 	}
+	if (me->newSheetObjects != NULL)
+	{
+		GSList *l = g_slist_reverse 
+			(g_slist_copy (me->newSheetObjects));
+
+		dao_set_omit_so (me->dao, FALSE);
+		g_slist_foreach (l,
+				 (GFunc) cmd_analysis_tool_draw_old_so, 
+				 me->dao);
+		g_slist_free (l);
+	}
+
 	if (continuity) {
 		g_warning ("There shouldn't be any data left in here!");
 	}
@@ -5074,11 +5100,13 @@
 
 	if (me->specs_owned) {
 		g_free (me->specs);
-		g_free (me->dao);
+		dao_free (me->dao);
 	}
 	if (me->old_contents)
 		cellregion_unref (me->old_contents);
 
+	go_slist_free_custom (me->newSheetObjects, g_object_unref);
+
 	gnm_command_finalize (cmd);
 }
 

Modified: trunk/src/tools/analysis-histogram.c
==============================================================================
--- trunk/src/tools/analysis-histogram.c	(original)
+++ trunk/src/tools/analysis-histogram.c	Fri Sep 19 04:18:19 2008
@@ -225,7 +225,7 @@
 	}
 
 	for (l = info->base.input, col = to_col + 1; l; col++, l = l->next) {
-		GnmValue *val = l->data;
+		GnmValue *val = value_dup ((GnmValue *)l->data);
 		GnmValue *val_c = NULL;
 		GnmExpr const *expr_count;
 		GnmExpr const *expr_data;
@@ -428,7 +428,7 @@
 		return FALSE;
 	}
 	case TOOL_ENGINE_CLEAN_UP:
-		return FALSE;
+		return analysis_tool_generic_clean (specs);
 	case TOOL_ENGINE_LAST_VALIDITY_CHECK:
 		return FALSE;
 	case TOOL_ENGINE_PREPARE_OUTPUT_RANGE:

Modified: trunk/src/tools/analysis-tools.c
==============================================================================
--- trunk/src/tools/analysis-tools.c	(original)
+++ trunk/src/tools/analysis-tools.c	Fri Sep 19 04:18:19 2008
@@ -684,9 +684,8 @@
 		(CellIterFunc)&cb_write_data, data);
 }
 
-static gboolean
-analysis_tool_generic_clean (G_GNUC_UNUSED data_analysis_output_t *dao,
-			     gpointer specs)
+gboolean
+analysis_tool_generic_clean (gpointer specs)
 {
 	analysis_tools_data_generic_t *info = specs;
 
@@ -832,7 +831,7 @@
 			    1 + g_slist_length (info->input));
 		return FALSE;
 	case TOOL_ENGINE_CLEAN_UP:
-		return analysis_tool_generic_clean (dao, specs);
+		return analysis_tool_generic_clean (specs);
 	case TOOL_ENGINE_LAST_VALIDITY_CHECK:
 		return FALSE;
 	case TOOL_ENGINE_PREPARE_OUTPUT_RANGE:
@@ -886,7 +885,7 @@
 			    1 + g_slist_length (info->input));
 		return FALSE;
 	case TOOL_ENGINE_CLEAN_UP:
-		return analysis_tool_generic_clean (dao, specs);
+		return analysis_tool_generic_clean (specs);
 	case TOOL_ENGINE_LAST_VALIDITY_CHECK:
 		return FALSE;
 	case TOOL_ENGINE_PREPARE_OUTPUT_RANGE:
@@ -1273,7 +1272,7 @@
 			    (info->kth_smallest ? 4 : 0 ) - 1);
 		return FALSE;
 	case TOOL_ENGINE_CLEAN_UP:
-		return analysis_tool_generic_clean (dao, specs);
+		return analysis_tool_generic_clean (specs);
 	case TOOL_ENGINE_LAST_VALIDITY_CHECK:
 		return FALSE;
 	case TOOL_ENGINE_PREPARE_OUTPUT_RANGE:
@@ -1395,7 +1394,7 @@
 			    1 + info->size);
 		return FALSE;
 	case TOOL_ENGINE_CLEAN_UP:
-		return analysis_tool_generic_clean (dao, specs);
+		return analysis_tool_generic_clean (specs);
 	case TOOL_ENGINE_LAST_VALIDITY_CHECK:
 		return FALSE;
 	case TOOL_ENGINE_PREPARE_OUTPUT_RANGE:
@@ -3436,7 +3435,7 @@
 			    1 + analysis_tool_calc_length (specs));
 		return FALSE;
 	case TOOL_ENGINE_CLEAN_UP:
-		return analysis_tool_generic_clean (dao, specs);
+		return analysis_tool_generic_clean (specs);
 	case TOOL_ENGINE_LAST_VALIDITY_CHECK:
 		return FALSE;
 	case TOOL_ENGINE_PREPARE_OUTPUT_RANGE:
@@ -3569,7 +3568,7 @@
 			    1 + analysis_tool_calc_length (specs));
 		return FALSE;
 	case TOOL_ENGINE_CLEAN_UP:
-		return analysis_tool_generic_clean (dao, specs);
+		return analysis_tool_generic_clean (specs);
 	case TOOL_ENGINE_LAST_VALIDITY_CHECK:
 		return FALSE;
 	case TOOL_ENGINE_PREPARE_OUTPUT_RANGE:
@@ -3701,7 +3700,7 @@
 			    1 + analysis_tool_calc_length (specs));
 		return FALSE;
 	case TOOL_ENGINE_CLEAN_UP:
-		return analysis_tool_generic_clean (dao, specs);
+		return analysis_tool_generic_clean (specs);
 	case TOOL_ENGINE_LAST_VALIDITY_CHECK:
 		return FALSE;
 	case TOOL_ENGINE_PREPARE_OUTPUT_RANGE:
@@ -4035,7 +4034,7 @@
 		dao_adjust (dao, 7, 11 + g_slist_length (info->base.input));
 		return FALSE;
 	case TOOL_ENGINE_CLEAN_UP:
-		return analysis_tool_generic_clean (dao, specs);
+		return analysis_tool_generic_clean (specs);
 	case TOOL_ENGINE_LAST_VALIDITY_CHECK:
 		return FALSE;
 	case TOOL_ENGINE_PREPARE_OUTPUT_RANGE:
@@ -4869,7 +4868,7 @@
 			    2 + analysis_tool_fourier_calc_length (specs));
 		return FALSE;
 	case TOOL_ENGINE_CLEAN_UP:
-		return analysis_tool_generic_clean (dao, specs);
+		return analysis_tool_generic_clean (specs);
 	case TOOL_ENGINE_LAST_VALIDITY_CHECK:
 		return FALSE;
 	case TOOL_ENGINE_PREPARE_OUTPUT_RANGE:

Modified: trunk/src/tools/analysis-tools.h
==============================================================================
--- trunk/src/tools/analysis-tools.h	(original)
+++ trunk/src/tools/analysis-tools.h	Fri Sep 19 04:18:19 2008
@@ -226,14 +226,11 @@
 gboolean analysis_tool_anova_two_factor_engine (data_analysis_output_t *dao, gpointer specs,
 					   analysis_tool_engine_t selector, gpointer result);
 
-/* THINGS NEEDED FOR THE HISTOGRAM SPLIT-OUT */
+/********************************************************************/
+/* Functions also needed elsewhere.                                 */
+
+gboolean analysis_tool_generic_clean (gpointer specs);
 
-/*
- *  prepare_input_range:
- *  @input_range:
- *  @group_by:
- *
- */
 void prepare_input_range (GSList **input_range, group_by_t group_by);
 
 const GnmExpr *make_cellref (int dx, int dy);

Modified: trunk/src/tools/dao.c
==============================================================================
--- trunk/src/tools/dao.c	(original)
+++ trunk/src/tools/dao.c	Fri Sep 19 04:18:19 2008
@@ -64,8 +64,11 @@
 dao_init (data_analysis_output_t *dao,
 	  data_analysis_output_type_t type)
 {
-	if (dao == NULL)
+	if (dao == NULL) {
 		dao = g_new (data_analysis_output_t, 1);
+		dao->use_gfree = TRUE;
+	} else
+		dao->use_gfree = FALSE;
 
 	dao->type              = type;
 	dao->start_col         = 0;
@@ -80,10 +83,21 @@
 	dao->retain_format     = FALSE;
 	dao->retain_comments   = FALSE;
 	dao->put_formulas      = FALSE;
+	dao->sos               = NULL;
+        dao->omit_so           = FALSE;
 
 	return dao;
 }
 
+void dao_free (data_analysis_output_t *dao)
+{
+	go_slist_free_custom (dao->sos, g_object_unref);
+	dao->sos = NULL;
+
+	if (dao->use_gfree)
+		g_free (dao);
+}
+
 data_analysis_output_t *
 dao_load_from_value (data_analysis_output_t *dao,
 		     GnmValue *output_range)
@@ -1156,6 +1170,11 @@
 	GnmRange	  anchor_r;
 
 	g_return_if_fail (so != NULL);
+
+	if (dao->omit_so) {
+		g_object_unref (so);
+		return;
+	}
 		
 	range_init (&anchor_r, dao->start_col + col, dao->start_row + row,
 		    dao->start_col + ((dao->cols < 5) ? dao->cols : 5),
@@ -1164,7 +1183,8 @@
 	sheet_object_anchor_init (&anchor, &anchor_r, 0, GOD_ANCHOR_DIR_UNKNOWN);
 	sheet_object_set_anchor (so, &anchor);
 	sheet_object_set_sheet (so, dao->sheet);
-	g_object_unref (so);
+
+	dao->sos = g_slist_prepend (dao->sos, so);
 }
 
 GOData	*
@@ -1172,3 +1192,18 @@
 {
 	return gnm_go_data_vector_new_expr (dao->sheet, gnm_expr_top_new (dao_get_rangeref (dao, ax, ay, bx, by)));
 }
+
+GSList *
+dao_surrender_so (data_analysis_output_t *dao)
+{
+	GSList *l = dao->sos;
+	dao->sos = NULL;
+
+	return l; 
+}
+
+void    
+dao_set_omit_so (data_analysis_output_t *dao, gboolean omit)
+{
+	dao->omit_so = omit;
+}

Modified: trunk/src/tools/dao.h
==============================================================================
--- trunk/src/tools/dao.h	(original)
+++ trunk/src/tools/dao.h	Fri Sep 19 04:18:19 2008
@@ -49,12 +49,16 @@
 	gboolean                    retain_comments;
 	gboolean                    put_formulas;
 	WorkbookControl             *wbc;
+	GSList                      *sos;
+	gboolean                    omit_so;
+	gboolean                    use_gfree; 
 } data_analysis_output_t;
 
 data_analysis_output_t *dao_init (data_analysis_output_t *dao, 
 				  data_analysis_output_type_t type);
 data_analysis_output_t *dao_load_from_value (data_analysis_output_t *dao,
 					     GnmValue *output_range);
+void dao_free (data_analysis_output_t *dao);
 
 void dao_autofit_columns      (data_analysis_output_t *dao);
 void dao_autofit_these_columns (data_analysis_output_t *dao, int from_col,
@@ -133,4 +137,11 @@
 
 GOData *dao_go_data_vector (data_analysis_output_t *dao, int ax, int ay,  int bx, int by);
 
+
+/* The following 2 functions are intended solely for undo support */
+/* of sheet objects normally created by the dao. */ 
+
+GSList *dao_surrender_so (data_analysis_output_t *dao);
+void    dao_set_omit_so (data_analysis_output_t *dao, gboolean omit);
+
 #endif



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