diff --git sc/inc/compiler.hxx sc/inc/compiler.hxx index c41c15d..75da014 100644 --- sc/inc/compiler.hxx +++ sc/inc/compiler.hxx @@ -404,9 +404,9 @@ public: const ScDocument* GetDoc() const { return pDoc; } const ScAddress& GetPos() const { return aPos; } - void MoveRelWrap(); - static void MoveRelWrap( ScTokenArray& rArr, ScDocument* pDoc, - const ScAddress& rPos ); + void MoveRelWrap( SCCOL nMaxCol, SCROW nMaxRow ); + static void MoveRelWrap( ScTokenArray& rArr, ScDocument* pDoc, const ScAddress& rPos, + SCCOL nMaxCol, SCROW nMaxRow ); BOOL UpdateNameReference( UpdateRefMode eUpdateRefMode, const ScRange&, diff --git sc/inc/rangenam.hxx sc/inc/rangenam.hxx index ece1609..59ca4f8 100644 --- sc/inc/rangenam.hxx +++ sc/inc/rangenam.hxx @@ -83,6 +83,11 @@ private: USHORT nIndex; BOOL bModified; // wird bei UpdateReference gesetzt/geloescht + // max row and column to use for wrapping of references. If -1 use the + // application's default. + SCROW mnMaxRow; + SCCOL mnMaxCol; + friend class ScRangeName; ScRangeData( USHORT nIndex ); public: @@ -158,6 +163,11 @@ public: static void MakeValidName( String& rName ); SC_DLLPUBLIC static BOOL IsNameValid( const String& rName, ScDocument* pDoc ); + + SC_DLLPUBLIC void SetMaxRow(SCROW nRow); + SCROW GetMaxRow() const; + SC_DLLPUBLIC void SetMaxCol(SCCOL nCol); + SCCOL GetMaxCol() const; }; inline BOOL ScRangeData::HasType( RangeType nType ) const diff --git sc/source/core/data/cell2.cxx sc/source/core/data/cell2.cxx index 4c38b39..58d154d 100644 --- sc/source/core/data/cell2.cxx +++ sc/source/core/data/cell2.cxx @@ -891,7 +891,7 @@ void ScFormulaCell::UpdateInsertTab(SCTAB nTable) pCode = new ScTokenArray( *pRangeData->GetCode() ); ScCompiler aComp2(pDocument, aPos, *pCode); aComp2.SetGrammar(pDocument->GetGrammar()); - aComp2.MoveRelWrap(); + aComp2.MoveRelWrap(pRangeData->GetMaxCol(), pRangeData->GetMaxRow()); aComp2.UpdateInsertTab( nTable, FALSE ); // If the shared formula contained a named range/formula containing // an absolute reference to a sheet, those have to be readjusted. @@ -927,7 +927,7 @@ BOOL ScFormulaCell::UpdateDeleteTab(SCTAB nTable, BOOL bIsMove) ScCompiler aComp2(pDocument, aPos, *pCode); aComp2.SetGrammar(pDocument->GetGrammar()); aComp2.CompileTokenArray(); - aComp2.MoveRelWrap(); + aComp2.MoveRelWrap(pRangeData->GetMaxCol(), pRangeData->GetMaxRow()); aComp2.UpdateDeleteTab( nTable, FALSE, FALSE, bRefChanged ); // If the shared formula contained a named range/formula containing // an absolute reference to a sheet, those have to be readjusted. @@ -964,7 +964,7 @@ void ScFormulaCell::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo ) ScCompiler aComp2(pDocument, aPos, *pCode); aComp2.SetGrammar(pDocument->GetGrammar()); aComp2.CompileTokenArray(); - aComp2.MoveRelWrap(); + aComp2.MoveRelWrap(pRangeData->GetMaxCol(), pRangeData->GetMaxRow()); aComp2.UpdateMoveTab( nOldPos, nNewPos, TRUE ); bCompile = TRUE; } diff --git sc/source/core/inc/refupdat.hxx sc/source/core/inc/refupdat.hxx index c60cccc..1a4c66d 100644 --- sc/source/core/inc/refupdat.hxx +++ sc/source/core/inc/refupdat.hxx @@ -81,8 +81,8 @@ public: SCsCOL nDx, SCsROW nDy, SCsTAB nDz, ScComplexRefData& rRef, BOOL bWrap, BOOL bAbsolute ); - static void MoveRelWrap( ScDocument* pDoc, const ScAddress& rPos, - ScComplexRefData& rRef ); + static void MoveRelWrap( ScDocument* pDoc, const ScAddress& rPos, + SCCOL nMaxCol, SCROW nMaxRow, ScComplexRefData& rRef ); /// Before calling, the absolute references must be up-to-date! static ScRefUpdateRes UpdateTranspose( ScDocument* pDoc, diff --git sc/source/core/tool/compiler.cxx sc/source/core/tool/compiler.cxx index da0f296..c5cfce0 100644 --- sc/source/core/tool/compiler.cxx +++ sc/source/core/tool/compiler.cxx @@ -3809,7 +3809,7 @@ BOOL ScCompiler::HandleRange() if( pRangeData->HasReferences() ) { SetRelNameReference(); - MoveRelWrap(); + MoveRelWrap(pRangeData->GetMaxCol(), pRangeData->GetMaxRow()); } pNew->Reset(); if ( bAddPair ) @@ -3861,7 +3861,7 @@ BOOL ScCompiler::HandleExternalReference(const FormulaToken& _aToken) if (pNew->GetNextReference() != NULL) { SetRelNameReference(); - MoveRelWrap(); + MoveRelWrap(MAXCOL, MAXROW); } pNew->Reset(); return GetToken(); @@ -3956,33 +3956,33 @@ void ScCompiler::SetRelNameReference() // Wrap-adjust relative references of a RangeName to current position, // don't call for other token arrays! -void ScCompiler::MoveRelWrap() +void ScCompiler::MoveRelWrap( SCCOL nMaxCol, SCROW nMaxRow ) { pArr->Reset(); for( ScToken* t = static_cast(pArr->GetNextReference()); t; t = static_cast(pArr->GetNextReference()) ) { if ( t->GetType() == svSingleRef || t->GetType() == svExternalSingleRef ) - ScRefUpdate::MoveRelWrap( pDoc, aPos, SingleDoubleRefModifier( t->GetSingleRef() ).Ref() ); + ScRefUpdate::MoveRelWrap( pDoc, aPos, nMaxCol, nMaxRow, SingleDoubleRefModifier( t->GetSingleRef() ).Ref() ); else - ScRefUpdate::MoveRelWrap( pDoc, aPos, t->GetDoubleRef() ); + ScRefUpdate::MoveRelWrap( pDoc, aPos, nMaxCol, nMaxRow, t->GetDoubleRef() ); } } // static // Wrap-adjust relative references of a RangeName to current position, // don't call for other token arrays! -void ScCompiler::MoveRelWrap( ScTokenArray& rArr, ScDocument* pDoc, - const ScAddress& rPos ) +void ScCompiler::MoveRelWrap( ScTokenArray& rArr, ScDocument* pDoc, const ScAddress& rPos, + SCCOL nMaxCol, SCROW nMaxRow ) { rArr.Reset(); for( ScToken* t = static_cast(rArr.GetNextReference()); t; t = static_cast(rArr.GetNextReference()) ) { if ( t->GetType() == svSingleRef || t->GetType() == svExternalSingleRef ) - ScRefUpdate::MoveRelWrap( pDoc, rPos, SingleDoubleRefModifier( t->GetSingleRef() ).Ref() ); + ScRefUpdate::MoveRelWrap( pDoc, rPos, nMaxCol, nMaxRow, SingleDoubleRefModifier( t->GetSingleRef() ).Ref() ); else - ScRefUpdate::MoveRelWrap( pDoc, rPos, t->GetDoubleRef() ); + ScRefUpdate::MoveRelWrap( pDoc, rPos, nMaxCol, nMaxRow, t->GetDoubleRef() ); } } @@ -4157,7 +4157,7 @@ ScRangeData* ScCompiler::UpdateReference(UpdateRefMode eUpdateRefMode, SingleDoubleRefModifier aMod( rRef ); if ( rRef.IsRelName() ) { - ScRefUpdate::MoveRelWrap( pDoc, aPos, aMod.Ref() ); + ScRefUpdate::MoveRelWrap( pDoc, aPos, MAXCOL, MAXROW, aMod.Ref() ); rChanged = TRUE; } else @@ -4187,7 +4187,7 @@ ScRangeData* ScCompiler::UpdateReference(UpdateRefMode eUpdateRefMode, SCTAB nTabs = rRef.Ref2.nTab - rRef.Ref1.nTab; if ( rRef.Ref1.IsRelName() || rRef.Ref2.IsRelName() ) { - ScRefUpdate::MoveRelWrap( pDoc, aPos, rRef ); + ScRefUpdate::MoveRelWrap( pDoc, aPos, MAXCOL, MAXROW, rRef ); rChanged = TRUE; } else diff --git sc/source/core/tool/rangenam.cxx sc/source/core/tool/rangenam.cxx index d30a3d5..d701b2a 100644 --- sc/source/core/tool/rangenam.cxx +++ sc/source/core/tool/rangenam.cxx @@ -60,7 +60,7 @@ using namespace formula; // Interner ctor fuer das Suchen nach einem Index ScRangeData::ScRangeData( USHORT n ) - : pCode( NULL ), nIndex( n ), bModified( FALSE ) + : pCode( NULL ), nIndex( n ), bModified( FALSE ), mnMaxRow(-1), mnMaxCol(-1) {} ScRangeData::ScRangeData( ScDocument* pDok, @@ -76,7 +76,9 @@ ScRangeData::ScRangeData( ScDocument* pDok, eType ( nType ), pDoc ( pDok ), nIndex ( 0 ), - bModified ( FALSE ) + bModified ( FALSE ), + mnMaxRow (-1), + mnMaxCol (-1) { if (rSymbol.Len() > 0) { @@ -122,7 +124,9 @@ ScRangeData::ScRangeData( ScDocument* pDok, eType ( nType ), pDoc ( pDok ), nIndex ( 0 ), - bModified ( FALSE ) + bModified ( FALSE ), + mnMaxRow (-1), + mnMaxCol (-1) { if( !pCode->GetCodeError() ) { @@ -157,7 +161,9 @@ ScRangeData::ScRangeData( ScDocument* pDok, eType ( RT_NAME ), pDoc ( pDok ), nIndex ( 0 ), - bModified ( FALSE ) + bModified ( FALSE ), + mnMaxRow (-1), + mnMaxCol (-1) { ScSingleRefData aRefData; aRefData.InitAddress( rTarget ); @@ -179,7 +185,9 @@ ScRangeData::ScRangeData(const ScRangeData& rScRangeData) : eType (rScRangeData.eType), pDoc (rScRangeData.pDoc), nIndex (rScRangeData.nIndex), - bModified (rScRangeData.bModified) + bModified (rScRangeData.bModified), + mnMaxRow (rScRangeData.mnMaxRow), + mnMaxCol (rScRangeData.mnMaxCol) {} ScRangeData::~ScRangeData() @@ -247,7 +255,7 @@ void ScRangeData::UpdateSymbol( rtl::OUStringBuffer& rBuffer, const ScAddress& r ::std::auto_ptr pTemp( pCode->Clone() ); ScCompiler aComp( pDoc, rPos, *pTemp.get()); aComp.SetGrammar(eGrammar); - aComp.MoveRelWrap(); + aComp.MoveRelWrap(GetMaxCol(), GetMaxRow()); aComp.CreateStringFromTokenArray( rBuffer ); } @@ -393,7 +401,7 @@ BOOL ScRangeData::IsReference( ScRange& rRange, const ScAddress& rPos ) const ::std::auto_ptr pTemp( pCode->Clone() ); ScCompiler aComp( pDoc, rPos, *pTemp); aComp.SetGrammar(pDoc->GetGrammar()); - aComp.MoveRelWrap(); + aComp.MoveRelWrap(MAXCOL, MAXROW); return pTemp->IsReference( rRange ); } @@ -520,6 +528,26 @@ BOOL ScRangeData::IsNameValid( const String& rName, ScDocument* pDoc ) return TRUE; } +void ScRangeData::SetMaxRow(SCROW nRow) +{ + mnMaxRow = nRow; +} + +SCROW ScRangeData::GetMaxRow() const +{ + return mnMaxRow >= 0 ? mnMaxRow : MAXROW; +} + +void ScRangeData::SetMaxCol(SCCOL nCol) +{ + mnMaxCol = nCol; +} + +SCCOL ScRangeData::GetMaxCol() const +{ + return mnMaxCol >= 0 ? mnMaxCol : MAXCOL; +} + USHORT ScRangeData::GetErrCode() { diff --git sc/source/core/tool/refupdat.cxx sc/source/core/tool/refupdat.cxx index 0836979..461a1d7 100644 --- sc/source/core/tool/refupdat.cxx +++ sc/source/core/tool/refupdat.cxx @@ -820,28 +820,28 @@ ScRefUpdateRes ScRefUpdate::Move( ScDocument* pDoc, const ScAddress& rPos, return eRet; } -void ScRefUpdate::MoveRelWrap( ScDocument* pDoc, const ScAddress& rPos, - ScComplexRefData& rRef ) +void ScRefUpdate::MoveRelWrap( ScDocument* pDoc, const ScAddress& rPos, + SCCOL nMaxCol, SCROW nMaxRow, ScComplexRefData& rRef ) { if( rRef.Ref1.IsColRel() ) { rRef.Ref1.nCol = rRef.Ref1.nRelCol + rPos.Col(); - lcl_MoveItWrap( rRef.Ref1.nCol, static_cast(0), MAXCOL ); + lcl_MoveItWrap( rRef.Ref1.nCol, static_cast(0), nMaxCol ); } if( rRef.Ref2.IsColRel() ) { rRef.Ref2.nCol = rRef.Ref2.nRelCol + rPos.Col(); - lcl_MoveItWrap( rRef.Ref2.nCol, static_cast(0), MAXCOL ); + lcl_MoveItWrap( rRef.Ref2.nCol, static_cast(0), nMaxCol ); } if( rRef.Ref1.IsRowRel() ) { rRef.Ref1.nRow = rRef.Ref1.nRelRow + rPos.Row(); - lcl_MoveItWrap( rRef.Ref1.nRow, static_cast(0), MAXROW ); + lcl_MoveItWrap( rRef.Ref1.nRow, static_cast(0), nMaxRow ); } if( rRef.Ref2.IsRowRel() ) { rRef.Ref2.nRow = rRef.Ref2.nRelRow + rPos.Row(); - lcl_MoveItWrap( rRef.Ref2.nRow, static_cast(0), MAXROW ); + lcl_MoveItWrap( rRef.Ref2.nRow, static_cast(0), nMaxRow ); } SCsTAB nMaxTab = (SCsTAB) pDoc->GetTableCount() - 1; if( rRef.Ref1.IsTabRel() ) diff --git sc/source/filter/excel/namebuff.cxx sc/source/filter/excel/namebuff.cxx index f007482..3c71823 100644 --- sc/source/filter/excel/namebuff.cxx +++ sc/source/filter/excel/namebuff.cxx @@ -127,6 +127,8 @@ void ShrfmlaBuffer::Store( const ScRange& rRange, const ScTokenArray& rToken ) DBG_ASSERT( mnCurrIdx <= 0xFFFF, "*ShrfmlaBuffer::Store(): Gleich wird mir schlecht...!" ); ScRangeData* pData = new ScRangeData( pExcRoot->pIR->GetDocPtr(), aName, rToken, rRange.aStart, RT_SHARED ); + pData->SetMaxCol(255); + pData->SetMaxRow(65535); pData->SetIndex( static_cast< USHORT >( mnCurrIdx ) ); pExcRoot->pIR->GetNamedRanges().Insert( pData ); index_hash[rRange.aStart] = static_cast< USHORT >( mnCurrIdx ); diff --git sc/source/filter/excel/xeformula.cxx sc/source/filter/excel/xeformula.cxx index 6767ad2..0611a63 100644 --- sc/source/filter/excel/xeformula.cxx +++ sc/source/filter/excel/xeformula.cxx @@ -619,7 +619,7 @@ void XclExpFmlaCompImpl::Init( XclFormulaType eType, const ScTokenArray& rScTokA DBG_ASSERT( mbOk, "XclExpFmlaCompImpl::Init - missing cell address" ); // clone the passed token array, convert references relative to current cell position mxOwnScTokArr.reset( rScTokArr.Clone() ); - ScCompiler::MoveRelWrap( *mxOwnScTokArr, GetDocPtr(), *pScBasePos ); + ScCompiler::MoveRelWrap( *mxOwnScTokArr, GetDocPtr(), *pScBasePos, MAXCOL, MAXROW ); // don't remember pScBasePos in mpScBasePos, shared formulas use real relative refs break; default:; diff --git sc/source/filter/xlsx/xlsx-xeformula.cxx sc/source/filter/xlsx/xlsx-xeformula.cxx index 31af0f9..c1989b8 100644 --- sc/source/filter/xlsx/xlsx-xeformula.cxx +++ sc/source/filter/xlsx/xlsx-xeformula.cxx @@ -619,7 +619,7 @@ void XclExpFmlaCompImpl::Init( XclFormulaType eType, const ScTokenArray& rScTokA DBG_ASSERT( mbOk, "XclExpFmlaCompImpl::Init - missing cell address" ); // clone the passed token array, convert references relative to current cell position mxOwnScTokArr.reset( rScTokArr.Clone() ); - ScCompiler::MoveRelWrap( *mxOwnScTokArr, GetDocPtr(), *pScBasePos ); + ScCompiler::MoveRelWrap( *mxOwnScTokArr, GetDocPtr(), *pScBasePos, MAXCOL, MAXROW ); // don't remember pScBasePos in mpScBasePos, shared formulas use real relative refs break; default:;