merge the formfield patch from ooo-build
[ooovba.git] / chart2 / source / view / main / VLegendSymbolFactory.cxx
blob4d73785c95104dcc14ea35e95c551ad31d0a9849
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: VLegendSymbolFactory.cxx,v $
10 * $Revision: 1.9.44.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "VLegendSymbolFactory.hxx"
34 #include "macros.hxx"
35 #include "PropertyMapper.hxx"
36 #include "ShapeFactory.hxx"
37 #include "ObjectIdentifier.hxx"
38 #include <com/sun/star/drawing/LineStyle.hpp>
39 #include <com/sun/star/chart2/Symbol.hpp>
41 // header for define DBG_ASSERT
42 #include <tools/debug.hxx>
44 // uncomment to disable line dashes at the border of boxes
45 // #define DISABLE_DASHES_AT_BORDER
47 using namespace ::com::sun::star;
48 using ::com::sun::star::uno::Reference;
49 using ::com::sun::star::uno::Sequence;
50 using ::rtl::OUString;
52 namespace
54 void lcl_setPropetiesToShape(
55 const Reference< beans::XPropertySet > & xProp,
56 const Reference< drawing::XShape > & xShape,
57 ::chart::VLegendSymbolFactory::tPropertyType ePropertyType )
59 const ::chart::tPropertyNameMap & aFilledSeriesNameMap( ::chart::PropertyMapper::getPropertyNameMapForFilledSeriesProperties());
60 const ::chart::tPropertyNameMap & aLineSeriesNameMap( ::chart::PropertyMapper::getPropertyNameMapForLineSeriesProperties());
61 const ::chart::tPropertyNameMap & aLineNameMap( ::chart::PropertyMapper::getPropertyNameMapForLineProperties());
62 const ::chart::tPropertyNameMap & aFillNameMap( ::chart::PropertyMapper::getPropertyNameMapForFillProperties());
63 const ::chart::tPropertyNameMap & aFillLineNameMap( ::chart::PropertyMapper::getPropertyNameMapForFillAndLineProperties());
65 Reference< beans::XPropertySet > xShapeProp( xShape, uno::UNO_QUERY );
66 if( xProp.is() && xShapeProp.is() )
68 ::chart::tPropertyNameValueMap aValueMap;
69 switch( ePropertyType )
71 case ::chart::VLegendSymbolFactory::PROP_TYPE_FILLED_SERIES:
72 ::chart::PropertyMapper::getValueMap( aValueMap, aFilledSeriesNameMap, xProp );
73 break;
74 case ::chart::VLegendSymbolFactory::PROP_TYPE_LINE_SERIES:
75 ::chart::PropertyMapper::getValueMap( aValueMap, aLineSeriesNameMap, xProp );
76 break;
77 case ::chart::VLegendSymbolFactory::PROP_TYPE_LINE:
78 ::chart::PropertyMapper::getValueMap( aValueMap, aLineNameMap, xProp );
79 break;
80 case ::chart::VLegendSymbolFactory::PROP_TYPE_FILL:
81 ::chart::PropertyMapper::getValueMap( aValueMap, aFillNameMap, xProp );
82 break;
83 case ::chart::VLegendSymbolFactory::PROP_TYPE_FILL_AND_LINE:
84 ::chart::PropertyMapper::getValueMap( aValueMap, aFillLineNameMap, xProp );
85 break;
88 ::chart::tNameSequence aPropNames;
89 ::chart::tAnySequence aPropValues;
90 ::chart::PropertyMapper::getMultiPropertyListsFromValueMap( aPropNames, aPropValues, aValueMap );
91 ::chart::PropertyMapper::setMultiProperties( aPropNames, aPropValues, xShapeProp );
95 } // anonymous namespace
97 namespace chart
100 // static
101 Reference< drawing::XShape > VLegendSymbolFactory::createSymbol(
102 const Reference< drawing::XShapes > xSymbolContainer,
103 chart2::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( ! (xSymbolContainer.is() &&
111 xShapeFactory.is()))
112 return xResult;
114 xResult.set( xShapeFactory->createInstance(
115 C2U( "com.sun.star.drawing.GroupShape" )), uno::UNO_QUERY );
116 xSymbolContainer->add( xResult );
117 Reference< drawing::XShapes > xResultGroup( xResult, uno::UNO_QUERY );
118 if( ! xResultGroup.is())
119 return xResult;
121 // aspect ratio of symbols is always 3:2
122 awt::Size aBoundSize( 3000, 2000 );
123 bool bUseBox = false;
125 // add an invisible square box to maintain aspect ratio
126 switch( eStyle )
128 case chart2::LegendSymbolStyle_BOX:
129 case chart2::LegendSymbolStyle_HORIZONTAL_LINE:
130 case chart2::LegendSymbolStyle_VERTICAL_LINE:
131 case chart2::LegendSymbolStyle_DIAGONAL_LINE:
132 case chart2::LegendSymbolStyle_LINE_WITH_BOX:
133 case chart2::LegendSymbolStyle_LINE_WITH_SYMBOL:
134 case chart2::LegendSymbolStyle_CIRCLE:
136 Reference< drawing::XShape > xBound( ShapeFactory(xShapeFactory).createInvisibleRectangle(
137 xResultGroup, aBoundSize ));
138 break;
141 case chart2::LegendSymbolStyle_BAR:
142 case chart2::LegendSymbolStyle_RECTANGLE:
143 case chart2::LegendSymbolStyle_STRETCHED_RECTANGLE:
144 case chart2::LegendSymbolStyle_USER_DEFINED:
145 default:
146 break;
149 // create symbol
150 switch( eStyle )
152 case chart2::LegendSymbolStyle_BOX:
153 case chart2::LegendSymbolStyle_BAR:
154 case chart2::LegendSymbolStyle_RECTANGLE:
155 case chart2::LegendSymbolStyle_STRETCHED_RECTANGLE:
156 case chart2::LegendSymbolStyle_CIRCLE:
160 Reference< drawing::XShape > xShape;
162 if( eStyle == chart2::LegendSymbolStyle_CIRCLE )
163 xShape.set( xShapeFactory->createInstance(
164 C2U( "com.sun.star.drawing.EllipseShape" )), uno::UNO_QUERY );
165 else
166 xShape.set( xShapeFactory->createInstance(
167 C2U( "com.sun.star.drawing.RectangleShape" )), uno::UNO_QUERY );
169 if( xShape.is())
171 xResultGroup->add( xShape );
172 if( eStyle == chart2::LegendSymbolStyle_BOX ||
173 eStyle == chart2::LegendSymbolStyle_CIRCLE )
175 xShape->setSize( awt::Size( 2000, 2000 ));
176 xShape->setPosition( awt::Point( 500, 0 ));
178 else
180 xShape->setSize( aBoundSize );
184 lcl_setPropetiesToShape( xLegendEntryProperties, xShape, ePropertyType ); // PROP_TYPE_FILLED_SERIES );
186 #ifdef DISABLE_DASHES_AT_BORDER
187 // don't allow dashed border style
188 Reference< beans::XPropertySet > xShapeProp( xShape, uno::UNO_QUERY );
189 if( xShapeProp.is())
191 drawing::LineStyle aLineStyle;
192 if( ( xShapeProp->getPropertyValue( C2U("LineStyle")) >>= aLineStyle ) &&
193 aLineStyle == drawing::LineStyle_DASH )
195 aLineStyle = drawing::LineStyle_SOLID;
196 xShapeProp->setPropertyValue( C2U("LineStyle"), uno::makeAny( aLineStyle ));
199 #endif
201 catch( uno::Exception & ex )
203 ASSERT_EXCEPTION( ex );
205 break;
208 case chart2::LegendSymbolStyle_HORIZONTAL_LINE:
212 Reference< drawing::XShape > xLine(
213 xShapeFactory->createInstance(
214 C2U( "com.sun.star.drawing.LineShape" )), uno::UNO_QUERY );
215 if( xLine.is())
217 xResultGroup->add( xLine );
218 xLine->setSize( awt::Size( 3000, 0 ));
219 xLine->setPosition( awt::Point( 0, 1000 ));
221 lcl_setPropetiesToShape( xLegendEntryProperties, xLine, ePropertyType ); // PROP_TYPE_LINE_SERIES );
224 catch( uno::Exception & ex )
226 ASSERT_EXCEPTION( ex );
228 break;
231 case chart2::LegendSymbolStyle_VERTICAL_LINE:
235 Reference< drawing::XShape > xLine(
236 xShapeFactory->createInstance(
237 C2U( "com.sun.star.drawing.LineShape" )), uno::UNO_QUERY );
238 if( xLine.is())
240 xResultGroup->add( xLine );
241 xLine->setSize( awt::Size( 0, 2000 ));
242 xLine->setPosition( awt::Point( 1500, 0 ));
244 lcl_setPropetiesToShape( xLegendEntryProperties, xLine, ePropertyType ); // PROP_TYPE_LINE_SERIES );
247 catch( uno::Exception & ex )
249 ASSERT_EXCEPTION( ex );
251 break;
254 case chart2::LegendSymbolStyle_DIAGONAL_LINE:
258 Reference< drawing::XShape > xLine(
259 xShapeFactory->createInstance(
260 C2U( "com.sun.star.drawing.LineShape" )), uno::UNO_QUERY );
261 if( xLine.is())
263 xResultGroup->add( xLine );
264 xLine->setSize( awt::Size( 2000, 2000 ));
265 xLine->setPosition( awt::Point( 500, 0 ));
267 lcl_setPropetiesToShape( xLegendEntryProperties, xLine, ePropertyType ); // PROP_TYPE_LINE_SERIES );
270 catch( uno::Exception & ex )
272 ASSERT_EXCEPTION( ex );
274 break;
277 case chart2::LegendSymbolStyle_LINE_WITH_BOX:
278 bUseBox = true;
279 // fall-through intended
280 case chart2::LegendSymbolStyle_LINE_WITH_SYMBOL:
283 Reference< drawing::XShape > xLine(
284 xShapeFactory->createInstance(
285 C2U( "com.sun.star.drawing.LineShape" )), uno::UNO_QUERY );
286 if( xLine.is())
288 xResultGroup->add( xLine );
289 xLine->setSize( awt::Size( 3000, 0 ));
290 xLine->setPosition( awt::Point( 0, 1000 ));
292 lcl_setPropetiesToShape( xLegendEntryProperties, xLine, ePropertyType );
295 Reference< drawing::XShape > xSymbol;
296 const sal_Int32 nSize = 1500;
297 if( bUseBox )
299 xSymbol.set( xShapeFactory->createInstance(
300 C2U( "com.sun.star.drawing.RectangleShape" )), uno::UNO_QUERY );
301 xResultGroup->add( xSymbol );
303 if( xSymbol.is())
305 xSymbol->setSize( awt::Size( nSize, nSize ));
306 xSymbol->setPosition( awt::Point( 1500 - nSize/2, 1000 - nSize/2 ));
308 lcl_setPropetiesToShape( xLegendEntryProperties, xSymbol, ePropertyType );
311 else
313 chart2::Symbol aSymbol;
315 if( rExplicitSymbol >>= aSymbol )
317 drawing::Direction3D aSymbolSize( nSize, nSize, 0 );
318 drawing::Position3D aPos( 1500, 1000, 0 );
319 ShapeFactory aFactory( xShapeFactory );
320 if( aSymbol.Style == chart2::SymbolStyle_STANDARD )
322 // border of symbols always black
323 aSymbol.BorderColor = 0x000000;
324 // take series color as fill color
325 xLegendEntryProperties->getPropertyValue( C2U("Color")) >>= aSymbol.FillColor;
327 xSymbol.set( aFactory.createSymbol2D(
328 xResultGroup,
329 aPos,
330 aSymbolSize,
331 aSymbol.StandardSymbol,
332 aSymbol.BorderColor,
333 aSymbol.FillColor ));
335 else if( aSymbol.Style == chart2::SymbolStyle_GRAPHIC )
337 xSymbol.set( aFactory.createGraphic2D(
338 xResultGroup,
339 aPos,
340 aSymbolSize,
341 aSymbol.Graphic ));
343 else if( aSymbol.Style == chart2::SymbolStyle_AUTO )
345 DBG_ERROR("the given parameter is not allowed to contain an automatic symbol style");
350 catch( uno::Exception & ex )
352 ASSERT_EXCEPTION( ex );
354 break;
356 case chart2::LegendSymbolStyle_USER_DEFINED:
357 break;
359 default:
360 // just to remove warning (there is an auto-generated extra label)
361 break;
364 return xResult;
367 } // namespace chart