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 "LineChartTypeTemplate.hxx"
22 #include "DiagramHelper.hxx"
23 #include "servicenames_charttypes.hxx"
24 #include "ContainerHelper.hxx"
25 #include "DataSeriesHelper.hxx"
26 #include "PropertyHelper.hxx"
27 #include <unonames.hxx>
29 #include <com/sun/star/chart2/SymbolStyle.hpp>
30 #include <com/sun/star/chart2/Symbol.hpp>
31 #include <com/sun/star/drawing/LineStyle.hpp>
32 #include <com/sun/star/beans/PropertyAttribute.hpp>
36 using namespace ::com::sun::star
;
38 using ::com::sun::star::uno::Reference
;
39 using ::com::sun::star::uno::Sequence
;
40 using ::com::sun::star::beans::Property
;
41 using ::com::sun::star::uno::Any
;
42 using ::osl::MutexGuard
;
49 PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
,
50 PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
,
51 PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
55 void lcl_AddPropertiesToVector(
56 ::std::vector
< Property
> & rOutProperties
)
58 rOutProperties
.push_back(
59 Property( CHART_UNONAME_CURVE_STYLE
,
60 PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
,
61 cppu::UnoType
<chart2::CurveStyle
>::get(),
62 beans::PropertyAttribute::BOUND
63 | beans::PropertyAttribute::MAYBEDEFAULT
));
64 rOutProperties
.push_back(
65 Property( CHART_UNONAME_CURVE_RESOLUTION
,
66 PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
,
67 cppu::UnoType
<sal_Int32
>::get(),
68 beans::PropertyAttribute::BOUND
69 | beans::PropertyAttribute::MAYBEDEFAULT
));
70 rOutProperties
.push_back(
71 Property( CHART_UNONAME_SPLINE_ORDER
,
72 PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
,
73 cppu::UnoType
<sal_Int32
>::get(),
74 beans::PropertyAttribute::BOUND
75 | beans::PropertyAttribute::MAYBEDEFAULT
));
78 struct StaticLineChartTypeTemplateDefaults_Initializer
80 ::chart::tPropertyValueMap
* operator()()
82 static ::chart::tPropertyValueMap aStaticDefaults
;
83 lcl_AddDefaultsToMap( aStaticDefaults
);
84 return &aStaticDefaults
;
87 static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap
& rOutMap
)
89 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
, chart2::CurveStyle_LINES
);
90 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
, 20 );
92 // todo: check whether order 3 means polygons of order 3 or 2. (see
93 // http://www.people.nnov.ru/fractal/Splines/Basis.htm )
94 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
, 3 );
98 struct StaticLineChartTypeTemplateDefaults
: public rtl::StaticAggregate
< ::chart::tPropertyValueMap
, StaticLineChartTypeTemplateDefaults_Initializer
>
102 struct StaticLineChartTypeTemplateInfoHelper_Initializer
104 ::cppu::OPropertyArrayHelper
* operator()()
106 static ::cppu::OPropertyArrayHelper
aPropHelper( lcl_GetPropertySequence() );
111 static Sequence
< Property
> lcl_GetPropertySequence()
113 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
114 lcl_AddPropertiesToVector( aProperties
);
116 ::std::sort( aProperties
.begin(), aProperties
.end(),
117 ::chart::PropertyNameLess() );
119 return ::chart::ContainerHelper::ContainerToSequence( aProperties
);
124 struct StaticLineChartTypeTemplateInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticLineChartTypeTemplateInfoHelper_Initializer
>
128 struct StaticLineChartTypeTemplateInfo_Initializer
130 uno::Reference
< beans::XPropertySetInfo
>* operator()()
132 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
133 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticLineChartTypeTemplateInfoHelper::get() ) );
134 return &xPropertySetInfo
;
138 struct StaticLineChartTypeTemplateInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticLineChartTypeTemplateInfo_Initializer
>
142 } // anonymous namespace
147 LineChartTypeTemplate::LineChartTypeTemplate(
149 uno::XComponentContext
> const & xContext
,
150 const OUString
& rServiceName
,
151 StackMode eStackMode
,
153 bool bHasLines
/* = true */,
154 sal_Int32 nDim
/* = 2 */ ) :
155 ChartTypeTemplate( xContext
, rServiceName
),
156 ::property::OPropertySet( m_aMutex
),
157 m_eStackMode( eStackMode
),
158 m_bHasSymbols( bSymbols
),
159 m_bHasLines( bHasLines
),
163 m_bHasSymbols
= false;
166 LineChartTypeTemplate::~LineChartTypeTemplate()
168 // ____ OPropertySet ____
169 uno::Any
LineChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle
) const
170 throw(beans::UnknownPropertyException
)
172 const tPropertyValueMap
& rStaticDefaults
= *StaticLineChartTypeTemplateDefaults::get();
173 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
174 if( aFound
== rStaticDefaults
.end() )
176 return (*aFound
).second
;
179 ::cppu::IPropertyArrayHelper
& SAL_CALL
LineChartTypeTemplate::getInfoHelper()
181 return *StaticLineChartTypeTemplateInfoHelper::get();
184 // ____ XPropertySet ____
185 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
LineChartTypeTemplate::getPropertySetInfo()
186 throw (uno::RuntimeException
, std::exception
)
188 return *StaticLineChartTypeTemplateInfo::get();
191 sal_Int32
LineChartTypeTemplate::getDimension() const
196 StackMode
LineChartTypeTemplate::getStackMode( sal_Int32
/* nChartTypeIndex */ ) const
201 // ____ XChartTypeTemplate ____
202 sal_Bool SAL_CALL
LineChartTypeTemplate::matchesTemplate(
203 const uno::Reference
< chart2::XDiagram
>& xDiagram
,
204 sal_Bool bAdaptProperties
)
205 throw (uno::RuntimeException
, std::exception
)
207 bool bResult
= ChartTypeTemplate::matchesTemplate( xDiagram
, bAdaptProperties
);
209 // check symbol-style and line-style
210 // for a template with symbols (or with lines) it is ok, if there is at least one series
211 // with symbols (or with lines)
214 bool bSymbolFound
= false;
215 bool bLineFound
= false;
217 ::std::vector
< Reference
< chart2::XDataSeries
> > aSeriesVec(
218 DiagramHelper::getDataSeriesFromDiagram( xDiagram
));
220 for( ::std::vector
< Reference
< chart2::XDataSeries
> >::const_iterator aIt
=
221 aSeriesVec
.begin(); aIt
!= aSeriesVec
.end(); ++aIt
)
225 chart2::Symbol aSymbProp
;
226 drawing::LineStyle eLineStyle
;
227 Reference
< beans::XPropertySet
> xProp( *aIt
, uno::UNO_QUERY_THROW
);
229 bool bCurrentHasSymbol
= (xProp
->getPropertyValue( "Symbol") >>= aSymbProp
) &&
230 (aSymbProp
.Style
!= chart2::SymbolStyle_NONE
);
232 if( bCurrentHasSymbol
)
235 if( bCurrentHasSymbol
&& (!m_bHasSymbols
) )
241 bool bCurrentHasLine
= (xProp
->getPropertyValue( "LineStyle") >>= eLineStyle
) &&
242 ( eLineStyle
!= drawing::LineStyle_NONE
);
244 if( bCurrentHasLine
)
247 if( bCurrentHasLine
&& (!m_bHasLines
) )
253 catch( const uno::Exception
& ex
)
255 ASSERT_EXCEPTION( ex
);
261 if( !bLineFound
&& m_bHasLines
&& bSymbolFound
)
263 else if( !bSymbolFound
&& m_bHasSymbols
&& bLineFound
)
265 else if( !bLineFound
&& !bSymbolFound
)
266 return m_bHasLines
&& m_bHasSymbols
;
270 // adapt curve style, spline order and resolution
271 if( bResult
&& bAdaptProperties
)
275 uno::Reference
< beans::XPropertySet
> xChartTypeProp(
276 DiagramHelper::getChartTypeByIndex( xDiagram
, 0 ),
277 uno::UNO_QUERY_THROW
);
278 setFastPropertyValue_NoBroadcast( PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
, xChartTypeProp
->getPropertyValue(CHART_UNONAME_CURVE_STYLE
) );
279 setFastPropertyValue_NoBroadcast( PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
, xChartTypeProp
->getPropertyValue(CHART_UNONAME_CURVE_RESOLUTION
) );
280 setFastPropertyValue_NoBroadcast( PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
, xChartTypeProp
->getPropertyValue(CHART_UNONAME_SPLINE_ORDER
) );
282 catch( const uno::Exception
& ex
)
284 ASSERT_EXCEPTION( ex
);
291 Reference
< chart2::XChartType
> LineChartTypeTemplate::getChartTypeForIndex( sal_Int32
/*nChartTypeIndex*/ )
293 Reference
< chart2::XChartType
> xResult
;
297 Reference
< lang::XMultiServiceFactory
> xFact(
298 GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW
);
299 xResult
.set( xFact
->createInstance(
300 CHART2_SERVICE_NAME_CHARTTYPE_LINE
), uno::UNO_QUERY_THROW
);
302 Reference
< beans::XPropertySet
> xCTProp( xResult
, uno::UNO_QUERY
);
305 xCTProp
->setPropertyValue(
306 CHART_UNONAME_CURVE_STYLE
, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
));
307 xCTProp
->setPropertyValue(
308 CHART_UNONAME_CURVE_RESOLUTION
, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
));
309 xCTProp
->setPropertyValue(
310 CHART_UNONAME_SPLINE_ORDER
, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
));
313 catch( const uno::Exception
& ex
)
315 ASSERT_EXCEPTION( ex
);
321 Reference
< chart2::XChartType
> SAL_CALL
LineChartTypeTemplate::getChartTypeForNewSeries(
322 const uno::Sequence
< Reference
< chart2::XChartType
> >& aFormerlyUsedChartTypes
)
323 throw (uno::RuntimeException
, std::exception
)
325 Reference
< chart2::XChartType
> xResult
;
329 Reference
< lang::XMultiServiceFactory
> xFact(
330 GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW
);
331 xResult
.set( xFact
->createInstance(
332 CHART2_SERVICE_NAME_CHARTTYPE_LINE
), uno::UNO_QUERY_THROW
);
334 ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes
, xResult
);
336 Reference
< beans::XPropertySet
> xCTProp( xResult
, uno::UNO_QUERY
);
339 xCTProp
->setPropertyValue(
340 CHART_UNONAME_CURVE_STYLE
, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
));
341 xCTProp
->setPropertyValue(
342 CHART_UNONAME_CURVE_RESOLUTION
, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
));
343 xCTProp
->setPropertyValue(
344 CHART_UNONAME_SPLINE_ORDER
, getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
));
347 catch( const uno::Exception
& ex
)
349 ASSERT_EXCEPTION( ex
);
355 void SAL_CALL
LineChartTypeTemplate::applyStyle(
356 const Reference
< chart2::XDataSeries
>& xSeries
,
357 ::sal_Int32 nChartTypeIndex
,
358 ::sal_Int32 nSeriesIndex
,
359 ::sal_Int32 nSeriesCount
)
360 throw (uno::RuntimeException
, std::exception
)
362 ChartTypeTemplate::applyStyle( xSeries
, nChartTypeIndex
, nSeriesIndex
, nSeriesCount
);
366 Reference
< beans::XPropertySet
> xProp( xSeries
, uno::UNO_QUERY_THROW
);
368 DataSeriesHelper::switchSymbolsOnOrOff( xProp
, m_bHasSymbols
, nSeriesIndex
);
369 DataSeriesHelper::switchLinesOnOrOff( xProp
, m_bHasLines
);
370 DataSeriesHelper::makeLinesThickOrThin( xProp
, m_nDim
==2 );
372 catch( const uno::Exception
& ex
)
374 ASSERT_EXCEPTION( ex
);
378 IMPLEMENT_FORWARD_XINTERFACE2( LineChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)
379 IMPLEMENT_FORWARD_XTYPEPROVIDER2( LineChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)
383 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */