update dev300-m58
[ooovba.git] / chart2 / source / model / template / AreaChartTypeTemplate.cxx
blob98874ef8d39c3789fc6009dbae4e700172bad629
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AreaChartTypeTemplate.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "AreaChartTypeTemplate.hxx"
34 #include "macros.hxx"
35 #include "servicenames_charttypes.hxx"
36 #include "DiagramHelper.hxx"
37 #include "ContainerHelper.hxx"
38 #include "PropertyHelper.hxx"
39 #include <com/sun/star/beans/PropertyAttribute.hpp>
40 #include <com/sun/star/drawing/LineStyle.hpp>
42 #include <algorithm>
44 using namespace ::com::sun::star;
46 using ::rtl::OUString;
47 using ::com::sun::star::beans::Property;
48 using ::com::sun::star::uno::Sequence;
49 using ::com::sun::star::uno::Reference;
50 using ::com::sun::star::uno::Any;
51 using ::osl::MutexGuard;
53 namespace
56 static const ::rtl::OUString lcl_aServiceName(
57 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.AreaChartTypeTemplate" ));
59 enum
61 PROP_AREA_TEMPLATE_DIMENSION
64 void lcl_AddPropertiesToVector(
65 ::std::vector< Property > & rOutProperties )
67 rOutProperties.push_back(
68 Property( C2U( "Dimension" ),
69 PROP_AREA_TEMPLATE_DIMENSION,
70 ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
71 beans::PropertyAttribute::BOUND
72 | beans::PropertyAttribute::MAYBEDEFAULT ));
75 void lcl_AddDefaultsToMap(
76 ::chart::tPropertyValueMap & rOutMap )
78 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_AREA_TEMPLATE_DIMENSION, 2 );
81 const uno::Sequence< Property > & lcl_GetPropertySequence()
83 static uno::Sequence< Property > aPropSeq;
85 // /--
86 MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
87 if( 0 == aPropSeq.getLength() )
89 // get properties
90 ::std::vector< ::com::sun::star::beans::Property > aProperties;
91 lcl_AddPropertiesToVector( aProperties );
93 // and sort them for access via bsearch
94 ::std::sort( aProperties.begin(), aProperties.end(),
95 ::chart::PropertyNameLess() );
97 // transfer result to static Sequence
98 aPropSeq = ::chart::ContainerHelper::ContainerToSequence( aProperties );
101 return aPropSeq;
104 ::cppu::IPropertyArrayHelper & lcl_getInfoHelper()
106 static ::cppu::OPropertyArrayHelper aArrayHelper(
107 lcl_GetPropertySequence(),
108 /* bSorted = */ sal_True );
110 return aArrayHelper;
113 } // anonymous namespace
115 namespace chart
118 AreaChartTypeTemplate::AreaChartTypeTemplate(
119 uno::Reference<
120 uno::XComponentContext > const & xContext,
121 const ::rtl::OUString & rServiceName,
122 StackMode eStackMode,
123 sal_Int32 nDim /* = 2 */ ) :
124 ChartTypeTemplate( xContext, rServiceName ),
125 ::property::OPropertySet( m_aMutex ),
126 m_eStackMode( eStackMode )
128 setFastPropertyValue_NoBroadcast( PROP_AREA_TEMPLATE_DIMENSION, uno::makeAny( nDim ));
131 AreaChartTypeTemplate::~AreaChartTypeTemplate()
134 // ____ OPropertySet ____
135 uno::Any AreaChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle ) const
136 throw(beans::UnknownPropertyException)
138 static tPropertyValueMap aStaticDefaults;
140 // /--
141 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
142 if( 0 == aStaticDefaults.size() )
144 // initialize defaults
145 lcl_AddDefaultsToMap( aStaticDefaults );
148 tPropertyValueMap::const_iterator aFound(
149 aStaticDefaults.find( nHandle ));
151 if( aFound == aStaticDefaults.end())
152 return uno::Any();
154 return (*aFound).second;
155 // \--
158 ::cppu::IPropertyArrayHelper & SAL_CALL AreaChartTypeTemplate::getInfoHelper()
160 return lcl_getInfoHelper();
164 // ____ XPropertySet ____
165 uno::Reference< beans::XPropertySetInfo > SAL_CALL
166 AreaChartTypeTemplate::getPropertySetInfo()
167 throw (uno::RuntimeException)
169 static uno::Reference< beans::XPropertySetInfo > xInfo;
171 // /--
172 MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
173 if( !xInfo.is())
175 xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo(
176 getInfoHelper());
179 return xInfo;
180 // \--
183 sal_Int32 AreaChartTypeTemplate::getDimension() const
185 sal_Int32 nDim = 2;
188 // note: UNO-methods are never const
189 const_cast< AreaChartTypeTemplate * >( this )->
190 getFastPropertyValue( PROP_AREA_TEMPLATE_DIMENSION ) >>= nDim;
192 catch( beans::UnknownPropertyException & ex )
194 ASSERT_EXCEPTION( ex );
197 return nDim;
200 StackMode AreaChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
202 return m_eStackMode;
205 // ____ XChartTypeTemplate ____
206 void SAL_CALL AreaChartTypeTemplate::applyStyle(
207 const Reference< chart2::XDataSeries >& xSeries,
208 ::sal_Int32 nChartTypeIndex,
209 ::sal_Int32 nSeriesIndex,
210 ::sal_Int32 nSeriesCount )
211 throw (uno::RuntimeException)
213 ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
214 if( getDimension() == 3 )
218 uno::Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY_THROW );
219 xProp->setPropertyValue( C2U("BorderStyle"),
220 uno::makeAny( drawing::LineStyle_NONE ));
222 catch( uno::Exception & ex )
224 ASSERT_EXCEPTION( ex );
229 void SAL_CALL AreaChartTypeTemplate::resetStyles( const Reference< chart2::XDiagram >& xDiagram )
230 throw (uno::RuntimeException)
232 ChartTypeTemplate::resetStyles( xDiagram );
233 if( getDimension() == 3 )
235 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
236 DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
237 uno::Any aLineStyleAny( uno::makeAny( drawing::LineStyle_NONE ));
238 for( ::std::vector< Reference< chart2::XDataSeries > >::iterator aIt( aSeriesVec.begin());
239 aIt != aSeriesVec.end(); ++aIt )
241 Reference< beans::XPropertyState > xState( *aIt, uno::UNO_QUERY );
242 Reference< beans::XPropertySet > xProp( *aIt, uno::UNO_QUERY );
243 if( xState.is() &&
244 xProp.is() &&
245 xProp->getPropertyValue( C2U("BorderStyle")) == aLineStyleAny )
247 xState->setPropertyToDefault( C2U("BorderStyle"));
253 Reference< chart2::XChartType > AreaChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
255 Reference< chart2::XChartType > xResult;
259 Reference< lang::XMultiServiceFactory > xFact(
260 GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
261 xResult.set( xFact->createInstance(
262 CHART2_SERVICE_NAME_CHARTTYPE_AREA ), uno::UNO_QUERY_THROW );
264 catch( uno::Exception & ex )
266 ASSERT_EXCEPTION( ex );
269 return xResult;
272 Reference< chart2::XChartType > SAL_CALL AreaChartTypeTemplate::getChartTypeForNewSeries(
273 const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
274 throw (uno::RuntimeException)
276 Reference< chart2::XChartType > xResult( getChartTypeForIndex( 0 ) );
277 ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult );
278 return xResult;
282 // ----------------------------------------
284 uno::Sequence< ::rtl::OUString > AreaChartTypeTemplate::getSupportedServiceNames_Static()
286 uno::Sequence< ::rtl::OUString > aServices( 2 );
287 aServices[ 0 ] = lcl_aServiceName;
288 aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" );
289 return aServices;
292 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
293 APPHELPER_XSERVICEINFO_IMPL( AreaChartTypeTemplate, lcl_aServiceName );
295 IMPLEMENT_FORWARD_XINTERFACE2( AreaChartTypeTemplate, ChartTypeTemplate, OPropertySet )
296 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AreaChartTypeTemplate, ChartTypeTemplate, OPropertySet )
298 } // namespace chart