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 <com/sun/star/beans/XPropertySet.hpp>
21 #include <comphelper/propmultiplex.hxx>
22 #include <osl/diagnose.h>
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::lang
;
31 using namespace ::com::sun::star::beans
;
33 OPropertyChangeListener::~OPropertyChangeListener()
36 m_xAdapter
->dispose();
40 void OPropertyChangeListener::_disposing(const EventObject
&)
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
)
64 ,m_pListener(_pListener
)
67 ,m_bAutoSetRelease(_bAutoReleaseSet
)
69 m_pListener
->setAdapter(this);
73 OPropertyChangeMultiplexer::~OPropertyChangeMultiplexer()
78 void OPropertyChangeMultiplexer::lock()
84 void OPropertyChangeMultiplexer::unlock()
90 void OPropertyChangeMultiplexer::dispose()
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
)
111 void SAL_CALL
OPropertyChangeMultiplexer::disposing( const EventObject
& _rSource
)
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
)
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
)
143 m_xSet
->addPropertyChangeListener(_sPropertyName
, static_cast< XPropertyChangeListener
*>(this));
144 m_aProperties
.push_back(_sPropertyName
);
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */