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