1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/osx/core/evtloop.h
3 // Purpose: CoreFoundation-based event loop
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_OSX_CORE_EVTLOOP_H_
13 #define _WX_OSX_CORE_EVTLOOP_H_
15 DECLARE_WXOSX_OPAQUE_CFREF( CFRunLoop
);
16 DECLARE_WXOSX_OPAQUE_CFREF( CFRunLoopObserver
);
18 class WXDLLIMPEXP_FWD_BASE wxCFEventLoopPauseIdleEvents
;
20 class WXDLLIMPEXP_BASE wxCFEventLoop
: public wxEventLoopBase
22 friend class wxCFEventLoopPauseIdleEvents
;
25 virtual ~wxCFEventLoop();
27 // enters a loop calling OnNextIteration(), Pending() and Dispatch() and
28 // terminating when Exit() is called
31 // sets the "should exit" flag and wakes up the loop so that it terminates
33 virtual void Exit(int rc
= 0);
35 // return true if any events are available
36 virtual bool Pending() const;
38 // dispatch a single event, return false if we should exit from the loop
39 virtual bool Dispatch();
41 // same as Dispatch() but doesn't wait for longer than the specified (in
42 // ms) timeout, return true if an event was processed, false if we should
43 // exit the loop or -1 if timeout expired
44 virtual int DispatchTimeout(unsigned long timeout
);
46 // implement this to wake up the loop: usually done by posting a dummy event
47 // to it (can be called from non main thread)
48 virtual void WakeUp();
50 virtual bool YieldFor(long eventsToProcess
);
52 #if wxUSE_EVENTLOOP_SOURCE
53 virtual wxEventLoopSource
*
54 AddSourceForFD(int fd
, wxEventLoopSourceHandler
*handler
, int flags
);
55 #endif // wxUSE_EVENTLOOP_SOURCE
57 bool ShouldProcessIdleEvents() const { return m_processIdleEvents
; }
59 void CommonModeObserverCallBack(CFRunLoopObserverRef observer
, int activity
);
60 void DefaultModeObserverCallBack(CFRunLoopObserverRef observer
, int activity
);
62 // set to false to avoid idling at unexpected moments - eg when having native message boxes
63 void SetProcessIdleEvents(bool process
) { m_processIdleEvents
= process
; }
65 static void OSXCommonModeObserverCallBack(CFRunLoopObserverRef observer
, int activity
, void *info
);
66 static void OSXDefaultModeObserverCallBack(CFRunLoopObserverRef observer
, int activity
, void *info
);
68 // get the currently executing CFRunLoop
69 virtual CFRunLoopRef
CFGetCurrentRunLoop() const;
71 virtual int DoDispatchTimeout(unsigned long timeout
);
75 virtual void DoStop();
77 // should we exit the loop?
84 CFRunLoopRef m_runLoop
;
86 // common modes runloop observer
87 CFRunLoopObserverRef m_commonModeRunLoopObserver
;
89 // default mode runloop observer
90 CFRunLoopObserverRef m_defaultModeRunLoopObserver
;
92 // set to false to avoid idling at unexpected moments - eg when having native message boxes
93 bool m_processIdleEvents
;
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_