Below are a number of functions/macros used with wxWidgets event-handling system.
Related class group: Events
Defines | |
#define | DEFINE_EVENT_TYPE(name) const wxEventType name = wxNewEventType(); |
Initializes a new event type using wxNewEventType(). | |
#define | wxDEFINE_EVENT(name, cls) const wxEventTypeTag< cls > name(wxNewEventType()) |
Define a new event type associated with the specified event class. | |
#define | wxDECLARE_EVENT(name, cls) wxDECLARE_EXPORTED_EVENT(wxEMPTY_PARAMETER_VALUE, name, cls) |
Declares a custom event type. | |
#define | wxDECLARE_EXPORTED_EVENT(expdecl, name, cls) extern const expdecl wxEventTypeTag< cls > name; |
Variant of wxDECLARE_EVENT() used for event types defined inside a shared library. | |
#define | wxEVENT_HANDLER_CAST(functype, func) (&func) |
Helper macro for definition of custom event table macros. | |
#define | wx__DECLARE_EVT1(evt, id, fn) wx__DECLARE_EVT2(evt, id, wxID_ANY, fn) |
This macro is used to define event table macros for handling custom events. | |
#define | wx__DECLARE_EVT2(evt, id1, id2, fn) DECLARE_EVENT_TABLE_ENTRY(evt, id1, id2, fn, NULL), |
Generalized version of the wx__DECLARE_EVT1() macro taking a range of IDs instead of a single one. | |
#define | wx__DECLARE_EVT0(evt, fn) wx__DECLARE_EVT1(evt, wxID_ANY, fn) |
Simplified version of the wx__DECLARE_EVT1() macro, to be used when the event type must be handled regardless of the ID associated with the specific event instances. | |
#define | DECLARE_EVENT_TABLE() |
Use this macro inside a class declaration to declare a static event table for that class. | |
#define | BEGIN_EVENT_TABLE(theClass, baseClass) |
Use this macro in a source file to start listing static event handlers for a specific class. | |
#define | END_EVENT_TABLE() |
Use this macro in a source file to end listing static event handlers for a specific class. | |
Typedefs | |
typedef int | wxEventType |
A value uniquely identifying the type of the event. | |
Functions | |
wxEventType | wxNewEventType () |
Generates a new unique event type. | |
void | wxPostEvent (wxEvtHandler *dest, const wxEvent &event) |
In a GUI application, this function posts event to the specified dest object using wxEvtHandler::AddPendingEvent(). | |
void | wxQueueEvent (wxEvtHandler *dest, wxEvent *event) |
Queue an event for processing on the given object. | |
Variables | |
wxEventType | wxEVT_NULL |
A special event type usually used to indicate that some wxEvent has yet no type assigned. |
#define BEGIN_EVENT_TABLE | ( | theClass, | |||
baseClass | ) |
Use this macro in a source file to start listing static event handlers for a specific class.
Use END_EVENT_TABLE() to terminate the event-declaration block.
#define DECLARE_EVENT_TABLE | ( | ) |
Use this macro inside a class declaration to declare a static event table for that class.
In the implementation file you'll need to use the BEGIN_EVENT_TABLE() and the END_EVENT_TABLE() macros, plus some additional EVT_xxx
macro to capture events.
#define DEFINE_EVENT_TYPE | ( | name | ) | const wxEventType name = wxNewEventType(); |
Initializes a new event type using wxNewEventType().
#define END_EVENT_TABLE | ( | ) |
Use this macro in a source file to end listing static event handlers for a specific class.
Use BEGIN_EVENT_TABLE() to start the event-declaration block.
#define wx__DECLARE_EVT0 | ( | evt, | |||
fn | ) | wx__DECLARE_EVT1(evt, wxID_ANY, fn) |
Simplified version of the wx__DECLARE_EVT1() macro, to be used when the event type must be handled regardless of the ID associated with the specific event instances.
#define wx__DECLARE_EVT1 | ( | evt, | |||
id, | |||||
fn | ) | wx__DECLARE_EVT2(evt, id, wxID_ANY, fn) |
This macro is used to define event table macros for handling custom events.
Example of use:
class MyEvent : public wxEvent { ... }; // note that this is not necessary unless using old compilers: for the // reasonably new ones just use &func instead of MyEventHandler(func) typedef void (wxEvtHandler::*MyEventFunction)(MyEvent&); #define MyEventHandler(func) wxEVENT_HANDLER_CAST(MyEventFunction, func) wxDEFINE_EVENT(MY_EVENT_TYPE, MyEvent); #define EVT_MY(id, func) \ wx__DECLARE_EVT1(MY_EVENT_TYPE, id, MyEventHandler(func)) ... BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MY(wxID_ANY, MyFrame::OnMyEvent) END_EVENT_TABLE()
evt | The event type to handle. | |
id | The identifier of events to handle. | |
fn | The event handler method. |
#define wx__DECLARE_EVT2 | ( | evt, | |||
id1, | |||||
id2, | |||||
fn | ) | DECLARE_EVENT_TABLE_ENTRY(evt, id1, id2, fn, NULL), |
Generalized version of the wx__DECLARE_EVT1() macro taking a range of IDs instead of a single one.
Argument id1 is the first identifier of the range, id2 is the second identifier of the range.
#define wxDECLARE_EVENT | ( | name, | |||
cls | ) | wxDECLARE_EXPORTED_EVENT(wxEMPTY_PARAMETER_VALUE, name, cls) |
Declares a custom event type.
This macro declares a variable called name which must be defined elsewhere using wxDEFINE_EVENT().
The class cls must be the wxEvent-derived class associated with the events of this type and its full declaration must be visible from the point of use of this macro.
For example:
wxDECLARE_EVENT(MY_COMMAND_EVENT, wxCommandEvent); class MyCustomEvent : public wxEvent { ... }; wxDECLARE_EVENT(MY_CUSTOM_EVENT, MyCustomEvent);
#define wxDECLARE_EXPORTED_EVENT | ( | expdecl, | |||
name, | |||||
cls | ) | extern const expdecl wxEventTypeTag< cls > name; |
Variant of wxDECLARE_EVENT() used for event types defined inside a shared library.
This is mostly used by wxWidgets internally, e.g.
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEvent)
#define wxDEFINE_EVENT | ( | name, | |||
cls | ) | const wxEventTypeTag< cls > name(wxNewEventType()) |
Define a new event type associated with the specified event class.
This macro defines a new unique event type name associated with the event class cls.
For example:
wxDEFINE_EVENT(MY_COMMAND_EVENT, wxCommandEvent); class MyCustomEvent : public wxEvent { ... }; wxDEFINE_EVENT(MY_CUSTOM_EVENT, MyCustomEvent);
#define wxEVENT_HANDLER_CAST | ( | functype, | |||
func | ) | (&func) |
Helper macro for definition of custom event table macros.
This macro must only be used if wxEVENTS_COMPATIBILITY_2_8 is 1, otherwise it is better and more clear to just use the address of the function directly as this is all this macro does in this case. However it needs to explicitly cast func to functype, which is the type of wxEvtHandler member function taking the custom event argument when wxEVENTS_COMPATIBILITY_2_8 is 0.
See wx__DECLARE_EVT0 for an example of use.
typedef int wxEventType |
A value uniquely identifying the type of the event.
The values of this type should only be created using wxNewEventType().
See the macro DEFINE_EVENT_TYPE() for more info.
wxEventType wxNewEventType | ( | ) |
Generates a new unique event type.
Usually this function is only used by wxDEFINE_EVENT() and not called directly.
void wxPostEvent | ( | wxEvtHandler * | dest, | |
const wxEvent & | event | |||
) |
In a GUI application, this function posts event to the specified dest object using wxEvtHandler::AddPendingEvent().
Otherwise, it dispatches event immediately using wxEvtHandler::ProcessEvent(). See the respective documentation for details (and caveats). Because of limitation of wxEvtHandler::AddPendingEvent() this function is not thread-safe for event objects having wxString fields, use wxQueueEvent() instead.
Include file:
#include <wx/event.h>
void wxQueueEvent | ( | wxEvtHandler * | dest, | |
wxEvent * | event | |||
) |
Queue an event for processing on the given object.
This is a wrapper around wxEvtHandler::QueueEvent(), see its documentation for more details.
Include file:
#include <wx/event.h>
dest | The object to queue the event on, can't be NULL . | |
event | The heap-allocated and non-NULL event to queue, the function takes ownership of it. |
A special event type usually used to indicate that some wxEvent has yet no type assigned.
![]() |
[ top ] |