Line data Source code
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 :
21 : #include "tools/PropertySet.hxx"
22 : #include <algorithm>
23 : #include <o3tl/compat_functional.hxx>
24 :
25 : using namespace ::com::sun::star;
26 : using namespace ::com::sun::star::uno;
27 : using ::rtl::OUString;
28 :
29 : namespace sd { namespace tools {
30 :
31 0 : PropertySet::PropertySet (void)
32 : : PropertySetInterfaceBase(m_aMutex),
33 0 : mpChangeListeners(new ChangeListenerContainer())
34 : {
35 0 : }
36 :
37 :
38 :
39 :
40 0 : PropertySet::~PropertySet (void)
41 : {
42 0 : }
43 :
44 :
45 :
46 :
47 0 : void SAL_CALL PropertySet::disposing (void)
48 : {
49 0 : }
50 :
51 : //----- XPropertySet ----------------------------------------------------------
52 :
53 0 : Reference<beans::XPropertySetInfo> SAL_CALL PropertySet::getPropertySetInfo (void)
54 : throw(RuntimeException)
55 : {
56 0 : return NULL;
57 : }
58 :
59 :
60 :
61 :
62 0 : void SAL_CALL PropertySet::setPropertyValue (
63 : const rtl::OUString& rsPropertyName,
64 : const css::uno::Any& rsPropertyValue)
65 : throw(css::beans::UnknownPropertyException,
66 : css::beans::PropertyVetoException,
67 : css::lang::IllegalArgumentException,
68 : css::lang::WrappedTargetException,
69 : css::uno::RuntimeException)
70 : {
71 0 : ThrowIfDisposed();
72 :
73 0 : Any aOldValue (SetPropertyValue(rsPropertyName,rsPropertyValue));
74 0 : if (aOldValue != rsPropertyValue)
75 : {
76 : // Inform listeners that are registered specifically for the
77 : // property and those registered for any property.
78 : beans::PropertyChangeEvent aEvent(
79 : static_cast<XWeak*>(this),
80 : rsPropertyName,
81 : sal_False,
82 : -1,
83 : aOldValue,
84 0 : rsPropertyValue);
85 0 : CallListeners(rsPropertyName, aEvent);
86 0 : CallListeners(OUString(), aEvent);
87 0 : }
88 0 : }
89 :
90 :
91 :
92 :
93 0 : Any SAL_CALL PropertySet::getPropertyValue (const OUString& rsPropertyName)
94 : throw(css::beans::UnknownPropertyException,
95 : css::lang::WrappedTargetException,
96 : css::uno::RuntimeException)
97 : {
98 0 : ThrowIfDisposed();
99 :
100 0 : return GetPropertyValue(rsPropertyName);
101 : }
102 :
103 :
104 :
105 :
106 0 : void SAL_CALL PropertySet::addPropertyChangeListener (
107 : const rtl::OUString& rsPropertyName,
108 : const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
109 : throw(css::beans::UnknownPropertyException,
110 : css::lang::WrappedTargetException,
111 : css::uno::RuntimeException)
112 : {
113 0 : if ( ! rxListener.is())
114 0 : throw lang::IllegalArgumentException();
115 :
116 0 : if (rBHelper.bDisposed || rBHelper.bInDispose)
117 0 : return;
118 :
119 : mpChangeListeners->insert(
120 : ChangeListenerContainer::value_type(
121 : rsPropertyName,
122 0 : rxListener));
123 : }
124 :
125 :
126 :
127 :
128 0 : void SAL_CALL PropertySet::removePropertyChangeListener (
129 : const rtl::OUString& rsPropertyName,
130 : const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
131 : throw(beans::UnknownPropertyException,
132 : css::lang::WrappedTargetException,
133 : css::uno::RuntimeException)
134 : {
135 : ::std::pair<ChangeListenerContainer::iterator,ChangeListenerContainer::iterator>
136 0 : aRange (mpChangeListeners->equal_range(rsPropertyName));
137 :
138 : ChangeListenerContainer::iterator iListener (
139 : ::std::find_if(
140 : aRange.first,
141 : aRange.second,
142 : o3tl::compose1(
143 : std::bind1st(std::equal_to<Reference<beans::XPropertyChangeListener> >(),
144 : rxListener),
145 0 : o3tl::select2nd<ChangeListenerContainer::value_type>())));
146 0 : if (iListener != mpChangeListeners->end())
147 : {
148 0 : mpChangeListeners->erase(iListener);
149 : }
150 : else
151 : {
152 0 : throw lang::IllegalArgumentException();
153 : }
154 0 : }
155 :
156 :
157 :
158 :
159 0 : void SAL_CALL PropertySet::addVetoableChangeListener (
160 : const rtl::OUString& rsPropertyName,
161 : const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener)
162 : throw(css::beans::UnknownPropertyException,
163 : css::lang::WrappedTargetException,
164 : css::uno::RuntimeException)
165 : {
166 : // Constraint properties are not supported and thus no vetoable
167 : // listeners.
168 : (void)rsPropertyName;
169 : (void)rxListener;
170 0 : }
171 :
172 :
173 :
174 :
175 0 : void SAL_CALL PropertySet::removeVetoableChangeListener (
176 : const rtl::OUString& rsPropertyName,
177 : const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener)
178 : throw(css::beans::UnknownPropertyException,
179 : css::lang::WrappedTargetException,
180 : css::uno::RuntimeException)
181 : {
182 : // Constraint properties are not supported and thus no vetoable
183 : // listeners.
184 : (void)rsPropertyName;
185 : (void)rxListener;
186 0 : }
187 :
188 :
189 :
190 :
191 : //-----------------------------------------------------------------------------
192 :
193 0 : void PropertySet::CallListeners (
194 : const rtl::OUString& rsPropertyName,
195 : const beans::PropertyChangeEvent& rEvent)
196 : {
197 : ::std::pair<ChangeListenerContainer::iterator,ChangeListenerContainer::iterator>
198 0 : aRange (mpChangeListeners->equal_range(rsPropertyName));
199 0 : ChangeListenerContainer::const_iterator iListener;
200 0 : for (iListener=aRange.first; iListener!=aRange.second; ++iListener)
201 : {
202 0 : if (iListener->second.is())
203 0 : iListener->second->propertyChange(rEvent);
204 : }
205 0 : }
206 :
207 :
208 :
209 :
210 0 : void PropertySet::ThrowIfDisposed (void)
211 : throw (::com::sun::star::lang::DisposedException)
212 : {
213 0 : if (rBHelper.bDisposed || rBHelper.bInDispose)
214 : {
215 : throw lang::DisposedException (
216 : "PropertySet object has already been disposed",
217 0 : static_cast<uno::XWeak*>(this));
218 : }
219 0 : }
220 :
221 : } } // end of namespace ::sd::tools
222 :
223 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|