1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 #include "AreaChartTypeTemplate.hxx"
27 #include "macros.hxx"
28 #include "servicenames_charttypes.hxx"
29 #include "DiagramHelper.hxx"
30 #include "DataSeriesHelper.hxx"
31 #include "ContainerHelper.hxx"
32 #include "PropertyHelper.hxx"
33 #include <com/sun/star/beans/PropertyAttribute.hpp>
34 #include <com/sun/star/drawing/LineStyle.hpp>
35 
36 #include <algorithm>
37 
38 using namespace ::com::sun::star;
39 
40 using ::rtl::OUString;
41 using ::com::sun::star::beans::Property;
42 using ::com::sun::star::uno::Sequence;
43 using ::com::sun::star::uno::Reference;
44 using ::com::sun::star::uno::Any;
45 using ::osl::MutexGuard;
46 
47 namespace
48 {
49 
50 static const ::rtl::OUString lcl_aServiceName(
51     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.AreaChartTypeTemplate" ));
52 
53 enum
54 {
55     PROP_AREA_TEMPLATE_DIMENSION
56 };
57 
lcl_AddPropertiesToVector(::std::vector<Property> & rOutProperties)58 void lcl_AddPropertiesToVector(
59     ::std::vector< Property > & rOutProperties )
60 {
61     rOutProperties.push_back(
62         Property( C2U( "Dimension" ),
63                   PROP_AREA_TEMPLATE_DIMENSION,
64                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
65                   beans::PropertyAttribute::BOUND
66                   | beans::PropertyAttribute::MAYBEDEFAULT ));
67 }
68 
69 struct StaticAreaChartTypeTemplateDefaults_Initializer
70 {
operator ()__anon40d3d8e70111::StaticAreaChartTypeTemplateDefaults_Initializer71     ::chart::tPropertyValueMap* operator()()
72     {
73         static ::chart::tPropertyValueMap aStaticDefaults;
74         lcl_AddDefaultsToMap( aStaticDefaults );
75         return &aStaticDefaults;
76     }
77 private:
lcl_AddDefaultsToMap__anon40d3d8e70111::StaticAreaChartTypeTemplateDefaults_Initializer78     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
79     {
80         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_AREA_TEMPLATE_DIMENSION, 2 );
81     }
82 };
83 
84 struct StaticAreaChartTypeTemplateDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticAreaChartTypeTemplateDefaults_Initializer >
85 {
86 };
87 
88 struct StaticAreaChartTypeTemplateInfoHelper_Initializer
89 {
operator ()__anon40d3d8e70111::StaticAreaChartTypeTemplateInfoHelper_Initializer90     ::cppu::OPropertyArrayHelper* operator()()
91     {
92         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
93         return &aPropHelper;
94     }
95 
96 private:
lcl_GetPropertySequence__anon40d3d8e70111::StaticAreaChartTypeTemplateInfoHelper_Initializer97     uno::Sequence< Property > lcl_GetPropertySequence()
98     {
99         ::std::vector< ::com::sun::star::beans::Property > aProperties;
100         lcl_AddPropertiesToVector( aProperties );
101 
102         ::std::sort( aProperties.begin(), aProperties.end(),
103                      ::chart::PropertyNameLess() );
104 
105         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
106     }
107 
108 };
109 
110 struct StaticAreaChartTypeTemplateInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticAreaChartTypeTemplateInfoHelper_Initializer >
111 {
112 };
113 
114 struct StaticAreaChartTypeTemplateInfo_Initializer
115 {
operator ()__anon40d3d8e70111::StaticAreaChartTypeTemplateInfo_Initializer116     uno::Reference< beans::XPropertySetInfo >* operator()()
117     {
118         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
119             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticAreaChartTypeTemplateInfoHelper::get() ) );
120         return &xPropertySetInfo;
121     }
122 };
123 
124 struct StaticAreaChartTypeTemplateInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticAreaChartTypeTemplateInfo_Initializer >
125 {
126 };
127 
128 } // anonymous namespace
129 
130 namespace chart
131 {
132 
AreaChartTypeTemplate(uno::Reference<uno::XComponentContext> const & xContext,const::rtl::OUString & rServiceName,StackMode eStackMode,sal_Int32 nDim)133 AreaChartTypeTemplate::AreaChartTypeTemplate(
134     uno::Reference<
135         uno::XComponentContext > const & xContext,
136     const ::rtl::OUString & rServiceName,
137     StackMode eStackMode,
138     sal_Int32 nDim /* = 2 */ ) :
139         ChartTypeTemplate( xContext, rServiceName ),
140         ::property::OPropertySet( m_aMutex ),
141         m_eStackMode( eStackMode )
142 {
143     setFastPropertyValue_NoBroadcast( PROP_AREA_TEMPLATE_DIMENSION, uno::makeAny( nDim ));
144 }
145 
~AreaChartTypeTemplate()146 AreaChartTypeTemplate::~AreaChartTypeTemplate()
147 {}
148 
149 // ____ OPropertySet ____
GetDefaultValue(sal_Int32 nHandle) const150 uno::Any AreaChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle ) const
151     throw(beans::UnknownPropertyException)
152 {
153     const tPropertyValueMap& rStaticDefaults = *StaticAreaChartTypeTemplateDefaults::get();
154     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
155     if( aFound == rStaticDefaults.end() )
156         return uno::Any();
157     return (*aFound).second;
158 }
159 
getInfoHelper()160 ::cppu::IPropertyArrayHelper & SAL_CALL AreaChartTypeTemplate::getInfoHelper()
161 {
162     return *StaticAreaChartTypeTemplateInfoHelper::get();
163 }
164 
165 // ____ XPropertySet ____
getPropertySetInfo()166 uno::Reference< beans::XPropertySetInfo > SAL_CALL AreaChartTypeTemplate::getPropertySetInfo()
167     throw (uno::RuntimeException)
168 {
169     return *StaticAreaChartTypeTemplateInfo::get();
170 }
171 
getDimension() const172 sal_Int32 AreaChartTypeTemplate::getDimension() const
173 {
174     sal_Int32 nDim = 2;
175     try
176     {
177         // note: UNO-methods are never const
178         const_cast< AreaChartTypeTemplate * >( this )->
179             getFastPropertyValue( PROP_AREA_TEMPLATE_DIMENSION ) >>= nDim;
180     }
181     catch( beans::UnknownPropertyException & ex )
182     {
183         ASSERT_EXCEPTION( ex );
184     }
185 
186     return nDim;
187 }
188 
getStackMode(sal_Int32) const189 StackMode AreaChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
190 {
191     return m_eStackMode;
192 }
193 
194 // ____ XChartTypeTemplate ____
applyStyle(const Reference<chart2::XDataSeries> & xSeries,::sal_Int32 nChartTypeIndex,::sal_Int32 nSeriesIndex,::sal_Int32 nSeriesCount)195 void SAL_CALL AreaChartTypeTemplate::applyStyle(
196     const Reference< chart2::XDataSeries >& xSeries,
197     ::sal_Int32 nChartTypeIndex,
198     ::sal_Int32 nSeriesIndex,
199     ::sal_Int32 nSeriesCount )
200     throw (uno::RuntimeException)
201 {
202     ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
203     DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "BorderStyle" ), uno::makeAny( drawing::LineStyle_NONE ) );
204 }
205 
resetStyles(const Reference<chart2::XDiagram> & xDiagram)206 void SAL_CALL AreaChartTypeTemplate::resetStyles( const Reference< chart2::XDiagram >& xDiagram )
207     throw (uno::RuntimeException)
208 {
209     ChartTypeTemplate::resetStyles( xDiagram );
210     ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
211         DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
212     uno::Any aLineStyleAny( uno::makeAny( drawing::LineStyle_NONE ));
213     for( ::std::vector< Reference< chart2::XDataSeries > >::iterator aIt( aSeriesVec.begin());
214          aIt != aSeriesVec.end(); ++aIt )
215     {
216         Reference< beans::XPropertyState > xState( *aIt, uno::UNO_QUERY );
217         Reference< beans::XPropertySet > xProp( *aIt, uno::UNO_QUERY );
218         if( xState.is() &&
219             xProp.is() &&
220             xProp->getPropertyValue( C2U("BorderStyle")) == aLineStyleAny )
221         {
222             xState->setPropertyToDefault( C2U("BorderStyle"));
223         }
224     }
225 }
226 
getChartTypeForIndex(sal_Int32)227 Reference< chart2::XChartType > AreaChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
228 {
229     Reference< chart2::XChartType > xResult;
230 
231     try
232     {
233         Reference< lang::XMultiServiceFactory > xFact(
234             GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
235         xResult.set( xFact->createInstance(
236                          CHART2_SERVICE_NAME_CHARTTYPE_AREA ), uno::UNO_QUERY_THROW );
237     }
238     catch( uno::Exception & ex )
239     {
240         ASSERT_EXCEPTION( ex );
241     }
242 
243     return xResult;
244 }
245 
getChartTypeForNewSeries(const uno::Sequence<Reference<chart2::XChartType>> & aFormerlyUsedChartTypes)246 Reference< chart2::XChartType > SAL_CALL AreaChartTypeTemplate::getChartTypeForNewSeries(
247         const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
248     throw (uno::RuntimeException)
249 {
250     Reference< chart2::XChartType > xResult( getChartTypeForIndex( 0 ) );
251     ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult );
252     return xResult;
253 }
254 
255 
256 // ----------------------------------------
257 
getSupportedServiceNames_Static()258 uno::Sequence< ::rtl::OUString > AreaChartTypeTemplate::getSupportedServiceNames_Static()
259 {
260     uno::Sequence< ::rtl::OUString > aServices( 2 );
261     aServices[ 0 ] = lcl_aServiceName;
262     aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" );
263     return aServices;
264 }
265 
266 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
267 APPHELPER_XSERVICEINFO_IMPL( AreaChartTypeTemplate, lcl_aServiceName );
268 
269 IMPLEMENT_FORWARD_XINTERFACE2( AreaChartTypeTemplate, ChartTypeTemplate, OPropertySet )
270 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AreaChartTypeTemplate, ChartTypeTemplate, OPropertySet )
271 
272 } //  namespace chart
273