fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / model / template / PieChartType.cxx
blob2a6ebf659e0abc3f8ed75488137ae3715d0d0028
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 "PieChartType.hxx"
21 #include "PropertyHelper.hxx"
22 #include "macros.hxx"
23 #include "PolarCoordinateSystem.hxx"
24 #include "AxisHelper.hxx"
25 #include "servicenames_charttypes.hxx"
26 #include "ContainerHelper.hxx"
27 #include "AxisIndexDefines.hxx"
28 #include <cppuhelper/supportsservice.hxx>
29 #include <com/sun/star/beans/PropertyAttribute.hpp>
30 #include <com/sun/star/chart2/AxisType.hpp>
32 using namespace ::com::sun::star;
34 using ::com::sun::star::beans::Property;
35 using ::com::sun::star::uno::Sequence;
36 using ::com::sun::star::uno::Reference;
37 using ::com::sun::star::uno::Any;
38 using ::osl::MutexGuard;
40 namespace
43 enum
45 PROP_PIECHARTTYPE_USE_RINGS,
46 PROP_PIECHARTTYPE_3DRELATIVEHEIGHT
49 static void lcl_AddPropertiesToVector(
50 ::std::vector< Property > & rOutProperties )
52 rOutProperties.push_back(
53 Property( "UseRings",
54 PROP_PIECHARTTYPE_USE_RINGS,
55 cppu::UnoType<bool>::get(),
56 beans::PropertyAttribute::BOUND
57 | beans::PropertyAttribute::MAYBEDEFAULT ));
58 rOutProperties.push_back(
59 Property( "3DRelativeHeight",
60 PROP_PIECHARTTYPE_3DRELATIVEHEIGHT,
61 cppu::UnoType<sal_Int32>::get(),
62 beans::PropertyAttribute::MAYBEVOID ));
65 struct StaticPieChartTypeDefaults_Initializer
67 ::chart::tPropertyValueMap* operator()()
69 static ::chart::tPropertyValueMap aStaticDefaults;
70 lcl_AddDefaultsToMap( aStaticDefaults );
71 return &aStaticDefaults;
73 private:
74 static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
76 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_PIECHARTTYPE_USE_RINGS, false );
77 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_PIECHARTTYPE_3DRELATIVEHEIGHT, 100 );
81 struct StaticPieChartTypeDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticPieChartTypeDefaults_Initializer >
85 struct StaticPieChartTypeInfoHelper_Initializer
87 ::cppu::OPropertyArrayHelper* operator()()
89 static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
90 return &aPropHelper;
93 private:
94 static Sequence< Property > lcl_GetPropertySequence()
96 ::std::vector< ::com::sun::star::beans::Property > aProperties;
97 lcl_AddPropertiesToVector( aProperties );
99 ::std::sort( aProperties.begin(), aProperties.end(),
100 ::chart::PropertyNameLess() );
102 return ::chart::ContainerHelper::ContainerToSequence( aProperties );
107 struct StaticPieChartTypeInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticPieChartTypeInfoHelper_Initializer >
111 struct StaticPieChartTypeInfo_Initializer
113 uno::Reference< beans::XPropertySetInfo >* operator()()
115 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
116 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticPieChartTypeInfoHelper::get() ) );
117 return &xPropertySetInfo;
121 struct StaticPieChartTypeInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticPieChartTypeInfo_Initializer >
125 } // anonymous namespace
127 namespace chart
130 PieChartType::PieChartType(
131 const uno::Reference< uno::XComponentContext > & xContext,
132 bool bUseRings /* = sal_False */) :
133 ChartType( xContext )
135 if( bUseRings )
136 setFastPropertyValue_NoBroadcast( PROP_PIECHARTTYPE_USE_RINGS, uno::makeAny( bUseRings ));
139 PieChartType::PieChartType( const PieChartType & rOther ) :
140 ChartType( rOther )
144 PieChartType::~PieChartType()
147 // ____ XCloneable ____
148 uno::Reference< util::XCloneable > SAL_CALL PieChartType::createClone()
149 throw (uno::RuntimeException, std::exception)
151 return uno::Reference< util::XCloneable >( new PieChartType( *this ));
154 // ____ XChartType ____
155 OUString SAL_CALL PieChartType::getChartType()
156 throw (uno::RuntimeException, std::exception)
158 return OUString(CHART2_SERVICE_NAME_CHARTTYPE_PIE);
161 Reference< chart2::XCoordinateSystem > SAL_CALL
162 PieChartType::createCoordinateSystem( ::sal_Int32 DimensionCount )
163 throw (lang::IllegalArgumentException,
164 uno::RuntimeException, std::exception)
166 Reference< chart2::XCoordinateSystem > xResult(
167 new PolarCoordinateSystem(
168 GetComponentContext(), DimensionCount, /* bSwapXAndYAxis */ false ));
170 for( sal_Int32 i=0; i<DimensionCount; ++i )
172 Reference< chart2::XAxis > xAxis( xResult->getAxisByDimension( i, MAIN_AXIS_INDEX ) );
173 if( !xAxis.is() )
175 OSL_FAIL("a created coordinate system should have an axis for each dimension");
176 continue;
179 //hhhh todo make axis invisible
181 chart2::ScaleData aScaleData = xAxis->getScaleData();
182 aScaleData.Scaling = AxisHelper::createLinearScaling();
183 aScaleData.AxisType = chart2::AxisType::REALNUMBER;
185 if( i == 0 )
186 aScaleData.Orientation = chart2::AxisOrientation_REVERSE;
187 else
188 aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
190 //remove explicit scalings from all axes
191 AxisHelper::removeExplicitScaling( aScaleData );
193 xAxis->setScaleData( aScaleData );
196 return xResult;
199 uno::Sequence< OUString > PieChartType::getSupportedPropertyRoles()
200 throw (uno::RuntimeException, std::exception)
202 uno::Sequence< OUString > aPropRoles(2);
203 aPropRoles[0] = "FillColor";
204 aPropRoles[1] = "BorderColor";
206 return aPropRoles;
209 // ____ OPropertySet ____
210 uno::Any PieChartType::GetDefaultValue( sal_Int32 nHandle ) const
211 throw(beans::UnknownPropertyException)
213 const tPropertyValueMap& rStaticDefaults = *StaticPieChartTypeDefaults::get();
214 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
215 if( aFound == rStaticDefaults.end() )
216 return uno::Any();
217 return (*aFound).second;
220 // ____ OPropertySet ____
221 ::cppu::IPropertyArrayHelper & SAL_CALL PieChartType::getInfoHelper()
223 return *StaticPieChartTypeInfoHelper::get();
226 // ____ XPropertySet ____
227 uno::Reference< beans::XPropertySetInfo > SAL_CALL PieChartType::getPropertySetInfo()
228 throw (uno::RuntimeException, std::exception)
230 return *StaticPieChartTypeInfo::get();
233 uno::Sequence< OUString > PieChartType::getSupportedServiceNames_Static()
235 uno::Sequence< OUString > aServices( 3 );
236 aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_PIE;
237 aServices[ 1 ] = "com.sun.star.chart2.ChartType";
238 aServices[ 2 ] = "com.sun.star.beans.PropertySet";
239 return aServices;
242 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
243 OUString SAL_CALL PieChartType::getImplementationName()
244 throw( css::uno::RuntimeException, std::exception )
246 return getImplementationName_Static();
249 OUString PieChartType::getImplementationName_Static()
251 return OUString("com.sun.star.comp.chart.PieChartType");
254 sal_Bool SAL_CALL PieChartType::supportsService( const OUString& rServiceName )
255 throw( css::uno::RuntimeException, std::exception )
257 return cppu::supportsService(this, rServiceName);
260 css::uno::Sequence< OUString > SAL_CALL PieChartType::getSupportedServiceNames()
261 throw( css::uno::RuntimeException, std::exception )
263 return getSupportedServiceNames_Static();
266 } // namespace chart
268 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
269 com_sun_star_comp_chart_PieChartType_get_implementation(css::uno::XComponentContext *context,
270 css::uno::Sequence<css::uno::Any> const &)
272 return cppu::acquire(new ::chart::PieChartType(context));
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */