diff --git a/common/dialog_shim.cpp b/common/dialog_shim.cpp index de7283fd76..98adf34154 100644 --- a/common/dialog_shim.cpp +++ b/common/dialog_shim.cpp @@ -318,231 +318,6 @@ void DIALOG_SHIM::OnPaint( wxPaintEvent &event ) you want to use KIWAY_PLAYER::ShowModal() from a dialog event. */ - - -/* -/// wxEventLoopActivator but with a friend so it -/// has access to m_evtLoopOld, and it does not SetActive() as that is -/// done inside base class Run(). -class ELOOP_ACTIVATOR -{ - friend class EVENT_LOOP; - -public: - ELOOP_ACTIVATOR( WX_EVENT_LOOP* evtLoop ) - { - m_evtLoopOld = wxEventLoopBase::GetActive(); - // wxEventLoopBase::SetActive( evtLoop ); - } - - ~ELOOP_ACTIVATOR() - { - // restore the previously active event loop - wxEventLoopBase::SetActive( m_evtLoopOld ); - } - -private: - WX_EVENT_LOOP* m_evtLoopOld; -}; -*/ - - -class EVENT_LOOP : public WX_EVENT_LOOP -{ -public: - - EVENT_LOOP() - { - ; - } - - ~EVENT_LOOP() - { - } - -#if 0 // does not work any better than inherited wxGuiEventLoop functions: - - // sets the "should exit" flag and wakes up the loop so that it terminates - // soon - void ScheduleExit( int rc = 0 ) - { - wxCHECK_RET( IsInsideRun(), wxT("can't call ScheduleExit() if not running") ); - - m_exitcode = rc; - m_shouldExit = true; - - OnExit(); - - // all we have to do to exit from the loop is to (maybe) wake it up so that - // it can notice that Exit() had been called - // - // in particular, do *not* use here calls such as PostQuitMessage() (under - // MSW) which terminate the current event loop here because we're not sure - // that it is going to be processed by the correct event loop: it would be - // possible that another one is started and terminated by mistake if we do - // this - WakeUp(); - } - - int Run() - { - // event loops are not recursive, you need to create another loop! - //wxCHECK_MSG( !IsInsideRun(), -1, wxT("can't reenter a message loop") ); - - // ProcessIdle() and ProcessEvents() below may throw so the code here should - // be exception-safe, hence we must use local objects for all actions we - // should undo - wxEventLoopActivator activate(this); - - // We might be called again, after a previous call to ScheduleExit(), so - // reset this flag. - m_shouldExit = false; - - // Set this variable to true for the duration of this method. - setInsideRun( true ); - - struct SET_FALSE - { - EVENT_LOOP* m_loop; - SET_FALSE( EVENT_LOOP* aLoop ) : m_loop( aLoop ) {} - ~SET_FALSE() { m_loop->setInsideRun( false ); } - } t( this ); - - // Finally really run the loop. - return DoRun(); - } - - bool ProcessEvents() - { - // process pending wx events first as they correspond to low-level events - // which happened before, i.e. typically pending events were queued by a - // previous call to Dispatch() and if we didn't process them now the next - // call to it might enqueue them again (as happens with e.g. socket events - // which would be generated as long as there is input available on socket - // and this input is only removed from it when pending event handlers are - // executed) - if( wxTheApp ) - { - wxTheApp->ProcessPendingEvents(); - - // One of the pending event handlers could have decided to exit the - // loop so check for the flag before trying to dispatch more events - // (which could block indefinitely if no more are coming). - if( m_shouldExit ) - return false; - } - - return Dispatch(); - } - - - int DoRun() - { - // we must ensure that OnExit() is called even if an exception is thrown - // from inside ProcessEvents() but we must call it from Exit() in normal - // situations because it is supposed to be called synchronously, - // wxModalEventLoop depends on this (so we can't just use ON_BLOCK_EXIT or - // something similar here) - #if wxUSE_EXCEPTIONS - for( ; ; ) - { - try - { - #endif // wxUSE_EXCEPTIONS - - // this is the event loop itself - for( ; ; ) - { - // generate and process idle events for as long as we don't - // have anything else to do - while ( !m_shouldExit && !Pending() && ProcessIdle() ) - ; - - if ( m_shouldExit ) - break; - - // a message came or no more idle processing to do, dispatch - // all the pending events and call Dispatch() to wait for the - // next message - if ( !ProcessEvents() ) - { - // we got WM_QUIT - break; - } - } - - // Process the remaining queued messages, both at the level of the - // underlying toolkit level (Pending/Dispatch()) and wx level - // (Has/ProcessPendingEvents()). - // - // We do run the risk of never exiting this loop if pending event - // handlers endlessly generate new events but they shouldn't do - // this in a well-behaved program and we shouldn't just discard the - // events we already have, they might be important. - for( ; ; ) - { - bool hasMoreEvents = false; - if ( wxTheApp && wxTheApp->HasPendingEvents() ) - { - wxTheApp->ProcessPendingEvents(); - hasMoreEvents = true; - } - - if ( Pending() ) - { - Dispatch(); - hasMoreEvents = true; - } - - if ( !hasMoreEvents ) - break; - } - - #if wxUSE_EXCEPTIONS - // exit the outer loop as well - break; - } - catch ( ... ) - { - try - { - if ( !wxTheApp || !wxTheApp->OnExceptionInMainLoop() ) - { - OnExit(); - break; - } - //else: continue running the event loop - } - catch ( ... ) - { - // OnException() throwed, possibly rethrowing the same - // exception again: very good, but we still need OnExit() to - // be called - OnExit(); - throw; - } - } - } - #endif // wxUSE_EXCEPTIONS - - return m_exitcode; - } - -protected: - int m_exitcode; - - /* this only works if you add - friend class EVENT_LOOP - to EventLoopBase - */ - void setInsideRun( bool aValue ) - { - m_isInsideRun = aValue; - } -#endif -}; - - int DIALOG_SHIM::ShowQuasiModal() { // This is an exception safe way to zero a pointer before returning. @@ -585,7 +360,7 @@ int DIALOG_SHIM::ShowQuasiModal() m_qmodal_showing = true; - EVENT_LOOP event_loop; + WX_EVENT_LOOP event_loop; m_qmodal_loop = &event_loop; diff --git a/include/dialog_shim.h b/include/dialog_shim.h index 6fc811c382..455da1e612 100644 --- a/include/dialog_shim.h +++ b/include/dialog_shim.h @@ -32,7 +32,7 @@ class WDO_ENABLE_DISABLE; -class EVENT_LOOP; +class WX_EVENT_LOOP; // These macros are for DIALOG_SHIM only, NOT for KIWAY_PLAYER. KIWAY_PLAYER // has its own support for quasi modal and its platform specific issues are different @@ -150,7 +150,7 @@ protected: wxWindow* m_initialFocusTarget; // variables for quasi-modal behavior support, only used by a few derivatives. - EVENT_LOOP* m_qmodal_loop; // points to nested event_loop, NULL means not qmodal and dismissed + WX_EVENT_LOOP* m_qmodal_loop; // points to nested event_loop, NULL means not qmodal and dismissed bool m_qmodal_showing; WDO_ENABLE_DISABLE* m_qmodal_parent_disabler; };