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