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