]> git.saurik.com Git - wxWidgets.git/blob - include/wx/evtloop.h
wxCocoa: Add native file dialog from Ryan Norton. Modified patch #1039368
[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 #include "wx/utils.h"
20
21 class WXDLLEXPORT wxEventLoop;
22
23 // ----------------------------------------------------------------------------
24 // wxEventLoop: a GUI event loop
25 // ----------------------------------------------------------------------------
26
27 class WXDLLEXPORT wxEventLoopBase
28 {
29 public:
30 // trivial, but needed (because of wxEventLoopBase) ctor
31 wxEventLoopBase() { }
32
33 // dtor
34 virtual ~wxEventLoopBase() { }
35
36 // start the event loop, return the exit code when it is finished
37 virtual int Run() = 0;
38
39 // exit from the loop with the given exit code
40 virtual void Exit(int rc = 0) = 0;
41
42 // return true if any events are available
43 virtual bool Pending() const = 0;
44
45 // dispatch a single event, return false if we should exit from the loop
46 virtual bool Dispatch() = 0;
47
48 // is the event loop running now?
49 virtual bool IsRunning() const = 0;
50
51 // return currently active (running) event loop, may be NULL
52 static wxEventLoop *GetActive() { return ms_activeLoop; }
53
54 // set currently active (running) event loop
55 static void SetActive(wxEventLoop* loop) { ms_activeLoop = loop; }
56
57 protected:
58 // this function should be called before the event loop terminates, whether
59 // this happens normally (because of Exit() call) or abnormally (because of
60 // an exception thrown from inside the loop)
61 virtual void OnExit() { }
62
63
64 // the pointer to currently active loop
65 static wxEventLoop *ms_activeLoop;
66
67 DECLARE_NO_COPY_CLASS(wxEventLoopBase)
68 };
69
70 // we're moving away from old m_impl wxEventLoop model as otherwise the user
71 // code doesn't have access to platform-specific wxEventLoop methods and this
72 // can sometimes be very useful (e.g. under MSW this is necessary for
73 // integration with MFC) but currently this is done for MSW only, other ports
74 // should follow a.s.a.p.
75 #ifdef __WXMSW__
76 #include "wx/msw/evtloop.h"
77 #else
78
79 class WXDLLEXPORT wxEventLoopImpl;
80
81 class WXDLLEXPORT wxEventLoop : public wxEventLoopBase
82 {
83 public:
84 wxEventLoop() { m_impl = NULL; }
85 virtual ~wxEventLoop();
86
87 virtual int Run();
88 virtual void Exit(int rc = 0);
89 virtual bool Pending() const;
90 virtual bool Dispatch();
91 virtual bool IsRunning() const { return GetActive() == this; }
92
93 protected:
94 // the pointer to the port specific implementation class
95 wxEventLoopImpl *m_impl;
96
97 DECLARE_NO_COPY_CLASS(wxEventLoop)
98 };
99
100 #endif // __WXMSW__/!__WXMSW__
101
102 // ----------------------------------------------------------------------------
103 // wxModalEventLoop
104 // ----------------------------------------------------------------------------
105
106 // this is a naive generic implementation which uses wxWindowDisabler to
107 // implement modality, we will surely need platform-specific implementations
108 // too, this generic implementation is here only temporarily to see how it
109 // works
110 class WXDLLEXPORT wxModalEventLoop : public wxEventLoop
111 {
112 public:
113 wxModalEventLoop(wxWindow *winModal)
114 {
115 m_windowDisabler = new wxWindowDisabler(winModal);
116 }
117
118 protected:
119 virtual void OnExit()
120 {
121 delete m_windowDisabler;
122 m_windowDisabler = NULL;
123
124 wxEventLoop::OnExit();
125 }
126
127 private:
128 wxWindowDisabler *m_windowDisabler;
129 };
130
131 #endif // _WX_EVTLOOP_H_