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