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