diff options
author | Eike Rathke <erack@redhat.com> | 2012-04-19 23:26:16 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2012-04-19 23:26:16 +0200 |
commit | 409f11ae387c859dcf9275c08093649a676e1f9e (patch) | |
tree | 1d72e2c89f33b93a31f8f0aa275247819e9c2e7e | |
parent | 791687613a66c13ee9f5f12b9859bc4ed0eff67e (diff) |
fdo#48856 update sheet-local named expressions correctly
* Named expression must be updated before any formulas that would access them.
* Handle all ocName tokens differentiating between global and sheet-local
names.
-rw-r--r-- | sc/inc/compiler.hxx | 7 | ||||
-rw-r--r-- | sc/inc/rangenam.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/table1.cxx | 8 | ||||
-rw-r--r-- | sc/source/core/tool/compiler.cxx | 43 | ||||
-rw-r--r-- | sc/source/core/tool/rangenam.cxx | 2 |
5 files changed, 32 insertions, 30 deletions
diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx index b83448b22c28..58a3c6c6f918 100644 --- a/sc/inc/compiler.hxx +++ b/sc/inc/compiler.hxx @@ -364,6 +364,13 @@ private: void SetRelNameReference(); + /** Obtain range data for ocName token, global or sheet local. + + Prerequisite: rToken is a FormulaIndexToken so IsGlobal() and + GetIndex() can be called on it. We don't check with RTTI. + */ + ScRangeData* GetRangeData( const formula::FormulaToken& pToken ) const; + static void InitCharClassEnglish(); public: diff --git a/sc/inc/rangenam.hxx b/sc/inc/rangenam.hxx index 2e3c007adb1c..dfb7d9e5bca2 100644 --- a/sc/inc/rangenam.hxx +++ b/sc/inc/rangenam.hxx @@ -201,7 +201,7 @@ public: SC_DLLPUBLIC const ScRangeData* findByRange(const ScRange& rRange) const; SC_DLLPUBLIC ScRangeData* findByUpperName(const rtl::OUString& rName); SC_DLLPUBLIC const ScRangeData* findByUpperName(const rtl::OUString& rName) const; - SC_DLLPUBLIC ScRangeData* findByIndex(sal_uInt16 i); + 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); diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx index acf52059080c..40cc82cd84fa 100644 --- a/sc/source/core/data/table1.cxx +++ b/sc/source/core/data/table1.cxx @@ -1372,16 +1372,18 @@ void ScTable::UpdateReference( UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW i = 0; iMax = MAXCOL; } - for ( ; i<=iMax; i++) - bUpdated |= aCol[i].UpdateReference( - eUpdateRefMode, nCol1, nRow1, nTab1, nCol2, nRow2, nTab2, nDx, nDy, nDz, pUndoDoc ); + // Named expressions need to be updated before formulas acessing them. if (mpRangeName) { ScRange aRange( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );; mpRangeName->UpdateReference( eUpdateRefMode, aRange, nDx, nDy, nDz, true ); } + for ( ; i<=iMax; i++) + bUpdated |= aCol[i].UpdateReference( + eUpdateRefMode, nCol1, nRow1, nTab1, nCol2, nRow2, nTab2, nDx, nDy, nDz, pUndoDoc ); + if ( bIncludeDraw ) UpdateDrawRef( eUpdateRefMode, nCol1, nRow1, nTab1, nCol2, nRow2, nTab2, nDx, nDy, nDz, bUpdateNoteCaptionPos ); diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index be051c9d69e3..a46bd00e4e0b 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -3978,22 +3978,27 @@ ScTokenArray* ScCompiler::CompileString( const String& rFormula, const String& r } -bool ScCompiler::HandleRange() +ScRangeData* ScCompiler::GetRangeData( const FormulaToken& rToken ) const { ScRangeData* pRangeData = NULL; - - bool bGlobal = pToken->IsGlobal(); + bool bGlobal = rToken.IsGlobal(); if (bGlobal) // global named range. - pRangeData = pDoc->GetRangeName()->findByIndex( pToken->GetIndex() ); + pRangeData = pDoc->GetRangeName()->findByIndex( rToken.GetIndex()); else { // sheet local named range. - ScRangeName* pRN = pDoc->GetRangeName(aPos.Tab()); + const ScRangeName* pRN = pDoc->GetRangeName( aPos.Tab()); if (pRN) - pRangeData = pRN->findByIndex( pToken->GetIndex() ); + pRangeData = pRN->findByIndex( rToken.GetIndex()); } + return pRangeData; +} + +bool ScCompiler::HandleRange() +{ + const ScRangeData* pRangeData = GetRangeData( *pToken); if (pRangeData) { sal_uInt16 nErr = pRangeData->GetErrCode(); @@ -4118,7 +4123,7 @@ bool ScCompiler::HasModifiedRange() OpCode eOpCode = t->GetOpCode(); if ( eOpCode == ocName ) { - ScRangeData* pRangeData = pDoc->GetRangeName()->findByIndex(t->GetIndex()); + const ScRangeData* pRangeData = GetRangeData( *t); if (pRangeData && pRangeData->IsModified()) return true; } @@ -4239,7 +4244,7 @@ ScRangeData* ScCompiler::UpdateReference(UpdateRefMode eUpdateRefMode, { if( j->GetOpCode() == ocName ) { - ScRangeData* pName = pDoc->GetRangeName()->findByIndex( j->GetIndex() ); + ScRangeData* pName = GetRangeData( *j); if (pName && pName->HasType(RT_SHARED)) pRangeData = pName; } @@ -4292,7 +4297,7 @@ ScRangeData* ScCompiler::UpdateReference(UpdateRefMode eUpdateRefMode, { if( t->GetOpCode() == ocName ) { - ScRangeData* pName = pDoc->GetRangeName()->findByIndex( t->GetIndex() ); + ScRangeData* pName = GetRangeData( *t); if (pName && pName->HasType(RT_SHAREDMOD)) { pRangeData = pName; // maybe need a replacement of shared with own code @@ -4582,7 +4587,7 @@ ScRangeData* ScCompiler::UpdateInsertTab( SCTAB nTable, bool bIsName , SCTAB nNe { if (!bIsName) { - ScRangeData* pName = pDoc->GetRangeName()->findByIndex(t->GetIndex()); + ScRangeData* pName = GetRangeData( *t); if (pName && pName->HasType(RT_SHAREDMOD)) pRangeData = pName; } @@ -4693,7 +4698,7 @@ ScRangeData* ScCompiler::UpdateDeleteTab(SCTAB nTable, bool /* bIsMove */, bool { if (!bIsName) { - ScRangeData* pName = pDoc->GetRangeName()->findByIndex(t->GetIndex()); + ScRangeData* pName = GetRangeData( *t); if (pName && pName->HasType(RT_SHAREDMOD)) pRangeData = pName; } @@ -4903,7 +4908,7 @@ ScRangeData* ScCompiler::UpdateMoveTab( SCTAB nOldTab, SCTAB nNewTab, { if (!bIsName) { - ScRangeData* pName = pDoc->GetRangeName()->findByIndex(t->GetIndex()); + ScRangeData* pName = GetRangeData( *t); if (pName && pName->HasType(RT_SHAREDMOD)) pRangeData = pName; } @@ -5157,19 +5162,7 @@ void ScCompiler::CreateStringFromIndex(rtl::OUStringBuffer& rBuffer,FormulaToken { case ocName: { - bool bGlobal = _pTokenP->IsGlobal(); - ScRangeData* pData = NULL; - if (bGlobal) - // global named range. - pData = pDoc->GetRangeName()->findByIndex(_pTokenP->GetIndex()); - else - { - // sheet local named range. - ScRangeName* pRN = pDoc->GetRangeName(aPos.Tab()); - if (pRN) - pData = pRN->findByIndex(_pTokenP->GetIndex()); - } - + ScRangeData* pData = GetRangeData( *_pTokenP); if (pData) { if (pData->HasType(RT_SHARED)) diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx index 8f10302a7e23..e671585ad91f 100644 --- a/sc/source/core/tool/rangenam.cxx +++ b/sc/source/core/tool/rangenam.cxx @@ -768,7 +768,7 @@ const ScRangeData* ScRangeName::findByUpperName(const OUString& rName) const return itr == maData.end() ? NULL : itr->second; } -ScRangeData* ScRangeName::findByIndex(sal_uInt16 i) +ScRangeData* ScRangeName::findByIndex(sal_uInt16 i) const { if (!i) // index should never be zero. |