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 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_chart2.hxx" 30 #include "ImplOPropertySet.hxx" 31 #include "CloneHelper.hxx" 32 33 #include <algorithm> 34 #include <functional> 35 #include <com/sun/star/beans/XFastPropertySet.hpp> 36 37 using namespace ::com::sun::star; 38 39 using ::rtl::OUString; 40 using ::com::sun::star::uno::Sequence; 41 using ::com::sun::star::uno::Reference; 42 using ::com::sun::star::uno::Any; 43 44 namespace 45 { 46 47 struct lcl_getPropertyStateByHandle : 48 public ::std::unary_function< sal_Int32, beans::PropertyState > 49 { 50 lcl_getPropertyStateByHandle( 51 const ::property::impl::ImplOPropertySet::tPropertyMap & rMap ) 52 : m_rMap( rMap ) 53 {} 54 55 inline beans::PropertyState operator() ( sal_Int32 nHandle ) 56 { 57 if( m_rMap.end() == m_rMap.find( nHandle )) 58 return beans::PropertyState_DEFAULT_VALUE; 59 return beans::PropertyState_DIRECT_VALUE; 60 } 61 62 private: 63 const ::property::impl::ImplOPropertySet::tPropertyMap & m_rMap; 64 }; 65 66 template< typename K, typename V > 67 struct lcl_eraseMapEntry : 68 public ::std::unary_function< K, void > 69 { 70 lcl_eraseMapEntry( ::std::map< K, V > & rMap ) 71 : m_rMap( rMap ) 72 {} 73 74 inline void operator() ( const K & aKey ) 75 { 76 m_rMap.erase( aKey ); 77 } 78 79 private: 80 ::std::map< K, V > m_rMap; 81 }; 82 83 struct lcl_replaceInterfacePropertiesByClones : 84 public ::std::unary_function< ::property::impl::ImplOPropertySet::tPropertyMap::value_type, void > 85 { 86 inline void operator() ( ::property::impl::ImplOPropertySet::tPropertyMap::value_type & rProp ) 87 { 88 if( rProp.second.hasValue() && 89 rProp.second.getValueType().getTypeClass() == uno::TypeClass_INTERFACE ) 90 { 91 Reference< util::XCloneable > xCloneable; 92 if( rProp.second >>= xCloneable ) 93 rProp.second <<= xCloneable->createClone(); 94 } 95 } 96 }; 97 98 } // anonymous namespace 99 100 namespace property 101 { 102 namespace impl 103 { 104 105 ImplOPropertySet::ImplOPropertySet() 106 {} 107 108 ImplOPropertySet::ImplOPropertySet( const ImplOPropertySet & rOther ) 109 { 110 ::std::copy( rOther.m_aProperties.begin(), rOther.m_aProperties.end(), 111 ::std::inserter( m_aProperties, m_aProperties.begin() )); 112 cloneInterfaceProperties(); 113 m_xStyle.set( ::chart::CloneHelper::CreateRefClone< Reference< style::XStyle > >()( rOther.m_xStyle )); 114 } 115 116 beans::PropertyState ImplOPropertySet::GetPropertyStateByHandle( sal_Int32 nHandle ) const 117 { 118 return lcl_getPropertyStateByHandle( m_aProperties ) ( nHandle ); 119 } 120 121 Sequence< beans::PropertyState > ImplOPropertySet::GetPropertyStatesByHandle( 122 const ::std::vector< sal_Int32 > & aHandles ) const 123 { 124 Sequence< beans::PropertyState > aResult( aHandles.size()); 125 126 ::std::transform( aHandles.begin(), aHandles.end(), 127 aResult.getArray(), 128 lcl_getPropertyStateByHandle( m_aProperties )); 129 130 return aResult; 131 } 132 133 void ImplOPropertySet::SetPropertyToDefault( sal_Int32 nHandle ) 134 { 135 tPropertyMap::iterator aFoundIter( m_aProperties.find( nHandle ) ); 136 137 if( m_aProperties.end() != aFoundIter ) 138 { 139 m_aProperties.erase( aFoundIter ); 140 } 141 } 142 143 void ImplOPropertySet::SetPropertiesToDefault( 144 const ::std::vector< sal_Int32 > & aHandles ) 145 { 146 ::std::for_each( aHandles.begin(), aHandles.end(), 147 lcl_eraseMapEntry< sal_Int32, Any >( m_aProperties ) ); 148 } 149 150 void ImplOPropertySet::SetAllPropertiesToDefault() 151 { 152 m_aProperties.clear(); 153 } 154 155 bool ImplOPropertySet::GetPropertyValueByHandle( 156 Any & rValue, 157 sal_Int32 nHandle ) const 158 { 159 bool bResult = false; 160 161 tPropertyMap::const_iterator aFoundIter( m_aProperties.find( nHandle ) ); 162 163 if( m_aProperties.end() != aFoundIter ) 164 { 165 rValue = (*aFoundIter).second; 166 bResult = true; 167 } 168 169 return bResult; 170 } 171 172 void ImplOPropertySet::SetPropertyValueByHandle( 173 sal_Int32 nHandle, const Any & rValue, Any * pOldValue ) 174 { 175 if( pOldValue != NULL ) 176 { 177 tPropertyMap::const_iterator aFoundIter( m_aProperties.find( nHandle ) ); 178 if( m_aProperties.end() != aFoundIter ) 179 (*pOldValue) = (*aFoundIter).second; 180 } 181 182 m_aProperties[ nHandle ] = rValue; 183 } 184 185 bool ImplOPropertySet::SetStyle( const Reference< style::XStyle > & xStyle ) 186 { 187 if( ! xStyle.is()) 188 return false; 189 190 m_xStyle = xStyle; 191 return true; 192 } 193 194 Reference< style::XStyle > ImplOPropertySet::GetStyle() const 195 { 196 return m_xStyle; 197 } 198 199 void ImplOPropertySet::cloneInterfaceProperties() 200 { 201 ::std::for_each( m_aProperties.begin(), m_aProperties.end(), 202 lcl_replaceInterfacePropertiesByClones()); 203 } 204 205 206 } // namespace impl 207 } // namespace chart 208