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