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 <com/sun/star/beans/PropertyAttribute.hpp>
26 : #include <com/sun/star/chart2/CurveStyle.hpp>
27 :
28 : using namespace ::com::sun::star;
29 :
30 : using ::rtl::OUString;
31 : using ::com::sun::star::beans::Property;
32 : using ::com::sun::star::uno::Sequence;
33 : using ::com::sun::star::uno::Reference;
34 : using ::com::sun::star::uno::Any;
35 : using ::osl::MutexGuard;
36 :
37 : namespace
38 : {
39 :
40 : enum
41 : {
42 : PROP_LINECHARTTYPE_CURVE_STYLE,
43 : PROP_LINECHARTTYPE_CURVE_RESOLUTION,
44 : PROP_LINECHARTTYPE_SPLINE_ORDER
45 : };
46 :
47 0 : void lcl_AddPropertiesToVector(
48 : ::std::vector< Property > & rOutProperties )
49 : {
50 : rOutProperties.push_back(
51 : Property( C2U( "CurveStyle" ),
52 : PROP_LINECHARTTYPE_CURVE_STYLE,
53 0 : ::getCppuType( reinterpret_cast< const chart2::CurveStyle * >(0)),
54 : beans::PropertyAttribute::BOUND
55 0 : | beans::PropertyAttribute::MAYBEDEFAULT ));
56 :
57 : rOutProperties.push_back(
58 : Property( C2U( "CurveResolution" ),
59 : PROP_LINECHARTTYPE_CURVE_RESOLUTION,
60 0 : ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
61 : beans::PropertyAttribute::BOUND
62 0 : | beans::PropertyAttribute::MAYBEDEFAULT ));
63 : rOutProperties.push_back(
64 : Property( C2U( "SplineOrder" ),
65 : PROP_LINECHARTTYPE_SPLINE_ORDER,
66 0 : ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
67 : beans::PropertyAttribute::BOUND
68 0 : | beans::PropertyAttribute::MAYBEDEFAULT ));
69 0 : }
70 :
71 : struct StaticLineChartTypeDefaults_Initializer
72 : {
73 0 : ::chart::tPropertyValueMap* operator()()
74 : {
75 0 : static ::chart::tPropertyValueMap aStaticDefaults;
76 0 : lcl_AddDefaultsToMap( aStaticDefaults );
77 0 : return &aStaticDefaults;
78 : }
79 : private:
80 0 : void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
81 : {
82 0 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LINECHARTTYPE_CURVE_STYLE, ::chart2::CurveStyle_LINES );
83 0 : ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_LINECHARTTYPE_CURVE_RESOLUTION, 20 );
84 :
85 : // todo: check whether order 3 means polygons of order 3 or 2. (see
86 : // http://www.people.nnov.ru/fractal/Splines/Basis.htm )
87 0 : ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_LINECHARTTYPE_SPLINE_ORDER, 3 );
88 0 : }
89 : };
90 :
91 : struct StaticLineChartTypeDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticLineChartTypeDefaults_Initializer >
92 : {
93 : };
94 :
95 : struct StaticLineChartTypeInfoHelper_Initializer
96 : {
97 0 : ::cppu::OPropertyArrayHelper* operator()()
98 : {
99 0 : static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
100 0 : return &aPropHelper;
101 : }
102 :
103 : private:
104 0 : Sequence< Property > lcl_GetPropertySequence()
105 : {
106 0 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
107 0 : lcl_AddPropertiesToVector( aProperties );
108 :
109 : ::std::sort( aProperties.begin(), aProperties.end(),
110 0 : ::chart::PropertyNameLess() );
111 :
112 0 : return ::chart::ContainerHelper::ContainerToSequence( aProperties );
113 : }
114 :
115 : };
116 :
117 : struct StaticLineChartTypeInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticLineChartTypeInfoHelper_Initializer >
118 : {
119 : };
120 :
121 : struct StaticLineChartTypeInfo_Initializer
122 : {
123 0 : uno::Reference< beans::XPropertySetInfo >* operator()()
124 : {
125 : static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
126 0 : ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticLineChartTypeInfoHelper::get() ) );
127 0 : return &xPropertySetInfo;
128 : }
129 : };
130 :
131 : struct StaticLineChartTypeInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticLineChartTypeInfo_Initializer >
132 : {
133 : };
134 :
135 : } // anonymous namespace
136 :
137 : namespace chart
138 : {
139 :
140 1 : LineChartType::LineChartType(
141 : const uno::Reference< uno::XComponentContext > & xContext ) :
142 1 : ChartType( xContext )
143 : {
144 1 : }
145 :
146 0 : LineChartType::LineChartType( const LineChartType & rOther ) :
147 0 : ChartType( rOther )
148 : {
149 0 : }
150 :
151 2 : LineChartType::~LineChartType()
152 2 : {}
153 :
154 : // ____ XCloneable ____
155 0 : uno::Reference< util::XCloneable > SAL_CALL LineChartType::createClone()
156 : throw (uno::RuntimeException)
157 : {
158 0 : return uno::Reference< util::XCloneable >( new LineChartType( *this ));
159 : }
160 :
161 : // ____ XChartType ____
162 0 : ::rtl::OUString SAL_CALL LineChartType::getChartType()
163 : throw (uno::RuntimeException)
164 : {
165 0 : return CHART2_SERVICE_NAME_CHARTTYPE_LINE;
166 : }
167 :
168 :
169 : // ____ OPropertySet ____
170 0 : uno::Any LineChartType::GetDefaultValue( sal_Int32 nHandle ) const
171 : throw(beans::UnknownPropertyException)
172 : {
173 0 : const tPropertyValueMap& rStaticDefaults = *StaticLineChartTypeDefaults::get();
174 0 : tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
175 0 : if( aFound == rStaticDefaults.end() )
176 0 : return uno::Any();
177 0 : return (*aFound).second;
178 : }
179 :
180 0 : ::cppu::IPropertyArrayHelper & SAL_CALL LineChartType::getInfoHelper()
181 : {
182 0 : return *StaticLineChartTypeInfoHelper::get();
183 : }
184 :
185 : // ____ XPropertySet ____
186 0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL LineChartType::getPropertySetInfo()
187 : throw (uno::RuntimeException)
188 : {
189 0 : return *StaticLineChartTypeInfo::get();
190 : }
191 :
192 1 : uno::Sequence< ::rtl::OUString > LineChartType::getSupportedServiceNames_Static()
193 : {
194 1 : uno::Sequence< ::rtl::OUString > aServices( 3 );
195 1 : aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_LINE;
196 1 : aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartType" );
197 1 : aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
198 1 : return aServices;
199 : }
200 :
201 : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
202 6 : APPHELPER_XSERVICEINFO_IMPL( LineChartType,
203 : C2U( "com.sun.star.comp.chart.LineChartType" ));
204 :
205 : } // namespace chart
206 :
207 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|