merge the formfield patch from ooo-build
[ooovba.git] / chart2 / source / model / template / BarChartTypeTemplate.cxx
blob0e5904dca628e6b42d6eb0b1ee24e65239f994f6
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 setStackModePropertiesToChartType(xResult);
225 return xResult;
229 // ____ OPropertySet ____
230 uno::Any BarChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle ) const
231 throw(beans::UnknownPropertyException)
233 static tPropertyValueMap aStaticDefaults;
235 // /--
236 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
237 if( 0 == aStaticDefaults.size() )
239 // initialize defaults
240 lcl_AddDefaultsToMap( aStaticDefaults );
243 tPropertyValueMap::const_iterator aFound(
244 aStaticDefaults.find( nHandle ));
246 if( aFound == aStaticDefaults.end())
247 return uno::Any();
249 return (*aFound).second;
250 // \--
253 ::cppu::IPropertyArrayHelper & SAL_CALL BarChartTypeTemplate::getInfoHelper()
255 return lcl_getInfoHelper();
259 // ____ XPropertySet ____
260 Reference< beans::XPropertySetInfo > SAL_CALL
261 BarChartTypeTemplate::getPropertySetInfo()
262 throw (uno::RuntimeException)
264 static Reference< beans::XPropertySetInfo > xInfo;
266 // /--
267 MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
268 if( !xInfo.is())
270 xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo(
271 getInfoHelper());
274 return xInfo;
275 // \--
278 void SAL_CALL BarChartTypeTemplate::applyStyle(
279 const Reference< chart2::XDataSeries >& xSeries,
280 ::sal_Int32 nChartTypeIndex,
281 ::sal_Int32 nSeriesIndex,
282 ::sal_Int32 nSeriesCount )
283 throw (uno::RuntimeException)
285 ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
286 if( getDimension() == 3 )
290 //apply Geometry3D
291 uno::Any aAGeometry3D;
292 this->getFastPropertyValue( aAGeometry3D, PROP_BAR_TEMPLATE_GEOMETRY3D );
293 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "Geometry3D" ), aAGeometry3D );
295 catch( uno::Exception & ex )
297 ASSERT_EXCEPTION( ex );
302 void SAL_CALL BarChartTypeTemplate::resetStyles(
303 const Reference< chart2::XDiagram >& xDiagram )
304 throw (uno::RuntimeException)
306 ChartTypeTemplate::resetStyles( xDiagram );
307 if( getDimension() == 3 )
309 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
310 DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
311 uno::Any aLineStyleAny( uno::makeAny( drawing::LineStyle_NONE ));
312 for( ::std::vector< Reference< chart2::XDataSeries > >::iterator aIt( aSeriesVec.begin());
313 aIt != aSeriesVec.end(); ++aIt )
315 Reference< beans::XPropertyState > xState( *aIt, uno::UNO_QUERY );
316 if( xState.is())
318 xState->setPropertyToDefault( C2U("Geometry3D"));
319 Reference< beans::XPropertySet > xProp( xState, uno::UNO_QUERY );
320 if( xProp.is() &&
321 xProp->getPropertyValue( C2U("BorderStyle")) == aLineStyleAny )
323 xState->setPropertyToDefault( C2U("BorderStyle"));
329 DiagramHelper::setVertical( xDiagram, false );
333 void BarChartTypeTemplate::createCoordinateSystems(
334 const Reference< chart2::XCoordinateSystemContainer > & xCooSysCnt )
336 ChartTypeTemplate::createCoordinateSystems( xCooSysCnt );
338 Reference< chart2::XDiagram > xDiagram( xCooSysCnt, uno::UNO_QUERY );
339 DiagramHelper::setVertical( xDiagram, m_eBarDirection == HORIZONTAL );
342 // ----------------------------------------
344 Sequence< OUString > BarChartTypeTemplate::getSupportedServiceNames_Static()
346 Sequence< OUString > aServices( 2 );
347 aServices[ 0 ] = lcl_aServiceName;
348 aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" );
349 return aServices;
352 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
353 APPHELPER_XSERVICEINFO_IMPL( BarChartTypeTemplate, lcl_aServiceName );
355 IMPLEMENT_FORWARD_XINTERFACE2( BarChartTypeTemplate, ChartTypeTemplate, OPropertySet )
356 IMPLEMENT_FORWARD_XTYPEPROVIDER2( BarChartTypeTemplate, ChartTypeTemplate, OPropertySet )
358 } // namespace chart