Kaydet (Commit) 7e1503b4 authored tarafından Bjoern Michaelsen's avatar Bjoern Michaelsen Kaydeden (comit) Björn Michaelsen

dont use SwClient/SwModify in unocore: SwXFieldMaster

Change-Id: I3e2579601c94fe6261e4eb56bbcf3b3b7905be7f
Reviewed-on: https://gerrit.libreoffice.org/55550Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarBjörn Michaelsen <bjoern.michaelsen@libreoffice.org>
üst d776263a
...@@ -227,7 +227,7 @@ OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang = ...@@ -227,7 +227,7 @@ OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang =
For each class there is one instance of the associated type class. For each class there is one instance of the associated type class.
Base class of all field types is SwFieldType. */ Base class of all field types is SwFieldType. */
class SW_DLLPUBLIC SwFieldType : public SwModify class SW_DLLPUBLIC SwFieldType : public SwModify, public sw::BroadcasterMixin
{ {
css::uno::WeakReference<css::beans::XPropertySet> m_wXFieldMaster; css::uno::WeakReference<css::beans::XPropertySet> m_wXFieldMaster;
......
...@@ -410,7 +410,7 @@ static sal_uInt16 lcl_GetPropertyMapOfService( SwServiceType nServiceId ) ...@@ -410,7 +410,7 @@ static sal_uInt16 lcl_GetPropertyMapOfService( SwServiceType nServiceId )
} }
class SwXFieldMaster::Impl class SwXFieldMaster::Impl
: public SwClient : public SvtListener
{ {
private: private:
::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper2 ::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper2
...@@ -420,8 +420,7 @@ public: ...@@ -420,8 +420,7 @@ public:
::comphelper::OInterfaceContainerHelper2 m_EventListeners; ::comphelper::OInterfaceContainerHelper2 m_EventListeners;
SwDoc* m_pDoc; SwDoc* m_pDoc;
SwFieldType* m_pType;
bool m_bIsDescriptor;
SwFieldIds m_nResTypeId; SwFieldIds m_nResTypeId;
...@@ -434,22 +433,39 @@ public: ...@@ -434,22 +433,39 @@ public:
bool m_bParam1; // IsExpression bool m_bParam1; // IsExpression
sal_Int32 m_nParam2; sal_Int32 m_nParam2;
Impl(SwModify *const pModify, Impl(SwPageDesc* const pPageDesc, SwDoc* pDoc, SwFieldIds nResId)
SwDoc * pDoc, SwFieldIds nResId, bool bIsDescriptor) : m_EventListeners(m_Mutex)
: SwClient(pModify)
, m_EventListeners(m_Mutex)
, m_pDoc(pDoc) , m_pDoc(pDoc)
, m_bIsDescriptor(bIsDescriptor) , m_pType(nullptr)
, m_nResTypeId(nResId) , m_nResTypeId(nResId)
, m_fParam1(0.0) , m_fParam1(0.0)
, m_nParam1(-1) , m_nParam1(-1)
, m_bParam1(false) , m_bParam1(false)
, m_nParam2(0) , m_nParam2(0)
{ } {
StartListening(pPageDesc->GetNotifier());
}
Impl(SwFieldType* const pType, SwDoc* pDoc, SwFieldIds nResId)
: m_EventListeners(m_Mutex)
, m_pDoc(pDoc)
, m_pType(pType)
, m_nResTypeId(nResId)
, m_fParam1(0.0)
, m_nParam1(-1)
, m_bParam1(false)
, m_nParam2(0)
{
StartListening(m_pType->GetNotifier());
}
void SetFieldType(SwFieldType* pType)
{
EndListeningAll();
m_pType = pType;
StartListening(m_pType->GetNotifier());
}
protected: protected:
// SwClient virtual void Notify(const SfxHint& rHint) override;
virtual void Modify(SfxPoolItem const* pOld, SfxPoolItem const* pNew) override;
}; };
namespace namespace
...@@ -522,13 +538,12 @@ SwXFieldMaster::getSupportedServiceNames() ...@@ -522,13 +538,12 @@ SwXFieldMaster::getSupportedServiceNames()
} }
SwXFieldMaster::SwXFieldMaster(SwDoc *const pDoc, SwFieldIds const nResId) SwXFieldMaster::SwXFieldMaster(SwDoc *const pDoc, SwFieldIds const nResId)
: m_pImpl(new Impl(pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD), : m_pImpl(new Impl(pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD), pDoc, nResId))
pDoc, nResId, true))
{ {
} }
SwXFieldMaster::SwXFieldMaster(SwFieldType& rType, SwDoc * pDoc) SwXFieldMaster::SwXFieldMaster(SwFieldType& rType, SwDoc * pDoc)
: m_pImpl(new Impl(&rType, pDoc, rType.Which(), false)) : m_pImpl(new Impl(&rType, pDoc, rType.Which()))
{ {
} }
...@@ -686,8 +701,7 @@ void SAL_CALL SwXFieldMaster::setPropertyValue( ...@@ -686,8 +701,7 @@ void SAL_CALL SwXFieldMaster::setPropertyValue(
{ {
throw uno::RuntimeException("no field type found!", *this); throw uno::RuntimeException("no field type found!", *this);
} }
pType2->Add(m_pImpl.get()); m_pImpl->SetFieldType(pType2);
m_pImpl->m_bIsDescriptor = false;
} }
else else
{ {
...@@ -781,7 +795,7 @@ void SAL_CALL SwXFieldMaster::setPropertyValue( ...@@ -781,7 +795,7 @@ void SAL_CALL SwXFieldMaster::setPropertyValue(
SwFieldType* SwXFieldMaster::GetFieldType(bool const bDontCreate) const SwFieldType* SwXFieldMaster::GetFieldType(bool const bDontCreate) const
{ {
if (!bDontCreate && SwFieldIds::Database == m_pImpl->m_nResTypeId if (!bDontCreate && SwFieldIds::Database == m_pImpl->m_nResTypeId
&& m_pImpl->m_bIsDescriptor && m_pImpl->m_pDoc) && !m_pImpl->m_pType && m_pImpl->m_pDoc)
{ {
SwDBData aData; SwDBData aData;
...@@ -798,13 +812,9 @@ SwFieldType* SwXFieldMaster::GetFieldType(bool const bDontCreate) const ...@@ -798,13 +812,9 @@ SwFieldType* SwXFieldMaster::GetFieldType(bool const bDontCreate) const
SwDBFieldType aType(m_pImpl->m_pDoc, m_pImpl->m_sParam3, aData); SwDBFieldType aType(m_pImpl->m_pDoc, m_pImpl->m_sParam3, aData);
SwFieldType *const pType = m_pImpl->m_pDoc->getIDocumentFieldsAccess().InsertFieldType(aType); SwFieldType *const pType = m_pImpl->m_pDoc->getIDocumentFieldsAccess().InsertFieldType(aType);
pType->Add(m_pImpl.get()); m_pImpl->SetFieldType(pType);
const_cast<SwXFieldMaster*>(this)->m_pImpl->m_bIsDescriptor = false;
} }
if (m_pImpl->m_bIsDescriptor) return m_pImpl->m_pType;
return nullptr;
else
return static_cast<SwFieldType*>(m_pImpl->GetRegisteredIn());
} }
uno::Any SAL_CALL uno::Any SAL_CALL
...@@ -1011,23 +1021,20 @@ void SAL_CALL SwXFieldMaster::removeEventListener( ...@@ -1011,23 +1021,20 @@ void SAL_CALL SwXFieldMaster::removeEventListener(
m_pImpl->m_EventListeners.removeInterface(xListener); m_pImpl->m_EventListeners.removeInterface(xListener);
} }
void SwXFieldMaster::Impl::Modify( void SwXFieldMaster::Impl::Notify(const SfxHint& rHint)
SfxPoolItem const*const pOld, SfxPoolItem const*const pNew)
{ {
ClientModify(this, pOld, pNew); if(rHint.GetId() == SfxHintId::Dying)
if (GetRegisteredIn())
{ {
return; // core object still alive m_pDoc = nullptr;
} m_pType = nullptr;
uno::Reference<uno::XInterface> const xThis(m_wThis);
m_pDoc = nullptr; if (!xThis.is())
uno::Reference<uno::XInterface> const xThis(m_wThis); { // fdo#72695: if UNO object is already dead, don't revive it with event
if (!xThis.is()) return;
{ // fdo#72695: if UNO object is already dead, don't revive it with event }
return; lang::EventObject const ev(xThis);
m_EventListeners.disposeAndClear(ev);
} }
lang::EventObject const ev(xThis);
m_EventListeners.disposeAndClear(ev);
} }
OUString SwXFieldMaster::GetProgrammaticName(const SwFieldType& rType, SwDoc& rDoc) OUString SwXFieldMaster::GetProgrammaticName(const SwFieldType& rType, SwDoc& rDoc)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment