sc/inc/column.hxx | 3 +- sc/inc/formulacell.hxx | 3 +- sc/inc/rangenam.hxx | 7 ++-- sc/inc/refupdatecontext.hxx | 9 ++++++ sc/inc/table.hxx | 4 +- sc/inc/tokenarray.hxx | 3 +- sc/source/core/data/colorscale.cxx | 3 +- sc/source/core/data/column.cxx | 14 ++++----- sc/source/core/data/conditio.cxx | 5 ++- sc/source/core/data/documen2.cxx | 18 +++++++----- sc/source/core/data/formulacell.cxx | 7 +++- sc/source/core/data/refupdatecontext.cxx | 3 ++ sc/source/core/data/table1.cxx | 44 ++++++++++++++++--------------- sc/source/core/tool/rangenam.cxx | 29 ++++++-------------- sc/source/core/tool/token.cxx | 44 +++++++++++++++++++++++-------- 15 files changed, 115 insertions(+), 81 deletions(-)
New commits: commit 8083253443099269469c7070fd617bef67585e62 Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Tue Jul 30 11:45:37 2013 -0400 Adjust named range references on sheet move. Change-Id: I3b20f79d9c2f373c93a34ccdb308c6d5c09f69e7 diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 88b1266..a42ac8f 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -50,6 +50,7 @@ namespace sc { struct RefUpdateContext; struct RefUpdateInsertTabContext; struct RefUpdateDeleteTabContext; + struct RefUpdateMoveTabContext; } class Fraction; @@ -327,7 +328,7 @@ public: void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ); void UpdateInsertTabOnlyCells( sc::RefUpdateInsertTabContext& rCxt ); void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ); - void UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo); + void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nTabNo ); void UpdateCompile( bool bForceIfNameInUse = false ); void UpdateTranspose( const ScRange& rSource, const ScAddress& rDest, ScDocument* pUndoDoc ); diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx index 28dbde5..1213959 100644 --- a/sc/inc/formulacell.hxx +++ b/sc/inc/formulacell.hxx @@ -35,6 +35,7 @@ class EndListeningContext; struct RefUpdateContext; struct RefUpdateInsertTabContext; struct RefUpdateDeleteTabContext; +struct RefUpdateMoveTabContext; } @@ -214,7 +215,7 @@ public: void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ); void UpdateInsertTabAbs(SCTAB nTable); bool UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ); - void UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo); + void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nTabNo ); void UpdateRenameTab(SCTAB nTable, const OUString& rName); bool TestTabRefAbs(SCTAB nTable); void UpdateCompile( bool bForceIfNameInUse = false ); diff --git a/sc/inc/rangenam.hxx b/sc/inc/rangenam.hxx index d18c0a7..4a56ea1 100644 --- a/sc/inc/rangenam.hxx +++ b/sc/inc/rangenam.hxx @@ -37,6 +37,7 @@ namespace sc { struct RefUpdateContext; struct RefUpdateInsertTabContext; struct RefUpdateDeleteTabContext; + struct RefUpdateMoveTabContext; } typedef sal_uInt16 RangeType; @@ -75,8 +76,6 @@ private: void InitCode(); public: - enum TabRefUpdateMode { Insert = 1, Delete = 2, Move = 3 }; - typedef ::std::map<sal_uInt16, sal_uInt16> IndexMap; SC_DLLPUBLIC ScRangeData( ScDocument* pDoc, @@ -142,9 +141,9 @@ public: SC_DLLPUBLIC bool IsValidReference( ScRange& rRef ) const; bool IsRangeAtBlock( const ScRange& ) const; - void UpdateTabRef(SCTAB nOldTable, TabRefUpdateMode eMode, SCTAB nNewTable, SCTAB nNewSheets); void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt, SCTAB nLocalTab = -1 ); void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt, SCTAB nLocalTab = -1 ); + void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nLocalTab = -1 ); void ValidateTabRefs(); @@ -195,7 +194,7 @@ public: void UpdateReference( sc::RefUpdateContext& rCxt, SCTAB nLocalTab = -1 ); void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt, SCTAB nLocalTab = -1 ); void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt, SCTAB nLocalTab = -1 ); - void UpdateTabRef(SCTAB nTable, ScRangeData::TabRefUpdateMode eMode, SCTAB nNewTable = 0, SCTAB nNewSheets = 1); + void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nLocalTab = -1 ); void UpdateTranspose(const ScRange& rSource, const ScAddress& rDest); void UpdateGrow(const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY); diff --git a/sc/inc/refupdatecontext.hxx b/sc/inc/refupdatecontext.hxx index 88ef9d2..380bc84 100644 --- a/sc/inc/refupdatecontext.hxx +++ b/sc/inc/refupdatecontext.hxx @@ -101,6 +101,15 @@ struct RefUpdateDeleteTabContext RefUpdateDeleteTabContext(SCTAB nInsertPos, SCTAB nSheets); }; +struct RefUpdateMoveTabContext +{ + SCTAB mnOldPos; + SCTAB mnNewPos; + UpdatedRangeNames maUpdatedNames; + + RefUpdateMoveTabContext(SCTAB nOldPos, SCTAB nNewPos); +}; + } #endif diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 63b8b73..37c1430 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -62,6 +62,7 @@ namespace sc { struct RefUpdateContext; struct RefUpdateInsertTabContext; struct RefUpdateDeleteTabContext; + struct RefUpdateMoveTabContext; } class SfxItemSet; @@ -518,7 +519,7 @@ public: void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ); void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ); - void UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo, ScProgress* pProgress ); + void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nTabNo, ScProgress* pProgress ); void UpdateCompile( bool bForceIfNameInUse = false ); void SetTabNo(SCTAB nNewTab); void FindRangeNamesInUse(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, @@ -828,7 +829,6 @@ public: void SetRangeName(ScRangeName* pNew); ScRangeName* GetRangeName() const; - void UpdateMoveTab(SCTAB nOldPos,SCTAB nNewPos); ScConditionalFormatList* GetCondFormList(); const ScConditionalFormatList* GetCondFormList() const; diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx index 0042544..f9a4ff1 100644 --- a/sc/inc/tokenarray.hxx +++ b/sc/inc/tokenarray.hxx @@ -32,6 +32,7 @@ namespace sc { struct RefUpdateContext; struct RefUpdateInsertTabContext; struct RefUpdateDeleteTabContext; +struct RefUpdateMoveTabContext; struct RefUpdateResult; } @@ -157,7 +158,7 @@ public: sc::RefUpdateResult AdjustReferenceOnInsertedTab( sc::RefUpdateInsertTabContext& rCxt, const ScAddress& rOldPos ); - void AdjustReferenceOnMovedTab( SCTAB nOldPos, SCTAB nNewPos, const ScAddress& rOldPos ); + sc::RefUpdateResult AdjustReferenceOnMovedTab( sc::RefUpdateMoveTabContext& rCxt, const ScAddress& rOldPos ); #if DEBUG_FORMULA_COMPILER void Dump() const; diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx index a1f440c..a0add6d 100644 --- a/sc/source/core/data/colorscale.cxx +++ b/sc/source/core/data/colorscale.cxx @@ -239,7 +239,8 @@ void ScColorScaleEntry::UpdateMoveTab( SCTAB nOldTab, SCTAB nNewTab, SCTAB nTabN { if(mpCell) { - mpCell->UpdateMoveTab( nOldTab, nNewTab, nTabNo ); + sc::RefUpdateMoveTabContext aCxt(nOldTab, nNewTab); + mpCell->UpdateMoveTab(aCxt, nTabNo); mpListener.reset(new ScFormulaListener(mpCell.get())); } } diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index 0de5c99..2d08247 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -2504,24 +2504,22 @@ public: class MoveTabUpdater { + sc::RefUpdateMoveTabContext& mrCxt; sc::CellTextAttrStoreType& mrTextAttrs; sc::CellTextAttrStoreType::iterator miAttrPos; SCTAB mnTab; - SCTAB mnOldPos; - SCTAB mnNewPos; bool mbModified; public: - MoveTabUpdater(sc::CellTextAttrStoreType& rTextAttrs, SCTAB nTab, SCTAB nOldPos, SCTAB nNewPos) : + MoveTabUpdater(sc::RefUpdateMoveTabContext& rCxt, sc::CellTextAttrStoreType& rTextAttrs, SCTAB nTab) : + mrCxt(rCxt), mrTextAttrs(rTextAttrs), miAttrPos(rTextAttrs.begin()), mnTab(nTab), - mnOldPos(nOldPos), - mnNewPos(nNewPos), mbModified(false) {} void operator() (size_t /*nRow*/, ScFormulaCell* pCell) { - pCell->UpdateMoveTab(mnOldPos, mnNewPos, mnTab); + pCell->UpdateMoveTab(mrCxt, mnTab); mbModified = true; } @@ -2912,12 +2910,12 @@ void ScColumn::UpdateInsertTabAbs(SCTAB nNewPos) CellStorageModified(); } -void ScColumn::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo ) +void ScColumn::UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nTabNo ) { nTab = nTabNo; pAttrArray->SetTab( nTabNo ); - MoveTabUpdater aFunc(maCellTextAttrs, nTab, nOldPos, nNewPos); + MoveTabUpdater aFunc(rCxt, maCellTextAttrs, nTab); sc::ProcessFormulaEditText(maCells, aFunc); if (aFunc.isModified()) CellStorageModified(); diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx index 3baae95..f2414c1 100644 --- a/sc/source/core/data/conditio.cxx +++ b/sc/source/core/data/conditio.cxx @@ -592,15 +592,16 @@ void ScConditionEntry::UpdateReference( UpdateRefMode eUpdateRefMode, void ScConditionEntry::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos ) { + sc::RefUpdateMoveTabContext aCxt(nOldPos, nNewPos); if (pFormula1) { - pFormula1->AdjustReferenceOnMovedTab(nOldPos, nNewPos, aSrcPos); + pFormula1->AdjustReferenceOnMovedTab(aCxt, aSrcPos); DELETEZ(pFCell1); } if (pFormula2) { - pFormula2->AdjustReferenceOnMovedTab(nOldPos, nNewPos, aSrcPos); + pFormula2->AdjustReferenceOnMovedTab(aCxt, aSrcPos); DELETEZ(pFCell2); } } diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx index 3179eff..1402e1d 100644 --- a/sc/source/core/data/documen2.cxx +++ b/sc/source/core/data/documen2.cxx @@ -87,6 +87,7 @@ #include "formulacell.hxx" #include "clipcontext.hxx" #include "refupdatecontext.hxx" +#include "scopetools.hxx" using namespace com::sun::star; @@ -700,8 +701,8 @@ bool ScDocument::MoveTab( SCTAB nOldPos, SCTAB nNewPos, ScProgress* pProgress ) { if (maTabs[nOldPos]) { - bool bOldAutoCalc = GetAutoCalc(); - SetAutoCalc( false ); // Mehrfachberechnungen vermeiden + sc::AutoCalcSwitch aACSwitch(*this, false); + SetNoListening( true ); if (nNewPos == SC_TAB_APPEND || nNewPos >= nTabCount) nNewPos = nTabCount-1; @@ -709,10 +710,13 @@ bool ScDocument::MoveTab( SCTAB nOldPos, SCTAB nNewPos, ScProgress* pProgress ) // Referenz-Updaterei //! mit UpdateReference zusammenfassen! + sc::RefUpdateMoveTabContext aCxt(nOldPos, nNewPos); + SCsTAB nDz = ((SCsTAB)nNewPos) - (SCsTAB)nOldPos; ScRange aSourceRange( 0,0,nOldPos, MAXCOL,MAXROW,nOldPos ); if (pRangeName) - pRangeName->UpdateTabRef(nOldPos, ScRangeData::Move, nNewPos); + pRangeName->UpdateMoveTab(aCxt); + pDBCollection->UpdateMoveTab( nOldPos, nNewPos ); xColNameRanges->UpdateReference( URM_REORDER, this, aSourceRange, 0,0,nDz ); xRowNameRanges->UpdateReference( URM_REORDER, this, aSourceRange, 0,0,nDz ); @@ -735,7 +739,7 @@ bool ScDocument::MoveTab( SCTAB nOldPos, SCTAB nNewPos, ScProgress* pProgress ) TableContainer::iterator it = maTabs.begin(); for (SCTAB i = 0; i < nTabCount; i++) if (maTabs[i]) - maTabs[i]->UpdateMoveTab( nOldPos, nNewPos, i, pProgress ); + maTabs[i]->UpdateMoveTab(aCxt, i, pProgress); it = maTabs.begin(); for (; it != maTabs.end(); ++it) if (*it) @@ -748,7 +752,6 @@ bool ScDocument::MoveTab( SCTAB nOldPos, SCTAB nNewPos, ScProgress* pProgress ) // sheet names of references may not be valid until sheet is moved pChartListenerCollection->UpdateScheduledSeriesRanges(); SetDirty(); - SetAutoCalc( bOldAutoCalc ); if (pDrawLayer) DrawMovePage( static_cast<sal_uInt16>(nOldPos), static_cast<sal_uInt16>(nNewPos) ); @@ -795,11 +798,13 @@ bool ScDocument::CopyTab( SCTAB nOldPos, SCTAB nNewPos, const ScMarkData* pOnlyM { SetNoListening( true ); + sc::RefUpdateInsertTabContext aCxt(nNewPos, 1); ScRange aRange( 0,0,nNewPos, MAXCOL,MAXROW,MAXTAB ); xColNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,1 ); xRowNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,1 ); if (pRangeName) - pRangeName->UpdateTabRef(nNewPos, ScRangeData::Insert); + pRangeName->UpdateInsertTab(aCxt); + pDBCollection->UpdateReference( URM_INSDEL, 0,0,nNewPos, MAXCOL,MAXROW,MAXTAB, 0,0,1 ); if (pDPCollection) @@ -812,7 +817,6 @@ bool ScDocument::CopyTab( SCTAB nOldPos, SCTAB nNewPos, const ScMarkData* pOnlyM pUnoBroadcaster->Broadcast( ScUpdateRefHint( URM_INSDEL, aRange, 0,0,1 ) ); SCTAB i; - sc::RefUpdateInsertTabContext aCxt(nNewPos, 1); for (TableContainer::iterator it = maTabs.begin(); it != maTabs.end(); ++it) if (*it && it != (maTabs.begin() + nOldPos)) (*it)->UpdateInsertTab(aCxt); diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index d2ddbc1..baec27d 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -2607,7 +2607,7 @@ bool ScFormulaCell::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) return aRes.mbReferenceModified; } -void ScFormulaCell::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo ) +void ScFormulaCell::UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nTabNo ) { pCode->Reset(); if (!pCode->GetNextReferenceRPN() || pDocument->IsClipOrUndo()) @@ -2622,7 +2622,10 @@ void ScFormulaCell::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo ) aPos.SetTab(nTabNo); // no StartListeningTo because pTab[nTab] not yet correct! - pCode->AdjustReferenceOnMovedTab(nOldPos, nNewPos, aOldPos); + sc::RefUpdateResult aRes = pCode->AdjustReferenceOnMovedTab(rCxt, aOldPos); + if (aRes.mbNameModified) + // Re-compile after sheet(s) have been deleted. + bCompile = true; } void ScFormulaCell::UpdateInsertTabAbs(SCTAB nTable) diff --git a/sc/source/core/data/refupdatecontext.cxx b/sc/source/core/data/refupdatecontext.cxx index e23128e..73ec40c 100644 --- a/sc/source/core/data/refupdatecontext.cxx +++ b/sc/source/core/data/refupdatecontext.cxx @@ -67,6 +67,9 @@ RefUpdateInsertTabContext::RefUpdateInsertTabContext(SCTAB nInsertPos, SCTAB nSh RefUpdateDeleteTabContext::RefUpdateDeleteTabContext(SCTAB nDeletePos, SCTAB nSheets) : mnDeletePos(nDeletePos), mnSheets(nSheets) {} +RefUpdateMoveTabContext::RefUpdateMoveTabContext(SCTAB nOldPos, SCTAB nNewPos) : + mnOldPos(nOldPos), mnNewPos(nNewPos) {} + } diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx index 74eb46c..11cd113 100644 --- a/sc/source/core/data/table1.cxx +++ b/sc/source/core/data/table1.cxx @@ -1588,20 +1588,21 @@ void ScTable::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) if (pDBDataNoName) pDBDataNoName->UpdateMoveTab(nTab - 1 ,nTab); } - for (SCCOL i=0; i <= MAXCOL; i++) aCol[i].UpdateInsertTab(rCxt); if (mpRangeName) mpRangeName->UpdateInsertTab(rCxt, nTab); - if (IsStreamValid()) - SetStreamValid(false); - if (mpCondFormatList) { mpCondFormatList->UpdateReference( URM_INSDEL, ScRange(0, 0, rCxt.mnInsertPos, MAXCOL, MAXROW, rCxt.mnInsertPos+rCxt.mnSheets-1), 0, 0, rCxt.mnSheets); } + + for (SCCOL i=0; i <= MAXCOL; i++) aCol[i].UpdateInsertTab(rCxt); + + if (IsStreamValid()) + SetStreamValid(false); } void ScTable::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) @@ -1613,44 +1614,45 @@ void ScTable::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) pDBDataNoName->UpdateMoveTab(nTab + 1,nTab); } - for (SCCOL i = 0; i <= MAXCOL; ++i) - aCol[i].UpdateDeleteTab(rCxt); - if (mpRangeName) mpRangeName->UpdateDeleteTab(rCxt, nTab); - if (IsStreamValid()) - SetStreamValid(false); - if (mpCondFormatList) { mpCondFormatList->UpdateReference( URM_INSDEL, ScRange(0,0, rCxt.mnDeletePos, MAXCOL, MAXROW, rCxt.mnDeletePos+rCxt.mnSheets-1), 0, 0, -1*rCxt.mnSheets); } + + for (SCCOL i = 0; i <= MAXCOL; ++i) + aCol[i].UpdateDeleteTab(rCxt); + + if (IsStreamValid()) + SetStreamValid(false); } -void ScTable::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo, - ScProgress* pProgress ) +void ScTable::UpdateMoveTab( + sc::RefUpdateMoveTabContext& rCxt, SCTAB nTabNo, ScProgress* pProgress ) { nTab = nTabNo; + if (mpRangeName) + mpRangeName->UpdateMoveTab(rCxt, nTab); + + if (pDBDataNoName) + pDBDataNoName->UpdateMoveTab(rCxt.mnOldPos, rCxt.mnNewPos); + + if(mpCondFormatList) + mpCondFormatList->UpdateMoveTab(rCxt.mnOldPos, rCxt.mnNewPos); + for ( SCCOL i=0; i <= MAXCOL; i++ ) { - aCol[i].UpdateMoveTab( nOldPos, nNewPos, nTabNo ); + aCol[i].UpdateMoveTab(rCxt, nTabNo); if (pProgress) pProgress->SetState(pProgress->GetState() + aCol[i].GetCodeCount()); } - if (mpRangeName) - mpRangeName->UpdateTabRef(nOldPos, ScRangeData::Move, nNewPos); - if (IsStreamValid()) SetStreamValid(false); - if (pDBDataNoName) - pDBDataNoName->UpdateMoveTab(nOldPos, nNewPos); - - if(mpCondFormatList) - mpCondFormatList->UpdateMoveTab(nOldPos, nNewPos); } void ScTable::UpdateCompile( bool bForceIfNameInUse ) diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx index 273bc03..aae97ed 100644 --- a/sc/source/core/tool/rangenam.cxx +++ b/sc/source/core/tool/rangenam.cxx @@ -397,24 +397,6 @@ bool ScRangeData::IsValidReference( ScRange& rRange ) const return false; } -void ScRangeData::UpdateTabRef(SCTAB nOldTable, TabRefUpdateMode eMode, SCTAB nNewTable, SCTAB nNewSheets) -{ - pCode->Reset(); - if (!pCode->GetNextReference()) - return; - - switch (eMode) - { - case Move: - pCode->AdjustReferenceOnMovedTab(nOldTable, nNewTable, aPos); - break; - default: - { - OSL_FAIL("ScRangeName::UpdateTabRef: Unknown Flag"); - } - } -} - void ScRangeData::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt, SCTAB nLocalTab ) { sc::RefUpdateResult aRes = pCode->AdjustReferenceOnInsertedTab(rCxt, aPos); @@ -429,6 +411,13 @@ void ScRangeData::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt, SCTAB nL rCxt.maUpdatedNames.setUpdatedName(nLocalTab, nIndex); } +void ScRangeData::UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nLocalTab ) +{ + sc::RefUpdateResult aRes = pCode->AdjustReferenceOnMovedTab(rCxt, aPos); + if (aRes.mbReferenceModified) + rCxt.maUpdatedNames.setUpdatedName(nLocalTab, nIndex); +} + void ScRangeData::MakeValidName( String& rName ) { @@ -742,11 +731,11 @@ void ScRangeName::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt, SCTAB nL itr->second->UpdateDeleteTab(rCxt, nLocalTab); } -void ScRangeName::UpdateTabRef(SCTAB nTable, ScRangeData::TabRefUpdateMode eMode, SCTAB nNewTable, SCTAB nNewSheets) +void ScRangeName::UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nLocalTab ) { DataType::iterator itr = maData.begin(), itrEnd = maData.end(); for (; itr != itrEnd; ++itr) - itr->second->UpdateTabRef(nTable, eMode, nNewTable, nNewSheets); + itr->second->UpdateMoveTab(rCxt, nLocalTab); } void ScRangeName::UpdateTranspose(const ScRange& rSource, const ScAddress& rDest) diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index cb0d4f9..806c05e 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -2794,7 +2794,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnInsertedTab( sc::RefUpdateIns namespace { -void adjustTabOnMove( ScAddress& rPos, SCTAB nOldPos, SCTAB nNewPos ) +bool adjustTabOnMove( ScAddress& rPos, SCTAB nOldPos, SCTAB nNewPos ) { // Sheets below the lower bound or above the uppper bound will not change. SCTAB nLowerBound = std::min(nOldPos, nNewPos); @@ -2802,12 +2802,12 @@ void adjustTabOnMove( ScAddress& rPos, SCTAB nOldPos, SCTAB nNewPos ) if (rPos.Tab() < nLowerBound || nUpperBound < rPos.Tab()) // Outside the boundary. Nothing to adjust. - return; + return false; if (rPos.Tab() == nOldPos) { rPos.SetTab(nNewPos); - return; + return true; } // It's somewhere in between. @@ -2821,17 +2821,20 @@ void adjustTabOnMove( ScAddress& rPos, SCTAB nOldPos, SCTAB nNewPos ) // Moving a sheet to the left. The rest of the sheets shifts to the right. rPos.IncTab(); } + return true; } } -void ScTokenArray::AdjustReferenceOnMovedTab( SCTAB nOldPos, SCTAB nNewPos, const ScAddress& rOldPos ) +sc::RefUpdateResult ScTokenArray::AdjustReferenceOnMovedTab( sc::RefUpdateMoveTabContext& rCxt, const ScAddress& rOldPos ) { - if (nOldPos == nNewPos) - return; + sc::RefUpdateResult aRes; + if (rCxt.mnOldPos == rCxt.mnNewPos) + return aRes; ScAddress aNewPos = rOldPos; - adjustTabOnMove(aNewPos, nOldPos, nNewPos); + if (adjustTabOnMove(aNewPos, rCxt.mnOldPos, rCxt.mnNewPos)) + aRes.mbReferenceModified = true; FormulaToken** p = pCode; FormulaToken** pEnd = p + static_cast<size_t>(nLen); @@ -2844,9 +2847,9 @@ void ScTokenArray::AdjustReferenceOnMovedTab( SCTAB nOldPos, SCTAB nNewPos, cons ScToken* pToken = static_cast<ScToken*>(*p); ScSingleRefData& rRef = pToken->GetSingleRef(); ScAddress aAbs = rRef.toAbs(rOldPos); - adjustTabOnMove(aAbs, nOldPos, nNewPos); + if (adjustTabOnMove(aAbs, rCxt.mnOldPos, rCxt.mnNewPos)) + aRes.mbReferenceModified = true; rRef.SetAddress(aAbs, aNewPos); - } break; case svDoubleRef: @@ -2854,15 +2857,34 @@ void ScTokenArray::AdjustReferenceOnMovedTab( SCTAB nOldPos, SCTAB nNewPos, cons ScToken* pToken = static_cast<ScToken*>(*p); ScComplexRefData& rRef = pToken->GetDoubleRef(); ScRange aAbs = rRef.toAbs(rOldPos); - adjustTabOnMove(aAbs.aStart, nOldPos, nNewPos); - adjustTabOnMove(aAbs.aEnd, nOldPos, nNewPos); + if (adjustTabOnMove(aAbs.aStart, rCxt.mnOldPos, rCxt.mnNewPos)) + aRes.mbReferenceModified = true; + if (adjustTabOnMove(aAbs.aEnd, rCxt.mnOldPos, rCxt.mnNewPos)) + aRes.mbReferenceModified = true; rRef.SetRange(aAbs, aNewPos); } break; + case svIndex: + { + const formula::FormulaToken* pToken = *p; + if (pToken->GetOpCode() == ocName) + { + SCTAB nTab = -1; + if (!pToken->IsGlobal()) + nTab = rOldPos.Tab(); + + // Check if this named expression has been modified. + if (rCxt.maUpdatedNames.isNameUpdated(nTab, pToken->GetIndex())) + aRes.mbNameModified = true; + } + } + break; default: ; } } + + return aRes; } #if DEBUG_FORMULA_COMPILER _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits