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