1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
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>
45 using namespace ::com::sun::star
;
46 using namespace ::ooo::vba
;
47 using namespace ::ooo::vba::excel::XlChartType
;
48 using namespace ::ooo::vba::excel::XlRowCol
;
49 using namespace ::ooo::vba::excel::XlAxisType
;
50 using namespace ::ooo::vba::excel::XlAxisGroup
;
52 constexpr OUStringLiteral
CHART_NAME(u
"Name");
53 // #TODO move this constant to vbaseries.[ch]xx ( when it exists )
54 constexpr OUStringLiteral
DEFAULTSERIESPREFIX(u
"Series");
55 constexpr OUString
DATAROWSOURCE(u
"DataRowSource"_ustr
);
56 constexpr OUString
UPDOWN(u
"UpDown"_ustr
);
57 constexpr OUString
VOLUME(u
"Volume"_ustr
);
58 constexpr OUString
LINES(u
"Lines"_ustr
);
59 constexpr OUString
SPLINETYPE(u
"SplineType"_ustr
);
60 constexpr OUString
SYMBOLTYPE(u
"SymbolType"_ustr
);
61 constexpr OUString
DEEP(u
"Deep"_ustr
);
62 constexpr OUString
SOLIDTYPE(u
"SolidType"_ustr
);
63 constexpr OUString
VERTICAL(u
"Vertical"_ustr
);
64 constexpr OUString
PERCENT(u
"Percent"_ustr
);
65 constexpr OUString
STACKED(u
"Stacked"_ustr
);
66 constexpr OUString
DIM3D(u
"Dim3D"_ustr
);
67 constexpr OUString
HASMAINTITLE(u
"HasMainTitle"_ustr
);
68 constexpr OUString
HASLEGEND(u
"HasLegend"_ustr
);
70 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
, css::uno::Reference
< css::table::XTableChart
> _xTableChart
) : ChartImpl_BASE( _xParent
, _xContext
), mxTableChart(std::move( _xTableChart
))
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
) ;
86 uno::Reference
< beans::XPropertySet
> xProps( mxChartDocument
, uno::UNO_QUERY_THROW
);
89 xProps
->getPropertyValue( CHART_NAME
) >>= sName
;
91 catch( const uno::Exception
& ) // swallow exceptions
98 ScVbaChart::SeriesCollection(const uno::Any
&)
104 ScVbaChart::getChartType()
106 sal_Int32 nChartType
= -1;
109 OUString sDiagramType
= mxChartDocument
->getDiagram()->getDiagramType();
110 if ( sDiagramType
== "com.sun.star.chart.AreaDiagram" )
114 nChartType
= getStackedType(xl3DAreaStacked
, xl3DAreaStacked100
, xl3DArea
);
118 nChartType
= getStackedType(xlAreaStacked
, xlAreaStacked100
, xlArea
);
121 else if ( sDiagramType
== "com.sun.star.chart.PieDiagram" )
124 nChartType
= xl3DPie
;
126 nChartType
= xlPie
; /*TODO XlChartType xlPieExploded, XlChartType xlPieOfPie */
128 else if ( sDiagramType
== "com.sun.star.chart.BarDiagram" )
130 sal_Int32 nSolidType
= chart::ChartSolidType::RECTANGULAR_SOLID
;
131 if (mxDiagramPropertySet
->getPropertySetInfo()->hasPropertyByName(SOLIDTYPE
))
132 { //in 2D diagrams 'SolidType' may not be set
134 mxDiagramPropertySet
->getPropertyValue(SOLIDTYPE
) >>= nSolidType
;
138 case chart::ChartSolidType::CONE
:
139 nChartType
= getSolidType(xlConeCol
, xlConeColStacked
, xlConeColStacked100
, xlConeColClustered
, xlConeBarStacked
, xlConeBarStacked100
, xlConeBarClustered
);
141 case chart::ChartSolidType::CYLINDER
:
142 nChartType
= getSolidType(xlCylinderCol
, xlCylinderColStacked
, xlCylinderColStacked100
, xlCylinderColClustered
, xlCylinderBarStacked
, xlCylinderBarStacked100
, xlCylinderBarClustered
);
144 case chart::ChartSolidType::PYRAMID
:
145 nChartType
= getSolidType(xlPyramidCol
, xlPyramidColStacked
, xlPyramidColStacked100
, xlPyramidColClustered
, xlPyramidBarStacked
, xlPyramidBarStacked100
, xlPyramidBarClustered
);
147 default: // RECTANGULAR_SOLID
150 nChartType
= getSolidType(xl3DColumn
, xl3DColumnStacked
, xl3DColumnStacked100
, xl3DColumnClustered
, xl3DBarStacked
, xl3DBarStacked100
, xl3DBarClustered
);
154 nChartType
= getSolidType(xlColumnClustered
, xlColumnStacked
, xlColumnStacked100
, xlColumnClustered
, xlBarStacked
, xlBarStacked100
, xlBarClustered
);
159 else if ( sDiagramType
== "com.sun.star.chart.StockDiagram" )
161 bool bVolume
= false;
162 mxDiagramPropertySet
->getPropertyValue(VOLUME
) >>= bVolume
;
165 nChartType
= getStockUpDownValue(xlStockVOHLC
, xlStockVHLC
);
169 nChartType
= getStockUpDownValue(xlStockOHLC
, xlStockHLC
);
172 else if ( sDiagramType
== "com.sun.star.chart.XYDiagram" )
174 bool bHasLines
= false;
175 mxDiagramPropertySet
->getPropertyValue(LINES
) >>= bHasLines
;
176 sal_Int32 nSplineType
= 0;
177 mxDiagramPropertySet
->getPropertyValue(SPLINETYPE
) >>= nSplineType
;
178 if (nSplineType
== 1)
180 nChartType
= getMarkerType(xlXYScatterSmooth
, xlXYScatterSmoothNoMarkers
);
184 nChartType
= getMarkerType(xlXYScatterLines
, xlXYScatterLinesNoMarkers
);
188 nChartType
= xlXYScatter
;
191 else if ( sDiagramType
== "com.sun.star.chart.LineDiagram" )
195 nChartType
= xl3DLine
;
197 else if (hasMarkers())
199 nChartType
= getStackedType(xlLineMarkersStacked
, xlLineMarkersStacked100
, xlLineMarkers
);
203 nChartType
= getStackedType(xlLineStacked
, xlLineStacked100
, xlLine
);
206 else if ( sDiagramType
== "com.sun.star.chart.DonutDiagram" )
208 nChartType
= xlDoughnut
; // TODO DoughnutExploded ??
210 else if ( sDiagramType
== "com.sun.star.chart.NetDiagram" )
212 nChartType
= getMarkerType(xlRadarMarkers
, xlRadar
);
215 catch ( const uno::Exception
& )
217 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED
), OUString() );
223 ScVbaChart::setChartType( ::sal_Int32 _nChartType
)
229 case xlColumnClustered
:
230 case xlColumnStacked
:
231 case xlColumnStacked100
:
232 case xl3DColumnClustered
:
233 case xl3DColumnStacked
:
234 case xl3DColumnStacked100
:
238 case xlBarStacked100
:
239 case xl3DBarClustered
:
241 case xl3DBarStacked100
:
242 case xlConeColClustered
:
243 case xlConeColStacked
:
244 case xlConeColStacked100
:
245 case xlConeBarClustered
:
246 case xlConeBarStacked
:
247 case xlConeBarStacked100
:
249 case xlPyramidColClustered
:
250 case xlPyramidColStacked
:
251 case xlPyramidColStacked100
:
252 case xlPyramidBarClustered
:
253 case xlPyramidBarStacked
:
254 case xlPyramidBarStacked100
:
256 case xlCylinderColClustered
:
257 case xlCylinderColStacked
:
258 case xlCylinderColStacked100
:
259 case xlCylinderBarClustered
:
260 case xlCylinderBarStacked
:
261 case xlCylinderBarStacked100
:
263 case xlSurface
: // not possible
264 case xlSurfaceWireframe
:
265 case xlSurfaceTopView
:
266 case xlSurfaceTopViewWireframe
:
267 setDiagram( u
"com.sun.star.chart.BarDiagram"_ustr
);
272 case xlLineStacked100
:
274 case xlLineMarkersStacked
:
275 case xlLineMarkersStacked100
:
276 setDiagram( u
"com.sun.star.chart.LineDiagram"_ustr
);
281 case xlAreaStacked100
:
282 case xl3DAreaStacked
:
283 case xl3DAreaStacked100
:
284 setDiagram( u
"com.sun.star.chart.AreaDiagram"_ustr
);
287 case xlDoughnutExploded
:
288 setDiagram( u
"com.sun.star.chart.DonutDiagram"_ustr
);
294 setDiagram( u
"com.sun.star.chart.StockDiagram"_ustr
);
295 mxDiagramPropertySet
->setPropertyValue( UPDOWN
, uno::Any((_nChartType
== xlStockOHLC
) || (_nChartType
== xlStockVOHLC
)));
296 mxDiagramPropertySet
->setPropertyValue( VOLUME
, uno::Any((_nChartType
== xlStockVHLC
) || (_nChartType
== xlStockVOHLC
)));
299 case xlPieOfPie
: // not possible
300 case xlPieExploded
: // SegmentOffset on ChartDataPointProperties -> get from XDiagram //How does Excel do this?
301 case xl3DPieExploded
:
304 case xlBarOfPie
: // not possible (Zoom pie)
305 setDiagram( u
"com.sun.star.chart.PieDiagram"_ustr
);
311 setDiagram( u
"com.sun.star.chart.NetDiagram"_ustr
);
314 case xlBubble
: // not possible
315 case xlBubble3DEffect
: // not possible
316 case xlXYScatterLines
:
317 case xlXYScatterLinesNoMarkers
:
318 case xlXYScatterSmooth
:
319 case xlXYScatterSmoothNoMarkers
:
320 setDiagram( u
"com.sun.star.chart.XYDiagram"_ustr
);
324 case xlBubble
: // not possible
325 case xlBubble3DEffect
: // not possible
326 mxDiagramPropertySet
->setPropertyValue(LINES
, uno::Any( false ));
328 case xlXYScatterLines
:
329 case xlXYScatterLinesNoMarkers
:
330 mxDiagramPropertySet
->setPropertyValue(LINES
, uno::Any( true ));
332 case xlXYScatterSmooth
:
333 case xlXYScatterSmoothNoMarkers
:
334 mxDiagramPropertySet
->setPropertyValue(SPLINETYPE
, uno::Any( sal_Int32(1)));
341 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), sal_uInt32(ERRCODE_BASIC_CONVERSION
), OUString() );
347 case xlLineMarkersStacked
:
348 case xlLineMarkersStacked100
:
350 case xlXYScatterLines
:
351 case xlXYScatterSmooth
:
353 case xlBubble
: // not possible
354 case xlBubble3DEffect
: // not possible
355 mxDiagramPropertySet
->setPropertyValue(SYMBOLTYPE
, uno::Any( chart::ChartSymbolType::AUTO
));
358 if (mxDiagramPropertySet
->getPropertySetInfo()->hasPropertyByName(SYMBOLTYPE
))
360 mxDiagramPropertySet
->setPropertyValue(SYMBOLTYPE
, uno::Any(chart::ChartSymbolType::NONE
));
371 case xlSurface
: // not possible
372 case xlSurfaceWireframe
:
373 case xlSurfaceTopView
:
374 case xlSurfaceTopViewWireframe
:
375 mxDiagramPropertySet
->setPropertyValue(DEEP
,uno::Any( true ));
378 if (mxDiagramPropertySet
->getPropertySetInfo()->hasPropertyByName(DEEP
))
380 mxDiagramPropertySet
->setPropertyValue(DEEP
, uno::Any( false));
387 case xlConeColClustered
:
388 case xlConeColStacked
:
389 case xlConeColStacked100
:
390 case xlConeBarClustered
:
391 case xlConeBarStacked
:
392 case xlConeBarStacked100
:
394 mxDiagramPropertySet
->setPropertyValue(SOLIDTYPE
, uno::Any(chart::ChartSolidType::CONE
));
396 case xlPyramidColClustered
:
397 case xlPyramidColStacked
:
398 case xlPyramidColStacked100
:
399 case xlPyramidBarClustered
:
400 case xlPyramidBarStacked
:
401 case xlPyramidBarStacked100
:
403 mxDiagramPropertySet
->setPropertyValue(SOLIDTYPE
, uno::Any(chart::ChartSolidType::PYRAMID
));
405 case xlCylinderColClustered
:
406 case xlCylinderColStacked
:
407 case xlCylinderColStacked100
:
408 case xlCylinderBarClustered
:
409 case xlCylinderBarStacked
:
410 case xlCylinderBarStacked100
:
412 mxDiagramPropertySet
->setPropertyValue(SOLIDTYPE
, uno::Any(chart::ChartSolidType::CYLINDER
));
415 if (mxDiagramPropertySet
->getPropertySetInfo()->hasPropertyByName(SOLIDTYPE
))
417 mxDiagramPropertySet
->setPropertyValue(SOLIDTYPE
, uno::Any(chart::ChartSolidType::RECTANGULAR_SOLID
));
422 switch ( _nChartType
)
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));
447 if (mxDiagramPropertySet
->getPropertySetInfo()->hasPropertyByName(VERTICAL
))
449 mxDiagramPropertySet
->setPropertyValue(VERTICAL
, uno::Any(false));
456 case xlColumnStacked
:
457 case xl3DColumnStacked
:
461 case xlLineMarkersStacked
:
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 ));
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 ));
491 mxDiagramPropertySet
->setPropertyValue(PERCENT
, uno::Any( false));
492 mxDiagramPropertySet
->setPropertyValue(STACKED
, uno::Any( false));
498 case xl3DAreaStacked
:
499 case xl3DAreaStacked100
:
500 case xl3DBarClustered
:
502 case xl3DBarStacked100
:
504 case xl3DColumnClustered
:
505 case xl3DColumnStacked
:
506 case xl3DColumnStacked100
:
509 case xl3DPieExploded
:
510 case xlConeColClustered
:
511 case xlConeColStacked
:
512 case xlConeColStacked100
:
513 case xlConeBarClustered
:
514 case xlConeBarStacked
:
515 case xlConeBarStacked100
:
517 case xlPyramidColClustered
:
518 case xlPyramidColStacked
:
519 case xlPyramidColStacked100
:
520 case xlPyramidBarClustered
:
521 case xlPyramidBarStacked
:
522 case xlPyramidBarStacked100
:
524 case xlCylinderColClustered
:
525 case xlCylinderColStacked
:
526 case xlCylinderColStacked100
:
527 case xlCylinderBarClustered
:
528 case xlCylinderBarStacked
:
529 case xlCylinderBarStacked100
:
531 mxDiagramPropertySet
->setPropertyValue(DIM3D
, uno::Any( true));
534 if (mxDiagramPropertySet
->getPropertySetInfo()->hasPropertyByName(DIM3D
))
536 mxDiagramPropertySet
->setPropertyValue(DIM3D
, uno::Any( false));
541 catch ( const uno::Exception
& )
543 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED
), OUString() );
548 ScVbaChart::Activate()
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() );
557 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED
), u
"no ChartObject as parent"_ustr
);
559 pChartObj
->Activate();
564 ScVbaChart::setSourceData( const css::uno::Reference
< ::ooo::vba::excel::XRange
>& _xCalcRange
, const css::uno::Any
& _aPlotBy
)
568 table::CellRangeAddress aSingleRangeAddress
;
570 uno::Reference
< sheet::XCellRangeAddressable
> xAddressable( _xCalcRange
->getCellRange(), uno::UNO_QUERY_THROW
);
571 aSingleRangeAddress
= xAddressable
->getRangeAddress();
573 mxTableChart
->setRanges({ aSingleRangeAddress
} );
575 bool bsetRowHeaders
= false;
576 bool bsetColumnHeaders
= false;
578 ScVbaRange
* pRange
= static_cast< ScVbaRange
* >( _xCalcRange
.get() );
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
));
585 mxTableChart
->setHasRowHeaders(bsetRowHeaders
);
586 mxTableChart
->setHasColumnHeaders(bsetColumnHeaders
);
588 if ((!bsetColumnHeaders
) || (!bsetRowHeaders
))
590 uno::Reference
< chart::XChartDataArray
> xChartDataArray( mxChartDocument
->getData(), uno::UNO_QUERY_THROW
);
591 if (!bsetColumnHeaders
)
593 xChartDataArray
->setColumnDescriptions( getDefaultSeriesDescriptions(xChartDataArray
->getColumnDescriptions().getLength() ));
597 xChartDataArray
->setRowDescriptions(getDefaultSeriesDescriptions(xChartDataArray
->getRowDescriptions().getLength() ));
601 if ( _aPlotBy
.hasValue() )
609 sal_Int32 nRows
= aSingleRangeAddress
.EndRow
- aSingleRangeAddress
.StartRow
;
610 sal_Int32 nCols
= aSingleRangeAddress
.EndColumn
- aSingleRangeAddress
.StartColumn
;
611 // AutoDetect emulation
613 setPlotBy( xlColumns
);
614 else if ( nRows
<= nCols
)
618 catch (const uno::Exception
&)
620 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED
), OUString() );
624 uno::Sequence
< OUString
>
625 ScVbaChart::getDefaultSeriesDescriptions( sal_Int32 _nCount
)
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
;
634 ScVbaChart::setDefaultChartType()
636 setChartType( xlColumnClustered
);
640 ScVbaChart::setPlotBy( ::sal_Int32 _nPlotBy
)
644 if ( !mxDiagramPropertySet
.is() )
645 setDefaultChartType();
649 mxDiagramPropertySet
->setPropertyValue( DATAROWSOURCE
, uno::Any( chart::ChartDataRowSource_ROWS
) );
652 mxDiagramPropertySet
->setPropertyValue( DATAROWSOURCE
, uno::Any( chart::ChartDataRowSource_COLUMNS
) );
655 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED
), OUString() );
658 catch (const uno::Exception
&)
660 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED
), OUString() );
665 ScVbaChart::getPlotBy( )
669 chart::ChartDataRowSource aChartDataRowSource
;
670 mxDiagramPropertySet
->getPropertyValue(DATAROWSOURCE
) >>= aChartDataRowSource
;
671 if (aChartDataRowSource
== chart::ChartDataRowSource_COLUMNS
)
680 catch (const uno::Exception
&)
682 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED
), OUString() );
687 ScVbaChart::setDiagram( const OUString
& _sDiagramType
)
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
);
696 catch ( const uno::Exception
& )
698 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED
), OUString() );
702 // #TODO find out why we have Location/getLocation? there is afaik no
703 // Location property, just a Location function for the Chart object
705 ScVbaChart::Location()
707 return getLocation();
711 ScVbaChart::getLocation()
717 ScVbaChart::setLocation( ::sal_Int32
/*where*/, const css::uno::Any
& /*Name*/ )
719 // Helper api just stubs out the code <shrug>
720 // #TODO come back and make sense out of this
721 // String sheetName = null;
723 // if ((name != null) && name instanceof String) {
724 // sheetName = (String) name;
726 // XSpreadsheetDocument xShDoc = (XSpreadsheetDocument) UnoRuntime.queryInterface( XSpreadsheetDocument.class,getXModel() );
727 // com.sun.star.sheet.XSpreadsheets xSheets = xShDoc.Sheets();
730 // case ClLocationType.clLocationAsObject_value: //{
732 // if (sheetName == null) {
733 // DebugHelper.writeInfo("Can't embed in Chart without knowing SheetName");
738 // Any any = (Any) xSheets.getByName(sheetName);
739 // chartSheet = (XSpreadsheet) any.getObject();
741 // // chartSheet = (XSpreadsheet) xSheets.getByName( sheetName );
742 // } catch (NoSuchElementException e) {
743 // // TODO Auto-generated catch block
744 // e.printStackTrace();
747 // } catch (WrappedTargetException e) {
748 // // TODO Auto-generated catch block
749 // e.printStackTrace();
752 // } catch (java.lang.Exception e) {
753 // e.printStackTrace();
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);
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...
769 // XIndexAccess xSheetIA = (XIndexAccess) UnoRuntime.queryInterface( XIndexAccess.class, xSheets);
771 // short newSheetNum = (short) (xSheetIA.getCount() + 1);
773 // if (sheetName == null){
774 // sheetName = "ChartSheet " + newSheetNum; // Why not?
776 // // DPK TODO : Probably should use Sheets to create this!
777 // xSheets.insertNewByName(sheetName, newSheetNum);
781 // (XSpreadsheet) xSheets.getByName(sheetName);
782 // } catch (NoSuchElementException e) {
783 // // TODO Auto-generated catch block
784 // e.printStackTrace();
787 // } catch (WrappedTargetException e) {
788 // // TODO Auto-generated catch block
789 // e.printStackTrace();
798 // // Last thing should be a call to createChartForReal(), one of them
799 // // should succeed.
800 // createChartForReal();
805 ScVbaChart::getHasTitle( )
807 bool bHasTitle
= false;
810 mxChartPropertySet
->getPropertyValue(HASMAINTITLE
) >>= bHasTitle
;
812 catch (const uno::Exception
&)
814 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED
), OUString() );
820 ScVbaChart::setHasTitle( sal_Bool bTitle
)
824 mxChartPropertySet
->setPropertyValue(HASMAINTITLE
, uno::Any( bTitle
));
826 catch (const uno::Exception
&)
828 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED
), OUString() );
834 ScVbaChart::getHasLegend( )
836 bool bHasLegend
= false;
839 mxChartPropertySet
->getPropertyValue(HASLEGEND
) >>= bHasLegend
;
841 catch (const uno::Exception
&)
843 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED
), OUString() );
849 ScVbaChart::setHasLegend( sal_Bool bLegend
)
853 mxChartPropertySet
->setPropertyValue(HASLEGEND
, uno::Any(bLegend
));
855 catch (const uno::Exception
&)
857 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED
), OUString() );
861 uno::Reference
< excel::XChartTitle
> SAL_CALL
862 ScVbaChart::getChartTitle( )
864 uno::Reference
< drawing::XShape
> xTitleShape
= mxChartDocument
->getTitle();
865 // #TODO check parent
866 return new ScVbaChartTitle(this, mxContext
, xTitleShape
);
870 ScVbaChart::Axes( const uno::Any
& Type
, const uno::Any
& AxisGroup
)
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
);
881 // #TODO perhaps provide limited Debughelper functionality
883 mxDiagramPropertySet
->getPropertyValue(DIM3D
) >>= is3d
;
888 ScVbaChart::getStackedType( sal_Int32 _nStacked
, sal_Int32 _n100PercentStacked
, sal_Int32 _nUnStacked
)
890 // #TODO perhaps provide limited Debughelper functionality
893 if (is100PercentStacked())
894 return _n100PercentStacked
;
903 ScVbaChart::isStacked()
905 // #TODO perhaps provide limited Debughelper functionality
906 bool bStacked
= false;
907 mxDiagramPropertySet
->getPropertyValue(STACKED
) >>= bStacked
;
912 ScVbaChart::is100PercentStacked()
914 // #TODO perhaps provide limited Debughelper functionality
915 bool b100Percent
= false;
916 mxDiagramPropertySet
->getPropertyValue(PERCENT
) >>= b100Percent
;
921 ScVbaChart::getSolidType(sal_Int32 _nDeep
, sal_Int32 _nVertiStacked
, sal_Int32 _nVerti100PercentStacked
, sal_Int32 _nVertiUnStacked
, sal_Int32 _nHoriStacked
, sal_Int32 _nHori100PercentStacked
, sal_Int32 _nHoriUnStacked
)
925 bool bIsVertical
= true;
926 mxDiagramPropertySet
->getPropertyValue(VERTICAL
) >>= bIsVertical
;
927 bool bIsDeep
= false;
928 mxDiagramPropertySet
->getPropertyValue(DEEP
) >>= bIsDeep
;
938 return getStackedType(_nVertiStacked
, _nVerti100PercentStacked
, _nVertiUnStacked
);
942 return getStackedType(_nHoriStacked
, _nHori100PercentStacked
, _nHoriUnStacked
);
946 catch (const uno::Exception
&)
948 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED
), OUString() );
953 ScVbaChart::getStockUpDownValue(sal_Int32 _nUpDown
, sal_Int32 _nNotUpDown
)
957 bool bUpDown
= false;
958 mxDiagramPropertySet
->getPropertyValue(UPDOWN
) >>= bUpDown
;
968 catch (const uno::Exception
&)
970 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED
), OUString() );
975 ScVbaChart::hasMarkers()
977 bool bHasMarkers
= false;
981 mxDiagramPropertySet
->getPropertyValue(SYMBOLTYPE
) >>= nSymbol
;
982 bHasMarkers
= nSymbol
!= chart::ChartSymbolType::NONE
;
984 catch (const uno::Exception
&)
986 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED
), OUString() );
992 ScVbaChart::getMarkerType(sal_Int32 _nWithMarkers
, sal_Int32 _nWithoutMarkers
)
995 return _nWithMarkers
;
996 return _nWithoutMarkers
;
1000 ScVbaChart::assignDiagramAttributes()
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
);
1009 uno::Reference
< beans::XPropertySet
>
1010 ScVbaChart::getAxisPropertySet(sal_Int32 _nAxisType
, sal_Int32 _nAxisGroup
)
1012 assignDiagramAttributes();
1013 uno::Reference
< beans::XPropertySet
> xAxisProps
;
1017 if (_nAxisGroup
== xlPrimary
)
1019 xAxisProps
= xAxisXSupplier
->getXAxis();
1021 else if (_nAxisGroup
== xlSecondary
)
1023 xAxisProps
= xTwoAxisXSupplier
->getSecondaryXAxis();
1027 xAxisProps
= xAxisZSupplier
->getZAxis();
1030 if (_nAxisGroup
== xlPrimary
)
1031 xAxisProps
= xAxisYSupplier
->getYAxis();
1032 else if (_nAxisGroup
== xlSecondary
)
1033 xAxisProps
= xTwoAxisYSupplier
->getSecondaryYAxis();
1042 ScVbaChart::getServiceImplName()
1044 return u
"ScVbaChart"_ustr
;
1047 uno::Sequence
< OUString
>
1048 ScVbaChart::getServiceNames()
1050 static uno::Sequence
< OUString
> const aServiceNames
1052 u
"ooo.vba.excel.Chart"_ustr
1054 return aServiceNames
;
1057 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */