diff options
author | Kohei Yoshida <kyoshida@novell.com> | 2011-05-05 22:46:39 -0400 |
---|---|---|
committer | Kohei Yoshida <kyoshida@novell.com> | 2011-05-05 22:46:39 -0400 |
commit | e892251cac6d6b8830dcf61361348561b99c67f3 (patch) | |
tree | 14b56273f62031818860ab29808cb69e14a176e8 | |
parent | 12400a5fe4204f9aed4ac7e3525a64ff357c862f (diff) |
Properly cache external reference values in named ranges.
Values of the external references used only in named ranges were
not cached properly. This commit fixes it.
-rw-r--r-- | sc/source/core/data/documen4.cxx | 85 |
1 files changed, 57 insertions, 28 deletions
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx index a5ecb95f5..85dc63668 100644 --- a/sc/source/core/data/documen4.cxx +++ b/sc/source/core/data/documen4.cxx @@ -296,42 +296,71 @@ void ScDocument::InsertTableOp(const ScTabOpParam& rParam, // Mehrfachopera pTab[i]->PutCell( j, k, aRefCell.CloneWithoutNote( *this, ScAddress( j, k, i ), SC_CLONECELL_STARTLISTENING ) ); } +namespace { + +bool setCacheTableReferenced(ScToken& rToken, ScExternalRefManager& rRefMgr) +{ + switch (rToken.GetType()) + { + case svExternalSingleRef: + return rRefMgr.setCacheTableReferenced( + rToken.GetIndex(), rToken.GetString(), 1); + case svExternalDoubleRef: + { + const ScComplexRefData& rRef = rToken.GetDoubleRef(); + size_t nSheets = rRef.Ref2.nTab - rRef.Ref1.nTab + 1; + return rRefMgr.setCacheTableReferenced( + rToken.GetIndex(), rToken.GetString(), nSheets); + } + case svExternalName: + /* TODO: external names aren't supported yet, but would + * have to be marked as well, if so. Mechanism would be + * different. */ + DBG_ERRORFILE("ScDocument::MarkUsedExternalReferences: implement the svExternalName case!"); + default: + ; + } + return false; +} + +} + bool ScDocument::MarkUsedExternalReferences( ScTokenArray & rArr ) { + if (!rArr.GetLen()) + return false; + + ScExternalRefManager* pRefMgr = NULL; + rArr.Reset(); + ScToken* t = NULL; bool bAllMarked = false; - if (rArr.GetLen()) + while (!bAllMarked && (t = static_cast<ScToken*>(rArr.GetNextReferenceOrName())) != NULL) { - ScExternalRefManager* pRefMgr = NULL; - rArr.Reset(); - ScToken* t; - while (!bAllMarked && (t = static_cast<ScToken*>(rArr.GetNextReferenceOrName())) != NULL) + if (t->IsExternalRef()) + { + if (!pRefMgr) + pRefMgr = GetExternalRefManager(); + + bAllMarked = setCacheTableReferenced(*t, *pRefMgr); + } + else if (t->GetType() == svIndex) { - if (t->IsExternalRef()) + // this is a named range. Check if the range contains an external + // reference. + ScRangeData* pRangeData = GetRangeName()->findByIndex(t->GetIndex()); + if (!pRangeData) + continue; + + ScTokenArray* pArray = pRangeData->GetCode(); + for (t = static_cast<ScToken*>(pArray->First()); t; t = static_cast<ScToken*>(pArray->Next())) { + if (!t->IsExternalRef()) + continue; + if (!pRefMgr) pRefMgr = GetExternalRefManager(); - switch (t->GetType()) - { - case svExternalSingleRef: - bAllMarked = pRefMgr->setCacheTableReferenced( - t->GetIndex(), t->GetString(), 1); - break; - case svExternalDoubleRef: - { - const ScComplexRefData& rRef = t->GetDoubleRef(); - size_t nSheets = rRef.Ref2.nTab - rRef.Ref1.nTab + 1; - bAllMarked = pRefMgr->setCacheTableReferenced( - t->GetIndex(), t->GetString(), nSheets); - } - break; - case svExternalName: - /* TODO: external names aren't supported yet, but would - * have to be marked as well, if so. Mechanism would be - * different. */ - DBG_ERRORFILE("ScDocument::MarkUsedExternalReferences: implement the svExternalName case!"); - break; - default: break; - } + + bAllMarked = setCacheTableReferenced(*t, *pRefMgr); } } } |