]>
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 // wxEventLoopManual is unused in the other ports
36 #if defined(__WXMSW__) || defined(__WXMAC__)
38 // ============================================================================
39 // wxEventLoopManual implementation
40 // ============================================================================
42 wxEventLoopManual::wxEventLoopManual()
48 int wxEventLoopManual::Run()
50 // event loops are not recursive, you need to create another loop!
51 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
53 // ProcessIdle() and Dispatch() below may throw so the code here should
54 // be exception-safe, hence we must use local objects for all actions we
56 wxEventLoopActivator
activate(wx_static_cast(wxEventLoop
*, this));
58 // we must ensure that OnExit() is called even if an exception is thrown
59 // from inside Dispatch() but we must call it from Exit() in normal
60 // situations because it is supposed to be called synchronously,
61 // wxModalEventLoop depends on this (so we can't just use ON_BLOCK_EXIT or
62 // something similar here)
68 #endif // wxUSE_EXCEPTIONS
70 // this is the event loop itself
73 // give them the possibility to do whatever they want
76 // generate and process idle events for as long as we don't
77 // have anything else to do
78 while ( !Pending() && (wxTheApp
&& wxTheApp
->ProcessIdle()) )
81 // if the "should exit" flag is set, the loop should terminate
82 // but not before processing any remaining messages so while
83 // Pending() returns true, do process them
92 // a message came or no more idle processing to do, sit in
93 // Dispatch() waiting for the next message
102 // exit the outer loop as well
109 if ( !wxTheApp
|| !wxTheApp
->OnExceptionInMainLoop() )
114 //else: continue running the event loop
118 // OnException() throwed, possibly rethrowing the same
119 // exception again: very good, but we still need OnExit() to
126 #endif // wxUSE_EXCEPTIONS
131 void wxEventLoopManual::Exit(int rc
)
133 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
140 // all we have to do to exit from the loop is to (maybe) wake it up so that
141 // it can notice that Exit() had been called
143 // in particular, do *not* use here calls such as PostQuitMessage() (under
144 // MSW) which terminate the current event loop here because we're not sure
145 // that it is going to be processed by the correct event loop: it would be
146 // possible that another one is started and terminated by mistake if we do
151 #endif // __WXMSW__ || __WXMAC__