basic/source/basmgr/basmgr.cxx    |    4 +--
 basic/source/classes/propacc.cxx  |   33 +++++++++++++----------------
 basic/source/classes/sbunoobj.cxx |    2 -
 basic/source/classes/sbxmod.cxx   |    2 -
 basic/source/uno/dlgcont.cxx      |    8 +++----
 basic/source/uno/namecont.cxx     |   42 +++++++++++++++++++-------------------
 basic/source/uno/scriptcont.cxx   |    4 +--
 7 files changed, 46 insertions(+), 49 deletions(-)

New commits:
commit 8da305acc9bc1fa0a31cd61d5da632e6bb4ae48c
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sun Apr 23 20:12:58 2023 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sun Jun 18 09:34:24 2023 +0200

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

diff --git a/basic/source/basmgr/basmgr.cxx b/basic/source/basmgr/basmgr.cxx
index c00221f27a12..206b917b7edd 100644
--- a/basic/source/basmgr/basmgr.cxx
+++ b/basic/source/basmgr/basmgr.cxx
@@ -1735,7 +1735,7 @@ void ModuleContainer_Impl::insertByName( const OUString& 
aName, const uno::Any&
     const uno::Type& aAnyType = aElement.getValueType();
     if( aModuleType != aAnyType )
     {
-        throw lang::IllegalArgumentException("types do not match", 
static_cast<cppu::OWeakObject*>(this), 2);
+        throw lang::IllegalArgumentException("types do not match", getXWeak(), 
2);
     }
     uno::Reference< script::XStarBasicModuleInfo > xMod;
     aElement >>= xMod;
@@ -1899,7 +1899,7 @@ void DialogContainer_Impl::insertByName( const OUString&, 
const uno::Any& aEleme
     const uno::Type& aAnyType = aElement.getValueType();
     if( aModuleType != aAnyType )
     {
-        throw lang::IllegalArgumentException("types do not match", 
static_cast<cppu::OWeakObject*>(this), 2);
+        throw lang::IllegalArgumentException("types do not match", getXWeak(), 
2);
     }
     uno::Reference< script::XStarBasicDialogInfo > xMod;
     aElement >>= xMod;
diff --git a/basic/source/classes/propacc.cxx b/basic/source/classes/propacc.cxx
index 4c948c3038af..f9eacc3d1298 100644
--- a/basic/source/classes/propacc.cxx
+++ b/basic/source/classes/propacc.cxx
@@ -129,7 +129,7 @@ Sequence< PropertyValue > 
SbPropertyValues::getPropertyValues()
 void SbPropertyValues::setPropertyValues(const Sequence< PropertyValue >& 
rPropertyValues )
 {
     if (!m_aPropVals.empty())
-        throw IllegalArgumentException("m_aPropVals not empty", 
static_cast<cppu::OWeakObject*>(this), -1);
+        throw IllegalArgumentException("m_aPropVals not empty", getXWeak(), 
-1);
 
     for (const PropertyValue& i : rPropertyValues)
     {
@@ -150,26 +150,23 @@ void RTL_Impl_CreatePropertySet( SbxArray& rPar )
 
     // Get class names of struct
 
-    Reference< XInterface > xInterface = static_cast<OWeakObject*>(new 
SbPropertyValues());
+    Reference xInterface(getXWeak(new SbPropertyValues()));
 
     SbxVariableRef refVar = rPar.Get(0);
-    if( xInterface.is() )
+    // Set PropertyValues
+    Any aArgAsAny = sbxToUnoValue(rPar.Get(1),
+            cppu::UnoType<Sequence<PropertyValue>>::get() );
+    auto pArg = o3tl::doAccess<Sequence<PropertyValue>>(aArgAsAny);
+    Reference< XPropertyAccess > xPropAcc( xInterface, UNO_QUERY );
+    xPropAcc->setPropertyValues( *pArg );
+
+    // Build a SbUnoObject and return it
+    auto xUnoObj = tools::make_ref<SbUnoObject>( 
"stardiv.uno.beans.PropertySet", Any(xInterface) );
+    if( xUnoObj->getUnoAny().hasValue() )
     {
-        // Set PropertyValues
-        Any aArgAsAny = sbxToUnoValue(rPar.Get(1),
-                cppu::UnoType<Sequence<PropertyValue>>::get() );
-        auto pArg = o3tl::doAccess<Sequence<PropertyValue>>(aArgAsAny);
-        Reference< XPropertyAccess > xPropAcc( xInterface, UNO_QUERY );
-        xPropAcc->setPropertyValues( *pArg );
-
-        // Build a SbUnoObject and return it
-        auto xUnoObj = tools::make_ref<SbUnoObject>( 
"stardiv.uno.beans.PropertySet", Any(xInterface) );
-        if( xUnoObj->getUnoAny().hasValue() )
-        {
-            // Return object
-            refVar->PutObject( xUnoObj.get() );
-            return;
-        }
+        // Return object
+        refVar->PutObject( xUnoObj.get() );
+        return;
     }
 
     // Object could not be created
diff --git a/basic/source/classes/sbunoobj.cxx 
b/basic/source/classes/sbunoobj.cxx
index 36feb923a6de..b9db47dcd306 100644
--- a/basic/source/classes/sbunoobj.cxx
+++ b/basic/source/classes/sbunoobj.cxx
@@ -3960,7 +3960,7 @@ Any SAL_CALL InvocationToAllListenerMapper::invoke(const 
OUString& FunctionName,
     }
 
     AllEventObject aAllEvent;
-    aAllEvent.Source = static_cast<OWeakObject*>(this);
+    aAllEvent.Source = getXWeak();
     aAllEvent.Helper = m_Helper;
     aAllEvent.ListenerType = Type(m_xListenerType->getTypeClass(), 
m_xListenerType->getName() );
     aAllEvent.MethodName = FunctionName;
diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx
index cce2caca22b4..5b7ee24e1f9c 100644
--- a/basic/source/classes/sbxmod.cxx
+++ b/basic/source/classes/sbxmod.cxx
@@ -165,7 +165,7 @@ DocObjectWrapper::DocObjectWrapper( SbModule* pVar ) : 
m_pMod( pVar )
         instances that are acquired during the call are released
         before m_refCount is decremented again */
     {
-        m_xAggProxy->setDelegator( static_cast< cppu::OWeakObject * >( this ) 
);
+        m_xAggProxy->setDelegator( getXWeak() );
     }
 
     osl_atomic_decrement( &m_refCount );
diff --git a/basic/source/uno/dlgcont.cxx b/basic/source/uno/dlgcont.cxx
index f729c3512d96..1ece724fe0c7 100644
--- a/basic/source/uno/dlgcont.cxx
+++ b/basic/source/uno/dlgcont.cxx
@@ -388,12 +388,12 @@ Reference< css::resource::XStringResourcePersistence >
             xLibrariesStor = mxStorage->openStorageElement( maLibrariesDir, 
embed::ElementModes::READ );
                 // TODO: Should be READWRITE with new storage concept using 
store() instead of storeTo()
             if ( !xLibrariesStor.is() )
-                throw uno::RuntimeException("null returned from 
openStorageElement",static_cast< cppu::OWeakObject * >(this));
+                throw uno::RuntimeException("null returned from 
openStorageElement",getXWeak());
 
             xLibraryStor = xLibrariesStor->openStorageElement( aLibName, 
embed::ElementModes::READ );
                 // TODO: Should be READWRITE with new storage concept using 
store() instead of storeTo()
             if ( !xLibraryStor.is() )
-                throw uno::RuntimeException("null returned from 
openStorageElement",static_cast< cppu::OWeakObject * >(this));
+                throw uno::RuntimeException("null returned from 
openStorageElement",getXWeak());
         }
         catch(const uno::Exception& )
         {
@@ -441,12 +441,12 @@ void SfxDialogLibraryContainer::onNewRootStorage()
             try {
                 xLibrariesStor = mxStorage->openStorageElement( 
maLibrariesDir, embed::ElementModes::READWRITE );
                 if ( !xLibrariesStor.is() )
-                    throw uno::RuntimeException("null returned from 
openStorageElement",static_cast< cppu::OWeakObject * >(this));
+                    throw uno::RuntimeException("null returned from 
openStorageElement",getXWeak());
 
                 OUString aLibName = pDialogLibrary->getName();
                 xLibraryStor = xLibrariesStor->openStorageElement( aLibName, 
embed::ElementModes::READWRITE );
                 if ( !xLibraryStor.is() )
-                    throw uno::RuntimeException("null returned from 
openStorageElement",static_cast< cppu::OWeakObject * >(this));
+                    throw uno::RuntimeException("null returned from 
openStorageElement",getXWeak());
 
                 Reference< resource::XStringResourceWithStorage >
                     xStringResourceWithStorage( xStringResourcePersistence, 
UNO_QUERY );
diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx
index 8c084d51a93c..beeee133b064 100644
--- a/basic/source/uno/namecont.cxx
+++ b/basic/source/uno/namecont.cxx
@@ -144,7 +144,7 @@ void NameContainer::replaceByName( const OUString& aName, 
const Any& aElement )
     const Type& aAnyType = aElement.getValueType();
     if( mType != aAnyType )
     {
-        throw IllegalArgumentException("types do not match", 
static_cast<cppu::OWeakObject*>(this), 2);
+        throw IllegalArgumentException("types do not match", getXWeak(), 2);
     }
     NameContainerNameMap::iterator aIt = mHashMap.find( aName );
     if( aIt == mHashMap.end() )
@@ -195,7 +195,7 @@ void NameContainer::insertNoCheck(const OUString& aName, 
const Any& aElement)
     const Type& aAnyType = aElement.getValueType();
     if( mType != aAnyType )
     {
-        throw IllegalArgumentException("types do not match", 
static_cast<cppu::OWeakObject*>(this), 2);
+        throw IllegalArgumentException("types do not match", getXWeak(), 2);
     }
 
     sal_Int32 nCount = mNames.size();
@@ -288,7 +288,7 @@ void SAL_CALL NameContainer::addContainerListener( const 
Reference< XContainerLi
 {
     if( !xListener.is() )
     {
-        throw RuntimeException("addContainerListener called with null 
xListener",static_cast< cppu::OWeakObject * >(this));
+        throw RuntimeException("addContainerListener called with null 
xListener",getXWeak());
     }
     maContainerListeners.addInterface( xListener );
 }
@@ -297,7 +297,7 @@ void SAL_CALL NameContainer::removeContainerListener( const 
Reference< XContaine
 {
     if( !xListener.is() )
     {
-        throw RuntimeException("removeContainerListener called with null 
xListener",static_cast< cppu::OWeakObject * >(this));
+        throw RuntimeException("removeContainerListener called with null 
xListener",getXWeak());
     }
     maContainerListeners.removeInterface( xListener );
 }
@@ -307,7 +307,7 @@ void SAL_CALL NameContainer::addChangesListener( const 
Reference< XChangesListen
 {
     if( !xListener.is() )
     {
-        throw RuntimeException("addChangesListener called with null 
xListener",static_cast< cppu::OWeakObject * >(this));
+        throw RuntimeException("addChangesListener called with null 
xListener",getXWeak());
     }
     maChangesListeners.addInterface( xListener );
 }
@@ -316,7 +316,7 @@ void SAL_CALL NameContainer::removeChangesListener( const 
Reference< XChangesLis
 {
     if( !xListener.is() )
     {
-        throw RuntimeException("removeChangesListener called with null 
xListener",static_cast< cppu::OWeakObject * >(this));
+        throw RuntimeException("removeChangesListener called with null 
xListener",getXWeak());
     }
     maChangesListeners.removeInterface( xListener );
 }
@@ -422,7 +422,7 @@ void SAL_CALL SfxLibraryContainer::setRootStorage( const 
Reference< XStorage >&
     LibraryContainerMethodGuard aGuard( *this );
     if ( !_rxRootStorage.is() )
     {
-        throw IllegalArgumentException("no root storage", 
static_cast<cppu::OWeakObject*>(this), 1);
+        throw IllegalArgumentException("no root storage", getXWeak(), 1);
     }
     mxStorage = _rxRootStorage;
     onNewRootStorage();
@@ -433,7 +433,7 @@ void SAL_CALL SfxLibraryContainer::storeLibrariesToStorage( 
const Reference< XSt
     LibraryContainerMethodGuard aGuard( *this );
     if ( !_rxRootStorage.is() )
     {
-        throw IllegalArgumentException("no root storage", 
static_cast<cppu::OWeakObject*>(this), 1);
+        throw IllegalArgumentException("no root storage", getXWeak(), 1);
     }
     try
     {
@@ -2211,7 +2211,7 @@ void SAL_CALL SfxLibraryContainer::removeLibrary( const 
OUString& Name )
     SfxLibrary* pImplLib = static_cast< SfxLibrary* >( xNameAccess.get() );
     if( pImplLib->mbReadOnly && !pImplLib->mbLink )
     {
-        throw IllegalArgumentException("readonly && !link", 
static_cast<cppu::OWeakObject*>(this), 1);
+        throw IllegalArgumentException("readonly && !link", getXWeak(), 1);
     }
     // Remove from container
     maNameContainer->removeByName( Name );
@@ -2317,7 +2317,7 @@ void SAL_CALL SfxLibraryContainer::loadLibrary( const 
OUString& Name )
                  " storage!"));
             if ( !xLibrariesStor.is() )
             {
-                throw uno::RuntimeException("null returned from 
openStorageElement",static_cast< cppu::OWeakObject * >(this));
+                throw uno::RuntimeException("null returned from 
openStorageElement",getXWeak());
             }
 
             xLibraryStor = xLibrariesStor->openStorageElement( Name, 
embed::ElementModes::READ );
@@ -2327,7 +2327,7 @@ void SAL_CALL SfxLibraryContainer::loadLibrary( const 
OUString& Name )
                  " storage!"));
             if ( !xLibrariesStor.is() )
             {
-                throw uno::RuntimeException("null returned from 
openStorageElement",static_cast< cppu::OWeakObject * >(this));
+                throw uno::RuntimeException("null returned from 
openStorageElement",getXWeak());
             }
 #if OSL_DEBUG_LEVEL > 0
         }
@@ -2434,7 +2434,7 @@ OUString SAL_CALL SfxLibraryContainer::getLibraryLinkURL( 
const OUString& Name )
     bool bLink = pImplLib->mbLink;
     if( !bLink )
     {
-        throw IllegalArgumentException("!link", 
static_cast<cppu::OWeakObject*>(this), 1);
+        throw IllegalArgumentException("!link", getXWeak(), 1);
     }
     OUString aRetStr = pImplLib->maLibInfoFileURL;
     return aRetStr;
@@ -2612,7 +2612,7 @@ void SAL_CALL SfxLibraryContainer::initialize( const 
Sequence< Any >& _rArgument
     LibraryContainerMethodGuard aGuard( *this );
     sal_Int32 nArgCount = _rArguments.getLength();
     if ( nArgCount != 1 )
-        throw IllegalArgumentException("too many args", 
static_cast<cppu::OWeakObject*>(this), -1);
+        throw IllegalArgumentException("too many args", getXWeak(), -1);
 
     OUString sInitialDocumentURL;
     Reference< XStorageBasedDocument > xDocument;
@@ -2627,7 +2627,7 @@ void SAL_CALL SfxLibraryContainer::initialize( const 
Sequence< Any >& _rArgument
         initializeFromDocument( xDocument );
         return;
     }
-    throw IllegalArgumentException("arg1 unknown type", 
static_cast<cppu::OWeakObject*>(this), 1);
+    throw IllegalArgumentException("arg1 unknown type", getXWeak(), 1);
 
 }
 
@@ -2652,7 +2652,7 @@ void SfxLibraryContainer::initializeFromDocument( const 
Reference< XStorageBased
 
     if ( !xDocStorage.is() )
     {
-        throw IllegalArgumentException("no doc storage", 
static_cast<cppu::OWeakObject*>(this), 1);
+        throw IllegalArgumentException("no doc storage", getXWeak(), 1);
     }
     init( OUString(), xDocStorage );
 }
@@ -2706,7 +2706,7 @@ void SAL_CALL 
SfxLibraryContainer::changeLibraryPassword(const OUString&, const
 void SAL_CALL SfxLibraryContainer::addContainerListener( const Reference< 
XContainerListener >& xListener )
 {
     LibraryContainerMethodGuard aGuard( *this );
-    maNameContainer->setEventSource( static_cast< XInterface* >( 
static_cast<OWeakObject*>(this) ) );
+    maNameContainer->setEventSource( getXWeak() );
     maNameContainer->addContainerListener( xListener );
 }
 
@@ -2778,7 +2778,7 @@ OUString SAL_CALL 
SfxLibraryContainer::getOriginalLibraryLinkURL( const OUString
     bool bLink = pImplLib->mbLink;
     if( !bLink )
     {
-        throw IllegalArgumentException("!link", 
static_cast<cppu::OWeakObject*>(this), 1);
+        throw IllegalArgumentException("!link", getXWeak(), 1);
     }
     OUString aRetStr = pImplLib->maOriginalStorageURL;
     return aRetStr;
@@ -2889,7 +2889,7 @@ void SAL_CALL SfxLibraryContainer::setPropertyValue(const 
OUString& aPropertyNam
                                                     const uno::Any& aValue)
 {
     if (aPropertyName != sVBATextEncodingPropName)
-        throw UnknownPropertyException(aPropertyName, 
static_cast<uno::XWeak*>(this));
+        throw UnknownPropertyException(aPropertyName, getXWeak());
     aValue >>= meVBATextEncoding;
 }
 
@@ -2897,7 +2897,7 @@ css::uno::Any SAL_CALL 
SfxLibraryContainer::getPropertyValue(const OUString& aPr
 {
     if (aPropertyName == sVBATextEncodingPropName)
         return uno::Any(meVBATextEncoding);
-    throw UnknownPropertyException(aPropertyName, 
static_cast<uno::XWeak*>(this));
+    throw UnknownPropertyException(aPropertyName, getXWeak());
 }
 
 void SAL_CALL SfxLibraryContainer::addPropertyChangeListener(
@@ -3157,7 +3157,7 @@ Sequence< sal_Int8 > SfxLibrary::getImplementationId()
 // Methods XContainer
 void SAL_CALL SfxLibrary::addContainerListener( const Reference< 
XContainerListener >& xListener )
 {
-    maNameContainer->setEventSource( static_cast< XInterface* >( 
static_cast<OWeakObject*>(this) ) );
+    maNameContainer->setEventSource( getXWeak() );
     maNameContainer->addContainerListener( xListener );
 }
 
@@ -3169,7 +3169,7 @@ void SAL_CALL SfxLibrary::removeContainerListener( const 
Reference< XContainerLi
 // Methods XChangesNotifier
 void SAL_CALL SfxLibrary::addChangesListener( const Reference< 
XChangesListener >& xListener )
 {
-    maNameContainer->setEventSource( static_cast< XInterface* >( 
static_cast<OWeakObject*>(this) ) );
+    maNameContainer->setEventSource( getXWeak() );
     maNameContainer->addChangesListener( xListener );
 }
 
diff --git a/basic/source/uno/scriptcont.cxx b/basic/source/uno/scriptcont.cxx
index eea449ac47fc..7c059ff66d7b 100644
--- a/basic/source/uno/scriptcont.cxx
+++ b/basic/source/uno/scriptcont.cxx
@@ -363,7 +363,7 @@ sal_Bool SAL_CALL 
SfxScriptLibraryContainer::isLibraryPasswordVerified( const OU
     SfxLibrary* pImplLib = getImplLib( Name );
     if( !pImplLib->mbPasswordProtected )
     {
-        throw IllegalArgumentException("!passwordProtected", 
static_cast<cppu::OWeakObject*>(this), 1);
+        throw IllegalArgumentException("!passwordProtected", getXWeak(), 1);
     }
     bool bRet = pImplLib->mbPasswordVerified;
     return bRet;
@@ -376,7 +376,7 @@ sal_Bool SAL_CALL 
SfxScriptLibraryContainer::verifyLibraryPassword
     SfxLibrary* pImplLib = getImplLib( Name );
     if( !pImplLib->mbPasswordProtected || pImplLib->mbPasswordVerified )
     {
-        throw IllegalArgumentException("!PasswordProtected || 
PasswordVerified", static_cast<cppu::OWeakObject*>(this), 1);
+        throw IllegalArgumentException("!PasswordProtected || 
PasswordVerified", getXWeak(), 1);
     }
     // Test password
     bool bSuccess = false;

Reply via email to