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