fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / view / main / PropertyMapper.cxx
blobc373f38561ee9e035bdb674df67546a4f8cc61e7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "PropertyMapper.hxx"
21 #include "ContainerHelper.hxx"
22 #include "macros.hxx"
23 #include <unonames.hxx>
25 #include <com/sun/star/beans/XMultiPropertySet.hpp>
26 #include <com/sun/star/drawing/LineStyle.hpp>
27 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
28 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
29 #include <com/sun/star/drawing/LineJoint.hpp>
31 namespace chart
33 using namespace ::com::sun::star;
35 namespace
38 void lcl_overwriteOrAppendValues(
39 tPropertyNameValueMap &rMap, const tPropertyNameValueMap& rOverwriteMap )
41 tPropertyNameValueMap::const_iterator aIt( rOverwriteMap.begin() );
42 tPropertyNameValueMap::const_iterator aEnd( rOverwriteMap.end() );
44 for( ; aIt != aEnd; ++aIt )
45 rMap[ aIt->first ] = aIt->second;
48 } // anonymous namespace
50 void PropertyMapper::setMappedProperties(
51 const uno::Reference< beans::XPropertySet >& xTarget
52 , const uno::Reference< beans::XPropertySet >& xSource
53 , const tPropertyNameMap& rMap
54 , tPropertyNameValueMap* pOverwriteMap )
56 if( !xTarget.is() || !xSource.is() )
57 return;
59 tNameSequence aNames;
60 tAnySequence aValues;
61 getMultiPropertyLists(aNames, aValues, xSource, rMap );
62 if(pOverwriteMap && (aNames.getLength() == aValues.getLength()))
64 tPropertyNameValueMap aNewMap;
65 for( sal_Int32 nI=0; nI<aNames.getLength(); ++nI )
66 aNewMap[ aNames[nI] ] = aValues[nI];
67 lcl_overwriteOrAppendValues( aNewMap, *pOverwriteMap );
68 aNames = ContainerHelper::MapKeysToSequence( aNewMap );
69 aValues = ContainerHelper::MapValuesToSequence( aNewMap );
72 PropertyMapper::setMultiProperties( aNames, aValues, xTarget );
75 void PropertyMapper::getValueMap(
76 tPropertyNameValueMap& rValueMap
77 , const tPropertyNameMap& rNameMap
78 , const uno::Reference< beans::XPropertySet >& xSourceProp
81 tPropertyNameMap::const_iterator aIt( rNameMap.begin() );
82 tPropertyNameMap::const_iterator aEnd( rNameMap.end() );
84 uno::Reference< beans::XMultiPropertySet > xMultiPropSet(xSourceProp, uno::UNO_QUERY);
85 if(false && xMultiPropSet.is())
87 uno::Sequence< rtl::OUString > aPropSourceNames(rNameMap.size());
88 uno::Sequence< rtl::OUString > aPropTargetNames(rNameMap.size());
89 for(sal_Int32 i = 0; aIt != aEnd; ++aIt, ++i)
91 aPropTargetNames[i] = aIt->first;
92 aPropSourceNames[i] = aIt->second;
95 uno::Sequence< uno::Any > xValues = xMultiPropSet->getPropertyValues(aPropSourceNames);
97 for(sal_Int32 i = 0, n = rNameMap.size(); i < n; ++i)
99 if( xValues[i].hasValue() )
100 rValueMap.insert( tPropertyNameValueMap::value_type( aPropTargetNames[i], xValues[i] ) );
103 else
105 for( ; aIt != aEnd; ++aIt )
107 OUString aTarget = aIt->first;
108 OUString aSource = aIt->second;
111 uno::Any aAny( xSourceProp->getPropertyValue(aSource) );
112 if( aAny.hasValue() )
113 rValueMap.insert( tPropertyNameValueMap::value_type( aTarget, aAny ) );
115 catch( const uno::Exception& e )
117 ASSERT_EXCEPTION( e );
123 void PropertyMapper::getMultiPropertyLists(
124 tNameSequence& rNames
125 , tAnySequence& rValues
126 , const uno::Reference< beans::XPropertySet >& xSourceProp
127 , const tPropertyNameMap& rNameMap
130 tPropertyNameValueMap aValueMap;
131 getValueMap( aValueMap, rNameMap, xSourceProp );
132 getMultiPropertyListsFromValueMap( rNames, rValues, aValueMap );
135 void PropertyMapper::getMultiPropertyListsFromValueMap(
136 tNameSequence& rNames
137 , tAnySequence& rValues
138 , const tPropertyNameValueMap& rValueMap
141 sal_Int32 nPropertyCount = rValueMap.size();
142 rNames.realloc(nPropertyCount);
143 rValues.realloc(nPropertyCount);
145 //fill sequences
146 tPropertyNameValueMap::const_iterator aValueIt( rValueMap.begin() );
147 tPropertyNameValueMap::const_iterator aValueEnd( rValueMap.end() );
148 sal_Int32 nN=0;
149 for( ; aValueIt != aValueEnd; ++aValueIt )
151 const uno::Any& rAny = aValueIt->second;
152 if( rAny.hasValue() )
154 //do not set empty anys because of performance (otherwise SdrAttrObj::ItemChange will take much longer)
155 rNames[nN] = aValueIt->first;
156 rValues[nN] = rAny;
157 ++nN;
160 //reduce to real property count
161 rNames.realloc(nN);
162 rValues.realloc(nN);
165 uno::Any* PropertyMapper::getValuePointer( tAnySequence& rPropValues
166 , const tNameSequence& rPropNames
167 , const OUString& rPropName )
169 sal_Int32 nCount = rPropNames.getLength();
170 for( sal_Int32 nN = 0; nN < nCount; nN++ )
172 if(rPropNames[nN].equals(rPropName))
173 return &rPropValues[nN];
175 return NULL;
178 uno::Any* PropertyMapper::getValuePointerForLimitedSpace( tAnySequence& rPropValues
179 , const tNameSequence& rPropNames
180 , bool bLimitedHeight)
182 return PropertyMapper::getValuePointer( rPropValues, rPropNames
183 , bLimitedHeight ? OUString("TextMaximumFrameHeight") : OUString("TextMaximumFrameWidth") );
186 const tMakePropertyNameMap& PropertyMapper::getPropertyNameMapForCharacterProperties()
188 //shape property -- chart model object property
189 static tMakePropertyNameMap m_aShapePropertyMapForCharacterProperties =
190 tMakePropertyNameMap
191 ( "CharColor", "CharColor" )
192 ( "CharContoured", "CharContoured" )
193 ( "CharEmphasis", "CharEmphasis" )//the service style::CharacterProperties describes a property called 'CharEmphasize' which is nowhere implemented
195 ( "CharFontFamily", "CharFontFamily" )
196 ( "CharFontFamilyAsian", "CharFontFamilyAsian" )
197 ( "CharFontFamilyComplex", "CharFontFamilyComplex" )
198 ( "CharFontCharSet", "CharFontCharSet" )
199 ( "CharFontCharSetAsian", "CharFontCharSetAsian" )
200 ( "CharFontCharSetComplex", "CharFontCharSetComplex" )
201 ( "CharFontName", "CharFontName" )
202 ( "CharFontNameAsian", "CharFontNameAsian" )
203 ( "CharFontNameComplex", "CharFontNameComplex" )
204 ( "CharFontPitch", "CharFontPitch" )
205 ( "CharFontPitchAsian", "CharFontPitchAsian" )
206 ( "CharFontPitchComplex", "CharFontPitchComplex" )
207 ( "CharFontStyleName", "CharFontStyleName" )
208 ( "CharFontStyleNameAsian", "CharFontStyleNameAsian" )
209 ( "CharFontStyleNameComplex", "CharFontStyleNameComplex" )
211 ( "CharHeight", "CharHeight" )
212 ( "CharHeightAsian", "CharHeightAsian" )
213 ( "CharHeightComplex", "CharHeightComplex" )
214 ( "CharKerning", "CharKerning" )
215 ( "CharLocale", "CharLocale" )
216 ( "CharLocaleAsian", "CharLocaleAsian" )
217 ( "CharLocaleComplex", "CharLocaleComplex" )
218 ( "CharPosture", "CharPosture" )
219 ( "CharPostureAsian", "CharPostureAsian" )
220 ( "CharPostureComplex", "CharPostureComplex" )
221 ( "CharRelief", "CharRelief" )
222 ( "CharShadowed", "CharShadowed" )
223 ( "CharStrikeout", "CharStrikeout" )
224 ( "CharUnderline", "CharUnderline" )
225 ( "CharUnderlineColor", "CharUnderlineColor" )
226 ( "CharUnderlineHasColor", "CharUnderlineHasColor" )
227 ( "CharOverline", "CharOverline" )
228 ( "CharOverlineColor", "CharOverlineColor" )
229 ( "CharOverlineHasColor", "CharOverlineHasColor" )
230 ( "CharWeight", "CharWeight" )
231 ( "CharWeightAsian", "CharWeightAsian" )
232 ( "CharWeightComplex", "CharWeightComplex" )
233 ( "CharWordMode", "CharWordMode" )
235 ( "WritingMode", "WritingMode" )
237 ( "ParaIsCharacterDistance", "ParaIsCharacterDistance" )
239 return m_aShapePropertyMapForCharacterProperties;
242 const tMakePropertyNameMap& PropertyMapper::getPropertyNameMapForParagraphProperties()
244 //shape property -- chart model object property
245 static tMakePropertyNameMap m_aShapePropertyMapForParagraphProperties =
246 tMakePropertyNameMap
247 ( "ParaAdjust", "ParaAdjust" )
248 ( "ParaBottomMargin", "ParaBottomMargin" )
249 ( "ParaIsHyphenation", "ParaIsHyphenation" )
250 ( "ParaLastLineAdjust", "ParaLastLineAdjust" )
251 ( "ParaLeftMargin", "ParaLeftMargin" )
252 ( "ParaRightMargin", "ParaRightMargin" )
253 ( "ParaTopMargin", "ParaTopMargin" )
255 return m_aShapePropertyMapForParagraphProperties;
258 const tMakePropertyNameMap& PropertyMapper::getPropertyNameMapForFillProperties()
260 //shape property -- chart model object property
261 static tMakePropertyNameMap m_aShapePropertyMapForFillProperties =
262 tMakePropertyNameMap
263 ( "FillBackground", "FillBackground" )
264 ( "FillBitmapName", "FillBitmapName" )
265 ( "FillColor", "FillColor" )
266 ( "FillGradientName", "FillGradientName" )
267 ( "FillGradientStepCount", "FillGradientStepCount" )
268 ( "FillHatchName", "FillHatchName" )
269 ( "FillStyle", "FillStyle" )
270 ( "FillTransparence", "FillTransparence" )
271 ( "FillTransparenceGradientName", "FillTransparenceGradientName" )
272 //bitmap properties
273 ( "FillBitmapMode", "FillBitmapMode" )
274 ( "FillBitmapSizeX", "FillBitmapSizeX" )
275 ( "FillBitmapSizeY", "FillBitmapSizeY" )
276 ( "FillBitmapLogicalSize", "FillBitmapLogicalSize" )
277 ( "FillBitmapOffsetX", "FillBitmapOffsetX" )
278 ( "FillBitmapOffsetY", "FillBitmapOffsetY" )
279 ( "FillBitmapRectanglePoint", "FillBitmapRectanglePoint" )
280 ( "FillBitmapPositionOffsetX", "FillBitmapPositionOffsetX" )
281 ( "FillBitmapPositionOffsetY", "FillBitmapPositionOffsetY" )
283 return m_aShapePropertyMapForFillProperties;
286 const tMakePropertyNameMap& PropertyMapper::getPropertyNameMapForLineProperties()
288 //shape property -- chart model object property
289 static tMakePropertyNameMap m_aShapePropertyMapForLineProperties =
290 tMakePropertyNameMap
291 ( "LineColor", "LineColor" )
292 ( "LineDashName", "LineDashName" )
293 ( "LineJoint", "LineJoint" )
294 ( "LineStyle", "LineStyle" )
295 ( "LineTransparence", "LineTransparence" )
296 ( "LineWidth", "LineWidth" )
298 return m_aShapePropertyMapForLineProperties;
301 const tMakePropertyNameMap& PropertyMapper::getPropertyNameMapForFillAndLineProperties()
303 static tMakePropertyNameMap m_aShapePropertyMapForFillAndLineProperties =
304 tMakePropertyNameMap
305 ( PropertyMapper::getPropertyNameMapForFillProperties() )
306 ( PropertyMapper::getPropertyNameMapForLineProperties() )
309 return m_aShapePropertyMapForFillAndLineProperties;
312 const tMakePropertyNameMap& PropertyMapper::getPropertyNameMapForTextShapeProperties()
314 static tMakePropertyNameMap m_aShapePropertyMapForTextShapeProperties =
315 tMakePropertyNameMap
316 ( PropertyMapper::getPropertyNameMapForCharacterProperties() )
317 ( PropertyMapper::getPropertyNameMapForFillProperties() )
318 ( PropertyMapper::getPropertyNameMapForLineProperties() );
320 return m_aShapePropertyMapForTextShapeProperties;
323 const tMakePropertyNameMap& PropertyMapper::getPropertyNameMapForLineSeriesProperties()
325 //shape property -- chart model object property
326 static tMakePropertyNameMap m_aShapePropertyMapForLineSeriesProperties =
327 tMakePropertyNameMap
328 ( "LineColor", "Color" )
329 ( "LineDashName", "LineDashName" )
330 ( "LineStyle", "LineStyle" )
331 ( "LineTransparence", "Transparency" )
332 ( "LineWidth", "LineWidth" )
335 return m_aShapePropertyMapForLineSeriesProperties;
338 const tMakePropertyNameMap& PropertyMapper::getPropertyNameMapForTextLabelProperties()
340 // target name (drawing layer) : source name (chart model)
341 static tMakePropertyNameMap aMap = tMakePropertyNameMap
342 ( getPropertyNameMapForCharacterProperties() )
343 ( "LineStyle", CHART_UNONAME_LABEL_BORDER_STYLE )
344 ( "LineWidth", CHART_UNONAME_LABEL_BORDER_WIDTH )
345 ( "LineColor", CHART_UNONAME_LABEL_BORDER_COLOR )
346 ( "LineTransparence", CHART_UNONAME_LABEL_BORDER_TRANS ) // fix the spelling!
348 return aMap;
351 const tMakePropertyNameMap& PropertyMapper::getPropertyNameMapForFilledSeriesProperties()
353 //shape property -- chart model object property
354 static tMakePropertyNameMap m_aShapePropertyMapForFilledSeriesProperties =
355 tMakePropertyNameMap
356 ( "FillBackground", "FillBackground" )
357 ( "FillBitmapName", "FillBitmapName" )
358 ( "FillColor", "Color" )
359 ( "FillGradientName", "GradientName" )
360 ( "FillGradientStepCount", "GradientStepCount" )
361 ( "FillHatchName", "HatchName" )
362 ( "FillStyle", "FillStyle" )
363 ( "FillTransparence", "Transparency" )
364 ( "FillTransparenceGradientName", "TransparencyGradientName" )
365 //bitmap properties
366 ( "FillBitmapMode", "FillBitmapMode" )
367 ( "FillBitmapSizeX", "FillBitmapSizeX" )
368 ( "FillBitmapSizeY", "FillBitmapSizeY" )
369 ( "FillBitmapLogicalSize", "FillBitmapLogicalSize" )
370 ( "FillBitmapOffsetX", "FillBitmapOffsetX" )
371 ( "FillBitmapOffsetY", "FillBitmapOffsetY" )
372 ( "FillBitmapRectanglePoint", "FillBitmapRectanglePoint" )
373 ( "FillBitmapPositionOffsetX", "FillBitmapPositionOffsetX" )
374 ( "FillBitmapPositionOffsetY", "FillBitmapPositionOffsetY" )
375 //line properties
376 ( "LineColor", "BorderColor" )
377 ( "LineDashName", "BorderDashName" )
378 ( "LineStyle", "BorderStyle" )
379 ( "LineTransparence", "BorderTransparency" )
380 ( "LineWidth", "BorderWidth" )
382 return m_aShapePropertyMapForFilledSeriesProperties;
385 void PropertyMapper::setMultiProperties(
386 const tNameSequence& rNames
387 , const tAnySequence& rValues
388 , const ::com::sun::star::uno::Reference<
389 ::com::sun::star::beans::XPropertySet >& xTarget )
391 bool bSuccess = false;
394 uno::Reference< beans::XMultiPropertySet > xShapeMultiProp( xTarget, uno::UNO_QUERY );
395 if( xShapeMultiProp.is() )
397 xShapeMultiProp->setPropertyValues( rNames, rValues );
398 bSuccess = true;
401 catch( const uno::Exception& e )
403 ASSERT_EXCEPTION( e ); //if this occurs more often think of removing the XMultiPropertySet completely for better performance
406 if(!bSuccess)
409 sal_Int32 nCount = std::max( rNames.getLength(), rValues.getLength() );
410 OUString aPropName;
411 uno::Any aValue;
412 for( sal_Int32 nN = 0; nN < nCount; nN++ )
414 aPropName = rNames[nN];
415 aValue = rValues[nN];
419 xTarget->setPropertyValue( aPropName, aValue );
421 catch( const uno::Exception& e )
423 ASSERT_EXCEPTION( e );
427 catch( const uno::Exception& e )
429 ASSERT_EXCEPTION( e );
433 void PropertyMapper::getTextLabelMultiPropertyLists(
434 const uno::Reference< beans::XPropertySet >& xSourceProp
435 , tNameSequence& rPropNames, tAnySequence& rPropValues
436 , bool bName
437 , sal_Int32 nLimitedSpace
438 , bool bLimitedHeight )
440 //fill character properties into the ValueMap
441 tPropertyNameValueMap aValueMap;
442 tMakePropertyNameMap aNameMap = PropertyMapper::getPropertyNameMapForTextLabelProperties();
444 PropertyMapper::getValueMap(aValueMap, aNameMap, xSourceProp);
446 //some more shape properties apart from character properties, position-matrix and label string
447 aValueMap.insert( tPropertyNameValueMap::value_type( "TextHorizontalAdjust", uno::makeAny(drawing::TextHorizontalAdjust_CENTER) ) ); // drawing::TextHorizontalAdjust - needs to be overwritten
448 aValueMap.insert( tPropertyNameValueMap::value_type( "TextVerticalAdjust", uno::makeAny(drawing::TextVerticalAdjust_CENTER) ) ); //drawing::TextVerticalAdjust - needs to be overwritten
449 aValueMap.insert( tPropertyNameValueMap::value_type( "TextAutoGrowHeight", uno::makeAny(sal_True) ) ); // sal_Bool
450 aValueMap.insert( tPropertyNameValueMap::value_type( "TextAutoGrowWidth", uno::makeAny(sal_True) ) ); // sal_Bool
451 if( bName )
452 aValueMap.insert( tPropertyNameValueMap::value_type( "Name", uno::makeAny( OUString() ) ) ); //CID OUString - needs to be overwritten for each point
454 if( nLimitedSpace > 0 )
456 if(bLimitedHeight)
457 aValueMap.insert( tPropertyNameValueMap::value_type( "TextMaximumFrameHeight", uno::makeAny(nLimitedSpace) ) ); //sal_Int32
458 else
459 aValueMap.insert( tPropertyNameValueMap::value_type( "TextMaximumFrameWidth", uno::makeAny(nLimitedSpace) ) ); //sal_Int32
460 aValueMap.insert( tPropertyNameValueMap::value_type( "ParaIsHyphenation", uno::makeAny(sal_True) ) );
463 PropertyMapper::getMultiPropertyListsFromValueMap( rPropNames, rPropValues, aValueMap );
466 void PropertyMapper::getPreparedTextShapePropertyLists(
467 const uno::Reference< beans::XPropertySet >& xSourceProp
468 , tNameSequence& rPropNames, tAnySequence& rPropValues )
470 //fill character, line and fill properties into the ValueMap
471 tPropertyNameValueMap aValueMap;
472 PropertyMapper::getValueMap( aValueMap
473 , PropertyMapper::getPropertyNameMapForTextShapeProperties()
474 , xSourceProp );
476 // auto-grow makes sure the shape has the correct size after setting text
477 aValueMap.insert( tPropertyNameValueMap::value_type( "TextHorizontalAdjust", uno::makeAny( drawing::TextHorizontalAdjust_CENTER )));
478 aValueMap.insert( tPropertyNameValueMap::value_type( "TextVerticalAdjust", uno::makeAny( drawing::TextVerticalAdjust_CENTER )));
479 aValueMap.insert( tPropertyNameValueMap::value_type( "TextAutoGrowHeight", uno::makeAny( true )));
480 aValueMap.insert( tPropertyNameValueMap::value_type( "TextAutoGrowWidth", uno::makeAny( true )));
482 // set some distance to the border, in case it is shown
483 const sal_Int32 nWidthDist = 250;
484 const sal_Int32 nHeightDist = 125;
485 aValueMap.insert( tPropertyNameValueMap::value_type( "TextLeftDistance", uno::makeAny( nWidthDist )));
486 aValueMap.insert( tPropertyNameValueMap::value_type( "TextRightDistance", uno::makeAny( nWidthDist )));
487 aValueMap.insert( tPropertyNameValueMap::value_type( "TextUpperDistance", uno::makeAny( nHeightDist )));
488 aValueMap.insert( tPropertyNameValueMap::value_type( "TextLowerDistance", uno::makeAny( nHeightDist )));
490 // use a line-joint showing the border of thick lines like two rectangles
491 // filled in between.
492 aValueMap["LineJoint"] <<= drawing::LineJoint_ROUND;
494 PropertyMapper::getMultiPropertyListsFromValueMap( rPropNames, rPropValues, aValueMap );
497 } //namespace chart
499 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */