1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <com/sun/star/frame/XLayoutManager.hpp>
23 #include <com/sun/star/frame/XLayoutManager.hpp>
24 #include <com/sun/star/frame/XDesktop.hpp>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <com/sun/star/sheet/XCalculatable.hpp>
27 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
28 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
29 #include <com/sun/star/sheet/XNamedRanges.hpp>
30 #include <com/sun/star/sheet/XSpreadsheetView.hpp>
31 #include <com/sun/star/sheet/XSpreadsheets.hpp>
32 #include <com/sun/star/task/XStatusIndicatorSupplier.hpp>
33 #include <com/sun/star/task/XStatusIndicator.hpp>
34 #include <com/sun/star/util/PathSettings.hpp>
35 #include <com/sun/star/view/XSelectionSupplier.hpp>
36 #include <ooo/vba/XExecutableDialog.hpp>
37 #include <ooo/vba/excel/XlCalculation.hpp>
38 #include <ooo/vba/excel/XlMousePointer.hpp>
40 #include "vbaapplication.hxx"
41 #include "vbaworkbooks.hxx"
42 #include "vbaworkbook.hxx"
43 #include "vbaworksheets.hxx"
44 #include "vbarange.hxx"
45 #include "vbawsfunction.hxx"
46 #include "vbadialogs.hxx"
47 #include "vbawindow.hxx"
48 #include "vbawindows.hxx"
49 #include "vbaglobals.hxx"
50 #include "vbamenubars.hxx"
51 #include "tabvwsh.hxx"
52 #include "gridwin.hxx"
53 #include "vbanames.hxx"
54 #include <vbahelper/vbashape.hxx>
55 #include "vbatextboxshape.hxx"
56 #include "vbaassistant.hxx"
58 #include "macromgr.hxx"
59 #include "defaultsoptions.hxx"
61 #include <osl/file.hxx>
62 #include <rtl/instance.hxx>
64 #include <sfx2/request.hxx>
65 #include <sfx2/objsh.hxx>
66 #include <sfx2/viewfrm.hxx>
67 #include <sfx2/app.hxx>
69 #include <comphelper/processfactory.hxx>
71 #include <toolkit/awt/vclxwindow.hxx>
72 #include <toolkit/helper/vclunohelper.hxx>
74 #include <tools/diagnose_ex.h>
75 #include <tools/urlobj.hxx>
79 #include <basic/sbx.hxx>
80 #include <basic/sbstar.hxx>
81 #include <basic/sbuno.hxx>
82 #include <basic/sbmeth.hxx>
84 #include "convuno.hxx"
85 #include "cellsuno.hxx"
86 #include "miscuno.hxx"
87 #include "unonames.hxx"
89 #include <vbahelper/helperdecl.hxx>
90 #include "excelvbahelper.hxx"
92 #include <basic/sbmod.hxx>
93 #include <basic/sbxobj.hxx>
95 #include "viewutil.hxx"
96 #include "docoptio.hxx"
98 using namespace ::ooo::vba
;
99 using namespace ::com::sun::star
;
100 using ::com::sun::star::uno::Reference
;
101 using ::com::sun::star::uno::UNO_QUERY_THROW
;
102 using ::com::sun::star::uno::UNO_QUERY
;
104 // ============================================================================
106 /** Global application settings shared by all open workbooks. */
107 struct ScVbaAppSettings
109 sal_Int32 mnCalculation
;
110 sal_Bool mbDisplayAlerts
;
111 sal_Bool mbEnableEvents
;
112 sal_Bool mbExcel4Menus
;
113 sal_Bool mbDisplayNoteIndicator
;
114 sal_Bool mbShowWindowsInTaskbar
;
115 sal_Bool mbEnableCancelKey
;
116 explicit ScVbaAppSettings();
119 ScVbaAppSettings::ScVbaAppSettings() :
120 mnCalculation( excel::XlCalculation::xlCalculationAutomatic
),
121 mbDisplayAlerts( sal_True
),
122 mbEnableEvents( sal_True
),
123 mbExcel4Menus( sal_False
),
124 mbDisplayNoteIndicator( sal_True
),
125 mbShowWindowsInTaskbar( sal_True
),
126 mbEnableCancelKey( sal_False
)
130 struct ScVbaStaticAppSettings
: public ::rtl::Static
< ScVbaAppSettings
, ScVbaStaticAppSettings
> {};
132 // ============================================================================
134 ScVbaApplication::ScVbaApplication( const uno::Reference
<uno::XComponentContext
>& xContext
) :
135 ScVbaApplication_BASE( xContext
),
136 mrAppSettings( ScVbaStaticAppSettings::get() )
140 ScVbaApplication::~ScVbaApplication()
144 /*static*/ bool ScVbaApplication::getDocumentEventsEnabled()
146 return ScVbaStaticAppSettings::get().mbEnableEvents
;
149 SfxObjectShell
* ScVbaApplication::GetDocShell( const uno::Reference
< frame::XModel
>& xModel
) throw (uno::RuntimeException
)
151 return static_cast< SfxObjectShell
* >( excel::getDocShell( xModel
) );
155 ScVbaApplication::getExactName( const OUString
& aApproximateName
) throw (uno::RuntimeException
)
157 uno::Reference
< beans::XExactName
> xWSF( new ScVbaWSFunction( this, mxContext
) );
158 return xWSF
->getExactName( aApproximateName
);
161 uno::Reference
< beans::XIntrospectionAccess
> SAL_CALL
162 ScVbaApplication::getIntrospection() throw(css::uno::RuntimeException
)
164 uno::Reference
< script::XInvocation
> xWSF( new ScVbaWSFunction( this, mxContext
) );
165 return xWSF
->getIntrospection();
169 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
)
171 /* When calling the functions directly at the Application object, no runtime
172 errors are thrown, but the error is inserted into the return value. */
176 uno::Reference
< script::XInvocation
> xWSF( new ScVbaWSFunction( this, mxContext
) );
177 aAny
= xWSF
->invoke( FunctionName
, Params
, OutParamIndex
, OutParam
);
179 catch (const uno::Exception
&)
181 aAny
<<= script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), 1000, OUString() );
187 ScVbaApplication::setValue( const OUString
& PropertyName
, const uno::Any
& Value
) throw(beans::UnknownPropertyException
, script::CannotConvertException
, reflection::InvocationTargetException
, uno::RuntimeException
)
189 uno::Reference
< script::XInvocation
> xWSF( new ScVbaWSFunction( this, mxContext
) );
190 xWSF
->setValue( PropertyName
, Value
);
194 ScVbaApplication::getValue( const OUString
& PropertyName
) throw(beans::UnknownPropertyException
, uno::RuntimeException
)
196 uno::Reference
< script::XInvocation
> xWSF( new ScVbaWSFunction( this, mxContext
) );
197 return xWSF
->getValue( PropertyName
);
201 ScVbaApplication::hasMethod( const OUString
& Name
) throw(uno::RuntimeException
)
203 uno::Reference
< script::XInvocation
> xWSF( new ScVbaWSFunction( this, mxContext
) );
204 return xWSF
->hasMethod( Name
);
208 ScVbaApplication::hasProperty( const OUString
& Name
) throw(uno::RuntimeException
)
210 uno::Reference
< script::XInvocation
> xWSF( new ScVbaWSFunction( this, mxContext
) );
211 return xWSF
->hasProperty( Name
);
214 uno::Reference
< excel::XWorkbook
>
215 ScVbaApplication::getActiveWorkbook() throw (uno::RuntimeException
)
217 uno::Reference
< frame::XModel
> xModel( getCurrentExcelDoc( 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
< excel::XWorkbook
> SAL_CALL
225 ScVbaApplication::getThisWorkbook() throw (uno::RuntimeException
)
227 uno::Reference
< frame::XModel
> xModel( getThisExcelDoc( mxContext
), uno::UNO_SET_THROW
);
228 uno::Reference
< excel::XWorkbook
> xWorkbook( getVBADocument( xModel
), uno::UNO_QUERY
);
229 if( xWorkbook
.is() ) return xWorkbook
;
230 // #i116936# getVBADocument() may return null in documents without global VBA mode enabled
231 return new ScVbaWorkbook( this, mxContext
, xModel
);
234 uno::Reference
< XAssistant
> SAL_CALL
235 ScVbaApplication::getAssistant() throw (uno::RuntimeException
)
237 return uno::Reference
< XAssistant
>( new ScVbaAssistant( this, mxContext
) );
241 ScVbaApplication::getSelection() throw (uno::RuntimeException
)
243 OSL_TRACE("** ScVbaApplication::getSelection() ** ");
244 uno::Reference
< frame::XModel
> xModel( getCurrentDocument() );
246 Reference
< view::XSelectionSupplier
> xSelSupp( xModel
->getCurrentController(), UNO_QUERY_THROW
);
247 Reference
< beans::XPropertySet
> xPropSet( xSelSupp
, UNO_QUERY_THROW
);
248 OUString
aPropName( SC_UNO_FILTERED_RANGE_SELECTION
);
249 uno::Any aOldVal
= xPropSet
->getPropertyValue( aPropName
);
252 xPropSet
->setPropertyValue( aPropName
, any
);
253 uno::Reference
< uno::XInterface
> aSelection
= ScUnoHelpFunctions::AnyToInterface(
254 xSelSupp
->getSelection() );
255 xPropSet
->setPropertyValue( aPropName
, aOldVal
);
257 if (!aSelection
.is())
259 throw uno::RuntimeException(
260 OUString("failed to obtain current selection"),
261 uno::Reference
< uno::XInterface
>() );
264 uno::Reference
< lang::XServiceInfo
> xServiceInfo( aSelection
, uno::UNO_QUERY_THROW
);
265 OUString sImplementationName
= xServiceInfo
->getImplementationName();
267 if( sImplementationName
.equalsIgnoreAsciiCase("com.sun.star.drawing.SvxShapeCollection") )
269 uno::Reference
< drawing::XShapes
> xShapes( aSelection
, uno::UNO_QUERY_THROW
);
270 uno::Reference
< container::XIndexAccess
> xIndexAccess( xShapes
, uno::UNO_QUERY_THROW
);
271 uno::Reference
< drawing::XShape
> xShape( xIndexAccess
->getByIndex(0), uno::UNO_QUERY_THROW
);
272 // if ScVbaShape::getType( xShape ) == office::MsoShapeType::msoAutoShape
273 // and the uno object implements the com.sun.star.drawing.Text service
274 // return a textboxshape object
275 if ( ScVbaShape::getType( xShape
) == office::MsoShapeType::msoAutoShape
)
277 uno::Reference
< lang::XServiceInfo
> xShapeServiceInfo( xShape
, uno::UNO_QUERY_THROW
);
278 if ( xShapeServiceInfo
->supportsService("com.sun.star.drawing.Text") )
280 return uno::makeAny( uno::Reference
< msforms::XTextBoxShape
>(new ScVbaTextBoxShape( mxContext
, xShape
, xShapes
, xModel
) ) );
283 return uno::makeAny( uno::Reference
< msforms::XShape
>(new ScVbaShape( this, mxContext
, xShape
, xShapes
, xModel
, ScVbaShape::getType( xShape
) ) ) );
285 else if( xServiceInfo
->supportsService("com.sun.star.sheet.SheetCellRange") ||
286 xServiceInfo
->supportsService("com.sun.star.sheet.SheetCellRanges") )
288 uno::Reference
< table::XCellRange
> xRange( aSelection
, ::uno::UNO_QUERY
);
291 uno::Reference
< sheet::XSheetCellRangeContainer
> xRanges( aSelection
, ::uno::UNO_QUERY
);
293 return uno::makeAny( uno::Reference
< excel::XRange
>( new ScVbaRange( excel::getUnoSheetModuleObj( xRanges
), mxContext
, xRanges
) ) );
296 return uno::makeAny( uno::Reference
< excel::XRange
>(new ScVbaRange( excel::getUnoSheetModuleObj( xRange
), mxContext
, xRange
) ) );
300 throw uno::RuntimeException( sImplementationName
+ OUString(
301 " not supported"), uno::Reference
< uno::XInterface
>() );
305 uno::Reference
< excel::XRange
>
306 ScVbaApplication::getActiveCell() throw (uno::RuntimeException
)
308 uno::Reference
< sheet::XSpreadsheetView
> xView( getCurrentDocument()->getCurrentController(), uno::UNO_QUERY_THROW
);
309 uno::Reference
< table::XCellRange
> xRange( xView
->getActiveSheet(), ::uno::UNO_QUERY_THROW
);
310 ScTabViewShell
* pViewShell
= excel::getCurrentBestViewShell(mxContext
);
312 throw uno::RuntimeException("No ViewShell available", uno::Reference
< uno::XInterface
>() );
313 ScViewData
* pTabView
= pViewShell
->GetViewData();
315 throw uno::RuntimeException("No ViewData available", uno::Reference
< uno::XInterface
>() );
317 sal_Int32 nCursorX
= pTabView
->GetCurX();
318 sal_Int32 nCursorY
= pTabView
->GetCurY();
320 // #i117392# excel::getUnoSheetModuleObj() may return null in documents without global VBA mode enabled
321 return new ScVbaRange( excel::getUnoSheetModuleObj( xRange
), mxContext
, xRange
->getCellRangeByPosition( nCursorX
, nCursorY
, nCursorX
, nCursorY
) );
325 ScVbaApplication::International( sal_Int32
/*Index*/ ) throw (uno::RuntimeException
)
327 // complete stub for now
328 // #TODO flesh out some of the Indices we could handle
334 ScVbaApplication::Workbooks( const uno::Any
& aIndex
) throw (uno::RuntimeException
)
336 uno::Reference
< XCollection
> xWorkBooks( new ScVbaWorkbooks( this, mxContext
) );
337 if ( aIndex
.getValueTypeClass() == uno::TypeClass_VOID
)
339 // void then somebody did Workbooks.something in vba
340 return uno::Any( xWorkBooks
);
343 return uno::Any ( xWorkBooks
->Item( aIndex
, uno::Any() ) );
347 ScVbaApplication::Worksheets( const uno::Any
& aIndex
) throw (uno::RuntimeException
)
349 uno::Reference
< excel::XWorkbook
> xWorkbook( getActiveWorkbook(), uno::UNO_SET_THROW
);
350 return xWorkbook
->Worksheets( aIndex
);
354 ScVbaApplication::WorksheetFunction( ) throw (::com::sun::star::uno::RuntimeException
)
356 return uno::makeAny( uno::Reference
< script::XInvocation
>( new ScVbaWSFunction( this, mxContext
) ) );
360 ScVbaApplication::Evaluate( const OUString
& Name
) throw (uno::RuntimeException
)
362 // #TODO Evaluate allows other things to be evaluated, e.g. functions
363 // I think ( like SIN(3) etc. ) need to investigate that
364 // named Ranges also? e.g. [MyRange] if so need a list of named ranges
366 return uno::Any( getActiveWorkbook()->getActiveSheet()->Range( uno::Any( Name
), aVoid
) );
370 ScVbaApplication::Dialogs( const uno::Any
&aIndex
) throw (uno::RuntimeException
)
372 uno::Reference
< excel::XDialogs
> xDialogs( new ScVbaDialogs( uno::Reference
< XHelperInterface
>( this ), mxContext
, getCurrentDocument() ) );
373 if( !aIndex
.hasValue() )
374 return uno::Any( xDialogs
);
375 return uno::Any( xDialogs
->Item( aIndex
) );
378 uno::Reference
< excel::XWindow
> SAL_CALL
379 ScVbaApplication::getActiveWindow() throw (uno::RuntimeException
)
381 uno::Reference
< frame::XModel
> xModel
= getCurrentDocument();
382 uno::Reference
< frame::XController
> xController( xModel
->getCurrentController(), uno::UNO_SET_THROW
);
383 uno::Reference
< XHelperInterface
> xParent( getActiveWorkbook(), uno::UNO_QUERY_THROW
);
384 uno::Reference
< excel::XWindow
> xWin( new ScVbaWindow( xParent
, mxContext
, xModel
, xController
) );
389 ScVbaApplication::getCutCopyMode() throw (uno::RuntimeException
)
391 //# FIXME TODO, implementation
393 result
<<= sal_False
;
398 ScVbaApplication::setCutCopyMode( const uno::Any
& /* _cutcopymode */ ) throw (uno::RuntimeException
)
400 //# FIXME TODO, implementation
404 ScVbaApplication::getStatusBar() throw (uno::RuntimeException
)
406 return uno::makeAny( !getDisplayStatusBar() );
410 ScVbaApplication::setStatusBar( const uno::Any
& _statusbar
) throw (uno::RuntimeException
)
413 sal_Bool bDefault
= false;
414 uno::Reference
< frame::XModel
> xModel( getCurrentDocument(), uno::UNO_QUERY_THROW
);
415 uno::Reference
< task::XStatusIndicatorSupplier
> xStatusIndicatorSupplier( xModel
->getCurrentController(), uno::UNO_QUERY_THROW
);
416 uno::Reference
< task::XStatusIndicator
> xStatusIndicator( xStatusIndicatorSupplier
->getStatusIndicator(), uno::UNO_QUERY_THROW
);
417 if( _statusbar
>>= sText
)
419 setDisplayStatusBar( sal_True
);
420 if ( !sText
.isEmpty() )
421 xStatusIndicator
->start( sText
, 100 );
423 xStatusIndicator
->end(); // restore normal state for empty text
425 else if( _statusbar
>>= bDefault
)
427 if( bDefault
== false )
429 xStatusIndicator
->end();
430 setDisplayStatusBar( sal_True
);
434 throw uno::RuntimeException("Invalid prarameter. It should be a string or False",
435 uno::Reference
< uno::XInterface
>() );
439 ScVbaApplication::getCalculation() throw (uno::RuntimeException
)
441 // TODO: in Excel, this is an application-wide setting
442 uno::Reference
<sheet::XCalculatable
> xCalc(getCurrentDocument(), uno::UNO_QUERY_THROW
);
443 if(xCalc
->isAutomaticCalculationEnabled())
444 return excel::XlCalculation::xlCalculationAutomatic
;
446 return excel::XlCalculation::xlCalculationManual
;
450 ScVbaApplication::setCalculation( ::sal_Int32 _calculation
) throw (uno::RuntimeException
)
452 // TODO: in Excel, this is an application-wide setting
453 uno::Reference
< sheet::XCalculatable
> xCalc(getCurrentDocument(), uno::UNO_QUERY_THROW
);
456 case excel::XlCalculation::xlCalculationManual
:
457 xCalc
->enableAutomaticCalculation(false);
459 case excel::XlCalculation::xlCalculationAutomatic
:
460 case excel::XlCalculation::xlCalculationSemiautomatic
:
461 xCalc
->enableAutomaticCalculation(sal_True
);
467 ScVbaApplication::Windows( const uno::Any
& aIndex
) throw (uno::RuntimeException
)
469 uno::Reference
< excel::XWindows
> xWindows( new ScVbaWindows( this, mxContext
) );
470 if ( aIndex
.getValueTypeClass() == uno::TypeClass_VOID
)
471 return uno::Any( xWindows
);
472 return uno::Any( xWindows
->Item( aIndex
, uno::Any() ) );
475 ScVbaApplication::wait( double time
) throw (uno::RuntimeException
)
477 StarBASIC
* pBasic
= SFX_APP()->GetBasic();
478 SbxArrayRef aArgs
= new SbxArray
;
479 SbxVariableRef aRef
= new SbxVariable
;
480 aRef
->PutDouble( time
);
481 aArgs
->Put( aRef
, 1 );
482 SbMethod
* pMeth
= (SbMethod
*)pBasic
->GetRtl()->Find( OUString("WaitUntil"), SbxCLASS_METHOD
);
486 pMeth
->SetParameters( aArgs
);
487 SbxVariableRef refTemp
= pMeth
;
488 // forces a broadcast
489 SbxVariableRef pNew
= new SbxMethod( *((SbxMethod
*)pMeth
));
494 ScVbaApplication::Range( const uno::Any
& Cell1
, const uno::Any
& Cell2
) throw (uno::RuntimeException
)
496 uno::Reference
< excel::XRange
> xVbRange
= ScVbaRange::ApplicationRange( mxContext
, Cell1
, Cell2
);
497 return uno::makeAny( xVbRange
);
501 ScVbaApplication::Names( const css::uno::Any
& aIndex
) throw ( uno::RuntimeException
)
503 uno::Reference
< frame::XModel
> xModel( getCurrentDocument(), uno::UNO_QUERY_THROW
);
504 uno::Reference
< beans::XPropertySet
> xPropertySet( xModel
, uno::UNO_QUERY_THROW
);
505 uno::Reference
< sheet::XNamedRanges
> xNamedRanges( xPropertySet
->getPropertyValue(
506 OUString( "NamedRanges" ) ), uno::UNO_QUERY_THROW
);
508 css::uno::Reference
< excel::XNames
> xNames ( new ScVbaNames( this , mxContext
, xNamedRanges
, xModel
) );
509 if ( aIndex
.getValueTypeClass() == uno::TypeClass_VOID
)
511 return uno::Any( xNames
);
513 return uno::Any( xNames
->Item( aIndex
, uno::Any() ) );
517 uno::Reference
< excel::XWorksheet
> SAL_CALL
518 ScVbaApplication::getActiveSheet() throw (uno::RuntimeException
)
520 uno::Reference
< excel::XWorksheet
> result
;
521 uno::Reference
< excel::XWorkbook
> xWorkbook( getActiveWorkbook(), uno::UNO_QUERY
);
522 if ( xWorkbook
.is() )
524 uno::Reference
< excel::XWorksheet
> xWorksheet(
525 xWorkbook
->getActiveSheet(), uno::UNO_QUERY
);
526 if ( xWorksheet
.is() )
534 // Fixme - check if this is reasonable/desired behavior
535 throw uno::RuntimeException("No activeSheet available",
536 uno::Reference
< uno::XInterface
>() );
542 /*******************************************************************************
544 * Reference Optional Variant. The destination. Can be a Range
545 * object, a string that contains a cell reference in R1C1-style notation,
546 * or a string that contains a Visual Basic procedure name.
547 * Scroll Optional Variant. True to scrol, False to not scroll through
548 * the window. The default is False.
549 * Parser is split to three parts, Range, R1C1 string and procedure name.
550 * by test excel, it seems Scroll no effect. ???
551 *******************************************************************************/
553 ScVbaApplication::GoTo( const uno::Any
& Reference
, const uno::Any
& Scroll
) throw (uno::RuntimeException
)
555 //test Scroll is a boolean
556 sal_Bool bScroll
= false;
557 //R1C1-style string or a string of procedure name.
559 if( Scroll
.hasValue() )
561 sal_Bool aScroll
= false;
562 if( Scroll
>>= aScroll
)
567 throw uno::RuntimeException("second parameter should be boolean",
568 uno::Reference
< uno::XInterface
>() );
572 if( Reference
>>= sRangeName
)
574 uno::Reference
< frame::XModel
> xModel( getCurrentDocument(), uno::UNO_QUERY_THROW
);
575 uno::Reference
< sheet::XSpreadsheetView
> xSpreadsheet(
576 xModel
->getCurrentController(), uno::UNO_QUERY_THROW
);
577 uno::Reference
< sheet::XSpreadsheet
> xDoc
= xSpreadsheet
->getActiveSheet();
579 ScTabViewShell
* pShell
= excel::getCurrentBestViewShell( mxContext
);
580 ScGridWindow
* gridWindow
= (ScGridWindow
*)pShell
->GetWindow();
583 uno::Reference
< excel::XRange
> xVbaSheetRange
= ScVbaRange::getRangeObjectForName(
584 mxContext
, sRangeName
, excel::getDocShell( xModel
), formula::FormulaGrammar::CONV_XL_R1C1
);
588 xVbaSheetRange
->Select();
589 uno::Reference
< excel::XWindow
> xWindow
= getActiveWindow();
590 ScSplitPos eWhich
= pShell
->GetViewData()->GetActivePart();
591 sal_Int32 nValueX
= pShell
->GetViewData()->GetPosX(WhichH(eWhich
));
592 sal_Int32 nValueY
= pShell
->GetViewData()->GetPosY(WhichV(eWhich
));
593 xWindow
->SmallScroll( uno::makeAny( (sal_Int16
)(xVbaSheetRange
->getRow() - 1) ),
594 uno::makeAny( (sal_Int16
)nValueY
),
595 uno::makeAny( (sal_Int16
)(xVbaSheetRange
->getColumn() - 1) ),
596 uno::makeAny( (sal_Int16
)nValueX
) );
597 gridWindow
->GrabFocus();
601 xVbaSheetRange
->Select();
602 gridWindow
->GrabFocus();
605 catch (const uno::RuntimeException
&)
607 //maybe this should be a procedure name
608 //TODO for procedure name
609 //browse::XBrowseNodeFactory is a singlton. OUString( "/singletons/com.sun.star.script.browse.theBrowseNodeFactory")
610 //and the createView( browse::BrowseNodeFactoryViewTypes::MACROSELECTOR ) to get a root browse::XBrowseNode.
611 //for query XInvocation interface.
612 //but how to directly get the XInvocation?
613 throw uno::RuntimeException("invalid reference for range name, it should be procedure name",
614 uno::Reference
< uno::XInterface
>() );
618 uno::Reference
< excel::XRange
> xRange
;
619 if( Reference
>>= xRange
)
621 uno::Reference
< excel::XRange
> xVbaRange( Reference
, uno::UNO_QUERY
);
622 ScTabViewShell
* pShell
= excel::getCurrentBestViewShell( mxContext
);
623 ScGridWindow
* gridWindow
= (ScGridWindow
*)pShell
->GetWindow();
624 if ( xVbaRange
.is() )
626 //TODO bScroll should be using, In this time, it doesenot have effection
630 uno::Reference
< excel::XWindow
> xWindow
= getActiveWindow();
631 ScSplitPos eWhich
= pShell
->GetViewData()->GetActivePart();
632 sal_Int32 nValueX
= pShell
->GetViewData()->GetPosX(WhichH(eWhich
));
633 sal_Int32 nValueY
= pShell
->GetViewData()->GetPosY(WhichV(eWhich
));
634 xWindow
->SmallScroll( uno::makeAny( (sal_Int16
)(xVbaRange
->getRow() - 1) ),
635 uno::makeAny( (sal_Int16
)nValueY
),
636 uno::makeAny( (sal_Int16
)(xVbaRange
->getColumn() - 1) ),
637 uno::makeAny( (sal_Int16
)nValueX
) );
638 gridWindow
->GrabFocus();
643 gridWindow
->GrabFocus();
648 throw uno::RuntimeException("invalid reference or name",
649 uno::Reference
< uno::XInterface
>() );
653 ScVbaApplication::getCursor() throw (uno::RuntimeException
)
655 sal_Int32 nPointerStyle
= getPointerStyle(getCurrentDocument());
657 switch( nPointerStyle
)
660 return excel::XlMousePointer::xlNorthwestArrow
;
662 return excel::XlMousePointer::xlDefault
;
664 return excel::XlMousePointer::xlWait
;
666 return excel::XlMousePointer::xlIBeam
;
668 return excel::XlMousePointer::xlDefault
;
673 ScVbaApplication::setCursor( sal_Int32 _cursor
) throw (uno::RuntimeException
)
677 uno::Reference
< frame::XModel
> xModel( getCurrentDocument(), uno::UNO_QUERY_THROW
);
680 case excel::XlMousePointer::xlNorthwestArrow
:
682 const Pointer
& rPointer( POINTER_ARROW
);
683 setCursorHelper( xModel
, rPointer
, false );
686 case excel::XlMousePointer::xlWait
:
687 case excel::XlMousePointer::xlIBeam
:
689 const Pointer
& rPointer( static_cast< PointerStyle
>( _cursor
) );
690 //It will set the edit window, toobar and statusbar's mouse pointer.
691 setCursorHelper( xModel
, rPointer
, sal_True
);
694 case excel::XlMousePointer::xlDefault
:
696 const Pointer
& rPointer( POINTER_NULL
);
697 setCursorHelper( xModel
, rPointer
, false );
701 throw uno::RuntimeException("Unknown value for Cursor pointer", uno::Reference
< uno::XInterface
>() );
702 // TODO: isn't this a flaw in the API? It should be allowed to throw an
703 // IllegalArgumentException, or so
706 catch (const uno::Exception
&)
708 DBG_UNHANDLED_EXCEPTION();
712 // #TODO perhaps we should switch the return type depending of the filter
713 // type, e.g. return Calc for Calc and Excel if its an imported doc
715 ScVbaApplication::getName() throw (uno::RuntimeException
)
717 static OUString
appName("Microsoft Excel" );
721 // #TODO #FIXME get/setDisplayAlerts are just stub impl
722 // here just the status of the switch is set
723 // the function that throws an error message needs to
724 // evaluate this switch in order to know whether it has to disable the
725 // error message thrown by OpenOffice
728 ScVbaApplication::setDisplayAlerts(sal_Bool displayAlerts
) throw (uno::RuntimeException
)
730 mrAppSettings
.mbDisplayAlerts
= displayAlerts
;
734 ScVbaApplication::getDisplayAlerts() throw (uno::RuntimeException
)
736 return mrAppSettings
.mbDisplayAlerts
;
740 ScVbaApplication::setEnableEvents(sal_Bool bEnable
) throw (uno::RuntimeException
)
742 mrAppSettings
.mbEnableEvents
= bEnable
;
746 ScVbaApplication::getEnableEvents() throw (uno::RuntimeException
)
748 return mrAppSettings
.mbEnableEvents
;
752 ScVbaApplication::setEnableCancelKey(sal_Bool bEnable
) throw (uno::RuntimeException
)
754 // Stub, does nothing
755 mrAppSettings
.mbEnableCancelKey
= bEnable
;
759 ScVbaApplication::getEnableCancelKey() throw (uno::RuntimeException
)
761 return mrAppSettings
.mbEnableCancelKey
;
765 ScVbaApplication::getDisplayFullScreen() throw (uno::RuntimeException
)
767 SfxViewShell
* pShell
= excel::getCurrentBestViewShell( mxContext
);
769 return ScViewUtil::IsFullScreen( *pShell
);
774 ScVbaApplication::setDisplayFullScreen( sal_Bool bSet
) throw (uno::RuntimeException
)
776 // #FIXME calling ScViewUtil::SetFullScreen( *pShell, bSet );
777 // directly results in a strange crash, using dispatch instead
778 if ( bSet
!= getDisplayFullScreen() )
779 dispatchRequests( getCurrentDocument(), OUString(".uno:FullScreen") );
783 ScVbaApplication::getDisplayScrollBars() throw (uno::RuntimeException
)
785 ScTabViewShell
* pShell
= excel::getCurrentBestViewShell( mxContext
);
788 return ( pShell
->GetViewData()->IsHScrollMode() && pShell
->GetViewData()->IsVScrollMode() );
794 ScVbaApplication::setDisplayScrollBars( sal_Bool bSet
) throw (uno::RuntimeException
)
796 // use uno here as it does all he repainting etc. magic
797 uno::Reference
< sheet::XSpreadsheetView
> xView( getCurrentDocument()->getCurrentController(), uno::UNO_QUERY_THROW
);
798 uno::Reference
< beans::XPropertySet
> xProps( xView
, uno::UNO_QUERY
);
799 xProps
->setPropertyValue("HasVerticalScrollBar", uno::makeAny( bSet
) );
800 xProps
->setPropertyValue("HasHorizontalScrollBar", uno::makeAny( bSet
) );
804 ScVbaApplication::getDisplayExcel4Menus() throw (css::uno::RuntimeException
)
806 return mrAppSettings
.mbExcel4Menus
;
810 ScVbaApplication::setDisplayExcel4Menus( sal_Bool bSet
) throw (css::uno::RuntimeException
)
812 mrAppSettings
.mbExcel4Menus
= bSet
;
816 ScVbaApplication::getDisplayNoteIndicator() throw (css::uno::RuntimeException
)
818 return mrAppSettings
.mbDisplayNoteIndicator
;
822 ScVbaApplication::setDisplayNoteIndicator( sal_Bool bSet
) throw (css::uno::RuntimeException
)
824 mrAppSettings
.mbDisplayNoteIndicator
= bSet
;
828 ScVbaApplication::getShowWindowsInTaskbar() throw (css::uno::RuntimeException
)
830 return mrAppSettings
.mbShowWindowsInTaskbar
;
834 ScVbaApplication::setShowWindowsInTaskbar( sal_Bool bSet
) throw (css::uno::RuntimeException
)
836 mrAppSettings
.mbShowWindowsInTaskbar
= bSet
;
840 ScVbaApplication::getIteration() throw (css::uno::RuntimeException
)
842 return SC_MOD()->GetDocOptions().IsIter();
846 ScVbaApplication::setIteration( sal_Bool bSet
) throw (css::uno::RuntimeException
)
848 uno::Reference
< lang::XMultiComponentFactory
> xSMgr(
849 mxContext
->getServiceManager(), uno::UNO_QUERY_THROW
);
851 uno::Reference
< frame::XDesktop
> xDesktop
852 (xSMgr
->createInstanceWithContext( "com.sun.star.frame.Desktop" , mxContext
), uno::UNO_QUERY_THROW
);
853 uno::Reference
< container::XEnumeration
> xComponents
= xDesktop
->getComponents()->createEnumeration();
854 while ( xComponents
->hasMoreElements() )
856 uno::Reference
< lang::XServiceInfo
> xServiceInfo( xComponents
->nextElement(), uno::UNO_QUERY
);
857 if ( xServiceInfo
.is() && xServiceInfo
->supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) )
859 uno::Reference
< beans::XPropertySet
> xProps( xServiceInfo
, uno::UNO_QUERY
);
861 xProps
->setPropertyValue( SC_UNO_ITERENABLED
, uno::Any( bSet
) );
864 ScDocOptions
aOpts( SC_MOD()->GetDocOptions() );
865 aOpts
.SetIter( bSet
);
866 SC_MOD()->SetDocOptions( aOpts
);
870 ScVbaApplication::Calculate() throw( script::BasicErrorException
, uno::RuntimeException
)
872 uno::Reference
< frame::XModel
> xModel( getCurrentDocument(), uno::UNO_QUERY_THROW
);
873 uno::Reference
< sheet::XCalculatable
> xCalculatable( getCurrentDocument(), uno::UNO_QUERY_THROW
);
874 xCalculatable
->calculateAll();
877 static uno::Reference
< util::XPathSettings
> lcl_getPathSettingsService( const uno::Reference
< uno::XComponentContext
>& xContext
) throw ( uno::RuntimeException
)
879 static uno::Reference
< util::XPathSettings
> xPathSettings
;
880 if ( !xPathSettings
.is() )
882 xPathSettings
.set( util::PathSettings::create( xContext
) );
884 return xPathSettings
;
886 OUString
ScVbaApplication::getOfficePath( const OUString
& _sPathType
) throw ( uno::RuntimeException
)
889 uno::Reference
< util::XPathSettings
> xProps
= lcl_getPathSettingsService( mxContext
);
893 xProps
->getPropertyValue( _sPathType
) >>= sUrl
;
895 // if it's a list of paths then use the last one
896 sal_Int32 nIndex
= sUrl
.lastIndexOf( ';' ) ;
898 sUrl
= sUrl
.copy( nIndex
+ 1 );
899 ::osl::File::getSystemPathFromFileURL( sUrl
, sRetPath
);
901 catch (const uno::Exception
&)
903 DebugHelper::exception(SbERR_METHOD_FAILED
, OUString());
909 ScVbaApplication::setDefaultFilePath( const OUString
& DefaultFilePath
) throw (uno::RuntimeException
)
911 uno::Reference
< util::XPathSettings
> xProps
= lcl_getPathSettingsService( mxContext
);
913 osl::FileBase::getFileURLFromSystemPath( DefaultFilePath
, aURL
);
914 xProps
->setWork( aURL
);
918 ScVbaApplication::getDefaultFilePath() throw (uno::RuntimeException
)
920 return getOfficePath( OUString("Work"));
924 ScVbaApplication::getLibraryPath() throw (uno::RuntimeException
)
926 return getOfficePath( OUString("Basic"));
930 ScVbaApplication::getTemplatesPath() throw (uno::RuntimeException
)
932 return getOfficePath( OUString("Template"));
936 ScVbaApplication::getPathSeparator() throw (uno::RuntimeException
)
938 return OUString( (sal_Unicode
) SAL_PATHDELIMITER
);
941 // ----------------------------------------------------------------------------
942 // Helpers for Intersect and Union
946 typedef ::std::list
< ScRange
> ListOfScRange
;
948 /** Appends all ranges of a VBA Range object in the passed Any to the list of ranges. */
949 void lclAddToListOfScRange( ListOfScRange
& rList
, const uno::Any
& rArg
)
950 throw (script::BasicErrorException
, uno::RuntimeException
)
952 if( rArg
.hasValue() )
954 uno::Reference
< excel::XRange
> xRange( rArg
, uno::UNO_QUERY_THROW
);
955 uno::Reference
< XCollection
> xCol( xRange
->Areas( uno::Any() ), uno::UNO_QUERY_THROW
);
956 for( sal_Int32 nIdx
= 1, nCount
= xCol
->getCount(); nIdx
<= nCount
; ++nIdx
)
958 uno::Reference
< excel::XRange
> xAreaRange( xCol
->Item( uno::Any( nIdx
), uno::Any() ), uno::UNO_QUERY_THROW
);
959 uno::Reference
< sheet::XCellRangeAddressable
> xAddressable( xAreaRange
->getCellRange(), uno::UNO_QUERY_THROW
);
961 ScUnoConversion::FillScRange( aScRange
, xAddressable
->getRangeAddress() );
962 rList
.push_back( aScRange
);
967 /** Returns true, if the passed ranges can be expressed by a single range. The
968 new range will be contained in r1 then, the range r2 can be removed. */
969 bool lclTryJoin( ScRange
& r1
, const ScRange
& r2
)
971 // 1) r2 is completely inside r1
975 // 2) r1 is completely inside r2
982 SCCOL n1L
= r1
.aStart
.Col();
983 SCCOL n1R
= r1
.aEnd
.Col();
984 SCROW n1T
= r1
.aStart
.Row();
985 SCROW n1B
= r1
.aEnd
.Row();
986 SCCOL n2L
= r2
.aStart
.Col();
987 SCCOL n2R
= r2
.aEnd
.Col();
988 SCROW n2T
= r2
.aStart
.Row();
989 SCROW n2B
= r2
.aEnd
.Row();
991 // 3) r1 and r2 have equal upper and lower border
992 if( (n1T
== n2T
) && (n1B
== n2B
) )
994 // check that r1 overlaps or touches r2
995 if( ((n1L
< n2L
) && (n2L
- 1 <= n1R
)) || ((n2L
< n1L
) && (n1L
- 1 <= n2R
)) )
997 r1
.aStart
.SetCol( ::std::min( n1L
, n2L
) );
998 r1
.aEnd
.SetCol( ::std::max( n1R
, n2R
) );
1004 // 4) r1 and r2 have equal left and right border
1005 if( (n1L
== n2L
) && (n1R
== n2R
) )
1007 // check that r1 overlaps or touches r2
1008 if( ((n1T
< n2T
) && (n2T
+ 1 <= n1B
)) || ((n2T
< n1T
) && (n1T
+ 1 <= n2B
)) )
1010 r1
.aStart
.SetRow( ::std::min( n1T
, n2T
) );
1011 r1
.aEnd
.SetRow( ::std::max( n1B
, n2B
) );
1017 // 5) cannot join these ranges
1021 /** Strips out ranges that are contained by other ranges, joins ranges that can be joined
1022 together (aligned borders, e.g. A4:D10 and B4:E10 would be combined to A4:E10. */
1023 void lclJoinRanges( ListOfScRange
& rList
)
1025 ListOfScRange::iterator aOuterIt
= rList
.begin();
1026 while( aOuterIt
!= rList
.end() )
1028 bool bAnyErased
= false; // true = any range erased from rList
1029 ListOfScRange::iterator aInnerIt
= rList
.begin();
1030 while( aInnerIt
!= rList
.end() )
1032 bool bInnerErased
= false; // true = aInnerIt erased from rList
1033 // do not compare a range with itself
1034 if( (aOuterIt
!= aInnerIt
) && lclTryJoin( *aOuterIt
, *aInnerIt
) )
1036 // aOuterIt points to joined range, aInnerIt will be removed
1037 aInnerIt
= rList
.erase( aInnerIt
);
1038 bInnerErased
= bAnyErased
= true;
1040 /* If aInnerIt has been erased from rList, it already points to
1041 the next element (return value of list::erase()). */
1045 // if any range has been erased, repeat outer loop with the same range
1051 /** Intersects the passed list with all ranges of a VBA Range object in the passed Any. */
1052 void lclIntersectRanges( ListOfScRange
& rList
, const uno::Any
& rArg
)
1053 throw (script::BasicErrorException
, uno::RuntimeException
)
1055 // extract the ranges from the passed argument, will throw on invalid data
1056 ListOfScRange aList2
;
1057 lclAddToListOfScRange( aList2
, rArg
);
1058 // do nothing, if the passed list is already empty
1059 if( !rList
.empty() && !aList2
.empty() )
1061 // save original list in a local
1062 ListOfScRange aList1
;
1063 aList1
.swap( rList
);
1064 // join ranges from passed argument
1065 lclJoinRanges( aList2
);
1066 // calculate intersection of the ranges in both lists
1067 for( ListOfScRange::const_iterator aOuterIt
= aList1
.begin(), aOuterEnd
= aList1
.end(); aOuterIt
!= aOuterEnd
; ++aOuterIt
)
1069 for( ListOfScRange::const_iterator aInnerIt
= aList2
.begin(), aInnerEnd
= aList2
.end(); aInnerIt
!= aInnerEnd
; ++aInnerIt
)
1071 if( aOuterIt
->Intersects( *aInnerIt
) )
1073 ScRange
aIsectRange(
1074 std::max( aOuterIt
->aStart
.Col(), aInnerIt
->aStart
.Col() ),
1075 std::max( aOuterIt
->aStart
.Row(), aInnerIt
->aStart
.Row() ),
1076 std::max( aOuterIt
->aStart
.Tab(), aInnerIt
->aStart
.Tab() ),
1077 std::min( aOuterIt
->aEnd
.Col(), aInnerIt
->aEnd
.Col() ),
1078 std::min( aOuterIt
->aEnd
.Row(), aInnerIt
->aEnd
.Row() ),
1079 std::min( aOuterIt
->aEnd
.Tab(), aInnerIt
->aEnd
.Tab() ) );
1080 rList
.push_back( aIsectRange
);
1084 // again, join the result ranges
1085 lclJoinRanges( rList
);
1089 /** Creates a VBA Range object from the passed list of ranges. */
1090 uno::Reference
< excel::XRange
> lclCreateVbaRange(
1091 const uno::Reference
< uno::XComponentContext
>& rxContext
,
1092 const uno::Reference
< frame::XModel
>& rxModel
,
1093 const ListOfScRange
& rList
) throw (uno::RuntimeException
)
1095 ScDocShell
* pDocShell
= excel::getDocShell( rxModel
);
1096 if( !pDocShell
) throw uno::RuntimeException();
1098 ScRangeList aCellRanges
;
1099 for( ListOfScRange::const_iterator aIt
= rList
.begin(), aEnd
= rList
.end(); aIt
!= aEnd
; ++aIt
)
1100 aCellRanges
.Append( *aIt
);
1102 if( aCellRanges
.size() == 1 )
1104 uno::Reference
< table::XCellRange
> xRange( new ScCellRangeObj( pDocShell
, *aCellRanges
.front() ) );
1105 return new ScVbaRange( excel::getUnoSheetModuleObj( xRange
), rxContext
, xRange
);
1107 if( aCellRanges
.size() > 1 )
1109 uno::Reference
< sheet::XSheetCellRangeContainer
> xRanges( new ScCellRangesObj( pDocShell
, aCellRanges
) );
1110 return new ScVbaRange( excel::getUnoSheetModuleObj( xRanges
), rxContext
, xRanges
);
1117 // ----------------------------------------------------------------------------
1119 uno::Reference
< excel::XRange
> SAL_CALL
ScVbaApplication::Intersect(
1120 const uno::Reference
< excel::XRange
>& rArg1
, const uno::Reference
< excel::XRange
>& rArg2
,
1121 const uno::Any
& rArg3
, const uno::Any
& rArg4
, const uno::Any
& rArg5
, const uno::Any
& rArg6
,
1122 const uno::Any
& rArg7
, const uno::Any
& rArg8
, const uno::Any
& rArg9
, const uno::Any
& rArg10
,
1123 const uno::Any
& rArg11
, const uno::Any
& rArg12
, const uno::Any
& rArg13
, const uno::Any
& rArg14
,
1124 const uno::Any
& rArg15
, const uno::Any
& rArg16
, const uno::Any
& rArg17
, const uno::Any
& rArg18
,
1125 const uno::Any
& rArg19
, const uno::Any
& rArg20
, const uno::Any
& rArg21
, const uno::Any
& rArg22
,
1126 const uno::Any
& rArg23
, const uno::Any
& rArg24
, const uno::Any
& rArg25
, const uno::Any
& rArg26
,
1127 const uno::Any
& rArg27
, const uno::Any
& rArg28
, const uno::Any
& rArg29
, const uno::Any
& rArg30
)
1128 throw (script::BasicErrorException
, uno::RuntimeException
)
1130 if( !rArg1
.is() || !rArg2
.is() )
1131 DebugHelper::exception( SbERR_BAD_PARAMETER
, OUString() );
1133 // initialize the result list with 1st parameter, join its ranges together
1134 ListOfScRange aList
;
1135 lclAddToListOfScRange( aList
, uno::Any( rArg1
) );
1136 lclJoinRanges( aList
);
1138 // process all other parameters, this updates the list with intersection
1139 lclIntersectRanges( aList
, uno::Any( rArg2
) );
1140 lclIntersectRanges( aList
, rArg3
);
1141 lclIntersectRanges( aList
, rArg4
);
1142 lclIntersectRanges( aList
, rArg5
);
1143 lclIntersectRanges( aList
, rArg6
);
1144 lclIntersectRanges( aList
, rArg7
);
1145 lclIntersectRanges( aList
, rArg8
);
1146 lclIntersectRanges( aList
, rArg9
);
1147 lclIntersectRanges( aList
, rArg10
);
1148 lclIntersectRanges( aList
, rArg11
);
1149 lclIntersectRanges( aList
, rArg12
);
1150 lclIntersectRanges( aList
, rArg13
);
1151 lclIntersectRanges( aList
, rArg14
);
1152 lclIntersectRanges( aList
, rArg15
);
1153 lclIntersectRanges( aList
, rArg16
);
1154 lclIntersectRanges( aList
, rArg17
);
1155 lclIntersectRanges( aList
, rArg18
);
1156 lclIntersectRanges( aList
, rArg19
);
1157 lclIntersectRanges( aList
, rArg20
);
1158 lclIntersectRanges( aList
, rArg21
);
1159 lclIntersectRanges( aList
, rArg22
);
1160 lclIntersectRanges( aList
, rArg23
);
1161 lclIntersectRanges( aList
, rArg24
);
1162 lclIntersectRanges( aList
, rArg25
);
1163 lclIntersectRanges( aList
, rArg26
);
1164 lclIntersectRanges( aList
, rArg27
);
1165 lclIntersectRanges( aList
, rArg28
);
1166 lclIntersectRanges( aList
, rArg29
);
1167 lclIntersectRanges( aList
, rArg30
);
1169 // create the VBA Range object
1170 return lclCreateVbaRange( mxContext
, getCurrentDocument(), aList
);
1173 uno::Reference
< excel::XRange
> SAL_CALL
ScVbaApplication::Union(
1174 const uno::Reference
< excel::XRange
>& rArg1
, const uno::Reference
< excel::XRange
>& rArg2
,
1175 const uno::Any
& rArg3
, const uno::Any
& rArg4
, const uno::Any
& rArg5
, const uno::Any
& rArg6
,
1176 const uno::Any
& rArg7
, const uno::Any
& rArg8
, const uno::Any
& rArg9
, const uno::Any
& rArg10
,
1177 const uno::Any
& rArg11
, const uno::Any
& rArg12
, const uno::Any
& rArg13
, const uno::Any
& rArg14
,
1178 const uno::Any
& rArg15
, const uno::Any
& rArg16
, const uno::Any
& rArg17
, const uno::Any
& rArg18
,
1179 const uno::Any
& rArg19
, const uno::Any
& rArg20
, const uno::Any
& rArg21
, const uno::Any
& rArg22
,
1180 const uno::Any
& rArg23
, const uno::Any
& rArg24
, const uno::Any
& rArg25
, const uno::Any
& rArg26
,
1181 const uno::Any
& rArg27
, const uno::Any
& rArg28
, const uno::Any
& rArg29
, const uno::Any
& rArg30
)
1182 throw (script::BasicErrorException
, uno::RuntimeException
)
1184 if( !rArg1
.is() || !rArg2
.is() )
1185 DebugHelper::exception( SbERR_BAD_PARAMETER
, OUString() );
1187 ListOfScRange aList
;
1188 lclAddToListOfScRange( aList
, uno::Any( rArg1
) );
1189 lclAddToListOfScRange( aList
, uno::Any( rArg2
) );
1190 lclAddToListOfScRange( aList
, rArg3
);
1191 lclAddToListOfScRange( aList
, rArg4
);
1192 lclAddToListOfScRange( aList
, rArg5
);
1193 lclAddToListOfScRange( aList
, rArg6
);
1194 lclAddToListOfScRange( aList
, rArg7
);
1195 lclAddToListOfScRange( aList
, rArg8
);
1196 lclAddToListOfScRange( aList
, rArg9
);
1197 lclAddToListOfScRange( aList
, rArg10
);
1198 lclAddToListOfScRange( aList
, rArg11
);
1199 lclAddToListOfScRange( aList
, rArg12
);
1200 lclAddToListOfScRange( aList
, rArg13
);
1201 lclAddToListOfScRange( aList
, rArg14
);
1202 lclAddToListOfScRange( aList
, rArg15
);
1203 lclAddToListOfScRange( aList
, rArg16
);
1204 lclAddToListOfScRange( aList
, rArg17
);
1205 lclAddToListOfScRange( aList
, rArg18
);
1206 lclAddToListOfScRange( aList
, rArg19
);
1207 lclAddToListOfScRange( aList
, rArg20
);
1208 lclAddToListOfScRange( aList
, rArg21
);
1209 lclAddToListOfScRange( aList
, rArg22
);
1210 lclAddToListOfScRange( aList
, rArg23
);
1211 lclAddToListOfScRange( aList
, rArg24
);
1212 lclAddToListOfScRange( aList
, rArg25
);
1213 lclAddToListOfScRange( aList
, rArg26
);
1214 lclAddToListOfScRange( aList
, rArg27
);
1215 lclAddToListOfScRange( aList
, rArg28
);
1216 lclAddToListOfScRange( aList
, rArg29
);
1217 lclAddToListOfScRange( aList
, rArg30
);
1219 // simply join together all ranges as much as possible, strip out covered ranges etc.
1220 lclJoinRanges( aList
);
1222 // create the VBA Range object
1223 return lclCreateVbaRange( mxContext
, getCurrentDocument(), aList
);
1227 ScVbaApplication::InchesToPoints( double Inches
) throw (uno::RuntimeException
)
1229 double result
= ( Inches
* 72.0 );
1234 ScVbaApplication::Volatile( const uno::Any
& aVolatile
) throw ( uno::RuntimeException
)
1236 sal_Bool bVolatile
= sal_True
;
1237 aVolatile
>>= bVolatile
;
1238 SbMethod
* pMeth
= StarBASIC::GetActiveMethod();
1241 OSL_TRACE("ScVbaApplication::Volatile() In method ->%s<-", OUStringToOString( pMeth
->GetName(), RTL_TEXTENCODING_UTF8
).getStr() );
1242 uno::Reference
< frame::XModel
> xModel( getCurrentDocument() );
1243 ScDocument
* pDoc
= excel::getDocShell( xModel
)->GetDocument();
1244 pDoc
->GetMacroManager()->SetUserFuncVolatile( pMeth
->GetName(), bVolatile
);
1247 // this is bound to break when loading the document
1252 ScVbaApplication::getDisplayFormulaBar() throw ( css::uno::RuntimeException
)
1254 sal_Bool bRes
= false;
1255 ScTabViewShell
* pViewShell
= excel::getCurrentBestViewShell( mxContext
);
1258 SfxBoolItem
sfxFormBar( FID_TOGGLEINPUTLINE
);
1259 SfxAllItemSet
reqList( SFX_APP()->GetPool() );
1260 reqList
.Put( sfxFormBar
);
1262 pViewShell
->GetState( reqList
);
1263 const SfxPoolItem
*pItem
=0;
1264 if ( reqList
.GetItemState( FID_TOGGLEINPUTLINE
, false, &pItem
) == SFX_ITEM_SET
)
1265 bRes
= ((SfxBoolItem
*)pItem
)->GetValue();
1271 ScVbaApplication::setDisplayFormulaBar( ::sal_Bool _displayformulabar
) throw ( css::uno::RuntimeException
)
1273 ScTabViewShell
* pViewShell
= excel::getCurrentBestViewShell( mxContext
);
1274 if ( pViewShell
&& ( _displayformulabar
!= getDisplayFormulaBar() ) )
1276 SfxBoolItem
sfxFormBar( FID_TOGGLEINPUTLINE
, _displayformulabar
);
1277 SfxAllItemSet
reqList( SFX_APP()->GetPool() );
1278 SfxRequest
aReq( FID_TOGGLEINPUTLINE
, 0, reqList
);
1279 pViewShell
->Execute( aReq
);
1284 ScVbaApplication::Caller( const uno::Any
& /*aIndex*/ ) throw ( uno::RuntimeException
)
1286 StarBASIC
* pBasic
= SFX_APP()->GetBasic();
1287 SbMethod
* pMeth
= (SbMethod
*)pBasic
->GetRtl()->Find( OUString("FuncCaller"), SbxCLASS_METHOD
);
1291 SbxVariableRef refTemp
= pMeth
;
1292 // forces a broadcast
1293 SbxVariableRef pNew
= new SbxMethod( *((SbxMethod
*)pMeth
));
1294 OSL_TRACE("pNew has type %d and string value %s", pNew
->GetType(), OUStringToOString( pNew
->GetOUString(), RTL_TEXTENCODING_UTF8
).getStr() );
1295 aRet
= sbxToUnoValue( pNew
);
1300 uno::Any SAL_CALL
ScVbaApplication::GetOpenFilename(
1301 const uno::Any
& rFileFilter
, const uno::Any
& rFilterIndex
, const uno::Any
& rTitle
,
1302 const uno::Any
& rButtonText
, const uno::Any
& rMultiSelect
) throw (uno::RuntimeException
)
1304 uno::Sequence
< uno::Any
> aArgs( 6 );
1305 aArgs
[ 0 ] <<= getThisExcelDoc( mxContext
);
1306 aArgs
[ 1 ] = rFileFilter
;
1307 aArgs
[ 2 ] = rFilterIndex
;
1308 aArgs
[ 3 ] = rTitle
;
1309 aArgs
[ 4 ] = rButtonText
;
1310 aArgs
[ 5 ] = rMultiSelect
;
1311 uno::Reference
< lang::XMultiComponentFactory
> xFactory( mxContext
->getServiceManager(), uno::UNO_SET_THROW
);
1312 uno::Reference
< XExecutableDialog
> xFilePicker( xFactory
->createInstanceWithArgumentsAndContext(
1313 OUString( "ooo.vba.OpenFilePicker" ), aArgs
, mxContext
), uno::UNO_QUERY_THROW
);
1314 return xFilePicker
->execute();
1317 uno::Any SAL_CALL
ScVbaApplication::GetSaveAsFilename(
1318 const uno::Any
& rInitialFileName
, const uno::Any
& rFileFilter
, const uno::Any
& rFilterIndex
,
1319 const uno::Any
& rTitle
, const uno::Any
& rButtonText
) throw (uno::RuntimeException
)
1321 uno::Sequence
< uno::Any
> aArgs( 6 );
1322 aArgs
[ 0 ] <<= getThisExcelDoc( mxContext
);
1323 aArgs
[ 1 ] = rInitialFileName
;
1324 aArgs
[ 2 ] = rFileFilter
;
1325 aArgs
[ 3 ] = rFilterIndex
;
1326 aArgs
[ 4 ] = rTitle
;
1327 aArgs
[ 5 ] = rButtonText
;
1328 uno::Reference
< lang::XMultiComponentFactory
> xFactory( mxContext
->getServiceManager(), uno::UNO_SET_THROW
);
1329 uno::Reference
< XExecutableDialog
> xFilePicker( xFactory
->createInstanceWithArgumentsAndContext(
1330 OUString( "ooo.vba.SaveAsFilePicker" ), aArgs
, mxContext
), uno::UNO_QUERY_THROW
);
1331 return xFilePicker
->execute();
1334 uno::Reference
< frame::XModel
>
1335 ScVbaApplication::getCurrentDocument() throw (css::uno::RuntimeException
)
1337 return getCurrentExcelDoc(mxContext
);
1341 ScVbaApplication::MenuBars( const uno::Any
& aIndex
) throw (uno::RuntimeException
)
1343 uno::Reference
< XCommandBars
> xCommandBars( CommandBars( uno::Any() ), uno::UNO_QUERY_THROW
);
1344 uno::Reference
< XCollection
> xMenuBars( new ScVbaMenuBars( this, mxContext
, xCommandBars
) );
1345 if ( aIndex
.hasValue() )
1347 return uno::Any ( xMenuBars
->Item( aIndex
, uno::Any() ) );
1350 return uno::Any( xMenuBars
);
1353 void SAL_CALL
ScVbaApplication::OnKey( const OUString
& Key
, const uno::Any
& Procedure
) throw (uno::RuntimeException
)
1357 // Perhaps we can catch some excel specific
1358 // related behaviour here
1359 VbaApplicationBase::OnKey( Key
, Procedure
);
1361 catch( container::NoSuchElementException
& )
1363 // #TODO special handling for unhandled
1368 void SAL_CALL
ScVbaApplication::Undo() throw (uno::RuntimeException
)
1370 uno::Reference
< frame::XModel
> xModel( getThisExcelDoc( mxContext
), uno::UNO_SET_THROW
);
1372 ScTabViewShell
* pViewShell
= excel::getBestViewShell( xModel
);
1374 dispatchExecute( pViewShell
, SID_UNDO
);
1378 ScVbaApplication::getServiceImplName()
1380 return OUString("ScVbaApplication");
1383 uno::Sequence
< OUString
>
1384 ScVbaApplication::getServiceNames()
1386 static uno::Sequence
< OUString
> aServiceNames
;
1387 if ( aServiceNames
.getLength() == 0 )
1389 aServiceNames
.realloc( 1 );
1390 aServiceNames
[ 0 ] = "ooo.vba.excel.Application";
1392 return aServiceNames
;
1395 namespace application
1397 namespace sdecl
= comphelper::service_decl
;
1398 sdecl::vba_service_class_
<ScVbaApplication
, sdecl::with_args
<false> > serviceImpl
;
1399 extern sdecl::ServiceDecl
const serviceDecl(
1402 "ooo.vba.excel.Application" );
1405 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */