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