xref: /aoo41x/main/sd/source/ui/inc/tools/PropertySet.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SD_TOOLS_PROPERTY_SET_HXX
29 #define SD_TOOLS_PROPERTY_SET_HXX
30 
31 #include <cppuhelper/basemutex.hxx>
32 #include <cppuhelper/compbase1.hxx>
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <boost/scoped_ptr.hpp>
35 #include <map>
36 
37 namespace css = ::com::sun::star;
38 
39 namespace sd { namespace tools {
40 
41 namespace {
42     typedef ::cppu::WeakComponentImplHelper1 <
43         css::beans::XPropertySet
44     > PropertySetInterfaceBase;
45 }
46 
47 
48 /** A very simple implementation of the XPropertySet interface.  It does not
49     support constrained properties and thus does not support vetoable
50     listeners.  It does not support the optional property set info.
51 
52     In order to use it you have to derive from this class and implement the
53     GetPropertyValue() and SetPropertyValue() methods.
54 */
55 class PropertySet
56     : protected ::cppu::BaseMutex,
57       public PropertySetInterfaceBase
58 {
59 public:
60     explicit PropertySet (void);
61     virtual ~PropertySet (void);
62 
63     virtual void SAL_CALL disposing (void);
64 
65     // XPropertySet
66 
67     virtual css::uno::Reference<css::beans::XPropertySetInfo>
68         SAL_CALL getPropertySetInfo (void)
69         throw(css::uno::RuntimeException);
70 
71     virtual void SAL_CALL setPropertyValue (
72         const rtl::OUString& rsPropertyName,
73         const css::uno::Any& rsPropertyValue)
74         throw(css::beans::UnknownPropertyException,
75             css::beans::PropertyVetoException,
76             css::lang::IllegalArgumentException,
77             css::lang::WrappedTargetException,
78             css::uno::RuntimeException);
79 
80     virtual css::uno::Any SAL_CALL getPropertyValue (const rtl::OUString& rsPropertyName)
81         throw(css::beans::UnknownPropertyException,
82             css::lang::WrappedTargetException,
83             css::uno::RuntimeException);
84 
85     virtual void SAL_CALL addPropertyChangeListener (
86         const rtl::OUString& rsPropertyName,
87         const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
88         throw(css::beans::UnknownPropertyException,
89             css::lang::WrappedTargetException,
90             css::uno::RuntimeException);
91 
92     virtual void SAL_CALL removePropertyChangeListener (
93         const rtl::OUString& rsPropertyName,
94         const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
95         throw(css::beans::UnknownPropertyException,
96             css::lang::WrappedTargetException,
97             css::uno::RuntimeException);
98 
99     virtual void SAL_CALL addVetoableChangeListener (
100         const rtl::OUString& rsPropertyName,
101         const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener)
102         throw(css::beans::UnknownPropertyException,
103             css::lang::WrappedTargetException,
104             css::uno::RuntimeException);
105 
106     virtual void SAL_CALL removeVetoableChangeListener (
107         const rtl::OUString& rsPropertyName,
108         const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener)
109         throw(css::beans::UnknownPropertyException,
110             css::lang::WrappedTargetException,
111             css::uno::RuntimeException);
112 
113 protected:
114     /** Return the requested property value.
115         @throw com::sun::star::beans::UnknownPropertyException when the
116             property is not supported.
117     */
118     virtual css::uno::Any GetPropertyValue (const ::rtl::OUString& rsPropertyName) = 0;
119     /** Set the given property value.
120         @return the old value.
121         @throw com::sun::star::beans::UnknownPropertyException when the
122             property is not supported.
123     */
124     virtual css::uno::Any SetPropertyValue (
125         const ::rtl::OUString& rsPropertyName,
126         const css::uno::Any& rValue) = 0;
127 
128 private:
129     typedef ::std::multimap<rtl::OUString,
130         css::uno::Reference<css::beans::XPropertyChangeListener> > ChangeListenerContainer;
131     ::boost::scoped_ptr<ChangeListenerContainer> mpChangeListeners;
132 
133     /** Call all listeners that are registered for the given property name.
134         Call this method with an empty property name to call listeners that
135         are registered for all properties.
136     */
137     void CallListeners (
138         const rtl::OUString& rsPropertyName,
139         const css::beans::PropertyChangeEvent& rEvent);
140 
141     /** This method throws a DisposedException when the object has already been
142         disposed.
143     */
144     void ThrowIfDisposed (void)
145         throw (css::lang::DisposedException);
146 };
147 
148 } } // end of namespace ::sd::tools
149 
150 #endif
151