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