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 <servicenames_charttypes.hxx>
22 #include <DiagramHelper.hxx>
23 #include <DataSeriesHelper.hxx>
24 #include <PropertyHelper.hxx>
25 #include <com/sun/star/beans/PropertyAttribute.hpp>
26 #include <com/sun/star/drawing/LineStyle.hpp>
27 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 #include <tools/diagnose_ex.h>
30 
31 #include <algorithm>
32 
33 using namespace ::com::sun::star;
34 
35 using ::com::sun::star::beans::Property;
36 using ::com::sun::star::uno::Sequence;
37 using ::com::sun::star::uno::Reference;
38 
39 namespace
40 {
41 
42 enum
43 {
44     PROP_AREA_TEMPLATE_DIMENSION
45 };
46 
lcl_AddPropertiesToVector(std::vector<Property> & rOutProperties)47 void lcl_AddPropertiesToVector(
48     std::vector< Property > & rOutProperties )
49 {
50     rOutProperties.emplace_back( "Dimension",
51                   PROP_AREA_TEMPLATE_DIMENSION,
52                   cppu::UnoType<sal_Int32>::get(),
53                   beans::PropertyAttribute::BOUND
54                   | beans::PropertyAttribute::MAYBEDEFAULT );
55 }
56 
57 struct StaticAreaChartTypeTemplateDefaults_Initializer
58 {
operator ()__anon7cfdabf50111::StaticAreaChartTypeTemplateDefaults_Initializer59     ::chart::tPropertyValueMap* operator()()
60     {
61         static ::chart::tPropertyValueMap aStaticDefaults;
62         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aStaticDefaults, PROP_AREA_TEMPLATE_DIMENSION, 2 );
63         return &aStaticDefaults;
64     }
65 };
66 
67 struct StaticAreaChartTypeTemplateDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticAreaChartTypeTemplateDefaults_Initializer >
68 {
69 };
70 
71 struct StaticAreaChartTypeTemplateInfoHelper_Initializer
72 {
operator ()__anon7cfdabf50111::StaticAreaChartTypeTemplateInfoHelper_Initializer73     ::cppu::OPropertyArrayHelper* operator()()
74     {
75         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
76         return &aPropHelper;
77     }
78 
79 private:
lcl_GetPropertySequence__anon7cfdabf50111::StaticAreaChartTypeTemplateInfoHelper_Initializer80     static uno::Sequence< Property > lcl_GetPropertySequence()
81     {
82         std::vector< css::beans::Property > aProperties;
83         lcl_AddPropertiesToVector( aProperties );
84 
85         std::sort( aProperties.begin(), aProperties.end(),
86                      ::chart::PropertyNameLess() );
87 
88         return comphelper::containerToSequence( aProperties );
89     }
90 
91 };
92 
93 struct StaticAreaChartTypeTemplateInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticAreaChartTypeTemplateInfoHelper_Initializer >
94 {
95 };
96 
97 struct StaticAreaChartTypeTemplateInfo_Initializer
98 {
operator ()__anon7cfdabf50111::StaticAreaChartTypeTemplateInfo_Initializer99     uno::Reference< beans::XPropertySetInfo >* operator()()
100     {
101         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
102             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticAreaChartTypeTemplateInfoHelper::get() ) );
103         return &xPropertySetInfo;
104     }
105 };
106 
107 struct StaticAreaChartTypeTemplateInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticAreaChartTypeTemplateInfo_Initializer >
108 {
109 };
110 
111 } // anonymous namespace
112 
113 namespace chart
114 {
115 
AreaChartTypeTemplate(uno::Reference<uno::XComponentContext> const & xContext,const OUString & rServiceName,StackMode eStackMode,sal_Int32 nDim)116 AreaChartTypeTemplate::AreaChartTypeTemplate(
117     uno::Reference<
118         uno::XComponentContext > const & xContext,
119     const OUString & rServiceName,
120     StackMode eStackMode,
121     sal_Int32 nDim /* = 2 */ ) :
122         ChartTypeTemplate( xContext, rServiceName ),
123         ::property::OPropertySet( m_aMutex ),
124         m_eStackMode( eStackMode )
125 {
126     setFastPropertyValue_NoBroadcast( PROP_AREA_TEMPLATE_DIMENSION, uno::Any( nDim ));
127 }
128 
~AreaChartTypeTemplate()129 AreaChartTypeTemplate::~AreaChartTypeTemplate()
130 {}
131 
132 // ____ OPropertySet ____
GetDefaultValue(sal_Int32 nHandle) const133 uno::Any AreaChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle ) const
134 {
135     const tPropertyValueMap& rStaticDefaults = *StaticAreaChartTypeTemplateDefaults::get();
136     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
137     if( aFound == rStaticDefaults.end() )
138         return uno::Any();
139     return (*aFound).second;
140 }
141 
getInfoHelper()142 ::cppu::IPropertyArrayHelper & SAL_CALL AreaChartTypeTemplate::getInfoHelper()
143 {
144     return *StaticAreaChartTypeTemplateInfoHelper::get();
145 }
146 
147 // ____ XPropertySet ____
getPropertySetInfo()148 uno::Reference< beans::XPropertySetInfo > SAL_CALL AreaChartTypeTemplate::getPropertySetInfo()
149 {
150     return *StaticAreaChartTypeTemplateInfo::get();
151 }
152 
getDimension() const153 sal_Int32 AreaChartTypeTemplate::getDimension() const
154 {
155     sal_Int32 nDim = 2;
156     try
157     {
158         // note: UNO-methods are never const
159         const_cast< AreaChartTypeTemplate * >( this )->
160             getFastPropertyValue( PROP_AREA_TEMPLATE_DIMENSION ) >>= nDim;
161     }
162     catch( const beans::UnknownPropertyException & )
163     {
164         DBG_UNHANDLED_EXCEPTION("chart2");
165     }
166 
167     return nDim;
168 }
169 
getStackMode(sal_Int32) const170 StackMode AreaChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
171 {
172     return m_eStackMode;
173 }
174 
175 // ____ XChartTypeTemplate ____
applyStyle(const Reference<chart2::XDataSeries> & xSeries,::sal_Int32 nChartTypeIndex,::sal_Int32 nSeriesIndex,::sal_Int32 nSeriesCount)176 void SAL_CALL AreaChartTypeTemplate::applyStyle(
177     const Reference< chart2::XDataSeries >& xSeries,
178     ::sal_Int32 nChartTypeIndex,
179     ::sal_Int32 nSeriesIndex,
180     ::sal_Int32 nSeriesCount )
181 {
182     ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
183     DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, "BorderStyle", uno::Any( drawing::LineStyle_NONE ) );
184 }
185 
resetStyles(const Reference<chart2::XDiagram> & xDiagram)186 void SAL_CALL AreaChartTypeTemplate::resetStyles( const Reference< chart2::XDiagram >& xDiagram )
187 {
188     ChartTypeTemplate::resetStyles( xDiagram );
189     std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
190         DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
191     uno::Any aLineStyleAny( drawing::LineStyle_NONE );
192     for (auto const& series : aSeriesVec)
193     {
194         Reference< beans::XPropertyState > xState(series, uno::UNO_QUERY);
195         Reference< beans::XPropertySet > xProp(series, uno::UNO_QUERY);
196         if( xState.is() &&
197             xProp.is() &&
198             xProp->getPropertyValue( "BorderStyle") == aLineStyleAny )
199         {
200             xState->setPropertyToDefault( "BorderStyle");
201         }
202     }
203 }
204 
getChartTypeForIndex(sal_Int32)205 Reference< chart2::XChartType > AreaChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
206 {
207     Reference< chart2::XChartType > xResult;
208 
209     try
210     {
211         Reference< lang::XMultiServiceFactory > xFact(
212             GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
213         xResult.set( xFact->createInstance(
214                          CHART2_SERVICE_NAME_CHARTTYPE_AREA ), uno::UNO_QUERY_THROW );
215     }
216     catch( const uno::Exception & )
217     {
218         DBG_UNHANDLED_EXCEPTION("chart2");
219     }
220 
221     return xResult;
222 }
223 
getChartTypeForNewSeries(const uno::Sequence<Reference<chart2::XChartType>> & aFormerlyUsedChartTypes)224 Reference< chart2::XChartType > SAL_CALL AreaChartTypeTemplate::getChartTypeForNewSeries(
225         const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
226 {
227     Reference< chart2::XChartType > xResult( getChartTypeForIndex( 0 ) );
228     ChartTypeTemplate::copyPropertiesFromOldToNewCoordinateSystem( aFormerlyUsedChartTypes, xResult );
229     return xResult;
230 }
231 
232 IMPLEMENT_FORWARD_XINTERFACE2( AreaChartTypeTemplate, ChartTypeTemplate, OPropertySet )
233 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AreaChartTypeTemplate, ChartTypeTemplate, OPropertySet )
234 
235 } //  namespace chart
236 
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
238