xref: /aoo42x/main/sc/source/ui/vba/vbacharts.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #include "vbacharts.hxx"
28 #include <basic/sberrors.hxx>
29 #include <com/sun/star/table/XTableChartsSupplier.hpp>
30 
31 using namespace ::com::sun::star;
32 using namespace ::ooo::vba;
33 
34 
35 ScVbaCharts::ScVbaCharts( const css::uno::Reference< ov::XHelperInterface >& _xParent, const css::uno::Reference< css::uno::XComponentContext >& _xContext, const uno::Reference< frame::XModel >& xModel ) : Charts_BASE(_xParent, _xContext, uno::Reference< container::XIndexAccess >())
36 {
37 	xComponent.set( xModel, uno::UNO_QUERY_THROW );
38 	xSpreadsheetDocument.set( xComponent, uno::UNO_QUERY_THROW );
39 }
40 
41 uno::Any SAL_CALL
42 ScVbaCharts::Add() throw (css::script::BasicErrorException, css::uno::RuntimeException)
43 {
44 	// Not implemented in the helperapi ( see ChartsImpl.java )
45 	if ( true )
46 		throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_BAD_METHOD, rtl::OUString() );
47 	return aNULL();
48 }
49 
50 uno::Reference< excel::XChart > SAL_CALL
51 ScVbaCharts::getActiveChart() throw (script::BasicErrorException, uno::RuntimeException)
52 {
53 	return xActiveChart;
54 }
55 
56 uno::Reference< container::XEnumeration > SAL_CALL
57 ScVbaCharts::createEnumeration() throw (uno::RuntimeException)
58 {
59 	// #FIXME not implemented
60 	if ( true )
61 		throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_BAD_METHOD, rtl::OUString() );
62 	return uno::Reference< container::XEnumeration >();
63 }
64 
65 // #FIXME #TODO this method shouldn't appear in this class directly
66 // a XIndexAccess/XNameAccess wrapper should be passed to the base class instead
67 ::sal_Int32 SAL_CALL
68 ScVbaCharts::getCount() throw (uno::RuntimeException)
69 {
70 	sal_Int32 ncount = 0;
71 	try
72 	{
73 		uno::Reference< sheet::XSpreadsheets > xSpreadsheets( xSpreadsheetDocument->getSheets() );
74 		uno::Sequence< rtl::OUString > SheetNames = xSpreadsheets->getElementNames();
75 		sal_Int32 nLen = SheetNames.getLength();
76 		for (sal_Int32 i = 0; i < nLen; i++)
77 		{
78 			uno::Reference< table::XTableChartsSupplier > xTableChartsSupplier( xSpreadsheets->getByName(SheetNames[i]), uno::UNO_QUERY);
79 			if ( xTableChartsSupplier.is() )
80 			{
81 				uno::Reference< table::XTableCharts > xTableCharts = xTableChartsSupplier->getCharts();
82 				ncount =+ xTableCharts->getElementNames().getLength();
83 			}
84 		}
85 	}
86 	catch (uno::Exception& )
87 	{
88 		throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() );
89 	}
90 	return ncount;
91 }
92 
93 uno::Any
94 ScVbaCharts::createCollectionObject( const uno::Any& aSource )
95 {
96 	if ( true )
97 		throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_BAD_METHOD, rtl::OUString() );
98 	// #TODO implementation please
99 	return aSource;
100 }
101 
102 rtl::OUString&
103 ScVbaCharts::getServiceImplName()
104 {
105 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaCharts") );
106 	return sImplName;
107 }
108 
109 css::uno::Sequence<rtl::OUString>
110 ScVbaCharts::getServiceNames()
111 {
112 	static uno::Sequence< rtl::OUString > sNames;
113 	if ( sNames.getLength() == 0 )
114 	{
115 		sNames.realloc( 1 );
116 		sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Charts") );
117 	}
118 	return sNames;
119 }
120 
121