fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / WrappedSplineProperties.cxx
blob1698c0ac7240d9efd19e74a096a3c73b9bac36b9
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 "WrappedSplineProperties.hxx"
21 #include "macros.hxx"
22 #include "FastPropertyIdRanges.hxx"
23 #include "DiagramHelper.hxx"
24 #include <unonames.hxx>
26 #include <com/sun/star/chart2/CurveStyle.hpp>
27 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 using namespace ::com::sun::star;
30 using ::com::sun::star::uno::Any;
31 using ::com::sun::star::uno::Reference;
32 using ::com::sun::star::uno::Sequence;
33 using ::com::sun::star::beans::Property;
35 namespace chart
37 namespace wrapper
40 //PROPERTYTYPE is the type of the outer property
42 template< typename PROPERTYTYPE >
43 class WrappedSplineProperty : public WrappedProperty
45 public:
46 explicit WrappedSplineProperty( const OUString& rOuterName, const OUString& rInnerName
47 , const ::com::sun::star::uno::Any& rDefaulValue
48 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
49 : WrappedProperty(rOuterName,OUString())
50 , m_spChart2ModelContact(spChart2ModelContact)
51 , m_aOuterValue(rDefaulValue)
52 , m_aDefaultValue(rDefaulValue)
53 , m_aOwnInnerName(rInnerName)
56 virtual ~WrappedSplineProperty() {};
58 bool detectInnerValue( PROPERTYTYPE& rValue, bool& rHasAmbiguousValue ) const
60 bool bHasDetectableInnerValue = false;
61 rHasAmbiguousValue = false;
62 Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > > aChartTypes(
63 ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
64 for( sal_Int32 nN = aChartTypes.getLength(); nN--; )
66 try
68 uno::Reference<beans::XPropertySet> xChartTypePropertySet(aChartTypes[nN], uno::UNO_QUERY);
69 if (!xChartTypePropertySet.is())
70 continue;
72 Any aSingleValue = this->convertInnerToOuterValue( xChartTypePropertySet->getPropertyValue(m_aOwnInnerName) );
73 PROPERTYTYPE aCurValue = PROPERTYTYPE();
74 aSingleValue >>= aCurValue;
75 if( !bHasDetectableInnerValue )
76 rValue = aCurValue;
77 else
79 if( rValue != aCurValue )
81 rHasAmbiguousValue = true;
82 break;
84 else
85 rValue = aCurValue;
87 bHasDetectableInnerValue = true;
89 catch( uno::Exception & ex )
91 //spline properties are not supported by all charttypes
92 //in that cases this exception is ok
93 ex.Context.is();//to have debug information without compilation warnings
96 return bHasDetectableInnerValue;
98 void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const
99 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
101 PROPERTYTYPE aNewValue;
102 if( ! (rOuterValue >>= aNewValue) )
103 throw ::com::sun::star::lang::IllegalArgumentException( "spline property requires different type", 0, 0 );
105 m_aOuterValue = rOuterValue;
107 bool bHasAmbiguousValue = false;
108 PROPERTYTYPE aOldValue = PROPERTYTYPE();
109 if( detectInnerValue( aOldValue, bHasAmbiguousValue ) )
111 if( bHasAmbiguousValue || aNewValue != aOldValue )
113 Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > > aChartTypes(
114 ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
115 for( sal_Int32 nN = aChartTypes.getLength(); nN--; )
119 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xChartTypePropertySet( aChartTypes[nN], ::com::sun::star::uno::UNO_QUERY );
120 if( xChartTypePropertySet.is() )
122 xChartTypePropertySet->setPropertyValue(m_aOwnInnerName,this->convertOuterToInnerValue(uno::makeAny(aNewValue)));
125 catch( uno::Exception & ex )
127 //spline properties are not supported by all charttypes
128 //in that cases this exception is ok
129 ex.Context.is();//to have debug information without compilation warnings
136 ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const
137 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
139 bool bHasAmbiguousValue = false;
140 PROPERTYTYPE aValue;
141 if( detectInnerValue( aValue, bHasAmbiguousValue ) )
143 m_aOuterValue <<= aValue;
145 return m_aOuterValue;
148 ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& /*xInnerPropertyState*/ ) const
149 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
151 return m_aDefaultValue;
154 protected:
155 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
156 mutable ::com::sun::star::uno::Any m_aOuterValue;
157 ::com::sun::star::uno::Any m_aDefaultValue;
158 // this inner name is not set as inner name at the base class
159 const OUString m_aOwnInnerName;
162 class WrappedSplineTypeProperty : public WrappedSplineProperty< sal_Int32 >
164 public:
165 explicit WrappedSplineTypeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
166 virtual ~WrappedSplineTypeProperty();
168 virtual ::com::sun::star::uno::Any convertInnerToOuterValue( const ::com::sun::star::uno::Any& rInnerValue ) const SAL_OVERRIDE;
169 virtual ::com::sun::star::uno::Any convertOuterToInnerValue( const ::com::sun::star::uno::Any& rOuterValue ) const SAL_OVERRIDE;
172 namespace
174 enum
176 //spline properties
177 PROP_CHART_SPLINE_TYPE = FAST_PROPERTY_ID_START_CHART_SPLINE_PROP
178 , PROP_CHART_SPLINE_ORDER
179 , PROP_CHART_SPLINE_RESOLUTION
182 }//anonymous namespace
184 void WrappedSplineProperties::addProperties( ::std::vector< Property > & rOutProperties )
186 rOutProperties.push_back(
187 Property( CHART_UNONAME_SPLINE_TYPE,
188 PROP_CHART_SPLINE_TYPE,
189 cppu::UnoType<sal_Int32>::get(),
190 beans::PropertyAttribute::BOUND
191 | beans::PropertyAttribute::MAYBEDEFAULT
192 | beans::PropertyAttribute::MAYBEVOID ));
193 rOutProperties.push_back(
194 Property( CHART_UNONAME_SPLINE_ORDER,
195 PROP_CHART_SPLINE_ORDER,
196 cppu::UnoType<sal_Int32>::get(),
197 beans::PropertyAttribute::BOUND
198 | beans::PropertyAttribute::MAYBEDEFAULT
199 | beans::PropertyAttribute::MAYBEVOID ));
200 rOutProperties.push_back(
201 Property( CHART_UNONAME_SPLINE_RESOLUTION,
202 PROP_CHART_SPLINE_RESOLUTION,
203 cppu::UnoType<sal_Int32>::get(),
204 beans::PropertyAttribute::BOUND
205 | beans::PropertyAttribute::MAYBEDEFAULT
206 | beans::PropertyAttribute::MAYBEVOID ));
209 void WrappedSplineProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
210 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
212 rList.push_back( new WrappedSplineTypeProperty( spChart2ModelContact ) );
213 rList.push_back(
214 new WrappedSplineProperty<sal_Int32>(
215 CHART_UNONAME_SPLINE_ORDER, CHART_UNONAME_SPLINE_ORDER,
216 uno::makeAny(sal_Int32(3)), spChart2ModelContact));
217 rList.push_back(
218 new WrappedSplineProperty<sal_Int32>(
219 CHART_UNONAME_SPLINE_RESOLUTION, CHART_UNONAME_CURVE_RESOLUTION,
220 uno::makeAny(sal_Int32(20)), spChart2ModelContact));
223 WrappedSplineTypeProperty::WrappedSplineTypeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
224 : WrappedSplineProperty<sal_Int32>(CHART_UNONAME_SPLINE_TYPE, CHART_UNONAME_CURVE_STYLE, uno::makeAny(sal_Int32(0)), spChart2ModelContact )
227 WrappedSplineTypeProperty::~WrappedSplineTypeProperty()
230 Any WrappedSplineTypeProperty::convertInnerToOuterValue( const Any& rInnerValue ) const
232 chart2::CurveStyle aInnerValue = chart2::CurveStyle_LINES;
233 rInnerValue >>= aInnerValue;
235 sal_Int32 nOuterValue;
236 switch (aInnerValue)
238 case chart2::CurveStyle_CUBIC_SPLINES:
239 nOuterValue = 1;
240 break;
241 case chart2::CurveStyle_B_SPLINES:
242 nOuterValue = 2;
243 break;
244 case chart2::CurveStyle_STEP_START:
245 nOuterValue = 3;
246 break;
247 case chart2::CurveStyle_STEP_END:
248 nOuterValue = 4;
249 break;
250 case chart2::CurveStyle_STEP_CENTER_X:
251 nOuterValue = 5;
252 break;
253 case chart2::CurveStyle_STEP_CENTER_Y:
254 nOuterValue = 6;
255 break;
256 default:
257 nOuterValue = 0;
260 return uno::makeAny(nOuterValue);
262 Any WrappedSplineTypeProperty::convertOuterToInnerValue( const Any& rOuterValue ) const
264 sal_Int32 nOuterValue=0;
265 rOuterValue >>= nOuterValue;
267 chart2::CurveStyle aInnerValue;
269 switch (nOuterValue)
271 case 1:
272 aInnerValue = chart2::CurveStyle_CUBIC_SPLINES;
273 break;
274 case 2:
275 aInnerValue = chart2::CurveStyle_B_SPLINES;
276 break;
277 case 3:
278 aInnerValue = chart2::CurveStyle_STEP_START;
279 break;
280 case 4:
281 aInnerValue = chart2::CurveStyle_STEP_END;
282 break;
283 case 5:
284 aInnerValue = chart2::CurveStyle_STEP_CENTER_X;
285 break;
286 case 6:
287 aInnerValue = chart2::CurveStyle_STEP_CENTER_Y;
288 break;
289 default:
290 SAL_WARN_IF(chart2::CurveStyle_LINES != 0, "chart2", "Unknown line style");
291 aInnerValue = chart2::CurveStyle_LINES;
294 return uno::makeAny(aInnerValue);
297 } //namespace wrapper
298 } //namespace chart
300 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */