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