1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: mgl/evtloop.cpp
3 // Purpose: implements wxEventLoop for MGL
4 // Author: Vaclav Slavik
6 // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
7 // License: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
14 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
15 #pragma implementation "evtloop.h"
18 // For compilers that support precompilation, includes "wx.h".
19 #include "wx/wxprec.h"
26 #include "wx/window.h"
28 #include "wx/thread.h"
31 #include "wx/evtloop.h"
33 #include "wx/mgl/private.h"
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 class WXDLLEXPORT wxEventLoopImpl
52 // generate an idle event, return TRUE if more idle time requested
55 // set/get the exit code
56 void SetExitCode(int exitcode
) { m_exitcode
= exitcode
; }
57 int GetExitCode() const { return m_exitcode
; }
59 void SetKeepLooping(bool k
) { m_keepLooping
= k
; }
60 bool GetKeepLooping() const { return m_keepLooping
; }
64 // the exit code of the event loop
66 // FALSE if the loop should end
70 // ============================================================================
71 // wxEventLoopImpl implementation
72 // ============================================================================
74 void wxEventLoopImpl::Dispatch()
78 // VS: The code bellow is equal to MGL's EVT_halt implementation, with
79 // two things added: sleeping (busy waiting is stupid, lets make CPU's
80 // life a bit easier) and timers updating
82 // EVT_halt(&evt, EVT_EVERYEVT);
86 wxTimer::NotifyTimers();
87 MGL_wmUpdateDC(g_winMng
);
90 if ( EVT_getNext(&evt
, EVT_EVERYEVT
) ) break;
95 MGL_wmProcessEvent(g_winMng
, &evt
);
98 bool wxEventLoopImpl::SendIdleEvent()
100 return wxTheApp
->ProcessIdle();
103 // ============================================================================
104 // wxEventLoop implementation
105 // ============================================================================
107 // ----------------------------------------------------------------------------
108 // wxEventLoop running and exiting
109 // ----------------------------------------------------------------------------
111 wxEventLoop
*wxEventLoopBase::ms_activeLoop
= NULL
;
113 wxEventLoop::~wxEventLoop()
115 wxASSERT_MSG( !m_impl
, _T("should have been deleted in Run()") );
118 int wxEventLoop::Run()
120 // event loops are not recursive, you need to create another loop!
121 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
123 m_impl
= new wxEventLoopImpl
;
125 wxEventLoop
*oldLoop
= ms_activeLoop
;
126 ms_activeLoop
= this;
131 //wxMutexGuiLeaveOrEnter(); // FIXME_MGL - huh?
132 #endif // wxUSE_THREADS
134 // generate and process idle events for as long as we don't have
135 // anything else to do
136 while ( !Pending() && m_impl
->SendIdleEvent() ) {}
138 // a message came or no more idle processing to do, sit in Dispatch()
139 // waiting for the next message
147 int exitcode
= m_impl
->GetExitCode();
151 ms_activeLoop
= oldLoop
;
156 void wxEventLoop::Exit(int rc
)
158 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
160 m_impl
->SetExitCode(rc
);
161 m_impl
->SetKeepLooping(FALSE
);
163 // Send a dummy event so that the app won't block in EVT_halt if there
164 // are no user-generated events in the queue:
165 EVT_post(0, EVT_USEREVT
, 0, 0);
168 // ----------------------------------------------------------------------------
169 // wxEventLoop message processing dispatching
170 // ----------------------------------------------------------------------------
172 bool wxEventLoop::Pending() const
174 // update the display here, so that wxYield refreshes display and
175 // changes take effect immediately, not after emptying events queue:
176 MGL_wmUpdateDC(g_winMng
);
178 // is there an event in the queue?
180 return EVT_peekNext(&evt
, EVT_EVERYEVT
);
183 bool wxEventLoop::Dispatch()
185 wxCHECK_MSG( IsRunning(), FALSE
, _T("can't call Dispatch() if not running") );
188 return m_impl
->GetKeepLooping();