[Libreoffice-commits] core.git: 2 commits - sc/inc sc/qa sc/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Thu Nov 14 20:25:05 UTC 2019


 sc/inc/address.hxx                                                |    4 
 sc/inc/grouparealistener.hxx                                      |    1 
 sc/inc/rangelst.hxx                                               |    2 
 sc/qa/unit/ucalc_pivottable.cxx                                   |    2 
 sc/qa/unit/ucalc_sort.cxx                                         |    2 
 sc/source/core/data/documen5.cxx                                  |    6 
 sc/source/core/tool/address.cxx                                   |   23 +-
 sc/source/core/tool/chgtrack.cxx                                  |    2 
 sc/source/core/tool/formulalogger.cxx                             |    2 
 sc/source/core/tool/grouparealistener.cxx                         |    5 
 sc/source/core/tool/rangelst.cxx                                  |    4 
 sc/source/core/tool/rangeutl.cxx                                  |    2 
 sc/source/filter/excel/excrecds.cxx                               |    4 
 sc/source/filter/excel/xecontent.cxx                              |    8 
 sc/source/filter/excel/xedbdata.cxx                               |    2 
 sc/source/filter/excel/xeescher.cxx                               |    2 
 sc/source/filter/excel/xeextlst.cxx                               |    2 
 sc/source/filter/excel/xelink.cxx                                 |    8 
 sc/source/filter/excel/xename.cxx                                 |    4 
 sc/source/filter/excel/xepivotxml.cxx                             |    4 
 sc/source/filter/excel/xestream.cxx                               |   12 -
 sc/source/filter/excel/xetable.cxx                                |    2 
 sc/source/filter/excel/xeview.cxx                                 |    2 
 sc/source/filter/inc/xestream.hxx                                 |    6 
 sc/source/filter/xcl97/XclExpChangeTrack.cxx                      |   12 -
 sc/source/filter/xcl97/xcl97rec.cxx                               |   14 -
 sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx       |    6 
 sc/source/ui/StatisticsDialogs/FourierAnalysisDialog.cxx          |    6 
 sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx    |    4 
 sc/source/ui/StatisticsDialogs/SamplingDialog.cxx                 |    4 
 sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog.cxx    |    4 
 sc/source/ui/StatisticsDialogs/StatisticsTwoVariableDialog.cxx    |   10 
 sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx |    4 
 sc/source/ui/app/inputhdl.cxx                                     |   10 
 sc/source/ui/app/inputwin.cxx                                     |    4 
 sc/source/ui/condformat/condformatdlg.cxx                         |    9 
 sc/source/ui/condformat/condformatmgr.cxx                         |    2 
 sc/source/ui/dbgui/PivotLayoutDialog.cxx                          |    4 
 sc/source/ui/dbgui/consdlg.cxx                                    |   10 
 sc/source/ui/dbgui/dbnamdlg.cxx                                   |    6 
 sc/source/ui/dbgui/foptmgr.cxx                                    |    2 
 sc/source/ui/dbgui/sfiltdlg.cxx                                   |    4 
 sc/source/ui/dbgui/validate.cxx                                   |    2 
 sc/source/ui/docshell/docfunc.cxx                                 |    2 
 sc/source/ui/docshell/impex.cxx                                   |    2 
 sc/source/ui/drawfunc/fuins2.cxx                                  |    6 
 sc/source/ui/formdlg/formula.cxx                                  |    2 
 sc/source/ui/inc/namedefdlg.hxx                                   |    2 
 sc/source/ui/miscdlgs/acredlin.cxx                                |    2 
 sc/source/ui/miscdlgs/crnrdlg.cxx                                 |   18 -
 sc/source/ui/miscdlgs/datastreamdlg.cxx                           |    2 
 sc/source/ui/miscdlgs/highred.cxx                                 |    4 
 sc/source/ui/miscdlgs/optsolver.cxx                               |    2 
 sc/source/ui/miscdlgs/simpref.cxx                                 |    2 
 sc/source/ui/miscdlgs/tabopdlg.cxx                                |    2 
 sc/source/ui/namedlg/namedefdlg.cxx                               |  113 ++++------
 sc/source/ui/namedlg/namedlg.cxx                                  |    2 
 sc/source/ui/navipi/content.cxx                                   |    4 
 sc/source/ui/optdlg/tpusrlst.cxx                                  |    2 
 sc/source/ui/pagedlg/areasdlg.cxx                                 |   12 -
 sc/source/ui/unoobj/addruno.cxx                                   |    2 
 sc/source/ui/unoobj/cellsuno.cxx                                  |    8 
 sc/source/ui/unoobj/chartuno.cxx                                  |    2 
 sc/source/ui/vba/vbapagesetup.cxx                                 |    2 
 sc/source/ui/vba/vbarange.cxx                                     |    2 
 sc/source/ui/view/cellsh.cxx                                      |    2 
 sc/source/ui/view/cellsh2.cxx                                     |    4 
 sc/source/ui/view/gridwin.cxx                                     |    6 
 sc/source/ui/view/gridwin2.cxx                                    |    6 
 sc/source/ui/view/viewfun6.cxx                                    |   10 
 70 files changed, 226 insertions(+), 225 deletions(-)

New commits:
commit 2c354558454e66c158c71164eaf56ad18433291c
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Thu Nov 14 12:49:07 2019 +0000
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Thu Nov 14 21:23:40 2019 +0100

    cid#1455325 establish that pDoc cannot be null there
    
    Change-Id: Ia7bca1e74a8ede90e29ec6cbd63c7fdcaf25b072
    Reviewed-on: https://gerrit.libreoffice.org/82696
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sc/inc/address.hxx b/sc/inc/address.hxx
index f38b216ecdb3..ebd9f022b1be 100644
--- a/sc/inc/address.hxx
+++ b/sc/inc/address.hxx
@@ -606,8 +606,8 @@ public:
         @returns
             String contains formatted cell range in address convention
      */
-    SC_DLLPUBLIC OUString Format( ScRefFlags nFlags = ScRefFlags::ZERO,
-                                  const ScDocument* pDocument = nullptr,
+    SC_DLLPUBLIC OUString Format( const ScDocument& rDocument,
+                                  ScRefFlags nFlags = ScRefFlags::ZERO,
                                   const ScAddress::Details& rDetails = ScAddress::detailsOOOa1,
                                   bool bFullAddressNotation = false ) const;
 
diff --git a/sc/inc/grouparealistener.hxx b/sc/inc/grouparealistener.hxx
index 0a044419b243..e892ded9a45c 100644
--- a/sc/inc/grouparealistener.hxx
+++ b/sc/inc/grouparealistener.hxx
@@ -27,6 +27,7 @@ class BulkDataHint;
 class FormulaGroupAreaListener final : public SvtListener
 {
     ScRange maRange;
+    const ScDocument& mrDocument;
     const ScColumn* mpColumn;
     SCROW mnTopCellRow;
     SCROW mnGroupLen;
diff --git a/sc/inc/rangelst.hxx b/sc/inc/rangelst.hxx
index c29284b0359d..6558c9539020 100644
--- a/sc/inc/rangelst.hxx
+++ b/sc/inc/rangelst.hxx
@@ -45,7 +45,7 @@ public:
                            formula::FormulaGrammar::AddressConvention eConv = formula::FormulaGrammar::CONV_OOO,
                            SCTAB nDefaultTab = 0, sal_Unicode cDelimiter = 0 );
 
-    void            Format( OUString&, ScRefFlags nFlags, const ScDocument*,
+    void            Format( OUString&, ScRefFlags nFlags, const ScDocument&,
                             formula::FormulaGrammar::AddressConvention eConv = formula::FormulaGrammar::CONV_OOO,
                             sal_Unicode cDelimiter = 0, bool bFullAddressNotation = false ) const;
 
diff --git a/sc/qa/unit/ucalc_pivottable.cxx b/sc/qa/unit/ucalc_pivottable.cxx
index 7c92556bb1e8..905a26ec0143 100644
--- a/sc/qa/unit/ucalc_pivottable.cxx
+++ b/sc/qa/unit/ucalc_pivottable.cxx
@@ -682,7 +682,7 @@ void Test::testPivotTableNamedSource()
 
     // Insert the raw data.
     ScRange aSrcRange = insertDPSourceData(m_pDoc, aFields, nFieldCount, aData, nDataCount);
-    OUString aRangeStr(aSrcRange.Format(ScRefFlags::RANGE_ABS_3D, m_pDoc));
+    OUString aRangeStr(aSrcRange.Format(*m_pDoc, ScRefFlags::RANGE_ABS_3D));
 
     // Name this range.
     OUString aRangeName("MyData");
diff --git a/sc/qa/unit/ucalc_sort.cxx b/sc/qa/unit/ucalc_sort.cxx
index bc44ac2e9ddc..c01cf53f231a 100644
--- a/sc/qa/unit/ucalc_sort.cxx
+++ b/sc/qa/unit/ucalc_sort.cxx
@@ -150,7 +150,7 @@ void Test::testSortHorizontal()
 
     // Insert raw data into A1:D4.
     ScRange aDataRange = insertRangeData(m_pDoc, ScAddress(0,0,0), aData, SAL_N_ELEMENTS(aData));
-    CPPUNIT_ASSERT_EQUAL(OUString("A1:D4"), aDataRange.Format(ScRefFlags::VALID));
+    CPPUNIT_ASSERT_EQUAL(OUString("A1:D4"), aDataRange.Format(*m_pDoc, ScRefFlags::VALID));
 
     // Check the formula values.
     CPPUNIT_ASSERT_EQUAL(OUString("Yes-No"), m_pDoc->GetString(ScAddress(3,1,0)));
diff --git a/sc/source/core/data/documen5.cxx b/sc/source/core/data/documen5.cxx
index 2000121fa892..cdab66a1b7e6 100644
--- a/sc/source/core/data/documen5.cxx
+++ b/sc/source/core/data/documen5.cxx
@@ -191,7 +191,7 @@ void ScDocument::SetChartRanges( const OUString& rChartName, const ::std::vector
         {
             ScRangeList aScRangeList( rRangesVector[nN] );
             OUString sRangeStr;
-            aScRangeList.Format( sRangeStr, ScRefFlags::RANGE_ABS_3D, this, GetAddressConvention() );
+            aScRangeList.Format( sRangeStr, ScRefFlags::RANGE_ABS_3D, *this, GetAddressConvention() );
             aRangeStrings[nN]=sRangeStr;
         }
         ScChartHelper::SetChartRanges( xChartDoc, aRangeStrings );
@@ -317,7 +317,7 @@ void ScDocument::UpdateChartArea( const OUString& rChartName,
                     }
 
                     OUString sRangeStr;
-                    aNewRanges->Format( sRangeStr, ScRefFlags::RANGE_ABS_3D, this, GetAddressConvention() );
+                    aNewRanges->Format( sRangeStr, ScRefFlags::RANGE_ABS_3D, *this, GetAddressConvention() );
 
                     lcl_SetChartParameters( xReceiver, sRangeStr, eDataRowSource, bHasCategories, bFirstCellAsLabel );
 
@@ -510,7 +510,7 @@ void ScDocument::SetChartRangeList( const OUString& rChartName,
                     lcl_GetChartParameters( xChartDoc, aRangesStr, eDataRowSource, bHasCategories, bFirstCellAsLabel );
 
                     OUString sRangeStr;
-                    rNewRangeListRef->Format( sRangeStr, ScRefFlags::RANGE_ABS_3D, this, GetAddressConvention() );
+                    rNewRangeListRef->Format( sRangeStr, ScRefFlags::RANGE_ABS_3D, *this, GetAddressConvention() );
 
                     lcl_SetChartParameters( xReceiver, sRangeStr, eDataRowSource, bHasCategories, bFirstCellAsLabel );
 
diff --git a/sc/source/core/tool/address.cxx b/sc/source/core/tool/address.cxx
index 6823277912ab..930833057634 100644
--- a/sc/source/core/tool/address.cxx
+++ b/sc/source/core/tool/address.cxx
@@ -2153,13 +2153,13 @@ static void lcl_Split_DocTab( const ScDocument& rDoc,  SCTAB nTab,
 }
 
 static void lcl_ScRange_Format_XL_Header( OUStringBuffer& rString, const ScRange& rRange,
-                                          ScRefFlags nFlags, const ScDocument* pDoc,
+                                          ScRefFlags nFlags, const ScDocument& rDoc,
                                           const ScAddress::Details& rDetails )
 {
     if( nFlags & ScRefFlags::TAB_3D )
     {
         OUString aTabName, aDocName;
-        lcl_Split_DocTab( *pDoc, rRange.aStart.Tab(), rDetails, nFlags, aTabName, aDocName );
+        lcl_Split_DocTab( rDoc, rRange.aStart.Tab(), rDetails, nFlags, aTabName, aDocName );
         switch (rDetails.eConv)
         {
             case formula::FormulaGrammar::CONV_XL_OOX:
@@ -2186,7 +2186,7 @@ static void lcl_ScRange_Format_XL_Header( OUStringBuffer& rString, const ScRange
         }
         if( nFlags & ScRefFlags::TAB2_3D )
         {
-            lcl_Split_DocTab( *pDoc, rRange.aEnd.Tab(), rDetails, nFlags, aTabName, aDocName );
+            lcl_Split_DocTab( rDoc, rRange.aEnd.Tab(), rDetails, nFlags, aTabName, aDocName );
             rString.append(":");
             rString.append(aTabName);
         }
@@ -2204,7 +2204,7 @@ static bool lcl_RowAbsFlagDiffer(const ScRefFlags nFlags)
     return static_cast<bool>(nFlags & ScRefFlags::ROW_ABS) != static_cast<bool>(nFlags & ScRefFlags::ROW2_ABS);
 }
 
-OUString ScRange::Format( ScRefFlags nFlags, const ScDocument* pDoc,
+OUString ScRange::Format( const ScDocument& rDoc, ScRefFlags nFlags,
                           const ScAddress::Details& rDetails, bool bFullAddressNotation ) const
 {
     if( !( nFlags & ScRefFlags::VALID ) )
@@ -2219,11 +2219,12 @@ OUString ScRange::Format( ScRefFlags nFlags, const ScDocument* pDoc,
         bool bOneTab = (aStart.Tab() == aEnd.Tab());
         if ( !bOneTab )
             nFlags |= ScRefFlags::TAB_3D;
-        r = aStart.Format(nFlags, pDoc, rDetails);
+        r = aStart.Format(nFlags, &rDoc, rDetails);
         if( aStart != aEnd ||
             lcl_ColAbsFlagDiffer( nFlags ) ||
             lcl_RowAbsFlagDiffer( nFlags ))
         {
+            const ScDocument* pDoc = &rDoc;
             // move flags of end reference to start reference, mask with BITS to exclude FORCE_DOC flag
             nFlags = ScRefFlags::VALID | (ScRefFlags(o3tl::underlyingEnumValue(nFlags) >> 4) & ScRefFlags::BITS);
             if ( bOneTab )
@@ -2239,10 +2240,10 @@ OUString ScRange::Format( ScRefFlags nFlags, const ScDocument* pDoc,
 
     case formula::FormulaGrammar::CONV_XL_A1:
     case formula::FormulaGrammar::CONV_XL_OOX: {
-        SCCOL nMaxCol = pDoc ? pDoc->MaxCol() : MAXCOL;
-        SCROW nMaxRow = pDoc ? pDoc->MaxRow() : MAXROW;
+        SCCOL nMaxCol = rDoc.MaxCol();
+        SCROW nMaxRow = rDoc.MaxRow();
 
-        lcl_ScRange_Format_XL_Header( r, *this, nFlags, pDoc, rDetails );
+        lcl_ScRange_Format_XL_Header( r, *this, nFlags, rDoc, rDetails );
         if( aStart.Col() == 0 && aEnd.Col() >= nMaxCol && !bFullAddressNotation )
         {
             // Full col refs always require 2 rows (2:2)
@@ -2274,10 +2275,10 @@ OUString ScRange::Format( ScRefFlags nFlags, const ScDocument* pDoc,
     }
 
     case formula::FormulaGrammar::CONV_XL_R1C1: {
-        SCCOL nMaxCol = pDoc ? pDoc->MaxCol() : MAXCOL;
-        SCROW nMaxRow = pDoc ? pDoc->MaxRow() : MAXROW;
+        SCCOL nMaxCol = rDoc.MaxCol();
+        SCROW nMaxRow = rDoc.MaxRow();
 
-        lcl_ScRange_Format_XL_Header( r, *this, nFlags, pDoc, rDetails );
+        lcl_ScRange_Format_XL_Header( r, *this, nFlags, rDoc, rDetails );
         if( aStart.Col() == 0 && aEnd.Col() >= nMaxCol && !bFullAddressNotation )
         {
             lcl_r1c1_append_r( r, aStart.Row(), (nFlags & ScRefFlags::ROW_ABS) != ScRefFlags::ZERO, rDetails );
diff --git a/sc/source/core/tool/chgtrack.cxx b/sc/source/core/tool/chgtrack.cxx
index f9254836a6a3..ba8c11ffa5ba 100644
--- a/sc/source/core/tool/chgtrack.cxx
+++ b/sc/source/core/tool/chgtrack.cxx
@@ -544,7 +544,7 @@ OUString ScChangeAction::GetRefString(
                 if ( bFlag3D || GetType() == SC_CAT_INSERT_TABS )
                     nFlags |= ScRefFlags::TAB_3D;
 
-                aBuf.append(aTmpRange.Format(nFlags, pDoc, pDoc->GetAddressConvention()));
+                aBuf.append(aTmpRange.Format(*pDoc, nFlags, pDoc->GetAddressConvention()));
             }
         }
         if ( (bFlag3D && IsDeleteType()) || IsDeletedIn() )
diff --git a/sc/source/core/tool/formulalogger.cxx b/sc/source/core/tool/formulalogger.cxx
index eeec1f81189b..9cddc2a46b9e 100644
--- a/sc/source/core/tool/formulalogger.cxx
+++ b/sc/source/core/tool/formulalogger.cxx
@@ -143,7 +143,7 @@ void FormulaLogger::GroupScope::addRefMessage(
 
     ScRange aRefRange(rRefPos);
     aRefRange.aEnd.IncRow(nLen-1);
-    OUString aRangeStr = aRefRange.Format(getRefFlags(rCellPos, rRefPos), &mpImpl->mrDoc);
+    OUString aRangeStr = aRefRange.Format(mpImpl->mrDoc, getRefFlags(rCellPos, rRefPos));
     aBuf.append(aRangeStr);
     aBuf.append(": ");
 
diff --git a/sc/source/core/tool/grouparealistener.cxx b/sc/source/core/tool/grouparealistener.cxx
index 44ca7d40003f..acbace1c4300 100644
--- a/sc/source/core/tool/grouparealistener.cxx
+++ b/sc/source/core/tool/grouparealistener.cxx
@@ -76,6 +76,7 @@ public:
 FormulaGroupAreaListener::FormulaGroupAreaListener( const ScRange& rRange, const ScDocument& rDocument,
         const ScAddress& rTopCellPos, SCROW nGroupLen, bool bStartFixed, bool bEndFixed ) :
     maRange(rRange),
+    mrDocument(rDocument),
     mpColumn(nullptr),
     mnTopCellRow(rTopCellPos.Row()),
     mnGroupLen(nGroupLen),
@@ -88,7 +89,7 @@ FormulaGroupAreaListener::FormulaGroupAreaListener( const ScRange& rRange, const
     assert(mpColumn);
     SAL_INFO( "sc.core.grouparealistener",
             "FormulaGroupAreaListener ctor this " << this <<
-            " range " << (maRange == BCA_LISTEN_ALWAYS ? "LISTEN-ALWAYS" : maRange.Format(ScRefFlags::VALID)) <<
+            " range " << (maRange == BCA_LISTEN_ALWAYS ? "LISTEN-ALWAYS" : maRange.Format(mrDocument, ScRefFlags::VALID)) <<
             " mnTopCellRow " << mnTopCellRow << " length " << mnGroupLen <<
             ", col/tab " << mpColumn->GetCol() << "/" << mpColumn->GetTab());
 }
@@ -177,7 +178,7 @@ void FormulaGroupAreaListener::collectFormulaCells(
 {
     SAL_INFO( "sc.core.grouparealistener",
             "FormulaGroupAreaListener::collectFormulaCells() this " << this <<
-            " range " << (maRange == BCA_LISTEN_ALWAYS ? "LISTEN-ALWAYS" : maRange.Format(ScRefFlags::VALID)) <<
+            " range " << (maRange == BCA_LISTEN_ALWAYS ? "LISTEN-ALWAYS" : maRange.Format(mrDocument, ScRefFlags::VALID)) <<
             " mnTopCellRow " << mnTopCellRow << " length " << mnGroupLen <<
             ", col/tab " << mpColumn->GetCol() << "/" << mpColumn->GetTab());
 
diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx
index fb5434bd1cb0..90bda2d1f9dc 100644
--- a/sc/source/core/tool/rangelst.cxx
+++ b/sc/source/core/tool/rangelst.cxx
@@ -144,7 +144,7 @@ ScRefFlags ScRangeList::Parse( const OUString& rStr, const ScDocument* pDoc,
         return ScRefFlags::ZERO;
 }
 
-void ScRangeList::Format( OUString& rStr, ScRefFlags nFlags, const ScDocument* pDoc,
+void ScRangeList::Format( OUString& rStr, ScRefFlags nFlags, const ScDocument& rDoc,
                           formula::FormulaGrammar::AddressConvention eConv,
                           sal_Unicode cDelimiter, bool bFullAddressNotation ) const
 {
@@ -159,7 +159,7 @@ void ScRangeList::Format( OUString& rStr, ScRefFlags nFlags, const ScDocument* p
             bFirst = false;
         else
             aBuf.append(OUStringChar(cDelimiter));
-        aBuf.append(r.Format(nFlags, pDoc, eConv, bFullAddressNotation));
+        aBuf.append(r.Format(rDoc, nFlags, eConv, bFullAddressNotation));
     }
     rStr = aBuf.makeStringAndClear();
 }
diff --git a/sc/source/core/tool/rangeutl.cxx b/sc/source/core/tool/rangeutl.cxx
index a2d146ff694b..8d398e1391ae 100644
--- a/sc/source/core/tool/rangeutl.cxx
+++ b/sc/source/core/tool/rangeutl.cxx
@@ -774,7 +774,7 @@ static void lcl_appendCellRangeAddress(
         ScRange aRange;
         aRange.aStart = rCell1;
         aRange.aEnd   = rCell2;
-        OUString aAddr(aRange.Format(ScRefFlags::RANGE_ABS_3D, pDoc, pDoc->GetAddressConvention()));
+        OUString aAddr(aRange.Format(*pDoc, ScRefFlags::RANGE_ABS_3D, pDoc->GetAddressConvention()));
         rBuf.append(aAddr);
     }
 }
diff --git a/sc/source/filter/excel/excrecds.cxx b/sc/source/filter/excel/excrecds.cxx
index 4fbe955d8b52..b68fa71e018a 100644
--- a/sc/source/filter/excel/excrecds.cxx
+++ b/sc/source/filter/excel/excrecds.cxx
@@ -484,7 +484,7 @@ void XclExpSheetProtection::SaveXml( XclExpXmlStream& rStrm )
                         XML_hashValue, rProt.maPasswordHash.maHashValue.isEmpty() ? nullptr : rProt.maPasswordHash.maHashValue.toUtf8().getStr(),
                         XML_saltValue, rProt.maPasswordHash.maSaltValue.isEmpty() ? nullptr : rProt.maPasswordHash.maSaltValue.toUtf8().getStr(),
                         XML_spinCount, rProt.maPasswordHash.mnSpinCount ? OString::number( rProt.maPasswordHash.mnSpinCount).getStr() : nullptr,
-                        XML_sqref, rProt.maRangeList.is() ? XclXmlUtils::ToOString( &rStrm.GetRoot().GetDoc(), *rProt.maRangeList).getStr() : nullptr);
+                        XML_sqref, rProt.maRangeList.is() ? XclXmlUtils::ToOString( rStrm.GetRoot().GetDoc(), *rProt.maRangeList).getStr() : nullptr);
             }
             rWorksheet->endElement( XML_protectedRanges);
         }
@@ -986,7 +986,7 @@ void ExcAutoFilterRecs::SaveXml( XclExpXmlStream& rStrm )
         return;
 
     sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
-    rWorksheet->startElement(XML_autoFilter, XML_ref, XclXmlUtils::ToOString(&rStrm.GetRoot().GetDoc(), maRef));
+    rWorksheet->startElement(XML_autoFilter, XML_ref, XclXmlUtils::ToOString(rStrm.GetRoot().GetDoc(), maRef));
     // OOXTODO: XML_extLst, XML_sortState
     if( !maFilterList.IsEmpty() )
         maFilterList.SaveXml( rStrm );
diff --git a/sc/source/filter/excel/xecontent.cxx b/sc/source/filter/excel/xecontent.cxx
index d1fa70c52dd5..98079cd96345 100644
--- a/sc/source/filter/excel/xecontent.cxx
+++ b/sc/source/filter/excel/xecontent.cxx
@@ -310,7 +310,7 @@ void XclExpMergedcells::SaveXml( XclExpXmlStream& rStrm )
     {
         const ScRange & rRange = maMergedRanges[ i ];
         rWorksheet->singleElement(XML_mergeCell, XML_ref,
-            XclXmlUtils::ToOString(&rStrm.GetRoot().GetDoc(), rRange));
+            XclXmlUtils::ToOString(rStrm.GetRoot().GetDoc(), rRange));
     }
     rWorksheet->endElement( XML_mergeCells );
 }
@@ -522,7 +522,7 @@ void XclExpHyperlink::SaveXml( XclExpXmlStream& rStrm )
             oox::getRelationship(Relationship::HYPERLINK),
             msTarget, true ) : OUString();
     rStrm.GetCurrentStream()->singleElement( XML_hyperlink,
-            XML_ref,                XclXmlUtils::ToOString(&rStrm.GetRoot().GetDoc(), maScPos),
+            XML_ref,                XclXmlUtils::ToOString(rStrm.GetRoot().GetDoc(), maScPos),
             FSNS( XML_r, XML_id ),  !sId.isEmpty()
                                        ? sId.toUtf8().getStr()
                                        : nullptr,
@@ -1357,7 +1357,7 @@ XclExpCondfmt::XclExpCondfmt( const XclExpRoot& rRoot, const ScConditionalFormat
                 else if(pFormatEntry->GetType() == ScFormatEntry::Type::Date)
                     maCFList.AppendNewRecord( new XclExpDateFormat( GetRoot(), static_cast<const ScCondDateFormatEntry&>(*pFormatEntry), ++rIndex ) );
             }
-        aScRanges.Format( msSeqRef, ScRefFlags::VALID, &GetDoc(), formula::FormulaGrammar::CONV_XL_OOX, ' ', true );
+        aScRanges.Format( msSeqRef, ScRefFlags::VALID, GetDoc(), formula::FormulaGrammar::CONV_XL_OOX, ' ', true );
 
         if(!aExtEntries.empty() && xExtLst.get())
         {
@@ -1851,7 +1851,7 @@ void XclExpDV::SaveXml( XclExpXmlStream& rStrm )
             XML_showDropDown,       ToPsz( ::get_flag( mnFlags, EXC_DV_SUPPRESSDROPDOWN ) ),
             XML_showErrorMessage,   ToPsz( ::get_flag( mnFlags, EXC_DV_SHOWERROR ) ),
             XML_showInputMessage,   ToPsz( ::get_flag( mnFlags, EXC_DV_SHOWPROMPT ) ),
-            XML_sqref,              XclXmlUtils::ToOString(&rStrm.GetRoot().GetDoc(), maScRanges),
+            XML_sqref,              XclXmlUtils::ToOString(rStrm.GetRoot().GetDoc(), maScRanges),
             XML_type,               lcl_GetValidationType(mnFlags) );
     if( !msFormula1.isEmpty() )
     {
diff --git a/sc/source/filter/excel/xedbdata.cxx b/sc/source/filter/excel/xedbdata.cxx
index 7dfb44eec058..6eacd6ef1a61 100644
--- a/sc/source/filter/excel/xedbdata.cxx
+++ b/sc/source/filter/excel/xedbdata.cxx
@@ -182,7 +182,7 @@ void XclExpTables::SaveTableXml( XclExpXmlStream& rStrm, const Entry& rEntry )
         XML_id, OString::number( rEntry.mnTableId),
         XML_name, rData.GetName().toUtf8(),
         XML_displayName, rData.GetName().toUtf8(),
-        XML_ref, XclXmlUtils::ToOString(&rStrm.GetRoot().GetDoc(), aRange),
+        XML_ref, XclXmlUtils::ToOString(rStrm.GetRoot().GetDoc(), aRange),
         XML_headerRowCount, ToPsz10(rData.HasHeader()),
         XML_totalsRowCount, ToPsz10(rData.HasTotals()),
         XML_totalsRowShown, ToPsz10(rData.HasTotals())  // we don't support that but if there are totals they are shown
diff --git a/sc/source/filter/excel/xeescher.cxx b/sc/source/filter/excel/xeescher.cxx
index c49e6a709177..44325e4804aa 100644
--- a/sc/source/filter/excel/xeescher.cxx
+++ b/sc/source/filter/excel/xeescher.cxx
@@ -1285,7 +1285,7 @@ void XclExpNote::WriteXml( sal_Int32 nAuthorId, XclExpXmlStream& rStrm )
     sax_fastparser::FSHelperPtr rComments = rStrm.GetCurrentStream();
 
     rComments->startElement( XML_comment,
-            XML_ref,        XclXmlUtils::ToOString(&mrRoot.GetDoc(), maScPos),
+            XML_ref,        XclXmlUtils::ToOString(mrRoot.GetDoc(), maScPos),
             XML_authorId,   OString::number(nAuthorId)
             // OOXTODO: XML_guid
     );
diff --git a/sc/source/filter/excel/xeextlst.cxx b/sc/source/filter/excel/xeextlst.cxx
index a3c25320ff72..f13335a6605b 100644
--- a/sc/source/filter/excel/xeextlst.cxx
+++ b/sc/source/filter/excel/xeextlst.cxx
@@ -464,7 +464,7 @@ void XclExpExtConditionalFormatting::SaveXml( XclExpXmlStream& rStrm )
 
     maCfRules.SaveXml( rStrm );
     rWorksheet->startElementNS(XML_xm, XML_sqref);
-    rWorksheet->write(XclXmlUtils::ToOString(&rStrm.GetRoot().GetDoc(), maRange));
+    rWorksheet->write(XclXmlUtils::ToOString(rStrm.GetRoot().GetDoc(), maRange));
 
     rWorksheet->endElementNS( XML_xm, XML_sqref );
 
diff --git a/sc/source/filter/excel/xelink.cxx b/sc/source/filter/excel/xelink.cxx
index 44fa0292f69d..4142ae5e625e 100644
--- a/sc/source/filter/excel/xelink.cxx
+++ b/sc/source/filter/excel/xelink.cxx
@@ -1230,26 +1230,26 @@ void XclExpCrn::SaveXml( XclExpXmlStream& rStrm )
             if (rtl::math::isFinite( fVal))
             {
                 // t='n' is omitted
-                pFS->startElement(XML_cell, XML_r, XclXmlUtils::ToOString(&rStrm.GetRoot().GetDoc(), aAdr));
+                pFS->startElement(XML_cell, XML_r, XclXmlUtils::ToOString(rStrm.GetRoot().GetDoc(), aAdr));
                 pFS->startElement(XML_v);
                 pFS->write( fVal );
             }
             else
             {
-                pFS->startElement(XML_cell, XML_r, XclXmlUtils::ToOString(&rStrm.GetRoot().GetDoc(), aAdr), XML_t, "e");
+                pFS->startElement(XML_cell, XML_r, XclXmlUtils::ToOString(rStrm.GetRoot().GetDoc(), aAdr), XML_t, "e");
                 pFS->startElement(XML_v);
                 pFS->write( "#VALUE!" );    // OOXTODO: support other error values
             }
         }
         else if( rValue.has< OUString >() )
         {
-            pFS->startElement(XML_cell, XML_r, XclXmlUtils::ToOString(&rStrm.GetRoot().GetDoc(), aAdr), XML_t, "str");
+            pFS->startElement(XML_cell, XML_r, XclXmlUtils::ToOString(rStrm.GetRoot().GetDoc(), aAdr), XML_t, "str");
             pFS->startElement(XML_v);
             pFS->write( rValue.get< OUString >() );
         }
         else if( rValue.has< bool >() )
         {
-            pFS->startElement(XML_cell, XML_r, XclXmlUtils::ToOString(&rStrm.GetRoot().GetDoc(), aAdr), XML_t, "b");
+            pFS->startElement(XML_cell, XML_r, XclXmlUtils::ToOString(rStrm.GetRoot().GetDoc(), aAdr), XML_t, "b");
             pFS->startElement(XML_v);
             pFS->write( rValue.get< bool >() ? "1" : "0" );
         }
diff --git a/sc/source/filter/excel/xename.cxx b/sc/source/filter/excel/xename.cxx
index 1e84fa0e0711..67a1fd3464df 100644
--- a/sc/source/filter/excel/xename.cxx
+++ b/sc/source/filter/excel/xename.cxx
@@ -446,7 +446,7 @@ sal_uInt16 XclExpNameManagerImpl::InsertBuiltInName( sal_Unicode cBuiltIn, const
     XclExpNameRef xName( new XclExpName( GetRoot(), cBuiltIn ) );
     xName->SetTokenArray( xTokArr );
     xName->SetLocalTab( aRange.aStart.Tab() );
-    OUString sSymbol(aRange.Format(ScRefFlags::RANGE_ABS_3D, &GetDoc(), ScAddress::Details( ::formula::FormulaGrammar::CONV_XL_A1)));
+    OUString sSymbol(aRange.Format(GetDoc(), ScRefFlags::RANGE_ABS_3D, ScAddress::Details( ::formula::FormulaGrammar::CONV_XL_A1)));
     xName->SetSymbol( sSymbol );
     return Append( xName );
 }
@@ -457,7 +457,7 @@ sal_uInt16 XclExpNameManagerImpl::InsertBuiltInName( sal_Unicode cBuiltIn, const
     xName->SetTokenArray( xTokArr );
     xName->SetLocalTab( nScTab );
     OUString sSymbol;
-    rRangeList.Format( sSymbol, ScRefFlags::RANGE_ABS_3D, &GetDoc(), ::formula::FormulaGrammar::CONV_XL_A1 );
+    rRangeList.Format( sSymbol, ScRefFlags::RANGE_ABS_3D, GetDoc(), ::formula::FormulaGrammar::CONV_XL_A1 );
     xName->SetSymbol( sSymbol );
     return Append( xName );
 }
diff --git a/sc/source/filter/excel/xepivotxml.cxx b/sc/source/filter/excel/xepivotxml.cxx
index e5af3d924863..28986d8632b0 100644
--- a/sc/source/filter/excel/xepivotxml.cxx
+++ b/sc/source/filter/excel/xepivotxml.cxx
@@ -271,7 +271,7 @@ void XclExpXmlPivotCaches::SavePivotCacheXml( XclExpXmlStream& rStrm, const Entr
     OUString aSheetName;
     GetDoc().GetName(rEntry.maSrcRange.aStart.Tab(), aSheetName);
     pDefStrm->singleElement(XML_worksheetSource,
-        XML_ref, XclXmlUtils::ToOString(&rStrm.GetRoot().GetDoc(), rEntry.maSrcRange),
+        XML_ref, XclXmlUtils::ToOString(rStrm.GetRoot().GetDoc(), rEntry.maSrcRange),
         XML_sheet, aSheetName.toUtf8());
 
     pDefStrm->endElement(XML_cacheSource);
@@ -864,7 +864,7 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP
 
     pPivotStrm->write("<")->writeId(XML_location);
     rStrm.WriteAttributes(XML_ref,
-        XclXmlUtils::ToOString(&rStrm.GetRoot().GetDoc(), aOutRange),
+        XclXmlUtils::ToOString(rStrm.GetRoot().GetDoc(), aOutRange),
         XML_firstHeaderRow, OUString::number(nFirstHeaderRow),
         XML_firstDataRow, OUString::number(nFirstDataRow),
         XML_firstDataCol, OUString::number(nFirstDataCol));
diff --git a/sc/source/filter/excel/xestream.cxx b/sc/source/filter/excel/xestream.cxx
index 19115bc86d68..ccfa2cfc9634 100644
--- a/sc/source/filter/excel/xestream.cxx
+++ b/sc/source/filter/excel/xestream.cxx
@@ -718,18 +718,18 @@ OString XclXmlUtils::ToOString( const ScfUInt16Vec& rBuffer )
         RTL_TEXTENCODING_UTF8);
 }
 
-OString XclXmlUtils::ToOString( const ScDocument* pDoc, const ScRange& rRange, bool bFullAddressNotation )
+OString XclXmlUtils::ToOString( const ScDocument& rDoc, const ScRange& rRange, bool bFullAddressNotation )
 {
-    OUString sRange(rRange.Format( ScRefFlags::VALID, pDoc,
+    OUString sRange(rRange.Format( rDoc, ScRefFlags::VALID,
                                    ScAddress::Details( FormulaGrammar::CONV_XL_A1 ),
                                    bFullAddressNotation ) );
     return sRange.toUtf8();
 }
 
-OString XclXmlUtils::ToOString( const ScDocument* pDoc, const ScRangeList& rRangeList )
+OString XclXmlUtils::ToOString( const ScDocument& rDoc, const ScRangeList& rRangeList )
 {
     OUString s;
-    rRangeList.Format(s, ScRefFlags::VALID, pDoc, FormulaGrammar::CONV_XL_OOX, ' ');
+    rRangeList.Format(s, ScRefFlags::VALID, rDoc, FormulaGrammar::CONV_XL_OOX, ' ');
     return s.toUtf8();
 }
 
@@ -768,14 +768,14 @@ static ScRange lcl_ToRange( const XclRange& rRange )
     return aRange;
 }
 
-OString XclXmlUtils::ToOString( const ScDocument* pDoc, const XclRangeList& rRanges )
+OString XclXmlUtils::ToOString( const ScDocument& rDoc, const XclRangeList& rRanges )
 {
     ScRangeList aRanges;
     for( const auto& rRange : rRanges )
     {
         aRanges.push_back( lcl_ToRange( rRange ) );
     }
-    return ToOString( pDoc, aRanges );
+    return ToOString( rDoc, aRanges );
 }
 
 OUString XclXmlUtils::ToOUString( const char* s )
diff --git a/sc/source/filter/excel/xetable.cxx b/sc/source/filter/excel/xetable.cxx
index 27c7a4960da5..4604b860172f 100644
--- a/sc/source/filter/excel/xetable.cxx
+++ b/sc/source/filter/excel/xetable.cxx
@@ -1524,7 +1524,7 @@ void XclExpDimensions::SaveXml( XclExpXmlStream& rStrm )
             // To be compatible with MS Office 2007,
             // we need full address notation format
             // e.g. "A1:AMJ177" and not partial like: "1:177".
-            XML_ref, XclXmlUtils::ToOString(&mrRoot.GetDoc(), aRange, true) );
+            XML_ref, XclXmlUtils::ToOString(mrRoot.GetDoc(), aRange, true) );
 }
 
 void XclExpDimensions::WriteBody( XclExpStream& rStrm )
diff --git a/sc/source/filter/excel/xeview.cxx b/sc/source/filter/excel/xeview.cxx
index b7efb0ac1a27..7fadf895eda5 100644
--- a/sc/source/filter/excel/xeview.cxx
+++ b/sc/source/filter/excel/xeview.cxx
@@ -232,7 +232,7 @@ void XclExpSelection::SaveXml( XclExpXmlStream& rStrm )
             XML_pane,           lcl_GetActivePane( mnPane ),
             XML_activeCell,     XclXmlUtils::ToOString( rStrm.GetRoot().GetStringBuf(), maSelData.maXclCursor ).getStr(),
             XML_activeCellId,   OString::number(maSelData.mnCursorIdx),
-            XML_sqref,          XclXmlUtils::ToOString(&rStrm.GetRoot().GetDoc(), maSelData.maXclSelection) );
+            XML_sqref,          XclXmlUtils::ToOString(rStrm.GetRoot().GetDoc(), maSelData.maXclSelection) );
 }
 
 void XclExpSelection::WriteBody( XclExpStream& rStrm )
diff --git a/sc/source/filter/inc/xestream.hxx b/sc/source/filter/inc/xestream.hxx
index 2a2a07bcca61..085e23fffaec 100644
--- a/sc/source/filter/inc/xestream.hxx
+++ b/sc/source/filter/inc/xestream.hxx
@@ -254,11 +254,11 @@ public:
     static OString ToOString( const Color& rColor );
     static OString ToOString( const ScfUInt16Vec& rBuffer );
     static OStringBuffer& ToOString( OStringBuffer& s, const ScAddress& rRange );
-    static OString ToOString( const ScDocument* pDoc, const ScRange& rRange, bool bFullAddressNotation = false );
-    static OString ToOString( const ScDocument* pDoc, const ScRangeList& rRangeList );
+    static OString ToOString( const ScDocument& rDoc, const ScRange& rRange, bool bFullAddressNotation = false );
+    static OString ToOString( const ScDocument& rDoc, const ScRangeList& rRangeList );
     static OStringBuffer& ToOString( OStringBuffer& s, const XclAddress& rAddress );
     static OString ToOString( const XclExpString& s );
-    static OString ToOString( const ScDocument* pDoc, const XclRangeList& rRangeList );
+    static OString ToOString( const ScDocument& rDoc, const XclRangeList& rRangeList );
 
     static OUString ToOUString( const char* s );
     static OUString ToOUString( const ScfUInt16Vec& rBuffer, sal_Int32 nStart = 0, sal_Int32 nLength = -1 );
diff --git a/sc/source/filter/xcl97/XclExpChangeTrack.cxx b/sc/source/filter/xcl97/XclExpChangeTrack.cxx
index b8d1cef7ada2..9a7ee2fa7392 100644
--- a/sc/source/filter/xcl97/XclExpChangeTrack.cxx
+++ b/sc/source/filter/xcl97/XclExpChangeTrack.cxx
@@ -992,7 +992,7 @@ static void lcl_WriteCell( XclExpXmlStream& rStrm, sal_Int32 nElement, const ScA
     sax_fastparser::FSHelperPtr pStream = rStrm.GetCurrentStream();
 
     pStream->startElement(nElement,
-        XML_r, XclXmlUtils::ToOString(&rStrm.GetRoot().GetDoc(), rPosition),
+        XML_r, XclXmlUtils::ToOString(rStrm.GetRoot().GetDoc(), rPosition),
         XML_s, nullptr,   // OOXTODO: not supported
         XML_t, lcl_GetType(pData),
         XML_cm, nullptr,   // OOXTODO: not supported
@@ -1053,7 +1053,7 @@ void XclExpChTrCellContent::SaveXml( XclExpXmlStream& rRevisionLogStrm )
         lcl_WriteCell( rRevisionLogStrm, XML_oc, aPosition, pOldData.get() );
         if (!pNewData)
         {
-            pStream->singleElement(XML_nc, XML_r, XclXmlUtils::ToOString(&rRevisionLogStrm.GetRoot().GetDoc(), aPosition));
+            pStream->singleElement(XML_nc, XML_r, XclXmlUtils::ToOString(rRevisionLogStrm.GetRoot().GetDoc(), aPosition));
         }
     }
     if( pNewData )
@@ -1169,7 +1169,7 @@ void XclExpChTrInsert::SaveXml( XclExpXmlStream& rRevisionLogStrm )
             XML_ra,     nullptr,       // OOXTODO: RRD.fUndoAction?  Or RRD.fAccepted?
             XML_sId,    OString::number(GetTabId(aRange.aStart.Tab())),
             XML_eol,    ToPsz10(mbEndOfList),
-            XML_ref,    XclXmlUtils::ToOString(&rRevisionLogStrm.GetRoot().GetDoc(), aRange),
+            XML_ref,    XclXmlUtils::ToOString(rRevisionLogStrm.GetRoot().GetDoc(), aRange),
             XML_action, lcl_GetAction( nOpCode ),
             XML_edge,   nullptr);      // OOXTODO: ???
 
@@ -1293,8 +1293,8 @@ void XclExpChTrMoveRange::SaveXml( XclExpXmlStream& rRevisionLogStrm )
             XML_ua,             ToPsz( GetAccepted () ),   // OOXTODO? bAccepted == ua or ra; not sure.
             XML_ra,             nullptr,       // OOXTODO: RRD.fUndoAction?  Or RRD.fAccepted?
             XML_sheetId,        OString::number(GetTabId(aDestRange.aStart.Tab())),
-            XML_source,         XclXmlUtils::ToOString(&rRevisionLogStrm.GetRoot().GetDoc(), aSourceRange),
-            XML_destination,    XclXmlUtils::ToOString(&rRevisionLogStrm.GetRoot().GetDoc(), aDestRange),
+            XML_source,         XclXmlUtils::ToOString(rRevisionLogStrm.GetRoot().GetDoc(), aSourceRange),
+            XML_destination,    XclXmlUtils::ToOString(rRevisionLogStrm.GetRoot().GetDoc(), aDestRange),
             XML_sourceSheetId,  OString::number(GetTabId(aSourceRange.aStart.Tab())) );
     // OOXTODO: does this handle XML_rfmt, XML_undo?
     XclExpChTrAction* pAction = GetAddAction();
@@ -1343,7 +1343,7 @@ void XclExpChTr0x014A::SaveXml( XclExpXmlStream& rStrm )
             XML_sheetId,    OString::number(GetTabId(aRange.aStart.Tab())),
             XML_xfDxf,      nullptr,   // OOXTODO: not supported
             XML_s,          nullptr,   // OOXTODO: style
-            XML_sqref,      XclXmlUtils::ToOString(&rStrm.GetRoot().GetDoc(), aRange),
+            XML_sqref,      XclXmlUtils::ToOString(rStrm.GetRoot().GetDoc(), aRange),
             XML_start,      nullptr,   // OOXTODO: for string changes
             XML_length,     nullptr);  // OOXTODO: for string changes
     // OOXTODO: XML_dxf, XML_extLst
diff --git a/sc/source/filter/xcl97/xcl97rec.cxx b/sc/source/filter/xcl97/xcl97rec.cxx
index 5597b635ecbd..da91d360aee3 100644
--- a/sc/source/filter/xcl97/xcl97rec.cxx
+++ b/sc/source/filter/xcl97/xcl97rec.cxx
@@ -1121,7 +1121,7 @@ ScRefFlags parseAddress(const OUString& rString, ScAddress& rAddress, const ScDo
     return rAddress.Parse(rString, pDoc, formula::FormulaGrammar::CONV_XL_R1C1);
 }
 
-void transformURL(const OUString& rOldURL, OUString& rNewURL, const ScDocument* pDoc)
+void transformURL(const OUString& rOldURL, OUString& rNewURL, const ScDocument& rDoc)
 {
     if (rOldURL.startsWith("#"))
     {
@@ -1132,19 +1132,19 @@ void transformURL(const OUString& rOldURL, OUString& rNewURL, const ScDocument*
 
         ScRange aRange;
         ScAddress aAddress;
-        ScRefFlags nResult = parseRange(aAddressString, aRange, pDoc);
+        ScRefFlags nResult = parseRange(aAddressString, aRange, &rDoc);
         if ( nResult & ScRefFlags::VALID )
         {
-            OUString aString = aRange.Format(nResult, pDoc, formula::FormulaGrammar::CONV_XL_OOX);
+            OUString aString = aRange.Format(rDoc, nResult, formula::FormulaGrammar::CONV_XL_OOX);
             rNewURL = "#" + aString;
             return;
         }
         else
         {
-            nResult = parseAddress(aAddressString, aAddress, pDoc);
+            nResult = parseAddress(aAddressString, aAddress, &rDoc);
             if( nResult & ScRefFlags::VALID )
             {
-                OUString aString = aAddress.Format(nResult, pDoc, formula::FormulaGrammar::CONV_XL_OOX);
+                OUString aString = aAddress.Format(nResult, &rDoc, formula::FormulaGrammar::CONV_XL_OOX);
                 rNewURL = "#" + aString;
                 return;
             }
@@ -1164,7 +1164,7 @@ ScURLTransformer::ScURLTransformer(ScDocument& rDoc)
 OUString ScURLTransformer::getTransformedString(const OUString& rURL) const
 {
     OUString aNewURL;
-    transformURL(rURL, aNewURL, &mrDoc);
+    transformURL(rURL, aNewURL, mrDoc);
     return aNewURL;
 }
 
@@ -1338,7 +1338,7 @@ void ExcEScenarioCell::SaveXml( XclExpXmlStream& rStrm ) const
     rStrm.GetCurrentStream()->singleElement( XML_inputCells,
             // OOXTODO: XML_deleted,
             // OOXTODO: XML_numFmtId,
-            XML_r,      XclXmlUtils::ToOString( &rStrm.GetRoot().GetDoc(), ScAddress( nCol, nRow, 0 ) ),
+            XML_r,      XclXmlUtils::ToOString( rStrm.GetRoot().GetDoc(), ScAddress( nCol, nRow, 0 ) ),
             // OOXTODO: XML_undone,
             XML_val,    XclXmlUtils::ToOString( sText ) );
 }
diff --git a/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx b/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx
index bdb4c51f350f..f508b0217b60 100644
--- a/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx
@@ -52,13 +52,13 @@ static const char strWildcardRange[] = "%RANGE%";
 
 OUString lclCreateMultiParameterFormula(
             ScRangeList&        aRangeList, const OUString& aFormulaTemplate,
-            const OUString&     aWildcard,  const ScDocument*     pDocument,
+            const OUString&     aWildcard,  const ScDocument& rDocument,
             const ScAddress::Details& aAddressDetails)
 {
     OUStringBuffer aResult;
     for (size_t i = 0; i < aRangeList.size(); i++)
     {
-        OUString aRangeString(aRangeList[i].Format(ScRefFlags::RANGE_ABS_3D, pDocument, aAddressDetails));
+        OUString aRangeString(aRangeList[i].Format(rDocument, ScRefFlags::RANGE_ABS_3D, aAddressDetails));
         OUString aFormulaString = aFormulaTemplate.replaceAll(aWildcard, aRangeString);
         aResult.append(aFormulaString);
         if(i != aRangeList.size() - 1) // Not Last
@@ -286,7 +286,7 @@ void ScAnalysisOfVarianceDialog::AnovaSingleFactor(AddressWalkerWriter& output,
         output.nextColumn();
 
         // Sum of Squares
-        OUString aSSPart = lclCreateMultiParameterFormula(aRangeList, "DEVSQ(%RANGE%)", strWildcardRange, &mDocument, mAddressDetails);
+        OUString aSSPart = lclCreateMultiParameterFormula(aRangeList, "DEVSQ(%RANGE%)", strWildcardRange, mDocument, mAddressDetails);
         aTemplate.setTemplate("=SUM(%RANGE%)");
         aTemplate.applyString(strWildcardRange, aSSPart);
         aTemplate.autoReplaceAddress("%WITHIN_SS%", output.current());
diff --git a/sc/source/ui/StatisticsDialogs/FourierAnalysisDialog.cxx b/sc/source/ui/StatisticsDialogs/FourierAnalysisDialog.cxx
index 635b83804226..70116e059077 100644
--- a/sc/source/ui/StatisticsDialogs/FourierAnalysisDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/FourierAnalysisDialog.cxx
@@ -209,9 +209,9 @@ void ScFourierAnalysisDialog::getDataLabel(OUString& rLabel)
         return;
     }
 
-    OUString aDataSrc(
-        mInputRange.Format(mbUse3DAddresses ? ScRefFlags::RANGE_ABS_3D : ScRefFlags::RANGE_ABS,
-                           &mDocument, mAddressDetails));
+    OUString aDataSrc(mInputRange.Format(
+        mDocument, mbUse3DAddresses ? ScRefFlags::RANGE_ABS_3D : ScRefFlags::RANGE_ABS,
+        mAddressDetails));
 
     rLabel = ScResId(STR_INPUT_DATA_RANGE) + " : " + aDataSrc;
     return;
diff --git a/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx b/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx
index 9a7673450570..c4f358c5e7d0 100644
--- a/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx
@@ -106,7 +106,7 @@ void ScRandomNumberGeneratorDialog::Init()
 void ScRandomNumberGeneratorDialog::GetRangeFromSelection()
 {
     mpViewData->GetSimpleArea(maInputRange);
-    OUString aCurrentString(maInputRange.Format(ScRefFlags::RANGE_ABS_3D, &mrDoc, mrDoc.GetAddressConvention()));
+    OUString aCurrentString(maInputRange.Format(mrDoc, ScRefFlags::RANGE_ABS_3D, mrDoc.GetAddressConvention()));
     mxInputRangeEdit->SetText( aCurrentString );
 }
 
@@ -139,7 +139,7 @@ void ScRandomNumberGeneratorDialog::SetReference( const ScRange& rReferenceRange
 
         maInputRange = rReferenceRange;
 
-        OUString aReferenceString(maInputRange.Format(ScRefFlags::RANGE_ABS_3D, &rDoc, rDoc.GetAddressConvention()));
+        OUString aReferenceString(maInputRange.Format(rDoc, ScRefFlags::RANGE_ABS_3D, rDoc.GetAddressConvention()));
         mxInputRangeEdit->SetRefString( aReferenceString );
 
         mxButtonApply->set_sensitive(true);
diff --git a/sc/source/ui/StatisticsDialogs/SamplingDialog.cxx b/sc/source/ui/StatisticsDialogs/SamplingDialog.cxx
index 7600ec78830c..62a93829c707 100644
--- a/sc/source/ui/StatisticsDialogs/SamplingDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/SamplingDialog.cxx
@@ -102,7 +102,7 @@ void ScSamplingDialog::Init()
 void ScSamplingDialog::GetRangeFromSelection()
 {
     mViewData->GetSimpleArea(mInputRange);
-    OUString aCurrentString(mInputRange.Format(ScRefFlags::RANGE_ABS_3D, &mDocument, mAddressDetails));
+    OUString aCurrentString(mInputRange.Format(mDocument, ScRefFlags::RANGE_ABS_3D, mAddressDetails));
     mxInputRangeEdit->SetText(aCurrentString);
 }
 
@@ -138,7 +138,7 @@ void ScSamplingDialog::SetReference( const ScRange& rReferenceRange, ScDocument&
         if ( mpActiveEdit == mxInputRangeEdit.get() )
         {
             mInputRange = rReferenceRange;
-            aReferenceString = mInputRange.Format(ScRefFlags::RANGE_ABS_3D, &rDocument, mAddressDetails);
+            aReferenceString = mInputRange.Format(rDocument, ScRefFlags::RANGE_ABS_3D, mAddressDetails);
             mxInputRangeEdit->SetRefString( aReferenceString );
 
             LimitSampleSizeAndPeriod();
diff --git a/sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog.cxx b/sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog.cxx
index fcb9666678da..959d7ee2dee3 100644
--- a/sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog.cxx
@@ -118,7 +118,7 @@ void ScStatisticsInputOutputDialog::Init()
 void ScStatisticsInputOutputDialog::GetRangeFromSelection()
 {
     mViewData->GetSimpleArea(mInputRange);
-    OUString aCurrentString(mInputRange.Format(ScRefFlags::RANGE_ABS_3D, &mDocument, mAddressDetails));
+    OUString aCurrentString(mInputRange.Format(mDocument, ScRefFlags::RANGE_ABS_3D, mAddressDetails));
     mxInputRangeEdit->SetText(aCurrentString);
 }
 
@@ -149,7 +149,7 @@ void ScStatisticsInputOutputDialog::SetReference( const ScRange& rReferenceRange
         if (mpActiveEdit == mxInputRangeEdit.get())
         {
             mInputRange = rReferenceRange;
-            aReferenceString = mInputRange.Format(ScRefFlags::RANGE_ABS_3D, &rDocument, mAddressDetails);
+            aReferenceString = mInputRange.Format(rDocument, ScRefFlags::RANGE_ABS_3D, mAddressDetails);
             mxInputRangeEdit->SetRefString( aReferenceString );
         }
         else if (mpActiveEdit == mxOutputRangeEdit.get())
diff --git a/sc/source/ui/StatisticsDialogs/StatisticsTwoVariableDialog.cxx b/sc/source/ui/StatisticsDialogs/StatisticsTwoVariableDialog.cxx
index fb0b34d6be4f..ab2b3c7fbd62 100644
--- a/sc/source/ui/StatisticsDialogs/StatisticsTwoVariableDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/StatisticsTwoVariableDialog.cxx
@@ -112,18 +112,18 @@ void ScStatisticsTwoVariableDialog::GetRangeFromSelection()
     {
         mVariable1Range = aCurrentRange;
         mVariable1Range.aEnd.SetCol(mVariable1Range.aStart.Col());
-        aCurrentString = mVariable1Range.Format(ScRefFlags::RANGE_ABS_3D, &mDocument, mAddressDetails);
+        aCurrentString = mVariable1Range.Format(mDocument, ScRefFlags::RANGE_ABS_3D, mAddressDetails);
         mxVariable1RangeEdit->SetText(aCurrentString);
 
         mVariable2Range = aCurrentRange;
         mVariable2Range.aStart.SetCol(mVariable2Range.aEnd.Col());
-        aCurrentString = mVariable2Range.Format(ScRefFlags::RANGE_ABS_3D, &mDocument, mAddressDetails);
+        aCurrentString = mVariable2Range.Format(mDocument, ScRefFlags::RANGE_ABS_3D, mAddressDetails);
         mxVariable2RangeEdit->SetText(aCurrentString);
     }
     else
     {
         mVariable1Range = aCurrentRange;
-        aCurrentString = mVariable1Range.Format(ScRefFlags::RANGE_ABS_3D, &mDocument, mAddressDetails);
+        aCurrentString = mVariable1Range.Format(mDocument, ScRefFlags::RANGE_ABS_3D, mAddressDetails);
         mxVariable1RangeEdit->SetText(aCurrentString);
     }
 }
@@ -155,13 +155,13 @@ void ScStatisticsTwoVariableDialog::SetReference( const ScRange& rReferenceRange
         if ( mpActiveEdit == mxVariable1RangeEdit.get() )
         {
             mVariable1Range = rReferenceRange;
-            aReferenceString = mVariable1Range.Format(ScRefFlags::RANGE_ABS_3D, &rDocument, mAddressDetails);
+            aReferenceString = mVariable1Range.Format(rDocument, ScRefFlags::RANGE_ABS_3D, mAddressDetails);
             mxVariable1RangeEdit->SetRefString(aReferenceString);
         }
         else if ( mpActiveEdit == mxVariable2RangeEdit.get() )
         {
             mVariable2Range = rReferenceRange;
-            aReferenceString = mVariable2Range.Format(ScRefFlags::RANGE_ABS_3D, &rDocument, mAddressDetails);
+            aReferenceString = mVariable2Range.Format(rDocument, ScRefFlags::RANGE_ABS_3D, mAddressDetails);
             mxVariable2RangeEdit->SetRefString(aReferenceString);
         }
         else if ( mpActiveEdit == mxOutputRangeEdit.get() )
diff --git a/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx b/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx
index 02d709bfd079..a27598441330 100644
--- a/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx
+++ b/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx
@@ -63,14 +63,14 @@ void FormulaTemplate::autoReplaceAddress(const OUString& aVariable, ScAddress co
 void FormulaTemplate::applyRange(const OUString& aVariable, const ScRange& aRange, bool b3D)
 {
     ScRefFlags nFlag = b3D ? ScRefFlags::RANGE_ABS_3D : ScRefFlags::RANGE_ABS;
-    OUString aString = aRange.Format(nFlag, mpDoc, mpDoc->GetAddressConvention());
+    OUString aString = aRange.Format(*mpDoc, nFlag, mpDoc->GetAddressConvention());
     mTemplate = mTemplate.replaceAll(aVariable, aString);
 }
 
 void FormulaTemplate::applyRangeList(const OUString& aVariable, const ScRangeList& aRangeList, sal_Unicode cDelimiter)
 {
     OUString aString;
-    aRangeList.Format(aString, ScRefFlags::RANGE_ABS_3D, mpDoc, mpDoc->GetAddressConvention(), cDelimiter);
+    aRangeList.Format(aString, ScRefFlags::RANGE_ABS_3D, *mpDoc, mpDoc->GetAddressConvention(), cDelimiter);
     mTemplate = mTemplate.replaceAll(aVariable, aString);
 }
 
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index 62ea17b0cc69..d7b016726c8d 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -570,7 +570,7 @@ void ScInputHandler::UpdateRange( sal_uInt16 nIndex, const ScRange& rNew )
         aJustified.PutInOrder(); // Always display Ref in the Formula the right way
         ScDocument* pDoc = pDocView->GetViewData().GetDocument();
         const ScAddress::Details aAddrDetails( *pDoc, aCursorPos );
-        OUString aNewStr(aJustified.Format(rData.nFlags, pDoc, aAddrDetails));
+        OUString aNewStr(aJustified.Format(*pDoc, rData.nFlags, aAddrDetails));
         ESelection aOldSel( 0, nOldStart, 0, nOldEnd );
         SfxItemSet aSet( mpEditEngine->GetEmptyItemSet() );
 
@@ -3239,7 +3239,7 @@ void ScInputHandler::SetReference( const ScRange& rRef, const ScDocument& rDoc )
         OSL_ENSURE(rRef.aStart.Tab()==rRef.aEnd.Tab(), "nStartTab!=nEndTab");
 
         // Always 3D and absolute.
-        OUString aTmp(rRef.Format( ScRefFlags::VALID | ScRefFlags::TAB_ABS_3D, &rDoc, aAddrDetails));
+        OUString aTmp(rRef.Format(rDoc, ScRefFlags::VALID | ScRefFlags::TAB_ABS_3D, aAddrDetails));
 
         SfxObjectShell* pObjSh = rDoc.GetDocumentShell();
         // #i75893# convert escaped URL of the document to something user friendly
@@ -3264,9 +3264,9 @@ void ScInputHandler::SetReference( const ScRange& rRef, const ScDocument& rDoc )
         if ( rRef.aStart.Tab() != aCursorPos.Tab() ||
              rRef.aStart.Tab() != rRef.aEnd.Tab() )
             // pointer-selected => absolute sheet reference
-            aRefStr = rRef.Format(ScRefFlags::VALID | ScRefFlags::TAB_ABS_3D, &rDoc, aAddrDetails);
+            aRefStr = rRef.Format(rDoc, ScRefFlags::VALID | ScRefFlags::TAB_ABS_3D, aAddrDetails);
         else
-            aRefStr = rRef.Format(ScRefFlags::VALID, &rDoc, aAddrDetails);
+            aRefStr = rRef.Format(rDoc, ScRefFlags::VALID, aAddrDetails);
     }
 
     if (pTableView || pTopView)
@@ -3854,7 +3854,7 @@ void ScInputHandler::NotifyChange( const ScInputHdlState* pState,
                         {
                             ScRange r(rSPos, rEPos);
                             applyStartToEndFlags(nFlags);
-                            aPosStr = r.Format(ScRefFlags::VALID | nFlags, &rDoc, aAddrDetails);
+                            aPosStr = r.Format(rDoc, ScRefFlags::VALID | nFlags, aAddrDetails);
                         }
                         else
                             aPosStr = aCursorPos.Format(ScRefFlags::VALID | nFlags, &rDoc, aAddrDetails);
diff --git a/sc/source/ui/app/inputwin.cxx b/sc/source/ui/app/inputwin.cxx
index 4fd72988df22..7d5695a63b9f 100644
--- a/sc/source/ui/app/inputwin.cxx
+++ b/sc/source/ui/app/inputwin.cxx
@@ -2314,7 +2314,7 @@ void ScPosWnd::DoEnter()
                     {
                         ScRangeName aNewRanges( *pNames );
                         ScAddress aCursor( rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo() );
-                        OUString aContent(aSelection.Format(ScRefFlags::RANGE_ABS_3D, &rDoc, rDoc.GetAddressConvention()));
+                        OUString aContent(aSelection.Format(rDoc, ScRefFlags::RANGE_ABS_3D, rDoc.GetAddressConvention()));
                         ScRangeData* pNew = new ScRangeData( &rDoc, aText, aContent, aCursor );
                         if ( aNewRanges.insert(pNew) )
                         {
@@ -2340,7 +2340,7 @@ void ScPosWnd::DoEnter()
                         // be in Calc A1 format.  Convert the text.
                         ScRange aRange(0,0, rViewData.GetTabNo());
                         aRange.ParseAny(aText, &rDoc, rDoc.GetAddressConvention());
-                        aText = aRange.Format(ScRefFlags::RANGE_ABS_3D, &rDoc, ::formula::FormulaGrammar::CONV_OOO);
+                        aText = aRange.Format(rDoc, ScRefFlags::RANGE_ABS_3D, ::formula::FormulaGrammar::CONV_OOO);
                     }
 
                     SfxStringItem aPosItem( SID_CURRENTCELL, aText );
diff --git a/sc/source/ui/condformat/condformatdlg.cxx b/sc/source/ui/condformat/condformatdlg.cxx
index 6b29156e47f4..d07eb9a49641 100644
--- a/sc/source/ui/condformat/condformatdlg.cxx
+++ b/sc/source/ui/condformat/condformatdlg.cxx
@@ -474,8 +474,8 @@ ScCondFormatDlg::ScCondFormatDlg(SfxBindings* pB, SfxChildWindow* pCW,
     mxEdRange->SetGetFocusHdl( LINK( this, ScCondFormatDlg, RangeGetFocusHdl ) );
 
     OUString aRangeString;
-    aRange.Format(aRangeString, ScRefFlags::VALID, pViewData->GetDocument(),
-                    pViewData->GetDocument()->GetAddressConvention());
+    const ScDocument* pDoc = pViewData->GetDocument();
+    aRange.Format(aRangeString, ScRefFlags::VALID, *pDoc, pDoc->GetAddressConvention());
     mxEdRange->SetText(aRangeString);
 
     msBaseTitle = m_xDialog->get_title();
@@ -546,8 +546,9 @@ void ScCondFormatDlg::SetReference(const ScRange& rRef, ScDocument&)
         else
             nFlags = ScRefFlags::RANGE_ABS;
 
-        OUString aRefStr(rRef.Format(nFlags, mpViewData->GetDocument(),
-            ScAddress::Details(mpViewData->GetDocument()->GetAddressConvention(), 0, 0)));
+        const ScDocument* pDoc = mpViewData->GetDocument();
+        OUString aRefStr(rRef.Format(*pDoc, nFlags,
+            ScAddress::Details(pDoc->GetAddressConvention(), 0, 0)));
         if (pEdit != mxEdRange.get())
         {
             Selection sel = pEdit->GetSelection();
diff --git a/sc/source/ui/condformat/condformatmgr.cxx b/sc/source/ui/condformat/condformatmgr.cxx
index a8206a3d1d7a..03e691ac2ed8 100644
--- a/sc/source/ui/condformat/condformatmgr.cxx
+++ b/sc/source/ui/condformat/condformatmgr.cxx
@@ -41,7 +41,7 @@ void ScCondFormatManagerWindow::Init()
         for(const auto& rItem : *mpFormatList)
         {
             const ScRangeList& aRange = rItem->GetRange();
-            aRange.Format(sRangeStr, ScRefFlags::VALID, mpDoc, mpDoc->GetAddressConvention());
+            aRange.Format(sRangeStr, ScRefFlags::VALID, *mpDoc, mpDoc->GetAddressConvention());
             mrTreeView.append(OUString::number(rItem->GetKey()), sRangeStr);
             mrTreeView.set_text(nRow, ScCondFormatHelper::GetExpression(*rItem, aRange.GetTopLeftCorner()), 1);
             ++nRow;
diff --git a/sc/source/ui/dbgui/PivotLayoutDialog.cxx b/sc/source/ui/dbgui/PivotLayoutDialog.cxx
index f5011412bb03..294771e955be 100644
--- a/sc/source/ui/dbgui/PivotLayoutDialog.cxx
+++ b/sc/source/ui/dbgui/PivotLayoutDialog.cxx
@@ -210,7 +210,7 @@ void ScPivotLayoutDialog::SetupSource()
         }
         else
         {
-            OUString aSourceRangeName = aSourceRange.Format(ScRefFlags::RANGE_ABS_3D, &mrDocument, maAddressDetails);
+            OUString aSourceRangeName = aSourceRange.Format(mrDocument, ScRefFlags::RANGE_ABS_3D, maAddressDetails);
             mxSourceEdit->SetText(aSourceRangeName);
         }
     }
@@ -342,7 +342,7 @@ void ScPivotLayoutDialog::SetReference(const ScRange& rReferenceRange, ScDocumen
     if (rReferenceRange.aStart != rReferenceRange.aEnd)
         RefInputStart(mpActiveEdit);
 
-    OUString aReferenceString = rReferenceRange.Format(ScRefFlags::RANGE_ABS_3D, &rDocument, maAddressDetails);
+    OUString aReferenceString = rReferenceRange.Format(rDocument, ScRefFlags::RANGE_ABS_3D, maAddressDetails);
 
     if (mpActiveEdit == mxSourceEdit.get())
     {
diff --git a/sc/source/ui/dbgui/consdlg.cxx b/sc/source/ui/dbgui/consdlg.cxx
index a7cf9b1d6589..4892cf044377 100644
--- a/sc/source/ui/dbgui/consdlg.cxx
+++ b/sc/source/ui/dbgui/consdlg.cxx
@@ -154,8 +154,8 @@ void ScConsolidateDlg::Init()
         if ( rArea.nTab < pDoc->GetTableCount() )
         {
             aStr = ScRange( rArea.nColStart, rArea.nRowStart, rArea.nTab,
-                    rArea.nColEnd, rArea.nRowEnd, rArea.nTab ).Format(
-                        ScRefFlags::RANGE_ABS_3D, pDoc, eConv );
+                    rArea.nColEnd, rArea.nRowEnd, rArea.nTab ).Format( *pDoc,
+                        ScRefFlags::RANGE_ABS_3D, eConv );
             m_xLbConsAreas->append_text(aStr);
         }
     }
@@ -190,7 +190,7 @@ void ScConsolidateDlg::Init()
         ScAreaNameIterator aIter( pDoc );
         while ( aIter.Next( aStrName, aRange ) )
         {
-            OUString aStrArea(aRange.Format(ScRefFlags::ADDR_ABS_3D, pDoc, eConv));
+            OUString aStrArea(aRange.Format(*pDoc, ScRefFlags::ADDR_ABS_3D, eConv));
             pAreaData[nAt++].Set( aStrName, aStrArea );
         }
     }
@@ -244,7 +244,7 @@ void ScConsolidateDlg::SetReference( const ScRange& rRef, ScDocument& rDocP )
             nFmt |= ScRefFlags::TAB2_3D;
 
         if ( m_pRefInputEdit == m_xEdDataArea.get())
-            aStr = rRef.Format(nFmt, &rDocP, eConv);
+            aStr = rRef.Format(rDocP, nFmt, eConv);
         else if ( m_pRefInputEdit == m_xEdDestArea.get() )
             aStr = rRef.aStart.Format(nFmt, &rDocP, eConv);
 
@@ -401,7 +401,7 @@ IMPL_LINK( ScConsolidateDlg, ClickHdl, weld::Button&, rBtn, void )
                     const ScArea& rArea = ppAreas[i];
                     OUString aNewArea = ScRange( rArea.nColStart, rArea.nRowStart, rArea.nTab,
                             rArea.nColEnd, rArea.nRowEnd, rArea.nTab
-                            ).Format(ScRefFlags::RANGE_ABS_3D, pDoc, eConv);
+                            ).Format(*pDoc, ScRefFlags::RANGE_ABS_3D, eConv);
 
                     if (m_xLbConsAreas->find_text(aNewArea) == -1)
                     {
diff --git a/sc/source/ui/dbgui/dbnamdlg.cxx b/sc/source/ui/dbgui/dbnamdlg.cxx
index 5f7ad383c979..722ffee83bdc 100644
--- a/sc/source/ui/dbgui/dbnamdlg.cxx
+++ b/sc/source/ui/dbgui/dbnamdlg.cxx
@@ -208,7 +208,7 @@ void ScDbNameDlg::Init()
 
         theCurArea = ScRange( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab);
 
-        theAreaStr = theCurArea.Format(ScRefFlags::RANGE_ABS_3D, &rDoc, aAddrDetails);
+        theAreaStr = theCurArea.Format(rDoc, ScRefFlags::RANGE_ABS_3D, aAddrDetails);
 
         if ( pDBColl )
         {
@@ -284,7 +284,7 @@ void ScDbNameDlg::SetReference( const ScRange& rRef, ScDocument& rDocP )
 
         theCurArea = rRef;
 
-        OUString aRefStr(theCurArea.Format(ScRefFlags::RANGE_ABS_3D, &rDocP, aAddrDetails));
+        OUString aRefStr(theCurArea.Format(rDocP, ScRefFlags::RANGE_ABS_3D, aAddrDetails));
         m_xEdAssign->SetRefString( aRefStr );
         m_xOptions->set_sensitive(true);
         m_xBtnAdd->set_sensitive(true);
@@ -351,7 +351,7 @@ void ScDbNameDlg::UpdateDBData( const OUString& rStrName )
         pData->GetArea( nTab, nColStart, nRowStart, nColEnd, nRowEnd );
         theCurArea = ScRange( ScAddress( nColStart, nRowStart, nTab ),
                               ScAddress( nColEnd,   nRowEnd,   nTab ) );
-        OUString theArea(theCurArea.Format(ScRefFlags::RANGE_ABS_3D, &rDoc, aAddrDetails));
+        OUString theArea(theCurArea.Format(rDoc, ScRefFlags::RANGE_ABS_3D, aAddrDetails));
         m_xEdAssign->SetText( theArea );
         m_xBtnAdd->set_label( aStrModify );
         m_xBtnHeader->set_active( pData->HasHeader() );
diff --git a/sc/source/ui/dbgui/foptmgr.cxx b/sc/source/ui/dbgui/foptmgr.cxx
index 84fb097dd97e..adaeb0c8c51f 100644
--- a/sc/source/ui/dbgui/foptmgr.cxx
+++ b/sc/source/ui/dbgui/foptmgr.cxx
@@ -98,7 +98,7 @@ void ScFilterOptionsMgr::Init()
         OUString   theDbName(STR_DB_LOCAL_NONAME);
         const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
 
-        theAreaStr = theCurArea.Format(ScRefFlags::RANGE_ABS_3D, pDoc, eConv);
+        theAreaStr = theCurArea.Format(*pDoc, ScRefFlags::RANGE_ABS_3D, eConv);
 
         // fill the target area list
 
diff --git a/sc/source/ui/dbgui/sfiltdlg.cxx b/sc/source/ui/dbgui/sfiltdlg.cxx
index 3b5d8ff55b81..36fad71fb953 100644
--- a/sc/source/ui/dbgui/sfiltdlg.cxx
+++ b/sc/source/ui/dbgui/sfiltdlg.cxx
@@ -150,7 +150,7 @@ void ScSpecialFilterDlg::Init( const SfxItemSet& rArgSet )
         ScRange aAdvSource;
         if (rQueryItem.GetAdvancedQuerySource(aAdvSource))
         {
-            OUString aRefStr(aAdvSource.Format(ScRefFlags::RANGE_ABS_3D, pDoc, pDoc->GetAddressConvention()));
+            OUString aRefStr(aAdvSource.Format(*pDoc, ScRefFlags::RANGE_ABS_3D, pDoc->GetAddressConvention()));
             m_xEdFilterArea->SetRefString( aRefStr );
         }
     }
@@ -209,7 +209,7 @@ void ScSpecialFilterDlg::SetReference( const ScRange& rRef, ScDocument& rDocP )
         if (m_pRefInputEdit == m_xEdCopyArea.get())
             aRefStr = rRef.aStart.Format(ScRefFlags::ADDR_ABS_3D, &rDocP, eConv);
         else if (m_pRefInputEdit == m_xEdFilterArea.get())
-            aRefStr = rRef.Format(ScRefFlags::RANGE_ABS_3D, &rDocP, eConv);
+            aRefStr = rRef.Format(rDocP, ScRefFlags::RANGE_ABS_3D, eConv);
 
         m_pRefInputEdit->SetRefString( aRefStr );
     }
diff --git a/sc/source/ui/dbgui/validate.cxx b/sc/source/ui/dbgui/validate.cxx
index 84de0b56b862..9e1e2693644d 100644
--- a/sc/source/ui/dbgui/validate.cxx
+++ b/sc/source/ui/dbgui/validate.cxx
@@ -110,7 +110,7 @@ void ScTPValidationValue::SetReferenceHdl( const ScRange&rRange , const ScDocume
 
     if ( m_pRefEdit )
     {
-        OUString aStr(rRange.Format(ScRefFlags::RANGE_ABS_3D, &rDoc, rDoc.GetAddressConvention()));
+        OUString aStr(rRange.Format(rDoc, ScRefFlags::RANGE_ABS_3D, rDoc.GetAddressConvention()));
         m_pRefEdit->SetRefString( aStr );
     }
 }
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index 1a2a61e263fa..6ce6664c024d 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -5168,7 +5168,7 @@ void ScDocFunc::CreateOneName( ScRangeName& rList,
         ScRangeData::MakeValidName(&rDoc, aName);
         if (!aName.isEmpty())
         {
-            OUString aContent(ScRange( nX1, nY1, nTab, nX2, nY2, nTab ).Format(ScRefFlags::RANGE_ABS_3D, &rDoc));
+            OUString aContent(ScRange( nX1, nY1, nTab, nX2, nY2, nTab ).Format(rDoc, ScRefFlags::RANGE_ABS_3D));
 
             bool bInsert = false;
             ScRangeData* pOld = rList.findByUpperName(ScGlobal::pCharClass->uppercase(aName));
diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index 1f3e733809cd..7015c16a8fdc 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -453,7 +453,7 @@ bool ScImportExport::ExportStream( SvStream& rStrm, const OUString& rBaseURL, So
             {
                 if( aRange.aStart.Tab() != aRange.aEnd.Tab() )
                     nFlags |= ScRefFlags::TAB2_3D;
-                aRefName = aRange.Format(nFlags, pDoc, formula::FormulaGrammar::CONV_OOO);
+                aRefName = aRange.Format(*pDoc, nFlags, formula::FormulaGrammar::CONV_OOO);
             }
             OUString aAppName = Application::GetAppName();
 
diff --git a/sc/source/ui/drawfunc/fuins2.cxx b/sc/source/ui/drawfunc/fuins2.cxx
index 65cfbf2237e6..6606f47f5fac 100644
--- a/sc/source/ui/drawfunc/fuins2.cxx
+++ b/sc/source/ui/drawfunc/fuins2.cxx
@@ -109,7 +109,7 @@ void lcl_ChartInit(const uno::Reference <embed::XEmbeddedObject>& xObj, ScViewDa
                 pDoc->LimitChartArea( nTab1, nCol1,nRow1, nCol2,nRow2 );
 
                 ScRange aRange( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
-                aRangeString = aRange.Format(ScRefFlags::RANGE_ABS_3D, &rScDoc, rScDoc.GetAddressConvention());
+                aRangeString = aRange.Format(rScDoc, ScRefFlags::RANGE_ABS_3D, rScDoc.GetAddressConvention());
             }
         }
     }
@@ -155,7 +155,7 @@ void lcl_ChartInit(const uno::Reference <embed::XEmbeddedObject>& xObj, ScViewDa
 
                 // update string from modified ranges.  The ranges must be in the current formula syntax.
                 OUString aTmpStr;
-                aRangeListRef->Format( aTmpStr, ScRefFlags::RANGE_ABS_3D, &rScDoc, rScDoc.GetAddressConvention() );
+                aRangeListRef->Format( aTmpStr, ScRefFlags::RANGE_ABS_3D, rScDoc, rScDoc.GetAddressConvention() );
                 aRangeString = aTmpStr;
 
                 ScChartPositioner aChartPositioner( &rScDoc, aRangeListRef );
@@ -451,7 +451,7 @@ FuInsertChart::FuInsertChart(ScTabViewShell& rViewSh, vcl::Window* pWin, ScDrawV
             ScRangeList aRanges;
             aMultiMark.FillRangeListWithMarks( &aRanges, false );
             OUString aStr;
-            aRanges.Format( aStr, ScRefFlags::RANGE_ABS_3D, pDocument, pDocument->GetAddressConvention() );
+            aRanges.Format( aStr, ScRefFlags::RANGE_ABS_3D, *pDocument, pDocument->GetAddressConvention() );
             aRangeString = aStr;
 
             // get "total" range for positioning
diff --git a/sc/source/ui/formdlg/formula.cxx b/sc/source/ui/formdlg/formula.cxx
index fa876f5cfed2..e68a5c8208dd 100644
--- a/sc/source/ui/formdlg/formula.cxx
+++ b/sc/source/ui/formdlg/formula.cxx
@@ -411,7 +411,7 @@ void ScFormulaDlg::SetReference( const ScRange& rRef, ScDocument& rRefDoc )
             OSL_ENSURE(rRef.aStart.Tab()==rRef.aEnd.Tab(), "nStartTab!=nEndTab");
 
             // Always 3D and absolute.
-            OUString aTmp( rRef.Format( ScRefFlags::VALID | ScRefFlags::TAB_ABS_3D, &rRefDoc));
+            OUString aTmp( rRef.Format(rRefDoc, ScRefFlags::VALID | ScRefFlags::TAB_ABS_3D));
 
             SfxObjectShell* pObjSh = rRefDoc.GetDocumentShell();
 
diff --git a/sc/source/ui/miscdlgs/acredlin.cxx b/sc/source/ui/miscdlgs/acredlin.cxx
index a30c56ef0b00..1c3d839ea2d8 100644
--- a/sc/source/ui/miscdlgs/acredlin.cxx
+++ b/sc/source/ui/miscdlgs/acredlin.cxx
@@ -241,7 +241,7 @@ void ScAcceptChgDlg::Init()
     if( !aChangeViewSet.GetTheRangeList().empty() )
     {
         const ScRange & rRangeEntry = aChangeViewSet.GetTheRangeList().front();
-        OUString aRefStr(rRangeEntry.Format(ScRefFlags::RANGE_ABS_3D, pDoc));
+        OUString aRefStr(rRangeEntry.Format(*pDoc, ScRefFlags::RANGE_ABS_3D));
         pTPFilter->SetRange(aRefStr);
     }
 
diff --git a/sc/source/ui/miscdlgs/crnrdlg.cxx b/sc/source/ui/miscdlgs/crnrdlg.cxx
index 424782050ec8..8258dded0aab 100644
--- a/sc/source/ui/miscdlgs/crnrdlg.cxx
+++ b/sc/source/ui/miscdlgs/crnrdlg.cxx
@@ -204,7 +204,7 @@ void ScColRowNameRangesDlg::SetColRowData( const ScRange& rLabelRange, bool bRef
     if ( bValid )
     {
         const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
-        OUString aStr(theCurArea.Format(ScRefFlags::RANGE_ABS_3D, pDoc, eConv));
+        OUString aStr(theCurArea.Format(*pDoc, ScRefFlags::RANGE_ABS_3D, eConv));
 
         if(bRef)
             m_xEdAssign->SetRefString( aStr );
@@ -212,7 +212,7 @@ void ScColRowNameRangesDlg::SetColRowData( const ScRange& rLabelRange, bool bRef
             m_xEdAssign->SetText( aStr );
 
         m_xEdAssign->SetCursorAtLast();
-        aStr = theCurData.Format(ScRefFlags::RANGE_ABS_3D, pDoc, eConv);
+        aStr = theCurData.Format(*pDoc, ScRefFlags::RANGE_ABS_3D, eConv);
 
         if(bRef)
             m_xEdAssign2->SetRefString( aStr );
@@ -291,7 +291,7 @@ void ScColRowNameRangesDlg::AdjustColRowData( const ScRange& rDataRange, bool bR
             }
         }
     }
-    OUString aStr(theCurData.Format(ScRefFlags::RANGE_ABS_3D, pDoc, pDoc->GetAddressConvention()));
+    OUString aStr(theCurData.Format(*pDoc, ScRefFlags::RANGE_ABS_3D, pDoc->GetAddressConvention()));
 
     if(bRef)
         m_xEdAssign2->SetRefString( aStr );
@@ -375,7 +375,7 @@ void ScColRowNameRangesDlg::UpdateNames()
         for ( j=0; j < nCount; j++ )
         {
             const ScRange aRange(aSortArray[j]->GetRange(0));
-            aString = aRange.Format(ScRefFlags::RANGE_ABS_3D, pDoc, aDetails);
+            aString = aRange.Format(*pDoc, ScRefFlags::RANGE_ABS_3D, aDetails);
 
             //@008 get range parameters from document
             aSortArray[j]->GetRange(0).GetVars( nCol1, nRow1, nTab1,
@@ -414,7 +414,7 @@ void ScColRowNameRangesDlg::UpdateNames()
         for ( j=0; j < nCount; j++ )
         {
             const ScRange aRange(aSortArray[j]->GetRange(0));
-            aString = aRange.Format(ScRefFlags::RANGE_ABS_3D, pDoc, aDetails);
+            aString = aRange.Format(*pDoc, ScRefFlags::RANGE_ABS_3D, aDetails);
 
             //@008 Build string for rows below
             aSortArray[j]->GetRange(0).GetVars( nCol1, nRow1, nTab1,
@@ -458,14 +458,14 @@ void ScColRowNameRangesDlg::UpdateRangeData( const ScRange& rRange, bool bColNam
     {
         const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
         theCurArea = rRange;
-        OUString aStr(theCurArea.Format(ScRefFlags::RANGE_ABS_3D, pDoc, eConv));
+        OUString aStr(theCurArea.Format(*pDoc, ScRefFlags::RANGE_ABS_3D, eConv));
         m_xEdAssign->SetText( aStr );
         m_xBtnAdd->set_sensitive(false);
         m_xBtnRemove->set_sensitive(true);
         m_xBtnColHead->set_active(bColName);
         m_xBtnRowHead->set_active(!bColName);
         theCurData = pPair->GetRange(1);
-        aStr = theCurData.Format(ScRefFlags::RANGE_ABS_3D, pDoc, eConv);
+        aStr = theCurData.Format(*pDoc, ScRefFlags::RANGE_ABS_3D, eConv);
         m_xEdAssign2->SetText( aStr );
     }
     else
@@ -748,7 +748,7 @@ IMPL_LINK_NOARG(ScColRowNameRangesDlg, ColClickHdl, weld::Button&, void)
         if ( theCurArea.aStart.Row() == 0 && theCurArea.aEnd.Row() == pDoc->MaxRow() )
         {
             theCurArea.aEnd.SetRow( pDoc->MaxRow() - 1 );
-            OUString aStr(theCurArea.Format(ScRefFlags::RANGE_ABS_3D, pDoc, pDoc->GetAddressConvention()));
+            OUString aStr(theCurArea.Format(*pDoc, ScRefFlags::RANGE_ABS_3D, pDoc->GetAddressConvention()));
             m_xEdAssign->SetText( aStr );
         }
         ScRange aRange( theCurData );
@@ -766,7 +766,7 @@ IMPL_LINK_NOARG(ScColRowNameRangesDlg, RowClickHdl, weld::Button&, void)
         if ( theCurArea.aStart.Col() == 0 && theCurArea.aEnd.Col() == pDoc->MaxCol() )
         {
             theCurArea.aEnd.SetCol( pDoc->MaxCol() - 1 );
-            OUString aStr(theCurArea.Format(ScRefFlags::RANGE_ABS_3D, pDoc, pDoc->GetAddressConvention()));
+            OUString aStr(theCurArea.Format(*pDoc, ScRefFlags::RANGE_ABS_3D, pDoc->GetAddressConvention()));
             m_xEdAssign->SetText( aStr );
         }
         ScRange aRange( theCurData );
diff --git a/sc/source/ui/miscdlgs/datastreamdlg.cxx b/sc/source/ui/miscdlgs/datastreamdlg.cxx
index 3fcf2e884091..672e04d5af70 100644
--- a/sc/source/ui/miscdlgs/datastreamdlg.cxx
+++ b/sc/source/ui/miscdlgs/datastreamdlg.cxx
@@ -129,7 +129,7 @@ void DataStreamDlg::Init( const DataStream& rStrm )
     ScRange aRange = rStrm.GetRange();
     ScRange aTopRange = aRange;
     aTopRange.aEnd.SetRow(aTopRange.aStart.Row());
-    OUString aStr = aTopRange.Format(ScRefFlags::RANGE_ABS_3D, &rDoc, rDoc.GetAddressConvention());
+    OUString aStr = aTopRange.Format(rDoc, ScRefFlags::RANGE_ABS_3D, rDoc.GetAddressConvention());
     m_xEdRange->set_text(aStr);
     SCROW nRows = aRange.aEnd.Row() - aRange.aStart.Row() + 1;
 
diff --git a/sc/source/ui/miscdlgs/highred.cxx b/sc/source/ui/miscdlgs/highred.cxx
index c99c79c80f18..33c8f29955c0 100644
--- a/sc/source/ui/miscdlgs/highred.cxx
+++ b/sc/source/ui/miscdlgs/highred.cxx
@@ -117,7 +117,7 @@ void ScHighlightChgDlg::Init()
     if ( !aChangeViewSet.GetTheRangeList().empty() )
     {
         const ScRange & rRangeEntry = aChangeViewSet.GetTheRangeList().front();
-        OUString aRefStr(rRangeEntry.Format(ScRefFlags::RANGE_ABS_3D, pDoc));
+        OUString aRefStr(rRangeEntry.Format(*pDoc, ScRefFlags::RANGE_ABS_3D));
         m_xFilterCtr->SetRange(aRefStr);
     }
     m_xFilterCtr->Enable(true);
@@ -132,7 +132,7 @@ void ScHighlightChgDlg::SetReference( const ScRange& rRef, ScDocument& rDocP )
     {
         if ( rRef.aStart != rRef.aEnd )
             RefInputStart(m_xEdAssign.get());
-        OUString aRefStr(rRef.Format(ScRefFlags::RANGE_ABS_3D, &rDocP, rDocP.GetAddressConvention()));
+        OUString aRefStr(rRef.Format(rDocP, ScRefFlags::RANGE_ABS_3D, rDocP.GetAddressConvention()));
         m_xEdAssign->SetRefString( aRefStr );
         m_xFilterCtr->SetRange(aRefStr);
     }
diff --git a/sc/source/ui/miscdlgs/optsolver.cxx b/sc/source/ui/miscdlgs/optsolver.cxx
index 2087e6fec152..795cd6f0f20c 100644
--- a/sc/source/ui/miscdlgs/optsolver.cxx
+++ b/sc/source/ui/miscdlgs/optsolver.cxx
@@ -470,7 +470,7 @@ void ScOptSolverDlg::SetReference( const ScRange& rRef, ScDocument& rDocP )
             if ( bSingle )
                 aStr = aAdr.Format(nFmt, &rDocP, rDocP.GetAddressConvention());
             else
-                aStr = rRef.Format(nFmt | ScRefFlags::RANGE_ABS, &rDocP, rDocP.GetAddressConvention());
+                aStr = rRef.Format(rDocP, nFmt | ScRefFlags::RANGE_ABS, rDocP.GetAddressConvention());
         }
 
         // variable cells can be several ranges, so only the selection is replaced
diff --git a/sc/source/ui/miscdlgs/simpref.cxx b/sc/source/ui/miscdlgs/simpref.cxx
index 884ed1e22d1e..da54b3c151ef 100644
--- a/sc/source/ui/miscdlgs/simpref.cxx
+++ b/sc/source/ui/miscdlgs/simpref.cxx
@@ -81,7 +81,7 @@ void ScSimpleRefDlg::SetReference( const ScRange& rRef, ScDocument& rDocP )
             aRefStr = aAdr.Format(ScRefFlags::ADDR_ABS_3D, &rDocP, rDocP.GetAddressConvention());
         }
         else
-            aRefStr = theCurArea.Format(ScRefFlags::RANGE_ABS_3D, &rDocP, rDocP.GetAddressConvention());
+            aRefStr = theCurArea.Format(rDocP, ScRefFlags::RANGE_ABS_3D, rDocP.GetAddressConvention());
 
         if ( bMultiSelection )
         {
diff --git a/sc/source/ui/miscdlgs/tabopdlg.cxx b/sc/source/ui/miscdlgs/tabopdlg.cxx
index 0eae510542e1..f3ba86e81f33 100644
--- a/sc/source/ui/miscdlgs/tabopdlg.cxx
+++ b/sc/source/ui/miscdlgs/tabopdlg.cxx
@@ -142,7 +142,7 @@ void ScTabOpDlg::SetReference( const ScRange& rRef, ScDocument& rDocP )
         {
             theFormulaCell.Set( rRef.aStart, false, false, false);
             theFormulaEnd.Set( rRef.aEnd, false, false, false);
-            aStr = rRef.Format(nFmt, &rDocP, aDetails);
+            aStr = rRef.Format(rDocP, nFmt, aDetails);
         }
         else if (m_pEdActive == m_xEdRowCell.get())
         {
diff --git a/sc/source/ui/namedlg/namedefdlg.cxx b/sc/source/ui/namedlg/namedefdlg.cxx
index 8b744839a0a7..8f5c45f85d8d 100644
--- a/sc/source/ui/namedlg/namedefdlg.cxx
+++ b/sc/source/ui/namedlg/namedefdlg.cxx
@@ -77,7 +77,7 @@ ScNameDefDlg::ScNameDefDlg( SfxBindings* pB, SfxChildWindow* pCW, weld::Window*
     ScRange aRange;
 
     pViewData->GetSimpleArea( aRange );
-    OUString aAreaStr(aRange.Format(ScRefFlags::RANGE_ABS_3D, &mrDoc,
+    OUString aAreaStr(aRange.Format(mrDoc, ScRefFlags::RANGE_ABS_3D,
             ScAddress::Details(mrDoc.GetAddressConvention(), 0, 0)));
 
     m_xEdRange->SetText( aAreaStr );
@@ -287,7 +287,7 @@ void ScNameDefDlg::SetReference( const ScRange& rRef, ScDocument& rDocP )
     {
         if ( rRef.aStart != rRef.aEnd )
             RefInputStart(m_xEdRange.get());
-        OUString aRefStr(rRef.Format(ScRefFlags::RANGE_ABS_3D, &rDocP,
+        OUString aRefStr(rRef.Format(rDocP, ScRefFlags::RANGE_ABS_3D,
                 ScAddress::Details(rDocP.GetAddressConvention(), 0, 0)));
         m_xEdRange->SetRefString( aRefStr );
     }
diff --git a/sc/source/ui/namedlg/namedlg.cxx b/sc/source/ui/namedlg/namedlg.cxx
index cf9da658f1d4..8a8f2f76ea05 100644
--- a/sc/source/ui/namedlg/namedlg.cxx
+++ b/sc/source/ui/namedlg/namedlg.cxx
@@ -164,7 +164,7 @@ void ScNameDlg::SetReference( const ScRange& rRef, ScDocument& rDocP )
     {
         if ( rRef.aStart != rRef.aEnd )
             RefInputStart(m_xEdAssign.get());
-        OUString aRefStr(rRef.Format(ScRefFlags::RANGE_ABS_3D, &rDocP,
+        OUString aRefStr(rRef.Format(rDocP, ScRefFlags::RANGE_ABS_3D,
                 ScAddress::Details(rDocP.GetAddressConvention(), 0, 0)));
         m_xEdAssign->SetRefString( aRefStr );
     }
diff --git a/sc/source/ui/navipi/content.cxx b/sc/source/ui/navipi/content.cxx
index bb3168956dd2..b778232ada75 100644
--- a/sc/source/ui/navipi/content.cxx
+++ b/sc/source/ui/navipi/content.cxx
@@ -355,7 +355,7 @@ static OUString lcl_GetDBAreaRange( const ScDocument* pDoc, const OUString& rDBN
         {
             ScRange aRange;
             pData->GetArea(aRange);
-            aRet = aRange.Format(ScRefFlags::RANGE_ABS_3D, pDoc);
+            aRet = aRange.Format(*pDoc, ScRefFlags::RANGE_ABS_3D);
         }
     }
     return aRet;
@@ -421,7 +421,7 @@ IMPL_LINK_NOARG(ScContentTree, ContentDoubleClickHdl, SvTreeListBox*, bool)
                 {
                     const ScRange& aRange = pLink->GetDestArea();
                     ScDocument* pSrcDoc = GetSourceDocument();
-                    OUString aRangeStr(aRange.Format(ScRefFlags::RANGE_ABS_3D, pSrcDoc, pSrcDoc->GetAddressConvention()));
+                    OUString aRangeStr(aRange.Format(*pSrcDoc, ScRefFlags::RANGE_ABS_3D, pSrcDoc->GetAddressConvention()));
                     pParentWindow->SetCurrentCellStr( aRangeStr );
                 }
             }
diff --git a/sc/source/ui/optdlg/tpusrlst.cxx b/sc/source/ui/optdlg/tpusrlst.cxx
index c50f171664fb..5d1868dc61ef 100644
--- a/sc/source/ui/optdlg/tpusrlst.cxx
+++ b/sc/source/ui/optdlg/tpusrlst.cxx
@@ -115,7 +115,7 @@ void ScTpUserLists::Init()
         PutInOrder( nStartTab, nEndTab );
 
         aStrSelectedArea = ScRange( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab
-                ).Format(ScRefFlags::RANGE_ABS_3D, pDoc);
+                ).Format(*pDoc, ScRefFlags::RANGE_ABS_3D);
 
         mxBtnCopy->connect_clicked ( LINK( this, ScTpUserLists, BtnClickHdl ) );
         mxBtnCopy->set_sensitive(true);
diff --git a/sc/source/ui/pagedlg/areasdlg.cxx b/sc/source/ui/pagedlg/areasdlg.cxx
index ddd8eb868b64..49bc0cbb54be 100644
--- a/sc/source/ui/pagedlg/areasdlg.cxx
+++ b/sc/source/ui/pagedlg/areasdlg.cxx
@@ -176,7 +176,7 @@ void ScPrintAreasDlg::SetReference( const ScRange& rRef, ScDocument& /* rDoc */
 
         if (m_xEdPrintArea.get() == m_pRefInputEdit)
         {
-            aStr = rRef.Format(ScRefFlags::RANGE_ABS, pDoc, eConv);
+            aStr = rRef.Format(*pDoc, ScRefFlags::RANGE_ABS, eConv);
             OUString aVal = m_xEdPrintArea->GetText();
             Selection aSel = m_xEdPrintArea->GetSelection();
             aSel.Justify();
@@ -269,7 +269,7 @@ void ScPrintAreasDlg::Impl_Reset()
         {
             if ( !aStrRange.isEmpty() )
                 aStrRange += OUStringChar(sep);
-            aStrRange += pPrintRange->Format(ScRefFlags::RANGE_ABS, pDoc, eConv);
+            aStrRange += pPrintRange->Format(*pDoc, ScRefFlags::RANGE_ABS, eConv);
         }
     }
     m_xEdPrintArea->SetText( aStrRange );
@@ -305,7 +305,7 @@ bool ScPrintAreasDlg::Impl_GetItem( const formula::RefEdit* pEd, SfxStringItem&
         ScRange aRange;
         const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
         lcl_CheckRepeatString(aRangeStr, pDoc, m_xEdRepeatRow.get() == pEd, &aRange);
-        aRangeStr = aRange.Format(ScRefFlags::RANGE_ABS, pDoc, eConv);
+        aRangeStr = aRange.Format(*pDoc, ScRefFlags::RANGE_ABS, eConv);
     }
 
     rItem.SetValue( aRangeStr );
@@ -392,12 +392,12 @@ void ScPrintAreasDlg::Impl_FillLists()
     formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
 
     if ( bSimple )
-        aStrRange = aRange.Format(ScRefFlags::RANGE_ABS, pDoc, eConv);
+        aStrRange = aRange.Format(*pDoc, ScRefFlags::RANGE_ABS, eConv);
     else
     {
         ScRangeListRef aList( new ScRangeList );
         pViewData->GetMarkData().FillRangeListWithMarks( aList.get(), false );
-        aList->Format(aStrRange, ScRefFlags::RANGE_ABS, pDoc, eConv);
+        aList->Format(aStrRange, ScRefFlags::RANGE_ABS, *pDoc, eConv);
     }
 
     m_xLbPrintArea->set_id(SC_AREASDLG_PR_SELECT, aStrRange);
@@ -424,7 +424,7 @@ void ScPrintAreasDlg::Impl_FillLists()
         {
             if (rEntry.second->HasType(ScRangeData::Type::PrintArea))
             {
-                aSymbol = aRange.Format(ScRefFlags::RANGE_ABS, pDoc, eConv);
+                aSymbol = aRange.Format(*pDoc, ScRefFlags::RANGE_ABS, eConv);
                 m_xLbPrintArea->append(aSymbol, aName);
             }
 
diff --git a/sc/source/ui/unoobj/addruno.cxx b/sc/source/ui/unoobj/addruno.cxx
index c9192ff402e0..d35f3e1f77d9 100644
--- a/sc/source/ui/unoobj/addruno.cxx
+++ b/sc/source/ui/unoobj/addruno.cxx
@@ -245,7 +245,7 @@ uno::Any SAL_CALL ScAddressConversionObj::getPropertyValue( const OUString& aPro
         if ( aRange.aStart.Tab() != nRefSheet )
             nFlags |= ScRefFlags::TAB_3D;
         if ( bIsRange )
-            aFormatStr = aRange.Format(nFlags, &rDoc);
+            aFormatStr = aRange.Format(rDoc, nFlags);
         else
             aFormatStr = aRange.aStart.Format(nFlags, &rDoc);
         aRet <<= aFormatStr;
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 34aba2fd2769..45df3be40ddc 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -2514,7 +2514,7 @@ void ScCellRangesBase::GetOnePropertyValue( const SfxItemPropertySimpleEntry* pE
                 case SC_WID_UNO_ABSNAME:
                     {
                         OUString sRet;
-                        aRanges.Format(sRet, ScRefFlags::RANGE_ABS_3D, &pDocShell->GetDocument());
+                        aRanges.Format(sRet, ScRefFlags::RANGE_ABS_3D, pDocShell->GetDocument());
                         rAny <<= sRet;
                     }
                 break;
@@ -4123,7 +4123,7 @@ OUString SAL_CALL ScCellRangesObj::getRangeAddressesAsString()
     ScDocShell* pDocSh = GetDocShell();
     const ScRangeList& rRanges = GetRangeList();
     if (pDocSh)
-        rRanges.Format( aString, ScRefFlags::VALID | ScRefFlags::TAB_3D, &pDocSh->GetDocument() );
+        rRanges.Format( aString, ScRefFlags::VALID | ScRefFlags::TAB_3D, pDocSh->GetDocument() );
     return aString;
 }
 
@@ -4290,7 +4290,7 @@ static bool lcl_FindRangeByName( const ScRangeList& rRanges, ScDocShell* pDocSh,
         ScDocument& rDoc = pDocSh->GetDocument();
         for ( size_t i = 0, nCount = rRanges.size(); i < nCount; i++ )
         {
-            aRangeStr = rRanges[ i ].Format(ScRefFlags::VALID | ScRefFlags::TAB_3D, &rDoc);
+            aRangeStr = rRanges[ i ].Format(rDoc, ScRefFlags::VALID | ScRefFlags::TAB_3D);
             if ( aRangeStr == rName )
             {
                 rIndex = i;
@@ -4481,7 +4481,7 @@ uno::Sequence<OUString> SAL_CALL ScCellRangesObj::getElementNames()
             if (m_pImpl->m_aNamedEntries.empty() ||
                 !lcl_FindEntryName(m_pImpl->m_aNamedEntries, rRange, aRangeStr))
             {
-                aRangeStr = rRange.Format(ScRefFlags::VALID | ScRefFlags::TAB_3D, &rDoc);
+                aRangeStr = rRange.Format(rDoc, ScRefFlags::VALID | ScRefFlags::TAB_3D);
             }
             pAry[i] = aRangeStr;
         }
diff --git a/sc/source/ui/unoobj/chartuno.cxx b/sc/source/ui/unoobj/chartuno.cxx
index c3b7e4f47380..b17c64801399 100644
--- a/sc/source/ui/unoobj/chartuno.cxx
+++ b/sc/source/ui/unoobj/chartuno.cxx
@@ -207,7 +207,7 @@ void SAL_CALL ScChartsObj::addNewByName( const OUString& rName,
             if( xReceiver.is())
             {
                 OUString sRangeStr;
-                xNewRanges->Format(sRangeStr, ScRefFlags::RANGE_ABS_3D, &rDoc);
+                xNewRanges->Format(sRangeStr, ScRefFlags::RANGE_ABS_3D, rDoc);
 
                 // connect
                 if( !sRangeStr.isEmpty() )
diff --git a/sc/source/ui/vba/vbapagesetup.cxx b/sc/source/ui/vba/vbapagesetup.cxx
index 15b27350acdb..12eaa49e13d0 100644
--- a/sc/source/ui/vba/vbapagesetup.cxx
+++ b/sc/source/ui/vba/vbapagesetup.cxx
@@ -77,7 +77,7 @@ OUString SAL_CALL ScVbaPageSetup::getPrintArea()
             aRangeList.push_back( aRange );
         }
         ScDocument& rDoc = excel::getDocShell( mxModel )->GetDocument();
-        aRangeList.Format( aPrintArea, ScRefFlags::RANGE_ABS, &rDoc, formula::FormulaGrammar::CONV_XL_A1, ','  );
+        aRangeList.Format( aPrintArea, ScRefFlags::RANGE_ABS, rDoc, formula::FormulaGrammar::CONV_XL_A1, ','  );
     }
 
     return aPrintArea;
diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx
index cbe375af50bf..7b049cb1c6ca 100644
--- a/sc/source/ui/vba/vbarange.cxx
+++ b/sc/source/ui/vba/vbarange.cxx
@@ -2081,7 +2081,7 @@ ScVbaRange::Address(  const uno::Any& RowAbsolute, const uno::Any& ColumnAbsolut
         table::CellRangeAddress refAddress = getCellRangeAddressForVBARange( RelativeTo, pDocShell );
         dDetails = ScAddress::Details( formula::FormulaGrammar::CONV_XL_R1C1, static_cast< SCROW >( refAddress.StartRow ), static_cast< SCCOL >( refAddress.StartColumn ) );
     }
-    return aRange.Format(nFlags, &rDoc, dDetails);
+    return aRange.Format(rDoc, nFlags, dDetails);
 }
 
 uno::Reference < excel::XFont >
diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx
index 67908ba1ba68..493f3473c4db 100644
--- a/sc/source/ui/view/cellsh.cxx
+++ b/sc/source/ui/view/cellsh.cxx
@@ -677,7 +677,7 @@ void ScCellShell::GetState(SfxItemSet &rSet)
                     ScRange aRange;
                     if ( pData->GetSimpleArea( aRange ) == SC_MARK_SIMPLE )
                     {
-                        OUString aStr(aRange.Format(ScRefFlags::VALID | ScRefFlags::TAB_3D,pDoc));
+                        OUString aStr(aRange.Format(*pDoc, ScRefFlags::VALID | ScRefFlags::TAB_3D));
                         rSet.Put( SfxStringItem( nWhich, aStr ) );
                     }
                 }
diff --git a/sc/source/ui/view/cellsh2.cxx b/sc/source/ui/view/cellsh2.cxx
index 8be53409fb9b..f0a042a702f3 100644
--- a/sc/source/ui/view/cellsh2.cxx
+++ b/sc/source/ui/view/cellsh2.cxx
@@ -178,10 +178,10 @@ static bool lcl_GetSortParam( const ScViewData* pData, const ScSortParam& rSortP
          (rSortParam.nRow1 == rSortParam.nRow2 && aExternalRange.aStart.Row() != aExternalRange.aEnd.Row())))
     {
         pTabViewShell->AddHighlightRange( aExternalRange,COL_LIGHTBLUE );
-        OUString aExtendStr( aExternalRange.Format(ScRefFlags::VALID, pDoc));
+        OUString aExtendStr( aExternalRange.Format(*pDoc, ScRefFlags::VALID));
 
         ScRange aCurrentRange( rSortParam.nCol1, rSortParam.nRow1, nTab, rSortParam.nCol2, rSortParam.nRow2, nTab );
-        OUString aCurrentStr( aCurrentRange.Format(ScRefFlags::VALID, pDoc));
+        OUString aCurrentStr(aCurrentRange.Format(*pDoc, ScRefFlags::VALID));
 
         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
 
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 9f4917b78be3..17c1bc503600 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -2280,7 +2280,7 @@ void ScGridWindow::MouseButtonUp( const MouseEvent& rMEvt )
             {
                 ScRange aScRange;
                 rMark.GetMarkArea( aScRange );
-                aAddr = aScRange.Format(ScRefFlags::RANGE_ABS);
+                aAddr = aScRange.Format(*pDoc, ScRefFlags::RANGE_ABS);
                 if ( aScRange.aStart == aScRange.aEnd )
                 {
                     //  make sure there is a range selection string even for a single cell
@@ -4007,7 +4007,7 @@ sal_Int8 ScGridWindow::DropTransferObj( ScTransferObj* pTransObj, SCCOL nDestPos
             OUString aChartName;
             if (pThisDoc->HasChartAtPoint( nThisTab, rLogicPos, aChartName ))
             {
-                OUString aRangeName(aSource.Format(ScRefFlags::RANGE_ABS_3D, pThisDoc));
+                OUString aRangeName(aSource.Format(*pThisDoc, ScRefFlags::RANGE_ABS_3D));
                 SfxStringItem aNameItem( SID_CHART_NAME, aChartName );
                 SfxStringItem aRangeItem( SID_CHART_SOURCE, aRangeName );
                 sal_uInt16 nId = bIsMove ? SID_CHART_SOURCE : SID_CHART_ADDSOURCE;
@@ -4202,7 +4202,7 @@ sal_Int8 ScGridWindow::DropTransferObj( ScTransferObj* pTransObj, SCCOL nDestPos
                 {
                     OUString aApp = Application::GetAppName();
                     OUString aTopic = pSourceSh->GetTitle( SFX_TITLE_FULLNAME );
-                    OUString aItem(aSource.Format(ScRefFlags::VALID | ScRefFlags::TAB_3D, pSourceDoc));
+                    OUString aItem(aSource.Format(*pSourceDoc, ScRefFlags::VALID | ScRefFlags::TAB_3D));
 
                     // TODO: we could define ocQuote for "
                     const OUString aQuote('"');
diff --git a/sc/source/ui/view/gridwin2.cxx b/sc/source/ui/view/gridwin2.cxx
index 4a3364593b85..83143de0c18b 100644
--- a/sc/source/ui/view/gridwin2.cxx
+++ b/sc/source/ui/view/gridwin2.cxx
@@ -1056,9 +1056,9 @@ void ScGridWindow::PagebreakMove( const MouseEvent& rMEvt, bool bUp )
                     {
                         OUString aTemp;
                         if ( *pOld != aPagebreakSource )
-                            aTemp = pOld->Format(ScRefFlags::VALID);
+                            aTemp = pOld->Format(rDoc, ScRefFlags::VALID);
                         else if ( !bHide )
-                            aTemp = aPagebreakDrag.Format(ScRefFlags::VALID);
+                            aTemp = aPagebreakDrag.Format(rDoc, ScRefFlags::VALID);
                         if (!aTemp.isEmpty())
                         {
                             if ( !aNewRanges.isEmpty() )
@@ -1069,7 +1069,7 @@ void ScGridWindow::PagebreakMove( const MouseEvent& rMEvt, bool bUp )
                 }
             }
             else if (!bHide)
-                aNewRanges = aPagebreakDrag.Format(ScRefFlags::VALID);
+                aNewRanges = aPagebreakDrag.Format(rDoc, ScRefFlags::VALID);
 
             pViewFunc->SetPrintRanges( rDoc.IsPrintEntireSheet( nTab ), &aNewRanges, nullptr, nullptr, false );
         }
diff --git a/sc/source/ui/view/viewfun6.cxx b/sc/source/ui/view/viewfun6.cxx
index 0e3cfde39e24..393b33c3a09b 100644
--- a/sc/source/ui/view/viewfun6.cxx
+++ b/sc/source/ui/view/viewfun6.cxx
@@ -104,9 +104,9 @@ void ScViewFunc::DetectiveRefresh()
     RecalcPPT();
 }
 
-static void lcl_jumpToRange(const ScRange& rRange, ScViewData* pView, const ScDocument* pDoc)
+static void lcl_jumpToRange(const ScRange& rRange, ScViewData* pView, const ScDocument& rDoc)
 {
-    OUString aAddrText(rRange.Format(ScRefFlags::RANGE_ABS_3D, pDoc));
+    OUString aAddrText(rRange.Format(rDoc, ScRefFlags::RANGE_ABS_3D));
     SfxStringItem aPosItem(SID_CURRENTCELL, aAddrText);
     SfxBoolItem aUnmarkItem(FN_PARAM_1, true);        // remove existing selection
     pView->GetDispatcher().ExecuteList(
@@ -137,7 +137,7 @@ void ScViewFunc::MarkAndJumpToRanges(const ScRangeList& rRanges)
 
     // Jump to the first range of all precedent ranges.
     const ScRange & r = aRangesToMark.front();
-    lcl_jumpToRange(r, &rView, &pDocSh->GetDocument());
+    lcl_jumpToRange(r, &rView, pDocSh->GetDocument());
 
     ListSize = aRangesToMark.size();
     for ( size_t i = 0; i < ListSize; ++i )
@@ -180,7 +180,7 @@ void ScViewFunc::DetectiveMarkPred()
         if (pPath && ScRefTokenHelper::getRangeFromToken(aRange, p, aCurPos, true))
         {
             OUString aTabName = p->GetString().getString();
-            OUString aRangeStr(aRange.Format(ScRefFlags::VALID));
+            OUString aRangeStr(aRange.Format(rDoc, ScRefFlags::VALID));
             OUString sUrl =
                 *pPath +
                 "#" +
@@ -200,7 +200,7 @@ void ScViewFunc::DetectiveMarkPred()
         {
             // The first precedent range is on a different sheet.  Jump to it
             // immediately and forget the rest.
-            lcl_jumpToRange(aRange, &rView, &rDoc);
+            lcl_jumpToRange(aRange, &rView, rDoc);
             return;
         }
     }
commit 7cb1599411c309a8544c8e86845593026a773f32
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Thu Nov 14 12:54:56 2019 +0000
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Thu Nov 14 21:23:11 2019 +0100

    mpDoc is assumed to be non-null
    
    Change-Id: Ib3fbd6cc2b01e4923e97260b66aa1cd7807ee281
    Reviewed-on: https://gerrit.libreoffice.org/82684
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sc/source/ui/inc/namedefdlg.hxx b/sc/source/ui/inc/namedefdlg.hxx
index 8c46f64fb43c..5b13f22c60dc 100644
--- a/sc/source/ui/inc/namedefdlg.hxx
+++ b/sc/source/ui/inc/namedefdlg.hxx
@@ -23,7 +23,7 @@ class ScNameDefDlg : public ScAnyRefDlgController
 {
 private:
     bool const mbUndo; //if true we need to add an undo action after creating a range name
-    ScDocument* mpDoc;
+    ScDocument& mrDoc;
     ScDocShell* mpDocShell;
 
     ScAddress const maCursorPos;
diff --git a/sc/source/ui/namedlg/namedefdlg.cxx b/sc/source/ui/namedlg/namedefdlg.cxx
index 06f8c720f1b7..8b744839a0a7 100644
--- a/sc/source/ui/namedlg/namedefdlg.cxx
+++ b/sc/source/ui/namedlg/namedefdlg.cxx
@@ -30,7 +30,7 @@ ScNameDefDlg::ScNameDefDlg( SfxBindings* pB, SfxChildWindow* pCW, weld::Window*
         const ScAddress& aCursorPos, const bool bUndo )
     : ScAnyRefDlgController( pB, pCW, pParent, "modules/scalc/ui/definename.ui", "DefineNameDialog")
     , mbUndo( bUndo )
-    , mpDoc( pViewData->GetDocument() )
+    , mrDoc(*pViewData->GetDocument())
     , mpDocShell ( pViewData->GetDocShell() )
     , maCursorPos( aCursorPos )
     , maGlobalNameStr  ( ScResId(STR_GLOBAL_SCOPE) )
@@ -59,11 +59,11 @@ ScNameDefDlg::ScNameDefDlg( SfxBindings* pB, SfxChildWindow* pCW, weld::Window*
     // Initialize scope list.
     m_xLbScope->append_text(maGlobalNameStr);
     m_xLbScope->set_active(0);
-    SCTAB n = mpDoc->GetTableCount();
+    SCTAB n = mrDoc.GetTableCount();
     for (SCTAB i = 0; i < n; ++i)
     {
         OUString aTabName;
-        mpDoc->GetName(i, aTabName);
+        mrDoc.GetName(i, aTabName);
         m_xLbScope->append_text(aTabName);
     }
 
@@ -77,8 +77,8 @@ ScNameDefDlg::ScNameDefDlg( SfxBindings* pB, SfxChildWindow* pCW, weld::Window*
     ScRange aRange;
 
     pViewData->GetSimpleArea( aRange );
-    OUString aAreaStr(aRange.Format(ScRefFlags::RANGE_ABS_3D, mpDoc,
-            ScAddress::Details(mpDoc->GetAddressConvention(), 0, 0)));
+    OUString aAreaStr(aRange.Format(ScRefFlags::RANGE_ABS_3D, &mrDoc,
+            ScAddress::Details(mrDoc.GetAddressConvention(), 0, 0)));
 
     m_xEdRange->SetText( aAreaStr );
 
@@ -103,7 +103,7 @@ void ScNameDefDlg::CancelPushed()
 
 bool ScNameDefDlg::IsFormulaValid()
 {
-    ScCompiler aComp( mpDoc, maCursorPos, mpDoc->GetGrammar());
+    ScCompiler aComp( &mrDoc, maCursorPos, mrDoc.GetGrammar());
     std::unique_ptr<ScTokenArray> pCode = aComp.CompileString(m_xEdRange->GetText());
     if (pCode->GetCodeError() != FormulaError::NONE)
     {
@@ -139,7 +139,7 @@ bool ScNameDefDlg::IsNameValid()
         m_xFtInfo->set_label(maStrInfoDefault);
         return false;
     }
-    else if ((eType = ScRangeData::IsNameValid( aName, mpDoc )) != ScRangeData::NAME_VALID)
+    else if ((eType = ScRangeData::IsNameValid( aName, &mrDoc )) != ScRangeData::NAME_VALID)
     {
         m_xFtInfo->set_message_type(weld::EntryMessageType::Error);
         if (eType == ScRangeData::NAME_INVALID_BAD_STRING)
@@ -204,66 +204,63 @@ void ScNameDefDlg::AddPushed()
         return;
     else
     {
-        if ( mpDoc )
-        {
-            ScRangeData::Type nType = ScRangeData::Type::Name;
+        ScRangeData::Type nType = ScRangeData::Type::Name;
+
+        ScRangeData* pNewEntry = new ScRangeData( &mrDoc,
+                aName,
+                aExpression,
+                maCursorPos,
+                nType );
 
-            ScRangeData* pNewEntry = new ScRangeData( mpDoc,
-                    aName,
-                    aExpression,
-                    maCursorPos,
-                    nType );
+        if ( m_xBtnRowHeader->get_active() ) nType |= ScRangeData::Type::RowHeader;
+        if ( m_xBtnColHeader->get_active() ) nType |= ScRangeData::Type::ColHeader;
+        if ( m_xBtnPrintArea->get_active() ) nType |= ScRangeData::Type::PrintArea;
+        if ( m_xBtnCriteria->get_active()  ) nType |= ScRangeData::Type::Criteria;
 
-            if ( m_xBtnRowHeader->get_active() ) nType |= ScRangeData::Type::RowHeader;
-            if ( m_xBtnColHeader->get_active() ) nType |= ScRangeData::Type::ColHeader;
-            if ( m_xBtnPrintArea->get_active() ) nType |= ScRangeData::Type::PrintArea;
-            if ( m_xBtnCriteria->get_active()  ) nType |= ScRangeData::Type::Criteria;
+        pNewEntry->AddType(nType);
 
-            pNewEntry->AddType(nType);
+        // aExpression valid?
+        if ( FormulaError::NONE == pNewEntry->GetErrCode() )
+        {
+            if ( !pRangeName->insert( pNewEntry, false /*bReuseFreeIndex*/ ) )
+                pNewEntry = nullptr;
 
-            // aExpression valid?
-            if ( FormulaError::NONE == pNewEntry->GetErrCode() )
+            if (mbUndo)
             {
-                if ( !pRangeName->insert( pNewEntry, false /*bReuseFreeIndex*/ ) )
-                    pNewEntry = nullptr;
-
-                if (mbUndo)
-                {
-                    // this means we called directly through the menu
-
-                    SCTAB nTab;
-                    // if no table with that name is found, assume global range name
-                    if (!mpDoc->GetTable(aScope, nTab))
-                        nTab = -1;
-
-                    assert( pNewEntry);     // undo of no insertion smells fishy
-                    if (pNewEntry)
-                        mpDocShell->GetUndoManager()->AddUndoAction(
-                                std::make_unique<ScUndoAddRangeData>( mpDocShell, pNewEntry, nTab) );
-
-                    // set table stream invalid, otherwise RangeName won't be saved if no other
-                    // call invalidates the stream
-                    if (nTab != -1)
-                        mpDoc->SetStreamValid(nTab, false);
-                    SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScAreasChanged ) );
-                    mpDocShell->SetDocumentModified();
-                    Close();
-                }
-                else
-                {
-                    maName = aName;
-                    maScope = aScope;
-                    ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
-                    pViewSh->SwitchBetweenRefDialogs(this);
-                }
+                // this means we called directly through the menu
+
+                SCTAB nTab;
+                // if no table with that name is found, assume global range name
+                if (!mrDoc.GetTable(aScope, nTab))
+                    nTab = -1;
+
+                assert( pNewEntry);     // undo of no insertion smells fishy
+                if (pNewEntry)
+                    mpDocShell->GetUndoManager()->AddUndoAction(
+                            std::make_unique<ScUndoAddRangeData>( mpDocShell, pNewEntry, nTab) );
+
+                // set table stream invalid, otherwise RangeName won't be saved if no other
+                // call invalidates the stream
+                if (nTab != -1)
+                    mrDoc.SetStreamValid(nTab, false);
+                SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScAreasChanged ) );
+                mpDocShell->SetDocumentModified();
+                Close();
             }
             else
             {
-                delete pNewEntry;
-                m_xEdRange->GrabFocus();
-                m_xEdRange->SelectAll();
+                maName = aName;
+                maScope = aScope;
+                ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
+                pViewSh->SwitchBetweenRefDialogs(this);
             }
         }
+        else
+        {
+            delete pNewEntry;
+            m_xEdRange->GrabFocus();
+            m_xEdRange->SelectAll();
+        }
     }
 }
 


More information about the Libreoffice-commits mailing list