LibreOffice Module sc (master)  1
vbachart.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 #include "vbachart.hxx"
20 #include <com/sun/star/beans/XPropertySet.hpp>
21 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
22 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
23 #include <com/sun/star/chart/XAxisXSupplier.hpp>
24 #include <com/sun/star/chart/XAxisYSupplier.hpp>
25 #include <com/sun/star/chart/XAxisZSupplier.hpp>
26 #include <com/sun/star/chart/XTwoAxisXSupplier.hpp>
27 #include <com/sun/star/chart/XTwoAxisYSupplier.hpp>
28 #include <com/sun/star/chart/XChartDataArray.hpp>
29 #include <com/sun/star/chart/ChartSymbolType.hpp>
30 #include <com/sun/star/chart/ChartSolidType.hpp>
31 #include <com/sun/star/chart/ChartDataRowSource.hpp>
32 #include <ooo/vba/excel/XlChartType.hpp>
33 #include <ooo/vba/excel/XlRowCol.hpp>
34 #include <ooo/vba/excel/XlAxisType.hpp>
35 #include <ooo/vba/excel/XlAxisGroup.hpp>
36 
37 #include <basic/sberrors.hxx>
38 #include "vbachartobject.hxx"
39 #include "vbarange.hxx"
40 #include "vbacharttitle.hxx"
41 #include "vbaaxes.hxx"
42 #include <document.hxx>
43 
44 using namespace ::com::sun::star;
45 using namespace ::ooo::vba;
46 using namespace ::ooo::vba::excel::XlChartType;
47 using namespace ::ooo::vba::excel::XlRowCol;
48 using namespace ::ooo::vba::excel::XlAxisType;
49 using namespace ::ooo::vba::excel::XlAxisGroup;
50 
51 constexpr OUStringLiteral CHART_NAME(u"Name");
52 // #TODO move this constant to vbaseries.[ch]xx ( when it exists )
53 constexpr OUStringLiteral DEFAULTSERIESPREFIX(u"Series");
54 constexpr OUStringLiteral DATAROWSOURCE(u"DataRowSource");
55 constexpr OUStringLiteral UPDOWN(u"UpDown");
56 constexpr OUStringLiteral VOLUME(u"Volume");
57 constexpr OUStringLiteral LINES(u"Lines");
58 constexpr OUStringLiteral SPLINETYPE(u"SplineType");
59 constexpr OUStringLiteral SYMBOLTYPE(u"SymbolType");
60 constexpr OUStringLiteral DEEP(u"Deep");
61 constexpr OUStringLiteral SOLIDTYPE(u"SolidType");
62 constexpr OUStringLiteral VERTICAL(u"Vertical");
63 constexpr OUStringLiteral PERCENT(u"Percent");
64 constexpr OUStringLiteral STACKED(u"Stacked");
65 constexpr OUStringLiteral DIM3D(u"Dim3D");
66 constexpr OUStringLiteral HASMAINTITLE(u"HasMainTitle");
67 constexpr OUStringLiteral HASLEGEND(u"HasLegend");
68 
69 ScVbaChart::ScVbaChart( const css::uno::Reference< ov::XHelperInterface >& _xParent, const css::uno::Reference< css::uno::XComponentContext >& _xContext, const css::uno::Reference< css::lang::XComponent >& _xChartComponent, const css::uno::Reference< css::table::XTableChart >& _xTableChart ) : ChartImpl_BASE( _xParent, _xContext ), mxTableChart( _xTableChart )
70 {
71  mxChartDocument.set( _xChartComponent, uno::UNO_QUERY_THROW ) ;
72  // #TODO is it possible that the XPropertySet interface is not set
73  // code in setPlotBy seems to indicate that this is possible? but
74  // additionally there is no check in most of the places where it is used
75  // ( and therefore could possibly be NULL )
76  // I'm going to let it throw for the moment ( npower )
77  mxDiagramPropertySet.set( mxChartDocument->getDiagram(), uno::UNO_QUERY_THROW );
78  mxChartPropertySet.set( _xChartComponent, uno::UNO_QUERY_THROW ) ;
79 }
80 
81 OUString SAL_CALL
83 {
84  OUString sName;
85  uno::Reference< beans::XPropertySet > xProps( mxChartDocument, uno::UNO_QUERY_THROW );
86  try
87  {
88  xProps->getPropertyValue( CHART_NAME ) >>= sName;
89  }
90  catch( const uno::Exception & ) // swallow exceptions
91  {
92  }
93  return sName;
94 }
95 
96 uno::Any SAL_CALL
98 {
99  return uno::Any();
100 }
101 
102 ::sal_Int32 SAL_CALL
104 {
105  sal_Int32 nChartType = -1;
106  try
107  {
108  OUString sDiagramType = mxChartDocument->getDiagram()->getDiagramType();
109  if ( sDiagramType == "com.sun.star.chart.AreaDiagram" )
110  {
111  if (is3D())
112  {
113  nChartType = getStackedType(xl3DAreaStacked, xl3DAreaStacked100, xl3DArea);
114  }
115  else
116  {
117  nChartType = getStackedType(xlAreaStacked, xlAreaStacked100, xlArea);
118  }
119  }
120  else if ( sDiagramType == "com.sun.star.chart.PieDiagram" )
121  {
122  if (is3D())
123  nChartType = xl3DPie;
124  else
125  nChartType = xlPie; /*TODO XlChartType xlPieExploded, XlChartType xlPieOfPie */
126  }
127  else if ( sDiagramType == "com.sun.star.chart.BarDiagram" )
128  {
129  sal_Int32 nSolidType = chart::ChartSolidType::RECTANGULAR_SOLID;
130  if (mxDiagramPropertySet->getPropertySetInfo()->hasPropertyByName(SOLIDTYPE))
131  { //in 2D diagrams 'SolidType' may not be set
132  if (is3D())
133  mxDiagramPropertySet->getPropertyValue(SOLIDTYPE) >>= nSolidType;
134  }
135  switch (nSolidType)
136  {
137  case chart::ChartSolidType::CONE:
138  nChartType = getSolidType(xlConeCol, xlConeColStacked, xlConeColStacked100, xlConeColClustered, xlConeBarStacked, xlConeBarStacked100, xlConeBarClustered);
139  break;
140  case chart::ChartSolidType::CYLINDER:
141  nChartType = getSolidType(xlCylinderCol, xlCylinderColStacked, xlCylinderColStacked100, xlCylinderColClustered, xlCylinderBarStacked, xlCylinderBarStacked100, xlCylinderBarClustered);
142  break;
143  case chart::ChartSolidType::PYRAMID:
144  nChartType = getSolidType(xlPyramidCol, xlPyramidColStacked, xlPyramidColStacked100, xlPyramidColClustered, xlPyramidBarStacked, xlPyramidBarStacked100, xlPyramidBarClustered);
145  break;
146  default: // RECTANGULAR_SOLID
147  if (is3D())
148  {
149  nChartType = getSolidType(xl3DColumn, xl3DColumnStacked, xl3DColumnStacked100, xl3DColumnClustered, xl3DBarStacked, xl3DBarStacked100, xl3DBarClustered);
150  }
151  else
152  {
153  nChartType = getSolidType(xlColumnClustered, xlColumnStacked, xlColumnStacked100, xlColumnClustered, xlBarStacked, xlBarStacked100, xlBarClustered);
154  }
155  break;
156  }
157  }
158  else if ( sDiagramType == "com.sun.star.chart.StockDiagram" )
159  {
160  bool bVolume = false;
161  mxDiagramPropertySet->getPropertyValue(VOLUME) >>= bVolume;
162  if (bVolume)
163  {
164  nChartType = getStockUpDownValue(xlStockVOHLC, xlStockVHLC);
165  }
166  else
167  {
168  nChartType = getStockUpDownValue(xlStockOHLC, xlStockHLC);
169  }
170  }
171  else if ( sDiagramType == "com.sun.star.chart.XYDiagram" )
172  {
173  bool bHasLines = false;
174  mxDiagramPropertySet->getPropertyValue(LINES) >>= bHasLines;
175  sal_Int32 nSplineType = 0;
176  mxDiagramPropertySet->getPropertyValue(SPLINETYPE) >>= nSplineType;
177  if (nSplineType == 1)
178  {
179  nChartType = getMarkerType(xlXYScatterSmooth, xlXYScatterSmoothNoMarkers);
180  }
181  else if (bHasLines)
182  {
183  nChartType = getMarkerType(xlXYScatterLines, xlXYScatterLinesNoMarkers);
184  }
185  else
186  {
187  nChartType = xlXYScatter;
188  }
189  }
190  else if ( sDiagramType == "com.sun.star.chart.LineDiagram" )
191  {
192  if (is3D())
193  {
194  nChartType = xl3DLine;
195  }
196  else if (hasMarkers())
197  {
198  nChartType = getStackedType(xlLineMarkersStacked, xlLineMarkersStacked100, xlLineMarkers);
199  }
200  else
201  {
202  nChartType = getStackedType(xlLineStacked, xlLineStacked100, xlLine);
203  }
204  }
205  else if ( sDiagramType == "com.sun.star.chart.DonutDiagram" )
206  {
207  nChartType = xlDoughnut; // TODO DoughnutExploded ??
208  }
209  else if ( sDiagramType == "com.sun.star.chart.NetDiagram" )
210  {
211  nChartType = getMarkerType(xlRadarMarkers, xlRadar);
212  }
213  }
214  catch ( const uno::Exception& )
215  {
216  throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
217  }
218  return nChartType;
219 }
220 
221 void SAL_CALL
222 ScVbaChart::setChartType( ::sal_Int32 _nChartType )
223 {
224  try
225  {
226  switch (_nChartType)
227  {
228  case xlColumnClustered:
229  case xlColumnStacked:
230  case xlColumnStacked100:
231  case xl3DColumnClustered:
232  case xl3DColumnStacked:
233  case xl3DColumnStacked100:
234  case xl3DColumn:
235  case xlBarClustered:
236  case xlBarStacked:
237  case xlBarStacked100:
238  case xl3DBarClustered:
239  case xl3DBarStacked:
240  case xl3DBarStacked100:
241  case xlConeColClustered:
242  case xlConeColStacked:
243  case xlConeColStacked100:
244  case xlConeBarClustered:
245  case xlConeBarStacked:
246  case xlConeBarStacked100:
247  case xlConeCol:
248  case xlPyramidColClustered:
249  case xlPyramidColStacked:
250  case xlPyramidColStacked100:
251  case xlPyramidBarClustered:
252  case xlPyramidBarStacked:
253  case xlPyramidBarStacked100:
254  case xlPyramidCol:
255  case xlCylinderColClustered:
256  case xlCylinderColStacked:
257  case xlCylinderColStacked100:
258  case xlCylinderBarClustered:
259  case xlCylinderBarStacked:
260  case xlCylinderBarStacked100:
261  case xlCylinderCol:
262  case xlSurface: // not possible
263  case xlSurfaceWireframe:
264  case xlSurfaceTopView:
265  case xlSurfaceTopViewWireframe:
266  setDiagram( "com.sun.star.chart.BarDiagram");
267  break;
268  case xlLine:
269  case xl3DLine:
270  case xlLineStacked:
271  case xlLineStacked100:
272  case xlLineMarkers:
273  case xlLineMarkersStacked:
274  case xlLineMarkersStacked100:
275  setDiagram( "com.sun.star.chart.LineDiagram");
276  break;
277  case xl3DArea:
278  case xlArea:
279  case xlAreaStacked:
280  case xlAreaStacked100:
281  case xl3DAreaStacked:
282  case xl3DAreaStacked100:
283  setDiagram( "com.sun.star.chart.AreaDiagram" );
284  break;
285  case xlDoughnut:
286  case xlDoughnutExploded:
287  setDiagram( "com.sun.star.chart.DonutDiagram" );
288  break;
289  case xlStockHLC:
290  case xlStockOHLC:
291  case xlStockVHLC:
292  case xlStockVOHLC:
293  setDiagram( "com.sun.star.chart.StockDiagram");
294  mxDiagramPropertySet->setPropertyValue( UPDOWN, uno::makeAny((_nChartType == xlStockOHLC) || (_nChartType == xlStockVOHLC)));
295  mxDiagramPropertySet->setPropertyValue( VOLUME, uno::makeAny((_nChartType == xlStockVHLC) || (_nChartType == xlStockVOHLC)));
296  break;
297 
298  case xlPieOfPie: // not possible
299  case xlPieExploded: // SegmentOffset on ChartDataPointProperties -> get from XDiagram //How does Excel do this?
300  case xl3DPieExploded:
301  case xl3DPie:
302  case xlPie:
303  case xlBarOfPie: // not possible (Zoom pie)
304  setDiagram( "com.sun.star.chart.PieDiagram");
305  break;
306 
307  case xlRadar:
308  case xlRadarMarkers:
309  case xlRadarFilled:
310  setDiagram( "com.sun.star.chart.NetDiagram");
311  break;
312  case xlXYScatter:
313  case xlBubble: // not possible
314  case xlBubble3DEffect: // not possible
315  case xlXYScatterLines:
316  case xlXYScatterLinesNoMarkers:
317  case xlXYScatterSmooth:
318  case xlXYScatterSmoothNoMarkers:
319  setDiagram( "com.sun.star.chart.XYDiagram");
320  switch(_nChartType)
321  {
322  case xlXYScatter:
323  case xlBubble: // not possible
324  case xlBubble3DEffect: // not possible
325  mxDiagramPropertySet->setPropertyValue(LINES, uno::makeAny( false ));
326  break;
327  case xlXYScatterLines:
328  case xlXYScatterLinesNoMarkers:
329  mxDiagramPropertySet->setPropertyValue(LINES, uno::makeAny( true ));
330  break;
331  case xlXYScatterSmooth:
332  case xlXYScatterSmoothNoMarkers:
333  mxDiagramPropertySet->setPropertyValue(SPLINETYPE, uno::makeAny( sal_Int32(1)));
334  break;
335  default:
336  break;
337  }
338  break;
339  default:
340  throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_CONVERSION), OUString() );
341  }
342 
343  switch (_nChartType)
344  {
345  case xlLineMarkers:
346  case xlLineMarkersStacked:
347  case xlLineMarkersStacked100:
348  case xlRadarMarkers:
349  case xlXYScatterLines:
350  case xlXYScatterSmooth:
351  case xlXYScatter:
352  case xlBubble: // not possible
353  case xlBubble3DEffect: // not possible
354  mxDiagramPropertySet->setPropertyValue(SYMBOLTYPE, uno::makeAny( chart::ChartSymbolType::AUTO));
355  break;
356  default:
357  if (mxDiagramPropertySet->getPropertySetInfo()->hasPropertyByName(SYMBOLTYPE))
358  {
359  mxDiagramPropertySet->setPropertyValue(SYMBOLTYPE, uno::makeAny(chart::ChartSymbolType::NONE));
360  }
361  break;
362  }
363 
364  switch (_nChartType)
365  {
366  case xlConeCol:
367  case xlPyramidCol:
368  case xlCylinderCol:
369  case xl3DColumn:
370  case xlSurface: // not possible
371  case xlSurfaceWireframe:
372  case xlSurfaceTopView:
373  case xlSurfaceTopViewWireframe:
374  mxDiagramPropertySet->setPropertyValue(DEEP,uno::makeAny( true ));
375  break;
376  default:
377  if (mxDiagramPropertySet->getPropertySetInfo()->hasPropertyByName(DEEP))
378  {
379  mxDiagramPropertySet->setPropertyValue(DEEP, uno::makeAny( false));
380  }
381  break;
382  }
383 
384  switch (_nChartType)
385  {
386  case xlConeColClustered:
387  case xlConeColStacked:
388  case xlConeColStacked100:
389  case xlConeBarClustered:
390  case xlConeBarStacked:
391  case xlConeBarStacked100:
392  case xlConeCol:
393  mxDiagramPropertySet->setPropertyValue(SOLIDTYPE, uno::makeAny(chart::ChartSolidType::CONE));
394  break;
395  case xlPyramidColClustered:
396  case xlPyramidColStacked:
397  case xlPyramidColStacked100:
398  case xlPyramidBarClustered:
399  case xlPyramidBarStacked:
400  case xlPyramidBarStacked100:
401  case xlPyramidCol:
402  mxDiagramPropertySet->setPropertyValue(SOLIDTYPE, uno::makeAny(chart::ChartSolidType::PYRAMID));
403  break;
404  case xlCylinderColClustered:
405  case xlCylinderColStacked:
406  case xlCylinderColStacked100:
407  case xlCylinderBarClustered:
408  case xlCylinderBarStacked:
409  case xlCylinderBarStacked100:
410  case xlCylinderCol:
411  mxDiagramPropertySet->setPropertyValue(SOLIDTYPE, uno::makeAny(chart::ChartSolidType::CYLINDER));
412  break;
413  default:
414  if (mxDiagramPropertySet->getPropertySetInfo()->hasPropertyByName(SOLIDTYPE))
415  {
416  mxDiagramPropertySet->setPropertyValue(SOLIDTYPE, uno::makeAny(chart::ChartSolidType::RECTANGULAR_SOLID));
417  }
418  break;
419  }
420 
421  switch ( _nChartType)
422  {
423  case xlConeCol:
424  case xlConeColClustered:
425  case xlConeColStacked:
426  case xlConeColStacked100:
427  case xlPyramidColClustered:
428  case xlPyramidColStacked:
429  case xlPyramidColStacked100:
430  case xlCylinderColClustered:
431  case xlCylinderColStacked:
432  case xlCylinderColStacked100:
433  case xlColumnClustered:
434  case xlColumnStacked:
435  case xlColumnStacked100:
436  case xl3DColumnClustered:
437  case xl3DColumnStacked:
438  case xl3DColumnStacked100:
439  case xlSurface: // not possible
440  case xlSurfaceWireframe:
441  case xlSurfaceTopView:
442  case xlSurfaceTopViewWireframe:
443  mxDiagramPropertySet->setPropertyValue(VERTICAL, uno::makeAny( true));
444  break;
445  default:
446  if (mxDiagramPropertySet->getPropertySetInfo()->hasPropertyByName(VERTICAL))
447  {
448  mxDiagramPropertySet->setPropertyValue(VERTICAL, uno::makeAny(false));
449  }
450  break;
451  }
452 
453  switch (_nChartType)
454  {
455  case xlColumnStacked:
456  case xl3DColumnStacked:
457  case xlBarStacked:
458  case xl3DBarStacked:
459  case xlLineStacked:
460  case xlLineMarkersStacked:
461  case xlAreaStacked:
462  case xl3DAreaStacked:
463  case xlCylinderColStacked:
464  case xlCylinderBarStacked:
465  case xlConeColStacked:
466  case xlConeBarStacked:
467  case xlPyramidColStacked:
468  case xlPyramidBarStacked:
469  mxDiagramPropertySet->setPropertyValue(PERCENT, uno::makeAny( false ));
470  mxDiagramPropertySet->setPropertyValue(STACKED, uno::makeAny( true ));
471  break;
472  case xlPyramidColStacked100:
473  case xlPyramidBarStacked100:
474  case xlConeColStacked100:
475  case xlConeBarStacked100:
476  case xlCylinderBarStacked100:
477  case xlCylinderColStacked100:
478  case xl3DAreaStacked100:
479  case xlLineMarkersStacked100:
480  case xlAreaStacked100:
481  case xlLineStacked100:
482  case xl3DBarStacked100:
483  case xlBarStacked100:
484  case xl3DColumnStacked100:
485  case xlColumnStacked100:
486  mxDiagramPropertySet->setPropertyValue(STACKED, uno::makeAny( true));
487  mxDiagramPropertySet->setPropertyValue(PERCENT, uno::makeAny( true ));
488  break;
489  default:
490  mxDiagramPropertySet->setPropertyValue(PERCENT, uno::makeAny( false));
491  mxDiagramPropertySet->setPropertyValue(STACKED, uno::makeAny( false));
492  break;
493  }
494  switch (_nChartType)
495  {
496  case xl3DArea:
497  case xl3DAreaStacked:
498  case xl3DAreaStacked100:
499  case xl3DBarClustered:
500  case xl3DBarStacked:
501  case xl3DBarStacked100:
502  case xl3DColumn:
503  case xl3DColumnClustered:
504  case xl3DColumnStacked:
505  case xl3DColumnStacked100:
506  case xl3DLine:
507  case xl3DPie:
508  case xl3DPieExploded:
509  case xlConeColClustered:
510  case xlConeColStacked:
511  case xlConeColStacked100:
512  case xlConeBarClustered:
513  case xlConeBarStacked:
514  case xlConeBarStacked100:
515  case xlConeCol:
516  case xlPyramidColClustered:
517  case xlPyramidColStacked:
518  case xlPyramidColStacked100:
519  case xlPyramidBarClustered:
520  case xlPyramidBarStacked:
521  case xlPyramidBarStacked100:
522  case xlPyramidCol:
523  case xlCylinderColClustered:
524  case xlCylinderColStacked:
525  case xlCylinderColStacked100:
526  case xlCylinderBarClustered:
527  case xlCylinderBarStacked:
528  case xlCylinderBarStacked100:
529  case xlCylinderCol:
530  mxDiagramPropertySet->setPropertyValue(DIM3D, uno::makeAny( true));
531  break;
532  default:
533  if (mxDiagramPropertySet->getPropertySetInfo()->hasPropertyByName(DIM3D))
534  {
535  mxDiagramPropertySet->setPropertyValue(DIM3D, uno::makeAny( false));
536  }
537  break;
538  }
539  }
540  catch ( const uno::Exception& )
541  {
542  throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
543  }
544 }
545 
546 void SAL_CALL
548 {
549  // #TODO how are Chart sheets handled ( I know we don't even consider
550  // them in the worksheets/sheets collections ), but...???
551  // note: in vba for excel the parent of a Chart sheet is a workbook,
552  // e.g. 'ThisWorkbook'
553  uno::Reference< XHelperInterface > xParent( getParent() );
554  ScVbaChartObject* pChartObj = static_cast< ScVbaChartObject* >( xParent.get() );
555  if ( !pChartObj )
556  throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), "no ChartObject as parent" );
557 
558  pChartObj->Activate();
559 
560 }
561 
562 void SAL_CALL
563 ScVbaChart::setSourceData( const css::uno::Reference< ::ooo::vba::excel::XRange >& _xCalcRange, const css::uno::Any& _aPlotBy )
564 {
565  try
566  {
567  uno::Sequence< table::CellRangeAddress > aRangeAddresses(1);
568  table::CellRangeAddress aSingleRangeAddress;
569 
570  uno::Reference< sheet::XCellRangeAddressable > xAddressable( _xCalcRange->getCellRange(), uno::UNO_QUERY_THROW );
571  aSingleRangeAddress = xAddressable->getRangeAddress();
572 
573  aRangeAddresses[0] = aSingleRangeAddress;
574 
575  mxTableChart->setRanges(aRangeAddresses);
576 
577  bool bsetRowHeaders = false;
578  bool bsetColumnHeaders = false;
579 
580  ScVbaRange* pRange = static_cast< ScVbaRange* >( _xCalcRange.get() );
581  if ( pRange )
582  {
583  ScDocument& rDoc = pRange->getScDocument();
584  bsetRowHeaders = rDoc.HasRowHeader( static_cast< SCCOL >( aSingleRangeAddress.StartColumn ), static_cast< SCROW >( aSingleRangeAddress.StartRow ), static_cast< SCCOL >( aSingleRangeAddress.EndColumn ), static_cast< SCROW >( aSingleRangeAddress.EndRow ), static_cast< SCTAB >( aSingleRangeAddress.Sheet ) );
585  bsetColumnHeaders = rDoc.HasColHeader( static_cast< SCCOL >( aSingleRangeAddress.StartColumn ), static_cast< SCROW >( aSingleRangeAddress.StartRow ), static_cast< SCCOL >( aSingleRangeAddress.EndColumn ), static_cast< SCROW >( aSingleRangeAddress.EndRow ), static_cast< SCTAB >( aSingleRangeAddress.Sheet ));
586  }
587  mxTableChart->setHasRowHeaders(bsetRowHeaders);
588  mxTableChart->setHasColumnHeaders(bsetColumnHeaders);
589 
590  if ((!bsetColumnHeaders) || (!bsetRowHeaders))
591  {
592  uno::Reference< chart::XChartDataArray > xChartDataArray( mxChartDocument->getData(), uno::UNO_QUERY_THROW );
593  if (!bsetColumnHeaders)
594  {
595  xChartDataArray->setColumnDescriptions( getDefaultSeriesDescriptions(xChartDataArray->getColumnDescriptions().getLength() ));
596  }
597  if (!bsetRowHeaders)
598  {
599  xChartDataArray->setRowDescriptions(getDefaultSeriesDescriptions(xChartDataArray->getRowDescriptions().getLength() ));
600  }
601  }
602 
603  if ( _aPlotBy.hasValue() )
604  {
605  sal_Int32 nVal = 0;
606  _aPlotBy >>= nVal;
607  setPlotBy( nVal );
608  }
609  else
610  {
611  sal_Int32 nRows = aSingleRangeAddress.EndRow - aSingleRangeAddress.StartRow;
612  sal_Int32 nCols = aSingleRangeAddress.EndColumn - aSingleRangeAddress.StartColumn;
613  // AutoDetect emulation
614  if ( nRows > nCols )
615  setPlotBy( xlColumns );
616  else if ( nRows <= nCols )
617  setPlotBy( xlRows );
618  }
619  }
620  catch (const uno::Exception&)
621  {
622  throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
623  }
624 }
625 
626 uno::Sequence< OUString >
628 {
629  uno::Sequence< OUString > sDescriptions ( _nCount );
630  std::generate_n(sDescriptions.begin(), _nCount,
631  [i = 1]() mutable -> OUString { return DEFAULTSERIESPREFIX + OUString::number(i++); });
632  return sDescriptions;
633 }
634 
635 void
637 {
638  setChartType( xlColumnClustered );
639 }
640 
641 void
642 ScVbaChart::setPlotBy( ::sal_Int32 _nPlotBy )
643 {
644  try
645  {
646  if ( !mxDiagramPropertySet.is() )
648  switch (_nPlotBy)
649  {
650  case xlRows:
651  mxDiagramPropertySet->setPropertyValue( DATAROWSOURCE, uno::makeAny( chart::ChartDataRowSource_ROWS ) );
652  break;
653  case xlColumns:
654  mxDiagramPropertySet->setPropertyValue( DATAROWSOURCE, uno::makeAny( chart::ChartDataRowSource_COLUMNS) );
655  break;
656  default:
657  throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
658  }
659  }
660  catch (const uno::Exception&)
661  {
662  throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
663  }
664 }
665 
666 ::sal_Int32 SAL_CALL
668 {
669  try
670  {
671  chart::ChartDataRowSource aChartDataRowSource;
672  mxDiagramPropertySet->getPropertyValue(DATAROWSOURCE) >>= aChartDataRowSource;
673  if (aChartDataRowSource == chart::ChartDataRowSource_COLUMNS)
674  {
675  return xlColumns;
676  }
677  else
678  {
679  return xlRows;
680  }
681  }
682  catch (const uno::Exception&)
683  {
684  throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
685  }
686 }
687 
688 void
689 ScVbaChart::setDiagram( const OUString& _sDiagramType )
690 {
691  try
692  {
693  uno::Reference< lang::XMultiServiceFactory > xMSF( mxChartDocument, uno::UNO_QUERY_THROW );
694  uno::Reference< chart::XDiagram > xDiagram( xMSF->createInstance( _sDiagramType ), uno::UNO_QUERY_THROW );
695  mxChartDocument->setDiagram( xDiagram );
696  mxDiagramPropertySet.set( xDiagram, uno::UNO_QUERY_THROW );
697  }
698  catch ( const uno::Exception& )
699  {
700  throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
701  }
702 }
703 
704 // #TODO find out why we have Location/getLocation? there is afaik no
705 // Location property, just a Location function for the Chart object
706 sal_Int32 SAL_CALL
708 {
709  return getLocation();
710 }
711 
712 sal_Int32 SAL_CALL
714 {
715  return -1;
716 }
717 
718 void SAL_CALL
719 ScVbaChart::setLocation( ::sal_Int32 /*where*/, const css::uno::Any& /*Name*/ )
720 {
721  // Helper api just stubs out the code <shrug>
722  // #TODO come back and make sense out of this
723 // String sheetName = null;
724 //
725 // if ((name != null) && name instanceof String) {
726 // sheetName = (String) name;
727 // }
728 // XSpreadsheetDocument xShDoc = (XSpreadsheetDocument) UnoRuntime.queryInterface( XSpreadsheetDocument.class,getXModel() );
729 // com.sun.star.sheet.XSpreadsheets xSheets = xShDoc.Sheets();
730 //
731 // switch (where) {
732 // case ClLocationType.clLocationAsObject_value: //{
733 //
734 // if (sheetName == null) {
735 // DebugHelper.writeInfo("Can't embed in Chart without knowing SheetName");
736 // return;
737 // }
738 //
739 // try {
740 // Any any = (Any) xSheets.getByName(sheetName);
741 // chartSheet = (XSpreadsheet) any.getObject();
742 //
743 // // chartSheet = (XSpreadsheet) xSheets.getByName( sheetName );
744 // } catch (NoSuchElementException e) {
745 // // TODO Auto-generated catch block
746 // e.printStackTrace();
747 //
748 // return;
749 // } catch (WrappedTargetException e) {
750 // // TODO Auto-generated catch block
751 // e.printStackTrace();
752 //
753 // return;
754 // } catch (java.lang.Exception e) {
755 // e.printStackTrace();
756 // }
757 //
758 // XTableChartsSupplier xTCS = (XTableChartsSupplier) UnoRuntime.queryInterface( XTableChartsSupplier.class, chartSheet);
759 // XTableCharts xTableCharts = xTCS.getCharts();
760 // XIndexAccess xIA = (XIndexAccess) UnoRuntime.queryInterface( XIndexAccess.class, xTableCharts);
761 // int numCharts = xIA.getCount();
762 // chartName = "Chart " + (numCharts + 1);
763 //
764 // //}
765 // break;
766 //
767 // case ClLocationType.clLocationAsNewSheet_value:
768 // case ClLocationType.clLocationAutomatic_value:default: //{
769 // chartName = "Chart 1"; // Since it's a new sheet, it's the first on it...
770 //
771 // XIndexAccess xSheetIA = (XIndexAccess) UnoRuntime.queryInterface( XIndexAccess.class, xSheets);
772 //
773 // short newSheetNum = (short) (xSheetIA.getCount() + 1);
774 //
775 // if (sheetName == null){
776 // sheetName = "ChartSheet " + newSheetNum; // Why not?
777 // }
778 // // DPK TODO : Probably should use Sheets to create this!
779 // xSheets.insertNewByName(sheetName, newSheetNum);
780 //
781 // try {
782 // chartSheet =
783 // (XSpreadsheet) xSheets.getByName(sheetName);
784 // } catch (NoSuchElementException e) {
785 // // TODO Auto-generated catch block
786 // e.printStackTrace();
787 //
788 // return;
789 // } catch (WrappedTargetException e) {
790 // // TODO Auto-generated catch block
791 // e.printStackTrace();
792 //
793 // return;
794 // }
795 //
796 // //}
797 // break;
798 // }
799 //
800 // // Last thing should be a call to createChartForReal(), one of them
801 // // should succeed.
802 // createChartForReal();
803 
804 }
805 
806 sal_Bool SAL_CALL
808 {
809  bool bHasTitle = false;
810  try
811  {
812  mxChartPropertySet->getPropertyValue(HASMAINTITLE) >>= bHasTitle;
813  }
814  catch (const uno::Exception&)
815  {
816  throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
817  }
818  return bHasTitle;
819 }
820 
821 void SAL_CALL
823 {
824  try
825  {
826  mxChartPropertySet->setPropertyValue(HASMAINTITLE, uno::makeAny( bTitle ));
827  }
828  catch (const uno::Exception&)
829  {
830  throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
831  }
832 
833 }
834 
835 sal_Bool SAL_CALL
837 {
838  bool bHasLegend = false;
839  try
840  {
841  mxChartPropertySet->getPropertyValue(HASLEGEND) >>= bHasLegend;
842  }
843  catch (const uno::Exception&)
844  {
845  throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
846  }
847  return bHasLegend;
848 }
849 
850 void SAL_CALL
852 {
853  try
854  {
855  mxChartPropertySet->setPropertyValue(HASLEGEND, uno::makeAny(bLegend));
856  }
857  catch (const uno::Exception&)
858  {
859  throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
860  }
861 }
862 
863 uno::Reference< excel::XChartTitle > SAL_CALL
865 {
866  uno::Reference< drawing::XShape > xTitleShape = mxChartDocument->getTitle();
867  // #TODO check parent
868  return new ScVbaChartTitle(this, mxContext, xTitleShape);
869 }
870 
871 uno::Any SAL_CALL
872 ScVbaChart::Axes( const uno::Any& Type, const uno::Any& AxisGroup )
873 {
874  // mmm chart probably is the parent, #TODO check parent
875  uno::Reference< excel::XAxes > xAxes = new ScVbaAxes( this, mxContext, this );
876  if ( !Type.hasValue() )
877  return uno::makeAny( xAxes );
878  return xAxes->Item( Type, AxisGroup );
879 }
880 bool
882 {
883  // #TODO perhaps provide limited Debughelper functionality
884  bool is3d = false;
885  mxDiagramPropertySet->getPropertyValue(DIM3D) >>= is3d;
886  return is3d;
887 }
888 
889 sal_Int32
890 ScVbaChart::getStackedType( sal_Int32 _nStacked, sal_Int32 _n100PercentStacked, sal_Int32 _nUnStacked )
891 {
892  // #TODO perhaps provide limited Debughelper functionality
893  if (isStacked())
894  {
895  if (is100PercentStacked())
896  return _n100PercentStacked;
897  else
898  return _nStacked;
899  }
900  else
901  return _nUnStacked;
902 }
903 
904 bool
906 {
907  // #TODO perhaps provide limited Debughelper functionality
908  bool bStacked = false;
909  mxDiagramPropertySet->getPropertyValue(STACKED) >>= bStacked;
910  return bStacked;
911 }
912 
913 bool
915 {
916  // #TODO perhaps provide limited Debughelper functionality
917  bool b100Percent = false;
918  mxDiagramPropertySet->getPropertyValue(PERCENT) >>= b100Percent;
919  return b100Percent;
920 }
921 
922 sal_Int32
923 ScVbaChart::getSolidType(sal_Int32 _nDeep, sal_Int32 _nVertiStacked, sal_Int32 _nVerti100PercentStacked, sal_Int32 _nVertiUnStacked, sal_Int32 _nHoriStacked, sal_Int32 _nHori100PercentStacked, sal_Int32 _nHoriUnStacked)
924 {
925  try
926  {
927  bool bIsVertical = true;
928  mxDiagramPropertySet->getPropertyValue(VERTICAL) >>= bIsVertical;
929  bool bIsDeep = false;
930  mxDiagramPropertySet->getPropertyValue(DEEP) >>= bIsDeep;
931 
932  if (bIsDeep)
933  {
934  return _nDeep;
935  }
936  else
937  {
938  if (bIsVertical)
939  {
940  return getStackedType(_nVertiStacked, _nVerti100PercentStacked, _nVertiUnStacked);
941  }
942  else
943  {
944  return getStackedType(_nHoriStacked, _nHori100PercentStacked, _nHoriUnStacked);
945  }
946  }
947  }
948  catch (const uno::Exception&)
949  {
950  throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
951  }
952 }
953 
954 sal_Int32
955 ScVbaChart::getStockUpDownValue(sal_Int32 _nUpDown, sal_Int32 _nNotUpDown)
956 {
957  try
958  {
959  bool bUpDown = false;
960  mxDiagramPropertySet->getPropertyValue(UPDOWN) >>= bUpDown;
961  if (bUpDown)
962  {
963  return _nUpDown;
964  }
965  else
966  {
967  return _nNotUpDown;
968  }
969  }
970  catch (const uno::Exception&)
971  {
972  throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
973  }
974 }
975 
976 bool
978 {
979  bool bHasMarkers = false;
980  try
981  {
982  sal_Int32 nSymbol=0;
983  mxDiagramPropertySet->getPropertyValue(SYMBOLTYPE) >>= nSymbol;
984  bHasMarkers = nSymbol != chart::ChartSymbolType::NONE;
985  }
986  catch (const uno::Exception&)
987  {
988  throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
989  }
990  return bHasMarkers;
991 }
992 
993 sal_Int32
994 ScVbaChart::getMarkerType(sal_Int32 _nWithMarkers, sal_Int32 _nWithoutMarkers)
995 {
996  if (hasMarkers())
997  return _nWithMarkers;
998  return _nWithoutMarkers;
999 }
1000 
1001 void
1003 {
1004  xAxisXSupplier.set( mxDiagramPropertySet, uno::UNO_QUERY_THROW );
1005  xAxisYSupplier.set( mxDiagramPropertySet, uno::UNO_QUERY_THROW );
1006  xAxisZSupplier.set( mxDiagramPropertySet, uno::UNO_QUERY_THROW );
1007  xTwoAxisXSupplier.set( mxDiagramPropertySet, uno::UNO_QUERY_THROW );
1008  xTwoAxisYSupplier.set( mxDiagramPropertySet, uno::UNO_QUERY_THROW );
1009 }
1010 
1011 uno::Reference< beans::XPropertySet >
1012 ScVbaChart::getAxisPropertySet(sal_Int32 _nAxisType, sal_Int32 _nAxisGroup)
1013 {
1015  uno::Reference< beans::XPropertySet > xAxisProps;
1016  switch(_nAxisType)
1017  {
1018  case xlCategory:
1019  if (_nAxisGroup == xlPrimary)
1020  {
1021  xAxisProps = xAxisXSupplier->getXAxis();
1022  }
1023  else if (_nAxisGroup == xlSecondary)
1024  {
1025  xAxisProps = xTwoAxisXSupplier->getSecondaryXAxis();
1026  }
1027  break;
1028  case xlSeriesAxis:
1029  xAxisProps = xAxisZSupplier->getZAxis();
1030  break;
1031  case xlValue:
1032  if (_nAxisGroup == xlPrimary)
1033  xAxisProps = xAxisYSupplier->getYAxis();
1034  else if (_nAxisGroup == xlSecondary)
1035  xAxisProps = xTwoAxisYSupplier->getSecondaryYAxis();
1036  break;
1037  default:
1038  return xAxisProps;
1039  }
1040  return xAxisProps;
1041 }
1042 
1043 OUString
1045 {
1046  return "ScVbaChart";
1047 }
1048 
1049 uno::Sequence< OUString >
1051 {
1052  static uno::Sequence< OUString > const aServiceNames
1053  {
1054  "ooo.vba.excel.Chart"
1055  };
1056  return aServiceNames;
1057 }
1058 
1059 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL setSourceData(const css::uno::Reference< ::ooo::vba::excel::XRange > &range, const css::uno::Any &PlotBy) override
Definition: vbachart.cxx:563
Type
virtual void SAL_CALL setHasLegend(sal_Bool bLegend) override
Definition: vbachart.cxx:851
virtual void SAL_CALL setPlotBy(::sal_Int32 xlRowCol) override
Definition: vbachart.cxx:642
css::uno::Reference< css::chart::XChartDocument > mxChartDocument
Definition: vbachart.hxx:40
SC_DLLPUBLIC bool HasColHeader(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab)
Definition: documen3.cxx:1508
bool hasValue()
css::uno::Reference< css::chart::XTwoAxisYSupplier > xTwoAxisYSupplier
Definition: vbachart.hxx:48
virtual OUString getServiceImplName() override
Definition: vbachart.cxx:1044
css::uno::Reference< css::table::XTableChart > mxTableChart
Definition: vbachart.hxx:41
virtual sal_Bool SAL_CALL getHasTitle() override
Definition: vbachart.cxx:807
constexpr OUStringLiteral SOLIDTYPE(u"SolidType")
css::uno::Reference< css::chart::XAxisZSupplier > xAxisZSupplier
Definition: vbachart.hxx:46
constexpr OUStringLiteral PERCENT(u"Percent")
Sequence< OUString > aServiceNames
virtual ::sal_Int32 SAL_CALL getLocation() override
Definition: vbachart.cxx:713
#define ERRCODE_BASIC_CONVERSION
bool hasMarkers()
Definition: vbachart.cxx:977
constexpr OUStringLiteral VOLUME(u"Volume")
void assignDiagramAttributes()
Definition: vbachart.cxx:1002
constexpr OUStringLiteral DEFAULTSERIESPREFIX(u"Series")
ScVbaChart(const css::uno::Reference< ov::XHelperInterface > &_xParent, const css::uno::Reference< css::uno::XComponentContext > &_xContext, const css::uno::Reference< css::lang::XComponent > &_xChartComponent, const css::uno::Reference< css::table::XTableChart > &_xTableChart)
Definition: vbachart.cxx:69
void setDefaultChartType()
Definition: vbachart.cxx:636
css::uno::Reference< css::beans::XPropertySet > getAxisPropertySet(sal_Int32 _nAxisType, sal_Int32 _nAxisGroup)
Definition: vbachart.cxx:1012
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbachart.cxx:1050
sal_Int32 getSolidType(sal_Int32 _nDeep, sal_Int32 _nVertiStacked, sal_Int32 _nVerti100PercentStacked, sal_Int32 _nVertiUnStacked, sal_Int32 _nHoriStacked, sal_Int32 _nHori100PercentStacked, sal_Int32 _nHoriUnStacked)
Definition: vbachart.cxx:923
virtual ::sal_Int32 SAL_CALL getPlotBy() override
Definition: vbachart.cxx:667
virtual void SAL_CALL setLocation(::sal_Int32 where, const css::uno::Any &Name) override
Definition: vbachart.cxx:719
constexpr OUStringLiteral DATAROWSOURCE(u"DataRowSource")
const char * sName
SC_DLLPUBLIC bool HasRowHeader(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab)
Definition: documen3.cxx:1514
constexpr OUStringLiteral HASMAINTITLE(u"HasMainTitle")
css::uno::Reference< css::chart::XAxisYSupplier > xAxisYSupplier
Definition: vbachart.hxx:45
sal_Int32 getStackedType(sal_Int32 _nStacked, sal_Int32 _n100PercentStacked, sal_Int32 _nUnStacked)
Definition: vbachart.cxx:890
int i
static css::uno::Sequence< OUString > getDefaultSeriesDescriptions(sal_Int32 nCount)
Definition: vbachart.cxx:627
virtual ::sal_Int32 SAL_CALL Location() override
Definition: vbachart.cxx:707
virtual css::uno::Reference< ov::excel::XChartTitle > SAL_CALL getChartTitle() override
Definition: vbachart.cxx:864
unsigned char sal_Bool
constexpr OUStringLiteral SYMBOLTYPE(u"SymbolType")
constexpr OUStringLiteral LINES(u"Lines")
css::uno::Reference< css::beans::XPropertySet > mxChartPropertySet
Definition: vbachart.hxx:43
constexpr OUStringLiteral DEEP(u"Deep")
css::uno::Reference< css::chart::XTwoAxisXSupplier > xTwoAxisXSupplier
Definition: vbachart.hxx:47
virtual void SAL_CALL Activate() override
Definition: vbachart.cxx:547
constexpr OUStringLiteral HASLEGEND(u"HasLegend")
bool is3D()
Definition: vbachart.cxx:881
virtual css::uno::Any SAL_CALL SeriesCollection(const css::uno::Any &) override
Definition: vbachart.cxx:97
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent() override
bool isStacked()
Definition: vbachart.cxx:905
constexpr OUStringLiteral SPLINETYPE(u"SplineType")
constexpr OUStringLiteral UPDOWN(u"UpDown")
sal_Int32 getMarkerType(sal_Int32 _nWithMarkers, sal_Int32 _nWithoutMarkers)
Definition: vbachart.cxx:994
#define ERRCODE_BASIC_METHOD_FAILED
virtual sal_Bool SAL_CALL getHasLegend() override
Definition: vbachart.cxx:836
virtual void SAL_CALL setHasTitle(sal_Bool bTitle) override
Definition: vbachart.cxx:822
css::uno::Reference< css::beans::XPropertySet > mxDiagramPropertySet
Definition: vbachart.hxx:42
ScDocument & getScDocument()
Definition: vbarange.cxx:419
constexpr OUStringLiteral CHART_NAME(u"Name")
virtual void SAL_CALL setChartType(::sal_Int32 _charttype) override
Definition: vbachart.cxx:222
virtual OUString SAL_CALL getName() override
Definition: vbachart.cxx:82
constexpr OUStringLiteral VERTICAL(u"Vertical")
constexpr OUStringLiteral STACKED(u"Stacked")
void setDiagram(const OUString &_sDiagramType)
Definition: vbachart.cxx:689
virtual ::sal_Int32 SAL_CALL getChartType() override
Definition: vbachart.cxx:103
constexpr OUStringLiteral DIM3D(u"Dim3D")
css::uno::Reference< css::chart::XAxisXSupplier > xAxisXSupplier
Definition: vbachart.hxx:44
bool is100PercentStacked()
Definition: vbachart.cxx:914
sal_Int32 getStockUpDownValue(sal_Int32 _nUpDown, sal_Int32 _nNotUpDown)
Definition: vbachart.cxx:955
virtual css::uno::Any SAL_CALL Axes(const css::uno::Any &Type, const css::uno::Any &AxisGroup) override
Definition: vbachart.cxx:872