]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/evtloop.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxEventLoop and related classes
4 // Author: Vadim Zeitlin
5 // Copyright: (C) 2008 Vadim Zeitlin
7 // Licence: wxWindows license
8 /////////////////////////////////////////////////////////////////////////////
11 @class wxEventLoopBase
13 Base class for all event loop implementations.
15 An object of this class is created by wxAppTraits::CreateEventLoop() and
16 used by wxApp to run the main application event loop.
19 @category{appmanagement}
27 Return the currently active (running) event loop.
29 May return @NULL if there is no active event loop (e.g. during
30 application startup or shutdown).
32 static wxEventLoopBase
*GetActive();
35 Set currently active (running) event loop.
37 Called by wxEventLoopActivator, use an instance of this class instead
38 of calling this method directly to ensure that the previously active
39 event loop is restored.
41 static void SetActive(wxEventLoopBase
* loop
);
45 Use this to check whether the event loop was successfully created
48 virtual bool IsOk() const;
51 Start the event loop, return the exit code when it is finished.
53 Logically, this method calls Dispatch() in a loop until it returns
54 @false and also takes care of generating idle events during each loop
55 iteration. However not all implementations of this class really
56 implement it like this (e.g. wxGTK does not) so you shouldn't rely on
57 Dispatch() being called from inside this function.
59 @return The argument passed to Exit() which terminated this event loop.
61 virtual int Run() = 0;
64 Exit from the loop with the given exit code.
66 virtual void Exit(int rc
= 0) = 0;
69 Return true if any events are available.
71 If this method returns @true, calling Dispatch() will not block.
73 virtual bool Pending() const = 0;
76 Dispatch a single event.
78 If there are currently no events in the queue, blocks until an event
81 @return @false only if the event loop should terminate.
83 virtual bool Dispatch() = 0;
86 Dispatch an event but not wait longer than the specified timeout for
89 If an event is received before the specified @a timeout expires, it is
90 processed and the function returns 1 normally or 0 if the event loop
91 should quite. Otherwise, i.e. if the timeout expires, the functions
92 returns -1 without processing any events.
95 The maximal time to wait for the events in milliseconds.
98 1 if an event was processed, 0 if the event loop should quit or -1
99 if the timeout expired.
101 virtual int DispatchTimeout(unsigned long timeout
) = 0;
104 Return true if this event loop is currently running.
106 Notice that even if this event loop hasn't terminated yet but has just
107 spawned a nested (e.g. modal) event loop, this method would return
110 bool IsRunning() const;
113 Called by wxWidgets to wake up the event loop even if it is currently
114 blocked inside Dispatch().
116 virtual void WakeUp() = 0;
120 This function is called before the event loop terminates, whether this
121 happens normally (because of Exit() call) or abnormally (because of an
122 exception thrown from inside the loop).
124 Default version does nothing.
126 virtual void OnExit();
130 @class wxEventLoopActivator
132 Makes an event loop temporarily active.
134 This class is used to make the event loop active during its life-time,
137 class MyEventLoop : public wxEventLoopBase { ... };
142 wxEventLoopActivator activate(&loop);
145 } // the previously active event loop restored here
149 @category{appmanagement}
153 class wxEventLoopActivator
157 Makes the loop passed as the parameter currently active.
159 This saves the current return value of wxEventLoopBase::GetActive() and
160 then calls wxEventLoopBase::SetActive() with the given @a loop.
162 wxEventLoopActivator(wxEventLoopBase
*loop
);
165 Restores the previously active event loop stored by the constructor.
167 ~wxEventLoopActivator();