]> git.saurik.com Git - wxWidgets.git/blob - include/wx/osx/evtloop.h
streamlining OSX event support second step, moving pending and idle event handling...
[wxWidgets.git] / include / wx / osx / evtloop.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/osx/evtloop.h
3 // Purpose: simply forwards to wx/mac/carbon/evtloop.h for consistency with
4 // the other Mac headers
5 // Author: Vadim Zeitlin
6 // Modified by:
7 // Created: 2006-01-12
8 // RCS-ID: $Id$
9 // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
10 // Licence: wxWindows licence
11 ///////////////////////////////////////////////////////////////////////////////
12
13 #ifndef _WX_OSX_EVTLOOP_H_
14 #define _WX_OSX_EVTLOOP_H_
15
16 DECLARE_WXOSX_OPAQUE_CFREF( CFRunLoop );
17 DECLARE_WXOSX_OPAQUE_CFREF( CFRunLoopObserver );
18
19 class WXDLLIMPEXP_BASE wxCFEventLoop : public wxEventLoopBase
20 {
21 public:
22 wxCFEventLoop();
23 virtual ~wxCFEventLoop();
24
25 // enters a loop calling OnNextIteration(), Pending() and Dispatch() and
26 // terminating when Exit() is called
27 virtual int Run();
28
29 // sets the "should exit" flag and wakes up the loop so that it terminates
30 // soon
31 virtual void Exit(int rc = 0);
32
33 // return true if any events are available
34 virtual bool Pending() const;
35
36 // dispatch a single event, return false if we should exit from the loop
37 virtual bool Dispatch();
38
39 // same as Dispatch() but doesn't wait for longer than the specified (in
40 // ms) timeout, return true if an event was processed, false if we should
41 // exit the loop or -1 if timeout expired
42 virtual int DispatchTimeout(unsigned long timeout);
43
44 // implement this to wake up the loop: usually done by posting a dummy event
45 // to it (can be called from non main thread)
46 virtual void WakeUp();
47
48 virtual bool YieldFor(long eventsToProcess);
49
50 #if wxUSE_EVENTLOOP_SOURCE
51 virtual wxEventLoopSource *
52 AddSourceForFD(int fd, wxEventLoopSourceHandler *handler, int flags);
53 #endif // wxUSE_EVENTLOOP_SOURCE
54
55 void ObserverCallBack(CFRunLoopObserverRef observer, int activity);
56
57 protected:
58 // get the currently executing CFRunLoop
59 virtual CFRunLoopRef CFGetCurrentRunLoop() const;
60
61 virtual int DoDispatchTimeout(unsigned long timeout);
62
63 // should we exit the loop?
64 bool m_shouldExit;
65
66 // the loop exit code
67 int m_exitcode;
68
69 // runloop observer
70 CFRunLoopObserverRef m_runLoopObserver;
71
72 private:
73 // process all already pending events and dispatch a new one (blocking
74 // until it appears in the event queue if necessary)
75 //
76 // returns the return value of DoDispatchTimeout()
77 int DoProcessEvents();
78
79 };
80
81 #if wxUSE_GUI
82 #ifdef __WXOSX_COCOA__
83 #include "wx/osx/cocoa/evtloop.h"
84 #else
85 #include "wx/osx/carbon/evtloop.h"
86 #endif
87 #endif // wxUSE_GUI
88
89 #endif // _WX_OSX_EVTLOOP_H_