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