X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7a34307e2463bca44f128e28b70e1df4f626e8f8..83b4d26c143314e9bb0425246e4cd85e83984ae8:/include/wx/event.h diff --git a/include/wx/event.h b/include/wx/event.h index 06cd01f28b..36f7a8b73e 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -26,6 +26,8 @@ #include "wx/dynarray.h" #include "wx/thread.h" #include "wx/tracker.h" +#include "wx/typeinfo.h" +#include "wx/any.h" #ifdef wxHAS_EVENT_BIND #include "wx/meta/convertible.h" @@ -189,16 +191,6 @@ typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&); // compiler we can restore its old definition for it. typedef wxEventFunction wxObjectEventFunction; - -// wxEventFunctorClassInfo is used as a unique identifier for wxEventFunctor- -// derived classes; it is more light weight than wxClassInfo and can be used in -// template classes -typedef void (*wxEventFunctorClassInfo)(); - -// this macro must be used in wxEventFunctor-derived classes -#define wxDEFINE_EVENT_FUNCTOR_CLASS_INFO( classInfoName ) \ - static void classInfoName() {} - // The event functor which is stored in the static and dynamic event tables: class WXDLLIMPEXP_BASE wxEventFunctor { @@ -212,11 +204,6 @@ public: // finding it in an event table in Unbind(), by the given functor: virtual bool IsMatching(const wxEventFunctor& functor) const = 0; - // Test whether the given class info is the same as from this functor. This - // allows us in IsMatching to safely downcast the given wxEventFunctor without - // the usage of dynamic_cast<>(). - virtual bool IsSameClass(wxEventFunctorClassInfo classInfo) const = 0; - // If the functor holds an wxEvtHandler, then get access to it and track // its lifetime with wxEventConnectionRef: virtual wxEvtHandler *GetEvtHandler() const @@ -228,6 +215,9 @@ public: // wxEventFunction: virtual wxEventFunction GetEvtMethod() const { return NULL; } + +private: + WX_DECLARE_ABSTRACT_TYPEINFO(wxEventFunctor) }; // A plain method functor for the untyped legacy event types: @@ -247,7 +237,7 @@ public: virtual bool IsMatching(const wxEventFunctor& functor) const { - if ( functor.IsSameClass( sm_classInfo )) + if ( wxTypeId(functor) == wxTypeId(*this) ) { const wxObjectEventFunctor &other = static_cast< const wxObjectEventFunctor & >( functor ); @@ -262,9 +252,6 @@ public: return false; } - virtual bool IsSameClass( wxEventFunctorClassInfo otherClassInfo ) const - { return sm_classInfo == otherClassInfo; } - virtual wxEvtHandler *GetEvtHandler() const { return m_handler; } @@ -275,7 +262,10 @@ private: wxEvtHandler *m_handler; wxEventFunction m_method; - wxDEFINE_EVENT_FUNCTOR_CLASS_INFO( sm_classInfo ); + // Provide a dummy default ctor for type info purposes + wxObjectEventFunctor() { } + + WX_DECLARE_TYPEINFO_INLINE(wxObjectEventFunctor) }; // Create a functor for the legacy events: used by Connect() @@ -424,22 +414,19 @@ public: virtual bool IsMatching(const wxEventFunctor& functor) const { - if ( !functor.IsSameClass(sm_classInfo) ) + if ( wxTypeId(functor) != wxTypeId(*this) ) return false; typedef wxEventFunctorMethod ThisFunctor; - // the cast is valid because IsSameClass() returned true above + // the cast is valid because wxTypeId()s matched above const ThisFunctor& other = static_cast(functor); return (m_method == other.m_method || other.m_method == NULL) && (m_handler == other.m_handler || other.m_handler == NULL); } - virtual bool IsSameClass( wxEventFunctorClassInfo otherClassInfo ) const - { return sm_classInfo == otherClassInfo; } - virtual wxEvtHandler *GetEvtHandler() const { return this->ConvertToEvtHandler(m_handler); } @@ -450,7 +437,12 @@ private: EventHandler *m_handler; void (Class::*m_method)(EventArg&); - wxDEFINE_EVENT_FUNCTOR_CLASS_INFO( sm_classInfo ); + // Provide a dummy default ctor for type info purposes + wxEventFunctorMethod() { } + + typedef wxEventFunctorMethod thisClass; + WX_DECLARE_TYPEINFO_INLINE(thisClass) }; @@ -488,7 +480,7 @@ public: virtual bool IsMatching(const wxEventFunctor &functor) const { - if ( !functor.IsSameClass(sm_classInfo) ) + if ( wxTypeId(functor) != wxTypeId(*this) ) return false; typedef wxEventFunctorFunction ThisFunctor; @@ -498,13 +490,14 @@ public: return m_handler == other.m_handler; } - virtual bool IsSameClass( wxEventFunctorClassInfo otherClassInfo ) const - { return sm_classInfo == otherClassInfo; } - private: void (*m_handler)(EventArg&); - wxDEFINE_EVENT_FUNCTOR_CLASS_INFO( sm_classInfo ); + // Provide a dummy default ctor for type info purposes + wxEventFunctorFunction() { } + + typedef wxEventFunctorFunction thisClass; + WX_DECLARE_TYPEINFO_INLINE(thisClass) }; @@ -532,7 +525,7 @@ public: virtual bool IsMatching(const wxEventFunctor &functor) const { - if ( !functor.IsSameClass(sm_classInfo) ) + if ( wxTypeId(functor) != wxTypeId(*this) ) return false; typedef wxEventFunctorFunctor FunctorThis; @@ -544,9 +537,6 @@ public: return m_handlerAddr == other.m_handlerAddr; } - virtual bool IsSameClass( wxEventFunctorClassInfo otherClassInfo ) const - { return sm_classInfo == otherClassInfo; } - private: // Store a copy of the functor to prevent using/calling an already // destroyed instance: @@ -555,7 +545,11 @@ private: // Use the address of the original functor for comparison in IsMatching: const void *m_handlerAddr; - wxDEFINE_EVENT_FUNCTOR_CLASS_INFO( sm_classInfo ); + // Provide a dummy default ctor for type info purposes + wxEventFunctorFunctor() { } + + typedef wxEventFunctorFunctor thisClass; + WX_DECLARE_TYPEINFO_INLINE(thisClass) }; // Create functors for the templatized events, either allocated on the heap for @@ -1210,16 +1204,15 @@ public: // make sure our string member (which uses COW, aka refcounting) is not // shared by other wxString instances: SetString(GetString().c_str()); + +#if wxUSE_ANY && (!defined(__VISUALC__) || wxCHECK_VISUALC_VERSION(7)) + m_payload = event.m_payload; +#endif } virtual wxEvent *Clone() const { - wxThreadEvent* ev = new wxThreadEvent(*this); - - // make sure our string member (which uses COW, aka refcounting) is not - // shared by other wxString instances: - ev->SetString(GetString().c_str()); - return ev; + return new wxThreadEvent(*this); } // this is important to avoid that calling wxEventLoopBase::YieldFor thread events @@ -1227,6 +1220,23 @@ public: virtual wxEventCategory GetEventCategory() const { return wxEVT_CATEGORY_THREAD; } +#if wxUSE_ANY && (!defined(__VISUALC__) || wxCHECK_VISUALC_VERSION(7)) + template + void SetPayload(const T& payload) + { + m_payload = payload; + } + + template + T GetPayload() const + { + return m_payload.As(); + } + +protected: + wxAny m_payload; +#endif // wxUSE_ANY && (!defined(__VISUALC__) || wxCHECK_VISUALC_VERSION(7)) + private: DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxThreadEvent) }; @@ -1519,7 +1529,7 @@ enum wxKeyCategoryFlags // home and end keys, on and off numeric keypads WXK_CATEGORY_JUMP = 4, - // tab key + // tab key, on and off numeric keypads WXK_CATEGORY_TAB = 8, // backspace and delete keys, on and off numeric keypads @@ -2760,7 +2770,10 @@ struct WXDLLIMPEXP_BASE wxEventTableEntryBase m_lastId(idLast), m_fn(fn), m_callbackUserData(data) - { } + { + wxASSERT_MSG( idLast == wxID_ANY || winid <= idLast, + "invalid IDs range: lower bound > upper bound" ); + } wxEventTableEntryBase( const wxEventTableEntryBase &entry ) : m_id( entry.m_id ), @@ -3927,12 +3940,12 @@ typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent& #ifdef wxHAS_EVENT_BIND #define wxBIND_OR_CONNECT_HACK_BASE_CLASS #define wxBIND_OR_CONNECT_HACK_ONLY_BASE_CLASS - #define wxBIND_OR_CONNECT_HACK(w, evt, handler, func, obj) \ + #define wxBIND_OR_CONNECT_HACK(win, evt, handler, func, obj) \ win->Bind(evt, &func, obj) #else // wxHAS_EVENT_BIND #define wxBIND_OR_CONNECT_HACK_BASE_CLASS public wxEvtHandler, #define wxBIND_OR_CONNECT_HACK_ONLY_BASE_CLASS : public wxEvtHandler - #define wxBIND_OR_CONNECT_HACK(w, evt, handler, func, obj) \ + #define wxBIND_OR_CONNECT_HACK(win, evt, handler, func, obj) \ win->Connect(evt, handler(func), NULL, obj) #endif // wxHAS_EVENT_BIND