1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_CANVAS_PROPERTYSETHELPER_HXX
21 #define INCLUDED_CANVAS_PROPERTYSETHELPER_HXX
23 #include <com/sun/star/beans/XPropertySetInfo.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <canvas/canvastools.hxx>
27 #include <boost/function.hpp>
31 #include <canvas/canvastoolsdllapi.h>
35 /** Really simplistic XPropertySet helper for properties.
37 This class provides easy access to properties, referenced via
38 ASCII strings. The name/property modification callbacks pairs
39 are passed into this class via a vector. Each time a property
40 is set or queried, the corresponding getter or setter callback
43 Use this class as a delegate for the corresponding
44 XPropertySet methods, and take care of UNO XInterface and lock
47 The core responsibility of this this class is the name/value
48 mapping for property sets.
50 class CANVASTOOLS_DLLPUBLIC PropertySetHelper
53 typedef boost::function0
< ::com::sun::star::uno::Any
> GetterType
;
54 typedef boost::function1
<void, const ::com::sun::star::uno::Any
&> SetterType
;
60 typedef tools::ValueMap
< Callbacks
> MapType
;
61 typedef std::vector
< MapType::MapEntry
> InputMap
;
63 class MakeMap
: public InputMap
66 MakeMap(const char* name
,
67 const GetterType
& getter
,
68 const SetterType
& setter
)
70 MapType::MapEntry aEntry
={name
, {getter
, setter
}};
71 this->push_back(aEntry
);
73 MakeMap(const char* name
,
74 const GetterType
& getter
)
76 MapType::MapEntry aEntry
={name
, {getter
, SetterType()}};
77 this->push_back(aEntry
);
79 MakeMap
& operator()(const char* name
,
80 const GetterType
& getter
,
81 const SetterType
& setter
)
83 MapType::MapEntry aEntry
={name
, {getter
, setter
}};
84 this->push_back(aEntry
);
87 MakeMap
& operator()(const char* name
,
88 const GetterType
& getter
)
90 MapType::MapEntry aEntry
={name
, {getter
, SetterType()}};
91 this->push_back(aEntry
);
96 /** Create helper with zero properties
100 /** Init helper with new name/value map
103 Vector of name/function pointers. Each name is offered as
104 a property, and reading/writing to this property is passed
105 on to the given function pointer.
107 void initProperties( const InputMap
& rMap
);
109 /** Add given properties to helper
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. These name/function
115 pairs are added to the already existing ones.
117 void addProperties( const InputMap
& rMap
);
119 /** Checks whether the given string corresponds to a valid
122 @return true, if the given name maps to a known property.
124 bool isPropertyName( const OUString
& aPropertyName
) const;
126 /** Request the currently active map
128 const InputMap
& getPropertyMap() const { return maMapEntries
; }
130 // XPropertySet implementation
131 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> getPropertySetInfo() const;
132 void setPropertyValue( const OUString
& aPropertyName
,
133 const ::com::sun::star::uno::Any
& aValue
);
134 ::com::sun::star::uno::Any
getPropertyValue( const OUString
& PropertyName
) const;
135 void addPropertyChangeListener( const OUString
& aPropertyName
,
136 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyChangeListener
>& xListener
);
137 void removePropertyChangeListener( const OUString
& aPropertyName
,
138 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyChangeListener
>& xListener
);
139 void addVetoableChangeListener( const OUString
& aPropertyName
,
140 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XVetoableChangeListener
>& xListener
);
141 void removeVetoableChangeListener( const OUString
& aPropertyName
,
142 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XVetoableChangeListener
>& xListener
);
145 std::auto_ptr
<MapType
> mpMap
;
146 InputMap maMapEntries
;
150 #endif /* INCLUDED_CANVAS_PROPERTYSETHELPER_HXX */
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */