[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - sc/inc sc/source
Kohei Yoshida
kohei.yoshida at gmail.com
Tue Jul 30 12:26:42 PDT 2013
sc/inc/colorscale.hxx | 27 ++-
sc/inc/conditio.hxx | 44 ++++--
sc/inc/refupdatecontext.hxx | 2
sc/inc/validat.hxx | 13 +
sc/source/core/data/colorscale.cxx | 125 ++++++++++++------
sc/source/core/data/conditio.cxx | 211 ++++++++++++++-----------------
sc/source/core/data/documen2.cxx | 26 +--
sc/source/core/data/documen3.cxx | 2
sc/source/core/data/document.cxx | 18 +-
sc/source/core/data/refupdatecontext.cxx | 24 +++
sc/source/core/data/table1.cxx | 16 --
sc/source/core/data/table2.cxx | 8 +
sc/source/core/data/validat.cxx | 23 ++-
sc/source/core/tool/token.cxx | 36 +----
14 files changed, 324 insertions(+), 251 deletions(-)
New commits:
commit 2f9d3f6ba8facbb2a6eac9a8e13b84fdfc7e8932
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Tue Jul 30 15:27:02 2013 -0400
Rework reference update in conditional formatting and cell validation.
No tests are written for this yet.
Change-Id: Ic26a7f19d6ce6e6d7059035dc9c99ae5bcb9d77b
diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx
index e220426..1264f27 100644
--- a/sc/inc/colorscale.hxx
+++ b/sc/inc/colorscale.hxx
@@ -69,8 +69,10 @@ public:
formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT);
void UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab, SCTAB nTabNo);
- void UpdateReference( ScDocument* pDoc, UpdateRefMode eUpdateRefMode,
- const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
+ void UpdateReference( sc::RefUpdateContext& rCxt );
+ void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt );
+ void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt );
+ void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt );
const ScTokenArray* GetFormula() const;
OUString GetFormula( formula::FormulaGrammar::Grammar eGrammar ) const;
@@ -249,9 +251,10 @@ public:
void AddEntry(ScColorScaleEntry* pEntry);
virtual void DataChanged(const ScRange& rRange);
- virtual void UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab);
- virtual void UpdateReference( UpdateRefMode eUpdateRefMode,
- const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
+ virtual void UpdateReference( sc::RefUpdateContext& rCxt );
+ virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt );
+ virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt );
+ virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt );
virtual bool NeedsRepaint() const;
@@ -279,9 +282,10 @@ public:
const ScDataBarFormatData* GetDataBarData() const;
virtual void DataChanged(const ScRange& rRange);
- virtual void UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab);
- virtual void UpdateReference( UpdateRefMode eUpdateRefMode,
- const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
+ virtual void UpdateReference( sc::RefUpdateContext& rCxt );
+ virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt );
+ virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt );
+ virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt );
virtual bool NeedsRepaint() const;
@@ -323,9 +327,10 @@ public:
const ScIconSetFormatData* GetIconSetData() const;
virtual void DataChanged(const ScRange& rRange);
- virtual void UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab);
- virtual void UpdateReference( UpdateRefMode eUpdateRefMode,
- const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
+ virtual void UpdateReference( sc::RefUpdateContext& rCxt );
+ virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt );
+ virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt );
+ virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt );
virtual bool NeedsRepaint() const;
diff --git a/sc/inc/conditio.hxx b/sc/inc/conditio.hxx
index 42ad1f7..7f50a27 100644
--- a/sc/inc/conditio.hxx
+++ b/sc/inc/conditio.hxx
@@ -40,6 +40,15 @@ class ScFormulaCell;
class ScTokenArray;
struct ScRefCellValue;
+namespace sc {
+
+struct RefUpdateContext;
+struct RefUpdateInsertTabContext;
+struct RefUpdateDeleteTabContext;
+struct RefUpdateMoveTabContext;
+
+}
+
// nOptions Flags
#define SC_COND_NOBLANKS 1
@@ -111,9 +120,10 @@ public:
virtual ~ScFormatEntry() {}
virtual condformat::ScFormatEntryType GetType() const = 0;
- virtual void UpdateReference( UpdateRefMode eUpdateRefMode,
- const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz ) = 0;
- virtual void UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos ) = 0;
+ virtual void UpdateReference( sc::RefUpdateContext& rCxt ) = 0;
+ virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) = 0;
+ virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) = 0;
+ virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt ) = 0;
virtual ScFormatEntry* Clone( ScDocument* pDoc = NULL ) const = 0;
@@ -217,9 +227,10 @@ public:
void CompileAll();
void CompileXML();
- void UpdateReference( UpdateRefMode eUpdateRefMode,
- const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
- void UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
+ virtual void UpdateReference( sc::RefUpdateContext& rCxt );
+ virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt );
+ virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt );
+ virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt );
void SourceChanged( const ScAddress& rChanged );
@@ -343,9 +354,10 @@ public:
void SetStyleName( const OUString& rStyleName );
virtual condformat::ScFormatEntryType GetType() const { return condformat::DATE; }
- virtual void UpdateReference( UpdateRefMode, const ScRange&,
- SCsCOL, SCsROW, SCsTAB ) {}
- virtual void UpdateMoveTab( SCTAB, SCTAB ) {}
+ virtual void UpdateReference( sc::RefUpdateContext& ) {}
+ virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& ) {}
+ virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& ) {}
+ virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& ) {}
virtual ScFormatEntry* Clone( ScDocument* pDoc = NULL ) const;
@@ -397,10 +409,11 @@ public:
void CompileAll();
void CompileXML();
- void UpdateReference( UpdateRefMode eUpdateRefMode,
- const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz, bool bCopyAsMove = false );
+ void UpdateReference( sc::RefUpdateContext& rCxt, bool bCopyAsMove = false );
+ void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt );
+ void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt );
+ void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt );
void DeleteArea( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 );
- void UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
void RenameCellStyle( const OUString& rOld, const OUString& rNew );
void SourceChanged( const ScAddress& rAddr );
@@ -461,10 +474,11 @@ public:
void CompileAll();
void CompileXML();
- void UpdateReference( UpdateRefMode eUpdateRefMode,
- const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
+ void UpdateReference( sc::RefUpdateContext& rCxt );
+ void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt );
+ void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt );
+ void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt );
void RenameCellStyle( const OUString& rOld, const OUString& rNew );
- void UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
void DeleteArea( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 );
void SourceChanged( const ScAddress& rAddr );
diff --git a/sc/inc/refupdatecontext.hxx b/sc/inc/refupdatecontext.hxx
index 380bc84..f5ca4d0 100644
--- a/sc/inc/refupdatecontext.hxx
+++ b/sc/inc/refupdatecontext.hxx
@@ -108,6 +108,8 @@ struct RefUpdateMoveTabContext
UpdatedRangeNames maUpdatedNames;
RefUpdateMoveTabContext(SCTAB nOldPos, SCTAB nNewPos);
+
+ SCTAB getNewTab(SCTAB nOldTab) const;
};
}
diff --git a/sc/inc/validat.hxx b/sc/inc/validat.hxx
index 904279a..64aa597 100644
--- a/sc/inc/validat.hxx
+++ b/sc/inc/validat.hxx
@@ -26,6 +26,12 @@
namespace ValidListType = ::com::sun::star::sheet::TableValidationVisibility;
+namespace sc {
+
+struct RefUpdateContext;
+
+}
+
class ScPatternAttr;
class ScTokenArray;
class ScTypedStrData;
@@ -191,9 +197,10 @@ public:
ScValidationData* GetData( sal_uInt32 nKey );
void CompileXML();
- void UpdateReference( UpdateRefMode eUpdateRefMode,
- const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
- void UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
+ void UpdateReference( sc::RefUpdateContext& rCxt );
+ void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt );
+ void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt );
+ void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt );
sal_Bool operator==( const ScValidationDataList& r ) const; // for ref-undo
};
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index a0add6d..ddc9309 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -245,20 +245,40 @@ void ScColorScaleEntry::UpdateMoveTab( SCTAB nOldTab, SCTAB nNewTab, SCTAB nTabN
}
}
-void ScColorScaleEntry::UpdateReference(
- ScDocument* pDoc, UpdateRefMode eUpdateRefMode, const ScRange& rRange,
- SCsCOL nDx, SCsROW nDy, SCsTAB nDz )
+void ScColorScaleEntry::UpdateReference( sc::RefUpdateContext& rCxt )
{
if (!mpCell)
return;
- sc::RefUpdateContext aCxt(*pDoc);
- aCxt.meMode = eUpdateRefMode;
- aCxt.maRange = rRange;
- aCxt.mnColDelta = nDx;
- aCxt.mnRowDelta = nDy;
- aCxt.mnTabDelta = nDz;
- mpCell->UpdateReference(aCxt);
+ mpCell->UpdateReference(rCxt);
+ mpListener.reset(new ScFormulaListener(mpCell.get()));
+}
+
+void ScColorScaleEntry::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt )
+{
+ if (!mpCell)
+ return;
+
+ mpCell->UpdateInsertTab(rCxt);
+ mpListener.reset(new ScFormulaListener(mpCell.get()));
+}
+
+void ScColorScaleEntry::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt )
+{
+ if (!mpCell)
+ return;
+
+ mpCell->UpdateDeleteTab(rCxt);
+ mpListener.reset(new ScFormulaListener(mpCell.get()));
+}
+
+void ScColorScaleEntry::UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt )
+{
+ if (!mpCell)
+ return;
+
+ SCTAB nTabNo = rCxt.getNewTab(mpCell->aPos.Tab());
+ mpCell->UpdateMoveTab(rCxt, nTabNo);
mpListener.reset(new ScFormulaListener(mpCell.get()));
}
@@ -574,22 +594,28 @@ Color* ScColorScaleFormat::GetColor( const ScAddress& rAddr ) const
return new Color(aColor);
}
-void ScColorScaleFormat::UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab)
+void ScColorScaleFormat::UpdateReference( sc::RefUpdateContext& rCxt )
{
- SCTAB nThisTab = GetRange().front()->aStart.Tab();
for(iterator itr = begin(); itr != end(); ++itr)
- {
- itr->UpdateMoveTab(nOldTab, nNewTab, nThisTab);
- }
+ itr->UpdateReference(rCxt);
}
-void ScColorScaleFormat::UpdateReference( UpdateRefMode eUpdateRefMode,
- const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz )
+void ScColorScaleFormat::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt )
{
- for(iterator itr = begin(); itr != end(); ++itr)
- {
- itr->UpdateReference(mpDoc, eUpdateRefMode, rRange, nDx, nDy, nDz);
- }
+ for (iterator it = begin(); it != end(); ++it)
+ it->UpdateInsertTab(rCxt);
+}
+
+void ScColorScaleFormat::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt )
+{
+ for (iterator it = begin(); it != end(); ++it)
+ it->UpdateDeleteTab(rCxt);
+}
+
+void ScColorScaleFormat::UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt )
+{
+ for (iterator it = begin(); it != end(); ++it)
+ it->UpdateMoveTab(rCxt);
}
bool ScColorScaleFormat::NeedsRepaint() const
@@ -698,11 +724,28 @@ condformat::ScFormatEntryType ScDataBarFormat::GetType() const
return condformat::DATABAR;
}
-void ScDataBarFormat::UpdateReference( UpdateRefMode eRefMode,
- const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz )
+void ScDataBarFormat::UpdateReference( sc::RefUpdateContext& rCxt )
+{
+ mpFormatData->mpUpperLimit->UpdateReference(rCxt);
+ mpFormatData->mpLowerLimit->UpdateReference(rCxt);
+}
+
+void ScDataBarFormat::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt )
{
- mpFormatData->mpUpperLimit->UpdateReference( mpDoc, eRefMode, rRange, nDx, nDy, nDz );
- mpFormatData->mpLowerLimit->UpdateReference( mpDoc, eRefMode, rRange, nDx, nDy, nDz );
+ mpFormatData->mpUpperLimit->UpdateInsertTab(rCxt);
+ mpFormatData->mpLowerLimit->UpdateInsertTab(rCxt);
+}
+
+void ScDataBarFormat::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt )
+{
+ mpFormatData->mpUpperLimit->UpdateDeleteTab(rCxt);
+ mpFormatData->mpLowerLimit->UpdateDeleteTab(rCxt);
+}
+
+void ScDataBarFormat::UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt )
+{
+ mpFormatData->mpUpperLimit->UpdateMoveTab(rCxt);
+ mpFormatData->mpLowerLimit->UpdateMoveTab(rCxt);
}
bool ScDataBarFormat::NeedsRepaint() const
@@ -742,13 +785,6 @@ void ScDataBarFormat::DataChanged(const ScRange& rRange)
}
}
-void ScDataBarFormat::UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab)
-{
- SCTAB nThisTab = GetRange().front()->aStart.Tab();
- mpFormatData->mpUpperLimit->UpdateMoveTab(nOldTab, nNewTab, nThisTab);
- mpFormatData->mpLowerLimit->UpdateMoveTab(nOldTab, nNewTab, nThisTab);
-}
-
double ScDataBarFormat::getMin(double nMin, double nMax) const
{
switch(mpFormatData->mpLowerLimit->GetType())
@@ -1001,20 +1037,35 @@ void ScIconSetFormat::DataChanged( const ScRange& )
{
}
-void ScIconSetFormat::UpdateMoveTab( SCTAB nOldTab, SCTAB nNewTab )
+void ScIconSetFormat::UpdateReference( sc::RefUpdateContext& rCxt )
+{
+ for(iterator itr = begin(); itr != end(); ++itr)
+ {
+ itr->UpdateReference(rCxt);
+ }
+}
+
+void ScIconSetFormat::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt )
+{
+ for(iterator itr = begin(); itr != end(); ++itr)
+ {
+ itr->UpdateInsertTab(rCxt);
+ }
+}
+
+void ScIconSetFormat::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt )
{
for(iterator itr = begin(); itr != end(); ++itr)
{
- itr->UpdateMoveTab(nOldTab, nNewTab, 0);
+ itr->UpdateDeleteTab(rCxt);
}
}
-void ScIconSetFormat::UpdateReference( UpdateRefMode eUpdateRefMode,
- const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz )
+void ScIconSetFormat::UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt )
{
for(iterator itr = begin(); itr != end(); ++itr)
{
- itr->UpdateReference( mpDoc, eUpdateRefMode, rRange, nDx, nDy, nDz );
+ itr->UpdateMoveTab(rCxt);
}
}
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx
index f2414c1..591fc0f 100644
--- a/sc/source/core/data/conditio.cxx
+++ b/sc/source/core/data/conditio.cxx
@@ -494,114 +494,73 @@ void ScConditionEntry::SetFormula2( const ScTokenArray& rArray )
}
}
-static void lcl_CondUpdateInsertTab( ScTokenArray& rCode, SCTAB nInsTab, bool& rChanged, SCTAB nTabs )
+void ScConditionEntry::UpdateReference( sc::RefUpdateContext& rCxt )
{
- // Insert table: only update absolute table references.
- // (Similar to ScCompiler::UpdateInsertTab with bIsName=true, result is the same as for named ranges)
- // For deleting, ScCompiler::UpdateDeleteTab is used because of the handling of invalid references.
-
- rCode.Reset();
- ScToken* p = static_cast<ScToken*>(rCode.GetNextReference());
- while( p )
- {
- ScSingleRefData& rRef1 = p->GetSingleRef();
- if (!rRef1.IsTabRel() && nInsTab <= rRef1.Tab())
- {
- rRef1.SetAbsTab(rRef1.Tab() + nTabs);
- rChanged = true;
- }
- if( p->GetType() == svDoubleRef )
- {
- ScSingleRefData& rRef2 = p->GetDoubleRef().Ref2;
- if (!rRef2.IsTabRel() && nInsTab <= rRef2.Tab())
- {
- rRef2.SetAbsTab(rRef2.Tab() + nTabs);
- rChanged = true;
- }
- }
- p = static_cast<ScToken*>(rCode.GetNextReference());
- }
-}
-
-void ScConditionEntry::UpdateReference( UpdateRefMode eUpdateRefMode,
- const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz )
-{
- bool bInsertTab = ( eUpdateRefMode == URM_INSDEL && nDz >= 1 );
- bool bDeleteTab = ( eUpdateRefMode == URM_INSDEL && nDz <= -1 );
if(pCondFormat)
aSrcPos = pCondFormat->GetRange().Combine().aStart;
ScAddress aOldSrcPos = aSrcPos;
bool bChangedPos = false;
- if(eUpdateRefMode == URM_INSDEL && rRange.In(aSrcPos))
+ if (rCxt.meMode == URM_INSDEL && rCxt.maRange.In(aSrcPos))
{
- aSrcPos.Move(nDx, nDy, nDz);
+ aSrcPos.Move(rCxt.mnColDelta, rCxt.mnRowDelta, rCxt.mnTabDelta);
bChangedPos = aSrcPos != aOldSrcPos;
}
if (pFormula1)
{
- bool bChanged1 = false;
- if ( bInsertTab )
- lcl_CondUpdateInsertTab( *pFormula1, rRange.aStart.Tab(), bChanged1, nDz );
- else
- {
- if ( bDeleteTab )
- {
- sc::RefUpdateDeleteTabContext aCxt(rRange.aStart.Tab(), -1*nDz);
- pFormula1->AdjustReferenceOnDeletedTab(aCxt, aSrcPos);
- }
- else
- {
- ScCompiler aComp( mpDoc, aSrcPos, *pFormula1 );
- aComp.SetGrammar(mpDoc->GetGrammar());
- bool bSizeChanged;
- aComp.UpdateReference( eUpdateRefMode, aOldSrcPos, rRange, nDx,
- nDy, nDz, bChanged1, bSizeChanged );
- }
- }
-
- if (bChanged1 || bChangedPos)
+ sc::RefUpdateResult aRes = pFormula1->AdjustReferenceInName(rCxt, aOldSrcPos);
+ if (aRes.mbReferenceModified || bChangedPos)
DELETEZ(pFCell1); // is created again in IsValid
}
if (pFormula2)
{
- bool bChanged2 = false;
- if ( bInsertTab )
- lcl_CondUpdateInsertTab( *pFormula2, rRange.aStart.Tab(), bChanged2, nDz );
- else
- {
- if ( bDeleteTab )
- {
- sc::RefUpdateDeleteTabContext aCxt(rRange.aStart.Tab(), -1*nDz);
- pFormula2->AdjustReferenceOnDeletedTab(aCxt, aSrcPos);
- }
- else
- {
- ScCompiler aComp( mpDoc, aSrcPos, *pFormula2);
- aComp.SetGrammar(mpDoc->GetGrammar());
- bool bSizeChanged;
- aComp.UpdateReference( eUpdateRefMode, aOldSrcPos, rRange, nDx,
- nDy, nDz, bChanged2, bSizeChanged );
- }
- }
-
- if (bChanged2 || bChangedPos)
+ sc::RefUpdateResult aRes = pFormula2->AdjustReferenceInName(rCxt, aOldSrcPos);
+ if (aRes.mbReferenceModified || bChangedPos)
DELETEZ(pFCell2); // is created again in IsValid
}
}
-void ScConditionEntry::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos )
+void ScConditionEntry::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt )
+{
+ if (pFormula1)
+ {
+ pFormula1->AdjustReferenceOnInsertedTab(rCxt, aSrcPos);
+ DELETEZ(pFCell1);
+ }
+
+ if (pFormula2)
+ {
+ pFormula2->AdjustReferenceOnInsertedTab(rCxt, aSrcPos);
+ DELETEZ(pFCell2);
+ }
+}
+
+void ScConditionEntry::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt )
+{
+ if (pFormula1)
+ {
+ pFormula1->AdjustReferenceOnDeletedTab(rCxt, aSrcPos);
+ DELETEZ(pFCell1);
+ }
+
+ if (pFormula2)
+ {
+ pFormula2->AdjustReferenceOnDeletedTab(rCxt, aSrcPos);
+ DELETEZ(pFCell2);
+ }
+}
+
+void ScConditionEntry::UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt )
{
- sc::RefUpdateMoveTabContext aCxt(nOldPos, nNewPos);
if (pFormula1)
{
- pFormula1->AdjustReferenceOnMovedTab(aCxt, aSrcPos);
+ pFormula1->AdjustReferenceOnMovedTab(rCxt, aSrcPos);
DELETEZ(pFCell1);
}
if (pFormula2)
{
- pFormula2->AdjustReferenceOnMovedTab(aCxt, aSrcPos);
+ pFormula2->AdjustReferenceOnMovedTab(rCxt, aSrcPos);
DELETEZ(pFCell2);
}
}
@@ -1987,40 +1946,34 @@ void ScConditionalFormat::CompileXML()
static_cast<ScCondFormatEntry&>(*itr).CompileXML();
}
-void ScConditionalFormat::UpdateReference( UpdateRefMode eUpdateRefMode,
- const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz, bool bCopyAsMove )
+void ScConditionalFormat::UpdateReference( sc::RefUpdateContext& rCxt, bool bCopyAsMove )
{
for(CondFormatContainer::iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr)
- itr->UpdateReference(eUpdateRefMode, rRange, nDx, nDy, nDz);
+ itr->UpdateReference(rCxt);
- if( eUpdateRefMode == URM_COPY && bCopyAsMove )
- maRanges.UpdateReference( URM_MOVE, pDoc, rRange, nDx, nDy, nDz );
+ if (rCxt.meMode == URM_COPY && bCopyAsMove)
+ maRanges.UpdateReference(URM_MOVE, pDoc, rCxt.maRange, rCxt.mnColDelta, rCxt.mnRowDelta, rCxt.mnTabDelta);
else
- maRanges.UpdateReference( eUpdateRefMode, pDoc, rRange, nDx, nDy, nDz );
+ maRanges.UpdateReference(rCxt.meMode, pDoc, rCxt.maRange, rCxt.mnColDelta, rCxt.mnRowDelta, rCxt.mnTabDelta);
}
-void ScConditionalFormat::DeleteArea( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
+void ScConditionalFormat::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt )
{
- SCTAB nTab = maRanges[0]->aStart.Tab();
- maRanges.DeleteArea( nCol1, nRow1, nTab, nCol2, nRow2, nTab );
+ for (CondFormatContainer::iterator it = maEntries.begin(); it != maEntries.end(); ++it)
+ it->UpdateInsertTab(rCxt);
}
-void ScConditionalFormat::RenameCellStyle(const OUString& rOld, const OUString& rNew)
+void ScConditionalFormat::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt )
{
- for(CondFormatContainer::iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr)
- if(itr->GetType() == condformat::CONDITION)
- {
- ScCondFormatEntry& rFormat = static_cast<ScCondFormatEntry&>(*itr);
- if(rFormat.GetStyle() == rOld)
- rFormat.UpdateStyleName( rNew );
- }
+ for (CondFormatContainer::iterator it = maEntries.begin(); it != maEntries.end(); ++it)
+ it->UpdateDeleteTab(rCxt);
}
-void ScConditionalFormat::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos )
+void ScConditionalFormat::UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt )
{
size_t n = maRanges.size();
- SCTAB nMinTab = std::min<SCTAB>(nOldPos, nNewPos);
- SCTAB nMaxTab = std::max<SCTAB>(nOldPos, nNewPos);
+ SCTAB nMinTab = std::min<SCTAB>(rCxt.mnOldPos, rCxt.mnNewPos);
+ SCTAB nMaxTab = std::max<SCTAB>(rCxt.mnOldPos, rCxt.mnNewPos);
for(size_t i = 0; i < n; ++i)
{
ScRange* pRange = maRanges[i];
@@ -2030,14 +1983,14 @@ void ScConditionalFormat::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos )
continue;
}
- if(nTab == nOldPos)
+ if (nTab == rCxt.mnOldPos)
{
- pRange->aStart.SetTab(nNewPos);
- pRange->aEnd.SetTab(nNewPos);
+ pRange->aStart.SetTab(rCxt.mnNewPos);
+ pRange->aEnd.SetTab(rCxt.mnNewPos);
continue;
}
- if(nNewPos < nOldPos)
+ if (rCxt.mnNewPos < rCxt.mnOldPos)
{
pRange->aStart.IncTab();
pRange->aEnd.IncTab();
@@ -2049,8 +2002,25 @@ void ScConditionalFormat::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos )
}
}
+ for (CondFormatContainer::iterator it = maEntries.begin(); it != maEntries.end(); ++it)
+ it->UpdateMoveTab(rCxt);
+}
+
+void ScConditionalFormat::DeleteArea( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
+{
+ SCTAB nTab = maRanges[0]->aStart.Tab();
+ maRanges.DeleteArea( nCol1, nRow1, nTab, nCol2, nRow2, nTab );
+}
+
+void ScConditionalFormat::RenameCellStyle(const OUString& rOld, const OUString& rNew)
+{
for(CondFormatContainer::iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr)
- itr->UpdateMoveTab( nOldPos, nNewPos );
+ if(itr->GetType() == condformat::CONDITION)
+ {
+ ScCondFormatEntry& rFormat = static_cast<ScCondFormatEntry&>(*itr);
+ if(rFormat.GetStyle() == rOld)
+ rFormat.UpdateStyleName( rNew );
+ }
}
void ScConditionalFormat::SourceChanged( const ScAddress& rAddr )
@@ -2176,13 +2146,12 @@ void ScConditionalFormatList::CompileXML()
itr->CompileXML();
}
-void ScConditionalFormatList::UpdateReference( UpdateRefMode eUpdateRefMode,
- const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz )
+void ScConditionalFormatList::UpdateReference( sc::RefUpdateContext& rCxt )
{
for( iterator itr = begin(); itr != end(); ++itr)
- itr->UpdateReference( eUpdateRefMode, rRange, nDx, nDy, nDz );
+ itr->UpdateReference(rCxt);
- if( eUpdateRefMode == URM_INSDEL )
+ if (rCxt.meMode == URM_INSDEL)
{
// need to check which must be deleted
iterator itr = begin();
@@ -2196,16 +2165,28 @@ void ScConditionalFormatList::UpdateReference( UpdateRefMode eUpdateRefMode,
}
}
-void ScConditionalFormatList::RenameCellStyle( const OUString& rOld, const OUString& rNew )
+void ScConditionalFormatList::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt )
{
- for( iterator itr = begin(); itr != end(); ++itr)
- itr->RenameCellStyle(rOld,rNew);
+ for (iterator it = begin(); it != end(); ++it)
+ it->UpdateInsertTab(rCxt);
+}
+
+void ScConditionalFormatList::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt )
+{
+ for (iterator it = begin(); it != end(); ++it)
+ it->UpdateDeleteTab(rCxt);
}
-void ScConditionalFormatList::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos )
+void ScConditionalFormatList::UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt )
+{
+ for (iterator it = begin(); it != end(); ++it)
+ it->UpdateMoveTab(rCxt);
+}
+
+void ScConditionalFormatList::RenameCellStyle( const OUString& rOld, const OUString& rNew )
{
for( iterator itr = begin(); itr != end(); ++itr)
- itr->UpdateMoveTab( nOldPos, nNewPos );
+ itr->RenameCellStyle(rOld,rNew);
}
bool ScConditionalFormatList::CheckAllEntries()
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index 1402e1d..7a9e9d6 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -728,7 +728,7 @@ bool ScDocument::MoveTab( SCTAB nOldPos, SCTAB nNewPos, ScProgress* pProgress )
0,0,nOldPos, MAXCOL,MAXROW,nOldPos, 0,0,nDz );
UpdateRefAreaLinks( URM_REORDER, aSourceRange, 0,0,nDz );
if ( pValidationList )
- pValidationList->UpdateMoveTab( nOldPos, nNewPos );
+ pValidationList->UpdateMoveTab(aCxt);
if ( pUnoBroadcaster )
pUnoBroadcaster->Broadcast( ScUpdateRefHint( URM_REORDER,
aSourceRange, 0,0,nDz ) );
@@ -783,8 +783,9 @@ bool ScDocument::CopyTab( SCTAB nOldPos, SCTAB nNewPos, const ScMarkData* pOnlyM
else
bValid = !GetTable( aName, nDummy );
- bool bOldAutoCalc = GetAutoCalc();
- SetAutoCalc( false ); // Mehrfachberechnungen vermeiden
+ sc::AutoCalcSwitch aACSwitch(*this, false);
+ sc::RefUpdateInsertTabContext aCxt(nNewPos, 1);
+
if (bValid)
{
if (nNewPos >= static_cast<SCTAB>(maTabs.size()))
@@ -798,7 +799,6 @@ 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 );
@@ -835,8 +835,9 @@ bool ScDocument::CopyTab( SCTAB nOldPos, SCTAB nNewPos, const ScMarkData* pOnlyM
if (*it && it != maTabs.begin()+nOldPos && it != maTabs.begin()+nNewPos)
(*it)->StartAllListeners();
- if ( pValidationList )
- pValidationList->UpdateReference( URM_INSDEL, aRange, 0,0,1 );
+ if (pValidationList)
+ pValidationList->UpdateInsertTab(aCxt);
+
// sheet names of references may not be valid until sheet is copied
pChartListenerCollection->UpdateScheduledSeriesRanges();
}
@@ -844,12 +845,12 @@ bool ScDocument::CopyTab( SCTAB nOldPos, SCTAB nNewPos, const ScMarkData* pOnlyM
bValid = false;
}
}
+
if (bValid)
{
-
SetNoListening( true ); // noch nicht bei CopyToTable/Insert
- sc::CopyToDocContext aCxt(*this);
- maTabs[nOldPos]->CopyToTable(aCxt, 0, 0, MAXCOL, MAXROW, IDF_ALL, (pOnlyMarked != NULL),
+ sc::CopyToDocContext aCopyDocCxt(*this);
+ maTabs[nOldPos]->CopyToTable(aCopyDocCxt, 0, 0, MAXCOL, MAXROW, IDF_ALL, (pOnlyMarked != NULL),
maTabs[nNewPos], pOnlyMarked );
maTabs[nNewPos]->SetTabBgColor(maTabs[nOldPos]->GetTabBgColor());
@@ -871,12 +872,10 @@ bool ScDocument::CopyTab( SCTAB nOldPos, SCTAB nNewPos, const ScMarkData* pOnlyM
maTabs[nNewPos]->StartAllListeners();
ScConditionalFormatList* pNewList = new ScConditionalFormatList(*maTabs[nOldPos]->GetCondFormList());
- pNewList->UpdateReference(URM_COPY, ScRange( 0, 0, nNewPos , MAXCOL, MAXROW,
- nNewPos), 0, 0, nDz);
+ pNewList->UpdateReference(aRefCxt);
maTabs[nNewPos]->SetCondFormList( pNewList );
SetDirty();
- SetAutoCalc( bOldAutoCalc );
if (pDrawLayer)
DrawCopyPage( static_cast<sal_uInt16>(nOldPos), static_cast<sal_uInt16>(nNewPos) );
@@ -894,8 +893,7 @@ bool ScDocument::CopyTab( SCTAB nOldPos, SCTAB nNewPos, const ScMarkData* pOnlyM
maTabs[nNewPos]->SetLayoutRTL(maTabs[nOldPos]->IsLayoutRTL());
maTabs[nNewPos]->SetLoadingRTL(maTabs[nOldPos]->IsLoadingRTL());
}
- else
- SetAutoCalc( bOldAutoCalc );
+
return bValid;
}
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index d8b7530..a239d05 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -1012,7 +1012,7 @@ void ScDocument::UpdateReference(
UpdateChartRef( eUpdateRefMode, nCol1, nRow1, nTab1, nCol2, nRow2, nTab2, nDx, nDy, nDz );
UpdateRefAreaLinks( eUpdateRefMode, aRange, nDx, nDy, nDz );
if ( pValidationList )
- pValidationList->UpdateReference( eUpdateRefMode, aRange, nDx, nDy, nDz );
+ pValidationList->UpdateReference(rCxt);
if ( pDetOpList )
pDetOpList->UpdateReference( this, eUpdateRefMode, aRange, nDx, nDy, nDz );
if ( pUnoBroadcaster )
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 8f6c37b..dbb03d7 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -501,8 +501,9 @@ bool ScDocument::InsertTab( SCTAB nPos, const OUString& rName,
if ( *it )
(*it)->StartAllListeners();
- if ( pValidationList )
- pValidationList->UpdateReference( URM_INSDEL, aRange, 0,0,1 );
+ if (pValidationList)
+ pValidationList->UpdateInsertTab(aCxt);
+
// sheet names of references are not valid until sheet is inserted
if ( pChartListenerCollection )
pChartListenerCollection->UpdateScheduledSeriesRanges();
@@ -587,8 +588,9 @@ bool ScDocument::InsertTabs( SCTAB nPos, const std::vector<OUString>& rNames,
if ( *it )
(*it)->StartAllListeners();
- if ( pValidationList )
- pValidationList->UpdateReference( URM_INSDEL, aRange, 0,0,nNewSheets );
+ if (pValidationList)
+ pValidationList->UpdateInsertTab(aCxt);
+
// sheet names of references are not valid until sheet is inserted
if ( pChartListenerCollection )
pChartListenerCollection->UpdateScheduledSeriesRanges();
@@ -650,8 +652,8 @@ bool ScDocument::DeleteTab( SCTAB nTab )
pDetOpList->UpdateReference( this, URM_INSDEL, aRange, 0,0,-1 );
UpdateChartRef( URM_INSDEL, 0,0,nTab, MAXCOL,MAXROW,MAXTAB, 0,0,-1 );
UpdateRefAreaLinks( URM_INSDEL, aRange, 0,0,-1 );
- if ( pValidationList )
- pValidationList->UpdateReference( URM_INSDEL, aRange, 0,0,-1 );
+ if (pValidationList)
+ pValidationList->UpdateDeleteTab(aCxt);
if ( pUnoBroadcaster )
pUnoBroadcaster->Broadcast( ScUpdateRefHint( URM_INSDEL, aRange, 0,0,-1 ) );
@@ -738,8 +740,8 @@ bool ScDocument::DeleteTabs( SCTAB nTab, SCTAB nSheets )
pDetOpList->UpdateReference( this, URM_INSDEL, aRange, 0,0,-1*nSheets );
UpdateChartRef( URM_INSDEL, 0,0,nTab, MAXCOL,MAXROW,MAXTAB, 0,0,-1*nSheets );
UpdateRefAreaLinks( URM_INSDEL, aRange, 0,0,-1*nSheets );
- if ( pValidationList )
- pValidationList->UpdateReference( URM_INSDEL, aRange, 0,0,-1*nSheets );
+ if (pValidationList)
+ pValidationList->UpdateDeleteTab(aCxt);
if ( pUnoBroadcaster )
pUnoBroadcaster->Broadcast( ScUpdateRefHint( URM_INSDEL, aRange, 0,0,-1*nSheets ) );
diff --git a/sc/source/core/data/refupdatecontext.cxx b/sc/source/core/data/refupdatecontext.cxx
index 73ec40c..ca550d1 100644
--- a/sc/source/core/data/refupdatecontext.cxx
+++ b/sc/source/core/data/refupdatecontext.cxx
@@ -70,6 +70,30 @@ RefUpdateDeleteTabContext::RefUpdateDeleteTabContext(SCTAB nDeletePos, SCTAB nSh
RefUpdateMoveTabContext::RefUpdateMoveTabContext(SCTAB nOldPos, SCTAB nNewPos) :
mnOldPos(nOldPos), mnNewPos(nNewPos) {}
+SCTAB RefUpdateMoveTabContext::getNewTab(SCTAB nOldTab) const
+{
+ // Sheets below the lower bound or above the uppper bound will not change.
+ SCTAB nLowerBound = std::min(mnOldPos, mnNewPos);
+ SCTAB nUpperBound = std::max(mnOldPos, mnNewPos);
+
+ if (nOldTab < nLowerBound || nUpperBound < nOldTab)
+ // Outside the boundary. Nothing to adjust.
+ return nOldTab;
+
+ if (nOldTab == mnOldPos)
+ return mnNewPos;
+
+ // It's somewhere in between.
+ if (mnOldPos < mnNewPos)
+ {
+ // Moving a sheet to the right. The rest of the sheets shifts to the left.
+ return nOldTab - 1;
+ }
+
+ // Moving a sheet to the left. The rest of the sheets shifts to the right.
+ return nOldTab + 1;
+}
+
}
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 11cd113..b3d1d28 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -1564,7 +1564,7 @@ void ScTable::UpdateReference(
SetStreamValid(false);
if(mpCondFormatList)
- mpCondFormatList->UpdateReference(eUpdateRefMode, rCxt.maRange, nDx, nDy, nDz);
+ mpCondFormatList->UpdateReference(rCxt);
}
void ScTable::UpdateTranspose( const ScRange& rSource, const ScAddress& rDest,
@@ -1593,11 +1593,7 @@ void ScTable::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt )
mpRangeName->UpdateInsertTab(rCxt, nTab);
if (mpCondFormatList)
- {
- mpCondFormatList->UpdateReference(
- URM_INSDEL, ScRange(0, 0, rCxt.mnInsertPos, MAXCOL, MAXROW, rCxt.mnInsertPos+rCxt.mnSheets-1),
- 0, 0, rCxt.mnSheets);
- }
+ mpCondFormatList->UpdateInsertTab(rCxt);
for (SCCOL i=0; i <= MAXCOL; i++) aCol[i].UpdateInsertTab(rCxt);
@@ -1618,11 +1614,7 @@ void ScTable::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt )
mpRangeName->UpdateDeleteTab(rCxt, nTab);
if (mpCondFormatList)
- {
- mpCondFormatList->UpdateReference(
- URM_INSDEL, ScRange(0,0, rCxt.mnDeletePos, MAXCOL, MAXROW, rCxt.mnDeletePos+rCxt.mnSheets-1),
- 0, 0, -1*rCxt.mnSheets);
- }
+ mpCondFormatList->UpdateDeleteTab(rCxt);
for (SCCOL i = 0; i <= MAXCOL; ++i)
aCol[i].UpdateDeleteTab(rCxt);
@@ -1642,7 +1634,7 @@ void ScTable::UpdateMoveTab(
pDBDataNoName->UpdateMoveTab(rCxt.mnOldPos, rCxt.mnNewPos);
if(mpCondFormatList)
- mpCondFormatList->UpdateMoveTab(rCxt.mnOldPos, rCxt.mnNewPos);
+ mpCondFormatList->UpdateMoveTab(rCxt);
for ( SCCOL i=0; i <= MAXCOL; i++ )
{
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index ebbd7fb..278096e 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -712,7 +712,13 @@ void ScTable::CopyConditionalFormat( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCRO
ScConditionalFormat* pNewFormat = itr->Clone(pDocument);
pNewFormat->AddRange(aIntersectedRange);
- pNewFormat->UpdateReference(URM_COPY, aNewRange, nDx, nDy, pTable->nTab - nTab, true);
+ sc::RefUpdateContext aRefCxt(*pDocument);
+ aRefCxt.meMode = URM_COPY;
+ aRefCxt.maRange = aNewRange;
+ aRefCxt.mnColDelta = nDx;
+ aRefCxt.mnRowDelta = nDy;
+ aRefCxt.mnTabDelta = pTable->nTab - nTab;
+ pNewFormat->UpdateReference(aRefCxt, true);
sal_uLong nMax = 0;
for(ScConditionalFormatList::const_iterator itrCond = mpCondFormatList->begin();
diff --git a/sc/source/core/data/validat.cxx b/sc/source/core/data/validat.cxx
index ea65bb5..779ef2a 100644
--- a/sc/source/core/data/validat.cxx
+++ b/sc/source/core/data/validat.cxx
@@ -945,17 +945,28 @@ void ScValidationDataList::CompileXML()
(*it)->CompileXML();
}
-void ScValidationDataList::UpdateReference( UpdateRefMode eUpdateRefMode,
- const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz )
+void ScValidationDataList::UpdateReference( sc::RefUpdateContext& rCxt )
{
for( iterator it = begin(); it != end(); ++it )
- (*it)->UpdateReference( eUpdateRefMode, rRange, nDx, nDy, nDz);
+ (*it)->UpdateReference(rCxt);
}
-void ScValidationDataList::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos )
+void ScValidationDataList::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt )
{
- for( iterator it = begin(); it != end(); ++it )
- (*it)->UpdateMoveTab( nOldPos, nNewPos );
+ for (iterator it = begin(); it != end(); ++it)
+ (*it)->UpdateInsertTab(rCxt);
+}
+
+void ScValidationDataList::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt )
+{
+ for (iterator it = begin(); it != end(); ++it)
+ (*it)->UpdateDeleteTab(rCxt);
+}
+
+void ScValidationDataList::UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt )
+{
+ for (iterator it = begin(); it != end(); ++it)
+ (*it)->UpdateMoveTab(rCxt);
}
sal_Bool ScValidationDataList::operator==( const ScValidationDataList& r ) const
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 806c05e..96e389f 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -2794,33 +2794,13 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnInsertedTab( sc::RefUpdateIns
namespace {
-bool adjustTabOnMove( ScAddress& rPos, SCTAB nOldPos, SCTAB nNewPos )
+bool adjustTabOnMove( ScAddress& rPos, sc::RefUpdateMoveTabContext& rCxt )
{
- // Sheets below the lower bound or above the uppper bound will not change.
- SCTAB nLowerBound = std::min(nOldPos, nNewPos);
- SCTAB nUpperBound = std::max(nOldPos, nNewPos);
-
- if (rPos.Tab() < nLowerBound || nUpperBound < rPos.Tab())
- // Outside the boundary. Nothing to adjust.
+ SCTAB nNewTab = rCxt.getNewTab(rPos.Tab());
+ if (nNewTab == rPos.Tab())
return false;
- if (rPos.Tab() == nOldPos)
- {
- rPos.SetTab(nNewPos);
- return true;
- }
-
- // It's somewhere in between.
- if (nOldPos < nNewPos)
- {
- // Moving a sheet to the right. The rest of the sheets shifts to the left.
- rPos.IncTab(-1);
- }
- else
- {
- // Moving a sheet to the left. The rest of the sheets shifts to the right.
- rPos.IncTab();
- }
+ rPos.SetTab(nNewTab);
return true;
}
@@ -2833,7 +2813,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnMovedTab( sc::RefUpdateMoveTa
return aRes;
ScAddress aNewPos = rOldPos;
- if (adjustTabOnMove(aNewPos, rCxt.mnOldPos, rCxt.mnNewPos))
+ if (adjustTabOnMove(aNewPos, rCxt))
aRes.mbReferenceModified = true;
FormulaToken** p = pCode;
@@ -2847,7 +2827,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnMovedTab( sc::RefUpdateMoveTa
ScToken* pToken = static_cast<ScToken*>(*p);
ScSingleRefData& rRef = pToken->GetSingleRef();
ScAddress aAbs = rRef.toAbs(rOldPos);
- if (adjustTabOnMove(aAbs, rCxt.mnOldPos, rCxt.mnNewPos))
+ if (adjustTabOnMove(aAbs, rCxt))
aRes.mbReferenceModified = true;
rRef.SetAddress(aAbs, aNewPos);
}
@@ -2857,9 +2837,9 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnMovedTab( sc::RefUpdateMoveTa
ScToken* pToken = static_cast<ScToken*>(*p);
ScComplexRefData& rRef = pToken->GetDoubleRef();
ScRange aAbs = rRef.toAbs(rOldPos);
- if (adjustTabOnMove(aAbs.aStart, rCxt.mnOldPos, rCxt.mnNewPos))
+ if (adjustTabOnMove(aAbs.aStart, rCxt))
aRes.mbReferenceModified = true;
- if (adjustTabOnMove(aAbs.aEnd, rCxt.mnOldPos, rCxt.mnNewPos))
+ if (adjustTabOnMove(aAbs.aEnd, rCxt))
aRes.mbReferenceModified = true;
rRef.SetRange(aAbs, aNewPos);
}
More information about the Libreoffice-commits
mailing list