diff options
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/tokenarray.hxx | 6 | ||||
-rw-r--r-- | sc/source/core/data/column4.cxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/table3.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/tool/token.cxx | 43 |
4 files changed, 55 insertions, 0 deletions
diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx index 84f43128516f..07f344b5bfce 100644 --- a/sc/inc/tokenarray.hxx +++ b/sc/inc/tokenarray.hxx @@ -206,6 +206,12 @@ public: void AdjustReferenceOnMovedOrigin( const ScAddress& rOldPos, const ScAddress& rNewPos ); /** + * Adjust all internal references on base position change if they point to + * a sheet other than the one of rOldPos. + */ + void AdjustReferenceOnMovedOriginIfOtherSheet( const ScAddress& rOldPos, const ScAddress& rNewPos ); + + /** * Clear sheet deleted flag from internal reference tokens if the sheet * index falls within specified range. Note that when a reference is on a * sheet that's been deleted, its referenced sheet index retains the diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx index 777f5a4666c7..42d166a0e7c0 100644 --- a/sc/source/core/data/column4.cxx +++ b/sc/source/core/data/column4.cxx @@ -1023,6 +1023,8 @@ public: pCell->aPos.SetRow(nRow); if (mbUpdateRefs) pCell->GetCode()->AdjustReferenceOnMovedOrigin(aOldPos, pCell->aPos); + else + pCell->GetCode()->AdjustReferenceOnMovedOriginIfOtherSheet(aOldPos, pCell->aPos); } else { diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx index 1111160d4314..227dfab8b5b9 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -868,6 +868,10 @@ void ScTable::SortReorderByRow( pNew->CopyAllBroadcasters(*rCell.maCell.mpFormula); pNew->GetCode()->AdjustReferenceOnMovedOrigin(aOldPos, aCellPos); } + else + { + pNew->GetCode()->AdjustReferenceOnMovedOriginIfOtherSheet(aOldPos, aCellPos); + } rCellStore.push_back(pNew); } diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index f0030f69826c..77f7cc2f8583 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -3426,6 +3426,49 @@ void ScTokenArray::AdjustReferenceOnMovedOrigin( const ScAddress& rOldPos, const } } +void ScTokenArray::AdjustReferenceOnMovedOriginIfOtherSheet( const ScAddress& rOldPos, const ScAddress& rNewPos ) +{ + FormulaToken** p = pCode; + FormulaToken** pEnd = p + static_cast<size_t>(nLen); + for (; p != pEnd; ++p) + { + bool bAdjust = false; + switch ((*p)->GetType()) + { + case svExternalSingleRef: + bAdjust = true; // always + // fallthru + case svSingleRef: + { + formula::FormulaToken* pToken = *p; + ScSingleRefData& rRef = *pToken->GetSingleRef(); + ScAddress aAbs = rRef.toAbs(rOldPos); + if (!bAdjust) + bAdjust = (aAbs.Tab() != rOldPos.Tab()); + if (bAdjust) + rRef.SetAddress(aAbs, rNewPos); + } + break; + case svExternalDoubleRef: + bAdjust = true; // always + // fallthru + case svDoubleRef: + { + formula::FormulaToken* pToken = *p; + ScComplexRefData& rRef = *pToken->GetDoubleRef(); + ScRange aAbs = rRef.toAbs(rOldPos); + if (!bAdjust) + bAdjust = (rOldPos.Tab() < aAbs.aStart.Tab() || aAbs.aEnd.Tab() < rOldPos.Tab()); + if (bAdjust) + rRef.SetRange(aAbs, rNewPos); + } + break; + default: + ; + } + } +} + namespace { void clearTabDeletedFlag( ScSingleRefData& rRef, const ScAddress& rPos, SCTAB nStartTab, SCTAB nEndTab ) |