xref: /trunk/main/sc/source/ui/vba/vbacharts.cxx (revision d311fc8b)
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 "vbacharts.hxx"
24 #include <basic/sberrors.hxx>
25 #include <com/sun/star/table/XTableChartsSupplier.hpp>
26 
27 using namespace ::com::sun::star;
28 using namespace ::ooo::vba;
29 
30 
ScVbaCharts(const css::uno::Reference<ov::XHelperInterface> & _xParent,const css::uno::Reference<css::uno::XComponentContext> & _xContext,const uno::Reference<frame::XModel> & xModel)31 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 >())
32 {
33 	xComponent.set( xModel, uno::UNO_QUERY_THROW );
34 	xSpreadsheetDocument.set( xComponent, uno::UNO_QUERY_THROW );
35 }
36 
37 uno::Any SAL_CALL
Add()38 ScVbaCharts::Add() throw (css::script::BasicErrorException, css::uno::RuntimeException)
39 {
40 	// Not implemented in the helperapi ( see ChartsImpl.java )
41 	if ( true )
42 		throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_BAD_METHOD, rtl::OUString() );
43 	return aNULL();
44 }
45 
46 uno::Reference< excel::XChart > SAL_CALL
getActiveChart()47 ScVbaCharts::getActiveChart() throw (script::BasicErrorException, uno::RuntimeException)
48 {
49 	return xActiveChart;
50 }
51 
52 uno::Reference< container::XEnumeration > SAL_CALL
createEnumeration()53 ScVbaCharts::createEnumeration() throw (uno::RuntimeException)
54 {
55 	// #FIXME not implemented
56 	if ( true )
57 		throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_BAD_METHOD, rtl::OUString() );
58 	return uno::Reference< container::XEnumeration >();
59 }
60 
61 // #FIXME #TODO this method shouldn't appear in this class directly
62 // a XIndexAccess/XNameAccess wrapper should be passed to the base class instead
63 ::sal_Int32 SAL_CALL
getCount()64 ScVbaCharts::getCount() throw (uno::RuntimeException)
65 {
66 	sal_Int32 ncount = 0;
67 	try
68 	{
69 		uno::Reference< sheet::XSpreadsheets > xSpreadsheets( xSpreadsheetDocument->getSheets() );
70 		uno::Sequence< rtl::OUString > SheetNames = xSpreadsheets->getElementNames();
71 		sal_Int32 nLen = SheetNames.getLength();
72 		for (sal_Int32 i = 0; i < nLen; i++)
73 		{
74 			uno::Reference< table::XTableChartsSupplier > xTableChartsSupplier( xSpreadsheets->getByName(SheetNames[i]), uno::UNO_QUERY);
75 			if ( xTableChartsSupplier.is() )
76 			{
77 				uno::Reference< table::XTableCharts > xTableCharts = xTableChartsSupplier->getCharts();
78 				ncount += xTableCharts->getElementNames().getLength();
79 			}
80 		}
81 	}
82 	catch (uno::Exception& )
83 	{
84 		throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() );
85 	}
86 	return ncount;
87 }
88 
89 uno::Any
createCollectionObject(const uno::Any & aSource)90 ScVbaCharts::createCollectionObject( const uno::Any& aSource )
91 {
92 	if ( true )
93 		throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_BAD_METHOD, rtl::OUString() );
94 	// #TODO implementation please
95 	return aSource;
96 }
97 
98 rtl::OUString&
getServiceImplName()99 ScVbaCharts::getServiceImplName()
100 {
101 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaCharts") );
102 	return sImplName;
103 }
104 
105 css::uno::Sequence<rtl::OUString>
getServiceNames()106 ScVbaCharts::getServiceNames()
107 {
108 	static uno::Sequence< rtl::OUString > sNames;
109 	if ( sNames.getLength() == 0 )
110 	{
111 		sNames.realloc( 1 );
112 		sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Charts") );
113 	}
114 	return sNames;
115 }
116 
117