gnumeric r16921 - in trunk: . plugins/excel src src/widgets



Author: mortenw
Date: Fri Oct 24 02:46:59 2008
New Revision: 16921
URL: http://svn.gnome.org/viewvc/gnumeric?rev=16921&view=rev

Log:
2008-10-23  Morten Welinder  <terra gnome org>

	* src/sheet.c (schedule_reapply_filters): New function.
	(sheet_insert_cols, sheet_insert_rows, sheet_delete_cols,
	sheet_delete_rows): Make sure filters get reapplied on undo after
	we put the contents back in.

	* src/sheet-filter.c (gnm_filter_condition_free): Rename from
	gnm_filter_condition_unref.  Actually free the condition.  Make
	static.
	(gnm_filter_condition_dup): Make static.
	(gnm_filter_combo_index): New function.
	(gnm_filter_add_field): Hold onto a reference to the fcombo.
	(gnm_filter_free): Free the fcombo reference.
	(gnm_sheet_filter_insdel_colrow): Handle fcombo references.
	Reapply filter when fields are removed.,
	(gnm_filter_reapply, gnm_filter_update_active): Extract from
	gnm_filter_set_condition.

2008-10-23  Morten Welinder  <terra gnome org>

	* gnm-filter-combo-foo-view.c (fcombo_fill_model): Make sure the
	fake sheet's name does not collide with an existing sheet.  Just
	in case.
	(fcombo_activate, fcombo_fill_model): Use gnm_filter_combo_index.



