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
50 void ProcessEvent(event_t
*evt
);
52 // generate an idle message, return TRUE if more idle time requested
53 bool SendIdleMessage();
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::ProcessEvent(event_t
*evt
)
76 MGL_wmProcessEvent(g_winMng
, evt
);
79 bool wxEventLoopImpl::SendIdleMessage()
83 return wxTheApp
->ProcessEvent(event
) && event
.MoreRequested();
86 // ============================================================================
87 // wxEventLoop implementation
88 // ============================================================================
90 // ----------------------------------------------------------------------------
91 // wxEventLoop running and exiting
92 // ----------------------------------------------------------------------------
94 wxEventLoop::~wxEventLoop()
96 wxASSERT_MSG( !m_impl
, _T("should have been deleted in Run()") );
99 bool wxEventLoop::IsRunning() const
101 return m_impl
!= NULL
;
104 int wxEventLoop::Run()
106 // event loops are not recursive, you need to create another loop!
107 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
109 m_impl
= new wxEventLoopImpl
;
114 //wxMutexGuiLeaveOrEnter(); // FIXME_MGL - huh?
115 #endif // wxUSE_THREADS
117 // generate and process idle events for as long as we don't have
118 // anything else to do
119 while ( !Pending() && m_impl
->SendIdleMessage() ) {}
121 // a message came or no more idle processing to do, sit in Dispatch()
122 // waiting for the next message
130 int exitcode
= m_impl
->GetExitCode();
137 void wxEventLoop::Exit(int rc
)
139 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
141 m_impl
->SetExitCode(rc
);
142 m_impl
->SetKeepLooping(FALSE
);
145 // ----------------------------------------------------------------------------
146 // wxEventLoop message processing dispatching
147 // ----------------------------------------------------------------------------
149 bool wxEventLoop::Pending() const
152 return EVT_peekNext(&evt
, EVT_EVERYEVT
);
155 bool wxEventLoop::Dispatch()
157 wxCHECK_MSG( IsRunning(), FALSE
, _T("can't call Dispatch() if not running") );
162 rc
= EVT_getNext(&evt
, EVT_EVERYEVT
);
166 if ( !m_impl
->GetKeepLooping() )
168 rc
= EVT_getNext(&evt
, EVT_EVERYEVT
);
171 m_impl
->ProcessEvent(&evt
);
173 return m_impl
->GetKeepLooping();