Version: 2.9.4
Public Member Functions | Static Public Member Functions | Protected Member Functions
wxEventLoopBase Class Reference

#include </home/zeitlin/src/wx/github/interface/wx/evtloop.h>

Inheritance diagram for wxEventLoopBase:

Detailed Description

Base class for all event loop implementations.

An event loop is a class which queries the queue of native events sent to the wxWidgets application and dispatches them to the appropriate wxEvtHandlers.

An object of this class is created by wxAppTraits::CreateEventLoop() and used by wxApp to run the main application event loop. Temporary event loops are usually created by wxDialog::ShowModal().

You can create your own event loop if you need, provided that you restore the main event loop once yours is destroyed (see wxEventLoopActivator).

Library:  wxBase
Category:  Application and Process Management
参照:
wxApp, wxEventLoopActivator

Public Member Functions

bool IsMain () const
 Returns true if this is the main loop executed by wxApp::OnRun().
Dispatch and processing
virtual int Run ()=0
 Start the event loop, return the exit code when it is finished.
bool IsRunning () const
 Return true if this event loop is currently running.
virtual bool IsOk () const
 Use this to check whether the event loop was successfully created before using it.
virtual void Exit (int rc=0)=0
 Exit from the loop with the given exit code.
virtual bool Pending () const =0
 Return true if any events are available.
virtual bool Dispatch ()=0
 Dispatches the next event in the windowing system event queue.
virtual int DispatchTimeout (unsigned long timeout)=0
 Dispatch an event but not wait longer than the specified timeout for it.
virtual void WakeUp ()=0
 Called by wxWidgets to wake up the event loop even if it is currently blocked inside Dispatch().
Idle handling
virtual void WakeUpIdle ()
 Makes sure that idle events are sent again.
virtual bool ProcessIdle ()
 This virtual function is called when the application becomes idle and normally just sends wxIdleEvent to all interested parties.
Yield-related hooks
virtual bool IsYielding () const
 Returns true if called from inside Yield() or from inside YieldFor().
bool Yield (bool onlyIfNeeded=false)
 Yields control to pending messages in the windowing system.
