summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorKurt Zenker <kz@openoffice.org>2004-01-28 11:46:55 +0000
committerKurt Zenker <kz@openoffice.org>2004-01-28 11:46:55 +0000
commit0e38b5529a2a1420ee2c5e58969e3bff0d21925b (patch)
treeb55e6bacc4741bdb5c94adfe031fb1cc76d580e5 /comphelper
parent9abbf7cec6aea14f95dba17376a154b3e7cb7f88 (diff)
INTEGRATION: CWS filtercfg (1.2.36); FILE MERGED
2003/07/30 09:08:48 as 1.2.36.1: #102620# new ctor to support outside filtered lists of container items
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/source/container/enumhelper.cxx186
1 files changed, 172 insertions, 14 deletions
diff --git a/comphelper/source/container/enumhelper.cxx b/comphelper/source/container/enumhelper.cxx
index 9f0369367231..f32c0fba119b 100644
--- a/comphelper/source/container/enumhelper.cxx
+++ b/comphelper/source/container/enumhelper.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: enumhelper.cxx,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: hr $ $Date: 2003-03-19 15:58:34 $
+ * last change: $Author: kz $ $Date: 2004-01-28 12:46:55 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -63,6 +63,10 @@
#include <comphelper/enumhelper.hxx>
#endif
+#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_
+#include <com/sun/star/lang/XComponent.hpp>
+#endif
+
//.........................................................................
namespace comphelper
{
@@ -72,26 +76,63 @@ namespace comphelper
//= OEnumerationByName
//==================================================================
//------------------------------------------------------------------------------
+OEnumerationByName::OEnumerationByName(const staruno::Reference<starcontainer::XNameAccess>& _rxAccess)
+ :m_aNames(_rxAccess->getElementNames())
+ ,m_nPos(0)
+ ,m_xAccess(_rxAccess)
+ ,m_bListening(sal_False)
+{
+ impl_startDisposeListening();
+}
+
+//------------------------------------------------------------------------------
+OEnumerationByName::OEnumerationByName(const staruno::Reference<starcontainer::XNameAccess>& _rxAccess,
+ const staruno::Sequence< ::rtl::OUString >& _aNames )
+ :m_aNames(_aNames)
+ ,m_nPos(0)
+ ,m_xAccess(_rxAccess)
+{
+ impl_startDisposeListening();
+}
+
+//------------------------------------------------------------------------------
+OEnumerationByName::~OEnumerationByName()
+{
+ impl_stopDisposeListening();
+}
+
+//------------------------------------------------------------------------------
sal_Bool SAL_CALL OEnumerationByName::hasMoreElements( ) throw(staruno::RuntimeException)
{
- sal_Bool bRet = sal_False;
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+
if (m_xAccess.is() && m_aNames.getLength() > m_nPos)
- bRet = sal_True;
- else if (m_xAccess.is())
- m_xAccess = NULL;
+ return sal_True;
- return bRet;
+ if (m_xAccess.is())
+ {
+ impl_stopDisposeListening();
+ m_xAccess.clear();
+ }
+
+ return sal_False;
}
//------------------------------------------------------------------------------
staruno::Any SAL_CALL OEnumerationByName::nextElement( )
throw(starcontainer::NoSuchElementException, starlang::WrappedTargetException, staruno::RuntimeException)
{
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+
staruno::Any aRes;
if (m_xAccess.is() && m_nPos < m_aNames.getLength())
aRes = m_xAccess->getByName(m_aNames.getConstArray()[m_nPos++]);
+
if (m_xAccess.is() && m_nPos >= m_aNames.getLength())
- m_xAccess = NULL;
+ {
+ impl_stopDisposeListening();
+ m_xAccess.clear();
+ }
if (!aRes.hasValue()) // es gibt kein Element mehr
throw starcontainer::NoSuchElementException();
@@ -99,31 +140,102 @@ staruno::Any SAL_CALL OEnumerationByName::nextElement( )
return aRes;
}
+//------------------------------------------------------------------------------
+void SAL_CALL OEnumerationByName::disposing(const starlang::EventObject& aEvent)
+ throw(staruno::RuntimeException)
+{
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+
+ if (aEvent.Source == m_xAccess)
+ m_xAccess.clear();
+}
+
+//------------------------------------------------------------------------------
+void OEnumerationByName::impl_startDisposeListening()
+{
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+
+ if (m_bListening)
+ return;
+
+ ++m_refCount;
+ staruno::Reference< starlang::XComponent > xDisposable(m_xAccess, staruno::UNO_QUERY);
+ if (xDisposable.is())
+ {
+ xDisposable->addEventListener(this);
+ m_bListening = sal_True;
+ }
+ --m_refCount;
+}
+
+//------------------------------------------------------------------------------
+void OEnumerationByName::impl_stopDisposeListening()
+{
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+
+ if (!m_bListening)
+ return;
+
+ ++m_refCount;
+ staruno::Reference< starlang::XComponent > xDisposable(m_xAccess, staruno::UNO_QUERY);
+ if (xDisposable.is())
+ {
+ xDisposable->removeEventListener(this);
+ m_bListening = sal_False;
+ }
+ --m_refCount;
+}
+
//==================================================================
//= OEnumerationByIndex
//==================================================================
//------------------------------------------------------------------------------
+OEnumerationByIndex::OEnumerationByIndex(const staruno::Reference< starcontainer::XIndexAccess >& _rxAccess)
+ :m_xAccess(_rxAccess)
+ ,m_nPos(0)
+ ,m_bListening(sal_False)
+{
+ impl_startDisposeListening();
+}
+
+//------------------------------------------------------------------------------
+OEnumerationByIndex::~OEnumerationByIndex()
+{
+ impl_stopDisposeListening();
+}
+
+//------------------------------------------------------------------------------
sal_Bool SAL_CALL OEnumerationByIndex::hasMoreElements( ) throw(staruno::RuntimeException)
{
- sal_Bool bRet = sal_False;
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+
if (m_xAccess.is() && m_xAccess->getCount() > m_nPos)
- bRet = sal_True;
- else if (m_xAccess.is())
- m_xAccess = NULL;
+ return sal_True;
+
+ if (m_xAccess.is())
+ {
+ impl_stopDisposeListening();
+ m_xAccess.clear();
+ }
- return bRet;
+ return sal_False;
}
//------------------------------------------------------------------------------
staruno::Any SAL_CALL OEnumerationByIndex::nextElement( )
throw(starcontainer::NoSuchElementException, starlang::WrappedTargetException, staruno::RuntimeException)
{
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+
staruno::Any aRes;
if (m_xAccess.is())
{
aRes = m_xAccess->getByIndex(m_nPos++);
if (m_nPos >= m_xAccess->getCount())
- m_xAccess = NULL;
+ {
+ impl_stopDisposeListening();
+ m_xAccess.clear();
+ }
}
if (!aRes.hasValue()) // es gibt kein Element mehr
@@ -131,6 +243,52 @@ staruno::Any SAL_CALL OEnumerationByIndex::nextElement( )
return aRes;
}
+//------------------------------------------------------------------------------
+void SAL_CALL OEnumerationByIndex::disposing(const starlang::EventObject& aEvent)
+ throw(staruno::RuntimeException)
+{
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+
+ if (aEvent.Source == m_xAccess)
+ m_xAccess.clear();
+}
+
+//------------------------------------------------------------------------------
+void OEnumerationByIndex::impl_startDisposeListening()
+{
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+
+ if (m_bListening)
+ return;
+
+ ++m_refCount;
+ staruno::Reference< starlang::XComponent > xDisposable(m_xAccess, staruno::UNO_QUERY);
+ if (xDisposable.is())
+ {
+ xDisposable->addEventListener(this);
+ m_bListening = sal_True;
+ }
+ --m_refCount;
+}
+
+//------------------------------------------------------------------------------
+void OEnumerationByIndex::impl_stopDisposeListening()
+{
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+
+ if (!m_bListening)
+ return;
+
+ ++m_refCount;
+ staruno::Reference< starlang::XComponent > xDisposable(m_xAccess, staruno::UNO_QUERY);
+ if (xDisposable.is())
+ {
+ xDisposable->removeEventListener(this);
+ m_bListening = sal_False;
+ }
+ --m_refCount;
+}
+
//.........................................................................
} // namespace comphelper
//.........................................................................