fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / vba / vbaapplication.cxx
blobcc51da63adeb19520d127dc21ff1c9d563150bd7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <stdio.h>
22 #include <com/sun/star/frame/XLayoutManager.hpp>
23 #include <com/sun/star/frame/XDesktop.hpp>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <com/sun/star/sheet/XCalculatable.hpp>
26 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
27 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
28 #include <com/sun/star/sheet/XNamedRanges.hpp>
29 #include <com/sun/star/sheet/XSpreadsheetView.hpp>
30 #include <com/sun/star/sheet/XSpreadsheets.hpp>
31 #include <com/sun/star/task/XStatusIndicatorSupplier.hpp>
32 #include <com/sun/star/task/XStatusIndicator.hpp>
33 #include <com/sun/star/util/PathSettings.hpp>
34 #include <com/sun/star/view/XSelectionSupplier.hpp>
35 #include <ooo/vba/XExecutableDialog.hpp>
36 #include <ooo/vba/excel/XlCalculation.hpp>
37 #include <ooo/vba/excel/XlMousePointer.hpp>
39 #include "vbaapplication.hxx"
40 #include "vbaworkbooks.hxx"
41 #include "vbaworkbook.hxx"
42 #include "vbaworksheets.hxx"
43 #include "vbarange.hxx"
44 #include "vbawsfunction.hxx"
45 #include "vbadialogs.hxx"
46 #include "vbawindow.hxx"
47 #include "vbawindows.hxx"
48 #include "vbaglobals.hxx"
49 #include "vbamenubars.hxx"
50 #include "tabvwsh.hxx"
51 #include "gridwin.hxx"
52 #include "vbanames.hxx"
53 #include <vbahelper/vbashape.hxx>
54 #include "vbatextboxshape.hxx"
55 #include "vbaassistant.hxx"
56 #include "sc.hrc"
57 #include "macromgr.hxx"
58 #include "defaultsoptions.hxx"
60 #include <osl/file.hxx>
61 #include <rtl/instance.hxx>
63 #include <sfx2/request.hxx>
64 #include <sfx2/objsh.hxx>
65 #include <sfx2/viewfrm.hxx>
66 #include <sfx2/app.hxx>
68 #include <comphelper/processfactory.hxx>
70 #include <toolkit/awt/vclxwindow.hxx>
71 #include <toolkit/helper/vclunohelper.hxx>
73 #include <tools/diagnose_ex.h>
74 #include <tools/urlobj.hxx>
76 #include <docuno.hxx>
78 #include <basic/sbx.hxx>
79 #include <basic/sbstar.hxx>
80 #include <basic/sbuno.hxx>
81 #include <basic/sbmeth.hxx>
83 #include "convuno.hxx"
84 #include "cellsuno.hxx"
85 #include "miscuno.hxx"
86 #include "unonames.hxx"
87 #include "docsh.hxx"
88 #include <vbahelper/helperdecl.hxx>
89 #include "excelvbahelper.hxx"
91 #include <basic/sbmod.hxx>
92 #include <basic/sbxobj.hxx>
94 #include "viewutil.hxx"
95 #include "docoptio.hxx"
97 using namespace ::ooo::vba;
98 using namespace ::com::sun::star;
99 using ::com::sun::star::uno::Reference;
100 using ::com::sun::star::uno::UNO_QUERY_THROW;
101 using ::com::sun::star::uno::UNO_QUERY;
103 /** Global application settings shared by all open workbooks. */
104 struct ScVbaAppSettings
106 sal_Int32 mnCalculation;
107 bool mbDisplayAlerts;
108 bool mbEnableEvents;
109 bool mbExcel4Menus;
110 bool mbDisplayNoteIndicator;
111 bool mbShowWindowsInTaskbar;
112 bool mbEnableCancelKey;
113 explicit ScVbaAppSettings();
116 ScVbaAppSettings::ScVbaAppSettings() :
117 mnCalculation( excel::XlCalculation::xlCalculationAutomatic ),
118 mbDisplayAlerts( true ),
119 mbEnableEvents( true ),
120 mbExcel4Menus( false ),
121 mbDisplayNoteIndicator( true ),
122 mbShowWindowsInTaskbar( true ),
123 mbEnableCancelKey( false )
127 struct ScVbaStaticAppSettings : public ::rtl::Static< ScVbaAppSettings, ScVbaStaticAppSettings > {};
129 ScVbaApplication::ScVbaApplication( const uno::Reference<uno::XComponentContext >& xContext ) :
130 ScVbaApplication_BASE( xContext ),
131 mrAppSettings( ScVbaStaticAppSettings::get() )
135 ScVbaApplication::~ScVbaApplication()
139 /*static*/ bool ScVbaApplication::getDocumentEventsEnabled()
141 return ScVbaStaticAppSettings::get().mbEnableEvents;
144 OUString SAL_CALL
145 ScVbaApplication::getExactName( const OUString& aApproximateName ) throw (uno::RuntimeException, std::exception)
147 uno::Reference< beans::XExactName > xWSF( new ScVbaWSFunction( this, mxContext ) );
148 return xWSF->getExactName( aApproximateName );
151 uno::Reference< beans::XIntrospectionAccess > SAL_CALL
152 ScVbaApplication::getIntrospection() throw(css::uno::RuntimeException, std::exception)
154 uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) );
155 return xWSF->getIntrospection();
158 uno::Any SAL_CALL
159 ScVbaApplication::invoke( const 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, std::exception)
161 /* When calling the functions directly at the Application object, no runtime
162 errors are thrown, but the error is inserted into the return value. */
163 uno::Any aAny;
166 uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) );
167 aAny = xWSF->invoke( FunctionName, Params, OutParamIndex, OutParam );
169 catch (const uno::Exception&)
171 aAny <<= script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), 1000, OUString() );
173 return aAny;
176 void SAL_CALL
177 ScVbaApplication::setValue( const OUString& PropertyName, const uno::Any& Value ) throw(beans::UnknownPropertyException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException, std::exception)
179 uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) );
180 xWSF->setValue( PropertyName, Value );
183 uno::Any SAL_CALL
184 ScVbaApplication::getValue( const OUString& PropertyName ) throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception)
186 uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) );
187 return xWSF->getValue( PropertyName );
190 sal_Bool SAL_CALL
191 ScVbaApplication::hasMethod( const OUString& Name ) throw(uno::RuntimeException, std::exception)
193 uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) );
194 return xWSF->hasMethod( Name );
197 sal_Bool SAL_CALL
198 ScVbaApplication::hasProperty( const OUString& Name ) throw(uno::RuntimeException, std::exception)
200 uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) );
201 return xWSF->hasProperty( Name );
204 uno::Reference< excel::XWorkbook >
205 ScVbaApplication::getActiveWorkbook() throw (uno::RuntimeException, std::exception)
207 uno::Reference< frame::XModel > xModel( getCurrentExcelDoc( mxContext ), uno::UNO_SET_THROW );
208 uno::Reference< excel::XWorkbook > xWorkbook( getVBADocument( xModel ), uno::UNO_QUERY );
209 if( xWorkbook.is() ) return xWorkbook;
210 // #i116936# getVBADocument() may return null in documents without global VBA mode enabled
211 return new ScVbaWorkbook( this, mxContext, xModel );
214 uno::Reference< excel::XWorkbook > SAL_CALL
215 ScVbaApplication::getThisWorkbook() throw (uno::RuntimeException, std::exception)
217 uno::Reference< frame::XModel > xModel( getThisExcelDoc( mxContext ), uno::UNO_SET_THROW );
218 uno::Reference< excel::XWorkbook > xWorkbook( getVBADocument( xModel ), uno::UNO_QUERY );
219 if( xWorkbook.is() ) return xWorkbook;
220 // #i116936# getVBADocument() may return null in documents without global VBA mode enabled
221 return new ScVbaWorkbook( this, mxContext, xModel );
224 uno::Reference< XAssistant > SAL_CALL
225 ScVbaApplication::getAssistant() throw (uno::RuntimeException, std::exception)
227 return uno::Reference< XAssistant >( new ScVbaAssistant( this, mxContext ) );
230 uno::Any SAL_CALL
231 ScVbaApplication::getSelection() throw (uno::RuntimeException, std::exception)
233 OSL_TRACE("** ScVbaApplication::getSelection() ** ");
234 uno::Reference< frame::XModel > xModel( getCurrentDocument() );
236 Reference< view::XSelectionSupplier > xSelSupp( xModel->getCurrentController(), UNO_QUERY_THROW );
237 Reference< beans::XPropertySet > xPropSet( xSelSupp, UNO_QUERY_THROW );
238 OUString aPropName( SC_UNO_FILTERED_RANGE_SELECTION );
239 uno::Any aOldVal = xPropSet->getPropertyValue( aPropName );
240 uno::Any any;
241 any <<= false;
242 xPropSet->setPropertyValue( aPropName, any );
243 uno::Reference< uno::XInterface > aSelection = ScUnoHelpFunctions::AnyToInterface(
244 xSelSupp->getSelection() );
245 xPropSet->setPropertyValue( aPropName, aOldVal );
247 if (!aSelection.is())
249 throw uno::RuntimeException( "failed to obtain current selection" );
252 uno::Reference< lang::XServiceInfo > xServiceInfo( aSelection, uno::UNO_QUERY_THROW );
253 OUString sImplementationName = xServiceInfo->getImplementationName();
255 if( sImplementationName.equalsIgnoreAsciiCase("com.sun.star.drawing.SvxShapeCollection") )
257 uno::Reference< drawing::XShapes > xShapes( aSelection, uno::UNO_QUERY_THROW );
258 uno::Reference< container::XIndexAccess > xIndexAccess( xShapes, uno::UNO_QUERY_THROW );
259 uno::Reference< drawing::XShape > xShape( xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW );
260 // if ScVbaShape::getType( xShape ) == office::MsoShapeType::msoAutoShape
261 // and the uno object implements the com.sun.star.drawing.Text service
262 // return a textboxshape object
263 if ( ScVbaShape::getType( xShape ) == office::MsoShapeType::msoAutoShape )
265 uno::Reference< lang::XServiceInfo > xShapeServiceInfo( xShape, uno::UNO_QUERY_THROW );
266 if ( xShapeServiceInfo->supportsService("com.sun.star.drawing.Text") )
268 return uno::makeAny( uno::Reference< msforms::XTextBoxShape >(new ScVbaTextBoxShape( mxContext, xShape, xShapes, xModel ) ) );
271 return uno::makeAny( uno::Reference< msforms::XShape >(new ScVbaShape( this, mxContext, xShape, xShapes, xModel, ScVbaShape::getType( xShape ) ) ) );
273 else if( xServiceInfo->supportsService("com.sun.star.sheet.SheetCellRange") ||
274 xServiceInfo->supportsService("com.sun.star.sheet.SheetCellRanges") )
276 uno::Reference< table::XCellRange > xRange( aSelection, ::uno::UNO_QUERY);
277 if ( !xRange.is() )
279 uno::Reference< sheet::XSheetCellRangeContainer > xRanges( aSelection, ::uno::UNO_QUERY);
280 if ( xRanges.is() )
281 return uno::makeAny( uno::Reference< excel::XRange >( new ScVbaRange( excel::getUnoSheetModuleObj( xRanges ), mxContext, xRanges ) ) );
284 return uno::makeAny( uno::Reference< excel::XRange >(new ScVbaRange( excel::getUnoSheetModuleObj( xRange ), mxContext, xRange ) ) );
286 else
288 throw uno::RuntimeException( sImplementationName + " not supported" );
292 uno::Reference< excel::XRange >
293 ScVbaApplication::getActiveCell() throw (uno::RuntimeException, std::exception )
295 uno::Reference< sheet::XSpreadsheetView > xView( getCurrentDocument()->getCurrentController(), uno::UNO_QUERY_THROW );
296 uno::Reference< table::XCellRange > xRange( xView->getActiveSheet(), ::uno::UNO_QUERY_THROW);
297 ScTabViewShell* pViewShell = excel::getCurrentBestViewShell(mxContext);
298 if ( !pViewShell )
299 throw uno::RuntimeException("No ViewShell available" );
300 ScViewData& rTabView = pViewShell->GetViewData();
302 sal_Int32 nCursorX = rTabView.GetCurX();
303 sal_Int32 nCursorY = rTabView.GetCurY();
305 // #i117392# excel::getUnoSheetModuleObj() may return null in documents without global VBA mode enabled
306 return new ScVbaRange( excel::getUnoSheetModuleObj( xRange ), mxContext, xRange->getCellRangeByPosition( nCursorX, nCursorY, nCursorX, nCursorY ) );
309 uno::Any SAL_CALL
310 ScVbaApplication::International( sal_Int32 /*Index*/ ) throw (uno::RuntimeException, std::exception)
312 // complete stub for now
313 // #TODO flesh out some of the Indices we could handle
314 uno::Any aRet;
315 return aRet;
318 uno::Any SAL_CALL
319 ScVbaApplication::Workbooks( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
321 uno::Reference< XCollection > xWorkBooks( new ScVbaWorkbooks( this, mxContext ) );
322 if ( aIndex.getValueTypeClass() == uno::TypeClass_VOID )
324 // void then somebody did Workbooks.something in vba
325 return uno::Any( xWorkBooks );
328 return uno::Any ( xWorkBooks->Item( aIndex, uno::Any() ) );
331 uno::Any SAL_CALL
332 ScVbaApplication::Worksheets( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
334 uno::Reference< excel::XWorkbook > xWorkbook( getActiveWorkbook(), uno::UNO_SET_THROW );
335 return xWorkbook->Worksheets( aIndex );
338 uno::Any SAL_CALL
339 ScVbaApplication::WorksheetFunction( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
341 return uno::makeAny( uno::Reference< script::XInvocation >( new ScVbaWSFunction( this, mxContext ) ) );
344 uno::Any SAL_CALL
345 ScVbaApplication::Evaluate( const OUString& Name ) throw (uno::RuntimeException, std::exception)
347 // #TODO Evaluate allows other things to be evaluated, e.g. functions
348 // I think ( like SIN(3) etc. ) need to investigate that
349 // named Ranges also? e.g. [MyRange] if so need a list of named ranges
350 uno::Any aVoid;
351 return uno::Any( getActiveWorkbook()->getActiveSheet()->Range( uno::Any( Name ), aVoid ) );
354 uno::Any
355 ScVbaApplication::Dialogs( const uno::Any &aIndex ) throw (uno::RuntimeException, std::exception)
357 uno::Reference< excel::XDialogs > xDialogs( new ScVbaDialogs( uno::Reference< XHelperInterface >( this ), mxContext, getCurrentDocument() ) );
358 if( !aIndex.hasValue() )
359 return uno::Any( xDialogs );
360 return uno::Any( xDialogs->Item( aIndex ) );
363 uno::Reference< excel::XWindow > SAL_CALL
364 ScVbaApplication::getActiveWindow() throw (uno::RuntimeException, std::exception)
366 uno::Reference< frame::XModel > xModel = getCurrentDocument();
367 uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW );
368 uno::Reference< XHelperInterface > xParent( getActiveWorkbook(), uno::UNO_QUERY_THROW );
369 uno::Reference< excel::XWindow > xWin( new ScVbaWindow( xParent, mxContext, xModel, xController ) );
370 return xWin;
373 uno::Any SAL_CALL
374 ScVbaApplication::getCutCopyMode() throw (uno::RuntimeException, std::exception)
376 //# FIXME TODO, implementation
377 uno::Any result;
378 result <<= sal_False;
379 return result;
382 void SAL_CALL
383 ScVbaApplication::setCutCopyMode( const uno::Any& /* _cutcopymode */ ) throw (uno::RuntimeException, std::exception)
385 //# FIXME TODO, implementation
388 uno::Any SAL_CALL
389 ScVbaApplication::getStatusBar() throw (uno::RuntimeException, std::exception)
391 return uno::makeAny( !getDisplayStatusBar() );
394 void SAL_CALL
395 ScVbaApplication::setStatusBar( const uno::Any& _statusbar ) throw (uno::RuntimeException, std::exception)
397 OUString sText;
398 bool bDefault = false;
399 uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
400 uno::Reference< task::XStatusIndicatorSupplier > xStatusIndicatorSupplier( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
401 uno::Reference< task::XStatusIndicator > xStatusIndicator( xStatusIndicatorSupplier->getStatusIndicator(), uno::UNO_QUERY_THROW );
402 if( _statusbar >>= sText )
404 setDisplayStatusBar( sal_True );
405 if ( !sText.isEmpty() )
406 xStatusIndicator->start( sText, 100 );
407 else
408 xStatusIndicator->end(); // restore normal state for empty text
410 else if( _statusbar >>= bDefault )
412 if( !bDefault )
414 xStatusIndicator->end();
415 setDisplayStatusBar( sal_True );
418 else
419 throw uno::RuntimeException("Invalid prarameter. It should be a string or False" );
422 ::sal_Int32 SAL_CALL
423 ScVbaApplication::getCalculation() throw (uno::RuntimeException, std::exception)
425 // TODO: in Excel, this is an application-wide setting
426 uno::Reference<sheet::XCalculatable> xCalc(getCurrentDocument(), uno::UNO_QUERY_THROW);
427 if(xCalc->isAutomaticCalculationEnabled())
428 return excel::XlCalculation::xlCalculationAutomatic;
429 else
430 return excel::XlCalculation::xlCalculationManual;
433 void SAL_CALL
434 ScVbaApplication::setCalculation( ::sal_Int32 _calculation ) throw (uno::RuntimeException, std::exception)
436 // TODO: in Excel, this is an application-wide setting
437 uno::Reference< sheet::XCalculatable > xCalc(getCurrentDocument(), uno::UNO_QUERY_THROW);
438 switch(_calculation)
440 case excel::XlCalculation::xlCalculationManual:
441 xCalc->enableAutomaticCalculation(false);
442 break;
443 case excel::XlCalculation::xlCalculationAutomatic:
444 case excel::XlCalculation::xlCalculationSemiautomatic:
445 xCalc->enableAutomaticCalculation(sal_True);
446 break;
450 uno::Any SAL_CALL
451 ScVbaApplication::Windows( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
453 uno::Reference< excel::XWindows > xWindows( new ScVbaWindows( this, mxContext ) );
454 if ( aIndex.getValueTypeClass() == uno::TypeClass_VOID )
455 return uno::Any( xWindows );
456 return uno::Any( xWindows->Item( aIndex, uno::Any() ) );
458 void SAL_CALL
459 ScVbaApplication::wait( double time ) throw (uno::RuntimeException, std::exception)
461 StarBASIC* pBasic = SfxApplication::GetBasic();
462 SbxArrayRef aArgs = new SbxArray;
463 SbxVariableRef aRef = new SbxVariable;
464 aRef->PutDouble( time );
465 aArgs->Put( aRef, 1 );
466 SbMethod* pMeth = static_cast<SbMethod*>(pBasic->GetRtl()->Find( OUString("WaitUntil"), SbxCLASS_METHOD ));
468 if ( pMeth )
470 pMeth->SetParameters( aArgs );
471 SbxVariableRef refTemp = pMeth;
472 // forces a broadcast
473 SbxVariableRef pNew = new SbxMethod( *((SbxMethod*)pMeth));
477 uno::Any SAL_CALL
478 ScVbaApplication::Range( const uno::Any& Cell1, const uno::Any& Cell2 ) throw (uno::RuntimeException, std::exception)
480 uno::Reference< excel::XRange > xVbRange = ScVbaRange::ApplicationRange( mxContext, Cell1, Cell2 );
481 return uno::makeAny( xVbRange );
484 uno::Any SAL_CALL
485 ScVbaApplication::Names( const css::uno::Any& aIndex ) throw ( uno::RuntimeException, std::exception )
487 uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
488 uno::Reference< beans::XPropertySet > xPropertySet( xModel, uno::UNO_QUERY_THROW );
489 uno::Reference< sheet::XNamedRanges > xNamedRanges( xPropertySet->getPropertyValue(
490 OUString( "NamedRanges" ) ), uno::UNO_QUERY_THROW );
492 css::uno::Reference< excel::XNames > xNames ( new ScVbaNames( this , mxContext , xNamedRanges , xModel ) );
493 if ( aIndex.getValueTypeClass() == uno::TypeClass_VOID )
495 return uno::Any( xNames );
497 return uno::Any( xNames->Item( aIndex, uno::Any() ) );
500 uno::Reference< excel::XWorksheet > SAL_CALL
501 ScVbaApplication::getActiveSheet() throw (uno::RuntimeException, std::exception)
503 uno::Reference< excel::XWorksheet > result;
504 uno::Reference< excel::XWorkbook > xWorkbook( getActiveWorkbook(), uno::UNO_QUERY );
505 if ( xWorkbook.is() )
507 uno::Reference< excel::XWorksheet > xWorksheet(
508 xWorkbook->getActiveSheet(), uno::UNO_QUERY );
509 if ( xWorksheet.is() )
511 result = xWorksheet;
515 if ( !result.is() )
517 // Fixme - check if this is reasonable/desired behavior
518 throw uno::RuntimeException("No activeSheet available" );
520 return result;
524 /*******************************************************************************
525 * In msdn:
526 * Reference Optional Variant. The destination. Can be a Range
527 * object, a string that contains a cell reference in R1C1-style notation,
528 * or a string that contains a Visual Basic procedure name.
529 * Scroll Optional Variant. True to scrol, False to not scroll through
530 * the window. The default is False.
531 * Parser is split to three parts, Range, R1C1 string and procedure name.
532 * by test excel, it seems Scroll no effect. ???
533 *******************************************************************************/
534 void SAL_CALL
535 ScVbaApplication::GoTo( const uno::Any& Reference, const uno::Any& Scroll ) throw (uno::RuntimeException, std::exception)
537 //test Scroll is a boolean
538 bool bScroll = false;
539 //R1C1-style string or a string of procedure name.
541 if( Scroll.hasValue() )
543 bool aScroll = false;
544 if( Scroll >>= aScroll )
546 bScroll = aScroll;
548 else
549 throw uno::RuntimeException("second parameter should be boolean" );
552 OUString sRangeName;
553 if( Reference >>= sRangeName )
555 uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
556 uno::Reference< sheet::XSpreadsheetView > xSpreadsheet(
557 xModel->getCurrentController(), uno::UNO_QUERY_THROW );
558 uno::Reference< sheet::XSpreadsheet > xDoc = xSpreadsheet->getActiveSheet();
560 ScTabViewShell* pShell = excel::getCurrentBestViewShell( mxContext );
561 ScGridWindow* gridWindow = static_cast<ScGridWindow*>(pShell->GetWindow());
564 uno::Reference< excel::XRange > xVbaSheetRange = ScVbaRange::getRangeObjectForName(
565 mxContext, sRangeName, excel::getDocShell( xModel ), formula::FormulaGrammar::CONV_XL_R1C1 );
567 if( bScroll )
569 xVbaSheetRange->Select();
570 uno::Reference< excel::XWindow > xWindow = getActiveWindow();
571 ScSplitPos eWhich = pShell->GetViewData().GetActivePart();
572 sal_Int32 nValueX = pShell->GetViewData().GetPosX(WhichH(eWhich));
573 sal_Int32 nValueY = pShell->GetViewData().GetPosY(WhichV(eWhich));
574 xWindow->SmallScroll( uno::makeAny( (sal_Int16)(xVbaSheetRange->getRow() - 1) ),
575 uno::makeAny( (sal_Int16)nValueY ),
576 uno::makeAny( (sal_Int16)(xVbaSheetRange->getColumn() - 1) ),
577 uno::makeAny( (sal_Int16)nValueX ) );
578 gridWindow->GrabFocus();
580 else
582 xVbaSheetRange->Select();
583 gridWindow->GrabFocus();
586 catch (const uno::RuntimeException&)
588 //maybe this should be a procedure name
589 //TODO for procedure name
590 //browse::XBrowseNodeFactory is a singlton. OUString( "/singletons/com.sun.star.script.browse.theBrowseNodeFactory")
591 //and the createView( browse::BrowseNodeFactoryViewTypes::MACROSELECTOR ) to get a root browse::XBrowseNode.
592 //for query XInvocation interface.
593 //but how to directly get the XInvocation?
594 throw uno::RuntimeException("invalid reference for range name, it should be procedure name" );
596 return;
598 uno::Reference< excel::XRange > xRange;
599 if( Reference >>= xRange )
601 uno::Reference< excel::XRange > xVbaRange( Reference, uno::UNO_QUERY );
602 ScTabViewShell* pShell = excel::getCurrentBestViewShell( mxContext );
603 ScGridWindow* gridWindow = static_cast<ScGridWindow*>(pShell->GetWindow());
604 if ( xVbaRange.is() )
606 //TODO bScroll should be using, In this time, it doesenot have effection
607 if( bScroll )
609 xVbaRange->Select();
610 uno::Reference< excel::XWindow > xWindow = getActiveWindow();
611 ScSplitPos eWhich = pShell->GetViewData().GetActivePart();
612 sal_Int32 nValueX = pShell->GetViewData().GetPosX(WhichH(eWhich));
613 sal_Int32 nValueY = pShell->GetViewData().GetPosY(WhichV(eWhich));
614 xWindow->SmallScroll( uno::makeAny( (sal_Int16)(xVbaRange->getRow() - 1) ),
615 uno::makeAny( (sal_Int16)nValueY ),
616 uno::makeAny( (sal_Int16)(xVbaRange->getColumn() - 1) ),
617 uno::makeAny( (sal_Int16)nValueX ) );
618 gridWindow->GrabFocus();
620 else
622 xVbaRange->Select();
623 gridWindow->GrabFocus();
626 return;
628 throw uno::RuntimeException("invalid reference or name" );
631 sal_Int32 SAL_CALL
632 ScVbaApplication::getCursor() throw (uno::RuntimeException, std::exception)
634 PointerStyle nPointerStyle = getPointerStyle(getCurrentDocument());
636 switch( nPointerStyle )
638 case PointerStyle::Arrow:
639 return excel::XlMousePointer::xlNorthwestArrow;
640 case PointerStyle::Null:
641 return excel::XlMousePointer::xlDefault;
642 case PointerStyle::Wait:
643 return excel::XlMousePointer::xlWait;
644 case PointerStyle::Text:
645 return excel::XlMousePointer::xlIBeam;
646 default:
647 return excel::XlMousePointer::xlDefault;
651 void SAL_CALL
652 ScVbaApplication::setCursor( sal_Int32 _cursor ) throw (uno::RuntimeException, std::exception)
656 uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
657 switch( _cursor )
659 case excel::XlMousePointer::xlNorthwestArrow:
661 const Pointer& rPointer( PointerStyle::Arrow );
662 setCursorHelper( xModel, rPointer, false );
663 break;
665 case excel::XlMousePointer::xlWait:
666 case excel::XlMousePointer::xlIBeam:
668 const Pointer& rPointer( static_cast< PointerStyle >( _cursor ) );
669 //It will set the edit window, toobar and statusbar's mouse pointer.
670 setCursorHelper( xModel, rPointer, true );
671 break;
673 case excel::XlMousePointer::xlDefault:
675 const Pointer& rPointer( PointerStyle::Null );
676 setCursorHelper( xModel, rPointer, false );
677 break;
679 default:
680 throw uno::RuntimeException("Unknown value for Cursor pointer" );
681 // TODO: isn't this a flaw in the API? It should be allowed to throw an
682 // IllegalArgumentException, or so
685 catch (const uno::Exception&)
687 DBG_UNHANDLED_EXCEPTION();
691 // #TODO perhaps we should switch the return type depending of the filter
692 // type, e.g. return Calc for Calc and Excel if its an imported doc
693 OUString SAL_CALL
694 ScVbaApplication::getName() throw (uno::RuntimeException, std::exception)
696 return OUString("Microsoft Excel" );
699 // #TODO #FIXME get/setDisplayAlerts are just stub impl
700 // here just the status of the switch is set
701 // the function that throws an error message needs to
702 // evaluate this switch in order to know whether it has to disable the
703 // error message thrown by OpenOffice
705 void SAL_CALL
706 ScVbaApplication::setDisplayAlerts(sal_Bool displayAlerts) throw (uno::RuntimeException, std::exception)
708 mrAppSettings.mbDisplayAlerts = displayAlerts;
711 sal_Bool SAL_CALL
712 ScVbaApplication::getDisplayAlerts() throw (uno::RuntimeException, std::exception)
714 return mrAppSettings.mbDisplayAlerts;
717 void SAL_CALL
718 ScVbaApplication::setEnableEvents(sal_Bool bEnable) throw (uno::RuntimeException, std::exception)
720 mrAppSettings.mbEnableEvents = bEnable;
723 sal_Bool SAL_CALL
724 ScVbaApplication::getEnableEvents() throw (uno::RuntimeException, std::exception)
726 return mrAppSettings.mbEnableEvents;
729 void SAL_CALL
730 ScVbaApplication::setEnableCancelKey(sal_Bool bEnable) throw (uno::RuntimeException, std::exception)
732 // Stub, does nothing
733 mrAppSettings.mbEnableCancelKey = bEnable;
736 sal_Bool SAL_CALL
737 ScVbaApplication::getEnableCancelKey() throw (uno::RuntimeException, std::exception)
739 return mrAppSettings.mbEnableCancelKey;
742 sal_Bool SAL_CALL
743 ScVbaApplication::getDisplayFullScreen() throw (uno::RuntimeException, std::exception)
745 SfxViewShell* pShell = excel::getCurrentBestViewShell( mxContext );
746 if ( pShell )
747 return ScViewUtil::IsFullScreen( *pShell );
748 return sal_False;
751 void SAL_CALL
752 ScVbaApplication::setDisplayFullScreen( sal_Bool bSet ) throw (uno::RuntimeException, std::exception)
754 // #FIXME calling ScViewUtil::SetFullScreen( *pShell, bSet );
755 // directly results in a strange crash, using dispatch instead
756 if ( bSet != getDisplayFullScreen() )
757 dispatchRequests( getCurrentDocument(), OUString(".uno:FullScreen") );
760 sal_Bool SAL_CALL
761 ScVbaApplication::getDisplayScrollBars() throw (uno::RuntimeException, std::exception)
763 ScTabViewShell* pShell = excel::getCurrentBestViewShell( mxContext );
764 if ( pShell )
766 return ( pShell->GetViewData().IsHScrollMode() && pShell->GetViewData().IsVScrollMode() );
768 return true;
771 void SAL_CALL
772 ScVbaApplication::setDisplayScrollBars( sal_Bool bSet ) throw (uno::RuntimeException, std::exception)
774 // use uno here as it does all he repainting etc. magic
775 uno::Reference< sheet::XSpreadsheetView > xView( getCurrentDocument()->getCurrentController(), uno::UNO_QUERY_THROW );
776 uno::Reference< beans::XPropertySet > xProps( xView, uno::UNO_QUERY );
777 xProps->setPropertyValue("HasVerticalScrollBar", uno::makeAny( bSet ) );
778 xProps->setPropertyValue("HasHorizontalScrollBar", uno::makeAny( bSet ) );
781 sal_Bool SAL_CALL
782 ScVbaApplication::getDisplayExcel4Menus() throw (css::uno::RuntimeException, std::exception)
784 return mrAppSettings.mbExcel4Menus;
787 void SAL_CALL
788 ScVbaApplication::setDisplayExcel4Menus( sal_Bool bSet ) throw (css::uno::RuntimeException, std::exception)
790 mrAppSettings.mbExcel4Menus = bSet;
793 sal_Bool SAL_CALL
794 ScVbaApplication::getDisplayNoteIndicator() throw (css::uno::RuntimeException, std::exception)
796 return mrAppSettings.mbDisplayNoteIndicator;
799 void SAL_CALL
800 ScVbaApplication::setDisplayNoteIndicator( sal_Bool bSet ) throw (css::uno::RuntimeException, std::exception)
802 mrAppSettings.mbDisplayNoteIndicator = bSet;
805 sal_Bool SAL_CALL
806 ScVbaApplication::getShowWindowsInTaskbar() throw (css::uno::RuntimeException, std::exception)
808 return mrAppSettings.mbShowWindowsInTaskbar;
811 void SAL_CALL
812 ScVbaApplication::setShowWindowsInTaskbar( sal_Bool bSet ) throw (css::uno::RuntimeException, std::exception)
814 mrAppSettings.mbShowWindowsInTaskbar = bSet;
817 sal_Bool SAL_CALL
818 ScVbaApplication::getIteration() throw (css::uno::RuntimeException, std::exception)
820 return SC_MOD()->GetDocOptions().IsIter();
823 void SAL_CALL
824 ScVbaApplication::setIteration( sal_Bool bSet ) throw (css::uno::RuntimeException, std::exception)
826 uno::Reference< lang::XMultiComponentFactory > xSMgr(
827 mxContext->getServiceManager(), uno::UNO_QUERY_THROW );
829 uno::Reference< frame::XDesktop > xDesktop
830 (xSMgr->createInstanceWithContext( "com.sun.star.frame.Desktop" , mxContext), uno::UNO_QUERY_THROW );
831 uno::Reference< container::XEnumeration > xComponents = xDesktop->getComponents()->createEnumeration();
832 while ( xComponents->hasMoreElements() )
834 uno::Reference< lang::XServiceInfo > xServiceInfo( xComponents->nextElement(), uno::UNO_QUERY );
835 if ( xServiceInfo.is() && xServiceInfo->supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) )
837 uno::Reference< beans::XPropertySet > xProps( xServiceInfo, uno::UNO_QUERY );
838 if ( xProps.is() )
839 xProps->setPropertyValue( SC_UNO_ITERENABLED, uno::Any( bSet ) );
842 ScDocOptions aOpts( SC_MOD()->GetDocOptions() );
843 aOpts.SetIter( bSet );
844 SC_MOD()->SetDocOptions( aOpts );
847 void SAL_CALL
848 ScVbaApplication::Calculate() throw( script::BasicErrorException , uno::RuntimeException, std::exception )
850 uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
851 uno::Reference< sheet::XCalculatable > xCalculatable( getCurrentDocument(), uno::UNO_QUERY_THROW );
852 xCalculatable->calculateAll();
855 static uno::Reference< util::XPathSettings > lcl_getPathSettingsService( const uno::Reference< uno::XComponentContext >& xContext ) throw ( uno::RuntimeException )
857 static uno::Reference< util::XPathSettings > xPathSettings;
858 if ( !xPathSettings.is() )
860 xPathSettings.set( util::PathSettings::create( xContext ) );
862 return xPathSettings;
865 OUString ScVbaApplication::getOfficePath( const OUString& _sPathType ) throw (uno::RuntimeException)
867 OUString sRetPath;
868 uno::Reference< util::XPathSettings > xProps = lcl_getPathSettingsService( mxContext );
871 OUString sUrl;
872 xProps->getPropertyValue( _sPathType ) >>= sUrl;
874 // if it's a list of paths then use the last one
875 sal_Int32 nIndex = sUrl.lastIndexOf( ';' ) ;
876 if ( nIndex > 0 )
877 sUrl = sUrl.copy( nIndex + 1 );
878 ::osl::File::getSystemPathFromFileURL( sUrl, sRetPath );
880 catch (const uno::Exception&)
882 DebugHelper::runtimeexception(SbERR_METHOD_FAILED, OUString());
884 return sRetPath;
887 void SAL_CALL
888 ScVbaApplication::setDefaultFilePath( const OUString& DefaultFilePath ) throw (uno::RuntimeException, std::exception)
890 uno::Reference< util::XPathSettings > xProps = lcl_getPathSettingsService( mxContext );
891 OUString aURL;
892 osl::FileBase::getFileURLFromSystemPath( DefaultFilePath, aURL );
893 xProps->setWork( aURL );
896 OUString SAL_CALL
897 ScVbaApplication::getDefaultFilePath() throw (uno::RuntimeException, std::exception)
899 return getOfficePath( OUString("Work"));
902 OUString SAL_CALL
903 ScVbaApplication::getLibraryPath() throw (uno::RuntimeException, std::exception)
905 return getOfficePath( OUString("Basic"));
908 OUString SAL_CALL
909 ScVbaApplication::getTemplatesPath() throw (uno::RuntimeException, std::exception)
911 return getOfficePath( OUString("Template"));
914 OUString SAL_CALL
915 ScVbaApplication::getPathSeparator() throw (uno::RuntimeException, std::exception)
917 return OUString( (sal_Unicode) SAL_PATHDELIMITER );
920 // Helpers for Intersect and Union
922 namespace {
924 typedef ::std::list< ScRange > ListOfScRange;
926 /** Appends all ranges of a VBA Range object in the passed Any to the list of ranges. */
927 void lclAddToListOfScRange( ListOfScRange& rList, const uno::Any& rArg )
928 throw (script::BasicErrorException, uno::RuntimeException)
930 if( rArg.hasValue() )
932 uno::Reference< excel::XRange > xRange( rArg, uno::UNO_QUERY_THROW );
933 uno::Reference< XCollection > xCol( xRange->Areas( uno::Any() ), uno::UNO_QUERY_THROW );
934 for( sal_Int32 nIdx = 1, nCount = xCol->getCount(); nIdx <= nCount; ++nIdx )
936 uno::Reference< excel::XRange > xAreaRange( xCol->Item( uno::Any( nIdx ), uno::Any() ), uno::UNO_QUERY_THROW );
937 uno::Reference< sheet::XCellRangeAddressable > xAddressable( xAreaRange->getCellRange(), uno::UNO_QUERY_THROW );
938 ScRange aScRange;
939 ScUnoConversion::FillScRange( aScRange, xAddressable->getRangeAddress() );
940 rList.push_back( aScRange );
945 /** Returns true, if the passed ranges can be expressed by a single range. The
946 new range will be contained in r1 then, the range r2 can be removed. */
947 bool lclTryJoin( ScRange& r1, const ScRange& r2 )
949 // 1) r2 is completely inside r1
950 if( r1.In( r2 ) )
951 return true;
953 // 2) r1 is completely inside r2
954 if( r2.In( r1 ) )
956 r1 = r2;
957 return true;
960 SCCOL n1L = r1.aStart.Col();
961 SCCOL n1R = r1.aEnd.Col();
962 SCROW n1T = r1.aStart.Row();
963 SCROW n1B = r1.aEnd.Row();
964 SCCOL n2L = r2.aStart.Col();
965 SCCOL n2R = r2.aEnd.Col();
966 SCROW n2T = r2.aStart.Row();
967 SCROW n2B = r2.aEnd.Row();
969 // 3) r1 and r2 have equal upper and lower border
970 if( (n1T == n2T) && (n1B == n2B) )
972 // check that r1 overlaps or touches r2
973 if( ((n1L < n2L) && (n2L - 1 <= n1R)) || ((n2L < n1L) && (n1L - 1 <= n2R)) )
975 r1.aStart.SetCol( ::std::min( n1L, n2L ) );
976 r1.aEnd.SetCol( ::std::max( n1R, n2R ) );
977 return true;
979 return false;
982 // 4) r1 and r2 have equal left and right border
983 if( (n1L == n2L) && (n1R == n2R) )
985 // check that r1 overlaps or touches r2
986 if( ((n1T < n2T) && (n2T + 1 <= n1B)) || ((n2T < n1T) && (n1T + 1 <= n2B)) )
988 r1.aStart.SetRow( ::std::min( n1T, n2T ) );
989 r1.aEnd.SetRow( ::std::max( n1B, n2B ) );
990 return true;
992 return false;
995 // 5) cannot join these ranges
996 return false;
999 /** Strips out ranges that are contained by other ranges, joins ranges that can be joined
1000 together (aligned borders, e.g. A4:D10 and B4:E10 would be combined to A4:E10. */
1001 void lclJoinRanges( ListOfScRange& rList )
1003 ListOfScRange::iterator aOuterIt = rList.begin();
1004 while( aOuterIt != rList.end() )
1006 bool bAnyErased = false; // true = any range erased from rList
1007 ListOfScRange::iterator aInnerIt = rList.begin();
1008 while( aInnerIt != rList.end() )
1010 bool bInnerErased = false; // true = aInnerIt erased from rList
1011 // do not compare a range with itself
1012 if( (aOuterIt != aInnerIt) && lclTryJoin( *aOuterIt, *aInnerIt ) )
1014 // aOuterIt points to joined range, aInnerIt will be removed
1015 aInnerIt = rList.erase( aInnerIt );
1016 bInnerErased = bAnyErased = true;
1018 /* If aInnerIt has been erased from rList, it already points to
1019 the next element (return value of list::erase()). */
1020 if( !bInnerErased )
1021 ++aInnerIt;
1023 // if any range has been erased, repeat outer loop with the same range
1024 if( !bAnyErased )
1025 ++aOuterIt;
1029 /** Intersects the passed list with all ranges of a VBA Range object in the passed Any. */
1030 void lclIntersectRanges( ListOfScRange& rList, const uno::Any& rArg )
1031 throw (script::BasicErrorException, uno::RuntimeException)
1033 // extract the ranges from the passed argument, will throw on invalid data
1034 ListOfScRange aList2;
1035 lclAddToListOfScRange( aList2, rArg );
1036 // do nothing, if the passed list is already empty
1037 if( !rList.empty() && !aList2.empty() )
1039 // save original list in a local
1040 ListOfScRange aList1;
1041 aList1.swap( rList );
1042 // join ranges from passed argument
1043 lclJoinRanges( aList2 );
1044 // calculate intersection of the ranges in both lists
1045 for( ListOfScRange::const_iterator aOuterIt = aList1.begin(), aOuterEnd = aList1.end(); aOuterIt != aOuterEnd; ++aOuterIt )
1047 for( ListOfScRange::const_iterator aInnerIt = aList2.begin(), aInnerEnd = aList2.end(); aInnerIt != aInnerEnd; ++aInnerIt )
1049 if( aOuterIt->Intersects( *aInnerIt ) )
1051 ScRange aIsectRange(
1052 std::max( aOuterIt->aStart.Col(), aInnerIt->aStart.Col() ),
1053 std::max( aOuterIt->aStart.Row(), aInnerIt->aStart.Row() ),
1054 std::max( aOuterIt->aStart.Tab(), aInnerIt->aStart.Tab() ),
1055 std::min( aOuterIt->aEnd.Col(), aInnerIt->aEnd.Col() ),
1056 std::min( aOuterIt->aEnd.Row(), aInnerIt->aEnd.Row() ),
1057 std::min( aOuterIt->aEnd.Tab(), aInnerIt->aEnd.Tab() ) );
1058 rList.push_back( aIsectRange );
1062 // again, join the result ranges
1063 lclJoinRanges( rList );
1067 /** Creates a VBA Range object from the passed list of ranges. */
1068 uno::Reference< excel::XRange > lclCreateVbaRange(
1069 const uno::Reference< uno::XComponentContext >& rxContext,
1070 const uno::Reference< frame::XModel >& rxModel,
1071 const ListOfScRange& rList ) throw (uno::RuntimeException)
1073 ScDocShell* pDocShell = excel::getDocShell( rxModel );
1074 if( !pDocShell ) throw uno::RuntimeException();
1076 ScRangeList aCellRanges;
1077 for( ListOfScRange::const_iterator aIt = rList.begin(), aEnd = rList.end(); aIt != aEnd; ++aIt )
1078 aCellRanges.Append( *aIt );
1080 if( aCellRanges.size() == 1 )
1082 uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pDocShell, *aCellRanges.front() ) );
1083 return new ScVbaRange( excel::getUnoSheetModuleObj( xRange ), rxContext, xRange );
1085 if( aCellRanges.size() > 1 )
1087 uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( pDocShell, aCellRanges ) );
1088 return new ScVbaRange( excel::getUnoSheetModuleObj( xRanges ), rxContext, xRanges );
1090 return 0;
1093 } // namespace
1095 uno::Reference< excel::XRange > SAL_CALL ScVbaApplication::Intersect(
1096 const uno::Reference< excel::XRange >& rArg1, const uno::Reference< excel::XRange >& rArg2,
1097 const uno::Any& rArg3, const uno::Any& rArg4, const uno::Any& rArg5, const uno::Any& rArg6,
1098 const uno::Any& rArg7, const uno::Any& rArg8, const uno::Any& rArg9, const uno::Any& rArg10,
1099 const uno::Any& rArg11, const uno::Any& rArg12, const uno::Any& rArg13, const uno::Any& rArg14,
1100 const uno::Any& rArg15, const uno::Any& rArg16, const uno::Any& rArg17, const uno::Any& rArg18,
1101 const uno::Any& rArg19, const uno::Any& rArg20, const uno::Any& rArg21, const uno::Any& rArg22,
1102 const uno::Any& rArg23, const uno::Any& rArg24, const uno::Any& rArg25, const uno::Any& rArg26,
1103 const uno::Any& rArg27, const uno::Any& rArg28, const uno::Any& rArg29, const uno::Any& rArg30 )
1104 throw (script::BasicErrorException, uno::RuntimeException, std::exception)
1106 if( !rArg1.is() || !rArg2.is() )
1107 DebugHelper::basicexception( SbERR_BAD_PARAMETER, OUString() );
1109 // initialize the result list with 1st parameter, join its ranges together
1110 ListOfScRange aList;
1111 lclAddToListOfScRange( aList, uno::Any( rArg1 ) );
1112 lclJoinRanges( aList );
1114 // process all other parameters, this updates the list with intersection
1115 lclIntersectRanges( aList, uno::Any( rArg2 ) );
1116 lclIntersectRanges( aList, rArg3 );
1117 lclIntersectRanges( aList, rArg4 );
1118 lclIntersectRanges( aList, rArg5 );
1119 lclIntersectRanges( aList, rArg6 );
1120 lclIntersectRanges( aList, rArg7 );
1121 lclIntersectRanges( aList, rArg8 );
1122 lclIntersectRanges( aList, rArg9 );
1123 lclIntersectRanges( aList, rArg10 );
1124 lclIntersectRanges( aList, rArg11 );
1125 lclIntersectRanges( aList, rArg12 );
1126 lclIntersectRanges( aList, rArg13 );
1127 lclIntersectRanges( aList, rArg14 );
1128 lclIntersectRanges( aList, rArg15 );
1129 lclIntersectRanges( aList, rArg16 );
1130 lclIntersectRanges( aList, rArg17 );
1131 lclIntersectRanges( aList, rArg18 );
1132 lclIntersectRanges( aList, rArg19 );
1133 lclIntersectRanges( aList, rArg20 );
1134 lclIntersectRanges( aList, rArg21 );
1135 lclIntersectRanges( aList, rArg22 );
1136 lclIntersectRanges( aList, rArg23 );
1137 lclIntersectRanges( aList, rArg24 );
1138 lclIntersectRanges( aList, rArg25 );
1139 lclIntersectRanges( aList, rArg26 );
1140 lclIntersectRanges( aList, rArg27 );
1141 lclIntersectRanges( aList, rArg28 );
1142 lclIntersectRanges( aList, rArg29 );
1143 lclIntersectRanges( aList, rArg30 );
1145 // create the VBA Range object
1146 return lclCreateVbaRange( mxContext, getCurrentDocument(), aList );
1149 uno::Reference< excel::XRange > SAL_CALL ScVbaApplication::Union(
1150 const uno::Reference< excel::XRange >& rArg1, const uno::Reference< excel::XRange >& rArg2,
1151 const uno::Any& rArg3, const uno::Any& rArg4, const uno::Any& rArg5, const uno::Any& rArg6,
1152 const uno::Any& rArg7, const uno::Any& rArg8, const uno::Any& rArg9, const uno::Any& rArg10,
1153 const uno::Any& rArg11, const uno::Any& rArg12, const uno::Any& rArg13, const uno::Any& rArg14,
1154 const uno::Any& rArg15, const uno::Any& rArg16, const uno::Any& rArg17, const uno::Any& rArg18,
1155 const uno::Any& rArg19, const uno::Any& rArg20, const uno::Any& rArg21, const uno::Any& rArg22,
1156 const uno::Any& rArg23, const uno::Any& rArg24, const uno::Any& rArg25, const uno::Any& rArg26,
1157 const uno::Any& rArg27, const uno::Any& rArg28, const uno::Any& rArg29, const uno::Any& rArg30 )
1158 throw (script::BasicErrorException, uno::RuntimeException, std::exception)
1160 if( !rArg1.is() || !rArg2.is() )
1161 DebugHelper::basicexception( SbERR_BAD_PARAMETER, OUString() );
1163 ListOfScRange aList;
1164 lclAddToListOfScRange( aList, uno::Any( rArg1 ) );
1165 lclAddToListOfScRange( aList, uno::Any( rArg2 ) );
1166 lclAddToListOfScRange( aList, rArg3 );
1167 lclAddToListOfScRange( aList, rArg4 );
1168 lclAddToListOfScRange( aList, rArg5 );
1169 lclAddToListOfScRange( aList, rArg6 );
1170 lclAddToListOfScRange( aList, rArg7 );
1171 lclAddToListOfScRange( aList, rArg8 );
1172 lclAddToListOfScRange( aList, rArg9 );
1173 lclAddToListOfScRange( aList, rArg10 );
1174 lclAddToListOfScRange( aList, rArg11 );
1175 lclAddToListOfScRange( aList, rArg12 );
1176 lclAddToListOfScRange( aList, rArg13 );
1177 lclAddToListOfScRange( aList, rArg14 );
1178 lclAddToListOfScRange( aList, rArg15 );
1179 lclAddToListOfScRange( aList, rArg16 );
1180 lclAddToListOfScRange( aList, rArg17 );
1181 lclAddToListOfScRange( aList, rArg18 );
1182 lclAddToListOfScRange( aList, rArg19 );
1183 lclAddToListOfScRange( aList, rArg20 );
1184 lclAddToListOfScRange( aList, rArg21 );
1185 lclAddToListOfScRange( aList, rArg22 );
1186 lclAddToListOfScRange( aList, rArg23 );
1187 lclAddToListOfScRange( aList, rArg24 );
1188 lclAddToListOfScRange( aList, rArg25 );
1189 lclAddToListOfScRange( aList, rArg26 );
1190 lclAddToListOfScRange( aList, rArg27 );
1191 lclAddToListOfScRange( aList, rArg28 );
1192 lclAddToListOfScRange( aList, rArg29 );
1193 lclAddToListOfScRange( aList, rArg30 );
1195 // simply join together all ranges as much as possible, strip out covered ranges etc.
1196 lclJoinRanges( aList );
1198 // create the VBA Range object
1199 return lclCreateVbaRange( mxContext, getCurrentDocument(), aList );
1202 double
1203 ScVbaApplication::InchesToPoints( double Inches ) throw (uno::RuntimeException, std::exception )
1205 double result = ( Inches * 72.0 );
1206 return result;
1209 void
1210 ScVbaApplication::Volatile( const uno::Any& aVolatile ) throw ( uno::RuntimeException, std::exception )
1212 bool bVolatile = true;
1213 aVolatile >>= bVolatile;
1214 SbMethod* pMeth = StarBASIC::GetActiveMethod();
1215 if ( pMeth )
1217 OSL_TRACE("ScVbaApplication::Volatile() In method ->%s<-", OUStringToOString( pMeth->GetName(), RTL_TEXTENCODING_UTF8 ).getStr() );
1218 uno::Reference< frame::XModel > xModel( getCurrentDocument() );
1219 ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument();
1220 rDoc.GetMacroManager()->SetUserFuncVolatile( pMeth->GetName(), bVolatile);
1223 // this is bound to break when loading the document
1224 return;
1227 sal_Bool SAL_CALL
1228 ScVbaApplication::getDisplayFormulaBar()
1229 throw (css::uno::RuntimeException, std::exception)
1231 bool bRes = false;
1232 ScTabViewShell* pViewShell = excel::getCurrentBestViewShell( mxContext );
1233 if ( pViewShell )
1235 SfxBoolItem sfxFormBar( FID_TOGGLEINPUTLINE);
1236 SfxAllItemSet reqList( SfxGetpApp()->GetPool() );
1237 reqList.Put( sfxFormBar );
1239 pViewShell->GetState( reqList );
1240 const SfxPoolItem *pItem=0;
1241 if ( reqList.GetItemState( FID_TOGGLEINPUTLINE, false, &pItem ) == SfxItemState::SET )
1242 bRes = static_cast<const SfxBoolItem*>(pItem)->GetValue();
1244 return bRes;
1247 void SAL_CALL
1248 ScVbaApplication::setDisplayFormulaBar( sal_Bool _displayformulabar )
1249 throw(css::uno::RuntimeException, std::exception)
1251 ScTabViewShell* pViewShell = excel::getCurrentBestViewShell( mxContext );
1252 if ( pViewShell && ( _displayformulabar != getDisplayFormulaBar() ) )
1254 SfxBoolItem sfxFormBar( FID_TOGGLEINPUTLINE, _displayformulabar);
1255 SfxAllItemSet reqList( SfxGetpApp()->GetPool() );
1256 SfxRequest aReq( FID_TOGGLEINPUTLINE, SfxCallMode::SLOT, reqList );
1257 pViewShell->Execute( aReq );
1261 uno::Any SAL_CALL
1262 ScVbaApplication::Caller( const uno::Any& /*aIndex*/ ) throw ( uno::RuntimeException, std::exception )
1264 StarBASIC* pBasic = SfxApplication::GetBasic();
1265 SbMethod* pMeth = static_cast<SbMethod*>(pBasic->GetRtl()->Find( OUString("FuncCaller"), SbxCLASS_METHOD ));
1266 uno::Any aRet;
1267 if ( pMeth )
1269 SbxVariableRef refTemp = pMeth;
1270 // forces a broadcast
1271 SbxVariableRef pNew = new SbxMethod( *((SbxMethod*)pMeth));
1272 OSL_TRACE("pNew has type %d and string value %s", pNew->GetType(), OUStringToOString( pNew->GetOUString(), RTL_TEXTENCODING_UTF8 ).getStr() );
1273 aRet = sbxToUnoValue( pNew );
1275 return aRet;
1278 uno::Reference< frame::XModel >
1279 ScVbaApplication::getCurrentDocument() throw (css::uno::RuntimeException)
1281 return getCurrentExcelDoc(mxContext);
1284 uno::Any SAL_CALL
1285 ScVbaApplication::MenuBars( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
1287 uno::Reference< XCommandBars > xCommandBars( CommandBars( uno::Any() ), uno::UNO_QUERY_THROW );
1288 uno::Reference< XCollection > xMenuBars( new ScVbaMenuBars( this, mxContext, xCommandBars ) );
1289 if ( aIndex.hasValue() )
1291 return uno::Any ( xMenuBars->Item( aIndex, uno::Any() ) );
1294 return uno::Any( xMenuBars );
1297 void SAL_CALL ScVbaApplication::OnKey( const OUString& Key, const uno::Any& Procedure ) throw (uno::RuntimeException, std::exception)
1301 // Perhaps we can catch some excel specific
1302 // related behaviour here
1303 VbaApplicationBase::OnKey( Key, Procedure );
1305 catch( container::NoSuchElementException& )
1307 // #TODO special handling for unhandled
1308 // bindings
1312 void SAL_CALL ScVbaApplication::Undo() throw (uno::RuntimeException, std::exception)
1314 uno::Reference< frame::XModel > xModel( getThisExcelDoc( mxContext ), uno::UNO_SET_THROW );
1316 ScTabViewShell* pViewShell = excel::getBestViewShell( xModel );
1317 if ( pViewShell )
1318 dispatchExecute( pViewShell, SID_UNDO );
1321 OUString
1322 ScVbaApplication::getServiceImplName()
1324 return OUString("ScVbaApplication");
1327 uno::Sequence< OUString >
1328 ScVbaApplication::getServiceNames()
1330 static uno::Sequence< OUString > aServiceNames;
1331 if ( aServiceNames.getLength() == 0 )
1333 aServiceNames.realloc( 1 );
1334 aServiceNames[ 0 ] = "ooo.vba.excel.Application";
1336 return aServiceNames;
1339 namespace application
1341 namespace sdecl = comphelper::service_decl;
1342 sdecl::vba_service_class_<ScVbaApplication, sdecl::with_args<false> > serviceImpl;
1343 extern sdecl::ServiceDecl const serviceDecl(
1344 serviceImpl,
1345 "ScVbaApplication",
1346 "ooo.vba.excel.Application" );
1349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */