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 .
19 #ifndef INCLUDED_CHART2_SOURCE_INC_PROPERTYHELPER_HXX
20 #define INCLUDED_CHART2_SOURCE_INC_PROPERTYHELPER_HXX
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/beans/Property.hpp>
24 #include <com/sun/star/beans/PropertyValue.hpp>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 #include <comphelper/property.hxx>
28 #include "charttoolsdllapi.hxx"
31 #include <unordered_map>
36 typedef int tPropertyValueMapKey
;
38 typedef std::unordered_map
<tPropertyValueMapKey
, css::uno::Any
> tPropertyValueMap
;
40 namespace PropertyHelper
43 /** adds a line dash with a unique name to the gradient obtained by the given
46 @return The name used for storing this element in the table
48 OOO_DLLPUBLIC_CHARTTOOLS OUString
addLineDashUniqueNameToTable(
49 const ::com::sun::star::uno::Any
& rValue
,
50 const ::com::sun::star::uno::Reference
<
51 ::com::sun::star::lang::XMultiServiceFactory
> & xFact
,
52 const OUString
& rPreferredName
);
54 /** adds a gradient with a unique name to the gradient obtained by the given
57 @return The name used for storing this element in the table
59 OOO_DLLPUBLIC_CHARTTOOLS OUString
addGradientUniqueNameToTable(
60 const ::com::sun::star::uno::Any
& rValue
,
61 const ::com::sun::star::uno::Reference
<
62 ::com::sun::star::lang::XMultiServiceFactory
> & xFact
,
63 const OUString
& rPreferredName
);
65 /** adds a transparency gradient with a unique name to the gradient obtained
68 @return The name used for storing this element in the table
70 OOO_DLLPUBLIC_CHARTTOOLS
71 OUString
addTransparencyGradientUniqueNameToTable(
72 const ::com::sun::star::uno::Any
& rValue
,
73 const ::com::sun::star::uno::Reference
<
74 ::com::sun::star::lang::XMultiServiceFactory
> & xFact
,
75 const OUString
& rPreferredName
);
77 /** adds a hatch with a unique name to the gradient obtained by the given
80 @return The name used for storing this element in the table
82 OOO_DLLPUBLIC_CHARTTOOLS OUString
addHatchUniqueNameToTable(
83 const ::com::sun::star::uno::Any
& rValue
,
84 const ::com::sun::star::uno::Reference
<
85 ::com::sun::star::lang::XMultiServiceFactory
> & xFact
,
86 const OUString
& rPreferredName
);
88 /** adds a bitmap with a unique name to the gradient obtained by the given
91 @return The name used for storing this element in the table
93 OOO_DLLPUBLIC_CHARTTOOLS OUString
addBitmapUniqueNameToTable(
94 const ::com::sun::star::uno::Any
& rValue
,
95 const ::com::sun::star::uno::Reference
<
96 ::com::sun::star::lang::XMultiServiceFactory
> & xFact
,
97 const OUString
& rPreferredName
);
99 /** Set a property to a certain value in the given map. This works for
100 properties that are already set, and those which are not yet in the map.
102 @param any is the value encapsulated in the variant type Any
104 OOO_DLLPUBLIC_CHARTTOOLS
105 void setPropertyValueAny( tPropertyValueMap
& rOutMap
, tPropertyValueMapKey key
,
106 const ::com::sun::star::uno::Any
& rAny
);
108 /** Set a property to a certain value in the given map. This works for
109 properties that are already set, and those which are not yet in the map.
111 @param value is the value of type Value that will be put into a variant type
112 Any before set in the property map.
114 template< typename Value
>
115 void setPropertyValue( tPropertyValueMap
& rOutMap
, tPropertyValueMapKey key
, const Value
& value
)
117 setPropertyValueAny( rOutMap
, key
, ::com::sun::star::uno::makeAny( value
));
121 void setPropertyValue
< ::com::sun::star::uno::Any
>( tPropertyValueMap
& rOutMap
, tPropertyValueMapKey key
, const ::com::sun::star::uno::Any
& rAny
);
123 OOO_DLLPUBLIC_CHARTTOOLS
void setPropertyValueDefaultAny( tPropertyValueMap
& rOutMap
, tPropertyValueMapKey key
, const ::com::sun::star::uno::Any
& rAny
);
125 /** Calls setPropertyValue() but asserts that the given property hasn't been set
128 template< typename Value
>
129 void setPropertyValueDefault( tPropertyValueMap
& rOutMap
, tPropertyValueMapKey key
, const Value
& value
)
131 setPropertyValueDefaultAny( rOutMap
, key
, ::com::sun::star::uno::makeAny( value
));
134 /** Calls setPropertyValue() but asserts that the given property hasn't been set
138 void setPropertyValueDefault
< ::com::sun::star::uno::Any
>( tPropertyValueMap
& rOutMap
, tPropertyValueMapKey key
, const ::com::sun::star::uno::Any
& rAny
);
140 /** Calls setPropertyValueDefault() with an empty Any as value
142 OOO_DLLPUBLIC_CHARTTOOLS
void setEmptyPropertyValueDefault( tPropertyValueMap
& rOutMap
, tPropertyValueMapKey key
);
144 } // namespace PropertyHelper
146 struct OOO_DLLPUBLIC_CHARTTOOLS PropertyNameLess
148 inline bool operator() ( const ::com::sun::star::beans::Property
& first
,
149 const ::com::sun::star::beans::Property
& second
)
151 return ( first
.Name
.compareTo( second
.Name
) < 0 );
155 struct OOO_DLLPUBLIC_CHARTTOOLS PropertyLess
: public ::std::binary_function
<
156 ::com::sun::star::beans::Property
,
157 ::com::sun::star::beans::Property
,
160 bool operator() ( const ::com::sun::star::beans::Property
& rFirst
,
161 const ::com::sun::star::beans::Property
& rSecond
)
163 return ( rFirst
.Name
.compareTo( rSecond
.Name
) < 0 );
167 struct OOO_DLLPUBLIC_CHARTTOOLS PropertyValueNameEquals
: public ::std::unary_function
< ::com::sun::star::beans::PropertyValue
, bool >
169 explicit PropertyValueNameEquals( const OUString
& rName
) :
173 bool operator() ( const ::com::sun::star::beans::PropertyValue
& rPropValue
)
175 return rPropValue
.Name
.equals( m_aName
);
184 // INCLUDED_CHART2_SOURCE_INC_PROPERTYHELPER_HXX
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */