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 "BarChartTypeTemplate.hxx"
21 : #include "macros.hxx"
22 : #include "DiagramHelper.hxx"
23 : #include "servicenames_charttypes.hxx"
24 : #include "ContainerHelper.hxx"
25 : #include "DataSeriesHelper.hxx"
26 : #include "PropertyHelper.hxx"
27 : #include <com/sun/star/beans/PropertyAttribute.hpp>
28 : #include <com/sun/star/drawing/LineStyle.hpp>
29 : #include <com/sun/star/chart2/DataPointGeometry3D.hpp>
30 :
31 : #include <algorithm>
32 :
33 : using namespace ::com::sun::star;
34 :
35 : using ::com::sun::star::uno::Reference;
36 : using ::com::sun::star::uno::Sequence;
37 : using ::com::sun::star::beans::Property;
38 : using ::osl::MutexGuard;
39 : using ::rtl::OUString;
40 :
41 : namespace
42 : {
43 :
44 2 : static const OUString lcl_aServiceName(
45 : RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.BarChartTypeTemplate" ));
46 :
47 : enum
48 : {
49 : PROP_BAR_TEMPLATE_DIMENSION,
50 : PROP_BAR_TEMPLATE_GEOMETRY3D
51 : };
52 :
53 0 : void lcl_AddPropertiesToVector(
54 : ::std::vector< Property > & rOutProperties )
55 : {
56 : rOutProperties.push_back(
57 : Property( C2U( "Dimension" ),
58 : PROP_BAR_TEMPLATE_DIMENSION,
59 0 : ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
60 : beans::PropertyAttribute::BOUND
61 0 : | beans::PropertyAttribute::MAYBEDEFAULT ));
62 : rOutProperties.push_back(
63 : Property( C2U( "Geometry3D" ),
64 : PROP_BAR_TEMPLATE_GEOMETRY3D,
65 0 : ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
66 : beans::PropertyAttribute::BOUND
67 0 : | beans::PropertyAttribute::MAYBEDEFAULT ));
68 0 : }
69 :
70 : struct StaticBarChartTypeTemplateDefaults_Initializer
71 : {
72 0 : ::chart::tPropertyValueMap* operator()()
73 : {
74 0 : static ::chart::tPropertyValueMap aStaticDefaults;
75 0 : lcl_AddDefaultsToMap( aStaticDefaults );
76 0 : return &aStaticDefaults;
77 : }
78 : private:
79 0 : void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
80 : {
81 0 : ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_BAR_TEMPLATE_DIMENSION, 2 );
82 0 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_BAR_TEMPLATE_GEOMETRY3D, ::chart2::DataPointGeometry3D::CUBOID );
83 0 : }
84 : };
85 :
86 : struct StaticBarChartTypeTemplateDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticBarChartTypeTemplateDefaults_Initializer >
87 : {
88 : };
89 :
90 : struct StaticBarChartTypeTemplateInfoHelper_Initializer
91 : {
92 0 : ::cppu::OPropertyArrayHelper* operator()()
93 : {
94 0 : static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
95 0 : return &aPropHelper;
96 : }
97 :
98 : private:
99 0 : Sequence< Property > lcl_GetPropertySequence()
100 : {
101 0 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
102 0 : lcl_AddPropertiesToVector( aProperties );
103 :
104 : ::std::sort( aProperties.begin(), aProperties.end(),
105 0 : ::chart::PropertyNameLess() );
106 :
107 0 : return ::chart::ContainerHelper::ContainerToSequence( aProperties );
108 : }
109 :
110 : };
111 :
112 : struct StaticBarChartTypeTemplateInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticBarChartTypeTemplateInfoHelper_Initializer >
113 : {
114 : };
115 :
116 : struct StaticBarChartTypeTemplateInfo_Initializer
117 : {
118 0 : uno::Reference< beans::XPropertySetInfo >* operator()()
119 : {
120 : static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
121 0 : ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticBarChartTypeTemplateInfoHelper::get() ) );
122 0 : return &xPropertySetInfo;
123 : }
124 : };
125 :
126 : struct StaticBarChartTypeTemplateInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticBarChartTypeTemplateInfo_Initializer >
127 : {
128 : };
129 :
130 : } // anonymous namespace
131 :
132 : namespace chart
133 : {
134 :
135 82 : BarChartTypeTemplate::BarChartTypeTemplate(
136 : Reference<
137 : uno::XComponentContext > const & xContext,
138 : const OUString & rServiceName,
139 : StackMode eStackMode,
140 : BarDirection eDirection,
141 : sal_Int32 nDim /* = 2 */ ) :
142 : ChartTypeTemplate( xContext, rServiceName ),
143 : ::property::OPropertySet( m_aMutex ),
144 : m_eStackMode( eStackMode ),
145 : m_eBarDirection( eDirection ),
146 82 : m_nDim( nDim )
147 82 : {}
148 :
149 164 : BarChartTypeTemplate::~BarChartTypeTemplate()
150 164 : {}
151 :
152 738 : sal_Int32 BarChartTypeTemplate::getDimension() const
153 : {
154 738 : return m_nDim;
155 : }
156 :
157 492 : StackMode BarChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
158 : {
159 492 : return m_eStackMode;
160 : }
161 :
162 246 : bool BarChartTypeTemplate::isSwapXAndY() const
163 : {
164 246 : return (m_eBarDirection == HORIZONTAL);
165 : }
166 :
167 : // ____ XChartTypeTemplate ____
168 0 : sal_Bool SAL_CALL BarChartTypeTemplate::matchesTemplate(
169 : const Reference< chart2::XDiagram >& xDiagram,
170 : sal_Bool bAdaptProperties )
171 : throw (uno::RuntimeException)
172 : {
173 0 : sal_Bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties );
174 :
175 : //check BarDirection
176 0 : if( bResult )
177 : {
178 0 : bool bFound = false;
179 0 : bool bAmbiguous = false;
180 0 : bool bVertical = DiagramHelper::getVertical( xDiagram, bFound, bAmbiguous );
181 0 : if( m_eBarDirection == HORIZONTAL )
182 0 : bResult = sal_Bool( bVertical );
183 0 : else if( m_eBarDirection == VERTICAL )
184 0 : bResult = sal_Bool( !bVertical );
185 : }
186 :
187 : // adapt solid-type of template according to values in series
188 0 : if( bAdaptProperties &&
189 : bResult &&
190 0 : getDimension() == 3 )
191 : {
192 : ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
193 0 : DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
194 :
195 0 : bool bGeomFound = false, bGeomAmbiguous = false;
196 0 : sal_Int32 aCommonGeom = DiagramHelper::getGeometry3D( xDiagram, bGeomFound, bGeomAmbiguous );
197 :
198 0 : if( !bGeomAmbiguous )
199 : {
200 : setFastPropertyValue_NoBroadcast(
201 0 : PROP_BAR_TEMPLATE_GEOMETRY3D, uno::makeAny( aCommonGeom ));
202 0 : }
203 : }
204 :
205 0 : return bResult;
206 : }
207 574 : Reference< chart2::XChartType > BarChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
208 : {
209 574 : Reference< chart2::XChartType > xResult;
210 :
211 : try
212 : {
213 : Reference< lang::XMultiServiceFactory > xFact(
214 574 : GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
215 574 : xResult.set( xFact->createInstance(
216 574 : CHART2_SERVICE_NAME_CHARTTYPE_COLUMN ), uno::UNO_QUERY_THROW );
217 : }
218 0 : catch( const uno::Exception & ex )
219 : {
220 : ASSERT_EXCEPTION( ex );
221 : }
222 :
223 574 : return xResult;
224 : }
225 :
226 246 : Reference< chart2::XChartType > SAL_CALL BarChartTypeTemplate::getChartTypeForNewSeries(
227 : const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
228 : throw (uno::RuntimeException)
229 : {
230 246 : Reference< chart2::XChartType > xResult( getChartTypeForIndex( 0 ) );
231 246 : ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult );
232 246 : return xResult;
233 : }
234 :
235 :
236 : // ____ OPropertySet ____
237 0 : uno::Any BarChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle ) const
238 : throw(beans::UnknownPropertyException)
239 : {
240 0 : const tPropertyValueMap& rStaticDefaults = *StaticBarChartTypeTemplateDefaults::get();
241 0 : tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
242 0 : if( aFound == rStaticDefaults.end() )
243 0 : return uno::Any();
244 0 : return (*aFound).second;
245 : }
246 :
247 0 : ::cppu::IPropertyArrayHelper & SAL_CALL BarChartTypeTemplate::getInfoHelper()
248 : {
249 0 : return *StaticBarChartTypeTemplateInfoHelper::get();
250 : }
251 :
252 : // ____ XPropertySet ____
253 0 : Reference< beans::XPropertySetInfo > SAL_CALL BarChartTypeTemplate::getPropertySetInfo()
254 : throw (uno::RuntimeException)
255 : {
256 0 : return *StaticBarChartTypeTemplateInfo::get();
257 : }
258 :
259 246 : void SAL_CALL BarChartTypeTemplate::applyStyle(
260 : const Reference< chart2::XDataSeries >& xSeries,
261 : ::sal_Int32 nChartTypeIndex,
262 : ::sal_Int32 nSeriesIndex,
263 : ::sal_Int32 nSeriesCount )
264 : throw (uno::RuntimeException)
265 : {
266 246 : ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
267 246 : DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "BorderStyle" ), uno::makeAny( drawing::LineStyle_NONE ) );
268 246 : if( getDimension() == 3 )
269 : {
270 : try
271 : {
272 : //apply Geometry3D
273 0 : uno::Any aAGeometry3D;
274 0 : this->getFastPropertyValue( aAGeometry3D, PROP_BAR_TEMPLATE_GEOMETRY3D );
275 0 : DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "Geometry3D" ), aAGeometry3D );
276 : }
277 0 : catch( const uno::Exception & ex )
278 : {
279 : ASSERT_EXCEPTION( ex );
280 : }
281 : }
282 246 : }
283 :
284 0 : void SAL_CALL BarChartTypeTemplate::resetStyles(
285 : const Reference< chart2::XDiagram >& xDiagram )
286 : throw (uno::RuntimeException)
287 : {
288 0 : ChartTypeTemplate::resetStyles( xDiagram );
289 : ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
290 0 : DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
291 0 : uno::Any aLineStyleAny( uno::makeAny( drawing::LineStyle_NONE ));
292 0 : for( ::std::vector< Reference< chart2::XDataSeries > >::iterator aIt( aSeriesVec.begin());
293 0 : aIt != aSeriesVec.end(); ++aIt )
294 : {
295 0 : Reference< beans::XPropertyState > xState( *aIt, uno::UNO_QUERY );
296 0 : if( xState.is())
297 : {
298 0 : if( getDimension() == 3 )
299 0 : xState->setPropertyToDefault( C2U("Geometry3D"));
300 0 : Reference< beans::XPropertySet > xProp( xState, uno::UNO_QUERY );
301 0 : if( xProp.is() &&
302 0 : xProp->getPropertyValue( C2U("BorderStyle")) == aLineStyleAny )
303 : {
304 0 : xState->setPropertyToDefault( C2U("BorderStyle"));
305 0 : }
306 : }
307 0 : }
308 :
309 0 : DiagramHelper::setVertical( xDiagram, false );
310 0 : }
311 :
312 :
313 82 : void BarChartTypeTemplate::createCoordinateSystems(
314 : const Reference< chart2::XCoordinateSystemContainer > & xCooSysCnt )
315 : {
316 82 : ChartTypeTemplate::createCoordinateSystems( xCooSysCnt );
317 :
318 82 : Reference< chart2::XDiagram > xDiagram( xCooSysCnt, uno::UNO_QUERY );
319 82 : DiagramHelper::setVertical( xDiagram, m_eBarDirection == HORIZONTAL );
320 82 : }
321 :
322 : // ----------------------------------------
323 :
324 0 : Sequence< OUString > BarChartTypeTemplate::getSupportedServiceNames_Static()
325 : {
326 0 : Sequence< OUString > aServices( 2 );
327 0 : aServices[ 0 ] = lcl_aServiceName;
328 0 : aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" );
329 0 : return aServices;
330 : }
331 :
332 : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
333 0 : APPHELPER_XSERVICEINFO_IMPL( BarChartTypeTemplate, lcl_aServiceName );
334 :
335 656 : IMPLEMENT_FORWARD_XINTERFACE2( BarChartTypeTemplate, ChartTypeTemplate, OPropertySet )
336 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( BarChartTypeTemplate, ChartTypeTemplate, OPropertySet )
337 :
338 6 : } // namespace chart
339 :
340 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|