From 5c04518c2d4b289289d551e22709e22702563d50 Mon Sep 17 00:00:00 2001 From: Bjoern Michaelsen Date: Wed, 31 Jan 2018 01:13:53 +0100 Subject: introduce sw::WriterMultiListener MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - it can handle multple sources to listen to: this should make SwDepend (always been a hack) soon obsolete - also add a unittest for it - WriterMultiListener notifies via hints about reregistering, so help migrating away from these crazy static_cast<>(GetRegisteredIn()) - fix expected<->actual asserts in uwriter.cxx Change-Id: I8c70826d1a8be5c8097d81304f0df42bb7319cd4 Reviewed-on: https://gerrit.libreoffice.org/49565 Tested-by: Jenkins Reviewed-by: Björn Michaelsen --- sw/source/core/attr/calbck.cxx | 70 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 12 deletions(-) (limited to 'sw/source/core/attr/calbck.cxx') diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index 98376e649a93..a0f82b381841 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -23,8 +23,20 @@ #include #include #include +#include sw::LegacyModifyHint::~LegacyModifyHint() {} +sw::ModifyChangedHint::~ModifyChangedHint() {} + + +SwClient::SwClient(SwClient&& o) +{ + if(o.m_pRegisteredIn) + { + o.m_pRegisteredIn->Add(this); + o.EndListeningAll(); + } +} SwClient::~SwClient() @@ -36,28 +48,33 @@ SwClient::~SwClient() m_pRegisteredIn->Remove( this ); } -void SwClient::CheckRegistration( const SfxPoolItem* pOld ) +std::unique_ptr SwClient::CheckRegistration( const SfxPoolItem* pOld ) { DBG_TESTSOLARMUTEX(); // this method only handles notification about dying SwModify objects if( !pOld || pOld->Which() != RES_OBJECTDYING ) - return; + return nullptr; const SwPtrMsgPoolItem* pDead = static_cast(pOld); - if(pDead && pDead->pObject == m_pRegisteredIn) + if(!pDead || pDead->pObject != m_pRegisteredIn) + { + // we should only care received death notes from objects we are following + return nullptr; + } + // I've got a notification from the object I know + SwModify* pAbove = m_pRegisteredIn->GetRegisteredIn(); + if(pAbove) + { + // if the dying object itself was listening at an SwModify, I take over + // adding myself to pAbove will automatically remove me from my current pRegisteredIn + pAbove->Add(this); + } + else { - // I've got a notification from the object I know - SwModify* pAbove = m_pRegisteredIn->GetRegisteredIn(); - if(pAbove) - { - // if the dying object itself was listening at an SwModify, I take over - // adding myself to pAbove will automatically remove me from my current pRegisteredIn - pAbove->Add(this); - return; - } // destroy connection EndListeningAll(); } + return std::unique_ptr(new sw::ModifyChangedHint(pAbove)); } void SwClient::SwClientNotify(const SwModify&, const SfxHint& rHint) @@ -280,5 +297,34 @@ void SwModify::CheckCaching( const sal_uInt16 nWhich ) } } +void sw::WriterMultiListener::StartListening(SwModify* pDepend) +{ + EndListening(nullptr); + m_vDepends.emplace_back(pointer_t( new SwDepend(&m_rToTell, pDepend))); +} + + +bool sw::WriterMultiListener::IsListeningTo(const SwModify* const pBroadcaster) +{ + return std::any_of(m_vDepends.begin(), m_vDepends.end(), + [&pBroadcaster](const pointer_t& pListener) + { + return pListener->GetRegisteredIn() == pBroadcaster; + }); +} + +void sw::WriterMultiListener::EndListening(SwModify* pBroadcaster) +{ + m_vDepends.remove_if( [&pBroadcaster](const pointer_t& pListener) + { + return pListener->GetRegisteredIn() == nullptr || pListener->GetRegisteredIn() == pBroadcaster; + }); +} + +void sw::WriterMultiListener::EndListeningAll() +{ + m_vDepends.clear(); +} + sw::ClientIteratorBase* sw::ClientIteratorBase::our_pClientIters = nullptr; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit