1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26
27 #include <xmloff/xmlprmap.hxx>
28
29 #include "SchXMLExport.hxx"
30 #include "XMLChartPropertySetMapper.hxx"
31 #include "SchXMLSeriesHelper.hxx"
32 #include "ColorPropertySet.hxx"
33 #include "SchXMLTools.hxx"
34 #include "SchXMLEnumConverter.hxx"
35
36 #include <tools/debug.hxx>
37 #include <rtl/logfile.hxx>
38 #include <comphelper/processfactory.hxx>
39 #include <tools/globname.hxx>
40 #include <sot/clsids.hxx>
41
42 #include <xmloff/nmspmap.hxx>
43 #include "xmloff/xmlnmspe.hxx"
44 #include <xmloff/xmltoken.hxx>
45 #include <xmloff/families.hxx>
46 #include <xmloff/xmlaustp.hxx>
47 #include <xmloff/xmluconv.hxx>
48 #include <xmloff/xmlmetae.hxx>
49 #include "xexptran.hxx"
50 #include <rtl/math.hxx>
51 // header for any2enum
52 #include <comphelper/extract.hxx>
53
54 #include <list>
55 #include <typeinfo>
56 #include <algorithm>
57 #include <iterator>
58
59 #include <com/sun/star/task/XStatusIndicatorSupplier.hpp>
60 #include <com/sun/star/lang/XServiceInfo.hpp>
61 #include <com/sun/star/lang/XServiceName.hpp>
62 #include <com/sun/star/beans/XPropertySet.hpp>
63 #include <com/sun/star/uno/XComponentContext.hpp>
64 #include <com/sun/star/util/XRefreshable.hpp>
65
66 #include <com/sun/star/chart/XAxis.hpp>
67 #include <com/sun/star/chart/XAxisSupplier.hpp>
68 #include <com/sun/star/chart/XChartDocument.hpp>
69 #include <com/sun/star/chart/ChartLegendPosition.hpp>
70 #include <com/sun/star/chart/ChartLegendExpansion.hpp>
71 #include <com/sun/star/chart/ChartDataRowSource.hpp>
72 #include <com/sun/star/chart/ChartAxisAssign.hpp>
73 #include <com/sun/star/chart/ChartAxisType.hpp>
74 #include <com/sun/star/chart/TimeIncrement.hpp>
75 #include <com/sun/star/chart/TimeInterval.hpp>
76 #include <com/sun/star/chart/TimeUnit.hpp>
77 #include <com/sun/star/chart/ChartSeriesAddress.hpp>
78 #include <com/sun/star/chart/X3DDisplay.hpp>
79 #include <com/sun/star/chart/XStatisticDisplay.hpp>
80 #include <com/sun/star/chart/XSecondAxisTitleSupplier.hpp>
81 #include <com/sun/star/chart/XDiagramPositioning.hpp>
82
83 #include <com/sun/star/chart2/XAnyDescriptionAccess.hpp>
84 #include <com/sun/star/chart2/AxisType.hpp>
85 #include <com/sun/star/chart2/XChartDocument.hpp>
86 #include <com/sun/star/chart2/XDiagram.hpp>
87 #include <com/sun/star/chart2/RelativePosition.hpp>
88 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
89 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
90 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
91 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
92 #include <com/sun/star/chart2/data/XDataSource.hpp>
93 #include <com/sun/star/chart2/data/XDataSink.hpp>
94 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
95 #include <com/sun/star/chart2/data/XDataProvider.hpp>
96 #include <com/sun/star/chart2/data/XDatabaseDataProvider.hpp>
97 #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
98 #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
99 #include <com/sun/star/chart2/data/XNumericalDataSequence.hpp>
100
101 #include <com/sun/star/util/XStringMapping.hpp>
102 #include <com/sun/star/drawing/HomogenMatrix.hpp>
103 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
104 #include <com/sun/star/drawing/XShapes.hpp>
105 #include <com/sun/star/embed/Aspects.hpp>
106 #include <com/sun/star/embed/XVisualObject.hpp>
107 #include <com/sun/star/container/XChild.hpp>
108
109
110 #include "MultiPropertySetHandler.hxx"
111 #include "PropertyMap.hxx"
112
113 using namespace com::sun::star;
114 using namespace ::xmloff::token;
115
116 using ::rtl::OUString;
117 using ::rtl::OUStringBuffer;
118 using ::rtl::OUStringToOString;
119 using ::com::sun::star::uno::Sequence;
120 using ::com::sun::star::uno::Reference;
121 using ::com::sun::star::uno::Any;
122 using ::std::vector;
123
124 // ========================================
125 // class SchXMLExportHelper_Impl
126 // ========================================
127
128 class SchXMLExportHelper_Impl
129 {
130 public:
131 // first: data sequence for label, second: data sequence for values.
132 typedef ::std::pair< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSequence >,
133 ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSequence > > tLabelValuesDataPair;
134 typedef ::std::vector< tLabelValuesDataPair > tDataSequenceCont;
135
136 public:
137 SchXMLExportHelper_Impl( SvXMLExport& rExport,
138 SvXMLAutoStylePoolP& rASPool );
139
140 virtual ~SchXMLExportHelper_Impl();
141
142 // auto-styles
143 /// parse chart and collect all auto-styles used in current pool
144 void collectAutoStyles( com::sun::star::uno::Reference<
145 com::sun::star::chart::XChartDocument > rChartDoc );
146
147 /// write the styles collected into the current pool as <style:style> elements
148 void exportAutoStyles();
149
150 /** export the <chart:chart> element corresponding to rChartDoc
151 if bIncludeTable is true, the chart data is exported as <table:table>
152 element (inside the chart element).
153
154 Otherwise the external references stored in the chart document are used
155 for writing the corresponding attributes at series
156
157 All attributes contained in xAttrList are written at the chart element,
158 which ist the outer element of a chart. So these attributes can easily
159 be parsed again by the container
160 */
161 void exportChart( com::sun::star::uno::Reference<
162 com::sun::star::chart::XChartDocument > rChartDoc,
163 sal_Bool bIncludeTable );
164
165 UniReference< XMLPropertySetMapper > GetPropertySetMapper() const;
166
SetChartRangeAddress(const::rtl::OUString & rAddress)167 void SetChartRangeAddress( const ::rtl::OUString& rAddress )
168 { msChartAddress = rAddress; }
SetTableNumberList(const::rtl::OUString & rList)169 void SetTableNumberList( const ::rtl::OUString& rList )
170 { msTableNumberList = rList; }
171
172 void InitRangeSegmentationProperties(
173 const ::com::sun::star::uno::Reference<
174 ::com::sun::star::chart2::XChartDocument > & xChartDoc );
175
176 ::com::sun::star::awt::Size getPageSize(
177 const ::com::sun::star::uno::Reference<
178 ::com::sun::star::chart2::XChartDocument > & xChartDoc ) const;
179
180 /** first parseDocument: collect autostyles and store names in this queue
181 second parseDocument: export content and use names from this queue
182 */
183 ::std::queue< ::rtl::OUString > maAutoStyleNameQueue;
184 void CollectAutoStyle(
185 const std::vector< XMLPropertyState >& aStates );
186 void AddAutoStyleAttribute(
187 const std::vector< XMLPropertyState >& aStates );
188
GetAutoStylePoolP()189 SvXMLAutoStylePoolP& GetAutoStylePoolP()
190 { return mrAutoStylePool; }
191
192 /// if bExportContent is false the auto-styles are collected
193 void parseDocument( com::sun::star::uno::Reference<
194 com::sun::star::chart::XChartDocument >& rChartDoc,
195 sal_Bool bExportContent,
196 sal_Bool bIncludeTable = sal_False );
197 void exportTable();
198 void exportPlotArea(
199 com::sun::star::uno::Reference< com::sun::star::chart::XDiagram > xDiagram,
200 com::sun::star::uno::Reference< com::sun::star::chart2::XDiagram > xNewDiagram,
201 const ::com::sun::star::awt::Size & rPageSize,
202 sal_Bool bExportContent,
203 sal_Bool bIncludeTable );
204 void exportCoordinateRegion( const com::sun::star::uno::Reference< com::sun::star::chart::XDiagram >& xDiagram );
205 void exportAxes( const com::sun::star::uno::Reference< com::sun::star::chart::XDiagram > & xDiagram,
206 const com::sun::star::uno::Reference< com::sun::star::chart2::XDiagram > & xNewDiagram,
207 sal_Bool bExportContent );
208 void exportAxis( enum XMLTokenEnum eDimension, enum XMLTokenEnum eAxisName,
209 const Reference< beans::XPropertySet > xAxisProps, const Reference< chart2::XAxis >& xChart2Axis,
210 const OUString& rCategoriesRanges,
211 bool bHasTitle, bool bHasMajorGrid, bool bHasMinorGrid, bool bExportContent );
212 void exportGrid( const Reference< beans::XPropertySet > xGridProperties, bool bMajor, bool bExportContent );
213 void exportDateScale( const Reference< beans::XPropertySet > xAxisProps );
214 void exportAxisTitle( const Reference< beans::XPropertySet > xTitleProps, bool bExportContent );
215
216 void exportSeries(
217 const com::sun::star::uno::Reference< com::sun::star::chart2::XDiagram > & xNewDiagram,
218 const ::com::sun::star::awt::Size & rPageSize,
219 sal_Bool bExportContent,
220 sal_Bool bHasTwoYAxes );
221 void exportCandleStickSeries(
222 const ::com::sun::star::uno::Sequence<
223 ::com::sun::star::uno::Reference<
224 ::com::sun::star::chart2::XDataSeries > > & aSeriesSeq,
225 const ::com::sun::star::uno::Reference<
226 ::com::sun::star::chart2::XDiagram > & xDiagram,
227 sal_Bool bJapaneseCandleSticks,
228 sal_Bool bExportContent );
229 void exportDataPoints(
230 const ::com::sun::star::uno::Reference<
231 ::com::sun::star::beans::XPropertySet > & xSeriesProperties,
232 sal_Int32 nSeriesLength,
233 const ::com::sun::star::uno::Reference<
234 ::com::sun::star::chart2::XDiagram > & xDiagram,
235 sal_Bool bExportContent );
236 void exportRegressionCurve(
237 const ::com::sun::star::uno::Reference<
238 ::com::sun::star::chart2::XDataSeries > & xSeries,
239 const ::com::sun::star::uno::Reference<
240 ::com::sun::star::beans::XPropertySet > & xSeriesProp,
241 const ::com::sun::star::awt::Size & rPageSize,
242 sal_Bool bExportContent );
243
244 /// add svg position as attribute for current element
245 void addPosition( const ::com::sun::star::awt::Point & rPosition );
246 void addPosition( com::sun::star::uno::Reference< com::sun::star::drawing::XShape > xShape );
247 /// add svg size as attribute for current element
248 void addSize( const ::com::sun::star::awt::Size & rSize, bool bIsOOoNamespace = false );
249 void addSize( com::sun::star::uno::Reference< com::sun::star::drawing::XShape > xShape, bool bIsOOoNamespace = false );
250 /// fills the member msString with the appropriate String (i.e. "A3")
251 void getCellAddress( sal_Int32 nCol, sal_Int32 nRow );
252 /// exports a string as a paragraph element
253 void exportText( const ::rtl::OUString& rText, bool bConvertTabsLFs = false );
254 void exportErrorBarRanges();
255
256 SchXMLExportHelper_Impl(SchXMLExportHelper_Impl &); // not defined
257 void operator =(SchXMLExportHelper_Impl &); // not defined
258
259 public:
260 SvXMLExport& mrExport;
261 SvXMLAutoStylePoolP& mrAutoStylePool;
262 UniReference< XMLPropertyHandlerFactory > mxPropertyHandlerFactory;
263 UniReference< XMLPropertySetMapper > mxPropertySetMapper;
264 UniReference< XMLChartExportPropertyMapper > mxExpPropMapper;
265
266 rtl::OUString msTableName;
267 rtl::OUStringBuffer msStringBuffer;
268 rtl::OUString msString;
269
270 // members filled by InitRangeSegmentationProperties (retrieved from DataProvider)
271 sal_Bool mbHasSeriesLabels;
272 sal_Bool mbHasCategoryLabels; //if the categories are only automatically generated this will be false
273 sal_Bool mbRowSourceColumns;
274 rtl::OUString msChartAddress;
275 rtl::OUString msTableNumberList;
276 ::com::sun::star::uno::Sequence< sal_Int32 > maSequenceMapping;
277
278 rtl::OUString msCLSID;
279
280 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes > mxAdditionalShapes;
281
282 tDataSequenceCont m_aDataSequencesToExport;
283 rtl::OUString maCategoriesRange;
284 };
285
286 namespace
287 {
lcl_getComponentContext()288 Reference< uno::XComponentContext > lcl_getComponentContext()
289 {
290 Reference< uno::XComponentContext > xContext;
291 try
292 {
293 Reference< beans::XPropertySet > xFactProp( comphelper::getProcessServiceFactory(), uno::UNO_QUERY );
294 if( xFactProp.is())
295 xFactProp->getPropertyValue(OUString::createFromAscii("DefaultContext")) >>= xContext;
296 }
297 catch( uno::Exception& )
298 {}
299
300 return xContext;
301 }
302
303 class lcl_MatchesRole
304 {
305 public:
306 typedef Reference< chart2::data::XLabeledDataSequence > argument_type;
307 typedef bool result_type;
lcl_MatchesRole(const OUString & aRole)308 explicit lcl_MatchesRole( const OUString & aRole ) :
309 m_aRole( aRole )
310 {}
311
operator ()(const Reference<chart2::data::XLabeledDataSequence> & xSeq) const312 bool operator () ( const Reference< chart2::data::XLabeledDataSequence > & xSeq ) const
313 {
314 if( !xSeq.is() )
315 return false;
316 Reference< beans::XPropertySet > xProp( xSeq->getValues(), uno::UNO_QUERY );
317 OUString aRole;
318
319 return ( xProp.is() &&
320 (xProp->getPropertyValue(
321 OUString( RTL_CONSTASCII_USTRINGPARAM( "Role" )) ) >>= aRole ) &&
322 m_aRole.equals( aRole ));
323 }
324
325 private:
326 OUString m_aRole;
327 };
328
329 template< typename T >
lcl_SequenceToVectorAppend(const Sequence<T> & rSource,::std::vector<T> & rDestination)330 void lcl_SequenceToVectorAppend( const Sequence< T > & rSource, ::std::vector< T > & rDestination )
331 {
332 rDestination.reserve( rDestination.size() + rSource.getLength());
333 ::std::copy( rSource.getConstArray(), rSource.getConstArray() + rSource.getLength(),
334 ::std::back_inserter( rDestination ));
335 }
336
337 template< typename T >
lcl_SequenceToVector(const Sequence<T> & rSource,::std::vector<T> & rDestination)338 void lcl_SequenceToVector( const Sequence< T > & rSource, ::std::vector< T > & rDestination )
339 {
340 rDestination.clear();
341 lcl_SequenceToVectorAppend( rSource, rDestination );
342 }
343
lcl_getCategories(const Reference<chart2::XDiagram> & xDiagram)344 Reference< chart2::data::XLabeledDataSequence > lcl_getCategories( const Reference< chart2::XDiagram > & xDiagram )
345 {
346 Reference< chart2::data::XLabeledDataSequence > xResult;
347 try
348 {
349 Reference< chart2::XCoordinateSystemContainer > xCooSysCnt(
350 xDiagram, uno::UNO_QUERY_THROW );
351 Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq(
352 xCooSysCnt->getCoordinateSystems());
353 for( sal_Int32 i=0; i<aCooSysSeq.getLength(); ++i )
354 {
355 Reference< chart2::XCoordinateSystem > xCooSys( aCooSysSeq[i] );
356 OSL_ASSERT( xCooSys.is());
357 for( sal_Int32 nN = xCooSys->getDimension(); nN--; )
358 {
359 const sal_Int32 nMaxAxisIndex = xCooSys->getMaximumAxisIndexByDimension(nN);
360 for(sal_Int32 nI=0; nI<=nMaxAxisIndex; ++nI)
361 {
362 Reference< chart2::XAxis > xAxis = xCooSys->getAxisByDimension( nN, nI );
363 OSL_ASSERT( xAxis.is());
364 if( xAxis.is())
365 {
366 chart2::ScaleData aScaleData = xAxis->getScaleData();
367 if( aScaleData.Categories.is())
368 {
369 xResult.set( aScaleData.Categories );
370 break;
371 }
372 }
373 }
374 }
375 }
376 }
377 catch( uno::Exception & ex )
378 {
379 (void)ex; // avoid warning for pro build
380 OSL_ENSURE( false, OUStringToOString(
381 OUString( RTL_CONSTASCII_USTRINGPARAM( "Exception caught. Type: " )) +
382 OUString::createFromAscii( typeid( ex ).name()) +
383 OUString( RTL_CONSTASCII_USTRINGPARAM( ", Message: " )) +
384 ex.Message, RTL_TEXTENCODING_ASCII_US ).getStr());
385 }
386
387 return xResult;
388 }
389
lcl_createDataSource(const Sequence<Reference<chart2::data::XLabeledDataSequence>> & aData)390 Reference< chart2::data::XDataSource > lcl_createDataSource(
391 const Sequence< Reference< chart2::data::XLabeledDataSequence > > & aData )
392 {
393 Reference< chart2::data::XDataSink > xSink;
394 Reference< uno::XComponentContext > xContext( lcl_getComponentContext());
395 if( xContext.is() )
396 xSink.set(
397 xContext->getServiceManager()->createInstanceWithContext(
398 OUString::createFromAscii("com.sun.star.chart2.data.DataSource"),
399 xContext ), uno::UNO_QUERY_THROW );
400 if( xSink.is())
401 xSink->setData( aData );
402
403 return Reference< chart2::data::XDataSource >( xSink, uno::UNO_QUERY );
404 }
405
lcl_getAllSeriesSequences(const Reference<chart2::XChartDocument> & xChartDoc)406 Sequence< Reference< chart2::data::XLabeledDataSequence > > lcl_getAllSeriesSequences( const Reference< chart2::XChartDocument >& xChartDoc )
407 {
408 ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aContainer;
409 if( xChartDoc.is() )
410 {
411 Reference< chart2::XDiagram > xDiagram( xChartDoc->getFirstDiagram());
412 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVector( SchXMLSeriesHelper::getDataSeriesFromDiagram( xDiagram ));
413 for( ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aSeriesIt( aSeriesVector.begin() )
414 ; aSeriesIt != aSeriesVector.end(); ++aSeriesIt )
415 {
416 Reference< chart2::data::XDataSource > xDataSource( *aSeriesIt, uno::UNO_QUERY );
417 if( !xDataSource.is() )
418 continue;
419 uno::Sequence< Reference< chart2::data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
420 lcl_SequenceToVectorAppend( aDataSequences, aContainer );
421 }
422 }
423
424 Sequence< Reference< chart2::data::XLabeledDataSequence > > aRet( aContainer.size());
425 ::std::copy( aContainer.begin(), aContainer.end(), aRet.getArray());
426
427 return aRet;
428 }
429
430 Reference< chart2::data::XLabeledDataSequence >
lcl_getDataSequenceByRole(const Sequence<Reference<chart2::data::XLabeledDataSequence>> & aLabeledSeq,const OUString & rRole)431 lcl_getDataSequenceByRole(
432 const Sequence< Reference< chart2::data::XLabeledDataSequence > > & aLabeledSeq,
433 const OUString & rRole )
434 {
435 Reference< chart2::data::XLabeledDataSequence > aNoResult;
436
437 const Reference< chart2::data::XLabeledDataSequence > * pBegin = aLabeledSeq.getConstArray();
438 const Reference< chart2::data::XLabeledDataSequence > * pEnd = pBegin + aLabeledSeq.getLength();
439 const Reference< chart2::data::XLabeledDataSequence > * pMatch =
440 ::std::find_if( pBegin, pEnd, lcl_MatchesRole( rRole ));
441
442 if( pMatch != pEnd )
443 return *pMatch;
444
445 return aNoResult;
446 }
447
lcl_pressUsedDataIntoRectangularFormat(const Reference<chart2::XChartDocument> & xChartDoc,sal_Bool & rOutSourceHasCategoryLabels)448 Reference< chart2::data::XDataSource > lcl_pressUsedDataIntoRectangularFormat( const Reference< chart2::XChartDocument >& xChartDoc, sal_Bool& rOutSourceHasCategoryLabels )
449 {
450 ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aLabeledSeqVector;
451
452 //categories are always the first sequence
453 Reference< chart2::XDiagram > xDiagram( xChartDoc->getFirstDiagram());
454 Reference< chart2::data::XLabeledDataSequence > xCategories( lcl_getCategories( xDiagram ) );
455 if( xCategories.is() )
456 aLabeledSeqVector.push_back( xCategories );
457 rOutSourceHasCategoryLabels = sal_Bool(xCategories.is());
458
459 Sequence< Reference< chart2::data::XLabeledDataSequence > > aSeriesSeqVector(
460 lcl_getAllSeriesSequences( xChartDoc ) );
461
462 //the first x-values is always the next sequence //todo ... other x-values get lost for old format
463 Reference< chart2::data::XLabeledDataSequence > xXValues(
464 lcl_getDataSequenceByRole( aSeriesSeqVector, OUString::createFromAscii("values-x" ) ) );
465 if( xXValues.is() )
466 aLabeledSeqVector.push_back( xXValues );
467
468 //add all other sequences now without x-values
469 lcl_MatchesRole aHasXValues( OUString::createFromAscii("values-x" ) );
470 for( sal_Int32 nN=0; nN<aSeriesSeqVector.getLength(); nN++ )
471 {
472 if( !aHasXValues( aSeriesSeqVector[nN] ) )
473 aLabeledSeqVector.push_back( aSeriesSeqVector[nN] );
474 }
475
476 Sequence< Reference< chart2::data::XLabeledDataSequence > > aSeq( aLabeledSeqVector.size() );
477 ::std::copy( aLabeledSeqVector.begin(), aLabeledSeqVector.end(), aSeq.getArray() );
478
479 return lcl_createDataSource( aSeq );
480 }
481
lcl_isSeriesAttachedToFirstAxis(const Reference<chart2::XDataSeries> & xDataSeries)482 bool lcl_isSeriesAttachedToFirstAxis(
483 const Reference< chart2::XDataSeries > & xDataSeries )
484 {
485 bool bResult=true;
486
487 try
488 {
489 sal_Int32 nAxisIndex = 0;
490 Reference< beans::XPropertySet > xProp( xDataSeries, uno::UNO_QUERY_THROW );
491 if( xProp.is() )
492 xProp->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("AttachedAxisIndex") ) ) >>= nAxisIndex;
493 bResult = (0==nAxisIndex);
494 }
495 catch( uno::Exception & ex )
496 {
497 (void)ex; // avoid warning for pro build
498 OSL_ENSURE( false, OUStringToOString(
499 OUString( RTL_CONSTASCII_USTRINGPARAM( "Exception caught. Type: " )) +
500 OUString::createFromAscii( typeid( ex ).name()) +
501 OUString( RTL_CONSTASCII_USTRINGPARAM( ", Message: " )) +
502 ex.Message, RTL_TEXTENCODING_ASCII_US ).getStr());
503 }
504
505 return bResult;
506 }
507
lcl_ConvertRange(const::rtl::OUString & rRange,const Reference<chart2::XChartDocument> & xDoc)508 OUString lcl_ConvertRange( const ::rtl::OUString & rRange, const Reference< chart2::XChartDocument > & xDoc )
509 {
510 OUString aResult = rRange;
511 if( !xDoc.is() )
512 return aResult;
513 Reference< chart2::data::XRangeXMLConversion > xConversion(
514 xDoc->getDataProvider(), uno::UNO_QUERY );
515 if( xConversion.is())
516 aResult = xConversion->convertRangeToXML( rRange );
517 return aResult;
518 }
519
520 typedef ::std::pair< OUString, OUString > tLabelAndValueRange;
521
lcl_getLabelAndValueRangeByRole(const Sequence<Reference<chart2::data::XLabeledDataSequence>> & aSeqCnt,const OUString & rRole,const Reference<chart2::XChartDocument> & xDoc,SchXMLExportHelper_Impl::tDataSequenceCont & rOutSequencesToExport)522 tLabelAndValueRange lcl_getLabelAndValueRangeByRole(
523 const Sequence< Reference< chart2::data::XLabeledDataSequence > > & aSeqCnt,
524 const OUString & rRole,
525 const Reference< chart2::XChartDocument > & xDoc,
526 SchXMLExportHelper_Impl::tDataSequenceCont & rOutSequencesToExport )
527 {
528 tLabelAndValueRange aResult;
529
530 Reference< chart2::data::XLabeledDataSequence > xLabeledSeq(
531 lcl_getDataSequenceByRole( aSeqCnt, rRole ));
532 if( xLabeledSeq.is())
533 {
534 Reference< chart2::data::XDataSequence > xLabelSeq( xLabeledSeq->getLabel());
535 if( xLabelSeq.is())
536 aResult.first = lcl_ConvertRange( xLabelSeq->getSourceRangeRepresentation(), xDoc );
537
538 Reference< chart2::data::XDataSequence > xValueSeq( xLabeledSeq->getValues());
539 if( xValueSeq.is())
540 aResult.second = lcl_ConvertRange( xValueSeq->getSourceRangeRepresentation(), xDoc );
541
542 if( xLabelSeq.is() || xValueSeq.is())
543 rOutSequencesToExport.push_back( SchXMLExportHelper_Impl::tLabelValuesDataPair( xLabelSeq, xValueSeq ));
544 }
545
546 return aResult;
547 }
548
lcl_getSequenceLengthByRole(const Sequence<Reference<chart2::data::XLabeledDataSequence>> & aSeqCnt,const OUString & rRole)549 sal_Int32 lcl_getSequenceLengthByRole(
550 const Sequence< Reference< chart2::data::XLabeledDataSequence > > & aSeqCnt,
551 const OUString & rRole )
552 {
553 Reference< chart2::data::XLabeledDataSequence > xLabeledSeq(
554 lcl_getDataSequenceByRole( aSeqCnt, rRole ));
555 if( xLabeledSeq.is())
556 {
557 Reference< chart2::data::XDataSequence > xSeq( xLabeledSeq->getValues());
558 return xSeq->getData().getLength();
559 }
560 return 0;
561 }
562
lcl_hasChartType(const Reference<chart2::XDiagram> & xDiagram,const OUString & rChartType)563 bool lcl_hasChartType( const Reference< chart2::XDiagram > & xDiagram, const OUString & rChartType )
564 {
565 try
566 {
567 Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY_THROW );
568 Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems());
569 for( sal_Int32 nCooSysIdx=0; nCooSysIdx<aCooSysSeq.getLength(); ++nCooSysIdx )
570 {
571 Reference< chart2::XChartTypeContainer > xCTCnt( aCooSysSeq[nCooSysIdx], uno::UNO_QUERY_THROW );
572 Sequence< Reference< chart2::XChartType > > aChartTypes( xCTCnt->getChartTypes());
573 for( sal_Int32 nCTIdx=0; nCTIdx<aChartTypes.getLength(); ++nCTIdx )
574 {
575 if( aChartTypes[nCTIdx]->getChartType().equals( rChartType ))
576 return true;
577 }
578 }
579 }
580 catch( uno::Exception & )
581 {
582 DBG_ERROR( "Exception while searching for chart type in diagram" );
583 }
584 return false;
585 }
586
lcl_flattenStringSequence(const Sequence<OUString> & rSequence)587 OUString lcl_flattenStringSequence( const Sequence< OUString > & rSequence )
588 {
589 OUStringBuffer aResult;
590 bool bPrecedeWithSpace = false;
591 for( sal_Int32 nIndex=0; nIndex<rSequence.getLength(); ++nIndex )
592 {
593 if( rSequence[nIndex].getLength())
594 {
595 if( bPrecedeWithSpace )
596 aResult.append( static_cast< sal_Unicode >( ' ' ));
597 aResult.append( rSequence[nIndex] );
598 bPrecedeWithSpace = true;
599 }
600 }
601 return aResult.makeStringAndClear();
602 }
603
lcl_getLabelStringSequence(Sequence<OUString> & rOutLabels,const Reference<chart2::data::XDataSequence> & xLabelSeq)604 void lcl_getLabelStringSequence( Sequence< OUString >& rOutLabels, const Reference< chart2::data::XDataSequence > & xLabelSeq )
605 {
606 uno::Reference< chart2::data::XTextualDataSequence > xTextualDataSequence( xLabelSeq, uno::UNO_QUERY );
607 if( xTextualDataSequence.is())
608 {
609 rOutLabels = xTextualDataSequence->getTextualData();
610 }
611 else if( xLabelSeq.is())
612 {
613 Sequence< uno::Any > aAnies( xLabelSeq->getData());
614 rOutLabels.realloc( aAnies.getLength());
615 for( sal_Int32 i=0; i<aAnies.getLength(); ++i )
616 aAnies[i] >>= rOutLabels[i];
617 }
618 }
619
lcl_getMaxSequenceLength(const SchXMLExportHelper_Impl::tDataSequenceCont & rContainer)620 sal_Int32 lcl_getMaxSequenceLength(
621 const SchXMLExportHelper_Impl::tDataSequenceCont & rContainer )
622 {
623 sal_Int32 nResult = 0;
624 for( SchXMLExportHelper_Impl::tDataSequenceCont::const_iterator aIt( rContainer.begin());
625 aIt != rContainer.end(); ++aIt )
626 {
627 if( aIt->second.is())
628 {
629 sal_Int32 nSeqLength = aIt->second->getData().getLength();
630 if( nSeqLength > nResult )
631 nResult = nSeqLength;
632 }
633 }
634 return nResult;
635 }
636
lcl_DataSequenceToStringSequence(const uno::Reference<chart2::data::XDataSequence> & xDataSequence)637 uno::Sequence< rtl::OUString > lcl_DataSequenceToStringSequence(
638 const uno::Reference< chart2::data::XDataSequence >& xDataSequence )
639 {
640 uno::Sequence< rtl::OUString > aResult;
641 if(!xDataSequence.is())
642 return aResult;
643
644 uno::Reference< chart2::data::XTextualDataSequence > xTextualDataSequence( xDataSequence, uno::UNO_QUERY );
645 if( xTextualDataSequence.is() )
646 {
647 aResult = xTextualDataSequence->getTextualData();
648 }
649 else
650 {
651 uno::Sequence< uno::Any > aValues = xDataSequence->getData();
652 aResult.realloc(aValues.getLength());
653
654 for(sal_Int32 nN=aValues.getLength();nN--;)
655 aValues[nN] >>= aResult[nN];
656 }
657
658 return aResult;
659 }
lcl_getAllValuesFromSequence(const Reference<chart2::data::XDataSequence> & xSeq)660 ::std::vector< double > lcl_getAllValuesFromSequence( const Reference< chart2::data::XDataSequence > & xSeq )
661 {
662 double fNan = 0.0;
663 ::rtl::math::setNan( &fNan );
664 ::std::vector< double > aResult;
665 if(!xSeq.is())
666 return aResult;
667
668 uno::Sequence< double > aValuesSequence;
669 Reference< chart2::data::XNumericalDataSequence > xNumSeq( xSeq, uno::UNO_QUERY );
670 if( xNumSeq.is() )
671 {
672 aValuesSequence = xNumSeq->getNumericalData();
673 }
674 else
675 {
676 Sequence< uno::Any > aAnies( xSeq->getData() );
677 aValuesSequence.realloc( aAnies.getLength() );
678 for( sal_Int32 i=0; i<aAnies.getLength(); ++i )
679 aAnies[i] >>= aValuesSequence[i];
680 }
681
682 //special handling for x-values (if x-values do point to categories, indices are used instead )
683 Reference< beans::XPropertySet > xProp( xSeq, uno::UNO_QUERY );
684 if( xProp.is() )
685 {
686 OUString aRole;
687 xProp->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Role") ) ) >>= aRole;
688 if( aRole.match( OUString( RTL_CONSTASCII_USTRINGPARAM( "values-x") ) ) )
689 {
690 //lcl_clearIfNoValuesButTextIsContained - replace by indices if the values are not appropriate
691 bool bHasValue=false;
692 bool bHasText=false;
693 sal_Int32 nCount = aValuesSequence.getLength();
694 for( sal_Int32 j = 0; j < nCount; ++j )
695 {
696 if( !::rtl::math::isNan( aValuesSequence[j] ) )
697 {
698 bHasValue=true;
699 break;
700 }
701 }
702 if(!bHasValue)
703 {
704 //no double value is countained
705 //is there any text?
706 uno::Sequence< rtl::OUString > aStrings( lcl_DataSequenceToStringSequence( xSeq ) );
707 sal_Int32 nTextCount = aStrings.getLength();
708 for( sal_Int32 j = 0; j < nTextCount; ++j )
709 {
710 if( aStrings[j].getLength() )
711 {
712 bHasText=true;
713 break;
714 }
715 }
716 }
717 if( !bHasValue && bHasText )
718 {
719 for( sal_Int32 j = 0; j < nCount; ++j )
720 aValuesSequence[j] = j+1;
721 }
722 }
723 }
724
725 ::std::copy( aValuesSequence.getConstArray(), aValuesSequence.getConstArray() + aValuesSequence.getLength(),
726 ::std::back_inserter( aResult ));
727 return aResult;
728 }
729
lcl_SequenceHasUnhiddenData(const uno::Reference<chart2::data::XDataSequence> & xDataSequence)730 bool lcl_SequenceHasUnhiddenData( const uno::Reference< chart2::data::XDataSequence >& xDataSequence )
731 {
732 if( !xDataSequence.is() )
733 return false;
734 uno::Reference< beans::XPropertySet > xProp( xDataSequence, uno::UNO_QUERY );
735 if( xProp.is() )
736 {
737 uno::Sequence< sal_Int32 > aHiddenValues;
738 try
739 {
740 xProp->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "HiddenValues" ) ) ) >>= aHiddenValues;
741 if( !aHiddenValues.getLength() )
742 return true;
743 }
744 catch( uno::Exception& e )
745 {
746 (void)e; // avoid warning
747 return true;
748 }
749 }
750 if( xDataSequence->getData().getLength() )
751 return true;
752 return false;
753 }
754
755 typedef vector< OUString > tStringVector;
756 typedef vector< double > tDoubleVector;
757 typedef vector< vector< OUString > > t2DStringVector;
758 typedef vector< vector< double > > t2DNumberContainer;
759
760 struct lcl_TableData
761 {
762 t2DNumberContainer aDataInRows;
763 tStringVector aDataRangeRepresentations;
764
765 tStringVector aColumnDescriptions;
766 tStringVector aColumnDescriptions_Ranges;
767
768 tStringVector aRowDescriptions;
769 tStringVector aRowDescriptions_Ranges;
770
771 Sequence< Sequence< uno::Any > > aComplexColumnDescriptions;//outer index is columns - inner index is level
772 Sequence< Sequence< uno::Any > > aComplexRowDescriptions;//outer index is rows - inner index is level
773
774 ::std::vector< sal_Int32 > aHiddenColumns;
775 };
776
777 // Function object that binds the size and default value for T::resize.
778 template< class T >
779 struct lcl_resize
780 {
lcl_resize__anon2a707c240111::lcl_resize781 lcl_resize( typename T::size_type nSize, typename T::value_type fDefaultValue ) : m_nSize( nSize ), m_fDefaultValue( fDefaultValue ) {}
operator ()__anon2a707c240111::lcl_resize782 void operator()( T & t )
783 { t.resize( m_nSize, m_fDefaultValue ); }
784 private:
785 typename T::size_type m_nSize;
786 typename T::value_type m_fDefaultValue;
787 };
788
789
790 typedef ::std::map< sal_Int32, SchXMLExportHelper_Impl::tLabelValuesDataPair >
791 lcl_DataSequenceMap;
792
793 struct lcl_SequenceToMapElement
794 {
795 typedef lcl_DataSequenceMap::mapped_type argument_type;
796 typedef lcl_DataSequenceMap::value_type result_type;
lcl_SequenceToMapElement__anon2a707c240111::lcl_SequenceToMapElement797 lcl_SequenceToMapElement()
798 {}
operator ()__anon2a707c240111::lcl_SequenceToMapElement799 result_type operator() ( const argument_type & rContent )
800 {
801 sal_Int32 nIndex = -1;
802 if( rContent.second.is()) //has values
803 {
804 OUString aRangeRep( rContent.second->getSourceRangeRepresentation());
805 nIndex = aRangeRep.toInt32();
806 }
807 else if( rContent.first.is()) //has labels
808 nIndex = rContent.first->getSourceRangeRepresentation().copy( sizeof("label ")).toInt32();
809 return result_type( nIndex, rContent );
810 }
811 };
812
lcl_ReorderInternalSequencesAccordingToTheirRangeName(SchXMLExportHelper_Impl::tDataSequenceCont & rInOutSequences)813 void lcl_ReorderInternalSequencesAccordingToTheirRangeName(
814 SchXMLExportHelper_Impl::tDataSequenceCont & rInOutSequences )
815 {
816 lcl_DataSequenceMap aIndexSequenceMap;
817 ::std::transform( rInOutSequences.begin(), rInOutSequences.end(),
818 ::std::inserter( aIndexSequenceMap, aIndexSequenceMap.begin()),
819 lcl_SequenceToMapElement());
820
821 rInOutSequences.clear();
822 sal_Int32 nIndex = 0;
823 for( lcl_DataSequenceMap::const_iterator aIt = aIndexSequenceMap.begin();
824 aIt != aIndexSequenceMap.end(); ++aIt, ++nIndex )
825 {
826 if( aIt->first < 0 )
827 continue;
828 // fill empty columns
829 for( ; nIndex < aIt->first; ++nIndex )
830 rInOutSequences.push_back(
831 SchXMLExportHelper_Impl::tDataSequenceCont::value_type( 0, 0 ));
832 OSL_ASSERT( nIndex == aIt->first );
833 rInOutSequences.push_back( aIt->second );
834 }
835 }
836
837
lcl_getDataForLocalTable(const SchXMLExportHelper_Impl::tDataSequenceCont & aSequencesToExport,const Reference<chart2::XAnyDescriptionAccess> & xAnyDescriptionAccess,const OUString & rCategoriesRange,bool bSeriesFromColumns,const Reference<chart2::data::XRangeXMLConversion> & xRangeConversion)838 lcl_TableData lcl_getDataForLocalTable(
839 const SchXMLExportHelper_Impl::tDataSequenceCont & aSequencesToExport,
840 const Reference< chart2::XAnyDescriptionAccess >& xAnyDescriptionAccess,
841 const OUString& rCategoriesRange,
842 bool bSeriesFromColumns,
843 const Reference< chart2::data::XRangeXMLConversion > & xRangeConversion )
844 {
845 lcl_TableData aResult;
846
847 try
848 {
849 Sequence< OUString > aSimpleCategories;
850 if( xAnyDescriptionAccess.is() )
851 {
852 //categories
853 if( bSeriesFromColumns )
854 {
855 aSimpleCategories = xAnyDescriptionAccess->getRowDescriptions();
856 aResult.aComplexRowDescriptions = xAnyDescriptionAccess->getAnyRowDescriptions();
857 }
858 else
859 {
860 aSimpleCategories = xAnyDescriptionAccess->getColumnDescriptions();
861 aResult.aComplexColumnDescriptions = xAnyDescriptionAccess->getAnyColumnDescriptions();
862 }
863 }
864
865 //series values and series labels
866 SchXMLExportHelper_Impl::tDataSequenceCont::size_type nNumSequences = aSequencesToExport.size();
867 SchXMLExportHelper_Impl::tDataSequenceCont::const_iterator aBegin( aSequencesToExport.begin());
868 SchXMLExportHelper_Impl::tDataSequenceCont::const_iterator aEnd( aSequencesToExport.end());
869 SchXMLExportHelper_Impl::tDataSequenceCont::const_iterator aIt( aBegin );
870
871 size_t nMaxSequenceLength( lcl_getMaxSequenceLength( aSequencesToExport ));
872 size_t nCategoriesLength( aSimpleCategories.getLength() );
873 if( nCategoriesLength > nMaxSequenceLength )
874 {
875 aSimpleCategories.realloc(nMaxSequenceLength);//#i110617#
876 nCategoriesLength = nMaxSequenceLength;
877 }
878 size_t nNumColumns( bSeriesFromColumns ? nNumSequences : nMaxSequenceLength );
879 size_t nNumRows( bSeriesFromColumns ? nMaxSequenceLength : nNumSequences );
880
881 // resize data
882 aResult.aDataInRows.resize( nNumRows );
883 double fNan = 0.0;
884 ::rtl::math::setNan( &fNan );
885 ::std::for_each( aResult.aDataInRows.begin(), aResult.aDataInRows.end(),
886 lcl_resize< t2DNumberContainer::value_type >( nNumColumns, fNan ));
887 aResult.aColumnDescriptions.resize( nNumColumns );
888 aResult.aComplexColumnDescriptions.realloc( nNumColumns );
889 aResult.aRowDescriptions.resize( nNumRows );
890 aResult.aComplexRowDescriptions.realloc( nNumRows );
891
892 tStringVector& rCategories = bSeriesFromColumns ? aResult.aRowDescriptions : aResult.aColumnDescriptions;
893 tStringVector& rLabels = bSeriesFromColumns ? aResult.aColumnDescriptions : aResult.aRowDescriptions;
894
895 //categories
896 lcl_SequenceToVector( aSimpleCategories, rCategories );
897 if( rCategoriesRange.getLength() )
898 {
899 OUString aRange(rCategoriesRange);
900 if( xRangeConversion.is())
901 aRange = xRangeConversion->convertRangeToXML( aRange );
902 if( bSeriesFromColumns )
903 aResult.aRowDescriptions_Ranges.push_back( aRange );
904 else
905 aResult.aColumnDescriptions_Ranges.push_back( aRange );
906 }
907
908 // iterate over all sequences
909 size_t nSeqIdx = 0;
910 Sequence< Sequence< OUString > > aComplexLabels(nNumSequences);
911 for( ; aIt != aEnd; ++aIt, ++nSeqIdx )
912 {
913 OUString aRange;
914 Sequence< OUString >& rCurrentComplexLabel = aComplexLabels[nSeqIdx];
915 if( aIt->first.is())
916 {
917 lcl_getLabelStringSequence( rCurrentComplexLabel, aIt->first );
918 rLabels[nSeqIdx] = lcl_flattenStringSequence( rCurrentComplexLabel );
919 aRange = aIt->first->getSourceRangeRepresentation();
920 if( xRangeConversion.is())
921 aRange = xRangeConversion->convertRangeToXML( aRange );
922 }
923 else if( aIt->second.is())
924 {
925 rCurrentComplexLabel.realloc(1);
926 rLabels[nSeqIdx] = rCurrentComplexLabel[0] = lcl_flattenStringSequence(
927 aIt->second->generateLabel( chart2::data::LabelOrigin_SHORT_SIDE ));
928 }
929 if( bSeriesFromColumns )
930 aResult.aColumnDescriptions_Ranges.push_back( aRange );
931 else
932 aResult.aRowDescriptions_Ranges.push_back( aRange );
933
934 ::std::vector< double > aNumbers( lcl_getAllValuesFromSequence( aIt->second ));
935 if( bSeriesFromColumns )
936 {
937 const sal_Int32 nSize( static_cast< sal_Int32 >( aNumbers.size()));
938 for( sal_Int32 nIdx=0; nIdx<nSize; ++nIdx )
939 aResult.aDataInRows[nIdx][nSeqIdx] = aNumbers[nIdx];
940 }
941 else
942 aResult.aDataInRows[nSeqIdx] = aNumbers;
943
944 if( aIt->second.is())
945 {
946 aRange = aIt->second->getSourceRangeRepresentation();
947 if( xRangeConversion.is())
948 aRange = xRangeConversion->convertRangeToXML( aRange );
949 }
950 aResult.aDataRangeRepresentations.push_back( aRange );
951
952 //is column hidden?
953 if( !lcl_SequenceHasUnhiddenData(aIt->first) && !lcl_SequenceHasUnhiddenData(aIt->second) )
954 aResult.aHiddenColumns.push_back(nSeqIdx);
955 }
956 Sequence< Sequence< Any > >& rComplexAnyLabels = bSeriesFromColumns ? aResult.aComplexColumnDescriptions : aResult.aComplexRowDescriptions;//#i116544#
957 rComplexAnyLabels.realloc(aComplexLabels.getLength());
958 for( sal_Int32 nN=0; nN<aComplexLabels.getLength();nN++ )
959 {
960 Sequence< OUString >& rSource = aComplexLabels[nN];
961 Sequence< Any >& rTarget = rComplexAnyLabels[nN];
962 rTarget.realloc( rSource.getLength() );
963 for( sal_Int32 i=0; i<rSource.getLength(); i++ )
964 rTarget[i] = uno::makeAny( rSource[i] );
965 }
966 }
967 catch( uno::Exception & rEx )
968 {
969 (void)rEx; // avoid warning for pro build
970 OSL_TRACE( OUStringToOString( OUString( RTL_CONSTASCII_USTRINGPARAM(
971 "something went wrong during table data collection: " )) + rEx.Message, RTL_TEXTENCODING_ASCII_US ).getStr());
972 }
973
974 return aResult;
975 }
976
lcl_exportNumberFormat(const OUString & rPropertyName,const Reference<beans::XPropertySet> & xPropSet,SvXMLExport & rExport)977 void lcl_exportNumberFormat( const OUString& rPropertyName, const Reference< beans::XPropertySet >& xPropSet,
978 SvXMLExport& rExport )
979 {
980 if( xPropSet.is())
981 {
982 sal_Int32 nNumberFormat = 0;
983 Any aNumAny = xPropSet->getPropertyValue( rPropertyName );
984 if( (aNumAny >>= nNumberFormat) && (nNumberFormat != -1) )
985 rExport.addDataStyle( nNumberFormat );
986 }
987 }
988
989 ::std::vector< Reference< chart2::data::XDataSequence > >
lcl_getErrorBarSequences(const Reference<beans::XPropertySet> & xErrorBarProp)990 lcl_getErrorBarSequences( const Reference< beans::XPropertySet > & xErrorBarProp )
991 {
992 ::std::vector< Reference< chart2::data::XDataSequence > > aResult;
993 Reference< chart2::data::XDataSource > xErrorBarDataSource( xErrorBarProp, uno::UNO_QUERY );
994 if( !xErrorBarDataSource.is())
995 return aResult;
996
997 const OUString aRolePrefix( RTL_CONSTASCII_USTRINGPARAM( "error-bars-" ));
998 // const OUString aXRolePrefix( aRolePrefix + OUString( RTL_CONSTASCII_USTRINGPARAM( "x-" )));
999 // const OUString aYRolePrefix( aRolePrefix + OUString( RTL_CONSTASCII_USTRINGPARAM( "y-" )));
1000 // const OUString aPositivePostfix( RTL_CONSTASCII_USTRINGPARAM( "positive" ));
1001 // const OUString aNegativePostfix( RTL_CONSTASCII_USTRINGPARAM( "negative" ));
1002
1003 Sequence< Reference< chart2::data::XLabeledDataSequence > > aSequences(
1004 xErrorBarDataSource->getDataSequences());
1005 for( sal_Int32 nI=0; nI< aSequences.getLength(); ++nI )
1006 {
1007 try
1008 {
1009 if( aSequences[nI].is())
1010 {
1011 Reference< chart2::data::XDataSequence > xSequence( aSequences[nI]->getValues());
1012 Reference< beans::XPropertySet > xSeqProp( xSequence, uno::UNO_QUERY_THROW );
1013 OUString aRole;
1014 if( ( xSeqProp->getPropertyValue(
1015 OUString( RTL_CONSTASCII_USTRINGPARAM( "Role" ))) >>= aRole ) &&
1016 aRole.match( aRolePrefix ))
1017 {
1018 aResult.push_back( xSequence );
1019 }
1020 }
1021 }
1022 catch( uno::Exception & rEx )
1023 {
1024 #ifdef DBG_UTIL
1025 String aStr( rEx.Message );
1026 ByteString aBStr( aStr, RTL_TEXTENCODING_ASCII_US );
1027 DBG_ERROR1( "chart:exporting error bar ranges: %s", aBStr.GetBuffer());
1028 #else
1029 (void)rEx; // avoid warning
1030 #endif
1031 }
1032 }
1033
1034 return aResult;
1035 }
1036
lcl_exportDomainForThisSequence(const Reference<chart2::data::XDataSequence> xValues,rtl::OUString & rFirstRangeForThisDomainIndex,SvXMLExport & rExport)1037 bool lcl_exportDomainForThisSequence( const Reference< chart2::data::XDataSequence > xValues, rtl::OUString& rFirstRangeForThisDomainIndex, SvXMLExport& rExport )
1038 {
1039 bool bDomainExported = false;
1040 if( xValues.is())
1041 {
1042 Reference< chart2::XChartDocument > xNewDoc( rExport.GetModel(), uno::UNO_QUERY );
1043 OUString aRange( lcl_ConvertRange( xValues->getSourceRangeRepresentation(), xNewDoc ) );
1044
1045 //work around error in OOo 2.0 (problems with multiple series having a domain element)
1046 if( !rFirstRangeForThisDomainIndex.getLength() || !aRange.equals(rFirstRangeForThisDomainIndex) )
1047 {
1048 rExport.AddAttribute( XML_NAMESPACE_TABLE, XML_CELL_RANGE_ADDRESS, aRange);
1049 SvXMLElementExport aDomain( rExport, XML_NAMESPACE_CHART, XML_DOMAIN, sal_True, sal_True );
1050 bDomainExported = true;
1051 }
1052
1053 if( !rFirstRangeForThisDomainIndex.getLength() )
1054 rFirstRangeForThisDomainIndex = aRange;
1055 }
1056 return bDomainExported;
1057 }
1058
1059 } // anonymous namespace
1060
1061 struct SchXMLDataPointStruct
1062 {
1063 OUString maStyleName;
1064 sal_Int32 mnRepeat;
1065
SchXMLDataPointStructSchXMLDataPointStruct1066 SchXMLDataPointStruct() : mnRepeat( 1 ) {}
1067 };
1068
1069 // ========================================
1070 // class SchXMLExportHelper
1071 // ========================================
1072
SchXMLExportHelper(SvXMLExport & rExport,SvXMLAutoStylePoolP & rASPool)1073 SchXMLExportHelper::SchXMLExportHelper( SvXMLExport& rExport, SvXMLAutoStylePoolP& rASPool )
1074 : m_pImpl( new SchXMLExportHelper_Impl( rExport, rASPool ) )
1075 {
1076 }
1077
~SchXMLExportHelper()1078 SchXMLExportHelper::~SchXMLExportHelper()
1079 {
1080 delete m_pImpl;
1081 }
1082
getChartCLSID()1083 const OUString& SchXMLExportHelper::getChartCLSID()
1084 {
1085 return m_pImpl->msCLSID;
1086 }
1087
GetPropertySetMapper() const1088 UniReference< XMLPropertySetMapper > SchXMLExportHelper_Impl::GetPropertySetMapper() const
1089 {
1090 return mxPropertySetMapper;
1091 }
1092
exportAutoStyles()1093 void SchXMLExportHelper_Impl::exportAutoStyles()
1094 {
1095 if( mxExpPropMapper.is())
1096 {
1097 //ToDo: when embedded in calc/writer this is not necessary because the
1098 // numberformatter is shared between both documents
1099 mrExport.exportAutoDataStyles();
1100
1101 // export chart auto styles
1102 mrAutoStylePool.exportXML(
1103 XML_STYLE_FAMILY_SCH_CHART_ID
1104 , mrExport.GetDocHandler(),
1105 mrExport.GetMM100UnitConverter(),
1106 mrExport.GetNamespaceMap()
1107 );
1108
1109 // export auto styles for additional shapes
1110 mrExport.GetShapeExport()->exportAutoStyles();
1111 // and for text in additional shapes
1112 mrExport.GetTextParagraphExport()->exportTextAutoStyles();
1113 }
1114 }
1115
1116 // private methods
1117 // ---------------
1118
SchXMLExportHelper_Impl(SvXMLExport & rExport,SvXMLAutoStylePoolP & rASPool)1119 SchXMLExportHelper_Impl::SchXMLExportHelper_Impl(
1120 SvXMLExport& rExport,
1121 SvXMLAutoStylePoolP& rASPool ) :
1122 mrExport( rExport ),
1123 mrAutoStylePool( rASPool ),
1124 mbHasSeriesLabels( sal_False ),
1125 mbHasCategoryLabels( sal_False ),
1126 mbRowSourceColumns( sal_True )
1127 // #110680#
1128 // this id depends on the ServiceManager used due to the binary filter stripping.
1129 // ,msCLSID( rtl::OUString( SvGlobalName( SO3_SCH_CLASSID ).GetHexName()))
1130 {
1131 // #110680#
1132 // changed initialisation for msCLSID. Compare the ServiceInfo name with
1133 // the known name of the LegacyServiceManager.
1134 Reference<lang::XServiceInfo> xServiceInfo( mrExport.getServiceFactory(), uno::UNO_QUERY );
1135 DBG_ASSERT( xServiceInfo.is(), "XMultiServiceFactory without xServiceInfo (!)" );
1136 OUString rdbURL = xServiceInfo->getImplementationName();
1137 OUString implLegacyServiceManagerName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.office.LegacyServiceManager" ) );
1138
1139 if( rdbURL.equals( implLegacyServiceManagerName ))
1140 {
1141 msCLSID = OUString( SvGlobalName( BF_SO3_SCH_CLASSID ).GetHexName());
1142 }
1143 else
1144 {
1145 msCLSID = OUString( SvGlobalName( SO3_SCH_CLASSID ).GetHexName());
1146 }
1147
1148 msTableName = OUString::createFromAscii( "local-table" );
1149
1150 // create factory
1151 mxPropertyHandlerFactory = new XMLChartPropHdlFactory;
1152
1153 if( mxPropertyHandlerFactory.is() )
1154 {
1155 // create property set mapper
1156 mxPropertySetMapper = new XMLChartPropertySetMapper;
1157 }
1158
1159 mxExpPropMapper = new XMLChartExportPropertyMapper( mxPropertySetMapper, rExport );
1160
1161 // register chart auto-style family
1162 mrAutoStylePool.AddFamily(
1163 XML_STYLE_FAMILY_SCH_CHART_ID,
1164 OUString::createFromAscii( XML_STYLE_FAMILY_SCH_CHART_NAME ),
1165 mxExpPropMapper.get(),
1166 OUString::createFromAscii( XML_STYLE_FAMILY_SCH_CHART_PREFIX ));
1167
1168 // register shape family
1169 mrAutoStylePool.AddFamily(
1170 XML_STYLE_FAMILY_SD_GRAPHICS_ID,
1171 OUString::createFromAscii( XML_STYLE_FAMILY_SD_GRAPHICS_NAME ),
1172 mxExpPropMapper.get(),
1173 OUString::createFromAscii( XML_STYLE_FAMILY_SD_GRAPHICS_PREFIX ));
1174 // register paragraph family also for shapes
1175 mrAutoStylePool.AddFamily(
1176 XML_STYLE_FAMILY_TEXT_PARAGRAPH,
1177 GetXMLToken( XML_PARAGRAPH ),
1178 mxExpPropMapper.get(),
1179 String( 'P' ));
1180 // register text family also for shapes
1181 mrAutoStylePool.AddFamily(
1182 XML_STYLE_FAMILY_TEXT_TEXT,
1183 GetXMLToken( XML_TEXT ),
1184 mxExpPropMapper.get(),
1185 String( 'T' ));
1186 }
1187
~SchXMLExportHelper_Impl()1188 SchXMLExportHelper_Impl::~SchXMLExportHelper_Impl()
1189 {
1190 }
1191
collectAutoStyles(Reference<chart::XChartDocument> rChartDoc)1192 void SchXMLExportHelper_Impl::collectAutoStyles( Reference< chart::XChartDocument > rChartDoc )
1193 {
1194 parseDocument( rChartDoc, sal_False );
1195 }
1196
exportChart(Reference<chart::XChartDocument> rChartDoc,sal_Bool bIncludeTable)1197 void SchXMLExportHelper_Impl::exportChart( Reference< chart::XChartDocument > rChartDoc,
1198 sal_Bool bIncludeTable )
1199 {
1200 parseDocument( rChartDoc, sal_True, bIncludeTable );
1201 DBG_ASSERT( maAutoStyleNameQueue.empty(), "There are still remaining autostyle names in the queue" );
1202 }
1203
lcl_GetStringFromNumberSequence(const::com::sun::star::uno::Sequence<sal_Int32> & rSequenceMapping,bool bRemoveOneFromEachIndex)1204 ::rtl::OUString lcl_GetStringFromNumberSequence( const ::com::sun::star::uno::Sequence< sal_Int32 >& rSequenceMapping, bool bRemoveOneFromEachIndex /*should be true if having categories*/ )
1205 {
1206 const sal_Int32* pArray = rSequenceMapping.getConstArray();
1207 const sal_Int32 nSize = rSequenceMapping.getLength();
1208 sal_Int32 i = 0;
1209 OUStringBuffer aBuf;
1210 bool bHasPredecessor = false;
1211 for( i = 0; i < nSize; ++i )
1212 {
1213 sal_Int32 nIndex = pArray[ i ];
1214 if( bRemoveOneFromEachIndex )
1215 --nIndex;
1216 if(nIndex>=0)
1217 {
1218 if(bHasPredecessor)
1219 aBuf.append( static_cast< sal_Unicode >( ' ' ));
1220 aBuf.append( nIndex, 10 );
1221 bHasPredecessor = true;
1222 }
1223 }
1224 return aBuf.makeStringAndClear();
1225 }
1226
1227 /// if bExportContent is false the auto-styles are collected
parseDocument(Reference<chart::XChartDocument> & rChartDoc,sal_Bool bExportContent,sal_Bool bIncludeTable)1228 void SchXMLExportHelper_Impl::parseDocument( Reference< chart::XChartDocument >& rChartDoc,
1229 sal_Bool bExportContent,
1230 sal_Bool bIncludeTable )
1231 {
1232 Reference< chart2::XChartDocument > xNewDoc( rChartDoc, uno::UNO_QUERY );
1233 if( !rChartDoc.is() || !xNewDoc.is() )
1234 {
1235 DBG_ERROR( "No XChartDocument was given for export." );
1236 return;
1237 }
1238
1239 awt::Size aPageSize( getPageSize( xNewDoc ));
1240 if( bExportContent )
1241 addSize( aPageSize );
1242 Reference< chart::XDiagram > xDiagram = rChartDoc->getDiagram();
1243 Reference< chart2::XDiagram > xNewDiagram;
1244 if( xNewDoc.is())
1245 xNewDiagram.set( xNewDoc->getFirstDiagram());
1246
1247 //todo remove if model changes are notified and view is updated automatically
1248 if( bExportContent )
1249 {
1250 Reference< util::XRefreshable > xRefreshable( xNewDoc, uno::UNO_QUERY );
1251 if( xRefreshable.is() )
1252 xRefreshable->refresh();
1253 }
1254
1255 // get Properties of ChartDocument
1256 sal_Bool bHasMainTitle = sal_False;
1257 sal_Bool bHasSubTitle = sal_False;
1258 sal_Bool bHasLegend = sal_False;
1259 util::DateTime aNullDate(0,0,0,0,30,12,1899);
1260
1261 std::vector< XMLPropertyState > aPropertyStates;
1262
1263 Reference< beans::XPropertySet > xDocPropSet( rChartDoc, uno::UNO_QUERY );
1264 if( xDocPropSet.is())
1265 {
1266 try
1267 {
1268 Any aAny( xDocPropSet->getPropertyValue(
1269 OUString( RTL_CONSTASCII_USTRINGPARAM( "HasMainTitle" ))));
1270 aAny >>= bHasMainTitle;
1271 aAny = xDocPropSet->getPropertyValue(
1272 OUString( RTL_CONSTASCII_USTRINGPARAM( "HasSubTitle" )));
1273 aAny >>= bHasSubTitle;
1274 aAny = xDocPropSet->getPropertyValue(
1275 OUString( RTL_CONSTASCII_USTRINGPARAM( "HasLegend" )));
1276 aAny >>= bHasLegend;
1277 if ( bIncludeTable )
1278 {
1279 OUString sNullDate( RTL_CONSTASCII_USTRINGPARAM( "NullDate" ));
1280 aAny = xDocPropSet->getPropertyValue(sNullDate);
1281 if ( !aAny.hasValue() )
1282 {
1283 Reference<container::XChild> xChild(rChartDoc, uno::UNO_QUERY );
1284 if ( xChild.is() )
1285 {
1286 Reference< beans::XPropertySet > xParentDoc( xChild->getParent(),uno::UNO_QUERY);
1287 if ( xParentDoc.is() && xParentDoc->getPropertySetInfo()->hasPropertyByName(sNullDate) )
1288 aAny = xParentDoc->getPropertyValue(sNullDate);
1289 }
1290 }
1291
1292 aAny >>= aNullDate;
1293 }
1294 }
1295 catch( beans::UnknownPropertyException & )
1296 {
1297 DBG_WARNING( "Required property not found in ChartDocument" );
1298 }
1299 } // if( xDocPropSet.is())
1300
1301 if ( bIncludeTable && (aNullDate.Day != 30 || aNullDate.Month != 12 || aNullDate.Year != 1899 ) )
1302 {
1303 SvXMLElementExport aSet( mrExport, XML_NAMESPACE_TABLE, XML_CALCULATION_SETTINGS, sal_True, sal_True );
1304 {
1305 ::rtl::OUStringBuffer sBuffer;
1306 SvXMLUnitConverter::convertDateTime(sBuffer,aNullDate);
1307 mrExport.AddAttribute( XML_NAMESPACE_TABLE,XML_DATE_VALUE,sBuffer.makeStringAndClear());
1308 SvXMLElementExport aNull( mrExport, XML_NAMESPACE_TABLE, XML_NULL_DATE, sal_True, sal_True );
1309 }
1310 }
1311
1312 // chart element
1313 // -------------
1314
1315 SvXMLElementExport* pElChart = 0;
1316 // get property states for autostyles
1317 if( mxExpPropMapper.is())
1318 {
1319 Reference< beans::XPropertySet > xPropSet( rChartDoc->getArea(), uno::UNO_QUERY );
1320 if( xPropSet.is())
1321 aPropertyStates = mxExpPropMapper->Filter( xPropSet );
1322 }
1323
1324 if( bExportContent )
1325 {
1326 //export data provider in xlink:href attribute
1327 const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() );
1328 if( nCurrentODFVersion >= SvtSaveOptions::ODFVER_012 )
1329 {
1330 OUString aDataProviderURL( RTL_CONSTASCII_USTRINGPARAM( ".." ) );
1331 if( xNewDoc->hasInternalDataProvider() )
1332 aDataProviderURL = OUString( RTL_CONSTASCII_USTRINGPARAM( "." ) );
1333 else //special handling for data base data provider necessary
1334 {
1335 Reference< chart2::data::XDatabaseDataProvider > xDBDataProvider( xNewDoc->getDataProvider(), uno::UNO_QUERY );
1336 if( xDBDataProvider.is() )
1337 aDataProviderURL = OUString( RTL_CONSTASCII_USTRINGPARAM( "." ) );
1338 }
1339 mrExport.AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, aDataProviderURL );
1340 mrExport.AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
1341 }
1342
1343 OUString sChartType( xDiagram->getDiagramType() );
1344
1345 // attributes
1346 // determine class
1347 if( sChartType.getLength())
1348 {
1349 enum XMLTokenEnum eXMLChartType = SchXMLTools::getTokenByChartType( sChartType, true /* bUseOldNames */ );
1350
1351 DBG_ASSERT( eXMLChartType != XML_TOKEN_INVALID, "invalid chart class" );
1352 if( eXMLChartType == XML_TOKEN_INVALID )
1353 eXMLChartType = XML_BAR;
1354
1355 if( eXMLChartType == XML_ADD_IN )
1356 {
1357 // sChartType is the servie-name of the add-in
1358 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_CLASS,
1359 mrExport.GetNamespaceMap().GetQNameByKey(
1360 XML_NAMESPACE_OOO, sChartType) );
1361 }
1362 else if( eXMLChartType != XML_TOKEN_INVALID )
1363 {
1364 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_CLASS,
1365 mrExport.GetNamespaceMap().GetQNameByKey(
1366 XML_NAMESPACE_CHART, GetXMLToken(eXMLChartType )) );
1367 }
1368
1369 //column-mapping or row-mapping
1370 if( maSequenceMapping.getLength() )
1371 {
1372 enum XMLTokenEnum eTransToken = ::xmloff::token::XML_ROW_MAPPING;
1373 if( mbRowSourceColumns )
1374 eTransToken = ::xmloff::token::XML_COLUMN_MAPPING;
1375 ::rtl::OUString aSequenceMappingStr( lcl_GetStringFromNumberSequence(
1376 maSequenceMapping, mbHasCategoryLabels && !xNewDoc->hasInternalDataProvider() ) );
1377
1378 mrExport.AddAttribute( XML_NAMESPACE_CHART,
1379 ::xmloff::token::GetXMLToken( eTransToken ),
1380 aSequenceMappingStr );
1381 }
1382 }
1383 // write style name
1384 AddAutoStyleAttribute( aPropertyStates );
1385
1386 //element
1387 pElChart = new SvXMLElementExport( mrExport, XML_NAMESPACE_CHART, XML_CHART, sal_True, sal_True );
1388 }
1389 else // autostyles
1390 {
1391 CollectAutoStyle( aPropertyStates );
1392 }
1393 // remove property states for autostyles
1394 aPropertyStates.clear();
1395
1396 // title element
1397 // -------------
1398
1399 if( bHasMainTitle )
1400 {
1401 // get property states for autostyles
1402 if( mxExpPropMapper.is())
1403 {
1404 Reference< beans::XPropertySet > xPropSet( rChartDoc->getTitle(), uno::UNO_QUERY );
1405 if( xPropSet.is())
1406 aPropertyStates = mxExpPropMapper->Filter( xPropSet );
1407 }
1408 if( bExportContent )
1409 {
1410 Reference< drawing::XShape > xShape = rChartDoc->getTitle();
1411 if( xShape.is()) // && "hasTitleBeenMoved"
1412 addPosition( xShape );
1413
1414 // write style name
1415 AddAutoStyleAttribute( aPropertyStates );
1416
1417 // element
1418 SvXMLElementExport aElTitle( mrExport, XML_NAMESPACE_CHART, XML_TITLE, sal_True, sal_True );
1419
1420 // content (text:p)
1421 Reference< beans::XPropertySet > xPropSet( xShape, uno::UNO_QUERY );
1422 if( xPropSet.is())
1423 {
1424 Any aAny( xPropSet->getPropertyValue(
1425 OUString( RTL_CONSTASCII_USTRINGPARAM( "String" ))));
1426 OUString aText;
1427 aAny >>= aText;
1428 exportText( aText );
1429 }
1430 }
1431 else // autostyles
1432 {
1433 CollectAutoStyle( aPropertyStates );
1434 }
1435 // remove property states for autostyles
1436 aPropertyStates.clear();
1437 }
1438
1439 // subtitle element
1440 // ----------------
1441
1442 if( bHasSubTitle )
1443 {
1444 // get property states for autostyles
1445 if( mxExpPropMapper.is())
1446 {
1447 Reference< beans::XPropertySet > xPropSet( rChartDoc->getSubTitle(), uno::UNO_QUERY );
1448 if( xPropSet.is())
1449 aPropertyStates = mxExpPropMapper->Filter( xPropSet );
1450 }
1451
1452 if( bExportContent )
1453 {
1454 Reference< drawing::XShape > xShape = rChartDoc->getSubTitle();
1455 if( xShape.is())
1456 addPosition( xShape );
1457
1458 // write style name
1459 AddAutoStyleAttribute( aPropertyStates );
1460
1461 // element (has no subelements)
1462 SvXMLElementExport aElSubTitle( mrExport, XML_NAMESPACE_CHART, XML_SUBTITLE, sal_True, sal_True );
1463
1464 // content (text:p)
1465 Reference< beans::XPropertySet > xPropSet( xShape, uno::UNO_QUERY );
1466 if( xPropSet.is())
1467 {
1468 Any aAny( xPropSet->getPropertyValue(
1469 OUString( RTL_CONSTASCII_USTRINGPARAM( "String" ))));
1470 OUString aText;
1471 aAny >>= aText;
1472 exportText( aText );
1473 }
1474 }
1475 else // autostyles
1476 {
1477 CollectAutoStyle( aPropertyStates );
1478 }
1479 // remove property states for autostyles
1480 aPropertyStates.clear();
1481 }
1482
1483 // legend element
1484 // --------------
1485 if( bHasLegend )
1486 {
1487 // get property states for autostyles
1488 if( mxExpPropMapper.is())
1489 {
1490 Reference< beans::XPropertySet > xPropSet( rChartDoc->getLegend(), uno::UNO_QUERY );
1491 if( xPropSet.is())
1492 aPropertyStates = mxExpPropMapper->Filter( xPropSet );
1493 }
1494
1495 if( bExportContent )
1496 {
1497 Reference< beans::XPropertySet > xProp( rChartDoc->getLegend(), uno::UNO_QUERY );
1498 if( xProp.is())
1499 {
1500 // export legend anchor position
1501 try
1502 {
1503 Any aAny( xProp->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Alignment" ))));
1504 if( SchXMLEnumConverter::getLegendPositionConverter().exportXML( msString, aAny, mrExport.GetMM100UnitConverter() ) )
1505 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_LEGEND_POSITION, msString );
1506 }
1507 catch( beans::UnknownPropertyException & )
1508 {
1509 DBG_WARNING( "Property Align not found in ChartLegend" );
1510 }
1511
1512 // export absolute legend position
1513 Reference< drawing::XShape > xLegendShape( xProp, uno::UNO_QUERY );
1514 addPosition( xLegendShape );
1515
1516 // export legend size
1517 const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() );
1518 if( xLegendShape.is() && nCurrentODFVersion >= SvtSaveOptions::ODFVER_012 && ( SvtSaveOptions::IsODFExtended( nCurrentODFVersion ) || nCurrentODFVersion >= SvtSaveOptions::ODFVER_013 ) )//do not export legend-expansion to ODF 1.0 and export size only if extensions are enabled or in ODF 1.3 //#i28670# todo: change this dependent on fileformat evolution
1519 {
1520 try
1521 {
1522 chart::ChartLegendExpansion nLegendExpansion = chart::ChartLegendExpansion_HIGH;
1523 OUString aExpansionString;
1524 Any aAny( xProp->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Expansion" ))));
1525 bool bHasExpansion = (aAny >>= nLegendExpansion);
1526 if( bHasExpansion && SchXMLEnumConverter::getLegendExpansionConverter().exportXML( aExpansionString, aAny, mrExport.GetMM100UnitConverter() ) )
1527 {
1528 mrExport.AddAttribute( XML_NAMESPACE_STYLE, XML_LEGEND_EXPANSION, aExpansionString );
1529 if( nLegendExpansion == chart::ChartLegendExpansion_CUSTOM)
1530 {
1531 awt::Size aSize( xLegendShape->getSize() );
1532 addSize( aSize, nCurrentODFVersion < SvtSaveOptions::ODFVER_013 );
1533 rtl::OUStringBuffer aAspectRatioString;
1534 SvXMLUnitConverter::convertDouble(aAspectRatioString, double(aSize.Width)/double(aSize.Height));
1535 mrExport.AddAttribute( XML_NAMESPACE_STYLE, XML_LEGEND_EXPANSION_ASPECT_RATIO, aAspectRatioString.makeStringAndClear() );
1536 }
1537 }
1538 }
1539 catch( beans::UnknownPropertyException & )
1540 {
1541 DBG_WARNING( "Property Expansion not found in ChartLegend" );
1542 }
1543 }
1544 }
1545
1546 // write style name
1547 AddAutoStyleAttribute( aPropertyStates );
1548
1549 // element
1550 SvXMLElementExport aLegend( mrExport, XML_NAMESPACE_CHART, XML_LEGEND, sal_True, sal_True );
1551 }
1552 else // autostyles
1553 {
1554 CollectAutoStyle( aPropertyStates );
1555 }
1556 // remove property states for autostyles
1557 aPropertyStates.clear();
1558 }
1559
1560 // plot-area element
1561 // -----------------
1562 if( xDiagram.is())
1563 exportPlotArea( xDiagram, xNewDiagram, aPageSize, bExportContent, bIncludeTable );
1564
1565 // export additional shapes
1566 // ------------------------
1567 if( xDocPropSet.is() )
1568 {
1569 if( bExportContent )
1570 {
1571 if( mxAdditionalShapes.is())
1572 {
1573 // can't call exportShapes with all shapes because the
1574 // initialisation happened with the complete draw page and not
1575 // the XShapes object used here. Thus the shapes have to be
1576 // exported one by one
1577 UniReference< XMLShapeExport > rShapeExport = mrExport.GetShapeExport();
1578 Reference< drawing::XShape > xShape;
1579 const sal_Int32 nShapeCount( mxAdditionalShapes->getCount());
1580 for( sal_Int32 nShapeId = 0; nShapeId < nShapeCount; nShapeId++ )
1581 {
1582 mxAdditionalShapes->getByIndex( nShapeId ) >>= xShape;
1583 DBG_ASSERT( xShape.is(), "Shape without an XShape?" );
1584 if( ! xShape.is())
1585 continue;
1586
1587 rShapeExport->exportShape( xShape );
1588 }
1589 // this would be the easier way if it worked:
1590 //mrExport.GetShapeExport()->exportShapes( mxAdditionalShapes );
1591 }
1592 }
1593 else
1594 {
1595 // get a sequence of non-chart shapes (inserted via clipboard)
1596 try
1597 {
1598 Any aShapesAny = xDocPropSet->getPropertyValue( OUString::createFromAscii( "AdditionalShapes" ));
1599 aShapesAny >>= mxAdditionalShapes;
1600 if( mrExport.getDefaultVersion() >= SvtSaveOptions::ODFVER_010 && mrExport.getDefaultVersion() < SvtSaveOptions::ODFVER_013 && !SvtSaveOptions::IsODFExtended( mrExport.getDefaultVersion() ) )
1601 mxAdditionalShapes.clear();
1602 }
1603 catch( uno::Exception & rEx )
1604 {
1605 (void)rEx; // avoid warning for pro build
1606 OSL_TRACE(
1607 OUStringToOString(
1608 OUString( RTL_CONSTASCII_USTRINGPARAM(
1609 "AdditionalShapes not found: " )) +
1610 rEx.Message,
1611 RTL_TEXTENCODING_ASCII_US ).getStr());
1612 }
1613
1614 if( mxAdditionalShapes.is())
1615 {
1616 // seek shapes has to be called for the whole page because in
1617 // the shape export the vector of shapes is accessed via the
1618 // ZOrder which might be (actually is) larger than the number of
1619 // shapes in mxAdditionalShapes
1620 Reference< drawing::XDrawPageSupplier > xSupplier( rChartDoc, uno::UNO_QUERY );
1621 DBG_ASSERT( xSupplier.is(), "Cannot retrieve draw page to initialize shape export" );
1622 if( xSupplier.is() )
1623 {
1624 Reference< drawing::XShapes > xDrawPage( xSupplier->getDrawPage(), uno::UNO_QUERY );
1625 DBG_ASSERT( xDrawPage.is(), "Invalid draw page for initializing shape export" );
1626 if( xDrawPage.is())
1627 mrExport.GetShapeExport()->seekShapes( xDrawPage );
1628 }
1629
1630 // can't call collectShapesAutoStyles with all shapes because
1631 // the initialisation happened with the complete draw page and
1632 // not the XShapes object used here. Thus the shapes have to be
1633 // exported one by one
1634 UniReference< XMLShapeExport > rShapeExport = mrExport.GetShapeExport();
1635 Reference< drawing::XShape > xShape;
1636 const sal_Int32 nShapeCount( mxAdditionalShapes->getCount());
1637 for( sal_Int32 nShapeId = 0; nShapeId < nShapeCount; nShapeId++ )
1638 {
1639 mxAdditionalShapes->getByIndex( nShapeId ) >>= xShape;
1640 DBG_ASSERT( xShape.is(), "Shape without an XShape?" );
1641 if( ! xShape.is())
1642 continue;
1643
1644 rShapeExport->collectShapeAutoStyles( xShape );
1645 }
1646 // this would be the easier way if it worked:
1647 // mrExport.GetShapeExport()->collectShapesAutoStyles( mxAdditionalShapes );
1648 }
1649 }
1650 }
1651
1652 // table element
1653 // (is included as subelement of chart)
1654 // ------------------------------------
1655 if( bExportContent )
1656 {
1657 // #85929# always export table, otherwise clipboard may loose data
1658 exportTable();
1659 }
1660
1661 // close <chart:chart> element
1662 if( pElChart )
1663 delete pElChart;
1664 }
1665
lcl_exportComplexLabel(const Sequence<uno::Any> & rComplexLabel,SvXMLExport & rExport)1666 void lcl_exportComplexLabel( const Sequence< uno::Any >& rComplexLabel, SvXMLExport& rExport )
1667 {
1668 sal_Int32 nLength = rComplexLabel.getLength();
1669 if( nLength<=1 )
1670 return;
1671 SvXMLElementExport aTextList( rExport, XML_NAMESPACE_TEXT, XML_LIST, sal_True, sal_True );
1672 for(sal_Int32 nN=0; nN<nLength; nN++)
1673 {
1674 SvXMLElementExport aListItem( rExport, XML_NAMESPACE_TEXT, XML_LIST_ITEM, sal_True, sal_True );
1675 OUString aString;
1676 if( !(rComplexLabel[nN]>>=aString) )
1677 {
1678 //todo?
1679 }
1680 SchXMLTools::exportText( rExport, aString, false /*bConvertTabsLFs*/ );
1681 }
1682 }
1683
exportTable()1684 void SchXMLExportHelper_Impl::exportTable()
1685 {
1686 // table element
1687 // -------------
1688 mrExport.AddAttribute( XML_NAMESPACE_TABLE, XML_NAME, msTableName );
1689
1690 try
1691 {
1692 bool bProtected = false;
1693 Reference< beans::XPropertySet > xProps( mrExport.GetModel(), uno::UNO_QUERY_THROW );
1694 if ( ( xProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "DisableDataTableDialog" ) ) ) >>= bProtected ) &&
1695 bProtected )
1696 {
1697 mrExport.AddAttribute( XML_NAMESPACE_TABLE, XML_PROTECTED, XML_TRUE );
1698 }
1699 }
1700 catch ( uno::Exception& )
1701 {
1702 }
1703
1704 SvXMLElementExport aTable( mrExport, XML_NAMESPACE_TABLE, XML_TABLE, sal_True, sal_True );
1705
1706 bool bHasOwnData = false;
1707 Reference< chart2::XChartDocument > xNewDoc( mrExport.GetModel(), uno::UNO_QUERY );
1708 Reference< chart2::data::XRangeXMLConversion > xRangeConversion;
1709 if( xNewDoc.is())
1710 {
1711 bHasOwnData = xNewDoc->hasInternalDataProvider();
1712 xRangeConversion.set( xNewDoc->getDataProvider(), uno::UNO_QUERY );
1713 }
1714
1715 Reference< chart2::XAnyDescriptionAccess > xAnyDescriptionAccess;
1716 {
1717 Reference< chart::XChartDocument > xChartDoc( mrExport.GetModel(), uno::UNO_QUERY );
1718 if( xChartDoc.is() )
1719 xAnyDescriptionAccess = Reference< chart2::XAnyDescriptionAccess >( xChartDoc->getData(), uno::UNO_QUERY );
1720 }
1721
1722 if( bHasOwnData )
1723 lcl_ReorderInternalSequencesAccordingToTheirRangeName( m_aDataSequencesToExport );
1724 lcl_TableData aData( lcl_getDataForLocalTable( m_aDataSequencesToExport
1725 , xAnyDescriptionAccess, maCategoriesRange
1726 , mbRowSourceColumns, xRangeConversion ));
1727
1728 tStringVector::const_iterator aDataRangeIter( aData.aDataRangeRepresentations.begin());
1729 const tStringVector::const_iterator aDataRangeEndIter( aData.aDataRangeRepresentations.end());
1730
1731 tStringVector::const_iterator aRowDescriptions_RangeIter( aData.aRowDescriptions_Ranges.begin());
1732 const tStringVector::const_iterator aRowDescriptions_RangeEnd( aData.aRowDescriptions_Ranges.end());
1733
1734 // declare columns
1735 {
1736 SvXMLElementExport aHeaderColumns( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_HEADER_COLUMNS, sal_True, sal_True );
1737 SvXMLElementExport aHeaderColumn( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_COLUMN, sal_True, sal_True );
1738 }
1739 if( !aData.aHiddenColumns.empty() || !aData.aColumnDescriptions.empty() )
1740 {
1741 SvXMLElementExport aColumns( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_COLUMNS, sal_True, sal_True );
1742
1743 sal_Int32 nNextIndex = 0;
1744 for( size_t nN=0; nN< aData.aHiddenColumns.size(); nN++ )
1745 {
1746 //i91578 display of hidden values (copy paste scenario; export hidden flag thus it can be used during migration to locale table upon paste )
1747 sal_Int32 nHiddenIndex = aData.aHiddenColumns[nN];
1748 if( nHiddenIndex > nNextIndex )
1749 {
1750 sal_Int64 nRepeat = static_cast< sal_Int64 >( nHiddenIndex - nNextIndex );
1751 if(nRepeat>1)
1752 mrExport.AddAttribute( XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_REPEATED,
1753 OUString::valueOf( nRepeat ));
1754 SvXMLElementExport aColumn( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_COLUMN, sal_True, sal_True );
1755 }
1756 mrExport.AddAttribute( XML_NAMESPACE_TABLE, XML_VISIBILITY, GetXMLToken( XML_COLLAPSE ) );
1757 SvXMLElementExport aColumn( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_COLUMN, sal_True, sal_True );
1758 nNextIndex = nHiddenIndex+1;
1759 }
1760
1761 sal_Int32 nEndIndex = aData.aColumnDescriptions.size()-1;
1762 if( nEndIndex >= nNextIndex )
1763 {
1764 sal_Int64 nRepeat = static_cast< sal_Int64 >( nEndIndex - nNextIndex + 1 );
1765 if(nRepeat>1)
1766 mrExport.AddAttribute( XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_REPEATED,
1767 OUString::valueOf( nRepeat ));
1768 SvXMLElementExport aColumn( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_COLUMN, sal_True, sal_True );
1769 }
1770 }
1771
1772 // export rows with content
1773 //export header row
1774 {
1775 SvXMLElementExport aHeaderRows( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_HEADER_ROWS, sal_True, sal_True );
1776 SvXMLElementExport aRow( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_ROW, sal_True, sal_True );
1777
1778 //first one empty cell for the row descriptions
1779 {
1780 SvXMLElementExport aEmptyCell( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_CELL, sal_True, sal_True );
1781 SvXMLElementExport aEmptyParagraph( mrExport, XML_NAMESPACE_TEXT, XML_P, sal_True, sal_True );
1782 }
1783
1784 //export column descriptions
1785 tStringVector::const_iterator aColumnDescriptions_RangeIter( aData.aColumnDescriptions_Ranges.begin());
1786 const tStringVector::const_iterator aColumnDescriptions_RangeEnd( aData.aColumnDescriptions_Ranges.end());
1787 const Sequence< Sequence< uno::Any > >& rComplexColumnDescriptions = aData.aComplexColumnDescriptions;
1788 sal_Int32 nComplexCount = rComplexColumnDescriptions.getLength();
1789 sal_Int32 nC = 0;
1790 for( tStringVector::const_iterator aIt( aData.aColumnDescriptions.begin())
1791 ; (aIt != aData.aColumnDescriptions.end())
1792 ; aIt++, nC++ )
1793 {
1794 bool bExportString = true;
1795 if( nC < nComplexCount )
1796 {
1797 const Sequence< uno::Any >& rComplexLabel = rComplexColumnDescriptions[nC];
1798 if( rComplexLabel.getLength()>0 )
1799 {
1800 double fValue=0.0;
1801 if( rComplexLabel[0] >>=fValue )
1802 {
1803 bExportString = false;
1804
1805 SvXMLUnitConverter::convertDouble( msStringBuffer, fValue );
1806 msString = msStringBuffer.makeStringAndClear();
1807 mrExport.AddAttribute( XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_FLOAT );
1808 mrExport.AddAttribute( XML_NAMESPACE_OFFICE, XML_VALUE, msString );
1809 }
1810 }
1811 }
1812 if( bExportString )
1813 {
1814 mrExport.AddAttribute( XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_STRING );
1815 }
1816
1817 SvXMLElementExport aCell( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_CELL, sal_True, sal_True );
1818 exportText( *aIt );
1819 if( nC < nComplexCount )
1820 lcl_exportComplexLabel( rComplexColumnDescriptions[nC], mrExport );
1821 if( !bHasOwnData && aColumnDescriptions_RangeIter != aColumnDescriptions_RangeEnd )
1822 {
1823 // remind the original range to allow a correct re-association when copying via clipboard
1824 if ((*aColumnDescriptions_RangeIter).getLength())
1825 SchXMLTools::exportRangeToSomewhere( mrExport, *aColumnDescriptions_RangeIter );
1826 ++aColumnDescriptions_RangeIter;
1827 }
1828 }
1829 OSL_ASSERT( bHasOwnData || aColumnDescriptions_RangeIter == aColumnDescriptions_RangeEnd );
1830 } // closing row and header-rows elements
1831
1832 // export value rows
1833 if( !aData.aDataInRows.empty() )
1834 {
1835 SvXMLElementExport aRows( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_ROWS, sal_True, sal_True );
1836 tStringVector::const_iterator aRowDescriptionsIter( aData.aRowDescriptions.begin());
1837 const Sequence< Sequence< uno::Any > >& rComplexRowDescriptions = aData.aComplexRowDescriptions;
1838 sal_Int32 nComplexCount = rComplexRowDescriptions.getLength();
1839 sal_Int32 nC = 0;
1840
1841 for( t2DNumberContainer::const_iterator aRowIt( aData.aDataInRows.begin())
1842 ; aRowIt != aData.aDataInRows.end()
1843 ; ++aRowIt, ++nC )
1844 {
1845 SvXMLElementExport aRow( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_ROW, sal_True, sal_True );
1846
1847 //export row descriptions
1848 {
1849 bool bExportString = true;
1850 if( nC < nComplexCount )
1851 {
1852 const Sequence< uno::Any >& rComplexLabel = rComplexRowDescriptions[nC];
1853 if( rComplexLabel.getLength()>0 )
1854 {
1855 double fValue=0.0;
1856 if( rComplexLabel[0] >>=fValue )
1857 {
1858 bExportString = false;
1859
1860 SvXMLUnitConverter::convertDouble( msStringBuffer, fValue );
1861 msString = msStringBuffer.makeStringAndClear();
1862 mrExport.AddAttribute( XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_FLOAT );
1863 mrExport.AddAttribute( XML_NAMESPACE_OFFICE, XML_VALUE, msString );
1864 }
1865 }
1866 }
1867 if( bExportString )
1868 {
1869 mrExport.AddAttribute( XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_STRING );
1870 }
1871
1872 SvXMLElementExport aCell( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_CELL, sal_True, sal_True );
1873 if( aRowDescriptionsIter != aData.aRowDescriptions.end())
1874 {
1875 exportText( *aRowDescriptionsIter );
1876 if( nC < nComplexCount )
1877 lcl_exportComplexLabel( rComplexRowDescriptions[nC], mrExport );
1878 if( !bHasOwnData && aRowDescriptions_RangeIter != aRowDescriptions_RangeEnd )
1879 {
1880 // remind the original range to allow a correct re-association when copying via clipboard
1881 SchXMLTools::exportRangeToSomewhere( mrExport, *aRowDescriptions_RangeIter );
1882 ++aRowDescriptions_RangeIter;
1883 }
1884 ++aRowDescriptionsIter;
1885 }
1886 }
1887
1888 //export row values
1889 for( t2DNumberContainer::value_type::const_iterator aColIt( aRowIt->begin());
1890 aColIt != aRowIt->end(); ++aColIt )
1891 {
1892 SvXMLUnitConverter::convertDouble( msStringBuffer, *aColIt );
1893 msString = msStringBuffer.makeStringAndClear();
1894 mrExport.AddAttribute( XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_FLOAT );
1895 mrExport.AddAttribute( XML_NAMESPACE_OFFICE, XML_VALUE, msString );
1896 SvXMLElementExport aCell( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_CELL, sal_True, sal_True );
1897 exportText( msString, false ); // do not convert tabs and lfs
1898 if( ( !bHasOwnData && aDataRangeIter != aDataRangeEndIter ) &&
1899 ( mbRowSourceColumns || (aColIt == aRowIt->begin()) ) )
1900 {
1901 // remind the original range to allow a correct re-association when copying via clipboard
1902 if ((*aDataRangeIter).getLength())
1903 SchXMLTools::exportRangeToSomewhere( mrExport, *aDataRangeIter );
1904 ++aDataRangeIter;
1905 }
1906 }
1907 }
1908 }
1909
1910 // if range iterator was used it should have reached its end
1911 OSL_ASSERT( bHasOwnData || (aDataRangeIter == aDataRangeEndIter) );
1912 OSL_ASSERT( bHasOwnData || (aRowDescriptions_RangeIter == aRowDescriptions_RangeEnd) );
1913 }
1914
1915 namespace
1916 {
1917
lcl_getCooSys(const Reference<chart2::XDiagram> & xNewDiagram)1918 Reference< chart2::XCoordinateSystem > lcl_getCooSys( const Reference< chart2::XDiagram > & xNewDiagram )
1919 {
1920 Reference< chart2::XCoordinateSystem > xCooSys;
1921 Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xNewDiagram, uno::UNO_QUERY );
1922 if(xCooSysCnt.is())
1923 {
1924 Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems() );
1925 if(aCooSysSeq.getLength()>0)
1926 xCooSys = aCooSysSeq[0];
1927 }
1928 return xCooSys;
1929 }
1930
lcl_getAxis(const Reference<chart2::XCoordinateSystem> & xCooSys,enum XMLTokenEnum eDimension,bool bPrimary=true)1931 Reference< chart2::XAxis > lcl_getAxis( const Reference< chart2::XCoordinateSystem >& xCooSys,
1932 enum XMLTokenEnum eDimension, bool bPrimary=true )
1933 {
1934 Reference< chart2::XAxis > xNewAxis;
1935 try
1936 {
1937 if( xCooSys.is() )
1938 {
1939 sal_Int32 nDimensionIndex=0;
1940 switch( eDimension )
1941 {
1942 case XML_X:
1943 nDimensionIndex=0;
1944 break;
1945 case XML_Y:
1946 nDimensionIndex=1;
1947 break;
1948 case XML_Z:
1949 nDimensionIndex=2;
1950 break;
1951 default:
1952 break;
1953 }
1954
1955 xNewAxis = xCooSys->getAxisByDimension( nDimensionIndex, bPrimary ? 0 : 1 );
1956 }
1957 }
1958 catch( const uno::Exception & )
1959 {
1960 }
1961 return xNewAxis;
1962 }
1963
1964 }
1965
exportPlotArea(Reference<chart::XDiagram> xDiagram,Reference<chart2::XDiagram> xNewDiagram,const awt::Size & rPageSize,sal_Bool bExportContent,sal_Bool bIncludeTable)1966 void SchXMLExportHelper_Impl::exportPlotArea(
1967 Reference< chart::XDiagram > xDiagram,
1968 Reference< chart2::XDiagram > xNewDiagram,
1969 const awt::Size & rPageSize,
1970 sal_Bool bExportContent,
1971 sal_Bool bIncludeTable )
1972 {
1973 DBG_ASSERT( xDiagram.is(), "Invalid XDiagram as parameter" );
1974 if( ! xDiagram.is())
1975 return;
1976
1977 // variables for autostyles
1978 Reference< beans::XPropertySet > xPropSet;
1979 std::vector< XMLPropertyState > aPropertyStates;
1980
1981 sal_Bool bIs3DChart = sal_False;
1982 drawing::HomogenMatrix aTransMatrix;
1983
1984 msStringBuffer.setLength( 0 );
1985
1986 // plot-area element
1987 // -----------------
1988
1989 SvXMLElementExport* pElPlotArea = 0;
1990 // get property states for autostyles
1991 xPropSet = Reference< beans::XPropertySet >( xDiagram, uno::UNO_QUERY );
1992 if( xPropSet.is())
1993 {
1994 if( mxExpPropMapper.is())
1995 aPropertyStates = mxExpPropMapper->Filter( xPropSet );
1996 }
1997 if( bExportContent )
1998 {
1999 UniReference< XMLShapeExport > rShapeExport;
2000
2001 // write style name
2002 AddAutoStyleAttribute( aPropertyStates );
2003
2004 if( msChartAddress.getLength() )
2005 {
2006 // ODF 1.4 removed table:cell-range-address from chart:plot-area; the importer takes the data from the series ranges
2007 if( !bIncludeTable && mrExport.getDefaultVersion() < SvtSaveOptions::ODFVER_014 )
2008 mrExport.AddAttribute( XML_NAMESPACE_TABLE, XML_CELL_RANGE_ADDRESS, msChartAddress );
2009
2010 Reference< chart::XChartDocument > xDoc( mrExport.GetModel(), uno::UNO_QUERY );
2011 if( xDoc.is() )
2012 {
2013 Reference< beans::XPropertySet > xDocProp( xDoc, uno::UNO_QUERY );
2014 if( xDocProp.is())
2015 {
2016 Any aAny;
2017 sal_Bool bFirstCol = false, bFirstRow = false;
2018
2019 try
2020 {
2021 aAny = xDocProp->getPropertyValue(
2022 OUString( RTL_CONSTASCII_USTRINGPARAM( "DataSourceLabelsInFirstColumn" )));
2023 aAny >>= bFirstCol;
2024 aAny = xDocProp->getPropertyValue(
2025 OUString( RTL_CONSTASCII_USTRINGPARAM( "DataSourceLabelsInFirstRow" )));
2026 aAny >>= bFirstRow;
2027
2028 if( bFirstCol || bFirstRow )
2029 {
2030 mrExport.AddAttribute( XML_NAMESPACE_CHART,
2031 ::xmloff::token::GetXMLToken( ::xmloff::token::XML_DATA_SOURCE_HAS_LABELS ),
2032 ( bFirstCol
2033 ? ( bFirstRow
2034 ? ::xmloff::token::GetXMLToken( ::xmloff::token::XML_BOTH )
2035 : ::xmloff::token::GetXMLToken( ::xmloff::token::XML_COLUMN ))
2036 : ::xmloff::token::GetXMLToken( ::xmloff::token::XML_ROW )));
2037 }
2038 }
2039 catch( beans::UnknownPropertyException & )
2040 {
2041 DBG_ERRORFILE( "Properties missing" );
2042 }
2043 }
2044 }
2045 }
2046
2047 // #i72973#, #144135# only export table-number-list in OOo format (also for binary)
2048 Reference< beans::XPropertySet > xExportInfo( mrExport.getExportInfo());
2049 if( msTableNumberList.getLength() &&
2050 xExportInfo.is())
2051 {
2052 try
2053 {
2054 OUString sExportTableNumListPropName( RTL_CONSTASCII_USTRINGPARAM("ExportTableNumberList"));
2055 Reference< beans::XPropertySetInfo > xInfo( xExportInfo->getPropertySetInfo());
2056 bool bExportTableNumberList = false;
2057 if( xInfo.is() && xInfo->hasPropertyByName( sExportTableNumListPropName ) &&
2058 (xExportInfo->getPropertyValue( sExportTableNumListPropName ) >>= bExportTableNumberList) &&
2059 bExportTableNumberList )
2060 {
2061 // this attribute is for charts embedded in calc documents only.
2062 // With this you are able to store a file again in 5.0 binary format
2063 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_TABLE_NUMBER_LIST, msTableNumberList );
2064 }
2065 }
2066 catch( uno::Exception & rEx )
2067 {
2068 #ifdef DBG_UTIL
2069 String aStr( rEx.Message );
2070 ByteString aBStr( aStr, RTL_TEXTENCODING_ASCII_US );
2071 DBG_ERROR1( "chart:TableNumberList property caught: %s", aBStr.GetBuffer());
2072 #else
2073 (void)rEx; // avoid warning
2074 #endif
2075 }
2076 }
2077
2078 // attributes
2079 Reference< drawing::XShape > xShape ( xDiagram, uno::UNO_QUERY );
2080 if( xShape.is())
2081 {
2082 addPosition( xShape );
2083 addSize( xShape );
2084 }
2085
2086 if( xPropSet.is())
2087 {
2088 Any aAny;
2089
2090 // 3d attributes
2091 try
2092 {
2093 aAny = xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Dim3D" )));
2094 aAny >>= bIs3DChart;
2095
2096 if( bIs3DChart )
2097 {
2098 rShapeExport = mrExport.GetShapeExport();
2099 if( rShapeExport.is())
2100 rShapeExport->export3DSceneAttributes( xPropSet );
2101 }
2102 }
2103 catch( uno::Exception & rEx )
2104 {
2105 #ifdef DBG_UTIL
2106 String aStr( rEx.Message );
2107 ByteString aBStr( aStr, RTL_TEXTENCODING_ASCII_US );
2108 DBG_ERROR1( "chart:exportPlotAreaException caught: %s", aBStr.GetBuffer());
2109 #else
2110 (void)rEx; // avoid warning
2111 #endif
2112 }
2113 }
2114
2115 // plot-area element
2116 pElPlotArea = new SvXMLElementExport( mrExport, XML_NAMESPACE_CHART, XML_PLOT_AREA, sal_True, sal_True );
2117
2118 //inner position rectangle element
2119 exportCoordinateRegion( xDiagram );
2120
2121 // light sources (inside plot area element)
2122 if( bIs3DChart &&
2123 rShapeExport.is())
2124 rShapeExport->export3DLamps( xPropSet );
2125 }
2126 else // autostyles
2127 {
2128 CollectAutoStyle( aPropertyStates );
2129 }
2130 // remove property states for autostyles
2131 aPropertyStates.clear();
2132
2133 // axis elements
2134 // -------------
2135 exportAxes( xDiagram, xNewDiagram, bExportContent );
2136
2137 // series elements
2138 // ---------------
2139 Reference< chart2::XAxis > xSecondYAxis = lcl_getAxis( lcl_getCooSys( xNewDiagram ), XML_Y, false );
2140 exportSeries( xNewDiagram, rPageSize, bExportContent, xSecondYAxis.is() );
2141
2142 // stock-chart elements
2143 OUString sChartType ( xDiagram->getDiagramType());
2144 if( 0 == sChartType.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart.StockDiagram" )))
2145 {
2146 Reference< chart::XStatisticDisplay > xStockPropProvider( xDiagram, uno::UNO_QUERY );
2147 if( xStockPropProvider.is())
2148 {
2149 // stock-gain-marker
2150 Reference< beans::XPropertySet > xStockPropSet = xStockPropProvider->getUpBar();
2151 if( xStockPropSet.is())
2152 {
2153 aPropertyStates.clear();
2154 aPropertyStates = mxExpPropMapper->Filter( xStockPropSet );
2155
2156 if( !aPropertyStates.empty() )
2157 {
2158 if( bExportContent )
2159 {
2160 AddAutoStyleAttribute( aPropertyStates );
2161
2162 SvXMLElementExport aGain( mrExport, XML_NAMESPACE_CHART, XML_STOCK_GAIN_MARKER, sal_True, sal_True );
2163 }
2164 else
2165 {
2166 CollectAutoStyle( aPropertyStates );
2167 }
2168 }
2169 }
2170
2171 // stock-loss-marker
2172 xStockPropSet = xStockPropProvider->getDownBar();
2173 if( xStockPropSet.is())
2174 {
2175 aPropertyStates.clear();
2176 aPropertyStates = mxExpPropMapper->Filter( xStockPropSet );
2177
2178 if( !aPropertyStates.empty() )
2179 {
2180 if( bExportContent )
2181 {
2182 AddAutoStyleAttribute( aPropertyStates );
2183
2184 SvXMLElementExport aGain( mrExport, XML_NAMESPACE_CHART, XML_STOCK_LOSS_MARKER, sal_True, sal_True );
2185 }
2186 else
2187 {
2188 CollectAutoStyle( aPropertyStates );
2189 }
2190 }
2191 }
2192
2193 // stock-range-line
2194 xStockPropSet = xStockPropProvider->getMinMaxLine();
2195 if( xStockPropSet.is())
2196 {
2197 aPropertyStates.clear();
2198 aPropertyStates = mxExpPropMapper->Filter( xStockPropSet );
2199
2200 if( !aPropertyStates.empty() )
2201 {
2202 if( bExportContent )
2203 {
2204 AddAutoStyleAttribute( aPropertyStates );
2205
2206 SvXMLElementExport aGain( mrExport, XML_NAMESPACE_CHART, XML_STOCK_RANGE_LINE, sal_True, sal_True );
2207 }
2208 else
2209 {
2210 CollectAutoStyle( aPropertyStates );
2211 }
2212 }
2213 }
2214 }
2215 }
2216
2217 // wall and floor element
2218 // ----------------------
2219
2220 Reference< chart::X3DDisplay > xWallFloorSupplier( xDiagram, uno::UNO_QUERY );
2221 if( mxExpPropMapper.is() &&
2222 xWallFloorSupplier.is())
2223 {
2224 // remove property states for autostyles
2225 aPropertyStates.clear();
2226
2227 Reference< beans::XPropertySet > xWallPropSet( xWallFloorSupplier->getWall(), uno::UNO_QUERY );
2228 if( xWallPropSet.is())
2229 {
2230 aPropertyStates = mxExpPropMapper->Filter( xWallPropSet );
2231
2232 if( !aPropertyStates.empty() )
2233 {
2234 // write element
2235 if( bExportContent )
2236 {
2237 // add style name attribute
2238 AddAutoStyleAttribute( aPropertyStates );
2239
2240 SvXMLElementExport aWall( mrExport, XML_NAMESPACE_CHART, XML_WALL, sal_True, sal_True );
2241 }
2242 else // autostyles
2243 {
2244 CollectAutoStyle( aPropertyStates );
2245 }
2246 }
2247 }
2248
2249 // floor element
2250 // -------------
2251
2252 // remove property states for autostyles
2253 aPropertyStates.clear();
2254
2255 Reference< beans::XPropertySet > xFloorPropSet( xWallFloorSupplier->getFloor(), uno::UNO_QUERY );
2256 if( xFloorPropSet.is())
2257 {
2258 aPropertyStates = mxExpPropMapper->Filter( xFloorPropSet );
2259
2260 if( !aPropertyStates.empty() )
2261 {
2262 // write element
2263 if( bExportContent )
2264 {
2265 // add style name attribute
2266 AddAutoStyleAttribute( aPropertyStates );
2267
2268 SvXMLElementExport aFloor( mrExport, XML_NAMESPACE_CHART, XML_FLOOR, sal_True, sal_True );
2269 }
2270 else // autostyles
2271 {
2272 CollectAutoStyle( aPropertyStates );
2273 }
2274 }
2275 }
2276 }
2277
2278 if( pElPlotArea )
2279 delete pElPlotArea;
2280 }
2281
exportCoordinateRegion(const uno::Reference<chart::XDiagram> & xDiagram)2282 void SchXMLExportHelper_Impl::exportCoordinateRegion( const uno::Reference< chart::XDiagram >& xDiagram )
2283 {
2284 const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() );
2285 const sal_Bool bODF13( nCurrentODFVersion >= SvtSaveOptions::ODFVER_013 );
2286 if( !bODF13 && !SvtSaveOptions::IsODFExtended( nCurrentODFVersion ) )//ODF 1.2 and older have no coordinate region, extended mode writes it as an extension
2287 return;
2288
2289 Reference< chart::XDiagramPositioning > xDiaPos( xDiagram, uno::UNO_QUERY );
2290 DBG_ASSERT( xDiaPos.is(), "Invalid xDiaPos as parameter" );
2291 if( !xDiaPos.is() )
2292 return;
2293
2294 awt::Rectangle aRect( xDiaPos->calculateDiagramPositionExcludingAxes() );
2295 addPosition( awt::Point(aRect.X,aRect.Y) );
2296 addSize( awt::Size(aRect.Width,aRect.Height) );
2297
2298 SvXMLElementExport aCoordinateRegion( mrExport, bODF13 ? XML_NAMESPACE_CHART : XML_NAMESPACE_CHART_EXT, XML_COORDINATE_REGION, sal_True, sal_True );
2299 }
2300
2301 namespace
2302 {
lcl_getTimeUnitToken(sal_Int32 nTimeUnit)2303 XMLTokenEnum lcl_getTimeUnitToken( sal_Int32 nTimeUnit )
2304 {
2305 XMLTokenEnum eToken = XML_DAYS;
2306 switch( nTimeUnit )
2307 {
2308 case ::com::sun::star::chart::TimeUnit::YEAR:
2309 eToken = XML_YEARS;
2310 break;
2311 case ::com::sun::star::chart::TimeUnit::MONTH:
2312 eToken = XML_MONTHS;
2313 break;
2314 default://days
2315 break;
2316 }
2317 return eToken;
2318 }
2319 }
2320
exportDateScale(const Reference<beans::XPropertySet> xAxisProps)2321 void SchXMLExportHelper_Impl::exportDateScale( const Reference< beans::XPropertySet > xAxisProps )
2322 {
2323 if( !xAxisProps.is() )
2324 return;
2325
2326 chart::TimeIncrement aIncrement;
2327 if( (xAxisProps->getPropertyValue( OUString::createFromAscii( "TimeIncrement" )) >>= aIncrement) )
2328 {
2329 sal_Int32 nTimeResolution = ::com::sun::star::chart::TimeUnit::DAY;
2330 if( aIncrement.TimeResolution >>= nTimeResolution )
2331 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_BASE_TIME_UNIT, lcl_getTimeUnitToken( nTimeResolution ) );
2332
2333 OUStringBuffer aValue;
2334 chart::TimeInterval aInterval;
2335 if( aIncrement.MajorTimeInterval >>= aInterval )
2336 {
2337 SvXMLUnitConverter::convertNumber( aValue, aInterval.Number );
2338 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_MAJOR_INTERVAL_VALUE, aValue.makeStringAndClear() );
2339 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_MAJOR_INTERVAL_UNIT, lcl_getTimeUnitToken( aInterval.TimeUnit ) );
2340 }
2341 if( aIncrement.MinorTimeInterval >>= aInterval )
2342 {
2343 SvXMLUnitConverter::convertNumber( aValue, aInterval.Number );
2344 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_MINOR_INTERVAL_VALUE, aValue.makeStringAndClear() );
2345 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_MINOR_INTERVAL_UNIT, lcl_getTimeUnitToken( aInterval.TimeUnit ) );
2346 }
2347
2348 SvXMLElementExport aDateScale( mrExport, XML_NAMESPACE_CHART_EXT, XML_DATE_SCALE, sal_True, sal_True );//#i25706#todo: change namespace for next ODF version
2349 }
2350 }
2351
exportAxisTitle(const Reference<beans::XPropertySet> xTitleProps,bool bExportContent)2352 void SchXMLExportHelper_Impl::exportAxisTitle( const Reference< beans::XPropertySet > xTitleProps, bool bExportContent )
2353 {
2354 if( !xTitleProps.is() )
2355 return;
2356 std::vector< XMLPropertyState > aPropertyStates = mxExpPropMapper->Filter( xTitleProps );
2357 if( bExportContent )
2358 {
2359 OUString aText;
2360 Any aAny( xTitleProps->getPropertyValue(
2361 OUString( RTL_CONSTASCII_USTRINGPARAM( "String" ))));
2362 aAny >>= aText;
2363
2364 Reference< drawing::XShape > xShape( xTitleProps, uno::UNO_QUERY );
2365 if( xShape.is())
2366 addPosition( xShape );
2367
2368 AddAutoStyleAttribute( aPropertyStates );
2369 SvXMLElementExport aTitle( mrExport, XML_NAMESPACE_CHART, XML_TITLE, sal_True, sal_True );
2370
2371 // paragraph containing title
2372 exportText( aText );
2373 }
2374 else
2375 {
2376 CollectAutoStyle( aPropertyStates );
2377 }
2378 aPropertyStates.clear();
2379 }
2380
exportGrid(const Reference<beans::XPropertySet> xGridProperties,bool bMajor,bool bExportContent)2381 void SchXMLExportHelper_Impl::exportGrid( const Reference< beans::XPropertySet > xGridProperties, bool bMajor, bool bExportContent )
2382 {
2383 if( !xGridProperties.is() )
2384 return;
2385 std::vector< XMLPropertyState > aPropertyStates = mxExpPropMapper->Filter( xGridProperties );
2386 if( bExportContent )
2387 {
2388 AddAutoStyleAttribute( aPropertyStates );
2389 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_CLASS, bMajor ? XML_MAJOR : XML_MINOR );
2390 SvXMLElementExport aGrid( mrExport, XML_NAMESPACE_CHART, XML_GRID, sal_True, sal_True );
2391 }
2392 else
2393 {
2394 CollectAutoStyle( aPropertyStates );
2395 }
2396 aPropertyStates.clear();
2397 }
2398
2399 namespace
2400 {
2401
2402 //returns true if a date scale needs to be exported
lcl_exportAxisType(const Reference<chart2::XAxis> xChart2Axis,SvXMLExport & rExport)2403 bool lcl_exportAxisType( const Reference< chart2::XAxis > xChart2Axis, SvXMLExport& rExport)
2404 {
2405 bool bExportDateScale = false;
2406 if( !xChart2Axis.is() )
2407 return bExportDateScale;
2408
2409 const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() );
2410 if( !SvtSaveOptions::IsODFExtended( nCurrentODFVersion ) ) //#i25706#todo: change version for next ODF version
2411 return bExportDateScale;
2412
2413 chart2::ScaleData aScale( xChart2Axis->getScaleData() );
2414 //#i25706#todo: change namespace for next ODF version
2415 sal_uInt16 nNameSpace = XML_NAMESPACE_CHART_EXT;
2416
2417 switch(aScale.AxisType)
2418 {
2419 case chart2::AxisType::CATEGORY:
2420 if( aScale.AutoDateAxis )
2421 {
2422 rExport.AddAttribute( nNameSpace, XML_AXIS_TYPE, XML_AUTO );
2423 bExportDateScale = true;
2424 }
2425 else
2426 rExport.AddAttribute( nNameSpace, XML_AXIS_TYPE, XML_TEXT );
2427 break;
2428 case chart2::AxisType::DATE:
2429 rExport.AddAttribute( nNameSpace, XML_AXIS_TYPE, XML_DATE );
2430 bExportDateScale = true;
2431 break;
2432 default: //AUTOMATIC
2433 rExport.AddAttribute( nNameSpace, XML_AXIS_TYPE, XML_AUTO );
2434 break;
2435 }
2436
2437 return bExportDateScale;
2438 }
2439
2440 }
2441
exportAxis(enum XMLTokenEnum eDimension,enum XMLTokenEnum eAxisName,const Reference<beans::XPropertySet> xAxisProps,const Reference<chart2::XAxis> & xChart2Axis,const OUString & rCategoriesRange,bool bHasTitle,bool bHasMajorGrid,bool bHasMinorGrid,bool bExportContent)2442 void SchXMLExportHelper_Impl::exportAxis(
2443 enum XMLTokenEnum eDimension,
2444 enum XMLTokenEnum eAxisName,
2445 const Reference< beans::XPropertySet > xAxisProps,
2446 const Reference< chart2::XAxis >& xChart2Axis,
2447 const OUString& rCategoriesRange,
2448 bool bHasTitle, bool bHasMajorGrid, bool bHasMinorGrid,
2449 bool bExportContent )
2450 {
2451 static const OUString sNumFormat( OUString::createFromAscii( "NumberFormat" ));
2452 std::vector< XMLPropertyState > aPropertyStates;
2453 SvXMLElementExport* pAxis = NULL;
2454
2455 // get property states for autostyles
2456 if( xAxisProps.is() && mxExpPropMapper.is() )
2457 {
2458 lcl_exportNumberFormat( sNumFormat, xAxisProps, mrExport );
2459 aPropertyStates = mxExpPropMapper->Filter( xAxisProps );
2460 }
2461
2462 bool bExportDateScale = false;
2463 if( bExportContent )
2464 {
2465 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_DIMENSION, eDimension );
2466 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_NAME, eAxisName );
2467 AddAutoStyleAttribute( aPropertyStates ); // write style name
2468 if( rCategoriesRange.getLength() )
2469 bExportDateScale = lcl_exportAxisType( xChart2Axis, mrExport );
2470
2471 // open axis element
2472 pAxis = new SvXMLElementExport( mrExport, XML_NAMESPACE_CHART, XML_AXIS, sal_True, sal_True );
2473 }
2474 else
2475 {
2476 CollectAutoStyle( aPropertyStates );
2477 }
2478 aPropertyStates.clear();
2479
2480 //date scale
2481 if( bExportDateScale )
2482 exportDateScale( xAxisProps );
2483
2484 Reference< beans::XPropertySet > xTitleProps;
2485 Reference< beans::XPropertySet > xMajorGridProps;
2486 Reference< beans::XPropertySet > xMinorGridProps;
2487 Reference< chart::XAxis > xAxis( xAxisProps, uno::UNO_QUERY );
2488 if( xAxis.is() )
2489 {
2490 xTitleProps = bHasTitle ? xAxis->getAxisTitle() : 0;
2491 xMajorGridProps = bHasMajorGrid ? xAxis->getMajorGrid() : 0;
2492 xMinorGridProps = bHasMinorGrid ? xAxis->getMinorGrid() : 0;
2493 }
2494
2495 // axis-title
2496 exportAxisTitle( xTitleProps , bExportContent );
2497
2498 // categories if we have a categories chart
2499 if( bExportContent && rCategoriesRange.getLength() )
2500 {
2501 mrExport.AddAttribute( XML_NAMESPACE_TABLE, XML_CELL_RANGE_ADDRESS, rCategoriesRange );
2502 SvXMLElementExport aCategories( mrExport, XML_NAMESPACE_CHART, XML_CATEGORIES, sal_True, sal_True );
2503 }
2504
2505 // grid
2506 exportGrid( xMajorGridProps, true, bExportContent );
2507 exportGrid( xMinorGridProps, false, bExportContent );
2508
2509 if( pAxis )
2510 {
2511 //close axis element
2512 delete pAxis;
2513 pAxis = NULL;
2514 }
2515 }
2516
exportAxes(const Reference<chart::XDiagram> & xDiagram,const Reference<chart2::XDiagram> & xNewDiagram,sal_Bool bExportContent)2517 void SchXMLExportHelper_Impl::exportAxes(
2518 const Reference< chart::XDiagram > & xDiagram,
2519 const Reference< chart2::XDiagram > & xNewDiagram,
2520 sal_Bool bExportContent )
2521 {
2522 DBG_ASSERT( xDiagram.is(), "Invalid XDiagram as parameter" );
2523 if( ! xDiagram.is())
2524 return;
2525
2526 // get some properties from document first
2527 sal_Bool bHasXAxis = sal_False,
2528 bHasYAxis = sal_False,
2529 bHasZAxis = sal_False,
2530 bHasSecondaryXAxis = sal_False,
2531 bHasSecondaryYAxis = sal_False;
2532 sal_Bool bHasXAxisTitle = sal_False,
2533 bHasYAxisTitle = sal_False,
2534 bHasZAxisTitle = sal_False,
2535 bHasSecondaryXAxisTitle = sal_False,
2536 bHasSecondaryYAxisTitle = sal_False;
2537 sal_Bool bHasXAxisMajorGrid = sal_False,
2538 bHasXAxisMinorGrid = sal_False,
2539 bHasYAxisMajorGrid = sal_False,
2540 bHasYAxisMinorGrid = sal_False,
2541 bHasZAxisMajorGrid = sal_False,
2542 bHasZAxisMinorGrid = sal_False;
2543
2544 // get multiple properties using XMultiPropertySet
2545 MultiPropertySetHandler aDiagramProperties (xDiagram);
2546
2547 aDiagramProperties.Add (
2548 OUString(RTL_CONSTASCII_USTRINGPARAM("HasXAxis")), bHasXAxis);
2549 aDiagramProperties.Add (
2550 OUString(RTL_CONSTASCII_USTRINGPARAM("HasYAxis")), bHasYAxis);
2551 aDiagramProperties.Add (
2552 OUString(RTL_CONSTASCII_USTRINGPARAM("HasZAxis")), bHasZAxis);
2553 aDiagramProperties.Add (
2554 OUString(RTL_CONSTASCII_USTRINGPARAM("HasSecondaryXAxis")), bHasSecondaryXAxis);
2555 aDiagramProperties.Add (
2556 OUString(RTL_CONSTASCII_USTRINGPARAM("HasSecondaryYAxis")), bHasSecondaryYAxis);
2557
2558 aDiagramProperties.Add (
2559 OUString (RTL_CONSTASCII_USTRINGPARAM ("HasXAxisTitle")), bHasXAxisTitle);
2560 aDiagramProperties.Add (
2561 OUString (RTL_CONSTASCII_USTRINGPARAM ("HasYAxisTitle")), bHasYAxisTitle);
2562 aDiagramProperties.Add (
2563 OUString (RTL_CONSTASCII_USTRINGPARAM ("HasZAxisTitle")), bHasZAxisTitle);
2564 aDiagramProperties.Add (
2565 OUString (RTL_CONSTASCII_USTRINGPARAM ("HasSecondaryXAxisTitle")), bHasSecondaryXAxisTitle);
2566 aDiagramProperties.Add (
2567 OUString (RTL_CONSTASCII_USTRINGPARAM ("HasSecondaryYAxisTitle")), bHasSecondaryYAxisTitle);
2568
2569 aDiagramProperties.Add (
2570 OUString (RTL_CONSTASCII_USTRINGPARAM ("HasXAxisGrid")), bHasXAxisMajorGrid);
2571 aDiagramProperties.Add (
2572 OUString (RTL_CONSTASCII_USTRINGPARAM ("HasYAxisGrid")), bHasYAxisMajorGrid);
2573 aDiagramProperties.Add (
2574 OUString (RTL_CONSTASCII_USTRINGPARAM ("HasZAxisGrid")), bHasZAxisMajorGrid);
2575
2576 aDiagramProperties.Add (
2577 OUString (RTL_CONSTASCII_USTRINGPARAM ("HasXAxisHelpGrid")), bHasXAxisMinorGrid);
2578 aDiagramProperties.Add (
2579 OUString (RTL_CONSTASCII_USTRINGPARAM ("HasYAxisHelpGrid")), bHasYAxisMinorGrid);
2580 aDiagramProperties.Add (
2581 OUString (RTL_CONSTASCII_USTRINGPARAM ("HasZAxisHelpGrid")), bHasZAxisMinorGrid);
2582
2583 if ( ! aDiagramProperties.GetProperties ())
2584 {
2585 DBG_WARNING ("Required properties not found in Chart diagram");
2586 }
2587
2588 Reference< chart2::XCoordinateSystem > xCooSys( lcl_getCooSys(xNewDiagram) );
2589
2590 // write an axis element also if the axis itself is not visible, but a grid or a title
2591
2592 OUString aCategoriesRange;
2593 Reference< chart::XAxisSupplier > xAxisSupp( xDiagram, uno::UNO_QUERY );
2594
2595 // x axis
2596 // -------
2597 Reference< ::com::sun::star::chart2::XAxis > xNewAxis = lcl_getAxis( xCooSys, XML_X );
2598 if( xNewAxis.is() )
2599 {
2600 Reference< beans::XPropertySet > xAxisProps( xAxisSupp.is() ? xAxisSupp->getAxis(0) : 0, uno::UNO_QUERY );
2601 if( mbHasCategoryLabels && bExportContent )
2602 {
2603 Reference< chart2::data::XLabeledDataSequence > xCategories( lcl_getCategories( xNewDiagram ) );
2604 if( xCategories.is() )
2605 {
2606 Reference< chart2::data::XDataSequence > xValues( xCategories->getValues() );
2607 if( xValues.is() )
2608 {
2609 Reference< chart2::XChartDocument > xNewDoc( mrExport.GetModel(), uno::UNO_QUERY );
2610 maCategoriesRange = xValues->getSourceRangeRepresentation();
2611 aCategoriesRange = lcl_ConvertRange( maCategoriesRange, xNewDoc );
2612 }
2613 }
2614 }
2615 exportAxis( XML_X, XML_PRIMARY_X, xAxisProps, xNewAxis, aCategoriesRange, bHasXAxisTitle, bHasXAxisMajorGrid, bHasXAxisMinorGrid, bExportContent );
2616 aCategoriesRange = OUString();
2617 }
2618
2619 // secondary x axis
2620 // -------
2621 Reference< chart::XSecondAxisTitleSupplier > xSecondTitleSupp( xDiagram, uno::UNO_QUERY );
2622 xNewAxis = lcl_getAxis( xCooSys, XML_X, false );
2623 if( xNewAxis.is() )
2624 {
2625 Reference< beans::XPropertySet > xAxisProps( xAxisSupp.is() ? xAxisSupp->getSecondaryAxis(0) : 0, uno::UNO_QUERY );
2626 exportAxis( XML_X, XML_SECONDARY_X, xAxisProps, xNewAxis, aCategoriesRange, bHasSecondaryXAxisTitle, false, false, bExportContent );
2627 }
2628
2629 // y axis
2630 // -------
2631 xNewAxis = lcl_getAxis( xCooSys, XML_Y );
2632 if( xNewAxis.is() )
2633 {
2634 Reference< beans::XPropertySet > xAxisProps( xAxisSupp.is() ? xAxisSupp->getAxis(1) : 0, uno::UNO_QUERY );
2635 exportAxis( XML_Y, XML_PRIMARY_Y, xAxisProps, xNewAxis, aCategoriesRange, bHasYAxisTitle, bHasYAxisMajorGrid, bHasYAxisMinorGrid, bExportContent );
2636 }
2637
2638 // secondary y axis
2639 // -------
2640 xNewAxis = lcl_getAxis( xCooSys, XML_Y, false );
2641 if( xNewAxis.is() )
2642 {
2643 Reference< beans::XPropertySet > xAxisProps( xAxisSupp.is() ? xAxisSupp->getSecondaryAxis(1) : 0, uno::UNO_QUERY );
2644 exportAxis( XML_Y, XML_SECONDARY_Y, xAxisProps, xNewAxis, aCategoriesRange, bHasSecondaryYAxisTitle, false, false, bExportContent );
2645 }
2646
2647 // z axis
2648 // -------
2649 xNewAxis = lcl_getAxis( xCooSys, XML_Z );
2650 if( xNewAxis.is() )
2651 {
2652 Reference< beans::XPropertySet > xAxisProps( xAxisSupp.is() ? xAxisSupp->getAxis(2) : 0, uno::UNO_QUERY );
2653 exportAxis( XML_Z, XML_PRIMARY_Z, xAxisProps, xNewAxis, aCategoriesRange, bHasZAxisTitle, bHasZAxisMajorGrid, bHasZAxisMinorGrid, bExportContent );
2654 }
2655 }
2656
2657 namespace
2658 {
lcl_hasNoValuesButText(const uno::Reference<chart2::data::XDataSequence> & xDataSequence)2659 bool lcl_hasNoValuesButText( const uno::Reference< chart2::data::XDataSequence >& xDataSequence )
2660 {
2661 if( !xDataSequence.is() )
2662 return false;//have no data
2663
2664 Sequence< uno::Any > aData;
2665 Reference< chart2::data::XNumericalDataSequence > xNumericalDataSequence( xDataSequence, uno::UNO_QUERY );
2666 if( xNumericalDataSequence.is() )
2667 {
2668 Sequence< double > aDoubles( xNumericalDataSequence->getNumericalData() );
2669 sal_Int32 nCount = aDoubles.getLength();
2670 for( sal_Int32 i = 0; i < nCount; ++i )
2671 {
2672 if( !::rtl::math::isNan( aDoubles[i] ) )
2673 return false;//have double value
2674 }
2675 }
2676 else
2677 {
2678 aData = xDataSequence->getData();
2679 double fDouble = 0.0;
2680 sal_Int32 nCount = aData.getLength();
2681 for( sal_Int32 i = 0; i < nCount; ++i )
2682 {
2683 if( (aData[i] >>= fDouble) && !::rtl::math::isNan( fDouble ) )
2684 return false;//have double value
2685 }
2686
2687 }
2688 //no values found
2689
2690 Reference< chart2::data::XTextualDataSequence > xTextualDataSequence( xDataSequence, uno::UNO_QUERY );
2691 if( xTextualDataSequence.is() )
2692 {
2693 uno::Sequence< rtl::OUString > aStrings( xTextualDataSequence->getTextualData() );
2694 sal_Int32 nCount = aStrings.getLength();
2695 for( sal_Int32 i = 0; i < nCount; ++i )
2696 {
2697 if( aStrings[i].getLength() )
2698 return true;//have text
2699 }
2700 }
2701 else
2702 {
2703 if( !aData.getLength() )
2704 aData = xDataSequence->getData();
2705 uno::Any aAny;
2706 OUString aString;
2707 sal_Int32 nCount = aData.getLength();
2708 for( sal_Int32 i = 0; i < nCount; ++i )
2709 {
2710 if( (aData[i]>>=aString) && aString.getLength() )
2711 return true;//have text
2712 }
2713 }
2714 //no doubles and no texts
2715 return false;
2716 }
2717 }
2718
exportSeries(const Reference<chart2::XDiagram> & xNewDiagram,const awt::Size & rPageSize,sal_Bool bExportContent,sal_Bool bHasTwoYAxes)2719 void SchXMLExportHelper_Impl::exportSeries(
2720 const Reference< chart2::XDiagram > & xNewDiagram,
2721 const awt::Size & rPageSize,
2722 sal_Bool bExportContent,
2723 sal_Bool bHasTwoYAxes )
2724 {
2725 Reference< chart2::XCoordinateSystemContainer > xBCooSysCnt( xNewDiagram, uno::UNO_QUERY );
2726 if( ! xBCooSysCnt.is())
2727 return;
2728 Reference< chart2::XChartDocument > xNewDoc( mrExport.GetModel(), uno::UNO_QUERY );
2729
2730 OUString aFirstXDomainRange;
2731 OUString aFirstYDomainRange;
2732
2733 std::vector< XMLPropertyState > aPropertyStates;
2734
2735 const OUString sNumFormat( OUString::createFromAscii( "NumberFormat" ));
2736 const OUString sPercentageNumFormat( OUString::createFromAscii( "PercentageNumberFormat" ));
2737
2738 Sequence< Reference< chart2::XCoordinateSystem > >
2739 aCooSysSeq( xBCooSysCnt->getCoordinateSystems());
2740 for( sal_Int32 nCSIdx=0; nCSIdx<aCooSysSeq.getLength(); ++nCSIdx )
2741 {
2742 Reference< chart2::XChartTypeContainer > xCTCnt( aCooSysSeq[nCSIdx], uno::UNO_QUERY );
2743 if( ! xCTCnt.is())
2744 continue;
2745 Sequence< Reference< chart2::XChartType > > aCTSeq( xCTCnt->getChartTypes());
2746 for( sal_Int32 nCTIdx=0; nCTIdx<aCTSeq.getLength(); ++nCTIdx )
2747 {
2748 Reference< chart2::XDataSeriesContainer > xDSCnt( aCTSeq[nCTIdx], uno::UNO_QUERY );
2749 if( ! xDSCnt.is())
2750 continue;
2751 // note: if xDSCnt.is() then also aCTSeq[nCTIdx]
2752 OUString aChartType( aCTSeq[nCTIdx]->getChartType());
2753 OUString aLabelRole = aCTSeq[nCTIdx]->getRoleOfSequenceForSeriesLabel();
2754
2755 // special export for stock charts
2756 if( aChartType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.chart2.CandleStickChartType")))
2757 {
2758 sal_Bool bJapaneseCandleSticks = sal_False;
2759 Reference< beans::XPropertySet > xCTProp( aCTSeq[nCTIdx], uno::UNO_QUERY );
2760 if( xCTProp.is())
2761 xCTProp->getPropertyValue( OUString::createFromAscii("Japanese")) >>= bJapaneseCandleSticks;
2762 exportCandleStickSeries(
2763 xDSCnt->getDataSeries(), xNewDiagram, bJapaneseCandleSticks, bExportContent );
2764 continue;
2765 }
2766
2767 // export dataseries for current chart-type
2768 Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xDSCnt->getDataSeries());
2769 for( sal_Int32 nSeriesIdx=0; nSeriesIdx<aSeriesSeq.getLength(); ++nSeriesIdx )
2770 {
2771 // export series
2772 Reference< chart2::data::XDataSource > xSource( aSeriesSeq[nSeriesIdx], uno::UNO_QUERY );
2773 if( xSource.is())
2774 {
2775 SvXMLElementExport* pSeries = NULL;
2776 Sequence< Reference< chart2::data::XLabeledDataSequence > > aSeqCnt(
2777 xSource->getDataSequences());
2778 sal_Int32 nMainSequenceIndex = -1;
2779 sal_Int32 nSeriesLength = 0;
2780 sal_Int32 nAttachedAxis = chart::ChartAxisAssign::PRIMARY_Y;
2781 sal_Bool bHasMeanValueLine = false;
2782 chart::ChartRegressionCurveType eRegressionType( chart::ChartRegressionCurveType_NONE );
2783 chart::ChartErrorIndicatorType eErrorType( chart::ChartErrorIndicatorType_NONE );
2784 sal_Int32 nErrorBarStyle( chart::ErrorBarStyle::NONE );
2785 Reference< beans::XPropertySet > xPropSet;
2786 tLabelValuesDataPair aSeriesLabelValuesPair;
2787
2788 // search for main sequence and create a series element
2789 {
2790 Reference< chart2::data::XDataSequence > xValuesSeq;
2791 Reference< chart2::data::XDataSequence > xLabelSeq;
2792 sal_Int32 nSeqIdx=0;
2793 for( ; nSeqIdx<aSeqCnt.getLength(); ++nSeqIdx )
2794 {
2795 OUString aRole;
2796 Reference< chart2::data::XDataSequence > xTempValueSeq( aSeqCnt[nSeqIdx]->getValues() );
2797 if( nMainSequenceIndex==-1 )
2798 {
2799 Reference< beans::XPropertySet > xSeqProp( xTempValueSeq, uno::UNO_QUERY );
2800 if( xSeqProp.is())
2801 xSeqProp->getPropertyValue(OUString::createFromAscii("Role")) >>= aRole;
2802 // "main" sequence
2803 if( aRole.equals( aLabelRole ))
2804 {
2805 xValuesSeq.set( xTempValueSeq );
2806 xLabelSeq.set( aSeqCnt[nSeqIdx]->getLabel());
2807 nMainSequenceIndex = nSeqIdx;
2808 }
2809 }
2810 sal_Int32 nSequenceLength = (xTempValueSeq.is()? xTempValueSeq->getData().getLength() : sal_Int32(0));
2811 if( nSeriesLength < nSequenceLength )
2812 nSeriesLength = nSequenceLength;
2813 }
2814
2815 // have found the main sequence, then xValuesSeq and
2816 // xLabelSeq contain those. Otherwise both are empty
2817 {
2818 // get property states for autostyles
2819 try
2820 {
2821 xPropSet = SchXMLSeriesHelper::createOldAPISeriesPropertySet(
2822 aSeriesSeq[nSeriesIdx], mrExport.GetModel() );
2823 }
2824 catch( uno::Exception & rEx )
2825 {
2826 (void)rEx; // avoid warning for pro build
2827 OSL_TRACE(
2828 OUStringToOString(
2829 OUString( RTL_CONSTASCII_USTRINGPARAM(
2830 "Series not found or no XPropertySet: " )) +
2831 rEx.Message,
2832 RTL_TEXTENCODING_ASCII_US ).getStr());
2833 continue;
2834 }
2835 if( xPropSet.is())
2836 {
2837 // determine attached axis
2838 try
2839 {
2840 Any aAny( xPropSet->getPropertyValue(
2841 OUString( RTL_CONSTASCII_USTRINGPARAM( "Axis" ))));
2842 aAny >>= nAttachedAxis;
2843
2844 aAny = xPropSet->getPropertyValue(
2845 OUString( RTL_CONSTASCII_USTRINGPARAM ( "MeanValue" )));
2846 aAny >>= bHasMeanValueLine;
2847
2848 aAny = xPropSet->getPropertyValue(
2849 OUString( RTL_CONSTASCII_USTRINGPARAM( "RegressionCurves" )));
2850 aAny >>= eRegressionType;
2851
2852 aAny = xPropSet->getPropertyValue(
2853 OUString( RTL_CONSTASCII_USTRINGPARAM( "ErrorIndicator" )));
2854 aAny >>= eErrorType;
2855
2856 aAny = xPropSet->getPropertyValue(
2857 OUString( RTL_CONSTASCII_USTRINGPARAM( "ErrorBarStyle" )));
2858 aAny >>= nErrorBarStyle;
2859 }
2860 catch( beans::UnknownPropertyException & rEx )
2861 {
2862 (void)rEx; // avoid warning for pro build
2863 OSL_TRACE(
2864 OUStringToOString(
2865 OUString( RTL_CONSTASCII_USTRINGPARAM(
2866 "Required property not found in DataRowProperties: " )) +
2867 rEx.Message,
2868 RTL_TEXTENCODING_ASCII_US ).getStr());
2869 }
2870
2871 const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() );
2872 if( nCurrentODFVersion >= SvtSaveOptions::ODFVER_012 )
2873 {
2874 lcl_exportNumberFormat( sNumFormat, xPropSet, mrExport );
2875 lcl_exportNumberFormat( sPercentageNumFormat, xPropSet, mrExport );
2876 }
2877
2878 if( mxExpPropMapper.is())
2879 aPropertyStates = mxExpPropMapper->Filter( xPropSet );
2880 }
2881
2882 if( bExportContent )
2883 {
2884 if( bHasTwoYAxes )
2885 {
2886 if( nAttachedAxis == chart::ChartAxisAssign::SECONDARY_Y )
2887 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_ATTACHED_AXIS, XML_SECONDARY_Y );
2888 else
2889 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_ATTACHED_AXIS, XML_PRIMARY_Y );
2890 }
2891
2892 // write style name
2893 AddAutoStyleAttribute( aPropertyStates );
2894
2895 if( xValuesSeq.is())
2896 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_VALUES_CELL_RANGE_ADDRESS,
2897 lcl_ConvertRange(
2898 xValuesSeq->getSourceRangeRepresentation(),
2899 xNewDoc ));
2900 else
2901 // #i75297# allow empty series, export empty range to have all ranges on import
2902 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_VALUES_CELL_RANGE_ADDRESS, OUString());
2903
2904 if( xLabelSeq.is())
2905 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_LABEL_CELL_ADDRESS,
2906 lcl_ConvertRange(
2907 xLabelSeq->getSourceRangeRepresentation(),
2908 xNewDoc ));
2909 if( xLabelSeq.is() || xValuesSeq.is() )
2910 aSeriesLabelValuesPair = tLabelValuesDataPair( xLabelSeq, xValuesSeq );
2911
2912 // chart-type for mixed types
2913 enum XMLTokenEnum eCTToken(
2914 SchXMLTools::getTokenByChartType( aChartType, false /* bUseOldNames */ ));
2915 //@todo: get token for current charttype
2916 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_CLASS,
2917 mrExport.GetNamespaceMap().GetQNameByKey(
2918 XML_NAMESPACE_CHART, GetXMLToken( eCTToken )));
2919
2920 // open series element until end of for loop
2921 pSeries = new SvXMLElementExport( mrExport, XML_NAMESPACE_CHART, XML_SERIES, sal_True, sal_True );
2922 }
2923 else // autostyles
2924 {
2925 CollectAutoStyle( aPropertyStates );
2926 }
2927 // remove property states for autostyles
2928 aPropertyStates.clear();
2929 }
2930 }
2931
2932 // export domain elements if we have a series parent element
2933 if( pSeries )
2934 {
2935 // domain elements
2936 if( bExportContent )
2937 {
2938 bool bIsScatterChart = aChartType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.chart2.ScatterChartType"));
2939 bool bIsBubbleChart = aChartType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.chart2.BubbleChartType"));
2940 Reference< chart2::data::XDataSequence > xYValuesForBubbleChart;
2941 if( bIsBubbleChart )
2942 {
2943 Reference< chart2::data::XLabeledDataSequence > xSequence( lcl_getDataSequenceByRole( aSeqCnt, OUString::createFromAscii("values-y" ) ) );
2944 if( xSequence.is() )
2945 {
2946 xYValuesForBubbleChart = xSequence->getValues();
2947 if( !lcl_exportDomainForThisSequence( xYValuesForBubbleChart, aFirstYDomainRange, mrExport ) )
2948 xYValuesForBubbleChart = 0;
2949 }
2950 }
2951 if( bIsScatterChart || bIsBubbleChart )
2952 {
2953 Reference< chart2::data::XLabeledDataSequence > xSequence( lcl_getDataSequenceByRole( aSeqCnt, OUString::createFromAscii("values-x" ) ) );
2954 if( xSequence.is() )
2955 {
2956 Reference< chart2::data::XDataSequence > xValues( xSequence->getValues() );
2957 if( lcl_exportDomainForThisSequence( xValues, aFirstXDomainRange, mrExport ) )
2958 m_aDataSequencesToExport.push_back( tLabelValuesDataPair( 0, xValues ));
2959 }
2960 else if( nSeriesIdx==0 )
2961 {
2962 //might be that the categories are used as x-values (e.g. for date axis) -> export them accordingly
2963 Reference< chart2::data::XLabeledDataSequence > xCategories( lcl_getCategories( xNewDiagram ) );
2964 if( xCategories.is() )
2965 {
2966 Reference< chart2::data::XDataSequence > xValues( xCategories->getValues() );
2967 if( !lcl_hasNoValuesButText( xValues ) )
2968 lcl_exportDomainForThisSequence( xValues, aFirstXDomainRange, mrExport );
2969 }
2970 }
2971 }
2972 if( xYValuesForBubbleChart.is() )
2973 m_aDataSequencesToExport.push_back( tLabelValuesDataPair( 0, xYValuesForBubbleChart ));
2974 }
2975 }
2976
2977 // add sequences for main sequence after domain sequences,
2978 // so that the export of the local table has the correct order
2979 if( bExportContent &&
2980 (aSeriesLabelValuesPair.first.is() || aSeriesLabelValuesPair.second.is()))
2981 m_aDataSequencesToExport.push_back( aSeriesLabelValuesPair );
2982
2983 // statistical objects:
2984 // regression curves and mean value lines
2985 if( bHasMeanValueLine &&
2986 xPropSet.is() &&
2987 mxExpPropMapper.is() )
2988 {
2989 Reference< beans::XPropertySet > xStatProp;
2990 try
2991 {
2992 Any aPropAny( xPropSet->getPropertyValue(
2993 OUString( RTL_CONSTASCII_USTRINGPARAM( "DataMeanValueProperties" ))));
2994 aPropAny >>= xStatProp;
2995 }
2996 catch( uno::Exception & rEx )
2997 {
2998 (void)rEx; // avoid warning for pro build
2999 DBG_ERROR1( "Exception caught during Export of series - optional DataMeanValueProperties not available: %s",
3000 OUStringToOString( rEx.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
3001 }
3002
3003 if( xStatProp.is() )
3004 {
3005 aPropertyStates = mxExpPropMapper->Filter( xStatProp );
3006
3007 if( !aPropertyStates.empty() )
3008 {
3009 // write element
3010 if( bExportContent )
3011 {
3012 // add style name attribute
3013 AddAutoStyleAttribute( aPropertyStates );
3014
3015 SvXMLElementExport( mrExport, XML_NAMESPACE_CHART, XML_MEAN_VALUE, sal_True, sal_True );
3016 }
3017 else // autostyles
3018 {
3019 CollectAutoStyle( aPropertyStates );
3020 }
3021 }
3022 }
3023 }
3024
3025 if( eRegressionType != chart::ChartRegressionCurveType_NONE &&
3026 xPropSet.is() &&
3027 mxExpPropMapper.is() )
3028 {
3029 exportRegressionCurve( aSeriesSeq[nSeriesIdx], xPropSet, rPageSize, bExportContent );
3030 }
3031
3032 if( nErrorBarStyle != chart::ErrorBarStyle::NONE &&
3033 eErrorType != chart::ChartErrorIndicatorType_NONE &&
3034 xPropSet.is() &&
3035 mxExpPropMapper.is() )
3036 {
3037 Reference< beans::XPropertySet > xStatProp;
3038 try
3039 {
3040 Any aPropAny( xPropSet->getPropertyValue(
3041 OUString( RTL_CONSTASCII_USTRINGPARAM( "DataErrorProperties" ))));
3042 aPropAny >>= xStatProp;
3043 }
3044 catch( uno::Exception & rEx )
3045 {
3046 (void)rEx; // avoid warning for pro build
3047 DBG_ERROR1( "Exception caught during Export of series - optional DataErrorProperties not available: %s",
3048 OUStringToOString( rEx.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
3049 }
3050
3051 if( xStatProp.is() )
3052 {
3053 if( bExportContent &&
3054 nErrorBarStyle == chart::ErrorBarStyle::FROM_DATA )
3055 {
3056 // register data ranges for error bars for export in local table
3057 ::std::vector< Reference< chart2::data::XDataSequence > > aErrorBarSequences(
3058 lcl_getErrorBarSequences( xStatProp ));
3059 for( ::std::vector< Reference< chart2::data::XDataSequence > >::const_iterator aIt(
3060 aErrorBarSequences.begin()); aIt != aErrorBarSequences.end(); ++aIt )
3061 {
3062 m_aDataSequencesToExport.push_back( tLabelValuesDataPair( 0, *aIt ));
3063 }
3064 }
3065
3066 aPropertyStates = mxExpPropMapper->Filter( xStatProp );
3067
3068 if( !aPropertyStates.empty() )
3069 {
3070 // write element
3071 if( bExportContent )
3072 {
3073 // add style name attribute
3074 AddAutoStyleAttribute( aPropertyStates );
3075
3076 const SvtSaveOptions::ODFDefaultVersion nCurrentVersion( SvtSaveOptions().GetODFDefaultVersion() );
3077 if( nCurrentVersion >= SvtSaveOptions::ODFVER_012 )
3078 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_DIMENSION, XML_Y );//#i114149#
3079 SvXMLElementExport( mrExport, XML_NAMESPACE_CHART, XML_ERROR_INDICATOR, sal_True, sal_True );
3080 }
3081 else // autostyles
3082 {
3083 CollectAutoStyle( aPropertyStates );
3084 }
3085 }
3086 }
3087 }
3088
3089 exportDataPoints(
3090 uno::Reference< beans::XPropertySet >( aSeriesSeq[nSeriesIdx], uno::UNO_QUERY ),
3091 nSeriesLength, xNewDiagram, bExportContent );
3092
3093 // close series element
3094 if( pSeries )
3095 delete pSeries;
3096 }
3097 }
3098 aPropertyStates.clear();
3099 }
3100 }
3101 }
3102
exportRegressionCurve(const Reference<chart2::XDataSeries> & xSeries,const Reference<beans::XPropertySet> & xSeriesProp,const awt::Size & rPageSize,sal_Bool bExportContent)3103 void SchXMLExportHelper_Impl::exportRegressionCurve(
3104 const Reference< chart2::XDataSeries > & xSeries,
3105 const Reference< beans::XPropertySet > & xSeriesProp,
3106 const awt::Size & rPageSize,
3107 sal_Bool bExportContent )
3108 {
3109 OSL_ASSERT( mxExpPropMapper.is());
3110
3111 std::vector< XMLPropertyState > aPropertyStates;
3112 std::vector< XMLPropertyState > aEquationPropertyStates;
3113 Reference< beans::XPropertySet > xStatProp;
3114 try
3115 {
3116 Any aPropAny( xSeriesProp->getPropertyValue(
3117 OUString( RTL_CONSTASCII_USTRINGPARAM( "DataRegressionProperties" ))));
3118 aPropAny >>= xStatProp;
3119 }
3120 catch( uno::Exception & rEx )
3121 {
3122 (void)rEx; // avoid warning for pro build
3123 DBG_ERROR1( "Exception caught during Export of series - optional DataRegressionProperties not available: %s",
3124 OUStringToOString( rEx.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
3125 }
3126
3127 if( xStatProp.is() )
3128 {
3129 Reference< chart2::XRegressionCurve > xRegCurve( SchXMLTools::getRegressionCurve( xSeries ));
3130 Reference< beans::XPropertySet > xEquationProperties;
3131 if( xRegCurve.is())
3132 xEquationProperties.set( xRegCurve->getEquationProperties());
3133
3134 bool bShowEquation = false;
3135 bool bShowRSquared = false;
3136 bool bExportEquation = false;
3137 aPropertyStates = mxExpPropMapper->Filter( xStatProp );
3138 if( xEquationProperties.is())
3139 {
3140 xEquationProperties->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "ShowEquation" )))
3141 >>= bShowEquation;
3142 xEquationProperties->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "ShowCorrelationCoefficient" )))
3143 >>= bShowRSquared;
3144 bExportEquation = ( bShowEquation || bShowRSquared );
3145 const SvtSaveOptions::ODFDefaultVersion nCurrentVersion( SvtSaveOptions().GetODFDefaultVersion() );
3146 if( nCurrentVersion < SvtSaveOptions::ODFVER_012 )
3147 bExportEquation=false;
3148 if( bExportEquation )
3149 {
3150 // number format
3151 sal_Int32 nNumberFormat = 0;
3152 if( ( xEquationProperties->getPropertyValue(
3153 OUString( RTL_CONSTASCII_USTRINGPARAM( "NumberFormat" ))) >>= nNumberFormat ) &&
3154 nNumberFormat != -1 )
3155 {
3156 mrExport.addDataStyle( nNumberFormat );
3157 }
3158 aEquationPropertyStates = mxExpPropMapper->Filter( xEquationProperties );
3159 }
3160 }
3161
3162 if( !aPropertyStates.empty() || bExportEquation )
3163 {
3164 // write element
3165 if( bExportContent )
3166 {
3167 // add style name attribute
3168 if( !aPropertyStates.empty())
3169 AddAutoStyleAttribute( aPropertyStates );
3170 SvXMLElementExport aRegressionExport( mrExport, XML_NAMESPACE_CHART, XML_REGRESSION_CURVE, sal_True, sal_True );
3171 if( bExportEquation )
3172 {
3173 // default is true
3174 if( !bShowEquation )
3175 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_DISPLAY_EQUATION, XML_FALSE );
3176 // default is false
3177 if( bShowRSquared )
3178 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_DISPLAY_R_SQUARE, XML_TRUE );
3179
3180 // export position
3181 chart2::RelativePosition aRelativePosition;
3182 if( xEquationProperties->getPropertyValue(
3183 OUString( RTL_CONSTASCII_USTRINGPARAM("RelativePosition"))) >>= aRelativePosition )
3184 {
3185 double fX = aRelativePosition.Primary * rPageSize.Width;
3186 double fY = aRelativePosition.Secondary * rPageSize.Height;
3187 awt::Point aPos;
3188 aPos.X = static_cast< sal_Int32 >( ::rtl::math::round( fX ));
3189 aPos.Y = static_cast< sal_Int32 >( ::rtl::math::round( fY ));
3190 addPosition( aPos );
3191 }
3192
3193 if( !aEquationPropertyStates.empty())
3194 AddAutoStyleAttribute( aEquationPropertyStates );
3195
3196 SvXMLElementExport( mrExport, XML_NAMESPACE_CHART, XML_EQUATION, sal_True, sal_True );
3197 }
3198 }
3199 else // autostyles
3200 {
3201 if( !aPropertyStates.empty())
3202 CollectAutoStyle( aPropertyStates );
3203 if( bExportEquation && !aEquationPropertyStates.empty())
3204 CollectAutoStyle( aEquationPropertyStates );
3205 }
3206 }
3207 }
3208 }
3209
exportCandleStickSeries(const Sequence<Reference<chart2::XDataSeries>> & aSeriesSeq,const Reference<chart2::XDiagram> & xDiagram,sal_Bool bJapaneseCandleSticks,sal_Bool bExportContent)3210 void SchXMLExportHelper_Impl::exportCandleStickSeries(
3211 const Sequence< Reference< chart2::XDataSeries > > & aSeriesSeq,
3212 const Reference< chart2::XDiagram > & xDiagram,
3213 sal_Bool bJapaneseCandleSticks,
3214 sal_Bool bExportContent )
3215 {
3216 // std::vector< XMLPropertyState > aPropertyStates;
3217
3218 for( sal_Int32 nSeriesIdx=0; nSeriesIdx<aSeriesSeq.getLength(); ++nSeriesIdx )
3219 {
3220 Reference< chart2::XDataSeries > xSeries( aSeriesSeq[nSeriesIdx] );
3221 sal_Int32 nAttachedAxis = lcl_isSeriesAttachedToFirstAxis( xSeries )
3222 ? chart::ChartAxisAssign::PRIMARY_Y
3223 : chart::ChartAxisAssign::SECONDARY_Y;
3224
3225 Reference< chart2::data::XDataSource > xSource( xSeries, uno::UNO_QUERY );
3226 if( xSource.is())
3227 {
3228 // export series in correct order (as we don't store roles)
3229 // with japanese candlesticks: open, low, high, close
3230 // otherwise: low, high, close
3231 Sequence< Reference< chart2::data::XLabeledDataSequence > > aSeqCnt(
3232 xSource->getDataSequences());
3233
3234 sal_Int32 nSeriesLength =
3235 lcl_getSequenceLengthByRole( aSeqCnt, OUString::createFromAscii("values-last"));
3236
3237 if( bExportContent )
3238 {
3239 Reference< chart2::XChartDocument > xNewDoc( mrExport.GetModel(), uno::UNO_QUERY );
3240 //@todo: export data points
3241
3242 // open
3243 if( bJapaneseCandleSticks )
3244 {
3245 tLabelAndValueRange aRanges( lcl_getLabelAndValueRangeByRole(
3246 aSeqCnt, OUString::createFromAscii("values-first"), xNewDoc, m_aDataSequencesToExport ));
3247 if( aRanges.second.getLength())
3248 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_VALUES_CELL_RANGE_ADDRESS, aRanges.second );
3249 if( aRanges.first.getLength())
3250 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_LABEL_CELL_ADDRESS, aRanges.first );
3251 if( nAttachedAxis == chart::ChartAxisAssign::SECONDARY_Y )
3252 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_ATTACHED_AXIS, XML_SECONDARY_Y );
3253 else
3254 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_ATTACHED_AXIS, XML_PRIMARY_Y );
3255 SvXMLElementExport aOpenSeries( mrExport, XML_NAMESPACE_CHART, XML_SERIES, sal_True, sal_True );
3256 // export empty data points
3257 exportDataPoints( 0, nSeriesLength, xDiagram, bExportContent );
3258 }
3259
3260 // low
3261 {
3262 tLabelAndValueRange aRanges( lcl_getLabelAndValueRangeByRole(
3263 aSeqCnt, OUString::createFromAscii("values-min"), xNewDoc, m_aDataSequencesToExport ));
3264 if( aRanges.second.getLength())
3265 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_VALUES_CELL_RANGE_ADDRESS, aRanges.second );
3266 if( aRanges.first.getLength())
3267 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_LABEL_CELL_ADDRESS, aRanges.first );
3268 if( nAttachedAxis == chart::ChartAxisAssign::SECONDARY_Y )
3269 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_ATTACHED_AXIS, XML_SECONDARY_Y );
3270 else
3271 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_ATTACHED_AXIS, XML_PRIMARY_Y );
3272 SvXMLElementExport aLowSeries( mrExport, XML_NAMESPACE_CHART, XML_SERIES, sal_True, sal_True );
3273 // export empty data points
3274 exportDataPoints( 0, nSeriesLength, xDiagram, bExportContent );
3275 }
3276
3277 // high
3278 {
3279 tLabelAndValueRange aRanges( lcl_getLabelAndValueRangeByRole(
3280 aSeqCnt, OUString::createFromAscii("values-max"), xNewDoc, m_aDataSequencesToExport ));
3281 if( aRanges.second.getLength())
3282 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_VALUES_CELL_RANGE_ADDRESS, aRanges.second );
3283 if( aRanges.first.getLength())
3284 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_LABEL_CELL_ADDRESS, aRanges.first );
3285 if( nAttachedAxis == chart::ChartAxisAssign::SECONDARY_Y )
3286 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_ATTACHED_AXIS, XML_SECONDARY_Y );
3287 else
3288 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_ATTACHED_AXIS, XML_PRIMARY_Y );
3289 SvXMLElementExport aHighSeries( mrExport, XML_NAMESPACE_CHART, XML_SERIES, sal_True, sal_True );
3290 // export empty data points
3291 exportDataPoints( 0, nSeriesLength, xDiagram, bExportContent );
3292 }
3293
3294 // close
3295 {
3296 tLabelAndValueRange aRanges( lcl_getLabelAndValueRangeByRole(
3297 aSeqCnt, OUString::createFromAscii("values-last"), xNewDoc, m_aDataSequencesToExport ));
3298 if( aRanges.second.getLength())
3299 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_VALUES_CELL_RANGE_ADDRESS, aRanges.second );
3300 if( aRanges.first.getLength())
3301 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_LABEL_CELL_ADDRESS, aRanges.first );
3302 if( nAttachedAxis == chart::ChartAxisAssign::SECONDARY_Y )
3303 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_ATTACHED_AXIS, XML_SECONDARY_Y );
3304 else
3305 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_ATTACHED_AXIS, XML_PRIMARY_Y );
3306 // write style name
3307 // AddAutoStyleAttribute( aPropertyStates );
3308 // chart type
3309 // mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_CLASS,
3310 // mrExport.GetNamespaceMap().GetQNameByKey(
3311 // XML_NAMESPACE_CHART, GetXMLToken( XML_STOCK )));
3312 SvXMLElementExport aCloseSeries( mrExport, XML_NAMESPACE_CHART, XML_SERIES, sal_True, sal_True );
3313 // export empty data points
3314 exportDataPoints( 0, nSeriesLength, xDiagram, bExportContent );
3315 }
3316 }
3317 else // autostyles
3318 {
3319 // for close series
3320 // CollectAutoStyle( aPropertyStates );
3321 }
3322 // remove property states for autostyles
3323 // aPropertyStates.clear();
3324 }
3325 }
3326 }
3327
exportDataPoints(const uno::Reference<beans::XPropertySet> & xSeriesProperties,sal_Int32 nSeriesLength,const uno::Reference<chart2::XDiagram> & xDiagram,sal_Bool bExportContent)3328 void SchXMLExportHelper_Impl::exportDataPoints(
3329 const uno::Reference< beans::XPropertySet > & xSeriesProperties,
3330 sal_Int32 nSeriesLength,
3331 const uno::Reference< chart2::XDiagram > & xDiagram,
3332 sal_Bool bExportContent )
3333 {
3334 // data-points
3335 // -----------
3336 // write data-points only if they contain autostyles
3337 // objects with equal autostyles are grouped using the attribute
3338 // repeat="number"
3339
3340 // Note: if only the nth data-point has autostyles there is an element
3341 // without style and repeat="n-1" attribute written in advance.
3342
3343 // the sequence aDataPointSeq contains indices of data-points that
3344 // do have own attributes. This increases the performance substantially.
3345
3346 // more performant version for #93600#
3347 if( mxExpPropMapper.is())
3348 {
3349 uno::Reference< chart2::XDataSeries > xSeries( xSeriesProperties, uno::UNO_QUERY );
3350
3351 std::vector< XMLPropertyState > aPropertyStates;
3352
3353 const OUString sNumFormat( OUString::createFromAscii( "NumberFormat" ));
3354 const OUString sPercentageNumFormat( OUString::createFromAscii( "PercentageNumberFormat" ));
3355
3356 bool bVaryColorsByPoint = false;
3357 Sequence< sal_Int32 > aDataPointSeq;
3358 if( xSeriesProperties.is())
3359 {
3360 Any aAny = xSeriesProperties->getPropertyValue(
3361 OUString( RTL_CONSTASCII_USTRINGPARAM( "AttributedDataPoints" )));
3362 aAny >>= aDataPointSeq;
3363 xSeriesProperties->getPropertyValue(
3364 OUString( RTL_CONSTASCII_USTRINGPARAM( "VaryColorsByPoint" ))) >>= bVaryColorsByPoint;
3365 }
3366
3367
3368 sal_Int32 nSize = aDataPointSeq.getLength();
3369 DBG_ASSERT( nSize <= nSeriesLength, "Too many point attributes" );
3370
3371 const sal_Int32 * pPoints = aDataPointSeq.getConstArray();
3372 sal_Int32 nElement;
3373 sal_Int32 nRepeat;
3374 Reference< chart2::XColorScheme > xColorScheme;
3375 if( xDiagram.is())
3376 xColorScheme.set( xDiagram->getDefaultColorScheme());
3377
3378 ::std::list< SchXMLDataPointStruct > aDataPointList;
3379
3380 sal_Int32 nLastIndex = -1;
3381 sal_Int32 nCurrIndex = 0;
3382
3383 // collect elements
3384 if( bVaryColorsByPoint && xColorScheme.is() )
3385 {
3386 ::std::set< sal_Int32 > aAttrPointSet;
3387 ::std::copy( pPoints, pPoints + aDataPointSeq.getLength(),
3388 ::std::inserter( aAttrPointSet, aAttrPointSet.begin()));
3389 const ::std::set< sal_Int32 >::const_iterator aEndIt( aAttrPointSet.end());
3390 for( nElement = 0; nElement < nSeriesLength; ++nElement )
3391 {
3392 aPropertyStates.clear();
3393 uno::Reference< beans::XPropertySet > xPropSet;
3394 bool bExportNumFmt = false;
3395 if( aAttrPointSet.find( nElement ) != aEndIt )
3396 {
3397 try
3398 {
3399 xPropSet = SchXMLSeriesHelper::createOldAPIDataPointPropertySet(
3400 xSeries, nElement, mrExport.GetModel() );
3401 bExportNumFmt = true;
3402 }
3403 catch( uno::Exception & rEx )
3404 {
3405 (void)rEx; // avoid warning for pro build
3406 DBG_ERROR1( "Exception caught during Export of data point: %s",
3407 OUStringToOString( rEx.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
3408 }
3409 }
3410 else
3411 {
3412 // property set only containing the color
3413 xPropSet.set( new ::xmloff::chart::ColorPropertySet(
3414 xColorScheme->getColorByIndex( nElement )));
3415 }
3416 DBG_ASSERT( xPropSet.is(), "Pie Segments should have properties" );
3417 if( xPropSet.is())
3418 {
3419 const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() );
3420 if( nCurrentODFVersion >= SvtSaveOptions::ODFVER_012 && bExportNumFmt )
3421 {
3422 lcl_exportNumberFormat( sNumFormat, xPropSet, mrExport );
3423 lcl_exportNumberFormat( sPercentageNumFormat, xPropSet, mrExport );
3424 }
3425
3426 aPropertyStates = mxExpPropMapper->Filter( xPropSet );
3427 if( !aPropertyStates.empty() )
3428 {
3429 if( bExportContent )
3430 {
3431 // write data-point with style
3432 DBG_ASSERT( ! maAutoStyleNameQueue.empty(), "Autostyle queue empty!" );
3433
3434 SchXMLDataPointStruct aPoint;
3435 aPoint.maStyleName = maAutoStyleNameQueue.front();
3436 maAutoStyleNameQueue.pop();
3437 aDataPointList.push_back( aPoint );
3438 }
3439 else
3440 {
3441 CollectAutoStyle( aPropertyStates );
3442 }
3443 }
3444 }
3445 }
3446 DBG_ASSERT( !bExportContent || (static_cast<sal_Int32>(aDataPointList.size()) == nSeriesLength),
3447 "not enough data points on content export" );
3448 }
3449 else
3450 {
3451 for( nElement = 0; nElement < nSize; ++nElement )
3452 {
3453 aPropertyStates.clear();
3454 nCurrIndex = pPoints[ nElement ];
3455 //assuming sorted indices in pPoints
3456
3457 if( nCurrIndex<0 || nCurrIndex>=nSeriesLength )
3458 break;
3459
3460 // write leading empty data points
3461 if( nCurrIndex - nLastIndex > 1 )
3462 {
3463 SchXMLDataPointStruct aPoint;
3464 aPoint.mnRepeat = nCurrIndex - nLastIndex - 1;
3465 aDataPointList.push_back( aPoint );
3466 }
3467
3468 uno::Reference< beans::XPropertySet > xPropSet;
3469 // get property states
3470 try
3471 {
3472 xPropSet = SchXMLSeriesHelper::createOldAPIDataPointPropertySet(
3473 xSeries, nCurrIndex, mrExport.GetModel() );
3474 }
3475 catch( uno::Exception & rEx )
3476 {
3477 (void)rEx; // avoid warning for pro build
3478 DBG_ERROR1( "Exception caught during Export of data point: %s",
3479 OUStringToOString( rEx.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
3480 }
3481 if( xPropSet.is())
3482 {
3483 const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() );
3484 if( nCurrentODFVersion >= SvtSaveOptions::ODFVER_012 )
3485 {
3486 lcl_exportNumberFormat( sNumFormat, xPropSet, mrExport );
3487 lcl_exportNumberFormat( sPercentageNumFormat, xPropSet, mrExport );
3488 }
3489
3490 aPropertyStates = mxExpPropMapper->Filter( xPropSet );
3491 if( !aPropertyStates.empty() )
3492 {
3493 if( bExportContent )
3494 {
3495 // write data-point with style
3496 DBG_ASSERT( ! maAutoStyleNameQueue.empty(), "Autostyle queue empty!" );
3497 SchXMLDataPointStruct aPoint;
3498 aPoint.maStyleName = maAutoStyleNameQueue.front();
3499 maAutoStyleNameQueue.pop();
3500
3501 aDataPointList.push_back( aPoint );
3502 nLastIndex = nCurrIndex;
3503 }
3504 else
3505 {
3506 CollectAutoStyle( aPropertyStates );
3507 }
3508 continue;
3509 }
3510 }
3511
3512 // if we get here the property states are empty
3513 SchXMLDataPointStruct aPoint;
3514 aDataPointList.push_back( aPoint );
3515
3516 nLastIndex = nCurrIndex;
3517 }
3518 // final empty elements
3519 nRepeat = nSeriesLength - nLastIndex - 1;
3520 if( nRepeat > 0 )
3521 {
3522 SchXMLDataPointStruct aPoint;
3523 aPoint.mnRepeat = nRepeat;
3524 aDataPointList.push_back( aPoint );
3525 }
3526 }
3527
3528 if( bExportContent )
3529 {
3530 // write elements (merge equal ones)
3531 ::std::list< SchXMLDataPointStruct >::iterator aIter = aDataPointList.begin();
3532 SchXMLDataPointStruct aPoint;
3533 SchXMLDataPointStruct aLastPoint;
3534
3535 // initialize so that it doesn't matter if
3536 // the element is counted in the first iteration
3537 aLastPoint.mnRepeat = 0;
3538
3539 for( ; aIter != aDataPointList.end(); ++aIter )
3540 {
3541 aPoint = (*aIter);
3542
3543 if( aPoint.maStyleName == aLastPoint.maStyleName )
3544 aPoint.mnRepeat += aLastPoint.mnRepeat;
3545 else if( aLastPoint.mnRepeat > 0 )
3546 {
3547 // write last element
3548 if( aLastPoint.maStyleName.getLength() )
3549 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_STYLE_NAME, aLastPoint.maStyleName );
3550
3551 if( aLastPoint.mnRepeat > 1 )
3552 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_REPEATED,
3553 OUString::valueOf( (sal_Int64)( aLastPoint.mnRepeat ) ));
3554
3555 SvXMLElementExport aPointElem( mrExport, XML_NAMESPACE_CHART, XML_DATA_POINT, sal_True, sal_True );
3556 }
3557 aLastPoint = aPoint;
3558 }
3559 // write last element if it hasn't been written in last iteration
3560 if( aPoint.maStyleName == aLastPoint.maStyleName )
3561 {
3562 if( aLastPoint.maStyleName.getLength() )
3563 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_STYLE_NAME, aLastPoint.maStyleName );
3564
3565 if( aLastPoint.mnRepeat > 1 )
3566 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_REPEATED,
3567 OUString::valueOf( (sal_Int64)( aLastPoint.mnRepeat ) ));
3568
3569 SvXMLElementExport aPointElem( mrExport, XML_NAMESPACE_CHART, XML_DATA_POINT, sal_True, sal_True );
3570 }
3571 }
3572 }
3573 }
3574
3575
getCellAddress(sal_Int32 nCol,sal_Int32 nRow)3576 void SchXMLExportHelper_Impl::getCellAddress( sal_Int32 nCol, sal_Int32 nRow )
3577 {
3578 msStringBuffer.append( (sal_Unicode)'.' );
3579 if( nCol < 26 )
3580 msStringBuffer.append( (sal_Unicode)('A' + nCol) );
3581 else if( nCol < 702 )
3582 {
3583 msStringBuffer.append( (sal_Unicode)('A' + nCol / 26 - 1 ));
3584 msStringBuffer.append( (sal_Unicode)('A' + nCol % 26) );
3585 }
3586 else
3587 {
3588 msStringBuffer.append( (sal_Unicode)('A' + nCol / 702 - 1 ));
3589 msStringBuffer.append( (sal_Unicode)('A' + (nCol % 702) / 26 ));
3590 msStringBuffer.append( (sal_Unicode)('A' + nCol % 26) );
3591 }
3592
3593 msStringBuffer.append( nRow + (sal_Int32)1 );
3594 }
3595
addPosition(const awt::Point & rPosition)3596 void SchXMLExportHelper_Impl::addPosition( const awt::Point & rPosition )
3597 {
3598 mrExport.GetMM100UnitConverter().convertMeasure( msStringBuffer, rPosition.X );
3599 msString = msStringBuffer.makeStringAndClear();
3600 mrExport.AddAttribute( XML_NAMESPACE_SVG, XML_X, msString );
3601
3602 mrExport.GetMM100UnitConverter().convertMeasure( msStringBuffer, rPosition.Y );
3603 msString = msStringBuffer.makeStringAndClear();
3604 mrExport.AddAttribute( XML_NAMESPACE_SVG, XML_Y, msString );
3605 }
3606
addPosition(Reference<drawing::XShape> xShape)3607 void SchXMLExportHelper_Impl::addPosition( Reference< drawing::XShape > xShape )
3608 {
3609 if( xShape.is())
3610 addPosition( xShape->getPosition());
3611 }
3612
addSize(const awt::Size & rSize,bool bIsOOoNamespace)3613 void SchXMLExportHelper_Impl::addSize( const awt::Size & rSize, bool bIsOOoNamespace)
3614 {
3615 mrExport.GetMM100UnitConverter().convertMeasure( msStringBuffer, rSize.Width );
3616 msString = msStringBuffer.makeStringAndClear();
3617 mrExport.AddAttribute( bIsOOoNamespace ? XML_NAMESPACE_CHART_EXT : XML_NAMESPACE_SVG , XML_WIDTH, msString );
3618
3619
3620 mrExport.GetMM100UnitConverter().convertMeasure( msStringBuffer, rSize.Height);
3621 msString = msStringBuffer.makeStringAndClear();
3622 mrExport.AddAttribute( bIsOOoNamespace ? XML_NAMESPACE_CHART_EXT : XML_NAMESPACE_SVG, XML_HEIGHT, msString );
3623 }
3624
addSize(Reference<drawing::XShape> xShape,bool bIsOOoNamespace)3625 void SchXMLExportHelper_Impl::addSize( Reference< drawing::XShape > xShape, bool bIsOOoNamespace )
3626 {
3627 if( xShape.is())
3628 addSize( xShape->getSize(), bIsOOoNamespace );
3629 }
3630
getPageSize(const Reference<chart2::XChartDocument> & xChartDoc) const3631 awt::Size SchXMLExportHelper_Impl::getPageSize( const Reference< chart2::XChartDocument > & xChartDoc ) const
3632 {
3633 awt::Size aSize( 8000, 7000 );
3634 uno::Reference< embed::XVisualObject > xVisualObject( xChartDoc, uno::UNO_QUERY );
3635 DBG_ASSERT( xVisualObject.is(),"need XVisualObject for page size" );
3636 if( xVisualObject.is() )
3637 aSize = xVisualObject->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT );
3638
3639 return aSize;
3640 }
3641
CollectAutoStyle(const std::vector<XMLPropertyState> & aStates)3642 void SchXMLExportHelper_Impl::CollectAutoStyle( const std::vector< XMLPropertyState >& aStates )
3643 {
3644 if( !aStates.empty() )
3645 maAutoStyleNameQueue.push( GetAutoStylePoolP().Add( XML_STYLE_FAMILY_SCH_CHART_ID, aStates ));
3646 }
3647
AddAutoStyleAttribute(const std::vector<XMLPropertyState> & aStates)3648 void SchXMLExportHelper_Impl::AddAutoStyleAttribute( const std::vector< XMLPropertyState >& aStates )
3649 {
3650 if( !aStates.empty() )
3651 {
3652 DBG_ASSERT( ! maAutoStyleNameQueue.empty(), "Autostyle queue empty!" );
3653
3654 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_STYLE_NAME, maAutoStyleNameQueue.front() );
3655 maAutoStyleNameQueue.pop();
3656 }
3657 }
3658
exportText(const OUString & rText,bool bConvertTabsLFs)3659 void SchXMLExportHelper_Impl::exportText( const OUString& rText, bool bConvertTabsLFs )
3660 {
3661 SchXMLTools::exportText( mrExport, rText, bConvertTabsLFs );
3662 }
3663
3664 // ========================================
3665 // class SchXMLExport
3666 // ========================================
3667
3668 // #110680#
SchXMLExport(const Reference<lang::XMultiServiceFactory> & xServiceFactory,sal_uInt16 nExportFlags)3669 SchXMLExport::SchXMLExport(
3670 const Reference< lang::XMultiServiceFactory >& xServiceFactory,
3671 sal_uInt16 nExportFlags )
3672 : SvXMLExport( xServiceFactory, MAP_CM, ::xmloff::token::XML_CHART, nExportFlags ),
3673 maAutoStylePool( *this ),
3674 maExportHelper( *this, maAutoStylePool )
3675 {
3676 if( SvtSaveOptions::IsODFExtended( getDefaultVersion() ) )
3677 _GetNamespaceMap().Add( GetXMLToken(XML_NP_CHART_EXT), GetXMLToken(XML_N_CHART_EXT), XML_NAMESPACE_CHART_EXT);
3678 }
3679
3680
~SchXMLExport()3681 SchXMLExport::~SchXMLExport()
3682 {
3683 // stop progress view
3684 if( mxStatusIndicator.is())
3685 {
3686 mxStatusIndicator->end();
3687 mxStatusIndicator->reset();
3688 }
3689 }
3690
exportDoc(enum::xmloff::token::XMLTokenEnum eClass)3691 sal_uInt32 SchXMLExport::exportDoc( enum ::xmloff::token::XMLTokenEnum eClass )
3692 {
3693 Reference< chart2::XChartDocument > xChartDoc( GetModel(), uno::UNO_QUERY );
3694 maExportHelper.m_pImpl->InitRangeSegmentationProperties( xChartDoc );
3695 return SvXMLExport::exportDoc( eClass );
3696 }
3697
_ExportStyles(sal_Bool bUsed)3698 void SchXMLExport::_ExportStyles( sal_Bool bUsed )
3699 {
3700 SvXMLExport::_ExportStyles( bUsed );
3701 }
3702
_ExportMasterStyles()3703 void SchXMLExport::_ExportMasterStyles()
3704 {
3705 // not available in chart
3706 DBG_WARNING( "Master Style Export requested. Not available for Chart" );
3707 }
3708
_ExportAutoStyles()3709 void SchXMLExport::_ExportAutoStyles()
3710 {
3711 // there are no styles that require their own autostyles
3712 if( getExportFlags() & EXPORT_CONTENT )
3713 {
3714 Reference< chart::XChartDocument > xChartDoc( GetModel(), uno::UNO_QUERY );
3715 if( xChartDoc.is())
3716 {
3717 maExportHelper.m_pImpl->collectAutoStyles( xChartDoc );
3718 maExportHelper.m_pImpl->exportAutoStyles();
3719 }
3720 else
3721 {
3722 DBG_ERROR( "Couldn't export chart due to wrong XModel (must be XChartDocument)" );
3723 }
3724 }
3725 }
3726
_ExportContent()3727 void SchXMLExport::_ExportContent()
3728 {
3729 Reference< chart::XChartDocument > xChartDoc( GetModel(), uno::UNO_QUERY );
3730 if( xChartDoc.is())
3731 {
3732 // determine if data comes from the outside
3733 sal_Bool bIncludeTable = sal_True;
3734
3735 Reference< chart2::XChartDocument > xNewDoc( xChartDoc, uno::UNO_QUERY );
3736 if( xNewDoc.is())
3737 {
3738 // check if we have own data. If so we must not export the complete
3739 // range string, as this is our only indicator for having own or
3740 // external data. @todo: fix this in the file format!
3741 Reference< lang::XServiceInfo > xDPServiceInfo( xNewDoc->getDataProvider(), uno::UNO_QUERY );
3742 if( ! (xDPServiceInfo.is() &&
3743 xDPServiceInfo->getImplementationName().equalsAsciiL(
3744 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.comp.chart.InternalDataProvider" ))))
3745 {
3746 bIncludeTable = sal_False;
3747 }
3748 }
3749 else
3750 {
3751 Reference< lang::XServiceInfo > xServ( xChartDoc, uno::UNO_QUERY );
3752 if( xServ.is())
3753 {
3754 if( xServ->supportsService(
3755 OUString::createFromAscii( "com.sun.star.chart.ChartTableAddressSupplier" )))
3756 {
3757 Reference< beans::XPropertySet > xProp( xServ, uno::UNO_QUERY );
3758 if( xProp.is())
3759 {
3760 Any aAny;
3761 try
3762 {
3763 OUString sChartAddress;
3764 aAny = xProp->getPropertyValue(
3765 OUString::createFromAscii( "ChartRangeAddress" ));
3766 aAny >>= sChartAddress;
3767 maExportHelper.m_pImpl->SetChartRangeAddress( sChartAddress );
3768
3769 OUString sTableNumberList;
3770 aAny = xProp->getPropertyValue(
3771 OUString::createFromAscii( "TableNumberList" ));
3772 aAny >>= sTableNumberList;
3773 maExportHelper.m_pImpl->SetTableNumberList( sTableNumberList );
3774
3775 // do not include own table if there are external addresses
3776 bIncludeTable = (sChartAddress.getLength() == 0);
3777 }
3778 catch( beans::UnknownPropertyException & )
3779 {
3780 DBG_ERROR( "Property ChartRangeAddress not supported by ChartDocument" );
3781 }
3782 }
3783 }
3784 }
3785 }
3786 maExportHelper.m_pImpl->exportChart( xChartDoc, bIncludeTable );
3787 }
3788 else
3789 {
3790 DBG_ERROR( "Couldn't export chart due to wrong XModel" );
3791 }
3792 }
3793
SetProgress(sal_Int32 nPercentage)3794 void SchXMLExport::SetProgress( sal_Int32 nPercentage )
3795 {
3796 // set progress view
3797 if( mxStatusIndicator.is())
3798 mxStatusIndicator->setValue( nPercentage );
3799 }
3800
GetPropertySetMapper() const3801 UniReference< XMLPropertySetMapper > SchXMLExport::GetPropertySetMapper() const
3802 {
3803 return maExportHelper.m_pImpl->GetPropertySetMapper();
3804 }
3805
InitRangeSegmentationProperties(const Reference<chart2::XChartDocument> & xChartDoc)3806 void SchXMLExportHelper_Impl::InitRangeSegmentationProperties( const Reference< chart2::XChartDocument > & xChartDoc )
3807 {
3808 if( xChartDoc.is())
3809 try
3810 {
3811 Reference< chart2::data::XDataProvider > xDataProvider( xChartDoc->getDataProvider() );
3812 OSL_ENSURE( xDataProvider.is(), "No DataProvider" );
3813 if( xDataProvider.is())
3814 {
3815 Reference< chart2::data::XDataSource > xDataSource( lcl_pressUsedDataIntoRectangularFormat( xChartDoc, mbHasCategoryLabels ));
3816 Sequence< beans::PropertyValue > aArgs( xDataProvider->detectArguments( xDataSource ));
3817 ::rtl::OUString sCellRange, sBrokenRange;
3818 bool bBrokenRangeAvailable = false;
3819 for( sal_Int32 i=0; i<aArgs.getLength(); ++i )
3820 {
3821 if( aArgs[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("CellRangeRepresentation")))
3822 aArgs[i].Value >>= sCellRange;
3823 else if( aArgs[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("BrokenCellRangeForExport")))
3824 {
3825 if( aArgs[i].Value >>= sBrokenRange )
3826 bBrokenRangeAvailable = true;
3827 }
3828 else if( aArgs[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("DataRowSource")))
3829 {
3830 chart::ChartDataRowSource eRowSource;
3831 aArgs[i].Value >>= eRowSource;
3832 mbRowSourceColumns = ( eRowSource == chart::ChartDataRowSource_COLUMNS );
3833 }
3834 else if( aArgs[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("FirstCellAsLabel")))
3835 aArgs[i].Value >>= mbHasSeriesLabels;
3836 else if( aArgs[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("SequenceMapping")))
3837 aArgs[i].Value >>= maSequenceMapping;
3838 else if( aArgs[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("TableNumberList")))
3839 aArgs[i].Value >>= msTableNumberList;
3840 }
3841
3842 // #i79009# For Writer we have to export a broken version of the
3843 // range, where every row number is noe too large, so that older
3844 // version can correctly read those files.
3845 msChartAddress = (bBrokenRangeAvailable ? sBrokenRange : sCellRange);
3846 if( msChartAddress.getLength() > 0 )
3847 {
3848 // convert format to XML-conform one
3849 Reference< chart2::data::XRangeXMLConversion > xConversion( xDataProvider, uno::UNO_QUERY );
3850 if( xConversion.is())
3851 msChartAddress = xConversion->convertRangeToXML( msChartAddress );
3852 }
3853 }
3854 }
3855 catch( uno::Exception & ex )
3856 {
3857 (void)ex; // avoid warning for pro build
3858 OSL_ENSURE( false, OUStringToOString(
3859 OUString( RTL_CONSTASCII_USTRINGPARAM( "Exception caught. Type: " )) +
3860 OUString::createFromAscii( typeid( ex ).name()) +
3861 OUString( RTL_CONSTASCII_USTRINGPARAM( ", Message: " )) +
3862 ex.Message, RTL_TEXTENCODING_ASCII_US ).getStr());
3863 }
3864 }
3865
3866 // export components ========================================
3867
3868 // first version: everything goes in one storage
3869
SchXMLExport_getSupportedServiceNames()3870 Sequence< OUString > SAL_CALL SchXMLExport_getSupportedServiceNames() throw()
3871 {
3872 const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Chart.XMLExporter" ) );
3873 const Sequence< OUString > aSeq( &aServiceName, 1 );
3874 return aSeq;
3875 }
3876
SchXMLExport_getImplementationName()3877 OUString SAL_CALL SchXMLExport_getImplementationName() throw()
3878 {
3879 return OUString( RTL_CONSTASCII_USTRINGPARAM( "SchXMLExport.Compact" ) );
3880 }
3881
SchXMLExport_createInstance(const Reference<lang::XMultiServiceFactory> & rSMgr)3882 Reference< uno::XInterface > SAL_CALL SchXMLExport_createInstance(const Reference< lang::XMultiServiceFactory > & rSMgr)
3883 {
3884 // #110680#
3885 // #103997# removed some flags from EXPORT_ALL
3886 // return (cppu::OWeakObject*)new SchXMLExport( EXPORT_ALL ^ ( EXPORT_SETTINGS | EXPORT_MASTERSTYLES | EXPORT_SCRIPTS ));
3887 return (cppu::OWeakObject*)new SchXMLExport( rSMgr, EXPORT_ALL ^ ( EXPORT_SETTINGS | EXPORT_MASTERSTYLES | EXPORT_SCRIPTS ));
3888 }
3889
3890 // Oasis format
SchXMLExport_Oasis_getSupportedServiceNames()3891 Sequence< OUString > SAL_CALL SchXMLExport_Oasis_getSupportedServiceNames() throw()
3892 {
3893 const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Chart.XMLOasisExporter" ) );
3894 const Sequence< OUString > aSeq( &aServiceName, 1 );
3895 return aSeq;
3896 }
3897
SchXMLExport_Oasis_getImplementationName()3898 OUString SAL_CALL SchXMLExport_Oasis_getImplementationName() throw()
3899 {
3900 return OUString( RTL_CONSTASCII_USTRINGPARAM( "SchXMLExport.Oasis.Compact" ) );
3901 }
3902
SchXMLExport_Oasis_createInstance(const Reference<lang::XMultiServiceFactory> & rSMgr)3903 Reference< uno::XInterface > SAL_CALL SchXMLExport_Oasis_createInstance(const Reference< lang::XMultiServiceFactory > & rSMgr)
3904 {
3905 // #103997# removed some flags from EXPORT_ALL
3906 return (cppu::OWeakObject*)new SchXMLExport( rSMgr,
3907 (EXPORT_ALL ^ ( EXPORT_SETTINGS | EXPORT_MASTERSTYLES | EXPORT_SCRIPTS )) | EXPORT_OASIS );
3908 }
3909
3910 // ============================================================
3911
3912 // multiple storage version: one for content / styles / meta
3913
SchXMLExport_Styles_getSupportedServiceNames()3914 Sequence< OUString > SAL_CALL SchXMLExport_Styles_getSupportedServiceNames() throw()
3915 {
3916 const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Chart.XMLStylesExporter" ));
3917 const Sequence< OUString > aSeq( &aServiceName, 1 );
3918 return aSeq;
3919 }
3920
SchXMLExport_Styles_getImplementationName()3921 OUString SAL_CALL SchXMLExport_Styles_getImplementationName() throw()
3922 {
3923 return OUString( RTL_CONSTASCII_USTRINGPARAM( "SchXMLExport.Styles" ));
3924 }
3925
SchXMLExport_Styles_createInstance(const Reference<lang::XMultiServiceFactory> & rSMgr)3926 Reference< uno::XInterface > SAL_CALL SchXMLExport_Styles_createInstance(const Reference< lang::XMultiServiceFactory >& rSMgr)
3927 {
3928 // #110680#
3929 // return (cppu::OWeakObject*)new SchXMLExport( EXPORT_STYLES );
3930 return (cppu::OWeakObject*)new SchXMLExport( rSMgr, EXPORT_STYLES );
3931 }
3932
3933 // Oasis format
SchXMLExport_Oasis_Styles_getSupportedServiceNames()3934 Sequence< OUString > SAL_CALL SchXMLExport_Oasis_Styles_getSupportedServiceNames() throw()
3935 {
3936 const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Chart.XMLOasisStylesExporter" ));
3937 const Sequence< OUString > aSeq( &aServiceName, 1 );
3938 return aSeq;
3939 }
3940
SchXMLExport_Oasis_Styles_getImplementationName()3941 OUString SAL_CALL SchXMLExport_Oasis_Styles_getImplementationName() throw()
3942 {
3943 return OUString( RTL_CONSTASCII_USTRINGPARAM( "SchXMLExport.Oasis.Styles" ));
3944 }
3945
SchXMLExport_Oasis_Styles_createInstance(const Reference<lang::XMultiServiceFactory> & rSMgr)3946 Reference< uno::XInterface > SAL_CALL SchXMLExport_Oasis_Styles_createInstance(const Reference< lang::XMultiServiceFactory > & rSMgr)
3947 {
3948 return (cppu::OWeakObject*)new SchXMLExport( rSMgr, EXPORT_STYLES | EXPORT_OASIS );
3949 }
3950
3951 // ------------------------------------------------------------
3952
SchXMLExport_Content_getSupportedServiceNames()3953 Sequence< OUString > SAL_CALL SchXMLExport_Content_getSupportedServiceNames() throw()
3954 {
3955 const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Chart.XMLContentExporter" ));
3956 const Sequence< OUString > aSeq( &aServiceName, 1 );
3957 return aSeq;
3958 }
3959
SchXMLExport_Content_getImplementationName()3960 OUString SAL_CALL SchXMLExport_Content_getImplementationName() throw()
3961 {
3962 return OUString( RTL_CONSTASCII_USTRINGPARAM( "SchXMLExport.Content" ));
3963 }
3964
SchXMLExport_Content_createInstance(const Reference<lang::XMultiServiceFactory> & rSMgr)3965 Reference< uno::XInterface > SAL_CALL SchXMLExport_Content_createInstance(const Reference< lang::XMultiServiceFactory > & rSMgr)
3966 {
3967 // #110680#
3968 // return (cppu::OWeakObject*)new SchXMLExport( EXPORT_AUTOSTYLES | EXPORT_CONTENT | EXPORT_FONTDECLS );
3969 return (cppu::OWeakObject*)new SchXMLExport( rSMgr, EXPORT_AUTOSTYLES | EXPORT_CONTENT | EXPORT_FONTDECLS );
3970 }
3971
3972 // Oasis format
SchXMLExport_Oasis_Content_getSupportedServiceNames()3973 Sequence< OUString > SAL_CALL SchXMLExport_Oasis_Content_getSupportedServiceNames() throw()
3974 {
3975 const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Chart.XMLOasisContentExporter" ));
3976 const Sequence< OUString > aSeq( &aServiceName, 1 );
3977 return aSeq;
3978 }
3979
SchXMLExport_Oasis_Content_getImplementationName()3980 OUString SAL_CALL SchXMLExport_Oasis_Content_getImplementationName() throw()
3981 {
3982 return OUString( RTL_CONSTASCII_USTRINGPARAM( "SchXMLExport.Oasis.Content" ));
3983 }
3984
SchXMLExport_Oasis_Content_createInstance(const Reference<lang::XMultiServiceFactory> & rSMgr)3985 Reference< uno::XInterface > SAL_CALL SchXMLExport_Oasis_Content_createInstance(const Reference< lang::XMultiServiceFactory > & rSMgr)
3986 {
3987 return (cppu::OWeakObject*)new SchXMLExport( rSMgr, EXPORT_AUTOSTYLES | EXPORT_CONTENT | EXPORT_FONTDECLS | EXPORT_OASIS );
3988 }
3989
3990 // ------------------------------------------------------------
3991
3992 // Sequence< OUString > SAL_CALL SchXMLExport_Meta_getSupportedServiceNames() throw()
3993 // {
3994 // const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Chart.XMLMetaExporter" ));
3995 // const Sequence< OUString > aSeq( &aServiceName, 1 );
3996 // return aSeq;
3997 // }
3998
3999 // OUString SAL_CALL SchXMLExport_Meta_getImplementationName() throw()
4000 // {
4001 // return OUString( RTL_CONSTASCII_USTRINGPARAM( "SchXMLExport.Meta" ));
4002 // }
4003
4004 // Reference< uno::XInterface > SAL_CALL SchXMLExport_Meta_createInstance(const Reference< lang::XMultiServiceFactory > & rSMgr) throw( uno::Exception )
4005 // {
4006 // return (cppu::OWeakObject*)new SchXMLExport( EXPORT_META );
4007 // }
4008
4009 // Oasis format
SchXMLExport_Oasis_Meta_getSupportedServiceNames()4010 Sequence< OUString > SAL_CALL SchXMLExport_Oasis_Meta_getSupportedServiceNames() throw()
4011 {
4012 const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Chart.XMLOasisMetaExporter" ));
4013 const Sequence< OUString > aSeq( &aServiceName, 1 );
4014 return aSeq;
4015 }
4016
SchXMLExport_Oasis_Meta_getImplementationName()4017 OUString SAL_CALL SchXMLExport_Oasis_Meta_getImplementationName() throw()
4018 {
4019 return OUString( RTL_CONSTASCII_USTRINGPARAM( "SchXMLExport.Oasis.Meta" ));
4020 }
4021
SchXMLExport_Oasis_Meta_createInstance(const Reference<lang::XMultiServiceFactory> & rSMgr)4022 Reference< uno::XInterface > SAL_CALL SchXMLExport_Oasis_Meta_createInstance(const Reference< lang::XMultiServiceFactory > & rSMgr)
4023 {
4024 return (cppu::OWeakObject*)new SchXMLExport( rSMgr, EXPORT_META | EXPORT_OASIS );
4025 }
4026
4027
4028 // XServiceInfo
getImplementationName()4029 OUString SAL_CALL SchXMLExport::getImplementationName()
4030 {
4031 switch( getExportFlags())
4032 {
4033 case EXPORT_ALL:
4034 return SchXMLExport_getImplementationName();
4035 case EXPORT_STYLES:
4036 return SchXMLExport_Styles_getImplementationName();
4037 case ( EXPORT_AUTOSTYLES | EXPORT_CONTENT | EXPORT_FONTDECLS ):
4038 return SchXMLExport_Content_getImplementationName();
4039 // case EXPORT_META:
4040 // return SchXMLExport_Meta_getImplementationName();
4041
4042 // Oasis format
4043 case ( EXPORT_ALL | EXPORT_OASIS ):
4044 return SchXMLExport_Oasis_getImplementationName();
4045 case ( EXPORT_STYLES | EXPORT_OASIS ):
4046 return SchXMLExport_Oasis_Styles_getImplementationName();
4047 case ( EXPORT_AUTOSTYLES | EXPORT_CONTENT | EXPORT_FONTDECLS | EXPORT_OASIS ):
4048 return SchXMLExport_Oasis_Content_getImplementationName();
4049 case ( EXPORT_META | EXPORT_OASIS ):
4050 return SchXMLExport_Oasis_Meta_getImplementationName();
4051
4052 case EXPORT_SETTINGS:
4053 // there is no settings component in chart
4054 default:
4055 return OUString::createFromAscii( "SchXMLExport" );
4056 }
4057 }
4058