1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include <vbahelper/helperdecl.hxx>
20 #include "vbaglobals.hxx"
22 #include <sal/macros.h>
24 #include <comphelper/unwrapargs.hxx>
26 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <cppuhelper/component_context.hxx>
30 #include "vbaapplication.hxx"
31 #include "vbaworksheet.hxx"
32 #include "vbarange.hxx"
33 #include <cppuhelper/bootstrap.hxx>
34 using namespace ::com::sun::star
;
35 using namespace ::com::sun::star::uno
;
36 using namespace ::ooo::vba
;
40 // =============================================================================
42 // =============================================================================
44 //ScVbaGlobals::ScVbaGlobals( css::uno::Reference< css::uno::XComponentContext >const& rxContext, ) : ScVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext )
45 OUString
sDocCtxName( "ExcelDocumentContext" );
47 ScVbaGlobals::ScVbaGlobals( uno::Sequence
< uno::Any
> const& aArgs
, uno::Reference
< uno::XComponentContext
>const& rxContext
) : ScVbaGlobals_BASE( uno::Reference
< XHelperInterface
>(), rxContext
, sDocCtxName
)
49 OSL_TRACE("ScVbaGlobals::ScVbaGlobals()");
51 uno::Sequence
< beans::PropertyValue
> aInitArgs( 2 );
52 aInitArgs
[ 0 ].Name
= OUString("Application");
53 aInitArgs
[ 0 ].Value
= uno::makeAny( getApplication() );
54 aInitArgs
[ 1 ].Name
= sDocCtxName
;
55 aInitArgs
[ 1 ].Value
= uno::makeAny( getXSomethingFromArgs
< frame::XModel
>( aArgs
, 0 ) );
60 ScVbaGlobals::~ScVbaGlobals()
62 OSL_TRACE("ScVbaGlobals::~ScVbaGlobals");
65 // =============================================================================
67 // =============================================================================
68 uno::Reference
<excel::XApplication
>
69 ScVbaGlobals::getApplication() throw (uno::RuntimeException
)
71 // OSL_TRACE("In ScVbaGlobals::getApplication");
72 if ( !mxApplication
.is() )
73 mxApplication
.set( new ScVbaApplication( mxContext
) );
78 uno::Reference
<excel::XApplication
> SAL_CALL
79 ScVbaGlobals::getExcel() throw (uno::RuntimeException
)
81 return getApplication();
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
);
95 // FIXME check if this is correct/desired behavior
96 throw uno::RuntimeException( OUString(
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();
114 ScVbaGlobals::WorkBooks( const uno::Any
& aIndex
) throw (uno::RuntimeException
)
116 return uno::Any( getApplication()->Workbooks(aIndex
) );
120 ScVbaGlobals::WorkSheets(const uno::Any
& aIndex
) throw (uno::RuntimeException
)
122 return getApplication()->Worksheets( aIndex
);
125 ScVbaGlobals::Sheets( const uno::Any
& aIndex
) throw (uno::RuntimeException
)
127 return WorkSheets( aIndex
);
131 ScVbaGlobals::Range( const uno::Any
& Cell1
, const uno::Any
& Cell2
) throw (uno::RuntimeException
)
133 return getApplication()->Range( Cell1
, Cell2
);
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();
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();
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
);
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
);
201 ScVbaGlobals::Evaluate( const 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();
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
);
227 ScVbaGlobals::getDebug() throw (uno::RuntimeException
)
229 try // return empty object on error
231 uno::Reference
< lang::XMultiComponentFactory
> xServiceManager( mxContext
->getServiceManager(), uno::UNO_SET_THROW
);
232 uno::Reference
< uno::XInterface
> xVBADebug
= xServiceManager
->createInstanceWithContext(
233 OUString( "ooo.vba.Debug" ), mxContext
);
234 return uno::Any( xVBADebug
);
236 catch( uno::Exception
& )
243 ScVbaGlobals::MenuBars( const uno::Any
& aIndex
) throw (uno::RuntimeException
)
245 return uno::Any( getApplication()->MenuBars(aIndex
) );
248 uno::Sequence
< OUString
> SAL_CALL
249 ScVbaGlobals::getAvailableServiceNames( ) throw (uno::RuntimeException
)
251 static bool bInit
= false;
252 static uno::Sequence
< OUString
> serviceNames( ScVbaGlobals_BASE::getAvailableServiceNames() );
256 OUString( "ooo.vba.excel.Range" ),
257 OUString( "ooo.vba.excel.Workbook" ),
258 OUString( "ooo.vba.excel.Window" ),
259 OUString( "ooo.vba.excel.Worksheet" ),
260 OUString( "ooo.vba.excel.Application" ),
261 OUString( "ooo.vba.excel.Hyperlink" ),
262 OUString( "com.sun.star.script.vba.VBASpreadsheetEventProcessor" )
264 sal_Int32 nExcelServices
= ( sizeof( names
)/ sizeof( names
[0] ) );
265 sal_Int32 startIndex
= serviceNames
.getLength();
266 serviceNames
.realloc( serviceNames
.getLength() + nExcelServices
);
267 for ( sal_Int32 index
= 0; index
< nExcelServices
; ++index
)
268 serviceNames
[ startIndex
+ index
] = names
[ index
];
275 ScVbaGlobals::getServiceImplName()
277 return OUString("ScVbaGlobals");
280 uno::Sequence
< OUString
>
281 ScVbaGlobals::getServiceNames()
283 static uno::Sequence
< OUString
> aServiceNames
;
284 if ( aServiceNames
.getLength() == 0 )
286 aServiceNames
.realloc( 1 );
287 aServiceNames
[ 0 ] = OUString( "ooo.vba.excel.Globals" );
289 return aServiceNames
;
294 namespace sdecl
= comphelper::service_decl
;
295 sdecl::vba_service_class_
<ScVbaGlobals
, sdecl::with_args
<true> > serviceImpl
;
296 extern sdecl::ServiceDecl
const serviceDecl(
299 "ooo.vba.excel.Globals" );
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */