]>
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"
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 wxEventLoop
*wxEventLoopBase::ms_activeLoop
= NULL
;
39 // wxEventLoopManual is unused in the other ports
40 #if defined(__WXMSW__) || defined(__WXMAC__) || defined(__WXDFB__) || (defined(__UNIX__) && !wxUSE_GUI)
42 // ============================================================================
43 // wxEventLoopManual implementation
44 // ============================================================================
46 wxEventLoopManual::wxEventLoopManual()
52 int wxEventLoopManual::Run()
54 // event loops are not recursive, you need to create another loop!
55 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
57 // ProcessIdle() and Dispatch() below may throw so the code here should
58 // be exception-safe, hence we must use local objects for all actions we
60 wxEventLoopActivator
activate(this);
62 // we must ensure that OnExit() is called even if an exception is thrown
63 // from inside Dispatch() but we must call it from Exit() in normal
64 // situations because it is supposed to be called synchronously,
65 // wxModalEventLoop depends on this (so we can't just use ON_BLOCK_EXIT or
66 // something similar here)
72 #endif // wxUSE_EXCEPTIONS
74 // this is the event loop itself
77 // give them the possibility to do whatever they want
80 // generate and process idle events for as long as we don't
81 // have anything else to do
82 while ( !Pending() && (wxTheApp
&& wxTheApp
->ProcessIdle()) )
85 // if the "should exit" flag is set, the loop should terminate
86 // but not before processing any remaining messages so while
87 // Pending() returns true, do process them
96 // a message came or no more idle processing to do, sit in
97 // Dispatch() waiting for the next message
106 // exit the outer loop as well
113 if ( !wxTheApp
|| !wxTheApp
->OnExceptionInMainLoop() )
118 //else: continue running the event loop
122 // OnException() throwed, possibly rethrowing the same
123 // exception again: very good, but we still need OnExit() to
130 #endif // wxUSE_EXCEPTIONS
135 void wxEventLoopManual::Exit(int rc
)
137 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
144 // all we have to do to exit from the loop is to (maybe) wake it up so that
145 // it can notice that Exit() had been called
147 // in particular, do *not* use here calls such as PostQuitMessage() (under
148 // MSW) which terminate the current event loop here because we're not sure
149 // that it is going to be processed by the correct event loop: it would be
150 // possible that another one is started and terminated by mistake if we do
155 #endif // __WXMSW__ || __WXMAC__ || __WXDFB__