1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir #ifndef CHART_PROPERTYHELPER_HXX
28*cdf0e10cSrcweir #define CHART_PROPERTYHELPER_HXX
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/beans/Property.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
34*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35*cdf0e10cSrcweir #include <comphelper/property.hxx>
36*cdf0e10cSrcweir #include <map>
37*cdf0e10cSrcweir #include "charttoolsdllapi.hxx"
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir namespace chart
40*cdf0e10cSrcweir {
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir typedef int tPropertyValueMapKey;
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir typedef ::std::map< tPropertyValueMapKey, ::com::sun::star::uno::Any >
45*cdf0e10cSrcweir     tPropertyValueMap;
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir namespace PropertyHelper
48*cdf0e10cSrcweir {
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir /** adds a line dash with a unique name to the gradient obtained by the given
51*cdf0e10cSrcweir     factory.
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir     @return The name used for storing this element in the table
54*cdf0e10cSrcweir */
55*cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS ::rtl::OUString addLineDashUniqueNameToTable(
56*cdf0e10cSrcweir     const ::com::sun::star::uno::Any & rValue,
57*cdf0e10cSrcweir     const ::com::sun::star::uno::Reference<
58*cdf0e10cSrcweir         ::com::sun::star::lang::XMultiServiceFactory > & xFact,
59*cdf0e10cSrcweir     const ::rtl::OUString & rPreferredName );
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir /** adds a gradient with a unique name to the gradient obtained by the given
62*cdf0e10cSrcweir     factory.
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir     @return The name used for storing this element in the table
65*cdf0e10cSrcweir */
66*cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS ::rtl::OUString addGradientUniqueNameToTable(
67*cdf0e10cSrcweir     const ::com::sun::star::uno::Any & rValue,
68*cdf0e10cSrcweir     const ::com::sun::star::uno::Reference<
69*cdf0e10cSrcweir         ::com::sun::star::lang::XMultiServiceFactory > & xFact,
70*cdf0e10cSrcweir     const ::rtl::OUString & rPreferredName );
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir /** adds a transparency gradient with a unique name to the gradient obtained
73*cdf0e10cSrcweir     by the given factory.
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir     @return The name used for storing this element in the table
76*cdf0e10cSrcweir */
77*cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS
78*cdf0e10cSrcweir ::rtl::OUString addTransparencyGradientUniqueNameToTable(
79*cdf0e10cSrcweir     const ::com::sun::star::uno::Any & rValue,
80*cdf0e10cSrcweir     const ::com::sun::star::uno::Reference<
81*cdf0e10cSrcweir         ::com::sun::star::lang::XMultiServiceFactory > & xFact,
82*cdf0e10cSrcweir     const ::rtl::OUString & rPreferredName );
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir /** adds a hatch with a unique name to the gradient obtained by the given
85*cdf0e10cSrcweir     factory.
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir     @return The name used for storing this element in the table
88*cdf0e10cSrcweir */
89*cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS ::rtl::OUString addHatchUniqueNameToTable(
90*cdf0e10cSrcweir     const ::com::sun::star::uno::Any & rValue,
91*cdf0e10cSrcweir     const ::com::sun::star::uno::Reference<
92*cdf0e10cSrcweir         ::com::sun::star::lang::XMultiServiceFactory > & xFact,
93*cdf0e10cSrcweir     const ::rtl::OUString & rPreferredName );
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir /** adds a bitmap with a unique name to the gradient obtained by the given
96*cdf0e10cSrcweir     factory.
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir     @return The name used for storing this element in the table
99*cdf0e10cSrcweir */
100*cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS ::rtl::OUString addBitmapUniqueNameToTable(
101*cdf0e10cSrcweir     const ::com::sun::star::uno::Any & rValue,
102*cdf0e10cSrcweir     const ::com::sun::star::uno::Reference<
103*cdf0e10cSrcweir         ::com::sun::star::lang::XMultiServiceFactory > & xFact,
104*cdf0e10cSrcweir     const ::rtl::OUString & rPreferredName );
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir // --------------------------------------------------------------------------------
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir /** Set a property to a certain value in the given map.  This works for
109*cdf0e10cSrcweir     properties that are already set, and those which are not yet in the map.
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir     @param any is the value encapsulated in the variant type Any
112*cdf0e10cSrcweir  */
113*cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS
114*cdf0e10cSrcweir void setPropertyValueAny( tPropertyValueMap & rOutMap, tPropertyValueMapKey key,
115*cdf0e10cSrcweir                           const ::com::sun::star::uno::Any & rAny );
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir /** Set a property to a certain value in the given map.  This works for
118*cdf0e10cSrcweir     properties that are already set, and those which are not yet in the map.
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir     @param value is the value of type Value that will be put into a variant type
121*cdf0e10cSrcweir         Any before set in the property map.
122*cdf0e10cSrcweir  */
123*cdf0e10cSrcweir template< typename Value >
124*cdf0e10cSrcweir     void setPropertyValue( tPropertyValueMap & rOutMap, tPropertyValueMapKey key, const Value & value )
125*cdf0e10cSrcweir {
126*cdf0e10cSrcweir     setPropertyValueAny( rOutMap, key, ::com::sun::star::uno::makeAny( value ));
127*cdf0e10cSrcweir }
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir template<>
130*cdf0e10cSrcweir     void setPropertyValue< ::com::sun::star::uno::Any >( tPropertyValueMap & rOutMap, tPropertyValueMapKey key, const ::com::sun::star::uno::Any & rAny );
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS void setPropertyValueDefaultAny( tPropertyValueMap & rOutMap, tPropertyValueMapKey key, const ::com::sun::star::uno::Any & rAny );
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir /** Calls setPropertyValue() but asserts that the given property hasn't been set
135*cdf0e10cSrcweir     before.
136*cdf0e10cSrcweir  */
137*cdf0e10cSrcweir template< typename Value >
138*cdf0e10cSrcweir     void setPropertyValueDefault( tPropertyValueMap & rOutMap, tPropertyValueMapKey key, const Value & value )
139*cdf0e10cSrcweir {
140*cdf0e10cSrcweir     setPropertyValueDefaultAny( rOutMap, key, ::com::sun::star::uno::makeAny( value ));
141*cdf0e10cSrcweir }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir /** Calls setPropertyValue() but asserts that the given property hasn't been set
144*cdf0e10cSrcweir     before.
145*cdf0e10cSrcweir  */
146*cdf0e10cSrcweir template<>
147*cdf0e10cSrcweir     void setPropertyValueDefault< ::com::sun::star::uno::Any >( tPropertyValueMap & rOutMap, tPropertyValueMapKey key, const ::com::sun::star::uno::Any & rAny );
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir /** Calls setPropertyValueDefault() with an empty Any as value
150*cdf0e10cSrcweir  */
151*cdf0e10cSrcweir OOO_DLLPUBLIC_CHARTTOOLS void setEmptyPropertyValueDefault( tPropertyValueMap & rOutMap, tPropertyValueMapKey key );
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir } // namespace PropertyHelper
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir // ================================================================================
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir struct OOO_DLLPUBLIC_CHARTTOOLS PropertyNameLess
159*cdf0e10cSrcweir {
160*cdf0e10cSrcweir     inline bool operator() ( const ::com::sun::star::beans::Property & first,
161*cdf0e10cSrcweir                              const ::com::sun::star::beans::Property & second )
162*cdf0e10cSrcweir     {
163*cdf0e10cSrcweir         return ( first.Name.compareTo( second.Name ) < 0 );
164*cdf0e10cSrcweir     }
165*cdf0e10cSrcweir };
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir struct OOO_DLLPUBLIC_CHARTTOOLS PropertyLess : public ::std::binary_function<
168*cdf0e10cSrcweir         ::com::sun::star::beans::Property,
169*cdf0e10cSrcweir         ::com::sun::star::beans::Property,
170*cdf0e10cSrcweir         bool >
171*cdf0e10cSrcweir {
172*cdf0e10cSrcweir     bool operator() ( const ::com::sun::star::beans::Property & rFirst,
173*cdf0e10cSrcweir                       const ::com::sun::star::beans::Property & rSecond )
174*cdf0e10cSrcweir     {
175*cdf0e10cSrcweir         return ( rFirst.Name.compareTo( rSecond.Name ) < 0 );
176*cdf0e10cSrcweir     }
177*cdf0e10cSrcweir };
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir struct OOO_DLLPUBLIC_CHARTTOOLS PropertyValueNameEquals : public ::std::unary_function< ::com::sun::star::beans::PropertyValue, bool >
180*cdf0e10cSrcweir {
181*cdf0e10cSrcweir     explicit PropertyValueNameEquals( const ::rtl::OUString & rName ) :
182*cdf0e10cSrcweir             m_aName( rName )
183*cdf0e10cSrcweir     {}
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir     bool operator() ( const ::com::sun::star::beans::PropertyValue & rPropValue )
186*cdf0e10cSrcweir     {
187*cdf0e10cSrcweir         return rPropValue.Name.equals( m_aName );
188*cdf0e10cSrcweir     }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir private:
191*cdf0e10cSrcweir     ::rtl::OUString m_aName;
192*cdf0e10cSrcweir };
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir } //  namespace chart
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir // CHART_PROPERTYHELPER_HXX
197*cdf0e10cSrcweir #endif
198