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 "AreaChartTypeTemplate.hxx"
21 : #include "macros.hxx"
22 : #include "servicenames_charttypes.hxx"
23 : #include "DiagramHelper.hxx"
24 : #include "DataSeriesHelper.hxx"
25 : #include "ContainerHelper.hxx"
26 : #include "PropertyHelper.hxx"
27 : #include <com/sun/star/beans/PropertyAttribute.hpp>
28 : #include <com/sun/star/drawing/LineStyle.hpp>
29 :
30 : #include <algorithm>
31 :
32 : using namespace ::com::sun::star;
33 :
34 : using ::rtl::OUString;
35 : using ::com::sun::star::beans::Property;
36 : using ::com::sun::star::uno::Sequence;
37 : using ::com::sun::star::uno::Reference;
38 : using ::com::sun::star::uno::Any;
39 : using ::osl::MutexGuard;
40 :
41 : namespace
42 : {
43 :
44 2 : static const ::rtl::OUString lcl_aServiceName(
45 : RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.AreaChartTypeTemplate" ));
46 :
47 : enum
48 : {
49 : PROP_AREA_TEMPLATE_DIMENSION
50 : };
51 :
52 0 : void lcl_AddPropertiesToVector(
53 : ::std::vector< Property > & rOutProperties )
54 : {
55 : rOutProperties.push_back(
56 : Property( C2U( "Dimension" ),
57 : PROP_AREA_TEMPLATE_DIMENSION,
58 0 : ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
59 : beans::PropertyAttribute::BOUND
60 0 : | beans::PropertyAttribute::MAYBEDEFAULT ));
61 0 : }
62 :
63 : struct StaticAreaChartTypeTemplateDefaults_Initializer
64 : {
65 0 : ::chart::tPropertyValueMap* operator()()
66 : {
67 0 : static ::chart::tPropertyValueMap aStaticDefaults;
68 0 : lcl_AddDefaultsToMap( aStaticDefaults );
69 0 : return &aStaticDefaults;
70 : }
71 : private:
72 0 : void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
73 : {
74 0 : ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_AREA_TEMPLATE_DIMENSION, 2 );
75 0 : }
76 : };
77 :
78 : struct StaticAreaChartTypeTemplateDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticAreaChartTypeTemplateDefaults_Initializer >
79 : {
80 : };
81 :
82 : struct StaticAreaChartTypeTemplateInfoHelper_Initializer
83 : {
84 0 : ::cppu::OPropertyArrayHelper* operator()()
85 : {
86 0 : static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
87 0 : return &aPropHelper;
88 : }
89 :
90 : private:
91 0 : uno::Sequence< Property > lcl_GetPropertySequence()
92 : {
93 0 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
94 0 : lcl_AddPropertiesToVector( aProperties );
95 :
96 : ::std::sort( aProperties.begin(), aProperties.end(),
97 0 : ::chart::PropertyNameLess() );
98 :
99 0 : return ::chart::ContainerHelper::ContainerToSequence( aProperties );
100 : }
101 :
102 : };
103 :
104 : struct StaticAreaChartTypeTemplateInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticAreaChartTypeTemplateInfoHelper_Initializer >
105 : {
106 : };
107 :
108 : struct StaticAreaChartTypeTemplateInfo_Initializer
109 : {
110 0 : uno::Reference< beans::XPropertySetInfo >* operator()()
111 : {
112 : static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
113 0 : ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticAreaChartTypeTemplateInfoHelper::get() ) );
114 0 : return &xPropertySetInfo;
115 : }
116 : };
117 :
118 : struct StaticAreaChartTypeTemplateInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticAreaChartTypeTemplateInfo_Initializer >
119 : {
120 : };
121 :
122 : } // anonymous namespace
123 :
124 : namespace chart
125 : {
126 :
127 0 : AreaChartTypeTemplate::AreaChartTypeTemplate(
128 : uno::Reference<
129 : uno::XComponentContext > const & xContext,
130 : const ::rtl::OUString & rServiceName,
131 : StackMode eStackMode,
132 : sal_Int32 nDim /* = 2 */ ) :
133 : ChartTypeTemplate( xContext, rServiceName ),
134 : ::property::OPropertySet( m_aMutex ),
135 0 : m_eStackMode( eStackMode )
136 : {
137 0 : setFastPropertyValue_NoBroadcast( PROP_AREA_TEMPLATE_DIMENSION, uno::makeAny( nDim ));
138 0 : }
139 :
140 0 : AreaChartTypeTemplate::~AreaChartTypeTemplate()
141 0 : {}
142 :
143 : // ____ OPropertySet ____
144 0 : uno::Any AreaChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle ) const
145 : throw(beans::UnknownPropertyException)
146 : {
147 0 : const tPropertyValueMap& rStaticDefaults = *StaticAreaChartTypeTemplateDefaults::get();
148 0 : tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
149 0 : if( aFound == rStaticDefaults.end() )
150 0 : return uno::Any();
151 0 : return (*aFound).second;
152 : }
153 :
154 0 : ::cppu::IPropertyArrayHelper & SAL_CALL AreaChartTypeTemplate::getInfoHelper()
155 : {
156 0 : return *StaticAreaChartTypeTemplateInfoHelper::get();
157 : }
158 :
159 : // ____ XPropertySet ____
160 0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL AreaChartTypeTemplate::getPropertySetInfo()
161 : throw (uno::RuntimeException)
162 : {
163 0 : return *StaticAreaChartTypeTemplateInfo::get();
164 : }
165 :
166 0 : sal_Int32 AreaChartTypeTemplate::getDimension() const
167 : {
168 0 : sal_Int32 nDim = 2;
169 : try
170 : {
171 : // note: UNO-methods are never const
172 : const_cast< AreaChartTypeTemplate * >( this )->
173 0 : getFastPropertyValue( PROP_AREA_TEMPLATE_DIMENSION ) >>= nDim;
174 : }
175 0 : catch( const beans::UnknownPropertyException & ex )
176 : {
177 : ASSERT_EXCEPTION( ex );
178 : }
179 :
180 0 : return nDim;
181 : }
182 :
183 0 : StackMode AreaChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
184 : {
185 0 : return m_eStackMode;
186 : }
187 :
188 : // ____ XChartTypeTemplate ____
189 0 : void SAL_CALL AreaChartTypeTemplate::applyStyle(
190 : const Reference< chart2::XDataSeries >& xSeries,
191 : ::sal_Int32 nChartTypeIndex,
192 : ::sal_Int32 nSeriesIndex,
193 : ::sal_Int32 nSeriesCount )
194 : throw (uno::RuntimeException)
195 : {
196 0 : ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
197 0 : DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "BorderStyle" ), uno::makeAny( drawing::LineStyle_NONE ) );
198 0 : }
199 :
200 0 : void SAL_CALL AreaChartTypeTemplate::resetStyles( const Reference< chart2::XDiagram >& xDiagram )
201 : throw (uno::RuntimeException)
202 : {
203 0 : ChartTypeTemplate::resetStyles( xDiagram );
204 : ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
205 0 : DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
206 0 : uno::Any aLineStyleAny( uno::makeAny( drawing::LineStyle_NONE ));
207 0 : for( ::std::vector< Reference< chart2::XDataSeries > >::iterator aIt( aSeriesVec.begin());
208 0 : aIt != aSeriesVec.end(); ++aIt )
209 : {
210 0 : Reference< beans::XPropertyState > xState( *aIt, uno::UNO_QUERY );
211 0 : Reference< beans::XPropertySet > xProp( *aIt, uno::UNO_QUERY );
212 0 : if( xState.is() &&
213 0 : xProp.is() &&
214 0 : xProp->getPropertyValue( C2U("BorderStyle")) == aLineStyleAny )
215 : {
216 0 : xState->setPropertyToDefault( C2U("BorderStyle"));
217 : }
218 0 : }
219 0 : }
220 :
221 0 : Reference< chart2::XChartType > AreaChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
222 : {
223 0 : Reference< chart2::XChartType > xResult;
224 :
225 : try
226 : {
227 : Reference< lang::XMultiServiceFactory > xFact(
228 0 : GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
229 0 : xResult.set( xFact->createInstance(
230 0 : CHART2_SERVICE_NAME_CHARTTYPE_AREA ), uno::UNO_QUERY_THROW );
231 : }
232 0 : catch( const uno::Exception & ex )
233 : {
234 : ASSERT_EXCEPTION( ex );
235 : }
236 :
237 0 : return xResult;
238 : }
239 :
240 0 : Reference< chart2::XChartType > SAL_CALL AreaChartTypeTemplate::getChartTypeForNewSeries(
241 : const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
242 : throw (uno::RuntimeException)
243 : {
244 0 : Reference< chart2::XChartType > xResult( getChartTypeForIndex( 0 ) );
245 0 : ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult );
246 0 : return xResult;
247 : }
248 :
249 :
250 : // ----------------------------------------
251 :
252 0 : uno::Sequence< ::rtl::OUString > AreaChartTypeTemplate::getSupportedServiceNames_Static()
253 : {
254 0 : uno::Sequence< ::rtl::OUString > aServices( 2 );
255 0 : aServices[ 0 ] = lcl_aServiceName;
256 0 : aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" );
257 0 : return aServices;
258 : }
259 :
260 : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
261 0 : APPHELPER_XSERVICEINFO_IMPL( AreaChartTypeTemplate, lcl_aServiceName );
262 :
263 0 : IMPLEMENT_FORWARD_XINTERFACE2( AreaChartTypeTemplate, ChartTypeTemplate, OPropertySet )
264 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( AreaChartTypeTemplate, ChartTypeTemplate, OPropertySet )
265 :
266 6 : } // namespace chart
267 :
268 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|