merge the formfield patch from ooo-build
[ooovba.git] / chart2 / source / tools / ImplOPropertySet.cxx
blobffe94a407468e1b52a83c652fe24e930cab50e94
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ImplOPropertySet.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "ImplOPropertySet.hxx"
34 #include "CloneHelper.hxx"
36 #include <algorithm>
37 #include <functional>
38 #include <com/sun/star/beans/XFastPropertySet.hpp>
40 using namespace ::com::sun::star;
42 using ::rtl::OUString;
43 using ::com::sun::star::uno::Sequence;
44 using ::com::sun::star::uno::Reference;
45 using ::com::sun::star::uno::Any;
47 namespace
50 struct lcl_getPropertyStateByHandle :
51 public ::std::unary_function< sal_Int32, beans::PropertyState >
53 lcl_getPropertyStateByHandle(
54 const ::property::impl::ImplOPropertySet::tPropertyMap & rMap )
55 : m_rMap( rMap )
58 inline beans::PropertyState operator() ( sal_Int32 nHandle )
60 if( m_rMap.end() == m_rMap.find( nHandle ))
61 return beans::PropertyState_DEFAULT_VALUE;
62 return beans::PropertyState_DIRECT_VALUE;
65 private:
66 const ::property::impl::ImplOPropertySet::tPropertyMap & m_rMap;
69 template< typename K, typename V >
70 struct lcl_eraseMapEntry :
71 public ::std::unary_function< K, void >
73 lcl_eraseMapEntry( ::std::map< K, V > & rMap )
74 : m_rMap( rMap )
77 inline void operator() ( const K & aKey )
79 m_rMap.erase( aKey );
82 private:
83 ::std::map< K, V > m_rMap;
86 struct lcl_replaceInterfacePropertiesByClones :
87 public ::std::unary_function< ::property::impl::ImplOPropertySet::tPropertyMap::value_type, void >
89 inline void operator() ( ::property::impl::ImplOPropertySet::tPropertyMap::value_type & rProp )
91 if( rProp.second.hasValue() &&
92 rProp.second.getValueType().getTypeClass() == uno::TypeClass_INTERFACE )
94 Reference< util::XCloneable > xCloneable;
95 if( rProp.second >>= xCloneable )
96 rProp.second <<= xCloneable->createClone();
101 } // anonymous namespace
103 namespace property
105 namespace impl
108 ImplOPropertySet::ImplOPropertySet()
111 ImplOPropertySet::ImplOPropertySet( const ImplOPropertySet & rOther )
113 ::std::copy( rOther.m_aProperties.begin(), rOther.m_aProperties.end(),
114 ::std::inserter( m_aProperties, m_aProperties.begin() ));
115 cloneInterfaceProperties();
116 m_xStyle.set( ::chart::CloneHelper::CreateRefClone< Reference< style::XStyle > >()( rOther.m_xStyle ));
119 beans::PropertyState ImplOPropertySet::GetPropertyStateByHandle( sal_Int32 nHandle ) const
121 return lcl_getPropertyStateByHandle( m_aProperties ) ( nHandle );
124 Sequence< beans::PropertyState > ImplOPropertySet::GetPropertyStatesByHandle(
125 const ::std::vector< sal_Int32 > & aHandles ) const
127 Sequence< beans::PropertyState > aResult( aHandles.size());
129 ::std::transform( aHandles.begin(), aHandles.end(),
130 aResult.getArray(),
131 lcl_getPropertyStateByHandle( m_aProperties ));
133 return aResult;
136 void ImplOPropertySet::SetPropertyToDefault( sal_Int32 nHandle )
138 tPropertyMap::iterator aFoundIter( m_aProperties.find( nHandle ) );
140 if( m_aProperties.end() != aFoundIter )
142 m_aProperties.erase( aFoundIter );
146 void ImplOPropertySet::SetPropertiesToDefault(
147 const ::std::vector< sal_Int32 > & aHandles )
149 ::std::for_each( aHandles.begin(), aHandles.end(),
150 lcl_eraseMapEntry< sal_Int32, Any >( m_aProperties ) );
153 void ImplOPropertySet::SetAllPropertiesToDefault()
155 m_aProperties.clear();
158 bool ImplOPropertySet::GetPropertyValueByHandle(
159 Any & rValue,
160 sal_Int32 nHandle ) const
162 bool bResult = false;
164 tPropertyMap::const_iterator aFoundIter( m_aProperties.find( nHandle ) );
166 if( m_aProperties.end() != aFoundIter )
168 rValue = (*aFoundIter).second;
169 bResult = true;
172 return bResult;
175 void ImplOPropertySet::SetPropertyValueByHandle(
176 sal_Int32 nHandle, const Any & rValue, Any * pOldValue )
178 if( pOldValue != NULL )
180 tPropertyMap::const_iterator aFoundIter( m_aProperties.find( nHandle ) );
181 if( m_aProperties.end() != aFoundIter )
182 (*pOldValue) = (*aFoundIter).second;
185 m_aProperties[ nHandle ] = rValue;
188 bool ImplOPropertySet::SetStyle( const Reference< style::XStyle > & xStyle )
190 if( ! xStyle.is())
191 return false;
193 m_xStyle = xStyle;
194 return true;
197 Reference< style::XStyle > ImplOPropertySet::GetStyle() const
199 return m_xStyle;
202 void ImplOPropertySet::cloneInterfaceProperties()
204 ::std::for_each( m_aProperties.begin(), m_aProperties.end(),
205 lcl_replaceInterfacePropertiesByClones());
209 } // namespace impl
210 } // namespace chart