fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / WrappedScaleProperty.cxx
blob8c86559b31b654d3ca80c001e17c922172d3f16b
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 "WrappedScaleProperty.hxx"
21 #include "macros.hxx"
22 #include "CommonConverters.hxx"
23 #include "AxisHelper.hxx"
24 #include <com/sun/star/chart2/XAxis.hpp>
25 #include <com/sun/star/chart/ChartAxisType.hpp>
26 #include <chartview/ExplicitScaleValues.hxx>
28 using namespace ::com::sun::star;
29 using ::com::sun::star::uno::Any;
30 using namespace ::com::sun::star::chart2;
31 using ::com::sun::star::uno::Reference;
32 using ::com::sun::star::uno::Sequence;
33 using ::com::sun::star::chart::TimeIncrement;
35 namespace chart
37 namespace wrapper
40 WrappedScaleProperty::WrappedScaleProperty( tScaleProperty eScaleProperty
41 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
42 : WrappedProperty(OUString(),OUString())
43 , m_spChart2ModelContact( spChart2ModelContact )
44 , m_eScaleProperty( eScaleProperty )
46 switch( m_eScaleProperty )
48 case SCALE_PROP_MAX:
49 m_aOuterName = "Max";
50 break;
51 case SCALE_PROP_MIN:
52 m_aOuterName = "Min";
53 break;
54 case SCALE_PROP_ORIGIN:
55 m_aOuterName = "Origin";
56 break;
57 case SCALE_PROP_STEPMAIN:
58 m_aOuterName = "StepMain";
59 break;
60 case SCALE_PROP_STEPHELP:
61 m_aOuterName = "StepHelp";
62 break;
63 case SCALE_PROP_STEPHELP_COUNT:
64 m_aOuterName = "StepHelpCount";
65 break;
66 case SCALE_PROP_AUTO_MAX:
67 m_aOuterName = "AutoMax";
68 break;
69 case SCALE_PROP_AUTO_MIN:
70 m_aOuterName = "AutoMin";
71 break;
72 case SCALE_PROP_AUTO_ORIGIN:
73 m_aOuterName = "AutoOrigin";
74 break;
75 case SCALE_PROP_AUTO_STEPMAIN:
76 m_aOuterName = "AutoStepMain";
77 break;
78 case SCALE_PROP_AUTO_STEPHELP:
79 m_aOuterName = "AutoStepHelp";
80 break;
81 case SCALE_PROP_AXIS_TYPE:
82 m_aOuterName = "AxisType";
83 break;
84 case SCALE_PROP_DATE_INCREMENT:
85 m_aOuterName = "TimeIncrement";
86 break;
87 case SCALE_PROP_EXPLICIT_DATE_INCREMENT:
88 m_aOuterName = "ExplicitTimeIncrement";
89 break;
90 case SCALE_PROP_LOGARITHMIC:
91 m_aOuterName = "Logarithmic";
92 break;
93 case SCALE_PROP_REVERSEDIRECTION:
94 m_aOuterName = "ReverseDirection";
95 break;
96 default:
97 OSL_FAIL("unknown scale property");
98 break;
102 WrappedScaleProperty::~WrappedScaleProperty()
106 void WrappedScaleProperty::addWrappedProperties( std::vector< WrappedProperty* >& rList
107 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
109 rList.push_back( new WrappedScaleProperty( SCALE_PROP_MAX, spChart2ModelContact ) );
110 rList.push_back( new WrappedScaleProperty( SCALE_PROP_MIN, spChart2ModelContact ) );
111 rList.push_back( new WrappedScaleProperty( SCALE_PROP_ORIGIN, spChart2ModelContact ) );
112 rList.push_back( new WrappedScaleProperty( SCALE_PROP_STEPMAIN, spChart2ModelContact ) );
113 rList.push_back( new WrappedScaleProperty( SCALE_PROP_STEPHELP, spChart2ModelContact ) );
114 rList.push_back( new WrappedScaleProperty( SCALE_PROP_STEPHELP_COUNT, spChart2ModelContact ) );
115 rList.push_back( new WrappedScaleProperty( SCALE_PROP_AUTO_MAX, spChart2ModelContact ) );
116 rList.push_back( new WrappedScaleProperty( SCALE_PROP_AUTO_MIN, spChart2ModelContact ) );
117 rList.push_back( new WrappedScaleProperty( SCALE_PROP_AUTO_ORIGIN, spChart2ModelContact ) );
118 rList.push_back( new WrappedScaleProperty( SCALE_PROP_AUTO_STEPMAIN, spChart2ModelContact ) );
119 rList.push_back( new WrappedScaleProperty( SCALE_PROP_AUTO_STEPHELP, spChart2ModelContact ) );
120 rList.push_back( new WrappedScaleProperty( SCALE_PROP_AXIS_TYPE, spChart2ModelContact ) );
121 rList.push_back( new WrappedScaleProperty( SCALE_PROP_DATE_INCREMENT, spChart2ModelContact ) );
122 rList.push_back( new WrappedScaleProperty( SCALE_PROP_EXPLICIT_DATE_INCREMENT, spChart2ModelContact ) );
123 rList.push_back( new WrappedScaleProperty( SCALE_PROP_LOGARITHMIC, spChart2ModelContact ) );
124 rList.push_back( new WrappedScaleProperty( SCALE_PROP_REVERSEDIRECTION, spChart2ModelContact ) );
127 void WrappedScaleProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
128 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
130 setPropertyValue( m_eScaleProperty, rOuterValue, xInnerPropertySet );
133 Any WrappedScaleProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
134 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
136 return getPropertyValue( m_eScaleProperty, xInnerPropertySet );
139 void WrappedScaleProperty::setPropertyValue( tScaleProperty eScaleProperty, const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
140 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
142 m_aOuterValue = rOuterValue;
144 Reference< chart2::XAxis > xAxis( xInnerPropertySet, uno::UNO_QUERY );
145 OSL_ENSURE(xAxis.is(),"need an XAxis");
146 if(!xAxis.is())
147 return;
149 bool bSetScaleData = false;
151 chart2::ScaleData aScaleData( xAxis->getScaleData() );
153 bool bBool = false;
154 switch( eScaleProperty )
156 case SCALE_PROP_MAX:
158 aScaleData.Maximum = rOuterValue;
159 bSetScaleData = true;
160 break;
162 case SCALE_PROP_MIN:
164 aScaleData.Minimum = rOuterValue;
165 bSetScaleData = true;
166 break;
168 case SCALE_PROP_STEPMAIN:
170 aScaleData.IncrementData.Distance = rOuterValue;
171 bSetScaleData = true;
172 break;
174 case SCALE_PROP_STEPHELP:
176 Sequence< chart2::SubIncrement >& rSubIncrements( aScaleData.IncrementData.SubIncrements );
177 if( rSubIncrements.getLength() == 0 )
178 rSubIncrements.realloc( 1 );
180 double fStepHelp = 0;
181 if( (rOuterValue >>= fStepHelp) )
183 double fStepMain = 0;
184 if( AxisHelper::isLogarithmic(aScaleData.Scaling) )
186 sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepHelp);
187 rSubIncrements[ 0 ].IntervalCount <<= nIntervalCount;
189 else if( (fStepHelp != 0.0) &&
190 (aScaleData.IncrementData.Distance >>= fStepMain) )
192 // approximate interval count
193 sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);//cppcheck-suppress zerodiv
194 rSubIncrements[ 0 ].IntervalCount <<= nIntervalCount;
197 bSetScaleData = true;
198 break;
200 case SCALE_PROP_STEPHELP_COUNT:
202 Sequence< chart2::SubIncrement >& rSubIncrements( aScaleData.IncrementData.SubIncrements );
203 if( rSubIncrements.getLength() == 0 )
204 rSubIncrements.realloc( 1 );
205 sal_Int32 nIntervalCount=0;
206 if( rOuterValue>>=nIntervalCount )
207 rSubIncrements[ 0 ].IntervalCount <<= nIntervalCount;
208 else
209 rSubIncrements[ 0 ].IntervalCount = Any();
210 bSetScaleData = true;
211 break;
213 case SCALE_PROP_AUTO_MAX:
215 if( (rOuterValue >>= bBool) && bBool )
216 aScaleData.Maximum = Any();
217 else
218 aScaleData.Maximum = getPropertyValue( SCALE_PROP_MAX, xInnerPropertySet );
219 bSetScaleData = true;
220 break;
222 case SCALE_PROP_AUTO_MIN:
224 if( (rOuterValue >>= bBool) && bBool )
225 aScaleData.Minimum = Any();
226 else
227 aScaleData.Minimum = getPropertyValue( SCALE_PROP_MIN, xInnerPropertySet );
228 bSetScaleData = true;
229 break;
231 case SCALE_PROP_AUTO_STEPMAIN:
233 if( (rOuterValue >>= bBool) && bBool )
234 aScaleData.IncrementData.Distance = Any();
235 else
236 aScaleData.IncrementData.Distance = getPropertyValue( SCALE_PROP_STEPMAIN, xInnerPropertySet );
237 bSetScaleData = true;
238 break;
240 case SCALE_PROP_AUTO_STEPHELP:
242 Sequence< chart2::SubIncrement >& rSubIncrements( aScaleData.IncrementData.SubIncrements );
243 if( rSubIncrements.getLength() == 0 )
244 rSubIncrements.realloc( 1 );
246 if( (rOuterValue >>= bBool) && bBool )
247 rSubIncrements[ 0 ].IntervalCount = Any();
248 else
249 rSubIncrements[ 0 ].IntervalCount = getPropertyValue( SCALE_PROP_STEPHELP_COUNT, xInnerPropertySet );
250 bSetScaleData = true;
251 break;
253 case SCALE_PROP_ORIGIN:
255 aScaleData.Origin = rOuterValue;
256 bSetScaleData = true;
257 break;
259 case SCALE_PROP_AUTO_ORIGIN:
261 if( (rOuterValue >>= bBool) && bBool )
262 aScaleData.Origin = Any();
263 else
264 aScaleData.Origin = getPropertyValue( SCALE_PROP_ORIGIN, xInnerPropertySet );
265 bSetScaleData = true;
266 break;
268 case SCALE_PROP_AXIS_TYPE:
270 sal_Int32 nType = 0;
271 if( (rOuterValue >>= nType) )
273 if( ::com::sun::star::chart::ChartAxisType::AUTOMATIC == nType )
275 aScaleData.AutoDateAxis = true;
276 if( aScaleData.AxisType == AxisType::DATE )
277 aScaleData.AxisType = AxisType::CATEGORY;
279 else if( ::com::sun::star::chart::ChartAxisType::CATEGORY == nType )
281 aScaleData.AutoDateAxis = false;
282 if( aScaleData.AxisType == AxisType::DATE )
283 aScaleData.AxisType = AxisType::CATEGORY;
285 else if( ::com::sun::star::chart::ChartAxisType::DATE == nType )
287 if( aScaleData.AxisType == AxisType::CATEGORY )
288 aScaleData.AxisType = AxisType::DATE;
290 bSetScaleData = true;
292 break;
294 case SCALE_PROP_DATE_INCREMENT:
296 TimeIncrement aTimeIncrement;
297 rOuterValue >>= aTimeIncrement;
298 aScaleData.TimeIncrement = aTimeIncrement;
299 bSetScaleData = true;
300 break;
302 case SCALE_PROP_EXPLICIT_DATE_INCREMENT:
303 //read only property
304 break;
305 case SCALE_PROP_LOGARITHMIC:
307 if( rOuterValue >>= bBool )
309 bool bWasLogarithm = AxisHelper::isLogarithmic( aScaleData.Scaling );
311 // safe comparison between sal_Bool and bool
312 if( (!bBool) != (!bWasLogarithm) )
314 if( bBool )
315 aScaleData.Scaling = AxisHelper::createLogarithmicScaling( 10.0 );
316 else
317 aScaleData.Scaling = 0;
318 bSetScaleData = true;
321 break;
323 case SCALE_PROP_REVERSEDIRECTION:
325 if( rOuterValue >>= bBool )
327 bool bWasReverse = ( AxisOrientation_REVERSE == aScaleData.Orientation );
328 if( (!bBool) != (!bWasReverse) ) // safe comparison between sal_Bool and bool
330 aScaleData.Orientation = bBool ? AxisOrientation_REVERSE : AxisOrientation_MATHEMATICAL;
331 bSetScaleData = true;
334 break;
336 default:
338 OSL_FAIL("unknown scale property");
339 break;
343 if( bSetScaleData )
344 xAxis->setScaleData( aScaleData );
347 Any WrappedScaleProperty::getPropertyValue( tScaleProperty eScaleProperty, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
348 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
350 Any aRet( m_aOuterValue );
352 Reference< chart2::XAxis > xAxis( xInnerPropertySet, uno::UNO_QUERY );
353 OSL_ENSURE(xAxis.is(),"need an XAxis");
354 if(!xAxis.is())
355 return aRet;
357 chart2::ScaleData aScaleData( xAxis->getScaleData() );
359 ExplicitScaleData aExplicitScale;
360 ExplicitIncrementData aExplicitIncrement;
362 switch( eScaleProperty )
364 case SCALE_PROP_MAX:
366 aRet = aScaleData.Maximum;
367 if( !aRet.hasValue() )
369 m_spChart2ModelContact->getExplicitValuesForAxis(
370 xAxis, aExplicitScale, aExplicitIncrement );
371 aRet <<= aExplicitScale.Maximum;
373 break;
375 case SCALE_PROP_MIN:
377 aRet = aScaleData.Minimum;
378 if( !aRet.hasValue() )
380 m_spChart2ModelContact->getExplicitValuesForAxis(
381 xAxis, aExplicitScale, aExplicitIncrement );
382 aRet <<= aExplicitScale.Minimum;
384 break;
387 case SCALE_PROP_STEPMAIN:
389 aRet = aScaleData.IncrementData.Distance;
390 if( !aRet.hasValue() )
392 m_spChart2ModelContact->getExplicitValuesForAxis(
393 xAxis, aExplicitScale, aExplicitIncrement );
394 aRet <<= aExplicitIncrement.Distance;
396 break;
398 case SCALE_PROP_STEPHELP:
400 // todo: evaluate PostEquidistant
401 bool bNeedToCalculateExplicitValues = true;
403 bool bLogarithmic( AxisHelper::isLogarithmic(aScaleData.Scaling) );
404 Sequence< chart2::SubIncrement >& rSubIncrements( aScaleData.IncrementData.SubIncrements );
405 if( bLogarithmic )
407 if( rSubIncrements.getLength() > 0 )
409 sal_Int32 nIntervalCount = 0;
410 rSubIncrements[ 0 ].IntervalCount >>= nIntervalCount;
411 aRet = uno::makeAny( double(nIntervalCount) );
412 bNeedToCalculateExplicitValues = false;
415 else if( aScaleData.IncrementData.Distance.hasValue() )
417 if( rSubIncrements.getLength() > 0 )
419 double fStepMain = 0;
420 sal_Int32 nIntervalCount = 0;
421 if( (aScaleData.IncrementData.Distance >>= fStepMain) &&
422 (rSubIncrements[ 0 ].IntervalCount >>= nIntervalCount) &&
423 nIntervalCount > 0 )
425 aRet <<= ( fStepMain / static_cast< double >( nIntervalCount ) );
426 bNeedToCalculateExplicitValues = false;
429 else
431 aRet = aScaleData.IncrementData.Distance;
432 bNeedToCalculateExplicitValues = false;
436 if( bNeedToCalculateExplicitValues )
438 m_spChart2ModelContact->getExplicitValuesForAxis(
439 xAxis, aExplicitScale, aExplicitIncrement );
441 if( !aExplicitIncrement.SubIncrements.empty() &&
442 aExplicitIncrement.SubIncrements[ 0 ].IntervalCount > 0 )
444 if( bLogarithmic )
446 if( rSubIncrements.getLength() > 0 )
448 sal_Int32 nIntervalCount = aExplicitIncrement.SubIncrements[ 0 ].IntervalCount;
449 aRet = uno::makeAny( double(nIntervalCount) );
452 else
453 aRet <<= ( aExplicitIncrement.Distance /
454 static_cast< double >(
455 aExplicitIncrement.SubIncrements[ 0 ].IntervalCount ));
457 else
459 if( bLogarithmic )
460 aRet <<= 5.0;
461 else
462 aRet <<= aExplicitIncrement.Distance;
465 break;
467 case SCALE_PROP_STEPHELP_COUNT:
469 sal_Int32 nIntervalCount = 0;
470 bool bNeedToCalculateExplicitValues = true;
471 Sequence< chart2::SubIncrement >& rSubIncrements( aScaleData.IncrementData.SubIncrements );
472 if( rSubIncrements.getLength() > 0 )
474 if( (rSubIncrements[ 0 ].IntervalCount >>= nIntervalCount) && (nIntervalCount > 0) )
475 bNeedToCalculateExplicitValues = false;
477 if( bNeedToCalculateExplicitValues )
479 m_spChart2ModelContact->getExplicitValuesForAxis( xAxis, aExplicitScale, aExplicitIncrement );
480 if( !aExplicitIncrement.SubIncrements.empty() )
481 nIntervalCount = aExplicitIncrement.SubIncrements[ 0 ].IntervalCount;
483 aRet = uno::makeAny( nIntervalCount );
484 break;
486 case SCALE_PROP_AUTO_MAX:
488 aRet <<= !aScaleData.Maximum.hasValue();
489 break;
491 case SCALE_PROP_AUTO_MIN:
493 aRet <<= !aScaleData.Minimum.hasValue();
494 break;
496 case SCALE_PROP_AUTO_STEPMAIN:
498 aRet <<= !aScaleData.IncrementData.Distance.hasValue();
499 break;
501 case SCALE_PROP_AUTO_STEPHELP:
503 Sequence< chart2::SubIncrement >& rSubIncrements( aScaleData.IncrementData.SubIncrements );
504 if( rSubIncrements.getLength() > 0 )
505 aRet <<= !rSubIncrements[ 0 ].IntervalCount.hasValue();
506 else
507 aRet <<= true;
508 break;
510 case SCALE_PROP_ORIGIN:
512 aRet = aScaleData.Origin;
513 if( !aRet.hasValue() )
515 m_spChart2ModelContact->getExplicitValuesForAxis(
516 xAxis, aExplicitScale, aExplicitIncrement );
517 aRet <<= aExplicitScale.Origin;
519 break;
521 case SCALE_PROP_AUTO_ORIGIN:
523 aRet <<= !hasDoubleValue(aScaleData.Origin);
524 break;
526 case SCALE_PROP_AXIS_TYPE:
528 sal_Int32 nType = ::com::sun::star::chart::ChartAxisType::AUTOMATIC;
529 if( aScaleData.AxisType == AxisType::DATE )
531 nType = ::com::sun::star::chart::ChartAxisType::DATE;
533 else if( aScaleData.AxisType == AxisType::CATEGORY )
535 if( !aScaleData.AutoDateAxis )
536 nType = ::com::sun::star::chart::ChartAxisType::CATEGORY;
538 aRet = uno::makeAny( nType );
539 break;
541 case SCALE_PROP_DATE_INCREMENT:
543 if( aScaleData.AxisType == AxisType::DATE || aScaleData.AutoDateAxis )
544 aRet = uno::makeAny( aScaleData.TimeIncrement );
545 break;
547 case SCALE_PROP_EXPLICIT_DATE_INCREMENT:
549 if( aScaleData.AxisType == AxisType::DATE || aScaleData.AutoDateAxis )
551 m_spChart2ModelContact->getExplicitValuesForAxis( xAxis, aExplicitScale, aExplicitIncrement );
552 if( aExplicitScale.AxisType == AxisType::DATE )
554 TimeIncrement aTimeIncrement;
555 aTimeIncrement.MajorTimeInterval = uno::makeAny( aExplicitIncrement.MajorTimeInterval );
556 aTimeIncrement.MinorTimeInterval = uno::makeAny( aExplicitIncrement.MinorTimeInterval );
557 aTimeIncrement.TimeResolution = uno::makeAny( aExplicitScale.TimeResolution );
558 aRet = uno::makeAny(aTimeIncrement);
562 if( aScaleData.AxisType == AxisType::DATE || aScaleData.AutoDateAxis )
563 aRet = uno::makeAny( aScaleData.TimeIncrement );
564 break;
566 case SCALE_PROP_LOGARITHMIC:
568 aRet <<= AxisHelper::isLogarithmic(aScaleData.Scaling);
569 break;
571 case SCALE_PROP_REVERSEDIRECTION:
573 aRet <<= AxisOrientation_REVERSE == aScaleData.Orientation;
574 break;
576 default:
578 OSL_FAIL("unknown scale property");
579 break;
583 return aRet;
586 } // namespace wrapper
587 } // namespace chart
589 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */