]> git.saurik.com Git - wxWidgets.git/blob - include/wx/evtloop.h
dcd2a766e07cb1eaf4e842c35a5172b73e03029d
[wxWidgets.git] / include / wx / evtloop.h
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>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_EVTLOOP_H_
13 #define _WX_EVTLOOP_H_
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "evtloop.h"
17 #endif
18
19 class WXDLLEXPORT wxEventLoopImpl;
20
21 // ----------------------------------------------------------------------------
22 // wxEventLoop: a GUI event loop
23 // ----------------------------------------------------------------------------
24
25 class WXDLLEXPORT wxEventLoop
26 {
27 public:
28 // ctor
29 wxEventLoop() { m_impl = NULL; }
30
31 // dtor
32 virtual ~wxEventLoop();
33
34 // start the event loop, return the exit code when it is finished
35 virtual int Run();
36
37 // exit from the loop with the given exit code
38 virtual void Exit(int rc = 0);
39
40 // return TRUE if any events are available
41 virtual bool Pending() const;
42
43 // dispatch a single event, return FALSE if we should exit from the loop
44 virtual bool Dispatch();
45
46 // is the event loop running now?
47 virtual bool IsRunning() const;
48
49 // return currently active (running) event loop, may be NULL
50 static wxEventLoop *GetActive() { return ms_activeLoop; }
51
52 // set currently active (running) event loop
53 static void SetActive(wxEventLoop* loop) { ms_activeLoop = loop; }
54
55 protected:
56 // this function should be called before the event loop terminates, whether
57 // this happens normally (because of Exit() call) or abnormally (because of
58 // an exception thrown from inside the loop)
59 virtual void OnExit() { }
60
61
62 // the pointer to currently active loop
63 static wxEventLoop *ms_activeLoop;
64
65 // the pointer to the port specific implementation class
66 wxEventLoopImpl *m_impl;
67
68 DECLARE_NO_COPY_CLASS(wxEventLoop)
69 };
70
71 // ----------------------------------------------------------------------------
72 // wxModalEventLoop
73 // ----------------------------------------------------------------------------
74
75 // this is a naive generic implementation which uses wxWindowDisabler to
76 // implement modality, we will surely need platform-specific implementations
77 // too, this generic implementation is here only temporarily to see how it
78 // works
79 class WXDLLEXPORT wxModalEventLoop : public wxEventLoop
80 {
81 public:
82 wxModalEventLoop(wxWindow *winModal)
83 {
84 m_windowDisabler = new wxWindowDisabler(winModal);
85 }
86
87 protected:
88 virtual void OnExit()
89 {
90 delete m_windowDisabler;
91 m_windowDisabler = NULL;
92
93 wxEventLoop::OnExit();
94 }
95
96 private:
97 wxWindowDisabler *m_windowDisabler;
98 };
99
100 #endif // _WX_EVTLOOP_H_