include/svx/AccessibilityCheckDialog.hxx                              |    2 
 include/svx/AccessibleShapeInfo.hxx                                   |   16 
+--
 include/svx/ClassificationDialog.hxx                                  |    2 
 include/svx/ClassificationField.hxx                                   |   19 
++--
 include/svx/ColorSets.hxx                                             |    4 
 include/svx/ShapeTypeHandler.hxx                                      |    5 -
 include/svx/SmartTagItem.hxx                                          |   10 +-
 include/svx/SmartTagMgr.hxx                                           |    7 -
 include/svx/XPropertyEntry.hxx                                        |    2 
 include/svx/colorbox.hxx                                              |    2 
 include/svx/colorwindow.hxx                                           |   10 +-
 include/svx/compressgraphicdialog.hxx                                 |    2 
 include/svx/diagram/datamodel.hxx                                     |    2 
 include/svx/drawitem.hxx                                              |   14 +-
 include/svx/e3dundo.hxx                                               |   13 +-
 include/svx/galmisc.hxx                                               |    9 +
 include/svx/hlnkitem.hxx                                              |    4 
 include/svx/lathe3d.hxx                                               |    2 
 include/svx/numinf.hxx                                                |    4 
 include/svx/ofaitem.hxx                                               |    2 
 include/svx/polypolygoneditor.hxx                                     |    2 
 include/svx/sdr/overlay/overlaypolypolygon.hxx                        |    4 
 include/svx/sidebar/SelectionChangeHandler.hxx                        |    2 
 include/svx/svddrgmt.hxx                                              |    2 
 include/svx/svdhdl.hxx                                                |    4 
 include/svx/svdlayer.hxx                                              |    2 
 include/svx/svdopath.hxx                                              |    2 
 include/svx/svdundo.hxx                                               |    4 
 include/svx/svxgraphicitem.hxx                                        |    2 
 include/svx/ucsubset.hxx                                              |    2 
 include/svx/unoshape.hxx                                              |    2 
 include/svx/xlnedit.hxx                                               |    4 
 include/svx/xlnstit.hxx                                               |    4 
 include/svx/xtable.hxx                                                |    4 
 svx/inc/DescriptionGenerator.hxx                                      |    2 
 svx/inc/extrud3d.hxx                                                  |    2 
 svx/inc/palettes.hxx                                                  |    6 -
 svx/inc/sdr/attribute/sdreffectstextattribute.hxx                     |    6 -
 svx/inc/sdr/attribute/sdrfilltextattribute.hxx                        |    6 -
 svx/inc/sdr/attribute/sdrlineeffectstextattribute.hxx                 |    4 
 svx/inc/sdr/attribute/sdrlinefilleffectstextattribute.hxx             |    4 
 svx/inc/sdr/primitive2d/sdrcaptionprimitive2d.hxx                     |    4 
 svx/inc/sdr/primitive2d/sdrconnectorprimitive2d.hxx                   |    2 
 svx/inc/sdr/primitive2d/sdrcustomshapeprimitive2d.hxx                 |    4 
 svx/inc/sdr/primitive2d/sdrellipseprimitive2d.hxx                     |    2 
 svx/inc/sdr/primitive2d/sdrgrafprimitive2d.hxx                        |    2 
 svx/inc/sdr/primitive2d/sdrole2primitive2d.hxx                        |    2 
 svx/inc/sdr/primitive2d/sdrolecontentprimitive2d.hxx                  |    2 
 svx/inc/sdr/primitive2d/sdrpathprimitive2d.hxx                        |    6 -
 svx/inc/sdr/primitive2d/sdrrectangleprimitive2d.hxx                   |    2 
 svx/inc/sdr/primitive2d/sdrtextprimitive2d.hxx                        |   18 
+--
 svx/inc/tbxcolorupdate.hxx                                            |    6 -
 svx/source/accessibility/AccessibleShapeInfo.cxx                      |   17 
+--
 svx/source/accessibility/ChildrenManagerImpl.cxx                      |    9 +
 svx/source/accessibility/ChildrenManagerImpl.hxx                      |    4 
 svx/source/accessibility/DescriptionGenerator.cxx                     |    5 -
 svx/source/accessibility/svxpixelctlaccessiblecontext.cxx             |    5 -
 svx/source/accessibility/svxrectctaccessiblecontext.cxx               |    9 +
 svx/source/core/extedit.cxx                                           |    5 -
 svx/source/customshapes/EnhancedCustomShapeFunctionParser.cxx         |   47 
+++++-----
 svx/source/customshapes/EnhancedCustomShapeHandle.cxx                 |    5 -
 svx/source/customshapes/EnhancedCustomShapeHandle.hxx                 |    2 
 svx/source/diagram/datamodel.cxx                                      |    7 -
 svx/source/dialog/AccessibilityCheckDialog.cxx                        |    5 -
 svx/source/dialog/ClassificationDialog.cxx                            |    5 -
 svx/source/dialog/charmap.cxx                                         |    5 -
 svx/source/dialog/compressgraphicdialog.cxx                           |    5 -
 svx/source/dialog/docrecovery.cxx                                     |    5 -
 svx/source/dialog/imapwnd.hxx                                         |    5 -
 svx/source/dialog/svxgraphicitem.cxx                                  |    5 -
 svx/source/engine3d/e3dundo.cxx                                       |    9 +
 svx/source/engine3d/extrud3d.cxx                                      |    5 -
 svx/source/engine3d/lathe3d.cxx                                       |    5 -
 svx/source/engine3d/view3d.cxx                                        |    5 -
 svx/source/form/datanavi.cxx                                          |    5 -
 svx/source/form/filtnav.cxx                                           |    5 -
 svx/source/form/fmexpl.cxx                                            |    5 -
 svx/source/form/fmscriptingenv.cxx                                    |    5 -
 svx/source/form/fmtextcontroldialogs.cxx                              |    5 -
 svx/source/form/fmtextcontrolfeature.cxx                              |    5 -
 svx/source/form/fmvwimp.cxx                                           |    5 -
 svx/source/form/formfeaturedispatcher.cxx                             |    5 -
 svx/source/form/tabwin.cxx                                            |    5 -
 svx/source/gallery2/galbrws1.cxx                                      |    5 -
 svx/source/gallery2/galbrws1.hxx                                      |    2 
 svx/source/inc/DefaultShapesPanel.hxx                                 |    2 
 svx/source/inc/StylesPreviewWindow.hxx                                |    2 
 svx/source/inc/datanavi.hxx                                           |    2 
 svx/source/inc/docrecovery.hxx                                        |    2 
 svx/source/inc/filtnav.hxx                                            |    7 -
 svx/source/inc/findtextfield.hxx                                      |    5 -
 svx/source/inc/fmcontrolbordermanager.hxx                             |    5 -
 svx/source/inc/fmexpl.hxx                                             |    2 
 svx/source/inc/fmtextcontroldialogs.hxx                               |    2 
 svx/source/inc/fmtextcontrolfeature.hxx                               |    2 
 svx/source/inc/fmvwimp.hxx                                            |    2 
 svx/source/inc/formfeaturedispatcher.hxx                              |    2 
 svx/source/inc/svxpixelctlaccessiblecontext.hxx                       |    2 
 svx/source/inc/svxrectctaccessiblecontext.hxx                         |    2 
 svx/source/items/SmartTagItem.cxx                                     |   21 
++--
 svx/source/items/drawitem.cxx                                         |   29 
+++---
 svx/source/items/hlnkitem.cxx                                         |   13 +-
 svx/source/items/numinf.cxx                                           |    9 +
 svx/source/items/ofaitem.cxx                                          |    5 -
 svx/source/mnuctrls/smarttagmenu.cxx                                  |    7 -
 svx/source/sdr/attribute/sdreffectstextattribute.cxx                  |   13 +-
 svx/source/sdr/attribute/sdrfilltextattribute.cxx                     |   13 +-
 svx/source/sdr/attribute/sdrformtextoutlineattribute.cxx              |    5 -
 svx/source/sdr/attribute/sdrlineeffectstextattribute.cxx              |    9 +
 svx/source/sdr/attribute/sdrlinefilleffectstextattribute.cxx          |    9 +
 svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx              |    5 -
 svx/source/sdr/overlay/overlaypolypolygon.cxx                         |    9 +
 svx/source/sdr/primitive2d/sdrcaptionprimitive2d.cxx                  |    9 +
 svx/source/sdr/primitive2d/sdrconnectorprimitive2d.cxx                |    5 -
 svx/source/sdr/primitive2d/sdrcustomshapeprimitive2d.cxx              |    9 +
 svx/source/sdr/primitive2d/sdrellipseprimitive2d.cxx                  |    5 -
 svx/source/sdr/primitive2d/sdrgrafprimitive2d.cxx                     |    5 -
 svx/source/sdr/primitive2d/sdrole2primitive2d.cxx                     |    5 -
 svx/source/sdr/primitive2d/sdrolecontentprimitive2d.cxx               |    5 -
 svx/source/sdr/primitive2d/sdrpathprimitive2d.cxx                     |   13 +-
 svx/source/sdr/primitive2d/sdrrectangleprimitive2d.cxx                |    5 -
 svx/source/sdr/primitive2d/sdrtextprimitive2d.cxx                     |   37 
++++---
 svx/source/sidebar/SelectionChangeHandler.cxx                         |    5 -
 svx/source/sidebar/paragraph/ParaPropertyPanel.cxx                    |    5 -
 svx/source/sidebar/paragraph/ParaPropertyPanel.hxx                    |    2 
 svx/source/sidebar/possize/PosSizePropertyPanel.cxx                   |    5 -
 svx/source/sidebar/possize/PosSizePropertyPanel.hxx                   |    2 
 svx/source/sidebar/shapes/DefaultShapesPanel.cxx                      |    5 -
 svx/source/smarttags/SmartTagMgr.cxx                                  |    5 -
 svx/source/styles/ColorSets.cxx                                       |    9 +
 svx/source/svdraw/polypolygoneditor.cxx                               |    5 -
 svx/source/svdraw/svddrgmt.cxx                                        |    5 -
 svx/source/svdraw/svdhdl.cxx                                          |    9 +
 svx/source/svdraw/svdlayer.cxx                                        |    5 -
 svx/source/svdraw/svdopath.cxx                                        |    5 -
 svx/source/svdraw/svdotextpathdecomposition.cxx                       |    5 -
 svx/source/svdraw/svdundo.cxx                                         |    9 +
 svx/source/table/accessiblecell.cxx                                   |    5 -
 svx/source/table/accessiblecell.hxx                                   |    2 
 svx/source/table/cell.cxx                                             |    7 -
 svx/source/table/cellrange.cxx                                        |    5 -
 svx/source/table/cellrange.hxx                                        |    2 
 svx/source/table/propertyset.cxx                                      |    6 -
 svx/source/table/propertyset.hxx                                      |    2 
 svx/source/table/tablecolumn.cxx                                      |    5 -
 svx/source/table/tablecolumn.hxx                                      |    2 
 svx/source/table/tablecolumns.cxx                                     |    5 -
 svx/source/table/tablecolumns.hxx                                     |    2 
 svx/source/table/tablehandles.cxx                                     |    7 -
 svx/source/table/tablelayouter.cxx                                    |    5 -
 svx/source/table/tablelayouter.hxx                                    |    2 
 svx/source/table/tablerow.cxx                                         |    5 -
 svx/source/table/tablerow.hxx                                         |    2 
 svx/source/table/tablerows.cxx                                        |    5 -
 svx/source/table/tablerows.hxx                                        |    2 
 svx/source/table/viewcontactoftableobj.cxx                            |    5 -
 svx/source/tbxctrls/Palette.cxx                                       |   19 
++--
 svx/source/tbxctrls/StylesPreviewWindow.cxx                           |    5 -
 svx/source/tbxctrls/layctrl.cxx                                       |    7 -
 svx/source/tbxctrls/tbcontrl.cxx                                      |   42 
++++----
 svx/source/tbxctrls/tbunocontroller.cxx                               |    7 -
 svx/source/tbxctrls/tbunosearchcontrollers.cxx                        |    9 +
 svx/source/tbxctrls/tbxcolorupdate.cxx                                |   13 +-
 svx/source/unodialogs/textconversiondlgs/chinese_dictionarydialog.cxx |    7 -
 svx/source/unodialogs/textconversiondlgs/chinese_dictionarydialog.hxx |    2 
 svx/source/unodraw/recoveryui.cxx                                     |    7 -
 svx/source/unodraw/unoshap4.cxx                                       |    5 -
 svx/source/xml/xmlxtimp.cxx                                           |    7 -
 svx/source/xoutdev/XPropertyEntry.cxx                                 |    5 -
 svx/source/xoutdev/xattr.cxx                                          |   16 
+--
 svx/source/xoutdev/xtable.cxx                                         |   11 +-
 sw/inc/fmtfld.hxx                                                     |   10 +-
 sw/inc/fmtftn.hxx                                                     |    9 +
 sw/inc/fmtmeta.hxx                                                    |    8 -
 sw/inc/fmtrfmrk.hxx                                                   |    9 +
 sw/inc/formatcontentcontrol.hxx                                       |   10 --
 sw/inc/formatlinebreak.hxx                                            |   14 +-
 sw/inc/ndtxt.hxx                                                      |    9 +
 sw/inc/section.hxx                                                    |    9 +
 sw/inc/tox.hxx                                                        |   11 +-
 sw/inc/unoframe.hxx                                                   |   17 
+--
 sw/inc/unoparagraph.hxx                                               |    2 
 sw/inc/unotbl.hxx                                                     |    2 
 sw/inc/unotextbodyhf.hxx                                              |    2 
 sw/inc/unotxdoc.hxx                                                   |    1 
 sw/qa/extras/layout/layout.cxx                                        |    9 -
 sw/source/core/crsr/bookmark.cxx                                      |    7 +
 sw/source/core/doc/rdfhelper.cxx                                      |    8 -
 sw/source/core/doc/textboxhelper.cxx                                  |   16 
+--
 sw/source/core/docnode/section.cxx                                    |   12 +-
 sw/source/core/edit/edfcol.cxx                                        |   24 
++---
 sw/source/core/inc/bookmark.hxx                                       |    9 +
 sw/source/core/inc/unobookmark.hxx                                    |    4 
 sw/source/core/inc/unocontentcontrol.hxx                              |    4 
 sw/source/core/inc/unofield.hxx                                       |    4 
 sw/source/core/inc/unofootnote.hxx                                    |    2 
 sw/source/core/inc/unoidx.hxx                                         |    4 
 sw/source/core/inc/unolinebreak.hxx                                   |    3 
 sw/source/core/inc/unometa.hxx                                        |    8 -
 sw/source/core/inc/unorefmark.hxx                                     |    2 
 sw/source/core/inc/unosection.hxx                                     |    2 
 sw/source/core/tox/tox.cxx                                            |    6 +
 sw/source/core/txtnode/atrfld.cxx                                     |    4 
 sw/source/core/txtnode/atrftn.cxx                                     |    6 +
 sw/source/core/txtnode/atrref.cxx                                     |    6 +
 sw/source/core/txtnode/attrcontentcontrol.cxx                         |    8 +
 sw/source/core/txtnode/attrlinebreak.cxx                              |    8 +
 sw/source/core/txtnode/fmtatr2.cxx                                    |    4 
 sw/source/core/txtnode/ndtxt.cxx                                      |    9 +
 sw/source/core/unocore/unobkm.cxx                                     |   16 
+--
 sw/source/core/unocore/unocoll.cxx                                    |   46 
++++-----
 sw/source/core/unocore/unocontentcontrol.cxx                          |   30 
++----
 sw/source/core/unocore/unodraw.cxx                                    |   10 +-
 sw/source/core/unocore/unofield.cxx                                   |   28 
++---
 sw/source/core/unocore/unoframe.cxx                                   |   29 
++----
 sw/source/core/unocore/unoftn.cxx                                     |   13 +-
 sw/source/core/unocore/unoidx.cxx                                     |   38 
+++-----
 sw/source/core/unocore/unolinebreak.cxx                               |    9 -
 sw/source/core/unocore/unoobj2.cxx                                    |    9 -
 sw/source/core/unocore/unoparagraph.cxx                               |   12 +-
 sw/source/core/unocore/unorefmk.cxx                                   |   46 
++++-----
 sw/source/core/unocore/unosect.cxx                                    |   12 +-
 sw/source/core/unocore/unotbl.cxx                                     |   15 
+--
 sw/source/core/unocore/unotext.cxx                                    |    9 +
 sw/source/filter/ww8/docxattributeoutput.cxx                          |    2 
 sw/source/filter/xml/xmltexti.cxx                                     |   20 
++--
 sw/source/uibase/dochdl/swdtflvr.cxx                                  |    2 
 sw/source/uibase/docvw/UnfloatTableButton.cxx                         |    7 -
 sw/source/uibase/uno/unotxdoc.cxx                                     |    5 +
 sw/source/uibase/uno/unotxvw.cxx                                      |   12 +-
 230 files changed, 930 insertions(+), 802 deletions(-)

New commits:
commit 7a076dd9a6d11aef547f657f525ec0c27a50db58
Author:     Noel Grandin <[email protected]>
AuthorDate: Wed Jul 20 20:57:14 2022 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Thu Jul 21 09:00:05 2022 +0200

    use more concrete UNO classes in writer
    
    as opposed to opaque UNO interfaces.
    This is a prelude which enables performance work because now I can
    regular C++ method
    
    Change-Id: I9bcfdca1000b4439431c9ea3b17bed081d80f0b0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137275
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/sw/inc/fmtfld.hxx b/sw/inc/fmtfld.hxx
index 08b58ec0b953..5807ed8fba70 100644
--- a/sw/inc/fmtfld.hxx
+++ b/sw/inc/fmtfld.hxx
@@ -24,6 +24,7 @@
 #include <svl/poolitem.hxx>
 #include <svl/SfxBroadcaster.hxx>
 #include <com/sun/star/text/XTextField.hpp>
+#include <unotools/weakref.hxx>
 
 #include "swdllapi.h"
 #include "calbck.hxx"
@@ -36,6 +37,7 @@ class SwView;
 class SwFieldType;
 class SwDDETable;
 class SwFormatField;
+class SwXTextField;
 class IDocumentRedlineAccess;
 
 namespace sw {
@@ -101,7 +103,7 @@ class SW_DLLPUBLIC SwFormatField final
     friend void InitCore();
     SwFormatField( sal_uInt16 nWhich ); // for default-Attribute
 
-    css::uno::WeakReference<css::text::XTextField> m_wXTextField;
+    unotools::WeakReference<SwXTextField> m_wXTextField;
 
     std::unique_ptr<SwField> mpField;
     SwTextField* mpTextField; // the TextAttribute
@@ -158,10 +160,10 @@ public:
     bool IsFieldInDoc() const;
     bool IsProtect() const;
 
-    SAL_DLLPRIVATE css::uno::WeakReference<css::text::XTextField> const& 
GetXTextField() const
+    SAL_DLLPRIVATE unotools::WeakReference<SwXTextField> const& 
GetXTextField() const
             { return m_wXTextField; }
-    SAL_DLLPRIVATE void 
SetXTextField(css::uno::Reference<css::text::XTextField> const& xTextField)
-            { m_wXTextField = xTextField; }
+    SAL_DLLPRIVATE void SetXTextField(rtl::Reference<SwXTextField> const& 
xTextField);
+
     void dumpAsXml(xmlTextWriterPtr pWriter) const override;
 
     void UpdateTextNode(const SfxPoolItem* pOld, const SfxPoolItem* pNew);
diff --git a/sw/inc/fmtftn.hxx b/sw/inc/fmtftn.hxx
index 4b2635f6bc90..8636b7024909 100644
--- a/sw/inc/fmtftn.hxx
+++ b/sw/inc/fmtftn.hxx
@@ -22,6 +22,7 @@
 #include <rtl/ustring.hxx>
 #include <cppuhelper/weakref.hxx>
 #include <svl/poolitem.hxx>
+#include <unotools/weakref.hxx>
 #include <com/sun/star/text/XFootnote.hpp>
 
 #include "swdllapi.h"
@@ -34,6 +35,7 @@ namespace com::sun::star::text {
 class SwDoc;
 class SwTextFootnote;
 class SwRootFrame;
+class SwXFootnote;
 
 // ATT_FTN
 
@@ -48,7 +50,7 @@ class SW_DLLPUBLIC SwFormatFootnote final
     sal_uInt16 m_nNumberRLHidden; ///< automatic sequence number (hidden 
redlines)
     bool    m_bEndNote;     ///< Is it an End note?
 
-    css::uno::WeakReference<css::text::XFootnote> m_wXFootnote;
+    unotools::WeakReference<SwXFootnote> m_wXFootnote;
 
     SwFormatFootnote& operator=(const SwFormatFootnote& rFootnote) = delete;
     SwFormatFootnote( const SwFormatFootnote& ) = delete;
@@ -91,10 +93,9 @@ public:
 
     css::uno::Reference<css::text::XTextRange> getAnchor(SwDoc& rDoc) const;
 
-    css::uno::WeakReference<css::text::XFootnote> const& GetXFootnote() const
+    unotools::WeakReference<SwXFootnote> const& GetXFootnote() const
         { return m_wXFootnote; }
-    void SetXFootnote(css::uno::Reference<css::text::XFootnote> const& xNote)
-        { m_wXFootnote = xNote; }
+    void SetXFootnote(rtl::Reference<SwXFootnote> const& xNote);
 };
 
 #endif
diff --git a/sw/inc/fmtmeta.hxx b/sw/inc/fmtmeta.hxx
index ab98b5537f3e..71031089a67b 100644
--- a/sw/inc/fmtmeta.hxx
+++ b/sw/inc/fmtmeta.hxx
@@ -131,8 +131,7 @@ class Meta
     friend class ::SwFormatMeta; ///< SetFormatMeta, NotifyChangeTextNode
     friend class ::SwXMeta;   ///< GetTextNode, GetTextAttr, Get/SetXMeta
 
-    css::uno::WeakReference<
-        css::rdf::XMetadatable> m_wXMeta;
+    unotools::WeakReference<SwXMeta> m_wXMeta;
 
     SwFormatMeta * m_pFormat;
     SwTextNode * m_pTextNode;
@@ -147,10 +146,9 @@ protected:
 
     void NotifyChangeTextNode(SwTextNode *const pTextNode);
 
-    css::uno::WeakReference<css::rdf::XMetadatable> const& GetXMeta() const
+    unotools::WeakReference<SwXMeta> const& GetXMeta() const
             { return m_wXMeta; }
-    void SetXMeta(css::uno::Reference<css::rdf::XMetadatable> const& xMeta)
-            { m_wXMeta = xMeta; }
+    void SetXMeta(rtl::Reference<SwXMeta> const& xMeta);
 
     virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
 
diff --git a/sw/inc/fmtrfmrk.hxx b/sw/inc/fmtrfmrk.hxx
index 8b28494f9e20..1d7836f46187 100644
--- a/sw/inc/fmtrfmrk.hxx
+++ b/sw/inc/fmtrfmrk.hxx
@@ -22,11 +22,13 @@
 #include <rtl/ustring.hxx>
 #include <cppuhelper/weakref.hxx>
 #include <svl/poolitem.hxx>
+#include <unotools/weakref.hxx>
 #include <com/sun/star/text/XTextContent.hpp>
 
 #include "calbck.hxx"
 
 class SwTextRefMark;
+class SwXReferenceMark;
 
 // ATT_REFMARK
 
@@ -40,7 +42,7 @@ class SAL_DLLPUBLIC_RTTI SwFormatRefMark final
     SwFormatRefMark& operator=(const SwFormatRefMark& rRefMark) = delete;
     OUString m_aRefName;
 
-    css::uno::WeakReference<css::text::XTextContent> m_wXReferenceMark;
+    unotools::WeakReference<SwXReferenceMark> m_wXReferenceMark;
 
 public:
     SwFormatRefMark( const OUString& rText );
@@ -61,10 +63,9 @@ public:
     OUString &GetRefName()       { return m_aRefName; }
     const OUString &GetRefName() const { return m_aRefName; }
 
-    css::uno::WeakReference<css::text::XTextContent> const& GetXRefMark() const
+    unotools::WeakReference<SwXReferenceMark> const& GetXRefMark() const
         { return m_wXReferenceMark; }
-    void SetXRefMark(css::uno::Reference<css::text::XTextContent> const& xMark)
-        { m_wXReferenceMark = xMark; }
+    void SetXRefMark(rtl::Reference<SwXReferenceMark> const& xMark);
 };
 
 #endif
diff --git a/sw/inc/formatcontentcontrol.hxx b/sw/inc/formatcontentcontrol.hxx
index 975972573c30..d7fc62fc2ecd 100644
--- a/sw/inc/formatcontentcontrol.hxx
+++ b/sw/inc/formatcontentcontrol.hxx
@@ -25,6 +25,7 @@
 #include <cppuhelper/weakref.hxx>
 #include <sal/types.h>
 #include <svl/poolitem.hxx>
+#include <unotools/weakref.hxx>
 
 #include "calbck.hxx"
 #include "swdllapi.h"
@@ -107,7 +108,7 @@ public:
 /// Stores the properties of a content control.
 class SW_DLLPUBLIC SwContentControl : public sw::BroadcastingModify
 {
-    css::uno::WeakReference<css::text::XTextContent> m_wXContentControl;
+    unotools::WeakReference<SwXContentControl> m_wXContentControl;
 
     SwFormatContentControl* m_pFormat;
 
@@ -185,15 +186,12 @@ public:
 
     void NotifyChangeTextNode(SwTextNode* pTextNode);
 
-    const css::uno::WeakReference<css::text::XTextContent>& 
GetXContentControl() const
+    const unotools::WeakReference<SwXContentControl>& GetXContentControl() 
const
     {
         return m_wXContentControl;
     }
 
-    void SetXContentControl(const 
css::uno::Reference<css::text::XTextContent>& xContentCnotrol)
-    {
-        m_wXContentControl = xContentCnotrol;
-    }
+    void SetXContentControl(const rtl::Reference<SwXContentControl>& 
xContentCnotrol);
 
     virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
 
diff --git a/sw/inc/formatlinebreak.hxx b/sw/inc/formatlinebreak.hxx
index 0aa8fcee9145..1bc05f092903 100644
--- a/sw/inc/formatlinebreak.hxx
+++ b/sw/inc/formatlinebreak.hxx
@@ -24,10 +24,12 @@
 #include "calbck.hxx"
 
 #include <cppuhelper/weakref.hxx>
+#include <unotools/weakref.hxx>
 #include <com/sun/star/text/XTextContent.hpp>
 
 class SwDoc;
 class SwTextLineBreak;
+class SwXLineBreak;
 
 /// Defines the location of a line break text wrapping restart.
 enum class SwLineBreakClear
@@ -46,7 +48,7 @@ class SW_DLLPUBLIC SwFormatLineBreak final : public 
SfxEnumItem<SwLineBreakClear
     /// The SwTextAttr that knows the position of the line break in the doc 
model.
     SwTextLineBreak* m_pTextAttr;
 
-    css::uno::WeakReference<css::text::XTextContent> m_wXLineBreak;
+    unotools::WeakReference<SwXLineBreak> m_wXLineBreak;
 
     SwFormatLineBreak& operator=(const SwFormatLineBreak& rLineBreak) = delete;
 
@@ -71,15 +73,9 @@ public:
 
     void SetTextLineBreak(SwTextLineBreak* pTextAttr) { m_pTextAttr = 
pTextAttr; }
 
-    css::uno::WeakReference<css::text::XTextContent> const& GetXTextContent() 
const
-    {
-        return m_wXLineBreak;
-    }
+    unotools::WeakReference<SwXLineBreak> const& GetXTextContent() const { 
return m_wXLineBreak; }
 
-    void SetXLineBreak(css::uno::Reference<css::text::XTextContent> const& 
xLineBreak)
-    {
-        m_wXLineBreak = xLineBreak;
-    }
+    void SetXLineBreak(rtl::Reference<SwXLineBreak> const& xLineBreak);
 
     void dumpAsXml(xmlTextWriterPtr pWriter) const override;
 };
diff --git a/sw/inc/ndtxt.hxx b/sw/inc/ndtxt.hxx
index fd64aaa8158b..c80174918b71 100644
--- a/sw/inc/ndtxt.hxx
+++ b/sw/inc/ndtxt.hxx
@@ -32,6 +32,7 @@
 #include "paratr.hxx"
 
 #include <sfx2/Metadatable.hxx>
+#include <unotools/weakref.hxx>
 #include <o3tl/sorted_vector.hxx>
 #include <memory>
 #include <vector>
@@ -41,6 +42,7 @@ class SfxHint;
 class SwNumRule;
 class SwNodeNum;
 class SvxLRSpaceItem;
+class SwXParagraph;
 
 namespace utl {
     class TransliterationWrapper;
@@ -124,7 +126,7 @@ class SW_DLLPUBLIC SwTextNode final
 
     std::optional< OUString > m_oNumStringCache;
 
-    css::uno::WeakReference<css::text::XTextContent> m_wXParagraph;
+    unotools::WeakReference<SwXParagraph> m_wXParagraph;
 
     // DrawingLayer FillAttributes in a preprocessed form for primitive usage
     drawinglayer::attribute::SdrAllFillAttributesHelperPtr  maFillAttributes;
@@ -800,10 +802,9 @@ public:
 
     bool IsFirstOfNumRule(SwRootFrame const& rLayout) const;
 
-    SAL_DLLPRIVATE css::uno::WeakReference<css::text::XTextContent> const& 
GetXParagraph() const
+    SAL_DLLPRIVATE unotools::WeakReference<SwXParagraph> const& 
GetXParagraph() const
             { return m_wXParagraph; }
-    SAL_DLLPRIVATE void 
SetXParagraph(css::uno::Reference<css::text::XTextContent> const& xParagraph)
-            { m_wXParagraph = xParagraph; }
+    SAL_DLLPRIVATE void SetXParagraph(rtl::Reference<SwXParagraph> const& 
xParagraph);
 
     /// sfx2::Metadatable
     virtual ::sfx2::IXmlIdRegistry& GetRegistry() override;
diff --git a/sw/inc/section.hxx b/sw/inc/section.hxx
index 67609057b13c..5600ecc3dc06 100644
--- a/sw/inc/section.hxx
+++ b/sw/inc/section.hxx
@@ -28,6 +28,7 @@
 #include <svl/listener.hxx>
 #include <sfx2/lnkbase.hxx>
 #include <sfx2/Metadatable.hxx>
+#include <unotools/weakref.hxx>
 
 #include "frmfmt.hxx"
 #include <vector>
@@ -38,6 +39,7 @@ class SwSection;
 class SwSectionNode;
 class SwTOXBase;
 class SwServerObject;
+class SwXTextSection;
 
 typedef std::vector<SwSection*> SwSections;
 
@@ -276,7 +278,7 @@ class SW_DLLPUBLIC SwSectionFormat final
         in case of an index, both a SwXDocumentIndex and a SwXTextSection
         register at this SwSectionFormat, so we need to have two refs.
      */
-    css::uno::WeakReference<css::text::XTextSection> m_wXTextSection;
+    unotools::WeakReference<SwXTextSection> m_wXTextSection;
 
     SAL_DLLPRIVATE void UpdateParent();      // Parent has been changed.
 
@@ -317,10 +319,9 @@ public:
     // Is section a valid one for global document?
     const SwSection* GetGlobalDocSection() const;
 
-    SAL_DLLPRIVATE css::uno::WeakReference<css::text::XTextSection> const& 
GetXTextSection() const
+    SAL_DLLPRIVATE unotools::WeakReference<SwXTextSection> const& 
GetXTextSection() const
             { return m_wXTextSection; }
-    SAL_DLLPRIVATE void 
SetXTextSection(css::uno::Reference<css::text::XTextSection> const& 
xTextSection)
-            { m_wXTextSection = xTextSection; }
+    SAL_DLLPRIVATE void SetXTextSection(rtl::Reference<SwXTextSection> const& 
xTextSection);
 
     // sfx2::Metadatable
     virtual ::sfx2::IXmlIdRegistry& GetRegistry() override;
diff --git a/sw/inc/tox.hxx b/sw/inc/tox.hxx
index f4e47cbbf6a6..551ca829a5e5 100644
--- a/sw/inc/tox.hxx
+++ b/sw/inc/tox.hxx
@@ -29,6 +29,7 @@
 #include <sal/log.hxx>
 #include <svl/listener.hxx>
 #include <svl/poolitem.hxx>
+#include <unotools/weakref.hxx>
 #include <com/sun/star/text/XDocumentIndexMark.hpp>
 
 #include "calbck.hxx"
@@ -42,7 +43,7 @@ class SwTextTOXMark;
 class SwDoc;
 class SwRootFrame;
 class SwContentFrame;
-
+class SwXDocumentIndexMark;
 
 typedef std::vector<SwTOXMark*> SwTOXMarks;
 
@@ -101,7 +102,7 @@ class SW_DLLPUBLIC SwTOXMark final
     bool    m_bAutoGenerated;     // generated using a concordance file
     bool    m_bMainEntry;         // main entry emphasized by character style
 
-    css::uno::WeakReference<css::text::XDocumentIndexMark> 
m_wXDocumentIndexMark;
+    unotools::WeakReference<SwXDocumentIndexMark> m_wXDocumentIndexMark;
 
     SwTOXMark();                    // to create the default attribute in 
InitCore
 
@@ -159,10 +160,10 @@ public:
     const SwTextTOXMark* GetTextTOXMark() const   { return m_pTextAttr; }
           SwTextTOXMark* GetTextTOXMark()         { return m_pTextAttr; }
 
-    SAL_DLLPRIVATE css::uno::WeakReference<css::text::XDocumentIndexMark> 
const& GetXTOXMark() const
+    SAL_DLLPRIVATE unotools::WeakReference<SwXDocumentIndexMark> const& 
GetXTOXMark() const
             { return m_wXDocumentIndexMark; }
-    SAL_DLLPRIVATE void 
SetXTOXMark(css::uno::Reference<css::text::XDocumentIndexMark> const& xMark)
-            { m_wXDocumentIndexMark = xMark; }
+    SAL_DLLPRIVATE void SetXTOXMark(rtl::Reference<SwXDocumentIndexMark> 
const& xMark);
+
     void RegisterToTOXType( SwTOXType& rMark );
 
     static constexpr OUStringLiteral S_PAGE_DELI = u", ";
diff --git a/sw/inc/unoframe.hxx b/sw/inc/unoframe.hxx
index fd976ae12260..de6f63887f02 100644
--- a/sw/inc/unoframe.hxx
+++ b/sw/inc/unoframe.hxx
@@ -90,8 +90,8 @@ protected:
     SwXFrame(SwFrameFormat& rFrameFormat, FlyCntType eSet,
                 const SfxItemPropertySet*    pPropSet);
 
-    template<class Interface, class Impl>
-    static css::uno::Reference<Interface>
+    template<class Impl>
+    static rtl::Reference<Impl>
     CreateXFrame(SwDoc & rDoc, SwFrameFormat *const pFrameFormat);
 
 public:
@@ -187,7 +187,7 @@ class SwXTextFrame final : public SwXTextFrameBaseClass,
     SwXTextFrame(SwFrameFormat& rFormat);
 
 public:
-    static SW_DLLPUBLIC css::uno::Reference<css::text::XTextFrame>
+    static SW_DLLPUBLIC rtl::Reference<SwXTextFrame>
             CreateXTextFrame(SwDoc & rDoc, SwFrameFormat * pFrameFormat);
 
     // FIXME: EVIL HACK:  make available for SwXFrame::attachToRange
@@ -195,14 +195,14 @@ public:
 
     virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType 
) override;
     virtual void SAL_CALL acquire(  ) noexcept override;
