Wx::Event

From WxPerl Wiki
Jump to: navigation, search

An event is an object holding information about an event. It is passed to an event-handler function or method.

For more information about events, see the handling overview at the (C++-oriented) wxWidgets documentation site.

In wxPerl, custom event classes should be derived from Wx::PlEvent and Wx::PlCommandEvent.

Beginners should focus on the GetEventObject, GetEventType, and Skip methods; most of the others are for more advanced uses, such as generating custom events.

Inheritance

Wx::Event derives from Wx::Object.

See also

Wx::CommandEvent, Wx::MouseEvent

Constructor

new

$ev = Wx::Event->new($id, $type);

Application code should never have to use this directly.

Methods

Clone

$copy = $ev->Clone;

Returns a copy of the event.

The following comes from the C++-oriented wxWidgets documentation at http://docs.wxwidgets.org; I don't know to what extent it applies to Perl classes that are derived from Wx::PlEvent. Anyone who knows more is asked to please update this section.

Any event that is posted to the wxWidgets event system for later action (via wxEvtHandler::AddPendingEvent or wxPostEvent) must implement this method. All wxWidgets events fully implement this method, but any derived events implemented by the user should also implement this method just in case they (or some event derived from them) are ever posted.
All wxWidgets events implement a copy constructor, so the easiest way of implementing the Clone function is to implement a copy constructor for a new event (call it MyEvent) and then define the Clone function like this:
wxEvent *Clone(void) const { return new MyEvent(*this); }


GetEventObject

$obj = $ev->GetEventObject();

Returns the object (usually a window) associated with the event, if any.

GetEventType

$type = $ev->GetEventType();

Returns the identifier of the given event type, such as wxEVT_COMMAND_BUTTON_CLICKED.

GetId

$int = $ev->GetId();

Returns the identifier associated with this event, such as a button command id.

GetSkipped

$bool = $ev->GetSkipped();

Returns true if the event handler should be skipped, false otherwise.

GetTimestamp

$long = $ev->GetTimestamp();

Gets the timestamp for the event. The timestamp is the time in milliseconds since some fixed moment (not necessarily the standard Unix Epoch, so only differences between the timestamps and not their absolute values usually make sense).

IsCommandEvent

$bool = $ev->IsCommandEvent();

Returns true if the event is or is derived from Wx::CommandEvent else it returns false. Note: Exists only for optimization purposes.

ResumePropagation

$ev->ResumePropagation($propagation_level);

Sets the propagation level to the given value (for example returned from an earlier call to StopPropagation).

SetEventObject

$ev->SetEventObject($object);

Sets the originating object.

SetEventType

$ev->SetEventType($type);

Sets the event type.

SetId

$ev->SetId($id);

Sets the identifier associated with this event, such as a button command id.

SetTimestamp

$ev->SetTimestamp($timeStamp);

Sets the timestamp (a long integer) for the event.

ShouldPropagate

$bool = $ev->ShouldPropagate();

Test if this event should be propagated or not, i.e. if the propagation level is currently greater than 0.

Skip

$ev->Skip($skip);

This method can be used inside an event handler to control whether further event handlers bound to this event will be called after the current one returns.

If $skip is true or omitted, the event processing system continues searching for a further handler function for this event, even though it has been processed already in the current handler.

If $skip is false, or if Skip() is never called, the event will not be processed any more after the current event handler.

In general, it is recommended to skip all non-command events to allow the default handling to take place. The command events are, however, normally not skipped, as usually a single command such as a button click or menu item selection must only be processed by one handler.

StopPropagation

$int = $ev->StopPropagation();

Stop the event from propagating to its parent window.

Returns the old propagation level value which may be later passed to ResumePropagation to allow propagating the event again.