1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: customshapeitem.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <svx/sdasitm.hxx>
34 #include <svx/svdattr.hxx>
36 using namespace ::std
;
37 using namespace com::sun::star
;
39 SdrCustomShapeEngineItem::SdrCustomShapeEngineItem()
40 : SfxStringItem( SDRATTR_CUSTOMSHAPE_ENGINE
, String() )
42 SdrCustomShapeEngineItem::SdrCustomShapeEngineItem( const String
& rVal
)
43 : SfxStringItem( SDRATTR_CUSTOMSHAPE_ENGINE
, rVal
)
46 SdrCustomShapeDataItem::SdrCustomShapeDataItem()
47 : SfxStringItem( SDRATTR_CUSTOMSHAPE_DATA
, String() )
49 SdrCustomShapeDataItem::SdrCustomShapeDataItem( const String
& rVal
)
50 : SfxStringItem( SDRATTR_CUSTOMSHAPE_DATA
, rVal
)
53 bool SdrCustomShapeGeometryItem::PropertyEq::operator()( const rtl::OUString
& r1
, const rtl::OUString
& r2
) const
55 return r1
.equals( r2
);
57 bool SdrCustomShapeGeometryItem::PropertyPairEq::operator()( const SdrCustomShapeGeometryItem::PropertyPair
& r1
, const SdrCustomShapeGeometryItem::PropertyPair
& r2
) const
59 return ( r1
.first
.equals( r2
.first
) ) && ( r1
.second
.equals( r2
.second
) );
61 size_t SdrCustomShapeGeometryItem::PropertyPairHash::operator()( const SdrCustomShapeGeometryItem::PropertyPair
&r1
) const
63 return (size_t)r1
.first
.hashCode() + r1
.second
.hashCode();
66 TYPEINIT1_FACTORY( SdrCustomShapeGeometryItem
, SfxPoolItem
, new SdrCustomShapeGeometryItem(0));
67 SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem()
68 : SfxPoolItem( SDRATTR_CUSTOMSHAPE_GEOMETRY
)
70 SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem( const uno::Sequence
< beans::PropertyValue
>& rVal
)
71 : SfxPoolItem( SDRATTR_CUSTOMSHAPE_GEOMETRY
)
76 // hashing property values
77 // beans::PropertyValue* pPropValues = aPropSeq.getArray();
78 // const rtl::OUString* pPtr = NULL;
79 for ( i
= 0; i
< aPropSeq
.getLength(); i
++ )
81 beans::PropertyValue
& rPropVal
= aPropSeq
[ i
];
82 aPropHashMap
[ rPropVal
.Name
] = i
;
83 if ( rPropVal
.Value
.getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence
< beans::PropertyValue
>*)0) )
85 uno::Sequence
< beans::PropertyValue
>& rPropSeq
= *( uno::Sequence
< beans::PropertyValue
>*)rPropVal
.Value
.getValue();
86 for ( j
= 0; j
< rPropSeq
.getLength(); j
++ )
88 beans::PropertyValue
& rPropVal2
= rPropSeq
[ j
];
89 aPropPairHashMap
[ PropertyPair( rPropVal
.Name
, rPropVal2
.Name
) ] = j
;
95 com::sun::star::uno::Any
* SdrCustomShapeGeometryItem::GetPropertyValueByName( const rtl::OUString
& rPropName
)
97 com::sun::star::uno::Any
* pRet
= NULL
;
98 PropertyHashMap::iterator
aHashIter( aPropHashMap
.find( rPropName
) );
99 if ( aHashIter
!= aPropHashMap
.end() )
100 pRet
= &aPropSeq
[ (*aHashIter
).second
].Value
;
104 com::sun::star::uno::Any
* SdrCustomShapeGeometryItem::GetPropertyValueByName( const rtl::OUString
& rSequenceName
, const rtl::OUString
& rPropName
)
106 com::sun::star::uno::Any
* pRet
= NULL
;
107 com::sun::star::uno::Any
* pSeqAny
= GetPropertyValueByName( rSequenceName
);
110 if ( pSeqAny
->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence
< beans::PropertyValue
>*)0) )
112 PropertyPairHashMap::iterator
aHashIter( aPropPairHashMap
.find( PropertyPair( rSequenceName
, rPropName
) ) );
113 if ( aHashIter
!= aPropPairHashMap
.end() )
115 ::com::sun::star::uno::Sequence
< beans::PropertyValue
>& rSecSequence
=
116 *((::com::sun::star::uno::Sequence
< beans::PropertyValue
>*)pSeqAny
->getValue());
117 pRet
= &rSecSequence
[ (*aHashIter
).second
].Value
;
124 void SdrCustomShapeGeometryItem::SetPropertyValue( const com::sun::star::beans::PropertyValue
& rPropVal
)
126 com::sun::star::uno::Any
* pAny
= GetPropertyValueByName( rPropVal
.Name
);
128 { // property is already available
130 if ( pAny
->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence
< beans::PropertyValue
>*)0) )
131 { // old property is a sequence->each entry has to be removed from the HashPairMap
132 ::com::sun::star::uno::Sequence
< beans::PropertyValue
>& rSecSequence
=
133 *((::com::sun::star::uno::Sequence
< beans::PropertyValue
>*)pAny
->getValue());
134 for ( i
= 0; i
< rSecSequence
.getLength(); i
++ )
136 PropertyPairHashMap::iterator
aHashIter( aPropPairHashMap
.find( PropertyPair( rPropVal
.Name
, rSecSequence
[ i
].Name
) ) );
137 if ( aHashIter
!= aPropPairHashMap
.end() )
138 aPropPairHashMap
.erase( aHashIter
);
141 *pAny
= rPropVal
.Value
;
142 if ( rPropVal
.Value
.getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence
< beans::PropertyValue
>*)0) )
143 { // the new property is a sequence->each entry has to be inserted into the HashPairMap
144 ::com::sun::star::uno::Sequence
< beans::PropertyValue
>& rSecSequence
=
145 *((::com::sun::star::uno::Sequence
< beans::PropertyValue
>*)pAny
->getValue());
146 for ( i
= 0; i
< rSecSequence
.getLength(); i
++ )
148 beans::PropertyValue
& rPropVal2
= rSecSequence
[ i
];
149 aPropPairHashMap
[ PropertyPair( rPropVal
.Name
, rPropVal2
.Name
) ] = i
;
154 { // its a new property
155 sal_uInt32 nIndex
= aPropSeq
.getLength();
156 aPropSeq
.realloc( nIndex
+ 1 );
157 aPropSeq
[ nIndex
] = rPropVal
;
159 aPropHashMap
[ rPropVal
.Name
] = nIndex
;
163 void SdrCustomShapeGeometryItem::SetPropertyValue( const rtl::OUString
& rSequenceName
, const com::sun::star::beans::PropertyValue
& rPropVal
)
165 com::sun::star::uno::Any
* pAny
= GetPropertyValueByName( rSequenceName
, rPropVal
.Name
);
166 if ( pAny
) // just replacing
167 *pAny
= rPropVal
.Value
;
170 com::sun::star::uno::Any
* pSeqAny
= GetPropertyValueByName( rSequenceName
);
171 if( pSeqAny
== NULL
)
173 ::com::sun::star::uno::Sequence
< beans::PropertyValue
> aSeq
;
174 beans::PropertyValue aValue
;
175 aValue
.Name
= rSequenceName
;
176 aValue
.Value
= ::com::sun::star::uno::makeAny( aSeq
);
178 sal_uInt32 nIndex
= aPropSeq
.getLength();
179 aPropSeq
.realloc( nIndex
+ 1 );
180 aPropSeq
[ nIndex
] = aValue
;
181 aPropHashMap
[ rSequenceName
] = nIndex
;
183 pSeqAny
= &aPropSeq
[ nIndex
].Value
;
186 DBG_ASSERT( pSeqAny
, "SdrCustomShapeGeometryItem::SetPropertyValue() - No Value??" );
190 if ( pSeqAny
->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence
< beans::PropertyValue
>*)0) )
192 PropertyPairHashMap::iterator
aHashIter( aPropPairHashMap
.find( PropertyPair( rSequenceName
, rPropVal
.Name
) ) );
193 if ( aHashIter
!= aPropPairHashMap
.end() )
195 ::com::sun::star::uno::Sequence
< beans::PropertyValue
>& rSecSequence
=
196 *((::com::sun::star::uno::Sequence
< beans::PropertyValue
>*)pSeqAny
->getValue());
197 rSecSequence
[ (*aHashIter
).second
].Value
= rPropVal
.Value
;
201 ::com::sun::star::uno::Sequence
< beans::PropertyValue
>& rSecSequence
=
202 *((::com::sun::star::uno::Sequence
< beans::PropertyValue
>*)pSeqAny
->getValue());
204 sal_Int32 nCount
= rSecSequence
.getLength();
205 rSecSequence
.realloc( nCount
+ 1 );
206 rSecSequence
[ nCount
] = rPropVal
;
208 aPropPairHashMap
[ PropertyPair( rSequenceName
, rPropVal
.Name
) ] = nCount
;
215 void SdrCustomShapeGeometryItem::ClearPropertyValue( const rtl::OUString
& rPropName
)
217 if ( aPropSeq
.getLength() )
219 PropertyHashMap::iterator
aHashIter( aPropHashMap
.find( rPropName
) );
220 if ( aHashIter
!= aPropHashMap
.end() )
222 com::sun::star::uno::Any
* pSeqAny
= &aPropSeq
[ (*aHashIter
).second
].Value
;
225 if ( pSeqAny
->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence
< beans::PropertyValue
>*)0) )
227 ::com::sun::star::uno::Sequence
< beans::PropertyValue
>& rSecSequence
=
228 *((::com::sun::star::uno::Sequence
< beans::PropertyValue
>*)pSeqAny
->getValue());
231 for ( i
= 0; i
< rSecSequence
.getLength(); i
++ )
233 PropertyPairHashMap::iterator
_aHashIter( aPropPairHashMap
.find( PropertyPair( rPropName
, rSecSequence
[ i
].Name
) ) );
234 if ( _aHashIter
!= aPropPairHashMap
.end() )
235 aPropPairHashMap
.erase( _aHashIter
); // removing property from pair hashmap
239 sal_Int32 nLength
= aPropSeq
.getLength();
242 sal_Int32 nIndex
= (*aHashIter
).second
;
243 if ( nIndex
!= ( nLength
- 1 ) ) // resizing sequence
245 PropertyHashMap::iterator
aHashIter2( aPropHashMap
.find( aPropSeq
[ nLength
- 1 ].Name
) );
246 (*aHashIter2
).second
= nIndex
;
247 aPropSeq
[ (*aHashIter
).second
] = aPropSeq
[ aPropSeq
.getLength() - 1 ];
249 aPropSeq
.realloc( aPropSeq
.getLength() - 1 );
251 aPropHashMap
.erase( aHashIter
); // removing property from hashmap
256 void SdrCustomShapeGeometryItem::ClearPropertyValue( const rtl::OUString
& rSequenceName
, const rtl::OUString
& rPropName
)
258 com::sun::star::uno::Any
* pSeqAny
= GetPropertyValueByName( rSequenceName
);
261 if ( pSeqAny
->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence
< beans::PropertyValue
>*)0) )
263 PropertyPairHashMap::iterator
aHashIter( aPropPairHashMap
.find( PropertyPair( rSequenceName
, rPropName
) ) );
264 if ( aHashIter
!= aPropPairHashMap
.end() )
266 ::com::sun::star::uno::Sequence
< beans::PropertyValue
>& rSecSequence
=
267 *((::com::sun::star::uno::Sequence
< beans::PropertyValue
>*)pSeqAny
->getValue());
269 sal_Int32 nLength
= rSecSequence
.getLength();
272 sal_Int32 nIndex
= (*aHashIter
).second
;
273 if ( nIndex
!= ( nLength
- 1 ) ) // resizing sequence
275 PropertyPairHashMap::iterator
aHashIter2( aPropPairHashMap
.find( PropertyPair( rSequenceName
, rSecSequence
[ nLength
- 1 ].Name
) ) );
276 (*aHashIter2
).second
= nIndex
;
277 rSecSequence
[ nIndex
] = rSecSequence
[ nLength
- 1 ];
279 rSecSequence
.realloc( aPropSeq
.getLength() - 1 );
281 aPropPairHashMap
.erase( aHashIter
);
287 SdrCustomShapeGeometryItem::~SdrCustomShapeGeometryItem()
290 SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem( SvStream
& /*rIn*/, sal_uInt16 nVersion
):
291 SfxPoolItem( SDRATTR_CUSTOMSHAPE_GEOMETRY
)
298 int __EXPORT
SdrCustomShapeGeometryItem::operator==( const SfxPoolItem
& rCmp
) const
300 int bRet
= SfxPoolItem::operator==( rCmp
);
302 bRet
= ((SdrCustomShapeGeometryItem
&)rCmp
).aPropSeq
== aPropSeq
;
306 SfxItemPresentation __EXPORT
SdrCustomShapeGeometryItem::GetPresentation(
307 SfxItemPresentation ePresentation
, SfxMapUnit
/*eCoreMetric*/,
308 SfxMapUnit
/*ePresentationMetric*/, XubString
&rText
, const IntlWrapper
*) const
310 rText
+= sal_Unicode( ' ' );
311 if ( ePresentation
== SFX_ITEM_PRESENTATION_COMPLETE
)
314 // SdrItemPool::TakeItemName( Which(), aStr );
315 aStr
+= sal_Unicode( ' ' );
316 rText
.Insert( aStr
, 0 );
318 return ePresentation
;
321 SfxPoolItem
* __EXPORT
SdrCustomShapeGeometryItem::Create( SvStream
& rIn
, sal_uInt16 nItemVersion
) const
323 return new SdrCustomShapeGeometryItem( rIn
, nItemVersion
);
326 SvStream
& __EXPORT
SdrCustomShapeGeometryItem::Store( SvStream
& rOut
, sal_uInt16 nItemVersion
) const
335 SfxPoolItem
* __EXPORT
SdrCustomShapeGeometryItem::Clone( SfxItemPool
* /*pPool*/ ) const
337 SdrCustomShapeGeometryItem
* pItem
= new SdrCustomShapeGeometryItem( GetGeometry() );
338 // SdrCustomShapeGeometryItem* pItem = new SdrCustomShapeGeometryItem( *this );
341 for ( i = 0; i < GetCount(); i++ )
343 const SdrCustomShapeAdjustmentValue& rVal = GetValue( i );
344 pItem->SetValue( i, rVal );
350 #ifdef SDR_ISPOOLABLE
351 int __EXPORT
SdrCustomShapeGeometryItem::IsPoolable() const
354 return nId
< SDRATTR_NOTPERSIST_FIRST
|| nId
> SDRATTR_NOTPERSIST_LAST
;
357 sal_uInt16
SdrCustomShapeGeometryItem::GetVersion( sal_uInt16
/*nFileFormatVersion*/ ) const
361 sal_Bool
SdrCustomShapeGeometryItem::QueryValue( uno::Any
& rVal
, BYTE
/*nMemberId*/ ) const
366 sal_Bool
SdrCustomShapeGeometryItem::PutValue( const uno::Any
& rVal
, BYTE
/*nMemberId*/ )
368 if ( ! ( rVal
>>= aPropSeq
) )
373 const uno::Sequence
< beans::PropertyValue
>& SdrCustomShapeGeometryItem::GetGeometry() const
378 const uno::Any* GetValueByName( const rtl::OUString& rProperty ) const
383 SdrCustomShapeReplacementURLItem::SdrCustomShapeReplacementURLItem()
384 : SfxStringItem( SDRATTR_CUSTOMSHAPE_REPLACEMENT_URL
, String() )
386 SdrCustomShapeReplacementURLItem::SdrCustomShapeReplacementURLItem( const String
& rVal
)
387 : SfxStringItem( SDRATTR_CUSTOMSHAPE_REPLACEMENT_URL
, rVal
)