nss: upgrade to release 3.73
[LibreOffice.git] / chart2 / source / controller / itemsetwrapper / AxisItemConverter.cxx
blob04646b69acb69f9e22963d4d802dcb2953797e02
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 <AxisHelper.hxx>
30 #include <CommonConverters.hxx>
31 #include <ChartTypeHelper.hxx>
32 #include <unonames.hxx>
33 #include <memory>
35 #include <com/sun/star/chart/ChartAxisLabelPosition.hpp>
36 #include <com/sun/star/chart/ChartAxisMarkPosition.hpp>
37 #include <com/sun/star/chart/ChartAxisPosition.hpp>
38 #include <com/sun/star/chart/TimeInterval.hpp>
39 #include <com/sun/star/chart2/XAxis.hpp>
40 #include <com/sun/star/chart2/XChartDocument.hpp>
41 #include <com/sun/star/chart2/AxisOrientation.hpp>
42 #include <com/sun/star/chart2/AxisType.hpp>
43 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
45 #include <osl/diagnose.h>
46 #include <o3tl/any.hxx>
47 #include <svl/eitem.hxx>
48 #include <svx/chrtitem.hxx>
49 #include <svl/intitem.hxx>
50 #include <rtl/math.hxx>
52 using namespace ::com::sun::star;
53 using namespace ::com::sun::star::chart2;
54 using ::com::sun::star::uno::Reference;
55 using ::com::sun::star::chart::TimeInterval;
56 using ::com::sun::star::chart::TimeIncrement;
58 namespace chart::wrapper {
60 namespace {
62 ItemPropertyMapType & lcl_GetAxisPropertyMap()
64 static ItemPropertyMapType aAxisPropertyMap{
65 {SCHATTR_AXIS_SHOWDESCR, {"DisplayLabels", 0}},
66 {SCHATTR_AXIS_TICKS, {"MajorTickmarks", 0}},
67 {SCHATTR_AXIS_HELPTICKS, {"MinorTickmarks", 0}},
68 {SCHATTR_AXIS_LABEL_ORDER, {"ArrangeOrder", 0}},
69 {SCHATTR_TEXT_STACKED, {"StackCharacters", 0}},
70 {SCHATTR_AXIS_LABEL_BREAK, {"TextBreak", 0}},
71 {SCHATTR_AXIS_LABEL_OVERLAP, {"TextOverlap", 0}}};
72 return aAxisPropertyMap;
75 } // anonymous namespace
77 AxisItemConverter::AxisItemConverter(
78 const Reference< beans::XPropertySet > & rPropertySet,
79 SfxItemPool& rItemPool,
80 SdrModel& rDrawModel,
81 const Reference< chart2::XChartDocument > & xChartDoc,
82 ::chart::ExplicitScaleData const * pScale /* = NULL */,
83 ::chart::ExplicitIncrementData const * pIncrement /* = NULL */,
84 const awt::Size* pRefSize ) :
85 ItemConverter( rPropertySet, rItemPool ),
86 m_xChartDoc( xChartDoc )
88 Reference< lang::XMultiServiceFactory > xNamedPropertyContainerFactory( xChartDoc, uno::UNO_QUERY );
90 if( pScale )
91 m_pExplicitScale.reset( new ::chart::ExplicitScaleData( *pScale ) );
92 if( pIncrement )
93 m_pExplicitIncrement.reset( new ::chart::ExplicitIncrementData( *pIncrement ) );
95 m_aConverters.emplace_back( new GraphicPropertyItemConverter(
96 rPropertySet, rItemPool, rDrawModel,
97 xNamedPropertyContainerFactory,
98 GraphicObjectType::LineProperties ));
99 m_aConverters.emplace_back(
100 new CharacterPropertyItemConverter(rPropertySet, rItemPool, pRefSize, "ReferencePageSize"));
102 m_xAxis.set( Reference< chart2::XAxis >( rPropertySet, uno::UNO_QUERY ) );
103 OSL_ASSERT( m_xAxis.is());
106 AxisItemConverter::~AxisItemConverter()
110 void AxisItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
112 for( const auto& pConv : m_aConverters )
113 pConv->FillItemSet( rOutItemSet );
115 // own items
116 ItemConverter::FillItemSet( rOutItemSet );
119 bool AxisItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
121 bool bResult = false;
123 for( const auto& pConv : m_aConverters )
124 bResult = pConv->ApplyItemSet( rItemSet ) || bResult;
126 // own items
127 return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
130 const sal_uInt16 * AxisItemConverter::GetWhichPairs() const
132 // must span all used items!
133 return nAxisWhichPairs;
136 bool AxisItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
138 ItemPropertyMapType & rMap( lcl_GetAxisPropertyMap());
139 ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
141 if( aIt == rMap.end())
142 return false;
144 rOutProperty =(*aIt).second;
146 return true;
149 static bool lcl_hasTimeIntervalValue( const uno::Any& rAny )
151 bool bRet = false;
152 TimeInterval aValue;
153 if( rAny >>= aValue )
154 bRet = true;
155 return bRet;
158 void AxisItemConverter::FillSpecialItem( sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
160 if( !m_xAxis.is() )
161 return;
163 const chart2::ScaleData& rScale( m_xAxis->getScaleData() );
164 const chart2::IncrementData& rIncrement( rScale.IncrementData );
165 const uno::Sequence< chart2::SubIncrement >& rSubIncrements( rScale.IncrementData.SubIncrements );
166 const TimeIncrement& rTimeIncrement( rScale.TimeIncrement );
167 bool bDateAxis = (rScale.AxisType == chart2::AxisType::DATE);
168 if( m_pExplicitScale )
169 bDateAxis = (m_pExplicitScale->AxisType == chart2::AxisType::DATE);
171 switch( nWhichId )
173 case SCHATTR_AXIS_AUTO_MAX:
174 rOutItemSet.Put( SfxBoolItem( nWhichId, !hasDoubleValue(rScale.Maximum) ) );
175 break;
177 case SCHATTR_AXIS_MAX:
179 double fMax = 10.0;
180 if( rScale.Maximum >>= fMax )
181 rOutItemSet.Put( SvxDoubleItem( fMax, nWhichId ) );
182 else
184 if( m_pExplicitScale )
185 fMax = m_pExplicitScale->Maximum;
186 rOutItemSet.Put( SvxDoubleItem( fMax, nWhichId ) );
189 break;
191 case SCHATTR_AXIS_AUTO_MIN:
192 rOutItemSet.Put( SfxBoolItem( nWhichId, !hasDoubleValue(rScale.Minimum) ) );
193 break;
195 case SCHATTR_AXIS_MIN:
197 double fMin = 0.0;
198 if( rScale.Minimum >>= fMin )
199 rOutItemSet.Put( SvxDoubleItem( fMin, nWhichId ) );
200 else if( m_pExplicitScale )
201 rOutItemSet.Put( SvxDoubleItem( m_pExplicitScale->Minimum, nWhichId ));
203 break;
205 case SCHATTR_AXIS_LOGARITHM:
207 bool bValue = AxisHelper::isLogarithmic( rScale.Scaling );
208 rOutItemSet.Put( SfxBoolItem( nWhichId, bValue ));
210 break;
212 case SCHATTR_AXIS_REVERSE:
213 rOutItemSet.Put( SfxBoolItem( nWhichId, (rScale.Orientation == AxisOrientation_REVERSE) ));
214 break;
216 // Increment
217 case SCHATTR_AXIS_AUTO_STEP_MAIN:
218 if( bDateAxis )
219 rOutItemSet.Put( SfxBoolItem( nWhichId, !lcl_hasTimeIntervalValue(rTimeIncrement.MajorTimeInterval) ) );
220 else
221 rOutItemSet.Put( SfxBoolItem( nWhichId, !hasDoubleValue(rIncrement.Distance) ) );
222 break;
224 case SCHATTR_AXIS_MAIN_TIME_UNIT:
226 TimeInterval aTimeInterval;
227 if( rTimeIncrement.MajorTimeInterval >>= aTimeInterval )
228 rOutItemSet.Put( SfxInt32Item( nWhichId, aTimeInterval.TimeUnit ) );
229 else if( m_pExplicitIncrement )
230 rOutItemSet.Put( SfxInt32Item( nWhichId, m_pExplicitIncrement->MajorTimeInterval.TimeUnit ) );
232 break;
234 case SCHATTR_AXIS_STEP_MAIN:
235 if( bDateAxis )
237 TimeInterval aTimeInterval;
238 if( rTimeIncrement.MajorTimeInterval >>= aTimeInterval )
239 rOutItemSet.Put( SvxDoubleItem(aTimeInterval.Number, nWhichId ));
240 else if( m_pExplicitIncrement )
241 rOutItemSet.Put( SvxDoubleItem( m_pExplicitIncrement->MajorTimeInterval.Number, nWhichId ));
243 else
245 double fDistance = 1.0;
246 if( rIncrement.Distance >>= fDistance )
247 rOutItemSet.Put( SvxDoubleItem(fDistance, nWhichId ));
248 else if( m_pExplicitIncrement )
249 rOutItemSet.Put( SvxDoubleItem( m_pExplicitIncrement->Distance, nWhichId ));
251 break;
253 // SubIncrement
254 case SCHATTR_AXIS_AUTO_STEP_HELP:
255 if( bDateAxis )
256 rOutItemSet.Put( SfxBoolItem( nWhichId, !lcl_hasTimeIntervalValue(rTimeIncrement.MinorTimeInterval) ) );
257 else
258 rOutItemSet.Put( SfxBoolItem( nWhichId,
259 ! ( rSubIncrements.hasElements() && rSubIncrements[0].IntervalCount.hasValue() )));
260 break;
262 case SCHATTR_AXIS_HELP_TIME_UNIT:
264 TimeInterval aTimeInterval;
265 if( rTimeIncrement.MinorTimeInterval >>= aTimeInterval )
266 rOutItemSet.Put( SfxInt32Item( nWhichId, aTimeInterval.TimeUnit ) );
267 else if( m_pExplicitIncrement )
268 rOutItemSet.Put( SfxInt32Item( nWhichId, m_pExplicitIncrement->MinorTimeInterval.TimeUnit ) );
270 break;
272 case SCHATTR_AXIS_STEP_HELP:
273 if( bDateAxis )
275 TimeInterval aTimeInterval;
276 if( rTimeIncrement.MinorTimeInterval >>= aTimeInterval )
277 rOutItemSet.Put( SfxInt32Item( nWhichId, aTimeInterval.Number ));
278 else if( m_pExplicitIncrement )
279 rOutItemSet.Put( SfxInt32Item( nWhichId, m_pExplicitIncrement->MinorTimeInterval.Number ));
281 else
283 if( rSubIncrements.hasElements() && rSubIncrements[0].IntervalCount.hasValue())
285 rOutItemSet.Put( SfxInt32Item( nWhichId,
286 *o3tl::doAccess<sal_Int32>(
287 rSubIncrements[0].IntervalCount) ));
289 else
291 if( m_pExplicitIncrement && !m_pExplicitIncrement->SubIncrements.empty() )
293 rOutItemSet.Put( SfxInt32Item( nWhichId,
294 m_pExplicitIncrement->SubIncrements[0].IntervalCount ));
298 break;
300 case SCHATTR_AXIS_AUTO_TIME_RESOLUTION:
302 rOutItemSet.Put( SfxBoolItem( nWhichId,
303 !rTimeIncrement.TimeResolution.hasValue() ));
305 break;
306 case SCHATTR_AXIS_TIME_RESOLUTION:
308 tools::Long nTimeResolution=0;
309 if( rTimeIncrement.TimeResolution >>= nTimeResolution )
310 rOutItemSet.Put( SfxInt32Item( nWhichId, nTimeResolution ) );
311 else if( m_pExplicitScale )
312 rOutItemSet.Put( SfxInt32Item( nWhichId, m_pExplicitScale->TimeResolution ) );
314 break;
316 case SCHATTR_AXIS_AUTO_ORIGIN:
318 rOutItemSet.Put( SfxBoolItem( nWhichId, ( !hasDoubleValue(rScale.Origin) )));
320 break;
322 case SCHATTR_AXIS_ORIGIN:
324 double fOrigin = 0.0;
325 if( !(rScale.Origin >>= fOrigin) )
327 if( m_pExplicitScale )
328 fOrigin = m_pExplicitScale->Origin;
330 rOutItemSet.Put( SvxDoubleItem( fOrigin, nWhichId ));
332 break;
334 case SCHATTR_AXIS_POSITION:
336 css::chart::ChartAxisPosition eAxisPos( css::chart::ChartAxisPosition_ZERO );
337 GetPropertySet()->getPropertyValue( "CrossoverPosition" ) >>= eAxisPos;
338 rOutItemSet.Put( SfxInt32Item( nWhichId, static_cast<sal_Int32>(eAxisPos) ) );
340 break;
342 case SCHATTR_AXIS_POSITION_VALUE:
344 double fValue = 0.0;
345 if( GetPropertySet()->getPropertyValue( "CrossoverValue" ) >>= fValue )
346 rOutItemSet.Put( SvxDoubleItem( fValue, nWhichId ) );
348 break;
350 case SCHATTR_AXIS_CROSSING_MAIN_AXIS_NUMBERFORMAT:
352 //read only item
353 //necessary tp display the crossing value with an appropriate format
355 Reference< chart2::XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis(
356 m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
358 Reference< chart2::XAxis > xCrossingMainAxis( AxisHelper::getCrossingMainAxis( m_xAxis, xCooSys ) );
360 sal_Int32 nFormatKey = ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
361 xCrossingMainAxis, xCooSys, m_xChartDoc);
363 rOutItemSet.Put( SfxUInt32Item( nWhichId, nFormatKey ));
365 break;
367 case SCHATTR_AXIS_SHIFTED_CATEGORY_POSITION:
368 rOutItemSet.Put(SfxBoolItem(nWhichId, rScale.ShiftedCategoryPosition));
369 break;
371 case SCHATTR_AXIS_LABEL_POSITION:
373 css::chart::ChartAxisLabelPosition ePos( css::chart::ChartAxisLabelPosition_NEAR_AXIS );
374 GetPropertySet()->getPropertyValue( "LabelPosition" ) >>= ePos;
375 rOutItemSet.Put( SfxInt32Item( nWhichId, static_cast<sal_Int32>(ePos) ) );
377 break;
379 case SCHATTR_AXIS_MARK_POSITION:
381 css::chart::ChartAxisMarkPosition ePos( css::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS );
382 GetPropertySet()->getPropertyValue( "MarkPosition" ) >>= ePos;
383 rOutItemSet.Put( SfxInt32Item( nWhichId, static_cast<sal_Int32>(ePos) ) );
385 break;
387 case SCHATTR_TEXT_DEGREES:
389 // convert double to int (times 100)
390 double fVal = 0;
392 if( GetPropertySet()->getPropertyValue( "TextRotation" ) >>= fVal )
394 rOutItemSet.Put( SfxInt32Item( nWhichId, static_cast< sal_Int32 >(
395 ::rtl::math::round( fVal * 100.0 ) ) ));
398 break;
400 case SID_ATTR_NUMBERFORMAT_VALUE:
402 if( m_pExplicitScale )
404 Reference< chart2::XCoordinateSystem > xCooSys(
405 AxisHelper::getCoordinateSystemOfAxis(
406 m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
408 sal_Int32 nFormatKey = ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
409 m_xAxis, xCooSys, m_xChartDoc);
411 rOutItemSet.Put( SfxUInt32Item( nWhichId, nFormatKey ));
414 break;
416 case SID_ATTR_NUMBERFORMAT_SOURCE:
418 bool bLinkToSource = true;
419 GetPropertySet()->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bLinkToSource;
420 rOutItemSet.Put(SfxBoolItem(nWhichId, bLinkToSource));
422 break;
424 case SCHATTR_AXISTYPE:
425 rOutItemSet.Put( SfxInt32Item( nWhichId, rScale.AxisType ));
426 break;
428 case SCHATTR_AXIS_AUTO_DATEAXIS:
429 rOutItemSet.Put( SfxBoolItem( nWhichId, rScale.AutoDateAxis ));
430 break;
432 case SCHATTR_AXIS_ALLOW_DATEAXIS:
434 Reference< chart2::XCoordinateSystem > xCooSys(
435 AxisHelper::getCoordinateSystemOfAxis( m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
436 sal_Int32 nDimensionIndex=0; sal_Int32 nAxisIndex=0;
437 AxisHelper::getIndicesForAxis(m_xAxis, xCooSys, nDimensionIndex, nAxisIndex );
438 bool bChartTypeAllowsDateAxis = ChartTypeHelper::isSupportingDateAxis( AxisHelper::getChartTypeByIndex( xCooSys, 0 ), nDimensionIndex );
439 rOutItemSet.Put( SfxBoolItem( nWhichId, bChartTypeAllowsDateAxis ));
441 break;
445 static bool lcl_isDateAxis( const SfxItemSet & rItemSet )
447 sal_Int32 nAxisType = rItemSet.Get( SCHATTR_AXISTYPE ).GetValue();//css::chart2::AxisType
448 return (nAxisType == chart2::AxisType::DATE);
451 static bool lcl_isAutoMajor( const SfxItemSet & rItemSet )
453 bool bRet = rItemSet.Get( SCHATTR_AXIS_AUTO_STEP_MAIN ).GetValue();
454 return bRet;
457 static bool lcl_isAutoMinor( const SfxItemSet & rItemSet )
459 bool bRet = rItemSet.Get( SCHATTR_AXIS_AUTO_STEP_HELP ).GetValue();
460 return bRet;
463 bool AxisItemConverter::ApplySpecialItem( sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
465 if( !m_xAxis.is() )
466 return false;
468 chart2::ScaleData aScale( m_xAxis->getScaleData() );
470 bool bSetScale = false;
471 bool bChangedOtherwise = false;
473 uno::Any aValue;
475 switch( nWhichId )
477 case SCHATTR_AXIS_AUTO_MAX:
478 if( static_cast< const SfxBoolItem & >(rItemSet.Get( nWhichId )).GetValue() )
480 aScale.Maximum.clear();
481 bSetScale = true;
483 // else SCHATTR_AXIS_MAX must have some value
484 break;
486 case SCHATTR_AXIS_MAX:
487 // only if auto if false
488 if( ! (rItemSet.Get( SCHATTR_AXIS_AUTO_MAX ).GetValue() ))
490 rItemSet.Get( nWhichId ).QueryValue( aValue );
492 if( aScale.Maximum != aValue )
494 aScale.Maximum = aValue;
495 bSetScale = true;
498 break;
500 case SCHATTR_AXIS_AUTO_MIN:
501 if( static_cast< const SfxBoolItem & >(rItemSet.Get( nWhichId )).GetValue() )
503 aScale.Minimum.clear();
504 bSetScale = true;
506 // else SCHATTR_AXIS_MIN must have some value
507 break;
509 case SCHATTR_AXIS_MIN:
510 // only if auto if false
511 if( ! (rItemSet.Get( SCHATTR_AXIS_AUTO_MIN ).GetValue() ))
513 rItemSet.Get( nWhichId ).QueryValue( aValue );
515 if( aScale.Minimum != aValue )
517 aScale.Minimum = aValue;
518 bSetScale = true;
521 break;
523 case SCHATTR_AXIS_LOGARITHM:
525 bool bWasLogarithm = AxisHelper::isLogarithmic( aScale.Scaling );
527 if( static_cast< const SfxBoolItem & >(rItemSet.Get( nWhichId )).GetValue() )
529 // logarithm is true
530 if( ! bWasLogarithm )
532 aScale.Scaling = AxisHelper::createLogarithmicScaling( 10.0 );
533 bSetScale = true;
536 else
538 // logarithm is false => linear scaling
539 if( bWasLogarithm )
541 aScale.Scaling = AxisHelper::createLinearScaling();
542 bSetScale = true;
546 break;
548 case SCHATTR_AXIS_REVERSE:
550 bool bWasReverse = ( aScale.Orientation == AxisOrientation_REVERSE );
551 bool bNewReverse = static_cast< const SfxBoolItem & >(
552 rItemSet.Get( nWhichId )).GetValue();
553 if( bWasReverse != bNewReverse )
555 aScale.Orientation = bNewReverse ? AxisOrientation_REVERSE : AxisOrientation_MATHEMATICAL;
556 bSetScale = true;
559 break;
561 // Increment
562 case SCHATTR_AXIS_AUTO_STEP_MAIN:
563 if( lcl_isAutoMajor(rItemSet) )
565 aScale.IncrementData.Distance.clear();
566 aScale.TimeIncrement.MajorTimeInterval.clear();
567 bSetScale = true;
569 // else SCHATTR_AXIS_STEP_MAIN must have some value
570 break;
572 case SCHATTR_AXIS_MAIN_TIME_UNIT:
573 if( !lcl_isAutoMajor(rItemSet) )
575 if( rItemSet.Get( nWhichId ).QueryValue( aValue ) )
577 TimeInterval aTimeInterval;
578 aScale.TimeIncrement.MajorTimeInterval >>= aTimeInterval;
579 aValue >>= aTimeInterval.TimeUnit;
580 aScale.TimeIncrement.MajorTimeInterval <<= aTimeInterval;
581 bSetScale = true;
584 break;
586 case SCHATTR_AXIS_STEP_MAIN:
587 // only if auto if false
588 if( !lcl_isAutoMajor(rItemSet) )
590 rItemSet.Get( nWhichId ).QueryValue( aValue );
591 if( lcl_isDateAxis(rItemSet) )
593 double fValue = 1.0;
594 if( aValue >>= fValue )
596 TimeInterval aTimeInterval;
597 aScale.TimeIncrement.MajorTimeInterval >>= aTimeInterval;
598 aTimeInterval.Number = static_cast<sal_Int32>(fValue);
599 aScale.TimeIncrement.MajorTimeInterval <<= aTimeInterval;
600 bSetScale = true;
603 else if( aScale.IncrementData.Distance != aValue )
605 aScale.IncrementData.Distance = aValue;
606 bSetScale = true;
609 break;
611 // SubIncrement
612 case SCHATTR_AXIS_AUTO_STEP_HELP:
613 if( lcl_isAutoMinor(rItemSet) )
615 if( aScale.IncrementData.SubIncrements.hasElements() &&
616 aScale.IncrementData.SubIncrements[0].IntervalCount.hasValue() )
618 aScale.IncrementData.SubIncrements[0].IntervalCount.clear();
619 bSetScale = true;
621 if( aScale.TimeIncrement.MinorTimeInterval.hasValue() )
623 aScale.TimeIncrement.MinorTimeInterval.clear();
624 bSetScale = true;
627 // else SCHATTR_AXIS_STEP_MAIN must have some value
628 break;
630 case SCHATTR_AXIS_HELP_TIME_UNIT:
631 if( !lcl_isAutoMinor(rItemSet) )
633 if( rItemSet.Get( nWhichId ).QueryValue( aValue ) )
635 TimeInterval aTimeInterval;
636 aScale.TimeIncrement.MinorTimeInterval >>= aTimeInterval;
637 aValue >>= aTimeInterval.TimeUnit;
638 aScale.TimeIncrement.MinorTimeInterval <<= aTimeInterval;
639 bSetScale = true;
642 break;
644 case SCHATTR_AXIS_STEP_HELP:
645 // only if auto is false
646 if( !lcl_isAutoMinor(rItemSet) )
648 rItemSet.Get( nWhichId ).QueryValue( aValue );
649 if( lcl_isDateAxis(rItemSet) )
651 TimeInterval aTimeInterval;
652 aScale.TimeIncrement.MinorTimeInterval >>= aTimeInterval;
653 aValue >>= aTimeInterval.Number;
654 aScale.TimeIncrement.MinorTimeInterval <<= aTimeInterval;
655 bSetScale = true;
657 else if( aScale.IncrementData.SubIncrements.hasElements() )
659 if( ! aScale.IncrementData.SubIncrements[0].IntervalCount.hasValue() ||
660 aScale.IncrementData.SubIncrements[0].IntervalCount != aValue )
662 OSL_ASSERT( aValue.getValueTypeClass() == uno::TypeClass_LONG );
663 aScale.IncrementData.SubIncrements[0].IntervalCount = aValue;
664 bSetScale = true;
668 break;
670 case SCHATTR_AXIS_AUTO_TIME_RESOLUTION:
671 if( static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId )).GetValue() )
673 aScale.TimeIncrement.TimeResolution.clear();
674 bSetScale = true;
676 break;
677 case SCHATTR_AXIS_TIME_RESOLUTION:
678 // only if auto is false
679 if( ! ( rItemSet.Get( SCHATTR_AXIS_AUTO_TIME_RESOLUTION ).GetValue() ))
681 rItemSet.Get( nWhichId ).QueryValue( aValue );
683 if( aScale.TimeIncrement.TimeResolution != aValue )
685 aScale.TimeIncrement.TimeResolution = aValue;
686 bSetScale = true;
689 break;
691 case SCHATTR_AXIS_AUTO_ORIGIN:
693 if( static_cast< const SfxBoolItem & >(rItemSet.Get( nWhichId )).GetValue() )
695 aScale.Origin.clear();
696 bSetScale = true;
699 break;
701 case SCHATTR_AXIS_ORIGIN:
703 // only if auto is false
704 if( ! (rItemSet.Get( SCHATTR_AXIS_AUTO_ORIGIN ).GetValue() ))
706 rItemSet.Get( nWhichId ).QueryValue( aValue );
708 if( aScale.Origin != aValue )
710 aScale.Origin = aValue;
711 bSetScale = true;
713 if( !AxisHelper::isAxisPositioningEnabled() )
715 //keep old and new settings for axis positioning in sync somehow
716 Reference< chart2::XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis(
717 m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
719 sal_Int32 nDimensionIndex=0;
720 sal_Int32 nAxisIndex=0;
721 if( AxisHelper::getIndicesForAxis( m_xAxis, xCooSys, nDimensionIndex, nAxisIndex ) && nAxisIndex==0 )
723 Reference< beans::XPropertySet > xCrossingMainAxis( AxisHelper::getCrossingMainAxis( m_xAxis, xCooSys ), uno::UNO_QUERY );
724 if( xCrossingMainAxis.is() )
726 double fValue = 0.0;
727 if( aValue >>= fValue )
729 xCrossingMainAxis->setPropertyValue( "CrossoverPosition" , uno::Any( css::chart::ChartAxisPosition_VALUE ));
730 xCrossingMainAxis->setPropertyValue( "CrossoverValue" , uno::Any( fValue ));
732 else
733 xCrossingMainAxis->setPropertyValue( "CrossoverPosition" , uno::Any( css::chart::ChartAxisPosition_START ));
740 break;
742 case SCHATTR_AXIS_POSITION:
744 css::chart::ChartAxisPosition eAxisPos =
745 static_cast<css::chart::ChartAxisPosition>(static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue());
747 css::chart::ChartAxisPosition eOldAxisPos( css::chart::ChartAxisPosition_ZERO );
748 bool bPropExisted = ( GetPropertySet()->getPropertyValue( "CrossoverPosition" ) >>= eOldAxisPos );
750 if( !bPropExisted || ( eOldAxisPos != eAxisPos ))
752 GetPropertySet()->setPropertyValue( "CrossoverPosition" , uno::Any( eAxisPos ));
753 bChangedOtherwise = true;
755 //move the parallel axes to the other side if necessary
756 if( eAxisPos==css::chart::ChartAxisPosition_START || eAxisPos==css::chart::ChartAxisPosition_END )
758 Reference< beans::XPropertySet > xParallelAxis( AxisHelper::getParallelAxis( m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ), uno::UNO_QUERY );
759 if( xParallelAxis.is() )
761 css::chart::ChartAxisPosition eOtherPos;
762 if( xParallelAxis->getPropertyValue( "CrossoverPosition" ) >>= eOtherPos )
764 if( eOtherPos == eAxisPos )
766 css::chart::ChartAxisPosition eOppositePos =
767 (eAxisPos==css::chart::ChartAxisPosition_START)
768 ? css::chart::ChartAxisPosition_END
769 : css::chart::ChartAxisPosition_START;
770 xParallelAxis->setPropertyValue( "CrossoverPosition" , uno::Any( eOppositePos ));
777 break;
779 case SCHATTR_AXIS_POSITION_VALUE:
781 double fValue = static_cast< const SvxDoubleItem & >( rItemSet.Get( nWhichId )).GetValue();
783 double fOldValue = 0.0;
784 bool bPropExisted = ( GetPropertySet()->getPropertyValue( "CrossoverValue" ) >>= fOldValue );
786 if( !bPropExisted || ( fOldValue != fValue ))
788 GetPropertySet()->setPropertyValue( "CrossoverValue" , uno::Any( fValue ));
789 bChangedOtherwise = true;
791 //keep old and new settings for axis positioning in sync somehow
793 Reference< chart2::XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis(
794 m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
796 sal_Int32 nDimensionIndex=0;
797 sal_Int32 nAxisIndex=0;
798 if( AxisHelper::getIndicesForAxis( m_xAxis, xCooSys, nDimensionIndex, nAxisIndex ) && nAxisIndex==0 )
800 Reference< chart2::XAxis > xCrossingMainAxis( AxisHelper::getCrossingMainAxis( m_xAxis, xCooSys ) );
801 if( xCrossingMainAxis.is() )
803 ScaleData aCrossingScale( xCrossingMainAxis->getScaleData() );
804 aCrossingScale.Origin <<= fValue;
805 xCrossingMainAxis->setScaleData(aCrossingScale);
811 break;
813 case SCHATTR_AXIS_SHIFTED_CATEGORY_POSITION:
815 bool bNewValue = static_cast<const SfxBoolItem &> (rItemSet.Get(nWhichId)).GetValue();
816 bool bOldValue = aScale.ShiftedCategoryPosition;
817 if (bOldValue != bNewValue)
819 aScale.ShiftedCategoryPosition = bNewValue;
820 bSetScale = true;
823 break;
825 case SCHATTR_AXIS_LABEL_POSITION:
827 css::chart::ChartAxisLabelPosition ePos =
828 static_cast<css::chart::ChartAxisLabelPosition>(static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue());
830 css::chart::ChartAxisLabelPosition eOldPos( css::chart::ChartAxisLabelPosition_NEAR_AXIS );
831 bool bPropExisted = ( GetPropertySet()->getPropertyValue( "LabelPosition" ) >>= eOldPos );
833 if( !bPropExisted || ( eOldPos != ePos ))
835 GetPropertySet()->setPropertyValue( "LabelPosition" , uno::Any( ePos ));
836 bChangedOtherwise = true;
838 //move the parallel axes to the other side if necessary
839 if( ePos==css::chart::ChartAxisLabelPosition_OUTSIDE_START || ePos==css::chart::ChartAxisLabelPosition_OUTSIDE_END )
841 Reference< beans::XPropertySet > xParallelAxis( AxisHelper::getParallelAxis( m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ), uno::UNO_QUERY );
842 if( xParallelAxis.is() )
844 css::chart::ChartAxisLabelPosition eOtherPos;
845 if( xParallelAxis->getPropertyValue( "LabelPosition" ) >>= eOtherPos )
847 if( eOtherPos == ePos )
849 css::chart::ChartAxisLabelPosition eOppositePos =
850 (ePos==css::chart::ChartAxisLabelPosition_OUTSIDE_START)
851 ? css::chart::ChartAxisLabelPosition_OUTSIDE_END
852 : css::chart::ChartAxisLabelPosition_OUTSIDE_START;
853 xParallelAxis->setPropertyValue( "LabelPosition" , uno::Any( eOppositePos ));
860 break;
862 case SCHATTR_AXIS_MARK_POSITION:
864 css::chart::ChartAxisMarkPosition ePos =
865 static_cast<css::chart::ChartAxisMarkPosition>(static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue());
867 css::chart::ChartAxisMarkPosition eOldPos( css::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS );
868 bool bPropExisted = ( GetPropertySet()->getPropertyValue( "MarkPosition" ) >>= eOldPos );
870 if( !bPropExisted || ( eOldPos != ePos ))
872 GetPropertySet()->setPropertyValue( "MarkPosition" , uno::Any( 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 || fOldVal != fVal )
890 GetPropertySet()->setPropertyValue( "TextRotation" , uno::Any( fVal ));
891 bChangedOtherwise = true;
894 break;
896 case SID_ATTR_NUMBERFORMAT_VALUE:
898 if( m_pExplicitScale )
900 bool bUseSourceFormat =
901 static_cast< const SfxBoolItem & >(
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 Reference< chart2::XCoordinateSystem > xCooSys(
945 AxisHelper::getCoordinateSystemOfAxis(
946 m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
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: */