Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / WrappedSymbolProperties.cxx
blobd9f594a83b6a3e5aeefbfd12b7ee67ff867aac7b
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 "WrappedSymbolProperties.hxx"
21 #include "WrappedSeriesOrDiagramProperty.hxx"
22 #include <FastPropertyIdRanges.hxx>
23 #include <ChartTypeHelper.hxx>
24 #include <com/sun/star/chart2/Symbol.hpp>
25 #include <com/sun/star/chart2/SymbolStyle.hpp>
26 #include <com/sun/star/awt/Size.hpp>
27 #include <com/sun/star/beans/PropertyAttribute.hpp>
28 #include <com/sun/star/chart/ChartSymbolType.hpp>
29 #include <com/sun/star/drawing/LineStyle.hpp>
30 #include <vcl/GraphicLoader.hxx>
32 #include <vcl/graph.hxx>
33 #include <vcl/outdev.hxx>
34 #include <tools/diagnose_ex.h>
35 #include <sal/log.hxx>
37 using namespace ::com::sun::star;
38 using ::com::sun::star::uno::Any;
39 using ::com::sun::star::uno::Reference;
40 using ::com::sun::star::beans::Property;
42 namespace chart
44 namespace wrapper
47 class WrappedSymbolTypeProperty : public WrappedSeriesOrDiagramProperty< sal_Int32 >
49 public:
50 virtual sal_Int32 getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const override;
51 virtual void setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const sal_Int32& aNewValue ) const override;
53 virtual Any getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const override;
54 virtual beans::PropertyState getPropertyState( const Reference< beans::XPropertyState >& xInnerPropertyState ) const override;
56 explicit WrappedSymbolTypeProperty(const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact,
57 tSeriesOrDiagramPropertyType ePropertyType);
60 class WrappedSymbolBitmapURLProperty : public WrappedSeriesOrDiagramProperty<OUString>
62 public:
63 virtual OUString getValueFromSeries(const Reference<beans::XPropertySet>& xSeriesPropertySet) const override;
64 virtual void setValueToSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet, OUString const & xNewGraphicURL) const override;
66 explicit WrappedSymbolBitmapURLProperty(const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact,
67 tSeriesOrDiagramPropertyType ePropertyType);
70 class WrappedSymbolBitmapProperty : public WrappedSeriesOrDiagramProperty<uno::Reference<graphic::XGraphic>>
72 public:
73 virtual uno::Reference<graphic::XGraphic> getValueFromSeries(const Reference<beans::XPropertySet>& xSeriesPropertySet) const override;
74 virtual void setValueToSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet, uno::Reference<graphic::XGraphic> const & xNewGraphic) const override;
76 explicit WrappedSymbolBitmapProperty(const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact,
77 tSeriesOrDiagramPropertyType ePropertyType);
80 class WrappedSymbolSizeProperty : public WrappedSeriesOrDiagramProperty< awt::Size >
82 public:
83 virtual awt::Size getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const override;
84 virtual void setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const awt::Size& aNewSize ) const override;
85 virtual beans::PropertyState getPropertyState( const Reference< beans::XPropertyState >& xInnerPropertyState ) const override;
87 explicit WrappedSymbolSizeProperty(const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact,
88 tSeriesOrDiagramPropertyType ePropertyType);
91 class WrappedSymbolAndLinesProperty : public WrappedSeriesOrDiagramProperty< bool >
93 public:
94 virtual bool getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const override;
95 virtual void setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const bool& bDrawLines ) const override;
96 virtual beans::PropertyState getPropertyState( const Reference< beans::XPropertyState >& xInnerPropertyState ) const override;
98 explicit WrappedSymbolAndLinesProperty(const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact,
99 tSeriesOrDiagramPropertyType ePropertyType);
102 namespace
104 enum
106 //symbol properties
107 PROP_CHART_SYMBOL_TYPE = FAST_PROPERTY_ID_START_CHART_SYMBOL_PROP,
108 PROP_CHART_SYMBOL_BITMAP_URL,
109 PROP_CHART_SYMBOL_BITMAP,
110 PROP_CHART_SYMBOL_SIZE,
111 PROP_CHART_SYMBOL_AND_LINES
114 sal_Int32 lcl_getSymbolType( const css::chart2::Symbol& rSymbol )
116 sal_Int32 nSymbol = css::chart::ChartSymbolType::NONE;
117 switch( rSymbol.Style )
119 case chart2::SymbolStyle_NONE:
120 break;
121 case chart2::SymbolStyle_AUTO:
122 nSymbol = css::chart::ChartSymbolType::AUTO;
123 break;
124 case chart2::SymbolStyle_STANDARD:
125 nSymbol = rSymbol.StandardSymbol%15;
126 break;
127 case chart2::SymbolStyle_POLYGON://new feature
128 nSymbol = css::chart::ChartSymbolType::AUTO;
129 break;
130 case chart2::SymbolStyle_GRAPHIC:
131 nSymbol = css::chart::ChartSymbolType::BITMAPURL;
132 break;
133 default:
134 nSymbol = css::chart::ChartSymbolType::AUTO;
135 break;
137 return nSymbol;
139 void lcl_setSymbolTypeToSymbol( sal_Int32 nSymbolType, chart2::Symbol& rSymbol )
141 switch( nSymbolType )
143 case css::chart::ChartSymbolType::NONE:
144 rSymbol.Style = chart2::SymbolStyle_NONE;
145 break;
146 case css::chart::ChartSymbolType::AUTO:
147 rSymbol.Style = chart2::SymbolStyle_AUTO;
148 break;
149 case css::chart::ChartSymbolType::BITMAPURL:
150 rSymbol.Style = chart2::SymbolStyle_GRAPHIC;
151 break;
152 default:
153 rSymbol.Style = chart2::SymbolStyle_STANDARD;
154 rSymbol.StandardSymbol = nSymbolType;
155 break;
159 void lcl_addWrappedProperties( std::vector< std::unique_ptr<WrappedProperty> >& rList
160 , const std::shared_ptr< Chart2ModelContact >& spChart2ModelContact
161 , tSeriesOrDiagramPropertyType ePropertyType )
163 rList.emplace_back( new WrappedSymbolTypeProperty( spChart2ModelContact, ePropertyType ) );
164 rList.emplace_back( new WrappedSymbolBitmapURLProperty( spChart2ModelContact, ePropertyType ) );
165 rList.emplace_back( new WrappedSymbolBitmapProperty( spChart2ModelContact, ePropertyType ) );
166 rList.emplace_back( new WrappedSymbolSizeProperty( spChart2ModelContact, ePropertyType ) );
167 rList.emplace_back( new WrappedSymbolAndLinesProperty( spChart2ModelContact, ePropertyType ) );
170 }//anonymous namespace
172 void WrappedSymbolProperties::addProperties( std::vector< Property > & rOutProperties )
174 rOutProperties.emplace_back( "SymbolType",
175 PROP_CHART_SYMBOL_TYPE,
176 cppu::UnoType<sal_Int32>::get(),
177 beans::PropertyAttribute::BOUND
178 | beans::PropertyAttribute::MAYBEDEFAULT );
180 rOutProperties.emplace_back( "SymbolBitmapURL",
181 PROP_CHART_SYMBOL_BITMAP_URL,
182 cppu::UnoType<OUString>::get(),
183 beans::PropertyAttribute::BOUND
184 | beans::PropertyAttribute::MAYBEDEFAULT );
186 rOutProperties.emplace_back( "SymbolBitmap",
187 PROP_CHART_SYMBOL_BITMAP,
188 cppu::UnoType<graphic::XGraphic>::get(),
189 beans::PropertyAttribute::BOUND
190 | beans::PropertyAttribute::MAYBEDEFAULT );
192 rOutProperties.emplace_back( "SymbolSize",
193 PROP_CHART_SYMBOL_SIZE,
194 cppu::UnoType<awt::Size>::get(),
195 beans::PropertyAttribute::BOUND
196 | beans::PropertyAttribute::MAYBEDEFAULT );
198 rOutProperties.emplace_back( "Lines",
199 PROP_CHART_SYMBOL_AND_LINES,
200 cppu::UnoType<bool>::get(),
201 beans::PropertyAttribute::BOUND
202 | beans::PropertyAttribute::MAYBEDEFAULT );
205 void WrappedSymbolProperties::addWrappedPropertiesForSeries( std::vector< std::unique_ptr<WrappedProperty> >& rList
206 , const std::shared_ptr< Chart2ModelContact >& spChart2ModelContact )
208 lcl_addWrappedProperties( rList, spChart2ModelContact, DATA_SERIES );
211 void WrappedSymbolProperties::addWrappedPropertiesForDiagram( std::vector< std::unique_ptr<WrappedProperty> >& rList
212 , const std::shared_ptr< Chart2ModelContact >& spChart2ModelContact )
214 lcl_addWrappedProperties( rList, spChart2ModelContact, DIAGRAM );
217 WrappedSymbolTypeProperty::WrappedSymbolTypeProperty(
218 const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact,
219 tSeriesOrDiagramPropertyType ePropertyType )
220 : WrappedSeriesOrDiagramProperty< sal_Int32 >( "SymbolType"
221 , uno::Any( css::chart::ChartSymbolType::NONE )
222 , spChart2ModelContact
223 , ePropertyType )
227 sal_Int32 WrappedSymbolTypeProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
229 sal_Int32 aRet = 0;
230 m_aDefaultValue >>= aRet;
231 chart2::Symbol aSymbol;
232 if( xSeriesPropertySet.is() && ( xSeriesPropertySet->getPropertyValue("Symbol") >>= aSymbol ) )
233 aRet = lcl_getSymbolType( aSymbol );
234 return aRet;
237 void WrappedSymbolTypeProperty::setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const sal_Int32& nSymbolType ) const
239 if(!xSeriesPropertySet.is())
240 return;
242 chart2::Symbol aSymbol;
243 xSeriesPropertySet->getPropertyValue("Symbol") >>= aSymbol;
245 lcl_setSymbolTypeToSymbol( nSymbolType, aSymbol );
246 xSeriesPropertySet->setPropertyValue( "Symbol", uno::Any( aSymbol ) );
249 Any WrappedSymbolTypeProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
251 //the old chart (< OOo 2.3) needs symbol-type="automatic" at the plot-area if any of the series should be able to have symbols
252 if( m_ePropertyType == DIAGRAM )
254 bool bHasAmbiguousValue = false;
255 sal_Int32 aValue = 0;
256 if( detectInnerValue( aValue, bHasAmbiguousValue ) )
258 if(bHasAmbiguousValue)
260 m_aOuterValue <<= css::chart::ChartSymbolType::AUTO;
262 else
264 if( aValue == css::chart::ChartSymbolType::NONE )
265 m_aOuterValue <<= css::chart::ChartSymbolType::NONE;
266 else
267 m_aOuterValue <<= css::chart::ChartSymbolType::AUTO;
270 return m_aOuterValue;
272 else
274 css::uno::Any aRet( m_aDefaultValue );
275 aRet <<= getValueFromSeries( xInnerPropertySet );
276 return aRet;
280 beans::PropertyState WrappedSymbolTypeProperty::getPropertyState( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
282 //the special situation for this property here is that the diagram default can be
283 //different from the normal default and different from all singles series values
284 //so we need to return PropertyState_DIRECT_VALUE for more cases
286 if( m_ePropertyType == DATA_SERIES && //single series or point
287 m_spChart2ModelContact.get())
289 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
290 Reference< chart2::XDataSeries > xSeries( xInnerPropertyState, uno::UNO_QUERY );
291 Reference< chart2::XChartType > xChartType( DiagramHelper::getChartTypeOfSeries( xDiagram, xSeries ) );
292 if( ChartTypeHelper::isSupportingSymbolProperties( xChartType, 2 ) )
293 return beans::PropertyState_DIRECT_VALUE;
295 return WrappedProperty::getPropertyState( xInnerPropertyState );
298 WrappedSymbolBitmapURLProperty::WrappedSymbolBitmapURLProperty(
299 const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact,
300 tSeriesOrDiagramPropertyType ePropertyType )
301 : WrappedSeriesOrDiagramProperty<OUString>("SymbolBitmapURL",
302 uno::Any(OUString()), spChart2ModelContact, ePropertyType)
306 OUString WrappedSymbolBitmapURLProperty::getValueFromSeries(const Reference< beans::XPropertySet >& /*xSeriesPropertySet*/) const
308 return OUString();
311 void WrappedSymbolBitmapURLProperty::setValueToSeries(
312 const Reference< beans::XPropertySet >& xSeriesPropertySet,
313 OUString const & xNewGraphicURL) const
315 if (!xSeriesPropertySet.is())
316 return;
318 chart2::Symbol aSymbol;
319 if (xSeriesPropertySet->getPropertyValue("Symbol") >>= aSymbol)
321 if (!xNewGraphicURL.isEmpty())
323 Graphic aGraphic = vcl::graphic::loadFromURL(xNewGraphicURL);
324 aSymbol.Graphic.set(aGraphic.GetXGraphic());
325 xSeriesPropertySet->setPropertyValue("Symbol", uno::Any(aSymbol));
330 WrappedSymbolBitmapProperty::WrappedSymbolBitmapProperty(
331 const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact,
332 tSeriesOrDiagramPropertyType ePropertyType )
333 : WrappedSeriesOrDiagramProperty<uno::Reference<graphic::XGraphic>>("SymbolBitmap",
334 uno::Any(uno::Reference<graphic::XGraphic>()), spChart2ModelContact, ePropertyType)
338 uno::Reference<graphic::XGraphic> WrappedSymbolBitmapProperty::getValueFromSeries(const Reference< beans::XPropertySet >& xSeriesPropertySet) const
340 uno::Reference<graphic::XGraphic> xGraphic;
341 m_aDefaultValue >>= xGraphic;
343 chart2::Symbol aSymbol;
344 if (xSeriesPropertySet.is() && (xSeriesPropertySet->getPropertyValue("Symbol") >>= aSymbol)
345 && aSymbol.Graphic.is())
347 xGraphic = aSymbol.Graphic;
349 return xGraphic;
352 void WrappedSymbolBitmapProperty::setValueToSeries(
353 const Reference< beans::XPropertySet >& xSeriesPropertySet,
354 uno::Reference<graphic::XGraphic> const & xNewGraphic) const
356 if (!xSeriesPropertySet.is())
357 return;
359 chart2::Symbol aSymbol;
360 if (xSeriesPropertySet->getPropertyValue("Symbol") >>= aSymbol)
362 if (xNewGraphic.is())
364 aSymbol.Graphic.set(xNewGraphic);
365 xSeriesPropertySet->setPropertyValue("Symbol", uno::Any(aSymbol));
370 namespace
373 void lcl_correctSymbolSizeForBitmaps( chart2::Symbol& rSymbol )
375 if( rSymbol.Style != chart2::SymbolStyle_GRAPHIC )
376 return;
377 if( rSymbol.Size.Width != -1 )
378 return;
379 if( rSymbol.Size.Height != -1 )
380 return;
382 //find a good automatic size
385 const awt::Size aDefaultSize(250,250);
386 awt::Size aSize = aDefaultSize;
387 uno::Reference< beans::XPropertySet > xProp( rSymbol.Graphic, uno::UNO_QUERY );
388 if( xProp.is() )
390 bool bFoundSize = false;
393 if( xProp->getPropertyValue( "Size100thMM" ) >>= aSize )
395 if( aSize.Width == 0 && aSize.Height == 0 )
396 aSize = aDefaultSize;
397 else
398 bFoundSize = true;
401 catch( const uno::Exception& )
403 TOOLS_WARN_EXCEPTION("chart2", "" );
406 if(!bFoundSize)
408 awt::Size aAWTPixelSize(10,10);
409 if( xProp->getPropertyValue( "SizePixel" ) >>= aAWTPixelSize )
411 Size aPixelSize(aAWTPixelSize.Width,aAWTPixelSize.Height);
412 Size aNewSize = OutputDevice::LogicToLogic(aPixelSize, MapMode(MapUnit::MapPixel), MapMode(MapUnit::Map100thMM));
413 aSize = awt::Size( aNewSize.Width(), aNewSize.Height() );
415 if( aSize.Width == 0 && aSize.Height == 0 )
416 aSize = aDefaultSize;
420 rSymbol.Size = aSize;
422 catch( const uno::Exception& )
424 TOOLS_WARN_EXCEPTION("chart2", "" );
428 }//end anonymous namespace
430 WrappedSymbolSizeProperty::WrappedSymbolSizeProperty(
431 const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact,
432 tSeriesOrDiagramPropertyType ePropertyType )
433 : WrappedSeriesOrDiagramProperty< awt::Size >( "SymbolSize"
434 , uno::Any( awt::Size(250,250) ), spChart2ModelContact, ePropertyType )
438 awt::Size WrappedSymbolSizeProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
440 awt::Size aRet;
441 m_aDefaultValue >>= aRet;
442 chart2::Symbol aSymbol;
443 if( xSeriesPropertySet.is() && ( xSeriesPropertySet->getPropertyValue("Symbol") >>= aSymbol ))
444 aRet = aSymbol.Size;
445 return aRet;
448 void WrappedSymbolSizeProperty::setValueToSeries(
449 const Reference< beans::XPropertySet >& xSeriesPropertySet,
450 const awt::Size& aNewSize ) const
452 if(!xSeriesPropertySet.is())
453 return;
455 chart2::Symbol aSymbol;
456 if( xSeriesPropertySet->getPropertyValue("Symbol") >>= aSymbol )
458 aSymbol.Size = aNewSize;
459 lcl_correctSymbolSizeForBitmaps(aSymbol);
460 xSeriesPropertySet->setPropertyValue( "Symbol", uno::Any( aSymbol ) );
464 beans::PropertyState WrappedSymbolSizeProperty::getPropertyState( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
466 //only export symbol size if necessary
467 if( m_ePropertyType == DIAGRAM )
468 return beans::PropertyState_DEFAULT_VALUE;
472 chart2::Symbol aSymbol;
473 Reference< beans::XPropertySet > xSeriesPropertySet( xInnerPropertyState, uno::UNO_QUERY );
474 if( xSeriesPropertySet.is() && ( xSeriesPropertySet->getPropertyValue("Symbol") >>= aSymbol ))
476 if( aSymbol.Style != chart2::SymbolStyle_NONE )
477 return beans::PropertyState_DIRECT_VALUE;
480 catch( const uno::Exception & )
482 DBG_UNHANDLED_EXCEPTION("chart2");
484 return beans::PropertyState_DEFAULT_VALUE;
487 WrappedSymbolAndLinesProperty::WrappedSymbolAndLinesProperty(
488 const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact,
489 tSeriesOrDiagramPropertyType ePropertyType )
490 : WrappedSeriesOrDiagramProperty< bool >( "Lines"
491 , uno::Any( true ), spChart2ModelContact, ePropertyType )
495 bool WrappedSymbolAndLinesProperty::getValueFromSeries( const Reference< beans::XPropertySet >& /*xSeriesPropertySet*/ ) const
497 //do not export this property anymore, instead use a linestyle none for no lines
498 return true;
501 void WrappedSymbolAndLinesProperty::setValueToSeries(
502 const Reference< beans::XPropertySet >& xSeriesPropertySet,
503 const bool& bDrawLines ) const
505 if(!xSeriesPropertySet.is())
506 return;
508 drawing::LineStyle eOldLineStyle( drawing::LineStyle_SOLID );
509 xSeriesPropertySet->getPropertyValue( "LineStyle" ) >>= eOldLineStyle;
510 if( bDrawLines )
512 //#i114298# don't overwrite dashed lines with solid lines here
513 if( eOldLineStyle == drawing::LineStyle_NONE )
514 xSeriesPropertySet->setPropertyValue( "LineStyle", uno::Any( drawing::LineStyle_SOLID ) );
516 else
518 if( eOldLineStyle != drawing::LineStyle_NONE )
519 xSeriesPropertySet->setPropertyValue( "LineStyle", uno::Any( drawing::LineStyle_NONE ) );
523 beans::PropertyState WrappedSymbolAndLinesProperty::getPropertyState( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
525 //do not export this property anymore, instead use a linestyle none for no lines
526 return beans::PropertyState_DEFAULT_VALUE;
529 } //namespace wrapper
530 } //namespace chart
532 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */