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