diff options
62 files changed, 551 insertions, 556 deletions
diff --git a/sc/inc/address.hxx b/sc/inc/address.hxx index 5a1f7d91f2ab..2109d582f67b 100644 --- a/sc/inc/address.hxx +++ b/sc/inc/address.hxx @@ -88,13 +88,13 @@ const SCCOL SC_TABSTART_NONE = SCCOL_MAX; const SCROW MAXROW_30 = 8191; -[[nodiscard]] inline bool ValidCol( SCCOL nCol, SCCOL nMaxCol = MAXCOL ) +[[nodiscard]] inline bool ValidCol( SCCOL nCol, SCCOL nMaxCol ) { assert(nMaxCol == MAXCOL); // temporary to debug jumbo sheets work return nCol >= 0 && nCol <= nMaxCol; } -[[nodiscard]] inline bool ValidRow( SCROW nRow, SCROW nMaxRow = MAXROW) +[[nodiscard]] inline bool ValidRow( SCROW nRow, SCROW nMaxRow) { assert(nMaxRow == MAXROW); // temporary to debug jumbo sheets work return nRow >= 0 && nRow <= nMaxRow; @@ -110,25 +110,25 @@ const SCROW MAXROW_30 = 8191; return nTab >= 0 && nTab <= nMaxTab; } -[[nodiscard]] inline bool ValidColRow( SCCOL nCol, SCROW nRow, SCCOL nMaxCol = MAXCOL, SCROW nMaxRow = MAXROW ) +[[nodiscard]] inline bool ValidColRow( SCCOL nCol, SCROW nRow, SCCOL nMaxCol, SCROW nMaxRow ) { assert(nMaxRow == MAXROW); // temporary to debug jumbo sheets work return ValidCol(nCol,nMaxCol) && ValidRow(nRow,nMaxRow); } -[[nodiscard]] inline bool ValidColRowTab( SCCOL nCol, SCROW nRow, SCTAB nTab, SCCOL nMaxCol = MAXCOL, SCROW nMaxRow = MAXROW ) +[[nodiscard]] inline bool ValidColRowTab( SCCOL nCol, SCROW nRow, SCTAB nTab, SCCOL nMaxCol, SCROW nMaxRow ) { assert(nMaxRow == MAXROW); // temporary to debug jumbo sheets work return ValidCol(nCol,nMaxCol) && ValidRow(nRow,nMaxRow) && ValidTab( nTab); } -[[nodiscard]] inline SCCOL SanitizeCol( SCCOL nCol, SCCOL nMaxCol = MAXCOL ) +[[nodiscard]] inline SCCOL SanitizeCol( SCCOL nCol, SCCOL nMaxCol ) { assert(nMaxCol == MAXCOL); // temporary to debug jumbo sheets work return nCol < 0 ? 0 : (nCol > nMaxCol ? nMaxCol : nCol); } -[[nodiscard]] inline SCROW SanitizeRow( SCROW nRow, SCROW nMaxRow = MAXROW ) +[[nodiscard]] inline SCROW SanitizeRow( SCROW nRow, SCROW nMaxRow ) { assert(nMaxRow == MAXROW); // temporary to debug jumbo sheets work return nRow < 0 ? 0 : (nRow > nMaxRow ? nMaxRow : nRow); diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx index 623f94945943..eca794a657a5 100644 --- a/sc/inc/compiler.hxx +++ b/sc/inc/compiler.hxx @@ -218,6 +218,7 @@ public: const OUString& rName ) const = 0; virtual void makeExternalRefStr( + ScSheetLimits& rLimits, OUStringBuffer& rBuffer, const ScAddress& rPos, sal_uInt16 nFileId, const OUString& rFileName, const OUString& rTabName, const ScSingleRefData& rRef ) const = 0; diff --git a/sc/inc/refdata.hxx b/sc/inc/refdata.hxx index a6e2299054b9..055095f485a2 100644 --- a/sc/inc/refdata.hxx +++ b/sc/inc/refdata.hxx @@ -24,6 +24,8 @@ #include "scdllapi.h" #include "calcmacros.hxx" +struct ScSheetLimits; + /// Single reference (one address) into the sheet struct SC_DLLPUBLIC ScSingleRefData { @@ -55,9 +57,9 @@ public: void InitAddress( const ScAddress& rAdr ); void InitAddress( SCCOL nCol, SCROW nRow, SCTAB nTab ); /// InitAddressRel: InitFlags and set address, everything relative to rPos - void InitAddressRel( const ScAddress& rAdr, const ScAddress& rPos ); + void InitAddressRel( const ScDocument* pDoc, const ScAddress& rAdr, const ScAddress& rPos ); /// InitFlags and set address, relative to rPos if rRef says so. - void InitFromRefAddress( const ScRefAddress& rRef, const ScAddress& rPos ); + void InitFromRefAddress( const ScDocument* pDoc, const ScRefAddress& rRef, const ScAddress& rPos ); sal_uInt8 FlagValue() const { return mnFlagValue;} void SetColRel( bool bVal ) { Flags.bColRel = bVal; } @@ -99,10 +101,9 @@ public: loaded. */ bool ValidExternal(const ScDocument* pDoc) const; - ScAddress toAbs( const ScAddress& rPos ) const; + ScAddress toAbs( ScSheetLimits& rLimits, const ScAddress& rPos ) const; ScAddress toAbs( const ScDocument* pDoc, const ScAddress& rPos ) const; - void SetAddress( const ScAddress& rAddr, const ScAddress& rPos ); - void SetAddress( const ScDocument* pDoc, const ScAddress& rAddr, const ScAddress& rPos ); + void SetAddress( ScSheetLimits& rLimits, const ScAddress& rAddr, const ScAddress& rPos ); SCROW Row() const; SCCOL Col() const; SCTAB Tab() const; @@ -131,10 +132,10 @@ struct ScComplexRefData Ref1.InitAddress( rRange.aStart ); Ref2.InitAddress( rRange.aEnd ); } - void InitRangeRel( const ScRange& rRange, const ScAddress& rPos ) + void InitRangeRel( const ScDocument* pDoc, const ScRange& rRange, const ScAddress& rPos ) { - Ref1.InitAddressRel( rRange.aStart, rPos ); - Ref2.InitAddressRel( rRange.aEnd, rPos ); + Ref1.InitAddressRel( pDoc, rRange.aStart, rPos ); + Ref2.InitAddressRel( pDoc, rRange.aEnd, rPos ); } void InitRange( SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2 ) @@ -144,7 +145,7 @@ struct ScComplexRefData } /// InitFlags and set range, relative to rPos if rRef1 and rRef2 say so. - void InitFromRefAddresses( const ScRefAddress& rRef1, const ScRefAddress& rRef2, const ScAddress& rPos ); + void InitFromRefAddresses( const ScDocument* pDoc, const ScRefAddress& rRef1, const ScRefAddress& rRef2, const ScAddress& rPos ); bool Valid(const ScDocument* pDoc) const; @@ -167,12 +168,12 @@ struct ScComplexRefData return Ref1.Col() == 0 && Ref2.Col() == MAXCOL && !Ref1.IsColRel() && !Ref2.IsColRel(); } - SC_DLLPUBLIC ScRange toAbs( const ScAddress& rPos ) const; + SC_DLLPUBLIC ScRange toAbs( ScSheetLimits& rLimits, const ScAddress& rPos ) const; SC_DLLPUBLIC ScRange toAbs( const ScDocument* pDoc, const ScAddress& rPos ) const; /** Set a new range, assuming that the ordering of the range matches the ordering of the reference data flags already set. */ - void SetRange( const ScRange& rRange, const ScAddress& rPos ); + void SetRange( ScSheetLimits& rLimits, const ScRange& rRange, const ScAddress& rPos ); /** Adjust ordering (front-top-left/rear-bottom-right) to a new position. */ void PutInOrder( const ScAddress& rPos ); @@ -182,8 +183,8 @@ struct ScComplexRefData /** Enlarge range if reference passed is not within existing range. ScAddress position is used to calculate absolute references from relative references. */ - ScComplexRefData& Extend( const ScSingleRefData & rRef, const ScAddress & rPos ); - ScComplexRefData& Extend( const ScComplexRefData & rRef, const ScAddress & rPos ); + ScComplexRefData& Extend( ScSheetLimits& rLimits, const ScSingleRefData & rRef, const ScAddress & rPos ); + ScComplexRefData& Extend( ScSheetLimits& rLimits, const ScComplexRefData & rRef, const ScAddress & rPos ); /** Increment or decrement end column unless or until sticky. @see ScRange::IncEndColSticky() diff --git a/sc/inc/reftokenhelper.hxx b/sc/inc/reftokenhelper.hxx index 759d69c5762e..a63d882011d7 100644 --- a/sc/inc/reftokenhelper.hxx +++ b/sc/inc/reftokenhelper.hxx @@ -40,9 +40,9 @@ namespace ScRefTokenHelper ::std::vector<ScTokenRef>& rRefTokens, const OUString& rRangeStr, ScDocument* pDoc, const sal_Unicode cSep, ::formula::FormulaGrammar::Grammar eGrammar, bool bOnly3DRef = false); - bool getRangeFromToken(ScRange& rRange, const ScTokenRef& pToken, const ScAddress& rPos, bool bExternal = false); + bool getRangeFromToken(const ScDocument* pDoc, ScRange& rRange, const ScTokenRef& pToken, const ScAddress& rPos, bool bExternal = false); - void getRangeListFromTokens(ScRangeList& rRangeList, const ::std::vector<ScTokenRef>& pTokens, const ScAddress& rPos); + void getRangeListFromTokens(const ScDocument* pDoc, ScRangeList& rRangeList, const ::std::vector<ScTokenRef>& pTokens, const ScAddress& rPos); /** * Create a double reference token from a range object. @@ -54,7 +54,7 @@ namespace ScRefTokenHelper bool SC_DLLPUBLIC isRef(const ScTokenRef& pToken); bool SC_DLLPUBLIC isExternalRef(const ScTokenRef& pToken); - bool SC_DLLPUBLIC intersects( + bool SC_DLLPUBLIC intersects(const ScDocument* pDoc, const ::std::vector<ScTokenRef>& rTokens, const ScTokenRef& pToken, const ScAddress& rPos); void SC_DLLPUBLIC join(const ScDocument* pDoc, ::std::vector<ScTokenRef>& rTokens, const ScTokenRef& pToken, const ScAddress& rPos); diff --git a/sc/inc/sharedformula.hxx b/sc/inc/sharedformula.hxx index b8ba5555812d..c61ce62b6b79 100644 --- a/sc/inc/sharedformula.hxx +++ b/sc/inc/sharedformula.hxx @@ -85,7 +85,7 @@ public: * @return TRUE if there indeed was a split, else FALSE (e.g. split * positions were only top or bottom cells or no formula group). */ - static bool splitFormulaCellGroups(CellStoreType& rCells, std::vector<SCROW>& rBounds); + static bool splitFormulaCellGroups(const ScDocument* pDoc, CellStoreType& rCells, std::vector<SCROW>& rBounds); /** * See if two specified adjacent formula cells can be merged, and if they diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 681167b9c5f6..8feb233480cf 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -449,7 +449,7 @@ public: CellType GetCellType( const ScAddress& rPos ) const { - if (!ValidColRow(rPos.Col(),rPos.Row())) + if (!GetDoc().ValidColRow(rPos.Col(),rPos.Row())) return CELLTYPE_NONE; if (rPos.Col() >= aCol.size()) return CELLTYPE_NONE; diff --git a/sc/inc/token.hxx b/sc/inc/token.hxx index ff52adac2031..433a5e33ab74 100644 --- a/sc/inc/token.hxx +++ b/sc/inc/token.hxx @@ -60,10 +60,11 @@ formula::FormulaTokenRef extendRangeReference( ScSheetLimits& rLimits, formula:: class ScSingleRefToken final : public formula::FormulaToken { private: + ScSheetLimits& mrSheetLimits; // don't use rtl::Reference to avoid ref-counting traffic ScSingleRefData aSingleRef; public: - ScSingleRefToken( ScSheetLimits& , const ScSingleRefData& r, OpCode e = ocPush ) : - FormulaToken( formula::svSingleRef, e ), aSingleRef( r ) {} + ScSingleRefToken( ScSheetLimits& rLimits, const ScSingleRefData& r, OpCode e = ocPush ) : + FormulaToken( formula::svSingleRef, e ), mrSheetLimits(rLimits), aSingleRef( r ) {} virtual const ScSingleRefData* GetSingleRef() const override; virtual ScSingleRefData* GetSingleRef() override; virtual bool TextEqual( const formula::FormulaToken& rToken ) const override; @@ -74,10 +75,11 @@ public: class ScDoubleRefToken final : public formula::FormulaToken { private: + ScSheetLimits& mrSheetLimits; // don't use rtl::Reference to avoid ref-counting traffic ScComplexRefData aDoubleRef; public: - ScDoubleRefToken( ScSheetLimits&, const ScComplexRefData& r, OpCode e = ocPush ) : - FormulaToken( formula::svDoubleRef, e ), aDoubleRef( r ) {} + ScDoubleRefToken( ScSheetLimits& rLimits, const ScComplexRefData& r, OpCode e = ocPush ) : + FormulaToken( formula::svDoubleRef, e ), mrSheetLimits(rLimits), aDoubleRef( r ) {} virtual const ScSingleRefData* GetSingleRef() const override; virtual ScSingleRefData* GetSingleRef() override; virtual const ScComplexRefData* GetDoubleRef() const override; diff --git a/sc/qa/unit/mark_test.cxx b/sc/qa/unit/mark_test.cxx index 6cd63a02de6b..8177d4444170 100644 --- a/sc/qa/unit/mark_test.cxx +++ b/sc/qa/unit/mark_test.cxx @@ -165,22 +165,22 @@ void Test::testSimpleMark( const ScRange& rRange, const ScRange& rSelectionCover SCCOL nOutCol2 = rRange.aStart.Col() - 1; CPPUNIT_ASSERT( aMark.IsCellMarked( nMidCol, nMidRow ) ); - if ( ValidCol( nOutCol1 ) && ValidRow( nOutRow1 ) ) + if ( ValidCol( nOutCol1, MAXCOL ) && ValidRow( nOutRow1, MAXROW ) ) CPPUNIT_ASSERT( !aMark.IsCellMarked( nOutCol1, nOutRow1 ) ); - if ( ValidCol( nOutCol2 ) && ValidRow( nOutRow2 ) ) + if ( ValidCol( nOutCol2, MAXCOL ) && ValidRow( nOutRow2, MAXROW ) ) CPPUNIT_ASSERT( !aMark.IsCellMarked( nOutCol2, nOutRow2 ) ); - if ( ValidRow( nOutRow1 ) ) + if ( ValidRow( nOutRow1, MAXROW ) ) CPPUNIT_ASSERT( !aMark.IsCellMarked( nMidCol, nOutRow1 ) ); - if ( ValidCol( nOutCol1 ) ) + if ( ValidCol( nOutCol1, MAXCOL ) ) CPPUNIT_ASSERT( !aMark.IsCellMarked( nOutCol1, nMidRow ) ); - if ( ValidRow( nOutRow2 ) ) + if ( ValidRow( nOutRow2, MAXROW ) ) CPPUNIT_ASSERT( !aMark.IsCellMarked( nMidCol, nOutRow2 ) ); - if ( ValidCol( nOutCol2 ) ) + if ( ValidCol( nOutCol2, MAXCOL ) ) CPPUNIT_ASSERT( !aMark.IsCellMarked( nOutCol2, nMidRow ) ); if ( rRange.aStart.Row() == 0 && rRange.aEnd.Row() == MAXROW ) diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index e8c643f4d5ba..1b62cc1eecb4 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -4600,7 +4600,7 @@ void Test::testFormulaPosition() namespace { -bool hasRange(const std::vector<ScTokenRef>& rRefTokens, const ScRange& rRange, const ScAddress& rPos) +bool hasRange(const ScDocument* pDoc, const std::vector<ScTokenRef>& rRefTokens, const ScRange& rRange, const ScAddress& rPos) { for (const ScTokenRef& p : rRefTokens) { @@ -4615,7 +4615,7 @@ bool hasRange(const std::vector<ScTokenRef>& rRefTokens, const ScRange& rRange, if (rRange.aStart != rRange.aEnd) break; - ScAddress aThis = aData.toAbs(rPos); + ScAddress aThis = aData.toAbs(pDoc, rPos); if (aThis == rRange.aStart) return true; } @@ -4623,7 +4623,7 @@ bool hasRange(const std::vector<ScTokenRef>& rRefTokens, const ScRange& rRange, case formula::svDoubleRef: { ScComplexRefData aData = *p->GetDoubleRef(); - ScRange aThis = aData.toAbs(rPos); + ScRange aThis = aData.toAbs(pDoc, rPos); if (aThis == rRange) return true; } @@ -4656,9 +4656,9 @@ void Test::testJumpToPrecedentsDependents() ScRangeList aRange(aC1); rDocFunc.DetectiveCollectAllPreds(aRange, aRefTokens); CPPUNIT_ASSERT_MESSAGE("A1:A2 should be a precedent of C1.", - hasRange(aRefTokens, ScRange(0, 0, 0, 0, 1, 0), aC1)); + hasRange(m_pDoc, aRefTokens, ScRange(0, 0, 0, 0, 1, 0), aC1)); CPPUNIT_ASSERT_MESSAGE("B3 should be a precedent of C1.", - hasRange(aRefTokens, ScRange(1, 2, 0), aC1)); + hasRange(m_pDoc, aRefTokens, ScRange(1, 2, 0), aC1)); } { @@ -4669,7 +4669,7 @@ void Test::testJumpToPrecedentsDependents() CPPUNIT_ASSERT_EQUAL_MESSAGE("there should only be one reference token.", static_cast<size_t>(1), aRefTokens.size()); CPPUNIT_ASSERT_MESSAGE("A1 should be a precedent of C1.", - hasRange(aRefTokens, ScRange(0, 0, 0), aC2)); + hasRange(m_pDoc, aRefTokens, ScRange(0, 0, 0), aC2)); } { @@ -4678,7 +4678,7 @@ void Test::testJumpToPrecedentsDependents() ScRangeList aRange(aA1); rDocFunc.DetectiveCollectAllSuccs(aRange, aRefTokens); CPPUNIT_ASSERT_MESSAGE("C1:C2 should be the only dependent of A1.", - aRefTokens.size() == 1 && hasRange(aRefTokens, ScRange(2, 0, 0, 2, 1, 0), aA1)); + aRefTokens.size() == 1 && hasRange(m_pDoc, aRefTokens, ScRange(2, 0, 0, 2, 1, 0), aA1)); } m_pDoc->DeleteTab(0); diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx index 5c93d3083111..6219a65d35c7 100644 --- a/sc/qa/unit/ucalc_formula.cxx +++ b/sc/qa/unit/ucalc_formula.cxx @@ -946,6 +946,8 @@ void Test::testFormulaTokenEquality() void Test::testFormulaRefData() { + std::unique_ptr<ScDocument> pDoc = std::make_unique<ScDocument>(); + ScAddress aAddr(4,5,3), aPos(2,2,2); ScSingleRefData aRef; aRef.InitAddress(aAddr); @@ -957,7 +959,7 @@ void Test::testFormulaRefData() aRef.SetRowRel(true); aRef.SetColRel(true); aRef.SetTabRel(true); - aRef.SetAddress(aAddr, aPos); + aRef.SetAddress(pDoc->GetSheetLimits(), aAddr, aPos); CPPUNIT_ASSERT_EQUAL(SCCOL(2), aRef.Col()); CPPUNIT_ASSERT_EQUAL(SCROW(3), aRef.Row()); CPPUNIT_ASSERT_EQUAL(SCTAB(1), aRef.Tab()); @@ -969,15 +971,15 @@ void Test::testFormulaRefData() aRef.InitAddress(ScAddress(6,5,0)); - aDoubleRef.Extend(aRef, ScAddress()); - ScRange aTest = aDoubleRef.toAbs(ScAddress()); + aDoubleRef.Extend(pDoc->GetSheetLimits(), aRef, ScAddress()); + ScRange aTest = aDoubleRef.toAbs(pDoc.get(), ScAddress()); CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong start position of extended range.", ScAddress(2,2,0), aTest.aStart); CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong end position of extended range.", ScAddress(6,5,0), aTest.aEnd); ScComplexRefData aDoubleRef2; - aDoubleRef2.InitRangeRel(ScRange(1,2,0,8,6,0), ScAddress(5,5,0)); - aDoubleRef.Extend(aDoubleRef2, ScAddress(5,5,0)); - aTest = aDoubleRef.toAbs(ScAddress(5,5,0)); + aDoubleRef2.InitRangeRel(pDoc.get(), ScRange(1,2,0,8,6,0), ScAddress(5,5,0)); + aDoubleRef.Extend(pDoc->GetSheetLimits(), aDoubleRef2, ScAddress(5,5,0)); + aTest = aDoubleRef.toAbs(pDoc.get(), ScAddress(5,5,0)); CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong start position of extended range.", ScAddress(1,2,0), aTest.aStart); CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong end position of extended range.", ScAddress(8,6,0), aTest.aEnd); @@ -1198,7 +1200,7 @@ void Test::testFormulaCompilerImplicitIntersection2Param() CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong type of token(third argument to SUMIF)", svDoubleRef, ppTokens[2]->GetType()); ScComplexRefData aSumRangeData = *ppTokens[2]->GetDoubleRef(); - ScRange aSumRange = aSumRangeData.toAbs(rCase.aCellAddress); + ScRange aSumRange = aSumRangeData.toAbs(m_pDoc, rCase.aCellAddress); CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong sum-range in RPN array", rCase.aSumRange, aSumRange); CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong IsRel type for start column address in sum-range", rCase.bStartColRel, aSumRangeData.Ref1.IsColRel()); @@ -1379,7 +1381,7 @@ void Test::testFormulaCompilerImplicitIntersection1ParamWithChange() CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong type of RPN token(argument to COS)", svSingleRef, ppRPNTokens[0]->GetType()); ScSingleRefData aArgAddrRPN = *ppRPNTokens[0]->GetSingleRef(); - ScAddress aArgAddrActual = aArgAddrRPN.toAbs(rCase.aCellAddress); + ScAddress aArgAddrActual = aArgAddrRPN.toAbs(m_pDoc, rCase.aCellAddress); CPPUNIT_ASSERT_EQUAL_MESSAGE("Computed implicit intersection singleref is wrong", rCase.aArgAddr, aArgAddrActual); } } diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx index 45e4994481ed..0c3f06d46602 100644 --- a/sc/qa/unit/ucalc_sharedformula.cxx +++ b/sc/qa/unit/ucalc_sharedformula.cxx @@ -1048,7 +1048,7 @@ void Test::testSharedFormulasDeleteColumns() CPPUNIT_ASSERT_EQUAL(svSingleRef, pToken->GetType()); const ScSingleRefData* pSRef = pToken->GetSingleRef(); CPPUNIT_ASSERT(pSRef->IsColDeleted()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(0), pSRef->toAbs(ScAddress(1,0,0)).Row()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(0), pSRef->toAbs(m_pDoc, ScAddress(1,0,0)).Row()); // The formula string should show #REF! in lieu of the column position (only for Calc A1 syntax). sc::CompileFormulaContext aCFCxt(m_pDoc, FormulaGrammar::GRAM_ENGLISH); diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx index e282ca78c5a1..2da00e1f03d6 100644 --- a/sc/source/core/data/colorscale.cxx +++ b/sc/source/core/data/colorscale.cxx @@ -54,8 +54,8 @@ void ScFormulaListener::startListening(const ScTokenArray* pArr, const ScRange& { case formula::svSingleRef: { - ScAddress aCell = t->GetSingleRef()->toAbs(rRange.aStart); - ScAddress aCell2 = t->GetSingleRef()->toAbs(rRange.aEnd); + ScAddress aCell = t->GetSingleRef()->toAbs(mpDoc, rRange.aStart); + ScAddress aCell2 = t->GetSingleRef()->toAbs(mpDoc, rRange.aEnd); ScRange aRange(aCell, aCell2); if (aRange.IsValid()) mpDoc->StartListeningArea(aRange, false, this); @@ -65,10 +65,10 @@ void ScFormulaListener::startListening(const ScTokenArray* pArr, const ScRange& { const ScSingleRefData& rRef1 = *t->GetSingleRef(); const ScSingleRefData& rRef2 = *t->GetSingleRef2(); - ScAddress aCell1 = rRef1.toAbs(rRange.aStart); - ScAddress aCell2 = rRef2.toAbs(rRange.aStart); - ScAddress aCell3 = rRef1.toAbs(rRange.aEnd); - ScAddress aCell4 = rRef2.toAbs(rRange.aEnd); + ScAddress aCell1 = rRef1.toAbs(mpDoc, rRange.aStart); + ScAddress aCell2 = rRef2.toAbs(mpDoc, rRange.aStart); + ScAddress aCell3 = rRef1.toAbs(mpDoc, rRange.aEnd); + ScAddress aCell4 = rRef2.toAbs(mpDoc, rRange.aEnd); ScRange aRange1(aCell1, aCell3); ScRange aRange2(aCell2, aCell4); aRange1.ExtendTo(aRange2); diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index fcc0e00de4bd..3cfe18891f63 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -2501,7 +2501,7 @@ bool ScColumn::UpdateReference( sc::RefUpdateContext& rCxt, ScDocument* pUndoDoc } // Do the actual splitting. - const bool bSplit = sc::SharedFormulaUtil::splitFormulaCellGroups(maCells, aBounds); + const bool bSplit = sc::SharedFormulaUtil::splitFormulaCellGroups(GetDoc(), maCells, aBounds); // Collect all formula groups. std::vector<sc::FormulaGroupEntry> aGroups = GetFormulaGroupEntries(); diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx index b684a87c84d1..3431f21ae80d 100644 --- a/sc/source/core/data/column4.cxx +++ b/sc/source/core/data/column4.cxx @@ -440,7 +440,7 @@ void ScColumn::ConvertFormulaToValue( aBounds.push_back(nRow2+1); // Split formula cell groups at top and bottom boundaries (if applicable). - sc::SharedFormulaUtil::splitFormulaCellGroups(maCells, aBounds); + sc::SharedFormulaUtil::splitFormulaCellGroups(GetDoc(), maCells, aBounds); // Parse all formulas within the range and store their results into temporary storage. ConvertFormulaToValueHandler aFunc; @@ -501,7 +501,7 @@ void ScColumn::SwapNonEmpty( aBounds.push_back(rRange.aEnd.Row()+1); // Split formula cell groups at top and bottom boundaries (if applicable). - sc::SharedFormulaUtil::splitFormulaCellGroups(maCells, aBounds); + sc::SharedFormulaUtil::splitFormulaCellGroups(GetDoc(), maCells, aBounds); std::vector<sc::CellValueSpan> aSpans = rValues.getNonEmptySpans(nTab, nCol); // Detach formula cells within the spans (if any). @@ -1197,13 +1197,13 @@ void ScColumn::SplitFormulaGroupByRelativeRef( const ScRange& rBoundRange ) aBounds.push_back(rBoundRange.aStart.Row()); if (rBoundRange.aEnd.Row() < GetDoc()->MaxRow()) aBounds.push_back(rBoundRange.aEnd.Row()+1); - sc::SharedFormulaUtil::splitFormulaCellGroups(maCells, aBounds); + sc::SharedFormulaUtil::splitFormulaCellGroups(GetDoc(), maCells, aBounds); RelativeRefBoundChecker aFunc(rBoundRange); sc::ProcessFormula( maCells.begin(), maCells, rBoundRange.aStart.Row(), rBoundRange.aEnd.Row(), aFunc); aFunc.swapBounds(aBounds); - sc::SharedFormulaUtil::splitFormulaCellGroups(maCells, aBounds); + sc::SharedFormulaUtil::splitFormulaCellGroups(GetDoc(), maCells, aBounds); } namespace { diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx index 72110495ba91..6a150a82c60c 100644 --- a/sc/source/core/data/conditio.cxx +++ b/sc/source/core/data/conditio.cxx @@ -1336,7 +1336,7 @@ ScAddress ScConditionEntry::GetValidSrcPos() const for ( auto t: pFormula->References() ) { ScSingleRefData& rRef1 = *t->GetSingleRef(); - ScAddress aAbs = rRef1.toAbs(aSrcPos); + ScAddress aAbs = rRef1.toAbs(mpDoc, aSrcPos); if (!rRef1.IsTabDeleted()) { if (aAbs.Tab() < nMinTab) @@ -1347,7 +1347,7 @@ ScAddress ScConditionEntry::GetValidSrcPos() const if ( t->GetType() == svDoubleRef ) { ScSingleRefData& rRef2 = t->GetDoubleRef()->Ref2; - aAbs = rRef2.toAbs(aSrcPos); + aAbs = rRef2.toAbs(mpDoc, aSrcPos); if (!rRef2.IsTabDeleted()) { if (aAbs.Tab() < nMinTab) diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx index 22c0ecfae717..871d0cba34cc 100644 --- a/sc/source/core/data/documen4.cxx +++ b/sc/source/core/data/documen4.cxx @@ -311,7 +311,7 @@ void ScDocument::InsertMatrixFormula(SCCOL nCol1, SCROW nRow1, aRefData.SetColRel( true ); aRefData.SetRowRel( true ); aRefData.SetTabRel( true ); - aRefData.SetAddress(aBasePos, aBasePos); + aRefData.SetAddress(GetSheetLimits(), aBasePos, aBasePos); ScTokenArray aArr(this); // consists only of one single reference token. formula::FormulaToken* t = aArr.AddMatrixSingleReference(aRefData); @@ -342,7 +342,7 @@ void ScDocument::InsertMatrixFormula(SCCOL nCol1, SCROW nRow1, // Token array must be cloned so that each formula cell receives its own copy. aPos = ScAddress(nCol, nRow, nTab); // Reference in each cell must point to the origin cell relative to the current cell. - aRefData.SetAddress(aBasePos, aPos); + aRefData.SetAddress(GetSheetLimits(), aBasePos, aPos); *t->GetSingleRef() = aRefData; std::unique_ptr<ScTokenArray> pTokArr(aArr.Clone()); pCell = new ScFormulaCell(this, aPos, *pTokArr, eGram, ScMatrixMode::Reference); @@ -453,7 +453,7 @@ void ScDocument::InsertTableOp(const ScTabOpParam& rParam, // multiple (repeate namespace { -bool setCacheTableReferenced(formula::FormulaToken& rToken, ScExternalRefManager& rRefMgr, const ScAddress& rPos) +bool setCacheTableReferenced(const ScDocument* pDoc, formula::FormulaToken& rToken, ScExternalRefManager& rRefMgr, const ScAddress& rPos) { switch (rToken.GetType()) { @@ -463,7 +463,7 @@ bool setCacheTableReferenced(formula::FormulaToken& rToken, ScExternalRefManager case svExternalDoubleRef: { const ScComplexRefData& rRef = *rToken.GetDoubleRef(); - ScRange aAbs = rRef.toAbs(rPos); + ScRange aAbs = rRef.toAbs(pDoc, rPos); size_t nSheets = aAbs.aEnd.Tab() - aAbs.aStart.Tab() + 1; return rRefMgr.setCacheTableReferenced( rToken.GetIndex(), rToken.GetString().getString(), nSheets); @@ -498,7 +498,7 @@ bool ScDocument::MarkUsedExternalReferences( const ScTokenArray& rArr, const ScA if (!pRefMgr) pRefMgr = GetExternalRefManager(); - bAllMarked = setCacheTableReferenced(*t, *pRefMgr, rPos); + bAllMarked = setCacheTableReferenced(this, *t, *pRefMgr, rPos); } else if (t->GetType() == svIndex) { @@ -518,7 +518,7 @@ bool ScDocument::MarkUsedExternalReferences( const ScTokenArray& rArr, const ScA if (!pRefMgr) pRefMgr = GetExternalRefManager(); - bAllMarked = setCacheTableReferenced(*t, *pRefMgr, rPos); + bAllMarked = setCacheTableReferenced(this, *t, *pRefMgr, rPos); } } } diff --git a/sc/source/core/data/documentimport.cxx b/sc/source/core/data/documentimport.cxx index e73a6c3831f1..46d1638fbe48 100644 --- a/sc/source/core/data/documentimport.cxx +++ b/sc/source/core/data/documentimport.cxx @@ -407,7 +407,7 @@ void ScDocumentImport::setMatrixCells( aRefData.SetColRel(true); aRefData.SetRowRel(true); aRefData.SetTabRel(true); - aRefData.SetAddress(rBasePos, rBasePos); + aRefData.SetAddress(mpImpl->mrDoc.GetSheetLimits(), rBasePos, rBasePos); ScTokenArray aArr(&mpImpl->mrDoc); // consists only of one single reference token. formula::FormulaToken* t = aArr.AddMatrixSingleReference(aRefData); @@ -418,7 +418,7 @@ void ScDocumentImport::setMatrixCells( // Token array must be cloned so that each formula cell receives its own copy. aPos.SetRow(nRow); // Reference in each cell must point to the origin cell relative to the current cell. - aRefData.SetAddress(rBasePos, aPos); + aRefData.SetAddress(mpImpl->mrDoc.GetSheetLimits(), rBasePos, aPos); *t->GetSingleRef() = aRefData; std::unique_ptr<ScTokenArray> pTokArr(aArr.Clone()); pCell = new ScFormulaCell(&mpImpl->mrDoc, aPos, *pTokArr, eGram, ScMatrixMode::Reference); @@ -438,7 +438,7 @@ void ScDocumentImport::setMatrixCells( for (SCROW nRow = rRange.aStart.Row(); nRow <= rRange.aEnd.Row(); ++nRow) { aPos.SetRow(nRow); - aRefData.SetAddress(rBasePos, aPos); + aRefData.SetAddress(mpImpl->mrDoc.GetSheetLimits(), rBasePos, aPos); *t->GetSingleRef() = aRefData; std::unique_ptr<ScTokenArray> pTokArr(aArr.Clone()); pCell = new ScFormulaCell(&mpImpl->mrDoc, aPos, *pTokArr, eGram, ScMatrixMode::Reference); diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index 693eeb6c678b..5bb89a1ff421 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -228,42 +228,44 @@ namespace { // Allow for a year's calendar (366). const sal_uInt16 MAXRECURSION = 400; -typedef SCCOLROW(*DimensionSelector)(const ScAddress&, const ScSingleRefData&); +typedef SCCOLROW(*DimensionSelector)(const ScDocument*, const ScAddress&, const ScSingleRefData&); -SCCOLROW lcl_GetCol(const ScAddress& rPos, const ScSingleRefData& rData) +SCCOLROW lcl_GetCol(const ScDocument* pDoc, const ScAddress& rPos, const ScSingleRefData& rData) { - return rData.toAbs(rPos).Col(); + return rData.toAbs(pDoc, rPos).Col(); } -SCCOLROW lcl_GetRow(const ScAddress& rPos, const ScSingleRefData& rData) +SCCOLROW lcl_GetRow(const ScDocument* pDoc, const ScAddress& rPos, const ScSingleRefData& rData) { - return rData.toAbs(rPos).Row(); + return rData.toAbs(pDoc, rPos).Row(); } -SCCOLROW lcl_GetTab(const ScAddress& rPos, const ScSingleRefData& rData) +SCCOLROW lcl_GetTab(const ScDocument* pDoc, const ScAddress& rPos, const ScSingleRefData& rData) { - return rData.toAbs(rPos).Tab(); + return rData.toAbs(pDoc, rPos).Tab(); } /** Check if both references span the same range in selected dimension. */ bool lcl_checkRangeDimension( + const ScDocument* pDoc, const ScAddress& rPos, const SingleDoubleRefProvider& rRef1, const SingleDoubleRefProvider& rRef2, const DimensionSelector aWhich) { - return aWhich(rPos, rRef1.Ref1) == aWhich(rPos, rRef2.Ref1) && - aWhich(rPos, rRef1.Ref2) == aWhich(rPos, rRef2.Ref2); + return aWhich(pDoc, rPos, rRef1.Ref1) == aWhich(pDoc, rPos, rRef2.Ref1) && + aWhich(pDoc, rPos, rRef1.Ref2) == aWhich(pDoc, rPos, rRef2.Ref2); } bool lcl_checkRangeDimensions( + const ScDocument* pDoc, const ScAddress& rPos, const SingleDoubleRefProvider& rRef1, const SingleDoubleRefProvider& rRef2, bool& bCol, bool& bRow, bool& bTab) { - const bool bSameCols(lcl_checkRangeDimension(rPos, rRef1, rRef2, lcl_GetCol)); - const bool bSameRows(lcl_checkRangeDimension(rPos, rRef1, rRef2, lcl_GetRow)); - const bool bSameTabs(lcl_checkRangeDimension(rPos, rRef1, rRef2, lcl_GetTab)); + const bool bSameCols(lcl_checkRangeDimension(pDoc, rPos, rRef1, rRef2, lcl_GetCol)); + const bool bSameRows(lcl_checkRangeDimension(pDoc, rPos, rRef1, rRef2, lcl_GetRow)); + const bool bSameTabs(lcl_checkRangeDimension(pDoc, rPos, rRef1, rRef2, lcl_GetTab)); // Test if exactly two dimensions are equal if (int(bSameCols) + int(bSameRows) + int(bSameTabs) == 2) @@ -281,7 +283,7 @@ lcl_checkRangeDimensions( */ bool lcl_checkRangeDimensions( - const ScAddress& rPos, + const ScDocument* pDoc, const ScAddress& rPos, const std::vector<formula::FormulaToken*>::const_iterator& rBegin, const std::vector<formula::FormulaToken*>::const_iterator& rEnd, bool& bCol, bool& bRow, bool& bTab) @@ -292,7 +294,7 @@ lcl_checkRangeDimensions( bool bOk(false); { const SingleDoubleRefProvider aRefCur(**aCur); - bOk = lcl_checkRangeDimensions(rPos, aRef, aRefCur, bCol, bRow, bTab); + bOk = lcl_checkRangeDimensions(pDoc, rPos, aRef, aRefCur, bCol, bRow, bTab); } while (bOk && aCur != rEnd) { @@ -300,7 +302,7 @@ lcl_checkRangeDimensions( bool bColTmp(false); bool bRowTmp(false); bool bTabTmp(false); - bOk = lcl_checkRangeDimensions(rPos, aRef, aRefCur, bColTmp, bRowTmp, bTabTmp); + bOk = lcl_checkRangeDimensions(pDoc, rPos, aRef, aRefCur, bColTmp, bRowTmp, bTabTmp); bOk = bOk && (bCol == bColTmp && bRow == bRowTmp && bTab == bTabTmp); ++aCur; } @@ -310,17 +312,18 @@ lcl_checkRangeDimensions( class LessByReference { + const ScDocument* mpDoc; ScAddress const maPos; DimensionSelector const maFunc; public: - LessByReference(const ScAddress& rPos, const DimensionSelector& rFunc) : - maPos(rPos), maFunc(rFunc) {} + LessByReference(const ScDocument* pDoc, const ScAddress& rPos, const DimensionSelector& rFunc) : + mpDoc(pDoc), maPos(rPos), maFunc(rFunc) {} bool operator() (const formula::FormulaToken* pRef1, const formula::FormulaToken* pRef2) { const SingleDoubleRefProvider aRef1(*pRef1); const SingleDoubleRefProvider aRef2(*pRef2); - return maFunc(maPos, aRef1.Ref1) < maFunc(maPos, aRef2.Ref1); + return maFunc(mpDoc, maPos, aRef1.Ref1) < maFunc(mpDoc, maPos, aRef2.Ref1); } }; @@ -331,22 +334,24 @@ public: */ class AdjacentByReference { + const ScDocument* mpDoc; ScAddress const maPos; DimensionSelector const maFunc; public: - AdjacentByReference(const ScAddress& rPos, DimensionSelector aFunc) : - maPos(rPos), maFunc(aFunc) {} + AdjacentByReference(const ScDocument* pDoc, const ScAddress& rPos, DimensionSelector aFunc) : + mpDoc(pDoc), maPos(rPos), maFunc(aFunc) {} bool operator() (const formula::FormulaToken* p1, const formula::FormulaToken* p2) { const SingleDoubleRefProvider aRef1(*p1); const SingleDoubleRefProvider aRef2(*p2); - return maFunc(maPos, aRef2.Ref1) - maFunc(maPos, aRef1.Ref2) == 1; + return maFunc(mpDoc, maPos, aRef2.Ref1) - maFunc(mpDoc, maPos, aRef1.Ref2) == 1; } }; bool lcl_checkIfAdjacent( + const ScDocument* pDoc, const ScAddress& rPos, const std::vector<formula::FormulaToken*>& rReferences, const DimensionSelector aWhich) { auto aBegin(rReferences.cbegin()); @@ -354,36 +359,38 @@ lcl_checkIfAdjacent( auto aBegin1(aBegin); ++aBegin1; --aEnd; - return std::equal(aBegin, aEnd, aBegin1, AdjacentByReference(rPos, aWhich)); + return std::equal(aBegin, aEnd, aBegin1, AdjacentByReference(pDoc, rPos, aWhich)); } void lcl_fillRangeFromRefList( + const ScDocument* pDoc, const ScAddress& aPos, const std::vector<formula::FormulaToken*>& rReferences, ScRange& rRange) { const ScSingleRefData aStart( SingleDoubleRefProvider(*rReferences.front()).Ref1); - rRange.aStart = aStart.toAbs(aPos); + rRange.aStart = aStart.toAbs(pDoc, aPos); const ScSingleRefData aEnd( SingleDoubleRefProvider(*rReferences.back()).Ref2); - rRange.aEnd = aEnd.toAbs(aPos); + rRange.aEnd = aEnd.toAbs(pDoc, aPos); } bool lcl_refListFormsOneRange( + const ScDocument* pDoc, const ScAddress& rPos, std::vector<formula::FormulaToken*>& rReferences, ScRange& rRange) { if (rReferences.size() == 1) { - lcl_fillRangeFromRefList(rPos, rReferences, rRange); + lcl_fillRangeFromRefList(pDoc, rPos, rReferences, rRange); return true; } bool bCell(false); bool bRow(false); bool bTab(false); - if (lcl_checkRangeDimensions(rPos, rReferences.begin(), rReferences.end(), bCell, bRow, bTab)) + if (lcl_checkRangeDimensions(pDoc, rPos, rReferences.begin(), rReferences.end(), bCell, bRow, bTab)) { DimensionSelector aWhich; if (bCell) @@ -405,10 +412,10 @@ lcl_refListFormsOneRange( } // Sort the references by start of range - std::sort(rReferences.begin(), rReferences.end(), LessByReference(rPos, aWhich)); - if (lcl_checkIfAdjacent(rPos, rReferences, aWhich)) + std::sort(rReferences.begin(), rReferences.end(), LessByReference(pDoc, rPos, aWhich)); + if (lcl_checkIfAdjacent(pDoc, rPos, rReferences, aWhich)) { - lcl_fillRangeFromRefList(rPos, rReferences, rRange); + lcl_fillRangeFromRefList(pDoc, rPos, rReferences, rRange); return true; } } @@ -982,7 +989,7 @@ void ScFormulaCell::GetFormula( OUStringBuffer& rBuffer, * Can we live without in all cases? */ ScFormulaCell* pCell = nullptr; ScSingleRefData& rRef = *p->GetSingleRef(); - ScAddress aAbs = rRef.toAbs(aPos); + ScAddress aAbs = rRef.toAbs(pDocument, aPos); if (pDocument->ValidAddress(aAbs)) pCell = pDocument->GetFormulaCell(aAbs); @@ -1048,7 +1055,7 @@ OUString ScFormulaCell::GetFormula( sc::CompileFormulaContext& rCxt, const ScInt * Can we live without in all cases? */ ScFormulaCell* pCell = nullptr; ScSingleRefData& rRef = *p->GetSingleRef(); - ScAddress aAbs = rRef.toAbs(aPos); + ScAddress aAbs = rRef.toAbs(pDocument, aPos); if (pDocument->ValidAddress(aAbs)) pCell = pDocument->GetFormulaCell(aAbs); @@ -2814,7 +2821,7 @@ bool ScFormulaCell::GetMatrixOrigin( const ScDocument* pDoc, ScAddress& rPos ) c if( t ) { ScSingleRefData& rRef = *t->GetSingleRef(); - ScAddress aAbs = rRef.toAbs(aPos); + ScAddress aAbs = rRef.toAbs(pDoc, aPos); if (pDoc->ValidAddress(aAbs)) { rPos = aAbs; @@ -2998,8 +3005,8 @@ bool ScFormulaCell::HasOneReference( ScRange& r ) const if( p && !aIter.GetNextReferenceRPN() ) // only one! { SingleDoubleRefProvider aProv( *p ); - r.aStart = aProv.Ref1.toAbs(aPos); - r.aEnd = aProv.Ref2.toAbs(aPos); + r.aStart = aProv.Ref1.toAbs(pDocument, aPos); + r.aEnd = aProv.Ref2.toAbs(pDocument, aPos); return true; } else @@ -3053,7 +3060,7 @@ ScFormulaCell::HasRefListExpressibleAsOneReference(ScRange& rRange) const if (pFunction && !aIter.GetNextReferenceRPN() && (pFunction->GetParamCount() == aReferences.size())) { - return lcl_refListFormsOneRange(aPos, aReferences, rRange); + return lcl_refListFormsOneRange(pDocument, aPos, aReferences, rRange); } } return false; @@ -3138,7 +3145,7 @@ bool checkCompileColRowName( ScSingleRefData& rRef = *t->GetSingleRef(); if (rCxt.mnRowDelta > 0 && rRef.IsColRel()) { // ColName - ScAddress aAdr = rRef.toAbs(aPos); + ScAddress aAdr = rRef.toAbs(&rDoc, aPos); ScRangePair* pR = pColList->Find( aAdr ); if ( pR ) { // defined @@ -3153,7 +3160,7 @@ bool checkCompileColRowName( } if (rCxt.mnColDelta > 0 && rRef.IsRowRel()) { // RowName - ScAddress aAdr = rRef.toAbs(aPos); + ScAddress aAdr = rRef.toAbs(&rDoc, aPos); ScRangePair* pR = pRowList->Find( aAdr ); if ( pR ) { // defined @@ -3181,7 +3188,7 @@ bool checkCompileColRowName( for (; t; t = aIter.GetNextColRowName()) { const ScSingleRefData& rRef = *t->GetSingleRef(); - ScAddress aAbs = rRef.toAbs(aPos); + ScAddress aAbs = rRef.toAbs(&rDoc, aPos); if (rDoc.ValidAddress(aAbs)) { if (rCxt.maRange.In(aAbs)) @@ -3804,11 +3811,11 @@ void ScFormulaCell::UpdateTranspose( const ScRange& rSource, const ScAddress& rD { SingleDoubleRefModifier aMod(*t); ScComplexRefData& rRef = aMod.Ref(); - ScRange aAbs = rRef.toAbs(aOldPos); + ScRange aAbs = rRef.toAbs(pDocument, aOldPos); bool bMod = (ScRefUpdate::UpdateTranspose(pDocument, rSource, rDest, aAbs) != UR_NOTHING || bPosChanged); if (bMod) { - rRef.SetRange(aAbs, aPos); // based on the new anchor position. + rRef.SetRange(pDocument->GetSheetLimits(), aAbs, aPos); // based on the new anchor position. bRefChanged = true; } } @@ -3854,11 +3861,11 @@ void ScFormulaCell::UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY { SingleDoubleRefModifier aMod(*t); ScComplexRefData& rRef = aMod.Ref(); - ScRange aAbs = rRef.toAbs(aPos); + ScRange aAbs = rRef.toAbs(pDocument, aPos); bool bMod = (ScRefUpdate::UpdateGrow(rArea, nGrowX, nGrowY, aAbs) != UR_NOTHING); if (bMod) { - rRef.SetRange(aAbs, aPos); + rRef.SetRange(pDocument->GetSheetLimits(), aAbs, aPos); bRefChanged = true; } } @@ -4428,7 +4435,7 @@ struct ScDependantsCalculator ScSingleRefData aRef = *p->GetSingleRef(); // =Sheet1!A1 if( aRef.IsDeleted()) return false; - ScAddress aRefPos = aRef.toAbs(mrPos); + ScAddress aRefPos = aRef.toAbs(&mrDoc, mrPos); if (!mrDoc.TableExists(aRefPos.Tab())) return false; // or true? @@ -4464,7 +4471,7 @@ struct ScDependantsCalculator ScComplexRefData aRef = *p->GetDoubleRef(); if( aRef.IsDeleted()) return false; - ScRange aAbs = aRef.toAbs(mrPos); + ScRange aAbs = aRef.toAbs(&mrDoc, mrPos); // Multiple sheet if (aRef.Ref1.Tab() != aRef.Ref2.Tab()) @@ -5122,7 +5129,7 @@ bool ScFormulaCell::InterpretInvariantFormulaGroup() case svSingleRef: { ScSingleRefData aRef = *p->GetSingleRef(); - ScAddress aRefPos = aRef.toAbs(aPos); + ScAddress aRefPos = aRef.toAbs(pDocument, aPos); formula::FormulaTokenRef pNewToken = pDocument->ResolveStaticReference(aRefPos); if (!pNewToken) return false; @@ -5133,7 +5140,7 @@ bool ScFormulaCell::InterpretInvariantFormulaGroup() case svDoubleRef: { ScComplexRefData aRef = *p->GetDoubleRef(); - ScRange aRefRange = aRef.toAbs(aPos); + ScRange aRefRange = aRef.toAbs(pDocument, aPos); formula::FormulaTokenRef pNewToken = pDocument->ResolveStaticReference(aRefRange); if (!pNewToken) return false; @@ -5189,8 +5196,8 @@ void startListeningArea( { const ScSingleRefData& rRef1 = *rToken.GetSingleRef(); const ScSingleRefData& rRef2 = *rToken.GetSingleRef2(); - ScAddress aCell1 = rRef1.toAbs(rPos); - ScAddress aCell2 = rRef2.toAbs(rPos); + ScAddress aCell1 = rRef1.toAbs(&rDoc, rPos); + ScAddress aCell2 = rRef2.toAbs(&rDoc, rPos); if (aCell1.IsValid() && aCell2.IsValid()) { if (rToken.GetOpCode() == ocColRowNameAuto) @@ -5236,7 +5243,7 @@ void ScFormulaCell::StartListeningTo( ScDocument* pDoc ) { case svSingleRef: { - ScAddress aCell = t->GetSingleRef()->toAbs(aPos); + ScAddress aCell = t->GetSingleRef()->toAbs(pDocument, aPos); if (aCell.IsValid()) pDoc->StartListeningCell(aCell, this); } @@ -5279,7 +5286,7 @@ void ScFormulaCell::StartListeningTo( sc::StartListeningContext& rCxt ) { case svSingleRef: { - ScAddress aCell = t->GetSingleRef()->toAbs(aPos); + ScAddress aCell = t->GetSingleRef()->toAbs(pDocument, aPos); if (aCell.IsValid()) rDoc.StartListeningCell(rCxt, aCell, *this); } @@ -5301,8 +5308,8 @@ void endListeningArea( { const ScSingleRefData& rRef1 = *rToken.GetSingleRef(); const ScSingleRefData& rRef2 = *rToken.GetSingleRef2(); - ScAddress aCell1 = rRef1.toAbs(rPos); - ScAddress aCell2 = rRef2.toAbs(rPos); + ScAddress aCell1 = rRef1.toAbs(&rDoc, rPos); + ScAddress aCell2 = rRef2.toAbs(&rDoc, rPos); if (aCell1.IsValid() && aCell2.IsValid()) { if (rToken.GetOpCode() == ocColRowNameAuto) @@ -5356,7 +5363,7 @@ void ScFormulaCell::EndListeningTo( ScDocument* pDoc, ScTokenArray* pArr, { case svSingleRef: { - ScAddress aCell = t->GetSingleRef()->toAbs(aCellPos); + ScAddress aCell = t->GetSingleRef()->toAbs(pDocument, aCellPos); if (aCell.IsValid()) pDoc->EndListeningCell(aCell, this); } @@ -5403,7 +5410,7 @@ void ScFormulaCell::EndListeningTo( sc::EndListeningContext& rCxt ) { case svSingleRef: { - ScAddress aCell = t->GetSingleRef()->toAbs(aCellPos); + ScAddress aCell = t->GetSingleRef()->toAbs(pDocument, aCellPos); if (aCell.IsValid()) rDoc.EndListeningCell(rCxt, aCell, *this); } diff --git a/sc/source/core/data/formulaiter.cxx b/sc/source/core/data/formulaiter.cxx index 4f71466888fa..7c27eb133864 100644 --- a/sc/source/core/data/formulaiter.cxx +++ b/sc/source/core/data/formulaiter.cxx @@ -36,13 +36,13 @@ ScDetectiveRefIter::ScDetectiveRefIter( const ScDocument* pDoc, ScFormulaCell* p static bool lcl_ScDetectiveRefIter_SkipRef( const ScDocument* pDoc, formula::FormulaToken* p, const ScAddress& rPos ) { ScSingleRefData& rRef1 = *p->GetSingleRef(); - ScAddress aAbs1 = rRef1.toAbs(rPos); + ScAddress aAbs1 = rRef1.toAbs(pDoc, rPos); if (!pDoc->ValidAddress(aAbs1)) return true; if ( p->GetType() == svDoubleRef || p->GetType() == svExternalDoubleRef ) { ScSingleRefData& rRef2 = p->GetDoubleRef()->Ref2; - ScAddress aAbs2 = rRef2.toAbs(rPos); + ScAddress aAbs2 = rRef2.toAbs(pDoc, rPos); if (!pDoc->ValidAddress(aAbs2)) return true; } @@ -56,8 +56,8 @@ bool ScDetectiveRefIter::GetNextRef( ScRange& rRange ) if( p ) { SingleDoubleRefProvider aProv( *p ); - rRange.aStart = aProv.Ref1.toAbs(aPos); - rRange.aEnd = aProv.Ref2.toAbs(aPos); + rRange.aStart = aProv.Ref1.toAbs(mpDoc, aPos); + rRange.aEnd = aProv.Ref2.toAbs(mpDoc, aPos); bRet = true; } diff --git a/sc/source/core/data/grouptokenconverter.cxx b/sc/source/core/data/grouptokenconverter.cxx index 9da4dc476ea2..ee79aedd5004 100644 --- a/sc/source/core/data/grouptokenconverter.cxx +++ b/sc/source/core/data/grouptokenconverter.cxx @@ -121,7 +121,7 @@ bool ScGroupTokenConverter::convert( const ScTokenArray& rCode, sc::FormulaLogge ScSingleRefData aRef = *p->GetSingleRef(); if( aRef.IsDeleted()) return false; - ScAddress aRefPos = aRef.toAbs(mrPos); + ScAddress aRefPos = aRef.toAbs(&mrDoc, mrPos); if (aRef.IsRowRel()) { if (isSelfReferenceRelative(aRefPos, aRef.Row())) @@ -192,7 +192,7 @@ bool ScGroupTokenConverter::convert( const ScTokenArray& rCode, sc::FormulaLogge ScComplexRefData aRef = *p->GetDoubleRef(); if( aRef.IsDeleted()) return false; - ScRange aAbs = aRef.toAbs(mrPos); + ScRange aAbs = aRef.toAbs(&mrDoc, mrPos); // Multiple sheets not handled by vector/matrix. if (aRef.Ref1.Tab() != aRef.Ref2.Tab()) diff --git a/sc/source/core/data/table7.cxx b/sc/source/core/data/table7.cxx index 29dd2ddc9041..38f1d02e3fd7 100644 --- a/sc/source/core/data/table7.cxx +++ b/sc/source/core/data/table7.cxx @@ -269,7 +269,7 @@ void ScTable::SplitFormulaGroups( SCCOL nCol, std::vector<SCROW>& rRows ) if (!IsColValid(nCol)) return; - sc::SharedFormulaUtil::splitFormulaCellGroups(aCol[nCol].maCells, rRows); + sc::SharedFormulaUtil::splitFormulaCellGroups(&GetDoc(), aCol[nCol].maCells, rRows); } void ScTable::UnshareFormulaCells( SCCOL nCol, std::vector<SCROW>& rRows ) diff --git a/sc/source/core/tool/address.cxx b/sc/source/core/tool/address.cxx index 930833057634..0ee1eeeb4862 100644 --- a/sc/source/core/tool/address.cxx +++ b/sc/source/core/tool/address.cxx @@ -2550,7 +2550,7 @@ bool AlphaToCol( const ScDocument* pDoc, SCCOL& rCol, const OUString& rStr) nResult += ScGlobal::ToUpperAlpha(c) - 'A'; ++nPos; } - bool bOk = (ValidCol(nResult) && nPos > 0); + bool bOk = (pDoc->ValidCol(nResult) && nPos > 0); if (bOk) rCol = nResult; return bOk; diff --git a/sc/source/core/tool/chartlis.cxx b/sc/source/core/tool/chartlis.cxx index fab194a2be5d..f5560479e109 100644 --- a/sc/source/core/tool/chartlis.cxx +++ b/sc/source/core/tool/chartlis.cxx @@ -186,7 +186,7 @@ void ScChartListener::Update() ScRangeListRef ScChartListener::GetRangeList() const { ScRangeListRef aRLRef(new ScRangeList); - ScRefTokenHelper::getRangeListFromTokens(*aRLRef, *mpTokens, ScAddress()); + ScRefTokenHelper::getRangeListFromTokens(mpDoc, *aRLRef, *mpTokens, ScAddress()); return aRLRef; } @@ -230,7 +230,7 @@ public: else { ScRange aRange; - ScRefTokenHelper::getRangeFromToken(aRange, pToken, ScAddress(), bExternal); + ScRefTokenHelper::getRangeFromToken(mpDoc, aRange, pToken, ScAddress(), bExternal); if (mbStart) startListening(aRange); else @@ -294,7 +294,7 @@ void ScChartListener::UpdateChartIntersecting( const ScRange& rRange ) ScTokenRef pToken; ScRefTokenHelper::getTokenFromRange(mpDoc, pToken, rRange); - if (ScRefTokenHelper::intersects(*mpTokens, pToken, ScAddress())) + if (ScRefTokenHelper::intersects(mpDoc, *mpTokens, pToken, ScAddress())) { // force update (chart has to be loaded), don't use ScChartListener::Update mpDoc->UpdateChart(GetName()); diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index 7f1460db8f51..f5d30d2e8f36 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -710,8 +710,8 @@ namespace { struct Convention_A1 : public ScCompiler::Convention { explicit Convention_A1( FormulaGrammar::AddressConvention eConv ) : ScCompiler::Convention( eConv ) { } - static void MakeColStr( OUStringBuffer& rBuffer, SCCOL nCol ); - static void MakeRowStr( OUStringBuffer& rBuffer, SCROW nRow ); + static void MakeColStr( ScSheetLimits& rLimits, OUStringBuffer& rBuffer, SCCOL nCol ); + static void MakeRowStr( ScSheetLimits& rLimits, OUStringBuffer& rBuffer, SCROW nRow ); ParseResult parseAnyToken( const OUString& rFormula, sal_Int32 nSrcPos, @@ -741,17 +741,17 @@ struct Convention_A1 : public ScCompiler::Convention } -void Convention_A1::MakeColStr( OUStringBuffer& rBuffer, SCCOL nCol ) +void Convention_A1::MakeColStr( ScSheetLimits& rLimits, OUStringBuffer& rBuffer, SCCOL nCol ) { - if ( !ValidCol( nCol) ) + if ( !rLimits.ValidCol(nCol) ) rBuffer.append(ScResId(STR_NO_REF_TABLE)); else ::ScColToAlpha( rBuffer, nCol); } -void Convention_A1::MakeRowStr( OUStringBuffer& rBuffer, SCROW nRow ) +void Convention_A1::MakeRowStr( ScSheetLimits& rLimits, OUStringBuffer& rBuffer, SCROW nRow ) { - if ( !ValidRow(nRow) ) + if ( !rLimits.ValidRow(nRow) ) rBuffer.append(ScResId(STR_NO_REF_TABLE)); else rBuffer.append(sal_Int32(nRow + 1)); @@ -781,7 +781,7 @@ struct ConventionOOO_A1 : public Convention_A1 }; static void MakeOneRefStrImpl( - OUStringBuffer& rBuffer, + ScSheetLimits& rLimits, OUStringBuffer& rBuffer, const OUString& rErrRef, const std::vector<OUString>& rTabNames, const ScSingleRefData& rRef, const ScAddress& rAbsRef, bool bForceTab, bool bODF, SingletonDisplay eSingletonDisplay ) @@ -815,20 +815,20 @@ struct ConventionOOO_A1 : public Convention_A1 { if (!rRef.IsColRel()) rBuffer.append('$'); - if (!ValidCol(rAbsRef.Col()) || rRef.IsColDeleted()) + if (!rLimits.ValidCol(rAbsRef.Col()) || rRef.IsColDeleted()) rBuffer.append(rErrRef); else - MakeColStr(rBuffer, rAbsRef.Col()); + MakeColStr(rLimits, rBuffer, rAbsRef.Col()); } if (eSingletonDisplay != SINGLETON_COL) { if (!rRef.IsRowRel()) rBuffer.append('$'); - if (!ValidRow(rAbsRef.Row()) || rRef.IsRowDeleted()) + if (!rLimits.ValidRow(rAbsRef.Row()) || rRef.IsRowDeleted()) rBuffer.append(rErrRef); else - MakeRowStr(rBuffer, rAbsRef.Row()); + MakeRowStr(rLimits, rBuffer, rAbsRef.Row()); } } @@ -836,8 +836,8 @@ struct ConventionOOO_A1 : public Convention_A1 const ScComplexRefData& rRef, bool bFromRangeName ) { // If any part is error, display as such. - if (!ValidCol(rAbs1.Col()) || rRef.Ref1.IsColDeleted() || !ValidRow(rAbs1.Row()) || rRef.Ref1.IsRowDeleted() || - !ValidCol(rAbs2.Col()) || rRef.Ref2.IsColDeleted() || !ValidRow(rAbs2.Row()) || rRef.Ref2.IsRowDeleted()) + if (!rLimits.ValidCol(rAbs1.Col()) || rRef.Ref1.IsColDeleted() || !rLimits.ValidRow(rAbs1.Row()) || rRef.Ref1.IsRowDeleted() || + !rLimits.ValidCol(rAbs2.Col()) || rRef.Ref2.IsColDeleted() || !rLimits.ValidRow(rAbs2.Row()) || rRef.Ref2.IsRowDeleted()) return SINGLETON_NONE; // A:A or $A:$A or A:$A or $A:A @@ -875,17 +875,17 @@ struct ConventionOOO_A1 : public Convention_A1 { // In case absolute/relative positions weren't separately available: // transform relative to absolute! - ScAddress aAbs1 = rRef.Ref1.toAbs(rPos), aAbs2; + ScAddress aAbs1 = rRef.Ref1.toAbs(rLimits, rPos), aAbs2; if( !bSingleRef ) - aAbs2 = rRef.Ref2.toAbs(rPos); + aAbs2 = rRef.Ref2.toAbs(rLimits, rPos); SingletonDisplay eSingleton = bSingleRef ? SINGLETON_NONE : getSingletonDisplay( rLimits, aAbs1, aAbs2, rRef, bFromRangeName); - MakeOneRefStrImpl(rBuffer, rErrRef, rTabNames, rRef.Ref1, aAbs1, false, false, eSingleton); + MakeOneRefStrImpl(rLimits, rBuffer, rErrRef, rTabNames, rRef.Ref1, aAbs1, false, false, eSingleton); if (!bSingleRef) { rBuffer.append(':'); - MakeOneRefStrImpl(rBuffer, rErrRef, rTabNames, rRef.Ref2, aAbs2, aAbs1.Tab() != aAbs2.Tab(), false, + MakeOneRefStrImpl(rLimits, rBuffer, rErrRef, rTabNames, rRef.Ref2, aAbs2, aAbs1.Tab() != aAbs2.Tab(), false, eSingleton); } } @@ -917,10 +917,11 @@ struct ConventionOOO_A1 : public Convention_A1 } static bool makeExternalSingleRefStr( + ScSheetLimits& rLimits, OUStringBuffer& rBuffer, const OUString& rFileName, const OUString& rTabName, const ScSingleRefData& rRef, const ScAddress& rPos, bool bDisplayTabName, bool bEncodeUrl ) { - ScAddress aAbsRef = rRef.toAbs(rPos); + ScAddress aAbsRef = rRef.toAbs(rLimits, rPos); if (bDisplayTabName) { OUString aFile; @@ -940,15 +941,16 @@ struct ConventionOOO_A1 : public Convention_A1 if (!rRef.IsColRel()) rBuffer.append('$'); - MakeColStr( rBuffer, aAbsRef.Col()); + MakeColStr( rLimits, rBuffer, aAbsRef.Col()); if (!rRef.IsRowRel()) rBuffer.append('$'); - MakeRowStr( rBuffer, aAbsRef.Row()); + MakeRowStr( rLimits, rBuffer, aAbsRef.Row()); return true; } static void makeExternalRefStrImpl( + ScSheetLimits& rLimits, OUStringBuffer& rBuffer, const ScAddress& rPos, const OUString& rFileName, const OUString& rTabName, const ScSingleRefData& rRef, bool bODF ) { @@ -956,24 +958,26 @@ struct ConventionOOO_A1 : public Convention_A1 rBuffer.append( '['); bool bEncodeUrl = bODF; - makeExternalSingleRefStr(rBuffer, rFileName, rTabName, rRef, rPos, true, bEncodeUrl); + makeExternalSingleRefStr(rLimits, rBuffer, rFileName, rTabName, rRef, rPos, true, bEncodeUrl); if (bODF) rBuffer.append( ']'); } virtual void makeExternalRefStr( + ScSheetLimits& rLimits, OUStringBuffer& rBuffer, const ScAddress& rPos, sal_uInt16 /*nFileId*/, const OUString& rFileName, const OUString& rTabName, const ScSingleRefData& rRef ) const override { - makeExternalRefStrImpl(rBuffer, rPos, rFileName, rTabName, rRef, false); + makeExternalRefStrImpl(rLimits, rBuffer, rPos, rFileName, rTabName, rRef, false); } static void makeExternalRefStrImpl( + ScSheetLimits& rLimits, OUStringBuffer& rBuffer, const ScAddress& rPos, const OUString& rFileName, const std::vector<OUString>& rTabNames, const OUString& rTabName, const ScComplexRefData& rRef, bool bODF ) { - ScRange aAbsRange = rRef.toAbs(rPos); + ScRange aAbsRange = rRef.toAbs(rLimits, rPos); if (bODF) rBuffer.append( '['); @@ -982,7 +986,7 @@ struct ConventionOOO_A1 : public Convention_A1 do { - if (!makeExternalSingleRefStr(rBuffer, rFileName, rTabName, rRef.Ref1, rPos, true, bEncodeUrl)) + if (!makeExternalSingleRefStr(rLimits, rBuffer, rFileName, rTabName, rRef.Ref1, rPos, true, bEncodeUrl)) break; rBuffer.append(':'); @@ -1000,7 +1004,7 @@ struct ConventionOOO_A1 : public Convention_A1 } else if (bODF) rBuffer.append( '.'); // need at least the sheet separator in ODF - makeExternalSingleRefStr( + makeExternalSingleRefStr(rLimits, rBuffer, rFileName, aLastTabName, rRef.Ref2, rPos, bDisplayTabName, bEncodeUrl); } while (false); @@ -1009,12 +1013,12 @@ struct ConventionOOO_A1 : public Convention_A1 } virtual void makeExternalRefStr( - ScSheetLimits&, + ScSheetLimits& rLimits, OUStringBuffer& rBuffer, const ScAddress& rPos, sal_uInt16 /*nFileId*/, const OUString& rFileName, const std::vector<OUString>& rTabNames, const OUString& rTabName, const ScComplexRefData& rRef ) const override { - makeExternalRefStrImpl(rBuffer, rPos, rFileName, rTabNames, rTabName, rRef, false); + makeExternalRefStrImpl(rLimits, rBuffer, rPos, rFileName, rTabNames, rTabName, rRef, false); } }; @@ -1035,12 +1039,12 @@ struct ConventionOOO_A1_ODF : public ConventionOOO_A1 rBuffer.append('['); // In case absolute/relative positions weren't separately available: // transform relative to absolute! - ScAddress aAbs1 = rRef.Ref1.toAbs(rPos), aAbs2; + ScAddress aAbs1 = rRef.Ref1.toAbs(rLimits, rPos), aAbs2; if( !bSingleRef ) - aAbs2 = rRef.Ref2.toAbs(rPos); + aAbs2 = rRef.Ref2.toAbs(rLimits, rPos); - if (FormulaGrammar::isODFF(eGram) && (rRef.Ref1.IsDeleted() || !ValidAddress(aAbs1) || - (!bSingleRef && (rRef.Ref2.IsDeleted() || !ValidAddress(aAbs2))))) + if (FormulaGrammar::isODFF(eGram) && (rRef.Ref1.IsDeleted() || !rLimits.ValidAddress(aAbs1) || + (!bSingleRef && (rRef.Ref2.IsDeleted() || !rLimits.ValidAddress(aAbs2))))) { rBuffer.append(rErrRef); // For ODFF write [#REF!], but not for PODF so apps reading ODF @@ -1051,11 +1055,11 @@ struct ConventionOOO_A1_ODF : public ConventionOOO_A1 { SingletonDisplay eSingleton = bSingleRef ? SINGLETON_NONE : getSingletonDisplay( rLimits, aAbs1, aAbs2, rRef, bFromRangeName); - MakeOneRefStrImpl(rBuffer, rErrRef, rTabNames, rRef.Ref1, aAbs1, false, true, eSingleton); + MakeOneRefStrImpl(rLimits, rBuffer, rErrRef, rTabNames, rRef.Ref1, aAbs1, false, true, eSingleton); if (!bSingleRef) { rBuffer.append(':'); - MakeOneRefStrImpl(rBuffer, rErrRef, rTabNames, rRef.Ref2, aAbs2, aAbs1.Tab() != aAbs2.Tab(), true, + MakeOneRefStrImpl(rLimits, rBuffer, rErrRef, rTabNames, rRef.Ref2, aAbs2, aAbs1.Tab() != aAbs2.Tab(), true, eSingleton); } } @@ -1069,19 +1073,20 @@ struct ConventionOOO_A1_ODF : public ConventionOOO_A1 } virtual void makeExternalRefStr( + ScSheetLimits& rLimits, OUStringBuffer& rBuffer, const ScAddress& rPos, sal_uInt16 /*nFileId*/, const OUString& rFileName, const OUString& rTabName, const ScSingleRefData& rRef ) const override { - makeExternalRefStrImpl(rBuffer, rPos, rFileName, rTabName, rRef, true); + makeExternalRefStrImpl(rLimits, rBuffer, rPos, rFileName, rTabName, rRef, true); } virtual void makeExternalRefStr( - ScSheetLimits& , + ScSheetLimits& rLimits, OUStringBuffer& rBuffer, const ScAddress& rPos, sal_uInt16 /*nFileId*/, const OUString& rFileName, const std::vector<OUString>& rTabNames, const OUString& rTabName, const ScComplexRefData& rRef ) const override { - makeExternalRefStrImpl(rBuffer, rPos, rFileName, rTabNames, rTabName, rRef, true); + makeExternalRefStrImpl(rLimits, rBuffer, rPos, rFileName, rTabNames, rTabName, rRef, true); } }; @@ -1092,10 +1097,11 @@ struct ConventionXL } static void GetTab( + ScSheetLimits& rLimits, const ScAddress& rPos, const std::vector<OUString>& rTabNames, const ScSingleRefData& rRef, OUString& rTabName ) { - ScAddress aAbs = rRef.toAbs(rPos); + ScAddress aAbs = rRef.toAbs(rLimits, rPos); if (rRef.IsTabDeleted() || static_cast<size_t>(aAbs.Tab()) >= rTabNames.size()) { rTabName = ScResId( STR_NO_REF_TABLE ); @@ -1104,7 +1110,7 @@ struct ConventionXL rTabName = rTabNames[aAbs.Tab()]; } - static void MakeTabStr( OUStringBuffer& rBuf, + static void MakeTabStr( ScSheetLimits& rLimits, OUStringBuffer& rBuf, const ScAddress& rPos, const std::vector<OUString>& rTabNames, const ScComplexRefData& rRef, @@ -1114,11 +1120,11 @@ struct ConventionXL { OUString aStartTabName, aEndTabName; - GetTab(rPos, rTabNames, rRef.Ref1, aStartTabName); + GetTab(rLimits, rPos, rTabNames, rRef.Ref1, aStartTabName); if( !bSingleRef && rRef.Ref2.IsFlag3D() ) { - GetTab(rPos, rTabNames, rRef.Ref2, aEndTabName); + GetTab(rLimits, rPos, rTabNames, rRef.Ref2, aEndTabName); } rBuf.append( aStartTabName ); @@ -1260,14 +1266,14 @@ struct ConventionXL_A1 : public Convention_A1, public ConventionXL ConventionXL_A1() : Convention_A1( FormulaGrammar::CONV_XL_A1 ) { } explicit ConventionXL_A1( FormulaGrammar::AddressConvention eConv ) : Convention_A1( eConv ) { } - static void makeSingleCellStr( OUStringBuffer& rBuf, const ScSingleRefData& rRef, const ScAddress& rAbs ) + static void makeSingleCellStr( ScSheetLimits& rLimits, OUStringBuffer& rBuf, const ScSingleRefData& rRef, const ScAddress& rAbs ) { if (!rRef.IsColRel()) rBuf.append('$'); - MakeColStr(rBuf, rAbs.Col()); + MakeColStr(rLimits, rBuf, rAbs.Col()); if (!rRef.IsRowRel()) rBuf.append('$'); - MakeRowStr(rBuf, rAbs.Row()); + MakeRowStr(rLimits, rBuf, rAbs.Row()); } virtual void makeRefStr( @@ -1284,11 +1290,11 @@ struct ConventionXL_A1 : public Convention_A1, public ConventionXL // Play fast and loose with invalid refs. There is not much point in producing // Foo!A1:#REF! versus #REF! at this point - ScAddress aAbs1 = aRef.Ref1.toAbs(rPos), aAbs2; + ScAddress aAbs1 = aRef.Ref1.toAbs(rLimits, rPos), aAbs2; - MakeTabStr(rBuf, rPos, rTabNames, aRef, bSingleRef); + MakeTabStr(rLimits, rBuf, rPos, rTabNames, aRef, bSingleRef); - if (!ValidAddress(aAbs1)) + if (!rLimits.ValidAddress(aAbs1)) { rBuf.append(rErrRef); return; @@ -1296,8 +1302,8 @@ struct ConventionXL_A1 : public Convention_A1, public ConventionXL if( !bSingleRef ) { - aAbs2 = aRef.Ref2.toAbs(rPos); - if (!ValidAddress(aAbs2)) + aAbs2 = aRef.Ref2.toAbs(rLimits, rPos); + if (!rLimits.ValidAddress(aAbs2)) { rBuf.append(rErrRef); return; @@ -1307,11 +1313,11 @@ struct ConventionXL_A1 : public Convention_A1, public ConventionXL { if (!aRef.Ref1.IsRowRel()) rBuf.append( '$' ); - MakeRowStr(rBuf, aAbs1.Row()); + MakeRowStr(rLimits, rBuf, aAbs1.Row()); rBuf.append( ':' ); if (!aRef.Ref2.IsRowRel()) rBuf.append( '$' ); - MakeRowStr(rBuf, aAbs2.Row()); + MakeRowStr(rLimits, rBuf, aAbs2.Row()); return; } @@ -1319,20 +1325,20 @@ struct ConventionXL_A1 : public Convention_A1, public ConventionXL { if (!aRef.Ref1.IsColRel()) rBuf.append( '$' ); - MakeColStr(rBuf, aAbs1.Col()); + MakeColStr(rLimits, rBuf, aAbs1.Col()); rBuf.append( ':' ); if (!aRef.Ref2.IsColRel()) rBuf.append( '$' ); - MakeColStr(rBuf, aAbs2.Col()); + MakeColStr(rLimits, rBuf, aAbs2.Col()); return; } } - makeSingleCellStr(rBuf, aRef.Ref1, aAbs1); + makeSingleCellStr(rLimits, rBuf, aRef.Ref1, aAbs1); if (!bSingleRef) { rBuf.append( ':' ); - makeSingleCellStr(rBuf, aRef.Ref2, aAbs2); + makeSingleCellStr(rLimits, rBuf, aRef.Ref2, aAbs2); } } @@ -1377,6 +1383,7 @@ struct ConventionXL_A1 : public Convention_A1, public ConventionXL } virtual void makeExternalRefStr( + ScSheetLimits& rLimits, OUStringBuffer& rBuffer, const ScAddress& rPos, sal_uInt16 /*nFileId*/, const OUString& rFileName, const OUString& rTabName, const ScSingleRefData& rRef ) const override { @@ -1390,26 +1397,26 @@ struct ConventionXL_A1 : public Convention_A1, public ConventionXL ScRangeStringConverter::AppendTableName(rBuffer, rTabName); rBuffer.append('!'); - makeSingleCellStr(rBuffer, rRef, rRef.toAbs(rPos)); + makeSingleCellStr(rLimits, rBuffer, rRef, rRef.toAbs(rLimits, rPos)); } virtual void makeExternalRefStr( - ScSheetLimits&, + ScSheetLimits& rLimits, OUStringBuffer& rBuffer, const ScAddress& rPos, sal_uInt16 /*nFileId*/, const OUString& rFileName, const std::vector<OUString>& rTabNames, const OUString& rTabName, const ScComplexRefData& rRef ) const override { - ScRange aAbsRef = rRef.toAbs(rPos); + ScRange aAbsRef = rRef.toAbs(rLimits, rPos); ConventionXL::makeExternalDocStr(rBuffer, rFileName); ConventionXL::makeExternalTabNameRange(rBuffer, rTabName, rTabNames, aAbsRef); rBuffer.append('!'); - makeSingleCellStr(rBuffer, rRef.Ref1, aAbsRef.aStart); + makeSingleCellStr(rLimits, rBuffer, rRef.Ref1, aAbsRef.aStart); if (aAbsRef.aStart != aAbsRef.aEnd) { rBuffer.append(':'); - makeSingleCellStr(rBuffer, rRef.Ref2, aAbsRef.aEnd); + makeSingleCellStr(rLimits, rBuffer, rRef.Ref2, aAbsRef.aEnd); } } }; @@ -1487,6 +1494,7 @@ struct ConventionXL_OOX : public ConventionXL_A1 } virtual void makeExternalRefStr( + ScSheetLimits& rLimits, OUStringBuffer& rBuffer, const ScAddress& rPos, sal_uInt16 nFileId, const OUString& /*rFileName*/, const OUString& rTabName, const ScSingleRefData& rRef ) const override { @@ -1509,11 +1517,11 @@ struct ConventionXL_OOX : public ConventionXL_A1 } rBuffer.append('!'); - makeSingleCellStr(rBuffer, rRef, rRef.toAbs(rPos)); + makeSingleCellStr(rLimits, rBuffer, rRef, rRef.toAbs(rLimits, rPos)); } virtual void makeExternalRefStr( - ScSheetLimits& , + ScSheetLimits& rLimits, OUStringBuffer& rBuffer, const ScAddress& rPos, sal_uInt16 nFileId, const OUString& /*rFileName*/, const std::vector<OUString>& rTabNames, const OUString& rTabName, const ScComplexRefData& rRef ) const override @@ -1524,7 +1532,7 @@ struct ConventionXL_OOX : public ConventionXL_A1 // sheet names as well. The [N] having to be within the quoted sheet // name is ugly enough... - ScRange aAbsRef = rRef.toAbs(rPos); + ScRange aAbsRef = rRef.toAbs(rLimits, rPos); OUStringBuffer aBuf; ConventionXL::makeExternalTabNameRange( aBuf, rTabName, rTabNames, aAbsRef); @@ -1541,11 +1549,11 @@ struct ConventionXL_OOX : public ConventionXL_A1 } rBuffer.append('!'); - makeSingleCellStr(rBuffer, rRef.Ref1, aAbsRef.aStart); + makeSingleCellStr(rLimits, rBuffer, rRef.Ref1, aAbsRef.aStart); if (aAbsRef.aStart != aAbsRef.aEnd) { rBuffer.append(':'); - makeSingleCellStr(rBuffer, rRef.Ref2, aAbsRef.aEnd); + makeSingleCellStr(rLimits, rBuffer, rRef.Ref2, aAbsRef.aEnd); } } @@ -1600,14 +1608,14 @@ struct ConventionXL_R1C1 : public ScCompiler::Convention, public ConventionXL bool bSingleRef, bool /*bFromRangeName*/ ) const override { - ScRange aAbsRef = rRef.toAbs(rPos); + ScRange aAbsRef = rRef.toAbs(rLimits, rPos); ScComplexRefData aRef( rRef ); - MakeTabStr(rBuf, rPos, rTabNames, aRef, bSingleRef); + MakeTabStr(rLimits, rBuf, rPos, rTabNames, aRef, bSingleRef); // Play fast and loose with invalid refs. There is not much point in producing // Foo!A1:#REF! versus #REF! at this point - if (!ValidCol(aAbsRef.aStart.Col()) || !ValidRow(aAbsRef.aStart.Row())) + if (!rLimits.ValidCol(aAbsRef.aStart.Col()) || !rLimits.ValidRow(aAbsRef.aStart.Row())) { rBuf.append(rErrRef); return; @@ -1615,7 +1623,7 @@ struct ConventionXL_R1C1 : public ScCompiler::Convention, public ConventionXL if( !bSingleRef ) { - if (!ValidCol(aAbsRef.aEnd.Col()) || !ValidRow(aAbsRef.aEnd.Row())) + if (!rLimits.ValidCol(aAbsRef.aEnd.Col()) || !rLimits.ValidRow(aAbsRef.aEnd.Row())) { rBuf.append(rErrRef); return; @@ -1699,6 +1707,7 @@ struct ConventionXL_R1C1 : public ScCompiler::Convention, public ConventionXL } virtual void makeExternalRefStr( + ScSheetLimits& rLimits, OUStringBuffer& rBuffer, const ScAddress& rPos, sal_uInt16 /*nFileId*/, const OUString& rFileName, const OUString& rTabName, const ScSingleRefData& rRef ) const override { @@ -1708,7 +1717,7 @@ struct ConventionXL_R1C1 : public ScCompiler::Convention, public ConventionXL // whole file path with [] because the file name can contain any // characters. - ScAddress aAbsRef = rRef.toAbs(rPos); + ScAddress aAbsRef = rRef.toAbs(rLimits, rPos); ConventionXL::makeExternalDocStr(rBuffer, rFileName); ScRangeStringConverter::AppendTableName(rBuffer, rTabName); rBuffer.append('!'); @@ -1723,13 +1732,13 @@ struct ConventionXL_R1C1 : public ScCompiler::Convention, public ConventionXL const std::vector<OUString>& rTabNames, const OUString& rTabName, const ScComplexRefData& rRef ) const override { - ScRange aAbsRef = rRef.toAbs(rPos); + ScRange aAbsRef = rRef.toAbs(rLimits, rPos); ConventionXL::makeExternalDocStr(rBuffer, rFileName); ConventionXL::makeExternalTabNameRange(rBuffer, rTabName, rTabNames, aAbsRef); rBuffer.append('!'); - if (!ValidCol(aAbsRef.aEnd.Col()) || !ValidRow(aAbsRef.aEnd.Row())) + if (!rLimits.ValidCol(aAbsRef.aEnd.Col()) || !rLimits.ValidRow(aAbsRef.aEnd.Row())) { rBuffer.append(ScResId(STR_NO_REF_TABLE)); return; @@ -3183,7 +3192,7 @@ bool ScCompiler::IsDoubleReference( const OUString& rName, const OUString* pErrR if ( !(nFlags & ScRefFlags::TAB2_VALID) ) aRef.Ref2.SetTabDeleted( true ); // #REF! aRef.Ref2.SetFlag3D( ( nFlags & ScRefFlags::TAB2_3D ) != ScRefFlags::ZERO ); - aRef.SetRange(aRange, aPos); + aRef.SetRange(pDoc->GetSheetLimits(), aRange, aPos); if (aExtInfo.mbExternal) { ScExternalRefManager* pRefMgr = pDoc->GetExternalRefManager(); @@ -3249,7 +3258,7 @@ bool ScCompiler::IsSingleReference( const OUString& rName, const OUString* pErrR aRef.SetTabDeleted(true); nFlags |= ScRefFlags::VALID; } - aRef.SetAddress(aAddr, aPos); + aRef.SetAddress(pDoc->GetSheetLimits(), aAddr, aPos); if (aExtInfo.mbExternal) { @@ -3583,7 +3592,7 @@ bool ScCompiler::IsColRowName( const OUString& rName ) aRef.SetColRel( true ); // ColName else aRef.SetRowRel( true ); // RowName - aRef.SetAddress(aIter.GetPos(), aPos); + aRef.SetAddress(pDoc->GetSheetLimits(), aIter.GetPos(), aPos); bInList = bFound = true; } } @@ -3765,7 +3774,7 @@ bool ScCompiler::IsColRowName( const OUString& rName ) aRef.SetRowRel( true ); // RowName else aRef.SetColRel( true ); // ColName - aRef.SetAddress(aAdr, aPos); + aRef.SetAddress(pDoc->GetSheetLimits(), aAdr, aPos); } } if ( bFound ) @@ -5011,7 +5020,7 @@ void ScCompiler::CreateStringFromExternal( OUStringBuffer& rBuffer, const Formul rBuffer.append(pConv->makeExternalNameStr( nFileId, *pFileName, t->GetString().getString())); break; case svExternalSingleRef: - pConv->makeExternalRefStr( + pConv->makeExternalRefStr(pDoc->GetSheetLimits(), rBuffer, GetPos(), nFileId, *pFileName, t->GetString().getString(), *t->GetSingleRef()); break; @@ -5118,7 +5127,7 @@ void ScCompiler::CreateStringFromSingleRef( OUStringBuffer& rBuffer, const Formu aRef.Ref1 = aRef.Ref2 = rRef; if ( eOp == ocColRowName ) { - ScAddress aAbs = rRef.toAbs(aPos); + ScAddress aAbs = rRef.toAbs(pDoc, aPos); if (pDoc->HasStringData(aAbs.Col(), aAbs.Row(), aAbs.Tab())) { OUString aStr = pDoc->GetString(aAbs, mpInterpreterContext); @@ -5135,7 +5144,7 @@ void ScCompiler::CreateStringFromSingleRef( OUStringBuffer& rBuffer, const Formu else if (pArr && (p = maArrIterator.PeekPrevNoSpaces()) && p->GetOpCode() == ocTableRefOpen) { OUString aStr; - ScAddress aAbs = rRef.toAbs(aPos); + ScAddress aAbs = rRef.toAbs(pDoc, aPos); const ScDBData* pData = pDoc->GetDBAtCursor( aAbs.Col(), aAbs.Row(), aAbs.Tab(), ScDBDataPortion::AREA); SAL_WARN_IF( !pData, "sc.core", "ScCompiler::CreateStringFromSingleRef - TableRef without ScDBData: " << aAbs.Format( ScRefFlags::VALID | ScRefFlags::TAB_3D, pDoc)); @@ -5323,8 +5332,8 @@ void ScCompiler::fillAddInToken(::std::vector< css::sheet::FormulaOpCodeMapEntry bool ScCompiler::HandleColRowName() { ScSingleRefData& rRef = *mpToken->GetSingleRef(); - const ScAddress aAbs = rRef.toAbs(aPos); - if (!ValidAddress(aAbs)) + const ScAddress aAbs = rRef.toAbs(pDoc, aPos); + if (!pDoc->ValidAddress(aAbs)) { SetError( FormulaError::NoRef ); return true; @@ -5497,7 +5506,7 @@ bool ScCompiler::HandleColRowName() aRefData.SetColRel( true ); else aRefData.SetRowRel( true ); - aRefData.SetAddress(aRange.aStart, aPos); + aRefData.SetAddress(pDoc->GetSheetLimits(), aRange.aStart, aPos); pNew->AddSingleReference( aRefData ); } else @@ -5514,7 +5523,7 @@ bool ScCompiler::HandleColRowName() aRefData.Ref1.SetRowRel( true ); aRefData.Ref2.SetRowRel( true ); } - aRefData.SetRange(aRange, aPos); + aRefData.SetRange(pDoc->GetSheetLimits(), aRange, aPos); if ( bInList ) pNew->AddDoubleReference( aRefData ); else @@ -5543,7 +5552,7 @@ bool ScCompiler::HandleDbData() ScRange aRange; pDBData->GetArea(aRange); aRange.aEnd.SetTab(aRange.aStart.Tab()); - aRefData.SetRange(aRange, aPos); + aRefData.SetRange(pDoc->GetSheetLimits(), aRange, aPos); ScTokenArray* pNew = new ScTokenArray(pDoc); pNew->AddDoubleReference( aRefData ); PushTokenArray( pNew, true ); @@ -5760,7 +5769,7 @@ bool ScCompiler::HandleTableRef() { case svSingleRef: { - aColRange.aStart = aColRange.aEnd = mpToken->GetSingleRef()->toAbs( aPos); + aColRange.aStart = aColRange.aEnd = mpToken->GetSingleRef()->toAbs(pDoc, aPos); if ( GetTokenIfOpCode( ocTableRefClose) && (nLevel--) && GetTokenIfOpCode( ocRange) && GetTokenIfOpCode( ocTableRefOpen) && (++nLevel) && @@ -5770,7 +5779,7 @@ bool ScCompiler::HandleTableRef() aColRange = ScRange( ScAddress::INITIALIZE_INVALID); else { - aColRange.aEnd = mpToken->GetSingleRef()->toAbs( aPos); + aColRange.aEnd = mpToken->GetSingleRef()->toAbs(pDoc, aPos); aColRange.PutInOrder(); bCol2Rel = mpToken->GetSingleRef()->IsColRel(); bCol2RelName = mpToken->GetSingleRef()->IsRelName(); @@ -5807,13 +5816,13 @@ bool ScCompiler::HandleTableRef() aRefData.SetFlag3D( true); if (nError != FormulaError::NONE) { - aRefData.SetAddress( aRange.aStart, aRange.aStart); + aRefData.SetAddress( pDoc->GetSheetLimits(), aRange.aStart, aRange.aStart); pTR->SetAreaRefRPN( new ScSingleRefToken(pDoc->GetSheetLimits(), aRefData)); // set reference at TableRef pNew->Add( new FormulaErrorToken( nError)); // set error in RPN } else { - aRefData.SetAddress( aRange.aStart, aPos); + aRefData.SetAddress( pDoc->GetSheetLimits(), aRange.aStart, aPos); pTR->SetAreaRefRPN( pNew->AddSingleReference( aRefData)); } } @@ -5836,13 +5845,13 @@ bool ScCompiler::HandleTableRef() aRefData.Ref1.SetFlag3D( true); if (nError != FormulaError::NONE) { - aRefData.SetRange( aRange, aRange.aStart); + aRefData.SetRange( pDoc->GetSheetLimits(), aRange, aRange.aStart); pTR->SetAreaRefRPN( new ScDoubleRefToken(pDoc->GetSheetLimits(), aRefData)); // set reference at TableRef pNew->Add( new FormulaErrorToken( nError)); // set error in RPN } else { - aRefData.SetRange( aRange, aPos); + aRefData.SetRange( pDoc->GetSheetLimits(), aRange, aPos); pTR->SetAreaRefRPN( pNew->AddDoubleReference( aRefData)); } } @@ -6078,7 +6087,7 @@ void ScCompiler::ReplaceDoubleRefII(FormulaToken** ppDoubleRefTok) if (!rRange.Ref1.IsRowRel() && !rRange.Ref2.IsRowRel()) return; - ScRange aAbsRange = rRange.toAbs(aPos); + ScRange aAbsRange = rRange.toAbs(pDoc, aPos); if (aAbsRange.aStart == aAbsRange.aEnd) return; // Nothing to do (trivial case). @@ -6092,7 +6101,7 @@ void ScCompiler::ReplaceDoubleRefII(FormulaToken** ppDoubleRefTok) aSingleRef.SetColRel(rRange.Ref1.IsColRel()); aSingleRef.SetRowRel(true); aSingleRef.SetTabRel(rRange.Ref1.IsTabRel()); - aSingleRef.SetAddress(aAddr, aPos); + aSingleRef.SetAddress(pDoc->GetSheetLimits(), aAddr, aPos); // Replace the original doubleref token with computed singleref token FormulaToken* pNewSingleRefTok = new ScSingleRefToken(pDoc->GetSheetLimits(), aSingleRef); @@ -6168,7 +6177,7 @@ static void lcl_GetColRowDeltas(const ScRange& rRange, SCCOL& rXDelta, SCROW& rY bool ScCompiler::AdjustSumRangeShape(const ScComplexRefData& rBaseRange, ScComplexRefData& rSumRange) { - ScRange aAbs = rSumRange.toAbs(aPos); + ScRange aAbs = rSumRange.toAbs(pDoc, aPos); // Current sum-range end col/row SCCOL nEndCol = aAbs.aEnd.Col(); @@ -6177,7 +6186,7 @@ bool ScCompiler::AdjustSumRangeShape(const ScComplexRefData& rBaseRange, ScCompl // Current behaviour is, we will get a #NAME? for the below case, so bail out. // Note that sum-range's End[Col,Row] are same as Start[Col,Row] if the original formula // has a single-ref as the sum-range. - if (!ValidCol(nEndCol) || !ValidRow(nEndRow)) + if (!pDoc->ValidCol(nEndCol) || !pDoc->ValidRow(nEndRow)) return false; SCCOL nXDeltaSum = 0; @@ -6185,7 +6194,7 @@ bool ScCompiler::AdjustSumRangeShape(const ScComplexRefData& rBaseRange, ScCompl lcl_GetColRowDeltas(aAbs, nXDeltaSum, nYDeltaSum); - aAbs = rBaseRange.toAbs(aPos); + aAbs = rBaseRange.toAbs(pDoc, aPos); SCCOL nXDelta = 0; SCROW nYDelta = 0; diff --git a/sc/source/core/tool/consoli.cxx b/sc/source/core/tool/consoli.cxx index bb8647e5e401..d134a9e45cec 100644 --- a/sc/source/core/tool/consoli.cxx +++ b/sc/source/core/tool/consoli.cxx @@ -474,7 +474,7 @@ void ScConsData::OutputToDocument( ScDocument* pDestDoc, SCCOL nCol, SCROW nRow, { // insert reference (absolute, 3d) - aSRef.SetAddress(ScAddress(aRef.nCol,aRef.nRow,aRef.nTab), ScAddress()); + aSRef.SetAddress(pDestDoc->GetSheetLimits(), ScAddress(aRef.nCol,aRef.nRow,aRef.nTab), ScAddress()); ScTokenArray aRefArr(pDestDoc); aRefArr.AddSingleReference(aSRef); @@ -493,7 +493,7 @@ void ScConsData::OutputToDocument( ScDocument* pDestDoc, SCCOL nCol, SCROW nRow, ScRange aRange(sal::static_int_cast<SCCOL>(nCol+nArrX), nRow+nArrY, nTab); aRange.aEnd.SetRow(nRow+nArrY+nNeeded-1); - aCRef.SetRange(aRange, aDest); + aCRef.SetRange(pDestDoc->GetSheetLimits(), aRange, aDest); ScTokenArray aArr(pDestDoc); aArr.AddOpCode(eOpCode); // selected function diff --git a/sc/source/core/tool/detfunc.cxx b/sc/source/core/tool/detfunc.cxx index 045998d7cdf8..ac1af287d1a5 100644 --- a/sc/source/core/tool/detfunc.cxx +++ b/sc/source/core/tool/detfunc.cxx @@ -1400,7 +1400,7 @@ void ScDetectiveFunc::GetAllSuccs(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW n { const ScAddress& aPos = aIter.GetPos(); ScTokenRef pRef(p->Clone()); - if (ScRefTokenHelper::intersects(aSrcRange, pRef, aPos)) + if (ScRefTokenHelper::intersects(pDoc, aSrcRange, pRef, aPos)) { // This address is absolute. pRef = ScRefTokenHelper::createRefToken(pDoc, aPos); diff --git a/sc/source/core/tool/doubleref.cxx b/sc/source/core/tool/doubleref.cxx index a2a464b6813f..2a2316a0c173 100644 --- a/sc/source/core/tool/doubleref.cxx +++ b/sc/source/core/tool/doubleref.cxx @@ -46,6 +46,7 @@ void lcl_uppercase(OUString& rStr) } bool lcl_createStarQuery( + const ScDocument* pDoc, svl::SharedStringPool& rPool, ScQueryParamBase* pParam, const ScDBRangeBase* pDBRef, const ScDBRangeBase* pQueryRef) { // A valid StarQuery must be at least 4 columns wide. To be precise it @@ -96,7 +97,7 @@ bool lcl_createStarQuery( // field name in the 2nd column. aCellStr = pQueryRef->getString(1, nRow); SCCOL nField = pDBRef->findFieldColumn(aCellStr); // TODO: must be case insensitive comparison. - if (ValidCol(nField)) + if (pDoc->ValidCol(nField)) { rEntry.nField = nField; bValid = true; @@ -147,6 +148,7 @@ bool lcl_createStarQuery( } bool lcl_createExcelQuery( + const ScDocument* pDoc, svl::SharedStringPool& rPool, ScQueryParamBase* pParam, const ScDBRangeBase* pDBRef, const ScDBRangeBase* pQueryRef) { bool bValid = true; @@ -158,7 +160,7 @@ bool lcl_createExcelQuery( { OUString aQueryStr = pQueryRef->getString(nCol, 0); SCCOL nField = pDBRef->findFieldColumn(aQueryStr); - if (ValidCol(nField)) + if (pDoc->ValidCol(nField)) aFields[nCol] = nField; else bValid = false; @@ -213,6 +215,7 @@ bool lcl_createExcelQuery( } bool lcl_fillQueryEntries( + const ScDocument* pDoc, svl::SharedStringPool& rPool, ScQueryParamBase* pParam, const ScDBRangeBase* pDBRef, const ScDBRangeBase* pQueryRef) { SCSIZE nCount = pParam->GetEntryCount(); @@ -220,10 +223,10 @@ bool lcl_fillQueryEntries( pParam->GetEntry(i).Clear(); // Standard QueryTabelle - bool bValid = lcl_createStarQuery(rPool, pParam, pDBRef, pQueryRef); + bool bValid = lcl_createStarQuery(pDoc, rPool, pParam, pDBRef, pQueryRef); // Excel QueryTabelle if (!bValid) - bValid = lcl_createExcelQuery(rPool, pParam, pDBRef, pQueryRef); + bValid = lcl_createExcelQuery(pDoc, rPool, pParam, pDBRef, pQueryRef); nCount = pParam->GetEntryCount(); if (bValid) @@ -257,7 +260,7 @@ bool ScDBRangeBase::fillQueryEntries(ScQueryParamBase* pParam, const ScDBRangeBa if (!pDBRef) return false; - return lcl_fillQueryEntries(getDoc()->GetSharedStringPool(), pParam, pDBRef, this); + return lcl_fillQueryEntries(getDoc(), getDoc()->GetSharedStringPool(), pParam, pDBRef, this); } void ScDBRangeBase::fillQueryOptions(ScQueryParamBase* pParam) diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index 5340d622e9b4..388ed68f14ed 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -4263,7 +4263,7 @@ void ScInterpreter::ScColumns() OUString aTabName; ScComplexRefData aRef; PopExternalDoubleRef( nFileId, aTabName, aRef); - ScRange aAbs = aRef.toAbs(aPos); + ScRange aAbs = aRef.toAbs(pDok, aPos); nVal += static_cast<sal_uLong>(aAbs.aEnd.Tab() - aAbs.aStart.Tab() + 1) * static_cast<sal_uLong>(aAbs.aEnd.Col() - aAbs.aStart.Col() + 1); } @@ -4320,7 +4320,7 @@ void ScInterpreter::ScRows() OUString aTabName; ScComplexRefData aRef; PopExternalDoubleRef( nFileId, aTabName, aRef); - ScRange aAbs = aRef.toAbs(aPos); + ScRange aAbs = aRef.toAbs(pDok, aPos); nVal += static_cast<sal_uLong>(aAbs.aEnd.Tab() - aAbs.aStart.Tab() + 1) * static_cast<sal_uLong>(aAbs.aEnd.Row() - aAbs.aStart.Row() + 1); } @@ -4367,7 +4367,7 @@ void ScInterpreter::ScSheets() OUString aTabName; ScComplexRefData aRef; PopExternalDoubleRef( nFileId, aTabName, aRef); - ScRange aAbs = aRef.toAbs(aPos); + ScRange aAbs = aRef.toAbs(pDok, aPos); nVal += static_cast<sal_uLong>(aAbs.aEnd.Tab() - aAbs.aStart.Tab() + 1); } break; @@ -4431,7 +4431,7 @@ void ScInterpreter::ScColumn() OUString aTabName; ScSingleRefData aRef; PopExternalSingleRef( nFileId, aTabName, aRef ); - ScAddress aAbsRef = aRef.toAbs(aPos); + ScAddress aAbsRef = aRef.toAbs(pDok, aPos); nVal = static_cast<double>( aAbsRef.Col() + 1 ); } break; @@ -4455,7 +4455,7 @@ void ScInterpreter::ScColumn() OUString aTabName; ScComplexRefData aRef; PopExternalDoubleRef( nFileId, aTabName, aRef ); - ScRange aAbs = aRef.toAbs(aPos); + ScRange aAbs = aRef.toAbs(pDok, aPos); nCol1 = aAbs.aStart.Col(); nCol2 = aAbs.aEnd.Col(); } @@ -4535,7 +4535,7 @@ void ScInterpreter::ScRow() OUString aTabName; ScSingleRefData aRef; PopExternalSingleRef( nFileId, aTabName, aRef ); - ScAddress aAbsRef = aRef.toAbs(aPos); + ScAddress aAbsRef = aRef.toAbs(pDok, aPos); nVal = static_cast<double>( aAbsRef.Row() + 1 ); } break; @@ -4558,7 +4558,7 @@ void ScInterpreter::ScRow() OUString aTabName; ScComplexRefData aRef; PopExternalDoubleRef( nFileId, aTabName, aRef ); - ScRange aAbs = aRef.toAbs(aPos); + ScRange aAbs = aRef.toAbs(pDok, aPos); nRow1 = aAbs.aStart.Row(); nRow2 = aAbs.aEnd.Row(); } @@ -8375,7 +8375,7 @@ void ScInterpreter::ScOffset() OUString aTabName; ScSingleRefData aRef; PopExternalSingleRef(nFileId, aTabName, aRef); - ScAddress aAbsRef = aRef.toAbs(aPos); + ScAddress aAbsRef = aRef.toAbs(pDok, aPos); nCol1 = aAbsRef.Col(); nRow1 = aAbsRef.Row(); nTab1 = aAbsRef.Tab(); @@ -8432,7 +8432,7 @@ void ScInterpreter::ScOffset() OUString aTabName; ScComplexRefData aRef; PopExternalDoubleRef(nFileId, aTabName, aRef); - ScRange aAbs = aRef.toAbs(aPos); + ScRange aAbs = aRef.toAbs(pDok, aPos); nCol1 = aAbs.aStart.Col(); nRow1 = aAbs.aStart.Row(); nTab1 = aAbs.aStart.Tab(); diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx index 43bf4f75da07..2dc9010e8eed 100644 --- a/sc/source/core/tool/interpr2.cxx +++ b/sc/source/core/tool/interpr2.cxx @@ -2465,12 +2465,12 @@ void ScInterpreter::ScIntersect() ScRefList* pRefList = xRes->GetRefList(); for (const auto& rRef1 : *x1->GetRefList()) { - const ScAddress& r11 = rRef1.Ref1.toAbs(aPos); - const ScAddress& r12 = rRef1.Ref2.toAbs(aPos); + const ScAddress& r11 = rRef1.Ref1.toAbs(pDok, aPos); + const ScAddress& r12 = rRef1.Ref2.toAbs(pDok, aPos); for (const auto& rRef2 : *x2->GetRefList()) { - const ScAddress& r21 = rRef2.Ref1.toAbs(aPos); - const ScAddress& r22 = rRef2.Ref2.toAbs(aPos); + const ScAddress& r21 = rRef2.Ref1.toAbs(pDok, aPos); + const ScAddress& r22 = rRef2.Ref2.toAbs(pDok, aPos); SCCOL nCol1 = ::std::max( r11.Col(), r21.Col()); SCROW nRow1 = ::std::max( r11.Row(), r21.Row()); SCTAB nTab1 = ::std::max( r11.Tab(), r21.Tab()); @@ -2516,14 +2516,14 @@ void ScInterpreter::ScIntersect() case svDoubleRef: { { - const ScAddress& r = pt[i]->GetSingleRef()->toAbs(aPos); + const ScAddress& r = pt[i]->GetSingleRef()->toAbs(pDok, aPos); nC1[i] = r.Col(); nR1[i] = r.Row(); nT1[i] = r.Tab(); } if (sv[i] == svDoubleRef) { - const ScAddress& r = pt[i]->GetSingleRef2()->toAbs(aPos); + const ScAddress& r = pt[i]->GetSingleRef2()->toAbs(pDok, aPos); nC2[i] = r.Col(); nR2[i] = r.Row(); nT2[i] = r.Tab(); diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx index 8a7143fb94ef..1a371f3f3381 100644 --- a/sc/source/core/tool/interpr4.cxx +++ b/sc/source/core/tool/interpr4.cxx @@ -878,12 +878,12 @@ void ScInterpreter::SingleRefToVars( const ScSingleRefData & rRef, else rTab = rRef.Tab(); - if( !ValidCol( rCol) || rRef.IsColDeleted() ) + if( !pDok->ValidCol( rCol) || rRef.IsColDeleted() ) { SetError( FormulaError::NoRef ); rCol = 0; } - if( !ValidRow( rRow) || rRef.IsRowDeleted() ) + if( !pDok->ValidRow( rRow) || rRef.IsRowDeleted() ) { SetError( FormulaError::NoRef ); rRow = 0; @@ -1178,7 +1178,7 @@ void ScInterpreter::PopExternalSingleRef( return; } - ScAddress aAddr = rRef.toAbs(aPos); + ScAddress aAddr = rRef.toAbs(pDok, aPos); ScExternalRefCache::CellFormat aFmt; ScExternalRefCache::TokenRef xNew = pRefMgr->getSingleRefToken( rFileId, rTabName, aAddr, &aPos, nullptr, &aFmt); @@ -1279,8 +1279,8 @@ void ScInterpreter::GetExternalDoubleRef( } ScComplexRefData aData(rData); - ScRange aRange = aData.toAbs(aPos); - if (!ValidColRow(aRange.aStart.Col(), aRange.aStart.Row()) || !ValidColRow(aRange.aEnd.Col(), aRange.aEnd.Row())) + ScRange aRange = aData.toAbs(pDok, aPos); + if (!pDok->ValidColRow(aRange.aStart.Col(), aRange.aStart.Row()) || !pDok->ValidColRow(aRange.aEnd.Col(), aRange.aEnd.Row())) { SetError(FormulaError::NoRef); return; @@ -1858,7 +1858,7 @@ void ScInterpreter::PushSingleRef( const ScRefAddress& rRef ) if (!IfErrorPushError()) { ScSingleRefData aRef; - aRef.InitFromRefAddress( rRef, aPos); + aRef.InitFromRefAddress( pDok, rRef, aPos); PushTempTokenWithoutError( new ScSingleRefToken( pDok->GetSheetLimits(), aRef ) ); } } @@ -1868,7 +1868,7 @@ void ScInterpreter::PushDoubleRef( const ScRefAddress& rRef1, const ScRefAddress if (!IfErrorPushError()) { ScComplexRefData aRef; - aRef.InitFromRefAddresses( rRef1, rRef2, aPos); + aRef.InitFromRefAddresses( pDok, rRef1, rRef2, aPos); PushTempTokenWithoutError( new ScDoubleRefToken( pDok->GetSheetLimits(), aRef ) ); } } @@ -3665,7 +3665,7 @@ void ScInterpreter::ScDBArea() ScRange aRange; pDBData->GetArea(aRange); aRange.aEnd.SetTab(aRange.aStart.Tab()); - aRefData.SetRange(aRange, aPos); + aRefData.SetRange(pDok->GetSheetLimits(), aRange, aPos); PushTempToken( new ScDoubleRefToken( pDok->GetSheetLimits(), aRefData ) ); } else @@ -3675,8 +3675,8 @@ void ScInterpreter::ScDBArea() void ScInterpreter::ScColRowNameAuto() { ScComplexRefData aRefData( *pCur->GetDoubleRef() ); - ScRange aAbs = aRefData.toAbs(aPos); - if (!ValidRange(aAbs)) + ScRange aAbs = aRefData.toAbs(pDok, aPos); + if (!pDok->ValidRange(aAbs)) { PushError( FormulaError::NoRef ); return; @@ -3749,7 +3749,7 @@ void ScInterpreter::ScColRowNameAuto() } } } - aRefData.SetRange(aAbs, aPos); + aRefData.SetRange(pDok->GetSheetLimits(), aAbs, aPos); PushTempToken( new ScDoubleRefToken( pDok->GetSheetLimits(), aRefData ) ); } diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx index 6b8c2098a305..7e6a8daebdcf 100644 --- a/sc/source/core/tool/rangenam.cxx +++ b/sc/source/core/tool/rangenam.cxx @@ -292,10 +292,10 @@ void ScRangeData::UpdateTranspose( const ScRange& rSource, const ScAddress& rDes (!rRef.Ref2.IsColRel() && !rRef.Ref2.IsRowRel() && (!rRef.Ref2.IsFlag3D() || !rRef.Ref2.IsTabRel())))) { - ScRange aAbs = rRef.toAbs(aPos); + ScRange aAbs = rRef.toAbs(pDoc, aPos); if (ScRefUpdate::UpdateTranspose(pDoc, rSource, rDest, aAbs) != UR_NOTHING) { - rRef.SetRange(aAbs, aPos); + rRef.SetRange(pDoc->GetSheetLimits(), aAbs, aPos); bChanged = true; } } @@ -324,10 +324,10 @@ void ScRangeData::UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY ) (!rRef.Ref2.IsColRel() && !rRef.Ref2.IsRowRel() && (!rRef.Ref2.IsFlag3D() || !rRef.Ref2.IsTabRel())))) { - ScRange aAbs = rRef.toAbs(aPos); + ScRange aAbs = rRef.toAbs(pDoc, aPos); if (ScRefUpdate::UpdateGrow(rArea, nGrowX, nGrowY, aAbs) != UR_NOTHING) { - rRef.SetRange(aAbs, aPos); + rRef.SetRange(pDoc->GetSheetLimits(), aAbs, aPos); bChanged = true; } } @@ -533,7 +533,7 @@ void ScRangeData::ValidateTabRefs() while ( ( t = aIter.GetNextReference() ) != nullptr ) { ScSingleRefData& rRef1 = *t->GetSingleRef(); - ScAddress aAbs = rRef1.toAbs(aPos); + ScAddress aAbs = rRef1.toAbs(pDoc, aPos); if ( rRef1.IsTabRel() && !rRef1.IsTabDeleted() ) { if (aAbs.Tab() < nMinTab) @@ -544,7 +544,7 @@ void ScRangeData::ValidateTabRefs() if ( t->GetType() == svDoubleRef ) { ScSingleRefData& rRef2 = t->GetDoubleRef()->Ref2; - aAbs = rRef2.toAbs(aPos); + aAbs = rRef2.toAbs(pDoc, aPos); if ( rRef2.IsTabRel() && !rRef2.IsTabDeleted() ) { if (aAbs.Tab() < nMinTab) @@ -575,8 +575,8 @@ void ScRangeData::ValidateTabRefs() ScSingleRefData& rRef = *t->GetSingleRef(); if (!rRef.IsTabDeleted()) { - ScAddress aAbs = rRef.toAbs(aOldPos); - rRef.SetAddress(aAbs, aPos); + ScAddress aAbs = rRef.toAbs(pDoc, aOldPos); + rRef.SetAddress(pDoc->GetSheetLimits(), aAbs, aPos); } } break; @@ -585,13 +585,13 @@ void ScRangeData::ValidateTabRefs() ScComplexRefData& rRef = *t->GetDoubleRef(); if (!rRef.Ref1.IsTabDeleted()) { - ScAddress aAbs = rRef.Ref1.toAbs(aOldPos); - rRef.Ref1.SetAddress(aAbs, aPos); + ScAddress aAbs = rRef.Ref1.toAbs(pDoc, aOldPos); + rRef.Ref1.SetAddress(pDoc->GetSheetLimits(), aAbs, aPos); } if (!rRef.Ref2.IsTabDeleted()) { - ScAddress aAbs = rRef.Ref2.toAbs(aOldPos); - rRef.Ref2.SetAddress(aAbs, aPos); + ScAddress aAbs = rRef.Ref2.toAbs(pDoc, aOldPos); + rRef.Ref2.SetAddress(pDoc->GetSheetLimits(), aAbs, aPos); } } break; diff --git a/sc/source/core/tool/refdata.cxx b/sc/source/core/tool/refdata.cxx index 3d9bfd29818e..9458ff546438 100644 --- a/sc/source/core/tool/refdata.cxx +++ b/sc/source/core/tool/refdata.cxx @@ -37,23 +37,23 @@ void ScSingleRefData::InitAddress( SCCOL nColP, SCROW nRowP, SCTAB nTabP ) mnTab = nTabP; } -void ScSingleRefData::InitAddressRel( const ScAddress& rAdr, const ScAddress& rPos ) +void ScSingleRefData::InitAddressRel( const ScDocument* pDoc, const ScAddress& rAdr, const ScAddress& rPos ) { InitFlags(); SetColRel(true); SetRowRel(true); SetTabRel(true); - SetAddress(rAdr, rPos); + SetAddress(pDoc->GetSheetLimits(), rAdr, rPos); } -void ScSingleRefData::InitFromRefAddress( const ScRefAddress& rRef, const ScAddress& rPos ) +void ScSingleRefData::InitFromRefAddress( const ScDocument* pDoc, const ScRefAddress& rRef, const ScAddress& rPos ) { InitFlags(); SetColRel( rRef.IsRelCol()); SetRowRel( rRef.IsRelRow()); SetTabRel( rRef.IsRelTab()); SetFlag3D( rRef.Tab() != rPos.Tab()); - SetAddress( rRef.GetAddress(), rPos); + SetAddress( pDoc->GetSheetLimits(), rRef.GetAddress(), rPos); } void ScSingleRefData::SetAbsCol( SCCOL nVal ) @@ -185,27 +185,12 @@ bool ScSingleRefData::ValidExternal(const ScDocument* pDoc) const return ColValid(pDoc) && RowValid(pDoc) && mnTab >= -1; } -ScAddress ScSingleRefData::toAbs( const ScAddress& rPos ) const +ScAddress ScSingleRefData::toAbs( const ScDocument* pDoc, const ScAddress& rPos ) const { - SCCOL nRetCol = Flags.bColRel ? mnCol + rPos.Col() : mnCol; - SCROW nRetRow = Flags.bRowRel ? mnRow + rPos.Row() : mnRow; - SCTAB nRetTab = Flags.bTabRel ? mnTab + rPos.Tab() : mnTab; - - ScAddress aAbs(ScAddress::INITIALIZE_INVALID); - - if (ValidCol(nRetCol)) - aAbs.SetCol(nRetCol); - - if (ValidRow(nRetRow)) - aAbs.SetRow(nRetRow); - - if (ValidTab(nRetTab)) - aAbs.SetTab(nRetTab); - - return aAbs; + return toAbs(pDoc->GetSheetLimits(), rPos); } -ScAddress ScSingleRefData::toAbs( const ScDocument* pDoc, const ScAddress& rPos ) const +ScAddress ScSingleRefData::toAbs( ScSheetLimits& rLimits, const ScAddress& rPos ) const { SCCOL nRetCol = Flags.bColRel ? mnCol + rPos.Col() : mnCol; SCROW nRetRow = Flags.bRowRel ? mnRow + rPos.Row() : mnRow; @@ -213,10 +198,10 @@ ScAddress ScSingleRefData::toAbs( const ScDocument* pDoc, const ScAddress& rPos ScAddress aAbs(ScAddress::INITIALIZE_INVALID); - if (pDoc->ValidCol(nRetCol)) + if (rLimits.ValidCol(nRetCol)) aAbs.SetCol(nRetCol); - if (pDoc->ValidRow(nRetRow)) + if (rLimits.ValidRow(nRetRow)) aAbs.SetRow(nRetRow); if (ValidTab(nRetTab)) @@ -225,41 +210,14 @@ ScAddress ScSingleRefData::toAbs( const ScDocument* pDoc, const ScAddress& rPos return aAbs; } -void ScSingleRefData::SetAddress( const ScAddress& rAddr, const ScAddress& rPos ) -{ - if (Flags.bColRel) - mnCol = rAddr.Col() - rPos.Col(); - else - mnCol = rAddr.Col(); - - if (!ValidCol(rAddr.Col())) - SetColDeleted(true); - - if (Flags.bRowRel) - mnRow = rAddr.Row() - rPos.Row(); - else - mnRow = rAddr.Row(); - - if (!ValidRow(rAddr.Row())) - SetRowDeleted(true); - - if (Flags.bTabRel) - mnTab = rAddr.Tab() - rPos.Tab(); - else - mnTab = rAddr.Tab(); - - if (!ValidTab( rAddr.Tab(), MAXTAB)) - SetTabDeleted(true); -} - -void ScSingleRefData::SetAddress( const ScDocument* pDoc, const ScAddress& rAddr, const ScAddress& rPos ) +void ScSingleRefData::SetAddress( ScSheetLimits& rLimits, const ScAddress& rAddr, const ScAddress& rPos ) { if (Flags.bColRel) mnCol = rAddr.Col() - rPos.Col(); else mnCol = rAddr.Col(); - if (!pDoc->ValidCol(rAddr.Col())) + if (!rLimits.ValidCol(rAddr.Col())) SetColDeleted(true); if (Flags.bRowRel) @@ -267,7 +225,7 @@ void ScSingleRefData::SetAddress( const ScDocument* pDoc, const ScAddress& rAddr else mnRow = rAddr.Row(); - if (!pDoc->ValidRow(rAddr.Row())) + if (!rLimits.ValidRow(rAddr.Row())) SetRowDeleted(true); if (Flags.bTabRel) @@ -419,7 +377,7 @@ void ScSingleRefData::Dump( int nIndent ) const } #endif -void ScComplexRefData::InitFromRefAddresses( const ScRefAddress& rRef1, const ScRefAddress& rRef2, const ScAddress& rPos ) +void ScComplexRefData::InitFromRefAddresses( const ScDocument* pDoc, const ScRefAddress& rRef1, const ScRefAddress& rRef2, const ScAddress& rPos ) { InitFlags(); Ref1.SetColRel( rRef1.IsRelCol()); @@ -430,13 +388,13 @@ void ScComplexRefData::InitFromRefAddresses( const ScRefAddress& rRef1, const Sc Ref2.SetRowRel( rRef2.IsRelRow()); Ref2.SetTabRel( rRef2.IsRelTab()); Ref2.SetFlag3D( rRef1.Tab() != rRef2.Tab()); - SetRange( ScRange( rRef1.GetAddress(), rRef2.GetAddress()), rPos); + SetRange( pDoc->GetSheetLimits(), ScRange( rRef1.GetAddress(), rRef2.GetAddress()), rPos); } -ScComplexRefData& ScComplexRefData::Extend( const ScSingleRefData & rRef, const ScAddress & rPos ) +ScComplexRefData& ScComplexRefData::Extend( ScSheetLimits& rLimits, const ScSingleRefData & rRef, const ScAddress & rPos ) { bool bInherit3D = (Ref1.IsFlag3D() && !Ref2.IsFlag3D() && !rRef.IsFlag3D()); - ScRange aAbsRange = toAbs(rPos); + ScRange aAbsRange = toAbs(rLimits, rPos); ScSingleRefData aRef = rRef; // If no sheet was given in the extending part, let it point to the same @@ -450,7 +408,7 @@ ScComplexRefData& ScComplexRefData::Extend( const ScSingleRefData & rRef, const else aRef.SetAbsTab( Ref2.Tab()); } - ScAddress aAbs = aRef.toAbs(rPos); + ScAddress aAbs = aRef.toAbs(rLimits, rPos); if (aAbs.Col() < aAbsRange.aStart.Col()) aAbsRange.aStart.SetCol(aAbs.Col()); @@ -507,14 +465,14 @@ ScComplexRefData& ScComplexRefData::Extend( const ScSingleRefData & rRef, const if (rRef.IsRelName()) Ref2.SetRelName(true); - SetRange(aAbsRange, rPos); + SetRange(rLimits, aAbsRange, rPos); return *this; } -ScComplexRefData& ScComplexRefData::Extend( const ScComplexRefData & rRef, const ScAddress & rPos ) +ScComplexRefData& ScComplexRefData::Extend( ScSheetLimits& rLimits, const ScComplexRefData & rRef, const ScAddress & rPos ) { - return Extend( rRef.Ref1, rPos).Extend( rRef.Ref2, rPos); + return Extend( rLimits, rRef.Ref1, rPos).Extend( rLimits, rRef.Ref2, rPos); } bool ScComplexRefData::Valid(const ScDocument* pDoc) const @@ -527,20 +485,20 @@ bool ScComplexRefData::ValidExternal(const ScDocument* pDoc) const return Ref1.ValidExternal(pDoc) && Ref2.ColValid(pDoc) && Ref2.RowValid(pDoc) && Ref1.Tab() <= Ref2.Tab(); } -ScRange ScComplexRefData::toAbs( const ScAddress& rPos ) const +ScRange ScComplexRefData::toAbs( const ScDocument* pDoc, const ScAddress& rPos ) const { - return ScRange(Ref1.toAbs(rPos), Ref2.toAbs(rPos)); + return toAbs(pDoc->GetSheetLimits(), rPos); } -ScRange ScComplexRefData::toAbs( const ScDocument* pDoc, const ScAddress& rPos ) const +ScRange ScComplexRefData::toAbs( ScSheetLimits& rLimits, const ScAddress& rPos ) const { - return ScRange(Ref1.toAbs(pDoc, rPos), Ref2.toAbs(pDoc, rPos)); + return ScRange(Ref1.toAbs(rLimits, rPos), Ref2.toAbs(rLimits, rPos)); } -void ScComplexRefData::SetRange( const ScRange& rRange, const ScAddress& rPos ) +void ScComplexRefData::SetRange( ScSheetLimits& rLimits, const ScRange& rRange, const ScAddress& rPos ) { - Ref1.SetAddress(rRange.aStart, rPos); - Ref2.SetAddress(rRange.aEnd, rPos); + Ref1.SetAddress(rLimits, rRange.aStart, rPos); + Ref2.SetAddress(rLimits, rRange.aEnd, rPos); } void ScComplexRefData::PutInOrder( const ScAddress& rPos ) diff --git a/sc/source/core/tool/reftokenhelper.cxx b/sc/source/core/tool/reftokenhelper.cxx index 15341e92f930..222b1bb3e211 100644 --- a/sc/source/core/tool/reftokenhelper.cxx +++ b/sc/source/core/tool/reftokenhelper.cxx @@ -121,6 +121,7 @@ void ScRefTokenHelper::compileRangeRepresentation( } bool ScRefTokenHelper::getRangeFromToken( + const ScDocument* pDoc, ScRange& rRange, const ScTokenRef& pToken, const ScAddress& rPos, bool bExternal) { StackVar eType = pToken->GetType(); @@ -134,7 +135,7 @@ bool ScRefTokenHelper::getRangeFromToken( return false; const ScSingleRefData& rRefData = *pToken->GetSingleRef(); - rRange.aStart = rRefData.toAbs(rPos); + rRange.aStart = rRefData.toAbs(pDoc, rPos); rRange.aEnd = rRange.aStart; return true; } @@ -146,7 +147,7 @@ bool ScRefTokenHelper::getRangeFromToken( return false; const ScComplexRefData& rRefData = *pToken->GetDoubleRef(); - rRange = rRefData.toAbs(rPos); + rRange = rRefData.toAbs(pDoc, rPos); return true; } default: @@ -156,12 +157,12 @@ bool ScRefTokenHelper::getRangeFromToken( } void ScRefTokenHelper::getRangeListFromTokens( - ScRangeList& rRangeList, const vector<ScTokenRef>& rTokens, const ScAddress& rPos) + const ScDocument* pDoc, ScRangeList& rRangeList, const vector<ScTokenRef>& rTokens, const ScAddress& rPos) { for (const auto& rToken : rTokens) { ScRange aRange; - getRangeFromToken(aRange, rToken, rPos); + getRangeFromToken(pDoc, aRange, rToken, rPos); rRangeList.push_back(aRange); } } @@ -223,6 +224,7 @@ bool ScRefTokenHelper::isExternalRef(const ScTokenRef& pToken) } bool ScRefTokenHelper::intersects( + const ScDocument* pDoc, const vector<ScTokenRef>& rTokens, const ScTokenRef& pToken, const ScAddress& rPos) { if (!isRef(pToken)) @@ -232,7 +234,7 @@ bool ScRefTokenHelper::intersects( sal_uInt16 nFileId = bExternal ? pToken->GetIndex() : 0; ScRange aRange; - getRangeFromToken(aRange, pToken, rPos, bExternal); + getRangeFromToken(pDoc, aRange, pToken, rPos, bExternal); for (const ScTokenRef& p : rTokens) { @@ -243,7 +245,7 @@ bool ScRefTokenHelper::intersects( continue; ScRange aRange2; - getRangeFromToken(aRange2, p, rPos, bExternal); + getRangeFromToken(pDoc, aRange2, p, rPos, bExternal); if (bExternal && nFileId != p->GetIndex()) // different external file @@ -341,7 +343,7 @@ private: if (!ScRefTokenHelper::getDoubleRefDataFromToken(aOldData, pOldToken)) continue; - ScRange aOld = aOldData.toAbs(rPos), aNew = aData.toAbs(rPos); + ScRange aOld = aOldData.toAbs(pDoc, rPos), aNew = aData.toAbs(pDoc, rPos); if (aNew.aStart.Tab() != aOld.aStart.Tab() || aNew.aEnd.Tab() != aOld.aEnd.Tab()) // Sheet ranges differ. @@ -366,7 +368,7 @@ private: { aNew.aStart.SetCol(nNewMin); aNew.aEnd.SetCol(nNewMax); - aNewData.SetRange(aNew, rPos); + aNewData.SetRange(pDoc->GetSheetLimits(), aNew, rPos); } } else if (bSameCols) @@ -380,7 +382,7 @@ private: { aNew.aStart.SetRow(nNewMin); aNew.aEnd.SetRow(nNewMax); - aNewData.SetRange(aNew, rPos); + aNewData.SetRange(pDoc->GetSheetLimits(), aNew, rPos); } } diff --git a/sc/source/core/tool/refupdat.cxx b/sc/source/core/tool/refupdat.cxx index 9d1e290569e9..c1c1ffa19cd5 100644 --- a/sc/source/core/tool/refupdat.cxx +++ b/sc/source/core/tool/refupdat.cxx @@ -463,7 +463,7 @@ ScRefUpdateRes ScRefUpdate::Update( UpdateRefMode eUpdateRefMode, void ScRefUpdate::MoveRelWrap( const ScDocument* pDoc, const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow, ScComplexRefData& rRef ) { - ScRange aAbsRange = rRef.toAbs(rPos); + ScRange aAbsRange = rRef.toAbs(pDoc, rPos); if( rRef.Ref1.IsColRel() ) { SCCOL nCol = aAbsRange.aStart.Col(); @@ -503,7 +503,7 @@ void ScRefUpdate::MoveRelWrap( const ScDocument* pDoc, const ScAddress& rPos, } aAbsRange.PutInOrder(); - rRef.SetRange(aAbsRange, rPos); + rRef.SetRange(pDoc->GetSheetLimits(), aAbsRange, rPos); } void ScRefUpdate::DoTranspose( SCCOL& rCol, SCROW& rRow, SCTAB& rTab, diff --git a/sc/source/core/tool/sharedformula.cxx b/sc/source/core/tool/sharedformula.cxx index 7573534bdd86..35e93a4155b5 100644 --- a/sc/source/core/tool/sharedformula.cxx +++ b/sc/source/core/tool/sharedformula.cxx @@ -120,7 +120,7 @@ bool SharedFormulaUtil::splitFormulaCellGroup(const CellStoreType::position_type return true; } -bool SharedFormulaUtil::splitFormulaCellGroups(CellStoreType& rCells, std::vector<SCROW>& rBounds) +bool SharedFormulaUtil::splitFormulaCellGroups(const ScDocument* pDoc, CellStoreType& rCells, std::vector<SCROW>& rBounds) { if (rBounds.empty()) return false; @@ -141,7 +141,7 @@ bool SharedFormulaUtil::splitFormulaCellGroups(CellStoreType& rCells, std::vecto for (++it; it != itEnd; ++it) { nRow = *it; - if (ValidRow(nRow)) + if (pDoc->ValidRow(nRow)) { aPos = rCells.position(aPos.first, nRow); if (aPos.first == rCells.end()) @@ -379,7 +379,7 @@ void SharedFormulaUtil::unshareFormulaCells(const ScDocument* pDoc, CellStoreTyp // Remove duplicates again (the vector should still be sorted). aRows2.erase(std::unique(aRows2.begin(), aRows2.end()), aRows2.end()); - splitFormulaCellGroups(rCells, aRows2); + splitFormulaCellGroups(pDoc, rCells, aRows2); } void SharedFormulaUtil::startListeningAsGroup( sc::StartListeningContext& rCxt, ScFormulaCell** ppSharedTop ) @@ -411,7 +411,7 @@ void SharedFormulaUtil::startListeningAsGroup( sc::StartListeningContext& rCxt, case formula::svSingleRef: { const ScSingleRefData* pRef = t->GetSingleRef(); - ScAddress aPos = pRef->toAbs(rTopCell.aPos); + ScAddress aPos = pRef->toAbs(&rDoc, rTopCell.aPos); ScFormulaCell** pp = ppSharedTop; ScFormulaCell** ppEnd = ppSharedTop + xGroup->mnLength; for (; pp != ppEnd; ++pp) @@ -429,8 +429,8 @@ void SharedFormulaUtil::startListeningAsGroup( sc::StartListeningContext& rCxt, { const ScSingleRefData& rRef1 = *t->GetSingleRef(); const ScSingleRefData& rRef2 = *t->GetSingleRef2(); - ScAddress aPos1 = rRef1.toAbs(rTopCell.aPos); - ScAddress aPos2 = rRef2.toAbs(rTopCell.aPos); + ScAddress aPos1 = rRef1.toAbs(&rDoc, rTopCell.aPos); + ScAddress aPos2 = rRef2.toAbs(&rDoc, rTopCell.aPos); ScRange aOrigRange(aPos1, aPos2); ScRange aListenedRange = aOrigRange; diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index 6fd70a6eaf23..1070fca89e23 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -428,7 +428,7 @@ FormulaToken* ScRawToken::CreateToken(ScSheetLimits& rLimits) const namespace { // TextEqual: if same formula entered (for optimization in sort) -bool checkTextEqual( const FormulaToken& _rToken1, const FormulaToken& _rToken2 ) +bool checkTextEqual( ScSheetLimits& rLimits, const FormulaToken& _rToken1, const FormulaToken& _rToken2 ) { assert( (_rToken1.GetType() == svSingleRef || _rToken1.GetType() == svDoubleRef) @@ -455,7 +455,7 @@ bool checkTextEqual( const FormulaToken& _rToken1, const FormulaToken& _rToken2 aTemp2 = *_rToken2.GetDoubleRef(); ScAddress aPos; - ScRange aRange1 = aTemp1.toAbs(aPos), aRange2 = aTemp2.toAbs(aPos); + ScRange aRange1 = aTemp1.toAbs(rLimits, aPos), aRange2 = aTemp2.toAbs(rLimits, aPos); // memcmp doesn't work because of the alignment byte after bFlags. // After SmartRelAbs only absolute parts have to be compared. @@ -545,7 +545,7 @@ FormulaTokenRef extendRangeReference( ScSheetLimits& rLimits, FormulaToken & rTo ScComplexRefData aRef; aRef.Ref1 = aRef.Ref2 = *rTok1.GetSingleRef(); aRef.Ref2.SetFlag3D( false); - aRef.Extend(rRef2, rPos); + aRef.Extend(rLimits, rRef2, rPos); if (bExternal) xRes = new ScExternalDoubleRefToken( rTok1.GetIndex(), rTok1.GetString(), aRef); else @@ -587,10 +587,10 @@ FormulaTokenRef extendRangeReference( ScSheetLimits& rLimits, FormulaToken & rTo switch (sv[i]) { case svSingleRef: - rRef.Extend(*pt[i]->GetSingleRef(), rPos); + rRef.Extend(rLimits, *pt[i]->GetSingleRef(), rPos); break; case svDoubleRef: - rRef.Extend(*pt[i]->GetDoubleRef(), rPos); + rRef.Extend(rLimits, *pt[i]->GetDoubleRef(), rPos); break; case svRefList: { @@ -599,7 +599,7 @@ FormulaTokenRef extendRangeReference( ScSheetLimits& rLimits, FormulaToken & rTo return nullptr; for (const auto& rRefData : *p) { - rRef.Extend(rRefData, rPos); + rRef.Extend(rLimits, rRefData, rPos); } } break; @@ -607,13 +607,13 @@ FormulaTokenRef extendRangeReference( ScSheetLimits& rLimits, FormulaToken & rTo if (rRef.Ref1.IsFlag3D() || rRef.Ref2.IsFlag3D()) return nullptr; // no other sheets with external refs else - rRef.Extend(*pt[i]->GetSingleRef(), rPos); + rRef.Extend(rLimits, *pt[i]->GetSingleRef(), rPos); break; case svExternalDoubleRef: if (rRef.Ref1.IsFlag3D() || rRef.Ref2.IsFlag3D()) return nullptr; // no other sheets with external refs else - rRef.Extend(*pt[i]->GetDoubleRef(), rPos); + rRef.Extend(rLimits, *pt[i]->GetDoubleRef(), rPos); break; default: ; // nothing, prevent compiler warning @@ -629,7 +629,7 @@ const ScSingleRefData* ScSingleRefToken::GetSingleRef() const { return &aSin ScSingleRefData* ScSingleRefToken::GetSingleRef() { return &aSingleRef; } bool ScSingleRefToken::TextEqual( const FormulaToken& _rToken ) const { - return FormulaToken::operator ==(_rToken) && checkTextEqual(*this, _rToken); + return FormulaToken::operator ==(_rToken) && checkTextEqual(mrSheetLimits, *this, _rToken); } bool ScSingleRefToken::operator==( const FormulaToken& r ) const { @@ -644,7 +644,7 @@ const ScSingleRefData* ScDoubleRefToken::GetSingleRef2() const { return &aDou ScSingleRefData* ScDoubleRefToken::GetSingleRef2() { return &aDoubleRef.Ref2; } bool ScDoubleRefToken::TextEqual( const FormulaToken& _rToken ) const { - return FormulaToken::operator ==(_rToken) && checkTextEqual(*this, _rToken); + return FormulaToken::operator ==(_rToken) && checkTextEqual(mrSheetLimits, *this, _rToken); } bool ScDoubleRefToken::operator==( const FormulaToken& r ) const { @@ -1689,7 +1689,7 @@ bool ScTokenArray::ImplGetReference( ScRange& rRange, const ScAddress& rPos, boo if ( pToken->GetType() == svSingleRef ) { const ScSingleRefData& rRef = *static_cast<const ScSingleRefToken*>(pToken)->GetSingleRef(); - rRange.aStart = rRange.aEnd = rRef.toAbs(rPos); + rRange.aStart = rRange.aEnd = rRef.toAbs(*mxSheetLimits, rPos); bIs = !bValidOnly || mxSheetLimits->ValidAddress(rRange.aStart); } else if ( pToken->GetType() == svDoubleRef ) @@ -1697,8 +1697,8 @@ bool ScTokenArray::ImplGetReference( ScRange& rRange, const ScAddress& rPos, boo const ScComplexRefData& rCompl = *static_cast<const ScDoubleRefToken*>(pToken)->GetDoubleRef(); const ScSingleRefData& rRef1 = rCompl.Ref1; const ScSingleRefData& rRef2 = rCompl.Ref2; - rRange.aStart = rRef1.toAbs(rPos); - rRange.aEnd = rRef2.toAbs(rPos); + rRange.aStart = rRef1.toAbs(*mxSheetLimits, rPos); + rRange.aEnd = rRef2.toAbs(*mxSheetLimits, rPos); bIs = !bValidOnly || mxSheetLimits->ValidRange(rRange); } } @@ -2311,7 +2311,7 @@ bool ScTokenArray::GetAdjacentExtendOfOuterFuncRefs( SCCOLROW& nExtend, case svSingleRef : { ScSingleRefData& rRef = *p->GetSingleRef(); - ScAddress aAbs = rRef.toAbs(rPos); + ScAddress aAbs = rRef.toAbs(*mxSheetLimits, rPos); switch ( eDir ) { case DIR_BOTTOM : @@ -2348,7 +2348,7 @@ bool ScTokenArray::GetAdjacentExtendOfOuterFuncRefs( SCCOLROW& nExtend, case svDoubleRef : { ScComplexRefData& rRef = *p->GetDoubleRef(); - ScRange aAbs = rRef.toAbs(rPos); + ScRange aAbs = rRef.toAbs(*mxSheetLimits, rPos); switch ( eDir ) { case DIR_BOTTOM : @@ -2416,7 +2416,7 @@ bool SkipReference(formula::FormulaToken* pToken, const ScAddress& rPos, const S { ScRange aRange; - if (!ScRefTokenHelper::getRangeFromToken(aRange, pToken, rPos)) + if (!ScRefTokenHelper::getRangeFromToken(pOldDoc, aRange, pToken, rPos)) return true; if (bRangeName && aRange.aStart.Tab() == rPos.Tab()) @@ -3083,7 +3083,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnShift( const sc::RefUpdateCon case svSingleRef: { ScSingleRefData& rRef = *p->GetSingleRef(); - ScAddress aAbs = rRef.toAbs(rOldPos); + ScAddress aAbs = rRef.toAbs(*mxSheetLimits, rOldPos); if (rCxt.isDeleted() && aSelectedRange.In(aAbs)) { @@ -3096,7 +3096,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnShift( const sc::RefUpdateCon if (!rCxt.isDeleted() && rRef.IsDeleted()) { // Check if the token has reference to previously deleted region. - ScAddress aCheckPos = rRef.toAbs(aNewPos); + ScAddress aCheckPos = rRef.toAbs(*mxSheetLimits, aNewPos); if (rCxt.maRange.In(aCheckPos)) { restoreDeletedRef(rRef, rCxt); @@ -3113,13 +3113,13 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnShift( const sc::RefUpdateCon aRes.mbReferenceModified = true; } - rRef.SetAddress(aAbs, aNewPos); + rRef.SetAddress(*mxSheetLimits, aAbs, aNewPos); } break; case svDoubleRef: { ScComplexRefData& rRef = *p->GetDoubleRef(); - ScRange aAbs = rRef.toAbs(rOldPos); + ScRange aAbs = rRef.toAbs(*mxSheetLimits, rOldPos); if (rCxt.isDeleted()) { @@ -3136,7 +3136,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnShift( const sc::RefUpdateCon if (eSR == SHRUNK) { // The reference range has been shrunk. - rRef.SetRange(aAbs, aNewPos); + rRef.SetRange(*mxSheetLimits, aAbs, aNewPos); aRes.mbValueChanged = true; aRes.mbReferenceModified = true; break; @@ -3165,7 +3165,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnShift( const sc::RefUpdateCon if (!rCxt.isDeleted() && rRef.IsDeleted()) { // Check if the token has reference to previously deleted region. - ScRange aCheckRange = rRef.toAbs(aNewPos); + ScRange aCheckRange = rRef.toAbs(*mxSheetLimits, aNewPos); if (aSelectedRange.In(aCheckRange)) { // This reference was previously in the deleted region. Restore it. @@ -3180,7 +3180,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnShift( const sc::RefUpdateCon if (expandRange(rCxt, aAbs, aSelectedRange, rRef)) { // The reference range has been expanded. - rRef.SetRange(aAbs, aNewPos); + rRef.SetRange(*mxSheetLimits, aAbs, aNewPos); aRes.mbValueChanged = true; aRes.mbReferenceModified = true; break; @@ -3189,7 +3189,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnShift( const sc::RefUpdateCon if (expandRangeByEdge(rCxt, aAbs, aSelectedRange, rRef)) { // The reference range has been expanded on the edge. - rRef.SetRange(aAbs, aNewPos); + rRef.SetRange(*mxSheetLimits, aAbs, aNewPos); aRes.mbValueChanged = true; aRes.mbReferenceModified = true; break; @@ -3223,7 +3223,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnShift( const sc::RefUpdateCon aRes.mbValueChanged = true; } - rRef.SetRange(aAbs, aNewPos); + rRef.SetRange(*mxSheetLimits, aAbs, aNewPos); } break; case svExternalSingleRef: @@ -3231,16 +3231,16 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnShift( const sc::RefUpdateCon // For external reference, just reset the reference with // respect to the new cell position. ScSingleRefData& rRef = *p->GetSingleRef(); - ScAddress aAbs = rRef.toAbs(rOldPos); - rRef.SetAddress(aAbs, aNewPos); + ScAddress aAbs = rRef.toAbs(*mxSheetLimits, rOldPos); + rRef.SetAddress(*mxSheetLimits, aAbs, aNewPos); } break; case svExternalDoubleRef: { // Same as above. ScComplexRefData& rRef = *p->GetDoubleRef(); - ScRange aAbs = rRef.toAbs(rOldPos); - rRef.SetRange(aAbs, aNewPos); + ScRange aAbs = rRef.toAbs(*mxSheetLimits, rOldPos); + rRef.SetRange(*mxSheetLimits, aAbs, aNewPos); } break; default: @@ -3315,7 +3315,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnMove( case svSingleRef: { ScSingleRefData& rRef = *p->GetSingleRef(); - ScAddress aAbs = rRef.toAbs(rOldPos); + ScAddress aAbs = rRef.toAbs(*mxSheetLimits, rOldPos); if (aOldRange.In(aAbs)) { ScAddress aErrorPos( ScAddress::UNINITIALIZED ); @@ -3329,14 +3329,14 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnMove( aRes.mbValueChanged = true; } - rRef.SetAddress(aAbs, rNewPos); + rRef.SetAddress(*mxSheetLimits, aAbs, rNewPos); rRef.SetFlag3D(aAbs.Tab() != rNewPos.Tab() || !rRef.IsTabRel()); } break; case svDoubleRef: { ScComplexRefData& rRef = *p->GetDoubleRef(); - ScRange aAbs = rRef.toAbs(rOldPos); + ScRange aAbs = rRef.toAbs(*mxSheetLimits, rOldPos); if (aOldRange.In(aAbs)) { ScRange aErrorRange( ScAddress::UNINITIALIZED ); @@ -3350,7 +3350,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnMove( aRes.mbValueChanged = true; } - rRef.SetRange(aAbs, rNewPos); + rRef.SetRange(*mxSheetLimits, aAbs, rNewPos); // Absolute sheet reference => set 3D flag. // More than one sheet referenced => has to have both 3D flags. // If end part has 3D flag => start part must have it too. @@ -3362,15 +3362,15 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnMove( case svExternalSingleRef: { ScSingleRefData& rRef = *p->GetSingleRef(); - ScAddress aAbs = rRef.toAbs(rOldPos); - rRef.SetAddress(aAbs, rNewPos); + ScAddress aAbs = rRef.toAbs(*mxSheetLimits, rOldPos); + rRef.SetAddress(*mxSheetLimits, aAbs, rNewPos); } break; case svExternalDoubleRef: { ScComplexRefData& rRef = *p->GetDoubleRef(); - ScRange aAbs = rRef.toAbs(rOldPos); - rRef.SetRange(aAbs, rNewPos); + ScRange aAbs = rRef.toAbs(*mxSheetLimits, rOldPos); + rRef.SetRange(*mxSheetLimits, aAbs, rNewPos); } break; default: @@ -3424,7 +3424,7 @@ void ScTokenArray::MoveReferenceColReorder( { formula::FormulaToken* pToken = *p; ScSingleRefData& rRef = *pToken->GetSingleRef(); - ScAddress aAbs = rRef.toAbs(rPos); + ScAddress aAbs = rRef.toAbs(*mxSheetLimits, rPos); if (aAbs.Tab() == nTab && nRow1 <= aAbs.Row() && aAbs.Row() <= nRow2) { @@ -3435,7 +3435,7 @@ void ScTokenArray::MoveReferenceColReorder( // This column is reordered. SCCOL nNewCol = it->second; aAbs.SetCol(nNewCol); - rRef.SetAddress(aAbs, rPos); + rRef.SetAddress(*mxSheetLimits, aAbs, rPos); } } } @@ -3444,7 +3444,7 @@ void ScTokenArray::MoveReferenceColReorder( { formula::FormulaToken* pToken = *p; ScComplexRefData& rRef = *pToken->GetDoubleRef(); - ScRange aAbs = rRef.toAbs(rPos); + ScRange aAbs = rRef.toAbs(*mxSheetLimits, rPos); if (aAbs.aStart.Tab() != aAbs.aEnd.Tab()) // Must be a single-sheet reference. @@ -3464,7 +3464,7 @@ void ScTokenArray::MoveReferenceColReorder( SCCOL nNewCol = it->second; aAbs.aStart.SetCol(nNewCol); aAbs.aEnd.SetCol(nNewCol); - rRef.SetRange(aAbs, rPos); + rRef.SetRange(*mxSheetLimits, aAbs, rPos); } } } @@ -3487,7 +3487,7 @@ void ScTokenArray::MoveReferenceRowReorder( const ScAddress& rPos, SCTAB nTab, S { formula::FormulaToken* pToken = *p; ScSingleRefData& rRef = *pToken->GetSingleRef(); - ScAddress aAbs = rRef.toAbs(rPos); + ScAddress aAbs = rRef.toAbs(*mxSheetLimits, rPos); if (aAbs.Tab() == nTab && nCol1 <= aAbs.Col() && aAbs.Col() <= nCol2) { @@ -3498,7 +3498,7 @@ void ScTokenArray::MoveReferenceRowReorder( const ScAddress& rPos, SCTAB nTab, S // This column is reordered. SCROW nNewRow = it->second; aAbs.SetRow(nNewRow); - rRef.SetAddress(aAbs, rPos); + rRef.SetAddress(*mxSheetLimits, aAbs, rPos); } } } @@ -3507,7 +3507,7 @@ void ScTokenArray::MoveReferenceRowReorder( const ScAddress& rPos, SCTAB nTab, S { formula::FormulaToken* pToken = *p; ScComplexRefData& rRef = *pToken->GetDoubleRef(); - ScRange aAbs = rRef.toAbs(rPos); + ScRange aAbs = rRef.toAbs(*mxSheetLimits, rPos); if (aAbs.aStart.Tab() != aAbs.aEnd.Tab()) // Must be a single-sheet reference. @@ -3527,7 +3527,7 @@ void ScTokenArray::MoveReferenceRowReorder( const ScAddress& rPos, SCTAB nTab, S SCROW nNewRow = it->second; aAbs.aStart.SetRow(nNewRow); aAbs.aEnd.SetRow(nNewRow); - rRef.SetRange(aAbs, rPos); + rRef.SetRange(*mxSheetLimits, aAbs, rPos); } } } @@ -3544,7 +3544,7 @@ bool adjustSingleRefInName( ScSingleRefData& rRef, const sc::RefUpdateContext& rCxt, const ScAddress& rPos, ScComplexRefData* pEndOfComplex ) { - ScAddress aAbs = rRef.toAbs(rPos); + ScAddress aAbs = rRef.toAbs(&rCxt.mrDoc, rPos); if (aAbs.Tab() < rCxt.maRange.aStart.Tab() || rCxt.maRange.aEnd.Tab() < aAbs.Tab()) { @@ -3552,7 +3552,7 @@ bool adjustSingleRefInName( return false; } - if (!rCxt.maRange.In(rRef.toAbs(rPos))) + if (!rCxt.maRange.In(rRef.toAbs(&rCxt.mrDoc, rPos))) return false; bool bChanged = false; @@ -3611,7 +3611,7 @@ bool adjustDoubleRefInName( { if (rCxt.mnRowDelta > 0 && !rRef.Ref1.IsRowRel() && !rRef.Ref2.IsRowRel()) { - ScRange aAbs = rRef.toAbs(rPos); + ScRange aAbs = rRef.toAbs(&rCxt.mrDoc, rPos); // Expand only if at least two rows tall. if (aAbs.aStart.Row() < aAbs.aEnd.Row()) { @@ -3628,7 +3628,7 @@ bool adjustDoubleRefInName( } if (rCxt.mnColDelta > 0 && !rRef.Ref1.IsColRel() && !rRef.Ref2.IsColRel()) { - ScRange aAbs = rRef.toAbs(rPos); + ScRange aAbs = rRef.toAbs(&rCxt.mrDoc, rPos); // Expand only if at least two columns wide. if (aAbs.aStart.Col() < aAbs.aEnd.Col()) { @@ -3721,7 +3721,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceInName( // Don't modify relative references in names. break; - ScAddress aAbs = rRef.toAbs(rPos); + ScAddress aAbs = rRef.toAbs(&rCxt.mrDoc, rPos); if (aAbs.Col() < rCxt.maRange.aStart.Col() || rCxt.maRange.aEnd.Col() < aAbs.Col()) // column of the reference is not in the deleted column range. @@ -3750,7 +3750,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceInName( // Don't modify relative references in names. break; - ScAddress aAbs = rRef.toAbs(rPos); + ScAddress aAbs = rRef.toAbs(&rCxt.mrDoc, rPos); if (aAbs.Row() < rCxt.maRange.aStart.Row() || rCxt.maRange.aEnd.Row() < aAbs.Row()) // row of the reference is not in the deleted row range. @@ -3779,7 +3779,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceInName( case svDoubleRef: { ScComplexRefData& rRef = *p->GetDoubleRef(); - ScRange aAbs = rRef.toAbs(rPos); + ScRange aAbs = rRef.toAbs(&rCxt.mrDoc, rPos); if (aAbs.aStart.Tab() > rCxt.maRange.aEnd.Tab() || aAbs.aEnd.Tab() < rCxt.maRange.aStart.Tab()) // Sheet references not affected. @@ -3991,7 +3991,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceInMovedName( const sc::RefUpdat if (rRef.IsColRel() || rRef.IsRowRel() || rRef.IsTabRel()) continue; - ScAddress aAbs = rRef.toAbs(rPos); + ScAddress aAbs = rRef.toAbs(&rCxt.mrDoc, rPos); if (aOldRange.In(aAbs)) { ScAddress aErrorPos( ScAddress::UNINITIALIZED ); @@ -4000,7 +4000,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceInMovedName( const sc::RefUpdat aRes.mbReferenceModified = true; } - rRef.SetAddress(aAbs, rPos); + rRef.SetAddress(rCxt.mrDoc.GetSheetLimits(), aAbs, rPos); } break; case svDoubleRef: @@ -4010,7 +4010,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceInMovedName( const sc::RefUpdat rRef.Ref2.IsColRel() || rRef.Ref2.IsRowRel() || rRef.Ref2.IsTabRel()) continue; - ScRange aAbs = rRef.toAbs(rPos); + ScRange aAbs = rRef.toAbs(&rCxt.mrDoc, rPos); if (aOldRange.In(aAbs)) { ScRange aErrorRange( ScAddress::UNINITIALIZED ); @@ -4019,7 +4019,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceInMovedName( const sc::RefUpdat aRes.mbReferenceModified = true; } - rRef.SetRange(aAbs, rPos); + rRef.SetRange(rCxt.mrDoc.GetSheetLimits(), aAbs, rPos); } break; default: @@ -4033,9 +4033,9 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceInMovedName( const sc::RefUpdat namespace { -bool adjustSingleRefOnDeletedTab( ScSingleRefData& rRef, SCTAB nDelPos, SCTAB nSheets, const ScAddress& rOldPos, const ScAddress& rNewPos ) +bool adjustSingleRefOnDeletedTab( ScSheetLimits& rLimits, ScSingleRefData& rRef, SCTAB nDelPos, SCTAB nSheets, const ScAddress& rOldPos, const ScAddress& rNewPos ) { - ScAddress aAbs = rRef.toAbs(rOldPos); + ScAddress aAbs = rRef.toAbs(rLimits, rOldPos); if (nDelPos <= aAbs.Tab() && aAbs.Tab() < nDelPos + nSheets) { rRef.SetTabDeleted(true); @@ -4046,45 +4046,45 @@ bool adjustSingleRefOnDeletedTab( ScSingleRefData& rRef, SCTAB nDelPos, SCTAB nS { // Reference sheet needs to be adjusted. aAbs.IncTab(-1*nSheets); - rRef.SetAddress(aAbs, rNewPos); + rRef.SetAddress(rLimits, aAbs, rNewPos); return true; } else if (rOldPos.Tab() != rNewPos.Tab()) { // Cell itself has moved. - rRef.SetAddress(aAbs, rNewPos); + rRef.SetAddress(rLimits, aAbs, rNewPos); return true; } return false; } -bool adjustSingleRefOnInsertedTab( ScSingleRefData& rRef, SCTAB nInsPos, SCTAB nSheets, const ScAddress& rOldPos, const ScAddress& rNewPos ) +bool adjustSingleRefOnInsertedTab( ScSheetLimits& rLimits, ScSingleRefData& rRef, SCTAB nInsPos, SCTAB nSheets, const ScAddress& rOldPos, const ScAddress& rNewPos ) { - ScAddress aAbs = rRef.toAbs(rOldPos); + ScAddress aAbs = rRef.toAbs(rLimits, rOldPos); if (nInsPos <= aAbs.Tab()) { // Reference sheet needs to be adjusted. aAbs.IncTab(nSheets); - rRef.SetAddress(aAbs, rNewPos); + rRef.SetAddress(rLimits, aAbs, rNewPos); return true; } else if (rOldPos.Tab() != rNewPos.Tab()) { // Cell itself has moved. - rRef.SetAddress(aAbs, rNewPos); + rRef.SetAddress(rLimits, aAbs, rNewPos); return true; } return false; } -bool adjustDoubleRefOnDeleteTab(ScComplexRefData& rRef, SCTAB nDelPos, SCTAB nSheets, const ScAddress& rOldPos, const ScAddress& rNewPos) +bool adjustDoubleRefOnDeleteTab(ScSheetLimits& rLimits, ScComplexRefData& rRef, SCTAB nDelPos, SCTAB nSheets, const ScAddress& rOldPos, const ScAddress& rNewPos) { ScSingleRefData& rRef1 = rRef.Ref1; ScSingleRefData& rRef2 = rRef.Ref2; - ScAddress aStartPos = rRef1.toAbs(rOldPos); - ScAddress aEndPos = rRef2.toAbs(rOldPos); + ScAddress aStartPos = rRef1.toAbs(rLimits, rOldPos); + ScAddress aEndPos = rRef2.toAbs(rLimits, rOldPos); bool bMoreThanOneTab = aStartPos.Tab() != aEndPos.Tab(); bool bModified = false; if (bMoreThanOneTab && aStartPos.Tab() == nDelPos && nDelPos + nSheets <= aEndPos.Tab()) @@ -4097,7 +4097,7 @@ bool adjustDoubleRefOnDeleteTab(ScComplexRefData& rRef, SCTAB nDelPos, SCTAB nSh } else { - bModified = adjustSingleRefOnDeletedTab(rRef1, nDelPos, nSheets, rOldPos, rNewPos); + bModified = adjustSingleRefOnDeletedTab(rLimits, rRef1, nDelPos, nSheets, rOldPos, rNewPos); } if (bMoreThanOneTab && aEndPos.Tab() == nDelPos && aStartPos.Tab() <= nDelPos - nSheets) @@ -4110,7 +4110,7 @@ bool adjustDoubleRefOnDeleteTab(ScComplexRefData& rRef, SCTAB nDelPos, SCTAB nSh } else { - bModified |= adjustSingleRefOnDeletedTab(rRef2, nDelPos, nSheets, rOldPos, rNewPos); + bModified |= adjustSingleRefOnDeletedTab(rLimits, rRef2, nDelPos, nSheets, rOldPos, rNewPos); } return bModified; } @@ -4140,14 +4140,14 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnDeletedTab( const sc::RefUpda case svSingleRef: { ScSingleRefData& rRef = *p->GetSingleRef(); - if (adjustSingleRefOnDeletedTab(rRef, rCxt.mnDeletePos, rCxt.mnSheets, rOldPos, aNewPos)) + if (adjustSingleRefOnDeletedTab(*mxSheetLimits, rRef, rCxt.mnDeletePos, rCxt.mnSheets, rOldPos, aNewPos)) aRes.mbReferenceModified = true; } break; case svDoubleRef: { ScComplexRefData& rRef = *p->GetDoubleRef(); - aRes.mbReferenceModified |= adjustDoubleRefOnDeleteTab(rRef, rCxt.mnDeletePos, rCxt.mnSheets, rOldPos, aNewPos); + aRes.mbReferenceModified |= adjustDoubleRefOnDeleteTab(*mxSheetLimits, rRef, rCxt.mnDeletePos, rCxt.mnSheets, rOldPos, aNewPos); } break; default: @@ -4213,16 +4213,16 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnInsertedTab( const sc::RefUpd case svSingleRef: { ScSingleRefData& rRef = *p->GetSingleRef(); - if (adjustSingleRefOnInsertedTab(rRef, rCxt.mnInsertPos, rCxt.mnSheets, rOldPos, aNewPos)) + if (adjustSingleRefOnInsertedTab(*mxSheetLimits, rRef, rCxt.mnInsertPos, rCxt.mnSheets, rOldPos, aNewPos)) aRes.mbReferenceModified = true; } break; case svDoubleRef: { ScComplexRefData& rRef = *p->GetDoubleRef(); - if (adjustSingleRefOnInsertedTab(rRef.Ref1, rCxt.mnInsertPos, rCxt.mnSheets, rOldPos, aNewPos)) + if (adjustSingleRefOnInsertedTab(*mxSheetLimits, rRef.Ref1, rCxt.mnInsertPos, rCxt.mnSheets, rOldPos, aNewPos)) aRes.mbReferenceModified = true; - if (adjustSingleRefOnInsertedTab(rRef.Ref2, rCxt.mnInsertPos, rCxt.mnSheets, rOldPos, aNewPos)) + if (adjustSingleRefOnInsertedTab(*mxSheetLimits, rRef.Ref2, rCxt.mnInsertPos, rCxt.mnSheets, rOldPos, aNewPos)) aRes.mbReferenceModified = true; } break; @@ -4302,21 +4302,21 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnMovedTab( const sc::RefUpdate case svSingleRef: { ScSingleRefData& rRef = *p->GetSingleRef(); - ScAddress aAbs = rRef.toAbs(rOldPos); + ScAddress aAbs = rRef.toAbs(*mxSheetLimits, rOldPos); if (adjustTabOnMove(aAbs, rCxt)) aRes.mbReferenceModified = true; - rRef.SetAddress(aAbs, aNewPos); + rRef.SetAddress(*mxSheetLimits, aAbs, aNewPos); } break; case svDoubleRef: { ScComplexRefData& rRef = *p->GetDoubleRef(); - ScRange aAbs = rRef.toAbs(rOldPos); + ScRange aAbs = rRef.toAbs(*mxSheetLimits, rOldPos); if (adjustTabOnMove(aAbs.aStart, rCxt)) aRes.mbReferenceModified = true; if (adjustTabOnMove(aAbs.aEnd, rCxt)) aRes.mbReferenceModified = true; - rRef.SetRange(aAbs, aNewPos); + rRef.SetRange(*mxSheetLimits, aAbs, aNewPos); } break; default: @@ -4376,16 +4376,16 @@ void ScTokenArray::AdjustReferenceOnMovedOrigin( const ScAddress& rOldPos, const case svExternalSingleRef: { ScSingleRefData& rRef = *p->GetSingleRef(); - ScAddress aAbs = rRef.toAbs(rOldPos); - rRef.SetAddress(aAbs, rNewPos); + ScAddress aAbs = rRef.toAbs(*mxSheetLimits, rOldPos); + rRef.SetAddress(*mxSheetLimits, aAbs, rNewPos); } break; case svDoubleRef: case svExternalDoubleRef: { ScComplexRefData& rRef = *p->GetDoubleRef(); - ScRange aAbs = rRef.toAbs(rOldPos); - rRef.SetRange(aAbs, rNewPos); + ScRange aAbs = rRef.toAbs(*mxSheetLimits, rOldPos); + rRef.SetRange(*mxSheetLimits, aAbs, rNewPos); } break; default: @@ -4417,11 +4417,11 @@ void ScTokenArray::AdjustReferenceOnMovedOriginIfOtherSheet( const ScAddress& rO case svSingleRef: { ScSingleRefData& rRef = *p->GetSingleRef(); - ScAddress aAbs = rRef.toAbs(rOldPos); + ScAddress aAbs = rRef.toAbs(*mxSheetLimits, rOldPos); if (!bAdjust) bAdjust = (aAbs.Tab() != rOldPos.Tab()); if (bAdjust) - rRef.SetAddress(aAbs, rNewPos); + rRef.SetAddress(*mxSheetLimits, aAbs, rNewPos); } break; case svExternalDoubleRef: @@ -4430,11 +4430,11 @@ void ScTokenArray::AdjustReferenceOnMovedOriginIfOtherSheet( const ScAddress& rO case svDoubleRef: { ScComplexRefData& rRef = *p->GetDoubleRef(); - ScRange aAbs = rRef.toAbs(rOldPos); + ScRange aAbs = rRef.toAbs(*mxSheetLimits, rOldPos); if (!bAdjust) bAdjust = (rOldPos.Tab() < aAbs.aStart.Tab() || aAbs.aEnd.Tab() < rOldPos.Tab()); if (bAdjust) - rRef.SetRange(aAbs, rNewPos); + rRef.SetRange(*mxSheetLimits, aAbs, rNewPos); } break; default: @@ -4474,12 +4474,12 @@ void ScTokenArray::AdjustReferenceOnCopy( const ScAddress& rNewPos ) namespace { -void clearTabDeletedFlag( ScSingleRefData& rRef, const ScAddress& rPos, SCTAB nStartTab, SCTAB nEndTab ) +void clearTabDeletedFlag( ScSheetLimits& rLimits, ScSingleRefData& rRef, const ScAddress& rPos, SCTAB nStartTab, SCTAB nEndTab ) { if (!rRef.IsTabDeleted()) return; - ScAddress aAbs = rRef.toAbs(rPos); + ScAddress aAbs = rRef.toAbs(rLimits, rPos); if (nStartTab <= aAbs.Tab() && aAbs.Tab() <= nEndTab) rRef.SetTabDeleted(false); } @@ -4501,15 +4501,15 @@ void ScTokenArray::ClearTabDeleted( const ScAddress& rPos, SCTAB nStartTab, SCTA { formula::FormulaToken* pToken = *p; ScSingleRefData& rRef = *pToken->GetSingleRef(); - clearTabDeletedFlag(rRef, rPos, nStartTab, nEndTab); + clearTabDeletedFlag(*mxSheetLimits, rRef, rPos, nStartTab, nEndTab); } break; case svDoubleRef: { formula::FormulaToken* pToken = *p; ScComplexRefData& rRef = *pToken->GetDoubleRef(); - clearTabDeletedFlag(rRef.Ref1, rPos, nStartTab, nEndTab); - clearTabDeletedFlag(rRef.Ref2, rPos, nStartTab, nEndTab); + clearTabDeletedFlag(*mxSheetLimits, rRef.Ref1, rPos, nStartTab, nEndTab); + clearTabDeletedFlag(*mxSheetLimits, rRef.Ref2, rPos, nStartTab, nEndTab); } break; default: @@ -4528,7 +4528,7 @@ void checkBounds( if (!rRef.IsRowRel()) return; - ScRange aAbs(rRef.toAbs(rPos)); + ScRange aAbs(rRef.toAbs(rLimits, rPos)); aAbs.aEnd.IncRow(nGroupLen-1); if (!rCheckRange.Intersects(aAbs) && (!pDeletedRange || !pDeletedRange->Intersects(aAbs))) return; @@ -4725,10 +4725,10 @@ void ScTokenArray::CheckExpandReferenceBounds( if (!bStartRowRelative && !bEndRowRelative) break; // switch - ScRange aAbsStart(rRef.toAbs(rPos)); + ScRange aAbsStart(rRef.toAbs(*mxSheetLimits, rPos)); ScAddress aPos(rPos); aPos.IncRow(nGroupLen); - ScRange aAbsEnd(rRef.toAbs(aPos)); + ScRange aAbsEnd(rRef.toAbs(*mxSheetLimits, aPos)); // References must be at least two rows to be expandable. if ((aAbsStart.aEnd.Row() - aAbsStart.aStart.Row() < 1) && (aAbsEnd.aEnd.Row() - aAbsEnd.aStart.Row() < 1)) @@ -4842,7 +4842,7 @@ void appendTokenByType( ScSheetLimits& rLimits, sc::TokenStringContext& rCxt, OU break; case svExternalSingleRef: rCxt.mpRefConv->makeExternalRefStr( - rBuf, rPos, nFileId, aFileName, aTabName, *rToken.GetSingleRef()); + rLimits, rBuf, rPos, nFileId, aFileName, aTabName, *rToken.GetSingleRef()); break; case svExternalDoubleRef: { @@ -5184,16 +5184,16 @@ void ScTokenArray::WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nM { formula::FormulaToken* pToken = *p; ScSingleRefData& rRef = *pToken->GetSingleRef(); - ScAddress aAbs = rRef.toAbs(rPos); + ScAddress aAbs = rRef.toAbs(*mxSheetLimits, rPos); wrapAddress(aAbs, nMaxCol, nMaxRow); - rRef.SetAddress(aAbs, rPos); + rRef.SetAddress(*mxSheetLimits, aAbs, rPos); } break; case svDoubleRef: { formula::FormulaToken* pToken = *p; ScComplexRefData& rRef = *pToken->GetDoubleRef(); - ScRange aAbs = rRef.toAbs(rPos); + ScRange aAbs = rRef.toAbs(*mxSheetLimits, rPos); // Entire columns/rows are sticky. if (!rRef.IsEntireCol() && !rRef.IsEntireRow()) { @@ -5206,7 +5206,7 @@ void ScTokenArray::WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nM wrapRowRange( aAbs, nMaxRow); // else nothing if both, column and row, are entire. aAbs.PutInOrder(); - rRef.SetRange(aAbs, rPos); + rRef.SetRange(*mxSheetLimits, aAbs, rPos); } break; default: @@ -5227,7 +5227,7 @@ bool ScTokenArray::NeedsWrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCR { formula::FormulaToken* pToken = *p; ScSingleRefData& rRef = *pToken->GetSingleRef(); - ScAddress aAbs = rRef.toAbs(rPos); + ScAddress aAbs = rRef.toAbs(*mxSheetLimits, rPos); if (aAbs.Col() > nMaxCol || aAbs.Row() > nMaxRow) return true; } @@ -5236,7 +5236,7 @@ bool ScTokenArray::NeedsWrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCR { formula::FormulaToken* pToken = *p; ScComplexRefData& rRef = *pToken->GetDoubleRef(); - ScRange aAbs = rRef.toAbs(rPos); + ScRange aAbs = rRef.toAbs(*mxSheetLimits, rPos); // Entire columns/rows are sticky. if ( (!rRef.IsEntireCol() && (aAbs.aStart.Row() > nMaxRow || aAbs.aEnd.Row() > nMaxRow)) || (!rRef.IsEntireRow() && (aAbs.aStart.Col() > nMaxCol || aAbs.aEnd.Col() > nMaxCol))) diff --git a/sc/source/filter/excel/excform8.cxx b/sc/source/filter/excel/excform8.cxx index fbe1151e595f..4d53dbce4f29 100644 --- a/sc/source/filter/excel/excform8.cxx +++ b/sc/source/filter/excel/excform8.cxx @@ -318,7 +318,7 @@ ConvErr ExcelToSc8::Convert( std::unique_ptr<ScTokenArray>& rpTokArray, XclImpSt else aSRD.SetColRel(true); - aSRD.SetAddress(&GetDocImport().getDoc(), aAddr, aEingPos); + aSRD.SetAddress(GetDocImport().getDoc().GetSheetLimits(), aAddr, aEingPos); aStack << aPool.StoreNlf( aSRD ); @@ -332,7 +332,7 @@ ConvErr ExcelToSc8::Convert( std::unique_ptr<ScTokenArray>& rpTokArray, XclImpSt ScAddress aAddr(static_cast<SCCOL>(nCol & 0xFF), static_cast<SCROW>(nRow), aEingPos.Tab()); aSRD.InitAddress(aAddr); aSRD.SetColRel(true); - aSRD.SetAddress(&GetDocImport().getDoc(), aAddr, aEingPos); + aSRD.SetAddress(GetDocImport().getDoc().GetSheetLimits(), aAddr, aEingPos); aStack << aPool.StoreNlf( aSRD ); diff --git a/sc/source/filter/excel/xeformula.cxx b/sc/source/filter/excel/xeformula.cxx index 11ed534a387e..a0e82fd160d6 100644 --- a/sc/source/filter/excel/xeformula.cxx +++ b/sc/source/filter/excel/xeformula.cxx @@ -1864,7 +1864,7 @@ void XclExpFmlaCompImpl::ConvertRefData( rXclPos.mnRow = static_cast<sal_uInt32>(aAbs.Row()) & mnMaxRowMask; // Update the reference. - rRefData.SetAddress(&GetRoot().GetDoc(), aAbs, *mxData->mpScBasePos); + rRefData.SetAddress(GetRoot().GetDoc().GetSheetLimits(), aAbs, *mxData->mpScBasePos); } else { diff --git a/sc/source/filter/lotus/lotform.cxx b/sc/source/filter/lotus/lotform.cxx index d92a34151242..6736732bfef3 100644 --- a/sc/source/filter/lotus/lotform.cxx +++ b/sc/source/filter/lotus/lotform.cxx @@ -25,6 +25,7 @@ #include <root.hxx> #include <ftools.hxx> #include <tool.h> +#include <document.hxx> #include <comphelper/string.hxx> #include <sal/log.hxx> @@ -332,7 +333,7 @@ void LotusToSc::ReadSRD( const ScDocument* pDoc, ScSingleRefData& rSRD, sal_uInt rSRD.SetTabRel( ( ( nRelBit & 0x04) != 0 ) || !b3D ); rSRD.SetFlag3D( b3D ); - rSRD.SetAddress(pDoc, ScAddress(nCol, nRow, nTab), aEingPos); + rSRD.SetAddress(pDoc->GetSheetLimits(), ScAddress(nCol, nRow, nTab), aEingPos); } void LotusToSc::IncToken( TokenId &rParam ) diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx index 4c8f4fa9153d..52e2ee5bb546 100644 --- a/sc/source/ui/app/inputhdl.cxx +++ b/sc/source/ui/app/inputhdl.cxx @@ -2203,16 +2203,20 @@ bool ScInputHandler::StartTable( sal_Unicode cTyped, bool bFromCommand, bool bIn { bool bNewTable = false; - if (bModified || !ValidCol(aCursorPos.Col())) + if (bModified) return false; if (pActiveViewSh) { + ScDocument& rDoc = pActiveViewSh->GetViewData().GetDocShell()->GetDocument(); + + if (!rDoc.ValidCol(aCursorPos.Col())) + return false; + ImplCreateEditEngine(); UpdateActiveView(); SyncViews(); - ScDocument& rDoc = pActiveViewSh->GetViewData().GetDocShell()->GetDocument(); const ScMarkData& rMark = pActiveViewSh->GetViewData().GetMarkData(); ScEditableTester aTester; diff --git a/sc/source/ui/docshell/arealink.cxx b/sc/source/ui/docshell/arealink.cxx index 366f17198650..0863c75f4be5 100644 --- a/sc/source/ui/docshell/arealink.cxx +++ b/sc/source/ui/docshell/arealink.cxx @@ -318,7 +318,7 @@ bool ScAreaLink::Refresh( const OUString& rNewFile, const OUString& rNewFilter, } //! check CanFitBlock only if bDoInsert is set? - bool bCanDo = ValidColRow( aNewRange.aEnd.Col(), aNewRange.aEnd.Row() ) && + bool bCanDo = rDoc.ValidColRow( aNewRange.aEnd.Col(), aNewRange.aEnd.Row() ) && rDoc.CanFitBlock( aOldRange, aNewRange ); if (bCanDo) { diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx index 6ae0cb176dfd..59446bcec528 100644 --- a/sc/source/ui/docshell/dbdocfun.cxx +++ b/sc/source/ui/docshell/dbdocfun.cxx @@ -678,7 +678,7 @@ bool ScDBDocFunc::Query( SCTAB nTab, const ScQueryParam& rQueryParam, { aLocalParam.MoveToDest(); nDestTab = rQueryParam.nDestTab; - if ( !ValidColRow( aLocalParam.nCol2, aLocalParam.nRow2 ) ) + if ( !rDoc.ValidColRow( aLocalParam.nCol2, aLocalParam.nRow2 ) ) { if (!bApi) rDocShell.ErrorMessage(STR_PASTE_FULL); @@ -1209,7 +1209,7 @@ bool checkNewOutputRange(ScDPObject& rDPObj, ScDocShell& rDocShell, ScRange& rNe SCROW nDiff = aOldRange.aStart.Row() - rNewOut.aStart.Row(); rNewOut.aStart.SetRow(aOldRange.aStart.Row()); rNewOut.aEnd.IncRow(nDiff); - if (!ValidRow(rNewOut.aStart.Row()) || !ValidRow(rNewOut.aEnd.Row())) + if (!rDoc.ValidRow(rNewOut.aStart.Row()) || !rDoc.ValidRow(rNewOut.aEnd.Row())) bOverflow = true; } diff --git a/sc/source/ui/docshell/dbdocimp.cxx b/sc/source/ui/docshell/dbdocimp.cxx index 4e95f43169c2..76d8333cdc78 100644 --- a/sc/source/ui/docshell/dbdocimp.cxx +++ b/sc/source/ui/docshell/dbdocimp.cxx @@ -325,7 +325,7 @@ bool ScDBDocFunc::DoImport( SCTAB nTab, const ScImportParam& rParam, if ( !bEnd ) { - if ( ValidRow(nRow) ) + if ( rDoc.ValidRow(nRow) ) { nCol = rParam.nCol1; for (long i=0; i<nColCount; i++) diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 880d33472e95..b9598ed24c55 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -1717,7 +1717,7 @@ bool ScDocFunc::InsertCells( const ScRange& rRange, const ScMarkData* pTabMark, SCROW nEndRow = aTargetRange.aEnd.Row(); SCTAB nEndTab = aTargetRange.aEnd.Tab(); - if ( !ValidRow(nStartRow) || !ValidRow(nEndRow) ) + if ( !rDoc.ValidRow(nStartRow) || !rDoc.ValidRow(nEndRow) ) { OSL_FAIL("invalid row in InsertCells"); return false; @@ -2231,7 +2231,7 @@ bool ScDocFunc::DeleteCells( const ScRange& rRange, const ScMarkData* pTabMark, SCROW nEndRow = rRange.aEnd.Row(); SCTAB nEndTab = rRange.aEnd.Tab(); - if ( !ValidRow(nStartRow) || !ValidRow(nEndRow) ) + if ( !rDoc.ValidRow(nStartRow) || !rDoc.ValidRow(nEndRow) ) { OSL_FAIL("invalid row in DeleteCells"); return false; @@ -2804,7 +2804,8 @@ bool ScDocFunc::MoveBlock( const ScRange& rSource, const ScAddress& rDestPos, SCROW nDestRow = rDestPos.Row(); SCTAB nDestTab = rDestPos.Tab(); - if ( !ValidRow(nStartRow) || !ValidRow(nEndRow) || !ValidRow(nDestRow) ) + ScDocument& rDoc = rDocShell.GetDocument(); + if ( !rDoc.ValidRow(nStartRow) || !rDoc.ValidRow(nEndRow) || !rDoc.ValidRow(nDestRow) ) { OSL_FAIL("invalid row in MoveBlock"); return false; @@ -2812,7 +2813,6 @@ bool ScDocFunc::MoveBlock( const ScRange& rSource, const ScAddress& rDestPos, // adjust related scenarios too - but only when moved within one sheet bool bScenariosAdded = false; - ScDocument& rDoc = rDocShell.GetDocument(); if (bRecord && !rDoc.IsUndoEnabled()) bRecord = false; @@ -2880,7 +2880,7 @@ bool ScDocFunc::MoveBlock( const ScRange& rSource, const ScAddress& rDestPos, nUndoEndRow = nDestEndRow + nUndoAdd; } - if (!ValidCol(nUndoEndCol) || !ValidRow(nUndoEndRow)) + if (!rDoc.ValidCol(nUndoEndCol) || !rDoc.ValidRow(nUndoEndRow)) { if (!bApi) rDocShell.ErrorMessage(STR_PASTE_FULL); diff --git a/sc/source/ui/docshell/docsh3.cxx b/sc/source/ui/docshell/docsh3.cxx index 33133e33a9e4..6806ef37d962 100644 --- a/sc/source/ui/docshell/docsh3.cxx +++ b/sc/source/ui/docshell/docsh3.cxx @@ -113,10 +113,10 @@ void ScDocShell::PostPaint( const ScRangeList& rRanges, PaintPartFlags nPart, sa SCROW nRow1 = rRange.aStart.Row(), nRow2 = rRange.aEnd.Row(); SCTAB nTab1 = rRange.aStart.Tab(), nTab2 = rRange.aEnd.Tab(); - if (!ValidCol(nCol1)) nCol1 = m_aDocument.MaxCol(); - if (!ValidRow(nRow1)) nRow1 = m_aDocument.MaxRow(); - if (!ValidCol(nCol2)) nCol2 = m_aDocument.MaxCol(); - if (!ValidRow(nRow2)) nRow2 = m_aDocument.MaxRow(); + if (!m_aDocument.ValidCol(nCol1)) nCol1 = m_aDocument.MaxCol(); + if (!m_aDocument.ValidRow(nRow1)) nRow1 = m_aDocument.MaxRow(); + if (!m_aDocument.ValidCol(nCol2)) nCol2 = m_aDocument.MaxCol(); + if (!m_aDocument.ValidRow(nRow2)) nRow2 = m_aDocument.MaxRow(); if ( m_pPaintLockData ) { diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx index bbe2bff7c845..9ccbf096fc10 100644 --- a/sc/source/ui/docshell/docsh4.cxx +++ b/sc/source/ui/docshell/docsh4.cxx @@ -204,7 +204,7 @@ void ScDocShell::Execute( SfxRequest& rReq ) SCTAB nTab = static_cast<const SfxInt16Item*>(pTabItem)->GetValue() - 1; SCTAB nTabCount = m_aDocument.GetTableCount(); - if ( ValidCol(nCol) && ValidRow(nRow) && ValidTab(nTab,nTabCount) ) + if ( m_aDocument.ValidCol(nCol) && m_aDocument.ValidRow(nRow) && ValidTab(nTab,nTabCount) ) { if ( m_aDocument.IsBlockEditable( nTab, nCol,nRow, nCol, nRow ) ) { diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index bfa4447b3d73..204cfafe86da 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -911,7 +911,7 @@ bool ScImportExport::Text2Doc( SvStream& rStrm ) } if (*p) ++p; - if (ValidCol(nCol) && ValidRow(nRow) ) + if (pDoc->ValidCol(nCol) && pDoc->ValidRow(nRow) ) { if( bSingle ) { @@ -923,9 +923,9 @@ bool ScImportExport::Text2Doc( SvStream& rStrm ) } else // too many columns/rows { - if (!ValidRow(nRow)) + if (!pDoc->ValidRow(nRow)) bOverflowRow = true; // display warning on import - if (!ValidCol(nCol)) + if (!pDoc->ValidCol(nCol)) bOverflowCol = true; // display warning on import } ++nCol; @@ -965,7 +965,7 @@ static bool lcl_PutString( { ScDocument* pDoc = &rDocImport.getDoc(); bool bMultiLine = false; - if ( nColFormat == SC_COL_SKIP || !ValidCol(nCol) || !ValidRow(nRow) ) + if ( nColFormat == SC_COL_SKIP || !pDoc->ValidCol(nCol) || !pDoc->ValidRow(nRow) ) return bMultiLine; if ( rStr.isEmpty() ) { diff --git a/sc/source/ui/formdlg/formula.cxx b/sc/source/ui/formdlg/formula.cxx index dd9ef3559496..f59a5b9cd9f5 100644 --- a/sc/source/ui/formdlg/formula.cxx +++ b/sc/source/ui/formdlg/formula.cxx @@ -431,7 +431,7 @@ void ScFormulaDlg::SetReference( const ScRange& rRef, ScDocument& rRefDoc ) // position. ScTokenArray aArray(&rRefDoc); ScComplexRefData aRefData; - aRefData.InitRangeRel(rRef, m_CursorPos); + aRefData.InitRangeRel(&rRefDoc, rRef, m_CursorPos); bool bSingle = aRefData.Ref1 == aRefData.Ref2; if (m_CursorPos.Tab() != rRef.aStart.Tab()) { diff --git a/sc/source/ui/miscdlgs/anyrefdg.cxx b/sc/source/ui/miscdlgs/anyrefdg.cxx index ed81d8980ef6..0fa7bff3634d 100644 --- a/sc/source/ui/miscdlgs/anyrefdg.cxx +++ b/sc/source/ui/miscdlgs/anyrefdg.cxx @@ -189,6 +189,8 @@ void ScFormulaReferenceHelper::ShowFormulaReference(const OUString& rStr) if (pTabViewShell && pScTokA) { + const ScViewData& rViewData = pTabViewShell->GetViewData(); + ScDocument* pDoc = rViewData.GetDocument(); pTabViewShell->DoneRefMode(); pTabViewShell->ClearHighlightRanges(); @@ -207,12 +209,12 @@ void ScFormulaReferenceHelper::ShowFormulaReference(const OUString& rStr) if(bDoubleRef) { ScComplexRefData aRef( *pToken->GetDoubleRef() ); - aRange = aRef.toAbs(aPos); + aRange = aRef.toAbs(pDoc, aPos); } else { ScSingleRefData aRef( *pToken->GetSingleRef() ); - aRange.aStart = aRef.toAbs(aPos); + aRange.aStart = aRef.toAbs(pDoc, aPos); aRange.aEnd = aRange.aStart; } Color aColName=ScRangeFindList::GetColorName(nIndex++); diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx index b7c11adfedba..9be81221a7b2 100644 --- a/sc/source/ui/unoobj/chart2uno.cxx +++ b/sc/source/ui/unoobj/chart2uno.cxx @@ -316,7 +316,7 @@ Chart2PositionMap::Chart2PositionMap(SCCOL nAllColCount, SCROW nAllRowCount, if( eType==svExternal || eType==svExternalSingleRef || eType==svExternalDoubleRef || eType==svExternalName ) bExternal = true;//lllll todo correct? ScTokenRef pSharedToken(rCell.second->Clone()); - ScRefTokenHelper::getRangeFromToken(aRange, pSharedToken, ScAddress(), bExternal); + ScRefTokenHelper::getRangeFromToken(pDoc, aRange, pSharedToken, ScAddress(), bExternal); SCCOL nCol1=0, nCol2=0; SCROW nRow1=0, nRow2=0; SCTAB nTab1=0, nTab2=0; @@ -2414,7 +2414,7 @@ void ScChart2DataSequence::RefChanged() for (const auto& rxToken : m_aTokens) { ScRange aRange; - if (!ScRefTokenHelper::getRangeFromToken(aRange, rxToken, ScAddress())) + if (!ScRefTokenHelper::getRangeFromToken(m_pDocument, aRange, rxToken, ScAddress())) continue; m_pDocument->StartListeningArea(aRange, false, m_pValueListener.get()); @@ -2446,7 +2446,7 @@ void ScChart2DataSequence::BuildDataCache() else { ScRange aRange; - if (!ScRefTokenHelper::getRangeFromToken(aRange, rxToken, ScAddress())) + if (!ScRefTokenHelper::getRangeFromToken(m_pDocument, aRange, rxToken, ScAddress())) continue; SCCOL nLastCol = -1; @@ -2536,7 +2536,7 @@ sal_Int32 ScChart2DataSequence::FillCacheFromExternalRef(const ScTokenRef& pToke { ScExternalRefManager* pRefMgr = m_pDocument->GetExternalRefManager(); ScRange aRange; - if (!ScRefTokenHelper::getRangeFromToken(aRange, pToken, ScAddress(), true)) + if (!ScRefTokenHelper::getRangeFromToken(m_pDocument, aRange, pToken, ScAddress(), true)) return 0; sal_uInt16 nFileId = pToken->GetIndex(); @@ -2707,7 +2707,7 @@ void ScChart2DataSequence::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint if (!ScRefTokenHelper::isExternalRef(*itr)) { ScRange aRange; - ScRefTokenHelper::getRangeFromToken(aRange, *itr, ScAddress()); + ScRefTokenHelper::getRangeFromToken(m_pDocument, aRange, *itr, ScAddress()); aRanges.push_back(aRange); sal_uInt32 nPos = distance(itrBeg, itr); m_pRangeIndices->push_back(nPos); @@ -2976,14 +2976,14 @@ namespace { class AccumulateRangeSize { public: - AccumulateRangeSize() : - mnCols(0), mnRows(0) {} + AccumulateRangeSize(const ScDocument* pDoc) : + mpDoc(pDoc), mnCols(0), mnRows(0) {} void operator() (const ScTokenRef& pToken) { ScRange r; bool bExternal = ScRefTokenHelper::isExternalRef(pToken); - ScRefTokenHelper::getRangeFromToken(r, pToken, ScAddress(), bExternal); + ScRefTokenHelper::getRangeFromToken(mpDoc, r, pToken, ScAddress(), bExternal); r.PutInOrder(); mnCols += r.aEnd.Col() - r.aStart.Col() + 1; mnRows += r.aEnd.Row() - r.aStart.Row() + 1; @@ -2992,6 +2992,7 @@ public: SCCOL getCols() const { return mnCols; } SCROW getRows() const { return mnRows; } private: + const ScDocument* mpDoc; SCCOL mnCols; SCROW mnRows; }; @@ -3003,7 +3004,8 @@ private: class GenerateLabelStrings { public: - GenerateLabelStrings(sal_Int32 nSize, chart2::data::LabelOrigin eOrigin, bool bColumn) : + GenerateLabelStrings(const ScDocument* pDoc, sal_Int32 nSize, chart2::data::LabelOrigin eOrigin, bool bColumn) : + mpDoc(pDoc), mpLabels(new Sequence<OUString>(nSize)), meOrigin(eOrigin), mnCount(0), @@ -3013,7 +3015,7 @@ public: { bool bExternal = ScRefTokenHelper::isExternalRef(pToken); ScRange aRange; - ScRefTokenHelper::getRangeFromToken(aRange, pToken, ScAddress(), bExternal); + ScRefTokenHelper::getRangeFromToken(mpDoc, aRange, pToken, ScAddress(), bExternal); OUString* pArr = mpLabels->getArray(); if (mbColumn) { @@ -3052,6 +3054,7 @@ public: const Sequence<OUString>& getLabels() const { return *mpLabels; } private: + const ScDocument* mpDoc; shared_ptr< Sequence<OUString> > mpLabels; chart2::data::LabelOrigin meOrigin; sal_Int32 mnCount; @@ -3067,7 +3070,7 @@ uno::Sequence< OUString > SAL_CALL ScChart2DataSequence::generateLabel(chart2::d throw uno::RuntimeException(); // Determine the total size of all ranges. - AccumulateRangeSize func; + AccumulateRangeSize func(m_pDocument); func = ::std::for_each(m_aTokens.begin(), m_aTokens.end(), func); SCCOL nCols = func.getCols(); SCROW nRows = func.getRows(); @@ -3091,7 +3094,7 @@ uno::Sequence< OUString > SAL_CALL ScChart2DataSequence::generateLabel(chart2::d // Generate label strings based on the info so far. sal_Int32 nCount = bColumn ? nCols : nRows; - GenerateLabelStrings genLabels(nCount, eOrigin, bColumn); + GenerateLabelStrings genLabels(m_pDocument, nCount, eOrigin, bColumn); genLabels = ::std::for_each(m_aTokens.begin(), m_aTokens.end(), genLabels); Sequence<OUString> aSeq = genLabels.getLabels(); @@ -3171,7 +3174,7 @@ void SAL_CALL ScChart2DataSequence::addModifyListener( const uno::Reference< uti return; ScRangeList aRanges; - ScRefTokenHelper::getRangeListFromTokens(aRanges, m_aTokens, ScAddress()); + ScRefTokenHelper::getRangeListFromTokens(m_pDocument, aRanges, m_aTokens, ScAddress()); m_aValueListeners.emplace_back( aListener ); if ( m_aValueListeners.size() == 1 ) @@ -3188,7 +3191,7 @@ void SAL_CALL ScChart2DataSequence::addModifyListener( const uno::Reference< uti for (const auto& rxToken : m_aTokens) { ScRange aRange; - if (!ScRefTokenHelper::getRangeFromToken(aRange, rxToken, ScAddress())) + if (!ScRefTokenHelper::getRangeFromToken(m_pDocument, aRange, rxToken, ScAddress())) continue; m_pDocument->StartListeningArea( aRange, false, m_pValueListener.get() ); diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index e3a7a8f69de0..1d0a86481f3b 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -4870,7 +4870,7 @@ static void lcl_PaintOneRange( ScDocShell* pDocSh, const ScRange& rRange, sal_uI bHiddenEdge = true; } nTmp = rDoc.FirstVisibleRow(0, nRow1, nTab1); - if (!ValidRow(nTmp)) + if (!rDoc.ValidRow(nTmp)) nTmp = 0; if (nTmp < nRow1) { @@ -4878,7 +4878,7 @@ static void lcl_PaintOneRange( ScDocShell* pDocSh, const ScRange& rRange, sal_uI bHiddenEdge = true; } nTmp = rDoc.FirstVisibleRow(nRow2, rDoc.MaxRow(), nTab1); - if (!ValidRow(nTmp)) + if (!rDoc.ValidRow(nTmp)) nTmp = rDoc.MaxRow(); if (nTmp > nRow2) { @@ -6326,7 +6326,7 @@ void ScGridWindow::UpdateDragRectOverlay() bool bLayoutRTL = pDoc->IsLayoutRTL( nTab ); long nLayoutSign = bLayoutRTL ? -1 : 1; - if (ValidCol(nX2) && nX2>=nX1) + if (pDoc->ValidCol(nX2) && nX2>=nX1) for (i=nX1; i<=nX2; i++) nSizeXPix += ScViewData::ToPixel( pDoc->GetColWidth( static_cast<SCCOL>(i), nTab ), nPPTX ); else @@ -6335,7 +6335,7 @@ void ScGridWindow::UpdateDragRectOverlay() nSizeXPix += 2; } - if (ValidRow(nY2) && nY2>=nY1) + if (pDoc->ValidRow(nY2) && nY2>=nY1) for (i=nY1; i<=nY2; i++) nSizeYPix += ScViewData::ToPixel( pDoc->GetRowHeight( i, nTab ), nPPTY ); else diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx index b60977f95025..7ed91bdac886 100644 --- a/sc/source/ui/view/gridwin4.cxx +++ b/sc/source/ui/view/gridwin4.cxx @@ -398,7 +398,7 @@ void ScGridWindow::Draw( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2, ScUpdateMod PutInOrder( nX1, nX2 ); PutInOrder( nY1, nY2 ); - OSL_ENSURE( ValidCol(nX2) && ValidRow(nY2), "GridWin Draw area too big" ); + OSL_ENSURE( rDoc.ValidCol(nX2) && rDoc.ValidRow(nY2), "GridWin Draw area too big" ); UpdateVisibleRange(); diff --git a/sc/source/ui/view/select.cxx b/sc/source/ui/view/select.cxx index 489ea67cfeda..e532e07bd518 100644 --- a/sc/source/ui/view/select.cxx +++ b/sc/source/ui/view/select.cxx @@ -351,7 +351,7 @@ void ScViewFunctionSet::SetCursorAtPoint( const Point& rPointPixel, bool /* bDon if (--nPosY >= 0) { nPosY = pDoc->LastVisibleRow(0, nPosY, nTab); - if (!ValidRow(nPosY)) + if (!pDoc->ValidRow(nPosY)) nPosY = -1; } } @@ -571,7 +571,7 @@ bool ScViewFunctionSet::SetCursorAtCell( SCCOL nPosX, SCROW nPosY, bool bScroll if (++nPosY < nStartY) { nPosY = pDoc->FirstVisibleRow(nPosY, nStartY-1, nTab); - if (!ValidRow(nPosY)) + if (!pDoc->ValidRow(nPosY)) nPosY = nStartY; } nSizeY += pDoc->GetRowHeight( nPosY, nStartY-1, nTab ); diff --git a/sc/source/ui/view/tabview2.cxx b/sc/source/ui/view/tabview2.cxx index 6983f2fee4b7..72d0a9faa77f 100644 --- a/sc/source/ui/view/tabview2.cxx +++ b/sc/source/ui/view/tabview2.cxx @@ -302,10 +302,10 @@ void moveCursorByMergedCell( void ScTabView::PaintMarks(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ) { auto pDoc = aViewData.GetDocument(); - if (!ValidCol(nStartCol)) nStartCol = pDoc->MaxCol(); - if (!ValidRow(nStartRow)) nStartRow = pDoc->MaxRow(); - if (!ValidCol(nEndCol)) nEndCol = pDoc->MaxCol(); - if (!ValidRow(nEndRow)) nEndRow = pDoc->MaxRow(); + if (!pDoc->ValidCol(nStartCol)) nStartCol = pDoc->MaxCol(); + if (!pDoc->ValidRow(nStartRow)) nStartRow = pDoc->MaxRow(); + if (!pDoc->ValidCol(nEndCol)) nEndCol = pDoc->MaxCol(); + if (!pDoc->ValidRow(nEndRow)) nEndRow = pDoc->MaxRow(); bool bLeft = (nStartCol==0 && nEndCol==pDoc->MaxCol()); bool bTop = (nStartRow==0 && nEndRow==pDoc->MaxRow()); @@ -355,8 +355,8 @@ void ScTabView::InitBlockMode( SCCOL nCurX, SCROW nCurY, SCTAB nCurZ, if (!IsBlockMode()) { auto pDoc = aViewData.GetDocument(); - if (!ValidCol(nCurX)) nCurX = pDoc->MaxCol(); - if (!ValidRow(nCurY)) nCurY = pDoc->MaxRow(); + if (!pDoc->ValidCol(nCurX)) nCurX = pDoc->MaxCol(); + if (!pDoc->ValidRow(nCurY)) nCurY = pDoc->MaxRow(); ScMarkData& rMark = aViewData.GetMarkData(); SCTAB nTab = aViewData.GetTabNo(); @@ -449,8 +449,8 @@ void ScTabView::MarkCursor( SCCOL nCurX, SCROW nCurY, SCTAB nCurZ, bool bCols, bool bRows, bool bCellSelection ) { ScDocument* pDocument = aViewData.GetDocument(); - if (!ValidCol(nCurX)) nCurX = pDocument->MaxCol(); - if (!ValidRow(nCurY)) nCurY = pDocument->MaxRow(); + if (!pDocument->ValidCol(nCurX)) nCurX = pDocument->MaxCol(); + if (!pDocument->ValidRow(nCurY)) nCurY = pDocument->MaxRow(); if (!IsBlockMode()) { diff --git a/sc/source/ui/view/tabview3.cxx b/sc/source/ui/view/tabview3.cxx index f512e8dd9127..a14fb12b3fc1 100644 --- a/sc/source/ui/view/tabview3.cxx +++ b/sc/source/ui/view/tabview3.cxx @@ -1170,11 +1170,11 @@ void ScTabView::MoveCursorAbs( SCCOL nCurX, SCROW nCurY, ScFollowMode eMode, if (!bKeepOld) aViewData.ResetOldCursor(); + ScDocument* pDoc = aViewData.GetDocument(); // #i123629# if( aViewData.GetViewShell()->GetForceFocusOnCurCell() ) - aViewData.GetViewShell()->SetForceFocusOnCurCell( !ValidColRow(nCurX, nCurY) ); + aViewData.GetViewShell()->SetForceFocusOnCurCell( !pDoc->ValidColRow(nCurX, nCurY) ); - ScDocument* pDoc = aViewData.GetDocument(); if (nCurX < 0) nCurX = 0; if (nCurY < 0) nCurY = 0; if (nCurX > pDoc->MaxCol()) nCurX = pDoc->MaxCol(); @@ -1288,10 +1288,10 @@ void ScTabView::MoveCursorRel( SCCOL nMovX, SCROW nMovY, ScFollowMode eMode, aViewData.ResetOldCursor(); - if (nMovX != 0 && ValidColRow(nCurX,nCurY)) + if (nMovX != 0 && pDoc->ValidColRow(nCurX,nCurY)) SkipCursorHorizontal(nCurX, nCurY, nOldX, nMovX); - if (nMovY != 0 && ValidColRow(nCurX,nCurY)) + if (nMovY != 0 && pDoc->ValidColRow(nCurX,nCurY)) SkipCursorVertical(nCurX, nCurY, nOldY, nMovY); MoveCursorAbs( nCurX, nCurY, eMode, bShift, false, true, bKeepSel ); @@ -2438,7 +2438,7 @@ void ScTabView::PaintRangeFinderEntry (const ScRangeFindData* pData, const SCTAB bHiddenEdge = true; } nTmp = pDoc->LastVisibleRow(0, nRow1, nTab); - if (!ValidRow(nTmp)) + if (!pDoc->ValidRow(nTmp)) nTmp = 0; if (nTmp < nRow1) { @@ -2446,7 +2446,7 @@ void ScTabView::PaintRangeFinderEntry (const ScRangeFindData* pData, const SCTAB bHiddenEdge = true; } nTmp = pDoc->FirstVisibleRow(nRow2, pDoc->MaxRow(), nTab); - if (!ValidRow(nTmp)) + if (!pDoc->ValidRow(nTmp)) nTmp = pDoc->MaxRow(); if (nTmp > nRow2) { diff --git a/sc/source/ui/view/tabview4.cxx b/sc/source/ui/view/tabview4.cxx index f584dfdc8482..45c7f3492a86 100644 --- a/sc/source/ui/view/tabview4.cxx +++ b/sc/source/ui/view/tabview4.cxx @@ -518,10 +518,10 @@ void ScTabView::InterpretVisible() ScHSplitPos eHWhich = WhichH( ScSplitPos(i) ); ScVSplitPos eVWhich = WhichV( ScSplitPos(i) ); - SCCOL nX1 = SanitizeCol( aViewData.GetPosX( eHWhich )); - SCROW nY1 = SanitizeRow( aViewData.GetPosY( eVWhich )); - SCCOL nX2 = SanitizeCol( nX1 + aViewData.VisibleCellsX( eHWhich )); - SCROW nY2 = SanitizeRow( nY1 + aViewData.VisibleCellsY( eVWhich )); + SCCOL nX1 = pDoc->SanitizeCol( aViewData.GetPosX( eHWhich )); + SCROW nY1 = pDoc->SanitizeRow( aViewData.GetPosY( eVWhich )); + SCCOL nX2 = pDoc->SanitizeCol( nX1 + aViewData.VisibleCellsX( eHWhich )); + SCROW nY2 = pDoc->SanitizeRow( nY1 + aViewData.VisibleCellsY( eVWhich )); pDoc->InterpretDirtyCells(ScRange(nX1, nY1, nTab, nX2, nY2, nTab)); } diff --git a/sc/source/ui/view/tabvwsh3.cxx b/sc/source/ui/view/tabvwsh3.cxx index 419c6bce7845..5601804260f1 100644 --- a/sc/source/ui/view/tabvwsh3.cxx +++ b/sc/source/ui/view/tabvwsh3.cxx @@ -381,7 +381,7 @@ void ScTabViewShell::Execute( SfxRequest& rReq ) } } - if ( !ValidRow(aScRange.aStart.Row()) || !ValidRow(aScRange.aEnd.Row()) ) + if ( !pDoc->ValidRow(aScRange.aStart.Row()) || !pDoc->ValidRow(aScRange.aEnd.Row()) ) nResult = ScRefFlags::ZERO; // we have found something diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx index d10e1d8be8ed..564c367d60f3 100644 --- a/sc/source/ui/view/viewdata.cxx +++ b/sc/source/ui/view/viewdata.cxx @@ -595,12 +595,12 @@ void ScViewDataTable::ReadUserDataSequence(const uno::Sequence <beans::PropertyV if (sName == SC_CURSORPOSITIONX) { rSetting.Value >>= nTemp32; - nCurX = SanitizeCol( static_cast<SCCOL>(nTemp32)); + nCurX = rViewData.GetDocument()->SanitizeCol( static_cast<SCCOL>(nTemp32)); } else if (sName == SC_CURSORPOSITIONY) { rSetting.Value >>= nTemp32; - nCurY = SanitizeRow( static_cast<SCROW>(nTemp32)); + nCurY = rViewData.GetDocument()->SanitizeRow( static_cast<SCROW>(nTemp32)); } else if (sName == SC_HORIZONTALSPLITMODE) { @@ -640,22 +640,22 @@ void ScViewDataTable::ReadUserDataSequence(const uno::Sequence <beans::PropertyV else if (sName == SC_POSITIONLEFT) { rSetting.Value >>= nTemp32; - nPosX[SC_SPLIT_LEFT] = SanitizeCol( static_cast<SCCOL>(nTemp32)); + nPosX[SC_SPLIT_LEFT] = rViewData.GetDocument()->SanitizeCol( static_cast<SCCOL>(nTemp32)); } else if (sName == SC_POSITIONRIGHT) { rSetting.Value >>= nTemp32; - nPosX[SC_SPLIT_RIGHT] = SanitizeCol( static_cast<SCCOL>(nTemp32)); + nPosX[SC_SPLIT_RIGHT] = rViewData.GetDocument()->SanitizeCol( static_cast<SCCOL>(nTemp32)); } else if (sName == SC_POSITIONTOP) { rSetting.Value >>= nTemp32; - nPosY[SC_SPLIT_TOP] = SanitizeRow( static_cast<SCROW>(nTemp32)); + nPosY[SC_SPLIT_TOP] = rViewData.GetDocument()->SanitizeRow( static_cast<SCROW>(nTemp32)); } else if (sName == SC_POSITIONBOTTOM) { rSetting.Value >>= nTemp32; - nPosY[SC_SPLIT_BOTTOM] = SanitizeRow( static_cast<SCROW>(nTemp32)); + nPosY[SC_SPLIT_BOTTOM] = rViewData.GetDocument()->SanitizeRow( static_cast<SCROW>(nTemp32)); } else if (sName == SC_ZOOMTYPE) { @@ -703,12 +703,12 @@ void ScViewDataTable::ReadUserDataSequence(const uno::Sequence <beans::PropertyV } if (eHSplitMode == SC_SPLIT_FIX) - nFixPosX = SanitizeCol( static_cast<SCCOL>( bHasHSplitInTwips ? nTempPosHTw : nTempPosH )); + nFixPosX = rViewData.GetDocument()->SanitizeCol( static_cast<SCCOL>( bHasHSplitInTwips ? nTempPosHTw : nTempPosH )); else nHSplitPos = bHasHSplitInTwips ? static_cast< long >( nTempPosHTw * rViewData.GetPPTX() ) : nTempPosH; if (eVSplitMode == SC_SPLIT_FIX) - nFixPosY = SanitizeRow( static_cast<SCROW>( bHasVSplitInTwips ? nTempPosVTw : nTempPosV )); + nFixPosY = rViewData.GetDocument()->SanitizeRow( static_cast<SCROW>( bHasVSplitInTwips ? nTempPosVTw : nTempPosV )); else nVSplitPos = bHasVSplitInTwips ? static_cast< long >( nTempPosVTw * rViewData.GetPPTY() ) : nTempPosV; @@ -2954,15 +2954,15 @@ void ScViewData::ReadUserData(const OUString& rData) if (cTabSep) { nIdx = 0; - maTabData[nPos]->nCurX = SanitizeCol( static_cast<SCCOL>(aTabOpt.getToken(0, cTabSep, nIdx).toInt32())); - maTabData[nPos]->nCurY = SanitizeRow( aTabOpt.getToken(0, cTabSep, nIdx).toInt32()); + maTabData[nPos]->nCurX = pDoc->SanitizeCol( static_cast<SCCOL>(aTabOpt.getToken(0, cTabSep, nIdx).toInt32())); + maTabData[nPos]->nCurY = pDoc->SanitizeRow( aTabOpt.getToken(0, cTabSep, nIdx).toInt32()); maTabData[nPos]->eHSplitMode = static_cast<ScSplitMode>(aTabOpt.getToken(0, cTabSep, nIdx).toInt32()); maTabData[nPos]->eVSplitMode = static_cast<ScSplitMode>(aTabOpt.getToken(0, cTabSep, nIdx).toInt32()); sal_Int32 nTmp{ aTabOpt.getToken(0, cTabSep, nIdx).toInt32() }; if ( maTabData[nPos]->eHSplitMode == SC_SPLIT_FIX ) { - maTabData[nPos]->nFixPosX = SanitizeCol( static_cast<SCCOL>(nTmp)); + maTabData[nPos]->nFixPosX = pDoc->SanitizeCol( static_cast<SCCOL>(nTmp)); UpdateFixX(nPos); } else @@ -2971,17 +2971,17 @@ void ScViewData::ReadUserData(const OUString& rData) nTmp = aTabOpt.getToken(0, cTabSep, nIdx).toInt32(); if ( maTabData[nPos]->eVSplitMode == SC_SPLIT_FIX ) { - maTabData[nPos]->nFixPosY = SanitizeRow(nTmp); + maTabData[nPos]->nFixPosY = pDoc->SanitizeRow(nTmp); UpdateFixY(nPos); } else maTabData[nPos]->nVSplitPos = nTmp; maTabData[nPos]->eWhichActive = static_cast<ScSplitPos>(aTabOpt.getToken(0, cTabSep, nIdx).toInt32()); - maTabData[nPos]->nPosX[0] = SanitizeCol( static_cast<SCCOL>(aTabOpt.getToken(0, cTabSep, nIdx).toInt32())); - maTabData[nPos]->nPosX[1] = SanitizeCol( static_cast<SCCOL>(aTabOpt.getToken(0, cTabSep, nIdx).toInt32())); - maTabData[nPos]->nPosY[0] = SanitizeRow( aTabOpt.getToken(0, cTabSep, nIdx).toInt32()); - maTabData[nPos]->nPosY[1] = SanitizeRow( aTabOpt.getToken(0, cTabSep, nIdx).toInt32()); + maTabData[nPos]->nPosX[0] = pDoc->SanitizeCol( static_cast<SCCOL>(aTabOpt.getToken(0, cTabSep, nIdx).toInt32())); + maTabData[nPos]->nPosX[1] = pDoc->SanitizeCol( static_cast<SCCOL>(aTabOpt.getToken(0, cTabSep, nIdx).toInt32())); + maTabData[nPos]->nPosY[0] = pDoc->SanitizeRow( aTabOpt.getToken(0, cTabSep, nIdx).toInt32()); + maTabData[nPos]->nPosY[1] = pDoc->SanitizeRow( aTabOpt.getToken(0, cTabSep, nIdx).toInt32()); maTabData[nPos]->eWhichActive = maTabData[nPos]->SanitizeWhichActive(); } diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index 198a53495798..1880365a38af 100644 --- a/sc/source/ui/view/viewfun2.cxx +++ b/sc/source/ui/view/viewfun2.cxx @@ -808,7 +808,7 @@ OUString ScViewFunc::GetAutoSumFormula( const ScRangeList& rRangeList, bool bSub if (i != 0) pArray->AddOpCode(ocSep); ScComplexRefData aRef; - aRef.InitRangeRel(r, rAddr); + aRef.InitRangeRel(pDoc, r, rAddr); pArray->AddDoubleReference(aRef); } } diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx index 7a39f5037fa2..72bd69f209f2 100644 --- a/sc/source/ui/view/viewfun3.cxx +++ b/sc/source/ui/view/viewfun3.cxx @@ -1129,7 +1129,7 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc, nEndTab = nStartTab; } - bool bOffLimits = !ValidCol(nEndCol) || !ValidRow(nEndRow); + bool bOffLimits = !pDoc->ValidCol(nEndCol) || !pDoc->ValidRow(nEndRow); // target-range, as displayed: ScRange aUserRange( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab ); @@ -1500,7 +1500,7 @@ bool ScViewFunc::PasteMultiRangesFromClip( nRowSize = static_cast<SCROW>(nTempColSize); } - if (!ValidCol(rCurPos.Col()+nColSize-1) || !ValidRow(rCurPos.Row()+nRowSize-1)) + if (!pDoc->ValidCol(rCurPos.Col()+nColSize-1) || !pDoc->ValidRow(rCurPos.Row()+nRowSize-1)) { ErrorMessage(STR_PASTE_FULL); return false; @@ -1668,7 +1668,7 @@ bool ScViewFunc::PasteFromClipToMultiRanges( SCROW nRowSize = aSrcRange.aEnd.Row() - aSrcRange.aStart.Row() + 1; SCCOL nColSize = aSrcRange.aEnd.Col() - aSrcRange.aStart.Col() + 1; - if (!ValidCol(rCurPos.Col()+nColSize-1) || !ValidRow(rCurPos.Row()+nRowSize-1)) + if (!pDoc->ValidCol(rCurPos.Col()+nColSize-1) || !pDoc->ValidRow(rCurPos.Row()+nRowSize-1)) { ErrorMessage(STR_PASTE_FULL); return false; diff --git a/sc/source/ui/view/viewfun6.cxx b/sc/source/ui/view/viewfun6.cxx index 393b33c3a09b..16a85889656e 100644 --- a/sc/source/ui/view/viewfun6.cxx +++ b/sc/source/ui/view/viewfun6.cxx @@ -177,7 +177,7 @@ void ScViewFunc::DetectiveMarkPred() const OUString* pPath = pRefMgr->getExternalFileName(nFileId); ScRange aRange; - if (pPath && ScRefTokenHelper::getRangeFromToken(aRange, p, aCurPos, true)) + if (pPath && ScRefTokenHelper::getRangeFromToken(&rDoc, aRange, p, aCurPos, true)) { OUString aTabName = p->GetString().getString(); OUString aRangeStr(aRange.Format(rDoc, ScRefFlags::VALID)); @@ -195,7 +195,7 @@ void ScViewFunc::DetectiveMarkPred() else { ScRange aRange; - ScRefTokenHelper::getRangeFromToken(aRange, p, aCurPos); + ScRefTokenHelper::getRangeFromToken(&rDoc, aRange, p, aCurPos); if (aRange.aStart.Tab() != aCurPos.Tab()) { // The first precedent range is on a different sheet. Jump to it @@ -206,7 +206,7 @@ void ScViewFunc::DetectiveMarkPred() } ScRangeList aDestRanges; - ScRefTokenHelper::getRangeListFromTokens(aDestRanges, aRefTokens, aCurPos); + ScRefTokenHelper::getRangeListFromTokens(&rDoc, aDestRanges, aRefTokens, aCurPos); MarkAndJumpToRanges(aDestRanges); } @@ -230,7 +230,7 @@ void ScViewFunc::DetectiveMarkSucc() return; ScRangeList aDestRanges; - ScRefTokenHelper::getRangeListFromTokens(aDestRanges, aRefTokens, aCurPos); + ScRefTokenHelper::getRangeListFromTokens(rView.GetDocument(), aDestRanges, aRefTokens, aCurPos); MarkAndJumpToRanges(aDestRanges); } diff --git a/sc/source/ui/view/viewutil.cxx b/sc/source/ui/view/viewutil.cxx index 8368cbee7c89..75c7ac543b80 100644 --- a/sc/source/ui/view/viewutil.cxx +++ b/sc/source/ui/view/viewutil.cxx @@ -263,7 +263,7 @@ bool ScViewUtil::FitToUnfilteredRows( ScRange & rRange, const ScDocument * pDoc, OSL_ENSURE( bOneTabOnly, "ScViewUtil::ExtendToUnfilteredRows: works only on one sheet"); SCROW nStartRow = rRange.aStart.Row(); SCROW nLastRow = pDoc->LastNonFilteredRow(nStartRow, pDoc->MaxRow(), nTab); - if (ValidRow(nLastRow)) + if (pDoc->ValidRow(nLastRow)) rRange.aEnd.SetRow(nLastRow); SCROW nCount = pDoc->CountNonFilteredRows(nStartRow, pDoc->MaxRow(), nTab); return static_cast<size_t>(nCount) == nRows && bOneTabOnly; |