LibreOffice Module canvas (master) 1
propertysethelper.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
23
24#include <functional>
25#include <vector>
26#include <memory>
27
29
30namespace com::sun::star::beans { class XPropertyChangeListener; }
31namespace com::sun::star::beans { class XPropertySetInfo; }
32namespace com::sun::star::beans { class XVetoableChangeListener; }
33
34namespace canvas
35{
52 {
53 public:
54 typedef std::function<css::uno::Any ()> GetterType;
55 typedef std::function<void (const css::uno::Any&)> SetterType;
56 struct Callbacks
57 {
60 };
62 typedef std::vector< MapType::MapEntry > InputMap;
63
64 class MakeMap : public InputMap
65 {
66 public:
67 MakeMap(const char* name,
68 const GetterType& getter,
69 const SetterType& setter)
70 {
71 MapType::MapEntry aEntry={name, {getter, setter}};
72 push_back(aEntry);
73 }
74 MakeMap(const char* name,
75 const GetterType& getter)
76 {
77 MapType::MapEntry aEntry={name, {getter, SetterType()}};
78 push_back(aEntry);
79 }
80 MakeMap& operator()(const char* name,
81 const GetterType& getter,
82 const SetterType& setter)
83 {
84 MapType::MapEntry aEntry={name, {getter, setter}};
85 push_back(aEntry);
86 return *this;
87 }
88 };
89
93
101 void initProperties( InputMap&& rMap );
102
111 void addProperties( const InputMap& rMap );
112
118 bool isPropertyName( const OUString& aPropertyName ) const;
119
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 );
129
130 private:
131 std::unique_ptr<MapType> mpMap;
133 };
134}
135
136/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define CANVASTOOLS_DLLPUBLIC
MakeMap & operator()(const char *name, const GetterType &getter, const SetterType &setter)
MakeMap(const char *name, const GetterType &getter)
MakeMap(const char *name, const GetterType &getter, const SetterType &setter)
Really simplistic XPropertySet helper for properties.
std::vector< MapType::MapEntry > InputMap
void addVetoableChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &xListener)
std::function< css::uno::Any()> GetterType
std::function< void(const css::uno::Any &)> SetterType
std::unique_ptr< MapType > mpMap
tools::ValueMap< Callbacks > MapType
void setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue)
void addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener)
A very simplistic map for ASCII strings and arbitrary value types.
const char * name
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)