1*cde9e8dcSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*cde9e8dcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*cde9e8dcSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*cde9e8dcSAndrew Rist * distributed with this work for additional information 6*cde9e8dcSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*cde9e8dcSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*cde9e8dcSAndrew Rist * "License"); you may not use this file except in compliance 9*cde9e8dcSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*cde9e8dcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*cde9e8dcSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*cde9e8dcSAndrew Rist * software distributed under the License is distributed on an 15*cde9e8dcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*cde9e8dcSAndrew Rist * KIND, either express or implied. See the License for the 17*cde9e8dcSAndrew Rist * specific language governing permissions and limitations 18*cde9e8dcSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*cde9e8dcSAndrew Rist *************************************************************/ 21*cde9e8dcSAndrew Rist 22*cde9e8dcSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_chart2.hxx" 26cdf0e10cSrcweir #include "ImplOPropertySet.hxx" 27cdf0e10cSrcweir #include "CloneHelper.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <algorithm> 30cdf0e10cSrcweir #include <functional> 31cdf0e10cSrcweir #include <com/sun/star/beans/XFastPropertySet.hpp> 32cdf0e10cSrcweir 33cdf0e10cSrcweir using namespace ::com::sun::star; 34cdf0e10cSrcweir 35cdf0e10cSrcweir using ::rtl::OUString; 36cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 37cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 38cdf0e10cSrcweir using ::com::sun::star::uno::Any; 39cdf0e10cSrcweir 40cdf0e10cSrcweir namespace 41cdf0e10cSrcweir { 42cdf0e10cSrcweir 43cdf0e10cSrcweir struct lcl_getPropertyStateByHandle : 44cdf0e10cSrcweir public ::std::unary_function< sal_Int32, beans::PropertyState > 45cdf0e10cSrcweir { 46cdf0e10cSrcweir lcl_getPropertyStateByHandle( 47cdf0e10cSrcweir const ::property::impl::ImplOPropertySet::tPropertyMap & rMap ) 48cdf0e10cSrcweir : m_rMap( rMap ) 49cdf0e10cSrcweir {} 50cdf0e10cSrcweir 51cdf0e10cSrcweir inline beans::PropertyState operator() ( sal_Int32 nHandle ) 52cdf0e10cSrcweir { 53cdf0e10cSrcweir if( m_rMap.end() == m_rMap.find( nHandle )) 54cdf0e10cSrcweir return beans::PropertyState_DEFAULT_VALUE; 55cdf0e10cSrcweir return beans::PropertyState_DIRECT_VALUE; 56cdf0e10cSrcweir } 57cdf0e10cSrcweir 58cdf0e10cSrcweir private: 59cdf0e10cSrcweir const ::property::impl::ImplOPropertySet::tPropertyMap & m_rMap; 60cdf0e10cSrcweir }; 61cdf0e10cSrcweir 62cdf0e10cSrcweir template< typename K, typename V > 63cdf0e10cSrcweir struct lcl_eraseMapEntry : 64cdf0e10cSrcweir public ::std::unary_function< K, void > 65cdf0e10cSrcweir { 66cdf0e10cSrcweir lcl_eraseMapEntry( ::std::map< K, V > & rMap ) 67cdf0e10cSrcweir : m_rMap( rMap ) 68cdf0e10cSrcweir {} 69cdf0e10cSrcweir 70cdf0e10cSrcweir inline void operator() ( const K & aKey ) 71cdf0e10cSrcweir { 72cdf0e10cSrcweir m_rMap.erase( aKey ); 73cdf0e10cSrcweir } 74cdf0e10cSrcweir 75cdf0e10cSrcweir private: 76cdf0e10cSrcweir ::std::map< K, V > m_rMap; 77cdf0e10cSrcweir }; 78cdf0e10cSrcweir 79cdf0e10cSrcweir struct lcl_replaceInterfacePropertiesByClones : 80cdf0e10cSrcweir public ::std::unary_function< ::property::impl::ImplOPropertySet::tPropertyMap::value_type, void > 81cdf0e10cSrcweir { 82cdf0e10cSrcweir inline void operator() ( ::property::impl::ImplOPropertySet::tPropertyMap::value_type & rProp ) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir if( rProp.second.hasValue() && 85cdf0e10cSrcweir rProp.second.getValueType().getTypeClass() == uno::TypeClass_INTERFACE ) 86cdf0e10cSrcweir { 87cdf0e10cSrcweir Reference< util::XCloneable > xCloneable; 88cdf0e10cSrcweir if( rProp.second >>= xCloneable ) 89cdf0e10cSrcweir rProp.second <<= xCloneable->createClone(); 90cdf0e10cSrcweir } 91cdf0e10cSrcweir } 92cdf0e10cSrcweir }; 93cdf0e10cSrcweir 94cdf0e10cSrcweir } // anonymous namespace 95cdf0e10cSrcweir 96cdf0e10cSrcweir namespace property 97cdf0e10cSrcweir { 98cdf0e10cSrcweir namespace impl 99cdf0e10cSrcweir { 100cdf0e10cSrcweir 101cdf0e10cSrcweir ImplOPropertySet::ImplOPropertySet() 102cdf0e10cSrcweir {} 103cdf0e10cSrcweir 104cdf0e10cSrcweir ImplOPropertySet::ImplOPropertySet( const ImplOPropertySet & rOther ) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir ::std::copy( rOther.m_aProperties.begin(), rOther.m_aProperties.end(), 107cdf0e10cSrcweir ::std::inserter( m_aProperties, m_aProperties.begin() )); 108cdf0e10cSrcweir cloneInterfaceProperties(); 109cdf0e10cSrcweir m_xStyle.set( ::chart::CloneHelper::CreateRefClone< Reference< style::XStyle > >()( rOther.m_xStyle )); 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir beans::PropertyState ImplOPropertySet::GetPropertyStateByHandle( sal_Int32 nHandle ) const 113cdf0e10cSrcweir { 114cdf0e10cSrcweir return lcl_getPropertyStateByHandle( m_aProperties ) ( nHandle ); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir Sequence< beans::PropertyState > ImplOPropertySet::GetPropertyStatesByHandle( 118cdf0e10cSrcweir const ::std::vector< sal_Int32 > & aHandles ) const 119cdf0e10cSrcweir { 120cdf0e10cSrcweir Sequence< beans::PropertyState > aResult( aHandles.size()); 121cdf0e10cSrcweir 122cdf0e10cSrcweir ::std::transform( aHandles.begin(), aHandles.end(), 123cdf0e10cSrcweir aResult.getArray(), 124cdf0e10cSrcweir lcl_getPropertyStateByHandle( m_aProperties )); 125cdf0e10cSrcweir 126cdf0e10cSrcweir return aResult; 127cdf0e10cSrcweir } 128cdf0e10cSrcweir 129cdf0e10cSrcweir void ImplOPropertySet::SetPropertyToDefault( sal_Int32 nHandle ) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir tPropertyMap::iterator aFoundIter( m_aProperties.find( nHandle ) ); 132cdf0e10cSrcweir 133cdf0e10cSrcweir if( m_aProperties.end() != aFoundIter ) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir m_aProperties.erase( aFoundIter ); 136cdf0e10cSrcweir } 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 139cdf0e10cSrcweir void ImplOPropertySet::SetPropertiesToDefault( 140cdf0e10cSrcweir const ::std::vector< sal_Int32 > & aHandles ) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir ::std::for_each( aHandles.begin(), aHandles.end(), 143cdf0e10cSrcweir lcl_eraseMapEntry< sal_Int32, Any >( m_aProperties ) ); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir void ImplOPropertySet::SetAllPropertiesToDefault() 147cdf0e10cSrcweir { 148cdf0e10cSrcweir m_aProperties.clear(); 149cdf0e10cSrcweir } 150cdf0e10cSrcweir 151cdf0e10cSrcweir bool ImplOPropertySet::GetPropertyValueByHandle( 152cdf0e10cSrcweir Any & rValue, 153cdf0e10cSrcweir sal_Int32 nHandle ) const 154cdf0e10cSrcweir { 155cdf0e10cSrcweir bool bResult = false; 156cdf0e10cSrcweir 157cdf0e10cSrcweir tPropertyMap::const_iterator aFoundIter( m_aProperties.find( nHandle ) ); 158cdf0e10cSrcweir 159cdf0e10cSrcweir if( m_aProperties.end() != aFoundIter ) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir rValue = (*aFoundIter).second; 162cdf0e10cSrcweir bResult = true; 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir return bResult; 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir void ImplOPropertySet::SetPropertyValueByHandle( 169cdf0e10cSrcweir sal_Int32 nHandle, const Any & rValue, Any * pOldValue ) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir if( pOldValue != NULL ) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir tPropertyMap::const_iterator aFoundIter( m_aProperties.find( nHandle ) ); 174cdf0e10cSrcweir if( m_aProperties.end() != aFoundIter ) 175cdf0e10cSrcweir (*pOldValue) = (*aFoundIter).second; 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir m_aProperties[ nHandle ] = rValue; 179cdf0e10cSrcweir } 180cdf0e10cSrcweir 181cdf0e10cSrcweir bool ImplOPropertySet::SetStyle( const Reference< style::XStyle > & xStyle ) 182cdf0e10cSrcweir { 183cdf0e10cSrcweir if( ! xStyle.is()) 184cdf0e10cSrcweir return false; 185cdf0e10cSrcweir 186cdf0e10cSrcweir m_xStyle = xStyle; 187cdf0e10cSrcweir return true; 188cdf0e10cSrcweir } 189cdf0e10cSrcweir 190cdf0e10cSrcweir Reference< style::XStyle > ImplOPropertySet::GetStyle() const 191cdf0e10cSrcweir { 192cdf0e10cSrcweir return m_xStyle; 193cdf0e10cSrcweir } 194cdf0e10cSrcweir 195cdf0e10cSrcweir void ImplOPropertySet::cloneInterfaceProperties() 196cdf0e10cSrcweir { 197cdf0e10cSrcweir ::std::for_each( m_aProperties.begin(), m_aProperties.end(), 198cdf0e10cSrcweir lcl_replaceInterfacePropertiesByClones()); 199cdf0e10cSrcweir } 200cdf0e10cSrcweir 201cdf0e10cSrcweir 202cdf0e10cSrcweir } // namespace impl 203cdf0e10cSrcweir } // namespace chart 204