fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / vba / vbaglobals.cxx
blobf6477be468c9682cd024ed522870d40321bf36be
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "vbaglobals.hxx"
21 #include <sal/macros.h>
23 #include <comphelper/unwrapargs.hxx>
25 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <cppuhelper/component_context.hxx>
29 #include "vbaapplication.hxx"
30 #include "vbaworksheet.hxx"
31 #include "vbarange.hxx"
32 #include <cppuhelper/bootstrap.hxx>
33 using namespace ::com::sun::star;
34 using namespace ::com::sun::star::uno;
35 using namespace ::ooo::vba;
37 // ScVbaGlobals
39 //ScVbaGlobals::ScVbaGlobals( css::uno::Reference< css::uno::XComponentContext >const& rxContext, ) : ScVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext )
41 ScVbaGlobals::ScVbaGlobals( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& rxContext ) : ScVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext, "ExcelDocumentContext" )
43 OSL_TRACE("ScVbaGlobals::ScVbaGlobals()");
45 uno::Sequence< beans::PropertyValue > aInitArgs( 2 );
46 aInitArgs[ 0 ].Name = "Application";
47 aInitArgs[ 0 ].Value = uno::makeAny( getApplication() );
48 aInitArgs[ 1 ].Name = "ExcelDocumentContext";
49 aInitArgs[ 1 ].Value = uno::makeAny( getXSomethingFromArgs< frame::XModel >( aArgs, 0 ) );
51 init( aInitArgs );
54 ScVbaGlobals::~ScVbaGlobals()
56 OSL_TRACE("ScVbaGlobals::~ScVbaGlobals");
59 // XGlobals
61 uno::Reference<excel::XApplication >
62 ScVbaGlobals::getApplication() throw (uno::RuntimeException)
64 // OSL_TRACE("In ScVbaGlobals::getApplication");
65 if ( !mxApplication.is() )
66 mxApplication.set( new ScVbaApplication( mxContext) );
67 return mxApplication;
70 uno::Reference<excel::XApplication > SAL_CALL
71 ScVbaGlobals::getExcel() throw (uno::RuntimeException, std::exception)
73 return getApplication();
76 uno::Reference< excel::XWorkbook > SAL_CALL
77 ScVbaGlobals::getActiveWorkbook() throw (uno::RuntimeException, std::exception)
79 // OSL_TRACE("In ScVbaGlobals::getActiveWorkbook");
80 uno::Reference< excel::XWorkbook > xWorkbook( getApplication()->getActiveWorkbook(), uno::UNO_QUERY);
81 if ( xWorkbook.is() )
83 return xWorkbook;
85 // FIXME check if this is correct/desired behavior
86 throw uno::RuntimeException( "No activeWorkbook available" );
89 uno::Reference< excel::XWindow > SAL_CALL
90 ScVbaGlobals::getActiveWindow() throw (uno::RuntimeException, std::exception)
92 return getApplication()->getActiveWindow();
95 uno::Reference< excel::XWorksheet > SAL_CALL
96 ScVbaGlobals::getActiveSheet() throw (uno::RuntimeException, std::exception)
98 return getApplication()->getActiveSheet();
101 uno::Any SAL_CALL
102 ScVbaGlobals::WorkBooks( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
104 return uno::Any( getApplication()->Workbooks(aIndex) );
107 uno::Any SAL_CALL
108 ScVbaGlobals::WorkSheets(const uno::Any& aIndex) throw (uno::RuntimeException, std::exception)
110 return getApplication()->Worksheets( aIndex );
112 uno::Any SAL_CALL
113 ScVbaGlobals::Sheets( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
115 return WorkSheets( aIndex );
118 uno::Any SAL_CALL
119 ScVbaGlobals::Range( const uno::Any& Cell1, const uno::Any& Cell2 ) throw (uno::RuntimeException, std::exception)
121 return getApplication()->Range( Cell1, Cell2 );
124 uno::Any SAL_CALL
125 ScVbaGlobals::Names( const css::uno::Any& aIndex ) throw ( uno::RuntimeException, std::exception )
127 return getApplication()->Names( aIndex );
130 uno::Reference< excel::XRange > SAL_CALL
131 ScVbaGlobals::getActiveCell() throw (uno::RuntimeException, std::exception)
133 return getApplication()->getActiveCell();
136 uno::Reference< XAssistant > SAL_CALL
137 ScVbaGlobals::getAssistant() throw (uno::RuntimeException, std::exception)
139 return getApplication()->getAssistant();
142 uno::Any SAL_CALL
143 ScVbaGlobals::getSelection() throw (uno::RuntimeException, std::exception)
145 return getApplication()->getSelection();
148 uno::Reference< excel::XWorkbook > SAL_CALL
149 ScVbaGlobals::getThisWorkbook() throw (uno::RuntimeException, std::exception)
151 return getApplication()->getThisWorkbook();
153 void SAL_CALL
154 ScVbaGlobals::Calculate() throw (::com::sun::star::script::BasicErrorException, ::com::sun::star::uno::RuntimeException, std::exception)
156 return getApplication()->Calculate();
159 uno::Reference< excel::XRange > SAL_CALL
160 ScVbaGlobals::Cells( const uno::Any& RowIndex, const uno::Any& ColumnIndex ) throw (uno::RuntimeException, std::exception)
162 return getApplication()->getActiveSheet()->Cells( RowIndex, ColumnIndex );
164 uno::Reference< excel::XRange > SAL_CALL
165 ScVbaGlobals::Columns( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
167 return getApplication()->getActiveSheet()->Columns( aIndex );
170 uno::Any SAL_CALL
171 ScVbaGlobals::CommandBars( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
173 uno::Reference< XApplicationBase > xBase( getApplication(), uno::UNO_QUERY_THROW );
174 return xBase->CommandBars( aIndex );
177 css::uno::Reference< ov::excel::XRange > SAL_CALL
178 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, std::exception)
180 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 );
182 css::uno::Reference< ov::excel::XRange > SAL_CALL
183 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, std::exception)
185 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 );
188 uno::Any SAL_CALL
189 ScVbaGlobals::Evaluate( const OUString& Name ) throw (uno::RuntimeException, std::exception)
191 return getApplication()->Evaluate( Name );
194 css::uno::Any SAL_CALL
195 ScVbaGlobals::WorksheetFunction( ) throw (css::uno::RuntimeException, std::exception)
197 return getApplication()->WorksheetFunction();
200 uno::Any SAL_CALL
201 ScVbaGlobals::Windows( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
203 return getApplication()->Windows( aIndex );
206 uno::Reference< excel::XRange > SAL_CALL
207 ScVbaGlobals::Rows( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
209 return getApplication()->getActiveSheet()->Rows( aIndex );
213 uno::Any SAL_CALL
214 ScVbaGlobals::getDebug() throw (uno::RuntimeException, std::exception)
216 try // return empty object on error
218 uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW );
219 uno::Reference< uno::XInterface > xVBADebug = xServiceManager->createInstanceWithContext(
220 OUString( "ooo.vba.Debug" ), mxContext );
221 return uno::Any( xVBADebug );
223 catch( uno::Exception& )
226 return uno::Any();
229 uno::Any SAL_CALL
230 ScVbaGlobals::MenuBars( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
232 return uno::Any( getApplication()->MenuBars(aIndex) );
235 uno::Sequence< OUString > SAL_CALL
236 ScVbaGlobals::getAvailableServiceNames( ) throw (uno::RuntimeException, std::exception)
238 static bool bInit = false;
239 static uno::Sequence< OUString > serviceNames( ScVbaGlobals_BASE::getAvailableServiceNames() );
240 if ( !bInit )
242 OUString names[] = {
243 OUString( "ooo.vba.excel.Range" ),
244 OUString( "ooo.vba.excel.Workbook" ),
245 OUString( "ooo.vba.excel.Window" ),
246 OUString( "ooo.vba.excel.Worksheet" ),
247 OUString( "ooo.vba.excel.Application" ),
248 OUString( "ooo.vba.excel.Hyperlink" ),
249 OUString( "com.sun.star.script.vba.VBASpreadsheetEventProcessor" )
251 sal_Int32 nExcelServices = ( sizeof( names )/ sizeof( names[0] ) );
252 sal_Int32 startIndex = serviceNames.getLength();
253 serviceNames.realloc( serviceNames.getLength() + nExcelServices );
254 for ( sal_Int32 index = 0; index < nExcelServices; ++index )
255 serviceNames[ startIndex + index ] = names[ index ];
256 bInit = true;
258 return serviceNames;
261 OUString
262 ScVbaGlobals::getServiceImplName()
264 return OUString("ScVbaGlobals");
267 uno::Sequence< OUString >
268 ScVbaGlobals::getServiceNames()
270 static uno::Sequence< OUString > aServiceNames;
271 if ( aServiceNames.getLength() == 0 )
273 aServiceNames.realloc( 1 );
274 aServiceNames[ 0 ] = "ooo.vba.excel.Globals" ;
276 return aServiceNames;
279 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
280 ScVbaGlobals_get_implementation(
281 css::uno::XComponentContext *context,
282 css::uno::Sequence<css::uno::Any> const &arguments)
284 return cppu::acquire(new ScVbaGlobals(arguments, context));
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */