merge the formfield patch from ooo-build
[ooovba.git] / comphelper / source / container / containermultiplexer.cxx
blob9c4e829e21eafb969d51803f1763f5e76dd1edda
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: containermultiplexer.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_comphelper.hxx"
33 #include "comphelper/containermultiplexer.hxx"
34 #include "comphelper/uno3.hxx"
35 #include <osl/diagnose.h>
36 //.........................................................................
37 namespace comphelper
39 //.........................................................................
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::lang;
43 using namespace ::com::sun::star::container;
45 //=====================================================================
46 //= OContainerListener
47 //=====================================================================
48 //---------------------------------------------------------------------
49 OContainerListener::OContainerListener(::osl::Mutex& _rMutex)
50 :m_pAdapter(NULL)
51 ,m_rMutex(_rMutex)
55 //---------------------------------------------------------------------
56 OContainerListener::~OContainerListener()
58 if (m_pAdapter)
60 m_pAdapter->dispose();
61 m_pAdapter = NULL;
65 //---------------------------------------------------------------------
66 void OContainerListener::_elementInserted( const ContainerEvent& /*_rEvent*/ ) throw(RuntimeException)
70 //---------------------------------------------------------------------
71 void OContainerListener::_elementRemoved( const ContainerEvent& ) throw(RuntimeException)
75 //---------------------------------------------------------------------
76 void OContainerListener::_elementReplaced( const ContainerEvent& /*_rEvent*/ ) throw(RuntimeException)
80 //---------------------------------------------------------------------
81 void OContainerListener::_disposing(const EventObject& ) throw( RuntimeException)
85 //------------------------------------------------------------------
86 void OContainerListener::setAdapter(OContainerListenerAdapter* pAdapter)
88 if (m_pAdapter)
90 ::osl::MutexGuard aGuard(m_rMutex);
91 m_pAdapter->release();
92 m_pAdapter = NULL;
95 if (pAdapter)
97 ::osl::MutexGuard aGuard(m_rMutex);
98 m_pAdapter = pAdapter;
99 m_pAdapter->acquire();
103 //=====================================================================
104 //= OContainerListenerAdapter
105 //=====================================================================
106 //---------------------------------------------------------------------
107 OContainerListenerAdapter::OContainerListenerAdapter(OContainerListener* _pListener,
108 const Reference< XContainer >& _rxContainer)
109 :m_xContainer(_rxContainer)
110 ,m_pListener(_pListener)
111 ,m_nLockCount(0)
113 if (m_pListener)
114 m_pListener->setAdapter(this);
116 ::comphelper::increment(m_refCount);
119 m_xContainer->addContainerListener(this);
121 catch(const Exception&)
123 OSL_ENSURE(0,"Exceptiopn catched!");
125 ::comphelper::decrement(m_refCount);
128 //---------------------------------------------------------------------
129 OContainerListenerAdapter::~OContainerListenerAdapter()
133 //------------------------------------------------------------------
134 void OContainerListenerAdapter::lock()
136 ++m_nLockCount;
139 //------------------------------------------------------------------
140 void OContainerListenerAdapter::unlock()
142 --m_nLockCount;
145 //------------------------------------------------------------------
146 void OContainerListenerAdapter::dispose()
148 if (m_xContainer.is())
152 Reference< XContainerListener > xPreventDelete(this);
153 m_xContainer->removeContainerListener(xPreventDelete);
154 m_pListener->setAdapter(NULL);
156 catch(const Exception&)
158 OSL_ENSURE(0,"Exception catched!");
160 m_xContainer = NULL;
161 m_pListener = NULL;
165 //------------------------------------------------------------------
166 void SAL_CALL OContainerListenerAdapter::disposing( const EventObject& _rSource) throw(RuntimeException)
168 if (m_pListener)
170 // tell the listener
171 if (!locked())
172 m_pListener->_disposing(_rSource);
173 // disconnect the listener
174 if ( m_pListener )
175 m_pListener->setAdapter(NULL);
178 m_xContainer = NULL;
179 m_pListener = NULL;
182 //------------------------------------------------------------------
183 void SAL_CALL OContainerListenerAdapter::elementInserted( const ContainerEvent& _rEvent ) throw(RuntimeException)
185 if (m_pListener && !locked())
186 m_pListener->_elementInserted(_rEvent);
189 //------------------------------------------------------------------
190 void SAL_CALL OContainerListenerAdapter::elementRemoved( const ContainerEvent& _rEvent ) throw(RuntimeException)
192 if (m_pListener && !locked())
193 m_pListener->_elementRemoved(_rEvent);
196 //------------------------------------------------------------------
197 void SAL_CALL OContainerListenerAdapter::elementReplaced( const ContainerEvent& _rEvent ) throw(RuntimeException)
199 if (m_pListener && !locked())
200 m_pListener->_elementReplaced(_rEvent);
203 //.........................................................................
204 } // namespace comphelper
205 //.........................................................................