sw/inc/fmtrfmrk.hxx                 |    7 +------
 sw/source/core/inc/unorefmark.hxx   |    2 ++
 sw/source/core/txtnode/atrref.cxx   |   19 ++++---------------
 sw/source/core/unocore/unorefmk.cxx |   14 +++-----------
 4 files changed, 10 insertions(+), 32 deletions(-)

New commits:
commit 466211a423d34b1383de5d7b942a0d5362c88fc2
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Fri Dec 27 18:45:30 2024 +0200
Commit:     Noel Grandin <noelgran...@gmail.com>
CommitDate: Sat Dec 28 09:54:51 2024 +0100

    Simplify SwFormatRefMark/SwXReferenceMark 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: Ie3a062d21f7215867ada5a9bacf1b00f0ce119f1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179474
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Tested-by: Jenkins

diff --git a/sw/inc/fmtrfmrk.hxx b/sw/inc/fmtrfmrk.hxx
index b41449fa97af..8b44a19d162a 100644
--- a/sw/inc/fmtrfmrk.hxx
+++ b/sw/inc/fmtrfmrk.hxx
@@ -37,9 +37,7 @@ class SwXReferenceMark;
 /// SwTextRefMark.
 ///
 /// It's Insert -> Cross-reference -> Cross-references -> set reference on the 
UI.
-class SAL_DLLPUBLIC_RTTI SwFormatRefMark final
-    : public SfxPoolItem
-    , public sw::BroadcastingModify
+class SAL_DLLPUBLIC_RTTI SwFormatRefMark final : public SfxPoolItem
 {
     friend class SwTextRefMark;
     SwTextRefMark* m_pTextAttr;
@@ -58,9 +56,6 @@ public:
     virtual bool            operator==( const SfxPoolItem& ) const override;
     virtual SwFormatRefMark* Clone( SfxItemPool* pPool = nullptr ) const 
override;
 
-    // SwClient
-    virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
-
     void InvalidateRefMark();
 
     const SwTextRefMark *GetTextRefMark() const   { return m_pTextAttr; }
diff --git a/sw/source/core/inc/unorefmark.hxx 
b/sw/source/core/inc/unorefmark.hxx
index 1d4ad9acec04..735350bb5c20 100644
--- a/sw/source/core/inc/unorefmark.hxx
+++ b/sw/source/core/inc/unorefmark.hxx
@@ -100,6 +100,8 @@ public:
             const css::uno::Reference< css::text::XTextRange > & xTextRange) 
override;
     virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getAnchor() 
override;
 
+    void OnFormatRefMarkDeleted();
+
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/txtnode/atrref.cxx 
b/sw/source/core/txtnode/atrref.cxx
index 87fdaf818637..038374ae4097 100644
--- a/sw/source/core/txtnode/atrref.cxx
+++ b/sw/source/core/txtnode/atrref.cxx
@@ -42,7 +42,6 @@ SwFormatRefMark::~SwFormatRefMark( )
 
 SwFormatRefMark::SwFormatRefMark( OUString aName )
     : SfxPoolItem(RES_TXTATR_REFMARK, SfxItemType::SwFormatRefMarkType)
-    , sw::BroadcastingModify()
     , m_pTextAttr(nullptr)
     , m_aRefName(std::move(aName))
 {
@@ -51,7 +50,6 @@ SwFormatRefMark::SwFormatRefMark( OUString aName )
 
 SwFormatRefMark::SwFormatRefMark( const SwFormatRefMark& rAttr )
     : SfxPoolItem(RES_TXTATR_REFMARK, SfxItemType::SwFormatRefMarkType)
-    , sw::BroadcastingModify()
     , m_pTextAttr(nullptr)
     , m_aRefName(rAttr.m_aRefName)
 {
@@ -72,22 +70,13 @@ SwFormatRefMark* SwFormatRefMark::Clone( SfxItemPool* ) 
const
     return new SwFormatRefMark( *this );
 }
 
-void SwFormatRefMark::SwClientNotify(const SwModify&, const SfxHint& rHint)
+void SwFormatRefMark::InvalidateRefMark()
 {
-    if(SfxHintId::SwRemoveUnoObject == rHint.GetId())
+    if (auto xUnoRefMark = m_wXReferenceMark.get())
     {
-        CallSwClientNotify(rHint);
-        SetXRefMark(nullptr);
-        return;
+        xUnoRefMark->OnFormatRefMarkDeleted();
+        m_wXReferenceMark.clear();
     }
-    if (rHint.GetId() != SfxHintId::SwLegacyModify)
-        return;
-    CallSwClientNotify(rHint);
-}
-
-void SwFormatRefMark::InvalidateRefMark()
-{
-    CallSwClientNotify(sw::RemoveUnoObjectHint(this));
 }
 
 void SwFormatRefMark::dumpAsXml(xmlTextWriterPtr pWriter) const
diff --git a/sw/source/core/unocore/unorefmk.cxx 
b/sw/source/core/unocore/unorefmk.cxx
index ac167a11e5fc..a393d69e00f3 100644
--- a/sw/source/core/unocore/unorefmk.cxx
+++ b/sw/source/core/unocore/unorefmk.cxx
@@ -60,7 +60,6 @@
 using namespace ::com::sun::star;
 
 class SwXReferenceMark::Impl
-    : public SvtListener
 {
 public:
     unotools::WeakReference<SwXReferenceMark> m_wThis;
@@ -78,7 +77,6 @@ public:
     {
         if (pRefMark)
         {
-            StartListening(pRefMark->GetNotifier());
             m_sMarkName = pRefMark->GetRefName();
         }
     }
@@ -86,14 +84,10 @@ public:
     bool IsValid() const { return m_pMarkFormat; }
     void InsertRefMark( SwPaM & rPam, SwXTextCursor const*const pCursor );
     void Invalidate();
-protected:
-    virtual void Notify(const SfxHint&) override;
-
 };
 
 void SwXReferenceMark::Impl::Invalidate()
 {
-    EndListeningAll();
     m_pDoc = nullptr;
     m_pMarkFormat = nullptr;
     uno::Reference<uno::XInterface> const xThis(m_wThis);
@@ -106,10 +100,9 @@ void SwXReferenceMark::Impl::Invalidate()
     m_EventListeners.disposeAndClear(aGuard, ev);
 }
 
-void SwXReferenceMark::Impl::Notify(const SfxHint& rHint)
+void SwXReferenceMark::OnFormatRefMarkDeleted()
 {
-    if(rHint.GetId() == SfxHintId::Dying)
-        Invalidate();
+    m_pImpl->Invalidate();
 }
 
 SwXReferenceMark::SwXReferenceMark(
@@ -245,8 +238,7 @@ void SwXReferenceMark::Impl::InsertRefMark(SwPaM& rPam,
     }
 
     m_pMarkFormat = &pTextAttr->GetRefMark();
-    EndListeningAll();
-    StartListening(const_cast<SwFormatRefMark*>(m_pMarkFormat)->GetNotifier());
+    const_cast<SwFormatRefMark*>(m_pMarkFormat)->SetXRefMark(m_wThis.get());
 }
 
 void SAL_CALL

Reply via email to