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 "AbstractShapeFactory.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 :
35 0 : 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))
40 : {
41 0 : const ::chart::tPropertyNameMap & aFilledSeriesNameMap( ::chart::PropertyMapper::getPropertyNameMapForFilledSeriesProperties());
42 0 : const ::chart::tPropertyNameMap & aLineSeriesNameMap( ::chart::PropertyMapper::getPropertyNameMapForLineSeriesProperties());
43 0 : const ::chart::tPropertyNameMap & aLineNameMap( ::chart::PropertyMapper::getPropertyNameMapForLineProperties());
44 0 : const ::chart::tPropertyNameMap & aFillNameMap( ::chart::PropertyMapper::getPropertyNameMapForFillProperties());
45 0 : const ::chart::tPropertyNameMap & aFillLineNameMap( ::chart::PropertyMapper::getPropertyNameMapForFillAndLineProperties());
46 :
47 0 : ::chart::tPropertyNameValueMap aValueMap;
48 0 : switch( ePropertyType )
49 : {
50 : case ::chart::VLegendSymbolFactory::PROP_TYPE_FILLED_SERIES:
51 0 : ::chart::PropertyMapper::getValueMap( aValueMap, aFilledSeriesNameMap, xProp );
52 0 : break;
53 : case ::chart::VLegendSymbolFactory::PROP_TYPE_LINE_SERIES:
54 0 : ::chart::PropertyMapper::getValueMap( aValueMap, aLineSeriesNameMap, xProp );
55 0 : break;
56 : case ::chart::VLegendSymbolFactory::PROP_TYPE_LINE:
57 0 : ::chart::PropertyMapper::getValueMap( aValueMap, aLineNameMap, xProp );
58 0 : break;
59 : case ::chart::VLegendSymbolFactory::PROP_TYPE_FILL:
60 0 : ::chart::PropertyMapper::getValueMap( aValueMap, aFillNameMap, xProp );
61 0 : break;
62 : case ::chart::VLegendSymbolFactory::PROP_TYPE_FILL_AND_LINE:
63 0 : ::chart::PropertyMapper::getValueMap( aValueMap, aFillLineNameMap, xProp );
64 0 : break;
65 : }
66 :
67 0 : ::chart::PropertyMapper::getMultiPropertyListsFromValueMap( rNames, rValues, aValueMap );
68 :
69 0 : uno::Any* pLineWidthAny = ::chart::PropertyMapper::getValuePointer(rValues,rNames,"LineWidth");
70 0 : sal_Int32 nLineWidth = 0;
71 0 : if( pLineWidthAny && (*pLineWidthAny>>=nLineWidth) )
72 : {
73 : // use legend entry height as upper limit for line width
74 0 : sal_Int32 nMaxLineWidthForLegend = aMaxSymbolExtent.Height;
75 0 : if( nLineWidth>nMaxLineWidthForLegend )
76 0 : *pLineWidthAny = uno::makeAny( nMaxLineWidthForLegend );
77 0 : }
78 0 : }
79 :
80 0 : 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))
85 : {
86 0 : ::chart::tNameSequence aPropNames;
87 0 : ::chart::tAnySequence aPropValues;
88 : getPropNamesAndValues( xProp, aPropNames, aPropValues,
89 0 : ePropertyType, aMaxSymbolExtent );
90 :
91 0 : Reference< beans::XPropertySet > xShapeProp( xShape, uno::UNO_QUERY );
92 0 : ::chart::PropertyMapper::setMultiProperties( aPropNames, aPropValues, xShapeProp );
93 0 : }
94 :
95 : } // anonymous namespace
96 :
97 : namespace chart
98 : {
99 :
100 0 : Reference< drawing::XShape > VLegendSymbolFactory::createSymbol(
101 : const awt::Size& rEntryKeyAspectRatio,
102 : const Reference< drawing::XShapes > xSymbolContainer,
103 : LegendSymbolStyle eStyle,
104 : const Reference< lang::XMultiServiceFactory > & xShapeFactory,
105 : const Reference< beans::XPropertySet > & xLegendEntryProperties,
106 : tPropertyType ePropertyType, const uno::Any& rExplicitSymbol )
107 : {
108 0 : Reference< drawing::XShape > xResult;
109 :
110 0 : if( ! (xSymbolContainer.is() && xShapeFactory.is()))
111 0 : return xResult;
112 :
113 0 : AbstractShapeFactory* pShapeFactory = AbstractShapeFactory::getOrCreateShapeFactory(xShapeFactory);
114 0 : xResult.set( pShapeFactory->createGroup2D( xSymbolContainer ), uno::UNO_QUERY );
115 :
116 0 : Reference< drawing::XShapes > xResultGroup( xResult, uno::UNO_QUERY );
117 0 : if( ! xResultGroup.is())
118 0 : return xResult;
119 :
120 : // add an invisible square box to maintain aspect ratio
121 : Reference< drawing::XShape > xBound( pShapeFactory->createInvisibleRectangle(
122 0 : xResultGroup, rEntryKeyAspectRatio ));
123 :
124 : // create symbol
125 : try
126 : {
127 0 : if( eStyle == LegendSymbolStyle_LINE )
128 : {
129 : Reference< drawing::XShape > xLine =
130 : pShapeFactory->createLine( xResultGroup, awt::Size( rEntryKeyAspectRatio.Width, 0 ),
131 0 : awt::Point( 0, rEntryKeyAspectRatio.Height/2 ));
132 0 : if( xLine.is())
133 : {
134 0 : lcl_setPropetiesToShape( xLegendEntryProperties, xLine, ePropertyType, rEntryKeyAspectRatio );
135 : }
136 :
137 0 : Reference< drawing::XShape > xSymbol;
138 0 : const sal_Int32 nSize = std::min(rEntryKeyAspectRatio.Width,rEntryKeyAspectRatio.Height);
139 0 : chart2::Symbol aSymbol;
140 0 : if( rExplicitSymbol >>= aSymbol )
141 : {
142 0 : drawing::Direction3D aSymbolSize( nSize, nSize, 0 );
143 0 : drawing::Position3D aPos( rEntryKeyAspectRatio.Width/2, rEntryKeyAspectRatio.Height/2, 0 );
144 0 : AbstractShapeFactory* pFactory = AbstractShapeFactory::getOrCreateShapeFactory( xShapeFactory );
145 0 : if( aSymbol.Style == chart2::SymbolStyle_STANDARD )
146 : {
147 : // take series color as fill color
148 0 : xLegendEntryProperties->getPropertyValue( "Color") >>= aSymbol.FillColor;
149 : // border of symbols always same as fill color
150 0 : aSymbol.BorderColor = aSymbol.FillColor;
151 :
152 : xSymbol.set( pFactory->createSymbol2D(
153 : xResultGroup,
154 : aPos,
155 : aSymbolSize,
156 : aSymbol.StandardSymbol,
157 : aSymbol.BorderColor,
158 0 : aSymbol.FillColor ));
159 : }
160 0 : else if( aSymbol.Style == chart2::SymbolStyle_GRAPHIC )
161 : {
162 : xSymbol.set( pFactory->createGraphic2D(
163 : xResultGroup,
164 : aPos,
165 : aSymbolSize,
166 0 : aSymbol.Graphic ));
167 : }
168 0 : else if( aSymbol.Style == chart2::SymbolStyle_AUTO )
169 : {
170 : SAL_WARN("chart2", "the given parameter is not allowed to contain an automatic symbol style");
171 : }
172 0 : }
173 : }
174 0 : else if( eStyle == LegendSymbolStyle_CIRCLE )
175 : {
176 0 : sal_Int32 nSize = std::min( rEntryKeyAspectRatio.Width, rEntryKeyAspectRatio.Height );
177 : Reference< drawing::XShape > xShape =
178 : pShapeFactory->createCircle( xResultGroup, awt::Size( nSize, nSize ),
179 0 : awt::Point( rEntryKeyAspectRatio.Width/2-nSize/2, rEntryKeyAspectRatio.Height/2-nSize/2 ));
180 0 : if( xShape.is() )
181 : {
182 0 : lcl_setPropetiesToShape( xLegendEntryProperties, xShape, ePropertyType ); // PROP_TYPE_FILLED_SERIES );
183 0 : }
184 : }
185 : else // eStyle == LegendSymbolStyle_BOX
186 : {
187 0 : tNameSequence aPropNames;
188 0 : tAnySequence aPropValues;
189 :
190 : getPropNamesAndValues( xLegendEntryProperties, aPropNames, aPropValues,
191 0 : ePropertyType );// PROP_TYPE_FILLED_SERIES
192 :
193 : Reference< drawing::XShape > xShape =
194 : pShapeFactory->createRectangle( xResultGroup,
195 : rEntryKeyAspectRatio, awt::Point( 0, 0 ),
196 0 : aPropNames, aPropValues );
197 : }
198 : }
199 0 : catch( const uno::Exception & ex )
200 : {
201 : ASSERT_EXCEPTION( ex );
202 : }
203 :
204 0 : return xResult;
205 : }
206 :
207 : } // namespace chart
208 :
209 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|