sw/inc/fmtftn.hxx | 4 +--- sw/source/core/inc/unofootnote.hxx | 3 +++ sw/source/core/txtnode/atrftn.cxx | 18 ++++-------------- sw/source/core/unocore/unoftn.cxx | 11 ++++++++--- sw/source/filter/html/swhtml.hxx | 2 +- sw/source/filter/ww8/ww8par2.cxx | 2 +- 6 files changed, 18 insertions(+), 22 deletions(-)
New commits: commit 5622a7c601a34c2176d39887ca898fbfd279513a Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Fri Dec 27 18:56:48 2024 +0200 Commit: Noel Grandin <noelgran...@gmail.com> CommitDate: Sat Dec 28 15:03:47 2024 +0100 Simplify SwFormatFootnote/SwXFootnote interaction No need to use listeners here, both sides hold a pointer to a concrete class. And we only need to deal with destruction in one direction, because the other direction uses a weak reference. Change-Id: I2b1e05bcebbb7ff8b62ac1874edc91557dd6951f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179476 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Jenkins diff --git a/sw/inc/fmtftn.hxx b/sw/inc/fmtftn.hxx index 96742789d89a..689fca574af0 100644 --- a/sw/inc/fmtftn.hxx +++ b/sw/inc/fmtftn.hxx @@ -44,7 +44,7 @@ class SwXTextRange; /// for the footnote content is defined by m_pTextAttr. class SW_DLLPUBLIC SwFormatFootnote final : public SfxPoolItem - , public sw::BroadcastingModify + , public SvtBroadcaster { friend class SwTextFootnote; SwTextFootnote* m_pTextAttr; ///< My TextAttribute. @@ -66,8 +66,6 @@ public: virtual bool operator==( const SfxPoolItem& ) const override; virtual SwFormatFootnote* Clone( SfxItemPool* pPool = nullptr ) const override; - virtual void SwClientNotify(const SwModify&, const SfxHint&) override; - void InvalidateFootnote(); const OUString& GetNumStr() const { return m_aNumber; } diff --git a/sw/source/core/inc/unofootnote.hxx b/sw/source/core/inc/unofootnote.hxx index dd12ff058e29..03acbc6cacc1 100644 --- a/sw/source/core/inc/unofootnote.hxx +++ b/sw/source/core/inc/unofootnote.hxx @@ -130,6 +130,9 @@ public: virtual rtl::Reference< SwXTextCursor > createXTextCursor() override; virtual rtl::Reference< SwXTextCursor > createXTextCursorByRange( const ::css::uno::Reference< ::css::text::XTextRange >& aTextPosition ) override; + + void OnFormatFootnoteDeleted(); + private: rtl::Reference< SwXTextCursor > createXTextCursorByRangeImpl(SwUnoInternalPaM& rPam); }; diff --git a/sw/source/core/txtnode/atrftn.cxx b/sw/source/core/txtnode/atrftn.cxx index a63bde260b1d..ef2130fd1686 100644 --- a/sw/source/core/txtnode/atrftn.cxx +++ b/sw/source/core/txtnode/atrftn.cxx @@ -125,7 +125,6 @@ namespace { SwFormatFootnote::SwFormatFootnote( bool bEndNote ) : SfxPoolItem( RES_TXTATR_FTN, SfxItemType::SwFormatFootnoteType ) - , sw::BroadcastingModify() , m_pTextAttr(nullptr) , m_nNumber(0) , m_nNumberRLHidden(0) @@ -156,22 +155,13 @@ SwFormatFootnote* SwFormatFootnote::Clone( SfxItemPool* ) const return pNew; } -void SwFormatFootnote::SwClientNotify(const SwModify&, const SfxHint& rHint) +void SwFormatFootnote::InvalidateFootnote() { - if(SfxHintId::SwRemoveUnoObject == rHint.GetId()) + if (auto xUnoFootnote = m_wXFootnote.get()) { - CallSwClientNotify(rHint); - SetXFootnote(nullptr); - return; + xUnoFootnote->OnFormatFootnoteDeleted(); + m_wXFootnote.clear(); } - if (rHint.GetId() != SfxHintId::SwLegacyModify) - return; - CallSwClientNotify(rHint); -} - -void SwFormatFootnote::InvalidateFootnote() -{ - CallSwClientNotify(sw::RemoveUnoObjectHint(this)); } void SwFormatFootnote::SetEndNote( bool b ) diff --git a/sw/source/core/unocore/unoftn.cxx b/sw/source/core/unocore/unoftn.cxx index c3f175d77681..bbfa61e62a63 100644 --- a/sw/source/core/unocore/unoftn.cxx +++ b/sw/source/core/unocore/unoftn.cxx @@ -80,7 +80,8 @@ public: , m_bIsDescriptor(nullptr == pFootnote) , m_pFormatFootnote(pFootnote) { - m_pFormatFootnote && StartListening(m_pFormatFootnote->GetNotifier()); + if (m_pFormatFootnote) + StartListening(*m_pFormatFootnote); } const SwFormatFootnote* GetFootnoteFormat() const { @@ -98,7 +99,6 @@ public: void Invalidate(); protected: void Notify(const SfxHint& rHint) override; - }; void SwXFootnote::Impl::Invalidate() @@ -122,6 +122,11 @@ void SwXFootnote::Impl::Notify(const SfxHint& rHint) Invalidate(); } +void SwXFootnote::OnFormatFootnoteDeleted() +{ + Invalidate(); +} + SwXFootnote::SwXFootnote(const bool bEndnote) : SwXText(nullptr, CursorType::Footnote) , m_pImpl( new SwXFootnote::Impl(*this, nullptr, bEndnote) ) @@ -319,7 +324,7 @@ SwXFootnote::attach(const uno::Reference< text::XTextRange > & xTextRange) m_pImpl->EndListeningAll(); SwFormatFootnote* pFootnote = const_cast<SwFormatFootnote*>(&pTextAttr->GetFootnote()); m_pImpl->m_pFormatFootnote = pFootnote; - m_pImpl->StartListening(pFootnote->GetNotifier()); + m_pImpl->StartListening(*pFootnote); // force creation of sequence id - is used for references if (pNewDoc->IsInReading()) { diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx index 1f50803633dc..11e0fbfebc94 100644 --- a/sw/source/filter/html/swhtml.hxx +++ b/sw/source/filter/html/swhtml.hxx @@ -1041,7 +1041,7 @@ public: SwHTMLTextFootnote(OUString rName, SwTextFootnote* pInTextFootnote) : m_sName(std::move(rName)) , m_pTextFootnote(pInTextFootnote) - , m_xDeleteListener(new SvtDeleteListener(static_cast<SwFormatFootnote&>(pInTextFootnote->GetAttr()).GetNotifier())) + , m_xDeleteListener(new SvtDeleteListener(static_cast<SwFormatFootnote&>(pInTextFootnote->GetAttr()))) { } const OUString& GetName() const diff --git a/sw/source/filter/ww8/ww8par2.cxx b/sw/source/filter/ww8/ww8par2.cxx index 246f56ad9b84..86ac1f91a202 100644 --- a/sw/source/filter/ww8/ww8par2.cxx +++ b/sw/source/filter/ww8/ww8par2.cxx @@ -251,7 +251,7 @@ sal_uInt16 SwWW8ImplReader::End_Footnote() SwFormatFootnote& rFormatFootnote = static_cast<SwFormatFootnote&>(pFN->GetAttr()); - SvtDeleteListener aDeleteListener(rFormatFootnote.GetNotifier()); + SvtDeleteListener aDeleteListener(rFormatFootnote); // read content of Ft-/End-Note Read_HdFtFootnoteText( pSttIdx, rDesc.mnStartCp, rDesc.mnLen, rDesc.meType);