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"
23 #include "FastPropertyIdRanges.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/chart/ChartSymbolType.hpp>
30 #include <com/sun/star/drawing/LineStyle.hpp>
31 #include <com/sun/star/graphic/GraphicProvider.hpp>
32 #include <com/sun/star/graphic/XGraphicProvider.hpp>
34 #include <editeng/unoprnms.hxx>
35 #include <vcl/graph.hxx>
36 #include <svtools/grfmgr.hxx>
37 #include <vcl/outdev.hxx>
39 #include <comphelper/processfactory.hxx>
41 using namespace ::com::sun::star
;
42 using ::com::sun::star::uno::Any
;
43 using ::com::sun::star::uno::Reference
;
44 using ::com::sun::star::uno::Sequence
;
45 using ::com::sun::star::beans::Property
;
47 namespace com
{ namespace sun
{ namespace star
{ namespace awt
{
49 // this operator is not defined by default
50 bool operator!=( const awt::Size
& rSize1
, const awt::Size
& rSize2
)
52 return (rSize1
.Width
!= rSize2
.Width
) || (rSize1
.Height
!= rSize2
.Height
);
62 class WrappedSymbolTypeProperty
: public WrappedSeriesOrDiagramProperty
< sal_Int32
>
65 virtual sal_Int32
getValueFromSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
) const SAL_OVERRIDE
;
66 virtual void setValueToSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
, const sal_Int32
& aNewValue
) const SAL_OVERRIDE
;
68 virtual Any
getPropertyValue( const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
69 throw ( beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
) SAL_OVERRIDE
;
70 virtual beans::PropertyState
getPropertyState( const Reference
< beans::XPropertyState
>& xInnerPropertyState
) const
71 throw (beans::UnknownPropertyException
, uno::RuntimeException
) SAL_OVERRIDE
;
73 explicit WrappedSymbolTypeProperty( ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
,
74 tSeriesOrDiagramPropertyType ePropertyType
);
75 virtual ~WrappedSymbolTypeProperty();
78 class WrappedSymbolBitmapURLProperty
: public WrappedSeriesOrDiagramProperty
< OUString
>
81 virtual OUString
getValueFromSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
) const SAL_OVERRIDE
;
82 virtual void setValueToSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
, const OUString
& aNewGraphicURL
) const SAL_OVERRIDE
;
84 explicit WrappedSymbolBitmapURLProperty( ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
,
85 tSeriesOrDiagramPropertyType ePropertyType
);
86 virtual ~WrappedSymbolBitmapURLProperty();
89 class WrappedSymbolSizeProperty
: public WrappedSeriesOrDiagramProperty
< awt::Size
>
92 virtual awt::Size
getValueFromSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
) const SAL_OVERRIDE
;
93 virtual void setValueToSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
, const awt::Size
& aNewSize
) const SAL_OVERRIDE
;
94 virtual beans::PropertyState
getPropertyState( const Reference
< beans::XPropertyState
>& xInnerPropertyState
) const
95 throw (beans::UnknownPropertyException
, uno::RuntimeException
) SAL_OVERRIDE
;
97 explicit WrappedSymbolSizeProperty( ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
,
98 tSeriesOrDiagramPropertyType ePropertyType
);
99 virtual ~WrappedSymbolSizeProperty();
102 class WrappedSymbolAndLinesProperty
: public WrappedSeriesOrDiagramProperty
< sal_Bool
>
105 virtual sal_Bool
getValueFromSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
) const SAL_OVERRIDE
;
106 virtual void setValueToSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
, const sal_Bool
& bDrawLines
) const SAL_OVERRIDE
;
107 virtual beans::PropertyState
getPropertyState( const Reference
< beans::XPropertyState
>& xInnerPropertyState
) const
108 throw (beans::UnknownPropertyException
, uno::RuntimeException
) SAL_OVERRIDE
;
110 explicit WrappedSymbolAndLinesProperty( ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
,
111 tSeriesOrDiagramPropertyType ePropertyType
);
112 virtual ~WrappedSymbolAndLinesProperty();
120 PROP_CHART_SYMBOL_TYPE
= FAST_PROPERTY_ID_START_CHART_SYMBOL_PROP
,
121 PROP_CHART_SYMBOL_BITMAP_URL
,
122 PROP_CHART_SYMBOL_SIZE
,
123 PROP_CHART_SYMBOL_AND_LINES
126 sal_Int32
lcl_getSymbolType( const ::com::sun::star::chart2::Symbol
& rSymbol
)
128 sal_Int32 nSymbol
= ::com::sun::star::chart::ChartSymbolType::NONE
;
129 switch( rSymbol
.Style
)
131 case chart2::SymbolStyle_NONE
:
133 case chart2::SymbolStyle_AUTO
:
134 nSymbol
= ::com::sun::star::chart::ChartSymbolType::AUTO
;
136 case chart2::SymbolStyle_STANDARD
:
137 nSymbol
= rSymbol
.StandardSymbol
%15;
139 case chart2::SymbolStyle_POLYGON
://new feature
140 nSymbol
= ::com::sun::star::chart::ChartSymbolType::AUTO
;
142 case chart2::SymbolStyle_GRAPHIC
:
143 nSymbol
= ::com::sun::star::chart::ChartSymbolType::BITMAPURL
;
146 nSymbol
= ::com::sun::star::chart::ChartSymbolType::AUTO
;
151 void lcl_setSymbolTypeToSymbol( sal_Int32 nSymbolType
, chart2::Symbol
& rSymbol
)
153 switch( nSymbolType
)
155 case ::com::sun::star::chart::ChartSymbolType::NONE
:
156 rSymbol
.Style
= chart2::SymbolStyle_NONE
;
158 case ::com::sun::star::chart::ChartSymbolType::AUTO
:
159 rSymbol
.Style
= chart2::SymbolStyle_AUTO
;
161 case ::com::sun::star::chart::ChartSymbolType::BITMAPURL
:
162 rSymbol
.Style
= chart2::SymbolStyle_GRAPHIC
;
165 rSymbol
.Style
= chart2::SymbolStyle_STANDARD
;
166 rSymbol
.StandardSymbol
= nSymbolType
;
171 void lcl_addWrappedProperties( std::vector
< WrappedProperty
* >& rList
172 , ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
173 , tSeriesOrDiagramPropertyType ePropertyType
)
175 rList
.push_back( new WrappedSymbolTypeProperty( spChart2ModelContact
, ePropertyType
) );
176 rList
.push_back( new WrappedSymbolBitmapURLProperty( spChart2ModelContact
, ePropertyType
) );
177 rList
.push_back( new WrappedSymbolSizeProperty( spChart2ModelContact
, ePropertyType
) );
178 rList
.push_back( new WrappedSymbolAndLinesProperty( spChart2ModelContact
, ePropertyType
) );
181 }//anonymous namespace
183 void WrappedSymbolProperties::addProperties( ::std::vector
< Property
> & rOutProperties
)
185 rOutProperties
.push_back(
186 Property( "SymbolType",
187 PROP_CHART_SYMBOL_TYPE
,
188 cppu::UnoType
<sal_Int32
>::get(),
189 beans::PropertyAttribute::BOUND
190 | beans::PropertyAttribute::MAYBEDEFAULT
));
192 rOutProperties
.push_back(
193 Property( "SymbolBitmapURL",
194 PROP_CHART_SYMBOL_BITMAP_URL
,
195 cppu::UnoType
<OUString
>::get(),
196 beans::PropertyAttribute::BOUND
197 | beans::PropertyAttribute::MAYBEDEFAULT
));
199 rOutProperties
.push_back(
200 Property( "SymbolSize",
201 PROP_CHART_SYMBOL_SIZE
,
202 cppu::UnoType
<awt::Size
>::get(),
203 beans::PropertyAttribute::BOUND
204 | beans::PropertyAttribute::MAYBEDEFAULT
));
206 rOutProperties
.push_back(
208 PROP_CHART_SYMBOL_AND_LINES
,
209 cppu::UnoType
<bool>::get(),
210 beans::PropertyAttribute::BOUND
211 | beans::PropertyAttribute::MAYBEDEFAULT
));
214 void WrappedSymbolProperties::addWrappedPropertiesForSeries( std::vector
< WrappedProperty
* >& rList
215 , ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
217 lcl_addWrappedProperties( rList
, spChart2ModelContact
, DATA_SERIES
);
220 void WrappedSymbolProperties::addWrappedPropertiesForDiagram( std::vector
< WrappedProperty
* >& rList
221 , ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
223 lcl_addWrappedProperties( rList
, spChart2ModelContact
, DIAGRAM
);
226 WrappedSymbolTypeProperty::WrappedSymbolTypeProperty(
227 ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
,
228 tSeriesOrDiagramPropertyType ePropertyType
)
229 : WrappedSeriesOrDiagramProperty
< sal_Int32
>( "SymbolType"
230 , uno::makeAny( ::com::sun::star::chart::ChartSymbolType::NONE
)
231 , spChart2ModelContact
235 WrappedSymbolTypeProperty::~WrappedSymbolTypeProperty()
239 sal_Int32
WrappedSymbolTypeProperty::getValueFromSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
) const
242 m_aDefaultValue
>>= aRet
;
243 chart2::Symbol aSymbol
;
244 if( xSeriesPropertySet
.is() && ( xSeriesPropertySet
->getPropertyValue("Symbol") >>= aSymbol
) )
245 aRet
= lcl_getSymbolType( aSymbol
);
249 void WrappedSymbolTypeProperty::setValueToSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
, const sal_Int32
& nSymbolType
) const
251 if(!xSeriesPropertySet
.is())
254 chart2::Symbol aSymbol
;
255 xSeriesPropertySet
->getPropertyValue("Symbol") >>= aSymbol
;
257 lcl_setSymbolTypeToSymbol( nSymbolType
, aSymbol
);
258 xSeriesPropertySet
->setPropertyValue( "Symbol", uno::makeAny( aSymbol
) );
261 Any
WrappedSymbolTypeProperty::getPropertyValue( const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
262 throw ( beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
264 //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
265 if( m_ePropertyType
== DIAGRAM
)
267 bool bHasAmbiguousValue
= false;
268 sal_Int32 aValue
= 0;
269 if( detectInnerValue( aValue
, bHasAmbiguousValue
) )
271 if(bHasAmbiguousValue
)
273 m_aOuterValue
= uno::makeAny( ::com::sun::star::chart::ChartSymbolType::AUTO
);
277 if( ::com::sun::star::chart::ChartSymbolType::NONE
== aValue
)
278 m_aOuterValue
= uno::makeAny( ::com::sun::star::chart::ChartSymbolType::NONE
);
280 m_aOuterValue
= uno::makeAny( ::com::sun::star::chart::ChartSymbolType::AUTO
);
283 return m_aOuterValue
;
287 ::com::sun::star::uno::Any
aRet( m_aDefaultValue
);
288 aRet
<<= getValueFromSeries( xInnerPropertySet
);
293 beans::PropertyState
WrappedSymbolTypeProperty::getPropertyState( const Reference
< beans::XPropertyState
>& xInnerPropertyState
) const
294 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
296 //the special situation for this property here is that the diagram default can be
297 //different from the normal default and different from all sinlges series values
298 //so we need to return PropertyState_DIRECT_VALUE for more cases
300 if( m_ePropertyType
== DATA_SERIES
&& //single series or point
301 m_spChart2ModelContact
.get())
303 Reference
< chart2::XDiagram
> xDiagram( m_spChart2ModelContact
->getChart2Diagram() );
304 Reference
< chart2::XDataSeries
> xSeries( xInnerPropertyState
, uno::UNO_QUERY
);
305 Reference
< chart2::XChartType
> xChartType( DiagramHelper::getChartTypeOfSeries( xDiagram
, xSeries
) );
306 if( ChartTypeHelper::isSupportingSymbolProperties( xChartType
, 2 ) )
307 return beans::PropertyState_DIRECT_VALUE
;
309 return WrappedProperty::getPropertyState( xInnerPropertyState
);
312 WrappedSymbolBitmapURLProperty::WrappedSymbolBitmapURLProperty(
313 ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
,
314 tSeriesOrDiagramPropertyType ePropertyType
)
315 : WrappedSeriesOrDiagramProperty
< OUString
>( "SymbolBitmapURL"
316 , uno::makeAny( OUString() ), spChart2ModelContact
, ePropertyType
)
320 WrappedSymbolBitmapURLProperty::~WrappedSymbolBitmapURLProperty()
324 OUString
WrappedSymbolBitmapURLProperty::getValueFromSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
) const
327 m_aDefaultValue
>>= aRet
;
328 chart2::Symbol aSymbol
;
329 if( xSeriesPropertySet
.is() && ( xSeriesPropertySet
->getPropertyValue("Symbol") >>= aSymbol
)
330 && aSymbol
.Graphic
.is())
332 GraphicObject
aGrObj( Graphic( aSymbol
.Graphic
));
333 aRet
= UNO_NAME_GRAPHOBJ_URLPREFIX
+
334 OStringToOUString(aGrObj
.GetUniqueID(),
335 RTL_TEXTENCODING_ASCII_US
);
340 void WrappedSymbolBitmapURLProperty::setValueToSeries(
341 const Reference
< beans::XPropertySet
>& xSeriesPropertySet
,
342 const OUString
& aNewGraphicURL
) const
344 if(!xSeriesPropertySet
.is())
347 chart2::Symbol aSymbol
;
348 if( xSeriesPropertySet
->getPropertyValue("Symbol") >>= aSymbol
)
350 bool bMatchesPrefix
= aNewGraphicURL
.match( UNO_NAME_GRAPHOBJ_URLPREFIX
);
353 GraphicObject aGrObj
= GraphicObject(
354 OUStringToOString(aNewGraphicURL
.copy( RTL_CONSTASCII_LENGTH(UNO_NAME_GRAPHOBJ_URLPREFIX
) ), RTL_TEXTENCODING_ASCII_US
));
355 aSymbol
.Graphic
.set( aGrObj
.GetGraphic().GetXGraphic());
356 xSeriesPropertySet
->setPropertyValue( "Symbol", uno::makeAny( aSymbol
) );
362 // @todo: get factory from some context?
363 Reference
< uno::XComponentContext
> xContext
= comphelper::getProcessComponentContext();
364 Reference
< graphic::XGraphicProvider
> xGraphProv( graphic::GraphicProvider::create(xContext
) );
365 Sequence
< beans::PropertyValue
> aArgs(1);
366 aArgs
[0] = beans::PropertyValue( "URL", -1, uno::makeAny( aNewGraphicURL
),
367 beans::PropertyState_DIRECT_VALUE
);
368 aSymbol
.Graphic
.set( xGraphProv
->queryGraphic( aArgs
));
369 OSL_ENSURE( aSymbol
.Graphic
.is(), "Invalid URL for Symbol Bitmap" );
370 xSeriesPropertySet
->setPropertyValue( "Symbol", uno::makeAny( aSymbol
) );
372 catch( const uno::Exception
& ex
)
374 ASSERT_EXCEPTION( ex
);
383 void lcl_correctSymbolSizeForBitmaps( chart2::Symbol
& rSymbol
)
385 if( rSymbol
.Style
!= chart2::SymbolStyle_GRAPHIC
)
387 if( rSymbol
.Size
.Width
!= -1 )
389 if( rSymbol
.Size
.Height
!= -1 )
392 //find a good automatic size
395 const awt::Size
aDefaultSize(250,250);
396 awt::Size aSize
= aDefaultSize
;
397 uno::Reference
< beans::XPropertySet
> xProp( rSymbol
.Graphic
, uno::UNO_QUERY
);
400 bool bFoundSize
= false;
403 if( (xProp
->getPropertyValue( "Size100thMM" ) >>= aSize
) )
405 if( aSize
.Width
== 0 && aSize
.Height
== 0 )
406 aSize
= aDefaultSize
;
411 catch( const uno::Exception
& e
)
413 ASSERT_EXCEPTION( e
);
418 awt::Size
aAWTPixelSize(10,10);
419 if( (xProp
->getPropertyValue( "SizePixel" ) >>= aAWTPixelSize
) )
421 Size
aPixelSize(aAWTPixelSize
.Width
,aAWTPixelSize
.Height
);
422 Size aNewSize
= ( OutputDevice::LogicToLogic( aPixelSize
, MAP_PIXEL
, MAP_100TH_MM
));
423 aSize
= awt::Size( aNewSize
.Width(), aNewSize
.Height() );
425 if( aSize
.Width
== 0 && aSize
.Height
== 0 )
426 aSize
= aDefaultSize
;
430 rSymbol
.Size
= aSize
;
432 catch( const uno::Exception
& e
)
434 ASSERT_EXCEPTION( e
);
438 }//end anonymous namespace
440 WrappedSymbolSizeProperty::WrappedSymbolSizeProperty(
441 ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
,
442 tSeriesOrDiagramPropertyType ePropertyType
)
443 : WrappedSeriesOrDiagramProperty
< awt::Size
>( "SymbolSize"
444 , uno::makeAny( awt::Size(250,250) ), spChart2ModelContact
, ePropertyType
)
448 WrappedSymbolSizeProperty::~WrappedSymbolSizeProperty()
452 awt::Size
WrappedSymbolSizeProperty::getValueFromSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
) const
455 m_aDefaultValue
>>= aRet
;
456 chart2::Symbol aSymbol
;
457 if( xSeriesPropertySet
.is() && ( xSeriesPropertySet
->getPropertyValue("Symbol") >>= aSymbol
))
462 void WrappedSymbolSizeProperty::setValueToSeries(
463 const Reference
< beans::XPropertySet
>& xSeriesPropertySet
,
464 const awt::Size
& aNewSize
) const
466 if(!xSeriesPropertySet
.is())
469 chart2::Symbol aSymbol
;
470 if( xSeriesPropertySet
->getPropertyValue("Symbol") >>= aSymbol
)
472 aSymbol
.Size
= aNewSize
;
473 lcl_correctSymbolSizeForBitmaps(aSymbol
);
474 xSeriesPropertySet
->setPropertyValue( "Symbol", uno::makeAny( aSymbol
) );
478 beans::PropertyState
WrappedSymbolSizeProperty::getPropertyState( const Reference
< beans::XPropertyState
>& xInnerPropertyState
) const
479 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
481 //only export symbol size if necessary
482 if( m_ePropertyType
== DIAGRAM
)
483 return beans::PropertyState_DEFAULT_VALUE
;
487 chart2::Symbol aSymbol
;
488 Reference
< beans::XPropertySet
> xSeriesPropertySet( xInnerPropertyState
, uno::UNO_QUERY
);
489 if( xSeriesPropertySet
.is() && ( xSeriesPropertySet
->getPropertyValue("Symbol") >>= aSymbol
))
491 if( chart2::SymbolStyle_NONE
!= aSymbol
.Style
)
492 return beans::PropertyState_DIRECT_VALUE
;
495 catch( const uno::Exception
& ex
)
497 ASSERT_EXCEPTION( ex
);
499 return beans::PropertyState_DEFAULT_VALUE
;
502 WrappedSymbolAndLinesProperty::WrappedSymbolAndLinesProperty(
503 ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
,
504 tSeriesOrDiagramPropertyType ePropertyType
)
505 : WrappedSeriesOrDiagramProperty
< sal_Bool
>( "Lines"
506 , uno::makeAny( sal_True
), spChart2ModelContact
, ePropertyType
)
510 WrappedSymbolAndLinesProperty::~WrappedSymbolAndLinesProperty()
514 sal_Bool
WrappedSymbolAndLinesProperty::getValueFromSeries( const Reference
< beans::XPropertySet
>& /*xSeriesPropertySet*/ ) const
516 //do not export this property anymore, instead use a linestyle none for no lines
520 void WrappedSymbolAndLinesProperty::setValueToSeries(
521 const Reference
< beans::XPropertySet
>& xSeriesPropertySet
,
522 const sal_Bool
& bDrawLines
) const
524 if(!xSeriesPropertySet
.is())
527 drawing::LineStyle
eOldLineStyle( drawing::LineStyle_SOLID
);
528 xSeriesPropertySet
->getPropertyValue( "LineStyle" ) >>= eOldLineStyle
;
531 //#i114298# don't overwrite dashed lines with solid lines here
532 if( eOldLineStyle
== drawing::LineStyle_NONE
)
533 xSeriesPropertySet
->setPropertyValue( "LineStyle", uno::makeAny( drawing::LineStyle_SOLID
) );
537 if( eOldLineStyle
!= drawing::LineStyle_NONE
)
538 xSeriesPropertySet
->setPropertyValue( "LineStyle", uno::makeAny( drawing::LineStyle_NONE
) );
542 beans::PropertyState
WrappedSymbolAndLinesProperty::getPropertyState( const Reference
< beans::XPropertyState
>& /*xInnerPropertyState*/ ) const
543 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
545 //do not export this property anymore, instead use a linestyle none for no lines
546 return beans::PropertyState_DEFAULT_VALUE
;
549 } //namespace wrapper
552 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */