Branch libreoffice-5-0-4
[LibreOffice.git] / oox / source / helper / propertymap.cxx
blob9db0e0991199e49d265560ea7500df4ce547d9df
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 "oox/helper/propertymap.hxx"
21 #include "oox/helper/helper.hxx"
23 #if OSL_DEBUG_LEVEL > 0
24 # include <cstdio>
25 # include <com/sun/star/style/LineSpacing.hpp>
26 # include <com/sun/star/style/LineSpacingMode.hpp>
27 # include <com/sun/star/text/WritingMode.hpp>
28 using ::com::sun::star::style::LineSpacing;
29 using ::com::sun::star::text::WritingMode;
30 #include <comphelper/anytostring.hxx>
31 #include <iostream>
32 #endif
34 #include <com/sun/star/beans/PropertyValue.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/beans/XPropertySetInfo.hpp>
37 #include <com/sun/star/container/XIndexReplace.hpp>
38 #include <com/sun/star/awt/Rectangle.hpp>
39 #include <com/sun/star/awt/Size.hpp>
40 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
41 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
42 #include <com/sun/star/drawing/EnhancedCustomShapeAdjustmentValue.hpp>
43 #include <com/sun/star/drawing/EnhancedCustomShapeSegment.hpp>
44 #include <com/sun/star/drawing/EnhancedCustomShapeTextFrame.hpp>
45 #include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
46 #include <com/sun/star/drawing/EnhancedCustomShapeParameterType.hpp>
47 #include <com/sun/star/drawing/HomogenMatrix3.hpp>
48 #include <cppuhelper/implbase2.hxx>
49 #include <osl/diagnose.h>
50 #include <osl/mutex.hxx>
51 #include "oox/token/propertynames.hxx"
52 using ::com::sun::star::uno::Any;
53 using ::com::sun::star::uno::Reference;
54 using ::com::sun::star::uno::RuntimeException;
55 using ::com::sun::star::uno::Sequence;
56 using ::com::sun::star::lang::IllegalArgumentException;
57 using ::com::sun::star::lang::WrappedTargetException;
58 using ::com::sun::star::beans::Property;
59 using ::com::sun::star::beans::PropertyValue;
60 using ::com::sun::star::beans::PropertyVetoException;
61 using ::com::sun::star::beans::UnknownPropertyException;
62 using ::com::sun::star::beans::XPropertyChangeListener;
63 using ::com::sun::star::beans::XPropertySet;
64 using ::com::sun::star::beans::XPropertySetInfo;
65 using ::com::sun::star::beans::XVetoableChangeListener;
66 using ::com::sun::star::container::XIndexReplace;
68 #if OSL_DEBUG_LEVEL > 0
69 #include <cstdio>
70 #include <com/sun/star/style/LineSpacing.hpp>
71 #include <com/sun/star/style/LineSpacingMode.hpp>
72 #include <com/sun/star/text/WritingMode.hpp>
73 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
74 #define USS(x) OUStringToOString( x, RTL_TEXTENCODING_UTF8 ).getStr()
75 using namespace ::com::sun::star;
76 using namespace ::com::sun::star::drawing;
77 using namespace ::com::sun::star::uno;
78 using ::com::sun::star::style::LineSpacing;
79 using ::com::sun::star::text::WritingMode;
80 using ::com::sun::star::drawing::TextHorizontalAdjust;
81 using ::com::sun::star::drawing::TextVerticalAdjust;
82 #endif
84 namespace oox {
85 using ::com::sun::star::container::XIndexReplace;
87 using namespace ::com::sun::star::beans;
88 using namespace ::com::sun::star::lang;
89 using namespace ::com::sun::star::drawing;
90 using namespace ::com::sun::star::uno;
91 using ::com::sun::star::drawing::TextHorizontalAdjust;
92 using ::com::sun::star::drawing::TextVerticalAdjust;
94 namespace {
96 typedef ::cppu::WeakImplHelper2< XPropertySet, XPropertySetInfo > GenericPropertySetBase;
98 /** This class implements a generic XPropertySet.
100 Properties of all names and types can be set and later retrieved.
101 TODO: move this to comphelper or better find an existing implementation
103 class GenericPropertySet : public GenericPropertySetBase
105 public:
106 explicit GenericPropertySet( const PropertyMap& rPropMap );
108 // XPropertySet
109 virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo() throw (RuntimeException, std::exception) SAL_OVERRIDE;
110 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException, std::exception) SAL_OVERRIDE;
111 virtual Any SAL_CALL getPropertyValue( const OUString& PropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception) SAL_OVERRIDE;
112 virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& xListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception) SAL_OVERRIDE;
113 virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception) SAL_OVERRIDE;
114 virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception) SAL_OVERRIDE;
115 virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception) SAL_OVERRIDE;
117 // XPropertySetInfo
118 virtual Sequence< Property > SAL_CALL getProperties() throw (RuntimeException, std::exception) SAL_OVERRIDE;
119 virtual Property SAL_CALL getPropertyByName( const OUString& aName ) throw (UnknownPropertyException, RuntimeException, std::exception) SAL_OVERRIDE;
120 virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
122 private:
123 osl::Mutex mMutex;
124 PropertyNameMap maPropMap;
127 GenericPropertySet::GenericPropertySet( const PropertyMap& rPropMap )
129 rPropMap.fillPropertyNameMap(maPropMap);
132 Reference< XPropertySetInfo > SAL_CALL GenericPropertySet::getPropertySetInfo() throw (RuntimeException, std::exception)
134 return this;
137 void SAL_CALL GenericPropertySet::setPropertyValue( const OUString& rPropertyName, const Any& rValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException, std::exception)
139 ::osl::MutexGuard aGuard( mMutex );
140 maPropMap[ rPropertyName ] = rValue;
143 Any SAL_CALL GenericPropertySet::getPropertyValue( const OUString& rPropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
145 PropertyNameMap::iterator aIt = maPropMap.find( rPropertyName );
146 if( aIt == maPropMap.end() )
147 throw UnknownPropertyException();
148 return aIt->second;
151 // listeners are not supported by this implementation
152 void SAL_CALL GenericPropertySet::addPropertyChangeListener( const OUString& , const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception) {}
153 void SAL_CALL GenericPropertySet::removePropertyChangeListener( const OUString& , const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception) {}
154 void SAL_CALL GenericPropertySet::addVetoableChangeListener( const OUString& , const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception) {}
155 void SAL_CALL GenericPropertySet::removeVetoableChangeListener( const OUString& , const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception) {}
157 // XPropertySetInfo
158 Sequence< Property > SAL_CALL GenericPropertySet::getProperties() throw (RuntimeException, std::exception)
160 Sequence< Property > aSeq( static_cast< sal_Int32 >( maPropMap.size() ) );
161 Property* pProperty = aSeq.getArray();
162 for( PropertyNameMap::iterator aIt = maPropMap.begin(), aEnd = maPropMap.end(); aIt != aEnd; ++aIt, ++pProperty )
164 pProperty->Name = aIt->first;
165 pProperty->Handle = 0;
166 pProperty->Type = aIt->second.getValueType();
167 pProperty->Attributes = 0;
169 return aSeq;
172 Property SAL_CALL GenericPropertySet::getPropertyByName( const OUString& rPropertyName ) throw (UnknownPropertyException, RuntimeException, std::exception)
174 PropertyNameMap::iterator aIt = maPropMap.find( rPropertyName );
175 if( aIt == maPropMap.end() )
176 throw UnknownPropertyException();
177 Property aProperty;
178 aProperty.Name = aIt->first;
179 aProperty.Handle = 0;
180 aProperty.Type = aIt->second.getValueType();
181 aProperty.Attributes = 0;
182 return aProperty;
185 sal_Bool SAL_CALL GenericPropertySet::hasPropertyByName( const OUString& rPropertyName ) throw (RuntimeException, std::exception)
187 return maPropMap.find( rPropertyName ) != maPropMap.end();
190 } // namespace
192 PropertyMap::PropertyMap() :
193 mpPropNames( &StaticPropertyNameVector::get() ) // pointer instead reference to get compiler generated copy c'tor and operator=
197 bool PropertyMap::hasProperty( sal_Int32 nPropId ) const
199 return maProperties.find( nPropId ) != maProperties.end();
202 bool PropertyMap::setAnyProperty( sal_Int32 nPropId, const Any& rValue )
204 if( nPropId < 0 )
205 return false;
207 maProperties[ nPropId ] = rValue;
208 return true;
211 Any PropertyMap::getProperty( sal_Int32 nPropId )
213 return maProperties[ nPropId ];
216 void PropertyMap::erase( sal_Int32 nPropId )
218 maProperties.erase(nPropId);
221 bool PropertyMap::empty() const
223 return maProperties.empty();
226 void PropertyMap::assignUsed( const PropertyMap& rPropMap )
228 maProperties.insert(rPropMap.maProperties.begin(), rPropMap.maProperties.end());
231 const OUString& PropertyMap::getPropertyName( sal_Int32 nPropId )
233 OSL_ENSURE( (0 <= nPropId) && (nPropId < PROP_COUNT), "PropertyMap::getPropertyName - invalid property identifier" );
234 return StaticPropertyNameVector::get()[ nPropId ];
237 void PropertyMap::assignAll( const PropertyMap& rPropMap )
239 for( PropertyMapType::const_iterator it=rPropMap.maProperties.begin(); it != rPropMap.maProperties.end(); ++it )
240 maProperties[it->first] = it->second;
243 Sequence< PropertyValue > PropertyMap::makePropertyValueSequence() const
245 Sequence< PropertyValue > aSeq( static_cast< sal_Int32 >( maProperties.size() ) );
246 if( !maProperties.empty() )
248 PropertyValue* pValues = aSeq.getArray();
249 for( PropertyMapType::const_iterator aIt = maProperties.begin(), aEnd = maProperties.end(); aIt != aEnd; ++aIt, ++pValues )
251 OSL_ENSURE( (0 <= aIt->first) && (aIt->first < PROP_COUNT), "PropertyMap::makePropertyValueSequence - invalid property identifier" );
252 pValues->Name = (*mpPropNames)[ aIt->first ];
253 pValues->Value = aIt->second;
254 pValues->State = PropertyState_DIRECT_VALUE;
257 return aSeq;
260 void PropertyMap::fillSequences( Sequence< OUString >& rNames, Sequence< Any >& rValues ) const
262 rNames.realloc( static_cast< sal_Int32 >( maProperties.size() ) );
263 rValues.realloc( static_cast< sal_Int32 >( maProperties.size() ) );
264 if( !maProperties.empty() )
266 OUString* pNames = rNames.getArray();
267 Any* pValues = rValues.getArray();
268 for( PropertyMapType::const_iterator aIt = maProperties.begin(), aEnd = maProperties.end(); aIt != aEnd; ++aIt, ++pNames, ++pValues )
270 OSL_ENSURE( (0 <= aIt->first) && (aIt->first < PROP_COUNT), "PropertyMap::fillSequences - invalid property identifier" );
271 *pNames = (*mpPropNames)[ aIt->first ];
272 *pValues = aIt->second;
277 void PropertyMap::fillPropertyNameMap(PropertyNameMap& rMap) const
279 for(PropertyMapType::const_iterator itr = maProperties.begin(),
280 itrEnd = maProperties.end(); itr != itrEnd; ++itr)
282 rMap.insert(std::pair<OUString, Any>((*mpPropNames)[itr->first], itr->second));
286 Reference< XPropertySet > PropertyMap::makePropertySet() const
288 return new GenericPropertySet( *this );
291 #if OSL_DEBUG_LEVEL > 0
292 static void lclDumpAnyValue( Any value)
294 OUString strValue;
295 Sequence< OUString > strArray;
296 Sequence< Any > anyArray;
297 Sequence< PropertyValue > propArray;
298 Sequence< Sequence< PropertyValue > > propArrayArray;
299 Sequence< EnhancedCustomShapeAdjustmentValue > adjArray;
300 Sequence< EnhancedCustomShapeSegment > segArray;
301 Sequence< EnhancedCustomShapeParameterPair > ppArray;
302 EnhancedCustomShapeSegment segment;
303 EnhancedCustomShapeParameterPair pp;
304 EnhancedCustomShapeParameter par;
305 HomogenMatrix3 aMatrix;
306 sal_Int32 intValue = 0;
307 sal_uInt32 uintValue = 0;
308 sal_Int16 int16Value = 0;
309 sal_uInt16 uint16Value = 0;
310 float floatValue = 0;
311 bool boolValue = false;
312 LineSpacing spacing;
313 // RectanglePoint pointValue;
314 WritingMode aWritingMode;
315 TextVerticalAdjust aTextVertAdj;
316 TextHorizontalAdjust aTextHorizAdj;
317 Reference< XIndexReplace > xNumRule;
319 if( value >>= strValue )
320 fprintf (stderr,"\"%s\"\n", USS( strValue ) );
321 else if( value >>= strArray ) {
322 fprintf (stderr,"%s\n", USS(value.getValueTypeName()));
323 for( int i=0; i<strArray.getLength(); i++ )
324 fprintf (stderr,"\t\t\t[%3d] \"%s\"\n", i, USS( strArray[i] ) );
325 } else if( value >>= propArray ) {
326 fprintf (stderr,"%s\n", USS(value.getValueTypeName()));
327 for( int i=0; i<propArray.getLength(); i++ ) {
328 fprintf (stderr,"\t\t\t[%3d] %s (%s) ", i, USS( propArray[i].Name ), USS(propArray[i].Value.getValueTypeName()) );
329 lclDumpAnyValue( propArray[i].Value );
331 } else if( value >>= propArrayArray ) {
332 fprintf (stderr,"%s\n", USS(value.getValueTypeName()));
333 for( int i=0; i<propArrayArray.getLength(); i++ ) {
334 fprintf (stderr,"\t\t\t[%3d] ", i);
335 lclDumpAnyValue( makeAny (propArrayArray[i]) );
337 } else if( value >>= anyArray ) {
338 fprintf (stderr,"%s\n", USS(value.getValueTypeName()));
339 for( int i=0; i<anyArray.getLength(); i++ ) {
340 fprintf (stderr,"\t\t\t[%3d] (%s) ", i, USS(value.getValueTypeName()) );
341 lclDumpAnyValue( anyArray[i] );
343 } else if( value >>= adjArray ) {
344 fprintf (stderr,"%s\n", USS(value.getValueTypeName()));
345 for( int i=0; i<adjArray.getLength(); i++ ) {
346 fprintf (stderr,"\t\t\t[%3d] (%s) ", i, USS(adjArray[i].Value.getValueTypeName()) );
347 lclDumpAnyValue( adjArray[i].Value );
349 } else if( value >>= segArray ) {
350 fprintf (stderr,"%s\n", USS(value.getValueTypeName()));
351 for( int i=0; i<segArray.getLength(); i++ ) {
352 fprintf (stderr,"\t\t\t[%3d] ", i );
353 lclDumpAnyValue( makeAny( segArray[i] ) );
355 } else if( value >>= ppArray ) {
356 fprintf (stderr,"%s\n", USS(value.getValueTypeName()));
357 for( int i=0; i<ppArray.getLength(); i++ ) {
358 fprintf (stderr,"\t\t\t[%3d] ", i );
359 lclDumpAnyValue( makeAny( ppArray[i] ) );
361 } else if( value >>= segment ) {
362 fprintf (stderr,"Command: %d Count: %d\n", segment.Command, segment.Count);
363 } else if( value >>= pp ) {
364 fprintf (stderr,"First: ");
365 lclDumpAnyValue( makeAny (pp.First) );
366 fprintf (stderr,"\t\t\t Second: ");
367 lclDumpAnyValue( makeAny (pp.Second) );
368 } else if( value >>= par ) {
369 fprintf (stderr,"Parameter (%s): ", USS(par.Value.getValueTypeName()));
370 lclDumpAnyValue( par.Value );
371 } else if( value >>= aMatrix ) {
372 fprintf (stderr,"Matrix\n%f %f %f\n%f %f %f\n%f %f %f\n", aMatrix.Line1.Column1, aMatrix.Line1.Column2, aMatrix.Line1.Column3, aMatrix.Line2.Column1, aMatrix.Line2.Column2, aMatrix.Line2.Column3, aMatrix.Line3.Column1, aMatrix.Line3.Column2, aMatrix.Line3.Column3);
373 } else if( value >>= intValue )
374 fprintf (stderr,"%" SAL_PRIdINT32 " (hex: %" SAL_PRIxUINT32 ")\n", intValue, intValue);
375 else if( value >>= uintValue )
376 fprintf (stderr,"%" SAL_PRIuUINT32 " (hex: %" SAL_PRIxUINT32 ")\n", uintValue, uintValue);
377 else if( value >>= int16Value )
378 fprintf (stderr,"%d (hex: %x)\n", int16Value, int16Value);
379 else if( value >>= uint16Value )
380 fprintf (stderr,"%d (hex: %x)\n", uint16Value, uint16Value);
381 else if( value >>= floatValue )
382 fprintf (stderr,"%f\n", floatValue);
383 else if( value >>= boolValue )
384 fprintf (stderr,"%d (bool)\n", boolValue);
385 else if( value >>= xNumRule ) {
386 fprintf (stderr, "XIndexReplace\n");
387 if (xNumRule.is()) {
388 for (int k=0; k<xNumRule->getCount(); k++) {
389 Sequence< PropertyValue > aBulletPropSeq;
390 fprintf (stderr, "level %d\n", k);
391 if (xNumRule->getByIndex (k) >>= aBulletPropSeq) {
392 for (int j=0; j<aBulletPropSeq.getLength(); j++) {
393 fprintf(stderr, "%46s = ", USS (aBulletPropSeq[j].Name));
394 lclDumpAnyValue (aBulletPropSeq[j].Value);
398 } else {
399 fprintf (stderr, "empty reference\n");
401 } else if( value >>= aWritingMode )
402 fprintf (stderr, "%d writing mode\n", aWritingMode);
403 else if( value >>= aTextVertAdj ) {
404 const char* s = "unknown";
405 switch( aTextVertAdj ) {
406 case TextVerticalAdjust_TOP:
407 s = "top";
408 break;
409 case TextVerticalAdjust_CENTER:
410 s = "center";
411 break;
412 case TextVerticalAdjust_BOTTOM:
413 s = "bottom";
414 break;
415 case TextVerticalAdjust_BLOCK:
416 s = "block";
417 break;
418 case TextVerticalAdjust_MAKE_FIXED_SIZE:
419 s = "make_fixed_size";
420 break;
422 fprintf (stderr, "%s\n", s);
423 } else if( value >>= aTextHorizAdj ) {
424 const char* s = "unknown";
425 switch( aTextHorizAdj ) {
426 case TextHorizontalAdjust_LEFT:
427 s = "left";
428 break;
429 case TextHorizontalAdjust_CENTER:
430 s = "center";
431 break;
432 case TextHorizontalAdjust_RIGHT:
433 s = "right";
434 break;
435 case TextHorizontalAdjust_BLOCK:
436 s = "block";
437 break;
438 case TextHorizontalAdjust_MAKE_FIXED_SIZE:
439 s = "make_fixed_size";
440 break;
442 fprintf (stderr, "%s\n", s);
443 } else if( value >>= spacing ) {
444 fprintf (stderr, "mode: %d value: %d\n", spacing.Mode, spacing.Height);
445 } else if( value.isExtractableTo(::cppu::UnoType<sal_Int32>::get())) {
446 fprintf (stderr,"is extractable to int32\n");
448 // else if( value >>= pointValue )
449 // fprintf (stderr,"%d (RectanglePoint)\n", pointValue);
450 else
451 fprintf (stderr,"??? <unhandled type %s>\n", USS(value.getValueTypeName()));
454 #ifdef DBG_UTIL
455 void PropertyMap::dump( Reference< XPropertySet > rXPropSet )
457 Reference< XPropertySetInfo > info = rXPropSet->getPropertySetInfo ();
458 Sequence< Property > props = info->getProperties ();
460 SAL_INFO("oox", "dump props, len: " << props.getLength ());
462 for (int i=0; i < props.getLength (); i++) {
463 OString name = OUStringToOString( props [i].Name, RTL_TEXTENCODING_UTF8);
464 fprintf (stderr,"%30s = ", name.getStr() );
466 try {
467 lclDumpAnyValue (rXPropSet->getPropertyValue( props [i].Name ));
468 } catch (const Exception&) {
469 fprintf (stderr,"unable to get '%s' value\n", USS(props [i].Name));
473 #endif
475 static void printLevel (int level)
477 for (int i=0; i<level; i++)
478 fprintf (stderr, " ");
481 static const char *lclGetEnhancedParameterType( sal_uInt16 nType )
483 const char* type;
484 switch (nType) {
485 case EnhancedCustomShapeParameterType::NORMAL:
486 type = "EnhancedCustomShapeParameterType::NORMAL";
487 break;
488 case EnhancedCustomShapeParameterType::EQUATION:
489 type = "EnhancedCustomShapeParameterType::EQUATION";
490 break;
491 case EnhancedCustomShapeParameterType::ADJUSTMENT:
492 type = "EnhancedCustomShapeParameterType::ADJUSTMENT";
493 break;
494 case EnhancedCustomShapeParameterType::LEFT:
495 type = "EnhancedCustomShapeParameterType::LEFT";
496 break;
497 case EnhancedCustomShapeParameterType::TOP:
498 type = "EnhancedCustomShapeParameterType::TOP";
499 break;
500 case EnhancedCustomShapeParameterType::RIGHT:
501 type = "EnhancedCustomShapeParameterType::RIGHT";
502 break;
503 case EnhancedCustomShapeParameterType::BOTTOM:
504 type = "EnhancedCustomShapeParameterType::BOTTOM";
505 break;
506 case EnhancedCustomShapeParameterType::XSTRETCH:
507 type = "EnhancedCustomShapeParameterType::XSTRETCH";
508 break;
509 case EnhancedCustomShapeParameterType::YSTRETCH:
510 type = "EnhancedCustomShapeParameterType::YSTRETCH";
511 break;
512 case EnhancedCustomShapeParameterType::HASSTROKE:
513 type = "EnhancedCustomShapeParameterType::HASSTROKE";
514 break;
515 case EnhancedCustomShapeParameterType::HASFILL:
516 type = "EnhancedCustomShapeParameterType::HASFILL";
517 break;
518 case EnhancedCustomShapeParameterType::WIDTH:
519 type = "EnhancedCustomShapeParameterType::WIDTH";
520 break;
521 case EnhancedCustomShapeParameterType::HEIGHT:
522 type = "EnhancedCustomShapeParameterType::HEIGHT";
523 break;
524 case EnhancedCustomShapeParameterType::LOGWIDTH:
525 type = "EnhancedCustomShapeParameterType::LOGWIDTH";
526 break;
527 case EnhancedCustomShapeParameterType::LOGHEIGHT:
528 type = "EnhancedCustomShapeParameterType::LOGHEIGHT";
529 break;
530 default:
531 type = "unknown";
532 break;
534 return type;
537 static void printParameterPairData(int level, EnhancedCustomShapeParameterPair &pp)
539 // These are always sal_Int32s so lets depend on that for our packing ...
540 sal_Int32 nFirstValue, nSecondValue;
541 if (!(pp.First.Value >>= nFirstValue))
542 assert (false);
543 if (!(pp.Second.Value >>= nSecondValue))
544 assert (false);
546 printLevel (level);
547 fprintf (stderr, "{\n");
548 printLevel (level + 1);
549 fprintf (stderr, "%s,\n", lclGetEnhancedParameterType(pp.First.Type));
550 printLevel (level + 1);
551 fprintf (stderr, "%s,\n", lclGetEnhancedParameterType(pp.Second.Type));
552 printLevel (level + 1);
553 fprintf (stderr, "%d, %d\n", (int)nFirstValue, (int)nSecondValue);
554 printLevel (level);
555 fprintf (stderr, "}");
558 static const char* lclDumpAnyValueCode( Any value, int level = 0)
560 OUString strValue;
561 Sequence< OUString > strArray;
562 Sequence< Any > anyArray;
563 Sequence< awt::Size > sizeArray;
564 Sequence< PropertyValue > propArray;
565 Sequence< Sequence< PropertyValue > > propArrayArray;
566 Sequence< EnhancedCustomShapeAdjustmentValue > adjArray;
567 Sequence< EnhancedCustomShapeTextFrame > segTextFrame;
568 Sequence< EnhancedCustomShapeSegment > segArray;
569 Sequence< EnhancedCustomShapeParameterPair > ppArray;
570 EnhancedCustomShapeSegment segment;
571 EnhancedCustomShapeTextFrame textFrame;
572 EnhancedCustomShapeParameterPair pp;
573 EnhancedCustomShapeParameter par;
574 awt::Rectangle rect;
575 awt::Size size;
576 sal_Int32 intValue;
577 sal_uInt32 uintValue;
578 sal_Int16 int16Value;
579 sal_uInt16 uint16Value;
580 long longValue;
581 float floatValue = 0;
582 bool boolValue;
583 LineSpacing spacing;
584 // RectanglePoint pointValue;
585 WritingMode aWritingMode;
586 TextVerticalAdjust aTextVertAdj;
587 TextHorizontalAdjust aTextHorizAdj;
588 Reference< XIndexReplace > xNumRule;
590 if( value >>= strValue )
592 printLevel (level);
593 fprintf (stderr,"OUString str = \"%s\";\n", USS( strValue ) );
594 return "Any (str)";
596 else if( value >>= strArray )
598 if (strArray.getLength() == 0)
599 return "Sequence< OUString >(0)";
601 printLevel (level);
602 fprintf (stderr,"static const char *aStrings[] = {\n");
603 for( int i=0; i<strArray.getLength(); i++ ) {
604 printLevel (level + 1);
605 fprintf (stderr,"\"%s\"%s\n", USS( strArray[i] ), i < strArray.getLength() - 1 ? "," : "" );
607 printLevel (level);
608 fprintf (stderr,"};\n");
609 return "createStringSequence( SAL_N_ELEMENTS( aStrings ), aStrings )";
611 else if( value >>= propArray )
613 printLevel (level);
614 fprintf (stderr,"Sequence< PropertyValue > aPropSequence (%" SAL_PRIdINT32 ");\n", propArray.getLength());
615 for( int i=0; i<propArray.getLength(); i++ ) {
616 printLevel (level);
617 fprintf (stderr, "{\n");
618 printLevel (level + 1);
619 fprintf (stderr, "aPropSequence [%d].Name = \"%s\";\n", i, USS( propArray[i].Name ));
620 const char *var = lclDumpAnyValueCode( propArray[i].Value, level + 1 );
621 printLevel (level + 1);
622 fprintf (stderr, "aPropSequence [%d].Value = makeAny (%s);\n", i, var);
623 printLevel (level);
624 fprintf (stderr, "}\n");
626 return "aPropSequence";
628 else if( value >>= sizeArray )
630 printLevel (level);
631 fprintf (stderr, "Sequence< awt::Size > aSizeSequence (%" SAL_PRIdINT32 ");\n", sizeArray.getLength());
632 for( int i=0; i<sizeArray.getLength(); i++ ) {
633 printLevel (level);
634 fprintf (stderr, "{\n");
635 const char *var = lclDumpAnyValueCode (makeAny (sizeArray[i]), level + 1);
636 printLevel (level + 1);
637 fprintf (stderr, "aSizeSequence [%d] = %s;\n", i, var);
638 printLevel (level);
639 fprintf (stderr, "}\n");
641 return "aSizeSequence";
643 else if( value >>= propArrayArray )
645 printLevel (level);
646 fprintf (stderr,"Sequence< Sequence < PropertyValue > > aPropSequenceSequence (%" SAL_PRIdINT32 ");\n", propArrayArray.getLength());
647 for( int i=0; i<propArrayArray.getLength(); i++ ) {
648 printLevel (level);
649 fprintf (stderr, "{\n");
650 const char *var = lclDumpAnyValueCode( makeAny (propArrayArray[i]), level + 1 );
651 printLevel (level + 1);
652 fprintf (stderr, "aPropSequenceSequence [%d] = %s;\n", i, var);
653 printLevel (level);
654 fprintf (stderr, "}\n");
656 return "aPropSequenceSequence";
658 else if( value >>= anyArray )
660 fprintf (stderr,"%s\n", USS(value.getValueTypeName()));
661 for( int i=0; i<anyArray.getLength(); i++ ) {
662 fprintf (stderr,"\t\t\t[%3d] (%s) ", i, USS(value.getValueTypeName()) );
663 lclDumpAnyValue( anyArray[i] );
666 else if( value >>= adjArray )
668 printLevel (level);
669 fprintf (stderr,"Sequence< EnhancedCustomShapeAdjustmentValue > aAdjSequence (%" SAL_PRIdINT32 ");\n", adjArray.getLength());
670 for( int i=0; i<adjArray.getLength(); i++ ) {
671 printLevel (level);
672 fprintf (stderr, "{\n");
673 const char *var = lclDumpAnyValueCode( adjArray[i].Value, level + 1 );
674 printLevel (level + 1);
675 fprintf (stderr, "aAdjSequence [%d].Value = %s;\n", i, var);
676 if (adjArray[i].Name.getLength() > 0) {
677 printLevel (level + 1);
678 fprintf (stderr, "aAdjSequence [%d].Name = \"%s\";\n", i, USS (adjArray[i].Name));
680 printLevel (level);
681 fprintf (stderr, "}\n");
683 return "aAdjSequence";
685 else if( value >>= segArray )
687 if (segArray.getLength() == 0)
688 return "Sequence< EnhancedCustomShapeSegment >(0)";
690 printLevel (level);
691 fprintf (stderr,"static const sal_uInt16 nValues[] = {\n");
692 printLevel (level);
693 fprintf (stderr,"// Command, Count\n");
694 for( int i = 0; i < segArray.getLength(); i++ ) {
695 printLevel (level + 1);
696 fprintf (stderr,"%d,%d%s\n", segArray[i].Command,
697 segArray[i].Count, i < segArray.getLength() - 1 ? "," : "");
699 printLevel (level);
700 fprintf (stderr,"};\n");
701 return "createSegmentSequence( SAL_N_ELEMENTS( nValues ), nValues )";
703 else if( value >>= segTextFrame )
705 printLevel (level);
706 fprintf (stderr, "Sequence< EnhancedCustomShapeTextFrame > aTextFrameSeq (%" SAL_PRIdINT32 ");\n", segTextFrame.getLength());
707 for( int i=0; i<segTextFrame.getLength(); i++ ) {
708 printLevel (level);
709 fprintf (stderr, "{\n");
710 const char *var = lclDumpAnyValueCode (makeAny (segTextFrame[i]), level + 1);
711 printLevel (level + 1);
712 fprintf (stderr, "aTextFrameSeq [%d] = %s;\n", i, var);
713 printLevel (level);
714 fprintf (stderr, "}\n");
716 return "aTextFrameSeq";
718 else if( value >>= ppArray )
720 printLevel (level);
721 if (ppArray.getLength() == 0)
722 return "Sequence< EnhancedCustomShapeParameterPair >(0)";
724 fprintf (stderr, "static const CustomShapeProvider::ParameterPairData aData[] = {\n");
725 for( int i = 0; i < ppArray.getLength(); i++ ) {
726 printParameterPairData(level + 1, ppArray[i]);
727 fprintf (stderr,"%s\n", i < ppArray.getLength() - 1 ? "," : "");
729 printLevel (level);
730 fprintf (stderr,"};\n");
732 return "createParameterPairSequence(SAL_N_ELEMENTS(aData), aData)";
734 else if( value >>= segment )
736 printLevel (level);
737 fprintf (stderr, "EnhancedCustomShapeSegment aSegment;\n");
738 printLevel (level);
739 // TODO: use EnhancedCustomShapeSegmentCommand constants
740 fprintf (stderr, "aSegment.Command = %d;\n", segment.Command);
741 printLevel (level);
742 fprintf (stderr, "aSegment.Count = %d;\n", segment.Count);
743 return "aSegment";
745 else if( value >>= textFrame )
747 printLevel (level);
748 fprintf (stderr, "EnhancedCustomShapeTextFrame aTextFrame;\n");
749 printLevel (level);
750 fprintf (stderr, "{\n");
752 const char* var = lclDumpAnyValueCode( makeAny (textFrame.TopLeft), level + 1 );
753 printLevel (level + 1);
754 fprintf (stderr, "aTextFrame.TopLeft = %s;\n", var);
756 printLevel (level);
757 fprintf (stderr, "}\n");
759 printLevel (level);
760 fprintf (stderr, "{\n");
762 const char* var = lclDumpAnyValueCode( makeAny (textFrame.BottomRight), level + 1 );
763 printLevel (level + 1);
764 fprintf (stderr, "aTextFrame.BottomRight = %s;\n", var);
766 printLevel (level);
767 fprintf (stderr, "}\n");
769 return "aTextFrame";
771 else if( value >>= pp )
773 printLevel (level);
774 fprintf (stderr, "static const CustomShapeProvider::ParameterPairData aData =\n");
775 printParameterPairData(level, pp);
776 fprintf (stderr, ";\n");
778 return "createParameterPair(&aData)";
780 else if( value >>= par )
782 printLevel (level);
783 fprintf (stderr,"EnhancedCustomShapeParameter aParameter;\n");
784 const char* var = lclDumpAnyValueCode( par.Value, level );
785 printLevel (level);
786 fprintf (stderr,"aParameter.Value = %s;\n", var);
787 printLevel (level);
788 fprintf (stderr,"aParameter.Type = %s;\n",
789 lclGetEnhancedParameterType(par.Type));
790 return "aParameter";
792 else if( value >>= longValue )
794 printLevel (level);
795 fprintf (stderr,"Any aAny ((sal_Int32) %ld);\n", longValue);
796 return "aAny";
798 else if( value >>= intValue )
799 fprintf (stderr,"%" SAL_PRIdINT32 " (hex: %" SAL_PRIxUINT32 ")\n", intValue, intValue);
800 else if( value >>= uintValue )
801 fprintf (stderr,"%" SAL_PRIdINT32 " (hex: %" SAL_PRIxUINT32 ")\n", uintValue, uintValue);
802 else if( value >>= int16Value )
803 fprintf (stderr,"%d (hex: %x)\n", int16Value, int16Value);
804 else if( value >>= uint16Value )
805 fprintf (stderr,"%d (hex: %x)\n", uint16Value, uint16Value);
806 else if( value >>= floatValue )
807 fprintf (stderr,"%f\n", floatValue);
808 else if( value >>= boolValue ) {
809 if (boolValue)
810 return "(sal_Bool) sal_True";
811 else
812 return "(sal_Bool) sal_False";
814 else if( value >>= xNumRule ) {
815 fprintf (stderr, "XIndexReplace\n");
816 for (int k=0; k<xNumRule->getCount(); k++) {
817 Sequence< PropertyValue > aBulletPropSeq;
818 fprintf (stderr, "level %d\n", k);
819 if (xNumRule->getByIndex (k) >>= aBulletPropSeq) {
820 for (int j=0; j<aBulletPropSeq.getLength(); j++) {
821 fprintf(stderr, "%46s = ", USS (aBulletPropSeq[j].Name));
822 lclDumpAnyValue (aBulletPropSeq[j].Value);
827 else if( value >>= aWritingMode )
828 fprintf (stderr, "%d writing mode\n", aWritingMode);
829 else if( value >>= aTextVertAdj ) {
830 const char* s = "unknown";
831 switch( aTextVertAdj ) {
832 case TextVerticalAdjust_TOP:
833 s = "top";
834 break;
835 case TextVerticalAdjust_CENTER:
836 s = "center";
837 break;
838 case TextVerticalAdjust_BOTTOM:
839 s = "bottom";
840 break;
841 case TextVerticalAdjust_BLOCK:
842 s = "block";
843 break;
844 case TextVerticalAdjust_MAKE_FIXED_SIZE:
845 s = "make_fixed_size";
846 break;
848 fprintf (stderr, "%s\n", s);
850 else if( value >>= aTextHorizAdj ) {
851 const char* s = "unknown";
852 switch( aTextHorizAdj ) {
853 case TextHorizontalAdjust_LEFT:
854 s = "left";
855 break;
856 case TextHorizontalAdjust_CENTER:
857 s = "center";
858 break;
859 case TextHorizontalAdjust_RIGHT:
860 s = "right";
861 break;
862 case TextHorizontalAdjust_BLOCK:
863 s = "block";
864 break;
865 case TextHorizontalAdjust_MAKE_FIXED_SIZE:
866 s = "make_fixed_size";
867 break;
869 fprintf (stderr, "%s\n", s);
871 else if( value >>= spacing ) {
872 fprintf (stderr, "mode: %d value: %d\n", spacing.Mode, spacing.Height);
874 else if( value >>= rect ) {
875 printLevel (level);
876 fprintf (stderr, "awt::Rectangle aRectangle;\n");
877 printLevel (level);
878 fprintf (stderr, "aRectangle.X = %" SAL_PRIdINT32 ";\n", rect.X);
879 printLevel (level);
880 fprintf (stderr, "aRectangle.Y = %" SAL_PRIdINT32 ";\n", rect.Y);
881 printLevel (level);
882 fprintf (stderr, "aRectangle.Width = %" SAL_PRIdINT32 ";\n", rect.Width);
883 printLevel (level);
884 fprintf (stderr, "aRectangle.Height = %" SAL_PRIdINT32 ";\n", rect.Height);
885 return "aRectangle";
887 else if( value >>= size ) {
888 printLevel (level);
889 fprintf (stderr, "awt::Size aSize;\n");
890 printLevel (level);
891 fprintf (stderr, "aSize.Width = %" SAL_PRIdINT32 ";\n", size.Width);
892 printLevel (level);
893 fprintf (stderr, "aSize.Height = %" SAL_PRIdINT32 ";\n", size.Height);
894 return "aSize";
896 else if( value.isExtractableTo(::cppu::UnoType<sal_Int32>::get())) {
897 fprintf (stderr,"is extractable to int32\n");
899 else
900 fprintf (stderr,"??? <unhandled type %s>\n", USS(value.getValueTypeName()));
902 return "";
905 void PropertyMap::dumpCode( Reference< XPropertySet > rXPropSet )
907 Reference< XPropertySetInfo > info = rXPropSet->getPropertySetInfo ();
908 Sequence< Property > props = info->getProperties ();
909 const OUString sType = "Type";
911 for (int i=0; i < props.getLength (); i++) {
913 // ignore Type, it is set elsewhere
914 if (props[i].Name.equals (sType))
915 continue;
917 OString name = OUStringToOString( props [i].Name, RTL_TEXTENCODING_UTF8);
918 int level = 1;
920 try {
921 printLevel (level);
922 fprintf (stderr, "{\n");
923 const char* var = lclDumpAnyValueCode (rXPropSet->getPropertyValue (props [i].Name), level + 1);
924 printLevel (level + 1);
925 fprintf (stderr,"aPropertyMap.setProperty(PROP_%s, %s);\n", name.getStr(), var);
926 printLevel (level);
927 fprintf (stderr, "}\n");
928 } catch (const Exception&) {
929 fprintf (stderr,"unable to get '%s' value\n", USS(props [i].Name));
934 void PropertyMap::dumpData(Reference<XPropertySet> xPropertySet)
936 Reference<XPropertySetInfo> xPropertySetInfo = xPropertySet->getPropertySetInfo();
937 Sequence<Property> aProperties = xPropertySetInfo->getProperties();
939 for (int i = 0; i < aProperties.getLength(); ++i)
941 std::cerr << aProperties[i].Name << std::endl;
942 std::cerr << comphelper::anyToString(xPropertySet->getPropertyValue(aProperties[i].Name)) << std::endl;
946 void PropertyMap::dumpCode()
948 dumpCode( Reference< XPropertySet >( makePropertySet(), UNO_QUERY ) );
951 void PropertyMap::dumpData()
953 dumpData( Reference< XPropertySet >( makePropertySet(), UNO_QUERY ) );
955 #endif
957 } // namespace oox
959 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */