sw/source/core/access/acccontext.cxx               |   10 -
 sw/source/core/access/accdoc.cxx                   |   12 -
 sw/source/core/access/accpara.cxx                  |   12 -
 sw/source/core/doc/textboxhelper.cxx               |    3 
 sw/source/core/docnode/finalthreadmanager.cxx      |    2 
 sw/source/core/unocore/SwXTextDefaults.cxx         |   14 -
 sw/source/core/unocore/unobkm.cxx                  |    4 
 sw/source/core/unocore/unochart.cxx                |    2 
 sw/source/core/unocore/unocoll.cxx                 |   54 +++---
 sw/source/core/unocore/unocontentcontrol.cxx       |   24 +-
 sw/source/core/unocore/unodraw.cxx                 |   20 +-
 sw/source/core/unocore/unofield.cxx                |   20 +-
 sw/source/core/unocore/unoflatpara.cxx             |    2 
 sw/source/core/unocore/unoframe.cxx                |   16 -
 sw/source/core/unocore/unoidx.cxx                  |   27 +--
 sw/source/core/unocore/unoobj.cxx                  |   23 +-
 sw/source/core/unocore/unoparagraph.cxx            |   24 +-
 sw/source/core/unocore/unoport.cxx                 |   14 -
 sw/source/core/unocore/unorefmk.cxx                |   18 +-
 sw/source/core/unocore/unosect.cxx                 |   22 +-
 sw/source/core/unocore/unosett.cxx                 |   18 +-
 sw/source/core/unocore/unosrch.cxx                 |    6 
 sw/source/core/unocore/unostyle.cxx                |   46 ++---
 sw/source/core/unocore/unotbl.cxx                  |  183 ++++++++++-----------
 sw/source/uibase/config/StoredChapterNumbering.cxx |    2 
 sw/source/uibase/uno/SwXDocumentSettings.cxx       |    2 
 sw/source/uibase/uno/unoatxt.cxx                   |    2 
 sw/source/uibase/uno/unodispatch.cxx               |    8 
 sw/source/uibase/uno/unomailmerge.cxx              |   36 ++--
 sw/source/uibase/uno/unotxdoc.cxx                  |    9 -
 sw/source/uibase/uno/unotxvw.cxx                   |   49 ++---
 31 files changed, 333 insertions(+), 351 deletions(-)

New commits:
commit 69c7722b6c70db7a39657026689103f541543d4a
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sun Apr 23 20:15:07 2023 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sun Oct 22 13:43:03 2023 +0200

    Use getXWeak in sw
    
    Change-Id: I49d2d1a00928c4cea68164e8c91fd9a6bb4b3b94
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150875
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sw/source/core/access/acccontext.cxx 
b/sw/source/core/access/acccontext.cxx
index 781533207793..46c4f4a825c7 100644
--- a/sw/source/core/access/acccontext.cxx
+++ b/sw/source/core/access/acccontext.cxx
@@ -529,7 +529,7 @@ void SwAccessibleContext::ThrowIfDisposed()
     if (IsDisposed())
     {
         throw lang::DisposedException("object is nonfunctional",
-                static_cast<cppu::OWeakObject*>(this));
+                getXWeak());
     }
 }
 
@@ -828,7 +828,7 @@ uno::Reference< XAccessible > SAL_CALL 
SwAccessibleContext::getAccessibleAtPoint
     vcl::Window *pWin = GetWindow();
     if (!pWin)
     {
-        throw uno::RuntimeException("no Window", 
static_cast<cppu::OWeakObject*>(this));
+        throw uno::RuntimeException("no Window", getXWeak());
     }
 
     Point aPixPoint( aPoint.X, aPoint.Y ); // px rel to parent
@@ -887,11 +887,11 @@ awt::Rectangle SwAccessibleContext::getBoundsImpl(bool 
bRelative)
 
     if (!pParent)
     {
-        throw uno::RuntimeException("no Parent", 
static_cast<cppu::OWeakObject*>(this));
+        throw uno::RuntimeException("no Parent", getXWeak());
     }
     if (!pWin)
     {
-        throw uno::RuntimeException("no Window", 
static_cast<cppu::OWeakObject*>(this));
+        throw uno::RuntimeException("no Window", getXWeak());
     }
 
     SwRect aLogBounds( GetBounds( *(GetMap()), GetFrame() ) ); // twip 
relative to document root
@@ -947,7 +947,7 @@ awt::Point SAL_CALL 
SwAccessibleContext::getLocationOnScreen()
     vcl::Window *pWin = GetWindow();
     if (!pWin)
     {
-        throw uno::RuntimeException("no Window", 
static_cast<cppu::OWeakObject*>(this));
+        throw uno::RuntimeException("no Window", getXWeak());
     }
 
     AbsoluteScreenPixelPoint aPixPosAbs = 
pWin->OutputToAbsoluteScreenPixel(aPixPos);
diff --git a/sw/source/core/access/accdoc.cxx b/sw/source/core/access/accdoc.cxx
index 5c8cfde0faa5..d1bb9d84b150 100644
--- a/sw/source/core/access/accdoc.cxx
+++ b/sw/source/core/access/accdoc.cxx
@@ -228,7 +228,7 @@ awt::Rectangle SAL_CALL 
SwAccessibleDocumentBase::getBounds()
         vcl::Window *pWin = GetWindow();
         if (!pWin)
         {
-            throw uno::RuntimeException("no Window", 
static_cast<cppu::OWeakObject*>(this));
+            throw uno::RuntimeException("no Window", getXWeak());
         }
 
         tools::Rectangle aPixBounds( pWin->GetWindowExtentsRelative( 
*pWin->GetAccessibleParentWindow() ) );
@@ -250,7 +250,7 @@ awt::Point SAL_CALL SwAccessibleDocumentBase::getLocation()
     vcl::Window *pWin = GetWindow();
     if (!pWin)
     {
-        throw uno::RuntimeException("no Window", 
static_cast<cppu::OWeakObject*>(this));
+        throw uno::RuntimeException("no Window", getXWeak());
     }
 
     Point aPixPos( pWin->GetWindowExtentsRelative( 
*pWin->GetAccessibleParentWindow() ).TopLeft() );
@@ -266,7 +266,7 @@ css::awt::Point SAL_CALL 
SwAccessibleDocumentBase::getLocationOnScreen()
     vcl::Window *pWin = GetWindow();
     if (!pWin)
     {
-        throw uno::RuntimeException("no Window", 
static_cast<cppu::OWeakObject*>(this));
+        throw uno::RuntimeException("no Window", getXWeak());
     }
 
     Point aPixPos( pWin->GetWindowExtentsAbsolute().TopLeft() );
@@ -282,7 +282,7 @@ css::awt::Size SAL_CALL SwAccessibleDocumentBase::getSize()
     vcl::Window *pWin = GetWindow();
     if (!pWin)
     {
-        throw uno::RuntimeException("no Window", 
static_cast<cppu::OWeakObject*>(this));
+        throw uno::RuntimeException("no Window", getXWeak());
     }
 
     Size aPixSize( pWin->GetWindowExtentsAbsolute().GetSize() );
@@ -299,7 +299,7 @@ sal_Bool SAL_CALL SwAccessibleDocumentBase::containsPoint(
     vcl::Window *pWin = GetWindow();
     if (!pWin)
     {
-        throw uno::RuntimeException("no Window", 
static_cast<cppu::OWeakObject*>(this));
+        throw uno::RuntimeException("no Window", getXWeak());
     }
 
     tools::Rectangle aPixBounds( pWin->GetWindowExtentsAbsolute() );
@@ -321,7 +321,7 @@ uno::Reference< XAccessible > SAL_CALL 
SwAccessibleDocumentBase::getAccessibleAt
         vcl::Window *pWin = GetWindow();
         if (!pWin)
         {
-            throw uno::RuntimeException("no Window", 
static_cast<cppu::OWeakObject*>(this));
+            throw uno::RuntimeException("no Window", getXWeak());
         }
         if (pWin->isDisposed()) // tdf#147967
             return nullptr;
diff --git a/sw/source/core/access/accpara.cxx 
b/sw/source/core/access/accpara.cxx
index ebd00faab9a3..7226ea72d35d 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -720,7 +720,7 @@ lang::Locale SAL_CALL SwAccessibleParagraph::getLocale()
     const SwTextFrame *pTextFrame = GetFrame()->DynCastTextFrame();
     if( !pTextFrame )
     {
-        throw uno::RuntimeException("no SwTextFrame", 
static_cast<cppu::OWeakObject*>(this));
+        throw uno::RuntimeException("no SwTextFrame", getXWeak());
     }
 
     lang::Locale 
aLoc(g_pBreakIt->GetLocale(pTextFrame->GetLangOfChar(TextFrameIndex(0), 0, 
true)));
@@ -1128,7 +1128,7 @@ css::uno::Sequence< css::style::TabStop > 
SwAccessibleParagraph::GetCurrentTabSt
         vcl::Window *pWin = GetWindow();
         if (!pWin)
         {
-            throw uno::RuntimeException("no Window", 
static_cast<cppu::OWeakObject*>(this));
+            throw uno::RuntimeException("no Window", getXWeak());
         }
 
         SwRect aTmpRect(0, 0, tabs[0].Position, 0);
@@ -2075,7 +2075,7 @@ awt::Rectangle SwAccessibleParagraph::getCharacterBounds(
     vcl::Window *pWin = GetWindow();
     if (!pWin)
     {
-        throw uno::RuntimeException("no Window", 
static_cast<cppu::OWeakObject*>(this));
+        throw uno::RuntimeException("no Window", getXWeak());
     }
 
     tools::Rectangle aScreenRect( GetMap()->CoreToPixel( aCoreRect ));
@@ -2109,7 +2109,7 @@ sal_Int32 SwAccessibleParagraph::getIndexAtPoint( const 
awt::Point& rPoint )
     vcl::Window *pWin = GetWindow();
     if (!pWin)
     {
-        throw uno::RuntimeException("no Window", 
static_cast<cppu::OWeakObject*>(this));
+        throw uno::RuntimeException("no Window", getXWeak());
     }
     Point aPoint( rPoint.X, rPoint.Y );
     SwRect aLogBounds( GetBounds( *(GetMap()), GetFrame() ) ); // twip rel to 
doc root
@@ -2501,7 +2501,7 @@ sal_Bool SwAccessibleParagraph::scrollSubstringTo( 
sal_Int32 nStartIndex,
 
     vcl::Window *pWin = GetWindow();
     if ( ! pWin )
-        throw uno::RuntimeException("no Window", 
static_cast<cppu::OWeakObject*>(this));
+        throw uno::RuntimeException("no Window", getXWeak());
 
     /* Start and end character bounds, in pixels, relative to the paragraph */
     awt::Rectangle startR, endR;
@@ -3305,7 +3305,7 @@ sal_Int32 SAL_CALL 
SwAccessibleParagraph::getNumberOfLineWithCaret()
                 vcl::Window *pWin = GetWindow();
                 if (!pWin)
                 {
-                    throw uno::RuntimeException("no Window", 
static_cast<cppu::OWeakObject*>(this));
+                    throw uno::RuntimeException("no Window", getXWeak());
                 }
 
                 tools::Rectangle aScreenRect( GetMap()->CoreToPixel( 
aCursorCoreRect ));
diff --git a/sw/source/core/doc/textboxhelper.cxx 
b/sw/source/core/doc/textboxhelper.cxx
index 98c77db26d4e..253e39a29383 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -465,8 +465,7 @@ static void lcl_queryInterface(const SwFrameFormat* pShape, 
uno::Any& rAny, SdrO
         = SwTextBoxHelper::getOtherTextBoxFormat(pShape, RES_DRAWFRMFMT, pObj))
     {
         uno::Reference<T> const xInterface(
-            static_cast<cppu::OWeakObject*>(
-                SwXTextFrame::CreateXTextFrame(*pFormat->GetDoc(), 
pFormat).get()),
+            getXWeak(SwXTextFrame::CreateXTextFrame(*pFormat->GetDoc(), 
pFormat).get()),
             uno::UNO_QUERY);
         rAny <<= xInterface;
     }
diff --git a/sw/source/core/docnode/finalthreadmanager.cxx 
b/sw/source/core/docnode/finalthreadmanager.cxx
index 73a0feccfaff..460d9ab13d92 100644
--- a/sw/source/core/docnode/finalthreadmanager.cxx
+++ b/sw/source/core/docnode/finalthreadmanager.cxx
@@ -405,7 +405,7 @@ void SAL_CALL FinalThreadManager::notifyTermination( const 
css::lang::EventObjec
     }
 
     // get reference of this
-    css::uno::Reference< css::uno::XInterface > aOwnRef( static_cast< 
cppu::OWeakObject* >( this ));
+    css::uno::Reference< css::uno::XInterface > aOwnRef( getXWeak());
     // notify <SwThreadJoiner> to release its reference
     SwThreadJoiner::ReleaseThreadJoiner();
 }
diff --git a/sw/source/core/unocore/SwXTextDefaults.cxx 
b/sw/source/core/unocore/SwXTextDefaults.cxx
index b4107f5f15a6..a74808141dc3 100644
--- a/sw/source/core/unocore/SwXTextDefaults.cxx
+++ b/sw/source/core/unocore/SwXTextDefaults.cxx
@@ -66,9 +66,9 @@ void SAL_CALL SwXTextDefaults::setPropertyValue( const 
OUString& rPropertyName,
         throw RuntimeException();
     const SfxItemPropertyMapEntry *pMap = 
m_pPropSet->getPropertyMap().getByName( rPropertyName );
     if (!pMap)
-        throw UnknownPropertyException( "Unknown property: " + rPropertyName, 
static_cast < cppu::OWeakObject * > ( this ) );
+        throw UnknownPropertyException( "Unknown property: " + rPropertyName, 
getXWeak() );
     if ( pMap->nFlags & PropertyAttribute::READONLY)
-        throw PropertyVetoException ( "Property is read-only: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+        throw PropertyVetoException ( "Property is read-only: " + 
rPropertyName, getXWeak() );
 
     const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID);
     if (RES_PAGEDESC == pMap->nWID && MID_PAGEDESC_PAGEDESCNAME == 
pMap->nMemberId)
@@ -126,7 +126,7 @@ Any SAL_CALL SwXTextDefaults::getPropertyValue( const 
OUString& rPropertyName )
         throw RuntimeException();
     const SfxItemPropertyMapEntry *pMap = 
m_pPropSet->getPropertyMap().getByName( rPropertyName );
     if (!pMap)
-        throw UnknownPropertyException( "Unknown property: " + rPropertyName, 
static_cast < cppu::OWeakObject * > ( this ) );
+        throw UnknownPropertyException( "Unknown property: " + rPropertyName, 
getXWeak() );
     Any aRet;
     const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID);
     rItem.QueryValue( aRet, pMap->nMemberId );
@@ -162,7 +162,7 @@ PropertyState SAL_CALL SwXTextDefaults::getPropertyState( 
const OUString& rPrope
         throw RuntimeException();
     const SfxItemPropertyMapEntry *pMap = 
m_pPropSet->getPropertyMap().getByName( rPropertyName );
     if (!pMap)
-        throw UnknownPropertyException( "Unknown property: " + rPropertyName, 
static_cast < cppu::OWeakObject * > ( this ) );
+        throw UnknownPropertyException( "Unknown property: " + rPropertyName, 
getXWeak() );
 
     const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID);
     if (IsStaticDefaultItem ( &rItem ) )
@@ -187,9 +187,9 @@ void SAL_CALL SwXTextDefaults::setPropertyToDefault( const 
OUString& rPropertyNa
         throw RuntimeException();
     const SfxItemPropertyMapEntry *pMap = 
m_pPropSet->getPropertyMap().getByName( rPropertyName );
     if (!pMap)
-        throw UnknownPropertyException( "Unknown property: " + rPropertyName, 
static_cast < cppu::OWeakObject * > ( this ) );
+        throw UnknownPropertyException( "Unknown property: " + rPropertyName, 
getXWeak() );
     if ( pMap->nFlags & PropertyAttribute::READONLY)
-        throw RuntimeException( "setPropertyToDefault: property is read-only: 
" + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+        throw RuntimeException( "setPropertyToDefault: property is read-only: 
" + rPropertyName, getXWeak() );
     SfxItemPool& rSet (m_pDoc->GetAttrPool());
     rSet.ResetPoolDefaultItem ( pMap->nWID );
 }
@@ -200,7 +200,7 @@ Any SAL_CALL SwXTextDefaults::getPropertyDefault( const 
OUString& rPropertyName
         throw RuntimeException();
     const SfxItemPropertyMapEntry *pMap = 
m_pPropSet->getPropertyMap().getByName( rPropertyName );
     if (!pMap)
-        throw UnknownPropertyException( "Unknown property: " + rPropertyName, 
static_cast < cppu::OWeakObject * > ( this ) );
+        throw UnknownPropertyException( "Unknown property: " + rPropertyName, 
getXWeak() );
     Any aRet;
     SfxItemPool& rSet (m_pDoc->GetAttrPool());
     SfxPoolItem const*const pItem = rSet.GetPoolDefaultItem(pMap->nWID);
diff --git a/sw/source/core/unocore/unobkm.cxx 
b/sw/source/core/unocore/unobkm.cxx
index ed99a076244a..81818a13d03a 100644
--- a/sw/source/core/unocore/unobkm.cxx
+++ b/sw/source/core/unocore/unobkm.cxx
@@ -326,7 +326,7 @@ void SAL_CALL SwXBookmark::setName(const OUString& rName)
     if(pMarkAccess->findMark(rName) != pMarkAccess->getAllMarksEnd())
     {
         throw uno::RuntimeException("setName(): name already in use",
-                static_cast<::cppu::OWeakObject*>(this));
+                getXWeak());
     }
 
     SwPaM aPam(m_pImpl->m_pRegisteredBookmark->GetMarkPos());
@@ -430,7 +430,7 @@ SwXBookmark::setPropertyValue(const OUString& PropertyName,
 
     // nothing to set here
     throw lang::IllegalArgumentException("Property is read-only: "
-            + PropertyName, static_cast< cppu::OWeakObject * >(this), 0 );
+            + PropertyName, getXWeak(), 0 );
 }
 
 uno::Any SAL_CALL SwXBookmark::getPropertyValue(const OUString& rPropertyName)
diff --git a/sw/source/core/unocore/unochart.cxx 
b/sw/source/core/unocore/unochart.cxx
index e5265acc4fec..a98f16595643 100644
--- a/sw/source/core/unocore/unochart.cxx
+++ b/sw/source/core/unocore/unochart.cxx
@@ -2200,7 +2200,7 @@ void SAL_CALL SwChartDataSequence::disposing( const 
lang::EventObject& rSource )
 {
     if (m_bDisposed)
         throw lang::DisposedException();
-    if (rSource.Source == 
static_cast<cppu::OWeakObject*>(m_xDataProvider.get()))
+    if (rSource.Source == cppu::getXWeak(m_xDataProvider.get()))
     {
         m_xDataProvider.clear();
     }
diff --git a/sw/source/core/unocore/unocoll.cxx 
b/sw/source/core/unocore/unocoll.cxx
index 5b78e31e5582..1b2c4f3c07d0 100644
--- a/sw/source/core/unocore/unocoll.cxx
+++ b/sw/source/core/unocore/unocoll.cxx
@@ -522,45 +522,45 @@ SwXServiceProvider::MakeInstance(SwServiceType 
nObjectType, SwDoc & rDoc)
     {
         case  SwServiceType::TypeTextTable:
         {
-            xRet = 
static_cast<cppu::OWeakObject*>(SwXTextTable::CreateXTextTable(nullptr).get());
+            xRet = getXWeak(SwXTextTable::CreateXTextTable(nullptr).get());
         }
         break;
         case  SwServiceType::TypeTextFrame:
         {
-            xRet = 
static_cast<cppu::OWeakObject*>(SwXTextFrame::CreateXTextFrame(rDoc, 
nullptr).get());
+            xRet = getXWeak(SwXTextFrame::CreateXTextFrame(rDoc, 
nullptr).get());
         }
         break;
         case  SwServiceType::TypeGraphic  :
         case  SwServiceType::TypeTextGraphic /* #i47503# */ :
         {
-            xRet = 
static_cast<cppu::OWeakObject*>(SwXTextGraphicObject::CreateXTextGraphicObject(rDoc,
 nullptr).get());
+            xRet = 
getXWeak(SwXTextGraphicObject::CreateXTextGraphicObject(rDoc, nullptr).get());
 
         }
         break;
         case  SwServiceType::TypeOLE      :
         {
-            xRet = 
static_cast<cppu::OWeakObject*>(SwXTextEmbeddedObject::CreateXTextEmbeddedObject(rDoc,
 nullptr).get());
+            xRet = 
getXWeak(SwXTextEmbeddedObject::CreateXTextEmbeddedObject(rDoc, nullptr).get());
         }
         break;
         case  SwServiceType::TypeBookmark :
         {
-            xRet = 
static_cast<cppu::OWeakObject*>(SwXBookmark::CreateXBookmark(rDoc, 
nullptr).get());
+            xRet = getXWeak(SwXBookmark::CreateXBookmark(rDoc, nullptr).get());
         }
         break;
         case  SwServiceType::TypeFieldMark :
         {
-            xRet = 
static_cast<cppu::OWeakObject*>(SwXFieldmark::CreateXFieldmark(rDoc, 
nullptr).get());
+            xRet = getXWeak(SwXFieldmark::CreateXFieldmark(rDoc, 
nullptr).get());
         }
         break;
         case  SwServiceType::TypeFormFieldMark :
         {
-            xRet = 
static_cast<cppu::OWeakObject*>(SwXFieldmark::CreateXFieldmark(rDoc, nullptr, 
true).get());
+            xRet = getXWeak(SwXFieldmark::CreateXFieldmark(rDoc, nullptr, 
true).get());
         }
         break;
         case  SwServiceType::VbaObjectProvider :
 #if HAVE_FEATURE_SCRIPTING
         {
-            xRet = static_cast<cppu::OWeakObject*>(new 
SwVbaObjectForCodeNameProvider(rDoc.GetDocShell()));
+            xRet = getXWeak(new 
SwVbaObjectForCodeNameProvider(rDoc.GetDocShell()));
         }
 #endif
         break;
@@ -569,7 +569,7 @@ SwXServiceProvider::MakeInstance(SwServiceType nObjectType, 
SwDoc & rDoc)
         {
             if (rDoc.GetDocShell() && 
ooo::vba::isAlienWordDoc(*rDoc.GetDocShell()))
             {
-                xRet = static_cast<cppu::OWeakObject*>(new 
SwVbaCodeNameProvider(rDoc.GetDocShell()));
+                xRet = getXWeak(new SwVbaCodeNameProvider(rDoc.GetDocShell()));
             }
         }
 #endif
@@ -605,10 +605,10 @@ SwXServiceProvider::MakeInstance(SwServiceType 
nObjectType, SwDoc & rDoc)
         break;
 
         case  SwServiceType::TypeFootnote :
-            xRet = 
static_cast<cppu::OWeakObject*>(SwXFootnote::CreateXFootnote(rDoc, 
nullptr).get());
+            xRet = getXWeak(SwXFootnote::CreateXFootnote(rDoc, nullptr).get());
         break;
         case  SwServiceType::TypeEndnote  :
-            xRet = 
static_cast<cppu::OWeakObject*>(SwXFootnote::CreateXFootnote(rDoc, nullptr, 
true).get());
+            xRet = getXWeak(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 = 
static_cast<cppu::OWeakObject*>(SwXDocumentIndexMark::CreateXDocumentIndexMark(rDoc,
 nullptr, eType).get());
+            xRet = 
getXWeak(SwXDocumentIndexMark::CreateXDocumentIndexMark(rDoc, nullptr, 
eType).get());
         }
         break;
         case  SwServiceType::ContentIndex      :
@@ -651,17 +651,17 @@ SwXServiceProvider::MakeInstance(SwServiceType 
nObjectType, SwDoc & rDoc)
             {
                 eType = TOX_TABLES;
             }
-            xRet = 
static_cast<cppu::OWeakObject*>(SwXDocumentIndex::CreateXDocumentIndex(rDoc, 
nullptr, eType).get());
+            xRet = getXWeak(SwXDocumentIndex::CreateXDocumentIndex(rDoc, 
nullptr, eType).get());
         }
         break;
         case SwServiceType::IndexHeaderSection :
         case SwServiceType::TextSection :
-            xRet = 
static_cast<cppu::OWeakObject*>(SwXTextSection::CreateXTextSection(nullptr,
+            xRet = getXWeak(SwXTextSection::CreateXTextSection(nullptr,
                     (SwServiceType::IndexHeaderSection == nObjectType)).get());
 
         break;
         case SwServiceType::ReferenceMark :
-            xRet = 
static_cast<cppu::OWeakObject*>(SwXReferenceMark::CreateXReferenceMark(rDoc, 
nullptr).get());
+            xRet = getXWeak(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 = 
static_cast<cppu::OWeakObject*>(SwXTextField::CreateXTextField(nullptr, 
nullptr, nObjectType).get());
+            xRet = getXWeak(SwXTextField::CreateXTextField(nullptr, nullptr, 
nObjectType).get());
             break;
         case SwServiceType::FieldTypeAnnotation:
-            xRet = 
static_cast<cppu::OWeakObject*>(SwXTextField::CreateXTextField(&rDoc, nullptr, 
nObjectType).get());
+            xRet = getXWeak(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 = 
static_cast<cppu::OWeakObject*>(SwXFieldMaster::CreateXFieldMaster(&rDoc, 
nullptr, nResId).get());
+            xRet = getXWeak(SwXFieldMaster::CreateXFieldMaster(&rDoc, nullptr, 
nResId).get());
         }
         break;
         case SwServiceType::FieldMasterBibliography:
@@ -786,20 +786,20 @@ SwXServiceProvider::MakeInstance(SwServiceType 
nObjectType, SwDoc & rDoc)
                 SwAuthorityFieldType aType(&rDoc);
                 pType = rDoc.getIDocumentFieldsAccess().InsertFieldType(aType);
             }
-            xRet = 
static_cast<cppu::OWeakObject*>(SwXFieldMaster::CreateXFieldMaster(&rDoc, 
pType).get());
+            xRet = getXWeak(SwXFieldMaster::CreateXFieldMaster(&rDoc, 
pType).get());
         }
         break;
         case SwServiceType::Paragraph:
-            xRet = 
static_cast<cppu::OWeakObject*>(SwXParagraph::CreateXParagraph(rDoc, nullptr, 
nullptr).get());
+            xRet = getXWeak(SwXParagraph::CreateXParagraph(rDoc, nullptr, 
nullptr).get());
         break;
         case SwServiceType::NumberingRules:
-            xRet = static_cast<cppu::OWeakObject*>(new 
SwXNumberingRules(rDoc));
+            xRet = getXWeak(new SwXNumberingRules(rDoc));
         break;
         case SwServiceType::TextColumns:
             xRet = SvxXTextColumns_createInstance();
         break;
         case SwServiceType::Defaults:
-            xRet = static_cast<cppu::OWeakObject*>(new SwXTextDefaults(&rDoc));
+            xRet = getXWeak(new SwXTextDefaults(&rDoc));
         break;
         case SwServiceType::IMapRectangle:
             xRet = SvUnoImageMapRectangleObject_createInstance( 
sw_GetSupportedMacroItems() );
@@ -816,23 +816,23 @@ SwXServiceProvider::MakeInstance(SwServiceType 
nObjectType, SwDoc & rDoc)
             // This should not happen during copy/paste, as this will unlink
             // charts using table data.
             if (rDoc.GetDocShell()->GetCreateMode() != 
SfxObjectCreateMode::EMBEDDED)
-                xRet = 
static_cast<cppu::OWeakObject*>(rDoc.getIDocumentChartDataProviderAccess().GetChartDataProvider(
 true /* create - if not yet available */ ));
+                xRet = 
getXWeak(rDoc.getIDocumentChartDataProviderAccess().GetChartDataProvider( true 
/* create - if not yet available */ ));
             else
                 SAL_WARN("sw.uno",
                     "not creating chart data provider for embedded object");
 
         break;
         case SwServiceType::TypeMeta:
-            xRet = static_cast<cppu::OWeakObject*>(SwXMeta::CreateXMeta(rDoc, 
false).get());
+            xRet = getXWeak(SwXMeta::CreateXMeta(rDoc, false).get());
         break;
         case SwServiceType::FieldTypeMetafield:
-            xRet = static_cast<cppu::OWeakObject*>(SwXMeta::CreateXMeta(rDoc, 
true).get());
+            xRet = getXWeak(SwXMeta::CreateXMeta(rDoc, true).get());
         break;
         case SwServiceType::LineBreak:
-            xRet = 
static_cast<cppu::OWeakObject*>(SwXLineBreak::CreateXLineBreak(nullptr).get());
+            xRet = getXWeak(SwXLineBreak::CreateXLineBreak(nullptr).get());
             break;
         case SwServiceType::ContentControl:
-            xRet = 
static_cast<cppu::OWeakObject*>(SwXContentControl::CreateXContentControl(rDoc).get());
+            xRet = 
getXWeak(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 8492e0fc94f7..fd77b4a77f9e 100644
--- a/sw/source/core/unocore/unocontentcontrol.cxx
+++ b/sw/source/core/unocore/unocontentcontrol.cxx
@@ -376,7 +376,7 @@ void SAL_CALL SwXContentControl::dispose()
     if (m_pImpl->m_bIsDescriptor)
     {
         m_pImpl->m_pTextPortions.reset();
-        lang::EventObject aEvent(static_cast<::cppu::OWeakObject&>(*this));
+        lang::EventObject aEvent(getXWeak());
         std::unique_lock aGuard(m_pImpl->m_Mutex);
         m_pImpl->m_EventListeners.disposeAndClear(aGuard, aEvent);
         m_pImpl->m_bIsDisposed = true;
@@ -417,7 +417,7 @@ void SwXContentControl::AttachImpl(const 
uno::Reference<text::XTextRange>& xText
     if (!m_pImpl->m_bIsDescriptor)
     {
         throw uno::RuntimeException("SwXContentControl::AttachImpl(): already 
attached",
-                                    static_cast<::cppu::OWeakObject*>(this));
+                                    getXWeak());
     }
 
     SwXTextRange* pRange = dynamic_cast<SwXTextRange*>(xTextRange.get());
@@ -426,16 +426,14 @@ void SwXContentControl::AttachImpl(const 
uno::Reference<text::XTextRange>& xText
     if (!pRange && !pCursor)
     {
         throw lang::IllegalArgumentException(
-            "SwXContentControl::AttachImpl(): argument not supported type",
-            static_cast<::cppu::OWeakObject*>(this), 0);
+            "SwXContentControl::AttachImpl(): argument not supported type", 
getXWeak(), 0);
     }
 
     SwDoc* pDoc = pRange ? &pRange->GetDoc() : pCursor->GetDoc();
     if (!pDoc)
     {
         throw lang::IllegalArgumentException(
-            "SwXContentControl::AttachImpl(): argument has no SwDoc",
-            static_cast<::cppu::OWeakObject*>(this), 0);
+            "SwXContentControl::AttachImpl(): argument has no SwDoc", 
getXWeak(), 0);
     }
 
     SwUnoInternalPaM aPam(*pDoc);
@@ -486,14 +484,13 @@ void SwXContentControl::AttachImpl(const 
uno::Reference<text::XTextRange>& xText
     {
         throw lang::IllegalArgumentException(
             "SwXContentControl::AttachImpl(): cannot create content control: 
invalid range",
-            static_cast<::cppu::OWeakObject*>(this), 1);
+            getXWeak(), 1);
     }
     if (!pTextAttr)
     {
         SAL_WARN("sw.core", "content control inserted, but has no text 
attribute?");
         throw uno::RuntimeException(
-            "SwXContentControl::AttachImpl(): cannot create content control",
-            static_cast<::cppu::OWeakObject*>(this));
+            "SwXContentControl::AttachImpl(): cannot create content control", 
getXWeak());
     }
 
     m_pImpl->EndListeningAll();
@@ -522,8 +519,7 @@ uno::Reference<text::XTextRange> SAL_CALL 
SwXContentControl::getAnchor()
     }
     if (m_pImpl->m_bIsDescriptor)
     {
-        throw uno::RuntimeException("SwXContentControl::getAnchor(): not 
inserted",
-                                    static_cast<::cppu::OWeakObject*>(this));
+        throw uno::RuntimeException("SwXContentControl::getAnchor(): not 
inserted", getXWeak());
     }
 
     SwTextNode* pTextNode;
@@ -533,8 +529,7 @@ uno::Reference<text::XTextRange> SAL_CALL 
SwXContentControl::getAnchor()
     if (!bSuccess)
     {
         SAL_WARN("sw.core", "no pam");
-        throw lang::DisposedException("SwXContentControl::getAnchor(): not 
attached",
-                                      static_cast<::cppu::OWeakObject*>(this));
+        throw lang::DisposedException("SwXContentControl::getAnchor(): not 
attached", getXWeak());
     }
 
     SwPosition aStart(*pTextNode, nContentControlStart - 1); // -1 due to 
CH_TXTATR
@@ -1392,8 +1387,7 @@ uno::Reference<container::XEnumeration> SAL_CALL 
SwXContentControl::createEnumer
     }
     if (m_pImpl->m_bIsDescriptor)
     {
-        throw uno::RuntimeException("createEnumeration(): not inserted",
-                                    static_cast<::cppu::OWeakObject*>(this));
+        throw uno::RuntimeException("createEnumeration(): not inserted", 
getXWeak());
     }
 
     SwTextNode* pTextNode;
diff --git a/sw/source/core/unocore/unodraw.cxx 
b/sw/source/core/unocore/unodraw.cxx
index dca041d95129..a229c1f2031f 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -333,17 +333,17 @@ uno::Reference< drawing::XShape > 
SwFmDrawPage::CreateShape( SdrObject *pObj ) c
                 const SwNode* pNd = pDoc->GetNodes()[ pIdx->GetIndex() + 1 ];
                 if(!pNd->IsNoTextNode())
                 {
-                    
xRet.set(static_cast<cppu::OWeakObject*>(SwXTextFrame::CreateXTextFrame(*pDoc, 
pFlyFormat).get()),
+                    
xRet.set(cppu::getXWeak(SwXTextFrame::CreateXTextFrame(*pDoc, 
pFlyFormat).get()),
                             uno::UNO_QUERY);
                 }
                 else if( pNd->IsGrfNode() )
                 {
-                    
xRet.set(static_cast<cppu::OWeakObject*>(SwXTextGraphicObject::CreateXTextGraphicObject(
+                    
xRet.set(cppu::getXWeak(SwXTextGraphicObject::CreateXTextGraphicObject(
                                 *pDoc, pFlyFormat).get()), uno::UNO_QUERY);
                 }
                 else if( pNd->IsOLENode() )
                 {
-                    
xRet.set(static_cast<cppu::OWeakObject*>(SwXTextEmbeddedObject::CreateXTextEmbeddedObject(
+                    
xRet.set(cppu::getXWeak(SwXTextEmbeddedObject::CreateXTextEmbeddedObject(
                                 *pDoc, pFlyFormat).get()), uno::UNO_QUERY);
                 }
             }
@@ -420,7 +420,7 @@ void SwFmDrawPage::setPropertyValue(const OUString& 
rPropertyName, const uno::An
             break;
 
         default:
-            throw beans::UnknownPropertyException(rPropertyName, 
static_cast<cppu::OWeakObject*>(this));
+            throw beans::UnknownPropertyException(rPropertyName, getXWeak());
     }
 }
 
@@ -465,7 +465,7 @@ uno::Any SwFmDrawPage::getPropertyValue(const OUString& 
rPropertyName)
             break;
 
         default:
-            throw beans::UnknownPropertyException(rPropertyName, 
static_cast<cppu::OWeakObject*>(this));
+            throw beans::UnknownPropertyException(rPropertyName, getXWeak());
     }
     return aAny;
 }
@@ -631,7 +631,7 @@ void SwFmDrawPage::add(const uno::Reference< 
drawing::XShape > & xShape)
     // this is not a writer shape
     if(!pShape)
         throw uno::RuntimeException("illegal object",
-                                    static_cast< cppu::OWeakObject * > ( this 
) );
+                                    getXWeak() );
 
     // we're already registered in the model / SwXDrawPage::add() already 
called
     if(pShape->m_pPage || !pShape->m_bDescriptor )
@@ -927,7 +927,7 @@ SwXShape::SwXShape(
     xShape = nullptr;
     osl_atomic_increment(&m_refCount);
     if( m_xShapeAgg.is() )
-        m_xShapeAgg->setDelegator( static_cast<cppu::OWeakObject*>(this) );
+        m_xShapeAgg->setDelegator( getXWeak() );
     osl_atomic_decrement(&m_refCount);
 }
 
@@ -1057,7 +1057,7 @@ void SwXShape::setPropertyValue(const OUString& 
rPropertyName, const uno::Any& a
     if(pEntry)
     {
         if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
-            throw beans::PropertyVetoException ("Property is read-only: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+            throw beans::PropertyVetoException ("Property is read-only: " + 
rPropertyName, getXWeak() );
         // with the layout it is possible to move the anchor without changing 
the position
         if(pFormat)
         {
@@ -1933,7 +1933,7 @@ void SwXShape::setPropertyToDefault( const OUString& 
rPropertyName )
     if(pEntry)
     {
         if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
-            throw uno::RuntimeException("Property is read-only: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+            throw uno::RuntimeException("Property is read-only: " + 
rPropertyName, getXWeak() );
         if(pFormat)
         {
             const SfxItemSet& rSet = pFormat->GetAttrSet();
@@ -2091,7 +2091,7 @@ void SwXShape::attach(const uno::Reference< 
text::XTextRange > & xTextRange)
             uno::Any aPos;
             aPos <<= xTextRange;
             setPropertyValue("TextRange", aPos);
-            uno::Reference< drawing::XShape > xTemp( 
static_cast<cppu::OWeakObject*>(this), uno::UNO_QUERY );
+            uno::Reference< drawing::XShape > xTemp( getXWeak(), 
uno::UNO_QUERY );
             xDP->add( xTemp );
         }
     }
diff --git a/sw/source/core/unocore/unofield.cxx 
b/sw/source/core/unocore/unofield.cxx
index cd493e615002..749678ec6b32 100644
--- a/sw/source/core/unocore/unofield.cxx
+++ b/sw/source/core/unocore/unofield.cxx
@@ -599,7 +599,7 @@ void SAL_CALL SwXFieldMaster::setPropertyValue(
             {
                 throw beans::UnknownPropertyException(
                     "Unknown property: " + rPropertyName,
-                    static_cast< cppu::OWeakObject * >( this ) );
+                    getXWeak() );
             }
 
             pType->PutValue( rValue, nMemberValueId );
@@ -756,7 +756,7 @@ void SAL_CALL SwXFieldMaster::setPropertyValue(
             }
             break;
         default:
-            throw beans::UnknownPropertyException( "Unknown property: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+            throw beans::UnknownPropertyException( "Unknown property: " + 
rPropertyName, getXWeak() );
         }
     }
 }
@@ -823,7 +823,7 @@ SwXFieldMaster::getPropertyValue(const OUString& 
rPropertyName)
             {
                 throw beans::UnknownPropertyException(
                         "Unknown property: " + rPropertyName,
-                        static_cast<cppu::OWeakObject *>(this));
+                        getXWeak());
             }
             pType->QueryValue( aRet, nMId );
 
@@ -904,7 +904,7 @@ SwXFieldMaster::getPropertyValue(const OUString& 
rPropertyName)
                 }
                 break;
             default:
-                throw beans::UnknownPropertyException( "Unknown property: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+                throw beans::UnknownPropertyException( "Unknown property: " + 
rPropertyName, getXWeak() );
             }
         }
     }
@@ -2141,9 +2141,9 @@ SwXTextField::setPropertyValue(
     const SfxItemPropertyMapEntry*   pEntry = 
_pPropSet->getPropertyMap().getByName(rPropertyName);
 
     if (!pEntry)
-        throw beans::UnknownPropertyException( "Unknown property: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+        throw beans::UnknownPropertyException( "Unknown property: " + 
rPropertyName, getXWeak() );
     if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
-        throw beans::PropertyVetoException( "Property is read-only: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+        throw beans::PropertyVetoException( "Property is read-only: " + 
rPropertyName, getXWeak() );
 
     if(pField)
     {
@@ -2306,7 +2306,7 @@ uno::Any SAL_CALL SwXTextField::getPropertyValue(const 
OUString& rPropertyName)
         pEntry = _pParaPropSet->getPropertyMap().getByName(rPropertyName);
     }
     if (!pEntry)
-        throw beans::UnknownPropertyException( "Unknown property: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+        throw beans::UnknownPropertyException( "Unknown property: " + 
rPropertyName, getXWeak() );
 
     switch( pEntry->nWID )
     {
@@ -2863,7 +2863,7 @@ SwXTextFieldTypes::~SwXTextFieldTypes()
 void SwXTextFieldTypes::Invalidate()
 {
     SwUnoCollection::Invalidate();
-    lang::EventObject const ev(static_cast< ::cppu::OWeakObject&>(*this));
+    lang::EventObject const ev(getXWeak());
     std::unique_lock aGuard(m_pImpl->m_Mutex);
     m_pImpl->m_RefreshListeners.disposeAndClear(aGuard, ev);
 }
@@ -2900,7 +2900,7 @@ void SAL_CALL SwXTextFieldTypes::refresh()
         GetDoc()->getIDocumentFieldsAccess().UpdateFields(false);
     }
     // call refresh listeners (without SolarMutex locked)
-    lang::EventObject const event(static_cast< ::cppu::OWeakObject*>(this));
+    lang::EventObject const event(getXWeak());
     std::unique_lock aGuard(m_pImpl->m_Mutex);
     m_pImpl->m_RefreshListeners.notifyEach(aGuard,
             & util::XRefreshListener::refreshed, event);
@@ -2986,7 +2986,7 @@ SwXFieldEnumeration::SwXFieldEnumeration(SwDoc & rDoc)
     IDocumentMarkAccess& rMarksAccess(*rDoc.getIDocumentMarkAccess());
     for (auto iter = rMarksAccess.getFieldmarksBegin(); iter != 
rMarksAccess.getFieldmarksEnd(); ++iter)
     {
-        
m_pImpl->m_Items.emplace_back(static_cast<cppu::OWeakObject*>(SwXFieldmark::CreateXFieldmark(rDoc,
 *iter).get()), uno::UNO_QUERY);
+        
m_pImpl->m_Items.emplace_back(cppu::getXWeak(SwXFieldmark::CreateXFieldmark(rDoc,
 *iter).get()), uno::UNO_QUERY);
     }
 }
 
diff --git a/sw/source/core/unocore/unoflatpara.cxx 
b/sw/source/core/unocore/unoflatpara.cxx
index c5c2ef94e441..ac3ebb4c6698 100644
--- a/sw/source/core/unocore/unoflatpara.cxx
+++ b/sw/source/core/unocore/unoflatpara.cxx
@@ -93,7 +93,7 @@ void SAL_CALL
 SwXFlatParagraph::setPropertyValue(const OUString&, const uno::Any&)
 {
     throw lang::IllegalArgumentException("no values can be set",
-            static_cast< ::cppu::OWeakObject*>(this), 0);
+            getXWeak(), 0);
 }
 
 uno::Any SAL_CALL
diff --git a/sw/source/core/unocore/unoframe.cxx 
b/sw/source/core/unocore/unoframe.cxx
index 329517cc11da..632b57698702 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -1287,7 +1287,7 @@ SwXFrame::CreateXFrame(SwDoc & rDoc, SwFrameFormat *const 
pFrameFormat)
                 : new NameLookupIsHard(&rDoc);
         if (pFrameFormat)
         {
-            
pFrameFormat->SetXObject(static_cast<cppu::OWeakObject*>(xFrame.get()));
+            pFrameFormat->SetXObject(cppu::getXWeak(xFrame.get()));
         }
         // need a permanent Reference to initialize m_wThis
         xFrame->SwXFrame::m_pImpl->m_wThis = 
uno::Reference<XWeak>(xFrame.get());
@@ -1426,7 +1426,7 @@ void SwXFrame::setPropertyValue(const OUString& 
rPropertyName, const ::uno::Any&
     {
         // Hack to skip the dummy CursorNotIgnoreTables property
         if (rPropertyName != "CursorNotIgnoreTables")
-            throw beans::UnknownPropertyException("Unknown property: " + 
rPropertyName, static_cast <cppu::OWeakObject*> (this));
+            throw beans::UnknownPropertyException("Unknown property: " + 
rPropertyName, getXWeak());
         return;
     }
 
@@ -1467,7 +1467,7 @@ void SwXFrame::setPropertyValue(const OUString& 
rPropertyName, const ::uno::Any&
     {
         bool bNextFrame = false;
         if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
-            throw beans::PropertyVetoException("Property is read-only: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+            throw beans::PropertyVetoException("Property is read-only: " + 
rPropertyName, getXWeak() );
 
         SwDoc* pDoc = pFormat->GetDoc();
         if ( ((m_eType == FLYCNTTYPE_GRF) && isGRFATR(pEntry->nWID)) ||
@@ -2014,7 +2014,7 @@ uno::Any SwXFrame::getPropertyValue(const OUString& 
rPropertyName)
     SwFrameFormat* pFormat = GetFrameFormat();
     const SfxItemPropertyMapEntry* pEntry = 
m_pPropSet->getPropertyMap().getByName(rPropertyName);
     if (!pEntry)
-        throw beans::UnknownPropertyException( "Unknown property: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+        throw beans::UnknownPropertyException( "Unknown property: " + 
rPropertyName, getXWeak() );
 
     const sal_uInt8 nMemberId(pEntry->nMemberId);
 
@@ -2444,7 +2444,7 @@ uno::Sequence< beans::PropertyState > 
SwXFrame::getPropertyStates(
         {
             const SfxItemPropertyMapEntry* pEntry = 
m_pPropSet->getPropertyMap().getByName(pNames[i]);
             if (!pEntry)
-                throw beans::UnknownPropertyException("Unknown property: " + 
pNames[i], static_cast < cppu::OWeakObject * > ( this ) );
+                throw beans::UnknownPropertyException("Unknown property: " + 
pNames[i], getXWeak() );
 
             if(pEntry->nWID == FN_UNO_ANCHOR_TYPES||
                 pEntry->nWID == FN_PARAM_LINK_DISPLAY_NAME||
@@ -2522,9 +2522,9 @@ void SwXFrame::setPropertyToDefault( const OUString& 
rPropertyName )
     {
         const SfxItemPropertyMapEntry* pEntry = 
m_pPropSet->getPropertyMap().getByName(rPropertyName);
         if (!pEntry)
-            throw beans::UnknownPropertyException( "Unknown property: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+            throw beans::UnknownPropertyException( "Unknown property: " + 
rPropertyName, getXWeak() );
         if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
-            throw uno::RuntimeException("setPropertyToDefault: property is 
read-only: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+            throw uno::RuntimeException("setPropertyToDefault: property is 
read-only: " + rPropertyName, getXWeak() );
 
         if(OWN_ATTR_FILLBMP_MODE == pEntry->nWID)
         {
@@ -2614,7 +2614,7 @@ uno::Any SwXFrame::getPropertyDefault( const OUString& 
rPropertyName )
     {
         const SfxItemPropertyMapEntry* pEntry = 
m_pPropSet->getPropertyMap().getByName(rPropertyName);
         if(!pEntry)
-            throw beans::UnknownPropertyException( "Unknown property: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+            throw beans::UnknownPropertyException( "Unknown property: " + 
rPropertyName, getXWeak() );
 
         if ( pEntry->nWID < RES_FRMATR_END )
         {
diff --git a/sw/source/core/unocore/unoidx.cxx 
b/sw/source/core/unocore/unoidx.cxx
index 594778768cc0..2505050d8cae 100644
--- a/sw/source/core/unocore/unoidx.cxx
+++ b/sw/source/core/unocore/unoidx.cxx
@@ -375,7 +375,7 @@ void SwXDocumentIndex::Impl::Notify(const SfxHint& rHint)
             return;
         }
         std::unique_lock g(m_Mutex);
-        lang::EventObject const 
ev(static_cast<cppu::OWeakObject*>(xThis.get()));
+        lang::EventObject const ev(xThis->getXWeak());
         m_RefreshListeners.disposeAndClear(g, ev);
         m_EventListeners.disposeAndClear(g, ev);
     }
@@ -416,7 +416,7 @@ SwXDocumentIndex::CreateXDocumentIndex(
                 : new SwXDocumentIndex(eTypes, rDoc);
         if (pSection)
         {
-            
pSection->GetFormat()->SetXObject(static_cast<cppu::OWeakObject*>(xIndex.get()));
+            pSection->GetFormat()->SetXObject(xIndex->getXWeak());
         }
         // need a permanent Reference to initialize m_wThis
         xIndex->m_pImpl->m_wThis = xIndex.get();
@@ -523,13 +523,13 @@ SwXDocumentIndex::setPropertyValue(
     {
         throw beans::UnknownPropertyException(
             "Unknown property: " + rPropertyName,
-            static_cast<cppu::OWeakObject *>(this));
+            getXWeak());
     }
     if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
     {
         throw beans::PropertyVetoException(
             "Property is read-only: " + rPropertyName,
-            static_cast<cppu::OWeakObject *>(this));
+            getXWeak());
     }
 
     SwSectionFormat *const pSectionFormat(m_pImpl->GetSectionFormat());
@@ -873,7 +873,7 @@ SwXDocumentIndex::getPropertyValue(const OUString& 
rPropertyName)
     {
         throw beans::UnknownPropertyException(
             "Unknown property: " + rPropertyName,
-            static_cast< cppu::OWeakObject * >(this));
+            getXWeak());
     }
     // TODO: is this the best approach to tell API clients about the change?
     if (pEntry->nWID == RES_BACKGROUND && pEntry->nMemberId == MID_GRAPHIC_URL)
@@ -1271,7 +1271,7 @@ void SAL_CALL SwXDocumentIndex::refresh()
         {
             throw uno::RuntimeException(
                     "SwXDocumentIndex::refresh: must be in attached state",
-                     static_cast< ::cppu::OWeakObject*>(this));
+                     getXWeak());
         }
         pTOXBase->Update(nullptr, 
m_pImpl->m_pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
 
@@ -1285,7 +1285,7 @@ void SAL_CALL SwXDocumentIndex::refresh()
     std::unique_lock g(m_pImpl->m_Mutex);
     if (m_pImpl->m_RefreshListeners.getLength(g))
     {
-        lang::EventObject const event(static_cast< 
::cppu::OWeakObject*>(this));
+        lang::EventObject const event(getXWeak());
         m_pImpl->m_RefreshListeners.notifyEach(g, & 
util::XRefreshListener::refreshed, event);
     }
 }
@@ -1353,7 +1353,7 @@ SwXDocumentIndex::attach(const uno::Reference< 
text::XTextRange > & xTextRange)
 
     // update page numbers
     m_pImpl->SetSectionFormat(*pTOX->GetFormat());
-    pTOX->GetFormat()->SetXObject(static_cast< ::cppu::OWeakObject*>(this));
+    pTOX->GetFormat()->SetXObject(getXWeak());
     pTOX->UpdatePageNum();
 
     m_pImpl->m_oProps.reset();
@@ -1575,8 +1575,7 @@ public:
             InsertTOXMark(rTOXType, rMark, rPam, nullptr);
         } catch (...) {
             OSL_FAIL("ReplaceTOXMark() failed!");
-            lang::EventObject const ev(
-                    static_cast< ::cppu::OWeakObject&>(m_rThis));
+            lang::EventObject const ev(m_rThis.getXWeak());
             std::unique_lock aGuard(m_Mutex);
             m_EventListeners.disposeAndClear(aGuard, ev);
             throw;
@@ -1595,7 +1594,7 @@ void SwXDocumentIndexMark::Impl::Invalidate()
         // fdo#72695: if UNO object is already dead, don't revive it with event
         if (xThis.is())
         {
-            lang::EventObject const 
ev(static_cast<cppu::OWeakObject*>(xThis.get()));
+            lang::EventObject const ev(xThis->getXWeak());
             std::unique_lock aGuard(m_Mutex);
             m_EventListeners.disposeAndClear(aGuard, ev);
         }
@@ -2051,13 +2050,13 @@ SwXDocumentIndexMark::setPropertyValue(
     {
         throw beans::UnknownPropertyException(
             "Unknown property: " + rPropertyName,
-            static_cast<cppu::OWeakObject *>(this));
+            getXWeak());
     }
     if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
     {
         throw beans::PropertyVetoException(
             "Property is read-only: " + rPropertyName,
-            static_cast<cppu::OWeakObject *>(this));
+            getXWeak());
     }
 
     SwTOXType *const pType = m_pImpl->GetTOXType();
@@ -2180,7 +2179,7 @@ SwXDocumentIndexMark::getPropertyValue(const OUString& 
rPropertyName)
     {
         throw beans::UnknownPropertyException(
             "Unknown property: " + rPropertyName,
-            static_cast<cppu::OWeakObject *>(this));
+            getXWeak());
     }
     if (::sw::GetDefaultTextContentValue(aRet, rPropertyName, pEntry->nWID))
     {
diff --git a/sw/source/core/unocore/unoobj.cxx 
b/sw/source/core/unocore/unoobj.cxx
index be8584202d78..b2f83fee30ea 100644
--- a/sw/source/core/unocore/unoobj.cxx
+++ b/sw/source/core/unocore/unoobj.cxx
@@ -1862,8 +1862,7 @@ uno::Any SwUnoCursorHelper::GetPropertyValue(
     if (!pEntry)
     {
         throw beans::UnknownPropertyException(
-            OUString::Concat("Unknown property: ") + rPropertyName,
-            static_cast<cppu::OWeakObject *>(nullptr));
+            OUString::Concat("Unknown property: ") + rPropertyName);
     }
 
     beans::PropertyState eTemp;
@@ -1992,9 +1991,9 @@ void SwUnoCursorHelper::SetPropertyValues(
     }
 
     if (!aUnknownExMsg.isEmpty())
-        throw beans::UnknownPropertyException(aUnknownExMsg, 
static_cast<cppu::OWeakObject *>(nullptr));
+        throw beans::UnknownPropertyException(aUnknownExMsg);
     if (!aPropertyVetoExMsg.isEmpty())
-        throw beans::PropertyVetoException(aPropertyVetoExMsg, 
static_cast<cppu::OWeakObject *>(nullptr));
+        throw beans::PropertyVetoException(aPropertyVetoExMsg);
 }
 
 namespace
@@ -2041,8 +2040,7 @@ SwUnoCursorHelper::GetPropertyStates(
             else
             {
                 throw beans::UnknownPropertyException(
-                    "Unknown property: " + pNames[i],
-                    static_cast<cppu::OWeakObject *>(nullptr));
+                    "Unknown property: " + pNames[i]);
             }
         }
         if (((SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION == eCaller)  ||
@@ -2155,8 +2153,7 @@ void SwUnoCursorHelper::SetPropertyToDefault(
     if (!pEntry)
     {
         throw beans::UnknownPropertyException(
-            OUString::Concat("Unknown property: ") + rPropertyName,
-            static_cast<cppu::OWeakObject *>(nullptr));
+            OUString::Concat("Unknown property: ") + rPropertyName);
     }
 
     if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
@@ -2193,8 +2190,7 @@ uno::Any SwUnoCursorHelper::GetPropertyDefault(
     if (!pEntry)
     {
         throw beans::UnknownPropertyException(
-            OUString::Concat("Unknown property: ") + rPropertyName,
-            static_cast<cppu::OWeakObject *>(nullptr));
+            OUString::Concat("Unknown property: ") + rPropertyName);
     }
 
     uno::Any aRet;
@@ -2582,13 +2578,13 @@ SwXTextCursor::setPropertiesToDefault(
             }
             throw beans::UnknownPropertyException(
                 "Unknown property: " + rName,
-                static_cast<cppu::OWeakObject *>(this));
+                getXWeak());
         }
         if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
         {
             throw uno::RuntimeException(
                 "setPropertiesToDefault: property is read-only: " + rName,
-                static_cast<cppu::OWeakObject *>(this));
+                getXWeak());
         }
 
         if (pEntry->nWID < RES_FRMATR_END)
@@ -2646,8 +2642,7 @@ SwXTextCursor::getPropertyDefaults(
                     continue;
                 }
                 throw beans::UnknownPropertyException(
-                    "Unknown property: " + pNames[i],
-                    static_cast<cppu::OWeakObject *>(nullptr));
+                    "Unknown property: " + pNames[i]);
             }
             if (pEntry->nWID < RES_FRMATR_END)
             {
diff --git a/sw/source/core/unocore/unoparagraph.cxx 
b/sw/source/core/unocore/unoparagraph.cxx
index 198f23ff2272..68dbe34f55d5 100644
--- a/sw/source/core/unocore/unoparagraph.cxx
+++ b/sw/source/core/unocore/unoparagraph.cxx
@@ -389,12 +389,12 @@ void SwXParagraph::Impl::SetPropertyValues_Impl(
             if (SfxItemPropertyMapEntry const* const pEntry = 
rMap.getByName(name); !pEntry)
             {
                 throw beans::UnknownPropertyException("Unknown property: " + 
name,
-                                                      
static_cast<cppu::OWeakObject*>(&m_rThis));
+                                                      m_rThis.getXWeak());
             }
             else if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
             {
                 throw beans::PropertyVetoException("Property is read-only: " + 
name,
-                                                   
static_cast<cppu::OWeakObject*>(&m_rThis));
+                                                   m_rThis.getXWeak());
             }
             return comphelper::makePropertyValue(name, value);
         });
@@ -407,7 +407,7 @@ void SAL_CALL SwXParagraph::setPropertyValues(
 {
     if (rPropertyNames.getLength() != rValues.getLength())
         throw lang::IllegalArgumentException("lengths do not match",
-                                             
static_cast<cppu::OWeakObject*>(this), -1);
+                                             getXWeak(), -1);
 
     SolarMutexGuard aGuard;
 
@@ -556,7 +556,7 @@ uno::Sequence< uno::Any > 
SwXParagraph::Impl::GetPropertyValues_Impl(
         {
             throw beans::UnknownPropertyException(
                 "Unknown property: " + pPropertyNames[nProp],
-                static_cast< cppu::OWeakObject * >(&m_rThis));
+                m_rThis.getXWeak());
         }
         if (! ::sw::GetDefaultTextContentValue(
                 pValues[nProp], pPropertyNames[nProp], pEntry->nWID))
@@ -588,13 +588,13 @@ SwXParagraph::getPropertyValues(const uno::Sequence< 
OUString >& rPropertyNames)
     {
         css::uno::Any anyEx = cppu::getCaughtException();
         throw css::lang::WrappedTargetRuntimeException("Unknown property 
exception caught",
-                static_cast < cppu::OWeakObject * > ( this ), anyEx );
+                getXWeak(), anyEx );
     }
     catch (lang::WrappedTargetException &)
     {
         css::uno::Any anyEx = cppu::getCaughtException();
         throw css::lang::WrappedTargetRuntimeException("WrappedTargetException 
caught",
-                static_cast < cppu::OWeakObject * > ( this ), anyEx );
+                getXWeak(), anyEx );
     }
 
     return aValues;
@@ -1031,7 +1031,7 @@ SwXParagraph::getPropertyState(const OUString& 
rPropertyName)
     {
         throw beans::UnknownPropertyException(
             "Unknown property: " + rPropertyName,
-            static_cast<cppu::OWeakObject *>(this));
+            getXWeak());
     }
     bool bDummy = false;
     const beans::PropertyState eRet =
@@ -1063,7 +1063,7 @@ SwXParagraph::getPropertyStates(
         {
             throw beans::UnknownPropertyException(
                 "Unknown property: " + *pNames,
-                static_cast<cppu::OWeakObject *>(this));
+                getXWeak());
         }
 
         if (bAttrSetFetched && !pSet && isATR(pEntry->nWID))
@@ -1104,14 +1104,14 @@ SwXParagraph::setPropertyToDefault(const OUString& 
rPropertyName)
     {
         throw beans::UnknownPropertyException(
             "Unknown property: " + rPropertyName,
-            static_cast<cppu::OWeakObject *>(this));
+            getXWeak());
     }
 
     if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
     {
         throw uno::RuntimeException(
             "Property is read-only: " + rPropertyName,
-            static_cast<cppu::OWeakObject *>(this));
+            getXWeak());
     }
 
     const bool bBelowFrameAtrEnd(pEntry->nWID < RES_FRMATR_END);
@@ -1187,7 +1187,7 @@ SwXParagraph::getPropertyDefault(const OUString& 
rPropertyName)
     {
         throw beans::UnknownPropertyException(
             "Unknown property: " + rPropertyName,
-            static_cast<cppu::OWeakObject *>(this));
+            getXWeak());
     }
 
     const bool bBelowFrameAtrEnd(pEntry->nWID < RES_FRMATR_END);
@@ -1237,7 +1237,7 @@ void SAL_CALL SwXParagraph::dispose()
     {
         SwCursor aCursor( SwPosition( *pTextNode ), nullptr );
         
pTextNode->GetDoc().getIDocumentContentOperations().DelFullPara(aCursor);
-        lang::EventObject const ev(static_cast< ::cppu::OWeakObject&>(*this));
+        lang::EventObject const ev(getXWeak());
         std::unique_lock aGuard2(m_pImpl->m_Mutex);
         m_pImpl->m_EventListeners.disposeAndClear(aGuard2, ev);
     }
diff --git a/sw/source/core/unocore/unoport.cxx 
b/sw/source/core/unocore/unoport.cxx
index 80de35b5f381..cfbe918ba2bb 100644
--- a/sw/source/core/unocore/unoport.cxx
+++ b/sw/source/core/unocore/unoport.cxx
@@ -427,7 +427,7 @@ uno::Sequence< uno::Any > 
SwXTextPortion::GetPropertyValues_Impl(
         {
             const SfxItemPropertyMapEntry* pEntry = 
rMap.getByName(pPropertyNames[nProp]);
             if(!pEntry)
-                throw beans::UnknownPropertyException( "Unknown property: " + 
pPropertyNames[nProp], static_cast < cppu::OWeakObject * > ( this ) );
+                throw beans::UnknownPropertyException( "Unknown property: " + 
pPropertyNames[nProp], getXWeak() );
             GetPropertyValue( pValues[nProp], *pEntry, &rUnoCursor, pSet );
         }
     }
@@ -448,7 +448,7 @@ void SwXTextPortion::SetPropertyValues_Impl(
 {
     if (rPropertyNames.getLength() != rValues.getLength())
         throw lang::IllegalArgumentException("lengths do not match",
-                                             
static_cast<cppu::OWeakObject*>(this), -1);
+                                             getXWeak(), -1);
 
     SwUnoCursor& rUnoCursor = GetCursor();
 
@@ -462,9 +462,9 @@ void SwXTextPortion::SetPropertyValues_Impl(
         {
             const SfxItemPropertyMapEntry* pEntry = 
rMap.getByName(pPropertyNames[nProp]);
             if (!pEntry)
-                throw beans::UnknownPropertyException( "Unknown property: " + 
pPropertyNames[nProp], static_cast < cppu::OWeakObject * > ( this ) );
+                throw beans::UnknownPropertyException( "Unknown property: " + 
pPropertyNames[nProp], getXWeak() );
             if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
-                throw beans::PropertyVetoException ("Property is read-only: " 
+ pPropertyNames[nProp], static_cast < cppu::OWeakObject * > ( this ) );
+                throw beans::PropertyVetoException ("Property is read-only: " 
+ pPropertyNames[nProp], getXWeak() );
 
             aValuesRange[nProp].Name = pPropertyNames[nProp];
             aValuesRange[nProp].Value = pValues[nProp];
@@ -509,13 +509,13 @@ uno::Sequence< uno::Any > 
SwXTextPortion::getPropertyValues(
     {
         css::uno::Any anyEx = cppu::getCaughtException();
         throw lang::WrappedTargetRuntimeException("Unknown property exception 
caught",
-                static_cast < cppu::OWeakObject * > ( this ), anyEx );
+                getXWeak(), anyEx );
     }
     catch (lang::WrappedTargetException &)
     {
         css::uno::Any anyEx = cppu::getCaughtException();
         throw lang::WrappedTargetRuntimeException("WrappedTargetException 
caught",
-                static_cast < cppu::OWeakObject * > ( this ), anyEx );
+                getXWeak(), anyEx );
     }
 
     return aValues;
@@ -675,7 +675,7 @@ uno::Sequence< beans::GetDirectPropertyTolerantResult > 
SwXTextPortion::GetPrope
                 {
                     const SfxItemPropertyMapEntry* pEntry = 
rPropMap.getByName( pProp[i] );
                     if (!pEntry)
-                        throw beans::UnknownPropertyException( "Unknown 
property: " + pProp[i], static_cast < cppu::OWeakObject * > ( this ) );
+                        throw beans::UnknownPropertyException( "Unknown 
property: " + pProp[i], getXWeak() );
                     aResult.State  = pPropertyStates[i];
 
                     aResult.Result = 
beans::TolerantPropertySetResultType::UNKNOWN_FAILURE;
diff --git a/sw/source/core/unocore/unorefmk.cxx 
b/sw/source/core/unocore/unorefmk.cxx
index feb403c05f0d..b86fbc675730 100644
--- a/sw/source/core/unocore/unorefmk.cxx
+++ b/sw/source/core/unocore/unorefmk.cxx
@@ -855,7 +855,7 @@ SwXMeta::dispose()
     if (m_pImpl->m_bIsDescriptor)
     {
         m_pImpl->m_pTextPortions.reset();
-        lang::EventObject const ev(static_cast< ::cppu::OWeakObject&>(*this));
+        lang::EventObject const ev(getXWeak());
         std::unique_lock aGuard(m_pImpl->m_Mutex);
         m_pImpl->m_EventListeners.disposeAndClear(aGuard, ev);
         m_pImpl->m_bIsDisposed = true;
@@ -895,7 +895,7 @@ SwXMeta::AttachImpl(const uno::Reference< text::XTextRange 
> & i_xTextRange,
     {
         throw uno::RuntimeException(
             "SwXMeta::attach(): already attached",
-            static_cast< ::cppu::OWeakObject* >(this));
+            getXWeak());
     }
 
     SwXTextRange *const 
pRange(dynamic_cast<SwXTextRange*>(i_xTextRange.get()));
@@ -904,7 +904,7 @@ SwXMeta::AttachImpl(const uno::Reference< text::XTextRange 
> & i_xTextRange,
     {
         throw lang::IllegalArgumentException(
             "SwXMeta::attach(): argument not supported type",
-            static_cast< ::cppu::OWeakObject* >(this), 0);
+            getXWeak(), 0);
     }
 
     SwDoc * const pDoc(
@@ -913,7 +913,7 @@ SwXMeta::AttachImpl(const uno::Reference< text::XTextRange 
> & i_xTextRange,
     {
         throw lang::IllegalArgumentException(
             "SwXMeta::attach(): argument has no SwDoc",
-            static_cast< ::cppu::OWeakObject* >(this), 0);
+            getXWeak(), 0);
     }
 
     SwUnoInternalPaM aPam(*pDoc);
@@ -940,14 +940,14 @@ SwXMeta::AttachImpl(const uno::Reference< 
text::XTextRange > & i_xTextRange,
     {
         throw lang::IllegalArgumentException(
             "SwXMeta::attach(): cannot create meta: range invalid?",
-            static_cast< ::cppu::OWeakObject* >(this), 1);
+            getXWeak(), 1);
     }
     if (!pTextAttr)
     {
         OSL_FAIL("meta inserted, but has no text attribute?");
         throw uno::RuntimeException(
             "SwXMeta::attach(): cannot create meta",
-            static_cast< ::cppu::OWeakObject* >(this));
+            getXWeak());
     }
 
     m_pImpl->EndListeningAll();
@@ -980,7 +980,7 @@ SwXMeta::getAnchor()
     {
         throw uno::RuntimeException(
                 "SwXMeta::getAnchor(): not inserted",
-                static_cast< ::cppu::OWeakObject* >(this));
+                getXWeak());
     }
 
     SwTextNode * pTextNode;
@@ -992,7 +992,7 @@ SwXMeta::getAnchor()
     {
         throw lang::DisposedException(
                 "SwXMeta::getAnchor(): not attached",
-                static_cast< ::cppu::OWeakObject* >(this));
+                getXWeak());
     }
 
     const SwPosition start(*pTextNode, nMetaStart - 1); // -1 due to CH_TXTATR
@@ -1138,7 +1138,7 @@ SwXMeta::createEnumeration()
     {
         throw uno::RuntimeException(
                 "createEnumeration(): not inserted",
-                static_cast< ::cppu::OWeakObject* >(this));
+                getXWeak());
     }
 
     SwTextNode * pTextNode;
diff --git a/sw/source/core/unocore/unosect.cxx 
b/sw/source/core/unocore/unosect.cxx
index 490bd8d1c435..4439862002d3 100644
--- a/sw/source/core/unocore/unosect.cxx
+++ b/sw/source/core/unocore/unosect.cxx
@@ -389,10 +389,10 @@ SwXTextSection::attach(const uno::Reference< 
text::XTextRange > & xTextRange)
         pDoc->GetIDocumentUndoRedo().EndUndo( SwUndoId::INSSECTION, nullptr );
         throw lang::IllegalArgumentException(
                 "SwXTextSection::attach(): invalid TextRange",
-                static_cast< ::cppu::OWeakObject*>(this), 0);
+                getXWeak(), 0);
     }
     m_pImpl->Attach(pRet->GetFormat());
-    pRet->GetFormat()->SetXObject(static_cast<cppu::OWeakObject*>(this));
+    pRet->GetFormat()->SetXObject(getXWeak());
 
     // XML import must hide sections depending on their old
     //         condition status
@@ -583,13 +583,13 @@ void SwXTextSection::Impl::SetPropertyValues_Impl(
         {
             throw beans::UnknownPropertyException(
                 "Unknown property: " + pPropertyNames[nProperty],
-                static_cast<cppu::OWeakObject *>(& m_rThis));
+                m_rThis.getXWeak());
         }
         if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
         {
             throw beans::PropertyVetoException(
                 "Property is read-only: " + pPropertyNames[nProperty],
-                static_cast<cppu::OWeakObject *>(& m_rThis));
+                m_rThis.getXWeak());
         }
         switch (pEntry->nWID)
         {
@@ -963,7 +963,7 @@ SwXTextSection::Impl::GetPropertyValues_Impl(
         {
             throw beans::UnknownPropertyException(
                 "Unknown property: " + pPropertyNames[nProperty],
-                static_cast<cppu::OWeakObject *>(& m_rThis));
+                m_rThis.getXWeak());
         }
         switch(pEntry->nWID)
         {
@@ -1260,13 +1260,13 @@ SwXTextSection::getPropertyValues(
     {
         css::uno::Any anyEx = cppu::getCaughtException();
         throw lang::WrappedTargetRuntimeException("Unknown property exception 
caught",
-                static_cast < cppu::OWeakObject * > ( this ), anyEx );
+                getXWeak(), anyEx );
     }
     catch (lang::WrappedTargetException &)
     {
         css::uno::Any anyEx = cppu::getCaughtException();
         throw lang::WrappedTargetRuntimeException("WrappedTargetException 
caught",
-                static_cast < cppu::OWeakObject * > ( this ), anyEx );
+                getXWeak(), anyEx );
     }
 
     return aValues;
@@ -1366,7 +1366,7 @@ SwXTextSection::getPropertyStates(
         {
             throw beans::UnknownPropertyException(
                 "Unknown property: " + pNames[i],
-                static_cast< cppu::OWeakObject* >(this));
+                getXWeak());
         }
         switch (pEntry->nWID)
         {
@@ -1441,13 +1441,13 @@ SwXTextSection::setPropertyToDefault(const OUString& 
rPropertyName)
     {
         throw beans::UnknownPropertyException(
             "Unknown property: " + rPropertyName,
-            static_cast< cppu::OWeakObject* >(this));
+            getXWeak());
     }
     if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
     {
         throw uno::RuntimeException(
             "Property is read-only: " + rPropertyName,
-            static_cast<cppu::OWeakObject *>(this));
+            getXWeak());
     }
 
     std::unique_ptr<SwSectionData> const pSectionData(
@@ -1579,7 +1579,7 @@ SwXTextSection::getPropertyDefault(const OUString& 
rPropertyName)
     {
         throw beans::UnknownPropertyException(
             "Unknown property: " + rPropertyName,
-            static_cast<cppu::OWeakObject *>(this));
+            getXWeak());
     }
 
     switch(pEntry->nWID)
diff --git a/sw/source/core/unocore/unosett.cxx 
b/sw/source/core/unocore/unosett.cxx
index 2430bf35fa49..1f25b8989402 100644
--- a/sw/source/core/unocore/unosett.cxx
+++ b/sw/source/core/unocore/unosett.cxx
@@ -287,10 +287,10 @@ void SwXFootnoteProperties::setPropertyValue(const 
OUString& rPropertyName, cons
 
     const SfxItemPropertyMapEntry*  pEntry = 
m_pPropertySet->getPropertyMap().getByName( rPropertyName );
     if(!pEntry)
-        throw beans::UnknownPropertyException("Unknown property: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+        throw beans::UnknownPropertyException("Unknown property: " + 
rPropertyName, getXWeak() );
 
     if ( pEntry->nFlags & PropertyAttribute::READONLY)
-        throw PropertyVetoException("Property is read-only: " + rPropertyName, 
static_cast < cppu::OWeakObject * > ( this ) );
+        throw PropertyVetoException("Property is read-only: " + rPropertyName, 
getXWeak() );
     SwFootnoteInfo aFootnoteInfo(m_pDoc->GetFootnoteInfo());
     switch(pEntry->nWID)
     {
@@ -408,7 +408,7 @@ uno::Any SwXFootnoteProperties::getPropertyValue(const 
OUString& rPropertyName)
 
     const SfxItemPropertyMapEntry*  pEntry = 
m_pPropertySet->getPropertyMap().getByName( rPropertyName );
     if(!pEntry)
-        throw UnknownPropertyException("Unknown property: " + rPropertyName, 
static_cast < cppu::OWeakObject * > ( this ) );
+        throw UnknownPropertyException("Unknown property: " + rPropertyName, 
getXWeak() );
 
     const SwFootnoteInfo& rFootnoteInfo = m_pDoc->GetFootnoteInfo();
     switch(pEntry->nWID)
@@ -566,10 +566,10 @@ void SwXEndnoteProperties::setPropertyValue(const 
OUString& rPropertyName, const
 
     const SfxItemPropertyMapEntry*  pEntry = 
m_pPropertySet->getPropertyMap().getByName( rPropertyName );
     if(!pEntry)
-        throw UnknownPropertyException("Unknown property: " + rPropertyName, 
static_cast < cppu::OWeakObject * > ( this ) );
+        throw UnknownPropertyException("Unknown property: " + rPropertyName, 
getXWeak() );
 
     if ( pEntry->nFlags & PropertyAttribute::READONLY)
-        throw PropertyVetoException("Property is read-only: " + rPropertyName, 
static_cast < cppu::OWeakObject * > ( this ) );
+        throw PropertyVetoException("Property is read-only: " + rPropertyName, 
getXWeak() );
     SwEndNoteInfo aEndInfo(m_pDoc->GetEndNoteInfo());
     switch(pEntry->nWID)
     {
@@ -640,7 +640,7 @@ uno::Any SwXEndnoteProperties::getPropertyValue(const 
OUString& rPropertyName)
     {
         const SfxItemPropertyMapEntry*  pEntry = 
m_pPropertySet->getPropertyMap().getByName( rPropertyName );
         if(!pEntry)
-            throw UnknownPropertyException("Unknown property: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+            throw UnknownPropertyException("Unknown property: " + 
rPropertyName, getXWeak() );
 
         const SwEndNoteInfo& rEndInfo = m_pDoc->GetEndNoteInfo();
         switch(pEntry->nWID)
@@ -769,10 +769,10 @@ void SwXLineNumberingProperties::setPropertyValue(
 
     const SfxItemPropertyMapEntry*  pEntry = 
m_pPropertySet->getPropertyMap().getByName( rPropertyName );
     if(!pEntry)
-        throw UnknownPropertyException("Unknown property: " + rPropertyName, 
static_cast < cppu::OWeakObject * > ( this ) );
+        throw UnknownPropertyException("Unknown property: " + rPropertyName, 
getXWeak() );
 
     if ( pEntry->nFlags & PropertyAttribute::READONLY)
-        throw PropertyVetoException("Property is read-only: " + rPropertyName, 
static_cast < cppu::OWeakObject * > ( this ) );
+        throw PropertyVetoException("Property is read-only: " + rPropertyName, 
getXWeak() );
     SwLineNumberInfo  aFontMetric(m_pDoc->GetLineNumberInfo());
     switch(pEntry->nWID)
     {
@@ -883,7 +883,7 @@ Any SwXLineNumberingProperties::getPropertyValue(const 
OUString& rPropertyName)
 
     const SfxItemPropertyMapEntry*  pEntry = 
m_pPropertySet->getPropertyMap().getByName( rPropertyName );
     if(!pEntry)
-        throw UnknownPropertyException("Unknown property: " + rPropertyName, 
static_cast < cppu::OWeakObject * > ( this ) );
+        throw UnknownPropertyException("Unknown property: " + rPropertyName, 
getXWeak() );
 
     const SwLineNumberInfo& rInfo = m_pDoc->GetLineNumberInfo();
     switch(pEntry->nWID)
diff --git a/sw/source/core/unocore/unosrch.cxx 
b/sw/source/core/unocore/unosrch.cxx
index f4ec332be90b..d41dccb0d07d 100644
--- a/sw/source/core/unocore/unosrch.cxx
+++ b/sw/source/core/unocore/unosrch.cxx
@@ -417,10 +417,10 @@ void SwXTextSearch::setPropertyValue(const OUString& 
rPropertyName, const uno::A
     SolarMutexGuard aGuard;
     const SfxItemPropertyMapEntry*  pEntry = 
m_pPropSet->getPropertyMap().getByName(rPropertyName);
     if(!pEntry)
-        throw beans::UnknownPropertyException("Unknown property: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+        throw beans::UnknownPropertyException("Unknown property: " + 
rPropertyName, getXWeak() );
 
     if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
-        throw beans::PropertyVetoException ("Property is read-only: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+        throw beans::PropertyVetoException ("Property is read-only: " + 
rPropertyName, getXWeak() );
     bool bVal = false;
     if(auto b = o3tl::tryAccess<bool>(aValue))
         bVal = *b;
@@ -450,7 +450,7 @@ uno::Any SwXTextSearch::getPropertyValue(const OUString& 
rPropertyName)
     const SfxItemPropertyMapEntry*  pEntry = 
m_pPropSet->getPropertyMap().getByName(rPropertyName);
     bool bSet = false;
     if(!pEntry)
-        throw beans::UnknownPropertyException("Unknown property: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+        throw beans::UnknownPropertyException("Unknown property: " + 
rPropertyName, getXWeak() );
 
     sal_Int16 nSet = 0;
     switch(pEntry->nWID)
diff --git a/sw/source/core/unocore/unostyle.cxx 
b/sw/source/core/unocore/unostyle.cxx
index 3be1ad0e23ec..94219281b562 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -1213,7 +1213,7 @@ void XStyleFamily::removeByName(const OUString& rName)
 uno::Any SAL_CALL XStyleFamily::getPropertyValue( const OUString& 
sPropertyName )
 {
     if(sPropertyName != "DisplayName")
-        throw beans::UnknownPropertyException( "unknown property: " + 
sPropertyName, static_cast<OWeakObject *>(this) );
+        throw beans::UnknownPropertyException( "unknown property: " + 
sPropertyName, getXWeak() );
     SolarMutexGuard aGuard;
     return uno::Any(SwResId(m_rEntry.resId()));
 }
@@ -2049,9 +2049,9 @@ void SwXStyle::SetPropertyValues_Impl(const 
uno::Sequence<OUString>& rPropertyNa
     {
         const SfxItemPropertyMapEntry* pEntry = rMap.getByName(pNames[nProp]);
         if(!pEntry || (!m_bIsConditional && pNames[nProp] == 
UNO_NAME_PARA_STYLE_CONDITIONS))
-            throw beans::UnknownPropertyException("Unknown property: " + 
pNames[nProp], static_cast<cppu::OWeakObject*>(this));
+            throw beans::UnknownPropertyException("Unknown property: " + 
pNames[nProp], getXWeak());
         if(pEntry->nFlags & beans::PropertyAttribute::READONLY)
-            throw beans::PropertyVetoException ("Property is read-only: " + 
pNames[nProp], static_cast<cppu::OWeakObject*>(this));
+            throw beans::PropertyVetoException ("Property is read-only: " + 
pNames[nProp], getXWeak());
         if(aBaseImpl.getNewBase().is())
             SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl);
         else if(!m_pPropertiesImpl->SetProperty(pNames[nProp], pValues[nProp]))
@@ -2362,7 +2362,7 @@ uno::Any SwXStyle::GetPropertyValue_Impl(const 
SfxItemPropertySet* pPropSet, SwS
     const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
     const SfxItemPropertyMapEntry* pEntry = rMap.getByName(rPropertyName);
     if(!pEntry || (!m_bIsConditional && rPropertyName == 
UNO_NAME_PARA_STYLE_CONDITIONS))
-        throw beans::UnknownPropertyException("Unknown property: " + 
rPropertyName, static_cast<cppu::OWeakObject*>(this));
+        throw beans::UnknownPropertyException("Unknown property: " + 
rPropertyName, getXWeak());
     if(m_pBasePool)
         return GetStyleProperty_Impl(*pEntry, *pPropSet, rBase);
     const uno::Any* pAny = nullptr;
@@ -2435,13 +2435,13 @@ uno::Sequence<uno::Any> 
SwXStyle::getPropertyValues(const uno::Sequence<OUString
     {
         css::uno::Any anyEx = cppu::getCaughtException();
         throw css::lang::WrappedTargetRuntimeException("Unknown property 
exception caught",
-                static_cast < cppu::OWeakObject * > ( this ), anyEx );
+                getXWeak(), anyEx );
     }
     catch(lang::WrappedTargetException&)
     {
         css::uno::Any anyEx = cppu::getCaughtException();
         throw lang::WrappedTargetRuntimeException("WrappedTargetException 
caught",
-                static_cast < cppu::OWeakObject * > ( this ), anyEx );
+                getXWeak(), anyEx );
     }
     return aValues;
 }
@@ -2504,7 +2504,7 @@ uno::Sequence<beans::PropertyState> 
SwXStyle::getPropertyStates(const uno::Seque
         const SfxItemPropertyMapEntry* pEntry = rMap.getByName(sPropName);
 
         if(!pEntry)
-            throw beans::UnknownPropertyException("Unknown property: " + 
sPropName, static_cast<cppu::OWeakObject*>(this));
+            throw beans::UnknownPropertyException("Unknown property: " + 
sPropName, getXWeak());
 
         if (FN_UNO_NUM_RULES == pEntry->nWID || FN_UNO_FOLLOW_STYLE == 
pEntry->nWID
             || pEntry->nWID == FN_UNO_LINK_STYLE)
@@ -2634,12 +2634,12 @@ void SAL_CALL SwXStyle::setPropertiesToDefault(const 
uno::Sequence<OUString>& aP
     {
         const SfxItemPropertyMapEntry* pEntry = rMap.getByName(rName);
         if(!pEntry)
-            throw beans::UnknownPropertyException("Unknown property: " + 
rName, static_cast<cppu::OWeakObject*>(this));
+            throw beans::UnknownPropertyException("Unknown property: " + 
rName, getXWeak());
         if (pEntry->nWID == FN_UNO_FOLLOW_STYLE || pEntry->nWID == 
FN_UNO_LINK_STYLE
             || pEntry->nWID == FN_UNO_NUM_RULES)
-            throw uno::RuntimeException("Cannot reset: " + rName, 
static_cast<cppu::OWeakObject*>(this));
+            throw uno::RuntimeException("Cannot reset: " + rName, getXWeak());
         if(pEntry->nFlags & beans::PropertyAttribute::READONLY)
-            throw uno::RuntimeException("setPropertiesToDefault: property is 
read-only: " + rName, static_cast<cppu::OWeakObject*>(this));
+            throw uno::RuntimeException("setPropertiesToDefault: property is 
read-only: " + rName, getXWeak());
         if(pEntry->nWID == RES_PARATR_OUTLINELEVEL)
         {
             
static_cast<SwTextFormatColl*>(pTargetFormat)->DeleteAssignmentToListLevelOfOutlineStyle();
@@ -2756,7 +2756,7 @@ uno::Sequence<uno::Any> SAL_CALL 
SwXStyle::getPropertyDefaults(const uno::Sequen
         const SfxItemPropertyMapEntry* pEntry = 
rMap.getByName(aPropertyNames[i]);
 
         if(!pEntry)
-            throw beans::UnknownPropertyException("Unknown property: " + 
aPropertyNames[i], static_cast < cppu::OWeakObject * >(this));
+            throw beans::UnknownPropertyException("Unknown property: " + 
aPropertyNames[i], getXWeak());
         // these cannot be in an item set, especially not the
         // parent set, so the default value is void
         if (pEntry->nWID >= RES_UNKNOWNATR_END)
@@ -2870,9 +2870,9 @@ void SwXPageStyle::SetPropertyValues_Impl(const 
uno::Sequence<OUString>& rProper
         const SfxItemPropertyMapEntry* pEntry = rMap.getByName(rPropName);
 
         if(!pEntry)
-            throw beans::UnknownPropertyException("Unknown property: " + 
rPropName, static_cast<cppu::OWeakObject*>(this));
+            throw beans::UnknownPropertyException("Unknown property: " + 
rPropName, getXWeak());
         if(pEntry->nFlags & beans::PropertyAttribute::READONLY)
-            throw beans::PropertyVetoException("Property is read-only: " + 
rPropName, static_cast<cppu::OWeakObject*>(this));
+            throw beans::PropertyVetoException("Property is read-only: " + 
rPropName, getXWeak());
 
         const bool bHeader(rPropName.startsWith("Header"));
         const bool bFooter(rPropName.startsWith("Footer"));
@@ -3005,7 +3005,7 @@ void SwXPageStyle::SetPropertyValues_Impl(const 
uno::Sequence<OUString>& rProper
             case SID_ATTR_PAGE_ON:
             case RES_HEADER_FOOTER_EAT_SPACING:
                 // these slots are exclusive to Header/Footer, thus this is an 
error
-                throw beans::UnknownPropertyException("Unknown property: " + 
rPropName, static_cast<cppu::OWeakObject*>(this));
+                throw beans::UnknownPropertyException("Unknown property: " + 
rPropName, getXWeak());
             case FN_UNO_HEADER:
             case FN_UNO_HEADER_LEFT:
             case FN_UNO_HEADER_RIGHT:
@@ -3116,7 +3116,7 @@ uno::Sequence<uno::Any> 
SwXPageStyle::GetPropertyValues_Impl(const uno::Sequence
         const SfxItemPropertyMapEntry* pEntry = rMap.getByName(rPropName);
 
         if (!pEntry)
-            throw beans::UnknownPropertyException("Unknown property: " + 
rPropName, static_cast < cppu::OWeakObject * > ( this ) );
+            throw beans::UnknownPropertyException("Unknown property: " + 
rPropName, getXWeak() );
         const bool bHeader(rPropName.startsWith("Header"));
         const bool bFooter(rPropName.startsWith("Footer"));
         const bool bFirstIsShared(rPropName == UNO_NAME_FIRST_IS_SHARED);
@@ -3207,7 +3207,7 @@ uno::Sequence<uno::Any> 
SwXPageStyle::GetPropertyValues_Impl(const uno::Sequence
             case SID_ATTR_PAGE_SHARED_FIRST:
             case SID_ATTR_PAGE_ON:
             case RES_HEADER_FOOTER_EAT_SPACING:
-                throw beans::UnknownPropertyException( "Unknown property: " + 
rPropName, static_cast < cppu::OWeakObject * > ( this ) );
+                throw beans::UnknownPropertyException( "Unknown property: " + 
rPropName, getXWeak() );
             case FN_UNO_HEADER:
             case FN_UNO_HEADER_LEFT:
             case FN_UNO_HEADER_FIRST:
@@ -3286,13 +3286,13 @@ uno::Sequence<uno::Any> 
SwXPageStyle::getPropertyValues(const uno::Sequence<OUSt
     {
         css::uno::Any anyEx = cppu::getCaughtException();
         throw lang::WrappedTargetRuntimeException("Unknown property exception 
caught",
-                static_cast < cppu::OWeakObject * > ( this ), anyEx );
+                getXWeak(), anyEx );
     }
     catch(lang::WrappedTargetException &)
     {
         css::uno::Any anyEx = cppu::getCaughtException();
         throw lang::WrappedTargetRuntimeException("WrappedTargetException 
caught",
-                static_cast < cppu::OWeakObject * > ( this ), anyEx );
+                getXWeak(), anyEx );
     }
 
     return aValues;
@@ -3992,7 +3992,7 @@ uno::Sequence< uno::Any > 
SwXAutoStyle::GetPropertyValues_Impl(
         const SfxItemPropertyMapEntry* pEntry = rMap.getByName(sPropName);
         if(!pEntry)
         {
-            throw beans::UnknownPropertyException("Unknown property: " + 
sPropName, static_cast < cppu::OWeakObject * > ( this ) );
+            throw beans::UnknownPropertyException("Unknown property: " + 
sPropName, getXWeak() );
         }
 
         uno::Any aTarget;
@@ -4110,12 +4110,12 @@ uno::Sequence< uno::Any > 
SwXAutoStyle::getPropertyValues (
     catch (beans::UnknownPropertyException &)
     {
         css::uno::Any exc = cppu::getCaughtException();
-        throw lang::WrappedTargetRuntimeException("Unknown property exception 
caught", static_cast < cppu::OWeakObject * > ( this ), exc );
+        throw lang::WrappedTargetRuntimeException("Unknown property exception 
caught", getXWeak(), exc );
     }
     catch (lang::WrappedTargetException &)
     {
         css::uno::Any exc = cppu::getCaughtException();
-        throw lang::WrappedTargetRuntimeException("WrappedTargetException 
caught", static_cast < cppu::OWeakObject * > ( this ), exc );
+        throw lang::WrappedTargetRuntimeException("WrappedTargetException 
caught", getXWeak(), exc );
     }
 
     return aValues;
@@ -4189,7 +4189,7 @@ uno::Sequence< beans::PropertyState > 
SwXAutoStyle::getPropertyStates(
         const SfxItemPropertyMapEntry* pEntry = rMap.getByName(sPropName);
         if(!pEntry)
         {
-            throw beans::UnknownPropertyException("Unknown property: " + 
sPropName, static_cast < cppu::OWeakObject * > ( this ) );
+            throw beans::UnknownPropertyException("Unknown property: " + 
sPropName, getXWeak() );
         }
 
         bool bDone(false);
@@ -4555,7 +4555,7 @@ uno::Any SAL_CALL SwXTextTableStyle::getByName(const 
OUString& rName)
         throw css::container::NoSuchElementException();
 
     auto nIdx = (*iter).second;
-    return 
css::uno::Any(uno::Reference<XInterface>(static_cast<cppu::OWeakObject*>(m_aCellStyles[nIdx].get())));
+    return 
css::uno::Any(uno::Reference(cppu::getXWeak(m_aCellStyles[nIdx].get())));
 }
 
 css::uno::Sequence<OUString> SAL_CALL SwXTextTableStyle::getElementNames()
diff --git a/sw/source/core/unocore/unotbl.cxx 
b/sw/source/core/unocore/unotbl.cxx
index 74aa98e6882f..c2f92df7f1cf 100644
--- a/sw/source/core/unocore/unotbl.cxx
+++ b/sw/source/core/unocore/unotbl.cxx
@@ -947,7 +947,7 @@ void SwXCell::setPropertyValue(const OUString& 
rPropertyName, const uno::Any& aV
         comphelper::SequenceAsHashMap aPropMap(tableCellProperties);
         OUString sRedlineType;
         if(!(aPropMap.getValue("RedlineType") >>= sRedlineType))
-            throw beans::UnknownPropertyException("No redline type property: 
", static_cast<cppu::OWeakObject*>(this));
+            throw beans::UnknownPropertyException("No redline type property: 
", getXWeak());
 
         // Create a 'Table Cell Redline' object
         SwUnoCursorHelper::makeTableCellRedline(*m_pBox, sRedlineType, 
tableCellProperties);
@@ -981,7 +981,7 @@ void SwXCell::setPropertyValue(const OUString& 
rPropertyName, const uno::Any& aV
         }
 
         if(!pEntry)
-            throw beans::UnknownPropertyException(rPropertyName, 
static_cast<cppu::OWeakObject*>(this));
+            throw beans::UnknownPropertyException(rPropertyName, getXWeak());
         if(pEntry->nWID != FN_UNO_CELL_ROW_SPAN)
         {
             SwFrameFormat* pBoxFormat = m_pBox->ClaimFrameFormat();
@@ -1001,7 +1001,7 @@ uno::Any SwXCell::getPropertyValue(const OUString& 
rPropertyName)
         return uno::Any();
     auto pEntry(m_pPropSet->getPropertyMap().getByName(rPropertyName));
     if(!pEntry)
-        throw beans::UnknownPropertyException(rPropertyName, 
static_cast<cppu::OWeakObject*>(this));
+        throw beans::UnknownPropertyException(rPropertyName, getXWeak());
     switch(pEntry->nWID)
     {
         case FN_UNO_CELL_ROW_SPAN:
@@ -1058,16 +1058,16 @@ uno::Any SwXCell::getPropertyValue(const OUString& 
rPropertyName)
 }
 
 void SwXCell::addPropertyChangeListener(const OUString& /*rPropertyName*/, 
const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/)
-    { throw uno::RuntimeException("not implemented", 
static_cast<cppu::OWeakObject*>(this)); };
+    { throw uno::RuntimeException("not implemented", getXWeak()); };
 
 void SwXCell::removePropertyChangeListener(const OUString& /*rPropertyName*/, 
const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/)
-    { throw uno::RuntimeException("not implemented", 
static_cast<cppu::OWeakObject*>(this)); };
+    { throw uno::RuntimeException("not implemented", getXWeak()); };
 
 void SwXCell::addVetoableChangeListener(const OUString& /*rPropertyName*/, 
const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/)
-    { throw uno::RuntimeException("not implemented", 
static_cast<cppu::OWeakObject*>(this)); };
+    { throw uno::RuntimeException("not implemented", getXWeak()); };
 
 void SwXCell::removeVetoableChangeListener(const OUString& /*rPropertyName*/, 
const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/)
-    { throw uno::RuntimeException("not implemented", 
static_cast<cppu::OWeakObject*>(this)); };
+    { throw uno::RuntimeException("not implemented", getXWeak()); };
 
 uno::Reference<container::XEnumeration> SwXCell::createEnumeration()
 {
@@ -1240,7 +1240,7 @@ uno::Reference< beans::XPropertySetInfo > 
SwXTextTableRow::getPropertySetInfo()
 void SwXTextTableRow::setPropertyValue(const OUString& rPropertyName, const 
uno::Any& aValue)
 {
     SolarMutexGuard aGuard;
-    SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), 
static_cast<cppu::OWeakObject*>(this));
+    SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), this);
     SwTable* pTable = SwTable::FindTable( pFormat );
     SwTableLine* pLn = SwXTextTableRow::FindLine(pTable, m_pLine);
     if(!pLn)
@@ -1255,7 +1255,7 @@ void SwXTextTableRow::setPropertyValue(const OUString& 
rPropertyName, const uno:
         OUString sRedlineType;
         if( !(aPropMap.getValue("RedlineType") >>= sRedlineType) )
         {
-            throw beans::UnknownPropertyException("No redline type property: 
", static_cast < cppu::OWeakObject * > ( this ) );
+            throw beans::UnknownPropertyException("No redline type property: 
", getXWeak() );
         }
 
         // Create a 'Table Row Redline' object
@@ -1268,9 +1268,9 @@ void SwXTextTableRow::setPropertyValue(const OUString& 
rPropertyName, const uno:
             m_pPropSet->getPropertyMap().getByName(rPropertyName);
         SwDoc* pDoc = pFormat->GetDoc();
         if (!pEntry)
-            throw beans::UnknownPropertyException("Unknown property: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+            throw beans::UnknownPropertyException("Unknown property: " + 
rPropertyName, getXWeak() );
         if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
-            throw beans::PropertyVetoException("Property is read-only: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+            throw beans::PropertyVetoException("Property is read-only: " + 
rPropertyName, getXWeak() );
 
         switch(pEntry->nWID)
         {
@@ -1318,7 +1318,7 @@ uno::Any SwXTextTableRow::getPropertyValue(const 
OUString& rPropertyName)
 {
     SolarMutexGuard aGuard;
     uno::Any aRet;
-    SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), 
static_cast<cppu::OWeakObject*>(this));
+    SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), this);
     SwTable* pTable = SwTable::FindTable( pFormat );
     SwTableLine* pLn = SwXTextTableRow::FindLine(pTable, m_pLine);
     if(pLn)
@@ -1326,7 +1326,7 @@ uno::Any SwXTextTableRow::getPropertyValue(const 
OUString& rPropertyName)
         const SfxItemPropertyMapEntry* pEntry =
                                 
m_pPropSet->getPropertyMap().getByName(rPropertyName);
         if (!pEntry)
-            throw beans::UnknownPropertyException("Unknown property: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+            throw beans::UnknownPropertyException("Unknown property: " + 
rPropertyName, getXWeak() );
 
         switch(pEntry->nWID)
         {
@@ -1360,16 +1360,16 @@ uno::Any SwXTextTableRow::getPropertyValue(const 
OUString& rPropertyName)
 }
 
 void SwXTextTableRow::addPropertyChangeListener(const OUString& 
/*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & 
/*xListener*/)
-    { throw uno::RuntimeException("not implemented", 
static_cast<cppu::OWeakObject*>(this)); };
+    { throw uno::RuntimeException("not implemented", getXWeak()); };
 
 void SwXTextTableRow::removePropertyChangeListener(const OUString& 
/*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & 
/*xListener*/)
-    { throw uno::RuntimeException("not implemented", 
static_cast<cppu::OWeakObject*>(this)); };
+    { throw uno::RuntimeException("not implemented", getXWeak()); };
 
 void SwXTextTableRow::addVetoableChangeListener(const OUString& 
/*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & 
/*xListener*/)
-    { throw uno::RuntimeException("not implemented", 
static_cast<cppu::OWeakObject*>(this)); };
+    { throw uno::RuntimeException("not implemented", getXWeak()); };
 
 void SwXTextTableRow::removeVetoableChangeListener(const OUString& 
/*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & 
/*xListener*/)
-    { throw uno::RuntimeException("not implemented", 
static_cast<cppu::OWeakObject*>(this)); };
+    { throw uno::RuntimeException("not implemented", getXWeak()); };
 
 void SwXTextTableRow::Notify(const SfxHint& rHint)
 {
@@ -1569,7 +1569,7 @@ sal_Bool SwXTextTableCursor::splitRange(sal_Int16 Count, 
sal_Bool Horizontal)
 {
     SolarMutexGuard aGuard;
     if (Count <= 0)
-        throw uno::RuntimeException("Illegal first argument: needs to be > 0", 
static_cast<cppu::OWeakObject*>(this));
+        throw uno::RuntimeException("Illegal first argument: needs to be > 0", 
getXWeak());
     SwUnoCursor& rUnoCursor = GetCursor();
     SwUnoTableCursor& rTableCursor = 
dynamic_cast<SwUnoTableCursor&>(rUnoCursor);
     {
@@ -1598,9 +1598,9 @@ void SwXTextTableCursor::setPropertyValue(const OUString& 
rPropertyName, const u
     SwUnoCursor& rUnoCursor = GetCursor();
     auto pEntry(m_pPropSet->getPropertyMap().getByName(rPropertyName));
     if(!pEntry)
-        throw beans::UnknownPropertyException("Unknown property: " + 
rPropertyName, static_cast<cppu::OWeakObject*>(this));
+        throw beans::UnknownPropertyException("Unknown property: " + 
rPropertyName, getXWeak());
     if(pEntry->nFlags & beans::PropertyAttribute::READONLY)
-        throw beans::PropertyVetoException("Property is read-only: " + 
rPropertyName, static_cast<cppu::OWeakObject*>(this));
+        throw beans::PropertyVetoException("Property is read-only: " + 
rPropertyName, getXWeak());
     {
         auto pSttNode = rUnoCursor.GetPointNode().StartOfSectionNode();
         const SwTableNode* pTableNode = pSttNode->FindTableNode();
@@ -1659,7 +1659,7 @@ uno::Any SwXTextTableCursor::getPropertyValue(const 
OUString& rPropertyName)
     SwUnoTableCursor& rTableCursor = 
dynamic_cast<SwUnoTableCursor&>(rUnoCursor);
     auto pEntry(m_pPropSet->getPropertyMap().getByName(rPropertyName));
     if(!pEntry)
-        throw beans::UnknownPropertyException("Unknown property: " + 
rPropertyName, static_cast<cppu::OWeakObject*>(this));
+        throw beans::UnknownPropertyException("Unknown property: " + 
rPropertyName, getXWeak());
     rTableCursor.MakeBoxSels();
     uno::Any aResult;
     switch(pEntry->nWID)
@@ -1673,7 +1673,7 @@ uno::Any SwXTextTableCursor::getPropertyValue(const 
OUString& rPropertyName)
         break;
         case RES_BOXATR_FORMAT:
             // TODO: GetAttr for table selections in a Doc is missing
-            throw uno::RuntimeException("Unknown property: " + rPropertyName, 
static_cast<cppu::OWeakObject*>(this));
+            throw uno::RuntimeException("Unknown property: " + rPropertyName, 
getXWeak());
         break;
         case FN_UNO_PARA_STYLE:
         {
@@ -1696,16 +1696,16 @@ uno::Any SwXTextTableCursor::getPropertyValue(const 
OUString& rPropertyName)
 }
 
 void SwXTextTableCursor::addPropertyChangeListener(const OUString& 
/*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & 
/*xListener*/)
-    { throw uno::RuntimeException("not implemented", 
static_cast<cppu::OWeakObject*>(this)); };
+    { throw uno::RuntimeException("not implemented", getXWeak()); };
 
 void SwXTextTableCursor::removePropertyChangeListener(const OUString& 
/*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & 
/*xListener*/)
-    { throw uno::RuntimeException("not implemented", 
static_cast<cppu::OWeakObject*>(this)); };
+    { throw uno::RuntimeException("not implemented", getXWeak()); };
 
 void SwXTextTableCursor::addVetoableChangeListener(const OUString& 
/*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & 
/*xListener*/)
-    { throw uno::RuntimeException("not implemented", 
static_cast<cppu::OWeakObject*>(this)); };
+    { throw uno::RuntimeException("not implemented", getXWeak()); };
 
 void SwXTextTableCursor::removeVetoableChangeListener(const OUString& 
/*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & 
/*xListener*/)
-    { throw uno::RuntimeException("not implemented", 
static_cast<cppu::OWeakObject*>(this)); };
+    { throw uno::RuntimeException("not implemented", getXWeak()); };
 
 void SwXTextTableCursor::Notify( const SfxHint& rHint )
 {
@@ -1921,8 +1921,7 @@ public:
         sal_uInt16 const nColCount(rThis.m_pImpl->GetColumnCount());
         if (!nRowCount || !nColCount)
         {
-            throw uno::RuntimeException("Table too complex",
-                    static_cast<cppu::OWeakObject*>(&rThis));
+            throw uno::RuntimeException("Table too complex", rThis.getXWeak());
         }
         return std::make_pair(nRowCount, nColCount);
     }
@@ -1957,7 +1956,7 @@ rtl::Reference<SwXTextTable> 
SwXTextTable::CreateXTextTable(SwFrameFormat* const
         return xTable;
     xTable = pFrameFormat ? new SwXTextTable(*pFrameFormat) : new 
SwXTextTable();
     if(pFrameFormat)
-        
pFrameFormat->SetXObject(static_cast<cppu::OWeakObject*>(xTable.get()));
+        pFrameFormat->SetXObject(xTable->getXWeak());
     // need a permanent Reference to initialize m_wThis
     xTable->m_pImpl->m_wThis = xTable.get();
     return xTable;
@@ -2005,7 +2004,7 @@ uno::Reference<table::XTableColumns> SAL_CALL 
SwXTextTable::getColumns()
 uno::Reference<table::XCell> SwXTextTable::getCellByName(const OUString& 
sCellName)
 {
     SolarMutexGuard aGuard;
-    SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), 
static_cast<cppu::OWeakObject*>(this));
+    SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), this);
     SwTable* pTable = SwTable::FindTable(pFormat);
     SwTableBox* pBox = const_cast<SwTableBox*>(pTable->GetTableBox(sCellName));
     if(!pBox)
@@ -2030,7 +2029,7 @@ uno::Sequence<OUString> SwXTextTable::getCellNames()
 uno::Reference<text::XTextTableCursor> 
SwXTextTable::createCursorByCellName(const OUString& sCellName)
 {
     SolarMutexGuard aGuard;
-    SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), 
static_cast<cppu::OWeakObject*>(this));
+    SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), this);
     SwTable* pTable = SwTable::FindTable(pFormat);
     SwTableBox* pBox = const_cast<SwTableBox*>(pTable->GetTableBox(sCellName));
     if(!pBox || pBox->getRowSpan() == 0)
@@ -2045,7 +2044,7 @@ SwXTextTable::attach(const 
uno::Reference<text::XTextRange> & xTextRange)
 
     // attach() must only be called once
     if (!m_pImpl->IsDescriptor())  /* already attached ? */
-        throw uno::RuntimeException("SwXTextTable: already attached to 
range.", static_cast<cppu::OWeakObject*>(this));
+        throw uno::RuntimeException("SwXTextTable: already attached to 
range.", getXWeak());
 
     SwXTextRange* pRange(dynamic_cast<SwXTextRange*>(xTextRange.get()));
     OTextCursorHelper* 
pCursor(dynamic_cast<OTextCursorHelper*>(xTextRange.get()));
@@ -2111,14 +2110,14 @@ uno::Reference<text::XTextRange>  
SwXTextTable::getAnchor()
 {
     SolarMutexGuard aGuard;
     SwTableFormat *const pFormat = static_cast<SwTableFormat*>(
-        lcl_EnsureCoreConnected(GetFrameFormat(), 
static_cast<cppu::OWeakObject*>(this)));
+        lcl_EnsureCoreConnected(GetFrameFormat(), this));
     return new SwXTextRange(*pFormat);
 }
 
 void SwXTextTable::dispose()
 {
     SolarMutexGuard aGuard;
-    SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), 
static_cast<cppu::OWeakObject*>(this));
+    SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), this);
     SwTable* pTable = SwTable::FindTable(pFormat);
     SwSelBoxes aSelBoxes;
     for(auto& rBox : pTable->GetTabSortBoxes() )
@@ -2217,8 +2216,8 @@ uno::Reference<table::XCellRange>  
SwXTextTable::getCellRangeByPosition(sal_Int3
 uno::Reference<table::XCellRange> SwXTextTable::getCellRangeByName(const 
OUString& sRange)
 {
     SolarMutexGuard aGuard;
-    SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), 
static_cast<cppu::OWeakObject*>(this));
-    SwTable* pTable = lcl_EnsureTableNotComplex(SwTable::FindTable(pFormat), 
static_cast<cppu::OWeakObject*>(this));
+    SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), this);
+    SwTable* pTable = lcl_EnsureTableNotComplex(SwTable::FindTable(pFormat), 
this);
     sal_Int32 nPos = 0;
     const OUString sTLName(sRange.getToken(0, ':', nPos));
     const OUString sBRName(sRange.getToken(0, ':', nPos));
@@ -2393,8 +2392,8 @@ void SwXTextTable::sort(const uno::Sequence< 
beans::PropertyValue >& rDescriptor
 void SwXTextTable::autoFormat(const OUString& sAutoFormatName)
 {
     SolarMutexGuard aGuard;
-    SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), 
static_cast<cppu::OWeakObject*>(this));
-    SwTable* pTable = lcl_EnsureTableNotComplex(SwTable::FindTable(pFormat), 
static_cast<cppu::OWeakObject*>(this));
+    SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), this);
+    SwTable* pTable = lcl_EnsureTableNotComplex(SwTable::FindTable(pFormat), 
this);
     SwTableAutoFormatTable aAutoFormatTable;
     aAutoFormatTable.Load();
     for (size_t i = aAutoFormatTable.size(); i;)
@@ -2432,7 +2431,7 @@ void SwXTextTable::setPropertyValue(const OUString& 
rPropertyName, const uno::An
     if(pFormat)
     {
         if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
-            throw beans::PropertyVetoException("Property is read-only: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+            throw beans::PropertyVetoException("Property is read-only: " + 
rPropertyName, getXWeak() );
 
         if(0xBF == pEntry->nMemberId)
         {
@@ -2686,7 +2685,7 @@ uno::Any SwXTextTable::getPropertyValue(const OUString& 
rPropertyName)
             m_pImpl->m_pPropSet->getPropertyMap().getByName(rPropertyName);
 
     if (!pEntry)
-        throw beans::UnknownPropertyException("Unknown property: " + 
rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );

... etc. - the rest is truncated

Reply via email to