Modified:
   trunk/ChangeLog
   trunk/NEWS
   trunk/plugins/excel/ms-excel-read.c
   trunk/src/mstyle.c
   trunk/src/sheet-filter-combo.h
   trunk/src/sheet-filter.c
   trunk/src/sheet-filter.h
   trunk/src/sheet.c
   trunk/src/wbc-gtk-actions.c
   trunk/src/widgets/ChangeLog
   trunk/src/widgets/gnm-filter-combo-foo-view.c
   trunk/src/xml-sax-read.c

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Fri Oct 24 02:46:59 2008
@@ -12,9 +12,10 @@
 
 Morten:
 	* Fix XLS import crash.  [#557077]
-	* Fix inter-process paste crash.  [#556561]
 	* Fix problem with auto filter after column insert.   [#557237]
-	* Fix undo problem with auto filters' combos.  [Part of #557591]
+	* Fix undo problem with auto filters.  [#557591]
+	* Remove the effect on an auto filter when its column is removed.
+	* Plug leaks.
 
 --------------------------------------------------------------------------
 Gnumeric 1.9.3

Modified: trunk/plugins/excel/ms-excel-read.c
==============================================================================
--- trunk/plugins/excel/ms-excel-read.c	(original)
+++ trunk/plugins/excel/ms-excel-read.c	Fri Oct 24 02:46:59 2008
@@ -2887,7 +2887,7 @@
 	 * objects */
 	if (esheet->filter != NULL) {
 		gnm_filter_remove (esheet->filter);
-		gnm_filter_free (esheet->filter);
+		gnm_filter_unref (esheet->filter);
 		esheet->filter = NULL;
 	}
 

Modified: trunk/src/mstyle.c
==============================================================================
--- trunk/src/mstyle.c	(original)
+++ trunk/src/mstyle.c	Fri Oct 24 02:46:59 2008
@@ -104,13 +104,13 @@
 	if (style->conditions != NULL)
 		style->cond_styles = gnm_style_conditions_overlay (style->conditions, style);
 
-	if (!style->color.back->is_auto)
+	if (style->color.back && !style->color.back->is_auto)
 		hash ^= GPOINTER_TO_UINT (style->color.back);
 	hash = (hash << 7) ^ (hash >> (sizeof (hash) * 8 - 7));
-	if (!style->color.pattern->is_auto)
+	if (style->color.pattern && !style->color.pattern->is_auto)
 		hash ^= GPOINTER_TO_UINT (style->color.pattern);
 	hash = (hash << 7) ^ (hash >> (sizeof (hash) * 8 - 7));
-	if (!style->color.font->is_auto)
+	if (style->color.font && !style->color.font->is_auto)
 		hash ^= GPOINTER_TO_UINT (style->color.font);
 	hash = (hash << 7) ^ (hash >> (sizeof (hash) * 8 - 7));
 

Modified: trunk/src/sheet-filter-combo.h
==============================================================================
--- trunk/src/sheet-filter-combo.h	(original)
+++ trunk/src/sheet-filter-combo.h	Fri Oct 24 02:46:59 2008
@@ -20,6 +20,8 @@
 GType gnm_filter_combo_get_type (void);
 void  gnm_filter_combo_apply    (GnmFilterCombo *fcombo, Sheet *target_sheet);
 
+int   gnm_filter_combo_index    (GnmFilterCombo *fcombo);
+
 G_END_DECLS
 
 #endif /* _GNM_SHEET_FILTER_COMBO_H_ */

Modified: trunk/src/sheet-filter.c
==============================================================================
--- trunk/src/sheet-filter.c	(original)
+++ trunk/src/sheet-filter.c	Fri Oct 24 02:46:59 2008
@@ -94,7 +94,7 @@
 	return res;
 }
 
-GnmFilterCondition *
+static GnmFilterCondition *
 gnm_filter_condition_dup (GnmFilterCondition const *src)
 {
 	GnmFilterCondition *dst;
@@ -112,14 +112,17 @@
 	return dst;
 }
 
-void
-gnm_filter_condition_unref (GnmFilterCondition *cond)
+static void
+gnm_filter_condition_free (GnmFilterCondition *cond)
 {
-	g_return_if_fail (cond != NULL);
+	if (cond == NULL)
+		return;
+
 	if (cond->value[0] != NULL)
 		value_release (cond->value[0]);
 	if (cond->value[1] != NULL)
 		value_release (cond->value[1]);
+	g_free (cond);
 }
 
 /*****************************************************************************/
@@ -365,6 +368,16 @@
 }
 /*****************************************************************************/
 
+int
+gnm_filter_combo_index (GnmFilterCombo *fcombo)
+{
+	g_return_val_if_fail (IS_GNM_FILTER_COMBO (fcombo), 0);
+
+	return (sheet_object_get_range (SHEET_OBJECT (fcombo))->start.col -
+		fcombo->filter->r.start.col);
+}
+
+
 /**
  * gnm_filter_combo_apply :
  * @fcombo : #GnmFilterCombo
@@ -483,10 +496,10 @@
 {
 	GnmFilterCombo *fcombo = GNM_FILTER_COMBO (object);
 	GObjectClass *parent;
-	if (fcombo->cond != NULL) {
-		gnm_filter_condition_unref (fcombo->cond);
-		fcombo->cond = NULL;
-	}
+
+	gnm_filter_condition_free (fcombo->cond);
+	fcombo->cond = NULL;
+
 	parent = g_type_class_peek (SHEET_OBJECT_TYPE);
 	parent->finalize (object);
 }
@@ -537,7 +550,7 @@
 gnm_filter_add_field (GnmFilter *filter, int i)
 {
 	/* pretend to fill the cell, then clip the X start later */
-	static float const a_offsets [4] = { .0, .0, 1., 1. };
+	static float const a_offsets[4] = { .0, .0, 1., 1. };
 	int n;
 	GnmRange tmp;
 	SheetObjectAnchor anchor;
@@ -554,11 +567,26 @@
 	g_ptr_array_add (filter->fields, NULL);
 	for (n = filter->fields->len; --n > i ; )
 		g_ptr_array_index (filter->fields, n) =
-			g_ptr_array_index (filter->fields, n-1);
+			g_ptr_array_index (filter->fields, n - 1);
 	g_ptr_array_index (filter->fields, n) = fcombo;
-	g_object_unref (G_OBJECT (fcombo));
+	/* We hold a reference to fcombo */
 }
 
+static void
+gnm_filter_attach (GnmFilter *filter, Sheet *sheet)
+{
+	g_return_if_fail (filter != NULL);
+	g_return_if_fail (filter->sheet == NULL);
+	g_return_if_fail (IS_SHEET (sheet));
+
+	gnm_filter_ref (filter);
+
+	filter->sheet = sheet;
+	sheet->filters = g_slist_prepend (sheet->filters, filter);
+	sheet->priv->filters_changed = TRUE;
+}
+
+
 /**
  * gnm_filter_new :
  * @sheet :
@@ -576,18 +604,17 @@
 	g_return_val_if_fail (r != NULL, NULL);
 
 	filter = g_new0 (GnmFilter, 1);
-	filter->sheet = sheet;
 
 	filter->is_active = FALSE;
 	filter->r = *r;
 	filter->fields = g_ptr_array_new ();
 
+	/* This creates the initial ref.  */
+	gnm_filter_attach (filter, sheet);
+
 	for (i = 0 ; i < range_width (r); i++)
 		gnm_filter_add_field (filter, i);
 
-	sheet->filters = g_slist_prepend (sheet->filters, filter);
-	sheet->priv->filters_changed = TRUE;
-
 	return filter;
 }
 
@@ -608,12 +635,14 @@
 	g_return_val_if_fail (IS_SHEET (sheet), NULL);
 
 	dst = g_new0 (GnmFilter, 1);
-	dst->sheet = sheet;
 
 	dst->is_active = src->is_active;
 	dst->r = src->r;
 	dst->fields = g_ptr_array_new ();
 
+	/* This creates the initial ref.  */
+	gnm_filter_attach (dst, sheet);
+
 	for (i = 0 ; i < range_width (&dst->r); i++) {
 		gnm_filter_add_field (dst, i);
 		gnm_filter_set_condition (dst, i,
@@ -622,20 +651,33 @@
 			FALSE);
 	}
 
-	sheet->filters = g_slist_prepend (sheet->filters, dst);
-	sheet->priv->filters_changed = TRUE;
-
 	return dst;
 }
+
+GnmFilter *
+gnm_filter_ref (GnmFilter *filter)
+{
+	g_return_val_if_fail (filter != NULL, NULL);
+	filter->ref_count++;
+	return filter;
+}
+
 void
-gnm_filter_free	(GnmFilter *filter)
+gnm_filter_unref (GnmFilter *filter)
 {
 	unsigned i;
 
 	g_return_if_fail (filter != NULL);
 
-	for (i = 0 ; i < filter->fields->len ; i++)
-		sheet_object_clear_sheet (g_ptr_array_index (filter->fields, i));
+	filter->ref_count--;
+	if (filter->ref_count > 0)
+		return;
+
+	for (i = 0 ; i < filter->fields->len ; i++) {
+		SheetObject *so = g_ptr_array_index (filter->fields, i);
+		sheet_object_clear_sheet (so);
+		g_object_unref (so);
+	}
 	g_ptr_array_free (filter->fields, TRUE);
 
 	filter->fields = NULL;
@@ -661,6 +703,7 @@
 			colrow_set_visibility (sheet, FALSE, TRUE, i, i);
 		}
 	}
+	filter->sheet = NULL;
 }
 
 /**
@@ -681,6 +724,43 @@
 	return fcombo->cond;
 }
 
+void
+gnm_filter_reapply (GnmFilter *filter)
+{
+	unsigned i;
+
+	colrow_set_visibility (filter->sheet, FALSE, TRUE,
+			       filter->r.start.row + 1, filter->r.end.row);
+	for (i = 0 ; i < filter->fields->len ; i++)
+		gnm_filter_combo_apply (g_ptr_array_index (filter->fields, i),
+					filter->sheet);
+}
+
+static void
+gnm_filter_update_active (GnmFilter *filter)
+{
+	unsigned i;
+	gboolean old_active = filter->is_active;
+
+	filter->is_active = FALSE;
+	for (i = 0 ; i < filter->fields->len ; i++) {
+		GnmFilterCombo *fcombo = g_ptr_array_index (filter->fields, i);
+		if (fcombo->cond != NULL) {
+			filter->is_active = TRUE;
+			break;
+		}
+	}
+
+	if (filter->is_active != old_active) {
+		int r;
+		for (r = filter->r.start.row; ++r <= filter->r.end.row ; ) {
+			ColRowInfo *ri = sheet_row_fetch (filter->sheet, r);
+			ri->in_filter = filter->is_active;
+		}
+	}
+}
+
+
 /**
  * gnm_filter_set_condition :
  * @filter :
@@ -699,9 +779,7 @@
 			  gboolean apply)
 {
 	GnmFilterCombo *fcombo;
-	gboolean set_infilter = FALSE;
 	gboolean existing_cond = FALSE;
-	int r;
 
 	g_return_if_fail (filter != NULL);
 	g_return_if_fail (i < filter->fields->len);
@@ -710,52 +788,26 @@
 
 	if (fcombo->cond != NULL) {
 		existing_cond = TRUE;
-		gnm_filter_condition_unref (fcombo->cond);
+		gnm_filter_condition_free (fcombo->cond);
 	}
 	fcombo->cond = cond;
 	g_signal_emit (G_OBJECT (fcombo), signals [COND_CHANGED], 0);
 
 	if (apply) {
 		/* if there was an existing cond then we need to do
-		 * 1) unfilter everything
-		 * 2) reapply all the filters
-		 * This is because we do record what elements this particular
-		 * field filtered
+		 * redo the whole filter.
+		 * This is because we do not record what elements this
+		 * particular field filtered
 		 */
-		if (existing_cond) {
-			colrow_set_visibility (filter->sheet, FALSE, TRUE,
-				filter->r.start.row + 1, filter->r.end.row);
-			for (i = 0 ; i < filter->fields->len ; i++)
-				gnm_filter_combo_apply (g_ptr_array_index (filter->fields, i),
-					filter->sheet);
-		} else
+		if (existing_cond)
+			gnm_filter_reapply (filter);
+		else
 			/* When adding a new cond all we need to do is
 			 * apply that filter */
 			gnm_filter_combo_apply (fcombo, filter->sheet);
 	}
 
-	/* set the activity flag and potentially activate the
-	 * in_filter flags in the rows */
-	if (cond == NULL) {
-		for (i = 0 ; i < filter->fields->len ; i++) {
-			fcombo = g_ptr_array_index (filter->fields, i);
-			if (fcombo->cond != NULL)
-				break;
-		}
-		if (i >= filter->fields->len) {
-			filter->is_active = FALSE;
-			set_infilter = TRUE;
-		}
-	} else if (!filter->is_active) {
-		filter->is_active = TRUE;
-		set_infilter = TRUE;
-	}
-
-	if (set_infilter)
-		for (r = filter->r.start.row; ++r <= filter->r.end.row ; ) {
-			ColRowInfo *ri = sheet_row_fetch (filter->sheet, r);
-			ri->in_filter = filter->is_active;
-		}
+	gnm_filter_update_active (filter);
 }
 
 /**
@@ -838,6 +890,49 @@
 	}
 }
 
+struct cb_remove_col_undo {
+	unsigned col;
+	GnmFilterCondition *cond;
+};
+
+static void
+cb_remove_col_undo_free (struct cb_remove_col_undo *r)
+{
+	gnm_filter_condition_free (r->cond);
+	g_free (r);
+}
+
+static void
+cb_remove_col_undo (GnmFilter *filter, struct cb_remove_col_undo *r, gpointer data)
+{
+	while (filter->fields->len <= r->col)
+		gnm_filter_add_field (filter, filter->fields->len);
+	gnm_filter_set_condition (filter, r->col,
+				  gnm_filter_condition_dup (r->cond),
+				  FALSE);
+}
+
+static void
+remove_col (GnmFilter *filter, unsigned col, GOUndo **pundo)
+{
+	GnmFilterCombo *fcombo = g_ptr_array_index (filter->fields, col);
+	if (pundo) {
+		struct cb_remove_col_undo *r = g_new (struct cb_remove_col_undo, 1);
+		GOUndo *u;
+
+		r->col = col;
+		r->cond = gnm_filter_condition_dup (fcombo->cond);
+		u = go_undo_binary_new
+			(gnm_filter_ref (filter), r,
+			 (GOUndoBinaryFunc)cb_remove_col_undo,
+			 (GFreeFunc)gnm_filter_unref,
+			 (GFreeFunc)cb_remove_col_undo_free);
+		*pundo = go_undo_combine (*pundo, u);
+	}
+	g_object_unref (fcombo);
+	g_ptr_array_remove_index (filter->fields, col);
+}
+
 /**
  * gnm_sheet_filter_insdel_colrow :
  * @sheet :
@@ -845,13 +940,15 @@
  * @is_insert :
  * @start :
  * @count :
+ * @pundo : location to store undo closures.
  *
  * Adjust filters as necessary to handle col/row insertions and deletions
  **/
 void
 gnm_sheet_filter_insdel_colrow (Sheet *sheet,
 				gboolean is_cols, gboolean is_insert,
-				int start, int count)
+				int start, int count,
+				GOUndo **pundo)
 {
 	GSList *ptr, *filters;
 
@@ -860,6 +957,8 @@
 	filters = g_slist_copy (sheet->filters);
 	for (ptr = filters; ptr != NULL ; ptr = ptr->next) {
 		GnmFilter *filter = ptr->data;
+		gboolean kill_filter = FALSE;
+		gboolean reapply_filter = FALSE;
 
 		if (is_cols) {
 			if (start > filter->r.end.col)	/* a */
@@ -900,10 +999,13 @@
 				}
 
 				if (filter->r.end.col < filter->r.start.col)
-					filter = NULL;
-				else
-					while (end_del-- > start_del)
-						g_ptr_array_remove_index (filter->fields, end_del);
+					kill_filter = TRUE;
+				else {
+					while (end_del-- > start_del) {
+						remove_col (filter, end_del, pundo);
+						reapply_filter = TRUE;
+					}
+				}
 			}
 		} else {
 			if (start > filter->r.end.row)
@@ -920,27 +1022,46 @@
 				/* REMOVING ROWS */
 				if (start <= filter->r.start.row) {
 					filter->r.end.row -= count;
-					if ((start+count) > filter->r.start.row)
+					if (start + count > filter->r.start.row)
 						/* delete if the dropdowns are wiped */
 						filter->r.start.row = filter->r.end.row + 1;
 					else
 						filter->r.start.row -= count;
-				} else if ((start+count) > filter->r.end.row)
+				} else if (start + count > filter->r.end.row)
 					filter->r.end.row = start -1;
 				else
 					filter->r.end.row -= count;
 
 				if (filter->r.end.row < filter->r.start.row)
-					filter = NULL;
+					kill_filter = TRUE;
 			}
 		}
 
-		if (filter == NULL) {
-			filter = ptr->data; /* we used it as a flag */
+		if (kill_filter) {
+			/*
+			 * Empty the filter as we need fresh combo boxes
+			 * if we undo.
+			 */
+			while (filter->fields->len)
+				remove_col (filter,
+					    filter->fields->len - 1,
+					    pundo);
+
 			gnm_filter_remove (filter);
-			/* the objects are already gone */
-			g_ptr_array_set_size (filter->fields, 0);
-			gnm_filter_free (filter);
+
+			if (pundo) {
+				GOUndo *u = go_undo_binary_new
+					(gnm_filter_ref (filter),
+					 sheet,
+					 (GOUndoBinaryFunc)gnm_filter_attach,
+					 (GFreeFunc)gnm_filter_unref,
+					 NULL);
+				*pundo = go_undo_combine (*pundo, u);
+			}
+			gnm_filter_unref (filter);
+		} else if (reapply_filter) {
+			gnm_filter_update_active (filter);
+			gnm_filter_reapply (filter);
 		}
 	}
 

Modified: trunk/src/sheet-filter.h
==============================================================================
--- trunk/src/sheet-filter.h	(original)
+++ trunk/src/sheet-filter.h	Fri Oct 24 02:46:59 2008
@@ -3,6 +3,7 @@
 # define _GNM_SHEET_FILTER_H_
 
 #include "gnumeric.h"
+#include <goffice/utils/go-undo.h>
 
 G_BEGIN_DECLS
 
@@ -52,6 +53,7 @@
 };
 
 struct _GnmFilter {
+	int ref_count;
 	Sheet *sheet;
 	GnmRange  r;
 
@@ -66,13 +68,12 @@
 GnmFilterCondition *gnm_filter_condition_new_bucket (gboolean top,
 						     gboolean absolute,
 						     float n);
-GnmFilterCondition *gnm_filter_condition_dup 	    (GnmFilterCondition const *src);
-void		    gnm_filter_condition_unref 	    (GnmFilterCondition *cond);
 
 GnmFilter 		 *gnm_filter_new	    (Sheet *sheet, GnmRange const *r);
 GnmFilter 		 *gnm_filter_dup	    (GnmFilter const *src,
 						     Sheet *sheet);
-void	   		  gnm_filter_free	    (GnmFilter *filter);
+GnmFilter *               gnm_filter_ref            (GnmFilter *filter);
+void	   		  gnm_filter_unref	    (GnmFilter *filter);
 void	   		  gnm_filter_remove	    (GnmFilter *filter);
 GnmFilterCondition const *gnm_filter_get_condition  (GnmFilter const *filter, unsigned i);
 void	   		  gnm_filter_set_condition  (GnmFilter *filter, unsigned i,
@@ -80,11 +81,14 @@
 						     gboolean apply);
 gboolean		  gnm_filter_overlaps_range (GnmFilter const *filter, GnmRange const *r);
 gboolean		  gnm_filter_overlaps_range (GnmFilter const *filter, GnmRange const *r);
+void                      gnm_filter_reapply        (GnmFilter *filter);
+
 
 void gnm_sheet_filter_guess_region  (Sheet *sheet, GnmRange *region);
 void gnm_sheet_filter_insdel_colrow (Sheet *sheet,
 				     gboolean is_cols, gboolean is_insert,
-				     int start, int count);
+				     int start, int count,
+				     GOUndo **pundo);
 
 G_END_DECLS
 

Modified: trunk/src/sheet.c
==============================================================================
--- trunk/src/sheet.c	(original)
+++ trunk/src/sheet.c	Fri Oct 24 02:46:59 2008
@@ -3490,7 +3490,7 @@
 	/* Save these because they are going to get zeroed. */
 	int const max_col = sheet->cols.max_used;
 	int const max_row = sheet->rows.max_used;
-
+	GSList *filters;
 	int i;
 	gpointer tmp;
 
@@ -3502,8 +3502,10 @@
 		return;
 
 	/* These contain SheetObjects, remove them first */
-	go_slist_free_custom (sheet->filters, (GFreeFunc)gnm_filter_free);
-	sheet->filters = NULL;
+	filters = g_slist_copy (sheet->filters);
+	g_slist_foreach (filters, (GFunc)gnm_filter_remove, NULL);
+	g_slist_foreach (filters, (GFunc)gnm_filter_unref, NULL);
+	g_slist_free (filters);
 
 	if (sheet->sheet_objects) {
 		/* The list is changed as we remove */
@@ -3885,7 +3887,7 @@
 	sheet_colrow_set_collapse (sheet, is_cols, pos);
 	sheet_colrow_set_collapse (sheet, is_cols, pos + count);
 	sheet_colrow_set_collapse (sheet, is_cols, colrow_max (is_cols, sheet));
-	gnm_sheet_filter_insdel_colrow (sheet, is_cols, TRUE, pos, count);
+	gnm_sheet_filter_insdel_colrow (sheet, is_cols, TRUE, pos, count, pundo);
 
 	/* WARNING WARNING WARNING
 	 * This is bad practice and should not really be here.
@@ -3909,7 +3911,7 @@
 	sheet_colrow_insdel_finish (rinfo, is_cols, pos, pundo);
 	sheet_colrow_set_collapse (sheet, is_cols, pos);
 	sheet_colrow_set_collapse (sheet, is_cols, end);
-	gnm_sheet_filter_insdel_colrow (sheet, is_cols, FALSE, pos, count);
+	gnm_sheet_filter_insdel_colrow (sheet, is_cols, FALSE, pos, count, pundo);
 
 	/* WARNING WARNING WARNING
 	 * This is bad practice and should not really be here.
@@ -3986,6 +3988,23 @@
 	combine_undo (pundo, u);
 }
 
+static void
+schedule_reapply_filters (Sheet *sheet, GOUndo **pundo)
+{
+	GSList *l;
+
+	if (!pundo)
+		return;
+
+	for (l = sheet->filters; l; l = l->next) {
+		GnmFilter *filter = l->data;
+		GOUndo *u = go_undo_unary_new
+			(gnm_filter_ref (filter),
+			 (GOUndoUnaryFunc)gnm_filter_reapply,
+			 (GFreeFunc)gnm_filter_unref);
+		*pundo = go_undo_combine (*pundo, u);
+	}
+}
 
 /**
  * sheet_insert_cols:
@@ -4008,11 +4027,14 @@
 	g_return_val_if_fail (IS_SHEET (sheet), TRUE);
 	g_return_val_if_fail (count > 0, TRUE);
 
+	if (pundo) *pundo = NULL;
+	schedule_reapply_filters (sheet, pundo);
+
 	if (pundo) {
 		int last = first + (count - 1);
 		GnmRange r;
 		range_init_cols (&r, first, last);
-		*pundo = clipboard_copy_range_undo (sheet, &r);
+		combine_undo (pundo, clipboard_copy_range_undo (sheet, &r));
 		states = colrow_get_states (sheet, TRUE, first, last);
 	}
 
@@ -4076,11 +4098,14 @@
 	g_return_val_if_fail (IS_SHEET (sheet), TRUE);
 	g_return_val_if_fail (count > 0, TRUE);
 
+	if (pundo) *pundo = NULL;
+	schedule_reapply_filters (sheet, pundo);
+
 	if (pundo) {
 		int last = col + (count - 1);
 		GnmRange r;
 		range_init_cols (&r, col, last);
-		*pundo = clipboard_copy_range_undo (sheet, &r);
+		combine_undo (pundo, clipboard_copy_range_undo (sheet, &r));
 		states = colrow_get_states (sheet, TRUE, col, last);
 	}
 
@@ -4160,11 +4185,14 @@
 	g_return_val_if_fail (IS_SHEET (sheet), TRUE);
 	g_return_val_if_fail (count > 0, TRUE);
 
+	if (pundo) *pundo = NULL;
+	schedule_reapply_filters (sheet, pundo);
+
 	if (pundo) {
 		int last = first + (count - 1);
 		GnmRange r;
 		range_init_rows (&r, first, last);
-		*pundo = clipboard_copy_range_undo (sheet, &r);
+		combine_undo (pundo, clipboard_copy_range_undo (sheet, &r));
 		states = colrow_get_states (sheet, FALSE, first, last);
 	}
 
@@ -4228,11 +4256,14 @@
 	g_return_val_if_fail (IS_SHEET (sheet), TRUE);
 	g_return_val_if_fail (count > 0, TRUE);
 
+	if (pundo) *pundo = NULL;
+	schedule_reapply_filters (sheet, pundo);
+
 	if (pundo) {
 		int last = row + (count - 1);
 		GnmRange r;
 		range_init_rows (&r, row, last);
-		*pundo = clipboard_copy_range_undo (sheet, &r);
+		combine_undo (pundo, clipboard_copy_range_undo (sheet, &r));
 		states = colrow_get_states (sheet, FALSE, row, last);
 	}
 

Modified: trunk/src/wbc-gtk-actions.c
==============================================================================
--- trunk/src/wbc-gtk-actions.c	(original)
+++ trunk/src/wbc-gtk-actions.c	Fri Oct 24 02:46:59 2008
@@ -773,7 +773,7 @@
 	} else {
 		/* keep distinct to simplify undo/redo later */
 		gnm_filter_remove (filter);
-		gnm_filter_free (filter);
+		gnm_filter_unref (filter);
 	}
 	/* ensure that the colour changes on the filtered row headers */
 	sheet_redraw_all (sv->sheet, TRUE);

