diff --git a/sw/source/core/unocore/unoparagraph.cxx b/sw/source/core/unocore/unoparagraph.cxx index f8a0983432e0..f7a76e902013 100644 --- a/sw/source/core/unocore/unoparagraph.cxx +++ b/sw/source/core/unocore/unoparagraph.cxx @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -44,14 +45,14 @@ #include #include #include -#include -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include using namespace ::com::sun::star; @@ -102,47 +103,47 @@ static beans::PropertyState lcl_SwXParagraph_getPropertyState( bool &rAttrSetFetched ); class SwXParagraph::Impl - : public SwClient + : public SvtListener { private: ::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper2 public: - SwXParagraph & m_rThis; + SwXParagraph& m_rThis; uno::WeakReference m_wThis; ::comphelper::OInterfaceContainerHelper2 m_EventListeners; - SfxItemPropertySet const& m_rPropSet; - bool m_bIsDescriptor; - sal_Int32 m_nSelectionStartPos; - sal_Int32 m_nSelectionEndPos; - OUString m_sText; + SfxItemPropertySet const& m_rPropSet; + bool m_bIsDescriptor; + sal_Int32 m_nSelectionStartPos; + sal_Int32 m_nSelectionEndPos; + OUString m_sText; uno::Reference m_xParentText; + SwTextNode* m_pTextNode; - Impl( SwXParagraph & rThis, - SwTextNode *const pTextNode = nullptr, - uno::Reference< text::XText > const & xParent = nullptr, + Impl(SwXParagraph& rThis, + SwTextNode* const pTextNode = nullptr, uno::Reference const& xParent = nullptr, const sal_Int32 nSelStart = -1, const sal_Int32 nSelEnd = -1) - : SwClient(pTextNode) - , m_rThis(rThis) + : m_rThis(rThis) , m_EventListeners(m_Mutex) , m_rPropSet(*aSwMapProvider.GetPropertySet(PROPERTY_MAP_PARAGRAPH)) , m_bIsDescriptor(nullptr == pTextNode) , m_nSelectionStartPos(nSelStart) , m_nSelectionEndPos(nSelEnd) , m_xParentText(xParent) + , m_pTextNode(pTextNode) { + m_pTextNode && StartListening(m_pTextNode->GetNotifier()); } SwTextNode* GetTextNode() { - return static_cast(GetRegisteredInNonConst()); + return m_pTextNode; } - SwTextNode & GetTextNodeOrThrow() { - SwTextNode *const pTextNode( GetTextNode() ); - if (!pTextNode) { + SwTextNode& GetTextNodeOrThrow() { + if (!m_pTextNode) { throw uno::RuntimeException("SwXParagraph: disposed or invalid", nullptr); } - return *pTextNode; + return *m_pTextNode; } bool IsDescriptor() const { return m_bIsDescriptor; } @@ -175,26 +176,23 @@ public: const uno::Sequence< OUString >& rPropertyNames, bool bDirectValuesOnly); protected: - // SwClient - virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override; + virtual void Notify(const SfxHint& rHint) override; }; -void SwXParagraph::Impl::Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew ) +void SwXParagraph::Impl::Notify(const SfxHint& rHint) { - ClientModify(this, pOld, pNew); - if (GetRegisteredIn()) + if(rHint.GetId() == SfxHintId::Dying) { - return; // core object still alive + m_pTextNode = nullptr; + uno::Reference const xThis(m_wThis); + if (!xThis.is()) + { // fdo#72695: if UNO object is already dead, don't revive it with event + return; + } + lang::EventObject const ev(xThis); + m_EventListeners.disposeAndClear(ev); } - - uno::Reference const xThis(m_wThis); - if (!xThis.is()) - { // fdo#72695: if UNO object is already dead, don't revive it with event - return; - } - lang::EventObject const ev(xThis); - m_EventListeners.disposeAndClear(ev); } SwXParagraph::SwXParagraph() @@ -336,7 +334,8 @@ SwXParagraph::attachToText(SwXText & rParent, SwTextNode & rTextNode) if (m_pImpl->m_bIsDescriptor) { m_pImpl->m_bIsDescriptor = false; - rTextNode.Add(m_pImpl.get()); + m_pImpl->EndListeningAll(); + m_pImpl->StartListening(rTextNode.GetNotifier()); rTextNode.SetXParagraph(uno::Reference(this)); m_pImpl->m_xParentText = &rParent; if (!m_pImpl->m_sText.isEmpty())