]>
Commit | Line | Data |
---|---|---|
5c6eb3a8 | 1 | /////////////////////////////////////////////////////////////////////////////// |
233f5738 VZ |
2 | // Name: wx/osx/evtloop.h |
3 | // Purpose: simply forwards to wx/osx/carbon/evtloop.h or | |
4 | // wx/osx/cocoa/evtloop.h for consistency with the other Mac | |
5 | // headers | |
5c6eb3a8 SC |
6 | // Author: Vadim Zeitlin |
7 | // Modified by: | |
8 | // Created: 2006-01-12 | |
9 | // RCS-ID: $Id$ | |
10 | // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org> | |
11 | // Licence: wxWindows licence | |
12 | /////////////////////////////////////////////////////////////////////////////// | |
13 | ||
5cd99866 VZ |
14 | #ifndef _WX_OSX_EVTLOOP_H_ |
15 | #define _WX_OSX_EVTLOOP_H_ | |
5c6eb3a8 | 16 | |
293a13ba SC |
17 | DECLARE_WXOSX_OPAQUE_CFREF( CFRunLoop ); |
18 | DECLARE_WXOSX_OPAQUE_CFREF( CFRunLoopObserver ); | |
5cd99866 | 19 | |
c657294b | 20 | class WXDLLIMPEXP_BASE wxCFEventLoopPauseIdleEvents; |
4c4cbded | 21 | |
0056673c | 22 | class WXDLLIMPEXP_BASE wxCFEventLoop : public wxEventLoopBase |
5cd99866 | 23 | { |
c657294b | 24 | friend class wxCFEventLoopPauseIdleEvents; |
5cd99866 | 25 | public: |
0056673c SC |
26 | wxCFEventLoop(); |
27 | virtual ~wxCFEventLoop(); | |
28 | ||
29 | // enters a loop calling OnNextIteration(), Pending() and Dispatch() and | |
30 | // terminating when Exit() is called | |
31 | virtual int Run(); | |
ce00f59b | 32 | |
0056673c SC |
33 | // sets the "should exit" flag and wakes up the loop so that it terminates |
34 | // soon | |
35 | virtual void Exit(int rc = 0); | |
ce00f59b | 36 | |
0056673c SC |
37 | // return true if any events are available |
38 | virtual bool Pending() const; | |
ce00f59b | 39 | |
0056673c SC |
40 | // dispatch a single event, return false if we should exit from the loop |
41 | virtual bool Dispatch(); | |
ce00f59b | 42 | |
0056673c SC |
43 | // same as Dispatch() but doesn't wait for longer than the specified (in |
44 | // ms) timeout, return true if an event was processed, false if we should | |
45 | // exit the loop or -1 if timeout expired | |
46 | virtual int DispatchTimeout(unsigned long timeout); | |
47 | ||
48 | // implement this to wake up the loop: usually done by posting a dummy event | |
49 | // to it (can be called from non main thread) | |
50 | virtual void WakeUp(); | |
ce00f59b | 51 | |
0056673c SC |
52 | virtual bool YieldFor(long eventsToProcess); |
53 | ||
5cd99866 VZ |
54 | #if wxUSE_EVENTLOOP_SOURCE |
55 | virtual wxEventLoopSource * | |
56 | AddSourceForFD(int fd, wxEventLoopSourceHandler *handler, int flags); | |
57 | #endif // wxUSE_EVENTLOOP_SOURCE | |
58 | ||
59 | protected: | |
3cac3654 SC |
60 | void CommonModeObserverCallBack(CFRunLoopObserverRef observer, int activity); |
61 | void DefaultModeObserverCallBack(CFRunLoopObserverRef observer, int activity); | |
62 | ||
4c4cbded SC |
63 | // set to false to avoid idling at unexpected moments - eg when having native message boxes |
64 | void SetProcessIdleEvents(bool process) { m_processIdleEvents = process; } | |
65 | ||
3cac3654 SC |
66 | static void OSXCommonModeObserverCallBack(CFRunLoopObserverRef observer, int activity, void *info); |
67 | static void OSXDefaultModeObserverCallBack(CFRunLoopObserverRef observer, int activity, void *info); | |
68 | ||
5cd99866 | 69 | // get the currently executing CFRunLoop |
0056673c SC |
70 | virtual CFRunLoopRef CFGetCurrentRunLoop() const; |
71 | ||
72 | virtual int DoDispatchTimeout(unsigned long timeout); | |
ce00f59b | 73 | |
80eee837 | 74 | virtual void DoRun(); |
0056673c | 75 | |
80eee837 | 76 | virtual void DoStop(); |
ce00f59b | 77 | |
0056673c SC |
78 | // should we exit the loop? |
79 | bool m_shouldExit; | |
80 | ||
81 | // the loop exit code | |
82 | int m_exitcode; | |
ce00f59b | 83 | |
9aee1212 SC |
84 | // cfrunloop |
85 | CFRunLoopRef m_runLoop; | |
ce00f59b | 86 | |
3cac3654 SC |
87 | // common modes runloop observer |
88 | CFRunLoopObserverRef m_commonModeRunLoopObserver; | |
89 | ||
90 | // default mode runloop observer | |
91 | CFRunLoopObserverRef m_defaultModeRunLoopObserver; | |
4c4cbded SC |
92 | |
93 | // set to false to avoid idling at unexpected moments - eg when having native message boxes | |
94 | bool m_processIdleEvents; | |
ce00f59b | 95 | |
0056673c SC |
96 | private: |
97 | // process all already pending events and dispatch a new one (blocking | |
98 | // until it appears in the event queue if necessary) | |
99 | // | |
100 | // returns the return value of DoDispatchTimeout() | |
101 | int DoProcessEvents(); | |
4c4cbded SC |
102 | |
103 | wxDECLARE_NO_COPY_CLASS(wxCFEventLoop); | |
104 | }; | |
105 | ||
c657294b | 106 | class WXDLLIMPEXP_BASE wxCFEventLoopPauseIdleEvents : public wxObject |
4c4cbded SC |
107 | { |
108 | public: | |
c657294b SC |
109 | wxCFEventLoopPauseIdleEvents(); |
110 | virtual ~wxCFEventLoopPauseIdleEvents(); | |
5cd99866 VZ |
111 | }; |
112 | ||
113 | #if wxUSE_GUI | |
80eee837 SC |
114 | |
115 | #ifdef __WXOSX_COCOA__ | |
116 | #include "wx/osx/cocoa/evtloop.h" | |
117 | #else | |
118 | #include "wx/osx/carbon/evtloop.h" | |
119 | #endif | |
120 | ||
121 | class WXDLLIMPEXP_FWD_CORE wxWindow; | |
122 | class WXDLLIMPEXP_FWD_CORE wxNonOwnedWindow; | |
123 | ||
124 | class WXDLLIMPEXP_CORE wxModalEventLoop : public wxGUIEventLoop | |
125 | { | |
126 | public: | |
cfb0ef70 SC |
127 | wxModalEventLoop(wxWindow *modalWindow); |
128 | wxModalEventLoop(WXWindow modalNativeWindow); | |
ce00f59b | 129 | |
80eee837 SC |
130 | protected: |
131 | virtual void DoRun(); | |
ce00f59b | 132 | |
80eee837 | 133 | virtual void DoStop(); |
ce00f59b | 134 | |
80eee837 SC |
135 | // (in case) the modal window for this event loop |
136 | wxNonOwnedWindow* m_modalWindow; | |
cfb0ef70 | 137 | WXWindow m_modalNativeWindow; |
80eee837 SC |
138 | }; |
139 | ||
5cd99866 VZ |
140 | #endif // wxUSE_GUI |
141 | ||
142 | #endif // _WX_OSX_EVTLOOP_H_ |