-    virtual void SAL_CALL release(  ) noexcept override;
+    virtual SW_DLLPUBLIC void SAL_CALL release(  ) noexcept override;
 
     //XTypeProvider
     virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes(  ) 
override;
     virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId(  ) 
override;
 
     //XTextFrame
-    virtual css::uno::Reference< css::text::XText >  SAL_CALL getText() 
override;
+    virtual SW_DLLPUBLIC css::uno::Reference< css::text::XText >  SAL_CALL 
getText() override;
 
     //XText
     virtual css::uno::Reference< css::text::XTextCursor >  SAL_CALL 
createTextCursor() override;
@@ -236,7 +236,8 @@ public:
     virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< 
sal_Int8 >& aIdentifier ) override;
 
     //XPropertySet
-    virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& 
PropertyName ) override;
+    virtual SW_DLLPUBLIC css::uno::Any SAL_CALL getPropertyValue( const 
OUString& PropertyName ) override;
+    using SwXFrame::setPropertyValue;
 };
 
 typedef cppu::ImplInheritanceHelper
@@ -255,7 +256,7 @@ class SwXTextGraphicObject final : public 
SwXTextGraphicObjectBaseClass
 
 public:
 
-    static css::uno::Reference<css::text::XTextContent>
+    static rtl::Reference<SwXTextGraphicObject>
         CreateXTextGraphicObject(SwDoc & rDoc, SwFrameFormat * pFrameFormat);
 
     //XServiceInfo
@@ -286,7 +287,7 @@ class SwXTextEmbeddedObject final : public 
SwXTextEmbeddedObjectBaseClass
 
 public:
 
-    static css::uno::Reference<css::text::XTextContent>
+    static rtl::Reference<SwXTextEmbeddedObject>
         CreateXTextEmbeddedObject(SwDoc & rDoc, SwFrameFormat * pFrameFormat);
 
     //XEmbeddedObjectSupplier2
diff --git a/sw/inc/unoparagraph.hxx b/sw/inc/unoparagraph.hxx
index dc4d22f896cd..82540afdc58b 100644
--- a/sw/inc/unoparagraph.hxx
+++ b/sw/inc/unoparagraph.hxx
@@ -80,7 +80,7 @@ private:
 
 public:
 
-    static css::uno::Reference<css::text::XTextContent>
+    static rtl::Reference<SwXParagraph>
         CreateXParagraph(SwDoc & rDoc, SwTextNode * pTextNode,
             css::uno::Reference< css::text::XText>
             const& xParentText = nullptr,
diff --git a/sw/inc/unotbl.hxx b/sw/inc/unotbl.hxx
index f4ab9ef81cb1..3522beb6b998 100644
--- a/sw/inc/unotbl.hxx
+++ b/sw/inc/unotbl.hxx
@@ -274,7 +274,7 @@ private:
     virtual ~SwXTextTable() override;
 
 public:
-    static css::uno::Reference<css::text::XTextTable>
+    static rtl::Reference<SwXTextTable>
             CreateXTextTable(SwFrameFormat * pFrameFormat);
 
     SW_DLLPUBLIC static const css::uno::Sequence< sal_Int8 > & 
getUnoTunnelId();
diff --git a/sw/inc/unotextbodyhf.hxx b/sw/inc/unotextbodyhf.hxx
index 99887c6beb5c..390adaead265 100644
--- a/sw/inc/unotextbodyhf.hxx
+++ b/sw/inc/unotextbodyhf.hxx
@@ -31,6 +31,7 @@
 class SwDoc;
 class SwFrameFormat;
 class SwXTextCursor;
+struct SwXParagraphEnumeration;
 
 typedef ::cppu::WeakAggImplHelper2
 <   css::lang::XServiceInfo
@@ -80,6 +81,7 @@ public:
     // XEnumerationAccess
     virtual css::uno::Reference< css::container::XEnumeration >  SAL_CALL
         createEnumeration() override;
+    rtl::Reference< SwXParagraphEnumeration > createParagraphEnumeration();
 
     // XSimpleText
     virtual css::uno::Reference< css::text::XTextCursor >  SAL_CALL
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index dc022d34ccc7..94abaac25607 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -225,6 +225,7 @@ public:
 
     //XTextDocument
     virtual css::uno::Reference< css::text::XText >  SAL_CALL getText() 
override;
+    rtl::Reference< SwXBodyText > getBodyText();
     virtual void SAL_CALL reformat() override;
 
     //XModel
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index d6cd15a2e239..cd7e58e929ef 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -1244,16 +1244,15 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, TestTdf137025)
     // Check the textbox as well:
     auto xTxFrm = SwXTextFrame::CreateXTextFrame(*pFrameFormat->GetDoc(), 
pFrameFormat);
     CPPUNIT_ASSERT(xTxFrm);
-    uno::Reference<beans::XPropertySet> xFrameProps(xTxFrm, uno::UNO_QUERY);
 
     const tools::Long nFrameLeftPaddng
-        = 
xFrameProps->getPropertyValue("LeftBorderDistance").get<tools::Long>();
+        = xTxFrm->getPropertyValue("LeftBorderDistance").get<tools::Long>();
     const tools::Long nFrameRightPaddng
-        = 
xFrameProps->getPropertyValue("RightBorderDistance").get<tools::Long>();
+        = xTxFrm->getPropertyValue("RightBorderDistance").get<tools::Long>();
     const tools::Long nFrameTopPaddng
-        = 
xFrameProps->getPropertyValue("TopBorderDistance").get<tools::Long>();
+        = xTxFrm->getPropertyValue("TopBorderDistance").get<tools::Long>();
     const tools::Long nFrameBottomPaddng
-        = 
xFrameProps->getPropertyValue("BottomBorderDistance").get<tools::Long>();
+        = xTxFrm->getPropertyValue("BottomBorderDistance").get<tools::Long>();
 
     // Check if the shape and frame have different setting
     CPPUNIT_ASSERT_EQUAL(nLPaddng, nFrameLeftPaddng);
diff --git a/sw/source/core/crsr/bookmark.cxx b/sw/source/core/crsr/bookmark.cxx
index a33cb1c1eab0..ac7f9fe2c8a3 100644
--- a/sw/source/core/crsr/bookmark.cxx
+++ b/sw/source/core/crsr/bookmark.cxx
@@ -280,6 +280,9 @@ namespace sw::mark
         }
     }
 
+    void MarkBase::SetXBookmark(rtl::Reference<SwXBookmark> const& xBkmk)
+    { m_wXBookmark = xBkmk.get(); }
+
     // For fieldmarks, the CH_TXT_ATR_FIELDSTART and CH_TXT_ATR_FIELDEND
     // themselves are part of the covered range. This is guaranteed by
     // TextFieldmark::InitDoc/lcl_AssureFieldMarksSet.
@@ -359,7 +362,7 @@ namespace sw::mark
         auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint);
         if(RES_REMOVE_UNO_OBJECT == pLegacy->GetWhich())
         {   // invalidate cached uno object
-            SetXBookmark(uno::Reference<text::XTextContent>(nullptr));
+            SetXBookmark(nullptr);
         }
     }
 
@@ -494,7 +497,7 @@ namespace sw::mark
     {
         SwDoc& rDoc( GetMarkPos().GetDoc() );
         const uno::Reference< rdf::XMetadatable> xMeta(
-                SwXBookmark::CreateXBookmark(rDoc, this), uno::UNO_QUERY);
+                SwXBookmark::CreateXBookmark(rDoc, this) );
         return xMeta;
     }
 
diff --git a/sw/source/core/doc/rdfhelper.cxx b/sw/source/core/doc/rdfhelper.cxx
index 651a899ff157..c06126830967 100644
--- a/sw/source/core/doc/rdfhelper.cxx
+++ b/sw/source/core/doc/rdfhelper.cxx
@@ -201,13 +201,13 @@ void SwRDFHelper::cloneStatements(const 
css::uno::Reference<css::frame::XModel>&
 
 std::map<OUString, OUString> SwRDFHelper::getTextNodeStatements(const 
OUString& rType, SwTextNode& rTextNode)
 {
-    uno::Reference<rdf::XResource> 
xTextNode(SwXParagraph::CreateXParagraph(rTextNode.GetDoc(), &rTextNode), 
uno::UNO_QUERY);
+    uno::Reference<rdf::XResource> 
xTextNode(SwXParagraph::CreateXParagraph(rTextNode.GetDoc(), &rTextNode));
     return getStatements(rTextNode.GetDoc().GetDocShell()->GetBaseModel(), 
rType, xTextNode);
 }
 
 void SwRDFHelper::addTextNodeStatement(const OUString& rType, const OUString& 
rPath, SwTextNode& rTextNode, const OUString& rKey, const OUString& rValue)
 {
-    uno::Reference<rdf::XResource> 
xSubject(SwXParagraph::CreateXParagraph(rTextNode.GetDoc(), &rTextNode), 
uno::UNO_QUERY);
+    uno::Reference<rdf::XResource> 
xSubject(SwXParagraph::CreateXParagraph(rTextNode.GetDoc(), &rTextNode));
     addStatement(rTextNode.GetDoc().GetDocShell()->GetBaseModel(), rType, 
rPath, xSubject, rKey, rValue);
 }
 
@@ -222,7 +222,7 @@ void SwRDFHelper::removeTextNodeStatement(const OUString& 
rType, SwTextNode& rTe
 
     uno::Reference<rdf::XURI> xGraphName = aGraphNames[0];
     uno::Reference<rdf::XNamedGraph> xGraph = 
xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName);
-    uno::Reference<rdf::XResource> 
xSubject(SwXParagraph::CreateXParagraph(rTextNode.GetDoc(), &rTextNode), 
uno::UNO_QUERY);
+    uno::Reference<rdf::XResource> 
xSubject(SwXParagraph::CreateXParagraph(rTextNode.GetDoc(), &rTextNode));
     uno::Reference<rdf::XURI> xKey = rdf::URI::create(xComponentContext, rKey);
     uno::Reference<rdf::XLiteral> xValue = 
rdf::Literal::create(xComponentContext, rValue);
     xGraph->removeStatements(xSubject, xKey, xValue);
@@ -246,7 +246,7 @@ void SwRDFHelper::updateTextNodeStatement(const OUString& 
rType, const OUString&
     }
 
     uno::Reference<rdf::XNamedGraph> xGraph = 
xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName);
-    uno::Reference<rdf::XResource> 
xSubject(SwXParagraph::CreateXParagraph(rTextNode.GetDoc(), &rTextNode), 
uno::UNO_QUERY);
+    uno::Reference<rdf::XResource> 
xSubject(SwXParagraph::CreateXParagraph(rTextNode.GetDoc(), &rTextNode));
     uno::Reference<rdf::XURI> xKey = rdf::URI::create(xComponentContext, rKey);
 
     if (aGraphNames.hasElements())
diff --git a/sw/source/core/doc/textboxhelper.cxx 
b/sw/source/core/doc/textboxhelper.cxx
index 674b22b3f4d4..ec8a8ec21fc8 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -468,7 +468,9 @@ static void lcl_queryInterface(const SwFrameFormat* pShape, 
uno::Any& rAny, SdrO
         = SwTextBoxHelper::getOtherTextBoxFormat(pShape, RES_DRAWFRMFMT, pObj))
     {
         uno::Reference<T> const xInterface(
-            SwXTextFrame::CreateXTextFrame(*pFormat->GetDoc(), pFormat), 
uno::UNO_QUERY);
+            static_cast<cppu::OWeakObject*>(
+                SwXTextFrame::CreateXTextFrame(*pFormat->GetDoc(), 
pFormat).get()),
+            uno::UNO_QUERY);
         rAny <<= xInterface;
     }
 }
@@ -707,8 +709,8 @@ css::uno::Any SwTextBoxHelper::getProperty(SwFrameFormat 
const* pShape, const OU
     if (!pFormat)
         return {};
 
-    uno::Reference<beans::XPropertySet> const xPropertySet(
-        SwXTextFrame::CreateXTextFrame(*pFormat->GetDoc(), pFormat), 
uno::UNO_QUERY);
+    rtl::Reference<SwXTextFrame> xPropertySet
+        = SwXTextFrame::CreateXTextFrame(*pFormat->GetDoc(), pFormat);
 
     return xPropertySet->getPropertyValue(rPropName);
 }
@@ -943,8 +945,8 @@ void SwTextBoxHelper::syncProperty(SwFrameFormat* pShape, 
sal_uInt16 nWID, sal_u
         }
     }
     auto aGuard = SwTextBoxLockGuard(*pShape->GetOtherTextBoxFormats());
-    uno::Reference<beans::XPropertySet> const xPropertySet(
-        SwXTextFrame::CreateXTextFrame(*pFormat->GetDoc(), pFormat), 
uno::UNO_QUERY);
+    rtl::Reference<SwXTextFrame> const xPropertySet
+        = SwXTextFrame::CreateXTextFrame(*pFormat->GetDoc(), pFormat);
     xPropertySet->setPropertyValue(aPropertyName, aValue);
 }
 
@@ -1222,8 +1224,8 @@ bool SwTextBoxHelper::changeAnchor(SwFrameFormat* pShape, 
SdrObject* pObj)
         {
             auto aGuard = 
SwTextBoxLockGuard(*pShape->GetOtherTextBoxFormats());
             ::sw::UndoGuard const 
UndoGuard(pShape->GetDoc()->GetIDocumentUndoRedo());
-            uno::Reference<beans::XPropertySet> const xPropertySet(
-                SwXTextFrame::CreateXTextFrame(*pFormat->GetDoc(), pFormat), 
uno::UNO_QUERY);
+            rtl::Reference<SwXTextFrame> const xPropertySet
+                = SwXTextFrame::CreateXTextFrame(*pFormat->GetDoc(), pFormat);
             if (pOldCnt && rNewAnch.GetAnchorId() == RndStdIds::FLY_AT_PAGE
                 && rNewAnch.GetPageNum())
             {
diff --git a/sw/source/core/docnode/section.cxx 
b/sw/source/core/docnode/section.cxx
index c35a614f8851..7510bd886604 100644
--- a/sw/source/core/docnode/section.cxx
+++ b/sw/source/core/docnode/section.cxx
@@ -795,10 +795,15 @@ void SwSectionFormat::SwClientNotify(const SwModify& 
rMod, const SfxHint& rHint)
 
     if (pOld && (RES_REMOVE_UNO_OBJECT == pOld->Which()))
     {   // invalidate cached uno object
-        SetXTextSection(uno::Reference<text::XTextSection>(nullptr));
+        SetXTextSection(nullptr);
     }
 }
 
+void SwSectionFormat::SetXTextSection(rtl::Reference<SwXTextSection> const& 
xTextSection)
+{
+    m_wXTextSection = xTextSection.get();
+}
+
 // Get info from the Format
 bool SwSectionFormat::GetInfo( SfxPoolItem& rInfo ) const
 {
@@ -976,9 +981,8 @@ SwSectionFormat::MakeUnoObject()
     SwSection *const pSection( GetSection() );
     if (pSection)
     {
-        xMeta.set(  SwXTextSection::CreateXTextSection(this,
-                        SectionType::ToxHeader == pSection->GetType()),
-                    uno::UNO_QUERY );
+        xMeta = SwXTextSection::CreateXTextSection(this,
+                        SectionType::ToxHeader == pSection->GetType());
     }
     return xMeta;
 }
diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx
index aade2988c94b..9ea61b6e5462 100644
--- a/sw/source/core/edit/edfcol.cxx
+++ b/sw/source/core/edit/edfcol.cxx
@@ -94,6 +94,8 @@
 #include <UndoParagraphSignature.hxx>
 #include <txtatr.hxx>
 #include <fmtmeta.hxx>
+#include <unotxdoc.hxx>
+#include <unotextbodyhf.hxx>
 
 #include <tools/diagnose_ex.h>
 #include <IDocumentRedlineAccess.hxx>
@@ -1276,8 +1278,8 @@ void 
SwEditShell::ApplyParagraphClassification(std::vector<svx::ClassificationRe
     });
 
     uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
