1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <ChartType.hxx>
24 #include <ChartTypeHelper.hxx>
25 #include <com/sun/star/chart2/Symbol.hpp>
26 #include <com/sun/star/chart2/SymbolStyle.hpp>
27 #include <com/sun/star/awt/Size.hpp>
28 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 #include <com/sun/star/beans/XPropertyState.hpp>
30 #include <com/sun/star/chart/ChartSymbolType.hpp>
31 #include <com/sun/star/drawing/LineStyle.hpp>
32 #include <vcl/GraphicLoader.hxx>
34 #include <vcl/graph.hxx>
35 #include <comphelper/diagnose_ex.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::wrapper
48 class WrappedSymbolTypeProperty
: public WrappedSeriesOrDiagramProperty
< sal_Int32
>
51 virtual sal_Int32
getValueFromSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
) const override
;
52 virtual void setValueToSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
, const sal_Int32
& aNewValue
) const override
;
54 virtual Any
getPropertyValue( const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const override
;
55 virtual beans::PropertyState
getPropertyState( const Reference
< beans::XPropertyState
>& xInnerPropertyState
) const override
;
57 explicit WrappedSymbolTypeProperty(const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
,
58 tSeriesOrDiagramPropertyType ePropertyType
);
61 class WrappedSymbolBitmapURLProperty
: public WrappedSeriesOrDiagramProperty
<OUString
>
64 virtual OUString
getValueFromSeries(const Reference
<beans::XPropertySet
>& xSeriesPropertySet
) const override
;
65 virtual void setValueToSeries(const Reference
<beans::XPropertySet
> & xSeriesPropertySet
, OUString
const & xNewGraphicURL
) const override
;
67 explicit WrappedSymbolBitmapURLProperty(const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
,
68 tSeriesOrDiagramPropertyType ePropertyType
);
71 class WrappedSymbolBitmapProperty
: public WrappedSeriesOrDiagramProperty
<uno::Reference
<graphic::XGraphic
>>
74 virtual uno::Reference
<graphic::XGraphic
> getValueFromSeries(const Reference
<beans::XPropertySet
>& xSeriesPropertySet
) const override
;
75 virtual void setValueToSeries(const Reference
<beans::XPropertySet
> & xSeriesPropertySet
, uno::Reference
<graphic::XGraphic
> const & xNewGraphic
) const override
;
77 explicit WrappedSymbolBitmapProperty(const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
,
78 tSeriesOrDiagramPropertyType ePropertyType
);
81 class WrappedSymbolSizeProperty
: public WrappedSeriesOrDiagramProperty
< awt::Size
>
84 virtual awt::Size
getValueFromSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
) const override
;
85 virtual void setValueToSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
, const awt::Size
& aNewSize
) const override
;
86 virtual beans::PropertyState
getPropertyState( const Reference
< beans::XPropertyState
>& xInnerPropertyState
) const override
;
88 explicit WrappedSymbolSizeProperty(const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
,
89 tSeriesOrDiagramPropertyType ePropertyType
);
92 class WrappedSymbolAndLinesProperty
: public WrappedSeriesOrDiagramProperty
< bool >
95 virtual bool getValueFromSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
) const override
;
96 virtual void setValueToSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
, const bool& bDrawLines
) const override
;
97 virtual beans::PropertyState
getPropertyState( const Reference
< beans::XPropertyState
>& xInnerPropertyState
) const override
;
99 explicit WrappedSymbolAndLinesProperty(const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
,
100 tSeriesOrDiagramPropertyType ePropertyType
);
106 PROP_CHART_SYMBOL_TYPE
= FAST_PROPERTY_ID_START_CHART_SYMBOL_PROP
,
107 PROP_CHART_SYMBOL_BITMAP_URL
,
108 PROP_CHART_SYMBOL_BITMAP
,
109 PROP_CHART_SYMBOL_SIZE
,
110 PROP_CHART_SYMBOL_AND_LINES
113 sal_Int32
lcl_getSymbolType( const css::chart2::Symbol
& rSymbol
)
115 sal_Int32 nSymbol
= css::chart::ChartSymbolType::NONE
;
116 switch( rSymbol
.Style
)
118 case chart2::SymbolStyle_NONE
:
120 case chart2::SymbolStyle_AUTO
:
121 case chart2::SymbolStyle_POLYGON
://new feature
122 nSymbol
= css::chart::ChartSymbolType::AUTO
;
124 case chart2::SymbolStyle_STANDARD
:
125 nSymbol
= rSymbol
.StandardSymbol
%15;
127 case chart2::SymbolStyle_GRAPHIC
:
128 nSymbol
= css::chart::ChartSymbolType::BITMAPURL
;
131 nSymbol
= css::chart::ChartSymbolType::AUTO
;
136 void lcl_setSymbolTypeToSymbol( sal_Int32 nSymbolType
, chart2::Symbol
& rSymbol
)
138 switch( nSymbolType
)
140 case css::chart::ChartSymbolType::NONE
:
141 rSymbol
.Style
= chart2::SymbolStyle_NONE
;
143 case css::chart::ChartSymbolType::AUTO
:
144 rSymbol
.Style
= chart2::SymbolStyle_AUTO
;
146 case css::chart::ChartSymbolType::BITMAPURL
:
147 rSymbol
.Style
= chart2::SymbolStyle_GRAPHIC
;
150 rSymbol
.Style
= chart2::SymbolStyle_STANDARD
;
151 rSymbol
.StandardSymbol
= nSymbolType
;
156 void lcl_addWrappedProperties( std::vector
< std::unique_ptr
<WrappedProperty
> >& rList
157 , const std::shared_ptr
< Chart2ModelContact
>& spChart2ModelContact
158 , tSeriesOrDiagramPropertyType ePropertyType
)
160 rList
.emplace_back( new WrappedSymbolTypeProperty( spChart2ModelContact
, ePropertyType
) );
161 rList
.emplace_back( new WrappedSymbolBitmapURLProperty( spChart2ModelContact
, ePropertyType
) );
162 rList
.emplace_back( new WrappedSymbolBitmapProperty( spChart2ModelContact
, ePropertyType
) );
163 rList
.emplace_back( new WrappedSymbolSizeProperty( spChart2ModelContact
, ePropertyType
) );
164 rList
.emplace_back( new WrappedSymbolAndLinesProperty( spChart2ModelContact
, ePropertyType
) );
167 }//anonymous namespace
169 void WrappedSymbolProperties::addProperties( std::vector
< Property
> & rOutProperties
)
171 rOutProperties
.emplace_back( "SymbolType",
172 PROP_CHART_SYMBOL_TYPE
,
173 cppu::UnoType
<sal_Int32
>::get(),
174 beans::PropertyAttribute::BOUND
175 | beans::PropertyAttribute::MAYBEDEFAULT
);
177 rOutProperties
.emplace_back( "SymbolBitmapURL",
178 PROP_CHART_SYMBOL_BITMAP_URL
,
179 cppu::UnoType
<OUString
>::get(),
180 beans::PropertyAttribute::BOUND
181 | beans::PropertyAttribute::MAYBEDEFAULT
);
183 rOutProperties
.emplace_back( "SymbolBitmap",
184 PROP_CHART_SYMBOL_BITMAP
,
185 cppu::UnoType
<graphic::XGraphic
>::get(),
186 beans::PropertyAttribute::BOUND
187 | beans::PropertyAttribute::MAYBEDEFAULT
);
189 rOutProperties
.emplace_back( "SymbolSize",
190 PROP_CHART_SYMBOL_SIZE
,
191 cppu::UnoType
<awt::Size
>::get(),
192 beans::PropertyAttribute::BOUND
193 | beans::PropertyAttribute::MAYBEDEFAULT
);
195 rOutProperties
.emplace_back( "Lines",
196 PROP_CHART_SYMBOL_AND_LINES
,
197 cppu::UnoType
<bool>::get(),
198 beans::PropertyAttribute::BOUND
199 | beans::PropertyAttribute::MAYBEDEFAULT
);
202 void WrappedSymbolProperties::addWrappedPropertiesForSeries( std::vector
< std::unique_ptr
<WrappedProperty
> >& rList
203 , const std::shared_ptr
< Chart2ModelContact
>& spChart2ModelContact
)
205 lcl_addWrappedProperties( rList
, spChart2ModelContact
, DATA_SERIES
);
208 void WrappedSymbolProperties::addWrappedPropertiesForDiagram( std::vector
< std::unique_ptr
<WrappedProperty
> >& rList
209 , const std::shared_ptr
< Chart2ModelContact
>& spChart2ModelContact
)
211 lcl_addWrappedProperties( rList
, spChart2ModelContact
, DIAGRAM
);
214 WrappedSymbolTypeProperty::WrappedSymbolTypeProperty(
215 const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
,
216 tSeriesOrDiagramPropertyType ePropertyType
)
217 : WrappedSeriesOrDiagramProperty
< sal_Int32
>( u
"SymbolType"_ustr
218 , uno::Any( css::chart::ChartSymbolType::NONE
)
219 , spChart2ModelContact
224 sal_Int32
WrappedSymbolTypeProperty::getValueFromSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
) const
227 m_aDefaultValue
>>= aRet
;
228 chart2::Symbol aSymbol
;
229 if( xSeriesPropertySet
.is() && ( xSeriesPropertySet
->getPropertyValue(u
"Symbol"_ustr
) >>= aSymbol
) )
230 aRet
= lcl_getSymbolType( aSymbol
);
234 void WrappedSymbolTypeProperty::setValueToSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
, const sal_Int32
& nSymbolType
) const
236 if(!xSeriesPropertySet
.is())
239 chart2::Symbol aSymbol
;
240 xSeriesPropertySet
->getPropertyValue(u
"Symbol"_ustr
) >>= aSymbol
;
242 lcl_setSymbolTypeToSymbol( nSymbolType
, aSymbol
);
243 xSeriesPropertySet
->setPropertyValue( u
"Symbol"_ustr
, uno::Any( aSymbol
) );
246 Any
WrappedSymbolTypeProperty::getPropertyValue( const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
248 //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
249 if( m_ePropertyType
== DIAGRAM
)
251 bool bHasAmbiguousValue
= false;
252 sal_Int32 aValue
= 0;
253 if( detectInnerValue( aValue
, bHasAmbiguousValue
) )
255 if(bHasAmbiguousValue
)
257 m_aOuterValue
<<= css::chart::ChartSymbolType::AUTO
;
261 if( aValue
== css::chart::ChartSymbolType::NONE
)
262 m_aOuterValue
<<= css::chart::ChartSymbolType::NONE
;
264 m_aOuterValue
<<= css::chart::ChartSymbolType::AUTO
;
267 return m_aOuterValue
;
271 css::uno::Any
aRet( m_aDefaultValue
);
272 aRet
<<= getValueFromSeries( xInnerPropertySet
);
277 beans::PropertyState
WrappedSymbolTypeProperty::getPropertyState( const Reference
< beans::XPropertyState
>& xInnerPropertyState
) const
279 //the special situation for this property here is that the diagram default can be
280 //different from the normal default and different from all singles series values
281 //so we need to return PropertyState_DIRECT_VALUE for more cases
283 if( m_ePropertyType
== DATA_SERIES
&& //single series or point
284 m_spChart2ModelContact
)
286 rtl::Reference
< ::chart::Diagram
> xDiagram( m_spChart2ModelContact
->getDiagram() );
287 rtl::Reference
< ::chart::DataSeries
> xSeries( dynamic_cast<DataSeries
*>(xInnerPropertyState
.get()) );
288 rtl::Reference
< ChartType
> xChartType( xDiagram
->getChartTypeOfSeries( xSeries
) );
289 if( ChartTypeHelper::isSupportingSymbolProperties( xChartType
, 2 ) )
290 return beans::PropertyState_DIRECT_VALUE
;
292 return WrappedProperty::getPropertyState( xInnerPropertyState
);
295 WrappedSymbolBitmapURLProperty::WrappedSymbolBitmapURLProperty(
296 const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
,
297 tSeriesOrDiagramPropertyType ePropertyType
)
298 : WrappedSeriesOrDiagramProperty
<OUString
>(u
"SymbolBitmapURL"_ustr
,
299 uno::Any(OUString()), spChart2ModelContact
, ePropertyType
)
303 OUString
WrappedSymbolBitmapURLProperty::getValueFromSeries(const Reference
< beans::XPropertySet
>& /*xSeriesPropertySet*/) const
308 void WrappedSymbolBitmapURLProperty::setValueToSeries(
309 const Reference
< beans::XPropertySet
>& xSeriesPropertySet
,
310 OUString
const & xNewGraphicURL
) const
312 if (!xSeriesPropertySet
.is())
315 chart2::Symbol aSymbol
;
316 if (xSeriesPropertySet
->getPropertyValue(u
"Symbol"_ustr
) >>= aSymbol
)
318 if (!xNewGraphicURL
.isEmpty())
320 Graphic aGraphic
= vcl::graphic::loadFromURL(xNewGraphicURL
);
321 aSymbol
.Graphic
.set(aGraphic
.GetXGraphic());
322 xSeriesPropertySet
->setPropertyValue(u
"Symbol"_ustr
, uno::Any(aSymbol
));
327 WrappedSymbolBitmapProperty::WrappedSymbolBitmapProperty(
328 const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
,
329 tSeriesOrDiagramPropertyType ePropertyType
)
330 : WrappedSeriesOrDiagramProperty
<uno::Reference
<graphic::XGraphic
>>(u
"SymbolBitmap"_ustr
,
331 uno::Any(uno::Reference
<graphic::XGraphic
>()), spChart2ModelContact
, ePropertyType
)
335 uno::Reference
<graphic::XGraphic
> WrappedSymbolBitmapProperty::getValueFromSeries(const Reference
< beans::XPropertySet
>& xSeriesPropertySet
) const
337 uno::Reference
<graphic::XGraphic
> xGraphic
;
338 m_aDefaultValue
>>= xGraphic
;
340 chart2::Symbol aSymbol
;
341 if (xSeriesPropertySet
.is() && (xSeriesPropertySet
->getPropertyValue(u
"Symbol"_ustr
) >>= aSymbol
)
342 && aSymbol
.Graphic
.is())
344 xGraphic
= aSymbol
.Graphic
;
349 void WrappedSymbolBitmapProperty::setValueToSeries(
350 const Reference
< beans::XPropertySet
>& xSeriesPropertySet
,
351 uno::Reference
<graphic::XGraphic
> const & xNewGraphic
) const
353 if (!xSeriesPropertySet
.is())
356 chart2::Symbol aSymbol
;
357 if (xSeriesPropertySet
->getPropertyValue(u
"Symbol"_ustr
) >>= aSymbol
)
359 if (xNewGraphic
.is())
361 aSymbol
.Graphic
.set(xNewGraphic
);
362 xSeriesPropertySet
->setPropertyValue(u
"Symbol"_ustr
, uno::Any(aSymbol
));
370 void lcl_correctSymbolSizeForBitmaps( chart2::Symbol
& rSymbol
)
372 if( rSymbol
.Style
!= chart2::SymbolStyle_GRAPHIC
)
374 if( rSymbol
.Size
.Width
!= -1 )
376 if( rSymbol
.Size
.Height
!= -1 )
379 //find a good automatic size
382 const awt::Size
aDefaultSize(250,250);
383 awt::Size aSize
= aDefaultSize
;
384 uno::Reference
< beans::XPropertySet
> xProp( rSymbol
.Graphic
, uno::UNO_QUERY
);
387 bool bFoundSize
= false;
390 if( xProp
->getPropertyValue( u
"Size100thMM"_ustr
) >>= aSize
)
392 if( aSize
.Width
== 0 && aSize
.Height
== 0 )
393 aSize
= aDefaultSize
;
398 catch( const uno::Exception
& )
400 TOOLS_WARN_EXCEPTION("chart2", "" );
405 awt::Size
aAWTPixelSize(10,10);
406 if( xProp
->getPropertyValue( u
"SizePixel"_ustr
) >>= aAWTPixelSize
)
408 Size
aPixelSize(aAWTPixelSize
.Width
,aAWTPixelSize
.Height
);
409 Size aNewSize
= o3tl::convert(aPixelSize
, o3tl::Length::pt
, o3tl::Length::mm100
);
411 aSize
= awt::Size( aNewSize
.Width(), aNewSize
.Height() );
413 if( aSize
.Width
== 0 && aSize
.Height
== 0 )
414 aSize
= aDefaultSize
;
418 rSymbol
.Size
= aSize
;
420 catch( const uno::Exception
& )
422 TOOLS_WARN_EXCEPTION("chart2", "" );
426 }//end anonymous namespace
428 WrappedSymbolSizeProperty::WrappedSymbolSizeProperty(
429 const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
,
430 tSeriesOrDiagramPropertyType ePropertyType
)
431 : WrappedSeriesOrDiagramProperty
< awt::Size
>( u
"SymbolSize"_ustr
432 , uno::Any( awt::Size(250,250) ), spChart2ModelContact
, ePropertyType
)
436 awt::Size
WrappedSymbolSizeProperty::getValueFromSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
) const
439 m_aDefaultValue
>>= aRet
;
440 chart2::Symbol aSymbol
;
441 if( xSeriesPropertySet
.is() && ( xSeriesPropertySet
->getPropertyValue(u
"Symbol"_ustr
) >>= aSymbol
))
446 void WrappedSymbolSizeProperty::setValueToSeries(
447 const Reference
< beans::XPropertySet
>& xSeriesPropertySet
,
448 const awt::Size
& aNewSize
) const
450 if(!xSeriesPropertySet
.is())
453 chart2::Symbol aSymbol
;
454 if( xSeriesPropertySet
->getPropertyValue(u
"Symbol"_ustr
) >>= aSymbol
)
456 aSymbol
.Size
= aNewSize
;
457 lcl_correctSymbolSizeForBitmaps(aSymbol
);
458 xSeriesPropertySet
->setPropertyValue( u
"Symbol"_ustr
, uno::Any( aSymbol
) );
462 beans::PropertyState
WrappedSymbolSizeProperty::getPropertyState( const Reference
< beans::XPropertyState
>& xInnerPropertyState
) const
464 //only export symbol size if necessary
465 if( m_ePropertyType
== DIAGRAM
)
466 return beans::PropertyState_DEFAULT_VALUE
;
470 chart2::Symbol aSymbol
;
471 Reference
< beans::XPropertySet
> xSeriesPropertySet( xInnerPropertyState
, uno::UNO_QUERY
);
472 if( xSeriesPropertySet
.is() && ( xSeriesPropertySet
->getPropertyValue(u
"Symbol"_ustr
) >>= aSymbol
))
474 if( aSymbol
.Style
!= chart2::SymbolStyle_NONE
)
475 return beans::PropertyState_DIRECT_VALUE
;
478 catch( const uno::Exception
& )
480 DBG_UNHANDLED_EXCEPTION("chart2");
482 return beans::PropertyState_DEFAULT_VALUE
;
485 WrappedSymbolAndLinesProperty::WrappedSymbolAndLinesProperty(
486 const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
,
487 tSeriesOrDiagramPropertyType ePropertyType
)
488 : WrappedSeriesOrDiagramProperty
< bool >( u
"Lines"_ustr
489 , uno::Any( true ), spChart2ModelContact
, ePropertyType
)
493 bool WrappedSymbolAndLinesProperty::getValueFromSeries( const Reference
< beans::XPropertySet
>& /*xSeriesPropertySet*/ ) const
495 //do not export this property anymore, instead use a linestyle none for no lines
499 void WrappedSymbolAndLinesProperty::setValueToSeries(
500 const Reference
< beans::XPropertySet
>& xSeriesPropertySet
,
501 const bool& bDrawLines
) const
503 if(!xSeriesPropertySet
.is())
506 drawing::LineStyle
eOldLineStyle( drawing::LineStyle_SOLID
);
507 xSeriesPropertySet
->getPropertyValue( u
"LineStyle"_ustr
) >>= eOldLineStyle
;
510 //#i114298# don't overwrite dashed lines with solid lines here
511 if( eOldLineStyle
== drawing::LineStyle_NONE
)
512 xSeriesPropertySet
->setPropertyValue( u
"LineStyle"_ustr
, uno::Any( drawing::LineStyle_SOLID
) );
516 if( eOldLineStyle
!= drawing::LineStyle_NONE
)
517 xSeriesPropertySet
->setPropertyValue( u
"LineStyle"_ustr
, uno::Any( drawing::LineStyle_NONE
) );
521 beans::PropertyState
WrappedSymbolAndLinesProperty::getPropertyState( const Reference
< beans::XPropertyState
>& /*xInnerPropertyState*/ ) const
523 //do not export this property anymore, instead use a linestyle none for no lines
524 return beans::PropertyState_DEFAULT_VALUE
;
529 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */