xref: /aoo42x/main/sd/source/ui/tools/PropertySet.cxx (revision 79aad27f)
1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5b190011SAndrew Rist  * distributed with this work for additional information
6*5b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist  * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5b190011SAndrew Rist  *
11*5b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5b190011SAndrew Rist  *
13*5b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist  * software distributed under the License is distributed on an
15*5b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5b190011SAndrew Rist  * specific language governing permissions and limitations
18*5b190011SAndrew Rist  * under the License.
19*5b190011SAndrew Rist  *
20*5b190011SAndrew Rist  *************************************************************/
21*5b190011SAndrew Rist 
22*5b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_sd.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "tools/PropertySet.hxx"
27cdf0e10cSrcweir #include <boost/bind.hpp>
28cdf0e10cSrcweir #include <algorithm>
29cdf0e10cSrcweir #include <functional>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir using namespace ::com::sun::star;
32cdf0e10cSrcweir using namespace ::com::sun::star::uno;
33cdf0e10cSrcweir using ::rtl::OUString;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir namespace sd { namespace tools {
36cdf0e10cSrcweir 
PropertySet(void)37cdf0e10cSrcweir PropertySet::PropertySet (void)
38cdf0e10cSrcweir     : PropertySetInterfaceBase(m_aMutex),
39cdf0e10cSrcweir       mpChangeListeners(new ChangeListenerContainer())
40cdf0e10cSrcweir {
41cdf0e10cSrcweir }
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 
~PropertySet(void)46cdf0e10cSrcweir PropertySet::~PropertySet (void)
47cdf0e10cSrcweir {
48cdf0e10cSrcweir }
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 
disposing(void)53cdf0e10cSrcweir void SAL_CALL PropertySet::disposing (void)
54cdf0e10cSrcweir {
55cdf0e10cSrcweir }
56cdf0e10cSrcweir 
57cdf0e10cSrcweir //----- XPropertySet ----------------------------------------------------------
58cdf0e10cSrcweir 
getPropertySetInfo(void)59cdf0e10cSrcweir Reference<beans::XPropertySetInfo> SAL_CALL PropertySet::getPropertySetInfo (void)
60cdf0e10cSrcweir     throw(RuntimeException)
61cdf0e10cSrcweir {
62cdf0e10cSrcweir     return NULL;
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 
setPropertyValue(const rtl::OUString & rsPropertyName,const css::uno::Any & rsPropertyValue)68cdf0e10cSrcweir void SAL_CALL PropertySet::setPropertyValue (
69cdf0e10cSrcweir     const rtl::OUString& rsPropertyName,
70cdf0e10cSrcweir     const css::uno::Any& rsPropertyValue)
71cdf0e10cSrcweir     throw(css::beans::UnknownPropertyException,
72cdf0e10cSrcweir         css::beans::PropertyVetoException,
73cdf0e10cSrcweir         css::lang::IllegalArgumentException,
74cdf0e10cSrcweir         css::lang::WrappedTargetException,
75cdf0e10cSrcweir         css::uno::RuntimeException)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir     ThrowIfDisposed();
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     Any aOldValue (SetPropertyValue(rsPropertyName,rsPropertyValue));
80cdf0e10cSrcweir     if (aOldValue != rsPropertyValue)
81cdf0e10cSrcweir     {
82cdf0e10cSrcweir         // Inform listeners that are registered specifically for the
83cdf0e10cSrcweir         // property and those registered for any property.
84cdf0e10cSrcweir         beans::PropertyChangeEvent aEvent(
85cdf0e10cSrcweir             static_cast<XWeak*>(this),
86cdf0e10cSrcweir             rsPropertyName,
87cdf0e10cSrcweir             sal_False,
88cdf0e10cSrcweir             -1,
89cdf0e10cSrcweir             aOldValue,
90cdf0e10cSrcweir             rsPropertyValue);
91cdf0e10cSrcweir         CallListeners(rsPropertyName, aEvent);
92cdf0e10cSrcweir         CallListeners(OUString(), aEvent);
93cdf0e10cSrcweir     }
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 
getPropertyValue(const OUString & rsPropertyName)99cdf0e10cSrcweir Any SAL_CALL PropertySet::getPropertyValue (const OUString& rsPropertyName)
100cdf0e10cSrcweir         throw(css::beans::UnknownPropertyException,
101cdf0e10cSrcweir             css::lang::WrappedTargetException,
102cdf0e10cSrcweir             css::uno::RuntimeException)
103cdf0e10cSrcweir {
104cdf0e10cSrcweir     ThrowIfDisposed();
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     return GetPropertyValue(rsPropertyName);
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 
addPropertyChangeListener(const rtl::OUString & rsPropertyName,const css::uno::Reference<css::beans::XPropertyChangeListener> & rxListener)112cdf0e10cSrcweir void SAL_CALL PropertySet::addPropertyChangeListener (
113cdf0e10cSrcweir     const rtl::OUString& rsPropertyName,
114cdf0e10cSrcweir     const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
115cdf0e10cSrcweir     throw(css::beans::UnknownPropertyException,
116cdf0e10cSrcweir         css::lang::WrappedTargetException,
117cdf0e10cSrcweir         css::uno::RuntimeException)
118cdf0e10cSrcweir {
119cdf0e10cSrcweir     if ( ! rxListener.is())
120cdf0e10cSrcweir         throw lang::IllegalArgumentException();
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     if (rBHelper.bDisposed || rBHelper.bInDispose)
123cdf0e10cSrcweir         return;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     mpChangeListeners->insert(
126cdf0e10cSrcweir         ChangeListenerContainer::value_type(
127cdf0e10cSrcweir             rsPropertyName,
128cdf0e10cSrcweir             rxListener));
129cdf0e10cSrcweir }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 
removePropertyChangeListener(const rtl::OUString & rsPropertyName,const css::uno::Reference<css::beans::XPropertyChangeListener> & rxListener)134cdf0e10cSrcweir void SAL_CALL PropertySet::removePropertyChangeListener (
135cdf0e10cSrcweir     const rtl::OUString& rsPropertyName,
136cdf0e10cSrcweir     const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
137cdf0e10cSrcweir     throw(beans::UnknownPropertyException,
138cdf0e10cSrcweir         css::lang::WrappedTargetException,
139cdf0e10cSrcweir         css::uno::RuntimeException)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir     ::std::pair<ChangeListenerContainer::iterator,ChangeListenerContainer::iterator>
142cdf0e10cSrcweir         aRange (mpChangeListeners->equal_range(rsPropertyName));
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     ChangeListenerContainer::iterator iListener (
145cdf0e10cSrcweir         ::std::find_if(
146cdf0e10cSrcweir             aRange.first,
147cdf0e10cSrcweir             aRange.second,
148cdf0e10cSrcweir             std::compose1(
149cdf0e10cSrcweir                 std::bind1st(std::equal_to<Reference<beans::XPropertyChangeListener> >(),
150cdf0e10cSrcweir                     rxListener),
151cdf0e10cSrcweir                 std::select2nd<ChangeListenerContainer::value_type>())));
152cdf0e10cSrcweir     if (iListener != mpChangeListeners->end())
153cdf0e10cSrcweir     {
154cdf0e10cSrcweir         mpChangeListeners->erase(iListener);
155cdf0e10cSrcweir     }
156cdf0e10cSrcweir     else
157cdf0e10cSrcweir     {
158cdf0e10cSrcweir         throw lang::IllegalArgumentException();
159cdf0e10cSrcweir     }
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 
addVetoableChangeListener(const rtl::OUString & rsPropertyName,const css::uno::Reference<css::beans::XVetoableChangeListener> & rxListener)165cdf0e10cSrcweir void SAL_CALL PropertySet::addVetoableChangeListener (
166cdf0e10cSrcweir     const rtl::OUString& rsPropertyName,
167cdf0e10cSrcweir     const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener)
168cdf0e10cSrcweir     throw(css::beans::UnknownPropertyException,
169cdf0e10cSrcweir         css::lang::WrappedTargetException,
170cdf0e10cSrcweir         css::uno::RuntimeException)
171cdf0e10cSrcweir {
172cdf0e10cSrcweir     // Constraint properties are not supported and thus no vetoable
173cdf0e10cSrcweir     // listeners.
174cdf0e10cSrcweir     (void)rsPropertyName;
175cdf0e10cSrcweir     (void)rxListener;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 
removeVetoableChangeListener(const rtl::OUString & rsPropertyName,const css::uno::Reference<css::beans::XVetoableChangeListener> & rxListener)181cdf0e10cSrcweir void SAL_CALL PropertySet::removeVetoableChangeListener (
182cdf0e10cSrcweir     const rtl::OUString& rsPropertyName,
183cdf0e10cSrcweir     const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener)
184cdf0e10cSrcweir     throw(css::beans::UnknownPropertyException,
185cdf0e10cSrcweir         css::lang::WrappedTargetException,
186cdf0e10cSrcweir         css::uno::RuntimeException)
187cdf0e10cSrcweir {
188cdf0e10cSrcweir     // Constraint properties are not supported and thus no vetoable
189cdf0e10cSrcweir     // listeners.
190cdf0e10cSrcweir     (void)rsPropertyName;
191cdf0e10cSrcweir     (void)rxListener;
192cdf0e10cSrcweir }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 
197cdf0e10cSrcweir //-----------------------------------------------------------------------------
198cdf0e10cSrcweir 
CallListeners(const rtl::OUString & rsPropertyName,const beans::PropertyChangeEvent & rEvent)199cdf0e10cSrcweir void PropertySet::CallListeners (
200cdf0e10cSrcweir     const rtl::OUString& rsPropertyName,
201cdf0e10cSrcweir     const beans::PropertyChangeEvent& rEvent)
202cdf0e10cSrcweir {
203cdf0e10cSrcweir     ::std::pair<ChangeListenerContainer::iterator,ChangeListenerContainer::iterator>
204cdf0e10cSrcweir         aRange (mpChangeListeners->equal_range(rsPropertyName));
205cdf0e10cSrcweir     ChangeListenerContainer::const_iterator iListener;
206cdf0e10cSrcweir     for (iListener=aRange.first; iListener!=aRange.second; ++iListener)
207cdf0e10cSrcweir     {
208cdf0e10cSrcweir         if (iListener->second.is())
209cdf0e10cSrcweir             iListener->second->propertyChange(rEvent);
210cdf0e10cSrcweir     }
211cdf0e10cSrcweir }
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 
ThrowIfDisposed(void)216cdf0e10cSrcweir void PropertySet::ThrowIfDisposed (void)
217cdf0e10cSrcweir     throw (::com::sun::star::lang::DisposedException)
218cdf0e10cSrcweir {
219cdf0e10cSrcweir 	if (rBHelper.bDisposed || rBHelper.bInDispose)
220cdf0e10cSrcweir 	{
221cdf0e10cSrcweir         throw lang::DisposedException (
222cdf0e10cSrcweir             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
223cdf0e10cSrcweir                 "PropertySet object has already been disposed")),
224cdf0e10cSrcweir             static_cast<uno::XWeak*>(this));
225cdf0e10cSrcweir     }
226cdf0e10cSrcweir }
227cdf0e10cSrcweir 
228cdf0e10cSrcweir } } // end of namespace ::sd::tools
229