sw/inc/docsh.hxx                                      |    4 
 sw/inc/rdfhelper.hxx                                  |   21 +--
 sw/qa/extras/mailmerge/mailmerge2.cxx                 |    5 
 sw/qa/extras/uiwriter/uiwriter.cxx                    |    5 
 sw/source/core/access/AccessibilityCheck.cxx          |    9 -
 sw/source/core/doc/docedt.cxx                         |    5 
 sw/source/core/doc/docnew.cxx                         |   12 +-
 sw/source/core/doc/rdfhelper.cxx                      |   49 ++++----
 sw/source/core/doc/textboxhelper.cxx                  |    5 
 sw/source/core/draw/dpage.cxx                         |    6 -
 sw/source/core/edit/edfcol.cxx                        |  105 ++++++++----------
 sw/source/core/edit/edlingu.cxx                       |    5 
 sw/source/core/text/itrform2.cxx                      |    5 
 sw/source/core/text/porlay.cxx                        |    7 -
 sw/source/core/txtnode/thints.cxx                     |    3 
 sw/source/core/unocore/unoframe.cxx                   |    7 -
 sw/source/core/unocore/unoidx.cxx                     |    8 -
 sw/source/core/unocore/unoobj2.cxx                    |    7 -
 sw/source/core/unocore/unostyle.cxx                   |    6 -
 sw/source/filter/html/htmlform.cxx                    |    7 -
 sw/source/filter/html/htmlforw.cxx                    |    4 
 sw/source/filter/html/htmlgrin.cxx                    |    5 
 sw/source/filter/ww8/docxattributeoutput.cxx          |    5 
 sw/source/filter/ww8/docxexport.cxx                   |   13 +-
 sw/source/filter/ww8/docxexportfilter.cxx             |    4 
 sw/source/filter/ww8/docxtablestyleexport.cxx         |    4 
 sw/source/filter/ww8/ww8par.cxx                       |   10 -
 sw/source/ui/dbui/mmresultdialogs.cxx                 |    9 -
 sw/source/ui/frmdlg/cption.cxx                        |   15 +-
 sw/source/ui/misc/bookmark.cxx                        |    6 -
 sw/source/uibase/app/applab.cxx                       |    5 
 sw/source/uibase/app/docsh.cxx                        |    6 +
 sw/source/uibase/app/docsh2.cxx                       |    5 
 sw/source/uibase/app/docshini.cxx                     |   16 +-
 sw/source/uibase/shells/textsh1.cxx                   |    3 
 sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx |   13 --
 sw/source/uibase/uno/unomailmerge.cxx                 |    2 
 sw/source/uibase/utlui/content.cxx                    |   49 +++-----
 38 files changed, 221 insertions(+), 234 deletions(-)

New commits:
commit c69ad797408fd93afec2c5ac47ba94eba5e4c81c
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Sep 17 11:37:15 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Sep 17 18:01:18 2024 +0200

    use more concrete UNO types in sw
    
    Change-Id: I0f84ce7116441abb2359ee756c912ae663baa2fe
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173545
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/docsh.hxx b/sw/inc/docsh.hxx
index 3cbc43c98803..f29c4ed78134 100644
--- a/sw/inc/docsh.hxx
+++ b/sw/inc/docsh.hxx
@@ -53,6 +53,7 @@ class SwDocShell;
 class SwDrawModel;
 class SwViewShell;
 class SwDocStyleSheetPool;
+class SwXTextDocument;
 namespace svt
 {
 class EmbeddedObjectRef;
@@ -185,6 +186,9 @@ public:
     /// OLE 2.0-notification.
     DECL_DLLPRIVATE_LINK( Ole2ModifiedHdl, bool, void );
 
+    /// Override SfxObjectShell::GetBaseModel and return a more accurate type
+    rtl::Reference<SwXTextDocument> GetBaseModel() const;
+
     /// OLE-stuff.
     virtual void      SetVisArea( const tools::Rectangle &rRect ) override;
     virtual tools::Rectangle GetVisArea( sal_uInt16 nAspect ) const override;
diff --git a/sw/inc/rdfhelper.hxx b/sw/inc/rdfhelper.hxx
index ee346c499fe2..164f99683495 100644
--- a/sw/inc/rdfhelper.hxx
+++ b/sw/inc/rdfhelper.hxx
@@ -12,6 +12,7 @@
 
 #include <map>
 
+#include <rtl/ref.hxx>
 #include <rtl/ustring.hxx>
 
 #include "swdllapi.h"
@@ -20,7 +21,7 @@
 #include <com/sun/star/uno/Sequence.h>
 
 class SwTextNode;
-
+class SwXTextDocument;
 namespace com::sun::star {
     namespace frame {
         class XModel;
@@ -43,44 +44,44 @@ public:
 
     /// Gets all graph-names in RDF of a given type.
     static css::uno::Sequence<css::uno::Reference<css::rdf::XURI>>
-    getGraphNames(const css::uno::Reference<css::frame::XModel>& xModel, const 
OUString& rType);
+    getGraphNames(const rtl::Reference<SwXTextDocument>& xModel, const 
OUString& rType);
 
     /// Gets all (XResource, key, value) statements in RDF graphs given the 
graph-names.
     static std::map<OUString, OUString>
-    getStatements(const css::uno::Reference<css::frame::XModel>& xModel,
+    getStatements(const rtl::Reference<SwXTextDocument>& xModel,
                   const 
css::uno::Sequence<css::uno::Reference<css::rdf::XURI>>& rGraphNames,
                   const css::uno::Reference<css::rdf::XResource>& xSubject);
 
     /// Gets all (XResource, key, value) statements in RDF graphs of type 
rType.
     static std::map<OUString, OUString>
-    getStatements(const css::uno::Reference<css::frame::XModel>& xModel, const 
OUString& rType,
+    getStatements(const rtl::Reference<SwXTextDocument>& xModel, const 
OUString& rType,
                   const css::uno::Reference<css::rdf::XResource>& xSubject);
 
     /// Add an (XResource, key, value) statement in the graph of type rType -- 
or if it does not exist, create a graph at rPath first.
-    static void addStatement(const css::uno::Reference<css::frame::XModel>& 
xModel,
+    static void addStatement(const rtl::Reference<SwXTextDocument>& xModel,
                              const OUString& rType, const OUString& rPath,
                              const css::uno::Reference<css::rdf::XResource>& 
xSubject,
                              const OUString& rKey, const OUString& rValue);
 
     /// Check if a graph of type rType exists.
-    static bool hasMetadataGraph(const 
css::uno::Reference<css::frame::XModel>& xModel,
+    static bool hasMetadataGraph(const rtl::Reference<SwXTextDocument>& xModel,
                                  const OUString& rType);
 
     /// Remove an (XResource, key, value) statement in the graph of type 
rType, if it exists.
-    static void removeStatement(const css::uno::Reference<css::frame::XModel>& 
xModel,
+    static void removeStatement(const rtl::Reference<SwXTextDocument>& xModel,
                                 const OUString& rType,
                                 const 
css::uno::Reference<css::rdf::XResource>& xSubject,
                                 const OUString& rKey, const OUString& rValue);
 
     /// Clone all statements in the graph of type rType, if any exists, from 
one subject to another.
-    static void cloneStatements(const css::uno::Reference<css::frame::XModel>& 
xSrcModel,
-                                const css::uno::Reference<css::frame::XModel>& 
xDstModel,
+    static void cloneStatements(const rtl::Reference<SwXTextDocument>& 
xSrcModel,
+                                const rtl::Reference<SwXTextDocument>& 
xDstModel,
                                 const OUString& rType,
                                 const 
css::uno::Reference<css::rdf::XResource>& xSrcSubject,
                                 const 
css::uno::Reference<css::rdf::XResource>& xDstSubject);
 
     /// Remove all statements in the graph of type rType, if any exists.
-    static void clearStatements(const css::uno::Reference<css::frame::XModel>& 
xModel,
+    static void clearStatements(const rtl::Reference<SwXTextDocument>& xModel,
                                 const OUString& rType,
                                 const 
css::uno::Reference<css::rdf::XResource>& xSubject);
 
diff --git a/sw/qa/extras/mailmerge/mailmerge2.cxx 
b/sw/qa/extras/mailmerge/mailmerge2.cxx
index 7f685ca5343f..f86486e92406 100644
--- a/sw/qa/extras/mailmerge/mailmerge2.cxx
+++ b/sw/qa/extras/mailmerge/mailmerge2.cxx
@@ -347,9 +347,8 @@ DECLARE_SHELL_MAILMERGE_TEST(testTdf128148, 
"tdf128148.odt", "4_v01.ods", "Tabel
     CPPUNIT_ASSERT_EQUAL(sal_uInt16(8), 
mxSwTextDocument->GetDocShell()->GetWrtShell()->GetPhyPageNum());
 
     SwDoc* pDocMM = mxSwTextDocument->GetDocShell()->GetDoc();
-    uno::Reference<frame::XModel> xModel = 
mxSwTextDocument->GetDocShell()->GetBaseModel();
-    uno::Reference<style::XStyleFamiliesSupplier> 
xStyleFamiliesSupplier(xModel, uno::UNO_QUERY);
-    uno::Reference<container::XNameAccess> xStyleFamilies = 
xStyleFamiliesSupplier->getStyleFamilies();
+    rtl::Reference<SwXTextDocument> xModel = 
mxSwTextDocument->GetDocShell()->GetBaseModel();
+    uno::Reference<container::XNameAccess> xStyleFamilies = 
xModel->getStyleFamilies();
     uno::Reference<container::XNameAccess> 
xStyleFamily(xStyleFamilies->getByName(u"PageStyles"_ustr), uno::UNO_QUERY);
 
     // All odd pages have no header, all even pages should have header with 
text "Page 2 of 2"
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx 
b/sw/qa/extras/uiwriter/uiwriter.cxx
index 05b6a9965018..5cc99e908bc8 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -1039,9 +1039,8 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest, 
testWatermarkPosition)
         SwEditShell* pEditShell = pDoc->GetEditShell();
         CPPUNIT_ASSERT(pEditShell);
         SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
-        uno::Reference<frame::XModel> xModel = 
pDoc->GetDocShell()->GetBaseModel();
-        uno::Reference<style::XStyleFamiliesSupplier> 
xStyleFamiliesSupplier(xModel, uno::UNO_QUERY);
-        uno::Reference<container::XNameAccess> xStyleFamilies = 
xStyleFamiliesSupplier->getStyleFamilies();
+        rtl::Reference<SwXTextDocument> xModel = 
pDoc->GetDocShell()->GetBaseModel();
+        uno::Reference<container::XNameAccess> xStyleFamilies = 
xModel->getStyleFamilies();
 
         // 1. Add additional page breaks
         for (int j = 0; j < aAdditionalPagesCount[i]; ++j)
diff --git a/sw/source/core/access/AccessibilityCheck.cxx 
b/sw/source/core/access/AccessibilityCheck.cxx
index 0fb2d456bc11..6804c8617b88 100644
--- a/sw/source/core/access/AccessibilityCheck.cxx
+++ b/sw/source/core/access/AccessibilityCheck.cxx
@@ -50,6 +50,7 @@
 #include <ndgrf.hxx>
 #include <svl/fstathelper.hxx>
 #include <osl/file.h>
+#include <unotxdoc.hxx>
 
 namespace sw
 {
@@ -2396,12 +2397,10 @@ public:
     }
     void check(SwDoc* pDoc) override
     {
-        uno::Reference<lang::XComponent> xDoc = 
pDoc->GetDocShell()->GetBaseModel();
-        uno::Reference<style::XStyleFamiliesSupplier> 
xStyleFamiliesSupplier(xDoc, uno::UNO_QUERY);
-        if (!xStyleFamiliesSupplier.is())
+        rtl::Reference<SwXTextDocument> xDoc = 
pDoc->GetDocShell()->GetBaseModel();
+        if (!xDoc)
             return;
-        uno::Reference<container::XNameAccess> xStyleFamilies
-            = xStyleFamiliesSupplier->getStyleFamilies();
+        uno::Reference<container::XNameAccess> xStyleFamilies = 
xDoc->getStyleFamilies();
         uno::Reference<container::XNameAccess> xStyleFamily(
             xStyleFamilies->getByName(u"PageStyles"_ustr), uno::UNO_QUERY);
         if (!xStyleFamily.is())
diff --git a/sw/source/core/doc/docedt.cxx b/sw/source/core/doc/docedt.cxx
index a627e8de57b9..1a0389e14416 100644
--- a/sw/source/core/doc/docedt.cxx
+++ b/sw/source/core/doc/docedt.cxx
@@ -40,6 +40,7 @@
 #include <ndtxt.hxx>
 #include <undobj.hxx>
 #include <frameformats.hxx>
+#include <unotxdoc.hxx>
 
 #include <vector>
 #include <com/sun/star/linguistic2/XProofreadingIterator.hpp>
@@ -620,7 +621,7 @@ uno::Any SwDoc::Spell( SwPaM& rPaM,
                             uno::Reference< linguistic2::XProofreadingIterator 
>  xGCIterator( GetGCIterator() );
                             if (xGCIterator.is())
                             {
-                                uno::Reference< lang::XComponent > xDoc = 
GetDocShell()->GetBaseModel();
+                                rtl::Reference< SwXTextDocument > xDoc = 
GetDocShell()->GetBaseModel();
                                 // Expand the string:
                                 const ModelToViewHelper 
aConversionMap(*pNd->GetTextNode(), pLayout);
                                 const OUString& aExpandText = 
aConversionMap.getViewText();
@@ -635,7 +636,7 @@ uno::Any SwDoc::Spell( SwPaM& rPaM,
                                 {
                                     aConversionMap.ConvertToViewPosition( 
nBeginGrammarCheck );
                                     aResult = 
xGCIterator->checkSentenceAtPosition(
-                                            xDoc, xFlatPara, aExpandText, 
lang::Locale(), nBeginGrammarCheck, -1, -1 );
+                                            cppu::getXWeak(xDoc.get()), 
xFlatPara, aExpandText, lang::Locale(), nBeginGrammarCheck, -1, -1 );
 
                                     lcl_syncGrammarError( *pNd->GetTextNode(), 
aResult, aConversionMap );
 
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index eb3c68a9c148..104fc5bf6221 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -113,6 +113,7 @@
 #include <unotools/configmgr.hxx>
 #include <i18nlangtag/mslangid.hxx>
 #include <svl/setitem.hxx>
+#include <unotxdoc.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::document;
@@ -163,11 +164,11 @@ bool SwDoc::StartGrammarChecking( bool bSkipStart )
         uno::Reference< linguistic2::XProofreadingIterator > xGCIterator( 
GetGCIterator() );
         if ( xGCIterator.is() )
         {
-            uno::Reference< lang::XComponent >  xDoc = 
GetDocShell()->GetBaseModel();
-            uno::Reference< text::XFlatParagraphIteratorProvider >  xFPIP( 
xDoc, uno::UNO_QUERY );
+            rtl::Reference< SwXTextDocument >  xDoc = 
GetDocShell()->GetBaseModel();
+            uno::Reference< text::XFlatParagraphIteratorProvider >  xFPIP( 
xDoc );
 
             // start automatic background checking if not active already
-            if ( xFPIP.is() && !xGCIterator->isProofreading( xDoc ) )
+            if ( xFPIP.is() && !xGCIterator->isProofreading( 
cppu::getXWeak(xDoc.get()) ) )
             {
                 bStarted = true;
                 if ( !bSkipStart )
@@ -177,7 +178,7 @@ bool SwDoc::StartGrammarChecking( bool bSkipStart )
                         // again until the user modifies the document
                         pLayout->SetNeedGrammarCheck(false);
                     }
-                    xGCIterator->startProofreading( xDoc, xFPIP );
+                    xGCIterator->startProofreading( 
cppu::getXWeak(xDoc.get()), xFPIP );
                 }
             }
         }
@@ -933,8 +934,7 @@ rtl::Reference<SfxObjectShell> SwDoc::CreateCopy(bool 
bCallInitNew, bool bEmpty)
 
     xRet->ReplaceStyles(*this);
 
-    uno::Reference<beans::XPropertySet> const xThisSet(
-        GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW);
+    rtl::Reference<SwXTextDocument> const 
xThisSet(GetDocShell()->GetBaseModel());
     uno::Reference<beans::XPropertySet> const xRetSet(
         pRetShell->GetBaseModel(), uno::UNO_QUERY_THROW);
     uno::Sequence<beans::PropertyValue> aInteropGrabBag;
diff --git a/sw/source/core/doc/rdfhelper.cxx b/sw/source/core/doc/rdfhelper.cxx
index d4e5d9da2b52..b3db96f149a1 100644
--- a/sw/source/core/doc/rdfhelper.cxx
+++ b/sw/source/core/doc/rdfhelper.cxx
@@ -22,6 +22,7 @@
 #include <ndtxt.hxx>
 #include <unoparagraph.hxx>
 #include <unotext.hxx>
+#include <unotxdoc.hxx>
 
 using namespace com::sun::star;
 
@@ -40,7 +41,7 @@ css::uno::Sequence<css::uno::Reference<css::rdf::XURI>> 
SwRDFHelper::getGraphNam
 }
 
 css::uno::Sequence<uno::Reference<css::rdf::XURI>>
-SwRDFHelper::getGraphNames(const css::uno::Reference<css::frame::XModel>& 
xModel,
+SwRDFHelper::getGraphNames(const rtl::Reference<SwXTextDocument>& xModel,
                            const OUString& rType)
 {
     try
@@ -51,9 +52,7 @@ SwRDFHelper::getGraphNames(const 
css::uno::Reference<css::frame::XModel>& xModel
         // message: component context fails to supply service 
com.sun.star.rdf.URI of type com.sun.star.rdf.XURI
         // context: cppu::ComponentContext
         uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, 
rType);
-        uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(xModel,
-                                                                             
uno::UNO_QUERY);
-        return getGraphNames(xDocumentMetadataAccess, xType);
+        return getGraphNames(xModel, xType);
     }
     catch (const ::css::uno::Exception&)
     {
@@ -62,7 +61,7 @@ SwRDFHelper::getGraphNames(const 
css::uno::Reference<css::frame::XModel>& xModel
 }
 
 std::map<OUString, OUString>
-SwRDFHelper::getStatements(const css::uno::Reference<css::frame::XModel>& 
xModel,
+SwRDFHelper::getStatements(const rtl::Reference<SwXTextDocument>& xModel,
                            const 
uno::Sequence<uno::Reference<css::rdf::XURI>>& rGraphNames,
                            const css::uno::Reference<css::rdf::XResource>& 
xSubject)
 {
@@ -70,8 +69,7 @@ SwRDFHelper::getStatements(const 
css::uno::Reference<css::frame::XModel>& xModel
     if (!rGraphNames.hasElements())
         return aRet;
 
-    uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(xModel, uno::UNO_QUERY);
-    const uno::Reference<rdf::XRepository>& xRepo = 
xDocumentMetadataAccess->getRDFRepository();
+    const uno::Reference<rdf::XRepository>& xRepo = xModel->getRDFRepository();
     for (const uno::Reference<rdf::XURI>& xGraphName : rGraphNames)
     {
         uno::Reference<rdf::XNamedGraph> xGraph = xRepo->getGraph(xGraphName);
@@ -91,21 +89,21 @@ SwRDFHelper::getStatements(const 
css::uno::Reference<css::frame::XModel>& xModel
 }
 
 std::map<OUString, OUString>
-SwRDFHelper::getStatements(const css::uno::Reference<css::frame::XModel>& 
xModel,
+SwRDFHelper::getStatements(const rtl::Reference<SwXTextDocument>& xModel,
                            const OUString& rType,
                            const css::uno::Reference<css::rdf::XResource>& 
xSubject)
 {
     return getStatements(xModel, getGraphNames(xModel, rType), xSubject);
 }
 
-void SwRDFHelper::addStatement(const css::uno::Reference<css::frame::XModel>& 
xModel,
+void SwRDFHelper::addStatement(const rtl::Reference<SwXTextDocument>& xModel,
                                const OUString& rType, const OUString& rPath,
                                const css::uno::Reference<css::rdf::XResource>& 
xSubject,
                                const OUString& rKey, const OUString& rValue)
 {
     uno::Reference<uno::XComponentContext> 
xComponentContext(comphelper::getProcessComponentContext());
     uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, 
rType);
-    uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(xModel, uno::UNO_QUERY);
+    uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(xModel);
     const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = 
getGraphNames(xDocumentMetadataAccess, xType);
     uno::Reference<rdf::XURI> xGraphName;
     if (aGraphNames.hasElements())
@@ -113,30 +111,30 @@ void SwRDFHelper::addStatement(const 
css::uno::Reference<css::frame::XModel>& xM
     else
     {
         uno::Sequence< uno::Reference<rdf::XURI> > xTypes = { xType };
-        xGraphName = xDocumentMetadataAccess->addMetadataFile(rPath, xTypes);
+        xGraphName = xModel->addMetadataFile(rPath, xTypes);
     }
-    uno::Reference<rdf::XNamedGraph> xGraph = 
xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName);
+    uno::Reference<rdf::XNamedGraph> xGraph = 
xModel->getRDFRepository()->getGraph(xGraphName);
     uno::Reference<rdf::XURI> xKey = rdf::URI::create(xComponentContext, rKey);
     uno::Reference<rdf::XLiteral> xValue = 
rdf::Literal::create(xComponentContext, rValue);
     xGraph->addStatement(xSubject, xKey, xValue);
 }
 
-bool SwRDFHelper::hasMetadataGraph(const 
css::uno::Reference<css::frame::XModel>& xModel, const OUString& rType)
+bool SwRDFHelper::hasMetadataGraph(const rtl::Reference<SwXTextDocument>& 
xModel, const OUString& rType)
 {
     uno::Reference<uno::XComponentContext> 
xComponentContext(comphelper::getProcessComponentContext());
     uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, 
rType);
-    uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(xModel, uno::UNO_QUERY);
+    uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(xModel);
     return getGraphNames(xDocumentMetadataAccess, xType).hasElements();
 }
 
-void SwRDFHelper::removeStatement(const 
css::uno::Reference<css::frame::XModel>& xModel,
+void SwRDFHelper::removeStatement(const rtl::Reference<SwXTextDocument>& 
xModel,
                                   const OUString& rType,
                                   const 
css::uno::Reference<css::rdf::XResource>& xSubject,
                                   const OUString& rKey, const OUString& rValue)
 {
     uno::Reference<uno::XComponentContext> 
xComponentContext(comphelper::getProcessComponentContext());
     uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, 
rType);
-    uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(xModel, uno::UNO_QUERY);
+    uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(xModel);
     const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = 
getGraphNames(xDocumentMetadataAccess, xType);
     if (!aGraphNames.hasElements())
         return;
@@ -147,20 +145,19 @@ void SwRDFHelper::removeStatement(const 
css::uno::Reference<css::frame::XModel>&
     xGraph->removeStatements(xSubject, xKey, xValue);
 }
 
-void SwRDFHelper::clearStatements(const 
css::uno::Reference<css::frame::XModel>& xModel,
+void SwRDFHelper::clearStatements(const rtl::Reference<SwXTextDocument>& 
xModel,
                                   const OUString& rType,
                                   const 
css::uno::Reference<css::rdf::XResource>& xSubject)
 {
     uno::Reference<uno::XComponentContext> 
xComponentContext(comphelper::getProcessComponentContext());
     uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, 
rType);
-    uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(xModel, uno::UNO_QUERY);
-    const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = 
getGraphNames(xDocumentMetadataAccess, xType);
+    const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = 
getGraphNames(xModel, xType);
     if (!aGraphNames.hasElements())
         return;
 
     for (const uno::Reference<rdf::XURI>& xGraphName : aGraphNames)
     {
-        uno::Reference<rdf::XNamedGraph> xGraph = 
xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName);
+        uno::Reference<rdf::XNamedGraph> xGraph = 
xModel->getRDFRepository()->getGraph(xGraphName);
         uno::Reference<container::XEnumeration> xStatements = 
xGraph->getStatements(xSubject, uno::Reference<rdf::XURI>(), 
uno::Reference<rdf::XURI>());
         while (xStatements->hasMoreElements())
         {
@@ -172,15 +169,15 @@ void SwRDFHelper::clearStatements(const 
css::uno::Reference<css::frame::XModel>&
     }
 }
 
-void SwRDFHelper::cloneStatements(const 
css::uno::Reference<css::frame::XModel>& xSrcModel,
-                                  const 
css::uno::Reference<css::frame::XModel>& xDstModel,
+void SwRDFHelper::cloneStatements(const rtl::Reference<SwXTextDocument>& 
xSrcModel,
+                                  const rtl::Reference<SwXTextDocument>& 
xDstModel,
                                   const OUString& rType,
                                   const 
css::uno::Reference<css::rdf::XResource>& xSrcSubject,
                                   const 
css::uno::Reference<css::rdf::XResource>& xDstSubject)
 {
     uno::Reference<uno::XComponentContext> 
xComponentContext(comphelper::getProcessComponentContext());
     uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, 
rType);
-    uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(xSrcModel, uno::UNO_QUERY);
+    uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(xSrcModel);
     const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = 
getGraphNames(xDocumentMetadataAccess, xType);
     if (!aGraphNames.hasElements())
         return;
@@ -216,7 +213,8 @@ void SwRDFHelper::removeTextNodeStatement(const OUString& 
rType, SwTextNode& rTe
 {
     uno::Reference<uno::XComponentContext> 
xComponentContext(comphelper::getProcessComponentContext());
     uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, 
rType);
-    uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(rTextNode.GetDoc().GetDocShell()->GetBaseModel(), 
uno::UNO_QUERY);
+    rtl::Reference<SwXTextDocument> 
xModel(rTextNode.GetDoc().GetDocShell()->GetBaseModel());
+    uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(xModel);
     const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = 
getGraphNames(xDocumentMetadataAccess, xType);
     if (!aGraphNames.hasElements())
         return;
@@ -233,7 +231,8 @@ void SwRDFHelper::updateTextNodeStatement(const OUString& 
rType, const OUString&
 {
     uno::Reference<uno::XComponentContext> 
xComponentContext(comphelper::getProcessComponentContext());
     uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, 
rType);
-    uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(rTextNode.GetDoc().GetDocShell()->GetBaseModel(), 
uno::UNO_QUERY);
+    rtl::Reference<SwXTextDocument> 
xModel(rTextNode.GetDoc().GetDocShell()->GetBaseModel());
+    uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(xModel);
     const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = 
getGraphNames(xDocumentMetadataAccess, xType);
     uno::Reference<rdf::XURI> xGraphName;
     if (aGraphNames.hasElements())
diff --git a/sw/source/core/doc/textboxhelper.cxx 
b/sw/source/core/doc/textboxhelper.cxx
index c242aeda532e..92fc92dc62c5 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -59,6 +59,7 @@
 #include <com/sun/star/text/WritingMode2.hpp>
 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
 #include <com/sun/star/style/ParagraphAdjust.hpp>
+#include <unotxdoc.hxx>
 
 using namespace com::sun::star;
 
@@ -105,8 +106,8 @@ void SwTextBoxHelper::create(SwFrameFormat* pShape, 
SdrObject* pObject, bool bCo
 
     if (!xTextContentAppend)
     {
-        uno::Reference<text::XTextDocument> xTextDocument(
-            pShape->GetDoc()->GetDocShell()->GetBaseModel(), 
uno::UNO_QUERY_THROW);
+        rtl::Reference<SwXTextDocument> xTextDocument(
+            pShape->GetDoc()->GetDocShell()->GetBaseModel());
         xTextContentAppend.set(xTextDocument->getText(), uno::UNO_QUERY_THROW);
     }
 
diff --git a/sw/source/core/draw/dpage.cxx b/sw/source/core/draw/dpage.cxx
index 93b5e42cbce1..699c50604f0f 100644
--- a/sw/source/core/draw/dpage.cxx
+++ b/sw/source/core/draw/dpage.cxx
@@ -38,6 +38,7 @@
 #include <dflyobj.hxx>
 #include <docsh.hxx>
 #include <flyfrm.hxx>
+#include <unotxdoc.hxx>
 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
 #include <com/sun/star/frame/XModel.hpp>
 
@@ -252,9 +253,8 @@ Reference< XInterface > SwDPage::createUnoPage()
     SwDocShell* pDocShell = m_pDoc->GetDocShell();
     if ( pDocShell )
     {
-        Reference<XModel> xModel = pDocShell->GetBaseModel();
-        Reference<XDrawPageSupplier> xPageSupp(xModel, UNO_QUERY);
-        xRet = xPageSupp->getDrawPage();
+        rtl::Reference<SwXTextDocument> xModel = pDocShell->GetBaseModel();
+        xRet = xModel->getDrawPage();
     }
     return xRet;
 }
diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx
index 18fb6455d76b..c0b1d27c3315 100644
--- a/sw/source/core/edit/edfcol.cxx
+++ b/sw/source/core/edit/edfcol.cxx
@@ -266,7 +266,7 @@ OString lcl_getParagraphBodyText(const 
uno::Reference<text::XTextContent>& xText
 }
 
 template <typename T>
-std::map<OUString, OUString> lcl_getRDFStatements(const 
uno::Reference<frame::XModel>& xModel,
+std::map<OUString, OUString> lcl_getRDFStatements(const 
rtl::Reference<SwXTextDocument>& xModel,
                                                   const T& xRef)
 {
     try
@@ -282,7 +282,7 @@ std::map<OUString, OUString> lcl_getRDFStatements(const 
uno::Reference<frame::XM
 }
 
 /// Returns RDF (key, value) pair associated with the field, if any.
-std::pair<OUString, OUString> lcl_getFieldRDFByPrefix(const 
uno::Reference<frame::XModel>& xModel,
+std::pair<OUString, OUString> lcl_getFieldRDFByPrefix(const 
rtl::Reference<SwXTextDocument>& xModel,
                                                       const 
uno::Reference<css::text::XTextField>& xField,
                                                       std::u16string_view 
sPrefix)
 {
@@ -297,7 +297,7 @@ std::pair<OUString, OUString> lcl_getFieldRDFByPrefix(const 
uno::Reference<frame
 
 /// Returns RDF (key, value) pair associated with the field, if any.
 template <typename T>
-std::pair<OUString, OUString> lcl_getRDF(const uno::Reference<frame::XModel>& 
xModel,
+std::pair<OUString, OUString> lcl_getRDF(const 
rtl::Reference<SwXTextDocument>& xModel,
                                          const T& xRef,
                                          const OUString& sRDFName)
 {
@@ -308,13 +308,13 @@ std::pair<OUString, OUString> lcl_getRDF(const 
uno::Reference<frame::XModel>& xM
 
 /// Returns true iff the field in question is paragraph signature.
 /// Note: must have associated RDF, since signatures are otherwise just 
metadata fields.
-bool lcl_IsParagraphSignatureField(const uno::Reference<frame::XModel>& xModel,
+bool lcl_IsParagraphSignatureField(const rtl::Reference<SwXTextDocument>& 
xModel,
                                    const 
uno::Reference<css::text::XTextField>& xField)
 {
     return (lcl_getRDF(xModel, xField, ParagraphSignatureIdRDFName).first == 
ParagraphSignatureIdRDFName);
 }
 
-uno::Reference<text::XTextField> lcl_findFieldByRDF(const 
uno::Reference<frame::XModel>& xModel,
+uno::Reference<text::XTextField> lcl_findFieldByRDF(const 
rtl::Reference<SwXTextDocument>& xModel,
                                                     const 
uno::Reference<text::XTextContent>& xParagraph,
                                                     const OUString& sRDFName,
                                                     std::u16string_view 
sRDFValue)
@@ -358,7 +358,7 @@ struct SignatureDescr
     bool isValid() const { return !msSignature.isEmpty(); }
 };
 
-SignatureDescr lcl_getSignatureDescr(const uno::Reference<frame::XModel>& 
xModel,
+SignatureDescr lcl_getSignatureDescr(const rtl::Reference<SwXTextDocument>& 
xModel,
                                      const 
uno::Reference<css::text::XTextContent>& xParagraph,
                                      std::u16string_view sFieldId)
 {
@@ -379,7 +379,7 @@ SignatureDescr lcl_getSignatureDescr(const 
uno::Reference<frame::XModel>& xModel
     return aDescr;
 }
 
-SignatureDescr lcl_getSignatureDescr(const uno::Reference<frame::XModel>& 
xModel,
+SignatureDescr lcl_getSignatureDescr(const rtl::Reference<SwXTextDocument>& 
xModel,
                                      const 
uno::Reference<css::text::XTextContent>& xParagraph,
                                      const 
uno::Reference<css::text::XTextField>& xField)
 {
@@ -424,7 +424,7 @@ std::pair<bool, OUString> 
lcl_MakeParagraphSignatureFieldText(const SignatureDes
 
 /// Validate and return validation result and signature field display text.
 std::pair<bool, OUString>
-lcl_MakeParagraphSignatureFieldText(const uno::Reference<frame::XModel>& 
xModel,
+lcl_MakeParagraphSignatureFieldText(const rtl::Reference<SwXTextDocument>& 
xModel,
                                     const 
uno::Reference<css::text::XTextContent>& xParagraph,
                                     const 
uno::Reference<css::text::XTextField>& xField,
                                     const OString& utf8Text)
@@ -434,7 +434,7 @@ lcl_MakeParagraphSignatureFieldText(const 
uno::Reference<frame::XModel>& xModel,
 }
 
 /// Generate the next valid ID for the new signature on this paragraph.
-OUString lcl_getNextSignatureId(const uno::Reference<frame::XModel>& xModel,
+OUString lcl_getNextSignatureId(const rtl::Reference<SwXTextDocument>& xModel,
                                 const uno::Reference<text::XTextContent>& 
xParagraph)
 {
     const OUString sFieldId = lcl_getRDF(xModel, xParagraph, 
ParagraphSignatureLastIdRDFName).second;
@@ -442,12 +442,12 @@ OUString lcl_getNextSignatureId(const 
uno::Reference<frame::XModel>& xModel,
 }
 
 /// Creates and inserts Paragraph Signature Metadata field and creates the RDF 
entry
-uno::Reference<text::XTextField> lcl_InsertParagraphSignature(const 
uno::Reference<frame::XModel>& xModel,
+uno::Reference<text::XTextField> lcl_InsertParagraphSignature(const 
rtl::Reference<SwXTextDocument>& xModel,
                                                               const 
uno::Reference<text::XTextContent>& xParagraph,
                                                               const OUString& 
signature,
                                                               const OUString& 
usage)
 {
-    uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, 
uno::UNO_QUERY);
+    uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel);
     auto xField = 
uno::Reference<text::XTextField>(xMultiServiceFactory->createInstance(MetadataFieldServiceName),
 uno::UNO_QUERY);
 
     // Add the signature at the end.
@@ -516,7 +516,7 @@ bool lcl_DoUpdateParagraphSignatureField(SwDoc& rDoc,
 
 /// Updates the signature field text if changed and returns true only iff 
updated.
 bool lcl_UpdateParagraphSignatureField(SwDoc& rDoc,
-                                       const uno::Reference<frame::XModel>& 
xModel,
+                                       const rtl::Reference<SwXTextDocument>& 
xModel,
                                        const 
uno::Reference<css::text::XTextContent>& xParagraph,
                                        const 
uno::Reference<css::text::XTextField>& xField,
                                        const OString& utf8Text)
@@ -534,7 +534,7 @@ void lcl_RemoveParagraphMetadataField(const 
uno::Reference<css::text::XTextField
 
 /// Returns true iff the field in question is paragraph classification.
 /// Note: must have associated RDF, since classifications are otherwise just 
metadata fields.
-bool lcl_IsParagraphClassificationField(const uno::Reference<frame::XModel>& 
xModel,
+bool lcl_IsParagraphClassificationField(const rtl::Reference<SwXTextDocument>& 
xModel,
                                         const 
uno::Reference<css::text::XTextField>& xField,
                                         std::u16string_view sKey)
 {
@@ -542,7 +542,7 @@ bool lcl_IsParagraphClassificationField(const 
uno::Reference<frame::XModel>& xMo
     return rdfPair.first == ParagraphClassificationNameRDFName && 
(sKey.empty() || rdfPair.second == sKey);
 }
 
-uno::Reference<text::XTextField> lcl_FindParagraphClassificationField(const 
uno::Reference<frame::XModel>& xModel,
+uno::Reference<text::XTextField> lcl_FindParagraphClassificationField(const 
rtl::Reference<SwXTextDocument>& xModel,
                                                                       const 
rtl::Reference<SwXParagraph>& xParagraph,
                                                                       
std::u16string_view sKey = u"")
 {
@@ -578,11 +578,10 @@ uno::Reference<text::XTextField> 
lcl_FindParagraphClassificationField(const uno:
 }
 
 /// Creates and inserts Paragraph Classification Metadata field and creates 
the RDF entry
-uno::Reference<text::XTextField> lcl_InsertParagraphClassification(const 
uno::Reference<frame::XModel>& xModel,
+uno::Reference<text::XTextField> lcl_InsertParagraphClassification(const 
rtl::Reference<SwXTextDocument>& xModel,
                                                                    const 
uno::Reference<text::XTextContent>& xParent)
 {
-    uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, 
uno::UNO_QUERY);
-    auto xField = 
uno::Reference<text::XTextField>(xMultiServiceFactory->createInstance(MetadataFieldServiceName),
 uno::UNO_QUERY);
+    auto xField = 
uno::Reference<text::XTextField>(xModel->createInstance(MetadataFieldServiceName),
 uno::UNO_QUERY);
 
     // Add the classification at the start.
     xField->attach(xParent->getAnchor()->getStart());
@@ -591,7 +590,7 @@ uno::Reference<text::XTextField> 
lcl_InsertParagraphClassification(const uno::Re
 
 /// Updates the paragraph classification field text if changed and returns 
true only iff updated.
 bool lcl_UpdateParagraphClassificationField(SwDoc* pDoc,
-                                            const 
uno::Reference<frame::XModel>& xModel,
+                                            const 
rtl::Reference<SwXTextDocument>& xModel,
                                             const 
uno::Reference<css::text::XTextContent>& xTextNode,
                                             const OUString& sKey,
                                             const OUString& sValue,
@@ -623,7 +622,7 @@ void lcl_ValidateParagraphSignatures(SwDoc& rDoc, const 
uno::Reference<text::XTe
     if (!pDocShell)
         return;
 
-    uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
+    rtl::Reference<SwXTextDocument> xModel = pDocShell->GetBaseModel();
 
     // Check if the paragraph is signed.
     try
@@ -786,12 +785,11 @@ void 
SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationRes
     if (!pObjSh)
         return;
 
-    uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
-    uno::Reference<style::XStyleFamiliesSupplier> 
xStyleFamiliesSupplier(xModel, uno::UNO_QUERY);
-    uno::Reference<container::XNameAccess> xStyleFamilies = 
xStyleFamiliesSupplier->getStyleFamilies();
+    rtl::Reference<SwXTextDocument> xModel = pDocShell->GetBaseModel();
+    uno::Reference<container::XNameAccess> xStyleFamilies = 
xModel->getStyleFamilies();
     uno::Reference<container::XNameAccess> 
xStyleFamily(xStyleFamilies->getByName(u"PageStyles"_ustr), uno::UNO_QUERY);
 
-    uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, 
uno::UNO_QUERY);
+    uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel);
 
     uno::Reference<document::XDocumentProperties> xDocumentProperties = 
pObjSh->getDocProperties();
 
@@ -968,9 +966,8 @@ std::vector<svx::ClassificationResult> 
SwEditShell::CollectAdvancedClassificatio
     uno::Reference<beans::XPropertyContainer> xPropertyContainer = 
xDocumentProperties->getUserDefinedProperties();
     sfx::ClassificationKeyCreator 
aCreator(SfxClassificationHelper::getPolicyType());
 
-    uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
-    uno::Reference<style::XStyleFamiliesSupplier> 
xStyleFamiliesSupplier(xModel, uno::UNO_QUERY);
-    uno::Reference<container::XNameAccess> xStyleFamilies = 
xStyleFamiliesSupplier->getStyleFamilies();
+    rtl::Reference<SwXTextDocument> xModel = pDocShell->GetBaseModel();
+    uno::Reference<container::XNameAccess> xStyleFamilies = 
xModel->getStyleFamilies();
     uno::Reference<container::XNameAccess> 
xStyleFamily(xStyleFamilies->getByName(u"PageStyles"_ustr), uno::UNO_QUERY);
 
     std::vector<OUString> aPageStyles = lcl_getUsedPageStyles(this);
@@ -1101,16 +1098,15 @@ void SwEditShell::SetClassification(const OUString& 
rName, SfxClassificationPoli
     if (!bHeaderIsNeeded && !bFooterIsNeeded && !bWatermarkIsNeeded && 
!bHadWatermark)
         return;
 
-    uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
-    uno::Reference<style::XStyleFamiliesSupplier> 
xStyleFamiliesSupplier(xModel, uno::UNO_QUERY);
-    uno::Reference<container::XNameAccess> xStyleFamilies = 
xStyleFamiliesSupplier->getStyleFamilies();
+    rtl::Reference<SwXTextDocument> xModel = pDocShell->GetBaseModel();
+    uno::Reference<container::XNameAccess> xStyleFamilies = 
xModel->getStyleFamilies();
     uno::Reference<container::XNameAccess> 
xStyleFamily(xStyleFamilies->getByName(u"PageStyles"_ustr), uno::UNO_QUERY);
     const uno::Sequence<OUString> aStyles = xStyleFamily->getElementNames();
 
     for (const OUString& rPageStyleName : aStyles)
     {
         uno::Reference<beans::XPropertySet> 
xPageStyle(xStyleFamily->getByName(rPageStyleName), uno::UNO_QUERY);
-        uno::Reference<lang::XMultiServiceFactory> 
xMultiServiceFactory(xModel, uno::UNO_QUERY);
+        uno::Reference<lang::XMultiServiceFactory> 
xMultiServiceFactory(xModel);
 
         if (bHeaderIsNeeded || bWatermarkIsNeeded || bHadWatermark)
         {
@@ -1168,7 +1164,7 @@ void SwEditShell::SetClassification(const OUString& 
rName, SfxClassificationPoli
 // We pass xParent and xNodeSubject even though they point to the same thing 
because the UNO_QUERY is
 // on a performance-sensitive path.
 static void lcl_ApplyParagraphClassification(SwDoc* pDoc,
-                                      const uno::Reference<frame::XModel>& 
xModel,
+                                      const rtl::Reference<SwXTextDocument>& 
xModel,
                                       const rtl::Reference<SwXParagraph>& 
xParent,
                                       const 
css::uno::Reference<css::rdf::XResource>& xNodeSubject,
                                       std::vector<svx::ClassificationResult> 
aResults)
@@ -1285,12 +1281,12 @@ void 
SwEditShell::ApplyParagraphClassification(std::vector<svx::ClassificationRe
         SetParagraphSignatureValidation(bOldValidationFlag);
     });
 
-    uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
+    rtl::Reference<SwXTextDocument> xModel = pDocShell->GetBaseModel();
     rtl::Reference<SwXParagraph> xParent = 
SwXParagraph::CreateXParagraph(pNode->GetDoc(), pNode, nullptr);
     lcl_ApplyParagraphClassification(GetDoc(), xModel, xParent, 
css::uno::Reference<css::rdf::XResource>(xParent), std::move(aResults));
 }
 
-static std::vector<svx::ClassificationResult> 
lcl_CollectParagraphClassification(const uno::Reference<frame::XModel>& xModel, 
const uno::Reference<text::XTextContent>& xParagraph)
+static std::vector<svx::ClassificationResult> 
lcl_CollectParagraphClassification(const rtl::Reference<SwXTextDocument>& 
xModel, const uno::Reference<text::XTextContent>& xParagraph)
 {
     std::vector<svx::ClassificationResult> aResult;
 
@@ -1361,7 +1357,7 @@ std::vector<svx::ClassificationResult> 
SwEditShell::CollectParagraphClassificati
         return aResult;
 
     rtl::Reference<SwXParagraph> xParent = 
SwXParagraph::CreateXParagraph(pNode->GetDoc(), pNode, nullptr);
-    uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
+    rtl::Reference<SwXTextDocument> xModel = pDocShell->GetBaseModel();
     return lcl_CollectParagraphClassification(xModel, xParent);
 }
 
@@ -1395,9 +1391,8 @@ SfxWatermarkItem SwEditShell::GetWatermark() const
     if (!pDocShell)
         return SfxWatermarkItem();
 
-    uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
-    uno::Reference<style::XStyleFamiliesSupplier> 
xStyleFamiliesSupplier(xModel, uno::UNO_QUERY);
-    uno::Reference<container::XNameAccess> xStyleFamilies = 
xStyleFamiliesSupplier->getStyleFamilies();
+    rtl::Reference<SwXTextDocument> xModel = pDocShell->GetBaseModel();
+    uno::Reference<container::XNameAccess> xStyleFamilies = 
xModel->getStyleFamilies();
     uno::Reference<container::XNameAccess> 
xStyleFamily(xStyleFamilies->getByName(u"PageStyles"_ustr), uno::UNO_QUERY);
     std::vector<OUString> aUsedPageStyles = lcl_getUsedPageStyles(this);
     for (const OUString& rPageStyleName : aUsedPageStyles)
@@ -1444,14 +1439,13 @@ SfxWatermarkItem SwEditShell::GetWatermark() const
 }
 
 static void lcl_placeWatermarkInHeader(const SfxWatermarkItem& rWatermark,
-                            const uno::Reference<frame::XModel>& xModel,
+                            const rtl::Reference<SwXTextDocument>& xModel,
                             const uno::Reference<beans::XPropertySet>& 
xPageStyle,
                             const uno::Reference<text::XText>& xHeaderText)
 {
     if (!xHeaderText.is())
         return;
 
-    uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, 
uno::UNO_QUERY);
     OUString aShapeServiceName = u"com.sun.star.drawing.CustomShape"_ustr;
     OUString sWatermark = WATERMARK_NAME;
     bool bSuccess = false;
@@ -1538,7 +1532,7 @@ static void lcl_placeWatermarkInHeader(const 
SfxWatermarkItem& rWatermark,
     sal_Int32 nHeight = fRatio * nWidth;
 
     // Create and insert the shape.
-    uno::Reference<drawing::XShape> 
xShape(xMultiServiceFactory->createInstance(aShapeServiceName), uno::UNO_QUERY);
+    uno::Reference<drawing::XShape> 
xShape(xModel->createInstance(aShapeServiceName), uno::UNO_QUERY);
 
     uno::Reference<container::XNamed> xNamed(xShape, uno::UNO_QUERY);
     xNamed->setName(sWatermark);
@@ -1623,9 +1617,8 @@ void SwEditShell::SetWatermark(const SfxWatermarkItem& 
rWatermark)
         return;
     const bool bNoWatermark = rWatermark.GetText().isEmpty();
 
-    uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
-    uno::Reference<style::XStyleFamiliesSupplier> 
xStyleFamiliesSupplier(xModel, uno::UNO_QUERY);
-    uno::Reference<container::XNameAccess> xStyleFamilies = 
xStyleFamiliesSupplier->getStyleFamilies();
+    rtl::Reference<SwXTextDocument> xModel = pDocShell->GetBaseModel();
+    uno::Reference<container::XNameAccess> xStyleFamilies = 
xModel->getStyleFamilies();
     uno::Reference<container::XNameAccess> 
xStyleFamily(xStyleFamilies->getByName(u"PageStyles"_ustr), uno::UNO_QUERY);
     const uno::Sequence<OUString> aStyles = xStyleFamily->getElementNames();
 
@@ -1688,7 +1681,7 @@ SwUndoParagraphSigning::SwUndoParagraphSigning(SwDoc& 
rDoc,
     m_bRemove(bRemove)
 {
     // Save the metadata and field content to undo/redo.
-    uno::Reference<frame::XModel> xModel = 
m_rDoc.GetDocShell()->GetBaseModel();
+    rtl::Reference<SwXTextDocument> xModel = 
m_rDoc.GetDocShell()->GetBaseModel();
     const std::map<OUString, OUString> aStatements = 
lcl_getRDFStatements(xModel, m_xField);
     const auto it = aStatements.find(ParagraphSignatureIdRDFName);
     if (it != aStatements.end())
@@ -1823,7 +1816,7 @@ void SwEditShell::SignParagraph()
 
     rDoc.GetIDocumentUndoRedo().StartUndo(SwUndoId::PARA_SIGN_ADD, nullptr);
 
-    const uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
+    const rtl::Reference<SwXTextDocument> xModel = pDocShell->GetBaseModel();
     uno::Reference<css::text::XTextField> xField = 
lcl_InsertParagraphSignature(xModel, xParagraph, signature, aUsage);
 
     lcl_UpdateParagraphSignatureField(*GetDoc(), xModel, xParagraph, xField, 
utf8Text);
@@ -1882,9 +1875,8 @@ void SwEditShell::ValidateAllParagraphSignatures(bool 
updateDontRemove)
             SetParagraphSignatureValidation(bOldValidationFlag);
         });
 
-    uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
-    const uno::Reference<text::XTextDocument> xDoc(xModel, uno::UNO_QUERY);
-    uno::Reference<text::XText> xParent = xDoc->getText();
+    rtl::Reference<SwXTextDocument> xModel = pDocShell->GetBaseModel();
+    uno::Reference<text::XText> xParent = xModel->getText();
     uno::Reference<container::XEnumerationAccess> 
xParagraphEnumerationAccess(xParent, uno::UNO_QUERY);
     if (!xParagraphEnumerationAccess.is())
         return;
@@ -1912,7 +1904,7 @@ static uno::Reference<text::XTextField> 
lcl_GetParagraphMetadataFieldAtIndex(con
             if (::sw::Meta* pMeta = rFormatMeta.GetMeta())
             {
                 const css::uno::Reference<css::rdf::XResource> xSubject = 
pMeta->MakeUnoObject();
-                uno::Reference<frame::XModel> xModel = pDocSh->GetBaseModel();
+                rtl::Reference<SwXTextDocument> xModel = 
pDocSh->GetBaseModel();
                 const std::map<OUString, OUString> aStatements = 
lcl_getRDFStatements(xModel, xSubject);
                 if (aStatements.find(ParagraphSignatureIdRDFName) != 
aStatements.end() ||
                     aStatements.find(ParagraphClassificationNameRDFName) != 
aStatements.end())
@@ -1938,9 +1930,8 @@ void 
SwEditShell::RestoreMetadataFieldsAndValidateParagraphSignatures()
             SetParagraphSignatureValidation(bOldValidationFlag);
         });
 
-    uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
-    const rtl::Reference<SwXTextDocument> 
xDoc(dynamic_cast<SwXTextDocument*>(xModel.get()));
-    rtl::Reference<SwXBodyText> xBodyText = xDoc->getBodyText();
+    rtl::Reference<SwXTextDocument> xModel = pDocShell->GetBaseModel();
+    rtl::Reference<SwXBodyText> xBodyText = xModel->getBodyText();
     if (!xBodyText.is())
         return;
     rtl::Reference<SwXParagraphEnumeration> xParagraphs = 
xBodyText->createParagraphEnumeration();
@@ -2040,8 +2031,7 @@ void 
SwEditShell::RestoreMetadataFieldsAndValidateParagraphSignatures()
                 uno::Reference<text::XTextField> xField = 
lcl_findFieldByRDF(xModel, xParagraph, ParagraphSignatureIdRDFName, pair.first);
                 if (!xField.is())
                 {
-                    uno::Reference<lang::XMultiServiceFactory> 
xMultiServiceFactory(xModel, uno::UNO_QUERY);
-                    xField = 
uno::Reference<text::XTextField>(xMultiServiceFactory->createInstance(MetadataFieldServiceName),
 uno::UNO_QUERY);
+                    xField = 
uno::Reference<text::XTextField>(xModel->createInstance(MetadataFieldServiceName),
 uno::UNO_QUERY);
 
                     // Add the signature at the end.
                     xField->attach(xParagraph->getAnchor()->getEnd());
@@ -2102,7 +2092,7 @@ bool SwEditShell::RemoveParagraphMetadataFieldAtCursor()
 }
 
 static OUString lcl_GetParagraphClassification(SfxClassificationHelper & 
rHelper, sfx::ClassificationKeyCreator const & rKeyCreator,
-                                        const uno::Reference<frame::XModel>& 
xModel, const rtl::Reference<SwXParagraph>& xParagraph)
+                                        const rtl::Reference<SwXTextDocument>& 
xModel, const rtl::Reference<SwXParagraph>& xParagraph)
 {
     uno::Reference<text::XTextField> xTextField;
     xTextField = lcl_FindParagraphClassificationField(xModel, xParagraph, 
rKeyCreator.makeCategoryIdentifierKey());
@@ -2136,9 +2126,8 @@ static OUString 
lcl_GetHighestClassificationParagraphClass(SwPaM* pCursor)
     SfxClassificationHelper aHelper(pDocShell->getDocProperties());
     sfx::ClassificationKeyCreator 
aKeyCreator(SfxClassificationHelper::getPolicyType());
 
-    uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
-    const rtl::Reference<SwXTextDocument> 
xDoc(dynamic_cast<SwXTextDocument*>(xModel.get()));
-    rtl::Reference<SwXBodyText> xBodyText = xDoc->getBodyText();
+    rtl::Reference<SwXTextDocument> xModel = pDocShell->GetBaseModel();
+    rtl::Reference<SwXBodyText> xBodyText = xModel->getBodyText();
 
     rtl::Reference<SwXParagraphEnumeration> xParagraphs = 
xBodyText->createParagraphEnumeration();
     while (xParagraphs->hasMoreElements())
diff --git a/sw/source/core/edit/edlingu.cxx b/sw/source/core/edit/edlingu.cxx
index 41123a009e63..d0f16de8d388 100644
--- a/sw/source/core/edit/edlingu.cxx
+++ b/sw/source/core/edit/edlingu.cxx
@@ -55,6 +55,7 @@
 #include <txatbase.hxx>
 #include <txtfrm.hxx>
 #include <comphelper/propertyvalue.hxx>
+#include <unotxdoc.hxx>
 
 using namespace ::svx;
 using namespace ::com::sun::star;
@@ -978,7 +979,7 @@ bool SwEditShell::GetGrammarCorrection(
             uno::Reference< linguistic2::XProofreadingIterator >  xGCIterator( 
mxDoc->GetGCIterator() );
             if (xGCIterator.is())
             {
-                uno::Reference< lang::XComponent > xDoc = 
mxDoc->GetDocShell()->GetBaseModel();
+                rtl::Reference< SwXTextDocument > xDoc = 
mxDoc->GetDocShell()->GetBaseModel();
 
                 // Expand the string:
                 const ModelToViewHelper aConversionMap(*pNode, GetLayout());
@@ -993,7 +994,7 @@ bool SwEditShell::GetGrammarCorrection(
                 const sal_Int32 nEndOfSentence = 
aConversionMap.ConvertToViewPosition( pWrong->getSentenceEnd( nBegin ) );
 
                 rResult = xGCIterator->checkSentenceAtPosition(
-                        xDoc, xFlatPara, aExpandText, lang::Locale(), 
nStartOfSentence,
+                        cppu::getXWeak(xDoc.get()), xFlatPara, aExpandText, 
lang::Locale(), nStartOfSentence,
                         nEndOfSentence == COMPLETE_STRING ? 
aExpandText.getLength() : nEndOfSentence,
                         rErrorPosInText );
                 bRes = true;
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index c6c68f8041fa..3317ca05725e 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -69,6 +69,7 @@
 #include <com/sun/star/rdf/XDocumentMetadataAccess.hpp>
 #include <com/sun/star/rdf/XLiteral.hpp>
 #include <com/sun/star/text/XTextContent.hpp>
+#include <unotxdoc.hxx>
 
 using namespace ::com::sun::star;
 
@@ -1266,8 +1267,8 @@ SwTextPortion *SwTextFormatter::WhichTextPor( 
SwTextFormatInfo &rInf ) const
                 static uno::Reference< rdf::XURI > xODF_SHADING(
                     rdf::URI::createKnown(xContext, 
rdf::URIs::LO_EXT_SHADING), uno::UNO_SET_THROW);
 
-                uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(
-                    rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY);
+                rtl::Reference<SwXTextDocument> xDocumentMetadataAccess(
+                    rDoc.GetDocShell()->GetBaseModel());
 
                 const css::uno::Reference<css::rdf::XResource> xSubject(xRet, 
uno::UNO_QUERY);
                 const uno::Reference<rdf::XRepository>& xRepository =
diff --git a/sw/source/core/text/porlay.cxx b/sw/source/core/text/porlay.cxx
index fbba4cc4cdaf..6837ae58539d 100644
--- a/sw/source/core/text/porlay.cxx
+++ b/sw/source/core/text/porlay.cxx
@@ -79,6 +79,7 @@
 #include <unicode/ubidi.h>
 #include <i18nutil/scripttypedetector.hxx>
 #include <i18nutil/unicode.hxx>
+#include <unotxdoc.hxx>
 
 using namespace ::com::sun::star;
 using namespace i18n::ScriptType;
@@ -973,7 +974,7 @@ static Color getBookmarkColor(const SwTextNode& rNode, 
const sw::mark::Bookmark*
         const rtl::Reference< SwXBookmark > xRef = 
SwXBookmark::CreateXBookmark(rDoc,
                 const_cast<sw::mark::MarkBase*>(static_cast<const 
sw::mark::MarkBase*>(pBookmark)));
         const css::uno::Reference<css::rdf::XResource> xSubject(xRef);
-        uno::Reference<frame::XModel> xModel = 
rDoc.GetDocShell()->GetBaseModel();
+        rtl::Reference<SwXTextDocument> xModel = 
rDoc.GetDocShell()->GetBaseModel();
 
         static uno::Reference< uno::XComponentContext > xContext(
             ::comphelper::getProcessComponentContext());
@@ -981,10 +982,8 @@ static Color getBookmarkColor(const SwTextNode& rNode, 
const sw::mark::Bookmark*
         static uno::Reference< rdf::XURI > xODF_SHADING(
             rdf::URI::createKnown(xContext, rdf::URIs::LO_EXT_SHADING), 
uno::UNO_SET_THROW);
 
-        uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(
-            rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY);
         const uno::Reference<rdf::XRepository>& xRepository =
-            xDocumentMetadataAccess->getRDFRepository();
+            xModel->getRDFRepository();
         const uno::Reference<container::XEnumeration> xEnum(
             xRepository->getStatements(xSubject, xODF_SHADING, nullptr), 
uno::UNO_SET_THROW);
 
diff --git a/sw/source/core/txtnode/thints.cxx 
b/sw/source/core/txtnode/thints.cxx
index a532efb352cc..4239a1b70ded 100644
--- a/sw/source/core/txtnode/thints.cxx
+++ b/sw/source/core/txtnode/thints.cxx
@@ -80,6 +80,7 @@
 
 #include <rdfhelper.hxx>
 #include <hints.hxx>
+#include <unotxdoc.hxx>
 
 #include <officecfg/Office/Common.hxx>
 
@@ -1280,7 +1281,7 @@ void SwTextNode::DestroyAttr( SwTextAttr* pAttr )
             {
                 static constexpr OUStringLiteral metaNS(u"urn:bails");
                 const css::uno::Reference<css::rdf::XResource> xSubject = 
pMeta->MakeUnoObject();
-                uno::Reference<frame::XModel> xModel = pDocSh->GetBaseModel();
+                rtl::Reference<SwXTextDocument> xModel = 
pDocSh->GetBaseModel();
                 SwRDFHelper::clearStatements(xModel, metaNS, xSubject);
             }
         }
diff --git a/sw/source/core/unocore/unoframe.cxx 
b/sw/source/core/unocore/unoframe.cxx
index f1ccffaf0f02..12fa64c38385 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -115,6 +115,7 @@
 #include <cppuhelper/supportsservice.hxx>
 #include <sal/log.hxx>
 #include <vcl/errinf.hxx>
+#include <unotxdoc.hxx>
 
 #include <svx/unobrushitemhelper.hxx>
 #include <svx/xbtmpit.hxx>
@@ -1210,11 +1211,9 @@ SwXFrame::SwXFrame(FlyCntType eSet, const 
::SfxItemPropertySet* pSet, SwDoc *pDo
     
StartListening(pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier());
     // get the property set for the default style data
     // First get the model
-    uno::Reference < XModel > xModel = pDoc->GetDocShell()->GetBaseModel();
-    // Ask the model for its family supplier interface
-    uno::Reference < XStyleFamiliesSupplier > xFamilySupplier ( xModel, 
uno::UNO_QUERY );
+    rtl::Reference < SwXTextDocument > xModel = 
pDoc->GetDocShell()->GetBaseModel();
     // Get the style families
-    uno::Reference < XNameAccess > xFamilies = 
xFamilySupplier->getStyleFamilies();
+    uno::Reference < XNameAccess > xFamilies = xModel->getStyleFamilies();
     // Get the Frame family (and keep it for later)
     const ::uno::Any aAny = xFamilies->getByName (u"FrameStyles"_ustr);
     aAny >>= mxStyleFamily;
diff --git a/sw/source/core/unocore/unoidx.cxx 
b/sw/source/core/unocore/unoidx.cxx
index 3d12a1c12011..1b5b805da1f8 100644
--- a/sw/source/core/unocore/unoidx.cxx
+++ b/sw/source/core/unocore/unoidx.cxx
@@ -61,6 +61,7 @@
 #include <svl/itemprop.hxx>
 #include <svl/listener.hxx>
 #include <mutex>
+#include <unotxdoc.hxx>
 
 using namespace ::com::sun::star;
 
@@ -1973,11 +1974,10 @@ SwXDocumentIndexMark::getAnchor()
     {
         aPam.GetPoint()->AdjustContent(1);
     }
-    const uno::Reference< frame::XModel > xModel =
+    const rtl::Reference< SwXTextDocument > xModel =
         m_pImpl->m_pDoc->GetDocShell()->GetBaseModel();
-    const uno::Reference< text::XTextDocument > xTDoc(xModel, uno::UNO_QUERY);
-    const uno::Reference< text::XTextRange >  xRet =
-        new SwXTextRange(aPam, xTDoc->getText());
+    const uno::Reference< text::XTextRange > xRet =
+        new SwXTextRange(aPam, xModel->getText());
 
     return xRet;
 }
diff --git a/sw/source/core/unocore/unoobj2.cxx 
b/sw/source/core/unocore/unoobj2.cxx
index 534c34a841f3..400659d373e2 100644
--- a/sw/source/core/unocore/unoobj2.cxx
+++ b/sw/source/core/unocore/unoobj2.cxx
@@ -74,6 +74,7 @@
 #include <frameformats.hxx>
 #include <algorithm>
 #include <iterator>
+#include <unotxdoc.hxx>
 
 using namespace ::com::sun::star;
 
@@ -1385,10 +1386,8 @@ CreateParentXText(SwDoc & rDoc, const SwPosition& rPos)
             if (SwDocShell *const pDocSh = rDoc.GetDocShell())
             {
                 // then it is the body text
-                const uno::Reference<frame::XModel> xModel = 
pDocSh->GetBaseModel();
-                const uno::Reference< text::XTextDocument > xDoc(
-                    xModel, uno::UNO_QUERY);
-                xParentText = dynamic_cast<SwXText*>(xDoc->getText().get());
+                const rtl::Reference<SwXTextDocument> xModel = 
pDocSh->GetBaseModel();
+                xParentText = dynamic_cast<SwXText*>(xModel->getText().get());
             }
         }
     }
diff --git a/sw/source/core/unocore/unostyle.cxx 
b/sw/source/core/unocore/unostyle.cxx
index a6dbf2aeffd2..3380f6aa4b7d 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -127,6 +127,7 @@
 #include <set>
 #include <string_view>
 #include <limits>
+#include <unotxdoc.hxx>
 
 using namespace css;
 using namespace css::io;
@@ -1296,9 +1297,8 @@ static uno::Reference<container::XNameAccess> 
lcl_InitStyleFamily(SwDoc* pDoc, c
             && rEntry.family() != SfxStyleFamily::Para
             && rEntry.family() != SfxStyleFamily::Page)
         return {};
-    auto xModel(pDoc->GetDocShell()->GetBaseModel());
-    uno::Reference<style::XStyleFamiliesSupplier> xFamilySupplier(xModel, 
uno::UNO_QUERY);
-    auto xFamilies = xFamilySupplier->getStyleFamilies();
+    rtl::Reference<SwXTextDocument> 
xModel(pDoc->GetDocShell()->GetBaseModel());
+    auto xFamilies = xModel->getStyleFamilies();
     auto aResult(xFamilies->getByName(rEntry.name()));
     if(!aResult.has<return_t>())
         return {};
diff --git a/sw/source/filter/html/htmlform.cxx 
b/sw/source/filter/html/htmlform.cxx
index e9d1707cc015..cc234aabd586 100644
--- a/sw/source/filter/html/htmlform.cxx
+++ b/sw/source/filter/html/htmlform.cxx
@@ -79,6 +79,7 @@
 #include <viewsh.hxx>
 #include <unodraw.hxx>
 #include <unotextrange.hxx>
+#include <unotxdoc.hxx>
 
 #include "swcss1.hxx"
 #include "swhtml.hxx"
@@ -280,8 +281,7 @@ const uno::Reference< XMultiServiceFactory >& 
SwHTMLForm_Impl::GetServiceFactory
     if( !m_xServiceFactory.is() && m_pDocShell )
     {
         m_xServiceFactory =
-            uno::Reference< XMultiServiceFactory >( 
m_pDocShell->GetBaseModel(),
-                                               UNO_QUERY );
+            uno::Reference< XMultiServiceFactory >( 
m_pDocShell->GetBaseModel() );
         OSL_ENSURE( m_xServiceFactory.is(),
                 "XServiceFactory not received from model" );
     }
@@ -292,8 +292,7 @@ void SwHTMLForm_Impl::GetDrawPage()
 {
     if( !m_xDrawPage.is() && m_pDocShell )
     {
-        uno::Reference< drawing::XDrawPageSupplier > xTextDoc( 
m_pDocShell->GetBaseModel(),
-                                                         UNO_QUERY );
+        rtl::Reference< SwXTextDocument > xTextDoc( 
m_pDocShell->GetBaseModel() );
         OSL_ENSURE( xTextDoc.is(),
                 "drawing::XDrawPageSupplier not received from model" );
         m_xDrawPage = xTextDoc->getDrawPage();
diff --git a/sw/source/filter/html/htmlforw.cxx 
b/sw/source/filter/html/htmlforw.cxx
index 2d7aa7200b0f..42db807771f9 100644
--- a/sw/source/filter/html/htmlforw.cxx
+++ b/sw/source/filter/html/htmlforw.cxx
@@ -61,6 +61,7 @@
 #include <frmfmt.hxx>
 #include <frameformats.hxx>
 #include <memory>
+#include <unotxdoc.hxx>
 
 using namespace ::com::sun::star;
 
@@ -346,8 +347,7 @@ void SwHTMLWriter::OutHiddenForms()
     if( !pDocSh )
         return;
 
-    uno::Reference< drawing::XDrawPageSupplier > xDPSupp( 
pDocSh->GetBaseModel(),
-                                                     uno::UNO_QUERY );
+    rtl::Reference< SwXTextDocument > xDPSupp( pDocSh->GetBaseModel() );
     OSL_ENSURE( xDPSupp.is(), "XTextDocument not received from XModel" );
     uno::Reference< drawing::XDrawPage > xDrawPage = xDPSupp->getDrawPage();
 
diff --git a/sw/source/filter/html/htmlgrin.cxx 
b/sw/source/filter/html/htmlgrin.cxx
index b292b9d69fd8..9282b7b8c175 100644
--- a/sw/source/filter/html/htmlgrin.cxx
+++ b/sw/source/filter/html/htmlgrin.cxx
@@ -74,6 +74,7 @@
 #include <tools/hostfilter.hxx>
 #include <tools/urlobj.hxx>
 #include <unotools/securityoptions.hxx>
+#include <unotxdoc.hxx>
 
 using namespace ::com::sun::star;
 
@@ -1572,8 +1573,8 @@ void SwHTMLParser::NotifyMacroEventRead()
     SwDocShell *pDocSh = m_xDoc->GetDocShell();
     if (!pDocSh)
         return;
-    uno::Reference<frame::XModel> const xModel(pDocSh->GetBaseModel());
-    comphelper::DocumentInfo::notifyMacroEventRead(xModel);
+    rtl::Reference<SwXTextDocument> const xModel(pDocSh->GetBaseModel());
+    
comphelper::DocumentInfo::notifyMacroEventRead(static_cast<SfxBaseModel*>(xModel.get()));
     m_bNotifyMacroEventRead = true;
 }
 
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index e3b2d9869b4e..60646c0f2a72 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -164,6 +164,7 @@
 #include <frozen/unordered_map.h>
 #include <IDocumentDeviceAccess.hxx>
 #include <sfx2/printer.hxx>
+#include <unotxdoc.hxx>
 
 using ::editeng::SvxBorderLine;
 
@@ -4832,7 +4833,7 @@ DocxStringTokenMap const aExceptionTokens[] = {
 void DocxAttributeOutput::LatentStyles()
 {
     // Do we have latent styles available?
-    uno::Reference<beans::XPropertySet> 
xPropertySet(m_rExport.m_rDoc.GetDocShell()->GetBaseModel(), 
uno::UNO_QUERY_THROW);
+    rtl::Reference<SwXTextDocument> 
xPropertySet(m_rExport.m_rDoc.GetDocShell()->GetBaseModel());
     uno::Sequence<beans::PropertyValue> aInteropGrabBag;
     xPropertySet->getPropertyValue(u"InteropGrabBag"_ustr) >>= aInteropGrabBag;
     uno::Sequence<beans::PropertyValue> aLatentStyles;
@@ -5825,7 +5826,7 @@ void DocxAttributeOutput::WriteOLE( SwOLENode& rNode, 
const Size& rSize, const S
     OSL_ASSERT(pFlyFrameFormat);
 
     // get interoperability information about embedded objects
-    uno::Reference< beans::XPropertySet > xPropSet( 
m_rExport.m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
+    rtl::Reference< SwXTextDocument > xPropSet( 
m_rExport.m_rDoc.GetDocShell()->GetBaseModel() );
     uno::Sequence< beans::PropertyValue > aGrabBag, 
aObjectsInteropList,aObjectInteropAttributes;
     xPropSet->getPropertyValue( UNO_NAME_MISC_OBJ_INTEROPGRABBAG ) >>= 
aGrabBag;
     auto pProp = std::find_if(std::cbegin(aGrabBag), std::cend(aGrabBag),
diff --git a/sw/source/filter/ww8/docxexport.cxx 
b/sw/source/filter/ww8/docxexport.cxx
index e63b6ed0daf5..f14bc8b603d6 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -100,6 +100,7 @@
 #include <sal/log.hxx>
 #include <unotools/ucbstreamhelper.hxx>
 #include <comphelper/diagnose_ex.hxx>
+#include <unotxdoc.hxx>
 
 using namespace sax_fastparser;
 using namespace ::comphelper;
@@ -1245,7 +1246,7 @@ void DocxExport::WriteSettings()
         m_pAttrOutput->WriteFootnoteEndnotePr( pFS, XML_endnotePr, 
m_rDoc.GetEndNoteInfo(), XML_endnote );
 
     // Has themeFontLang information
-    uno::Reference< beans::XPropertySet > xPropSet( pDocShell->GetBaseModel(), 
uno::UNO_QUERY_THROW );
+    rtl::Reference< SwXTextDocument > xPropSet( pDocShell->GetBaseModel() );
 
     bool bUseGrabBagProtection = false;
     bool bWriterWantsToProtect = false;
@@ -1537,7 +1538,7 @@ void DocxExport::WriteTheme()
 // See OOXMLDocumentImpl::resolveGlossaryStream
 void DocxExport::WriteGlossary()
 {
-    uno::Reference< beans::XPropertySet > xPropSet( 
m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
+    rtl::Reference< SwXTextDocument > xPropSet( 
m_rDoc.GetDocShell()->GetBaseModel() );
 
     uno::Reference< beans::XPropertySetInfo > xPropSetInfo = 
xPropSet->getPropertySetInfo();
     OUString aName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG;
@@ -1700,7 +1701,7 @@ static void lcl_UpdateXmlValues(const SdtData& sdtData, 
const uno::Reference<css
 
 void DocxExport::WriteCustomXml()
 {
-    uno::Reference< beans::XPropertySet > xPropSet( 
m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
+    rtl::Reference< SwXTextDocument > xPropSet( 
m_rDoc.GetDocShell()->GetBaseModel() );
 
     uno::Reference< beans::XPropertySetInfo > xPropSetInfo = 
xPropSet->getPropertySetInfo();
     if ( !xPropSetInfo->hasPropertyByName( UNO_NAME_MISC_OBJ_INTEROPGRABBAG ) )
@@ -1802,7 +1803,7 @@ void DocxExport::WriteCustomXml()
 
 void DocxExport::WriteVBA()
 {
-    uno::Reference<document::XStorageBasedDocument> 
xStorageBasedDocument(m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY);
+    rtl::Reference<SwXTextDocument> 
xStorageBasedDocument(m_rDoc.GetDocShell()->GetBaseModel());
     if (!xStorageBasedDocument.is())
         return;
 
@@ -1861,7 +1862,7 @@ void DocxExport::WriteVBA()
 
 void DocxExport::WriteEmbeddings()
 {
-    uno::Reference< beans::XPropertySet > xPropSet( 
m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
+    rtl::Reference< SwXTextDocument > xPropSet( 
m_rDoc.GetDocShell()->GetBaseModel() );
 
     uno::Reference< beans::XPropertySetInfo > xPropSetInfo = 
xPropSet->getPropertySetInfo();
     OUString aName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG;
@@ -2116,7 +2117,7 @@ sal_Int32 DocxExport::WriteOutliner(const 
OutlinerParaObject& rParaObj, sal_uInt
 sal_Int32 DocxExport::getWordCompatibilityModeFromGrabBag() const
 {
     sal_Int32 nWordCompatibilityMode = -1;
-    uno::Reference< beans::XPropertySet > 
xPropSet(m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW);
+    rtl::Reference< SwXTextDocument > 
xPropSet(m_rDoc.GetDocShell()->GetBaseModel());
     uno::Reference< beans::XPropertySetInfo > xPropSetInfo = 
xPropSet->getPropertySetInfo();
     if (xPropSetInfo->hasPropertyByName(UNO_NAME_MISC_OBJ_INTEROPGRABBAG))
     {
diff --git a/sw/source/filter/ww8/docxexportfilter.cxx 
b/sw/source/filter/ww8/docxexportfilter.cxx
index 1d3004e2aa9b..ac910902935e 100644
--- a/sw/source/filter/ww8/docxexportfilter.cxx
+++ b/sw/source/filter/ww8/docxexportfilter.cxx
@@ -73,8 +73,8 @@ bool DocxExportFilter::exportDocument()
         // Check whether application is in headless mode
         if (!Application::IsHeadlessModeEnabled())
         {
-            uno::Reference<document::XStorageBasedDocument> 
xStorageBasedDocument(
-                pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY);
+            rtl::Reference<SwXTextDocument> xStorageBasedDocument(
+                pDoc->GetDocShell()->GetBaseModel());
             if (xStorageBasedDocument.is())
             {
                 uno::Reference<embed::XStorage> xDocumentStorage =
diff --git a/sw/source/filter/ww8/docxtablestyleexport.cxx 
b/sw/source/filter/ww8/docxtablestyleexport.cxx
index 99904394acef..d843cdd515a2 100644
--- a/sw/source/filter/ww8/docxtablestyleexport.cxx
+++ b/sw/source/filter/ww8/docxtablestyleexport.cxx
@@ -20,6 +20,7 @@
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/beans/PropertyValue.hpp>
 #include <com/sun/star/frame/XModel.hpp>
+#include <unotxdoc.hxx>
 
 using namespace com::sun::star;
 using namespace oox;
@@ -124,8 +125,7 @@ void DocxTableStyleExport::CnfStyle(const 
uno::Sequence<beans::PropertyValue>& r
 void DocxTableStyleExport::TableStyles(sal_Int32 nCountStylesToWrite)
 {
     // Do we have table styles from InteropGrabBag available?
-    uno::Reference<beans::XPropertySet> xPropertySet(
-        m_pImpl->getDoc().GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW);
+    rtl::Reference<SwXTextDocument> 
xPropertySet(m_pImpl->getDoc().GetDocShell()->GetBaseModel());
     uno::Sequence<beans::PropertyValue> aInteropGrabBag;
     xPropertySet->getPropertyValue(u"InteropGrabBag"_ustr) >>= aInteropGrabBag;
     uno::Sequence<beans::PropertyValue> aTableStyles;
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index cf15871c8abc..f33256aa5cdd 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -156,6 +156,7 @@
 #include <sfx2/DocumentMetadataAccess.hxx>
 #include <comphelper/diagnose_ex.hxx>
 #include <officecfg/Office/Common.hxx>
+#include <unotxdoc.hxx>
 
 using namespace ::com::sun::star;
 using namespace sw::util;
@@ -5037,13 +5038,12 @@ ErrCode SwWW8ImplReader::CoreLoad(WW8Glossary const 
*pGloss)
         // Initialize RDF metadata, to be able to add statements during the 
import.
         try
         {
-            uno::Reference<frame::XModel> const 
xModel(m_rDoc.GetDocShell()->GetBaseModel());
-            uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(xModel, uno::UNO_QUERY_THROW);
+            rtl::Reference<SwXTextDocument> const 
xModel(m_rDoc.GetDocShell()->GetBaseModel());
             uno::Reference<uno::XComponentContext> 
xComponentContext(comphelper::getProcessComponentContext());
             uno::Reference<embed::XStorage> xStorage = 
comphelper::OStorageHelper::GetTemporaryStorage();
-            const uno::Reference<rdf::XURI> 
xBaseURI(sfx2::createBaseURI(xComponentContext, xModel, m_sBaseURL));
+            const uno::Reference<rdf::XURI> 
xBaseURI(sfx2::createBaseURI(xComponentContext, 
static_cast<SfxBaseModel*>(xModel.get()), m_sBaseURL));
             uno::Reference<task::XInteractionHandler> xHandler;
-            xDocumentMetadataAccess->loadMetadataFromStorage(xStorage, 
xBaseURI, xHandler);
+            xModel->loadMetadataFromStorage(xStorage, xBaseURI, xHandler);
         }
         catch (const uno::Exception&)
         {
@@ -6765,7 +6765,7 @@ void SwWW8ImplReader::NotifyMacroEventRead()
 {
     if (m_bNotifyMacroEventRead)
         return;
-    uno::Reference<frame::XModel> const 
xModel(m_rDoc.GetDocShell()->GetBaseModel());
+    uno::Reference<frame::XModel> const 
xModel(static_cast<SfxBaseModel*>(m_rDoc.GetDocShell()->GetBaseModel().get()));
     comphelper::DocumentInfo::notifyMacroEventRead(xModel);
     m_bNotifyMacroEventRead = true;
 }
diff --git a/sw/source/ui/dbui/mmresultdialogs.cxx 
b/sw/source/ui/dbui/mmresultdialogs.cxx
index 46ad98a62504..2a960e6a8f01 100644
--- a/sw/source/ui/dbui/mmresultdialogs.cxx
+++ b/sw/source/ui/dbui/mmresultdialogs.cxx
@@ -75,6 +75,7 @@
 #include <comphelper/propertyvalue.hxx>
 #include <comphelper/string.hxx>
 #include <iodetect.hxx>
+#include <unotxdoc.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -686,10 +687,10 @@ IMPL_LINK_NOARG(SwMMResultSaveDialog, SaveOutputHdl_Impl, 
weld::Button&, void)
             pTempView->GetDocShell()->GetDoc()->ReplaceDefaults( 
*pTargetView->GetDocShell()->GetDoc());
             pTempView->GetDocShell()->GetDoc()->ReplaceDocumentProperties( 
*pTargetView->GetDocShell()->GetDoc(), true );
 
-            uno::Reference<beans::XPropertySet> const xThisSet(
-                pTargetView->GetDocShell()->GetBaseModel(), 
uno::UNO_QUERY_THROW);
-            uno::Reference<beans::XPropertySet> const xRetSet(
-                pTempView->GetDocShell()->GetBaseModel(), 
uno::UNO_QUERY_THROW);
+            rtl::Reference<SwXTextDocument> const xThisSet(
+                pTargetView->GetDocShell()->GetBaseModel());
+            rtl::Reference<SwXTextDocument> const xRetSet(
+                pTempView->GetDocShell()->GetBaseModel());
             uno::Sequence<beans::PropertyValue> aInteropGrabBag;
             xThisSet->getPropertyValue(u"InteropGrabBag"_ustr) >>= 
aInteropGrabBag;
             xRetSet->setPropertyValue(u"InteropGrabBag"_ustr, 
uno::Any(aInteropGrabBag));
diff --git a/sw/source/ui/frmdlg/cption.cxx b/sw/source/ui/frmdlg/cption.cxx
index 8f86732f7dd9..40f9dd5e4100 100644
--- a/sw/source/ui/frmdlg/cption.cxx
+++ b/sw/source/ui/frmdlg/cption.cxx
@@ -40,6 +40,7 @@
 #include <vcl/weld.hxx>
 #include <strings.hrc>
 #include <SwStyleNameMapper.hxx>
+#include <unotxdoc.hxx>
 
 using namespace ::com::sun::star;
 
@@ -112,14 +113,13 @@ SwCaptionDialog::SwCaptionDialog(weld::Window *pParent, 
SwView &rV)
     //#i61007# order of captions
     ApplyCaptionOrder();
     SwWrtShell &rSh = m_rView.GetWrtShell();
-    uno::Reference< frame::XModel >  xModel = 
m_rView.GetDocShell()->GetBaseModel();
+    rtl::Reference< SwXTextDocument >  xModel = 
m_rView.GetDocShell()->GetBaseModel();
 
     SelectionType eType = rSh.GetSelectionType();
     if ( eType & SelectionType::Ole )
     {
         eType = SelectionType::Graphic;
-        uno::Reference< text::XTextEmbeddedObjectsSupplier >  xObjs(xModel, 
uno::UNO_QUERY);
-        m_xNameAccess = xObjs->getEmbeddedObjects();
+        m_xNameAccess = xModel->getEmbeddedObjects();
     }
 
     m_xCategoryBox->connect_changed(LINK(this, SwCaptionDialog, 
ModifyComboHdl));
@@ -162,8 +162,7 @@ SwCaptionDialog::SwCaptionDialog(weld::Window *pParent, 
SwView &rV)
         //if not OLE
         if(!m_xNameAccess.is())
         {
-            uno::Reference< text::XTextGraphicObjectsSupplier >  
xGraphics(xModel, uno::UNO_QUERY);
-            m_xNameAccess = xGraphics->getGraphicObjects();
+            m_xNameAccess = xModel->getGraphicObjects();
         }
 
     }
@@ -171,15 +170,13 @@ SwCaptionDialog::SwCaptionDialog(weld::Window *pParent, 
SwView &rV)
     {
         nPoolId = RES_POOLCOLL_LABEL_TABLE;
         sString = m_rView.GetOldTabCat();
-        uno::Reference< text::XTextTablesSupplier >  xTables(xModel, 
uno::UNO_QUERY);
-        m_xNameAccess = xTables->getTextTables();
+        m_xNameAccess = xModel->getTextTables();
     }
     else if( eType & SelectionType::Frame )
     {
         nPoolId = RES_POOLCOLL_LABEL_FRAME;
         sString = m_rView.GetOldFrameCat();
-        uno::Reference< text::XTextFramesSupplier >  xFrames(xModel, 
uno::UNO_QUERY);
-        m_xNameAccess = xFrames->getTextFrames();
+        m_xNameAccess = xModel->getTextFrames();
     }
     else if( eType == SelectionType::Text )
     {
diff --git a/sw/source/ui/misc/bookmark.cxx b/sw/source/ui/misc/bookmark.cxx
index d6bbaf0e4b1d..decf3ea80324 100644
--- a/sw/source/ui/misc/bookmark.cxx
+++ b/sw/source/ui/misc/bookmark.cxx
@@ -37,6 +37,7 @@
 #include <ndtxt.hxx>
 #include <strings.hrc>
 #include <IDocumentSettingAccess.hxx>
+#include <unotxdoc.hxx>
 
 using namespace ::com::sun::star;
 
@@ -207,9 +208,8 @@ IMPL_LINK_NOARG(SwInsertBookmarkDlg, RenameHdl, 
weld::Button&, void)
 
     sw::mark::MarkBase* pBookmark
         = 
weld::fromId<sw::mark::MarkBase*>(m_xBookmarksBox->get_id(*xSelected));
-    uno::Reference<frame::XModel> xModel = 
m_rSh.GetView().GetDocShell()->GetBaseModel();
-    uno::Reference<text::XBookmarksSupplier> xBkms(xModel, uno::UNO_QUERY);
-    uno::Reference<container::XNameAccess> xNameAccess = xBkms->getBookmarks();
+    rtl::Reference<SwXTextDocument> xModel = 
m_rSh.GetView().GetDocShell()->GetBaseModel();
+    uno::Reference<container::XNameAccess> xNameAccess = 
xModel->getBookmarks();
     uno::Any aObj = xNameAccess->getByName(pBookmark->GetName());
     uno::Reference<uno::XInterface> xTmp;
     aObj >>= xTmp;
diff --git a/sw/source/uibase/app/applab.cxx b/sw/source/uibase/app/applab.cxx
index 5fe8816cb079..0b9aa2e90312 100644
--- a/sw/source/uibase/app/applab.cxx
+++ b/sw/source/uibase/app/applab.cxx
@@ -60,6 +60,7 @@
 
 #include "appenv.hxx"
 #include <memory>
+#include <unotxdoc.hxx>
 
 using namespace ::com::sun::star;
 
@@ -357,10 +358,10 @@ void SwModule::InsertLab(SfxRequest& rReq, bool bLabel)
         //fill the user fields
         if(!bLabel)
         {
-            uno::Reference< frame::XModel >  xModel = 
pSh->GetView().GetDocShell()->GetBaseModel();
+            rtl::Reference< SwXTextDocument > xModel = 
pSh->GetView().GetDocShell()->GetBaseModel();
             OSL_ENSURE(pDialogFactory, "SwAbstractDialogFactory fail!");
             SwLabDlgMethod SwLabDlgUpdateFieldInformation = 
pDialogFactory->GetSwLabDlgStaticMethod ();
-            SwLabDlgUpdateFieldInformation(xModel, rItem);
+            
SwLabDlgUpdateFieldInformation(static_cast<SfxBaseModel*>(xModel.get()), rItem);
         }
 
         pFieldMgr->SetEvalExpFields(true);
diff --git a/sw/source/uibase/app/docsh.cxx b/sw/source/uibase/app/docsh.cxx
index 6f8673eaff12..a9887b0e8494 100644
--- a/sw/source/uibase/app/docsh.cxx
+++ b/sw/source/uibase/app/docsh.cxx
@@ -105,6 +105,7 @@
 #include <iodetect.hxx>
 
 #include <comphelper/processfactory.hxx>
+#include <unotxdoc.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -889,6 +890,11 @@ void SwDocShell::Draw( OutputDevice* pDev, const JobSetup& 
rSetup,
         EnableSetModified();
 }
 
+rtl::Reference<SwXTextDocument> SwDocShell::GetBaseModel() const
+{
+    return 
dynamic_cast<SwXTextDocument*>(SfxObjectShell::GetBaseModel().get());
+}
+
 void SwDocShell::SetVisArea( const tools::Rectangle &rRect )
 {
     tools::Rectangle aRect( rRect );
diff --git a/sw/source/uibase/app/docsh2.cxx b/sw/source/uibase/app/docsh2.cxx
index ee079554cbe5..a6f5bf0728bd 100644
--- a/sw/source/uibase/app/docsh2.cxx
+++ b/sw/source/uibase/app/docsh2.cxx
@@ -1542,9 +1542,8 @@ void SwDocShell::ReloadFromHtml( const OUString& 
rStreamName, SwSrcView* pSrcVie
     RemoveLink();
 
     // now also the UNO-Model has to be informed about the new Doc #51535#
-    uno::Reference<text::XTextDocument> xDoc(GetBaseModel(), uno::UNO_QUERY);
-    text::XTextDocument* pxDoc = xDoc.get();
-    static_cast<SwXTextDocument*>(pxDoc)->InitNewDoc();
+    rtl::Reference<SwXTextDocument> xDoc(GetBaseModel());
+    xDoc->InitNewDoc();
 
     AddLink();
     //#116402# update font list when new document is created
diff --git a/sw/source/uibase/app/docshini.cxx 
b/sw/source/uibase/app/docshini.cxx
index 5d54d9c1af1c..8605ce7fba92 100644
--- a/sw/source/uibase/app/docshini.cxx
+++ b/sw/source/uibase/app/docshini.cxx
@@ -402,8 +402,8 @@ void SwDocShell::AddLink()
         m_xDoc->getIDocumentSettingAccess().set(DocumentSettingId::HTML_MODE, 
dynamic_cast< const SwWebDocShell *>( this ) !=  nullptr );
     }
     m_xDoc->SetDocShell( this );      // set the DocShell-Pointer for Doc
-    uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), 
uno::UNO_QUERY);
-    static_cast<SwXTextDocument*>(xDoc.get())->Reactivate(this);
+    rtl::Reference< SwXTextDocument > xDoc(GetBaseModel());
+    xDoc->Reactivate(this);
 
     SetPool(&m_xDoc->GetAttrPool());
 
@@ -430,8 +430,8 @@ void SwDocShell::UpdateFontList()
 void SwDocShell::RemoveLink()
 {
     // disconnect Uno-Object
-    uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), 
uno::UNO_QUERY);
-    static_cast<SwXTextDocument*>(xDoc.get())->Invalidate();
+    rtl::Reference< SwXTextDocument > xDoc(GetBaseModel());
+    xDoc->Invalidate();
     if (m_xDoc)
     {
         if (m_xBasePool.is())
@@ -447,14 +447,14 @@ void SwDocShell::RemoveLink()
 void SwDocShell::InvalidateModel()
 {
     // disconnect Uno-Object
-    uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), 
uno::UNO_QUERY);
-    static_cast<SwXTextDocument*>(xDoc.get())->Invalidate();
+    rtl::Reference< SwXTextDocument > xDoc(GetBaseModel());
+    xDoc->Invalidate();
 }
 void SwDocShell::ReactivateModel()
 {
     // disconnect Uno-Object
-    uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), 
uno::UNO_QUERY);
-    static_cast<SwXTextDocument*>(xDoc.get())->Reactivate(this);
+    rtl::Reference< SwXTextDocument > xDoc(GetBaseModel());
+    xDoc->Reactivate(this);
 }
 
 // Load, Default-Format
diff --git a/sw/source/uibase/shells/textsh1.cxx 
b/sw/source/uibase/shells/textsh1.cxx
index fa0a4fad018f..1c07d8e8f5a3 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -131,6 +131,7 @@
 #include <boost/property_tree/json_parser.hpp>
 #include <formatcontentcontrol.hxx>
 #include <rtl/uri.hxx>
+#include <unotxdoc.hxx>
 
 using namespace ::com::sun::star;
 using namespace com::sun::star::beans;
@@ -2782,7 +2783,7 @@ void SwTextShell::GetState( SfxItemSet &rSet )
                 static constexpr OUStringLiteral sDisplay(u"DisplayName");
                 const OUString sHeaderOn(nWhich == FN_INSERT_PAGEHEADER ? 
u"HeaderIsOn"_ustr : u"FooterIsOn"_ustr);
 
-                uno::Reference< XStyleFamiliesSupplier > 
xSupplier(GetView().GetDocShell()->GetBaseModel(), uno::UNO_QUERY);
+                rtl::Reference< SwXTextDocument > 
xSupplier(GetView().GetDocShell()->GetBaseModel());
                 if (xSupplier.is())
                 {
                     uno::Reference< XNameContainer > xContainer;
diff --git a/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx 
b/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx
index 6a836cd2fe4b..4a69c2c1b21b 100644
--- a/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx
+++ b/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx
@@ -46,6 +46,7 @@
 #include <inspectorproperties.hrc>
 #include <strings.hrc>
 #include <rdfhelper.hxx>
+#include <unotxdoc.hxx>
 
 namespace sw::sidebar
 {
@@ -440,8 +441,7 @@ static void MetadataToTreeNode(const 
css::uno::Reference<css::uno::XInterface>&
     // under the tree node "Metadata Reference"
     if (SwDocShell* pDocSh = 
static_cast<SwDocShell*>(SfxObjectShell::Current()))
     {
-        uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(pDocSh->GetBaseModel(),
-                                                                             
uno::UNO_QUERY);
+        rtl::Reference<SwXTextDocument> 
xDocumentMetadataAccess(pDocSh->GetBaseModel());
         const uno::Reference<rdf::XRepository>& xRepo = 
xDocumentMetadataAccess->getRDFRepository();
         const css::uno::Reference<css::rdf::XResource> xSubject(rSource, 
uno::UNO_QUERY);
         std::map<OUString, OUString> xStatements
@@ -592,8 +592,7 @@ static void UpdateTree(SwDocShell& rDocSh, SwEditShell& 
rEditSh,
     InsertValues(static_cast<cppu::OWeakObject*>(xRange.get()), aIsDefined, 
aCharDFNode, false,
                  aHiddenProperties, aFieldsNode);
 
-    uno::Reference<style::XStyleFamiliesSupplier> 
xStyleFamiliesSupplier(rDocSh.GetBaseModel(),
-                                                                         
uno::UNO_QUERY);
+    rtl::Reference<SwXTextDocument> 
xStyleFamiliesSupplier(rDocSh.GetBaseModel());
     uno::Reference<container::XNameAccess> xStyleFamilies
         = xStyleFamiliesSupplier->getStyleFamilies();
     OUString sCurrentCharStyle, sCurrentParaStyle, sDisplayName;
@@ -654,8 +653,7 @@ static void UpdateTree(SwDocShell& rDocSh, SwEditShell& 
rEditSh,
                  aParaNode.children.end()); // Parent style should be first 
then children
 
     // Collect bookmarks at character position
-    uno::Reference<text::XBookmarksSupplier> 
xBookmarksSupplier(rDocSh.GetBaseModel(),
-                                                                
uno::UNO_QUERY);
+    rtl::Reference<SwXTextDocument> xBookmarksSupplier(rDocSh.GetBaseModel());
 
     uno::Reference<container::XIndexAccess> 
xBookmarks(xBookmarksSupplier->getBookmarks(),
                                                        uno::UNO_QUERY);
@@ -690,8 +688,7 @@ static void UpdateTree(SwDocShell& rDocSh, SwEditShell& 
rEditSh,
     }
 
     // Collect sections at character position
-    uno::Reference<text::XTextSectionsSupplier> 
xTextSectionsSupplier(rDocSh.GetBaseModel(),
-                                                                      
uno::UNO_QUERY);
+    rtl::Reference<SwXTextDocument> 
xTextSectionsSupplier(rDocSh.GetBaseModel());
 
     uno::Reference<container::XIndexAccess> 
xTextSections(xTextSectionsSupplier->getTextSections(),
                                                           uno::UNO_QUERY);
diff --git a/sw/source/uibase/uno/unomailmerge.cxx 
b/sw/source/uibase/uno/unomailmerge.cxx
index 33de8d3a1f3b..86d983b27ae1 100644
--- a/sw/source/uibase/uno/unomailmerge.cxx
+++ b/sw/source/uibase/uno/unomailmerge.cxx
@@ -806,7 +806,7 @@ uno::Any SAL_CALL SwXMailMerge::execute(
 
     if (DBMGR_MERGE_SHELL == nMergeType)
     {
-        return Any( 
aMergeDesc.pMailMergeConfigItem->GetTargetView()->GetDocShell()->GetBaseModel() 
);
+        return Any( 
Reference<XModel>(static_cast<SfxBaseModel*>(aMergeDesc.pMailMergeConfigItem->GetTargetView()->GetDocShell()->GetBaseModel().get()))
 );
     }
     else
         return Any( true );
diff --git a/sw/source/uibase/utlui/content.cxx 
b/sw/source/uibase/utlui/content.cxx
index c626a8574bed..b2571a7a68ff 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -124,6 +124,7 @@
 #include <svl/fstathelper.hxx>
 
 #include <expfld.hxx>
+#include <unotxdoc.hxx>
 
 #define CTYPE_CNT   0
 #define CTYPE_CTT   1
@@ -5907,9 +5908,8 @@ void SwContentTree::EditEntry(const weld::TreeIter& 
rEntry, EditEntryMode nMode)
             }
             else if(nMode == EditEntryMode::RENAME)
             {
-                uno::Reference< frame::XModel >  xModel = 
m_pActiveShell->GetView().GetDocShell()->GetBaseModel();
-                uno::Reference< text::XTextTablesSupplier >  xTables(xModel, 
uno::UNO_QUERY);
-                xNameAccess = xTables->getTextTables();
+                rtl::Reference< SwXTextDocument >  xModel = 
m_pActiveShell->GetView().GetDocShell()->GetBaseModel();
+                xNameAccess = xModel->getTextTables();
             }
             else
                 nSlot = FN_FORMAT_TABLE_DLG;
@@ -5922,13 +5922,10 @@ void SwContentTree::EditEntry(const weld::TreeIter& 
rEntry, EditEntryMode nMode)
             }
             else if(nMode == EditEntryMode::RENAME)
             {
-                uno::Reference< frame::XModel >  xModel = 
m_pActiveShell->GetView().GetDocShell()->GetBaseModel();
-                uno::Reference< text::XTextGraphicObjectsSupplier >  
xGraphics(xModel, uno::UNO_QUERY);
-                xNameAccess = xGraphics->getGraphicObjects();
-                uno::Reference< text::XTextFramesSupplier >  xFrames(xModel, 
uno::UNO_QUERY);
-                xSecond = xFrames->getTextFrames();
-                uno::Reference< text::XTextEmbeddedObjectsSupplier >  
xObjs(xModel, uno::UNO_QUERY);
-                xThird = xObjs->getEmbeddedObjects();
+                rtl::Reference< SwXTextDocument >  xModel = 
m_pActiveShell->GetView().GetDocShell()->GetBaseModel();
+                xNameAccess = xModel->getGraphicObjects();
+                xSecond = xModel->getTextFrames();
+                xThird = xModel->getEmbeddedObjects();
             }
             else
                 nSlot = FN_FORMAT_GRAFIC_DLG;
@@ -5942,21 +5939,18 @@ void SwContentTree::EditEntry(const weld::TreeIter& 
rEntry, EditEntryMode nMode)
             }
             else if(nMode == EditEntryMode::RENAME)
             {
-                uno::Reference< frame::XModel >  xModel = 
m_pActiveShell->GetView().GetDocShell()->GetBaseModel();
-                uno::Reference< text::XTextFramesSupplier >  xFrames(xModel, 
uno::UNO_QUERY);
-                uno::Reference< text::XTextEmbeddedObjectsSupplier >  
xObjs(xModel, uno::UNO_QUERY);
+                rtl::Reference< SwXTextDocument >  xModel = 
m_pActiveShell->GetView().GetDocShell()->GetBaseModel();
                 if(ContentTypeId::FRAME == nType)
                 {
-                    xNameAccess = xFrames->getTextFrames();
-                    xSecond = xObjs->getEmbeddedObjects();
+                    xNameAccess = xModel->getTextFrames();
+                    xSecond = xModel->getEmbeddedObjects();
                 }
                 else
                 {
-                    xNameAccess = xObjs->getEmbeddedObjects();
-                    xSecond = xFrames->getTextFrames();
+                    xNameAccess = xModel->getEmbeddedObjects();
+                    xSecond = xModel->getTextFrames();
                 }
-                uno::Reference< text::XTextGraphicObjectsSupplier >  
xGraphics(xModel, uno::UNO_QUERY);
-                xThird = xGraphics->getGraphicObjects();
+                xThird = xModel->getGraphicObjects();
             }
             else
                 nSlot = FN_FORMAT_FRAME_DLG;
@@ -5971,9 +5965,8 @@ void SwContentTree::EditEntry(const weld::TreeIter& 
rEntry, EditEntryMode nMode)
             else if(nMode == EditEntryMode::RENAME)
             {
                 
assert(!m_pActiveShell->getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS));
-                uno::Reference< frame::XModel >  xModel = 
m_pActiveShell->GetView().GetDocShell()->GetBaseModel();
-                uno::Reference< text::XBookmarksSupplier >  xBkms(xModel, 
uno::UNO_QUERY);
-                xNameAccess = xBkms->getBookmarks();
+                rtl::Reference< SwXTextDocument > xModel = 
m_pActiveShell->GetView().GetDocShell()->GetBaseModel();
+                xNameAccess = xModel->getBookmarks();
             }
             else
             {
@@ -5996,9 +5989,8 @@ void SwContentTree::EditEntry(const weld::TreeIter& 
rEntry, EditEntryMode nMode)
             }
             else if (nMode == EditEntryMode::RENAME)
             {
-                uno::Reference< frame::XModel >  xModel = 
m_pActiveShell->GetView().GetDocShell()->GetBaseModel();
-                uno::Reference< text::XTextSectionsSupplier >  xSects(xModel, 
uno::UNO_QUERY);
-                xNameAccess = xSects->getTextSections();
+                rtl::Reference< SwXTextDocument > xModel = 
m_pActiveShell->GetView().GetDocShell()->GetBaseModel();
+                xNameAccess = xModel->getTextSections();
             }
             else
                 nSlot = FN_EDIT_REGION;
@@ -6080,9 +6072,8 @@ void SwContentTree::EditEntry(const weld::TreeIter& 
rEntry, EditEntryMode nMode)
                 case EditEntryMode::UPD_IDX:
                 case EditEntryMode::RENAME:
                 {
-                    Reference< frame::XModel >  xModel = 
m_pActiveShell->GetView().GetDocShell()->GetBaseModel();
-                    Reference< XDocumentIndexesSupplier >  xIndexes(xModel, 
UNO_QUERY);
-                    Reference< XIndexAccess> 
xIdxAcc(xIndexes->getDocumentIndexes());
+                    rtl::Reference< SwXTextDocument > xModel = 
m_pActiveShell->GetView().GetDocShell()->GetBaseModel();
+                    Reference< XIndexAccess> 
xIdxAcc(xModel->getDocumentIndexes());
                     Reference< XNameAccess >xLocalNameAccess(xIdxAcc, 
UNO_QUERY);
                     if(EditEntryMode::RENAME == nMode)
                         xNameAccess = xLocalNameAccess;
@@ -6591,7 +6582,7 @@ void SwContentTree::GotoContent(const SwContent* pCnt)
             // multiple bookmarks are there on the selected text range.
             // Note: this is a workaround because getDialog() of XPanel is not 
implemented
             // for SwNavigatorPanel.
-            uno::Reference< frame::XModel > xModel = 
m_pActiveShell->GetView().GetDocShell()->GetBaseModel();
+            rtl::Reference< SwXTextDocument > xModel = 
m_pActiveShell->GetView().GetDocShell()->GetBaseModel();
 
             Reference<frame::XController2> xController( 
xModel->getCurrentController(), uno::UNO_QUERY);
             if ( !xController.is() )

Reply via email to