X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0b632977d75f403b7bc043d48a1c15e7394c546c..f1b63efe8993c6c0460354bc2da7331526d43efa:/include/wx/event.h diff --git a/include/wx/event.h b/include/wx/event.h index 6c77cf5467..fd6866ee58 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -105,10 +105,10 @@ extern WXDLLIMPEXP_BASE wxEventType wxNewEventType(); extern const expdecl wxEventType name; #define wxDEFINE_EVENT_REFERENCE( name, type, value ) \ - const wxEventType &name( value ); + const wxEventType& name = value; #define wxDECLARE_EXPORTED_EVENT_REFERENCE( expdecl, name, type ) \ - extern const expdecl wxEventType &name; + extern const expdecl wxEventType& name; #define wxDECLARE_LOCAL_EVENT( name, type ) \ wxDECLARE_EXPORTED_EVENT( wxEMPTY_PARAMETER_VALUE, name, type ) @@ -199,9 +199,12 @@ class WXDLLIMPEXP_BASE wxEventFunctor public: virtual ~wxEventFunctor(); + // this operator is used to actually invoke the event handler virtual void operator()(wxEvtHandler *, wxEvent &) = 0; - virtual bool operator==(const wxEventFunctor& other) const = 0; + // this function tests whether this functor is matched, for the purpose of + // finding it in an event table in Disconnect(), by the given func + virtual bool Matches(const wxEventFunctor& func) const = 0; virtual wxEvtHandler *GetHandler() const { return NULL; } @@ -225,13 +228,12 @@ public: (realHandler->*m_method)(event); } - virtual bool operator==(const wxEventFunctor& other) const + virtual bool Matches(const wxEventFunctor& other) const { wxEvtHandler * const handler = other.GetHandler(); - const wxObjectEventFunction method = other.GetMethod(); return (m_handler == handler || !handler) && - (m_method == method || !method); + (m_method == other.GetMethod()); } virtual wxEvtHandler *GetHandler() const { return m_handler; } @@ -242,6 +244,25 @@ private: wxObjectEventFunction m_method; }; +// Create a functor for the legacy events: handler can be NULL and its default +// value is used by the event table macros + +inline wxObjectEventFunctor * +wxNewEventFunctor(wxEventType WXUNUSED(evtType), + wxObjectEventFunction method, + wxEvtHandler *handler = NULL) +{ + return new wxObjectEventFunctor(method, handler); +} + +inline wxObjectEventFunctor +wxConstructEventFunctor(wxEventType WXUNUSED(evtType), + wxObjectEventFunction method, + wxEvtHandler *handler) +{ + return wxObjectEventFunctor(method, handler); +} + #if !wxEVENTS_COMPATIBILITY_2_8 template @@ -262,7 +283,7 @@ public: ( *m_handler )( dynamic_cast< typename EventType::CorrespondingEvent & >( event )); } - virtual bool operator == ( const wxEventFunctor &right ) const + virtual bool Matches( const wxEventFunctor &right ) const { wxEventFunctorFunction const &other = dynamic_cast< wxEventFunctorFunction const & >( right ); @@ -307,7 +328,7 @@ public: ( realHandler->*m_method )( dynamic_cast< typename EventType::CorrespondingEvent & >( event )); } - virtual bool operator == ( const wxEventFunctor &right ) const + virtual bool Matches( const wxEventFunctor &right ) const { wxEventFunctorMethod const &other = dynamic_cast< wxEventFunctorMethod const & >( right ); @@ -355,7 +376,7 @@ public: m_functor( dynamic_cast< typename EventType::CorrespondingEvent & >( event )); } - virtual bool operator == ( const wxEventFunctor &right ) const + virtual bool Matches( const wxEventFunctor &right ) const { wxEventFunctorAdapter const &other = dynamic_cast< wxEventFunctorAdapter const & >( right ); @@ -366,28 +387,6 @@ private: Functor m_functor; }; -#endif // wxEVENTS_COMPATIBILITY_2_8 - -// Create a functor for the legacy events: - -inline wxObjectEventFunctor * -wxNewEventFunctor(wxEventType WXUNUSED(evtType), - wxObjectEventFunction method, - wxEvtHandler *handler = NULL) -{ - return new wxObjectEventFunctor(method, handler); -} - -inline wxObjectEventFunctor -wxConstructEventFunctor(wxEventType WXUNUSED(evtType), - wxObjectEventFunction method, - wxEvtHandler *handler = NULL) -{ - return wxObjectEventFunctor(method, handler); -} - -#if !wxEVENTS_COMPATIBILITY_2_8 - // // Create functors for the templatized events (needed in wxEvtHandler::Connect): // @@ -1495,7 +1494,7 @@ private: class WXDLLIMPEXP_CORE wxEraseEvent : public wxEvent { public: - wxEraseEvent(int Id = 0, wxDC *dc = (wxDC *) NULL) + wxEraseEvent(int Id = 0, wxDC *dc = NULL) : wxEvent(Id, wxEVT_ERASE_BACKGROUND), m_dc(dc) { } @@ -1890,7 +1889,7 @@ public: wxDropFilesEvent(wxEventType type = wxEVT_NULL, int noFiles = 0, - wxString *files = (wxString *) NULL) + wxString *files = NULL) : wxEvent(0, type), m_noFiles(noFiles), m_pos(), @@ -2123,7 +2122,7 @@ class WXDLLIMPEXP_CORE wxPaletteChangedEvent : public wxEvent public: wxPaletteChangedEvent(wxWindowID winid = 0) : wxEvent(winid, wxEVT_PALETTE_CHANGED), - m_changedWindow((wxWindow *) NULL) + m_changedWindow(NULL) { } wxPaletteChangedEvent(const wxPaletteChangedEvent& event) @@ -2184,7 +2183,7 @@ public: wxNavigationKeyEvent() : wxEvent(0, wxEVT_NAVIGATION_KEY), m_flags(IsForward | FromTab), // defaults are for TAB - m_focus((wxWindow *)NULL) + m_focus(NULL) { m_propagationLevel = wxEVENT_PROPAGATE_NONE; } @@ -2695,8 +2694,8 @@ public: int lastId, wxEventType eventType, wxObjectEventFunction func, - wxObject *userData = (wxObject *) NULL, - wxEvtHandler *eventSink = (wxEvtHandler *) NULL) + wxObject *userData = NULL, + wxEvtHandler *eventSink = NULL) { wxObjectEventFunctor *functor = wxNewEventFunctor( eventType, func, eventSink ); @@ -2707,23 +2706,23 @@ public: void Connect(int winid, wxEventType eventType, wxObjectEventFunction func, - wxObject *userData = (wxObject *) NULL, - wxEvtHandler *eventSink = (wxEvtHandler *) NULL) + wxObject *userData = NULL, + wxEvtHandler *eventSink = NULL) { Connect(winid, wxID_ANY, eventType, func, userData, eventSink); } // Even more convenient: without id (same as using id of wxID_ANY) void Connect(wxEventType eventType, wxObjectEventFunction func, - wxObject *userData = (wxObject *) NULL, - wxEvtHandler *eventSink = (wxEvtHandler *) NULL) + wxObject *userData = NULL, + wxEvtHandler *eventSink = NULL) { Connect(wxID_ANY, wxID_ANY, eventType, func, userData, eventSink); } bool Disconnect(int winid, int lastId, wxEventType eventType, wxObjectEventFunction func = NULL, - wxObject *userData = (wxObject *) NULL, - wxEvtHandler *eventSink = (wxEvtHandler *) NULL) + wxObject *userData = NULL, + wxEvtHandler *eventSink = NULL) { wxObjectEventFunctor functor = wxConstructEventFunctor( eventType, func, eventSink ); @@ -2733,14 +2732,14 @@ public: bool Disconnect(int winid = wxID_ANY, wxEventType eventType = wxEVT_NULL, wxObjectEventFunction func = NULL, - wxObject *userData = (wxObject *) NULL, - wxEvtHandler *eventSink = (wxEvtHandler *) NULL) + wxObject *userData = NULL, + wxEvtHandler *eventSink = NULL) { return Disconnect(winid, wxID_ANY, eventType, func, userData, eventSink); } bool Disconnect(wxEventType eventType, wxObjectEventFunction func, - wxObject *userData = (wxObject *) NULL, - wxEvtHandler *eventSink = (wxEvtHandler *) NULL) + wxObject *userData = NULL, + wxEvtHandler *eventSink = NULL) { return Disconnect(wxID_ANY, eventType, func, userData, eventSink); } @@ -3059,14 +3058,15 @@ public: // implementation from now on // -------------------------- - // check if the given event table entry matches this event and call the - // handler if it does + // check if the given event table entry matches this event by id (the check + // for the event type should be done by caller) and call the handler if it + // does // // return true if the event was processed, false otherwise (no match or the // handler decided to skip the event) - static bool ProcessEventIfMatches(const wxEventTableEntryBase& tableEntry, - wxEvtHandler *handler, - wxEvent& event); + static bool ProcessEventIfMatchesId(const wxEventTableEntryBase& tableEntry, + wxEvtHandler *handler, + wxEvent& event); virtual bool SearchEventTable(wxEventTable& table, wxEvent& event); bool SearchDynamicEventTable( wxEvent& event );