[gnumeric] Workbook: avoid some inclusion of workbook-priv.h



commit 3c68863ff48e89d325229f5dcdfeba57fa3ecf59
Author: Morten Welinder <terra gnome org>
Date:   Sun May 22 11:40:48 2011 -0400

    Workbook: avoid some inclusion of workbook-priv.h

 ChangeLog                             |    5 ++++
 plugins/excel/ms-formula-write.c      |    2 +-
 plugins/openoffice/ChangeLog          |    6 +++++
 plugins/openoffice/openoffice-read.c  |   34 +++++++++++---------------------
 plugins/openoffice/openoffice-write.c |   14 ++++++------
 src/dialogs/dialog-goto-cell.c        |   15 +++++--------
 src/expr-name.c                       |    3 ++
 src/expr.c                            |    2 +-
 src/session.c                         |    1 -
 src/wbc-gtk-actions.c                 |    2 +-
 src/workbook-priv.h                   |   10 ---------
 src/workbook.h                        |   12 +++++++++++
 12 files changed, 54 insertions(+), 52 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 26217ac..52aba27 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2011-05-22  Morten Welinder  <terra gnome org>
+
+	* src/workbook.h (WORKBOOK_FOREACH_SHEET): Move from
+	workbook-priv.h
+
 2011-05-21  Morten Welinder  <terra gnome org>
 
 	* src/expr-name.c (expr_name_set_pos): Rename from
diff --git a/plugins/excel/ms-formula-write.c b/plugins/excel/ms-formula-write.c
index 1e0c835..32e3e71 100644
--- a/plugins/excel/ms-formula-write.c
+++ b/plugins/excel/ms-formula-write.c
@@ -22,7 +22,7 @@
 
 #include <sheet.h>
 #include <gutils.h>
-#include <workbook-priv.h>
+#include <workbook.h>
 #include <func.h>
 #include <value.h>
 #include <cell.h>
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index fec5db3..7f272f0 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,9 @@
+2011-05-22  Morten Welinder  <terra gnome org>
+
+	* openoffice-write.c (odf_write_content): Remove test for
+	always-true condition.  If we must have that check, it should
+	check for an active global name that we intend to write.
+
 2011-05-21  Morten Welinder  <terra gnome org>
 
 	* openoffice-read.c (odf_fix_en_apply): Use expr_name_set_name.
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index d005a8d..da45407 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -29,7 +29,6 @@
 #include <gnm-plugin.h>
 #include <workbook-view.h>
 #include <workbook.h>
-#include <workbook-priv.h>
 #include <sheet.h>
 #include <sheet-merge.h>
 #include <sheet-filter.h>
@@ -1287,18 +1286,20 @@ odf_fix_expr_names_t_add (odf_fix_expr_names_t *fen, char const *orig, char *fix
 static gboolean
 odf_fix_en_validate (char const *name, odf_fix_expr_names_t *fen)
 {
-	GSList *sheets;
-
 	if (!expr_name_validate (name))
 		return FALSE;
 	if (NULL != g_hash_table_lookup (fen->fixed2orig, name))
 		return FALSE;
-	if (NULL != gnm_named_expr_collection_lookup (fen->state->pos.wb->names, name))
-		return FALSE;
-	for (sheets = workbook_sheets (fen->state->pos.wb); sheets != NULL; sheets = sheets->next)
-		if (NULL != gnm_named_expr_collection_lookup 
-		    (((Sheet *)(sheets->data))->names, name))
-			return FALSE;
+
+	WORKBOOK_FOREACH_SHEET
+		(fen->state->pos.wb, sheet,
+		 {
+			 GnmParsePos pp;
+			 parse_pos_init_sheet (&pp, sheet);
+			 if (expr_name_lookup (&pp, name))
+				 return FALSE;
+		 });
+
 	return TRUE;
 }
 
@@ -1339,21 +1340,10 @@ static void
 odf_fix_expr_names (OOParseState *state)
 {
 	odf_fix_expr_names_t *fen = odf_fix_expr_names_t_new (state);
-	GSList *sheets = workbook_sheets (state->pos.wb), *l;
-
-	g_hash_table_foreach (state->pos.wb->names->names, 
-			      (GHFunc)odf_fix_en_collect, fen);
-	g_hash_table_foreach (state->pos.wb->names->placeholders, 
-			      (GHFunc)odf_fix_en_collect, fen);
-	for (l = sheets; l != NULL; l = l->next) {
-		Sheet *sheet = l->data;
-		g_hash_table_foreach (sheet->names->names, 
-				      (GHFunc) odf_fix_en_collect, fen);
-		g_hash_table_foreach (sheet->names->placeholders, 
-				      (GHFunc) odf_fix_en_collect, fen);
-	}
 
 	workbook_foreach_name (state->pos.wb, FALSE,
+			       (GHFunc)odf_fix_en_collect, fen);
+	workbook_foreach_name (state->pos.wb, FALSE,
 			       (GHFunc)odf_fix_en_apply, fen->orig2fixed);
 
 	odf_fix_expr_names_t_free (fen);
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index eedec7d..d669465 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -4268,13 +4268,13 @@ odf_write_content (GnmOOExport *state, GsfOutput *child)
 		has_autofilters |= (sheet->filters != NULL);
 		odf_update_progress (state, state->sheet_progress);
 	}
-	if (state->wb->names != NULL) {
-		gsf_xml_out_start_element (state->xml, TABLE "named-expressions");
-		workbook_foreach_name
-			(state->wb, (get_gsf_odf_version () > 101),
-			 (GHFunc)&odf_write_named_expression, state);
-		gsf_xml_out_end_element (state->xml); /* </table:named-expressions> */
-	}
+
+	gsf_xml_out_start_element (state->xml, TABLE "named-expressions");
+	workbook_foreach_name
+		(state->wb, (get_gsf_odf_version () > 101),
+		 (GHFunc)&odf_write_named_expression, state);
+	gsf_xml_out_end_element (state->xml); /* </table:named-expressions> */
+
 	if (has_autofilters) {
 		gsf_xml_out_start_element (state->xml, TABLE "database-ranges");
 		for (i = 0; i < workbook_sheet_count (state->wb); i++) {
diff --git a/src/dialogs/dialog-goto-cell.c b/src/dialogs/dialog-goto-cell.c
index 74944cb..31906b5 100644
--- a/src/dialogs/dialog-goto-cell.c
+++ b/src/dialogs/dialog-goto-cell.c
@@ -29,12 +29,12 @@
 #include "help.h"
 
 #include <gui-util.h>
-#include <workbook-priv.h> /* for Workbook::names */
 #include <workbook-control.h>
 #include <ranges.h>
 #include <value.h>
 #include <expr-name.h>
 #include <sheet.h>
+#include <workbook.h>
 #include <workbook-view.h>
 
 #include <wbc-gtk.h>
@@ -138,6 +138,9 @@ cb_load_names (G_GNUC_UNUSED gpointer key,
 	GtkTreeIter iter;
 	gboolean is_address = gnm_expr_top_is_rangeref (nexpr->texpr);
 
+	if (expr_name_is_placeholder (nexpr))
+		return;
+
 	if (is_address) {
 		gtk_tree_store_append (user->state->model, &iter, &user->iter);
 		gtk_tree_store_set (user->state->model, &iter,
@@ -165,9 +168,8 @@ dialog_goto_load_names (GotoState *state)
 			    SHEET_POINTER,	NULL,
 			    EXPRESSION,		NULL,
 			    -1);
-	if (state->wb->names != NULL)
-		g_hash_table_foreach (state->wb->names->names,
-			(GHFunc) cb_load_names, &closure);
+	workbook_foreach_name (state->wb, FALSE,
+			       (GHFunc)cb_load_names, &closure);
 
 	l = workbook_sheet_count (state->wb);
 	for (i = 0; i < l; i++) {
@@ -179,12 +181,7 @@ dialog_goto_load_names (GotoState *state)
 				    SHEET_POINTER,	sheet,
 				    EXPRESSION,		NULL,
 				    -1);
-
-		if (sheet->names != NULL)
-			g_hash_table_foreach (sheet->names->names,
-				(GHFunc) cb_load_names, &closure);
 	}
-
 }
 
 static void
diff --git a/src/expr-name.c b/src/expr-name.c
index b179731..47ee101 100644
--- a/src/expr-name.c
+++ b/src/expr-name.c
@@ -730,6 +730,9 @@ expr_name_set_name (GnmNamedExpr *nexpr,
 	if (go_str_compare (new_name, old_name) == 0)
 		return FALSE;
 
+#if 1
+	g_printerr ("Renaming %s to %s\n", old_name, new_name);
+#endif
 	h = nexpr->scope
 		? (nexpr->is_placeholder
 		   ? nexpr->scope->placeholders
diff --git a/src/expr.c b/src/expr.c
index 8bf8774..f402b5a 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -36,7 +36,7 @@
 #include "parse-util.h"
 #include "ranges.h"
 #include "number-match.h"
-#include "workbook-priv.h"
+#include "workbook.h"
 #include "gutils.h"
 #include "parse-util.h"
 #include "mathfunc.h"
diff --git a/src/session.c b/src/session.c
index 637c1a4..b339142 100644
--- a/src/session.c
+++ b/src/session.c
@@ -27,7 +27,6 @@
 #include "session.h"
 #include "application.h"
 #include <workbook.h>
-#include <workbook-priv.h>
 #include <workbook-view.h>
 #include <wbc-gtk.h>
 #include <gui-file.h>
diff --git a/src/wbc-gtk-actions.c b/src/wbc-gtk-actions.c
index f40ac41..e56ad14 100644
--- a/src/wbc-gtk-actions.c
+++ b/src/wbc-gtk-actions.c
@@ -48,7 +48,7 @@
 #include "sheet-control-gui-priv.h"
 #include "sheet-view.h"
 #include "cmd-edit.h"
-#include "workbook-priv.h"
+#include "workbook.h"
 #include "workbook-view.h"
 #include "wbc-gtk-impl.h"
 #include "workbook-cmd-format.h"
diff --git a/src/workbook-priv.h b/src/workbook-priv.h
index 63abadd..765ed67 100644
--- a/src/workbook-priv.h
+++ b/src/workbook-priv.h
@@ -68,16 +68,6 @@ do {										\
 	WORKBOOK_FOREACH_VIEW((wb), view,				\
 		WORKBOOK_VIEW_FOREACH_CONTROL(view, control, code);)
 
-
-#define WORKBOOK_FOREACH_SHEET(wb, sheet, code)					\
-  do {										\
-	unsigned _sheetno;							\
-	for (_sheetno = 0; _sheetno < (wb)->sheets->len; _sheetno++) {		\
-		Sheet *sheet = g_ptr_array_index ((wb)->sheets, _sheetno);	\
-		code;								\
-	}									\
-  } while (0)
-
 /*
  * Walk the dependents.  WARNING: Note, that it is only valid to muck with
  * the current dependency in the code.
diff --git a/src/workbook.h b/src/workbook.h
index 6371fb7..1dfe40c 100644
--- a/src/workbook.h
+++ b/src/workbook.h
@@ -90,6 +90,18 @@ int workbook_sheet_state_size	(WorkbookSheetState const *wss);
 char *workbook_sheet_state_diff (WorkbookSheetState const *wss_a,
 				 WorkbookSheetState const *wss_b);
 
+#define WORKBOOK_FOREACH_SHEET(wb, sheet, code)				\
+  do {									\
+	  const Workbook *wb_ = (wb);					\
+	  unsigned sheetno_;						\
+	  unsigned sheetcount_ = workbook_sheet_count (wb_);		\
+	  for (sheetno_ = 0; sheetno_ < sheetcount_; sheetno_++) {	\
+		  Sheet *sheet = workbook_sheet_by_index (wb_, sheetno_); \
+		  code;							\
+	  }								\
+  } while (0)
+
+
 G_END_DECLS
 
 #endif /* _GNM_WORKBOOK_H_ */



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