Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / source / model / template / AreaChartTypeTemplate.cxx
blobf2ff81a1e8d1748225b203ad2d6b1ad842f93bc3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "AreaChartTypeTemplate.hxx"
21 #include "AreaChartType.hxx"
22 #include <Diagram.hxx>
23 #include <DiagramHelper.hxx>
24 #include <DataSeries.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/uno/XComponentContext.hpp>
30 #include <comphelper/diagnose_ex.hxx>
32 #include <algorithm>
34 using namespace ::com::sun::star;
36 using ::com::sun::star::beans::Property;
37 using ::com::sun::star::uno::Sequence;
38 using ::com::sun::star::uno::Reference;
40 namespace
43 enum
45 PROP_AREA_TEMPLATE_DIMENSION
48 void lcl_AddPropertiesToVector(
49 std::vector< Property > & rOutProperties )
51 rOutProperties.emplace_back( "Dimension",
52 PROP_AREA_TEMPLATE_DIMENSION,
53 cppu::UnoType<sal_Int32>::get(),
54 beans::PropertyAttribute::BOUND
55 | beans::PropertyAttribute::MAYBEDEFAULT );
58 ::cppu::OPropertyArrayHelper& StaticAreaChartTypeTemplateInfoHelper()
60 static ::cppu::OPropertyArrayHelper aPropHelper = []()
62 std::vector< css::beans::Property > aProperties;
63 lcl_AddPropertiesToVector( aProperties );
65 std::sort( aProperties.begin(), aProperties.end(),
66 ::chart::PropertyNameLess() );
68 return comphelper::containerToSequence( aProperties );
69 }();
70 return aPropHelper;
73 } // anonymous namespace
75 namespace chart
78 AreaChartTypeTemplate::AreaChartTypeTemplate(
79 uno::Reference<
80 uno::XComponentContext > const & xContext,
81 const OUString & rServiceName,
82 StackMode eStackMode,
83 sal_Int32 nDim /* = 2 */ ) :
84 ChartTypeTemplate( xContext, rServiceName ),
85 m_eStackMode( eStackMode )
87 setFastPropertyValue_NoBroadcast( PROP_AREA_TEMPLATE_DIMENSION, uno::Any( nDim ));
90 AreaChartTypeTemplate::~AreaChartTypeTemplate()
93 // ____ OPropertySet ____
94 void AreaChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAny ) const
96 static ::chart::tPropertyValueMap aStaticDefaults = []()
98 ::chart::tPropertyValueMap aTmp;
99 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aTmp, PROP_AREA_TEMPLATE_DIMENSION, 2 );
100 return aTmp;
101 }();
102 tPropertyValueMap::const_iterator aFound( aStaticDefaults.find( nHandle ) );
103 if( aFound == aStaticDefaults.end() )
104 rAny.clear();
105 else
106 rAny = (*aFound).second;
109 ::cppu::IPropertyArrayHelper & SAL_CALL AreaChartTypeTemplate::getInfoHelper()
111 return StaticAreaChartTypeTemplateInfoHelper();
114 // ____ XPropertySet ____
115 uno::Reference< beans::XPropertySetInfo > SAL_CALL AreaChartTypeTemplate::getPropertySetInfo()
117 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
118 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticAreaChartTypeTemplateInfoHelper() ) );
119 return xPropertySetInfo;
122 sal_Int32 AreaChartTypeTemplate::getDimension() const
124 sal_Int32 nDim = 2;
127 // note: UNO-methods are never const
128 const_cast< AreaChartTypeTemplate * >( this )->
129 getFastPropertyValue( PROP_AREA_TEMPLATE_DIMENSION ) >>= nDim;
131 catch( const beans::UnknownPropertyException & )
133 DBG_UNHANDLED_EXCEPTION("chart2");
136 return nDim;
139 StackMode AreaChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
141 return m_eStackMode;
144 // ____ ChartTypeTemplate ____
145 void AreaChartTypeTemplate::applyStyle2(
146 const rtl::Reference< DataSeries >& xSeries,
147 ::sal_Int32 nChartTypeIndex,
148 ::sal_Int32 nSeriesIndex,
149 ::sal_Int32 nSeriesCount )
151 ChartTypeTemplate::applyStyle2( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
152 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, "BorderStyle", uno::Any( drawing::LineStyle_NONE ) );
155 void AreaChartTypeTemplate::resetStyles2( const rtl::Reference< ::chart::Diagram >& xDiagram )
157 ChartTypeTemplate::resetStyles2( xDiagram );
158 std::vector< rtl::Reference< ::chart::DataSeries > > aSeriesVec(
159 xDiagram->getDataSeries());
160 uno::Any aLineStyleAny( drawing::LineStyle_NONE );
161 for (auto const& series : aSeriesVec)
163 if( series->getPropertyValue( "BorderStyle") == aLineStyleAny )
165 series->setPropertyToDefault( "BorderStyle");
170 rtl::Reference< ChartType > AreaChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
172 return new AreaChartType();
175 rtl::Reference< ChartType > AreaChartTypeTemplate::getChartTypeForNewSeries2(
176 const std::vector< rtl::Reference< ChartType > >& aFormerlyUsedChartTypes )
178 rtl::Reference< ChartType > xResult( getChartTypeForIndex( 0 ) );
179 ChartTypeTemplate::copyPropertiesFromOldToNewCoordinateSystem( aFormerlyUsedChartTypes, xResult );
180 return xResult;
183 IMPLEMENT_FORWARD_XINTERFACE2( AreaChartTypeTemplate, ChartTypeTemplate, OPropertySet )
184 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AreaChartTypeTemplate, ChartTypeTemplate, OPropertySet )
186 } // namespace chart
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */