1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_comphelper.hxx"
30 #include "comphelper/containermultiplexer.hxx"
31 #include "comphelper/uno3.hxx"
32 #include <osl/diagnose.h>
33 //.........................................................................
36 //.........................................................................
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::lang
;
40 using namespace ::com::sun::star::container
;
42 //=====================================================================
43 //= OContainerListener
44 //=====================================================================
45 //---------------------------------------------------------------------
46 OContainerListener::OContainerListener(::osl::Mutex
& _rMutex
)
52 //---------------------------------------------------------------------
53 OContainerListener::~OContainerListener()
57 m_pAdapter
->dispose();
62 //---------------------------------------------------------------------
63 void OContainerListener::_elementInserted( const ContainerEvent
& /*_rEvent*/ ) throw(RuntimeException
)
67 //---------------------------------------------------------------------
68 void OContainerListener::_elementRemoved( const ContainerEvent
& ) throw(RuntimeException
)
72 //---------------------------------------------------------------------
73 void OContainerListener::_elementReplaced( const ContainerEvent
& /*_rEvent*/ ) throw(RuntimeException
)
77 //---------------------------------------------------------------------
78 void OContainerListener::_disposing(const EventObject
& ) throw( RuntimeException
)
82 //------------------------------------------------------------------
83 void OContainerListener::setAdapter(OContainerListenerAdapter
* pAdapter
)
87 ::osl::MutexGuard
aGuard(m_rMutex
);
88 m_pAdapter
->release();
94 ::osl::MutexGuard
aGuard(m_rMutex
);
95 m_pAdapter
= pAdapter
;
96 m_pAdapter
->acquire();
100 //=====================================================================
101 //= OContainerListenerAdapter
102 //=====================================================================
103 //---------------------------------------------------------------------
104 OContainerListenerAdapter::OContainerListenerAdapter(OContainerListener
* _pListener
,
105 const Reference
< XContainer
>& _rxContainer
)
106 :m_xContainer(_rxContainer
)
107 ,m_pListener(_pListener
)
111 m_pListener
->setAdapter(this);
113 ::comphelper::increment(m_refCount
);
116 m_xContainer
->addContainerListener(this);
118 catch(const Exception
&)
120 OSL_ENSURE(0,"Exceptiopn catched!");
122 ::comphelper::decrement(m_refCount
);
125 //---------------------------------------------------------------------
126 OContainerListenerAdapter::~OContainerListenerAdapter()
130 //------------------------------------------------------------------
131 void OContainerListenerAdapter::lock()
136 //------------------------------------------------------------------
137 void OContainerListenerAdapter::unlock()
142 //------------------------------------------------------------------
143 void OContainerListenerAdapter::dispose()
145 if (m_xContainer
.is())
149 Reference
< XContainerListener
> xPreventDelete(this);
150 m_xContainer
->removeContainerListener(xPreventDelete
);
151 m_pListener
->setAdapter(NULL
);
153 catch(const Exception
&)
155 OSL_ENSURE(0,"Exception catched!");
162 //------------------------------------------------------------------
163 void SAL_CALL
OContainerListenerAdapter::disposing( const EventObject
& _rSource
) throw(RuntimeException
)
169 m_pListener
->_disposing(_rSource
);
170 // disconnect the listener
172 m_pListener
->setAdapter(NULL
);
179 //------------------------------------------------------------------
180 void SAL_CALL
OContainerListenerAdapter::elementInserted( const ContainerEvent
& _rEvent
) throw(RuntimeException
)
182 if (m_pListener
&& !locked())
183 m_pListener
->_elementInserted(_rEvent
);
186 //------------------------------------------------------------------
187 void SAL_CALL
OContainerListenerAdapter::elementRemoved( const ContainerEvent
& _rEvent
) throw(RuntimeException
)
189 if (m_pListener
&& !locked())
190 m_pListener
->_elementRemoved(_rEvent
);
193 //------------------------------------------------------------------
194 void SAL_CALL
OContainerListenerAdapter::elementReplaced( const ContainerEvent
& _rEvent
) throw(RuntimeException
)
196 if (m_pListener
&& !locked())
197 m_pListener
->_elementReplaced(_rEvent
);
200 //.........................................................................
201 } // namespace comphelper
202 //.........................................................................