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 "LineChartType.hxx"
21 #include "PropertyHelper.hxx"
23 #include "servicenames_charttypes.hxx"
24 #include "ContainerHelper.hxx"
25 #include <unonames.hxx>
26 #include <cppuhelper/supportsservice.hxx>
28 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 #include <com/sun/star/chart2/CurveStyle.hpp>
31 using namespace ::com::sun::star
;
33 using ::com::sun::star::beans::Property
;
34 using ::com::sun::star::uno::Sequence
;
35 using ::com::sun::star::uno::Reference
;
36 using ::com::sun::star::uno::Any
;
37 using ::osl::MutexGuard
;
44 PROP_LINECHARTTYPE_CURVE_STYLE
,
45 PROP_LINECHARTTYPE_CURVE_RESOLUTION
,
46 PROP_LINECHARTTYPE_SPLINE_ORDER
49 void lcl_AddPropertiesToVector(
50 ::std::vector
< Property
> & rOutProperties
)
52 rOutProperties
.push_back(
53 Property( CHART_UNONAME_CURVE_STYLE
,
54 PROP_LINECHARTTYPE_CURVE_STYLE
,
55 cppu::UnoType
<chart2::CurveStyle
>::get(),
56 beans::PropertyAttribute::BOUND
57 | beans::PropertyAttribute::MAYBEDEFAULT
));
59 rOutProperties
.push_back(
60 Property( CHART_UNONAME_CURVE_RESOLUTION
,
61 PROP_LINECHARTTYPE_CURVE_RESOLUTION
,
62 cppu::UnoType
<sal_Int32
>::get(),
63 beans::PropertyAttribute::BOUND
64 | beans::PropertyAttribute::MAYBEDEFAULT
));
65 rOutProperties
.push_back(
66 Property( CHART_UNONAME_SPLINE_ORDER
,
67 PROP_LINECHARTTYPE_SPLINE_ORDER
,
68 cppu::UnoType
<sal_Int32
>::get(),
69 beans::PropertyAttribute::BOUND
70 | beans::PropertyAttribute::MAYBEDEFAULT
));
73 struct StaticLineChartTypeDefaults_Initializer
75 ::chart::tPropertyValueMap
* operator()()
77 static ::chart::tPropertyValueMap aStaticDefaults
;
78 lcl_AddDefaultsToMap( aStaticDefaults
);
79 return &aStaticDefaults
;
82 static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap
& rOutMap
)
84 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_LINECHARTTYPE_CURVE_STYLE
, ::chart2::CurveStyle_LINES
);
85 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_LINECHARTTYPE_CURVE_RESOLUTION
, 20 );
87 // todo: check whether order 3 means polygons of order 3 or 2. (see
88 // http://www.people.nnov.ru/fractal/Splines/Basis.htm )
89 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_LINECHARTTYPE_SPLINE_ORDER
, 3 );
93 struct StaticLineChartTypeDefaults
: public rtl::StaticAggregate
< ::chart::tPropertyValueMap
, StaticLineChartTypeDefaults_Initializer
>
97 struct StaticLineChartTypeInfoHelper_Initializer
99 ::cppu::OPropertyArrayHelper
* operator()()
101 static ::cppu::OPropertyArrayHelper
aPropHelper( lcl_GetPropertySequence() );
106 static Sequence
< Property
> lcl_GetPropertySequence()
108 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
109 lcl_AddPropertiesToVector( aProperties
);
111 ::std::sort( aProperties
.begin(), aProperties
.end(),
112 ::chart::PropertyNameLess() );
114 return ::chart::ContainerHelper::ContainerToSequence( aProperties
);
119 struct StaticLineChartTypeInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticLineChartTypeInfoHelper_Initializer
>
123 struct StaticLineChartTypeInfo_Initializer
125 uno::Reference
< beans::XPropertySetInfo
>* operator()()
127 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
128 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticLineChartTypeInfoHelper::get() ) );
129 return &xPropertySetInfo
;
133 struct StaticLineChartTypeInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticLineChartTypeInfo_Initializer
>
137 } // anonymous namespace
142 LineChartType::LineChartType(
143 const uno::Reference
< uno::XComponentContext
> & xContext
) :
144 ChartType( xContext
)
148 LineChartType::LineChartType( const LineChartType
& rOther
) :
153 LineChartType::~LineChartType()
156 // ____ XCloneable ____
157 uno::Reference
< util::XCloneable
> SAL_CALL
LineChartType::createClone()
158 throw (uno::RuntimeException
, std::exception
)
160 return uno::Reference
< util::XCloneable
>( new LineChartType( *this ));
163 // ____ XChartType ____
164 OUString SAL_CALL
LineChartType::getChartType()
165 throw (uno::RuntimeException
, std::exception
)
167 return OUString(CHART2_SERVICE_NAME_CHARTTYPE_LINE
);
170 // ____ OPropertySet ____
171 uno::Any
LineChartType::GetDefaultValue( sal_Int32 nHandle
) const
172 throw(beans::UnknownPropertyException
)
174 const tPropertyValueMap
& rStaticDefaults
= *StaticLineChartTypeDefaults::get();
175 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
176 if( aFound
== rStaticDefaults
.end() )
178 return (*aFound
).second
;
181 ::cppu::IPropertyArrayHelper
& SAL_CALL
LineChartType::getInfoHelper()
183 return *StaticLineChartTypeInfoHelper::get();
186 // ____ XPropertySet ____
187 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
LineChartType::getPropertySetInfo()
188 throw (uno::RuntimeException
, std::exception
)
190 return *StaticLineChartTypeInfo::get();
193 uno::Sequence
< OUString
> LineChartType::getSupportedServiceNames_Static()
195 uno::Sequence
< OUString
> aServices( 3 );
196 aServices
[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_LINE
;
197 aServices
[ 1 ] = "com.sun.star.chart2.ChartType";
198 aServices
[ 2 ] = "com.sun.star.beans.PropertySet";
202 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
203 OUString SAL_CALL
LineChartType::getImplementationName()
204 throw( css::uno::RuntimeException
, std::exception
)
206 return getImplementationName_Static();
209 OUString
LineChartType::getImplementationName_Static()
211 return OUString("com.sun.star.comp.chart.LineChartType");
214 sal_Bool SAL_CALL
LineChartType::supportsService( const OUString
& rServiceName
)
215 throw( css::uno::RuntimeException
, std::exception
)
217 return cppu::supportsService(this, rServiceName
);
220 css::uno::Sequence
< OUString
> SAL_CALL
LineChartType::getSupportedServiceNames()
221 throw( css::uno::RuntimeException
, std::exception
)
223 return getSupportedServiceNames_Static();
228 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
229 com_sun_star_comp_chart_LineChartType_get_implementation(css::uno::XComponentContext
*context
,
230 css::uno::Sequence
<css::uno::Any
> const &)
232 return cppu::acquire(new ::chart::LineChartType(context
));
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */