fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / itemsetwrapper / AxisItemConverter.cxx
blob0c2efa7fb1ad875ce85926b54cf47aba52ff331d
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/ExplicitValueProvider.hxx"
26 #include "SchWhichPairs.hxx"
27 #include "macros.hxx"
28 #include "ChartModelHelper.hxx"
29 #include "AxisHelper.hxx"
30 #include "CommonConverters.hxx"
31 #include "ChartTypeHelper.hxx"
32 #include <unonames.hxx>
34 #include <com/sun/star/chart/ChartAxisLabelPosition.hpp>
35 #include <com/sun/star/chart/ChartAxisMarkPosition.hpp>
36 #include <com/sun/star/chart/ChartAxisPosition.hpp>
37 #include <com/sun/star/chart2/XAxis.hpp>
38 #include <com/sun/star/chart2/AxisOrientation.hpp>
39 #include <com/sun/star/chart2/AxisType.hpp>
41 #include <svl/eitem.hxx>
42 #include <svx/chrtitem.hxx>
43 #include <svl/intitem.hxx>
44 #include <rtl/math.hxx>
46 #include <algorithm>
48 using namespace ::com::sun::star;
49 using namespace ::com::sun::star::chart2;
50 using ::com::sun::star::uno::Reference;
51 using ::com::sun::star::chart::TimeInterval;
52 using ::com::sun::star::chart::TimeIncrement;
54 namespace chart { namespace wrapper {
56 namespace {
58 ItemPropertyMapType & lcl_GetAxisPropertyMap()
60 static ItemPropertyMapType aAxisPropertyMap(
61 MakeItemPropertyMap
62 IPM_MAP_ENTRY( SCHATTR_AXIS_SHOWDESCR, "DisplayLabels", 0 )
63 IPM_MAP_ENTRY( SCHATTR_AXIS_TICKS, "MajorTickmarks", 0 )
64 IPM_MAP_ENTRY( SCHATTR_AXIS_HELPTICKS, "MinorTickmarks", 0 )
65 IPM_MAP_ENTRY( SCHATTR_AXIS_LABEL_ORDER, "ArrangeOrder", 0 )
66 IPM_MAP_ENTRY( SCHATTR_TEXT_STACKED, "StackCharacters", 0 )
67 IPM_MAP_ENTRY( SCHATTR_AXIS_LABEL_BREAK, "TextBreak", 0 )
68 IPM_MAP_ENTRY( SCHATTR_AXIS_LABEL_OVERLAP, "TextOverlap", 0 )
71 return aAxisPropertyMap;
74 } // anonymous namespace
76 AxisItemConverter::AxisItemConverter(
77 const Reference< beans::XPropertySet > & rPropertySet,
78 SfxItemPool& rItemPool,
79 SdrModel& rDrawModel,
80 const Reference< chart2::XChartDocument > & xChartDoc,
81 ::chart::ExplicitScaleData * pScale /* = NULL */,
82 ::chart::ExplicitIncrementData * pIncrement /* = NULL */,
83 const awt::Size* pRefSize ) :
84 ItemConverter( rPropertySet, rItemPool ),
85 m_xChartDoc( xChartDoc ),
86 m_pExplicitScale( NULL ),
87 m_pExplicitIncrement( NULL )
89 Reference< lang::XMultiServiceFactory > xNamedPropertyContainerFactory( xChartDoc, uno::UNO_QUERY );
91 if( pScale )
92 m_pExplicitScale = new ::chart::ExplicitScaleData( *pScale );
93 if( pIncrement )
94 m_pExplicitIncrement = new ::chart::ExplicitIncrementData( *pIncrement );
96 m_aConverters.push_back( new GraphicPropertyItemConverter(
97 rPropertySet, rItemPool, rDrawModel,
98 xNamedPropertyContainerFactory,
99 GraphicPropertyItemConverter::LINE_PROPERTIES ));
100 m_aConverters.push_back(
101 new CharacterPropertyItemConverter(rPropertySet, rItemPool, pRefSize, "ReferencePageSize"));
103 m_xAxis.set( Reference< chart2::XAxis >( rPropertySet, uno::UNO_QUERY ) );
104 OSL_ASSERT( m_xAxis.is());
107 AxisItemConverter::~AxisItemConverter()
109 delete m_pExplicitScale;
110 delete m_pExplicitIncrement;
112 ::std::for_each(m_aConverters.begin(), m_aConverters.end(), boost::checked_deleter<ItemConverter>());
115 void AxisItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
117 ::std::for_each( m_aConverters.begin(), m_aConverters.end(), FillItemSetFunc( rOutItemSet ));
119 // own items
120 ItemConverter::FillItemSet( rOutItemSet );
123 bool AxisItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
125 bool bResult = false;
127 ::std::for_each( m_aConverters.begin(), m_aConverters.end(), ApplyItemSetFunc( rItemSet, bResult ));
129 // own items
130 return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
133 const sal_uInt16 * AxisItemConverter::GetWhichPairs() const
135 // must span all used items!
136 return nAxisWhichPairs;
139 bool AxisItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
141 ItemPropertyMapType & rMap( lcl_GetAxisPropertyMap());
142 ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
144 if( aIt == rMap.end())
145 return false;
147 rOutProperty =(*aIt).second;
149 return true;
152 bool lcl_hasTimeIntervalValue( const uno::Any& rAny )
154 bool bRet = false;
155 TimeInterval aValue;
156 if( rAny >>= aValue )
157 bRet = true;
158 return bRet;
161 void AxisItemConverter::FillSpecialItem( sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
162 throw( uno::Exception )
164 if( !m_xAxis.is() )
165 return;
167 const chart2::ScaleData& rScale( m_xAxis->getScaleData() );
168 const chart2::IncrementData& rIncrement( rScale.IncrementData );
169 const uno::Sequence< chart2::SubIncrement >& rSubIncrements( rScale.IncrementData.SubIncrements );
170 const TimeIncrement& rTimeIncrement( rScale.TimeIncrement );
171 bool bDateAxis = (chart2::AxisType::DATE == rScale.AxisType);
172 if( m_pExplicitScale )
173 bDateAxis = (chart2::AxisType::DATE == m_pExplicitScale->AxisType);
175 switch( nWhichId )
177 case SCHATTR_AXIS_AUTO_MAX:
178 rOutItemSet.Put( SfxBoolItem( nWhichId, !hasDoubleValue(rScale.Maximum) ) );
179 break;
181 case SCHATTR_AXIS_MAX:
183 double fMax = 10.0;
184 if( rScale.Maximum >>= fMax )
185 rOutItemSet.Put( SvxDoubleItem( fMax, nWhichId ) );
186 else
188 if( m_pExplicitScale )
189 fMax = m_pExplicitScale->Maximum;
190 rOutItemSet.Put( SvxDoubleItem( fMax, nWhichId ) );
193 break;
195 case SCHATTR_AXIS_AUTO_MIN:
196 rOutItemSet.Put( SfxBoolItem( nWhichId, !hasDoubleValue(rScale.Minimum) ) );
197 break;
199 case SCHATTR_AXIS_MIN:
201 double fMin = 0.0;
202 if( rScale.Minimum >>= fMin )
203 rOutItemSet.Put( SvxDoubleItem( fMin, nWhichId ) );
204 else if( m_pExplicitScale )
205 rOutItemSet.Put( SvxDoubleItem( m_pExplicitScale->Minimum, nWhichId ));
207 break;
209 case SCHATTR_AXIS_LOGARITHM:
211 bool bValue = AxisHelper::isLogarithmic( rScale.Scaling );
212 rOutItemSet.Put( SfxBoolItem( nWhichId, bValue ));
214 break;
216 case SCHATTR_AXIS_REVERSE:
217 rOutItemSet.Put( SfxBoolItem( nWhichId, (AxisOrientation_REVERSE == rScale.Orientation) ));
218 break;
220 // Increment
221 case SCHATTR_AXIS_AUTO_STEP_MAIN:
222 if( bDateAxis )
223 rOutItemSet.Put( SfxBoolItem( nWhichId, !lcl_hasTimeIntervalValue(rTimeIncrement.MajorTimeInterval) ) );
224 else
225 rOutItemSet.Put( SfxBoolItem( nWhichId, !hasDoubleValue(rIncrement.Distance) ) );
226 break;
228 case SCHATTR_AXIS_MAIN_TIME_UNIT:
230 TimeInterval aTimeInterval;
231 if( rTimeIncrement.MajorTimeInterval >>= aTimeInterval )
232 rOutItemSet.Put( SfxInt32Item( nWhichId, aTimeInterval.TimeUnit ) );
233 else if( m_pExplicitIncrement )
234 rOutItemSet.Put( SfxInt32Item( nWhichId, m_pExplicitIncrement->MajorTimeInterval.TimeUnit ) );
236 break;
238 case SCHATTR_AXIS_STEP_MAIN:
239 if( bDateAxis )
241 TimeInterval aTimeInterval;
242 if( rTimeIncrement.MajorTimeInterval >>= aTimeInterval )
243 rOutItemSet.Put( SvxDoubleItem(aTimeInterval.Number, nWhichId ));
244 else if( m_pExplicitIncrement )
245 rOutItemSet.Put( SvxDoubleItem( m_pExplicitIncrement->MajorTimeInterval.Number, nWhichId ));
247 else
249 double fDistance = 1.0;
250 if( rIncrement.Distance >>= fDistance )
251 rOutItemSet.Put( SvxDoubleItem(fDistance, nWhichId ));
252 else if( m_pExplicitIncrement )
253 rOutItemSet.Put( SvxDoubleItem( m_pExplicitIncrement->Distance, nWhichId ));
255 break;
257 // SubIncrement
258 case SCHATTR_AXIS_AUTO_STEP_HELP:
259 if( bDateAxis )
260 rOutItemSet.Put( SfxBoolItem( nWhichId, !lcl_hasTimeIntervalValue(rTimeIncrement.MinorTimeInterval) ) );
261 else
262 rOutItemSet.Put( SfxBoolItem( nWhichId,
263 ! ( rSubIncrements.getLength() > 0 && rSubIncrements[0].IntervalCount.hasValue() )));
264 break;
266 case SCHATTR_AXIS_HELP_TIME_UNIT:
268 TimeInterval aTimeInterval;
269 if( rTimeIncrement.MinorTimeInterval >>= aTimeInterval )
270 rOutItemSet.Put( SfxInt32Item( nWhichId, aTimeInterval.TimeUnit ) );
271 else if( m_pExplicitIncrement )
272 rOutItemSet.Put( SfxInt32Item( nWhichId, m_pExplicitIncrement->MinorTimeInterval.TimeUnit ) );
274 break;
276 case SCHATTR_AXIS_STEP_HELP:
277 if( bDateAxis )
279 TimeInterval aTimeInterval;
280 if( rTimeIncrement.MinorTimeInterval >>= aTimeInterval )
281 rOutItemSet.Put( SfxInt32Item( nWhichId, aTimeInterval.Number ));
282 else if( m_pExplicitIncrement )
283 rOutItemSet.Put( SfxInt32Item( nWhichId, m_pExplicitIncrement->MinorTimeInterval.Number ));
285 else
287 if( rSubIncrements.getLength() > 0 && rSubIncrements[0].IntervalCount.hasValue())
289 OSL_ASSERT( rSubIncrements[0].IntervalCount.getValueTypeClass() == uno::TypeClass_LONG );
290 rOutItemSet.Put( SfxInt32Item( nWhichId,
291 *static_cast< const sal_Int32 * >(
292 rSubIncrements[0].IntervalCount.getValue()) ));
294 else
296 if( m_pExplicitIncrement && !m_pExplicitIncrement->SubIncrements.empty() )
298 rOutItemSet.Put( SfxInt32Item( nWhichId,
299 m_pExplicitIncrement->SubIncrements[0].IntervalCount ));
303 break;
305 case SCHATTR_AXIS_AUTO_TIME_RESOLUTION:
307 rOutItemSet.Put( SfxBoolItem( nWhichId,
308 !rTimeIncrement.TimeResolution.hasValue() ));
310 break;
311 case SCHATTR_AXIS_TIME_RESOLUTION:
313 long nTimeResolution=0;
314 if( rTimeIncrement.TimeResolution >>= nTimeResolution )
315 rOutItemSet.Put( SfxInt32Item( nWhichId, nTimeResolution ) );
316 else if( m_pExplicitScale )
317 rOutItemSet.Put( SfxInt32Item( nWhichId, m_pExplicitScale->TimeResolution ) );
319 break;
321 case SCHATTR_AXIS_AUTO_ORIGIN:
323 rOutItemSet.Put( SfxBoolItem( nWhichId, ( !hasDoubleValue(rScale.Origin) )));
325 break;
327 case SCHATTR_AXIS_ORIGIN:
329 double fOrigin = 0.0;
330 if( !(rScale.Origin >>= fOrigin) )
332 if( m_pExplicitScale )
333 fOrigin = m_pExplicitScale->Origin;
335 rOutItemSet.Put( SvxDoubleItem( fOrigin, nWhichId ));
337 break;
339 case SCHATTR_AXIS_POSITION:
341 ::com::sun::star::chart::ChartAxisPosition eAxisPos( ::com::sun::star::chart::ChartAxisPosition_ZERO );
342 GetPropertySet()->getPropertyValue( "CrossoverPosition" ) >>= eAxisPos;
343 rOutItemSet.Put( SfxInt32Item( nWhichId, eAxisPos ) );
345 break;
347 case SCHATTR_AXIS_POSITION_VALUE:
349 double fValue = 0.0;
350 if( GetPropertySet()->getPropertyValue( "CrossoverValue" ) >>= fValue )
351 rOutItemSet.Put( SvxDoubleItem( fValue, nWhichId ) );
353 break;
355 case SCHATTR_AXIS_CROSSING_MAIN_AXIS_NUMBERFORMAT:
357 //read only item
358 //necessary tp display the crossing value with an appropriate format
360 Reference< chart2::XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis(
361 m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
363 Reference< chart2::XAxis > xCrossingMainAxis( AxisHelper::getCrossingMainAxis( m_xAxis, xCooSys ) );
365 sal_Int32 nFormatKey = ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
366 xCrossingMainAxis, xCooSys, m_xChartDoc);
368 rOutItemSet.Put( SfxUInt32Item( nWhichId, nFormatKey ));
370 break;
372 case SCHATTR_AXIS_LABEL_POSITION:
374 ::com::sun::star::chart::ChartAxisLabelPosition ePos( ::com::sun::star::chart::ChartAxisLabelPosition_NEAR_AXIS );
375 GetPropertySet()->getPropertyValue( "LabelPosition" ) >>= ePos;
376 rOutItemSet.Put( SfxInt32Item( nWhichId, ePos ) );
378 break;
380 case SCHATTR_AXIS_MARK_POSITION:
382 ::com::sun::star::chart::ChartAxisMarkPosition ePos( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS );
383 GetPropertySet()->getPropertyValue( "MarkPosition" ) >>= ePos;
384 rOutItemSet.Put( SfxInt32Item( nWhichId, ePos ) );
386 break;
388 case SCHATTR_TEXT_DEGREES:
390 // convert double to int (times 100)
391 double fVal = 0;
393 if( GetPropertySet()->getPropertyValue( "TextRotation" ) >>= fVal )
395 rOutItemSet.Put( SfxInt32Item( nWhichId, static_cast< sal_Int32 >(
396 ::rtl::math::round( fVal * 100.0 ) ) ));
399 break;
401 case SID_ATTR_NUMBERFORMAT_VALUE:
403 if( m_pExplicitScale )
405 Reference< chart2::XCoordinateSystem > xCooSys(
406 AxisHelper::getCoordinateSystemOfAxis(
407 m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
409 sal_Int32 nFormatKey = ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
410 m_xAxis, xCooSys, m_xChartDoc);
412 rOutItemSet.Put( SfxUInt32Item( nWhichId, nFormatKey ));
415 break;
417 case SID_ATTR_NUMBERFORMAT_SOURCE:
419 bool bLinkToSource = true;
420 GetPropertySet()->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bLinkToSource;
421 rOutItemSet.Put(SfxBoolItem(nWhichId, bLinkToSource));
423 break;
425 case SCHATTR_AXISTYPE:
426 rOutItemSet.Put( SfxInt32Item( nWhichId, rScale.AxisType ));
427 break;
429 case SCHATTR_AXIS_AUTO_DATEAXIS:
430 rOutItemSet.Put( SfxBoolItem( nWhichId, rScale.AutoDateAxis ));
431 break;
433 case SCHATTR_AXIS_ALLOW_DATEAXIS:
435 Reference< chart2::XCoordinateSystem > xCooSys(
436 AxisHelper::getCoordinateSystemOfAxis( m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
437 sal_Int32 nDimensionIndex=0; sal_Int32 nAxisIndex=0;
438 AxisHelper::getIndicesForAxis(m_xAxis, xCooSys, nDimensionIndex, nAxisIndex );
439 bool bChartTypeAllowsDateAxis = ChartTypeHelper::isSupportingDateAxis( AxisHelper::getChartTypeByIndex( xCooSys, 0 ), 2, nDimensionIndex );
440 rOutItemSet.Put( SfxBoolItem( nWhichId, bChartTypeAllowsDateAxis ));
442 break;
446 bool lcl_isDateAxis( const SfxItemSet & rItemSet )
448 sal_Int32 nAxisType = static_cast< const SfxInt32Item & >( rItemSet.Get( SCHATTR_AXISTYPE )).GetValue();//::com::sun::star::chart2::AxisType
449 return (chart2::AxisType::DATE == nAxisType);
452 bool lcl_isAutoMajor( const SfxItemSet & rItemSet )
454 bool bRet = static_cast< const SfxBoolItem & >( rItemSet.Get( SCHATTR_AXIS_AUTO_STEP_MAIN )).GetValue();
455 return bRet;
458 bool lcl_isAutoMinor( const SfxItemSet & rItemSet )
460 bool bRet = static_cast< const SfxBoolItem & >( rItemSet.Get( SCHATTR_AXIS_AUTO_STEP_HELP )).GetValue();
461 return bRet;
464 bool AxisItemConverter::ApplySpecialItem( sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
465 throw( uno::Exception )
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 & >(
481 rItemSet.Get( nWhichId )).GetValue() ))
483 aScale.Maximum.clear();
484 bSetScale = true;
486 // else SCHATTR_AXIS_MAX must have some value
487 break;
489 case SCHATTR_AXIS_MAX:
490 // only if auto if false
491 if( ! (static_cast< const SfxBoolItem & >(
492 rItemSet.Get( SCHATTR_AXIS_AUTO_MAX )).GetValue() ))
494 rItemSet.Get( nWhichId ).QueryValue( aValue );
496 if( aScale.Maximum != aValue )
498 aScale.Maximum = aValue;
499 bSetScale = true;
502 break;
504 case SCHATTR_AXIS_AUTO_MIN:
505 if( (static_cast< const SfxBoolItem & >(
506 rItemSet.Get( nWhichId )).GetValue() ))
508 aScale.Minimum.clear();
509 bSetScale = true;
511 // else SCHATTR_AXIS_MIN must have some value
512 break;
514 case SCHATTR_AXIS_MIN:
515 // only if auto if false
516 if( ! (static_cast< const SfxBoolItem & >(
517 rItemSet.Get( SCHATTR_AXIS_AUTO_MIN )).GetValue() ))
519 rItemSet.Get( nWhichId ).QueryValue( aValue );
521 if( aScale.Minimum != aValue )
523 aScale.Minimum = aValue;
524 bSetScale = true;
527 break;
529 case SCHATTR_AXIS_LOGARITHM:
531 bool bWasLogarithm = AxisHelper::isLogarithmic( aScale.Scaling );
533 if( (static_cast< const SfxBoolItem & >(
534 rItemSet.Get( nWhichId )).GetValue() ))
536 // logarithm is true
537 if( ! bWasLogarithm )
539 aScale.Scaling = AxisHelper::createLogarithmicScaling( 10.0 );
540 bSetScale = true;
543 else
545 // logarithm is false => linear scaling
546 if( bWasLogarithm )
548 aScale.Scaling = AxisHelper::createLinearScaling();
549 bSetScale = true;
553 break;
555 case SCHATTR_AXIS_REVERSE:
557 bool bWasReverse = ( AxisOrientation_REVERSE == aScale.Orientation );
558 bool bNewReverse = (static_cast< const SfxBoolItem & >(
559 rItemSet.Get( nWhichId )).GetValue() );
560 if( bWasReverse != bNewReverse )
562 aScale.Orientation = bNewReverse ? AxisOrientation_REVERSE : AxisOrientation_MATHEMATICAL;
563 bSetScale = true;
566 break;
568 // Increment
569 case SCHATTR_AXIS_AUTO_STEP_MAIN:
570 if( lcl_isAutoMajor(rItemSet) )
572 aScale.IncrementData.Distance.clear();
573 aScale.TimeIncrement.MajorTimeInterval.clear();
574 bSetScale = true;
576 // else SCHATTR_AXIS_STEP_MAIN must have some value
577 break;
579 case SCHATTR_AXIS_MAIN_TIME_UNIT:
580 if( !lcl_isAutoMajor(rItemSet) )
582 if( rItemSet.Get( nWhichId ).QueryValue( aValue ) )
584 TimeInterval aTimeInterval;
585 aScale.TimeIncrement.MajorTimeInterval >>= aTimeInterval;
586 aValue >>= aTimeInterval.TimeUnit;
587 aScale.TimeIncrement.MajorTimeInterval = uno::makeAny( aTimeInterval );
588 bSetScale = true;
591 break;
593 case SCHATTR_AXIS_STEP_MAIN:
594 // only if auto if false
595 if( !lcl_isAutoMajor(rItemSet) )
597 rItemSet.Get( nWhichId ).QueryValue( aValue );
598 if( lcl_isDateAxis(rItemSet) )
600 double fValue = 1.0;
601 if( aValue >>= fValue )
603 TimeInterval aTimeInterval;
604 aScale.TimeIncrement.MajorTimeInterval >>= aTimeInterval;
605 aTimeInterval.Number = static_cast<sal_Int32>(fValue);
606 aScale.TimeIncrement.MajorTimeInterval = uno::makeAny( aTimeInterval );
607 bSetScale = true;
610 else if( aScale.IncrementData.Distance != aValue )
612 aScale.IncrementData.Distance = aValue;
613 bSetScale = true;
616 break;
618 // SubIncrement
619 case SCHATTR_AXIS_AUTO_STEP_HELP:
620 if( lcl_isAutoMinor(rItemSet) )
622 if( aScale.IncrementData.SubIncrements.getLength() > 0 &&
623 aScale.IncrementData.SubIncrements[0].IntervalCount.hasValue() )
625 aScale.IncrementData.SubIncrements[0].IntervalCount.clear();
626 bSetScale = true;
628 if( aScale.TimeIncrement.MinorTimeInterval.hasValue() )
630 aScale.TimeIncrement.MinorTimeInterval.clear();
631 bSetScale = true;
634 // else SCHATTR_AXIS_STEP_MAIN must have some value
635 break;
637 case SCHATTR_AXIS_HELP_TIME_UNIT:
638 if( !lcl_isAutoMinor(rItemSet) )
640 if( rItemSet.Get( nWhichId ).QueryValue( aValue ) )
642 TimeInterval aTimeInterval;
643 aScale.TimeIncrement.MinorTimeInterval >>= aTimeInterval;
644 aValue >>= aTimeInterval.TimeUnit;
645 aScale.TimeIncrement.MinorTimeInterval = uno::makeAny( aTimeInterval );
646 bSetScale = true;
649 break;
651 case SCHATTR_AXIS_STEP_HELP:
652 // only if auto is false
653 if( !lcl_isAutoMinor(rItemSet) )
655 rItemSet.Get( nWhichId ).QueryValue( aValue );
656 if( lcl_isDateAxis(rItemSet) )
658 TimeInterval aTimeInterval;
659 aScale.TimeIncrement.MinorTimeInterval >>= aTimeInterval;
660 aValue >>= aTimeInterval.Number;
661 aScale.TimeIncrement.MinorTimeInterval = uno::makeAny(aTimeInterval);
662 bSetScale = true;
664 else if( aScale.IncrementData.SubIncrements.getLength() > 0 )
666 if( ! aScale.IncrementData.SubIncrements[0].IntervalCount.hasValue() ||
667 aScale.IncrementData.SubIncrements[0].IntervalCount != aValue )
669 OSL_ASSERT( aValue.getValueTypeClass() == uno::TypeClass_LONG );
670 aScale.IncrementData.SubIncrements[0].IntervalCount = aValue;
671 bSetScale = true;
675 break;
677 case SCHATTR_AXIS_AUTO_TIME_RESOLUTION:
678 if( (static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId )).GetValue() ))
680 aScale.TimeIncrement.TimeResolution.clear();
681 bSetScale = true;
683 break;
684 case SCHATTR_AXIS_TIME_RESOLUTION:
685 // only if auto is false
686 if( ! (static_cast< const SfxBoolItem & >( rItemSet.Get( SCHATTR_AXIS_AUTO_TIME_RESOLUTION )).GetValue() ))
688 rItemSet.Get( nWhichId ).QueryValue( aValue );
690 if( aScale.TimeIncrement.TimeResolution != aValue )
692 aScale.TimeIncrement.TimeResolution = aValue;
693 bSetScale = true;
696 break;
698 case SCHATTR_AXIS_AUTO_ORIGIN:
700 if( (static_cast< const SfxBoolItem & >(
701 rItemSet.Get( nWhichId )).GetValue() ))
703 aScale.Origin.clear();
704 bSetScale = true;
707 break;
709 case SCHATTR_AXIS_ORIGIN:
711 // only if auto is false
712 if( ! (static_cast< const SfxBoolItem & >(
713 rItemSet.Get( SCHATTR_AXIS_AUTO_ORIGIN )).GetValue() ))
715 rItemSet.Get( nWhichId ).QueryValue( aValue );
717 if( aScale.Origin != aValue )
719 aScale.Origin = aValue;
720 bSetScale = true;
722 if( !AxisHelper::isAxisPositioningEnabled() )
724 //keep old and new settings for axis positioning in sync somehow
725 Reference< chart2::XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis(
726 m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
728 sal_Int32 nDimensionIndex=0;
729 sal_Int32 nAxisIndex=0;
730 if( AxisHelper::getIndicesForAxis( m_xAxis, xCooSys, nDimensionIndex, nAxisIndex ) && nAxisIndex==0 )
732 Reference< beans::XPropertySet > xCrossingMainAxis( AxisHelper::getCrossingMainAxis( m_xAxis, xCooSys ), uno::UNO_QUERY );
733 if( xCrossingMainAxis.is() )
735 double fValue = 0.0;
736 if( aValue >>= fValue )
738 xCrossingMainAxis->setPropertyValue( "CrossoverPosition" , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_VALUE ));
739 xCrossingMainAxis->setPropertyValue( "CrossoverValue" , uno::makeAny( fValue ));
741 else
742 xCrossingMainAxis->setPropertyValue( "CrossoverPosition" , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START ));
749 break;
751 case SCHATTR_AXIS_POSITION:
753 ::com::sun::star::chart::ChartAxisPosition eAxisPos =
754 (::com::sun::star::chart::ChartAxisPosition)
755 static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();
757 ::com::sun::star::chart::ChartAxisPosition eOldAxisPos( ::com::sun::star::chart::ChartAxisPosition_ZERO );
758 bool bPropExisted = ( GetPropertySet()->getPropertyValue( "CrossoverPosition" ) >>= eOldAxisPos );
760 if( !bPropExisted || ( eOldAxisPos != eAxisPos ))
762 GetPropertySet()->setPropertyValue( "CrossoverPosition" , uno::makeAny( eAxisPos ));
763 bChangedOtherwise = true;
765 //move the parallel axes to the other side if necessary
766 if( eAxisPos==::com::sun::star::chart::ChartAxisPosition_START || eAxisPos==::com::sun::star::chart::ChartAxisPosition_END )
768 Reference< beans::XPropertySet > xParallelAxis( AxisHelper::getParallelAxis( m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ), uno::UNO_QUERY );
769 if( xParallelAxis.is() )
771 ::com::sun::star::chart::ChartAxisPosition eOtherPos;
772 if( xParallelAxis->getPropertyValue( "CrossoverPosition" ) >>= eOtherPos )
774 if( eOtherPos == eAxisPos )
776 ::com::sun::star::chart::ChartAxisPosition eOppositePos =
777 (eAxisPos==::com::sun::star::chart::ChartAxisPosition_START)
778 ? ::com::sun::star::chart::ChartAxisPosition_END
779 : ::com::sun::star::chart::ChartAxisPosition_START;
780 xParallelAxis->setPropertyValue( "CrossoverPosition" , uno::makeAny( eOppositePos ));
787 break;
789 case SCHATTR_AXIS_POSITION_VALUE:
791 double fValue = static_cast< const SvxDoubleItem & >( rItemSet.Get( nWhichId )).GetValue();
793 double fOldValue = 0.0;
794 bool bPropExisted = ( GetPropertySet()->getPropertyValue( "CrossoverValue" ) >>= fOldValue );
796 if( !bPropExisted || ( fOldValue != fValue ))
798 GetPropertySet()->setPropertyValue( "CrossoverValue" , uno::makeAny( fValue ));
799 bChangedOtherwise = true;
801 //keep old and new settings for axis positioning in sync somehow
803 Reference< chart2::XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis(
804 m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
806 sal_Int32 nDimensionIndex=0;
807 sal_Int32 nAxisIndex=0;
808 if( AxisHelper::getIndicesForAxis( m_xAxis, xCooSys, nDimensionIndex, nAxisIndex ) && nAxisIndex==0 )
810 Reference< chart2::XAxis > xCrossingMainAxis( AxisHelper::getCrossingMainAxis( m_xAxis, xCooSys ) );
811 if( xCrossingMainAxis.is() )
813 ScaleData aCrossingScale( xCrossingMainAxis->getScaleData() );
814 aCrossingScale.Origin = uno::makeAny(fValue);
815 xCrossingMainAxis->setScaleData(aCrossingScale);
821 break;
823 case SCHATTR_AXIS_LABEL_POSITION:
825 ::com::sun::star::chart::ChartAxisLabelPosition ePos =
826 (::com::sun::star::chart::ChartAxisLabelPosition)
827 static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();
829 ::com::sun::star::chart::ChartAxisLabelPosition eOldPos( ::com::sun::star::chart::ChartAxisLabelPosition_NEAR_AXIS );
830 bool bPropExisted = ( GetPropertySet()->getPropertyValue( "LabelPosition" ) >>= eOldPos );
832 if( !bPropExisted || ( eOldPos != ePos ))
834 GetPropertySet()->setPropertyValue( "LabelPosition" , uno::makeAny( ePos ));
835 bChangedOtherwise = true;
837 //move the parallel axes to the other side if necessary
838 if( ePos==::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START || ePos==::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_END )
840 Reference< beans::XPropertySet > xParallelAxis( AxisHelper::getParallelAxis( m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ), uno::UNO_QUERY );
841 if( xParallelAxis.is() )
843 ::com::sun::star::chart::ChartAxisLabelPosition eOtherPos;
844 if( xParallelAxis->getPropertyValue( "LabelPosition" ) >>= eOtherPos )
846 if( eOtherPos == ePos )
848 ::com::sun::star::chart::ChartAxisLabelPosition eOppositePos =
849 (ePos==::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START)
850 ? ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_END
851 : ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START;
852 xParallelAxis->setPropertyValue( "LabelPosition" , uno::makeAny( eOppositePos ));
859 break;
861 case SCHATTR_AXIS_MARK_POSITION:
863 ::com::sun::star::chart::ChartAxisMarkPosition ePos =
864 (::com::sun::star::chart::ChartAxisMarkPosition)
865 static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();
867 ::com::sun::star::chart::ChartAxisMarkPosition eOldPos( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS );
868 bool bPropExisted = ( GetPropertySet()->getPropertyValue( "MarkPosition" ) >>= eOldPos );
870 if( !bPropExisted || ( eOldPos != ePos ))
872 GetPropertySet()->setPropertyValue( "MarkPosition" , uno::makeAny( ePos ));
873 bChangedOtherwise = true;
876 break;
878 case SCHATTR_TEXT_DEGREES:
880 // convert int to double (divided by 100)
881 double fVal = static_cast< double >(
882 static_cast< const SfxInt32Item & >(
883 rItemSet.Get( nWhichId )).GetValue()) / 100.0;
884 double fOldVal = 0.0;
885 bool bPropExisted =
886 ( GetPropertySet()->getPropertyValue( "TextRotation" ) >>= fOldVal );
888 if( ! bPropExisted ||
889 ( bPropExisted && fOldVal != fVal ))
891 GetPropertySet()->setPropertyValue( "TextRotation" , uno::makeAny( fVal ));
892 bChangedOtherwise = true;
895 break;
897 case SID_ATTR_NUMBERFORMAT_VALUE:
899 if( m_pExplicitScale )
901 bool bUseSourceFormat =
902 (static_cast< const SfxBoolItem & >(
903 rItemSet.Get( SID_ATTR_NUMBERFORMAT_SOURCE )).GetValue() );
905 if( ! bUseSourceFormat )
907 sal_Int32 nFmt = static_cast< sal_Int32 >(
908 static_cast< const SfxUInt32Item & >(
909 rItemSet.Get( nWhichId )).GetValue());
911 aValue = uno::makeAny(nFmt);
912 if (GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT) != aValue)
914 GetPropertySet()->setPropertyValue(CHART_UNONAME_NUMFMT , aValue);
915 bChangedOtherwise = true;
920 break;
922 case SID_ATTR_NUMBERFORMAT_SOURCE:
924 bool bUseSourceFormat =
925 (static_cast< const SfxBoolItem & >(
926 rItemSet.Get( nWhichId )).GetValue() );
927 GetPropertySet()->setPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT, uno::makeAny(bUseSourceFormat));
929 bool bNumberFormatIsSet = GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT).hasValue();
931 bChangedOtherwise = (bUseSourceFormat == bNumberFormatIsSet);
932 if( bChangedOtherwise )
934 if( ! bUseSourceFormat )
936 SfxItemState aState = rItemSet.GetItemState( SID_ATTR_NUMBERFORMAT_VALUE );
937 if( aState == SfxItemState::SET )
939 sal_Int32 nFormatKey = static_cast< sal_Int32 >(
940 static_cast< const SfxUInt32Item & >(
941 rItemSet.Get( SID_ATTR_NUMBERFORMAT_VALUE )).GetValue());
942 aValue <<= nFormatKey;
944 else
946 Reference< chart2::XCoordinateSystem > xCooSys(
947 AxisHelper::getCoordinateSystemOfAxis(
948 m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
950 sal_Int32 nFormatKey = ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
951 m_xAxis, xCooSys, m_xChartDoc);
953 aValue <<= nFormatKey;
956 // else set a void Any
957 GetPropertySet()->setPropertyValue(CHART_UNONAME_NUMFMT , aValue);
960 break;
962 case SCHATTR_AXISTYPE:
964 sal_Int32 nNewAxisType = static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();//::com::sun::star::chart2::AxisType
965 aScale.AxisType = nNewAxisType;
966 bSetScale = true;
968 break;
970 case SCHATTR_AXIS_AUTO_DATEAXIS:
972 bool bNewValue = static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId )).GetValue();
973 bool bOldValue = aScale.AutoDateAxis;
974 if( bOldValue != bNewValue )
976 aScale.AutoDateAxis = bNewValue;
977 bSetScale = true;
980 break;
983 if( bSetScale )
984 m_xAxis->setScaleData( aScale );
986 return (bSetScale || bChangedOtherwise);
991 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */