bump product version to 6.3.0.0.beta1
[LibreOffice.git] / comphelper / source / property / propmultiplex.cxx
blob5feaa7b5db09536f3bf759c33557cef62f3d12e1
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 <com/sun/star/beans/XPropertySet.hpp>
21 #include <comphelper/propmultiplex.hxx>
22 #include <osl/diagnose.h>
25 namespace comphelper
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::lang;
31 using namespace ::com::sun::star::beans;
33 OPropertyChangeListener::~OPropertyChangeListener()
35 if (m_xAdapter.is())
36 m_xAdapter->dispose();
40 void OPropertyChangeListener::_disposing(const EventObject&)
42 // nothing to do here
46 void OPropertyChangeListener::disposeAdapter()
48 if ( m_xAdapter.is() )
49 m_xAdapter->dispose();
51 // will automatically set a new adapter
52 OSL_ENSURE( !m_xAdapter.is(), "OPropertyChangeListener::disposeAdapter: what did dispose do?" );
56 void OPropertyChangeListener::setAdapter(OPropertyChangeMultiplexer* pAdapter)
58 ::osl::MutexGuard aGuard(m_rMutex);
59 m_xAdapter = pAdapter;
62 OPropertyChangeMultiplexer::OPropertyChangeMultiplexer(OPropertyChangeListener* _pListener, const Reference< XPropertySet>& _rxSet, bool _bAutoReleaseSet)
63 :m_xSet(_rxSet)
64 ,m_pListener(_pListener)
65 ,m_nLockCount(0)
66 ,m_bListening(false)
67 ,m_bAutoSetRelease(_bAutoReleaseSet)
69 m_pListener->setAdapter(this);
73 OPropertyChangeMultiplexer::~OPropertyChangeMultiplexer()
78 void OPropertyChangeMultiplexer::lock()
80 ++m_nLockCount;
84 void OPropertyChangeMultiplexer::unlock()
86 --m_nLockCount;
90 void OPropertyChangeMultiplexer::dispose()
92 if (m_bListening)
94 Reference< XPropertyChangeListener> xPreventDelete(this);
96 for (const OUString& rProp : m_aProperties)
97 m_xSet->removePropertyChangeListener(rProp, static_cast< XPropertyChangeListener*>(this));
99 m_pListener->setAdapter(nullptr);
101 m_pListener = nullptr;
102 m_bListening = false;
104 if (m_bAutoSetRelease)
105 m_xSet = nullptr;
109 // XEventListener
111 void SAL_CALL OPropertyChangeMultiplexer::disposing( const EventObject& _rSource)
113 if (m_pListener)
115 // tell the listener
116 if (!locked())
117 m_pListener->_disposing(_rSource);
118 // disconnect the listener
119 if (m_pListener) // may have been reset whilst calling into _disposing
120 m_pListener->setAdapter(nullptr);
123 m_pListener = nullptr;
124 m_bListening = false;
126 if (m_bAutoSetRelease)
127 m_xSet = nullptr;
130 // XPropertyChangeListener
132 void SAL_CALL OPropertyChangeMultiplexer::propertyChange( const PropertyChangeEvent& _rEvent )
134 if (m_pListener && !locked())
135 m_pListener->_propertyChanged(_rEvent);
139 void OPropertyChangeMultiplexer::addProperty(const OUString& _sPropertyName)
141 if (m_xSet.is())
143 m_xSet->addPropertyChangeListener(_sPropertyName, static_cast< XPropertyChangeListener*>(this));
144 m_aProperties.push_back(_sPropertyName);
145 m_bListening = true;
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */