]>
git.saurik.com Git - wxWidgets.git/blob - src/common/evtloopcmn.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/evtloopcmn.cpp
3 // Purpose: common wxEventLoop-related stuff
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/evtloop.h"
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 wxEventLoop
*wxEventLoopBase::ms_activeLoop
= NULL
;
35 // ============================================================================
36 // wxEventLoopManual implementation
37 // ============================================================================
39 wxEventLoopManual::wxEventLoopManual()
45 int wxEventLoopManual::Run()
47 // event loops are not recursive, you need to create another loop!
48 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
50 // ProcessIdle() and Dispatch() below may throw so the code here should
51 // be exception-safe, hence we must use local objects for all actions we
53 wxEventLoopActivator
activate(wx_static_cast(wxEventLoop
*, this));
55 // we must ensure that OnExit() is called even if an exception is thrown
56 // from inside Dispatch() but we must call it from Exit() in normal
57 // situations because it is supposed to be called synchronously,
58 // wxModalEventLoop depends on this (so we can't just use ON_BLOCK_EXIT or
59 // something similar here)
65 #endif // wxUSE_EXCEPTIONS
67 // this is the event loop itself
70 // give them the possibility to do whatever they want
73 // generate and process idle events for as long as we don't
74 // have anything else to do
75 while ( !Pending() && (wxTheApp
&& wxTheApp
->ProcessIdle()) )
78 // if the "should exit" flag is set, the loop should terminate
79 // but not before processing any remaining messages so while
80 // Pending() returns true, do process them
89 // a message came or no more idle processing to do, sit in
90 // Dispatch() waiting for the next message
99 // exit the outer loop as well
106 if ( !wxTheApp
|| !wxTheApp
->OnExceptionInMainLoop() )
111 //else: continue running the event loop
115 // OnException() throwed, possibly rethrowing the same
116 // exception again: very good, but we still need OnExit() to
123 #endif // wxUSE_EXCEPTIONS
128 void wxEventLoopManual::Exit(int rc
)
130 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
137 // all we have to do to exit from the loop is to (maybe) wake it up so that
138 // it can notice that Exit() had been called
140 // in particular, do *not* use here calls such as PostQuitMessage() (under
141 // MSW) which terminate the current event loop here because we're not sure
142 // that it is going to be processed by the correct event loop: it would be
143 // possible that another one is started and terminated by mistake if we do