Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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 <com/sun/star/beans/PropertyAttribute.hpp>
29 : #include <com/sun/star/chart2/AxisType.hpp>
30 :
31 : using namespace ::com::sun::star;
32 :
33 : using ::com::sun::star::beans::Property;
34 : using ::com::sun::star::uno::Sequence;
35 : using ::com::sun::star::uno::Reference;
36 : using ::com::sun::star::uno::Any;
37 : using ::osl::MutexGuard;
38 :
39 : namespace
40 : {
41 :
42 : enum
43 : {
44 : PROP_PIECHARTTYPE_USE_RINGS,
45 : PROP_PIECHARTTYPE_3DRELATIVEHEIGHT
46 : };
47 :
48 16 : static void lcl_AddPropertiesToVector(
49 : ::std::vector< Property > & rOutProperties )
50 : {
51 : rOutProperties.push_back(
52 : Property( "UseRings",
53 : PROP_PIECHARTTYPE_USE_RINGS,
54 16 : ::getBooleanCppuType(),
55 : beans::PropertyAttribute::BOUND
56 32 : | beans::PropertyAttribute::MAYBEDEFAULT ));
57 : rOutProperties.push_back(
58 : Property( "3DRelativeHeight",
59 : PROP_PIECHARTTYPE_3DRELATIVEHEIGHT,
60 16 : cppu::UnoType<sal_Int32>::get(),
61 16 : beans::PropertyAttribute::MAYBEVOID ));
62 16 : }
63 :
64 : struct StaticPieChartTypeDefaults_Initializer
65 : {
66 16 : ::chart::tPropertyValueMap* operator()()
67 : {
68 16 : static ::chart::tPropertyValueMap aStaticDefaults;
69 16 : lcl_AddDefaultsToMap( aStaticDefaults );
70 16 : return &aStaticDefaults;
71 : }
72 : private:
73 16 : void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
74 : {
75 16 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_PIECHARTTYPE_USE_RINGS, false );
76 16 : ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_PIECHARTTYPE_3DRELATIVEHEIGHT, 100 );
77 16 : }
78 : };
79 :
80 : struct StaticPieChartTypeDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticPieChartTypeDefaults_Initializer >
81 : {
82 : };
83 :
84 : struct StaticPieChartTypeInfoHelper_Initializer
85 : {
86 16 : ::cppu::OPropertyArrayHelper* operator()()
87 : {
88 16 : static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
89 16 : return &aPropHelper;
90 : }
91 :
92 : private:
93 16 : Sequence< Property > lcl_GetPropertySequence()
94 : {
95 16 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
96 16 : lcl_AddPropertiesToVector( aProperties );
97 :
98 : ::std::sort( aProperties.begin(), aProperties.end(),
99 16 : ::chart::PropertyNameLess() );
100 :
101 16 : return ::chart::ContainerHelper::ContainerToSequence( aProperties );
102 : }
103 :
104 : };
105 :
106 : struct StaticPieChartTypeInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticPieChartTypeInfoHelper_Initializer >
107 : {
108 : };
109 :
110 : struct StaticPieChartTypeInfo_Initializer
111 : {
112 8 : uno::Reference< beans::XPropertySetInfo >* operator()()
113 : {
114 : static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
115 8 : ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticPieChartTypeInfoHelper::get() ) );
116 8 : return &xPropertySetInfo;
117 : }
118 : };
119 :
120 : struct StaticPieChartTypeInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticPieChartTypeInfo_Initializer >
121 : {
122 : };
123 :
124 : } // anonymous namespace
125 :
126 : namespace chart
127 : {
128 :
129 15158 : PieChartType::PieChartType(
130 : const uno::Reference< uno::XComponentContext > & xContext,
131 : bool bUseRings /* = sal_False */) :
132 15158 : ChartType( xContext )
133 : {
134 15158 : if( bUseRings )
135 0 : setFastPropertyValue_NoBroadcast( PROP_PIECHARTTYPE_USE_RINGS, uno::makeAny( bUseRings ));
136 15158 : }
137 :
138 0 : PieChartType::PieChartType( const PieChartType & rOther ) :
139 0 : ChartType( rOther )
140 : {
141 0 : }
142 :
143 30312 : PieChartType::~PieChartType()
144 30312 : {}
145 :
146 : // ____ XCloneable ____
147 0 : uno::Reference< util::XCloneable > SAL_CALL PieChartType::createClone()
148 : throw (uno::RuntimeException, std::exception)
149 : {
150 0 : return uno::Reference< util::XCloneable >( new PieChartType( *this ));
151 : }
152 :
153 : // ____ XChartType ____
154 60045 : OUString SAL_CALL PieChartType::getChartType()
155 : throw (uno::RuntimeException, std::exception)
156 : {
157 60045 : return CHART2_SERVICE_NAME_CHARTTYPE_PIE;
158 : }
159 :
160 : Reference< chart2::XCoordinateSystem > SAL_CALL
161 40 : PieChartType::createCoordinateSystem( ::sal_Int32 DimensionCount )
162 : throw (lang::IllegalArgumentException,
163 : uno::RuntimeException, std::exception)
164 : {
165 : Reference< chart2::XCoordinateSystem > xResult(
166 : new PolarCoordinateSystem(
167 40 : GetComponentContext(), DimensionCount, /* bSwapXAndYAxis */ false ));
168 :
169 128 : for( sal_Int32 i=0; i<DimensionCount; ++i )
170 : {
171 88 : Reference< chart2::XAxis > xAxis( xResult->getAxisByDimension( i, MAIN_AXIS_INDEX ) );
172 88 : if( !xAxis.is() )
173 : {
174 : OSL_FAIL("a created coordinate system should have an axis for each dimension");
175 0 : continue;
176 : }
177 :
178 : //hhhh todo make axis invisible
179 :
180 176 : chart2::ScaleData aScaleData = xAxis->getScaleData();
181 88 : aScaleData.Scaling = AxisHelper::createLinearScaling();
182 88 : aScaleData.AxisType = chart2::AxisType::REALNUMBER;
183 :
184 88 : if( i == 0 )
185 40 : aScaleData.Orientation = chart2::AxisOrientation_REVERSE;
186 : else
187 48 : aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
188 :
189 : //remove explicit scalings from all axes
190 88 : AxisHelper::removeExplicitScaling( aScaleData );
191 :
192 88 : xAxis->setScaleData( aScaleData );
193 88 : }
194 :
195 40 : return xResult;
196 : }
197 :
198 102 : uno::Sequence< OUString > PieChartType::getSupportedPropertyRoles()
199 : throw (uno::RuntimeException, std::exception)
200 : {
201 102 : uno::Sequence< OUString > aPropRoles(2);
202 102 : aPropRoles[0] = "FillColor";
203 102 : aPropRoles[1] = "BorderColor";
204 :
205 102 : return aPropRoles;
206 : }
207 :
208 : // ____ OPropertySet ____
209 25604 : uno::Any PieChartType::GetDefaultValue( sal_Int32 nHandle ) const
210 : throw(beans::UnknownPropertyException)
211 : {
212 25604 : const tPropertyValueMap& rStaticDefaults = *StaticPieChartTypeDefaults::get();
213 25604 : tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
214 25604 : if( aFound == rStaticDefaults.end() )
215 0 : return uno::Any();
216 25604 : return (*aFound).second;
217 : }
218 :
219 : // ____ OPropertySet ____
220 45680 : ::cppu::IPropertyArrayHelper & SAL_CALL PieChartType::getInfoHelper()
221 : {
222 45680 : return *StaticPieChartTypeInfoHelper::get();
223 : }
224 :
225 : // ____ XPropertySet ____
226 42 : uno::Reference< beans::XPropertySetInfo > SAL_CALL PieChartType::getPropertySetInfo()
227 : throw (uno::RuntimeException, std::exception)
228 : {
229 42 : return *StaticPieChartTypeInfo::get();
230 : }
231 :
232 16 : uno::Sequence< OUString > PieChartType::getSupportedServiceNames_Static()
233 : {
234 16 : uno::Sequence< OUString > aServices( 3 );
235 16 : aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_PIE;
236 16 : aServices[ 1 ] = "com.sun.star.chart2.ChartType";
237 16 : aServices[ 2 ] = "com.sun.star.beans.PropertySet";
238 16 : return aServices;
239 : }
240 :
241 : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
242 236 : APPHELPER_XSERVICEINFO_IMPL( PieChartType,
243 : OUString("com.sun.star.comp.chart.PieChartType") );
244 :
245 108 : } // namespace chart
246 :
247 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|