android: Update app-specific/MIME type icons
[LibreOffice.git] / comphelper / source / property / propmultiplex2.cxx
blob16c06c3bc1f979039c9966d67c4ed36f6e757b39
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/propmultiplex2.hxx>
22 #include <osl/diagnose.h>
24 namespace comphelper
26 using namespace ::com::sun::star::uno;
27 using namespace ::com::sun::star::lang;
28 using namespace ::com::sun::star::beans;
30 OPropertyChangeListener2::~OPropertyChangeListener2()
32 if (m_xAdapter.is())
33 m_xAdapter->onListenerDestruction();
36 void OPropertyChangeListener2::disposeAdapter(std::unique_lock<std::mutex>& rGuard)
38 if (m_xAdapter.is())
39 m_xAdapter->dispose(rGuard);
41 // will automatically set a new adapter
42 OSL_ENSURE(!m_xAdapter.is(), "OPropertyChangeListener::disposeAdapter: what did dispose do?");
45 void OPropertyChangeListener2::setAdapter(std::unique_lock<std::mutex>& /*rGuard*/,
46 OPropertyChangeMultiplexer2* pAdapter)
48 m_xAdapter = pAdapter;
51 OPropertyChangeMultiplexer2::OPropertyChangeMultiplexer2(std::mutex& rMutex,
52 std::unique_lock<std::mutex>& rGuard,
53 OPropertyChangeListener2* _pListener,
54 const Reference<XPropertySet>& _rxSet,
55 bool _bAutoReleaseSet)
56 : m_rMutex(rMutex)
57 , m_xSet(_rxSet)
58 , m_pListener(_pListener)
59 , m_nLockCount(0)
60 , m_bListening(false)
61 , m_bAutoSetRelease(_bAutoReleaseSet)
63 m_pListener->setAdapter(rGuard, this);
66 OPropertyChangeMultiplexer2::~OPropertyChangeMultiplexer2() {}
68 void OPropertyChangeMultiplexer2::lock() { ++m_nLockCount; }
70 void OPropertyChangeMultiplexer2::unlock() { --m_nLockCount; }
72 void OPropertyChangeMultiplexer2::dispose(std::unique_lock<std::mutex>& rGuard)
74 if (!m_bListening)
75 return;
77 Reference<XPropertyChangeListener> xPreventDelete(this);
79 for (const OUString& rProp : m_aProperties)
80 m_xSet->removePropertyChangeListener(rProp, static_cast<XPropertyChangeListener*>(this));
82 m_pListener->setAdapter(rGuard, nullptr);
84 m_pListener = nullptr;
85 m_bListening = false;
87 if (m_bAutoSetRelease)
88 m_xSet = nullptr;
91 void OPropertyChangeMultiplexer2::onListenerDestruction()
93 if (!m_bListening)
94 return;
96 Reference<XPropertyChangeListener> xPreventDelete(this);
98 for (const OUString& rProp : m_aProperties)
99 m_xSet->removePropertyChangeListener(rProp, static_cast<XPropertyChangeListener*>(this));
102 // XEventListener
104 void SAL_CALL OPropertyChangeMultiplexer2::disposing(const EventObject& /*_rSource*/)
106 std::unique_lock g(m_rMutex);
107 if (m_pListener)
109 // disconnect the listener
110 if (m_pListener) // may have been reset whilst calling into _disposing
111 m_pListener->setAdapter(g, nullptr);
114 m_pListener = nullptr;
115 m_bListening = false;
117 if (m_bAutoSetRelease)
118 m_xSet = nullptr;
121 // XPropertyChangeListener
123 void SAL_CALL OPropertyChangeMultiplexer2::propertyChange(const PropertyChangeEvent& _rEvent)
125 if (m_pListener && !locked())
126 m_pListener->_propertyChanged(_rEvent);
129 void OPropertyChangeMultiplexer2::addProperty(const OUString& _sPropertyName)
131 if (m_xSet.is())
133 m_xSet->addPropertyChangeListener(_sPropertyName,
134 static_cast<XPropertyChangeListener*>(this));
135 m_aProperties.push_back(_sPropertyName);
136 m_bListening = true;
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */