summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kyoshida@novell.com>2011-05-06 00:07:35 -0400
committerKohei Yoshida <kyoshida@novell.com>2011-05-06 00:07:35 -0400
commitd27a9990830d5742aa71c241723e2e5a0c050ed4 (patch)
tree51be279be2862f5a51d8c690cae953cf23f0d304 /sc
parentfb4f96da8c159ad75da3a16e08d1940dd588c1e7 (diff)
fdo#34930: Remove range names with external references when breaking link.
When breaking a link in Edit -> Links, cells containing references to that link get staticized i.e. their formulas replaced with static values. This also applies to cells containing range names that point to external document. We should remove such range names when the link gets broken, or else reloading the document would re-introduce the link on file load again, and the link would never go away (without manually removing those range names).
Diffstat (limited to 'sc')
-rw-r--r--sc/source/ui/docshell/externalrefmgr.cxx48
1 files changed, 47 insertions, 1 deletions
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index fc12cf1a8681..59365c103763 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -74,6 +74,7 @@ using ::rtl::OUString;
using ::std::vector;
using ::std::find;
using ::std::find_if;
+using ::std::remove_if;
using ::std::distance;
using ::std::pair;
using ::std::list;
@@ -85,7 +86,7 @@ using namespace formula;
namespace {
-class TabNameSearchPredicate : public unary_function<bool, ScExternalRefCache::TableName>
+class TabNameSearchPredicate : public unary_function<ScExternalRefCache::TableName, bool>
{
public:
explicit TabNameSearchPredicate(const String& rSearchName) :
@@ -201,6 +202,35 @@ private:
ScDocument* mpDoc;
};
+/**
+ * Predicate used to determine whether a named range contains an external
+ * reference to a particular document.
+ */
+class RangeNameWithExtRef : unary_function<ScRangeData, bool>
+{
+ sal_uInt16 mnFileId;
+public:
+ RangeNameWithExtRef(sal_uInt16 nFileId) : mnFileId(nFileId) {}
+ bool operator() (ScRangeData& rData) const
+ {
+ ScTokenArray* pArray = rData.GetCode();
+ if (!pArray)
+ return false;
+
+ pArray->Reset();
+ ScToken* p = static_cast<ScToken*>(pArray->GetNextReference());
+ for (; p; p = static_cast<ScToken*>(pArray->GetNextReference()))
+ {
+ if (!p->IsExternalRef())
+ continue;
+
+ if (p->GetIndex() == mnFileId)
+ return true;
+ }
+ return false;
+ }
+};
+
}
// ============================================================================
@@ -2391,6 +2421,22 @@ void ScExternalRefManager::breakLink(sal_uInt16 nFileId)
// the original container.
RefCellSet aSet = itrRefs->second;
for_each(aSet.begin(), aSet.end(), ConvertFormulaToStatic(mpDoc));
+
+ // Remove all named ranges that reference this document.
+
+ // Global named ranges.
+ ScRangeName* pRanges = mpDoc->GetRangeName();
+ if (pRanges)
+ remove_if(pRanges->begin(), pRanges->end(), RangeNameWithExtRef(nFileId));
+
+ // Sheet-local named ranges.
+ for (SCTAB i = 0, n = mpDoc->GetTableCount(); i < n; ++i)
+ {
+ pRanges = mpDoc->GetRangeName(i);
+ if (pRanges)
+ remove_if(pRanges->begin(), pRanges->end(), RangeNameWithExtRef(nFileId));
+ }
+
maRefCells.erase(nFileId);
}