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"
22 #include "PropertyMapper.hxx"
23 #include "AbstractShapeFactory.hxx"
24 #include "ObjectIdentifier.hxx"
25 #include <com/sun/star/drawing/LineStyle.hpp>
26 #include <com/sun/star/chart2/Symbol.hpp>
28 using namespace ::com::sun::star
;
29 using ::com::sun::star::uno::Reference
;
30 using ::com::sun::star::uno::Sequence
;
35 void getPropNamesAndValues( const Reference
< beans::XPropertySet
>& xProp
,
36 ::chart::tNameSequence
& rNames
,
37 ::chart::tAnySequence
& rValues
,
38 ::chart::VLegendSymbolFactory::tPropertyType ePropertyType
,
39 const awt::Size
& aMaxSymbolExtent
= awt::Size(0,0))
41 const ::chart::tPropertyNameMap
& aFilledSeriesNameMap( ::chart::PropertyMapper::getPropertyNameMapForFilledSeriesProperties());
42 const ::chart::tPropertyNameMap
& aLineSeriesNameMap( ::chart::PropertyMapper::getPropertyNameMapForLineSeriesProperties());
43 const ::chart::tPropertyNameMap
& aLineNameMap( ::chart::PropertyMapper::getPropertyNameMapForLineProperties());
44 const ::chart::tPropertyNameMap
& aFillNameMap( ::chart::PropertyMapper::getPropertyNameMapForFillProperties());
45 const ::chart::tPropertyNameMap
& aFillLineNameMap( ::chart::PropertyMapper::getPropertyNameMapForFillAndLineProperties());
47 ::chart::tPropertyNameValueMap aValueMap
;
48 switch( ePropertyType
)
50 case ::chart::VLegendSymbolFactory::PROP_TYPE_FILLED_SERIES
:
51 ::chart::PropertyMapper::getValueMap( aValueMap
, aFilledSeriesNameMap
, xProp
);
53 case ::chart::VLegendSymbolFactory::PROP_TYPE_LINE_SERIES
:
54 ::chart::PropertyMapper::getValueMap( aValueMap
, aLineSeriesNameMap
, xProp
);
56 case ::chart::VLegendSymbolFactory::PROP_TYPE_LINE
:
57 ::chart::PropertyMapper::getValueMap( aValueMap
, aLineNameMap
, xProp
);
59 case ::chart::VLegendSymbolFactory::PROP_TYPE_FILL
:
60 ::chart::PropertyMapper::getValueMap( aValueMap
, aFillNameMap
, xProp
);
62 case ::chart::VLegendSymbolFactory::PROP_TYPE_FILL_AND_LINE
:
63 ::chart::PropertyMapper::getValueMap( aValueMap
, aFillLineNameMap
, xProp
);
67 ::chart::PropertyMapper::getMultiPropertyListsFromValueMap( rNames
, rValues
, aValueMap
);
69 uno::Any
* pLineWidthAny
= ::chart::PropertyMapper::getValuePointer(rValues
,rNames
,"LineWidth");
70 sal_Int32 nLineWidth
= 0;
71 if( pLineWidthAny
&& (*pLineWidthAny
>>=nLineWidth
) )
73 // use legend entry height as upper limit for line width
74 sal_Int32 nMaxLineWidthForLegend
= aMaxSymbolExtent
.Height
;
75 if( nLineWidth
>nMaxLineWidthForLegend
)
76 *pLineWidthAny
= uno::makeAny( nMaxLineWidthForLegend
);
80 void lcl_setPropetiesToShape(
81 const Reference
< beans::XPropertySet
> & xProp
,
82 const Reference
< drawing::XShape
> & xShape
,
83 ::chart::VLegendSymbolFactory::tPropertyType ePropertyType
,
84 const awt::Size
& aMaxSymbolExtent
= awt::Size(0,0))
86 ::chart::tNameSequence aPropNames
;
87 ::chart::tAnySequence aPropValues
;
88 getPropNamesAndValues( xProp
, aPropNames
, aPropValues
,
89 ePropertyType
, aMaxSymbolExtent
);
91 Reference
< beans::XPropertySet
> xShapeProp( xShape
, uno::UNO_QUERY
);
92 ::chart::PropertyMapper::setMultiProperties( aPropNames
, aPropValues
, xShapeProp
);
95 } // anonymous namespace
100 Reference
< drawing::XShape
> VLegendSymbolFactory::createSymbol(
101 const awt::Size
& rEntryKeyAspectRatio
,
102 const Reference
< drawing::XShapes
>& rSymbolContainer
,
103 LegendSymbolStyle eStyle
,
104 const Reference
< lang::XMultiServiceFactory
> & xShapeFactory
,
105 const Reference
< beans::XPropertySet
> & xLegendEntryProperties
,
106 tPropertyType ePropertyType
, const uno::Any
& rExplicitSymbol
)
108 Reference
< drawing::XShape
> xResult
;
110 if( ! (rSymbolContainer
.is() && xShapeFactory
.is()))
113 AbstractShapeFactory
* pShapeFactory
= AbstractShapeFactory::getOrCreateShapeFactory(xShapeFactory
);
114 xResult
.set( pShapeFactory
->createGroup2D( rSymbolContainer
), uno::UNO_QUERY
);
116 Reference
< drawing::XShapes
> xResultGroup( xResult
, uno::UNO_QUERY
);
117 if( ! xResultGroup
.is())
120 // add an invisible square box to maintain aspect ratio
121 Reference
< drawing::XShape
> xBound( pShapeFactory
->createInvisibleRectangle(
122 xResultGroup
, rEntryKeyAspectRatio
));
127 if( eStyle
== LegendSymbolStyle_LINE
)
129 Reference
< drawing::XShape
> xLine
=
130 pShapeFactory
->createLine( xResultGroup
, awt::Size( rEntryKeyAspectRatio
.Width
, 0 ),
131 awt::Point( 0, rEntryKeyAspectRatio
.Height
/2 ));
134 lcl_setPropetiesToShape( xLegendEntryProperties
, xLine
, ePropertyType
, rEntryKeyAspectRatio
);
137 Reference
< drawing::XShape
> xSymbol
;
138 const sal_Int32 nSize
= std::min(rEntryKeyAspectRatio
.Width
,rEntryKeyAspectRatio
.Height
);
139 chart2::Symbol aSymbol
;
140 if( rExplicitSymbol
>>= aSymbol
)
142 drawing::Direction3D
aSymbolSize( nSize
, nSize
, 0 );
143 drawing::Position3D
aPos( rEntryKeyAspectRatio
.Width
/2.0, rEntryKeyAspectRatio
.Height
/2.0, 0 );
144 AbstractShapeFactory
* pFactory
= AbstractShapeFactory::getOrCreateShapeFactory( xShapeFactory
);
145 if( aSymbol
.Style
== chart2::SymbolStyle_STANDARD
)
147 // take series color as fill color
148 xLegendEntryProperties
->getPropertyValue( "Color") >>= aSymbol
.FillColor
;
149 // border of symbols always same as fill color
150 aSymbol
.BorderColor
= aSymbol
.FillColor
;
152 xSymbol
.set( pFactory
->createSymbol2D(
156 aSymbol
.StandardSymbol
,
158 aSymbol
.FillColor
));
160 else if( aSymbol
.Style
== chart2::SymbolStyle_GRAPHIC
)
162 xSymbol
.set( pFactory
->createGraphic2D(
168 else if( aSymbol
.Style
== chart2::SymbolStyle_AUTO
)
170 SAL_WARN("chart2", "the given parameter is not allowed to contain an automatic symbol style");
174 else if( eStyle
== LegendSymbolStyle_CIRCLE
)
176 sal_Int32 nSize
= std::min( rEntryKeyAspectRatio
.Width
, rEntryKeyAspectRatio
.Height
);
177 Reference
< drawing::XShape
> xShape
=
178 pShapeFactory
->createCircle( xResultGroup
, awt::Size( nSize
, nSize
),
179 awt::Point( rEntryKeyAspectRatio
.Width
/2-nSize
/2, rEntryKeyAspectRatio
.Height
/2-nSize
/2 ));
182 lcl_setPropetiesToShape( xLegendEntryProperties
, xShape
, ePropertyType
); // PROP_TYPE_FILLED_SERIES );
185 else // eStyle == LegendSymbolStyle_BOX
187 tNameSequence aPropNames
;
188 tAnySequence aPropValues
;
190 getPropNamesAndValues( xLegendEntryProperties
, aPropNames
, aPropValues
,
191 ePropertyType
);// PROP_TYPE_FILLED_SERIES
193 Reference
< drawing::XShape
> xShape
=
194 pShapeFactory
->createRectangle( xResultGroup
,
195 rEntryKeyAspectRatio
, awt::Point( 0, 0 ),
196 aPropNames
, aPropValues
);
199 catch( const uno::Exception
& ex
)
201 ASSERT_EXCEPTION( ex
);
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */