summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-10-06 12:17:55 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-10-06 13:48:42 +0200
commita5dbe5a8a9e98f2d79f2c535182fc557b561ed0f (patch)
tree1e99bc70ad0c923996d2eccc35cec6caee6354f3 /sfx2
parent62fc21675ccbfa5dcadbb2407729b804aac75ae2 (diff)
use rtl::Reference in svl,sfx2
instead of manual ref-counting Change-Id: Icb6472ffadfb57c9723b26f6f247e78fff45e528 Reviewed-on: https://gerrit.libreoffice.org/43193 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/control/bindings.cxx13
-rw-r--r--sfx2/source/control/statcach.cxx40
-rw-r--r--sfx2/source/inc/statcach.hxx9
3 files changed, 24 insertions, 38 deletions
diff --git a/sfx2/source/control/bindings.cxx b/sfx2/source/control/bindings.cxx
index a8d3124e9e1c..cc3990ba70f6 100644
--- a/sfx2/source/control/bindings.cxx
+++ b/sfx2/source/control/bindings.cxx
@@ -1567,16 +1567,15 @@ SfxItemState SfxBindings::QueryState( sal_uInt16 nSlot, std::unique_ptr<SfxPoolI
}
SfxItemState eState = SfxItemState::SET;
- BindDispatch_Impl *pBind = new BindDispatch_Impl( xDisp, aURL, pCache, pSlot );
- pBind->acquire();
- xDisp->addStatusListener( pBind, aURL );
- if ( !pBind->GetStatus().IsEnabled )
+ rtl::Reference<BindDispatch_Impl> xBind(new BindDispatch_Impl( xDisp, aURL, pCache, pSlot ));
+ xDisp->addStatusListener( xBind.get(), aURL );
+ if ( !xBind->GetStatus().IsEnabled )
{
eState = SfxItemState::DISABLED;
}
else
{
- css::uno::Any aAny = pBind->GetStatus().State;
+ css::uno::Any aAny = xBind->GetStatus().State;
css::uno::Type aType = aAny.getValueType();
if ( aType == cppu::UnoType<bool>::get() )
@@ -1607,8 +1606,8 @@ SfxItemState SfxBindings::QueryState( sal_uInt16 nSlot, std::unique_ptr<SfxPoolI
rpState.reset(new SfxVoidItem( nSlot ));
}
- xDisp->removeStatusListener( pBind, aURL );
- pBind->Release();
+ xDisp->removeStatusListener( xBind.get(), aURL );
+ xBind.clear();
if ( bDeleteCache )
DELETEZ( pCache );
return eState;
diff --git a/sfx2/source/control/statcach.cxx b/sfx2/source/control/statcach.cxx
index 1d0d794c428b..a8654ba26f77 100644
--- a/sfx2/source/control/statcach.cxx
+++ b/sfx2/source/control/statcach.cxx
@@ -145,16 +145,13 @@ void SAL_CALL BindDispatch_Impl::statusChanged( const css::frame::FeatureStateE
}
}
-void BindDispatch_Impl::Release()
+BindDispatch_Impl::~BindDispatch_Impl()
{
if ( xDisp.is() )
{
xDisp->removeStatusListener( static_cast<css::frame::XStatusListener*>(this), aURL );
xDisp.clear();
}
-
- pCache = nullptr;
- release();
}
@@ -180,7 +177,6 @@ sal_Int16 BindDispatch_Impl::Dispatch( const css::uno::Sequence < css::beans::Pr
// This constructor for an invalid cache that is updated in the first request.
SfxStateCache::SfxStateCache( sal_uInt16 nFuncId ):
- pDispatch( nullptr ),
nId(nFuncId),
pInternalController(nullptr),
pController(nullptr),
@@ -201,11 +197,6 @@ SfxStateCache::~SfxStateCache()
DBG_ASSERT( pController == nullptr && pInternalController == nullptr, "there are still Controllers registered" );
if ( !IsInvalidItem(pLastItem) )
delete pLastItem;
- if ( pDispatch )
- {
- pDispatch->Release();
- pDispatch = nullptr;
- }
}
@@ -217,11 +208,7 @@ void SfxStateCache::Invalidate( bool bWithMsg )
{
bSlotDirty = true;
aSlotServ.SetSlot( nullptr );
- if ( pDispatch )
- {
- pDispatch->Release();
- pDispatch = nullptr;
- }
+ mxDispatch.clear();
}
}
@@ -236,7 +223,7 @@ const SfxSlotServer* SfxStateCache::GetSlotServer( SfxDispatcher &rDispat , cons
// get the SlotServer; we need it for internal controllers anyway, but also in most cases
rDispat.FindServer_( nId, aSlotServ, false );
- DBG_ASSERT( !pDispatch, "Old Dispatch not removed!" );
+ DBG_ASSERT( !mxDispatch.is(), "Old Dispatch not removed!" );
// we don't need to check the dispatch provider if we only have an internal controller
if ( xProv.is() )
@@ -291,13 +278,12 @@ const SfxSlotServer* SfxStateCache::GetSlotServer( SfxDispatcher &rDispat , cons
}
// so the dispatch object isn't a SfxDispatcher wrapper or it is one, but it uses another dispatcher, but not rDispat
- pDispatch = new BindDispatch_Impl( xDisp, aURL, this, pSlot );
- pDispatch->acquire();
+ mxDispatch = new BindDispatch_Impl( xDisp, aURL, this, pSlot );
// flags must be set before adding StatusListener because the dispatch object will set the state
bSlotDirty = false;
bCtrlDirty = true;
- xDisp->addStatusListener( pDispatch, aURL );
+ xDisp->addStatusListener( mxDispatch.get(), aURL );
}
else if ( rDispat.GetFrame() )
{
@@ -367,7 +353,7 @@ void SfxStateCache::SetVisibleState( bool bShow )
}
// Update Controller
- if ( !pDispatch && pController )
+ if ( !mxDispatch.is() && pController )
{
for ( SfxControllerItem *pCtrl = pController;
pCtrl;
@@ -416,7 +402,7 @@ void SfxStateCache::SetState_Impl
if ( bNotify )
{
// Update Controller
- if ( !pDispatch && pController )
+ if ( !mxDispatch.is() && pController )
{
for ( SfxControllerItem *pCtrl = pController;
pCtrl;
@@ -454,7 +440,7 @@ void SfxStateCache::SetCachedState( bool bAlways )
if ( bAlways || ( !bItemDirty && !bSlotDirty ) )
{
// Update Controller
- if ( !pDispatch && pController )
+ if ( !mxDispatch.is() && pController )
{
for ( SfxControllerItem *pCtrl = pController;
pCtrl;
@@ -473,24 +459,24 @@ void SfxStateCache::SetCachedState( bool bAlways )
css::uno::Reference< css::frame::XDispatch > SfxStateCache::GetDispatch() const
{
- if ( pDispatch )
- return pDispatch->xDisp;
+ if ( mxDispatch.is() )
+ return mxDispatch->xDisp;
return css::uno::Reference< css::frame::XDispatch > ();
}
sal_Int16 SfxStateCache::Dispatch( const SfxItemSet* pSet, bool bForceSynchron )
{
// protect pDispatch against destruction in the call
- css::uno::Reference < css::frame::XStatusListener > xKeepAlive( pDispatch );
+ rtl::Reference<BindDispatch_Impl> xKeepAlive( mxDispatch );
sal_Int16 eRet = css::frame::DispatchResultState::DONTKNOW;
- if ( pDispatch )
+ if ( mxDispatch.is() )
{
uno::Sequence < beans::PropertyValue > aArgs;
if (pSet)
TransformItems( nId, *pSet, aArgs );
- eRet = pDispatch->Dispatch( aArgs, bForceSynchron );
+ eRet = mxDispatch->Dispatch( aArgs, bForceSynchron );
}
return eRet;
diff --git a/sfx2/source/inc/statcach.hxx b/sfx2/source/inc/statcach.hxx
index 6f17fe20dbb7..ef09b5dd51c4 100644
--- a/sfx2/source/inc/statcach.hxx
+++ b/sfx2/source/inc/statcach.hxx
@@ -46,11 +46,11 @@ public:
const css::uno::Reference< css::frame::XDispatch > & rDisp,
const css::util::URL& rURL,
SfxStateCache* pStateCache, const SfxSlot* pSlot );
+ ~BindDispatch_Impl() override;
- virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) override;
- virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
+ virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) override;
+ virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
- void Release();
const css::frame::FeatureStateEvent& GetStatus() const { return aStatus;}
sal_Int16 Dispatch( const css::uno::Sequence < css::beans::PropertyValue >& aProps, bool bForceSynchron );
};
@@ -58,7 +58,8 @@ public:
class SfxStateCache
{
friend class BindDispatch_Impl;
- BindDispatch_Impl* pDispatch;
+ rtl::Reference<BindDispatch_Impl>
+ mxDispatch;
sal_uInt16 nId; // Slot-Id
SfxControllerItem* pInternalController;
css::uno::Reference < css::frame::XDispatch > xMyDispatch;