[Libreoffice-commits] .: Branch 'libreoffice-3-4' - sc/source
Kohei Yoshida
kohei at kemper.freedesktop.org
Thu May 5 21:12:16 PDT 2011
sc/source/ui/docshell/externalrefmgr.cxx | 48 ++++++++++++++++++++++++++++++-
1 file changed, 47 insertions(+), 1 deletion(-)
New commits:
commit c719ed67aa45701c771134cabf51c37dc7d0ec9d
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Fri May 6 00:07:35 2011 -0400
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).
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index fc12cf1..59365c1 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);
}
More information about the Libreoffice-commits
mailing list