Update ooo320-m1
[ooovba.git] / xmloff / source / chart / SchXMLPlotAreaContext.cxx
blob3d8a8495f494e654841eff070611710eb1e00db7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SchXMLPlotAreaContext.cxx,v $
10 * $Revision: 1.47.38.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
34 #include "SchXMLPlotAreaContext.hxx"
35 #include "SchXMLImport.hxx"
36 #include "SchXMLSeries2Context.hxx"
37 #include "SchXMLTools.hxx"
38 #include <tools/debug.hxx>
39 #ifdef DBG_UTIL
40 #include <tools/string.hxx>
41 #endif
43 #include <comphelper/processfactory.hxx>
44 #include "xmlnmspe.hxx"
45 #include <xmloff/xmltoken.hxx>
46 #include <xmloff/xmlement.hxx>
47 #include <xmloff/nmspmap.hxx>
48 #include <xmloff/xmluconv.hxx>
49 #include <xmloff/prstylei.hxx>
50 #include <xmloff/xmlstyle.hxx>
51 #include "xexptran.hxx"
52 #include <cppuhelper/implbase1.hxx>
54 #include <com/sun/star/awt/Point.hpp>
55 #include <com/sun/star/awt/Size.hpp>
57 #include <com/sun/star/chart/ChartAxisLabelPosition.hpp>
58 #include <com/sun/star/chart/ChartAxisMarkPosition.hpp>
59 #include <com/sun/star/chart/ChartAxisPosition.hpp>
60 #include <com/sun/star/chart/XTwoAxisXSupplier.hpp>
61 #include <com/sun/star/chart/XTwoAxisYSupplier.hpp>
62 #include <com/sun/star/chart/XAxisZSupplier.hpp>
63 #include <com/sun/star/chart/XSecondAxisTitleSupplier.hpp>
64 #include <com/sun/star/chart/ChartDataRowSource.hpp>
65 #include <com/sun/star/chart/X3DDisplay.hpp>
66 #include <com/sun/star/chart/XStatisticDisplay.hpp>
68 #include <com/sun/star/chart2/XChartDocument.hpp>
69 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
70 #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
71 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
72 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
73 #include <com/sun/star/chart2/AxisType.hpp>
74 #include <com/sun/star/chart2/RelativePosition.hpp>
76 #include <com/sun/star/drawing/CameraGeometry.hpp>
77 #include <com/sun/star/drawing/FillStyle.hpp>
78 #include <com/sun/star/drawing/LineStyle.hpp>
79 #include <com/sun/star/lang/XServiceInfo.hpp>
80 #include <com/sun/star/util/XStringMapping.hpp>
81 #include <com/sun/star/xml/sax/XAttributeList.hpp>
83 using namespace com::sun::star;
84 using namespace ::xmloff::token;
86 using ::rtl::OUString;
87 using com::sun::star::uno::Reference;
89 static __FAR_DATA SvXMLEnumMapEntry aXMLAxisClassMap[] =
91 { XML_X, SCH_XML_AXIS_X },
92 { XML_Y, SCH_XML_AXIS_Y },
93 { XML_Z, SCH_XML_AXIS_Z },
94 { XML_TOKEN_INVALID, 0 }
97 namespace
100 struct lcl_AxisHasCategories : public ::std::unary_function< SchXMLAxis, bool >
102 bool operator() ( const SchXMLAxis & rAxis )
104 return rAxis.bHasCategories;
108 OUString lcl_ConvertRange( const ::rtl::OUString & rRange, const uno::Reference< chart2::XChartDocument > & xDoc )
110 OUString aResult = rRange;
111 if(!xDoc.is())
112 return aResult;
113 uno::Reference< chart2::data::XRangeXMLConversion > xConversion(
114 xDoc->getDataProvider(), uno::UNO_QUERY );
115 if( xConversion.is())
116 aResult = xConversion->convertRangeFromXML( rRange );
117 return aResult;
120 Reference< chart2::XAxis > lcl_getAxis( const Reference< chart2::XCoordinateSystem > xCooSys, sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
122 Reference< chart2::XAxis > xAxis;
125 xAxis = xCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex );
127 catch( uno::Exception & )
130 return xAxis;
133 } // anonymous namespace
135 SchXML3DSceneAttributesHelper::SchXML3DSceneAttributesHelper( SvXMLImport& rImporter )
136 : SdXML3DSceneAttributesHelper( rImporter )
140 void SchXML3DSceneAttributesHelper::getCameraDefaultFromDiagram( const uno::Reference< chart::XDiagram >& xDiagram )
142 //different defaults for camera geometry necessary to workaround wrong behaviour in old chart
143 //in future make this version dependent if we have versioning (metastream) for ole objects
147 uno::Reference< beans::XPropertySet > xProp( xDiagram, uno::UNO_QUERY );
148 if( xProp.is() )
150 drawing::CameraGeometry aCamGeo;
151 xProp->getPropertyValue( ::rtl::OUString::createFromAscii("D3DCameraGeometry")) >>= aCamGeo;
152 maVRP.setX( aCamGeo.vrp.PositionX );
153 maVRP.setY( aCamGeo.vrp.PositionY );
154 maVRP.setZ( aCamGeo.vrp.PositionZ );
155 maVPN.setX( aCamGeo.vpn.DirectionX );
156 maVPN.setY( aCamGeo.vpn.DirectionY );
157 maVPN.setZ( aCamGeo.vpn.DirectionZ );
158 maVUP.setX( aCamGeo.vup.DirectionX );
159 maVUP.setY( aCamGeo.vup.DirectionY );
160 maVUP.setZ( aCamGeo.vup.DirectionZ );
163 catch( uno::Exception & rEx )
165 #ifdef DBG_UTIL
166 String aStr( rEx.Message );
167 ByteString aBStr( aStr, RTL_TEXTENCODING_ASCII_US );
168 DBG_ERROR1( "Exception caught for property NumberOfLines: %s", aBStr.GetBuffer());
169 #else
170 (void)rEx; // avoid warning for pro build
171 #endif
175 SchXML3DSceneAttributesHelper::~SchXML3DSceneAttributesHelper()
179 SchXMLPlotAreaContext::SchXMLPlotAreaContext(
180 SchXMLImportHelper& rImpHelper,
181 SvXMLImport& rImport, const rtl::OUString& rLocalName,
182 const rtl::OUString& rXLinkHRefAttributeToIndicateDataProvider,
183 uno::Sequence< chart::ChartSeriesAddress >& rSeriesAddresses,
184 ::rtl::OUString& rCategoriesAddress,
185 ::rtl::OUString& rChartAddress,
186 bool& rbHasRangeAtPlotArea,
187 sal_Bool & rAllRangeAddressesAvailable,
188 sal_Bool & rColHasLabels,
189 sal_Bool & rRowHasLabels,
190 chart::ChartDataRowSource & rDataRowSource,
191 SeriesDefaultsAndStyles& rSeriesDefaultsAndStyles,
192 const ::rtl::OUString& aChartTypeServiceName,
193 tSchXMLLSequencesPerIndex & rLSequencesPerIndex,
194 const awt::Size & rChartSize ) :
195 SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ),
196 mrImportHelper( rImpHelper ),
197 mrSeriesAddresses( rSeriesAddresses ),
198 mrCategoriesAddress( rCategoriesAddress ),
199 mrSeriesDefaultsAndStyles( rSeriesDefaultsAndStyles ),
200 mnNumOfLinesProp( 0 ),
201 mbStockHasVolume( sal_False ),
202 mnSeries( 0 ),
203 m_aGlobalSeriesImportInfo( rAllRangeAddressesAvailable ),
204 maSceneImportHelper( rImport ),
205 mbHasSize(false),
206 mbHasPosition(false),
207 mbPercentStacked(false),
208 m_bAxisPositionAttributeImported(false),
209 m_rXLinkHRefAttributeToIndicateDataProvider(rXLinkHRefAttributeToIndicateDataProvider),
210 mrChartAddress( rChartAddress ),
211 m_rbHasRangeAtPlotArea( rbHasRangeAtPlotArea ),
212 mrColHasLabels( rColHasLabels ),
213 mrRowHasLabels( rRowHasLabels ),
214 mrDataRowSource( rDataRowSource ),
215 maChartTypeServiceName( aChartTypeServiceName ),
216 mrLSequencesPerIndex( rLSequencesPerIndex ),
217 mbGlobalChartTypeUsedBySeries( false ),
218 maChartSize( rChartSize )
220 m_rbHasRangeAtPlotArea = false;
222 // get Diagram
223 uno::Reference< chart::XChartDocument > xDoc( rImpHelper.GetChartDocument(), uno::UNO_QUERY );
224 if( xDoc.is())
226 mxDiagram = xDoc->getDiagram();
227 mxNewDoc.set( xDoc, uno::UNO_QUERY );
229 maSceneImportHelper.getCameraDefaultFromDiagram( mxDiagram );
231 DBG_ASSERT( mxDiagram.is(), "Couldn't get XDiagram" );
233 // turn off all axes initially
234 uno::Any aFalseBool;
235 aFalseBool <<= (sal_Bool)(sal_False);
237 uno::Reference< lang::XServiceInfo > xInfo( mxDiagram, uno::UNO_QUERY );
238 uno::Reference< beans::XPropertySet > xProp( mxDiagram, uno::UNO_QUERY );
239 if( xInfo.is() &&
240 xProp.is())
244 if( xInfo->supportsService( rtl::OUString::createFromAscii( "com.sun.star.chart.ChartAxisXSupplier" )))
246 xProp->setPropertyValue(
247 rtl::OUString::createFromAscii( "HasXAxis" ), aFalseBool );
248 xProp->setPropertyValue(
249 rtl::OUString::createFromAscii( "HasXAxisGrid" ), aFalseBool );
250 xProp->setPropertyValue(
251 rtl::OUString::createFromAscii( "HasXAxisDescription" ), aFalseBool );
253 if( xInfo->supportsService( rtl::OUString::createFromAscii( "com.sun.star.chart.ChartTwoAxisXSupplier" )))
255 xProp->setPropertyValue(
256 rtl::OUString::createFromAscii( "HasSecondaryXAxis" ), aFalseBool );
257 xProp->setPropertyValue(
258 rtl::OUString::createFromAscii( "HasSecondaryXAxisDescription" ), aFalseBool );
261 if( xInfo->supportsService( rtl::OUString::createFromAscii( "com.sun.star.chart.ChartAxisYSupplier" )))
263 xProp->setPropertyValue(
264 rtl::OUString::createFromAscii( "HasYAxis" ), aFalseBool );
265 xProp->setPropertyValue(
266 rtl::OUString::createFromAscii( "HasYAxisGrid" ), aFalseBool );
267 xProp->setPropertyValue(
268 rtl::OUString::createFromAscii( "HasYAxisDescription" ), aFalseBool );
270 if( xInfo->supportsService( rtl::OUString::createFromAscii( "com.sun.star.chart.ChartTwoAxisYSupplier" )))
272 xProp->setPropertyValue(
273 rtl::OUString::createFromAscii( "HasSecondaryYAxis" ), aFalseBool );
274 xProp->setPropertyValue(
275 rtl::OUString::createFromAscii( "HasSecondaryYAxisDescription" ), aFalseBool );
278 if( xInfo->supportsService( rtl::OUString::createFromAscii( "com.sun.star.chart.ChartAxisZSupplier" )))
280 xProp->setPropertyValue(
281 rtl::OUString::createFromAscii( "HasZAxis" ), aFalseBool );
282 xProp->setPropertyValue(
283 rtl::OUString::createFromAscii( "HasZAxisDescription" ), aFalseBool );
285 uno::Any aAny;
286 chart::ChartDataRowSource eSource = chart::ChartDataRowSource_COLUMNS;
287 aAny <<= eSource;
288 xProp->setPropertyValue( rtl::OUString::createFromAscii( "DataRowSource" ), aAny );
290 catch( beans::UnknownPropertyException & )
292 DBG_ERROR( "Property required by service not supported" );
297 SchXMLPlotAreaContext::~SchXMLPlotAreaContext()
300 void SchXMLPlotAreaContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
302 uno::Any aTransMatrixAny;
304 // initialize size and position
305 uno::Reference< drawing::XShape > xDiaShape( mxDiagram, uno::UNO_QUERY );
306 bool bHasSizeWidth = false;
307 bool bHasSizeHeight = false;
308 bool bHasPositionX = false;
309 bool bHasPositionY = false;
311 // parse attributes
312 sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
313 const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetPlotAreaAttrTokenMap();
314 uno::Reference< chart2::XChartDocument > xNewDoc( GetImport().GetModel(), uno::UNO_QUERY );
316 for( sal_Int16 i = 0; i < nAttrCount; i++ )
318 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
319 rtl::OUString aLocalName;
320 rtl::OUString aValue = xAttrList->getValueByIndex( i );
321 USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
323 switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
325 case XML_TOK_PA_X:
326 GetImport().GetMM100UnitConverter().convertMeasure( maPosition.X, aValue );
327 bHasPositionX = true;
328 break;
329 case XML_TOK_PA_Y:
330 GetImport().GetMM100UnitConverter().convertMeasure( maPosition.Y, aValue );
331 bHasPositionY = true;
332 break;
333 case XML_TOK_PA_WIDTH:
334 GetImport().GetMM100UnitConverter().convertMeasure( maSize.Width, aValue );
335 bHasSizeWidth = true;
336 break;
337 case XML_TOK_PA_HEIGHT:
338 GetImport().GetMM100UnitConverter().convertMeasure( maSize.Height, aValue );
339 bHasSizeHeight = true;
340 break;
341 case XML_TOK_PA_STYLE_NAME:
342 msAutoStyleName = aValue;
343 break;
344 case XML_TOK_PA_CHART_ADDRESS:
345 mrChartAddress = lcl_ConvertRange( aValue, xNewDoc );
346 // indicator for getting data from the outside
347 m_rbHasRangeAtPlotArea = true;
348 break;
349 case XML_TOK_PA_DS_HAS_LABELS:
351 if( aValue.equals( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_BOTH )))
352 mrColHasLabels = mrRowHasLabels = sal_True;
353 else if( aValue.equals( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_ROW )))
354 mrRowHasLabels = sal_True;
355 else if( aValue.equals( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_COLUMN )))
356 mrColHasLabels = sal_True;
358 break;
359 case XML_TOK_PA_TRANSFORM:
360 case XML_TOK_PA_VRP:
361 case XML_TOK_PA_VPN:
362 case XML_TOK_PA_VUP:
363 case XML_TOK_PA_PROJECTION:
364 case XML_TOK_PA_DISTANCE:
365 case XML_TOK_PA_FOCAL_LENGTH:
366 case XML_TOK_PA_SHADOW_SLANT:
367 case XML_TOK_PA_SHADE_MODE:
368 case XML_TOK_PA_AMBIENT_COLOR:
369 case XML_TOK_PA_LIGHTING_MODE:
370 maSceneImportHelper.processSceneAttribute( nPrefix, aLocalName, aValue );
371 break;
375 mbHasSize = bHasSizeWidth && bHasSizeHeight;
376 mbHasPosition = bHasPositionX && bHasPositionY;
378 if( ! mxNewDoc.is())
380 uno::Reference< beans::XPropertySet > xDocProp( mrImportHelper.GetChartDocument(), uno::UNO_QUERY );
381 if( xDocProp.is())
385 uno::Any aAny;
386 aAny <<= (sal_Bool)(mrColHasLabels);
387 xDocProp->setPropertyValue(
388 ::rtl::OUString::createFromAscii( "DataSourceLabelsInFirstColumn" ),
389 aAny );
391 aAny <<= (sal_Bool)(mrRowHasLabels);
392 xDocProp->setPropertyValue(
393 ::rtl::OUString::createFromAscii( "DataSourceLabelsInFirstRow" ),
394 aAny );
396 catch( beans::UnknownPropertyException & )
398 DBG_ERRORFILE( "Properties missing" );
403 // set properties
404 uno::Reference< beans::XPropertySet > xProp( mxDiagram, uno::UNO_QUERY );
405 if( msAutoStyleName.getLength())
407 if( xProp.is())
409 const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
410 if( pStylesCtxt )
412 const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
413 mrImportHelper.GetChartFamilyID(), msAutoStyleName );
415 XMLPropStyleContext* pPropStyleContext =
416 const_cast< XMLPropStyleContext * >(
417 dynamic_cast< const XMLPropStyleContext * >( pStyle ) );
418 if( pPropStyleContext )
420 pPropStyleContext->FillPropertySet( xProp );
422 // get the data row source that was set without having data
423 xProp->getPropertyValue( ::rtl::OUString::createFromAscii("DataRowSource"))
424 >>= mrDataRowSource;
426 //lines on/off
427 //this old property is not supported fully anymore with the new chart, so we need to get the information a little bit different from similar properties
428 mrSeriesDefaultsAndStyles.maLinesOnProperty = SchXMLTools::getPropertyFromContext(
429 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Lines")), pPropStyleContext, pStylesCtxt );
431 //handle automatic position and size
432 bool bAutoSize = false;
433 bool bAutoPosition = false;
434 SchXMLTools::getPropertyFromContext(
435 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AutomaticSize")), pPropStyleContext, pStylesCtxt ) >>= bAutoSize;
436 SchXMLTools::getPropertyFromContext(
437 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AutomaticPosition")), pPropStyleContext, pStylesCtxt ) >>= bAutoPosition;
438 mbHasSize = mbHasSize && !bAutoSize;
439 mbHasPosition = mbHasPosition && !bAutoPosition;
441 //correct default starting angle for old 3D pies
442 if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan3_0( GetImport().GetModel() ) )
444 bool bIs3d = false;
445 if( xProp.is() && ( xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Dim3D"))) >>= bIs3d ) &&
446 bIs3d )
448 if( maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.PieChartType" ))
449 || maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.DonutChartType" )) )
451 ::rtl::OUString aPropName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StartingAngle")) );
452 uno::Any aAStartingAngle( SchXMLTools::getPropertyFromContext( aPropName, pPropStyleContext, pStylesCtxt ) );
453 if( !aAStartingAngle.hasValue() )
454 xProp->setPropertyValue( aPropName, uno::makeAny(sal_Int32(0)) ) ;
463 //remember default values for dataseries
464 if(xProp.is())
467 mrSeriesDefaultsAndStyles.maSymbolTypeDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SymbolType")));
468 mrSeriesDefaultsAndStyles.maDataCaptionDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataCaption")));
470 mrSeriesDefaultsAndStyles.maErrorIndicatorDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ErrorIndicator")));
471 mrSeriesDefaultsAndStyles.maErrorCategoryDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ErrorCategory")));
472 mrSeriesDefaultsAndStyles.maConstantErrorLowDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ConstantErrorLow")));
473 mrSeriesDefaultsAndStyles.maConstantErrorHighDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ConstantErrorHigh")));
474 mrSeriesDefaultsAndStyles.maPercentageErrorDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PercentageError")));
475 mrSeriesDefaultsAndStyles.maErrorMarginDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ErrorMargin")));
477 mrSeriesDefaultsAndStyles.maMeanValueDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MeanValue")));
478 mrSeriesDefaultsAndStyles.maRegressionCurvesDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RegressionCurves")));
480 bool bStacked = false;
481 mrSeriesDefaultsAndStyles.maStackedDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Stacked")));
482 mrSeriesDefaultsAndStyles.maStackedDefault >>= bStacked;
483 mrSeriesDefaultsAndStyles.maPercentDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Percent")));
484 mrSeriesDefaultsAndStyles.maPercentDefault >>= mbPercentStacked;
485 mrSeriesDefaultsAndStyles.maStackedBarsConnectedDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StackedBarsConnected")));
487 // deep
488 uno::Any aDeepProperty( xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Deep"))));
489 // #124488# old versions store a 3d area and 3D line deep chart with Deep==false => workaround for this
490 if( ! (bStacked || mbPercentStacked ))
492 if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan2_3( GetImport().GetModel() ) )
494 bool bIs3d = false;
495 if( ( xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Dim3D"))) >>= bIs3d ) &&
496 bIs3d )
498 if( maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.AreaChartType" )) ||
499 maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.LineChartType" )) )
501 aDeepProperty <<= uno::makeAny( true );
506 mrSeriesDefaultsAndStyles.maDeepDefault = aDeepProperty;
508 xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NumberOfLines"))) >>= mnNumOfLinesProp;
509 xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Volume"))) >>= mbStockHasVolume;
511 catch( uno::Exception & rEx )
513 #ifdef DBG_UTIL
514 String aStr( rEx.Message );
515 ByteString aBStr( aStr, RTL_TEXTENCODING_ASCII_US );
516 DBG_ERROR1( "PlotAreaContext:EndElement(): Exception caught: %s", aBStr.GetBuffer());
517 #else
518 (void)rEx; // avoid warning for pro build
519 #endif
523 bool bCreateInternalDataProvider = false;
524 if( m_rXLinkHRefAttributeToIndicateDataProvider.equalsAscii( "." ) ) //data comes from the chart itself
525 bCreateInternalDataProvider = true;
526 else if( m_rXLinkHRefAttributeToIndicateDataProvider.equalsAscii( ".." ) ) //data comes from the parent application
527 bCreateInternalDataProvider = false;
528 else if( m_rXLinkHRefAttributeToIndicateDataProvider.getLength() ) //not supported so far to get the data by sibling objects -> fall back to chart itself
529 bCreateInternalDataProvider = true;
530 else if( !m_rbHasRangeAtPlotArea )
531 bCreateInternalDataProvider = true;
533 if( bCreateInternalDataProvider && mxNewDoc.is() )
535 // we have no complete range => we have own data, so switch the data
536 // provider to internal. Clone is not necessary, as we don't have any
537 // data yet.
538 mxNewDoc->createInternalDataProvider( false /* bCloneExistingData */ );
539 if( xProp.is() && mrDataRowSource!=chart::ChartDataRowSource_COLUMNS )
540 xProp->setPropertyValue( rtl::OUString::createFromAscii( "DataRowSource" ), uno::makeAny(mrDataRowSource) );
544 SvXMLImportContext* SchXMLPlotAreaContext::CreateChildContext(
545 USHORT nPrefix,
546 const rtl::OUString& rLocalName,
547 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
549 SvXMLImportContext* pContext = 0;
550 const SvXMLTokenMap& rTokenMap = mrImportHelper.GetPlotAreaElemTokenMap();
552 switch( rTokenMap.Get( nPrefix, rLocalName ))
554 case XML_TOK_PA_AXIS:
556 bool bAddMissingXAxisForNetCharts = false;
557 bool bAdaptWrongPercentScaleValues = false;
558 if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan2_3( GetImport().GetModel() ) )
560 //correct errors from older versions
562 // for NetCharts there were no xAxis exported to older files
563 // so we need to add the x axis here for those old NetChart files
564 if( maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.NetChartType" )) )
565 bAddMissingXAxisForNetCharts = true;
567 //Issue 59288
568 if( mbPercentStacked )
569 bAdaptWrongPercentScaleValues = true;
572 bool bAdaptXAxisOrientationForOld2DBarCharts = false;
573 if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan2_4( GetImport().GetModel() ) )
575 //issue74660
576 if( maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.ColumnChartType" )) )
577 bAdaptXAxisOrientationForOld2DBarCharts = true;
580 pContext = new SchXMLAxisContext( mrImportHelper, GetImport(), rLocalName, mxDiagram, maAxes, mrCategoriesAddress,
581 bAddMissingXAxisForNetCharts, bAdaptWrongPercentScaleValues, bAdaptXAxisOrientationForOld2DBarCharts, m_bAxisPositionAttributeImported );
583 break;
585 case XML_TOK_PA_SERIES:
587 if( mxNewDoc.is())
589 pContext = new SchXMLSeries2Context(
590 mrImportHelper, GetImport(), rLocalName,
591 mxNewDoc, maAxes,
592 mrSeriesDefaultsAndStyles.maSeriesStyleList,
593 mnSeries,
594 mbStockHasVolume,
595 m_aGlobalSeriesImportInfo,
596 maChartTypeServiceName,
597 mrLSequencesPerIndex,
598 mbGlobalChartTypeUsedBySeries, maChartSize );
600 mnSeries++;
602 break;
604 case XML_TOK_PA_WALL:
605 pContext = new SchXMLWallFloorContext( mrImportHelper, GetImport(), nPrefix, rLocalName, mxDiagram,
606 SchXMLWallFloorContext::CONTEXT_TYPE_WALL );
607 break;
608 case XML_TOK_PA_FLOOR:
609 pContext = new SchXMLWallFloorContext( mrImportHelper, GetImport(), nPrefix, rLocalName, mxDiagram,
610 SchXMLWallFloorContext::CONTEXT_TYPE_FLOOR );
611 break;
613 case XML_TOK_PA_LIGHT_SOURCE:
614 pContext = maSceneImportHelper.create3DLightContext( nPrefix, rLocalName, xAttrList );
615 break;
617 // elements for stock charts
618 case XML_TOK_PA_STOCK_GAIN:
619 pContext = new SchXMLStockContext( mrImportHelper, GetImport(), nPrefix, rLocalName, mxDiagram,
620 SchXMLStockContext::CONTEXT_TYPE_GAIN );
621 break;
622 case XML_TOK_PA_STOCK_LOSS:
623 pContext = new SchXMLStockContext( mrImportHelper, GetImport(), nPrefix, rLocalName, mxDiagram,
624 SchXMLStockContext::CONTEXT_TYPE_LOSS );
625 break;
626 case XML_TOK_PA_STOCK_RANGE:
627 pContext = new SchXMLStockContext( mrImportHelper, GetImport(), nPrefix, rLocalName, mxDiagram,
628 SchXMLStockContext::CONTEXT_TYPE_RANGE );
629 break;
631 default:
632 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
635 return pContext;
638 void SchXMLPlotAreaContext::EndElement()
640 // set categories
641 if( mrCategoriesAddress.getLength() && mxNewDoc.is())
643 uno::Reference< chart2::data::XDataProvider > xDataProvider(
644 mxNewDoc->getDataProvider() );
645 // @todo: correct coordinate system index
646 sal_Int32 nDimension( 0 );
647 ::std::vector< SchXMLAxis >::const_iterator aIt(
648 ::std::find_if( maAxes.begin(), maAxes.end(), lcl_AxisHasCategories()));
649 if( aIt != maAxes.end())
650 nDimension = static_cast< sal_Int32 >( (*aIt).eClass );
651 SchXMLTools::CreateCategories(
652 xDataProvider, mxNewDoc, mrCategoriesAddress,
653 0 /* nCooSysIndex */,
654 nDimension, &mrLSequencesPerIndex );
657 uno::Reference< beans::XPropertySet > xDiaProp( mxDiagram, uno::UNO_QUERY );
658 if( xDiaProp.is())
660 sal_Bool bIsThreeDim = sal_False;
661 uno::Any aAny = xDiaProp->getPropertyValue( ::rtl::OUString::createFromAscii( "Dim3D" ));
662 aAny >>= bIsThreeDim;
664 // set 3d scene attributes
665 if( bIsThreeDim )
667 // set scene attributes at diagram
668 maSceneImportHelper.setSceneAttributes( xDiaProp );
671 // set correct number of lines at series
672 if( ! m_aGlobalSeriesImportInfo.rbAllRangeAddressesAvailable &&
673 mnNumOfLinesProp > 0 &&
674 maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.ColumnChartType" )))
678 xDiaProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "NumberOfLines" )),
679 uno::makeAny( mnNumOfLinesProp ));
681 catch( uno::Exception & rEx )
683 #ifdef DBG_UTIL
684 String aStr( rEx.Message );
685 ByteString aBStr( aStr, RTL_TEXTENCODING_ASCII_US );
686 DBG_ERROR1( "Exception caught for property NumberOfLines: %s", aBStr.GetBuffer());
687 #else
688 (void)rEx; // avoid warning for pro build
689 #endif
693 // #i32366# stock has volume
694 if( ( 0 == mxDiagram->getDiagramType().reverseCompareToAsciiL(
695 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart.StockDiagram" ))) &&
696 mbStockHasVolume )
700 xDiaProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Volume" )),
701 uno::makeAny( true ));
703 catch( uno::Exception & rEx )
705 #ifdef DBG_UTIL
706 String aStr( rEx.Message );
707 ByteString aBStr( aStr, RTL_TEXTENCODING_ASCII_US );
708 DBG_ERROR1( "Exception caught for property Volume: %s", aBStr.GetBuffer());
709 #else
710 (void)rEx; // avoid warning for pro build
711 #endif
716 // set changed size and position after properties (esp. 3d)
717 uno::Reference< drawing::XShape > xDiaShape( mxDiagram, uno::UNO_QUERY );
718 if( xDiaShape.is())
720 if( mbHasSize )
721 xDiaShape->setSize( maSize );
722 if( mbHasPosition )
723 xDiaShape->setPosition( maPosition );
726 CorrectAxisPositions();
729 void SchXMLPlotAreaContext::CorrectAxisPositions()
731 ::rtl::OUString aODFVersionOfFile( GetImport().GetODFVersion() );
733 if( ( !aODFVersionOfFile.getLength() || aODFVersionOfFile.equalsAscii("1.0")
734 || aODFVersionOfFile.equalsAscii("1.1")
735 || ( aODFVersionOfFile.equalsAscii("1.2") && !m_bAxisPositionAttributeImported ) ) )
737 uno::Reference< chart2::XChartDocument > xNewDoc( mrImportHelper.GetChartDocument(), uno::UNO_QUERY );
741 Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xNewDoc->getFirstDiagram(), uno::UNO_QUERY_THROW );
742 uno::Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems());
743 if( aCooSysSeq.getLength() )
745 Reference< chart2::XCoordinateSystem > xCooSys( aCooSysSeq[0] );
746 if( xCooSys.is() )
748 Reference< chart2::XAxis > xMainXAxis = lcl_getAxis( xCooSys, 0, 0 );
749 Reference< chart2::XAxis > xMainYAxis = lcl_getAxis( xCooSys, 1, 0 );
750 //Reference< chart2::XAxis > xMajorZAxis = lcl_getAxis( xCooSys, 2, 0 );
751 Reference< chart2::XAxis > xSecondaryXAxis = lcl_getAxis( xCooSys, 0, 1 );
752 Reference< chart2::XAxis > xSecondaryYAxis = lcl_getAxis( xCooSys, 1, 1 );
754 uno::Reference< beans::XPropertySet > xMainXAxisProp( xMainXAxis, uno::UNO_QUERY );
755 uno::Reference< beans::XPropertySet > xMainYAxisProp( xMainYAxis, uno::UNO_QUERY );
756 uno::Reference< beans::XPropertySet > xSecondaryXAxisProp( xSecondaryXAxis, uno::UNO_QUERY );
757 uno::Reference< beans::XPropertySet > xSecondaryYAxisProp( xSecondaryYAxis, uno::UNO_QUERY );
759 if( xMainXAxisProp.is() && xMainYAxisProp.is() )
761 chart2::ScaleData aMainXScale = xMainXAxis->getScaleData();
762 if( 0 == maChartTypeServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.ScatterChartType" ) ) )
764 xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition")
765 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_VALUE) );
766 double fCrossoverValue = 0.0;
767 aMainXScale.Origin >>= fCrossoverValue;
768 xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverValue")
769 , uno::makeAny( fCrossoverValue ) );
771 if( aMainXScale.Orientation == chart2::AxisOrientation_REVERSE )
773 xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("LabelPosition")
774 , uno::makeAny( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_END) );
775 xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("MarkPosition")
776 , uno::makeAny( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS) );
777 if( xSecondaryYAxisProp.is() )
778 xSecondaryYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition")
779 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START) );
781 else
783 xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("LabelPosition")
784 , uno::makeAny( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START) );
785 xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("MarkPosition")
786 , uno::makeAny( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS) );
787 if( xSecondaryYAxisProp.is() )
788 xSecondaryYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition")
789 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_END) );
792 else
794 if( aMainXScale.Orientation == chart2::AxisOrientation_REVERSE )
796 xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition")
797 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_END) );
798 if( xSecondaryYAxisProp.is() )
799 xSecondaryYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition")
800 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START) );
802 else
804 xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition")
805 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START) );
806 if( xSecondaryYAxisProp.is() )
807 xSecondaryYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition")
808 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_END) );
812 chart2::ScaleData aMainYScale = xMainYAxis->getScaleData();
813 xMainXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition")
814 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_VALUE) );
815 double fCrossoverValue = 0.0;
816 aMainYScale.Origin >>= fCrossoverValue;
817 xMainXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverValue")
818 , uno::makeAny( fCrossoverValue ) );
820 if( aMainYScale.Orientation == chart2::AxisOrientation_REVERSE )
822 xMainXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("LabelPosition")
823 , uno::makeAny( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_END) );
824 xMainXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("MarkPosition")
825 , uno::makeAny( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS) );
826 if( xSecondaryXAxisProp.is() )
827 xSecondaryXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition")
828 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START) );
830 else
832 xMainXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("LabelPosition")
833 , uno::makeAny( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START) );
834 xMainXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("MarkPosition")
835 , uno::makeAny( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS) );
836 if( xSecondaryXAxisProp.is() )
837 xSecondaryXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition")
838 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_END) );
844 catch( uno::Exception & )
850 // ========================================
852 SchXMLAxisContext::SchXMLAxisContext( SchXMLImportHelper& rImpHelper,
853 SvXMLImport& rImport, const rtl::OUString& rLocalName,
854 uno::Reference< chart::XDiagram > xDiagram,
855 std::vector< SchXMLAxis >& aAxes,
856 ::rtl::OUString & rCategoriesAddress,
857 bool bAddMissingXAxisForNetCharts,
858 bool bAdaptWrongPercentScaleValues,
859 bool bAdaptXAxisOrientationForOld2DBarCharts,
860 bool& rbAxisPositionAttributeImported ) :
861 SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ),
862 mrImportHelper( rImpHelper ),
863 mxDiagram( xDiagram ),
864 maAxes( aAxes ),
865 mrCategoriesAddress( rCategoriesAddress ),
866 mbAddMissingXAxisForNetCharts( bAddMissingXAxisForNetCharts ),
867 mbAdaptWrongPercentScaleValues( bAdaptWrongPercentScaleValues ),
868 mbAdaptXAxisOrientationForOld2DBarCharts( bAdaptXAxisOrientationForOld2DBarCharts ),
869 m_rbAxisPositionAttributeImported( rbAxisPositionAttributeImported )
873 SchXMLAxisContext::~SchXMLAxisContext()
876 /* returns a shape for the current axis's title. The property
877 "Has...AxisTitle" is set to "True" to get the shape
879 uno::Reference< drawing::XShape > SchXMLAxisContext::getTitleShape()
881 uno::Reference< drawing::XShape > xResult;
882 uno::Any aTrueBool;
883 aTrueBool <<= (sal_Bool)(sal_True);
884 uno::Reference< beans::XPropertySet > xDiaProp( mxDiagram, uno::UNO_QUERY );
886 switch( maCurrentAxis.eClass )
888 case SCH_XML_AXIS_X:
889 if( maCurrentAxis.nIndexInCategory == 0 )
891 uno::Reference< chart::XAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
892 if( xSuppl.is())
894 if( xDiaProp.is())
895 xDiaProp->setPropertyValue( rtl::OUString::createFromAscii( "HasXAxisTitle" ), aTrueBool );
896 xResult = uno::Reference< drawing::XShape >( xSuppl->getXAxisTitle(), uno::UNO_QUERY );
899 else
901 uno::Reference< chart::XSecondAxisTitleSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
902 if( xSuppl.is() )
904 if( xDiaProp.is() )
905 xDiaProp->setPropertyValue( rtl::OUString::createFromAscii( "HasSecondaryXAxisTitle" ), aTrueBool );
906 xResult = uno::Reference< drawing::XShape >( xSuppl->getSecondXAxisTitle(), uno::UNO_QUERY );
909 break;
910 case SCH_XML_AXIS_Y:
911 if( maCurrentAxis.nIndexInCategory == 0 )
913 uno::Reference< chart::XAxisYSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
914 if( xSuppl.is())
916 if( xDiaProp.is())
917 xDiaProp->setPropertyValue( rtl::OUString::createFromAscii( "HasYAxisTitle" ), aTrueBool );
918 xResult = uno::Reference< drawing::XShape >( xSuppl->getYAxisTitle(), uno::UNO_QUERY );
921 else
923 uno::Reference< chart::XSecondAxisTitleSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
924 if( xSuppl.is() )
926 if( xDiaProp.is() )
927 xDiaProp->setPropertyValue( rtl::OUString::createFromAscii( "HasSecondaryYAxisTitle" ), aTrueBool );
928 xResult = uno::Reference< drawing::XShape >( xSuppl->getSecondYAxisTitle(), uno::UNO_QUERY );
931 break;
932 case SCH_XML_AXIS_Z:
934 uno::Reference< chart::XAxisZSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
935 if( xSuppl.is())
937 if( xDiaProp.is())
938 xDiaProp->setPropertyValue( rtl::OUString::createFromAscii( "HasZAxisTitle" ), aTrueBool );
939 xResult = uno::Reference< drawing::XShape >( xSuppl->getZAxisTitle(), uno::UNO_QUERY );
941 break;
943 case SCH_XML_AXIS_UNDEF:
944 DBG_ERROR( "Invalid axis" );
945 break;
948 return xResult;
951 void SchXMLAxisContext::CreateGrid( ::rtl::OUString sAutoStyleName,
952 sal_Bool bIsMajor )
954 uno::Reference< chart::XDiagram > xDia = mrImportHelper.GetChartDocument()->getDiagram();
955 uno::Reference< beans::XPropertySet > xGridProp;
956 ::rtl::OUString sPropertyName;
957 DBG_ASSERT( xDia.is(), "diagram object is invalid!" );
959 uno::Reference< beans::XPropertySet > xDiaProp( xDia, uno::UNO_QUERY );
960 uno::Any aTrueBool( uno::makeAny( true ));
962 switch( maCurrentAxis.eClass )
964 case SCH_XML_AXIS_X:
966 uno::Reference< chart::XAxisXSupplier > xSuppl( xDia, uno::UNO_QUERY );
967 if( xSuppl.is())
969 if( bIsMajor )
971 if( xDiaProp.is())
972 xDiaProp->setPropertyValue( ::rtl::OUString::createFromAscii("HasXAxisGrid"), aTrueBool );
973 xGridProp = xSuppl->getXMainGrid();
975 else
977 if( xDiaProp.is())
978 xDiaProp->setPropertyValue( ::rtl::OUString::createFromAscii("HasXAxisHelpGrid"), aTrueBool );
979 xGridProp = xSuppl->getXHelpGrid();
983 break;
984 case SCH_XML_AXIS_Y:
986 uno::Reference< chart::XAxisYSupplier > xSuppl( xDia, uno::UNO_QUERY );
987 if( xSuppl.is())
989 if( bIsMajor )
991 if( xDiaProp.is())
992 xDiaProp->setPropertyValue( ::rtl::OUString::createFromAscii("HasYAxisGrid"), aTrueBool );
993 xGridProp = xSuppl->getYMainGrid();
995 else
997 if( xDiaProp.is())
998 xDiaProp->setPropertyValue( ::rtl::OUString::createFromAscii("HasYAxisHelpGrid"), aTrueBool );
999 xGridProp = xSuppl->getYHelpGrid();
1003 break;
1004 case SCH_XML_AXIS_Z:
1006 uno::Reference< chart::XAxisZSupplier > xSuppl( xDia, uno::UNO_QUERY );
1007 if( xSuppl.is())
1009 if( bIsMajor )
1011 if( xDiaProp.is())
1012 xDiaProp->setPropertyValue( ::rtl::OUString::createFromAscii("HasZAxisGrid"), aTrueBool );
1013 xGridProp = xSuppl->getZMainGrid();
1015 else
1017 if( xDiaProp.is())
1018 xDiaProp->setPropertyValue( ::rtl::OUString::createFromAscii("HasZAxisHelpGrid"), aTrueBool );
1019 xGridProp = xSuppl->getZHelpGrid();
1023 break;
1024 case SCH_XML_AXIS_UNDEF:
1025 DBG_ERROR( "Invalid axis" );
1026 break;
1029 // set properties
1030 if( xGridProp.is())
1032 // the line color is black as default, in the model it is a light gray
1033 xGridProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LineColor" )),
1034 uno::makeAny( COL_BLACK ));
1035 if( sAutoStyleName.getLength())
1037 const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
1038 if( pStylesCtxt )
1040 const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
1041 mrImportHelper.GetChartFamilyID(), sAutoStyleName );
1043 if( pStyle && pStyle->ISA( XMLPropStyleContext ))
1044 (( XMLPropStyleContext* )pStyle )->FillPropertySet( xGridProp );
1050 void SchXMLAxisContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
1052 // parse attributes
1053 sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
1054 SchXMLImport& rImport = ( SchXMLImport& )GetImport();
1055 const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetAxisAttrTokenMap();
1057 for( sal_Int16 i = 0; i < nAttrCount; i++ )
1059 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
1060 rtl::OUString aLocalName;
1061 rtl::OUString aValue = xAttrList->getValueByIndex( i );
1062 USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
1064 switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
1066 case XML_TOK_AXIS_DIMENSION:
1068 USHORT nEnumVal;
1069 if( rImport.GetMM100UnitConverter().convertEnum( nEnumVal, aValue, aXMLAxisClassMap ))
1070 maCurrentAxis.eClass = ( SchXMLAxisClass )nEnumVal;
1072 break;
1073 case XML_TOK_AXIS_NAME:
1074 maCurrentAxis.aName = aValue;
1075 break;
1076 case XML_TOK_AXIS_STYLE_NAME:
1077 msAutoStyleName = aValue;
1078 break;
1082 // check for number of axes with same category
1083 maCurrentAxis.nIndexInCategory = 0;
1084 sal_Int32 nNumOfAxes = maAxes.size();
1085 for( sal_Int32 nCurrent = 0; nCurrent < nNumOfAxes; nCurrent++ )
1087 if( maAxes[ nCurrent ].eClass == maCurrentAxis.eClass )
1088 maCurrentAxis.nIndexInCategory++;
1090 CreateAxis();
1092 namespace
1095 uno::Reference< chart2::XAxis > lcl_getAxis( const uno::Reference< frame::XModel >& xChartModel,
1096 sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
1098 uno::Reference< chart2::XAxis > xAxis;
1102 uno::Reference< chart2::XChartDocument > xChart2Document( xChartModel, uno::UNO_QUERY );
1103 if( xChart2Document.is() )
1105 uno::Reference< chart2::XDiagram > xDiagram( xChart2Document->getFirstDiagram());
1106 uno::Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY_THROW );
1107 uno::Sequence< uno::Reference< chart2::XCoordinateSystem > >
1108 aCooSysSeq( xCooSysCnt->getCoordinateSystems());
1109 sal_Int32 nCooSysIndex = 0;
1110 if( nCooSysIndex < aCooSysSeq.getLength() )
1112 uno::Reference< chart2::XCoordinateSystem > xCooSys( aCooSysSeq[nCooSysIndex] );
1113 if( xCooSys.is() && nDimensionIndex < xCooSys->getDimension() )
1115 const sal_Int32 nMaxAxisIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex);
1116 if( nAxisIndex <= nMaxAxisIndex )
1117 xAxis = xCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex );
1122 catch( uno::Exception & )
1124 DBG_ERROR( "Couldn't get axis" );
1127 return xAxis;
1130 bool lcl_divideBy100( uno::Any& rDoubleAny )
1132 bool bChanged = false;
1133 double fValue=0.0;
1134 if( (rDoubleAny>>=fValue) && (fValue!=0.0) )
1136 fValue/=100.0;
1137 rDoubleAny = uno::makeAny(fValue);
1138 bChanged = true;
1140 return bChanged;
1143 bool lcl_AdaptWrongPercentScaleValues(chart2::ScaleData& rScaleData)
1145 bool bChanged = lcl_divideBy100( rScaleData.Minimum );
1146 bChanged = lcl_divideBy100( rScaleData.Maximum ) || bChanged;
1147 bChanged = lcl_divideBy100( rScaleData.Origin ) || bChanged;
1148 bChanged = lcl_divideBy100( rScaleData.IncrementData.Distance ) || bChanged;
1149 return bChanged;
1152 }//end anonymous namespace
1154 void SchXMLAxisContext::CreateAxis()
1156 // add new Axis to list
1157 maAxes.push_back( maCurrentAxis );
1159 // set axis at chart
1160 uno::Reference< beans::XPropertySet > xDiaProp( mxDiagram, uno::UNO_QUERY );
1161 uno::Reference< beans::XPropertySet > xProp;
1162 uno::Any aTrueBool;
1163 aTrueBool <<= (sal_Bool)(sal_True);
1164 uno::Any aFalseBool;
1165 aFalseBool <<= (sal_Bool)(sal_False);
1166 uno::Reference< frame::XModel > xDoc( mrImportHelper.GetChartDocument(), uno::UNO_QUERY );
1168 switch( maCurrentAxis.eClass )
1170 case SCH_XML_AXIS_X:
1171 if( maCurrentAxis.nIndexInCategory == 0 )
1175 xDiaProp->setPropertyValue(
1176 rtl::OUString::createFromAscii( "HasXAxis" ), aTrueBool );
1178 catch( beans::UnknownPropertyException & )
1180 DBG_ERROR( "Couldn't turn on x axis" );
1182 uno::Reference< chart::XAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
1183 if( xSuppl.is())
1184 xProp = xSuppl->getXAxis();
1186 else
1190 xDiaProp->setPropertyValue(
1191 rtl::OUString::createFromAscii( "HasSecondaryXAxis" ), aTrueBool );
1193 catch( beans::UnknownPropertyException & )
1195 DBG_ERROR( "Couldn't turn on second x axis" );
1197 uno::Reference< chart::XTwoAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
1198 if( xSuppl.is())
1199 xProp = xSuppl->getSecondaryXAxis();
1201 break;
1203 case SCH_XML_AXIS_Y:
1204 if( maCurrentAxis.nIndexInCategory == 0 )
1208 xDiaProp->setPropertyValue(
1209 rtl::OUString::createFromAscii( "HasYAxis" ), aTrueBool );
1211 catch( beans::UnknownPropertyException & )
1213 DBG_ERROR( "Couldn't turn on y axis" );
1215 uno::Reference< chart::XAxisYSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
1216 if( xSuppl.is())
1217 xProp = xSuppl->getYAxis();
1220 if( mbAddMissingXAxisForNetCharts )
1222 if( xDiaProp.is() )
1226 xDiaProp->setPropertyValue(
1227 rtl::OUString::createFromAscii( "HasXAxis" ), uno::makeAny(sal_True) );
1229 catch( beans::UnknownPropertyException & )
1231 DBG_ERROR( "Couldn't turn on x axis" );
1236 else
1240 xDiaProp->setPropertyValue(
1241 rtl::OUString::createFromAscii( "HasSecondaryYAxis" ), aTrueBool );
1243 catch( beans::UnknownPropertyException & )
1245 DBG_ERROR( "Couldn't turn on second y axis" );
1247 uno::Reference< chart::XTwoAxisYSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
1248 if( xSuppl.is())
1249 xProp = xSuppl->getSecondaryYAxis();
1251 break;
1253 case SCH_XML_AXIS_Z:
1257 xDiaProp->setPropertyValue(
1258 rtl::OUString::createFromAscii( "HasZAxis" ), aTrueBool );
1260 catch( beans::UnknownPropertyException & )
1262 DBG_ERROR( "Couldn't turn on z axis" );
1264 uno::Reference< chart::XAxisZSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
1265 if( xSuppl.is())
1266 xProp = xSuppl->getZAxis();
1268 break;
1269 case SCH_XML_AXIS_UNDEF:
1270 // nothing
1271 break;
1274 // set properties
1275 if( xProp.is())
1277 xProp->setPropertyValue( rtl::OUString::createFromAscii( "DisplayLabels" ), aFalseBool );
1279 // #88077# AutoOrigin 'on' is default
1280 xProp->setPropertyValue( rtl::OUString::createFromAscii( "AutoOrigin" ), aTrueBool );
1282 if( msAutoStyleName.getLength())
1284 const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
1285 if( pStylesCtxt )
1287 const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
1288 mrImportHelper.GetChartFamilyID(), msAutoStyleName );
1290 if( pStyle && pStyle->ISA( XMLPropStyleContext ))
1292 // note: SvXMLStyleContext::FillPropertySet is not const
1293 XMLPropStyleContext * pPropStyleContext = const_cast< XMLPropStyleContext * >( dynamic_cast< const XMLPropStyleContext * >( pStyle ));
1294 if( pPropStyleContext )
1295 pPropStyleContext->FillPropertySet( xProp );
1297 if( mbAdaptWrongPercentScaleValues && maCurrentAxis.eClass==SCH_XML_AXIS_Y )
1299 //set scale data of added x axis back to default
1300 uno::Reference< chart2::XAxis > xAxis( lcl_getAxis( GetImport().GetModel(),
1301 1 /*nDimensionIndex*/, maCurrentAxis.nIndexInCategory /*nAxisIndex*/ ) );
1302 if( xAxis.is() )
1304 chart2::ScaleData aScaleData( xAxis->getScaleData());
1305 if( lcl_AdaptWrongPercentScaleValues(aScaleData) )
1306 xAxis->setScaleData( aScaleData );
1310 if( mbAddMissingXAxisForNetCharts )
1312 //copy style from y axis to added x axis:
1314 uno::Reference< chart::XAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
1315 if( xSuppl.is() )
1317 uno::Reference< beans::XPropertySet > xXAxisProp( xSuppl->getXAxis() );
1318 (( XMLPropStyleContext* )pStyle )->FillPropertySet( xXAxisProp );
1321 //set scale data of added x axis back to default
1322 uno::Reference< chart2::XAxis > xAxis( lcl_getAxis( GetImport().GetModel(),
1323 0 /*nDimensionIndex*/, 0 /*nAxisIndex*/ ) );
1324 if( xAxis.is() )
1326 chart2::ScaleData aScaleData;
1327 aScaleData.AxisType = chart2::AxisType::CATEGORY;
1328 aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
1329 xAxis->setScaleData( aScaleData );
1332 //set line style of added x axis to invisible
1333 uno::Reference< beans::XPropertySet > xNewAxisProp( xAxis, uno::UNO_QUERY );
1334 if( xNewAxisProp.is() )
1336 xNewAxisProp->setPropertyValue( rtl::OUString::createFromAscii("LineStyle")
1337 , uno::makeAny(drawing::LineStyle_NONE));
1341 if( mbAdaptXAxisOrientationForOld2DBarCharts && maCurrentAxis.eClass == SCH_XML_AXIS_X )
1343 bool bIs3DChart = false;
1344 if( xDiaProp.is() && ( xDiaProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Dim3D"))) >>= bIs3DChart )
1345 && !bIs3DChart )
1347 uno::Reference< chart2::XChartDocument > xChart2Document( GetImport().GetModel(), uno::UNO_QUERY );
1348 if( xChart2Document.is() )
1350 uno::Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xChart2Document->getFirstDiagram(), uno::UNO_QUERY );
1351 if( xCooSysCnt.is() )
1353 uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems() );
1354 if( aCooSysSeq.getLength() )
1356 bool bSwapXandYAxis = false;
1357 uno::Reference< chart2::XCoordinateSystem > xCooSys( aCooSysSeq[0] );
1358 uno::Reference< beans::XPropertySet > xCooSysProp( xCooSys, uno::UNO_QUERY );
1359 if( xCooSysProp.is() && ( xCooSysProp->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwapXAndYAxis"))) >>= bSwapXandYAxis )
1360 && bSwapXandYAxis )
1362 uno::Reference< chart2::XAxis > xAxis = xCooSys->getAxisByDimension( 0, maCurrentAxis.nIndexInCategory );
1363 if( xAxis.is() )
1365 chart2::ScaleData aScaleData = xAxis->getScaleData();
1366 aScaleData.Orientation = chart2::AxisOrientation_REVERSE;
1367 xAxis->setScaleData( aScaleData );
1376 m_rbAxisPositionAttributeImported = m_rbAxisPositionAttributeImported || SchXMLTools::getPropertyFromContext(
1377 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CrossoverPosition")), pPropStyleContext, pStylesCtxt ).hasValue();
1384 void SchXMLAxisContext::SetAxisTitle()
1386 // add new Axis to list
1387 maAxes.push_back( maCurrentAxis );
1389 // set axis at chart
1390 sal_Bool bHasTitle = ( maCurrentAxis.aTitle.getLength() > 0 );
1391 uno::Reference< frame::XModel > xDoc( mrImportHelper.GetChartDocument(), uno::UNO_QUERY );
1393 switch( maCurrentAxis.eClass )
1395 case SCH_XML_AXIS_X:
1396 if( maCurrentAxis.nIndexInCategory == 0 )
1398 uno::Reference< chart::XAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
1399 if( xSuppl.is() &&
1400 bHasTitle )
1402 uno::Reference< beans::XPropertySet > xTitleProp( xSuppl->getXAxisTitle(), uno::UNO_QUERY );
1403 if( xTitleProp.is())
1407 uno::Any aAny;
1408 aAny <<= maCurrentAxis.aTitle;
1409 xTitleProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny );
1411 catch( beans::UnknownPropertyException & )
1413 DBG_ERROR( "Property String for Title not available" );
1418 else
1420 uno::Reference< chart::XSecondAxisTitleSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
1421 if( xSuppl.is() &&
1422 bHasTitle )
1424 uno::Reference< beans::XPropertySet > xTitleProp( xSuppl->getSecondXAxisTitle(), uno::UNO_QUERY );
1425 if( xTitleProp.is())
1429 uno::Any aAny;
1430 aAny <<= maCurrentAxis.aTitle;
1431 xTitleProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny );
1433 catch( beans::UnknownPropertyException & )
1435 DBG_ERROR( "Property String for Title not available" );
1440 break;
1442 case SCH_XML_AXIS_Y:
1443 if( maCurrentAxis.nIndexInCategory == 0 )
1445 uno::Reference< chart::XAxisYSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
1446 if( xSuppl.is() &&
1447 bHasTitle )
1449 uno::Reference< beans::XPropertySet > xTitleProp( xSuppl->getYAxisTitle(), uno::UNO_QUERY );
1450 if( xTitleProp.is())
1454 uno::Any aAny;
1455 aAny <<= maCurrentAxis.aTitle;
1456 xTitleProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny );
1458 catch( beans::UnknownPropertyException & )
1460 DBG_ERROR( "Property String for Title not available" );
1465 else
1467 uno::Reference< chart::XSecondAxisTitleSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
1468 if( xSuppl.is() &&
1469 bHasTitle )
1471 uno::Reference< beans::XPropertySet > xTitleProp( xSuppl->getSecondYAxisTitle(), uno::UNO_QUERY );
1472 if( xTitleProp.is())
1476 uno::Any aAny;
1477 aAny <<= maCurrentAxis.aTitle;
1478 xTitleProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny );
1480 catch( beans::UnknownPropertyException & )
1482 DBG_ERROR( "Property String for Title not available" );
1487 break;
1489 case SCH_XML_AXIS_Z:
1491 uno::Reference< chart::XAxisZSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
1492 if( xSuppl.is() &&
1493 bHasTitle )
1495 uno::Reference< beans::XPropertySet > xTitleProp( xSuppl->getZAxisTitle(), uno::UNO_QUERY );
1496 if( xTitleProp.is())
1500 uno::Any aAny;
1501 aAny <<= maCurrentAxis.aTitle;
1502 xTitleProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny );
1504 catch( beans::UnknownPropertyException & )
1506 DBG_ERROR( "Property String for Title not available" );
1511 break;
1512 case SCH_XML_AXIS_UNDEF:
1513 // nothing
1514 break;
1518 SvXMLImportContext* SchXMLAxisContext::CreateChildContext(
1519 USHORT p_nPrefix,
1520 const rtl::OUString& rLocalName,
1521 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
1523 SvXMLImportContext* pContext = 0;
1524 const SvXMLTokenMap& rTokenMap = mrImportHelper.GetAxisElemTokenMap();
1526 switch( rTokenMap.Get( p_nPrefix, rLocalName ))
1528 case XML_TOK_AXIS_TITLE:
1530 uno::Reference< drawing::XShape > xTitleShape = getTitleShape();
1531 pContext = new SchXMLTitleContext( mrImportHelper, GetImport(), rLocalName,
1532 maCurrentAxis.aTitle,
1533 xTitleShape );
1535 break;
1537 case XML_TOK_AXIS_CATEGORIES:
1538 pContext = new SchXMLCategoriesContext( mrImportHelper, GetImport(),
1539 p_nPrefix, rLocalName,
1540 mrCategoriesAddress );
1541 maCurrentAxis.bHasCategories = true;
1542 break;
1544 case XML_TOK_AXIS_GRID:
1546 sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
1547 sal_Bool bIsMajor = sal_True; // default value for class is "major"
1548 rtl::OUString sAutoStyleName;
1550 for( sal_Int16 i = 0; i < nAttrCount; i++ )
1552 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
1553 rtl::OUString aLocalName;
1554 USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
1556 if( nPrefix == XML_NAMESPACE_CHART )
1558 if( IsXMLToken( aLocalName, XML_CLASS ) )
1560 if( IsXMLToken( xAttrList->getValueByIndex( i ), XML_MINOR ) )
1561 bIsMajor = sal_False;
1563 else if( IsXMLToken( aLocalName, XML_STYLE_NAME ) )
1564 sAutoStyleName = xAttrList->getValueByIndex( i );
1568 CreateGrid( sAutoStyleName, bIsMajor );
1570 // don't create a context => use default context. grid elements are empty
1571 pContext = new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
1573 break;
1575 default:
1576 pContext = new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
1577 break;
1580 return pContext;
1583 void SchXMLAxisContext::EndElement()
1585 SetAxisTitle();
1588 // ========================================
1590 SchXMLDataPointContext::SchXMLDataPointContext( SchXMLImportHelper& rImpHelper,
1591 SvXMLImport& rImport, const rtl::OUString& rLocalName,
1592 ::std::list< DataRowPointStyle >& rStyleList,
1593 const ::com::sun::star::uno::Reference<
1594 ::com::sun::star::chart2::XDataSeries >& xSeries,
1595 sal_Int32& rIndex,
1596 bool bSymbolSizeForSeriesIsMissingInFile ) :
1597 SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ),
1598 mrImportHelper( rImpHelper ),
1599 mrStyleList( rStyleList ),
1600 m_xSeries( xSeries ),
1601 mrIndex( rIndex ),
1602 mbSymbolSizeForSeriesIsMissingInFile( bSymbolSizeForSeriesIsMissingInFile )
1606 SchXMLDataPointContext::~SchXMLDataPointContext()
1610 void SchXMLDataPointContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
1612 sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
1613 ::rtl::OUString aValue;
1614 ::rtl::OUString sAutoStyleName;
1615 sal_Int32 nRepeat = 1;
1617 for( sal_Int16 i = 0; i < nAttrCount; i++ )
1619 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
1620 rtl::OUString aLocalName;
1621 USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
1623 if( nPrefix == XML_NAMESPACE_CHART )
1625 if( IsXMLToken( aLocalName, XML_STYLE_NAME ) )
1626 sAutoStyleName = xAttrList->getValueByIndex( i );
1627 else if( IsXMLToken( aLocalName, XML_REPEATED ) )
1628 nRepeat = xAttrList->getValueByIndex( i ).toInt32();
1632 if( sAutoStyleName.getLength())
1634 DataRowPointStyle aStyle(
1635 DataRowPointStyle::DATA_POINT,
1636 m_xSeries, mrIndex, nRepeat, sAutoStyleName );
1637 aStyle.mbSymbolSizeForSeriesIsMissingInFile = mbSymbolSizeForSeriesIsMissingInFile;
1638 mrStyleList.push_back( aStyle );
1640 mrIndex += nRepeat;
1643 // ========================================
1645 SchXMLCategoriesContext::SchXMLCategoriesContext(
1646 SchXMLImportHelper& rImpHelper,
1647 SvXMLImport& rImport,
1648 sal_uInt16 nPrefix,
1649 const rtl::OUString& rLocalName,
1650 rtl::OUString& rAddress ) :
1651 SvXMLImportContext( rImport, nPrefix, rLocalName ),
1652 mrImportHelper( rImpHelper ),
1653 mrAddress( rAddress )
1657 SchXMLCategoriesContext::~SchXMLCategoriesContext()
1661 void SchXMLCategoriesContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
1663 sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
1665 for( sal_Int16 i = 0; i < nAttrCount; i++ )
1667 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
1668 rtl::OUString aLocalName;
1669 USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
1671 if( nPrefix == XML_NAMESPACE_TABLE &&
1672 IsXMLToken( aLocalName, XML_CELL_RANGE_ADDRESS ) )
1674 uno::Reference< chart2::XChartDocument > xNewDoc( GetImport().GetModel(), uno::UNO_QUERY );
1675 mrAddress = xAttrList->getValueByIndex( i );
1676 // lcl_ConvertRange( xAttrList->getValueByIndex( i ), xNewDoc );
1681 // ========================================
1683 SchXMLWallFloorContext::SchXMLWallFloorContext(
1684 SchXMLImportHelper& rImpHelper,
1685 SvXMLImport& rImport,
1686 sal_uInt16 nPrefix,
1687 const rtl::OUString& rLocalName,
1688 uno::Reference< chart::XDiagram >& xDiagram,
1689 ContextType eContextType ) :
1690 SvXMLImportContext( rImport, nPrefix, rLocalName ),
1691 mrImportHelper( rImpHelper ),
1692 mxWallFloorSupplier( xDiagram, uno::UNO_QUERY ),
1693 meContextType( eContextType )
1697 SchXMLWallFloorContext::~SchXMLWallFloorContext()
1701 void SchXMLWallFloorContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
1703 if( mxWallFloorSupplier.is())
1705 sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
1706 rtl::OUString sAutoStyleName;
1708 for( sal_Int16 i = 0; i < nAttrCount; i++ )
1710 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
1711 rtl::OUString aLocalName;
1712 USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
1714 if( nPrefix == XML_NAMESPACE_CHART &&
1715 IsXMLToken( aLocalName, XML_STYLE_NAME ) )
1717 sAutoStyleName = xAttrList->getValueByIndex( i );
1721 // set properties
1722 uno::Reference< beans::XPropertySet > xProp( ( meContextType == CONTEXT_TYPE_WALL )
1723 ? mxWallFloorSupplier->getWall()
1724 : mxWallFloorSupplier->getFloor(),
1725 uno::UNO_QUERY );
1726 if( xProp.is())
1728 if( sAutoStyleName.getLength())
1730 const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
1731 if( pStylesCtxt )
1733 const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
1734 mrImportHelper.GetChartFamilyID(), sAutoStyleName );
1736 if( pStyle && pStyle->ISA( XMLPropStyleContext ))
1737 (( XMLPropStyleContext* )pStyle )->FillPropertySet( xProp );
1744 // ========================================
1746 SchXMLStockContext::SchXMLStockContext(
1747 SchXMLImportHelper& rImpHelper,
1748 SvXMLImport& rImport,
1749 sal_uInt16 nPrefix,
1750 const rtl::OUString& rLocalName,
1751 uno::Reference< chart::XDiagram >& xDiagram,
1752 ContextType eContextType ) :
1753 SvXMLImportContext( rImport, nPrefix, rLocalName ),
1754 mrImportHelper( rImpHelper ),
1755 mxStockPropProvider( xDiagram, uno::UNO_QUERY ),
1756 meContextType( eContextType )
1760 SchXMLStockContext::~SchXMLStockContext()
1764 void SchXMLStockContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
1766 if( mxStockPropProvider.is())
1768 sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
1769 rtl::OUString sAutoStyleName;
1771 for( sal_Int16 i = 0; i < nAttrCount; i++ )
1773 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
1774 rtl::OUString aLocalName;
1775 USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
1777 if( nPrefix == XML_NAMESPACE_CHART &&
1778 IsXMLToken( aLocalName, XML_STYLE_NAME ) )
1780 sAutoStyleName = xAttrList->getValueByIndex( i );
1784 if( sAutoStyleName.getLength())
1786 // set properties
1787 uno::Reference< beans::XPropertySet > xProp;
1788 switch( meContextType )
1790 case CONTEXT_TYPE_GAIN:
1791 xProp = mxStockPropProvider->getUpBar();
1792 break;
1793 case CONTEXT_TYPE_LOSS:
1794 xProp = mxStockPropProvider->getDownBar();
1795 break;
1796 case CONTEXT_TYPE_RANGE:
1797 xProp = mxStockPropProvider->getMinMaxLine();
1798 break;
1800 if( xProp.is())
1802 const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
1803 if( pStylesCtxt )
1805 const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
1806 mrImportHelper.GetChartFamilyID(), sAutoStyleName );
1808 if( pStyle && pStyle->ISA( XMLPropStyleContext ))
1809 (( XMLPropStyleContext* )pStyle )->FillPropertySet( xProp );
1816 // ========================================
1818 SchXMLStatisticsObjectContext::SchXMLStatisticsObjectContext(
1820 SchXMLImportHelper& rImpHelper,
1821 SvXMLImport& rImport,
1822 sal_uInt16 nPrefix,
1823 const rtl::OUString& rLocalName,
1824 ::std::list< DataRowPointStyle >& rStyleList,
1825 const ::com::sun::star::uno::Reference<
1826 ::com::sun::star::chart2::XDataSeries >& xSeries,
1827 ContextType eContextType,
1828 const awt::Size & rChartSize ) :
1830 SvXMLImportContext( rImport, nPrefix, rLocalName ),
1831 mrImportHelper( rImpHelper ),
1832 mrStyleList( rStyleList ),
1833 m_xSeries( xSeries ),
1834 meContextType( eContextType ),
1835 maChartSize( rChartSize )
1838 SchXMLStatisticsObjectContext::~SchXMLStatisticsObjectContext()
1842 void SchXMLStatisticsObjectContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
1844 sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
1845 ::rtl::OUString aValue;
1846 ::rtl::OUString sAutoStyleName;
1848 for( sal_Int16 i = 0; i < nAttrCount; i++ )
1850 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
1851 rtl::OUString aLocalName;
1852 USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
1854 if( nPrefix == XML_NAMESPACE_CHART )
1856 if( IsXMLToken( aLocalName, XML_STYLE_NAME ) )
1857 sAutoStyleName = xAttrList->getValueByIndex( i );
1861 // note: regression-curves must get a style-object even if there is no
1862 // auto-style set, because they can contain an equation
1863 if( sAutoStyleName.getLength() || meContextType == CONTEXT_TYPE_REGRESSION_CURVE )
1865 DataRowPointStyle::StyleType eType = DataRowPointStyle::MEAN_VALUE;
1866 switch( meContextType )
1868 case CONTEXT_TYPE_MEAN_VALUE_LINE:
1869 eType = DataRowPointStyle::MEAN_VALUE;
1870 break;
1871 case CONTEXT_TYPE_REGRESSION_CURVE:
1872 eType = DataRowPointStyle::REGRESSION;
1873 break;
1874 case CONTEXT_TYPE_ERROR_INDICATOR:
1875 eType = DataRowPointStyle::ERROR_INDICATOR;
1876 break;
1878 DataRowPointStyle aStyle(
1879 eType, m_xSeries, -1, 1, sAutoStyleName );
1880 mrStyleList.push_back( aStyle );
1884 SvXMLImportContext* SchXMLStatisticsObjectContext::CreateChildContext(
1885 USHORT nPrefix,
1886 const rtl::OUString& rLocalName,
1887 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
1889 SvXMLImportContext* pContext = 0;
1891 if( nPrefix == XML_NAMESPACE_CHART &&
1892 IsXMLToken( rLocalName, XML_EQUATION ) )
1894 pContext = new SchXMLEquationContext(
1895 mrImportHelper, GetImport(), nPrefix, rLocalName, m_xSeries, maChartSize, mrStyleList.back());
1897 else
1899 pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
1902 return pContext;
1905 // ========================================
1907 SchXMLEquationContext::SchXMLEquationContext(
1908 SchXMLImportHelper& rImpHelper,
1909 SvXMLImport& rImport,
1910 sal_uInt16 nPrefix,
1911 const rtl::OUString& rLocalName,
1912 const ::com::sun::star::uno::Reference<
1913 ::com::sun::star::chart2::XDataSeries >& xSeries,
1914 const awt::Size & rChartSize,
1915 DataRowPointStyle & rRegressionStyle ) :
1916 SvXMLImportContext( rImport, nPrefix, rLocalName ),
1917 mrImportHelper( rImpHelper ),
1918 mrRegressionStyle( rRegressionStyle ),
1919 m_xSeries( xSeries ),
1920 maChartSize( rChartSize )
1923 SchXMLEquationContext::~SchXMLEquationContext()
1926 void SchXMLEquationContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
1928 // parse attributes
1929 sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
1930 SchXMLImport& rImport = ( SchXMLImport& )GetImport();
1931 const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetRegEquationAttrTokenMap();
1932 OUString sAutoStyleName;
1934 sal_Bool bShowEquation = sal_True;
1935 sal_Bool bShowRSquare = sal_False;
1936 awt::Point aPosition;
1937 bool bHasXPos = false;
1938 bool bHasYPos = false;
1940 for( sal_Int16 i = 0; i < nAttrCount; i++ )
1942 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
1943 rtl::OUString aLocalName;
1944 rtl::OUString aValue = xAttrList->getValueByIndex( i );
1945 USHORT nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
1947 switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
1949 case XML_TOK_REGEQ_POS_X:
1950 rImport.GetMM100UnitConverter().convertMeasure( aPosition.X, aValue );
1951 bHasXPos = true;
1952 break;
1953 case XML_TOK_REGEQ_POS_Y:
1954 rImport.GetMM100UnitConverter().convertMeasure( aPosition.Y, aValue );
1955 bHasYPos = true;
1956 break;
1957 case XML_TOK_REGEQ_DISPLAY_EQUATION:
1958 rImport.GetMM100UnitConverter().convertBool( bShowEquation, aValue );
1959 break;
1960 case XML_TOK_REGEQ_DISPLAY_R_SQUARE:
1961 rImport.GetMM100UnitConverter().convertBool( bShowRSquare, aValue );
1962 break;
1963 case XML_TOK_REGEQ_STYLE_NAME:
1964 sAutoStyleName = aValue;
1965 break;
1969 if( sAutoStyleName.getLength() || bShowEquation || bShowRSquare )
1971 uno::Reference< beans::XPropertySet > xEqProp;
1972 uno::Reference< lang::XMultiServiceFactory > xFact( comphelper::getProcessServiceFactory(), uno::UNO_QUERY );
1973 if( xFact.is())
1974 xEqProp.set( xFact->createInstance(
1975 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.RegressionEquation" ))), uno::UNO_QUERY );
1976 if( xEqProp.is())
1978 if( sAutoStyleName.getLength() )
1980 const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
1981 if( pStylesCtxt )
1983 const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
1984 mrImportHelper.GetChartFamilyID(), sAutoStyleName );
1985 // note: SvXMLStyleContext::FillPropertySet is not const
1986 XMLPropStyleContext * pPropStyleContext =
1987 const_cast< XMLPropStyleContext * >( dynamic_cast< const XMLPropStyleContext * >( pStyle ));
1989 if( pPropStyleContext )
1990 pPropStyleContext->FillPropertySet( xEqProp );
1993 xEqProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("ShowEquation")), uno::makeAny( bShowEquation ));
1994 xEqProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("ShowCorrelationCoefficient")), uno::makeAny( bShowRSquare ));
1996 if( bHasXPos && bHasYPos )
1998 chart2::RelativePosition aRelPos;
1999 aRelPos.Primary = static_cast< double >( aPosition.X ) / static_cast< double >( maChartSize.Width );
2000 aRelPos.Secondary = static_cast< double >( aPosition.Y ) / static_cast< double >( maChartSize.Height );
2001 xEqProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "RelativePosition" )),
2002 uno::makeAny( aRelPos ));
2004 OSL_ASSERT( mrRegressionStyle.meType == DataRowPointStyle::REGRESSION );
2005 mrRegressionStyle.m_xEquationProperties.set( xEqProp );