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_svx.hxx"
26 #include <svx/sdasitm.hxx>
27 #include <svx/svdattr.hxx>
28
29 using namespace ::std;
30 using namespace com::sun::star;
31
SdrCustomShapeEngineItem()32 SdrCustomShapeEngineItem::SdrCustomShapeEngineItem()
33 : SfxStringItem( SDRATTR_CUSTOMSHAPE_ENGINE, String() )
34 {}
SdrCustomShapeEngineItem(const String & rVal)35 SdrCustomShapeEngineItem::SdrCustomShapeEngineItem( const String& rVal )
36 : SfxStringItem( SDRATTR_CUSTOMSHAPE_ENGINE, rVal )
37 {}
38
SdrCustomShapeDataItem()39 SdrCustomShapeDataItem::SdrCustomShapeDataItem()
40 : SfxStringItem( SDRATTR_CUSTOMSHAPE_DATA, String() )
41 {}
SdrCustomShapeDataItem(const String & rVal)42 SdrCustomShapeDataItem::SdrCustomShapeDataItem( const String& rVal )
43 : SfxStringItem( SDRATTR_CUSTOMSHAPE_DATA, rVal )
44 {}
45
46 TYPEINIT1_FACTORY( SdrCustomShapeGeometryItem, SfxPoolItem , new SdrCustomShapeGeometryItem);
SdrCustomShapeGeometryItem()47 SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem()
48 : SfxPoolItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )
49 {}
SdrCustomShapeGeometryItem(const uno::Sequence<beans::PropertyValue> & rVal)50 SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem( const uno::Sequence< beans::PropertyValue >& rVal )
51 : SfxPoolItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )
52 {
53 sal_Int32 i, j;
54 aPropSeq = rVal;
55
56 // hashing property values
57 // beans::PropertyValue* pPropValues = aPropSeq.getArray();
58 // const rtl::OUString* pPtr = NULL;
59 for ( i = 0; i < aPropSeq.getLength(); i++ )
60 {
61 beans::PropertyValue& rPropVal = aPropSeq[ i ];
62 aPropHashMap[ rPropVal.Name ] = i;
63 if ( rPropVal.Value.getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
64 {
65 uno::Sequence< beans::PropertyValue >& rPropSeq = *( uno::Sequence< beans::PropertyValue >*)rPropVal.Value.getValue();
66 for ( j = 0; j < rPropSeq.getLength(); j++ )
67 {
68 beans::PropertyValue& rPropVal2 = rPropSeq[ j ];
69 aPropPairHashMap[ PropertyPair( rPropVal.Name, rPropVal2.Name ) ] = j;
70 }
71 }
72 }
73 }
74
GetPropertyValueByName(const rtl::OUString & rPropName)75 com::sun::star::uno::Any* SdrCustomShapeGeometryItem::GetPropertyValueByName( const rtl::OUString& rPropName )
76 {
77 com::sun::star::uno::Any* pRet = NULL;
78 PropertyHashMap::iterator aHashIter( aPropHashMap.find( rPropName ) );
79 if ( aHashIter != aPropHashMap.end() )
80 pRet = &aPropSeq[ (*aHashIter).second ].Value;
81 return pRet;
82 }
83
GetPropertyValueByName(const rtl::OUString & rSequenceName,const rtl::OUString & rPropName)84 com::sun::star::uno::Any* SdrCustomShapeGeometryItem::GetPropertyValueByName( const rtl::OUString& rSequenceName, const rtl::OUString& rPropName )
85 {
86 com::sun::star::uno::Any* pRet = NULL;
87 com::sun::star::uno::Any* pSeqAny = GetPropertyValueByName( rSequenceName );
88 if ( pSeqAny )
89 {
90 if ( pSeqAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
91 {
92 PropertyPairHashMap::iterator aHashIter( aPropPairHashMap.find( PropertyPair( rSequenceName, rPropName ) ) );
93 if ( aHashIter != aPropPairHashMap.end() )
94 {
95 ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
96 *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pSeqAny->getValue());
97 pRet = &rSecSequence[ (*aHashIter).second ].Value;
98 }
99 }
100 }
101 return pRet;
102 }
103
SetPropertyValue(const com::sun::star::beans::PropertyValue & rPropVal)104 void SdrCustomShapeGeometryItem::SetPropertyValue( const com::sun::star::beans::PropertyValue& rPropVal )
105 {
106 com::sun::star::uno::Any* pAny = GetPropertyValueByName( rPropVal.Name );
107 if ( pAny )
108 { // property is already available
109 sal_Int32 i;
110 if ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
111 { // old property is a sequence->each entry has to be removed from the HashPairMap
112 ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
113 *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pAny->getValue());
114 for ( i = 0; i < rSecSequence.getLength(); i++ )
115 {
116 PropertyPairHashMap::iterator aHashIter( aPropPairHashMap.find( PropertyPair( rPropVal.Name, rSecSequence[ i ].Name ) ) );
117 if ( aHashIter != aPropPairHashMap.end() )
118 aPropPairHashMap.erase( aHashIter );
119 }
120 }
121 *pAny = rPropVal.Value;
122 if ( rPropVal.Value.getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
123 { // the new property is a sequence->each entry has to be inserted into the HashPairMap
124 ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
125 *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pAny->getValue());
126 for ( i = 0; i < rSecSequence.getLength(); i++ )
127 {
128 beans::PropertyValue& rPropVal2 = rSecSequence[ i ];
129 aPropPairHashMap[ PropertyPair( rPropVal.Name, rPropVal2.Name ) ] = i;
130 }
131 }
132 }
133 else
134 { // its a new property
135 sal_uInt32 nIndex = aPropSeq.getLength();
136 aPropSeq.realloc( nIndex + 1 );
137 aPropSeq[ nIndex ] = rPropVal ;
138
139 aPropHashMap[ rPropVal.Name ] = nIndex;
140 }
141 }
142
SetPropertyValue(const rtl::OUString & rSequenceName,const com::sun::star::beans::PropertyValue & rPropVal)143 void SdrCustomShapeGeometryItem::SetPropertyValue( const rtl::OUString& rSequenceName, const com::sun::star::beans::PropertyValue& rPropVal )
144 {
145 com::sun::star::uno::Any* pAny = GetPropertyValueByName( rSequenceName, rPropVal.Name );
146 if ( pAny ) // just replacing
147 *pAny = rPropVal.Value;
148 else
149 {
150 com::sun::star::uno::Any* pSeqAny = GetPropertyValueByName( rSequenceName );
151 if( pSeqAny == NULL )
152 {
153 ::com::sun::star::uno::Sequence < beans::PropertyValue > aSeq;
154 beans::PropertyValue aValue;
155 aValue.Name = rSequenceName;
156 aValue.Value = ::com::sun::star::uno::makeAny( aSeq );
157
158 sal_uInt32 nIndex = aPropSeq.getLength();
159 aPropSeq.realloc( nIndex + 1 );
160 aPropSeq[ nIndex ] = aValue;
161 aPropHashMap[ rSequenceName ] = nIndex;
162
163 pSeqAny = &aPropSeq[ nIndex ].Value;
164 }
165
166 DBG_ASSERT( pSeqAny, "SdrCustomShapeGeometryItem::SetPropertyValue() - No Value??" );
167
168 if( pSeqAny )
169 {
170 if ( pSeqAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
171 {
172 PropertyPairHashMap::iterator aHashIter( aPropPairHashMap.find( PropertyPair( rSequenceName, rPropVal.Name ) ) );
173 if ( aHashIter != aPropPairHashMap.end() )
174 {
175 ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
176 *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pSeqAny->getValue());
177 rSecSequence[ (*aHashIter).second ].Value = rPropVal.Value;
178 }
179 else
180 {
181 ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
182 *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pSeqAny->getValue());
183
184 sal_Int32 nCount = rSecSequence.getLength();
185 rSecSequence.realloc( nCount + 1 );
186 rSecSequence[ nCount ] = rPropVal;
187
188 aPropPairHashMap[ PropertyPair( rSequenceName, rPropVal.Name ) ] = nCount;
189 }
190 }
191 }
192 }
193 }
194
ClearPropertyValue(const rtl::OUString & rPropName)195 void SdrCustomShapeGeometryItem::ClearPropertyValue( const rtl::OUString& rPropName )
196 {
197 if ( aPropSeq.getLength() )
198 {
199 PropertyHashMap::iterator aHashIter( aPropHashMap.find( rPropName ) );
200 if ( aHashIter != aPropHashMap.end() )
201 {
202 com::sun::star::uno::Any* pSeqAny = &aPropSeq[ (*aHashIter).second ].Value;
203 if ( pSeqAny )
204 {
205 if ( pSeqAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
206 {
207 ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
208 *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pSeqAny->getValue());
209
210 sal_Int32 i;
211 for ( i = 0; i < rSecSequence.getLength(); i++ )
212 {
213 PropertyPairHashMap::iterator _aHashIter( aPropPairHashMap.find( PropertyPair( rPropName, rSecSequence[ i ].Name ) ) );
214 if ( _aHashIter != aPropPairHashMap.end() )
215 aPropPairHashMap.erase( _aHashIter ); // removing property from pair hashmap
216 }
217 }
218 }
219 sal_Int32 nLength = aPropSeq.getLength();
220 if ( nLength )
221 {
222 sal_Int32 nIndex = (*aHashIter).second;
223 if ( nIndex != ( nLength - 1 ) ) // resizing sequence
224 {
225 PropertyHashMap::iterator aHashIter2( aPropHashMap.find( aPropSeq[ nLength - 1 ].Name ) );
226 (*aHashIter2).second = nIndex;
227 aPropSeq[ (*aHashIter).second ] = aPropSeq[ aPropSeq.getLength() - 1 ];
228 }
229 aPropSeq.realloc( aPropSeq.getLength() - 1 );
230 }
231 aPropHashMap.erase( aHashIter ); // removing property from hashmap
232 }
233 }
234 }
235
ClearPropertyValue(const rtl::OUString & rSequenceName,const rtl::OUString & rPropName)236 void SdrCustomShapeGeometryItem::ClearPropertyValue( const rtl::OUString& rSequenceName, const rtl::OUString& rPropName )
237 {
238 com::sun::star::uno::Any* pSeqAny = GetPropertyValueByName( rSequenceName );
239 if ( pSeqAny )
240 {
241 if ( pSeqAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
242 {
243 PropertyPairHashMap::iterator aHashIter( aPropPairHashMap.find( PropertyPair( rSequenceName, rPropName ) ) );
244 if ( aHashIter != aPropPairHashMap.end() )
245 {
246 ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
247 *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pSeqAny->getValue());
248
249 sal_Int32 nLength = rSecSequence.getLength();
250 if ( nLength )
251 {
252 sal_Int32 nIndex = (*aHashIter).second;
253 if ( nIndex != ( nLength - 1 ) ) // resizing sequence
254 {
255 PropertyPairHashMap::iterator aHashIter2( aPropPairHashMap.find( PropertyPair( rSequenceName, rSecSequence[ nLength - 1 ].Name ) ) );
256 (*aHashIter2).second = nIndex;
257 rSecSequence[ nIndex ] = rSecSequence[ nLength - 1 ];
258 }
259 rSecSequence.realloc( aPropSeq.getLength() - 1 );
260 }
261 aPropPairHashMap.erase( aHashIter );
262 }
263 }
264 }
265 }
266
~SdrCustomShapeGeometryItem()267 SdrCustomShapeGeometryItem::~SdrCustomShapeGeometryItem()
268 {
269 }
SdrCustomShapeGeometryItem(SvStream &,sal_uInt16 nVersion)270 SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem( SvStream& /*rIn*/, sal_uInt16 nVersion ):
271 SfxPoolItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )
272 {
273 if ( nVersion )
274 {
275
276 }
277 }
operator ==(const SfxPoolItem & rCmp) const278 int __EXPORT SdrCustomShapeGeometryItem::operator==( const SfxPoolItem& rCmp ) const
279 {
280 int bRet = SfxPoolItem::operator==( rCmp );
281 if ( bRet )
282 bRet = ((SdrCustomShapeGeometryItem&)rCmp).aPropSeq == aPropSeq;
283 return bRet;
284 }
285
GetPresentation(SfxItemPresentation ePresentation,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper *) const286 SfxItemPresentation __EXPORT SdrCustomShapeGeometryItem::GetPresentation(
287 SfxItemPresentation ePresentation, SfxMapUnit /*eCoreMetric*/,
288 SfxMapUnit /*ePresentationMetric*/, XubString &rText, const IntlWrapper *) const
289 {
290 rText += sal_Unicode( ' ' );
291 if ( ePresentation == SFX_ITEM_PRESENTATION_COMPLETE )
292 {
293 XubString aStr;
294 // SdrItemPool::TakeItemName( Which(), aStr );
295 aStr += sal_Unicode( ' ' );
296 rText.Insert( aStr, 0 );
297 }
298 return ePresentation;
299 }
300
Create(SvStream & rIn,sal_uInt16 nItemVersion) const301 SfxPoolItem* __EXPORT SdrCustomShapeGeometryItem::Create( SvStream& rIn, sal_uInt16 nItemVersion ) const
302 {
303 return new SdrCustomShapeGeometryItem( rIn, nItemVersion );
304 }
305
Store(SvStream & rOut,sal_uInt16 nItemVersion) const306 SvStream& __EXPORT SdrCustomShapeGeometryItem::Store( SvStream& rOut, sal_uInt16 nItemVersion ) const
307 {
308 if ( nItemVersion )
309 {
310
311 }
312 return rOut;
313 }
314
Clone(SfxItemPool *) const315 SfxPoolItem* __EXPORT SdrCustomShapeGeometryItem::Clone( SfxItemPool * /*pPool*/ ) const
316 {
317 SdrCustomShapeGeometryItem* pItem = new SdrCustomShapeGeometryItem( GetGeometry() );
318 // SdrCustomShapeGeometryItem* pItem = new SdrCustomShapeGeometryItem( *this );
319
320 /*
321 for ( i = 0; i < GetCount(); i++ )
322 {
323 const SdrCustomShapeAdjustmentValue& rVal = GetValue( i );
324 pItem->SetValue( i, rVal );
325 }
326 */
327 return pItem;
328 }
329
330 #ifdef SDR_ISPOOLABLE
IsPoolable() const331 int __EXPORT SdrCustomShapeGeometryItem::IsPoolable() const
332 {
333 sal_uInt16 nId=Which();
334 return nId < SDRATTR_NOTPERSIST_FIRST || nId > SDRATTR_NOTPERSIST_LAST;
335 }
336 #endif
GetVersion(sal_uInt16) const337 sal_uInt16 SdrCustomShapeGeometryItem::GetVersion( sal_uInt16 /*nFileFormatVersion*/ ) const
338 {
339 return 1;
340 }
QueryValue(uno::Any & rVal,sal_uInt8) const341 sal_Bool SdrCustomShapeGeometryItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
342 {
343 rVal <<= aPropSeq;
344 return sal_True;
345 }
PutValue(const uno::Any & rVal,sal_uInt8)346 sal_Bool SdrCustomShapeGeometryItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
347 {
348 if ( ! ( rVal >>= aPropSeq ) )
349 return sal_False;
350 else
351 return sal_True;
352 }
GetGeometry() const353 const uno::Sequence< beans::PropertyValue >& SdrCustomShapeGeometryItem::GetGeometry() const
354 {
355 return aPropSeq;
356 }
357 /*
358 const uno::Any* GetValueByName( const rtl::OUString& rProperty ) const
359 {
360
361 }
362 */
SdrCustomShapeReplacementURLItem()363 SdrCustomShapeReplacementURLItem::SdrCustomShapeReplacementURLItem()
364 : SfxStringItem( SDRATTR_CUSTOMSHAPE_REPLACEMENT_URL, String() )
365 {}
SdrCustomShapeReplacementURLItem(const String & rVal)366 SdrCustomShapeReplacementURLItem::SdrCustomShapeReplacementURLItem( const String& rVal )
367 : SfxStringItem( SDRATTR_CUSTOMSHAPE_REPLACEMENT_URL, rVal )
368 {}
369
370