Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / comphelper / source / container / containermultiplexer.cxx
blobc687e72793ad026c52a621d4c87baeba0ef6ad6e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <com/sun/star/container/XContainer.hpp>
22 #include <osl/diagnose.h>
24 namespace comphelper
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::lang;
30 using namespace ::com::sun::star::container;
32 OContainerListener::OContainerListener(::osl::Mutex& _rMutex)
33 :m_rMutex(_rMutex)
38 OContainerListener::~OContainerListener()
40 if (m_xAdapter.is())
42 m_xAdapter->dispose();
47 void OContainerListener::_elementInserted( const ContainerEvent& /*_rEvent*/ )
52 void OContainerListener::_elementRemoved( const ContainerEvent& )
57 void OContainerListener::_elementReplaced( const ContainerEvent& /*_rEvent*/ )
62 void OContainerListener::_disposing(const EventObject& )
67 void OContainerListener::setAdapter(OContainerListenerAdapter* pAdapter)
69 ::osl::MutexGuard aGuard(m_rMutex);
70 m_xAdapter = pAdapter;
73 OContainerListenerAdapter::OContainerListenerAdapter(OContainerListener* _pListener,
74 const Reference< XContainer >& _rxContainer)
75 :m_xContainer(_rxContainer)
76 ,m_pListener(_pListener)
78 if (m_pListener)
79 m_pListener->setAdapter(this);
81 osl_atomic_increment(&m_refCount);
82 try
84 m_xContainer->addContainerListener(this);
86 catch(const Exception&)
88 OSL_FAIL("Exception caught!");
90 osl_atomic_decrement(&m_refCount);
94 OContainerListenerAdapter::~OContainerListenerAdapter()
99 void OContainerListenerAdapter::dispose()
101 if (!m_xContainer.is())
102 return;
106 Reference< XContainerListener > xPreventDelete(this);
107 m_xContainer->removeContainerListener(xPreventDelete);
108 m_pListener->setAdapter(nullptr);
110 catch(const Exception&)
112 OSL_FAIL("Exception caught!");
114 m_xContainer = nullptr;
115 m_pListener = nullptr;
119 void SAL_CALL OContainerListenerAdapter::disposing( const EventObject& _rSource)
121 if (m_pListener)
123 // tell the listener
124 m_pListener->_disposing(_rSource);
125 // disconnect the listener
126 if ( m_pListener )
127 m_pListener->setAdapter(nullptr);
130 m_xContainer = nullptr;
131 m_pListener = nullptr;
135 void SAL_CALL OContainerListenerAdapter::elementInserted( const ContainerEvent& _rEvent )
137 if (m_pListener)
138 m_pListener->_elementInserted(_rEvent);
142 void SAL_CALL OContainerListenerAdapter::elementRemoved( const ContainerEvent& _rEvent )
144 if (m_pListener)
145 m_pListener->_elementRemoved(_rEvent);
149 void SAL_CALL OContainerListenerAdapter::elementReplaced( const ContainerEvent& _rEvent )
151 if (m_pListener)
152 m_pListener->_elementReplaced(_rEvent);
156 } // namespace comphelper
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */