sc/inc/document.hxx                                  |    8 +-
 sc/inc/prnsave.hxx                                   |   13 ++-
 sc/inc/table.hxx                                     |   12 +--
 sc/qa/unit/subsequent_filters_test2.cxx              |    2 
 sc/source/core/data/document.cxx                     |   16 ++--
 sc/source/core/data/table1.cxx                       |   64 +++++++++----------
 sc/source/core/tool/prnsave.cxx                      |   17 +----
 sc/source/filter/excel/impop.cxx                     |    4 -
 sc/source/filter/excel/xename.cxx                    |   12 +--
 sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx |   12 +--
 sc/source/ui/docshell/docsh4.cxx                     |   22 +++---
 sc/source/ui/pagedlg/areasdlg.cxx                    |   24 +++----
 sc/source/ui/unoobj/cellsuno.cxx                     |   37 +++++-----
 sc/source/ui/view/printfun.cxx                       |   16 ++--
 sc/source/ui/view/viewfun2.cxx                       |    8 +-
 15 files changed, 129 insertions(+), 138 deletions(-)

New commits:
commit dabd26614ddf73a2fb382e7a105c8c11c88741d9
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue May 31 15:47:38 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Jun 1 18:12:09 2022 +0200

    pass ScRange around by value
    
    it's a very small object, and trivially movable. No need to allocate it
    separately
    
    Change-Id: I0adf947433e73a425f39004297c450a93ac4e5f7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135216
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index a2bacddee3a3..7bd27c6b95fa 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -2102,8 +2102,8 @@ public:
     SC_DLLPUBLIC bool           HasPrintRange();
     SC_DLLPUBLIC sal_uInt16     GetPrintRangeCount( SCTAB nTab );
     SC_DLLPUBLIC const ScRange* GetPrintRange( SCTAB nTab, sal_uInt16 nPos );
-    SC_DLLPUBLIC const ScRange* GetRepeatColRange( SCTAB nTab );
-    SC_DLLPUBLIC const ScRange* GetRepeatRowRange( SCTAB nTab );
+    SC_DLLPUBLIC std::optional<ScRange> GetRepeatColRange( SCTAB nTab );
+    SC_DLLPUBLIC std::optional<ScRange> GetRepeatRowRange( SCTAB nTab );
     /** Returns true, if the specified sheet is always printed. */
     bool                        IsPrintEntireSheet( SCTAB nTab ) const;
 
@@ -2113,8 +2113,8 @@ public:
     SC_DLLPUBLIC void            AddPrintRange( SCTAB nTab, const ScRange& 
rNew );
     /** Marks the specified sheet to be printed completely. Deletes old print 
ranges on the sheet! */
     SC_DLLPUBLIC void            SetPrintEntireSheet( SCTAB nTab );
-    SC_DLLPUBLIC void            SetRepeatColRange( SCTAB nTab, 
std::unique_ptr<ScRange> pNew );
-    SC_DLLPUBLIC void            SetRepeatRowRange( SCTAB nTab, 
std::unique_ptr<ScRange> pNew );
+    SC_DLLPUBLIC void            SetRepeatColRange( SCTAB nTab, 
std::optional<ScRange> oNew );
+    SC_DLLPUBLIC void            SetRepeatRowRange( SCTAB nTab, 
std::optional<ScRange> oNew );
     std::unique_ptr<ScPrintRangeSaver> CreatePrintRangeSaver() const;
     void                         RestorePrintRanges( const ScPrintRangeSaver& 
rSaver );
 
diff --git a/sc/inc/prnsave.hxx b/sc/inc/prnsave.hxx
index af2824b40cf8..9d10b430d4c6 100644
--- a/sc/inc/prnsave.hxx
+++ b/sc/inc/prnsave.hxx
@@ -20,8 +20,9 @@
 #pragma once
 
 #include "address.hxx"
-#include <vector>
+#include <optional>
 #include <memory>
+#include <vector>
 
 namespace tools { class JsonWriter; }
 
@@ -30,8 +31,8 @@ class ScPrintSaverTab
     typedef ::std::vector< ScRange > ScRangeVec;
 
     ScRangeVec  maPrintRanges;      ///< Array
-    std::unique_ptr<ScRange> mpRepeatCol;        ///< single
-    std::unique_ptr<ScRange> mpRepeatRow;        ///< single
+    std::optional<ScRange> moRepeatCol;        ///< single
+    std::optional<ScRange> moRepeatRow;        ///< single
     bool        mbEntireSheet;
 
 public:
@@ -39,12 +40,12 @@ public:
             ~ScPrintSaverTab();
 
     void            SetAreas( ScRangeVec&& rRanges, bool bEntireSheet );
-    void            SetRepeat( const ScRange* pCol, const ScRange* pRow );
+    void            SetRepeat( std::optional<ScRange> oCol, 
std::optional<ScRange> oRow );
 
     const ScRangeVec&   GetPrintRanges() const  { return maPrintRanges; }
     bool                IsEntireSheet() const   { return mbEntireSheet; }
-    const ScRange*      GetRepeatCol() const    { return mpRepeatCol.get(); }
-    const ScRange*      GetRepeatRow() const    { return mpRepeatRow.get(); }
+    const std::optional<ScRange>& GetRepeatCol() const { return moRepeatCol; }
+    const std::optional<ScRange>& GetRepeatRow() const { return moRepeatRow; }
 
     bool    operator==( const ScPrintSaverTab& rCmp ) const;
 };
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 6c083e064add..1a0a0e477758 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -216,8 +216,8 @@ private:
 
     ScRangeVec      aPrintRanges;
 
-    std::unique_ptr<ScRange> pRepeatColRange;
-    std::unique_ptr<ScRange> pRepeatRowRange;
+    std::optional<ScRange> moRepeatColRange;
+    std::optional<ScRange> moRepeatRowRange;
 
     sal_uInt16          nLockCount;
 
@@ -793,10 +793,10 @@ public:
     void        ClearSelectionItems( const sal_uInt16* pWhich, const 
ScMarkData& rMark );
     void        ChangeSelectionIndent( bool bIncrement, const ScMarkData& 
rMark );
 
-    const ScRange*  GetRepeatColRange() const   { return 
pRepeatColRange.get(); }
-    const ScRange*  GetRepeatRowRange() const   { return 
pRepeatRowRange.get(); }
-    void            SetRepeatColRange( std::unique_ptr<ScRange> pNew );
-    void            SetRepeatRowRange( std::unique_ptr<ScRange> pNew );
+    const std::optional<ScRange>& GetRepeatColRange() const { return 
moRepeatColRange; }
+    const std::optional<ScRange>& GetRepeatRowRange() const { return 
moRepeatRowRange; }
+    void            SetRepeatColRange( std::optional<ScRange> oNew );
+    void            SetRepeatRowRange( std::optional<ScRange> oNew );
 
     sal_uInt16          GetPrintRangeCount() const          { return 
static_cast< sal_uInt16 >( aPrintRanges.size() ); }
     const ScRange*  GetPrintRange(sal_uInt16 nPos) const;
diff --git a/sc/qa/unit/subsequent_filters_test2.cxx 
b/sc/qa/unit/subsequent_filters_test2.cxx
index ebdb2bd84a52..05a393aa3f6b 100644
--- a/sc/qa/unit/subsequent_filters_test2.cxx
+++ b/sc/qa/unit/subsequent_filters_test2.cxx
@@ -505,7 +505,7 @@ void ScFiltersTest2::testPrintRangeODS()
 {
     ScDocShellRef xDocSh = loadDoc(u"print-range.", FORMAT_ODS);
     ScDocument& rDoc = xDocSh->GetDocument();
-    const ScRange* pRange = rDoc.GetRepeatRowRange(0);
+    std::optional<ScRange> pRange = rDoc.GetRepeatRowRange(0);
     CPPUNIT_ASSERT(pRange);
     CPPUNIT_ASSERT_EQUAL(ScRange(0, 0, 0, 0, 1, 0), *pRange);
 
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 8cf93a6abe5c..a458f4d765e6 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -6386,20 +6386,20 @@ const ScRange* ScDocument::GetPrintRange( SCTAB nTab, 
sal_uInt16 nPos )
     return nullptr;
 }
 
-const ScRange* ScDocument::GetRepeatColRange( SCTAB nTab )
+std::optional<ScRange> ScDocument::GetRepeatColRange( SCTAB nTab )
 {
     if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && 
maTabs[nTab])
         return maTabs[nTab]->GetRepeatColRange();
 
-    return nullptr;
+    return std::nullopt;
 }
 
-const ScRange* ScDocument::GetRepeatRowRange( SCTAB nTab )
+std::optional<ScRange> ScDocument::GetRepeatRowRange( SCTAB nTab )
 {
     if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && 
maTabs[nTab])
         return maTabs[nTab]->GetRepeatRowRange();
 
-    return nullptr;
+    return std::nullopt;
 }
 
 void ScDocument::ClearPrintRanges( SCTAB nTab )
@@ -6420,16 +6420,16 @@ void ScDocument::SetPrintEntireSheet( SCTAB nTab )
         maTabs[nTab]->SetPrintEntireSheet();
 }
 
-void ScDocument::SetRepeatColRange( SCTAB nTab, std::unique_ptr<ScRange> pNew )
+void ScDocument::SetRepeatColRange( SCTAB nTab, std::optional<ScRange> oNew )
 {
     if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && 
maTabs[nTab])
-        maTabs[nTab]->SetRepeatColRange( std::move(pNew) );
+        maTabs[nTab]->SetRepeatColRange( std::move(oNew) );
 }
 
-void ScDocument::SetRepeatRowRange( SCTAB nTab, std::unique_ptr<ScRange> pNew )
+void ScDocument::SetRepeatRowRange( SCTAB nTab, std::optional<ScRange> oNew )
 {
     if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && 
maTabs[nTab])
-        maTabs[nTab]->SetRepeatRowRange( std::move(pNew) );
+        maTabs[nTab]->SetRepeatRowRange( std::move(oNew) );
 }
 
 std::unique_ptr<ScPrintRangeSaver> ScDocument::CreatePrintRangeSaver() const
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 0b75dcefca2e..4a293f5068de 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -335,8 +335,8 @@ ScTable::~ScTable() COVERITY_NOEXCEPT_FALSE
     pSheetEvents.reset();
     pOutlineTable.reset();
     pSearchText.reset();
-    pRepeatColRange.reset();
-    pRepeatRowRange.reset();
+    moRepeatColRange.reset();
+    moRepeatRowRange.reset();
     pScenarioRanges.reset();
     mpRangeName.reset();
     pDBDataNoName.reset();
@@ -1873,12 +1873,12 @@ void ScTable::UpdateReference(
             }
         }
 
-        if ( pRepeatColRange )
+        if ( moRepeatColRange )
         {
-            nSCol = pRepeatColRange->aStart.Col();
-            nSRow = pRepeatColRange->aStart.Row();
-            nECol = pRepeatColRange->aEnd.Col();
-            nERow = pRepeatColRange->aEnd.Row();
+            nSCol = moRepeatColRange->aStart.Col();
+            nSRow = moRepeatColRange->aStart.Row();
+            nECol = moRepeatColRange->aEnd.Col();
+            nERow = moRepeatColRange->aEnd.Row();
 
             // do not try to modify sheet index of repeat range
             if ( ScRefUpdate::Update( &rDocument, eUpdateRefMode,
@@ -1886,19 +1886,19 @@ void ScTable::UpdateReference(
                                       nDx,nDy,0,
                                       nSCol,nSRow,nSTab, nECol,nERow,nETab ) )
             {
-                *pRepeatColRange = ScRange( nSCol, nSRow, 0, nECol, nERow, 0 );
+                *moRepeatColRange = ScRange( nSCol, nSRow, 0, nECol, nERow, 0 
);
                 bRecalcPages = true;
                 nRepeatStartX = nSCol;  // for UpdatePageBreaks
                 nRepeatEndX = nECol;
             }
         }
 
-        if ( pRepeatRowRange )
+        if ( moRepeatRowRange )
         {
-            nSCol = pRepeatRowRange->aStart.Col();
-            nSRow = pRepeatRowRange->aStart.Row();
-            nECol = pRepeatRowRange->aEnd.Col();
-            nERow = pRepeatRowRange->aEnd.Row();
+            nSCol = moRepeatRowRange->aStart.Col();
+            nSRow = moRepeatRowRange->aStart.Row();
+            nECol = moRepeatRowRange->aEnd.Col();
+            nERow = moRepeatRowRange->aEnd.Row();
 
             // do not try to modify sheet index of repeat range
             if ( ScRefUpdate::Update( &rDocument, eUpdateRefMode,
@@ -1906,7 +1906,7 @@ void ScTable::UpdateReference(
                                       nDx,nDy,0,
                                       nSCol,nSRow,nSTab, nECol,nERow,nETab ) )
             {
-                *pRepeatRowRange = ScRange( nSCol, nSRow, 0, nECol, nERow, 0 );
+                *moRepeatRowRange = ScRange( nSCol, nSRow, 0, nECol, nERow, 0 
);
                 bRecalcPages = true;
                 nRepeatStartY = nSRow;  // for UpdatePageBreaks
                 nRepeatEndY = nERow;
@@ -2252,35 +2252,35 @@ void ScTable::CopyPrintRange(const ScTable& rTable)
 
     bPrintEntireSheet = rTable.bPrintEntireSheet;
 
-    pRepeatColRange.reset();
-    if (rTable.pRepeatColRange)
+    moRepeatColRange.reset();
+    if (rTable.moRepeatColRange)
     {
-        pRepeatColRange.reset(new ScRange(*rTable.pRepeatColRange));
-        pRepeatColRange->aStart.SetTab(nTab);
-        pRepeatColRange->aEnd.SetTab(nTab);
+        moRepeatColRange.emplace(*rTable.moRepeatColRange);
+        moRepeatColRange->aStart.SetTab(nTab);
+        moRepeatColRange->aEnd.SetTab(nTab);
     }
 
-    pRepeatRowRange.reset();
-    if (rTable.pRepeatRowRange)
+    moRepeatRowRange.reset();
+    if (rTable.moRepeatRowRange)
     {
-        pRepeatRowRange.reset(new ScRange(*rTable.pRepeatRowRange));
-        pRepeatRowRange->aStart.SetTab(nTab);
-        pRepeatRowRange->aEnd.SetTab(nTab);
+        moRepeatRowRange.emplace(*rTable.moRepeatRowRange);
+        moRepeatRowRange->aStart.SetTab(nTab);
+        moRepeatRowRange->aEnd.SetTab(nTab);
     }
 }
 
-void ScTable::SetRepeatColRange( std::unique_ptr<ScRange> pNew )
+void ScTable::SetRepeatColRange( std::optional<ScRange> oNew )
 {
-    pRepeatColRange = std::move(pNew);
+    moRepeatColRange = std::move(oNew);
 
     SetStreamValid(false);
 
     InvalidatePageBreaks();
 }
 
-void ScTable::SetRepeatRowRange( std::unique_ptr<ScRange> pNew )
+void ScTable::SetRepeatRowRange( std::optional<ScRange> oNew )
 {
-    pRepeatRowRange = std::move(pNew);
+    moRepeatRowRange = std::move(oNew);
 
     SetStreamValid(false);
 
@@ -2325,17 +2325,15 @@ const ScRange* ScTable::GetPrintRange(sal_uInt16 nPos) 
const
 void ScTable::FillPrintSaver( ScPrintSaverTab& rSaveTab ) const
 {
     rSaveTab.SetAreas( std::vector(aPrintRanges), bPrintEntireSheet );
-    rSaveTab.SetRepeat( pRepeatColRange.get(), pRepeatRowRange.get() );
+    rSaveTab.SetRepeat( moRepeatColRange, moRepeatRowRange );
 }
 
 void ScTable::RestorePrintRanges( const ScPrintSaverTab& rSaveTab )
 {
     aPrintRanges = rSaveTab.GetPrintRanges();
     bPrintEntireSheet = rSaveTab.IsEntireSheet();
-    auto p = rSaveTab.GetRepeatCol();
-    SetRepeatColRange( std::unique_ptr<ScRange>(p ? new ScRange(*p) : nullptr) 
);
-    p = rSaveTab.GetRepeatRow();
-    SetRepeatRowRange( std::unique_ptr<ScRange>(p ? new ScRange(*p) : nullptr) 
);
+    SetRepeatColRange( rSaveTab.GetRepeatCol() );
+    SetRepeatRowRange( rSaveTab.GetRepeatRow() );
 
     InvalidatePageBreaks();     // #i117952# forget page breaks for an old 
print range
     UpdatePageBreaks(nullptr);
diff --git a/sc/source/core/tool/prnsave.cxx b/sc/source/core/tool/prnsave.cxx
index f5700cbd3e08..ff4298e54724 100644
--- a/sc/source/core/tool/prnsave.cxx
+++ b/sc/source/core/tool/prnsave.cxx
@@ -32,8 +32,6 @@ ScPrintSaverTab::ScPrintSaverTab() :
 
 ScPrintSaverTab::~ScPrintSaverTab()
 {
-    mpRepeatCol.reset();
-    mpRepeatRow.reset();
 }
 
 void ScPrintSaverTab::SetAreas( ScRangeVec&& rRanges, bool bEntireSheet )
@@ -42,22 +40,17 @@ void ScPrintSaverTab::SetAreas( ScRangeVec&& rRanges, bool 
bEntireSheet )
     mbEntireSheet = bEntireSheet;
 }
 
-void ScPrintSaverTab::SetRepeat( const ScRange* pCol, const ScRange* pRow )
+void ScPrintSaverTab::SetRepeat( std::optional<ScRange> oCol, 
std::optional<ScRange> oRow )
 {
-    mpRepeatCol.reset(pCol ? new ScRange(*pCol) : nullptr);
-    mpRepeatRow.reset(pRow ? new ScRange(*pRow) : nullptr);
-}
-
-static bool PtrEqual( const ScRange* p1, const ScRange* p2 )
-{
-    return ( !p1 && !p2 ) || ( p1 && p2 && *p1 == *p2 );
+    moRepeatCol = std::move(oCol);
+    moRepeatRow = std::move(oRow);
 }
 
 bool ScPrintSaverTab::operator==( const ScPrintSaverTab& rCmp ) const
 {
     return
-        PtrEqual( mpRepeatCol.get(), rCmp.mpRepeatCol.get() ) &&
-        PtrEqual( mpRepeatRow.get(), rCmp.mpRepeatRow.get() ) &&
+        (moRepeatCol == rCmp.moRepeatCol) &&
+        (moRepeatRow == rCmp.moRepeatRow) &&
         (mbEntireSheet == rCmp.mbEntireSheet) &&
         (maPrintRanges == rCmp.maPrintRanges);
 }
diff --git a/sc/source/filter/excel/impop.cxx b/sc/source/filter/excel/impop.cxx
index 5bfc7a5193bb..9ddc6e6e756e 100644
--- a/sc/source/filter/excel/impop.cxx
+++ b/sc/source/filter/excel/impop.cxx
@@ -1371,13 +1371,13 @@ void ImportExcel::PostDocLoad()
             {
                 if( p->aStart.Col() == 0 && p->aEnd.Col() == rD.MaxCol() && 
bRowVirgin )
                 {
-                    rD.SetRepeatRowRange( n, std::unique_ptr<ScRange>(new 
ScRange(*p)) );
+                    rD.SetRepeatRowRange( n, *p );
                     bRowVirgin = false;
                 }
 
                 if( p->aStart.Row() == 0 && p->aEnd.Row() == rD.MaxRow() && 
bColVirgin )
                 {
-                    rD.SetRepeatColRange( n, std::unique_ptr<ScRange>(new 
ScRange(*p)) );
+                    rD.SetRepeatColRange( n, *p );
                     bColVirgin = false;
                 }
 
diff --git a/sc/source/filter/excel/xename.cxx 
b/sc/source/filter/excel/xename.cxx
index 3b6cc061f627..c8fd0ed37036 100644
--- a/sc/source/filter/excel/xename.cxx
+++ b/sc/source/filter/excel/xename.cxx
@@ -719,15 +719,15 @@ void XclExpNameManagerImpl::CreateBuiltInNames()
 
             ScRangeList aTitleList;
             // repeated columns
-            if( const ScRange* pColRange = rDoc.GetRepeatColRange( nScTab ) )
+            if( std::optional<ScRange> oColRange = rDoc.GetRepeatColRange( 
nScTab ) )
                 aTitleList.push_back( ScRange(
-                    pColRange->aStart.Col(), 0, nScTab,
-                    pColRange->aEnd.Col(), GetXclMaxPos().Row(), nScTab ) );
+                    oColRange->aStart.Col(), 0, nScTab,
+                    oColRange->aEnd.Col(), GetXclMaxPos().Row(), nScTab ) );
             // repeated rows
-            if( const ScRange* pRowRange = rDoc.GetRepeatRowRange( nScTab ) )
+            if( std::optional<ScRange> oRowRange = rDoc.GetRepeatRowRange( 
nScTab ) )
                 aTitleList.push_back( ScRange(
-                    0, pRowRange->aStart.Row(), nScTab,
-                    GetXclMaxPos().Col(), pRowRange->aEnd.Row(), nScTab ) );
+                    0, oRowRange->aStart.Row(), nScTab,
+                    GetXclMaxPos().Col(), oRowRange->aEnd.Row(), nScTab ) );
             // create the NAME record
             GetAddressConverter().ValidateRangeList( aTitleList, false );
             if( !aTitleList.empty() )
diff --git a/sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx 
b/sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx
index 09d8ad605043..e435c37e76a6 100644
--- a/sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx
+++ b/sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx
@@ -777,10 +777,10 @@ uno::Reference< XAccessibleTable > SAL_CALL 
ScAccessibleSpreadsheet::getAccessib
     uno::Reference< XAccessibleTable > xAccessibleTable;
     if( mpDoc && mbIsSpreadsheet )
     {
-        if( const ScRange* pRowRange = mpDoc->GetRepeatRowRange( mnTab ) )
+        if( std::optional<ScRange> oRowRange = mpDoc->GetRepeatRowRange( mnTab 
) )
         {
-            SCROW nStart = pRowRange->aStart.Row();
-            SCROW nEnd = pRowRange->aEnd.Row();
+            SCROW nStart = oRowRange->aStart.Row();
+            SCROW nEnd = oRowRange->aEnd.Row();
             ScDocument* pDoc = GetDocument(mpViewShell);
             if( (0 <= nStart) && (nStart <= nEnd) && (nEnd <= pDoc->MaxRow()) )
                 xAccessibleTable.set( new ScAccessibleSpreadsheet( *this, 
ScRange( 0, nStart, mnTab, pDoc->MaxCol(), nEnd, mnTab ) ) );
@@ -796,10 +796,10 @@ uno::Reference< XAccessibleTable > SAL_CALL 
ScAccessibleSpreadsheet::getAccessib
     uno::Reference< XAccessibleTable > xAccessibleTable;
     if( mpDoc && mbIsSpreadsheet )
     {
-        if( const ScRange* pColRange = mpDoc->GetRepeatColRange( mnTab ) )
+        if( std::optional<ScRange> oColRange = mpDoc->GetRepeatColRange( mnTab 
) )
         {
-            SCCOL nStart = pColRange->aStart.Col();
-            SCCOL nEnd = pColRange->aEnd.Col();
+            SCCOL nStart = oColRange->aStart.Col();
+            SCCOL nEnd = oColRange->aEnd.Col();
             ScDocument* pDoc = GetDocument(mpViewShell);
             if( (0 <= nStart) && (nStart <= nEnd) && (nEnd <= pDoc->MaxCol()) )
                 xAccessibleTable.set( new ScAccessibleSpreadsheet( *this, 
ScRange( nStart, 0, mnTab, nEnd, pDoc->MaxRow(), mnTab ) ) );
diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx
index 480e99be0b84..14f0bc4a4615 100644
--- a/sc/source/ui/docshell/docsh4.cxx
+++ b/sc/source/ui/docshell/docsh4.cxx
@@ -1696,8 +1696,8 @@ bool ScDocShell::AdjustPrintZoom( const ScRange& rRange )
         bool bHeaders = rSet.Get(ATTR_PAGE_HEADERS).GetValue();
         sal_uInt16 nOldScale = rSet.Get(ATTR_PAGE_SCALE).GetValue();
         sal_uInt16 nOldPages = rSet.Get(ATTR_PAGE_SCALETOPAGES).GetValue();
-        const ScRange* pRepeatCol = m_pDocument->GetRepeatColRange( nTab );
-        const ScRange* pRepeatRow = m_pDocument->GetRepeatRowRange( nTab );
+        std::optional<ScRange> oRepeatCol = m_pDocument->GetRepeatColRange( 
nTab );
+        std::optional<ScRange> oRepeatRow = m_pDocument->GetRepeatRowRange( 
nTab );
 
         //  calculate needed scaling for selection
 
@@ -1708,12 +1708,12 @@ bool ScDocShell::AdjustPrintZoom( const ScRange& rRange 
)
             nBlkTwipsX += PRINT_HEADER_WIDTH;
         SCCOL nStartCol = rRange.aStart.Col();
         SCCOL nEndCol = rRange.aEnd.Col();
-        if ( pRepeatCol && nStartCol >= pRepeatCol->aStart.Col() )
+        if ( oRepeatCol && nStartCol >= oRepeatCol->aStart.Col() )
         {
-            for (SCCOL i=pRepeatCol->aStart.Col(); i<=pRepeatCol->aEnd.Col(); 
i++ )
+            for (SCCOL i=oRepeatCol->aStart.Col(); i<=oRepeatCol->aEnd.Col(); 
i++ )
                 nBlkTwipsX += m_pDocument->GetColWidth( i, nTab );
-            if ( nStartCol <= pRepeatCol->aEnd.Col() )
-                nStartCol = pRepeatCol->aEnd.Col() + 1;
+            if ( nStartCol <= oRepeatCol->aEnd.Col() )
+                nStartCol = oRepeatCol->aEnd.Col() + 1;
         }
         // legacy compilers' own scope for i
         {
@@ -1726,12 +1726,12 @@ bool ScDocShell::AdjustPrintZoom( const ScRange& rRange 
)
             nBlkTwipsY += PRINT_HEADER_HEIGHT;
         SCROW nStartRow = rRange.aStart.Row();
         SCROW nEndRow = rRange.aEnd.Row();
-        if ( pRepeatRow && nStartRow >= pRepeatRow->aStart.Row() )
+        if ( oRepeatRow && nStartRow >= oRepeatRow->aStart.Row() )
         {
-            nBlkTwipsY += m_pDocument->GetRowHeight( pRepeatRow->aStart.Row(),
-                    pRepeatRow->aEnd.Row(), nTab );
-            if ( nStartRow <= pRepeatRow->aEnd.Row() )
-                nStartRow = pRepeatRow->aEnd.Row() + 1;
+            nBlkTwipsY += m_pDocument->GetRowHeight( oRepeatRow->aStart.Row(),
+                    oRepeatRow->aEnd.Row(), nTab );
+            if ( nStartRow <= oRepeatRow->aEnd.Row() )
+                nStartRow = oRepeatRow->aEnd.Row() + 1;
         }
         nBlkTwipsY += m_pDocument->GetRowHeight( nStartRow, nEndRow, nTab );
 
diff --git a/sc/source/ui/pagedlg/areasdlg.cxx 
b/sc/source/ui/pagedlg/areasdlg.cxx
index 10d82641c157..51533dbf2e01 100644
--- a/sc/source/ui/pagedlg/areasdlg.cxx
+++ b/sc/source/ui/pagedlg/areasdlg.cxx
@@ -63,7 +63,7 @@ namespace
 // global functions (->at the end of the file):
 
 static bool lcl_CheckRepeatString( const OUString& rStr, const ScDocument& 
rDoc, bool bIsRow, ScRange* pRange );
-static void lcl_GetRepeatRangeString( const ScRange* pRange, const ScDocument& 
rDoc, bool bIsRow, OUString& rStr );
+static void lcl_GetRepeatRangeString( std::optional<ScRange> oRange, const 
ScDocument& rDoc, bool bIsRow, OUString& rStr );
 
 #if 0
 // this method is useful when debugging address flags.
@@ -187,7 +187,7 @@ void ScPrintAreasDlg::SetReference( const ScRange& rRef, 
ScDocument& /* rDoc */
     else
     {
         bool bRow = ( m_xEdRepeatRow.get() == m_pRefInputEdit );
-        lcl_GetRepeatRangeString(&rRef, *pDoc, bRow, aStr);
+        lcl_GetRepeatRangeString(rRef, *pDoc, bRow, aStr);
         m_pRefInputEdit->SetRefString( aStr );
     }
     Impl_ModifyHdl( *m_pRefInputEdit );
@@ -234,8 +234,8 @@ void ScPrintAreasDlg::SetActive()
 void ScPrintAreasDlg::Impl_Reset()
 {
     OUString        aStrRange;
-    const ScRange*  pRepeatColRange = pDoc->GetRepeatColRange( nCurTab );
-    const ScRange*  pRepeatRowRange = pDoc->GetRepeatRowRange( nCurTab );
+    std::optional<ScRange> oRepeatColRange = pDoc->GetRepeatColRange( nCurTab 
);
+    std::optional<ScRange> oRepeatRowRange = pDoc->GetRepeatRowRange( nCurTab 
);
 
     m_xEdPrintArea->SetModifyHdl   (LINK( this, ScPrintAreasDlg, 
Impl_ModifyHdl));
     m_xEdRepeatRow->SetModifyHdl   (LINK( this, ScPrintAreasDlg, 
Impl_ModifyHdl));
@@ -274,12 +274,12 @@ void ScPrintAreasDlg::Impl_Reset()
 
     // repeat row
 
-    lcl_GetRepeatRangeString(pRepeatRowRange, *pDoc, true, aStrRange);
+    lcl_GetRepeatRangeString(oRepeatRowRange, *pDoc, true, aStrRange);
     m_xEdRepeatRow->SetText( aStrRange );
 
     // repeat column
 
-    lcl_GetRepeatRangeString(pRepeatColRange, *pDoc, false, aStrRange);
+    lcl_GetRepeatRangeString(oRepeatColRange, *pDoc, false, aStrRange);
     m_xEdRepeatCol->SetText( aStrRange );
 
     Impl_ModifyHdl( *m_xEdPrintArea );
@@ -427,13 +427,13 @@ void ScPrintAreasDlg::Impl_FillLists()
 
             if (rEntry.second->HasType(ScRangeData::Type::RowHeader))
             {
-                lcl_GetRepeatRangeString(&aRange, *pDoc, true, aSymbol);
+                lcl_GetRepeatRangeString(aRange, *pDoc, true, aSymbol);
                 m_xLbRepeatRow->append(aSymbol, aName);
             }
 
             if (rEntry.second->HasType(ScRangeData::Type::ColHeader))
             {
-                lcl_GetRepeatRangeString(&aRange, *pDoc, false, aSymbol);
+                lcl_GetRepeatRangeString(aRange, *pDoc, false, aSymbol);
                 m_xLbRepeatCol->append(aSymbol, aName);
             }
         }
@@ -762,15 +762,15 @@ static bool lcl_CheckRepeatString( const OUString& rStr, 
const ScDocument& rDoc,
     return true;
 }
 
-static void lcl_GetRepeatRangeString( const ScRange* pRange, const ScDocument& 
rDoc, bool bIsRow, OUString& rStr )
+static void lcl_GetRepeatRangeString( std::optional<ScRange> oRange, const 
ScDocument& rDoc, bool bIsRow, OUString& rStr )
 {
     rStr.clear();
-    if (!pRange)
+    if (!oRange)
         return;
 
     const formula::FormulaGrammar::AddressConvention eConv = 
rDoc.GetAddressConvention();
-    const ScAddress& rStart = pRange->aStart;
-    const ScAddress& rEnd   = pRange->aEnd;
+    const ScAddress& rStart = oRange->aStart;
+    const ScAddress& rEnd   = oRange->aEnd;
 
     const ScRefFlags nFmt = bIsRow
                             ? (ScRefFlags::ROW_VALID | ScRefFlags::ROW_ABS)
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index c2ef70015d1f..529830d6f510 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -7083,7 +7083,7 @@ sal_Bool SAL_CALL ScTableSheetObj::getPrintTitleColumns()
     {
         ScDocument& rDoc = pDocSh->GetDocument();
         SCTAB nTab = GetTab_Impl();
-        return ( rDoc.GetRepeatColRange(nTab) != nullptr );
+        return rDoc.GetRepeatColRange(nTab).has_value();
     }
     return false;
 }
@@ -7104,11 +7104,11 @@ void SAL_CALL ScTableSheetObj::setPrintTitleColumns( 
sal_Bool bPrintTitleColumns
     {
         if ( !rDoc.GetRepeatColRange( nTab ) )         // do not change 
existing area
         {
-            rDoc.SetRepeatColRange( nTab, std::unique_ptr<ScRange>(new 
ScRange( 0, 0, nTab, 0, 0, nTab )) );     // enable
+            rDoc.SetRepeatColRange( nTab, ScRange( 0, 0, nTab, 0, 0, nTab ) ); 
    // enable
         }
     }
     else
-        rDoc.SetRepeatColRange( nTab, nullptr );          // disable
+        rDoc.SetRepeatColRange( nTab, std::nullopt );          // disable
 
     PrintAreaUndo_Impl( std::move(pOldRanges) );   // undo, page break, 
modified etc.
 
@@ -7124,10 +7124,10 @@ table::CellRangeAddress SAL_CALL 
ScTableSheetObj::getTitleColumns()
     {
         ScDocument& rDoc = pDocSh->GetDocument();
         SCTAB nTab = GetTab_Impl();
-        const ScRange* pRange = rDoc.GetRepeatColRange(nTab);
-        if (pRange)
+        std::optional<ScRange> oRange = rDoc.GetRepeatColRange(nTab);
+        if (oRange)
         {
-            ScUnoConversion::FillApiRange( aRet, *pRange );
+            ScUnoConversion::FillApiRange( aRet, *oRange );
             aRet.Sheet = nTab; // core does not care about sheet index
         }
     }
@@ -7146,9 +7146,9 @@ void SAL_CALL ScTableSheetObj::setTitleColumns( const 
table::CellRangeAddress& a
 
     std::unique_ptr<ScPrintRangeSaver> pOldRanges = 
rDoc.CreatePrintRangeSaver();
 
-    std::unique_ptr<ScRange> pNew(new ScRange);
-    ScUnoConversion::FillScRange( *pNew, aTitleColumns );
-    rDoc.SetRepeatColRange( nTab, std::move(pNew) );     // also always enable
+    ScRange aNew;
+    ScUnoConversion::FillScRange( aNew, aTitleColumns );
+    rDoc.SetRepeatColRange( nTab, std::move(aNew) );     // also always enable
 
     PrintAreaUndo_Impl( std::move(pOldRanges) );           // undo, page 
breaks, modified etc.
 }
@@ -7161,7 +7161,7 @@ sal_Bool SAL_CALL ScTableSheetObj::getPrintTitleRows()
     {
         ScDocument& rDoc = pDocSh->GetDocument();
         SCTAB nTab = GetTab_Impl();
-        return ( rDoc.GetRepeatRowRange(nTab) != nullptr );
+        return rDoc.GetRepeatRowRange(nTab).has_value();
     }
     return false;
 }
@@ -7182,12 +7182,11 @@ void SAL_CALL ScTableSheetObj::setPrintTitleRows( 
sal_Bool bPrintTitleRows )
     {
         if ( !rDoc.GetRepeatRowRange( nTab ) )         // do not change 
existing area
         {
-            std::unique_ptr<ScRange> pNew( new ScRange(0, 0, nTab, 0, 0, nTab) 
);
-            rDoc.SetRepeatRowRange( nTab, std::move(pNew) );     // enable
+            rDoc.SetRepeatRowRange( nTab, ScRange(0, 0, nTab, 0, 0, nTab) );   
  // enable
         }
     }
     else
-        rDoc.SetRepeatRowRange( nTab, nullptr );          // disable
+        rDoc.SetRepeatRowRange( nTab, std::nullopt );          // disable
 
     PrintAreaUndo_Impl( std::move(pOldRanges) );   // undo, page breaks, 
modified etc.
 
@@ -7203,10 +7202,10 @@ table::CellRangeAddress SAL_CALL 
ScTableSheetObj::getTitleRows()
     {
         ScDocument& rDoc = pDocSh->GetDocument();
         SCTAB nTab = GetTab_Impl();
-        const ScRange* pRange = rDoc.GetRepeatRowRange(nTab);
-        if (pRange)
+        std::optional<ScRange> oRange = rDoc.GetRepeatRowRange(nTab);
+        if (oRange)
         {
-            ScUnoConversion::FillApiRange( aRet, *pRange );
+            ScUnoConversion::FillApiRange( aRet, *oRange );
             aRet.Sheet = nTab; // core does not care about sheet index
         }
     }
@@ -7225,9 +7224,9 @@ void SAL_CALL ScTableSheetObj::setTitleRows( const 
table::CellRangeAddress& aTit
 
     std::unique_ptr<ScPrintRangeSaver> pOldRanges = 
rDoc.CreatePrintRangeSaver();
 
-    std::unique_ptr<ScRange> pNew(new ScRange);
-    ScUnoConversion::FillScRange( *pNew, aTitleRows );
-    rDoc.SetRepeatRowRange( nTab, std::move(pNew) );     // also always enable
+    ScRange aNew;
+    ScUnoConversion::FillScRange( aNew, aTitleRows );
+    rDoc.SetRepeatRowRange( nTab, std::move(aNew) );     // also always enable
 
     PrintAreaUndo_Impl( std::move(pOldRanges) );           // Undo, page 
breaks, modified etc.
 }
diff --git a/sc/source/ui/view/printfun.cxx b/sc/source/ui/view/printfun.cxx
index 92e593a9dcca..d5f1d8634865 100644
--- a/sc/source/ui/view/printfun.cxx
+++ b/sc/source/ui/view/printfun.cxx
@@ -1001,8 +1001,8 @@ void ScPrintFunc::InitParam( const ScPrintOptions* 
pOptions )
 
     //! walk through all PrintAreas of the table !!!
     const ScRange*  pPrintArea = rDoc.GetPrintRange( nPrintTab, 0 );
-    const ScRange*  pRepeatCol = rDoc.GetRepeatColRange( nPrintTab );
-    const ScRange*  pRepeatRow = rDoc.GetRepeatRowRange( nPrintTab );
+    std::optional<ScRange> oRepeatCol = rDoc.GetRepeatColRange( nPrintTab );
+    std::optional<ScRange> oRepeatRow = rDoc.GetRepeatRowRange( nPrintTab );
 
     //  ignoring ATTR_PAGE_PRINTTABLES
 
@@ -1055,11 +1055,11 @@ void ScPrintFunc::InitParam( const ScPrintOptions* 
pOptions )
         }
     }
 
-    if ( pRepeatCol )
+    if ( oRepeatCol )
     {
         aAreaParam.bRepeatCol = true;
-        nRepeatStartCol = pRepeatCol->aStart.Col();
-        nRepeatEndCol   = pRepeatCol->aEnd  .Col();
+        nRepeatStartCol = oRepeatCol->aStart.Col();
+        nRepeatEndCol   = oRepeatCol->aEnd  .Col();
     }
     else
     {
@@ -1067,11 +1067,11 @@ void ScPrintFunc::InitParam( const ScPrintOptions* 
pOptions )
         nRepeatStartCol = nRepeatEndCol = SCCOL_REPEAT_NONE;
     }
 
-    if ( pRepeatRow )
+    if ( oRepeatRow )
     {
         aAreaParam.bRepeatRow = true;
-        nRepeatStartRow = pRepeatRow->aStart.Row();
-        nRepeatEndRow   = pRepeatRow->aEnd  .Row();
+        nRepeatStartRow = oRepeatRow->aStart.Row();
+        nRepeatEndRow   = oRepeatRow->aEnd  .Row();
     }
     else
     {
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index c1f301fd0ea2..0327a94ca249 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -1109,10 +1109,10 @@ void ScViewFunc::SetPrintRanges( bool bEntireSheet, 
const OUString* pPrint,
         if ( pRepCol )
         {
             if ( pRepCol->isEmpty() )
-                rDoc.SetRepeatColRange( nTab, nullptr );
+                rDoc.SetRepeatColRange( nTab, std::nullopt );
             else
                 if ( aRange.ParseAny( *pRepCol, rDoc, aDetails ) & 
ScRefFlags::VALID )
-                    rDoc.SetRepeatColRange( nTab, std::unique_ptr<ScRange>(new 
ScRange(aRange)) );
+                    rDoc.SetRepeatColRange( nTab, aRange );
         }
 
         //  repeat rows
@@ -1120,10 +1120,10 @@ void ScViewFunc::SetPrintRanges( bool bEntireSheet, 
const OUString* pPrint,
         if ( pRepRow )
         {
             if ( pRepRow->isEmpty() )
-                rDoc.SetRepeatRowRange( nTab, nullptr );
+                rDoc.SetRepeatRowRange( nTab, std::nullopt );
             else
                 if ( aRange.ParseAny( *pRepRow, rDoc, aDetails ) & 
ScRefFlags::VALID )
-                    rDoc.SetRepeatRowRange( nTab, std::unique_ptr<ScRange>(new 
ScRange(aRange)) );
+                    rDoc.SetRepeatRowRange( nTab, aRange );
         }
     }
 

Reply via email to