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