[gnumeric] Sheet: Make sheet_cells take extra range argument.



commit 7721f31b1eef863a3b65b87012afd10dae31569c
Author: Morten Welinder <terra gnome org>
Date:   Sun Oct 14 08:41:52 2012 -0400

    Sheet: Make sheet_cells take extra range argument.

 ChangeLog                  |    5 +++++
 plugins/excel/xlsx-write.c |    2 +-
 src/sheet.c                |   16 +++++++---------
 src/sheet.h                |    2 +-
 4 files changed, 14 insertions(+), 11 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 86d3151..03ca0a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2012-10-14  Morten Welinder  <terra gnome org>
+
+	* src/sheet.c (sheet_cells): Take extra optional range argument.
+	All callers changed.
+
 2012-10-06  Morten Welinder  <terra gnome org>
 
 	* src/sheet.c (sheet_cell_positions): Renamed from sheet_cells.
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index 08d6916..a408ef7 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -1205,7 +1205,7 @@ xlsx_write_cells (XLSXWriteState *state, GsfXMLOut *xml,
 	gpointer tmp;
 	char *cheesy_span = g_strdup_printf ("%d:%d", extent->start.col+1, extent->end.col+1);
 	Sheet *sheet = (Sheet *)state->sheet;
-	GPtrArray *all_cells = sheet_cells (sheet);
+	GPtrArray *all_cells = sheet_cells (sheet, extent);
 	guint cno = 0;
 	int *boring_count;
 
diff --git a/src/sheet.c b/src/sheet.c
index b7b5080..58c5703 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -3737,7 +3737,7 @@ cell_ordering (gconstpointer a_, gconstpointer b_)
 }
 
 GPtrArray *
-sheet_cells (Sheet *sheet)
+sheet_cells (Sheet *sheet, const GnmRange *r)
 {
 	GPtrArray *res = g_ptr_array_new ();
 	GHashTableIter hiter;	
@@ -3745,7 +3745,9 @@ sheet_cells (Sheet *sheet)
 
 	g_hash_table_iter_init (&hiter, sheet->cell_hash);
 	while (g_hash_table_iter_next (&hiter, NULL, &value)) {
-		g_ptr_array_add (res, value);
+		GnmCell *cell = value;
+		if (!r || range_contains (r, cell->pos.col, cell->pos.row))
+			g_ptr_array_add (res, cell);
 	}
 	g_ptr_array_sort (res, cell_ordering);
 
@@ -3830,22 +3832,18 @@ sheet_foreach_cell_in_range (Sheet *sheet, CellIterFlags flags,
 		int last_row = -1, last_col = -1;
 		GnmValue *res = NULL;
 		unsigned ui;
+		GnmRange r;
 
 		if (gnm_debug_flag ("sheet-foreach"))
 			g_printerr ("Using celllist for area of size %d\n",
 				    (int)range_size);
 
-		all_cells = sheet_cells (sheet);
+		range_init (&r, start_col, start_row, end_col, end_row);
+		all_cells = sheet_cells (sheet, &r);
 
 		for (ui = 0; ui < all_cells->len; ui++) {
 			GnmCell *cell = g_ptr_array_index (all_cells, ui);
 
-			if (cell->pos.col < start_col ||
-			    cell->pos.col > end_col ||
-			    cell->pos.row < start_row ||
-			    cell->pos.row > end_row)
-				continue;
-
 			iter.cell = cell;
 			iter.pp.eval.row = cell->pos.row;
 			iter.pp.eval.col = cell->pos.col;
diff --git a/src/sheet.h b/src/sheet.h
index 5a3b5fe..8fd90b2 100644
--- a/src/sheet.h
+++ b/src/sheet.h
@@ -167,7 +167,7 @@ void	    sheet_cell_foreach	 (Sheet const *sheet,
 unsigned    sheet_cells_count	 (Sheet const *sheet);
 GPtrArray  *sheet_cell_positions (Sheet *sheet, gboolean comments);
 
-GPtrArray  *sheet_cells          (Sheet *sheet);
+GPtrArray  *sheet_cells          (Sheet *sheet, const GnmRange *r);
 
 void        sheet_recompute_spans_for_col     (Sheet *sheet, int col);
 



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