LCOV - code coverage report
Current view: top level - xmloff/source/chart - SchXMLAxisContext.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 306 458 66.8 %
Date: 2014-04-11 Functions: 29 34 85.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <sax/tools/converter.hxx>
      21             : 
      22             : #include "SchXMLAxisContext.hxx"
      23             : #include "SchXMLChartContext.hxx"
      24             : #include "SchXMLTools.hxx"
      25             : #include <xmloff/xmlnmspe.hxx>
      26             : #include <xmloff/xmlement.hxx>
      27             : #include <xmloff/xmlstyle.hxx>
      28             : #include <xmloff/prstylei.hxx>
      29             : #include <xmloff/nmspmap.hxx>
      30             : #include <xmloff/xmluconv.hxx>
      31             : 
      32             : #include <tools/color.hxx>
      33             : 
      34             : #include <com/sun/star/chart/ChartAxisLabelPosition.hpp>
      35             : #include <com/sun/star/chart/ChartAxisMarkPosition.hpp>
      36             : #include <com/sun/star/chart/ChartAxisPosition.hpp>
      37             : #include <com/sun/star/chart/ChartAxisType.hpp>
      38             : #include <com/sun/star/chart/TimeIncrement.hpp>
      39             : #include <com/sun/star/chart/TimeInterval.hpp>
      40             : #include <com/sun/star/chart/TimeUnit.hpp>
      41             : #include <com/sun/star/chart/XAxis.hpp>
      42             : #include <com/sun/star/chart/XAxisSupplier.hpp>
      43             : #include <com/sun/star/chart2/AxisType.hpp>
      44             : #include <com/sun/star/chart2/XChartDocument.hpp>
      45             : #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
      46             : 
      47             : #include <com/sun/star/drawing/LineStyle.hpp>
      48             : 
      49             : using namespace ::xmloff::token;
      50             : using namespace com::sun::star;
      51             : 
      52             : using com::sun::star::uno::Reference;
      53             : 
      54             : static const SvXMLEnumMapEntry aXMLAxisDimensionMap[] =
      55             : {
      56             :     { XML_X,  SCH_XML_AXIS_X  },
      57             :     { XML_Y,  SCH_XML_AXIS_Y  },
      58             :     { XML_Z,  SCH_XML_AXIS_Z  },
      59             :     { XML_TOKEN_INVALID, 0 }
      60             : };
      61             : 
      62             : static const SvXMLEnumMapEntry aXMLAxisTypeMap[] =
      63             : {
      64             :     { XML_AUTO,  ::com::sun::star::chart::ChartAxisType::AUTOMATIC },
      65             :     { XML_TEXT,  ::com::sun::star::chart::ChartAxisType::CATEGORY },
      66             :     { XML_DATE,  ::com::sun::star::chart::ChartAxisType::DATE },
      67             :     { XML_TOKEN_INVALID, 0 }
      68             : };
      69             : 
      70             : class SchXMLCategoriesContext : public SvXMLImportContext
      71             : {
      72             : private:
      73             :     OUString& mrAddress;
      74             : 
      75             : public:
      76             :     SchXMLCategoriesContext( SvXMLImport& rImport,
      77             :                                    sal_uInt16 nPrefix,
      78             :                                    const OUString& rLocalName,
      79             :                                    OUString& rAddress );
      80             :     virtual ~SchXMLCategoriesContext();
      81             :     virtual void StartElement( const Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ) SAL_OVERRIDE;
      82             : };
      83             : 
      84             : class DateScaleContext : public SvXMLImportContext
      85             : {
      86             : public:
      87             :     DateScaleContext( SvXMLImport& rImport,
      88             :                         sal_uInt16 nPrefix, const OUString& rLocalName,
      89             :                         const Reference< beans::XPropertySet > xAxisProps );
      90             : 
      91             :     virtual ~DateScaleContext();
      92             :     virtual void StartElement( const Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ) SAL_OVERRIDE;
      93             : 
      94             : private:
      95             :     Reference< beans::XPropertySet > m_xAxisProps;
      96             : };
      97             : 
      98         201 : SchXMLAxisContext::SchXMLAxisContext( SchXMLImportHelper& rImpHelper,
      99             :                                       SvXMLImport& rImport, const OUString& rLocalName,
     100             :                                       Reference< chart::XDiagram > xDiagram,
     101             :                                       std::vector< SchXMLAxis >& rAxes,
     102             :                                       OUString & rCategoriesAddress,
     103             :                                       bool bAddMissingXAxisForNetCharts,
     104             :                                       bool bAdaptWrongPercentScaleValues,
     105             :                                       bool bAdaptXAxisOrientationForOld2DBarCharts,
     106             :                                       bool& rbAxisPositionAttributeImported ) :
     107             :         SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ),
     108             :         m_rImportHelper( rImpHelper ),
     109             :         m_xDiagram( xDiagram ),
     110             :         m_rAxes( rAxes ),
     111             :         m_rCategoriesAddress( rCategoriesAddress ),
     112             :         m_nAxisType(chart::ChartAxisType::AUTOMATIC),
     113             :         m_bAxisTypeImported(false),
     114             :         m_bDateScaleImported(false),
     115             :         m_bAddMissingXAxisForNetCharts( bAddMissingXAxisForNetCharts ),
     116             :         m_bAdaptWrongPercentScaleValues( bAdaptWrongPercentScaleValues ),
     117             :         m_bAdaptXAxisOrientationForOld2DBarCharts( bAdaptXAxisOrientationForOld2DBarCharts ),
     118         201 :         m_rbAxisPositionAttributeImported( rbAxisPositionAttributeImported )
     119             : {
     120         201 : }
     121             : 
     122         402 : SchXMLAxisContext::~SchXMLAxisContext()
     123         402 : {}
     124             : 
     125         339 : static Reference< chart::XAxis > lcl_getChartAxis( SchXMLAxis aCurrentAxis, const Reference< chart::XDiagram > xDiagram )
     126             : {
     127         339 :     Reference< chart::XAxis > xAxis;
     128         678 :     Reference< chart::XAxisSupplier > xAxisSuppl( xDiagram, uno::UNO_QUERY );
     129         339 :     if( !xAxisSuppl.is() )
     130           0 :         return xAxis;
     131         339 :     if( aCurrentAxis.nAxisIndex == 0 )
     132         331 :         xAxis = xAxisSuppl->getAxis(aCurrentAxis.eDimension);
     133             :     else
     134           8 :         xAxis = xAxisSuppl->getSecondaryAxis(aCurrentAxis.eDimension);
     135         339 :     return xAxis;
     136             : }
     137             : 
     138             : /* returns a shape for the current axis's title. The property
     139             :    "Has...AxisTitle" is set to "True" to get the shape
     140             :  */
     141          22 : Reference< drawing::XShape > SchXMLAxisContext::getTitleShape()
     142             : {
     143          22 :     Reference< drawing::XShape > xResult;
     144          44 :     Reference< beans::XPropertySet > xDiaProp( m_rImportHelper.GetChartDocument()->getDiagram(), uno::UNO_QUERY );
     145          44 :     Reference< chart::XAxis > xAxis( lcl_getChartAxis( m_aCurrentAxis, m_xDiagram ) );
     146          22 :     if( !xDiaProp.is() || !xAxis.is() )
     147           0 :         return xResult;
     148             : 
     149          44 :     OUString aPropName;
     150          22 :     switch( m_aCurrentAxis.eDimension )
     151             :     {
     152             :         case SCH_XML_AXIS_X:
     153          12 :             if( m_aCurrentAxis.nAxisIndex == 0 )
     154          12 :                 aPropName = "HasXAxisTitle";
     155             :             else
     156           0 :                 aPropName = "HasSecondaryXAxisTitle";
     157          12 :             break;
     158             :         case SCH_XML_AXIS_Y:
     159          10 :             if( m_aCurrentAxis.nAxisIndex == 0 )
     160          10 :                 aPropName = "HasYAxisTitle";
     161             :             else
     162           0 :                 aPropName = "HasSecondaryYAxisTitle";
     163          10 :             break;
     164             :         case SCH_XML_AXIS_Z:
     165           0 :             aPropName = "HasZAxisTitle";
     166           0 :             break;
     167             :         case SCH_XML_AXIS_UNDEF:
     168             :             SAL_INFO("xmloff.chart", "Invalid axis" );
     169           0 :             break;
     170             :     }
     171          22 :     xDiaProp->setPropertyValue( aPropName, uno::makeAny(sal_True) );
     172          22 :     xResult = Reference< drawing::XShape >( xAxis->getAxisTitle(), uno::UNO_QUERY );
     173          22 :     return xResult;
     174             : }
     175             : 
     176          94 : void SchXMLAxisContext::CreateGrid( const OUString& sAutoStyleName, bool bIsMajor )
     177             : {
     178          94 :     Reference< beans::XPropertySet > xDiaProp( m_rImportHelper.GetChartDocument()->getDiagram(), uno::UNO_QUERY );
     179         188 :     Reference< chart::XAxis > xAxis( lcl_getChartAxis( m_aCurrentAxis, m_xDiagram ) );
     180          94 :     if( !xDiaProp.is() || !xAxis.is() )
     181          94 :         return;
     182             : 
     183         188 :     OUString aPropName;
     184          94 :     switch( m_aCurrentAxis.eDimension )
     185             :     {
     186             :         case SCH_XML_AXIS_X:
     187          11 :             if( bIsMajor )
     188          11 :                 aPropName = "HasXAxisGrid";
     189             :             else
     190           0 :                 aPropName = "HasXAxisHelpGrid";
     191          11 :             break;
     192             :         case SCH_XML_AXIS_Y:
     193          83 :             if( bIsMajor )
     194          71 :                 aPropName = "HasYAxisGrid";
     195             :             else
     196          12 :                 aPropName = "HasYAxisHelpGrid";
     197          83 :             break;
     198             :         case SCH_XML_AXIS_Z:
     199           0 :             if( bIsMajor )
     200           0 :                 aPropName = "HasZAxisGrid";
     201             :             else
     202           0 :                 aPropName = "HasZAxisHelpGrid";
     203           0 :             break;
     204             :         case SCH_XML_AXIS_UNDEF:
     205             :             SAL_INFO("xmloff.chart", "Invalid axis" );
     206           0 :             break;
     207             :     }
     208          94 :     xDiaProp->setPropertyValue( aPropName, uno::makeAny(sal_True) );
     209             : 
     210          94 :     Reference< beans::XPropertySet > xGridProp;
     211          94 :     if( bIsMajor )
     212          82 :         xGridProp = xAxis->getMajorGrid();
     213             :     else
     214          12 :         xGridProp = xAxis->getMinorGrid();
     215             : 
     216             :     // set properties
     217          94 :     if( xGridProp.is())
     218             :     {
     219             :         // the line color is black as default, in the model it is a light gray
     220          94 :         xGridProp->setPropertyValue("LineColor",
     221          94 :                                      uno::makeAny( COL_BLACK ));
     222          94 :         if( !sAutoStyleName.isEmpty())
     223             :         {
     224          94 :             const SvXMLStylesContext* pStylesCtxt = m_rImportHelper.GetAutoStylesContext();
     225          94 :             if( pStylesCtxt )
     226             :             {
     227             :                 const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
     228          94 :                     m_rImportHelper.GetChartFamilyID(), sAutoStyleName );
     229             : 
     230          94 :                 if( pStyle && pStyle->ISA( XMLPropStyleContext ))
     231          94 :                     (( XMLPropStyleContext* )pStyle )->FillPropertySet( xGridProp );
     232             :             }
     233             :         }
     234         188 :     }
     235             : }
     236             : 
     237             : namespace
     238             : {
     239             : enum AxisAttributeTokens
     240             : {
     241             :     XML_TOK_AXIS_DIMENSION,
     242             :     XML_TOK_AXIS_NAME,
     243             :     XML_TOK_AXIS_STYLE_NAME,
     244             :     XML_TOK_AXIS_TYPE,
     245             :     XML_TOK_AXIS_TYPE_EXT
     246             : };
     247             : 
     248             : const SvXMLTokenMapEntry aAxisAttributeTokenMap[] =
     249             : {
     250             :     { XML_NAMESPACE_CHART,      XML_DIMENSION,  XML_TOK_AXIS_DIMENSION      },
     251             :     { XML_NAMESPACE_CHART,      XML_NAME,       XML_TOK_AXIS_NAME           },
     252             :     { XML_NAMESPACE_CHART,      XML_STYLE_NAME, XML_TOK_AXIS_STYLE_NAME     },
     253             :     { XML_NAMESPACE_CHART,      XML_AXIS_TYPE,  XML_TOK_AXIS_TYPE           },
     254             :     { XML_NAMESPACE_CHART_EXT,  XML_AXIS_TYPE,  XML_TOK_AXIS_TYPE_EXT       },
     255             :     XML_TOKEN_MAP_END
     256             : };
     257             : 
     258             : class AxisAttributeTokenMap : public SvXMLTokenMap
     259             : {
     260             : public:
     261           7 :     AxisAttributeTokenMap(): SvXMLTokenMap( aAxisAttributeTokenMap ) {}
     262           7 :     virtual ~AxisAttributeTokenMap() {}
     263             : };
     264             : 
     265             : //a AxisAttributeTokenMap Singleton
     266             : struct theAxisAttributeTokenMap : public rtl::Static< AxisAttributeTokenMap, theAxisAttributeTokenMap > {};
     267             : }
     268             : 
     269         201 : void SchXMLAxisContext::StartElement( const Reference< xml::sax::XAttributeList >& xAttrList )
     270             : {
     271             :     // parse attributes
     272         201 :     sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
     273         201 :     SchXMLImport& rImport = ( SchXMLImport& )GetImport();
     274         201 :     const SvXMLTokenMap& rAttrTokenMap = theAxisAttributeTokenMap::get();
     275             : 
     276         855 :     for( sal_Int16 i = 0; i < nAttrCount; i++ )
     277             :     {
     278         654 :         OUString sAttrName = xAttrList->getNameByIndex( i );
     279        1308 :         OUString aLocalName;
     280        1308 :         OUString aValue = xAttrList->getValueByIndex( i );
     281         654 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
     282             : 
     283         654 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
     284             :         {
     285             :             case XML_TOK_AXIS_DIMENSION:
     286             :                 {
     287             :                     sal_uInt16 nEnumVal;
     288         201 :                     if( rImport.GetMM100UnitConverter().convertEnum( nEnumVal, aValue, aXMLAxisDimensionMap ))
     289         201 :                         m_aCurrentAxis.eDimension = ( SchXMLAxisDimension )nEnumVal;
     290             :                 }
     291         201 :                 break;
     292             :             case XML_TOK_AXIS_NAME:
     293         201 :                 m_aCurrentAxis.aName = aValue;
     294         201 :                 break;
     295             :             case XML_TOK_AXIS_TYPE:
     296             :             case XML_TOK_AXIS_TYPE_EXT:
     297             :                 sal_uInt16 nEnumVal;
     298          51 :                 if( rImport.GetMM100UnitConverter().convertEnum( nEnumVal, aValue, aXMLAxisTypeMap ))
     299             :                 {
     300          51 :                     m_nAxisType = nEnumVal;
     301          51 :                     m_bAxisTypeImported = true;
     302             :                 }
     303          51 :                 break;
     304             :             case XML_TOK_AXIS_STYLE_NAME:
     305         201 :                 m_aAutoStyleName = aValue;
     306         201 :                 break;
     307             :         }
     308         654 :     }
     309             : 
     310             :     // check for number of axes with same dimension
     311         201 :     m_aCurrentAxis.nAxisIndex = 0;
     312         201 :     sal_Int32 nNumOfAxes = m_rAxes.size();
     313         358 :     for( sal_Int32 nCurrent = 0; nCurrent < nNumOfAxes; nCurrent++ )
     314             :     {
     315         157 :         if( m_rAxes[ nCurrent ].eDimension == m_aCurrentAxis.eDimension )
     316           8 :             m_aCurrentAxis.nAxisIndex++;
     317             :     }
     318         201 :     CreateAxis();
     319         201 : }
     320             : namespace
     321             : {
     322             : 
     323         150 : Reference< chart2::XAxis > lcl_getAxis( const Reference< frame::XModel >& xChartModel,
     324             :                                             sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
     325             : {
     326         150 :     Reference< chart2::XAxis > xAxis;
     327             : 
     328             :     try
     329             :     {
     330         150 :         Reference< chart2::XChartDocument > xChart2Document( xChartModel, uno::UNO_QUERY );
     331         150 :         if( xChart2Document.is() )
     332             :         {
     333         150 :             Reference< chart2::XDiagram > xDiagram( xChart2Document->getFirstDiagram());
     334         300 :             Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY_THROW );
     335             :             uno::Sequence< Reference< chart2::XCoordinateSystem > >
     336         300 :                 aCooSysSeq( xCooSysCnt->getCoordinateSystems());
     337         150 :             sal_Int32 nCooSysIndex = 0;
     338         150 :             if( nCooSysIndex < aCooSysSeq.getLength() )
     339             :             {
     340         150 :                 Reference< chart2::XCoordinateSystem > xCooSys( aCooSysSeq[nCooSysIndex] );
     341         150 :                 if( xCooSys.is() && nDimensionIndex < xCooSys->getDimension() )
     342             :                 {
     343         150 :                     const sal_Int32 nMaxAxisIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex);
     344         150 :                     if( nAxisIndex <= nMaxAxisIndex )
     345         150 :                         xAxis = xCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex );
     346         150 :                 }
     347         150 :             }
     348         150 :         }
     349             :     }
     350           0 :     catch( uno::Exception & )
     351             :     {
     352             :         SAL_INFO("xmloff.chart", "Couldn't get axis" );
     353             :     }
     354             : 
     355         150 :     return xAxis;
     356             : }
     357             : 
     358           0 : bool lcl_divideBy100( uno::Any& rDoubleAny )
     359             : {
     360           0 :     bool bChanged = false;
     361           0 :     double fValue=0.0;
     362           0 :     if( (rDoubleAny>>=fValue) && (fValue!=0.0) )
     363             :     {
     364           0 :         fValue/=100.0;
     365           0 :         rDoubleAny = uno::makeAny(fValue);
     366           0 :         bChanged = true;
     367             :     }
     368           0 :     return bChanged;
     369             : }
     370             : 
     371           0 : bool lcl_AdaptWrongPercentScaleValues(chart2::ScaleData& rScaleData)
     372             : {
     373           0 :     bool bChanged = lcl_divideBy100( rScaleData.Minimum );
     374           0 :     bChanged = lcl_divideBy100( rScaleData.Maximum ) || bChanged;
     375           0 :     bChanged = lcl_divideBy100( rScaleData.Origin ) || bChanged;
     376           0 :     bChanged = lcl_divideBy100( rScaleData.IncrementData.Distance ) || bChanged;
     377           0 :     return bChanged;
     378             : }
     379             : 
     380             : }//end anonymous namespace
     381             : 
     382         201 : void SchXMLAxisContext::CreateAxis()
     383             : {
     384         201 :     m_rAxes.push_back( m_aCurrentAxis );
     385             : 
     386         201 :     Reference< beans::XPropertySet > xDiaProp( m_rImportHelper.GetChartDocument()->getDiagram(), uno::UNO_QUERY );
     387         201 :     if( !xDiaProp.is() )
     388           0 :         return;
     389         402 :     OUString aPropName;
     390         201 :     switch( m_aCurrentAxis.eDimension )
     391             :     {
     392             :         case SCH_XML_AXIS_X:
     393          87 :             if( m_aCurrentAxis.nAxisIndex == 0 )
     394          83 :                 aPropName = "HasXAxis";
     395             :             else
     396           4 :                 aPropName = "HasSecondaryXAxis";
     397          87 :             break;
     398             :         case SCH_XML_AXIS_Y:
     399          87 :             if( m_aCurrentAxis.nAxisIndex == 0 )
     400          83 :                 aPropName = "HasYAxis";
     401             :             else
     402           4 :                 aPropName = "HasSecondaryYAxis";
     403          87 :             break;
     404             :         case SCH_XML_AXIS_Z:
     405          27 :             if( m_aCurrentAxis.nAxisIndex == 0 )
     406          27 :                 aPropName = "HasXAxis";
     407             :             else
     408           0 :                 aPropName = "HasSecondaryXAxis";
     409          27 :             break;
     410             :         case SCH_XML_AXIS_UNDEF:
     411             :             SAL_INFO("xmloff.chart", "Invalid axis" );
     412           0 :             break;
     413             :     }
     414             :     try
     415             :     {
     416         201 :         xDiaProp->setPropertyValue( aPropName, uno::makeAny(sal_True) );
     417             :     }
     418           0 :     catch( beans::UnknownPropertyException & )
     419             :     {
     420             :         SAL_INFO("xmloff.chart", "Couldn't turn on axis" );
     421             :     }
     422         201 :     if( m_aCurrentAxis.eDimension==SCH_XML_AXIS_Z )
     423             :     {
     424          27 :         bool bSettingZAxisSuccedded = false;
     425             :         try
     426             :         {
     427          27 :             xDiaProp->getPropertyValue( aPropName ) >>= bSettingZAxisSuccedded;
     428             :         }
     429           0 :         catch( beans::UnknownPropertyException & )
     430             :         {
     431             :             SAL_INFO("xmloff.chart", "Couldn't turn on z axis" );
     432             :         }
     433          27 :         if( !bSettingZAxisSuccedded )
     434           0 :             return;
     435             :     }
     436             : 
     437         201 :     m_xAxisProps = Reference<beans::XPropertySet>( lcl_getChartAxis( m_aCurrentAxis, m_xDiagram ), uno::UNO_QUERY );
     438             : 
     439         201 :     if( m_bAddMissingXAxisForNetCharts && m_aCurrentAxis.eDimension==SCH_XML_AXIS_Y && m_aCurrentAxis.nAxisIndex==0 )
     440             :     {
     441             :         try
     442             :         {
     443           0 :             xDiaProp->setPropertyValue("HasXAxis", uno::makeAny(sal_True) );
     444             :         }
     445           0 :         catch( beans::UnknownPropertyException & )
     446             :         {
     447             :             SAL_INFO("xmloff.chart", "Couldn't turn on x axis" );
     448             :         }
     449             :     }
     450             : 
     451             :     // set properties
     452         201 :     if( m_xAxisProps.is())
     453             :     {
     454         201 :         uno::Any aTrueBool( uno::makeAny( sal_True ));
     455         402 :         uno::Any aFalseBool( uno::makeAny( sal_False ));
     456             : 
     457             :         // #i109879# the line color is black as default, in the model it is a light gray
     458         201 :         m_xAxisProps->setPropertyValue("LineColor",
     459         201 :                                      uno::makeAny( COL_BLACK ));
     460             : 
     461         201 :         m_xAxisProps->setPropertyValue("DisplayLabels", aFalseBool );
     462             : 
     463             :         // #88077# AutoOrigin 'on' is default
     464         201 :         m_xAxisProps->setPropertyValue("AutoOrigin", aTrueBool );
     465             : 
     466         201 :         if( m_bAxisTypeImported )
     467          51 :             m_xAxisProps->setPropertyValue("AxisType", uno::makeAny(m_nAxisType) );
     468             : 
     469         201 :         if( !m_aAutoStyleName.isEmpty())
     470             :         {
     471         201 :             const SvXMLStylesContext* pStylesCtxt = m_rImportHelper.GetAutoStylesContext();
     472         201 :             if( pStylesCtxt )
     473             :             {
     474             :                 const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
     475         201 :                     m_rImportHelper.GetChartFamilyID(), m_aAutoStyleName );
     476             : 
     477         201 :                 if( pStyle && pStyle->ISA( XMLPropStyleContext ))
     478             :                 {
     479             :                     // note: SvXMLStyleContext::FillPropertySet is not const
     480         201 :                     XMLPropStyleContext * pPropStyleContext = const_cast< XMLPropStyleContext * >( dynamic_cast< const XMLPropStyleContext * >( pStyle ));
     481         201 :                     if( pPropStyleContext )
     482         201 :                         pPropStyleContext->FillPropertySet( m_xAxisProps );
     483             : 
     484         201 :                     if( m_bAdaptWrongPercentScaleValues && m_aCurrentAxis.eDimension==SCH_XML_AXIS_Y )
     485             :                     {
     486             :                         //set scale data of added x axis back to default
     487           0 :                         Reference< chart2::XAxis > xAxis( lcl_getAxis( GetImport().GetModel(),
     488           0 :                                             m_aCurrentAxis.eDimension, m_aCurrentAxis.nAxisIndex ) );
     489           0 :                         if( xAxis.is() )
     490             :                         {
     491           0 :                             chart2::ScaleData aScaleData( xAxis->getScaleData());
     492           0 :                             if( lcl_AdaptWrongPercentScaleValues(aScaleData) )
     493           0 :                                 xAxis->setScaleData( aScaleData );
     494           0 :                         }
     495             :                     }
     496             : 
     497         201 :                     if( m_bAddMissingXAxisForNetCharts )
     498             :                     {
     499             :                         //copy style from y axis to added x axis:
     500             : 
     501           0 :                         Reference< chart::XAxisSupplier > xAxisSuppl( xDiaProp, uno::UNO_QUERY );
     502           0 :                         if( xAxisSuppl.is() )
     503             :                         {
     504           0 :                             Reference< beans::XPropertySet > xXAxisProp( xAxisSuppl->getAxis(0), uno::UNO_QUERY );
     505           0 :                             (( XMLPropStyleContext* )pStyle )->FillPropertySet( xXAxisProp );
     506             :                         }
     507             : 
     508             :                         //set scale data of added x axis back to default
     509           0 :                         Reference< chart2::XAxis > xAxis( lcl_getAxis( GetImport().GetModel(),
     510           0 :                                             0 /*nDimensionIndex*/, 0 /*nAxisIndex*/ ) );
     511           0 :                         if( xAxis.is() )
     512             :                         {
     513           0 :                             chart2::ScaleData aScaleData;
     514           0 :                             aScaleData.AxisType = chart2::AxisType::CATEGORY;
     515           0 :                             aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
     516           0 :                             xAxis->setScaleData( aScaleData );
     517             :                         }
     518             : 
     519             :                         //set line style of added x axis to invisible
     520           0 :                         Reference< beans::XPropertySet > xNewAxisProp( xAxis, uno::UNO_QUERY );
     521           0 :                         if( xNewAxisProp.is() )
     522             :                         {
     523           0 :                             xNewAxisProp->setPropertyValue("LineStyle"
     524           0 :                                 , uno::makeAny(drawing::LineStyle_NONE));
     525           0 :                         }
     526             :                     }
     527             : 
     528         201 :                     if( m_bAdaptXAxisOrientationForOld2DBarCharts && m_aCurrentAxis.eDimension == SCH_XML_AXIS_X )
     529             :                     {
     530           0 :                         bool bIs3DChart = false;
     531           0 :                         if( xDiaProp.is() && ( xDiaProp->getPropertyValue("Dim3D") >>= bIs3DChart )
     532           0 :                             && !bIs3DChart )
     533             :                         {
     534           0 :                             Reference< chart2::XChartDocument > xChart2Document( GetImport().GetModel(), uno::UNO_QUERY );
     535           0 :                             if( xChart2Document.is() )
     536             :                             {
     537           0 :                                 Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xChart2Document->getFirstDiagram(), uno::UNO_QUERY );
     538           0 :                                 if( xCooSysCnt.is() )
     539             :                                 {
     540           0 :                                     uno::Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems() );
     541           0 :                                     if( aCooSysSeq.getLength() )
     542             :                                     {
     543           0 :                                         bool bSwapXandYAxis = false;
     544           0 :                                         Reference< chart2::XCoordinateSystem > xCooSys( aCooSysSeq[0] );
     545           0 :                                         Reference< beans::XPropertySet > xCooSysProp( xCooSys, uno::UNO_QUERY );
     546           0 :                                         if( xCooSysProp.is() && ( xCooSysProp->getPropertyValue("SwapXAndYAxis") >>= bSwapXandYAxis )
     547           0 :                                             && bSwapXandYAxis )
     548             :                                         {
     549           0 :                                             Reference< chart2::XAxis > xAxis = xCooSys->getAxisByDimension( 0, m_aCurrentAxis.nAxisIndex );
     550           0 :                                             if( xAxis.is() )
     551             :                                             {
     552           0 :                                                 chart2::ScaleData aScaleData = xAxis->getScaleData();
     553           0 :                                                 aScaleData.Orientation = chart2::AxisOrientation_REVERSE;
     554           0 :                                                 xAxis->setScaleData( aScaleData );
     555           0 :                                             }
     556           0 :                                         }
     557           0 :                                     }
     558           0 :                                 }
     559           0 :                             }
     560             :                         }
     561             :                     }
     562             : 
     563         373 :                     m_rbAxisPositionAttributeImported = m_rbAxisPositionAttributeImported || SchXMLTools::getPropertyFromContext(
     564         574 :                         OUString("CrossoverPosition"), pPropStyleContext, pStylesCtxt ).hasValue();
     565             :                 }
     566             :             }
     567         201 :         }
     568         201 :     }
     569             : }
     570             : 
     571         201 : void SchXMLAxisContext::SetAxisTitle()
     572             : {
     573         201 :     if( m_aCurrentAxis.aTitle.isEmpty() )
     574         358 :         return;
     575             : 
     576          22 :     Reference< chart::XAxis > xAxis( lcl_getChartAxis( m_aCurrentAxis, m_xDiagram ) );
     577          22 :     if( !xAxis.is() )
     578           0 :         return;
     579             : 
     580          44 :     Reference< beans::XPropertySet > xTitleProp( xAxis->getAxisTitle() );
     581          22 :     if( xTitleProp.is() )
     582             :     {
     583             :         try
     584             :         {
     585          22 :             xTitleProp->setPropertyValue("String", uno::makeAny(m_aCurrentAxis.aTitle) );
     586             :         }
     587           0 :         catch( beans::UnknownPropertyException & )
     588             :         {
     589             :             SAL_INFO("xmloff.chart", "Property String for Title not available" );
     590             :         }
     591          22 :     }
     592             : }
     593             : 
     594             : namespace
     595             : {
     596             : enum AxisChildTokens
     597             : {
     598             :     XML_TOK_AXIS_TITLE,
     599             :     XML_TOK_AXIS_CATEGORIES,
     600             :     XML_TOK_AXIS_GRID,
     601             :     XML_TOK_AXIS_DATE_SCALE,
     602             :     XML_TOK_AXIS_DATE_SCALE_EXT
     603             : };
     604             : 
     605             : const SvXMLTokenMapEntry aAxisChildTokenMap[] =
     606             : {
     607             :     { XML_NAMESPACE_CHART,      XML_TITLE,              XML_TOK_AXIS_TITLE          },
     608             :     { XML_NAMESPACE_CHART,      XML_CATEGORIES,         XML_TOK_AXIS_CATEGORIES     },
     609             :     { XML_NAMESPACE_CHART,      XML_GRID,               XML_TOK_AXIS_GRID           },
     610             :     { XML_NAMESPACE_CHART,      XML_DATE_SCALE,         XML_TOK_AXIS_DATE_SCALE     },
     611             :     { XML_NAMESPACE_CHART_EXT,  XML_DATE_SCALE,         XML_TOK_AXIS_DATE_SCALE_EXT },
     612             :     XML_TOKEN_MAP_END
     613             : };
     614             : 
     615             : class AxisChildTokenMap : public SvXMLTokenMap
     616             : {
     617             : public:
     618           7 :     AxisChildTokenMap(): SvXMLTokenMap( aAxisChildTokenMap ) {}
     619           7 :     virtual ~AxisChildTokenMap() {}
     620             : };
     621             : 
     622             : //a AxisChildTokenMap Singleton
     623             : struct theAxisChildTokenMap : public rtl::Static< AxisChildTokenMap, theAxisChildTokenMap > {};
     624             : }
     625             : 
     626         213 : SvXMLImportContext* SchXMLAxisContext::CreateChildContext(
     627             :     sal_uInt16 p_nPrefix,
     628             :     const OUString& rLocalName,
     629             :     const Reference< xml::sax::XAttributeList >& xAttrList )
     630             : {
     631         213 :     SvXMLImportContext* pContext = 0;
     632         213 :     const SvXMLTokenMap& rTokenMap = theAxisChildTokenMap::get();
     633             : 
     634         213 :     switch( rTokenMap.Get( p_nPrefix, rLocalName ))
     635             :     {
     636             :         case XML_TOK_AXIS_TITLE:
     637             :         {
     638          22 :             Reference< drawing::XShape > xTitleShape = getTitleShape();
     639          22 :             pContext = new SchXMLTitleContext( m_rImportHelper, GetImport(), rLocalName,
     640             :                                                m_aCurrentAxis.aTitle,
     641          22 :                                                xTitleShape );
     642             :         }
     643          22 :         break;
     644             : 
     645             :         case XML_TOK_AXIS_CATEGORIES:
     646          55 :             pContext = new SchXMLCategoriesContext( GetImport(),
     647             :                                                           p_nPrefix, rLocalName,
     648          55 :                                                           m_rCategoriesAddress );
     649          55 :             m_aCurrentAxis.bHasCategories = true;
     650          55 :             break;
     651             : 
     652             :         case XML_TOK_AXIS_DATE_SCALE:
     653             :         case XML_TOK_AXIS_DATE_SCALE_EXT:
     654          42 :             pContext = new DateScaleContext( GetImport(),
     655          42 :                             p_nPrefix, rLocalName, m_xAxisProps );
     656          42 :             m_bDateScaleImported = true;
     657          42 :             break;
     658             : 
     659             :         case XML_TOK_AXIS_GRID:
     660             :         {
     661          94 :             sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
     662          94 :             bool bIsMajor = true;       // default value for class is "major"
     663          94 :             OUString sAutoStyleName;
     664             : 
     665         282 :             for( sal_Int16 i = 0; i < nAttrCount; i++ )
     666             :             {
     667         188 :                 OUString sAttrName = xAttrList->getNameByIndex( i );
     668         376 :                 OUString aLocalName;
     669         188 :                 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
     670             : 
     671         188 :                 if( nPrefix == XML_NAMESPACE_CHART )
     672             :                 {
     673         188 :                     if( IsXMLToken( aLocalName, XML_CLASS ) )
     674             :                     {
     675          94 :                         if( IsXMLToken( xAttrList->getValueByIndex( i ), XML_MINOR ) )
     676          12 :                             bIsMajor = false;
     677             :                     }
     678          94 :                     else if( IsXMLToken( aLocalName, XML_STYLE_NAME ) )
     679          94 :                         sAutoStyleName = xAttrList->getValueByIndex( i );
     680             :                 }
     681         188 :             }
     682             : 
     683          94 :             CreateGrid( sAutoStyleName, bIsMajor );
     684             : 
     685             :             // don't create a context => use default context. grid elements are empty
     686          94 :             pContext = new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
     687             :         }
     688          94 :         break;
     689             : 
     690             :         default:
     691           0 :             pContext = new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
     692           0 :             break;
     693             :     }
     694             : 
     695         213 :     return pContext;
     696             : }
     697             : 
     698         201 : void SchXMLAxisContext::EndElement()
     699             : {
     700         201 :     if( !m_bDateScaleImported && m_nAxisType==chart::ChartAxisType::AUTOMATIC )
     701             :     {
     702         150 :         Reference< chart2::XAxis > xAxis( lcl_getAxis( GetImport().GetModel(), m_aCurrentAxis.eDimension, m_aCurrentAxis.nAxisIndex ) );
     703         150 :         if( xAxis.is() )
     704             :         {
     705         150 :             chart2::ScaleData aScaleData( xAxis->getScaleData());
     706         150 :             aScaleData.AutoDateAxis = false;//different default for older documents
     707         150 :             xAxis->setScaleData( aScaleData );
     708         150 :         }
     709             :     }
     710             : 
     711         201 :     SetAxisTitle();
     712         201 : }
     713             : 
     714             : namespace
     715             : {
     716             : 
     717          12 : Reference< chart2::XAxis > lcl_getAxis( const Reference< chart2::XCoordinateSystem > xCooSys, sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
     718             : {
     719          12 :     Reference< chart2::XAxis > xAxis;
     720             :     try
     721             :     {
     722          12 :         xAxis = xCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex );
     723             :     }
     724           6 :     catch( uno::Exception & )
     725             :     {
     726             :     }
     727          12 :     return xAxis;
     728             : }
     729             : 
     730             : } // anonymous namespace
     731             : 
     732          83 : void SchXMLAxisContext::CorrectAxisPositions( const Reference< chart2::XChartDocument >& xNewDoc,
     733             :                           const OUString& rChartTypeServiceName,
     734             :                           const OUString& rODFVersionOfFile,
     735             :                           bool bAxisPositionAttributeImported )
     736             : {
     737         249 :     if( ( rODFVersionOfFile.isEmpty() || rODFVersionOfFile == "1.0" || rODFVersionOfFile == "1.1"
     738         163 :         || ( rODFVersionOfFile == "1.2" && !bAxisPositionAttributeImported ) ) )
     739             :     {
     740             :         try
     741             :         {
     742           3 :             Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xNewDoc->getFirstDiagram(), uno::UNO_QUERY_THROW );
     743           6 :             uno::Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems());
     744           3 :             if( aCooSysSeq.getLength() )
     745             :             {
     746           3 :                 Reference< chart2::XCoordinateSystem > xCooSys( aCooSysSeq[0] );
     747           3 :                 if( xCooSys.is() )
     748             :                 {
     749           3 :                     Reference< chart2::XAxis > xMainXAxis = lcl_getAxis( xCooSys, 0, 0 );
     750           6 :                     Reference< chart2::XAxis > xMainYAxis = lcl_getAxis( xCooSys, 1, 0 );
     751             :                     //Reference< chart2::XAxis > xMajorZAxis = lcl_getAxis( xCooSys, 2, 0 );
     752           6 :                     Reference< chart2::XAxis > xSecondaryXAxis = lcl_getAxis( xCooSys, 0, 1 );
     753           6 :                     Reference< chart2::XAxis > xSecondaryYAxis = lcl_getAxis( xCooSys, 1, 1 );
     754             : 
     755           6 :                     Reference< beans::XPropertySet > xMainXAxisProp( xMainXAxis, uno::UNO_QUERY );
     756           6 :                     Reference< beans::XPropertySet > xMainYAxisProp( xMainYAxis, uno::UNO_QUERY );
     757           6 :                     Reference< beans::XPropertySet > xSecondaryXAxisProp( xSecondaryXAxis, uno::UNO_QUERY );
     758           6 :                     Reference< beans::XPropertySet > xSecondaryYAxisProp( xSecondaryYAxis, uno::UNO_QUERY );
     759             : 
     760           3 :                     if( xMainXAxisProp.is() && xMainYAxisProp.is() )
     761             :                     {
     762           3 :                         chart2::ScaleData aMainXScale = xMainXAxis->getScaleData();
     763           3 :                         if( rChartTypeServiceName == "com.sun.star.chart2.ScatterChartType" )
     764             :                         {
     765           0 :                             xMainYAxisProp->setPropertyValue("CrossoverPosition"
     766           0 :                                     , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_VALUE) );
     767           0 :                             double fCrossoverValue = 0.0;
     768           0 :                             aMainXScale.Origin >>= fCrossoverValue;
     769           0 :                             xMainYAxisProp->setPropertyValue("CrossoverValue"
     770           0 :                                     , uno::makeAny( fCrossoverValue ) );
     771             : 
     772           0 :                             if( aMainXScale.Orientation == chart2::AxisOrientation_REVERSE )
     773             :                             {
     774           0 :                                 xMainYAxisProp->setPropertyValue("LabelPosition"
     775           0 :                                     , uno::makeAny( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_END) );
     776           0 :                                 xMainYAxisProp->setPropertyValue("MarkPosition"
     777           0 :                                     , uno::makeAny( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS) );
     778           0 :                                 if( xSecondaryYAxisProp.is() )
     779           0 :                                     xSecondaryYAxisProp->setPropertyValue("CrossoverPosition"
     780           0 :                                     , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START) );
     781             :                             }
     782             :                             else
     783             :                             {
     784           0 :                                 xMainYAxisProp->setPropertyValue("LabelPosition"
     785           0 :                                     , uno::makeAny( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START) );
     786           0 :                                 xMainYAxisProp->setPropertyValue("MarkPosition"
     787           0 :                                     , uno::makeAny( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS) );
     788           0 :                                 if( xSecondaryYAxisProp.is() )
     789           0 :                                     xSecondaryYAxisProp->setPropertyValue("CrossoverPosition"
     790           0 :                                     , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_END) );
     791             :                             }
     792             :                         }
     793             :                         else
     794             :                         {
     795           3 :                             if( aMainXScale.Orientation == chart2::AxisOrientation_REVERSE )
     796             :                             {
     797           0 :                                 xMainYAxisProp->setPropertyValue("CrossoverPosition"
     798           0 :                                     , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_END) );
     799           0 :                                 if( xSecondaryYAxisProp.is() )
     800           0 :                                     xSecondaryYAxisProp->setPropertyValue("CrossoverPosition"
     801           0 :                                         , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START) );
     802             :                             }
     803             :                             else
     804             :                             {
     805           3 :                                 xMainYAxisProp->setPropertyValue("CrossoverPosition"
     806           3 :                                     , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START) );
     807           3 :                                 if( xSecondaryYAxisProp.is() )
     808           0 :                                     xSecondaryYAxisProp->setPropertyValue("CrossoverPosition"
     809           0 :                                         , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_END) );
     810             :                             }
     811             :                         }
     812             : 
     813           6 :                         chart2::ScaleData aMainYScale = xMainYAxis->getScaleData();
     814           3 :                         xMainXAxisProp->setPropertyValue("CrossoverPosition"
     815           3 :                                 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_VALUE) );
     816           3 :                         double fCrossoverValue = 0.0;
     817           3 :                         aMainYScale.Origin >>= fCrossoverValue;
     818           3 :                         xMainXAxisProp->setPropertyValue("CrossoverValue"
     819           3 :                                 , uno::makeAny( fCrossoverValue ) );
     820             : 
     821           3 :                         if( aMainYScale.Orientation == chart2::AxisOrientation_REVERSE )
     822             :                         {
     823           0 :                             xMainXAxisProp->setPropertyValue("LabelPosition"
     824           0 :                                 , uno::makeAny( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_END) );
     825           0 :                             xMainXAxisProp->setPropertyValue("MarkPosition"
     826           0 :                                 , uno::makeAny( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS) );
     827           0 :                             if( xSecondaryXAxisProp.is() )
     828           0 :                                 xSecondaryXAxisProp->setPropertyValue("CrossoverPosition"
     829           0 :                                 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START) );
     830             :                         }
     831             :                         else
     832             :                         {
     833           3 :                             xMainXAxisProp->setPropertyValue("LabelPosition"
     834           3 :                                 , uno::makeAny( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START) );
     835           3 :                             xMainXAxisProp->setPropertyValue("MarkPosition"
     836           3 :                                 , uno::makeAny( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS) );
     837           3 :                             if( xSecondaryXAxisProp.is() )
     838           0 :                                 xSecondaryXAxisProp->setPropertyValue("CrossoverPosition"
     839           0 :                                 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_END) );
     840           3 :                         }
     841           3 :                     }
     842           3 :                 }
     843           3 :             }
     844             :         }
     845           0 :         catch( uno::Exception & )
     846             :         {
     847             :         }
     848             :     }
     849          83 : }
     850             : 
     851          55 : SchXMLCategoriesContext::SchXMLCategoriesContext(
     852             :     SvXMLImport& rImport,
     853             :     sal_uInt16 nPrefix,
     854             :     const OUString& rLocalName,
     855             :     OUString& rAddress ) :
     856             :         SvXMLImportContext( rImport, nPrefix, rLocalName ),
     857          55 :         mrAddress( rAddress )
     858             : {
     859          55 : }
     860             : 
     861         110 : SchXMLCategoriesContext::~SchXMLCategoriesContext()
     862             : {
     863         110 : }
     864             : 
     865          55 : void SchXMLCategoriesContext::StartElement( const Reference< xml::sax::XAttributeList >& xAttrList )
     866             : {
     867          55 :     sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
     868             : 
     869         110 :     for( sal_Int16 i = 0; i < nAttrCount; i++ )
     870             :     {
     871          55 :         OUString sAttrName = xAttrList->getNameByIndex( i );
     872         110 :         OUString aLocalName;
     873          55 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
     874             : 
     875         110 :         if( nPrefix == XML_NAMESPACE_TABLE &&
     876          55 :             IsXMLToken( aLocalName, XML_CELL_RANGE_ADDRESS ) )
     877             :         {
     878          55 :             Reference< chart2::XChartDocument > xNewDoc( GetImport().GetModel(), uno::UNO_QUERY );
     879          55 :             mrAddress = xAttrList->getValueByIndex( i );
     880             :         }
     881          55 :     }
     882          55 : }
     883             : 
     884          42 : DateScaleContext::DateScaleContext(
     885             :     SvXMLImport& rImport,
     886             :     sal_uInt16 nPrefix,
     887             :     const OUString& rLocalName,
     888             :     const Reference< beans::XPropertySet > xAxisProps ) :
     889             :         SvXMLImportContext( rImport, nPrefix, rLocalName ),
     890          42 :         m_xAxisProps( xAxisProps )
     891             : {
     892          42 : }
     893             : 
     894          84 : DateScaleContext::~DateScaleContext()
     895             : {
     896          84 : }
     897             : 
     898             : namespace
     899             : {
     900             : enum DateScaleAttributeTokens
     901             : {
     902             :     XML_TOK_DATESCALE_BASE_TIME_UNIT,
     903             :     XML_TOK_DATESCALE_MAJOR_INTERVAL_VALUE,
     904             :     XML_TOK_DATESCALE_MAJOR_INTERVAL_UNIT,
     905             :     XML_TOK_DATESCALE_MINOR_INTERVAL_VALUE,
     906             :     XML_TOK_DATESCALE_MINOR_INTERVAL_UNIT
     907             : };
     908             : 
     909             : const SvXMLTokenMapEntry aDateScaleAttributeTokenMap[] =
     910             : {
     911             :     { XML_NAMESPACE_CHART,  XML_BASE_TIME_UNIT,         XML_TOK_DATESCALE_BASE_TIME_UNIT  },
     912             :     { XML_NAMESPACE_CHART,  XML_MAJOR_INTERVAL_VALUE,   XML_TOK_DATESCALE_MAJOR_INTERVAL_VALUE  },
     913             :     { XML_NAMESPACE_CHART,  XML_MAJOR_INTERVAL_UNIT,    XML_TOK_DATESCALE_MAJOR_INTERVAL_UNIT  },
     914             :     { XML_NAMESPACE_CHART,  XML_MINOR_INTERVAL_VALUE,   XML_TOK_DATESCALE_MINOR_INTERVAL_VALUE  },
     915             :     { XML_NAMESPACE_CHART,  XML_MINOR_INTERVAL_UNIT,    XML_TOK_DATESCALE_MINOR_INTERVAL_UNIT  },
     916             :     XML_TOKEN_MAP_END
     917             : };
     918             : 
     919             : class DateScaleAttributeTokenMap : public SvXMLTokenMap
     920             : {
     921             : public:
     922           5 :     DateScaleAttributeTokenMap(): SvXMLTokenMap( aDateScaleAttributeTokenMap ) {}
     923           5 :     virtual ~DateScaleAttributeTokenMap() {}
     924             : };
     925             : 
     926             : struct theDateScaleAttributeTokenMap : public rtl::Static< DateScaleAttributeTokenMap, theDateScaleAttributeTokenMap > {};
     927             : 
     928           1 : sal_Int32 lcl_getTimeUnit( const OUString& rValue )
     929             : {
     930           1 :     sal_Int32 nTimeUnit = ::com::sun::star::chart::TimeUnit::DAY;
     931           1 :     if( IsXMLToken( rValue, XML_DAYS ) )
     932           0 :         nTimeUnit = ::com::sun::star::chart::TimeUnit::DAY;
     933           1 :     else if( IsXMLToken( rValue, XML_MONTHS ) )
     934           1 :         nTimeUnit = ::com::sun::star::chart::TimeUnit::MONTH;
     935           0 :     else if( IsXMLToken( rValue, XML_YEARS ) )
     936           0 :         nTimeUnit = ::com::sun::star::chart::TimeUnit::YEAR;
     937           1 :     return nTimeUnit;
     938             : }
     939             : 
     940             : }
     941             : 
     942          42 : void DateScaleContext::StartElement( const Reference< xml::sax::XAttributeList >& xAttrList )
     943             : {
     944          42 :     if( !m_xAxisProps.is() )
     945          42 :         return;
     946             : 
     947             :     // parse attributes
     948          42 :     sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
     949          42 :     const SvXMLTokenMap& rAttrTokenMap = theDateScaleAttributeTokenMap::get();
     950             : 
     951          42 :     bool bSetNewIncrement=false;
     952          42 :     chart::TimeIncrement aIncrement;
     953          42 :     m_xAxisProps->getPropertyValue("TimeIncrement") >>= aIncrement;
     954             : 
     955          43 :     for( sal_Int16 i = 0; i < nAttrCount; i++ )
     956             :     {
     957           1 :         OUString sAttrName = xAttrList->getNameByIndex( i );
     958           2 :         OUString aLocalName;
     959           2 :         OUString aValue = xAttrList->getValueByIndex( i );
     960           1 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
     961             : 
     962           1 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
     963             :         {
     964             :             case XML_TOK_DATESCALE_BASE_TIME_UNIT:
     965             :                 {
     966           1 :                     aIncrement.TimeResolution = uno::makeAny( lcl_getTimeUnit(aValue) );
     967           1 :                     bSetNewIncrement = true;
     968             :                 }
     969           1 :                 break;
     970             :             case XML_TOK_DATESCALE_MAJOR_INTERVAL_VALUE:
     971             :                 {
     972           0 :                     chart::TimeInterval aInterval(1,0);
     973           0 :                     aIncrement.MajorTimeInterval >>= aInterval;
     974           0 :                     ::sax::Converter::convertNumber( aInterval.Number, aValue );
     975           0 :                     aIncrement.MajorTimeInterval = uno::makeAny(aInterval);
     976           0 :                     bSetNewIncrement = true;
     977             :                 }
     978           0 :                 break;
     979             :             case XML_TOK_DATESCALE_MAJOR_INTERVAL_UNIT:
     980             :                 {
     981           0 :                     chart::TimeInterval aInterval(1,0);
     982           0 :                     aIncrement.MajorTimeInterval >>= aInterval;
     983           0 :                     aInterval.TimeUnit = lcl_getTimeUnit(aValue);
     984           0 :                     aIncrement.MajorTimeInterval = uno::makeAny(aInterval);
     985           0 :                     bSetNewIncrement = true;
     986             :                 }
     987           0 :                 break;
     988             :             case XML_TOK_DATESCALE_MINOR_INTERVAL_VALUE:
     989             :                 {
     990           0 :                     chart::TimeInterval aInterval(1,0);
     991           0 :                     aIncrement.MinorTimeInterval >>= aInterval;
     992           0 :                     ::sax::Converter::convertNumber( aInterval.Number, aValue );
     993           0 :                     aIncrement.MinorTimeInterval = uno::makeAny(aInterval);
     994           0 :                     bSetNewIncrement = true;
     995             :                 }
     996           0 :                 break;
     997             :             case XML_TOK_DATESCALE_MINOR_INTERVAL_UNIT:
     998             :                 {
     999           0 :                     chart::TimeInterval aInterval(1,0);
    1000           0 :                     aIncrement.MinorTimeInterval >>= aInterval;
    1001           0 :                     aInterval.TimeUnit = lcl_getTimeUnit(aValue);
    1002           0 :                     aIncrement.MinorTimeInterval = uno::makeAny(aInterval);
    1003           0 :                     bSetNewIncrement = true;
    1004             :                 }
    1005           0 :                 break;
    1006             :         }
    1007           1 :     }
    1008             : 
    1009          42 :     if( bSetNewIncrement )
    1010           1 :         m_xAxisProps->setPropertyValue("TimeIncrement", uno::makeAny( aIncrement ) );
    1011             : }
    1012             : 
    1013             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10