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/sheet/XCellRangeAddressable.hpp>
22 #include <com/sun/star/chart/XAxisXSupplier.hpp>
23 #include <com/sun/star/chart/XAxisYSupplier.hpp>
24 #include <com/sun/star/chart/XAxisZSupplier.hpp>
25 #include <com/sun/star/chart/XTwoAxisXSupplier.hpp>
26 #include <com/sun/star/chart/XTwoAxisYSupplier.hpp>
27 #include <com/sun/star/chart/XChartDataArray.hpp>
28 #include <com/sun/star/chart/ChartSymbolType.hpp>
29 #include <com/sun/star/chart/ChartSolidType.hpp>
30 #include <com/sun/star/chart/ChartDataRowSource.hpp>
31 #include <com/sun/star/chart/ChartDataCaption.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"
43 using namespace ::com::sun::star
;
44 using namespace ::ooo::vba
;
45 using namespace ::ooo::vba::excel::XlChartType
;
46 using namespace ::ooo::vba::excel::XlRowCol
;
47 using namespace ::ooo::vba::excel::XlAxisType
;
48 using namespace ::ooo::vba::excel::XlAxisGroup
;
50 const OUString
CHART_NAME("Name");
51 // #TODO move this constant to vbaseries.[ch]xx ( when it exists )
52 const OUString
DEFAULTSERIESPREFIX("Series");
53 const OUString
DATAROWSOURCE("DataRowSource");
54 const OUString
UPDOWN("UpDown");
55 const OUString
VOLUME("Volume");
56 const OUString
LINES("Lines");
57 const OUString
SPLINETYPE("SplineType");
58 const OUString
SYMBOLTYPE("SymbolType");
59 const OUString
DEEP("Deep");
60 const OUString
SOLIDTYPE("SolidType");
61 const OUString
VERTICAL("Vertical");
62 const OUString
PERCENT("Percent");
63 const OUString
STACKED("Stacked");
64 const OUString
DIM3D("Dim3D");
65 const OUString
HASMAINTITLE("HasMainTitle");
66 const OUString
HASLEGEND("HasLegend");
68 ScVbaChart::ScVbaChart( const css::uno::Reference
< ov::XHelperInterface
>& _xParent
, const css::uno::Reference
< css::uno::XComponentContext
>& _xContext
, const css::uno::Reference
< css::lang::XComponent
>& _xChartComponent
, const css::uno::Reference
< css::table::XTableChart
>& _xTableChart
) : ChartImpl_BASE( _xParent
, _xContext
), mxTableChart( _xTableChart
)
70 mxChartDocument
.set( _xChartComponent
, uno::UNO_QUERY_THROW
) ;
71 // #TODO is is possible that the XPropertySet interface is not set
72 // code in setPlotBy seems to indicate that this is possible? but
73 // additionally there is no check in most of the places where it is used
74 // ( and therefore could possibly be NULL )
75 // I'm going to let it throw for the moment ( npower )
76 mxDiagramPropertySet
.set( mxChartDocument
->getDiagram(), uno::UNO_QUERY_THROW
);
77 mxChartPropertySet
.set( _xChartComponent
, uno::UNO_QUERY_THROW
) ;
81 ScVbaChart::getName() throw (css::uno::RuntimeException
)
84 uno::Reference
< beans::XPropertySet
> xProps( mxChartDocument
, uno::UNO_QUERY_THROW
);
87 xProps
->getPropertyValue( CHART_NAME
) >>= sName
;
89 catch( const uno::Exception
& ) // swallow exceptions
96 ScVbaChart::SeriesCollection(const uno::Any
&) throw (uno::RuntimeException
)
102 ScVbaChart::getChartType() throw ( uno::RuntimeException
, script::BasicErrorException
)
104 sal_Int32 nChartType
= -1;
107 OUString sDiagramType
= mxChartDocument
->getDiagram()->getDiagramType();
108 if ( sDiagramType
== "com.sun.star.chart.AreaDiagram" )
112 nChartType
= getStackedType(xl3DAreaStacked
, xl3DAreaStacked100
, xl3DArea
);
116 nChartType
= getStackedType(xlAreaStacked
, xlAreaStacked100
, xlArea
);
119 else if ( sDiagramType
== "com.sun.star.chart.PieDiagram" )
122 nChartType
= xl3DPie
;
124 nChartType
= xlPie
; /*TODO XlChartType xlPieExploded, XlChartType xlPieOfPie */
126 else if ( sDiagramType
== "com.sun.star.chart.BarDiagram" )
128 sal_Int32 nSolidType
= chart::ChartSolidType::RECTANGULAR_SOLID
;
129 if (mxDiagramPropertySet
->getPropertySetInfo()->hasPropertyByName(SOLIDTYPE
))
130 { //in 2D diagrams 'SolidType' may not be set
132 mxDiagramPropertySet
->getPropertyValue(SOLIDTYPE
) >>= nSolidType
;
136 case chart::ChartSolidType::CONE
:
137 nChartType
= getSolidType(xlConeCol
, xlConeColStacked
, xlConeColStacked100
, xlConeColClustered
, xlConeBarStacked
, xlConeBarStacked100
, xlConeBarClustered
);
139 case chart::ChartSolidType::CYLINDER
:
140 nChartType
= getSolidType(xlCylinderCol
, xlCylinderColStacked
, xlCylinderColStacked100
, xlCylinderColClustered
, xlCylinderBarStacked
, xlCylinderBarStacked100
, xlCylinderBarClustered
);
142 case chart::ChartSolidType::PYRAMID
:
143 nChartType
= getSolidType(xlPyramidCol
, xlPyramidColStacked
, xlPyramidColStacked100
, xlPyramidColClustered
, xlPyramidBarStacked
, xlPyramidBarStacked100
, xlPyramidBarClustered
);
145 default: // RECTANGULAR_SOLID
148 nChartType
= getSolidType(xl3DColumn
, xl3DColumnStacked
, xl3DColumnStacked100
, xl3DColumnClustered
, xl3DBarStacked
, xl3DBarStacked100
, xl3DBarClustered
);
152 nChartType
= getSolidType(xlColumnClustered
, xlColumnStacked
, xlColumnStacked100
, xlColumnClustered
, xlBarStacked
, xlBarStacked100
, xlBarClustered
);
157 else if ( sDiagramType
== "com.sun.star.chart.StockDiagram" )
159 sal_Bool bVolume
= false;
160 mxDiagramPropertySet
->getPropertyValue(VOLUME
) >>= bVolume
;
163 nChartType
= getStockUpDownValue(xlStockVOHLC
, xlStockVHLC
);
167 nChartType
= getStockUpDownValue(xlStockOHLC
, xlStockHLC
);
170 else if ( sDiagramType
== "com.sun.star.chart.XYDiagram" )
172 sal_Bool bHasLines
= false;
173 mxDiagramPropertySet
->getPropertyValue(LINES
) >>= bHasLines
;
174 sal_Int32 nSplineType
= 0;
175 mxDiagramPropertySet
->getPropertyValue(SPLINETYPE
) >>= nSplineType
;
176 if (nSplineType
== 1)
178 nChartType
= getMarkerType(xlXYScatterSmooth
, xlXYScatterSmoothNoMarkers
);
182 nChartType
= getMarkerType(xlXYScatterLines
, xlXYScatterLinesNoMarkers
);
186 nChartType
= xlXYScatter
;
189 else if ( sDiagramType
== "com.sun.star.chart.LineDiagram" )
193 nChartType
= xl3DLine
;
195 else if (hasMarkers())
197 nChartType
= getStackedType(xlLineMarkersStacked
, xlLineMarkersStacked100
, xlLineMarkers
);
201 nChartType
= getStackedType(xlLineStacked
, xlLineStacked100
, xlLine
);
204 else if ( sDiagramType
== "com.sun.star.chart.DonutDiagram" )
206 nChartType
= xlDoughnut
; // TODO DoughnutExploded ??
208 else if ( sDiagramType
== "com.sun.star.chart.NetDiagram" )
210 nChartType
= getMarkerType(xlRadarMarkers
, xlRadar
);
213 catch ( const uno::Exception
& )
215 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, OUString() );
221 ScVbaChart::setChartType( ::sal_Int32 _nChartType
) throw ( uno::RuntimeException
, script::BasicErrorException
)
227 case xlColumnClustered
:
228 case xlColumnStacked
:
229 case xlColumnStacked100
:
230 case xl3DColumnClustered
:
231 case xl3DColumnStacked
:
232 case xl3DColumnStacked100
:
236 case xlBarStacked100
:
237 case xl3DBarClustered
:
239 case xl3DBarStacked100
:
240 case xlConeColClustered
:
241 case xlConeColStacked
:
242 case xlConeColStacked100
:
243 case xlConeBarClustered
:
244 case xlConeBarStacked
:
245 case xlConeBarStacked100
:
247 case xlPyramidColClustered
:
248 case xlPyramidColStacked
:
249 case xlPyramidColStacked100
:
250 case xlPyramidBarClustered
:
251 case xlPyramidBarStacked
:
252 case xlPyramidBarStacked100
:
254 case xlCylinderColClustered
:
255 case xlCylinderColStacked
:
256 case xlCylinderColStacked100
:
257 case xlCylinderBarClustered
:
258 case xlCylinderBarStacked
:
259 case xlCylinderBarStacked100
:
261 case xlSurface
: // not possible
262 case xlSurfaceWireframe
:
263 case xlSurfaceTopView
:
264 case xlSurfaceTopViewWireframe
:
265 setDiagram( OUString("com.sun.star.chart.BarDiagram"));
270 case xlLineStacked100
:
272 case xlLineMarkersStacked
:
273 case xlLineMarkersStacked100
:
274 setDiagram( OUString("com.sun.star.chart.LineDiagram"));
279 case xlAreaStacked100
:
280 case xl3DAreaStacked
:
281 case xl3DAreaStacked100
:
282 setDiagram( OUString("com.sun.star.chart.AreaDiagram") );
285 case xlDoughnutExploded
:
286 setDiagram( OUString("com.sun.star.chart.DonutDiagram") );
292 setDiagram( OUString("com.sun.star.chart.StockDiagram"));
293 mxDiagramPropertySet
->setPropertyValue( UPDOWN
, uno::makeAny(sal_Bool((_nChartType
== xlStockOHLC
) || (_nChartType
== xlStockVOHLC
))));
294 mxDiagramPropertySet
->setPropertyValue(VOLUME
, uno::makeAny(sal_Bool((_nChartType
== xlStockVHLC
) || (_nChartType
== xlStockVOHLC
))));
297 case xlPieOfPie
: // not possible
298 case xlPieExploded
: // SegmentOffset an ChartDataPointProperties ->am XDiagram abholen //wie macht Excel das?
299 case xl3DPieExploded
:
302 case xlBarOfPie
: // not possible (Zoom pie)
303 setDiagram( OUString("com.sun.star.chart.PieDiagram"));
309 setDiagram( OUString("com.sun.star.chart.NetDiagram"));
312 case xlBubble
: // not possible
313 case xlBubble3DEffect
: // not possible
314 case xlXYScatterLines
:
315 case xlXYScatterLinesNoMarkers
:
316 case xlXYScatterSmooth
:
317 case xlXYScatterSmoothNoMarkers
:
318 setDiagram( OUString("com.sun.star.chart.XYDiagram"));
322 case xlBubble
: // not possible
323 case xlBubble3DEffect
: // not possible
324 mxDiagramPropertySet
->setPropertyValue(LINES
, uno::makeAny( sal_False
));
326 case xlXYScatterLines
:
327 case xlXYScatterLinesNoMarkers
:
328 mxDiagramPropertySet
->setPropertyValue(LINES
, uno::makeAny( sal_True
));
330 case xlXYScatterSmooth
:
331 case xlXYScatterSmoothNoMarkers
:
332 mxDiagramPropertySet
->setPropertyValue(SPLINETYPE
, uno::makeAny( sal_Int32(1)));
339 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), SbERR_CONVERSION
, OUString() );
345 case xlLineMarkersStacked
:
346 case xlLineMarkersStacked100
:
348 case xlXYScatterLines
:
349 case xlXYScatterSmooth
:
351 case xlBubble
: // not possible
352 case xlBubble3DEffect
: // not possible
353 mxDiagramPropertySet
->setPropertyValue(SYMBOLTYPE
, uno::makeAny( chart::ChartSymbolType::AUTO
));
356 if (mxDiagramPropertySet
->getPropertySetInfo()->hasPropertyByName(SYMBOLTYPE
))
358 mxDiagramPropertySet
->setPropertyValue(SYMBOLTYPE
, uno::makeAny(chart::ChartSymbolType::NONE
));
369 case xlSurface
: // not possible
370 case xlSurfaceWireframe
:
371 case xlSurfaceTopView
:
372 case xlSurfaceTopViewWireframe
:
373 mxDiagramPropertySet
->setPropertyValue(DEEP
,uno::makeAny( sal_True
));
376 if (mxDiagramPropertySet
->getPropertySetInfo()->hasPropertyByName(DEEP
))
378 mxDiagramPropertySet
->setPropertyValue(DEEP
, uno::makeAny( sal_False
));
386 case xlConeColClustered
:
387 case xlConeColStacked
:
388 case xlConeColStacked100
:
389 case xlConeBarClustered
:
390 case xlConeBarStacked
:
391 case xlConeBarStacked100
:
393 mxDiagramPropertySet
->setPropertyValue(SOLIDTYPE
, uno::makeAny(chart::ChartSolidType::CONE
));
395 case xlPyramidColClustered
:
396 case xlPyramidColStacked
:
397 case xlPyramidColStacked100
:
398 case xlPyramidBarClustered
:
399 case xlPyramidBarStacked
:
400 case xlPyramidBarStacked100
:
402 mxDiagramPropertySet
->setPropertyValue(SOLIDTYPE
, uno::makeAny(chart::ChartSolidType::PYRAMID
));
404 case xlCylinderColClustered
:
405 case xlCylinderColStacked
:
406 case xlCylinderColStacked100
:
407 case xlCylinderBarClustered
:
408 case xlCylinderBarStacked
:
409 case xlCylinderBarStacked100
:
411 mxDiagramPropertySet
->setPropertyValue(SOLIDTYPE
, uno::makeAny(chart::ChartSolidType::CYLINDER
));
414 if (mxDiagramPropertySet
->getPropertySetInfo()->hasPropertyByName(SOLIDTYPE
))
416 mxDiagramPropertySet
->setPropertyValue(SOLIDTYPE
, uno::makeAny(chart::ChartSolidType::RECTANGULAR_SOLID
));
421 switch ( _nChartType
)
424 case xlConeColClustered
:
425 case xlConeColStacked
:
426 case xlConeColStacked100
:
427 case xlPyramidColClustered
:
428 case xlPyramidColStacked
:
429 case xlPyramidColStacked100
:
430 case xlCylinderColClustered
:
431 case xlCylinderColStacked
:
432 case xlCylinderColStacked100
:
433 case xlColumnClustered
:
434 case xlColumnStacked
:
435 case xlColumnStacked100
:
436 case xl3DColumnClustered
:
437 case xl3DColumnStacked
:
438 case xl3DColumnStacked100
:
439 case xlSurface
: // not possible
440 case xlSurfaceWireframe
:
441 case xlSurfaceTopView
:
442 case xlSurfaceTopViewWireframe
:
443 mxDiagramPropertySet
->setPropertyValue(VERTICAL
, uno::makeAny( sal_True
));
446 if (mxDiagramPropertySet
->getPropertySetInfo()->hasPropertyByName(VERTICAL
))
448 mxDiagramPropertySet
->setPropertyValue(VERTICAL
, uno::makeAny(sal_False
));
455 case xlColumnStacked
:
456 case xl3DColumnStacked
:
460 case xlLineMarkersStacked
:
462 case xl3DAreaStacked
:
463 case xlCylinderColStacked
:
464 case xlCylinderBarStacked
:
465 case xlConeColStacked
:
466 case xlConeBarStacked
:
467 case xlPyramidColStacked
:
468 case xlPyramidBarStacked
:
469 mxDiagramPropertySet
->setPropertyValue(PERCENT
, uno::makeAny( sal_False
));
470 mxDiagramPropertySet
->setPropertyValue(STACKED
, uno::makeAny( sal_True
));
472 case xlPyramidColStacked100
:
473 case xlPyramidBarStacked100
:
474 case xlConeColStacked100
:
475 case xlConeBarStacked100
:
476 case xlCylinderBarStacked100
:
477 case xlCylinderColStacked100
:
478 case xl3DAreaStacked100
:
479 case xlLineMarkersStacked100
:
480 case xlAreaStacked100
:
481 case xlLineStacked100
:
482 case xl3DBarStacked100
:
483 case xlBarStacked100
:
484 case xl3DColumnStacked100
:
485 case xlColumnStacked100
:
486 mxDiagramPropertySet
->setPropertyValue(STACKED
, uno::makeAny( sal_True
));
487 mxDiagramPropertySet
->setPropertyValue(PERCENT
, uno::makeAny( sal_True
));
490 mxDiagramPropertySet
->setPropertyValue(PERCENT
, uno::makeAny( sal_False
));
491 mxDiagramPropertySet
->setPropertyValue(STACKED
, uno::makeAny( sal_False
));
497 case xl3DAreaStacked
:
498 case xl3DAreaStacked100
:
499 case xl3DBarClustered
:
501 case xl3DBarStacked100
:
503 case xl3DColumnClustered
:
504 case xl3DColumnStacked
:
505 case xl3DColumnStacked100
:
508 case xl3DPieExploded
:
509 case xlConeColClustered
:
510 case xlConeColStacked
:
511 case xlConeColStacked100
:
512 case xlConeBarClustered
:
513 case xlConeBarStacked
:
514 case xlConeBarStacked100
:
516 case xlPyramidColClustered
:
517 case xlPyramidColStacked
:
518 case xlPyramidColStacked100
:
519 case xlPyramidBarClustered
:
520 case xlPyramidBarStacked
:
521 case xlPyramidBarStacked100
:
523 case xlCylinderColClustered
:
524 case xlCylinderColStacked
:
525 case xlCylinderColStacked100
:
526 case xlCylinderBarClustered
:
527 case xlCylinderBarStacked
:
528 case xlCylinderBarStacked100
:
530 mxDiagramPropertySet
->setPropertyValue(DIM3D
, uno::makeAny( sal_True
));
533 if (mxDiagramPropertySet
->getPropertySetInfo()->hasPropertyByName(DIM3D
))
535 mxDiagramPropertySet
->setPropertyValue(DIM3D
, uno::makeAny( sal_False
));
540 catch ( const uno::Exception
& )
542 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, OUString() );
547 ScVbaChart::Activate() throw (script::BasicErrorException
, uno::RuntimeException
)
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() );
556 pChartObj
->Activate();
558 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, OUString( "no ChartObject as parent" ) );
562 ScVbaChart::setSourceData( const css::uno::Reference
< ::ooo::vba::excel::XRange
>& _xCalcRange
, const css::uno::Any
& _aPlotBy
) throw (css::script::BasicErrorException
, css::uno::RuntimeException
)
566 uno::Sequence
< table::CellRangeAddress
> mRangeAddresses(1);
567 table::CellRangeAddress mSingleRangeAddress
;
569 uno::Reference
< sheet::XCellRangeAddressable
> xAddressable( _xCalcRange
->getCellRange(), uno::UNO_QUERY_THROW
);
570 mSingleRangeAddress
= xAddressable
->getRangeAddress();
572 mRangeAddresses
[0] = mSingleRangeAddress
;
574 mxTableChart
->setRanges(mRangeAddresses
);
576 sal_Bool bsetRowHeaders
= false;
577 sal_Bool bsetColumnHeaders
= false;
579 ScVbaRange
* pRange
= static_cast< ScVbaRange
* >( _xCalcRange
.get() );
582 ScDocument
* pDoc
= pRange
->getScDocument();
585 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
) );
586 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
));
590 mxTableChart
->setHasRowHeaders(bsetRowHeaders
);
591 mxTableChart
->setHasColumnHeaders(bsetColumnHeaders
);
593 if ((!bsetColumnHeaders
) || (!bsetRowHeaders
))
595 uno::Reference
< chart::XChartDataArray
> xChartDataArray( mxChartDocument
->getData(), uno::UNO_QUERY_THROW
);
596 if (!bsetColumnHeaders
)
598 xChartDataArray
->setColumnDescriptions( getDefaultSeriesDescriptions(xChartDataArray
->getColumnDescriptions().getLength() ));
602 xChartDataArray
->setRowDescriptions(getDefaultSeriesDescriptions(xChartDataArray
->getRowDescriptions().getLength() ));
606 if ( _aPlotBy
.hasValue() )
614 sal_Int32 nRows
= mSingleRangeAddress
.EndRow
- mSingleRangeAddress
.StartRow
;
615 sal_Int32 nCols
= mSingleRangeAddress
.EndColumn
- mSingleRangeAddress
.StartColumn
;
616 // AutoDetect emulation
618 setPlotBy( xlColumns
);
619 else if ( nRows
<= nCols
)
623 catch (const uno::Exception
&)
625 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, OUString() );
629 uno::Sequence
< OUString
>
630 ScVbaChart::getDefaultSeriesDescriptions( sal_Int32 _nCount
)
632 uno::Sequence
< OUString
> sDescriptions ( _nCount
);
633 sal_Int32 nLen
= sDescriptions
.getLength();
634 for (sal_Int32 i
= 0; i
< nLen
; i
++)
636 sDescriptions
[i
] = DEFAULTSERIESPREFIX
+ OUString::number(i
+1);
638 return sDescriptions
;
642 ScVbaChart::setDefaultChartType() throw ( script::BasicErrorException
)
644 setChartType( xlColumnClustered
);
648 ScVbaChart::setPlotBy( ::sal_Int32 _nPlotBy
) throw (css::script::BasicErrorException
, css::uno::RuntimeException
)
652 if ( !mxDiagramPropertySet
.is() )
653 setDefaultChartType();
657 mxDiagramPropertySet
->setPropertyValue( DATAROWSOURCE
, uno::makeAny( chart::ChartDataRowSource_ROWS
) );
660 mxDiagramPropertySet
->setPropertyValue( DATAROWSOURCE
, uno::makeAny( chart::ChartDataRowSource_COLUMNS
) );
663 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, OUString() );
666 catch (const uno::Exception
&)
668 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, OUString() );
673 ScVbaChart::getPlotBy( ) throw (script::BasicErrorException
, uno::RuntimeException
)
677 chart::ChartDataRowSource aChartDataRowSource
;
678 mxDiagramPropertySet
->getPropertyValue(DATAROWSOURCE
) >>= aChartDataRowSource
;
679 if (aChartDataRowSource
== chart::ChartDataRowSource_COLUMNS
)
688 catch (const uno::Exception
&)
690 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, OUString() );
695 ScVbaChart::setDiagram( const OUString
& _sDiagramType
) throw( script::BasicErrorException
)
699 uno::Reference
< lang::XMultiServiceFactory
> xMSF( mxChartDocument
, uno::UNO_QUERY_THROW
);
700 uno::Reference
< chart::XDiagram
> xDiagram( xMSF
->createInstance( _sDiagramType
), uno::UNO_QUERY_THROW
);
701 mxChartDocument
->setDiagram( xDiagram
);
702 mxDiagramPropertySet
.set( xDiagram
, uno::UNO_QUERY_THROW
);
704 catch ( const uno::Exception
& )
706 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, OUString() );
710 // #TODO find out why we have Location/getLocation ? there is afaiks no
711 // Location property, just a Location function for the Chart object
713 ScVbaChart::Location() throw (css::script::BasicErrorException
, css::uno::RuntimeException
)
715 return getLocation();
719 ScVbaChart::getLocation() throw (css::script::BasicErrorException
, css::uno::RuntimeException
)
725 ScVbaChart::setLocation( ::sal_Int32
/*where*/, const css::uno::Any
& /*Name*/ ) throw (script::BasicErrorException
, uno::RuntimeException
)
727 // Helper api just stubs out the code <shrug>
728 // #TODO come back and make sense out of this
729 // String sheetName = null;
731 // if ((name != null) && name instanceof String) {
732 // sheetName = (String) name;
734 // XSpreadsheetDocument xShDoc = (XSpreadsheetDocument) UnoRuntime.queryInterface( XSpreadsheetDocument.class,getXModel() );
735 // com.sun.star.sheet.XSpreadsheets xSheets = xShDoc.Sheets();
738 // case ClLocationType.clLocationAsObject_value: //{
740 // if (sheetName == null) {
741 // DebugHelper.writeInfo("Can't embed in Chart without knowing SheetName");
746 // Any any = (Any) xSheets.getByName(sheetName);
747 // chartSheet = (XSpreadsheet) any.getObject();
749 // // chartSheet = (XSpreadsheet) xSheets.getByName( sheetName );
750 // } catch (NoSuchElementException e) {
751 // // TODO Auto-generated catch block
752 // e.printStackTrace();
755 // } catch (WrappedTargetException e) {
756 // // TODO Auto-generated catch block
757 // e.printStackTrace();
760 // } catch (java.lang.Exception e) {
761 // e.printStackTrace();
764 // XTableChartsSupplier xTCS = (XTableChartsSupplier) UnoRuntime.queryInterface( XTableChartsSupplier.class, chartSheet);
765 // XTableCharts xTableCharts = xTCS.getCharts();
766 // XIndexAccess xIA = (XIndexAccess) UnoRuntime.queryInterface( XIndexAccess.class, xTableCharts);
767 // int numCharts = xIA.getCount();
768 // chartName = "Chart " + (numCharts + 1);
773 // case ClLocationType.clLocationAsNewSheet_value:
774 // case ClLocationType.clLocationAutomatic_value:default: //{
775 // chartName = "Chart 1"; // Since it's a new sheet, it's the first on it...
777 // XIndexAccess xSheetIA = (XIndexAccess) UnoRuntime.queryInterface( XIndexAccess.class, xSheets);
779 // short newSheetNum = (short) (xSheetIA.getCount() + 1);
781 // if (sheetName == null){
782 // sheetName = "ChartSheet " + newSheetNum; // Why not?
784 // // DPK TODO : Probably should use Sheets to create this!
785 // xSheets.insertNewByName(sheetName, newSheetNum);
789 // (XSpreadsheet) xSheets.getByName(sheetName);
790 // } catch (NoSuchElementException e) {
791 // // TODO Auto-generated catch block
792 // e.printStackTrace();
795 // } catch (WrappedTargetException e) {
796 // // TODO Auto-generated catch block
797 // e.printStackTrace();
806 // // Last thing should be a call to createChartForReal(), one of them
807 // // should succeed.
808 // createChartForReal();
813 ScVbaChart::getHasTitle( ) throw (script::BasicErrorException
, uno::RuntimeException
)
815 sal_Bool bHasTitle
= false;
818 mxChartPropertySet
->getPropertyValue(HASMAINTITLE
) >>= bHasTitle
;
820 catch (const uno::Exception
&)
822 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, OUString() );
828 ScVbaChart::setHasTitle( ::sal_Bool bTitle
) throw (script::BasicErrorException
, uno::RuntimeException
)
832 mxChartPropertySet
->setPropertyValue(HASMAINTITLE
, uno::makeAny( bTitle
));
834 catch (const uno::Exception
&)
836 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, OUString() );
842 ScVbaChart::getHasLegend( ) throw (script::BasicErrorException
, uno::RuntimeException
)
844 sal_Bool bHasLegend
= false;
847 mxChartPropertySet
->getPropertyValue(HASLEGEND
) >>= bHasLegend
;
849 catch (const uno::Exception
&)
851 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, OUString() );
857 ScVbaChart::setHasLegend( ::sal_Bool bLegend
) throw (script::BasicErrorException
, uno::RuntimeException
)
861 mxChartPropertySet
->setPropertyValue(HASLEGEND
, uno::makeAny(bLegend
));
863 catch (const uno::Exception
&)
865 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, OUString() );
869 uno::Reference
< excel::XChartTitle
> SAL_CALL
870 ScVbaChart::getChartTitle( ) throw (script::BasicErrorException
, uno::RuntimeException
)
872 uno::Reference
< drawing::XShape
> xTitleShape
= mxChartDocument
->getTitle();
873 // #TODO check parent
874 return new ScVbaChartTitle(this, mxContext
, xTitleShape
);
878 ScVbaChart::Axes( const uno::Any
& Type
, const uno::Any
& AxisGroup
) throw (script::BasicErrorException
, uno::RuntimeException
)
880 // mmm chart probably is the parent, #TODO check parent
881 uno::Reference
< excel::XAxes
> xAxes
= new ScVbaAxes( this, mxContext
, this );
882 if ( !Type
.hasValue() )
883 return uno::makeAny( xAxes
);
884 return xAxes
->Item( Type
, AxisGroup
);
887 ScVbaChart::is3D() throw ( uno::RuntimeException
)
889 // #TODO perhaps provide limited Debughelper functionality
890 sal_Bool is3d
= false;
891 mxDiagramPropertySet
->getPropertyValue(DIM3D
) >>= is3d
;
896 ScVbaChart::getStackedType( sal_Int32 _nStacked
, sal_Int32 _n100PercentStacked
, sal_Int32 _nUnStacked
) throw ( uno::RuntimeException
)
898 // #TODO perhaps provide limited Debughelper functionality
901 if (is100PercentStacked())
902 return _n100PercentStacked
;
911 ScVbaChart::isStacked() throw ( uno::RuntimeException
)
913 // #TODO perhaps provide limited Debughelper functionality
914 sal_Bool bStacked
= false;
915 mxDiagramPropertySet
->getPropertyValue(STACKED
) >>= bStacked
;
920 ScVbaChart::is100PercentStacked() throw ( uno::RuntimeException
)
922 // #TODO perhaps provide limited Debughelper functionality
923 sal_Bool b100Percent
= false;
924 mxDiagramPropertySet
->getPropertyValue(PERCENT
) >>= b100Percent
;
929 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
)
931 sal_Bool bIsVertical
= true;
934 mxDiagramPropertySet
->getPropertyValue(VERTICAL
) >>= bIsVertical
;
935 sal_Bool bIsDeep
= false;
936 mxDiagramPropertySet
->getPropertyValue(DEEP
) >>= bIsDeep
;
946 return getStackedType(_nVertiStacked
, _nVerti100PercentStacked
, _nVertiUnStacked
);
950 return getStackedType(_nHoriStacked
, _nHori100PercentStacked
, _nHoriUnStacked
);
954 catch (const uno::Exception
&)
956 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, OUString() );
962 ScVbaChart::getStockUpDownValue(sal_Int32 _nUpDown
, sal_Int32 _nNotUpDown
) throw (script::BasicErrorException
)
964 sal_Bool bUpDown
= false;
967 mxDiagramPropertySet
->getPropertyValue(UPDOWN
) >>= bUpDown
;
977 catch (const uno::Exception
&)
979 OUString aTemp
; // temporary needed for g++ 3.3.5
980 script::BasicErrorException( aTemp
, uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, OUString() );
986 ScVbaChart::hasMarkers() throw ( script::BasicErrorException
)
988 bool bHasMarkers
= false;
992 mxDiagramPropertySet
->getPropertyValue(SYMBOLTYPE
) >>= nSymbol
;
993 bHasMarkers
= nSymbol
!= chart::ChartSymbolType::NONE
;
995 catch (const uno::Exception
&)
997 OUString aTemp
; // temporary needed for g++ 3.3.5
998 script::BasicErrorException( aTemp
, uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, OUString() );
1004 ScVbaChart::getMarkerType(sal_Int32 _nWithMarkers
, sal_Int32 _nWithoutMarkers
) throw ( script::BasicErrorException
)
1007 return _nWithMarkers
;
1008 return _nWithoutMarkers
;
1012 ScVbaChart::assignDiagramAttributes()
1014 xAxisXSupplier
.set( mxDiagramPropertySet
, uno::UNO_QUERY_THROW
);
1015 xAxisYSupplier
.set( mxDiagramPropertySet
, uno::UNO_QUERY_THROW
);
1016 xAxisZSupplier
.set( mxDiagramPropertySet
, uno::UNO_QUERY_THROW
);
1017 xTwoAxisXSupplier
.set( mxDiagramPropertySet
, uno::UNO_QUERY_THROW
);
1018 xTwoAxisYSupplier
.set( mxDiagramPropertySet
, uno::UNO_QUERY_THROW
);
1022 uno::Reference
< beans::XPropertySet
>
1023 ScVbaChart::getAxisPropertySet(sal_Int32 _nAxisType
, sal_Int32 _nAxisGroup
) throw ( script::BasicErrorException
)
1025 assignDiagramAttributes();
1026 uno::Reference
< beans::XPropertySet
> xAxisProps
;
1030 if (_nAxisGroup
== xlPrimary
)
1032 xAxisProps
= xAxisXSupplier
->getXAxis();
1034 else if (_nAxisGroup
== xlSecondary
)
1036 xAxisProps
= xTwoAxisXSupplier
->getSecondaryXAxis();
1040 xAxisProps
= xAxisZSupplier
->getZAxis();
1043 if (_nAxisGroup
== xlPrimary
)
1044 xAxisProps
= xAxisYSupplier
->getYAxis();
1045 else if (_nAxisGroup
== xlSecondary
)
1046 xAxisProps
= xTwoAxisYSupplier
->getSecondaryYAxis();
1056 ScVbaChart::getServiceImplName()
1058 return OUString("ScVbaChart");
1061 uno::Sequence
< OUString
>
1062 ScVbaChart::getServiceNames()
1064 static uno::Sequence
< OUString
> aServiceNames
;
1065 if ( aServiceNames
.getLength() == 0 )
1067 aServiceNames
.realloc( 1 );
1068 aServiceNames
[ 0 ] = "ooo.vba.excel.Chart";
1070 return aServiceNames
;
1073 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */