bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / items / customshapeitem.cxx
blob5b8ed9f51c5076310fa507bae46620e768651b04
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/sdasitm.hxx>
21 #include <svx/svdattr.hxx>
23 using namespace ::std;
24 using namespace com::sun::star;
26 SdrCustomShapeEngineItem::SdrCustomShapeEngineItem()
27 : SfxStringItem( SDRATTR_CUSTOMSHAPE_ENGINE, String() )
30 SdrCustomShapeDataItem::SdrCustomShapeDataItem()
31 : SfxStringItem( SDRATTR_CUSTOMSHAPE_DATA, String() )
34 bool SdrCustomShapeGeometryItem::PropertyEq::operator()( const OUString& r1, const OUString& r2 ) const
36 return r1.equals( r2 );
38 bool SdrCustomShapeGeometryItem::PropertyPairEq::operator()( const SdrCustomShapeGeometryItem::PropertyPair& r1, const SdrCustomShapeGeometryItem::PropertyPair& r2 ) const
40 return ( r1.first.equals( r2.first ) ) && ( r1.second.equals( r2.second ) );
42 size_t SdrCustomShapeGeometryItem::PropertyPairHash::operator()( const SdrCustomShapeGeometryItem::PropertyPair &r1 ) const
44 return (size_t)r1.first.hashCode() + r1.second.hashCode();
47 TYPEINIT1_FACTORY( SdrCustomShapeGeometryItem, SfxPoolItem , new SdrCustomShapeGeometryItem);
48 SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem()
49 : SfxPoolItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )
51 SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem( const uno::Sequence< beans::PropertyValue >& rVal )
52 : SfxPoolItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )
54 sal_Int32 i, j;
55 aPropSeq = rVal;
57 for ( i = 0; i < aPropSeq.getLength(); i++ )
59 beans::PropertyValue& rPropVal = aPropSeq[ i ];
60 aPropHashMap[ rPropVal.Name ] = i;
61 if ( rPropVal.Value.getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
63 uno::Sequence< beans::PropertyValue >& rPropSeq = *( uno::Sequence< beans::PropertyValue >*)rPropVal.Value.getValue();
64 for ( j = 0; j < rPropSeq.getLength(); j++ )
66 beans::PropertyValue& rPropVal2 = rPropSeq[ j ];
67 aPropPairHashMap[ PropertyPair( rPropVal.Name, rPropVal2.Name ) ] = j;
73 com::sun::star::uno::Any* SdrCustomShapeGeometryItem::GetPropertyValueByName( const OUString& rPropName )
75 com::sun::star::uno::Any* pRet = NULL;
76 PropertyHashMap::iterator aHashIter( aPropHashMap.find( rPropName ) );
77 if ( aHashIter != aPropHashMap.end() )
78 pRet = &aPropSeq[ (*aHashIter).second ].Value;
79 return pRet;
82 com::sun::star::uno::Any* SdrCustomShapeGeometryItem::GetPropertyValueByName( const OUString& rSequenceName, const OUString& rPropName )
84 com::sun::star::uno::Any* pRet = NULL;
85 com::sun::star::uno::Any* pSeqAny = GetPropertyValueByName( rSequenceName );
86 if ( pSeqAny )
88 if ( pSeqAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
90 PropertyPairHashMap::iterator aHashIter( aPropPairHashMap.find( PropertyPair( rSequenceName, rPropName ) ) );
91 if ( aHashIter != aPropPairHashMap.end() )
93 ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
94 *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pSeqAny->getValue());
95 pRet = &rSecSequence[ (*aHashIter).second ].Value;
99 return pRet;
102 void SdrCustomShapeGeometryItem::SetPropertyValue( const com::sun::star::beans::PropertyValue& rPropVal )
104 com::sun::star::uno::Any* pAny = GetPropertyValueByName( rPropVal.Name );
105 if ( pAny )
106 { // property is already available
107 sal_Int32 i;
108 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 *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pAny->getValue());
112 for ( i = 0; i < rSecSequence.getLength(); i++ )
114 PropertyPairHashMap::iterator aHashIter( aPropPairHashMap.find( PropertyPair( rPropVal.Name, rSecSequence[ i ].Name ) ) );
115 if ( aHashIter != aPropPairHashMap.end() )
116 aPropPairHashMap.erase( aHashIter );
119 *pAny = rPropVal.Value;
120 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 *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pAny->getValue());
124 for ( i = 0; i < rSecSequence.getLength(); i++ )
126 beans::PropertyValue& rPropVal2 = rSecSequence[ i ];
127 aPropPairHashMap[ PropertyPair( rPropVal.Name, rPropVal2.Name ) ] = i;
131 else
132 { // its a new property
133 sal_uInt32 nIndex = aPropSeq.getLength();
134 aPropSeq.realloc( nIndex + 1 );
135 aPropSeq[ nIndex ] = rPropVal ;
137 aPropHashMap[ rPropVal.Name ] = nIndex;
141 void SdrCustomShapeGeometryItem::SetPropertyValue( const OUString& rSequenceName, const com::sun::star::beans::PropertyValue& rPropVal )
143 com::sun::star::uno::Any* pAny = GetPropertyValueByName( rSequenceName, rPropVal.Name );
144 if ( pAny ) // just replacing
145 *pAny = rPropVal.Value;
146 else
148 com::sun::star::uno::Any* pSeqAny = GetPropertyValueByName( rSequenceName );
149 if( pSeqAny == NULL )
151 ::com::sun::star::uno::Sequence < beans::PropertyValue > aSeq;
152 beans::PropertyValue aValue;
153 aValue.Name = rSequenceName;
154 aValue.Value = ::com::sun::star::uno::makeAny( aSeq );
156 sal_uInt32 nIndex = aPropSeq.getLength();
157 aPropSeq.realloc( nIndex + 1 );
158 aPropSeq[ nIndex ] = aValue;
159 aPropHashMap[ rSequenceName ] = nIndex;
161 pSeqAny = &aPropSeq[ nIndex ].Value;
164 DBG_ASSERT( pSeqAny, "SdrCustomShapeGeometryItem::SetPropertyValue() - No Value??" );
166 if( pSeqAny )
168 if ( pSeqAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
170 PropertyPairHashMap::iterator aHashIter( aPropPairHashMap.find( PropertyPair( rSequenceName, rPropVal.Name ) ) );
171 if ( aHashIter != aPropPairHashMap.end() )
173 ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
174 *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pSeqAny->getValue());
175 rSecSequence[ (*aHashIter).second ].Value = rPropVal.Value;
177 else
179 ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
180 *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pSeqAny->getValue());
182 sal_Int32 nCount = rSecSequence.getLength();
183 rSecSequence.realloc( nCount + 1 );
184 rSecSequence[ nCount ] = rPropVal;
186 aPropPairHashMap[ PropertyPair( rSequenceName, rPropVal.Name ) ] = nCount;
193 void SdrCustomShapeGeometryItem::ClearPropertyValue( const OUString& rPropName )
195 if ( aPropSeq.getLength() )
197 PropertyHashMap::iterator aHashIter( aPropHashMap.find( rPropName ) );
198 if ( aHashIter != aPropHashMap.end() )
200 com::sun::star::uno::Any* pSeqAny = &aPropSeq[ (*aHashIter).second ].Value;
201 if ( pSeqAny )
203 if ( pSeqAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
205 ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
206 *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pSeqAny->getValue());
208 sal_Int32 i;
209 for ( i = 0; i < rSecSequence.getLength(); i++ )
211 PropertyPairHashMap::iterator _aHashIter( aPropPairHashMap.find( PropertyPair( rPropName, rSecSequence[ i ].Name ) ) );
212 if ( _aHashIter != aPropPairHashMap.end() )
213 aPropPairHashMap.erase( _aHashIter ); // removing property from pair hashmap
217 sal_Int32 nLength = aPropSeq.getLength();
218 if ( nLength )
220 sal_Int32 nIndex = (*aHashIter).second;
221 if ( nIndex != ( nLength - 1 ) ) // resizing sequence
223 PropertyHashMap::iterator aHashIter2( aPropHashMap.find( aPropSeq[ nLength - 1 ].Name ) );
224 (*aHashIter2).second = nIndex;
225 aPropSeq[ (*aHashIter).second ] = aPropSeq[ aPropSeq.getLength() - 1 ];
227 aPropSeq.realloc( aPropSeq.getLength() - 1 );
229 aPropHashMap.erase( aHashIter ); // removing property from hashmap
234 SdrCustomShapeGeometryItem::~SdrCustomShapeGeometryItem()
237 SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem( SvStream& /*rIn*/, sal_uInt16 nVersion ):
238 SfxPoolItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )
240 if ( nVersion )
245 int SdrCustomShapeGeometryItem::operator==( const SfxPoolItem& rCmp ) const
247 int bRet = SfxPoolItem::operator==( rCmp );
248 if ( bRet )
249 bRet = ((SdrCustomShapeGeometryItem&)rCmp).aPropSeq == aPropSeq;
250 return bRet;
253 SfxItemPresentation SdrCustomShapeGeometryItem::GetPresentation(
254 SfxItemPresentation ePresentation, SfxMapUnit /*eCoreMetric*/,
255 SfxMapUnit /*ePresentationMetric*/, OUString &rText, const IntlWrapper *) const
257 rText += " ";
258 if ( ePresentation == SFX_ITEM_PRESENTATION_COMPLETE )
260 rText = " " + rText;
262 return ePresentation;
265 SfxPoolItem* SdrCustomShapeGeometryItem::Create( SvStream& rIn, sal_uInt16 nItemVersion ) const
267 return new SdrCustomShapeGeometryItem( rIn, nItemVersion );
270 SvStream& SdrCustomShapeGeometryItem::Store( SvStream& rOut, sal_uInt16 nItemVersion ) const
272 if ( nItemVersion )
276 return rOut;
279 SfxPoolItem* SdrCustomShapeGeometryItem::Clone( SfxItemPool * /*pPool*/ ) const
281 return new SdrCustomShapeGeometryItem( GetGeometry() );
284 sal_uInt16 SdrCustomShapeGeometryItem::GetVersion( sal_uInt16 /*nFileFormatVersion*/ ) const
286 return 1;
288 bool SdrCustomShapeGeometryItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
290 rVal <<= aPropSeq;
291 return true;
293 bool SdrCustomShapeGeometryItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
295 if ( ! ( rVal >>= aPropSeq ) )
296 return false;
297 else
298 return true;
300 const uno::Sequence< beans::PropertyValue >& SdrCustomShapeGeometryItem::GetGeometry() const
302 return aPropSeq;
305 SdrCustomShapeReplacementURLItem::SdrCustomShapeReplacementURLItem()
306 : SfxStringItem( SDRATTR_CUSTOMSHAPE_REPLACEMENT_URL, String() )
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */