]>
git.saurik.com Git - wxWidgets.git/blob - src/common/evtloopcmn.cpp
808e82c972207a8a06979498d365d5a4181a3778
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"
31 #include "wx/stopwatch.h" // for wxMilliClock_t
34 // ----------------------------------------------------------------------------
36 // ----------------------------------------------------------------------------
38 wxEventLoopBase
*wxEventLoopBase::ms_activeLoop
= NULL
;
40 // wxEventLoopManual is unused in the other ports
41 #if defined(__WXMSW__) || defined(__WXMAC__) || defined(__WXDFB__) || (defined(__UNIX__) && wxUSE_BASE)
43 // ============================================================================
44 // wxEventLoopManual implementation
45 // ============================================================================
47 wxEventLoopManual::wxEventLoopManual()
53 int wxEventLoopManual::Run()
55 // event loops are not recursive, you need to create another loop!
56 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
58 // ProcessIdle() and Dispatch() below may throw so the code here should
59 // be exception-safe, hence we must use local objects for all actions we
61 wxEventLoopActivator
activate(this);
63 // we must ensure that OnExit() is called even if an exception is thrown
64 // from inside Dispatch() but we must call it from Exit() in normal
65 // situations because it is supposed to be called synchronously,
66 // wxModalEventLoop depends on this (so we can't just use ON_BLOCK_EXIT or
67 // something similar here)
73 #endif // wxUSE_EXCEPTIONS
75 // this is the event loop itself
78 // give them the possibility to do whatever they want
81 // generate and process idle events for as long as we don't
82 // have anything else to do
83 while ( !Pending() && (wxTheApp
&& wxTheApp
->ProcessIdle()) )
86 // if the "should exit" flag is set, the loop should terminate
87 // but not before processing any remaining messages so while
88 // Pending() returns true, do process them
97 // a message came or no more idle processing to do, sit in
98 // Dispatch() waiting for the next message
107 // exit the outer loop as well
114 if ( !wxTheApp
|| !wxTheApp
->OnExceptionInMainLoop() )
119 //else: continue running the event loop
123 // OnException() throwed, possibly rethrowing the same
124 // exception again: very good, but we still need OnExit() to
131 #endif // wxUSE_EXCEPTIONS
136 void wxEventLoopManual::Exit(int rc
)
138 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
145 // all we have to do to exit from the loop is to (maybe) wake it up so that
146 // it can notice that Exit() had been called
148 // in particular, do *not* use here calls such as PostQuitMessage() (under
149 // MSW) which terminate the current event loop here because we're not sure
150 // that it is going to be processed by the correct event loop: it would be
151 // possible that another one is started and terminated by mistake if we do
156 #endif // __WXMSW__ || __WXMAC__ || __WXDFB__
158 #ifdef wxNEEDS_GENERIC_DISPATCH_TIMEOUT
160 int wxGUIEventLoop::DispatchTimeout(unsigned long timeout
)
162 // TODO: this is, of course, horribly inefficient and a proper wait with
163 // timeout should be implemented for all ports natively...
164 const wxMilliClock_t timeEnd
= wxGetLocalTimeMillis() + timeout
;
170 if ( wxGetLocalTimeMillis() >= timeEnd
)
175 #endif // wxNEEDS_GENERIC_DISPATCH_TIMEOUT