Modified: trunk/src/widgets/gnm-filter-combo-foo-view.c
==============================================================================
--- trunk/src/widgets/gnm-filter-combo-foo-view.c	(original)
+++ trunk/src/widgets/gnm-filter-combo-foo-view.c	Fri Oct 24 02:46:59 2008
@@ -44,13 +44,6 @@
 #include <glib/gi18n-lib.h>
 #include <string.h>
 
-static int
-fcombo_index (GnmFilterCombo const *fcombo)
-{
-	return fcombo->parent.anchor.cell_bound.start.col
-		- fcombo->filter->r.start.col;
-}
-
 static void
 fcombo_activate (SheetObject *so, GtkWidget *popup, GtkTreeView *list,
 		 WBCGtk *wbcg)
@@ -68,7 +61,7 @@
 				    2, &type, 3, &v,
 				    -1);
 
-		field_num = fcombo_index (fcombo);
+		field_num = gnm_filter_combo_index (fcombo);
 		switch (type) {
 		case  0:
 			cond = gnm_filter_condition_new_single (
@@ -159,7 +152,7 @@
 	GtkTreeIter	 iter;
 	GtkListStore *model;
 	GPtrArray    *sorted = g_ptr_array_new ();
-	unsigned i, field_num = fcombo_index (fcombo);
+	unsigned i, field_num = gnm_filter_combo_index (fcombo);
 	gboolean is_custom = FALSE;
 	GnmValue const *v;
 	GnmValue const *cur_val = NULL;
@@ -199,7 +192,10 @@
 	 * The cleanest way to do that is to create a temporary sheet, apply
 	 * all of the other conditions to it and use that as the source of visibility. */
 	if (filter->fields->len > 1) {
-		filtered_sheet = sheet_new (uc.src_sheet->workbook, "_DummyFilterPopulate");
+		Workbook *wb = uc.src_sheet->workbook;
+		char *name = workbook_sheet_get_free_name (wb, "DummyFilterPopulate", FALSE, FALSE);
+		filtered_sheet = sheet_new (wb, name);
+		g_free (name);
 		for (i = 0 ; i < filter->fields->len ; i++)
 			if (i != field_num)
 				gnm_filter_combo_apply (g_ptr_array_index (filter->fields, i),

Modified: trunk/src/xml-sax-read.c
==============================================================================
--- trunk/src/xml-sax-read.c	(original)
+++ trunk/src/xml-sax-read.c	Fri Oct 24 02:46:59 2008
@@ -1244,7 +1244,7 @@
 	g_return_if_fail (state->style_range_init == FALSE);
 	g_return_if_fail (state->style == NULL);
 
-	state->style = (state->version >= GNM_XML_V6 ||
+	state->style = (1 || state->version >= GNM_XML_V6 ||
 			state->version <= GNM_XML_V2)
 		? gnm_style_new_default ()
 		: gnm_style_new ();
@@ -1332,6 +1332,25 @@
 		else
 			unknown_attr (xin, attrs);
 	}
+
+	/*
+	 * Old versions of Gnumeric evidently do not set all the attributes.
+	 * http://bugzilla.gnome.org/show_bug.cgi?id=555933
+	 */
+	if (!gnm_style_is_element_set (state->style, MSTYLE_COLOR_BACK)) {
+		colour = style_color_white ();
+		gnm_style_set_back_color (state->style, colour);
+	}
+
+	if (!gnm_style_is_element_set (state->style, MSTYLE_FONT_COLOR)) {
+		colour = style_color_black ();
+		gnm_style_set_font_color (state->style, colour);
+	}
+
+	if (!gnm_style_is_element_set (state->style, MSTYLE_COLOR_PATTERN)) {
+		colour = style_color_black ();
+		gnm_style_set_pattern_color (state->style, colour);
+	}
 }
 
 static void



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