Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <stdio.h>
30 : :
31 : : #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
32 : : #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
33 : : #include <com/sun/star/sheet/XSpreadsheetView.hpp>
34 : : #include <com/sun/star/sheet/XSpreadsheets.hpp>
35 : : #include <com/sun/star/view/XSelectionSupplier.hpp>
36 : : #include <com/sun/star/lang/XServiceInfo.hpp>
37 : : #include <ooo/vba/excel/XlCalculation.hpp>
38 : : #include <ooo/vba/excel/XlCutCopyMode.hpp>
39 : : #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
40 : : #include <com/sun/star/sheet/XCalculatable.hpp>
41 : : #include <com/sun/star/frame/XLayoutManager.hpp>
42 : : #include <com/sun/star/task/XStatusIndicatorSupplier.hpp>
43 : : #include <com/sun/star/task/XStatusIndicator.hpp>
44 : : #include <ooo/vba/excel/XlMousePointer.hpp>
45 : : #include <com/sun/star/sheet/XNamedRanges.hpp>
46 : : #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
47 : : #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
48 : : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
49 : : #include <com/sun/star/ui/dialogs/XFilePicker2.hpp>
50 : : #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
51 : : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
52 : : #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
53 : : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
54 : : #include<ooo/vba/XCommandBars.hpp>
55 : : #include <ooo/vba/excel/XlEnableCancelKey.hpp>
56 : : #include <ooo/vba/excel/XlApplicationInternational.hpp>
57 : : #include <unotools/localedatawrapper.hxx>
58 : :
59 : : #include "vbaapplication.hxx"
60 : : #include "vbaworkbooks.hxx"
61 : : #include "vbaworkbook.hxx"
62 : : #include "vbaworksheets.hxx"
63 : : #include "vbarange.hxx"
64 : : #include "vbawsfunction.hxx"
65 : : #include "vbadialogs.hxx"
66 : : #include "vbawindow.hxx"
67 : : #include "vbawindows.hxx"
68 : : #include "vbaglobals.hxx"
69 : : #include "vbamenubars.hxx"
70 : : #include "tabvwsh.hxx"
71 : : #include "gridwin.hxx"
72 : : #include "vbanames.hxx"
73 : : #include <vbahelper/vbashape.hxx>
74 : : #include "vbatextboxshape.hxx"
75 : : #include "vbaassistant.hxx"
76 : : #include "vbafilesearch.hxx" // add the support of VBA Application.FileSearch
77 : : #include "sc.hrc"
78 : : #include "macromgr.hxx"
79 : : #include "global.hxx"
80 : : #include "scmod.hxx"
81 : : #include "docoptio.hxx"
82 : : #include "defaultsoptions.hxx"
83 : :
84 : : #include <osl/file.hxx>
85 : : #include <rtl/instance.hxx>
86 : :
87 : : #include <map>
88 : :
89 : : #include <sfx2/request.hxx>
90 : : #include <sfx2/objsh.hxx>
91 : : #include <sfx2/viewfrm.hxx>
92 : : #include <sfx2/app.hxx>
93 : :
94 : : #include <comphelper/processfactory.hxx>
95 : :
96 : : #include <toolkit/awt/vclxwindow.hxx>
97 : : #include <toolkit/helper/vclunohelper.hxx>
98 : :
99 : : #include <tools/diagnose_ex.h>
100 : : #include <tools/urlobj.hxx>
101 : :
102 : : #include <docuno.hxx>
103 : :
104 : : #include <basic/sbx.hxx>
105 : : #include <basic/sbstar.hxx>
106 : : #include <basic/sbuno.hxx>
107 : : #include <basic/sbmeth.hxx>
108 : :
109 : : #include "transobj.hxx"
110 : : #include "convuno.hxx"
111 : : #include "cellsuno.hxx"
112 : : #include "miscuno.hxx"
113 : : #include "unonames.hxx"
114 : : #include "docsh.hxx"
115 : : #include <vbahelper/helperdecl.hxx>
116 : : #include "excelvbahelper.hxx"
117 : :
118 : : #include <basic/sbmod.hxx>
119 : : #include <basic/sbxobj.hxx>
120 : :
121 : : #include "vbafiledialog.hxx"
122 : : #include "viewutil.hxx"
123 : :
124 : : using namespace ::ooo::vba;
125 : : using namespace ::com::sun::star;
126 : : using ::com::sun::star::uno::Reference;
127 : : using ::com::sun::star::uno::UNO_QUERY_THROW;
128 : : using ::com::sun::star::uno::UNO_QUERY;
129 : : using ::rtl::OUString;
130 : :
131 : : // #TODO is this defined somewhere else?
132 : : #if ( defined UNX ) //unix
133 : : #define FILE_PATH_SEPERATOR "/"
134 : : #else // windows
135 : : #define FILE_PATH_SEPERATOR "\\"
136 : : #endif
137 : :
138 [ # # ]: 0 : class ActiveWorkbook : public ScVbaWorkbook
139 : : {
140 : : protected:
141 : 0 : virtual uno::Reference< frame::XModel > getModel()
142 : : {
143 : 0 : return getCurrentExcelDoc(mxContext);
144 : : }
145 : : public:
146 : 0 : ActiveWorkbook( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext) : ScVbaWorkbook( xParent, xContext ){}
147 : : };
148 : :
149 : : // ============================================================================
150 : :
151 : : /** Global application settings shared by all open workbooks. */
152 : : struct ScVbaAppSettings
153 : : {
154 : : sal_Int32 mnCalculation;
155 : : sal_Bool mbDisplayAlerts;
156 : : sal_Bool mbEnableEvents;
157 : : sal_Bool mbExcel4Menus;
158 : : sal_Bool mbDisplayNoteIndicator;
159 : : sal_Bool mbShowWindowsInTaskbar;
160 : : explicit ScVbaAppSettings();
161 : : };
162 : :
163 : 3 : ScVbaAppSettings::ScVbaAppSettings() :
164 : : mnCalculation( excel::XlCalculation::xlCalculationAutomatic ),
165 : : mbDisplayAlerts( sal_True ),
166 : : mbEnableEvents( sal_True ),
167 : : mbExcel4Menus( sal_False ),
168 : : mbDisplayNoteIndicator( sal_True ),
169 : 3 : mbShowWindowsInTaskbar( sal_True )
170 : : {
171 : 3 : }
172 : :
173 : : struct ScVbaStaticAppSettings : public ::rtl::Static< ScVbaAppSettings, ScVbaStaticAppSettings > {};
174 : :
175 : : // ============================================================================
176 : :
177 : 5 : ScVbaApplication::ScVbaApplication( const uno::Reference<uno::XComponentContext >& xContext ) :
178 : : ScVbaApplication_BASE( xContext ),
179 : 5 : mrAppSettings( ScVbaStaticAppSettings::get() )
180 : : {
181 : 5 : }
182 : :
183 : 5 : ScVbaApplication::~ScVbaApplication()
184 : : {
185 [ - + ]: 10 : }
186 : :
187 : 64 : /*static*/ bool ScVbaApplication::getDocumentEventsEnabled()
188 : : {
189 : 64 : return ScVbaStaticAppSettings::get().mbEnableEvents;
190 : : }
191 : :
192 : 0 : SfxObjectShell* ScVbaApplication::GetDocShell( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
193 : : {
194 : 0 : return static_cast< SfxObjectShell* >( excel::getDocShell( xModel ) );
195 : : }
196 : :
197 : : ::rtl::OUString SAL_CALL
198 : 0 : ScVbaApplication::getExactName( const ::rtl::OUString& aApproximateName ) throw (uno::RuntimeException)
199 : : {
200 [ # # ][ # # ]: 0 : uno::Reference< beans::XExactName > xWSF( new ScVbaWSFunction( this, mxContext ) );
[ # # ][ # # ]
201 [ # # ][ # # ]: 0 : return xWSF->getExactName( aApproximateName );
202 : : }
203 : :
204 : : uno::Reference< beans::XIntrospectionAccess > SAL_CALL
205 : 0 : ScVbaApplication::getIntrospection() throw(css::uno::RuntimeException)
206 : : {
207 [ # # ][ # # ]: 0 : uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) );
[ # # ][ # # ]
208 [ # # ][ # # ]: 0 : return xWSF->getIntrospection();
209 : : }
210 : :
211 : : uno::Any SAL_CALL
212 : 0 : ScVbaApplication::invoke( const ::rtl::OUString& FunctionName, const uno::Sequence< uno::Any >& Params, uno::Sequence< sal_Int16 >& OutParamIndex, uno::Sequence< uno::Any >& OutParam) throw(lang::IllegalArgumentException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException)
213 : : {
214 : : /* When calling the functions directly at the Application object, no runtime
215 : : errors are thrown, but the error is inserted into the return value. */
216 : 0 : uno::Any aAny;
217 : : try
218 : : {
219 [ # # ][ # # ]: 0 : uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) );
[ # # ][ # # ]
220 [ # # ][ # # ]: 0 : aAny = xWSF->invoke( FunctionName, Params, OutParamIndex, OutParam );
221 : : }
222 [ # # # # ]: 0 : catch (const uno::Exception&)
223 : : {
224 [ # # # # : 0 : aAny <<= script::BasicErrorException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), 1000, ::rtl::OUString() );
# # ]
225 : : }
226 : 0 : return aAny;
227 : : }
228 : :
229 : : void SAL_CALL
230 : 0 : ScVbaApplication::setValue( const ::rtl::OUString& PropertyName, const uno::Any& Value ) throw(beans::UnknownPropertyException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException)
231 : : {
232 [ # # ][ # # ]: 0 : uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) );
[ # # ][ # # ]
233 [ # # ][ # # ]: 0 : xWSF->setValue( PropertyName, Value );
234 : 0 : }
235 : :
236 : : uno::Any SAL_CALL
237 : 0 : ScVbaApplication::getValue( const ::rtl::OUString& PropertyName ) throw(beans::UnknownPropertyException, uno::RuntimeException)
238 : : {
239 [ # # ][ # # ]: 0 : uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) );
[ # # ][ # # ]
240 [ # # ][ # # ]: 0 : return xWSF->getValue( PropertyName );
241 : : }
242 : :
243 : : sal_Bool SAL_CALL
244 : 0 : ScVbaApplication::hasMethod( const ::rtl::OUString& Name ) throw(uno::RuntimeException)
245 : : {
246 [ # # ][ # # ]: 0 : uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) );
[ # # ][ # # ]
247 [ # # ][ # # ]: 0 : return xWSF->hasMethod( Name );
248 : : }
249 : :
250 : : sal_Bool SAL_CALL
251 : 0 : ScVbaApplication::hasProperty( const ::rtl::OUString& Name ) throw(uno::RuntimeException)
252 : : {
253 [ # # ][ # # ]: 0 : uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) );
[ # # ][ # # ]
254 [ # # ][ # # ]: 0 : return xWSF->hasProperty( Name );
255 : : }
256 : :
257 : : uno::Reference< excel::XWorkbook >
258 : 34 : ScVbaApplication::getActiveWorkbook() throw (uno::RuntimeException)
259 : : {
260 : 34 : uno::Reference< excel::XWorkbook > xWrkbk;
261 [ + - ][ + - ]: 34 : ScDocShell* pShell = excel::getDocShell( getCurrentExcelDoc( mxContext ) );
262 [ + - ]: 34 : if ( pShell )
263 : : {
264 [ + - ]: 34 : String aName;
265 [ + - ]: 34 : if ( pShell->GetDocument() )
266 : : {
267 [ + - ]: 34 : aName = pShell->GetDocument()->GetCodeName();
268 [ + - ][ + - ]: 34 : xWrkbk.set( getUnoDocModule( aName, pShell ), uno::UNO_QUERY );
269 : : // fallback ( e.g. it's possible a new document was created via the api )
270 : : // in that case the document will not have the appropriate Document Modules
271 : : // #TODO #FIXME ( needs to be fixes as part of providing support for an overall document
272 : : // vba mode etc. )
273 [ - + ]: 34 : if ( !xWrkbk.is() )
274 [ # # ][ # # ]: 34 : return new ActiveWorkbook( this, mxContext );
[ # # ][ # # ]
275 [ + - ][ + - ]: 34 : }
276 : : }
277 : 34 : return xWrkbk;
278 : : }
279 : :
280 : : uno::Reference< excel::XWorkbook > SAL_CALL
281 : 0 : ScVbaApplication::getThisWorkbook() throw (uno::RuntimeException)
282 : : {
283 : 0 : uno::Reference< excel::XWorkbook > xWrkbk;
284 [ # # ][ # # ]: 0 : ScDocShell* pShell = excel::getDocShell( getThisExcelDoc( mxContext ) );
285 [ # # ]: 0 : if ( pShell )
286 : : {
287 [ # # ]: 0 : String aName;
288 [ # # ]: 0 : if ( pShell->GetDocument() )
289 : : {
290 [ # # ]: 0 : aName = pShell->GetDocument()->GetCodeName();
291 [ # # ][ # # ]: 0 : xWrkbk.set( getUnoDocModule( aName, pShell ), uno::UNO_QUERY );
292 : : // fallback ( e.g. it's possible a new document was created via the api )
293 : : // in that case the document will not have the appropriate Document Modules
294 : : // #TODO #FIXME ( needs to be fixes as part of providing support for an overall document
295 : : // vba mode etc. )
296 [ # # ]: 0 : if ( !xWrkbk.is() )
297 [ # # ][ # # ]: 0 : return new ActiveWorkbook( this, mxContext );
[ # # ][ # # ]
298 [ # # ][ # # ]: 0 : }
299 : : }
300 : 0 : return xWrkbk;
301 : : }
302 : :
303 : : uno::Reference< XAssistant > SAL_CALL
304 : 0 : ScVbaApplication::getAssistant() throw (uno::RuntimeException)
305 : : {
306 [ # # ][ # # ]: 0 : return uno::Reference< XAssistant >( new ScVbaAssistant( this, mxContext ) );
[ # # ]
307 : : }
308 : :
309 : : // add support of VBA Application.FileSearch
310 : : uno::Reference< XFileSearch > SAL_CALL
311 : 0 : ScVbaApplication::getFileSearch() throw (uno::RuntimeException)
312 : : {
313 [ # # ]: 0 : if (! m_xFileSearch.get() )
314 : : {
315 [ # # ][ # # ]: 0 : m_xFileSearch = uno::Reference< XFileSearch >( new ScVbaFileSearch( this, uno::Reference< XHelperInterface >( this ), mxContext ) );
[ # # ][ # # ]
316 : : }
317 : :
318 : 0 : return m_xFileSearch;
319 : : }
320 : :
321 : : uno::Any SAL_CALL
322 : 0 : ScVbaApplication::getSelection() throw (uno::RuntimeException)
323 : : {
324 : : OSL_TRACE("** ScVbaApplication::getSelection() ** ");
325 [ # # ]: 0 : uno::Reference< frame::XModel > xModel( getCurrentDocument() );
326 : :
327 [ # # ][ # # ]: 0 : Reference< view::XSelectionSupplier > xSelSupp( xModel->getCurrentController(), UNO_QUERY_THROW );
[ # # ]
328 [ # # ]: 0 : Reference< beans::XPropertySet > xPropSet( xSelSupp, UNO_QUERY_THROW );
329 [ # # ]: 0 : OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_FILTERED_RANGE_SELECTION ) );
330 [ # # ][ # # ]: 0 : uno::Any aOldVal = xPropSet->getPropertyValue( aPropName );
331 : 0 : uno::Any any;
332 [ # # ]: 0 : any <<= false;
333 [ # # ][ # # ]: 0 : xPropSet->setPropertyValue( aPropName, any );
334 : : uno::Reference< uno::XInterface > aSelection = ScUnoHelpFunctions::AnyToInterface(
335 [ # # ][ # # ]: 0 : xSelSupp->getSelection() );
[ # # ]
336 [ # # ][ # # ]: 0 : xPropSet->setPropertyValue( aPropName, aOldVal );
337 : :
338 [ # # ]: 0 : if (!aSelection.is())
339 : : {
340 : : throw uno::RuntimeException(
341 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("failed to obtain current selection")),
342 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >() );
343 : : }
344 : :
345 [ # # ]: 0 : uno::Reference< lang::XServiceInfo > xServiceInfo( aSelection, uno::UNO_QUERY_THROW );
346 [ # # ][ # # ]: 0 : rtl::OUString sImplementationName = xServiceInfo->getImplementationName();
347 : :
348 [ # # ]: 0 : if( sImplementationName.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.SvxShapeCollection")) )
349 : : {
350 [ # # ]: 0 : uno::Reference< drawing::XShapes > xShapes( aSelection, uno::UNO_QUERY_THROW );
351 [ # # ]: 0 : uno::Reference< container::XIndexAccess > xIndexAccess( xShapes, uno::UNO_QUERY_THROW );
352 [ # # ][ # # ]: 0 : uno::Reference< drawing::XShape > xShape( xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW );
[ # # ]
353 : : // if ScVbaShape::getType( xShape ) == office::MsoShapeType::msoAutoShape
354 : : // and the uno object implements the com.sun.star.drawing.Text service
355 : : // return a textboxshape object
356 [ # # ][ # # ]: 0 : if ( ScVbaShape::getType( xShape ) == office::MsoShapeType::msoAutoShape )
357 : : {
358 [ # # ]: 0 : uno::Reference< lang::XServiceInfo > xShapeServiceInfo( xShape, uno::UNO_QUERY_THROW );
359 [ # # ][ # # ]: 0 : if ( xShapeServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.Text" ) ) ) )
[ # # ][ # # ]
360 : : {
361 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< msforms::XTextBoxShape >(new ScVbaTextBoxShape( mxContext, xShape, xShapes, xModel ) ) );
[ # # ][ # # ]
362 [ # # ]: 0 : }
363 : : }
364 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< msforms::XShape >(new ScVbaShape( this, mxContext, xShape, xShapes, xModel, ScVbaShape::getType( xShape ) ) ) );
[ # # ][ # # ]
[ # # ][ # # ]
365 : : }
366 [ # # ][ # # ]: 0 : else if( xServiceInfo->supportsService( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SheetCellRange")) ) ||
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
367 [ # # ][ # # ]: 0 : xServiceInfo->supportsService( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SheetCellRanges")) ) )
[ # # ][ # # ]
[ # # ]
368 : : {
369 [ # # ]: 0 : uno::Reference< table::XCellRange > xRange( aSelection, ::uno::UNO_QUERY);
370 [ # # ]: 0 : if ( !xRange.is() )
371 : : {
372 [ # # ]: 0 : uno::Reference< sheet::XSheetCellRangeContainer > xRanges( aSelection, ::uno::UNO_QUERY);
373 [ # # ]: 0 : if ( xRanges.is() )
374 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< excel::XRange >( new ScVbaRange( excel::getUnoSheetModuleObj( xRanges ), mxContext, xRanges ) ) );
[ # # ][ # # ]
[ # # ][ # # ]
375 : :
376 : : }
377 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< excel::XRange >(new ScVbaRange( excel::getUnoSheetModuleObj( xRange ), mxContext, xRange ) ) );
[ # # ][ # # ]
[ # # ]
378 : : }
379 : : else
380 : : {
381 : : throw uno::RuntimeException( sImplementationName + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
382 [ # # ][ # # ]: 0 : " not supported")), uno::Reference< uno::XInterface >() );
383 : 0 : }
384 : : }
385 : :
386 : : uno::Reference< excel::XRange >
387 : 0 : ScVbaApplication::getActiveCell() throw (uno::RuntimeException )
388 : : {
389 [ # # ][ # # ]: 0 : uno::Reference< sheet::XSpreadsheetView > xView( getCurrentDocument()->getCurrentController(), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
390 [ # # ][ # # ]: 0 : uno::Reference< table::XCellRange > xRange( xView->getActiveSheet(), ::uno::UNO_QUERY_THROW);
[ # # ]
391 [ # # ]: 0 : ScTabViewShell* pViewShell = excel::getCurrentBestViewShell(mxContext);
392 [ # # ]: 0 : if ( !pViewShell )
393 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("No ViewShell available")), uno::Reference< uno::XInterface >() );
394 : 0 : ScViewData* pTabView = pViewShell->GetViewData();
395 [ # # ]: 0 : if ( !pTabView )
396 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("No ViewData available")), uno::Reference< uno::XInterface >() );
397 : :
398 : 0 : sal_Int32 nCursorX = pTabView->GetCurX();
399 : 0 : sal_Int32 nCursorY = pTabView->GetCurY();
400 : :
401 [ # # ][ # # ]: 0 : uno::Reference< XHelperInterface > xParent( excel::getUnoSheetModuleObj( xRange ), uno::UNO_QUERY_THROW );
402 [ # # ][ # # ]: 0 : return new ScVbaRange( xParent, mxContext, xRange->getCellRangeByPosition( nCursorX, nCursorY, nCursorX, nCursorY ) );
[ # # ][ # # ]
[ # # ]
403 : : }
404 : :
405 : : uno::Any SAL_CALL
406 : 0 : ScVbaApplication::Workbooks( const uno::Any& aIndex ) throw (uno::RuntimeException)
407 : : {
408 [ # # ][ # # ]: 0 : uno::Reference< XCollection > xWorkBooks( new ScVbaWorkbooks( this, mxContext ) );
[ # # ][ # # ]
409 [ # # ]: 0 : if ( aIndex.getValueTypeClass() == uno::TypeClass_VOID )
410 : : {
411 : : // void then somebody did Workbooks.something in vba
412 [ # # ]: 0 : return uno::Any( xWorkBooks );
413 : : }
414 : :
415 [ # # ][ # # ]: 0 : return uno::Any ( xWorkBooks->Item( aIndex, uno::Any() ) );
416 : : }
417 : :
418 : : uno::Any SAL_CALL
419 : 22 : ScVbaApplication::Worksheets( const uno::Any& aIndex ) throw (uno::RuntimeException)
420 : : {
421 [ + - ][ + - ]: 22 : uno::Reference< excel::XWorkbook > xWorkbook( getActiveWorkbook(), uno::UNO_QUERY );
422 : 22 : uno::Any result;
423 [ + - ]: 22 : if ( xWorkbook.is() )
424 [ + - ][ + - ]: 22 : result = xWorkbook->Worksheets( aIndex );
425 : :
426 : : else
427 : : // Fixme - check if this is reasonable/desired behavior
428 : : throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "No ActiveWorkBook available" )),
429 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >() );
430 : :
431 : 22 : return result;
432 : : }
433 : :
434 : : uno::Any SAL_CALL
435 : 0 : ScVbaApplication::WorksheetFunction( ) throw (::com::sun::star::uno::RuntimeException)
436 : : {
437 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< script::XInvocation >( new ScVbaWSFunction( this, mxContext ) ) );
[ # # ][ # # ]
438 : : }
439 : :
440 : : uno::Any SAL_CALL
441 : 0 : ScVbaApplication::Evaluate( const ::rtl::OUString& Name ) throw (uno::RuntimeException)
442 : : {
443 : : // #TODO Evaluate allows other things to be evaluated, e.g. functions
444 : : // I think ( like SIN(3) etc. ) need to investigate that
445 : : // named Ranges also? e.g. [MyRange] if so need a list of named ranges
446 : 0 : uno::Any aVoid;
447 [ # # ][ # # ]: 0 : return uno::Any( getActiveWorkbook()->getActiveSheet()->Range( uno::Any( Name ), aVoid ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
448 : : }
449 : :
450 : : uno::Any
451 : 0 : ScVbaApplication::Dialogs( const uno::Any &aIndex ) throw (uno::RuntimeException)
452 : : {
453 [ # # ][ # # ]: 0 : uno::Reference< excel::XDialogs > xDialogs( new ScVbaDialogs( uno::Reference< XHelperInterface >( this ), mxContext, getCurrentDocument() ) );
[ # # ][ # # ]
[ # # ]
454 [ # # ]: 0 : if( !aIndex.hasValue() )
455 [ # # ]: 0 : return uno::Any( xDialogs );
456 [ # # ][ # # ]: 0 : return uno::Any( xDialogs->Item( aIndex ) );
457 : : }
458 : :
459 : : uno::Reference< excel::XWindow > SAL_CALL
460 : 0 : ScVbaApplication::getActiveWindow() throw (uno::RuntimeException)
461 : : {
462 [ # # ]: 0 : uno::Reference< frame::XModel > xModel = getCurrentDocument();
463 [ # # ][ # # ]: 0 : uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW );
[ # # ]
464 [ # # ][ # # ]: 0 : uno::Reference< XHelperInterface > xParent( getActiveWorkbook(), uno::UNO_QUERY_THROW );
465 [ # # ][ # # ]: 0 : uno::Reference< excel::XWindow > xWin( new ScVbaWindow( xParent, mxContext, xModel, xController ) );
[ # # ]
466 : 0 : return xWin;
467 : : }
468 : :
469 : : uno::Any SAL_CALL
470 : 0 : ScVbaApplication::getCutCopyMode() throw (uno::RuntimeException)
471 : : {
472 : 0 : uno::Any result;
473 [ # # ]: 0 : ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( NULL );
474 [ # # ]: 0 : ScDocument* pDoc = pOwnClip ? pOwnClip->GetDocument() : NULL;
475 [ # # ]: 0 : if ( pDoc )
476 : : {
477 [ # # ][ # # ]: 0 : if ( pDoc->IsCutMode() )
478 : : {
479 [ # # ]: 0 : result <<= excel::XlCutCopyMode::xlCut;
480 : : }
481 : : else
482 : : {
483 [ # # ]: 0 : result <<= excel::XlCutCopyMode::xlCopy;
484 : : }
485 : : }
486 : : else
487 : : {
488 [ # # ]: 0 : result <<= false;
489 : : }
490 : 0 : return result;
491 : : }
492 : :
493 : : void SAL_CALL
494 : 0 : ScVbaApplication::setCutCopyMode( const uno::Any& _cutcopymode ) throw (uno::RuntimeException)
495 : : {
496 : : // According to Excel's behavior, no matter what is the value of _cutcopymode, always releases the clip object.
497 : 0 : sal_Bool bCutCopyMode = false;
498 [ # # ]: 0 : if ( ( _cutcopymode >>= bCutCopyMode ) )
499 : : {
500 [ # # ]: 0 : ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( NULL );
501 [ # # ]: 0 : if ( pOwnClip )
502 : : {
503 [ # # ]: 0 : pOwnClip->ObjectReleased();
504 [ # # ][ # # ]: 0 : ScTabViewShell* pTabViewShell = excel::getBestViewShell( getCurrentDocument() );
505 [ # # ]: 0 : if ( pTabViewShell )
506 : : {
507 : 0 : ScViewData* pView = pTabViewShell->GetViewData();
508 [ # # ][ # # ]: 0 : Window* pWindow = pView ? pView->GetActiveWin() : NULL;
509 [ # # ]: 0 : if ( pWindow )
510 : : {
511 [ # # ]: 0 : Reference< datatransfer::clipboard::XClipboard > xClipboard = pWindow->GetClipboard();
512 [ # # ]: 0 : Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
513 [ # # ]: 0 : if ( xClipboard.is() )
514 : : {
515 [ # # ][ # # ]: 0 : xClipboard->setContents( NULL, NULL );
[ # # ][ # # ]
[ # # ]
516 [ # # ]: 0 : if ( xFlushableClipboard.is() )
517 : : {
518 [ # # ]: 0 : const sal_uInt32 nRef = Application::ReleaseSolarMutex();
519 : : try
520 : : {
521 [ # # ][ # # ]: 0 : xFlushableClipboard->flushClipboard();
522 : : }
523 [ # # ]: 0 : catch (const uno::Exception&)
524 : : {
525 : : }
526 [ # # ]: 0 : Application::AcquireSolarMutex( nRef );
527 : : }
528 : 0 : }
529 : : }
530 : : }
531 : : }
532 : : }
533 : 0 : }
534 : :
535 : : uno::Any SAL_CALL
536 : 0 : ScVbaApplication::getStatusBar() throw (uno::RuntimeException)
537 : : {
538 [ # # ]: 0 : return uno::makeAny( !getDisplayStatusBar() );
539 : : }
540 : :
541 : : void SAL_CALL
542 : 0 : ScVbaApplication::setStatusBar( const uno::Any& _statusbar ) throw (uno::RuntimeException)
543 : : {
544 : 0 : rtl::OUString sText;
545 : 0 : sal_Bool bDefault = false;
546 [ # # ][ # # ]: 0 : uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
547 [ # # ][ # # ]: 0 : uno::Reference< task::XStatusIndicatorSupplier > xStatusIndicatorSupplier( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
[ # # ]
548 [ # # ][ # # ]: 0 : uno::Reference< task::XStatusIndicator > xStatusIndicator( xStatusIndicatorSupplier->getStatusIndicator(), uno::UNO_QUERY_THROW );
[ # # ]
549 [ # # ]: 0 : if( _statusbar >>= sText )
550 : : {
551 [ # # ]: 0 : setDisplayStatusBar( sal_True );
552 [ # # ]: 0 : if ( !sText.isEmpty() )
553 [ # # ][ # # ]: 0 : xStatusIndicator->start( sText, 100 );
554 : : else
555 [ # # ][ # # ]: 0 : xStatusIndicator->end(); // restore normal state for empty text
556 : : }
557 [ # # ]: 0 : else if( _statusbar >>= bDefault )
558 : : {
559 [ # # ]: 0 : if( bDefault == false )
560 : : {
561 [ # # ][ # # ]: 0 : xStatusIndicator->end();
562 [ # # ]: 0 : setDisplayStatusBar( sal_True );
563 : : }
564 : : }
565 : : else
566 : : throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Invalid prarameter. It should be a string or False" )),
567 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >() );
568 : 0 : }
569 : :
570 : : ::sal_Int32 SAL_CALL
571 : 0 : ScVbaApplication::getCalculation() throw (uno::RuntimeException)
572 : : {
573 : : // TODO: in Excel, this is an application-wide setting
574 [ # # ][ # # ]: 0 : uno::Reference<sheet::XCalculatable> xCalc(getCurrentDocument(), uno::UNO_QUERY_THROW);
575 [ # # ][ # # ]: 0 : if(xCalc->isAutomaticCalculationEnabled())
[ # # ]
576 : 0 : return excel::XlCalculation::xlCalculationAutomatic;
577 : : else
578 : 0 : return excel::XlCalculation::xlCalculationManual;
579 : : }
580 : :
581 : : void SAL_CALL
582 : 0 : ScVbaApplication::setCalculation( ::sal_Int32 _calculation ) throw (uno::RuntimeException)
583 : : {
584 : : // TODO: in Excel, this is an application-wide setting
585 [ # # ][ # # ]: 0 : uno::Reference< sheet::XCalculatable > xCalc(getCurrentDocument(), uno::UNO_QUERY_THROW);
586 [ # # # ]: 0 : switch(_calculation)
587 : : {
588 : : case excel::XlCalculation::xlCalculationManual:
589 [ # # ][ # # ]: 0 : xCalc->enableAutomaticCalculation(false);
590 : 0 : break;
591 : : case excel::XlCalculation::xlCalculationAutomatic:
592 : : case excel::XlCalculation::xlCalculationSemiautomatic:
593 [ # # ][ # # ]: 0 : xCalc->enableAutomaticCalculation(sal_True);
594 : 0 : break;
595 : 0 : }
596 : 0 : }
597 : :
598 : : uno::Any SAL_CALL
599 : 0 : ScVbaApplication::Windows( const uno::Any& aIndex ) throw (uno::RuntimeException)
600 : : {
601 [ # # ][ # # ]: 0 : uno::Reference< excel::XWindows > xWindows( new ScVbaWindows( this, mxContext ) );
[ # # ][ # # ]
602 [ # # ]: 0 : if ( aIndex.getValueTypeClass() == uno::TypeClass_VOID )
603 [ # # ]: 0 : return uno::Any( xWindows );
604 [ # # ][ # # ]: 0 : return uno::Any( xWindows->Item( aIndex, uno::Any() ) );
605 : : }
606 : : void SAL_CALL
607 : 0 : ScVbaApplication::wait( double time ) throw (uno::RuntimeException)
608 : : {
609 [ # # ][ # # ]: 0 : StarBASIC* pBasic = SFX_APP()->GetBasic();
610 [ # # ][ # # ]: 0 : SbxArrayRef aArgs = new SbxArray;
611 [ # # ][ # # ]: 0 : SbxVariableRef aRef = new SbxVariable;
612 [ # # ]: 0 : aRef->PutDouble( time );
613 [ # # ]: 0 : aArgs->Put( aRef, 1 );
614 [ # # ][ # # ]: 0 : SbMethod* pMeth = (SbMethod*)pBasic->GetRtl()->Find( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("WaitUntil") ), SbxCLASS_METHOD );
615 : :
616 [ # # ]: 0 : if ( pMeth )
617 : : {
618 [ # # ]: 0 : pMeth->SetParameters( aArgs );
619 : 0 : SbxVariableRef refTemp = pMeth;
620 : : // forces a broadcast
621 [ # # ][ # # ]: 0 : SbxVariableRef pNew = new SbxMethod( *((SbxMethod*)pMeth));
[ # # ][ # # ]
622 [ # # ][ # # ]: 0 : }
623 : 0 : }
624 : :
625 : : uno::Any SAL_CALL
626 : 48 : ScVbaApplication::Range( const uno::Any& Cell1, const uno::Any& Cell2 ) throw (uno::RuntimeException)
627 : : {
628 [ + + ]: 48 : uno::Reference< excel::XRange > xVbRange = ScVbaRange::ApplicationRange( mxContext, Cell1, Cell2 );
629 [ + - ]: 48 : return uno::makeAny( xVbRange );
630 : : }
631 : :
632 : : uno::Any SAL_CALL
633 : 0 : ScVbaApplication::Names( const css::uno::Any& aIndex ) throw ( uno::RuntimeException )
634 : : {
635 [ # # ][ # # ]: 0 : uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
636 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xPropertySet( xModel, uno::UNO_QUERY_THROW );
637 [ # # ]: 0 : uno::Reference< sheet::XNamedRanges > xNamedRanges( xPropertySet->getPropertyValue(
638 [ # # ][ # # ]: 0 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "NamedRanges" )) ), uno::UNO_QUERY_THROW );
[ # # ]
639 : :
640 [ # # ][ # # ]: 0 : css::uno::Reference< excel::XNames > xNames ( new ScVbaNames( this , mxContext , xNamedRanges , xModel ) );
[ # # ][ # # ]
641 [ # # ]: 0 : if ( aIndex.getValueTypeClass() == uno::TypeClass_VOID )
642 : : {
643 [ # # ]: 0 : return uno::Any( xNames );
644 : : }
645 [ # # ][ # # ]: 0 : return uno::Any( xNames->Item( aIndex, uno::Any() ) );
646 : : }
647 : :
648 : :
649 : : uno::Reference< excel::XWorksheet > SAL_CALL
650 : 12 : ScVbaApplication::getActiveSheet() throw (uno::RuntimeException)
651 : : {
652 : 12 : uno::Reference< excel::XWorksheet > result;
653 [ + - ][ + - ]: 12 : uno::Reference< excel::XWorkbook > xWorkbook( getActiveWorkbook(), uno::UNO_QUERY );
654 [ + - ]: 12 : if ( xWorkbook.is() )
655 : : {
656 : : uno::Reference< excel::XWorksheet > xWorksheet(
657 [ + - ][ + - ]: 12 : xWorkbook->getActiveSheet(), uno::UNO_QUERY );
[ + - ]
658 [ + - ]: 12 : if ( xWorksheet.is() )
659 : : {
660 [ + - ]: 12 : result = xWorksheet;
661 : 12 : }
662 : : }
663 : :
664 [ - + ]: 12 : if ( !result.is() )
665 : : {
666 : : // Fixme - check if this is reasonable/desired behavior
667 : : throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "No activeSheet available" )),
668 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >() );
669 : : }
670 : 12 : return result;
671 : :
672 : : }
673 : :
674 : : /*******************************************************************************
675 : : * In msdn:
676 : : * Reference Optional Variant. The destination. Can be a Range
677 : : * object, a string that contains a cell reference in R1C1-style notation,
678 : : * or a string that contains a Visual Basic procedure name.
679 : : * Scroll Optional Variant. True to scrol, False to not scroll through
680 : : * the window. The default is False.
681 : : * Parser is split to three parts, Range, R1C1 string and procedure name.
682 : : * by test excel, it seems Scroll no effect. ???
683 : : *******************************************************************************/
684 : : void SAL_CALL
685 : 0 : ScVbaApplication::GoTo( const uno::Any& Reference, const uno::Any& Scroll ) throw (uno::RuntimeException)
686 : : {
687 : : //test Scroll is a boolean
688 : 0 : sal_Bool bScroll = false;
689 : : //R1C1-style string or a string of procedure name.
690 : :
691 [ # # ]: 0 : if( Scroll.hasValue() )
692 : : {
693 : 0 : sal_Bool aScroll = false;
694 [ # # ]: 0 : if( Scroll >>= aScroll )
695 : : {
696 : 0 : bScroll = aScroll;
697 : : }
698 : : else
699 : : throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "second parameter should be boolean" )),
700 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >() );
701 : : }
702 : :
703 : 0 : rtl::OUString sRangeName;
704 [ # # ]: 0 : if( Reference >>= sRangeName )
705 : : {
706 [ # # ][ # # ]: 0 : uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
707 : : uno::Reference< sheet::XSpreadsheetView > xSpreadsheet(
708 [ # # ][ # # ]: 0 : xModel->getCurrentController(), uno::UNO_QUERY_THROW );
[ # # ]
709 [ # # ][ # # ]: 0 : uno::Reference< sheet::XSpreadsheet > xDoc = xSpreadsheet->getActiveSheet();
710 : :
711 [ # # ]: 0 : ScTabViewShell* pShell = excel::getCurrentBestViewShell( mxContext );
712 : 0 : ScGridWindow* gridWindow = (ScGridWindow*)pShell->GetWindow();
713 : : try
714 : : {
715 : : uno::Reference< excel::XRange > xVbaSheetRange = ScVbaRange::getRangeObjectForName(
716 [ # # ][ # # ]: 0 : mxContext, sRangeName, excel::getDocShell( xModel ), formula::FormulaGrammar::CONV_XL_R1C1 );
717 : :
718 [ # # ]: 0 : if( bScroll )
719 : : {
720 [ # # ][ # # ]: 0 : xVbaSheetRange->Select();
721 [ # # ]: 0 : uno::Reference< excel::XWindow > xWindow = getActiveWindow();
722 : 0 : ScSplitPos eWhich = pShell->GetViewData()->GetActivePart();
723 : 0 : sal_Int32 nValueX = pShell->GetViewData()->GetPosX(WhichH(eWhich));
724 : 0 : sal_Int32 nValueY = pShell->GetViewData()->GetPosY(WhichV(eWhich));
725 [ # # ][ # # ]: 0 : xWindow->SmallScroll( uno::makeAny( (sal_Int16)(xVbaSheetRange->getRow() - 1) ),
[ # # ]
726 : : uno::makeAny( (sal_Int16)nValueY ),
727 [ # # ][ # # ]: 0 : uno::makeAny( (sal_Int16)(xVbaSheetRange->getColumn() - 1) ),
728 [ # # ][ # # ]: 0 : uno::makeAny( (sal_Int16)nValueX ) );
[ # # ][ # # ]
[ # # ]
729 [ # # ]: 0 : gridWindow->GrabFocus();
730 : : }
731 : : else
732 : : {
733 [ # # ][ # # ]: 0 : xVbaSheetRange->Select();
734 [ # # ]: 0 : gridWindow->GrabFocus();
735 : 0 : }
736 : : }
737 [ # # ]: 0 : catch (const uno::RuntimeException&)
738 : : {
739 : : //maybe this should be a procedure name
740 : : //TODO for procedure name
741 : : //browse::XBrowseNodeFactory is a singlton. OUString(RTL_CONSTASCII_USTRINGPARAM( "/singletons/com.sun.star.script.browse.theBrowseNodeFactory"))
742 : : //and the createView( browse::BrowseNodeFactoryViewTypes::MACROSELECTOR ) to get a root browse::XBrowseNode.
743 : : //for query XInvocation interface.
744 : : //but how to directly get the XInvocation?
745 : : throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "invalid reference for range name, it should be procedure name" )),
746 [ # # # # ]: 0 : uno::Reference< uno::XInterface >() );
747 : : }
748 : 0 : return;
749 : : }
750 : 0 : uno::Reference< excel::XRange > xRange;
751 [ # # ][ # # ]: 0 : if( Reference >>= xRange )
752 : : {
753 [ # # ]: 0 : uno::Reference< excel::XRange > xVbaRange( Reference, uno::UNO_QUERY );
754 [ # # ]: 0 : ScTabViewShell* pShell = excel::getCurrentBestViewShell( mxContext );
755 : 0 : ScGridWindow* gridWindow = (ScGridWindow*)pShell->GetWindow();
756 [ # # ]: 0 : if ( xVbaRange.is() )
757 : : {
758 : : //TODO bScroll should be using, In this time, it doesenot have effection
759 [ # # ]: 0 : if( bScroll )
760 : : {
761 [ # # ][ # # ]: 0 : xVbaRange->Select();
762 [ # # ]: 0 : uno::Reference< excel::XWindow > xWindow = getActiveWindow();
763 : 0 : ScSplitPos eWhich = pShell->GetViewData()->GetActivePart();
764 : 0 : sal_Int32 nValueX = pShell->GetViewData()->GetPosX(WhichH(eWhich));
765 : 0 : sal_Int32 nValueY = pShell->GetViewData()->GetPosY(WhichV(eWhich));
766 [ # # ][ # # ]: 0 : xWindow->SmallScroll( uno::makeAny( (sal_Int16)(xVbaRange->getRow() - 1) ),
[ # # ]
767 : : uno::makeAny( (sal_Int16)nValueY ),
768 [ # # ][ # # ]: 0 : uno::makeAny( (sal_Int16)(xVbaRange->getColumn() - 1) ),
769 [ # # ][ # # ]: 0 : uno::makeAny( (sal_Int16)nValueX ) );
[ # # ][ # # ]
[ # # ]
770 [ # # ]: 0 : gridWindow->GrabFocus();
771 : : }
772 : : else
773 : : {
774 [ # # ][ # # ]: 0 : xVbaRange->Select();
775 [ # # ]: 0 : gridWindow->GrabFocus();
776 : : }
777 : : }
778 : 0 : return;
779 : : }
780 : : throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "invalid reference or name" )),
781 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >() );
782 : : }
783 : :
784 : : sal_Int32 SAL_CALL
785 : 0 : ScVbaApplication::getCursor() throw (uno::RuntimeException)
786 : : {
787 [ # # ]: 0 : sal_Int32 nPointerStyle = getPointerStyle(getCurrentDocument());
788 : :
789 [ # # # # : 0 : switch( nPointerStyle )
# ]
790 : : {
791 : : case POINTER_ARROW:
792 : 0 : return excel::XlMousePointer::xlNorthwestArrow;
793 : : case POINTER_NULL:
794 : 0 : return excel::XlMousePointer::xlDefault;
795 : : case POINTER_WAIT:
796 : 0 : return excel::XlMousePointer::xlWait;
797 : : case POINTER_TEXT:
798 : 0 : return excel::XlMousePointer::xlIBeam;
799 : : default:
800 : 0 : return excel::XlMousePointer::xlDefault;
801 : : }
802 : : }
803 : :
804 : : void SAL_CALL
805 : 0 : ScVbaApplication::setCursor( sal_Int32 _cursor ) throw (uno::RuntimeException)
806 : : {
807 : : try
808 : : {
809 [ # # ][ # # ]: 0 : uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
810 [ # # # # ]: 0 : switch( _cursor )
811 : : {
812 : : case excel::XlMousePointer::xlNorthwestArrow:
813 : : {
814 : 0 : const Pointer& rPointer( POINTER_ARROW );
815 [ # # ]: 0 : setCursorHelper( xModel, rPointer, false );
816 : 0 : break;
817 : : }
818 : : case excel::XlMousePointer::xlWait:
819 : : case excel::XlMousePointer::xlIBeam:
820 : : {
821 : 0 : const Pointer& rPointer( static_cast< PointerStyle >( _cursor ) );
822 : : //It will set the edit window, toobar and statusbar's mouse pointer.
823 [ # # ]: 0 : setCursorHelper( xModel, rPointer, sal_True );
824 : 0 : break;
825 : : }
826 : : case excel::XlMousePointer::xlDefault:
827 : : {
828 : 0 : const Pointer& rPointer( POINTER_NULL );
829 [ # # ]: 0 : setCursorHelper( xModel, rPointer, false );
830 : 0 : break;
831 : : }
832 : : default:
833 : : throw uno::RuntimeException( rtl::OUString(
834 [ # # ][ # # ]: 0 : RTL_CONSTASCII_USTRINGPARAM("Unknown value for Cursor pointer")), uno::Reference< uno::XInterface >() );
835 : : // TODO: isn't this a flaw in the API? It should be allowed to throw an
836 : : // IllegalArgumentException, or so
837 [ # # ]: 0 : }
838 : : }
839 : 0 : catch (const uno::Exception&)
840 : : {
841 : : DBG_UNHANDLED_EXCEPTION();
842 : : }
843 : 0 : }
844 : :
845 : : // #TODO perhaps we should switch the return type depending of the filter
846 : : // type, e.g. return Calc for Calc and Excel if its an imported doc
847 : : rtl::OUString SAL_CALL
848 : 0 : ScVbaApplication::getName() throw (uno::RuntimeException)
849 : : {
850 [ # # ][ # # ]: 0 : static rtl::OUString appName( RTL_CONSTASCII_USTRINGPARAM("Microsoft Excel" ) );
[ # # ][ # # ]
851 : 0 : return appName;
852 : : }
853 : :
854 : : // #TODO #FIXME get/setDisplayAlerts are just stub impl
855 : : // here just the status of the switch is set
856 : : // the function that throws an error message needs to
857 : : // evaluate this switch in order to know whether it has to disable the
858 : : // error message thrown by OpenOffice
859 : :
860 : : void SAL_CALL
861 : 0 : ScVbaApplication::setDisplayAlerts(sal_Bool displayAlerts) throw (uno::RuntimeException)
862 : : {
863 : 0 : mrAppSettings.mbDisplayAlerts = displayAlerts;
864 : 0 : }
865 : :
866 : : sal_Bool SAL_CALL
867 : 0 : ScVbaApplication::getDisplayAlerts() throw (uno::RuntimeException)
868 : : {
869 : 0 : return mrAppSettings.mbDisplayAlerts;
870 : : }
871 : :
872 : : void SAL_CALL
873 : 0 : ScVbaApplication::setEnableEvents(sal_Bool bEnable) throw (uno::RuntimeException)
874 : : {
875 : 0 : mrAppSettings.mbEnableEvents = bEnable;
876 : 0 : }
877 : :
878 : : sal_Bool SAL_CALL
879 : 0 : ScVbaApplication::getEnableEvents() throw (uno::RuntimeException)
880 : : {
881 : 0 : return mrAppSettings.mbEnableEvents;
882 : : }
883 : :
884 : : sal_Bool SAL_CALL
885 : 0 : ScVbaApplication::getDisplayFullScreen() throw (uno::RuntimeException)
886 : : {
887 : 0 : SfxViewShell* pShell = excel::getCurrentBestViewShell( mxContext );
888 [ # # ]: 0 : if ( pShell )
889 : 0 : return ScViewUtil::IsFullScreen( *pShell );
890 : 0 : return sal_False;
891 : : }
892 : :
893 : : void SAL_CALL
894 : 0 : ScVbaApplication::setDisplayFullScreen( sal_Bool bSet ) throw (uno::RuntimeException)
895 : : {
896 : : // #FIXME calling ScViewUtil::SetFullScreen( *pShell, bSet );
897 : : // directly results in a strange crash, using dispatch instead
898 [ # # ]: 0 : if ( bSet != getDisplayFullScreen() )
899 [ # # ][ # # ]: 0 : dispatchRequests( getCurrentDocument(), rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".uno:FullScreen") ) );
900 : 0 : }
901 : :
902 : : sal_Bool SAL_CALL
903 : 0 : ScVbaApplication::getDisplayScrollBars() throw (uno::RuntimeException)
904 : : {
905 : 0 : ScTabViewShell* pShell = excel::getCurrentBestViewShell( mxContext );
906 [ # # ]: 0 : if ( pShell )
907 : : {
908 [ # # ][ # # ]: 0 : return ( pShell->GetViewData()->IsHScrollMode() && pShell->GetViewData()->IsVScrollMode() );
909 : : }
910 : 0 : return true;
911 : : }
912 : :
913 : : void SAL_CALL
914 : 0 : ScVbaApplication::setDisplayScrollBars( sal_Bool bSet ) throw (uno::RuntimeException)
915 : : {
916 : : // use uno here as it does all he repainting etc. magic
917 [ # # ][ # # ]: 0 : uno::Reference< sheet::XSpreadsheetView > xView( getCurrentDocument()->getCurrentController(), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
918 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xProps( xView, uno::UNO_QUERY );
919 [ # # ][ # # ]: 0 : xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HasVerticalScrollBar") ), uno::makeAny( bSet ) );
[ # # ][ # # ]
920 [ # # ][ # # ]: 0 : xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HasHorizontalScrollBar") ), uno::makeAny( bSet ) );
[ # # ][ # # ]
921 : 0 : }
922 : :
923 : : sal_Bool SAL_CALL
924 : 0 : ScVbaApplication::getDisplayExcel4Menus() throw (css::uno::RuntimeException)
925 : : {
926 : 0 : return mrAppSettings.mbExcel4Menus;
927 : : }
928 : :
929 : : void SAL_CALL
930 : 0 : ScVbaApplication::setDisplayExcel4Menus( sal_Bool bSet ) throw (css::uno::RuntimeException)
931 : : {
932 : 0 : mrAppSettings.mbExcel4Menus = bSet;
933 : 0 : }
934 : :
935 : : sal_Bool SAL_CALL
936 : 0 : ScVbaApplication::getDisplayNoteIndicator() throw (css::uno::RuntimeException)
937 : : {
938 : 0 : return mrAppSettings.mbDisplayNoteIndicator;
939 : : }
940 : :
941 : : void SAL_CALL
942 : 0 : ScVbaApplication::setDisplayNoteIndicator( sal_Bool bSet ) throw (css::uno::RuntimeException)
943 : : {
944 : 0 : mrAppSettings.mbDisplayNoteIndicator = bSet;
945 : 0 : }
946 : :
947 : : sal_Bool SAL_CALL
948 : 0 : ScVbaApplication::getShowWindowsInTaskbar() throw (css::uno::RuntimeException)
949 : : {
950 : 0 : return mrAppSettings.mbShowWindowsInTaskbar;
951 : : }
952 : :
953 : : void SAL_CALL
954 : 0 : ScVbaApplication::setShowWindowsInTaskbar( sal_Bool bSet ) throw (css::uno::RuntimeException)
955 : : {
956 : 0 : mrAppSettings.mbShowWindowsInTaskbar = bSet;
957 : 0 : }
958 : :
959 : : sal_Bool SAL_CALL
960 : 0 : ScVbaApplication::getVisible() throw (uno::RuntimeException)
961 : : {
962 : 0 : sal_Bool bVisible = sal_True;
963 : 0 : return bVisible;
964 : : }
965 : :
966 : : void SAL_CALL
967 : 0 : ScVbaApplication::setVisible(sal_Bool /*bVisible*/) throw (uno::RuntimeException)
968 : : {
969 : 0 : }
970 : :
971 : : //add the support of Excel VBA Application.Iteration
972 : : //The Excel Iteration option is global and unique, but in Symphony there is an Iteration property in ScModule and one in every ScDocument,
973 : : //so the set method will set all the Iteration properties
974 : : sal_Bool SAL_CALL
975 : 0 : ScVbaApplication::getIteration() throw (uno::RuntimeException)
976 : : {
977 [ # # ]: 0 : ScModule* pScMod = SC_MOD();
978 [ # # ][ # # ]: 0 : ScDocOptions aDocOpt = pScMod->GetDocOptions();
979 : :
980 [ # # ]: 0 : return aDocOpt.IsIter();
981 : : }
982 : :
983 : : void SAL_CALL
984 : 0 : ScVbaApplication::setIteration(sal_Bool bIteration) throw (uno::RuntimeException)
985 : : {
986 [ # # ]: 0 : ScModule* pScMod = SC_MOD();
987 [ # # ]: 0 : ScDocOptions& aDocOpt = const_cast< ScDocOptions& > (pScMod->GetDocOptions());
988 : 0 : aDocOpt.SetIter( bIteration );
989 : :
990 : 0 : uno::Any aIteration;
991 [ # # ]: 0 : aIteration <<= bIteration;
992 : :
993 [ # # ]: 0 : OUString aPropName(RTL_CONSTASCII_USTRINGPARAM( "IsIterationEnabled" ));
994 : :
995 [ # # ][ # # ]: 0 : uno::Reference< XCollection > xWorkbooks( new ScVbaWorkbooks( this, mxContext ) );
[ # # ][ # # ]
996 [ # # ][ # # ]: 0 : sal_Int32 nCount = xWorkbooks->getCount();
997 : :
998 [ # # ]: 0 : for (sal_Int32 i = 1; i <= nCount; i++)
999 : : {
1000 : 0 : uno::Reference< ooo::vba::excel::XWorkbook > xWorkbook;
1001 [ # # ][ # # ]: 0 : uno::Any aWorkbook = xWorkbooks->Item(uno::makeAny(i), uno::Any());
[ # # ]
1002 [ # # ]: 0 : aWorkbook >>= xWorkbook;
1003 [ # # ]: 0 : ScVbaWorkbook* pWorkbook = excel::getImplFromDocModuleWrapper<ScVbaWorkbook>( xWorkbook );
1004 [ # # ][ # # ]: 0 : uno::Reference< frame::XModel > xModel( pWorkbook->getDocModel(), uno::UNO_QUERY_THROW );
1005 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xPropertySet( xModel, uno::UNO_QUERY_THROW );
1006 [ # # ][ # # ]: 0 : xPropertySet->setPropertyValue( aPropName, aIteration );
1007 : 0 : }
1008 : 0 : }
1009 : :
1010 : : //add the support of Excel VBA Application.EnableCancelKey
1011 : : sal_Int32 SAL_CALL
1012 : 0 : ScVbaApplication::getEnableCancelKey() throw (uno::RuntimeException)
1013 : : {
1014 : 0 : return ooo::vba::excel::XlEnableCancelKey::xlDisabled;
1015 : : }
1016 : :
1017 : : void SAL_CALL
1018 : 0 : ScVbaApplication::setEnableCancelKey(sal_Int32 /*lEnableCancelKey*/) throw (uno::RuntimeException)
1019 : : {
1020 : 0 : }
1021 : :
1022 : 0 : sal_Int32 SAL_CALL ScVbaApplication::getSheetsInNewWorkbook() throw (uno::RuntimeException)
1023 : : {
1024 : 0 : const ScDefaultsOptions& rOpt = SC_MOD()->GetDefaultsOptions();
1025 : 0 : return rOpt.GetInitTabCount();
1026 : : }
1027 : :
1028 : 0 : void SAL_CALL ScVbaApplication::setSheetsInNewWorkbook( sal_Int32 SheetsInNewWorkbook ) throw (script::BasicErrorException, uno::RuntimeException)
1029 : : {
1030 [ # # ][ # # ]: 0 : if ( SheetsInNewWorkbook < MININITTAB
1031 : : || SheetsInNewWorkbook > MAXINITTAB )
1032 : : {
1033 : : DebugHelper::exception( OUString(RTL_CONSTASCII_USTRINGPARAM("The number must be between 1 and 1024")),
1034 [ # # ][ # # ]: 0 : uno::Exception(), SbERR_METHOD_FAILED, OUString() );
[ # # ][ # # ]
1035 : : }
1036 : : else
1037 : : {
1038 : 0 : ScDefaultsOptions& rOpt = const_cast< ScDefaultsOptions& >(SC_MOD()->GetDefaultsOptions());
1039 : 0 : rOpt.SetInitTabCount( SheetsInNewWorkbook );
1040 : : }
1041 : 0 : }
1042 : :
1043 : : void SAL_CALL
1044 : 0 : ScVbaApplication::Calculate() throw( script::BasicErrorException , uno::RuntimeException )
1045 : : {
1046 [ # # ][ # # ]: 0 : uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
1047 [ # # ][ # # ]: 0 : uno::Reference< sheet::XCalculatable > xCalculatable( getCurrentDocument(), uno::UNO_QUERY_THROW );
1048 [ # # ][ # # ]: 0 : xCalculatable->calculateAll();
1049 : 0 : }
1050 : :
1051 : 0 : uno::Reference< beans::XPropertySet > lcl_getPathSettingsService( const uno::Reference< uno::XComponentContext >& xContext ) throw ( uno::RuntimeException )
1052 : : {
1053 [ # # ][ # # ]: 0 : static uno::Reference< beans::XPropertySet > xPathSettings;
1054 [ # # ]: 0 : if ( !xPathSettings.is() )
1055 : : {
1056 [ # # ][ # # ]: 0 : uno::Reference< lang::XMultiComponentFactory > xSMgr( xContext->getServiceManager(), uno::UNO_QUERY_THROW );
[ # # ]
1057 [ # # ][ # # ]: 0 : xPathSettings.set( xSMgr->createInstanceWithContext( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.PathSettings")), xContext ), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
1058 : : }
1059 : 0 : return xPathSettings;
1060 : : }
1061 : 0 : rtl::OUString ScVbaApplication::getOfficePath( const rtl::OUString& _sPathType ) throw ( uno::RuntimeException )
1062 : : {
1063 : 0 : rtl::OUString sRetPath;
1064 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xProps = lcl_getPathSettingsService( mxContext );
1065 : : try
1066 : : {
1067 : 0 : rtl::OUString sUrl;
1068 [ # # ][ # # ]: 0 : xProps->getPropertyValue( _sPathType ) >>= sUrl;
1069 : :
1070 : : // if its a list of paths then use the last one
1071 : 0 : sal_Int32 nIndex = sUrl.lastIndexOf( ';' ) ;
1072 [ # # ]: 0 : if ( nIndex > 0 )
1073 : 0 : sUrl = sUrl.copy( nIndex + 1 );
1074 [ # # ]: 0 : ::osl::File::getSystemPathFromFileURL( sUrl, sRetPath );
1075 : : }
1076 [ # # # # ]: 0 : catch (const uno::Exception&)
1077 : : {
1078 [ # # ]: 0 : DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
1079 : : }
1080 : 0 : return sRetPath;
1081 : : }
1082 : : void SAL_CALL
1083 : 0 : ScVbaApplication::setDefaultFilePath( const ::rtl::OUString& DefaultFilePath ) throw (script::BasicErrorException, uno::RuntimeException)
1084 : : {
1085 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xProps = lcl_getPathSettingsService( mxContext );
1086 : 0 : rtl::OUString aURL;
1087 [ # # ]: 0 : osl::FileBase::getFileURLFromSystemPath( DefaultFilePath, aURL );
1088 [ # # ][ # # ]: 0 : xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Work")), uno::makeAny( aURL ) );
[ # # ][ # # ]
1089 : :
1090 : :
1091 : 0 : }
1092 : :
1093 : : ::rtl::OUString SAL_CALL
1094 : 0 : ScVbaApplication::getDefaultFilePath( ) throw (script::BasicErrorException, uno::RuntimeException)
1095 : : {
1096 [ # # ]: 0 : return getOfficePath( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Work")));
1097 : : }
1098 : :
1099 : : ::rtl::OUString SAL_CALL
1100 : 0 : ScVbaApplication::LibraryPath( ) throw (script::BasicErrorException, uno::RuntimeException)
1101 : : {
1102 [ # # ]: 0 : return getOfficePath( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Basic")));
1103 : : }
1104 : :
1105 : : ::rtl::OUString SAL_CALL
1106 : 0 : ScVbaApplication::TemplatesPath( ) throw (script::BasicErrorException, uno::RuntimeException)
1107 : : {
1108 [ # # ]: 0 : return getOfficePath( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Template")));
1109 : : }
1110 : :
1111 : : ::rtl::OUString SAL_CALL
1112 : 0 : ScVbaApplication::PathSeparator( ) throw (script::BasicErrorException, uno::RuntimeException)
1113 : : {
1114 [ # # ][ # # ]: 0 : static rtl::OUString sPathSep( RTL_CONSTASCII_USTRINGPARAM( FILE_PATH_SEPERATOR ) );
[ # # ][ # # ]
1115 : 0 : return sPathSep;
1116 : : }
1117 : :
1118 : : // ----------------------------------------------------------------------------
1119 : : // Helpers for Intersect and Union
1120 : :
1121 : : namespace {
1122 : :
1123 : : typedef ::std::list< ScRange > ListOfScRange;
1124 : :
1125 : : /** Appends all ranges of a VBA Range object in the passed Any to the list of ranges. */
1126 : 0 : void lclAddToListOfScRange( ListOfScRange& rList, const uno::Any& rArg )
1127 : : throw (script::BasicErrorException, uno::RuntimeException)
1128 : : {
1129 [ # # ]: 0 : if( rArg.hasValue() )
1130 : : {
1131 [ # # ]: 0 : uno::Reference< excel::XRange > xRange( rArg, uno::UNO_QUERY_THROW );
1132 [ # # ][ # # ]: 0 : uno::Reference< XCollection > xCol( xRange->Areas( uno::Any() ), uno::UNO_QUERY_THROW );
[ # # ]
1133 [ # # ][ # # ]: 0 : for( sal_Int32 nIdx = 1, nCount = xCol->getCount(); nIdx <= nCount; ++nIdx )
[ # # ]
1134 : : {
1135 [ # # ][ # # ]: 0 : uno::Reference< excel::XRange > xAreaRange( xCol->Item( uno::Any( nIdx ), uno::Any() ), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
1136 [ # # ][ # # ]: 0 : uno::Reference< sheet::XCellRangeAddressable > xAddressable( xAreaRange->getCellRange(), uno::UNO_QUERY_THROW );
[ # # ]
1137 : 0 : ScRange aScRange;
1138 [ # # ][ # # ]: 0 : ScUnoConversion::FillScRange( aScRange, xAddressable->getRangeAddress() );
1139 [ # # ]: 0 : rList.push_back( aScRange );
1140 : 0 : }
1141 : : }
1142 : 0 : }
1143 : :
1144 : : /** Returns true, if the passed ranges can be expressed by a single range. The
1145 : : new range will be contained in r1 then, the range r2 can be removed. */
1146 : 0 : bool lclTryJoin( ScRange& r1, const ScRange& r2 )
1147 : : {
1148 : : // 1) r2 is completely inside r1
1149 [ # # ]: 0 : if( r1.In( r2 ) )
1150 : 0 : return true;
1151 : :
1152 : : // 2) r1 is completely inside r2
1153 [ # # ]: 0 : if( r2.In( r1 ) )
1154 : : {
1155 : 0 : r1 = r2;
1156 : 0 : return true;
1157 : : }
1158 : :
1159 : 0 : SCCOL n1L = r1.aStart.Col();
1160 : 0 : SCCOL n1R = r1.aEnd.Col();
1161 : 0 : SCROW n1T = r1.aStart.Row();
1162 : 0 : SCROW n1B = r1.aEnd.Row();
1163 : 0 : SCCOL n2L = r2.aStart.Col();
1164 : 0 : SCCOL n2R = r2.aEnd.Col();
1165 : 0 : SCROW n2T = r2.aStart.Row();
1166 : 0 : SCROW n2B = r2.aEnd.Row();
1167 : :
1168 : : // 3) r1 and r2 have equal upper and lower border
1169 [ # # ][ # # ]: 0 : if( (n1T == n2T) && (n1B == n2B) )
1170 : : {
1171 : : // check that r1 overlaps or touches r2
1172 [ # # ][ # # ]: 0 : if( ((n1L < n2L) && (n2L - 1 <= n1R)) || ((n2L < n1L) && (n1L - 1 <= n2R)) )
[ # # ][ # # ]
1173 : : {
1174 [ # # ]: 0 : r1.aStart.SetCol( ::std::min( n1L, n2L ) );
1175 [ # # ]: 0 : r1.aEnd.SetCol( ::std::max( n1R, n2R ) );
1176 : 0 : return true;
1177 : : }
1178 : 0 : return false;
1179 : : }
1180 : :
1181 : : // 4) r1 and r2 have equal left and right border
1182 [ # # ][ # # ]: 0 : if( (n1L == n2L) && (n1R == n2R) )
1183 : : {
1184 : : // check that r1 overlaps or touches r2
1185 [ # # ][ # # ]: 0 : if( ((n1T < n2T) && (n2T + 1 <= n1B)) || ((n2T < n1T) && (n1T + 1 <= n2B)) )
[ # # ][ # # ]
1186 : : {
1187 [ # # ]: 0 : r1.aStart.SetRow( ::std::min( n1T, n2T ) );
1188 [ # # ]: 0 : r1.aEnd.SetRow( ::std::max( n1B, n2B ) );
1189 : 0 : return true;
1190 : : }
1191 : 0 : return false;
1192 : : }
1193 : :
1194 : : // 5) cannot join these ranges
1195 : 0 : return false;
1196 : : }
1197 : :
1198 : : /** Strips out ranges that are contained by other ranges, joins ranges that can be joined
1199 : : together (aligned borders, e.g. A4:D10 and B4:E10 would be combined to A4:E10. */
1200 : 0 : void lclJoinRanges( ListOfScRange& rList )
1201 : : {
1202 : 0 : ListOfScRange::iterator aOuterIt = rList.begin();
1203 [ # # ]: 0 : while( aOuterIt != rList.end() )
1204 : : {
1205 : 0 : bool bAnyErased = false; // true = any range erased from rList
1206 : 0 : ListOfScRange::iterator aInnerIt = rList.begin();
1207 [ # # ]: 0 : while( aInnerIt != rList.end() )
1208 : : {
1209 : 0 : bool bInnerErased = false; // true = aInnerIt erased from rList
1210 : : // do not compare a range with itself
1211 [ # # ][ # # ]: 0 : if( (aOuterIt != aInnerIt) && lclTryJoin( *aOuterIt, *aInnerIt ) )
[ # # ][ # # ]
1212 : : {
1213 : : // aOuterIt points to joined range, aInnerIt will be removed
1214 [ # # ]: 0 : aInnerIt = rList.erase( aInnerIt );
1215 : 0 : bInnerErased = bAnyErased = true;
1216 : : }
1217 : : /* If aInnerIt has been erased from rList, it already points to
1218 : : the next element (return value of list::erase()). */
1219 [ # # ]: 0 : if( !bInnerErased )
1220 : 0 : ++aInnerIt;
1221 : : }
1222 : : // if any range has been erased, repeat outer loop with the same range
1223 [ # # ]: 0 : if( !bAnyErased )
1224 : 0 : ++aOuterIt;
1225 : : }
1226 : 0 : }
1227 : :
1228 : : /** Intersects the passed list with all ranges of a VBA Range object in the passed Any. */
1229 : 0 : void lclIntersectRanges( ListOfScRange& rList, const uno::Any& rArg )
1230 : : throw (script::BasicErrorException, uno::RuntimeException)
1231 : : {
1232 : : // extract the ranges from the passed argument, will throw on invalid data
1233 [ # # ]: 0 : ListOfScRange aList2;
1234 [ # # ]: 0 : lclAddToListOfScRange( aList2, rArg );
1235 : : // do nothing, if the passed list is already empty
1236 [ # # ][ # # ]: 0 : if( !rList.empty() && !aList2.empty() )
[ # # ]
1237 : : {
1238 : : // save original list in a local
1239 [ # # ]: 0 : ListOfScRange aList1;
1240 [ # # ]: 0 : aList1.swap( rList );
1241 : : // join ranges from passed argument
1242 [ # # ]: 0 : lclJoinRanges( aList2 );
1243 : : // calculate intersection of the ranges in both lists
1244 [ # # ]: 0 : for( ListOfScRange::const_iterator aOuterIt = aList1.begin(), aOuterEnd = aList1.end(); aOuterIt != aOuterEnd; ++aOuterIt )
1245 : : {
1246 [ # # ]: 0 : for( ListOfScRange::const_iterator aInnerIt = aList2.begin(), aInnerEnd = aList2.end(); aInnerIt != aInnerEnd; ++aInnerIt )
1247 : : {
1248 [ # # ][ # # ]: 0 : if( aOuterIt->Intersects( *aInnerIt ) )
1249 : : {
1250 : : ScRange aIsectRange(
1251 : 0 : Max( aOuterIt->aStart.Col(), aInnerIt->aStart.Col() ),
1252 : 0 : Max( aOuterIt->aStart.Row(), aInnerIt->aStart.Row() ),
1253 : 0 : Max( aOuterIt->aStart.Tab(), aInnerIt->aStart.Tab() ),
1254 : 0 : Min( aOuterIt->aEnd.Col(), aInnerIt->aEnd.Col() ),
1255 : 0 : Min( aOuterIt->aEnd.Row(), aInnerIt->aEnd.Row() ),
1256 : 0 : Min( aOuterIt->aEnd.Tab(), aInnerIt->aEnd.Tab() ) );
1257 [ # # ]: 0 : rList.push_back( aIsectRange );
1258 : : }
1259 : : }
1260 : : }
1261 : : // again, join the result ranges
1262 [ # # ]: 0 : lclJoinRanges( rList );
1263 : 0 : }
1264 : 0 : }
1265 : :
1266 : : /** Creates a VBA Range object from the passed list of ranges. */
1267 : 0 : uno::Reference< excel::XRange > lclCreateVbaRange(
1268 : : const uno::Reference< uno::XComponentContext >& rxContext,
1269 : : const uno::Reference< frame::XModel >& rxModel,
1270 : : const ListOfScRange& rList ) throw (uno::RuntimeException)
1271 : : {
1272 [ # # ]: 0 : ScDocShell* pDocShell = excel::getDocShell( rxModel );
1273 [ # # ][ # # ]: 0 : if( !pDocShell ) throw uno::RuntimeException();
1274 : :
1275 [ # # ]: 0 : ScRangeList aCellRanges;
1276 [ # # ]: 0 : for( ListOfScRange::const_iterator aIt = rList.begin(), aEnd = rList.end(); aIt != aEnd; ++aIt )
1277 [ # # ]: 0 : aCellRanges.Append( *aIt );
1278 : :
1279 [ # # ][ # # ]: 0 : if( aCellRanges.size() == 1 )
1280 : : {
1281 [ # # ][ # # ]: 0 : uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pDocShell, *aCellRanges.front() ) );
[ # # ][ # # ]
1282 [ # # ][ # # ]: 0 : return new ScVbaRange( excel::getUnoSheetModuleObj( xRange ), rxContext, xRange );
[ # # ][ # # ]
1283 : : }
1284 [ # # ][ # # ]: 0 : if( aCellRanges.size() > 1 )
1285 : : {
1286 [ # # ][ # # ]: 0 : uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( pDocShell, aCellRanges ) );
[ # # ]
1287 [ # # ][ # # ]: 0 : return new ScVbaRange( excel::getUnoSheetModuleObj( xRanges ), rxContext, xRanges );
[ # # ][ # # ]
1288 : : }
1289 [ # # ][ # # ]: 0 : return 0;
1290 : : }
1291 : :
1292 : : } // namespace
1293 : :
1294 : : // ----------------------------------------------------------------------------
1295 : :
1296 : 0 : uno::Reference< excel::XRange > SAL_CALL ScVbaApplication::Intersect(
1297 : : const uno::Reference< excel::XRange >& rArg1, const uno::Reference< excel::XRange >& rArg2,
1298 : : const uno::Any& rArg3, const uno::Any& rArg4, const uno::Any& rArg5, const uno::Any& rArg6,
1299 : : const uno::Any& rArg7, const uno::Any& rArg8, const uno::Any& rArg9, const uno::Any& rArg10,
1300 : : const uno::Any& rArg11, const uno::Any& rArg12, const uno::Any& rArg13, const uno::Any& rArg14,
1301 : : const uno::Any& rArg15, const uno::Any& rArg16, const uno::Any& rArg17, const uno::Any& rArg18,
1302 : : const uno::Any& rArg19, const uno::Any& rArg20, const uno::Any& rArg21, const uno::Any& rArg22,
1303 : : const uno::Any& rArg23, const uno::Any& rArg24, const uno::Any& rArg25, const uno::Any& rArg26,
1304 : : const uno::Any& rArg27, const uno::Any& rArg28, const uno::Any& rArg29, const uno::Any& rArg30 )
1305 : : throw (script::BasicErrorException, uno::RuntimeException)
1306 : : {
1307 [ # # ][ # # ]: 0 : if( !rArg1.is() || !rArg2.is() )
[ # # ]
1308 [ # # ]: 0 : DebugHelper::exception( SbERR_BAD_PARAMETER, rtl::OUString() );
1309 : :
1310 : : // initialize the result list with 1st parameter, join its ranges together
1311 [ # # ]: 0 : ListOfScRange aList;
1312 [ # # ][ # # ]: 0 : lclAddToListOfScRange( aList, uno::Any( rArg1 ) );
1313 [ # # ]: 0 : lclJoinRanges( aList );
1314 : :
1315 : : // process all other parameters, this updates the list with intersection
1316 [ # # ][ # # ]: 0 : lclIntersectRanges( aList, uno::Any( rArg2 ) );
1317 [ # # ]: 0 : lclIntersectRanges( aList, rArg3 );
1318 [ # # ]: 0 : lclIntersectRanges( aList, rArg4 );
1319 [ # # ]: 0 : lclIntersectRanges( aList, rArg5 );
1320 [ # # ]: 0 : lclIntersectRanges( aList, rArg6 );
1321 [ # # ]: 0 : lclIntersectRanges( aList, rArg7 );
1322 [ # # ]: 0 : lclIntersectRanges( aList, rArg8 );
1323 [ # # ]: 0 : lclIntersectRanges( aList, rArg9 );
1324 [ # # ]: 0 : lclIntersectRanges( aList, rArg10 );
1325 [ # # ]: 0 : lclIntersectRanges( aList, rArg11 );
1326 [ # # ]: 0 : lclIntersectRanges( aList, rArg12 );
1327 [ # # ]: 0 : lclIntersectRanges( aList, rArg13 );
1328 [ # # ]: 0 : lclIntersectRanges( aList, rArg14 );
1329 [ # # ]: 0 : lclIntersectRanges( aList, rArg15 );
1330 [ # # ]: 0 : lclIntersectRanges( aList, rArg16 );
1331 [ # # ]: 0 : lclIntersectRanges( aList, rArg17 );
1332 [ # # ]: 0 : lclIntersectRanges( aList, rArg18 );
1333 [ # # ]: 0 : lclIntersectRanges( aList, rArg19 );
1334 [ # # ]: 0 : lclIntersectRanges( aList, rArg20 );
1335 [ # # ]: 0 : lclIntersectRanges( aList, rArg21 );
1336 [ # # ]: 0 : lclIntersectRanges( aList, rArg22 );
1337 [ # # ]: 0 : lclIntersectRanges( aList, rArg23 );
1338 [ # # ]: 0 : lclIntersectRanges( aList, rArg24 );
1339 [ # # ]: 0 : lclIntersectRanges( aList, rArg25 );
1340 [ # # ]: 0 : lclIntersectRanges( aList, rArg26 );
1341 [ # # ]: 0 : lclIntersectRanges( aList, rArg27 );
1342 [ # # ]: 0 : lclIntersectRanges( aList, rArg28 );
1343 [ # # ]: 0 : lclIntersectRanges( aList, rArg29 );
1344 [ # # ]: 0 : lclIntersectRanges( aList, rArg30 );
1345 : :
1346 : : // create the VBA Range object
1347 [ # # ][ # # ]: 0 : return lclCreateVbaRange( mxContext, getCurrentDocument(), aList );
1348 : : }
1349 : :
1350 : 0 : uno::Reference< excel::XRange > SAL_CALL ScVbaApplication::Union(
1351 : : const uno::Reference< excel::XRange >& rArg1, const uno::Reference< excel::XRange >& rArg2,
1352 : : const uno::Any& rArg3, const uno::Any& rArg4, const uno::Any& rArg5, const uno::Any& rArg6,
1353 : : const uno::Any& rArg7, const uno::Any& rArg8, const uno::Any& rArg9, const uno::Any& rArg10,
1354 : : const uno::Any& rArg11, const uno::Any& rArg12, const uno::Any& rArg13, const uno::Any& rArg14,
1355 : : const uno::Any& rArg15, const uno::Any& rArg16, const uno::Any& rArg17, const uno::Any& rArg18,
1356 : : const uno::Any& rArg19, const uno::Any& rArg20, const uno::Any& rArg21, const uno::Any& rArg22,
1357 : : const uno::Any& rArg23, const uno::Any& rArg24, const uno::Any& rArg25, const uno::Any& rArg26,
1358 : : const uno::Any& rArg27, const uno::Any& rArg28, const uno::Any& rArg29, const uno::Any& rArg30 )
1359 : : throw (script::BasicErrorException, uno::RuntimeException)
1360 : : {
1361 [ # # ][ # # ]: 0 : if( !rArg1.is() || !rArg2.is() )
[ # # ]
1362 [ # # ]: 0 : DebugHelper::exception( SbERR_BAD_PARAMETER, rtl::OUString() );
1363 : :
1364 [ # # ]: 0 : ListOfScRange aList;
1365 [ # # ][ # # ]: 0 : lclAddToListOfScRange( aList, uno::Any( rArg1 ) );
1366 [ # # ][ # # ]: 0 : lclAddToListOfScRange( aList, uno::Any( rArg2 ) );
1367 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg3 );
1368 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg4 );
1369 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg5 );
1370 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg6 );
1371 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg7 );
1372 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg8 );
1373 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg9 );
1374 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg10 );
1375 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg11 );
1376 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg12 );
1377 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg13 );
1378 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg14 );
1379 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg15 );
1380 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg16 );
1381 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg17 );
1382 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg18 );
1383 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg19 );
1384 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg20 );
1385 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg21 );
1386 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg22 );
1387 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg23 );
1388 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg24 );
1389 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg25 );
1390 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg26 );
1391 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg27 );
1392 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg28 );
1393 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg29 );
1394 [ # # ]: 0 : lclAddToListOfScRange( aList, rArg30 );
1395 : :
1396 : : // simply join together all ranges as much as possible, strip out covered ranges etc.
1397 [ # # ]: 0 : lclJoinRanges( aList );
1398 : :
1399 : : // create the VBA Range object
1400 [ # # ][ # # ]: 0 : return lclCreateVbaRange( mxContext, getCurrentDocument(), aList );
1401 : : }
1402 : :
1403 : : void
1404 : 0 : ScVbaApplication::Volatile( const uno::Any& aVolatile ) throw ( uno::RuntimeException )
1405 : : {
1406 : 0 : sal_Bool bVolatile = sal_True;
1407 : 0 : aVolatile >>= bVolatile;
1408 [ # # ]: 0 : SbMethod* pMeth = StarBASIC::GetActiveMethod();
1409 [ # # ]: 0 : if ( pMeth )
1410 : : {
1411 : : OSL_TRACE("ScVbaApplication::Volatile() In method ->%s<-", rtl::OUStringToOString( pMeth->GetName(), RTL_TEXTENCODING_UTF8 ).getStr() );
1412 [ # # ]: 0 : uno::Reference< frame::XModel > xModel( getCurrentDocument() );
1413 [ # # ]: 0 : ScDocument* pDoc = excel::getDocShell( xModel )->GetDocument();
1414 [ # # ][ # # ]: 0 : pDoc->GetMacroManager()->SetUserFuncVolatile( pMeth->GetName(), bVolatile);
[ # # ][ # # ]
1415 : : }
1416 : :
1417 : : // this is bound to break when loading the document
1418 : 0 : return;
1419 : : }
1420 : :
1421 : : ::sal_Bool SAL_CALL
1422 : 0 : ScVbaApplication::getDisplayFormulaBar() throw ( css::uno::RuntimeException )
1423 : : {
1424 : 0 : sal_Bool bRes = false;
1425 : 0 : ScTabViewShell* pViewShell = excel::getCurrentBestViewShell( mxContext );
1426 [ # # ]: 0 : if ( pViewShell )
1427 : : {
1428 [ # # ]: 0 : SfxBoolItem sfxFormBar( FID_TOGGLEINPUTLINE);
1429 [ # # ][ # # ]: 0 : SfxAllItemSet reqList( SFX_APP()->GetPool() );
1430 [ # # ]: 0 : reqList.Put( sfxFormBar );
1431 : :
1432 [ # # ]: 0 : pViewShell->GetState( reqList );
1433 : 0 : const SfxPoolItem *pItem=0;
1434 [ # # ][ # # ]: 0 : if ( reqList.GetItemState( FID_TOGGLEINPUTLINE, false, &pItem ) == SFX_ITEM_SET )
1435 [ # # ][ # # ]: 0 : bRes = ((SfxBoolItem*)pItem)->GetValue();
1436 : : }
1437 : 0 : return bRes;
1438 : : }
1439 : :
1440 : : void SAL_CALL
1441 : 0 : ScVbaApplication::setDisplayFormulaBar( ::sal_Bool _displayformulabar ) throw ( css::uno::RuntimeException )
1442 : : {
1443 : 0 : ScTabViewShell* pViewShell = excel::getCurrentBestViewShell( mxContext );
1444 [ # # ][ # # ]: 0 : if ( pViewShell && ( _displayformulabar != getDisplayFormulaBar() ) )
[ # # ]
1445 : : {
1446 [ # # ]: 0 : SfxBoolItem sfxFormBar( FID_TOGGLEINPUTLINE, _displayformulabar);
1447 [ # # ][ # # ]: 0 : SfxAllItemSet reqList( SFX_APP()->GetPool() );
1448 [ # # ]: 0 : SfxRequest aReq( FID_TOGGLEINPUTLINE, 0, reqList );
1449 [ # # ][ # # ]: 0 : pViewShell->Execute( aReq );
[ # # ][ # # ]
1450 : : }
1451 : 0 : }
1452 : :
1453 : : uno::Any SAL_CALL
1454 : 0 : ScVbaApplication::Caller( const uno::Any& /*aIndex*/ ) throw ( uno::RuntimeException )
1455 : : {
1456 : 0 : StarBASIC* pBasic = SFX_APP()->GetBasic();
1457 [ # # ]: 0 : SbMethod* pMeth = (SbMethod*)pBasic->GetRtl()->Find( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FuncCaller") ), SbxCLASS_METHOD );
1458 : 0 : uno::Any aRet;
1459 [ # # ]: 0 : if ( pMeth )
1460 : : {
1461 : 0 : SbxVariableRef refTemp = pMeth;
1462 : : // forces a broadcast
1463 [ # # ][ # # ]: 0 : SbxVariableRef pNew = new SbxMethod( *((SbxMethod*)pMeth));
1464 : : OSL_TRACE("pNew has type %d and string value %s", pNew->GetType(), rtl::OUStringToOString( pNew->GetString(), RTL_TEXTENCODING_UTF8 ).getStr() );
1465 [ # # ][ # # ]: 0 : aRet = sbxToUnoValue( pNew );
[ # # ]
1466 : : }
1467 : 0 : return aRet;
1468 : : }
1469 : :
1470 : : uno::Any SAL_CALL
1471 : 0 : ScVbaApplication::GetOpenFilename(const uno::Any& FileFilter, const uno::Any& FilterIndex, const uno::Any& Title, const uno::Any& ButtonText, const uno::Any& MultiSelect) throw (uno::RuntimeException)
1472 : : {
1473 [ # # ]: 0 : uno::Any aRet = uno::makeAny( false );
1474 : : try
1475 : : {
1476 [ # # ]: 0 : const rtl::OUString sServiceName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ));
1477 [ # # ][ # # ]: 0 : uno::Reference< lang::XMultiServiceFactory > xMSF( comphelper::getProcessServiceFactory(), uno::UNO_QUERY );
1478 : : // Set the type of File Picker Dialog: TemplateDescription::FILEOPEN_SIMPLE.
1479 [ # # ]: 0 : uno::Sequence< uno::Any > aDialogType( 1 );
1480 [ # # ][ # # ]: 0 : aDialogType[0] <<= ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE;
1481 [ # # ][ # # ]: 0 : uno::Reference< ui::dialogs::XFilePicker > xFilePicker( xMSF->createInstanceWithArguments( sServiceName, aDialogType ), UNO_QUERY );
[ # # ]
1482 [ # # ]: 0 : uno::Reference< ui::dialogs::XFilePicker2 > xFilePicker2( xFilePicker, UNO_QUERY );
1483 [ # # ]: 0 : uno::Reference< ui::dialogs::XFilterManager > xFilterManager( xFilePicker, UNO_QUERY );
1484 [ # # ]: 0 : uno::Reference< ui::dialogs::XExecutableDialog > xExecutableDialog( xFilePicker, UNO_QUERY );
1485 [ # # ]: 0 : uno::Reference< ui::dialogs::XFilePickerControlAccess > xPickerControlAccess( xFilePicker, UNO_QUERY );
1486 : :
1487 [ # # ][ # # ]: 0 : if ( xFilterManager.is() && FileFilter.hasValue() )
[ # # ]
1488 : : {
1489 : 0 : sal_Int32 nFilterIndex = 1;
1490 [ # # ]: 0 : if ( FilterIndex.hasValue() )
1491 : : {
1492 : 0 : FilterIndex >>= nFilterIndex;
1493 : : }
1494 : 0 : ::rtl::OUString strFilter;
1495 : 0 : FileFilter >>= strFilter;
1496 : 0 : sal_Int32 nCommaID = 0;
1497 : 0 : sal_Int32 nIndex = 1;
1498 [ # # ]: 0 : do
1499 : : {
1500 : 0 : ::rtl::OUString aFilterTitleToken = strFilter.getToken( 0, ',' , nCommaID );
1501 : 0 : ::rtl::OUString aFilterToken;
1502 [ # # ]: 0 : if ( nCommaID >= 0 )
1503 : : {
1504 : 0 : aFilterToken = strFilter.getToken( 0, ',' , nCommaID );
1505 : : }
1506 [ # # ][ # # ]: 0 : else if ( nCommaID < 0 && nIndex == 1 )
1507 : : {
1508 : : throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Invalid FileFilter format!" )),
1509 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >() );
1510 : : }
1511 [ # # ][ # # ]: 0 : xFilterManager->appendFilter( aFilterTitleToken, aFilterToken );
1512 [ # # ]: 0 : if ( nFilterIndex == nIndex )
1513 : : {
1514 [ # # ][ # # ]: 0 : xFilterManager->setCurrentFilter( aFilterTitleToken );
1515 : : }
1516 : 0 : nIndex++;
1517 : 0 : } while ( nCommaID >= 0 );
1518 : : }
1519 [ # # ][ # # ]: 0 : if ( xExecutableDialog.is() && Title.hasValue() )
[ # # ]
1520 : : {
1521 : 0 : ::rtl::OUString sTitle;
1522 : 0 : Title >>= sTitle;
1523 [ # # ][ # # ]: 0 : xExecutableDialog->setTitle( sTitle );
1524 : : }
1525 [ # # ][ # # ]: 0 : if ( xPickerControlAccess.is() && ButtonText.hasValue() )
[ # # ]
1526 : : {
1527 : 0 : ::rtl::OUString sButtonText;
1528 : 0 : ButtonText >>= sButtonText;
1529 [ # # ][ # # ]: 0 : xPickerControlAccess->setLabel( ui::dialogs::CommonFilePickerElementIds::PUSHBUTTON_OK, sButtonText );
1530 : : }
1531 : 0 : sal_Bool bMultiSelect = false;
1532 [ # # ][ # # ]: 0 : if ( xFilePicker.is() && MultiSelect.hasValue() )
[ # # ]
1533 : : {
1534 : 0 : MultiSelect >>= bMultiSelect;
1535 [ # # ][ # # ]: 0 : xFilePicker->setMultiSelectionMode( bMultiSelect );
1536 : : }
1537 : :
1538 [ # # ][ # # ]: 0 : if ( xFilePicker.is() && xFilePicker->execute() )
[ # # ][ # # ]
[ # # ]
1539 : : {
1540 [ # # ]: 0 : uno::Sequence< rtl::OUString > aSelectedFiles;
1541 [ # # ]: 0 : if ( xFilePicker2.is() )
1542 : : {
1543 : : // On Linux, XFilePicker->getFiles() always return one selected file although we select more than one file, also on Vista
1544 : : // XFilePicker->getFiles() does not work well too, so we call XFilePicker2->getSelectedFiles() to get selected files.
1545 [ # # ][ # # ]: 0 : aSelectedFiles = xFilePicker2->getSelectedFiles();
[ # # ][ # # ]
1546 : : }
1547 : : else
1548 : : {
1549 : : // If only one file is selected, the first entry of the sequence contains the complete path/filename in URL format. If multiple files are selected,
1550 : : // the first entry of the sequence contains the path in URL format, and the other entries contains the names of the selected files without path information.
1551 [ # # ][ # # ]: 0 : uno::Sequence< rtl::OUString > aTmpFiles = xFilePicker->getFiles();
1552 [ # # ]: 0 : aSelectedFiles = aTmpFiles;
1553 : 0 : sal_Int32 iFileCount = aTmpFiles.getLength();
1554 [ # # ]: 0 : if ( iFileCount > 1 )
1555 : : {
1556 [ # # ]: 0 : aSelectedFiles.realloc( iFileCount - 1 );
1557 [ # # ][ # # ]: 0 : INetURLObject aPath( aTmpFiles[0] );
1558 [ # # ]: 0 : aPath.setFinalSlash();
1559 [ # # ]: 0 : for ( sal_Int32 i = 1; i < iFileCount; i++ )
1560 : : {
1561 [ # # ][ # # ]: 0 : if ( aTmpFiles[i].indexOf ('/') > 0 || aTmpFiles[i].indexOf ('\\') > 0 )
[ # # ][ # # ]
[ # # ]
1562 : : {
1563 [ # # ][ # # ]: 0 : aSelectedFiles[i - 1] = aTmpFiles[i];
1564 : : }
1565 : : else
1566 : : {
1567 [ # # ]: 0 : if ( i == 1 )
1568 [ # # ][ # # ]: 0 : aPath.Append( aTmpFiles[i] );
1569 : : else
1570 [ # # ][ # # ]: 0 : aPath.setName( aTmpFiles[i] );
1571 [ # # ][ # # ]: 0 : aSelectedFiles[i - 1] = aPath.GetMainURL( INetURLObject::NO_DECODE );
1572 : : }
1573 [ # # ]: 0 : }
1574 [ # # ]: 0 : }
1575 : : }
1576 : :
1577 : 0 : sal_Int32 iFileCount = aSelectedFiles.getLength();
1578 [ # # ]: 0 : for ( sal_Int32 i = 0; i < iFileCount; i++ )
1579 : : {
1580 [ # # ][ # # ]: 0 : INetURLObject aObj( aSelectedFiles[i] );
1581 [ # # ]: 0 : if ( aObj.GetProtocol() == INET_PROT_FILE )
1582 : : {
1583 [ # # ]: 0 : rtl::OUString aTemp = aObj.PathToFileName();
1584 [ # # ][ # # ]: 0 : aSelectedFiles[i] = aTemp.isEmpty() ? aSelectedFiles[i] : aTemp ;
[ # # ]
1585 : : }
1586 [ # # ]: 0 : }
1587 [ # # ]: 0 : if ( bMultiSelect )
1588 : : {
1589 [ # # ]: 0 : aRet = uno::makeAny( aSelectedFiles );
1590 : : }
1591 [ # # ][ # # ]: 0 : else if ( aSelectedFiles.getLength() > 0 && !bMultiSelect )
[ # # ]
1592 : : {
1593 [ # # ][ # # ]: 0 : aRet = uno::makeAny( aSelectedFiles[0] );
1594 [ # # ]: 0 : }
1595 [ # # ]: 0 : }
1596 : : }
1597 [ # # # # ]: 0 : catch (const uno::Exception&)
1598 : : {
1599 [ # # ]: 0 : DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
1600 : : }
1601 : :
1602 : 0 : return aRet;
1603 : : }
1604 : :
1605 : : ::com::sun::star::uno::Reference< ::ooo::vba::XFileDialog > SAL_CALL
1606 : 0 : ScVbaApplication::getFileDialog() throw (::com::sun::star::uno::RuntimeException)
1607 : : {
1608 [ # # ][ # # ]: 0 : uno::Reference< XFileDialog > xFileDialogs( new ScVbaFileDialog( uno::Reference< XHelperInterface >( this ), mxContext, getCurrentDocument() ) );
[ # # ][ # # ]
1609 : 0 : return xFileDialogs;
1610 : : }
1611 : :
1612 : : typedef std::map< ::rtl::OUString, ::rtl::OUString > FileFilterMap;
1613 : :
1614 : : uno::Any SAL_CALL
1615 : 0 : ScVbaApplication::GetSaveAsFilename( const ::com::sun::star::uno::Any& InitialFilename, const ::com::sun::star::uno::Any& FileFilter, const ::com::sun::star::uno::Any& FilterIndex, const ::com::sun::star::uno::Any& Title, const ::com::sun::star::uno::Any& ButtonText ) throw (::com::sun::star::uno::RuntimeException)
1616 : : {
1617 : 0 : uno::Any strRet;
1618 : : try
1619 : : {
1620 [ # # ]: 0 : const rtl::OUString sServiceName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ));
1621 [ # # ][ # # ]: 0 : uno::Reference< lang::XMultiServiceFactory > xMSF( comphelper::getProcessServiceFactory(), uno::UNO_QUERY );
1622 : :
1623 [ # # ]: 0 : uno::Sequence< uno::Any > aDialogType( 1 );
1624 [ # # ][ # # ]: 0 : aDialogType[0] <<= ui::dialogs::TemplateDescription::FILESAVE_SIMPLE;
1625 [ # # ][ # # ]: 0 : uno::Reference< ui::dialogs::XFilePicker > xFilePicker( xMSF->createInstanceWithArguments( sServiceName, aDialogType ), UNO_QUERY );
[ # # ]
1626 : :
1627 [ # # ]: 0 : if (InitialFilename.hasValue())
1628 : : {
1629 : 0 : ::rtl::OUString strInitFileName;
1630 : 0 : InitialFilename >>= strInitFileName;
1631 [ # # ][ # # ]: 0 : xFilePicker->setDefaultName(strInitFileName);
1632 : : }
1633 : :
1634 : : // Begin from 1.
1635 : 0 : sal_Int32 nFilterIndex = 1;
1636 [ # # ]: 0 : if (FilterIndex.hasValue())
1637 : : {
1638 : 0 : FilterIndex >>= nFilterIndex;
1639 : : }
1640 : :
1641 [ # # ]: 0 : uno::Reference< ui::dialogs::XFilterManager > xFilter( xFilePicker, UNO_QUERY );
1642 [ # # ]: 0 : FileFilterMap mFilterNameMap;
1643 [ # # ]: 0 : if (FileFilter.hasValue())
1644 : : {
1645 : 0 : ::rtl::OUString strFilter;
1646 : 0 : sal_Int32 nCommaID = 0;
1647 : 0 : FileFilter >>= strFilter;
1648 : :
1649 : 0 : sal_Int32 nIndex = 1;
1650 [ # # ]: 0 : do
1651 : : {
1652 : 0 : ::rtl::OUString aFilterTitleToken = strFilter.getToken( 0, ',' , nCommaID );
1653 : 0 : ::rtl::OUString aFilterToken;
1654 [ # # ]: 0 : if ( nCommaID >= 0 )
1655 : : {
1656 : 0 : aFilterToken = strFilter.getToken( 0, ',' , nCommaID );
1657 : : }
1658 [ # # ][ # # ]: 0 : else if ( nCommaID < 0 && nIndex == 1 )
1659 : : {
1660 : : throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Invalid FileFilter format!" )),
1661 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >() );
1662 : : }
1663 : :
1664 [ # # ]: 0 : FileFilterMap::const_iterator aIt = mFilterNameMap.find( aFilterTitleToken );
1665 [ # # ]: 0 : if ( aIt == mFilterNameMap.end() )
1666 : : {
1667 [ # # ][ # # ]: 0 : xFilter->appendFilter( aFilterTitleToken, aFilterToken );
1668 [ # # ]: 0 : if ( nFilterIndex == nIndex )
1669 : : {
1670 [ # # ][ # # ]: 0 : xFilter->setCurrentFilter( aFilterTitleToken );
1671 : : }
1672 : 0 : nIndex++;
1673 [ # # ]: 0 : mFilterNameMap[aFilterTitleToken] = aFilterToken;
1674 : 0 : }
1675 : 0 : } while ( nCommaID >= 0 );
1676 : : }
1677 : :
1678 [ # # ]: 0 : if (Title.hasValue())
1679 : : {
1680 : 0 : ::rtl::OUString strTitle;
1681 : 0 : Title >>= strTitle;
1682 [ # # ]: 0 : uno::Reference< ::com::sun::star::ui::dialogs::XExecutableDialog> xExcTblDlg(xFilePicker, UNO_QUERY );
1683 [ # # ][ # # ]: 0 : xExcTblDlg->setTitle(strTitle);
1684 : : }
1685 : :
1686 [ # # ]: 0 : if (ButtonText.hasValue())
1687 : : {
1688 : 0 : ::rtl::OUString strBttTxt;
1689 : 0 : ButtonText >>= strBttTxt;
1690 : : }
1691 : :
1692 : :
1693 [ # # ]: 0 : if ( xFilePicker.is() )
1694 : : {
1695 [ # # ][ # # ]: 0 : sal_Int16 nRet = xFilePicker->execute();
1696 [ # # ]: 0 : if (nRet == 0)
1697 : : {
1698 [ # # ]: 0 : strRet <<= false;
1699 : : }
1700 : : else
1701 : : {
1702 [ # # ][ # # ]: 0 : uno::Sequence < rtl::OUString > aPathSeq = xFilePicker->getFiles();
1703 : :
1704 [ # # ]: 0 : if ( aPathSeq.getLength() )
1705 : : {
1706 : 0 : ::rtl::OUString sSelectedFilters;
1707 [ # # ]: 0 : if ( xFilter.is() )
1708 : : {
1709 [ # # ][ # # ]: 0 : ::rtl::OUString sSelectedFilterName = xFilter->getCurrentFilter();
1710 [ # # ]: 0 : FileFilterMap::const_iterator aIt = mFilterNameMap.find( sSelectedFilterName );
1711 [ # # ]: 0 : if ( aIt != mFilterNameMap.end() )
1712 : : {
1713 : 0 : sSelectedFilters = aIt->second;
1714 : 0 : }
1715 : : }
1716 [ # # ][ # # ]: 0 : INetURLObject aURLObj( aPathSeq[0] );
1717 [ # # ]: 0 : ::rtl::OUString aPathStr = aURLObj.PathToFileName();
1718 [ # # ]: 0 : if ( aURLObj.GetProtocol() == INET_PROT_FILE )
1719 : : {
1720 : 0 : sal_Int32 nSemicolonID = 0;
1721 : 0 : ::rtl::OUString sFirstFilter = sSelectedFilters.getToken( 0, ';' , nSemicolonID );
1722 [ # # ]: 0 : ::rtl::OUString sFileExtension = aURLObj.GetExtension();
1723 [ # # ]: 0 : if ( sFileExtension.isEmpty() )
1724 : : {
1725 [ # # ]: 0 : sFileExtension = sFirstFilter == "*.*" ? sFileExtension : sFirstFilter.copy( sFirstFilter.indexOfAsciiL("*.", 2) + 2 );
1726 [ # # ][ # # ]: 0 : aPathStr = sFileExtension.isEmpty() ? aPathStr : aPathStr + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".")) + sFileExtension;
[ # # ]
[ # # # # ]
[ # # ]
1727 : : }
1728 : : else
1729 : : {
1730 : 0 : sal_Bool bValidFilter = false;
1731 : 0 : FileFilterMap::const_iterator aIt = mFilterNameMap.begin();
1732 [ # # ]: 0 : while ( aIt != mFilterNameMap.end() )
1733 : : {
1734 : 0 : sSelectedFilters = aIt->second;
1735 : 0 : nSemicolonID = 0;
1736 [ # # ]: 0 : do
1737 : : {
1738 : 0 : ::rtl::OUString aFilterToken = sSelectedFilters.getToken( 0, ';' , nSemicolonID );
1739 [ # # ][ # # ]: 0 : if ( aFilterToken.trim().equalsIgnoreAsciiCase( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("*.")) + sFileExtension) )
1740 : : {
1741 : 0 : bValidFilter = sal_True;
1742 : : break;
1743 [ # # ]: 0 : }
1744 : : } while ( nSemicolonID >= 0 );
1745 [ # # ]: 0 : if ( bValidFilter )
1746 : : {
1747 : 0 : break;
1748 : : }
1749 : 0 : ++aIt;
1750 : : }
1751 [ # # ]: 0 : if ( !bValidFilter )
1752 : : {
1753 : 0 : sFileExtension = sFirstFilter == "*.*" ? rtl::OUString()
1754 [ # # ]: 0 : : sFirstFilter.copy( sFirstFilter.indexOfAsciiL("*.", 2) + 2 );
1755 : 0 : aPathStr = sFileExtension.isEmpty() ? aPathStr
1756 [ # # ][ # # ]: 0 : : aPathStr + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".")) + sFileExtension;
[ # # ]
[ # # # # ]
[ # # ]
1757 : : }
1758 : 0 : }
1759 : : }
1760 [ # # ][ # # ]: 0 : strRet <<= aPathStr;
1761 [ # # ]: 0 : }
1762 : : }
1763 [ # # ]: 0 : }
1764 : : }
1765 [ # # # # ]: 0 : catch (const uno::Exception&)
1766 : : {
1767 [ # # ]: 0 : DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
1768 : : }
1769 : 0 : return strRet;
1770 : : }
1771 : :
1772 : : //end add
1773 : :
1774 : : uno::Reference< frame::XModel >
1775 : 0 : ScVbaApplication::getCurrentDocument() throw (css::uno::RuntimeException)
1776 : : {
1777 : 0 : return getCurrentExcelDoc(mxContext);
1778 : : }
1779 : :
1780 : : uno::Any SAL_CALL
1781 : 0 : ScVbaApplication::MenuBars( const uno::Any& aIndex ) throw (uno::RuntimeException)
1782 : : {
1783 [ # # ][ # # ]: 0 : uno::Reference< XCommandBars > xCommandBars( CommandBars( uno::Any() ), uno::UNO_QUERY_THROW );
1784 [ # # ][ # # ]: 0 : uno::Reference< XCollection > xMenuBars( new ScVbaMenuBars( this, mxContext, xCommandBars ) );
[ # # ][ # # ]
1785 [ # # ]: 0 : if ( aIndex.hasValue() )
1786 : : {
1787 [ # # ][ # # ]: 0 : return uno::Any ( xMenuBars->Item( aIndex, uno::Any() ) );
1788 : : }
1789 : :
1790 [ # # ]: 0 : return uno::Any( xMenuBars );
1791 : : }
1792 : :
1793 : : //add the support of Application.International
1794 : : sal_Int32 SAL_CALL
1795 : 0 : ConvertCountryCode(const OUString& language)
1796 : : {
1797 : 0 : sal_Int32 nCode = 0;
1798 : :
1799 [ # # ]: 0 : if( language == "ar" ) nCode = 966; // Arabic
1800 [ # # ]: 0 : else if ( language == "cs" ) nCode = 42; // Czech
1801 [ # # ]: 0 : else if ( language == "da" ) nCode = 45; // Danish
1802 [ # # ]: 0 : else if ( language == "de" ) nCode = 49; // German
1803 [ # # ]: 0 : else if ( language == "en" ) nCode = 1; // English
1804 [ # # ]: 0 : else if ( language == "es" ) nCode = 34; // Spanish
1805 [ # # ]: 0 : else if ( language == "el" ) nCode = 30; // Greek
1806 [ # # ]: 0 : else if ( language == "fa" ) nCode = 98; // Persian = Farsi
1807 [ # # ]: 0 : else if ( language == "fi" ) nCode = 358; // Finnish
1808 [ # # ]: 0 : else if ( language == "fr" ) nCode = 33; // French
1809 [ # # ]: 0 : else if ( language == "he" ) nCode = 972; // Hebrew
1810 [ # # ]: 0 : else if ( language == "hi" ) nCode = 91; // Indian = Hindi
1811 [ # # ]: 0 : else if ( language == "hu" ) nCode = 36; // Hungarian
1812 [ # # ]: 0 : else if ( language == "it" ) nCode = 39; // Italian
1813 [ # # ]: 0 : else if ( language == "ja" ) nCode = 81; // Japanese
1814 [ # # ]: 0 : else if ( language == "ko" ) nCode = 82; // Korean
1815 [ # # ]: 0 : else if ( language == "nl" ) nCode = 31; // Dutch
1816 [ # # ]: 0 : else if ( language == "no" ) nCode = 47; // Norwegian
1817 [ # # ]: 0 : else if ( language == "pl" ) nCode = 48; // Polish
1818 [ # # ]: 0 : else if ( language == "pt" ) nCode = 351; // Portuguese
1819 [ # # ]: 0 : else if ( language == "ru" ) nCode = 7; // Russian
1820 [ # # ]: 0 : else if ( language == "sv" ) nCode = 46; // Swedish
1821 [ # # ]: 0 : else if ( language == "th" ) nCode = 66; // Thai
1822 [ # # ]: 0 : else if ( language == "tk" ) nCode = 90; // Turkish
1823 [ # # ]: 0 : else if ( language == "ur" ) nCode = 92; // Urdu
1824 [ # # ]: 0 : else if ( language == "vi" ) nCode = 84; // Vietnamese
1825 [ # # ]: 0 : else if ( language == "zh" ) nCode = 86; // Simplified Chinese
1826 : :
1827 : 0 : return nCode;
1828 : : }
1829 : :
1830 : : uno::Any SAL_CALL
1831 : 0 : ScVbaApplication::International( sal_Int32 Index ) throw (uno::RuntimeException)
1832 : : {
1833 : 0 : uno::Any aRet;
1834 : 0 : OUString str;
1835 [ # # ]: 0 : const LocaleDataWrapper* pLocaleData = ScGlobal::GetpLocaleData();
1836 [ # # # # ]: 0 : switch ( Index )
1837 : : {
1838 : : case excel::XlApplicationInternational::xlCountryCode:
1839 [ # # ][ # # ]: 0 : aRet <<= ConvertCountryCode( pLocaleData->getLanguageCountryInfo().Language );
[ # # ]
1840 : 0 : break;
1841 : : case excel::XlApplicationInternational::xlDecimalSeparator:
1842 [ # # ]: 0 : str = pLocaleData->getNumDecimalSep();
1843 [ # # ]: 0 : aRet <<= str;
1844 : 0 : break;
1845 : : case excel::XlApplicationInternational::xlDateSeparator:
1846 [ # # ]: 0 : str = pLocaleData->getDateSep();
1847 [ # # ]: 0 : aRet <<= str;
1848 : 0 : break;
1849 : : default:
1850 : 0 : break;
1851 : : }
1852 : 0 : return aRet;
1853 : : }
1854 : :
1855 : 0 : void SAL_CALL ScVbaApplication::Undo( ) throw (::com::sun::star::uno::RuntimeException)
1856 : : {
1857 [ # # ][ # # ]: 0 : SfxAllItemSet reqList( SFX_APP()->GetPool() );
1858 [ # # ]: 0 : SfxRequest rReq(SID_UNDO, 0, reqList);
1859 [ # # ]: 0 : ScTabViewShell* pViewShell = excel::getCurrentBestViewShell( mxContext );
1860 : :
1861 [ # # ]: 0 : if (pViewShell != NULL)
1862 : : {
1863 [ # # ]: 0 : pViewShell->ExecuteUndo(rReq);
1864 [ # # ][ # # ]: 0 : }
1865 : 0 : }
1866 : :
1867 : 0 : double SAL_CALL ScVbaApplication::InchesToPoints( double Inches ) throw (uno::RuntimeException)
1868 : : {
1869 : : // Convert a measurement from Inch to Point (1 inch = 72 points).
1870 : 0 : return MetricField::ConvertDoubleValue( Inches, 0, 0, FUNIT_INCH, FUNIT_POINT );
1871 : : }
1872 : :
1873 : : rtl::OUString
1874 : 0 : ScVbaApplication::getServiceImplName()
1875 : : {
1876 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScVbaApplication"));
1877 : : }
1878 : :
1879 : : uno::Sequence< rtl::OUString >
1880 : 0 : ScVbaApplication::getServiceNames()
1881 : : {
1882 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > aServiceNames;
[ # # ][ # # ]
1883 [ # # ]: 0 : if ( aServiceNames.getLength() == 0 )
1884 : : {
1885 : 0 : aServiceNames.realloc( 1 );
1886 [ # # ]: 0 : aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Application" ) );
1887 : : }
1888 : 0 : return aServiceNames;
1889 : : }
1890 : :
1891 : : namespace application
1892 : : {
1893 : : namespace sdecl = comphelper::service_decl;
1894 : 3 : sdecl::vba_service_class_<ScVbaApplication, sdecl::with_args<false> > serviceImpl;
1895 : 3 : extern sdecl::ServiceDecl const serviceDecl(
1896 : : serviceImpl,
1897 : : "ScVbaApplication",
1898 : : "ooo.vba.excel.Application" );
1899 [ + - ][ + - ]: 9 : }
1900 : :
1901 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|