1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef CHART_PROPERTYHELPER_HXX
24 #define CHART_PROPERTYHELPER_HXX
25 
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/beans/Property.hpp>
28 #include <com/sun/star/beans/PropertyValue.hpp>
29 #include <com/sun/star/uno/Any.hxx>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <comphelper/property.hxx>
32 #include <map>
33 #include "charttoolsdllapi.hxx"
34 
35 namespace chart
36 {
37 
38 typedef int tPropertyValueMapKey;
39 
40 typedef ::std::map< tPropertyValueMapKey, ::com::sun::star::uno::Any >
41     tPropertyValueMap;
42 
43 namespace PropertyHelper
44 {
45 
46 /** adds a line dash with a unique name to the gradient obtained by the given
47     factory.
48 
49     @return The name used for storing this element in the table
50 */
51 OOO_DLLPUBLIC_CHARTTOOLS ::rtl::OUString addLineDashUniqueNameToTable(
52     const ::com::sun::star::uno::Any & rValue,
53     const ::com::sun::star::uno::Reference<
54         ::com::sun::star::lang::XMultiServiceFactory > & xFact,
55     const ::rtl::OUString & rPreferredName );
56 
57 /** adds a gradient with a unique name to the gradient obtained by the given
58     factory.
59 
60     @return The name used for storing this element in the table
61 */
62 OOO_DLLPUBLIC_CHARTTOOLS ::rtl::OUString addGradientUniqueNameToTable(
63     const ::com::sun::star::uno::Any & rValue,
64     const ::com::sun::star::uno::Reference<
65         ::com::sun::star::lang::XMultiServiceFactory > & xFact,
66     const ::rtl::OUString & rPreferredName );
67 
68 /** adds a transparency gradient with a unique name to the gradient obtained
69     by the given factory.
70 
71     @return The name used for storing this element in the table
72 */
73 OOO_DLLPUBLIC_CHARTTOOLS
74 ::rtl::OUString addTransparencyGradientUniqueNameToTable(
75     const ::com::sun::star::uno::Any & rValue,
76     const ::com::sun::star::uno::Reference<
77         ::com::sun::star::lang::XMultiServiceFactory > & xFact,
78     const ::rtl::OUString & rPreferredName );
79 
80 /** adds a hatch with a unique name to the gradient obtained by the given
81     factory.
82 
83     @return The name used for storing this element in the table
84 */
85 OOO_DLLPUBLIC_CHARTTOOLS ::rtl::OUString addHatchUniqueNameToTable(
86     const ::com::sun::star::uno::Any & rValue,
87     const ::com::sun::star::uno::Reference<
88         ::com::sun::star::lang::XMultiServiceFactory > & xFact,
89     const ::rtl::OUString & rPreferredName );
90 
91 /** adds a bitmap with a unique name to the gradient obtained by the given
92     factory.
93 
94     @return The name used for storing this element in the table
95 */
96 OOO_DLLPUBLIC_CHARTTOOLS ::rtl::OUString addBitmapUniqueNameToTable(
97     const ::com::sun::star::uno::Any & rValue,
98     const ::com::sun::star::uno::Reference<
99         ::com::sun::star::lang::XMultiServiceFactory > & xFact,
100     const ::rtl::OUString & rPreferredName );
101 
102 // --------------------------------------------------------------------------------
103 
104 /** Set a property to a certain value in the given map.  This works for
105     properties that are already set, and those which are not yet in the map.
106 
107     @param any is the value encapsulated in the variant type Any
108  */
109 OOO_DLLPUBLIC_CHARTTOOLS
110 void setPropertyValueAny( tPropertyValueMap & rOutMap, tPropertyValueMapKey key,
111                           const ::com::sun::star::uno::Any & rAny );
112 
113 /** Set a property to a certain value in the given map.  This works for
114     properties that are already set, and those which are not yet in the map.
115 
116     @param value is the value of type Value that will be put into a variant type
117         Any before set in the property map.
118  */
119 template< typename Value >
setPropertyValue(tPropertyValueMap & rOutMap,tPropertyValueMapKey key,const Value & value)120     void setPropertyValue( tPropertyValueMap & rOutMap, tPropertyValueMapKey key, const Value & value )
121 {
122     setPropertyValueAny( rOutMap, key, ::com::sun::star::uno::makeAny( value ));
123 }
124 
125 template<>
126     void setPropertyValue< ::com::sun::star::uno::Any >( tPropertyValueMap & rOutMap, tPropertyValueMapKey key, const ::com::sun::star::uno::Any & rAny );
127 
128 OOO_DLLPUBLIC_CHARTTOOLS void setPropertyValueDefaultAny( tPropertyValueMap & rOutMap, tPropertyValueMapKey key, const ::com::sun::star::uno::Any & rAny );
129 
130 /** Calls setPropertyValue() but asserts that the given property hasn't been set
131     before.
132  */
133 template< typename Value >
setPropertyValueDefault(tPropertyValueMap & rOutMap,tPropertyValueMapKey key,const Value & value)134     void setPropertyValueDefault( tPropertyValueMap & rOutMap, tPropertyValueMapKey key, const Value & value )
135 {
136     setPropertyValueDefaultAny( rOutMap, key, ::com::sun::star::uno::makeAny( value ));
137 }
138 
139 /** Calls setPropertyValue() but asserts that the given property hasn't been set
140     before.
141  */
142 template<>
143     void setPropertyValueDefault< ::com::sun::star::uno::Any >( tPropertyValueMap & rOutMap, tPropertyValueMapKey key, const ::com::sun::star::uno::Any & rAny );
144 
145 /** Calls setPropertyValueDefault() with an empty Any as value
146  */
147 OOO_DLLPUBLIC_CHARTTOOLS void setEmptyPropertyValueDefault( tPropertyValueMap & rOutMap, tPropertyValueMapKey key );
148 
149 
150 } // namespace PropertyHelper
151 
152 // ================================================================================
153 
154 struct OOO_DLLPUBLIC_CHARTTOOLS PropertyNameLess
155 {
operator ()chart::PropertyNameLess156     inline bool operator() ( const ::com::sun::star::beans::Property & first,
157                              const ::com::sun::star::beans::Property & second )
158     {
159         return ( first.Name.compareTo( second.Name ) < 0 );
160     }
161 };
162 
163 struct OOO_DLLPUBLIC_CHARTTOOLS PropertyLess : public ::std::binary_function<
164         ::com::sun::star::beans::Property,
165         ::com::sun::star::beans::Property,
166         bool >
167 {
operator ()chart::PropertyLess168     bool operator() ( const ::com::sun::star::beans::Property & rFirst,
169                       const ::com::sun::star::beans::Property & rSecond )
170     {
171         return ( rFirst.Name.compareTo( rSecond.Name ) < 0 );
172     }
173 };
174 
175 struct OOO_DLLPUBLIC_CHARTTOOLS PropertyValueNameEquals : public ::std::unary_function< ::com::sun::star::beans::PropertyValue, bool >
176 {
PropertyValueNameEqualschart::PropertyValueNameEquals177     explicit PropertyValueNameEquals( const ::rtl::OUString & rName ) :
178             m_aName( rName )
179     {}
180 
operator ()chart::PropertyValueNameEquals181     bool operator() ( const ::com::sun::star::beans::PropertyValue & rPropValue )
182     {
183         return rPropValue.Name.equals( m_aName );
184     }
185 
186 private:
187     ::rtl::OUString m_aName;
188 };
189 
190 } //  namespace chart
191 
192 // CHART_PROPERTYHELPER_HXX
193 #endif
194