1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include "vbahelper/vbaapplicationbase.hxx" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp> 31*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/container/XEnumeration.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/frame/XLayoutManager.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/container/XEnumerationAccess.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/document/XDocumentInfoSupplier.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/document/XDocumentProperties.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/document/XEmbeddedScripts.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/awt/XWindow2.hpp> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #include <hash_map> 45*cdf0e10cSrcweir #include <filter/msfilter/msvbahelper.hxx> 46*cdf0e10cSrcweir #include <tools/datetime.hxx> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #include <basic/sbx.hxx> 49*cdf0e10cSrcweir #include <basic/sbstar.hxx> 50*cdf0e10cSrcweir #include <basic/sbuno.hxx> 51*cdf0e10cSrcweir #include <basic/sbmeth.hxx> 52*cdf0e10cSrcweir #include <basic/sbmod.hxx> 53*cdf0e10cSrcweir #include <basic/vbahelper.hxx> 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir #include "vbacommandbars.hxx" 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir using namespace ::com::sun::star; 58*cdf0e10cSrcweir using namespace ::ooo::vba; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir #define OFFICEVERSION "11.0" 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir // ====VbaTimerInfo================================== 63*cdf0e10cSrcweir typedef ::std::pair< ::rtl::OUString, ::std::pair< double, double > > VbaTimerInfo; 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir // ====VbaTimer================================== 66*cdf0e10cSrcweir class VbaTimer 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir Timer m_aTimer; 69*cdf0e10cSrcweir VbaTimerInfo m_aTimerInfo; 70*cdf0e10cSrcweir ::rtl::Reference< VbaApplicationBase > m_xBase; 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir // the following declarations are here to prevent the usage of them 73*cdf0e10cSrcweir VbaTimer( const VbaTimer& ); 74*cdf0e10cSrcweir VbaTimer& operator=( const VbaTimer& ); 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir public: 77*cdf0e10cSrcweir VbaTimer() 78*cdf0e10cSrcweir {} 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir virtual ~VbaTimer() 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir m_aTimer.Stop(); 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir static double GetNow() 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir Date aDateNow; 88*cdf0e10cSrcweir Time aTimeNow; 89*cdf0e10cSrcweir Date aRefDate( 1,1,1900 ); 90*cdf0e10cSrcweir long nDiffDays = (long)(aDateNow - aRefDate); 91*cdf0e10cSrcweir nDiffDays += 2; // Anpassung VisualBasic: 1.Jan.1900 == 2 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir long nDiffSeconds = aTimeNow.GetHour() * 3600 + aTimeNow.GetMin() * 60 + aTimeNow.GetSec(); 94*cdf0e10cSrcweir return (double)nDiffDays + ((double)nDiffSeconds)/(double)(24*3600); 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir static sal_Int32 GetTimerMiliseconds( double nFrom, double nTo ) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir double nResult = nTo - nFrom; 100*cdf0e10cSrcweir if ( nResult > 0 ) 101*cdf0e10cSrcweir nResult *= 24*3600*1000; 102*cdf0e10cSrcweir else 103*cdf0e10cSrcweir nResult = 50; 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir return (sal_Int32) nResult; 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir void Start( const ::rtl::Reference< VbaApplicationBase > xBase, const ::rtl::OUString& aFunction, double nFrom, double nTo ) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir if ( !xBase.is() || !aFunction.getLength() ) 111*cdf0e10cSrcweir throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected arguments!" ) ), uno::Reference< uno::XInterface >() ); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir m_xBase = xBase; 114*cdf0e10cSrcweir m_aTimerInfo = VbaTimerInfo( aFunction, ::std::pair< double, double >( nFrom, nTo ) ); 115*cdf0e10cSrcweir m_aTimer.SetTimeoutHdl( LINK( this, VbaTimer, MacroCallHdl ) ); 116*cdf0e10cSrcweir m_aTimer.SetTimeout( GetTimerMiliseconds( GetNow(), nFrom ) ); 117*cdf0e10cSrcweir m_aTimer.Start(); 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir DECL_LINK( MacroCallHdl, void* ); 121*cdf0e10cSrcweir }; 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir IMPL_LINK( VbaTimer, MacroCallHdl, void*, EMPTYARG ) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir if ( m_aTimerInfo.second.second == 0 || GetNow() < m_aTimerInfo.second.second ) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir uno::Any aDummyArg; 128*cdf0e10cSrcweir try 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir m_xBase->Run( m_aTimerInfo.first, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg ); 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir catch( uno::Exception& ) 133*cdf0e10cSrcweir {} 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir // mast be the last call in the method since it deletes the timer 137*cdf0e10cSrcweir try 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir m_xBase->OnTime( uno::makeAny( m_aTimerInfo.second.first ), m_aTimerInfo.first, uno::makeAny( m_aTimerInfo.second.second ), uno::makeAny( sal_False ) ); 140*cdf0e10cSrcweir } catch( uno::Exception& ) 141*cdf0e10cSrcweir {} 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir return 0; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir // ====VbaTimerInfoHash================================== 147*cdf0e10cSrcweir struct VbaTimerInfoHash 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir size_t operator()( const VbaTimerInfo& rTimerInfo ) const 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir return (size_t)rTimerInfo.first.hashCode() 152*cdf0e10cSrcweir + (size_t)rtl_str_hashCode_WithLength( (char*)&rTimerInfo.second.first, sizeof( double ) ) 153*cdf0e10cSrcweir + (size_t)rtl_str_hashCode_WithLength( (char*)&rTimerInfo.second.second, sizeof( double ) ); 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir }; 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir // ====VbaTimerHashMap================================== 158*cdf0e10cSrcweir typedef ::std::hash_map< VbaTimerInfo, VbaTimer*, VbaTimerInfoHash, ::std::equal_to< VbaTimerInfo > > VbaTimerHashMap; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir // ====VbaApplicationBase_Impl================================== 161*cdf0e10cSrcweir struct VbaApplicationBase_Impl 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir VbaTimerHashMap m_aTimerHash; 164*cdf0e10cSrcweir sal_Bool mbVisible; 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir inline VbaApplicationBase_Impl() : mbVisible( sal_True ) {} 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir virtual ~VbaApplicationBase_Impl() 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir // remove the remaining timers 171*cdf0e10cSrcweir for ( VbaTimerHashMap::iterator aIter = m_aTimerHash.begin(); 172*cdf0e10cSrcweir aIter != m_aTimerHash.end(); 173*cdf0e10cSrcweir aIter++ ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir delete aIter->second; 176*cdf0e10cSrcweir aIter->second = NULL; 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir }; 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir // ====VbaApplicationBase================================== 182*cdf0e10cSrcweir VbaApplicationBase::VbaApplicationBase( const uno::Reference< uno::XComponentContext >& xContext ) 183*cdf0e10cSrcweir : ApplicationBase_BASE( uno::Reference< XHelperInterface >(), xContext ) 184*cdf0e10cSrcweir , m_pImpl( new VbaApplicationBase_Impl ) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir VbaApplicationBase::~VbaApplicationBase() 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir delete m_pImpl; 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir sal_Bool SAL_CALL 194*cdf0e10cSrcweir VbaApplicationBase::getScreenUpdating() throw (uno::RuntimeException) 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); 197*cdf0e10cSrcweir return !xModel->hasControllersLocked(); 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir void SAL_CALL 201*cdf0e10cSrcweir VbaApplicationBase::setScreenUpdating(sal_Bool bUpdate) throw (uno::RuntimeException) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); 204*cdf0e10cSrcweir // #163808# use helper from module "basic" to lock all documents of this application 205*cdf0e10cSrcweir ::basic::vba::lockControllersOfAllDocuments( xModel, !bUpdate ); 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir sal_Bool SAL_CALL 209*cdf0e10cSrcweir VbaApplicationBase::getDisplayStatusBar() throw (uno::RuntimeException) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); 212*cdf0e10cSrcweir uno::Reference< frame::XFrame > xFrame( xModel->getCurrentController()->getFrame(), uno::UNO_QUERY_THROW ); 213*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProps( xFrame, uno::UNO_QUERY_THROW ); 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir if( xProps.is() ){ 216*cdf0e10cSrcweir uno::Reference< frame::XLayoutManager > xLayoutManager( xProps->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LayoutManager")) ), uno::UNO_QUERY_THROW ); 217*cdf0e10cSrcweir rtl::OUString url(RTL_CONSTASCII_USTRINGPARAM( "private:resource/statusbar/statusbar" )); 218*cdf0e10cSrcweir if( xLayoutManager.is() && xLayoutManager->isElementVisible( url ) ){ 219*cdf0e10cSrcweir return sal_True; 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir return sal_False; 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir void SAL_CALL 226*cdf0e10cSrcweir VbaApplicationBase::setDisplayStatusBar(sal_Bool bDisplayStatusBar) throw (uno::RuntimeException) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); 229*cdf0e10cSrcweir uno::Reference< frame::XFrame > xFrame( xModel->getCurrentController()->getFrame(), uno::UNO_QUERY_THROW ); 230*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProps( xFrame, uno::UNO_QUERY_THROW ); 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir if( xProps.is() ){ 233*cdf0e10cSrcweir uno::Reference< frame::XLayoutManager > xLayoutManager( xProps->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LayoutManager")) ), uno::UNO_QUERY_THROW ); 234*cdf0e10cSrcweir rtl::OUString url(RTL_CONSTASCII_USTRINGPARAM( "private:resource/statusbar/statusbar" )); 235*cdf0e10cSrcweir if( xLayoutManager.is() ){ 236*cdf0e10cSrcweir if( bDisplayStatusBar && !xLayoutManager->isElementVisible( url ) ){ 237*cdf0e10cSrcweir if( !xLayoutManager->showElement( url ) ) 238*cdf0e10cSrcweir xLayoutManager->createElement( url ); 239*cdf0e10cSrcweir return; 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir else if( !bDisplayStatusBar && xLayoutManager->isElementVisible( url ) ){ 242*cdf0e10cSrcweir xLayoutManager->hideElement( url ); 243*cdf0e10cSrcweir return; 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir return; 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir ::sal_Bool SAL_CALL VbaApplicationBase::getInteractive() 251*cdf0e10cSrcweir throw (uno::RuntimeException) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); 254*cdf0e10cSrcweir uno::Reference< frame::XFrame > xFrame( xModel->getCurrentController()->getFrame(), uno::UNO_QUERY_THROW ); 255*cdf0e10cSrcweir uno::Reference< awt::XWindow2 > xWindow( xFrame->getContainerWindow(), uno::UNO_QUERY_THROW ); 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir return xWindow->isEnabled(); 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir void SAL_CALL VbaApplicationBase::setInteractive( ::sal_Bool bInteractive ) 261*cdf0e10cSrcweir throw (uno::RuntimeException) 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); 264*cdf0e10cSrcweir // #163808# use helper from module "basic" to enable/disable all container windows of all documents of this application 265*cdf0e10cSrcweir ::basic::vba::enableContainerWindowsOfAllDocuments( xModel, bInteractive ); 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir sal_Bool SAL_CALL VbaApplicationBase::getVisible() throw (uno::RuntimeException) 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir return m_pImpl->mbVisible; // dummy implementation 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir void SAL_CALL VbaApplicationBase::setVisible( sal_Bool bVisible ) throw (uno::RuntimeException) 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir m_pImpl->mbVisible = bVisible; // dummy implementation 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir uno::Any SAL_CALL 279*cdf0e10cSrcweir VbaApplicationBase::CommandBars( const uno::Any& aIndex ) throw (uno::RuntimeException) 280*cdf0e10cSrcweir { 281*cdf0e10cSrcweir uno::Reference< XCommandBars > xCommandBars( new ScVbaCommandBars( this, mxContext, uno::Reference< container::XIndexAccess >(), getCurrentDocument() ) ); 282*cdf0e10cSrcweir if( aIndex.hasValue() ) 283*cdf0e10cSrcweir return uno::makeAny( xCommandBars->Item( aIndex, uno::Any() ) ); 284*cdf0e10cSrcweir return uno::makeAny( xCommandBars ); 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir ::rtl::OUString SAL_CALL 288*cdf0e10cSrcweir VbaApplicationBase::getVersion() throw (uno::RuntimeException) 289*cdf0e10cSrcweir { 290*cdf0e10cSrcweir return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(OFFICEVERSION)); 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir void SAL_CALL VbaApplicationBase::Run( const ::rtl::OUString& MacroName, const uno::Any& varg1, const uno::Any& varg2, const uno::Any& varg3, const uno::Any& varg4, const uno::Any& varg5, const uno::Any& varg6, const uno::Any& varg7, const uno::Any& varg8, const uno::Any& varg9, const uno::Any& varg10, const uno::Any& varg11, const uno::Any& varg12, const uno::Any& varg13, const uno::Any& varg14, const uno::Any& varg15, const uno::Any& varg16, const uno::Any& varg17, const uno::Any& varg18, const uno::Any& varg19, const uno::Any& varg20, const uno::Any& varg21, const uno::Any& varg22, const uno::Any& varg23, const uno::Any& varg24, const uno::Any& varg25, const uno::Any& varg26, const uno::Any& varg27, const uno::Any& varg28, const uno::Any& varg29, const uno::Any& varg30 ) throw (uno::RuntimeException) 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir ::rtl::OUString aMacroName = MacroName.trim(); 296*cdf0e10cSrcweir if (0 == aMacroName.indexOf('!')) 297*cdf0e10cSrcweir aMacroName = aMacroName.copy(1).trim(); 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir uno::Reference< frame::XModel > xModel; 300*cdf0e10cSrcweir SbMethod* pMeth = StarBASIC::GetActiveMethod(); 301*cdf0e10cSrcweir if ( pMeth ) 302*cdf0e10cSrcweir { 303*cdf0e10cSrcweir SbModule* pMod = dynamic_cast< SbModule* >( pMeth->GetParent() ); 304*cdf0e10cSrcweir if ( pMod ) 305*cdf0e10cSrcweir xModel = StarBASIC::GetModelFromBasic( pMod ); 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir if ( !xModel.is() ) 309*cdf0e10cSrcweir xModel = getCurrentDocument(); 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir MacroResolvedInfo aMacroInfo = resolveVBAMacro( getSfxObjShell( xModel ), aMacroName ); 312*cdf0e10cSrcweir if( aMacroInfo.mbFound ) 313*cdf0e10cSrcweir { 314*cdf0e10cSrcweir // handle the arguments 315*cdf0e10cSrcweir const uno::Any* aArgsPtrArray[] = { &varg1, &varg2, &varg3, &varg4, &varg5, &varg6, &varg7, &varg8, &varg9, &varg10, &varg11, &varg12, &varg13, &varg14, &varg15, &varg16, &varg17, &varg18, &varg19, &varg20, &varg21, &varg22, &varg23, &varg24, &varg25, &varg26, &varg27, &varg28, &varg29, &varg30 }; 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir int nArg = sizeof( aArgsPtrArray ) / sizeof( aArgsPtrArray[0] ); 318*cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( nArg ); 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir const uno::Any** pArg = aArgsPtrArray; 321*cdf0e10cSrcweir const uno::Any** pArgEnd = ( aArgsPtrArray + nArg ); 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir sal_Int32 nLastArgWithValue = 0; 324*cdf0e10cSrcweir sal_Int32 nArgProcessed = 0; 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir for ( ; pArg != pArgEnd; ++pArg, ++nArgProcessed ) 327*cdf0e10cSrcweir { 328*cdf0e10cSrcweir aArgs[ nArgProcessed ] = **pArg; 329*cdf0e10cSrcweir if( (*pArg)->hasValue() ) 330*cdf0e10cSrcweir nLastArgWithValue = nArgProcessed; 331*cdf0e10cSrcweir } 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir // resize array to position of last param with value 334*cdf0e10cSrcweir aArgs.realloc( nArgProcessed + 1 ); 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir uno::Any aRet; 337*cdf0e10cSrcweir uno::Any aDummyCaller; 338*cdf0e10cSrcweir executeMacro( aMacroInfo.mpDocContext, aMacroInfo.msResolvedMacro, aArgs, aRet, aDummyCaller ); 339*cdf0e10cSrcweir } 340*cdf0e10cSrcweir else 341*cdf0e10cSrcweir { 342*cdf0e10cSrcweir throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("The macro doesn't exist") ), uno::Reference< uno::XInterface >() ); 343*cdf0e10cSrcweir } 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir void SAL_CALL VbaApplicationBase::OnTime( const uno::Any& aEarliestTime, const ::rtl::OUString& aFunction, const uno::Any& aLatestTime, const uno::Any& aSchedule ) 347*cdf0e10cSrcweir throw ( uno::RuntimeException ) 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir if ( !aFunction.getLength() ) 350*cdf0e10cSrcweir throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected function name!" ) ), uno::Reference< uno::XInterface >() ); 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir double nEarliestTime = 0; 353*cdf0e10cSrcweir double nLatestTime = 0; 354*cdf0e10cSrcweir if ( !( aEarliestTime >>= nEarliestTime ) 355*cdf0e10cSrcweir || ( aLatestTime.hasValue() && !( aLatestTime >>= nLatestTime ) ) ) 356*cdf0e10cSrcweir throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Only double is supported as time for now!" ) ), uno::Reference< uno::XInterface >() ); 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir sal_Bool bSetTimer = sal_True; 359*cdf0e10cSrcweir aSchedule >>= bSetTimer; 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir VbaTimerInfo aTimerIndex( aFunction, ::std::pair< double, double >( nEarliestTime, nLatestTime ) ); 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir VbaTimerHashMap::iterator aIter = m_pImpl->m_aTimerHash.find( aTimerIndex ); 364*cdf0e10cSrcweir if ( aIter != m_pImpl->m_aTimerHash.end() ) 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir delete aIter->second; 367*cdf0e10cSrcweir aIter->second = NULL; 368*cdf0e10cSrcweir m_pImpl->m_aTimerHash.erase( aIter ); 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir if ( bSetTimer ) 372*cdf0e10cSrcweir { 373*cdf0e10cSrcweir VbaTimer* pTimer = new VbaTimer; 374*cdf0e10cSrcweir m_pImpl->m_aTimerHash[ aTimerIndex ] = pTimer; 375*cdf0e10cSrcweir pTimer->Start( this, aFunction, nEarliestTime, nLatestTime ); 376*cdf0e10cSrcweir } 377*cdf0e10cSrcweir } 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir float SAL_CALL VbaApplicationBase::CentimetersToPoints( float _Centimeters ) throw (uno::RuntimeException) 380*cdf0e10cSrcweir { 381*cdf0e10cSrcweir // i cm = 28.35 points 382*cdf0e10cSrcweir static const float rate = 28.35f; 383*cdf0e10cSrcweir return ( _Centimeters * rate ); 384*cdf0e10cSrcweir } 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir uno::Any SAL_CALL VbaApplicationBase::getVBE() throw (uno::RuntimeException) 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir try // return empty object on error 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir // "VBE" object does not have a parent, but pass document model to be able to determine application type 391*cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 1 ); 392*cdf0e10cSrcweir aArgs[ 0 ] <<= getCurrentDocument(); 393*cdf0e10cSrcweir uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW ); 394*cdf0e10cSrcweir uno::Reference< uno::XInterface > xVBE = xServiceManager->createInstanceWithArgumentsAndContext( 395*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.vbide.VBE" ) ), aArgs, mxContext ); 396*cdf0e10cSrcweir return uno::Any( xVBE ); 397*cdf0e10cSrcweir } 398*cdf0e10cSrcweir catch( uno::Exception& ) 399*cdf0e10cSrcweir { 400*cdf0e10cSrcweir } 401*cdf0e10cSrcweir return uno::Any(); 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir rtl::OUString& 405*cdf0e10cSrcweir VbaApplicationBase::getServiceImplName() 406*cdf0e10cSrcweir { 407*cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("VbaApplicationBase") ); 408*cdf0e10cSrcweir return sImplName; 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir uno::Sequence<rtl::OUString> 412*cdf0e10cSrcweir VbaApplicationBase::getServiceNames() 413*cdf0e10cSrcweir { 414*cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 415*cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 416*cdf0e10cSrcweir { 417*cdf0e10cSrcweir aServiceNames.realloc( 1 ); 418*cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.VbaApplicationBase" ) ); 419*cdf0e10cSrcweir } 420*cdf0e10cSrcweir return aServiceNames; 421*cdf0e10cSrcweir } 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir void SAL_CALL VbaApplicationBase::Undo() 424*cdf0e10cSrcweir throw (uno::RuntimeException) 425*cdf0e10cSrcweir { 426*cdf0e10cSrcweir uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); 427*cdf0e10cSrcweir dispatchRequests( xModel, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:Undo" ) ) ); 428*cdf0e10cSrcweir } 429*cdf0e10cSrcweir 430*cdf0e10cSrcweir void VbaApplicationBase::Quit() throw (uno::RuntimeException) 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir // need to stop basic 433*cdf0e10cSrcweir SbMethod* pMeth = StarBASIC::GetActiveMethod(); 434*cdf0e10cSrcweir if ( pMeth ) 435*cdf0e10cSrcweir { 436*cdf0e10cSrcweir SbModule* pMod = dynamic_cast< SbModule* >( pMeth->GetParent() ); 437*cdf0e10cSrcweir if ( pMod ) 438*cdf0e10cSrcweir { 439*cdf0e10cSrcweir StarBASIC* pBasic = dynamic_cast< StarBASIC* >( pMod->GetParent() ); 440*cdf0e10cSrcweir if ( pBasic ) 441*cdf0e10cSrcweir pBasic->QuitAndExitApplication(); 442*cdf0e10cSrcweir } 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir } 445*cdf0e10cSrcweir 446