diff options
-rw-r--r-- | sc/inc/column.hxx | 5 | ||||
-rw-r--r-- | sc/inc/formulacell.hxx | 3 | ||||
-rw-r--r-- | sc/inc/rangenam.hxx | 3 | ||||
-rw-r--r-- | sc/inc/refupdatecontext.hxx | 35 | ||||
-rw-r--r-- | sc/inc/table.hxx | 3 | ||||
-rw-r--r-- | sc/inc/tokenarray.hxx | 3 | ||||
-rw-r--r-- | sc/qa/unit/ucalc_formula.cxx | 10 | ||||
-rw-r--r-- | sc/source/core/data/column.cxx | 20 | ||||
-rw-r--r-- | sc/source/core/data/documen2.cxx | 8 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 11 | ||||
-rw-r--r-- | sc/source/core/data/formulacell.cxx | 14 | ||||
-rw-r--r-- | sc/source/core/data/refupdatecontext.cxx | 33 | ||||
-rw-r--r-- | sc/source/core/data/table1.cxx | 21 | ||||
-rw-r--r-- | sc/source/core/tool/rangenam.cxx | 20 | ||||
-rw-r--r-- | sc/source/core/tool/token.cxx | 38 |
15 files changed, 150 insertions, 77 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 9850840ef30d..03d05e10a5af 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -48,6 +48,7 @@ namespace sc { struct ColumnBlockPosition; class SingleColumnSpanSet; struct RefUpdateContext; + struct RefUpdateInsertTabContext; } class Fraction; @@ -322,8 +323,8 @@ public: */ bool UpdateReference( const sc::RefUpdateContext& rCxt, ScDocument* pUndoDoc = NULL ); - void UpdateInsertTab(SCTAB nInsPos, SCTAB nNewSheets = 1); - void UpdateInsertTabOnlyCells(SCTAB nInsPos, SCTAB nNewSheets = 1); + void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ); + void UpdateInsertTabOnlyCells( sc::RefUpdateInsertTabContext& rCxt ); void UpdateDeleteTab(SCTAB nDelPos, SCTAB nSheets = 1); void UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo); void UpdateCompile( bool bForceIfNameInUse = false ); diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx index d19c01cbbe97..4c41305f8931 100644 --- a/sc/inc/formulacell.hxx +++ b/sc/inc/formulacell.hxx @@ -33,6 +33,7 @@ namespace sc { class StartListeningContext; class EndListeningContext; struct RefUpdateContext; +struct RefUpdateInsertTabContext; } @@ -209,7 +210,7 @@ public: void UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY ); - void UpdateInsertTab(SCTAB nTable, SCTAB nNewSheets = 1); + void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ); void UpdateInsertTabAbs(SCTAB nTable); bool UpdateDeleteTab(SCTAB nTable, SCTAB nSheets = 1); void UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo); diff --git a/sc/inc/rangenam.hxx b/sc/inc/rangenam.hxx index a040a6b96880..cceb4d6c9b7d 100644 --- a/sc/inc/rangenam.hxx +++ b/sc/inc/rangenam.hxx @@ -35,6 +35,7 @@ class ScTokenArray; namespace sc { struct RefUpdateContext; + struct RefUpdateInsertTabContext; } typedef sal_uInt16 RangeType; @@ -141,6 +142,7 @@ public: bool IsRangeAtBlock( const ScRange& ) const; void UpdateTabRef(SCTAB nOldTable, TabRefUpdateMode eMode, SCTAB nNewTable, SCTAB nNewSheets); + void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt, SCTAB nLocalTab = -1 ); void ValidateTabRefs(); @@ -189,6 +191,7 @@ public: SC_DLLPUBLIC const ScRangeData* findByUpperName(const OUString& rName) const; SC_DLLPUBLIC ScRangeData* findByIndex(sal_uInt16 i) const; void UpdateReference( sc::RefUpdateContext& rCxt, SCTAB nLocalTab = -1 ); + void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt, SCTAB nLocalTab = -1 ); void UpdateTabRef(SCTAB nTable, ScRangeData::TabRefUpdateMode eMode, SCTAB nNewTable = 0, SCTAB nNewSheets = 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 6bb4e73aa2d4..036ee9a7789d 100644 --- a/sc/inc/refupdatecontext.hxx +++ b/sc/inc/refupdatecontext.hxx @@ -20,11 +20,28 @@ class ScDocument; namespace sc { -struct RefUpdateContext +/** + * Keep track of all named expressions that have been updated during + * reference update. + */ +class UpdatedRangeNames { typedef boost::unordered_set<sal_uInt16> NameIndicesType; typedef boost::unordered_map<SCTAB, NameIndicesType> UpdatedNamesType; + UpdatedNamesType maUpdatedNames; + +public: + void setUpdatedName(SCTAB nTab, sal_uInt16 nIndex); + bool isNameUpdated(SCTAB nTab, sal_uInt16 nIndex) const; +}; + +/** + * Context for reference update during shifting, moving or copying of cell + * ranges. + */ +struct RefUpdateContext +{ ScDocument& mrDoc; /** @@ -48,17 +65,12 @@ struct RefUpdateContext /** Amount and direction of movement in the sheet direction. */ SCTAB mnTabDelta; - /** All named expressions that have been updated during this reference - * update run. */ - UpdatedNamesType maUpdatedNames; + UpdatedRangeNames maUpdatedNames; RefUpdateContext(ScDocument& rDoc); bool isInserted() const; bool isDeleted() const; - - void setUpdatedName(SCTAB nTab, sal_uInt16 nIndex); - bool isNameUpdated(SCTAB nTab, sal_uInt16 nIndex) const; }; struct RefUpdateResult @@ -71,6 +83,15 @@ struct RefUpdateResult RefUpdateResult(const RefUpdateResult& r); }; +struct RefUpdateInsertTabContext +{ + SCTAB mnInsertPos; + SCTAB mnSheets; + UpdatedRangeNames maUpdatedNames; + + RefUpdateInsertTabContext(SCTAB nInsertPos, SCTAB nSheets); +}; + } #endif diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 14c68ec064aa..95b7febb9148 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -60,6 +60,7 @@ namespace sc { class ColumnSpanSet; struct ColumnBlockPosition; struct RefUpdateContext; + struct RefUpdateInsertTabContext; } class SfxItemSet; @@ -514,7 +515,7 @@ public: void UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY ); - void UpdateInsertTab(SCTAB nTable, SCTAB nNewSheets = 1); + void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ); void UpdateDeleteTab( SCTAB nTable, SCTAB nSheets = 1 ); void UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo, ScProgress* pProgress ); void UpdateCompile( bool bForceIfNameInUse = false ); diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx index 54bd2fb1e203..f2d59cea827e 100644 --- a/sc/inc/tokenarray.hxx +++ b/sc/inc/tokenarray.hxx @@ -30,6 +30,7 @@ namespace sc { struct RefUpdateContext; +struct RefUpdateInsertTabContext; struct RefUpdateResult; } @@ -153,7 +154,7 @@ public: */ bool AdjustReferenceOnDeletedTab( SCTAB nDelPos, SCTAB nSheets, const ScAddress& rOldPos ); - bool AdjustReferenceOnInsertedTab( SCTAB nInsPos, SCTAB nSheets, const ScAddress& rOldPos ); + sc::RefUpdateResult AdjustReferenceOnInsertedTab( sc::RefUpdateInsertTabContext& rCxt, const ScAddress& rOldPos ); void AdjustReferenceOnMovedTab( SCTAB nOldPos, SCTAB nNewPos, const ScAddress& rOldPos ); diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx index d082c19118be..1dba4538b687 100644 --- a/sc/qa/unit/ucalc_formula.cxx +++ b/sc/qa/unit/ucalc_formula.cxx @@ -1049,6 +1049,16 @@ void Test::testFormulaRefUpdateNamedExpression() m_pDoc->SetValue(ScAddress(3,9,0), 20); CPPUNIT_ASSERT_EQUAL(43.0, m_pDoc->GetValue(ScAddress(2,7,0))); + // Insert a new sheet before the current. + m_pDoc->InsertTab(0, "New"); + m_pDoc->CalcAll(); + OUString aName; + m_pDoc->GetName(1, aName); + CPPUNIT_ASSERT_EQUAL(OUString("Formula"), aName); + CPPUNIT_ASSERT_EQUAL(43.0, m_pDoc->GetValue(ScAddress(2,7,1))); + + m_pDoc->DeleteTab(0); + m_pDoc->DeleteTab(0); } diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index 94a08b1aeca0..504de753c35c 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -2403,6 +2403,7 @@ public: class InsertTabUpdater { + sc::RefUpdateInsertTabContext& mrCxt; sc::CellTextAttrStoreType& mrTextAttrs; sc::CellTextAttrStoreType::iterator miAttrPos; SCTAB mnTab; @@ -2411,17 +2412,16 @@ class InsertTabUpdater bool mbModified; public: - InsertTabUpdater(sc::CellTextAttrStoreType& rTextAttrs, SCTAB nTab, SCTAB nInsPos, SCTAB nNewSheets) : + InsertTabUpdater(sc::RefUpdateInsertTabContext& rCxt, sc::CellTextAttrStoreType& rTextAttrs, SCTAB nTab) : + mrCxt(rCxt), mrTextAttrs(rTextAttrs), miAttrPos(rTextAttrs.begin()), mnTab(nTab), - mnInsPos(nInsPos), - mnNewSheets(nNewSheets), mbModified(false) {} void operator() (size_t /*nRow*/, ScFormulaCell* pCell) { - pCell->UpdateInsertTab(mnInsPos, mnNewSheets); + pCell->UpdateInsertTab(mrCxt); mbModified = true; } @@ -2871,20 +2871,20 @@ void ScColumn::UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY ) } -void ScColumn::UpdateInsertTab(SCTAB nInsPos, SCTAB nNewSheets) +void ScColumn::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) { - if (nTab >= nInsPos) + if (nTab >= rCxt.mnInsertPos) { - nTab += nNewSheets; + nTab += rCxt.mnSheets; pAttrArray->SetTab(nTab); } - UpdateInsertTabOnlyCells(nInsPos, nNewSheets); + UpdateInsertTabOnlyCells(rCxt); } -void ScColumn::UpdateInsertTabOnlyCells(SCTAB nInsPos, SCTAB nNewSheets) +void ScColumn::UpdateInsertTabOnlyCells( sc::RefUpdateInsertTabContext& rCxt ) { - InsertTabUpdater aFunc(maCellTextAttrs, nTab, nInsPos, nNewSheets); + InsertTabUpdater aFunc(rCxt, maCellTextAttrs, nTab); sc::ProcessFormulaEditText(maCells, aFunc); if (aFunc.isModified()) CellStorageModified(); diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx index 72f912f2e6ed..3179eff2f583 100644 --- a/sc/source/core/data/documen2.cxx +++ b/sc/source/core/data/documen2.cxx @@ -812,9 +812,10 @@ 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(nNewPos); + (*it)->UpdateInsertTab(aCxt); maTabs.push_back(NULL); for (i = static_cast<SCTAB>(maTabs.size())-1; i > nNewPos; i--) maTabs[i] = maTabs[i - 1]; @@ -841,9 +842,9 @@ bool ScDocument::CopyTab( SCTAB nOldPos, SCTAB nNewPos, const ScMarkData* pOnlyM } if (bValid) { - sc::CopyToDocContext aCxt(*this); SetNoListening( true ); // noch nicht bei CopyToTable/Insert + sc::CopyToDocContext aCxt(*this); maTabs[nOldPos]->CopyToTable(aCxt, 0, 0, MAXCOL, MAXROW, IDF_ALL, (pOnlyMarked != NULL), maTabs[nNewPos], pOnlyMarked ); maTabs[nNewPos]->SetTabBgColor(maTabs[nOldPos]->GetTabBgColor()); @@ -855,8 +856,9 @@ bool ScDocument::CopyTab( SCTAB nOldPos, SCTAB nNewPos, const ScMarkData* pOnlyM aRefCxt.mnTabDelta = nDz; maTabs[nNewPos]->UpdateReference(aRefCxt, NULL); + sc::RefUpdateInsertTabContext aInsTabCxt(nNewPos, 1); maTabs[nNewPos]->UpdateInsertTabAbs(nNewPos); // alle abs. um eins hoch!! - maTabs[nOldPos]->UpdateInsertTab(nNewPos); + maTabs[nOldPos]->UpdateInsertTab(aInsTabCxt); maTabs[nOldPos]->UpdateCompile(); maTabs[nNewPos]->UpdateCompile( true ); // maybe already compiled in Clone, but used names need recompilation diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index eab8347e200b..90cadf72cf35 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -457,11 +457,13 @@ bool ScDocument::InsertTab( SCTAB nPos, const OUString& rName, { if (ValidTab(nPos) && (nPos < nTabCount)) { + sc::RefUpdateInsertTabContext aCxt(nPos, 1); + ScRange aRange( 0,0,nPos, 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(nPos, ScRangeData::Insert); + pRangeName->UpdateInsertTab(aCxt); pDBCollection->UpdateReference( URM_INSDEL, 0,0,nPos, MAXCOL,MAXROW,MAXTAB, 0,0,1 ); if (pDPCollection) @@ -477,7 +479,7 @@ bool ScDocument::InsertTab( SCTAB nPos, const OUString& rName, TableContainer::iterator it = maTabs.begin(); for (; it != maTabs.end(); ++it) if ( *it ) - (*it)->UpdateInsertTab(nPos); + (*it)->UpdateInsertTab(aCxt); maTabs.push_back(NULL); for (i = nTabCount; i > nPos; i--) { @@ -542,11 +544,12 @@ bool ScDocument::InsertTabs( SCTAB nPos, const std::vector<OUString>& rNames, { if (ValidTab(nPos) && (nPos < nTabCount)) { + sc::RefUpdateInsertTabContext aCxt(nPos, nNewSheets); ScRange aRange( 0,0,nPos, MAXCOL,MAXROW,MAXTAB ); xColNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,nNewSheets ); xRowNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,nNewSheets ); if (pRangeName) - pRangeName->UpdateTabRef(nPos, ScRangeData::Insert, 0, nNewSheets); + pRangeName->UpdateInsertTab(aCxt); pDBCollection->UpdateReference( URM_INSDEL, 0,0,nPos, MAXCOL,MAXROW,MAXTAB, 0,0,nNewSheets ); if (pDPCollection) @@ -561,7 +564,7 @@ bool ScDocument::InsertTabs( SCTAB nPos, const std::vector<OUString>& rNames, TableContainer::iterator it = maTabs.begin(); for (; it != maTabs.end(); ++it) if ( *it ) - (*it)->UpdateInsertTab(nPos, nNewSheets); + (*it)->UpdateInsertTab(aCxt); it = maTabs.begin(); maTabs.insert(it+nPos,nNewSheets, NULL); for (SCTAB i = 0; i < nNewSheets; ++i) diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index c6c567fad847..7dcfaaf5cc07 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -2556,14 +2556,14 @@ bool ScFormulaCell::UpdateReference( return false; } -void ScFormulaCell::UpdateInsertTab(SCTAB nTable, SCTAB nNewSheets) +void ScFormulaCell::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) { - bool bPosChanged = (nTable <= aPos.Tab()); + bool bPosChanged = (rCxt.mnInsertPos <= aPos.Tab()); pCode->Reset(); if (pDocument->IsClipOrUndo() || !pCode->GetNextReferenceRPN()) { if (bPosChanged) - aPos.IncTab(nNewSheets); + aPos.IncTab(rCxt.mnSheets); return; } @@ -2572,9 +2572,13 @@ void ScFormulaCell::UpdateInsertTab(SCTAB nTable, SCTAB nNewSheets) ScAddress aOldPos = aPos; // IncTab _after_ EndListeningTo and _before_ Compiler UpdateInsertTab! if (bPosChanged) - aPos.IncTab(nNewSheets); + aPos.IncTab(rCxt.mnSheets); + + sc::RefUpdateResult aRes = pCode->AdjustReferenceOnInsertedTab(rCxt, aOldPos); + if (aRes.mbNameModified) + // Re-compile after new sheet(s) have been inserted. + bCompile = true; - pCode->AdjustReferenceOnInsertedTab(nTable, nNewSheets, aOldPos); // no StartListeningTo because the new sheets have not been inserted yet. } diff --git a/sc/source/core/data/refupdatecontext.cxx b/sc/source/core/data/refupdatecontext.cxx index 25ffceb55b82..ff68ea8cc0ac 100644 --- a/sc/source/core/data/refupdatecontext.cxx +++ b/sc/source/core/data/refupdatecontext.cxx @@ -11,20 +11,7 @@ namespace sc { -RefUpdateContext::RefUpdateContext(ScDocument& rDoc) : - mrDoc(rDoc), meMode(URM_INSDEL), mnColDelta(0), mnRowDelta(0), mnTabDelta(0) {} - -bool RefUpdateContext::isInserted() const -{ - return (meMode == URM_INSDEL) && (mnColDelta > 0 || mnRowDelta > 0 || mnTabDelta > 0); -} - -bool RefUpdateContext::isDeleted() const -{ - return (meMode == URM_INSDEL) && (mnColDelta < 0 || mnRowDelta < 0 || mnTabDelta < 0); -} - -void RefUpdateContext::setUpdatedName(SCTAB nTab, sal_uInt16 nIndex) +void UpdatedRangeNames::setUpdatedName(SCTAB nTab, sal_uInt16 nIndex) { UpdatedNamesType::iterator it = maUpdatedNames.find(nTab); if (it == maUpdatedNames.end()) @@ -45,7 +32,7 @@ void RefUpdateContext::setUpdatedName(SCTAB nTab, sal_uInt16 nIndex) rIndices.insert(nIndex); } -bool RefUpdateContext::isNameUpdated(SCTAB nTab, sal_uInt16 nIndex) const +bool UpdatedRangeNames::isNameUpdated(SCTAB nTab, sal_uInt16 nIndex) const { UpdatedNamesType::const_iterator it = maUpdatedNames.find(nTab); if (it == maUpdatedNames.end()) @@ -55,12 +42,28 @@ bool RefUpdateContext::isNameUpdated(SCTAB nTab, sal_uInt16 nIndex) const return rIndices.count(nIndex) > 0; } +RefUpdateContext::RefUpdateContext(ScDocument& rDoc) : + mrDoc(rDoc), meMode(URM_INSDEL), mnColDelta(0), mnRowDelta(0), mnTabDelta(0) {} + +bool RefUpdateContext::isInserted() const +{ + return (meMode == URM_INSDEL) && (mnColDelta > 0 || mnRowDelta > 0 || mnTabDelta > 0); +} + +bool RefUpdateContext::isDeleted() const +{ + return (meMode == URM_INSDEL) && (mnColDelta < 0 || mnRowDelta < 0 || mnTabDelta < 0); +} + RefUpdateResult::RefUpdateResult() : mbValueChanged(false), mbReferenceModified(false), mbNameModified(false) {} RefUpdateResult::RefUpdateResult(const RefUpdateResult& r) : mbValueChanged(r.mbValueChanged), mbReferenceModified(r.mbReferenceModified), mbNameModified(r.mbNameModified) {} +RefUpdateInsertTabContext::RefUpdateInsertTabContext(SCTAB nInsertPos, SCTAB nSheets) : + mnInsertPos(nInsertPos), mnSheets(nSheets) {} + } diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx index f74c09f51709..ad2d17e35670 100644 --- a/sc/source/core/data/table1.cxx +++ b/sc/source/core/data/table1.cxx @@ -1580,27 +1580,28 @@ void ScTable::UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY ) aCol[i].UpdateGrow( rArea, nGrowX, nGrowY ); } -void ScTable::UpdateInsertTab(SCTAB nTable, SCTAB nNewSheets) +void ScTable::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) { - if (nTab >= nTable) + if (nTab >= rCxt.mnInsertPos) { - nTab += nNewSheets; + nTab += rCxt.mnSheets; if (pDBDataNoName) pDBDataNoName->UpdateMoveTab(nTab - 1 ,nTab); } - for (SCCOL i=0; i <= MAXCOL; i++) aCol[i].UpdateInsertTab(nTable, nNewSheets); + for (SCCOL i=0; i <= MAXCOL; i++) aCol[i].UpdateInsertTab(rCxt); if (mpRangeName) - { - mpRangeName->UpdateTabRef(nTable, ScRangeData::Insert, 0, nNewSheets); - mpRangeName->UpdateTabRef(nTable, ScRangeData::Insert); - } + mpRangeName->UpdateInsertTab(rCxt, nTab); if (IsStreamValid()) SetStreamValid(false); - if(mpCondFormatList) - mpCondFormatList->UpdateReference( URM_INSDEL, ScRange(0,0, nTable, MAXCOL, MAXROW, nTable+nNewSheets-1),0,0, nNewSheets); + if (mpCondFormatList) + { + mpCondFormatList->UpdateReference( + URM_INSDEL, ScRange(0, 0, rCxt.mnInsertPos, MAXCOL, MAXROW, rCxt.mnInsertPos+rCxt.mnSheets-1), + 0, 0, rCxt.mnSheets); + } } void ScTable::UpdateDeleteTab( SCTAB nTable, SCTAB nSheets ) diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx index 846a208c1062..6f2beca73f97 100644 --- a/sc/source/core/tool/rangenam.cxx +++ b/sc/source/core/tool/rangenam.cxx @@ -273,12 +273,10 @@ void ScRangeData::UpdateSymbol( OUStringBuffer& rBuffer, const ScAddress& rPos, void ScRangeData::UpdateReference( sc::RefUpdateContext& rCxt, SCTAB nLocalTab ) { - OUString aStr; - rCxt.maRange.Format(aStr, SCR_ABS_3D, pDoc); sc::RefUpdateResult aRes = pCode->AdjustReferenceInName(rCxt, aPos); bModified = aRes.mbReferenceModified; if (aRes.mbReferenceModified) - rCxt.setUpdatedName(nLocalTab, nIndex); + rCxt.maUpdatedNames.setUpdatedName(nLocalTab, nIndex); } void ScRangeData::UpdateTranspose( const ScRange& rSource, const ScAddress& rDest ) @@ -407,9 +405,6 @@ void ScRangeData::UpdateTabRef(SCTAB nOldTable, TabRefUpdateMode eMode, SCTAB nN switch (eMode) { - case Insert: - pCode->AdjustReferenceOnInsertedTab(nOldTable, nNewSheets, aPos); - break; case Delete: pCode->AdjustReferenceOnDeletedTab(nOldTable, nNewSheets, aPos); break; @@ -423,6 +418,12 @@ void ScRangeData::UpdateTabRef(SCTAB nOldTable, TabRefUpdateMode eMode, SCTAB nN } } +void ScRangeData::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt, SCTAB nLocalTab ) +{ + sc::RefUpdateResult aRes = pCode->AdjustReferenceOnInsertedTab(rCxt, aPos); + if (aRes.mbReferenceModified) + rCxt.maUpdatedNames.setUpdatedName(nLocalTab, nIndex); +} void ScRangeData::MakeValidName( String& rName ) { @@ -723,6 +724,13 @@ void ScRangeName::UpdateReference(sc::RefUpdateContext& rCxt, SCTAB nLocalTab ) itr->second->UpdateReference(rCxt, nLocalTab); } +void ScRangeName::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt, SCTAB nLocalTab ) +{ + DataType::iterator itr = maData.begin(), itrEnd = maData.end(); + for (; itr != itrEnd; ++itr) + itr->second->UpdateInsertTab(rCxt, nLocalTab); +} + void ScRangeName::UpdateTabRef(SCTAB nTable, ScRangeData::TabRefUpdateMode eMode, SCTAB nNewTable, SCTAB nNewSheets) { DataType::iterator itr = maData.begin(), itrEnd = maData.end(); diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index 469063c453b7..1a14bd597716 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -2481,7 +2481,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnShift( const sc::RefUpdateCon nTab = rOldPos.Tab(); // Check if this named expression has been modified. - if (rCxt.isNameUpdated(nTab, pToken->GetIndex())) + if (rCxt.maUpdatedNames.isNameUpdated(nTab, pToken->GetIndex())) aRes.mbNameModified = true; } } @@ -2724,12 +2724,12 @@ bool ScTokenArray::AdjustReferenceOnDeletedTab( SCTAB nDelPos, SCTAB nSheets, co return bRefChanged; } -bool ScTokenArray::AdjustReferenceOnInsertedTab( SCTAB nInsPos, SCTAB nSheets, const ScAddress& rOldPos ) +sc::RefUpdateResult ScTokenArray::AdjustReferenceOnInsertedTab( sc::RefUpdateInsertTabContext& rCxt, const ScAddress& rOldPos ) { - bool bRefChanged = false; + sc::RefUpdateResult aRes; ScAddress aNewPos = rOldPos; - if (nInsPos <= rOldPos.Tab()) - aNewPos.IncTab(nSheets); + if (rCxt.mnInsertPos <= rOldPos.Tab()) + aNewPos.IncTab(rCxt.mnSheets); FormulaToken** p = pCode; FormulaToken** pEnd = p + static_cast<size_t>(nLen); @@ -2741,25 +2741,39 @@ bool ScTokenArray::AdjustReferenceOnInsertedTab( SCTAB nInsPos, SCTAB nSheets, c { ScToken* pToken = static_cast<ScToken*>(*p); ScSingleRefData& rRef = pToken->GetSingleRef(); - if (adjustSingleRefOnInsertedTab(rRef, nInsPos, nSheets, rOldPos, aNewPos)) - bRefChanged = true; + if (adjustSingleRefOnInsertedTab(rRef, rCxt.mnInsertPos, rCxt.mnSheets, rOldPos, aNewPos)) + aRes.mbReferenceModified = true; } break; case svDoubleRef: { ScToken* pToken = static_cast<ScToken*>(*p); ScComplexRefData& rRef = pToken->GetDoubleRef(); - if (adjustSingleRefOnInsertedTab(rRef.Ref1, nInsPos, nSheets, rOldPos, aNewPos)) - bRefChanged = true; - if (adjustSingleRefOnInsertedTab(rRef.Ref2, nInsPos, nSheets, rOldPos, aNewPos)) - bRefChanged = true; + if (adjustSingleRefOnInsertedTab(rRef.Ref1, rCxt.mnInsertPos, rCxt.mnSheets, rOldPos, aNewPos)) + aRes.mbReferenceModified = true; + if (adjustSingleRefOnInsertedTab(rRef.Ref2, rCxt.mnInsertPos, rCxt.mnSheets, rOldPos, aNewPos)) + aRes.mbReferenceModified = true; } 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; + } + } default: ; } } - return bRefChanged; + return aRes; } namespace { |