1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "comphelper/containermultiplexer.hxx"
21 #include "comphelper/uno3.hxx"
22 #include <osl/diagnose.h>
23 //.........................................................................
26 //.........................................................................
28 using namespace ::com::sun::star::uno
;
29 using namespace ::com::sun::star::lang
;
30 using namespace ::com::sun::star::container
;
32 //=====================================================================
33 //= OContainerListener
34 //=====================================================================
35 //---------------------------------------------------------------------
36 OContainerListener::OContainerListener(::osl::Mutex
& _rMutex
)
42 //---------------------------------------------------------------------
43 OContainerListener::~OContainerListener()
47 m_pAdapter
->dispose();
52 //---------------------------------------------------------------------
53 void OContainerListener::_elementInserted( const ContainerEvent
& /*_rEvent*/ ) throw(RuntimeException
)
57 //---------------------------------------------------------------------
58 void OContainerListener::_elementRemoved( const ContainerEvent
& ) throw(RuntimeException
)
62 //---------------------------------------------------------------------
63 void OContainerListener::_elementReplaced( const ContainerEvent
& /*_rEvent*/ ) throw(RuntimeException
)
67 //---------------------------------------------------------------------
68 void OContainerListener::_disposing(const EventObject
& ) throw( RuntimeException
)
72 //------------------------------------------------------------------
73 void OContainerListener::setAdapter(OContainerListenerAdapter
* pAdapter
)
77 ::osl::MutexGuard
aGuard(m_rMutex
);
78 m_pAdapter
->release();
84 ::osl::MutexGuard
aGuard(m_rMutex
);
85 m_pAdapter
= pAdapter
;
86 m_pAdapter
->acquire();
90 //=====================================================================
91 //= OContainerListenerAdapter
92 //=====================================================================
93 //---------------------------------------------------------------------
94 OContainerListenerAdapter::OContainerListenerAdapter(OContainerListener
* _pListener
,
95 const Reference
< XContainer
>& _rxContainer
)
96 :m_xContainer(_rxContainer
)
97 ,m_pListener(_pListener
)
101 m_pListener
->setAdapter(this);
103 ::comphelper::increment(m_refCount
);
106 m_xContainer
->addContainerListener(this);
108 catch(const Exception
&)
110 OSL_FAIL("Exceptiopn caught!");
112 ::comphelper::decrement(m_refCount
);
115 //---------------------------------------------------------------------
116 OContainerListenerAdapter::~OContainerListenerAdapter()
120 //------------------------------------------------------------------
121 void OContainerListenerAdapter::dispose()
123 if (m_xContainer
.is())
127 Reference
< XContainerListener
> xPreventDelete(this);
128 m_xContainer
->removeContainerListener(xPreventDelete
);
129 m_pListener
->setAdapter(NULL
);
131 catch(const Exception
&)
133 OSL_FAIL("Exception caught!");
140 //------------------------------------------------------------------
141 void SAL_CALL
OContainerListenerAdapter::disposing( const EventObject
& _rSource
) throw(RuntimeException
)
147 m_pListener
->_disposing(_rSource
);
148 // disconnect the listener
150 m_pListener
->setAdapter(NULL
);
157 //------------------------------------------------------------------
158 void SAL_CALL
OContainerListenerAdapter::elementInserted( const ContainerEvent
& _rEvent
) throw(RuntimeException
)
160 if (m_pListener
&& !locked())
161 m_pListener
->_elementInserted(_rEvent
);
164 //------------------------------------------------------------------
165 void SAL_CALL
OContainerListenerAdapter::elementRemoved( const ContainerEvent
& _rEvent
) throw(RuntimeException
)
167 if (m_pListener
&& !locked())
168 m_pListener
->_elementRemoved(_rEvent
);
171 //------------------------------------------------------------------
172 void SAL_CALL
OContainerListenerAdapter::elementReplaced( const ContainerEvent
& _rEvent
) throw(RuntimeException
)
174 if (m_pListener
&& !locked())
175 m_pListener
->_elementReplaced(_rEvent
);
178 //.........................................................................
179 } // namespace comphelper
180 //.........................................................................
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */