Update ooo320-m1
[ooovba.git] / sd / source / ui / tools / PropertySet.cxx
blobb64db781ca9cc1d57b730dfd6b69683711d4a297
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PropertySet.cxx,v $
11 * $Revision: 1.3 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "precompiled_sd.hxx"
34 #include "tools/PropertySet.hxx"
35 #include <boost/bind.hpp>
36 #include <algorithm>
37 #include <functional>
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::uno;
41 using ::rtl::OUString;
43 namespace sd { namespace tools {
45 PropertySet::PropertySet (void)
46 : PropertySetInterfaceBase(m_aMutex),
47 mpChangeListeners(new ChangeListenerContainer())
54 PropertySet::~PropertySet (void)
61 void SAL_CALL PropertySet::disposing (void)
68 beans::UnknownPropertyException PropertySet::CreateUnknownPropertyException (
69 const rtl::OUString& rsPropertyName)
71 return beans::UnknownPropertyException(
72 OUString::createFromAscii("property ")
73 + rsPropertyName
74 + OUString::createFromAscii(" is not known"),
75 static_cast<XWeak*>(this));
81 //----- XPropertySet ----------------------------------------------------------
83 Reference<beans::XPropertySetInfo> SAL_CALL PropertySet::getPropertySetInfo (void)
84 throw(RuntimeException)
86 return NULL;
92 void SAL_CALL PropertySet::setPropertyValue (
93 const rtl::OUString& rsPropertyName,
94 const css::uno::Any& rsPropertyValue)
95 throw(css::beans::UnknownPropertyException,
96 css::beans::PropertyVetoException,
97 css::lang::IllegalArgumentException,
98 css::lang::WrappedTargetException,
99 css::uno::RuntimeException)
101 ThrowIfDisposed();
103 Any aOldValue (SetPropertyValue(rsPropertyName,rsPropertyValue));
104 if (aOldValue != rsPropertyValue)
106 // Inform listeners that are registered specifically for the
107 // property and those registered for any property.
108 beans::PropertyChangeEvent aEvent(
109 static_cast<XWeak*>(this),
110 rsPropertyName,
111 sal_False,
113 aOldValue,
114 rsPropertyValue);
115 CallListeners(rsPropertyName, aEvent);
116 CallListeners(OUString(), aEvent);
123 Any SAL_CALL PropertySet::getPropertyValue (const OUString& rsPropertyName)
124 throw(css::beans::UnknownPropertyException,
125 css::lang::WrappedTargetException,
126 css::uno::RuntimeException)
128 ThrowIfDisposed();
130 return GetPropertyValue(rsPropertyName);
136 void SAL_CALL PropertySet::addPropertyChangeListener (
137 const rtl::OUString& rsPropertyName,
138 const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
139 throw(css::beans::UnknownPropertyException,
140 css::lang::WrappedTargetException,
141 css::uno::RuntimeException)
143 if ( ! rxListener.is())
144 throw lang::IllegalArgumentException();
146 if (rBHelper.bDisposed || rBHelper.bInDispose)
147 return;
149 mpChangeListeners->insert(
150 ChangeListenerContainer::value_type(
151 rsPropertyName,
152 rxListener));
158 void SAL_CALL PropertySet::removePropertyChangeListener (
159 const rtl::OUString& rsPropertyName,
160 const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
161 throw(beans::UnknownPropertyException,
162 css::lang::WrappedTargetException,
163 css::uno::RuntimeException)
165 ::std::pair<ChangeListenerContainer::iterator,ChangeListenerContainer::iterator>
166 aRange (mpChangeListeners->equal_range(rsPropertyName));
168 ChangeListenerContainer::iterator iListener (
169 ::std::find_if(
170 aRange.first,
171 aRange.second,
172 std::compose1(
173 std::bind1st(std::equal_to<Reference<beans::XPropertyChangeListener> >(),
174 rxListener),
175 std::select2nd<ChangeListenerContainer::value_type>())));
176 if (iListener != mpChangeListeners->end())
178 mpChangeListeners->erase(iListener);
180 else
182 throw lang::IllegalArgumentException();
189 void SAL_CALL PropertySet::addVetoableChangeListener (
190 const rtl::OUString& rsPropertyName,
191 const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener)
192 throw(css::beans::UnknownPropertyException,
193 css::lang::WrappedTargetException,
194 css::uno::RuntimeException)
196 // Constraint properties are not supported and thus no vetoable
197 // listeners.
198 (void)rsPropertyName;
199 (void)rxListener;
205 void SAL_CALL PropertySet::removeVetoableChangeListener (
206 const rtl::OUString& rsPropertyName,
207 const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener)
208 throw(css::beans::UnknownPropertyException,
209 css::lang::WrappedTargetException,
210 css::uno::RuntimeException)
212 // Constraint properties are not supported and thus no vetoable
213 // listeners.
214 (void)rsPropertyName;
215 (void)rxListener;
221 //-----------------------------------------------------------------------------
223 void PropertySet::CallListeners (
224 const rtl::OUString& rsPropertyName,
225 const beans::PropertyChangeEvent& rEvent)
227 ::std::pair<ChangeListenerContainer::iterator,ChangeListenerContainer::iterator>
228 aRange (mpChangeListeners->equal_range(rsPropertyName));
229 ChangeListenerContainer::const_iterator iListener;
230 for (iListener=aRange.first; iListener!=aRange.second; ++iListener)
232 if (iListener->second.is())
233 iListener->second->propertyChange(rEvent);
240 void PropertySet::ThrowIfDisposed (void)
241 throw (::com::sun::star::lang::DisposedException)
243 if (rBHelper.bDisposed || rBHelper.bInDispose)
245 throw lang::DisposedException (
246 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
247 "PropertySet object has already been disposed")),
248 static_cast<uno::XWeak*>(this));
252 } } // end of namespace ::sd::tools