1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*63bba73cSAndrew Rist * distributed with this work for additional information
6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at
10*63bba73cSAndrew Rist *
11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist *
13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the
17*63bba73cSAndrew Rist * specific language governing permissions and limitations
18*63bba73cSAndrew Rist * under the License.
19*63bba73cSAndrew Rist *
20*63bba73cSAndrew Rist *************************************************************/
21*63bba73cSAndrew Rist
22*63bba73cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "SchXMLChartContext.hxx"
28cdf0e10cSrcweir #include "SchXMLImport.hxx"
29cdf0e10cSrcweir #include "SchXMLLegendContext.hxx"
30cdf0e10cSrcweir #include "SchXMLPlotAreaContext.hxx"
31cdf0e10cSrcweir #include "SchXMLParagraphContext.hxx"
32cdf0e10cSrcweir #include "SchXMLTableContext.hxx"
33cdf0e10cSrcweir #include "SchXMLSeriesHelper.hxx"
34cdf0e10cSrcweir #include "SchXMLSeries2Context.hxx"
35cdf0e10cSrcweir #include "SchXMLTools.hxx"
36cdf0e10cSrcweir #include <comphelper/mediadescriptor.hxx>
37cdf0e10cSrcweir #include <tools/debug.hxx>
38cdf0e10cSrcweir // header for class ByteString
39cdf0e10cSrcweir #include <tools/string.hxx>
40cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
41cdf0e10cSrcweir #include <xmloff/xmlement.hxx>
42cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
43cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
44cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
45cdf0e10cSrcweir #include <xmloff/xmlstyle.hxx>
46cdf0e10cSrcweir #include <xmloff/prstylei.hxx>
47cdf0e10cSrcweir
48cdf0e10cSrcweir #include "vector"
49cdf0e10cSrcweir #include <com/sun/star/chart/XChartDocument.hpp>
50cdf0e10cSrcweir #include <com/sun/star/chart/XDiagram.hpp>
51cdf0e10cSrcweir #include <com/sun/star/xml/sax/XAttributeList.hpp>
52cdf0e10cSrcweir #include <com/sun/star/util/XStringMapping.hpp>
53cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
54cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPage.hpp>
55cdf0e10cSrcweir #include <com/sun/star/chart/ChartDataRowSource.hpp>
56cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
57cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp>
58cdf0e10cSrcweir #include <com/sun/star/embed/XVisualObject.hpp>
59cdf0e10cSrcweir
60cdf0e10cSrcweir #include <com/sun/star/chart2/XChartDocument.hpp>
61cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataSink.hpp>
62cdf0e10cSrcweir #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
63cdf0e10cSrcweir #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
64cdf0e10cSrcweir #include <com/sun/star/chart2/XChartTypeContainer.hpp>
65cdf0e10cSrcweir #include <com/sun/star/chart2/XTitled.hpp>
66cdf0e10cSrcweir
67cdf0e10cSrcweir using namespace com::sun::star;
68cdf0e10cSrcweir using namespace ::xmloff::token;
69cdf0e10cSrcweir using ::rtl::OUString;
70cdf0e10cSrcweir using com::sun::star::uno::Reference;
71cdf0e10cSrcweir using namespace ::SchXMLTools;
72cdf0e10cSrcweir
73cdf0e10cSrcweir namespace
74cdf0e10cSrcweir {
75cdf0e10cSrcweir
lcl_setRoleAtLabeledSequence(const uno::Reference<chart2::data::XLabeledDataSequence> & xLSeq,const::rtl::OUString & rRole)76cdf0e10cSrcweir void lcl_setRoleAtLabeledSequence(
77cdf0e10cSrcweir const uno::Reference< chart2::data::XLabeledDataSequence > & xLSeq,
78cdf0e10cSrcweir const ::rtl::OUString &rRole )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir // set role of sequence
81cdf0e10cSrcweir uno::Reference< chart2::data::XDataSequence > xValues( xLSeq->getValues());
82cdf0e10cSrcweir if( xValues.is())
83cdf0e10cSrcweir {
84cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProp( xValues, uno::UNO_QUERY );
85cdf0e10cSrcweir if( xProp.is())
86cdf0e10cSrcweir xProp->setPropertyValue(OUString::createFromAscii("Role"), uno::makeAny( rRole ));
87cdf0e10cSrcweir }
88cdf0e10cSrcweir }
89cdf0e10cSrcweir
lcl_MoveDataToCandleStickSeries(const uno::Reference<chart2::data::XDataSource> & xDataSource,const uno::Reference<chart2::XDataSeries> & xDestination,const OUString & rRole)90cdf0e10cSrcweir void lcl_MoveDataToCandleStickSeries(
91cdf0e10cSrcweir const uno::Reference< chart2::data::XDataSource > & xDataSource,
92cdf0e10cSrcweir const uno::Reference< chart2::XDataSeries > & xDestination,
93cdf0e10cSrcweir const OUString & rRole )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir try
96cdf0e10cSrcweir {
97cdf0e10cSrcweir uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aLabeledSeq(
98cdf0e10cSrcweir xDataSource->getDataSequences());
99cdf0e10cSrcweir if( aLabeledSeq.getLength())
100cdf0e10cSrcweir {
101cdf0e10cSrcweir lcl_setRoleAtLabeledSequence( aLabeledSeq[0], rRole );
102cdf0e10cSrcweir
103cdf0e10cSrcweir // add to data series
104cdf0e10cSrcweir uno::Reference< chart2::data::XDataSource > xSource( xDestination, uno::UNO_QUERY_THROW );
105cdf0e10cSrcweir // @todo: realloc only once outside this function
106cdf0e10cSrcweir uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aData( xSource->getDataSequences());
107cdf0e10cSrcweir aData.realloc( aData.getLength() + 1);
108cdf0e10cSrcweir aData[ aData.getLength() - 1 ] = aLabeledSeq[0];
109cdf0e10cSrcweir uno::Reference< chart2::data::XDataSink > xSink( xDestination, uno::UNO_QUERY_THROW );
110cdf0e10cSrcweir xSink->setData( aData );
111cdf0e10cSrcweir }
112cdf0e10cSrcweir }
113cdf0e10cSrcweir catch( uno::Exception & )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir OSL_ENSURE( false, "Exception caught while moving data to candlestick series" );
116cdf0e10cSrcweir }
117cdf0e10cSrcweir }
118cdf0e10cSrcweir
lcl_setRoleAtFirstSequence(const uno::Reference<chart2::XDataSeries> & xSeries,const::rtl::OUString & rRole)119cdf0e10cSrcweir void lcl_setRoleAtFirstSequence(
120cdf0e10cSrcweir const uno::Reference< chart2::XDataSeries > & xSeries,
121cdf0e10cSrcweir const ::rtl::OUString & rRole )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir uno::Reference< chart2::data::XDataSource > xSource( xSeries, uno::UNO_QUERY );
124cdf0e10cSrcweir if( xSource.is())
125cdf0e10cSrcweir {
126cdf0e10cSrcweir uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aSeq( xSource->getDataSequences());
127cdf0e10cSrcweir if( aSeq.getLength())
128cdf0e10cSrcweir lcl_setRoleAtLabeledSequence( aSeq[0], rRole );
129cdf0e10cSrcweir }
130cdf0e10cSrcweir }
131cdf0e10cSrcweir
lcl_removeEmptyChartTypeGroups(const uno::Reference<chart2::XChartDocument> & xDoc)132cdf0e10cSrcweir void lcl_removeEmptyChartTypeGroups( const uno::Reference< chart2::XChartDocument > & xDoc )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir if( ! xDoc.is())
135cdf0e10cSrcweir return;
136cdf0e10cSrcweir
137cdf0e10cSrcweir uno::Reference< chart2::XDiagram > xDia( xDoc->getFirstDiagram());
138cdf0e10cSrcweir if( ! xDia.is())
139cdf0e10cSrcweir return;
140cdf0e10cSrcweir
141cdf0e10cSrcweir try
142cdf0e10cSrcweir {
143cdf0e10cSrcweir // count all charttype groups to be able to leave at least one
144cdf0e10cSrcweir sal_Int32 nRemainingGroups = 0;
145cdf0e10cSrcweir uno::Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xDia, uno::UNO_QUERY_THROW );
146cdf0e10cSrcweir uno::Sequence< uno::Reference< chart2::XCoordinateSystem > >
147cdf0e10cSrcweir aCooSysSeq( xCooSysCnt->getCoordinateSystems());
148cdf0e10cSrcweir for( sal_Int32 nI = aCooSysSeq.getLength(); nI--; )
149cdf0e10cSrcweir {
150cdf0e10cSrcweir uno::Reference< chart2::XChartTypeContainer > xCTCnt( aCooSysSeq[nI], uno::UNO_QUERY_THROW );
151cdf0e10cSrcweir nRemainingGroups += xCTCnt->getChartTypes().getLength();
152cdf0e10cSrcweir }
153cdf0e10cSrcweir
154cdf0e10cSrcweir // delete all empty groups, but leave at least group (empty or not)
155cdf0e10cSrcweir for( sal_Int32 nI = aCooSysSeq.getLength(); nI-- && (nRemainingGroups > 1); )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir uno::Reference< chart2::XChartTypeContainer > xCTCnt( aCooSysSeq[nI], uno::UNO_QUERY_THROW );
158cdf0e10cSrcweir uno::Sequence< uno::Reference< chart2::XChartType > > aCTSeq( xCTCnt->getChartTypes());
159cdf0e10cSrcweir for( sal_Int32 nJ=aCTSeq.getLength(); nJ-- && (nRemainingGroups > 1); )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir uno::Reference< chart2::XDataSeriesContainer > xDSCnt( aCTSeq[nJ], uno::UNO_QUERY_THROW );
162cdf0e10cSrcweir if( xDSCnt->getDataSeries().getLength() == 0 )
163cdf0e10cSrcweir {
164cdf0e10cSrcweir // note: iterator stays valid as we have a local sequence
165cdf0e10cSrcweir xCTCnt->removeChartType( aCTSeq[nJ] );
166cdf0e10cSrcweir --nRemainingGroups;
167cdf0e10cSrcweir }
168cdf0e10cSrcweir }
169cdf0e10cSrcweir }
170cdf0e10cSrcweir }
171cdf0e10cSrcweir catch( uno::Exception & ex )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir String aStr( ex.Message );
174cdf0e10cSrcweir ByteString aBStr( aStr, RTL_TEXTENCODING_ASCII_US );
175cdf0e10cSrcweir DBG_ERROR1( "Exception caught while removing empty chart types: %s", aBStr.GetBuffer());
176cdf0e10cSrcweir }
177cdf0e10cSrcweir }
178cdf0e10cSrcweir
lcl_getNumberSequenceFromString(const::rtl::OUString & rStr,bool bAddOneToEachOldIndex)179cdf0e10cSrcweir uno::Sequence< sal_Int32 > lcl_getNumberSequenceFromString( const ::rtl::OUString& rStr, bool bAddOneToEachOldIndex )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir const sal_Unicode aSpace( ' ' );
182cdf0e10cSrcweir
183cdf0e10cSrcweir // count number of entries
184cdf0e10cSrcweir ::std::vector< sal_Int32 > aVec;
185cdf0e10cSrcweir sal_Int32 nLastPos = 0;
186cdf0e10cSrcweir sal_Int32 nPos = 0;
187cdf0e10cSrcweir while( nPos != -1 )
188cdf0e10cSrcweir {
189cdf0e10cSrcweir nPos = rStr.indexOf( aSpace, nLastPos );
190cdf0e10cSrcweir if( nPos > nLastPos )
191cdf0e10cSrcweir {
192cdf0e10cSrcweir aVec.push_back( rStr.copy( nLastPos, (nPos - nLastPos) ).toInt32() );
193cdf0e10cSrcweir }
194cdf0e10cSrcweir if( nPos != -1 )
195cdf0e10cSrcweir nLastPos = nPos + 1;
196cdf0e10cSrcweir }
197cdf0e10cSrcweir // last entry
198cdf0e10cSrcweir if( nLastPos != 0 &&
199cdf0e10cSrcweir rStr.getLength() > nLastPos )
200cdf0e10cSrcweir {
201cdf0e10cSrcweir aVec.push_back( rStr.copy( nLastPos, (rStr.getLength() - nLastPos) ).toInt32() );
202cdf0e10cSrcweir }
203cdf0e10cSrcweir
204cdf0e10cSrcweir const sal_Int32 nVecSize = aVec.size();
205cdf0e10cSrcweir uno::Sequence< sal_Int32 > aSeq( nVecSize );
206cdf0e10cSrcweir
207cdf0e10cSrcweir if(!bAddOneToEachOldIndex)
208cdf0e10cSrcweir {
209cdf0e10cSrcweir sal_Int32* pSeqArr = aSeq.getArray();
210cdf0e10cSrcweir for( nPos = 0; nPos < nVecSize; ++nPos )
211cdf0e10cSrcweir {
212cdf0e10cSrcweir pSeqArr[ nPos ] = aVec[ nPos ];
213cdf0e10cSrcweir }
214cdf0e10cSrcweir }
215cdf0e10cSrcweir else if( bAddOneToEachOldIndex )
216cdf0e10cSrcweir {
217cdf0e10cSrcweir aSeq.realloc( nVecSize+1 );
218cdf0e10cSrcweir aSeq[0]=0;
219cdf0e10cSrcweir
220cdf0e10cSrcweir sal_Int32* pSeqArr = aSeq.getArray();
221cdf0e10cSrcweir for( nPos = 0; nPos < nVecSize; ++nPos )
222cdf0e10cSrcweir {
223cdf0e10cSrcweir pSeqArr[ nPos+1 ] = aVec[ nPos ]+1;
224cdf0e10cSrcweir }
225cdf0e10cSrcweir }
226cdf0e10cSrcweir
227cdf0e10cSrcweir return aSeq;
228cdf0e10cSrcweir }
229cdf0e10cSrcweir
230cdf0e10cSrcweir } // anonymous namespace
231cdf0e10cSrcweir
232cdf0e10cSrcweir // ----------------------------------------
233cdf0e10cSrcweir
SchXMLChartContext(SchXMLImportHelper & rImpHelper,SvXMLImport & rImport,const rtl::OUString & rLocalName)234cdf0e10cSrcweir SchXMLChartContext::SchXMLChartContext( SchXMLImportHelper& rImpHelper,
235cdf0e10cSrcweir SvXMLImport& rImport, const rtl::OUString& rLocalName ) :
236cdf0e10cSrcweir SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ),
237cdf0e10cSrcweir mrImportHelper( rImpHelper ),
238cdf0e10cSrcweir m_bHasRangeAtPlotArea( false ),
239cdf0e10cSrcweir m_bHasTableElement( false ),
240cdf0e10cSrcweir mbAllRangeAddressesAvailable( sal_True ),
241cdf0e10cSrcweir mbColHasLabels( sal_False ),
242cdf0e10cSrcweir mbRowHasLabels( sal_False ),
243cdf0e10cSrcweir meDataRowSource( chart::ChartDataRowSource_COLUMNS ),
244cdf0e10cSrcweir mbIsStockChart( false )
245cdf0e10cSrcweir {
246cdf0e10cSrcweir }
247cdf0e10cSrcweir
~SchXMLChartContext()248cdf0e10cSrcweir SchXMLChartContext::~SchXMLChartContext()
249cdf0e10cSrcweir {}
250cdf0e10cSrcweir
StartElement(const uno::Reference<xml::sax::XAttributeList> & xAttrList)251cdf0e10cSrcweir void SchXMLChartContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
252cdf0e10cSrcweir {
253cdf0e10cSrcweir // parse attributes
254cdf0e10cSrcweir sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
255cdf0e10cSrcweir const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetChartAttrTokenMap();
256cdf0e10cSrcweir
257cdf0e10cSrcweir uno::Reference< embed::XVisualObject > xVisualObject( mrImportHelper.GetChartDocument(), uno::UNO_QUERY);
258cdf0e10cSrcweir DBG_ASSERT(xVisualObject.is(),"need xVisualObject for page size");
259cdf0e10cSrcweir if( xVisualObject.is() )
260cdf0e10cSrcweir maChartSize = xVisualObject->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT ); //#i103460# take the size given from the parent frame as default
261cdf0e10cSrcweir
262cdf0e10cSrcweir // this flag is necessarry for pie charts in the core
263cdf0e10cSrcweir sal_Bool bSetSwitchData = sal_False;
264cdf0e10cSrcweir
265cdf0e10cSrcweir ::rtl::OUString sAutoStyleName;
266cdf0e10cSrcweir ::rtl::OUString aOldChartTypeName;
267cdf0e10cSrcweir bool bHasAddin = false;
268cdf0e10cSrcweir
269cdf0e10cSrcweir for( sal_Int16 i = 0; i < nAttrCount; i++ )
270cdf0e10cSrcweir {
271cdf0e10cSrcweir rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
272cdf0e10cSrcweir rtl::OUString aLocalName;
273cdf0e10cSrcweir rtl::OUString aValue = xAttrList->getValueByIndex( i );
274cdf0e10cSrcweir sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
275cdf0e10cSrcweir
276cdf0e10cSrcweir switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
277cdf0e10cSrcweir {
278cdf0e10cSrcweir case XML_TOK_CHART_HREF:
279cdf0e10cSrcweir m_aXLinkHRefAttributeToIndicateDataProvider = aValue;
280cdf0e10cSrcweir break;
281cdf0e10cSrcweir
282cdf0e10cSrcweir case XML_TOK_CHART_CLASS:
283cdf0e10cSrcweir {
284cdf0e10cSrcweir rtl::OUString sClassName;
285cdf0e10cSrcweir sal_uInt16 nClassPrefix =
286cdf0e10cSrcweir GetImport().GetNamespaceMap().GetKeyByAttrName(
287cdf0e10cSrcweir aValue, &sClassName );
288cdf0e10cSrcweir if( XML_NAMESPACE_CHART == nClassPrefix )
289cdf0e10cSrcweir {
290cdf0e10cSrcweir SchXMLChartTypeEnum eChartTypeEnum = SchXMLTools::GetChartTypeEnum( sClassName );
291cdf0e10cSrcweir if( eChartTypeEnum != XML_CHART_CLASS_UNKNOWN )
292cdf0e10cSrcweir {
293cdf0e10cSrcweir aOldChartTypeName = SchXMLTools::GetChartTypeByClassName( sClassName, true /* bUseOldNames */ );
294cdf0e10cSrcweir maChartTypeServiceName = SchXMLTools::GetChartTypeByClassName( sClassName, false /* bUseOldNames */ );
295cdf0e10cSrcweir switch( eChartTypeEnum )
296cdf0e10cSrcweir {
297cdf0e10cSrcweir case XML_CHART_CLASS_CIRCLE:
298cdf0e10cSrcweir bSetSwitchData = sal_True;
299cdf0e10cSrcweir break;
300cdf0e10cSrcweir case XML_CHART_CLASS_STOCK:
301cdf0e10cSrcweir mbIsStockChart = true;
302cdf0e10cSrcweir break;
303cdf0e10cSrcweir default:
304cdf0e10cSrcweir break;
305cdf0e10cSrcweir }
306cdf0e10cSrcweir }
307cdf0e10cSrcweir }
308cdf0e10cSrcweir else if( XML_NAMESPACE_OOO == nClassPrefix )
309cdf0e10cSrcweir {
310cdf0e10cSrcweir // service is taken from add-in-name attribute
311cdf0e10cSrcweir bHasAddin = true;
312cdf0e10cSrcweir
313cdf0e10cSrcweir aOldChartTypeName = sClassName;
314cdf0e10cSrcweir maChartTypeServiceName = sClassName;
315cdf0e10cSrcweir }
316cdf0e10cSrcweir }
317cdf0e10cSrcweir break;
318cdf0e10cSrcweir
319cdf0e10cSrcweir case XML_TOK_CHART_WIDTH:
320cdf0e10cSrcweir GetImport().GetMM100UnitConverter().convertMeasure( maChartSize.Width, aValue );
321cdf0e10cSrcweir break;
322cdf0e10cSrcweir
323cdf0e10cSrcweir case XML_TOK_CHART_HEIGHT:
324cdf0e10cSrcweir GetImport().GetMM100UnitConverter().convertMeasure( maChartSize.Height, aValue );
325cdf0e10cSrcweir break;
326cdf0e10cSrcweir
327cdf0e10cSrcweir case XML_TOK_CHART_STYLE_NAME:
328cdf0e10cSrcweir sAutoStyleName = aValue;
329cdf0e10cSrcweir break;
330cdf0e10cSrcweir
331cdf0e10cSrcweir case XML_TOK_CHART_COL_MAPPING:
332cdf0e10cSrcweir msColTrans = aValue;
333cdf0e10cSrcweir break;
334cdf0e10cSrcweir case XML_TOK_CHART_ROW_MAPPING:
335cdf0e10cSrcweir msRowTrans = aValue;
336cdf0e10cSrcweir break;
337cdf0e10cSrcweir }
338cdf0e10cSrcweir }
339cdf0e10cSrcweir
340cdf0e10cSrcweir if( aOldChartTypeName.getLength()<= 0 )
341cdf0e10cSrcweir {
342cdf0e10cSrcweir DBG_ERROR( "need a charttype to create a diagram" );
343cdf0e10cSrcweir //set a fallback value:
344cdf0e10cSrcweir ::rtl::OUString aChartClass_Bar( GetXMLToken(XML_BAR ) );
345cdf0e10cSrcweir aOldChartTypeName = SchXMLTools::GetChartTypeByClassName( aChartClass_Bar, true /* bUseOldNames */ );
346cdf0e10cSrcweir maChartTypeServiceName = SchXMLTools::GetChartTypeByClassName( aChartClass_Bar, false /* bUseOldNames */ );
347cdf0e10cSrcweir }
348cdf0e10cSrcweir
349cdf0e10cSrcweir // Set the size of the draw page.
350cdf0e10cSrcweir if( xVisualObject.is() )
351cdf0e10cSrcweir xVisualObject->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT, maChartSize );
352cdf0e10cSrcweir
353cdf0e10cSrcweir InitChart( aOldChartTypeName, bSetSwitchData);
354cdf0e10cSrcweir
355cdf0e10cSrcweir if( bHasAddin )
356cdf0e10cSrcweir {
357cdf0e10cSrcweir //correct charttype serveice name when having an addin
358cdf0e10cSrcweir //and don't refresh addin during load
359cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xDocProp( mrImportHelper.GetChartDocument(), uno::UNO_QUERY );
360cdf0e10cSrcweir if( xDocProp.is() )
361cdf0e10cSrcweir {
362cdf0e10cSrcweir try
363cdf0e10cSrcweir {
364cdf0e10cSrcweir xDocProp->getPropertyValue( ::rtl::OUString::createFromAscii("BaseDiagram")) >>= aOldChartTypeName;
365cdf0e10cSrcweir maChartTypeServiceName = SchXMLTools::GetNewChartTypeName( aOldChartTypeName );
366cdf0e10cSrcweir xDocProp->setPropertyValue( rtl::OUString::createFromAscii( "RefreshAddInAllowed" ) , uno::makeAny( sal_False) );
367cdf0e10cSrcweir }
368cdf0e10cSrcweir catch( uno::Exception & )
369cdf0e10cSrcweir {
370cdf0e10cSrcweir DBG_ERROR( "Exception during import SchXMLChartContext::StartElement" );
371cdf0e10cSrcweir }
372cdf0e10cSrcweir }
373cdf0e10cSrcweir }
374cdf0e10cSrcweir
375cdf0e10cSrcweir // set auto-styles for Area
376cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProp( mrImportHelper.GetChartDocument()->getArea(), uno::UNO_QUERY );
377cdf0e10cSrcweir if( xProp.is())
378cdf0e10cSrcweir {
379cdf0e10cSrcweir const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
380cdf0e10cSrcweir if( pStylesCtxt )
381cdf0e10cSrcweir {
382cdf0e10cSrcweir const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
383cdf0e10cSrcweir mrImportHelper.GetChartFamilyID(), sAutoStyleName );
384cdf0e10cSrcweir
385cdf0e10cSrcweir if( pStyle && pStyle->ISA( XMLPropStyleContext ))
386cdf0e10cSrcweir (( XMLPropStyleContext* )pStyle )->FillPropertySet( xProp );
387cdf0e10cSrcweir }
388cdf0e10cSrcweir }
389cdf0e10cSrcweir }
390cdf0e10cSrcweir
391cdf0e10cSrcweir namespace
392cdf0e10cSrcweir {
393cdf0e10cSrcweir
394cdf0e10cSrcweir struct NewDonutSeries
395cdf0e10cSrcweir {
396cdf0e10cSrcweir ::com::sun::star::uno::Reference<
397cdf0e10cSrcweir ::com::sun::star::chart2::XDataSeries > m_xSeries;
398cdf0e10cSrcweir ::rtl::OUString msStyleName;
399cdf0e10cSrcweir sal_Int32 mnAttachedAxis;
400cdf0e10cSrcweir
401cdf0e10cSrcweir ::std::vector< ::rtl::OUString > m_aSeriesStyles;
402cdf0e10cSrcweir ::std::vector< ::rtl::OUString > m_aPointStyles;
403cdf0e10cSrcweir
NewDonutSeries__anon716043d90211::NewDonutSeries404cdf0e10cSrcweir NewDonutSeries( const ::com::sun::star::uno::Reference<
405cdf0e10cSrcweir ::com::sun::star::chart2::XDataSeries >& xSeries, sal_Int32 nPointCount )
406cdf0e10cSrcweir : m_xSeries( xSeries )
407cdf0e10cSrcweir , mnAttachedAxis( 1 )
408cdf0e10cSrcweir {
409cdf0e10cSrcweir m_aPointStyles.resize(nPointCount);
410cdf0e10cSrcweir m_aSeriesStyles.resize(nPointCount);
411cdf0e10cSrcweir }
412cdf0e10cSrcweir
setSeriesStyleNameToPoint__anon716043d90211::NewDonutSeries413cdf0e10cSrcweir void setSeriesStyleNameToPoint( const ::rtl::OUString& rStyleName, sal_Int32 nPointIndex )
414cdf0e10cSrcweir {
415cdf0e10cSrcweir DBG_ASSERT(nPointIndex < static_cast<sal_Int32>(m_aSeriesStyles.size()),"donut point <-> series count mismatch");
416cdf0e10cSrcweir if( nPointIndex < static_cast<sal_Int32>(m_aSeriesStyles.size()) )
417cdf0e10cSrcweir m_aSeriesStyles[nPointIndex]=rStyleName;
418cdf0e10cSrcweir }
419cdf0e10cSrcweir
setPointStyleNameToPoint__anon716043d90211::NewDonutSeries420cdf0e10cSrcweir void setPointStyleNameToPoint( const ::rtl::OUString& rStyleName, sal_Int32 nPointIndex )
421cdf0e10cSrcweir {
422cdf0e10cSrcweir DBG_ASSERT(nPointIndex < static_cast<sal_Int32>(m_aPointStyles.size()),"donut point <-> series count mismatch");
423cdf0e10cSrcweir if( nPointIndex < static_cast<sal_Int32>(m_aPointStyles.size()) )
424cdf0e10cSrcweir m_aPointStyles[nPointIndex]=rStyleName;
425cdf0e10cSrcweir }
426cdf0e10cSrcweir
creatStyleList__anon716043d90211::NewDonutSeries427cdf0e10cSrcweir ::std::list< DataRowPointStyle > creatStyleList()
428cdf0e10cSrcweir {
429cdf0e10cSrcweir ::std::list< DataRowPointStyle > aRet;
430cdf0e10cSrcweir
431cdf0e10cSrcweir DataRowPointStyle aSeriesStyle( DataRowPointStyle::DATA_SERIES
432cdf0e10cSrcweir , m_xSeries, -1, 1, msStyleName, mnAttachedAxis );
433cdf0e10cSrcweir aRet.push_back( aSeriesStyle );
434cdf0e10cSrcweir
435cdf0e10cSrcweir sal_Int32 nPointIndex=0;
436cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::iterator aPointIt( m_aPointStyles.begin() );
437cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::iterator aPointEnd( m_aPointStyles.end() );
438cdf0e10cSrcweir while( aPointIt != aPointEnd )
439cdf0e10cSrcweir {
440cdf0e10cSrcweir DataRowPointStyle aPointStyle( DataRowPointStyle::DATA_POINT
441cdf0e10cSrcweir , m_xSeries, nPointIndex, 1, *aPointIt, mnAttachedAxis );
442cdf0e10cSrcweir if( nPointIndex < static_cast<sal_Int32>(m_aSeriesStyles.size()) )
443cdf0e10cSrcweir {
444cdf0e10cSrcweir aPointStyle.msSeriesStyleNameForDonuts = m_aSeriesStyles[nPointIndex];
445cdf0e10cSrcweir }
446cdf0e10cSrcweir if( aPointStyle.msSeriesStyleNameForDonuts.getLength()
447cdf0e10cSrcweir || aPointStyle.msStyleName.getLength() )
448cdf0e10cSrcweir aRet.push_back( aPointStyle );
449cdf0e10cSrcweir ++aPointIt;
450cdf0e10cSrcweir ++nPointIndex;
451cdf0e10cSrcweir }
452cdf0e10cSrcweir
453cdf0e10cSrcweir return aRet;
454cdf0e10cSrcweir }
455cdf0e10cSrcweir };
456cdf0e10cSrcweir
lcl_swapPointAndSeriesStylesForDonutCharts(::std::list<DataRowPointStyle> & rStyleList,const::std::map<::com::sun::star::uno::Reference<::com::sun::star::chart2::XDataSeries>,sal_Int32> & rSeriesMap)457cdf0e10cSrcweir void lcl_swapPointAndSeriesStylesForDonutCharts( ::std::list< DataRowPointStyle >& rStyleList
458cdf0e10cSrcweir , const ::std::map< ::com::sun::star::uno::Reference<
459cdf0e10cSrcweir ::com::sun::star::chart2::XDataSeries> , sal_Int32 >& rSeriesMap )
460cdf0e10cSrcweir {
461cdf0e10cSrcweir ::std::list< DataRowPointStyle >::iterator aIt(rStyleList.begin());
462cdf0e10cSrcweir ::std::list< DataRowPointStyle >::iterator aEnd(rStyleList.end());
463cdf0e10cSrcweir
464cdf0e10cSrcweir //detect old series count
465cdf0e10cSrcweir //and add old series to aSeriesMap
466cdf0e10cSrcweir ::std::map< ::com::sun::star::uno::Reference<
467cdf0e10cSrcweir ::com::sun::star::chart2::XDataSeries >, sal_Int32 > aSeriesMap(rSeriesMap);
468cdf0e10cSrcweir sal_Int32 nOldSeriesCount = 0;
469cdf0e10cSrcweir {
470cdf0e10cSrcweir sal_Int32 nMaxOldSeriesIndex = 0;
471cdf0e10cSrcweir sal_Int32 nOldSeriesIndex = 0;
472cdf0e10cSrcweir for( aIt = rStyleList.begin(); aIt != aEnd; ++aIt )
473cdf0e10cSrcweir {
474cdf0e10cSrcweir DataRowPointStyle aStyle(*aIt);
475cdf0e10cSrcweir if(aStyle.meType == DataRowPointStyle::DATA_SERIES &&
476cdf0e10cSrcweir aStyle.m_xSeries.is() )
477cdf0e10cSrcweir {
478cdf0e10cSrcweir nMaxOldSeriesIndex = nOldSeriesIndex;
479cdf0e10cSrcweir
480cdf0e10cSrcweir if( aSeriesMap.end() == aSeriesMap.find(aStyle.m_xSeries) )
481cdf0e10cSrcweir aSeriesMap[aStyle.m_xSeries] = nOldSeriesIndex;
482cdf0e10cSrcweir
483cdf0e10cSrcweir nOldSeriesIndex++;
484cdf0e10cSrcweir }
485cdf0e10cSrcweir }
486cdf0e10cSrcweir nOldSeriesCount = nMaxOldSeriesIndex+1;
487cdf0e10cSrcweir }
488cdf0e10cSrcweir /*
489cdf0e10cSrcweir sal_Int32 nOldSeriesCount = 0;
490cdf0e10cSrcweir {
491cdf0e10cSrcweir sal_Int32 nMaxOldSeriesIndex = 0;
492cdf0e10cSrcweir sal_Int32 nOldSeriesIndex = 0;
493cdf0e10cSrcweir for( aIt = rStyleList.begin(); aIt != aEnd; ++aIt )
494cdf0e10cSrcweir {
495cdf0e10cSrcweir DataRowPointStyle aStyle(*aIt);
496cdf0e10cSrcweir if(aStyle.meType == DataRowPointStyle::DATA_SERIES )
497cdf0e10cSrcweir {
498cdf0e10cSrcweir nMaxOldSeriesIndex = nOldSeriesIndex;
499cdf0e10cSrcweir nOldSeriesIndex++;
500cdf0e10cSrcweir }
501cdf0e10cSrcweir }
502cdf0e10cSrcweir nOldSeriesCount = nMaxOldSeriesIndex+1;
503cdf0e10cSrcweir }
504cdf0e10cSrcweir */
505cdf0e10cSrcweir
506cdf0e10cSrcweir
507cdf0e10cSrcweir //initialize new series styles
508cdf0e10cSrcweir ::std::map< Reference< chart2::XDataSeries >, sal_Int32 >::const_iterator aSeriesMapIt( aSeriesMap.begin() );
509cdf0e10cSrcweir ::std::map< Reference< chart2::XDataSeries >, sal_Int32 >::const_iterator aSeriesMapEnd( aSeriesMap.end() );
510cdf0e10cSrcweir
511cdf0e10cSrcweir //sort by index
512cdf0e10cSrcweir ::std::vector< NewDonutSeries > aNewSeriesVector;
513cdf0e10cSrcweir {
514cdf0e10cSrcweir ::std::map< sal_Int32, Reference< chart2::XDataSeries > > aIndexSeriesMap;
515cdf0e10cSrcweir for( ; aSeriesMapIt != aSeriesMapEnd; ++aSeriesMapIt )
516cdf0e10cSrcweir aIndexSeriesMap[aSeriesMapIt->second] = aSeriesMapIt->first;
517cdf0e10cSrcweir
518cdf0e10cSrcweir ::std::map< sal_Int32, Reference< chart2::XDataSeries > >::const_iterator aIndexIt( aIndexSeriesMap.begin() );
519cdf0e10cSrcweir ::std::map< sal_Int32, Reference< chart2::XDataSeries > >::const_iterator aIndexEnd( aIndexSeriesMap.end() );
520cdf0e10cSrcweir
521cdf0e10cSrcweir for( ; aIndexIt != aIndexEnd; ++aIndexIt )
522cdf0e10cSrcweir aNewSeriesVector.push_back( NewDonutSeries(aIndexIt->second,nOldSeriesCount) );
523cdf0e10cSrcweir }
524cdf0e10cSrcweir
525cdf0e10cSrcweir //overwrite attached axis information according to old series styles
526cdf0e10cSrcweir for( aIt = rStyleList.begin(); aIt != aEnd; ++aIt )
527cdf0e10cSrcweir {
528cdf0e10cSrcweir DataRowPointStyle aStyle(*aIt);
529cdf0e10cSrcweir if(aStyle.meType == DataRowPointStyle::DATA_SERIES )
530cdf0e10cSrcweir {
531cdf0e10cSrcweir aSeriesMapIt = aSeriesMap.find( aStyle.m_xSeries );
532cdf0e10cSrcweir if( aSeriesMapIt != aSeriesMapEnd && aSeriesMapIt->second < static_cast<sal_Int32>(aNewSeriesVector.size()) )
533cdf0e10cSrcweir aNewSeriesVector[aSeriesMapIt->second].mnAttachedAxis = aStyle.mnAttachedAxis;
534cdf0e10cSrcweir }
535cdf0e10cSrcweir }
536cdf0e10cSrcweir
537cdf0e10cSrcweir //overwrite new series style names with old series style name information
538cdf0e10cSrcweir for( aIt = rStyleList.begin(); aIt != aEnd; ++aIt )
539cdf0e10cSrcweir {
540cdf0e10cSrcweir DataRowPointStyle aStyle(*aIt);
541cdf0e10cSrcweir if( aStyle.meType == DataRowPointStyle::DATA_SERIES )
542cdf0e10cSrcweir {
543cdf0e10cSrcweir aSeriesMapIt = aSeriesMap.find(aStyle.m_xSeries);
544cdf0e10cSrcweir if( aSeriesMapEnd != aSeriesMapIt )
545cdf0e10cSrcweir {
546cdf0e10cSrcweir sal_Int32 nNewPointIndex = aSeriesMapIt->second;
547cdf0e10cSrcweir
548cdf0e10cSrcweir ::std::vector< NewDonutSeries >::iterator aNewSeriesIt( aNewSeriesVector.begin() );
549cdf0e10cSrcweir ::std::vector< NewDonutSeries >::iterator aNewSeriesEnd( aNewSeriesVector.end() );
550cdf0e10cSrcweir
551cdf0e10cSrcweir for( ;aNewSeriesIt!=aNewSeriesEnd; ++aNewSeriesIt)
552cdf0e10cSrcweir aNewSeriesIt->setSeriesStyleNameToPoint( aStyle.msStyleName, nNewPointIndex );
553cdf0e10cSrcweir }
554cdf0e10cSrcweir }
555cdf0e10cSrcweir }
556cdf0e10cSrcweir
557cdf0e10cSrcweir //overwrite new series style names with point style name information
558cdf0e10cSrcweir for( aIt = rStyleList.begin(); aIt != aEnd; ++aIt )
559cdf0e10cSrcweir {
560cdf0e10cSrcweir DataRowPointStyle aStyle(*aIt);
561cdf0e10cSrcweir if( aStyle.meType == DataRowPointStyle::DATA_POINT )
562cdf0e10cSrcweir {
563cdf0e10cSrcweir aSeriesMapIt = aSeriesMap.find(aStyle.m_xSeries);
564cdf0e10cSrcweir if( aSeriesMapEnd != aSeriesMapIt )
565cdf0e10cSrcweir {
566cdf0e10cSrcweir sal_Int32 nNewPointIndex = aSeriesMapIt->second;
567cdf0e10cSrcweir sal_Int32 nNewSeriesIndex = aStyle.m_nPointIndex;
568cdf0e10cSrcweir sal_Int32 nRepeatCount = aStyle.m_nPointRepeat;
569cdf0e10cSrcweir
570cdf0e10cSrcweir while( nRepeatCount && (nNewSeriesIndex>=0) && (nNewSeriesIndex< static_cast<sal_Int32>(aNewSeriesVector.size()) ) )
571cdf0e10cSrcweir {
572cdf0e10cSrcweir NewDonutSeries& rNewSeries( aNewSeriesVector[nNewSeriesIndex] );
573cdf0e10cSrcweir rNewSeries.setPointStyleNameToPoint( aStyle.msStyleName, nNewPointIndex );
574cdf0e10cSrcweir
575cdf0e10cSrcweir nRepeatCount--;
576cdf0e10cSrcweir nNewSeriesIndex++;
577cdf0e10cSrcweir }
578cdf0e10cSrcweir }
579cdf0e10cSrcweir }
580cdf0e10cSrcweir }
581cdf0e10cSrcweir
582cdf0e10cSrcweir //put information from aNewSeriesVector to output parameter rStyleList
583cdf0e10cSrcweir rStyleList.clear();
584cdf0e10cSrcweir
585cdf0e10cSrcweir ::std::vector< NewDonutSeries >::iterator aNewSeriesIt( aNewSeriesVector.begin() );
586cdf0e10cSrcweir ::std::vector< NewDonutSeries >::iterator aNewSeriesEnd( aNewSeriesVector.end() );
587cdf0e10cSrcweir for( ;aNewSeriesIt!=aNewSeriesEnd; ++aNewSeriesIt)
588cdf0e10cSrcweir {
589cdf0e10cSrcweir ::std::list< DataRowPointStyle > aList( aNewSeriesIt->creatStyleList() );
590cdf0e10cSrcweir rStyleList.insert(rStyleList.end(),aList.begin(),aList.end());
591cdf0e10cSrcweir }
592cdf0e10cSrcweir }
593cdf0e10cSrcweir
lcl_SpecialHandlingForDonutChartNeeded(const::rtl::OUString & rServiceName,const SvXMLImport & rImport)594cdf0e10cSrcweir bool lcl_SpecialHandlingForDonutChartNeeded(
595cdf0e10cSrcweir const ::rtl::OUString & rServiceName,
596cdf0e10cSrcweir const SvXMLImport & rImport )
597cdf0e10cSrcweir {
598cdf0e10cSrcweir bool bResult = false;
599cdf0e10cSrcweir if( rServiceName.equalsAsciiL(
600cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.DonutChartType" )))
601cdf0e10cSrcweir {
602cdf0e10cSrcweir bResult = SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan2_3( rImport.GetModel() );
603cdf0e10cSrcweir }
604cdf0e10cSrcweir return bResult;
605cdf0e10cSrcweir }
606cdf0e10cSrcweir
607cdf0e10cSrcweir } // anonymous namespace
608cdf0e10cSrcweir
609cdf0e10cSrcweir
lcl_ApplyDataFromRectangularRangeToDiagram(const uno::Reference<chart2::XChartDocument> & xNewDoc,const rtl::OUString & rRectangularRange,::com::sun::star::chart::ChartDataRowSource eDataRowSource,bool bRowHasLabels,bool bColHasLabels,bool bSwitchOnLabelsAndCategoriesForOwnData,const rtl::OUString & sColTrans,const rtl::OUString & sRowTrans)610cdf0e10cSrcweir void lcl_ApplyDataFromRectangularRangeToDiagram(
611cdf0e10cSrcweir const uno::Reference< chart2::XChartDocument >& xNewDoc
612cdf0e10cSrcweir , const rtl::OUString& rRectangularRange
613cdf0e10cSrcweir , ::com::sun::star::chart::ChartDataRowSource eDataRowSource
614cdf0e10cSrcweir , bool bRowHasLabels, bool bColHasLabels
615cdf0e10cSrcweir , bool bSwitchOnLabelsAndCategoriesForOwnData
616cdf0e10cSrcweir , const rtl::OUString& sColTrans
617cdf0e10cSrcweir , const rtl::OUString& sRowTrans )
618cdf0e10cSrcweir {
619cdf0e10cSrcweir if( !xNewDoc.is() )
620cdf0e10cSrcweir return;
621cdf0e10cSrcweir
622cdf0e10cSrcweir uno::Reference< chart2::XDiagram > xNewDia( xNewDoc->getFirstDiagram());
623cdf0e10cSrcweir uno::Reference< chart2::data::XDataProvider > xDataProvider( xNewDoc->getDataProvider() );
624cdf0e10cSrcweir if( !xNewDia.is() || !xDataProvider.is() )
625cdf0e10cSrcweir return;
626cdf0e10cSrcweir
627cdf0e10cSrcweir sal_Bool bFirstCellAsLabel =
628cdf0e10cSrcweir (eDataRowSource==chart::ChartDataRowSource_COLUMNS)? bRowHasLabels : bColHasLabels;
629cdf0e10cSrcweir sal_Bool bHasCateories =
630cdf0e10cSrcweir (eDataRowSource==chart::ChartDataRowSource_COLUMNS)? bColHasLabels : bRowHasLabels;
631cdf0e10cSrcweir
632cdf0e10cSrcweir if( bSwitchOnLabelsAndCategoriesForOwnData )
633cdf0e10cSrcweir {
634cdf0e10cSrcweir bFirstCellAsLabel = true;
635cdf0e10cSrcweir bHasCateories = true;
636cdf0e10cSrcweir }
637cdf0e10cSrcweir
638cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aArgs( 3 );
639cdf0e10cSrcweir aArgs[0] = beans::PropertyValue(
640cdf0e10cSrcweir ::rtl::OUString::createFromAscii("CellRangeRepresentation"),
641cdf0e10cSrcweir -1, uno::makeAny( rRectangularRange ),
642cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE );
643cdf0e10cSrcweir aArgs[1] = beans::PropertyValue(
644cdf0e10cSrcweir ::rtl::OUString::createFromAscii("DataRowSource"),
645cdf0e10cSrcweir -1, uno::makeAny( eDataRowSource ),
646cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE );
647cdf0e10cSrcweir aArgs[2] = beans::PropertyValue(
648cdf0e10cSrcweir ::rtl::OUString::createFromAscii("FirstCellAsLabel"),
649cdf0e10cSrcweir -1, uno::makeAny( bFirstCellAsLabel ),
650cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE );
651cdf0e10cSrcweir
652cdf0e10cSrcweir if( sColTrans.getLength() || sRowTrans.getLength() )
653cdf0e10cSrcweir {
654cdf0e10cSrcweir aArgs.realloc( aArgs.getLength() + 1 );
655cdf0e10cSrcweir aArgs[ aArgs.getLength() - 1 ] = beans::PropertyValue(
656cdf0e10cSrcweir ::rtl::OUString::createFromAscii("SequenceMapping"),
657cdf0e10cSrcweir -1, uno::makeAny( sColTrans.getLength()
658cdf0e10cSrcweir ? lcl_getNumberSequenceFromString( sColTrans, bHasCateories && !xNewDoc->hasInternalDataProvider() )
659cdf0e10cSrcweir : lcl_getNumberSequenceFromString( sRowTrans, bHasCateories && !xNewDoc->hasInternalDataProvider() ) ),
660cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE );
661cdf0e10cSrcweir }
662cdf0e10cSrcweir
663cdf0e10cSrcweir //work around wrong writer ranges ( see Issue 58464 )
664cdf0e10cSrcweir {
665cdf0e10cSrcweir rtl::OUString aChartOleObjectName;
666cdf0e10cSrcweir uno::Reference< frame::XModel > xModel(xNewDoc, uno::UNO_QUERY );
667cdf0e10cSrcweir if( xModel.is() )
668cdf0e10cSrcweir {
669cdf0e10cSrcweir comphelper::MediaDescriptor aMediaDescriptor( xModel->getArgs() );
670cdf0e10cSrcweir
671cdf0e10cSrcweir comphelper::MediaDescriptor::const_iterator aIt(
672cdf0e10cSrcweir aMediaDescriptor.find( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HierarchicalDocumentName" ))));
673cdf0e10cSrcweir if( aIt != aMediaDescriptor.end() )
674cdf0e10cSrcweir {
675cdf0e10cSrcweir aChartOleObjectName = (*aIt).second.get< ::rtl::OUString >();
676cdf0e10cSrcweir }
677cdf0e10cSrcweir }
678cdf0e10cSrcweir if( aChartOleObjectName.getLength() )
679cdf0e10cSrcweir {
680cdf0e10cSrcweir aArgs.realloc( aArgs.getLength() + 1 );
681cdf0e10cSrcweir aArgs[ aArgs.getLength() - 1 ] = beans::PropertyValue(
682cdf0e10cSrcweir ::rtl::OUString::createFromAscii("ChartOleObjectName"),
683cdf0e10cSrcweir -1, uno::makeAny( aChartOleObjectName ),
684cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE );
685cdf0e10cSrcweir }
686cdf0e10cSrcweir }
687cdf0e10cSrcweir
688cdf0e10cSrcweir
689cdf0e10cSrcweir uno::Reference< chart2::data::XDataSource > xDataSource(
690cdf0e10cSrcweir xDataProvider->createDataSource( aArgs ));
691cdf0e10cSrcweir
692cdf0e10cSrcweir aArgs.realloc( aArgs.getLength() + 2 );
693cdf0e10cSrcweir aArgs[ aArgs.getLength() - 2 ] = beans::PropertyValue(
694cdf0e10cSrcweir ::rtl::OUString::createFromAscii("HasCategories"),
695cdf0e10cSrcweir -1, uno::makeAny( bHasCateories ),
696cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE );
697cdf0e10cSrcweir aArgs[ aArgs.getLength() - 1 ] = beans::PropertyValue(
698cdf0e10cSrcweir ::rtl::OUString::createFromAscii("UseCategoriesAsX"),
699cdf0e10cSrcweir -1, uno::makeAny( sal_False ),//categories in ODF files are not to be used as x values (independent from what is offered in our ui)
700cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE );
701cdf0e10cSrcweir
702cdf0e10cSrcweir xNewDia->setDiagramData( xDataSource, aArgs );
703cdf0e10cSrcweir }
704cdf0e10cSrcweir
EndElement()705cdf0e10cSrcweir void SchXMLChartContext::EndElement()
706cdf0e10cSrcweir {
707cdf0e10cSrcweir uno::Reference< chart::XChartDocument > xDoc = mrImportHelper.GetChartDocument();
708cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProp( xDoc, uno::UNO_QUERY );
709cdf0e10cSrcweir uno::Reference< chart2::XChartDocument > xNewDoc( xDoc, uno::UNO_QUERY );
710cdf0e10cSrcweir
711cdf0e10cSrcweir if( xProp.is())
712cdf0e10cSrcweir {
713cdf0e10cSrcweir if( maMainTitle.getLength())
714cdf0e10cSrcweir {
715cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xTitleProp( xDoc->getTitle(), uno::UNO_QUERY );
716cdf0e10cSrcweir if( xTitleProp.is())
717cdf0e10cSrcweir {
718cdf0e10cSrcweir try
719cdf0e10cSrcweir {
720cdf0e10cSrcweir uno::Any aAny;
721cdf0e10cSrcweir aAny <<= maMainTitle;
722cdf0e10cSrcweir xTitleProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny );
723cdf0e10cSrcweir }
724cdf0e10cSrcweir catch( beans::UnknownPropertyException )
725cdf0e10cSrcweir {
726cdf0e10cSrcweir DBG_ERROR( "Property String for Title not available" );
727cdf0e10cSrcweir }
728cdf0e10cSrcweir }
729cdf0e10cSrcweir }
730cdf0e10cSrcweir if( maSubTitle.getLength())
731cdf0e10cSrcweir {
732cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xTitleProp( xDoc->getSubTitle(), uno::UNO_QUERY );
733cdf0e10cSrcweir if( xTitleProp.is())
734cdf0e10cSrcweir {
735cdf0e10cSrcweir try
736cdf0e10cSrcweir {
737cdf0e10cSrcweir uno::Any aAny;
738cdf0e10cSrcweir aAny <<= maSubTitle;
739cdf0e10cSrcweir xTitleProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny );
740cdf0e10cSrcweir }
741cdf0e10cSrcweir catch( beans::UnknownPropertyException )
742cdf0e10cSrcweir {
743cdf0e10cSrcweir DBG_ERROR( "Property String for Title not available" );
744cdf0e10cSrcweir }
745cdf0e10cSrcweir }
746cdf0e10cSrcweir }
747cdf0e10cSrcweir }
748cdf0e10cSrcweir
749cdf0e10cSrcweir // cleanup: remove empty chart type groups
750cdf0e10cSrcweir lcl_removeEmptyChartTypeGroups( xNewDoc );
751cdf0e10cSrcweir
752cdf0e10cSrcweir // set stack mode before a potential chart type detection (in case we have a rectangular range)
753cdf0e10cSrcweir uno::Reference< chart::XDiagram > xDiagram( xDoc->getDiagram() );
754cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xDiaProp( xDiagram, uno::UNO_QUERY );
755cdf0e10cSrcweir if( xDiaProp.is())
756cdf0e10cSrcweir {
757cdf0e10cSrcweir if( maSeriesDefaultsAndStyles.maStackedDefault.hasValue())
758cdf0e10cSrcweir xDiaProp->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Stacked")),maSeriesDefaultsAndStyles.maStackedDefault);
759cdf0e10cSrcweir if( maSeriesDefaultsAndStyles.maPercentDefault.hasValue())
760cdf0e10cSrcweir xDiaProp->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Percent")),maSeriesDefaultsAndStyles.maPercentDefault);
761cdf0e10cSrcweir if( maSeriesDefaultsAndStyles.maDeepDefault.hasValue())
762cdf0e10cSrcweir xDiaProp->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Deep")),maSeriesDefaultsAndStyles.maDeepDefault);
763cdf0e10cSrcweir if( maSeriesDefaultsAndStyles.maStackedBarsConnectedDefault.hasValue())
764cdf0e10cSrcweir xDiaProp->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StackedBarsConnected")),maSeriesDefaultsAndStyles.maStackedBarsConnectedDefault);
765cdf0e10cSrcweir }
766cdf0e10cSrcweir
767cdf0e10cSrcweir //the OOo 2.0 implementation and older has a bug with donuts
768cdf0e10cSrcweir bool bSpecialHandlingForDonutChart = lcl_SpecialHandlingForDonutChartNeeded(
769cdf0e10cSrcweir maChartTypeServiceName, GetImport());
770cdf0e10cSrcweir
771cdf0e10cSrcweir // apply data
772cdf0e10cSrcweir if(!xNewDoc.is())
773cdf0e10cSrcweir return;
774cdf0e10cSrcweir
775cdf0e10cSrcweir bool bHasOwnData = false;
776cdf0e10cSrcweir if( m_aXLinkHRefAttributeToIndicateDataProvider.equalsAscii( "." ) ) //data comes from the chart itself
777cdf0e10cSrcweir bHasOwnData = true;
778cdf0e10cSrcweir else if( m_aXLinkHRefAttributeToIndicateDataProvider.equalsAscii( ".." ) ) //data comes from the parent application
779cdf0e10cSrcweir bHasOwnData = false;
780cdf0e10cSrcweir else if( m_aXLinkHRefAttributeToIndicateDataProvider.getLength() ) //not supported so far to get the data by sibling objects -> fall back to chart itself if data are available
781cdf0e10cSrcweir bHasOwnData = m_bHasTableElement;
782cdf0e10cSrcweir else
783cdf0e10cSrcweir bHasOwnData = !m_bHasRangeAtPlotArea;
784cdf0e10cSrcweir
785cdf0e10cSrcweir if( xNewDoc->hasInternalDataProvider())
786cdf0e10cSrcweir {
787cdf0e10cSrcweir if( !m_bHasTableElement && !m_aXLinkHRefAttributeToIndicateDataProvider.equalsAscii( "." ) )
788cdf0e10cSrcweir {
789cdf0e10cSrcweir //#i103147# ODF, workaround broken files with a missing table:cell-range-address at the plot-area
790cdf0e10cSrcweir bool bSwitchSuccessful = SchXMLTools::switchBackToDataProviderFromParent( xNewDoc, maLSequencesPerIndex );
791cdf0e10cSrcweir bHasOwnData = !bSwitchSuccessful;
792cdf0e10cSrcweir }
793cdf0e10cSrcweir else
794cdf0e10cSrcweir bHasOwnData = true;//e.g. in case of copy->paste from calc to impress
795cdf0e10cSrcweir }
796cdf0e10cSrcweir else if( bHasOwnData )
797cdf0e10cSrcweir {
798cdf0e10cSrcweir xNewDoc->createInternalDataProvider( sal_False /* bCloneExistingData */ );
799cdf0e10cSrcweir }
800cdf0e10cSrcweir if( bHasOwnData )
801cdf0e10cSrcweir msChartAddress = ::rtl::OUString::createFromAscii("all");
802cdf0e10cSrcweir
803cdf0e10cSrcweir bool bSwitchRangesFromOuterToInternalIfNecessary = false;
804cdf0e10cSrcweir if( !bHasOwnData && mbAllRangeAddressesAvailable )
805cdf0e10cSrcweir {
806cdf0e10cSrcweir // special handling for stock chart (merge series together)
807cdf0e10cSrcweir if( mbIsStockChart )
808cdf0e10cSrcweir MergeSeriesForStockChart();
809cdf0e10cSrcweir }
810cdf0e10cSrcweir else if( msChartAddress.getLength() )
811cdf0e10cSrcweir {
812cdf0e10cSrcweir //own data or only rectangular range available
813cdf0e10cSrcweir
814cdf0e10cSrcweir if( xNewDoc->hasInternalDataProvider() )
815cdf0e10cSrcweir SchXMLTableHelper::applyTableToInternalDataProvider( maTable, xNewDoc );
816cdf0e10cSrcweir
817cdf0e10cSrcweir bool bOlderThan2_3 = SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan2_3( Reference< frame::XModel >( xNewDoc, uno::UNO_QUERY ));
818cdf0e10cSrcweir bool bOldFileWithOwnDataFromRows = (bOlderThan2_3 && bHasOwnData && (meDataRowSource==chart::ChartDataRowSource_ROWS)); // in this case there are range addresses that are simply wrong.
819cdf0e10cSrcweir
820cdf0e10cSrcweir if( mbAllRangeAddressesAvailable && !bSpecialHandlingForDonutChart && !mbIsStockChart &&
821cdf0e10cSrcweir !bOldFileWithOwnDataFromRows )
822cdf0e10cSrcweir {
823cdf0e10cSrcweir //bHasOwnData is true in this case!
824cdf0e10cSrcweir //e.g. for normal files with own data or also in case of copy paste scenario (e.g. calc to impress)
825cdf0e10cSrcweir bSwitchRangesFromOuterToInternalIfNecessary = true;
826cdf0e10cSrcweir }
827cdf0e10cSrcweir else
828cdf0e10cSrcweir {
829cdf0e10cSrcweir //apply data from rectangular range
830cdf0e10cSrcweir
831cdf0e10cSrcweir // create datasource from data provider with rectangular range parameters and change the diagram setDiagramData
832cdf0e10cSrcweir try
833cdf0e10cSrcweir {
834cdf0e10cSrcweir if( bOlderThan2_3 && xDiaProp.is() )//for older charts the hidden cells were removed by calc on the fly
835cdf0e10cSrcweir xDiaProp->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IncludeHiddenCells")),uno::makeAny(false));
836cdf0e10cSrcweir
837cdf0e10cSrcweir // note: mbRowHasLabels means the first row contains labels, that means we have "column-descriptions",
838cdf0e10cSrcweir // (analogously mbColHasLabels means we have "row-descriptions")
839cdf0e10cSrcweir lcl_ApplyDataFromRectangularRangeToDiagram( xNewDoc, msChartAddress, meDataRowSource, mbRowHasLabels, mbColHasLabels, bHasOwnData, msColTrans, msRowTrans );
840cdf0e10cSrcweir }
841cdf0e10cSrcweir catch( uno::Exception & )
842cdf0e10cSrcweir {
843cdf0e10cSrcweir //try to fallback to internal data
844cdf0e10cSrcweir DBG_ERROR( "Exception during import SchXMLChartContext::lcl_ApplyDataFromRectangularRangeToDiagram try to fallback to internal data" );
845cdf0e10cSrcweir if(!bHasOwnData)
846cdf0e10cSrcweir {
847cdf0e10cSrcweir bHasOwnData = true;
848cdf0e10cSrcweir msChartAddress = ::rtl::OUString::createFromAscii("all");
849cdf0e10cSrcweir if( !xNewDoc->hasInternalDataProvider() )
850cdf0e10cSrcweir {
851cdf0e10cSrcweir xNewDoc->createInternalDataProvider( sal_False /* bCloneExistingData */ );
852cdf0e10cSrcweir SchXMLTableHelper::applyTableToInternalDataProvider( maTable, xNewDoc );
853cdf0e10cSrcweir try
854cdf0e10cSrcweir {
855cdf0e10cSrcweir lcl_ApplyDataFromRectangularRangeToDiagram( xNewDoc, msChartAddress, meDataRowSource, mbRowHasLabels, mbColHasLabels, bHasOwnData, msColTrans, msRowTrans );
856cdf0e10cSrcweir }
857cdf0e10cSrcweir catch( uno::Exception & )
858cdf0e10cSrcweir {
859cdf0e10cSrcweir DBG_ERROR( "Exception during import SchXMLChartContext::lcl_ApplyDataFromRectangularRangeToDiagram fallback to internal data failed also" );
860cdf0e10cSrcweir }
861cdf0e10cSrcweir }
862cdf0e10cSrcweir }
863cdf0e10cSrcweir }
864cdf0e10cSrcweir }
865cdf0e10cSrcweir }
866cdf0e10cSrcweir else
867cdf0e10cSrcweir {
868cdf0e10cSrcweir DBG_ERROR( " Must not get here" );
869cdf0e10cSrcweir }
870cdf0e10cSrcweir
871cdf0e10cSrcweir // now all series and data point properties are available and can be set
872cdf0e10cSrcweir {
873cdf0e10cSrcweir if( bSpecialHandlingForDonutChart )
874cdf0e10cSrcweir {
875cdf0e10cSrcweir uno::Reference< chart2::XDiagram > xNewDiagram( xNewDoc->getFirstDiagram() );
876cdf0e10cSrcweir lcl_swapPointAndSeriesStylesForDonutCharts( maSeriesDefaultsAndStyles.maSeriesStyleList
877cdf0e10cSrcweir , SchXMLSeriesHelper::getDataSeriesIndexMapFromDiagram(xNewDiagram) );
878cdf0e10cSrcweir }
879cdf0e10cSrcweir
880cdf0e10cSrcweir SchXMLSeries2Context::initSeriesPropertySets( maSeriesDefaultsAndStyles, uno::Reference< frame::XModel >(xDoc, uno::UNO_QUERY ) );
881cdf0e10cSrcweir
882cdf0e10cSrcweir //set defaults from diagram to the new series:
883cdf0e10cSrcweir //check whether we need to remove lines from symbol only charts
884cdf0e10cSrcweir bool bSwitchOffLinesForScatter = false;
885cdf0e10cSrcweir {
886cdf0e10cSrcweir bool bLinesOn = true;
887cdf0e10cSrcweir if( (maSeriesDefaultsAndStyles.maLinesOnProperty >>= bLinesOn) && !bLinesOn )
888cdf0e10cSrcweir {
889cdf0e10cSrcweir if( 0 == maChartTypeServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.ScatterChartType" ) ) )
890cdf0e10cSrcweir {
891cdf0e10cSrcweir bSwitchOffLinesForScatter = true;
892cdf0e10cSrcweir SchXMLSeries2Context::switchSeriesLinesOff( maSeriesDefaultsAndStyles.maSeriesStyleList );
893cdf0e10cSrcweir }
894cdf0e10cSrcweir }
895cdf0e10cSrcweir }
896cdf0e10cSrcweir SchXMLSeries2Context::setDefaultsToSeries( maSeriesDefaultsAndStyles );
897cdf0e10cSrcweir
898cdf0e10cSrcweir // set autostyles for series and data points
899cdf0e10cSrcweir const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
900cdf0e10cSrcweir const SvXMLStyleContext* pStyle = NULL;
901cdf0e10cSrcweir ::rtl::OUString sCurrStyleName;
902cdf0e10cSrcweir
903cdf0e10cSrcweir if( pStylesCtxt )
904cdf0e10cSrcweir {
905cdf0e10cSrcweir //iterate over data-series first
906cdf0e10cSrcweir //don't set series styles for donut charts
907cdf0e10cSrcweir if( !bSpecialHandlingForDonutChart )
908cdf0e10cSrcweir {
909cdf0e10cSrcweir SchXMLSeries2Context::setStylesToSeries( maSeriesDefaultsAndStyles
910cdf0e10cSrcweir , pStylesCtxt, pStyle, sCurrStyleName, mrImportHelper, GetImport(), mbIsStockChart, maLSequencesPerIndex );
911cdf0e10cSrcweir // ... then set attributes for statistics (after their existence was set in the series)
912cdf0e10cSrcweir SchXMLSeries2Context::setStylesToStatisticsObjects( maSeriesDefaultsAndStyles
913cdf0e10cSrcweir , pStylesCtxt, pStyle, sCurrStyleName );
914cdf0e10cSrcweir }
915cdf0e10cSrcweir }
916cdf0e10cSrcweir
917cdf0e10cSrcweir //#i98319# call switchRangesFromOuterToInternalIfNecessary before the data point styles are applied, otherwise in copy->paste scenario the data point styles do get lost
918cdf0e10cSrcweir if( bSwitchRangesFromOuterToInternalIfNecessary )
919cdf0e10cSrcweir {
920cdf0e10cSrcweir if( xNewDoc->hasInternalDataProvider() )
921cdf0e10cSrcweir SchXMLTableHelper::switchRangesFromOuterToInternalIfNecessary( maTable, maLSequencesPerIndex, xNewDoc, meDataRowSource );
922cdf0e10cSrcweir }
923cdf0e10cSrcweir
924cdf0e10cSrcweir if( pStylesCtxt )
925cdf0e10cSrcweir {
926cdf0e10cSrcweir // ... then iterate over data-point attributes, so the latter are not overwritten
927cdf0e10cSrcweir SchXMLSeries2Context::setStylesToDataPoints( maSeriesDefaultsAndStyles
928cdf0e10cSrcweir , pStylesCtxt, pStyle, sCurrStyleName, mrImportHelper, GetImport(), mbIsStockChart, bSpecialHandlingForDonutChart, bSwitchOffLinesForScatter );
929cdf0e10cSrcweir }
930cdf0e10cSrcweir }
931cdf0e10cSrcweir
932cdf0e10cSrcweir if( xProp.is())
933cdf0e10cSrcweir xProp->setPropertyValue( rtl::OUString::createFromAscii( "RefreshAddInAllowed" ) , uno::makeAny( sal_True) );
934cdf0e10cSrcweir }
935cdf0e10cSrcweir
MergeSeriesForStockChart()936cdf0e10cSrcweir void SchXMLChartContext::MergeSeriesForStockChart()
937cdf0e10cSrcweir {
938cdf0e10cSrcweir OSL_ASSERT( mbIsStockChart );
939cdf0e10cSrcweir try
940cdf0e10cSrcweir {
941cdf0e10cSrcweir uno::Reference< chart::XChartDocument > xOldDoc( mrImportHelper.GetChartDocument());
942cdf0e10cSrcweir uno::Reference< chart2::XChartDocument > xDoc( xOldDoc, uno::UNO_QUERY_THROW );
943cdf0e10cSrcweir uno::Reference< chart2::XDiagram > xDiagram( xDoc->getFirstDiagram());
944cdf0e10cSrcweir if( ! xDiagram.is())
945cdf0e10cSrcweir return;
946cdf0e10cSrcweir
947cdf0e10cSrcweir bool bHasJapaneseCandlestick = true;
948cdf0e10cSrcweir uno::Reference< chart2::XDataSeriesContainer > xDSContainer;
949cdf0e10cSrcweir uno::Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY_THROW );
950cdf0e10cSrcweir uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems());
951cdf0e10cSrcweir for( sal_Int32 nCooSysIdx=0; nCooSysIdx<aCooSysSeq.getLength(); ++nCooSysIdx )
952cdf0e10cSrcweir {
953cdf0e10cSrcweir uno::Reference< chart2::XChartTypeContainer > xCTCnt( aCooSysSeq[nCooSysIdx], uno::UNO_QUERY_THROW );
954cdf0e10cSrcweir uno::Sequence< uno::Reference< chart2::XChartType > > aChartTypes( xCTCnt->getChartTypes());
955cdf0e10cSrcweir for( sal_Int32 nCTIdx=0; nCTIdx<aChartTypes.getLength(); ++nCTIdx )
956cdf0e10cSrcweir {
957cdf0e10cSrcweir if( aChartTypes[nCTIdx]->getChartType().equalsAsciiL(
958cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("com.sun.star.chart2.CandleStickChartType")))
959cdf0e10cSrcweir {
960cdf0e10cSrcweir xDSContainer.set( aChartTypes[nCTIdx], uno::UNO_QUERY_THROW );
961cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xCTProp( aChartTypes[nCTIdx], uno::UNO_QUERY_THROW );
962cdf0e10cSrcweir xCTProp->getPropertyValue( ::rtl::OUString::createFromAscii("Japanese")) >>= bHasJapaneseCandlestick;
963cdf0e10cSrcweir break;
964cdf0e10cSrcweir }
965cdf0e10cSrcweir }
966cdf0e10cSrcweir }
967cdf0e10cSrcweir
968cdf0e10cSrcweir if( xDSContainer.is())
969cdf0e10cSrcweir {
970cdf0e10cSrcweir // with japanese candlesticks: open, low, high, close
971cdf0e10cSrcweir // otherwise: low, high, close
972cdf0e10cSrcweir uno::Sequence< uno::Reference< chart2::XDataSeries > > aSeriesSeq( xDSContainer->getDataSeries());
973cdf0e10cSrcweir const sal_Int32 nSeriesCount( aSeriesSeq.getLength());
974cdf0e10cSrcweir const sal_Int32 nSeriesPerCandleStick = bHasJapaneseCandlestick ? 4: 3;
975cdf0e10cSrcweir sal_Int32 nCandleStickCount = nSeriesCount / nSeriesPerCandleStick;
976cdf0e10cSrcweir OSL_ASSERT( nSeriesPerCandleStick * nCandleStickCount == nSeriesCount );
977cdf0e10cSrcweir uno::Sequence< uno::Reference< chart2::XDataSeries > > aNewSeries( nCandleStickCount );
978cdf0e10cSrcweir for( sal_Int32 i=0; i<nCandleStickCount; ++i )
979cdf0e10cSrcweir {
980cdf0e10cSrcweir sal_Int32 nSeriesIndex = i*nSeriesPerCandleStick;
981cdf0e10cSrcweir if( bHasJapaneseCandlestick )
982cdf0e10cSrcweir {
983cdf0e10cSrcweir // open values
984cdf0e10cSrcweir lcl_setRoleAtFirstSequence( aSeriesSeq[ nSeriesIndex ], OUString::createFromAscii("values-first"));
985cdf0e10cSrcweir aNewSeries[i] = aSeriesSeq[ nSeriesIndex ];
986cdf0e10cSrcweir // low values
987cdf0e10cSrcweir lcl_MoveDataToCandleStickSeries(
988cdf0e10cSrcweir uno::Reference< chart2::data::XDataSource >( aSeriesSeq[ ++nSeriesIndex ], uno::UNO_QUERY_THROW ),
989cdf0e10cSrcweir aNewSeries[i], OUString::createFromAscii("values-min"));
990cdf0e10cSrcweir }
991cdf0e10cSrcweir else
992cdf0e10cSrcweir {
993cdf0e10cSrcweir // low values
994cdf0e10cSrcweir lcl_setRoleAtFirstSequence( aSeriesSeq[ nSeriesIndex ], OUString::createFromAscii("values-min"));
995cdf0e10cSrcweir aNewSeries[i] = aSeriesSeq[ nSeriesIndex ];
996cdf0e10cSrcweir }
997cdf0e10cSrcweir // high values
998cdf0e10cSrcweir lcl_MoveDataToCandleStickSeries(
999cdf0e10cSrcweir uno::Reference< chart2::data::XDataSource >( aSeriesSeq[ ++nSeriesIndex ], uno::UNO_QUERY_THROW ),
1000cdf0e10cSrcweir aNewSeries[i], OUString::createFromAscii("values-max"));
1001cdf0e10cSrcweir // close values
1002cdf0e10cSrcweir lcl_MoveDataToCandleStickSeries(
1003cdf0e10cSrcweir uno::Reference< chart2::data::XDataSource >( aSeriesSeq[ ++nSeriesIndex ], uno::UNO_QUERY_THROW ),
1004cdf0e10cSrcweir aNewSeries[i], OUString::createFromAscii("values-last"));
1005cdf0e10cSrcweir }
1006cdf0e10cSrcweir xDSContainer->setDataSeries( aNewSeries );
1007cdf0e10cSrcweir }
1008cdf0e10cSrcweir }
1009cdf0e10cSrcweir catch( uno::Exception & )
1010cdf0e10cSrcweir {
1011cdf0e10cSrcweir DBG_ERROR( "Exception while merging series for stock chart" );
1012cdf0e10cSrcweir }
1013cdf0e10cSrcweir }
1014cdf0e10cSrcweir
CreateChildContext(sal_uInt16 nPrefix,const rtl::OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)1015cdf0e10cSrcweir SvXMLImportContext* SchXMLChartContext::CreateChildContext(
1016cdf0e10cSrcweir sal_uInt16 nPrefix,
1017cdf0e10cSrcweir const rtl::OUString& rLocalName,
1018cdf0e10cSrcweir const uno::Reference< xml::sax::XAttributeList >& xAttrList )
1019cdf0e10cSrcweir {
1020cdf0e10cSrcweir static const sal_Bool bTrue = sal_True;
1021cdf0e10cSrcweir static const uno::Any aTrueBool( &bTrue, ::getBooleanCppuType());
1022cdf0e10cSrcweir
1023cdf0e10cSrcweir SvXMLImportContext* pContext = 0;
1024cdf0e10cSrcweir const SvXMLTokenMap& rTokenMap = mrImportHelper.GetChartElemTokenMap();
1025cdf0e10cSrcweir uno::Reference< chart::XChartDocument > xDoc = mrImportHelper.GetChartDocument();
1026cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProp( xDoc, uno::UNO_QUERY );
1027cdf0e10cSrcweir
1028cdf0e10cSrcweir switch( rTokenMap.Get( nPrefix, rLocalName ))
1029cdf0e10cSrcweir {
1030cdf0e10cSrcweir case XML_TOK_CHART_PLOT_AREA:
1031cdf0e10cSrcweir pContext = new SchXMLPlotAreaContext( mrImportHelper, GetImport(), rLocalName,
1032cdf0e10cSrcweir m_aXLinkHRefAttributeToIndicateDataProvider,
1033cdf0e10cSrcweir maSeriesAddresses, msCategoriesAddress,
1034cdf0e10cSrcweir msChartAddress, m_bHasRangeAtPlotArea, mbAllRangeAddressesAvailable,
1035cdf0e10cSrcweir mbColHasLabels, mbRowHasLabels,
1036cdf0e10cSrcweir meDataRowSource,
1037cdf0e10cSrcweir maSeriesDefaultsAndStyles,
1038cdf0e10cSrcweir maChartTypeServiceName,
1039cdf0e10cSrcweir maLSequencesPerIndex, maChartSize );
1040cdf0e10cSrcweir break;
1041cdf0e10cSrcweir
1042cdf0e10cSrcweir case XML_TOK_CHART_TITLE:
1043cdf0e10cSrcweir if( xDoc.is())
1044cdf0e10cSrcweir {
1045cdf0e10cSrcweir if( xProp.is())
1046cdf0e10cSrcweir {
1047cdf0e10cSrcweir xProp->setPropertyValue( rtl::OUString::createFromAscii( "HasMainTitle" ), aTrueBool );
1048cdf0e10cSrcweir }
1049cdf0e10cSrcweir uno::Reference< drawing::XShape > xTitleShape( xDoc->getTitle(), uno::UNO_QUERY );
1050cdf0e10cSrcweir pContext = new SchXMLTitleContext( mrImportHelper, GetImport(),
1051cdf0e10cSrcweir rLocalName, maMainTitle, xTitleShape );
1052cdf0e10cSrcweir }
1053cdf0e10cSrcweir break;
1054cdf0e10cSrcweir
1055cdf0e10cSrcweir case XML_TOK_CHART_SUBTITLE:
1056cdf0e10cSrcweir if( xDoc.is())
1057cdf0e10cSrcweir {
1058cdf0e10cSrcweir if( xProp.is())
1059cdf0e10cSrcweir {
1060cdf0e10cSrcweir xProp->setPropertyValue( rtl::OUString::createFromAscii( "HasSubTitle" ), aTrueBool );
1061cdf0e10cSrcweir }
1062cdf0e10cSrcweir uno::Reference< drawing::XShape > xTitleShape( xDoc->getSubTitle(), uno::UNO_QUERY );
1063cdf0e10cSrcweir pContext = new SchXMLTitleContext( mrImportHelper, GetImport(),
1064cdf0e10cSrcweir rLocalName, maSubTitle, xTitleShape );
1065cdf0e10cSrcweir }
1066cdf0e10cSrcweir break;
1067cdf0e10cSrcweir
1068cdf0e10cSrcweir case XML_TOK_CHART_LEGEND:
1069cdf0e10cSrcweir pContext = new SchXMLLegendContext( mrImportHelper, GetImport(), rLocalName );
1070cdf0e10cSrcweir break;
1071cdf0e10cSrcweir
1072cdf0e10cSrcweir case XML_TOK_CHART_TABLE:
1073cdf0e10cSrcweir {
1074cdf0e10cSrcweir SchXMLTableContext * pTableContext =
1075cdf0e10cSrcweir new SchXMLTableContext( mrImportHelper, GetImport(), rLocalName, maTable );
1076cdf0e10cSrcweir m_bHasTableElement = true;
1077cdf0e10cSrcweir // #i85913# take into account column- and row- mapping for
1078cdf0e10cSrcweir // charts with own data only for those which were not copied
1079cdf0e10cSrcweir // from a place where they got data from the container. Note,
1080cdf0e10cSrcweir // that this requires the plot-area been read before the table
1081cdf0e10cSrcweir // (which is required in the ODF spec)
1082cdf0e10cSrcweir // Note: For stock charts and donut charts with special handling
1083cdf0e10cSrcweir // the mapping must not be applied!
1084cdf0e10cSrcweir if( !msChartAddress.getLength() && !mbIsStockChart &&
1085cdf0e10cSrcweir !lcl_SpecialHandlingForDonutChartNeeded(
1086cdf0e10cSrcweir maChartTypeServiceName, GetImport()))
1087cdf0e10cSrcweir {
1088cdf0e10cSrcweir if( msColTrans.getLength() > 0 )
1089cdf0e10cSrcweir {
1090cdf0e10cSrcweir OSL_ASSERT( msRowTrans.getLength() == 0 );
1091cdf0e10cSrcweir pTableContext->setColumnPermutation( lcl_getNumberSequenceFromString( msColTrans, true ));
1092cdf0e10cSrcweir msColTrans = OUString();
1093cdf0e10cSrcweir }
1094cdf0e10cSrcweir else if( msRowTrans.getLength() > 0 )
1095cdf0e10cSrcweir {
1096cdf0e10cSrcweir pTableContext->setRowPermutation( lcl_getNumberSequenceFromString( msRowTrans, true ));
1097cdf0e10cSrcweir msRowTrans = OUString();
1098cdf0e10cSrcweir }
1099cdf0e10cSrcweir }
1100cdf0e10cSrcweir pContext = pTableContext;
1101cdf0e10cSrcweir }
1102cdf0e10cSrcweir break;
1103cdf0e10cSrcweir
1104cdf0e10cSrcweir default:
1105cdf0e10cSrcweir // try importing as an additional shape
1106cdf0e10cSrcweir if( ! mxDrawPage.is())
1107cdf0e10cSrcweir {
1108cdf0e10cSrcweir uno::Reference< drawing::XDrawPageSupplier > xSupp( xDoc, uno::UNO_QUERY );
1109cdf0e10cSrcweir if( xSupp.is())
1110cdf0e10cSrcweir mxDrawPage = uno::Reference< drawing::XShapes >( xSupp->getDrawPage(), uno::UNO_QUERY );
1111cdf0e10cSrcweir
1112cdf0e10cSrcweir DBG_ASSERT( mxDrawPage.is(), "Invalid Chart Page" );
1113cdf0e10cSrcweir }
1114cdf0e10cSrcweir if( mxDrawPage.is())
1115cdf0e10cSrcweir pContext = GetImport().GetShapeImport()->CreateGroupChildContext(
1116cdf0e10cSrcweir GetImport(), nPrefix, rLocalName, xAttrList, mxDrawPage );
1117cdf0e10cSrcweir break;
1118cdf0e10cSrcweir }
1119cdf0e10cSrcweir
1120cdf0e10cSrcweir if( ! pContext )
1121cdf0e10cSrcweir pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1122cdf0e10cSrcweir
1123cdf0e10cSrcweir return pContext;
1124cdf0e10cSrcweir }
1125cdf0e10cSrcweir
1126cdf0e10cSrcweir
1127cdf0e10cSrcweir /*
1128cdf0e10cSrcweir With a locked controller the following is done here:
1129cdf0e10cSrcweir 1. Hide title, subtitle, and legend.
1130cdf0e10cSrcweir 2. Set the size of the draw page.
1131cdf0e10cSrcweir 3. Set a (logically) empty data set.
1132cdf0e10cSrcweir 4. Set the chart type.
1133cdf0e10cSrcweir */
InitChart(const OUString & rChartTypeServiceName,sal_Bool)1134cdf0e10cSrcweir void SchXMLChartContext::InitChart(
1135cdf0e10cSrcweir const OUString & rChartTypeServiceName, // currently the old service name
1136cdf0e10cSrcweir sal_Bool /* bSetSwitchData */ )
1137cdf0e10cSrcweir {
1138cdf0e10cSrcweir uno::Reference< chart::XChartDocument > xDoc = mrImportHelper.GetChartDocument();
1139cdf0e10cSrcweir DBG_ASSERT( xDoc.is(), "No valid document!" );
1140cdf0e10cSrcweir uno::Reference< frame::XModel > xModel (xDoc, uno::UNO_QUERY );
1141cdf0e10cSrcweir
1142cdf0e10cSrcweir // Remove Title and Diagram ("De-InitNew")
1143cdf0e10cSrcweir uno::Reference< chart2::XChartDocument > xNewDoc( mrImportHelper.GetChartDocument(), uno::UNO_QUERY );
1144cdf0e10cSrcweir if( xNewDoc.is())
1145cdf0e10cSrcweir {
1146cdf0e10cSrcweir xNewDoc->setFirstDiagram( 0 );
1147cdf0e10cSrcweir uno::Reference< chart2::XTitled > xTitled( xNewDoc, uno::UNO_QUERY );
1148cdf0e10cSrcweir if( xTitled.is())
1149cdf0e10cSrcweir xTitled->setTitleObject( 0 );
1150cdf0e10cSrcweir }
1151cdf0e10cSrcweir
1152cdf0e10cSrcweir // Set the chart type via setting the diagram.
1153cdf0e10cSrcweir if( rChartTypeServiceName.getLength() &&
1154cdf0e10cSrcweir xDoc.is())
1155cdf0e10cSrcweir {
1156cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xFact( xDoc, uno::UNO_QUERY );
1157cdf0e10cSrcweir if( xFact.is())
1158cdf0e10cSrcweir {
1159cdf0e10cSrcweir uno::Reference< chart::XDiagram > xDia( xFact->createInstance( rChartTypeServiceName ), uno::UNO_QUERY );
1160cdf0e10cSrcweir if( xDia.is())
1161cdf0e10cSrcweir xDoc->setDiagram( xDia );
1162cdf0e10cSrcweir }
1163cdf0e10cSrcweir }
1164cdf0e10cSrcweir }
1165cdf0e10cSrcweir
1166cdf0e10cSrcweir // ----------------------------------------
1167cdf0e10cSrcweir
SchXMLTitleContext(SchXMLImportHelper & rImpHelper,SvXMLImport & rImport,const rtl::OUString & rLocalName,rtl::OUString & rTitle,uno::Reference<drawing::XShape> & xTitleShape)1168cdf0e10cSrcweir SchXMLTitleContext::SchXMLTitleContext( SchXMLImportHelper& rImpHelper, SvXMLImport& rImport,
1169cdf0e10cSrcweir const rtl::OUString& rLocalName,
1170cdf0e10cSrcweir rtl::OUString& rTitle,
1171cdf0e10cSrcweir uno::Reference< drawing::XShape >& xTitleShape ) :
1172cdf0e10cSrcweir SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ),
1173cdf0e10cSrcweir mrImportHelper( rImpHelper ),
1174cdf0e10cSrcweir mrTitle( rTitle ),
1175cdf0e10cSrcweir mxTitleShape( xTitleShape )
1176cdf0e10cSrcweir {
1177cdf0e10cSrcweir }
1178cdf0e10cSrcweir
~SchXMLTitleContext()1179cdf0e10cSrcweir SchXMLTitleContext::~SchXMLTitleContext()
1180cdf0e10cSrcweir {}
1181cdf0e10cSrcweir
StartElement(const uno::Reference<xml::sax::XAttributeList> & xAttrList)1182cdf0e10cSrcweir void SchXMLTitleContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
1183cdf0e10cSrcweir {
1184cdf0e10cSrcweir sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
1185cdf0e10cSrcweir
1186cdf0e10cSrcweir com::sun::star::awt::Point maPosition;
1187cdf0e10cSrcweir bool bHasXPosition=false;
1188cdf0e10cSrcweir bool bHasYPosition=false;
1189cdf0e10cSrcweir
1190cdf0e10cSrcweir for( sal_Int16 i = 0; i < nAttrCount; i++ )
1191cdf0e10cSrcweir {
1192cdf0e10cSrcweir rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
1193cdf0e10cSrcweir rtl::OUString aLocalName;
1194cdf0e10cSrcweir rtl::OUString aValue = xAttrList->getValueByIndex( i );
1195cdf0e10cSrcweir sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
1196cdf0e10cSrcweir
1197cdf0e10cSrcweir if( nPrefix == XML_NAMESPACE_SVG )
1198cdf0e10cSrcweir {
1199cdf0e10cSrcweir if( IsXMLToken( aLocalName, XML_X ) )
1200cdf0e10cSrcweir {
1201cdf0e10cSrcweir GetImport().GetMM100UnitConverter().convertMeasure( maPosition.X, aValue );
1202cdf0e10cSrcweir bHasXPosition = true;
1203cdf0e10cSrcweir }
1204cdf0e10cSrcweir else if( IsXMLToken( aLocalName, XML_Y ) )
1205cdf0e10cSrcweir {
1206cdf0e10cSrcweir GetImport().GetMM100UnitConverter().convertMeasure( maPosition.Y, aValue );
1207cdf0e10cSrcweir bHasYPosition = true;
1208cdf0e10cSrcweir }
1209cdf0e10cSrcweir }
1210cdf0e10cSrcweir else if( nPrefix == XML_NAMESPACE_CHART )
1211cdf0e10cSrcweir {
1212cdf0e10cSrcweir if( IsXMLToken( aLocalName, XML_STYLE_NAME ) )
1213cdf0e10cSrcweir msAutoStyleName = aValue;
1214cdf0e10cSrcweir }
1215cdf0e10cSrcweir }
1216cdf0e10cSrcweir
1217cdf0e10cSrcweir
1218cdf0e10cSrcweir if( mxTitleShape.is())
1219cdf0e10cSrcweir {
1220cdf0e10cSrcweir if( bHasXPosition && bHasYPosition )
1221cdf0e10cSrcweir mxTitleShape->setPosition( maPosition );
1222cdf0e10cSrcweir
1223cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProp( mxTitleShape, uno::UNO_QUERY );
1224cdf0e10cSrcweir if( xProp.is())
1225cdf0e10cSrcweir {
1226cdf0e10cSrcweir const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
1227cdf0e10cSrcweir if( pStylesCtxt )
1228cdf0e10cSrcweir {
1229cdf0e10cSrcweir const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
1230cdf0e10cSrcweir mrImportHelper.GetChartFamilyID(), msAutoStyleName );
1231cdf0e10cSrcweir
1232cdf0e10cSrcweir if( pStyle && pStyle->ISA( XMLPropStyleContext ))
1233cdf0e10cSrcweir (( XMLPropStyleContext* )pStyle )->FillPropertySet( xProp );
1234cdf0e10cSrcweir }
1235cdf0e10cSrcweir }
1236cdf0e10cSrcweir }
1237cdf0e10cSrcweir }
1238cdf0e10cSrcweir
CreateChildContext(sal_uInt16 nPrefix,const rtl::OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> &)1239cdf0e10cSrcweir SvXMLImportContext* SchXMLTitleContext::CreateChildContext(
1240cdf0e10cSrcweir sal_uInt16 nPrefix,
1241cdf0e10cSrcweir const rtl::OUString& rLocalName,
1242cdf0e10cSrcweir const uno::Reference< xml::sax::XAttributeList >& )
1243cdf0e10cSrcweir {
1244cdf0e10cSrcweir SvXMLImportContext* pContext = 0;
1245cdf0e10cSrcweir
1246cdf0e10cSrcweir if( nPrefix == XML_NAMESPACE_TEXT &&
1247cdf0e10cSrcweir IsXMLToken( rLocalName, XML_P ) )
1248cdf0e10cSrcweir {
1249cdf0e10cSrcweir pContext = new SchXMLParagraphContext( GetImport(), rLocalName, mrTitle );
1250cdf0e10cSrcweir }
1251cdf0e10cSrcweir else
1252cdf0e10cSrcweir pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1253cdf0e10cSrcweir
1254cdf0e10cSrcweir return pContext;
1255cdf0e10cSrcweir }
1256cdf0e10cSrcweir
1257cdf0e10cSrcweir // ----------------------------------------
1258