1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
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
;
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
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
;
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 // ============================================================================
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
109 explicit GenericPropertySet( const PropertyMap
& rPropMap
);
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
);
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
);
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
)
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();
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
) {}
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;
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();
185 aProperty
.Name
= aIt
->first
;
186 aProperty
.Handle
= 0;
187 aProperty
.Type
= aIt
->second
.getValueType();
188 aProperty
.Attributes
= 0;
192 sal_Bool SAL_CALL
GenericPropertySet::hasPropertyByName( const OUString
& rPropertyName
) throw (RuntimeException
)
194 return maPropMap
.find( rPropertyName
) != maPropMap
.end();
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() ) );
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
;
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() ) );
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
)
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;
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");
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
);
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
:
375 case TextVerticalAdjust_CENTER
:
378 case TextVerticalAdjust_BOTTOM
:
381 case TextVerticalAdjust_BLOCK
:
384 case TextVerticalAdjust_MAKE_FIXED_SIZE
:
385 s
= "make_fixed_size";
388 fprintf (stderr
, "%s\n", s
);
389 } else if( value
>>= aTextHorizAdj
) {
390 const char* s
= "unknown";
391 switch( aTextHorizAdj
) {
392 case TextHorizontalAdjust_LEFT
:
395 case TextHorizontalAdjust_CENTER
:
398 case TextHorizontalAdjust_RIGHT
:
401 case TextHorizontalAdjust_BLOCK
:
404 case TextHorizontalAdjust_MAKE_FIXED_SIZE
:
405 s
= "make_fixed_size";
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);
417 fprintf (stderr
,"??? <unhandled type %s>\n", USS(value
.getValueTypeName()));
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() );
433 lclDumpAnyValue (rXPropSet
->getPropertyValue( props
[i
].Name
));
434 } catch (const Exception
&) {
435 fprintf (stderr
,"unable to get '%s' value\n", USS(props
[i
].Name
));
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
)
451 case EnhancedCustomShapeParameterType::NORMAL
:
452 type
= "EnhancedCustomShapeParameterType::NORMAL";
454 case EnhancedCustomShapeParameterType::EQUATION
:
455 type
= "EnhancedCustomShapeParameterType::EQUATION";
457 case EnhancedCustomShapeParameterType::ADJUSTMENT
:
458 type
= "EnhancedCustomShapeParameterType::ADJUSTMENT";
460 case EnhancedCustomShapeParameterType::LEFT
:
461 type
= "EnhancedCustomShapeParameterType::LEFT";
463 case EnhancedCustomShapeParameterType::TOP
:
464 type
= "EnhancedCustomShapeParameterType::TOP";
466 case EnhancedCustomShapeParameterType::RIGHT
:
467 type
= "EnhancedCustomShapeParameterType::RIGHT";
469 case EnhancedCustomShapeParameterType::BOTTOM
:
470 type
= "EnhancedCustomShapeParameterType::BOTTOM";
472 case EnhancedCustomShapeParameterType::XSTRETCH
:
473 type
= "EnhancedCustomShapeParameterType::XSTRETCH";
475 case EnhancedCustomShapeParameterType::YSTRETCH
:
476 type
= "EnhancedCustomShapeParameterType::YSTRETCH";
478 case EnhancedCustomShapeParameterType::HASSTROKE
:
479 type
= "EnhancedCustomShapeParameterType::HASSTROKE";
481 case EnhancedCustomShapeParameterType::HASFILL
:
482 type
= "EnhancedCustomShapeParameterType::HASFILL";
484 case EnhancedCustomShapeParameterType::WIDTH
:
485 type
= "EnhancedCustomShapeParameterType::WIDTH";
487 case EnhancedCustomShapeParameterType::HEIGHT
:
488 type
= "EnhancedCustomShapeParameterType::HEIGHT";
490 case EnhancedCustomShapeParameterType::LOGWIDTH
:
491 type
= "EnhancedCustomShapeParameterType::LOGWIDTH";
493 case EnhancedCustomShapeParameterType::LOGHEIGHT
:
494 type
= "EnhancedCustomShapeParameterType::LOGHEIGHT";
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
))
509 if (!(pp
.Second
.Value
>>= nSecondValue
))
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
);
521 fprintf (stderr
, "}");
524 static const char* lclDumpAnyValueCode( Any value
, int level
= 0)
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
;
543 sal_uInt32 uintValue
;
544 sal_Int16 int16Value
;
545 sal_uInt16 uint16Value
;
547 float floatValue
= 0;
550 // RectanglePoint pointValue;
551 WritingMode aWritingMode
;
552 TextVerticalAdjust aTextVertAdj
;
553 TextHorizontalAdjust aTextHorizAdj
;
554 Reference
< XIndexReplace
> xNumRule
;
556 if( value
>>= strValue
) {
558 fprintf (stderr
,"OUString str = \"%s\";\n", USS( strValue
) );
560 } else if( value
>>= strArray
) {
561 if (strArray
.getLength() == 0)
562 return "Sequence< OUString >(0)";
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 ? "," : "" );
571 fprintf (stderr
,"};\n");
572 return "createStringSequence( SAL_N_ELEMENTS( aStrings ), aStrings )";
573 } else if( value
>>= propArray
) {
575 fprintf (stderr
,"Sequence< PropertyValue > aPropSequence (%" SAL_PRIdINT32
");\n", propArray
.getLength());
576 for( int i
=0; i
<propArray
.getLength(); i
++ ) {
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
);
585 fprintf (stderr
, "}\n");
587 return "aPropSequence";
588 } else if( value
>>= sizeArray
) {
590 fprintf (stderr
, "Sequence< awt::Size > aSizeSequence (%" SAL_PRIdINT32
");\n", sizeArray
.getLength());
591 for( int i
=0; i
<sizeArray
.getLength(); i
++ ) {
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
);
598 fprintf (stderr
, "}\n");
600 return "aSizeSequence";
601 } else if( value
>>= propArrayArray
) {
603 fprintf (stderr
,"Sequence< Sequence < PropertyValue > > aPropSequenceSequence (%" SAL_PRIdINT32
");\n", propArrayArray
.getLength());
604 for( int i
=0; i
<propArrayArray
.getLength(); i
++ ) {
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
);
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
) {
622 fprintf (stderr
,"Sequence< EnhancedCustomShapeAdjustmentValue > aAdjSequence (%" SAL_PRIdINT32
");\n", adjArray
.getLength());
623 for( int i
=0; i
<adjArray
.getLength(); i
++ ) {
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
));
634 fprintf (stderr
, "}\n");
636 return "aAdjSequence";
637 } else if( value
>>= segArray
) {
638 if (segArray
.getLength() == 0)
639 return "Sequence< EnhancedCustomShapeSegment >(0)";
642 fprintf (stderr
,"static const sal_uInt16 nValues[] = {\n");
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 ? "," : "");
651 fprintf (stderr
,"};\n");
652 return "createSegmentSequence( SAL_N_ELEMENTS( nValues ), nValues )";
653 } else if( value
>>= segTextFrame
) {
655 fprintf (stderr
, "Sequence< EnhancedCustomShapeTextFrame > aTextFrameSeq (%" SAL_PRIdINT32
");\n", segTextFrame
.getLength());
656 for( int i
=0; i
<segTextFrame
.getLength(); i
++ ) {
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
);
663 fprintf (stderr
, "}\n");
665 return "aTextFrameSeq";
666 } else if( value
>>= ppArray
) {
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 ? "," : "");
677 fprintf (stderr
,"};\n");
679 return "createParameterPairSequence(SAL_N_ELEMENTS(aData), aData)";
680 } else if( value
>>= segment
) {
682 fprintf (stderr
, "EnhancedCustomShapeSegment aSegment;\n");
684 // TODO: use EnhancedCustomShapeSegmentCommand constants
685 fprintf (stderr
, "aSegment.Command = %d;\n", segment
.Command
);
687 fprintf (stderr
, "aSegment.Count = %d;\n", segment
.Count
);
689 } else if( value
>>= textFrame
) {
691 fprintf (stderr
, "EnhancedCustomShapeTextFrame aTextFrame;\n");
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
);
700 fprintf (stderr
, "}\n");
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
);
710 fprintf (stderr
, "}\n");
713 } else if( value
>>= pp
) {
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
) {
722 fprintf (stderr
,"EnhancedCustomShapeParameter aParameter;\n");
723 const char* var
= lclDumpAnyValueCode( par
.Value
, level
);
725 fprintf (stderr
,"aParameter.Value = %s;\n", var
);
727 fprintf (stderr
,"aParameter.Type = %s;\n",
728 lclGetEnhancedParameterType(par
.Type
));
730 } else if( value
>>= longValue
) {
732 fprintf (stderr
,"Any aAny ((sal_Int32) %ld);\n", longValue
);
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
) {
746 return "Any ((sal_Bool) sal_True)";
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
:
769 case TextVerticalAdjust_CENTER
:
772 case TextVerticalAdjust_BOTTOM
:
775 case TextVerticalAdjust_BLOCK
:
778 case TextVerticalAdjust_MAKE_FIXED_SIZE
:
779 s
= "make_fixed_size";
782 fprintf (stderr
, "%s\n", s
);
783 } else if( value
>>= aTextHorizAdj
) {
784 const char* s
= "unknown";
785 switch( aTextHorizAdj
) {
786 case TextHorizontalAdjust_LEFT
:
789 case TextHorizontalAdjust_CENTER
:
792 case TextHorizontalAdjust_RIGHT
:
795 case TextHorizontalAdjust_BLOCK
:
798 case TextHorizontalAdjust_MAKE_FIXED_SIZE
:
799 s
= "make_fixed_size";
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
) {
807 fprintf (stderr
, "awt::Rectangle aRectangle;\n");
809 fprintf (stderr
, "aRectangle.X = %" SAL_PRIdINT32
";\n", rect
.X
);
811 fprintf (stderr
, "aRectangle.Y = %" SAL_PRIdINT32
";\n", rect
.Y
);
813 fprintf (stderr
, "aRectangle.Width = %" SAL_PRIdINT32
";\n", rect
.Width
);
815 fprintf (stderr
, "aRectangle.Height = %" SAL_PRIdINT32
";\n", rect
.Height
);
817 } else if( value
>>= size
) {
819 fprintf (stderr
, "awt::Size aSize;\n");
821 fprintf (stderr
, "aSize.Width = %" SAL_PRIdINT32
";\n", size
.Width
);
823 fprintf (stderr
, "aSize.Height = %" SAL_PRIdINT32
";\n", size
.Height
);
825 } else if( value
.isExtractableTo(::getCppuType((const sal_Int32
*)0))) {
826 fprintf (stderr
,"is extractable to int32\n");
829 fprintf (stderr
,"??? <unhandled type %s>\n", USS(value
.getValueTypeName()));
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
))
846 OString name
= OUStringToOString( props
[i
].Name
, RTL_TEXTENCODING_UTF8
);
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
);
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
) );
869 // ============================================================================
873 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */