tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / canvas / inc / propertysethelper.hxx
blobaebcbe049e200cfde89635f43ac4699e3a12a455
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include <canvas/canvastools.hxx>
24 #include <functional>
25 #include <vector>
26 #include <memory>
28 #include <canvas/canvastoolsdllapi.h>
30 namespace com::sun::star::beans { class XPropertyChangeListener; }
31 namespace com::sun::star::beans { class XPropertySetInfo; }
32 namespace com::sun::star::beans { class XVetoableChangeListener; }
34 namespace canvas
36 /** Really simplistic XPropertySet helper for properties.
38 This class provides easy access to properties, referenced via
39 ASCII strings. The name/property modification callbacks pairs
40 are passed into this class via a vector. Each time a property
41 is set or queried, the corresponding getter or setter callback
42 is called.
44 Use this class as a delegate for the corresponding
45 XPropertySet methods, and take care of UNO XInterface and lock
46 handling by yourself.
48 The core responsibility of this class is the name/value
49 mapping for property sets.
51 class CANVASTOOLS_DLLPUBLIC PropertySetHelper
53 public:
54 typedef std::function<css::uno::Any ()> GetterType;
55 typedef std::function<void (const css::uno::Any&)> SetterType;
56 struct Callbacks
58 GetterType getter;
59 SetterType setter;
61 typedef tools::ValueMap< Callbacks > MapType;
62 typedef std::vector< MapType::MapEntry > InputMap;
64 class MakeMap : public InputMap
66 public:
67 MakeMap(const char* name,
68 const GetterType& getter,
69 const SetterType& setter)
71 MapType::MapEntry aEntry={name, {getter, setter}};
72 push_back(aEntry);
74 MakeMap(const char* name,
75 const GetterType& getter)
77 MapType::MapEntry aEntry={name, {getter, SetterType()}};
78 push_back(aEntry);
80 MakeMap& operator()(const char* name,
81 const GetterType& getter,
82 const SetterType& setter)
84 MapType::MapEntry aEntry={name, {getter, setter}};
85 push_back(aEntry);
86 return *this;
90 /** Create helper with zero properties
92 PropertySetHelper();
94 /** Init helper with new name/value map
96 @param rMap
97 Vector of name/function pointers. Each name is offered as
98 a property, and reading/writing to this property is passed
99 on to the given function pointer.
101 void initProperties( InputMap&& rMap );
103 /** Add given properties to helper
105 @param rMap
106 Vector of name/function pointers. Each name is offered as
107 a property, and reading/writing to this property is passed
108 on to the given function pointer. These name/function
109 pairs are added to the already existing ones.
111 void addProperties( const InputMap& rMap );
113 /** Checks whether the given string corresponds to a valid
114 property name.
116 @return true, if the given name maps to a known property.
118 bool isPropertyName( const OUString& aPropertyName ) const;
120 // XPropertySet implementation
121 css::uno::Reference< css::beans::XPropertySetInfo > getPropertySetInfo() const;
122 void setPropertyValue( const OUString& aPropertyName,
123 const css::uno::Any& aValue );
124 css::uno::Any getPropertyValue( const OUString& PropertyName ) const;
125 void addPropertyChangeListener( const OUString& aPropertyName,
126 const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener );
127 void addVetoableChangeListener( const OUString& aPropertyName,
128 const css::uno::Reference< css::beans::XVetoableChangeListener >& xListener );
130 private:
131 std::unique_ptr<MapType> mpMap;
132 InputMap maMapEntries;
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */