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 <svx/sdasitm.hxx>
21 : #include <svx/svdattr.hxx>
22 :
23 : using namespace ::std;
24 : using namespace com::sun::star;
25 :
26 394 : SdrCustomShapeEngineItem::SdrCustomShapeEngineItem()
27 394 : : SfxStringItem( SDRATTR_CUSTOMSHAPE_ENGINE, String() )
28 394 : {}
29 :
30 394 : SdrCustomShapeDataItem::SdrCustomShapeDataItem()
31 394 : : SfxStringItem( SDRATTR_CUSTOMSHAPE_DATA, String() )
32 394 : {}
33 :
34 13863 : bool SdrCustomShapeGeometryItem::PropertyEq::operator()( const rtl::OUString& r1, const rtl::OUString& r2 ) const
35 : {
36 13863 : return r1.equals( r2 );
37 : }
38 1186 : bool SdrCustomShapeGeometryItem::PropertyPairEq::operator()( const SdrCustomShapeGeometryItem::PropertyPair& r1, const SdrCustomShapeGeometryItem::PropertyPair& r2 ) const
39 : {
40 1186 : return ( r1.first.equals( r2.first ) ) && ( r1.second.equals( r2.second ) );
41 : }
42 11693 : size_t SdrCustomShapeGeometryItem::PropertyPairHash::operator()( const SdrCustomShapeGeometryItem::PropertyPair &r1 ) const
43 : {
44 11693 : return (size_t)r1.first.hashCode() + r1.second.hashCode();
45 : };
46 :
47 37555 : TYPEINIT1_FACTORY( SdrCustomShapeGeometryItem, SfxPoolItem , new SdrCustomShapeGeometryItem);
48 394 : SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem()
49 394 : : SfxPoolItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )
50 394 : {}
51 3621 : SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem( const uno::Sequence< beans::PropertyValue >& rVal )
52 3621 : : SfxPoolItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )
53 : {
54 : sal_Int32 i, j;
55 3621 : aPropSeq = rVal;
56 :
57 8092 : for ( i = 0; i < aPropSeq.getLength(); i++ )
58 : {
59 4471 : beans::PropertyValue& rPropVal = aPropSeq[ i ];
60 4471 : aPropHashMap[ rPropVal.Name ] = i;
61 4471 : if ( rPropVal.Value.getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
62 : {
63 260 : uno::Sequence< beans::PropertyValue >& rPropSeq = *( uno::Sequence< beans::PropertyValue >*)rPropVal.Value.getValue();
64 845 : for ( j = 0; j < rPropSeq.getLength(); j++ )
65 : {
66 585 : beans::PropertyValue& rPropVal2 = rPropSeq[ j ];
67 585 : aPropPairHashMap[ PropertyPair( rPropVal.Name, rPropVal2.Name ) ] = j;
68 : }
69 : }
70 : }
71 3621 : }
72 :
73 25351 : com::sun::star::uno::Any* SdrCustomShapeGeometryItem::GetPropertyValueByName( const rtl::OUString& rPropName )
74 : {
75 25351 : com::sun::star::uno::Any* pRet = NULL;
76 25351 : PropertyHashMap::iterator aHashIter( aPropHashMap.find( rPropName ) );
77 25351 : if ( aHashIter != aPropHashMap.end() )
78 13863 : pRet = &aPropSeq[ (*aHashIter).second ].Value;
79 25351 : return pRet;
80 : }
81 :
82 11858 : com::sun::star::uno::Any* SdrCustomShapeGeometryItem::GetPropertyValueByName( const rtl::OUString& rSequenceName, const rtl::OUString& rPropName )
83 : {
84 11858 : com::sun::star::uno::Any* pRet = NULL;
85 11858 : com::sun::star::uno::Any* pSeqAny = GetPropertyValueByName( rSequenceName );
86 11858 : if ( pSeqAny )
87 : {
88 10007 : if ( pSeqAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
89 : {
90 10007 : PropertyPairHashMap::iterator aHashIter( aPropPairHashMap.find( PropertyPair( rSequenceName, rPropName ) ) );
91 10007 : if ( aHashIter != aPropPairHashMap.end() )
92 : {
93 : ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
94 1186 : *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pSeqAny->getValue());
95 1186 : pRet = &rSecSequence[ (*aHashIter).second ].Value;
96 : }
97 : }
98 : }
99 11858 : return pRet;
100 : }
101 :
102 1762 : void SdrCustomShapeGeometryItem::SetPropertyValue( const com::sun::star::beans::PropertyValue& rPropVal )
103 : {
104 1762 : com::sun::star::uno::Any* pAny = GetPropertyValueByName( rPropVal.Name );
105 1762 : if ( pAny )
106 : { // property is already available
107 : sal_Int32 i;
108 71 : if ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
109 : { // old property is a sequence->each entry has to be removed from the HashPairMap
110 : ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
111 0 : *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pAny->getValue());
112 0 : for ( i = 0; i < rSecSequence.getLength(); i++ )
113 : {
114 0 : PropertyPairHashMap::iterator aHashIter( aPropPairHashMap.find( PropertyPair( rPropVal.Name, rSecSequence[ i ].Name ) ) );
115 0 : if ( aHashIter != aPropPairHashMap.end() )
116 0 : aPropPairHashMap.erase( aHashIter );
117 : }
118 : }
119 71 : *pAny = rPropVal.Value;
120 71 : if ( rPropVal.Value.getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
121 : { // the new property is a sequence->each entry has to be inserted into the HashPairMap
122 : ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
123 0 : *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pAny->getValue());
124 0 : for ( i = 0; i < rSecSequence.getLength(); i++ )
125 : {
126 0 : beans::PropertyValue& rPropVal2 = rSecSequence[ i ];
127 0 : aPropPairHashMap[ PropertyPair( rPropVal.Name, rPropVal2.Name ) ] = i;
128 : }
129 : }
130 : }
131 : else
132 : { // its a new property
133 1691 : sal_uInt32 nIndex = aPropSeq.getLength();
134 1691 : aPropSeq.realloc( nIndex + 1 );
135 1691 : aPropSeq[ nIndex ] = rPropVal ;
136 :
137 1691 : aPropHashMap[ rPropVal.Name ] = nIndex;
138 : }
139 1762 : }
140 :
141 947 : void SdrCustomShapeGeometryItem::SetPropertyValue( const rtl::OUString& rSequenceName, const com::sun::star::beans::PropertyValue& rPropVal )
142 : {
143 947 : com::sun::star::uno::Any* pAny = GetPropertyValueByName( rSequenceName, rPropVal.Name );
144 947 : if ( pAny ) // just replacing
145 0 : *pAny = rPropVal.Value;
146 : else
147 : {
148 947 : com::sun::star::uno::Any* pSeqAny = GetPropertyValueByName( rSequenceName );
149 947 : if( pSeqAny == NULL )
150 : {
151 793 : ::com::sun::star::uno::Sequence < beans::PropertyValue > aSeq;
152 793 : beans::PropertyValue aValue;
153 793 : aValue.Name = rSequenceName;
154 793 : aValue.Value = ::com::sun::star::uno::makeAny( aSeq );
155 :
156 793 : sal_uInt32 nIndex = aPropSeq.getLength();
157 793 : aPropSeq.realloc( nIndex + 1 );
158 793 : aPropSeq[ nIndex ] = aValue;
159 793 : aPropHashMap[ rSequenceName ] = nIndex;
160 :
161 793 : pSeqAny = &aPropSeq[ nIndex ].Value;
162 : }
163 :
164 : DBG_ASSERT( pSeqAny, "SdrCustomShapeGeometryItem::SetPropertyValue() - No Value??" );
165 :
166 947 : if( pSeqAny )
167 : {
168 947 : if ( pSeqAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
169 : {
170 947 : PropertyPairHashMap::iterator aHashIter( aPropPairHashMap.find( PropertyPair( rSequenceName, rPropVal.Name ) ) );
171 947 : if ( aHashIter != aPropPairHashMap.end() )
172 : {
173 : ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
174 0 : *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pSeqAny->getValue());
175 0 : rSecSequence[ (*aHashIter).second ].Value = rPropVal.Value;
176 : }
177 : else
178 : {
179 : ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
180 947 : *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pSeqAny->getValue());
181 :
182 947 : sal_Int32 nCount = rSecSequence.getLength();
183 947 : rSecSequence.realloc( nCount + 1 );
184 947 : rSecSequence[ nCount ] = rPropVal;
185 :
186 947 : aPropPairHashMap[ PropertyPair( rSequenceName, rPropVal.Name ) ] = nCount;
187 : }
188 : }
189 : }
190 : }
191 947 : }
192 :
193 0 : void SdrCustomShapeGeometryItem::ClearPropertyValue( const rtl::OUString& rPropName )
194 : {
195 0 : if ( aPropSeq.getLength() )
196 : {
197 0 : PropertyHashMap::iterator aHashIter( aPropHashMap.find( rPropName ) );
198 0 : if ( aHashIter != aPropHashMap.end() )
199 : {
200 0 : com::sun::star::uno::Any* pSeqAny = &aPropSeq[ (*aHashIter).second ].Value;
201 0 : if ( pSeqAny )
202 : {
203 0 : if ( pSeqAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
204 : {
205 : ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
206 0 : *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pSeqAny->getValue());
207 :
208 : sal_Int32 i;
209 0 : for ( i = 0; i < rSecSequence.getLength(); i++ )
210 : {
211 0 : PropertyPairHashMap::iterator _aHashIter( aPropPairHashMap.find( PropertyPair( rPropName, rSecSequence[ i ].Name ) ) );
212 0 : if ( _aHashIter != aPropPairHashMap.end() )
213 0 : aPropPairHashMap.erase( _aHashIter ); // removing property from pair hashmap
214 : }
215 : }
216 : }
217 0 : sal_Int32 nLength = aPropSeq.getLength();
218 0 : if ( nLength )
219 : {
220 0 : sal_Int32 nIndex = (*aHashIter).second;
221 0 : if ( nIndex != ( nLength - 1 ) ) // resizing sequence
222 : {
223 0 : PropertyHashMap::iterator aHashIter2( aPropHashMap.find( aPropSeq[ nLength - 1 ].Name ) );
224 0 : (*aHashIter2).second = nIndex;
225 0 : aPropSeq[ (*aHashIter).second ] = aPropSeq[ aPropSeq.getLength() - 1 ];
226 : }
227 0 : aPropSeq.realloc( aPropSeq.getLength() - 1 );
228 : }
229 0 : aPropHashMap.erase( aHashIter ); // removing property from hashmap
230 : }
231 : }
232 0 : }
233 :
234 7805 : SdrCustomShapeGeometryItem::~SdrCustomShapeGeometryItem()
235 : {
236 7805 : }
237 0 : SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem( SvStream& /*rIn*/, sal_uInt16 nVersion ):
238 0 : SfxPoolItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )
239 : {
240 : if ( nVersion )
241 : {
242 :
243 : }
244 0 : }
245 17453 : int SdrCustomShapeGeometryItem::operator==( const SfxPoolItem& rCmp ) const
246 : {
247 17453 : int bRet = SfxPoolItem::operator==( rCmp );
248 17453 : if ( bRet )
249 17453 : bRet = ((SdrCustomShapeGeometryItem&)rCmp).aPropSeq == aPropSeq;
250 17453 : return bRet;
251 : }
252 :
253 0 : SfxItemPresentation SdrCustomShapeGeometryItem::GetPresentation(
254 : SfxItemPresentation ePresentation, SfxMapUnit /*eCoreMetric*/,
255 : SfxMapUnit /*ePresentationMetric*/, XubString &rText, const IntlWrapper *) const
256 : {
257 0 : rText += sal_Unicode( ' ' );
258 0 : if ( ePresentation == SFX_ITEM_PRESENTATION_COMPLETE )
259 : {
260 0 : XubString aStr;
261 0 : aStr += sal_Unicode( ' ' );
262 0 : rText.Insert( aStr, 0 );
263 : }
264 0 : return ePresentation;
265 : }
266 :
267 0 : SfxPoolItem* SdrCustomShapeGeometryItem::Create( SvStream& rIn, sal_uInt16 nItemVersion ) const
268 : {
269 0 : return new SdrCustomShapeGeometryItem( rIn, nItemVersion );
270 : }
271 :
272 0 : SvStream& SdrCustomShapeGeometryItem::Store( SvStream& rOut, sal_uInt16 nItemVersion ) const
273 : {
274 : if ( nItemVersion )
275 : {
276 :
277 : }
278 0 : return rOut;
279 : }
280 :
281 2033 : SfxPoolItem* SdrCustomShapeGeometryItem::Clone( SfxItemPool * /*pPool*/ ) const
282 : {
283 2033 : return new SdrCustomShapeGeometryItem( GetGeometry() );
284 : }
285 :
286 0 : sal_uInt16 SdrCustomShapeGeometryItem::GetVersion( sal_uInt16 /*nFileFormatVersion*/ ) const
287 : {
288 0 : return 1;
289 : }
290 69 : bool SdrCustomShapeGeometryItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
291 : {
292 69 : rVal <<= aPropSeq;
293 69 : return true;
294 : }
295 74 : bool SdrCustomShapeGeometryItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
296 : {
297 74 : if ( ! ( rVal >>= aPropSeq ) )
298 0 : return false;
299 : else
300 74 : return true;
301 : }
302 2033 : const uno::Sequence< beans::PropertyValue >& SdrCustomShapeGeometryItem::GetGeometry() const
303 : {
304 2033 : return aPropSeq;
305 : }
306 :
307 394 : SdrCustomShapeReplacementURLItem::SdrCustomShapeReplacementURLItem()
308 394 : : SfxStringItem( SDRATTR_CUSTOMSHAPE_REPLACEMENT_URL, String() )
309 394 : {}
310 :
311 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|