bool YieldFor (long eventsToProcess)
 Works like Yield() with onlyIfNeeded == true, except that it allows the caller to specify a mask of the wxEventCategory values which indicates which events should be processed and which should instead be "delayed" (i.e.
virtual bool IsEventAllowedInsideYield (wxEventCategory cat) const
 Returns true if the given event category is allowed inside a YieldFor() call (i.e.

Static Public Member Functions

static wxEventLoopBaseGetActive ()
 Return the currently active (running) event loop.
static void SetActive (wxEventLoopBase *loop)
 Set currently active (running) event loop.

Protected Member Functions

virtual void OnExit ()
 This function is called before the event loop terminates, whether this happens normally (because of Exit() call) or abnormally (because of an exception thrown from inside the loop).

List of all members.


Member Function Documentation

virtual bool wxEventLoopBase::Dispatch ( ) [pure virtual]

Dispatches the next event in the windowing system event queue.

Blocks until an event appears if there are none currently (use Pending() if this is not wanted).

This can be used for programming event loops, e.g.

        while (evtloop->Pending())
            evtloop->Dispatch();
Returns:
false if the event loop should stop and true otherwise.
参照:
Pending(), wxEventLoopBase
virtual int wxEventLoopBase::DispatchTimeout ( unsigned long  timeout) [pure virtual]

Dispatch an event but not wait longer than the specified timeout for it.

If an event is received before the specified timeout expires, it is processed and the function returns 1 normally or 0 if the event loop should quite. Otherwise, i.e. if the timeout expires, the functions returns -1 without processing any events.

Parameters:
timeoutThe maximal time to wait for the events in milliseconds.
Returns:
1 if an event was processed, 0 if the event loop should quit or -1 if the timeout expired.
virtual void wxEventLoopBase::Exit ( int  rc = 0) [pure virtual]

Exit from the loop with the given exit code.

static wxEventLoopBase* wxEventLoopBase::GetActive ( ) [static]

Return the currently active (running) event loop.

May return NULL if there is no active event loop (e.g. during application startup or shutdown).

virtual bool wxEventLoopBase::IsEventAllowedInsideYield ( wxEventCategory  cat) const [virtual]

Returns true if the given event category is allowed inside a YieldFor() call (i.e.

compares the given category against the last mask passed to YieldFor()).

参照:
wxEvent::GetEventCategory
bool wxEventLoopBase::IsMain ( ) const

Returns true if this is the main loop executed by wxApp::OnRun().

virtual bool wxEventLoopBase::IsOk ( ) const [virtual]

Use this to check whether the event loop was successfully created before using it.

bool wxEventLoopBase::IsRunning ( ) const

Return true if this event loop is currently running.

Notice that even if this event loop hasn't terminated yet but has just spawned a nested (e.g. modal) event loop, this method would return false.

virtual bool wxEventLoopBase::IsYielding ( ) const [virtual]

Returns true if called from inside Yield() or from inside YieldFor().

virtual void wxEventLoopBase::OnExit ( ) [protected, virtual]

This function is called before the event loop terminates, whether this happens normally (because of Exit() call) or abnormally (because of an exception thrown from inside the loop).

The default implementation calls wxAppConsole::OnEventLoopExit.

virtual bool wxEventLoopBase::Pending ( ) const [pure virtual]

Return true if any events are available.

If this method returns true, calling Dispatch() will not block.

virtual bool wxEventLoopBase::ProcessIdle ( ) [virtual]

This virtual function is called when the application becomes idle and normally just sends wxIdleEvent to all interested parties.

It should return true if more idle events are needed, false if not.

virtual int wxEventLoopBase::Run ( ) [pure virtual]

Start the event loop, return the exit code when it is finished.

Logically, this method calls Dispatch() in a loop until it returns false and also takes care of generating idle events during each loop iteration. However not all implementations of this class really implement it like this (e.g. wxGTK does not) so you shouldn't rely on Dispatch() being called from inside this function.

Returns:
The argument passed to Exit() which terminated this event loop.
static void wxEventLoopBase::SetActive ( wxEventLoopBase loop) [static]

Set currently active (running) event loop.

Called by wxEventLoopActivator, use an instance of this class instead of calling this method directly to ensure that the previously active event loop is restored.

Results in a call to wxAppConsole::OnEventLoopEnter.

virtual void wxEventLoopBase::WakeUp ( ) [pure virtual]

Called by wxWidgets to wake up the event loop even if it is currently blocked inside Dispatch().

virtual void wxEventLoopBase::WakeUpIdle ( ) [virtual]

Makes sure that idle events are sent again.

bool wxEventLoopBase::Yield ( bool  onlyIfNeeded = false)

Yields control to pending messages in the windowing system.

This can be useful, for example, when a time-consuming process writes to a text window. Without an occasional yield, the text window will not be updated properly, and on systems with cooperative multitasking, such as Windows 3.1 other processes will not respond.

Caution should be exercised, however, since yielding may allow the user to perform actions which are not compatible with the current task. Disabling menu items or whole menus during processing can avoid unwanted reentrance of code: see wxSafeYield for a better function. You can avoid unwanted reentrancies also using IsYielding().

Note that Yield() will not flush the message logs. This is intentional as calling Yield() is usually done to quickly update the screen and popping up a message box dialog may be undesirable. If you do wish to flush the log messages immediately (otherwise it will be done during the next idle loop iteration), call wxLog::FlushActive.

Calling Yield() recursively is normally an error and an assert failure is raised in debug build if such situation is detected. However if the onlyIfNeeded parameter is true, the method will just silently return false instead.

bool wxEventLoopBase::YieldFor ( long  eventsToProcess)

Works like Yield() with onlyIfNeeded == true, except that it allows the caller to specify a mask of the wxEventCategory values which indicates which events should be processed and which should instead be "delayed" (i.e.

processed by the main loop later).

Note that this is a safer alternative to Yield() since it ensures that only the events you're interested to will be processed; i.e. this method helps to avoid unwanted reentrancies.

Note that currently only wxMSW and wxGTK do support selective yield of native events coming from the underlying GUI toolkit. wxWidgets events posted using wxEvtHandler::AddPendingEvent or wxEvtHandler::QueueEvent are instead selectively processed by all ports.

参照:
wxEvent::GetEventCategory
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines