sw/inc/tox.hxx | 1 - sw/source/core/inc/unoidx.hxx | 3 +++ sw/source/core/tox/tox.cxx | 17 ++++++----------- sw/source/core/unocore/unoidx.cxx | 13 ++++++------- 4 files changed, 15 insertions(+), 19 deletions(-)
New commits: commit c028e57f9622028d31a8eb07bcbbb56d98c9765e Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Fri Dec 27 13:49:20 2024 +0200 Commit: Noel Grandin <noelgran...@gmail.com> CommitDate: Fri Dec 27 15:05:23 2024 +0100 Simplify SwTOXMark/SwXDocumentIndexMark 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: I64058c1dee78056441847d85f33f57fc37a8c05d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179441 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Jenkins diff --git a/sw/inc/tox.hxx b/sw/inc/tox.hxx index dcaf4f92d487..201e519d7404 100644 --- a/sw/inc/tox.hxx +++ b/sw/inc/tox.hxx @@ -78,7 +78,6 @@ extern const sal_Unicode C_END_PAGE_NUM; class SW_DLLPUBLIC SwTOXMark final : public SfxPoolItem - , public sw::BroadcasterMixin , public SvtListener { friend void InitCore(); diff --git a/sw/source/core/inc/unoidx.hxx b/sw/source/core/inc/unoidx.hxx index 00049859376a..6d5f2f9eb393 100644 --- a/sw/source/core/inc/unoidx.hxx +++ b/sw/source/core/inc/unoidx.hxx @@ -206,6 +206,9 @@ public: virtual OUString SAL_CALL getMarkEntry() override; virtual void SAL_CALL setMarkEntry(const OUString& rIndexEntry) override; + // called when the associated SwTOXMark is deleted + void OnSwTOXMarkDeleted(); + }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/tox/tox.cxx b/sw/source/core/tox/tox.cxx index 056d427b592f..54ac15c6e0b5 100644 --- a/sw/source/core/tox/tox.cxx +++ b/sw/source/core/tox/tox.cxx @@ -167,16 +167,7 @@ SwTOXMark* SwTOXMark::Clone( SfxItemPool* ) const void SwTOXMark::Notify(const SfxHint& rHint) { - if(SfxHintId::SwRemoveUnoObject == rHint.GetId()) - { - GetNotifier().Broadcast(rHint); - SetXTOXMark(nullptr); - } - else if (rHint.GetId() == SfxHintId::SwLegacyModify) - { - GetNotifier().Broadcast(rHint); - } - else if (rHint.GetId() == SfxHintId::SwCollectTextMarks) + if (rHint.GetId() == SfxHintId::SwCollectTextMarks) { auto pCollectHint = static_cast<const sw::CollectTextMarksHint*>(&rHint); if(GetTextTOXMark()) @@ -208,7 +199,11 @@ void SwTOXMark::Notify(const SfxHint& rHint) void SwTOXMark::InvalidateTOXMark() { - GetNotifier().Broadcast(sw::RemoveUnoObjectHint(this)); + if (auto xUnoIndexMark = m_wXDocumentIndexMark.get()) + { + xUnoIndexMark->OnSwTOXMarkDeleted(); + m_wXDocumentIndexMark.clear(); + } } OUString SwTOXMark::GetText(SwRootFrame const*const pLayout) const diff --git a/sw/source/core/unocore/unoidx.cxx b/sw/source/core/unocore/unoidx.cxx index 9e47678d7a1e..3cba56977729 100644 --- a/sw/source/core/unocore/unoidx.cxx +++ b/sw/source/core/unocore/unoidx.cxx @@ -1542,11 +1542,8 @@ public: , m_bMainEntry(false) , m_nLevel(0) { - auto pMarkNonConst = const_cast<SwTOXMark*>(m_pTOXMark); auto pTypeNonConst = const_cast<SwTOXType*>(m_pTOXType); - if(pMarkNonConst) - StartListening(pMarkNonConst->GetNotifier()); if(pTypeNonConst) StartListening(pTypeNonConst->GetNotifier()); } @@ -1610,9 +1607,6 @@ void SwXDocumentIndexMark::Impl::Notify(const SfxHint& rHint) auto pModifyChangedHint = static_cast<const sw::ModifyChangedHint*>(&rHint); if(auto pNewType = dynamic_cast<const SwTOXType*>(pModifyChangedHint->m_pNew)) m_pTOXType = pNewType; - - else - Invalidate(); } } @@ -1632,6 +1626,12 @@ SwXDocumentIndexMark::~SwXDocumentIndexMark() { } +// called when the associated SwTOXMark is deleted +void SwXDocumentIndexMark::OnSwTOXMarkDeleted() +{ + m_pImpl->Invalidate(); +} + rtl::Reference<SwXDocumentIndexMark> SwXDocumentIndexMark::CreateXDocumentIndexMark( SwDoc & rDoc, SwTOXMark *const pMark, TOXTypes const eType) @@ -1941,7 +1941,6 @@ void SwXDocumentIndexMark::Impl::InsertTOXMark( m_pTOXMark = &pNewTextAttr->GetTOXMark(); m_pTOXType = &rTOXType; EndListeningAll(); - StartListening(const_cast<SwTOXMark*>(m_pTOXMark)->GetNotifier()); StartListening(const_cast<SwTOXType*>(m_pTOXType)->GetNotifier()); }