Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "VLegendSymbolFactory.hxx"
21 : #include "macros.hxx"
22 : #include "PropertyMapper.hxx"
23 : #include "ShapeFactory.hxx"
24 : #include "ObjectIdentifier.hxx"
25 : #include <com/sun/star/drawing/LineStyle.hpp>
26 : #include <com/sun/star/chart2/Symbol.hpp>
27 :
28 : using namespace ::com::sun::star;
29 : using ::com::sun::star::uno::Reference;
30 : using ::com::sun::star::uno::Sequence;
31 :
32 : namespace
33 : {
34 1726 : void lcl_setPropetiesToShape(
35 : const Reference< beans::XPropertySet > & xProp,
36 : const Reference< drawing::XShape > & xShape,
37 : ::chart::VLegendSymbolFactory::tPropertyType ePropertyType,
38 : const awt::Size& aMaxSymbolExtent = awt::Size(0,0))
39 : {
40 1726 : const ::chart::tPropertyNameMap & aFilledSeriesNameMap( ::chart::PropertyMapper::getPropertyNameMapForFilledSeriesProperties());
41 1726 : const ::chart::tPropertyNameMap & aLineSeriesNameMap( ::chart::PropertyMapper::getPropertyNameMapForLineSeriesProperties());
42 1726 : const ::chart::tPropertyNameMap & aLineNameMap( ::chart::PropertyMapper::getPropertyNameMapForLineProperties());
43 1726 : const ::chart::tPropertyNameMap & aFillNameMap( ::chart::PropertyMapper::getPropertyNameMapForFillProperties());
44 1726 : const ::chart::tPropertyNameMap & aFillLineNameMap( ::chart::PropertyMapper::getPropertyNameMapForFillAndLineProperties());
45 :
46 1726 : Reference< beans::XPropertySet > xShapeProp( xShape, uno::UNO_QUERY );
47 1726 : if( xProp.is() && xShapeProp.is() )
48 : {
49 1726 : ::chart::tPropertyNameValueMap aValueMap;
50 1726 : switch( ePropertyType )
51 : {
52 : case ::chart::VLegendSymbolFactory::PROP_TYPE_FILLED_SERIES:
53 1572 : ::chart::PropertyMapper::getValueMap( aValueMap, aFilledSeriesNameMap, xProp );
54 1572 : break;
55 : case ::chart::VLegendSymbolFactory::PROP_TYPE_LINE_SERIES:
56 133 : ::chart::PropertyMapper::getValueMap( aValueMap, aLineSeriesNameMap, xProp );
57 133 : break;
58 : case ::chart::VLegendSymbolFactory::PROP_TYPE_LINE:
59 21 : ::chart::PropertyMapper::getValueMap( aValueMap, aLineNameMap, xProp );
60 21 : break;
61 : case ::chart::VLegendSymbolFactory::PROP_TYPE_FILL:
62 0 : ::chart::PropertyMapper::getValueMap( aValueMap, aFillNameMap, xProp );
63 0 : break;
64 : case ::chart::VLegendSymbolFactory::PROP_TYPE_FILL_AND_LINE:
65 0 : ::chart::PropertyMapper::getValueMap( aValueMap, aFillLineNameMap, xProp );
66 0 : break;
67 : }
68 :
69 1726 : ::chart::tNameSequence aPropNames;
70 3452 : ::chart::tAnySequence aPropValues;
71 1726 : ::chart::PropertyMapper::getMultiPropertyListsFromValueMap( aPropNames, aPropValues, aValueMap );
72 :
73 1726 : uno::Any* pLineWidthAny = ::chart::PropertyMapper::getValuePointer(aPropValues,aPropNames,"LineWidth");
74 1726 : sal_Int32 nLineWidth = 0;
75 1726 : if( pLineWidthAny && (*pLineWidthAny>>=nLineWidth) )
76 : {
77 : // use legend entry height as upper limit for line width
78 1726 : sal_Int32 nMaxLineWidthForLegend = aMaxSymbolExtent.Height;
79 1726 : if( nLineWidth>nMaxLineWidthForLegend )
80 0 : *pLineWidthAny = uno::makeAny( nMaxLineWidthForLegend );
81 : }
82 :
83 3452 : ::chart::PropertyMapper::setMultiProperties( aPropNames, aPropValues, xShapeProp );
84 1726 : }
85 1726 : }
86 :
87 : } // anonymous namespace
88 :
89 : namespace chart
90 : {
91 :
92 1726 : Reference< drawing::XShape > VLegendSymbolFactory::createSymbol(
93 : const awt::Size& rEntryKeyAspectRatio,
94 : const Reference< drawing::XShapes > xSymbolContainer,
95 : LegendSymbolStyle eStyle,
96 : const Reference< lang::XMultiServiceFactory > & xShapeFactory,
97 : const Reference< beans::XPropertySet > & xLegendEntryProperties,
98 : tPropertyType ePropertyType, const uno::Any& rExplicitSymbol )
99 : {
100 1726 : Reference< drawing::XShape > xResult;
101 :
102 1726 : if( ! (xSymbolContainer.is() && xShapeFactory.is()))
103 0 : return xResult;
104 :
105 1726 : xResult.set( xShapeFactory->createInstance(
106 1726 : "com.sun.star.drawing.GroupShape"), uno::UNO_QUERY );
107 1726 : xSymbolContainer->add( xResult );
108 3452 : Reference< drawing::XShapes > xResultGroup( xResult, uno::UNO_QUERY );
109 1726 : if( ! xResultGroup.is())
110 0 : return xResult;
111 :
112 : // add an invisible square box to maintain aspect ratio
113 : Reference< drawing::XShape > xBound( ShapeFactory(xShapeFactory).createInvisibleRectangle(
114 3452 : xResultGroup, rEntryKeyAspectRatio ));
115 :
116 : // create symbol
117 : try
118 : {
119 1726 : if( eStyle == LegendSymbolStyle_LINE )
120 : {
121 154 : Reference< drawing::XShape > xLine( xShapeFactory->createInstance(
122 154 : "com.sun.star.drawing.LineShape"), uno::UNO_QUERY );
123 154 : if( xLine.is())
124 : {
125 154 : xResultGroup->add( xLine );
126 154 : xLine->setSize( awt::Size( rEntryKeyAspectRatio.Width, 0 ));
127 154 : xLine->setPosition( awt::Point( 0, rEntryKeyAspectRatio.Height/2 ));
128 :
129 154 : lcl_setPropetiesToShape( xLegendEntryProperties, xLine, ePropertyType, rEntryKeyAspectRatio );
130 : }
131 :
132 308 : Reference< drawing::XShape > xSymbol;
133 154 : const sal_Int32 nSize = std::min(rEntryKeyAspectRatio.Width,rEntryKeyAspectRatio.Height);
134 308 : chart2::Symbol aSymbol;
135 154 : if( rExplicitSymbol >>= aSymbol )
136 : {
137 123 : drawing::Direction3D aSymbolSize( nSize, nSize, 0 );
138 123 : drawing::Position3D aPos( rEntryKeyAspectRatio.Width/2, rEntryKeyAspectRatio.Height/2, 0 );
139 123 : ShapeFactory aFactory( xShapeFactory );
140 123 : if( aSymbol.Style == chart2::SymbolStyle_STANDARD )
141 : {
142 : // take series color as fill color
143 24 : xLegendEntryProperties->getPropertyValue( "Color") >>= aSymbol.FillColor;
144 : // border of symbols always same as fill color
145 24 : aSymbol.BorderColor = aSymbol.FillColor;
146 :
147 : xSymbol.set( aFactory.createSymbol2D(
148 : xResultGroup,
149 : aPos,
150 : aSymbolSize,
151 : aSymbol.StandardSymbol,
152 : aSymbol.BorderColor,
153 24 : aSymbol.FillColor ));
154 : }
155 99 : else if( aSymbol.Style == chart2::SymbolStyle_GRAPHIC )
156 : {
157 : xSymbol.set( aFactory.createGraphic2D(
158 : xResultGroup,
159 : aPos,
160 : aSymbolSize,
161 0 : aSymbol.Graphic ));
162 : }
163 99 : else if( aSymbol.Style == chart2::SymbolStyle_AUTO )
164 : {
165 : OSL_TRACE("the given parameter is not allowed to contain an automatic symbol style");
166 123 : }
167 154 : }
168 : }
169 1572 : else if( eStyle == LegendSymbolStyle_CIRCLE )
170 : {
171 0 : Reference< drawing::XShape > xShape( xShapeFactory->createInstance(
172 0 : "com.sun.star.drawing.EllipseShape"), uno::UNO_QUERY );
173 0 : if( xShape.is() )
174 : {
175 0 : xResultGroup->add( xShape );
176 0 : sal_Int32 nSize = std::min( rEntryKeyAspectRatio.Width, rEntryKeyAspectRatio.Height );
177 0 : xShape->setSize( awt::Size( nSize, nSize ) );
178 0 : xShape->setPosition( awt::Point( rEntryKeyAspectRatio.Width/2-nSize/2, rEntryKeyAspectRatio.Height/2-nSize/2 ) );
179 0 : lcl_setPropetiesToShape( xLegendEntryProperties, xShape, ePropertyType ); // PROP_TYPE_FILLED_SERIES );
180 0 : }
181 : }
182 : else // eStyle == LegendSymbolStyle_BOX
183 : {
184 1572 : Reference< drawing::XShape > xShape( xShapeFactory->createInstance(
185 1572 : "com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY );
186 1572 : if( xShape.is() )
187 : {
188 1572 : xResultGroup->add( xShape );
189 1572 : xShape->setSize( rEntryKeyAspectRatio );
190 1572 : xShape->setPosition( awt::Point( 0, 0 ) );
191 1572 : lcl_setPropetiesToShape( xLegendEntryProperties, xShape, ePropertyType ); // PROP_TYPE_FILLED_SERIES );
192 1572 : }
193 : }
194 : }
195 0 : catch( const uno::Exception & ex )
196 : {
197 : ASSERT_EXCEPTION( ex );
198 : }
199 :
200 1726 : return xResult;
201 : }
202 :
203 : } // namespace chart
204 :
205 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|