update dev300-m58
[ooovba.git] / chart2 / source / model / template / BarChartTypeTemplate.cxx
blobe6382d542f692d730131946108ae12b5763e1126
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: BarChartTypeTemplate.cxx,v $
10 * $Revision: 1.14 $
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 "BarChartTypeTemplate.hxx"
34 #include "macros.hxx"
35 #include "DiagramHelper.hxx"
36 #include "servicenames_charttypes.hxx"
37 #include "ContainerHelper.hxx"
38 #include "DataSeriesHelper.hxx"
39 #include "PropertyHelper.hxx"
40 #include <com/sun/star/beans/PropertyAttribute.hpp>
41 #include <com/sun/star/drawing/LineStyle.hpp>
42 #include <com/sun/star/chart2/DataPointGeometry3D.hpp>
44 #include <algorithm>
46 using namespace ::com::sun::star;
48 using ::com::sun::star::uno::Reference;
49 using ::com::sun::star::uno::Sequence;
50 using ::com::sun::star::beans::Property;
51 using ::osl::MutexGuard;
52 using ::rtl::OUString;
54 namespace
57 static const OUString lcl_aServiceName(
58 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.BarChartTypeTemplate" ));
60 enum
62 PROP_BAR_TEMPLATE_DIMENSION,
63 PROP_BAR_TEMPLATE_GEOMETRY3D
66 void lcl_AddPropertiesToVector(
67 ::std::vector< Property > & rOutProperties )
69 rOutProperties.push_back(
70 Property( C2U( "Dimension" ),
71 PROP_BAR_TEMPLATE_DIMENSION,
72 ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
73 beans::PropertyAttribute::BOUND
74 | beans::PropertyAttribute::MAYBEDEFAULT ));
75 rOutProperties.push_back(
76 Property( C2U( "Geometry3D" ),
77 PROP_BAR_TEMPLATE_GEOMETRY3D,
78 ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
79 beans::PropertyAttribute::BOUND
80 | beans::PropertyAttribute::MAYBEDEFAULT ));
83 void lcl_AddDefaultsToMap(
84 ::chart::tPropertyValueMap & rOutMap )
86 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_BAR_TEMPLATE_DIMENSION, 2 );
87 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_BAR_TEMPLATE_GEOMETRY3D, ::chart2::DataPointGeometry3D::CUBOID );
90 const Sequence< Property > & lcl_GetPropertySequence()
92 static Sequence< Property > aPropSeq;
94 // /--
95 MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
96 if( 0 == aPropSeq.getLength() )
98 // get properties
99 ::std::vector< ::com::sun::star::beans::Property > aProperties;
100 lcl_AddPropertiesToVector( aProperties );
102 // and sort them for access via bsearch
103 ::std::sort( aProperties.begin(), aProperties.end(),
104 ::chart::PropertyNameLess() );
106 // transfer result to static Sequence
107 aPropSeq = ::chart::ContainerHelper::ContainerToSequence( aProperties );
110 return aPropSeq;
113 ::cppu::IPropertyArrayHelper & lcl_getInfoHelper()
115 static ::cppu::OPropertyArrayHelper aArrayHelper(
116 lcl_GetPropertySequence(),
117 /* bSorted = */ sal_True );
119 return aArrayHelper;
122 } // anonymous namespace
124 namespace chart
127 BarChartTypeTemplate::BarChartTypeTemplate(
128 Reference<
129 uno::XComponentContext > const & xContext,
130 const OUString & rServiceName,
131 StackMode eStackMode,
132 BarDirection eDirection,
133 sal_Int32 nDim /* = 2 */ ) :
134 ChartTypeTemplate( xContext, rServiceName ),
135 ::property::OPropertySet( m_aMutex ),
136 m_eStackMode( eStackMode ),
137 m_eBarDirection( eDirection ),
138 m_nDim( nDim )
141 BarChartTypeTemplate::~BarChartTypeTemplate()
144 sal_Int32 BarChartTypeTemplate::getDimension() const
146 return m_nDim;
149 StackMode BarChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
151 return m_eStackMode;
154 bool BarChartTypeTemplate::isSwapXAndY() const
156 return (m_eBarDirection == HORIZONTAL);
159 // ____ XChartTypeTemplate ____
160 sal_Bool SAL_CALL BarChartTypeTemplate::matchesTemplate(
161 const Reference< chart2::XDiagram >& xDiagram,
162 sal_Bool bAdaptProperties )
163 throw (uno::RuntimeException)
165 sal_Bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties );
167 //check BarDirection
168 if( bResult )
170 bool bFound = false;
171 bool bAmbiguous = false;
172 bool bVertical = DiagramHelper::getVertical( xDiagram, bFound, bAmbiguous );
173 if( m_eBarDirection == HORIZONTAL )
174 bResult = sal_Bool( bVertical );
175 else if( m_eBarDirection == VERTICAL )
176 bResult = sal_Bool( !bVertical );
179 // adapt solid-type of template according to values in series
180 if( bAdaptProperties &&
181 bResult &&
182 getDimension() == 3 )
184 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
185 DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
187 bool bGeomFound = false, bGeomAmbiguous = false;
188 sal_Int32 aCommonGeom = DiagramHelper::getGeometry3D( xDiagram, bGeomFound, bGeomAmbiguous );
190 if( !bGeomAmbiguous )
192 setFastPropertyValue_NoBroadcast(
193 PROP_BAR_TEMPLATE_GEOMETRY3D, uno::makeAny( aCommonGeom ));
197 return bResult;
199 Reference< chart2::XChartType > BarChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
201 Reference< chart2::XChartType > xResult;
205 Reference< lang::XMultiServiceFactory > xFact(
206 GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
207 xResult.set( xFact->createInstance(
208 CHART2_SERVICE_NAME_CHARTTYPE_COLUMN ), uno::UNO_QUERY_THROW );
210 catch( uno::Exception & ex )
212 ASSERT_EXCEPTION( ex );
215 return xResult;
218 Reference< chart2::XChartType > SAL_CALL BarChartTypeTemplate::getChartTypeForNewSeries(
219 const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
220 throw (uno::RuntimeException)
222 Reference< chart2::XChartType > xResult( getChartTypeForIndex( 0 ) );
223 ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult );
224 return xResult;
228 // ____ OPropertySet ____
229 uno::Any BarChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle ) const
230 throw(beans::UnknownPropertyException)
232 static tPropertyValueMap aStaticDefaults;
234 // /--
235 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
236 if( 0 == aStaticDefaults.size() )
238 // initialize defaults
239 lcl_AddDefaultsToMap( aStaticDefaults );
242 tPropertyValueMap::const_iterator aFound(
243 aStaticDefaults.find( nHandle ));
245 if( aFound == aStaticDefaults.end())
246 return uno::Any();
248 return (*aFound).second;
249 // \--
252 ::cppu::IPropertyArrayHelper & SAL_CALL BarChartTypeTemplate::getInfoHelper()
254 return lcl_getInfoHelper();
258 // ____ XPropertySet ____
259 Reference< beans::XPropertySetInfo > SAL_CALL
260 BarChartTypeTemplate::getPropertySetInfo()
261 throw (uno::RuntimeException)
263 static Reference< beans::XPropertySetInfo > xInfo;
265 // /--
266 MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
267 if( !xInfo.is())
269 xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo(
270 getInfoHelper());
273 return xInfo;
274 // \--
277 void SAL_CALL BarChartTypeTemplate::applyStyle(
278 const Reference< chart2::XDataSeries >& xSeries,
279 ::sal_Int32 nChartTypeIndex,
280 ::sal_Int32 nSeriesIndex,
281 ::sal_Int32 nSeriesCount )
282 throw (uno::RuntimeException)
284 ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
285 if( getDimension() == 3 )
289 //apply Geometry3D
290 uno::Any aAGeometry3D;
291 this->getFastPropertyValue( aAGeometry3D, PROP_BAR_TEMPLATE_GEOMETRY3D );
292 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "Geometry3D" ), aAGeometry3D );
294 catch( uno::Exception & ex )
296 ASSERT_EXCEPTION( ex );
301 void SAL_CALL BarChartTypeTemplate::resetStyles(
302 const Reference< chart2::XDiagram >& xDiagram )
303 throw (uno::RuntimeException)
305 ChartTypeTemplate::resetStyles( xDiagram );
306 if( getDimension() == 3 )
308 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
309 DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
310 uno::Any aLineStyleAny( uno::makeAny( drawing::LineStyle_NONE ));
311 for( ::std::vector< Reference< chart2::XDataSeries > >::iterator aIt( aSeriesVec.begin());
312 aIt != aSeriesVec.end(); ++aIt )
314 Reference< beans::XPropertyState > xState( *aIt, uno::UNO_QUERY );
315 if( xState.is())
317 xState->setPropertyToDefault( C2U("Geometry3D"));
318 Reference< beans::XPropertySet > xProp( xState, uno::UNO_QUERY );
319 if( xProp.is() &&
320 xProp->getPropertyValue( C2U("BorderStyle")) == aLineStyleAny )
322 xState->setPropertyToDefault( C2U("BorderStyle"));
328 DiagramHelper::setVertical( xDiagram, false );
332 void BarChartTypeTemplate::createCoordinateSystems(
333 const Reference< chart2::XCoordinateSystemContainer > & xCooSysCnt )
335 ChartTypeTemplate::createCoordinateSystems( xCooSysCnt );
337 Reference< chart2::XDiagram > xDiagram( xCooSysCnt, uno::UNO_QUERY );
338 DiagramHelper::setVertical( xDiagram, m_eBarDirection == HORIZONTAL );
341 // ----------------------------------------
343 Sequence< OUString > BarChartTypeTemplate::getSupportedServiceNames_Static()
345 Sequence< OUString > aServices( 2 );
346 aServices[ 0 ] = lcl_aServiceName;
347 aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" );
348 return aServices;
351 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
352 APPHELPER_XSERVICEINFO_IMPL( BarChartTypeTemplate, lcl_aServiceName );
354 IMPLEMENT_FORWARD_XINTERFACE2( BarChartTypeTemplate, ChartTypeTemplate, OPropertySet )
355 IMPLEMENT_FORWARD_XTYPEPROVIDER2( BarChartTypeTemplate, ChartTypeTemplate, OPropertySet )
357 } // namespace chart