fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / model / template / BarChartTypeTemplate.cxx
blob971f666a6a5c435c5c72e16a221cd606b271c89b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "BarChartTypeTemplate.hxx"
21 #include "macros.hxx"
22 #include "DiagramHelper.hxx"
23 #include "servicenames_charttypes.hxx"
24 #include "ContainerHelper.hxx"
25 #include "DataSeriesHelper.hxx"
26 #include "PropertyHelper.hxx"
27 #include <com/sun/star/beans/PropertyAttribute.hpp>
28 #include <com/sun/star/drawing/LineStyle.hpp>
29 #include <com/sun/star/chart2/DataPointGeometry3D.hpp>
31 #include <algorithm>
33 using namespace ::com::sun::star;
35 using ::com::sun::star::uno::Reference;
36 using ::com::sun::star::uno::Sequence;
37 using ::com::sun::star::beans::Property;
38 using ::osl::MutexGuard;
40 namespace
43 enum
45 PROP_BAR_TEMPLATE_DIMENSION,
46 PROP_BAR_TEMPLATE_GEOMETRY3D
49 void lcl_AddPropertiesToVector(
50 ::std::vector< Property > & rOutProperties )
52 rOutProperties.push_back(
53 Property( "Dimension",
54 PROP_BAR_TEMPLATE_DIMENSION,
55 cppu::UnoType<sal_Int32>::get(),
56 beans::PropertyAttribute::BOUND
57 | beans::PropertyAttribute::MAYBEDEFAULT ));
58 rOutProperties.push_back(
59 Property( "Geometry3D",
60 PROP_BAR_TEMPLATE_GEOMETRY3D,
61 cppu::UnoType<sal_Int32>::get(),
62 beans::PropertyAttribute::BOUND
63 | beans::PropertyAttribute::MAYBEDEFAULT ));
66 struct StaticBarChartTypeTemplateDefaults_Initializer
68 ::chart::tPropertyValueMap* operator()()
70 static ::chart::tPropertyValueMap aStaticDefaults;
71 lcl_AddDefaultsToMap( aStaticDefaults );
72 return &aStaticDefaults;
74 private:
75 static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
77 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_BAR_TEMPLATE_DIMENSION, 2 );
78 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_BAR_TEMPLATE_GEOMETRY3D, ::chart2::DataPointGeometry3D::CUBOID );
82 struct StaticBarChartTypeTemplateDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticBarChartTypeTemplateDefaults_Initializer >
86 struct StaticBarChartTypeTemplateInfoHelper_Initializer
88 ::cppu::OPropertyArrayHelper* operator()()
90 static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
91 return &aPropHelper;
94 private:
95 static Sequence< Property > lcl_GetPropertySequence()
97 ::std::vector< ::com::sun::star::beans::Property > aProperties;
98 lcl_AddPropertiesToVector( aProperties );
100 ::std::sort( aProperties.begin(), aProperties.end(),
101 ::chart::PropertyNameLess() );
103 return ::chart::ContainerHelper::ContainerToSequence( aProperties );
108 struct StaticBarChartTypeTemplateInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticBarChartTypeTemplateInfoHelper_Initializer >
112 struct StaticBarChartTypeTemplateInfo_Initializer
114 uno::Reference< beans::XPropertySetInfo >* operator()()
116 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
117 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticBarChartTypeTemplateInfoHelper::get() ) );
118 return &xPropertySetInfo;
122 struct StaticBarChartTypeTemplateInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticBarChartTypeTemplateInfo_Initializer >
126 } // anonymous namespace
128 namespace chart
131 BarChartTypeTemplate::BarChartTypeTemplate(
132 Reference<
133 uno::XComponentContext > const & xContext,
134 const OUString & rServiceName,
135 StackMode eStackMode,
136 BarDirection eDirection,
137 sal_Int32 nDim /* = 2 */ ) :
138 ChartTypeTemplate( xContext, rServiceName ),
139 ::property::OPropertySet( m_aMutex ),
140 m_eStackMode( eStackMode ),
141 m_eBarDirection( eDirection ),
142 m_nDim( nDim )
145 BarChartTypeTemplate::~BarChartTypeTemplate()
148 sal_Int32 BarChartTypeTemplate::getDimension() const
150 return m_nDim;
153 StackMode BarChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
155 return m_eStackMode;
158 bool BarChartTypeTemplate::isSwapXAndY() const
160 return (m_eBarDirection == HORIZONTAL);
163 // ____ XChartTypeTemplate ____
164 sal_Bool SAL_CALL BarChartTypeTemplate::matchesTemplate(
165 const Reference< chart2::XDiagram >& xDiagram,
166 sal_Bool bAdaptProperties )
167 throw (uno::RuntimeException, std::exception)
169 bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties );
171 //check BarDirection
172 if( bResult )
174 bool bFound = false;
175 bool bAmbiguous = false;
176 bool bVertical = DiagramHelper::getVertical( xDiagram, bFound, bAmbiguous );
177 if( m_eBarDirection == HORIZONTAL )
178 bResult = bVertical;
179 else if( m_eBarDirection == VERTICAL )
180 bResult = !bVertical;
183 // adapt solid-type of template according to values in series
184 if( bAdaptProperties &&
185 bResult &&
186 getDimension() == 3 )
189 bool bGeomFound = false, bGeomAmbiguous = false;
190 sal_Int32 aCommonGeom = DiagramHelper::getGeometry3D( xDiagram, bGeomFound, bGeomAmbiguous );
192 if( !bGeomAmbiguous )
194 setFastPropertyValue_NoBroadcast(
195 PROP_BAR_TEMPLATE_GEOMETRY3D, uno::makeAny( aCommonGeom ));
199 return bResult;
201 Reference< chart2::XChartType > BarChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
203 Reference< chart2::XChartType > xResult;
207 Reference< lang::XMultiServiceFactory > xFact(
208 GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
209 xResult.set( xFact->createInstance(
210 CHART2_SERVICE_NAME_CHARTTYPE_COLUMN ), uno::UNO_QUERY_THROW );
212 catch( const uno::Exception & ex )
214 ASSERT_EXCEPTION( ex );
217 return xResult;
220 Reference< chart2::XChartType > SAL_CALL BarChartTypeTemplate::getChartTypeForNewSeries(
221 const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
222 throw (uno::RuntimeException, std::exception)
224 Reference< chart2::XChartType > xResult( getChartTypeForIndex( 0 ) );
225 ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult );
226 return xResult;
229 // ____ OPropertySet ____
230 uno::Any BarChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle ) const
231 throw(beans::UnknownPropertyException)
233 const tPropertyValueMap& rStaticDefaults = *StaticBarChartTypeTemplateDefaults::get();
234 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
235 if( aFound == rStaticDefaults.end() )
236 return uno::Any();
237 return (*aFound).second;
240 ::cppu::IPropertyArrayHelper & SAL_CALL BarChartTypeTemplate::getInfoHelper()
242 return *StaticBarChartTypeTemplateInfoHelper::get();
245 // ____ XPropertySet ____
246 Reference< beans::XPropertySetInfo > SAL_CALL BarChartTypeTemplate::getPropertySetInfo()
247 throw (uno::RuntimeException, std::exception)
249 return *StaticBarChartTypeTemplateInfo::get();
252 void SAL_CALL BarChartTypeTemplate::applyStyle(
253 const Reference< chart2::XDataSeries >& xSeries,
254 ::sal_Int32 nChartTypeIndex,
255 ::sal_Int32 nSeriesIndex,
256 ::sal_Int32 nSeriesCount )
257 throw (uno::RuntimeException, std::exception)
259 ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
260 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, "BorderStyle", uno::makeAny( drawing::LineStyle_NONE ) );
261 if( getDimension() == 3 )
265 //apply Geometry3D
266 uno::Any aAGeometry3D;
267 this->getFastPropertyValue( aAGeometry3D, PROP_BAR_TEMPLATE_GEOMETRY3D );
268 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, "Geometry3D", aAGeometry3D );
270 catch( const uno::Exception & ex )
272 ASSERT_EXCEPTION( ex );
277 void SAL_CALL BarChartTypeTemplate::resetStyles(
278 const Reference< chart2::XDiagram >& xDiagram )
279 throw (uno::RuntimeException, std::exception)
281 ChartTypeTemplate::resetStyles( xDiagram );
282 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
283 DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
284 uno::Any aLineStyleAny( uno::makeAny( drawing::LineStyle_NONE ));
285 for( ::std::vector< Reference< chart2::XDataSeries > >::iterator aIt( aSeriesVec.begin());
286 aIt != aSeriesVec.end(); ++aIt )
288 Reference< beans::XPropertyState > xState( *aIt, uno::UNO_QUERY );
289 if( xState.is())
291 if( getDimension() == 3 )
292 xState->setPropertyToDefault( "Geometry3D");
293 Reference< beans::XPropertySet > xProp( xState, uno::UNO_QUERY );
294 if( xProp.is() &&
295 xProp->getPropertyValue( "BorderStyle") == aLineStyleAny )
297 xState->setPropertyToDefault( "BorderStyle");
302 DiagramHelper::setVertical( xDiagram, false );
305 void BarChartTypeTemplate::createCoordinateSystems(
306 const Reference< chart2::XCoordinateSystemContainer > & xCooSysCnt )
308 ChartTypeTemplate::createCoordinateSystems( xCooSysCnt );
310 Reference< chart2::XDiagram > xDiagram( xCooSysCnt, uno::UNO_QUERY );
311 DiagramHelper::setVertical( xDiagram, m_eBarDirection == HORIZONTAL );
314 IMPLEMENT_FORWARD_XINTERFACE2( BarChartTypeTemplate, ChartTypeTemplate, OPropertySet )
315 IMPLEMENT_FORWARD_XTYPEPROVIDER2( BarChartTypeTemplate, ChartTypeTemplate, OPropertySet )
317 } // namespace chart
319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */