sc/inc/arealink.hxx                                          |    2 
 sc/inc/document.hxx                                          |    8 +-
 sc/inc/tablink.hxx                                           |    2 
 sc/source/core/data/SolverSettings.cxx                       |    2 
 sc/source/core/data/attarray.cxx                             |    1 
 sc/source/core/data/bcaslot.cxx                              |    3 
 sc/source/core/data/dociter.cxx                              |    1 
 sc/source/core/data/documen2.cxx                             |    4 -
 sc/source/core/data/documen3.cxx                             |    1 
 sc/source/core/data/documen4.cxx                             |    1 
 sc/source/core/data/documen5.cxx                             |    3 
 sc/source/core/data/documen8.cxx                             |    5 -
 sc/source/core/data/documen9.cxx                             |    3 
 sc/source/core/data/document.cxx                             |   10 +-
 sc/source/core/data/document10.cxx                           |    2 
 sc/source/core/data/drwlayer.cxx                             |    5 -
 sc/source/core/data/simpleformulacalc.cxx                    |    1 
 sc/source/core/data/table1.cxx                               |    1 
 sc/source/core/data/table2.cxx                               |    4 -
 sc/source/core/data/validat.cxx                              |    5 -
 sc/source/core/tool/addinlis.cxx                             |    1 
 sc/source/core/tool/address.cxx                              |    1 
 sc/source/core/tool/adiasync.cxx                             |    1 
 sc/source/core/tool/chgtrack.cxx                             |    3 
 sc/source/core/tool/compiler.cxx                             |    3 
 sc/source/core/tool/detfunc.cxx                              |    2 
 sc/source/core/tool/editutil.cxx                             |    3 
 sc/source/core/tool/formulalogger.cxx                        |    3 
 sc/source/core/tool/formulaparserpool.cxx                    |    5 -
 sc/source/core/tool/interpr1.cxx                             |    3 
 sc/source/core/tool/interpr2.cxx                             |    3 
 sc/source/core/tool/interpr4.cxx                             |    5 -
 sc/source/core/tool/progress.cxx                             |    1 
 sc/source/filter/dif/difexp.cxx                              |    1 
 sc/source/filter/dif/difimp.cxx                              |    1 
 sc/source/filter/excel/excdoc.cxx                            |    7 +
 sc/source/filter/excel/excform8.cxx                          |    1 
 sc/source/filter/excel/excimp8.cxx                           |    7 +
 sc/source/filter/excel/expop2.cxx                            |    6 -
 sc/source/filter/excel/impop.cxx                             |    5 -
 sc/source/filter/excel/namebuff.cxx                          |    1 
 sc/source/filter/excel/read.cxx                              |    1 
 sc/source/filter/excel/xecontent.cxx                         |    3 
 sc/source/filter/excel/xehelper.cxx                          |    1 
 sc/source/filter/excel/xeroot.cxx                            |    3 
 sc/source/filter/excel/xichart.cxx                           |    5 -
 sc/source/filter/excel/xicontent.cxx                         |    1 
 sc/source/filter/excel/xiescher.cxx                          |   15 ++-
 sc/source/filter/excel/xilink.cxx                            |    1 
 sc/source/filter/excel/xistyle.cxx                           |   11 +-
 sc/source/filter/excel/xlroot.cxx                            |    7 +
 sc/source/filter/html/htmlexp.cxx                            |    3 
 sc/source/filter/html/htmlpars.cxx                           |   13 +--
 sc/source/filter/inc/xlroot.hxx                              |    3 
 sc/source/filter/lotus/filter.cxx                            |    1 
 sc/source/filter/lotus/lotread.cxx                           |    1 
 sc/source/filter/oox/excelfilter.cxx                         |    2 
 sc/source/filter/oox/workbookhelper.cxx                      |    2 
 sc/source/filter/rtf/eeimpars.cxx                            |    1 
 sc/source/filter/xcl97/xcl97esc.cxx                          |    1 
 sc/source/filter/xml/XMLTableSourceContext.cxx               |    1 
 sc/source/filter/xml/xmlcelli.cxx                            |    1 
 sc/source/filter/xml/xmlimprt.cxx                            |    4 -
 sc/source/filter/xml/xmlwrap.cxx                             |    4 -
 sc/source/ui/Accessibility/AccessibleCellBase.cxx            |   42 +++++------
 sc/source/ui/Accessibility/AccessibleDocument.cxx            |    2 
 sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx |    2 
 sc/source/ui/Accessibility/AccessibleEditObject.cxx          |    8 +-
 sc/source/ui/Accessibility/AccessibleText.cxx                |    8 +-
 sc/source/ui/app/inputhdl.cxx                                |    2 
 sc/source/ui/dataprovider/csvdataprovider.cxx                |    2 
 sc/source/ui/dataprovider/dataprovider.cxx                   |    2 
 sc/source/ui/docshell/arealink.cxx                           |    5 -
 sc/source/ui/docshell/docfunc.cxx                            |    2 
 sc/source/ui/docshell/docsh3.cxx                             |    2 
 sc/source/ui/docshell/externalrefmgr.cxx                     |   10 +-
 sc/source/ui/docshell/impex.cxx                              |   10 +-
 sc/source/ui/docshell/macromgr.cxx                           |    4 -
 sc/source/ui/docshell/tablink.cxx                            |   23 ------
 sc/source/ui/formdlg/formula.cxx                             |    6 -
 sc/source/ui/navipi/content.cxx                              |    4 -
 sc/source/ui/undo/areasave.cxx                               |    3 
 sc/source/ui/unoobj/PivotTableDataProvider.cxx               |    3 
 sc/source/ui/unoobj/cellsuno.cxx                             |    3 
 sc/source/ui/unoobj/chart2uno.cxx                            |    3 
 sc/source/ui/unoobj/shapeuno.cxx                             |   20 +----
 sc/source/ui/vba/vbainterior.cxx                             |    3 
 sc/source/ui/view/cliputil.cxx                               |    2 
 sc/source/ui/view/drawview.cxx                               |    6 -
 sc/source/ui/view/gridwin.cxx                                |    2 
 sc/source/ui/view/viewfun3.cxx                               |    2 
 sc/source/ui/xmlsource/xmlsourcedlg.cxx                      |    2 
 92 files changed, 210 insertions(+), 185 deletions(-)

New commits:
commit 6d61e34e5623eab8f735344b0e659d834f6069e0
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri Sep 15 14:22:52 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Sep 15 18:09:27 2023 +0200

    reduce casting around ScDocShell
    
    instead of using SfxObjectShell and then static_cast'ing it
    everywhere.
    
    Change-Id: Id3184e44f048228dc4d0d9fa5d579e663c2762cc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156945
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/inc/arealink.hxx b/sc/inc/arealink.hxx
index 81e884e093d3..5eff082b6b80 100644
--- a/sc/inc/arealink.hxx
+++ b/sc/inc/arealink.hxx
@@ -42,7 +42,7 @@ private:
     static bool FindExtRange( ScRange& rRange, const ScDocument& rSrcDoc, 
const OUString& rAreaName );
 
 public:
-    ScAreaLink( SfxObjectShell* pShell, OUString aFile,
+    ScAreaLink( ScDocShell* pShell, OUString aFile,
                     OUString aFilter, OUString aOpt,
                     OUString aArea, const ScRange& rDest, sal_Int32 
nRefreshDelaySeconds );
     virtual ~ScAreaLink() override;
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 94ff88b23d17..dbaf26c4e33d 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -368,7 +368,7 @@ private:
     ScUndoManager*     mpUndoManager;
     std::unique_ptr<ScFieldEditEngine>  mpEditEngine;                   // 
uses pEditPool from xPoolHelper
     std::unique_ptr<ScNoteEditEngine>   mpNoteEngine;                   // 
uses pEditPool from xPoolHelper
-    SfxObjectShell*     mpShell;
+    ScDocShell*     mpShell;
     VclPtr<SfxPrinter>  mpPrinter;
     VclPtr<VirtualDevice> mpVirtualDevice_100th_mm;
     std::unique_ptr<ScDrawLayer> mpDrawLayer;           // SdrModel
@@ -602,7 +602,7 @@ public:
                                                                 // number 
formatter
 public:
     SC_DLLPUBLIC                ScDocument( ScDocumentMode eMode = 
SCDOCMODE_DOCUMENT,
-                                            SfxObjectShell* pDocShell = 
nullptr );
+                                            ScDocShell* pDocShell = nullptr );
     SC_DLLPUBLIC                ~ScDocument();
 
     void              SetName( const OUString& r ) { aDocName = r; }
@@ -612,7 +612,7 @@ public:
 
     void              GetDocStat( ScDocStat& rDocStat );
 
-    SC_DLLPUBLIC void  InitDrawLayer( SfxObjectShell* pDocShell = nullptr );
+    SC_DLLPUBLIC void  InitDrawLayer( ScDocShell* pDocShell = nullptr );
 
     ScInterpreterContext& GetNonThreadedContext() const
     {
@@ -1080,7 +1080,7 @@ public:
     bool            SetDdeLinkResultMatrix( size_t nDdePos, const ScMatrixRef& 
pResults );
 
     SfxBindings*                    GetViewBindings();
-    SfxObjectShell*                 GetDocumentShell() const    { return 
mpShell; }
+    ScDocShell*                     GetDocumentShell() const    { return 
mpShell; }
     SC_DLLPUBLIC ScDrawLayer*       GetDrawLayer() { return mpDrawLayer.get(); 
 }
     SC_DLLPUBLIC const ScDrawLayer* GetDrawLayer() const { return 
mpDrawLayer.get();  }
     SfxBroadcaster*                 GetDrawBroadcaster();       // to avoid 
header
diff --git a/sc/inc/tablink.hxx b/sc/inc/tablink.hxx
index 6233ddc912fd..a7d27a1a961f 100644
--- a/sc/inc/tablink.hxx
+++ b/sc/inc/tablink.hxx
@@ -45,8 +45,6 @@ private:
 public:
     ScTableLink( ScDocShell* pDocSh, OUString aFile,
                     OUString aFilter, OUString aOpt, sal_Int32 
nRefreshDelaySeconds );
-    ScTableLink( SfxObjectShell* pShell, OUString aFile,
-                    OUString aFilter, OUString aOpt, sal_Int32 
nRefreshDelaySeconds );
     virtual ~ScTableLink() override;
     virtual void Closed() override;
     virtual ::sfx2::SvBaseLink::UpdateResult DataChanged(
diff --git a/sc/source/core/data/SolverSettings.cxx 
b/sc/source/core/data/SolverSettings.cxx
index 53fc497c849e..bbeeca7bd4cf 100644
--- a/sc/source/core/data/SolverSettings.cxx
+++ b/sc/source/core/data/SolverSettings.cxx
@@ -20,7 +20,7 @@ namespace sc
 SolverSettings::SolverSettings(ScTable& rTable)
     : m_rTable(rTable)
     , m_rDoc(m_rTable.GetDoc())
-    , m_pDocShell(dynamic_cast<ScDocShell*>(m_rDoc.GetDocumentShell()))
+    , m_pDocShell(m_rDoc.GetDocumentShell())
 {
     // Get the named range manager for this tab
     std::map<OUString, ScRangeName*> rRangeMap;
diff --git a/sc/source/core/data/attarray.cxx b/sc/source/core/data/attarray.cxx
index 02b6b9d793ed..2efd31c7675f 100644
--- a/sc/source/core/data/attarray.cxx
+++ b/sc/source/core/data/attarray.cxx
@@ -32,6 +32,7 @@
 #include <global.hxx>
 #include <document.hxx>
 #include <docpool.hxx>
+#include <docsh.hxx>
 #include <patattr.hxx>
 #include <stlsheet.hxx>
 #include <stlpool.hxx>
diff --git a/sc/source/core/data/bcaslot.cxx b/sc/source/core/data/bcaslot.cxx
index 910eb46082e6..c8f182e11f38 100644
--- a/sc/source/core/data/bcaslot.cxx
+++ b/sc/source/core/data/bcaslot.cxx
@@ -23,6 +23,7 @@
 #include <osl/diagnose.h>
 
 #include <document.hxx>
+#include <docsh.hxx>
 #include <brdcst.hxx>
 #include <bcaslot.hxx>
 #include <scerrors.hxx>
@@ -73,7 +74,7 @@ ScDocument::HardRecalcState 
ScBroadcastAreaSlot::CheckHardRecalcStateCondition()
     {
         if (aBroadcastAreaTbl.size() >= aBroadcastAreaTbl.max_size())
         {   // this is more hypothetical now, check existed for old 
SV_PTRARR_SORT
-            SfxObjectShell* pShell = pDoc->GetDocumentShell();
+            ScDocShell* pShell = pDoc->GetDocumentShell();
             OSL_ENSURE( pShell, "Missing DocShell :-/" );
 
             if ( pShell )
diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx
index 267d814daf76..5c0f0984b308 100644
--- a/sc/source/core/data/dociter.cxx
+++ b/sc/source/core/data/dociter.cxx
@@ -23,6 +23,7 @@
 #include <global.hxx>
 #include <dociter.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 #include <table.hxx>
 #include <column.hxx>
 #include <formulacell.hxx>
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index dd80e89434cc..4b07b0d33ff5 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -111,7 +111,7 @@ ScSheetLimits ScSheetLimits::CreateDefault()
         return ScSheetLimits(MAXCOL, MAXROW);
 }
 
-ScDocument::ScDocument( ScDocumentMode eMode, SfxObjectShell* pDocShell ) :
+ScDocument::ScDocument( ScDocumentMode eMode, ScDocShell* pDocShell ) :
         
mpCellStringPool(std::make_shared<svl::SharedStringPool>(ScGlobal::getCharClass())),
         mpDocLinkMgr(new sc::DocumentLinkManager(pDocShell)),
         mbFormulaGroupCxtBlockDiscard(false),
@@ -1090,7 +1090,7 @@ sal_uLong ScDocument::TransferTab( ScDocument& rSrcDoc, 
SCTAB nSrcPos,
 
     if ( bVbaEnabled  )
     {
-        SfxObjectShell* pSrcShell = rSrcDoc.GetDocumentShell();
+        ScDocShell* pSrcShell = rSrcDoc.GetDocumentShell();
         if ( pSrcShell )
         {
             OUString aLibName("Standard");
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index b52deed7d85b..b42a8d36b582 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -36,6 +36,7 @@
 #include <rangenam.hxx>
 #include <dbdata.hxx>
 #include <docpool.hxx>
+#include <docsh.hxx>
 #include <poolhelp.hxx>
 #include <rangelst.hxx>
 #include <chartlock.hxx>
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index 313340676df1..e9a4fea132f2 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -27,6 +27,7 @@
 #include <o3tl/string_view.hxx>
 
 #include <document.hxx>
+#include <docsh.hxx>
 #include <table.hxx>
 #include <globstr.hrc>
 #include <scresid.hxx>
diff --git a/sc/source/core/data/documen5.cxx b/sc/source/core/data/documen5.cxx
index 0355812a7b9f..b9356b210bf1 100644
--- a/sc/source/core/data/documen5.cxx
+++ b/sc/source/core/data/documen5.cxx
@@ -30,6 +30,7 @@
 #include <svtools/embedhlp.hxx>
 
 #include <document.hxx>
+#include <docsh.hxx>
 #include <table.hxx>
 #include <drwlayer.hxx>
 #include <chartlis.hxx>
@@ -313,7 +314,7 @@ void ScDocument::UpdateChartArea( const OUString& 
rChartName,
                         uno::Reference< chart2::data::XDataProvider > 
xDataProvider = new ScChart2DataProvider( this );
                         xReceiver->attachDataProvider( xDataProvider );
                         uno::Reference< util::XNumberFormatsSupplier > 
xNumberFormatsSupplier(
-                                mpShell->GetModel(), uno::UNO_QUERY );
+                                
static_cast<cppu::OWeakObject*>(mpShell->GetModel()), uno::UNO_QUERY );
                         xReceiver->attachNumberFormatsSupplier( 
xNumberFormatsSupplier );
                     }
 
diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index d77cb2204b60..84233f4c5867 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -51,6 +51,7 @@
 #include <column.hxx>
 #include <poolhelp.hxx>
 #include <docpool.hxx>
+#include <docsh.hxx>
 #include <stlpool.hxx>
 #include <stlsheet.hxx>
 #include <docoptio.hxx>
@@ -690,7 +691,7 @@ void ScDocument::RepaintRange( const ScRange& rRange )
 {
     if ( bIsVisible && mpShell )
     {
-        ScModelObj* pModel = comphelper::getFromUnoTunnel<ScModelObj>( 
mpShell->GetModel() );
+        ScModelObj* pModel = mpShell->GetModel();
         if ( pModel )
             pModel->RepaintRange( rRange );     // locked repaints are checked 
there
     }
@@ -700,7 +701,7 @@ void ScDocument::RepaintRange( const ScRangeList& rRange )
 {
     if ( bIsVisible && mpShell )
     {
-        ScModelObj* pModel = comphelper::getFromUnoTunnel<ScModelObj>( 
mpShell->GetModel() );
+        ScModelObj* pModel = mpShell->GetModel();
         if ( pModel )
             pModel->RepaintRange( rRange );     // locked repaints are checked 
there
     }
diff --git a/sc/source/core/data/documen9.cxx b/sc/source/core/data/documen9.cxx
index cc49d58c5cdb..a9f04943c0d1 100644
--- a/sc/source/core/data/documen9.cxx
+++ b/sc/source/core/data/documen9.cxx
@@ -38,6 +38,7 @@
 
 #include <document.hxx>
 #include <docoptio.hxx>
+#include <docsh.hxx>
 #include <table.hxx>
 #include <drwlayer.hxx>
 #include <markdata.hxx>
@@ -102,7 +103,7 @@ void ScDocument::TransferDrawPage(const ScDocument& 
rSrcDoc, SCTAB nSrcPos, SCTA
     ScChartHelper::UpdateChartsOnDestinationPage(*this, nDestPos);
 }
 
-void ScDocument::InitDrawLayer( SfxObjectShell* pDocShell )
+void ScDocument::InitDrawLayer( ScDocShell* pDocShell )
 {
     if (pDocShell && !mpShell)
     {
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 0c383ea12c99..68522377dae9 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -562,7 +562,7 @@ bool ScDocument::InsertTab(
 
         if (comphelper::LibreOfficeKit::isActive() && GetDrawLayer())
         {
-            ScModelObj* pModel = 
comphelper::getFromUnoTunnel<ScModelObj>(this->GetDocumentShell()->GetModel());
+            ScModelObj* pModel = GetDocumentShell()->GetModel();
             SfxLokHelper::notifyDocumentSizeChangedAllViews(pModel);
         }
     }
@@ -734,7 +734,7 @@ bool ScDocument::DeleteTab( SCTAB nTab )
 
             if (comphelper::LibreOfficeKit::isActive())
             {
-                ScModelObj* pModel = 
comphelper::getFromUnoTunnel<ScModelObj>(this->GetDocumentShell()->GetModel());
+                ScModelObj* pModel = GetDocumentShell()->GetModel();
                 SfxLokHelper::notifyDocumentSizeChangedAllViews(pModel);
             }
 
@@ -824,7 +824,7 @@ bool ScDocument::DeleteTabs( SCTAB nTab, SCTAB nSheets )
 
             if (comphelper::LibreOfficeKit::isActive())
             {
-                ScModelObj* pModel = 
comphelper::getFromUnoTunnel<ScModelObj>(this->GetDocumentShell()->GetModel());
+                ScModelObj* pModel = GetDocumentShell()->GetModel();
                 SfxLokHelper::notifyDocumentSizeChangedAllViews(pModel);
             }
 
@@ -870,7 +870,7 @@ bool ScDocument::RenameTab( SCTAB nTab, const OUString& 
rName, bool bExternalDoc
 
             if (comphelper::LibreOfficeKit::isActive() && GetDrawLayer())
             {
-                ScModelObj* pModel = 
comphelper::getFromUnoTunnel<ScModelObj>(this->GetDocumentShell()->GetModel());
+                ScModelObj* pModel = GetDocumentShell()->GetModel();
                 SfxLokHelper::notifyDocumentSizeChangedAllViews(pModel);
             }
         }
@@ -6615,7 +6615,7 @@ void ScDocument::SetNote(SCCOL nCol, SCROW nRow, SCTAB 
nTab, std::unique_ptr<ScP
     {
         pTable->SetNote(nCol, nRow, std::move(pNote));
 
-        if (ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(GetDocumentShell()))
+        if (ScDocShell* pDocSh = GetDocumentShell())
         {
             HelperNotifyChanges::NotifyIfChangesListeners(
                 *pDocSh, ScRange(nCol, nRow, nTab), "note");
diff --git a/sc/source/core/data/document10.cxx 
b/sc/source/core/data/document10.cxx
index 3b190b1882e5..a0a097d7de84 100644
--- a/sc/source/core/data/document10.cxx
+++ b/sc/source/core/data/document10.cxx
@@ -952,7 +952,7 @@ bool ScDocument::CopyAdjustRangeName( SCTAB& rSheet, 
sal_uInt16& rIndex, ScRange
 
         if (rpRangeData && !rNewDoc.IsClipOrUndo())
         {
-            ScDocShell* pDocSh = 
static_cast<ScDocShell*>(rNewDoc.GetDocumentShell());
+            ScDocShell* pDocSh = rNewDoc.GetDocumentShell();
             if (pDocSh)
                 pDocSh->SetAreasChangedNeedBroadcast();
         }
diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx
index 8e989012b4e8..26ee7fb41375 100644
--- a/sc/source/core/data/drwlayer.cxx
+++ b/sc/source/core/data/drwlayer.cxx
@@ -74,6 +74,7 @@
 #include <drawpage.hxx>
 #include <global.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 #include <userdat.hxx>
 #include <markdata.hxx>
 #include <globstr.hrc>
@@ -259,7 +260,7 @@ ScDrawLayer::ScDrawLayer( ScDocument* pDocument, OUString 
_aName ) :
 
     pGlobalDrawPersist = nullptr;          // Only use once
 
-    SfxObjectShell* pObjSh = pDocument ? pDocument->GetDocumentShell() : 
nullptr;
+    ScDocShell* pObjSh = pDocument ? pDocument->GetDocumentShell() : nullptr;
     XColorListRef pXCol = XColorList::GetStdColorList();
     if ( pObjSh )
     {
@@ -2941,7 +2942,7 @@ css::uno::Reference< css::uno::XInterface > 
ScDrawLayer::createUnoModel()
 {
     css::uno::Reference< css::uno::XInterface > xRet;
     if( pDoc && pDoc->GetDocumentShell() )
-        xRet = pDoc->GetDocumentShell()->GetModel();
+        xRet = 
static_cast<cppu::OWeakObject*>(pDoc->GetDocumentShell()->GetModel());
 
     return xRet;
 }
diff --git a/sc/source/core/data/simpleformulacalc.cxx 
b/sc/source/core/data/simpleformulacalc.cxx
index 102373d5a94a..cd2559e9f22f 100644
--- a/sc/source/core/data/simpleformulacalc.cxx
+++ b/sc/source/core/data/simpleformulacalc.cxx
@@ -10,6 +10,7 @@
 #include <memory>
 #include <simpleformulacalc.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 #include <tokenarray.hxx>
 #include <interpre.hxx>
 #include <compiler.hxx>
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 4c0cf3e02a9a..27ee878682ca 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -28,6 +28,7 @@
 #include <patattr.hxx>
 #include <table.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 #include <drwlayer.hxx>
 #include <olinetab.hxx>
 #include <global.hxx>
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index ab1516b8297d..31a0d6f1dd1e 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1327,7 +1327,7 @@ void ScTable::CopyToTable(
         pDestTab->SetRangeName( std::unique_ptr<ScRangeName>( new ScRangeName( 
*GetRangeName())));
         if (!pDestTab->rDocument.IsClipOrUndo())
         {
-            ScDocShell* pDocSh = 
static_cast<ScDocShell*>(pDestTab->rDocument.GetDocumentShell());
+            ScDocShell* pDocSh = pDestTab->rDocument.GetDocumentShell();
             if (pDocSh)
                 pDocSh->SetAreasChangedNeedBroadcast();
         }
@@ -1513,7 +1513,7 @@ void ScTable::UndoToTable(
         pDestTab->SetRangeName( std::unique_ptr<ScRangeName>( new ScRangeName( 
*GetRangeName())));
         if (!pDestTab->rDocument.IsClipOrUndo())
         {
-            ScDocShell* pDocSh = 
static_cast<ScDocShell*>(pDestTab->rDocument.GetDocumentShell());
+            ScDocShell* pDocSh = pDestTab->rDocument.GetDocumentShell();
             if (pDocSh)
                 pDocSh->SetAreasChangedNeedBroadcast();
         }
diff --git a/sc/source/core/data/validat.cxx b/sc/source/core/data/validat.cxx
index befdbb40831d..a46b09986b3d 100644
--- a/sc/source/core/data/validat.cxx
+++ b/sc/source/core/data/validat.cxx
@@ -39,6 +39,7 @@
 #include <osl/diagnose.h>
 
 #include <document.hxx>
+#include <docsh.hxx>
 #include <formulacell.hxx>
 #include <patattr.hxx>
 #include <globstr.hrc>
@@ -187,7 +188,7 @@ bool ScValidationData::DoScript( const ScAddress& rPos, 
const OUString& rInput,
                                 ScFormulaCell* pCell, weld::Window* pParent ) 
const
 {
     ScDocument* pDocument = GetDocument();
-    SfxObjectShell* pDocSh = pDocument->GetDocumentShell();
+    ScDocShell* pDocSh = pDocument->GetDocumentShell();
     if ( !pDocSh )
         return false;
 
@@ -266,7 +267,7 @@ bool ScValidationData::DoMacro( const ScAddress& rPos, 
const OUString& rInput,
     }
 
     ScDocument* pDocument = GetDocument();
-    SfxObjectShell* pDocSh = pDocument->GetDocumentShell();
+    ScDocShell* pDocSh = pDocument->GetDocumentShell();
     if ( !pDocSh )
         return false;
 
diff --git a/sc/source/core/tool/addinlis.cxx b/sc/source/core/tool/addinlis.cxx
index 9f09e464a229..f8a236780e07 100644
--- a/sc/source/core/tool/addinlis.cxx
+++ b/sc/source/core/tool/addinlis.cxx
@@ -24,6 +24,7 @@
 #include <addinlis.hxx>
 #include <miscuno.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 #include <brdcst.hxx>
 
 #include <com/sun/star/sheet/XVolatileResult.hpp>
diff --git a/sc/source/core/tool/address.cxx b/sc/source/core/tool/address.cxx
index 7d95ac0fdfd6..7b0c848a2b16 100644
--- a/sc/source/core/tool/address.cxx
+++ b/sc/source/core/tool/address.cxx
@@ -25,6 +25,7 @@
 #include <global.hxx>
 #include <compiler.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 #include <externalrefmgr.hxx>
 
 #include <osl/diagnose.h>
diff --git a/sc/source/core/tool/adiasync.cxx b/sc/source/core/tool/adiasync.cxx
index d9822fee3b4f..ba2b49eb3896 100644
--- a/sc/source/core/tool/adiasync.cxx
+++ b/sc/source/core/tool/adiasync.cxx
@@ -26,6 +26,7 @@
 #include <adiasync.hxx>
 #include <brdcst.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 #include <osl/diagnose.h>
 #include <osl/thread.h>
 
diff --git a/sc/source/core/tool/chgtrack.cxx b/sc/source/core/tool/chgtrack.cxx
index 49cc8c8d748e..53fe660f103d 100644
--- a/sc/source/core/tool/chgtrack.cxx
+++ b/sc/source/core/tool/chgtrack.cxx
@@ -21,6 +21,7 @@
 #include <compiler.hxx>
 #include <formulacell.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 #include <dociter.hxx>
 #include <global.hxx>
 #include <scmod.hxx>
@@ -2166,7 +2167,7 @@ void ScChangeTrack::ConfigurationChanged( 
utl::ConfigurationBroadcaster*, Config
         //  (Has to be done in the Notify handler, to be sure
         //  the user collection has already been updated)
 
-        SfxObjectShell* pDocSh = rDoc.GetDocumentShell();
+        ScDocShell* pDocSh = rDoc.GetDocumentShell();
         if (pDocSh)
             pDocSh->Broadcast( ScPaintHint( 
ScRange(0,0,0,rDoc.MaxCol(),rDoc.MaxRow(),MAXTAB), PaintPartFlags::Grid ) );
     }
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index c09383930e15..da0eadbe3309 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -53,6 +53,7 @@
 #include <rangenam.hxx>
 #include <dbdata.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 #include <callform.hxx>
 #include <addincol.hxx>
 #include <refupdat.hxx>
@@ -3554,7 +3555,7 @@ bool ScCompiler::ParseMacro( const OUString& rName )
 
     OUString aName( rName);
     StarBASIC* pObj = nullptr;
-    SfxObjectShell* pDocSh = rDoc.GetDocumentShell();
+    ScDocShell* pDocSh = rDoc.GetDocumentShell();
 
     try
     {
diff --git a/sc/source/core/tool/detfunc.cxx b/sc/source/core/tool/detfunc.cxx
index ac2c477b0210..b5dc71b92a63 100644
--- a/sc/source/core/tool/detfunc.cxx
+++ b/sc/source/core/tool/detfunc.cxx
@@ -1395,7 +1395,7 @@ void ScDetectiveFunc::UpdateAllComments( ScDocument& rDoc 
)
 
     aNewData.InitFromStyle(pStyleSheet);
 
-    ScDocShell* pDocSh = static_cast<ScDocShell*>(rDoc.GetDocumentShell());
+    ScDocShell* pDocSh = rDoc.GetDocumentShell();
     pDocSh->GetUndoManager()->AddUndoAction(
         std::make_unique<ScUndoModifyStyle>(pDocSh, pStyleSheet->GetFamily(), 
aOldData, aNewData));
 }
diff --git a/sc/source/core/tool/editutil.cxx b/sc/source/core/tool/editutil.cxx
index ce703b0f6a84..57e93d513866 100644
--- a/sc/source/core/tool/editutil.cxx
+++ b/sc/source/core/tool/editutil.cxx
@@ -43,6 +43,7 @@
 #include <attrib.hxx>
 #include <document.hxx>
 #include <docpool.hxx>
+#include <docsh.hxx>
 #include <patattr.hxx>
 #include <scmod.hxx>
 #include <inputopt.hxx>
@@ -269,7 +270,7 @@ OUString ScEditUtil::GetCellFieldValue(
         {
             if (pDoc)
             {
-                SfxObjectShell* pDocShell = pDoc->GetDocumentShell();
+                ScDocShell* pDocShell = pDoc->GetDocumentShell();
                 if (pDocShell)
                 {
                     aRet = pDocShell->getDocProperties()->getTitle();
diff --git a/sc/source/core/tool/formulalogger.cxx 
b/sc/source/core/tool/formulalogger.cxx
index c3282e3c0046..a5c01a596b42 100644
--- a/sc/source/core/tool/formulalogger.cxx
+++ b/sc/source/core/tool/formulalogger.cxx
@@ -9,6 +9,7 @@
 #include <formulacell.hxx>
 #include <tokenarray.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 #include <tokenstringcontext.hxx>
 #include <address.hxx>
 #include <interpre.hxx>
@@ -329,7 +330,7 @@ FormulaLogger::GroupScope FormulaLogger::enterGroup(
     const ScDocument& rDoc, const ScFormulaCell& rCell )
 {
     // Get the file name if available.
-    const SfxObjectShell* pShell = rDoc.GetDocumentShell();
+    const ScDocShell* pShell = rDoc.GetDocumentShell();
     const SfxMedium* pMedium = pShell ? pShell->GetMedium() : nullptr;
     OUString aName;
     if (pMedium)
diff --git a/sc/source/core/tool/formulaparserpool.cxx 
b/sc/source/core/tool/formulaparserpool.cxx
index 00c5c9108063..6ac873042d11 100644
--- a/sc/source/core/tool/formulaparserpool.cxx
+++ b/sc/source/core/tool/formulaparserpool.cxx
@@ -26,6 +26,7 @@
 #include <comphelper/processfactory.hxx>
 #include <sfx2/objsh.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 
 using namespace ::com::sun::star::beans;
 using namespace ::com::sun::star::container;
@@ -126,11 +127,11 @@ Reference< XFormulaParser > 
ScFormulaParserPool::getFormulaParser( const OUStrin
     Reference< XFormulaParser >& rxParser = maParsers[ rNamespace ];
 
     // try to create a new parser object
-    if( SfxObjectShell* pDocShell = mrDoc.GetDocumentShell() ) try
+    if( ScDocShell* pDocShell = mrDoc.GetDocumentShell() ) try
     {
         static ScParserFactoryMap theScParserFactoryMap;
 
-        Reference< XComponent > xComponent( pDocShell->GetModel(), 
UNO_QUERY_THROW );
+        Reference< XComponent > xComponent( pDocShell->GetModel() );
         rxParser = theScParserFactoryMap.createFormulaParser( xComponent, 
rNamespace );
     }
     catch( Exception& )
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index e5197dd34ece..e372228721e3 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -47,6 +47,7 @@
 #include <global.hxx>
 #include <document.hxx>
 #include <dociter.hxx>
+#include <docsh.hxx>
 #include <formulacell.hxx>
 #include <scmatrix.hxx>
 #include <docoptio.hxx>
@@ -2340,7 +2341,7 @@ void ScInterpreter::ScCell()
                     mrDoc.GetName( nTab, aFuncResult );
                 else
                 {
-                    SfxObjectShell* pShell = mrDoc.GetDocumentShell();
+                    ScDocShell* pShell = mrDoc.GetDocumentShell();
                     if( pShell && pShell->GetMedium() )
                     {
                         const INetURLObject& rURLObj = 
pShell->GetMedium()->GetURLObject();
diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx
index 60bde22f534b..a6753a4aa78b 100644
--- a/sc/source/core/tool/interpr2.cxx
+++ b/sc/source/core/tool/interpr2.cxx
@@ -37,6 +37,7 @@
 #include <formulacell.hxx>
 #include <document.hxx>
 #include <dociter.hxx>
+#include <docsh.hxx>
 #include <unitconv.hxx>
 #include <hints.hxx>
 #include <dpobject.hxx>
@@ -2659,7 +2660,7 @@ void ScInterpreter::ScStyle()
     // Execute request to apply style
     if ( !mrDoc.IsClipOrUndo() )
     {
-        SfxObjectShell* pShell = mrDoc.GetDocumentShell();
+        ScDocShell* pShell = mrDoc.GetDocumentShell();
         if (pShell)
         {
             // Normalize style names right here, making sure that character 
case is correct,
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index 95596b0ed14d..c40c111f226e 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -51,6 +51,7 @@
 #include <addincol.hxx>
 #include <document.hxx>
 #include <dociter.hxx>
+#include <docsh.hxx>
 #include <docoptio.hxx>
 #include <scmatrix.hxx>
 #include <adiasync.hxx>
@@ -2753,7 +2754,7 @@ void ScInterpreter::ScExternal()
 
         if ( aCall.NeedsCaller() && GetError() == FormulaError::NONE )
         {
-            SfxObjectShell* pShell = mrDoc.GetDocumentShell();
+            ScDocShell* pShell = mrDoc.GetDocumentShell();
             if (pShell)
                 aCall.SetCallerFromObjectShell( pShell );
             else
@@ -3228,7 +3229,7 @@ void ScInterpreter::ScMacro()
     sal_uInt8 nParamCount = GetByte();
     OUString aMacro( pCur->GetExternal() );
 
-    SfxObjectShell* pDocSh = mrDoc.GetDocumentShell();
+    ScDocShell* pDocSh = mrDoc.GetDocumentShell();
     if ( !pDocSh )
     {
         PushNoValue();      // without DocShell no CallBasic
diff --git a/sc/source/core/tool/progress.cxx b/sc/source/core/tool/progress.cxx
index 892f1821dce2..ae0b99b32f48 100644
--- a/sc/source/core/tool/progress.cxx
+++ b/sc/source/core/tool/progress.cxx
@@ -31,6 +31,7 @@
 #define SC_PROGRESS_CXX
 #include <progress.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 #include <globstr.hrc>
 #include <scresid.hxx>
 
diff --git a/sc/source/filter/dif/difexp.cxx b/sc/source/filter/dif/difexp.cxx
index 40a9941a70ab..ca2821fac9db 100644
--- a/sc/source/filter/dif/difexp.cxx
+++ b/sc/source/filter/dif/difexp.cxx
@@ -19,6 +19,7 @@
 
 #include <dif.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 #include <formulacell.hxx>
 #include <globstr.hrc>
 #include <scresid.hxx>
diff --git a/sc/source/filter/dif/difimp.cxx b/sc/source/filter/dif/difimp.cxx
index fd88cdf4cfd4..224cb998fb1a 100644
--- a/sc/source/filter/dif/difimp.cxx
+++ b/sc/source/filter/dif/difimp.cxx
@@ -23,6 +23,7 @@
 #include <dif.hxx>
 #include <docpool.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 #include <fprogressbar.hxx>
 #include <ftools.hxx>
 #include <patattr.hxx>
diff --git a/sc/source/filter/excel/excdoc.cxx 
b/sc/source/filter/excel/excdoc.cxx
index 6c97b8686edf..00b1ab0a3d72 100644
--- a/sc/source/filter/excel/excdoc.cxx
+++ b/sc/source/filter/excel/excdoc.cxx
@@ -21,6 +21,7 @@
 #include <rtl/ustring.hxx>
 
 #include <document.hxx>
+#include <docsh.hxx>
 #include <scextopt.hxx>
 #include <docoptio.hxx>
 #include <tabprotection.hxx>
@@ -155,7 +156,7 @@ void ExcTable::FillAsHeaderBinary( ExcBoundsheetList& 
rBoundsheetList )
     sal_uInt16  nExcTabCount    = rTabInfo.GetXclTabCount();
     sal_uInt16  nCodenames      = static_cast< sal_uInt16 >( 
GetExtDocOptions().GetCodeNameCount() );
 
-    SfxObjectShell* pShell = GetDocShell();
+    ScDocShell* pShell = GetDocShell();
     sal_uInt16 nWriteProtHash = pShell ? pShell->GetModifyPasswordHash() : 0;
     bool bRecommendReadOnly = pShell && pShell->IsLoadReadonly();
 
@@ -808,10 +809,10 @@ void ExcDocument::Write( SvStream& rSvStrm )
 
 void ExcDocument::WriteXml( XclExpXmlStream& rStrm )
 {
-    SfxObjectShell* pDocShell = GetDocShell();
+    ScDocShell* pDocShell = GetDocShell();
 
     using namespace ::com::sun::star;
-    uno::Reference<document::XDocumentPropertiesSupplier> xDPS( 
pDocShell->GetModel(), uno::UNO_QUERY_THROW );
+    uno::Reference<document::XDocumentPropertiesSupplier> xDPS( 
static_cast<cppu::OWeakObject*>(pDocShell->GetModel()), uno::UNO_QUERY_THROW );
     uno::Reference<document::XDocumentProperties> xDocProps = 
xDPS->getDocumentProperties();
 
     OUString sUserName = GetUserName();
diff --git a/sc/source/filter/excel/excform8.cxx 
b/sc/source/filter/excel/excform8.cxx
index 62e184204a1c..00c01923e201 100644
--- a/sc/source/filter/excel/excform8.cxx
+++ b/sc/source/filter/excel/excform8.cxx
@@ -21,6 +21,7 @@
 
 #include <document.hxx>
 #include <documentimport.hxx>
+#include <docsh.hxx>
 #include <xltracer.hxx>
 #include <xistream.hxx>
 #include <xihelper.hxx>
diff --git a/sc/source/filter/excel/excimp8.cxx 
b/sc/source/filter/excel/excimp8.cxx
index 3996e18337b1..28a819f9d6fa 100644
--- a/sc/source/filter/excel/excimp8.cxx
+++ b/sc/source/filter/excel/excimp8.cxx
@@ -37,6 +37,7 @@
 #include <unotools/localedatawrapper.hxx>
 
 #include <document.hxx>
+#include <docsh.hxx>
 #include <attrib.hxx>
 #include <dbdata.hxx>
 #include <globalnames.hxx>
@@ -320,7 +321,7 @@ void ImportExcel8::Feat()
 
 void ImportExcel8::ReadBasic()
 {
-    SfxObjectShell* pShell = GetDocShell();
+    ScDocShell* pShell = GetDocShell();
     tools::SvRef<SotStorage> xRootStrg = GetRootStorage();
     const SvtFilterOptions& rFilterOpt = SvtFilterOptions::Get();
     if( !pShell || !xRootStrg.is() )
@@ -407,7 +408,7 @@ void ImportExcel8::PostDocLoad()
     }
 
     // read doc info (no docshell while pasting from clipboard)
-    SfxObjectShell* pShell = GetDocShell();
+    ScDocShell* pShell = GetDocShell();
     if(!pShell)
         return;
 
@@ -415,7 +416,7 @@ void ImportExcel8::PostDocLoad()
     tools::SvRef<SotStorage> xRootStrg = GetRootStorage();
     if( xRootStrg.is() ) try
     {
-        uno::Reference< document::XDocumentPropertiesSupplier > xDPS( 
pShell->GetModel(), uno::UNO_QUERY_THROW );
+        uno::Reference< document::XDocumentPropertiesSupplier > xDPS( 
static_cast<cppu::OWeakObject*>(pShell->GetModel()), uno::UNO_QUERY_THROW );
         uno::Reference< document::XDocumentProperties > xDocProps( 
xDPS->getDocumentProperties(), uno::UNO_SET_THROW );
         sfx2::LoadOlePropertySet( xDocProps, xRootStrg.get() );
     }
diff --git a/sc/source/filter/excel/expop2.cxx 
b/sc/source/filter/excel/expop2.cxx
index ee8ba0fff2b9..3ad57b358faf 100644
--- a/sc/source/filter/excel/expop2.cxx
+++ b/sc/source/filter/excel/expop2.cxx
@@ -23,7 +23,7 @@
 #include <sfx2/objsh.hxx>
 #include <sfx2/docinf.hxx>
 #include <filter/msfilter/svxmsbas.hxx>
-
+#include <docsh.hxx>
 #include <oox/ole/vbaexport.hxx>
 
 #include <scerrors.hxx>
@@ -69,7 +69,7 @@ ExportBiff5::~ExportBiff5()
 
 ErrCode ExportBiff5::Write()
 {
-    SfxObjectShell* pDocShell = GetDocShell();
+    ScDocShell* pDocShell = GetDocShell();
     OSL_ENSURE( pDocShell, "ExportBiff5::Write - no document shell" );
 
     tools::SvRef<SotStorage> xRootStrg = GetRootStorage();
@@ -112,7 +112,7 @@ ErrCode ExportBiff5::Write()
     {
         using namespace ::com::sun::star;
         uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
-                pDocShell->GetModel(), uno::UNO_QUERY_THROW);
+                static_cast<cppu::OWeakObject*>(pDocShell->GetModel()), 
uno::UNO_QUERY_THROW);
         uno::Reference<document::XDocumentProperties> xDocProps
                 = xDPS->getDocumentProperties();
         if ( SvtFilterOptions::Get().IsEnableCalcPreview() )
diff --git a/sc/source/filter/excel/impop.cxx b/sc/source/filter/excel/impop.cxx
index 51f58557e9fe..3262586c14cb 100644
--- a/sc/source/filter/excel/impop.cxx
+++ b/sc/source/filter/excel/impop.cxx
@@ -34,6 +34,7 @@
 #include <sfx2/objsh.hxx>
 #include <tools/urlobj.hxx>
 #include <docuno.hxx>
+#include <docsh.hxx>
 
 #include <formulacell.hxx>
 #include <document.hxx>
@@ -169,7 +170,7 @@ void ImportExcel::ReadFileSharing()
 
     GetMedium().GetItemSet().Put( SfxBoolItem( SID_DOC_READONLY, true ) );
 
-    if( SfxObjectShell* pShell = GetDocShell() )
+    if( ScDocShell* pShell = GetDocShell() )
     {
         if( nRecommendReadOnly != 0 )
             pShell->SetLoadReadonly( true );
@@ -1294,7 +1295,7 @@ void ImportExcel::PostDocLoad()
     GetObjectManager().ConvertObjects();
 
     // visible area (used if this document is an embedded OLE object)
-    if( SfxObjectShell* pDocShell = GetDocShell() )
+    if( ScDocShell* pDocShell = GetDocShell() )
     {
         // visible area if embedded
         const ScExtDocSettings& rDocSett = GetExtDocOptions().GetDocSettings();
diff --git a/sc/source/filter/excel/namebuff.cxx 
b/sc/source/filter/excel/namebuff.cxx
index 52314520976b..d64e77ccd8cf 100644
--- a/sc/source/filter/excel/namebuff.cxx
+++ b/sc/source/filter/excel/namebuff.cxx
@@ -20,6 +20,7 @@
 #include <namebuff.hxx>
 
 #include <document.hxx>
+#include <docsh.hxx>
 #include <scextopt.hxx>
 #include <tokenarray.hxx>
 
diff --git a/sc/source/filter/excel/read.cxx b/sc/source/filter/excel/read.cxx
index e151c7bc75c7..ad580407295e 100644
--- a/sc/source/filter/excel/read.cxx
+++ b/sc/source/filter/excel/read.cxx
@@ -18,6 +18,7 @@
  */
 
 #include <document.hxx>
+#include <docsh.hxx>
 #include <scerrors.hxx>
 #include <fprogressbar.hxx>
 #include <globstr.hrc>
diff --git a/sc/source/filter/excel/xecontent.cxx 
b/sc/source/filter/excel/xecontent.cxx
index b1329e56f535..037e99c408a0 100644
--- a/sc/source/filter/excel/xecontent.cxx
+++ b/sc/source/filter/excel/xecontent.cxx
@@ -36,6 +36,7 @@
 #include <scitems.hxx>
 #include <editeng/flditem.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 #include <validat.hxx>
 #include <unonames.hxx>
 #include <convuno.hxx>
@@ -2142,7 +2143,7 @@ void XclExpWebQuery::Save( XclExpStream& rStrm )
 XclExpWebQueryBuffer::XclExpWebQueryBuffer( const XclExpRoot& rRoot )
 {
     SCTAB nScTab = rRoot.GetCurrScTab();
-    SfxObjectShell* pShell = rRoot.GetDocShell();
+    ScDocShell* pShell = rRoot.GetDocShell();
     if( !pShell ) return;
     ScfPropertySet aModelProp( pShell->GetModel() );
     if( !aModelProp.Is() ) return;
diff --git a/sc/source/filter/excel/xehelper.cxx 
b/sc/source/filter/excel/xehelper.cxx
index 2bae772b0ebd..aa21902dfb73 100644
--- a/sc/source/filter/excel/xehelper.cxx
+++ b/sc/source/filter/excel/xehelper.cxx
@@ -48,6 +48,7 @@
 
 #include <document.hxx>
 #include <docpool.hxx>
+#include <docsh.hxx>
 #include <editutil.hxx>
 #include <patattr.hxx>
 #include <scmatrix.hxx>
diff --git a/sc/source/filter/excel/xeroot.cxx 
b/sc/source/filter/excel/xeroot.cxx
index 3e068284e666..ce281890f837 100644
--- a/sc/source/filter/excel/xeroot.cxx
+++ b/sc/source/filter/excel/xeroot.cxx
@@ -44,6 +44,7 @@
 #include <excrecds.hxx>
 #include <tabprotection.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 
 #include <formulabase.hxx>
 #include <com/sun/star/sheet/FormulaOpCodeMapEntry.hpp>
@@ -229,7 +230,7 @@ void XclExpRoot::InitializeGlobals()
             // instantiated instead of a ScFormulaOpCodeMapperObj and the
             // ScCompiler virtuals not be called! Which would be the case with
             // the current (2013-01-24) rDoc.GetServiceManager()
-            const SfxObjectShell* pShell = rDoc.GetDocumentShell();
+            const ScDocShell* pShell = rDoc.GetDocumentShell();
             if (!pShell)
             {
                 SAL_WARN( "sc", "XclExpRoot::InitializeGlobals - no object 
shell");
diff --git a/sc/source/filter/excel/xichart.cxx 
b/sc/source/filter/excel/xichart.cxx
index a52bb103fbb6..f0e1a5b8f569 100644
--- a/sc/source/filter/excel/xichart.cxx
+++ b/sc/source/filter/excel/xichart.cxx
@@ -85,6 +85,7 @@
 
 #include <document.hxx>
 #include <drwlayer.hxx>
+#include <docsh.hxx>
 #include <tokenarray.hxx>
 #include <compiler.hxx>
 #include <reftokenhelper.hxx>
@@ -270,7 +271,7 @@ void XclImpChRoot::InitConversion( const 
Reference<XChartDocument>& xChartDoc, c
     if( xChartDoc.is() )
         xChartDoc->lockControllers();
 
-    SfxObjectShell* pDocShell = GetDocShell();
+    ScDocShell* pDocShell = GetDocShell();
     Reference< XDataReceiver > xDataRec( xChartDoc, UNO_QUERY );
     if( pDocShell && xDataRec.is() )
     {
@@ -280,7 +281,7 @@ void XclImpChRoot::InitConversion( const 
Reference<XChartDocument>& xChartDoc, c
         if( xDataProv.is() )
             xDataRec->attachDataProvider( xDataProv );
         // attach the number formatter
-        Reference< XNumberFormatsSupplier > xNumFmtSupp( 
pDocShell->GetModel(), UNO_QUERY );
+        Reference< XNumberFormatsSupplier > xNumFmtSupp( 
static_cast<cppu::OWeakObject*>(pDocShell->GetModel()), UNO_QUERY );
         if( xNumFmtSupp.is() )
             xDataRec->attachNumberFormatsSupplier( xNumFmtSupp );
     }
diff --git a/sc/source/filter/excel/xicontent.cxx 
b/sc/source/filter/excel/xicontent.cxx
index 6606390da375..32a6ec04a4d8 100644
--- a/sc/source/filter/excel/xicontent.cxx
+++ b/sc/source/filter/excel/xicontent.cxx
@@ -41,6 +41,7 @@
 #include <validat.hxx>
 #include <patattr.hxx>
 #include <docpool.hxx>
+#include <docsh.hxx>
 #include <rangenam.hxx>
 #include <arealink.hxx>
 #include <stlsheet.hxx>
diff --git a/sc/source/filter/excel/xiescher.cxx 
b/sc/source/filter/excel/xiescher.cxx
index 1805b7a26312..1df74ca56de4 100644
--- a/sc/source/filter/excel/xiescher.cxx
+++ b/sc/source/filter/excel/xiescher.cxx
@@ -102,6 +102,7 @@
 
 #include <document.hxx>
 #include <drwlayer.hxx>
+#include <docsh.hxx>
 #include <userdat.hxx>
 #include <unonames.hxx>
 #include <convuno.hxx>
@@ -523,7 +524,7 @@ void XclImpDrawObjBase::NotifyMacroEventRead()
 {
     if (mbNotifyMacroEventRead)
         return;
-    SfxObjectShell* pDocShell = GetDocShell();
+    ScDocShell* pDocShell = GetDocShell();
     if (!pDocShell)
         return;
     comphelper::DocumentInfo::notifyMacroEventRead(pDocShell->GetModel());
@@ -1760,7 +1761,7 @@ std::size_t XclImpChartObj::DoGetProgressSize() const
 rtl::Reference<SdrObject> XclImpChartObj::DoCreateSdrObj( XclImpDffConverter& 
rDffConv, const tools::Rectangle& rAnchorRect ) const
 {
     rtl::Reference<SdrObject> xSdrObj;
-    SfxObjectShell* pDocShell = GetDocShell();
+    ScDocShell* pDocShell = GetDocShell();
     if( rDffConv.SupportsOleObjects() && SvtModuleOptions().IsChart() && 
pDocShell && mxChart && !mxChart->IsPivotChart() )
     {
         // create embedded chart object
@@ -1914,12 +1915,12 @@ void XclImpControlHelper::ApplySheetLinkProps() const
         return;
 
    // sheet links
-    SfxObjectShell* pDocShell = mrRoot.GetDocShell();
+    ScDocShell* pDocShell = mrRoot.GetDocShell();
     if(!pDocShell)
         return;
 
-    Reference< XMultiServiceFactory > xFactory( pDocShell->GetModel(), 
UNO_QUERY );
-    if( !xFactory.is() )
+    ScModelObj* pModelObj = pDocShell->GetModel();
+    if( !pModelObj )
         return;
 
     // cell link
@@ -1945,7 +1946,7 @@ void XclImpControlHelper::ApplySheetLinkProps() const
             case EXC_CTRL_BINDPOSITION: aServiceName = 
SC_SERVICENAME_LISTCELLBIND;  break;
         }
         Reference< XValueBinding > xBinding(
-            xFactory->createInstanceWithArguments( aServiceName, aArgs ), 
UNO_QUERY_THROW );
+            pModelObj->createInstanceWithArguments( aServiceName, aArgs ), 
UNO_QUERY_THROW );
         xBindable->setValueBinding( xBinding );
     }
     catch( const Exception& )
@@ -1971,7 +1972,7 @@ void XclImpControlHelper::ApplySheetLinkProps() const
         Sequence< Any > aArgs{ Any(aValue) };
 
         // create the EntrySource instance and set at the control model
-        Reference< XListEntrySource > xEntrySource( 
xFactory->createInstanceWithArguments(
+        Reference< XListEntrySource > xEntrySource( 
pModelObj->createInstanceWithArguments(
             SC_SERVICENAME_LISTSOURCE, aArgs ), UNO_QUERY_THROW );
         xEntrySink->setListEntrySource( xEntrySource );
     }
diff --git a/sc/source/filter/excel/xilink.cxx 
b/sc/source/filter/excel/xilink.cxx
index 10933aecf9c5..cfaf9af5680f 100644
--- a/sc/source/filter/excel/xilink.cxx
+++ b/sc/source/filter/excel/xilink.cxx
@@ -20,6 +20,7 @@
 #include <utility>
 #include <xilink.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 #include <scextopt.hxx>
 #include <xistream.hxx>
 #include <xihelper.hxx>
diff --git a/sc/source/filter/excel/xistyle.cxx 
b/sc/source/filter/excel/xistyle.cxx
index 0d417deb4886..e1dc476e1d9e 100644
--- a/sc/source/filter/excel/xistyle.cxx
+++ b/sc/source/filter/excel/xistyle.cxx
@@ -52,6 +52,7 @@
 #include <document.hxx>
 #include <documentimport.hxx>
 #include <docpool.hxx>
+#include <docsh.hxx>
 #include <attrib.hxx>
 #include <patattr.hxx>
 #include <stlpool.hxx>
@@ -123,7 +124,7 @@ private:
 void
 XclImpPalette::ExportPalette()
 {
-    SfxObjectShell* pDocShell = mrRoot.GetDocShell();
+    ScDocShell* pDocShell = mrRoot.GetDocShell();
     if(!pDocShell)
         return;
 
@@ -134,11 +135,11 @@ XclImpPalette::ExportPalette()
     for( sal_uInt16 nIndex = 0; nIndex < nColors; ++nIndex )
         aColors[ nIndex ] = GetColor( nIndex );
 
-    uno::Reference< beans::XPropertySet > xProps( pDocShell->GetModel(), 
uno::UNO_QUERY );
-    if ( xProps.is() )
+    ScModelObj* pModel = pDocShell->GetModel();
+    if ( pModel )
     {
         uno::Reference< container::XIndexAccess > xIndex( new PaletteIndex( 
std::move(aColors) ) );
-        xProps->setPropertyValue( "ColorPalette", uno::Any( xIndex ) );
+        pModel->setPropertyValue( "ColorPalette", uno::Any( xIndex ) );
     }
 
 }
@@ -218,7 +219,7 @@ void XclImpFont::SetFontData( const XclFontData& rFontData, 
bool bHasCharSet )
     mbHasCharSet = bHasCharSet;
     if( !maData.maStyle.isEmpty() )
     {
-        if( SfxObjectShell* pDocShell = GetDocShell() )
+        if( ScDocShell* pDocShell = GetDocShell() )
         {
             if( const SvxFontListItem* pInfoItem = static_cast< const 
SvxFontListItem* >(
                 pDocShell->GetItem( SID_ATTR_CHAR_FONTLIST ) ) )
diff --git a/sc/source/filter/excel/xlroot.cxx 
b/sc/source/filter/excel/xlroot.cxx
index 0b61f9e17e7d..c26529e7fe2d 100644
--- a/sc/source/filter/excel/xlroot.cxx
+++ b/sc/source/filter/excel/xlroot.cxx
@@ -48,6 +48,7 @@
 #include <document.hxx>
 #include <docpool.hxx>
 #include <docuno.hxx>
+#include <docsh.hxx>
 #include <editutil.hxx>
 #include <drwlayer.hxx>
 #include <scextopt.hxx>
@@ -290,15 +291,15 @@ ScDocument& XclRoot::GetDoc() const
     return mrData.mrDoc;
 }
 
-SfxObjectShell* XclRoot::GetDocShell() const
+ScDocShell* XclRoot::GetDocShell() const
 {
     return GetDoc().GetDocumentShell();
 }
 
 ScModelObj* XclRoot::GetDocModelObj() const
 {
-    SfxObjectShell* pDocShell = GetDocShell();
-    return pDocShell ? comphelper::getFromUnoTunnel<ScModelObj>( 
pDocShell->GetModel() ) : nullptr;
+    ScDocShell* pDocShell = GetDocShell();
+    return pDocShell ? pDocShell->GetModel() : nullptr;
 }
 
 OutputDevice* XclRoot::GetPrinter(bool bForceVirtDev) const
diff --git a/sc/source/filter/html/htmlexp.cxx 
b/sc/source/filter/html/htmlexp.cxx
index ba823c5fe83f..150a4ef66dd8 100644
--- a/sc/source/filter/html/htmlexp.cxx
+++ b/sc/source/filter/html/htmlexp.cxx
@@ -55,6 +55,7 @@
 #include <global.hxx>
 #include <postit.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 #include <attrib.hxx>
 #include <patattr.hxx>
 #include <stlpool.hxx>
@@ -321,7 +322,7 @@ void ScHTMLExport::WriteHeader()
     else
     {
         uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
-            pDoc->GetDocumentShell()->GetModel(), uno::UNO_QUERY_THROW);
+            
static_cast<cppu::OWeakObject*>(pDoc->GetDocumentShell()->GetModel()), 
uno::UNO_QUERY_THROW);
         uno::Reference<document::XDocumentProperties> xDocProps
             = xDPS->getDocumentProperties();
         SfxFrameHTMLWriter::Out_DocInfo( rStrm, aBaseURL, xDocProps,
diff --git a/sc/source/filter/html/htmlpars.cxx 
b/sc/source/filter/html/htmlpars.cxx
index db7bfc432a86..f5f890081592 100644
--- a/sc/source/filter/html/htmlpars.cxx
+++ b/sc/source/filter/html/htmlpars.cxx
@@ -57,6 +57,7 @@
 #include <htmlpars.hxx>
 #include <global.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 #include <rangelst.hxx>
 
 #include <orcus/css_parser.hpp>
@@ -252,7 +253,7 @@ ErrCode ScHTMLLayoutParser::Read( SvStream& rStream, const 
OUString& rBaseURL )
     Link<HtmlImportInfo&,void> aOldLink = pEdit->GetHtmlImportHdl();
     pEdit->SetHtmlImportHdl( LINK( this, ScHTMLLayoutParser, HTMLImportHdl ) );
 
-    SfxObjectShell* pObjSh = mpDoc->GetDocumentShell();
+    ScDocShell* pObjSh = mpDoc->GetDocumentShell();
     bool bLoading = pObjSh && pObjSh->IsLoading();
 
     SvKeyValueIteratorRef xValues;
@@ -1470,7 +1471,7 @@ void ScHTMLLayoutParser::ProcToken( HtmlImportInfo* pInfo 
)
         {
             HTMLParser* pParser = static_cast<HTMLParser*>(pInfo->pParser);
             uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
-                mpDoc->GetDocumentShell()->GetModel(), uno::UNO_QUERY_THROW);
+                
static_cast<cppu::OWeakObject*>(mpDoc->GetDocumentShell()->GetModel()), 
uno::UNO_QUERY_THROW);
             pParser->ParseMetaOptions(
                 xDPS->getDocumentProperties(),
                 mpDoc->GetDocumentShell()->GetHeaderAttributes() );
@@ -1489,7 +1490,7 @@ void ScHTMLLayoutParser::ProcToken( HtmlImportInfo* pInfo 
)
                 // Remove blanks from line breaks
                 aString = aString.trim();
                 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
-                    mpDoc->GetDocumentShell()->GetModel(),
+                    
static_cast<cppu::OWeakObject*>(mpDoc->GetDocumentShell()->GetModel()),
                     uno::UNO_QUERY_THROW);
                 xDPS->getDocumentProperties()->setTitle(aString);
             }
@@ -2788,7 +2789,7 @@ ErrCode ScHTMLQueryParser::Read( SvStream& rStrm, const 
OUString& rBaseURL  )
     SvKeyValueIteratorRef xValues;
     SvKeyValueIterator* pAttributes = nullptr;
 
-    SfxObjectShell* pObjSh = mpDoc->GetDocumentShell();
+    ScDocShell* pObjSh = mpDoc->GetDocumentShell();
     if( pObjSh && pObjSh->IsLoading() )
     {
         pAttributes = pObjSh->GetHeaderAttributes();
@@ -2967,7 +2968,7 @@ void ScHTMLQueryParser::MetaOn( const HtmlImportInfo& 
rInfo )
         HTMLParser* pParser = static_cast< HTMLParser* >( rInfo.pParser );
 
         uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
-            mpDoc->GetDocumentShell()->GetModel(), uno::UNO_QUERY_THROW);
+            
static_cast<cppu::OWeakObject*>(mpDoc->GetDocumentShell()->GetModel()), 
uno::UNO_QUERY_THROW);
         pParser->ParseMetaOptions(
             xDPS->getDocumentProperties(),
             mpDoc->GetDocumentShell()->GetHeaderAttributes() );
@@ -2989,7 +2990,7 @@ void ScHTMLQueryParser::TitleOff( const HtmlImportInfo& 
rInfo )
     if (!aTitle.isEmpty() && mpDoc->GetDocumentShell())
     {
         uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
-            mpDoc->GetDocumentShell()->GetModel(), uno::UNO_QUERY_THROW);
+            
static_cast<cppu::OWeakObject*>(mpDoc->GetDocumentShell()->GetModel()), 
uno::UNO_QUERY_THROW);
 
         xDPS->getDocumentProperties()->setTitle(aTitle);
     }
diff --git a/sc/source/filter/inc/xlroot.hxx b/sc/source/filter/inc/xlroot.hxx
index 3085ee8c8516..b4621bea5fce 100644
--- a/sc/source/filter/inc/xlroot.hxx
+++ b/sc/source/filter/inc/xlroot.hxx
@@ -33,6 +33,7 @@ namespace comphelper { class IDocPasswordVerifier; }
 class DateTime;
 class SotStorage;
 class SotStorageStream;
+class ScDocShell;
 
 // Global data ================================================================
 
@@ -200,7 +201,7 @@ public:
     ScDocument& GetDoc() const;
 
     /** Returns the object shell of the Calc document. May be 0 (i.e. import 
from clipboard). */
-    SfxObjectShell*     GetDocShell() const;
+    ScDocShell*         GetDocShell() const;
     /** Returns the object model of the Calc document. */
     ScModelObj*         GetDocModelObj() const;
     /** Returns pointer to the printer of the Calc document. */
diff --git a/sc/source/filter/lotus/filter.cxx 
b/sc/source/filter/lotus/filter.cxx
index d61015595a16..3c89cf693128 100644
--- a/sc/source/filter/lotus/filter.cxx
+++ b/sc/source/filter/lotus/filter.cxx
@@ -23,6 +23,7 @@
 
 #include <filter.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 #include <scerrors.hxx>
 
 #include <optab.h>
diff --git a/sc/source/filter/lotus/lotread.cxx 
b/sc/source/filter/lotus/lotread.cxx
index 240ac323cebb..4696156ffa30 100644
--- a/sc/source/filter/lotus/lotread.cxx
+++ b/sc/source/filter/lotus/lotread.cxx
@@ -19,6 +19,7 @@
 
 #include <document.hxx>
 #include <docoptio.hxx>
+#include <docsh.hxx>
 
 #include <scdll.hxx>
 #include <scerrors.hxx>
diff --git a/sc/source/filter/oox/excelfilter.cxx 
b/sc/source/filter/oox/excelfilter.cxx
index b992a43a52fc..3a2d822d1431 100644
--- a/sc/source/filter/oox/excelfilter.cxx
+++ b/sc/source/filter/oox/excelfilter.cxx
@@ -106,7 +106,7 @@ bool ExcelFilter::importDocument()
             rtl::Reference<WorkbookFragment> xWorkbookFragment( new 
WorkbookFragment(*xBookGlob, aWorkbookPath));
 
             ScDocument& rDoc = xWorkbookFragment->getScDocument();
-            ScDocShell* pDocSh = 
static_cast<ScDocShell*>(rDoc.GetDocumentShell());
+            ScDocShell* pDocSh = rDoc.GetDocumentShell();
             assert( pDocSh );
             pDocSh->SetInitialLinkUpdate( pDocSh->GetMedium());
 
diff --git a/sc/source/filter/oox/workbookhelper.cxx 
b/sc/source/filter/oox/workbookhelper.cxx
index b8a52b09db2c..eaeca2d09912 100644
--- a/sc/source/filter/oox/workbookhelper.cxx
+++ b/sc/source/filter/oox/workbookhelper.cxx
@@ -487,7 +487,7 @@ Reference< XDatabaseRange > 
WorkbookGlobals::createUnnamedDatabaseRangeObject( c
                                        aDestRange.aStart.Col(), 
aDestRange.aStart.Row(),
                                        aDestRange.aEnd.Col(), 
aDestRange.aEnd.Row() ));
         rDoc.SetAnonymousDBData( aDestRange.aStart.Tab() , 
std::move(pNewDBData) );
-        ScDocShell* pDocSh = static_cast< ScDocShell* 
>(rDoc.GetDocumentShell());
+        ScDocShell* pDocSh = rDoc.GetDocumentShell();
         xDatabaseRange.set(new ScDatabaseRangeObj(pDocSh, 
aDestRange.aStart.Tab()));
     }
     catch( Exception& )
diff --git a/sc/source/filter/rtf/eeimpars.cxx 
b/sc/source/filter/rtf/eeimpars.cxx
index c8e81992c28f..70562308120f 100644
--- a/sc/source/filter/rtf/eeimpars.cxx
+++ b/sc/source/filter/rtf/eeimpars.cxx
@@ -41,6 +41,7 @@
 #include <eeimport.hxx>
 #include <global.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 #include <editutil.hxx>
 #include <docpool.hxx>
 #include <attrib.hxx>
diff --git a/sc/source/filter/xcl97/xcl97esc.cxx 
b/sc/source/filter/xcl97/xcl97esc.cxx
index 5120dea3973a..b7db3ba669dd 100644
--- a/sc/source/filter/xcl97/xcl97esc.cxx
+++ b/sc/source/filter/xcl97/xcl97esc.cxx
@@ -48,6 +48,7 @@
 #include <unotools/streamwrap.hxx>
 #include <oox/ole/olehelper.hxx>
 #include <sfx2/objsh.hxx>
+#include <docsh.hxx>
 
 using ::com::sun::star::uno::Any;
 using ::com::sun::star::uno::Exception;
diff --git a/sc/source/filter/xml/XMLTableSourceContext.cxx 
b/sc/source/filter/xml/XMLTableSourceContext.cxx
index 535f532dcaa3..9f66f6f4a089 100644
--- a/sc/source/filter/xml/XMLTableSourceContext.cxx
+++ b/sc/source/filter/xml/XMLTableSourceContext.cxx
@@ -20,6 +20,7 @@
 #include "XMLTableSourceContext.hxx"
 #include "xmlimprt.hxx"
 #include <document.hxx>
+#include <docsh.hxx>
 #include "xmlsubti.hxx"
 #include <tablink.hxx>
 #include <xmloff/xmltoken.hxx>
diff --git a/sc/source/filter/xml/xmlcelli.cxx 
b/sc/source/filter/xml/xmlcelli.cxx
index 3e94b576c679..e0968d3ad3dc 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -26,6 +26,7 @@
 #include <cellvalue.hxx>
 #include <document.hxx>
 #include <docuno.hxx>
+#include <docsh.hxx>
 #include <postit.hxx>
 #include <sheetdata.hxx>
 #include <cellform.hxx>
diff --git a/sc/source/filter/xml/xmlimprt.cxx 
b/sc/source/filter/xml/xmlimprt.cxx
index 46bc0b957b67..3aa681b10bdc 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -1126,7 +1126,7 @@ void SAL_CALL ScXMLImport::setTargetDocument( const 
css::uno::Reference< css::la
     if (!pDoc)
         throw lang::IllegalArgumentException();
 
-    if (ScDocShell* pDocSh = 
static_cast<ScDocShell*>(pDoc->GetDocumentShell()))
+    if (ScDocShell* pDocSh = pDoc->GetDocumentShell())
         pDocSh->SetInitialLinkUpdate( pDocSh->GetMedium());
 
     mpDocImport.reset(new ScDocumentImport(*pDoc));
@@ -1439,7 +1439,7 @@ void SAL_CALL ScXMLImport::endDocument()
                 pDoc->UnlockAdjustHeight();
             }
 
-            ScSizeDeviceProvider 
aProv(static_cast<ScDocShell*>(pDoc->GetDocumentShell()));
+            ScSizeDeviceProvider aProv(pDoc->GetDocumentShell());
             ScDocRowHeightUpdater aUpdater(*pDoc, aProv.GetDevice(), 
aProv.GetPPTX(), aProv.GetPPTY(), &maRecalcRowRanges);
             aUpdater.update();
 
diff --git a/sc/source/filter/xml/xmlwrap.cxx b/sc/source/filter/xml/xmlwrap.cxx
index f1eadd91c4b6..f7bbaa2a5301 100644
--- a/sc/source/filter/xml/xmlwrap.cxx
+++ b/sc/source/filter/xml/xmlwrap.cxx
@@ -584,7 +584,7 @@ bool ScXMLImportWrapper::Import( ImportFlags nMode, 
ErrCode& rError )
 
 static bool lcl_HasValidStream(const ScDocument& rDoc)
 {
-    SfxObjectShell* pObjSh = rDoc.GetDocumentShell();
+    ScDocShell* pObjSh = rDoc.GetDocumentShell();
     if ( pObjSh->IsDocShared() )
         return false;                       // never copy stream from shared 
file
 
@@ -740,7 +740,7 @@ bool ScXMLImportWrapper::Export(bool bStylesOnly)
     OUString sFileName;
     if (pMedium)
         sFileName = pMedium->GetName();
-    SfxObjectShell* pObjSh = rDoc.GetDocumentShell();
+    ScDocShell* pObjSh = rDoc.GetDocumentShell();
     uno::Sequence<beans::PropertyValue> aDescriptor( 
comphelper::InitPropertySequence({
             { "FileName", uno::Any(sFileName) }
         }));
diff --git a/sc/source/ui/Accessibility/AccessibleCellBase.cxx 
b/sc/source/ui/Accessibility/AccessibleCellBase.cxx
index 033c79566cd5..d8b84fabafc1 100644
--- a/sc/source/ui/Accessibility/AccessibleCellBase.cxx
+++ b/sc/source/ui/Accessibility/AccessibleCellBase.cxx
@@ -91,13 +91,13 @@ sal_Int32 SAL_CALL ScAccessibleCellBase::getForeground()
     sal_Int32 nColor(0);
     if (mpDoc)
     {
-        SfxObjectShell* pObjSh = mpDoc->GetDocumentShell();
+        ScDocShell* pObjSh = mpDoc->GetDocumentShell();
         if ( pObjSh )
         {
-            uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( 
pObjSh->GetModel(), uno::UNO_QUERY );
-            if ( xSpreadDoc.is() )
+            ScModelObj* pSpreadDoc = pObjSh->GetModel();
+            if ( pSpreadDoc )
             {
-                uno::Reference<sheet::XSpreadsheets> xSheets = 
xSpreadDoc->getSheets();
+                uno::Reference<sheet::XSpreadsheets> xSheets = 
pSpreadDoc->getSheets();
                 uno::Reference<container::XIndexAccess> xIndex( xSheets, 
uno::UNO_QUERY );
                 if ( xIndex.is() )
                 {
@@ -131,13 +131,13 @@ sal_Int32 SAL_CALL ScAccessibleCellBase::getBackground()
 
     if (mpDoc)
     {
-        SfxObjectShell* pObjSh = mpDoc->GetDocumentShell();
+        ScDocShell* pObjSh = mpDoc->GetDocumentShell();
         if ( pObjSh )
         {
-            uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( 
pObjSh->GetModel(), uno::UNO_QUERY );
-            if ( xSpreadDoc.is() )
+            ScModelObj* pSpreadDoc = pObjSh->GetModel();
+            if ( pSpreadDoc )
             {
-                uno::Reference<sheet::XSpreadsheets> xSheets = 
xSpreadDoc->getSheets();
+                uno::Reference<sheet::XSpreadsheets> xSheets = 
pSpreadDoc->getSheets();
                 uno::Reference<container::XIndexAccess> xIndex( xSheets, 
uno::UNO_QUERY );
                 if ( xIndex.is() )
                 {
@@ -240,7 +240,7 @@ sal_Bool SAL_CALL
         }
         if (IsEditable(nParentStates))
         {
-            ScDocShell* pDocShell = 
static_cast<ScDocShell*>(mpDoc->GetDocumentShell());
+            ScDocShell* pDocShell = mpDoc->GetDocumentShell();
             bResult = pDocShell->GetDocFunc().SetValueCell(maCellAddress, 
fValue, false);
         }
     }
@@ -298,13 +298,13 @@ OUString ScAccessibleCellBase::GetNote() const
     OUString sNote;
     if (mpDoc)
     {
-        SfxObjectShell* pObjSh = mpDoc->GetDocumentShell();
+        ScDocShell* pObjSh = mpDoc->GetDocumentShell();
         if ( pObjSh )
         {
-            uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( 
pObjSh->GetModel(), uno::UNO_QUERY );
-            if ( xSpreadDoc.is() )
+            ScModelObj* pSpreadDoc = pObjSh->GetModel();
+            if ( pSpreadDoc )
             {
-                uno::Reference<sheet::XSpreadsheets> xSheets = 
xSpreadDoc->getSheets();
+                uno::Reference<sheet::XSpreadsheets> xSheets = 
pSpreadDoc->getSheets();
                 uno::Reference<container::XIndexAccess> xIndex( xSheets, 
uno::UNO_QUERY );
                 if ( xIndex.is() )
                 {
@@ -344,13 +344,13 @@ OUString ScAccessibleCellBase::getShadowAttrs() const
     table::ShadowFormat aShadowFmt;
     if (mpDoc)
     {
-        SfxObjectShell* pObjSh = mpDoc->GetDocumentShell();
+        ScDocShell* pObjSh = mpDoc->GetDocumentShell();
         if ( pObjSh )
         {
-            uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( 
pObjSh->GetModel(), uno::UNO_QUERY );
-            if ( xSpreadDoc.is() )
+            ScModelObj* pSpreadDoc = pObjSh->GetModel();
+            if ( pSpreadDoc )
             {
-                uno::Reference<sheet::XSpreadsheets> xSheets = 
xSpreadDoc->getSheets();
+                uno::Reference<sheet::XSpreadsheets> xSheets = 
pSpreadDoc->getSheets();
                 uno::Reference<container::XIndexAccess> xIndex( xSheets, 
uno::UNO_QUERY );
                 if ( xIndex.is() )
                 {
@@ -427,13 +427,13 @@ OUString ScAccessibleCellBase::getBorderAttrs()
     table::BorderLine aRightBorder;
     if (mpDoc)
     {
-        SfxObjectShell* pObjSh = mpDoc->GetDocumentShell();
+        ScDocShell* pObjSh = mpDoc->GetDocumentShell();
         if ( pObjSh )
         {
-            uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( 
pObjSh->GetModel(), uno::UNO_QUERY );
-            if ( xSpreadDoc.is() )
+            ScModelObj* pSpreadDoc = pObjSh->GetModel();
+            if ( pSpreadDoc )
             {
-                uno::Reference<sheet::XSpreadsheets> xSheets = 
xSpreadDoc->getSheets();
+                uno::Reference<sheet::XSpreadsheets> xSheets = 
pSpreadDoc->getSheets();
                 uno::Reference<container::XIndexAccess> xIndex( xSheets, 
uno::UNO_QUERY );
                 if ( xIndex.is() )
                 {
diff --git a/sc/source/ui/Accessibility/AccessibleDocument.cxx 
b/sc/source/ui/Accessibility/AccessibleDocument.cxx
index 7fbb6b792941..5095dabd3097 100644
--- a/sc/source/ui/Accessibility/AccessibleDocument.cxx
+++ b/sc/source/ui/Accessibility/AccessibleDocument.cxx
@@ -1760,7 +1760,7 @@ OUString SAL_CALL
     if (!pScDoc)
         return aName;
 
-    SfxObjectShell* pObjSh = pScDoc->GetDocumentShell();
+    ScDocShell* pObjSh = pScDoc->GetDocumentShell();
     if (!pObjSh)
         return aName;
 
diff --git a/sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx 
b/sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx
index 672785f7d35f..46dcdcfec8df 100644
--- a/sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx
+++ b/sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx
@@ -1550,7 +1550,7 @@ OUString 
ScAccessibleDocumentPagePreview::getAccessibleName()
     OUString aName = ScResId(STR_ACC_DOC_SPREADSHEET);
     ScDocument& rScDoc = mpViewShell->GetDocument();
 
-    SfxObjectShell* pObjSh = rScDoc.GetDocumentShell();
+    ScDocShell* pObjSh = rScDoc.GetDocumentShell();
     if (!pObjSh)
         return aName;
 
diff --git a/sc/source/ui/Accessibility/AccessibleEditObject.cxx 
b/sc/source/ui/Accessibility/AccessibleEditObject.cxx
index 8666666e5c79..7e58af04ef66 100644
--- a/sc/source/ui/Accessibility/AccessibleEditObject.cxx
+++ b/sc/source/ui/Accessibility/AccessibleEditObject.cxx
@@ -413,13 +413,13 @@ sal_Int32 ScAccessibleEditObject::GetFgBgColor( const 
OUString &strPropColor)
     sal_Int32 nColor(0);
     if (m_pScDoc)
     {
-        SfxObjectShell* pObjSh = m_pScDoc->GetDocumentShell();
+        ScDocShell* pObjSh = m_pScDoc->GetDocumentShell();
         if ( pObjSh )
         {
-            uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( 
pObjSh->GetModel(), uno::UNO_QUERY );
-            if ( xSpreadDoc.is() )
+            ScModelObj* pSpreadDoc = pObjSh->GetModel();
+            if ( pSpreadDoc )
             {
-                uno::Reference<sheet::XSpreadsheets> xSheets = 
xSpreadDoc->getSheets();
+                uno::Reference<sheet::XSpreadsheets> xSheets = 
pSpreadDoc->getSheets();
                 uno::Reference<container::XIndexAccess> xIndex( xSheets, 
uno::UNO_QUERY );
                 if ( xIndex.is() )
                 {
diff --git a/sc/source/ui/Accessibility/AccessibleText.cxx 
b/sc/source/ui/Accessibility/AccessibleText.cxx
index 9bc283716d41..3f7ff57f8f4a 100644
--- a/sc/source/ui/Accessibility/AccessibleText.cxx
+++ b/sc/source/ui/Accessibility/AccessibleText.cxx
@@ -971,7 +971,7 @@ ScDocShell* 
ScAccessiblePreviewCellTextData::GetDocShell(ScPreviewShell* pViewSh
 {
     ScDocShell* pDocSh = nullptr;
     if (pViewShell)
-        pDocSh = static_cast<ScDocShell*>( 
pViewShell->GetDocument().GetDocumentShell());
+        pDocSh = pViewShell->GetDocument().GetDocumentShell();
     return pDocSh;
 }
 
@@ -1071,7 +1071,7 @@ ScDocShell* 
ScAccessiblePreviewHeaderCellTextData::GetDocShell(ScPreviewShell* p
 {
     ScDocShell* pDocSh = nullptr;
     if (pViewShell)
-        pDocSh = 
static_cast<ScDocShell*>(pViewShell->GetDocument().GetDocumentShell());
+        pDocSh = pViewShell->GetDocument().GetDocumentShell();
     return pDocSh;
 }
 
@@ -1085,7 +1085,7 @@ 
ScAccessibleHeaderTextData::ScAccessibleHeaderTextData(ScPreviewShell* pViewShel
     meAdjust(eAdjust)
 {
     if (pViewShell)
-        mpDocSh = 
static_cast<ScDocShell*>(pViewShell->GetDocument().GetDocumentShell());
+        mpDocSh = pViewShell->GetDocument().GetDocumentShell();
     if (mpDocSh)
         mpDocSh->GetDocument().AddUnoObject(*this);
 }
@@ -1192,7 +1192,7 @@ 
ScAccessibleNoteTextData::ScAccessibleNoteTextData(ScPreviewShell* pViewShell,
     mbDataValid(false)
 {
     if (pViewShell)
-        mpDocSh = 
static_cast<ScDocShell*>(pViewShell->GetDocument().GetDocumentShell());
+        mpDocSh = pViewShell->GetDocument().GetDocumentShell();
     if (mpDocSh)
         mpDocSh->GetDocument().AddUnoObject(*this);
 }
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index 4a728f54874d..b4d56988ca0f 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -3617,7 +3617,7 @@ void ScInputHandler::SetReference( const ScRange& rRef, 
const ScDocument& rDoc )
         // Always 3D and absolute.
         OUString aTmp(rRef.Format(rDoc, ScRefFlags::VALID | 
ScRefFlags::TAB_ABS_3D, aAddrDetails));
 
-        SfxObjectShell* pObjSh = rDoc.GetDocumentShell();
+        ScDocShell* pObjSh = rDoc.GetDocumentShell();
         // #i75893# convert escaped URL of the document to something user 
friendly
         OUString aFileName = pObjSh->GetMedium()->GetURLObject().GetMainURL( 
INetURLObject::DecodeMechanism::Unambiguous );
 
diff --git a/sc/source/ui/dataprovider/csvdataprovider.cxx 
b/sc/source/ui/dataprovider/csvdataprovider.cxx
index fc8d4ccaf888..11051aab3f92 100644
--- a/sc/source/ui/dataprovider/csvdataprovider.cxx
+++ b/sc/source/ui/dataprovider/csvdataprovider.cxx
@@ -158,7 +158,7 @@ void CSVDataProvider::ImportFinished()
 
 void CSVDataProvider::Refresh()
 {
-    ScDocShell* pDocShell = 
static_cast<ScDocShell*>(mpDocument->GetDocumentShell());
+    ScDocShell* pDocShell = mpDocument->GetDocumentShell();
     if (pDocShell)
         pDocShell->SetDocumentModified();
 }
diff --git a/sc/source/ui/dataprovider/dataprovider.cxx 
b/sc/source/ui/dataprovider/dataprovider.cxx
index cc83294366cb..dced70cca0bd 100644
--- a/sc/source/ui/dataprovider/dataprovider.cxx
+++ b/sc/source/ui/dataprovider/dataprovider.cxx
@@ -242,7 +242,7 @@ void ScDBDataManager::WriteToDoc(ScDocument& rDoc)
     ScMarkData aMark(mpDoc->GetSheetLimits());
     aMark.SelectTable(0, true);
     mpDoc->CopyFromClip(aDestRange, aMark, InsertDeleteFlags::CONTENTS, 
nullptr, &rDoc);
-    ScDocShell* pDocShell = 
static_cast<ScDocShell*>(mpDoc->GetDocumentShell());
+    ScDocShell* pDocShell = mpDoc->GetDocumentShell();
     if (pDocShell)
         pDocShell->PostPaint(aDestRange, PaintPartFlags::All);
 }
diff --git a/sc/source/ui/docshell/arealink.cxx 
b/sc/source/ui/docshell/arealink.cxx
index 64fb1e963aaf..26e076bd1cdf 100644
--- a/sc/source/ui/docshell/arealink.cxx
+++ b/sc/source/ui/docshell/arealink.cxx
@@ -47,13 +47,13 @@
 #include <clipparam.hxx>
 
 
-ScAreaLink::ScAreaLink( SfxObjectShell* pShell, OUString aFile,
+ScAreaLink::ScAreaLink( ScDocShell* pShell, OUString aFile,
                         OUString aFilter, OUString aOpt,
                         OUString aArea, const ScRange& rDest,
                         sal_Int32 nRefreshDelaySeconds ) :
     
::sfx2::SvBaseLink(SfxLinkUpdateMode::ONCALL,SotClipboardFormatId::SIMPLE_FILE),
     ScRefreshTimer  ( nRefreshDelaySeconds ),
-    m_pDocSh(static_cast<ScDocShell*>(pShell)),
+    m_pDocSh(pShell),
     aFileName       (std::move(aFile)),
     aFilterName     (std::move(aFilter)),
     aOptions        (std::move(aOpt)),
@@ -63,7 +63,6 @@ ScAreaLink::ScAreaLink( SfxObjectShell* pShell, OUString 
aFile,
     bInCreate       (false),
     bDoInsert       (true)
 {
-    OSL_ENSURE(dynamic_cast< const ScDocShell *>( pShell ) !=  nullptr, 
"ScAreaLink with wrong ObjectShell");
     SetRefreshHandler( LINK( this, ScAreaLink, RefreshHdl ) );
     SetRefreshControl( 
&m_pDocSh->GetDocument().GetRefreshTimerControlAddress() );
 }
diff --git a/sc/source/ui/docshell/docfunc.cxx 
b/sc/source/ui/docshell/docfunc.cxx
index e89e48476e1c..5691a67b9780 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -3197,7 +3197,7 @@ static script::ModuleInfo lcl_InitModuleInfo( const 
SfxObjectShell& rDocSh, cons
 
 void VBA_InsertModule( ScDocument& rDoc, SCTAB nTab, const OUString& sSource )
 {
-    SfxObjectShell& rDocSh = *rDoc.GetDocumentShell();
+    ScDocShell& rDocSh = *rDoc.GetDocumentShell();
     uno::Reference< script::XLibraryContainer > xLibContainer = 
rDocSh.GetBasicContainer();
     OSL_ENSURE( xLibContainer.is(), "No BasicContainer!" );
 
diff --git a/sc/source/ui/docshell/docsh3.cxx b/sc/source/ui/docshell/docsh3.cxx
index 50e99f36f109..788aac9af86e 100644
--- a/sc/source/ui/docshell/docsh3.cxx
+++ b/sc/source/ui/docshell/docsh3.cxx
@@ -684,7 +684,7 @@ void ScDocShell::CompareDocument( ScDocument& rOtherDoc )
         if (pThisMed)
             aThisFile = pThisMed->GetName();
         OUString aOtherFile;
-        SfxObjectShell* pOtherSh = rOtherDoc.GetDocumentShell();
+        ScDocShell* pOtherSh = rOtherDoc.GetDocumentShell();
         if (pOtherSh)
         {
             const SfxMedium* pOtherMed = pOtherSh->GetMedium();
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx 
b/sc/source/ui/docshell/externalrefmgr.cxx
index f99011e5d7fd..8e1f8e40ed55 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -1663,7 +1663,7 @@ static std::unique_ptr<ScTokenArray> 
lcl_fillEmptyMatrix(const ScDocument& rDoc,
 namespace {
 bool isLinkUpdateAllowedInDoc(const ScDocument& rDoc)
 {
-    SfxObjectShell* pDocShell = rDoc.GetDocumentShell();
+    ScDocShell* pDocShell = rDoc.GetDocumentShell();
     if (!pDocShell)
         return rDoc.IsFunctionAccess();
 
@@ -1934,7 +1934,7 @@ void initDocInCache(ScExternalRefCache& rRefCache, const 
ScDocument* pSrcDoc, sa
     OUString aBaseName;
     if (nTabCount == 1)
     {
-        const SfxObjectShell* pShell = pSrcDoc->GetDocumentShell();
+        const ScDocShell* pShell = pSrcDoc->GetDocumentShell();
         if (pShell && pShell->GetMedium())
         {
             OUString aName = pShell->GetMedium()->GetName();
@@ -2575,7 +2575,7 @@ SfxObjectShellRef 
ScExternalRefManager::loadSrcDocument(sal_uInt16 nFileId, OUSt
     // to update as well. When loading the document ScDocShell::Load() will
     // check through ScDocShell::GetLinkUpdateModeState() if its location is
     // trusted.
-    SfxObjectShell* pShell = mrDoc.GetDocumentShell();
+    ScDocShell* pShell = mrDoc.GetDocumentShell();
     if (pShell)
     {
         SfxMedium* pMedium = pShell->GetMedium();
@@ -2758,7 +2758,7 @@ OUString ScExternalRefManager::getOwnDocumentName() const
     if (utl::ConfigManager::IsFuzzing())
         return "file:///tmp/document";
 
-    SfxObjectShell* pShell = mrDoc.GetDocumentShell();
+    ScDocShell* pShell = mrDoc.GetDocumentShell();
     if (!pShell)
         // This should not happen!
         return OUString();
@@ -2787,7 +2787,7 @@ void ScExternalRefManager::convertToAbsName(OUString& 
rFile) const
         pShell = static_cast<ScDocShell*>(SfxObjectShell::GetNext(*pShell, 
checkSfxObjectShell<ScDocShell>, false));
     }
 
-    SfxObjectShell* pDocShell = mrDoc.GetDocumentShell();
+    ScDocShell* pDocShell = mrDoc.GetDocumentShell();
     rFile = ScGlobal::GetAbsDocName(rFile, pDocShell);
 }
 
diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index 1e62c3338e24..17e1db62b6be 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -110,7 +110,7 @@ enum class SylkVersion
 
 // Whole document without Undo
 ScImportExport::ScImportExport( ScDocument& r )
-    : pDocSh( dynamic_cast< ScDocShell* >(r.GetDocumentShell()) ), rDoc( r ),
+    : pDocSh( r.GetDocumentShell() ), rDoc( r ),
       nSizeLimit( 0 ), nMaxImportRow(!utl::ConfigManager::IsFuzzing() ? 
rDoc.MaxRow() : SCROWS32K),
       cSep( '\t' ), cStr( '"' ),
       bFormulas( false ), bIncludeFiltered( true ),
@@ -124,7 +124,7 @@ ScImportExport::ScImportExport( ScDocument& r )
 
 // Insert am current cell without range(es)
 ScImportExport::ScImportExport( ScDocument& r, const ScAddress& rPt )
-    : pDocSh( dynamic_cast< ScDocShell* >(r.GetDocumentShell()) ), rDoc( r ),
+    : pDocSh( r.GetDocumentShell() ), rDoc( r ),
       aRange( rPt ),
       nSizeLimit( 0 ), nMaxImportRow(!utl::ConfigManager::IsFuzzing() ? 
rDoc.MaxRow() : SCROWS32K),
       cSep( '\t' ), cStr( '"' ),
@@ -140,7 +140,7 @@ ScImportExport::ScImportExport( ScDocument& r, const 
ScAddress& rPt )
 //  ctor with a range is only used for export
 //! ctor with a string (and bSingle=true) is also used for DdeSetData
 ScImportExport::ScImportExport( ScDocument& r, const ScRange& rRange )
-    : pDocSh( dynamic_cast<ScDocShell* >(r.GetDocumentShell()) ), rDoc( r ),
+    : pDocSh( r.GetDocumentShell() ), rDoc( r ),
       aRange( rRange ),
       nSizeLimit( 0 ), nMaxImportRow(!utl::ConfigManager::IsFuzzing() ? 
rDoc.MaxRow() : SCROWS32K),
       cSep( '\t' ), cStr( '"' ),
@@ -158,7 +158,7 @@ ScImportExport::ScImportExport( ScDocument& r, const 
ScRange& rRange )
 // Evaluate input string - either range, cell or the whole document (when 
error)
 // If a View exists, the TabNo of the view will be used.
 ScImportExport::ScImportExport( ScDocument& r, const OUString& rPos )
-    : pDocSh( dynamic_cast< ScDocShell* >(r.GetDocumentShell()) ), rDoc( r ),
+    : pDocSh( r.GetDocumentShell() ), rDoc( r ),
       nSizeLimit( 0 ), nMaxImportRow(!utl::ConfigManager::IsFuzzing() ? 
rDoc.MaxRow() : SCROWS32K),
       cSep( '\t' ), cStr( '"' ),
       bFormulas( false ), bIncludeFiltered( true ),
@@ -456,7 +456,7 @@ bool ScImportExport::ExportStream( SvStream& rStrm, const 
OUString& rBaseURL, So
             aDocName = ScGlobal::GetClipDocName();
         else
         {
-            SfxObjectShell* pShell = rDoc.GetDocumentShell();
+            ScDocShell* pShell = rDoc.GetDocumentShell();
             if (pShell)
                 aDocName = pShell->GetTitle( SFX_TITLE_FULLNAME );
         }
diff --git a/sc/source/ui/docshell/macromgr.cxx 
b/sc/source/ui/docshell/macromgr.cxx
index 39080c67811b..9850b4ce90d2 100644
--- a/sc/source/ui/docshell/macromgr.cxx
+++ b/sc/source/ui/docshell/macromgr.cxx
@@ -19,7 +19,7 @@
 
 #include <macromgr.hxx>
 #include <document.hxx>
-
+#include <docsh.hxx>
 #include <basic/basmgr.hxx>
 #include <cppuhelper/implbase.hxx>
 #include <sfx2/objsh.hxx>
@@ -134,7 +134,7 @@ void ScMacroManager::InitUserFuncData()
     OUString sProjectName("Standard");
 
     Reference< container::XContainer > xModuleContainer;
-    SfxObjectShell* pShell = mrDoc.GetDocumentShell();
+    ScDocShell* pShell = mrDoc.GetDocumentShell();
     if (!pShell)
         return;
 #if HAVE_FEATURE_SCRIPTING
diff --git a/sc/source/ui/docshell/tablink.cxx 
b/sc/source/ui/docshell/tablink.cxx
index 1058bd49ef2a..f4841f84b8f0 100644
--- a/sc/source/ui/docshell/tablink.cxx
+++ b/sc/source/ui/docshell/tablink.cxx
@@ -61,24 +61,7 @@ struct TableLink_Impl
     TableLink_Impl() : m_pDocSh( nullptr ) {}
 };
 
-
-ScTableLink::ScTableLink(ScDocShell* pDocSh, OUString aFile,
-                            OUString aFilter, OUString aOpt,
-                            sal_Int32 nRefreshDelaySeconds ):
-    
::sfx2::SvBaseLink(SfxLinkUpdateMode::ONCALL,SotClipboardFormatId::SIMPLE_FILE),
-    ScRefreshTimer( nRefreshDelaySeconds ),
-    pImpl( new TableLink_Impl ),
-    aFileName(std::move(aFile)),
-    aFilterName(std::move(aFilter)),
-    aOptions(std::move(aOpt)),
-    bInCreate( false ),
-    bInEdit( false ),
-    bAddUndo( true )
-{
-    pImpl->m_pDocSh = pDocSh;
-}
-
-ScTableLink::ScTableLink(SfxObjectShell* pShell, OUString aFile,
+ScTableLink::ScTableLink(ScDocShell* pShell, OUString aFile,
                             OUString aFilter, OUString aOpt,
                             sal_Int32 nRefreshDelaySeconds ):
     
::sfx2::SvBaseLink(SfxLinkUpdateMode::ONCALL,SotClipboardFormatId::SIMPLE_FILE),
@@ -91,9 +74,7 @@ ScTableLink::ScTableLink(SfxObjectShell* pShell, OUString 
aFile,
     bInEdit( false ),
     bAddUndo( true )
 {
-    pImpl->m_pDocSh = static_cast< ScDocShell* >( pShell );
-    SetRefreshHandler( LINK( this, ScTableLink, RefreshHdl ) );
-    SetRefreshControl( 
&pImpl->m_pDocSh->GetDocument().GetRefreshTimerControlAddress() );
+    pImpl->m_pDocSh = pShell;
 }
 
 ScTableLink::~ScTableLink()
diff --git a/sc/source/ui/formdlg/formula.cxx b/sc/source/ui/formdlg/formula.cxx
index 6f4dfab2cc7a..c75091bde20c 100644
--- a/sc/source/ui/formdlg/formula.cxx
+++ b/sc/source/ui/formdlg/formula.cxx
@@ -87,12 +87,12 @@ ScFormulaDlg::ScFormulaDlg(SfxBindings* pB, SfxChildWindow* 
pCW,
 
     m_pDoc = &rViewData.GetDocument();
     
m_xParser.set(ScServiceProvider::MakeInstance(ScServiceProvider::Type::FORMULAPARS,
-                                                  
static_cast<ScDocShell*>(m_pDoc->GetDocumentShell())),uno::UNO_QUERY);
+                                                  m_pDoc->GetDocumentShell()), 
uno::UNO_QUERY);
     uno::Reference< beans::XPropertySet> xSet(m_xParser,uno::UNO_QUERY);
     xSet->setPropertyValue(SC_UNO_COMPILEFAP, uno::Any(true));
 
     
m_xOpCodeMapper.set(ScServiceProvider::MakeInstance(ScServiceProvider::Type::OPCODEMAPPER,
-                                                        
static_cast<ScDocShell*>(m_pDoc->GetDocumentShell())),uno::UNO_QUERY);
+                                                        
m_pDoc->GetDocumentShell()), uno::UNO_QUERY);
 
     ScInputHandler* pInputHdl = SC_MOD()->GetInputHdl(m_pViewShell);
 
@@ -425,7 +425,7 @@ void ScFormulaDlg::SetReference( const ScRange& rRef, 
ScDocument& rRefDoc )
         // Sheet always 3D and absolute.
         OUString aTmp( rRef.Format(rRefDoc, ScRefFlags::VALID | 
ScRefFlags::TAB_ABS_3D | eRangeFlags));
 
-        SfxObjectShell* pObjSh = rRefDoc.GetDocumentShell();
+        ScDocShell* pObjSh = rRefDoc.GetDocumentShell();
 
         // #i75893# convert escaped URL of the document to something user 
friendly
 //           OUString aFileName = pObjSh->GetMedium()->GetName();
diff --git a/sc/source/ui/navipi/content.cxx b/sc/source/ui/navipi/content.cxx
index 3b405d9449f6..dfdcc29ffcc1 100644
--- a/sc/source/ui/navipi/content.cxx
+++ b/sc/source/ui/navipi/content.cxx
@@ -831,7 +831,7 @@ void ScContentTree::GetDrawNames( ScContentId nType )
     if (!pDrawLayer)
         return;
 
-    SfxObjectShell* pShell = pDoc->GetDocumentShell();
+    ScDocShell* pShell = pDoc->GetDocumentShell();
     if (!pShell)
         return;
 
@@ -1021,7 +1021,7 @@ bool ScContentTree::DrawNamesChanged( ScContentId nType )
 
     bool bEqual = true;
     ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
-    SfxObjectShell* pShell = pDoc->GetDocumentShell();
+    ScDocShell* pShell = pDoc->GetDocumentShell();
     if (pDrawLayer && pShell)
     {
         SCTAB nTabCount = pDoc->GetTableCount();
diff --git a/sc/source/ui/undo/areasave.cxx b/sc/source/ui/undo/areasave.cxx
index f675c1abc34c..bc224bba651d 100644
--- a/sc/source/ui/undo/areasave.cxx
+++ b/sc/source/ui/undo/areasave.cxx
@@ -23,6 +23,7 @@
 #include <arealink.hxx>
 #include <document.hxx>
 #include <documentlinkmgr.hxx>
+#include <docsh.hxx>
 
 ScAreaLinkSaver::ScAreaLinkSaver( const ScAreaLink& rSource ) :
     aFileName   ( rSource.GetFile() ),
@@ -59,7 +60,7 @@ void ScAreaLinkSaver::InsertNewLink( ScDocument* pDoc )
     // (see ScUndoRemoveAreaLink::Undo)
 
     sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
-    SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
+    ScDocShell* pObjSh = pDoc->GetDocumentShell();
 
     if ( pLinkManager && pObjSh )
     {
diff --git a/sc/source/ui/unoobj/PivotTableDataProvider.cxx 
b/sc/source/ui/unoobj/PivotTableDataProvider.cxx
index b25b1702cfe1..97b9a09d6d36 100644
--- a/sc/source/ui/unoobj/PivotTableDataProvider.cxx
+++ b/sc/source/ui/unoobj/PivotTableDataProvider.cxx
@@ -17,6 +17,7 @@
 
 #include <miscuno.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 #include <unonames.hxx>
 #include <scresid.hxx>
 #include <globstr.hrc>
@@ -73,7 +74,7 @@ o3tl::span<const SfxItemPropertyMapEntry> 
lcl_GetDataProviderPropertyMap()
 uno::Reference<frame::XModel> lcl_GetXModel(const ScDocument * pDoc)
 {
     uno::Reference<frame::XModel> xModel;
-    SfxObjectShell* pObjSh(pDoc ? pDoc->GetDocumentShell() : nullptr);
+    ScDocShell* pObjSh(pDoc ? pDoc->GetDocumentShell() : nullptr);
     if (pObjSh)
         xModel.set(pObjSh->GetModel());
     return xModel;
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 27f1f739c003..9ba02be536dc 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -4473,8 +4473,7 @@ uno::Sequence<OUString> SAL_CALL 
ScCellRangesObj::getSupportedServiceNames()
 
 uno::Reference<table::XCellRange> ScCellRangeObj::CreateRangeFromDoc( const 
ScDocument& rDoc, const ScRange& rR )
 {
-    SfxObjectShell* pObjSh = rDoc.GetDocumentShell();
-    if ( auto pDocShell = dynamic_cast<ScDocShell*>( pObjSh) )
+    if ( ScDocShell* pDocShell = rDoc.GetDocumentShell() )
         return new ScCellRangeObj( pDocShell, rR );
     return nullptr;
 }
diff --git a/sc/source/ui/unoobj/chart2uno.cxx 
b/sc/source/ui/unoobj/chart2uno.cxx
index e8df8eaf97e9..7fb711b53ac6 100644
--- a/sc/source/ui/unoobj/chart2uno.cxx
+++ b/sc/source/ui/unoobj/chart2uno.cxx
@@ -27,6 +27,7 @@
 #include <chart2uno.hxx>
 #include <miscuno.hxx>
 #include <document.hxx>
+#include <docsh.hxx>
 #include <formulacell.hxx>
 #include <unonames.hxx>
 #include <globstr.hrc>
@@ -128,7 +129,7 @@ OUString lcl_createTableNumberList( const ::std::vector< 
SCTAB > & rTableVector
 uno::Reference< frame::XModel > lcl_GetXModel( const ScDocument * pDoc )
 {
     uno::Reference< frame::XModel > xModel;
-    SfxObjectShell * pObjSh( pDoc ? pDoc->GetDocumentShell() : nullptr );
+    ScDocShell * pObjSh( pDoc ? pDoc->GetDocumentShell() : nullptr );
     if( pObjSh )
         xModel.set( pObjSh->GetModel());
     return xModel;
diff --git a/sc/source/ui/unoobj/shapeuno.cxx b/sc/source/ui/unoobj/shapeuno.cxx
index 29f34158bb2a..49eb4220fa6c 100644
--- a/sc/source/ui/unoobj/shapeuno.cxx
+++ b/sc/source/ui/unoobj/shapeuno.cxx
@@ -330,8 +330,7 @@ void SAL_CALL ScShapeObj::setPropertyValue(const OUString& 
aPropertyName, const
 
                 if ( pDoc )
                 {
-                    SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
-                    if ( auto pDocSh = dynamic_cast<ScDocShell*>( pObjSh) )
+                    if ( ScDocShell* pDocSh = pDoc->GetDocumentShell() )
                     {
                         SCTAB nTab = 0;
                         if ( lcl_GetPageNum( pPage, rModel, nTab ) )
@@ -483,8 +482,7 @@ void SAL_CALL ScShapeObj::setPropertyValue(const OUString& 
aPropertyName, const
                         ScDocument* pDoc = rModel.GetDocument();
                         if ( pDoc )
                         {
-                            SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
-                            if ( auto pDocSh = dynamic_cast<ScDocShell*>( 
pObjSh) )
+                            if ( ScDocShell* pDocSh = pDoc->GetDocumentShell() 
)
                             {
                                 uno::Reference<drawing::XShape> xShape( 
mxShapeAgg, uno::UNO_QUERY );
                                 if (xShape.is())
@@ -583,8 +581,7 @@ void SAL_CALL ScShapeObj::setPropertyValue(const OUString& 
aPropertyName, const
                         ScDocument* pDoc = rModel.GetDocument();
                         if ( pDoc )
                         {
-                            SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
-                            if ( auto pDocSh = dynamic_cast<ScDocShell*>( 
pObjSh) )
+                            if ( ScDocShell* pDocSh = pDoc->GetDocumentShell() 
)
                             {
                                 uno::Reference<drawing::XShape> xShape( 
mxShapeAgg, uno::UNO_QUERY );
                                 if (xShape.is())
@@ -697,8 +694,7 @@ uno::Any SAL_CALL ScShapeObj::getPropertyValue( const 
OUString& aPropertyName )
                     SCTAB nTab = 0;
                     if ( lcl_GetPageNum( pPage, rModel, nTab ) )
                     {
-                        SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
-                        if ( auto pDocSh = dynamic_cast<ScDocShell*>( pObjSh) )
+                        if ( ScDocShell* pDocSh = pDoc->GetDocumentShell() )
                         {
                             uno::Reference< uno::XInterface > xAnchor;
                             if (ScDrawObjData *pAnchor = 
ScDrawLayer::GetObjDataTab(pObj, nTab))
@@ -871,7 +867,7 @@ uno::Any SAL_CALL ScShapeObj::getPropertyValue( const 
OUString& aPropertyName )
                 ScDrawLayer& rModel(static_cast< ScDrawLayer& 
>(pObj->getSdrModelFromSdrObject()));
                 ScDocument* pDoc = rModel.GetDocument();
                 aAny <<= uno::Reference<style::XStyle>(new ScStyleObj(
-                    static_cast<ScDocShell*>(pDoc ? pDoc->GetDocumentShell() : 
nullptr),
+                    pDoc ? pDoc->GetDocumentShell() : nullptr,
                     SfxStyleFamily::Frame, pStyleSheet->GetName()));
             }
         }
@@ -1045,8 +1041,7 @@ uno::Reference<text::XTextRange> SAL_CALL 
ScShapeObj::getAnchor()
 
         if ( pPage && pDoc )
         {
-            SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
-            if ( auto pDocSh = dynamic_cast<ScDocShell*>( pObjSh) )
+            if ( ScDocShell* pDocSh = pDoc->GetDocumentShell() )
             {
                 SCTAB nTab = 0;
                 if ( lcl_GetPageNum( pPage, rModel, nTab ) )
@@ -1284,8 +1279,7 @@ uno::Reference< uno::XInterface > SAL_CALL 
ScShapeObj::getParent()
 
         if ( pPage && pDoc )
         {
-            SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
-            if ( auto pDocSh = dynamic_cast<ScDocShell*>( pObjSh) )
+            if ( ScDocShell* pDocSh = pDoc->GetDocumentShell() )
             {
                 SCTAB nTab = 0;
                 if ( lcl_GetPageNum( pPage, rModel, nTab ) )
diff --git a/sc/source/ui/vba/vbainterior.cxx b/sc/source/ui/vba/vbainterior.cxx
index 2de1abb73654..33c5c5547442 100644
--- a/sc/source/ui/vba/vbainterior.cxx
+++ b/sc/source/ui/vba/vbainterior.cxx
@@ -29,6 +29,7 @@
 #include "vbainterior.hxx"
 #include "vbapalette.hxx"
 #include <document.hxx>
+#include <docsh.hxx>
 #include <utility>
 #include <frozen/bits/defines.h>
 #include <frozen/bits/elsa_std.h>
@@ -129,7 +130,7 @@ ScVbaInterior::getPalette() const
 {
     if ( !m_pScDoc )
         throw uno::RuntimeException();
-    SfxObjectShell* pShell = m_pScDoc->GetDocumentShell();
+    ScDocShell* pShell = m_pScDoc->GetDocumentShell();
     ScVbaPalette aPalette( pShell );
     return aPalette.getPalette();
 }
diff --git a/sc/source/ui/view/cliputil.cxx b/sc/source/ui/view/cliputil.cxx
index 770e309dbe97..9c7d25db1055 100644
--- a/sc/source/ui/view/cliputil.cxx
+++ b/sc/source/ui/view/cliputil.cxx
@@ -36,7 +36,7 @@ bool lcl_checkClassification(ScDocument* pSourceDoc, const 
ScDocument& rDestinat
         return true;
 
     ScClipOptions* pSourceOptions = pSourceDoc->GetClipOptions();
-    SfxObjectShell* pDestinationShell = rDestinationDoc.GetDocumentShell();
+    ScDocShell* pDestinationShell = rDestinationDoc.GetDocumentShell();
     if (!pSourceOptions || !pDestinationShell)
         return true;
 
diff --git a/sc/source/ui/view/drawview.cxx b/sc/source/ui/view/drawview.cxx
index c2190c1623e9..24315ce4812e 100644
--- a/sc/source/ui/view/drawview.cxx
+++ b/sc/source/ui/view/drawview.cxx
@@ -642,7 +642,7 @@ void ScDrawView::UpdateUserViewOptions()
 
 SdrObject* ScDrawView::GetObjectByName(std::u16string_view rName)
 {
-    SfxObjectShell* pShell = rDoc.GetDocumentShell();
+    ScDocShell* pShell = rDoc.GetDocumentShell();
     if (pShell)
     {
         SdrModel& rDrawLayer = GetModel();
@@ -675,7 +675,7 @@ void ScDrawView::SelectCurrentViewObject( 
std::u16string_view rName )
 {
     sal_uInt16 nObjectTab = 0;
     SdrObject* pFound = nullptr;
-    SfxObjectShell* pShell = rDoc.GetDocumentShell();
+    ScDocShell* pShell = rDoc.GetDocumentShell();
     if (pShell)
     {
         SdrModel& rDrawLayer = GetModel();
@@ -729,7 +729,7 @@ bool ScDrawView::SelectObject( std::u16string_view rName )
     SCTAB nObjectTab = 0;
     SdrObject* pFound = nullptr;
 
-    SfxObjectShell* pShell = rDoc.GetDocumentShell();
+    ScDocShell* pShell = rDoc.GetDocumentShell();
     if (pShell)
     {
         SdrModel& rDrawLayer = GetModel();
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index d5a6bf9db155..c214f2ec2d1e 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -4701,7 +4701,7 @@ sal_Int8 ScGridWindow::DropTransferObj( ScTransferObj* 
pTransObj, SCCOL nDestPos
             //  as in PasteDDE
             //  (external references might be used instead?)
 
-            SfxObjectShell* pSourceSh = pSourceDoc->GetDocumentShell();
+            ScDocShell* pSourceSh = pSourceDoc->GetDocumentShell();
             OSL_ENSURE(pSourceSh, "drag document has no shell");
             if (pSourceSh)
             {
diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx
index 651724209946..7a6403237b89 100644
--- a/sc/source/ui/view/viewfun3.cxx
+++ b/sc/source/ui/view/viewfun3.cxx
@@ -251,7 +251,7 @@ bool ScViewFunc::CopyToClipSingleRange( ScDocument* 
pClipDoc, const ScRangeList&
     // and lose the 'if' above
     aClipParam.setSourceDocID( rDoc.GetDocumentID() );
 
-    if (SfxObjectShell* pObjectShell = rDoc.GetDocumentShell())
+    if (ScDocShell* pObjectShell = rDoc.GetDocumentShell())
     {
         // Copy document properties from pObjectShell to pClipDoc (to its clip 
options, as it has no object shell).
         uno::Reference<util::XCloneable> 
xCloneable(pObjectShell->getDocProperties(), uno::UNO_QUERY_THROW);
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx 
b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index f82b693e6073..40d52d9a4d78 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -534,7 +534,7 @@ void ScXMLSourceDlg::OkPressed()
     mpXMLContext->importXML(aParam);
 
     // Don't forget to broadcast the change.
-    SfxObjectShell* pShell = mpDoc->GetDocumentShell();
+    ScDocShell* pShell = mpDoc->GetDocumentShell();
     pShell->Broadcast(SfxHint(SfxHintId::ScDataChanged));
 
     // Repaint the grid to force repaint the cell values.

Reply via email to