GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / oox / source / helper / propertymap.cxx
blobe168cbba6fbc525017db196b65395d36abbe0875
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 #endif
32 #include <com/sun/star/beans/PropertyValue.hpp>
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <com/sun/star/beans/XPropertySetInfo.hpp>
35 #include <com/sun/star/container/XIndexReplace.hpp>
36 #include <com/sun/star/awt/Rectangle.hpp>
37 #include <com/sun/star/awt/Size.hpp>
38 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
39 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
40 #include <com/sun/star/drawing/EnhancedCustomShapeAdjustmentValue.hpp>
41 #include <com/sun/star/drawing/EnhancedCustomShapeSegment.hpp>
42 #include <com/sun/star/drawing/EnhancedCustomShapeTextFrame.hpp>
43 #include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
44 #include <com/sun/star/drawing/EnhancedCustomShapeParameterType.hpp>
45 #include <com/sun/star/drawing/HomogenMatrix3.hpp>
46 #include <cppuhelper/implbase2.hxx>
47 #include <osl/mutex.hxx>
48 #include "oox/token/propertynames.hxx"
49 using ::com::sun::star::uno::Any;
50 using ::com::sun::star::uno::Reference;
51 using ::com::sun::star::uno::RuntimeException;
52 using ::com::sun::star::uno::Sequence;
53 using ::com::sun::star::lang::IllegalArgumentException;
54 using ::com::sun::star::lang::WrappedTargetException;
55 using ::com::sun::star::beans::Property;
56 using ::com::sun::star::beans::PropertyValue;
57 using ::com::sun::star::beans::PropertyVetoException;
58 using ::com::sun::star::beans::UnknownPropertyException;
59 using ::com::sun::star::beans::XPropertyChangeListener;
60 using ::com::sun::star::beans::XPropertySet;
61 using ::com::sun::star::beans::XPropertySetInfo;
62 using ::com::sun::star::beans::XVetoableChangeListener;
63 using ::com::sun::star::container::XIndexReplace;
65 #if OSL_DEBUG_LEVEL > 0
66 #include <cstdio>
67 #include <com/sun/star/style/LineSpacing.hpp>
68 #include <com/sun/star/style/LineSpacingMode.hpp>
69 #include <com/sun/star/text/WritingMode.hpp>
70 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
71 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
72 #define USS(x) OUStringToOString( x, RTL_TEXTENCODING_UTF8 ).getStr()
73 using namespace ::com::sun::star;
74 using namespace ::com::sun::star::drawing;
75 using namespace ::com::sun::star::uno;
76 using ::com::sun::star::style::LineSpacing;
77 using ::com::sun::star::text::WritingMode;
78 using ::com::sun::star::drawing::TextHorizontalAdjust;
79 using ::com::sun::star::drawing::TextVerticalAdjust;
80 #endif
82 namespace oox {
83 using ::com::sun::star::container::XIndexReplace;
85 // ============================================================================
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;
95 // ============================================================================
97 namespace {
99 typedef ::cppu::WeakImplHelper2< XPropertySet, XPropertySetInfo > GenericPropertySetBase;
101 /** This class implements a generic XPropertySet.
103 Properties of all names and types can be set and later retrieved.
104 TODO: move this to comphelper or better find an existing implementation
106 class GenericPropertySet : public GenericPropertySetBase, private ::osl::Mutex
108 public:
109 explicit GenericPropertySet( const PropertyMap& rPropMap );
111 // XPropertySet
112 virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo() throw (RuntimeException);
113 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException);
114 virtual Any SAL_CALL getPropertyValue( const OUString& PropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
115 virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& xListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
116 virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
117 virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
118 virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
120 // XPropertySetInfo
121 virtual Sequence< Property > SAL_CALL getProperties() throw (RuntimeException);
122 virtual Property SAL_CALL getPropertyByName( const OUString& aName ) throw (UnknownPropertyException, RuntimeException);
123 virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) throw (RuntimeException);
125 private:
126 typedef ::std::map< OUString, Any > PropertyNameMap;
127 PropertyNameMap maPropMap;
130 // ----------------------------------------------------------------------------
132 GenericPropertySet::GenericPropertySet( const PropertyMap& rPropMap )
134 const PropertyNameVector& rPropNames = StaticPropertyNameVector::get();
135 for( PropertyMap::const_iterator aIt = rPropMap.begin(), aEnd = rPropMap.end(); aIt != aEnd; ++aIt )
136 maPropMap[ rPropNames[ aIt->first ] ] = aIt->second;
139 Reference< XPropertySetInfo > SAL_CALL GenericPropertySet::getPropertySetInfo() throw (RuntimeException)
141 return this;
144 void SAL_CALL GenericPropertySet::setPropertyValue( const OUString& rPropertyName, const Any& rValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
146 ::osl::MutexGuard aGuard( *this );
147 maPropMap[ rPropertyName ] = rValue;
150 Any SAL_CALL GenericPropertySet::getPropertyValue( const OUString& rPropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
152 PropertyNameMap::iterator aIt = maPropMap.find( rPropertyName );
153 if( aIt == maPropMap.end() )
154 throw UnknownPropertyException();
155 return aIt->second;
158 // listeners are not supported by this implementation
159 void SAL_CALL GenericPropertySet::addPropertyChangeListener( const OUString& , const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
160 void SAL_CALL GenericPropertySet::removePropertyChangeListener( const OUString& , const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
161 void SAL_CALL GenericPropertySet::addVetoableChangeListener( const OUString& , const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
162 void SAL_CALL GenericPropertySet::removeVetoableChangeListener( const OUString& , const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
164 // XPropertySetInfo
165 Sequence< Property > SAL_CALL GenericPropertySet::getProperties() throw (RuntimeException)
167 Sequence< Property > aSeq( static_cast< sal_Int32 >( maPropMap.size() ) );
168 Property* pProperty = aSeq.getArray();
169 for( PropertyNameMap::iterator aIt = maPropMap.begin(), aEnd = maPropMap.end(); aIt != aEnd; ++aIt, ++pProperty )
171 pProperty->Name = aIt->first;
172 pProperty->Handle = 0;
173 pProperty->Type = aIt->second.getValueType();
174 pProperty->Attributes = 0;
176 return aSeq;
179 Property SAL_CALL GenericPropertySet::getPropertyByName( const OUString& rPropertyName ) throw (UnknownPropertyException, RuntimeException)
181 PropertyNameMap::iterator aIt = maPropMap.find( rPropertyName );
182 if( aIt == maPropMap.end() )
183 throw UnknownPropertyException();
184 Property aProperty;
185 aProperty.Name = aIt->first;
186 aProperty.Handle = 0;
187 aProperty.Type = aIt->second.getValueType();
188 aProperty.Attributes = 0;
189 return aProperty;
192 sal_Bool SAL_CALL GenericPropertySet::hasPropertyByName( const OUString& rPropertyName ) throw (RuntimeException)
194 return maPropMap.find( rPropertyName ) != maPropMap.end();
197 } // namespace
199 // ============================================================================
201 PropertyMap::PropertyMap() :
202 mpPropNames( &StaticPropertyNameVector::get() ) // pointer instead reference to get compiler generated copy c'tor and operator=
206 const OUString& PropertyMap::getPropertyName( sal_Int32 nPropId )
208 OSL_ENSURE( (0 <= nPropId) && (nPropId < PROP_COUNT), "PropertyMap::getPropertyName - invalid property identifier" );
209 return StaticPropertyNameVector::get()[ nPropId ];
212 void PropertyMap::assignAll( const PropertyMap& rPropMap )
214 for( PropertyMap::const_iterator it=rPropMap.begin(); it != rPropMap.end(); ++it )
215 (*this)[it->first] = it->second;
218 Sequence< PropertyValue > PropertyMap::makePropertyValueSequence() const
220 Sequence< PropertyValue > aSeq( static_cast< sal_Int32 >( size() ) );
221 if( !empty() )
223 PropertyValue* pValues = aSeq.getArray();
224 for( const_iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt, ++pValues )
226 OSL_ENSURE( (0 <= aIt->first) && (aIt->first < PROP_COUNT), "PropertyMap::makePropertyValueSequence - invalid property identifier" );
227 pValues->Name = (*mpPropNames)[ aIt->first ];
228 pValues->Value = aIt->second;
229 pValues->State = PropertyState_DIRECT_VALUE;
232 return aSeq;
235 void PropertyMap::fillSequences( Sequence< OUString >& rNames, Sequence< Any >& rValues ) const
237 rNames.realloc( static_cast< sal_Int32 >( size() ) );
238 rValues.realloc( static_cast< sal_Int32 >( size() ) );
239 if( !empty() )
241 OUString* pNames = rNames.getArray();
242 Any* pValues = rValues.getArray();
243 for( const_iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt, ++pNames, ++pValues )
245 OSL_ENSURE( (0 <= aIt->first) && (aIt->first < PROP_COUNT), "PropertyMap::fillSequences - invalid property identifier" );
246 *pNames = (*mpPropNames)[ aIt->first ];
247 *pValues = aIt->second;
252 Reference< XPropertySet > PropertyMap::makePropertySet() const
254 return new GenericPropertySet( *this );
257 #if OSL_DEBUG_LEVEL > 0
258 static void lclDumpAnyValue( Any value)
260 OUString strValue;
261 Sequence< OUString > strArray;
262 Sequence< Any > anyArray;
263 Sequence< PropertyValue > propArray;
264 Sequence< Sequence< PropertyValue > > propArrayArray;
265 Sequence< EnhancedCustomShapeAdjustmentValue > adjArray;
266 Sequence< EnhancedCustomShapeSegment > segArray;
267 Sequence< EnhancedCustomShapeParameterPair > ppArray;
268 EnhancedCustomShapeSegment segment;
269 EnhancedCustomShapeParameterPair pp;
270 EnhancedCustomShapeParameter par;
271 HomogenMatrix3 aMatrix;
272 sal_Int32 intValue = 0;
273 sal_uInt32 uintValue = 0;
274 sal_Int16 int16Value = 0;
275 sal_uInt16 uint16Value = 0;
276 float floatValue = 0;
277 bool boolValue = false;
278 LineSpacing spacing;
279 // RectanglePoint pointValue;
280 WritingMode aWritingMode;
281 TextVerticalAdjust aTextVertAdj;
282 TextHorizontalAdjust aTextHorizAdj;
283 Reference< XIndexReplace > xNumRule;
285 if( value >>= strValue )
286 fprintf (stderr,"\"%s\"\n", USS( strValue ) );
287 else if( value >>= strArray ) {
288 fprintf (stderr,"%s\n", USS(value.getValueTypeName()));
289 for( int i=0; i<strArray.getLength(); i++ )
290 fprintf (stderr,"\t\t\t[%3d] \"%s\"\n", i, USS( strArray[i] ) );
291 } else if( value >>= propArray ) {
292 fprintf (stderr,"%s\n", USS(value.getValueTypeName()));
293 for( int i=0; i<propArray.getLength(); i++ ) {
294 fprintf (stderr,"\t\t\t[%3d] %s (%s) ", i, USS( propArray[i].Name ), USS(propArray[i].Value.getValueTypeName()) );
295 lclDumpAnyValue( propArray[i].Value );
297 } else if( value >>= propArrayArray ) {
298 fprintf (stderr,"%s\n", USS(value.getValueTypeName()));
299 for( int i=0; i<propArrayArray.getLength(); i++ ) {
300 fprintf (stderr,"\t\t\t[%3d] ", i);
301 lclDumpAnyValue( makeAny (propArrayArray[i]) );
303 } else if( value >>= anyArray ) {
304 fprintf (stderr,"%s\n", USS(value.getValueTypeName()));
305 for( int i=0; i<anyArray.getLength(); i++ ) {
306 fprintf (stderr,"\t\t\t[%3d] (%s) ", i, USS(value.getValueTypeName()) );
307 lclDumpAnyValue( anyArray[i] );
309 } else if( value >>= adjArray ) {
310 fprintf (stderr,"%s\n", USS(value.getValueTypeName()));
311 for( int i=0; i<adjArray.getLength(); i++ ) {
312 fprintf (stderr,"\t\t\t[%3d] (%s) ", i, USS(adjArray[i].Value.getValueTypeName()) );
313 lclDumpAnyValue( adjArray[i].Value );
315 } else if( value >>= segArray ) {
316 fprintf (stderr,"%s\n", USS(value.getValueTypeName()));
317 for( int i=0; i<segArray.getLength(); i++ ) {
318 fprintf (stderr,"\t\t\t[%3d] ", i );
319 lclDumpAnyValue( makeAny( segArray[i] ) );
321 } else if( value >>= ppArray ) {
322 fprintf (stderr,"%s\n", USS(value.getValueTypeName()));
323 for( int i=0; i<ppArray.getLength(); i++ ) {
324 fprintf (stderr,"\t\t\t[%3d] ", i );
325 lclDumpAnyValue( makeAny( ppArray[i] ) );
327 } else if( value >>= segment ) {
328 fprintf (stderr,"Command: %d Count: %d\n", segment.Command, segment.Count);
329 } else if( value >>= pp ) {
330 fprintf (stderr,"First: ");
331 lclDumpAnyValue( makeAny (pp.First) );
332 fprintf (stderr,"\t\t\t Second: ");
333 lclDumpAnyValue( makeAny (pp.Second) );
334 } else if( value >>= par ) {
335 fprintf (stderr,"Parameter (%s): ", USS(par.Value.getValueTypeName()));
336 lclDumpAnyValue( par.Value );
337 } else if( value >>= aMatrix ) {
338 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);
339 } else if( value >>= intValue )
340 fprintf (stderr,"%" SAL_PRIdINT32 " (hex: %" SAL_PRIxUINT32 ")\n", intValue, intValue);
341 else if( value >>= uintValue )
342 fprintf (stderr,"%" SAL_PRIuUINT32 " (hex: %" SAL_PRIxUINT32 ")\n", uintValue, uintValue);
343 else if( value >>= int16Value )
344 fprintf (stderr,"%d (hex: %x)\n", int16Value, int16Value);
345 else if( value >>= uint16Value )
346 fprintf (stderr,"%d (hex: %x)\n", uint16Value, uint16Value);
347 else if( value >>= floatValue )
348 fprintf (stderr,"%f\n", floatValue);
349 else if( value >>= boolValue )
350 fprintf (stderr,"%d (bool)\n", boolValue);
351 else if( value >>= xNumRule ) {
352 fprintf (stderr, "XIndexReplace\n");
353 if (xNumRule.is()) {
354 for (int k=0; k<xNumRule->getCount(); k++) {
355 Sequence< PropertyValue > aBulletPropSeq;
356 fprintf (stderr, "level %d\n", k);
357 if (xNumRule->getByIndex (k) >>= aBulletPropSeq) {
358 for (int j=0; j<aBulletPropSeq.getLength(); j++) {
359 fprintf(stderr, "%46s = ", USS (aBulletPropSeq[j].Name));
360 lclDumpAnyValue (aBulletPropSeq[j].Value);
364 } else {
365 fprintf (stderr, "empty reference\n");
367 } else if( value >>= aWritingMode )
368 fprintf (stderr, "%d writing mode\n", aWritingMode);
369 else if( value >>= aTextVertAdj ) {
370 const char* s = "unknown";
371 switch( aTextVertAdj ) {
372 case TextVerticalAdjust_TOP:
373 s = "top";
374 break;
375 case TextVerticalAdjust_CENTER:
376 s = "center";
377 break;
378 case TextVerticalAdjust_BOTTOM:
379 s = "bottom";
380 break;
381 case TextVerticalAdjust_BLOCK:
382 s = "block";
383 break;
384 case TextVerticalAdjust_MAKE_FIXED_SIZE:
385 s = "make_fixed_size";
386 break;
388 fprintf (stderr, "%s\n", s);
389 } else if( value >>= aTextHorizAdj ) {
390 const char* s = "unknown";
391 switch( aTextHorizAdj ) {
392 case TextHorizontalAdjust_LEFT:
393 s = "left";
394 break;
395 case TextHorizontalAdjust_CENTER:
396 s = "center";
397 break;
398 case TextHorizontalAdjust_RIGHT:
399 s = "right";
400 break;
401 case TextHorizontalAdjust_BLOCK:
402 s = "block";
403 break;
404 case TextHorizontalAdjust_MAKE_FIXED_SIZE:
405 s = "make_fixed_size";
406 break;
408 fprintf (stderr, "%s\n", s);
409 } else if( value >>= spacing ) {
410 fprintf (stderr, "mode: %d value: %d\n", spacing.Mode, spacing.Height);
411 } else if( value.isExtractableTo(::getCppuType((const sal_Int32*)0))) {
412 fprintf (stderr,"is extractable to int32\n");
414 // else if( value >>= pointValue )
415 // fprintf (stderr,"%d (RectanglePoint)\n", pointValue);
416 else
417 fprintf (stderr,"??? <unhandled type %s>\n", USS(value.getValueTypeName()));
420 #ifdef DBG_UTIL
421 void PropertyMap::dump( Reference< XPropertySet > rXPropSet )
423 Reference< XPropertySetInfo > info = rXPropSet->getPropertySetInfo ();
424 Sequence< Property > props = info->getProperties ();
426 OSL_TRACE("dump props, len: %d", props.getLength ());
428 for (int i=0; i < props.getLength (); i++) {
429 OString name = OUStringToOString( props [i].Name, RTL_TEXTENCODING_UTF8);
430 fprintf (stderr,"%30s = ", name.getStr() );
432 try {
433 lclDumpAnyValue (rXPropSet->getPropertyValue( props [i].Name ));
434 } catch (const Exception&) {
435 fprintf (stderr,"unable to get '%s' value\n", USS(props [i].Name));
439 #endif
441 static void printLevel (int level)
443 for (int i=0; i<level; i++)
444 fprintf (stderr, " ");
447 static const char *lclGetEnhancedParameterType( sal_uInt16 nType )
449 const char* type;
450 switch (nType) {
451 case EnhancedCustomShapeParameterType::NORMAL:
452 type = "EnhancedCustomShapeParameterType::NORMAL";
453 break;
454 case EnhancedCustomShapeParameterType::EQUATION:
455 type = "EnhancedCustomShapeParameterType::EQUATION";
456 break;
457 case EnhancedCustomShapeParameterType::ADJUSTMENT:
458 type = "EnhancedCustomShapeParameterType::ADJUSTMENT";
459 break;
460 case EnhancedCustomShapeParameterType::LEFT:
461 type = "EnhancedCustomShapeParameterType::LEFT";
462 break;
463 case EnhancedCustomShapeParameterType::TOP:
464 type = "EnhancedCustomShapeParameterType::TOP";
465 break;
466 case EnhancedCustomShapeParameterType::RIGHT:
467 type = "EnhancedCustomShapeParameterType::RIGHT";
468 break;
469 case EnhancedCustomShapeParameterType::BOTTOM:
470 type = "EnhancedCustomShapeParameterType::BOTTOM";
471 break;
472 case EnhancedCustomShapeParameterType::XSTRETCH:
473 type = "EnhancedCustomShapeParameterType::XSTRETCH";
474 break;
475 case EnhancedCustomShapeParameterType::YSTRETCH:
476 type = "EnhancedCustomShapeParameterType::YSTRETCH";
477 break;
478 case EnhancedCustomShapeParameterType::HASSTROKE:
479 type = "EnhancedCustomShapeParameterType::HASSTROKE";
480 break;
481 case EnhancedCustomShapeParameterType::HASFILL:
482 type = "EnhancedCustomShapeParameterType::HASFILL";
483 break;
484 case EnhancedCustomShapeParameterType::WIDTH:
485 type = "EnhancedCustomShapeParameterType::WIDTH";
486 break;
487 case EnhancedCustomShapeParameterType::HEIGHT:
488 type = "EnhancedCustomShapeParameterType::HEIGHT";
489 break;
490 case EnhancedCustomShapeParameterType::LOGWIDTH:
491 type = "EnhancedCustomShapeParameterType::LOGWIDTH";
492 break;
493 case EnhancedCustomShapeParameterType::LOGHEIGHT:
494 type = "EnhancedCustomShapeParameterType::LOGHEIGHT";
495 break;
496 default:
497 type = "unknown";
498 break;
500 return type;
503 static void printParameterPairData(int level, EnhancedCustomShapeParameterPair &pp)
505 // These are always sal_Int32s so lets depend on that for our packing ...
506 sal_Int32 nFirstValue, nSecondValue;
507 if (!(pp.First.Value >>= nFirstValue))
508 assert (false);
509 if (!(pp.Second.Value >>= nSecondValue))
510 assert (false);
512 printLevel (level);
513 fprintf (stderr, "{\n");
514 printLevel (level + 1);
515 fprintf (stderr, "%s,\n", lclGetEnhancedParameterType(pp.First.Type));
516 printLevel (level + 1);
517 fprintf (stderr, "%s,\n", lclGetEnhancedParameterType(pp.Second.Type));
518 printLevel (level + 1);
519 fprintf (stderr, "%d, %d\n", (int)nFirstValue, (int)nSecondValue);
520 printLevel (level);
521 fprintf (stderr, "}");
524 static const char* lclDumpAnyValueCode( Any value, int level = 0)
526 OUString strValue;
527 Sequence< OUString > strArray;
528 Sequence< Any > anyArray;
529 Sequence< awt::Size > sizeArray;
530 Sequence< PropertyValue > propArray;
531 Sequence< Sequence< PropertyValue > > propArrayArray;
532 Sequence< EnhancedCustomShapeAdjustmentValue > adjArray;
533 Sequence< EnhancedCustomShapeTextFrame > segTextFrame;
534 Sequence< EnhancedCustomShapeSegment > segArray;
535 Sequence< EnhancedCustomShapeParameterPair > ppArray;
536 EnhancedCustomShapeSegment segment;
537 EnhancedCustomShapeTextFrame textFrame;
538 EnhancedCustomShapeParameterPair pp;
539 EnhancedCustomShapeParameter par;
540 awt::Rectangle rect;
541 awt::Size size;
542 sal_Int32 intValue;
543 sal_uInt32 uintValue;
544 sal_Int16 int16Value;
545 sal_uInt16 uint16Value;
546 long longValue;
547 float floatValue = 0;
548 bool boolValue;
549 LineSpacing spacing;
550 // RectanglePoint pointValue;
551 WritingMode aWritingMode;
552 TextVerticalAdjust aTextVertAdj;
553 TextHorizontalAdjust aTextHorizAdj;
554 Reference< XIndexReplace > xNumRule;
556 if( value >>= strValue ) {
557 printLevel (level);
558 fprintf (stderr,"OUString str = \"%s\";\n", USS( strValue ) );
559 return "Any (str)";
560 } else if( value >>= strArray ) {
561 if (strArray.getLength() == 0)
562 return "Sequence< OUString >(0)";
564 printLevel (level);
565 fprintf (stderr,"static const char *aStrings[] = {\n");
566 for( int i=0; i<strArray.getLength(); i++ ) {
567 printLevel (level + 1);
568 fprintf (stderr,"\"%s\"%s\n", USS( strArray[i] ), i < strArray.getLength() - 1 ? "," : "" );
570 printLevel (level);
571 fprintf (stderr,"};\n");
572 return "createStringSequence( SAL_N_ELEMENTS( aStrings ), aStrings )";
573 } else if( value >>= propArray ) {
574 printLevel (level);
575 fprintf (stderr,"Sequence< PropertyValue > aPropSequence (%" SAL_PRIdINT32 ");\n", propArray.getLength());
576 for( int i=0; i<propArray.getLength(); i++ ) {
577 printLevel (level);
578 fprintf (stderr, "{\n");
579 printLevel (level + 1);
580 fprintf (stderr, "aPropSequence [%d].Name = \"%s\";\n", i, USS( propArray[i].Name ));
581 const char *var = lclDumpAnyValueCode( propArray[i].Value, level + 1 );
582 printLevel (level + 1);
583 fprintf (stderr, "aPropSequence [%d].Value = makeAny (%s);\n", i, var);
584 printLevel (level);
585 fprintf (stderr, "}\n");
587 return "aPropSequence";
588 } else if( value >>= sizeArray ) {
589 printLevel (level);
590 fprintf (stderr, "Sequence< awt::Size > aSizeSequence (%" SAL_PRIdINT32 ");\n", sizeArray.getLength());
591 for( int i=0; i<sizeArray.getLength(); i++ ) {
592 printLevel (level);
593 fprintf (stderr, "{\n");
594 const char *var = lclDumpAnyValueCode (makeAny (sizeArray[i]), level + 1);
595 printLevel (level + 1);
596 fprintf (stderr, "aSizeSequence [%d] = %s;\n", i, var);
597 printLevel (level);
598 fprintf (stderr, "}\n");
600 return "aSizeSequence";
601 } else if( value >>= propArrayArray ) {
602 printLevel (level);
603 fprintf (stderr,"Sequence< Sequence < PropertyValue > > aPropSequenceSequence (%" SAL_PRIdINT32 ");\n", propArrayArray.getLength());
604 for( int i=0; i<propArrayArray.getLength(); i++ ) {
605 printLevel (level);
606 fprintf (stderr, "{\n");
607 const char *var = lclDumpAnyValueCode( makeAny (propArrayArray[i]), level + 1 );
608 printLevel (level + 1);
609 fprintf (stderr, "aPropSequenceSequence [%d] = %s;\n", i, var);
610 printLevel (level);
611 fprintf (stderr, "}\n");
613 return "aPropSequenceSequence";
614 } else if( value >>= anyArray ) {
615 fprintf (stderr,"%s\n", USS(value.getValueTypeName()));
616 for( int i=0; i<anyArray.getLength(); i++ ) {
617 fprintf (stderr,"\t\t\t[%3d] (%s) ", i, USS(value.getValueTypeName()) );
618 lclDumpAnyValue( anyArray[i] );
620 } else if( value >>= adjArray ) {
621 printLevel (level);
622 fprintf (stderr,"Sequence< EnhancedCustomShapeAdjustmentValue > aAdjSequence (%" SAL_PRIdINT32 ");\n", adjArray.getLength());
623 for( int i=0; i<adjArray.getLength(); i++ ) {
624 printLevel (level);
625 fprintf (stderr, "{\n");
626 const char *var = lclDumpAnyValueCode( makeAny (adjArray[i].Value), level + 1 );
627 printLevel (level + 1);
628 fprintf (stderr, "aAdjSequence [%d].Value = %s;\n", i, var);
629 if (adjArray[i].Name.getLength() > 0) {
630 printLevel (level + 1);
631 fprintf (stderr, "aAdjSequence [%d].Name = \"%s\";\n", i, USS (adjArray[i].Name));
633 printLevel (level);
634 fprintf (stderr, "}\n");
636 return "aAdjSequence";
637 } else if( value >>= segArray ) {
638 if (segArray.getLength() == 0)
639 return "Sequence< EnhancedCustomShapeSegment >(0)";
641 printLevel (level);
642 fprintf (stderr,"static const sal_uInt16 nValues[] = {\n");
643 printLevel (level);
644 fprintf (stderr,"// Command, Count\n");
645 for( int i = 0; i < segArray.getLength(); i++ ) {
646 printLevel (level + 1);
647 fprintf (stderr,"%d,%d%s\n", segArray[i].Command,
648 segArray[i].Count, i < segArray.getLength() - 1 ? "," : "");
650 printLevel (level);
651 fprintf (stderr,"};\n");
652 return "createSegmentSequence( SAL_N_ELEMENTS( nValues ), nValues )";
653 } else if( value >>= segTextFrame ) {
654 printLevel (level);
655 fprintf (stderr, "Sequence< EnhancedCustomShapeTextFrame > aTextFrameSeq (%" SAL_PRIdINT32 ");\n", segTextFrame.getLength());
656 for( int i=0; i<segTextFrame.getLength(); i++ ) {
657 printLevel (level);
658 fprintf (stderr, "{\n");
659 const char *var = lclDumpAnyValueCode (makeAny (segTextFrame[i]), level + 1);
660 printLevel (level + 1);
661 fprintf (stderr, "aTextFrameSeq [%d] = %s;\n", i, var);
662 printLevel (level);
663 fprintf (stderr, "}\n");
665 return "aTextFrameSeq";
666 } else if( value >>= ppArray ) {
667 printLevel (level);
668 if (ppArray.getLength() == 0)
669 return "Sequence< EnhancedCustomShapeParameterPair >(0)";
671 fprintf (stderr, "static const CustomShapeProvider::ParameterPairData aData[] = {\n");
672 for( int i = 0; i < ppArray.getLength(); i++ ) {
673 printParameterPairData(level + 1, ppArray[i]);
674 fprintf (stderr,"%s\n", i < ppArray.getLength() - 1 ? "," : "");
676 printLevel (level);
677 fprintf (stderr,"};\n");
679 return "createParameterPairSequence(SAL_N_ELEMENTS(aData), aData)";
680 } else if( value >>= segment ) {
681 printLevel (level);
682 fprintf (stderr, "EnhancedCustomShapeSegment aSegment;\n");
683 printLevel (level);
684 // TODO: use EnhancedCustomShapeSegmentCommand constants
685 fprintf (stderr, "aSegment.Command = %d;\n", segment.Command);
686 printLevel (level);
687 fprintf (stderr, "aSegment.Count = %d;\n", segment.Count);
688 return "aSegment";
689 } else if( value >>= textFrame ) {
690 printLevel (level);
691 fprintf (stderr, "EnhancedCustomShapeTextFrame aTextFrame;\n");
692 printLevel (level);
693 fprintf (stderr, "{\n");
695 const char* var = lclDumpAnyValueCode( makeAny (textFrame.TopLeft), level + 1 );
696 printLevel (level + 1);
697 fprintf (stderr, "aTextFrame.TopLeft = %s;\n", var);
699 printLevel (level);
700 fprintf (stderr, "}\n");
702 printLevel (level);
703 fprintf (stderr, "{\n");
705 const char* var = lclDumpAnyValueCode( makeAny (textFrame.BottomRight), level + 1 );
706 printLevel (level + 1);
707 fprintf (stderr, "aTextFrame.BottomRight = %s;\n", var);
709 printLevel (level);
710 fprintf (stderr, "}\n");
712 return "aTextFrame";
713 } else if( value >>= pp ) {
714 printLevel (level);
715 fprintf (stderr, "static const CustomShapeProvider::ParameterPairData aData =\n");
716 printParameterPairData(level, pp);
717 fprintf (stderr, ";\n");
719 return "createParameterPair(&aData)";
720 } else if( value >>= par ) {
721 printLevel (level);
722 fprintf (stderr,"EnhancedCustomShapeParameter aParameter;\n");
723 const char* var = lclDumpAnyValueCode( par.Value, level );
724 printLevel (level);
725 fprintf (stderr,"aParameter.Value = %s;\n", var);
726 printLevel (level);
727 fprintf (stderr,"aParameter.Type = %s;\n",
728 lclGetEnhancedParameterType(par.Type));
729 return "aParameter";
730 } else if( value >>= longValue ) {
731 printLevel (level);
732 fprintf (stderr,"Any aAny ((sal_Int32) %ld);\n", longValue);
733 return "aAny";
734 } else if( value >>= intValue )
735 fprintf (stderr,"%" SAL_PRIdINT32 " (hex: %" SAL_PRIxUINT32 ")\n", intValue, intValue);
736 else if( value >>= uintValue )
737 fprintf (stderr,"%" SAL_PRIdINT32 " (hex: %" SAL_PRIxUINT32 ")\n", uintValue, uintValue);
738 else if( value >>= int16Value )
739 fprintf (stderr,"%d (hex: %x)\n", int16Value, int16Value);
740 else if( value >>= uint16Value )
741 fprintf (stderr,"%d (hex: %x)\n", uint16Value, uint16Value);
742 else if( value >>= floatValue )
743 fprintf (stderr,"%f\n", floatValue);
744 else if( value >>= boolValue ) {
745 if (boolValue)
746 return "Any ((sal_Bool) sal_True)";
747 else
748 return "Any ((sal_Bool) sal_False)";
749 } else if( value >>= xNumRule ) {
750 fprintf (stderr, "XIndexReplace\n");
751 for (int k=0; k<xNumRule->getCount(); k++) {
752 Sequence< PropertyValue > aBulletPropSeq;
753 fprintf (stderr, "level %d\n", k);
754 if (xNumRule->getByIndex (k) >>= aBulletPropSeq) {
755 for (int j=0; j<aBulletPropSeq.getLength(); j++) {
756 fprintf(stderr, "%46s = ", USS (aBulletPropSeq[j].Name));
757 lclDumpAnyValue (aBulletPropSeq[j].Value);
761 } else if( value >>= aWritingMode )
762 fprintf (stderr, "%d writing mode\n", aWritingMode);
763 else if( value >>= aTextVertAdj ) {
764 const char* s = "unknown";
765 switch( aTextVertAdj ) {
766 case TextVerticalAdjust_TOP:
767 s = "top";
768 break;
769 case TextVerticalAdjust_CENTER:
770 s = "center";
771 break;
772 case TextVerticalAdjust_BOTTOM:
773 s = "bottom";
774 break;
775 case TextVerticalAdjust_BLOCK:
776 s = "block";
777 break;
778 case TextVerticalAdjust_MAKE_FIXED_SIZE:
779 s = "make_fixed_size";
780 break;
782 fprintf (stderr, "%s\n", s);
783 } else if( value >>= aTextHorizAdj ) {
784 const char* s = "unknown";
785 switch( aTextHorizAdj ) {
786 case TextHorizontalAdjust_LEFT:
787 s = "left";
788 break;
789 case TextHorizontalAdjust_CENTER:
790 s = "center";
791 break;
792 case TextHorizontalAdjust_RIGHT:
793 s = "right";
794 break;
795 case TextHorizontalAdjust_BLOCK:
796 s = "block";
797 break;
798 case TextHorizontalAdjust_MAKE_FIXED_SIZE:
799 s = "make_fixed_size";
800 break;
802 fprintf (stderr, "%s\n", s);
803 } else if( value >>= spacing ) {
804 fprintf (stderr, "mode: %d value: %d\n", spacing.Mode, spacing.Height);
805 } else if( value >>= rect ) {
806 printLevel (level);
807 fprintf (stderr, "awt::Rectangle aRectangle;\n");
808 printLevel (level);
809 fprintf (stderr, "aRectangle.X = %" SAL_PRIdINT32 ";\n", rect.X);
810 printLevel (level);
811 fprintf (stderr, "aRectangle.Y = %" SAL_PRIdINT32 ";\n", rect.Y);
812 printLevel (level);
813 fprintf (stderr, "aRectangle.Width = %" SAL_PRIdINT32 ";\n", rect.Width);
814 printLevel (level);
815 fprintf (stderr, "aRectangle.Height = %" SAL_PRIdINT32 ";\n", rect.Height);
816 return "aRectangle";
817 } else if( value >>= size ) {
818 printLevel (level);
819 fprintf (stderr, "awt::Size aSize;\n");
820 printLevel (level);
821 fprintf (stderr, "aSize.Width = %" SAL_PRIdINT32 ";\n", size.Width);
822 printLevel (level);
823 fprintf (stderr, "aSize.Height = %" SAL_PRIdINT32 ";\n", size.Height);
824 return "aSize";
825 } else if( value.isExtractableTo(::getCppuType((const sal_Int32*)0))) {
826 fprintf (stderr,"is extractable to int32\n");
828 else
829 fprintf (stderr,"??? <unhandled type %s>\n", USS(value.getValueTypeName()));
831 return "";
834 void PropertyMap::dumpCode( Reference< XPropertySet > rXPropSet )
836 Reference< XPropertySetInfo > info = rXPropSet->getPropertySetInfo ();
837 Sequence< Property > props = info->getProperties ();
838 const OUString sType = "Type";
840 for (int i=0; i < props.getLength (); i++) {
842 // ignore Type, it is set elsewhere
843 if (props[i].Name.equals (sType))
844 continue;
846 OString name = OUStringToOString( props [i].Name, RTL_TEXTENCODING_UTF8);
847 int level = 1;
849 try {
850 printLevel (level);
851 fprintf (stderr, "{\n");
852 const char* var = lclDumpAnyValueCode (rXPropSet->getPropertyValue (props [i].Name), level + 1);
853 printLevel (level + 1);
854 fprintf (stderr,"aPropertyMap [PROP_%s] <<= %s;\n", name.getStr(), var);
855 printLevel (level);
856 fprintf (stderr, "}\n");
857 } catch (const Exception&) {
858 fprintf (stderr,"unable to get '%s' value\n", USS(props [i].Name));
863 void PropertyMap::dumpCode()
865 dumpCode( Reference< XPropertySet >( makePropertySet(), UNO_QUERY ) );
867 #endif
869 // ============================================================================
871 } // namespace oox
873 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */