xref: /AOO41X/main/chart2/source/tools/ImplOPropertySet.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_chart2.hxx"
30*cdf0e10cSrcweir #include "ImplOPropertySet.hxx"
31*cdf0e10cSrcweir #include "CloneHelper.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <algorithm>
34*cdf0e10cSrcweir #include <functional>
35*cdf0e10cSrcweir #include <com/sun/star/beans/XFastPropertySet.hpp>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir using namespace ::com::sun::star;
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir using ::rtl::OUString;
40*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
41*cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
42*cdf0e10cSrcweir using ::com::sun::star::uno::Any;
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir namespace
45*cdf0e10cSrcweir {
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir struct lcl_getPropertyStateByHandle :
48*cdf0e10cSrcweir         public ::std::unary_function< sal_Int32,  beans::PropertyState >
49*cdf0e10cSrcweir {
50*cdf0e10cSrcweir     lcl_getPropertyStateByHandle(
51*cdf0e10cSrcweir         const ::property::impl::ImplOPropertySet::tPropertyMap & rMap )
52*cdf0e10cSrcweir             : m_rMap( rMap )
53*cdf0e10cSrcweir     {}
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir     inline beans::PropertyState operator() ( sal_Int32 nHandle )
56*cdf0e10cSrcweir     {
57*cdf0e10cSrcweir         if( m_rMap.end() == m_rMap.find( nHandle ))
58*cdf0e10cSrcweir             return beans::PropertyState_DEFAULT_VALUE;
59*cdf0e10cSrcweir         return beans::PropertyState_DIRECT_VALUE;
60*cdf0e10cSrcweir     }
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir private:
63*cdf0e10cSrcweir     const ::property::impl::ImplOPropertySet::tPropertyMap & m_rMap;
64*cdf0e10cSrcweir };
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir template< typename K, typename V >
67*cdf0e10cSrcweir struct lcl_eraseMapEntry :
68*cdf0e10cSrcweir         public ::std::unary_function< K, void >
69*cdf0e10cSrcweir {
70*cdf0e10cSrcweir     lcl_eraseMapEntry( ::std::map< K, V > & rMap )
71*cdf0e10cSrcweir             : m_rMap( rMap )
72*cdf0e10cSrcweir     {}
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir     inline void operator() ( const K & aKey )
75*cdf0e10cSrcweir     {
76*cdf0e10cSrcweir         m_rMap.erase( aKey );
77*cdf0e10cSrcweir     }
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir private:
80*cdf0e10cSrcweir     ::std::map< K, V > m_rMap;
81*cdf0e10cSrcweir };
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir struct lcl_replaceInterfacePropertiesByClones :
84*cdf0e10cSrcweir     public ::std::unary_function< ::property::impl::ImplOPropertySet::tPropertyMap::value_type, void >
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir     inline void operator() ( ::property::impl::ImplOPropertySet::tPropertyMap::value_type & rProp )
87*cdf0e10cSrcweir     {
88*cdf0e10cSrcweir         if( rProp.second.hasValue() &&
89*cdf0e10cSrcweir             rProp.second.getValueType().getTypeClass() == uno::TypeClass_INTERFACE )
90*cdf0e10cSrcweir         {
91*cdf0e10cSrcweir             Reference< util::XCloneable > xCloneable;
92*cdf0e10cSrcweir             if( rProp.second >>= xCloneable )
93*cdf0e10cSrcweir                 rProp.second <<= xCloneable->createClone();
94*cdf0e10cSrcweir         }
95*cdf0e10cSrcweir     }
96*cdf0e10cSrcweir };
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir } //  anonymous namespace
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir namespace property
101*cdf0e10cSrcweir {
102*cdf0e10cSrcweir namespace impl
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir ImplOPropertySet::ImplOPropertySet()
106*cdf0e10cSrcweir {}
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir ImplOPropertySet::ImplOPropertySet( const ImplOPropertySet & rOther )
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir     ::std::copy( rOther.m_aProperties.begin(), rOther.m_aProperties.end(),
111*cdf0e10cSrcweir                  ::std::inserter( m_aProperties, m_aProperties.begin() ));
112*cdf0e10cSrcweir     cloneInterfaceProperties();
113*cdf0e10cSrcweir     m_xStyle.set( ::chart::CloneHelper::CreateRefClone< Reference< style::XStyle > >()( rOther.m_xStyle ));
114*cdf0e10cSrcweir }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir beans::PropertyState ImplOPropertySet::GetPropertyStateByHandle( sal_Int32 nHandle ) const
117*cdf0e10cSrcweir {
118*cdf0e10cSrcweir     return lcl_getPropertyStateByHandle( m_aProperties ) ( nHandle );
119*cdf0e10cSrcweir }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir Sequence< beans::PropertyState > ImplOPropertySet::GetPropertyStatesByHandle(
122*cdf0e10cSrcweir     const ::std::vector< sal_Int32 > & aHandles ) const
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir     Sequence< beans::PropertyState > aResult( aHandles.size());
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir     ::std::transform( aHandles.begin(), aHandles.end(),
127*cdf0e10cSrcweir                       aResult.getArray(),
128*cdf0e10cSrcweir                       lcl_getPropertyStateByHandle( m_aProperties ));
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir     return aResult;
131*cdf0e10cSrcweir }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir void ImplOPropertySet::SetPropertyToDefault( sal_Int32 nHandle )
134*cdf0e10cSrcweir {
135*cdf0e10cSrcweir     tPropertyMap::iterator aFoundIter( m_aProperties.find( nHandle ) );
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir     if( m_aProperties.end() != aFoundIter )
138*cdf0e10cSrcweir     {
139*cdf0e10cSrcweir         m_aProperties.erase( aFoundIter );
140*cdf0e10cSrcweir     }
141*cdf0e10cSrcweir }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir void ImplOPropertySet::SetPropertiesToDefault(
144*cdf0e10cSrcweir     const ::std::vector< sal_Int32 > & aHandles )
145*cdf0e10cSrcweir {
146*cdf0e10cSrcweir     ::std::for_each( aHandles.begin(), aHandles.end(),
147*cdf0e10cSrcweir                      lcl_eraseMapEntry< sal_Int32, Any >( m_aProperties ) );
148*cdf0e10cSrcweir }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir void ImplOPropertySet::SetAllPropertiesToDefault()
151*cdf0e10cSrcweir {
152*cdf0e10cSrcweir     m_aProperties.clear();
153*cdf0e10cSrcweir }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir bool ImplOPropertySet::GetPropertyValueByHandle(
156*cdf0e10cSrcweir     Any & rValue,
157*cdf0e10cSrcweir     sal_Int32 nHandle ) const
158*cdf0e10cSrcweir {
159*cdf0e10cSrcweir     bool bResult = false;
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir     tPropertyMap::const_iterator aFoundIter( m_aProperties.find( nHandle ) );
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir     if( m_aProperties.end() != aFoundIter )
164*cdf0e10cSrcweir     {
165*cdf0e10cSrcweir         rValue = (*aFoundIter).second;
166*cdf0e10cSrcweir         bResult = true;
167*cdf0e10cSrcweir     }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir     return bResult;
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir void ImplOPropertySet::SetPropertyValueByHandle(
173*cdf0e10cSrcweir     sal_Int32 nHandle, const Any & rValue, Any * pOldValue )
174*cdf0e10cSrcweir {
175*cdf0e10cSrcweir     if( pOldValue != NULL )
176*cdf0e10cSrcweir     {
177*cdf0e10cSrcweir         tPropertyMap::const_iterator aFoundIter( m_aProperties.find( nHandle ) );
178*cdf0e10cSrcweir         if( m_aProperties.end() != aFoundIter )
179*cdf0e10cSrcweir             (*pOldValue) = (*aFoundIter).second;
180*cdf0e10cSrcweir     }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir     m_aProperties[ nHandle ] = rValue;
183*cdf0e10cSrcweir }
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir bool ImplOPropertySet::SetStyle( const Reference< style::XStyle > & xStyle )
186*cdf0e10cSrcweir {
187*cdf0e10cSrcweir     if( ! xStyle.is())
188*cdf0e10cSrcweir         return false;
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir     m_xStyle = xStyle;
191*cdf0e10cSrcweir     return true;
192*cdf0e10cSrcweir }
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir Reference< style::XStyle > ImplOPropertySet::GetStyle() const
195*cdf0e10cSrcweir {
196*cdf0e10cSrcweir     return m_xStyle;
197*cdf0e10cSrcweir }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir void ImplOPropertySet::cloneInterfaceProperties()
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir     ::std::for_each( m_aProperties.begin(), m_aProperties.end(),
202*cdf0e10cSrcweir                      lcl_replaceInterfacePropertiesByClones());
203*cdf0e10cSrcweir }
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir } //  namespace impl
207*cdf0e10cSrcweir } //  namespace chart
208