LibreOffice Module sc (master)  1
vbaglobals.cxx
Go to the documentation of this file.
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 <com/sun/star/lang/XMultiComponentFactory.hpp>
22 #include <comphelper/sequence.hxx>
23 #include <com/sun/star/beans/PropertyValue.hpp>
24 #include <com/sun/star/frame/XModel.hpp>
25 
26 #include "vbaapplication.hxx"
27 
28 using namespace ::com::sun::star;
29 using namespace ::com::sun::star::uno;
30 using namespace ::ooo::vba;
31 
32 // ScVbaGlobals
33 
34 //ScVbaGlobals::ScVbaGlobals( css::uno::Reference< css::uno::XComponentContext >const& rxContext, ) : ScVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext )
35 
36 ScVbaGlobals::ScVbaGlobals( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& rxContext ) : ScVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext, "ExcelDocumentContext" )
37 {
38  uno::Sequence< beans::PropertyValue > aInitArgs( aArgs.getLength() + 1 );
39  aInitArgs[ 0 ].Name = "Application";
40  aInitArgs[ 0 ].Value <<= getApplication();
41  if ( aArgs.hasElements() )
42  {
43  aInitArgs[ 1 ].Name = "ExcelDocumentContext";
44  aInitArgs[ 1 ].Value <<= getXSomethingFromArgs< frame::XModel >( aArgs, 0 );
45  }
46  init( aInitArgs );
47 }
48 
50 {
51 }
52 
53 // XGlobals
54 
55 uno::Reference<excel::XApplication > const &
57 {
58  if ( !mxApplication.is() )
60  return mxApplication;
61 }
62 
63 uno::Reference<excel::XApplication > SAL_CALL
65 {
66  return getApplication();
67 }
68 
69 uno::Reference< excel::XWorkbook > SAL_CALL
71 {
72  uno::Reference< excel::XWorkbook > xWorkbook( getApplication()->getActiveWorkbook(), uno::UNO_SET_THROW);
73  return xWorkbook;
74 }
75 
76 uno::Reference< excel::XWindow > SAL_CALL
78 {
79  return getApplication()->getActiveWindow();
80 }
81 
82 uno::Reference< excel::XWorksheet > SAL_CALL
84 {
85  return getApplication()->getActiveSheet();
86 }
87 
88 uno::Any SAL_CALL
90 {
91  return getApplication()->Workbooks(aIndex);
92 }
93 
94 uno::Any SAL_CALL
96 {
97  return getApplication()->Worksheets( aIndex );
98 }
99 uno::Any SAL_CALL
101 {
102  return WorkSheets( aIndex );
103 }
104 
105 uno::Any SAL_CALL
106 ScVbaGlobals::Range( const uno::Any& Cell1, const uno::Any& Cell2 )
107 {
108  return getApplication()->Range( Cell1, Cell2 );
109 }
110 
111 uno::Any SAL_CALL
112 ScVbaGlobals::Names( const css::uno::Any& aIndex )
113 {
114  return getApplication()->Names( aIndex );
115 }
116 
117 uno::Reference< excel::XRange > SAL_CALL
119 {
120  return getApplication()->getActiveCell();
121 }
122 
123 uno::Reference< XAssistant > SAL_CALL
125 {
126  return getApplication()->getAssistant();
127 }
128 
129 uno::Any SAL_CALL
131 {
132  return getApplication()->getSelection();
133 }
134 
135 uno::Reference< excel::XWorkbook > SAL_CALL
137 {
138  return getApplication()->getThisWorkbook();
139 }
140 void SAL_CALL
142 {
143  return getApplication()->Calculate();
144 }
145 
146 uno::Reference< excel::XRange > SAL_CALL
147 ScVbaGlobals::Cells( const uno::Any& RowIndex, const uno::Any& ColumnIndex )
148 {
149  return getApplication()->getActiveSheet()->Cells( RowIndex, ColumnIndex );
150 }
151 uno::Reference< excel::XRange > SAL_CALL
153 {
154  return getApplication()->getActiveSheet()->Columns( aIndex );
155 }
156 
157 uno::Any SAL_CALL
159 {
160  uno::Reference< XApplicationBase > xBase( getApplication(), uno::UNO_QUERY_THROW );
161  return xBase->CommandBars( aIndex );
162 }
163 
164 css::uno::Reference< ov::excel::XRange > SAL_CALL
165 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 )
166 {
167  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 );
168 }
169 css::uno::Reference< ov::excel::XRange > SAL_CALL
170 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 )
171 {
172  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 );
173 }
174 
175 uno::Any SAL_CALL
176 ScVbaGlobals::Evaluate( const OUString& Name )
177 {
178  return getApplication()->Evaluate( Name );
179 }
180 
181 css::uno::Any SAL_CALL
183 {
184  return getApplication()->WorksheetFunction();
185 }
186 
187 uno::Any SAL_CALL
189 {
190  return getApplication()->Windows( aIndex );
191 }
192 
193 uno::Reference< excel::XRange > SAL_CALL
194 ScVbaGlobals::Rows( const uno::Any& aIndex )
195 {
196  return getApplication()->getActiveSheet()->Rows( aIndex );
197 
198 }
199 
200 uno::Any SAL_CALL
202 {
203  try // return empty object on error
204  {
205  uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW );
206  uno::Reference< uno::XInterface > xVBADebug = xServiceManager->createInstanceWithContext(
207  "ooo.vba.Debug", mxContext );
208  return uno::Any( xVBADebug );
209  }
210  catch( uno::Exception& )
211  {
212  }
213  return uno::Any();
214 }
215 
216 uno::Any SAL_CALL
218 {
219  return getApplication()->MenuBars(aIndex);
220 }
221 
222 uno::Sequence< OUString > SAL_CALL
224 {
225  static const uno::Sequence< OUString > serviceNames = comphelper::concatSequences(
226  ScVbaGlobals_BASE::getAvailableServiceNames(),
227  uno::Sequence< OUString >
228  {
229  "ooo.vba.excel.Range",
230  "ooo.vba.excel.Workbook",
231  "ooo.vba.excel.Window",
232  "ooo.vba.excel.Worksheet",
233  "ooo.vba.excel.Application",
234  "ooo.vba.excel.Hyperlink",
235  "com.sun.star.script.vba.VBASpreadsheetEventProcessor"
236  } );
237  return serviceNames;
238 }
239 
240 OUString
242 {
243  return "ScVbaGlobals";
244 }
245 
246 uno::Sequence< OUString >
248 {
249  static uno::Sequence< OUString > aServiceNames
250  {
251  "ooo.vba.excel.Globals"
252  };
253  return aServiceNames;
254 }
255 
256 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
258  css::uno::XComponentContext *context,
259  css::uno::Sequence<css::uno::Any> const &arguments)
260 {
261  return cppu::acquire(new ScVbaGlobals(arguments, context));
262 }
263 
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
uno::Reference< uno::XComponentContext > mxContext
::cppu::ImplInheritanceHelper< VbaGlobalsBase, ov::excel::XGlobals > ScVbaGlobals_BASE
Definition: vbaglobals.hxx:32
Reference
Sequence< OUString > aServiceNames
css::uno::Reference< ov::excel::XApplication > mxApplication
Definition: vbaglobals.hxx:36
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbaglobals.cxx:247
virtual css::uno::Any SAL_CALL Sheets(const css::uno::Any &aIndex) override
Definition: vbaglobals.cxx:100
css::uno::Reference< ov::excel::XApplication > const & getApplication()
Definition: vbaglobals.cxx:56
virtual OUString getServiceImplName() override
Definition: vbaglobals.cxx:241
virtual void SAL_CALL Calculate() override
Definition: vbaglobals.cxx:141
virtual css::uno::Any SAL_CALL WorkBooks(const css::uno::Any &aIndex) override
Definition: vbaglobals.cxx:89
virtual css::uno::Reference< ov::excel::XRange > SAL_CALL 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) override
Definition: vbaglobals.cxx:170
virtual css::uno::Reference< ov::excel::XApplication > SAL_CALL getExcel() override
Definition: vbaglobals.cxx:64
virtual css::uno::Any SAL_CALL CommandBars(const css::uno::Any &aIndex) override
Definition: vbaglobals.cxx:158
virtual css::uno::Reference< ov::excel::XWorkbook > SAL_CALL getThisWorkbook() override
Definition: vbaglobals.cxx:136
virtual css::uno::Any SAL_CALL getSelection() override
Definition: vbaglobals.cxx:130
virtual css::uno::Reference< ::ooo::vba::excel::XRange > SAL_CALL Rows(const css::uno::Any &aIndex) override
Definition: vbaglobals.cxx:194
virtual css::uno::Reference< ov::excel::XRange > SAL_CALL 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) override
Definition: vbaglobals.cxx:165
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &...rSn)
virtual css::uno::Reference< ov::excel::XWorkbook > SAL_CALL getActiveWorkbook() override
Definition: vbaglobals.cxx:70
virtual css::uno::Any SAL_CALL getDebug() override
Definition: vbaglobals.cxx:201
virtual css::uno::Any SAL_CALL Names(const css::uno::Any &aIndex) override
Definition: vbaglobals.cxx:112
virtual css::uno::Any SAL_CALL WorkSheets(const css::uno::Any &aIndex) override
Definition: vbaglobals.cxx:95
virtual css::uno::Any SAL_CALL Evaluate(const OUString &Name) override
Definition: vbaglobals.cxx:176
virtual css::uno::Any SAL_CALL MenuBars(const css::uno::Any &aIndex) override
Definition: vbaglobals.cxx:217
virtual css::uno::Reference< ov::excel::XWindow > SAL_CALL getActiveWindow() override
Definition: vbaglobals.cxx:77
ScVbaGlobals(css::uno::Sequence< css::uno::Any > const &aArgs, css::uno::Reference< css::uno::XComponentContext >const &rxContext)
Definition: vbaglobals.cxx:36
virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Columns(const css::uno::Any &aIndex) override
Definition: vbaglobals.cxx:152
FILE * init(int, char **)
virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getActiveCell() override
Definition: vbaglobals.cxx:118
virtual css::uno::Reference< ov::XAssistant > SAL_CALL getAssistant() override
Definition: vbaglobals.cxx:124
virtual css::uno::Reference< ov::excel::XWorksheet > SAL_CALL getActiveSheet() override
Definition: vbaglobals.cxx:83
virtual ~ScVbaGlobals() override
Definition: vbaglobals.cxx:49
virtual css::uno::Sequence< OUString > SAL_CALL getAvailableServiceNames() override
Definition: vbaglobals.cxx:223
virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Cells(const css::uno::Any &RowIndex, const css::uno::Any &ColumnIndex) override
Definition: vbaglobals.cxx:147
virtual css::uno::Any SAL_CALL Windows(const css::uno::Any &aIndex) override
Definition: vbaglobals.cxx:188
virtual css::uno::Any SAL_CALL WorksheetFunction() override
Definition: vbaglobals.cxx:182
virtual css::uno::Any SAL_CALL Range(const css::uno::Any &Cell1, const css::uno::Any &Cell2) override
Definition: vbaglobals.cxx:106
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * ScVbaGlobals_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &arguments)
Definition: vbaglobals.cxx:257