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