Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef INCLUDED_CANVAS_PROPERTYSETHELPER_HXX
30 : : #define INCLUDED_CANVAS_PROPERTYSETHELPER_HXX
31 : :
32 : : #include <com/sun/star/beans/XPropertySetInfo.hpp>
33 : : #include <com/sun/star/beans/XPropertySet.hpp>
34 : : #include <canvas/canvastools.hxx>
35 : :
36 : : #include <boost/function.hpp>
37 : : #include <vector>
38 : : #include <memory>
39 : :
40 : : #include <canvas/canvastoolsdllapi.h>
41 : :
42 : : namespace canvas
43 : : {
44 : : /** Really simplistic XPropertySet helper for properties.
45 : :
46 : : This class provides easy access to properties, referenced via
47 : : ASCII strings. The name/property modification callbacks pairs
48 : : are passed into this class via a vector. Each time a property
49 : : is set or queried, the corresponding getter or setter callback
50 : : is called.
51 : :
52 : : Use this class as a delegate for the corresponding
53 : : XPropertySet methods, and take care of UNO XInterface and lock
54 : : handling by yourself.
55 : :
56 : : The core responsibility of this this class is the name/value
57 : : mapping for property sets.
58 : : */
59 : 0 : class CANVASTOOLS_DLLPUBLIC PropertySetHelper
60 : : {
61 : : public:
62 : : typedef boost::function0< ::com::sun::star::uno::Any > GetterType;
63 : : typedef boost::function1<void, const ::com::sun::star::uno::Any&> SetterType;
64 [ # # ][ # # ]: 0 : struct Callbacks
65 : : {
66 : : GetterType getter;
67 : : SetterType setter;
68 : : };
69 : : typedef tools::ValueMap< Callbacks > MapType;
70 : : typedef std::vector< MapType::MapEntry > InputMap;
71 : :
72 : 0 : class MakeMap : public InputMap
73 : : {
74 : : public:
75 : 0 : MakeMap(const char* name,
76 : : const GetterType& getter,
77 : : const SetterType& setter)
78 : 0 : {
79 : 0 : MapType::MapEntry aEntry={name, {getter, setter}};
80 : 0 : this->push_back(aEntry);
81 : 0 : }
82 : 0 : MakeMap(const char* name,
83 : : const GetterType& getter)
84 : 0 : {
85 : 0 : MapType::MapEntry aEntry={name, {getter, SetterType()}};
86 : 0 : this->push_back(aEntry);
87 : 0 : }
88 : 0 : MakeMap& operator()(const char* name,
89 : : const GetterType& getter,
90 : : const SetterType& setter)
91 : : {
92 : 0 : MapType::MapEntry aEntry={name, {getter, setter}};
93 : 0 : this->push_back(aEntry);
94 : 0 : return *this;
95 : : }
96 : 0 : MakeMap& operator()(const char* name,
97 : : const GetterType& getter)
98 : : {
99 : 0 : MapType::MapEntry aEntry={name, {getter, SetterType()}};
100 : 0 : this->push_back(aEntry);
101 : 0 : return *this;
102 : : }
103 : : };
104 : :
105 : : /** Create helper with zero properties
106 : : */
107 : : PropertySetHelper();
108 : :
109 : : /** Init helper with new name/value map
110 : :
111 : : @param rMap
112 : : Vector of name/function pointers. Each name is offered as
113 : : a property, and reading/writing to this property is passed
114 : : on to the given function pointer.
115 : : */
116 : : void initProperties( const InputMap& rMap );
117 : :
118 : : /** Add given properties to helper
119 : :
120 : : @param rMap
121 : : Vector of name/function pointers. Each name is offered as
122 : : a property, and reading/writing to this property is passed
123 : : on to the given function pointer. These name/function
124 : : pairs are added to the already existing ones.
125 : : */
126 : : void addProperties( const InputMap& rMap );
127 : :
128 : : /** Checks whether the given string corresponds to a valid
129 : : property name.
130 : :
131 : : @return true, if the given name maps to a known property.
132 : : */
133 : : bool isPropertyName( const ::rtl::OUString& aPropertyName ) const;
134 : :
135 : : /** Request the currently active map
136 : : */
137 : 0 : const InputMap& getPropertyMap() const { return maMapEntries; }
138 : :
139 : : // XPropertySet implementation
140 : : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > getPropertySetInfo() const;
141 : : void setPropertyValue( const ::rtl::OUString& aPropertyName,
142 : : const ::com::sun::star::uno::Any& aValue );
143 : : ::com::sun::star::uno::Any getPropertyValue( const ::rtl::OUString& PropertyName ) const;
144 : : void addPropertyChangeListener( const ::rtl::OUString& aPropertyName,
145 : : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener );
146 : : void removePropertyChangeListener( const ::rtl::OUString& aPropertyName,
147 : : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener );
148 : : void addVetoableChangeListener( const ::rtl::OUString& aPropertyName,
149 : : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& xListener );
150 : : void removeVetoableChangeListener( const ::rtl::OUString& aPropertyName,
151 : : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& xListener );
152 : :
153 : : private:
154 : : std::auto_ptr<MapType> mpMap;
155 : : InputMap maMapEntries;
156 : : };
157 : : }
158 : :
159 : : #endif /* INCLUDED_CANVAS_PROPERTYSETHELPER_HXX */
160 : :
161 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|