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