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