Update ooo320-m1
[ooovba.git] / chart2 / source / controller / itemsetwrapper / AxisItemConverter.cxx
blob686aa2e16366854b00304d764bbb6f772455faf6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AxisItemConverter.cxx,v $
10 * $Revision: 1.14.44.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "AxisItemConverter.hxx"
34 #include "ItemPropertyMap.hxx"
35 #include "CharacterPropertyItemConverter.hxx"
36 #include "GraphicPropertyItemConverter.hxx"
37 #include "chartview/ChartSfxItemIds.hxx"
38 #include "chartview/ExplicitValueProvider.hxx"
39 #include "SchWhichPairs.hxx"
40 #include "macros.hxx"
41 #include "ChartModelHelper.hxx"
42 #include "AxisHelper.hxx"
43 #include "CommonConverters.hxx"
45 #include <com/sun/star/chart/ChartAxisLabelPosition.hpp>
46 #include <com/sun/star/chart/ChartAxisMarkPosition.hpp>
47 #include <com/sun/star/chart/ChartAxisPosition.hpp>
48 #include <com/sun/star/chart2/XAxis.hpp>
49 #include <com/sun/star/chart2/AxisOrientation.hpp>
51 // for SfxBoolItem
52 #include <svtools/eitem.hxx>
53 // for SvxDoubleItem
54 #include <svx/chrtitem.hxx>
55 // for SfxInt32Item
56 #include <svtools/intitem.hxx>
57 #include <rtl/math.hxx>
59 #include <algorithm>
61 using namespace ::com::sun::star;
62 using namespace ::com::sun::star::chart2;
63 using ::com::sun::star::uno::Reference;
65 namespace
67 ::comphelper::ItemPropertyMapType & lcl_GetAxisPropertyMap()
69 static ::comphelper::ItemPropertyMapType aAxisPropertyMap(
70 ::comphelper::MakeItemPropertyMap
71 IPM_MAP_ENTRY( SCHATTR_AXIS_SHOWDESCR, "DisplayLabels", 0 )
72 IPM_MAP_ENTRY( SCHATTR_AXIS_TICKS, "MajorTickmarks", 0 )
73 IPM_MAP_ENTRY( SCHATTR_AXIS_HELPTICKS, "MinorTickmarks", 0 )
74 IPM_MAP_ENTRY( SCHATTR_TEXT_ORDER, "ArrangeOrder", 0 )
75 IPM_MAP_ENTRY( SCHATTR_TEXT_STACKED, "StackCharacters", 0 )
76 IPM_MAP_ENTRY( SCHATTR_TEXTBREAK, "TextBreak", 0 )
77 IPM_MAP_ENTRY( SCHATTR_TEXT_OVERLAP, "TextOverlap", 0 )
80 return aAxisPropertyMap;
82 } // anonymous namespace
84 namespace chart
86 namespace wrapper
89 AxisItemConverter::AxisItemConverter(
90 const Reference< beans::XPropertySet > & rPropertySet,
91 SfxItemPool& rItemPool,
92 SdrModel& rDrawModel,
93 const Reference< chart2::XChartDocument > & xChartDoc,
94 chart2::ExplicitScaleData * pScale /* = NULL */,
95 chart2::ExplicitIncrementData * pIncrement /* = NULL */,
96 ::std::auto_ptr< awt::Size > pRefSize /* = NULL */ ) :
97 ItemConverter( rPropertySet, rItemPool ),
98 m_xChartDoc( xChartDoc ),
99 m_pExplicitScale( NULL ),
100 m_pExplicitIncrement( NULL )
102 Reference< lang::XMultiServiceFactory > xNamedPropertyContainerFactory( xChartDoc, uno::UNO_QUERY );
104 if( pScale )
105 m_pExplicitScale = new chart2::ExplicitScaleData( *pScale );
106 if( pIncrement )
107 m_pExplicitIncrement = new chart2::ExplicitIncrementData( *pIncrement );
109 m_aConverters.push_back( new GraphicPropertyItemConverter(
110 rPropertySet, rItemPool, rDrawModel,
111 xNamedPropertyContainerFactory,
112 GraphicPropertyItemConverter::LINE_PROPERTIES ));
113 m_aConverters.push_back( new CharacterPropertyItemConverter( rPropertySet, rItemPool, pRefSize,
114 C2U( "ReferencePageSize" ) ));
116 m_xAxis.set( Reference< chart2::XAxis >( rPropertySet, uno::UNO_QUERY ) );
117 OSL_ASSERT( m_xAxis.is());
120 AxisItemConverter::~AxisItemConverter()
122 delete m_pExplicitScale;
123 delete m_pExplicitIncrement;
125 ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
126 ::comphelper::DeleteItemConverterPtr() );
129 void AxisItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
131 ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
132 ::comphelper::FillItemSetFunc( rOutItemSet ));
134 // own items
135 ItemConverter::FillItemSet( rOutItemSet );
138 bool AxisItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
140 bool bResult = false;
142 ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
143 ::comphelper::ApplyItemSetFunc( rItemSet, bResult ));
145 // own items
146 return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
149 const USHORT * AxisItemConverter::GetWhichPairs() const
151 // must span all used items!
152 return nAxisWhichPairs;
155 bool AxisItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
157 ::comphelper::ItemPropertyMapType & rMap( lcl_GetAxisPropertyMap());
158 ::comphelper::ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
160 if( aIt == rMap.end())
161 return false;
163 rOutProperty =(*aIt).second;
165 return true;
168 void AxisItemConverter::FillSpecialItem( USHORT nWhichId, SfxItemSet & rOutItemSet ) const
169 throw( uno::Exception )
171 if( ! m_xAxis.is() )
172 return;
174 const chart2::ScaleData aScale( m_xAxis->getScaleData() );
175 const chart2::IncrementData aInc( aScale.IncrementData );
176 const uno::Sequence< chart2::SubIncrement > aSubIncs( aScale.IncrementData.SubIncrements );
178 switch( nWhichId )
180 case SCHATTR_AXIS_AUTO_MAX:
181 // if the any has no value => auto is on
182 rOutItemSet.Put( SfxBoolItem( nWhichId, !hasDoubleValue(aScale.Maximum) ) );
183 break;
185 case SCHATTR_AXIS_MAX:
187 double fMax = 10.0;
188 if( aScale.Maximum >>= fMax )
190 rOutItemSet.Put( SvxDoubleItem( fMax, nWhichId ) );
192 else
194 if( m_pExplicitScale )
195 fMax = m_pExplicitScale->Maximum;
196 rOutItemSet.Put( SvxDoubleItem( fMax, nWhichId ) );
199 break;
201 case SCHATTR_AXIS_AUTO_MIN:
202 // if the any has no value => auto is on
203 rOutItemSet.Put( SfxBoolItem( nWhichId, !hasDoubleValue(aScale.Minimum) ) );
204 break;
206 case SCHATTR_AXIS_MIN:
208 double fMin = 0.0;
209 if( aScale.Minimum >>= fMin )
211 rOutItemSet.Put( SvxDoubleItem( fMin, nWhichId ) );
213 else
215 if( m_pExplicitScale )
216 rOutItemSet.Put( SvxDoubleItem( m_pExplicitScale->Minimum, nWhichId ));
219 break;
221 case SCHATTR_AXIS_LOGARITHM:
223 BOOL bValue = AxisHelper::isLogarithmic( aScale.Scaling );
224 rOutItemSet.Put( SfxBoolItem( nWhichId, bValue ));
226 break;
228 case SCHATTR_AXIS_REVERSE:
229 rOutItemSet.Put( SfxBoolItem( nWhichId, (AxisOrientation_REVERSE == aScale.Orientation) ));
230 break;
232 // Increment
233 case SCHATTR_AXIS_AUTO_STEP_MAIN:
234 // if the any has no value => auto is on
235 rOutItemSet.Put( SfxBoolItem( nWhichId, !hasDoubleValue(aInc.Distance) ) );
236 break;
238 case SCHATTR_AXIS_STEP_MAIN:
240 double fDistance = 1.0;
241 if( aInc.Distance >>= fDistance )
243 rOutItemSet.Put( SvxDoubleItem(fDistance, nWhichId ));
245 else
247 if( m_pExplicitIncrement )
248 rOutItemSet.Put( SvxDoubleItem( m_pExplicitIncrement->Distance, nWhichId ));
251 break;
253 // SubIncrement
254 case SCHATTR_AXIS_AUTO_STEP_HELP:
256 // if the any has no value => auto is on
257 rOutItemSet.Put(
258 SfxBoolItem(
259 nWhichId,
260 ! ( aSubIncs.getLength() > 0 &&
261 aSubIncs[0].IntervalCount.hasValue() )));
263 break;
265 case SCHATTR_AXIS_STEP_HELP:
267 if( aSubIncs.getLength() > 0 &&
268 aSubIncs[0].IntervalCount.hasValue())
270 OSL_ASSERT( aSubIncs[0].IntervalCount.getValueTypeClass() == uno::TypeClass_LONG );
271 rOutItemSet.Put(
272 SfxInt32Item(
273 nWhichId,
274 *reinterpret_cast< const sal_Int32 * >(
275 aSubIncs[0].IntervalCount.getValue()) ));
277 else
279 if( m_pExplicitIncrement &&
280 m_pExplicitIncrement->SubIncrements.getLength() > 0 )
282 rOutItemSet.Put(
283 SfxInt32Item(
284 nWhichId,
285 m_pExplicitIncrement->SubIncrements[0].IntervalCount ));
289 break;
291 case SCHATTR_AXIS_AUTO_ORIGIN:
293 // if the any has no double value => auto is on
294 rOutItemSet.Put( SfxBoolItem( nWhichId, ( !hasDoubleValue(aScale.Origin) )));
296 break;
298 case SCHATTR_AXIS_ORIGIN:
300 double fOrigin = 0.0;
301 if( !(aScale.Origin >>= fOrigin) )
303 if( m_pExplicitScale )
304 fOrigin = m_pExplicitScale->Origin;
306 rOutItemSet.Put( SvxDoubleItem( fOrigin, nWhichId ));
308 break;
310 case SCHATTR_AXIS_POSITION:
312 ::com::sun::star::chart::ChartAxisPosition eAxisPos( ::com::sun::star::chart::ChartAxisPosition_ZERO );
313 GetPropertySet()->getPropertyValue(C2U( "CrossoverPosition" )) >>= eAxisPos;
314 rOutItemSet.Put( SfxInt32Item( nWhichId, eAxisPos ) );
316 break;
318 case SCHATTR_AXIS_POSITION_VALUE:
320 double fValue = 0.0;
321 if( GetPropertySet()->getPropertyValue(C2U( "CrossoverValue" )) >>= fValue )
322 rOutItemSet.Put( SvxDoubleItem( fValue, nWhichId ) );
324 break;
326 case SCHATTR_AXIS_CROSSING_MAIN_AXIS_NUMBERFORMAT:
328 //read only item
329 //necessary tp display the crossing value with an appropriate format
331 Reference< chart2::XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis(
332 m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
334 Reference< chart2::XAxis > xCrossingMainAxis( AxisHelper::getCrossingMainAxis( m_xAxis, xCooSys ) );
336 sal_Int32 nFormatKey = ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
337 xCrossingMainAxis, xCooSys, Reference< util::XNumberFormatsSupplier >( m_xChartDoc, uno::UNO_QUERY ) );
339 rOutItemSet.Put( SfxUInt32Item( nWhichId, nFormatKey ));
341 break;
343 case SCHATTR_AXIS_LABEL_POSITION:
345 ::com::sun::star::chart::ChartAxisLabelPosition ePos( ::com::sun::star::chart::ChartAxisLabelPosition_NEAR_AXIS );
346 GetPropertySet()->getPropertyValue(C2U( "LabelPosition" )) >>= ePos;
347 rOutItemSet.Put( SfxInt32Item( nWhichId, ePos ) );
349 break;
351 case SCHATTR_AXIS_MARK_POSITION:
353 ::com::sun::star::chart::ChartAxisMarkPosition ePos( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS );
354 GetPropertySet()->getPropertyValue(C2U( "MarkPosition" )) >>= ePos;
355 rOutItemSet.Put( SfxInt32Item( nWhichId, ePos ) );
357 break;
359 case SCHATTR_TEXT_DEGREES:
361 // convert double to int (times 100)
362 double fVal = 0;
364 if( GetPropertySet()->getPropertyValue( C2U( "TextRotation" )) >>= fVal )
366 rOutItemSet.Put( SfxInt32Item( nWhichId, static_cast< sal_Int32 >(
367 ::rtl::math::round( fVal * 100.0 ) ) ));
370 break;
372 case SID_ATTR_NUMBERFORMAT_VALUE:
373 // case SCHATTR_AXIS_NUMFMT:
375 if( m_pExplicitScale )
377 Reference< chart2::XCoordinateSystem > xCooSys(
378 AxisHelper::getCoordinateSystemOfAxis(
379 m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
381 sal_Int32 nFormatKey = ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
382 m_xAxis, xCooSys, Reference< util::XNumberFormatsSupplier >( m_xChartDoc, uno::UNO_QUERY ) );
384 rOutItemSet.Put( SfxUInt32Item( nWhichId, nFormatKey ));
387 break;
389 case SID_ATTR_NUMBERFORMAT_SOURCE:
391 bool bNumberFormatIsSet = ( GetPropertySet()->getPropertyValue( C2U( "NumberFormat" )).hasValue());
392 rOutItemSet.Put( SfxBoolItem( nWhichId, ! bNumberFormatIsSet ));
394 break;
396 case SCHATTR_AXISTYPE:
397 rOutItemSet.Put( SfxInt32Item( nWhichId, aScale.AxisType ));
398 break;
402 bool AxisItemConverter::ApplySpecialItem( USHORT nWhichId, const SfxItemSet & rItemSet )
403 throw( uno::Exception )
405 if( !m_xAxis.is() )
406 return false;
408 chart2::ScaleData aScale( m_xAxis->getScaleData() );
410 bool bSetScale = false;
411 bool bChangedOtherwise = false;
413 uno::Any aValue;
415 switch( nWhichId )
417 case SCHATTR_AXIS_AUTO_MAX:
418 if( (static_cast< const SfxBoolItem & >(
419 rItemSet.Get( nWhichId )).GetValue() ))
421 aScale.Maximum.clear();
422 bSetScale = true;
424 // else SCHATTR_AXIS_MAX must have some value
425 break;
427 case SCHATTR_AXIS_MAX:
428 // only if auto if false
429 if( ! (static_cast< const SfxBoolItem & >(
430 rItemSet.Get( SCHATTR_AXIS_AUTO_MAX )).GetValue() ))
432 rItemSet.Get( nWhichId ).QueryValue( aValue );
434 if( aScale.Maximum != aValue )
436 aScale.Maximum = aValue;
437 bSetScale = true;
440 break;
442 case SCHATTR_AXIS_AUTO_MIN:
443 if( (static_cast< const SfxBoolItem & >(
444 rItemSet.Get( nWhichId )).GetValue() ))
446 aScale.Minimum.clear();
447 bSetScale = true;
449 // else SCHATTR_AXIS_MIN must have some value
450 break;
452 case SCHATTR_AXIS_MIN:
453 // only if auto if false
454 if( ! (static_cast< const SfxBoolItem & >(
455 rItemSet.Get( SCHATTR_AXIS_AUTO_MIN )).GetValue() ))
457 rItemSet.Get( nWhichId ).QueryValue( aValue );
459 if( aScale.Minimum != aValue )
461 aScale.Minimum = aValue;
462 bSetScale = true;
465 break;
467 case SCHATTR_AXIS_LOGARITHM:
469 bool bWasLogarithm = AxisHelper::isLogarithmic( aScale.Scaling );
471 if( (static_cast< const SfxBoolItem & >(
472 rItemSet.Get( nWhichId )).GetValue() ))
474 // logarithm is true
475 if( ! bWasLogarithm )
477 aScale.Scaling = AxisHelper::createLogarithmicScaling( 10.0 );
478 bSetScale = true;
481 else
483 // logarithm is false => linear scaling
484 if( bWasLogarithm )
486 aScale.Scaling = AxisHelper::createLinearScaling();
487 bSetScale = true;
491 break;
493 case SCHATTR_AXIS_REVERSE:
495 bool bWasReverse = ( AxisOrientation_REVERSE == aScale.Orientation );
496 bool bNewReverse = (static_cast< const SfxBoolItem & >(
497 rItemSet.Get( nWhichId )).GetValue() );
498 if( bWasReverse != bNewReverse )
500 aScale.Orientation = bNewReverse ? AxisOrientation_REVERSE : AxisOrientation_MATHEMATICAL;
501 bSetScale = true;
504 break;
506 // Increment
507 case SCHATTR_AXIS_AUTO_STEP_MAIN:
508 if( (static_cast< const SfxBoolItem & >(
509 rItemSet.Get( nWhichId )).GetValue() ))
511 aScale.IncrementData.Distance.clear();
512 bSetScale = true;
514 // else SCHATTR_AXIS_STEP_MAIN must have some value
515 break;
517 case SCHATTR_AXIS_STEP_MAIN:
518 // only if auto if false
519 if( ! (static_cast< const SfxBoolItem & >(
520 rItemSet.Get( SCHATTR_AXIS_AUTO_STEP_MAIN )).GetValue() ))
522 rItemSet.Get( nWhichId ).QueryValue( aValue );
524 if( aScale.IncrementData.Distance != aValue )
526 aScale.IncrementData.Distance = aValue;
527 bSetScale = true;
530 break;
532 // SubIncrement
533 case SCHATTR_AXIS_AUTO_STEP_HELP:
534 if( (static_cast< const SfxBoolItem & >(
535 rItemSet.Get( nWhichId )).GetValue() ) &&
536 aScale.IncrementData.SubIncrements.getLength() > 0 &&
537 aScale.IncrementData.SubIncrements[0].IntervalCount.hasValue() )
539 aScale.IncrementData.SubIncrements[0].IntervalCount.clear();
540 bSetScale = true;
542 // else SCHATTR_AXIS_STEP_MAIN must have some value
543 break;
545 case SCHATTR_AXIS_STEP_HELP:
546 // only if auto if false
547 if( ! (static_cast< const SfxBoolItem & >(
548 rItemSet.Get( SCHATTR_AXIS_AUTO_STEP_HELP )).GetValue() ) &&
549 aScale.IncrementData.SubIncrements.getLength() > 0 )
551 rItemSet.Get( nWhichId ).QueryValue( aValue );
553 if( ! aScale.IncrementData.SubIncrements[0].IntervalCount.hasValue() ||
554 aScale.IncrementData.SubIncrements[0].IntervalCount != aValue )
556 OSL_ASSERT( aValue.getValueTypeClass() == uno::TypeClass_LONG );
557 aScale.IncrementData.SubIncrements[0].IntervalCount = aValue;
558 bSetScale = true;
561 break;
563 case SCHATTR_AXIS_AUTO_ORIGIN:
565 if( (static_cast< const SfxBoolItem & >(
566 rItemSet.Get( nWhichId )).GetValue() ))
568 aScale.Origin.clear();
569 bSetScale = true;
572 break;
574 case SCHATTR_AXIS_ORIGIN:
576 // only if auto is false
577 if( ! (static_cast< const SfxBoolItem & >(
578 rItemSet.Get( SCHATTR_AXIS_AUTO_ORIGIN )).GetValue() ))
580 rItemSet.Get( nWhichId ).QueryValue( aValue );
582 if( aScale.Origin != aValue )
584 aScale.Origin = aValue;
585 bSetScale = true;
587 if( !AxisHelper::isAxisPositioningEnabled() )
589 //keep old and new settings for axis positioning in sync somehow
590 Reference< chart2::XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis(
591 m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
593 sal_Int32 nDimensionIndex=0;
594 sal_Int32 nAxisIndex=0;
595 if( AxisHelper::getIndicesForAxis( m_xAxis, xCooSys, nDimensionIndex, nAxisIndex ) && nAxisIndex==0 )
597 Reference< beans::XPropertySet > xCrossingMainAxis( AxisHelper::getCrossingMainAxis( m_xAxis, xCooSys ), uno::UNO_QUERY );
598 if( xCrossingMainAxis.is() )
600 double fValue = 0.0;
601 if( aValue >>= fValue )
603 xCrossingMainAxis->setPropertyValue( C2U( "CrossoverPosition" ), uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_VALUE ));
604 xCrossingMainAxis->setPropertyValue( C2U( "CrossoverValue" ), uno::makeAny( fValue ));
606 else
607 xCrossingMainAxis->setPropertyValue( C2U( "CrossoverPosition" ), uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START ));
614 break;
616 case SCHATTR_AXIS_POSITION:
618 ::com::sun::star::chart::ChartAxisPosition eAxisPos =
619 (::com::sun::star::chart::ChartAxisPosition)
620 static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();
622 ::com::sun::star::chart::ChartAxisPosition eOldAxisPos( ::com::sun::star::chart::ChartAxisPosition_ZERO );
623 bool bPropExisted = ( GetPropertySet()->getPropertyValue(C2U( "CrossoverPosition" )) >>= eOldAxisPos );
625 if( !bPropExisted || ( eOldAxisPos != eAxisPos ))
627 GetPropertySet()->setPropertyValue( C2U( "CrossoverPosition" ), uno::makeAny( eAxisPos ));
628 bChangedOtherwise = true;
630 //move the parallel axes to the other side if necessary
631 if( eAxisPos==::com::sun::star::chart::ChartAxisPosition_START || eAxisPos==::com::sun::star::chart::ChartAxisPosition_END )
633 Reference< beans::XPropertySet > xParallelAxis( AxisHelper::getParallelAxis( m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ), uno::UNO_QUERY );
634 if( xParallelAxis.is() )
636 ::com::sun::star::chart::ChartAxisPosition eOtherPos;
637 if( xParallelAxis->getPropertyValue( C2U( "CrossoverPosition" ) ) >>= eOtherPos )
639 if( eOtherPos == eAxisPos )
641 ::com::sun::star::chart::ChartAxisPosition eOppositePos =
642 (eAxisPos==::com::sun::star::chart::ChartAxisPosition_START)
643 ? ::com::sun::star::chart::ChartAxisPosition_END
644 : ::com::sun::star::chart::ChartAxisPosition_START;
645 xParallelAxis->setPropertyValue( C2U( "CrossoverPosition" ), uno::makeAny( eOppositePos ));
652 break;
654 case SCHATTR_AXIS_POSITION_VALUE:
656 double fValue = static_cast< const SvxDoubleItem & >( rItemSet.Get( nWhichId )).GetValue();
658 double fOldValue = 0.0;
659 bool bPropExisted = ( GetPropertySet()->getPropertyValue(C2U( "CrossoverValue" )) >>= fOldValue );
661 if( !bPropExisted || ( fOldValue != fValue ))
663 GetPropertySet()->setPropertyValue( C2U( "CrossoverValue" ), uno::makeAny( fValue ));
664 bChangedOtherwise = true;
666 //keep old and new settings for axis positioning in sync somehow
668 Reference< chart2::XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis(
669 m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
671 sal_Int32 nDimensionIndex=0;
672 sal_Int32 nAxisIndex=0;
673 if( AxisHelper::getIndicesForAxis( m_xAxis, xCooSys, nDimensionIndex, nAxisIndex ) && nAxisIndex==0 && nDimensionIndex==0 )
675 Reference< chart2::XAxis > xCrossingMainAxis( AxisHelper::getCrossingMainAxis( m_xAxis, xCooSys ) );
676 if( xCrossingMainAxis.is() )
678 ScaleData aCrossingScale( xCrossingMainAxis->getScaleData() );
679 aCrossingScale.Origin = uno::makeAny(fValue);
680 xCrossingMainAxis->setScaleData(aCrossingScale);
686 break;
688 case SCHATTR_AXIS_LABEL_POSITION:
690 ::com::sun::star::chart::ChartAxisLabelPosition ePos =
691 (::com::sun::star::chart::ChartAxisLabelPosition)
692 static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();
694 ::com::sun::star::chart::ChartAxisLabelPosition eOldPos( ::com::sun::star::chart::ChartAxisLabelPosition_NEAR_AXIS );
695 bool bPropExisted = ( GetPropertySet()->getPropertyValue(C2U( "LabelPosition" )) >>= eOldPos );
697 if( !bPropExisted || ( eOldPos != ePos ))
699 GetPropertySet()->setPropertyValue( C2U( "LabelPosition" ), uno::makeAny( ePos ));
700 bChangedOtherwise = true;
702 //move the parallel axes to the other side if necessary
703 if( ePos==::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START || ePos==::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_END )
705 Reference< beans::XPropertySet > xParallelAxis( AxisHelper::getParallelAxis( m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ), uno::UNO_QUERY );
706 if( xParallelAxis.is() )
708 ::com::sun::star::chart::ChartAxisLabelPosition eOtherPos;
709 if( xParallelAxis->getPropertyValue( C2U( "LabelPosition" ) ) >>= eOtherPos )
711 if( eOtherPos == ePos )
713 ::com::sun::star::chart::ChartAxisLabelPosition eOppositePos =
714 (ePos==::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START)
715 ? ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_END
716 : ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START;
717 xParallelAxis->setPropertyValue( C2U( "LabelPosition" ), uno::makeAny( eOppositePos ));
724 break;
726 case SCHATTR_AXIS_MARK_POSITION:
728 ::com::sun::star::chart::ChartAxisMarkPosition ePos =
729 (::com::sun::star::chart::ChartAxisMarkPosition)
730 static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();
732 ::com::sun::star::chart::ChartAxisMarkPosition eOldPos( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS );
733 bool bPropExisted = ( GetPropertySet()->getPropertyValue(C2U( "MarkPosition" )) >>= eOldPos );
735 if( !bPropExisted || ( eOldPos != ePos ))
737 GetPropertySet()->setPropertyValue( C2U( "MarkPosition" ), uno::makeAny( ePos ));
738 bChangedOtherwise = true;
741 break;
743 case SCHATTR_TEXT_DEGREES:
745 // convert int to double (divided by 100)
746 double fVal = static_cast< double >(
747 static_cast< const SfxInt32Item & >(
748 rItemSet.Get( nWhichId )).GetValue()) / 100.0;
749 double fOldVal = 0.0;
750 bool bPropExisted =
751 ( GetPropertySet()->getPropertyValue( C2U( "TextRotation" )) >>= fOldVal );
753 if( ! bPropExisted ||
754 ( bPropExisted && fOldVal != fVal ))
756 GetPropertySet()->setPropertyValue( C2U( "TextRotation" ), uno::makeAny( fVal ));
757 bChangedOtherwise = true;
760 break;
762 case SID_ATTR_NUMBERFORMAT_VALUE:
763 // case SCHATTR_AXIS_NUMFMT:
765 if( m_pExplicitScale )
767 bool bUseSourceFormat =
768 (static_cast< const SfxBoolItem & >(
769 rItemSet.Get( SID_ATTR_NUMBERFORMAT_SOURCE )).GetValue() );
771 if( ! bUseSourceFormat )
773 sal_Int32 nFmt = static_cast< sal_Int32 >(
774 static_cast< const SfxUInt32Item & >(
775 rItemSet.Get( nWhichId )).GetValue());
777 aValue = uno::makeAny(nFmt);
778 if( GetPropertySet()->getPropertyValue( C2U( "NumberFormat" )) != aValue )
780 GetPropertySet()->setPropertyValue( C2U( "NumberFormat" ), aValue );
781 bChangedOtherwise = true;
786 break;
788 case SID_ATTR_NUMBERFORMAT_SOURCE:
790 bool bUseSourceFormat =
791 (static_cast< const SfxBoolItem & >(
792 rItemSet.Get( nWhichId )).GetValue() );
793 bool bNumberFormatIsSet = ( GetPropertySet()->getPropertyValue( C2U( "NumberFormat" )).hasValue());
795 bChangedOtherwise = (bUseSourceFormat == bNumberFormatIsSet);
796 if( bChangedOtherwise )
798 if( ! bUseSourceFormat )
800 SfxItemState aState = rItemSet.GetItemState( SID_ATTR_NUMBERFORMAT_VALUE );
801 if( aState == SFX_ITEM_SET )
803 sal_Int32 nFormatKey = static_cast< sal_Int32 >(
804 static_cast< const SfxUInt32Item & >(
805 rItemSet.Get( SID_ATTR_NUMBERFORMAT_VALUE )).GetValue());
806 aValue <<= nFormatKey;
808 else
810 Reference< chart2::XCoordinateSystem > xCooSys(
811 AxisHelper::getCoordinateSystemOfAxis(
812 m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
814 sal_Int32 nFormatKey = ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
815 m_xAxis, xCooSys, Reference< util::XNumberFormatsSupplier >( m_xChartDoc, uno::UNO_QUERY ) );
817 aValue <<= nFormatKey;
820 // else set a void Any
821 GetPropertySet()->setPropertyValue( C2U( "NumberFormat" ), aValue );
824 break;
826 case SCHATTR_AXISTYPE:
827 //don't allow to change the axis type so far
828 break;
831 if( bSetScale )
832 m_xAxis->setScaleData( aScale );
834 return (bSetScale || bChangedOtherwise);
837 } // namespace wrapper
838 } // namespace chart