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: LineChartTypeTemplate.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 "LineChartTypeTemplate.hxx"
35 #include "DiagramHelper.hxx"
36 #include "servicenames_charttypes.hxx"
37 #include "ContainerHelper.hxx"
38 #include "DataSeriesHelper.hxx"
39 #include <com/sun/star/chart2/SymbolStyle.hpp>
40 #include <com/sun/star/chart2/Symbol.hpp>
41 #include <com/sun/star/drawing/LineStyle.hpp>
42 #include "PropertyHelper.hxx"
43 #include <com/sun/star/beans/PropertyAttribute.hpp>
47 using namespace ::com::sun::star
;
49 using ::com::sun::star::uno::Reference
;
50 using ::com::sun::star::uno::Sequence
;
51 using ::rtl::OUString
;
52 using ::com::sun::star::beans::Property
;
53 using ::com::sun::star::uno::Reference
;
54 using ::com::sun::star::uno::Any
;
55 using ::osl::MutexGuard
;
60 static const OUString
lcl_aServiceName(
61 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.LineChartTypeTemplate" ));
65 PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
,
66 PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
,
67 PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
71 void lcl_AddPropertiesToVector(
72 ::std::vector
< Property
> & rOutProperties
)
74 rOutProperties
.push_back(
75 Property( C2U( "CurveStyle" ),
76 PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
,
77 ::getCppuType( reinterpret_cast< const chart2::CurveStyle
* >(0)),
78 beans::PropertyAttribute::BOUND
79 | beans::PropertyAttribute::MAYBEDEFAULT
));
80 rOutProperties
.push_back(
81 Property( C2U( "CurveResolution" ),
82 PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
,
83 ::getCppuType( reinterpret_cast< const sal_Int32
* >(0)),
84 beans::PropertyAttribute::BOUND
85 | beans::PropertyAttribute::MAYBEDEFAULT
));
86 rOutProperties
.push_back(
87 Property( C2U( "SplineOrder" ),
88 PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
,
89 ::getCppuType( reinterpret_cast< const sal_Int32
* >(0)),
90 beans::PropertyAttribute::BOUND
91 | beans::PropertyAttribute::MAYBEDEFAULT
));
94 void lcl_AddDefaultsToMap(
95 ::chart::tPropertyValueMap
& rOutMap
)
97 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
, chart2::CurveStyle_LINES
);
98 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
, 20 );
100 // todo: check whether order 3 means polygons of order 3 or 2. (see
101 // http://www.people.nnov.ru/fractal/Splines/Basis.htm )
102 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
, 3 );
105 const Sequence
< Property
> & lcl_GetPropertySequence()
107 static Sequence
< Property
> aPropSeq
;
110 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
111 if( 0 == aPropSeq
.getLength() )
114 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
115 lcl_AddPropertiesToVector( aProperties
);
117 // and sort them for access via bsearch
118 ::std::sort( aProperties
.begin(), aProperties
.end(),
119 ::chart::PropertyNameLess() );
121 // transfer result to static Sequence
122 aPropSeq
= ::chart::ContainerHelper::ContainerToSequence( aProperties
);
128 ::cppu::IPropertyArrayHelper
& lcl_getInfoHelper()
130 static ::cppu::OPropertyArrayHelper
aArrayHelper(
131 lcl_GetPropertySequence(),
132 /* bSorted = */ sal_True
);
137 } // anonymous namespace
142 LineChartTypeTemplate::LineChartTypeTemplate(
144 uno::XComponentContext
> const & xContext
,
145 const ::rtl::OUString
& rServiceName
,
146 StackMode eStackMode
,
148 bool bHasLines
/* = true */,
149 sal_Int32 nDim
/* = 2 */ ) :
150 ChartTypeTemplate( xContext
, rServiceName
),
151 ::property::OPropertySet( m_aMutex
),
152 m_eStackMode( eStackMode
),
153 m_bHasSymbols( bSymbols
),
154 m_bHasLines( bHasLines
),
158 m_bHasSymbols
= false;
161 LineChartTypeTemplate::~LineChartTypeTemplate()
163 // ____ OPropertySet ____
164 uno::Any
LineChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle
) const
165 throw(beans::UnknownPropertyException
)
167 static tPropertyValueMap aStaticDefaults
;
170 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
171 if( 0 == aStaticDefaults
.size() )
173 // initialize defaults
174 lcl_AddDefaultsToMap( aStaticDefaults
);
177 tPropertyValueMap::const_iterator
aFound(
178 aStaticDefaults
.find( nHandle
));
180 if( aFound
== aStaticDefaults
.end())
183 return (*aFound
).second
;
187 ::cppu::IPropertyArrayHelper
& SAL_CALL
LineChartTypeTemplate::getInfoHelper()
189 return lcl_getInfoHelper();
193 // ____ XPropertySet ____
194 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
195 LineChartTypeTemplate::getPropertySetInfo()
196 throw (uno::RuntimeException
)
198 static uno::Reference
< beans::XPropertySetInfo
> xInfo
;
201 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
204 xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo(
212 sal_Int32
LineChartTypeTemplate::getDimension() const
217 StackMode
LineChartTypeTemplate::getStackMode( sal_Int32
/* nChartTypeIndex */ ) const
222 // ____ XChartTypeTemplate ____
223 sal_Bool SAL_CALL
LineChartTypeTemplate::matchesTemplate(
224 const uno::Reference
< chart2::XDiagram
>& xDiagram
,
225 sal_Bool bAdaptProperties
)
226 throw (uno::RuntimeException
)
228 sal_Bool bResult
= ChartTypeTemplate::matchesTemplate( xDiagram
, bAdaptProperties
);
230 // check symbol-style and line-style
231 // for a template with symbols (or with lines) it is ok, if there is at least one series
232 // with symbols (or with lines)
235 bool bSymbolFound
= false;
236 bool bLineFound
= false;
238 ::std::vector
< Reference
< chart2::XDataSeries
> > aSeriesVec(
239 DiagramHelper::getDataSeriesFromDiagram( xDiagram
));
241 for( ::std::vector
< Reference
< chart2::XDataSeries
> >::const_iterator aIt
=
242 aSeriesVec
.begin(); aIt
!= aSeriesVec
.end(); ++aIt
)
246 chart2::Symbol aSymbProp
;
247 drawing::LineStyle eLineStyle
;
248 Reference
< beans::XPropertySet
> xProp( *aIt
, uno::UNO_QUERY_THROW
);
250 bool bCurrentHasSymbol
= (xProp
->getPropertyValue( C2U( "Symbol" )) >>= aSymbProp
) &&
251 (aSymbProp
.Style
!= chart2::SymbolStyle_NONE
);
253 if( bCurrentHasSymbol
)
256 if( bCurrentHasSymbol
&& (!m_bHasSymbols
) )
262 bool bCurrentHasLine
= (xProp
->getPropertyValue( C2U( "LineStyle" )) >>= eLineStyle
) &&
263 ( eLineStyle
!= drawing::LineStyle_NONE
);
265 if( bCurrentHasLine
)
268 if( bCurrentHasLine
&& (!m_bHasLines
) )
274 catch( uno::Exception
& ex
)
276 ASSERT_EXCEPTION( ex
);
282 if( !bLineFound
&& m_bHasLines
&& bSymbolFound
)
284 else if( !bSymbolFound
&& m_bHasSymbols
&& bLineFound
)
286 else if( !bLineFound
&& !bSymbolFound
)
287 return m_bHasLines
&& m_bHasSymbols
;
291 // adapt curve style, spline order and resolution
292 if( bResult
&& bAdaptProperties
)
296 uno::Reference
< beans::XPropertySet
> xChartTypeProp(
297 DiagramHelper::getChartTypeByIndex( xDiagram
, 0 ),
298 uno::UNO_QUERY_THROW
);
299 setFastPropertyValue_NoBroadcast( PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
, xChartTypeProp
->getPropertyValue(C2U("CurveStyle" )) );
300 setFastPropertyValue_NoBroadcast( PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
, xChartTypeProp
->getPropertyValue(C2U("CurveResolution" )) );
301 setFastPropertyValue_NoBroadcast( PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
, xChartTypeProp
->getPropertyValue(C2U("SplineOrder" )) );
303 catch( uno::Exception
& ex
)
305 ASSERT_EXCEPTION( ex
);
312 Reference
< chart2::XChartType
> LineChartTypeTemplate::getChartTypeForIndex( sal_Int32
/*nChartTypeIndex*/ )
314 Reference
< chart2::XChartType
> xResult
;
318 Reference
< lang::XMultiServiceFactory
> xFact(
319 GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW
);
320 xResult
.set( xFact
->createInstance(
321 CHART2_SERVICE_NAME_CHARTTYPE_LINE
), uno::UNO_QUERY_THROW
);
323 Reference
< beans::XPropertySet
> xCTProp( xResult
, uno::UNO_QUERY
);
326 xCTProp
->setPropertyValue(
327 C2U( "CurveStyle" ), getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
));
328 xCTProp
->setPropertyValue(
329 C2U( "CurveResolution" ), getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
));
330 xCTProp
->setPropertyValue(
331 C2U( "SplineOrder" ), getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
));
334 catch( uno::Exception
& ex
)
336 ASSERT_EXCEPTION( ex
);
342 Reference
< chart2::XChartType
> SAL_CALL
LineChartTypeTemplate::getChartTypeForNewSeries(
343 const uno::Sequence
< Reference
< chart2::XChartType
> >& aFormerlyUsedChartTypes
)
344 throw (uno::RuntimeException
)
346 Reference
< chart2::XChartType
> xResult
;
350 Reference
< lang::XMultiServiceFactory
> xFact(
351 GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW
);
352 xResult
.set( xFact
->createInstance(
353 CHART2_SERVICE_NAME_CHARTTYPE_LINE
), uno::UNO_QUERY_THROW
);
355 ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes
, xResult
);
357 Reference
< beans::XPropertySet
> xCTProp( xResult
, uno::UNO_QUERY
);
360 xCTProp
->setPropertyValue(
361 C2U( "CurveStyle" ), getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE
));
362 xCTProp
->setPropertyValue(
363 C2U( "CurveResolution" ), getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION
));
364 xCTProp
->setPropertyValue(
365 C2U( "SplineOrder" ), getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER
));
368 catch( uno::Exception
& ex
)
370 ASSERT_EXCEPTION( ex
);
376 void SAL_CALL
LineChartTypeTemplate::applyStyle(
377 const Reference
< chart2::XDataSeries
>& xSeries
,
378 ::sal_Int32 nChartTypeIndex
,
379 ::sal_Int32 nSeriesIndex
,
380 ::sal_Int32 nSeriesCount
)
381 throw (uno::RuntimeException
)
383 ChartTypeTemplate::applyStyle( xSeries
, nChartTypeIndex
, nSeriesIndex
, nSeriesCount
);
387 Reference
< beans::XPropertySet
> xProp( xSeries
, uno::UNO_QUERY_THROW
);
389 DataSeriesHelper::switchSymbolsOnOrOff( xProp
, m_bHasSymbols
, nSeriesIndex
);
390 DataSeriesHelper::switchLinesOnOrOff( xProp
, m_bHasLines
);
391 DataSeriesHelper::makeLinesThickOrThin( xProp
, m_nDim
==2 );
393 catch( uno::Exception
& ex
)
395 ASSERT_EXCEPTION( ex
);
399 // ----------------------------------------
401 Sequence
< OUString
> LineChartTypeTemplate::getSupportedServiceNames_Static()
403 Sequence
< OUString
> aServices( 2 );
404 aServices
[ 0 ] = lcl_aServiceName
;
405 aServices
[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" );
409 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
410 APPHELPER_XSERVICEINFO_IMPL( LineChartTypeTemplate
, lcl_aServiceName
);
412 IMPLEMENT_FORWARD_XINTERFACE2( LineChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)
413 IMPLEMENT_FORWARD_XTYPEPROVIDER2( LineChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)