-    uno::Reference<text::XTextContent> xParent = 
SwXParagraph::CreateXParagraph(pNode->GetDoc(), pNode);
-    lcl_ApplyParagraphClassification(GetDoc(), xModel, xParent, 
css::uno::Reference<css::rdf::XResource>(xParent, uno::UNO_QUERY), 
std::move(aResults));
+    rtl::Reference<SwXParagraph> xParent = 
SwXParagraph::CreateXParagraph(pNode->GetDoc(), pNode);
+    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)
@@ -1918,14 +1920,11 @@ void 
SwEditShell::RestoreMetadataFieldsAndValidateParagraphSignatures()
         });
 
     uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
-    const uno::Reference<text::XTextDocument> xDoc(xModel, uno::UNO_QUERY);
-    uno::Reference<text::XText> xParent = xDoc->getText();
-    uno::Reference<container::XEnumerationAccess> 
xParagraphEnumerationAccess(xParent, uno::UNO_QUERY);
-    if (!xParagraphEnumerationAccess.is())
-        return;
-    uno::Reference<container::XEnumeration> xParagraphs = 
xParagraphEnumerationAccess->createEnumeration();
-    if (!xParagraphs.is())
+    const rtl::Reference<SwXTextDocument> 
xDoc(dynamic_cast<SwXTextDocument*>(xModel.get()));
+    rtl::Reference<SwXBodyText> xBodyText = xDoc->getBodyText();
+    if (!xBodyText.is())
         return;
+    rtl::Reference<SwXParagraphEnumeration> xParagraphs = 
xBodyText->createParagraphEnumeration();
 
     static constexpr OUStringLiteral sBlank(u"");
     const sfx::ClassificationKeyCreator 
aKeyCreator(SfxClassificationHelper::getPolicyType());
@@ -2116,11 +2115,10 @@ static OUString 
lcl_GetHighestClassificationParagraphClass(SwPaM* pCursor)
     sfx::ClassificationKeyCreator 
aKeyCreator(SfxClassificationHelper::getPolicyType());
 
     uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
-    const uno::Reference< text::XTextDocument > xDoc(xModel, uno::UNO_QUERY);
-    uno::Reference<text::XText> xParent = xDoc->getText();
+    const rtl::Reference<SwXTextDocument> 
xDoc(dynamic_cast<SwXTextDocument*>(xModel.get()));
+    rtl::Reference<SwXBodyText> xBodyText = xDoc->getBodyText();
 
-    uno::Reference<container::XEnumerationAccess> 
xParagraphEnumerationAccess(xParent, uno::UNO_QUERY);
-    uno::Reference<container::XEnumeration> xParagraphs = 
xParagraphEnumerationAccess->createEnumeration();
+    rtl::Reference<SwXParagraphEnumeration> xParagraphs = 
xBodyText->createParagraphEnumeration();
     while (xParagraphs->hasMoreElements())
     {
         uno::Reference<text::XTextContent> 
xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY);
diff --git a/sw/source/core/inc/bookmark.hxx b/sw/source/core/inc/bookmark.hxx
index a9c807063f4f..6e20feca5262 100644
--- a/sw/source/core/inc/bookmark.hxx
+++ b/sw/source/core/inc/bookmark.hxx
@@ -22,6 +22,7 @@
 #include <cppuhelper/weakref.hxx>
 #include <sfx2/Metadatable.hxx>
 #include <vcl/keycod.hxx>
+#include <unotools/weakref.hxx>
 #include <memory>
 #include <string_view>
 #include <com/sun/star/text/XTextContent.hpp>
@@ -38,6 +39,7 @@ class SwEditWin;
 class SwServerObject;
 class SvNumberFormatter;
 class SfxViewShell;
+class SwXBookmark;
 
 namespace sw::mark {
         class MarkBase
@@ -99,10 +101,9 @@ namespace sw::mark {
 
             virtual ~MarkBase() override;
 
-            const css::uno::WeakReference< css::text::XTextContent> & 
GetXBookmark() const
+            const unotools::WeakReference<SwXBookmark> & GetXBookmark() const
                     { return m_wXBookmark; }
-            void SetXBookmark(css::uno::Reference< css::text::XTextContent> 
const& xBkmk)
-                    { m_wXBookmark = xBkmk; }
+            void SetXBookmark(rtl::Reference<SwXBookmark> const& xBkmk);
 
         protected:
             // SwClient
@@ -114,7 +115,7 @@ namespace sw::mark {
             OUString m_aName;
             static OUString GenerateNewName(std::u16string_view rPrefix);
 
-            css::uno::WeakReference< css::text::XTextContent> m_wXBookmark;
+            unotools::WeakReference<SwXBookmark> m_wXBookmark;
         };
 
         class NavigatorReminder final
diff --git a/sw/source/core/inc/unobookmark.hxx 
b/sw/source/core/inc/unobookmark.hxx
index 09ccb69e6da4..740e11865a2d 100644
--- a/sw/source/core/inc/unobookmark.hxx
+++ b/sw/source/core/inc/unobookmark.hxx
@@ -85,7 +85,7 @@ protected:
 
 public:
 
-    static css::uno::Reference< css::text::XTextContent>
+    static rtl::Reference<SwXBookmark>
         CreateXBookmark(SwDoc & rDoc, ::sw::mark::IMark * pBookmark);
 
     /// @return IMark for this, but only if it lives in pDoc
@@ -201,7 +201,7 @@ class SwXFieldmark final
     SwXFieldmark(bool isReplacementObject, SwDoc* pDoc);
 
 public:
-    static css::uno::Reference<css::text::XTextContent>
+    static rtl::Reference<SwXBookmark>
         CreateXFieldmark(SwDoc & rDoc, ::sw::mark::IMark * pMark,
                 bool isReplacementObject = false);
 
diff --git a/sw/source/core/inc/unocontentcontrol.hxx 
b/sw/source/core/inc/unocontentcontrol.hxx
index c34f57b4ead0..3ba4b8e3d2b3 100644
--- a/sw/source/core/inc/unocontentcontrol.hxx
+++ b/sw/source/core/inc/unocontentcontrol.hxx
@@ -71,13 +71,13 @@ protected:
     SwXContentControl(SwDoc* pDoc);
 
 public:
-    static css::uno::Reference<css::text::XTextContent>
+    static rtl::Reference<SwXContentControl>
     CreateXContentControl(SwContentControl& rContentControl,
                           const css::uno::Reference<css::text::XText>& 
xParentText = nullptr,
                           std::unique_ptr<const TextRangeList_t>&& pPortions
                           = std::unique_ptr<const TextRangeList_t>());
 
-    static css::uno::Reference<css::text::XTextContent> 
CreateXContentControl(SwDoc& rDoc);
+    static rtl::Reference<SwXContentControl> CreateXContentControl(SwDoc& 
rDoc);
 
     /// Initializes params with position of the attribute content (without 
CH_TXTATR).
     bool SetContentRange(SwTextNode*& rpNode, sal_Int32& rStart, sal_Int32& 
rEnd) const;
diff --git a/sw/source/core/inc/unofield.hxx b/sw/source/core/inc/unofield.hxx
index b6b281cec582..7ec3d45b9ff9 100644
--- a/sw/source/core/inc/unofield.hxx
+++ b/sw/source/core/inc/unofield.hxx
@@ -60,7 +60,7 @@ private:
 
 public:
 
-    static css::uno::Reference<css::beans::XPropertySet>
+    static rtl::Reference<SwXFieldMaster>
         CreateXFieldMaster(SwDoc * pDoc, SwFieldType * pType,
                 SwFieldIds nResId = SwFieldIds::Unknown);
 
@@ -145,7 +145,7 @@ public:
     static void TransmuteLeadToInputField(SwSetExpField & rField);
 
     /// @return an SwXTextField, either an already existing one or a new one
-    static css::uno::Reference< css::text::XTextField>
+    static rtl::Reference<SwXTextField>
         CreateXTextField(SwDoc * pDoc, SwFormatField const* pFormat,
                 SwServiceType nServiceId = SwServiceType::Invalid);
 
diff --git a/sw/source/core/inc/unofootnote.hxx 
b/sw/source/core/inc/unofootnote.hxx
index b30c89d8b542..0303ee12335b 100644
--- a/sw/source/core/inc/unofootnote.hxx
+++ b/sw/source/core/inc/unofootnote.hxx
@@ -61,7 +61,7 @@ class SwXFootnote final
 
 public:
 
-    static css::uno::Reference<css::text::XFootnote>
+    static rtl::Reference<SwXFootnote>
         CreateXFootnote(SwDoc & rDoc, SwFormatFootnote * pFootnoteFormat,
                 bool isEndnote = false);
 
diff --git a/sw/source/core/inc/unoidx.hxx b/sw/source/core/inc/unoidx.hxx
index d7db053734f5..8b1b67fc6771 100644
--- a/sw/source/core/inc/unoidx.hxx
+++ b/sw/source/core/inc/unoidx.hxx
@@ -70,7 +70,7 @@ private:
 
 public:
 
-    static css::uno::Reference< css::text::XDocumentIndex>
+    static rtl::Reference<SwXDocumentIndex>
         CreateXDocumentIndex(SwDoc & rDoc, SwTOXBaseSection * pSection,
                 TOXTypes eTypes = TOX_INDEX);
 
@@ -168,7 +168,7 @@ private:
 
 public:
 
-    static css::uno::Reference< css::text::XDocumentIndexMark>
+    static rtl::Reference<SwXDocumentIndexMark>
         CreateXDocumentIndexMark(SwDoc & rDoc,
             SwTOXMark * pMark, TOXTypes eType = TOX_INDEX);
 
diff --git a/sw/source/core/inc/unolinebreak.hxx 
b/sw/source/core/inc/unolinebreak.hxx
index 46968556633c..b1a26e604ad0 100644
--- a/sw/source/core/inc/unolinebreak.hxx
+++ b/sw/source/core/inc/unolinebreak.hxx
@@ -45,8 +45,7 @@ class SwXLineBreak final
     ~SwXLineBreak() override;
 
 public:
-    static css::uno::Reference<css::text::XTextContent>
-    CreateXLineBreak(SwFormatLineBreak* pLineBreakFormat);
+    static rtl::Reference<SwXLineBreak> CreateXLineBreak(SwFormatLineBreak* 
pLineBreakFormat);
 
     // XPropertySet
     css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL 
getPropertySetInfo() override;
diff --git a/sw/source/core/inc/unometa.hxx b/sw/source/core/inc/unometa.hxx
index ca298fcd8f63..d662c1adba36 100644
--- a/sw/source/core/inc/unometa.hxx
+++ b/sw/source/core/inc/unometa.hxx
@@ -90,13 +90,13 @@ protected:
 
 public:
 
-    static css::uno::Reference< css::rdf::XMetadatable >
+    static rtl::Reference<SwXMeta>
         CreateXMeta(
             ::sw::Meta & rMeta,
             css::uno::Reference< css::text::XText> const& xParentText = 
nullptr,
             std::unique_ptr<TextRangeList_t const> && pPortions = 
std::unique_ptr<TextRangeList_t const>());
 
-    static css::uno::Reference<css::rdf::XMetadatable>
+    static rtl::Reference<SwXMeta>
         CreateXMeta(SwDoc & rDoc, bool isField);
 
     /// init params with position of the attribute content (w/out CH_TXTATR)
@@ -198,7 +198,7 @@ private:
 
     virtual ~SwXMetaField() override;
 
-    friend css::uno::Reference< css::rdf::XMetadatable >
+    friend rtl::Reference<SwXMeta>
         SwXMeta::CreateXMeta(::sw::Meta &,
             css::uno::Reference< css::text::XText> const&,
             std::unique_ptr<TextRangeList_t const> && pPortions);
@@ -207,7 +207,7 @@ private:
         css::uno::Reference< css::text::XText> const& xParentText,
         std::unique_ptr<TextRangeList_t const> pPortions);
 
-    friend css::uno::Reference<css::rdf::XMetadatable>
+    friend rtl::Reference<SwXMeta>
         SwXMeta::CreateXMeta(SwDoc &, bool);
 
     SwXMetaField(SwDoc *const pDoc);
diff --git a/sw/source/core/inc/unorefmark.hxx 
b/sw/source/core/inc/unorefmark.hxx
index 94d81dd28055..057de4f443da 100644
--- a/sw/source/core/inc/unorefmark.hxx
+++ b/sw/source/core/inc/unorefmark.hxx
@@ -56,7 +56,7 @@ private:
 
 public:
 
-    static css::uno::Reference<css::text::XTextContent>
+    static rtl::Reference<SwXReferenceMark>
         CreateXReferenceMark(SwDoc & rDoc, SwFormatRefMark * pMarkFormat);
 
     static const css::uno::Sequence< sal_Int8 >& getUnoTunnelId();
diff --git a/sw/source/core/inc/unosection.hxx 
b/sw/source/core/inc/unosection.hxx
index 2b12b7364235..a90732e4bd5c 100644
--- a/sw/source/core/inc/unosection.hxx
+++ b/sw/source/core/inc/unosection.hxx
@@ -64,7 +64,7 @@ public:
 
     SwSectionFormat*   GetFormat() const;
 
-    static css::uno::Reference< css::text::XTextSection >
+    static rtl::Reference< SwXTextSection >
         CreateXTextSection(SwSectionFormat *const pFormat,
                 const bool bIndexHeader = false);
 
diff --git a/sw/source/core/tox/tox.cxx b/sw/source/core/tox/tox.cxx
index f636d171238e..63d9d430d0ae 100644
--- a/sw/source/core/tox/tox.cxx
+++ b/sw/source/core/tox/tox.cxx
@@ -32,6 +32,7 @@
 #include <tox.hxx>
 #include <txtfrm.hxx>
 #include <txttxmrk.hxx>
+#include <unoidx.hxx>
 
 #include <optional>
 #include <sal/log.hxx>
@@ -133,6 +134,9 @@ SwTOXMark::~SwTOXMark()
 {
 }
 
+void SwTOXMark::SetXTOXMark(rtl::Reference<SwXDocumentIndexMark> const& xMark)
+{ m_wXDocumentIndexMark = xMark.get(); }
+
 void SwTOXMark::RegisterToTOXType(SwTOXType& rType)
 {
     SvtListener::EndListeningAll();
@@ -158,7 +162,7 @@ void SwTOXMark::Notify(const SfxHint& rHint)
         auto pLegacyHint = static_cast<const sw::LegacyModifyHint*>(&rHint);
         CallSwClientNotify(rHint);
         if (pLegacyHint->m_pOld && (RES_REMOVE_UNO_OBJECT == 
pLegacyHint->m_pOld->Which()))
-            
SetXTOXMark(css::uno::Reference<css::text::XDocumentIndexMark>(nullptr));
+            SetXTOXMark(nullptr);
     }
     else if (rHint.GetId() == SfxHintId::SwCollectTextMarks)
     {
diff --git a/sw/source/core/txtnode/atrfld.cxx 
b/sw/source/core/txtnode/atrfld.cxx
index 85d1eafc98c5..15de4fdcb9aa 100644
--- a/sw/source/core/txtnode/atrfld.cxx
+++ b/sw/source/core/txtnode/atrfld.cxx
@@ -27,6 +27,7 @@
 #include <docfld.hxx>
 #include <docufld.hxx>
 #include <doc.hxx>
+#include <unofield.hxx>
 
 #include <pam.hxx>
 #include <reffld.hxx>
@@ -769,4 +770,7 @@ SwTextAnnotationField::~SwTextAnnotationField()
            : nullptr;
 }
 
+void SwFormatField::SetXTextField(rtl::Reference<SwXTextField> const& 
xTextField)
+{ m_wXTextField = xTextField.get(); }
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/txtnode/atrftn.cxx 
b/sw/source/core/txtnode/atrftn.cxx
index 82485f4c5d22..bfc961bc7d3a 100644
--- a/sw/source/core/txtnode/atrftn.cxx
+++ b/sw/source/core/txtnode/atrftn.cxx
@@ -43,6 +43,7 @@
 #include <vcl/svapp.hxx>
 #include <unotextrange.hxx>
 #include <osl/diagnose.h>
+#include <unofootnote.hxx>
 
 namespace {
     /// Get a sorted list of the used footnote reference numbers.
@@ -134,6 +135,9 @@ SwFormatFootnote::SwFormatFootnote( bool bEndNote )
 {
 }
 
+void SwFormatFootnote::SetXFootnote(rtl::Reference<SwXFootnote> const& xNote)
+{ m_wXFootnote = xNote.get(); }
+
 bool SwFormatFootnote::operator==( const SfxPoolItem& rAttr ) const
 {
     assert(SfxPoolItem::operator==(rAttr));
@@ -160,7 +164,7 @@ void SwFormatFootnote::SwClientNotify(const SwModify&, 
const SfxHint& rHint)
     auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint);
     CallSwClientNotify(rHint);
     if(RES_REMOVE_UNO_OBJECT == pLegacy->GetWhich())
-        SetXFootnote(css::uno::Reference<css::text::XFootnote>(nullptr));
+        SetXFootnote(nullptr);
 }
 
 void SwFormatFootnote::InvalidateFootnote()
diff --git a/sw/source/core/txtnode/atrref.cxx 
b/sw/source/core/txtnode/atrref.cxx
index e281803050e3..167306efb706 100644
--- a/sw/source/core/txtnode/atrref.cxx
+++ b/sw/source/core/txtnode/atrref.cxx
@@ -22,6 +22,7 @@
 #include <hintids.hxx>
 #include <hints.hxx>
 #include <txtrfmrk.hxx>
+#include <unorefmark.hxx>
 
 SwFormatRefMark::~SwFormatRefMark( )
 {
@@ -43,6 +44,9 @@ SwFormatRefMark::SwFormatRefMark( const SwFormatRefMark& 
rAttr )
 {
 }
 
+void SwFormatRefMark::SetXRefMark(rtl::Reference<SwXReferenceMark> const& 
xMark)
+{ m_wXReferenceMark = xMark.get(); }
+
 bool SwFormatRefMark::operator==( const SfxPoolItem& rAttr ) const
 {
     assert(SfxPoolItem::operator==(rAttr));
@@ -61,7 +65,7 @@ void SwFormatRefMark::SwClientNotify(const SwModify&, const 
SfxHint& rHint)
     auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint);
     CallSwClientNotify(rHint);
     if(RES_REMOVE_UNO_OBJECT == pLegacy->GetWhich())
-        SetXRefMark(css::uno::Reference<css::text::XTextContent>(nullptr));
+        SetXRefMark(nullptr);
 }
 
 void SwFormatRefMark::InvalidateRefMark()
diff --git a/sw/source/core/txtnode/attrcontentcontrol.cxx 
b/sw/source/core/txtnode/attrcontentcontrol.cxx
index 6b7dac905de4..f809b1b26cc5 100644
--- a/sw/source/core/txtnode/attrcontentcontrol.cxx
+++ b/sw/source/core/txtnode/attrcontentcontrol.cxx
@@ -30,6 +30,7 @@
 #include <ndtxt.hxx>
 #include <textcontentcontrol.hxx>
 #include <doc.hxx>
+#include <unocontentcontrol.hxx>
 
 using namespace com::sun::star;
 
@@ -175,6 +176,11 @@ SwContentControl::SwContentControl(SwFormatContentControl* 
pFormat)
 
 SwContentControl::~SwContentControl() {}
 
+void SwContentControl::SetXContentControl(const 
rtl::Reference<SwXContentControl>& xContentCnotrol)
+{
+    m_wXContentControl = xContentCnotrol.get();
+}
+
 SwTextContentControl* SwContentControl::GetTextAttr() const
 {
     return m_pFormat ? m_pFormat->GetTextAttr() : nullptr;
@@ -210,7 +216,7 @@ void SwContentControl::SwClientNotify(const SwModify&, 
const SfxHint& rHint)
     if (pLegacy->GetWhich() == RES_REMOVE_UNO_OBJECT)
     {
         // Invalidate cached uno object.
-        SetXContentControl(uno::Reference<text::XTextContent>());
+        SetXContentControl(nullptr);
         GetNotifier().Broadcast(SfxHint(SfxHintId::Deinitializing));
     }
 }
diff --git a/sw/source/core/txtnode/attrlinebreak.cxx 
b/sw/source/core/txtnode/attrlinebreak.cxx
index 3f987f7e76cb..59d7c247e47b 100644
--- a/sw/source/core/txtnode/attrlinebreak.cxx
+++ b/sw/source/core/txtnode/attrlinebreak.cxx
@@ -28,6 +28,7 @@
 #include <textlinebreak.hxx>
 #include <ndtxt.hxx>
 #include <unotextrange.hxx>
+#include <unolinebreak.hxx>
 
 using namespace com::sun::star;
 
@@ -40,6 +41,11 @@ SwFormatLineBreak::SwFormatLineBreak(SwLineBreakClear eClear)
 
 SwFormatLineBreak::~SwFormatLineBreak() {}
 
+void SwFormatLineBreak::SetXLineBreak(rtl::Reference<SwXLineBreak> const& 
xLineBreak)
+{
+    m_wXLineBreak = xLineBreak.get();
+}
+
 bool SwFormatLineBreak::operator==(const SfxPoolItem& rAttr) const
 {
     assert(SfxPoolItem::operator==(rAttr));
@@ -59,7 +65,7 @@ void SwFormatLineBreak::SwClientNotify(const SwModify&, const 
SfxHint& rHint)
     CallSwClientNotify(rHint);
     if (RES_REMOVE_UNO_OBJECT == pLegacy->GetWhich())
     {
-        SetXLineBreak(css::uno::Reference<css::text::XTextContent>(nullptr));
+        SetXLineBreak(nullptr);
     }
 }
 
diff --git a/sw/source/core/txtnode/fmtatr2.cxx 
b/sw/source/core/txtnode/fmtatr2.cxx
index 67a55e28c9b5..6088866fca22 100644
--- a/sw/source/core/txtnode/fmtatr2.cxx
+++ b/sw/source/core/txtnode/fmtatr2.cxx
@@ -653,6 +653,8 @@ SwTextMeta * Meta::GetTextAttr() const
     return m_pFormat ? m_pFormat->GetTextAttr() : nullptr;
 }
 
+void Meta::SetXMeta(rtl::Reference<SwXMeta> const& xMeta)
+{ m_wXMeta = xMeta.get(); }
 
 void Meta::NotifyChangeTextNode(SwTextNode *const pTextNode)
 {
@@ -680,7 +682,7 @@ void Meta::SwClientNotify(const SwModify&, const SfxHint& 
rHint)
     GetNotifier().Broadcast(SfxHint(SfxHintId::DataChanged));
     if(RES_REMOVE_UNO_OBJECT == pLegacy->GetWhich())
     {   // invalidate cached uno object
-        SetXMeta(uno::Reference<rdf::XMetadatable>(nullptr));
+        SetXMeta(nullptr);
         GetNotifier().Broadcast(SfxHint(SfxHintId::Deinitializing));
     }
 }
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index 62d78bf87526..879faf170b09 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -5378,7 +5378,7 @@ void SwTextNode::TriggerNodeUpdate(const 
sw::LegacyModifyHint& rHint)
 
     if (pOldValue && (RES_REMOVE_UNO_OBJECT == pOldValue->Which()))
     {   // invalidate cached uno object
-        SetXParagraph(css::uno::Reference<css::text::XTextContent>(nullptr));
+        SetXParagraph(nullptr);
     }
 }
 
@@ -5400,7 +5400,7 @@ uno::Reference< rdf::XMetadatable >
 SwTextNode::MakeUnoObject()
 {
     const uno::Reference<rdf::XMetadatable> xMeta(
-            SwXParagraph::CreateXParagraph(GetDoc(), this), uno::UNO_QUERY);
+            SwXParagraph::CreateXParagraph(GetDoc(), this));
     return xMeta;
 }
 
@@ -5415,4 +5415,9 @@ drawinglayer::attribute::SdrAllFillAttributesHelperPtr 
SwTextNode::getSdrAllFill
     return maFillAttributes;
 }
 
+void SwTextNode::SetXParagraph(rtl::Reference<SwXParagraph> const & xParagraph)
+{
+    m_wXParagraph = xParagraph.get();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/unocore/unobkm.cxx 
b/sw/source/core/unocore/unobkm.cxx
index 456325d5f575..ca4c465ca551 100644
--- a/sw/source/core/unocore/unobkm.cxx
+++ b/sw/source/core/unocore/unobkm.cxx
@@ -44,7 +44,7 @@ class SwXBookmark::Impl
     : public SvtListener
 {
 public:
-    uno::WeakReference<uno::XInterface> m_wThis;
+    unotools::WeakReference<SwXBookmark> m_wThis;
     std::mutex m_Mutex; // just for OInterfaceContainerHelper3
     ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> 
m_EventListeners;
     SwDoc* m_pDoc;
@@ -87,7 +87,7 @@ void SwXBookmark::Impl::Notify(const SfxHint& rHint)
 void SwXBookmark::Impl::registerInMark(SwXBookmark& rThis,
         ::sw::mark::IMark* const pBkmk)
 {
-    const uno::Reference<text::XTextContent> xBookmark(&rThis);
+    const rtl::Reference<SwXBookmark> xBookmark(&rThis);
     if (pBkmk)
     {
         EndListeningAll();
@@ -116,7 +116,7 @@ void SwXBookmark::Impl::registerInMark(SwXBookmark& rThis,
     }
     m_pRegisteredBookmark = pBkmk;
     // need a permanent Reference to initialize m_wThis
-    m_wThis = xBookmark;
+    m_wThis = xBookmark.get();
 }
 
 void SwXBookmark::registerInMark(SwXBookmark & rThis,
@@ -154,14 +154,14 @@ SwXBookmark::~SwXBookmark()
 {
 }
 
-uno::Reference<text::XTextContent> SwXBookmark::CreateXBookmark(
+rtl::Reference<SwXBookmark> SwXBookmark::CreateXBookmark(
     SwDoc & rDoc,
     ::sw::mark::IMark *const pBookmark)
 {
     // #i105557#: do not iterate over the registered clients: race condition
     ::sw::mark::MarkBase *const pMarkBase(dynamic_cast< ::sw::mark::MarkBase * 
>(pBookmark));
     OSL_ENSURE(!pBookmark || pMarkBase, "CreateXBookmark: no MarkBase?");
-    uno::Reference<text::XTextContent> xBookmark;
+    rtl::Reference<SwXBookmark> xBookmark;
     if (pMarkBase)
     {
         xBookmark = pMarkBase->GetXBookmark();
@@ -683,7 +683,7 @@ uno::Reference<container::XNameContainer> 
SwXFieldmark::getParameters()
     return uno::Reference<container::XNameContainer>(new 
SwXFieldmarkParameters(pBkm));
 }
 
-uno::Reference<text::XTextContent>
+rtl::Reference<SwXBookmark>
 SwXFieldmark::CreateXFieldmark(SwDoc & rDoc, ::sw::mark::IMark *const pMark,
         bool const isReplacementObject)
 {
@@ -691,7 +691,7 @@ SwXFieldmark::CreateXFieldmark(SwDoc & rDoc, 
::sw::mark::IMark *const pMark,
     ::sw::mark::MarkBase *const pMarkBase(
         dynamic_cast< ::sw::mark::MarkBase * >(pMark));
     assert(!pMark || pMarkBase);
-    uno::Reference<text::XTextContent> xMark;
+    rtl::Reference<SwXBookmark> xMark;
     if (pMarkBase)
     {
         xMark = pMarkBase->GetXBookmark();
@@ -711,7 +711,7 @@ SwXFieldmark::CreateXFieldmark(SwDoc & rDoc, 
::sw::mark::IMark *const pMark,
         else
             pXBkmk = new SwXFieldmark(isReplacementObject, &rDoc);
 
-        xMark.set(static_cast<::cppu::OWeakObject*>(pXBkmk.get()), 
uno::UNO_QUERY); // work around ambiguous base
+        xMark = pXBkmk.get();
         pXBkmk->registerInMark(*pXBkmk, pMarkBase);
     }
     return xMark;
diff --git a/sw/source/core/unocore/unocoll.cxx 
b/sw/source/core/unocore/unocoll.cxx
index fe2043e37f7c..d4e1028534e7 100644
--- a/sw/source/core/unocore/unocoll.cxx
+++ b/sw/source/core/unocore/unocoll.cxx
@@ -522,39 +522,39 @@ SwXServiceProvider::MakeInstance(SwServiceType 
nObjectType, SwDoc & rDoc)
     {
         case  SwServiceType::TypeTextTable:
         {
-            xRet = SwXTextTable::CreateXTextTable(nullptr);
+            xRet = 
static_cast<cppu::OWeakObject*>(SwXTextTable::CreateXTextTable(nullptr).get());
         }
         break;
         case  SwServiceType::TypeTextFrame:
         {
-            xRet = SwXTextFrame::CreateXTextFrame(rDoc, nullptr);
+            xRet = 
static_cast<cppu::OWeakObject*>(SwXTextFrame::CreateXTextFrame(rDoc, 
nullptr).get());
         }
         break;
         case  SwServiceType::TypeGraphic  :
         case  SwServiceType::TypeTextGraphic /* #i47503# */ :
         {
-            xRet = SwXTextGraphicObject::CreateXTextGraphicObject(rDoc, 
nullptr);
+            xRet = 
static_cast<cppu::OWeakObject*>(SwXTextGraphicObject::CreateXTextGraphicObject(rDoc,
 nullptr).get());
 
         }
         break;
         case  SwServiceType::TypeOLE      :
         {
-            xRet = SwXTextEmbeddedObject::CreateXTextEmbeddedObject(rDoc, 
nullptr);
+            xRet = 
static_cast<cppu::OWeakObject*>(SwXTextEmbeddedObject::CreateXTextEmbeddedObject(rDoc,
 nullptr).get());
         }
         break;
         case  SwServiceType::TypeBookmark :
         {
-            xRet = SwXBookmark::CreateXBookmark(rDoc, nullptr);
+            xRet = 
static_cast<cppu::OWeakObject*>(SwXBookmark::CreateXBookmark(rDoc, 
nullptr).get());
         }
         break;
         case  SwServiceType::TypeFieldMark :
         {
-            xRet = SwXFieldmark::CreateXFieldmark(rDoc, nullptr);
+            xRet = 
static_cast<cppu::OWeakObject*>(SwXFieldmark::CreateXFieldmark(rDoc, 
nullptr).get());
         }
         break;
         case  SwServiceType::TypeFormFieldMark :
         {
-            xRet = SwXFieldmark::CreateXFieldmark(rDoc, nullptr, true);
+            xRet = 
static_cast<cppu::OWeakObject*>(SwXFieldmark::CreateXFieldmark(rDoc, nullptr, 
true).get());
         }
         break;
         case  SwServiceType::VbaObjectProvider :
@@ -605,10 +605,10 @@ SwXServiceProvider::MakeInstance(SwServiceType 
nObjectType, SwDoc & rDoc)
         break;
 
         case  SwServiceType::TypeFootnote :
-            xRet = SwXFootnote::CreateXFootnote(rDoc, nullptr);
+            xRet = 
static_cast<cppu::OWeakObject*>(SwXFootnote::CreateXFootnote(rDoc, 
nullptr).get());
         break;
         case  SwServiceType::TypeEndnote  :
-            xRet = SwXFootnote::CreateXFootnote(rDoc, nullptr, true);
+            xRet = 
static_cast<cppu::OWeakObject*>(SwXFootnote::CreateXFootnote(rDoc, nullptr, 
true).get());
         break;
         case  SwServiceType::ContentIndexMark :
         case  SwServiceType::UserIndexMark    :
@@ -619,7 +619,7 @@ SwXServiceProvider::MakeInstance(SwServiceType nObjectType, 
SwDoc & rDoc)
                 eType = TOX_CONTENT;
             else if(SwServiceType::UserIndexMark == nObjectType)
                 eType = TOX_USER;
-            xRet = SwXDocumentIndexMark::CreateXDocumentIndexMark(rDoc, 
nullptr, eType);
+            xRet = 
static_cast<cppu::OWeakObject*>(SwXDocumentIndexMark::CreateXDocumentIndexMark(rDoc,
 nullptr, eType).get());
         }
         break;
         case  SwServiceType::ContentIndex      :
@@ -651,17 +651,17 @@ SwXServiceProvider::MakeInstance(SwServiceType 
nObjectType, SwDoc & rDoc)
             {
                 eType = TOX_TABLES;
             }
-            xRet = SwXDocumentIndex::CreateXDocumentIndex(rDoc, nullptr, 
eType);
+            xRet = 
static_cast<cppu::OWeakObject*>(SwXDocumentIndex::CreateXDocumentIndex(rDoc, 
nullptr, eType).get());
         }
         break;
         case SwServiceType::IndexHeaderSection :
         case SwServiceType::TextSection :
-            xRet = SwXTextSection::CreateXTextSection(nullptr,
-                    (SwServiceType::IndexHeaderSection == nObjectType));
+            xRet = 
static_cast<cppu::OWeakObject*>(SwXTextSection::CreateXTextSection(nullptr,
+                    (SwServiceType::IndexHeaderSection == nObjectType)).get());
 
         break;
         case SwServiceType::ReferenceMark :
-            xRet = SwXReferenceMark::CreateXReferenceMark(rDoc, nullptr);
+            xRet = 
static_cast<cppu::OWeakObject*>(SwXReferenceMark::CreateXReferenceMark(rDoc, 
nullptr).get());
         break;
         case SwServiceType::StyleCharacter:
         case SwServiceType::StyleParagraph:
@@ -756,10 +756,10 @@ SwXServiceProvider::MakeInstance(SwServiceType 
nObjectType, SwDoc & rDoc)
         case SwServiceType::FieldTypeDropdown:
         case SwServiceType::FieldTypeTableFormula:
             // NOTE: the sw.SwXAutoTextEntry unoapi test depends on pDoc = 0
-            xRet = SwXTextField::CreateXTextField(nullptr, nullptr, 
nObjectType);
+            xRet = 
static_cast<cppu::OWeakObject*>(SwXTextField::CreateXTextField(nullptr, 
nullptr, nObjectType).get());
             break;
         case SwServiceType::FieldTypeAnnotation:
-            xRet = SwXTextField::CreateXTextField(&rDoc, nullptr, nObjectType);
+            xRet = 
static_cast<cppu::OWeakObject*>(SwXTextField::CreateXTextField(&rDoc, nullptr, 
nObjectType).get());
             break;
         case SwServiceType::FieldMasterUser:
         case SwServiceType::FieldMasterDDE:
@@ -775,7 +775,7 @@ SwXServiceProvider::MakeInstance(SwServiceType nObjectType, 
SwDoc & rDoc)
                 case SwServiceType::FieldMasterDatabase: nResId = 
SwFieldIds::Database; break;
                 default: break;
             }
-            xRet = SwXFieldMaster::CreateXFieldMaster(&rDoc, nullptr, nResId);
+            xRet = 
static_cast<cppu::OWeakObject*>(SwXFieldMaster::CreateXFieldMaster(&rDoc, 
nullptr, nResId).get());
         }
         break;
         case SwServiceType::FieldMasterBibliography:
@@ -786,11 +786,11 @@ SwXServiceProvider::MakeInstance(SwServiceType 
nObjectType, SwDoc & rDoc)
                 SwAuthorityFieldType aType(&rDoc);
                 pType = rDoc.getIDocumentFieldsAccess().InsertFieldType(aType);
             }
-            xRet = SwXFieldMaster::CreateXFieldMaster(&rDoc, pType);
+            xRet = 
static_cast<cppu::OWeakObject*>(SwXFieldMaster::CreateXFieldMaster(&rDoc, 
pType).get());
         }
         break;
         case SwServiceType::Paragraph:
-            xRet = SwXParagraph::CreateXParagraph(rDoc, nullptr);
+            xRet = 
static_cast<cppu::OWeakObject*>(SwXParagraph::CreateXParagraph(rDoc, 
nullptr).get());
         break;
         case SwServiceType::NumberingRules:
             xRet = static_cast<cppu::OWeakObject*>(new 
SwXNumberingRules(rDoc));
@@ -823,16 +823,16 @@ SwXServiceProvider::MakeInstance(SwServiceType 
nObjectType, SwDoc & rDoc)
 
         break;
         case SwServiceType::TypeMeta:
-            xRet = SwXMeta::CreateXMeta(rDoc, false);
+            xRet = static_cast<cppu::OWeakObject*>(SwXMeta::CreateXMeta(rDoc, 
false).get());
         break;
         case SwServiceType::FieldTypeMetafield:
-            xRet = SwXMeta::CreateXMeta(rDoc, true);
+            xRet = static_cast<cppu::OWeakObject*>(SwXMeta::CreateXMeta(rDoc, 
true).get());
         break;
         case SwServiceType::LineBreak:
-            xRet = SwXLineBreak::CreateXLineBreak(nullptr);
+            xRet = 
static_cast<cppu::OWeakObject*>(SwXLineBreak::CreateXLineBreak(nullptr).get());
             break;
         case SwServiceType::ContentControl:
-            xRet = SwXContentControl::CreateXContentControl(rDoc);
+            xRet = 
static_cast<cppu::OWeakObject*>(SwXContentControl::CreateXContentControl(rDoc).get());
         break;
         default:
             throw uno::RuntimeException();
diff --git a/sw/source/core/unocore/unocontentcontrol.cxx 
b/sw/source/core/unocore/unocontentcontrol.cxx
index 6a8fda8c81cb..4bbc3e242e98 100644
--- a/sw/source/core/unocore/unocontentcontrol.cxx
+++ b/sw/source/core/unocore/unocontentcontrol.cxx
@@ -144,7 +144,7 @@ uno::Reference<text::XTextCursor> SAL_CALL 
SwXContentControlText::createTextCurs
 class SwXContentControl::Impl : public SvtListener
 {
 public:
-    uno::WeakReference<uno::XInterface> m_wThis;
+    unotools::WeakReference<SwXContentControl> m_wThis;
     // Just for OInterfaceContainerHelper4.
     std::mutex m_Mutex;
     ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> 
m_EventListeners;
@@ -249,37 +249,32 @@ SwXContentControl::SwXContentControl(SwDoc* pDoc)
 
 SwXContentControl::~SwXContentControl() {}
 
-uno::Reference<text::XTextContent> 
SwXContentControl::CreateXContentControl(SwDoc& rDoc)
+rtl::Reference<SwXContentControl> 
SwXContentControl::CreateXContentControl(SwDoc& rDoc)
 {
     rtl::Reference<SwXContentControl> xContentControl(new 
SwXContentControl(&rDoc));
-    uno::Reference<text::XTextContent> xTextContent(xContentControl);
-    xContentControl->m_pImpl->m_wThis = xTextContent;
+    xContentControl->m_pImpl->m_wThis = xContentControl.get();
     return xContentControl;
 }
 
-uno::Reference<text::XTextContent>
+rtl::Reference<SwXContentControl>
 SwXContentControl::CreateXContentControl(SwContentControl& rContentControl,
                                          const uno::Reference<text::XText>& 
xParent,
                                          std::unique_ptr<const 
TextRangeList_t>&& pPortions)
 {
     // re-use existing SwXContentControl
-    uno::Reference<text::XTextContent> 
xContentControl(rContentControl.GetXContentControl());
+    rtl::Reference<SwXContentControl> 
xContentControl(rContentControl.GetXContentControl());
     if (xContentControl.is())
     {
         if (pPortions)
         {
-            // Set the cache in the XContentControl to the given portions.
-            auto pXContentControl
-                = 
comphelper::getFromUnoTunnel<SwXContentControl>(xContentControl);
-            assert(pXContentControl);
             // The content control must always be created with the complete 
content.  If
             // SwXTextPortionEnumeration is created for a selection, it must 
be checked that the
             // content control is contained in the selection.
-            pXContentControl->m_pImpl->m_pTextPortions = std::move(pPortions);
-            if (pXContentControl->m_pImpl->m_xParentText.get() != 
xParent.get())
+            xContentControl->m_pImpl->m_pTextPortions = std::move(pPortions);
+            if (xContentControl->m_pImpl->m_xParentText.get() != xParent.get())
             {
                 SAL_WARN("sw.uno", "SwXContentControl with different parent");
-                pXContentControl->m_pImpl->m_xParentText.set(xParent);
+                xContentControl->m_pImpl->m_xParentText.set(xParent);
             }
         }
         return xContentControl;
@@ -308,11 +303,10 @@ 
SwXContentControl::CreateXContentControl(SwContentControl& rContentControl,
     {
         return nullptr;
     }
-    rtl::Reference<SwXContentControl> pXContentControl = new SwXContentControl(
-        &pTextNode->GetDoc(), &rContentControl, xParentText, 
std::move(pPortions));
-    xContentControl.set(pXContentControl);
+    xContentControl = new SwXContentControl(&pTextNode->GetDoc(), 
&rContentControl, xParentText,
+                                            std::move(pPortions));
     rContentControl.SetXContentControl(xContentControl);
-    pXContentControl->m_pImpl->m_wThis = xContentControl;
+    xContentControl->m_pImpl->m_wThis = xContentControl.get();
     return xContentControl;
 }
 
@@ -507,7 +501,7 @@ void SwXContentControl::AttachImpl(const 
uno::Reference<text::XTextRange>& xText
     m_pImpl->EndListeningAll();
     m_pImpl->m_pContentControl = pContentControl.get();
     m_pImpl->StartListening(pContentControl->GetNotifier());
-    
pContentControl->SetXContentControl(uno::Reference<text::XTextContent>(this));
+    pContentControl->SetXContentControl(this);
 
     m_pImpl->m_xParentText = sw::CreateParentXText(*pDoc, *aPam.GetPoint());
 
diff --git a/sw/source/core/unocore/unodraw.cxx 
b/sw/source/core/unocore/unodraw.cxx
index a3d5888e684b..9177075a5f83 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -331,18 +331,18 @@ uno::Reference< drawing::XShape > 
SwFmDrawPage::CreateShape( SdrObject *pObj ) c
                 const SwNode* pNd = pDoc->GetNodes()[ pIdx->GetIndex() + 1 ];
                 if(!pNd->IsNoTextNode())
                 {
-                    xRet.set(SwXTextFrame::CreateXTextFrame(*pDoc, pFlyFormat),
+                    
xRet.set(static_cast<cppu::OWeakObject*>(SwXTextFrame::CreateXTextFrame(*pDoc, 
pFlyFormat).get()),
                             uno::UNO_QUERY);
                 }
                 else if( pNd->IsGrfNode() )
                 {
-                    xRet.set(SwXTextGraphicObject::CreateXTextGraphicObject(
-                                *pDoc, pFlyFormat), uno::UNO_QUERY);
+                    
xRet.set(static_cast<cppu::OWeakObject*>(SwXTextGraphicObject::CreateXTextGraphicObject(
+                                *pDoc, pFlyFormat).get()), uno::UNO_QUERY);
                 }
                 else if( pNd->IsOLENode() )
                 {
-                    xRet.set(SwXTextEmbeddedObject::CreateXTextEmbeddedObject(
-                                *pDoc, pFlyFormat), uno::UNO_QUERY);
+                    
xRet.set(static_cast<cppu::OWeakObject*>(SwXTextEmbeddedObject::CreateXTextEmbeddedObject(
+                                *pDoc, pFlyFormat).get()), uno::UNO_QUERY);
                 }
             }
             else
diff --git a/sw/source/core/unocore/unofield.cxx 
b/sw/source/core/unocore/unofield.cxx
index 53eb083e8156..800eda41d5b6 100644
--- a/sw/source/core/unocore/unofield.cxx
+++ b/sw/source/core/unocore/unofield.cxx
@@ -407,7 +407,7 @@ class SwXFieldMaster::Impl
 public:
     std::mutex m_Mutex; // just for OInterfaceContainerHelper4
 
-    uno::WeakReference<uno::XInterface> m_wThis;
+    unotools::WeakReference<SwXFieldMaster> m_wThis;
     ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> 
m_EventListeners;
 
     SwDoc*          m_pDoc;
@@ -532,15 +532,15 @@ SwXFieldMaster::~SwXFieldMaster()
 {
 }
 
-uno::Reference<beans::XPropertySet>
+rtl::Reference<SwXFieldMaster>
 SwXFieldMaster::CreateXFieldMaster(SwDoc * pDoc, SwFieldType *const pType,
         SwFieldIds nResId)
 {
     // re-use existing SwXFieldMaster
-    uno::Reference<beans::XPropertySet> xFM;
+    rtl::Reference<SwXFieldMaster> xFM;
     if (pType)
     {
-        xFM = pType->GetXObject();
+        xFM = dynamic_cast<SwXFieldMaster*>(pType->GetXObject().get().get());
     }
     if (!xFM.is())
     {
@@ -553,7 +553,7 @@ SwXFieldMaster::CreateXFieldMaster(SwDoc * pDoc, 
SwFieldType *const pType,
             pType->SetXObject(xFM);
         }
         // need a permanent Reference to initialize m_wThis
-        pFM->m_pImpl->m_wThis = xFM;
+        pFM->m_pImpl->m_wThis = xFM.get();
     }
     return xFM;
 }
@@ -824,7 +824,7 @@ SwXFieldMaster::getPropertyValue(const OUString& 
rPropertyName)
             pType->GatherFields(vpFields);
             uno::Sequence<uno::Reference <text::XDependentTextField> > 
aSeq(vpFields.size());
             std::transform(vpFields.begin(), vpFields.end(), aSeq.getArray(),
-                    [this](SwFormatField* pF) { return 
uno::Reference<text::XDependentTextField>(SwXTextField::CreateXTextField(m_pImpl->m_pDoc,
 pF), uno::UNO_QUERY); });
+                    [this](SwFormatField* pF) { return 
uno::Reference<text::XDependentTextField>(SwXTextField::CreateXTextField(m_pImpl->m_pDoc,
 pF)); });
             aRet <<= aSeq;
         }
         else
@@ -1087,7 +1087,7 @@ public:
     SwFieldType* m_pFieldType;
     SwFormatField* m_pFormatField;
 
-    uno::WeakReference<uno::XInterface> m_wThis;
+    unotools::WeakReference<SwXTextField> m_wThis;
     ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> 
m_EventListeners;
 
     SwDoc* m_pDoc;
@@ -1212,14 +1212,14 @@ SwXTextField::~SwXTextField()
 {
 }
 
-uno::Reference<text::XTextField>
+rtl::Reference<SwXTextField>
 SwXTextField::CreateXTextField(SwDoc *const pDoc, SwFormatField const* pFormat,
         SwServiceType nServiceId)
 {
     assert(!pFormat || pDoc);
     assert(pFormat || nServiceId != SwServiceType::Invalid);
     // re-use existing SwXTextField
-    uno::Reference<text::XTextField> xField;
+    rtl::Reference<SwXTextField> xField;
     if (pFormat)
     {
         xField = pFormat->GetXTextField();
@@ -1235,7 +1235,7 @@ SwXTextField::CreateXTextField(SwDoc *const pDoc, 
SwFormatField const* pFormat,
             const_cast<SwFormatField *>(pFormat)->SetXTextField(xField);
         }
         // need a permanent Reference to initialize m_wThis
-        pField->m_pImpl->m_wThis = xField;
+        pField->m_pImpl->m_wThis = xField.get();
     }
     return xField;
 }
@@ -1260,10 +1260,10 @@ SwServiceType SwXTextField::GetServiceId() const
 void SwXTextField::TransmuteLeadToInputField(SwSetExpField & rField)
 {
     assert(rField.GetFormatField()->Which() == (rField.GetInputFlag() ? 
RES_TXTATR_INPUTFIELD : RES_TXTATR_FIELD));
-    uno::Reference<text::XTextField> const xField(
+    rtl::Reference<SwXTextField> const xField(
         rField.GetFormatField()->GetXTextField());
     SwXTextField *const pXField = xField.is()
-        ? 
comphelper::getFromUnoTunnel<SwXTextField>(uno::Reference<lang::XUnoTunnel>(xField,
 uno::UNO_QUERY_THROW))
+        ? 
comphelper::getFromUnoTunnel<SwXTextField>(uno::Reference<lang::XUnoTunnel>(xField))
         : nullptr;
     if (pXField)
         pXField->m_pImpl->SetFormatField(nullptr, nullptr);
@@ -1988,7 +1988,7 @@ void SAL_CALL SwXTextField::attach(
         assert(m_pImpl->GetFormatField());
         m_pImpl->m_pDoc = pDoc;
         m_pImpl->GetFormatField()->SetXTextField(this);
-        m_pImpl->m_wThis = *this;
+        m_pImpl->m_wThis = this;
         m_pImpl->m_bIsDescriptor = false;
         m_pImpl->ClearFieldType();
         m_pImpl->m_pProps.reset();
@@ -2981,7 +2981,7 @@ SwXFieldEnumeration::SwXFieldEnumeration(SwDoc & rDoc)
     IDocumentMarkAccess& rMarksAccess(*rDoc.getIDocumentMarkAccess());
     for (auto iter = rMarksAccess.getFieldmarksBegin(); iter != 
rMarksAccess.getFieldmarksEnd(); ++iter)
     {
-        m_pImpl->m_Items.emplace_back(SwXFieldmark::CreateXFieldmark(rDoc, 
*iter), uno::UNO_QUERY);
+        
m_pImpl->m_Items.emplace_back(static_cast<cppu::OWeakObject*>(SwXFieldmark::CreateXFieldmark(rDoc,
 *iter).get()), uno::UNO_QUERY);
     }
 }
 
diff --git a/sw/source/core/unocore/unoframe.cxx 
b/sw/source/core/unocore/unoframe.cxx
index 8e30322644c6..66598af084dd 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -1260,28 +1260,27 @@ SwXFrame::~SwXFrame()
     EndListeningAll();
 }
 
-template<class Interface, class NameLookupIsHard>
-uno::Reference<Interface>
+template<class NameLookupIsHard>
+rtl::Reference<NameLookupIsHard>
 SwXFrame::CreateXFrame(SwDoc & rDoc, SwFrameFormat *const pFrameFormat)
 {
     assert(!pFrameFormat || &rDoc == pFrameFormat->GetDoc());
-    uno::Reference<Interface> xFrame;
+    rtl::Reference<NameLookupIsHard> xFrame;
     if (pFrameFormat)
     {
-        xFrame.set(pFrameFormat->GetXObject(), uno::UNO_QUERY); // cached?
+        xFrame = 
dynamic_cast<NameLookupIsHard*>(pFrameFormat->GetXObject().get().get()); // 
cached?
     }
     if (!xFrame.is())
     {
-        NameLookupIsHard *const pNew(pFrameFormat
+        xFrame = pFrameFormat
                 ? new NameLookupIsHard(*pFrameFormat)
-                : new NameLookupIsHard(&rDoc));
-        xFrame.set(pNew);
+                : new NameLookupIsHard(&rDoc);
         if (pFrameFormat)
         {
-            pFrameFormat->SetXObject(xFrame);
+            
pFrameFormat->SetXObject(static_cast<cppu::OWeakObject*>(xFrame.get()));
         }
         // need a permanent Reference to initialize m_wThis
-        pNew->SwXFrame::m_pImpl->m_wThis = xFrame;
+        xFrame->SwXFrame::m_pImpl->m_wThis = 
uno::Reference<XWeak>(xFrame.get());
     }
     return xFrame;
 }
@@ -3214,10 +3213,10 @@ SwXTextFrame::~SwXTextFrame()
 {
 }
 
-uno::Reference<text::XTextFrame>
+rtl::Reference<SwXTextFrame>
 SwXTextFrame::CreateXTextFrame(SwDoc & rDoc, SwFrameFormat *const pFrameFormat)
 {
-    return CreateXFrame<text::XTextFrame, SwXTextFrame>(rDoc, pFrameFormat);
+    return CreateXFrame<SwXTextFrame>(rDoc, pFrameFormat);
 }
 
 void SAL_CALL SwXTextFrame::acquire(  )noexcept
@@ -3455,10 +3454,10 @@ SwXTextGraphicObject::~SwXTextGraphicObject()
 {
 }
 
-uno::Reference<text::XTextContent>
+rtl::Reference<SwXTextGraphicObject>
 SwXTextGraphicObject::CreateXTextGraphicObject(SwDoc & rDoc, SwFrameFormat 
*const pFrameFormat)
 {
-    return CreateXFrame<text::XTextContent, SwXTextGraphicObject>(rDoc, 
pFrameFormat);
+    return CreateXFrame<SwXTextGraphicObject>(rDoc, pFrameFormat);
 }
 
 OUString SwXTextGraphicObject::getImplementationName()
@@ -3502,10 +3501,10 @@ SwXTextEmbeddedObject::~SwXTextEmbeddedObject()
 {
 }
 
-uno::Reference<text::XTextContent>
+rtl::Reference<SwXTextEmbeddedObject>
 SwXTextEmbeddedObject::CreateXTextEmbeddedObject(SwDoc & rDoc, SwFrameFormat 
*const pFrameFormat)
 {
-    return CreateXFrame<text::XTextContent, SwXTextEmbeddedObject>(rDoc, 
pFrameFormat);
+    return CreateXFrame<SwXTextEmbeddedObject>(rDoc, pFrameFormat);
 }
 
 uno::Reference< lang::XComponent >  SwXTextEmbeddedObject::getEmbeddedObject()
diff --git a/sw/source/core/unocore/unoftn.cxx 
b/sw/source/core/unocore/unoftn.cxx
index ca012bbb03e5..8ed3775b9e2b 100644
--- a/sw/source/core/unocore/unoftn.cxx
+++ b/sw/source/core/unocore/unoftn.cxx
@@ -64,7 +64,7 @@ class SwXFootnote::Impl
 public:
 
     SwXFootnote& m_rThis;
-    uno::WeakReference<uno::XInterface> m_wThis;
+    unotools::WeakReference<SwXFootnote> m_wThis;
     const bool m_bIsEndnote;
     std::mutex m_Mutex; // just for OInterfaceContainerHelper4
     ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> 
m_EventListeners;
@@ -138,28 +138,27 @@ SwXFootnote::~SwXFootnote()
 {
 }
 
-uno::Reference<text::XFootnote>
+rtl::Reference<SwXFootnote>
 SwXFootnote::CreateXFootnote(SwDoc & rDoc, SwFormatFootnote *const 
pFootnoteFormat,
         bool const isEndnote)
 {
     // i#105557: do not iterate over the registered clients: race condition
-    uno::Reference<text::XFootnote> xNote;
+    rtl::Reference<SwXFootnote> xNote;
     if (pFootnoteFormat)
     {
         xNote = pFootnoteFormat->GetXFootnote();
     }
     if (!xNote.is())
     {
-        SwXFootnote *const pNote(pFootnoteFormat
+        xNote = pFootnoteFormat
                 ? new SwXFootnote(rDoc, *pFootnoteFormat)
-                : new SwXFootnote(isEndnote));
-        xNote.set(pNote);
+                : new SwXFootnote(isEndnote);
         if (pFootnoteFormat)
         {
             pFootnoteFormat->SetXFootnote(xNote);
         }
         // need a permanent Reference to initialize m_wThis
-        pNote->m_pImpl->m_wThis = xNote;
+        xNote->m_pImpl->m_wThis = xNote.get();
     }
     return xNote;
 }
diff --git a/sw/source/core/unocore/unoidx.cxx 
b/sw/source/core/unocore/unoidx.cxx
index b2d521c6d44e..0d1fb2ff7f1e 100644
--- a/sw/source/core/unocore/unoidx.cxx
+++ b/sw/source/core/unocore/unoidx.cxx
@@ -295,7 +295,7 @@ private:
     SwSectionFormat* m_pFormat;
 
 public:
-    uno::WeakReference<uno::XInterface> m_wThis;
+    unotools::WeakReference<SwXDocumentIndex> m_wThis;
     ::comphelper::OMultiTypeInterfaceContainerHelper2 m_Listeners;
     SfxItemPropertySet const& m_rPropSet;
     const TOXTypes m_eTOXType;
@@ -371,12 +371,12 @@ void SwXDocumentIndex::Impl::Notify(const SfxHint& rHint)
     if(!m_pFormat)
     {
         EndListeningAll();
-        uno::Reference<uno::XInterface> const xThis(m_wThis);
+        rtl::Reference<SwXDocumentIndex> const xThis(m_wThis);
         if (!xThis.is())
         {   // fdo#72695: if UNO object is already dead, don't revive it with 
event
             return;
         }
-        lang::EventObject const ev(xThis);
+        lang::EventObject const 
ev(static_cast<cppu::OWeakObject*>(xThis.get()));
         m_Listeners.disposeAndClear(ev);
     }
 }
@@ -397,30 +397,29 @@ SwXDocumentIndex::~SwXDocumentIndex()
 {
 }
 
-uno::Reference<text::XDocumentIndex>
+rtl::Reference<SwXDocumentIndex>
 SwXDocumentIndex::CreateXDocumentIndex(
         SwDoc & rDoc, SwTOXBaseSection * pSection, TOXTypes const eTypes)
 {
     // re-use existing SwXDocumentIndex
     // #i105557#: do not iterate over the registered clients: race condition
-    uno::Reference<text::XDocumentIndex> xIndex;
+    rtl::Reference<SwXDocumentIndex> xIndex;
     if (pSection)
     {
         SwSectionFormat const *const pFormat = pSection->GetFormat();
-        xIndex.set(pFormat->GetXObject(), uno::UNO_QUERY);
+        xIndex = 
dynamic_cast<SwXDocumentIndex*>(pFormat->GetXObject().get().get());
     }
     if (!xIndex.is())
     {
-        SwXDocumentIndex *const pIndex(pSection
+        xIndex = pSection
                 ? new SwXDocumentIndex(*pSection, rDoc)
-                : new SwXDocumentIndex(eTypes, rDoc));
-        xIndex.set(pIndex);
+                : new SwXDocumentIndex(eTypes, rDoc);
         if (pSection)
         {
-            pSection->GetFormat()->SetXObject(xIndex);
+            
pSection->GetFormat()->SetXObject(static_cast<cppu::OWeakObject*>(xIndex.get()));
         }
         // need a permanent Reference to initialize m_wThis
-        pIndex->m_pImpl->m_wThis = xIndex;
+        xIndex->m_pImpl->m_wThis = xIndex.get();
     }
     return xIndex;
 }
@@ -1483,7 +1482,7 @@ private:
 
 public:
 
-    uno::WeakReference<uno::XInterface> m_wThis;
+    unotools::WeakReference<SwXDocumentIndexMark> m_wThis;
     SfxItemPropertySet const& m_rPropSet;
     const TOXTypes m_eTOXType;
     std::mutex m_Mutex; // just for OInterfaceContainerHelper4
@@ -1568,11 +1567,11 @@ void SwXDocumentIndexMark::Impl::Invalidate()
 {
     if (!m_bInReplaceMark) // #i109983# only dispose on delete, not on replace!
     {
-        uno::Reference<uno::XInterface> const xThis(m_wThis);
+        rtl::Reference<SwXDocumentIndexMark> const xThis(m_wThis);
         // fdo#72695: if UNO object is already dead, don't revive it with event
         if (xThis.is())
         {
-            lang::EventObject const ev(xThis);
+            lang::EventObject const 
ev(static_cast<cppu::OWeakObject*>(xThis.get()));
             std::unique_lock aGuard(m_Mutex);
             m_EventListeners.disposeAndClear(aGuard, ev);
         }
@@ -1611,31 +1610,30 @@ SwXDocumentIndexMark::~SwXDocumentIndexMark()
 {
 }
 
-uno::Reference<text::XDocumentIndexMark>
+rtl::Reference<SwXDocumentIndexMark>
 SwXDocumentIndexMark::CreateXDocumentIndexMark(
         SwDoc & rDoc, SwTOXMark *const pMark, TOXTypes const eType)
 {
     // re-use existing SwXDocumentIndexMark
     // NB: xmloff depends on this caching to generate ID from the address!
     // #i105557#: do not iterate over the registered clients: race condition
-    uno::Reference<text::XDocumentIndexMark> xTOXMark;
+    rtl::Reference<SwXDocumentIndexMark> xTOXMark;
     if (pMark)
     {
         xTOXMark = pMark->GetXTOXMark();
     }
     if (!xTOXMark.is())
     {
-        SwXDocumentIndexMark *const pNew(pMark
+        xTOXMark = pMark
             ? new SwXDocumentIndexMark(rDoc,
                     *const_cast<SwTOXType*>(pMark->GetTOXType()), *pMark)
-            : new SwXDocumentIndexMark(eType));
-        xTOXMark.set(pNew);
+            : new SwXDocumentIndexMark(eType);
         if (pMark)
         {
             pMark->SetXTOXMark(xTOXMark);
         }
         // need a permanent Reference to initialize m_wThis
-        pNew->m_pImpl->m_wThis = xTOXMark;
+        xTOXMark->m_pImpl->m_wThis = xTOXMark.get();
     }
     return xTOXMark;
 }
diff --git a/sw/source/core/unocore/unolinebreak.cxx 
b/sw/source/core/unocore/unolinebreak.cxx
index b7f8a174ad17..4b8bfa08ff74 100644
--- a/sw/source/core/unocore/unolinebreak.cxx
+++ b/sw/source/core/unocore/unolinebreak.cxx
@@ -108,19 +108,16 @@ SwXLineBreak::SwXLineBreak()
 
 SwXLineBreak::~SwXLineBreak() {}
 
-uno::Reference<text::XTextContent>
-SwXLineBreak::CreateXLineBreak(SwFormatLineBreak* pLineBreakFormat)
+rtl::Reference<SwXLineBreak> SwXLineBreak::CreateXLineBreak(SwFormatLineBreak* 
pLineBreakFormat)
 {
-    uno::Reference<text::XTextContent> xLineBreak;
+    rtl::Reference<SwXLineBreak> xLineBreak;
     if (pLineBreakFormat)
     {
         xLineBreak = pLineBreakFormat->GetXTextContent();
     }
     if (!xLineBreak.is())
     {
-        SwXLineBreak* const pLineBreak(pLineBreakFormat ? new 
SwXLineBreak(*pLineBreakFormat)
-                                                        : new SwXLineBreak);
-        xLineBreak.set(pLineBreak);
+        xLineBreak = pLineBreakFormat ? new SwXLineBreak(*pLineBreakFormat) : 
new SwXLineBreak;
         if (pLineBreakFormat)
         {
             pLineBreakFormat->SetXLineBreak(xLineBreak);
diff --git a/sw/source/core/unocore/unoobj2.cxx 
b/sw/source/core/unocore/unoobj2.cxx
index 1bfe4fae6ae3..d0dc4d34f8e9 100644
--- a/sw/source/core/unocore/unoobj2.cxx
+++ b/sw/source/core/unocore/unoobj2.cxx
@@ -1260,8 +1260,7 @@ CreateParentXText(SwDoc & rDoc, const SwPosition& rPos)
             SwFrameFormat *const pFormat = pSttNode->GetFlyFormat();
             if (nullptr != pFormat)
             {
-                xParentText.set(SwXTextFrame::CreateXTextFrame(rDoc, pFormat),
-                        uno::UNO_QUERY);
+                xParentText = SwXTextFrame::CreateXTextFrame(rDoc, pFormat);
             }
         }
         break;
@@ -1315,7 +1314,7 @@ CreateParentXText(SwDoc & rDoc, const SwPosition& rPos)
                                     FindSttNodeByType(SwFootnoteStartNode))
                 {
                     xParentText.set(SwXFootnote::CreateXFootnote(rDoc,
-                            &const_cast<SwFormatFootnote&>(rFootnote)), 
uno::UNO_QUERY);
+                            &const_cast<SwFormatFootnote&>(rFootnote)));
                     break;
                 }
             }
@@ -1807,8 +1806,8 @@ bool SwXParaFrameEnumerationImpl::CreateNextObject()
 
         if (!pNd->IsNoTextNode())
         {
-            m_xNextObject.set(SwXTextFrame::CreateXTextFrame(
-                        *pFormat->GetDoc(), pFormat));
+            m_xNextObject = 
static_cast<SwXFrame*>(SwXTextFrame::CreateXTextFrame(
+                        *pFormat->GetDoc(), pFormat).get());
         }
         else if (pNd->IsGrfNode())
         {
diff --git a/sw/source/core/unocore/unoparagraph.cxx 
b/sw/source/core/unocore/unoparagraph.cxx
index 7485b98b1580..1bd8949d58b5 100644
--- a/sw/source/core/unocore/unoparagraph.cxx
+++ b/sw/source/core/unocore/unoparagraph.cxx
@@ -113,7 +113,7 @@ class SwXParagraph::Impl
 {
 public:
     SwXParagraph& m_rThis;
-    uno::WeakReference<uno::XInterface> m_wThis;
+    unotools::WeakReference<SwXParagraph> m_wThis;
     std::mutex m_Mutex; // just for OInterfaceContainerHelper4
     ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> 
m_EventListeners;
     SfxItemPropertySet const& m_rPropSet;
@@ -227,17 +227,17 @@ bool SwXParagraph::IsDescriptor() const
     return m_pImpl->IsDescriptor();
 }
 
-uno::Reference<text::XTextContent>
+rtl::Reference<SwXParagraph>
 SwXParagraph::CreateXParagraph(SwDoc & rDoc, SwTextNode *const pTextNode,
         uno::Reference< text::XText> const& i_xParent,
         const sal_Int32 nSelStart, const sal_Int32 nSelEnd)
 {
     // re-use existing SwXParagraph
     // #i105557#: do not iterate over the registered clients: race condition
-    uno::Reference<text::XTextContent> xParagraph;
+    rtl::Reference<SwXParagraph> xParagraph;
     if (pTextNode && (-1 == nSelStart) && (-1 == nSelEnd))
     {   // only use cache if no selection!
-        xParagraph.set(pTextNode->GetXParagraph());
+        xParagraph = pTextNode->GetXParagraph();
     }
     if (xParagraph.is())
     {
@@ -262,7 +262,7 @@ SwXParagraph::CreateXParagraph(SwDoc & rDoc, SwTextNode 
*const pTextNode,
         pTextNode->SetXParagraph(xParagraph);
     }
     // need a permanent Reference to initialize m_wThis
-    pXPara->m_pImpl->m_wThis = xParagraph;
+    pXPara->m_pImpl->m_wThis = xParagraph.get();
     return xParagraph;
 }
 
@@ -331,7 +331,7 @@ SwXParagraph::attachToText(SwXText & rParent, SwTextNode & 
rTextNode)
     m_pImpl->m_bIsDescriptor = false;
     m_pImpl->EndListeningAll();
     m_pImpl->StartListening(rTextNode.GetNotifier());
-    rTextNode.SetXParagraph(uno::Reference<text::XTextContent>(this));
+    rTextNode.SetXParagraph(this);
     m_pImpl->m_xParentText = &rParent;
     if (!m_pImpl->m_sText.isEmpty())
     {
diff --git a/sw/source/core/unocore/unorefmk.cxx 
b/sw/source/core/unocore/unorefmk.cxx
index 1b1b8bdb0e09..e11df03dc7f9 100644
--- a/sw/source/core/unocore/unorefmk.cxx
+++ b/sw/source/core/unocore/unorefmk.cxx
@@ -63,7 +63,7 @@ class SwXReferenceMark::Impl
     : public SvtListener
 {
 public:
-    uno::WeakReference<uno::XInterface> m_wThis;
+    unotools::WeakReference<SwXReferenceMark> m_wThis;
     std::mutex m_Mutex; // just for OInterfaceContainerHelper4
     ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> 
m_EventListeners;
     bool m_bIsDescriptor;
@@ -122,26 +122,25 @@ SwXReferenceMark::~SwXReferenceMark()
 {
 }
 
-uno::Reference<text::XTextContent>
+rtl::Reference<SwXReferenceMark>
 SwXReferenceMark::CreateXReferenceMark(
         SwDoc & rDoc, SwFormatRefMark *const pMarkFormat)
 {
     // i#105557: do not iterate over the registered clients: race condition
-    uno::Reference<text::XTextContent> xMark;
+    rtl::Reference<SwXReferenceMark> xMark;
     if (pMarkFormat)
     {
         xMark = pMarkFormat->GetXRefMark();
     }
     if (!xMark.is())
     {
-        rtl::Reference<SwXReferenceMark> pMark(new SwXReferenceMark(&rDoc, 
pMarkFormat));
-        xMark = pMark;
+        xMark = new SwXReferenceMark(&rDoc, pMarkFormat);
         if (pMarkFormat)
         {
             pMarkFormat->SetXRefMark(xMark);
         }
         // need a permanent Reference to initialize m_wThis
-        pMark->m_pImpl->m_wThis = xMark;
+        xMark->m_pImpl->m_wThis = xMark.get();
     }
     return xMark;
 }
@@ -606,7 +605,7 @@ SwXMetaText::createTextCursorByRange(
 class SwXMeta::Impl : public SvtListener
 {
 public:
-    uno::WeakReference<uno::XInterface> m_wThis;
+    unotools::WeakReference<SwXMeta> m_wThis;
     std::mutex m_Mutex; // just for OInterfaceContainerHelper4
     ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> 
m_EventListeners;
     std::unique_ptr<const TextRangeList_t> m_pTextPortions;
@@ -685,42 +684,38 @@ SwXMeta::~SwXMeta()
 {
 }
 
-uno::Reference<rdf::XMetadatable>
+rtl::Reference<SwXMeta>
 SwXMeta::CreateXMeta(SwDoc & rDoc, bool const isField)
 {
-    SwXMeta *const pXMeta(isField
-            ? new SwXMetaField(& rDoc) : new SwXMeta(& rDoc));
     // this is why the constructor is private: need to acquire pXMeta here
-    uno::Reference<rdf::XMetadatable> const xMeta(pXMeta);
+    rtl::Reference<SwXMeta> xMeta(isField
+            ? new SwXMetaField(& rDoc) : new SwXMeta(& rDoc));
     // need a permanent Reference to initialize m_wThis
-    pXMeta->m_pImpl->m_wThis = xMeta;
+    xMeta->m_pImpl->m_wThis = xMeta.get();
     return xMeta;
 }
 
-uno::Reference<rdf::XMetadatable>
+rtl::Reference<SwXMeta>
 SwXMeta::CreateXMeta(::sw::Meta & rMeta,
             uno::Reference<text::XText> const& i_xParent,
             std::unique_ptr<TextRangeList_t const> && pPortions)
 {
     // re-use existing SwXMeta
     // #i105557#: do not iterate over the registered clients: race condition
-    uno::Reference<rdf::XMetadatable> xMeta(rMeta.GetXMeta());
+    rtl::Reference<SwXMeta> xMeta(rMeta.GetXMeta());
     if (xMeta.is())
     {
         if (pPortions) // set cache in the XMeta to the given portions
         {
-            SwXMeta *const pXMeta(
-                comphelper::getFromUnoTunnel<SwXMeta>(xMeta));
-            assert(pXMeta);
             // NB: the meta must always be created with the complete content
             // if SwXTextPortionEnumeration is created for a selection,
             // it must be checked that the Meta is contained in the selection!
-            pXMeta->m_pImpl->m_pTextPortions = std::move(pPortions);
+            xMeta->m_pImpl->m_pTextPortions = std::move(pPortions);
             // ??? is this necessary?
-            if (pXMeta->m_pImpl->m_xParentText.get() != i_xParent.get())
+            if (xMeta->m_pImpl->m_xParentText.get() != i_xParent.get())
             {
                 SAL_WARN("sw.uno", "SwXMeta with different parent?");
-                pXMeta->m_pImpl->m_xParentText.set(i_xParent);
+                xMeta->m_pImpl->m_xParentText.set(i_xParent);
             }
         }
         return xMeta;
@@ -740,17 +735,16 @@ SwXMeta::CreateXMeta(::sw::Meta & rMeta,
         xParentText.set( ::sw::CreateParentXText(pTextNode->GetDoc(), aPos) );
     }
     if (!xParentText.is()) { return nullptr; }
-    SwXMeta *const pXMeta( (RES_TXTATR_META == rMeta.GetFormatMeta()->Which())
+    // this is why the constructor is private: need to acquire pXMeta here
+    xMeta = (RES_TXTATR_META == rMeta.GetFormatMeta()->Which())
         ? new SwXMeta     (&pTextNode->GetDoc(), &rMeta, xParentText,
                             std::move(pPortions))
         : new SwXMetaField(&pTextNode->GetDoc(), &rMeta, xParentText,
-                            std::move(pPortions)));
-    // this is why the constructor is private: need to acquire pXMeta here
-    xMeta.set(pXMeta);
+                            std::move(pPortions));
     // in order to initialize the weak pointer cache in the core object
     rMeta.SetXMeta(xMeta);
     // need a permanent Reference to initialize m_wThis
-    pXMeta->m_pImpl->m_wThis = xMeta;
+    xMeta->m_pImpl->m_wThis = xMeta.get();
     return xMeta;
 }
 
@@ -1006,7 +1000,7 @@ SwXMeta::AttachImpl(const uno::Reference< 
text::XTextRange > & i_xTextRange,
     m_pImpl->EndListeningAll();
     m_pImpl->m_pMeta = pMeta.get();
     m_pImpl->StartListening(pMeta->GetNotifier());
-    pMeta->SetXMeta(uno::Reference<rdf::XMetadatable>(this));
+    pMeta->SetXMeta(this);
 
     m_pImpl->m_xParentText = ::sw::CreateParentXText(*pDoc, *aPam.GetPoint());
 
diff --git a/sw/source/core/unocore/unosect.cxx 
b/sw/source/core/unocore/unosect.cxx
index 292cfdb8ea89..29672c7f178d 100644
--- a/sw/source/core/unocore/unosect.cxx
+++ b/sw/source/core/unocore/unosect.cxx
@@ -111,7 +111,7 @@ class SwXTextSection::Impl
 {
 public:
     SwXTextSection &            m_rThis;
-    uno::WeakReference<uno::XInterface> m_wThis;
+    unotools::WeakReference<SwXTextSection> m_wThis;
     const SfxItemPropertySet &  m_rPropSet;
     std::mutex m_Mutex; // just for OInterfaceContainerHelper4
     ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> 
m_EventListeners;
@@ -190,27 +190,27 @@ SwSectionFormat * SwXTextSection::GetFormat() const
     return m_pImpl->GetSectionFormat();
 }
 
-uno::Reference< text::XTextSection >
+rtl::Reference< SwXTextSection >
 SwXTextSection::CreateXTextSection(
         SwSectionFormat *const pFormat, const bool bIndexHeader)
 {
     // re-use existing SwXTextSection
     // #i105557#: do not iterate over the registered clients: race condition
-    uno::Reference< text::XTextSection > xSection;
+    rtl::Reference< SwXTextSection > xSection;
     if (pFormat)
     {
-        xSection.set(pFormat->GetXTextSection());
+        xSection = pFormat->GetXTextSection();
     }
     if ( !xSection.is() )
     {
         rtl::Reference<SwXTextSection> pNew = new SwXTextSection(pFormat, 
bIndexHeader);
-        xSection.set(pNew);
+        xSection = pNew;
         if (pFormat)
         {
             pFormat->SetXTextSection(xSection);
         }
         // need a permanent Reference to initialize m_wThis
-        pNew->m_pImpl->m_wThis = xSection;
+        pNew->m_pImpl->m_wThis = xSection.get();
     }
     return xSection;
 }
diff --git a/sw/source/core/unocore/unotbl.cxx 
b/sw/source/core/unocore/unotbl.cxx
index 90df0f543428..4fbe405521cb 100644
--- a/sw/source/core/unocore/unotbl.cxx
+++ b/sw/source/core/unocore/unotbl.cxx
@@ -1896,7 +1896,7 @@ private:
     SwFrameFormat* m_pFrameFormat;
 
 public:
-    uno::WeakReference<uno::XInterface> m_wThis;
+    unotools::WeakReference<SwXTextTable> m_wThis;
     std::mutex m_Mutex; // just for OInterfaceContainerHelper4
     ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> 
m_EventListeners;
     
::comphelper::OInterfaceContainerHelper4<chart::XChartDataChangeEventListener> 
m_ChartListeners;
@@ -1984,19 +1984,18 @@ SwXTextTable::~SwXTextTable()
 {
 }
 
-uno::Reference<text::XTextTable> SwXTextTable::CreateXTextTable(SwFrameFormat* 
const pFrameFormat)
+rtl::Reference<SwXTextTable> SwXTextTable::CreateXTextTable(SwFrameFormat* 
const pFrameFormat)
 {
-    uno::Reference<text::XTextTable> xTable;
+    rtl::Reference<SwXTextTable> xTable;
     if(pFrameFormat)
-        xTable.set(pFrameFormat->GetXObject(), uno::UNO_QUERY); // cached?
+        xTable = 
dynamic_cast<SwXTextTable*>(pFrameFormat->GetXObject().get().get()); // cached?
     if(xTable.is())
         return xTable;
-    SwXTextTable* const pNew( pFrameFormat ? new SwXTextTable(*pFrameFormat) : 
new SwXTextTable());
-    xTable.set(pNew);
+    xTable = pFrameFormat ? new SwXTextTable(*pFrameFormat) : new 
SwXTextTable();
     if(pFrameFormat)
-        pFrameFormat->SetXObject(xTable);
+        
pFrameFormat->SetXObject(static_cast<cppu::OWeakObject*>(xTable.get()));
     // need a permanent Reference to initialize m_wThis
-    pNew->m_pImpl->m_wThis = xTable;
+    xTable->m_pImpl->m_wThis = xTable.get();
     return xTable;
 }
 
diff --git a/sw/source/core/unocore/unotext.cxx 
b/sw/source/core/unocore/unotext.cxx
index f49e076005b7..ae0faed8c1be 100644
--- a/sw/source/core/unocore/unotext.cxx
+++ b/sw/source/core/unocore/unotext.cxx
@@ -1339,8 +1339,7 @@ SwXText::Impl::finishOrAppendParagraph(
     OSL_ENSURE(pTextNode, "no SwTextNode?");
     if (pTextNode)
     {
-        xRet.set(SwXParagraph::CreateXParagraph(*m_pDoc, pTextNode, &m_rThis),
-                uno::UNO_QUERY);
+        xRet = SwXParagraph::CreateXParagraph(*m_pDoc, pTextNode, &m_rThis);
     }
 
     return xRet;
@@ -2560,6 +2559,12 @@ SwXBodyText::createTextCursorByRange(
 
 uno::Reference< container::XEnumeration > SAL_CALL
 SwXBodyText::createEnumeration()
+{
+    return createParagraphEnumeration();
+}
+
+rtl::Reference< SwXParagraphEnumeration >
+SwXBodyText::createParagraphEnumeration()
 {
     SolarMutexGuard aGuard;
 
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index b834f59e9eea..28097d40c411 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -9867,7 +9867,7 @@ void DocxAttributeOutput::FormatFillGradient( const 
XFillGradientItem& rFillGrad
         SwFrameFormat & rFormat(
                 
const_cast<SwFrameFormat&>(m_rExport.m_pParentFrame->GetFrameFormat()));
         uno::Reference<beans::XPropertySet> const xPropertySet(
-            SwXTextFrame::CreateXTextFrame(*rFormat.GetDoc(), &rFormat),
+            
static_cast<cppu::OWeakObject*>(SwXTextFrame::CreateXTextFrame(*rFormat.GetDoc(),
 &rFormat).get()),
             uno::UNO_QUERY);
         m_rDrawingML.SetFS(m_pSerializer);
         m_rDrawingML.WriteGradientFill(xPropertySet);
diff --git a/sw/source/filter/xml/xmltexti.cxx 
b/sw/source/filter/xml/xmltexti.cxx
index 43f1a98abe56..64be72d6146c 100644
--- a/sw/source/filter/xml/xmltexti.cxx
+++ b/sw/source/filter/xml/xmltexti.cxx
@@ -337,8 +337,8 @@ uno::Reference< XPropertySet > 
SwXMLTextImportHelper::createAndInsertOLEObject(
             pOLENd->SetOLESizeInvalid( true );
     }
 
-    xPropSet.set(SwXTextEmbeddedObject::CreateXTextEmbeddedObject(
-                *pDoc, pFrameFormat), uno::UNO_QUERY);
+    xPropSet = SwXTextEmbeddedObject::CreateXTextEmbeddedObject(
+                *pDoc, pFrameFormat);
     if( pDoc->getIDocumentDrawModelAccess().GetDrawModel() )
     {
         // req for z-order
@@ -580,8 +580,8 @@ uno::Reference< XPropertySet > 
SwXMLTextImportHelper::createAndInsertOOoLink(
 
             // TODO/LATER: in future may need a way to set replacement image 
url to the link ( may be even to the object ), needs oasis cws???
 
-            xPropSet.set(SwXTextEmbeddedObject::CreateXTextEmbeddedObject(
-                            *pDoc, pFrameFormat), uno::UNO_QUERY);
+            xPropSet = SwXTextEmbeddedObject::CreateXTextEmbeddedObject(
+                            *pDoc, pFrameFormat);
             if( pDoc->getIDocumentDrawModelAccess().GetDrawModel() )
             {
                 SwXFrame::GetOrCreateSdrObject(*
@@ -636,8 +636,8 @@ uno::Reference< XPropertySet > 
SwXMLTextImportHelper::createAndInsertApplet(
         pDoc->getIDocumentContentOperations().InsertEmbObject( 
*pTextCursor->GetPaM(),
         ::svt::EmbeddedObjectRef(aAppletImpl.GetApplet(), 
embed::Aspects::MSOLE_CONTENT),
         &aAppletImpl.GetItemSet());
-    xPropSet.set(SwXTextEmbeddedObject::CreateXTextEmbeddedObject(
-                *pDoc, pFrameFormat), uno::UNO_QUERY);
+    xPropSet = SwXTextEmbeddedObject::CreateXTextEmbeddedObject(
+                *pDoc, pFrameFormat);
     if( pDoc->getIDocumentDrawModelAccess().GetDrawModel() )
     {
         // req for z-order
@@ -707,8 +707,8 @@ uno::Reference< XPropertySet > 
SwXMLTextImportHelper::createAndInsertPlugin(
                     *pTextCursor->GetPaM(),
                     ::svt::EmbeddedObjectRef(xObj, 
embed::Aspects::MSOLE_CONTENT),
                     &aItemSet);
-            xPropSet.set(SwXTextEmbeddedObject::CreateXTextEmbeddedObject(
-                            *pDoc, pFrameFormat), uno::UNO_QUERY);
+            xPropSet = SwXTextEmbeddedObject::CreateXTextEmbeddedObject(
+                            *pDoc, pFrameFormat);
             if( pDoc->getIDocumentDrawModelAccess().GetDrawModel() )
             {
                 SwXFrame::GetOrCreateSdrObject(*
@@ -856,8 +856,8 @@ uno::Reference< XPropertySet > 
SwXMLTextImportHelper::createAndInsertFloatingFra
                     *pTextCursor->GetPaM(),
                     ::svt::EmbeddedObjectRef(xObj, 
embed::Aspects::MSOLE_CONTENT),
                     &aItemSet);
-            xPropSet.set(SwXTextEmbeddedObject::CreateXTextEmbeddedObject(
-                            *pDoc, pFrameFormat), uno::UNO_QUERY);
+            xPropSet = SwXTextEmbeddedObject::CreateXTextEmbeddedObject(
+                            *pDoc, pFrameFormat);
             if( pDoc->getIDocumentDrawModelAccess().GetDrawModel() )
             {
                 // req for z-order
diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx 
b/sw/source/uibase/dochdl/swdtflvr.cxx
index dd9fc88fbe57..5ef544a941fd 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -1319,7 +1319,7 @@ SwPasteContext::~SwPasteContext()
 
                 aPropertyValue.Name = "TextGraphicObject";
                 aPropertyValue.Value
-                    <<= 
SwXTextGraphicObject::CreateXTextGraphicObject(*pFormat->GetDoc(), pFormat);
+                    <<= 
uno::Reference<text::XTextContent>(SwXTextGraphicObject::CreateXTextGraphicObject(*pFormat->GetDoc(),
 pFormat));
                 break;
             }
 
diff --git a/sw/source/uibase/docvw/UnfloatTableButton.cxx 
b/sw/source/uibase/docvw/UnfloatTableButton.cxx
index 96d3c2f61460..82320732c707 100644
--- a/sw/source/uibase/docvw/UnfloatTableButton.cxx
+++ b/sw/source/uibase/docvw/UnfloatTableButton.cxx
@@ -140,10 +140,9 @@ void UnfloatTableButton::MouseButtonDown(const MouseEvent& 
/*rMEvt*/)
         {
             css::uno::Any aVal;
             aGrabBagItem.QueryValue(aVal);
-            const auto xTable = SwXTextTable::CreateXTextTable(pTableFormat);
-            const css::uno::Reference<css::beans::XPropertySet> xSet(xTable, 
css::uno::UNO_QUERY);
-            assert(xSet);
-            xSet->setPropertyValue(UNO_NAME_TABLE_INTEROP_GRAB_BAG, aVal);
+            const rtl::Reference<SwXTextTable> xTable
+                = SwXTextTable::CreateXTextTable(pTableFormat);
+            xTable->setPropertyValue(UNO_NAME_TABLE_INTEROP_GRAB_BAG, aVal);
         }
     }
 
diff --git a/sw/source/uibase/uno/unotxdoc.cxx 
b/sw/source/uibase/uno/unotxdoc.cxx
index b59795d3c2a4..9cd713820290 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -438,6 +438,11 @@ void SwXTextDocument::GetNumberFormatter()
 }
 
 Reference< XText >  SwXTextDocument::getText()
+{
+    return getBodyText();
+}
+
+rtl::Reference< SwXBodyText > SwXTextDocument::getBodyText()
 {
     SolarMutexGuard aGuard;
     if(!IsValid())

... etc. - the rest is truncated

Reply via email to