1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: BarChartTypeTemplate.cxx,v $
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"
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>
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
;
57 static const OUString
lcl_aServiceName(
58 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.BarChartTypeTemplate" ));
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
;
95 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
96 if( 0 == aPropSeq
.getLength() )
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
);
113 ::cppu::IPropertyArrayHelper
& lcl_getInfoHelper()
115 static ::cppu::OPropertyArrayHelper
aArrayHelper(
116 lcl_GetPropertySequence(),
117 /* bSorted = */ sal_True
);
122 } // anonymous namespace
127 BarChartTypeTemplate::BarChartTypeTemplate(
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
),
141 BarChartTypeTemplate::~BarChartTypeTemplate()
144 sal_Int32
BarChartTypeTemplate::getDimension() const
149 StackMode
BarChartTypeTemplate::getStackMode( sal_Int32
/* nChartTypeIndex */ ) const
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
);
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
&&
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
));
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
);
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
);
229 // ____ OPropertySet ____
230 uno::Any
BarChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle
) const
231 throw(beans::UnknownPropertyException
)
233 static tPropertyValueMap aStaticDefaults
;
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())
249 return (*aFound
).second
;
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
;
267 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
270 xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo(
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 )
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
);
318 xState
->setPropertyToDefault( C2U("Geometry3D"));
319 Reference
< beans::XPropertySet
> xProp( xState
, uno::UNO_QUERY
);
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" );
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
)