1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vbachart.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "vbachart.hxx"
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
33 #include <com/sun/star/chart/XAxisXSupplier.hpp>
34 #include <com/sun/star/chart/XAxisYSupplier.hpp>
35 #include <com/sun/star/chart/XAxisZSupplier.hpp>
36 #include <com/sun/star/chart/XTwoAxisXSupplier.hpp>
37 #include <com/sun/star/chart/XTwoAxisYSupplier.hpp>
38 #include <com/sun/star/chart/XChartDataArray.hpp>
39 #include <com/sun/star/chart/ChartSymbolType.hpp>
40 #include <com/sun/star/chart/ChartSolidType.hpp>
41 #include <com/sun/star/chart/ChartDataRowSource.hpp>
42 #include <com/sun/star/chart/ChartDataCaption.hpp>
43 #include <ooo/vba/excel/XlChartType.hpp>
44 #include <ooo/vba/excel/XlRowCol.hpp>
45 #include <ooo/vba/excel/XlAxisType.hpp>
46 #include <ooo/vba/excel/XlAxisGroup.hpp>
48 #include <basic/sberrors.hxx>
49 #include "vbachartobject.hxx"
50 #include "vbarange.hxx"
51 #include "vbacharttitle.hxx"
52 #include "vbaaxes.hxx"
54 using namespace ::com::sun::star
;
55 using namespace ::ooo::vba
;
56 using namespace ::ooo::vba::excel::XlChartType
;
57 using namespace ::ooo::vba::excel::XlRowCol
;
58 using namespace ::ooo::vba::excel::XlAxisType
;
59 using namespace ::ooo::vba::excel::XlAxisGroup
;
61 const rtl::OUString
CHART_NAME( RTL_CONSTASCII_USTRINGPARAM("Name") );
62 // #TODO move this constant to vbaseries.[ch]xx ( when it exists )
63 const rtl::OUString
DEFAULTSERIESPREFIX( RTL_CONSTASCII_USTRINGPARAM("Series") );
64 const rtl::OUString
DATAROWSOURCE( RTL_CONSTASCII_USTRINGPARAM("DataRowSource") );
65 const rtl::OUString
UPDOWN( RTL_CONSTASCII_USTRINGPARAM("UpDown") );
66 const rtl::OUString
VOLUME( RTL_CONSTASCII_USTRINGPARAM("Volume") );
67 const rtl::OUString
LINES( RTL_CONSTASCII_USTRINGPARAM("Lines") );
68 const rtl::OUString
SPLINETYPE( RTL_CONSTASCII_USTRINGPARAM("SplineType") );
69 const rtl::OUString
SYMBOLTYPE( RTL_CONSTASCII_USTRINGPARAM("SymbolType") );
70 const rtl::OUString
DEEP( RTL_CONSTASCII_USTRINGPARAM("Deep") );
71 const rtl::OUString
SOLIDTYPE( RTL_CONSTASCII_USTRINGPARAM("SolidType") );
72 const rtl::OUString
VERTICAL( RTL_CONSTASCII_USTRINGPARAM("Vertical") );
73 const rtl::OUString
PERCENT( RTL_CONSTASCII_USTRINGPARAM("Percent") );
74 const rtl::OUString
STACKED( RTL_CONSTASCII_USTRINGPARAM("Stacked") );
75 const rtl::OUString
DIM3D( RTL_CONSTASCII_USTRINGPARAM("Dim3D") );
76 const rtl::OUString
HASMAINTITLE( RTL_CONSTASCII_USTRINGPARAM("HasMainTitle") );
77 const rtl::OUString
HASLEGEND( RTL_CONSTASCII_USTRINGPARAM("HasLegend") );
78 const rtl::OUString
DATACAPTION( RTL_CONSTASCII_USTRINGPARAM("DataCaption") );
80 ScVbaChart::ScVbaChart( const css::uno::Reference
< ov::XHelperInterface
>& _xParent
, const css::uno::Reference
< css::uno::XComponentContext
>& _xContext
, const css::uno::Reference
< css::lang::XComponent
>& _xChartComponent
, const css::uno::Reference
< css::table::XTableChart
>& _xTableChart
) : ChartImpl_BASE( _xParent
, _xContext
), mxTableChart( _xTableChart
)
82 mxChartDocument
.set( _xChartComponent
, uno::UNO_QUERY_THROW
) ;
83 // #TODO is is possible that the XPropertySet interface is not set
84 // code in setPlotBy seems to indicate that this is possible? but
85 // additionally there is no check in most of the places where it is used
86 // ( and therefore could possibly be NULL )
87 // I'm going to let it throw for the moment ( npower )
88 mxDiagramPropertySet
.set( mxChartDocument
->getDiagram(), uno::UNO_QUERY_THROW
);
89 mxChartPropertySet
.set( _xChartComponent
, uno::UNO_QUERY_THROW
) ;
92 ::rtl::OUString SAL_CALL
93 ScVbaChart::getName() throw (css::uno::RuntimeException
)
96 uno::Reference
< beans::XPropertySet
> xProps( mxChartDocument
, uno::UNO_QUERY_THROW
);
99 xProps
->getPropertyValue( CHART_NAME
) >>= sName
;
101 catch( uno::Exception e
) // swallow exceptions
108 ScVbaChart::SeriesCollection(const uno::Any
&) throw (uno::RuntimeException
)
114 ScVbaChart::getChartType() throw ( uno::RuntimeException
, script::BasicErrorException
)
116 sal_Int32 nChartType
= -1;
119 rtl::OUString sDiagramType
= mxChartDocument
->getDiagram()->getDiagramType();
120 if (sDiagramType
.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart.AreaDiagram" ))))
124 nChartType
= getStackedType(xl3DAreaStacked
, xl3DAreaStacked100
, xl3DArea
);
128 nChartType
= getStackedType(xlAreaStacked
, xlAreaStacked100
, xlArea
);
131 else if (sDiagramType
.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.PieDiagram"))))
134 nChartType
= xl3DPie
;
136 nChartType
= xlPie
; /*TODO XlChartType xlPieExploded, XlChartType xlPieOfPie */
138 else if (sDiagramType
.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.BarDiagram"))))
140 sal_Int32 nSolidType
= chart::ChartSolidType::RECTANGULAR_SOLID
;
141 if (mxDiagramPropertySet
->getPropertySetInfo()->hasPropertyByName(SOLIDTYPE
))
142 { //in 2D diagrams 'SolidType' may not be set
144 mxDiagramPropertySet
->getPropertyValue(SOLIDTYPE
) >>= nSolidType
;
148 case chart::ChartSolidType::CONE
:
149 nChartType
= getSolidType(xlConeCol
, xlConeColStacked
, xlConeColStacked100
, xlConeColClustered
, xlConeBarStacked
, xlConeBarStacked100
, xlConeBarClustered
);
151 case chart::ChartSolidType::CYLINDER
:
152 nChartType
= getSolidType(xlCylinderCol
, xlCylinderColStacked
, xlCylinderColStacked100
, xlCylinderColClustered
, xlCylinderBarStacked
, xlCylinderBarStacked100
, xlCylinderBarClustered
);
154 case chart::ChartSolidType::PYRAMID
:
155 nChartType
= getSolidType(xlPyramidCol
, xlPyramidColStacked
, xlPyramidColStacked100
, xlPyramidColClustered
, xlPyramidBarStacked
, xlPyramidBarStacked100
, xlPyramidBarClustered
);
157 default: // RECTANGULAR_SOLID
160 nChartType
= getSolidType(xl3DColumn
, xl3DColumnStacked
, xl3DColumnStacked100
, xl3DColumnClustered
, xl3DBarStacked
, xl3DBarStacked100
, xl3DBarClustered
);
164 nChartType
= getSolidType(xlColumnClustered
, xlColumnStacked
, xlColumnStacked100
, xlColumnClustered
, xlBarStacked
, xlBarStacked100
, xlBarClustered
);
169 else if (sDiagramType
.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.StockDiagram"))))
171 sal_Bool bVolume
= sal_False
;
172 mxDiagramPropertySet
->getPropertyValue(VOLUME
) >>= bVolume
;
175 nChartType
= getStockUpDownValue(xlStockVOHLC
, xlStockVHLC
);
179 nChartType
= getStockUpDownValue(xlStockOHLC
, xlStockHLC
);
182 else if (sDiagramType
.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.XYDiagram"))))
184 sal_Bool bHasLines
= sal_False
;
185 mxDiagramPropertySet
->getPropertyValue(LINES
) >>= bHasLines
;
186 sal_Int32 nSplineType
= 0;
187 mxDiagramPropertySet
->getPropertyValue(SPLINETYPE
) >>= nSplineType
;
188 if (nSplineType
== 1)
190 nChartType
= getMarkerType(xlXYScatterSmooth
, xlXYScatterSmoothNoMarkers
);
194 nChartType
= getMarkerType(xlXYScatterLines
, xlXYScatterLinesNoMarkers
);
198 nChartType
= xlXYScatter
;
201 else if (sDiagramType
.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.LineDiagram"))))
205 nChartType
= xl3DLine
;
207 else if (hasMarkers())
209 nChartType
= getStackedType(xlLineMarkersStacked
, xlLineMarkersStacked100
, xlLineMarkers
);
213 nChartType
= getStackedType(xlLineStacked
, xlLineStacked100
, xlLine
);
216 else if (sDiagramType
.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.DonutDiagram"))))
218 nChartType
= xlDoughnut
; // TODO DoughnutExploded ??
220 else if (sDiagramType
.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.NetDiagram"))))
222 nChartType
= getMarkerType(xlRadarMarkers
, xlRadar
);
225 catch (uno::Exception
& )
227 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString() );
233 ScVbaChart::setChartType( ::sal_Int32 _nChartType
) throw ( uno::RuntimeException
, script::BasicErrorException
)
239 case xlColumnClustered
:
240 case xlColumnStacked
:
241 case xlColumnStacked100
:
242 case xl3DColumnClustered
:
243 case xl3DColumnStacked
:
244 case xl3DColumnStacked100
:
248 case xlBarStacked100
:
249 case xl3DBarClustered
:
251 case xl3DBarStacked100
:
252 case xlConeColClustered
:
253 case xlConeColStacked
:
254 case xlConeColStacked100
:
255 case xlConeBarClustered
:
256 case xlConeBarStacked
:
257 case xlConeBarStacked100
:
259 case xlPyramidColClustered
:
260 case xlPyramidColStacked
:
261 case xlPyramidColStacked100
:
262 case xlPyramidBarClustered
:
263 case xlPyramidBarStacked
:
264 case xlPyramidBarStacked100
:
266 case xlCylinderColClustered
:
267 case xlCylinderColStacked
:
268 case xlCylinderColStacked100
:
269 case xlCylinderBarClustered
:
270 case xlCylinderBarStacked
:
271 case xlCylinderBarStacked100
:
273 case xlSurface
: // not possible
274 case xlSurfaceWireframe
:
275 case xlSurfaceTopView
:
276 case xlSurfaceTopViewWireframe
:
277 setDiagram( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.BarDiagram")));
282 case xlLineStacked100
:
284 case xlLineMarkersStacked
:
285 case xlLineMarkersStacked100
:
286 setDiagram( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.LineDiagram")));
291 case xlAreaStacked100
:
292 case xl3DAreaStacked
:
293 case xl3DAreaStacked100
:
294 setDiagram( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.AreaDiagram")) );
297 case xlDoughnutExploded
:
298 setDiagram( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.DonutDiagram") ) );
304 setDiagram( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.StockDiagram")));
305 mxDiagramPropertySet
->setPropertyValue( UPDOWN
, uno::makeAny(sal_Bool((_nChartType
== xlStockOHLC
) || (_nChartType
== xlStockVOHLC
))));
306 mxDiagramPropertySet
->setPropertyValue(VOLUME
, uno::makeAny(sal_Bool((_nChartType
== xlStockVHLC
) || (_nChartType
== xlStockVOHLC
))));
309 case xlPieOfPie
: // not possible
310 case xlPieExploded
: // SegmentOffset an ChartDataPointProperties ->am XDiagram abholen //wie macht Excel das?
311 case xl3DPieExploded
:
314 case xlBarOfPie
: // not possible (Zoom pie)
315 setDiagram( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.PieDiagram")));
321 setDiagram( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.NetDiagram")));
324 case xlBubble
: // not possible
325 case xlBubble3DEffect
: // not possible
326 case xlXYScatterLines
:
327 case xlXYScatterLinesNoMarkers
:
328 case xlXYScatterSmooth
:
329 case xlXYScatterSmoothNoMarkers
:
330 setDiagram( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.XYDiagram")));
334 case xlBubble
: // not possible
335 case xlBubble3DEffect
: // not possible
336 mxDiagramPropertySet
->setPropertyValue(LINES
, uno::makeAny( sal_False
));
338 case xlXYScatterLines
:
339 case xlXYScatterLinesNoMarkers
:
340 mxDiagramPropertySet
->setPropertyValue(LINES
, uno::makeAny( sal_True
));
342 case xlXYScatterSmooth
:
343 case xlXYScatterSmoothNoMarkers
:
344 mxDiagramPropertySet
->setPropertyValue(SPLINETYPE
, uno::makeAny( sal_Int32(1)));
351 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_CONVERSION
, rtl::OUString() );
357 case xlLineMarkersStacked
:
358 case xlLineMarkersStacked100
:
360 case xlXYScatterLines
:
361 case xlXYScatterSmooth
:
363 case xlBubble
: // not possible
364 case xlBubble3DEffect
: // not possible
365 mxDiagramPropertySet
->setPropertyValue(SYMBOLTYPE
, uno::makeAny( chart::ChartSymbolType::AUTO
));
368 if (mxDiagramPropertySet
->getPropertySetInfo()->hasPropertyByName(SYMBOLTYPE
))
370 mxDiagramPropertySet
->setPropertyValue(SYMBOLTYPE
, uno::makeAny(chart::ChartSymbolType::NONE
));
381 case xlSurface
: // not possible
382 case xlSurfaceWireframe
:
383 case xlSurfaceTopView
:
384 case xlSurfaceTopViewWireframe
:
385 mxDiagramPropertySet
->setPropertyValue(DEEP
,uno::makeAny( sal_True
));
388 if (mxDiagramPropertySet
->getPropertySetInfo()->hasPropertyByName(DEEP
))
390 mxDiagramPropertySet
->setPropertyValue(DEEP
, uno::makeAny( sal_False
));
398 case xlConeColClustered
:
399 case xlConeColStacked
:
400 case xlConeColStacked100
:
401 case xlConeBarClustered
:
402 case xlConeBarStacked
:
403 case xlConeBarStacked100
:
405 mxDiagramPropertySet
->setPropertyValue(SOLIDTYPE
, uno::makeAny(chart::ChartSolidType::CONE
));
407 case xlPyramidColClustered
:
408 case xlPyramidColStacked
:
409 case xlPyramidColStacked100
:
410 case xlPyramidBarClustered
:
411 case xlPyramidBarStacked
:
412 case xlPyramidBarStacked100
:
414 mxDiagramPropertySet
->setPropertyValue(SOLIDTYPE
, uno::makeAny(chart::ChartSolidType::PYRAMID
));
416 case xlCylinderColClustered
:
417 case xlCylinderColStacked
:
418 case xlCylinderColStacked100
:
419 case xlCylinderBarClustered
:
420 case xlCylinderBarStacked
:
421 case xlCylinderBarStacked100
:
423 mxDiagramPropertySet
->setPropertyValue(SOLIDTYPE
, uno::makeAny(chart::ChartSolidType::CYLINDER
));
426 if (mxDiagramPropertySet
->getPropertySetInfo()->hasPropertyByName(SOLIDTYPE
))
428 mxDiagramPropertySet
->setPropertyValue(SOLIDTYPE
, uno::makeAny(chart::ChartSolidType::RECTANGULAR_SOLID
));
433 switch ( _nChartType
)
436 case xlConeColClustered
:
437 case xlConeColStacked
:
438 case xlConeColStacked100
:
439 case xlPyramidColClustered
:
440 case xlPyramidColStacked
:
441 case xlPyramidColStacked100
:
442 case xlCylinderColClustered
:
443 case xlCylinderColStacked
:
444 case xlCylinderColStacked100
:
445 case xlColumnClustered
:
446 case xlColumnStacked
:
447 case xlColumnStacked100
:
448 case xl3DColumnClustered
:
449 case xl3DColumnStacked
:
450 case xl3DColumnStacked100
:
451 case xlSurface
: // not possible
452 case xlSurfaceWireframe
:
453 case xlSurfaceTopView
:
454 case xlSurfaceTopViewWireframe
:
455 mxDiagramPropertySet
->setPropertyValue(VERTICAL
, uno::makeAny( sal_True
));
458 if (mxDiagramPropertySet
->getPropertySetInfo()->hasPropertyByName(VERTICAL
))
460 mxDiagramPropertySet
->setPropertyValue(VERTICAL
, uno::makeAny(sal_False
));
467 case xlColumnStacked
:
468 case xl3DColumnStacked
:
472 case xlLineMarkersStacked
:
474 case xl3DAreaStacked
:
475 case xlCylinderColStacked
:
476 case xlCylinderBarStacked
:
477 case xlConeColStacked
:
478 case xlConeBarStacked
:
479 case xlPyramidColStacked
:
480 case xlPyramidBarStacked
:
481 mxDiagramPropertySet
->setPropertyValue(PERCENT
, uno::makeAny( sal_False
));
482 mxDiagramPropertySet
->setPropertyValue(STACKED
, uno::makeAny( sal_True
));
484 case xlPyramidColStacked100
:
485 case xlPyramidBarStacked100
:
486 case xlConeColStacked100
:
487 case xlConeBarStacked100
:
488 case xlCylinderBarStacked100
:
489 case xlCylinderColStacked100
:
490 case xl3DAreaStacked100
:
491 case xlLineMarkersStacked100
:
492 case xlAreaStacked100
:
493 case xlLineStacked100
:
494 case xl3DBarStacked100
:
495 case xlBarStacked100
:
496 case xl3DColumnStacked100
:
497 case xlColumnStacked100
:
498 mxDiagramPropertySet
->setPropertyValue(STACKED
, uno::makeAny( sal_True
));
499 mxDiagramPropertySet
->setPropertyValue(PERCENT
, uno::makeAny( sal_True
));
502 mxDiagramPropertySet
->setPropertyValue(PERCENT
, uno::makeAny( sal_False
));
503 mxDiagramPropertySet
->setPropertyValue(STACKED
, uno::makeAny( sal_False
));
509 case xl3DAreaStacked
:
510 case xl3DAreaStacked100
:
511 case xl3DBarClustered
:
513 case xl3DBarStacked100
:
515 case xl3DColumnClustered
:
516 case xl3DColumnStacked
:
517 case xl3DColumnStacked100
:
520 case xl3DPieExploded
:
521 case xlConeColClustered
:
522 case xlConeColStacked
:
523 case xlConeColStacked100
:
524 case xlConeBarClustered
:
525 case xlConeBarStacked
:
526 case xlConeBarStacked100
:
528 case xlPyramidColClustered
:
529 case xlPyramidColStacked
:
530 case xlPyramidColStacked100
:
531 case xlPyramidBarClustered
:
532 case xlPyramidBarStacked
:
533 case xlPyramidBarStacked100
:
535 case xlCylinderColClustered
:
536 case xlCylinderColStacked
:
537 case xlCylinderColStacked100
:
538 case xlCylinderBarClustered
:
539 case xlCylinderBarStacked
:
540 case xlCylinderBarStacked100
:
542 mxDiagramPropertySet
->setPropertyValue(DIM3D
, uno::makeAny( sal_True
));
545 if (mxDiagramPropertySet
->getPropertySetInfo()->hasPropertyByName(DIM3D
))
547 mxDiagramPropertySet
->setPropertyValue(DIM3D
, uno::makeAny( sal_False
));
552 catch ( uno::Exception
& )
554 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString() );
559 ScVbaChart::Activate() throw (script::BasicErrorException
, uno::RuntimeException
)
561 // #TODO how are Chart sheets handled ( I know we don't even consider
562 // them in the worksheets/sheets collections ), but.....???
563 // note: in vba for excel the parent of a Chart sheet is a workbook,
564 // e.g. 'ThisWorkbook'
565 uno::Reference
< XHelperInterface
> xParent( getParent() );
566 ScVbaChartObject
* pChartObj
= static_cast< ScVbaChartObject
* >( xParent
.get() );
568 pChartObj
->Activate();
570 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "no ChartObject as parent" ) ) );
574 ScVbaChart::setSourceData( const css::uno::Reference
< ::ooo::vba::excel::XRange
>& _xCalcRange
, const css::uno::Any
& _aPlotBy
) throw (css::script::BasicErrorException
, css::uno::RuntimeException
)
578 uno::Sequence
< table::CellRangeAddress
> mRangeAddresses(1);
579 table::CellRangeAddress mSingleRangeAddress
;
581 uno::Reference
< sheet::XCellRangeAddressable
> xAddressable( _xCalcRange
->getCellRange(), uno::UNO_QUERY_THROW
);
582 mSingleRangeAddress
= xAddressable
->getRangeAddress();
584 mRangeAddresses
[0] = mSingleRangeAddress
;
586 mxTableChart
->setRanges(mRangeAddresses
);
588 sal_Bool bsetRowHeaders
= sal_False
;
589 sal_Bool bsetColumnHeaders
= sal_False
;
591 ScVbaRange
* pRange
= static_cast< ScVbaRange
* >( _xCalcRange
.get() );
594 ScDocument
* pDoc
= pRange
->getScDocument();
597 bsetRowHeaders
= pDoc
->HasRowHeader( static_cast< SCCOL
>( mSingleRangeAddress
.StartColumn
), static_cast< SCROW
>( mSingleRangeAddress
.StartRow
), static_cast< SCCOL
>( mSingleRangeAddress
.EndColumn
), static_cast< SCROW
>( mSingleRangeAddress
.EndRow
), static_cast< SCTAB
>( mSingleRangeAddress
.Sheet
) );;
598 bsetColumnHeaders
= pDoc
->HasColHeader( static_cast< SCCOL
>( mSingleRangeAddress
.StartColumn
), static_cast< SCROW
>( mSingleRangeAddress
.StartRow
), static_cast< SCCOL
>( mSingleRangeAddress
.EndColumn
), static_cast< SCROW
>( mSingleRangeAddress
.EndRow
), static_cast< SCTAB
>( mSingleRangeAddress
.Sheet
));
602 mxTableChart
->setHasRowHeaders(bsetRowHeaders
);
603 mxTableChart
->setHasColumnHeaders(bsetColumnHeaders
);
605 if ((!bsetColumnHeaders
) || (!bsetRowHeaders
))
607 uno::Reference
< chart::XChartDataArray
> xChartDataArray( mxChartDocument
->getData(), uno::UNO_QUERY_THROW
);
608 if (!bsetColumnHeaders
)
610 xChartDataArray
->setColumnDescriptions( getDefaultSeriesDescriptions(xChartDataArray
->getColumnDescriptions().getLength() ));
614 xChartDataArray
->setRowDescriptions(getDefaultSeriesDescriptions(xChartDataArray
->getRowDescriptions().getLength() ));
618 if ( _aPlotBy
.hasValue() )
626 sal_Int32 nRows
= mSingleRangeAddress
.EndRow
- mSingleRangeAddress
.StartRow
;
627 sal_Int32 nCols
= mSingleRangeAddress
.EndColumn
- mSingleRangeAddress
.StartColumn
;
628 // AutoDetect emulation
630 setPlotBy( xlColumns
);
631 else if ( nRows
<= nCols
)
635 catch (uno::Exception
& )
637 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString() );
641 uno::Sequence
< rtl::OUString
>
642 ScVbaChart::getDefaultSeriesDescriptions( sal_Int32 _nCount
)
644 uno::Sequence
< rtl::OUString
> sDescriptions ( _nCount
);
645 sal_Int32 nLen
= sDescriptions
.getLength();
646 for (sal_Int32 i
= 0; i
< nLen
; i
++)
648 sDescriptions
[i
] = DEFAULTSERIESPREFIX
+ rtl::OUString::valueOf(i
+1);
650 return sDescriptions
;
654 ScVbaChart::setDefaultChartType() throw ( script::BasicErrorException
)
656 setChartType( xlColumnClustered
);
660 ScVbaChart::setPlotBy( ::sal_Int32 _nPlotBy
) throw (css::script::BasicErrorException
, css::uno::RuntimeException
)
664 if ( !mxDiagramPropertySet
.is() )
665 setDefaultChartType();
669 mxDiagramPropertySet
->setPropertyValue( DATAROWSOURCE
, uno::makeAny( chart::ChartDataRowSource_ROWS
) );
672 mxDiagramPropertySet
->setPropertyValue( DATAROWSOURCE
, uno::makeAny( chart::ChartDataRowSource_COLUMNS
) );
675 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString() );
678 catch (uno::Exception
& )
680 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString() );
685 ScVbaChart::getPlotBy( ) throw (script::BasicErrorException
, uno::RuntimeException
)
689 chart::ChartDataRowSource aChartDataRowSource
;
690 mxDiagramPropertySet
->getPropertyValue(DATAROWSOURCE
) >>= aChartDataRowSource
;
691 if (aChartDataRowSource
== chart::ChartDataRowSource_COLUMNS
)
700 catch (uno::Exception
& )
702 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString() );
707 ScVbaChart::setDiagram( const rtl::OUString
& _sDiagramType
) throw( script::BasicErrorException
)
711 uno::Reference
< lang::XMultiServiceFactory
> xMSF( mxChartDocument
, uno::UNO_QUERY_THROW
);
712 uno::Reference
< chart::XDiagram
> xDiagram( xMSF
->createInstance( _sDiagramType
), uno::UNO_QUERY_THROW
);
713 mxChartDocument
->setDiagram( xDiagram
);
714 mxDiagramPropertySet
.set( xDiagram
, uno::UNO_QUERY_THROW
);
716 catch ( uno::Exception
& )
718 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString() );
722 // #TODO find out why we have Location/getLocation ? there is afaiks no
723 // Location property, just a Location function for the Chart object
725 ScVbaChart::Location() throw (css::script::BasicErrorException
, css::uno::RuntimeException
)
727 return getLocation();
731 ScVbaChart::getLocation() throw (css::script::BasicErrorException
, css::uno::RuntimeException
)
737 ScVbaChart::setLocation( ::sal_Int32
/*where*/, const css::uno::Any
& /*Name*/ ) throw (script::BasicErrorException
, uno::RuntimeException
)
739 // Helper api just stubs out the code <shrug>
740 // #TODO come back and make sense out of this
741 // String sheetName = null;
743 // if ((name != null) && name instanceof String) {
744 // sheetName = (String) name;
746 // XSpreadsheetDocument xShDoc = (XSpreadsheetDocument) UnoRuntime.queryInterface( XSpreadsheetDocument.class,getXModel() );
747 // com.sun.star.sheet.XSpreadsheets xSheets = xShDoc.Sheets();
750 // case ClLocationType.clLocationAsObject_value: //{
752 // if (sheetName == null) {
753 // DebugHelper.writeInfo("Can't embed in Chart without knowing SheetName");
758 // Any any = (Any) xSheets.getByName(sheetName);
759 // chartSheet = (XSpreadsheet) any.getObject();
761 // // chartSheet = (XSpreadsheet) xSheets.getByName( sheetName );
762 // } catch (NoSuchElementException e) {
763 // // TODO Auto-generated catch block
764 // e.printStackTrace();
767 // } catch (WrappedTargetException e) {
768 // // TODO Auto-generated catch block
769 // e.printStackTrace();
772 // } catch (java.lang.Exception e) {
773 // e.printStackTrace();
776 // XTableChartsSupplier xTCS = (XTableChartsSupplier) UnoRuntime.queryInterface( XTableChartsSupplier.class, chartSheet);
777 // XTableCharts xTableCharts = xTCS.getCharts();
778 // XIndexAccess xIA = (XIndexAccess) UnoRuntime.queryInterface( XIndexAccess.class, xTableCharts);
779 // int numCharts = xIA.getCount();
780 // chartName = "Chart " + (numCharts + 1);
785 // case ClLocationType.clLocationAsNewSheet_value:
786 // case ClLocationType.clLocationAutomatic_value:default: //{
787 // chartName = "Chart 1"; // Since it's a new sheet, it's the first on it...
789 // XIndexAccess xSheetIA = (XIndexAccess) UnoRuntime.queryInterface( XIndexAccess.class, xSheets);
791 // short newSheetNum = (short) (xSheetIA.getCount() + 1);
793 // if (sheetName == null){
794 // sheetName = "ChartSheet " + newSheetNum; // Why not?
796 // // DPK TODO : Probably should use Sheets to create this!
797 // xSheets.insertNewByName(sheetName, newSheetNum);
801 // (XSpreadsheet) xSheets.getByName(sheetName);
802 // } catch (NoSuchElementException e) {
803 // // TODO Auto-generated catch block
804 // e.printStackTrace();
807 // } catch (WrappedTargetException e) {
808 // // TODO Auto-generated catch block
809 // e.printStackTrace();
818 // // Last thing should be a call to createChartForReal(), one of them
819 // // should succeed.
820 // createChartForReal();
825 ScVbaChart::getHasTitle( ) throw (script::BasicErrorException
, uno::RuntimeException
)
827 sal_Bool bHasTitle
= sal_False
;
830 mxChartPropertySet
->getPropertyValue(HASMAINTITLE
) >>= bHasTitle
;
832 catch (uno::Exception
& )
834 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString() );
840 ScVbaChart::setHasTitle( ::sal_Bool bTitle
) throw (script::BasicErrorException
, uno::RuntimeException
)
844 mxChartPropertySet
->setPropertyValue(HASMAINTITLE
, uno::makeAny( bTitle
));
846 catch (uno::Exception
& )
848 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString() );
854 ScVbaChart::getHasLegend( ) throw (script::BasicErrorException
, uno::RuntimeException
)
856 sal_Bool bHasLegend
= sal_False
;
859 mxChartPropertySet
->getPropertyValue(HASLEGEND
) >>= bHasLegend
;
861 catch (uno::Exception
& )
863 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString() );
869 ScVbaChart::setHasLegend( ::sal_Bool bLegend
) throw (script::BasicErrorException
, uno::RuntimeException
)
873 mxChartPropertySet
->setPropertyValue(HASLEGEND
, uno::makeAny(bLegend
));
875 catch (uno::Exception
& )
877 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString() );
881 uno::Reference
< excel::XChartTitle
> SAL_CALL
882 ScVbaChart::getChartTitle( ) throw (script::BasicErrorException
, uno::RuntimeException
)
884 uno::Reference
< drawing::XShape
> xTitleShape
= mxChartDocument
->getTitle();
885 // #TODO check parent
886 return new ScVbaChartTitle(this, mxContext
, xTitleShape
);
890 ScVbaChart::Axes( const uno::Any
& Type
, const uno::Any
& AxisGroup
) throw (script::BasicErrorException
, uno::RuntimeException
)
892 // mmm chart probably is the parent, #TODO check parent
893 uno::Reference
< excel::XAxes
> xAxes
= new ScVbaAxes( this, mxContext
, this );
894 if ( !Type
.hasValue() )
895 return uno::makeAny( xAxes
);
896 return xAxes
->Item( Type
, AxisGroup
);
899 ScVbaChart::is3D() throw ( uno::RuntimeException
)
901 // #TODO perhaps provide limited Debughelper functionality
902 sal_Bool is3d
= sal_False
;
903 mxDiagramPropertySet
->getPropertyValue(DIM3D
) >>= is3d
;
908 ScVbaChart::getStackedType( sal_Int32 _nStacked
, sal_Int32 _n100PercentStacked
, sal_Int32 _nUnStacked
) throw ( uno::RuntimeException
)
910 // #TODO perhaps provide limited Debughelper functionality
913 if (is100PercentStacked())
914 return _n100PercentStacked
;
923 ScVbaChart::isStacked() throw ( uno::RuntimeException
)
925 // #TODO perhaps provide limited Debughelper functionality
926 sal_Bool bStacked
= sal_False
;
927 mxDiagramPropertySet
->getPropertyValue(STACKED
) >>= bStacked
;
932 ScVbaChart::is100PercentStacked() throw ( uno::RuntimeException
)
934 // #TODO perhaps provide limited Debughelper functionality
935 sal_Bool b100Percent
= sal_False
;
936 mxDiagramPropertySet
->getPropertyValue(PERCENT
) >>= b100Percent
;
941 ScVbaChart::getSolidType(sal_Int32 _nDeep
, sal_Int32 _nVertiStacked
, sal_Int32 _nVerti100PercentStacked
, sal_Int32 _nVertiUnStacked
, sal_Int32 _nHoriStacked
, sal_Int32 _nHori100PercentStacked
, sal_Int32 _nHoriUnStacked
) throw ( script::BasicErrorException
)
943 sal_Bool bIsVertical
= true;
946 mxDiagramPropertySet
->getPropertyValue(VERTICAL
) >>= bIsVertical
;
947 sal_Bool bIsDeep
= false;
948 mxDiagramPropertySet
->getPropertyValue(DEEP
) >>= bIsDeep
;
958 return getStackedType(_nVertiStacked
, _nVerti100PercentStacked
, _nVertiUnStacked
);
962 return getStackedType(_nHoriStacked
, _nHori100PercentStacked
, _nHoriUnStacked
);
966 catch (uno::Exception
& )
968 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString() );
974 ScVbaChart::getStockUpDownValue(sal_Int32 _nUpDown
, sal_Int32 _nNotUpDown
) throw (script::BasicErrorException
)
976 sal_Bool bUpDown
= sal_False
;
979 mxDiagramPropertySet
->getPropertyValue(UPDOWN
) >>= bUpDown
;
989 catch (uno::Exception
& )
991 rtl::OUString aTemp
; // temporary needed for g++ 3.3.5
992 script::BasicErrorException( aTemp
, uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString() );
998 ScVbaChart::hasMarkers() throw ( script::BasicErrorException
)
1000 bool bHasMarkers
= false;
1003 sal_Int32 nSymbol
=0;
1004 mxDiagramPropertySet
->getPropertyValue(SYMBOLTYPE
) >>= nSymbol
;
1005 bHasMarkers
= nSymbol
!= chart::ChartSymbolType::NONE
;
1007 catch ( uno::Exception
& )
1009 rtl::OUString aTemp
; // temporary needed for g++ 3.3.5
1010 script::BasicErrorException( aTemp
, uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString() );
1016 ScVbaChart::getMarkerType(sal_Int32 _nWithMarkers
, sal_Int32 _nWithoutMarkers
) throw ( script::BasicErrorException
)
1019 return _nWithMarkers
;
1020 return _nWithoutMarkers
;
1024 ScVbaChart::assignDiagramAttributes()
1026 xAxisXSupplier
.set( mxDiagramPropertySet
, uno::UNO_QUERY_THROW
);
1027 xAxisYSupplier
.set( mxDiagramPropertySet
, uno::UNO_QUERY_THROW
);
1028 xAxisZSupplier
.set( mxDiagramPropertySet
, uno::UNO_QUERY_THROW
);
1029 xTwoAxisXSupplier
.set( mxDiagramPropertySet
, uno::UNO_QUERY_THROW
);
1030 xTwoAxisYSupplier
.set( mxDiagramPropertySet
, uno::UNO_QUERY_THROW
);
1034 ScVbaChart::isSeriesIndexValid(sal_Int32 _seriesindex
) throw( script::BasicErrorException
)
1039 uno::Reference
< chart::XChartDataArray
> xChartDataArray( mxChartDocument
->getData(), uno::UNO_QUERY_THROW
);
1040 // dblValues = xChartDataArray.getData();
1041 //TODO I guess we have to differentiate between XlRowCol
1042 if ( !xChartDataArray
.is() )
1044 if (getPlotBy() == xlRows
)
1046 if ((_seriesindex
< xChartDataArray
->getRowDescriptions().getLength() ) && (_seriesindex
>= 0))
1051 if ((_seriesindex
< xChartDataArray
->getColumnDescriptions().getLength() ) && (_seriesindex
>= 0))
1056 catch (uno::Exception
& )
1058 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString() );
1062 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_OUT_OF_RANGE
, rtl::OUString() );
1068 ScVbaChart::areIndicesValid( sal_Int32 _seriesindex
, sal_Int32 _valindex
) throw ( css::script::BasicErrorException
)
1070 if (isSeriesIndexValid(_seriesindex
))
1072 uno::Reference
< chart::XChartDataArray
> xChartDataArray( mxChartDocument
->getData(), uno::UNO_QUERY_THROW
);
1073 dblValues
= xChartDataArray
->getData();
1074 return (_valindex
< dblValues
[_seriesindex
].getLength() );
1080 ScVbaChart::getSeriesIndex(rtl::OUString _sseriesname
) throw ( script::BasicErrorException
)
1082 uno::Reference
< chart::XChartDataArray
> xChartDataArray( mxChartDocument
->getData(), uno::UNO_QUERY_THROW
);
1083 if (getPlotBy() == xlRows
)
1084 return ContainerUtilities::FieldInList(xChartDataArray
->getRowDescriptions(), _sseriesname
);
1085 return ContainerUtilities::FieldInList(xChartDataArray
->getColumnDescriptions(), _sseriesname
);
1088 ScVbaChart::setSeriesName(sal_Int32 _index
, rtl::OUString _sname
) throw ( script::BasicErrorException
)
1090 uno::Reference
< chart::XChartDataArray
> xChartDataArray( mxChartDocument
->getData(), uno::UNO_QUERY_THROW
);
1091 if (isSeriesIndexValid(_index
))
1093 uno::Sequence
< rtl::OUString
> sDescriptions
= xChartDataArray
->getColumnDescriptions();
1094 sDescriptions
[_index
] = _sname
;
1095 xChartDataArray
->setColumnDescriptions(sDescriptions
);
1100 ScVbaChart::getSeriesCount() throw ( script::BasicErrorException
)
1102 uno::Reference
< chart::XChartDataArray
> xChartDataArray( mxChartDocument
->getData(), uno::UNO_QUERY_THROW
);
1104 if (getPlotBy() == xlRows
)
1105 return xChartDataArray
->getRowDescriptions().getLength();
1106 return xChartDataArray
->getColumnDescriptions().getLength();
1111 ScVbaChart::getSeriesName(sal_Int32 _index
) throw ( script::BasicErrorException
)
1113 uno::Reference
< chart::XChartDataArray
> xChartDataArray( mxChartDocument
->getData(), uno::UNO_QUERY_THROW
);
1114 uno::Sequence
< rtl::OUString
> sDescriptions
;
1115 rtl::OUString sName
;
1116 if (isSeriesIndexValid(_index
))
1118 if (getPlotBy() == xlRows
)
1119 sDescriptions
= xChartDataArray
->getRowDescriptions();
1121 sDescriptions
= xChartDataArray
->getColumnDescriptions();
1122 sName
= sDescriptions
[_index
];
1128 ScVbaChart::getValue(sal_Int32 _seriesindex
, sal_Int32 _valindex
) throw ( script::BasicErrorException
)
1130 double result
= -1.0;
1131 if (areIndicesValid(_seriesindex
, _valindex
))
1133 if (getPlotBy() == xlRows
)
1134 result
= dblValues
[_seriesindex
][_valindex
];
1136 result
= dblValues
[_valindex
][_seriesindex
];
1142 ScVbaChart::getValuesCount(sal_Int32 _seriesIndex
) throw ( script::BasicErrorException
)
1144 sal_Int32 nCount
= 0;
1145 uno::Reference
< chart::XChartDataArray
> xChartDataArray( mxChartDocument
->getData(), uno::UNO_QUERY_THROW
);
1146 if (isSeriesIndexValid(_seriesIndex
))
1148 dblValues
= xChartDataArray
->getData();
1149 if (getPlotBy() == xlRows
)
1150 nCount
= dblValues
[_seriesIndex
].getLength();
1152 nCount
= dblValues
.getLength();
1158 uno::Reference
< excel::XDataLabels
>
1159 ScVbaChart::DataLabels( const uno::Reference
< ov::excel::XSeries
> /*_oSeries*/ ) throw ( css::script::BasicErrorException
)
1162 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString() );
1163 // #TODO #FIXE provide implementation
1164 return uno::Reference
< excel::XDataLabels
> ();
1168 ScVbaChart::getHasDataCaption( const uno::Reference
< css::beans::XPropertySet
>& _xPropertySet
)throw ( script::BasicErrorException
)
1170 bool bResult
= false;
1173 sal_Int32 nChartDataCaption
= 0;
1174 _xPropertySet
->getPropertyValue(DATACAPTION
) >>= nChartDataCaption
;
1175 bResult
= (nChartDataCaption
!= chart::ChartDataCaption::NONE
);
1177 catch (uno::Exception
& )
1179 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString() );
1185 ScVbaChart::setHasDataCaption( const uno::Reference
< beans::XPropertySet
>& _xPropertySet
, bool _bHasDataLabels
)throw ( script::BasicErrorException
)
1189 if ( _bHasDataLabels
)
1190 _xPropertySet
->setPropertyValue(DATACAPTION
, uno::makeAny ( chart::ChartDataCaption::VALUE
) );
1192 _xPropertySet
->setPropertyValue(DATACAPTION
, uno::makeAny ( chart::ChartDataCaption::NONE
) );
1194 catch (uno::Exception
& )
1196 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString() );
1200 uno::Reference
< beans::XPropertySet
>
1201 ScVbaChart::getAxisPropertySet(sal_Int32 _nAxisType
, sal_Int32 _nAxisGroup
) throw ( script::BasicErrorException
)
1203 assignDiagramAttributes();
1204 uno::Reference
< beans::XPropertySet
> xAxisProps
;
1208 if (_nAxisGroup
== xlPrimary
)
1210 xAxisProps
= xAxisXSupplier
->getXAxis();
1212 else if (_nAxisGroup
== xlSecondary
)
1214 xAxisProps
= xTwoAxisXSupplier
->getSecondaryXAxis();
1218 // if (_nAxisGroup == xlPrimary){
1219 xAxisProps
= xAxisZSupplier
->getZAxis();
1222 // else if (_nAxisGroup == xlSecondary){
1223 // return xTwoAxisXSupplier.getSecondaryZAxis();
1226 if (_nAxisGroup
== xlPrimary
)
1227 xAxisProps
= xAxisYSupplier
->getYAxis();
1228 else if (_nAxisGroup
== xlSecondary
)
1229 xAxisProps
= xTwoAxisYSupplier
->getSecondaryYAxis();
1239 ScVbaChart::getServiceImplName()
1241 static rtl::OUString
sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaChart") );
1245 uno::Sequence
< rtl::OUString
>
1246 ScVbaChart::getServiceNames()
1248 static uno::Sequence
< rtl::OUString
> aServiceNames
;
1249 if ( aServiceNames
.getLength() == 0 )
1251 aServiceNames
.realloc( 1 );
1252 aServiceNames
[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Chart" ) );
1254 return aServiceNames
;