sc/inc/address.hxx               |   20 ++-----------
 sc/inc/refdata.hxx               |   12 +-------
 sc/inc/sheetlimits.hxx           |    4 ++
 sc/source/core/tool/address.cxx  |   12 ++++++++
 sc/source/core/tool/compiler.cxx |    4 +-
 sc/source/core/tool/refdata.cxx  |   13 +++++++++
 sc/source/core/tool/token.cxx    |   56 ++++++++++++++++++++-------------------
 7 files changed, 66 insertions(+), 55 deletions(-)

New commits:
commit 32e480cecd9f5c35880a8d1762012e44c36c478c
Author:     Luboš Luňák <l.lu...@collabora.com>
AuthorDate: Fri Feb 11 18:46:30 2022 +0100
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Mon Feb 14 09:13:57 2022 +0100

    remove use of MAXCOL/MAXROW from address.hxx
    
    Change-Id: Icfc00584b0190ee90e506f80c73231e12f155cc9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129853
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/sc/inc/address.hxx b/sc/inc/address.hxx
index a87f1bbf2b2c..dab74ac0fcc0 100644
--- a/sc/inc/address.hxx
+++ b/sc/inc/address.hxx
@@ -478,7 +478,7 @@ struct ScAddressHashFunctor
     }
 };
 
-[[nodiscard]] inline bool ValidAddress( const ScAddress& rAddress, SCCOL 
nMaxCol = MAXCOL, SCROW nMaxRow = MAXROW )
+[[nodiscard]] inline bool ValidAddress( const ScAddress& rAddress, SCCOL 
nMaxCol, SCROW nMaxRow )
 {
     return ValidCol(rAddress.Col(), nMaxCol) && ValidRow(rAddress.Row(), 
nMaxRow) && ValidTab(rAddress.Tab());
 }
@@ -636,9 +636,9 @@ public:
     ScRange Intersection( const ScRange& rOther ) const;
 
     /// If maximum end column should not be adapted during reference update.
-    inline bool IsEndColSticky() const;
+    bool IsEndColSticky( const ScDocument& rDoc ) const;
     /// If maximum end row should not be adapted during reference update.
-    inline bool IsEndRowSticky() const;
+    bool IsEndRowSticky( const ScDocument& rDoc ) const;
 
     /** Increment or decrement end column unless sticky or until it becomes
         sticky. Checks if the range encompasses at least two columns so should
@@ -687,18 +687,6 @@ inline void ScRange::GetVars( SCCOL& nCol1, SCROW& nRow1, 
SCTAB& nTab1,
     aEnd.GetVars( nCol2, nRow2, nTab2 );
 }
 
-inline bool ScRange::IsEndColSticky() const
-{
-    // Only in an actual column range, i.e. not if both columns are MAXCOL.
-    return aEnd.Col() == MAXCOL && aStart.Col() < aEnd.Col();
-}
-
-inline bool ScRange::IsEndRowSticky() const
-{
-    // Only in an actual row range, i.e. not if both rows are MAXROW.
-    return aEnd.Row() == MAXROW && aStart.Row() < aEnd.Row();
-}
-
 inline bool ScRange::operator==( const ScRange& rRange ) const
 {
     return ( (aStart == rRange.aStart) && (aEnd == rRange.aEnd) );
@@ -788,7 +776,7 @@ inline size_t ScRange::hashStartColumn() const
 #endif
 }
 
-[[nodiscard]] inline bool ValidRange( const ScRange& rRange, SCCOL nMaxCol = 
MAXCOL, SCROW nMaxRow = MAXROW )
+[[nodiscard]] inline bool ValidRange( const ScRange& rRange, SCCOL nMaxCol, 
SCROW nMaxRow )
 {
     return ValidAddress(rRange.aStart, nMaxCol, nMaxRow) && 
ValidAddress(rRange.aEnd, nMaxCol, nMaxRow);
 }
diff --git a/sc/inc/refdata.hxx b/sc/inc/refdata.hxx
index 96519b885d84..4cc296a0a394 100644
--- a/sc/inc/refdata.hxx
+++ b/sc/inc/refdata.hxx
@@ -155,18 +155,10 @@ struct ScComplexRefData
     bool ValidExternal(const ScDocument& rDoc) const;
 
     /** Whether this references entire columns, A:A */
-    bool IsEntireCol() const
-    {
-        // Both row anchors must be absolute.
-        return Ref1.Row() == 0 && Ref2.Row() == MAXROW && !Ref1.IsRowRel() && 
!Ref2.IsRowRel();
-    }
+    bool IsEntireCol( const ScSheetLimits& rLimits ) const;
 
     /** Whether this references entire rows, 1:1 */
-    bool IsEntireRow() const
-    {
-        // Both column anchors must be absolute.
-        return Ref1.Col() == 0 && Ref2.Col() == MAXCOL && !Ref1.IsColRel() && 
!Ref2.IsColRel();
-    }
+    bool IsEntireRow( const ScSheetLimits& rLimits ) const;
 
     SC_DLLPUBLIC ScRange toAbs( const ScSheetLimits& rLimits, const ScAddress& 
rPos ) const;
     SC_DLLPUBLIC ScRange toAbs( const ScDocument& rDoc, const ScAddress& rPos 
) const;
diff --git a/sc/inc/sheetlimits.hxx b/sc/inc/sheetlimits.hxx
index 26bd423d422f..c8dbc1165216 100644
--- a/sc/inc/sheetlimits.hxx
+++ b/sc/inc/sheetlimits.hxx
@@ -57,6 +57,10 @@ struct ScSheetLimits final : public 
salhelper::SimpleReferenceObject
     [[nodiscard]] SCCOL SanitizeCol(SCCOL nCol) const { return 
::SanitizeCol(nCol, mnMaxCol); }
     [[nodiscard]] SCROW SanitizeRow(SCROW nRow) const { return 
::SanitizeRow(nRow, mnMaxRow); }
 
+    // equivalent of MAXROW in address.hxx
+    SCROW MaxRow() const { return mnMaxRow; }
+    // equivalent of MAXCOL in address.hxx
+    SCCOL MaxCol() const { return mnMaxCol; }
     // equivalent of MAXROWCOUNT in address.hxx
     SCROW GetMaxRowCount() const { return mnMaxRow + 1; }
     // equivalent of MAXCOLCOUNT in address.hxx
diff --git a/sc/source/core/tool/address.cxx b/sc/source/core/tool/address.cxx
index ade934380aae..668c08b063d3 100644
--- a/sc/source/core/tool/address.cxx
+++ b/sc/source/core/tool/address.cxx
@@ -2423,6 +2423,18 @@ void ScRange::IncRowIfNotLessThan(const ScDocument& 
rDoc, SCROW nStartRow, SCROW
     }
 }
 
+bool ScRange::IsEndColSticky( const ScDocument& rDoc ) const
+{
+    // Only in an actual column range, i.e. not if both columns are MAXCOL.
+    return aEnd.Col() == rDoc.MaxCol() && aStart.Col() < aEnd.Col();
+}
+
+bool ScRange::IsEndRowSticky( const ScDocument& rDoc ) const
+{
+    // Only in an actual row range, i.e. not if both rows are MAXROW.
+    return aEnd.Row() == rDoc.MaxRow() && aStart.Row() < aEnd.Row();
+}
+
 void ScRange::IncEndColSticky( const ScDocument& rDoc, SCCOL nDelta )
 {
     SCCOL nCol = aEnd.Col();
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index aa65019434ea..8929e0756e90 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -861,7 +861,7 @@ struct ConventionOOO_A1 : public Convention_A1
             return SINGLETON_NONE;
 
         // A:A or $A:$A or A:$A or $A:A
-        if (rRef.IsEntireCol())
+        if (rRef.IsEntireCol(rLimits))
             return SINGLETON_COL;
 
         // Same if not in named expression and both rows of entire columns are
@@ -871,7 +871,7 @@ struct ConventionOOO_A1 : public Convention_A1
             return SINGLETON_COL;
 
         // 1:1 or $1:$1 or 1:$1 or $1:1
-        if (rRef.IsEntireRow())
+        if (rRef.IsEntireRow(rLimits))
             return SINGLETON_ROW;
 
         // Same if not in named expression and both columns of entire rows are
diff --git a/sc/source/core/tool/refdata.cxx b/sc/source/core/tool/refdata.cxx
index 59a224dbcfbd..ec18dc06f598 100644
--- a/sc/source/core/tool/refdata.cxx
+++ b/sc/source/core/tool/refdata.cxx
@@ -506,6 +506,19 @@ void ScComplexRefData::PutInOrder( const ScAddress& rPos )
     ScSingleRefData::PutInOrder( Ref1, Ref2, rPos);
 }
 
