1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/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 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
22 #include "wx/window.h"
24 #include "wx/thread.h"
28 #include "wx/evtloop.h"
29 #include "wx/mgl/private.h"
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 class WXDLLEXPORT wxEventLoopImpl
48 // generate an idle event, return true if more idle time requested
51 // set/get the exit code
52 void SetExitCode(int exitcode
) { m_exitcode
= exitcode
; }
53 int GetExitCode() const { return m_exitcode
; }
55 void SetKeepLooping(bool k
) { m_keepLooping
= k
; }
56 bool GetKeepLooping() const { return m_keepLooping
; }
60 // the exit code of the event loop
62 // false if the loop should end
66 // ============================================================================
67 // wxEventLoopImpl implementation
68 // ============================================================================
70 void wxEventLoopImpl::Dispatch()
74 // VS: The code bellow is equal to MGL's EVT_halt implementation, with
75 // two things added: sleeping (busy waiting is stupid, lets make CPU's
76 // life a bit easier) and timers updating
78 // EVT_halt(&evt, EVT_EVERYEVT);
82 wxTimer::NotifyTimers();
83 MGL_wmUpdateDC(g_winMng
);
86 if ( EVT_getNext(&evt
, EVT_EVERYEVT
) ) break;
91 MGL_wmProcessEvent(g_winMng
, &evt
);
94 bool wxEventLoopImpl::SendIdleEvent()
96 return wxTheApp
->ProcessIdle();
99 // ============================================================================
100 // wxEventLoop implementation
101 // ============================================================================
103 // ----------------------------------------------------------------------------
104 // wxEventLoop running and exiting
105 // ----------------------------------------------------------------------------
107 wxEventLoop::~wxEventLoop()
109 wxASSERT_MSG( !m_impl
, _T("should have been deleted in Run()") );
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 wxEventLoopActivator
activate(this);
124 //wxMutexGuiLeaveOrEnter(); // FIXME_MGL - huh?
125 #endif // wxUSE_THREADS
127 // generate and process idle events for as long as we don't have
128 // anything else to do
129 while ( !Pending() && m_impl
->SendIdleEvent() ) {}
131 // a message came or no more idle processing to do, sit in Dispatch()
132 // waiting for the next message
140 int exitcode
= m_impl
->GetExitCode();
147 void wxEventLoop::Exit(int rc
)
149 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
151 m_impl
->SetExitCode(rc
);
152 m_impl
->SetKeepLooping(false);
154 // Send a dummy event so that the app won't block in EVT_halt if there
155 // are no user-generated events in the queue:
156 EVT_post(0, EVT_USEREVT
, 0, 0);
159 // ----------------------------------------------------------------------------
160 // wxEventLoop message processing dispatching
161 // ----------------------------------------------------------------------------
163 bool wxEventLoop::Pending() const
165 // update the display here, so that wxYield refreshes display and
166 // changes take effect immediately, not after emptying events queue:
167 MGL_wmUpdateDC(g_winMng
);
169 // is there an event in the queue?
171 return (bool)(EVT_peekNext(&evt
, EVT_EVERYEVT
));
174 bool wxEventLoop::Dispatch()
176 wxCHECK_MSG( IsRunning(), false, _T("can't call Dispatch() if not running") );
179 return m_impl
->GetKeepLooping();