diff options
author | Bjoern Michaelsen <bjoern.michaelsen@libreoffice.org> | 2018-01-31 01:13:53 +0100 |
---|---|---|
committer | Björn Michaelsen <bjoern.michaelsen@libreoffice.org> | 2018-03-11 23:32:14 +0100 |
commit | 5c04518c2d4b289289d551e22709e22702563d50 (patch) | |
tree | fd9b18cac156f4129ef18ee0db1c8132f085508d /sw/source/core/attr/calbck.cxx | |
parent | cf4b65c75c07142be0fcab5835188a28e839b749 (diff) |
introduce sw::WriterMultiListener
- 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 <ci@libreoffice.org>
Reviewed-by: Björn Michaelsen <bjoern.michaelsen@libreoffice.org>
Diffstat (limited to 'sw/source/core/attr/calbck.cxx')
-rw-r--r-- | sw/source/core/attr/calbck.cxx | 70 |
1 files changed, 58 insertions, 12 deletions
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 <swcache.hxx> #include <swfntcch.hxx> #include <tools/debug.hxx> +#include <algorithm> 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<sw::ModifyChangedHint> 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<const SwPtrMsgPoolItem*>(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<sw::ModifyChangedHint>(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: */ |