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