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/propmultiplex.hxx>
21 #include <osl/diagnose.h>
28 using namespace ::com::sun::star::uno
;
29 using namespace ::com::sun::star::lang
;
30 using namespace ::com::sun::star::beans
;
32 OPropertyChangeListener::~OPropertyChangeListener()
35 m_pAdapter
->dispose();
39 void OPropertyChangeListener::_disposing(const EventObject
&)
40 throw (RuntimeException
, std::exception
)
46 void OPropertyChangeListener::disposeAdapter()
49 m_pAdapter
->dispose();
51 // will automatically set a new adapter
52 OSL_ENSURE( !m_pAdapter
, "OPropertyChangeListener::disposeAdapter: what did dispose do?" );
56 void OPropertyChangeListener::setAdapter(OPropertyChangeMultiplexer
* pAdapter
)
60 ::osl::MutexGuard
aGuard(m_rMutex
);
61 m_pAdapter
->release();
67 ::osl::MutexGuard
aGuard(m_rMutex
);
68 m_pAdapter
= pAdapter
;
69 m_pAdapter
->acquire();
73 OPropertyChangeMultiplexer::OPropertyChangeMultiplexer(OPropertyChangeListener
* _pListener
, const Reference
< XPropertySet
>& _rxSet
, bool _bAutoReleaseSet
)
75 ,m_pListener(_pListener
)
78 ,m_bAutoSetRelease(_bAutoReleaseSet
)
80 m_pListener
->setAdapter(this);
84 OPropertyChangeMultiplexer::~OPropertyChangeMultiplexer()
89 void OPropertyChangeMultiplexer::lock()
95 void OPropertyChangeMultiplexer::unlock()
101 void OPropertyChangeMultiplexer::dispose()
105 Reference
< XPropertyChangeListener
> xPreventDelete(this);
107 const OUString
* pProperties
= m_aProperties
.getConstArray();
108 for (sal_Int32 i
= 0; i
< m_aProperties
.getLength(); ++i
, ++pProperties
)
109 m_xSet
->removePropertyChangeListener(*pProperties
, static_cast< XPropertyChangeListener
*>(this));
111 m_pListener
->setAdapter(NULL
);
114 m_bListening
= false;
116 if (m_bAutoSetRelease
)
123 void SAL_CALL
OPropertyChangeMultiplexer::disposing( const EventObject
& _rSource
) throw( RuntimeException
, std::exception
)
129 m_pListener
->_disposing(_rSource
);
130 // disconnect the listener
131 if (m_pListener
) // may have been reset whilest calling into _disposing
132 m_pListener
->setAdapter(NULL
);
136 m_bListening
= false;
138 if (m_bAutoSetRelease
)
142 // XPropertyChangeListener
144 void SAL_CALL
OPropertyChangeMultiplexer::propertyChange( const PropertyChangeEvent
& _rEvent
) throw( RuntimeException
, std::exception
)
146 if (m_pListener
&& !locked())
147 m_pListener
->_propertyChanged(_rEvent
);
151 void OPropertyChangeMultiplexer::addProperty(const OUString
& _sPropertyName
)
155 m_xSet
->addPropertyChangeListener(_sPropertyName
, static_cast< XPropertyChangeListener
*>(this));
156 m_aProperties
.realloc(m_aProperties
.getLength() + 1);
157 m_aProperties
.getArray()[m_aProperties
.getLength()-1] = _sPropertyName
;
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */