#include </home/zeitlin/src/wx/github/interface/wx/event.h>
ウィンドウから送信されるベントを処理可能なクラス。
wxWindow is (and therefore all window classes are) derived from this class.
When events are received, wxEvtHandler invokes the method listed in the event table using itself as the object. When using multiple inheritance it is imperative that the wxEvtHandler(-derived) class is the first class inherited such that the this
pointer for the overall object will be identical to the this
pointer of the wxEvtHandler portion.
Public Member Functions | |
wxEvtHandler () | |
Constructor. | |
virtual | ~wxEvtHandler () |
Destructor. | |
Event queuing and processing | |
virtual void | QueueEvent (wxEvent *event) |
あとで処理するためにイベントをキューに追加します。 | |
virtual void | AddPendingEvent (const wxEvent &event) |
あとで処理されるイベントを送信します。 | |
virtual bool | ProcessEvent (wxEvent &event) |
Processes an event, searching event tables and calling zero or more suitable event handler function(s). | |
bool | ProcessEventLocally (wxEvent &event) |
Try to process the event in this handler and all those chained to it. | |
bool | SafelyProcessEvent (wxEvent &event) |
Processes an event by calling ProcessEvent() and handles any exceptions that occur in the process. | |
void | ProcessPendingEvents () |
Processes the pending events previously queued using QueueEvent() or AddPendingEvent(); you must call this function only if you are sure there are pending events for this handler, otherwise a wxCHECK will fail. | |
void | DeletePendingEvents () |
Deletes all events queued on this event handler using QueueEvent() or AddPendingEvent(). | |
virtual bool | SearchEventTable (wxEventTable &table, wxEvent &event) |
Searches the event table, executing an event handler function if an appropriate one is found. | |
Connecting and disconnecting | |
void | Connect (int id, int lastId, wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL) |
Connects the given function dynamically with the event handler, id and event type. | |
void | Connect (int id, wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL) |
See the Connect(int, int, wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info. | |
void | Connect (wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL) |
See the Connect(int, int, wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info. | |
bool | Disconnect (wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL) |
Disconnects the given function dynamically from the event handler, using the specified parameters as search criteria and returning true if a matching function has been found and removed. | |
bool | Disconnect (int id=wxID_ANY, wxEventType eventType=wxEVT_NULL, wxObjectEventFunction function=NULL, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL) |
See the Disconnect(wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info. | |
bool | Disconnect (int id, int lastId, wxEventType eventType, wxObjectEventFunction function=NULL, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL) |
See the Disconnect(wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info. | |
Binding and Unbinding | |
template<typename EventTag , typename Functor > | |
void | Bind (const EventTag &eventType, Functor functor, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL) |
指定された関数、ファンクタ、メンバ関数をイベントへ動的にバインドします。 | |
template<typename EventTag , typename Class , typename EventArg , typename EventHandler > | |
void | Bind (const EventTag &eventType, void(Class::*method)(EventArg &), EventHandler *handler, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL) |
See the Bind<>(const EventTag&, Functor, int, int, wxObject*) overload for more info. | |
template<typename EventTag , typename Functor > | |
bool | Unbind (const EventTag &eventType, Functor functor, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL) |
Unbinds the given function, functor or method dynamically from the event handler, using the specified parameters as search criteria and returning true if a matching function has been found and removed. | |
template<typename EventTag , typename Class , typename EventArg , typename EventHandler > | |
bool | Unbind (const EventTag &eventType, void(Class::*method)(EventArg &), EventHandler *handler, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL) |
See the Unbind<>(const EventTag&, Functor, int, int, wxObject*) overload for more info. | |
User-supplied data | |
void * | GetClientData () const |
Returns user-supplied client data. | |
wxClientData * | GetClientObject () const |
Returns a pointer to the user-supplied client data object. | |
void | SetClientData (void *data) |
Sets user-supplied client data. | |
void | SetClientObject (wxClientData *data) |
Set the client data object. | |
Event handler chaining | |
wxEvtHandler can be arranged in a double-linked list of handlers which is automatically iterated by ProcessEvent() if needed. | |
bool | GetEvtHandlerEnabled () const |
Returns true if the event handler is enabled, false otherwise. | |
wxEvtHandler * | GetNextHandler () const |
Returns the pointer to the next handler in the chain. | |
wxEvtHandler * | GetPreviousHandler () const |
Returns the pointer to the previous handler in the chain. | |
void | SetEvtHandlerEnabled (bool enabled) |
イベントハンドラを有効化、無効化します。 | |
virtual void | SetNextHandler (wxEvtHandler *handler) |
次のイベントハンドラへのポインタを設定します。 | |
virtual void | SetPreviousHandler (wxEvtHandler *handler) |
Sets the pointer to the previous handler. | |
void | Unlink () |
Unlinks this event handler from the chain it's part of (if any); then links the "previous" event handler to the "next" one (so that the chain won't be interrupted). | |
bool | IsUnlinked () const |
Returns true if the next and the previous handler pointers of this event handler instance are NULL. | |
Static Public Member Functions | |
Global event filters. | |
Methods for working with the global list of event filters. Event filters can be defined to pre-process all the events that happen in an application, see wxEventFilter documentation for more information. | |
static void | AddFilter (wxEventFilter *filter) |
Add an event filter whose FilterEvent() method will be called for each and every event processed by wxWidgets. | |
static void | RemoveFilter (wxEventFilter *filter) |
Remove a filter previously installed with AddFilter(). | |
Protected Member Functions | |
virtual bool | TryBefore (wxEvent &event) |
Method called by ProcessEvent() before examining this object event tables. | |
virtual bool | TryAfter (wxEvent &event) |
Method called by ProcessEvent() as last resort. |
wxEvtHandler::wxEvtHandler | ( | ) |
Constructor.
virtual wxEvtHandler::~wxEvtHandler | ( | ) | [virtual] |
Destructor.
If the handler is part of a chain, the destructor will unlink itself (see Unlink()).
static void wxEvtHandler::AddFilter | ( | wxEventFilter * | filter | ) | [static] |
Add an event filter whose FilterEvent() method will be called for each and every event processed by wxWidgets.
The filters are called in LIFO order and wxApp is registered as an event filter by default. The pointer must remain valid until it's removed with RemoveFilter() and is not deleted by wxEvtHandler.
virtual void wxEvtHandler::AddPendingEvent | ( | const wxEvent & | event | ) | [virtual] |
あとで処理されるイベントを送信します。
This function is similar to QueueEvent() but can't be used to post events from worker threads for the event objects with wxString fields (i.e. in practice most of them) because of an unsafe use of the same wxString object which happens because the wxString field in the original event object and its copy made internally by this function share the same string buffer internally. Use QueueEvent() to avoid this.
A copy of event is made by the function, so the original can be deleted as soon as function returns (it is common that the original is created on the stack). This requires that the wxEvent::Clone() method be implemented by event so that it can be duplicated and stored until it gets processed.
event | Event to add to the pending events queue. |
Reimplemented in wxWindow.
void wxEvtHandler::Bind | ( | const EventTag & | eventType, |
void(Class::*)(EventArg &) | method, | ||
EventHandler * | handler, | ||
int | id = wxID_ANY , |
||
int | lastId = wxID_ANY , |
||
wxObject * | userData = NULL |
||
) |
See the Bind<>(const EventTag&, Functor, int, int, wxObject*) overload for more info.
This overload will bind the given method as the event handler.
eventType | The event type to be associated with this event handler. |
method | The event handler method. This can be an arbitrary method (doesn't need to be from a wxEvtHandler derived class). |
handler | Object whose method should be called. It must always be specified so it can be checked at compile time whether the given method is an actual member of the given handler. |
id | The first ID of the identifier range to be associated with the event handler. |
lastId | The last ID of the identifier range to be associated with the event handler. |
userData | Data to be associated with the event table entry. |
void wxEvtHandler::Bind | ( | const EventTag & | eventType, |
Functor | functor, | ||
int | id = wxID_ANY , |
||
int | lastId = wxID_ANY , |
||
wxObject * | userData = NULL |
||
) |
指定された関数、ファンクタ、メンバ関数をイベントへ動的にバインドします。
This offers basically the same functionality as Connect(), but it is more flexible as it also allows you to use ordinary functions and arbitrary functors as event handlers. It is also less restrictive then Connect() because you can use an arbitrary method as an event handler, whereas Connect() requires a wxEvtHandler derived handler.
See Dynamic Event Handling for more detailed explanation of this function and the Event Sample sample for usage examples.
eventType | The event type to be associated with this event handler. |
functor | The event handler functor. This can be an ordinary function but also an arbitrary functor like boost::function<>. |
id | The first ID of the identifier range to be associated with the event handler. |
lastId | The last ID of the identifier range to be associated with the event handler. |
userData | Data to be associated with the event table entry. |
void wxEvtHandler::Connect | ( | int | id, |
int | lastId, | ||
wxEventType | eventType, | ||
wxObjectEventFunction | function, | ||
wxObject * | userData = NULL , |
||
wxEvtHandler * | eventSink = NULL |
||
) |
Connects the given function dynamically with the event handler, id and event type.
Notice that Bind() provides a more flexible and safer way to do the same thing as Connect(), please use it in any new code -- while Connect() is not formally deprecated due to its existing widespread usage, it has no advantages compared to Bind().
This is an alternative to the use of static event tables. It is more flexible as it allows to connect events generated by some object to an event handler defined in a different object of a different class (which is impossible to do directly with the event tables -- the events can be only handled in another object if they are propagated upwards to it). Do make sure to specify the correct eventSink when connecting to an event of a different object.
See Dynamic Event Handling for more detailed explanation of this function and the Event Sample sample for usage examples.
This specific overload allows you to connect an event handler to a range of source IDs. Do not confuse source IDs with event types: source IDs identify the event generator objects (typically wxMenuItem or wxWindow objects) while the event type identify which type of events should be handled by the given function (an event generator object may generate many different types of events!).
id | The first ID of the identifier range to be associated with the event handler function. |
lastId | The last ID of the identifier range to be associated with the event handler function. |
eventType | The event type to be associated with this event handler. |
function | The event handler function. Note that this function should be explicitly converted to the correct type which can be done using a macro called wxFooEventHandler for the handler for any wxFooEvent . |
userData | Data to be associated with the event table entry. |
eventSink | Object whose member function should be called. It must be specified when connecting an event generated by one object to a member function of a different object. If it is omitted, this is used. |
wxPerl Note: In wxPerl this function takes 4 arguments: id, lastid, type, method; if method is undef, the handler is disconnected.}
void wxEvtHandler::Connect | ( | int | id, |
wxEventType | eventType, | ||
wxObjectEventFunction | function, | ||
wxObject * | userData = NULL , |
||
wxEvtHandler * | eventSink = NULL |
||
) |
See the Connect(int, int, wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info.
This overload can be used to attach an event handler to a single source ID:
例:
frame->Connect( wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnQuit) );
wxPerl Note: Not supported by wxPerl.
void wxEvtHandler::Connect | ( | wxEventType | eventType, |
wxObjectEventFunction | function, | ||
wxObject * | userData = NULL , |
||
wxEvtHandler * | eventSink = NULL |
||
) |
See the Connect(int, int, wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info.
This overload will connect the given event handler so that regardless of the ID of the event source, the handler will be called.
wxPerl Note: Not supported by wxPerl.
void wxEvtHandler::DeletePendingEvents | ( | ) |
Deletes all events queued on this event handler using QueueEvent() or AddPendingEvent().
Use with care because the events which are deleted are (obviously) not processed and this may have unwanted consequences (e.g. user actions events will be lost).
Reimplemented in wxAppConsole.
bool wxEvtHandler::Disconnect | ( | wxEventType | eventType, |
wxObjectEventFunction | function, | ||
wxObject * | userData = NULL , |
||
wxEvtHandler * | eventSink = NULL |
||
) |
Disconnects the given function dynamically from the event handler, using the specified parameters as search criteria and returning true if a matching function has been found and removed.
This method can only disconnect functions which have been added using the Connect() method. There is no way to disconnect functions connected using the (static) event tables.
eventType | The event type associated with this event handler. |
function | The event handler function. |
userData | Data associated with the event table entry. |
eventSink | Object whose member function should be called. |
wxPerl Note: Not supported by wxPerl.
bool wxEvtHandler::Disconnect | ( | int | id = wxID_ANY , |
wxEventType | eventType = wxEVT_NULL , |
||
wxObjectEventFunction | function = NULL , |
||
wxObject * | userData = NULL , |
||
wxEvtHandler * | eventSink = NULL |
||
) |
See the Disconnect(wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info.
This overload takes the additional id parameter.
wxPerl Note: Not supported by wxPerl.
bool wxEvtHandler::Disconnect | ( | int | id, |
int | lastId, | ||
wxEventType | eventType, | ||
wxObjectEventFunction | function = NULL , |
||
wxObject * | userData = NULL , |
||
wxEvtHandler * | eventSink = NULL |
||
) |
See the Disconnect(wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info.
This overload takes an additional range of source IDs.
wxPerl Note: In wxPerl this function takes 3 arguments: id, lastid, type.
void* wxEvtHandler::GetClientData | ( | ) | const |
Returns user-supplied client data.
wxClientData* wxEvtHandler::GetClientObject | ( | ) | const |
Returns a pointer to the user-supplied client data object.
bool wxEvtHandler::GetEvtHandlerEnabled | ( | ) | const |
Returns true if the event handler is enabled, false otherwise.
wxEvtHandler* wxEvtHandler::GetNextHandler | ( | ) | const |
Returns the pointer to the next handler in the chain.
wxEvtHandler* wxEvtHandler::GetPreviousHandler | ( | ) | const |
Returns the pointer to the previous handler in the chain.
bool wxEvtHandler::IsUnlinked | ( | ) | const |
Returns true if the next and the previous handler pointers of this event handler instance are NULL.
virtual bool wxEvtHandler::ProcessEvent | ( | wxEvent & | event | ) | [virtual] |
Processes an event, searching event tables and calling zero or more suitable event handler function(s).
Normally, your application would not call this function: it is called in the wxWidgets implementation to dispatch incoming user interface events to the framework (and application).
However, you might need to call it if implementing new functionality (such as a new control) where you define new event types, as opposed to allowing the user to override virtual functions.
Notice that you don't usually need to override ProcessEvent() to customize the event handling, overriding the specially provided TryBefore() and TryAfter() functions is usually enough. For example, wxMDIParentFrame may override TryBefore() to ensure that the menu events are processed in the active child frame before being processed in the parent frame itself.
The normal order of event table searching is as follows:
-1
(default) the processing stops here.A->ProcessEvent
でイベントが処理されないと B->ProcessEvent
が呼び出され、これが繰り返されます。) Note that in the case of wxWindow you can build a stack of event handlers (see wxWindow::PushEventHandler() for more info). If any of the handlers of the chain return true, the function exits.Notice that steps (2)-(6) are performed in ProcessEventLocally() which is called by this function.
event | Event to process. |
Reimplemented in wxWindow.
bool wxEvtHandler::ProcessEventLocally | ( | wxEvent & | event | ) |
Try to process the event in this handler and all those chained to it.
As explained in ProcessEvent() documentation, the event handlers may be chained in a doubly-linked list. This function tries to process the event in this handler (including performing any pre-processing done in TryBefore(), e.g. applying validators) and all those following it in the chain until the event is processed or the chain is exhausted.
This function is called from ProcessEvent() and, in turn, calls TryBefore() and TryAfter(). It is not virtual and so cannot be overridden but can, and should, be called to forward an event to another handler instead of ProcessEvent() which would result in a duplicate call to TryAfter(), e.g. resulting in all unprocessed events being sent to the application object multiple times.
event | Event to process. |
void wxEvtHandler::ProcessPendingEvents | ( | ) |
Processes the pending events previously queued using QueueEvent() or AddPendingEvent(); you must call this function only if you are sure there are pending events for this handler, otherwise a wxCHECK
will fail.
The real processing still happens in ProcessEvent() which is called by this function.
Note that this function needs a valid application object (see wxAppConsole::GetInstance()) because wxApp holds the list of the event handlers with pending events and this function manipulates that list.
Reimplemented in wxAppConsole, and wxWindow.
virtual void wxEvtHandler::QueueEvent | ( | wxEvent * | event | ) | [virtual] |
あとで処理するためにイベントをキューに追加します。
This method is similar to ProcessEvent() but while the latter is synchronous, i.e. the event is processed immediately, before the function returns, this one is asynchronous and returns immediately while the event will be processed at some later time (usually during the next event loop iteration).
Another important difference is that this method takes ownership of the event parameter, i.e. it will delete it itself. This implies that the event should be allocated on the heap and that the pointer can't be used any more after the function returns (as it can be deleted at any moment).
QueueEvent() can be used for inter-thread communication from the worker threads to the main thread, it is safe in the sense that it uses locking internally and avoids the problem mentioned in AddPendingEvent() documentation by ensuring that the event object is not used by the calling thread any more. Care should still be taken to avoid that some fields of this object are used by it, notably any wxString members of the event object must not be shallow copies of another wxString object as this would result in them still using the same string buffer behind the scenes. 以下に例を示します:
void FunctionInAWorkerThread(const wxString& str) { wxCommandEvent* evt = new wxCommandEvent; // NOT evt->SetString(str) as this would be a shallow copy evt->SetString(str.c_str()); // make a deep copy wxTheApp->QueueEvent( evt ); }
Note that you can use wxThreadEvent instead of wxCommandEvent to avoid this problem:
void FunctionInAWorkerThread(const wxString& str) { wxThreadEvent evt; evt->SetString(str); // wxThreadEvent::Clone() makes sure that the internal wxString // member is not shared by other wxString instances: wxTheApp->QueueEvent( evt.Clone() ); }
Finally notice that this method automatically wakes up the event loop if it is currently idle by calling wxWakeUpIdle() so there is no need to do it manually when using it.
event | A heap-allocated event to be queued, QueueEvent() takes ownership of it. This parameter shouldn't be NULL . |
Reimplemented in wxWindow.
static void wxEvtHandler::RemoveFilter | ( | wxEventFilter * | filter | ) | [static] |
Remove a filter previously installed with AddFilter().
It's an error to remove a filter that hadn't been previously added or was already removed.
bool wxEvtHandler::SafelyProcessEvent | ( | wxEvent & | event | ) |
Processes an event by calling ProcessEvent() and handles any exceptions that occur in the process.
If an exception is thrown in event handler, wxApp::OnExceptionInMainLoop is called.
event | Event to process. |
Reimplemented in wxWindow.
virtual bool wxEvtHandler::SearchEventTable | ( | wxEventTable & | table, |
wxEvent & | event | ||
) | [virtual] |
Searches the event table, executing an event handler function if an appropriate one is found.
table | Event table to be searched. |
event | Event to be matched against an event table entry. |
void wxEvtHandler::SetClientData | ( | void * | data | ) |
Sets user-supplied client data.
data | Data to be associated with the event handler. |
void wxEvtHandler::SetClientObject | ( | wxClientData * | data | ) |
void wxEvtHandler::SetEvtHandlerEnabled | ( | bool | enabled | ) |
イベントハンドラを有効化、無効化します。
enabled | true if the event handler is to be enabled, false if it is to be disabled. |
virtual void wxEvtHandler::SetNextHandler | ( | wxEvtHandler * | handler | ) | [virtual] |
次のイベントハンドラへのポインタを設定します。
handlerA->SetNextHandler(handlerB); handlerB->SetPreviousHandler(handlerA);
handler | The event handler to be set as the next handler. Cannot be NULL. |
Reimplemented in wxWindow.
virtual void wxEvtHandler::SetPreviousHandler | ( | wxEvtHandler * | handler | ) | [virtual] |
Sets the pointer to the previous handler.
All remarks about SetNextHandler() apply to this function as well.
handler | The event handler to be set as the previous handler. Cannot be NULL. |
Reimplemented in wxWindow.
virtual bool wxEvtHandler::TryAfter | ( | wxEvent & | event | ) | [protected, virtual] |
Method called by ProcessEvent() as last resort.
This method can be overridden to implement post-processing for the events which were not processed anywhere else.
The base class version handles forwarding the unprocessed events to wxApp at wxEvtHandler level and propagating them upwards the window child-parent chain at wxWindow level and so should usually be called when overriding this method:
virtual bool wxEvtHandler::TryBefore | ( | wxEvent & | event | ) | [protected, virtual] |
Method called by ProcessEvent() before examining this object event tables.
This method can be overridden to hook into the event processing logic as early as possible. You should usually call the base class version when overriding this method, even if wxEvtHandler itself does nothing here, some derived classes do use this method, e.g. wxWindow implements support for wxValidator in it.
例:
class MyClass : public BaseClass // inheriting from wxEvtHandler { ... protected: virtual bool TryBefore(wxEvent& event) { if ( MyPreProcess(event) ) return true; return BaseClass::TryBefore(event); } };
bool wxEvtHandler::Unbind | ( | const EventTag & | eventType, |
Functor | functor, | ||
int | id = wxID_ANY , |
||
int | lastId = wxID_ANY , |
||
wxObject * | userData = NULL |
||
) |
Unbinds the given function, functor or method dynamically from the event handler, using the specified parameters as search criteria and returning true if a matching function has been found and removed.
This method can only unbind functions, functors or methods which have been added using the Bind<>() method. There is no way to unbind functions bound using the (static) event tables.
eventType | The event type associated with this event handler. |
functor | The event handler functor. This can be an ordinary function but also an arbitrary functor like boost::function<>. |
id | The first ID of the identifier range associated with the event handler. |
lastId | The last ID of the identifier range associated with the event handler. |
userData | Data associated with the event table entry. |
bool wxEvtHandler::Unbind | ( | const EventTag & | eventType, |
void(Class::*)(EventArg &) | method, | ||
EventHandler * | handler, | ||
int | id = wxID_ANY , |
||
int | lastId = wxID_ANY , |
||
wxObject * | userData = NULL |
||
) |
See the Unbind<>(const EventTag&, Functor, int, int, wxObject*) overload for more info.
This overload unbinds the given method from the event..
eventType | The event type associated with this event handler. |
method | The event handler method associated with this event. |
handler | Object whose method was called. |
id | The first ID of the identifier range associated with the event handler. |
lastId | The last ID of the identifier range associated with the event handler. |
userData | Data associated with the event table entry. |
void wxEvtHandler::Unlink | ( | ) |