- // event loops are not recursive, you need to create another loop!
- wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
-
- // ProcessIdle() and Dispatch() 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(&ms_activeLoop, this);
-
-#if wxUSE_EXCEPTIONS
- try
- {
-#endif
- // this is the event loop itself
- for ( ;; )
- {
- #if wxUSE_THREADS
- wxMutexGuiLeaveOrEnter();
- #endif // wxUSE_THREADS
-
- // generate and process idle events for as long as we don't
- // have anything else to do
- while ( !Pending() && (wxTheApp && wxTheApp->ProcessIdle()) )
- ;
-
- // if the "should exit" flag is set, the loop should terminate
- // but not before processing any remaining messages so while
- // Pending() returns true, do process them
- if ( m_shouldExit )
- {
- while ( Pending() )
- Dispatch();
-
- break;
- }
-
- // a message came or no more idle processing to do, sit in
- // Dispatch() waiting for the next message
- if ( !Dispatch() )
- {
- // we got WM_QUIT
- break;
- }
- }
-#if wxUSE_EXCEPTIONS
- }
- catch ( ... )
- {
- // we need OnExit() to be called before the event loop stops
- OnExit();
- throw;
- }
-#endif // wxUSE_EXCEPTIONS
-
- return m_exitcode;