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