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