merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / model / template / AreaChartTypeTemplate.cxx
blob5fe21cfb25e0b9ff5f57ee5f6fcf563701c211d0
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 "AreaChartTypeTemplate.hxx"
31 #include "macros.hxx"
32 #include "servicenames_charttypes.hxx"
33 #include "DiagramHelper.hxx"
34 #include "DataSeriesHelper.hxx"
35 #include "ContainerHelper.hxx"
36 #include "PropertyHelper.hxx"
37 #include <com/sun/star/beans/PropertyAttribute.hpp>
38 #include <com/sun/star/drawing/LineStyle.hpp>
40 #include <algorithm>
42 using namespace ::com::sun::star;
44 using ::rtl::OUString;
45 using ::com::sun::star::beans::Property;
46 using ::com::sun::star::uno::Sequence;
47 using ::com::sun::star::uno::Reference;
48 using ::com::sun::star::uno::Any;
49 using ::osl::MutexGuard;
51 namespace
54 static const ::rtl::OUString lcl_aServiceName(
55 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.AreaChartTypeTemplate" ));
57 enum
59 PROP_AREA_TEMPLATE_DIMENSION
62 void lcl_AddPropertiesToVector(
63 ::std::vector< Property > & rOutProperties )
65 rOutProperties.push_back(
66 Property( C2U( "Dimension" ),
67 PROP_AREA_TEMPLATE_DIMENSION,
68 ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
69 beans::PropertyAttribute::BOUND
70 | beans::PropertyAttribute::MAYBEDEFAULT ));
73 void lcl_AddDefaultsToMap(
74 ::chart::tPropertyValueMap & rOutMap )
76 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_AREA_TEMPLATE_DIMENSION, 2 );
79 const uno::Sequence< Property > & lcl_GetPropertySequence()
81 static uno::Sequence< Property > aPropSeq;
83 // /--
84 MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
85 if( 0 == aPropSeq.getLength() )
87 // get properties
88 ::std::vector< ::com::sun::star::beans::Property > aProperties;
89 lcl_AddPropertiesToVector( aProperties );
91 // and sort them for access via bsearch
92 ::std::sort( aProperties.begin(), aProperties.end(),
93 ::chart::PropertyNameLess() );
95 // transfer result to static Sequence
96 aPropSeq = ::chart::ContainerHelper::ContainerToSequence( aProperties );
99 return aPropSeq;
102 ::cppu::IPropertyArrayHelper & lcl_getInfoHelper()
104 static ::cppu::OPropertyArrayHelper aArrayHelper(
105 lcl_GetPropertySequence(),
106 /* bSorted = */ sal_True );
108 return aArrayHelper;
111 } // anonymous namespace
113 namespace chart
116 AreaChartTypeTemplate::AreaChartTypeTemplate(
117 uno::Reference<
118 uno::XComponentContext > const & xContext,
119 const ::rtl::OUString & rServiceName,
120 StackMode eStackMode,
121 sal_Int32 nDim /* = 2 */ ) :
122 ChartTypeTemplate( xContext, rServiceName ),
123 ::property::OPropertySet( m_aMutex ),
124 m_eStackMode( eStackMode )
126 setFastPropertyValue_NoBroadcast( PROP_AREA_TEMPLATE_DIMENSION, uno::makeAny( nDim ));
129 AreaChartTypeTemplate::~AreaChartTypeTemplate()
132 // ____ OPropertySet ____
133 uno::Any AreaChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle ) const
134 throw(beans::UnknownPropertyException)
136 static tPropertyValueMap aStaticDefaults;
138 // /--
139 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
140 if( 0 == aStaticDefaults.size() )
142 // initialize defaults
143 lcl_AddDefaultsToMap( aStaticDefaults );
146 tPropertyValueMap::const_iterator aFound(
147 aStaticDefaults.find( nHandle ));
149 if( aFound == aStaticDefaults.end())
150 return uno::Any();
152 return (*aFound).second;
153 // \--
156 ::cppu::IPropertyArrayHelper & SAL_CALL AreaChartTypeTemplate::getInfoHelper()
158 return lcl_getInfoHelper();
162 // ____ XPropertySet ____
163 uno::Reference< beans::XPropertySetInfo > SAL_CALL
164 AreaChartTypeTemplate::getPropertySetInfo()
165 throw (uno::RuntimeException)
167 static uno::Reference< beans::XPropertySetInfo > xInfo;
169 // /--
170 MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
171 if( !xInfo.is())
173 xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo(
174 getInfoHelper());
177 return xInfo;
178 // \--
181 sal_Int32 AreaChartTypeTemplate::getDimension() const
183 sal_Int32 nDim = 2;
186 // note: UNO-methods are never const
187 const_cast< AreaChartTypeTemplate * >( this )->
188 getFastPropertyValue( PROP_AREA_TEMPLATE_DIMENSION ) >>= nDim;
190 catch( beans::UnknownPropertyException & ex )
192 ASSERT_EXCEPTION( ex );
195 return nDim;
198 StackMode AreaChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
200 return m_eStackMode;
203 // ____ XChartTypeTemplate ____
204 void SAL_CALL AreaChartTypeTemplate::applyStyle(
205 const Reference< chart2::XDataSeries >& xSeries,
206 ::sal_Int32 nChartTypeIndex,
207 ::sal_Int32 nSeriesIndex,
208 ::sal_Int32 nSeriesCount )
209 throw (uno::RuntimeException)
211 ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
212 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "BorderStyle" ), uno::makeAny( drawing::LineStyle_NONE ) );
215 void SAL_CALL AreaChartTypeTemplate::resetStyles( const Reference< chart2::XDiagram >& xDiagram )
216 throw (uno::RuntimeException)
218 ChartTypeTemplate::resetStyles( xDiagram );
219 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
220 DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
221 uno::Any aLineStyleAny( uno::makeAny( drawing::LineStyle_NONE ));
222 for( ::std::vector< Reference< chart2::XDataSeries > >::iterator aIt( aSeriesVec.begin());
223 aIt != aSeriesVec.end(); ++aIt )
225 Reference< beans::XPropertyState > xState( *aIt, uno::UNO_QUERY );
226 Reference< beans::XPropertySet > xProp( *aIt, uno::UNO_QUERY );
227 if( xState.is() &&
228 xProp.is() &&
229 xProp->getPropertyValue( C2U("BorderStyle")) == aLineStyleAny )
231 xState->setPropertyToDefault( C2U("BorderStyle"));
236 Reference< chart2::XChartType > AreaChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
238 Reference< chart2::XChartType > xResult;
242 Reference< lang::XMultiServiceFactory > xFact(
243 GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
244 xResult.set( xFact->createInstance(
245 CHART2_SERVICE_NAME_CHARTTYPE_AREA ), uno::UNO_QUERY_THROW );
247 catch( uno::Exception & ex )
249 ASSERT_EXCEPTION( ex );
252 return xResult;
255 Reference< chart2::XChartType > SAL_CALL AreaChartTypeTemplate::getChartTypeForNewSeries(
256 const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
257 throw (uno::RuntimeException)
259 Reference< chart2::XChartType > xResult( getChartTypeForIndex( 0 ) );
260 ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult );
261 return xResult;
265 // ----------------------------------------
267 uno::Sequence< ::rtl::OUString > AreaChartTypeTemplate::getSupportedServiceNames_Static()
269 uno::Sequence< ::rtl::OUString > aServices( 2 );
270 aServices[ 0 ] = lcl_aServiceName;
271 aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" );
272 return aServices;
275 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
276 APPHELPER_XSERVICEINFO_IMPL( AreaChartTypeTemplate, lcl_aServiceName );
278 IMPLEMENT_FORWARD_XINTERFACE2( AreaChartTypeTemplate, ChartTypeTemplate, OPropertySet )
279 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AreaChartTypeTemplate, ChartTypeTemplate, OPropertySet )
281 } // namespace chart