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