update dev300-m58
[ooovba.git] / sc / source / ui / vba / vbaglobals.cxx
blob6c6e5380ef02226d9bac96a83d5fdf348c011342
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vbaglobals.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include <vbahelper/helperdecl.hxx>
31 #include "vbaglobals.hxx"
33 #include <comphelper/unwrapargs.hxx>
35 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <cppuhelper/component_context.hxx>
39 #include "vbaapplication.hxx"
40 #include "vbaworksheet.hxx"
41 #include "vbarange.hxx"
42 #include <cppuhelper/bootstrap.hxx>
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::uno;
45 using namespace ::ooo::vba;
49 // =============================================================================
50 // ScVbaGlobals
51 // =============================================================================
53 //ScVbaGlobals::ScVbaGlobals( css::uno::Reference< css::uno::XComponentContext >const& rxContext, ) : ScVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext )
54 rtl::OUString sDocCtxName( RTL_CONSTASCII_USTRINGPARAM("ExcelDocumentContext") );
56 ScVbaGlobals::ScVbaGlobals( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& rxContext ) : ScVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext, sDocCtxName )
58 OSL_TRACE("ScVbaGlobals::ScVbaGlobals()");
60 uno::Sequence< beans::PropertyValue > aInitArgs( 2 );
61 aInitArgs[ 0 ].Name = rtl::OUString::createFromAscii("Application");
62 aInitArgs[ 0 ].Value = uno::makeAny( getApplication() );
63 aInitArgs[ 1 ].Name = sDocCtxName;
64 aInitArgs[ 1 ].Value = uno::makeAny( getXSomethingFromArgs< frame::XModel >( aArgs, 0 ) );
66 init( aInitArgs );
69 ScVbaGlobals::~ScVbaGlobals()
71 OSL_TRACE("ScVbaGlobals::~ScVbaGlobals");
74 // =============================================================================
75 // XGlobals
76 // =============================================================================
77 uno::Reference<excel::XApplication >
78 ScVbaGlobals::getApplication() throw (uno::RuntimeException)
80 // OSL_TRACE("In ScVbaGlobals::getApplication");
81 if ( !mxApplication.is() )
82 mxApplication.set( new ScVbaApplication( mxContext) );
83 return mxApplication;
86 uno::Reference< excel::XWorkbook > SAL_CALL
87 ScVbaGlobals::getActiveWorkbook() throw (uno::RuntimeException)
89 // OSL_TRACE("In ScVbaGlobals::getActiveWorkbook");
90 uno::Reference< excel::XWorkbook > xWorkbook( getApplication()->getActiveWorkbook(), uno::UNO_QUERY);
91 if ( xWorkbook.is() )
93 return xWorkbook;
95 // FIXME check if this is correct/desired behavior
96 throw uno::RuntimeException( rtl::OUString::createFromAscii(
97 "No activeWorkbook available" ), Reference< uno::XInterface >() );
101 uno::Reference< excel::XWindow > SAL_CALL
102 ScVbaGlobals::getActiveWindow() throw (uno::RuntimeException)
104 return getApplication()->getActiveWindow();
107 uno::Reference< excel::XWorksheet > SAL_CALL
108 ScVbaGlobals::getActiveSheet() throw (uno::RuntimeException)
110 return getApplication()->getActiveSheet();
113 uno::Any SAL_CALL
114 ScVbaGlobals::WorkBooks( const uno::Any& aIndex ) throw (uno::RuntimeException)
116 return uno::Any( getApplication()->Workbooks(aIndex) );
119 uno::Any SAL_CALL
120 ScVbaGlobals::WorkSheets(const uno::Any& aIndex) throw (uno::RuntimeException)
122 return getApplication()->Worksheets( aIndex );
124 uno::Any SAL_CALL
125 ScVbaGlobals::Sheets( const uno::Any& aIndex ) throw (uno::RuntimeException)
127 return WorkSheets( aIndex );
130 uno::Any SAL_CALL
131 ScVbaGlobals::Range( const uno::Any& Cell1, const uno::Any& Cell2 ) throw (uno::RuntimeException)
133 return getApplication()->Range( Cell1, Cell2 );
136 uno::Any SAL_CALL
137 ScVbaGlobals::Names( const css::uno::Any& aIndex ) throw ( uno::RuntimeException )
139 return getApplication()->Names( aIndex );
142 uno::Reference< excel::XRange > SAL_CALL
143 ScVbaGlobals::getActiveCell() throw (uno::RuntimeException)
145 return getApplication()->getActiveCell();
148 uno::Reference< XAssistant > SAL_CALL
149 ScVbaGlobals::getAssistant() throw (uno::RuntimeException)
151 return getApplication()->getAssistant();
154 uno::Any SAL_CALL
155 ScVbaGlobals::getSelection() throw (uno::RuntimeException)
157 return getApplication()->getSelection();
160 uno::Reference< excel::XWorkbook > SAL_CALL
161 ScVbaGlobals::getThisWorkbook() throw (uno::RuntimeException)
163 return getApplication()->getThisWorkbook();
165 void SAL_CALL
166 ScVbaGlobals::Calculate() throw (::com::sun::star::script::BasicErrorException, ::com::sun::star::uno::RuntimeException)
168 return getApplication()->Calculate();
171 uno::Reference< excel::XRange > SAL_CALL
172 ScVbaGlobals::Cells( const uno::Any& RowIndex, const uno::Any& ColumnIndex ) throw (uno::RuntimeException)
174 return getApplication()->getActiveSheet()->Cells( RowIndex, ColumnIndex );
176 uno::Reference< excel::XRange > SAL_CALL
177 ScVbaGlobals::Columns( const uno::Any& aIndex ) throw (uno::RuntimeException)
179 return getApplication()->getActiveSheet()->Columns( aIndex );
182 uno::Any SAL_CALL
183 ScVbaGlobals::CommandBars( const uno::Any& aIndex ) throw (uno::RuntimeException)
185 uno::Reference< XApplicationBase > xBase( getApplication(), uno::UNO_QUERY_THROW );
186 return xBase->CommandBars( aIndex );
189 css::uno::Reference< ov::excel::XRange > SAL_CALL
190 ScVbaGlobals::Union( const css::uno::Reference< ov::excel::XRange >& Arg1, const css::uno::Reference< ov::excel::XRange >& Arg2, const css::uno::Any& Arg3, const css::uno::Any& Arg4, const css::uno::Any& Arg5, const css::uno::Any& Arg6, const css::uno::Any& Arg7, const css::uno::Any& Arg8, const css::uno::Any& Arg9, const css::uno::Any& Arg10, const css::uno::Any& Arg11, const css::uno::Any& Arg12, const css::uno::Any& Arg13, const css::uno::Any& Arg14, const css::uno::Any& Arg15, const css::uno::Any& Arg16, const css::uno::Any& Arg17, const css::uno::Any& Arg18, const css::uno::Any& Arg19, const css::uno::Any& Arg20, const css::uno::Any& Arg21, const css::uno::Any& Arg22, const css::uno::Any& Arg23, const css::uno::Any& Arg24, const css::uno::Any& Arg25, const css::uno::Any& Arg26, const css::uno::Any& Arg27, const css::uno::Any& Arg28, const css::uno::Any& Arg29, const css::uno::Any& Arg30 ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
192 return getApplication()->Union( Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9, Arg10, Arg11, Arg12, Arg13, Arg14, Arg15, Arg16, Arg17, Arg18, Arg19, Arg20, Arg21, Arg22, Arg23, Arg24, Arg25, Arg26, Arg27, Arg28, Arg29, Arg30 );
194 css::uno::Reference< ov::excel::XRange > SAL_CALL
195 ScVbaGlobals::Intersect( const css::uno::Reference< ov::excel::XRange >& Arg1, const css::uno::Reference< ov::excel::XRange >& Arg2, const css::uno::Any& Arg3, const css::uno::Any& Arg4, const css::uno::Any& Arg5, const css::uno::Any& Arg6, const css::uno::Any& Arg7, const css::uno::Any& Arg8, const css::uno::Any& Arg9, const css::uno::Any& Arg10, const css::uno::Any& Arg11, const css::uno::Any& Arg12, const css::uno::Any& Arg13, const css::uno::Any& Arg14, const css::uno::Any& Arg15, const css::uno::Any& Arg16, const css::uno::Any& Arg17, const css::uno::Any& Arg18, const css::uno::Any& Arg19, const css::uno::Any& Arg20, const css::uno::Any& Arg21, const css::uno::Any& Arg22, const css::uno::Any& Arg23, const css::uno::Any& Arg24, const css::uno::Any& Arg25, const css::uno::Any& Arg26, const css::uno::Any& Arg27, const css::uno::Any& Arg28, const css::uno::Any& Arg29, const css::uno::Any& Arg30 ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
197 return getApplication()->Intersect( Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9, Arg10, Arg11, Arg12, Arg13, Arg14, Arg15, Arg16, Arg17, Arg18, Arg19, Arg20, Arg21, Arg22, Arg23, Arg24, Arg25, Arg26, Arg27, Arg28, Arg29, Arg30 );
200 uno::Any SAL_CALL
201 ScVbaGlobals::Evaluate( const ::rtl::OUString& Name ) throw (uno::RuntimeException)
203 return getApplication()->Evaluate( Name );
206 css::uno::Any SAL_CALL
207 ScVbaGlobals::WorksheetFunction( ) throw (css::uno::RuntimeException)
209 return getApplication()->WorksheetFunction();
212 uno::Any SAL_CALL
213 ScVbaGlobals::Windows( const uno::Any& aIndex ) throw (uno::RuntimeException)
215 return getApplication()->Windows( aIndex );
218 uno::Reference< excel::XRange > SAL_CALL
219 ScVbaGlobals::Rows( const uno::Any& aIndex ) throw (uno::RuntimeException)
221 return getApplication()->getActiveSheet()->Rows( aIndex );
225 uno::Any SAL_CALL
226 ScVbaGlobals::MenuBars( const uno::Any& aIndex ) throw (uno::RuntimeException)
228 return uno::Any( getApplication()->MenuBars(aIndex) );
231 uno::Sequence< ::rtl::OUString > SAL_CALL
232 ScVbaGlobals::getAvailableServiceNames( ) throw (uno::RuntimeException)
234 static bool bInit = false;
235 static uno::Sequence< rtl::OUString > serviceNames( ScVbaGlobals_BASE::getAvailableServiceNames() );
236 if ( !bInit )
238 rtl::OUString names[] = {
239 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "ooo.vba.excel.Range" ) ),
240 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "ooo.vba.excel.Workbook" ) ),
241 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "ooo.vba.excel.Window" ) ),
242 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "ooo.vba.excel.Worksheet" ) ),
243 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "ooo.vba.excel.Application" ) ),
244 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "ooo.vba.excel.Hyperlink" ) ),
246 sal_Int32 nExcelServices = ( sizeof( names )/ sizeof( names[0] ) );
247 sal_Int32 startIndex = serviceNames.getLength();
248 serviceNames.realloc( serviceNames.getLength() + nExcelServices );
249 for ( sal_Int32 index = 0; index < nExcelServices; ++index )
250 serviceNames[ startIndex + index ] = names[ index ];
251 bInit = true;
253 return serviceNames;
256 rtl::OUString&
257 ScVbaGlobals::getServiceImplName()
259 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaGlobals") );
260 return sImplName;
263 uno::Sequence< rtl::OUString >
264 ScVbaGlobals::getServiceNames()
266 static uno::Sequence< rtl::OUString > aServiceNames;
267 if ( aServiceNames.getLength() == 0 )
269 aServiceNames.realloc( 1 );
270 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Globals" ) );
272 return aServiceNames;
275 namespace globals
277 namespace sdecl = comphelper::service_decl;
278 sdecl::vba_service_class_<ScVbaGlobals, sdecl::with_args<true> > serviceImpl;
279 extern sdecl::ServiceDecl const serviceDecl(
280 serviceImpl,
281 "ScVbaGlobals",
282 "ooo.vba.excel.Globals" );