LibreOffice Module comphelper (master) 1
propmultiplex.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <com/sun/star/beans/XPropertySet.hpp>
22#include <osl/diagnose.h>
23
24
25namespace comphelper
26{
27
28
29using namespace ::com::sun::star::uno;
30using namespace ::com::sun::star::lang;
31using namespace ::com::sun::star::beans;
32
34{
35 if (m_xAdapter.is())
36 m_xAdapter->dispose();
37}
38
39
41{
42 // nothing to do here
43}
44
45
47{
48 if ( m_xAdapter.is() )
49 m_xAdapter->dispose();
50
51 // will automatically set a new adapter
52 OSL_ENSURE( !m_xAdapter.is(), "OPropertyChangeListener::disposeAdapter: what did dispose do?" );
53}
54
55
57{
58 ::osl::MutexGuard aGuard(m_rMutex);
59 m_xAdapter = pAdapter;
60}
61
62OPropertyChangeMultiplexer::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)
68{
70}
71
72
74{
75}
76
77
79{
81}
82
83
85{
87}
88
89
91{
92 if (!m_bListening)
93 return;
94
95 Reference< XPropertyChangeListener> xPreventDelete(this);
96
97 for (const OUString& rProp : m_aProperties)
98 m_xSet->removePropertyChangeListener(rProp, static_cast< XPropertyChangeListener*>(this));
99
100 m_pListener->setAdapter(nullptr);
101
102 m_pListener = nullptr;
103 m_bListening = false;
104
106 m_xSet = nullptr;
107}
108
109// XEventListener
110
111void SAL_CALL OPropertyChangeMultiplexer::disposing( const EventObject& _rSource)
112{
113 if (m_pListener)
114 {
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);
121 }
122
123 m_pListener = nullptr;
124 m_bListening = false;
125
127 m_xSet = nullptr;
128}
129
130// XPropertyChangeListener
131
132void SAL_CALL OPropertyChangeMultiplexer::propertyChange( const PropertyChangeEvent& _rEvent )
133{
134 if (m_pListener && !locked())
136}
137
138
139void OPropertyChangeMultiplexer::addProperty(const OUString& _sPropertyName)
140{
141 if (m_xSet.is())
142 {
143 m_xSet->addPropertyChangeListener(_sPropertyName, static_cast< XPropertyChangeListener*>(this));
144 m_aProperties.push_back(_sPropertyName);
145 m_bListening = true;
146 }
147}
148
149
150}
151
152
153/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::rtl::Reference< comphelper::OPropertyChangeMultiplexer > m_pListener
simple listener adapter for property sets
rtl::Reference< OPropertyChangeMultiplexer > m_xAdapter
void setAdapter(OPropertyChangeMultiplexer *_pAdapter)
virtual void _propertyChanged(const css::beans::PropertyChangeEvent &_rEvent)=0
void disposeAdapter()
If the derivee also owns the mutex which we know as reference, then call this within your derivee's d...
virtual void _disposing(const css::lang::EventObject &_rSource)
virtual ~OPropertyChangeMultiplexer() override
OPropertyChangeMultiplexer(OPropertyChangeListener *_pListener, const css::uno::Reference< css::beans::XPropertySet > &_rxSet, bool _bAutoReleaseSet=true)
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent &evt) override
sal_Int32 locked() const
get the lock count
std::vector< OUString > m_aProperties
OPropertyChangeListener * m_pListener
void addProperty(const OUString &aPropertyName)
css::uno::Reference< css::beans::XPropertySet > m_xSet