sc/inc/colorscale.hxx                          |   22 +--
 sc/inc/conditio.hxx                            |   24 +--
 sc/inc/dbdata.hxx                              |    2 
 sc/inc/detdata.hxx                             |    2 
 sc/inc/fmtuno.hxx                              |    2 
 sc/inc/rangelst.hxx                            |    4 
 sc/inc/validat.hxx                             |    6 
 sc/qa/unit/subsequent_export_test.cxx          |    2 
 sc/qa/unit/ucalc_condformat.cxx                |   98 +++++++-------
 sc/qa/unit/ucalc_rangelst.cxx                  |   12 -
 sc/source/core/data/bcaslot.cxx                |   50 +++----
 sc/source/core/data/colorscale.cxx             |   64 ++++-----
 sc/source/core/data/conditio.cxx               |  164 ++++++++++++-------------
 sc/source/core/data/documen2.cxx               |   14 +-
 sc/source/core/data/documen3.cxx               |    8 -
 sc/source/core/data/documen4.cxx               |    2 
 sc/source/core/data/documen5.cxx               |    2 
 sc/source/core/data/documen8.cxx               |    2 
 sc/source/core/data/document.cxx               |   24 +--
 sc/source/core/data/dpobject.cxx               |    6 
 sc/source/core/data/table1.cxx                 |    6 
 sc/source/core/data/tabprotection.cxx          |    2 
 sc/source/core/data/validat.cxx                |   96 +++++++-------
 sc/source/core/inc/bcaslot.hxx                 |    8 -
 sc/source/core/inc/refupdat.hxx                |    2 
 sc/source/core/tool/dbdata.cxx                 |   12 -
 sc/source/core/tool/detdata.cxx                |    4 
 sc/source/core/tool/rangelst.cxx               |    8 -
 sc/source/core/tool/refupdat.cxx               |   40 +++---
 sc/source/filter/excel/xicontent.cxx           |    2 
 sc/source/filter/inc/condformatbuffer.hxx      |    6 
 sc/source/filter/oox/condformatbuffer.cxx      |   56 ++++----
 sc/source/filter/oox/extlstcontext.cxx         |    6 
 sc/source/filter/orcus/interface.cxx           |    4 
 sc/source/filter/xml/xmlcondformat.cxx         |   10 -
 sc/source/filter/xml/xmlstyli.cxx              |    2 
 sc/source/ui/condformat/condformatdlg.cxx      |    2 
 sc/source/ui/condformat/condformatdlgentry.cxx |   10 -
 sc/source/ui/condformat/condformateasydlg.cxx  |    2 
 sc/source/ui/unoobj/cellsuno.cxx               |   14 +-
 sc/source/ui/unoobj/chart2uno.cxx              |    2 
 sc/source/ui/unoobj/condformatuno.cxx          |   10 -
 sc/source/ui/unoobj/dapiuno.cxx                |    2 
 sc/source/ui/unoobj/fmtuno.cxx                 |    8 -
 sc/source/ui/view/cellsh1.cxx                  |    8 -
 45 files changed, 415 insertions(+), 417 deletions(-)

New commits:
commit 8e1c8353d61e85e867eabcfa18813abbc7d6352a
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Thu May 15 13:47:45 2025 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Fri May 16 17:19:21 2025 +0200

    ScConditionalFormat: pass ScDocument by ref
    
    and in other related places
    
    Change-Id: Ic4fd970c0f91f246893013f0751376043dd809f2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185361
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Tested-by: Jenkins

diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx
index 55b1f10cb8a8..52425a8d0658 100644
--- a/sc/inc/colorscale.hxx
+++ b/sc/inc/colorscale.hxx
@@ -58,7 +58,7 @@ public:
                                    ScConditionMode eMode = 
ScConditionMode::EqGreater);
     SC_DLLPUBLIC ScColorScaleEntry();
     ScColorScaleEntry(const ScColorScaleEntry& rEntry);
-    ScColorScaleEntry(ScDocument* pDoc, const ScColorScaleEntry& rEntry);
+    ScColorScaleEntry(ScDocument& rDoc, const ScColorScaleEntry& rEntry);
     SC_DLLPUBLIC ~ScColorScaleEntry() COVERITY_NOEXCEPT_FALSE;
 
     const Color& GetColor() const { return maColor;}
@@ -225,7 +225,7 @@ struct ScIconSetMap {
 class SAL_DLLPUBLIC_RTTI ScColorFormat : public ScFormatEntry
 {
 public:
-    ScColorFormat(ScDocument* pDoc);
+    ScColorFormat(ScDocument& rDoc);
     SC_DLLPUBLIC virtual ~ScColorFormat() override;
 
     SC_DLLPUBLIC const ScRangeList& GetRange() const;
@@ -260,13 +260,13 @@ private:
     void calcMinMax(double& nMin, double& nMax) const;
     double CalcValue(double nMin, double nMax, const 
ScColorScaleEntries::const_iterator& rItr) const;
 public:
-    SC_DLLPUBLIC ScColorScaleFormat(ScDocument* pDoc);
-    ScColorScaleFormat(ScDocument* pDoc, const ScColorScaleFormat& rFormat);
+    SC_DLLPUBLIC ScColorScaleFormat(ScDocument& rDoc);
+    ScColorScaleFormat(ScDocument& rDoc, const ScColorScaleFormat& rFormat);
     ScColorScaleFormat(const ScColorScaleFormat&) = delete;
     virtual ~ScColorScaleFormat() override;
     const ScColorScaleFormat& operator=(const ScColorScaleFormat&) = delete;
 
-    virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
+    virtual ScColorFormat* Clone(ScDocument& rDoc) const override;
 
     virtual void SetParent(ScConditionalFormat* pParent) override;
 
@@ -301,9 +301,9 @@ public:
 class SAL_DLLPUBLIC_RTTI ScDataBarFormat final : public ScColorFormat
 {
 public:
-    SC_DLLPUBLIC ScDataBarFormat(ScDocument* pDoc);
-    ScDataBarFormat(ScDocument* pDoc, const ScDataBarFormat& rFormat);
-    virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
+    SC_DLLPUBLIC ScDataBarFormat(ScDocument& rDoc);
+    ScDataBarFormat(ScDocument& rDoc, const ScDataBarFormat& rFormat);
+    virtual ScColorFormat* Clone(ScDocument& rDoc) const override;
 
     virtual void SetParent(ScConditionalFormat* pParent) override;
 
@@ -364,10 +364,10 @@ struct ScIconSetFormatData
 class SAL_DLLPUBLIC_RTTI ScIconSetFormat final : public ScColorFormat
 {
 public:
-    SC_DLLPUBLIC ScIconSetFormat(ScDocument* pDoc);
-    ScIconSetFormat(ScDocument* pDoc, const ScIconSetFormat& rFormat);
+    SC_DLLPUBLIC ScIconSetFormat(ScDocument& rDoc);
+    ScIconSetFormat(ScDocument& rDoc, const ScIconSetFormat& rFormat);
 
-    virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
+    virtual ScColorFormat* Clone(ScDocument& rDoc) const override;
 
     virtual void SetParent(ScConditionalFormat* pParent) override;
 
diff --git a/sc/inc/conditio.hxx b/sc/inc/conditio.hxx
index abcf24b00933..bf705f63154f 100644
--- a/sc/inc/conditio.hxx
+++ b/sc/inc/conditio.hxx
@@ -225,7 +225,7 @@ struct SC_DLLPUBLIC ScCondFormatData
 class SC_DLLPUBLIC ScFormatEntry
 {
 public:
-    ScFormatEntry(ScDocument* pDoc);
+    ScFormatEntry(ScDocument& rDoc);
     virtual ~ScFormatEntry() {}
 
     enum class Type
@@ -244,7 +244,7 @@ public:
     virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) = 0;
     virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt ) = 0;
 
-    virtual ScFormatEntry* Clone( ScDocument* pDoc ) const = 0;
+    virtual ScFormatEntry* Clone( ScDocument& rDoc ) const = 0;
 
     virtual void SetParent( ScConditionalFormat* pNew ) = 0;
 
@@ -255,7 +255,7 @@ public:
     virtual void endRendering();
     virtual void updateValues();
 protected:
-    ScDocument* mpDoc;
+    ScDocument& mrDoc;
 
 };
 
@@ -405,7 +405,7 @@ public:
 
     virtual Type GetType() const override { return eConditionType; }
 
-    virtual ScFormatEntry* Clone(ScDocument* pDoc) const override;
+    virtual ScFormatEntry* Clone(ScDocument& rDoc) const override;
 
     static ScConditionMode GetModeFromApi(css::sheet::ConditionOperator 
nOperator);
 
@@ -417,7 +417,7 @@ public:
 
 protected:
     virtual void    DataChanged() const;
-    ScDocument*     GetDocument() const     { return mpDoc; }
+    ScDocument&     GetDocument() const     { return mrDoc; }
     ScConditionalFormat*    pCondFormat;
 
 private:
@@ -481,7 +481,7 @@ public:
 
     const OUString&   GetStyle() const        { return aStyleName; }
     void            UpdateStyleName(const OUString& rNew)  { aStyleName=rNew; }
-    virtual ScFormatEntry* Clone(ScDocument* pDoc) const override;
+    virtual ScFormatEntry* Clone(ScDocument& rDoc) const override;
     virtual Type GetType() const override { return eCondFormatType; }
 
 private:
@@ -512,8 +512,8 @@ enum ScCondFormatDateType
 class SC_DLLPUBLIC ScCondDateFormatEntry final : public ScFormatEntry
 {
 public:
-    ScCondDateFormatEntry(ScDocument* pDoc);
-    ScCondDateFormatEntry(ScDocument* pDoc, const ScCondDateFormatEntry& 
rEntry);
+    ScCondDateFormatEntry(ScDocument& rDoc);
+    ScCondDateFormatEntry(ScDocument& rDoc, const ScCondDateFormatEntry& 
rEntry);
 
     bool IsValid( const ScAddress& rPos ) const;
 
@@ -529,7 +529,7 @@ public:
     virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& ) override {}
     virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& ) override {}
 
-    virtual ScFormatEntry* Clone( ScDocument* pDoc ) const override;
+    virtual ScFormatEntry* Clone( ScDocument& rDoc ) const override;
 
     virtual void SetParent( ScConditionalFormat* ) override {}
 
@@ -561,7 +561,7 @@ public:
 //  complete conditional formatting
 class ScConditionalFormat
 {
-    ScDocument*         mpDoc;
+    ScDocument&         mrDoc;
     sal_uInt32          mnKey;               // Index in attributes
 
     std::vector<std::unique_ptr<ScFormatEntry>> maEntries;
@@ -570,7 +570,7 @@ class ScConditionalFormat
     mutable std::unique_ptr<ScColorFormatCache> mpCache;
 
 public:
-    SC_DLLPUBLIC ScConditionalFormat(sal_uInt32 nNewKey, ScDocument* 
pDocument);
+    SC_DLLPUBLIC ScConditionalFormat(sal_uInt32 nNewKey, ScDocument& 
rDocument);
     SC_DLLPUBLIC ~ScConditionalFormat();
      ScConditionalFormat(const ScConditionalFormat&) = delete;
      const ScConditionalFormat& operator=(const ScConditionalFormat&) = delete;
@@ -588,7 +588,7 @@ public:
     bool IsEmpty() const;
     SC_DLLPUBLIC size_t size() const;
 
-    ScDocument* GetDocument();
+    ScDocument& GetDocument();
 
     void            CompileAll();
     void            CompileXML();
diff --git a/sc/inc/dbdata.hxx b/sc/inc/dbdata.hxx
index be6d193f7d54..11cc5465f91f 100644
--- a/sc/inc/dbdata.hxx
+++ b/sc/inc/dbdata.hxx
@@ -216,7 +216,7 @@ public:
     void        SetModified(bool bMod)      { bModified = bMod; }
 
     void    UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
-    bool    UpdateReference(const ScDocument* pDoc, UpdateRefMode 
eUpdateRefMode, SCCOL nCol1,
+    bool    UpdateReference(const ScDocument& rDoc, UpdateRefMode 
eUpdateRefMode, SCCOL nCol1,
                             SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW 
nRow2, SCTAB nTab2,
                             SCCOL nDx, SCROW nDy, SCTAB nDz);
 
diff --git a/sc/inc/detdata.hxx b/sc/inc/detdata.hxx
index d9eeea6ad996..40809f9f56fe 100644
--- a/sc/inc/detdata.hxx
+++ b/sc/inc/detdata.hxx
@@ -65,7 +65,7 @@ public:
         ScDetOpList(const ScDetOpList& rList);
 
     void    DeleteOnTab( SCTAB nTab );
-    void    UpdateReference( const ScDocument* pDoc, UpdateRefMode 
eUpdateRefMode,
+    void    UpdateReference( const ScDocument& rDoc, UpdateRefMode 
eUpdateRefMode,
                              const ScRange& rRange, SCCOL nDx, SCROW nDy, 
SCTAB nDz );
 
     bool        operator==( const ScDetOpList& r ) const;       // for ref-undo
diff --git a/sc/inc/fmtuno.hxx b/sc/inc/fmtuno.hxx
index 91e3b66db020..5e7cefbd3f17 100644
--- a/sc/inc/fmtuno.hxx
+++ b/sc/inc/fmtuno.hxx
@@ -75,7 +75,7 @@ private:
     void                        AddEntry_Impl(const ScCondFormatEntryItem& 
aEntry);
 public:
                             ScTableConditionalFormat() = delete;
-                            ScTableConditionalFormat(const ScDocument* pDoc, 
sal_uLong nKey,
+                            ScTableConditionalFormat(const ScDocument& rDoc, 
sal_uLong nKey,
                                     SCTAB nTab, 
formula::FormulaGrammar::Grammar eGrammar);
     virtual                 ~ScTableConditionalFormat() override;
 
diff --git a/sc/inc/rangelst.hxx b/sc/inc/rangelst.hxx
index f1618b06c9d9..f1d33eb63024 100644
--- a/sc/inc/rangelst.hxx
+++ b/sc/inc/rangelst.hxx
@@ -51,7 +51,7 @@ public:
 
     void            Join( const ScRange&, bool bIsInList = false );
 
-    bool            UpdateReference( UpdateRefMode, const ScDocument*,
+    bool            UpdateReference( UpdateRefMode, const ScDocument&,
                                      const ScRange& rWhere,
                                      SCCOL nDx,
                                      SCROW nDy,
@@ -139,7 +139,7 @@ public:
                             maPairs.push_back( rRangePair );
                         }
     void                Join( const ScRangePair&, bool bIsInList = false );
-    void                UpdateReference( UpdateRefMode, const ScDocument*,
+    void                UpdateReference( UpdateRefMode, const ScDocument&,
                                     const ScRange& rWhere,
                                     SCCOL nDx, SCROW nDy, SCTAB nDz );
     void                DeleteOnTab( SCTAB nTab );
diff --git a/sc/inc/validat.hxx b/sc/inc/validat.hxx
index 8316ec64ae52..b79b294643c9 100644
--- a/sc/inc/validat.hxx
+++ b/sc/inc/validat.hxx
@@ -99,9 +99,9 @@ public:
     SC_DLLPUBLIC virtual ~ScValidationData() override;
 
     ScValidationData* Clone() const     // real copy
-                    { return new ScValidationData( *GetDocument(), *this ); }
-    ScValidationData* Clone(ScDocument* pNew) const override
-                    { return new ScValidationData( *pNew, *this ); }
+                    { return new ScValidationData( GetDocument(), *this ); }
+    ScValidationData* Clone(ScDocument& rNew) const override
+                    { return new ScValidationData( rNew, *this ); }
 
     SC_DLLPUBLIC void ResetInput();
     SC_DLLPUBLIC void ResetError();
diff --git a/sc/qa/unit/subsequent_export_test.cxx 
b/sc/qa/unit/subsequent_export_test.cxx
index 98151610a2c7..f40511673b80 100644
--- a/sc/qa/unit/subsequent_export_test.cxx
+++ b/sc/qa/unit/subsequent_export_test.cxx
@@ -2118,7 +2118,7 @@ CPPUNIT_TEST_FIXTURE(ScExportTest, 
testConditionalFormatNumberInTextRule)
     ScDocument* pDocument = getScDoc();
     ScAddress aAddress(0, 0, 0);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(0, pDocument);
+    auto pFormat = std::make_unique<ScConditionalFormat>(0, *pDocument);
     ScRange aCondFormatRange(aAddress);
     ScRangeList aRangeList(aCondFormatRange);
     pFormat->SetRange(aRangeList);
diff --git a/sc/qa/unit/ucalc_condformat.cxx b/sc/qa/unit/ucalc_condformat.cxx
index 7b077ba5d1ed..e470fe8f5400 100644
--- a/sc/qa/unit/ucalc_condformat.cxx
+++ b/sc/qa/unit/ucalc_condformat.cxx
@@ -49,18 +49,18 @@ struct ScDataBarLengthData
     double nLength;
 };
 
-void testDataBarLengthImpl(ScDocument* pDoc, const ScDataBarLengthData* pData, 
const ScRange& rRange,
+void testDataBarLengthImpl(ScDocument& rDoc, const ScDataBarLengthData* pData, 
const ScRange& rRange,
         double nMinVal, ScColorScaleEntryType eMinType,
         double nMaxVal, ScColorScaleEntryType eMaxType,
         double nZeroPos, databar::ScAxisPosition eAxisPos)
 {
-    std::unique_ptr<ScConditionalFormat> pFormat(new ScConditionalFormat(1, 
pDoc));
+    std::unique_ptr<ScConditionalFormat> pFormat(new ScConditionalFormat(1, 
rDoc));
     ScRangeList aRangeList(rRange);
     pFormat->SetRange(aRangeList);
 
     SCCOL nCol = rRange.aStart.Col();
 
-    ScDataBarFormat* pDatabar = new ScDataBarFormat(pDoc);
+    ScDataBarFormat* pDatabar = new ScDataBarFormat(rDoc);
     pFormat->AddEntry(pDatabar);
 
     ScDataBarFormatData* pFormatData = new ScDataBarFormatData();
@@ -76,7 +76,7 @@ void testDataBarLengthImpl(ScDocument* pDoc, const 
ScDataBarLengthData* pData, c
 
     for (size_t i = 0; pData[i].nLength != -200; ++i)
     {
-        pDoc->SetValue(nCol, i, 0, pData[i].nVal);
+        rDoc.SetValue(nCol, i, 0, pData[i].nVal);
     }
 
     for (size_t i = 0; pData[i].nLength != -200; ++i)
@@ -88,17 +88,17 @@ void testDataBarLengthImpl(ScDocument* pDoc, const 
ScDataBarLengthData* pData, c
     }
 }
 
-sal_uInt32 addSingleCellCondFormat(ScDocument* pDoc, const ScAddress& rAddr, 
sal_uInt32 nKey, const OUString& rCondition)
+sal_uInt32 addSingleCellCondFormat(ScDocument& rDoc, const ScAddress& rAddr, 
sal_uInt32 nKey, const OUString& rCondition)
 {
-    auto pFormat = std::make_unique<ScConditionalFormat>(nKey, pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(nKey, rDoc);
     ScRange aCondFormatRange(rAddr);
     ScRangeList aRangeList(aCondFormatRange);
     pFormat->SetRange(aRangeList);
 
     ScCondFormatEntry* pEntry = new ScCondFormatEntry(ScConditionMode::Direct, 
rCondition, u""_ustr,
-            *pDoc, ScAddress(0,0,0), ScResId(STR_STYLENAME_RESULT));
+            rDoc, ScAddress(0,0,0), ScResId(STR_STYLENAME_RESULT));
     pFormat->AddEntry(pEntry);
-    return pDoc->AddCondFormat(std::move(pFormat), 0);
+    return rDoc.AddCondFormat(std::move(pFormat), 0);
 }
 
 }
@@ -113,7 +113,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, testCondFormatINSDEL)
     m_pDoc->InsertTab(0, u"Test"_ustr);
     ScConditionalFormatList* pList = m_pDoc->GetCondFormList(0);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(1, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(1, *m_pDoc);
     ScRangeList aRangeList(ScRange(0,0,0,0,3,0));
     pFormat->SetRange(aRangeList);
     ScCondFormatEntry* pEntry = new 
ScCondFormatEntry(ScConditionMode::Direct,u"=B2"_ustr,u""_ustr,*m_pDoc,ScAddress(0,0,0),ScResId(STR_STYLENAME_RESULT));
@@ -138,7 +138,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testCondFormatInsertCol)
     m_pDoc->InsertTab(0, u"Test"_ustr);
     ScConditionalFormatList* pList = m_pDoc->GetCondFormList(0);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(1, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(1, *m_pDoc);
     ScRangeList aRangeList(ScRange(0,0,0,3,3,0));
     pFormat->SetRange(aRangeList);
 
@@ -161,7 +161,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testCondFormatInsertRow)
     m_pDoc->InsertTab(0, u"Test"_ustr);
     ScConditionalFormatList* pList = m_pDoc->GetCondFormList(0);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(1, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(1, *m_pDoc);
     ScRangeList aRangeList(ScRange(0,0,0,3,3,0));
     pFormat->SetRange(aRangeList);
 
@@ -184,7 +184,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testCondFormatInsertDeleteSheets)
     m_pDoc->InsertTab(0, u"Test"_ustr);
 
     // Add a conditional format to B2:B4.
-    auto pFormat = std::make_unique<ScConditionalFormat>(1, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(1, *m_pDoc);
     pFormat->SetRange(ScRange(1,1,0,1,3,0));
 
     auto pFormatTmp = pFormat.get();
@@ -290,12 +290,12 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testDataBarCondCopyPaste)
 {
     m_pDoc->InsertTab(0, u"Test"_ustr);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(1, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(1, *m_pDoc);
     ScRange aCondFormatRange(0, 0, 0, 2, 0, 0);
     ScRangeList aRangeList(aCondFormatRange);
     pFormat->SetRange(aRangeList);
 
-    ScDataBarFormat* pDatabar = new ScDataBarFormat(m_pDoc);
+    ScDataBarFormat* pDatabar = new ScDataBarFormat(*m_pDoc);
     ScDataBarFormatData* pFormatData = new ScDataBarFormatData();
     pFormatData->meAxisPosition = databar::AUTOMATIC;
     pFormatData->maPositiveColor = COL_BLUE;
@@ -398,14 +398,14 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testColorScaleInMergedCell)
     m_pDoc->SetValue(ScAddress(0, 0, 0), 1.0);
 
     // Add a conditional format to A1.
-    auto pFormat = std::make_unique<ScConditionalFormat>(1, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(1, *m_pDoc);
     pFormat->SetRange(ScRange(0, 0, 0, 0, 0, 0));
     auto pFormatTmp = pFormat.get();
     sal_uInt32 nKey = m_pDoc->AddCondFormat(std::move(pFormat), 0);
 
     // Add color scale entries.
     // The coloring is based on the value. (BLUE (x <= 0), GREEN (x == 1), RED 
(x >= 2))
-    ScColorScaleFormat* pColorScaleFormat = new ScColorScaleFormat(m_pDoc);
+    ScColorScaleFormat* pColorScaleFormat = new ScColorScaleFormat(*m_pDoc);
     ScColorScaleEntry* pEntryBlue = new ScColorScaleEntry(0, COL_BLUE);
     ScColorScaleEntry* pEntryGreen = new ScColorScaleEntry(1, COL_GREEN);
     ScColorScaleEntry* pEntryRed = new ScColorScaleEntry(2, COL_RED);
@@ -448,12 +448,12 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testColorScaleCondCopyPaste)
 {
     m_pDoc->InsertTab(0, u"Test"_ustr);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(1, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(1, *m_pDoc);
     ScRange aCondFormatRange(0, 0, 0, 2, 0, 0);
     ScRangeList aRangeList(aCondFormatRange);
     pFormat->SetRange(aRangeList);
 
-    ScColorScaleFormat* pColorScaleFormat = new ScColorScaleFormat(m_pDoc);
+    ScColorScaleFormat* pColorScaleFormat = new ScColorScaleFormat(*m_pDoc);
     ScColorScaleEntry* pEntryBlue = new ScColorScaleEntry(0, COL_BLUE);
     ScColorScaleEntry* pEntryGreen = new ScColorScaleEntry(1, COL_GREEN);
     ScColorScaleEntry* pEntryRed = new ScColorScaleEntry(2, COL_RED);
@@ -553,7 +553,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, testCondCopyPaste)
 {
     m_pDoc->InsertTab(0, u"Test"_ustr);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(1, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(1, *m_pDoc);
     ScRange aCondFormatRange(0,0,0,3,3,0);
     ScRangeList aRangeList(aCondFormatRange);
     pFormat->SetRange(aRangeList);
@@ -593,7 +593,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testCondCopyPasteSingleCell)
     //e.g. fdo#82503
     m_pDoc->InsertTab(0, u"Test"_ustr);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(1, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(1, *m_pDoc);
     ScRange aCondFormatRange(0,0,0,3,3,0);
     ScRangeList aRangeList(aCondFormatRange);
     pFormat->SetRange(aRangeList);
@@ -633,7 +633,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testCondCopyPasteSingleCellToRange)
     //e.g. fdo#82503
     m_pDoc->InsertTab(0, u"Test"_ustr);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(1, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(1, *m_pDoc);
     ScRange aCondFormatRange(0,0,0,3,3,0);
     ScRangeList aRangeList(aCondFormatRange);
     pFormat->SetRange(aRangeList);
@@ -679,7 +679,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testCondCopyPasteSingleCellIntoSameFormatRa
     // e.g., tdf#95295
     m_pDoc->InsertTab(0, u"Test"_ustr);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(1, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(1, *m_pDoc);
     ScRange aCondFormatRange(0, 0, 0, 3, 3, 0);
     ScRangeList aRangeList(aCondFormatRange);
     pFormat->SetRange(aRangeList);
@@ -717,7 +717,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testCondCopyPasteSingleRowToRange)
     //e.g. tdf#106242
     m_pDoc->InsertTab(0, u"Test"_ustr);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(1, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(1, *m_pDoc);
     ScRange aCondFormatRange(0,0,0,0,0,0);
     ScRangeList aRangeList(aCondFormatRange);
     pFormat->SetRange(aRangeList);
@@ -749,7 +749,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testCondCopyPasteSingleRowToRange2)
 {
     m_pDoc->InsertTab(0, u"Test"_ustr);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(1, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(1, *m_pDoc);
     ScRange aCondFormatRange(0,0,0,0,0,0);
     ScRangeList aRangeList(aCondFormatRange);
     pFormat->SetRange(aRangeList);
@@ -779,7 +779,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testCondCopyPasteSheetBetweenDoc)
 {
     m_pDoc->InsertTab(0, u"Test"_ustr);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(1, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(1, *m_pDoc);
     ScRange aCondFormatRange(0,0,0,3,3,0);
     ScRangeList aRangeList(aCondFormatRange);
     pFormat->SetRange(aRangeList);
@@ -801,7 +801,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, testCondCopyPasteSheet)
 {
     m_pDoc->InsertTab(0, u"Test"_ustr);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(1, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(1, *m_pDoc);
     ScRange aCondFormatRange(0,0,0,3,3,0);
     ScRangeList aRangeList(aCondFormatRange);
     pFormat->SetRange(aRangeList);
@@ -835,11 +835,11 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, testIconSet)
     m_pDoc->InsertTab(0, u"Test"_ustr);
     ScConditionalFormatList* pList = m_pDoc->GetCondFormList(0);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(1, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(1, *m_pDoc);
     ScRangeList aRangeList(ScRange(0,0,0,0,0,0));
     pFormat->SetRange(aRangeList);
 
-    ScIconSetFormat* pEntry = new ScIconSetFormat(m_pDoc);
+    ScIconSetFormat* pEntry = new ScIconSetFormat(*m_pDoc);
     ScIconSetFormatData* pData = new ScIconSetFormatData;
     pData->m_Entries.emplace_back(new ScColorScaleEntry(0, COL_BLUE, 
COLORSCALE_VALUE, ScConditionMode::EqLess));
     pData->m_Entries.emplace_back(new ScColorScaleEntry(1, COL_GREEN, 
COLORSCALE_VALUE, ScConditionMode::EqGreater));
@@ -885,7 +885,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testDataBarLengthAutomaticAxis)
         { 0, -200 }
     };
 
-    testDataBarLengthImpl(m_pDoc, aValues, ScRange(0,0,0,0,7,0),
+    testDataBarLengthImpl(*m_pDoc, aValues, ScRange(0,0,0,0,7,0),
             3, COLORSCALE_VALUE, 7, COLORSCALE_VALUE, 0.0, databar::AUTOMATIC);
 
     static const ScDataBarLengthData aValues2[] = {
@@ -907,7 +907,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testDataBarLengthAutomaticAxis)
         { 9, 100.0 },
         { 0, -200 }
     };
-    testDataBarLengthImpl(m_pDoc, aValues2, ScRange(1,0,0,1,15,0),
+    testDataBarLengthImpl(*m_pDoc, aValues2, ScRange(1,0,0,1,15,0),
             -4, COLORSCALE_VALUE, 8, COLORSCALE_VALUE, 1.0/3.0 * 100, 
databar::AUTOMATIC);
 
     static const ScDataBarLengthData aValues3[] = {
@@ -917,7 +917,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testDataBarLengthAutomaticAxis)
         { 6, 100.0 },
         { 0, -200 }
     };
-    testDataBarLengthImpl(m_pDoc, aValues3, ScRange(2,0,0,2,3,0),
+    testDataBarLengthImpl(*m_pDoc, aValues3, ScRange(2,0,0,2,3,0),
             0, COLORSCALE_MIN, 0, COLORSCALE_MAX, 0, databar::AUTOMATIC);
 
     static const ScDataBarLengthData aValues4[] = {
@@ -927,7 +927,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testDataBarLengthAutomaticAxis)
         { 5, 100.0 },
         { 0, -200 }
     };
-    testDataBarLengthImpl(m_pDoc, aValues4, ScRange(3,0,0,3,3,0),
+    testDataBarLengthImpl(*m_pDoc, aValues4, ScRange(3,0,0,3,3,0),
             0, COLORSCALE_AUTO, 0, COLORSCALE_AUTO, 0, databar::AUTOMATIC);
 
     m_pDoc->DeleteTab(0);
@@ -950,7 +950,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testDataBarLengthMiddleAxis)
         { 0, -200 }
     };
 
-    testDataBarLengthImpl(m_pDoc, aValues, ScRange(0,0,0,0,8,0),
+    testDataBarLengthImpl(*m_pDoc, aValues, ScRange(0,0,0,0,8,0),
             2, COLORSCALE_VALUE, 8, COLORSCALE_VALUE, 50.0, databar::MIDDLE);
 
     static const ScDataBarLengthData aValues2[] = {
@@ -972,7 +972,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testDataBarLengthMiddleAxis)
         { 9, 100.0 },
         { 0, -200 }
     };
-    testDataBarLengthImpl(m_pDoc, aValues2, ScRange(1,0,0,1,15,0),
+    testDataBarLengthImpl(*m_pDoc, aValues2, ScRange(1,0,0,1,15,0),
             -4, COLORSCALE_VALUE, 8, COLORSCALE_VALUE, 50.0, databar::MIDDLE);
 
     m_pDoc->DeleteTab(0);
@@ -1141,7 +1141,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testCondFormatUpdateMoveTab)
 
     ScConditionEntry* pEntry = new ScConditionEntry(ScConditionMode::Equal, 
u"A1"_ustr, u""_ustr, *m_pDoc, ScAddress(10, 10, 0), u""_ustr, u""_ustr, 
formula::FormulaGrammar::GRAM_DEFAULT, formula::FormulaGrammar::GRAM_DEFAULT);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(0, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(0, *m_pDoc);
     pFormat->SetRange(ScRange(10, 10, 0, 10, 12, 0));
     auto pFormatTmp = pFormat.get();
     m_pDoc->AddCondFormat(std::move(pFormat), 0);
@@ -1177,7 +1177,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testCondFormatUpdateInsertTab)
 
     ScConditionEntry* pEntry = new ScConditionEntry(ScConditionMode::Equal, 
u"A1"_ustr, u""_ustr, *m_pDoc, ScAddress(10, 10, 0), u""_ustr, u""_ustr, 
formula::FormulaGrammar::GRAM_DEFAULT, formula::FormulaGrammar::GRAM_DEFAULT);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(0, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(0, *m_pDoc);
     pFormat->SetRange(ScRange(10, 10, 0, 10, 12, 0));
     auto pFormatTmp = pFormat.get();
     m_pDoc->AddCondFormat(std::move(pFormat), 0);
@@ -1217,7 +1217,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testCondFormatUpdateDeleteTab)
 
     ScConditionEntry* pEntry = new ScConditionEntry(ScConditionMode::Equal, 
u"A1"_ustr, u""_ustr, *m_pDoc, ScAddress(10, 10, 1), u""_ustr, u""_ustr, 
formula::FormulaGrammar::GRAM_DEFAULT, formula::FormulaGrammar::GRAM_DEFAULT);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(0, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(0, *m_pDoc);
     pFormat->SetRange(ScRange(10, 10, 1, 10, 12, 1));
     auto pFormatTmp = pFormat.get();
     m_pDoc->AddCondFormat(std::move(pFormat), 1);
@@ -1250,7 +1250,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testCondFormatUpdateReference)
 
     ScConditionEntry* pEntry = new ScConditionEntry(ScConditionMode::Equal, 
u"A1"_ustr, u""_ustr, *m_pDoc, ScAddress(10, 10, 0), u""_ustr, u""_ustr, 
formula::FormulaGrammar::GRAM_DEFAULT, formula::FormulaGrammar::GRAM_DEFAULT);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(0, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(0, *m_pDoc);
     pFormat->SetRange(ScRange(10, 10, 0, 10, 12, 0));
     auto pFormatTmp = pFormat.get();
     m_pDoc->AddCondFormat(std::move(pFormat), 0);
@@ -1274,7 +1274,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testCondFormatUpdateReferenceDelRow)
 
     ScConditionEntry* pEntry = new ScConditionEntry(ScConditionMode::Equal, 
u"B6"_ustr, u""_ustr, *m_pDoc, ScAddress(0, 5, 0), u""_ustr, u""_ustr, 
formula::FormulaGrammar::GRAM_DEFAULT, formula::FormulaGrammar::GRAM_DEFAULT);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(0, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(0, *m_pDoc);
     pFormat->SetRange(ScRange(0, 5, 0, 0, 5, 0));
     auto pFormatTmp = pFormat.get();
     m_pDoc->AddCondFormat(std::move(pFormat), 0);
@@ -1295,7 +1295,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testCondFormatUpdateReferenceInsRow)
 
     ScConditionEntry* pEntry = new ScConditionEntry(ScConditionMode::Equal, 
u"B6"_ustr, u""_ustr, *m_pDoc, ScAddress(0, 5, 0), u""_ustr, u""_ustr, 
formula::FormulaGrammar::GRAM_DEFAULT, formula::FormulaGrammar::GRAM_DEFAULT);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(0, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(0, *m_pDoc);
     pFormat->SetRange(ScRange(0, 5, 0, 0, 5, 0));
     auto pFormatTmp = pFormat.get();
     m_pDoc->AddCondFormat(std::move(pFormat), 0);
@@ -1316,7 +1316,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testCondFormatUndoList)
 
     ScConditionEntry* pEntry = new ScConditionEntry(ScConditionMode::Equal, 
u"B6"_ustr, u""_ustr, *m_pDoc, ScAddress(0, 5, 0), u""_ustr, u""_ustr, 
formula::FormulaGrammar::GRAM_DEFAULT, formula::FormulaGrammar::GRAM_DEFAULT);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(0, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(0, *m_pDoc);
     pFormat->AddEntry(pEntry);
     pFormat->SetRange(ScRange(0, 0, 0, 0, 5, 0));
     auto pFormatTmp = pFormat.get();
@@ -1356,8 +1356,8 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testMultipleSingleCellCondFormatCopyPaste)
 {
     m_pDoc->InsertTab(0, u"Test"_ustr);
 
-    sal_uInt32 nFirstCondFormatKey = addSingleCellCondFormat(m_pDoc, 
ScAddress(0, 0, 0), 1, u"=A2"_ustr);
-    sal_uInt32 nSecondCondFormatKey = addSingleCellCondFormat(m_pDoc, 
ScAddress(1, 0, 0), 2, u"=B3"_ustr);
+    sal_uInt32 nFirstCondFormatKey = addSingleCellCondFormat(*m_pDoc, 
ScAddress(0, 0, 0), 1, u"=A2"_ustr);
+    sal_uInt32 nSecondCondFormatKey = addSingleCellCondFormat(*m_pDoc, 
ScAddress(1, 0, 0), 2, u"=B3"_ustr);
 
     ScDocument aClipDoc(SCDOCMODE_CLIP);
     copyToClip(m_pDoc, ScRange(0,0,0,2,0,0), &aClipDoc);
@@ -1388,8 +1388,8 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testDeduplicateMultipleCondFormats)
 {
     m_pDoc->InsertTab(0, u"Test"_ustr);
 
-    sal_uInt32 nFirstCondFormatKey = addSingleCellCondFormat(m_pDoc, 
ScAddress(0, 0, 0), 1, u"=B2"_ustr);
-    sal_uInt32 nSecondCondFormatKey = addSingleCellCondFormat(m_pDoc, 
ScAddress(1, 0, 0), 2, u"=B2"_ustr);
+    sal_uInt32 nFirstCondFormatKey = addSingleCellCondFormat(*m_pDoc, 
ScAddress(0, 0, 0), 1, u"=B2"_ustr);
+    sal_uInt32 nSecondCondFormatKey = addSingleCellCondFormat(*m_pDoc, 
ScAddress(1, 0, 0), 2, u"=B2"_ustr);
 
     ScDocument aClipDoc(SCDOCMODE_CLIP);
     copyToClip(m_pDoc, ScRange(0,0,0,2,0,0), &aClipDoc);
@@ -1422,11 +1422,11 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testCondFormatListenToOwnRange)
 
     ScConditionalFormatList* pList = m_pDoc->GetCondFormList(0);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(1, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(1, *m_pDoc);
     ScRangeList aRangeList(ScRange(0,0,0,10,0,0));
     pFormat->SetRange(aRangeList);
 
-    ScIconSetFormat* pEntry = new ScIconSetFormat(m_pDoc);
+    ScIconSetFormat* pEntry = new ScIconSetFormat(*m_pDoc);
     ScIconSetFormatData* pData = new ScIconSetFormatData;
     pData->m_Entries.emplace_back(new ScColorScaleEntry(0, COL_BLUE));
     pData->m_Entries.emplace_back(new ScColorScaleEntry(1, COL_GREEN));
@@ -1458,7 +1458,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testCondFormatVolatileFunctionRecalc)
 
     ScConditionalFormatList* pList = m_pDoc->GetCondFormList(0);
 
-    auto pFormat = std::make_unique<ScConditionalFormat>(1, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(1, *m_pDoc);
     ScRangeList aRangeList(ScRange(0,0,0,10,0,0));
     pFormat->SetRange(aRangeList);
 
@@ -1502,7 +1502,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testConditionStyleInMergedCell)
     m_pDoc->SetValue(ScAddress(0, 0, 0), 1.0);
 
     // Add a conditional format.
-    auto pFormat = std::make_unique<ScConditionalFormat>(1, m_pDoc);
+    auto pFormat = std::make_unique<ScConditionalFormat>(1, *m_pDoc);
     pFormat->SetRange(ScRange(0, 0, 0, 0, 0, 0));
 
     // Add condition in which if the value equals 1, set the "Good" style.
diff --git a/sc/qa/unit/ucalc_rangelst.cxx b/sc/qa/unit/ucalc_rangelst.cxx
index 364bd40d69d3..469ca889bd45 100644
--- a/sc/qa/unit/ucalc_rangelst.cxx
+++ b/sc/qa/unit/ucalc_rangelst.cxx
@@ -410,7 +410,7 @@ CPPUNIT_TEST_FIXTURE(Test, testJoin_Case5)
 CPPUNIT_TEST_FIXTURE(Test, testUpdateReference_DeleteRow)
 {
     ScRangeList aList(ScRange(1,1,0,4,4,0));
-    bool bUpdated = aList.UpdateReference(URM_INSDEL, m_pDoc, 
ScRange(0,3,0,m_pDoc->MaxCol(),m_pDoc->MaxRow(),0), 0, -1, 0);
+    bool bUpdated = aList.UpdateReference(URM_INSDEL, *m_pDoc, 
ScRange(0,3,0,m_pDoc->MaxCol(),m_pDoc->MaxRow(),0), 0, -1, 0);
     CPPUNIT_ASSERT(bUpdated);
 
     for(SCCOL nCol = 1; nCol <= 4; ++nCol)
@@ -424,13 +424,13 @@ CPPUNIT_TEST_FIXTURE(Test, testUpdateReference_DeleteRow)
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt64>(12), aList.GetCellCount());
 
     ScRangeList aList2(ScRange(2,2,0,2,2,0));
-    aList2.UpdateReference(URM_INSDEL, m_pDoc, 
ScRange(0,3,0,m_pDoc->MaxCol(),m_pDoc->MaxRow(),0), 0, -1, 0);
+    aList2.UpdateReference(URM_INSDEL, *m_pDoc, 
ScRange(0,3,0,m_pDoc->MaxCol(),m_pDoc->MaxRow(),0), 0, -1, 0);
     CPPUNIT_ASSERT(aList2.empty());
 
     ScRangeList aList3;
     aList3.push_back(ScRange(2,2,0,2,8,0));
     aList3.push_back(ScRange(4,2,0,4,8,0));
-    aList3.UpdateReference(URM_INSDEL, m_pDoc, 
ScRange(2,5,0,m_pDoc->MaxCol(),m_pDoc->MaxRow(),0), 0, -1, 0);
+    aList3.UpdateReference(URM_INSDEL, *m_pDoc, 
ScRange(2,5,0,m_pDoc->MaxCol(),m_pDoc->MaxRow(),0), 0, -1, 0);
     // Verify all ranges in the list have been updated properly.
     CPPUNIT_ASSERT_EQUAL(size_t(2), aList3.size());
     CPPUNIT_ASSERT_EQUAL(ScRange(2,2,0,2,7,0), aList3[0]);
@@ -438,21 +438,21 @@ CPPUNIT_TEST_FIXTURE(Test, testUpdateReference_DeleteRow)
 
     ScRangeList aList4(ScRange(0,0,0,m_pDoc->MaxCol(),m_pDoc->MaxRow(),0));
     ScRangeList aList4Copy = aList4;
-    aList4.UpdateReference(URM_INSDEL, m_pDoc, 
ScRange(14,3,0,m_pDoc->MaxCol(),7,0), 0, -2, 0);
+    aList4.UpdateReference(URM_INSDEL, *m_pDoc, 
ScRange(14,3,0,m_pDoc->MaxCol(),7,0), 0, -2, 0);
     CPPUNIT_ASSERT_EQUAL(aList4Copy, aList4);
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testUpdateReference_DeleteLastRow)
 {
     ScRangeList aList(ScRange(1,1,0,4,4,0));
-    bool bUpdated = aList.UpdateReference(URM_INSDEL, m_pDoc, 
ScRange(0,4,0,m_pDoc->MaxCol(),4,0), 0, -1, 0);
+    bool bUpdated = aList.UpdateReference(URM_INSDEL, *m_pDoc, 
ScRange(0,4,0,m_pDoc->MaxCol(),4,0), 0, -1, 0);
     CPPUNIT_ASSERT(bUpdated);
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testUpdateReference_DeleteCol)
 {
     ScRangeList aList(ScRange(1,1,0,4,4,0));
-    bool bUpdated = aList.UpdateReference(URM_INSDEL, m_pDoc, 
ScRange(3,0,0,m_pDoc->MaxCol(),m_pDoc->MaxRow(),0), -1, 0, 0);
+    bool bUpdated = aList.UpdateReference(URM_INSDEL, *m_pDoc, 
ScRange(3,0,0,m_pDoc->MaxCol(),m_pDoc->MaxRow(),0), -1, 0, 0);
     CPPUNIT_ASSERT(bUpdated);
 
     for(SCROW nRow = 1; nRow <= 4; ++nRow)
diff --git a/sc/source/core/data/bcaslot.cxx b/sc/source/core/data/bcaslot.cxx
index 92f694c3071b..f9746be2c281 100644
--- a/sc/source/core/data/bcaslot.cxx
+++ b/sc/source/core/data/bcaslot.cxx
@@ -40,10 +40,10 @@ ScBroadcastArea::ScBroadcastArea( const ScRange& rRange ) :
     mbInUpdateChain(false),
     mbGroupListening(false) {}
 
-ScBroadcastAreaSlot::ScBroadcastAreaSlot( ScDocument* pDocument,
+ScBroadcastAreaSlot::ScBroadcastAreaSlot( ScDocument& rDocument,
         ScBroadcastAreaSlotMachine* pBASMa ) :
     aTmpSeekBroadcastArea( ScRange()),
-    pDoc( pDocument ),
+    rDoc( rDocument ),
     pBASM( pBASMa ),
     mbInBroadcastIteration( false),
     mbHasErasedArea(false)
@@ -68,20 +68,20 @@ ScBroadcastAreaSlot::~ScBroadcastAreaSlot()
 
 ScDocument::HardRecalcState 
ScBroadcastAreaSlot::CheckHardRecalcStateCondition() const
 {
-    ScDocument::HardRecalcState eState = pDoc->GetHardRecalcState();
+    ScDocument::HardRecalcState eState = rDoc.GetHardRecalcState();
     if (eState == ScDocument::HardRecalcState::OFF)
     {
         if (aBroadcastAreaTbl.size() >= aBroadcastAreaTbl.max_size())
         {   // this is more hypothetical now, check existed for old 
SV_PTRARR_SORT
-            ScDocShell* pShell = pDoc->GetDocumentShell();
+            ScDocShell* pShell = rDoc.GetDocumentShell();
             OSL_ENSURE( pShell, "Missing DocShell :-/" );
 
             if ( pShell )
                 pShell->SetError(SCWARN_CORE_HARD_RECALC);
 
-            pDoc->SetAutoCalc( false );
+            rDoc.SetAutoCalc( false );
             eState = ScDocument::HardRecalcState::ETERNAL;
-            pDoc->SetHardRecalcState( eState );
+            rDoc.SetHardRecalcState( eState );
         }
     }
     return eState;
@@ -92,7 +92,7 @@ bool ScBroadcastAreaSlot::StartListeningArea(
 {
     bool bNewArea = false;
     OSL_ENSURE(pListener, "StartListeningArea: pListener Null");
-    assert(!pDoc->IsDelayedFormulaGrouping()); // otherwise the group size 
might be incorrect
+    assert(!rDoc.IsDelayedFormulaGrouping()); // otherwise the group size 
might be incorrect
     if (CheckHardRecalcStateCondition() == 
ScDocument::HardRecalcState::ETERNAL)
         return false;
     if ( !rpArea )
@@ -357,7 +357,7 @@ void ScBroadcastAreaSlot::UpdateRemove( UpdateRefMode 
eUpdateRefMode,
         else
         {
             pArea->GetRange().GetVars( theCol1, theRow1, theTab1, theCol2, 
theRow2, theTab2);
-            if ( ScRefUpdate::Update( pDoc, eUpdateRefMode,
+            if ( ScRefUpdate::Update( rDoc, eUpdateRefMode,
                     nCol1,nRow1,nTab1, nCol2,nRow2,nTab2, nDx,nDy,nDz,
                     theCol1,theRow1,theTab1, theCol2,theRow2,theTab2 ))
             {
@@ -553,8 +553,8 @@ ScBroadcastAreaSlotMachine::TableSlots::~TableSlots()
 }
 
 ScBroadcastAreaSlotMachine::ScBroadcastAreaSlotMachine(
-        ScDocument* pDocument ) :
-    pDoc( pDocument ),
+        ScDocument& rDocument ) :
+    rDoc( rDocument ),
     pUpdateChain( nullptr ),
     pEOUpdateChain( nullptr ),
     nInBulkBroadcast( 0 )
@@ -575,7 +575,7 @@ ScBroadcastAreaSlotMachine::ScBroadcastAreaSlotMachine(
     sal_Int32 nCol1 = 0;
     sal_Int32 nCol2 = 1024;
     SCSIZE nSliceCol = 16;
-    while (nCol2 <= pDoc->GetMaxColCount())
+    while (nCol2 <= rDoc.GetMaxColCount())
     {
         SCROW nRow1 = 0;
         SCROW nRow2 = 32*1024;
@@ -583,7 +583,7 @@ ScBroadcastAreaSlotMachine::ScBroadcastAreaSlotMachine(
         SCSIZE nSlotsCol = 0;
         SCSIZE nSlotsStartCol = nSlots;
         // Must be sorted by row1,row2!
-        while (nRow2 <= pDoc->GetMaxRowCount())
+        while (nRow2 <= rDoc.GetMaxRowCount())
         {
             maSlotDistribution.emplace_back(nRow1, nRow2, nSliceRow, 
nSlotsCol, nCol1, nCol2, nSliceCol, nSlotsStartCol);
             nSlotsCol += (nRow2 - nRow1) / nSliceRow;
@@ -621,7 +621,7 @@ inline SCSIZE ScBroadcastAreaSlotMachine::ComputeSlotOffset(
 {
     SCROW nRow = rAddress.Row();
     SCCOL nCol = rAddress.Col();
-    if ( !pDoc->ValidRow(nRow) || !pDoc->ValidCol(nCol) )
+    if ( !rDoc.ValidRow(nRow) || !rDoc.ValidCol(nCol) )
     {
         OSL_FAIL( "Row/Col invalid, using first slot!" );
         return 0;
@@ -693,7 +693,7 @@ void ScBroadcastAreaSlotMachine::DoChecks()
     compare( ComputeSlotOffset( ScAddress( nSliceCol - 1, 0, 0 )),
              ComputeSlotOffset( ScAddress( nSliceCol, 0, 0 )) - mnBcaSlotsCol, 
__LINE__ );
     // Check that last cell is the last slot.
-    compare( ComputeSlotOffset( ScAddress( pDoc->GetMaxColCount() - 1, 
pDoc->GetMaxRowCount() - 1, 0 )),
+    compare( ComputeSlotOffset( ScAddress( rDoc.GetMaxColCount() - 1, 
rDoc.GetMaxRowCount() - 1, 0 )),
              mnBcaSlots - 1, __LINE__ );
     // Check that adjacent rows in the same column but in different 
distribution areas differ by one slot.
     for( size_t i = 0; i < maSlotDistribution.size() - 1; ++i )
@@ -723,7 +723,7 @@ void ScBroadcastAreaSlotMachine::DoChecks()
         }
     }
     // Iterate all slots.
-    ScRange range( ScAddress( 0, 0, 0 ), ScAddress( pDoc->MaxCol(), 
pDoc->MaxRow(), 0 ));
+    ScRange range( ScAddress( 0, 0, 0 ), ScAddress( rDoc.MaxCol(), 
rDoc.MaxRow(), 0 ));
     SCSIZE nStart, nEnd, nRowBreak;
     ComputeAreaPoints( range, nStart, nEnd, nRowBreak );
     assert( nStart == 0 );
@@ -740,8 +740,8 @@ void ScBroadcastAreaSlotMachine::DoChecks()
         compare( nOff, previous + 1, __LINE__ );
     }
     // Iterate slots in the last row (each will differ by mnBcaSlotsCol).
-    range = ScRange( ScAddress( 0, pDoc->MaxRow(), 0 ),
-                     ScAddress( pDoc->MaxCol(), pDoc->MaxRow() - 1, 0 ));
+    range = ScRange( ScAddress( 0, rDoc.MaxRow(), 0 ),
+                     ScAddress( rDoc.MaxCol(), rDoc.MaxRow() - 1, 0 ));
     ComputeAreaPoints( range, nStart, nEnd, nRowBreak );
     assert( nStart == mnBcaSlotsCol - 1 );
     assert( nEnd == mnBcaSlots - 1 );
@@ -791,7 +791,7 @@ void ScBroadcastAreaSlotMachine::StartListeningArea(
             while ( !bDone && nOff <= nEnd )
             {
                 if ( !*pp )
-                    *pp = new ScBroadcastAreaSlot( pDoc, this );
+                    *pp = new ScBroadcastAreaSlot( rDoc, this );
                 if (!pArea)
                 {
                     // If the call to StartListeningArea didn't create the
@@ -1088,7 +1088,7 @@ void ScBroadcastAreaSlotMachine::UpdateBroadcastAreas(
 
         // update range
         aRange.GetVars( theCol1, theRow1, theTab1, theCol2, theRow2, theTab2);
-        if ( ScRefUpdate::Update( pDoc, eUpdateRefMode,
+        if ( ScRefUpdate::Update( rDoc, eUpdateRefMode,
                 nCol1,nRow1,nTab1, nCol2,nRow2,nTab2, nDx,nDy,nDz,
                 theCol1,theRow1,theTab1, theCol2,theRow2,theTab2 ))
         {
@@ -1114,7 +1114,7 @@ void ScBroadcastAreaSlotMachine::UpdateBroadcastAreas(
             while ( nOff <= nEnd )
             {
                 if (!*pp)
-                    *pp = new ScBroadcastAreaSlot( pDoc, this );
+                    *pp = new ScBroadcastAreaSlot( rDoc, this );
                 (*pp)->UpdateInsert( pArea );
                 ComputeNextSlot( nOff, nBreak, pp, nStart, ppSlots, nRowBreak, 
mnBcaSlotsCol);
             }
@@ -1147,10 +1147,10 @@ void ScBroadcastAreaSlotMachine::LeaveBulkBroadcast( 
SfxHintId nHintId )
         ScBroadcastAreasBulk().swap( aBulkBroadcastAreas);
         bool bBroadcasted = BulkBroadcastGroupAreas();
         // Trigger the "final" tracking.
-        if (pDoc->IsTrackFormulasPending())
-            pDoc->FinalTrackFormulas( nHintId );
+        if (rDoc.IsTrackFormulasPending())
+            rDoc.FinalTrackFormulas( nHintId );
         else if (bBroadcasted)
-            pDoc->TrackFormulas( nHintId );
+            rDoc.TrackFormulas( nHintId );
     }
 }
 
@@ -1169,7 +1169,7 @@ void ScBroadcastAreaSlotMachine::InsertBulkGroupArea( 
ScBroadcastArea* pArea, co
     }
 
     sc::ColumnSpanSet& rSet = it->second;
-    rSet.set(*pDoc, rRange, true);
+    rSet.set(rDoc, rRange, true);
 }
 
 bool ScBroadcastAreaSlotMachine::BulkBroadcastGroupAreas()
@@ -1177,7 +1177,7 @@ bool ScBroadcastAreaSlotMachine::BulkBroadcastGroupAreas()
     if (m_BulkGroupAreas.empty())
         return false;
 
-    sc::BulkDataHint aHint( *pDoc );
+    sc::BulkDataHint aHint( rDoc );
 
     bool bBroadcasted = false;
     for (const auto& [pArea, rSpans] : m_BulkGroupAreas)
diff --git a/sc/source/core/data/colorscale.cxx 
b/sc/source/core/data/colorscale.cxx
index 786f1d242a4c..736f2c76582d 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -185,7 +185,7 @@ ScColorScaleEntry::ScColorScaleEntry(const 
ScColorScaleEntry& rEntry):
     }
 }
 
-ScColorScaleEntry::ScColorScaleEntry(ScDocument* pDoc, const 
ScColorScaleEntry& rEntry):
+ScColorScaleEntry::ScColorScaleEntry(ScDocument& rDoc, const 
ScColorScaleEntry& rEntry):
     mnVal(rEntry.mnVal),
     mpFormat(rEntry.mpFormat),
     maColor(rEntry.maColor),
@@ -195,8 +195,8 @@ ScColorScaleEntry::ScColorScaleEntry(ScDocument* pDoc, 
const ScColorScaleEntry&
     setListener();
     if(rEntry.mpCell)
     {
-        mpCell.reset(new ScFormulaCell(*rEntry.mpCell, *pDoc, 
rEntry.mpCell->aPos, ScCloneFlags::NoMakeAbsExternal));
-        mpCell->StartListeningTo( *pDoc );
+        mpCell.reset(new ScFormulaCell(*rEntry.mpCell, rDoc, 
rEntry.mpCell->aPos, ScCloneFlags::NoMakeAbsExternal));
+        mpCell->StartListeningTo( rDoc );
         mpListener.reset(new ScFormulaListener(mpCell.get()));
         if (mpFormat)
             mpListener->setCallback([&]() { mpFormat->DoRepaint();});
@@ -356,7 +356,7 @@ void ScColorScaleEntry::setListener()
             || meType == COLORSCALE_MIN || meType == COLORSCALE_MAX
             || meType == COLORSCALE_AUTO)
     {
-        mpListener.reset(new ScFormulaListener(*mpFormat->GetDocument(), 
mpFormat->GetRange()));
+        mpListener.reset(new ScFormulaListener(mpFormat->GetDocument(), 
mpFormat->GetRange()));
         mpListener->setCallback([&]() { mpFormat->DoRepaint();});
     }
 }
@@ -366,8 +366,8 @@ void ScColorScaleEntry::SetRepaintCallback(const 
std::function<void()>& func)
     mpListener->setCallback(func);
 }
 
-ScColorFormat::ScColorFormat(ScDocument* pDoc)
-    : ScFormatEntry(pDoc)
+ScColorFormat::ScColorFormat(ScDocument& rDoc)
+    : ScFormatEntry(rDoc)
     , mpParent(nullptr)
 {
 }
@@ -381,26 +381,26 @@ void ScColorFormat::SetParent( ScConditionalFormat* 
pParent )
     mpParent = pParent;
 }
 
-ScColorScaleFormat::ScColorScaleFormat(ScDocument* pDoc):
-    ScColorFormat(pDoc)
+ScColorScaleFormat::ScColorScaleFormat(ScDocument& rDoc):
+    ScColorFormat(rDoc)
 {
 }
 
-ScColorScaleFormat::ScColorScaleFormat(ScDocument* pDoc, const 
ScColorScaleFormat& rFormat):
-    ScColorFormat(pDoc)
+ScColorScaleFormat::ScColorScaleFormat(ScDocument& rDoc, const 
ScColorScaleFormat& rFormat):
+    ScColorFormat(rDoc)
 {
     for(const auto& rxEntry : rFormat)
     {
-        maColorScales.emplace_back(new ScColorScaleEntry(pDoc, *rxEntry));
+        maColorScales.emplace_back(new ScColorScaleEntry(rDoc, *rxEntry));
     }
 
     auto aCache = rFormat.GetCache();
     SetCache(aCache);
 }
 
-ScColorFormat* ScColorScaleFormat::Clone(ScDocument* pDoc) const
+ScColorFormat* ScColorScaleFormat::Clone(ScDocument& rDoc) const
 {
-    return new ScColorScaleFormat(pDoc, *this);
+    return new ScColorScaleFormat(rDoc, *this);
 }
 
 ScColorScaleFormat::~ScColorScaleFormat()
@@ -523,10 +523,10 @@ std::vector<double>& ScColorFormat::getValues() const
             SCCOL nColEnd = rRange.aEnd.Col();
             SCROW nRowEnd = rRange.aEnd.Row();
 
-            if(nRowEnd == mpDoc->MaxRow())
+            if(nRowEnd == mrDoc.MaxRow())
             {
                 bool bShrunk = false;
-                mpDoc->ShrinkToUsedDataArea(bShrunk, nTab, nColStart, 
nRowStart,
+                mrDoc.ShrinkToUsedDataArea(bShrunk, nTab, nColStart, nRowStart,
                         nColEnd, nRowEnd, false);
             }
             for(SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
@@ -534,7 +534,7 @@ std::vector<double>& ScColorFormat::getValues() const
                 for(SCROW nRow = nRowStart; nRow <= nRowEnd; ++nRow)
                 {
                     ScAddress aAddr(nCol, nRow, nTab);
-                    ScRefCellValue rCell(*mpDoc, aAddr);
+                    ScRefCellValue rCell(mrDoc, aAddr);
                     if(rCell.hasNumeric())
                     {
                         double aVal = rCell.getValue();
@@ -662,7 +662,7 @@ double ScColorScaleFormat::CalcValue(double nMin, double 
nMax, const ScColorScal
 
 std::optional<Color> ScColorScaleFormat::GetColor( const ScAddress& rAddr ) 
const
 {
-    ScRefCellValue rCell(*mpDoc, rAddr);
+    ScRefCellValue rCell(mrDoc, rAddr);
     if(!rCell.hasNumeric())
         return std::optional<Color>();
 
@@ -784,14 +784,14 @@ void ScColorScaleFormat::EnsureSize()
     }
 }
 
-ScDataBarFormat::ScDataBarFormat(ScDocument* pDoc):
-    ScColorFormat(pDoc),
+ScDataBarFormat::ScDataBarFormat(ScDocument& rDoc):
+    ScColorFormat(rDoc),
     mpFormatData(new ScDataBarFormatData())
 {
 }
 
-ScDataBarFormat::ScDataBarFormat(ScDocument* pDoc, const ScDataBarFormat& 
rFormat):
-    ScColorFormat(pDoc),
+ScDataBarFormat::ScDataBarFormat(ScDocument& rDoc, const ScDataBarFormat& 
rFormat):
+    ScColorFormat(rDoc),
     mpFormatData(new ScDataBarFormatData(*rFormat.mpFormatData))
 {
 }
@@ -816,9 +816,9 @@ const ScDataBarFormatData* 
ScDataBarFormat::GetDataBarData() const
     return mpFormatData.get();
 }
 
-ScColorFormat* ScDataBarFormat::Clone(ScDocument* pDoc) const
+ScColorFormat* ScDataBarFormat::Clone(ScDocument& rDoc) const
 {
-    return new ScDataBarFormat(pDoc, *this);
+    return new ScDataBarFormat(rDoc, *this);
 }
 
 void ScDataBarFormat::SetParent(ScConditionalFormat* pFormat)
@@ -948,7 +948,7 @@ double ScDataBarFormat::getMax(double nMin, double nMax) 
const
 
 std::unique_ptr<ScDataBarInfo> ScDataBarFormat::GetDataBarInfo(const 
ScAddress& rAddr) const
 {
-    ScRefCellValue rCell(*mpDoc, rAddr);
+    ScRefCellValue rCell(mrDoc, rAddr);
     if(!rCell.hasNumeric())
         return nullptr;
 
@@ -1117,21 +1117,21 @@ 
ScIconSetFormatData::ScIconSetFormatData(ScIconSetFormatData const& rOther)
     }
 }
 
-ScIconSetFormat::ScIconSetFormat(ScDocument* pDoc):
-    ScColorFormat(pDoc),
+ScIconSetFormat::ScIconSetFormat(ScDocument& rDoc):
+    ScColorFormat(rDoc),
     mpFormatData(new ScIconSetFormatData)
 {
 }
 
-ScIconSetFormat::ScIconSetFormat(ScDocument* pDoc, const ScIconSetFormat& 
rFormat):
-    ScColorFormat(pDoc),
+ScIconSetFormat::ScIconSetFormat(ScDocument& rDoc, const ScIconSetFormat& 
rFormat):
+    ScColorFormat(rDoc),
     mpFormatData(new ScIconSetFormatData(*rFormat.mpFormatData))
 {
 }
 
-ScColorFormat* ScIconSetFormat::Clone( ScDocument* pDoc ) const
+ScColorFormat* ScIconSetFormat::Clone( ScDocument& rDoc ) const
 {
-    return new ScIconSetFormat(pDoc, *this);
+    return new ScIconSetFormat(rDoc, *this);
 }
 
 void ScIconSetFormat::SetParent(ScConditionalFormat* pFormat)
@@ -1161,7 +1161,7 @@ const ScIconSetFormatData* 
ScIconSetFormat::GetIconSetData() const
 
 std::unique_ptr<ScIconSetInfo> ScIconSetFormat::GetIconSetInfo(const 
ScAddress& rAddr) const
 {
-    ScRefCellValue rCell(*mpDoc, rAddr);
+    ScRefCellValue rCell(mrDoc, rAddr);
     if(!rCell.hasNumeric())
         return nullptr;
 
@@ -1195,7 +1195,7 @@ std::unique_ptr<ScIconSetInfo> 
ScIconSetFormat::GetIconSetInfo(const ScAddress&
 
     std::unique_ptr<ScIconSetInfo> pInfo(new ScIconSetInfo);
 
-    const SfxPoolItem& rPoolItem = 
mpDoc->GetPattern(rAddr)->GetItem(ATTR_FONT_HEIGHT);
+    const SfxPoolItem& rPoolItem = 
mrDoc.GetPattern(rAddr)->GetItem(ATTR_FONT_HEIGHT);
     tools::Long aFontHeight = static_cast<const 
SvxFontHeightItem&>(rPoolItem).GetHeight();
     pInfo->mnHeight = aFontHeight;
 
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx
index 625d3bac2bd7..4882dcbc63ee 100644
--- a/sc/source/core/data/conditio.cxx
+++ b/sc/source/core/data/conditio.cxx
@@ -48,8 +48,8 @@
 
 using namespace formula;
 
-ScFormatEntry::ScFormatEntry(ScDocument* pDoc):
-    mpDoc(pDoc)
+ScFormatEntry::ScFormatEntry(ScDocument& rDoc):
+    mrDoc(rDoc)
 {
 }
 
@@ -78,7 +78,7 @@ void ScFormatEntry::updateValues()
 {
 }
 
-static bool lcl_HasRelRef( ScDocument* pDoc, const ScTokenArray* pFormula, 
sal_uInt16 nRecursion = 0 )
+static bool lcl_HasRelRef( ScDocument& rDoc, const ScTokenArray* pFormula, 
sal_uInt16 nRecursion = 0 )
 {
     if (pFormula)
     {
@@ -107,8 +107,8 @@ static bool lcl_HasRelRef( ScDocument* pDoc, const 
ScTokenArray* pFormula, sal_u
                 case svIndex:
                 {
                     if( t->GetOpCode() == ocName )      // DB areas always 
absolute
-                        if( ScRangeData* pRangeData = 
pDoc->FindRangeNameBySheetAndIndex( t->GetSheet(), t->GetIndex()) )
-                            if( (nRecursion < 42) && lcl_HasRelRef( pDoc, 
pRangeData->GetCode(), nRecursion + 1 ) )
+                        if( ScRangeData* pRangeData = 
rDoc.FindRangeNameBySheetAndIndex( t->GetSheet(), t->GetIndex()) )
+                            if( (nRecursion < 42) && lcl_HasRelRef( rDoc, 
pRangeData->GetCode(), nRecursion + 1 ) )
                                 return true;
                 }
                 break;
@@ -176,7 +176,7 @@ void ScConditionEntry::SetParent(ScConditionalFormat* 
pParent)
 }
 
 ScConditionEntry::ScConditionEntry( const ScConditionEntry& r ) :
-    ScFormatEntry(r.mpDoc),
+    ScFormatEntry(r.mrDoc),
     eOp(r.eOp),
     nOptions(r.nOptions),
     nVal1(r.nVal1),
@@ -194,7 +194,7 @@ ScConditionEntry::ScConditionEntry( const ScConditionEntry& 
r ) :
     bRelRef1(r.bRelRef1),
     bRelRef2(r.bRelRef2),
     bFirstRun(true),
-    mpListener(new ScFormulaListener(*r.mpDoc)),
+    mpListener(new ScFormulaListener(r.mrDoc)),
     eConditionType( r.eConditionType ),
     pCondFormat(r.pCondFormat),
     mpRepaintTask()
@@ -210,7 +210,7 @@ ScConditionEntry::ScConditionEntry( const ScConditionEntry& 
r ) :
 }
 
 ScConditionEntry::ScConditionEntry( ScDocument& rDocument, const 
ScConditionEntry& r ) :
-    ScFormatEntry(&rDocument),
+    ScFormatEntry(rDocument),
     eOp(r.eOp),
     nOptions(r.nOptions),
     nVal1(r.nVal1),
@@ -248,7 +248,7 @@ ScConditionEntry::ScConditionEntry( ScConditionMode eOper,
         const OUString& rExprNmsp1, const OUString& rExprNmsp2,
         FormulaGrammar::Grammar eGrammar1, FormulaGrammar::Grammar eGrammar2,
         Type eType ) :
-    ScFormatEntry(&rDocument),
+    ScFormatEntry(rDocument),
     eOp(eOper),
     nOptions(0),
     nVal1(0.0),
@@ -276,7 +276,7 @@ ScConditionEntry::ScConditionEntry( ScConditionMode eOper,
 ScConditionEntry::ScConditionEntry( ScConditionMode eOper,
                                 const ScTokenArray* pArr1, const ScTokenArray* 
pArr2,
                                 ScDocument& rDocument, const ScAddress& rPos ) 
:
-    ScFormatEntry(&rDocument),
+    ScFormatEntry(rDocument),
     eOp(eOper),
     nOptions(0),
     nVal1(0.0),
@@ -298,13 +298,13 @@ ScConditionEntry::ScConditionEntry( ScConditionMode eOper,
     {
         pFormula1.reset( new ScTokenArray( *pArr1 ) );
         SimplifyCompiledFormula( pFormula1, nVal1, bIsStr1, aStrVal1 );
-        bRelRef1 = lcl_HasRelRef( mpDoc, pFormula1.get() );
+        bRelRef1 = lcl_HasRelRef( mrDoc, pFormula1.get() );
     }
     if ( pArr2 )
     {
         pFormula2.reset( new ScTokenArray( *pArr2 ) );
         SimplifyCompiledFormula( pFormula2, nVal2, bIsStr2, aStrVal2 );
-        bRelRef2 = lcl_HasRelRef( mpDoc, pFormula2.get() );
+        bRelRef2 = lcl_HasRelRef( mrDoc, pFormula2.get() );
     }
 
     StartListening();
@@ -353,16 +353,16 @@ void ScConditionEntry::Compile( const OUString& rExpr1, 
const OUString& rExpr2,
 {
     if ( !rExpr1.isEmpty() || !rExpr2.isEmpty() )
     {
-        ScCompiler aComp( *mpDoc, aSrcPos );
+        ScCompiler aComp( mrDoc, aSrcPos );
 
         if ( !rExpr1.isEmpty() )
         {
             pFormula1.reset();
             aComp.SetGrammar( eGrammar1 );
-            if ( mpDoc->IsImportingXML() && !bTextToReal )
+            if ( mrDoc.IsImportingXML() && !bTextToReal )
             {
                 //  temporary formula string as string tokens
-                pFormula1.reset( new ScTokenArray(*mpDoc) );
+                pFormula1.reset( new ScTokenArray(mrDoc) );
                 pFormula1->AssignXMLString( rExpr1, rExprNmsp1 );
                 // bRelRef1 is set when the formula is compiled again 
(CompileXML)
             }
@@ -370,7 +370,7 @@ void ScConditionEntry::Compile( const OUString& rExpr1, 
const OUString& rExpr2,
             {
                 pFormula1 = aComp.CompileString( rExpr1, rExprNmsp1 );
                 SimplifyCompiledFormula( pFormula1, nVal1, bIsStr1, aStrVal1 );
-                bRelRef1 = lcl_HasRelRef( mpDoc, pFormula1.get() );
+                bRelRef1 = lcl_HasRelRef( mrDoc, pFormula1.get() );
             }
         }
 
@@ -378,10 +378,10 @@ void ScConditionEntry::Compile( const OUString& rExpr1, 
const OUString& rExpr2,
         {
             pFormula2.reset();
             aComp.SetGrammar( eGrammar2 );
-            if ( mpDoc->IsImportingXML() && !bTextToReal )
+            if ( mrDoc.IsImportingXML() && !bTextToReal )
             {
                 //  temporary formula string as string tokens
-                pFormula2.reset( new ScTokenArray(*mpDoc) );
+                pFormula2.reset( new ScTokenArray(mrDoc) );
                 pFormula2->AssignXMLString( rExpr2, rExprNmsp2 );
                 // bRelRef2 is set when the formula is compiled again 
(CompileXML)
             }
@@ -389,7 +389,7 @@ void ScConditionEntry::Compile( const OUString& rExpr1, 
const OUString& rExpr2,
             {
                 pFormula2 = aComp.CompileString( rExpr2, rExprNmsp2 );
                 SimplifyCompiledFormula( pFormula2, nVal2, bIsStr2, aStrVal2 );
-                bRelRef2 = lcl_HasRelRef( mpDoc, pFormula2.get() );
+                bRelRef2 = lcl_HasRelRef( mrDoc, pFormula2.get() );
             }
         }
     }
@@ -402,25 +402,25 @@ void ScConditionEntry::Compile( const OUString& rExpr1, 
const OUString& rExpr2,
  */
 void ScConditionEntry::MakeCells( const ScAddress& rPos )
 {
-    if ( mpDoc->IsClipOrUndo() ) // Never calculate in the Clipboard!
+    if ( mrDoc.IsClipOrUndo() ) // Never calculate in the Clipboard!
         return;
 
     if ( pFormula1 && !pFCell1 && !bRelRef1 )
     {
         // pFCell1 will hold a flat-copied ScTokenArray sharing ref-counted
         // code tokens with pFormula1
-        pFCell1.reset( new ScFormulaCell(*mpDoc, rPos, *pFormula1) );
+        pFCell1.reset( new ScFormulaCell(mrDoc, rPos, *pFormula1) );
         pFCell1->SetFreeFlying(true);
-        pFCell1->StartListeningTo( *mpDoc );
+        pFCell1->StartListeningTo( mrDoc );
     }
 
     if ( pFormula2 && !pFCell2 && !bRelRef2 )
     {
         // pFCell2 will hold a flat-copied ScTokenArray sharing ref-counted
         // code tokens with pFormula2
-        pFCell2.reset( new ScFormulaCell(*mpDoc, rPos, *pFormula2) );
+        pFCell2.reset( new ScFormulaCell(mrDoc, rPos, *pFormula2) );
         pFCell2->SetFreeFlying(true);
-        pFCell2->StartListeningTo( *mpDoc );
+        pFCell2->StartListeningTo( mrDoc );
     }
 }
 
@@ -461,7 +461,7 @@ void ScConditionEntry::CompileXML()
         ScAddress aNew;
         /* XML is always in OOo:A1 format, although R1C1 would be more amenable
          * to compression */
-        if ( aNew.Parse( aSrcString, *mpDoc ) & ScRefFlags::VALID )
+        if ( aNew.Parse( aSrcString, mrDoc ) & ScRefFlags::VALID )
             aSrcPos = aNew;
         // if the position is invalid, there isn't much we can do at this time
         aSrcString.clear();
@@ -474,15 +474,15 @@ void ScConditionEntry::CompileXML()
 
     // Importing ocDde/ocWebservice?
     if (pFormula1)
-        mpDoc->CheckLinkFormulaNeedingCheck(*pFormula1);
+        mrDoc.CheckLinkFormulaNeedingCheck(*pFormula1);
     if (pFormula2)
-        mpDoc->CheckLinkFormulaNeedingCheck(*pFormula2);
+        mrDoc.CheckLinkFormulaNeedingCheck(*pFormula2);
 }
 
 void ScConditionEntry::SetSrcString( const OUString& rNew )
 {
     // aSrcString is only evaluated in CompileXML
-    SAL_WARN_IF( !mpDoc->IsImportingXML(), "sc", "SetSrcString is only valid 
for XML import" );
+    SAL_WARN_IF( !mrDoc.IsImportingXML(), "sc", "SetSrcString is only valid 
for XML import" );
 
     aSrcString = rNew;
 }
@@ -494,7 +494,7 @@ void ScConditionEntry::SetFormula1( const ScTokenArray& 
rArray )
     {
         pFormula1.reset( new ScTokenArray( rArray ) );
         SimplifyCompiledFormula(pFormula1, nVal1, bIsStr1, aStrVal1);
-        bRelRef1 = lcl_HasRelRef( mpDoc, pFormula1.get() );
+        bRelRef1 = lcl_HasRelRef( mrDoc, pFormula1.get() );
     }
 
     StartListening();
@@ -507,7 +507,7 @@ void ScConditionEntry::SetFormula2( const ScTokenArray& 
rArray )
     {
         pFormula2.reset( new ScTokenArray( rArray ) );
         SimplifyCompiledFormula(pFormula2, nVal2, bIsStr2, aStrVal2);
-        bRelRef2 = lcl_HasRelRef( mpDoc, pFormula2.get() );
+        bRelRef2 = lcl_HasRelRef( mrDoc, pFormula2.get() );
     }
 
     StartListening();
@@ -522,7 +522,7 @@ void ScConditionEntry::UpdateReference( 
sc::RefUpdateContext& rCxt )
     if (rCxt.meMode == URM_INSDEL && rCxt.maRange.Contains(aSrcPos))
     {
         ScAddress aErrorPos( ScAddress::UNINITIALIZED );
-        if (!aSrcPos.Move(rCxt.mnColDelta, rCxt.mnRowDelta, rCxt.mnTabDelta, 
aErrorPos, *mpDoc))
+        if (!aSrcPos.Move(rCxt.mnColDelta, rCxt.mnRowDelta, rCxt.mnTabDelta, 
aErrorPos, mrDoc))
         {
             assert(!"can't move ScConditionEntry");
         }
@@ -684,9 +684,9 @@ void ScConditionEntry::Interpret( const ScAddress& rPos )
     if ( bRelRef1 )
     {
         if (pFormula1)
-            oTemp.emplace(*mpDoc, rPos, *pFormula1);
+            oTemp.emplace(mrDoc, rPos, *pFormula1);
         else
-            oTemp.emplace(*mpDoc, rPos);
+            oTemp.emplace(mrDoc, rPos);
         pEff1 = &*oTemp;
         pEff1->SetFreeFlying(true);
     }
@@ -695,7 +695,7 @@ void ScConditionEntry::Interpret( const ScAddress& rPos )
         if (!pEff1->IsRunning()) // Don't create 522
         {
             //TODO: Query Changed instead of Dirty!
-            if (pEff1->GetDirty() && !bRelRef1 && mpDoc->GetAutoCalc())
+            if (pEff1->GetDirty() && !bRelRef1 && mrDoc.GetAutoCalc())
                 bDirty = true;
             if (pEff1->IsValue())
             {
@@ -717,9 +717,9 @@ void ScConditionEntry::Interpret( const ScAddress& rPos )
     if ( bRelRef2 )
     {
         if (pFormula2)
-            oTemp.emplace(*mpDoc, rPos, *pFormula2);
+            oTemp.emplace(mrDoc, rPos, *pFormula2);
         else
-            oTemp.emplace(*mpDoc, rPos);
+            oTemp.emplace(mrDoc, rPos);
         pEff2 = &*oTemp;
         pEff2->SetFreeFlying(true);
     }
@@ -727,7 +727,7 @@ void ScConditionEntry::Interpret( const ScAddress& rPos )
     {
         if (!pEff2->IsRunning()) // Don't create 522
         {
-            if (pEff2->GetDirty() && !bRelRef2 && mpDoc->GetAutoCalc())
+            if (pEff2->GetDirty() && !bRelRef2 && mrDoc.GetAutoCalc())
                 bDirty = true;
             if (pEff2->IsValue())
             {
@@ -756,7 +756,7 @@ void ScConditionEntry::Interpret( const ScAddress& rPos )
 }
 
 static bool lcl_GetCellContent( const ScRefCellValue& rCell, bool bIsStr1, 
double& rArg, OUString& rArgStr,
-        const ScDocument* pDoc )
+        const ScDocument& rDoc )
 {
 
     if (rCell.isEmpty())
@@ -784,7 +784,7 @@ static bool lcl_GetCellContent( const ScRefCellValue& 
rCell, bool bIsStr1, doubl
             if (rCell.getType() == CELLTYPE_STRING)
                 rArgStr = rCell.getSharedString()->getString();
             else if (rCell.getEditText())
-                rArgStr = ScEditUtil::GetString(*rCell.getEditText(), pDoc);
+                rArgStr = ScEditUtil::GetString(*rCell.getEditText(), &rDoc);
         break;
         default:
             ;
@@ -812,23 +812,23 @@ void ScConditionEntry::FillCache() const
 
         // temporary fix to workaround slow duplicate entry
         // conditions, prevent to use a whole row
-        if(nRow == mpDoc->MaxRow())
+        if(nRow == mrDoc.MaxRow())
         {
             bool bShrunk = false;
-            mpDoc->ShrinkToUsedDataArea(bShrunk, nTab, nColStart, nRowStart,
+            mrDoc.ShrinkToUsedDataArea(bShrunk, nTab, nColStart, nRowStart,
                     nCol, nRow, false);
         }
 
         for( SCROW r = nRowStart; r <= nRow; r++ )
             for( SCCOL c = nColStart; c <= nCol; c++ )
             {
-                ScRefCellValue aCell(*mpDoc, ScAddress(c, r, nTab));
+                ScRefCellValue aCell(mrDoc, ScAddress(c, r, nTab));
                 if (aCell.isEmpty())
                     continue;
 
                 double nVal = 0.0;
                 OUString aStr;
-                if (!lcl_GetCellContent(aCell, false, nVal, aStr, mpDoc))
+                if (!lcl_GetCellContent(aCell, false, nVal, aStr, mrDoc))
                 {
                     
std::pair<ScConditionEntryCache::StringCacheType::iterator, bool> aResult =
                         mpCache->maStrings.emplace(aStr, 1);
@@ -984,7 +984,7 @@ bool ScConditionEntry::IsAboveAverage( double nArg, bool 
bEqual ) const
 
 bool ScConditionEntry::IsError( const ScAddress& rPos ) const
 {
-    ScRefCellValue rCell(*mpDoc, rPos);
+    ScRefCellValue rCell(mrDoc, rPos);
 
     if (rCell.getType() == CELLTYPE_FORMULA)
     {
@@ -1270,7 +1270,7 @@ bool ScConditionEntry::IsCellValid( const ScRefCellValue& 
rCell, const ScAddress
 
     double nArg = 0.0;
     OUString aArgStr;
-    bool bVal = lcl_GetCellContent( rCell, bIsStr1, nArg, aArgStr, mpDoc );
+    bool bVal = lcl_GetCellContent( rCell, bIsStr1, nArg, aArgStr, mrDoc );
     if (bVal)
         return IsValid( nArg, rPos );
     else
@@ -1285,13 +1285,13 @@ OUString ScConditionEntry::GetExpression( const 
ScAddress& rCursor, sal_uInt16 n
     OUString aRet;
 
     if ( FormulaGrammar::isEnglish( eGrammar) && nNumFmt == 0 )
-        nNumFmt = mpDoc->GetFormatTable()->GetStandardIndex( 
LANGUAGE_ENGLISH_US );
+        nNumFmt = mrDoc.GetFormatTable()->GetStandardIndex( 
LANGUAGE_ENGLISH_US );
 
     if ( nIndex==0 )
     {
         if ( pFormula1 )
         {
-            ScCompiler aComp(*mpDoc, rCursor, *pFormula1, eGrammar);
+            ScCompiler aComp(mrDoc, rCursor, *pFormula1, eGrammar);
             OUStringBuffer aBuffer;
             aComp.CreateStringFromTokenArray( aBuffer );
             aRet = aBuffer.makeStringAndClear();
@@ -1301,13 +1301,13 @@ OUString ScConditionEntry::GetExpression( const 
ScAddress& rCursor, sal_uInt16 n
             aRet = "\"" + aStrVal1 + "\"";
         }
         else
-            aRet = mpDoc->GetFormatTable()->GetInputLineString(nVal1, nNumFmt);
+            aRet = mrDoc.GetFormatTable()->GetInputLineString(nVal1, nNumFmt);
     }
     else if ( nIndex==1 )
     {
         if ( pFormula2 )
         {
-            ScCompiler aComp(*mpDoc, rCursor, *pFormula2, eGrammar);
+            ScCompiler aComp(mrDoc, rCursor, *pFormula2, eGrammar);
             OUStringBuffer aBuffer;
             aComp.CreateStringFromTokenArray( aBuffer );
             aRet = aBuffer.makeStringAndClear();
@@ -1317,7 +1317,7 @@ OUString ScConditionEntry::GetExpression( const 
ScAddress& rCursor, sal_uInt16 n
             aRet = "\"" + aStrVal2 + "\"";
         }
         else
-            aRet = mpDoc->GetFormatTable()->GetInputLineString(nVal2, nNumFmt);
+            aRet = mrDoc.GetFormatTable()->GetInputLineString(nVal2, nNumFmt);
     }
 
     return aRet;
@@ -1334,10 +1334,10 @@ std::unique_ptr<ScTokenArray> 
ScConditionEntry::CreateFlatCopiedTokenArray( sal_
             pRet.reset(new ScTokenArray( *pFormula1 ));
         else
         {
-            pRet.reset(new ScTokenArray(*mpDoc));
+            pRet.reset(new ScTokenArray(mrDoc));
             if (bIsStr1)
             {
-                svl::SharedStringPool& rSPool = mpDoc->GetSharedStringPool();
+                svl::SharedStringPool& rSPool = mrDoc.GetSharedStringPool();
                 pRet->AddString(rSPool.intern(aStrVal1));
             }
             else
@@ -1350,10 +1350,10 @@ std::unique_ptr<ScTokenArray> 
ScConditionEntry::CreateFlatCopiedTokenArray( sal_
             pRet.reset(new ScTokenArray( *pFormula2 ));
         else
         {
-            pRet.reset(new ScTokenArray(*mpDoc));
+            pRet.reset(new ScTokenArray(mrDoc));
             if (bIsStr2)
             {
-                svl::SharedStringPool& rSPool = mpDoc->GetSharedStringPool();
+                svl::SharedStringPool& rSPool = mrDoc.GetSharedStringPool();
                 pRet->AddString(rSPool.intern(aStrVal2));
             }
             else
@@ -1381,7 +1381,7 @@ ScAddress ScConditionEntry::GetValidSrcPos() const
             for ( auto t: pFormula->References() )
             {
                 ScSingleRefData& rRef1 = *t->GetSingleRef();
-                ScAddress aAbs = rRef1.toAbs(*mpDoc, aSrcPos);
+                ScAddress aAbs = rRef1.toAbs(mrDoc, aSrcPos);
                 if (!rRef1.IsTabDeleted())
                 {
                     if (aAbs.Tab() < nMinTab)
@@ -1392,7 +1392,7 @@ ScAddress ScConditionEntry::GetValidSrcPos() const
                 if ( t->GetType() == svDoubleRef )
                 {
                     ScSingleRefData& rRef2 = t->GetDoubleRef()->Ref2;
-                    aAbs = rRef2.toAbs(*mpDoc, aSrcPos);
+                    aAbs = rRef2.toAbs(mrDoc, aSrcPos);
                     if (!rRef2.IsTabDeleted())
                     {
                         if (aAbs.Tab() < nMinTab)
@@ -1406,7 +1406,7 @@ ScAddress ScConditionEntry::GetValidSrcPos() const
     }
 
     ScAddress aValidPos = aSrcPos;
-    SCTAB nTabCount = mpDoc->GetTableCount();
+    SCTAB nTabCount = mrDoc.GetTableCount();
     if ( nMaxTab >= nTabCount && nMinTab > 0 )
         aValidPos.SetTab( aSrcPos.Tab() - nMinTab ); // so the lowest tab ref 
will be on 0
 
@@ -1428,14 +1428,14 @@ bool ScConditionEntry::MarkUsedExternalReferences() 
const
     {
         ScTokenArray* pFormula = nPass ? pFormula2.get() : pFormula1.get();
         if (pFormula)
-            bAllMarked = mpDoc->MarkUsedExternalReferences(*pFormula, aSrcPos);
+            bAllMarked = mrDoc.MarkUsedExternalReferences(*pFormula, aSrcPos);
     }
     return bAllMarked;
 }
 
-ScFormatEntry* ScConditionEntry::Clone(ScDocument* pDoc) const
+ScFormatEntry* ScConditionEntry::Clone(ScDocument& rDoc) const
 {
-    return new ScConditionEntry(*pDoc, *this);
+    return new ScConditionEntry(rDoc, *this);
 }
 
 ScConditionMode ScConditionEntry::GetModeFromApi(css::sheet::ConditionOperator 
nOperation)
@@ -1551,9 +1551,9 @@ void ScCondFormatEntry::DataChanged() const
         pCondFormat->DoRepaint();
 }
 
-ScFormatEntry* ScCondFormatEntry::Clone( ScDocument* pDoc ) const
+ScFormatEntry* ScCondFormatEntry::Clone( ScDocument& rDoc ) const
 {
-    return new ScCondFormatEntry( *pDoc, *this );
+    return new ScCondFormatEntry(rDoc, *this );
 }
 
 void ScConditionEntry::CalcAll()
@@ -1568,14 +1568,14 @@ void ScConditionEntry::CalcAll()
     }
 }
 
-ScCondDateFormatEntry::ScCondDateFormatEntry( ScDocument* pDoc )
-    : ScFormatEntry( pDoc )
+ScCondDateFormatEntry::ScCondDateFormatEntry( ScDocument& rDoc )
+    : ScFormatEntry( rDoc )
     , meType(condformat::TODAY)
 {
 }
 
-ScCondDateFormatEntry::ScCondDateFormatEntry( ScDocument* pDoc, const 
ScCondDateFormatEntry& rFormat ):
-    ScFormatEntry( pDoc ),
+ScCondDateFormatEntry::ScCondDateFormatEntry( ScDocument& rDoc, const 
ScCondDateFormatEntry& rFormat ):
+    ScFormatEntry( rDoc ),
     meType( rFormat.meType ),
     maStyleName( rFormat.maStyleName )
 {
@@ -1583,7 +1583,7 @@ ScCondDateFormatEntry::ScCondDateFormatEntry( ScDocument* 
pDoc, const ScCondDate
 
 bool ScCondDateFormatEntry::IsValid( const ScAddress& rPos ) const
 {
-    ScRefCellValue rCell(*mpDoc, rPos);
+    ScRefCellValue rCell(mrDoc, rPos);
 
     if (!rCell.hasNumeric())
         // non-numerical cell.
@@ -1593,7 +1593,7 @@ bool ScCondDateFormatEntry::IsValid( const ScAddress& 
rPos ) const
         mpCache.reset( new Date( Date::SYSTEM ) );
 
     const Date& rActDate = *mpCache;
-    SvNumberFormatter* pFormatter = mpDoc->GetFormatTable();
+    SvNumberFormatter* pFormatter = mrDoc.GetFormatTable();
     sal_Int32 nCurrentDate = rActDate - pFormatter->GetNullDate();
 
     double nVal = rCell.getValue();
@@ -1724,9 +1724,9 @@ void ScCondDateFormatEntry::SetStyleName( const OUString& 
rStyleName )
     maStyleName = rStyleName;
 }
 
-ScFormatEntry* ScCondDateFormatEntry::Clone( ScDocument* pDoc ) const
+ScFormatEntry* ScCondDateFormatEntry::Clone( ScDocument& rDoc ) const
 {
-    return new ScCondDateFormatEntry( pDoc, *this );
+    return new ScCondDateFormatEntry(rDoc, *this );
 }
 
 void ScCondDateFormatEntry::startRendering()
@@ -1769,8 +1769,8 @@ void ScColorFormatCache::Notify(const SfxHint& rHint)
 }
 
 
-ScConditionalFormat::ScConditionalFormat(sal_uInt32 nNewKey, ScDocument* 
pDocument) :
-    mpDoc( pDocument ),
+ScConditionalFormat::ScConditionalFormat(sal_uInt32 nNewKey, ScDocument& 
rDocument) :
+    mrDoc( rDocument ),
     mnKey( nNewKey )
 {
 }
@@ -1779,14 +1779,14 @@ std::unique_ptr<ScConditionalFormat> 
ScConditionalFormat::Clone(ScDocument* pNew
 {
     // Real copy of the formula (for Ref Undo/between documents)
     if (!pNewDoc)
-        pNewDoc = mpDoc;
+        pNewDoc = &mrDoc;
 
-    std::unique_ptr<ScConditionalFormat> pNew(new ScConditionalFormat(mnKey, 
pNewDoc));
+    std::unique_ptr<ScConditionalFormat> pNew(new ScConditionalFormat(mnKey, 
*pNewDoc));
     pNew->SetRange( maRanges );     // prerequisite for listeners
 
     for (const auto& rxEntry : maEntries)
     {
-        ScFormatEntry* pNewEntry = rxEntry->Clone(pNewDoc);
+        ScFormatEntry* pNewEntry = rxEntry->Clone(*pNewDoc);
         pNew->maEntries.push_back( std::unique_ptr<ScFormatEntry>(pNewEntry) );
         pNewEntry->SetParent(pNew.get());
     }
@@ -1845,9 +1845,9 @@ size_t ScConditionalFormat::size() const
     return maEntries.size();
 }
 
-ScDocument* ScConditionalFormat::GetDocument()
+ScDocument& ScConditionalFormat::GetDocument()
 {
-    return mpDoc;
+    return mrDoc;
 }
 
 ScConditionalFormat::~ScConditionalFormat()
@@ -1925,7 +1925,7 @@ ScCondFormatData ScConditionalFormat::GetData( const 
ScRefCellValue& rCell, cons
 void ScConditionalFormat::DoRepaint()
 {
     // all conditional format cells
-    mpDoc->RepaintRange( maRanges );
+    mrDoc.RepaintRange( maRanges );
 }
 
 void ScConditionalFormat::CompileAll()
@@ -1951,7 +1951,7 @@ void ScConditionalFormat::UpdateReference( 
sc::RefUpdateContext& rCxt, bool bCop
         // ScConditionEntry::UpdateReference() obtains its aSrcPos from
         // maRanges and does not update it on URM_COPY, but it's needed later
         // for the moved position, so update maRanges beforehand.
-        maRanges.UpdateReference(URM_MOVE, mpDoc, rCxt.maRange, 
rCxt.mnColDelta, rCxt.mnRowDelta, rCxt.mnTabDelta);
+        maRanges.UpdateReference(URM_MOVE, mrDoc, rCxt.maRange, 
rCxt.mnColDelta, rCxt.mnRowDelta, rCxt.mnTabDelta);
         for (auto& rxEntry : maEntries)
             rxEntry->UpdateReference(rCxt);
     }
@@ -1959,7 +1959,7 @@ void ScConditionalFormat::UpdateReference( 
sc::RefUpdateContext& rCxt, bool bCop
     {
         for (auto& rxEntry : maEntries)
             rxEntry->UpdateReference(rCxt);
-        maRanges.UpdateReference(rCxt.meMode, mpDoc, rCxt.maRange, 
rCxt.mnColDelta, rCxt.mnRowDelta, rCxt.mnTabDelta);
+        maRanges.UpdateReference(rCxt.meMode, mrDoc, rCxt.maRange, 
rCxt.mnColDelta, rCxt.mnRowDelta, rCxt.mnTabDelta);
     }
 
     ResetCache();
@@ -2146,8 +2146,8 @@ void ScConditionalFormat::CalcAll()
 
 void ScConditionalFormat::ResetCache() const
 {
-    if (!maRanges.empty() && mpDoc)
-        mpCache = std::make_unique<ScColorFormatCache>(*mpDoc, maRanges);
+    if (!maRanges.empty())
+        mpCache = std::make_unique<ScColorFormatCache>(mrDoc, maRanges);
     else
         mpCache.reset();
 }
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index b60a4cd1d6d1..2fb75cb6e777 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -222,7 +222,7 @@ ScDocument::ScDocument( ScDocumentMode eMode, ScDocShell* 
pDocShell ) :
     {
         mxPoolHelper = new ScPoolHelper( *this );
         if (!comphelper::IsFuzzing()) //just too slow
-            pBASM.reset( new ScBroadcastAreaSlotMachine( this ) );
+            pBASM.reset( new ScBroadcastAreaSlotMachine( *this ) );
         pChartListenerCollection.reset( new ScChartListenerCollection( *this ) 
);
         pRefreshTimerControl.reset( new ScRefreshTimerControl );
     }
@@ -777,12 +777,12 @@ bool ScDocument::MoveTab( SCTAB nOldPos, SCTAB nNewPos, 
ScProgress* pProgress )
                 pRangeName->UpdateMoveTab(aCxt);
 
             pDBCollection->UpdateMoveTab( nOldPos, nNewPos );
-            xColNameRanges->UpdateReference( URM_REORDER, this, aSourceRange, 
0,0,nDz );
-            xRowNameRanges->UpdateReference( URM_REORDER, this, aSourceRange, 
0,0,nDz );
+            xColNameRanges->UpdateReference( URM_REORDER, *this, aSourceRange, 
0,0,nDz );
+            xRowNameRanges->UpdateReference( URM_REORDER, *this, aSourceRange, 
0,0,nDz );
             if (pDPCollection)
                 pDPCollection->UpdateReference( URM_REORDER, aSourceRange, 
0,0,nDz );
             if (pDetOpList)
-                pDetOpList->UpdateReference( this, URM_REORDER, aSourceRange, 
0,0,nDz );
+                pDetOpList->UpdateReference( *this, URM_REORDER, aSourceRange, 
0,0,nDz );
             UpdateChartRef( URM_REORDER,
                     0,0,nOldPos, MaxCol(),MaxRow(),nOldPos, 0,0,nDz );
             UpdateRefAreaLinks( URM_REORDER, aSourceRange, 0,0,nDz );
@@ -853,8 +853,8 @@ bool ScDocument::CopyTab( SCTAB nOldPos, SCTAB nNewPos, 
const ScMarkData* pOnlyM
                 SetNoListening( true );
 
                 ScRange aRange( 0,0,nNewPos, MaxCol(),MaxRow(),MAXTAB );
-                xColNameRanges->UpdateReference( URM_INSDEL, this, aRange, 
0,0,1 );
-                xRowNameRanges->UpdateReference( URM_INSDEL, this, aRange, 
0,0,1 );
+                xColNameRanges->UpdateReference( URM_INSDEL, *this, aRange, 
0,0,1 );
+                xRowNameRanges->UpdateReference( URM_INSDEL, *this, aRange, 
0,0,1 );
                 if (pRangeName)
                     pRangeName->UpdateInsertTab(aCxt);
 
@@ -863,7 +863,7 @@ bool ScDocument::CopyTab( SCTAB nOldPos, SCTAB nNewPos, 
const ScMarkData* pOnlyM
                 if (pDPCollection)
                     pDPCollection->UpdateReference( URM_INSDEL, aRange, 0,0,1 
);
                 if (pDetOpList)
-                    pDetOpList->UpdateReference( this, URM_INSDEL, aRange, 
0,0,1 );
+                    pDetOpList->UpdateReference( *this, URM_INSDEL, aRange, 
0,0,1 );
                 UpdateChartRef( URM_INSDEL, 0,0,nNewPos, 
MaxCol(),MaxRow(),MAXTAB, 0,0,1 );
                 UpdateRefAreaLinks( URM_INSDEL, aRange, 0,0,1 );
                 if ( pUnoBroadcaster )
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index 3c95015874c0..52529d721aaa 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -1042,8 +1042,8 @@ void ScDocument::UpdateReference(
         SCROW nRow1 = rCxt.maRange.aStart.Row(), nRow2 = 
rCxt.maRange.aEnd.Row();
         SCTAB nTab1 = rCxt.maRange.aStart.Tab(), nTab2 = 
rCxt.maRange.aEnd.Tab();
 
-        xColNameRanges->UpdateReference( eUpdateRefMode, this, aRange, nDx, 
nDy, nDz );
-        xRowNameRanges->UpdateReference( eUpdateRefMode, this, aRange, nDx, 
nDy, nDz );
+        xColNameRanges->UpdateReference( eUpdateRefMode, *this, aRange, nDx, 
nDy, nDz );
+        xRowNameRanges->UpdateReference( eUpdateRefMode, *this, aRange, nDx, 
nDy, nDz );
         pDBCollection->UpdateReference( eUpdateRefMode, nCol1, nRow1, nTab1, 
nCol2, nRow2, nTab2, nDx, nDy, nDz );
         if (pRangeName)
             pRangeName->UpdateReference(rCxt);
@@ -1057,7 +1057,7 @@ void ScDocument::UpdateReference(
             pValidationList->UpdateReference(rCxt);
         }
         if ( pDetOpList )
-            pDetOpList->UpdateReference( this, eUpdateRefMode, aRange, nDx, 
nDy, nDz );
+            pDetOpList->UpdateReference( *this, eUpdateRefMode, aRange, nDx, 
nDy, nDz );
         if ( pUnoBroadcaster )
             pUnoBroadcaster->Broadcast( ScUpdateRefHint(
                                 eUpdateRefMode, aRange, nDx, nDy, nDz ) );
@@ -1098,7 +1098,7 @@ void ScDocument::UpdateReference(
         SCROW nRow1 = rCxt.maRange.aStart.Row(), nRow2 = 
rCxt.maRange.aEnd.Row();
         SCTAB nTab1 = rCxt.maRange.aStart.Tab(), nTab2 = 
rCxt.maRange.aEnd.Tab();
 
-        if ( ScRefUpdate::Update( this, eUpdateRefMode, nCol1,nRow1,nTab1, 
nCol2,nRow2,nTab2,
+        if ( ScRefUpdate::Update( *this, eUpdateRefMode, nCol1,nRow1,nTab1, 
nCol2,nRow2,nTab2,
                                     nDx,nDy,nDz, theCol1,theRow1,theTab1, 
theCol2,theRow2,theTab2 ) )
         {
             aEmbedRange = ScRange( theCol1,theRow1,theTab1, 
theCol2,theRow2,theTab2 );
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index d69d71913238..0b736ca449c9 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -730,7 +730,7 @@ sal_uInt32 ScDocument::AddValidationEntry( const 
ScValidationData& rNew )
 
     // might be called from ScPatternAttr::MigrateToDocument; thus clone (real 
copy)
     sal_uInt32 nNewKey = nMax + 1;
-    std::unique_ptr<ScValidationData> pInsert(rNew.Clone(this));
+    std::unique_ptr<ScValidationData> pInsert(rNew.Clone(*this));
     pInsert->SetKey( nNewKey );
     ScMutationGuard aGuard(*this, ScMutationGuardFlags::CORE);
     pValidationList->InsertNew( std::move(pInsert) );
diff --git a/sc/source/core/data/documen5.cxx b/sc/source/core/data/documen5.cxx
index 7e2aa26679ce..ebf92ef634e7 100644
--- a/sc/source/core/data/documen5.cxx
+++ b/sc/source/core/data/documen5.cxx
@@ -417,7 +417,7 @@ void ScDocument::UpdateChartRef( UpdateRefMode 
eUpdateRefMode,
             SCROW theRow2 = rRange.aEnd.Row();
             SCTAB theTab2 = rRange.aEnd.Tab();
             ScRefUpdateRes eRes = ScRefUpdate::Update(
-                this, eUpdateRefMode,
+                *this, eUpdateRefMode,
                 nCol1,nRow1,nTab1, nCol2,nRow2,nTab2,
                 nDx,nDy,nDz,
                 theCol1,theRow1,theTab1,
diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 9ef1045a3a63..16443d1b84fe 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -1103,7 +1103,7 @@ void ScDocument::UpdateRefAreaLinks( UpdateRefMode 
eUpdateRefMode,
             SCTAB nTab2 = aOutRange.aEnd.Tab();
 
             ScRefUpdateRes eRes =
-                ScRefUpdate::Update( this, eUpdateRefMode,
+                ScRefUpdate::Update( *this, eUpdateRefMode,
                     rRange.aStart.Col(), rRange.aStart.Row(), 
rRange.aStart.Tab(),
                     rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aEnd.Tab(), 
nDx, nDy, nDz,
                     nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index c1fcaff47ab3..029d53e0f393 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -516,8 +516,8 @@ bool ScDocument::InsertTab(
                 sc::RefUpdateInsertTabContext aCxt( *this, nPos, 1);
 
                 ScRange aRange( 0,0,nPos, MaxCol(),MaxRow(),MAXTAB );
-                xColNameRanges->UpdateReference( URM_INSDEL, this, aRange, 
0,0,1 );
-                xRowNameRanges->UpdateReference( URM_INSDEL, this, aRange, 
0,0,1 );
+                xColNameRanges->UpdateReference( URM_INSDEL, *this, aRange, 
0,0,1 );
+                xRowNameRanges->UpdateReference( URM_INSDEL, *this, aRange, 
0,0,1 );
                 if (pRangeName)
                     pRangeName->UpdateInsertTab(aCxt);
                 pDBCollection->UpdateReference(
@@ -525,7 +525,7 @@ bool ScDocument::InsertTab(
                 if (pDPCollection)
                     pDPCollection->UpdateReference( URM_INSDEL, aRange, 0,0,1 
);
                 if (pDetOpList)
-                    pDetOpList->UpdateReference( this, URM_INSDEL, aRange, 
0,0,1 );
+                    pDetOpList->UpdateReference( *this, URM_INSDEL, aRange, 
0,0,1 );
                 UpdateChartRef( URM_INSDEL, 0,0,nPos, 
MaxCol(),MaxRow(),MAXTAB, 0,0,1 );
                 UpdateRefAreaLinks( URM_INSDEL, aRange, 0,0,1 );
                 if ( pUnoBroadcaster )
@@ -603,8 +603,8 @@ bool ScDocument::InsertTabs( SCTAB nPos, const 
std::vector<OUString>& rNames,
             {
                 sc::RefUpdateInsertTabContext aCxt( *this, nPos, nNewSheets);
                 ScRange aRange( 0,0,nPos, MaxCol(),MaxRow(),MAXTAB );
-                xColNameRanges->UpdateReference( URM_INSDEL, this, aRange, 
0,0,nNewSheets );
-                xRowNameRanges->UpdateReference( URM_INSDEL, this, aRange, 
0,0,nNewSheets );
+                xColNameRanges->UpdateReference( URM_INSDEL, *this, aRange, 
0,0,nNewSheets );
+                xRowNameRanges->UpdateReference( URM_INSDEL, *this, aRange, 
0,0,nNewSheets );
                 if (pRangeName)
                     pRangeName->UpdateInsertTab(aCxt);
                 pDBCollection->UpdateReference(
@@ -612,7 +612,7 @@ bool ScDocument::InsertTabs( SCTAB nPos, const 
std::vector<OUString>& rNames,
                 if (pDPCollection)
                     pDPCollection->UpdateReference( URM_INSDEL, aRange, 
0,0,nNewSheets );
                 if (pDetOpList)
-                    pDetOpList->UpdateReference( this, URM_INSDEL, aRange, 
0,0,nNewSheets );
+                    pDetOpList->UpdateReference( *this, URM_INSDEL, aRange, 
0,0,nNewSheets );
                 UpdateChartRef( URM_INSDEL, 0,0,nPos, 
MaxCol(),MaxRow(),MAXTAB, 0,0,nNewSheets );
                 UpdateRefAreaLinks( URM_INSDEL, aRange, 0,0, nNewSheets );
                 if ( pUnoBroadcaster )
@@ -692,8 +692,8 @@ bool ScDocument::DeleteTab( SCTAB nTab )
             // normal reference update
 
             aRange.aEnd.SetTab(GetTableCount() - 1);
-            xColNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,-1 
);
-            xRowNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,-1 
);
+            xColNameRanges->UpdateReference( URM_INSDEL, *this, aRange, 0,0,-1 
);
+            xRowNameRanges->UpdateReference( URM_INSDEL, *this, aRange, 0,0,-1 
);
             if (pRangeName)
                 pRangeName->UpdateDeleteTab(aCxt);
             pDBCollection->UpdateReference(
@@ -701,7 +701,7 @@ bool ScDocument::DeleteTab( SCTAB nTab )
             if (pDPCollection)
                 pDPCollection->UpdateReference( URM_INSDEL, aRange, 0,0,-1 );
             if (pDetOpList)
-                pDetOpList->UpdateReference( this, URM_INSDEL, aRange, 0,0,-1 
);
+                pDetOpList->UpdateReference( *this, URM_INSDEL, aRange, 0,0,-1 
);
             UpdateChartRef( URM_INSDEL, 0,0,nTab, MaxCol(),MaxRow(),MAXTAB, 
0,0,-1 );
             UpdateRefAreaLinks( URM_INSDEL, aRange, 0,0,-1 );
             if (pValidationList)
@@ -791,14 +791,14 @@ bool ScDocument::DeleteTabs( SCTAB nTab, SCTAB nSheets )
             // normal reference update
 
             ScRange aRange( 0, 0, nTab, MaxCol(), MaxRow(), nTabCount - 1 );
-            xColNameRanges->UpdateReference( URM_INSDEL, this, aRange, 
0,0,-1*nSheets );
-            xRowNameRanges->UpdateReference( URM_INSDEL, this, aRange, 
0,0,-1*nSheets );
+            xColNameRanges->UpdateReference( URM_INSDEL, *this, aRange, 
0,0,-1*nSheets );
+            xRowNameRanges->UpdateReference( URM_INSDEL, *this, aRange, 
0,0,-1*nSheets );
             pDBCollection->UpdateReference(
                                 URM_INSDEL, 0,0,nTab, 
MaxCol(),MaxRow(),MAXTAB, 0,0,-1*nSheets );
             if (pDPCollection)
                 pDPCollection->UpdateReference( URM_INSDEL, aRange, 
0,0,-1*nSheets );
             if (pDetOpList)
-                pDetOpList->UpdateReference( this, URM_INSDEL, aRange, 
0,0,-1*nSheets );
+                pDetOpList->UpdateReference( *this, URM_INSDEL, aRange, 
0,0,-1*nSheets );
             UpdateChartRef( URM_INSDEL, 0,0,nTab, MaxCol(),MaxRow(),MAXTAB, 
0,0,-1*nSheets );
             UpdateRefAreaLinks( URM_INSDEL, aRange, 0,0,-1*nSheets );
             if (pValidationList)
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 5608384604cb..9727deaaf831 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -1075,7 +1075,7 @@ void ScDPObject::UpdateReference( UpdateRefMode 
eUpdateRefMode,
     SCTAB nTab2 = maOutputRange.aEnd.Tab();
 
     ScRefUpdateRes eRes =
-        ScRefUpdate::Update(mpDocument, eUpdateRefMode,
+        ScRefUpdate::Update(*mpDocument, eUpdateRefMode,
             rRange.aStart.Col(), rRange.aStart.Row(), rRange.aStart.Tab(),
             rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aEnd.Tab(), nDx, nDy, 
nDz,
             nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
@@ -1100,7 +1100,7 @@ void ScDPObject::UpdateReference( UpdateRefMode 
eUpdateRefMode,
     nRow2 = rSrcRange.aEnd.Row();
     nTab2 = rSrcRange.aEnd.Tab();
 
-    eRes = ScRefUpdate::Update(mpDocument, eUpdateRefMode,
+    eRes = ScRefUpdate::Update(*mpDocument, eUpdateRefMode,
             rRange.aStart.Col(), rRange.aStart.Row(), rRange.aStart.Tab(),
             rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aEnd.Tab(), nDx, nDy, 
nDz,
             nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
@@ -3077,7 +3077,7 @@ void ScDPCollection::SheetCaches::updateReference(
         SCTAB nTab2 = rKeyRange.aEnd.Tab();
 
         ScRefUpdateRes eRes = ScRefUpdate::Update(
-            &mrDoc, eMode,
+            mrDoc, eMode,
             r.aStart.Col(), r.aStart.Row(), r.aStart.Tab(),
             r.aEnd.Col(), r.aEnd.Row(), r.aEnd.Tab(), nDx, nDy, nDz,
             nCol1, nRow1, nTab1, nCol2, nRow2, nTab2);
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index cf22133056cf..9ccc26f2f247 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -1923,7 +1923,7 @@ void ScTable::UpdateReference(
             nERow = rPrintRange.aEnd.Row();
 
             // do not try to modify sheet index of print range
-            if ( ScRefUpdate::Update( &rDocument, eUpdateRefMode,
+            if ( ScRefUpdate::Update( rDocument, eUpdateRefMode,
                                       nCol1,nRow1,nTab, nCol2,nRow2,nTab,
                                       nDx,nDy,0,
                                       nSCol,nSRow,nSTab, nECol,nERow,nETab ) )
@@ -1941,7 +1941,7 @@ void ScTable::UpdateReference(
             nERow = moRepeatColRange->aEnd.Row();
 
             // do not try to modify sheet index of repeat range
-            if ( ScRefUpdate::Update( &rDocument, eUpdateRefMode,
+            if ( ScRefUpdate::Update( rDocument, eUpdateRefMode,
                                       nCol1,nRow1,nTab, nCol2,nRow2,nTab,
                                       nDx,nDy,0,
                                       nSCol,nSRow,nSTab, nECol,nERow,nETab ) )
@@ -1961,7 +1961,7 @@ void ScTable::UpdateReference(
             nERow = moRepeatRowRange->aEnd.Row();
 
             // do not try to modify sheet index of repeat range
-            if ( ScRefUpdate::Update( &rDocument, eUpdateRefMode,
+            if ( ScRefUpdate::Update( rDocument, eUpdateRefMode,
                                       nCol1,nRow1,nTab, nCol2,nRow2,nTab,
                                       nDx,nDy,0,
                                       nSCol,nSRow,nSTab, nECol,nERow,nETab ) )
diff --git a/sc/source/core/data/tabprotection.cxx 
b/sc/source/core/data/tabprotection.cxx
index 6f960c6d100a..789ef20168a7 100644
--- a/sc/source/core/data/tabprotection.cxx
+++ b/sc/source/core/data/tabprotection.cxx
@@ -435,7 +435,7 @@ bool ScTableProtectionImpl::updateReference( UpdateRefMode 
eMode, const ScDocume
     for (auto& rEnhancedProtection : maEnhancedProtection)
     {
         if (rEnhancedProtection.maRangeList.is())
-            bChanged |= rEnhancedProtection.maRangeList->UpdateReference( 
eMode, &rDoc, rWhere, nDx, nDy, nDz);
+            bChanged |= rEnhancedProtection.maRangeList->UpdateReference( 
eMode, rDoc, rWhere, nDx, nDy, nDz);
     }
     return bChanged;
 }
diff --git a/sc/source/core/data/validat.cxx b/sc/source/core/data/validat.cxx
index 6acc7185df42..54104849740b 100644
--- a/sc/source/core/data/validat.cxx
+++ b/sc/source/core/data/validat.cxx
@@ -127,7 +127,7 @@ ScValidationData::~ScValidationData()
 
 bool ScValidationData::IsEmpty() const
 {
-    ScValidationData aDefault( SC_VALID_ANY, ScConditionMode::Equal, u""_ustr, 
u""_ustr, *GetDocument(), ScAddress() );
+    ScValidationData aDefault( SC_VALID_ANY, ScConditionMode::Equal, u""_ustr, 
u""_ustr, GetDocument(), ScAddress() );
     return EqualEntries( aDefault );
 }
 
@@ -185,8 +185,8 @@ bool ScValidationData::GetErrMsg( OUString& rTitle, 
OUString& rMsg,
 bool ScValidationData::DoScript( const ScAddress& rPos, const OUString& rInput,
                                 ScFormulaCell* pCell, weld::Window* pParent ) 
const
 {
-    ScDocument* pDocument = GetDocument();
-    ScDocShell* pDocSh = pDocument->GetDocumentShell();
+    ScDocument& rDocument = GetDocument();
+    ScDocShell* pDocSh = rDocument.GetDocumentShell();
     if ( !pDocSh )
         return false;
 
@@ -203,19 +203,19 @@ bool ScValidationData::DoScript( const ScAddress& rPos, 
const OUString& rInput,
     }
 
     //  2) Position of the cell
-    OUString aPosStr(rPos.Format(ScRefFlags::VALID | ScRefFlags::TAB_3D, 
pDocument, pDocument->GetAddressConvention()));
+    OUString aPosStr(rPos.Format(ScRefFlags::VALID | ScRefFlags::TAB_3D, 
&rDocument, rDocument.GetAddressConvention()));
 
     // Set up parameters
     css::uno::Sequence< css::uno::Any > aParams{ aParam0, 
css::uno::Any(aPosStr) };
 
     //  use link-update flag to prevent closing the document
     //  while the macro is running
-    bool bWasInLinkUpdate = pDocument->IsInLinkUpdate();
+    bool bWasInLinkUpdate = rDocument.IsInLinkUpdate();
     if ( !bWasInLinkUpdate )
-        pDocument->SetInLinkUpdate( true );
+        rDocument.SetInLinkUpdate( true );
 
     if ( pCell )
-        pDocument->LockTable( rPos.Tab() );
+        rDocument.LockTable( rPos.Tab() );
 
     css::uno::Any aRet;
     css::uno::Sequence< sal_Int16 > aOutArgsIndex;
@@ -225,10 +225,10 @@ bool ScValidationData::DoScript( const ScAddress& rPos, 
const OUString& rInput,
         aErrorTitle, aParams, aRet, aOutArgsIndex, aOutArgs );
 
     if ( pCell )
-        pDocument->UnlockTable( rPos.Tab() );
+        rDocument.UnlockTable( rPos.Tab() );
 
     if ( !bWasInLinkUpdate )
-        pDocument->SetInLinkUpdate( false );
+        rDocument.SetInLinkUpdate( false );
 
     // Check the return value from the script
     // The contents of the cell get reset if the script returns false
@@ -264,8 +264,8 @@ bool ScValidationData::DoMacro( const ScAddress& rPos, 
const OUString& rInput,
         return DoScript( rPos, rInput, pCell, pParent );
     }
 
-    ScDocument* pDocument = GetDocument();
-    ScDocShell* pDocSh = pDocument->GetDocumentShell();
+    ScDocument& rDocument = GetDocument();
+    ScDocShell* pDocSh = rDocument.GetDocumentShell();
     if ( !pDocSh )
         return false;
 
@@ -323,24 +323,24 @@ bool ScValidationData::DoMacro( const ScAddress& rPos, 
const OUString& rInput,
             refPar->Get(1)->PutString(aValStr);
 
         //  2) Position of the cell
-        OUString aPosStr(rPos.Format(ScRefFlags::VALID | ScRefFlags::TAB_3D, 
pDocument, pDocument->GetAddressConvention()));
+        OUString aPosStr(rPos.Format(ScRefFlags::VALID | ScRefFlags::TAB_3D, 
&rDocument, rDocument.GetAddressConvention()));
         refPar->Get(2)->PutString(aPosStr);
 
         //  use link-update flag to prevent closing the document
         //  while the macro is running
-        bool bWasInLinkUpdate = pDocument->IsInLinkUpdate();
+        bool bWasInLinkUpdate = rDocument.IsInLinkUpdate();
         if ( !bWasInLinkUpdate )
-            pDocument->SetInLinkUpdate( true );
+            rDocument.SetInLinkUpdate( true );
 
         if ( pCell )
-            pDocument->LockTable( rPos.Tab() );
+            rDocument.LockTable( rPos.Tab() );
         SbxVariableRef refRes = new SbxVariable;
         ErrCode eRet = pDocSh->CallBasic( aMacroStr, aBasicStr, refPar.get(), 
refRes.get() );
         if ( pCell )
-            pDocument->UnlockTable( rPos.Tab() );
+            rDocument.UnlockTable( rPos.Tab() );
 
         if ( !bWasInLinkUpdate )
-            pDocument->SetInLinkUpdate( false );
+            rDocument.SetInLinkUpdate( false );
 
         //  Interrupt input if Basic macro returns false
         if ( eRet == ERRCODE_NONE && refRes->GetType() == SbxBOOL && 
!refRes->GetBool() )
@@ -459,7 +459,7 @@ bool ScValidationData::IsDataValidCustom(
     }
     else
     {
-        pFormatter = GetDocument()->GetFormatTable();
+        pFormatter = GetDocument().GetFormatTable();
 
         // get the value if any
         nFormat = rPattern.GetNumberFormat(pFormatter);
@@ -475,15 +475,15 @@ bool ScValidationData::IsDataValidCustom(
     }
     else
     {
-        aSS = mpDoc->GetSharedStringPool().intern(rStrResult);
+        aSS = mrDoc.GetSharedStringPool().intern(rStrResult);
         aTmpCell = ScRefCellValue(&aSS);
     }
 
-    ScCellValue aOriginalCellValue(ScRefCellValue(*GetDocument(), rPos));
+    ScCellValue aOriginalCellValue(ScRefCellValue(GetDocument(), rPos));
 
-    aTmpCell.commit(*GetDocument(), rPos);
+    aTmpCell.commit(GetDocument(), rPos);
     bool bRet = IsCellValid(aTmpCell, rPos);
-    aOriginalCellValue.commit(*GetDocument(), rPos);
+    aOriginalCellValue.commit(GetDocument(), rPos);
 
     return bRet;
 }
@@ -521,7 +521,7 @@ bool ScValidationData::IsDataValidTextLen( 
std::u16string_view rTest, const ScAd
     else
     {
         if (!pDataNumeric->mpFormatter)
-            pDataNumeric->init( *GetDocument(), rPos);
+            pDataNumeric->init( GetDocument(), rPos);
 
         // For numeric values use the resulting input line string to
         // determine length, otherwise an once accepted value maybe could
@@ -560,7 +560,7 @@ bool ScValidationData::IsDataValid(
     }
     else
     {
-        pFormatter = GetDocument()->GetFormatTable();
+        pFormatter = GetDocument().GetFormatTable();
 
         // get the value if any
         nFormat = rPattern.GetNumberFormat(pFormatter);
@@ -588,7 +588,7 @@ bool ScValidationData::IsDataValid(
         }
         else
         {
-            svl::SharedString aSS = mpDoc->GetSharedStringPool().intern( 
rStrResult );
+            svl::SharedString aSS = mrDoc.GetSharedStringPool().intern( 
rStrResult );
             ScRefCellValue aTmpCell(&aSS);
             bRet = IsDataValid(aTmpCell, rPos);
         }
@@ -620,7 +620,7 @@ bool ScValidationData::IsDataValid( const ScRefCellValue& 
rCell, const ScAddress
         break;
         case CELLTYPE_EDIT:
             if (rCell.getEditText())
-                aString = ScEditUtil::GetString(*rCell.getEditText(), 
GetDocument());
+                aString = ScEditUtil::GetString(*rCell.getEditText(), 
&GetDocument());
             bIsVal = false;
         break;
         case CELLTYPE_FORMULA:
@@ -674,7 +674,7 @@ bool ScValidationData::IsDataValid( const ScRefCellValue& 
rCell, const ScAddress
 bool ScValidationData::isFormulaResultsValidatable(const OUString& rTest, 
const ScAddress& rPos, SvNumberFormatter* pFormatter,
     OUString& rStrResult, double& nVal, sal_uInt32& nFormat, bool& bIsVal) 
const
 {
-    std::optional<ScSimpleFormulaCalculator> pFCell(std::in_place, *mpDoc, 
rPos, rTest, true);
+    std::optional<ScSimpleFormulaCalculator> pFCell(std::in_place, mrDoc, 
rPos, rTest, true);
     pFCell->SetLimitString(true);
 
     bool bColRowName = pFCell->HasColRowName();
@@ -685,7 +685,7 @@ bool ScValidationData::isFormulaResultsValidatable(const 
OUString& rTest, const
         {   // ==1: area
             // ==0: would be an area if...
             OUString aBraced = "(" + rTest + ")";
-            pFCell.emplace(*mpDoc, rPos, aBraced, true);
+            pFCell.emplace(mrDoc, rPos, aBraced, true);
             pFCell->SetLimitString(true);
         }
         else
-e 
... etc. - the rest is truncated

Reply via email to