Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "LineChartType.hxx"
21 : #include "PropertyHelper.hxx"
22 : #include "macros.hxx"
23 : #include "servicenames_charttypes.hxx"
24 : #include "ContainerHelper.hxx"
25 : #include <unonames.hxx>
26 : #include <cppuhelper/supportsservice.hxx>
27 :
28 : #include <com/sun/star/beans/PropertyAttribute.hpp>
29 : #include <com/sun/star/chart2/CurveStyle.hpp>
30 :
31 : using namespace ::com::sun::star;
32 :
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;
38 :
39 : namespace
40 : {
41 :
42 : enum
43 : {
44 : PROP_LINECHARTTYPE_CURVE_STYLE,
45 : PROP_LINECHARTTYPE_CURVE_RESOLUTION,
46 : PROP_LINECHARTTYPE_SPLINE_ORDER
47 : };
48 :
49 7 : void lcl_AddPropertiesToVector(
50 : ::std::vector< Property > & rOutProperties )
51 : {
52 : rOutProperties.push_back(
53 : Property( CHART_UNONAME_CURVE_STYLE,
54 : PROP_LINECHARTTYPE_CURVE_STYLE,
55 7 : cppu::UnoType<chart2::CurveStyle>::get(),
56 : beans::PropertyAttribute::BOUND
57 14 : | beans::PropertyAttribute::MAYBEDEFAULT ));
58 :
59 : rOutProperties.push_back(
60 : Property( CHART_UNONAME_CURVE_RESOLUTION,
61 : PROP_LINECHARTTYPE_CURVE_RESOLUTION,
62 7 : cppu::UnoType<sal_Int32>::get(),
63 : beans::PropertyAttribute::BOUND
64 14 : | beans::PropertyAttribute::MAYBEDEFAULT ));
65 : rOutProperties.push_back(
66 : Property( CHART_UNONAME_SPLINE_ORDER,
67 : PROP_LINECHARTTYPE_SPLINE_ORDER,
68 7 : cppu::UnoType<sal_Int32>::get(),
69 : beans::PropertyAttribute::BOUND
70 14 : | beans::PropertyAttribute::MAYBEDEFAULT ));
71 7 : }
72 :
73 : struct StaticLineChartTypeDefaults_Initializer
74 : {
75 7 : ::chart::tPropertyValueMap* operator()()
76 : {
77 7 : static ::chart::tPropertyValueMap aStaticDefaults;
78 7 : lcl_AddDefaultsToMap( aStaticDefaults );
79 7 : return &aStaticDefaults;
80 : }
81 : private:
82 7 : static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
83 : {
84 7 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LINECHARTTYPE_CURVE_STYLE, ::chart2::CurveStyle_LINES );
85 7 : ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_LINECHARTTYPE_CURVE_RESOLUTION, 20 );
86 :
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 7 : ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_LINECHARTTYPE_SPLINE_ORDER, 3 );
90 7 : }
91 : };
92 :
93 : struct StaticLineChartTypeDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticLineChartTypeDefaults_Initializer >
94 : {
95 : };
96 :
97 : struct StaticLineChartTypeInfoHelper_Initializer
98 : {
99 7 : ::cppu::OPropertyArrayHelper* operator()()
100 : {
101 7 : static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
102 7 : return &aPropHelper;
103 : }
104 :
105 : private:
106 7 : static Sequence< Property > lcl_GetPropertySequence()
107 : {
108 7 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
109 7 : lcl_AddPropertiesToVector( aProperties );
110 :
111 : ::std::sort( aProperties.begin(), aProperties.end(),
112 7 : ::chart::PropertyNameLess() );
113 :
114 7 : return ::chart::ContainerHelper::ContainerToSequence( aProperties );
115 : }
116 :
117 : };
118 :
119 : struct StaticLineChartTypeInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticLineChartTypeInfoHelper_Initializer >
120 : {
121 : };
122 :
123 : struct StaticLineChartTypeInfo_Initializer
124 : {
125 2 : uno::Reference< beans::XPropertySetInfo >* operator()()
126 : {
127 : static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
128 2 : ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticLineChartTypeInfoHelper::get() ) );
129 2 : return &xPropertySetInfo;
130 : }
131 : };
132 :
133 : struct StaticLineChartTypeInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticLineChartTypeInfo_Initializer >
134 : {
135 : };
136 :
137 : } // anonymous namespace
138 :
139 : namespace chart
140 : {
141 :
142 14286 : LineChartType::LineChartType(
143 : const uno::Reference< uno::XComponentContext > & xContext ) :
144 14286 : ChartType( xContext )
145 : {
146 14286 : }
147 :
148 0 : LineChartType::LineChartType( const LineChartType & rOther ) :
149 0 : ChartType( rOther )
150 : {
151 0 : }
152 :
153 28570 : LineChartType::~LineChartType()
154 28570 : {}
155 :
156 : // ____ XCloneable ____
157 0 : uno::Reference< util::XCloneable > SAL_CALL LineChartType::createClone()
158 : throw (uno::RuntimeException, std::exception)
159 : {
160 0 : return uno::Reference< util::XCloneable >( new LineChartType( *this ));
161 : }
162 :
163 : // ____ XChartType ____
164 36562 : OUString SAL_CALL LineChartType::getChartType()
165 : throw (uno::RuntimeException, std::exception)
166 : {
167 36562 : return OUString(CHART2_SERVICE_NAME_CHARTTYPE_LINE);
168 : }
169 :
170 : // ____ OPropertySet ____
171 43645 : uno::Any LineChartType::GetDefaultValue( sal_Int32 nHandle ) const
172 : throw(beans::UnknownPropertyException)
173 : {
174 43645 : const tPropertyValueMap& rStaticDefaults = *StaticLineChartTypeDefaults::get();
175 43645 : tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
176 43645 : if( aFound == rStaticDefaults.end() )
177 0 : return uno::Any();
178 43645 : return (*aFound).second;
179 : }
180 :
181 87519 : ::cppu::IPropertyArrayHelper & SAL_CALL LineChartType::getInfoHelper()
182 : {
183 87519 : return *StaticLineChartTypeInfoHelper::get();
184 : }
185 :
186 : // ____ XPropertySet ____
187 29 : uno::Reference< beans::XPropertySetInfo > SAL_CALL LineChartType::getPropertySetInfo()
188 : throw (uno::RuntimeException, std::exception)
189 : {
190 29 : return *StaticLineChartTypeInfo::get();
191 : }
192 :
193 1 : uno::Sequence< OUString > LineChartType::getSupportedServiceNames_Static()
194 : {
195 1 : uno::Sequence< OUString > aServices( 3 );
196 1 : aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_LINE;
197 1 : aServices[ 1 ] = "com.sun.star.chart2.ChartType";
198 1 : aServices[ 2 ] = "com.sun.star.beans.PropertySet";
199 1 : return aServices;
200 : }
201 :
202 : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
203 1 : OUString SAL_CALL LineChartType::getImplementationName()
204 : throw( css::uno::RuntimeException, std::exception )
205 : {
206 1 : return getImplementationName_Static();
207 : }
208 :
209 1 : OUString LineChartType::getImplementationName_Static()
210 : {
211 1 : return OUString("com.sun.star.comp.chart.LineChartType");
212 : }
213 :
214 0 : sal_Bool SAL_CALL LineChartType::supportsService( const OUString& rServiceName )
215 : throw( css::uno::RuntimeException, std::exception )
216 : {
217 0 : return cppu::supportsService(this, rServiceName);
218 : }
219 :
220 1 : css::uno::Sequence< OUString > SAL_CALL LineChartType::getSupportedServiceNames()
221 : throw( css::uno::RuntimeException, std::exception )
222 : {
223 1 : return getSupportedServiceNames_Static();
224 : }
225 :
226 : } // namespace chart
227 :
228 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
229 14286 : com_sun_star_comp_chart_LineChartType_get_implementation(css::uno::XComponentContext *context,
230 : css::uno::Sequence<css::uno::Any> const &)
231 : {
232 14286 : return cppu::acquire(new ::chart::LineChartType(context));
233 : }
234 :
235 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|