1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 #include "PieChartType.hxx"
27 #include "PropertyHelper.hxx"
28 #include "macros.hxx"
29 #include "PolarCoordinateSystem.hxx"
30 #include "AxisHelper.hxx"
31 #include "servicenames_charttypes.hxx"
32 #include "ContainerHelper.hxx"
33 #include "AxisIndexDefines.hxx"
34 #include "AxisHelper.hxx"
35 #include <com/sun/star/beans/PropertyAttribute.hpp>
36 #include <com/sun/star/chart2/AxisType.hpp>
37 
38 using namespace ::com::sun::star;
39 
40 using ::rtl::OUString;
41 using ::com::sun::star::beans::Property;
42 using ::com::sun::star::uno::Sequence;
43 using ::com::sun::star::uno::Reference;
44 using ::com::sun::star::uno::Any;
45 using ::osl::MutexGuard;
46 
47 namespace
48 {
49 
50 enum
51 {
52     PROP_PIECHARTTYPE_USE_RINGS,
53     PROP_PIECHARTTYPE_3DRELATIVEHEIGHT
54 };
55 
lcl_AddPropertiesToVector(::std::vector<Property> & rOutProperties)56 void lcl_AddPropertiesToVector(
57     ::std::vector< Property > & rOutProperties )
58 {
59     rOutProperties.push_back(
60         Property( C2U( "UseRings" ),
61                   PROP_PIECHARTTYPE_USE_RINGS,
62                   ::getBooleanCppuType(),
63                   beans::PropertyAttribute::BOUND
64                   | beans::PropertyAttribute::MAYBEDEFAULT ));
65     rOutProperties.push_back(
66         Property( C2U("3DRelativeHeight"),
67                   PROP_PIECHARTTYPE_3DRELATIVEHEIGHT,
68                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
69                   beans::PropertyAttribute::MAYBEVOID ));
70 }
71 
72 struct StaticPieChartTypeDefaults_Initializer
73 {
operator ()__anon2766e2070111::StaticPieChartTypeDefaults_Initializer74     ::chart::tPropertyValueMap* operator()()
75     {
76         static ::chart::tPropertyValueMap aStaticDefaults;
77         lcl_AddDefaultsToMap( aStaticDefaults );
78         return &aStaticDefaults;
79     }
80 private:
lcl_AddDefaultsToMap__anon2766e2070111::StaticPieChartTypeDefaults_Initializer81     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
82     {
83         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_PIECHARTTYPE_USE_RINGS, false );
84     	::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_PIECHARTTYPE_3DRELATIVEHEIGHT, 100 );
85     }
86 };
87 
88 struct StaticPieChartTypeDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticPieChartTypeDefaults_Initializer >
89 {
90 };
91 
92 struct StaticPieChartTypeInfoHelper_Initializer
93 {
operator ()__anon2766e2070111::StaticPieChartTypeInfoHelper_Initializer94     ::cppu::OPropertyArrayHelper* operator()()
95     {
96         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
97         return &aPropHelper;
98     }
99 
100 private:
lcl_GetPropertySequence__anon2766e2070111::StaticPieChartTypeInfoHelper_Initializer101     Sequence< Property > lcl_GetPropertySequence()
102     {
103         ::std::vector< ::com::sun::star::beans::Property > aProperties;
104         lcl_AddPropertiesToVector( aProperties );
105 
106         ::std::sort( aProperties.begin(), aProperties.end(),
107                      ::chart::PropertyNameLess() );
108 
109         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
110     }
111 
112 };
113 
114 struct StaticPieChartTypeInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticPieChartTypeInfoHelper_Initializer >
115 {
116 };
117 
118 struct StaticPieChartTypeInfo_Initializer
119 {
operator ()__anon2766e2070111::StaticPieChartTypeInfo_Initializer120     uno::Reference< beans::XPropertySetInfo >* operator()()
121     {
122         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
123             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticPieChartTypeInfoHelper::get() ) );
124         return &xPropertySetInfo;
125     }
126 };
127 
128 struct StaticPieChartTypeInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticPieChartTypeInfo_Initializer >
129 {
130 };
131 
132 } // anonymous namespace
133 
134 namespace chart
135 {
136 
PieChartType(const uno::Reference<uno::XComponentContext> & xContext,sal_Bool bUseRings)137 PieChartType::PieChartType(
138     const uno::Reference< uno::XComponentContext > & xContext,
139     sal_Bool bUseRings  /* = sal_False */) :
140         ChartType( xContext )
141 {
142     if( bUseRings )
143         setFastPropertyValue_NoBroadcast( PROP_PIECHARTTYPE_USE_RINGS, uno::makeAny( bUseRings ));
144 }
145 
PieChartType(const PieChartType & rOther)146 PieChartType::PieChartType( const PieChartType & rOther ) :
147         ChartType( rOther )
148 {
149 }
150 
~PieChartType()151 PieChartType::~PieChartType()
152 {}
153 
154 // ____ XCloneable ____
createClone()155 uno::Reference< util::XCloneable > SAL_CALL PieChartType::createClone()
156     throw (uno::RuntimeException)
157 {
158     return uno::Reference< util::XCloneable >( new PieChartType( *this ));
159 }
160 
161 // ____ XChartType ____
getChartType()162 ::rtl::OUString SAL_CALL PieChartType::getChartType()
163     throw (uno::RuntimeException)
164 {
165     return CHART2_SERVICE_NAME_CHARTTYPE_PIE;
166 }
167 
168 Reference< chart2::XCoordinateSystem > SAL_CALL
createCoordinateSystem(::sal_Int32 DimensionCount)169     PieChartType::createCoordinateSystem( ::sal_Int32 DimensionCount )
170     throw (lang::IllegalArgumentException,
171            uno::RuntimeException)
172 {
173     Reference< chart2::XCoordinateSystem > xResult(
174         new PolarCoordinateSystem(
175             GetComponentContext(), DimensionCount, /* bSwapXAndYAxis */ sal_False ));
176 
177     for( sal_Int32 i=0; i<DimensionCount; ++i )
178     {
179         Reference< chart2::XAxis > xAxis( xResult->getAxisByDimension( i, MAIN_AXIS_INDEX ) );
180         if( !xAxis.is() )
181         {
182             OSL_ENSURE(false,"a created coordinate system should have an axis for each dimension");
183             continue;
184         }
185 
186         //hhhh todo make axis invisible
187 
188         chart2::ScaleData aScaleData = xAxis->getScaleData();
189         aScaleData.Scaling = AxisHelper::createLinearScaling();
190         aScaleData.AxisType = chart2::AxisType::REALNUMBER;
191 
192         if( i == 0 )
193             aScaleData.Orientation = chart2::AxisOrientation_REVERSE;
194         else
195             aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
196 
197         //remove explicit scalings from all axes
198         AxisHelper::removeExplicitScaling( aScaleData );
199 
200         xAxis->setScaleData( aScaleData );
201     }
202 
203     return xResult;
204 }
205 
206 // ____ OPropertySet ____
GetDefaultValue(sal_Int32 nHandle) const207 uno::Any PieChartType::GetDefaultValue( sal_Int32 nHandle ) const
208     throw(beans::UnknownPropertyException)
209 {
210     const tPropertyValueMap& rStaticDefaults = *StaticPieChartTypeDefaults::get();
211     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
212     if( aFound == rStaticDefaults.end() )
213         return uno::Any();
214     return (*aFound).second;
215 }
216 
217 // ____ OPropertySet ____
getInfoHelper()218 ::cppu::IPropertyArrayHelper & SAL_CALL PieChartType::getInfoHelper()
219 {
220     return *StaticPieChartTypeInfoHelper::get();
221 }
222 
223 // ____ XPropertySet ____
getPropertySetInfo()224 uno::Reference< beans::XPropertySetInfo > SAL_CALL PieChartType::getPropertySetInfo()
225     throw (uno::RuntimeException)
226 {
227     return *StaticPieChartTypeInfo::get();
228 }
229 
getSupportedServiceNames_Static()230 uno::Sequence< ::rtl::OUString > PieChartType::getSupportedServiceNames_Static()
231 {
232     uno::Sequence< ::rtl::OUString > aServices( 3 );
233     aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_PIE;
234     aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartType" );
235     aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
236     return aServices;
237 }
238 
239 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
240 APPHELPER_XSERVICEINFO_IMPL( PieChartType,
241                              C2U( "com.sun.star.comp.chart.PieChartType" ));
242 
243 } //  namespace chart
244