xref: /trunk/main/chart2/source/controller/itemsetwrapper/AxisItemConverter.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chartcontroller.hxx"
26 #include "AxisItemConverter.hxx"
27 #include "ItemPropertyMap.hxx"
28 #include "CharacterPropertyItemConverter.hxx"
29 #include "GraphicPropertyItemConverter.hxx"
30 #include "chartview/ChartSfxItemIds.hxx"
31 #include "chartview/ExplicitValueProvider.hxx"
32 #include "SchWhichPairs.hxx"
33 #include "macros.hxx"
34 #include "ChartModelHelper.hxx"
35 #include "AxisHelper.hxx"
36 #include "CommonConverters.hxx"
37 #include "ChartTypeHelper.hxx"
38 
39 #include <com/sun/star/chart/ChartAxisLabelPosition.hpp>
40 #include <com/sun/star/chart/ChartAxisMarkPosition.hpp>
41 #include <com/sun/star/chart/ChartAxisPosition.hpp>
42 #include <com/sun/star/chart2/XAxis.hpp>
43 #include <com/sun/star/chart2/AxisOrientation.hpp>
44 #include <com/sun/star/chart2/AxisType.hpp>
45 
46 // for SfxBoolItem
47 #include <svl/eitem.hxx>
48 // for SvxDoubleItem
49 #include <svx/chrtitem.hxx>
50 // for SfxInt32Item
51 #include <svl/intitem.hxx>
52 #include <rtl/math.hxx>
53 
54 #include <algorithm>
55 
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;
61 
62 namespace
63 {
lcl_GetAxisPropertyMap()64 ::comphelper::ItemPropertyMapType & lcl_GetAxisPropertyMap()
65 {
66     static ::comphelper::ItemPropertyMapType aAxisPropertyMap(
67         ::comphelper::MakeItemPropertyMap
68         IPM_MAP_ENTRY( SCHATTR_AXIS_SHOWDESCR,     "DisplayLabels",    0 )
69         IPM_MAP_ENTRY( SCHATTR_AXIS_TICKS,         "MajorTickmarks",   0 )
70         IPM_MAP_ENTRY( SCHATTR_AXIS_HELPTICKS,     "MinorTickmarks",   0 )
71         IPM_MAP_ENTRY( SCHATTR_AXIS_LABEL_ORDER,   "ArrangeOrder",     0 )
72         IPM_MAP_ENTRY( SCHATTR_TEXT_STACKED,       "StackCharacters",  0 )
73         IPM_MAP_ENTRY( SCHATTR_AXIS_LABEL_BREAK,   "TextBreak",        0 )
74         IPM_MAP_ENTRY( SCHATTR_AXIS_LABEL_OVERLAP, "TextOverlap",      0 )
75         );
76 
77     return aAxisPropertyMap;
78 };
79 } // anonymous namespace
80 
81 namespace chart
82 {
83 namespace wrapper
84 {
85 
AxisItemConverter(const Reference<beans::XPropertySet> & rPropertySet,SfxItemPool & rItemPool,SdrModel & rDrawModel,const Reference<chart2::XChartDocument> & xChartDoc,::chart::ExplicitScaleData * pScale,::chart::ExplicitIncrementData * pIncrement,::std::auto_ptr<awt::Size> pRefSize)86 AxisItemConverter::AxisItemConverter(
87     const Reference< beans::XPropertySet > & rPropertySet,
88     SfxItemPool& rItemPool,
89     SdrModel& rDrawModel,
90     const Reference< chart2::XChartDocument > & xChartDoc,
91     ::chart::ExplicitScaleData * pScale /* = NULL */,
92     ::chart::ExplicitIncrementData * pIncrement /* = NULL */,
93     ::std::auto_ptr< awt::Size > pRefSize /* = NULL */ ) :
94         ItemConverter( rPropertySet, rItemPool ),
95         m_xChartDoc( xChartDoc ),
96         m_pExplicitScale( NULL ),
97         m_pExplicitIncrement( NULL )
98 {
99     Reference< lang::XMultiServiceFactory > xNamedPropertyContainerFactory( xChartDoc, uno::UNO_QUERY );
100 
101     if( pScale )
102         m_pExplicitScale = new ::chart::ExplicitScaleData( *pScale );
103     if( pIncrement )
104         m_pExplicitIncrement = new ::chart::ExplicitIncrementData( *pIncrement );
105 
106     m_aConverters.push_back( new GraphicPropertyItemConverter(
107                                  rPropertySet, rItemPool, rDrawModel,
108                                  xNamedPropertyContainerFactory,
109                                  GraphicPropertyItemConverter::LINE_PROPERTIES ));
110     m_aConverters.push_back( new CharacterPropertyItemConverter( rPropertySet, rItemPool, pRefSize,
111                                                                  C2U( "ReferencePageSize" ) ));
112 
113     m_xAxis.set( Reference< chart2::XAxis >( rPropertySet, uno::UNO_QUERY ) );
114     OSL_ASSERT( m_xAxis.is());
115 }
116 
~AxisItemConverter()117 AxisItemConverter::~AxisItemConverter()
118 {
119     delete m_pExplicitScale;
120     delete m_pExplicitIncrement;
121 
122     ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
123                      ::comphelper::DeleteItemConverterPtr() );
124 }
125 
FillItemSet(SfxItemSet & rOutItemSet) const126 void AxisItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
127 {
128     ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
129                      ::comphelper::FillItemSetFunc( rOutItemSet ));
130 
131     // own items
132     ItemConverter::FillItemSet( rOutItemSet );
133 }
134 
ApplyItemSet(const SfxItemSet & rItemSet)135 bool AxisItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
136 {
137     bool bResult = false;
138 
139     ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
140                      ::comphelper::ApplyItemSetFunc( rItemSet, bResult ));
141 
142     // own items
143     return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
144 }
145 
GetWhichPairs() const146 const sal_uInt16 * AxisItemConverter::GetWhichPairs() const
147 {
148     // must span all used items!
149     return nAxisWhichPairs;
150 }
151 
GetItemProperty(tWhichIdType nWhichId,tPropertyNameWithMemberId & rOutProperty) const152 bool AxisItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
153 {
154     ::comphelper::ItemPropertyMapType & rMap( lcl_GetAxisPropertyMap());
155     ::comphelper::ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
156 
157     if( aIt == rMap.end())
158         return false;
159 
160     rOutProperty =(*aIt).second;
161 
162     return true;
163 }
164 
lcl_hasTimeIntervalValue(const uno::Any & rAny)165 bool lcl_hasTimeIntervalValue( const uno::Any& rAny )
166 {
167     bool bRet = false;
168     TimeInterval aValue;
169     if( rAny >>= aValue )
170         bRet = true;
171     return bRet;
172 }
173 
FillSpecialItem(sal_uInt16 nWhichId,SfxItemSet & rOutItemSet) const174 void AxisItemConverter::FillSpecialItem( sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
175 {
176     if( !m_xAxis.is() )
177         return;
178 
179     const chart2::ScaleData&     rScale( m_xAxis->getScaleData() );
180     const chart2::IncrementData& rIncrement( rScale.IncrementData );
181     const uno::Sequence< chart2::SubIncrement >& rSubIncrements( rScale.IncrementData.SubIncrements );
182     const TimeIncrement& rTimeIncrement( rScale.TimeIncrement );
183     bool bDateAxis = (chart2::AxisType::DATE == rScale.AxisType);
184     if( m_pExplicitScale )
185         bDateAxis = (chart2::AxisType::DATE == m_pExplicitScale->AxisType);
186 
187     switch( nWhichId )
188     {
189         case SCHATTR_AXIS_AUTO_MAX:
190                 rOutItemSet.Put( SfxBoolItem( nWhichId, !hasDoubleValue(rScale.Maximum) ) );
191             break;
192 
193         case SCHATTR_AXIS_MAX:
194             {
195                 double fMax = 10.0;
196                 if( rScale.Maximum >>= fMax )
197                     rOutItemSet.Put( SvxDoubleItem( fMax, nWhichId ) );
198                 else
199                 {
200                     if( m_pExplicitScale )
201                         fMax = m_pExplicitScale->Maximum;
202                     rOutItemSet.Put( SvxDoubleItem( fMax, nWhichId ) );
203                 }
204             }
205             break;
206 
207         case SCHATTR_AXIS_AUTO_MIN:
208                 rOutItemSet.Put( SfxBoolItem( nWhichId, !hasDoubleValue(rScale.Minimum) ) );
209             break;
210 
211         case SCHATTR_AXIS_MIN:
212             {
213                 double fMin = 0.0;
214                 if( rScale.Minimum >>= fMin )
215                     rOutItemSet.Put( SvxDoubleItem( fMin, nWhichId ) );
216                 else if( m_pExplicitScale )
217                     rOutItemSet.Put( SvxDoubleItem( m_pExplicitScale->Minimum, nWhichId ));
218             }
219             break;
220 
221         case SCHATTR_AXIS_LOGARITHM:
222             {
223                 sal_Bool bValue = AxisHelper::isLogarithmic( rScale.Scaling );
224                 rOutItemSet.Put( SfxBoolItem( nWhichId, bValue ));
225             }
226             break;
227 
228         case SCHATTR_AXIS_REVERSE:
229                 rOutItemSet.Put( SfxBoolItem( nWhichId, (AxisOrientation_REVERSE == rScale.Orientation) ));
230             break;
231 
232         // Increment
233         case SCHATTR_AXIS_AUTO_STEP_MAIN:
234             if( bDateAxis )
235                 rOutItemSet.Put( SfxBoolItem( nWhichId, !lcl_hasTimeIntervalValue(rTimeIncrement.MajorTimeInterval) ) );
236             else
237                 rOutItemSet.Put( SfxBoolItem( nWhichId, !hasDoubleValue(rIncrement.Distance) ) );
238             break;
239 
240         case SCHATTR_AXIS_MAIN_TIME_UNIT:
241             {
242                 TimeInterval aTimeInterval;
243                 if( rTimeIncrement.MajorTimeInterval >>= aTimeInterval )
244                     rOutItemSet.Put( SfxInt32Item( nWhichId, aTimeInterval.TimeUnit ) );
245                 else if( m_pExplicitIncrement )
246                     rOutItemSet.Put( SfxInt32Item( nWhichId, m_pExplicitIncrement->MajorTimeInterval.TimeUnit ) );
247             }
248             break;
249 
250         case SCHATTR_AXIS_STEP_MAIN:
251             if( bDateAxis )
252             {
253                 TimeInterval aTimeInterval;
254                 if( rTimeIncrement.MajorTimeInterval >>= aTimeInterval )
255                     rOutItemSet.Put( SvxDoubleItem(aTimeInterval.Number, nWhichId ));
256                 else if( m_pExplicitIncrement )
257                     rOutItemSet.Put( SvxDoubleItem( m_pExplicitIncrement->MajorTimeInterval.Number, nWhichId ));
258             }
259             else
260             {
261                 double fDistance = 1.0;
262                 if( rIncrement.Distance >>= fDistance )
263                     rOutItemSet.Put( SvxDoubleItem(fDistance, nWhichId ));
264                 else if( m_pExplicitIncrement )
265                     rOutItemSet.Put( SvxDoubleItem( m_pExplicitIncrement->Distance, nWhichId ));
266             }
267             break;
268 
269         // SubIncrement
270         case SCHATTR_AXIS_AUTO_STEP_HELP:
271             if( bDateAxis )
272                 rOutItemSet.Put( SfxBoolItem( nWhichId, !lcl_hasTimeIntervalValue(rTimeIncrement.MinorTimeInterval) ) );
273             else
274                 rOutItemSet.Put( SfxBoolItem( nWhichId,
275                     ! ( rSubIncrements.getLength() > 0 && rSubIncrements[0].IntervalCount.hasValue() )));
276             break;
277 
278         case SCHATTR_AXIS_HELP_TIME_UNIT:
279             {
280                 TimeInterval aTimeInterval;
281                 if( rTimeIncrement.MinorTimeInterval >>= aTimeInterval )
282                     rOutItemSet.Put( SfxInt32Item( nWhichId, aTimeInterval.TimeUnit ) );
283                 else if( m_pExplicitIncrement )
284                     rOutItemSet.Put( SfxInt32Item( nWhichId, m_pExplicitIncrement->MinorTimeInterval.TimeUnit ) );
285             }
286             break;
287 
288         case SCHATTR_AXIS_STEP_HELP:
289             if( bDateAxis )
290             {
291                 TimeInterval aTimeInterval;
292                 if( rTimeIncrement.MinorTimeInterval >>= aTimeInterval )
293                     rOutItemSet.Put( SfxInt32Item( nWhichId, aTimeInterval.Number ));
294                 else if( m_pExplicitIncrement )
295                     rOutItemSet.Put( SfxInt32Item( nWhichId, m_pExplicitIncrement->MinorTimeInterval.Number ));
296             }
297             else
298             {
299                 if( rSubIncrements.getLength() > 0 && rSubIncrements[0].IntervalCount.hasValue())
300                 {
301                     OSL_ASSERT( rSubIncrements[0].IntervalCount.getValueTypeClass() == uno::TypeClass_LONG );
302                     rOutItemSet.Put( SfxInt32Item( nWhichId,
303                             *reinterpret_cast< const sal_Int32 * >(
304                                 rSubIncrements[0].IntervalCount.getValue()) ));
305                 }
306                 else
307                 {
308                     if( m_pExplicitIncrement && !m_pExplicitIncrement->SubIncrements.empty() )
309                     {
310                         rOutItemSet.Put( SfxInt32Item( nWhichId,
311                                 m_pExplicitIncrement->SubIncrements[0].IntervalCount ));
312                     }
313                 }
314             }
315             break;
316 
317         case SCHATTR_AXIS_AUTO_TIME_RESOLUTION:
318             {
319                 rOutItemSet.Put( SfxBoolItem( nWhichId,
320                         !rTimeIncrement.TimeResolution.hasValue() ));
321             }
322             break;
323         case SCHATTR_AXIS_TIME_RESOLUTION:
324             {
325                 long nTimeResolution=0;
326                 if( rTimeIncrement.TimeResolution >>= nTimeResolution )
327                     rOutItemSet.Put( SfxInt32Item( nWhichId, nTimeResolution ) );
328                 else if( m_pExplicitScale )
329                     rOutItemSet.Put( SfxInt32Item( nWhichId, m_pExplicitScale->TimeResolution ) );
330             }
331             break;
332 
333         case SCHATTR_AXIS_AUTO_ORIGIN:
334         {
335             rOutItemSet.Put( SfxBoolItem( nWhichId, ( !hasDoubleValue(rScale.Origin) )));
336         }
337         break;
338 
339         case SCHATTR_AXIS_ORIGIN:
340         {
341             double fOrigin = 0.0;
342             if( !(rScale.Origin >>= fOrigin) )
343             {
344                 if( m_pExplicitScale )
345                     fOrigin = m_pExplicitScale->Origin;
346             }
347             rOutItemSet.Put( SvxDoubleItem( fOrigin, nWhichId ));
348         }
349         break;
350 
351         case SCHATTR_AXIS_POSITION:
352         {
353             ::com::sun::star::chart::ChartAxisPosition eAxisPos( ::com::sun::star::chart::ChartAxisPosition_ZERO );
354             GetPropertySet()->getPropertyValue(C2U( "CrossoverPosition" )) >>= eAxisPos;
355             rOutItemSet.Put( SfxInt32Item( nWhichId, eAxisPos ) );
356         }
357         break;
358 
359         case SCHATTR_AXIS_POSITION_VALUE:
360         {
361             double fValue = 0.0;
362             if( GetPropertySet()->getPropertyValue(C2U( "CrossoverValue" )) >>= fValue )
363                 rOutItemSet.Put( SvxDoubleItem( fValue, nWhichId ) );
364         }
365         break;
366 
367         case SCHATTR_AXIS_CROSSING_MAIN_AXIS_NUMBERFORMAT:
368         {
369             //read only item
370             //necessary tp display the crossing value with an appropriate format
371 
372             Reference< chart2::XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis(
373                 m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
374 
375             Reference< chart2::XAxis > xCrossingMainAxis( AxisHelper::getCrossingMainAxis( m_xAxis, xCooSys ) );
376 
377             sal_Int32 nFormatKey = ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
378                 xCrossingMainAxis, xCooSys, Reference< util::XNumberFormatsSupplier >( m_xChartDoc, uno::UNO_QUERY ) );
379 
380             rOutItemSet.Put( SfxUInt32Item( nWhichId, nFormatKey ));
381         }
382         break;
383 
384         case SCHATTR_AXIS_LABEL_POSITION:
385         {
386             ::com::sun::star::chart::ChartAxisLabelPosition ePos( ::com::sun::star::chart::ChartAxisLabelPosition_NEAR_AXIS );
387             GetPropertySet()->getPropertyValue(C2U( "LabelPosition" )) >>= ePos;
388             rOutItemSet.Put( SfxInt32Item( nWhichId, ePos ) );
389         }
390         break;
391 
392         case SCHATTR_AXIS_MARK_POSITION:
393         {
394             ::com::sun::star::chart::ChartAxisMarkPosition ePos( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS );
395             GetPropertySet()->getPropertyValue(C2U( "MarkPosition" )) >>= ePos;
396             rOutItemSet.Put( SfxInt32Item( nWhichId, ePos ) );
397         }
398         break;
399 
400         case SCHATTR_TEXT_DEGREES:
401         {
402             // convert double to int (times 100)
403             double fVal = 0;
404 
405             if( GetPropertySet()->getPropertyValue( C2U( "TextRotation" )) >>= fVal )
406             {
407                 rOutItemSet.Put( SfxInt32Item( nWhichId, static_cast< sal_Int32 >(
408                                                    ::rtl::math::round( fVal * 100.0 ) ) ));
409             }
410         }
411         break;
412 
413         case SID_ATTR_NUMBERFORMAT_VALUE:
414         {
415             if( m_pExplicitScale )
416             {
417                 Reference< chart2::XCoordinateSystem > xCooSys(
418                         AxisHelper::getCoordinateSystemOfAxis(
419                               m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
420 
421                 sal_Int32 nFormatKey = ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
422                     m_xAxis, xCooSys, Reference< util::XNumberFormatsSupplier >( m_xChartDoc, uno::UNO_QUERY ) );
423 
424                 rOutItemSet.Put( SfxUInt32Item( nWhichId, nFormatKey ));
425             }
426         }
427         break;
428 
429         case SID_ATTR_NUMBERFORMAT_SOURCE:
430         {
431             bool bNumberFormatIsSet = ( GetPropertySet()->getPropertyValue( C2U( "NumberFormat" )).hasValue());
432             rOutItemSet.Put( SfxBoolItem( nWhichId, ! bNumberFormatIsSet ));
433         }
434         break;
435 
436         case SCHATTR_AXISTYPE:
437             rOutItemSet.Put( SfxInt32Item( nWhichId, rScale.AxisType ));
438         break;
439 
440         case SCHATTR_AXIS_AUTO_DATEAXIS:
441             rOutItemSet.Put( SfxBoolItem( nWhichId, rScale.AutoDateAxis ));
442         break;
443 
444         case SCHATTR_AXIS_ALLOW_DATEAXIS:
445         {
446             Reference< chart2::XCoordinateSystem > xCooSys(
447                 AxisHelper::getCoordinateSystemOfAxis( m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
448             sal_Int32 nDimensionIndex=0; sal_Int32 nAxisIndex=0;
449             AxisHelper::getIndicesForAxis(m_xAxis, xCooSys, nDimensionIndex, nAxisIndex );
450             bool bChartTypeAllowsDateAxis = ChartTypeHelper::isSupportingDateAxis( AxisHelper::getChartTypeByIndex( xCooSys, 0 ), 2, nDimensionIndex );
451             rOutItemSet.Put( SfxBoolItem( nWhichId, bChartTypeAllowsDateAxis ));
452         }
453         break;
454     }
455 }
456 
lcl_isDateAxis(const SfxItemSet & rItemSet)457 bool lcl_isDateAxis( const SfxItemSet & rItemSet )
458 {
459     sal_Int32 nAxisType = static_cast< const SfxInt32Item & >( rItemSet.Get( SCHATTR_AXISTYPE )).GetValue();//::com::sun::star::chart2::AxisType
460     return (chart2::AxisType::DATE == nAxisType);
461 }
462 
lcl_isAutoMajor(const SfxItemSet & rItemSet)463 bool lcl_isAutoMajor( const SfxItemSet & rItemSet )
464 {
465     bool bRet = static_cast< const SfxBoolItem & >( rItemSet.Get( SCHATTR_AXIS_AUTO_STEP_MAIN )).GetValue();
466     return bRet;
467 }
468 
lcl_isAutoMinor(const SfxItemSet & rItemSet)469 bool lcl_isAutoMinor( const SfxItemSet & rItemSet )
470 {
471     bool bRet = static_cast< const SfxBoolItem & >( rItemSet.Get( SCHATTR_AXIS_AUTO_STEP_HELP )).GetValue();
472     return bRet;
473 }
474 
ApplySpecialItem(sal_uInt16 nWhichId,const SfxItemSet & rItemSet)475 bool AxisItemConverter::ApplySpecialItem( sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
476 {
477     if( !m_xAxis.is() )
478         return false;
479 
480     chart2::ScaleData     aScale( m_xAxis->getScaleData() );
481 
482     bool bSetScale    = false;
483     bool bChangedOtherwise = false;
484 
485     uno::Any aValue;
486 
487     switch( nWhichId )
488     {
489         case SCHATTR_AXIS_AUTO_MAX:
490             if( (static_cast< const SfxBoolItem & >(
491                      rItemSet.Get( nWhichId )).GetValue() ))
492             {
493                 aScale.Maximum.clear();
494                 bSetScale = true;
495             }
496             // else SCHATTR_AXIS_MAX must have some value
497             break;
498 
499         case SCHATTR_AXIS_MAX:
500             // only if auto if false
501             if( ! (static_cast< const SfxBoolItem & >(
502                        rItemSet.Get( SCHATTR_AXIS_AUTO_MAX )).GetValue() ))
503             {
504                 rItemSet.Get( nWhichId ).QueryValue( aValue );
505 
506                 if( aScale.Maximum != aValue )
507                 {
508                     aScale.Maximum = aValue;
509                     bSetScale = true;
510                 }
511             }
512             break;
513 
514         case SCHATTR_AXIS_AUTO_MIN:
515             if( (static_cast< const SfxBoolItem & >(
516                      rItemSet.Get( nWhichId )).GetValue() ))
517             {
518                 aScale.Minimum.clear();
519                 bSetScale = true;
520             }
521             // else SCHATTR_AXIS_MIN must have some value
522             break;
523 
524         case SCHATTR_AXIS_MIN:
525             // only if auto if false
526             if( ! (static_cast< const SfxBoolItem & >(
527                        rItemSet.Get( SCHATTR_AXIS_AUTO_MIN )).GetValue() ))
528             {
529                 rItemSet.Get( nWhichId ).QueryValue( aValue );
530 
531                 if( aScale.Minimum != aValue )
532                 {
533                     aScale.Minimum = aValue;
534                     bSetScale = true;
535                 }
536             }
537             break;
538 
539         case SCHATTR_AXIS_LOGARITHM:
540         {
541             bool bWasLogarithm = AxisHelper::isLogarithmic( aScale.Scaling );
542 
543             if( (static_cast< const SfxBoolItem & >(
544                      rItemSet.Get( nWhichId )).GetValue() ))
545             {
546                 // logarithm is true
547                 if( ! bWasLogarithm )
548                 {
549                     aScale.Scaling = AxisHelper::createLogarithmicScaling( 10.0 );
550                     bSetScale = true;
551                 }
552             }
553             else
554             {
555                 // logarithm is false => linear scaling
556                 if( bWasLogarithm )
557                 {
558                     aScale.Scaling = AxisHelper::createLinearScaling();
559                     bSetScale = true;
560                 }
561             }
562         }
563         break;
564 
565         case SCHATTR_AXIS_REVERSE:
566         {
567             bool bWasReverse = ( AxisOrientation_REVERSE == aScale.Orientation );
568             bool bNewReverse = (static_cast< const SfxBoolItem & >(
569                      rItemSet.Get( nWhichId )).GetValue() );
570             if( bWasReverse != bNewReverse )
571             {
572                 aScale.Orientation = bNewReverse ? AxisOrientation_REVERSE : AxisOrientation_MATHEMATICAL;
573                 bSetScale = true;
574             }
575         }
576         break;
577 
578         // Increment
579         case SCHATTR_AXIS_AUTO_STEP_MAIN:
580             if( lcl_isAutoMajor(rItemSet) )
581             {
582                 aScale.IncrementData.Distance.clear();
583                 aScale.TimeIncrement.MajorTimeInterval.clear();
584                 bSetScale = true;
585             }
586             // else SCHATTR_AXIS_STEP_MAIN must have some value
587             break;
588 
589         case SCHATTR_AXIS_MAIN_TIME_UNIT:
590             if( !lcl_isAutoMajor(rItemSet) )
591             {
592                 if( rItemSet.Get( nWhichId ).QueryValue( aValue ) )
593                 {
594                     TimeInterval aTimeInterval;
595                     aScale.TimeIncrement.MajorTimeInterval >>= aTimeInterval;
596                     aValue >>= aTimeInterval.TimeUnit;
597                     aScale.TimeIncrement.MajorTimeInterval = uno::makeAny( aTimeInterval );
598                     bSetScale = true;
599                 }
600             }
601             break;
602 
603         case SCHATTR_AXIS_STEP_MAIN:
604             // only if auto if false
605             if( !lcl_isAutoMajor(rItemSet) )
606             {
607                 rItemSet.Get( nWhichId ).QueryValue( aValue );
608                 if( lcl_isDateAxis(rItemSet) )
609                 {
610                     double fValue = 1.0;
611                     if( aValue >>= fValue )
612                     {
613                         TimeInterval aTimeInterval;
614                         aScale.TimeIncrement.MajorTimeInterval >>= aTimeInterval;
615                         aTimeInterval.Number = static_cast<sal_Int32>(fValue);
616                         aScale.TimeIncrement.MajorTimeInterval = uno::makeAny( aTimeInterval );
617                         bSetScale = true;
618                     }
619                 }
620                 else if( aScale.IncrementData.Distance != aValue )
621                 {
622                     aScale.IncrementData.Distance = aValue;
623                     bSetScale = true;
624                 }
625             }
626             break;
627 
628         // SubIncrement
629         case SCHATTR_AXIS_AUTO_STEP_HELP:
630             if( lcl_isAutoMinor(rItemSet) )
631             {
632                 if( aScale.IncrementData.SubIncrements.getLength() > 0 &&
633                     aScale.IncrementData.SubIncrements[0].IntervalCount.hasValue() )
634                 {
635                         aScale.IncrementData.SubIncrements[0].IntervalCount.clear();
636                         bSetScale = true;
637                 }
638                 if( aScale.TimeIncrement.MinorTimeInterval.hasValue() )
639                 {
640                     aScale.TimeIncrement.MinorTimeInterval.clear();
641                     bSetScale = true;
642                 }
643             }
644             // else SCHATTR_AXIS_STEP_MAIN must have some value
645             break;
646 
647         case SCHATTR_AXIS_HELP_TIME_UNIT:
648             if( !lcl_isAutoMinor(rItemSet) )
649             {
650                 if( rItemSet.Get( nWhichId ).QueryValue( aValue ) )
651                 {
652                     TimeInterval aTimeInterval;
653                     aScale.TimeIncrement.MinorTimeInterval >>= aTimeInterval;
654                     aValue >>= aTimeInterval.TimeUnit;
655                     aScale.TimeIncrement.MinorTimeInterval = uno::makeAny( aTimeInterval );
656                     bSetScale = true;
657                 }
658             }
659             break;
660 
661         case SCHATTR_AXIS_STEP_HELP:
662             // only if auto is false
663             if( !lcl_isAutoMinor(rItemSet) )
664             {
665                 rItemSet.Get( nWhichId ).QueryValue( aValue );
666                 if( lcl_isDateAxis(rItemSet) )
667                 {
668                     TimeInterval aTimeInterval;
669                     aScale.TimeIncrement.MinorTimeInterval >>= aTimeInterval;
670                     aValue >>= aTimeInterval.Number;
671                     aScale.TimeIncrement.MinorTimeInterval = uno::makeAny(aTimeInterval);
672                     bSetScale = true;
673                 }
674                 else if( aScale.IncrementData.SubIncrements.getLength() > 0 )
675                 {
676                     if( ! aScale.IncrementData.SubIncrements[0].IntervalCount.hasValue() ||
677                         aScale.IncrementData.SubIncrements[0].IntervalCount != aValue )
678                     {
679                         OSL_ASSERT( aValue.getValueTypeClass() == uno::TypeClass_LONG );
680                         aScale.IncrementData.SubIncrements[0].IntervalCount = aValue;
681                         bSetScale = true;
682                     }
683                 }
684             }
685             break;
686 
687         case SCHATTR_AXIS_AUTO_TIME_RESOLUTION:
688             if( (static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId )).GetValue() ))
689             {
690                 aScale.TimeIncrement.TimeResolution.clear();
691                 bSetScale = true;
692             }
693             break;
694         case SCHATTR_AXIS_TIME_RESOLUTION:
695             // only if auto is false
696             if( ! (static_cast< const SfxBoolItem & >( rItemSet.Get( SCHATTR_AXIS_AUTO_TIME_RESOLUTION )).GetValue() ))
697             {
698                 rItemSet.Get( nWhichId ).QueryValue( aValue );
699 
700                 if( aScale.TimeIncrement.TimeResolution != aValue )
701                 {
702                     aScale.TimeIncrement.TimeResolution = aValue;
703                     bSetScale = true;
704                 }
705             }
706             break;
707 
708 
709         case SCHATTR_AXIS_AUTO_ORIGIN:
710         {
711             if( (static_cast< const SfxBoolItem & >(
712                      rItemSet.Get( nWhichId )).GetValue() ))
713             {
714                 aScale.Origin.clear();
715                 bSetScale = true;
716             }
717         }
718         break;
719 
720         case SCHATTR_AXIS_ORIGIN:
721         {
722             // only if auto is false
723             if( ! (static_cast< const SfxBoolItem & >(
724                        rItemSet.Get( SCHATTR_AXIS_AUTO_ORIGIN )).GetValue() ))
725             {
726                 rItemSet.Get( nWhichId ).QueryValue( aValue );
727 
728                 if( aScale.Origin != aValue )
729                 {
730                     aScale.Origin = aValue;
731                     bSetScale = true;
732 
733                     if( !AxisHelper::isAxisPositioningEnabled() )
734                     {
735                         //keep old and new settings for axis positioning in sync somehow
736                         Reference< chart2::XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis(
737                             m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
738 
739                         sal_Int32 nDimensionIndex=0;
740                         sal_Int32 nAxisIndex=0;
741                         if( AxisHelper::getIndicesForAxis( m_xAxis, xCooSys, nDimensionIndex, nAxisIndex ) && nAxisIndex==0 )
742                         {
743                             Reference< beans::XPropertySet > xCrossingMainAxis( AxisHelper::getCrossingMainAxis( m_xAxis, xCooSys ), uno::UNO_QUERY );
744                             if( xCrossingMainAxis.is() )
745                             {
746                                 double fValue = 0.0;
747                                 if( aValue >>= fValue )
748                                 {
749                                     xCrossingMainAxis->setPropertyValue( C2U( "CrossoverPosition" ), uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_VALUE ));
750                                     xCrossingMainAxis->setPropertyValue( C2U( "CrossoverValue" ), uno::makeAny( fValue ));
751                                 }
752                                 else
753                                     xCrossingMainAxis->setPropertyValue( C2U( "CrossoverPosition" ), uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START ));
754                             }
755                         }
756                     }
757                 }
758             }
759         }
760         break;
761 
762         case SCHATTR_AXIS_POSITION:
763         {
764             ::com::sun::star::chart::ChartAxisPosition eAxisPos =
765                 (::com::sun::star::chart::ChartAxisPosition)
766                 static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();
767 
768             ::com::sun::star::chart::ChartAxisPosition eOldAxisPos( ::com::sun::star::chart::ChartAxisPosition_ZERO );
769             bool bPropExisted = ( GetPropertySet()->getPropertyValue(C2U( "CrossoverPosition" )) >>= eOldAxisPos );
770 
771             if( !bPropExisted || ( eOldAxisPos != eAxisPos ))
772             {
773                 GetPropertySet()->setPropertyValue( C2U( "CrossoverPosition" ), uno::makeAny( eAxisPos ));
774                 bChangedOtherwise = true;
775 
776                 //move the parallel axes to the other side if necessary
777                 if( eAxisPos==::com::sun::star::chart::ChartAxisPosition_START || eAxisPos==::com::sun::star::chart::ChartAxisPosition_END )
778                 {
779                     Reference< beans::XPropertySet > xParallelAxis( AxisHelper::getParallelAxis( m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ), uno::UNO_QUERY );
780                     if( xParallelAxis.is() )
781                     {
782                         ::com::sun::star::chart::ChartAxisPosition eOtherPos;
783                         if( xParallelAxis->getPropertyValue( C2U( "CrossoverPosition" ) ) >>= eOtherPos )
784                         {
785                             if( eOtherPos == eAxisPos )
786                             {
787                                 ::com::sun::star::chart::ChartAxisPosition eOppositePos =
788                                     (eAxisPos==::com::sun::star::chart::ChartAxisPosition_START)
789                                     ? ::com::sun::star::chart::ChartAxisPosition_END
790                                     : ::com::sun::star::chart::ChartAxisPosition_START;
791                                 xParallelAxis->setPropertyValue( C2U( "CrossoverPosition" ), uno::makeAny( eOppositePos ));
792                             }
793                         }
794                     }
795                 }
796             }
797         }
798         break;
799 
800         case SCHATTR_AXIS_POSITION_VALUE:
801         {
802             double fValue = static_cast< const SvxDoubleItem & >( rItemSet.Get( nWhichId )).GetValue();
803 
804             double fOldValue = 0.0;
805             bool bPropExisted = ( GetPropertySet()->getPropertyValue(C2U( "CrossoverValue" )) >>= fOldValue );
806 
807             if( !bPropExisted || ( fOldValue != fValue ))
808             {
809                 GetPropertySet()->setPropertyValue( C2U( "CrossoverValue" ), uno::makeAny( fValue ));
810                 bChangedOtherwise = true;
811 
812                 //keep old and new settings for axis positioning in sync somehow
813                 {
814                     Reference< chart2::XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemOfAxis(
815                         m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
816 
817                     sal_Int32 nDimensionIndex=0;
818                     sal_Int32 nAxisIndex=0;
819                     if( AxisHelper::getIndicesForAxis( m_xAxis, xCooSys, nDimensionIndex, nAxisIndex ) && nAxisIndex==0 && nDimensionIndex==0 )
820                     {
821                         Reference< chart2::XAxis > xCrossingMainAxis( AxisHelper::getCrossingMainAxis( m_xAxis, xCooSys ) );
822                         if( xCrossingMainAxis.is() )
823                         {
824                             ScaleData aCrossingScale( xCrossingMainAxis->getScaleData() );
825                             aCrossingScale.Origin = uno::makeAny(fValue);
826                             xCrossingMainAxis->setScaleData(aCrossingScale);
827                         }
828                     }
829                 }
830             }
831         }
832         break;
833 
834         case SCHATTR_AXIS_LABEL_POSITION:
835         {
836             ::com::sun::star::chart::ChartAxisLabelPosition ePos =
837                 (::com::sun::star::chart::ChartAxisLabelPosition)
838                 static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();
839 
840             ::com::sun::star::chart::ChartAxisLabelPosition eOldPos( ::com::sun::star::chart::ChartAxisLabelPosition_NEAR_AXIS );
841             bool bPropExisted = ( GetPropertySet()->getPropertyValue(C2U( "LabelPosition" )) >>= eOldPos );
842 
843             if( !bPropExisted || ( eOldPos != ePos ))
844             {
845                 GetPropertySet()->setPropertyValue( C2U( "LabelPosition" ), uno::makeAny( ePos ));
846                 bChangedOtherwise = true;
847 
848                 //move the parallel axes to the other side if necessary
849                 if( ePos==::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START || ePos==::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_END )
850                 {
851                     Reference< beans::XPropertySet > xParallelAxis( AxisHelper::getParallelAxis( m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ), uno::UNO_QUERY );
852                     if( xParallelAxis.is() )
853                     {
854                         ::com::sun::star::chart::ChartAxisLabelPosition eOtherPos;
855                         if( xParallelAxis->getPropertyValue( C2U( "LabelPosition" ) ) >>= eOtherPos )
856                         {
857                             if( eOtherPos == ePos )
858                             {
859                                 ::com::sun::star::chart::ChartAxisLabelPosition eOppositePos =
860                                     (ePos==::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START)
861                                     ? ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_END
862                                     : ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START;
863                                 xParallelAxis->setPropertyValue( C2U( "LabelPosition" ), uno::makeAny( eOppositePos ));
864                             }
865                         }
866                     }
867                 }
868             }
869         }
870         break;
871 
872         case SCHATTR_AXIS_MARK_POSITION:
873         {
874             ::com::sun::star::chart::ChartAxisMarkPosition ePos =
875                 (::com::sun::star::chart::ChartAxisMarkPosition)
876                 static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();
877 
878             ::com::sun::star::chart::ChartAxisMarkPosition eOldPos( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS );
879             bool bPropExisted = ( GetPropertySet()->getPropertyValue(C2U( "MarkPosition" )) >>= eOldPos );
880 
881             if( !bPropExisted || ( eOldPos != ePos ))
882             {
883                 GetPropertySet()->setPropertyValue( C2U( "MarkPosition" ), uno::makeAny( ePos ));
884                 bChangedOtherwise = true;
885             }
886         }
887         break;
888 
889         case SCHATTR_TEXT_DEGREES:
890         {
891             // convert int to double (divided by 100)
892             double fVal = static_cast< double >(
893                 static_cast< const SfxInt32Item & >(
894                     rItemSet.Get( nWhichId )).GetValue()) / 100.0;
895             double fOldVal = 0.0;
896             bool bPropExisted =
897                 ( GetPropertySet()->getPropertyValue( C2U( "TextRotation" )) >>= fOldVal );
898 
899             if( ! bPropExisted ||
900                 ( bPropExisted && fOldVal != fVal ))
901             {
902                 GetPropertySet()->setPropertyValue( C2U( "TextRotation" ), uno::makeAny( fVal ));
903                 bChangedOtherwise = true;
904             }
905         }
906         break;
907 
908         case SID_ATTR_NUMBERFORMAT_VALUE:
909         {
910             if( m_pExplicitScale )
911             {
912                 bool bUseSourceFormat =
913                     (static_cast< const SfxBoolItem & >(
914                         rItemSet.Get( SID_ATTR_NUMBERFORMAT_SOURCE )).GetValue() );
915 
916                 if( ! bUseSourceFormat )
917                 {
918                     sal_Int32 nFmt = static_cast< sal_Int32 >(
919                         static_cast< const SfxUInt32Item & >(
920                             rItemSet.Get( nWhichId )).GetValue());
921 
922                     aValue = uno::makeAny(nFmt);
923                     if( GetPropertySet()->getPropertyValue( C2U( "NumberFormat" )) != aValue )
924                     {
925                         GetPropertySet()->setPropertyValue( C2U( "NumberFormat" ), aValue );
926                         bChangedOtherwise = true;
927                     }
928                 }
929             }
930         }
931         break;
932 
933         case SID_ATTR_NUMBERFORMAT_SOURCE:
934         {
935             bool bUseSourceFormat =
936                 (static_cast< const SfxBoolItem & >(
937                     rItemSet.Get( nWhichId )).GetValue() );
938             bool bNumberFormatIsSet = ( GetPropertySet()->getPropertyValue( C2U( "NumberFormat" )).hasValue());
939 
940             bChangedOtherwise = (bUseSourceFormat == bNumberFormatIsSet);
941             if( bChangedOtherwise )
942             {
943                 if( ! bUseSourceFormat )
944                 {
945                     SfxItemState aState = rItemSet.GetItemState( SID_ATTR_NUMBERFORMAT_VALUE );
946                     if( aState == SFX_ITEM_SET )
947                     {
948                         sal_Int32 nFormatKey = static_cast< sal_Int32 >(
949                         static_cast< const SfxUInt32Item & >(
950                             rItemSet.Get( SID_ATTR_NUMBERFORMAT_VALUE )).GetValue());
951                         aValue <<= nFormatKey;
952                     }
953                     else
954                     {
955                         Reference< chart2::XCoordinateSystem > xCooSys(
956                         AxisHelper::getCoordinateSystemOfAxis(
957                               m_xAxis, ChartModelHelper::findDiagram( m_xChartDoc ) ) );
958 
959                         sal_Int32 nFormatKey = ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
960                             m_xAxis, xCooSys, Reference< util::XNumberFormatsSupplier >( m_xChartDoc, uno::UNO_QUERY ) );
961 
962                         aValue <<= nFormatKey;
963                     }
964                 }
965                 // else set a void Any
966                 GetPropertySet()->setPropertyValue( C2U( "NumberFormat" ), aValue );
967             }
968         }
969         break;
970 
971         case SCHATTR_AXISTYPE:
972         {
973             sal_Int32 nNewAxisType = static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();//::com::sun::star::chart2::AxisType
974             aScale.AxisType = nNewAxisType;
975             bSetScale = true;
976         }
977         break;
978 
979         case SCHATTR_AXIS_AUTO_DATEAXIS:
980         {
981             bool bNewValue = static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId )).GetValue();
982             bool bOldValue = aScale.AutoDateAxis;
983             if( bOldValue != bNewValue )
984             {
985                 aScale.AutoDateAxis = bNewValue;
986                 bSetScale = true;
987             }
988         }
989         break;
990     }
991 
992     if( bSetScale )
993         m_xAxis->setScaleData( aScale );
994 
995     return (bSetScale || bChangedOtherwise);
996 }
997 
998 } //  namespace wrapper
999 } //  namespace chart
1000