[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - sc/inc sc/source
Kohei Yoshida
kohei.yoshida at gmail.com
Thu Jul 25 19:17:11 PDT 2013
sc/inc/rangenam.hxx | 18 ++++----------
sc/source/core/data/documen2.cxx | 4 +--
sc/source/core/data/document.cxx | 8 +++---
sc/source/core/data/table1.cxx | 19 +++++---------
sc/source/core/tool/rangenam.cxx | 50 ++++++++++++++-------------------------
5 files changed, 37 insertions(+), 62 deletions(-)
New commits:
commit df1e34997beb78fcd2622678209571469dc6bdc1
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Thu Jul 25 22:17:28 2013 -0400
Let's not use numerical magic numbers. Prefer enum.
Change-Id: I84d14dd06a2b28d7a8a1544f26eae180b6ea86b5
diff --git a/sc/inc/rangenam.hxx b/sc/inc/rangenam.hxx
index 436f82a..4a5944f 100644
--- a/sc/inc/rangenam.hxx
+++ b/sc/inc/rangenam.hxx
@@ -30,13 +30,8 @@
#include <boost/ptr_container/ptr_set.hpp>
#include <boost/ptr_container/ptr_map.hpp>
-//------------------------------------------------------------------------
-
class ScDocument;
-
-
-
-//------------------------------------------------------------------------
+class ScTokenArray;
typedef sal_uInt16 RangeType;
@@ -52,10 +47,6 @@ typedef sal_uInt16 RangeType;
#define RT_SHARED ((RangeType)0x0100)
#define RT_SHAREDMOD ((RangeType)0x0200)
-//------------------------------------------------------------------------
-
-class ScTokenArray;
-
class ScRangeData
{
private:
@@ -77,6 +68,9 @@ private:
void CompileRangeData( const String& rSymbol, bool bSetError );
void InitCode();
public:
+
+ enum TabRefUpdateMode { Insert = 1, Delete = 2, Move = 3 };
+
typedef ::std::map<sal_uInt16, sal_uInt16> IndexMap;
SC_DLLPUBLIC ScRangeData( ScDocument* pDoc,
@@ -139,7 +133,7 @@ public:
SC_DLLPUBLIC bool IsValidReference( ScRange& rRef ) const;
bool IsRangeAtBlock( const ScRange& ) const;
- void UpdateTabRef(SCTAB nOldTable, sal_uInt16 nFlag, SCTAB nNewTable, SCTAB nNewSheets);
+ void UpdateTabRef(SCTAB nOldTable, TabRefUpdateMode eMode, SCTAB nNewTable, SCTAB nNewSheets);
void ValidateTabRefs();
@@ -189,7 +183,7 @@ public:
SC_DLLPUBLIC ScRangeData* findByIndex(sal_uInt16 i) const;
void UpdateReference(UpdateRefMode eUpdateRefMode, const ScRange& rRange,
SCsCOL nDx, SCsROW nDy, SCsTAB nDz, bool bLocal = false);
- void UpdateTabRef(SCTAB nTable, sal_uInt16 nFlag, SCTAB nNewTable = 0, SCTAB nNewSheets = 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/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index d5ddbd4..72f912f 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -712,7 +712,7 @@ bool ScDocument::MoveTab( SCTAB nOldPos, SCTAB nNewPos, ScProgress* pProgress )
SCsTAB nDz = ((SCsTAB)nNewPos) - (SCsTAB)nOldPos;
ScRange aSourceRange( 0,0,nOldPos, MAXCOL,MAXROW,nOldPos );
if (pRangeName)
- pRangeName->UpdateTabRef(nOldPos, 3, nNewPos);
+ pRangeName->UpdateTabRef(nOldPos, ScRangeData::Move, nNewPos);
pDBCollection->UpdateMoveTab( nOldPos, nNewPos );
xColNameRanges->UpdateReference( URM_REORDER, this, aSourceRange, 0,0,nDz );
xRowNameRanges->UpdateReference( URM_REORDER, this, aSourceRange, 0,0,nDz );
@@ -799,7 +799,7 @@ bool ScDocument::CopyTab( SCTAB nOldPos, SCTAB nNewPos, const ScMarkData* pOnlyM
xColNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,1 );
xRowNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,1 );
if (pRangeName)
- pRangeName->UpdateTabRef(nNewPos, 1);
+ pRangeName->UpdateTabRef(nNewPos, ScRangeData::Insert);
pDBCollection->UpdateReference(
URM_INSDEL, 0,0,nNewPos, MAXCOL,MAXROW,MAXTAB, 0,0,1 );
if (pDPCollection)
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 1a4d379..8cbb01f 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -461,7 +461,7 @@ bool ScDocument::InsertTab( SCTAB nPos, const OUString& rName,
xColNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,1 );
xRowNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,1 );
if (pRangeName)
- pRangeName->UpdateTabRef( nPos, 1 );
+ pRangeName->UpdateTabRef(nPos, ScRangeData::Insert);
pDBCollection->UpdateReference(
URM_INSDEL, 0,0,nPos, MAXCOL,MAXROW,MAXTAB, 0,0,1 );
if (pDPCollection)
@@ -546,7 +546,7 @@ bool ScDocument::InsertTabs( SCTAB nPos, const std::vector<OUString>& rNames,
xColNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,nNewSheets );
xRowNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,nNewSheets );
if (pRangeName)
- pRangeName->UpdateTabRef( nPos, 1, 0, nNewSheets);
+ pRangeName->UpdateTabRef(nPos, ScRangeData::Insert, 0, nNewSheets);
pDBCollection->UpdateReference(
URM_INSDEL, 0,0,nPos, MAXCOL,MAXROW,MAXTAB, 0,0,nNewSheets );
if (pDPCollection)
@@ -637,7 +637,7 @@ bool ScDocument::DeleteTab( SCTAB nTab )
xColNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,-1 );
xRowNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,-1 );
if (pRangeName)
- pRangeName->UpdateTabRef( nTab, 2 );
+ pRangeName->UpdateTabRef(nTab, ScRangeData::Delete);
pDBCollection->UpdateReference(
URM_INSDEL, 0,0,nTab, MAXCOL,MAXROW,MAXTAB, 0,0,-1 );
if (pDPCollection)
@@ -717,7 +717,7 @@ bool ScDocument::DeleteTabs( SCTAB nTab, SCTAB nSheets )
pDetOpList->DeleteOnTab( nTab + aTab );
DeleteAreaLinksOnTab( nTab + aTab );
if (pRangeName)
- pRangeName->UpdateTabRef( nTab + aTab, 2 );
+ pRangeName->UpdateTabRef(nTab + aTab, ScRangeData::Delete);
}
// normal reference update
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 74d41f7..f4bb6b9 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -1591,10 +1591,10 @@ void ScTable::UpdateInsertTab(SCTAB nTable, SCTAB nNewSheets)
for (SCCOL i=0; i <= MAXCOL; i++) aCol[i].UpdateInsertTab(nTable, nNewSheets);
if (mpRangeName)
- mpRangeName->UpdateTabRef( nTable, 1, 0, nNewSheets);
-
- if (mpRangeName)
- mpRangeName->UpdateTabRef( nTable, 1);
+ {
+ mpRangeName->UpdateTabRef(nTable, ScRangeData::Insert, 0, nNewSheets);
+ mpRangeName->UpdateTabRef(nTable, ScRangeData::Insert);
+ }
if (IsStreamValid())
SetStreamValid(false);
@@ -1618,14 +1618,9 @@ void ScTable::UpdateDeleteTab( SCTAB nTable, SCTAB nSheets )
if (mpRangeName)
{
for (SCTAB aTab = 0; aTab < nSheets; ++aTab)
- {
- mpRangeName->UpdateTabRef( nTable + aTab, 2 );
- }
- }
+ mpRangeName->UpdateTabRef(nTable + aTab, ScRangeData::Delete);
- if (mpRangeName)
- {
- mpRangeName->UpdateTabRef( nTable, 2 );
+ mpRangeName->UpdateTabRef(nTable, ScRangeData::Delete);
}
if (IsStreamValid())
@@ -1647,7 +1642,7 @@ void ScTable::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo,
}
if (mpRangeName)
- mpRangeName->UpdateTabRef(nOldPos, 3, nNewPos);
+ mpRangeName->UpdateTabRef(nOldPos, ScRangeData::Move, nNewPos);
if (IsStreamValid())
SetStreamValid(false);
diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx
index 51d402f..e838b49 100644
--- a/sc/source/core/tool/rangenam.cxx
+++ b/sc/source/core/tool/rangenam.cxx
@@ -416,40 +416,26 @@ bool ScRangeData::IsValidReference( ScRange& rRange ) const
return false;
}
-void ScRangeData::UpdateTabRef(SCTAB nOldTable, sal_uInt16 nFlag, SCTAB nNewTable, SCTAB nNewSheets)
+void ScRangeData::UpdateTabRef(SCTAB nOldTable, TabRefUpdateMode eMode, SCTAB nNewTable, SCTAB nNewSheets)
{
pCode->Reset();
- if( pCode->GetNextReference() )
+ if (!pCode->GetNextReference())
+ return;
+
+ switch (eMode)
{
- ScRangeData* pRangeData = NULL; // must not be dereferenced
- bool bChanged;
- ScCompiler aComp( pDoc, aPos, *pCode);
- aComp.SetGrammar(pDoc->GetGrammar());
- switch (nFlag)
+ case Insert:
+ pCode->AdjustReferenceOnInsertedTab(nOldTable, nNewSheets, aPos);
+ break;
+ case Delete:
+ pCode->AdjustReferenceOnDeletedTab(nOldTable, nNewSheets, aPos);
+ break;
+ case Move:
+ pCode->AdjustReferenceOnMovedTab(nOldTable, nNewTable, aPos);
+ break;
+ default:
{
- case 1: // simple InsertTab (doc.cxx)
- pRangeData = aComp.UpdateInsertTab(nOldTable, true, nNewSheets ); // und CopyTab (doc2.cxx)
- break;
- case 2: // simple delete (doc.cxx)
- pRangeData = aComp.UpdateDeleteTab(nOldTable, false, true, bChanged);
- break;
- case 3: // move (doc2.cxx)
- {
- pRangeData = aComp.UpdateMoveTab(nOldTable, nNewTable, true );
- }
- break;
- default:
- {
- OSL_FAIL("ScRangeName::UpdateTabRef: Unknown Flag");
- }
- break;
- }
- if (eType&RT_SHARED)
- {
- if (pRangeData)
- eType = eType | RT_SHAREDMOD;
- else
- eType = eType & ~RT_SHAREDMOD;
+ OSL_FAIL("ScRangeName::UpdateTabRef: Unknown Flag");
}
}
}
@@ -755,11 +741,11 @@ void ScRangeName::UpdateReference(
itr->second->UpdateReference(eUpdateRefMode, rRange, nDx, nDy, nDz, bLocal);
}
-void ScRangeName::UpdateTabRef(SCTAB nTable, sal_uInt16 nFlag, SCTAB nNewTable, SCTAB nNewSheets)
+void ScRangeName::UpdateTabRef(SCTAB nTable, ScRangeData::TabRefUpdateMode eMode, SCTAB nNewTable, SCTAB nNewSheets)
{
DataType::iterator itr = maData.begin(), itrEnd = maData.end();
for (; itr != itrEnd; ++itr)
- itr->second->UpdateTabRef(nTable, nFlag, nNewTable, nNewSheets);
+ itr->second->UpdateTabRef(nTable, eMode, nNewTable, nNewSheets);
}
void ScRangeName::UpdateTranspose(const ScRange& rSource, const ScAddress& rDest)
More information about the Libreoffice-commits
mailing list