]>
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"
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 wxEventLoop
*wxEventLoopBase::ms_activeLoop
= NULL
;
36 // wxEventLoopManual is unused in the other ports
37 #if defined(__WXMSW__) || defined(__WXMAC__)
39 // ============================================================================
40 // wxEventLoopManual implementation
41 // ============================================================================
43 wxEventLoopManual::wxEventLoopManual()
49 int wxEventLoopManual::Run()
51 // event loops are not recursive, you need to create another loop!
52 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
54 // ProcessIdle() and Dispatch() below may throw so the code here should
55 // be exception-safe, hence we must use local objects for all actions we
57 wxEventLoopActivator
activate(wx_static_cast(wxEventLoop
*, this));
59 // we must ensure that OnExit() is called even if an exception is thrown
60 // from inside Dispatch() but we must call it from Exit() in normal
61 // situations because it is supposed to be called synchronously,
62 // wxModalEventLoop depends on this (so we can't just use ON_BLOCK_EXIT or
63 // something similar here)
69 #endif // wxUSE_EXCEPTIONS
71 // this is the event loop itself
74 // give them the possibility to do whatever they want
77 // generate and process idle events for as long as we don't
78 // have anything else to do
79 while ( !Pending() && (wxTheApp
&& wxTheApp
->ProcessIdle()) )
82 // if the "should exit" flag is set, the loop should terminate
83 // but not before processing any remaining messages so while
84 // Pending() returns true, do process them
93 // a message came or no more idle processing to do, sit in
94 // Dispatch() waiting for the next message
103 // exit the outer loop as well
110 if ( !wxTheApp
|| !wxTheApp
->OnExceptionInMainLoop() )
115 //else: continue running the event loop
119 // OnException() throwed, possibly rethrowing the same
120 // exception again: very good, but we still need OnExit() to
127 #endif // wxUSE_EXCEPTIONS
132 void wxEventLoopManual::Exit(int rc
)
134 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
141 // all we have to do to exit from the loop is to (maybe) wake it up so that
142 // it can notice that Exit() had been called
144 // in particular, do *not* use here calls such as PostQuitMessage() (under
145 // MSW) which terminate the current event loop here because we're not sure
146 // that it is going to be processed by the correct event loop: it would be
147 // possible that another one is started and terminated by mistake if we do
152 #endif // __WXMSW__ || __WXMAC__