1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: mgl/evtloop.cpp
3 // Purpose: implements wxEventLoop for MGL
4 // Author: Vaclav Slavik
6 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
7 // License: wxWindows license
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
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()
79 MGL_wmUpdateDC(g_winMng
);
81 EVT_halt(&evt
, EVT_EVERYEVT
);
82 MGL_wmProcessEvent(g_winMng
, &evt
);
85 bool wxEventLoopImpl::SendIdleEvent()
89 return wxTheApp
->ProcessEvent(event
) && event
.MoreRequested();
92 // ============================================================================
93 // wxEventLoop implementation
94 // ============================================================================
96 // ----------------------------------------------------------------------------
97 // wxEventLoop running and exiting
98 // ----------------------------------------------------------------------------
100 wxEventLoop
*wxEventLoop::ms_activeLoop
= NULL
;
102 wxEventLoop::~wxEventLoop()
104 wxASSERT_MSG( !m_impl
, _T("should have been deleted in Run()") );
107 bool wxEventLoop::IsRunning() const
109 return m_impl
!= NULL
;
112 int wxEventLoop::Run()
114 // event loops are not recursive, you need to create another loop!
115 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
117 m_impl
= new wxEventLoopImpl
;
119 wxEventLoop
*oldLoop
= ms_activeLoop
;
120 ms_activeLoop
= this;
125 //wxMutexGuiLeaveOrEnter(); // FIXME_MGL - huh?
126 #endif // wxUSE_THREADS
128 // generate and process idle events for as long as we don't have
129 // anything else to do
130 while ( !Pending() && m_impl
->SendIdleEvent() ) {}
132 // a message came or no more idle processing to do, sit in Dispatch()
133 // waiting for the next message
141 int exitcode
= m_impl
->GetExitCode();
145 ms_activeLoop
= oldLoop
;
150 void wxEventLoop::Exit(int rc
)
152 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
154 m_impl
->SetExitCode(rc
);
155 m_impl
->SetKeepLooping(FALSE
);
158 // ----------------------------------------------------------------------------
159 // wxEventLoop message processing dispatching
160 // ----------------------------------------------------------------------------
162 bool wxEventLoop::Pending() const
165 return EVT_peekNext(&evt
, EVT_EVERYEVT
);
168 bool wxEventLoop::Dispatch()
170 wxCHECK_MSG( IsRunning(), FALSE
, _T("can't call Dispatch() if not running") );
173 return m_impl
->GetKeepLooping();