]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/evtloop.cpp
Remove my binary compatibility stuff from HEAD. Patch #1367014 used for reference.
[wxWidgets.git] / src / mgl / evtloop.cpp
CommitLineData
7bdc1879 1///////////////////////////////////////////////////////////////////////////////
127eab18 2// Name: src/mgl/evtloop.cpp
7bdc1879
VS
3// Purpose: implements wxEventLoop for MGL
4// Author: Vaclav Slavik
5// RCS-ID: $Id$
c41c20a5 6// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
65571936 7// License: wxWindows licence
7bdc1879
VS
8///////////////////////////////////////////////////////////////////////////////
9
10// ----------------------------------------------------------------------------
11// headers
12// ----------------------------------------------------------------------------
13
7bdc1879
VS
14// For compilers that support precompilation, includes "wx.h".
15#include "wx/wxprec.h"
16
17#ifdef __BORLANDC__
18 #pragma hdrstop
19#endif
20
21#ifndef WX_PRECOMP
22 #include "wx/window.h"
23 #include "wx/app.h"
24 #include "wx/thread.h"
25#endif //WX_PRECOMP
26
27#include "wx/evtloop.h"
1acd70f9 28#include "wx/timer.h"
7bdc1879
VS
29#include "wx/mgl/private.h"
30
31// ----------------------------------------------------------------------------
32// wxEventLoopImpl
33// ----------------------------------------------------------------------------
34
35class WXDLLEXPORT wxEventLoopImpl
36{
37public:
38 // ctor
39 wxEventLoopImpl()
40 {
41 SetExitCode(0);
127eab18 42 SetKeepLooping(true);
7bdc1879
VS
43 }
44
ef344ff8
VS
45 // process an event
46 void Dispatch();
7bdc1879 47
127eab18 48 // generate an idle event, return true if more idle time requested
ef344ff8 49 bool SendIdleEvent();
7bdc1879
VS
50
51 // set/get the exit code
52 void SetExitCode(int exitcode) { m_exitcode = exitcode; }
53 int GetExitCode() const { return m_exitcode; }
127eab18 54
7bdc1879
VS
55 void SetKeepLooping(bool k) { m_keepLooping = k; }
56 bool GetKeepLooping() const { return m_keepLooping; }
57
58private:
59
60 // the exit code of the event loop
61 int m_exitcode;
127eab18 62 // false if the loop should end
7bdc1879
VS
63 bool m_keepLooping;
64};
65
66// ============================================================================
67// wxEventLoopImpl implementation
68// ============================================================================
69
ef344ff8 70void wxEventLoopImpl::Dispatch()
7bdc1879 71{
ef344ff8 72 event_t evt;
ef344ff8 73
1acd70f9
VS
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
77
78 // EVT_halt(&evt, EVT_EVERYEVT);
88f2a771 79 for (;;)
1acd70f9 80 {
1acd70f9
VS
81#if wxUSE_TIMER
82 wxTimer::NotifyTimers();
88f2a771 83 MGL_wmUpdateDC(g_winMng);
1acd70f9 84#endif
88f2a771
VS
85 EVT_pollJoystick();
86 if ( EVT_getNext(&evt, EVT_EVERYEVT) ) break;
1acd70f9 87 PM_sleep(10);
88f2a771 88 }
1acd70f9 89 // end of EVT_halt
127eab18 90
ef344ff8 91 MGL_wmProcessEvent(g_winMng, &evt);
7bdc1879
VS
92}
93
ef344ff8 94bool wxEventLoopImpl::SendIdleEvent()
7bdc1879 95{
e39af974 96 return wxTheApp->ProcessIdle();
7bdc1879
VS
97}
98
99// ============================================================================
100// wxEventLoop implementation
101// ============================================================================
102
103// ----------------------------------------------------------------------------
104// wxEventLoop running and exiting
105// ----------------------------------------------------------------------------
106
3754265e 107wxEventLoop *wxEventLoopBase::ms_activeLoop = NULL;
ef344ff8 108
7bdc1879
VS
109wxEventLoop::~wxEventLoop()
110{
111 wxASSERT_MSG( !m_impl, _T("should have been deleted in Run()") );
112}
113
7bdc1879
VS
114int wxEventLoop::Run()
115{
116 // event loops are not recursive, you need to create another loop!
117 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
118
119 m_impl = new wxEventLoopImpl;
127eab18 120
ef344ff8
VS
121 wxEventLoop *oldLoop = ms_activeLoop;
122 ms_activeLoop = this;
7bdc1879
VS
123
124 for ( ;; )
125 {
126#if wxUSE_THREADS
127 //wxMutexGuiLeaveOrEnter(); // FIXME_MGL - huh?
128#endif // wxUSE_THREADS
129
130 // generate and process idle events for as long as we don't have
131 // anything else to do
ef344ff8 132 while ( !Pending() && m_impl->SendIdleEvent() ) {}
7bdc1879
VS
133
134 // a message came or no more idle processing to do, sit in Dispatch()
135 // waiting for the next message
136 if ( !Dispatch() )
137 {
138 // app terminated
139 break;
140 }
141 }
142
143 int exitcode = m_impl->GetExitCode();
144 delete m_impl;
145 m_impl = NULL;
146
ef344ff8
VS
147 ms_activeLoop = oldLoop;
148
7bdc1879
VS
149 return exitcode;
150}
151
152void wxEventLoop::Exit(int rc)
153{
154 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
155
156 m_impl->SetExitCode(rc);
127eab18
WS
157 m_impl->SetKeepLooping(false);
158
f41ed3c4
VS
159 // Send a dummy event so that the app won't block in EVT_halt if there
160 // are no user-generated events in the queue:
161 EVT_post(0, EVT_USEREVT, 0, 0);
7bdc1879
VS
162}
163
164// ----------------------------------------------------------------------------
165// wxEventLoop message processing dispatching
166// ----------------------------------------------------------------------------
167
168bool wxEventLoop::Pending() const
169{
127eab18 170 // update the display here, so that wxYield refreshes display and
c41c20a5
VS
171 // changes take effect immediately, not after emptying events queue:
172 MGL_wmUpdateDC(g_winMng);
127eab18 173
c41c20a5 174 // is there an event in the queue?
7bdc1879 175 event_t evt;
127eab18 176 return (bool)(EVT_peekNext(&evt, EVT_EVERYEVT));
7bdc1879
VS
177}
178
179bool wxEventLoop::Dispatch()
180{
127eab18 181 wxCHECK_MSG( IsRunning(), false, _T("can't call Dispatch() if not running") );
7bdc1879 182
ef344ff8 183 m_impl->Dispatch();
7bdc1879
VS
184 return m_impl->GetKeepLooping();
185}