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 {
46 typedef sal_Int32 argument_type;
47 typedef beans::PropertyState result_type;
lcl_getPropertyStateByHandle__anonc39fe63c0111::lcl_getPropertyStateByHandle48 lcl_getPropertyStateByHandle(
49 const ::property::impl::ImplOPropertySet::tPropertyMap & rMap )
50 : m_rMap( rMap )
51 {}
52
operator ()__anonc39fe63c0111::lcl_getPropertyStateByHandle53 inline beans::PropertyState operator() ( sal_Int32 nHandle )
54 {
55 if( m_rMap.end() == m_rMap.find( nHandle ))
56 return beans::PropertyState_DEFAULT_VALUE;
57 return beans::PropertyState_DIRECT_VALUE;
58 }
59
60 private:
61 const ::property::impl::ImplOPropertySet::tPropertyMap & m_rMap;
62 };
63
64 template< typename K, typename V >
65 struct lcl_eraseMapEntry
66 {
67 typedef K argument_type;
68 typedef void result_type;
lcl_eraseMapEntry__anonc39fe63c0111::lcl_eraseMapEntry69 lcl_eraseMapEntry( ::std::map< K, V > & rMap )
70 : m_rMap( rMap )
71 {}
72
operator ()__anonc39fe63c0111::lcl_eraseMapEntry73 inline void operator() ( const K & aKey )
74 {
75 m_rMap.erase( aKey );
76 }
77
78 private:
79 ::std::map< K, V > m_rMap;
80 };
81
82 struct lcl_replaceInterfacePropertiesByClones
83 {
84 typedef ::property::impl::ImplOPropertySet::tPropertyMap::value_type argument_type;
85 typedef void result_type;
operator ()__anonc39fe63c0111::lcl_replaceInterfacePropertiesByClones86 inline void operator() ( ::property::impl::ImplOPropertySet::tPropertyMap::value_type & rProp )
87 {
88 if( rProp.second.hasValue() &&
89 rProp.second.getValueType().getTypeClass() == uno::TypeClass_INTERFACE )
90 {
91 Reference< util::XCloneable > xCloneable;
92 if( rProp.second >>= xCloneable )
93 rProp.second <<= xCloneable->createClone();
94 }
95 }
96 };
97
98 } // anonymous namespace
99
100 namespace property
101 {
102 namespace impl
103 {
104
ImplOPropertySet()105 ImplOPropertySet::ImplOPropertySet()
106 {}
107
ImplOPropertySet(const ImplOPropertySet & rOther)108 ImplOPropertySet::ImplOPropertySet( const ImplOPropertySet & rOther )
109 {
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 ));
114 }
115
GetPropertyStateByHandle(sal_Int32 nHandle) const116 beans::PropertyState ImplOPropertySet::GetPropertyStateByHandle( sal_Int32 nHandle ) const
117 {
118 return lcl_getPropertyStateByHandle( m_aProperties ) ( nHandle );
119 }
120
GetPropertyStatesByHandle(const::std::vector<sal_Int32> & aHandles) const121 Sequence< beans::PropertyState > ImplOPropertySet::GetPropertyStatesByHandle(
122 const ::std::vector< sal_Int32 > & aHandles ) const
123 {
124 Sequence< beans::PropertyState > aResult( aHandles.size());
125
126 ::std::transform( aHandles.begin(), aHandles.end(),
127 aResult.getArray(),
128 lcl_getPropertyStateByHandle( m_aProperties ));
129
130 return aResult;
131 }
132
SetPropertyToDefault(sal_Int32 nHandle)133 void ImplOPropertySet::SetPropertyToDefault( sal_Int32 nHandle )
134 {
135 tPropertyMap::iterator aFoundIter( m_aProperties.find( nHandle ) );
136
137 if( m_aProperties.end() != aFoundIter )
138 {
139 m_aProperties.erase( aFoundIter );
140 }
141 }
142
SetPropertiesToDefault(const::std::vector<sal_Int32> & aHandles)143 void ImplOPropertySet::SetPropertiesToDefault(
144 const ::std::vector< sal_Int32 > & aHandles )
145 {
146 ::std::for_each( aHandles.begin(), aHandles.end(),
147 lcl_eraseMapEntry< sal_Int32, Any >( m_aProperties ) );
148 }
149
SetAllPropertiesToDefault()150 void ImplOPropertySet::SetAllPropertiesToDefault()
151 {
152 m_aProperties.clear();
153 }
154
GetPropertyValueByHandle(Any & rValue,sal_Int32 nHandle) const155 bool ImplOPropertySet::GetPropertyValueByHandle(
156 Any & rValue,
157 sal_Int32 nHandle ) const
158 {
159 bool bResult = false;
160
161 tPropertyMap::const_iterator aFoundIter( m_aProperties.find( nHandle ) );
162
163 if( m_aProperties.end() != aFoundIter )
164 {
165 rValue = (*aFoundIter).second;
166 bResult = true;
167 }
168
169 return bResult;
170 }
171
SetPropertyValueByHandle(sal_Int32 nHandle,const Any & rValue,Any * pOldValue)172 void ImplOPropertySet::SetPropertyValueByHandle(
173 sal_Int32 nHandle, const Any & rValue, Any * pOldValue )
174 {
175 if( pOldValue != NULL )
176 {
177 tPropertyMap::const_iterator aFoundIter( m_aProperties.find( nHandle ) );
178 if( m_aProperties.end() != aFoundIter )
179 (*pOldValue) = (*aFoundIter).second;
180 }
181
182 m_aProperties[ nHandle ] = rValue;
183 }
184
SetStyle(const Reference<style::XStyle> & xStyle)185 bool ImplOPropertySet::SetStyle( const Reference< style::XStyle > & xStyle )
186 {
187 if( ! xStyle.is())
188 return false;
189
190 m_xStyle = xStyle;
191 return true;
192 }
193
GetStyle() const194 Reference< style::XStyle > ImplOPropertySet::GetStyle() const
195 {
196 return m_xStyle;
197 }
198
cloneInterfaceProperties()199 void ImplOPropertySet::cloneInterfaceProperties()
200 {
201 ::std::for_each( m_aProperties.begin(), m_aProperties.end(),
202 lcl_replaceInterfacePropertiesByClones());
203 }
204
205
206 } // namespace impl
207 } // namespace chart
208