]> git.saurik.com Git - wxWidgets.git/blob - include/wx/osx/core/evtloop.h
862a4d9d54689c07c77fad35e751fbafd177301c
[wxWidgets.git] / include / wx / osx / core / evtloop.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/osx/core/evtloop.h
3 // Purpose: CoreFoundation-based event loop
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 2006-01-12
7 // RCS-ID: $Id$
8 // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_OSX_CORE_EVTLOOP_H_
13 #define _WX_OSX_CORE_EVTLOOP_H_
14
15 DECLARE_WXOSX_OPAQUE_CFREF( CFRunLoop );
16 DECLARE_WXOSX_OPAQUE_CFREF( CFRunLoopObserver );
17
18 class WXDLLIMPEXP_FWD_BASE wxCFEventLoopPauseIdleEvents;
19
20 class WXDLLIMPEXP_BASE wxCFEventLoop : public wxEventLoopBase
21 {
22 friend class wxCFEventLoopPauseIdleEvents;
23 public:
24 wxCFEventLoop();
25 virtual ~wxCFEventLoop();
26
27 // sets the "should exit" flag and wakes up the loop so that it terminates
28 // soon
29 virtual void ScheduleExit(int rc = 0);
30
31 // return true if any events are available
32 virtual bool Pending() const;
33
34 // dispatch a single event, return false if we should exit from the loop
35 virtual bool Dispatch();
36
37 // same as Dispatch() but doesn't wait for longer than the specified (in
38 // ms) timeout, return true if an event was processed, false if we should
39 // exit the loop or -1 if timeout expired
40 virtual int DispatchTimeout(unsigned long timeout);
41
42 // implement this to wake up the loop: usually done by posting a dummy event
43 // to it (can be called from non main thread)
44 virtual void WakeUp();
45
46 virtual bool YieldFor(long eventsToProcess);
47
48 #if wxUSE_EVENTLOOP_SOURCE
49 virtual wxEventLoopSource *
50 AddSourceForFD(int fd, wxEventLoopSourceHandler *handler, int flags);
51 #endif // wxUSE_EVENTLOOP_SOURCE
52
53 bool ShouldProcessIdleEvents() const { return m_processIdleEvents ; }
54
55 #if wxUSE_UIACTIONSIMULATOR
56 // notifies Yield and Dispatch to wait for at least one event before
57 // returning, this is necessary, because the synthesized events need to be
58 // converted by the OS before being available on the native event queue
59 void SetShouldWaitForEvent(bool should) { m_shouldWaitForEvent = should; }
60 #endif
61 protected:
62 // enters a loop calling OnNextIteration(), Pending() and Dispatch() and
63 // terminating when Exit() is called
64 virtual int DoRun();
65
66 void CommonModeObserverCallBack(CFRunLoopObserverRef observer, int activity);
67 void DefaultModeObserverCallBack(CFRunLoopObserverRef observer, int activity);
68
69 // set to false to avoid idling at unexpected moments - eg when having native message boxes
70 void SetProcessIdleEvents(bool process) { m_processIdleEvents = process; }
71
72 static void OSXCommonModeObserverCallBack(CFRunLoopObserverRef observer, int activity, void *info);
73 static void OSXDefaultModeObserverCallBack(CFRunLoopObserverRef observer, int activity, void *info);
74
75 // get the currently executing CFRunLoop
76 virtual CFRunLoopRef CFGetCurrentRunLoop() const;
77
78 virtual int DoDispatchTimeout(unsigned long timeout);
79
80 virtual void OSXDoRun();
81 virtual void OSXDoStop();
82
83 // the loop exit code
84 int m_exitcode;
85
86 // cfrunloop
87 CFRunLoopRef m_runLoop;
88
89 // common modes runloop observer
90 CFRunLoopObserverRef m_commonModeRunLoopObserver;
91
92 // default mode runloop observer
93 CFRunLoopObserverRef m_defaultModeRunLoopObserver;
94
95 // set to false to avoid idling at unexpected moments - eg when having native message boxes
96 bool m_processIdleEvents;
97
98 #if wxUSE_UIACTIONSIMULATOR
99 bool m_shouldWaitForEvent;
100 #endif
101 private:
102 // process all already pending events and dispatch a new one (blocking
103 // until it appears in the event queue if necessary)
104 //
105 // returns the return value of DoDispatchTimeout()
106 int DoProcessEvents();
107
108 wxDECLARE_NO_COPY_CLASS(wxCFEventLoop);
109 };
110
111 class WXDLLIMPEXP_BASE wxCFEventLoopPauseIdleEvents : public wxObject
112 {
113 public:
114 wxCFEventLoopPauseIdleEvents();
115 virtual ~wxCFEventLoopPauseIdleEvents();
116 private:
117 bool m_formerState;
118 };
119
120 #endif // _WX_OSX_EVTLOOP_H_