X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9de71074ec549ba06e70a39716d7a458152bc710..97d13342cc2ac77e21c38115cc6ebecac930f92a:/interface/wx/event.h diff --git a/interface/wx/event.h b/interface/wx/event.h index c35a940299..9f061f5a0c 100644 --- a/interface/wx/event.h +++ b/interface/wx/event.h @@ -467,11 +467,11 @@ public: the function skips to step (7). -# TryBefore() is called (this is where wxValidator are taken into account for wxWindow objects). If this returns @true, the function exits. - -# Dynamic event table of the handlers connected using Connect() is + -# Dynamic event table of the handlers binded using Bind<>() is searched. If a handler is found, it is executed and the function returns @true unless the handler used wxEvent::Skip() to indicate that it didn't handle the event in which case the search continues. - -# Static events table of the handlers connected using event table + -# Static events table of the handlers binded using event table macros is searched for this event handler. If this fails, the base class event table table is tried, and so on until no more tables exist or an appropriate function was found. If a handler is found, @@ -533,17 +533,17 @@ public: @see wxWindow::HandleWindowEvent */ bool SafelyProcessEvent(wxEvent& event); - + /** - Processes the pending events previously queued using QueueEvent() or + 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 @c 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 + + 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. */ @@ -552,13 +552,13 @@ public: /** 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). */ void DeletePendingEvents(); - + /** Searches the event table, executing an event handler function if an appropriate one is found. @@ -580,7 +580,7 @@ public: If a suitable function is called but calls wxEvent::Skip, this function will fail, and searching will continue. - + @todo this function in the header is listed as an "implementation only" function; are we sure we want to document it? @@ -601,6 +601,11 @@ public: 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 @@ -609,7 +614,7 @@ public: Do make sure to specify the correct @a eventSink when connecting to an event of a different object. - See @ref overview_events_connect for more detailed explanation + See @ref overview_events_bind for more detailed explanation of this function and the @ref page_samples_event sample for usage examples. @@ -639,6 +644,8 @@ public: 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, @c this is used. + + @see Bind<>() */ void Connect(int id, int lastId, wxEventType eventType, wxObjectEventFunction function, @@ -724,6 +731,143 @@ public: //@} + /** + @name Binding and Unbinding + */ + //@{ + + /** + Binds the given function, functor or method dynamically with the event. + + 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, + where as Connect() requires a wxEvtHandler derived handler. + + See @ref overview_events_bind for more detailed explanation + of this function and the @ref page_samples_event sample for usage + examples. + + @param eventType + The event type to be associated with this event handler. + @param functor + The event handler functor. This can be an ordinary function but also + an arbitrary functor like boost::function<>. + @param id + The first ID of the identifier range to be associated with the event + handler. + @param lastId + The last ID of the identifier range to be associated with the event + handler. + @param userData + Data to be associated with the event table entry. + + @since 2.9.0 + */ + template + void Bind(const EventTag& eventType, + Functor functor, + 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. + + @param eventType + The event type to be associated with this event handler. + @param method + The event handler method. This can be an arbitrary method (doesn't need + to be from a wxEvtHandler derived class). + @param 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. + @param id + The first ID of the identifier range to be associated with the event + handler. + @param lastId + The last ID of the identifier range to be associated with the event + handler. + @param userData + Data to be associated with the event table entry. + + @since 2.9.0 + */ + template + void Bind(const EventTag &eventType, + void (Class::*method)(EventArg &), + EventHandler *handler, + 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 binded using the (static) event tables. + + @param eventType + The event type associated with this event handler. + @param functor + The event handler functor. This can be an ordinary function but also + an arbitrary functor like boost::function<>. + @param id + The first ID of the identifier range associated with the event + handler. + @param lastId + The last ID of the identifier range associated with the event + handler. + @param userData + Data associated with the event table entry. + + @since 2.9.0 + */ + template + bool Unbind(const EventTag& eventType, + Functor functor, + 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.. + + @param eventType + The event type associated with this event handler. + @param method + The event handler method associated with this event. + @param handler + Object whose method was called. + @param id + The first ID of the identifier range associated with the event + handler. + @param lastId + The last ID of the identifier range associated with the event + handler. + @param userData + Data associated with the event table entry. + + @since 2.9.0 + */ + template + bool Unbind(const EventTag &eventType, + void (Class::*method)(EventArg&), + EventHandler *handler, + int id = wxID_ANY, + int lastId = wxID_ANY, + wxObject *userData = NULL ); + //@} /** @name User-supplied data */ @@ -3679,6 +3823,14 @@ wxEventType wxNewEventType(); The class @a 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: + @code + wxDECLARE_EVENT(MY_COMMAND_EVENT, wxCommandEvent); + + class MyCustomEvent : public wxEvent { ... }; + wxDECLARE_EVENT(MY_CUSTOM_EVENT, MyCustomEvent); + @endcode */ #define wxDECLARE_EVENT(name, cls) \ wxDECLARE_EXPORTED_EVENT(wxEMPTY_PARAMETER_VALUE, name, cls)