Kaydet (Commit) 9f0f289c authored tarafından Michael Stahl's avatar Michael Stahl

sw: replace SwEventListenerContainer in SwXDocumentIndex(,Mark}

Change-Id: I52b826ca071f71597f7d10f0ee44bf6c2d2468c1
üst 44df3bdc
...@@ -55,7 +55,6 @@ ...@@ -55,7 +55,6 @@
#include <docsh.hxx> #include <docsh.hxx>
#include <chpfld.hxx> #include <chpfld.hxx>
#include <SwStyleNameMapper.hxx> #include <SwStyleNameMapper.hxx>
#include <unoevtlstnr.hxx>
#include <comphelper/servicehelper.hxx> #include <comphelper/servicehelper.hxx>
#include <comphelper/string.hxx> #include <comphelper/string.hxx>
...@@ -319,15 +318,14 @@ lcl_TypeToPropertyMap_Index(const TOXTypes eType) ...@@ -319,15 +318,14 @@ lcl_TypeToPropertyMap_Index(const TOXTypes eType)
class SwXDocumentIndex::Impl class SwXDocumentIndex::Impl
: public SwClient : public SwClient
{ {
private:
::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper
public: public:
SwXDocumentIndex & m_rThis; SwXDocumentIndex & m_rThis;
::cppu::OMultiTypeInterfaceContainerHelper m_Listeners;
SfxItemPropertySet const& m_rPropSet; SfxItemPropertySet const& m_rPropSet;
const TOXTypes m_eTOXType; const TOXTypes m_eTOXType;
SwEventListenerContainer m_ListenerContainer;
osl::Mutex m_Mutex; // just for OInterfaceContainerHelper
::cppu::OInterfaceContainerHelper m_RefreshListeners;
bool m_bIsDescriptor; bool m_bIsDescriptor;
SwDoc * m_pDoc; SwDoc * m_pDoc;
::std::auto_ptr<SwDocIndexDescriptorProperties_Impl> m_pProps; ::std::auto_ptr<SwDocIndexDescriptorProperties_Impl> m_pProps;
...@@ -340,11 +338,10 @@ public: ...@@ -340,11 +338,10 @@ public:
SwTOXBaseSection const*const pBaseSection) SwTOXBaseSection const*const pBaseSection)
: SwClient((pBaseSection) ? pBaseSection->GetFmt() : 0) : SwClient((pBaseSection) ? pBaseSection->GetFmt() : 0)
, m_rThis(rThis) , m_rThis(rThis)
, m_Listeners(m_Mutex)
, m_rPropSet( , m_rPropSet(
*aSwMapProvider.GetPropertySet(lcl_TypeToPropertyMap_Index(eType))) *aSwMapProvider.GetPropertySet(lcl_TypeToPropertyMap_Index(eType)))
, m_eTOXType(eType) , m_eTOXType(eType)
, m_ListenerContainer(static_cast< ::cppu::OWeakObject* >(&rThis))
, m_RefreshListeners(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 == pBaseSection) ? true : false) , m_bIsDescriptor((0 == pBaseSection) ? true : false)
, m_pDoc(&rDoc) , m_pDoc(&rDoc)
...@@ -394,9 +391,8 @@ void SwXDocumentIndex::Impl::Modify(const SfxPoolItem *pOld, const SfxPoolItem * ...@@ -394,9 +391,8 @@ void SwXDocumentIndex::Impl::Modify(const SfxPoolItem *pOld, const SfxPoolItem *
if (!GetRegisteredIn()) if (!GetRegisteredIn())
{ {
m_ListenerContainer.Disposing();
lang::EventObject const ev(static_cast< ::cppu::OWeakObject&>(m_rThis)); lang::EventObject const ev(static_cast< ::cppu::OWeakObject&>(m_rThis));
m_RefreshListeners.disposeAndClear(ev); m_Listeners.disposeAndClear(ev);
} }
} }
...@@ -1263,9 +1259,14 @@ void SAL_CALL SwXDocumentIndex::refresh() throw (uno::RuntimeException) ...@@ -1263,9 +1259,14 @@ void SAL_CALL SwXDocumentIndex::refresh() throw (uno::RuntimeException)
pTOXBase->UpdatePageNum(); pTOXBase->UpdatePageNum();
} }
lang::EventObject const event(static_cast< ::cppu::OWeakObject*>(this)); ::cppu::OInterfaceContainerHelper *const pContainer(
m_pImpl->m_RefreshListeners.notifyEach( m_pImpl->m_Listeners.getContainer(
& util::XRefreshListener::refreshed, event); util::XRefreshListener::static_type()));
if (pContainer)
{
lang::EventObject const event(static_cast< ::cppu::OWeakObject*>(this));
pContainer->notifyEach(& util::XRefreshListener::refreshed, event);
}
} }
void SAL_CALL SwXDocumentIndex::addRefreshListener( void SAL_CALL SwXDocumentIndex::addRefreshListener(
...@@ -1273,7 +1274,8 @@ void SAL_CALL SwXDocumentIndex::addRefreshListener( ...@@ -1273,7 +1274,8 @@ void SAL_CALL SwXDocumentIndex::addRefreshListener(
throw (uno::RuntimeException) throw (uno::RuntimeException)
{ {
// no need to lock here as m_pImpl is const and container threadsafe // no need to lock here as m_pImpl is const and container threadsafe
m_pImpl->m_RefreshListeners.addInterface(xListener); m_pImpl->m_Listeners.addInterface(
util::XRefreshListener::static_type(), xListener);
} }
void SAL_CALL SwXDocumentIndex::removeRefreshListener( void SAL_CALL SwXDocumentIndex::removeRefreshListener(
...@@ -1281,7 +1283,8 @@ void SAL_CALL SwXDocumentIndex::removeRefreshListener( ...@@ -1281,7 +1283,8 @@ void SAL_CALL SwXDocumentIndex::removeRefreshListener(
throw (uno::RuntimeException) throw (uno::RuntimeException)
{ {
// no need to lock here as m_pImpl is const and container threadsafe // no need to lock here as m_pImpl is const and container threadsafe
m_pImpl->m_RefreshListeners.removeInterface(xListener); m_pImpl->m_Listeners.removeInterface(
util::XRefreshListener::static_type(), xListener);
} }
void SAL_CALL void SAL_CALL
...@@ -1390,13 +1393,9 @@ SwXDocumentIndex::addEventListener( ...@@ -1390,13 +1393,9 @@ SwXDocumentIndex::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_Listeners.addInterface(
if (!m_pImpl->GetRegisteredIn()) lang::XEventListener::static_type(), xListener);
{
throw uno::RuntimeException();
}
m_pImpl->m_ListenerContainer.AddListener(xListener);
} }
void SAL_CALL void SAL_CALL
...@@ -1404,13 +1403,9 @@ SwXDocumentIndex::removeEventListener( ...@@ -1404,13 +1403,9 @@ SwXDocumentIndex::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_Listeners.removeInterface(
if (!m_pImpl->GetRegisteredIn() || lang::XEventListener::static_type(), xListener);
!m_pImpl->m_ListenerContainer.RemoveListener(xListener))
{
throw uno::RuntimeException();
}
} }
OUString SAL_CALL SwXDocumentIndex::getName() throw (uno::RuntimeException) OUString SAL_CALL SwXDocumentIndex::getName() throw (uno::RuntimeException)
...@@ -1503,13 +1498,15 @@ class SwXDocumentIndexMark::Impl ...@@ -1503,13 +1498,15 @@ class SwXDocumentIndexMark::Impl
: public SwClient : public SwClient
{ {
private: private:
::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper
SwXDocumentIndexMark & m_rThis;
bool m_bInReplaceMark; bool m_bInReplaceMark;
public: public:
SfxItemPropertySet const& m_rPropSet; SfxItemPropertySet const& m_rPropSet;
const TOXTypes m_eTOXType; const TOXTypes m_eTOXType;
SwEventListenerContainer m_ListenerContainer; ::cppu::OInterfaceContainerHelper m_EventListeners;
bool m_bIsDescriptor; bool m_bIsDescriptor;
SwDepend m_TypeDepend; SwDepend m_TypeDepend;
const SwTOXMark * m_pTOXMark; const SwTOXMark * m_pTOXMark;
...@@ -1530,11 +1527,12 @@ public: ...@@ -1530,11 +1527,12 @@ public:
const enum TOXTypes eType, const enum TOXTypes eType,
SwTOXType *const pType, SwTOXMark const*const pMark) SwTOXType *const pType, SwTOXMark const*const pMark)
: SwClient(const_cast<SwTOXMark*>(pMark)) : SwClient(const_cast<SwTOXMark*>(pMark))
, m_rThis(rThis)
, m_bInReplaceMark(false) , m_bInReplaceMark(false)
, m_rPropSet( , m_rPropSet(
*aSwMapProvider.GetPropertySet(lcl_TypeToPropertyMap_Mark(eType))) *aSwMapProvider.GetPropertySet(lcl_TypeToPropertyMap_Mark(eType)))
, m_eTOXType(eType) , m_eTOXType(eType)
, m_ListenerContainer(static_cast< ::cppu::OWeakObject* >(&rThis)) , m_EventListeners(m_Mutex)
// #i112513#: unxsols4 (Sun C++ 5.9 SunOS_sparc) generates wrong code for this // #i112513#: unxsols4 (Sun C++ 5.9 SunOS_sparc) generates wrong code for this
// , m_bIsDescriptor(0 == pMark) // , m_bIsDescriptor(0 == pMark)
, m_bIsDescriptor((0 == pMark) ? true : false) , m_bIsDescriptor((0 == pMark) ? true : false)
...@@ -1569,7 +1567,9 @@ public: ...@@ -1569,7 +1567,9 @@ public:
InsertTOXMark(rTOXType, rMark, rPam, 0); InsertTOXMark(rTOXType, rMark, rPam, 0);
} catch (...) { } catch (...) {
OSL_FAIL("ReplaceTOXMark() failed!"); OSL_FAIL("ReplaceTOXMark() failed!");
m_ListenerContainer.Disposing(); lang::EventObject const ev(
static_cast< ::cppu::OWeakObject&>(m_rThis));
m_EventListeners.disposeAndClear(ev);
throw; throw;
} }
} }
...@@ -1593,7 +1593,8 @@ void SwXDocumentIndexMark::Impl::Invalidate() ...@@ -1593,7 +1593,8 @@ void SwXDocumentIndexMark::Impl::Invalidate()
} }
if (!m_bInReplaceMark) // #i109983# only dispose on delete, not on replace! if (!m_bInReplaceMark) // #i109983# only dispose on delete, not on replace!
{ {
m_ListenerContainer.Disposing(); lang::EventObject const ev(static_cast< ::cppu::OWeakObject&>(m_rThis));
m_EventListeners.disposeAndClear(ev);
} }
m_pDoc = 0; m_pDoc = 0;
m_pTOXMark = 0; m_pTOXMark = 0;
...@@ -2036,13 +2037,8 @@ SwXDocumentIndexMark::addEventListener( ...@@ -2036,13 +2037,8 @@ SwXDocumentIndexMark::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->GetRegisteredIn())
{
throw uno::RuntimeException();
}
m_pImpl->m_ListenerContainer.AddListener(xListener);
} }
void SAL_CALL void SAL_CALL
...@@ -2050,13 +2046,8 @@ SwXDocumentIndexMark::removeEventListener( ...@@ -2050,13 +2046,8 @@ SwXDocumentIndexMark::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->GetRegisteredIn() ||
!m_pImpl->m_ListenerContainer.RemoveListener(xListener))
{
throw uno::RuntimeException();
}
} }
uno::Reference< beans::XPropertySetInfo > SAL_CALL uno::Reference< beans::XPropertySetInfo > SAL_CALL
......
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