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