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 <VLegendSymbolFactory.hxx>
21 #include <PropertyMapper.hxx>
22 #include <ShapeFactory.hxx>
23 #include <com/sun/star/drawing/Position3D.hpp>
24 #include <com/sun/star/chart2/Symbol.hpp>
25 #include <com/sun/star/drawing/Direction3D.hpp>
26 #include <comphelper/diagnose_ex.hxx>
27 #include <sal/log.hxx>
29 using namespace ::com::sun::star
;
30 using ::com::sun::star::uno::Reference
;
35 void getPropNamesAndValues( const Reference
< beans::XPropertySet
>& xProp
,
36 ::chart::tNameSequence
& rNames
,
37 ::chart::tAnySequence
& rValues
,
38 ::chart::VLegendSymbolFactory::PropertyType ePropertyType
,
39 const awt::Size
& aMaxSymbolExtent
)
41 const ::chart::tPropertyNameMap
& aFilledSeriesNameMap( ::chart::PropertyMapper::getPropertyNameMapForFilledSeriesProperties());
42 const ::chart::tPropertyNameMap
& aLineSeriesNameMap( ::chart::PropertyMapper::getPropertyNameMapForLineSeriesProperties());
43 const ::chart::tPropertyNameMap
& aLineNameMap( ::chart::PropertyMapper::getPropertyNameMapForLineProperties());
45 ::chart::tPropertyNameValueMap aValueMap
;
46 switch( ePropertyType
)
48 case ::chart::VLegendSymbolFactory::PropertyType::FilledSeries
:
49 ::chart::PropertyMapper::getValueMap( aValueMap
, aFilledSeriesNameMap
, xProp
);
51 case ::chart::VLegendSymbolFactory::PropertyType::LineSeries
:
52 ::chart::PropertyMapper::getValueMap( aValueMap
, aLineSeriesNameMap
, xProp
);
54 case ::chart::VLegendSymbolFactory::PropertyType::Line
:
55 ::chart::PropertyMapper::getValueMap( aValueMap
, aLineNameMap
, xProp
);
59 ::chart::PropertyMapper::getMultiPropertyListsFromValueMap( rNames
, rValues
, aValueMap
);
61 uno::Any
* pLineWidthAny
= ::chart::PropertyMapper::getValuePointer(rValues
,rNames
,u
"LineWidth");
62 sal_Int32 nLineWidth
= 0;
63 if( pLineWidthAny
&& (*pLineWidthAny
>>=nLineWidth
) )
65 // use legend entry height as upper limit for line width
66 sal_Int32 nMaxLineWidthForLegend
= aMaxSymbolExtent
.Height
;
67 if( nLineWidth
>nMaxLineWidthForLegend
)
68 *pLineWidthAny
<<= nMaxLineWidthForLegend
;
72 void lcl_setPropertiesToShape(
73 const Reference
< beans::XPropertySet
> & xProp
,
74 const rtl::Reference
< SvxShape
> & xShape
,
75 ::chart::VLegendSymbolFactory::PropertyType ePropertyType
,
76 const awt::Size
& aMaxSymbolExtent
)
78 ::chart::tNameSequence aPropNames
;
79 ::chart::tAnySequence aPropValues
;
80 getPropNamesAndValues( xProp
, aPropNames
, aPropValues
,
81 ePropertyType
, aMaxSymbolExtent
);
83 ::chart::PropertyMapper::setMultiProperties( aPropNames
, aPropValues
, *xShape
);
86 } // anonymous namespace
91 rtl::Reference
< SvxShapeGroup
> VLegendSymbolFactory::createSymbol(
92 const awt::Size
& rEntryKeyAspectRatio
,
93 const rtl::Reference
<SvxShapeGroupAnyD
>& rSymbolContainer
,
94 LegendSymbolStyle eStyle
,
95 const Reference
< beans::XPropertySet
> & xLegendEntryProperties
,
96 PropertyType ePropertyType
, const uno::Any
& rExplicitSymbol
)
98 rtl::Reference
< SvxShapeGroup
> xResult
;
100 if( !rSymbolContainer
)
103 xResult
= ShapeFactory::createGroup2D( rSymbolContainer
);
107 rtl::Reference
<SvxShapeGroupAnyD
> xResultGroup
= xResult
;
109 // add an invisible square box to maintain aspect ratio
110 ShapeFactory::createInvisibleRectangle( xResultGroup
, rEntryKeyAspectRatio
);
115 if( eStyle
== LegendSymbolStyle::Line
)
117 rtl::Reference
<SvxShapePolyPolygon
> xLine
=
118 ShapeFactory::createLine( xResultGroup
, awt::Size( rEntryKeyAspectRatio
.Width
, 0 ),
119 awt::Point( 0, rEntryKeyAspectRatio
.Height
/2 ));
120 lcl_setPropertiesToShape( xLegendEntryProperties
, xLine
, ePropertyType
, rEntryKeyAspectRatio
);
122 const sal_Int32 nSize
= std::min(rEntryKeyAspectRatio
.Width
,rEntryKeyAspectRatio
.Height
);
123 chart2::Symbol aSymbol
;
124 if( rExplicitSymbol
>>= aSymbol
)
126 drawing::Direction3D
aSymbolSize( nSize
, nSize
, 0 );
127 drawing::Position3D
aPos( rEntryKeyAspectRatio
.Width
/2.0, rEntryKeyAspectRatio
.Height
/2.0, 0 );
128 if( aSymbol
.Style
== chart2::SymbolStyle_STANDARD
)
130 // take series color as fill color
131 xLegendEntryProperties
->getPropertyValue( u
"Color"_ustr
) >>= aSymbol
.FillColor
;
132 // border of symbols always same as fill color
133 aSymbol
.BorderColor
= aSymbol
.FillColor
;
135 ShapeFactory::createSymbol2D(
139 aSymbol
.StandardSymbol
,
143 else if( aSymbol
.Style
== chart2::SymbolStyle_GRAPHIC
)
145 ShapeFactory::createGraphic2D(
151 else if( aSymbol
.Style
== chart2::SymbolStyle_AUTO
)
153 SAL_WARN("chart2", "the given parameter is not allowed to contain an automatic symbol style");
157 else if( eStyle
== LegendSymbolStyle::Circle
)
159 sal_Int32 nSize
= std::min( rEntryKeyAspectRatio
.Width
, rEntryKeyAspectRatio
.Height
);
160 rtl::Reference
<SvxShapeCircle
> xShape
=
161 ShapeFactory::createCircle( xResultGroup
, awt::Size( nSize
, nSize
),
162 awt::Point( rEntryKeyAspectRatio
.Width
/2-nSize
/2, rEntryKeyAspectRatio
.Height
/2-nSize
/2 ));
163 lcl_setPropertiesToShape( xLegendEntryProperties
, xShape
, ePropertyType
, awt::Size(0,0) ); // PropertyType::FilledSeries );
165 else // eStyle == LegendSymbolStyle::Box
167 tNameSequence aPropNames
;
168 tAnySequence aPropValues
;
170 getPropNamesAndValues( xLegendEntryProperties
, aPropNames
, aPropValues
,
171 ePropertyType
, awt::Size(0,0) );// PropertyType::FilledSeries
173 ShapeFactory::createRectangle( xResultGroup
,
174 rEntryKeyAspectRatio
, awt::Point( 0, 0 ),
175 aPropNames
, aPropValues
);
178 catch( const uno::Exception
& )
180 DBG_UNHANDLED_EXCEPTION("chart2");
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */