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