Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / source / controller / itemsetwrapper / AxisItemConverter.cxx
blob79020e023af247333ce29048691a7e08daf9ab16
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 <AxisItemConverter.hxx>
21 #include <ItemPropertyMap.hxx>
22 #include <CharacterPropertyItemConverter.hxx>
23 #include <GraphicPropertyItemConverter.hxx>
24 #include <chartview/ChartSfxItemIds.hxx>
25 #include <chartview/ExplicitScaleValues.hxx>
26 #include <chartview/ExplicitValueProvider.hxx>
27 #include "SchWhichPairs.hxx"
28 #include <ChartModelHelper.hxx>
29 #include <ChartModel.hxx>
30 #include <Axis.hxx>
31 #include <AxisHelper.hxx>
32 #include <CommonConverters.hxx>
33 #include <ChartType.hxx>
34 #include <ChartTypeHelper.hxx>
35 #include <Diagram.hxx>
36 #include <unonames.hxx>
37 #include <BaseCoordinateSystem.hxx>
38 #include <memory>
40 #include <com/sun/star/chart/ChartAxisLabelPosition.hpp>
41 #include <com/sun/star/chart/ChartAxisMarkPosition.hpp>
42 #include <com/sun/star/chart/ChartAxisPosition.hpp>
43 #include <com/sun/star/chart/TimeInterval.hpp>
44 #include <com/sun/star/chart2/XAxis.hpp>
45 #include <com/sun/star/chart2/AxisOrientation.hpp>
46 #include <com/sun/star/chart2/AxisType.hpp>
48 #include <osl/diagnose.h>
49 #include <o3tl/any.hxx>
50 #include <svl/eitem.hxx>
51 #include <svx/chrtitem.hxx>
52 #include <svx/sdangitm.hxx>
53 #include <svl/intitem.hxx>
54 #include <rtl/math.hxx>
56 using namespace ::com::sun::star;
57 using namespace ::com::sun::star::chart2;
58 using ::com::sun::star::uno::Reference;
59 using ::com::sun::star::chart::TimeInterval;
60 using ::com::sun::star::chart::TimeIncrement;
62 namespace chart::wrapper {
64 namespace {
66 ItemPropertyMapType & lcl_GetAxisPropertyMap()
68 static ItemPropertyMapType aAxisPropertyMap{
69 {SCHATTR_AXIS_SHOWDESCR, {"DisplayLabels", 0}},
70 {SCHATTR_AXIS_TICKS, {"MajorTickmarks", 0}},
71 {SCHATTR_AXIS_HELPTICKS, {"MinorTickmarks", 0}},
72 {SCHATTR_AXIS_LABEL_ORDER, {"ArrangeOrder", 0}},
73 {SCHATTR_TEXT_STACKED, {"StackCharacters", 0}},
74 {SCHATTR_AXIS_LABEL_BREAK, {"TextBreak", 0}},
75 {SCHATTR_AXIS_LABEL_OVERLAP, {"TextOverlap", 0}}};
76 return aAxisPropertyMap;
79 } // anonymous namespace
81 AxisItemConverter::AxisItemConverter(
82 const Reference< beans::XPropertySet > & rPropertySet,
83 SfxItemPool& rItemPool,
84 SdrModel& rDrawModel,
85 const rtl::Reference<::chart::ChartModel> & xChartDoc,
86 ::chart::ExplicitScaleData const * pScale /* = NULL */,
87 ::chart::ExplicitIncrementData const * pIncrement /* = NULL */,
88 const awt::Size* pRefSize ) :
89 ItemConverter( rPropertySet, rItemPool ),
90 m_xChartDoc( xChartDoc )
92 if( pScale )
93 m_pExplicitScale.reset( new ::chart::ExplicitScaleData( *pScale ) );
94 if( pIncrement )
95 m_pExplicitIncrement.reset( new ::chart::ExplicitIncrementData( *pIncrement ) );
97 m_aConverters.emplace_back( new GraphicPropertyItemConverter(
98 rPropertySet, rItemPool, rDrawModel,
99 xChartDoc,
100 GraphicObjectType::LineProperties ));
101 m_aConverters.emplace_back(
102 new CharacterPropertyItemConverter(rPropertySet, rItemPool, pRefSize, "ReferencePageSize"));
104 m_xAxis = dynamic_cast<::chart::Axis*>(rPropertySet.get());
105 assert(m_xAxis);
108 AxisItemConverter::~AxisItemConverter()
112 void AxisItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
114 for( const auto& pConv : m_aConverters )
115 pConv->FillItemSet( rOutItemSet );
117 // own items
118 ItemConverter::FillItemSet( rOutItemSet );
121 bool AxisItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
123 bool bResult = false;
125 for( const auto& pConv : m_aConverters )
126 bResult = pConv->ApplyItemSet( rItemSet ) || bResult;
128 // own items
129 return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
132 const WhichRangesContainer& AxisItemConverter::GetWhichPairs() const
134 // must span all used items!
135 return nAxisWhichPairs;
138 bool AxisItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
140 ItemPropertyMapType & rMap( lcl_GetAxisPropertyMap());
141 ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
143 if( aIt == rMap.end())
144 return false;
146 rOutProperty =(*aIt).second;
148 return true;
151 static bool lcl_hasTimeIntervalValue( const uno::Any& rAny )
153 bool bRet = false;
154 TimeInterval aValue;
155 if( rAny >>= aValue )
156 bRet = true;
157 return bRet;
160 void AxisItemConverter::FillSpecialItem( sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
162 if( !m_xAxis.is() )
163 return;
165 const chart2::ScaleData& rScale( m_xAxis->getScaleData() );
166 const chart2::IncrementData& rIncrement( rScale.IncrementData );
167 const uno::Sequence< chart2::SubIncrement >& rSubIncrements( rScale.IncrementData.SubIncrements );
168 const TimeIncrement& rTimeIncrement( rScale.TimeIncrement );
169 bool bDateAxis = (rScale.AxisType == chart2::AxisType::DATE);
170 if( m_pExplicitScale )
171 bDateAxis = (m_pExplicitScale->AxisType == chart2::AxisType::DATE);
173 switch( nWhichId )
175 case SCHATTR_AXIS_AUTO_MAX:
176 rOutItemSet.Put( SfxBoolItem( nWhichId, !hasDoubleValue(rScale.Maximum) ) );
177 break;
179 case SCHATTR_AXIS_MAX:
181 double fMax = 10.0;
182 if( rScale.Maximum >>= fMax )
183 rOutItemSet.Put( SvxDoubleItem( fMax, SCHATTR_AXIS_MAX ) );
184 else
186 if( m_pExplicitScale )
187 fMax = m_pExplicitScale->Maximum;
188 rOutItemSet.Put( SvxDoubleItem( fMax, SCHATTR_AXIS_MAX ) );
191 break;
193 case SCHATTR_AXIS_AUTO_MIN:
194 rOutItemSet.Put( SfxBoolItem( nWhichId, !hasDoubleValue(rScale.Minimum) ) );
195 break;
197 case SCHATTR_AXIS_MIN:
199 double fMin = 0.0;
200 if( rScale.Minimum >>= fMin )
201 rOutItemSet.Put( SvxDoubleItem( fMin, SCHATTR_AXIS_MIN ) );
202 else if( m_pExplicitScale )
203 rOutItemSet.Put( SvxDoubleItem( m_pExplicitScale->Minimum, SCHATTR_AXIS_MIN ));
205 break;
207 case SCHATTR_AXIS_LOGARITHM:
209 bool bValue = AxisHelper::isLogarithmic( rScale.Scaling );
210 rOutItemSet.Put( SfxBoolItem( nWhichId, bValue ));
212 break;
214 case SCHATTR_AXIS_REVERSE:
215 rOutItemSet.Put( SfxBoolItem( nWhichId, (rScale.Orientation == AxisOrientation_REVERSE) ));
216 break;
218 // Increment
219 case SCHATTR_AXIS_AUTO_STEP_MAIN:
220 if( bDateAxis )
221 rOutItemSet.Put( SfxBoolItem( nWhichId, !lcl_hasTimeIntervalValue(rTimeIncrement.MajorTimeInterval) ) );
222 else
223 rOutItemSet.Put( SfxBoolItem( nWhichId, !hasDoubleValue(rIncrement.Distance) ) );
224 break;
226 case SCHATTR_AXIS_MAIN_TIME_UNIT:
228 TimeInterval aTimeInterval;
229 if( rTimeIncrement.MajorTimeInterval >>= aTimeInterval )
230 rOutItemSet.Put( SfxInt32Item( nWhichId, aTimeInterval.TimeUnit ) );
231 else if( m_pExplicitIncrement )
232 rOutItemSet.Put( SfxInt32Item( nWhichId, m_pExplicitIncrement->MajorTimeInterval.TimeUnit ) );
234 break;
236 case SCHATTR_AXIS_STEP_MAIN:
237 if( bDateAxis )
239 TimeInterval aTimeInterval;
240 if( rTimeIncrement.MajorTimeInterval >>= aTimeInterval )
241 rOutItemSet.Put( SvxDoubleItem(aTimeInterval.Number, SCHATTR_AXIS_STEP_MAIN ));
242 else if( m_pExplicitIncrement )
243 rOutItemSet.Put( SvxDoubleItem( m_pExplicitIncrement->MajorTimeInterval.Number, SCHATTR_AXIS_STEP_MAIN ));
245 else
247 double fDistance = 1.0;
248 if( rIncrement.Distance >>= fDistance )
249 rOutItemSet.Put( SvxDoubleItem(fDistance, SCHATTR_AXIS_STEP_MAIN ));
250 else if( m_pExplicitIncrement )
251 rOutItemSet.Put( SvxDoubleItem( m_pExplicitIncrement->Distance, SCHATTR_AXIS_STEP_MAIN ));
253 break;
255 // SubIncrement
256 case SCHATTR_AXIS_AUTO_STEP_HELP:
257 if( bDateAxis )
258 rOutItemSet.Put( SfxBoolItem( nWhichId, !lcl_hasTimeIntervalValue(rTimeIncrement.MinorTimeInterval) ) );
259 else
260 rOutItemSet.Put( SfxBoolItem( nWhichId,
261 ! ( rSubIncrements.hasElements() && rSubIncrements[0].IntervalCount.hasValue() )));
262 break;
264 case SCHATTR_AXIS_HELP_TIME_UNIT:
266 TimeInterval aTimeInterval;
267 if( rTimeIncrement.MinorTimeInterval >>= aTimeInterval )
268 rOutItemSet.Put( SfxInt32Item( nWhichId, aTimeInterval.TimeUnit ) );
269 else if( m_pExplicitIncrement )
270 rOutItemSet.Put( SfxInt32Item( nWhichId, m_pExplicitIncrement->MinorTimeInterval.TimeUnit ) );
272 break;
274 case SCHATTR_AXIS_STEP_HELP:
275 if( bDateAxis )
277 TimeInterval aTimeInterval;
278 if( rTimeIncrement.MinorTimeInterval >>= aTimeInterval )
279 rOutItemSet.Put( SfxInt32Item( nWhichId, aTimeInterval.Number ));
280 else if( m_pExplicitIncrement )
281 rOutItemSet.Put( SfxInt32Item( nWhichId, m_pExplicitIncrement->MinorTimeInterval.Number ));
283 else
285 if( rSubIncrements.hasElements() && rSubIncrements[0].IntervalCount.hasValue())
287 rOutItemSet.Put( SfxInt32Item( nWhichId,
288 *o3tl::doAccess<sal_Int32>(
289 rSubIncrements[0].IntervalCount) ));
291 else
293 if( m_pExplicitIncrement && !m_pExplicitIncrement->SubIncrements.empty() )
295 rOutItemSet.Put( SfxInt32Item( nWhichId,
296 m_pExplicitIncrement->SubIncrements[0].IntervalCount ));
300 break;
302 case SCHATTR_AXIS_AUTO_TIME_RESOLUTION:
304 rOutItemSet.Put( SfxBoolItem( nWhichId,
305 !rTimeIncrement.TimeResolution.hasValue() ));
307 break;
308 case SCHATTR_AXIS_TIME_RESOLUTION:
310 sal_Int32 nTimeResolution=0;
311 if( rTimeIncrement.TimeResolution >>= nTimeResolution )
312 rOutItemSet.Put( SfxInt32Item( nWhichId, nTimeResolution ) );
313 else if( m_pExplicitScale )
314 rOutItemSet.Put( SfxInt32Item( nWhichId, m_pExplicitScale->TimeResolution ) );
316 break;
318 case SCHATTR_AXIS_AUTO_ORIGIN:
320 rOutItemSet.Put( SfxBoolItem( nWhichId, ( !hasDoubleValue(rScale.Origin) )));
322 break;
324 case SCHATTR_AXIS_ORIGIN:
326 double fOrigin = 0.0;
327 if( !(rScale.Origin >>= fOrigin) )
329 if( m_pExplicitScale )
330 fOrigin = m_pExplicitScale->Origin;
332 rOutItemSet.Put( SvxDoubleItem( fOrigin, SCHATTR_AXIS_ORIGIN ));
334 break;
336 case SCHATTR_AXIS_POSITION:
338 css::chart::ChartAxisPosition eAxisPos( css::chart::ChartAxisPosition_ZERO );
339 GetPropertySet()->getPropertyValue( "CrossoverPosition" ) >>= eAxisPos;
340 rOutItemSet.Put( SfxInt32Item( nWhichId, static_cast<sal_Int32>(eAxisPos) ) );
342 break;
344 case SCHATTR_AXIS_POSITION_VALUE:
346 double fValue = 0.0;
347 if( GetPropertySet()->getPropertyValue( "CrossoverValue" ) >>= fValue )
348 rOutItemSet.Put( SvxDoubleItem( fValue, SCHATTR_AXIS_POSITION_VALUE ) );
350 break;
352 case SCHATTR_AXIS_CROSSING_MAIN_AXIS_NUMBERFORMAT:
354 //read only item
355 //necessary tp display the crossing value with an appropriate format
357 rtl::Reference< BaseCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis(
358 m_xAxis, m_xChartDoc->getFirstChartDiagram() ) );
360 rtl::Reference< Axis > xCrossingMainAxis = AxisHelper::getCrossingMainAxis( m_xAxis, xCooSys );
362 sal_Int32 nFormatKey = ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
363 xCrossingMainAxis, xCooSys, m_xChartDoc);
365 rOutItemSet.Put( SfxUInt32Item( nWhichId, nFormatKey ));
367 break;
369 case SCHATTR_AXIS_SHIFTED_CATEGORY_POSITION:
370 rOutItemSet.Put(SfxBoolItem(nWhichId, rScale.ShiftedCategoryPosition));
371 break;
373 case SCHATTR_AXIS_LABEL_POSITION:
375 css::chart::ChartAxisLabelPosition ePos( css::chart::ChartAxisLabelPosition_NEAR_AXIS );
376 GetPropertySet()->getPropertyValue( "LabelPosition" ) >>= ePos;
377 rOutItemSet.Put( SfxInt32Item( nWhichId, static_cast<sal_Int32>(ePos) ) );
379 break;
381 case SCHATTR_AXIS_MARK_POSITION:
383 css::chart::ChartAxisMarkPosition ePos( css::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS );
384 GetPropertySet()->getPropertyValue( "MarkPosition" ) >>= ePos;
385 rOutItemSet.Put( SfxInt32Item( nWhichId, static_cast<sal_Int32>(ePos) ) );
387 break;
389 case SCHATTR_TEXT_DEGREES:
391 // convert double to int (times 100)
392 double fVal = 0;
394 if( GetPropertySet()->getPropertyValue( "TextRotation" ) >>= fVal )
396 rOutItemSet.Put( SdrAngleItem( SCHATTR_TEXT_DEGREES, Degree100(static_cast< sal_Int32 >(
397 ::rtl::math::round( fVal * 100.0 )) ) ));
400 break;
402 case SID_ATTR_NUMBERFORMAT_VALUE:
404 if( m_pExplicitScale )
406 rtl::Reference< BaseCoordinateSystem > xCooSys(
407 AxisHelper::getCoordinateSystemOfAxis(
408 m_xAxis, m_xChartDoc->getFirstChartDiagram() ) );
410 sal_Int32 nFormatKey = ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
411 m_xAxis, xCooSys, m_xChartDoc);
413 rOutItemSet.Put( SfxUInt32Item( nWhichId, nFormatKey ));
416 break;
418 case SID_ATTR_NUMBERFORMAT_SOURCE:
420 bool bLinkToSource = true;
421 GetPropertySet()->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bLinkToSource;
422 rOutItemSet.Put(SfxBoolItem(nWhichId, bLinkToSource));
424 break;
426 case SCHATTR_AXISTYPE:
427 rOutItemSet.Put( SfxInt32Item( nWhichId, rScale.AxisType ));
428 break;
430 case SCHATTR_AXIS_AUTO_DATEAXIS:
431 rOutItemSet.Put( SfxBoolItem( nWhichId, rScale.AutoDateAxis ));
432 break;
434 case SCHATTR_AXIS_ALLOW_DATEAXIS:
436 rtl::Reference< BaseCoordinateSystem > xCooSys(
437 AxisHelper::getCoordinateSystemOfAxis( m_xAxis, m_xChartDoc->getFirstChartDiagram() ) );
438 sal_Int32 nDimensionIndex=0; sal_Int32 nAxisIndex=0;
439 AxisHelper::getIndicesForAxis(m_xAxis, xCooSys, nDimensionIndex, nAxisIndex );
440 bool bChartTypeAllowsDateAxis = ChartTypeHelper::isSupportingDateAxis( AxisHelper::getChartTypeByIndex( xCooSys, 0 ), nDimensionIndex );
441 rOutItemSet.Put( SfxBoolItem( nWhichId, bChartTypeAllowsDateAxis ));
443 break;
447 static bool lcl_isDateAxis( const SfxItemSet & rItemSet )
449 sal_Int32 nAxisType = rItemSet.Get( SCHATTR_AXISTYPE ).GetValue();//css::chart2::AxisType
450 return (nAxisType == chart2::AxisType::DATE);
453 static bool lcl_isAutoMajor( const SfxItemSet & rItemSet )
455 bool bRet = rItemSet.Get( SCHATTR_AXIS_AUTO_STEP_MAIN ).GetValue();
456 return bRet;
459 static bool lcl_isAutoMinor( const SfxItemSet & rItemSet )
461 bool bRet = rItemSet.Get( SCHATTR_AXIS_AUTO_STEP_HELP ).GetValue();
462 return bRet;
465 bool AxisItemConverter::ApplySpecialItem( sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
467 if( !m_xAxis.is() )
468 return false;
470 chart2::ScaleData aScale( m_xAxis->getScaleData() );
472 bool bSetScale = false;
473 bool bChangedOtherwise = false;
475 uno::Any aValue;
477 switch( nWhichId )
479 case SCHATTR_AXIS_AUTO_MAX:
480 if( static_cast< const SfxBoolItem & >(rItemSet.Get( nWhichId )).GetValue() )
482 aScale.Maximum.clear();
483 bSetScale = true;
485 // else SCHATTR_AXIS_MAX must have some value
486 break;
488 case SCHATTR_AXIS_MAX:
489 // only if auto if false
490 if( ! (rItemSet.Get( SCHATTR_AXIS_AUTO_MAX ).GetValue() ))
492 rItemSet.Get( nWhichId ).QueryValue( aValue );
494 if( aScale.Maximum != aValue )
496 aScale.Maximum = aValue;
497 bSetScale = true;
500 break;
502 case SCHATTR_AXIS_AUTO_MIN:
503 if( static_cast< const SfxBoolItem & >(rItemSet.Get( nWhichId )).GetValue() )
505 aScale.Minimum.clear();
506 bSetScale = true;
508 // else SCHATTR_AXIS_MIN must have some value
509 break;
511 case SCHATTR_AXIS_MIN:
512 // only if auto if false
513 if( ! (rItemSet.Get( SCHATTR_AXIS_AUTO_MIN ).GetValue() ))
515 rItemSet.Get( nWhichId ).QueryValue( aValue );
517 if( aScale.Minimum != aValue )
519 aScale.Minimum = aValue;
520 bSetScale = true;
523 break;
525 case SCHATTR_AXIS_LOGARITHM:
527 bool bWasLogarithm = AxisHelper::isLogarithmic( aScale.Scaling );
529 if( static_cast< const SfxBoolItem & >(rItemSet.Get( nWhichId )).GetValue() )
531 // logarithm is true
532 if( ! bWasLogarithm )
534 aScale.Scaling = AxisHelper::createLogarithmicScaling( 10.0 );
535 bSetScale = true;
538 else
540 // logarithm is false => linear scaling
541 if( bWasLogarithm )
543 aScale.Scaling = AxisHelper::createLinearScaling();
544 bSetScale = true;
548 break;
550 case SCHATTR_AXIS_REVERSE:
552 bool bWasReverse = ( aScale.Orientation == AxisOrientation_REVERSE );
553 bool bNewReverse = static_cast< const SfxBoolItem & >(
554 rItemSet.Get( nWhichId )).GetValue();
555 if( bWasReverse != bNewReverse )
557 aScale.Orientation = bNewReverse ? AxisOrientation_REVERSE : AxisOrientation_MATHEMATICAL;
558 bSetScale = true;
561 break;
563 // Increment
564 case SCHATTR_AXIS_AUTO_STEP_MAIN:
565 if( lcl_isAutoMajor(rItemSet) )
567 aScale.IncrementData.Distance.clear();
568 aScale.TimeIncrement.MajorTimeInterval.clear();
569 bSetScale = true;
571 // else SCHATTR_AXIS_STEP_MAIN must have some value
572 break;
574 case SCHATTR_AXIS_MAIN_TIME_UNIT:
575 if( !lcl_isAutoMajor(rItemSet) )
577 if( rItemSet.Get( nWhichId ).QueryValue( aValue ) )
579 TimeInterval aTimeInterval;
580 aScale.TimeIncrement.MajorTimeInterval >>= aTimeInterval;
581 aValue >>= aTimeInterval.TimeUnit;
582 aScale.TimeIncrement.MajorTimeInterval <<= aTimeInterval;
583 bSetScale = true;
586 break;
588 case SCHATTR_AXIS_STEP_MAIN:
589 // only if auto if false
590 if( !lcl_isAutoMajor(rItemSet) )
592 rItemSet.Get( nWhichId ).QueryValue( aValue );
593 if( lcl_isDateAxis(rItemSet) )
595 double fValue = 1.0;
596 if( aValue >>= fValue )
598 TimeInterval aTimeInterval;
599 aScale.TimeIncrement.MajorTimeInterval >>= aTimeInterval;
600 aTimeInterval.Number = static_cast<sal_Int32>(fValue);
601 aScale.TimeIncrement.MajorTimeInterval <<= aTimeInterval;
602 bSetScale = true;
605 else if( aScale.IncrementData.Distance != aValue )
607 aScale.IncrementData.Distance = aValue;
608 bSetScale = true;
611 break;
613 // SubIncrement
614 case SCHATTR_AXIS_AUTO_STEP_HELP:
615 if( lcl_isAutoMinor(rItemSet) )
617 if( aScale.IncrementData.SubIncrements.hasElements() &&
618 aScale.IncrementData.SubIncrements[0].IntervalCount.hasValue() )
620 aScale.IncrementData.SubIncrements.getArray()[0].IntervalCount.clear();
621 bSetScale = true;
623 if( aScale.TimeIncrement.MinorTimeInterval.hasValue() )
625 aScale.TimeIncrement.MinorTimeInterval.clear();
626 bSetScale = true;
629 // else SCHATTR_AXIS_STEP_MAIN must have some value
630 break;
632 case SCHATTR_AXIS_HELP_TIME_UNIT:
633 if( !lcl_isAutoMinor(rItemSet) )
635 if( rItemSet.Get( nWhichId ).QueryValue( aValue ) )
637 TimeInterval aTimeInterval;
638 aScale.TimeIncrement.MinorTimeInterval >>= aTimeInterval;
639 aValue >>= aTimeInterval.TimeUnit;
640 aScale.TimeIncrement.MinorTimeInterval <<= aTimeInterval;
641 bSetScale = true;
644 break;
646 case SCHATTR_AXIS_STEP_HELP:
647 // only if auto is false
648 if( !lcl_isAutoMinor(rItemSet) )
650 rItemSet.Get( nWhichId ).QueryValue( aValue );
651 if( lcl_isDateAxis(rItemSet) )
653 TimeInterval aTimeInterval;
654 aScale.TimeIncrement.MinorTimeInterval >>= aTimeInterval;
655 aValue >>= aTimeInterval.Number;
656 aScale.TimeIncrement.MinorTimeInterval <<= aTimeInterval;
657 bSetScale = true;
659 else if( aScale.IncrementData.SubIncrements.hasElements() )
661 if( ! aScale.IncrementData.SubIncrements[0].IntervalCount.hasValue() ||
662 aScale.IncrementData.SubIncrements[0].IntervalCount != aValue )
664 OSL_ASSERT( aValue.getValueTypeClass() == uno::TypeClass_LONG );
665 aScale.IncrementData.SubIncrements.getArray()[0].IntervalCount = aValue;
666 bSetScale = true;
670 break;
672 case SCHATTR_AXIS_AUTO_TIME_RESOLUTION:
673 if( static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId )).GetValue() )
675 aScale.TimeIncrement.TimeResolution.clear();
676 bSetScale = true;
678 break;
679 case SCHATTR_AXIS_TIME_RESOLUTION:
680 // only if auto is false
681 if( ! ( rItemSet.Get( SCHATTR_AXIS_AUTO_TIME_RESOLUTION ).GetValue() ))
683 rItemSet.Get( nWhichId ).QueryValue( aValue );
685 if( aScale.TimeIncrement.TimeResolution != aValue )
687 aScale.TimeIncrement.TimeResolution = aValue;
688 bSetScale = true;
691 break;
693 case SCHATTR_AXIS_AUTO_ORIGIN:
695 if( static_cast< const SfxBoolItem & >(rItemSet.Get( nWhichId )).GetValue() )
697 aScale.Origin.clear();
698 bSetScale = true;
701 break;
703 case SCHATTR_AXIS_ORIGIN:
705 // only if auto is false
706 if( ! (rItemSet.Get( SCHATTR_AXIS_AUTO_ORIGIN ).GetValue() ))
708 rItemSet.Get( nWhichId ).QueryValue( aValue );
710 if( aScale.Origin != aValue )
712 aScale.Origin = aValue;
713 bSetScale = true;
715 if( !AxisHelper::isAxisPositioningEnabled() )
717 //keep old and new settings for axis positioning in sync somehow
718 rtl::Reference< BaseCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis(
719 m_xAxis, m_xChartDoc->getFirstChartDiagram() ) );
721 sal_Int32 nDimensionIndex=0;
722 sal_Int32 nAxisIndex=0;
723 if( AxisHelper::getIndicesForAxis( m_xAxis, xCooSys, nDimensionIndex, nAxisIndex ) && nAxisIndex==0 )
725 rtl::Reference< Axis > xCrossingMainAxis = AxisHelper::getCrossingMainAxis( m_xAxis, xCooSys );
726 if( xCrossingMainAxis.is() )
728 double fValue = 0.0;
729 if( aValue >>= fValue )
731 xCrossingMainAxis->setPropertyValue( "CrossoverPosition" , uno::Any( css::chart::ChartAxisPosition_VALUE ));
732 xCrossingMainAxis->setPropertyValue( "CrossoverValue" , uno::Any( fValue ));
734 else
735 xCrossingMainAxis->setPropertyValue( "CrossoverPosition" , uno::Any( css::chart::ChartAxisPosition_START ));
742 break;
744 case SCHATTR_AXIS_POSITION:
746 css::chart::ChartAxisPosition eAxisPos =
747 static_cast<css::chart::ChartAxisPosition>(static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue());
749 css::chart::ChartAxisPosition eOldAxisPos( css::chart::ChartAxisPosition_ZERO );
750 bool bPropExisted = ( GetPropertySet()->getPropertyValue( "CrossoverPosition" ) >>= eOldAxisPos );
752 if( !bPropExisted || ( eOldAxisPos != eAxisPos ))
754 GetPropertySet()->setPropertyValue( "CrossoverPosition" , uno::Any( eAxisPos ));
755 bChangedOtherwise = true;
757 //move the parallel axes to the other side if necessary
758 if( eAxisPos==css::chart::ChartAxisPosition_START || eAxisPos==css::chart::ChartAxisPosition_END )
760 rtl::Reference<Diagram> xDiagram = m_xChartDoc->getFirstChartDiagram();
761 rtl::Reference< Axis > xParallelAxis = AxisHelper::getParallelAxis( m_xAxis, xDiagram );
762 if( xParallelAxis.is() )
764 css::chart::ChartAxisPosition eOtherPos;
765 if( xParallelAxis->getPropertyValue( "CrossoverPosition" ) >>= eOtherPos )
767 if( eOtherPos == eAxisPos )
769 css::chart::ChartAxisPosition eOppositePos =
770 (eAxisPos==css::chart::ChartAxisPosition_START)
771 ? css::chart::ChartAxisPosition_END
772 : css::chart::ChartAxisPosition_START;
773 xParallelAxis->setPropertyValue( "CrossoverPosition" , uno::Any( eOppositePos ));
780 break;
782 case SCHATTR_AXIS_POSITION_VALUE:
784 double fValue = static_cast< const SvxDoubleItem & >( rItemSet.Get( nWhichId )).GetValue();
786 double fOldValue = 0.0;
787 bool bPropExisted = ( GetPropertySet()->getPropertyValue( "CrossoverValue" ) >>= fOldValue );
789 if( !bPropExisted || ( fOldValue != fValue ))
791 GetPropertySet()->setPropertyValue( "CrossoverValue" , uno::Any( fValue ));
792 bChangedOtherwise = true;
794 //keep old and new settings for axis positioning in sync somehow
796 rtl::Reference< BaseCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis(
797 m_xAxis, m_xChartDoc->getFirstChartDiagram() ) );
799 sal_Int32 nDimensionIndex=0;
800 sal_Int32 nAxisIndex=0;
801 if( AxisHelper::getIndicesForAxis( m_xAxis, xCooSys, nDimensionIndex, nAxisIndex ) && nAxisIndex==0 )
803 Reference< chart2::XAxis > xCrossingMainAxis( AxisHelper::getCrossingMainAxis( m_xAxis, xCooSys ) );
804 if( xCrossingMainAxis.is() )
806 ScaleData aCrossingScale( xCrossingMainAxis->getScaleData() );
807 aCrossingScale.Origin <<= fValue;
808 xCrossingMainAxis->setScaleData(aCrossingScale);
814 break;
816 case SCHATTR_AXIS_SHIFTED_CATEGORY_POSITION:
818 bool bNewValue = static_cast<const SfxBoolItem &> (rItemSet.Get(nWhichId)).GetValue();
819 bool bOldValue = aScale.ShiftedCategoryPosition;
820 if (bOldValue != bNewValue)
822 aScale.ShiftedCategoryPosition = bNewValue;
823 bSetScale = true;
826 break;
828 case SCHATTR_AXIS_LABEL_POSITION:
830 css::chart::ChartAxisLabelPosition ePos =
831 static_cast<css::chart::ChartAxisLabelPosition>(static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue());
833 css::chart::ChartAxisLabelPosition eOldPos( css::chart::ChartAxisLabelPosition_NEAR_AXIS );
834 bool bPropExisted = ( GetPropertySet()->getPropertyValue( "LabelPosition" ) >>= eOldPos );
836 if( !bPropExisted || ( eOldPos != ePos ))
838 GetPropertySet()->setPropertyValue( "LabelPosition" , uno::Any( ePos ));
839 bChangedOtherwise = true;
841 //move the parallel axes to the other side if necessary
842 if( ePos==css::chart::ChartAxisLabelPosition_OUTSIDE_START || ePos==css::chart::ChartAxisLabelPosition_OUTSIDE_END )
844 rtl::Reference<Diagram> xDiagram = m_xChartDoc->getFirstChartDiagram();
845 rtl::Reference< Axis > xParallelAxis = AxisHelper::getParallelAxis( m_xAxis, xDiagram );
846 if( xParallelAxis.is() )
848 css::chart::ChartAxisLabelPosition eOtherPos;
849 if( xParallelAxis->getPropertyValue( "LabelPosition" ) >>= eOtherPos )
851 if( eOtherPos == ePos )
853 css::chart::ChartAxisLabelPosition eOppositePos =
854 (ePos==css::chart::ChartAxisLabelPosition_OUTSIDE_START)
855 ? css::chart::ChartAxisLabelPosition_OUTSIDE_END
856 : css::chart::ChartAxisLabelPosition_OUTSIDE_START;
857 xParallelAxis->setPropertyValue( "LabelPosition" , uno::Any( eOppositePos ));
864 break;
866 case SCHATTR_AXIS_MARK_POSITION:
868 css::chart::ChartAxisMarkPosition ePos =
869 static_cast<css::chart::ChartAxisMarkPosition>(static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue());
871 css::chart::ChartAxisMarkPosition eOldPos( css::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS );
872 bool bPropExisted = ( GetPropertySet()->getPropertyValue( "MarkPosition" ) >>= eOldPos );
874 if( !bPropExisted || ( eOldPos != ePos ))
876 GetPropertySet()->setPropertyValue( "MarkPosition" , uno::Any( ePos ));
877 bChangedOtherwise = true;
880 break;
882 case SCHATTR_TEXT_DEGREES:
884 double fVal = toDegrees(rItemSet.Get(SCHATTR_TEXT_DEGREES).GetValue());
885 double fOldVal = 0.0;
886 bool bPropExisted =
887 ( GetPropertySet()->getPropertyValue( "TextRotation" ) >>= fOldVal );
889 if( ! bPropExisted || fOldVal != fVal )
891 GetPropertySet()->setPropertyValue( "TextRotation" , uno::Any( fVal ));
892 bChangedOtherwise = true;
895 break;
897 case SID_ATTR_NUMBERFORMAT_VALUE:
899 if( m_pExplicitScale )
901 bool bUseSourceFormat =
902 rItemSet.Get( SID_ATTR_NUMBERFORMAT_SOURCE ).GetValue();
904 if( ! bUseSourceFormat )
906 sal_Int32 nFmt = static_cast< sal_Int32 >(
907 static_cast< const SfxUInt32Item & >(
908 rItemSet.Get( nWhichId )).GetValue());
910 aValue <<= nFmt;
911 if (GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT) != aValue)
913 GetPropertySet()->setPropertyValue(CHART_UNONAME_NUMFMT , aValue);
914 bChangedOtherwise = true;
919 break;
921 case SID_ATTR_NUMBERFORMAT_SOURCE:
923 bool bUseSourceFormat =
924 static_cast< const SfxBoolItem & >(
925 rItemSet.Get( nWhichId )).GetValue();
926 GetPropertySet()->setPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT, uno::Any(bUseSourceFormat));
928 bool bNumberFormatIsSet = GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT).hasValue();
930 bChangedOtherwise = (bUseSourceFormat == bNumberFormatIsSet);
931 if( bChangedOtherwise )
933 if( ! bUseSourceFormat )
935 SfxItemState aState = rItemSet.GetItemState( SID_ATTR_NUMBERFORMAT_VALUE );
936 if( aState == SfxItemState::SET )
938 sal_Int32 nFormatKey = static_cast< sal_Int32 >(
939 rItemSet.Get( SID_ATTR_NUMBERFORMAT_VALUE ).GetValue());
940 aValue <<= nFormatKey;
942 else
944 rtl::Reference< BaseCoordinateSystem > xCooSys =
945 AxisHelper::getCoordinateSystemOfAxis(
946 m_xAxis, m_xChartDoc->getFirstChartDiagram() );
948 sal_Int32 nFormatKey = ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
949 m_xAxis, xCooSys, m_xChartDoc);
951 aValue <<= nFormatKey;
954 // else set a void Any
955 GetPropertySet()->setPropertyValue(CHART_UNONAME_NUMFMT , aValue);
958 break;
960 case SCHATTR_AXISTYPE:
962 sal_Int32 nNewAxisType = static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();//css::chart2::AxisType
963 aScale.AxisType = nNewAxisType;
964 bSetScale = true;
966 break;
968 case SCHATTR_AXIS_AUTO_DATEAXIS:
970 bool bNewValue = static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId )).GetValue();
971 bool bOldValue = aScale.AutoDateAxis;
972 if( bOldValue != bNewValue )
974 aScale.AutoDateAxis = bNewValue;
975 bSetScale = true;
978 break;
981 if( bSetScale )
982 m_xAxis->setScaleData( aScale );
984 return (bSetScale || bChangedOtherwise);
989 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */