diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2011-12-22 02:51:08 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2011-12-23 09:14:17 +0100 |
commit | c638b526a98915bf1190ca8ab2f8b6ec9b39a101 (patch) | |
tree | 231fffa06452119ccc8d55d510e4c27ee118a944 | |
parent | sc test : enhance importSheet tests regarding namedRanges (diff) | |
download | core-c638b526a98915bf1190ca8ab2f8b6ec9b39a101.tar.gz core-c638b526a98915bf1190ca8ab2f8b6ec9b39a101.zip |
adjust absolute refs to copied areas correctly
-rw-r--r-- | sc/inc/tokenarray.hxx | 7 | ||||
-rw-r--r-- | sc/source/core/data/cell.cxx | 6 | ||||
-rw-r--r-- | sc/source/core/tool/token.cxx | 68 |
3 files changed, 72 insertions, 9 deletions
diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx index 1819de247647..df214b07cebc 100644 --- a/sc/inc/tokenarray.hxx +++ b/sc/inc/tokenarray.hxx @@ -104,7 +104,12 @@ public: * @param rPos position of the cell to determine if the reference is in the copied area * @param bRangeName set for range names, range names have special handling for absolute sheet ref + relative col/row ref */ - void ReadjusteAbsolute3DReferences( const ScDocument* pOldDoc, const ScDocument* pNewDoc, const ScAddress& rPos, bool bRangeName = false ); + void ReadjustAbsolute3DReferences( const ScDocument* pOldDoc, const ScDocument* pNewDoc, const ScAddress& rPos, bool bRangeName = false ); + + /** + * Make all absolute references pointing to the copied range if the range is copied too + */ + void AdjustAbsoluteRefs( const ScDocument* pOldDoc, const ScAddress& rOldPos, const ScAddress& rNewPos ); }; #endif // SC_TOKENARRAY_HXX diff --git a/sc/source/core/data/cell.cxx b/sc/source/core/data/cell.cxx index f7ea541435fd..cf5f70ffbd9e 100644 --- a/sc/source/core/data/cell.cxx +++ b/sc/source/core/data/cell.cxx @@ -182,7 +182,7 @@ void adjustRangeName(ScToken* pToken, ScDocument& rNewDoc, const ScDocument* pOl ScTokenArray* pRangeNameToken = pRangeData->GetCode(); if (rNewDoc.GetPool() != const_cast<ScDocument*>(pOldDoc)->GetPool()) { - pRangeNameToken->ReadjusteAbsolute3DReferences(pOldDoc, &rNewDoc, pRangeData->GetPos(), true); + pRangeNameToken->ReadjustAbsolute3DReferences(pOldDoc, &rNewDoc, pRangeData->GetPos(), true); } bool bInserted; @@ -890,8 +890,10 @@ ScFormulaCell::ScFormulaCell( const ScFormulaCell& rCell, ScDocument& rDoc, cons if (pDocument->GetPool() != rCell.pDocument->GetPool()) { - pCode->ReadjusteAbsolute3DReferences( rCell.pDocument, &rDoc, rCell.aPos); + pCode->ReadjustAbsolute3DReferences( rCell.pDocument, &rDoc, rCell.aPos); } + + pCode->AdjustAbsoluteRefs( rCell.pDocument, rCell.aPos, aPos ); } if( !bCompile ) diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index dcc08d449c40..6ef4346029fa 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -1875,9 +1875,25 @@ bool SkipReference(ScToken* pToken, const ScAddress& rPos, const ScDocument* pOl return false; } +void AdjustSingleRefData( ScSingleRefData& rRef, const ScAddress& rOldPos, const ScAddress& rNewPos) +{ + SCsCOL nCols = rNewPos.Col() - rOldPos.Col(); + SCsROW nRows = rNewPos.Row() - rOldPos.Row(); + SCsTAB nTabs = rNewPos.Tab() - rOldPos.Tab(); + + if (!rRef.IsColRel()) + rRef.nCol += nCols; + + if (!rRef.IsRowRel()) + rRef.nRow += nRows; + + if (!rRef.IsTabRel()) + rRef.nTab += nTabs; } -void ScTokenArray::ReadjusteAbsolute3DReferences( const ScDocument* pOldDoc, const ScDocument* pNewDoc, const ScAddress& rPos, bool bRangeName ) +} + +void ScTokenArray::ReadjustAbsolute3DReferences( const ScDocument* pOldDoc, const ScDocument* pNewDoc, const ScAddress& rPos, bool bRangeName ) { for ( sal_uInt16 j=0; j<nLen; ++j ) { @@ -1885,13 +1901,13 @@ void ScTokenArray::ReadjusteAbsolute3DReferences( const ScDocument* pOldDoc, con { case svDoubleRef : { + if (SkipReference(static_cast<ScToken*>(pCode[j]), rPos, pOldDoc, bRangeName)) + continue; + ScComplexRefData& rRef = static_cast<ScToken*>(pCode[j])->GetDoubleRef(); ScSingleRefData& rRef2 = rRef.Ref2; ScSingleRefData& rRef1 = rRef.Ref1; - if (SkipReference(static_cast<ScToken*>(pCode[j]), rPos, pOldDoc, bRangeName)) - continue; - if ( (rRef2.IsFlag3D() && !rRef2.IsTabRel()) || (rRef1.IsFlag3D() && !rRef1.IsTabRel()) ) { rtl::OUString aTabName; @@ -1906,11 +1922,11 @@ void ScTokenArray::ReadjusteAbsolute3DReferences( const ScDocument* pOldDoc, con break; case svSingleRef : { - ScSingleRefData& rRef = static_cast<ScToken*>(pCode[j])->GetSingleRef(); - if (SkipReference(static_cast<ScToken*>(pCode[j]), rPos, pOldDoc, bRangeName)) continue; + ScSingleRefData& rRef = static_cast<ScToken*>(pCode[j])->GetSingleRef(); + if ( rRef.IsFlag3D() && !rRef.IsTabRel() ) { rtl::OUString aTabName; @@ -1932,5 +1948,45 @@ void ScTokenArray::ReadjusteAbsolute3DReferences( const ScDocument* pOldDoc, con } } +void ScTokenArray::AdjustAbsoluteRefs( const ScDocument* pOldDoc, const ScAddress& rOldPos, const ScAddress& rNewPos) +{ + for ( sal_uInt16 j=0; j<nLen; ++j ) + { + switch ( pCode[j]->GetType() ) + { + case svDoubleRef : + { + if (!SkipReference(static_cast<ScToken*>(pCode[j]), rOldPos, pOldDoc, false)) + continue; + + ScComplexRefData& rRef = static_cast<ScToken*>(pCode[j])->GetDoubleRef(); + ScSingleRefData& rRef2 = rRef.Ref2; + ScSingleRefData& rRef1 = rRef.Ref1; + + AdjustSingleRefData( rRef1, rOldPos, rNewPos ); + AdjustSingleRefData( rRef2, rOldPos, rNewPos ); + + } + break; + case svSingleRef : + { + if (!SkipReference(static_cast<ScToken*>(pCode[j]), rOldPos, pOldDoc, false)) + continue; + + ScSingleRefData& rRef = static_cast<ScToken*>(pCode[j])->GetSingleRef(); + + AdjustSingleRefData( rRef, rOldPos, rNewPos ); + + + } + break; + default: + { + // added to avoid warnings + } + } + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |