xref: /trunk/main/sd/source/ui/inc/tools/PropertySet.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 
66     virtual void SAL_CALL setPropertyValue (
67         const rtl::OUString& rsPropertyName,
68         const css::uno::Any& rsPropertyValue);
69 
70     virtual css::uno::Any SAL_CALL getPropertyValue (const rtl::OUString& rsPropertyName);
71 
72     virtual void SAL_CALL addPropertyChangeListener (
73         const rtl::OUString& rsPropertyName,
74         const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener);
75 
76     virtual void SAL_CALL removePropertyChangeListener (
77         const rtl::OUString& rsPropertyName,
78         const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener);
79 
80     virtual void SAL_CALL addVetoableChangeListener (
81         const rtl::OUString& rsPropertyName,
82         const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener);
83 
84     virtual void SAL_CALL removeVetoableChangeListener (
85         const rtl::OUString& rsPropertyName,
86         const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener);
87 
88 protected:
89     /** Return the requested property value.
90         @throw com::sun::star::beans::UnknownPropertyException when the
91             property is not supported.
92     */
93     virtual css::uno::Any GetPropertyValue (const ::rtl::OUString& rsPropertyName) = 0;
94     /** Set the given property value.
95         @return the old value.
96         @throw com::sun::star::beans::UnknownPropertyException when the
97             property is not supported.
98     */
99     virtual css::uno::Any SetPropertyValue (
100         const ::rtl::OUString& rsPropertyName,
101         const css::uno::Any& rValue) = 0;
102 
103 private:
104     typedef ::std::multimap<rtl::OUString,
105         css::uno::Reference<css::beans::XPropertyChangeListener> > ChangeListenerContainer;
106     ::boost::scoped_ptr<ChangeListenerContainer> mpChangeListeners;
107 
108     /** Call all listeners that are registered for the given property name.
109         Call this method with an empty property name to call listeners that
110         are registered for all properties.
111     */
112     void CallListeners (
113         const rtl::OUString& rsPropertyName,
114         const css::beans::PropertyChangeEvent& rEvent);
115 
116     /** This method throws a DisposedException when the object has already been
117         disposed.
118     */
119     void ThrowIfDisposed (void);
120 };
121 
122 } } // end of namespace ::sd::tools
123 
124 #endif
125