]> git.saurik.com Git - wxWidgets.git/blame - include/wx/osx/core/evtloop.h
Only return -1,0,1 from wxXmlResource::CompareVersion().
[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
7ce6da52
VZ
27 // sets the "should exit" flag and wakes up the loop so that it terminates
28 // soon
d3ad22bd 29 virtual void ScheduleExit(int rc = 0);
7ce6da52
VZ
30
31 // return true if any events are available
32 virtual bool Pending() const;
33
34 // dispatch a single event, return false if we should exit from the loop
35 virtual bool Dispatch();
36
37 // same as Dispatch() but doesn't wait for longer than the specified (in
38 // ms) timeout, return true if an event was processed, false if we should
39 // exit the loop or -1 if timeout expired
40 virtual int DispatchTimeout(unsigned long timeout);
41
42 // implement this to wake up the loop: usually done by posting a dummy event
43 // to it (can be called from non main thread)
44 virtual void WakeUp();
45
46 virtual bool YieldFor(long eventsToProcess);
47
19736e64 48 bool ShouldProcessIdleEvents() const { return m_processIdleEvents ; }
d60957aa
SC
49
50#if wxUSE_UIACTIONSIMULATOR
51 // notifies Yield and Dispatch to wait for at least one event before
52 // returning, this is necessary, because the synthesized events need to be
53 // converted by the OS before being available on the native event queue
54 void SetShouldWaitForEvent(bool should) { m_shouldWaitForEvent = should; }
55#endif
7ce6da52 56protected:
c738d187
VZ
57 // enters a loop calling OnNextIteration(), Pending() and Dispatch() and
58 // terminating when Exit() is called
59 virtual int DoRun();
60
7ce6da52
VZ
61 void CommonModeObserverCallBack(CFRunLoopObserverRef observer, int activity);
62 void DefaultModeObserverCallBack(CFRunLoopObserverRef observer, int activity);
63
64 // set to false to avoid idling at unexpected moments - eg when having native message boxes
65 void SetProcessIdleEvents(bool process) { m_processIdleEvents = process; }
66
67 static void OSXCommonModeObserverCallBack(CFRunLoopObserverRef observer, int activity, void *info);
68 static void OSXDefaultModeObserverCallBack(CFRunLoopObserverRef observer, int activity, void *info);
69
70 // get the currently executing CFRunLoop
71 virtual CFRunLoopRef CFGetCurrentRunLoop() const;
72
73 virtual int DoDispatchTimeout(unsigned long timeout);
74
8d40c05f
VZ
75 virtual void OSXDoRun();
76 virtual void OSXDoStop();
7ce6da52 77
7ce6da52
VZ
78 // the loop exit code
79 int m_exitcode;
80
81 // cfrunloop
82 CFRunLoopRef m_runLoop;
83
84 // common modes runloop observer
85 CFRunLoopObserverRef m_commonModeRunLoopObserver;
86
87 // default mode runloop observer
88 CFRunLoopObserverRef m_defaultModeRunLoopObserver;
89
90 // set to false to avoid idling at unexpected moments - eg when having native message boxes
91 bool m_processIdleEvents;
92
d60957aa
SC
93#if wxUSE_UIACTIONSIMULATOR
94 bool m_shouldWaitForEvent;
95#endif
7ce6da52
VZ
96private:
97 // process all already pending events and dispatch a new one (blocking
98 // until it appears in the event queue if necessary)
99 //
100 // returns the return value of DoDispatchTimeout()
101 int DoProcessEvents();
102
103 wxDECLARE_NO_COPY_CLASS(wxCFEventLoop);
104};
105
106class WXDLLIMPEXP_BASE wxCFEventLoopPauseIdleEvents : public wxObject
107{
108public:
109 wxCFEventLoopPauseIdleEvents();
110 virtual ~wxCFEventLoopPauseIdleEvents();
19736e64
SC
111private:
112 bool m_formerState;
7ce6da52
VZ
113};
114
115#endif // _WX_OSX_EVTLOOP_H_