From bba176a844bd993cf7fe6acce9ff18027870dfa5 Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Mon, 23 Apr 2012 01:15:01 +0200 Subject: only update absolute refs when copying between docs, fdo#48482 The copy/paste formulas code is getting a bit complex. I will try to write some test cases for it. --- sc/inc/tokenarray.hxx | 3 ++- sc/source/core/data/cell.cxx | 7 ++++--- sc/source/core/tool/token.cxx | 14 +++++++------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx index 48bf4c504287..cc55936afe88 100644 --- a/sc/inc/tokenarray.hxx +++ b/sc/inc/tokenarray.hxx @@ -108,8 +108,9 @@ public: /** * Make all absolute references pointing to the copied range if the range is copied too + * @param bCheckCopyArea should references pointing into the copy area be adjusted independently from being absolute, should be true only for copy&paste between documents */ - void AdjustAbsoluteRefs( const ScDocument* pOldDoc, const ScAddress& rOldPos, const ScAddress& rNewPos, bool bRangeName = false ); + void AdjustAbsoluteRefs( const ScDocument* pOldDoc, const ScAddress& rOldPos, const ScAddress& rNewPos, bool bRangeName = false, bool bCheckCopyArea = false ); }; #endif // SC_TOKENARRAY_HXX diff --git a/sc/source/core/data/cell.cxx b/sc/source/core/data/cell.cxx index a4e536191ed8..fd9499bece11 100644 --- a/sc/source/core/data/cell.cxx +++ b/sc/source/core/data/cell.cxx @@ -175,7 +175,7 @@ void adjustRangeName(ScToken* pToken, ScDocument& rNewDoc, const ScDocument* pOl if (rNewDoc.GetPool() != const_cast(pOldDoc)->GetPool()) { pRangeNameToken->ReadjustAbsolute3DReferences(pOldDoc, &rNewDoc, pRangeData->GetPos(), true); - pRangeNameToken->AdjustAbsoluteRefs(pOldDoc, aOldPos, aNewPos, true); + pRangeNameToken->AdjustAbsoluteRefs(pOldDoc, aOldPos, aNewPos, false, true); } bool bInserted; @@ -811,12 +811,13 @@ ScFormulaCell::ScFormulaCell( const ScFormulaCell& rCell, ScDocument& rDoc, cons } } - if (pDocument->GetPool() != rCell.pDocument->GetPool()) + bool bCopyBetweenDocs = pDocument->GetPool() != rCell.pDocument->GetPool(); + if (bCopyBetweenDocs) { pCode->ReadjustAbsolute3DReferences( rCell.pDocument, &rDoc, rCell.aPos); } - pCode->AdjustAbsoluteRefs( rCell.pDocument, rCell.aPos, aPos ); + pCode->AdjustAbsoluteRefs( rCell.pDocument, rCell.aPos, aPos, false, bCopyBetweenDocs ); } if ( nCloneFlags & SC_CLONECELL_ADJUST3DREL ) diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index 0bbb3d6cc07b..dc88df1d2cfd 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -1832,7 +1832,7 @@ bool IsInCopyRange( const ScRange& rRange, const ScDocument* pClipDoc ) return rClipParam.maRanges.In(rRange); } -bool SkipReference(ScToken* pToken, const ScAddress& rPos, const ScDocument* pOldDoc, bool bRangeName) +bool SkipReference(ScToken* pToken, const ScAddress& rPos, const ScDocument* pOldDoc, bool bRangeName, bool bCheckCopyArea) { ScRange aRange; @@ -1862,7 +1862,7 @@ bool SkipReference(ScToken* pToken, const ScAddress& rPos, const ScDocument* pOl } } - if (IsInCopyRange(aRange, pOldDoc)) + if (bCheckCopyArea && IsInCopyRange(aRange, pOldDoc)) return true; return false; @@ -1894,7 +1894,7 @@ void ScTokenArray::ReadjustAbsolute3DReferences( const ScDocument* pOldDoc, cons { case svDoubleRef : { - if (SkipReference(static_cast(pCode[j]), rPos, pOldDoc, bRangeName)) + if (SkipReference(static_cast(pCode[j]), rPos, pOldDoc, bRangeName, true)) continue; ScComplexRefData& rRef = static_cast(pCode[j])->GetDoubleRef(); @@ -1915,7 +1915,7 @@ void ScTokenArray::ReadjustAbsolute3DReferences( const ScDocument* pOldDoc, cons break; case svSingleRef : { - if (SkipReference(static_cast(pCode[j]), rPos, pOldDoc, bRangeName)) + if (SkipReference(static_cast(pCode[j]), rPos, pOldDoc, bRangeName, true)) continue; ScSingleRefData& rRef = static_cast(pCode[j])->GetSingleRef(); @@ -1941,7 +1941,7 @@ void ScTokenArray::ReadjustAbsolute3DReferences( const ScDocument* pOldDoc, cons } } -void ScTokenArray::AdjustAbsoluteRefs( const ScDocument* pOldDoc, const ScAddress& rOldPos, const ScAddress& rNewPos, bool bRangeName) +void ScTokenArray::AdjustAbsoluteRefs( const ScDocument* pOldDoc, const ScAddress& rOldPos, const ScAddress& rNewPos, bool bRangeName, bool bCheckCopyRange) { for ( sal_uInt16 j=0; j(pCode[j]), rOldPos, pOldDoc, false)) + if (!SkipReference(static_cast(pCode[j]), rOldPos, pOldDoc, false, bCheckCopyRange)) continue; ScComplexRefData& rRef = static_cast(pCode[j])->GetDoubleRef(); @@ -1966,7 +1966,7 @@ void ScTokenArray::AdjustAbsoluteRefs( const ScDocument* pOldDoc, const ScAddres break; case svSingleRef : { - if (!SkipReference(static_cast(pCode[j]), rOldPos, pOldDoc, false)) + if (!SkipReference(static_cast(pCode[j]), rOldPos, pOldDoc, false, bCheckCopyRange)) continue; ScSingleRefData& rRef = static_cast(pCode[j])->GetSingleRef(); -- cgit v1.2.3