]> git.saurik.com Git - wxWidgets.git/blame - include/wx/evtloop.h
Change reference from GetForce to CanVeto
[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
JS
43
44 // is the event loop running now?
3754265e 45 virtual bool IsRunning() const = 0;
f2108ede 46
b9f246f7
VS
47 // return currently active (running) event loop, may be NULL
48 static wxEventLoop *GetActive() { return ms_activeLoop; }
3808e191 49
df0e1b64
JS
50 // set currently active (running) event loop
51 static void SetActive(wxEventLoop* loop) { ms_activeLoop = loop; }
52
3808e191 53protected:
4300caa7
VZ
54 // this function should be called before the event loop terminates, whether
55 // this happens normally (because of Exit() call) or abnormally (because of
56 // an exception thrown from inside the loop)
57 virtual void OnExit() { }
58
59
b9f246f7
VS
60 // the pointer to currently active loop
61 static wxEventLoop *ms_activeLoop;
22f3361e 62
3754265e
VZ
63 DECLARE_NO_COPY_CLASS(wxEventLoopBase)
64};
65
66// we're moving away from old m_impl wxEventLoop model as otherwise the user
67// code doesn't have access to platform-specific wxEventLoop methods and this
68// can sometimes be very useful (e.g. under MSW this is necessary for
69// integration with MFC) but currently this is done for MSW only, other ports
70// should follow a.s.a.p.
4055ed82 71#if defined(__WXPALMOS__)
ffecfa5a
JS
72 #include "wx/palmos/evtloop.h"
73#elif defined(__WXMSW__)
3754265e
VZ
74 #include "wx/msw/evtloop.h"
75#else
76
77class WXDLLEXPORT wxEventLoopImpl;
78
79class WXDLLEXPORT wxEventLoop : public wxEventLoopBase
80{
81public:
82 wxEventLoop() { m_impl = NULL; }
eaca2a2c 83 virtual ~wxEventLoop();
1a18887b 84
3754265e
VZ
85 virtual int Run();
86 virtual void Exit(int rc = 0);
87 virtual bool Pending() const;
88 virtual bool Dispatch();
9213ca5d 89 virtual bool IsRunning() const { return GetActive() == this; }
3754265e
VZ
90
91protected:
4300caa7
VZ
92 // the pointer to the port specific implementation class
93 wxEventLoopImpl *m_impl;
94
22f3361e 95 DECLARE_NO_COPY_CLASS(wxEventLoop)
eaca2a2c 96 };
3754265e
VZ
97
98#endif // __WXMSW__/!__WXMSW__
3808e191 99
4300caa7
VZ
100// ----------------------------------------------------------------------------
101// wxModalEventLoop
102// ----------------------------------------------------------------------------
103
104// this is a naive generic implementation which uses wxWindowDisabler to
105// implement modality, we will surely need platform-specific implementations
106// too, this generic implementation is here only temporarily to see how it
107// works
108class WXDLLEXPORT wxModalEventLoop : public wxEventLoop
109{
110public:
111 wxModalEventLoop(wxWindow *winModal)
112 {
113 m_windowDisabler = new wxWindowDisabler(winModal);
114 }
115
116protected:
117 virtual void OnExit()
118 {
119 delete m_windowDisabler;
120 m_windowDisabler = NULL;
121
122 wxEventLoop::OnExit();
123 }
124
125private:
126 wxWindowDisabler *m_windowDisabler;
127};
128
3808e191 129#endif // _WX_EVTLOOP_H_