1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/osx/core/evtloop.h
3 // Purpose: CoreFoundation-based event loop
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_OSX_CORE_EVTLOOP_H_
12 #define _WX_OSX_CORE_EVTLOOP_H_
14 DECLARE_WXOSX_OPAQUE_CFREF( CFRunLoop
);
15 DECLARE_WXOSX_OPAQUE_CFREF( CFRunLoopObserver
);
17 class WXDLLIMPEXP_FWD_BASE wxCFEventLoopPauseIdleEvents
;
19 class WXDLLIMPEXP_BASE wxCFEventLoop
: public wxEventLoopBase
21 friend class wxCFEventLoopPauseIdleEvents
;
24 virtual ~wxCFEventLoop();
26 // sets the "should exit" flag and wakes up the loop so that it terminates
28 virtual void ScheduleExit(int rc
= 0);
30 // return true if any events are available
31 virtual bool Pending() const;
33 // dispatch a single event, return false if we should exit from the loop
34 virtual bool Dispatch();
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
);
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();
45 virtual bool YieldFor(long eventsToProcess
);
47 bool ShouldProcessIdleEvents() const { return m_processIdleEvents
; }
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
; }
56 // enters a loop calling OnNextIteration(), Pending() and Dispatch() and
57 // terminating when Exit() is called
60 void CommonModeObserverCallBack(CFRunLoopObserverRef observer
, int activity
);
61 void DefaultModeObserverCallBack(CFRunLoopObserverRef observer
, int activity
);
63 // set to false to avoid idling at unexpected moments - eg when having native message boxes
64 void SetProcessIdleEvents(bool process
) { m_processIdleEvents
= process
; }
66 static void OSXCommonModeObserverCallBack(CFRunLoopObserverRef observer
, int activity
, void *info
);
67 static void OSXDefaultModeObserverCallBack(CFRunLoopObserverRef observer
, int activity
, void *info
);
69 // get the currently executing CFRunLoop
70 virtual CFRunLoopRef
CFGetCurrentRunLoop() const;
72 virtual int DoDispatchTimeout(unsigned long timeout
);
74 virtual void OSXDoRun();
75 virtual void OSXDoStop();
81 CFRunLoopRef m_runLoop
;
83 // common modes runloop observer
84 CFRunLoopObserverRef m_commonModeRunLoopObserver
;
86 // default mode runloop observer
87 CFRunLoopObserverRef m_defaultModeRunLoopObserver
;
89 // set to false to avoid idling at unexpected moments - eg when having native message boxes
90 bool m_processIdleEvents
;
92 #if wxUSE_UIACTIONSIMULATOR
93 bool m_shouldWaitForEvent
;
96 // process all already pending events and dispatch a new one (blocking
97 // until it appears in the event queue if necessary)
99 // returns the return value of DoDispatchTimeout()
100 int DoProcessEvents();
102 wxDECLARE_NO_COPY_CLASS(wxCFEventLoop
);
105 class WXDLLIMPEXP_BASE wxCFEventLoopPauseIdleEvents
: public wxObject
108 wxCFEventLoopPauseIdleEvents();
109 virtual ~wxCFEventLoopPauseIdleEvents();
114 #endif // _WX_OSX_EVTLOOP_H_