[Libreoffice-commits] core.git: include/sfx2 sfx2/source

Noel (via logerrit) logerrit at kemper.freedesktop.org
Sat Feb 20 18:22:39 UTC 2021


 include/sfx2/stbitem.hxx                 |    3 ++-
 sfx2/source/appl/appdispatchprovider.cxx |    2 +-
 sfx2/source/appl/appopen.cxx             |    4 ++--
 sfx2/source/appl/helpinterceptor.cxx     |    3 +--
 sfx2/source/appl/workwin.cxx             |    5 ++---
 sfx2/source/control/thumbnailviewacc.cxx |    4 ++--
 sfx2/source/dialog/infobar.cxx           |    9 ++-------
 sfx2/source/dialog/mailmodel.cxx         |    7 +++----
 sfx2/source/doc/docfile.cxx              |    8 +++-----
 sfx2/source/doc/doctemplateslocal.cxx    |   16 +++++++---------
 sfx2/source/doc/objmisc.cxx              |    8 ++++----
 sfx2/source/doc/objstor.cxx              |   10 ++++------
 sfx2/source/doc/sfxbasemodel.cxx         |   12 +++++-------
 sfx2/source/view/sfxbasecontroller.cxx   |    4 ++--
 sfx2/source/view/viewprn.cxx             |    2 +-
 15 files changed, 41 insertions(+), 56 deletions(-)

New commits:
commit d49277fc7c017c5a62a0c28af782cfc04a6460ab
Author:     Noel <noel.grandin at collabora.co.uk>
AuthorDate: Sat Feb 20 12:50:48 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sat Feb 20 19:21:52 2021 +0100

    loplugin:refcounting in sfx2
    
    Change-Id: I22ca5dab32fb4bf9a1ab7d478105db2d12e14b14
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111262
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/sfx2/stbitem.hxx b/include/sfx2/stbitem.hxx
index 8929e2efb2f3..060866e4c3eb 100644
--- a/include/sfx2/stbitem.hxx
+++ b/include/sfx2/stbitem.hxx
@@ -61,12 +61,13 @@ class SFX2_DLLPUBLIC SfxStatusBarControl: public svt::StatusbarController
     sal_uInt16         nId;
     VclPtr<StatusBar>  pBar;
 
-protected:
+public:
     // new controller API
     // XInterface
     virtual void               SAL_CALL acquire() throw() override;
     virtual void               SAL_CALL release() throw() override;
 
+protected:
     // XEventListener
     using svt::StatusbarController::disposing;
 
diff --git a/sfx2/source/appl/appdispatchprovider.cxx b/sfx2/source/appl/appdispatchprovider.cxx
index a62872a9a420..af86f8bcc02c 100644
--- a/sfx2/source/appl/appdispatchprovider.cxx
+++ b/sfx2/source/appl/appdispatchprovider.cxx
@@ -133,7 +133,7 @@ Reference < XDispatch > SAL_CALL SfxAppDispatchProvider::queryDispatch(
 
     if ( pSlot )
     {
-        SfxOfficeDispatch* pDispatch = new SfxOfficeDispatch( pAppDisp, pSlot, aURL ) ;
+        rtl::Reference<SfxOfficeDispatch> pDispatch = new SfxOfficeDispatch( pAppDisp, pSlot, aURL ) ;
         pDispatch->SetFrame(m_xFrame);
         pDispatch->SetMasterUnoCommand( bMasterCommand );
         xDisp = pDispatch;
diff --git a/sfx2/source/appl/appopen.cxx b/sfx2/source/appl/appopen.cxx
index e59e58b08033..4a6c1f403bbb 100644
--- a/sfx2/source/appl/appopen.cxx
+++ b/sfx2/source/appl/appopen.cxx
@@ -676,8 +676,8 @@ void SfxApplication::OpenDocExec_Impl( SfxRequest& rReq )
             // intercept all incoming interactions and provide useful information
             // later if the following transaction was finished.
 
-            sfx2::PreventDuplicateInteraction* pHandler = new sfx2::PreventDuplicateInteraction(comphelper::getProcessComponentContext());
-            uno::Reference<task::XInteractionHandler> xHandler(static_cast< css::task::XInteractionHandler* >(pHandler), css::uno::UNO_QUERY);
+            rtl::Reference<sfx2::PreventDuplicateInteraction> pHandler = new sfx2::PreventDuplicateInteraction(comphelper::getProcessComponentContext());
+            uno::Reference<task::XInteractionHandler> xHandler(pHandler);
             uno::Reference<task::XInteractionHandler> xWrappedHandler;
 
             // wrap existing handler or create new UUI handler
diff --git a/sfx2/source/appl/helpinterceptor.cxx b/sfx2/source/appl/helpinterceptor.cxx
index ccab2578e750..7fd631b05951 100644
--- a/sfx2/source/appl/helpinterceptor.cxx
+++ b/sfx2/source/appl/helpinterceptor.cxx
@@ -112,8 +112,7 @@ Reference< XDispatch > SAL_CALL HelpInterceptor_Impl::queryDispatch(
     if ( bHelpURL )
     {
         DBG_ASSERT( xResult.is(), "invalid dispatch" );
-        HelpDispatch_Impl* pHelpDispatch = new HelpDispatch_Impl( *this, xResult );
-        xResult.set( static_cast< ::cppu::OWeakObject* >(pHelpDispatch), UNO_QUERY );
+        xResult = new HelpDispatch_Impl( *this, xResult );
     }
 
     return xResult;
diff --git a/sfx2/source/appl/workwin.cxx b/sfx2/source/appl/workwin.cxx
index 217ae75436bf..d3af7dfa6950 100644
--- a/sfx2/source/appl/workwin.cxx
+++ b/sfx2/source/appl/workwin.cxx
@@ -485,9 +485,8 @@ SfxWorkWindow::SfxWorkWindow( vcl::Window *pWin, SfxFrame *pFrm, SfxFrame* pMast
 
     // create and initialize layout manager listener
     Reference< css::frame::XFrame > xFrame = GetFrameInterface();
-    LayoutManagerListener* pLayoutManagerListener = new LayoutManagerListener( this );
-    m_xLayoutManagerListener.set( static_cast< cppu::OWeakObject* >( pLayoutManagerListener ),
-                                  css::uno::UNO_QUERY );
+    rtl::Reference<LayoutManagerListener> pLayoutManagerListener = new LayoutManagerListener( this );
+    m_xLayoutManagerListener = pLayoutManagerListener;
     pLayoutManagerListener->setFrame( xFrame );
 
     SfxShell* pConfigShell = pFrm->GetCurrentViewFrame();
diff --git a/sfx2/source/control/thumbnailviewacc.cxx b/sfx2/source/control/thumbnailviewacc.cxx
index 8c67445f226f..8f6cfa69d866 100644
--- a/sfx2/source/control/thumbnailviewacc.cxx
+++ b/sfx2/source/control/thumbnailviewacc.cxx
@@ -177,7 +177,7 @@ uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL ThumbnailViewAc
 uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL ThumbnailViewAcc::getAccessibleStateSet()
 {
     ThrowIfDisposed();
-    ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper();
+    rtl::Reference<::utl::AccessibleStateSetHelper> pStateSet = new ::utl::AccessibleStateSetHelper();
 
     // Set some states.
     pStateSet->AddState (accessibility::AccessibleStateType::ENABLED);
@@ -694,7 +694,7 @@ uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL ThumbnailViewIt
 uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL ThumbnailViewItemAcc::getAccessibleStateSet()
 {
     const SolarMutexGuard aSolarGuard;
-    ::utl::AccessibleStateSetHelper*    pStateSet = new ::utl::AccessibleStateSetHelper;
+    rtl::Reference<::utl::AccessibleStateSetHelper> pStateSet = new ::utl::AccessibleStateSetHelper;
 
     if( mpParent )
     {
diff --git a/sfx2/source/dialog/infobar.cxx b/sfx2/source/dialog/infobar.cxx
index c37c563567e7..4844e8eb88df 100644
--- a/sfx2/source/dialog/infobar.cxx
+++ b/sfx2/source/dialog/infobar.cxx
@@ -122,9 +122,7 @@ void SfxInfoBarWindow::SetCloseButtonImage()
     aPolygon.append(B2DPoint(aRect.Left(), aRect.Bottom()));
     aPolygon.setClosed(true);
 
-    PolyPolygonColorPrimitive2D* pBack
-        = new PolyPolygonColorPrimitive2D(B2DPolyPolygon(aPolygon), m_aBackgroundColor);
-    aSeq[0] = pBack;
+    aSeq[0] = new PolyPolygonColorPrimitive2D(B2DPolyPolygon(aPolygon), m_aBackgroundColor);
 
     LineAttribute aLineAttribute(m_aForegroundColor, 2.0);
 
@@ -141,10 +139,7 @@ void SfxInfoBarWindow::SetCloseButtonImage()
     aLine2.append(B2DPoint(aRect.Left(), aRect.Bottom()));
     aCross.append(aLine2);
 
-    PolyPolygonStrokePrimitive2D* pCross
-        = new PolyPolygonStrokePrimitive2D(aCross, aLineAttribute, StrokeAttribute());
-
-    aSeq[1] = pCross;
+    aSeq[1] = new PolyPolygonStrokePrimitive2D(aCross, aLineAttribute, StrokeAttribute());
 
     pProcessor->process(aSeq);
 
diff --git a/sfx2/source/dialog/mailmodel.cxx b/sfx2/source/dialog/mailmodel.cxx
index b468d35988e4..87ad643da40d 100644
--- a/sfx2/source/dialog/mailmodel.cxx
+++ b/sfx2/source/dialog/mailmodel.cxx
@@ -497,11 +497,10 @@ SfxMailModel::SaveResult SfxMailModel::SaveDocumentAsFormat(
                         xPrepareDispatch.set( xDispatchProvider->queryDispatch( aPrepareURL, OUString(), 0 ));
                         if ( xPrepareDispatch.is() )
                         {
-                                PrepareListener_Impl* pPrepareListener = new PrepareListener_Impl;
-                                uno::Reference< css::frame::XStatusListener > xStatusListener = pPrepareListener;
-                                xPrepareDispatch->addStatusListener( xStatusListener, aPrepareURL );
+                                rtl::Reference<PrepareListener_Impl> pPrepareListener = new PrepareListener_Impl;
+                                xPrepareDispatch->addStatusListener( pPrepareListener, aPrepareURL );
                                 bNeedsPreparation = pPrepareListener->IsSet();
-                                xPrepareDispatch->removeStatusListener( xStatusListener, aPrepareURL );
+                                xPrepareDispatch->removeStatusListener( pPrepareListener, aPrepareURL );
                         }
                     }
                 }
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index 2654bd0eda94..e8040fcef57d 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -470,9 +470,7 @@ Reference < XContent > SfxMedium::GetContent() const
                 css::task::InteractionHandler::createWithParent( comphelper::getProcessComponentContext(), nullptr ) );
 
         css::uno::Reference< css::ucb::XProgressHandler > xProgress;
-        ::ucbhelper::CommandEnvironment* pCommandEnv = new ::ucbhelper::CommandEnvironment( new comphelper::SimpleFileAccessInteraction( xIH ), xProgress );
-
-        Reference < css::ucb::XCommandEnvironment > xEnv( static_cast< css::ucb::XCommandEnvironment* >(pCommandEnv), css::uno::UNO_QUERY );
+        rtl::Reference<::ucbhelper::CommandEnvironment> pCommandEnv = new ::ucbhelper::CommandEnvironment( new comphelper::SimpleFileAccessInteraction( xIH ), xProgress );
 
         const SfxUnoAnyItem* pItem = SfxItemSet::GetItem<SfxUnoAnyItem>(pImpl->m_pSet.get(), SID_CONTENT, false);
         if ( pItem )
@@ -482,7 +480,7 @@ Reference < XContent > SfxMedium::GetContent() const
         {
             try
             {
-                pImpl->aContent = ::ucbhelper::Content( xContent, xEnv, comphelper::getProcessComponentContext() );
+                pImpl->aContent = ::ucbhelper::Content( xContent, pCommandEnv, comphelper::getProcessComponentContext() );
             }
             catch ( const Exception& )
             {
@@ -497,7 +495,7 @@ Reference < XContent > SfxMedium::GetContent() const
             else if ( !pImpl->m_aLogicName.isEmpty() )
                 aURL = GetURLObject().GetMainURL( INetURLObject::DecodeMechanism::NONE );
             if (!aURL.isEmpty() )
-                (void)::ucbhelper::Content::create( aURL, xEnv, comphelper::getProcessComponentContext(), pImpl->aContent );
+                (void)::ucbhelper::Content::create( aURL, pCommandEnv, comphelper::getProcessComponentContext(), pImpl->aContent );
         }
     }
 
diff --git a/sfx2/source/doc/doctemplateslocal.cxx b/sfx2/source/doc/doctemplateslocal.cxx
index e72b74eb8efe..41561925bd6b 100644
--- a/sfx2/source/doc/doctemplateslocal.cxx
+++ b/sfx2/source/doc/doctemplateslocal.cxx
@@ -25,6 +25,7 @@
 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
 
 #include <comphelper/attributelist.hxx>
+#include <rtl/ref.hxx>
 
 #include "doctemplateslocal.hxx"
 
@@ -61,24 +62,22 @@ void DocTemplLocaleHelper::WriteGroupLocalizationSequence( const uno::Reference<
     const OUString aWhiteSpace( " " );
 
     // write the namespace
-    ::comphelper::AttributeList* pRootAttrList = new ::comphelper::AttributeList;
-    uno::Reference< xml::sax::XAttributeList > xRootAttrList( pRootAttrList );
+    rtl::Reference<::comphelper::AttributeList> pRootAttrList = new ::comphelper::AttributeList;
     pRootAttrList->AddAttribute(
         "xmlns:groupuinames",
         aCDATAString,
         "http://openoffice.org/2006/groupuinames" );
 
     xWriterHandler->startDocument();
-    xWriterHandler->startElement( g_sGroupListElement, xRootAttrList );
+    xWriterHandler->startElement( g_sGroupListElement, pRootAttrList );
 
     for (const auto & i : aSequence)
     {
-        ::comphelper::AttributeList *pAttrList = new ::comphelper::AttributeList;
-        uno::Reference< xml::sax::XAttributeList > xAttrList( pAttrList );
+        rtl::Reference<::comphelper::AttributeList> pAttrList = new ::comphelper::AttributeList;
         pAttrList->AddAttribute( g_sNameAttr, aCDATAString, i.First );
         pAttrList->AddAttribute( g_sUINameAttr, aCDATAString, i.Second );
 
-        xWriterHandler->startElement( g_sGroupElement, xAttrList );
+        xWriterHandler->startElement( g_sGroupElement, pAttrList );
         xWriterHandler->ignorableWhitespace( aWhiteSpace );
         xWriterHandler->endElement( g_sGroupElement );
     }
@@ -96,12 +95,11 @@ std::vector< beans::StringPair > DocTemplLocaleHelper::ReadLocalizationSequence_
 
     uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create( xContext );
 
-    DocTemplLocaleHelper* pHelper = new DocTemplLocaleHelper();
-    uno::Reference< xml::sax::XDocumentHandler > xHelper( static_cast< xml::sax::XDocumentHandler* >( pHelper ) );
+    rtl::Reference<DocTemplLocaleHelper> pHelper = new DocTemplLocaleHelper();
     xml::sax::InputSource aParserInput;
     aParserInput.aInputStream = xInStream;
     aParserInput.sSystemId = aStringID;
-    xParser->setDocumentHandler( xHelper );
+    xParser->setDocumentHandler( pHelper );
     xParser->parseStream( aParserInput );
     xParser->setDocumentHandler( uno::Reference < xml::sax::XDocumentHandler > () );
 
diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx
index 4f34d7d2440a..b4321576b3b8 100644
--- a/sfx2/source/doc/objmisc.cxx
+++ b/sfx2/source/doc/objmisc.cxx
@@ -1685,10 +1685,10 @@ bool SfxObjectShell::UseInteractionToHandleError(
         {
             uno::Any aInteraction;
             uno::Sequence< uno::Reference< task::XInteractionContinuation > > lContinuations(2);
-            ::comphelper::OInteractionAbort* pAbort = new ::comphelper::OInteractionAbort();
-            ::comphelper::OInteractionApprove* pApprove = new ::comphelper::OInteractionApprove();
-            lContinuations[0].set( static_cast< task::XInteractionContinuation* >( pAbort ), uno::UNO_QUERY );
-            lContinuations[1].set( static_cast< task::XInteractionContinuation* >( pApprove ), uno::UNO_QUERY );
+            rtl::Reference<::comphelper::OInteractionAbort> pAbort = new ::comphelper::OInteractionAbort();
+            rtl::Reference<::comphelper::OInteractionApprove> pApprove = new ::comphelper::OInteractionApprove();
+            lContinuations[0] = pAbort;
+            lContinuations[1] = pApprove;
 
             task::ErrorCodeRequest aErrorCode;
             aErrorCode.ErrCode = sal_uInt32(nError);
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index bcda0a10debb..bc5e80224d84 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -890,10 +890,9 @@ ErrCode SfxObjectShell::HandleFilter( SfxMedium* pMedium, SfxObjectShell const *
 
                                 Sequence< PropertyValue > rProperties;
                                 TransformItems( SID_OPENDOC, *pSet, rProperties );
-                                RequestFilterOptions* pFORequest = new RequestFilterOptions( pDoc->GetModel(), rProperties );
+                                rtl::Reference<RequestFilterOptions> pFORequest = new RequestFilterOptions( pDoc->GetModel(), rProperties );
 
-                                css::uno::Reference< XInteractionRequest > rRequest( pFORequest );
-                                rHandler->handle( rRequest );
+                                rHandler->handle( pFORequest );
 
                                 if ( !pFORequest->isAbort() )
                                 {
@@ -3700,9 +3699,8 @@ bool SfxObjectShell::QuerySaveSizeExceededModules_Impl( const uno::Reference< ta
     {
         if( pImpl->aBasicManager.LegacyPsswdBinaryLimitExceeded( sModules ) )
         {
-            ModuleSizeExceeded* pReq =  new ModuleSizeExceeded( sModules );
-            uno::Reference< task::XInteractionRequest > xReq( pReq );
-            xHandler->handle( xReq );
+            rtl::Reference<ModuleSizeExceeded> pReq =  new ModuleSizeExceeded( sModules );
+            xHandler->handle( pReq );
             return pReq->isApprove();
         }
     }
diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx
index e1c457d2f338..dd0d7b54caf6 100644
--- a/sfx2/source/doc/sfxbasemodel.cxx
+++ b/sfx2/source/doc/sfxbasemodel.cxx
@@ -3887,8 +3887,8 @@ Reference< frame::XTitle > SfxBaseModel::impl_getTitleHelper ()
         Reference< frame::XUntitledNumbers >    xDesktop( frame::Desktop::create(xContext), UNO_QUERY_THROW);
         Reference< frame::XModel >              xThis   (static_cast< frame::XModel* >(this), UNO_QUERY_THROW);
 
-        ::framework::TitleHelper* pHelper = new ::framework::TitleHelper(xContext);
-        m_pData->m_xTitleHelper.set(static_cast< ::cppu::OWeakObject* >(pHelper), UNO_QUERY_THROW);
+        rtl::Reference<::framework::TitleHelper> pHelper = new ::framework::TitleHelper(xContext);
+        m_pData->m_xTitleHelper = pHelper;
         pHelper->setOwner                   (xThis   );
         pHelper->connectWithUntitledNumbers (xDesktop);
     }
@@ -3904,9 +3904,9 @@ Reference< frame::XUntitledNumbers > SfxBaseModel::impl_getUntitledHelper ()
     if ( ! m_pData->m_xNumberedControllers.is ())
     {
         Reference< frame::XModel > xThis   (static_cast< frame::XModel* >(this), UNO_QUERY_THROW);
-        ::comphelper::NumberedCollection*         pHelper = new ::comphelper::NumberedCollection();
+        rtl::Reference<::comphelper::NumberedCollection> pHelper = new ::comphelper::NumberedCollection();
 
-        m_pData->m_xNumberedControllers.set(static_cast< ::cppu::OWeakObject* >(pHelper), UNO_QUERY_THROW);
+        m_pData->m_xNumberedControllers = pHelper;
 
         pHelper->setOwner          (xThis);
         pHelper->setUntitledPrefix (" : ");
@@ -4047,9 +4047,7 @@ Reference< container::XEnumeration > SAL_CALL SfxBaseModel::getControllers()
     for (i=0; i<c; ++i)
         lEnum[i] <<= m_pData->m_seqControllers[i];
 
-    ::comphelper::OAnyEnumeration*                      pEnum = new ::comphelper::OAnyEnumeration(lEnum);
-    Reference< container::XEnumeration > xEnum(static_cast< container::XEnumeration* >(pEnum), UNO_QUERY_THROW);
-    return xEnum;
+    return new ::comphelper::OAnyEnumeration(lEnum);
 }
 
 
diff --git a/sfx2/source/view/sfxbasecontroller.cxx b/sfx2/source/view/sfxbasecontroller.cxx
index f07f9b4a1fd0..a74674a82917 100644
--- a/sfx2/source/view/sfxbasecontroller.cxx
+++ b/sfx2/source/view/sfxbasecontroller.cxx
@@ -1426,8 +1426,8 @@ Reference< frame::XTitle > SfxBaseController::impl_getTitleHelper ()
         Reference< frame::XUntitledNumbers > xUntitledProvider(xModel                                       , uno::UNO_QUERY      );
         Reference< frame::XController >      xThis            (static_cast< frame::XController* >(this), uno::UNO_QUERY_THROW);
 
-        ::framework::TitleHelper* pHelper                 = new ::framework::TitleHelper(::comphelper::getProcessComponentContext());
-        m_pData->m_xTitleHelper.set(static_cast< ::cppu::OWeakObject* >(pHelper), uno::UNO_QUERY_THROW);
+        rtl::Reference<::framework::TitleHelper> pHelper = new ::framework::TitleHelper(::comphelper::getProcessComponentContext());
+        m_pData->m_xTitleHelper = pHelper;
 
         pHelper->setOwner                   (xThis            );
         pHelper->connectWithUntitledNumbers (xUntitledProvider);
diff --git a/sfx2/source/view/viewprn.cxx b/sfx2/source/view/viewprn.cxx
index a01be90a0395..0007daf4a2f8 100644
--- a/sfx2/source/view/viewprn.cxx
+++ b/sfx2/source/view/viewprn.cxx
@@ -203,7 +203,7 @@ Sequence< beans::PropertyValue > SfxPrinterController::getMergedOptions() const
     if( xPrinter.get() != mpLastPrinter )
     {
         mpLastPrinter = xPrinter.get();
-        VCLXDevice* pXDevice = new VCLXDevice();
+        rtl::Reference<VCLXDevice> pXDevice = new VCLXDevice();
         pXDevice->SetOutputDevice( mpLastPrinter );
         mxDevice.set( pXDevice );
     }


More information about the Libreoffice-commits mailing list