+bool ScComplexRefData::IsEntireCol( const ScSheetLimits& rLimits ) const
+{
+    // Both row anchors must be absolute.
+    return Ref1.Row() == 0 && Ref2.Row() == rLimits.MaxRow() && 
!Ref1.IsRowRel() && !Ref2.IsRowRel();
+}
+
+/** Whether this references entire rows, 1:1 */
+bool ScComplexRefData::IsEntireRow( const ScSheetLimits& rLimits ) const
+{
+    // Both column anchors must be absolute.
+    return Ref1.Col() == 0 && Ref2.Col() == rLimits.MaxCol() && 
!Ref1.IsColRel() && !Ref2.IsColRel();
+}
+
 bool ScComplexRefData::IncEndColSticky( const ScDocument& rDoc, SCCOL nDelta, 
const ScAddress& rPos )
 {
     SCCOL nCol1 = Ref1.IsColRel() ? Ref1.Col() + rPos.Col() : Ref1.Col();
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 6cdb552a7397..33e99dc65eb4 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -2851,7 +2851,7 @@ ShrinkResult shrinkRange( const sc::RefUpdateContext& 
rCxt, ScRange& rRefRange,
 
     if (rCxt.mnColDelta < 0)
     {
-        if (rRef.IsEntireRow())
+        if (rRef.IsEntireRow(rCxt.mrDoc.GetSheetLimits()))
             // Entire rows are not affected, columns are anchored.
             return STICKY;
 
@@ -2878,7 +2878,7 @@ ShrinkResult shrinkRange( const sc::RefUpdateContext& 
rCxt, ScRange& rRefRange,
         }
         else if (rDeletedRange.aEnd.Col() < rRefRange.aEnd.Col())
         {
-            if (rRefRange.IsEndColSticky())
+            if (rRefRange.IsEndColSticky(rCxt.mrDoc))
                 // Sticky end not affected.
                 return STICKY;
 
@@ -2889,7 +2889,7 @@ ShrinkResult shrinkRange( const sc::RefUpdateContext& 
rCxt, ScRange& rRefRange,
         }
         else
         {
-            if (rRefRange.IsEndColSticky())
+            if (rRefRange.IsEndColSticky(rCxt.mrDoc))
                 // Sticky end not affected.
                 return STICKY;
 
@@ -2901,7 +2901,7 @@ ShrinkResult shrinkRange( const sc::RefUpdateContext& 
rCxt, ScRange& rRefRange,
     }
     else if (rCxt.mnRowDelta < 0)
     {
-        if (rRef.IsEntireCol())
+        if (rRef.IsEntireCol(rCxt.mrDoc.GetSheetLimits()))
             // Entire columns are not affected, rows are anchored.
             return STICKY;
 
@@ -2929,7 +2929,7 @@ ShrinkResult shrinkRange( const sc::RefUpdateContext& 
rCxt, ScRange& rRefRange,
         }
         else if (rDeletedRange.aEnd.Row() < rRefRange.aEnd.Row())
         {
-            if (rRefRange.IsEndRowSticky())
+            if (rRefRange.IsEndRowSticky(rCxt.mrDoc))
                 // Sticky end not affected.
                 return STICKY;
 
@@ -2940,7 +2940,7 @@ ShrinkResult shrinkRange( const sc::RefUpdateContext& 
rCxt, ScRange& rRefRange,
         }
         else
         {
-            if (rRefRange.IsEndRowSticky())
+            if (rRefRange.IsEndRowSticky(rCxt.mrDoc))
                 // Sticky end not affected.
                 return STICKY;
 
@@ -2962,7 +2962,7 @@ bool expandRange( const sc::RefUpdateContext& rCxt, 
ScRange& rRefRange, const Sc
 
     if (rCxt.mnColDelta > 0)
     {
-        if (rRef.IsEntireRow())
+        if (rRef.IsEntireRow(rCxt.mrDoc.GetSheetLimits()))
             // Entire rows are not affected, columns are anchored.
             return false;
 
@@ -2984,7 +2984,7 @@ bool expandRange( const sc::RefUpdateContext& rCxt, 
ScRange& rRefRange, const Sc
                 return false;
         }
 
-        if (rRefRange.IsEndColSticky())
+        if (rRefRange.IsEndColSticky(rCxt.mrDoc))
             // Sticky end not affected.
             return false;
 
@@ -2995,7 +2995,7 @@ bool expandRange( const sc::RefUpdateContext& rCxt, 
ScRange& rRefRange, const Sc
     }
     else if (rCxt.mnRowDelta > 0)
     {
-        if (rRef.IsEntireCol())
+        if (rRef.IsEntireCol(rCxt.mrDoc.GetSheetLimits()))
             // Entire columns are not affected, rows are anchored.
             return false;
 
@@ -3017,7 +3017,7 @@ bool expandRange( const sc::RefUpdateContext& rCxt, 
ScRange& rRefRange, const Sc
                 return false;
         }
 
-        if (rRefRange.IsEndRowSticky())
+        if (rRefRange.IsEndRowSticky(rCxt.mrDoc))
             // Sticky end not affected.
             return false;
 
@@ -3046,7 +3046,7 @@ bool expandRangeByEdge( const sc::RefUpdateContext& rCxt, 
ScRange& rRefRange, co
 
     if (rCxt.mnColDelta > 0)
     {
-        if (rRef.IsEntireRow())
+        if (rRef.IsEntireRow(rCxt.mrDoc.GetSheetLimits()))
             // Entire rows are not affected, columns are anchored.
             return false;
 
@@ -3064,7 +3064,7 @@ bool expandRangeByEdge( const sc::RefUpdateContext& rCxt, 
ScRange& rRefRange, co
             // Selected range is not immediately adjacent. Bail out.
             return false;
 
-        if (rRefRange.IsEndColSticky())
+        if (rRefRange.IsEndColSticky(rCxt.mrDoc))
             // Sticky end not affected.
             return false;
 
@@ -3075,7 +3075,7 @@ bool expandRangeByEdge( const sc::RefUpdateContext& rCxt, 
ScRange& rRefRange, co
     }
     else if (rCxt.mnRowDelta > 0)
     {
-        if (rRef.IsEntireCol())
+        if (rRef.IsEntireCol(rCxt.mrDoc.GetSheetLimits()))
             // Entire columns are not affected, rows are anchored.
             return false;
 
@@ -3091,7 +3091,7 @@ bool expandRangeByEdge( const sc::RefUpdateContext& rCxt, 
ScRange& rRefRange, co
             // Selected range is not immediately adjacent. Bail out.
             return false;
 
-        if (rRefRange.IsEndRowSticky())
+        if (rRefRange.IsEndRowSticky(rCxt.mrDoc))
             // Sticky end not affected.
             return false;
 
@@ -3276,7 +3276,8 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnShift( 
const sc::RefUpdateCon
                             // We shift either by column or by row, not both,
                             // so moving the reference has only to be done in
                             // the non-sticky case.
-                            if ((rCxt.mnRowDelta && rRef.IsEntireCol()) || 
(rCxt.mnColDelta && rRef.IsEntireRow()))
+                            if ((rCxt.mnRowDelta && 
rRef.IsEntireCol(rCxt.mrDoc.GetSheetLimits()))
+                                || (rCxt.mnColDelta && 
rRef.IsEntireRow(rCxt.mrDoc.GetSheetLimits())))
                             {
                                 // In entire col/row, values are shifted within
                                 // the reference, which affects all positional
@@ -3744,7 +3745,8 @@ bool adjustDoubleRefInName(
         }
     }
 
-    if ((rCxt.mnRowDelta && rRef.IsEntireCol()) || (rCxt.mnColDelta && 
rRef.IsEntireRow()))
+    if ((rCxt.mnRowDelta && rRef.IsEntireCol(rCxt.mrDoc.GetSheetLimits()))
+        || (rCxt.mnColDelta && rRef.IsEntireRow(rCxt.mrDoc.GetSheetLimits())))
     {
         sc::RefUpdateContext aCxt( rCxt.mrDoc);
         // We only need a few parameters of RefUpdateContext.
@@ -3754,9 +3756,9 @@ bool adjustDoubleRefInName(
         aCxt.mnTabDelta = rCxt.mnTabDelta;
 
         // References to entire col/row are not to be adjusted in the other 
axis.
-        if (aCxt.mnRowDelta && rRef.IsEntireCol())
+        if (aCxt.mnRowDelta && rRef.IsEntireCol(rCxt.mrDoc.GetSheetLimits()))
             aCxt.mnRowDelta = 0;
-        if (aCxt.mnColDelta && rRef.IsEntireRow())
+        if (aCxt.mnColDelta && rRef.IsEntireRow(rCxt.mrDoc.GetSheetLimits()))
             aCxt.mnColDelta = 0;
         if (!aCxt.mnColDelta && !aCxt.mnRowDelta && !aCxt.mnTabDelta)
             // early bailout
@@ -3894,7 +3896,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceInName(
                         {
                             // row(s) deleted.
 
-                            if (rRef.IsEntireCol())
+                            if (rRef.IsEntireCol(rCxt.mrDoc.GetSheetLimits()))
                                 // Rows of entire columns are not affected.
                                 break;
 
@@ -3925,7 +3927,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceInName(
 
                             if (aAbs.aStart.Row() < aDeleted.aStart.Row())
                             {
-                                if (!aAbs.IsEndRowSticky())
+                                if (!aAbs.IsEndRowSticky(rCxt.mrDoc))
                                 {
                                     if (aDeleted.aEnd.Row() < aAbs.aEnd.Row())
                                         // Deleted in the middle.  Make the 
reference shorter.
@@ -3940,7 +3942,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceInName(
                                 // Deleted at the top.  Cut the top off and 
shift up.
                                 rRef.Ref1.SetAbsRow(aDeleted.aEnd.Row()+1);
                                 rRef.Ref1.IncRow(rCxt.mnRowDelta);
-                                if (!aAbs.IsEndRowSticky())
+                                if (!aAbs.IsEndRowSticky(rCxt.mrDoc))
                                     rRef.Ref2.IncRow(rCxt.mnRowDelta);
                             }
 
@@ -3950,7 +3952,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceInName(
                         {
                             // column(s) deleted.
 
-                            if (rRef.IsEntireRow())
+                            if (rRef.IsEntireRow(rCxt.mrDoc.GetSheetLimits()))
                                 // Rows of entire rows are not affected.
                                 break;
 
@@ -3981,7 +3983,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceInName(
 
                             if (aAbs.aStart.Col() < aDeleted.aStart.Col())
                             {
-                                if (!aAbs.IsEndColSticky())
+                                if (!aAbs.IsEndColSticky(rCxt.mrDoc))
                                 {
                                     if (aDeleted.aEnd.Col() < aAbs.aEnd.Col())
                                         // Deleted in the middle.  Make the 
reference shorter.
@@ -3996,7 +3998,7 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceInName(
                                 // Deleted at the left.  Cut the left off and 
shift left.
                                 rRef.Ref1.SetAbsCol(aDeleted.aEnd.Col()+1);
                                 rRef.Ref1.IncCol(rCxt.mnColDelta);
-                                if (!aAbs.IsEndColSticky())
+                                if (!aAbs.IsEndColSticky(rCxt.mrDoc))
                                     rRef.Ref2.IncCol(rCxt.mnColDelta);
                             }
 
@@ -5313,14 +5315,14 @@ void ScTokenArray::WrapReference( const ScAddress& 
rPos, SCCOL nMaxCol, SCROW nM
                 ScComplexRefData& rRef = *pToken->GetDoubleRef();
                 ScRange aAbs = rRef.toAbs(*mxSheetLimits, rPos);
                 // Entire columns/rows are sticky.
-                if (!rRef.IsEntireCol() && !rRef.IsEntireRow())
+                if (!rRef.IsEntireCol(*mxSheetLimits) && 
!rRef.IsEntireRow(*mxSheetLimits))
                 {
                     wrapColRange( aAbs, nMaxCol);
                     wrapRowRange( aAbs, nMaxRow);
                 }
-                else if (rRef.IsEntireCol() && !rRef.IsEntireRow())
+                else if (rRef.IsEntireCol(*mxSheetLimits) && 
!rRef.IsEntireRow(*mxSheetLimits))
                     wrapColRange( aAbs, nMaxCol);
-                else if (!rRef.IsEntireCol() && rRef.IsEntireRow())
+                else if (!rRef.IsEntireCol(*mxSheetLimits) && 
rRef.IsEntireRow(*mxSheetLimits))
                     wrapRowRange( aAbs, nMaxRow);
                 // else nothing if both, column and row, are entire.
                 aAbs.PutInOrder();

Reply via email to