X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5706de1cf469f1ca53be7c402365d47e12a616cf..9bb1b0554014ee7f1e482d64c899ecef0391e74b:/include/wx/event.h diff --git a/include/wx/event.h b/include/wx/event.h index 06a60da6cc..b94fcb8c9f 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -108,8 +108,8 @@ BEGIN_DECLARE_EVENT_TYPES() // it is important to still have these as constants to avoid // initialization order related problems DECLARE_EVENT_TYPE(wxEVT_NULL, 0) - const wxEventType wxEVT_FIRST = 10000; - const wxEventType wxEVT_USER_FIRST = wxEVT_FIRST + 2000; + DECLARE_EVENT_TYPE(wxEVT_FIRST, 10000) + DECLARE_EVENT_TYPE(wxEVT_USER_FIRST, wxEVT_FIRST + 2000) #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES DECLARE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED, 1) @@ -937,7 +937,7 @@ public: m_size(event.m_size), m_rect(event.m_rect) { } wxSizeEvent(const wxRect& rect, int id = 0) - : m_rect(rect), m_size(rect.GetSize()) + : m_size(rect.GetSize()), m_rect(rect) { m_eventType = wxEVT_SIZING; m_id = id; } wxSize GetSize() const { return m_size; } @@ -1969,19 +1969,27 @@ struct WXDLLEXPORT wxEventTableEntry : public wxEventTableEntryBase const int& m_eventType; }; +class WXDLLEXPORT wxEvtHandler; + // an entry used in dynamic event table managed by wxEvtHandler::Connect() struct WXDLLEXPORT wxDynamicEventTableEntry : public wxEventTableEntryBase { wxDynamicEventTableEntry(int evType, int winid, int idLast, - wxObjectEventFunction fn, wxObject *data) + wxObjectEventFunction fn, wxObject *data, wxEvtHandler* eventSink) : wxEventTableEntryBase(winid, idLast, fn, data), - m_eventType(evType) + m_eventType(evType), + m_eventSink(eventSink) { } // not a reference here as we can't keep a reference to a temporary int // created to wrap the constant value typically passed to Connect() - nor // do we need it int m_eventType; + + // Pointer to object whose function is fn - so we don't assume the + // EventFunction is always a member of the EventHandler receiving the + // message + wxEvtHandler* m_eventSink; }; #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES @@ -2031,23 +2039,27 @@ public: // winid and event type void Connect( int winid, int lastId, int eventType, wxObjectEventFunction func, - wxObject *userData = (wxObject *) NULL ); + wxObject *userData = (wxObject *) NULL, + wxEvtHandler *eventSink = (wxEvtHandler *) NULL ); // Convenience function: take just one id void Connect( int winid, int eventType, wxObjectEventFunction func, - wxObject *userData = (wxObject *) NULL ) - { Connect(winid, wxID_ANY, eventType, func, userData); } + wxObject *userData = (wxObject *) NULL, + wxEvtHandler *eventSink = (wxEvtHandler *) NULL ) + { Connect(winid, wxID_ANY, eventType, func, userData, eventSink); } bool Disconnect( int winid, int lastId, wxEventType eventType, wxObjectEventFunction func = NULL, - wxObject *userData = (wxObject *) NULL ); + wxObject *userData = (wxObject *) NULL, + wxEvtHandler *eventSink = (wxEvtHandler *) NULL ); // Convenience function: take just one id bool Disconnect( int winid, wxEventType eventType = wxEVT_NULL, wxObjectEventFunction func = NULL, - wxObject *userData = (wxObject *) NULL ) - { return Disconnect(winid, wxID_ANY, eventType, func, userData); } + wxObject *userData = (wxObject *) NULL, + wxEvtHandler *eventSink = (wxEvtHandler *) NULL ) + { return Disconnect(winid, wxID_ANY, eventType, func, userData, eventSink); } // User data can be associated with each wxEvtHandler @@ -2094,6 +2106,22 @@ private: static const wxEventTableEntry sm_eventTableEntries[]; protected: + // hooks for wxWindow used by ProcessEvent() + // ----------------------------------------- + + // this one is called before trying our own event table to allow plugging + // in the validators +#if wxUSE_VALIDATORS + virtual bool TryValidator(wxEvent& WXUNUSED(event)) { return false; } +#endif // wxUSE_VALIDATORS + + // this one is called after failing to find the event handle in our own + // table to give a chance to the other windows to process it + // + // base class implementation passes the event to wxTheApp + virtual bool TryParent(wxEvent& event); + + static const wxEventTable sm_eventTable; virtual const wxEventTable *GetEventTable() const; @@ -2111,10 +2139,6 @@ protected: # endif #endif - // optimization: instead of using costly IsKindOf() to decide whether we're - // a window (which is true in 99% of cases), use this flag - bool m_isWindow; - // Is event handler enabled? bool m_enabled; @@ -2145,6 +2169,15 @@ private: DECLARE_DYNAMIC_CLASS(wxEvtHandler) }; +// Post a message to the given eventhandler which will be processed during the +// next event loop iteration +inline void wxPostEvent(wxEvtHandler *dest, wxEvent& event) +{ + wxCHECK_RET( dest, wxT("need an object to post event to in wxPostEvent") ); + + dest->AddPendingEvent(event); +} + typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&); #if wxUSE_GUI typedef void (wxEvtHandler::*wxCommandEventFunction)(wxCommandEvent&);