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