1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PropertyHelper.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef CHART_PROPERTYHELPER_HXX
31 #define CHART_PROPERTYHELPER_HXX
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <com/sun/star/beans/Property.hpp>
35 #include <com/sun/star/beans/PropertyValue.hpp>
36 #include <com/sun/star/uno/Any.hxx>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <comphelper/property.hxx>
40 #include "charttoolsdllapi.hxx"
45 typedef int tPropertyValueMapKey
;
47 typedef ::std::map
< tPropertyValueMapKey
, ::com::sun::star::uno::Any
>
50 namespace PropertyHelper
53 /** adds a line dash with a unique name to the gradient obtained by the given
56 @return The name used for storing this element in the table
58 OOO_DLLPUBLIC_CHARTTOOLS ::rtl::OUString
addLineDashUniqueNameToTable(
59 const ::com::sun::star::uno::Any
& rValue
,
60 const ::com::sun::star::uno::Reference
<
61 ::com::sun::star::lang::XMultiServiceFactory
> & xFact
,
62 const ::rtl::OUString
& rPreferredName
);
64 /** adds a gradient with a unique name to the gradient obtained by the given
67 @return The name used for storing this element in the table
69 OOO_DLLPUBLIC_CHARTTOOLS ::rtl::OUString
addGradientUniqueNameToTable(
70 const ::com::sun::star::uno::Any
& rValue
,
71 const ::com::sun::star::uno::Reference
<
72 ::com::sun::star::lang::XMultiServiceFactory
> & xFact
,
73 const ::rtl::OUString
& rPreferredName
);
75 /** adds a transparency gradient with a unique name to the gradient obtained
78 @return The name used for storing this element in the table
80 OOO_DLLPUBLIC_CHARTTOOLS
81 ::rtl::OUString
addTransparencyGradientUniqueNameToTable(
82 const ::com::sun::star::uno::Any
& rValue
,
83 const ::com::sun::star::uno::Reference
<
84 ::com::sun::star::lang::XMultiServiceFactory
> & xFact
,
85 const ::rtl::OUString
& rPreferredName
);
87 /** adds a hatch with a unique name to the gradient obtained by the given
90 @return The name used for storing this element in the table
92 OOO_DLLPUBLIC_CHARTTOOLS ::rtl::OUString
addHatchUniqueNameToTable(
93 const ::com::sun::star::uno::Any
& rValue
,
94 const ::com::sun::star::uno::Reference
<
95 ::com::sun::star::lang::XMultiServiceFactory
> & xFact
,
96 const ::rtl::OUString
& rPreferredName
);
98 /** adds a bitmap with a unique name to the gradient obtained by the given
101 @return The name used for storing this element in the table
103 OOO_DLLPUBLIC_CHARTTOOLS ::rtl::OUString
addBitmapUniqueNameToTable(
104 const ::com::sun::star::uno::Any
& rValue
,
105 const ::com::sun::star::uno::Reference
<
106 ::com::sun::star::lang::XMultiServiceFactory
> & xFact
,
107 const ::rtl::OUString
& rPreferredName
);
109 // --------------------------------------------------------------------------------
111 /** Set a property to a certain value in the given map. This works for
112 properties that are already set, and those which are not yet in the map.
114 @param any is the value encapsulated in the variant type Any
116 OOO_DLLPUBLIC_CHARTTOOLS
117 void setPropertyValueAny( tPropertyValueMap
& rOutMap
, tPropertyValueMapKey key
,
118 const ::com::sun::star::uno::Any
& rAny
);
120 /** Set a property to a certain value in the given map. This works for
121 properties that are already set, and those which are not yet in the map.
123 @param value is the value of type Value that will be put into a variant type
124 Any before set in the property map.
126 template< typename Value
>
127 void setPropertyValue( tPropertyValueMap
& rOutMap
, tPropertyValueMapKey key
, const Value
& value
)
129 setPropertyValueAny( rOutMap
, key
, ::com::sun::star::uno::makeAny( value
));
133 void setPropertyValue
< ::com::sun::star::uno::Any
>( tPropertyValueMap
& rOutMap
, tPropertyValueMapKey key
, const ::com::sun::star::uno::Any
& rAny
);
135 OOO_DLLPUBLIC_CHARTTOOLS
void setPropertyValueDefaultAny( tPropertyValueMap
& rOutMap
, tPropertyValueMapKey key
, const ::com::sun::star::uno::Any
& rAny
);
137 /** Calls setPropertyValue() but asserts that the given property hasn't been set
140 template< typename Value
>
141 void setPropertyValueDefault( tPropertyValueMap
& rOutMap
, tPropertyValueMapKey key
, const Value
& value
)
143 setPropertyValueDefaultAny( rOutMap
, key
, ::com::sun::star::uno::makeAny( value
));
146 /** Calls setPropertyValue() but asserts that the given property hasn't been set
150 void setPropertyValueDefault
< ::com::sun::star::uno::Any
>( tPropertyValueMap
& rOutMap
, tPropertyValueMapKey key
, const ::com::sun::star::uno::Any
& rAny
);
152 /** Calls setPropertyValueDefault() with an empty Any as value
154 OOO_DLLPUBLIC_CHARTTOOLS
void setEmptyPropertyValueDefault( tPropertyValueMap
& rOutMap
, tPropertyValueMapKey key
);
157 } // namespace PropertyHelper
159 // ================================================================================
161 struct OOO_DLLPUBLIC_CHARTTOOLS PropertyNameLess
163 inline bool operator() ( const ::com::sun::star::beans::Property
& first
,
164 const ::com::sun::star::beans::Property
& second
)
166 return ( first
.Name
.compareTo( second
.Name
) < 0 );
170 struct OOO_DLLPUBLIC_CHARTTOOLS PropertyLess
: public ::std::binary_function
<
171 ::com::sun::star::beans::Property
,
172 ::com::sun::star::beans::Property
,
175 bool operator() ( const ::com::sun::star::beans::Property
& rFirst
,
176 const ::com::sun::star::beans::Property
& rSecond
)
178 return ( rFirst
.Name
.compareTo( rSecond
.Name
) < 0 );
182 struct OOO_DLLPUBLIC_CHARTTOOLS PropertyValueNameEquals
: public ::std::unary_function
< ::com::sun::star::beans::PropertyValue
, bool >
184 explicit PropertyValueNameEquals( const ::rtl::OUString
& rName
) :
188 bool operator() ( const ::com::sun::star::beans::PropertyValue
& rPropValue
)
190 return rPropValue
.Name
.equals( m_aName
);
194 ::rtl::OUString m_aName
;
199 // CHART_PROPERTYHELPER_HXX