1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 #include "ImplOPropertySet.hxx"
31 #include "CloneHelper.hxx"
35 #include <com/sun/star/beans/XFastPropertySet.hpp>
37 using namespace ::com::sun::star
;
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
;
47 struct lcl_getPropertyStateByHandle
:
48 public ::std::unary_function
< sal_Int32
, beans::PropertyState
>
50 lcl_getPropertyStateByHandle(
51 const ::property::impl::ImplOPropertySet::tPropertyMap
& rMap
)
55 inline beans::PropertyState
operator() ( sal_Int32 nHandle
)
57 if( m_rMap
.end() == m_rMap
.find( nHandle
))
58 return beans::PropertyState_DEFAULT_VALUE
;
59 return beans::PropertyState_DIRECT_VALUE
;
63 const ::property::impl::ImplOPropertySet::tPropertyMap
& m_rMap
;
66 template< typename K
, typename V
>
67 struct lcl_eraseMapEntry
:
68 public ::std::unary_function
< K
, void >
70 lcl_eraseMapEntry( ::std::map
< K
, V
> & rMap
)
74 inline void operator() ( const K
& aKey
)
80 ::std::map
< K
, V
> m_rMap
;
83 struct lcl_replaceInterfacePropertiesByClones
:
84 public ::std::unary_function
< ::property::impl::ImplOPropertySet::tPropertyMap::value_type
, void >
86 inline void operator() ( ::property::impl::ImplOPropertySet::tPropertyMap::value_type
& rProp
)
88 if( rProp
.second
.hasValue() &&
89 rProp
.second
.getValueType().getTypeClass() == uno::TypeClass_INTERFACE
)
91 Reference
< util::XCloneable
> xCloneable
;
92 if( rProp
.second
>>= xCloneable
)
93 rProp
.second
<<= xCloneable
->createClone();
98 } // anonymous namespace
105 ImplOPropertySet::ImplOPropertySet()
108 ImplOPropertySet::ImplOPropertySet( const ImplOPropertySet
& rOther
)
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
));
116 beans::PropertyState
ImplOPropertySet::GetPropertyStateByHandle( sal_Int32 nHandle
) const
118 return lcl_getPropertyStateByHandle( m_aProperties
) ( nHandle
);
121 Sequence
< beans::PropertyState
> ImplOPropertySet::GetPropertyStatesByHandle(
122 const ::std::vector
< sal_Int32
> & aHandles
) const
124 Sequence
< beans::PropertyState
> aResult( aHandles
.size());
126 ::std::transform( aHandles
.begin(), aHandles
.end(),
128 lcl_getPropertyStateByHandle( m_aProperties
));
133 void ImplOPropertySet::SetPropertyToDefault( sal_Int32 nHandle
)
135 tPropertyMap::iterator
aFoundIter( m_aProperties
.find( nHandle
) );
137 if( m_aProperties
.end() != aFoundIter
)
139 m_aProperties
.erase( aFoundIter
);
143 void ImplOPropertySet::SetPropertiesToDefault(
144 const ::std::vector
< sal_Int32
> & aHandles
)
146 ::std::for_each( aHandles
.begin(), aHandles
.end(),
147 lcl_eraseMapEntry
< sal_Int32
, Any
>( m_aProperties
) );
150 void ImplOPropertySet::SetAllPropertiesToDefault()
152 m_aProperties
.clear();
155 bool ImplOPropertySet::GetPropertyValueByHandle(
157 sal_Int32 nHandle
) const
159 bool bResult
= false;
161 tPropertyMap::const_iterator
aFoundIter( m_aProperties
.find( nHandle
) );
163 if( m_aProperties
.end() != aFoundIter
)
165 rValue
= (*aFoundIter
).second
;
172 void ImplOPropertySet::SetPropertyValueByHandle(
173 sal_Int32 nHandle
, const Any
& rValue
, Any
* pOldValue
)
175 if( pOldValue
!= NULL
)
177 tPropertyMap::const_iterator
aFoundIter( m_aProperties
.find( nHandle
) );
178 if( m_aProperties
.end() != aFoundIter
)
179 (*pOldValue
) = (*aFoundIter
).second
;
182 m_aProperties
[ nHandle
] = rValue
;
185 bool ImplOPropertySet::SetStyle( const Reference
< style::XStyle
> & xStyle
)
194 Reference
< style::XStyle
> ImplOPropertySet::GetStyle() const
199 void ImplOPropertySet::cloneInterfaceProperties()
201 ::std::for_each( m_aProperties
.begin(), m_aProperties
.end(),
202 lcl_replaceInterfacePropertiesByClones());