X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d3a919bdcef1691d993419fdad6370289d0339b8..a1d6c5df6f91f034663953fb5d43daa1b65187f3:/src/os2/evtloop.cpp diff --git a/src/os2/evtloop.cpp b/src/os2/evtloop.cpp index 143a0a2ca6..6624e1bc4a 100644 --- a/src/os2/evtloop.cpp +++ b/src/os2/evtloop.cpp @@ -1,12 +1,12 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: os2/evtloop.cpp -// Purpose: implements wxEventLoop for PM +// Name: src/os2/evtloop.cpp +// Purpose: implements wxGUIEventLoop for PM // Author: Vadim Zeitlin // Modified by: // Created: 01.06.01 // RCS-ID: $Id$ // Copyright: (c) 2001 Vadim Zeitlin -// License: wxWindows licence +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -17,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ - #pragma implementation "evtloop.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -32,14 +28,15 @@ #include "wx/window.h" #include "wx/app.h" #include "wx/timer.h" + #include "wx/log.h" #endif //WX_PRECOMP #include "wx/evtloop.h" -#include "wx/log.h" #include "wx/tooltip.h" -#include "wx/ptr_scpd.h" +#include "wx/scopedptr.h" #include "wx/os2/private.h" +#include "wx/os2/private/timer.h" // for wxTimerProc #if wxUSE_THREADS // define the array of QMSG strutures @@ -87,30 +84,6 @@ private: wxDEFINE_TIED_SCOPED_PTR_TYPE(wxEventLoopImpl); -// this object sets the wxEventLoop given to the ctor as the currently active -// one and unsets it in its dtor -class wxEventLoopActivator -{ -public: - wxEventLoopActivator(wxEventLoop **pActive, - wxEventLoop *evtLoop) - { - m_pActive = pActive; - m_evtLoopOld = *pActive; - *pActive = evtLoop; - } - - ~wxEventLoopActivator() - { - // restore the previously active event loop - *m_pActive = m_evtLoopOld; - } - -private: - wxEventLoop *m_evtLoopOld; - wxEventLoop **m_pActive; -}; - // ============================================================================ // wxEventLoopImpl implementation // ============================================================================ @@ -192,11 +165,11 @@ bool wxEventLoopImpl::PreProcessMessage(QMSG *pMsg) { if((bRc = pWnd->OS2TranslateMessage((WXMSG*)pMsg)) == TRUE) break; - // stop at first top level window, i.e. don't try to process the - // key strokes originating in a dialog using the accelerators of - // the parent frame - this doesn't make much sense - if ( pWnd->IsTopLevel() ) - break; + // stop at first top level window, i.e. don't try to process the + // key strokes originating in a dialog using the accelerators of + // the parent frame - this doesn't make much sense + if ( pWnd->IsTopLevel() ) + break; } if(!bRc) // untranslated, should restore original value @@ -224,23 +197,16 @@ bool wxEventLoopImpl::SendIdleMessage() } // ============================================================================ -// wxEventLoop implementation +// wxGUIEventLoop implementation // ============================================================================ -wxEventLoop *wxEventLoop::ms_activeLoop = NULL; - // ---------------------------------------------------------------------------- -// wxEventLoop running and exiting +// wxGUIEventLoop running and exiting // ---------------------------------------------------------------------------- -wxEventLoop::~wxEventLoop() -{ - wxASSERT_MSG( !m_impl, _T("should have been deleted in Run()") ); -} - -bool wxEventLoop::IsRunning() const +wxGUIEventLoop::~wxGUIEventLoop() { - return m_impl != NULL; + wxASSERT_MSG( !m_impl, wxT("should have been deleted in Run()") ); } ////////////////////////////////////////////////////////////////////////////// @@ -261,29 +227,29 @@ bool wxEventLoop::IsRunning() const class CallEventLoopMethod { public: - typedef void (wxEventLoop::*FuncType)(); + typedef void (wxGUIEventLoop::*FuncType)(); - CallEventLoopMethod(wxEventLoop *evtLoop, FuncType fn) + CallEventLoopMethod(wxGUIEventLoop *evtLoop, FuncType fn) : m_evtLoop(evtLoop), m_fn(fn) { } ~CallEventLoopMethod() { (m_evtLoop->*m_fn)(); } private: - wxEventLoop *m_evtLoop; + wxGUIEventLoop *m_evtLoop; FuncType m_fn; }; -int wxEventLoop::Run() +int wxGUIEventLoop::Run() { // event loops are not recursive, you need to create another loop! - wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") ); + wxCHECK_MSG( !IsRunning(), -1, wxT("can't reenter a message loop") ); // SendIdleMessage() 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); + wxEventLoopActivator activate(this); wxEventLoopImplTiedPtr impl(&m_impl, new wxEventLoopImpl); - CallEventLoopMethod callOnExit(this, &wxEventLoop::OnExit); + CallEventLoopMethod callOnExit(this, &wxGUIEventLoop::OnExit); for ( ;; ) { @@ -294,30 +260,32 @@ int wxEventLoop::Run() // generate and process idle events for as long as we don't have // anything else to do while ( !Pending() && m_impl->SendIdleMessage() ) - { - wxTheApp->HandleSockets(); - wxMilliSleep(10); - } + { + wxTheApp->HandleSockets(); + wxMilliSleep(10); + } wxTheApp->HandleSockets(); if (Pending()) - { - if ( !Dispatch() ) - { - // we got WM_QUIT - break; - } - } + { + if ( !Dispatch() ) + { + // we got WM_QUIT + break; + } + } else wxMilliSleep(10); } + OnExit(); + return m_impl->GetExitCode(); } -void wxEventLoop::Exit(int rc) +void wxGUIEventLoop::Exit(int rc) { - wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") ); + wxCHECK_RET( IsRunning(), wxT("can't call Exit() if not running") ); m_impl->SetExitCode(rc); @@ -325,18 +293,18 @@ void wxEventLoop::Exit(int rc) } // ---------------------------------------------------------------------------- -// wxEventLoop message processing dispatching +// wxGUIEventLoop message processing dispatching // ---------------------------------------------------------------------------- -bool wxEventLoop::Pending() const +bool wxGUIEventLoop::Pending() const { QMSG msg; return ::WinPeekMsg(vHabmain, &msg, 0, 0, 0, PM_NOREMOVE) != 0; } -bool wxEventLoop::Dispatch() +bool wxGUIEventLoop::Dispatch() { - wxCHECK_MSG( IsRunning(), FALSE, _T("can't call Dispatch() if not running") ); + wxCHECK_MSG( IsRunning(), false, wxT("can't call Dispatch() if not running") ); QMSG msg; BOOL bRc = ::WinGetMsg(vHabmain, &msg, (HWND) NULL, 0, 0); @@ -344,14 +312,14 @@ bool wxEventLoop::Dispatch() if ( bRc == 0 ) { // got WM_QUIT - return FALSE; + return false; } #if wxUSE_THREADS wxASSERT_MSG( wxThread::IsMain(), wxT("only the main thread can process Windows messages") ); - static bool s_hadGuiLock = TRUE; + static bool s_hadGuiLock = true; static wxMsgArray s_aSavedMessages; // if a secondary thread owning the mutex is doing GUI calls, save all @@ -359,7 +327,7 @@ bool wxEventLoop::Dispatch() // it will lead to recursive library calls (and we're not reentrant) if ( !wxGuiOwnedByMainThread() ) { - s_hadGuiLock = FALSE; + s_hadGuiLock = false; // leave out WM_COMMAND messages: too dangerous, sometimes // the message will be processed twice @@ -368,7 +336,7 @@ bool wxEventLoop::Dispatch() s_aSavedMessages.Add(msg); } - return TRUE; + return true; } else { @@ -379,7 +347,7 @@ bool wxEventLoop::Dispatch() // messages normally - expect some things to break... if ( !s_hadGuiLock ) { - s_hadGuiLock = TRUE; + s_hadGuiLock = true; size_t count = s_aSavedMessages.Count(); for ( size_t n = 0; n < count; n++ ) @@ -395,6 +363,55 @@ bool wxEventLoop::Dispatch() m_impl->ProcessMessage(&msg); - return TRUE; + return true; } +// +// Yield to incoming messages +// +bool wxGUIEventLoop::YieldFor(long eventsToProcess) +{ + HAB vHab = 0; + QMSG vMsg; + + // + // Disable log flushing from here because a call to wxYield() shouldn't + // normally result in message boxes popping up &c + // + wxLog::Suspend(); + + m_isInsideYield = true; + m_eventsToProcessInsideYield = eventsToProcess; + + // + // We want to go back to the main message loop + // if we see a WM_QUIT. (?) + // + while (::WinPeekMsg(vHab, &vMsg, (HWND)NULL, 0, 0, PM_NOREMOVE) && vMsg.msg != WM_QUIT) + { + // TODO: implement event filtering using the eventsToProcess mask + +#if wxUSE_THREADS + wxMutexGuiLeaveOrEnter(); +#endif // wxUSE_THREADS + if (!wxTheApp->Dispatch()) + break; + } + + // + // If they are pending events, we must process them. + // + if (wxTheApp) + { + wxTheApp->ProcessPendingEvents(); + wxTheApp->HandleSockets(); + } + + // + // Let the logs be flashed again + // + wxLog::Resume(); + m_isInsideYield = false; + + return true; +} // end of wxYield