Kaydet (Commit) 99990c99 authored tarafından Michael Stahl's avatar Michael Stahl

sw: replace SwEventListenerContainer in SwXReferenceMark,SwXMeta

Change-Id: Iba34cbc9afcd372426a90f3fd5e2d5fa997d7c5e
üst 9f0f289c
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <osl/mutex.hxx> #include <osl/mutex.hxx>
#include <cppuhelper/interfacecontainer.h>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <unomid.h> #include <unomid.h>
...@@ -27,7 +28,6 @@ ...@@ -27,7 +28,6 @@
#include <unotextcursor.hxx> #include <unotextcursor.hxx>
#include <unomap.hxx> #include <unomap.hxx>
#include <unocrsr.hxx> #include <unocrsr.hxx>
#include <unoevtlstnr.hxx>
#include <unocrsrhelper.hxx> #include <unocrsrhelper.hxx>
#include <doc.hxx> #include <doc.hxx>
#include <ndtxt.hxx> #include <ndtxt.hxx>
...@@ -46,9 +46,12 @@ using ::rtl::OUString; ...@@ -46,9 +46,12 @@ using ::rtl::OUString;
class SwXReferenceMark::Impl class SwXReferenceMark::Impl
: public SwClient : public SwClient
{ {
private:
::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper
SwXReferenceMark & m_rThis;
public: public:
SwEventListenerContainer m_ListenerContainer; ::cppu::OInterfaceContainerHelper m_EventListeners;
bool m_bIsDescriptor; bool m_bIsDescriptor;
SwDoc * m_pDoc; SwDoc * m_pDoc;
const SwFmtRefMark * m_pMarkFmt; const SwFmtRefMark * m_pMarkFmt;
...@@ -57,7 +60,8 @@ public: ...@@ -57,7 +60,8 @@ public:
Impl( SwXReferenceMark & rThis, Impl( SwXReferenceMark & rThis,
SwDoc *const pDoc, SwFmtRefMark const*const pRefMark) SwDoc *const pDoc, SwFmtRefMark const*const pRefMark)
: SwClient((pDoc) ? pDoc->GetUnoCallBack() : 0) : SwClient((pDoc) ? pDoc->GetUnoCallBack() : 0)
, m_ListenerContainer(static_cast< ::cppu::OWeakObject* >(&rThis)) , m_rThis(rThis)
, m_EventListeners(m_Mutex)
// #i111177# unxsols4 (Sun C++ 5.9 SunOS_sparc) may generate wrong code // #i111177# unxsols4 (Sun C++ 5.9 SunOS_sparc) may generate wrong code
, m_bIsDescriptor((0 == pRefMark) ? true : false) , m_bIsDescriptor((0 == pRefMark) ? true : false)
, m_pDoc(pDoc) , m_pDoc(pDoc)
...@@ -84,9 +88,10 @@ void SwXReferenceMark::Impl::Invalidate() ...@@ -84,9 +88,10 @@ void SwXReferenceMark::Impl::Invalidate()
{ {
const_cast<SwModify*>(GetRegisteredIn())->Remove(this); const_cast<SwModify*>(GetRegisteredIn())->Remove(this);
} }
m_ListenerContainer.Disposing();
m_pDoc = 0; m_pDoc = 0;
m_pMarkFmt = 0; m_pMarkFmt = 0;
lang::EventObject const ev(static_cast< ::cppu::OWeakObject&>(m_rThis));
m_EventListeners.disposeAndClear(ev);
} }
void SwXReferenceMark::Impl::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) void SwXReferenceMark::Impl::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
...@@ -374,26 +379,16 @@ void SAL_CALL SwXReferenceMark::addEventListener( ...@@ -374,26 +379,16 @@ void SAL_CALL SwXReferenceMark::addEventListener(
const uno::Reference< lang::XEventListener > & xListener) const uno::Reference< lang::XEventListener > & xListener)
throw (uno::RuntimeException) throw (uno::RuntimeException)
{ {
SolarMutexGuard g; // no need to lock here as m_pImpl is const and container threadsafe
m_pImpl->m_EventListeners.addInterface(xListener);
if (!m_pImpl->IsValid())
{
throw uno::RuntimeException();
}
m_pImpl->m_ListenerContainer.AddListener(xListener);
} }
void SAL_CALL SwXReferenceMark::removeEventListener( void SAL_CALL SwXReferenceMark::removeEventListener(
const uno::Reference< lang::XEventListener > & xListener) const uno::Reference< lang::XEventListener > & xListener)
throw (uno::RuntimeException) throw (uno::RuntimeException)
{ {
SolarMutexGuard g; // no need to lock here as m_pImpl is const and container threadsafe
m_pImpl->m_EventListeners.removeInterface(xListener);
if (!m_pImpl->IsValid() ||
!m_pImpl->m_ListenerContainer.RemoveListener(xListener))
{
throw uno::RuntimeException();
}
} }
OUString SAL_CALL SwXReferenceMark::getName() OUString SAL_CALL SwXReferenceMark::getName()
...@@ -662,10 +657,11 @@ SwXMetaText::createTextCursorByRange( ...@@ -662,10 +657,11 @@ SwXMetaText::createTextCursorByRange(
class SwXMeta::Impl class SwXMeta::Impl
: public SwClient : public SwClient
{ {
private:
::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper
public: public:
::cppu::OInterfaceContainerHelper m_EventListeners;
SwEventListenerContainer m_ListenerContainer;
SAL_WNODEPRECATED_DECLARATIONS_PUSH SAL_WNODEPRECATED_DECLARATIONS_PUSH
::std::auto_ptr<const TextRangeList_t> m_pTextPortions; ::std::auto_ptr<const TextRangeList_t> m_pTextPortions;
SAL_WNODEPRECATED_DECLARATIONS_POP SAL_WNODEPRECATED_DECLARATIONS_POP
...@@ -680,7 +676,7 @@ public: ...@@ -680,7 +676,7 @@ public:
uno::Reference<text::XText> const& xParentText, uno::Reference<text::XText> const& xParentText,
TextRangeList_t const * const pPortions) TextRangeList_t const * const pPortions)
: SwClient(pMeta) : SwClient(pMeta)
, m_ListenerContainer(static_cast< ::cppu::OWeakObject* >(&rThis)) , m_EventListeners(m_Mutex)
, m_pTextPortions( pPortions ) , m_pTextPortions( pPortions )
, m_bIsDisposed( false ) , m_bIsDisposed( false )
// #i111177# unxsols4 (Sun C++ 5.9 SunOS_sparc) may generate wrong code // #i111177# unxsols4 (Sun C++ 5.9 SunOS_sparc) may generate wrong code
...@@ -713,8 +709,10 @@ void SwXMeta::Impl::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) ...@@ -713,8 +709,10 @@ void SwXMeta::Impl::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
if (!GetRegisteredIn()) // removed => dispose if (!GetRegisteredIn()) // removed => dispose
{ {
m_ListenerContainer.Disposing();
m_bIsDisposed = true; m_bIsDisposed = true;
lang::EventObject const ev(
static_cast< ::cppu::OWeakObject&>(m_Text.GetXMeta()));
m_EventListeners.disposeAndClear(ev);
m_Text.Invalidate(); m_Text.Invalidate();
} }
} }
...@@ -936,13 +934,8 @@ SwXMeta::addEventListener( ...@@ -936,13 +934,8 @@ SwXMeta::addEventListener(
uno::Reference< lang::XEventListener> const & xListener ) uno::Reference< lang::XEventListener> const & xListener )
throw (uno::RuntimeException) throw (uno::RuntimeException)
{ {
SolarMutexGuard g; // no need to lock here as m_pImpl is const and container threadsafe
m_pImpl->m_EventListeners.addInterface(xListener);
m_pImpl->m_ListenerContainer.AddListener(xListener);
if (m_pImpl->m_bIsDisposed)
{
m_pImpl->m_ListenerContainer.Disposing();
}
} }
void SAL_CALL void SAL_CALL
...@@ -950,12 +943,8 @@ SwXMeta::removeEventListener( ...@@ -950,12 +943,8 @@ SwXMeta::removeEventListener(
uno::Reference< lang::XEventListener> const & xListener ) uno::Reference< lang::XEventListener> const & xListener )
throw (uno::RuntimeException) throw (uno::RuntimeException)
{ {
SolarMutexGuard g; // no need to lock here as m_pImpl is const and container threadsafe
m_pImpl->m_EventListeners.removeInterface(xListener);
if (!m_pImpl->m_bIsDisposed)
{
m_pImpl->m_ListenerContainer.RemoveListener(xListener);
}
} }
void SAL_CALL void SAL_CALL
...@@ -966,7 +955,8 @@ SwXMeta::dispose() throw (uno::RuntimeException) ...@@ -966,7 +955,8 @@ SwXMeta::dispose() throw (uno::RuntimeException)
if (m_pImpl->m_bIsDescriptor) if (m_pImpl->m_bIsDescriptor)
{ {
m_pImpl->m_pTextPortions.reset(); m_pImpl->m_pTextPortions.reset();
m_pImpl->m_ListenerContainer.Disposing(); lang::EventObject const ev(static_cast< ::cppu::OWeakObject&>(*this));
m_pImpl->m_EventListeners.disposeAndClear(ev);
m_pImpl->m_bIsDisposed = true; m_pImpl->m_bIsDisposed = true;
m_pImpl->m_Text.Invalidate(); m_pImpl->m_Text.Invalidate();
} }
......
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