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

dont use SwClient/SwModify in unocore: Meta

Change-Id: Icde1f5b9af599ca8b1ef52863c2772670659a39b
Reviewed-on: https://gerrit.libreoffice.org/54648Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarBjörn Michaelsen <bjoern.michaelsen@libreoffice.org>
üst 74aeeb9a
...@@ -127,6 +127,7 @@ namespace sw { ...@@ -127,6 +127,7 @@ namespace sw {
class Meta class Meta
: public ::sfx2::Metadatable : public ::sfx2::Metadatable
, public SwModify , public SwModify
, public sw::BroadcasterMixin
{ {
protected: protected:
friend class ::SwFormatMeta; ///< SetFormatMeta, NotifyChangeTextNode friend class ::SwFormatMeta; ///< SetFormatMeta, NotifyChangeTextNode
......
...@@ -664,9 +664,7 @@ void Meta::NotifyChangeTextNode(SwTextNode *const pTextNode) ...@@ -664,9 +664,7 @@ void Meta::NotifyChangeTextNode(SwTextNode *const pTextNode)
} }
if (!pTextNode) // text node gone? invalidate UNO object! if (!pTextNode) // text node gone? invalidate UNO object!
{ {
SwPtrMsgPoolItem aMsgHint( RES_REMOVE_UNO_OBJECT, GetNotifier().Broadcast(SfxHint(SfxHintId::Deinitializing));
&static_cast<SwModify&>(*this) ); // cast to base class!
Modify(&aMsgHint, &aMsgHint);
} }
} }
...@@ -674,9 +672,11 @@ void Meta::NotifyChangeTextNode(SwTextNode *const pTextNode) ...@@ -674,9 +672,11 @@ void Meta::NotifyChangeTextNode(SwTextNode *const pTextNode)
void Meta::Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew ) void Meta::Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew )
{ {
NotifyClients(pOld, pNew); NotifyClients(pOld, pNew);
GetNotifier().Broadcast(SfxHint(SfxHintId::DataChanged));
if (pOld && (RES_REMOVE_UNO_OBJECT == pOld->Which())) if (pOld && (RES_REMOVE_UNO_OBJECT == pOld->Which()))
{ // invalidate cached uno object { // invalidate cached uno object
SetXMeta(uno::Reference<rdf::XMetadatable>(nullptr)); SetXMeta(uno::Reference<rdf::XMetadatable>(nullptr));
GetNotifier().Broadcast(SfxHint(SfxHintId::Deinitializing));
} }
} }
......
...@@ -607,8 +607,7 @@ SwXMetaText::createTextCursorByRange( ...@@ -607,8 +607,7 @@ SwXMetaText::createTextCursorByRange(
// the Meta has a cached list of text portions for its contents // the Meta has a cached list of text portions for its contents
// this list is created by SwXTextPortionEnumeration // this list is created by SwXTextPortionEnumeration
// the Meta listens at the SwTextNode and throws away the cache when it changes // the Meta listens at the SwTextNode and throws away the cache when it changes
class SwXMeta::Impl class SwXMeta::Impl : public SvtListener
: public SwClient
{ {
private: private:
::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper2 ::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper2
...@@ -622,56 +621,53 @@ public: ...@@ -622,56 +621,53 @@ public:
bool m_bIsDescriptor; bool m_bIsDescriptor;
uno::Reference<text::XText> m_xParentText; uno::Reference<text::XText> m_xParentText;
rtl::Reference<SwXMetaText> m_xText; rtl::Reference<SwXMetaText> m_xText;
sw::Meta* m_pMeta;
Impl( SwXMeta & rThis, SwDoc & rDoc, Impl(SwXMeta& rThis, SwDoc& rDoc,
::sw::Meta * const pMeta, ::sw::Meta* const pMeta,
uno::Reference<text::XText> const& xParentText, uno::Reference<text::XText> const& xParentText,
TextRangeList_t const * const pPortions) TextRangeList_t const * const pPortions)
: SwClient(pMeta) : m_EventListeners(m_Mutex)
, m_EventListeners(m_Mutex) , m_pTextPortions(pPortions)
, m_pTextPortions( pPortions ) , m_bIsDisposed(false)
, m_bIsDisposed( false )
, m_bIsDescriptor(nullptr == pMeta) , m_bIsDescriptor(nullptr == pMeta)
, m_xParentText(xParentText) , m_xParentText(xParentText)
, m_xText(new SwXMetaText(rDoc, rThis)) , m_xText(new SwXMetaText(rDoc, rThis))
, m_pMeta(pMeta)
{ {
!m_bIsDescriptor && StartListening(m_pMeta->GetNotifier());
} }
inline const ::sw::Meta * GetMeta() const; inline const ::sw::Meta* GetMeta() const;
// only for SwXMetaField! // only for SwXMetaField!
inline const ::sw::MetaField * GetMetaField() const; inline const ::sw::MetaField* GetMetaField() const;
protected: protected:
// SwClient virtual void Notify(const SfxHint& rHint) override;
virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) override;
}; };
inline const ::sw::Meta * SwXMeta::Impl::GetMeta() const inline const ::sw::Meta* SwXMeta::Impl::GetMeta() const
{ {
return static_cast< const ::sw::Meta * >(GetRegisteredIn()); return m_pMeta;
} }
// SwModify // SwModify
void SwXMeta::Impl::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) void SwXMeta::Impl::Notify(const SfxHint& rHint)
{ {
m_pTextPortions.reset(); // throw away cache (SwTextNode changed) m_pTextPortions.reset(); // throw away cache (SwTextNode changed)
if(rHint.GetId() == SfxHintId::Dying || rHint.GetId() == SfxHintId::Deinitializing)
ClientModify(this, pOld, pNew);
if (GetRegisteredIn())
{ {
return; // core object still alive m_bIsDisposed = true;
} m_pMeta = nullptr;
m_xText->Invalidate();
m_bIsDisposed = true; uno::Reference<uno::XInterface> const xThis(m_wThis);
m_xText->Invalidate(); 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);
} }
uno::Reference<text::XText> const & SwXMeta::GetParentText() const uno::Reference<text::XText> const & SwXMeta::GetParentText() const
...@@ -1020,7 +1016,9 @@ SwXMeta::AttachImpl(const uno::Reference< text::XTextRange > & i_xTextRange, ...@@ -1020,7 +1016,9 @@ SwXMeta::AttachImpl(const uno::Reference< text::XTextRange > & i_xTextRange,
static_cast< ::cppu::OWeakObject* >(this)); static_cast< ::cppu::OWeakObject* >(this));
} }
pMeta->Add(m_pImpl.get()); m_pImpl->EndListeningAll();
m_pImpl->m_pMeta = pMeta.get();
m_pImpl->StartListening(pMeta->GetNotifier());
pMeta->SetXMeta(uno::Reference<rdf::XMetadatable>(this)); pMeta->SetXMeta(uno::Reference<rdf::XMetadatable>(this));
m_pImpl->m_xParentText = ::sw::CreateParentXText(*pDoc, *aPam.GetPoint()); m_pImpl->m_xParentText = ::sw::CreateParentXText(*pDoc, *aPam.GetPoint());
...@@ -1186,12 +1184,10 @@ SwXMeta::getElementType() ...@@ -1186,12 +1184,10 @@ SwXMeta::getElementType()
return cppu::UnoType<text::XTextRange>::get(); return cppu::UnoType<text::XTextRange>::get();
} }
sal_Bool SAL_CALL sal_Bool SAL_CALL SwXMeta::hasElements()
SwXMeta::hasElements()
{ {
SolarMutexGuard g; SolarMutexGuard g;
return m_pImpl->m_pMeta != nullptr;
return m_pImpl->GetRegisteredIn() != nullptr;
} }
// XEnumerationAccess // XEnumerationAccess
...@@ -1253,9 +1249,9 @@ uno::Reference<frame::XModel> SwXMeta::GetModel() ...@@ -1253,9 +1249,9 @@ uno::Reference<frame::XModel> SwXMeta::GetModel()
return nullptr; return nullptr;
} }
inline const ::sw::MetaField * SwXMeta::Impl::GetMetaField() const inline const ::sw::MetaField* SwXMeta::Impl::GetMetaField() const
{ {
return static_cast< const ::sw::MetaField * >(GetRegisteredIn()); return dynamic_cast<sw::MetaField*>(m_pMeta);
} }
SwXMetaField::SwXMetaField(SwDoc *const pDoc, ::sw::Meta *const pMeta, SwXMetaField::SwXMetaField(SwDoc *const pDoc, ::sw::Meta *const pMeta,
......
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