merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / model / template / BarChartTypeTemplate.cxx
blob01dc4c253d2b7acbfb5ee2a9da1874372e605185
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 #include "BarChartTypeTemplate.hxx"
31 #include "macros.hxx"
32 #include "DiagramHelper.hxx"
33 #include "servicenames_charttypes.hxx"
34 #include "ContainerHelper.hxx"
35 #include "DataSeriesHelper.hxx"
36 #include "PropertyHelper.hxx"
37 #include <com/sun/star/beans/PropertyAttribute.hpp>
38 #include <com/sun/star/drawing/LineStyle.hpp>
39 #include <com/sun/star/chart2/DataPointGeometry3D.hpp>
41 #include <algorithm>
43 using namespace ::com::sun::star;
45 using ::com::sun::star::uno::Reference;
46 using ::com::sun::star::uno::Sequence;
47 using ::com::sun::star::beans::Property;
48 using ::osl::MutexGuard;
49 using ::rtl::OUString;
51 namespace
54 static const OUString lcl_aServiceName(
55 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.BarChartTypeTemplate" ));
57 enum
59 PROP_BAR_TEMPLATE_DIMENSION,
60 PROP_BAR_TEMPLATE_GEOMETRY3D
63 void lcl_AddPropertiesToVector(
64 ::std::vector< Property > & rOutProperties )
66 rOutProperties.push_back(
67 Property( C2U( "Dimension" ),
68 PROP_BAR_TEMPLATE_DIMENSION,
69 ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
70 beans::PropertyAttribute::BOUND
71 | beans::PropertyAttribute::MAYBEDEFAULT ));
72 rOutProperties.push_back(
73 Property( C2U( "Geometry3D" ),
74 PROP_BAR_TEMPLATE_GEOMETRY3D,
75 ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
76 beans::PropertyAttribute::BOUND
77 | beans::PropertyAttribute::MAYBEDEFAULT ));
80 void lcl_AddDefaultsToMap(
81 ::chart::tPropertyValueMap & rOutMap )
83 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_BAR_TEMPLATE_DIMENSION, 2 );
84 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_BAR_TEMPLATE_GEOMETRY3D, ::chart2::DataPointGeometry3D::CUBOID );
87 const Sequence< Property > & lcl_GetPropertySequence()
89 static Sequence< Property > aPropSeq;
91 // /--
92 MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
93 if( 0 == aPropSeq.getLength() )
95 // get properties
96 ::std::vector< ::com::sun::star::beans::Property > aProperties;
97 lcl_AddPropertiesToVector( aProperties );
99 // and sort them for access via bsearch
100 ::std::sort( aProperties.begin(), aProperties.end(),
101 ::chart::PropertyNameLess() );
103 // transfer result to static Sequence
104 aPropSeq = ::chart::ContainerHelper::ContainerToSequence( aProperties );
107 return aPropSeq;
110 ::cppu::IPropertyArrayHelper & lcl_getInfoHelper()
112 static ::cppu::OPropertyArrayHelper aArrayHelper(
113 lcl_GetPropertySequence(),
114 /* bSorted = */ sal_True );
116 return aArrayHelper;
119 } // anonymous namespace
121 namespace chart
124 BarChartTypeTemplate::BarChartTypeTemplate(
125 Reference<
126 uno::XComponentContext > const & xContext,
127 const OUString & rServiceName,
128 StackMode eStackMode,
129 BarDirection eDirection,
130 sal_Int32 nDim /* = 2 */ ) :
131 ChartTypeTemplate( xContext, rServiceName ),
132 ::property::OPropertySet( m_aMutex ),
133 m_eStackMode( eStackMode ),
134 m_eBarDirection( eDirection ),
135 m_nDim( nDim )
138 BarChartTypeTemplate::~BarChartTypeTemplate()
141 sal_Int32 BarChartTypeTemplate::getDimension() const
143 return m_nDim;
146 StackMode BarChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
148 return m_eStackMode;
151 bool BarChartTypeTemplate::isSwapXAndY() const
153 return (m_eBarDirection == HORIZONTAL);
156 // ____ XChartTypeTemplate ____
157 sal_Bool SAL_CALL BarChartTypeTemplate::matchesTemplate(
158 const Reference< chart2::XDiagram >& xDiagram,
159 sal_Bool bAdaptProperties )
160 throw (uno::RuntimeException)
162 sal_Bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties );
164 //check BarDirection
165 if( bResult )
167 bool bFound = false;
168 bool bAmbiguous = false;
169 bool bVertical = DiagramHelper::getVertical( xDiagram, bFound, bAmbiguous );
170 if( m_eBarDirection == HORIZONTAL )
171 bResult = sal_Bool( bVertical );
172 else if( m_eBarDirection == VERTICAL )
173 bResult = sal_Bool( !bVertical );
176 // adapt solid-type of template according to values in series
177 if( bAdaptProperties &&
178 bResult &&
179 getDimension() == 3 )
181 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
182 DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
184 bool bGeomFound = false, bGeomAmbiguous = false;
185 sal_Int32 aCommonGeom = DiagramHelper::getGeometry3D( xDiagram, bGeomFound, bGeomAmbiguous );
187 if( !bGeomAmbiguous )
189 setFastPropertyValue_NoBroadcast(
190 PROP_BAR_TEMPLATE_GEOMETRY3D, uno::makeAny( aCommonGeom ));
194 return bResult;
196 Reference< chart2::XChartType > BarChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
198 Reference< chart2::XChartType > xResult;
202 Reference< lang::XMultiServiceFactory > xFact(
203 GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
204 xResult.set( xFact->createInstance(
205 CHART2_SERVICE_NAME_CHARTTYPE_COLUMN ), uno::UNO_QUERY_THROW );
207 catch( uno::Exception & ex )
209 ASSERT_EXCEPTION( ex );
212 return xResult;
215 Reference< chart2::XChartType > SAL_CALL BarChartTypeTemplate::getChartTypeForNewSeries(
216 const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
217 throw (uno::RuntimeException)
219 Reference< chart2::XChartType > xResult( getChartTypeForIndex( 0 ) );
220 ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult );
221 return xResult;
225 // ____ OPropertySet ____
226 uno::Any BarChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle ) const
227 throw(beans::UnknownPropertyException)
229 static tPropertyValueMap aStaticDefaults;
231 // /--
232 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
233 if( 0 == aStaticDefaults.size() )
235 // initialize defaults
236 lcl_AddDefaultsToMap( aStaticDefaults );
239 tPropertyValueMap::const_iterator aFound(
240 aStaticDefaults.find( nHandle ));
242 if( aFound == aStaticDefaults.end())
243 return uno::Any();
245 return (*aFound).second;
246 // \--
249 ::cppu::IPropertyArrayHelper & SAL_CALL BarChartTypeTemplate::getInfoHelper()
251 return lcl_getInfoHelper();
255 // ____ XPropertySet ____
256 Reference< beans::XPropertySetInfo > SAL_CALL
257 BarChartTypeTemplate::getPropertySetInfo()
258 throw (uno::RuntimeException)
260 static Reference< beans::XPropertySetInfo > xInfo;
262 // /--
263 MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
264 if( !xInfo.is())
266 xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo(
267 getInfoHelper());
270 return xInfo;
271 // \--
274 void SAL_CALL BarChartTypeTemplate::applyStyle(
275 const Reference< chart2::XDataSeries >& xSeries,
276 ::sal_Int32 nChartTypeIndex,
277 ::sal_Int32 nSeriesIndex,
278 ::sal_Int32 nSeriesCount )
279 throw (uno::RuntimeException)
281 ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
282 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "BorderStyle" ), uno::makeAny( drawing::LineStyle_NONE ) );
283 if( getDimension() == 3 )
287 //apply Geometry3D
288 uno::Any aAGeometry3D;
289 this->getFastPropertyValue( aAGeometry3D, PROP_BAR_TEMPLATE_GEOMETRY3D );
290 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "Geometry3D" ), aAGeometry3D );
292 catch( uno::Exception & ex )
294 ASSERT_EXCEPTION( ex );
299 void SAL_CALL BarChartTypeTemplate::resetStyles(
300 const Reference< chart2::XDiagram >& xDiagram )
301 throw (uno::RuntimeException)
303 ChartTypeTemplate::resetStyles( xDiagram );
304 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
305 DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
306 uno::Any aLineStyleAny( uno::makeAny( drawing::LineStyle_NONE ));
307 for( ::std::vector< Reference< chart2::XDataSeries > >::iterator aIt( aSeriesVec.begin());
308 aIt != aSeriesVec.end(); ++aIt )
310 Reference< beans::XPropertyState > xState( *aIt, uno::UNO_QUERY );
311 if( xState.is())
313 if( getDimension() == 3 )
314 xState->setPropertyToDefault( C2U("Geometry3D"));
315 Reference< beans::XPropertySet > xProp( xState, uno::UNO_QUERY );
316 if( xProp.is() &&
317 xProp->getPropertyValue( C2U("BorderStyle")) == aLineStyleAny )
319 xState->setPropertyToDefault( C2U("BorderStyle"));
324 DiagramHelper::setVertical( xDiagram, false );
328 void BarChartTypeTemplate::createCoordinateSystems(
329 const Reference< chart2::XCoordinateSystemContainer > & xCooSysCnt )
331 ChartTypeTemplate::createCoordinateSystems( xCooSysCnt );
333 Reference< chart2::XDiagram > xDiagram( xCooSysCnt, uno::UNO_QUERY );
334 DiagramHelper::setVertical( xDiagram, m_eBarDirection == HORIZONTAL );
337 // ----------------------------------------
339 Sequence< OUString > BarChartTypeTemplate::getSupportedServiceNames_Static()
341 Sequence< OUString > aServices( 2 );
342 aServices[ 0 ] = lcl_aServiceName;
343 aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" );
344 return aServices;
347 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
348 APPHELPER_XSERVICEINFO_IMPL( BarChartTypeTemplate, lcl_aServiceName );
350 IMPLEMENT_FORWARD_XINTERFACE2( BarChartTypeTemplate, ChartTypeTemplate, OPropertySet )
351 IMPLEMENT_FORWARD_XTYPEPROVIDER2( BarChartTypeTemplate, ChartTypeTemplate, OPropertySet )
353 } // namespace chart