]> git.saurik.com Git - wxWidgets.git/blame - include/wx/evtloop.h
fix aui crash related to SF bug 1531361
[wxWidgets.git] / include / wx / evtloop.h
CommitLineData
3808e191
JS
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/evtloop.h
3// Purpose: declares wxEventLoop class
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 01.06.01
7// RCS-ID: $Id$
8// Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
65571936 9// Licence: wxWindows licence
3808e191
JS
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_EVTLOOP_H_
13#define _WX_EVTLOOP_H_
14
752464f9
VS
15#include "wx/utils.h"
16
3754265e 17class WXDLLEXPORT wxEventLoop;
4300caa7 18
3808e191
JS
19// ----------------------------------------------------------------------------
20// wxEventLoop: a GUI event loop
21// ----------------------------------------------------------------------------
22
3754265e 23class WXDLLEXPORT wxEventLoopBase
3808e191
JS
24{
25public:
3754265e
VZ
26 // trivial, but needed (because of wxEventLoopBase) ctor
27 wxEventLoopBase() { }
3808e191
JS
28
29 // dtor
3754265e 30 virtual ~wxEventLoopBase() { }
3808e191
JS
31
32 // start the event loop, return the exit code when it is finished
3754265e 33 virtual int Run() = 0;
3808e191
JS
34
35 // exit from the loop with the given exit code
3754265e 36 virtual void Exit(int rc = 0) = 0;
3808e191 37
1a18887b 38 // return true if any events are available
3754265e 39 virtual bool Pending() const = 0;
3808e191 40
1a18887b 41 // dispatch a single event, return false if we should exit from the loop
3754265e 42 virtual bool Dispatch() = 0;
3808e191 43
b9f246f7
VS
44 // return currently active (running) event loop, may be NULL
45 static wxEventLoop *GetActive() { return ms_activeLoop; }
3808e191 46
df0e1b64
JS
47 // set currently active (running) event loop
48 static void SetActive(wxEventLoop* loop) { ms_activeLoop = loop; }
49
77fb1a02
VZ
50 // is this event loop running now?
51 //
52 // notice that even if this event loop hasn't terminated yet but has just
53 // spawned a nested (e.g. modal) event loop, this would return false
54 bool IsRunning() const;
55
3808e191 56protected:
4300caa7
VZ
57 // this function should be called before the event loop terminates, whether
58 // this happens normally (because of Exit() call) or abnormally (because of
59 // an exception thrown from inside the loop)
60 virtual void OnExit() { }
61
62
b9f246f7
VS
63 // the pointer to currently active loop
64 static wxEventLoop *ms_activeLoop;
22f3361e 65
3754265e
VZ
66 DECLARE_NO_COPY_CLASS(wxEventLoopBase)
67};
68
b3c86150 69#if defined(__WXMSW__) || defined(__WXMAC__) || defined(__WXDFB__)
c8026dea
VZ
70
71// this class can be used to implement a standard event loop logic using
72// Pending() and Dispatch()
73//
74// it also handles idle processing automatically
75class WXDLLEXPORT wxEventLoopManual : public wxEventLoopBase
76{
77public:
78 wxEventLoopManual();
79
80 // enters a loop calling OnNextIteration(), Pending() and Dispatch() and
81 // terminating when Exit() is called
82 virtual int Run();
83
84 // sets the "should exit" flag and wakes up the loop so that it terminates
85 // soon
5b87e74a 86 virtual void Exit(int rc = 0);
c8026dea
VZ
87
88protected:
89 // implement this to wake up the loop: usually done by posting a dummy event
90 // to it (called from Exit())
91 virtual void WakeUp() = 0;
92
93 // may be overridden to perform some action at the start of each new event
94 // loop iteration
95 virtual void OnNextIteration() { }
96
97
98 // the loop exit code
99 int m_exitcode;
100
101 // should we exit the loop?
102 bool m_shouldExit;
103};
104
105#endif // platforms using "manual" loop
106
3754265e
VZ
107// we're moving away from old m_impl wxEventLoop model as otherwise the user
108// code doesn't have access to platform-specific wxEventLoop methods and this
109// can sometimes be very useful (e.g. under MSW this is necessary for
110// integration with MFC) but currently this is done for MSW only, other ports
111// should follow a.s.a.p.
4055ed82 112#if defined(__WXPALMOS__)
ffecfa5a
JS
113 #include "wx/palmos/evtloop.h"
114#elif defined(__WXMSW__)
3754265e 115 #include "wx/msw/evtloop.h"
4d90072c
VZ
116#elif defined(__WXMAC__)
117 #include "wx/mac/evtloop.h"
b3c86150
VS
118#elif defined(__WXDFB__)
119 #include "wx/dfb/evtloop.h"
4d90072c 120#else // other platform
3754265e
VZ
121
122class WXDLLEXPORT wxEventLoopImpl;
123
124class WXDLLEXPORT wxEventLoop : public wxEventLoopBase
125{
126public:
127 wxEventLoop() { m_impl = NULL; }
eaca2a2c 128 virtual ~wxEventLoop();
1a18887b 129
3754265e
VZ
130 virtual int Run();
131 virtual void Exit(int rc = 0);
132 virtual bool Pending() const;
133 virtual bool Dispatch();
3754265e
VZ
134
135protected:
4300caa7
VZ
136 // the pointer to the port specific implementation class
137 wxEventLoopImpl *m_impl;
138
22f3361e 139 DECLARE_NO_COPY_CLASS(wxEventLoop)
4d90072c 140};
3754265e 141
4d90072c 142#endif // platforms
3808e191 143
77fb1a02
VZ
144inline bool wxEventLoopBase::IsRunning() const { return GetActive() == this; }
145
4300caa7
VZ
146// ----------------------------------------------------------------------------
147// wxModalEventLoop
148// ----------------------------------------------------------------------------
149
150// this is a naive generic implementation which uses wxWindowDisabler to
151// implement modality, we will surely need platform-specific implementations
152// too, this generic implementation is here only temporarily to see how it
153// works
154class WXDLLEXPORT wxModalEventLoop : public wxEventLoop
155{
156public:
157 wxModalEventLoop(wxWindow *winModal)
158 {
159 m_windowDisabler = new wxWindowDisabler(winModal);
160 }
161
162protected:
163 virtual void OnExit()
164 {
165 delete m_windowDisabler;
166 m_windowDisabler = NULL;
167
168 wxEventLoop::OnExit();
169 }
170
171private:
172 wxWindowDisabler *m_windowDisabler;
173};
174
77fb1a02
VZ
175// ----------------------------------------------------------------------------
176// wxEventLoopActivator: helper class for wxEventLoop implementations
177// ----------------------------------------------------------------------------
178
179// this object sets the wxEventLoop given to the ctor as the currently active
180// one and unsets it in its dtor, this is especially useful in presence of
181// exceptions but is more tidy even when we don't use them
182class wxEventLoopActivator
183{
184public:
185 wxEventLoopActivator(wxEventLoop *evtLoop)
186 {
187 m_evtLoopOld = wxEventLoop::GetActive();
188 wxEventLoop::SetActive(evtLoop);
189 }
190
191 ~wxEventLoopActivator()
192 {
193 // restore the previously active event loop
194 wxEventLoop::SetActive(m_evtLoopOld);
195 }
196
197private:
198 wxEventLoop *m_evtLoopOld;
199};
200
3808e191 201#endif // _WX_EVTLOOP_H_