Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #include "vbaglobals.hxx"
20 :
21 : #include <sal/macros.h>
22 :
23 : #include <comphelper/unwrapargs.hxx>
24 :
25 : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
26 : #include <com/sun/star/beans/XPropertySet.hpp>
27 : #include <cppuhelper/component_context.hxx>
28 :
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;
36 :
37 :
38 : // ScVbaGlobals
39 :
40 :
41 : //ScVbaGlobals::ScVbaGlobals( css::uno::Reference< css::uno::XComponentContext >const& rxContext, ) : ScVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext )
42 :
43 0 : ScVbaGlobals::ScVbaGlobals( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& rxContext ) : ScVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext, "ExcelDocumentContext" )
44 : {
45 : OSL_TRACE("ScVbaGlobals::ScVbaGlobals()");
46 :
47 0 : uno::Sequence< beans::PropertyValue > aInitArgs( 2 );
48 0 : aInitArgs[ 0 ].Name = "Application";
49 0 : aInitArgs[ 0 ].Value = uno::makeAny( getApplication() );
50 0 : aInitArgs[ 1 ].Name = "ExcelDocumentContext";
51 0 : aInitArgs[ 1 ].Value = uno::makeAny( getXSomethingFromArgs< frame::XModel >( aArgs, 0 ) );
52 :
53 0 : init( aInitArgs );
54 0 : }
55 :
56 0 : ScVbaGlobals::~ScVbaGlobals()
57 : {
58 : OSL_TRACE("ScVbaGlobals::~ScVbaGlobals");
59 0 : }
60 :
61 :
62 : // XGlobals
63 :
64 : uno::Reference<excel::XApplication >
65 0 : ScVbaGlobals::getApplication() throw (uno::RuntimeException)
66 : {
67 : // OSL_TRACE("In ScVbaGlobals::getApplication");
68 0 : if ( !mxApplication.is() )
69 0 : mxApplication.set( new ScVbaApplication( mxContext) );
70 0 : return mxApplication;
71 : }
72 :
73 :
74 : uno::Reference<excel::XApplication > SAL_CALL
75 0 : ScVbaGlobals::getExcel() throw (uno::RuntimeException, std::exception)
76 : {
77 0 : return getApplication();
78 : }
79 :
80 : uno::Reference< excel::XWorkbook > SAL_CALL
81 0 : ScVbaGlobals::getActiveWorkbook() throw (uno::RuntimeException, std::exception)
82 : {
83 : // OSL_TRACE("In ScVbaGlobals::getActiveWorkbook");
84 0 : uno::Reference< excel::XWorkbook > xWorkbook( getApplication()->getActiveWorkbook(), uno::UNO_QUERY);
85 0 : if ( xWorkbook.is() )
86 : {
87 0 : return xWorkbook;
88 : }
89 : // FIXME check if this is correct/desired behavior
90 : throw uno::RuntimeException( OUString(
91 0 : "No activeWorkbook available" ), Reference< uno::XInterface >() );
92 : }
93 :
94 :
95 : uno::Reference< excel::XWindow > SAL_CALL
96 0 : ScVbaGlobals::getActiveWindow() throw (uno::RuntimeException, std::exception)
97 : {
98 0 : return getApplication()->getActiveWindow();
99 : }
100 :
101 : uno::Reference< excel::XWorksheet > SAL_CALL
102 0 : ScVbaGlobals::getActiveSheet() throw (uno::RuntimeException, std::exception)
103 : {
104 0 : return getApplication()->getActiveSheet();
105 : }
106 :
107 : uno::Any SAL_CALL
108 0 : ScVbaGlobals::WorkBooks( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
109 : {
110 0 : return uno::Any( getApplication()->Workbooks(aIndex) );
111 : }
112 :
113 : uno::Any SAL_CALL
114 0 : ScVbaGlobals::WorkSheets(const uno::Any& aIndex) throw (uno::RuntimeException, std::exception)
115 : {
116 0 : return getApplication()->Worksheets( aIndex );
117 : }
118 : uno::Any SAL_CALL
119 0 : ScVbaGlobals::Sheets( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
120 : {
121 0 : return WorkSheets( aIndex );
122 : }
123 :
124 : uno::Any SAL_CALL
125 0 : ScVbaGlobals::Range( const uno::Any& Cell1, const uno::Any& Cell2 ) throw (uno::RuntimeException, std::exception)
126 : {
127 0 : return getApplication()->Range( Cell1, Cell2 );
128 : }
129 :
130 : uno::Any SAL_CALL
131 0 : ScVbaGlobals::Names( const css::uno::Any& aIndex ) throw ( uno::RuntimeException, std::exception )
132 : {
133 0 : return getApplication()->Names( aIndex );
134 : }
135 :
136 : uno::Reference< excel::XRange > SAL_CALL
137 0 : ScVbaGlobals::getActiveCell() throw (uno::RuntimeException, std::exception)
138 : {
139 0 : return getApplication()->getActiveCell();
140 : }
141 :
142 : uno::Reference< XAssistant > SAL_CALL
143 0 : ScVbaGlobals::getAssistant() throw (uno::RuntimeException, std::exception)
144 : {
145 0 : return getApplication()->getAssistant();
146 : }
147 :
148 : uno::Any SAL_CALL
149 0 : ScVbaGlobals::getSelection() throw (uno::RuntimeException, std::exception)
150 : {
151 0 : return getApplication()->getSelection();
152 : }
153 :
154 : uno::Reference< excel::XWorkbook > SAL_CALL
155 0 : ScVbaGlobals::getThisWorkbook() throw (uno::RuntimeException, std::exception)
156 : {
157 0 : return getApplication()->getThisWorkbook();
158 : }
159 : void SAL_CALL
160 0 : ScVbaGlobals::Calculate() throw (::com::sun::star::script::BasicErrorException, ::com::sun::star::uno::RuntimeException, std::exception)
161 : {
162 0 : return getApplication()->Calculate();
163 : }
164 :
165 : uno::Reference< excel::XRange > SAL_CALL
166 0 : ScVbaGlobals::Cells( const uno::Any& RowIndex, const uno::Any& ColumnIndex ) throw (uno::RuntimeException, std::exception)
167 : {
168 0 : return getApplication()->getActiveSheet()->Cells( RowIndex, ColumnIndex );
169 : }
170 : uno::Reference< excel::XRange > SAL_CALL
171 0 : ScVbaGlobals::Columns( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
172 : {
173 0 : return getApplication()->getActiveSheet()->Columns( aIndex );
174 : }
175 :
176 : uno::Any SAL_CALL
177 0 : ScVbaGlobals::CommandBars( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
178 : {
179 0 : uno::Reference< XApplicationBase > xBase( getApplication(), uno::UNO_QUERY_THROW );
180 0 : return xBase->CommandBars( aIndex );
181 : }
182 :
183 : css::uno::Reference< ov::excel::XRange > SAL_CALL
184 0 : 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)
185 : {
186 0 : 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 );
187 : }
188 : css::uno::Reference< ov::excel::XRange > SAL_CALL
189 0 : 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)
190 : {
191 0 : 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 );
192 : }
193 :
194 : uno::Any SAL_CALL
195 0 : ScVbaGlobals::Evaluate( const OUString& Name ) throw (uno::RuntimeException, std::exception)
196 : {
197 0 : return getApplication()->Evaluate( Name );
198 : }
199 :
200 : css::uno::Any SAL_CALL
201 0 : ScVbaGlobals::WorksheetFunction( ) throw (css::uno::RuntimeException, std::exception)
202 : {
203 0 : return getApplication()->WorksheetFunction();
204 : }
205 :
206 : uno::Any SAL_CALL
207 0 : ScVbaGlobals::Windows( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
208 : {
209 0 : return getApplication()->Windows( aIndex );
210 : }
211 :
212 : uno::Reference< excel::XRange > SAL_CALL
213 0 : ScVbaGlobals::Rows( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
214 : {
215 0 : return getApplication()->getActiveSheet()->Rows( aIndex );
216 :
217 : }
218 :
219 :
220 : uno::Any SAL_CALL
221 0 : ScVbaGlobals::getDebug() throw (uno::RuntimeException, std::exception)
222 : {
223 : try // return empty object on error
224 : {
225 0 : uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW );
226 0 : uno::Reference< uno::XInterface > xVBADebug = xServiceManager->createInstanceWithContext(
227 0 : OUString( "ooo.vba.Debug" ), mxContext );
228 0 : return uno::Any( xVBADebug );
229 : }
230 0 : catch( uno::Exception& )
231 : {
232 : }
233 0 : return uno::Any();
234 : }
235 :
236 : uno::Any SAL_CALL
237 0 : ScVbaGlobals::MenuBars( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
238 : {
239 0 : return uno::Any( getApplication()->MenuBars(aIndex) );
240 : }
241 :
242 : uno::Sequence< OUString > SAL_CALL
243 0 : ScVbaGlobals::getAvailableServiceNames( ) throw (uno::RuntimeException, std::exception)
244 : {
245 : static bool bInit = false;
246 0 : static uno::Sequence< OUString > serviceNames( ScVbaGlobals_BASE::getAvailableServiceNames() );
247 0 : if ( !bInit )
248 : {
249 : OUString names[] = {
250 : OUString( "ooo.vba.excel.Range" ),
251 : OUString( "ooo.vba.excel.Workbook" ),
252 : OUString( "ooo.vba.excel.Window" ),
253 : OUString( "ooo.vba.excel.Worksheet" ),
254 : OUString( "ooo.vba.excel.Application" ),
255 : OUString( "ooo.vba.excel.Hyperlink" ),
256 : OUString( "com.sun.star.script.vba.VBASpreadsheetEventProcessor" )
257 0 : };
258 0 : sal_Int32 nExcelServices = ( sizeof( names )/ sizeof( names[0] ) );
259 0 : sal_Int32 startIndex = serviceNames.getLength();
260 0 : serviceNames.realloc( serviceNames.getLength() + nExcelServices );
261 0 : for ( sal_Int32 index = 0; index < nExcelServices; ++index )
262 0 : serviceNames[ startIndex + index ] = names[ index ];
263 0 : bInit = true;
264 : }
265 0 : return serviceNames;
266 : }
267 :
268 : OUString
269 0 : ScVbaGlobals::getServiceImplName()
270 : {
271 0 : return OUString("ScVbaGlobals");
272 : }
273 :
274 : uno::Sequence< OUString >
275 0 : ScVbaGlobals::getServiceNames()
276 : {
277 0 : static uno::Sequence< OUString > aServiceNames;
278 0 : if ( aServiceNames.getLength() == 0 )
279 : {
280 0 : aServiceNames.realloc( 1 );
281 0 : aServiceNames[ 0 ] = "ooo.vba.excel.Globals" ;
282 : }
283 0 : return aServiceNames;
284 : }
285 :
286 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
287 0 : ScVbaGlobals_get_implementation(
288 : css::uno::XComponentContext *context,
289 : css::uno::Sequence<css::uno::Any> const &arguments)
290 : {
291 0 : return cppu::acquire(new ScVbaGlobals(arguments, context));
292 : }
293 :
294 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|