sw/source/core/unocore/unofield.cxx |   57 +++++++++++++++++++++---------------
 sw/source/core/unocore/unotbl.cxx   |    1 
 2 files changed, 34 insertions(+), 24 deletions(-)

New commits:
commit 2c9298e4f667a5dd7606d79890fcedfff0f66e26
Author:     Bjoern Michaelsen <bjoern.michael...@libreoffice.org>
AuthorDate: Fri Apr 5 23:14:47 2019 +0200
Commit:     Björn Michaelsen <bjoern.michael...@libreoffice.org>
CommitDate: Sat Apr 6 12:33:22 2019 +0200

    SwXTextField::Impl FieldTypeClient: SwClient no more
    
    Change-Id: I745ebae5a58df9b3a7dcb96448099f6803b7b1a2
    Reviewed-on: https://gerrit.libreoffice.org/70326
    Tested-by: Jenkins
    Reviewed-by: Björn Michaelsen <bjoern.michael...@libreoffice.org>

diff --git a/sw/source/core/unocore/unofield.cxx 
b/sw/source/core/unocore/unofield.cxx
index 439a387488a9..5bf539324d0b 100644
--- a/sw/source/core/unocore/unofield.cxx
+++ b/sw/source/core/unocore/unofield.cxx
@@ -1117,10 +1117,11 @@ struct SwFieldProperties_Impl
 };
 
 class SwXTextField::Impl
-    : public SwClient
+    : public SwClient, public SvtListener
 {
 private:
     ::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper2
+    SwFieldType* m_pFieldType;
 
 public:
     uno::WeakReference<uno::XInterface> m_wThis;
@@ -1131,8 +1132,6 @@ public:
     rtl::Reference<SwTextAPIObject> m_xTextObject;
 
     bool                m_bIsDescriptor;
-    // required to access field master of not yet inserted fields
-    SwClient            m_FieldTypeClient;
     bool                m_bCallUpdate;
     SwServiceType const       m_nServiceId;
     OUString            m_sTypeName;
@@ -1164,9 +1163,29 @@ public:
 
     const SwField*      GetField() const;
 
+    SwFieldType* GetFieldType()
+    {
+        if (m_bIsDescriptor)
+            return m_pFieldType;
+        if (!GetRegisteredIn())
+            throw uno::RuntimeException();
+        return m_pFormatField->GetField()->GetTyp();
+    }
+    void SetFieldType(SwFieldType& rType)
+    {
+        SvtListener::EndListeningAll();
+        m_pFieldType = &rType;
+        StartListening(m_pFieldType->GetNotifier());
+    }
+    void ClearFieldType()
+    {
+        SvtListener::EndListeningAll();
+        m_pFieldType = nullptr;
+    }
 protected:
     // SwClient
     virtual void Modify(SfxPoolItem const* pOld, SfxPoolItem const* pNew) 
override;
+    virtual void Notify(const SfxHint&) override;
 };
 
 namespace
@@ -1270,26 +1289,14 @@ void SAL_CALL SwXTextField::attachTextFieldMaster(
         throw lang::IllegalArgumentException();
     }
     m_pImpl->m_sTypeName = pFieldType->GetName();
-    pFieldType->Add( &m_pImpl->m_FieldTypeClient );
+    m_pImpl->SetFieldType(*pFieldType);
 }
 
 uno::Reference< beans::XPropertySet > SAL_CALL
 SwXTextField::getTextFieldMaster()
 {
     SolarMutexGuard aGuard;
-    SwFieldType* pType = nullptr;
-    if (m_pImpl->m_bIsDescriptor && 
m_pImpl->m_FieldTypeClient.GetRegisteredIn())
-    {
-        pType = static_cast<SwFieldType*>(
-                    m_pImpl->m_FieldTypeClient.GetRegisteredIn());
-    }
-    else
-    {
-        if (!m_pImpl->GetRegisteredIn())
-            throw uno::RuntimeException();
-        pType = m_pImpl->m_pFormatField->GetField()->GetTyp();
-    }
-
+    SwFieldType* pType = m_pImpl->GetFieldType();
     uno::Reference<beans::XPropertySet> const xRet(
             SwXFieldMaster::CreateXFieldMaster(m_pImpl->m_pDoc, pType));
     return xRet;
@@ -1959,11 +1966,7 @@ void SAL_CALL SwXTextField::attach(
     m_pImpl->m_pDoc = pDoc;
     const_cast<SwFormatField *>(m_pImpl->m_pFormatField)->Add(m_pImpl.get());
     m_pImpl->m_bIsDescriptor = false;
-    if (m_pImpl->m_FieldTypeClient.GetRegisteredIn())
-    {
-        m_pImpl->m_FieldTypeClient.GetRegisteredIn()
-            ->Remove(&m_pImpl->m_FieldTypeClient);
-    }
+    m_pImpl->ClearFieldType();
     m_pImpl->m_pProps.reset();
     if (m_pImpl->m_bCallUpdate)
         update();
@@ -2574,7 +2577,7 @@ void SwXTextField::Impl::Invalidate()
 {
     if (GetRegisteredIn())
     {
-        EndListeningAll();
+        SwClient::EndListeningAll();
         m_pFormatField = nullptr;
         m_pDoc = nullptr;
         uno::Reference<uno::XInterface> const xThis(m_wThis);
@@ -2607,6 +2610,14 @@ void SwXTextField::Impl::Modify(
     }
 }
 
+void SwXTextField::Impl::Notify(const SfxHint& rHint)
+{
+    if(rHint.GetId() == SfxHintId::Dying)
+    {
+        m_pFieldType = nullptr;
+    }
+}
+
 const SwField*  SwXTextField::Impl::GetField() const
 {
     if (GetRegisteredIn() && m_pFormatField)
diff --git a/sw/source/core/unocore/unotbl.cxx 
b/sw/source/core/unocore/unotbl.cxx
index 2bf04080a03d..d7abd42dea4a 100644
--- a/sw/source/core/unocore/unotbl.cxx
+++ b/sw/source/core/unocore/unotbl.cxx
@@ -105,7 +105,6 @@
 #include <rtl/math.hxx>
 #include <sal/log.hxx>
 #include <editeng/frmdiritem.hxx>
-#include <calbck.hxx>
 #include <comphelper/interfacecontainer2.hxx>
 #include <comphelper/servicehelper.hxx>
 #include <comphelper/string.hxx>
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to