1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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"
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
;
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
);
74 case ::chart::VLegendSymbolFactory::PROP_TYPE_LINE_SERIES
:
75 ::chart::PropertyMapper::getValueMap( aValueMap
, aLineSeriesNameMap
, xProp
);
77 case ::chart::VLegendSymbolFactory::PROP_TYPE_LINE
:
78 ::chart::PropertyMapper::getValueMap( aValueMap
, aLineNameMap
, xProp
);
80 case ::chart::VLegendSymbolFactory::PROP_TYPE_FILL
:
81 ::chart::PropertyMapper::getValueMap( aValueMap
, aFillNameMap
, xProp
);
83 case ::chart::VLegendSymbolFactory::PROP_TYPE_FILL_AND_LINE
:
84 ::chart::PropertyMapper::getValueMap( aValueMap
, aFillLineNameMap
, xProp
);
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
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() &&
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())
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
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
));
141 case chart2::LegendSymbolStyle_BAR
:
142 case chart2::LegendSymbolStyle_RECTANGLE
:
143 case chart2::LegendSymbolStyle_STRETCHED_RECTANGLE
:
144 case chart2::LegendSymbolStyle_USER_DEFINED
:
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
);
166 xShape
.set( xShapeFactory
->createInstance(
167 C2U( "com.sun.star.drawing.RectangleShape" )), uno::UNO_QUERY
);
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 ));
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
);
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
));
201 catch( uno::Exception
& ex
)
203 ASSERT_EXCEPTION( ex
);
208 case chart2::LegendSymbolStyle_HORIZONTAL_LINE
:
212 Reference
< drawing::XShape
> xLine(
213 xShapeFactory
->createInstance(
214 C2U( "com.sun.star.drawing.LineShape" )), uno::UNO_QUERY
);
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
);
231 case chart2::LegendSymbolStyle_VERTICAL_LINE
:
235 Reference
< drawing::XShape
> xLine(
236 xShapeFactory
->createInstance(
237 C2U( "com.sun.star.drawing.LineShape" )), uno::UNO_QUERY
);
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
);
254 case chart2::LegendSymbolStyle_DIAGONAL_LINE
:
258 Reference
< drawing::XShape
> xLine(
259 xShapeFactory
->createInstance(
260 C2U( "com.sun.star.drawing.LineShape" )), uno::UNO_QUERY
);
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
);
277 case chart2::LegendSymbolStyle_LINE_WITH_BOX
:
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
);
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;
299 xSymbol
.set( xShapeFactory
->createInstance(
300 C2U( "com.sun.star.drawing.RectangleShape" )), uno::UNO_QUERY
);
301 xResultGroup
->add( xSymbol
);
305 xSymbol
->setSize( awt::Size( nSize
, nSize
));
306 xSymbol
->setPosition( awt::Point( 1500 - nSize
/2, 1000 - nSize
/2 ));
308 lcl_setPropetiesToShape( xLegendEntryProperties
, xSymbol
, ePropertyType
);
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(
331 aSymbol
.StandardSymbol
,
333 aSymbol
.FillColor
));
335 else if( aSymbol
.Style
== chart2::SymbolStyle_GRAPHIC
)
337 xSymbol
.set( aFactory
.createGraphic2D(
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
);
356 case chart2::LegendSymbolStyle_USER_DEFINED
:
360 // just to remove warning (there is an auto-generated extra label)