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