From c99b24c76c886ddaa93e290412c7674807c23405 Mon Sep 17 00:00:00 2001 From: Daniel Rentz Date: Mon, 23 Aug 2010 13:53:47 +0200 Subject: mib19: improved event handling: do not supreppress global events, when Application.EnableEvents symbol set to false --- sc/source/ui/vba/vbaeventshelper.cxx | 50 +++++++++++++++++------------------- sc/source/ui/vba/vbaeventshelper.hxx | 1 - 2 files changed, 24 insertions(+), 27 deletions(-) (limited to 'sc') diff --git a/sc/source/ui/vba/vbaeventshelper.cxx b/sc/source/ui/vba/vbaeventshelper.cxx index f19a2e57e549..99ccbeaaa822 100755 --- a/sc/source/ui/vba/vbaeventshelper.cxx +++ b/sc/source/ui/vba/vbaeventshelper.cxx @@ -441,35 +441,13 @@ void SAL_CALL ScVbaEventsHelper::disposing( const lang::EventObject& rSource ) t // protected ------------------------------------------------------------------ -bool ScVbaEventsHelper::implEventsEnabled() throw (uno::RuntimeException) +bool ScVbaEventsHelper::implPrepareEvent( EventQueue& rEventQueue, + const EventHandlerInfo& rInfo, const uno::Sequence< uno::Any >& rArgs ) throw (uno::RuntimeException) { // document and document shell are needed during event processing - if( !mpDocShell || !mpDoc ) + if( !mpShell || !mpDoc ) throw uno::RuntimeException(); - // get Application object and check if events are enabled (this is an Excel-only attribute) - uno::Reference< excel::XApplication > xApplication( mxApplication.get(), uno::UNO_QUERY ); - if( !xApplication.is() && mpShell ) - { - uno::Any aVBAGlobals; - mpShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aVBAGlobals ); - uno::Reference< XHelperInterface > xHelperInterface( aVBAGlobals, uno::UNO_QUERY ); - if( xHelperInterface.is() ) - { - xApplication.set( xHelperInterface->Application(), uno::UNO_QUERY ); - mxApplication = xApplication; - } - } - if( !xApplication.is() ) - throw uno::RuntimeException(); - - // return whether event processing is enabled - return xApplication->getEnableEvents(); -} - -bool ScVbaEventsHelper::implPrepareEvent( EventQueue& rEventQueue, - const EventHandlerInfo& rInfo, const uno::Sequence< uno::Any >& rArgs ) throw (uno::RuntimeException) -{ // framework and Calc fire a few events before 'opened', ignore them bool bExecuteEvent = mbOpened; @@ -492,12 +470,32 @@ bool ScVbaEventsHelper::implPrepareEvent( EventQueue& rEventQueue, break; } - // add workbook event associated to a sheet event if( bExecuteEvent ) { + // add workbook event associated to a sheet event bool bSheetEvent = false; if( (rInfo.maUserData >>= bSheetEvent) && bSheetEvent ) rEventQueue.push_back( EventQueueEntry( rInfo.mnEventId + USERDEFINED_START, rArgs ) ); + + /* For document events: get Application object and check if events are + enabled via EnableEvents symbol (this is an Excel-only attribute). + Check this again for every event, as the event handler may change + the state of the EnableEvents symbol. Global events such as + AUTO_OPEN and AUTO_CLOSE are always enabled. */ + if( rInfo.meType == EVENTHANDLER_DOCUMENT ) + { + // reference to application is held weakly, get application on first try + uno::Reference< excel::XApplication > xApplication( mxApplication.get(), uno::UNO_QUERY ); + if( !xApplication.is() ) + { + uno::Any aVBAGlobals; + mpShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aVBAGlobals ); + uno::Reference< XHelperInterface > xHelperInterface( aVBAGlobals, uno::UNO_QUERY_THROW ); + xApplication.set( xHelperInterface->Application(), uno::UNO_QUERY_THROW ); + mxApplication = xApplication; + } + bExecuteEvent = xApplication->getEnableEvents(); + } } return bExecuteEvent; diff --git a/sc/source/ui/vba/vbaeventshelper.hxx b/sc/source/ui/vba/vbaeventshelper.hxx index a77f5128b3e9..eaac96117d32 100755 --- a/sc/source/ui/vba/vbaeventshelper.hxx +++ b/sc/source/ui/vba/vbaeventshelper.hxx @@ -51,7 +51,6 @@ public: virtual void SAL_CALL disposing( const css::lang::EventObject& rSource ) throw (css::uno::RuntimeException); protected: - virtual bool implEventsEnabled() throw (css::uno::RuntimeException); virtual bool implPrepareEvent( EventQueue& rEventQueue, const EventHandlerInfo& rInfo, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::uno::RuntimeException); virtual css::uno::Sequence< css::uno::Any > implBuildArgumentList( const EventHandlerInfo& rInfo, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException); virtual void implPostProcessEvent( EventQueue& rEventQueue, const EventHandlerInfo& rInfo, bool bSuccess, bool bCancel ) throw (css::uno::RuntimeException); -- cgit