merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / model / template / LineChartType.cxx
blobf96d7ed1297de8f52985bd50b3faae60d2777baa
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 #include "LineChartType.hxx"
31 #include "PropertyHelper.hxx"
32 #include "macros.hxx"
33 #include "servicenames_charttypes.hxx"
34 #include "ContainerHelper.hxx"
35 #include <com/sun/star/beans/PropertyAttribute.hpp>
36 #include <com/sun/star/chart2/CurveStyle.hpp>
38 using namespace ::com::sun::star;
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;
47 namespace
50 enum
52 PROP_LINECHARTTYPE_CURVE_STYLE,
53 PROP_LINECHARTTYPE_CURVE_RESOLUTION,
54 PROP_LINECHARTTYPE_SPLINE_ORDER
57 void lcl_AddPropertiesToVector(
58 ::std::vector< Property > & rOutProperties )
60 rOutProperties.push_back(
61 Property( C2U( "CurveStyle" ),
62 PROP_LINECHARTTYPE_CURVE_STYLE,
63 ::getCppuType( reinterpret_cast< const chart2::CurveStyle * >(0)),
64 beans::PropertyAttribute::BOUND
65 | beans::PropertyAttribute::MAYBEDEFAULT ));
67 rOutProperties.push_back(
68 Property( C2U( "CurveResolution" ),
69 PROP_LINECHARTTYPE_CURVE_RESOLUTION,
70 ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
71 beans::PropertyAttribute::BOUND
72 | beans::PropertyAttribute::MAYBEDEFAULT ));
73 rOutProperties.push_back(
74 Property( C2U( "SplineOrder" ),
75 PROP_LINECHARTTYPE_SPLINE_ORDER,
76 ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
77 beans::PropertyAttribute::BOUND
78 | beans::PropertyAttribute::MAYBEDEFAULT ));
81 void lcl_AddDefaultsToMap(
82 ::chart::tPropertyValueMap & rOutMap )
84 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LINECHARTTYPE_CURVE_STYLE, ::chart2::CurveStyle_LINES );
85 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_LINECHARTTYPE_CURVE_RESOLUTION, 20 );
87 // todo: check whether order 3 means polygons of order 3 or 2. (see
88 // http://www.people.nnov.ru/fractal/Splines/Basis.htm )
89 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_LINECHARTTYPE_SPLINE_ORDER, 3 );
92 const Sequence< Property > & lcl_GetPropertySequence()
94 static Sequence< Property > aPropSeq;
96 // /--
97 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
98 if( 0 == aPropSeq.getLength() )
100 // get properties
101 ::std::vector< ::com::sun::star::beans::Property > aProperties;
102 lcl_AddPropertiesToVector( aProperties );
104 // and sort them for access via bsearch
105 ::std::sort( aProperties.begin(), aProperties.end(),
106 ::chart::PropertyNameLess() );
108 // transfer result to static Sequence
109 aPropSeq = ::chart::ContainerHelper::ContainerToSequence( aProperties );
112 return aPropSeq;
115 } // anonymous namespace
117 namespace chart
120 LineChartType::LineChartType(
121 const uno::Reference< uno::XComponentContext > & xContext ) :
122 ChartType( xContext )
126 LineChartType::LineChartType( const LineChartType & rOther ) :
127 ChartType( rOther )
131 LineChartType::~LineChartType()
134 // ____ XCloneable ____
135 uno::Reference< util::XCloneable > SAL_CALL LineChartType::createClone()
136 throw (uno::RuntimeException)
138 return uno::Reference< util::XCloneable >( new LineChartType( *this ));
141 // ____ XChartType ____
142 ::rtl::OUString SAL_CALL LineChartType::getChartType()
143 throw (uno::RuntimeException)
145 return CHART2_SERVICE_NAME_CHARTTYPE_LINE;
149 // ____ OPropertySet ____
150 uno::Any LineChartType::GetDefaultValue( sal_Int32 nHandle ) const
151 throw(beans::UnknownPropertyException)
153 static tPropertyValueMap aStaticDefaults;
155 // /--
156 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
157 if( 0 == aStaticDefaults.size() )
159 // initialize defaults
160 lcl_AddDefaultsToMap( aStaticDefaults );
163 tPropertyValueMap::const_iterator aFound(
164 aStaticDefaults.find( nHandle ));
166 if( aFound == aStaticDefaults.end())
167 return uno::Any();
169 return (*aFound).second;
170 // \--
173 ::cppu::IPropertyArrayHelper & SAL_CALL LineChartType::getInfoHelper()
175 static ::cppu::OPropertyArrayHelper aArrayHelper( lcl_GetPropertySequence(),
176 /* bSorted = */ sal_True );
178 return aArrayHelper;
182 // ____ XPropertySet ____
183 uno::Reference< beans::XPropertySetInfo > SAL_CALL
184 LineChartType::getPropertySetInfo()
185 throw (uno::RuntimeException)
187 static uno::Reference< beans::XPropertySetInfo > xInfo;
189 // /--
190 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
191 if( !xInfo.is())
193 xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo(
194 getInfoHelper());
197 return xInfo;
198 // \--
201 uno::Sequence< ::rtl::OUString > LineChartType::getSupportedServiceNames_Static()
203 uno::Sequence< ::rtl::OUString > aServices( 3 );
204 aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_LINE;
205 aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartType" );
206 aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
207 return aServices;
210 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
211 APPHELPER_XSERVICEINFO_IMPL( LineChartType,
212 C2U( "com.sun.star.comp.chart.LineChartType" ));
214 } // namespace chart