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
;
30 #include <comphelper/anytostring.hxx>
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
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
;
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
;
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
106 explicit GenericPropertySet( const PropertyMap
& rPropMap
);
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
;
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
;
124 PropertyNameMap maPropMap
;
127 GenericPropertySet::GenericPropertySet( const PropertyMap
& rPropMap
)
129 rPropMap
.fillPropertyNameMap(maPropMap
);
132 Reference
< XPropertySetInfo
> SAL_CALL
GenericPropertySet::getPropertySetInfo() throw (RuntimeException
, std::exception
)
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();
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
) {}
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;
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();
178 aProperty
.Name
= aIt
->first
;
179 aProperty
.Handle
= 0;
180 aProperty
.Type
= aIt
->second
.getValueType();
181 aProperty
.Attributes
= 0;
185 sal_Bool SAL_CALL
GenericPropertySet::hasPropertyByName( const OUString
& rPropertyName
) throw (RuntimeException
, std::exception
)
187 return maPropMap
.find( rPropertyName
) != maPropMap
.end();
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
)
207 maProperties
[ nPropId
] = rValue
;
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
;
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
)
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;
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");
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
);
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
:
409 case TextVerticalAdjust_CENTER
:
412 case TextVerticalAdjust_BOTTOM
:
415 case TextVerticalAdjust_BLOCK
:
418 case TextVerticalAdjust_MAKE_FIXED_SIZE
:
419 s
= "make_fixed_size";
422 fprintf (stderr
, "%s\n", s
);
423 } else if( value
>>= aTextHorizAdj
) {
424 const char* s
= "unknown";
425 switch( aTextHorizAdj
) {
426 case TextHorizontalAdjust_LEFT
:
429 case TextHorizontalAdjust_CENTER
:
432 case TextHorizontalAdjust_RIGHT
:
435 case TextHorizontalAdjust_BLOCK
:
438 case TextHorizontalAdjust_MAKE_FIXED_SIZE
:
439 s
= "make_fixed_size";
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);
451 fprintf (stderr
,"??? <unhandled type %s>\n", USS(value
.getValueTypeName()));
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() );
467 lclDumpAnyValue (rXPropSet
->getPropertyValue( props
[i
].Name
));
468 } catch (const Exception
&) {
469 fprintf (stderr
,"unable to get '%s' value\n", USS(props
[i
].Name
));
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
)
485 case EnhancedCustomShapeParameterType::NORMAL
:
486 type
= "EnhancedCustomShapeParameterType::NORMAL";
488 case EnhancedCustomShapeParameterType::EQUATION
:
489 type
= "EnhancedCustomShapeParameterType::EQUATION";
491 case EnhancedCustomShapeParameterType::ADJUSTMENT
:
492 type
= "EnhancedCustomShapeParameterType::ADJUSTMENT";
494 case EnhancedCustomShapeParameterType::LEFT
:
495 type
= "EnhancedCustomShapeParameterType::LEFT";
497 case EnhancedCustomShapeParameterType::TOP
:
498 type
= "EnhancedCustomShapeParameterType::TOP";
500 case EnhancedCustomShapeParameterType::RIGHT
:
501 type
= "EnhancedCustomShapeParameterType::RIGHT";
503 case EnhancedCustomShapeParameterType::BOTTOM
:
504 type
= "EnhancedCustomShapeParameterType::BOTTOM";
506 case EnhancedCustomShapeParameterType::XSTRETCH
:
507 type
= "EnhancedCustomShapeParameterType::XSTRETCH";
509 case EnhancedCustomShapeParameterType::YSTRETCH
:
510 type
= "EnhancedCustomShapeParameterType::YSTRETCH";
512 case EnhancedCustomShapeParameterType::HASSTROKE
:
513 type
= "EnhancedCustomShapeParameterType::HASSTROKE";
515 case EnhancedCustomShapeParameterType::HASFILL
:
516 type
= "EnhancedCustomShapeParameterType::HASFILL";
518 case EnhancedCustomShapeParameterType::WIDTH
:
519 type
= "EnhancedCustomShapeParameterType::WIDTH";
521 case EnhancedCustomShapeParameterType::HEIGHT
:
522 type
= "EnhancedCustomShapeParameterType::HEIGHT";
524 case EnhancedCustomShapeParameterType::LOGWIDTH
:
525 type
= "EnhancedCustomShapeParameterType::LOGWIDTH";
527 case EnhancedCustomShapeParameterType::LOGHEIGHT
:
528 type
= "EnhancedCustomShapeParameterType::LOGHEIGHT";
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
))
543 if (!(pp
.Second
.Value
>>= nSecondValue
))
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
);
555 fprintf (stderr
, "}");
558 static const char* lclDumpAnyValueCode( Any value
, int level
= 0)
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
;
577 sal_uInt32 uintValue
;
578 sal_Int16 int16Value
;
579 sal_uInt16 uint16Value
;
581 float floatValue
= 0;
584 // RectanglePoint pointValue;
585 WritingMode aWritingMode
;
586 TextVerticalAdjust aTextVertAdj
;
587 TextHorizontalAdjust aTextHorizAdj
;
588 Reference
< XIndexReplace
> xNumRule
;
590 if( value
>>= strValue
)
593 fprintf (stderr
,"OUString str = \"%s\";\n", USS( strValue
) );
596 else if( value
>>= strArray
)
598 if (strArray
.getLength() == 0)
599 return "Sequence< OUString >(0)";
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 ? "," : "" );
608 fprintf (stderr
,"};\n");
609 return "createStringSequence( SAL_N_ELEMENTS( aStrings ), aStrings )";
611 else if( value
>>= propArray
)
614 fprintf (stderr
,"Sequence< PropertyValue > aPropSequence (%" SAL_PRIdINT32
");\n", propArray
.getLength());
615 for( int i
=0; i
<propArray
.getLength(); i
++ ) {
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
);
624 fprintf (stderr
, "}\n");
626 return "aPropSequence";
628 else if( value
>>= sizeArray
)
631 fprintf (stderr
, "Sequence< awt::Size > aSizeSequence (%" SAL_PRIdINT32
");\n", sizeArray
.getLength());
632 for( int i
=0; i
<sizeArray
.getLength(); i
++ ) {
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
);
639 fprintf (stderr
, "}\n");
641 return "aSizeSequence";
643 else if( value
>>= propArrayArray
)
646 fprintf (stderr
,"Sequence< Sequence < PropertyValue > > aPropSequenceSequence (%" SAL_PRIdINT32
");\n", propArrayArray
.getLength());
647 for( int i
=0; i
<propArrayArray
.getLength(); i
++ ) {
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
);
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
)
669 fprintf (stderr
,"Sequence< EnhancedCustomShapeAdjustmentValue > aAdjSequence (%" SAL_PRIdINT32
");\n", adjArray
.getLength());
670 for( int i
=0; i
<adjArray
.getLength(); i
++ ) {
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
));
681 fprintf (stderr
, "}\n");
683 return "aAdjSequence";
685 else if( value
>>= segArray
)
687 if (segArray
.getLength() == 0)
688 return "Sequence< EnhancedCustomShapeSegment >(0)";
691 fprintf (stderr
,"static const sal_uInt16 nValues[] = {\n");
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 ? "," : "");
700 fprintf (stderr
,"};\n");
701 return "createSegmentSequence( SAL_N_ELEMENTS( nValues ), nValues )";
703 else if( value
>>= segTextFrame
)
706 fprintf (stderr
, "Sequence< EnhancedCustomShapeTextFrame > aTextFrameSeq (%" SAL_PRIdINT32
");\n", segTextFrame
.getLength());
707 for( int i
=0; i
<segTextFrame
.getLength(); i
++ ) {
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
);
714 fprintf (stderr
, "}\n");
716 return "aTextFrameSeq";
718 else if( value
>>= ppArray
)
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 ? "," : "");
730 fprintf (stderr
,"};\n");
732 return "createParameterPairSequence(SAL_N_ELEMENTS(aData), aData)";
734 else if( value
>>= segment
)
737 fprintf (stderr
, "EnhancedCustomShapeSegment aSegment;\n");
739 // TODO: use EnhancedCustomShapeSegmentCommand constants
740 fprintf (stderr
, "aSegment.Command = %d;\n", segment
.Command
);
742 fprintf (stderr
, "aSegment.Count = %d;\n", segment
.Count
);
745 else if( value
>>= textFrame
)
748 fprintf (stderr
, "EnhancedCustomShapeTextFrame aTextFrame;\n");
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
);
757 fprintf (stderr
, "}\n");
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
);
767 fprintf (stderr
, "}\n");
771 else if( value
>>= pp
)
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
)
783 fprintf (stderr
,"EnhancedCustomShapeParameter aParameter;\n");
784 const char* var
= lclDumpAnyValueCode( par
.Value
, level
);
786 fprintf (stderr
,"aParameter.Value = %s;\n", var
);
788 fprintf (stderr
,"aParameter.Type = %s;\n",
789 lclGetEnhancedParameterType(par
.Type
));
792 else if( value
>>= longValue
)
795 fprintf (stderr
,"Any aAny ((sal_Int32) %ld);\n", longValue
);
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
) {
810 return "(sal_Bool) sal_True";
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
:
835 case TextVerticalAdjust_CENTER
:
838 case TextVerticalAdjust_BOTTOM
:
841 case TextVerticalAdjust_BLOCK
:
844 case TextVerticalAdjust_MAKE_FIXED_SIZE
:
845 s
= "make_fixed_size";
848 fprintf (stderr
, "%s\n", s
);
850 else if( value
>>= aTextHorizAdj
) {
851 const char* s
= "unknown";
852 switch( aTextHorizAdj
) {
853 case TextHorizontalAdjust_LEFT
:
856 case TextHorizontalAdjust_CENTER
:
859 case TextHorizontalAdjust_RIGHT
:
862 case TextHorizontalAdjust_BLOCK
:
865 case TextHorizontalAdjust_MAKE_FIXED_SIZE
:
866 s
= "make_fixed_size";
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
) {
876 fprintf (stderr
, "awt::Rectangle aRectangle;\n");
878 fprintf (stderr
, "aRectangle.X = %" SAL_PRIdINT32
";\n", rect
.X
);
880 fprintf (stderr
, "aRectangle.Y = %" SAL_PRIdINT32
";\n", rect
.Y
);
882 fprintf (stderr
, "aRectangle.Width = %" SAL_PRIdINT32
";\n", rect
.Width
);
884 fprintf (stderr
, "aRectangle.Height = %" SAL_PRIdINT32
";\n", rect
.Height
);
887 else if( value
>>= size
) {
889 fprintf (stderr
, "awt::Size aSize;\n");
891 fprintf (stderr
, "aSize.Width = %" SAL_PRIdINT32
";\n", size
.Width
);
893 fprintf (stderr
, "aSize.Height = %" SAL_PRIdINT32
";\n", size
.Height
);
896 else if( value
.isExtractableTo(::cppu::UnoType
<sal_Int32
>::get())) {
897 fprintf (stderr
,"is extractable to int32\n");
900 fprintf (stderr
,"??? <unhandled type %s>\n", USS(value
.getValueTypeName()));
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
))
917 OString name
= OUStringToOString( props
[i
].Name
, RTL_TEXTENCODING_UTF8
);
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
);
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
) );
959 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */