1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "BarChartTypeTemplate.hxx"
22 #include "DiagramHelper.hxx"
23 #include "servicenames_charttypes.hxx"
24 #include "ContainerHelper.hxx"
25 #include "DataSeriesHelper.hxx"
26 #include "PropertyHelper.hxx"
27 #include <com/sun/star/beans/PropertyAttribute.hpp>
28 #include <com/sun/star/drawing/LineStyle.hpp>
29 #include <com/sun/star/chart2/DataPointGeometry3D.hpp>
33 using namespace ::com::sun::star
;
35 using ::com::sun::star::uno::Reference
;
36 using ::com::sun::star::uno::Sequence
;
37 using ::com::sun::star::beans::Property
;
38 using ::osl::MutexGuard
;
45 PROP_BAR_TEMPLATE_DIMENSION
,
46 PROP_BAR_TEMPLATE_GEOMETRY3D
49 void lcl_AddPropertiesToVector(
50 ::std::vector
< Property
> & rOutProperties
)
52 rOutProperties
.push_back(
53 Property( "Dimension",
54 PROP_BAR_TEMPLATE_DIMENSION
,
55 cppu::UnoType
<sal_Int32
>::get(),
56 beans::PropertyAttribute::BOUND
57 | beans::PropertyAttribute::MAYBEDEFAULT
));
58 rOutProperties
.push_back(
59 Property( "Geometry3D",
60 PROP_BAR_TEMPLATE_GEOMETRY3D
,
61 cppu::UnoType
<sal_Int32
>::get(),
62 beans::PropertyAttribute::BOUND
63 | beans::PropertyAttribute::MAYBEDEFAULT
));
66 struct StaticBarChartTypeTemplateDefaults_Initializer
68 ::chart::tPropertyValueMap
* operator()()
70 static ::chart::tPropertyValueMap aStaticDefaults
;
71 lcl_AddDefaultsToMap( aStaticDefaults
);
72 return &aStaticDefaults
;
75 static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap
& rOutMap
)
77 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_BAR_TEMPLATE_DIMENSION
, 2 );
78 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_BAR_TEMPLATE_GEOMETRY3D
, ::chart2::DataPointGeometry3D::CUBOID
);
82 struct StaticBarChartTypeTemplateDefaults
: public rtl::StaticAggregate
< ::chart::tPropertyValueMap
, StaticBarChartTypeTemplateDefaults_Initializer
>
86 struct StaticBarChartTypeTemplateInfoHelper_Initializer
88 ::cppu::OPropertyArrayHelper
* operator()()
90 static ::cppu::OPropertyArrayHelper
aPropHelper( lcl_GetPropertySequence() );
95 static Sequence
< Property
> lcl_GetPropertySequence()
97 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
98 lcl_AddPropertiesToVector( aProperties
);
100 ::std::sort( aProperties
.begin(), aProperties
.end(),
101 ::chart::PropertyNameLess() );
103 return ::chart::ContainerHelper::ContainerToSequence( aProperties
);
108 struct StaticBarChartTypeTemplateInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticBarChartTypeTemplateInfoHelper_Initializer
>
112 struct StaticBarChartTypeTemplateInfo_Initializer
114 uno::Reference
< beans::XPropertySetInfo
>* operator()()
116 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
117 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticBarChartTypeTemplateInfoHelper::get() ) );
118 return &xPropertySetInfo
;
122 struct StaticBarChartTypeTemplateInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticBarChartTypeTemplateInfo_Initializer
>
126 } // anonymous namespace
131 BarChartTypeTemplate::BarChartTypeTemplate(
133 uno::XComponentContext
> const & xContext
,
134 const OUString
& rServiceName
,
135 StackMode eStackMode
,
136 BarDirection eDirection
,
137 sal_Int32 nDim
/* = 2 */ ) :
138 ChartTypeTemplate( xContext
, rServiceName
),
139 ::property::OPropertySet( m_aMutex
),
140 m_eStackMode( eStackMode
),
141 m_eBarDirection( eDirection
),
145 BarChartTypeTemplate::~BarChartTypeTemplate()
148 sal_Int32
BarChartTypeTemplate::getDimension() const
153 StackMode
BarChartTypeTemplate::getStackMode( sal_Int32
/* nChartTypeIndex */ ) const
158 bool BarChartTypeTemplate::isSwapXAndY() const
160 return (m_eBarDirection
== HORIZONTAL
);
163 // ____ XChartTypeTemplate ____
164 sal_Bool SAL_CALL
BarChartTypeTemplate::matchesTemplate(
165 const Reference
< chart2::XDiagram
>& xDiagram
,
166 sal_Bool bAdaptProperties
)
167 throw (uno::RuntimeException
, std::exception
)
169 bool bResult
= ChartTypeTemplate::matchesTemplate( xDiagram
, bAdaptProperties
);
175 bool bAmbiguous
= false;
176 bool bVertical
= DiagramHelper::getVertical( xDiagram
, bFound
, bAmbiguous
);
177 if( m_eBarDirection
== HORIZONTAL
)
179 else if( m_eBarDirection
== VERTICAL
)
180 bResult
= !bVertical
;
183 // adapt solid-type of template according to values in series
184 if( bAdaptProperties
&&
186 getDimension() == 3 )
189 bool bGeomFound
= false, bGeomAmbiguous
= false;
190 sal_Int32 aCommonGeom
= DiagramHelper::getGeometry3D( xDiagram
, bGeomFound
, bGeomAmbiguous
);
192 if( !bGeomAmbiguous
)
194 setFastPropertyValue_NoBroadcast(
195 PROP_BAR_TEMPLATE_GEOMETRY3D
, uno::makeAny( aCommonGeom
));
201 Reference
< chart2::XChartType
> BarChartTypeTemplate::getChartTypeForIndex( sal_Int32
/*nChartTypeIndex*/ )
203 Reference
< chart2::XChartType
> xResult
;
207 Reference
< lang::XMultiServiceFactory
> xFact(
208 GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW
);
209 xResult
.set( xFact
->createInstance(
210 CHART2_SERVICE_NAME_CHARTTYPE_COLUMN
), uno::UNO_QUERY_THROW
);
212 catch( const uno::Exception
& ex
)
214 ASSERT_EXCEPTION( ex
);
220 Reference
< chart2::XChartType
> SAL_CALL
BarChartTypeTemplate::getChartTypeForNewSeries(
221 const uno::Sequence
< Reference
< chart2::XChartType
> >& aFormerlyUsedChartTypes
)
222 throw (uno::RuntimeException
, std::exception
)
224 Reference
< chart2::XChartType
> xResult( getChartTypeForIndex( 0 ) );
225 ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes
, xResult
);
229 // ____ OPropertySet ____
230 uno::Any
BarChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle
) const
231 throw(beans::UnknownPropertyException
)
233 const tPropertyValueMap
& rStaticDefaults
= *StaticBarChartTypeTemplateDefaults::get();
234 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
235 if( aFound
== rStaticDefaults
.end() )
237 return (*aFound
).second
;
240 ::cppu::IPropertyArrayHelper
& SAL_CALL
BarChartTypeTemplate::getInfoHelper()
242 return *StaticBarChartTypeTemplateInfoHelper::get();
245 // ____ XPropertySet ____
246 Reference
< beans::XPropertySetInfo
> SAL_CALL
BarChartTypeTemplate::getPropertySetInfo()
247 throw (uno::RuntimeException
, std::exception
)
249 return *StaticBarChartTypeTemplateInfo::get();
252 void SAL_CALL
BarChartTypeTemplate::applyStyle(
253 const Reference
< chart2::XDataSeries
>& xSeries
,
254 ::sal_Int32 nChartTypeIndex
,
255 ::sal_Int32 nSeriesIndex
,
256 ::sal_Int32 nSeriesCount
)
257 throw (uno::RuntimeException
, std::exception
)
259 ChartTypeTemplate::applyStyle( xSeries
, nChartTypeIndex
, nSeriesIndex
, nSeriesCount
);
260 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries
, "BorderStyle", uno::makeAny( drawing::LineStyle_NONE
) );
261 if( getDimension() == 3 )
266 uno::Any aAGeometry3D
;
267 this->getFastPropertyValue( aAGeometry3D
, PROP_BAR_TEMPLATE_GEOMETRY3D
);
268 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries
, "Geometry3D", aAGeometry3D
);
270 catch( const uno::Exception
& ex
)
272 ASSERT_EXCEPTION( ex
);
277 void SAL_CALL
BarChartTypeTemplate::resetStyles(
278 const Reference
< chart2::XDiagram
>& xDiagram
)
279 throw (uno::RuntimeException
, std::exception
)
281 ChartTypeTemplate::resetStyles( xDiagram
);
282 ::std::vector
< Reference
< chart2::XDataSeries
> > aSeriesVec(
283 DiagramHelper::getDataSeriesFromDiagram( xDiagram
));
284 uno::Any
aLineStyleAny( uno::makeAny( drawing::LineStyle_NONE
));
285 for( ::std::vector
< Reference
< chart2::XDataSeries
> >::iterator
aIt( aSeriesVec
.begin());
286 aIt
!= aSeriesVec
.end(); ++aIt
)
288 Reference
< beans::XPropertyState
> xState( *aIt
, uno::UNO_QUERY
);
291 if( getDimension() == 3 )
292 xState
->setPropertyToDefault( "Geometry3D");
293 Reference
< beans::XPropertySet
> xProp( xState
, uno::UNO_QUERY
);
295 xProp
->getPropertyValue( "BorderStyle") == aLineStyleAny
)
297 xState
->setPropertyToDefault( "BorderStyle");
302 DiagramHelper::setVertical( xDiagram
, false );
305 void BarChartTypeTemplate::createCoordinateSystems(
306 const Reference
< chart2::XCoordinateSystemContainer
> & xCooSysCnt
)
308 ChartTypeTemplate::createCoordinateSystems( xCooSysCnt
);
310 Reference
< chart2::XDiagram
> xDiagram( xCooSysCnt
, uno::UNO_QUERY
);
311 DiagramHelper::setVertical( xDiagram
, m_eBarDirection
== HORIZONTAL
);
314 IMPLEMENT_FORWARD_XINTERFACE2( BarChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)
315 IMPLEMENT_FORWARD_XTYPEPROVIDER2( BarChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)
319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */