]> git.saurik.com Git - wxWidgets.git/blame - include/wx/osx/core/evtloop.h
wxMessageBox off the main thread lost result code.
[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
7ce6da52
VZ
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
14DECLARE_WXOSX_OPAQUE_CFREF( CFRunLoop );
15DECLARE_WXOSX_OPAQUE_CFREF( CFRunLoopObserver );
16
754afd10 17class WXDLLIMPEXP_FWD_BASE wxCFEventLoopPauseIdleEvents;
7ce6da52
VZ
18
19class WXDLLIMPEXP_BASE wxCFEventLoop : public wxEventLoopBase
20{
21 friend class wxCFEventLoopPauseIdleEvents;
22public:
23 wxCFEventLoop();
24 virtual ~wxCFEventLoop();
25
7ce6da52
VZ
26 // sets the "should exit" flag and wakes up the loop so that it terminates
27 // soon
d3ad22bd 28 virtual void ScheduleExit(int rc = 0);
7ce6da52
VZ
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
19736e64 47 bool ShouldProcessIdleEvents() const { return m_processIdleEvents ; }
d60957aa
SC
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
7ce6da52 55protected:
c738d187
VZ
56 // enters a loop calling OnNextIteration(), Pending() and Dispatch() and
57 // terminating when Exit() is called
58 virtual int DoRun();
59
7ce6da52
VZ
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
8d40c05f
VZ
74 virtual void OSXDoRun();
75 virtual void OSXDoStop();
7ce6da52 76
7ce6da52
VZ
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
d60957aa
SC
92#if wxUSE_UIACTIONSIMULATOR
93 bool m_shouldWaitForEvent;
94#endif
7ce6da52
VZ
95private:
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
105class WXDLLIMPEXP_BASE wxCFEventLoopPauseIdleEvents : public wxObject
106{
107public:
108 wxCFEventLoopPauseIdleEvents();
109 virtual ~wxCFEventLoopPauseIdleEvents();
19736e64
SC
110private:
111 bool m_formerState;
7ce6da52
VZ
112};
113
114#endif // _WX_OSX_EVTLOOP_H_