bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / tools / PropertySet.cxx
blob980c15bf5b276b5c9502e7f0a277965fe0093f88
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 <tools/PropertySet.hxx>
21 #include <algorithm>
23 using namespace ::com::sun::star;
24 using namespace ::com::sun::star::uno;
26 namespace sd { namespace tools {
28 PropertySet::PropertySet()
29 : PropertySetInterfaceBase(m_aMutex),
30 mpChangeListeners(new ChangeListenerContainer)
34 PropertySet::~PropertySet()
38 void SAL_CALL PropertySet::disposing()
42 //----- XPropertySet ----------------------------------------------------------
44 Reference<beans::XPropertySetInfo> SAL_CALL PropertySet::getPropertySetInfo()
46 return nullptr;
49 void SAL_CALL PropertySet::setPropertyValue (
50 const OUString& rsPropertyName,
51 const css::uno::Any& rsPropertyValue)
53 ThrowIfDisposed();
55 Any aOldValue (SetPropertyValue(rsPropertyName,rsPropertyValue));
56 if (aOldValue == rsPropertyValue)
57 return;
59 // Inform listeners that are registered specifically for the
60 // property and those registered for any property.
61 beans::PropertyChangeEvent aEvent(
62 static_cast<XWeak*>(this),
63 rsPropertyName,
64 false,
65 -1,
66 aOldValue,
67 rsPropertyValue);
68 CallListeners(rsPropertyName, aEvent);
69 CallListeners(OUString(), aEvent);
72 Any SAL_CALL PropertySet::getPropertyValue (const OUString& rsPropertyName)
74 ThrowIfDisposed();
76 return GetPropertyValue(rsPropertyName);
79 void SAL_CALL PropertySet::addPropertyChangeListener (
80 const OUString& rsPropertyName,
81 const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
83 if ( ! rxListener.is())
84 throw lang::IllegalArgumentException();
86 if (rBHelper.bDisposed || rBHelper.bInDispose)
87 return;
89 mpChangeListeners->emplace(rsPropertyName, rxListener);
92 void SAL_CALL PropertySet::removePropertyChangeListener (
93 const OUString& rsPropertyName,
94 const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
96 ::std::pair<ChangeListenerContainer::iterator,ChangeListenerContainer::iterator>
97 aRange (mpChangeListeners->equal_range(rsPropertyName));
99 ChangeListenerContainer::iterator iListener (
100 ::std::find_if(
101 aRange.first,
102 aRange.second,
103 [&rxListener] (const ChangeListenerContainer::value_type& listener) {
104 return listener.second == rxListener;
105 }));
107 if (iListener == mpChangeListeners->end())
109 throw lang::IllegalArgumentException();
112 mpChangeListeners->erase(iListener);
116 void SAL_CALL PropertySet::addVetoableChangeListener (
117 const OUString&,
118 const css::uno::Reference<css::beans::XVetoableChangeListener>&)
120 // Constraint properties are not supported and thus no vetoable
121 // listeners.
124 void SAL_CALL PropertySet::removeVetoableChangeListener (
125 const OUString&,
126 const css::uno::Reference<css::beans::XVetoableChangeListener>&)
128 // Constraint properties are not supported and thus no vetoable
129 // listeners.
132 void PropertySet::CallListeners (
133 const OUString& rsPropertyName,
134 const beans::PropertyChangeEvent& rEvent)
136 ::std::pair<ChangeListenerContainer::iterator,ChangeListenerContainer::iterator>
137 aRange (mpChangeListeners->equal_range(rsPropertyName));
138 ChangeListenerContainer::const_iterator iListener;
139 for (iListener=aRange.first; iListener!=aRange.second; ++iListener)
141 if (iListener->second.is())
142 iListener->second->propertyChange(rEvent);
146 void PropertySet::ThrowIfDisposed()
148 if (rBHelper.bDisposed || rBHelper.bInDispose)
150 throw lang::DisposedException (
151 "PropertySet object has already been disposed",
152 static_cast<uno::XWeak*>(this));
156 } } // end of namespace ::sd::tools
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */