xref: /aoo42x/main/sd/source/ui/inc/tools/PropertySet.hxx (revision 67e470da)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SD_TOOLS_PROPERTY_SET_HXX
25 #define SD_TOOLS_PROPERTY_SET_HXX
26 
27 #include <cppuhelper/basemutex.hxx>
28 #include <cppuhelper/compbase1.hxx>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <boost/scoped_ptr.hpp>
31 #include <map>
32 
33 namespace css = ::com::sun::star;
34 
35 namespace sd { namespace tools {
36 
37 namespace {
38     typedef ::cppu::WeakComponentImplHelper1 <
39         css::beans::XPropertySet
40     > PropertySetInterfaceBase;
41 }
42 
43 
44 /** A very simple implementation of the XPropertySet interface.  It does not
45     support constrained properties and thus does not support vetoable
46     listeners.  It does not support the optional property set info.
47 
48     In order to use it you have to derive from this class and implement the
49     GetPropertyValue() and SetPropertyValue() methods.
50 */
51 class PropertySet
52     : protected ::cppu::BaseMutex,
53       public PropertySetInterfaceBase
54 {
55 public:
56     explicit PropertySet (void);
57     virtual ~PropertySet (void);
58 
59     virtual void SAL_CALL disposing (void);
60 
61     // XPropertySet
62 
63     virtual css::uno::Reference<css::beans::XPropertySetInfo>
64         SAL_CALL getPropertySetInfo (void)
65         throw(css::uno::RuntimeException);
66 
67     virtual void SAL_CALL setPropertyValue (
68         const rtl::OUString& rsPropertyName,
69         const css::uno::Any& rsPropertyValue)
70         throw(css::beans::UnknownPropertyException,
71             css::beans::PropertyVetoException,
72             css::lang::IllegalArgumentException,
73             css::lang::WrappedTargetException,
74             css::uno::RuntimeException);
75 
76     virtual css::uno::Any SAL_CALL getPropertyValue (const rtl::OUString& rsPropertyName)
77         throw(css::beans::UnknownPropertyException,
78             css::lang::WrappedTargetException,
79             css::uno::RuntimeException);
80 
81     virtual void SAL_CALL addPropertyChangeListener (
82         const rtl::OUString& rsPropertyName,
83         const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
84         throw(css::beans::UnknownPropertyException,
85             css::lang::WrappedTargetException,
86             css::uno::RuntimeException);
87 
88     virtual void SAL_CALL removePropertyChangeListener (
89         const rtl::OUString& rsPropertyName,
90         const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
91         throw(css::beans::UnknownPropertyException,
92             css::lang::WrappedTargetException,
93             css::uno::RuntimeException);
94 
95     virtual void SAL_CALL addVetoableChangeListener (
96         const rtl::OUString& rsPropertyName,
97         const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener)
98         throw(css::beans::UnknownPropertyException,
99             css::lang::WrappedTargetException,
100             css::uno::RuntimeException);
101 
102     virtual void SAL_CALL removeVetoableChangeListener (
103         const rtl::OUString& rsPropertyName,
104         const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener)
105         throw(css::beans::UnknownPropertyException,
106             css::lang::WrappedTargetException,
107             css::uno::RuntimeException);
108 
109 protected:
110     /** Return the requested property value.
111         @throw com::sun::star::beans::UnknownPropertyException when the
112             property is not supported.
113     */
114     virtual css::uno::Any GetPropertyValue (const ::rtl::OUString& rsPropertyName) = 0;
115     /** Set the given property value.
116         @return the old value.
117         @throw com::sun::star::beans::UnknownPropertyException when the
118             property is not supported.
119     */
120     virtual css::uno::Any SetPropertyValue (
121         const ::rtl::OUString& rsPropertyName,
122         const css::uno::Any& rValue) = 0;
123 
124 private:
125     typedef ::std::multimap<rtl::OUString,
126         css::uno::Reference<css::beans::XPropertyChangeListener> > ChangeListenerContainer;
127     ::boost::scoped_ptr<ChangeListenerContainer> mpChangeListeners;
128 
129     /** Call all listeners that are registered for the given property name.
130         Call this method with an empty property name to call listeners that
131         are registered for all properties.
132     */
133     void CallListeners (
134         const rtl::OUString& rsPropertyName,
135         const css::beans::PropertyChangeEvent& rEvent);
136 
137     /** This method throws a DisposedException when the object has already been
138         disposed.
139     */
140     void ThrowIfDisposed (void)
141         throw (css::lang::DisposedException);
142 };
143 
144 } } // end of namespace ::sd::tools
145 
146 #endif
147