]> git.saurik.com Git - wxWidgets.git/blame - include/wx/osx/core/evtloop.h
update project files
[wxWidgets.git] / include / wx / osx / core / evtloop.h
CommitLineData
7ce6da52
VZ
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
15DECLARE_WXOSX_OPAQUE_CFREF( CFRunLoop );
16DECLARE_WXOSX_OPAQUE_CFREF( CFRunLoopObserver );
17
754afd10 18class WXDLLIMPEXP_FWD_BASE wxCFEventLoopPauseIdleEvents;
7ce6da52
VZ
19
20class WXDLLIMPEXP_BASE wxCFEventLoop : public wxEventLoopBase
21{
22 friend class wxCFEventLoopPauseIdleEvents;
23public:
24 wxCFEventLoop();
25 virtual ~wxCFEventLoop();
26
27 // enters a loop calling OnNextIteration(), Pending() and Dispatch() and
28 // terminating when Exit() is called
29 virtual int Run();
30
31 // sets the "should exit" flag and wakes up the loop so that it terminates
32 // soon
33 virtual void Exit(int rc = 0);
34
35 // return true if any events are available
36 virtual bool Pending() const;
37
38 // dispatch a single event, return false if we should exit from the loop
39 virtual bool Dispatch();
40
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);
45
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();
49
50 virtual bool YieldFor(long eventsToProcess);
51
52#if wxUSE_EVENTLOOP_SOURCE
53 virtual wxEventLoopSource *
54 AddSourceForFD(int fd, wxEventLoopSourceHandler *handler, int flags);
55#endif // wxUSE_EVENTLOOP_SOURCE
56
19736e64 57 bool ShouldProcessIdleEvents() const { return m_processIdleEvents ; }
d60957aa
SC
58
59#if wxUSE_UIACTIONSIMULATOR
60 // notifies Yield and Dispatch to wait for at least one event before
61 // returning, this is necessary, because the synthesized events need to be
62 // converted by the OS before being available on the native event queue
63 void SetShouldWaitForEvent(bool should) { m_shouldWaitForEvent = should; }
64#endif
7ce6da52
VZ
65protected:
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 DoRun();
81
82 virtual void DoStop();
83
84 // should we exit the loop?
85 bool m_shouldExit;
86
87 // the loop exit code
88 int m_exitcode;
89
90 // cfrunloop
91 CFRunLoopRef m_runLoop;
92
93 // common modes runloop observer
94 CFRunLoopObserverRef m_commonModeRunLoopObserver;
95
96 // default mode runloop observer
97 CFRunLoopObserverRef m_defaultModeRunLoopObserver;
98
99 // set to false to avoid idling at unexpected moments - eg when having native message boxes
100 bool m_processIdleEvents;
101
d60957aa
SC
102#if wxUSE_UIACTIONSIMULATOR
103 bool m_shouldWaitForEvent;
104#endif
7ce6da52
VZ
105private:
106 // process all already pending events and dispatch a new one (blocking
107 // until it appears in the event queue if necessary)
108 //
109 // returns the return value of DoDispatchTimeout()
110 int DoProcessEvents();
111
112 wxDECLARE_NO_COPY_CLASS(wxCFEventLoop);
113};
114
115class WXDLLIMPEXP_BASE wxCFEventLoopPauseIdleEvents : public wxObject
116{
117public:
118 wxCFEventLoopPauseIdleEvents();
119 virtual ~wxCFEventLoopPauseIdleEvents();
19736e64
SC
120private:
121 bool m_formerState;
7ce6da52
VZ
122};
123
124#endif // _WX_OSX_EVTLOOP_H_