]>
Commit | Line | Data |
---|---|---|
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 | 17 | class WXDLLEXPORT wxEventLoop; |
4300caa7 | 18 | |
3808e191 JS |
19 | // ---------------------------------------------------------------------------- |
20 | // wxEventLoop: a GUI event loop | |
21 | // ---------------------------------------------------------------------------- | |
22 | ||
3754265e | 23 | class WXDLLEXPORT wxEventLoopBase |
3808e191 JS |
24 | { |
25 | public: | |
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 | 56 | protected: |
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 | ||
69 | // we're moving away from old m_impl wxEventLoop model as otherwise the user | |
70 | // code doesn't have access to platform-specific wxEventLoop methods and this | |
71 | // can sometimes be very useful (e.g. under MSW this is necessary for | |
72 | // integration with MFC) but currently this is done for MSW only, other ports | |
73 | // should follow a.s.a.p. | |
4055ed82 | 74 | #if defined(__WXPALMOS__) |
ffecfa5a JS |
75 | #include "wx/palmos/evtloop.h" |
76 | #elif defined(__WXMSW__) | |
3754265e VZ |
77 | #include "wx/msw/evtloop.h" |
78 | #else | |
79 | ||
80 | class WXDLLEXPORT wxEventLoopImpl; | |
81 | ||
82 | class WXDLLEXPORT wxEventLoop : public wxEventLoopBase | |
83 | { | |
84 | public: | |
85 | wxEventLoop() { m_impl = NULL; } | |
eaca2a2c | 86 | virtual ~wxEventLoop(); |
1a18887b | 87 | |
3754265e VZ |
88 | virtual int Run(); |
89 | virtual void Exit(int rc = 0); | |
90 | virtual bool Pending() const; | |
91 | virtual bool Dispatch(); | |
3754265e VZ |
92 | |
93 | protected: | |
4300caa7 VZ |
94 | // the pointer to the port specific implementation class |
95 | wxEventLoopImpl *m_impl; | |
96 | ||
22f3361e | 97 | DECLARE_NO_COPY_CLASS(wxEventLoop) |
eaca2a2c | 98 | }; |
3754265e VZ |
99 | |
100 | #endif // __WXMSW__/!__WXMSW__ | |
3808e191 | 101 | |
77fb1a02 VZ |
102 | inline bool wxEventLoopBase::IsRunning() const { return GetActive() == this; } |
103 | ||
4300caa7 VZ |
104 | // ---------------------------------------------------------------------------- |
105 | // wxModalEventLoop | |
106 | // ---------------------------------------------------------------------------- | |
107 | ||
108 | // this is a naive generic implementation which uses wxWindowDisabler to | |
109 | // implement modality, we will surely need platform-specific implementations | |
110 | // too, this generic implementation is here only temporarily to see how it | |
111 | // works | |
112 | class WXDLLEXPORT wxModalEventLoop : public wxEventLoop | |
113 | { | |
114 | public: | |
115 | wxModalEventLoop(wxWindow *winModal) | |
116 | { | |
117 | m_windowDisabler = new wxWindowDisabler(winModal); | |
118 | } | |
119 | ||
120 | protected: | |
121 | virtual void OnExit() | |
122 | { | |
123 | delete m_windowDisabler; | |
124 | m_windowDisabler = NULL; | |
125 | ||
126 | wxEventLoop::OnExit(); | |
127 | } | |
128 | ||
129 | private: | |
130 | wxWindowDisabler *m_windowDisabler; | |
131 | }; | |
132 | ||
77fb1a02 VZ |
133 | // ---------------------------------------------------------------------------- |
134 | // wxEventLoopActivator: helper class for wxEventLoop implementations | |
135 | // ---------------------------------------------------------------------------- | |
136 | ||
137 | // this object sets the wxEventLoop given to the ctor as the currently active | |
138 | // one and unsets it in its dtor, this is especially useful in presence of | |
139 | // exceptions but is more tidy even when we don't use them | |
140 | class wxEventLoopActivator | |
141 | { | |
142 | public: | |
143 | wxEventLoopActivator(wxEventLoop *evtLoop) | |
144 | { | |
145 | m_evtLoopOld = wxEventLoop::GetActive(); | |
146 | wxEventLoop::SetActive(evtLoop); | |
147 | } | |
148 | ||
149 | ~wxEventLoopActivator() | |
150 | { | |
151 | // restore the previously active event loop | |
152 | wxEventLoop::SetActive(m_evtLoopOld); | |
153 | } | |
154 | ||
155 | private: | |
156 | wxEventLoop *m_evtLoopOld; | |
157 | }; | |
158 | ||
3808e191 | 159 | #endif // _WX_EVTLOOP_H_ |