Update ooo320-m1
[ooovba.git] / chart2 / source / model / template / PieChartType.cxx
blob70bdcc05f926c3233af6559df1e136801e8b0bdc
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: PieChartType.cxx,v $
10 * $Revision: 1.8 $
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 "PieChartType.hxx"
34 #include "PropertyHelper.hxx"
35 #include "macros.hxx"
36 #include "PolarCoordinateSystem.hxx"
37 #include "AxisHelper.hxx"
38 #include "servicenames_charttypes.hxx"
39 #include "ContainerHelper.hxx"
40 #include "AxisIndexDefines.hxx"
41 #include "AxisHelper.hxx"
42 #include <com/sun/star/beans/PropertyAttribute.hpp>
43 #include <com/sun/star/chart2/AxisType.hpp>
45 using namespace ::com::sun::star;
47 using ::rtl::OUString;
48 using ::com::sun::star::beans::Property;
49 using ::com::sun::star::uno::Sequence;
50 using ::com::sun::star::uno::Reference;
51 using ::com::sun::star::uno::Any;
52 using ::osl::MutexGuard;
54 namespace
57 enum
59 PROP_PIECHARTTYPE_USE_RINGS
62 void lcl_AddPropertiesToVector(
63 ::std::vector< Property > & rOutProperties )
65 rOutProperties.push_back(
66 Property( C2U( "UseRings" ),
67 PROP_PIECHARTTYPE_USE_RINGS,
68 ::getBooleanCppuType(),
69 beans::PropertyAttribute::BOUND
70 | beans::PropertyAttribute::MAYBEDEFAULT ));
73 void lcl_AddDefaultsToMap(
74 ::chart::tPropertyValueMap & rOutMap )
76 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_PIECHARTTYPE_USE_RINGS, false );
79 const Sequence< Property > & lcl_GetPropertySequence()
81 static Sequence< Property > aPropSeq;
83 // /--
84 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
85 if( 0 == aPropSeq.getLength() )
87 // get properties
88 ::std::vector< ::com::sun::star::beans::Property > aProperties;
89 lcl_AddPropertiesToVector( aProperties );
91 // and sort them for access via bsearch
92 ::std::sort( aProperties.begin(), aProperties.end(),
93 ::chart::PropertyNameLess() );
95 // transfer result to static Sequence
96 aPropSeq = ::chart::ContainerHelper::ContainerToSequence( aProperties );
99 return aPropSeq;
102 } // anonymous namespace
104 namespace chart
107 PieChartType::PieChartType(
108 const uno::Reference< uno::XComponentContext > & xContext,
109 sal_Bool bUseRings /* = sal_False */) :
110 ChartType( xContext )
112 if( bUseRings )
113 setFastPropertyValue_NoBroadcast( PROP_PIECHARTTYPE_USE_RINGS, uno::makeAny( bUseRings ));
116 PieChartType::PieChartType( const PieChartType & rOther ) :
117 ChartType( rOther )
121 PieChartType::~PieChartType()
124 // ____ XCloneable ____
125 uno::Reference< util::XCloneable > SAL_CALL PieChartType::createClone()
126 throw (uno::RuntimeException)
128 return uno::Reference< util::XCloneable >( new PieChartType( *this ));
131 // ____ XChartType ____
132 ::rtl::OUString SAL_CALL PieChartType::getChartType()
133 throw (uno::RuntimeException)
135 return CHART2_SERVICE_NAME_CHARTTYPE_PIE;
138 Reference< chart2::XCoordinateSystem > SAL_CALL
139 PieChartType::createCoordinateSystem( ::sal_Int32 DimensionCount )
140 throw (lang::IllegalArgumentException,
141 uno::RuntimeException)
143 Reference< chart2::XCoordinateSystem > xResult(
144 new PolarCoordinateSystem(
145 GetComponentContext(), DimensionCount, /* bSwapXAndYAxis */ sal_False ));
147 for( sal_Int32 i=0; i<DimensionCount; ++i )
149 Reference< chart2::XAxis > xAxis( xResult->getAxisByDimension( i, MAIN_AXIS_INDEX ) );
150 if( !xAxis.is() )
152 OSL_ENSURE(false,"a created coordinate system should have an axis for each dimension");
153 continue;
156 //hhhh todo make axis invisible
158 chart2::ScaleData aScaleData = xAxis->getScaleData();
159 aScaleData.Scaling = AxisHelper::createLinearScaling();
160 aScaleData.AxisType = chart2::AxisType::REALNUMBER;
162 if( i == 0 )
163 aScaleData.Orientation = chart2::AxisOrientation_REVERSE;
164 else
165 aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
167 //remove explicit scalings from all axes
168 AxisHelper::removeExplicitScaling( aScaleData );
170 xAxis->setScaleData( aScaleData );
173 return xResult;
176 // ____ OPropertySet ____
177 uno::Any PieChartType::GetDefaultValue( sal_Int32 nHandle ) const
178 throw(beans::UnknownPropertyException)
180 static tPropertyValueMap aStaticDefaults;
182 // /--
183 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
184 if( 0 == aStaticDefaults.size() )
186 // initialize defaults
187 lcl_AddDefaultsToMap( aStaticDefaults );
190 tPropertyValueMap::const_iterator aFound(
191 aStaticDefaults.find( nHandle ));
193 if( aFound == aStaticDefaults.end())
194 return uno::Any();
196 return (*aFound).second;
197 // \--
200 // ____ OPropertySet ____
201 ::cppu::IPropertyArrayHelper & SAL_CALL PieChartType::getInfoHelper()
203 static ::cppu::OPropertyArrayHelper aArrayHelper( lcl_GetPropertySequence(),
204 /* bSorted = */ sal_True );
206 return aArrayHelper;
210 // ____ XPropertySet ____
211 uno::Reference< beans::XPropertySetInfo > SAL_CALL
212 PieChartType::getPropertySetInfo()
213 throw (uno::RuntimeException)
215 static uno::Reference< beans::XPropertySetInfo > xInfo;
217 // /--
218 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
219 if( !xInfo.is())
221 xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo(
222 getInfoHelper());
225 return xInfo;
226 // \--
229 uno::Sequence< ::rtl::OUString > PieChartType::getSupportedServiceNames_Static()
231 uno::Sequence< ::rtl::OUString > aServices( 3 );
232 aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_PIE;
233 aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartType" );
234 aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
235 return aServices;
238 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
239 APPHELPER_XSERVICEINFO_IMPL( PieChartType,
240 C2U( "com.sun.star.comp.chart.PieChartType" ));
242 } // namespace chart