1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 #include "LineChartTypeTemplate.hxx"
32 #include "DiagramHelper.hxx"
33 #include "servicenames_charttypes.hxx"
34 #include "ContainerHelper.hxx"
35 #include "DataSeriesHelper.hxx"
36 #include <com/sun/star/chart2/SymbolStyle.hpp>
37 #include <com/sun/star/chart2/Symbol.hpp>
38 #include <com/sun/star/drawing/LineStyle.hpp>
39 #include "PropertyHelper.hxx"
40 #include <com/sun/star/beans/PropertyAttribute.hpp>
44 using namespace ::com::sun::star
;
46 using ::com::sun::star::uno::Reference
;
47 using ::com::sun::star::uno::Sequence
;
48 using ::rtl::OUString
;
49 using ::com::sun::star::beans::Property
;
50 using ::com::sun::star::uno::Reference
;
51 using ::com::sun::star::uno::Any
;
52 using ::osl::MutexGuard
;
57 static const OUString
lcl_aServiceName(
58 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.LineChartTypeTemplate" ));
62 PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
,
63 PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
,
64 PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
68 void lcl_AddPropertiesToVector(
69 ::std::vector
< Property
> & rOutProperties
)
71 rOutProperties
.push_back(
72 Property( C2U( "CurveStyle" ),
73 PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
,
74 ::getCppuType( reinterpret_cast< const chart2::CurveStyle
* >(0)),
75 beans::PropertyAttribute::BOUND
76 | beans::PropertyAttribute::MAYBEDEFAULT
));
77 rOutProperties
.push_back(
78 Property( C2U( "CurveResolution" ),
79 PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
,
80 ::getCppuType( reinterpret_cast< const sal_Int32
* >(0)),
81 beans::PropertyAttribute::BOUND
82 | beans::PropertyAttribute::MAYBEDEFAULT
));
83 rOutProperties
.push_back(
84 Property( C2U( "SplineOrder" ),
85 PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
,
86 ::getCppuType( reinterpret_cast< const sal_Int32
* >(0)),
87 beans::PropertyAttribute::BOUND
88 | beans::PropertyAttribute::MAYBEDEFAULT
));
91 void lcl_AddDefaultsToMap(
92 ::chart::tPropertyValueMap
& rOutMap
)
94 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
, chart2::CurveStyle_LINES
);
95 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
, 20 );
97 // todo: check whether order 3 means polygons of order 3 or 2. (see
98 // http://www.people.nnov.ru/fractal/Splines/Basis.htm )
99 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
, 3 );
102 const Sequence
< Property
> & lcl_GetPropertySequence()
104 static Sequence
< Property
> aPropSeq
;
107 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
108 if( 0 == aPropSeq
.getLength() )
111 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
112 lcl_AddPropertiesToVector( aProperties
);
114 // and sort them for access via bsearch
115 ::std::sort( aProperties
.begin(), aProperties
.end(),
116 ::chart::PropertyNameLess() );
118 // transfer result to static Sequence
119 aPropSeq
= ::chart::ContainerHelper::ContainerToSequence( aProperties
);
125 ::cppu::IPropertyArrayHelper
& lcl_getInfoHelper()
127 static ::cppu::OPropertyArrayHelper
aArrayHelper(
128 lcl_GetPropertySequence(),
129 /* bSorted = */ sal_True
);
134 } // anonymous namespace
139 LineChartTypeTemplate::LineChartTypeTemplate(
141 uno::XComponentContext
> const & xContext
,
142 const ::rtl::OUString
& rServiceName
,
143 StackMode eStackMode
,
145 bool bHasLines
/* = true */,
146 sal_Int32 nDim
/* = 2 */ ) :
147 ChartTypeTemplate( xContext
, rServiceName
),
148 ::property::OPropertySet( m_aMutex
),
149 m_eStackMode( eStackMode
),
150 m_bHasSymbols( bSymbols
),
151 m_bHasLines( bHasLines
),
155 m_bHasSymbols
= false;
158 LineChartTypeTemplate::~LineChartTypeTemplate()
160 // ____ OPropertySet ____
161 uno::Any
LineChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle
) const
162 throw(beans::UnknownPropertyException
)
164 static tPropertyValueMap aStaticDefaults
;
167 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
168 if( 0 == aStaticDefaults
.size() )
170 // initialize defaults
171 lcl_AddDefaultsToMap( aStaticDefaults
);
174 tPropertyValueMap::const_iterator
aFound(
175 aStaticDefaults
.find( nHandle
));
177 if( aFound
== aStaticDefaults
.end())
180 return (*aFound
).second
;
184 ::cppu::IPropertyArrayHelper
& SAL_CALL
LineChartTypeTemplate::getInfoHelper()
186 return lcl_getInfoHelper();
190 // ____ XPropertySet ____
191 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
192 LineChartTypeTemplate::getPropertySetInfo()
193 throw (uno::RuntimeException
)
195 static uno::Reference
< beans::XPropertySetInfo
> xInfo
;
198 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
201 xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo(
209 sal_Int32
LineChartTypeTemplate::getDimension() const
214 StackMode
LineChartTypeTemplate::getStackMode( sal_Int32
/* nChartTypeIndex */ ) const
219 // ____ XChartTypeTemplate ____
220 sal_Bool SAL_CALL
LineChartTypeTemplate::matchesTemplate(
221 const uno::Reference
< chart2::XDiagram
>& xDiagram
,
222 sal_Bool bAdaptProperties
)
223 throw (uno::RuntimeException
)
225 sal_Bool bResult
= ChartTypeTemplate::matchesTemplate( xDiagram
, bAdaptProperties
);
227 // check symbol-style and line-style
228 // for a template with symbols (or with lines) it is ok, if there is at least one series
229 // with symbols (or with lines)
232 bool bSymbolFound
= false;
233 bool bLineFound
= false;
235 ::std::vector
< Reference
< chart2::XDataSeries
> > aSeriesVec(
236 DiagramHelper::getDataSeriesFromDiagram( xDiagram
));
238 for( ::std::vector
< Reference
< chart2::XDataSeries
> >::const_iterator aIt
=
239 aSeriesVec
.begin(); aIt
!= aSeriesVec
.end(); ++aIt
)
243 chart2::Symbol aSymbProp
;
244 drawing::LineStyle eLineStyle
;
245 Reference
< beans::XPropertySet
> xProp( *aIt
, uno::UNO_QUERY_THROW
);
247 bool bCurrentHasSymbol
= (xProp
->getPropertyValue( C2U( "Symbol" )) >>= aSymbProp
) &&
248 (aSymbProp
.Style
!= chart2::SymbolStyle_NONE
);
250 if( bCurrentHasSymbol
)
253 if( bCurrentHasSymbol
&& (!m_bHasSymbols
) )
259 bool bCurrentHasLine
= (xProp
->getPropertyValue( C2U( "LineStyle" )) >>= eLineStyle
) &&
260 ( eLineStyle
!= drawing::LineStyle_NONE
);
262 if( bCurrentHasLine
)
265 if( bCurrentHasLine
&& (!m_bHasLines
) )
271 catch( uno::Exception
& ex
)
273 ASSERT_EXCEPTION( ex
);
279 if( !bLineFound
&& m_bHasLines
&& bSymbolFound
)
281 else if( !bSymbolFound
&& m_bHasSymbols
&& bLineFound
)
283 else if( !bLineFound
&& !bSymbolFound
)
284 return m_bHasLines
&& m_bHasSymbols
;
288 // adapt curve style, spline order and resolution
289 if( bResult
&& bAdaptProperties
)
293 uno::Reference
< beans::XPropertySet
> xChartTypeProp(
294 DiagramHelper::getChartTypeByIndex( xDiagram
, 0 ),
295 uno::UNO_QUERY_THROW
);
296 setFastPropertyValue_NoBroadcast( PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
, xChartTypeProp
->getPropertyValue(C2U("CurveStyle" )) );
297 setFastPropertyValue_NoBroadcast( PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
, xChartTypeProp
->getPropertyValue(C2U("CurveResolution" )) );
298 setFastPropertyValue_NoBroadcast( PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
, xChartTypeProp
->getPropertyValue(C2U("SplineOrder" )) );
300 catch( uno::Exception
& ex
)
302 ASSERT_EXCEPTION( ex
);
309 Reference
< chart2::XChartType
> LineChartTypeTemplate::getChartTypeForIndex( sal_Int32
/*nChartTypeIndex*/ )
311 Reference
< chart2::XChartType
> xResult
;
315 Reference
< lang::XMultiServiceFactory
> xFact(
316 GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW
);
317 xResult
.set( xFact
->createInstance(
318 CHART2_SERVICE_NAME_CHARTTYPE_LINE
), uno::UNO_QUERY_THROW
);
320 Reference
< beans::XPropertySet
> xCTProp( xResult
, uno::UNO_QUERY
);
323 xCTProp
->setPropertyValue(
324 C2U( "CurveStyle" ), getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
));
325 xCTProp
->setPropertyValue(
326 C2U( "CurveResolution" ), getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
));
327 xCTProp
->setPropertyValue(
328 C2U( "SplineOrder" ), getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
));
331 catch( uno::Exception
& ex
)
333 ASSERT_EXCEPTION( ex
);
339 Reference
< chart2::XChartType
> SAL_CALL
LineChartTypeTemplate::getChartTypeForNewSeries(
340 const uno::Sequence
< Reference
< chart2::XChartType
> >& aFormerlyUsedChartTypes
)
341 throw (uno::RuntimeException
)
343 Reference
< chart2::XChartType
> xResult
;
347 Reference
< lang::XMultiServiceFactory
> xFact(
348 GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW
);
349 xResult
.set( xFact
->createInstance(
350 CHART2_SERVICE_NAME_CHARTTYPE_LINE
), uno::UNO_QUERY_THROW
);
352 ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes
, xResult
);
354 Reference
< beans::XPropertySet
> xCTProp( xResult
, uno::UNO_QUERY
);
357 xCTProp
->setPropertyValue(
358 C2U( "CurveStyle" ), getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
));
359 xCTProp
->setPropertyValue(
360 C2U( "CurveResolution" ), getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
));
361 xCTProp
->setPropertyValue(
362 C2U( "SplineOrder" ), getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
));
365 catch( uno::Exception
& ex
)
367 ASSERT_EXCEPTION( ex
);
373 void SAL_CALL
LineChartTypeTemplate::applyStyle(
374 const Reference
< chart2::XDataSeries
>& xSeries
,
375 ::sal_Int32 nChartTypeIndex
,
376 ::sal_Int32 nSeriesIndex
,
377 ::sal_Int32 nSeriesCount
)
378 throw (uno::RuntimeException
)
380 ChartTypeTemplate::applyStyle( xSeries
, nChartTypeIndex
, nSeriesIndex
, nSeriesCount
);
384 Reference
< beans::XPropertySet
> xProp( xSeries
, uno::UNO_QUERY_THROW
);
386 DataSeriesHelper::switchSymbolsOnOrOff( xProp
, m_bHasSymbols
, nSeriesIndex
);
387 DataSeriesHelper::switchLinesOnOrOff( xProp
, m_bHasLines
);
388 DataSeriesHelper::makeLinesThickOrThin( xProp
, m_nDim
==2 );
390 catch( uno::Exception
& ex
)
392 ASSERT_EXCEPTION( ex
);
396 // ----------------------------------------
398 Sequence
< OUString
> LineChartTypeTemplate::getSupportedServiceNames_Static()
400 Sequence
< OUString
> aServices( 2 );
401 aServices
[ 0 ] = lcl_aServiceName
;
402 aServices
[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" );
406 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
407 APPHELPER_XSERVICEINFO_IMPL( LineChartTypeTemplate
, lcl_aServiceName
);
409 IMPLEMENT_FORWARD_XINTERFACE2( LineChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)
410 IMPLEMENT_FORWARD_XTYPEPROVIDER2( LineChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)