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
44using namespace ::com::sun::star;
45using namespace ::ooo::vba;
46using namespace ::ooo::vba::excel::XlChartType;
47using namespace ::ooo::vba::excel::XlRowCol;
48using namespace ::ooo::vba::excel::XlAxisType;
49using namespace ::ooo::vba::excel::XlAxisGroup;
50
51constexpr OUStringLiteral CHART_NAME(u"Name");
52// #TODO move this constant to vbaseries.[ch]xx ( when it exists )
53constexpr OUStringLiteral DEFAULTSERIESPREFIX(u"Series");
54constexpr OUStringLiteral DATAROWSOURCE(u"DataRowSource");
55constexpr OUStringLiteral UPDOWN(u"UpDown");
56constexpr OUStringLiteral VOLUME(u"Volume");
57constexpr OUStringLiteral LINES(u"Lines");
58constexpr OUStringLiteral SPLINETYPE(u"SplineType");
59constexpr OUStringLiteral SYMBOLTYPE(u"SymbolType");
60constexpr OUStringLiteral DEEP(u"Deep");
61constexpr OUStringLiteral SOLIDTYPE(u"SolidType");
62constexpr OUStringLiteral VERTICAL(u"Vertical");
63constexpr OUStringLiteral PERCENT(u"Percent");
64constexpr OUStringLiteral STACKED(u"Stacked");
65constexpr OUStringLiteral DIM3D(u"Dim3D");
66constexpr OUStringLiteral HASMAINTITLE(u"HasMainTitle");
67constexpr OUStringLiteral HASLEGEND(u"HasLegend");
68
69ScVbaChart::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
81OUString 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
96uno::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
221void SAL_CALL
222ScVbaChart::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::Any((_nChartType == xlStockOHLC) || (_nChartType == xlStockVOHLC)));
295 mxDiagramPropertySet->setPropertyValue( VOLUME, uno::Any((_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::Any( false ));
326 break;
327 case xlXYScatterLines:
328 case xlXYScatterLinesNoMarkers:
329 mxDiagramPropertySet->setPropertyValue(LINES, uno::Any( true ));
330 break;
331 case xlXYScatterSmooth:
332 case xlXYScatterSmoothNoMarkers:
333 mxDiagramPropertySet->setPropertyValue(SPLINETYPE, uno::Any( 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::Any( chart::ChartSymbolType::AUTO));
355 break;
356 default:
357 if (mxDiagramPropertySet->getPropertySetInfo()->hasPropertyByName(SYMBOLTYPE))
358 {
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::Any( true ));
375 break;
376 default:
377 if (mxDiagramPropertySet->getPropertySetInfo()->hasPropertyByName(DEEP))
378 {
379 mxDiagramPropertySet->setPropertyValue(DEEP, uno::Any( 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::Any(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::Any(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::Any(chart::ChartSolidType::CYLINDER));
412 break;
413 default:
414 if (mxDiagramPropertySet->getPropertySetInfo()->hasPropertyByName(SOLIDTYPE))
415 {
416 mxDiagramPropertySet->setPropertyValue(SOLIDTYPE, uno::Any(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::Any( true));
444 break;
445 default:
446 if (mxDiagramPropertySet->getPropertySetInfo()->hasPropertyByName(VERTICAL))
447 {
448 mxDiagramPropertySet->setPropertyValue(VERTICAL, uno::Any(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::Any( false ));
470 mxDiagramPropertySet->setPropertyValue(STACKED, uno::Any( 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::Any( true));
487 mxDiagramPropertySet->setPropertyValue(PERCENT, uno::Any( true ));
488 break;
489 default:
490 mxDiagramPropertySet->setPropertyValue(PERCENT, uno::Any( false));
491 mxDiagramPropertySet->setPropertyValue(STACKED, uno::Any( 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::Any( true));
531 break;
532 default:
533 if (mxDiagramPropertySet->getPropertySetInfo()->hasPropertyByName(DIM3D))
534 {
535 mxDiagramPropertySet->setPropertyValue(DIM3D, uno::Any( 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
546void 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
562void SAL_CALL
563ScVbaChart::setSourceData( const css::uno::Reference< ::ooo::vba::excel::XRange >& _xCalcRange, const css::uno::Any& _aPlotBy )
564{
565 try
566 {
567 table::CellRangeAddress aSingleRangeAddress;
568
569 uno::Reference< sheet::XCellRangeAddressable > xAddressable( _xCalcRange->getCellRange(), uno::UNO_QUERY_THROW );
570 aSingleRangeAddress = xAddressable->getRangeAddress();
571
572 mxTableChart->setRanges({ aSingleRangeAddress } );
573
574 bool bsetRowHeaders = false;
575 bool bsetColumnHeaders = false;
576
577 ScVbaRange* pRange = static_cast< ScVbaRange* >( _xCalcRange.get() );
578 if ( pRange )
579 {
580 ScDocument& rDoc = pRange->getScDocument();
581 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 ) );
582 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 ));
583 }
584 mxTableChart->setHasRowHeaders(bsetRowHeaders);
585 mxTableChart->setHasColumnHeaders(bsetColumnHeaders);
586
587 if ((!bsetColumnHeaders) || (!bsetRowHeaders))
588 {
589 uno::Reference< chart::XChartDataArray > xChartDataArray( mxChartDocument->getData(), uno::UNO_QUERY_THROW );
590 if (!bsetColumnHeaders)
591 {
592 xChartDataArray->setColumnDescriptions( getDefaultSeriesDescriptions(xChartDataArray->getColumnDescriptions().getLength() ));
593 }
594 if (!bsetRowHeaders)
595 {
596 xChartDataArray->setRowDescriptions(getDefaultSeriesDescriptions(xChartDataArray->getRowDescriptions().getLength() ));
597 }
598 }
599
600 if ( _aPlotBy.hasValue() )
601 {
602 sal_Int32 nVal = 0;
603 _aPlotBy >>= nVal;
604 setPlotBy( nVal );
605 }
606 else
607 {
608 sal_Int32 nRows = aSingleRangeAddress.EndRow - aSingleRangeAddress.StartRow;
609 sal_Int32 nCols = aSingleRangeAddress.EndColumn - aSingleRangeAddress.StartColumn;
610 // AutoDetect emulation
611 if ( nRows > nCols )
612 setPlotBy( xlColumns );
613 else if ( nRows <= nCols )
614 setPlotBy( xlRows );
615 }
616 }
617 catch (const uno::Exception&)
618 {
619 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
620 }
621}
622
623uno::Sequence< OUString >
625{
626 uno::Sequence< OUString > sDescriptions ( _nCount );
627 std::generate_n(sDescriptions.getArray(), _nCount,
628 [i = 1]() mutable -> OUString { return DEFAULTSERIESPREFIX + OUString::number(i++); });
629 return sDescriptions;
630}
631
632void
634{
635 setChartType( xlColumnClustered );
636}
637
638void
639ScVbaChart::setPlotBy( ::sal_Int32 _nPlotBy )
640{
641 try
642 {
643 if ( !mxDiagramPropertySet.is() )
645 switch (_nPlotBy)
646 {
647 case xlRows:
648 mxDiagramPropertySet->setPropertyValue( DATAROWSOURCE, uno::Any( chart::ChartDataRowSource_ROWS ) );
649 break;
650 case xlColumns:
651 mxDiagramPropertySet->setPropertyValue( DATAROWSOURCE, uno::Any( chart::ChartDataRowSource_COLUMNS) );
652 break;
653 default:
654 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
655 }
656 }
657 catch (const uno::Exception&)
658 {
659 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
660 }
661}
662
663::sal_Int32 SAL_CALL
665{
666 try
667 {
668 chart::ChartDataRowSource aChartDataRowSource;
669 mxDiagramPropertySet->getPropertyValue(DATAROWSOURCE) >>= aChartDataRowSource;
670 if (aChartDataRowSource == chart::ChartDataRowSource_COLUMNS)
671 {
672 return xlColumns;
673 }
674 else
675 {
676 return xlRows;
677 }
678 }
679 catch (const uno::Exception&)
680 {
681 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
682 }
683}
684
685void
686ScVbaChart::setDiagram( const OUString& _sDiagramType )
687{
688 try
689 {
690 uno::Reference< lang::XMultiServiceFactory > xMSF( mxChartDocument, uno::UNO_QUERY_THROW );
691 uno::Reference< chart::XDiagram > xDiagram( xMSF->createInstance( _sDiagramType ), uno::UNO_QUERY_THROW );
692 mxChartDocument->setDiagram( xDiagram );
693 mxDiagramPropertySet.set( xDiagram, uno::UNO_QUERY_THROW );
694 }
695 catch ( const uno::Exception& )
696 {
697 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
698 }
699}
700
701// #TODO find out why we have Location/getLocation? there is afaik no
702// Location property, just a Location function for the Chart object
703sal_Int32 SAL_CALL
705{
706 return getLocation();
707}
708
709sal_Int32 SAL_CALL
711{
712 return -1;
713}
714
715void SAL_CALL
716ScVbaChart::setLocation( ::sal_Int32 /*where*/, const css::uno::Any& /*Name*/ )
717{
718 // Helper api just stubs out the code <shrug>
719 // #TODO come back and make sense out of this
720// String sheetName = null;
721//
722// if ((name != null) && name instanceof String) {
723// sheetName = (String) name;
724// }
725// XSpreadsheetDocument xShDoc = (XSpreadsheetDocument) UnoRuntime.queryInterface( XSpreadsheetDocument.class,getXModel() );
726// com.sun.star.sheet.XSpreadsheets xSheets = xShDoc.Sheets();
727//
728// switch (where) {
729// case ClLocationType.clLocationAsObject_value: //{
730//
731// if (sheetName == null) {
732// DebugHelper.writeInfo("Can't embed in Chart without knowing SheetName");
733// return;
734// }
735//
736// try {
737// Any any = (Any) xSheets.getByName(sheetName);
738// chartSheet = (XSpreadsheet) any.getObject();
739//
740// // chartSheet = (XSpreadsheet) xSheets.getByName( sheetName );
741// } catch (NoSuchElementException e) {
742// // TODO Auto-generated catch block
743// e.printStackTrace();
744//
745// return;
746// } catch (WrappedTargetException e) {
747// // TODO Auto-generated catch block
748// e.printStackTrace();
749//
750// return;
751// } catch (java.lang.Exception e) {
752// e.printStackTrace();
753// }
754//
755// XTableChartsSupplier xTCS = (XTableChartsSupplier) UnoRuntime.queryInterface( XTableChartsSupplier.class, chartSheet);
756// XTableCharts xTableCharts = xTCS.getCharts();
757// XIndexAccess xIA = (XIndexAccess) UnoRuntime.queryInterface( XIndexAccess.class, xTableCharts);
758// int numCharts = xIA.getCount();
759// chartName = "Chart " + (numCharts + 1);
760//
761// //}
762// break;
763//
764// case ClLocationType.clLocationAsNewSheet_value:
765// case ClLocationType.clLocationAutomatic_value:default: //{
766// chartName = "Chart 1"; // Since it's a new sheet, it's the first on it...
767//
768// XIndexAccess xSheetIA = (XIndexAccess) UnoRuntime.queryInterface( XIndexAccess.class, xSheets);
769//
770// short newSheetNum = (short) (xSheetIA.getCount() + 1);
771//
772// if (sheetName == null){
773// sheetName = "ChartSheet " + newSheetNum; // Why not?
774// }
775// // DPK TODO : Probably should use Sheets to create this!
776// xSheets.insertNewByName(sheetName, newSheetNum);
777//
778// try {
779// chartSheet =
780// (XSpreadsheet) xSheets.getByName(sheetName);
781// } catch (NoSuchElementException e) {
782// // TODO Auto-generated catch block
783// e.printStackTrace();
784//
785// return;
786// } catch (WrappedTargetException e) {
787// // TODO Auto-generated catch block
788// e.printStackTrace();
789//
790// return;
791// }
792//
793// //}
794// break;
795// }
796//
797// // Last thing should be a call to createChartForReal(), one of them
798// // should succeed.
799// createChartForReal();
800
801}
802
803sal_Bool SAL_CALL
805{
806 bool bHasTitle = false;
807 try
808 {
809 mxChartPropertySet->getPropertyValue(HASMAINTITLE) >>= bHasTitle;
810 }
811 catch (const uno::Exception&)
812 {
813 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
814 }
815 return bHasTitle;
816}
817
818void SAL_CALL
820{
821 try
822 {
823 mxChartPropertySet->setPropertyValue(HASMAINTITLE, uno::Any( bTitle ));
824 }
825 catch (const uno::Exception&)
826 {
827 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
828 }
829
830}
831
832sal_Bool SAL_CALL
834{
835 bool bHasLegend = false;
836 try
837 {
838 mxChartPropertySet->getPropertyValue(HASLEGEND) >>= bHasLegend;
839 }
840 catch (const uno::Exception&)
841 {
842 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
843 }
844 return bHasLegend;
845}
846
847void SAL_CALL
849{
850 try
851 {
852 mxChartPropertySet->setPropertyValue(HASLEGEND, uno::Any(bLegend));
853 }
854 catch (const uno::Exception&)
855 {
856 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
857 }
858}
859
860uno::Reference< excel::XChartTitle > SAL_CALL
862{
863 uno::Reference< drawing::XShape > xTitleShape = mxChartDocument->getTitle();
864 // #TODO check parent
865 return new ScVbaChartTitle(this, mxContext, xTitleShape);
866}
867
868uno::Any SAL_CALL
869ScVbaChart::Axes( const uno::Any& Type, const uno::Any& AxisGroup )
870{
871 // mmm chart probably is the parent, #TODO check parent
872 uno::Reference< excel::XAxes > xAxes = new ScVbaAxes( this, mxContext, this );
873 if ( !Type.hasValue() )
874 return uno::Any( xAxes );
875 return xAxes->Item( Type, AxisGroup );
876}
877bool
879{
880 // #TODO perhaps provide limited Debughelper functionality
881 bool is3d = false;
882 mxDiagramPropertySet->getPropertyValue(DIM3D) >>= is3d;
883 return is3d;
884}
885
886sal_Int32
887ScVbaChart::getStackedType( sal_Int32 _nStacked, sal_Int32 _n100PercentStacked, sal_Int32 _nUnStacked )
888{
889 // #TODO perhaps provide limited Debughelper functionality
890 if (isStacked())
891 {
893 return _n100PercentStacked;
894 else
895 return _nStacked;
896 }
897 else
898 return _nUnStacked;
899}
900
901bool
903{
904 // #TODO perhaps provide limited Debughelper functionality
905 bool bStacked = false;
906 mxDiagramPropertySet->getPropertyValue(STACKED) >>= bStacked;
907 return bStacked;
908}
909
910bool
912{
913 // #TODO perhaps provide limited Debughelper functionality
914 bool b100Percent = false;
915 mxDiagramPropertySet->getPropertyValue(PERCENT) >>= b100Percent;
916 return b100Percent;
917}
918
919sal_Int32
920ScVbaChart::getSolidType(sal_Int32 _nDeep, sal_Int32 _nVertiStacked, sal_Int32 _nVerti100PercentStacked, sal_Int32 _nVertiUnStacked, sal_Int32 _nHoriStacked, sal_Int32 _nHori100PercentStacked, sal_Int32 _nHoriUnStacked)
921{
922 try
923 {
924 bool bIsVertical = true;
925 mxDiagramPropertySet->getPropertyValue(VERTICAL) >>= bIsVertical;
926 bool bIsDeep = false;
927 mxDiagramPropertySet->getPropertyValue(DEEP) >>= bIsDeep;
928
929 if (bIsDeep)
930 {
931 return _nDeep;
932 }
933 else
934 {
935 if (bIsVertical)
936 {
937 return getStackedType(_nVertiStacked, _nVerti100PercentStacked, _nVertiUnStacked);
938 }
939 else
940 {
941 return getStackedType(_nHoriStacked, _nHori100PercentStacked, _nHoriUnStacked);
942 }
943 }
944 }
945 catch (const uno::Exception&)
946 {
947 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
948 }
949}
950
951sal_Int32
952ScVbaChart::getStockUpDownValue(sal_Int32 _nUpDown, sal_Int32 _nNotUpDown)
953{
954 try
955 {
956 bool bUpDown = false;
957 mxDiagramPropertySet->getPropertyValue(UPDOWN) >>= bUpDown;
958 if (bUpDown)
959 {
960 return _nUpDown;
961 }
962 else
963 {
964 return _nNotUpDown;
965 }
966 }
967 catch (const uno::Exception&)
968 {
969 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
970 }
971}
972
973bool
975{
976 bool bHasMarkers = false;
977 try
978 {
979 sal_Int32 nSymbol=0;
980 mxDiagramPropertySet->getPropertyValue(SYMBOLTYPE) >>= nSymbol;
981 bHasMarkers = nSymbol != chart::ChartSymbolType::NONE;
982 }
983 catch (const uno::Exception&)
984 {
985 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED), OUString() );
986 }
987 return bHasMarkers;
988}
989
990sal_Int32
991ScVbaChart::getMarkerType(sal_Int32 _nWithMarkers, sal_Int32 _nWithoutMarkers)
992{
993 if (hasMarkers())
994 return _nWithMarkers;
995 return _nWithoutMarkers;
996}
997
998void
1000{
1001 xAxisXSupplier.set( mxDiagramPropertySet, uno::UNO_QUERY_THROW );
1002 xAxisYSupplier.set( mxDiagramPropertySet, uno::UNO_QUERY_THROW );
1003 xAxisZSupplier.set( mxDiagramPropertySet, uno::UNO_QUERY_THROW );
1004 xTwoAxisXSupplier.set( mxDiagramPropertySet, uno::UNO_QUERY_THROW );
1005 xTwoAxisYSupplier.set( mxDiagramPropertySet, uno::UNO_QUERY_THROW );
1006}
1007
1008uno::Reference< beans::XPropertySet >
1009ScVbaChart::getAxisPropertySet(sal_Int32 _nAxisType, sal_Int32 _nAxisGroup)
1010{
1012 uno::Reference< beans::XPropertySet > xAxisProps;
1013 switch(_nAxisType)
1014 {
1015 case xlCategory:
1016 if (_nAxisGroup == xlPrimary)
1017 {
1018 xAxisProps = xAxisXSupplier->getXAxis();
1019 }
1020 else if (_nAxisGroup == xlSecondary)
1021 {
1022 xAxisProps = xTwoAxisXSupplier->getSecondaryXAxis();
1023 }
1024 break;
1025 case xlSeriesAxis:
1026 xAxisProps = xAxisZSupplier->getZAxis();
1027 break;
1028 case xlValue:
1029 if (_nAxisGroup == xlPrimary)
1030 xAxisProps = xAxisYSupplier->getYAxis();
1031 else if (_nAxisGroup == xlSecondary)
1032 xAxisProps = xTwoAxisYSupplier->getSecondaryYAxis();
1033 break;
1034 default:
1035 return xAxisProps;
1036 }
1037 return xAxisProps;
1038}
1039
1040OUString
1042{
1043 return "ScVbaChart";
1044}
1045
1046uno::Sequence< OUString >
1048{
1049 static uno::Sequence< OUString > const aServiceNames
1050 {
1051 "ooo.vba.excel.Chart"
1052 };
1053 return aServiceNames;
1054}
1055
1056/* 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:1542
SC_DLLPUBLIC bool HasRowHeader(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab)
Definition: documen3.cxx:1548
virtual void SAL_CALL Activate() override
Definition: vbachart.cxx:547
virtual void SAL_CALL setSourceData(const css::uno::Reference< ::ooo::vba::excel::XRange > &range, const css::uno::Any &PlotBy) override
Definition: vbachart.cxx:563
virtual ::sal_Int32 SAL_CALL getChartType() override
Definition: vbachart.cxx:103
sal_Int32 getStockUpDownValue(sal_Int32 _nUpDown, sal_Int32 _nNotUpDown)
Definition: vbachart.cxx:952
virtual void SAL_CALL setPlotBy(::sal_Int32 xlRowCol) override
Definition: vbachart.cxx:639
virtual void SAL_CALL setChartType(::sal_Int32 _charttype) override
Definition: vbachart.cxx:222
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbachart.cxx:1047
css::uno::Reference< css::beans::XPropertySet > mxDiagramPropertySet
Definition: vbachart.hxx:41
bool is100PercentStacked()
Definition: vbachart.cxx:911
virtual sal_Bool SAL_CALL getHasTitle() override
Definition: vbachart.cxx:804
virtual sal_Bool SAL_CALL getHasLegend() override
Definition: vbachart.cxx:833
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:97
css::uno::Reference< css::chart::XTwoAxisXSupplier > xTwoAxisXSupplier
Definition: vbachart.hxx:46
virtual void SAL_CALL setHasTitle(sal_Bool bTitle) override
Definition: vbachart.cxx:819
sal_Int32 getMarkerType(sal_Int32 _nWithMarkers, sal_Int32 _nWithoutMarkers)
Definition: vbachart.cxx:991
virtual ::sal_Int32 SAL_CALL Location() override
Definition: vbachart.cxx:704
css::uno::Reference< css::chart::XTwoAxisYSupplier > xTwoAxisYSupplier
Definition: vbachart.hxx:47
virtual ::sal_Int32 SAL_CALL getLocation() override
Definition: vbachart.cxx:710
bool isStacked()
Definition: vbachart.cxx:902
css::uno::Reference< css::beans::XPropertySet > getAxisPropertySet(sal_Int32 _nAxisType, sal_Int32 _nAxisGroup)
Definition: vbachart.cxx:1009
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:624
void setDefaultChartType()
Definition: vbachart.cxx:633
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:869
css::uno::Reference< css::chart::XAxisZSupplier > xAxisZSupplier
Definition: vbachart.hxx:45
bool is3D()
Definition: vbachart.cxx:878
virtual void SAL_CALL setHasLegend(sal_Bool bLegend) override
Definition: vbachart.cxx:848
css::uno::Reference< css::chart::XAxisYSupplier > xAxisYSupplier
Definition: vbachart.hxx:44
virtual OUString SAL_CALL getName() override
Definition: vbachart.cxx:82
void setDiagram(const OUString &_sDiagramType)
Definition: vbachart.cxx:686
sal_Int32 getStackedType(sal_Int32 _nStacked, sal_Int32 _n100PercentStacked, sal_Int32 _nUnStacked)
Definition: vbachart.cxx:887
virtual void SAL_CALL setLocation(::sal_Int32 where, const css::uno::Any &Name) override
Definition: vbachart.cxx:716
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
bool hasMarkers()
Definition: vbachart.cxx:974
virtual css::uno::Reference< ov::excel::XChartTitle > SAL_CALL getChartTitle() override
Definition: vbachart.cxx:861
virtual ::sal_Int32 SAL_CALL getPlotBy() override
Definition: vbachart.cxx:664
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:920
void assignDiagramAttributes()
Definition: vbachart.cxx:999
virtual OUString getServiceImplName() override
Definition: vbachart.cxx:1041
ScDocument & getScDocument()
Definition: vbarange.cxx:417
Sequence< OUString > aServiceNames
const char * 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")