00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "precompiled_xmloff.hxx"
00030
00031 #include "SchXMLPlotAreaContext.hxx"
00032 #include "SchXMLImport.hxx"
00033 #include "SchXMLSeries2Context.hxx"
00034 #include "SchXMLTools.hxx"
00035 #include <tools/debug.hxx>
00036 #ifdef DBG_UTIL
00037 #include <tools/string.hxx>
00038 #endif
00039
00040 #include <comphelper/processfactory.hxx>
00041 #include "xmlnmspe.hxx"
00042 #include <xmloff/xmltoken.hxx>
00043 #include <xmloff/xmlement.hxx>
00044 #include <xmloff/nmspmap.hxx>
00045 #include <xmloff/xmluconv.hxx>
00046 #include <xmloff/prstylei.hxx>
00047 #include <xmloff/xmlstyle.hxx>
00048 #include "xexptran.hxx"
00049 #include <cppuhelper/implbase1.hxx>
00050
00051 #include <com/sun/star/awt/Point.hpp>
00052 #include <com/sun/star/awt/Size.hpp>
00053
00054 #include <com/sun/star/chart/ChartAxisLabelPosition.hpp>
00055 #include <com/sun/star/chart/ChartAxisMarkPosition.hpp>
00056 #include <com/sun/star/chart/ChartAxisPosition.hpp>
00057 #include <com/sun/star/chart/XTwoAxisXSupplier.hpp>
00058 #include <com/sun/star/chart/XTwoAxisYSupplier.hpp>
00059 #include <com/sun/star/chart/XAxisZSupplier.hpp>
00060 #include <com/sun/star/chart/XSecondAxisTitleSupplier.hpp>
00061 #include <com/sun/star/chart/ChartDataRowSource.hpp>
00062 #include <com/sun/star/chart/X3DDisplay.hpp>
00063 #include <com/sun/star/chart/XStatisticDisplay.hpp>
00064
00065 #include <com/sun/star/chart2/XChartDocument.hpp>
00066 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
00067 #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
00068 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
00069 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
00070 #include <com/sun/star/chart2/AxisType.hpp>
00071 #include <com/sun/star/chart2/RelativePosition.hpp>
00072
00073 #include <com/sun/star/drawing/CameraGeometry.hpp>
00074 #include <com/sun/star/drawing/FillStyle.hpp>
00075 #include <com/sun/star/drawing/LineStyle.hpp>
00076 #include <com/sun/star/lang/XServiceInfo.hpp>
00077 #include <com/sun/star/util/XStringMapping.hpp>
00078 #include <com/sun/star/xml/sax/XAttributeList.hpp>
00079
00080 using namespace com::sun::star;
00081 using namespace ::xmloff::token;
00082
00083 using ::rtl::OUString;
00084 using com::sun::star::uno::Reference;
00085
00086 static __FAR_DATA SvXMLEnumMapEntry aXMLAxisClassMap[] =
00087 {
00088 { XML_X, SCH_XML_AXIS_X },
00089 { XML_Y, SCH_XML_AXIS_Y },
00090 { XML_Z, SCH_XML_AXIS_Z },
00091 { XML_TOKEN_INVALID, 0 }
00092 };
00093
00094 namespace
00095 {
00096
00097 struct lcl_AxisHasCategories : public ::std::unary_function< SchXMLAxis, bool >
00098 {
00099 bool operator() ( const SchXMLAxis & rAxis )
00100 {
00101 return rAxis.bHasCategories;
00102 }
00103 };
00104
00105 OUString lcl_ConvertRange( const ::rtl::OUString & rRange, const uno::Reference< chart2::XChartDocument > & xDoc )
00106 {
00107 OUString aResult = rRange;
00108 if(!xDoc.is())
00109 return aResult;
00110 uno::Reference< chart2::data::XRangeXMLConversion > xConversion(
00111 xDoc->getDataProvider(), uno::UNO_QUERY );
00112 if( xConversion.is())
00113 aResult = xConversion->convertRangeFromXML( rRange );
00114 return aResult;
00115 }
00116
00117 Reference< chart2::XAxis > lcl_getAxis( const Reference< chart2::XCoordinateSystem > xCooSys, sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
00118 {
00119 Reference< chart2::XAxis > xAxis;
00120 try
00121 {
00122 xAxis = xCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex );
00123 }
00124 catch( uno::Exception & )
00125 {
00126 }
00127 return xAxis;
00128 }
00129
00130 }
00131
00132 SchXML3DSceneAttributesHelper::SchXML3DSceneAttributesHelper( SvXMLImport& rImporter )
00133 : SdXML3DSceneAttributesHelper( rImporter )
00134 {
00135 }
00136
00137 void SchXML3DSceneAttributesHelper::getCameraDefaultFromDiagram( const uno::Reference< chart::XDiagram >& xDiagram )
00138 {
00139
00140
00141
00142 try
00143 {
00144 uno::Reference< beans::XPropertySet > xProp( xDiagram, uno::UNO_QUERY );
00145 if( xProp.is() )
00146 {
00147 drawing::CameraGeometry aCamGeo;
00148 xProp->getPropertyValue( ::rtl::OUString::createFromAscii("D3DCameraGeometry")) >>= aCamGeo;
00149 maVRP.setX( aCamGeo.vrp.PositionX );
00150 maVRP.setY( aCamGeo.vrp.PositionY );
00151 maVRP.setZ( aCamGeo.vrp.PositionZ );
00152 maVPN.setX( aCamGeo.vpn.DirectionX );
00153 maVPN.setY( aCamGeo.vpn.DirectionY );
00154 maVPN.setZ( aCamGeo.vpn.DirectionZ );
00155 maVUP.setX( aCamGeo.vup.DirectionX );
00156 maVUP.setY( aCamGeo.vup.DirectionY );
00157 maVUP.setZ( aCamGeo.vup.DirectionZ );
00158 }
00159 }
00160 catch( uno::Exception & rEx )
00161 {
00162 #ifdef DBG_UTIL
00163 String aStr( rEx.Message );
00164 ByteString aBStr( aStr, RTL_TEXTENCODING_ASCII_US );
00165 DBG_ERROR1( "Exception caught for property NumberOfLines: %s", aBStr.GetBuffer());
00166 #else
00167 (void)rEx;
00168 #endif
00169 }
00170 }
00171
00172 SchXML3DSceneAttributesHelper::~SchXML3DSceneAttributesHelper()
00173 {
00174 }
00175
00176 SchXMLPlotAreaContext::SchXMLPlotAreaContext(
00177 SchXMLImportHelper& rImpHelper,
00178 SvXMLImport& rImport, const rtl::OUString& rLocalName,
00179 const rtl::OUString& rXLinkHRefAttributeToIndicateDataProvider,
00180 uno::Sequence< chart::ChartSeriesAddress >& rSeriesAddresses,
00181 ::rtl::OUString& rCategoriesAddress,
00182 ::rtl::OUString& rChartAddress,
00183 bool& rbHasRangeAtPlotArea,
00184 sal_Bool & rAllRangeAddressesAvailable,
00185 sal_Bool & rColHasLabels,
00186 sal_Bool & rRowHasLabels,
00187 chart::ChartDataRowSource & rDataRowSource,
00188 SeriesDefaultsAndStyles& rSeriesDefaultsAndStyles,
00189 const ::rtl::OUString& aChartTypeServiceName,
00190 tSchXMLLSequencesPerIndex & rLSequencesPerIndex,
00191 const awt::Size & rChartSize ) :
00192 SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ),
00193 mrImportHelper( rImpHelper ),
00194 mrSeriesAddresses( rSeriesAddresses ),
00195 mrCategoriesAddress( rCategoriesAddress ),
00196 mrSeriesDefaultsAndStyles( rSeriesDefaultsAndStyles ),
00197 mnNumOfLinesProp( 0 ),
00198 mbStockHasVolume( sal_False ),
00199 mnSeries( 0 ),
00200 m_aGlobalSeriesImportInfo( rAllRangeAddressesAvailable ),
00201 maSceneImportHelper( rImport ),
00202 mbHasSize(false),
00203 mbHasPosition(false),
00204 mbPercentStacked(false),
00205 m_bAxisPositionAttributeImported(false),
00206 m_rXLinkHRefAttributeToIndicateDataProvider(rXLinkHRefAttributeToIndicateDataProvider),
00207 mrChartAddress( rChartAddress ),
00208 m_rbHasRangeAtPlotArea( rbHasRangeAtPlotArea ),
00209 mrColHasLabels( rColHasLabels ),
00210 mrRowHasLabels( rRowHasLabels ),
00211 mrDataRowSource( rDataRowSource ),
00212 maChartTypeServiceName( aChartTypeServiceName ),
00213 mrLSequencesPerIndex( rLSequencesPerIndex ),
00214 mbGlobalChartTypeUsedBySeries( false ),
00215 maChartSize( rChartSize )
00216 {
00217 m_rbHasRangeAtPlotArea = false;
00218
00219
00220 uno::Reference< chart::XChartDocument > xDoc( rImpHelper.GetChartDocument(), uno::UNO_QUERY );
00221 if( xDoc.is())
00222 {
00223 mxDiagram = xDoc->getDiagram();
00224 mxNewDoc.set( xDoc, uno::UNO_QUERY );
00225
00226 maSceneImportHelper.getCameraDefaultFromDiagram( mxDiagram );
00227 }
00228 DBG_ASSERT( mxDiagram.is(), "Couldn't get XDiagram" );
00229
00230
00231 uno::Any aFalseBool;
00232 aFalseBool <<= (sal_Bool)(sal_False);
00233
00234 uno::Reference< lang::XServiceInfo > xInfo( mxDiagram, uno::UNO_QUERY );
00235 uno::Reference< beans::XPropertySet > xProp( mxDiagram, uno::UNO_QUERY );
00236 if( xInfo.is() &&
00237 xProp.is())
00238 {
00239 try
00240 {
00241 if( xInfo->supportsService( rtl::OUString::createFromAscii( "com.sun.star.chart.ChartAxisXSupplier" )))
00242 {
00243 xProp->setPropertyValue(
00244 rtl::OUString::createFromAscii( "HasXAxis" ), aFalseBool );
00245 xProp->setPropertyValue(
00246 rtl::OUString::createFromAscii( "HasXAxisGrid" ), aFalseBool );
00247 xProp->setPropertyValue(
00248 rtl::OUString::createFromAscii( "HasXAxisDescription" ), aFalseBool );
00249 }
00250 if( xInfo->supportsService( rtl::OUString::createFromAscii( "com.sun.star.chart.ChartTwoAxisXSupplier" )))
00251 {
00252 xProp->setPropertyValue(
00253 rtl::OUString::createFromAscii( "HasSecondaryXAxis" ), aFalseBool );
00254 xProp->setPropertyValue(
00255 rtl::OUString::createFromAscii( "HasSecondaryXAxisDescription" ), aFalseBool );
00256 }
00257
00258 if( xInfo->supportsService( rtl::OUString::createFromAscii( "com.sun.star.chart.ChartAxisYSupplier" )))
00259 {
00260 xProp->setPropertyValue(
00261 rtl::OUString::createFromAscii( "HasYAxis" ), aFalseBool );
00262 xProp->setPropertyValue(
00263 rtl::OUString::createFromAscii( "HasYAxisGrid" ), aFalseBool );
00264 xProp->setPropertyValue(
00265 rtl::OUString::createFromAscii( "HasYAxisDescription" ), aFalseBool );
00266 }
00267 if( xInfo->supportsService( rtl::OUString::createFromAscii( "com.sun.star.chart.ChartTwoAxisYSupplier" )))
00268 {
00269 xProp->setPropertyValue(
00270 rtl::OUString::createFromAscii( "HasSecondaryYAxis" ), aFalseBool );
00271 xProp->setPropertyValue(
00272 rtl::OUString::createFromAscii( "HasSecondaryYAxisDescription" ), aFalseBool );
00273 }
00274
00275 if( xInfo->supportsService( rtl::OUString::createFromAscii( "com.sun.star.chart.ChartAxisZSupplier" )))
00276 {
00277 xProp->setPropertyValue(
00278 rtl::OUString::createFromAscii( "HasZAxis" ), aFalseBool );
00279 xProp->setPropertyValue(
00280 rtl::OUString::createFromAscii( "HasZAxisDescription" ), aFalseBool );
00281 }
00282 uno::Any aAny;
00283 chart::ChartDataRowSource eSource = chart::ChartDataRowSource_COLUMNS;
00284 aAny <<= eSource;
00285 xProp->setPropertyValue( rtl::OUString::createFromAscii( "DataRowSource" ), aAny );
00286 }
00287 catch( beans::UnknownPropertyException & )
00288 {
00289 DBG_ERROR( "Property required by service not supported" );
00290 }
00291 }
00292 }
00293
00294 SchXMLPlotAreaContext::~SchXMLPlotAreaContext()
00295 {}
00296
00297 void SchXMLPlotAreaContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
00298 {
00299 uno::Any aTransMatrixAny;
00300
00301
00302 uno::Reference< drawing::XShape > xDiaShape( mxDiagram, uno::UNO_QUERY );
00303 bool bHasSizeWidth = false;
00304 bool bHasSizeHeight = false;
00305 bool bHasPositionX = false;
00306 bool bHasPositionY = false;
00307
00308
00309 sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
00310 const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetPlotAreaAttrTokenMap();
00311 uno::Reference< chart2::XChartDocument > xNewDoc( GetImport().GetModel(), uno::UNO_QUERY );
00312
00313 for( sal_Int16 i = 0; i < nAttrCount; i++ )
00314 {
00315 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
00316 rtl::OUString aLocalName;
00317 rtl::OUString aValue = xAttrList->getValueByIndex( i );
00318 USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
00319
00320 switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
00321 {
00322 case XML_TOK_PA_X:
00323 GetImport().GetMM100UnitConverter().convertMeasure( maPosition.X, aValue );
00324 bHasPositionX = true;
00325 break;
00326 case XML_TOK_PA_Y:
00327 GetImport().GetMM100UnitConverter().convertMeasure( maPosition.Y, aValue );
00328 bHasPositionY = true;
00329 break;
00330 case XML_TOK_PA_WIDTH:
00331 GetImport().GetMM100UnitConverter().convertMeasure( maSize.Width, aValue );
00332 bHasSizeWidth = true;
00333 break;
00334 case XML_TOK_PA_HEIGHT:
00335 GetImport().GetMM100UnitConverter().convertMeasure( maSize.Height, aValue );
00336 bHasSizeHeight = true;
00337 break;
00338 case XML_TOK_PA_STYLE_NAME:
00339 msAutoStyleName = aValue;
00340 break;
00341 case XML_TOK_PA_CHART_ADDRESS:
00342 mrChartAddress = lcl_ConvertRange( aValue, xNewDoc );
00343
00344 m_rbHasRangeAtPlotArea = true;
00345 break;
00346 case XML_TOK_PA_DS_HAS_LABELS:
00347 {
00348 if( aValue.equals( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_BOTH )))
00349 mrColHasLabels = mrRowHasLabels = sal_True;
00350 else if( aValue.equals( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_ROW )))
00351 mrRowHasLabels = sal_True;
00352 else if( aValue.equals( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_COLUMN )))
00353 mrColHasLabels = sal_True;
00354 }
00355 break;
00356 case XML_TOK_PA_TRANSFORM:
00357 case XML_TOK_PA_VRP:
00358 case XML_TOK_PA_VPN:
00359 case XML_TOK_PA_VUP:
00360 case XML_TOK_PA_PROJECTION:
00361 case XML_TOK_PA_DISTANCE:
00362 case XML_TOK_PA_FOCAL_LENGTH:
00363 case XML_TOK_PA_SHADOW_SLANT:
00364 case XML_TOK_PA_SHADE_MODE:
00365 case XML_TOK_PA_AMBIENT_COLOR:
00366 case XML_TOK_PA_LIGHTING_MODE:
00367 maSceneImportHelper.processSceneAttribute( nPrefix, aLocalName, aValue );
00368 break;
00369 }
00370 }
00371
00372 mbHasSize = bHasSizeWidth && bHasSizeHeight;
00373 mbHasPosition = bHasPositionX && bHasPositionY;
00374
00375 if( ! mxNewDoc.is())
00376 {
00377 uno::Reference< beans::XPropertySet > xDocProp( mrImportHelper.GetChartDocument(), uno::UNO_QUERY );
00378 if( xDocProp.is())
00379 {
00380 try
00381 {
00382 uno::Any aAny;
00383 aAny <<= (sal_Bool)(mrColHasLabels);
00384 xDocProp->setPropertyValue(
00385 ::rtl::OUString::createFromAscii( "DataSourceLabelsInFirstColumn" ),
00386 aAny );
00387
00388 aAny <<= (sal_Bool)(mrRowHasLabels);
00389 xDocProp->setPropertyValue(
00390 ::rtl::OUString::createFromAscii( "DataSourceLabelsInFirstRow" ),
00391 aAny );
00392 }
00393 catch( beans::UnknownPropertyException & )
00394 {
00395 DBG_ERRORFILE( "Properties missing" );
00396 }
00397 }
00398 }
00399
00400
00401 uno::Reference< beans::XPropertySet > xProp( mxDiagram, uno::UNO_QUERY );
00402 if( msAutoStyleName.getLength())
00403 {
00404 if( xProp.is())
00405 {
00406 const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
00407 if( pStylesCtxt )
00408 {
00409 const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
00410 mrImportHelper.GetChartFamilyID(), msAutoStyleName );
00411
00412 XMLPropStyleContext* pPropStyleContext =
00413 const_cast< XMLPropStyleContext * >(
00414 dynamic_cast< const XMLPropStyleContext * >( pStyle ) );
00415 if( pPropStyleContext )
00416 {
00417 pPropStyleContext->FillPropertySet( xProp );
00418
00419
00420 xProp->getPropertyValue( ::rtl::OUString::createFromAscii("DataRowSource"))
00421 >>= mrDataRowSource;
00422
00423
00424
00425 mrSeriesDefaultsAndStyles.maLinesOnProperty = SchXMLTools::getPropertyFromContext(
00426 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Lines")), pPropStyleContext, pStylesCtxt );
00427
00428
00429 bool bAutoSize = false;
00430 bool bAutoPosition = false;
00431 SchXMLTools::getPropertyFromContext(
00432 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AutomaticSize")), pPropStyleContext, pStylesCtxt ) >>= bAutoSize;
00433 SchXMLTools::getPropertyFromContext(
00434 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AutomaticPosition")), pPropStyleContext, pStylesCtxt ) >>= bAutoPosition;
00435 mbHasSize = mbHasSize && !bAutoSize;
00436 mbHasPosition = mbHasPosition && !bAutoPosition;
00437
00438
00439 if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan3_0( GetImport().GetModel() ) )
00440 {
00441 bool bIs3d = false;
00442 if( xProp.is() && ( xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Dim3D"))) >>= bIs3d ) &&
00443 bIs3d )
00444 {
00445 if( maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.PieChartType" ))
00446 || maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.DonutChartType" )) )
00447 {
00448 ::rtl::OUString aPropName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StartingAngle")) );
00449 uno::Any aAStartingAngle( SchXMLTools::getPropertyFromContext( aPropName, pPropStyleContext, pStylesCtxt ) );
00450 if( !aAStartingAngle.hasValue() )
00451 xProp->setPropertyValue( aPropName, uno::makeAny(sal_Int32(0)) ) ;
00452 }
00453 }
00454 }
00455 }
00456 }
00457 }
00458 }
00459
00460
00461 if(xProp.is())
00462 try
00463 {
00464 mrSeriesDefaultsAndStyles.maSymbolTypeDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SymbolType")));
00465 mrSeriesDefaultsAndStyles.maDataCaptionDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataCaption")));
00466
00467 mrSeriesDefaultsAndStyles.maErrorIndicatorDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ErrorIndicator")));
00468 mrSeriesDefaultsAndStyles.maErrorCategoryDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ErrorCategory")));
00469 mrSeriesDefaultsAndStyles.maConstantErrorLowDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ConstantErrorLow")));
00470 mrSeriesDefaultsAndStyles.maConstantErrorHighDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ConstantErrorHigh")));
00471 mrSeriesDefaultsAndStyles.maPercentageErrorDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PercentageError")));
00472 mrSeriesDefaultsAndStyles.maErrorMarginDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ErrorMargin")));
00473
00474 mrSeriesDefaultsAndStyles.maMeanValueDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MeanValue")));
00475 mrSeriesDefaultsAndStyles.maRegressionCurvesDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RegressionCurves")));
00476
00477 bool bStacked = false;
00478 mrSeriesDefaultsAndStyles.maStackedDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Stacked")));
00479 mrSeriesDefaultsAndStyles.maStackedDefault >>= bStacked;
00480 mrSeriesDefaultsAndStyles.maPercentDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Percent")));
00481 mrSeriesDefaultsAndStyles.maPercentDefault >>= mbPercentStacked;
00482 mrSeriesDefaultsAndStyles.maStackedBarsConnectedDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StackedBarsConnected")));
00483
00484
00485 uno::Any aDeepProperty( xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Deep"))));
00486
00487 if( ! (bStacked || mbPercentStacked ))
00488 {
00489 if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan2_3( GetImport().GetModel() ) )
00490 {
00491 bool bIs3d = false;
00492 if( ( xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Dim3D"))) >>= bIs3d ) &&
00493 bIs3d )
00494 {
00495 if( maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.AreaChartType" )) ||
00496 maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.LineChartType" )) )
00497 {
00498 aDeepProperty <<= uno::makeAny( true );
00499 }
00500 }
00501 }
00502 }
00503 mrSeriesDefaultsAndStyles.maDeepDefault = aDeepProperty;
00504
00505 xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NumberOfLines"))) >>= mnNumOfLinesProp;
00506 xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Volume"))) >>= mbStockHasVolume;
00507 }
00508 catch( uno::Exception & rEx )
00509 {
00510 #ifdef DBG_UTIL
00511 String aStr( rEx.Message );
00512 ByteString aBStr( aStr, RTL_TEXTENCODING_ASCII_US );
00513 DBG_ERROR1( "PlotAreaContext:EndElement(): Exception caught: %s", aBStr.GetBuffer());
00514 #else
00515 (void)rEx;
00516 #endif
00517 }
00518
00519
00520 bool bCreateInternalDataProvider = false;
00521 if( m_rXLinkHRefAttributeToIndicateDataProvider.equalsAscii( "." ) )
00522 bCreateInternalDataProvider = true;
00523 else if( m_rXLinkHRefAttributeToIndicateDataProvider.equalsAscii( ".." ) )
00524 bCreateInternalDataProvider = false;
00525 else if( m_rXLinkHRefAttributeToIndicateDataProvider.getLength() )
00526 bCreateInternalDataProvider = true;
00527 else if( !m_rbHasRangeAtPlotArea )
00528 bCreateInternalDataProvider = true;
00529
00530 if( bCreateInternalDataProvider && mxNewDoc.is() )
00531 {
00532
00533
00534
00535 mxNewDoc->createInternalDataProvider( false );
00536 if( xProp.is() && mrDataRowSource!=chart::ChartDataRowSource_COLUMNS )
00537 xProp->setPropertyValue( rtl::OUString::createFromAscii( "DataRowSource" ), uno::makeAny(mrDataRowSource) );
00538 }
00539 }
00540
00541 SvXMLImportContext* SchXMLPlotAreaContext::CreateChildContext(
00542 USHORT nPrefix,
00543 const rtl::OUString& rLocalName,
00544 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
00545 {
00546 SvXMLImportContext* pContext = 0;
00547 const SvXMLTokenMap& rTokenMap = mrImportHelper.GetPlotAreaElemTokenMap();
00548
00549 switch( rTokenMap.Get( nPrefix, rLocalName ))
00550 {
00551 case XML_TOK_PA_AXIS:
00552 {
00553 bool bAddMissingXAxisForNetCharts = false;
00554 bool bAdaptWrongPercentScaleValues = false;
00555 if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan2_3( GetImport().GetModel() ) )
00556 {
00557
00558
00559
00560
00561 if( maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.NetChartType" )) )
00562 bAddMissingXAxisForNetCharts = true;
00563
00564
00565 if( mbPercentStacked )
00566 bAdaptWrongPercentScaleValues = true;
00567 }
00568
00569 bool bAdaptXAxisOrientationForOld2DBarCharts = false;
00570 if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan2_4( GetImport().GetModel() ) )
00571 {
00572
00573 if( maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.ColumnChartType" )) )
00574 bAdaptXAxisOrientationForOld2DBarCharts = true;
00575 }
00576
00577 pContext = new SchXMLAxisContext( mrImportHelper, GetImport(), rLocalName, mxDiagram, maAxes, mrCategoriesAddress,
00578 bAddMissingXAxisForNetCharts, bAdaptWrongPercentScaleValues, bAdaptXAxisOrientationForOld2DBarCharts, m_bAxisPositionAttributeImported );
00579 }
00580 break;
00581
00582 case XML_TOK_PA_SERIES:
00583 {
00584 if( mxNewDoc.is())
00585 {
00586 pContext = new SchXMLSeries2Context(
00587 mrImportHelper, GetImport(), rLocalName,
00588 mxNewDoc, maAxes,
00589 mrSeriesDefaultsAndStyles.maSeriesStyleList,
00590 mnSeries,
00591 mbStockHasVolume,
00592 m_aGlobalSeriesImportInfo,
00593 maChartTypeServiceName,
00594 mrLSequencesPerIndex,
00595 mbGlobalChartTypeUsedBySeries, maChartSize );
00596 }
00597 mnSeries++;
00598 }
00599 break;
00600
00601 case XML_TOK_PA_WALL:
00602 pContext = new SchXMLWallFloorContext( mrImportHelper, GetImport(), nPrefix, rLocalName, mxDiagram,
00603 SchXMLWallFloorContext::CONTEXT_TYPE_WALL );
00604 break;
00605 case XML_TOK_PA_FLOOR:
00606 pContext = new SchXMLWallFloorContext( mrImportHelper, GetImport(), nPrefix, rLocalName, mxDiagram,
00607 SchXMLWallFloorContext::CONTEXT_TYPE_FLOOR );
00608 break;
00609
00610 case XML_TOK_PA_LIGHT_SOURCE:
00611 pContext = maSceneImportHelper.create3DLightContext( nPrefix, rLocalName, xAttrList );
00612 break;
00613
00614
00615 case XML_TOK_PA_STOCK_GAIN:
00616 pContext = new SchXMLStockContext( mrImportHelper, GetImport(), nPrefix, rLocalName, mxDiagram,
00617 SchXMLStockContext::CONTEXT_TYPE_GAIN );
00618 break;
00619 case XML_TOK_PA_STOCK_LOSS:
00620 pContext = new SchXMLStockContext( mrImportHelper, GetImport(), nPrefix, rLocalName, mxDiagram,
00621 SchXMLStockContext::CONTEXT_TYPE_LOSS );
00622 break;
00623 case XML_TOK_PA_STOCK_RANGE:
00624 pContext = new SchXMLStockContext( mrImportHelper, GetImport(), nPrefix, rLocalName, mxDiagram,
00625 SchXMLStockContext::CONTEXT_TYPE_RANGE );
00626 break;
00627
00628 default:
00629 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
00630 }
00631
00632 return pContext;
00633 }
00634
00635 void SchXMLPlotAreaContext::EndElement()
00636 {
00637
00638 if( mrCategoriesAddress.getLength() && mxNewDoc.is())
00639 {
00640 uno::Reference< chart2::data::XDataProvider > xDataProvider(
00641 mxNewDoc->getDataProvider() );
00642
00643 sal_Int32 nDimension( 0 );
00644 ::std::vector< SchXMLAxis >::const_iterator aIt(
00645 ::std::find_if( maAxes.begin(), maAxes.end(), lcl_AxisHasCategories()));
00646 if( aIt != maAxes.end())
00647 nDimension = static_cast< sal_Int32 >( (*aIt).eClass );
00648 SchXMLTools::CreateCategories(
00649 xDataProvider, mxNewDoc, mrCategoriesAddress,
00650 0 ,
00651 nDimension, &mrLSequencesPerIndex );
00652 }
00653
00654 uno::Reference< beans::XPropertySet > xDiaProp( mxDiagram, uno::UNO_QUERY );
00655 if( xDiaProp.is())
00656 {
00657 sal_Bool bIsThreeDim = sal_False;
00658 uno::Any aAny = xDiaProp->getPropertyValue( ::rtl::OUString::createFromAscii( "Dim3D" ));
00659 aAny >>= bIsThreeDim;
00660
00661
00662 if( bIsThreeDim )
00663 {
00664
00665 maSceneImportHelper.setSceneAttributes( xDiaProp );
00666 }
00667
00668
00669 if( ! m_aGlobalSeriesImportInfo.rbAllRangeAddressesAvailable &&
00670 mnNumOfLinesProp > 0 &&
00671 maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.ColumnChartType" )))
00672 {
00673 try
00674 {
00675 xDiaProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "NumberOfLines" )),
00676 uno::makeAny( mnNumOfLinesProp ));
00677 }
00678 catch( uno::Exception & rEx )
00679 {
00680 #ifdef DBG_UTIL
00681 String aStr( rEx.Message );
00682 ByteString aBStr( aStr, RTL_TEXTENCODING_ASCII_US );
00683 DBG_ERROR1( "Exception caught for property NumberOfLines: %s", aBStr.GetBuffer());
00684 #else
00685 (void)rEx;
00686 #endif
00687 }
00688 }
00689
00690
00691 if( ( 0 == mxDiagram->getDiagramType().reverseCompareToAsciiL(
00692 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart.StockDiagram" ))) &&
00693 mbStockHasVolume )
00694 {
00695 try
00696 {
00697 xDiaProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Volume" )),
00698 uno::makeAny( true ));
00699 }
00700 catch( uno::Exception & rEx )
00701 {
00702 #ifdef DBG_UTIL
00703 String aStr( rEx.Message );
00704 ByteString aBStr( aStr, RTL_TEXTENCODING_ASCII_US );
00705 DBG_ERROR1( "Exception caught for property Volume: %s", aBStr.GetBuffer());
00706 #else
00707 (void)rEx;
00708 #endif
00709 }
00710 }
00711 }
00712
00713
00714 uno::Reference< drawing::XShape > xDiaShape( mxDiagram, uno::UNO_QUERY );
00715 if( xDiaShape.is())
00716 {
00717 if( mbHasSize )
00718 xDiaShape->setSize( maSize );
00719 if( mbHasPosition )
00720 xDiaShape->setPosition( maPosition );
00721 }
00722
00723 CorrectAxisPositions();
00724 }
00725
00726 void SchXMLPlotAreaContext::CorrectAxisPositions()
00727 {
00728 ::rtl::OUString aODFVersionOfFile( GetImport().GetODFVersion() );
00729
00730 if( ( !aODFVersionOfFile.getLength() || aODFVersionOfFile.equalsAscii("1.0")
00731 || aODFVersionOfFile.equalsAscii("1.1")
00732 || ( aODFVersionOfFile.equalsAscii("1.2") && !m_bAxisPositionAttributeImported ) ) )
00733 {
00734 uno::Reference< chart2::XChartDocument > xNewDoc( mrImportHelper.GetChartDocument(), uno::UNO_QUERY );
00735
00736 try
00737 {
00738 Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xNewDoc->getFirstDiagram(), uno::UNO_QUERY_THROW );
00739 uno::Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems());
00740 if( aCooSysSeq.getLength() )
00741 {
00742 Reference< chart2::XCoordinateSystem > xCooSys( aCooSysSeq[0] );
00743 if( xCooSys.is() )
00744 {
00745 Reference< chart2::XAxis > xMainXAxis = lcl_getAxis( xCooSys, 0, 0 );
00746 Reference< chart2::XAxis > xMainYAxis = lcl_getAxis( xCooSys, 1, 0 );
00747
00748 Reference< chart2::XAxis > xSecondaryXAxis = lcl_getAxis( xCooSys, 0, 1 );
00749 Reference< chart2::XAxis > xSecondaryYAxis = lcl_getAxis( xCooSys, 1, 1 );
00750
00751 uno::Reference< beans::XPropertySet > xMainXAxisProp( xMainXAxis, uno::UNO_QUERY );
00752 uno::Reference< beans::XPropertySet > xMainYAxisProp( xMainYAxis, uno::UNO_QUERY );
00753 uno::Reference< beans::XPropertySet > xSecondaryXAxisProp( xSecondaryXAxis, uno::UNO_QUERY );
00754 uno::Reference< beans::XPropertySet > xSecondaryYAxisProp( xSecondaryYAxis, uno::UNO_QUERY );
00755
00756 if( xMainXAxisProp.is() && xMainYAxisProp.is() )
00757 {
00758 chart2::ScaleData aMainXScale = xMainXAxis->getScaleData();
00759 if( 0 == maChartTypeServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.ScatterChartType" ) ) )
00760 {
00761 xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition")
00762 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_VALUE) );
00763 double fCrossoverValue = 0.0;
00764 aMainXScale.Origin >>= fCrossoverValue;
00765 xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverValue")
00766 , uno::makeAny( fCrossoverValue ) );
00767
00768 if( aMainXScale.Orientation == chart2::AxisOrientation_REVERSE )
00769 {
00770 xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("LabelPosition")
00771 , uno::makeAny( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_END) );
00772 xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("MarkPosition")
00773 , uno::makeAny( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS) );
00774 if( xSecondaryYAxisProp.is() )
00775 xSecondaryYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition")
00776 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START) );
00777 }
00778 else
00779 {
00780 xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("LabelPosition")
00781 , uno::makeAny( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START) );
00782 xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("MarkPosition")
00783 , uno::makeAny( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS) );
00784 if( xSecondaryYAxisProp.is() )
00785 xSecondaryYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition")
00786 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_END) );
00787 }
00788 }
00789 else
00790 {
00791 if( aMainXScale.Orientation == chart2::AxisOrientation_REVERSE )
00792 {
00793 xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition")
00794 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_END) );
00795 if( xSecondaryYAxisProp.is() )
00796 xSecondaryYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition")
00797 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START) );
00798 }
00799 else
00800 {
00801 xMainYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition")
00802 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START) );
00803 if( xSecondaryYAxisProp.is() )
00804 xSecondaryYAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition")
00805 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_END) );
00806 }
00807 }
00808
00809 chart2::ScaleData aMainYScale = xMainYAxis->getScaleData();
00810 xMainXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition")
00811 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_VALUE) );
00812 double fCrossoverValue = 0.0;
00813 aMainYScale.Origin >>= fCrossoverValue;
00814 xMainXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverValue")
00815 , uno::makeAny( fCrossoverValue ) );
00816
00817 if( aMainYScale.Orientation == chart2::AxisOrientation_REVERSE )
00818 {
00819 xMainXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("LabelPosition")
00820 , uno::makeAny( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_END) );
00821 xMainXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("MarkPosition")
00822 , uno::makeAny( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS) );
00823 if( xSecondaryXAxisProp.is() )
00824 xSecondaryXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition")
00825 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_START) );
00826 }
00827 else
00828 {
00829 xMainXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("LabelPosition")
00830 , uno::makeAny( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START) );
00831 xMainXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("MarkPosition")
00832 , uno::makeAny( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS) );
00833 if( xSecondaryXAxisProp.is() )
00834 xSecondaryXAxisProp->setPropertyValue( rtl::OUString::createFromAscii("CrossoverPosition")
00835 , uno::makeAny( ::com::sun::star::chart::ChartAxisPosition_END) );
00836 }
00837 }
00838 }
00839 }
00840 }
00841 catch( uno::Exception & )
00842 {
00843 }
00844 }
00845 }
00846
00847
00848
00849 SchXMLAxisContext::SchXMLAxisContext( SchXMLImportHelper& rImpHelper,
00850 SvXMLImport& rImport, const rtl::OUString& rLocalName,
00851 uno::Reference< chart::XDiagram > xDiagram,
00852 std::vector< SchXMLAxis >& aAxes,
00853 ::rtl::OUString & rCategoriesAddress,
00854 bool bAddMissingXAxisForNetCharts,
00855 bool bAdaptWrongPercentScaleValues,
00856 bool bAdaptXAxisOrientationForOld2DBarCharts,
00857 bool& rbAxisPositionAttributeImported ) :
00858 SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ),
00859 mrImportHelper( rImpHelper ),
00860 mxDiagram( xDiagram ),
00861 maAxes( aAxes ),
00862 mrCategoriesAddress( rCategoriesAddress ),
00863 mbAddMissingXAxisForNetCharts( bAddMissingXAxisForNetCharts ),
00864 mbAdaptWrongPercentScaleValues( bAdaptWrongPercentScaleValues ),
00865 mbAdaptXAxisOrientationForOld2DBarCharts( bAdaptXAxisOrientationForOld2DBarCharts ),
00866 m_rbAxisPositionAttributeImported( rbAxisPositionAttributeImported )
00867 {
00868 }
00869
00870 SchXMLAxisContext::~SchXMLAxisContext()
00871 {}
00872
00873
00874
00875
00876 uno::Reference< drawing::XShape > SchXMLAxisContext::getTitleShape()
00877 {
00878 uno::Reference< drawing::XShape > xResult;
00879 uno::Any aTrueBool;
00880 aTrueBool <<= (sal_Bool)(sal_True);
00881 uno::Reference< beans::XPropertySet > xDiaProp( mxDiagram, uno::UNO_QUERY );
00882
00883 switch( maCurrentAxis.eClass )
00884 {
00885 case SCH_XML_AXIS_X:
00886 if( maCurrentAxis.nIndexInCategory == 0 )
00887 {
00888 uno::Reference< chart::XAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
00889 if( xSuppl.is())
00890 {
00891 if( xDiaProp.is())
00892 xDiaProp->setPropertyValue( rtl::OUString::createFromAscii( "HasXAxisTitle" ), aTrueBool );
00893 xResult = uno::Reference< drawing::XShape >( xSuppl->getXAxisTitle(), uno::UNO_QUERY );
00894 }
00895 }
00896 else
00897 {
00898 uno::Reference< chart::XSecondAxisTitleSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
00899 if( xSuppl.is() )
00900 {
00901 if( xDiaProp.is() )
00902 xDiaProp->setPropertyValue( rtl::OUString::createFromAscii( "HasSecondaryXAxisTitle" ), aTrueBool );
00903 xResult = uno::Reference< drawing::XShape >( xSuppl->getSecondXAxisTitle(), uno::UNO_QUERY );
00904 }
00905 }
00906 break;
00907 case SCH_XML_AXIS_Y:
00908 if( maCurrentAxis.nIndexInCategory == 0 )
00909 {
00910 uno::Reference< chart::XAxisYSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
00911 if( xSuppl.is())
00912 {
00913 if( xDiaProp.is())
00914 xDiaProp->setPropertyValue( rtl::OUString::createFromAscii( "HasYAxisTitle" ), aTrueBool );
00915 xResult = uno::Reference< drawing::XShape >( xSuppl->getYAxisTitle(), uno::UNO_QUERY );
00916 }
00917 }
00918 else
00919 {
00920 uno::Reference< chart::XSecondAxisTitleSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
00921 if( xSuppl.is() )
00922 {
00923 if( xDiaProp.is() )
00924 xDiaProp->setPropertyValue( rtl::OUString::createFromAscii( "HasSecondaryYAxisTitle" ), aTrueBool );
00925 xResult = uno::Reference< drawing::XShape >( xSuppl->getSecondYAxisTitle(), uno::UNO_QUERY );
00926 }
00927 }
00928 break;
00929 case SCH_XML_AXIS_Z:
00930 {
00931 uno::Reference< chart::XAxisZSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
00932 if( xSuppl.is())
00933 {
00934 if( xDiaProp.is())
00935 xDiaProp->setPropertyValue( rtl::OUString::createFromAscii( "HasZAxisTitle" ), aTrueBool );
00936 xResult = uno::Reference< drawing::XShape >( xSuppl->getZAxisTitle(), uno::UNO_QUERY );
00937 }
00938 break;
00939 }
00940 case SCH_XML_AXIS_UNDEF:
00941 DBG_ERROR( "Invalid axis" );
00942 break;
00943 }
00944
00945 return xResult;
00946 }
00947
00948 void SchXMLAxisContext::CreateGrid( ::rtl::OUString sAutoStyleName,
00949 sal_Bool bIsMajor )
00950 {
00951 uno::Reference< chart::XDiagram > xDia = mrImportHelper.GetChartDocument()->getDiagram();
00952 uno::Reference< beans::XPropertySet > xGridProp;
00953 ::rtl::OUString sPropertyName;
00954 DBG_ASSERT( xDia.is(), "diagram object is invalid!" );
00955
00956 uno::Reference< beans::XPropertySet > xDiaProp( xDia, uno::UNO_QUERY );
00957 uno::Any aTrueBool( uno::makeAny( true ));
00958
00959 switch( maCurrentAxis.eClass )
00960 {
00961 case SCH_XML_AXIS_X:
00962 {
00963 uno::Reference< chart::XAxisXSupplier > xSuppl( xDia, uno::UNO_QUERY );
00964 if( xSuppl.is())
00965 {
00966 if( bIsMajor )
00967 {
00968 if( xDiaProp.is())
00969 xDiaProp->setPropertyValue( ::rtl::OUString::createFromAscii("HasXAxisGrid"), aTrueBool );
00970 xGridProp = xSuppl->getXMainGrid();
00971 }
00972 else
00973 {
00974 if( xDiaProp.is())
00975 xDiaProp->setPropertyValue( ::rtl::OUString::createFromAscii("HasXAxisHelpGrid"), aTrueBool );
00976 xGridProp = xSuppl->getXHelpGrid();
00977 }
00978 }
00979 }
00980 break;
00981 case SCH_XML_AXIS_Y:
00982 {
00983 uno::Reference< chart::XAxisYSupplier > xSuppl( xDia, uno::UNO_QUERY );
00984 if( xSuppl.is())
00985 {
00986 if( bIsMajor )
00987 {
00988 if( xDiaProp.is())
00989 xDiaProp->setPropertyValue( ::rtl::OUString::createFromAscii("HasYAxisGrid"), aTrueBool );
00990 xGridProp = xSuppl->getYMainGrid();
00991 }
00992 else
00993 {
00994 if( xDiaProp.is())
00995 xDiaProp->setPropertyValue( ::rtl::OUString::createFromAscii("HasYAxisHelpGrid"), aTrueBool );
00996 xGridProp = xSuppl->getYHelpGrid();
00997 }
00998 }
00999 }
01000 break;
01001 case SCH_XML_AXIS_Z:
01002 {
01003 uno::Reference< chart::XAxisZSupplier > xSuppl( xDia, uno::UNO_QUERY );
01004 if( xSuppl.is())
01005 {
01006 if( bIsMajor )
01007 {
01008 if( xDiaProp.is())
01009 xDiaProp->setPropertyValue( ::rtl::OUString::createFromAscii("HasZAxisGrid"), aTrueBool );
01010 xGridProp = xSuppl->getZMainGrid();
01011 }
01012 else
01013 {
01014 if( xDiaProp.is())
01015 xDiaProp->setPropertyValue( ::rtl::OUString::createFromAscii("HasZAxisHelpGrid"), aTrueBool );
01016 xGridProp = xSuppl->getZHelpGrid();
01017 }
01018 }
01019 }
01020 break;
01021 case SCH_XML_AXIS_UNDEF:
01022 DBG_ERROR( "Invalid axis" );
01023 break;
01024 }
01025
01026
01027 if( xGridProp.is())
01028 {
01029
01030 xGridProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LineColor" )),
01031 uno::makeAny( COL_BLACK ));
01032 if( sAutoStyleName.getLength())
01033 {
01034 const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
01035 if( pStylesCtxt )
01036 {
01037 const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
01038 mrImportHelper.GetChartFamilyID(), sAutoStyleName );
01039
01040 if( pStyle && pStyle->ISA( XMLPropStyleContext ))
01041 (( XMLPropStyleContext* )pStyle )->FillPropertySet( xGridProp );
01042 }
01043 }
01044 }
01045 }
01046
01047 void SchXMLAxisContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
01048 {
01049
01050 sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
01051 SchXMLImport& rImport = ( SchXMLImport& )GetImport();
01052 const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetAxisAttrTokenMap();
01053
01054 for( sal_Int16 i = 0; i < nAttrCount; i++ )
01055 {
01056 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
01057 rtl::OUString aLocalName;
01058 rtl::OUString aValue = xAttrList->getValueByIndex( i );
01059 USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
01060
01061 switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
01062 {
01063 case XML_TOK_AXIS_DIMENSION:
01064 {
01065 USHORT nEnumVal;
01066 if( rImport.GetMM100UnitConverter().convertEnum( nEnumVal, aValue, aXMLAxisClassMap ))
01067 maCurrentAxis.eClass = ( SchXMLAxisClass )nEnumVal;
01068 }
01069 break;
01070 case XML_TOK_AXIS_NAME:
01071 maCurrentAxis.aName = aValue;
01072 break;
01073 case XML_TOK_AXIS_STYLE_NAME:
01074 msAutoStyleName = aValue;
01075 break;
01076 }
01077 }
01078
01079
01080 maCurrentAxis.nIndexInCategory = 0;
01081 sal_Int32 nNumOfAxes = maAxes.size();
01082 for( sal_Int32 nCurrent = 0; nCurrent < nNumOfAxes; nCurrent++ )
01083 {
01084 if( maAxes[ nCurrent ].eClass == maCurrentAxis.eClass )
01085 maCurrentAxis.nIndexInCategory++;
01086 }
01087 CreateAxis();
01088 }
01089 namespace
01090 {
01091
01092 uno::Reference< chart2::XAxis > lcl_getAxis( const uno::Reference< frame::XModel >& xChartModel,
01093 sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
01094 {
01095 uno::Reference< chart2::XAxis > xAxis;
01096
01097 try
01098 {
01099 uno::Reference< chart2::XChartDocument > xChart2Document( xChartModel, uno::UNO_QUERY );
01100 if( xChart2Document.is() )
01101 {
01102 uno::Reference< chart2::XDiagram > xDiagram( xChart2Document->getFirstDiagram());
01103 uno::Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY_THROW );
01104 uno::Sequence< uno::Reference< chart2::XCoordinateSystem > >
01105 aCooSysSeq( xCooSysCnt->getCoordinateSystems());
01106 sal_Int32 nCooSysIndex = 0;
01107 if( nCooSysIndex < aCooSysSeq.getLength() )
01108 {
01109 uno::Reference< chart2::XCoordinateSystem > xCooSys( aCooSysSeq[nCooSysIndex] );
01110 if( xCooSys.is() && nDimensionIndex < xCooSys->getDimension() )
01111 {
01112 const sal_Int32 nMaxAxisIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex);
01113 if( nAxisIndex <= nMaxAxisIndex )
01114 xAxis = xCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex );
01115 }
01116 }
01117 }
01118 }
01119 catch( uno::Exception & )
01120 {
01121 DBG_ERROR( "Couldn't get axis" );
01122 }
01123
01124 return xAxis;
01125 }
01126
01127 bool lcl_divideBy100( uno::Any& rDoubleAny )
01128 {
01129 bool bChanged = false;
01130 double fValue=0.0;
01131 if( (rDoubleAny>>=fValue) && (fValue!=0.0) )
01132 {
01133 fValue/=100.0;
01134 rDoubleAny = uno::makeAny(fValue);
01135 bChanged = true;
01136 }
01137 return bChanged;
01138 }
01139
01140 bool lcl_AdaptWrongPercentScaleValues(chart2::ScaleData& rScaleData)
01141 {
01142 bool bChanged = lcl_divideBy100( rScaleData.Minimum );
01143 bChanged = lcl_divideBy100( rScaleData.Maximum ) || bChanged;
01144 bChanged = lcl_divideBy100( rScaleData.Origin ) || bChanged;
01145 bChanged = lcl_divideBy100( rScaleData.IncrementData.Distance ) || bChanged;
01146 return bChanged;
01147 }
01148
01149 }
01150
01151 void SchXMLAxisContext::CreateAxis()
01152 {
01153
01154 maAxes.push_back( maCurrentAxis );
01155
01156
01157 uno::Reference< beans::XPropertySet > xDiaProp( mxDiagram, uno::UNO_QUERY );
01158 uno::Reference< beans::XPropertySet > xProp;
01159 uno::Any aTrueBool;
01160 aTrueBool <<= (sal_Bool)(sal_True);
01161 uno::Any aFalseBool;
01162 aFalseBool <<= (sal_Bool)(sal_False);
01163 uno::Reference< frame::XModel > xDoc( mrImportHelper.GetChartDocument(), uno::UNO_QUERY );
01164
01165 switch( maCurrentAxis.eClass )
01166 {
01167 case SCH_XML_AXIS_X:
01168 if( maCurrentAxis.nIndexInCategory == 0 )
01169 {
01170 try
01171 {
01172 xDiaProp->setPropertyValue(
01173 rtl::OUString::createFromAscii( "HasXAxis" ), aTrueBool );
01174 }
01175 catch( beans::UnknownPropertyException & )
01176 {
01177 DBG_ERROR( "Couldn't turn on x axis" );
01178 }
01179 uno::Reference< chart::XAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
01180 if( xSuppl.is())
01181 xProp = xSuppl->getXAxis();
01182 }
01183 else
01184 {
01185 try
01186 {
01187 xDiaProp->setPropertyValue(
01188 rtl::OUString::createFromAscii( "HasSecondaryXAxis" ), aTrueBool );
01189 }
01190 catch( beans::UnknownPropertyException & )
01191 {
01192 DBG_ERROR( "Couldn't turn on second x axis" );
01193 }
01194 uno::Reference< chart::XTwoAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
01195 if( xSuppl.is())
01196 xProp = xSuppl->getSecondaryXAxis();
01197 }
01198 break;
01199
01200 case SCH_XML_AXIS_Y:
01201 if( maCurrentAxis.nIndexInCategory == 0 )
01202 {
01203 try
01204 {
01205 xDiaProp->setPropertyValue(
01206 rtl::OUString::createFromAscii( "HasYAxis" ), aTrueBool );
01207 }
01208 catch( beans::UnknownPropertyException & )
01209 {
01210 DBG_ERROR( "Couldn't turn on y axis" );
01211 }
01212 uno::Reference< chart::XAxisYSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
01213 if( xSuppl.is())
01214 xProp = xSuppl->getYAxis();
01215
01216
01217 if( mbAddMissingXAxisForNetCharts )
01218 {
01219 if( xDiaProp.is() )
01220 {
01221 try
01222 {
01223 xDiaProp->setPropertyValue(
01224 rtl::OUString::createFromAscii( "HasXAxis" ), uno::makeAny(sal_True) );
01225 }
01226 catch( beans::UnknownPropertyException & )
01227 {
01228 DBG_ERROR( "Couldn't turn on x axis" );
01229 }
01230 }
01231 }
01232 }
01233 else
01234 {
01235 try
01236 {
01237 xDiaProp->setPropertyValue(
01238 rtl::OUString::createFromAscii( "HasSecondaryYAxis" ), aTrueBool );
01239 }
01240 catch( beans::UnknownPropertyException & )
01241 {
01242 DBG_ERROR( "Couldn't turn on second y axis" );
01243 }
01244 uno::Reference< chart::XTwoAxisYSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
01245 if( xSuppl.is())
01246 xProp = xSuppl->getSecondaryYAxis();
01247 }
01248 break;
01249
01250 case SCH_XML_AXIS_Z:
01251 {
01252 try
01253 {
01254 xDiaProp->setPropertyValue(
01255 rtl::OUString::createFromAscii( "HasZAxis" ), aTrueBool );
01256 }
01257 catch( beans::UnknownPropertyException & )
01258 {
01259 DBG_ERROR( "Couldn't turn on z axis" );
01260 }
01261 uno::Reference< chart::XAxisZSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
01262 if( xSuppl.is())
01263 xProp = xSuppl->getZAxis();
01264 }
01265 break;
01266 case SCH_XML_AXIS_UNDEF:
01267
01268 break;
01269 }
01270
01271
01272 if( xProp.is())
01273 {
01274 xProp->setPropertyValue( rtl::OUString::createFromAscii( "DisplayLabels" ), aFalseBool );
01275
01276
01277 xProp->setPropertyValue( rtl::OUString::createFromAscii( "AutoOrigin" ), aTrueBool );
01278
01279 if( msAutoStyleName.getLength())
01280 {
01281 const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
01282 if( pStylesCtxt )
01283 {
01284 const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
01285 mrImportHelper.GetChartFamilyID(), msAutoStyleName );
01286
01287 if( pStyle && pStyle->ISA( XMLPropStyleContext ))
01288 {
01289
01290 XMLPropStyleContext * pPropStyleContext = const_cast< XMLPropStyleContext * >( dynamic_cast< const XMLPropStyleContext * >( pStyle ));
01291 if( pPropStyleContext )
01292 pPropStyleContext->FillPropertySet( xProp );
01293
01294 if( mbAdaptWrongPercentScaleValues && maCurrentAxis.eClass==SCH_XML_AXIS_Y )
01295 {
01296
01297 uno::Reference< chart2::XAxis > xAxis( lcl_getAxis( GetImport().GetModel(),
01298 1 , maCurrentAxis.nIndexInCategory ) );
01299 if( xAxis.is() )
01300 {
01301 chart2::ScaleData aScaleData( xAxis->getScaleData());
01302 if( lcl_AdaptWrongPercentScaleValues(aScaleData) )
01303 xAxis->setScaleData( aScaleData );
01304 }
01305 }
01306
01307 if( mbAddMissingXAxisForNetCharts )
01308 {
01309
01310
01311 uno::Reference< chart::XAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
01312 if( xSuppl.is() )
01313 {
01314 uno::Reference< beans::XPropertySet > xXAxisProp( xSuppl->getXAxis() );
01315 (( XMLPropStyleContext* )pStyle )->FillPropertySet( xXAxisProp );
01316 }
01317
01318
01319 uno::Reference< chart2::XAxis > xAxis( lcl_getAxis( GetImport().GetModel(),
01320 0 , 0 ) );
01321 if( xAxis.is() )
01322 {
01323 chart2::ScaleData aScaleData;
01324 aScaleData.AxisType = chart2::AxisType::CATEGORY;
01325 aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
01326 xAxis->setScaleData( aScaleData );
01327 }
01328
01329
01330 uno::Reference< beans::XPropertySet > xNewAxisProp( xAxis, uno::UNO_QUERY );
01331 if( xNewAxisProp.is() )
01332 {
01333 xNewAxisProp->setPropertyValue( rtl::OUString::createFromAscii("LineStyle")
01334 , uno::makeAny(drawing::LineStyle_NONE));
01335 }
01336 }
01337
01338 if( mbAdaptXAxisOrientationForOld2DBarCharts && maCurrentAxis.eClass == SCH_XML_AXIS_X )
01339 {
01340 bool bIs3DChart = false;
01341 if( xDiaProp.is() && ( xDiaProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Dim3D"))) >>= bIs3DChart )
01342 && !bIs3DChart )
01343 {
01344 uno::Reference< chart2::XChartDocument > xChart2Document( GetImport().GetModel(), uno::UNO_QUERY );
01345 if( xChart2Document.is() )
01346 {
01347 uno::Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xChart2Document->getFirstDiagram(), uno::UNO_QUERY );
01348 if( xCooSysCnt.is() )
01349 {
01350 uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems() );
01351 if( aCooSysSeq.getLength() )
01352 {
01353 bool bSwapXandYAxis = false;
01354 uno::Reference< chart2::XCoordinateSystem > xCooSys( aCooSysSeq[0] );
01355 uno::Reference< beans::XPropertySet > xCooSysProp( xCooSys, uno::UNO_QUERY );
01356 if( xCooSysProp.is() && ( xCooSysProp->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwapXAndYAxis"))) >>= bSwapXandYAxis )
01357 && bSwapXandYAxis )
01358 {
01359 uno::Reference< chart2::XAxis > xAxis = xCooSys->getAxisByDimension( 0, maCurrentAxis.nIndexInCategory );
01360 if( xAxis.is() )
01361 {
01362 chart2::ScaleData aScaleData = xAxis->getScaleData();
01363 aScaleData.Orientation = chart2::AxisOrientation_REVERSE;
01364 xAxis->setScaleData( aScaleData );
01365 }
01366 }
01367 }
01368 }
01369 }
01370 }
01371 }
01372
01373 m_rbAxisPositionAttributeImported = m_rbAxisPositionAttributeImported || SchXMLTools::getPropertyFromContext(
01374 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CrossoverPosition")), pPropStyleContext, pStylesCtxt ).hasValue();
01375 }
01376 }
01377 }
01378 }
01379 }
01380
01381 void SchXMLAxisContext::SetAxisTitle()
01382 {
01383
01384 maAxes.push_back( maCurrentAxis );
01385
01386
01387 sal_Bool bHasTitle = ( maCurrentAxis.aTitle.getLength() > 0 );
01388 uno::Reference< frame::XModel > xDoc( mrImportHelper.GetChartDocument(), uno::UNO_QUERY );
01389
01390 switch( maCurrentAxis.eClass )
01391 {
01392 case SCH_XML_AXIS_X:
01393 if( maCurrentAxis.nIndexInCategory == 0 )
01394 {
01395 uno::Reference< chart::XAxisXSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
01396 if( xSuppl.is() &&
01397 bHasTitle )
01398 {
01399 uno::Reference< beans::XPropertySet > xTitleProp( xSuppl->getXAxisTitle(), uno::UNO_QUERY );
01400 if( xTitleProp.is())
01401 {
01402 try
01403 {
01404 uno::Any aAny;
01405 aAny <<= maCurrentAxis.aTitle;
01406 xTitleProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny );
01407 }
01408 catch( beans::UnknownPropertyException & )
01409 {
01410 DBG_ERROR( "Property String for Title not available" );
01411 }
01412 }
01413 }
01414 }
01415 else
01416 {
01417 uno::Reference< chart::XSecondAxisTitleSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
01418 if( xSuppl.is() &&
01419 bHasTitle )
01420 {
01421 uno::Reference< beans::XPropertySet > xTitleProp( xSuppl->getSecondXAxisTitle(), uno::UNO_QUERY );
01422 if( xTitleProp.is())
01423 {
01424 try
01425 {
01426 uno::Any aAny;
01427 aAny <<= maCurrentAxis.aTitle;
01428 xTitleProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny );
01429 }
01430 catch( beans::UnknownPropertyException & )
01431 {
01432 DBG_ERROR( "Property String for Title not available" );
01433 }
01434 }
01435 }
01436 }
01437 break;
01438
01439 case SCH_XML_AXIS_Y:
01440 if( maCurrentAxis.nIndexInCategory == 0 )
01441 {
01442 uno::Reference< chart::XAxisYSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
01443 if( xSuppl.is() &&
01444 bHasTitle )
01445 {
01446 uno::Reference< beans::XPropertySet > xTitleProp( xSuppl->getYAxisTitle(), uno::UNO_QUERY );
01447 if( xTitleProp.is())
01448 {
01449 try
01450 {
01451 uno::Any aAny;
01452 aAny <<= maCurrentAxis.aTitle;
01453 xTitleProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny );
01454 }
01455 catch( beans::UnknownPropertyException & )
01456 {
01457 DBG_ERROR( "Property String for Title not available" );
01458 }
01459 }
01460 }
01461 }
01462 else
01463 {
01464 uno::Reference< chart::XSecondAxisTitleSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
01465 if( xSuppl.is() &&
01466 bHasTitle )
01467 {
01468 uno::Reference< beans::XPropertySet > xTitleProp( xSuppl->getSecondYAxisTitle(), uno::UNO_QUERY );
01469 if( xTitleProp.is())
01470 {
01471 try
01472 {
01473 uno::Any aAny;
01474 aAny <<= maCurrentAxis.aTitle;
01475 xTitleProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny );
01476 }
01477 catch( beans::UnknownPropertyException & )
01478 {
01479 DBG_ERROR( "Property String for Title not available" );
01480 }
01481 }
01482 }
01483 }
01484 break;
01485
01486 case SCH_XML_AXIS_Z:
01487 {
01488 uno::Reference< chart::XAxisZSupplier > xSuppl( mxDiagram, uno::UNO_QUERY );
01489 if( xSuppl.is() &&
01490 bHasTitle )
01491 {
01492 uno::Reference< beans::XPropertySet > xTitleProp( xSuppl->getZAxisTitle(), uno::UNO_QUERY );
01493 if( xTitleProp.is())
01494 {
01495 try
01496 {
01497 uno::Any aAny;
01498 aAny <<= maCurrentAxis.aTitle;
01499 xTitleProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny );
01500 }
01501 catch( beans::UnknownPropertyException & )
01502 {
01503 DBG_ERROR( "Property String for Title not available" );
01504 }
01505 }
01506 }
01507 }
01508 break;
01509 case SCH_XML_AXIS_UNDEF:
01510
01511 break;
01512 }
01513 }
01514
01515 SvXMLImportContext* SchXMLAxisContext::CreateChildContext(
01516 USHORT p_nPrefix,
01517 const rtl::OUString& rLocalName,
01518 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
01519 {
01520 SvXMLImportContext* pContext = 0;
01521 const SvXMLTokenMap& rTokenMap = mrImportHelper.GetAxisElemTokenMap();
01522
01523 switch( rTokenMap.Get( p_nPrefix, rLocalName ))
01524 {
01525 case XML_TOK_AXIS_TITLE:
01526 {
01527 uno::Reference< drawing::XShape > xTitleShape = getTitleShape();
01528 pContext = new SchXMLTitleContext( mrImportHelper, GetImport(), rLocalName,
01529 maCurrentAxis.aTitle,
01530 xTitleShape );
01531 }
01532 break;
01533
01534 case XML_TOK_AXIS_CATEGORIES:
01535 pContext = new SchXMLCategoriesContext( mrImportHelper, GetImport(),
01536 p_nPrefix, rLocalName,
01537 mrCategoriesAddress );
01538 maCurrentAxis.bHasCategories = true;
01539 break;
01540
01541 case XML_TOK_AXIS_GRID:
01542 {
01543 sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
01544 sal_Bool bIsMajor = sal_True;
01545 rtl::OUString sAutoStyleName;
01546
01547 for( sal_Int16 i = 0; i < nAttrCount; i++ )
01548 {
01549 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
01550 rtl::OUString aLocalName;
01551 USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
01552
01553 if( nPrefix == XML_NAMESPACE_CHART )
01554 {
01555 if( IsXMLToken( aLocalName, XML_CLASS ) )
01556 {
01557 if( IsXMLToken( xAttrList->getValueByIndex( i ), XML_MINOR ) )
01558 bIsMajor = sal_False;
01559 }
01560 else if( IsXMLToken( aLocalName, XML_STYLE_NAME ) )
01561 sAutoStyleName = xAttrList->getValueByIndex( i );
01562 }
01563 }
01564
01565 CreateGrid( sAutoStyleName, bIsMajor );
01566
01567
01568 pContext = new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
01569 }
01570 break;
01571
01572 default:
01573 pContext = new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
01574 break;
01575 }
01576
01577 return pContext;
01578 }
01579
01580 void SchXMLAxisContext::EndElement()
01581 {
01582 SetAxisTitle();
01583 }
01584
01585
01586
01587 SchXMLDataPointContext::SchXMLDataPointContext( SchXMLImportHelper& rImpHelper,
01588 SvXMLImport& rImport, const rtl::OUString& rLocalName,
01589 ::std::list< DataRowPointStyle >& rStyleList,
01590 const ::com::sun::star::uno::Reference<
01591 ::com::sun::star::chart2::XDataSeries >& xSeries,
01592 sal_Int32& rIndex,
01593 bool bSymbolSizeForSeriesIsMissingInFile ) :
01594 SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ),
01595 mrImportHelper( rImpHelper ),
01596 mrStyleList( rStyleList ),
01597 m_xSeries( xSeries ),
01598 mrIndex( rIndex ),
01599 mbSymbolSizeForSeriesIsMissingInFile( bSymbolSizeForSeriesIsMissingInFile )
01600 {
01601 }
01602
01603 SchXMLDataPointContext::~SchXMLDataPointContext()
01604 {
01605 }
01606
01607 void SchXMLDataPointContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
01608 {
01609 sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
01610 ::rtl::OUString aValue;
01611 ::rtl::OUString sAutoStyleName;
01612 sal_Int32 nRepeat = 1;
01613
01614 for( sal_Int16 i = 0; i < nAttrCount; i++ )
01615 {
01616 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
01617 rtl::OUString aLocalName;
01618 USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
01619
01620 if( nPrefix == XML_NAMESPACE_CHART )
01621 {
01622 if( IsXMLToken( aLocalName, XML_STYLE_NAME ) )
01623 sAutoStyleName = xAttrList->getValueByIndex( i );
01624 else if( IsXMLToken( aLocalName, XML_REPEATED ) )
01625 nRepeat = xAttrList->getValueByIndex( i ).toInt32();
01626 }
01627 }
01628
01629 if( sAutoStyleName.getLength())
01630 {
01631 DataRowPointStyle aStyle(
01632 DataRowPointStyle::DATA_POINT,
01633 m_xSeries, mrIndex, nRepeat, sAutoStyleName );
01634 aStyle.mbSymbolSizeForSeriesIsMissingInFile = mbSymbolSizeForSeriesIsMissingInFile;
01635 mrStyleList.push_back( aStyle );
01636 }
01637 mrIndex += nRepeat;
01638 }
01639
01640
01641
01642 SchXMLCategoriesContext::SchXMLCategoriesContext(
01643 SchXMLImportHelper& rImpHelper,
01644 SvXMLImport& rImport,
01645 sal_uInt16 nPrefix,
01646 const rtl::OUString& rLocalName,
01647 rtl::OUString& rAddress ) :
01648 SvXMLImportContext( rImport, nPrefix, rLocalName ),
01649 mrImportHelper( rImpHelper ),
01650 mrAddress( rAddress )
01651 {
01652 }
01653
01654 SchXMLCategoriesContext::~SchXMLCategoriesContext()
01655 {
01656 }
01657
01658 void SchXMLCategoriesContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
01659 {
01660 sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
01661
01662 for( sal_Int16 i = 0; i < nAttrCount; i++ )
01663 {
01664 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
01665 rtl::OUString aLocalName;
01666 USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
01667
01668 if( nPrefix == XML_NAMESPACE_TABLE &&
01669 IsXMLToken( aLocalName, XML_CELL_RANGE_ADDRESS ) )
01670 {
01671 uno::Reference< chart2::XChartDocument > xNewDoc( GetImport().GetModel(), uno::UNO_QUERY );
01672 mrAddress = xAttrList->getValueByIndex( i );
01673
01674 }
01675 }
01676 }
01677
01678
01679
01680 SchXMLWallFloorContext::SchXMLWallFloorContext(
01681 SchXMLImportHelper& rImpHelper,
01682 SvXMLImport& rImport,
01683 sal_uInt16 nPrefix,
01684 const rtl::OUString& rLocalName,
01685 uno::Reference< chart::XDiagram >& xDiagram,
01686 ContextType eContextType ) :
01687 SvXMLImportContext( rImport, nPrefix, rLocalName ),
01688 mrImportHelper( rImpHelper ),
01689 mxWallFloorSupplier( xDiagram, uno::UNO_QUERY ),
01690 meContextType( eContextType )
01691 {
01692 }
01693
01694 SchXMLWallFloorContext::~SchXMLWallFloorContext()
01695 {
01696 }
01697
01698 void SchXMLWallFloorContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
01699 {
01700 if( mxWallFloorSupplier.is())
01701 {
01702 sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
01703 rtl::OUString sAutoStyleName;
01704
01705 for( sal_Int16 i = 0; i < nAttrCount; i++ )
01706 {
01707 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
01708 rtl::OUString aLocalName;
01709 USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
01710
01711 if( nPrefix == XML_NAMESPACE_CHART &&
01712 IsXMLToken( aLocalName, XML_STYLE_NAME ) )
01713 {
01714 sAutoStyleName = xAttrList->getValueByIndex( i );
01715 }
01716 }
01717
01718
01719 uno::Reference< beans::XPropertySet > xProp( ( meContextType == CONTEXT_TYPE_WALL )
01720 ? mxWallFloorSupplier->getWall()
01721 : mxWallFloorSupplier->getFloor(),
01722 uno::UNO_QUERY );
01723 if( xProp.is())
01724 {
01725 if( sAutoStyleName.getLength())
01726 {
01727 const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
01728 if( pStylesCtxt )
01729 {
01730 const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
01731 mrImportHelper.GetChartFamilyID(), sAutoStyleName );
01732
01733 if( pStyle && pStyle->ISA( XMLPropStyleContext ))
01734 (( XMLPropStyleContext* )pStyle )->FillPropertySet( xProp );
01735 }
01736 }
01737 }
01738 }
01739 }
01740
01741
01742
01743 SchXMLStockContext::SchXMLStockContext(
01744 SchXMLImportHelper& rImpHelper,
01745 SvXMLImport& rImport,
01746 sal_uInt16 nPrefix,
01747 const rtl::OUString& rLocalName,
01748 uno::Reference< chart::XDiagram >& xDiagram,
01749 ContextType eContextType ) :
01750 SvXMLImportContext( rImport, nPrefix, rLocalName ),
01751 mrImportHelper( rImpHelper ),
01752 mxStockPropProvider( xDiagram, uno::UNO_QUERY ),
01753 meContextType( eContextType )
01754 {
01755 }
01756
01757 SchXMLStockContext::~SchXMLStockContext()
01758 {
01759 }
01760
01761 void SchXMLStockContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
01762 {
01763 if( mxStockPropProvider.is())
01764 {
01765 sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
01766 rtl::OUString sAutoStyleName;
01767
01768 for( sal_Int16 i = 0; i < nAttrCount; i++ )
01769 {
01770 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
01771 rtl::OUString aLocalName;
01772 USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
01773
01774 if( nPrefix == XML_NAMESPACE_CHART &&
01775 IsXMLToken( aLocalName, XML_STYLE_NAME ) )
01776 {
01777 sAutoStyleName = xAttrList->getValueByIndex( i );
01778 }
01779 }
01780
01781 if( sAutoStyleName.getLength())
01782 {
01783
01784 uno::Reference< beans::XPropertySet > xProp;
01785 switch( meContextType )
01786 {
01787 case CONTEXT_TYPE_GAIN:
01788 xProp = mxStockPropProvider->getUpBar();
01789 break;
01790 case CONTEXT_TYPE_LOSS:
01791 xProp = mxStockPropProvider->getDownBar();
01792 break;
01793 case CONTEXT_TYPE_RANGE:
01794 xProp = mxStockPropProvider->getMinMaxLine();
01795 break;
01796 }
01797 if( xProp.is())
01798 {
01799 const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
01800 if( pStylesCtxt )
01801 {
01802 const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
01803 mrImportHelper.GetChartFamilyID(), sAutoStyleName );
01804
01805 if( pStyle && pStyle->ISA( XMLPropStyleContext ))
01806 (( XMLPropStyleContext* )pStyle )->FillPropertySet( xProp );
01807 }
01808 }
01809 }
01810 }
01811 }
01812
01813
01814
01815 SchXMLStatisticsObjectContext::SchXMLStatisticsObjectContext(
01816
01817 SchXMLImportHelper& rImpHelper,
01818 SvXMLImport& rImport,
01819 sal_uInt16 nPrefix,
01820 const rtl::OUString& rLocalName,
01821 ::std::list< DataRowPointStyle >& rStyleList,
01822 const ::com::sun::star::uno::Reference<
01823 ::com::sun::star::chart2::XDataSeries >& xSeries,
01824 ContextType eContextType,
01825 const awt::Size & rChartSize ) :
01826
01827 SvXMLImportContext( rImport, nPrefix, rLocalName ),
01828 mrImportHelper( rImpHelper ),
01829 mrStyleList( rStyleList ),
01830 m_xSeries( xSeries ),
01831 meContextType( eContextType ),
01832 maChartSize( rChartSize )
01833 {}
01834
01835 SchXMLStatisticsObjectContext::~SchXMLStatisticsObjectContext()
01836 {
01837 }
01838
01839 void SchXMLStatisticsObjectContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
01840 {
01841 sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
01842 ::rtl::OUString aValue;
01843 ::rtl::OUString sAutoStyleName;
01844
01845 for( sal_Int16 i = 0; i < nAttrCount; i++ )
01846 {
01847 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
01848 rtl::OUString aLocalName;
01849 USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
01850
01851 if( nPrefix == XML_NAMESPACE_CHART )
01852 {
01853 if( IsXMLToken( aLocalName, XML_STYLE_NAME ) )
01854 sAutoStyleName = xAttrList->getValueByIndex( i );
01855 }
01856 }
01857
01858
01859
01860 if( sAutoStyleName.getLength() || meContextType == CONTEXT_TYPE_REGRESSION_CURVE )
01861 {
01862 DataRowPointStyle::StyleType eType = DataRowPointStyle::MEAN_VALUE;
01863 switch( meContextType )
01864 {
01865 case CONTEXT_TYPE_MEAN_VALUE_LINE:
01866 eType = DataRowPointStyle::MEAN_VALUE;
01867 break;
01868 case CONTEXT_TYPE_REGRESSION_CURVE:
01869 eType = DataRowPointStyle::REGRESSION;
01870 break;
01871 case CONTEXT_TYPE_ERROR_INDICATOR:
01872 eType = DataRowPointStyle::ERROR_INDICATOR;
01873 break;
01874 }
01875 DataRowPointStyle aStyle(
01876 eType, m_xSeries, -1, 1, sAutoStyleName );
01877 mrStyleList.push_back( aStyle );
01878 }
01879 }
01880
01881 SvXMLImportContext* SchXMLStatisticsObjectContext::CreateChildContext(
01882 USHORT nPrefix,
01883 const rtl::OUString& rLocalName,
01884 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
01885 {
01886 SvXMLImportContext* pContext = 0;
01887
01888 if( nPrefix == XML_NAMESPACE_CHART &&
01889 IsXMLToken( rLocalName, XML_EQUATION ) )
01890 {
01891 pContext = new SchXMLEquationContext(
01892 mrImportHelper, GetImport(), nPrefix, rLocalName, m_xSeries, maChartSize, mrStyleList.back());
01893 }
01894 else
01895 {
01896 pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
01897 }
01898
01899 return pContext;
01900 }
01901
01902
01903
01904 SchXMLEquationContext::SchXMLEquationContext(
01905 SchXMLImportHelper& rImpHelper,
01906 SvXMLImport& rImport,
01907 sal_uInt16 nPrefix,
01908 const rtl::OUString& rLocalName,
01909 const ::com::sun::star::uno::Reference<
01910 ::com::sun::star::chart2::XDataSeries >& xSeries,
01911 const awt::Size & rChartSize,
01912 DataRowPointStyle & rRegressionStyle ) :
01913 SvXMLImportContext( rImport, nPrefix, rLocalName ),
01914 mrImportHelper( rImpHelper ),
01915 mrRegressionStyle( rRegressionStyle ),
01916 m_xSeries( xSeries ),
01917 maChartSize( rChartSize )
01918 {}
01919
01920 SchXMLEquationContext::~SchXMLEquationContext()
01921 {}
01922
01923 void SchXMLEquationContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
01924 {
01925
01926 sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
01927 SchXMLImport& rImport = ( SchXMLImport& )GetImport();
01928 const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetRegEquationAttrTokenMap();
01929 OUString sAutoStyleName;
01930
01931 sal_Bool bShowEquation = sal_True;
01932 sal_Bool bShowRSquare = sal_False;
01933 awt::Point aPosition;
01934 bool bHasXPos = false;
01935 bool bHasYPos = false;
01936
01937 for( sal_Int16 i = 0; i < nAttrCount; i++ )
01938 {
01939 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
01940 rtl::OUString aLocalName;
01941 rtl::OUString aValue = xAttrList->getValueByIndex( i );
01942 USHORT nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
01943
01944 switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
01945 {
01946 case XML_TOK_REGEQ_POS_X:
01947 rImport.GetMM100UnitConverter().convertMeasure( aPosition.X, aValue );
01948 bHasXPos = true;
01949 break;
01950 case XML_TOK_REGEQ_POS_Y:
01951 rImport.GetMM100UnitConverter().convertMeasure( aPosition.Y, aValue );
01952 bHasYPos = true;
01953 break;
01954 case XML_TOK_REGEQ_DISPLAY_EQUATION:
01955 rImport.GetMM100UnitConverter().convertBool( bShowEquation, aValue );
01956 break;
01957 case XML_TOK_REGEQ_DISPLAY_R_SQUARE:
01958 rImport.GetMM100UnitConverter().convertBool( bShowRSquare, aValue );
01959 break;
01960 case XML_TOK_REGEQ_STYLE_NAME:
01961 sAutoStyleName = aValue;
01962 break;
01963 }
01964 }
01965
01966 if( sAutoStyleName.getLength() || bShowEquation || bShowRSquare )
01967 {
01968 uno::Reference< beans::XPropertySet > xEqProp;
01969 uno::Reference< lang::XMultiServiceFactory > xFact( comphelper::getProcessServiceFactory(), uno::UNO_QUERY );
01970 if( xFact.is())
01971 xEqProp.set( xFact->createInstance(
01972 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.RegressionEquation" ))), uno::UNO_QUERY );
01973 if( xEqProp.is())
01974 {
01975 if( sAutoStyleName.getLength() )
01976 {
01977 const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
01978 if( pStylesCtxt )
01979 {
01980 const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
01981 mrImportHelper.GetChartFamilyID(), sAutoStyleName );
01982
01983 XMLPropStyleContext * pPropStyleContext =
01984 const_cast< XMLPropStyleContext * >( dynamic_cast< const XMLPropStyleContext * >( pStyle ));
01985
01986 if( pPropStyleContext )
01987 pPropStyleContext->FillPropertySet( xEqProp );
01988 }
01989 }
01990 xEqProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("ShowEquation")), uno::makeAny( bShowEquation ));
01991 xEqProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("ShowCorrelationCoefficient")), uno::makeAny( bShowRSquare ));
01992
01993 if( bHasXPos && bHasYPos )
01994 {
01995 chart2::RelativePosition aRelPos;
01996 aRelPos.Primary = static_cast< double >( aPosition.X ) / static_cast< double >( maChartSize.Width );
01997 aRelPos.Secondary = static_cast< double >( aPosition.Y ) / static_cast< double >( maChartSize.Height );
01998 xEqProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "RelativePosition" )),
01999 uno::makeAny( aRelPos ));
02000 }
02001 OSL_ASSERT( mrRegressionStyle.meType == DataRowPointStyle::REGRESSION );
02002 mrRegressionStyle.m_xEquationProperties.set( xEqProp );
02003 }
02004 }
02005 }