diff options
author | Bjoern Michaelsen <bjoern.michaelsen@libreoffice.org> | 2018-02-04 17:40:15 +0100 |
---|---|---|
committer | Bjoern Michaelsen <bjoern.michaelsen@libreoffice.org> | 2018-02-04 17:40:15 +0100 |
commit | 484572952270629b89e8ca0389164514ea5bba61 (patch) | |
tree | 2e64e5e0ff965e7c3ddec3875e6423abb5aa80c4 | |
parent | 66df13011e863016182ff6b73f4472cba07a9083 (diff) |
ChangeNotify
-rw-r--r-- | sw/inc/calbck.hxx | 16 | ||||
-rw-r--r-- | sw/source/core/attr/calbck.cxx | 36 |
2 files changed, 32 insertions, 20 deletions
diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx index dea6e20c24aa..15b6a81fff81 100644 --- a/sw/inc/calbck.hxx +++ b/sw/inc/calbck.hxx @@ -27,6 +27,7 @@ #include <typeinfo> #include <type_traits> #include <list> +#include <memory> class SwModify; @@ -71,6 +72,12 @@ namespace sw const SfxPoolItem* m_pOld; const SfxPoolItem* m_pNew; }; + struct SW_DLLPUBLIC ModifyChangedHint final: SfxHint + { + ModifyChangedHint(const SwModify* pNew) : m_pNew(pNew) {}; + virtual ~ModifyChangedHint() override; + const SwModify* m_pNew; + }; /// refactoring out the some of the more sane SwClient functionality class SW_DLLPUBLIC WriterListener { @@ -124,7 +131,7 @@ public: // in case an SwModify object is destroyed that itself is registered in another SwModify, // its SwClient objects can decide to get registered to the latter instead by calling this method - void CheckRegistration( const SfxPoolItem *pOldValue ); + std::unique_ptr<sw::ModifyChangedHint> CheckRegistration( const SfxPoolItem* pOldValue ); // controlled access to Modify method // mba: this is still considered a hack and it should be fixed; the name makes grep-ing easier @@ -224,7 +231,12 @@ private: virtual void Modify( const SfxPoolItem* pOldValue, const SfxPoolItem *pNewValue ) override { if( pNewValue && pNewValue->Which() == RES_OBJECTDYING ) - CheckRegistration(pOldValue); + { + const auto& rOld = *GetRegisteredIn(); + const auto pChangeHint = CheckRegistration(pOldValue); + if(pChangeHint) + m_pToTell->SwClientNotify(rOld, *pChangeHint); + } else if( m_pToTell ) m_pToTell->ModifyNotification(pOldValue, pNewValue); } diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index c389e1d3fe14..53baf82662df 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -26,7 +26,7 @@ #include <algorithm> sw::LegacyModifyHint::~LegacyModifyHint() {} - +sw::ModifyChangedHint::~ModifyChangedHint() {} SwClient::~SwClient() { @@ -37,28 +37,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) + { + assert(false); // we should only 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::make_unique<sw::ModifyChangedHint>(pAbove); } void SwClient::SwClientNotify(const SwModify&, const SfxHint& rHint) @@ -303,11 +308,6 @@ void SwMultiDepend::EndListening(SwModify* pBroadcaster) { return aListener.GetRegisteredIn() == nullptr || aListener.GetRegisteredIn() == pBroadcaster; }); - /* m_vpDepends.erase(std::remove_if(m_vpDepends.begin(), m_vpDepends.end(), - [&pBroadcaster](const std::shared_ptr<SwDepend> pListener) - { - return pListener->GetRegisteredIn() == nullptr || pListener->GetRegisteredIn() == pBroadcaster; - })); */ } void SwMultiDepend::EndListeningAll() |