1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 #include "LineChartType.hxx"
27 #include "PropertyHelper.hxx"
28 #include "macros.hxx"
29 #include "servicenames_charttypes.hxx"
30 #include "ContainerHelper.hxx"
31 #include <com/sun/star/beans/PropertyAttribute.hpp>
32 #include <com/sun/star/chart2/CurveStyle.hpp>
33 
34 using namespace ::com::sun::star;
35 
36 using ::rtl::OUString;
37 using ::com::sun::star::beans::Property;
38 using ::com::sun::star::uno::Sequence;
39 using ::com::sun::star::uno::Reference;
40 using ::com::sun::star::uno::Any;
41 using ::osl::MutexGuard;
42 
43 namespace
44 {
45 
46 enum
47 {
48     PROP_LINECHARTTYPE_CURVE_STYLE,
49     PROP_LINECHARTTYPE_CURVE_RESOLUTION,
50     PROP_LINECHARTTYPE_SPLINE_ORDER
51 };
52 
lcl_AddPropertiesToVector(::std::vector<Property> & rOutProperties)53 void lcl_AddPropertiesToVector(
54     ::std::vector< Property > & rOutProperties )
55 {
56     rOutProperties.push_back(
57         Property( C2U( "CurveStyle" ),
58                   PROP_LINECHARTTYPE_CURVE_STYLE,
59                   ::getCppuType( reinterpret_cast< const chart2::CurveStyle * >(0)),
60                   beans::PropertyAttribute::BOUND
61                   | beans::PropertyAttribute::MAYBEDEFAULT ));
62 
63     rOutProperties.push_back(
64         Property( C2U( "CurveResolution" ),
65                   PROP_LINECHARTTYPE_CURVE_RESOLUTION,
66                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
67                   beans::PropertyAttribute::BOUND
68                   | beans::PropertyAttribute::MAYBEDEFAULT ));
69     rOutProperties.push_back(
70         Property( C2U( "SplineOrder" ),
71                   PROP_LINECHARTTYPE_SPLINE_ORDER,
72                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
73                   beans::PropertyAttribute::BOUND
74                   | beans::PropertyAttribute::MAYBEDEFAULT ));
75 }
76 
77 struct StaticLineChartTypeDefaults_Initializer
78 {
operator ()__anonf3bac87a0111::StaticLineChartTypeDefaults_Initializer79     ::chart::tPropertyValueMap* operator()()
80     {
81         static ::chart::tPropertyValueMap aStaticDefaults;
82         lcl_AddDefaultsToMap( aStaticDefaults );
83         return &aStaticDefaults;
84     }
85 private:
lcl_AddDefaultsToMap__anonf3bac87a0111::StaticLineChartTypeDefaults_Initializer86     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
87     {
88         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LINECHARTTYPE_CURVE_STYLE, ::chart2::CurveStyle_LINES );
89         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_LINECHARTTYPE_CURVE_RESOLUTION, 20 );
90 
91         // todo: check whether order 3 means polygons of order 3 or 2. (see
92         // http://www.people.nnov.ru/fractal/Splines/Basis.htm )
93         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_LINECHARTTYPE_SPLINE_ORDER, 3 );
94     }
95 };
96 
97 struct StaticLineChartTypeDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticLineChartTypeDefaults_Initializer >
98 {
99 };
100 
101 struct StaticLineChartTypeInfoHelper_Initializer
102 {
operator ()__anonf3bac87a0111::StaticLineChartTypeInfoHelper_Initializer103     ::cppu::OPropertyArrayHelper* operator()()
104     {
105         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
106         return &aPropHelper;
107     }
108 
109 private:
lcl_GetPropertySequence__anonf3bac87a0111::StaticLineChartTypeInfoHelper_Initializer110     Sequence< Property > lcl_GetPropertySequence()
111     {
112         ::std::vector< ::com::sun::star::beans::Property > aProperties;
113         lcl_AddPropertiesToVector( aProperties );
114 
115         ::std::sort( aProperties.begin(), aProperties.end(),
116                      ::chart::PropertyNameLess() );
117 
118         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
119     }
120 
121 };
122 
123 struct StaticLineChartTypeInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticLineChartTypeInfoHelper_Initializer >
124 {
125 };
126 
127 struct StaticLineChartTypeInfo_Initializer
128 {
operator ()__anonf3bac87a0111::StaticLineChartTypeInfo_Initializer129     uno::Reference< beans::XPropertySetInfo >* operator()()
130     {
131         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
132             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticLineChartTypeInfoHelper::get() ) );
133         return &xPropertySetInfo;
134     }
135 };
136 
137 struct StaticLineChartTypeInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticLineChartTypeInfo_Initializer >
138 {
139 };
140 
141 } // anonymous namespace
142 
143 namespace chart
144 {
145 
LineChartType(const uno::Reference<uno::XComponentContext> & xContext)146 LineChartType::LineChartType(
147     const uno::Reference< uno::XComponentContext > & xContext ) :
148         ChartType( xContext )
149 {
150 }
151 
LineChartType(const LineChartType & rOther)152 LineChartType::LineChartType( const LineChartType & rOther ) :
153         ChartType( rOther )
154 {
155 }
156 
~LineChartType()157 LineChartType::~LineChartType()
158 {}
159 
160 // ____ XCloneable ____
createClone()161 uno::Reference< util::XCloneable > SAL_CALL LineChartType::createClone()
162     throw (uno::RuntimeException)
163 {
164     return uno::Reference< util::XCloneable >( new LineChartType( *this ));
165 }
166 
167 // ____ XChartType ____
getChartType()168 ::rtl::OUString SAL_CALL LineChartType::getChartType()
169     throw (uno::RuntimeException)
170 {
171     return CHART2_SERVICE_NAME_CHARTTYPE_LINE;
172 }
173 
174 
175 // ____ OPropertySet ____
GetDefaultValue(sal_Int32 nHandle) const176 uno::Any LineChartType::GetDefaultValue( sal_Int32 nHandle ) const
177     throw(beans::UnknownPropertyException)
178 {
179     const tPropertyValueMap& rStaticDefaults = *StaticLineChartTypeDefaults::get();
180     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
181     if( aFound == rStaticDefaults.end() )
182         return uno::Any();
183     return (*aFound).second;
184 }
185 
getInfoHelper()186 ::cppu::IPropertyArrayHelper & SAL_CALL LineChartType::getInfoHelper()
187 {
188     return *StaticLineChartTypeInfoHelper::get();
189 }
190 
191 // ____ XPropertySet ____
getPropertySetInfo()192 uno::Reference< beans::XPropertySetInfo > SAL_CALL LineChartType::getPropertySetInfo()
193     throw (uno::RuntimeException)
194 {
195     return *StaticLineChartTypeInfo::get();
196 }
197 
getSupportedServiceNames_Static()198 uno::Sequence< ::rtl::OUString > LineChartType::getSupportedServiceNames_Static()
199 {
200     uno::Sequence< ::rtl::OUString > aServices( 3 );
201     aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_LINE;
202     aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartType" );
203     aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
204     return aServices;
205 }
206 
207 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
208 APPHELPER_XSERVICEINFO_IMPL( LineChartType,
209                              C2U( "com.sun.star.comp.chart.LineChartType" ));
210 
211 } //  namespace chart
212