X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7a34307e2463bca44f128e28b70e1df4f626e8f8..438959cca892a7651634cc3a7aad4819ac49b23c:/include/wx/event.h diff --git a/include/wx/event.h b/include/wx/event.h index 06cd01f28b..87a1a6a304 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -26,17 +26,28 @@ #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" #endif +// Currently VC6 and VC7 are known to not be able to compile CallAfter() code, +// so disable it for them. +#if !defined(__VISUALC__) || wxCHECK_VISUALC_VERSION(8) + #include "wx/meta/removeref.h" + + #define wxHAS_CALL_AFTER +#endif + // ---------------------------------------------------------------------------- // forward declarations // ---------------------------------------------------------------------------- class WXDLLIMPEXP_FWD_BASE wxList; class WXDLLIMPEXP_FWD_BASE wxEvent; +class WXDLLIMPEXP_FWD_BASE wxEventFilter; #if wxUSE_GUI class WXDLLIMPEXP_FWD_CORE wxDC; class WXDLLIMPEXP_FWD_CORE wxMenu; @@ -77,25 +88,12 @@ typedef int wxEventType; // the wxEVENT_HANDLER_CAST-macro. #define wxStaticCastEvent(type, val) static_cast(val) -#define DECLARE_EVENT_TABLE_ENTRY(type, winid, idLast, fn, obj) \ +#define wxDECLARE_EVENT_TABLE_ENTRY(type, winid, idLast, fn, obj) \ wxEventTableEntry(type, winid, idLast, wxNewEventTableFunctor(type, fn), obj) -#define DECLARE_EVENT_TABLE_TERMINATOR() \ +#define wxDECLARE_EVENT_TABLE_TERMINATOR() \ wxEventTableEntry(wxEVT_NULL, 0, 0, 0, 0) -// obsolete event declaration/definition macros, we don't need them any longer -// but we keep them for compatibility as it doesn't cost us anything anyhow -#define BEGIN_DECLARE_EVENT_TYPES() -#define END_DECLARE_EVENT_TYPES() -#define DECLARE_EXPORTED_EVENT_TYPE(expdecl, name, value) \ - extern expdecl const wxEventType name; -#define DECLARE_EVENT_TYPE(name, value) \ - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE, name, value) -#define DECLARE_LOCAL_EVENT_TYPE(name, value) \ - DECLARE_EXPORTED_EVENT_TYPE(wxEMPTY_PARAMETER_VALUE, name, value) -#define DEFINE_EVENT_TYPE(name) const wxEventType name = wxNewEventType(); -#define DEFINE_LOCAL_EVENT_TYPE(name) DEFINE_EVENT_TYPE(name) - // generate a new unique event type extern WXDLLIMPEXP_BASE wxEventType wxNewEventType(); @@ -189,16 +187,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 +200,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 +211,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: @@ -238,33 +224,28 @@ public: : m_handler( handler ), m_method( method ) { } - virtual void operator()(wxEvtHandler *handler, wxEvent& event) - { - wxEvtHandler * const realHandler = m_handler ? m_handler : handler; - - (realHandler->*m_method)(event); - } + virtual void operator()(wxEvtHandler *handler, wxEvent& event); 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 ); - // FIXME-VC6: amazing but true: replacing "method == NULL" here - // with "!method" makes VC6 crash with an ICE in DLL build (only!) + // FIXME-VC6: amazing but true: replacing "m_method == 0" here + // with "!m_method" makes VC6 crash with an ICE in DLL build (only!) + // Also notice that using "NULL" instead of "0" results in warnings + // about "using NULL in arithmetics" from arm-linux-androideabi-g++ + // 4.4.3 used for wxAndroid build. - return ( m_method == other.m_method || other.m_method == NULL ) && + return ( m_method == other.m_method || other.m_method == 0 ) && ( m_handler == other.m_handler || other.m_handler == NULL ); } else return false; } - virtual bool IsSameClass( wxEventFunctorClassInfo otherClassInfo ) const - { return sm_classInfo == otherClassInfo; } - virtual wxEvtHandler *GetEvtHandler() const { return m_handler; } @@ -275,7 +256,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() @@ -287,7 +271,7 @@ wxNewEventFunctor(const wxEventType& WXUNUSED(evtType), return new wxObjectEventFunctor(method, handler); } -// This version is used by DECLARE_EVENT_TABLE_ENTRY() +// This version is used by wxDECLARE_EVENT_TABLE_ENTRY() inline wxObjectEventFunctor * wxNewEventTableFunctor(const wxEventType& WXUNUSED(evtType), wxObjectEventFunction method) @@ -424,22 +408,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 +431,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 +474,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 +484,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 +519,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 +531,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 +539,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 @@ -617,7 +605,7 @@ wxMakeEventFunctor(const EventTag&, method, handler); } -// Create an event functor for the event table via DECLARE_EVENT_TABLE_ENTRY: +// Create an event functor for the event table via wxDECLARE_EVENT_TABLE_ENTRY: // in this case we don't have the handler (as it's always the same as the // object which generated the event) so we must use Class as its type template @@ -639,8 +627,10 @@ extern WXDLLIMPEXP_BASE const wxEventType wxEVT_FIRST; extern WXDLLIMPEXP_BASE const wxEventType wxEVT_USER_FIRST; // Need events declared to do this +class WXDLLIMPEXP_FWD_BASE wxIdleEvent; +class WXDLLIMPEXP_FWD_BASE wxThreadEvent; +class WXDLLIMPEXP_FWD_BASE wxAsyncMethodCallEvent; class WXDLLIMPEXP_FWD_CORE wxCommandEvent; -class WXDLLIMPEXP_FWD_CORE wxThreadEvent; class WXDLLIMPEXP_FWD_CORE wxMouseEvent; class WXDLLIMPEXP_FWD_CORE wxFocusEvent; class WXDLLIMPEXP_FWD_CORE wxChildFocusEvent; @@ -673,36 +663,36 @@ class WXDLLIMPEXP_FWD_CORE wxPaletteChangedEvent; class WXDLLIMPEXP_FWD_CORE wxJoystickEvent; class WXDLLIMPEXP_FWD_CORE wxDropFilesEvent; class WXDLLIMPEXP_FWD_CORE wxInitDialogEvent; -class WXDLLIMPEXP_FWD_CORE wxIdleEvent; class WXDLLIMPEXP_FWD_CORE wxUpdateUIEvent; class WXDLLIMPEXP_FWD_CORE wxClipboardTextEvent; class WXDLLIMPEXP_FWD_CORE wxHelpEvent; // Command events -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEvent); -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEvent); -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEvent); -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEvent); -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEvent); -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, wxCommandEvent); -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEvent); -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_SLIDER_UPDATED, wxCommandEvent); -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEvent); -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEvent); - -// wxEVT_COMMAND_SCROLLBAR_UPDATED is deprecated, use wxEVT_SCROLL... events -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_SCROLLBAR_UPDATED, wxCommandEvent); -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_VLBOX_SELECTED, wxCommandEvent); -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEvent); -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TOOL_RCLICKED, wxCommandEvent); -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED, wxCommandEvent); -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TOOL_ENTER, wxCommandEvent); -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_COMBOBOX_DROPDOWN, wxCommandEvent); -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_COMBOBOX_CLOSEUP, wxCommandEvent); - - // Thread events -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_THREAD, wxThreadEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_BUTTON, wxCommandEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_CHECKBOX, wxCommandEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_CHOICE, wxCommandEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_LISTBOX, wxCommandEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_LISTBOX_DCLICK, wxCommandEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_CHECKLISTBOX, wxCommandEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MENU, wxCommandEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SLIDER, wxCommandEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_RADIOBOX, wxCommandEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_RADIOBUTTON, wxCommandEvent); + +// wxEVT_SCROLLBAR is deprecated, use wxEVT_SCROLL... events +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLBAR, wxCommandEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_VLBOX, wxCommandEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMBOBOX, wxCommandEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TOOL_RCLICKED, wxCommandEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TOOL_DROPDOWN, wxCommandEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TOOL_ENTER, wxCommandEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMBOBOX_DROPDOWN, wxCommandEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMBOBOX_CLOSEUP, wxCommandEvent); + + // Thread and asynchronous method call events +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_BASE, wxEVT_THREAD, wxThreadEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_BASE, wxEVT_ASYNC_METHOD_CALL, wxAsyncMethodCallEvent); // Mouse event types wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_LEFT_DOWN, wxMouseEvent); @@ -737,6 +727,10 @@ wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_KEY_UP, wxKeyEvent); #if wxUSE_HOTKEY wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_HOTKEY, wxKeyEvent); #endif +// This is a private event used by wxMSW code only and subject to change or +// disappear in the future. Don't use. +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_AFTER_CHAR, wxKeyEvent); + // Set cursor event wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SET_CURSOR, wxSetCursorEvent); @@ -817,9 +811,9 @@ wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOVE_END, wxMoveEvent); wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_HIBERNATE, wxActivateEvent); // Clipboard events -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TEXT_COPY, wxClipboardTextEvent); -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TEXT_CUT, wxClipboardTextEvent); -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TEXT_PASTE, wxClipboardTextEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TEXT_COPY, wxClipboardTextEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TEXT_CUT, wxClipboardTextEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TEXT_PASTE, wxClipboardTextEvent); // Generic command events // Note: a click is a higher-level event than button down/up @@ -836,7 +830,7 @@ wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_HELP, wxHelpEvent); wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_DETAILED_HELP, wxHelpEvent); // these 2 events are the same -#define wxEVT_COMMAND_TOOL_CLICKED wxEVT_COMMAND_MENU_SELECTED +#define wxEVT_TOOL wxEVT_MENU // ---------------------------------------------------------------------------- // Compatibility @@ -846,7 +840,7 @@ wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_DETAILED_HELP, wxHelpEvent); // wx/textctrl.h in all ports [yet], so declare it here as well // // still, any new code using it should include wx/textctrl.h explicitly -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TEXT, wxCommandEvent); // ---------------------------------------------------------------------------- @@ -946,6 +940,10 @@ public: int GetId() const { return m_id; } void SetId(int Id) { m_id = Id; } + // Returns the user data optionally associated with the event handler when + // using Connect() or Bind(). + wxObject *GetEventUserData() const { return m_callbackUserData; } + // Can instruct event processor that we wish to ignore this event // (treat as if the event table entry had not been found): this must be done // to allow the event processing by the base classes (calling event.Skip() @@ -1002,6 +1000,43 @@ public: return false; } + // This is for internal use only and is used for setting, testing and + // resetting of m_willBeProcessedAgain flag. + void SetWillBeProcessedAgain() + { + m_willBeProcessedAgain = true; + } + + bool WillBeProcessedAgain() + { + if ( m_willBeProcessedAgain ) + { + m_willBeProcessedAgain = false; + return true; + } + + return false; + } + + // This is also used only internally by ProcessEvent() to check if it + // should process the event normally or only restrict the search for the + // event handler to this object itself. + bool ShouldProcessOnlyIn(wxEvtHandler *h) const + { + return h == m_handlerToProcessOnlyIn; + } + + // Called to indicate that the result of ShouldProcessOnlyIn() wasn't taken + // into account. The existence of this function may seem counterintuitive + // but unfortunately it's needed by wxScrollHelperEvtHandler, see comments + // there. Don't even think of using this in your own code, this is a gross + // hack and is only needed because of wx complicated history and should + // never be used anywhere else. + void DidntHonourProcessOnlyIn() + { + m_handlerToProcessOnlyIn = NULL; + } + protected: wxObject* m_eventObject; wxEventType m_eventType; @@ -1012,6 +1047,10 @@ public: // m_callbackUserData is for internal usage only wxObject* m_callbackUserData; +private: + // If this handler + wxEvtHandler *m_handlerToProcessOnlyIn; + protected: // the propagation level: while it is positive, we propagate the event to // the parent window (if any) @@ -1026,6 +1065,11 @@ protected: // once for this event bool m_wasProcessed; + // This one is initially false too, but can be set to true to indicate that + // the event will be passed to another handler if it's not processed in + // this one. + bool m_willBeProcessedAgain; + protected: wxEvent(const wxEvent&); // for implementing Clone() wxEvent& operator=(const wxEvent&); // for derived classes operator=() @@ -1034,6 +1078,10 @@ private: // it needs to access our m_propagationLevel friend class WXDLLIMPEXP_FWD_BASE wxPropagateOnce; + // and this one needs to access our m_handlerToProcessOnlyIn + friend class WXDLLIMPEXP_FWD_BASE wxEventProcessInHandlerOnly; + + DECLARE_ABSTRACT_CLASS(wxEvent) }; @@ -1085,42 +1133,369 @@ private: wxDECLARE_NO_COPY_CLASS(wxPropagateOnce); }; +// A helper object used to temporarily make wxEvent::ShouldProcessOnlyIn() +// return true for the handler passed to its ctor. +class wxEventProcessInHandlerOnly +{ +public: + wxEventProcessInHandlerOnly(wxEvent& event, wxEvtHandler *handler) + : m_event(event), + m_handlerToProcessOnlyInOld(event.m_handlerToProcessOnlyIn) + { + m_event.m_handlerToProcessOnlyIn = handler; + } + + ~wxEventProcessInHandlerOnly() + { + m_event.m_handlerToProcessOnlyIn = m_handlerToProcessOnlyInOld; + } + +private: + wxEvent& m_event; + wxEvtHandler * const m_handlerToProcessOnlyInOld; + + wxDECLARE_NO_COPY_CLASS(wxEventProcessInHandlerOnly); +}; + + +class WXDLLIMPEXP_BASE wxEventBasicPayloadMixin +{ +public: + wxEventBasicPayloadMixin() + : m_commandInt(0), + m_extraLong(0) + { + } + + void SetString(const wxString& s) { m_cmdString = s; } + const wxString& GetString() const { return m_cmdString; } + + void SetInt(int i) { m_commandInt = i; } + int GetInt() const { return m_commandInt; } + + void SetExtraLong(long extraLong) { m_extraLong = extraLong; } + long GetExtraLong() const { return m_extraLong; } + +protected: + // Note: these variables have "cmd" or "command" in their name for backward compatibility: + // they used to be part of wxCommandEvent, not this mixin. + wxString m_cmdString; // String event argument + int m_commandInt; + long m_extraLong; // Additional information (e.g. select/deselect) + + wxDECLARE_NO_ASSIGN_CLASS(wxEventBasicPayloadMixin); +}; + +class WXDLLIMPEXP_BASE wxEventAnyPayloadMixin : public wxEventBasicPayloadMixin +{ +public: + wxEventAnyPayloadMixin() : wxEventBasicPayloadMixin() {} + +#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)) + + wxDECLARE_NO_ASSIGN_CLASS(wxEventBasicPayloadMixin); +}; + + +// Idle event +/* + wxEVT_IDLE + */ + +// Whether to always send idle events to windows, or +// to only send update events to those with the +// wxWS_EX_PROCESS_IDLE style. + +enum wxIdleMode +{ + // Send idle events to all windows + wxIDLE_PROCESS_ALL, + + // Send idle events to windows that have + // the wxWS_EX_PROCESS_IDLE flag specified + wxIDLE_PROCESS_SPECIFIED +}; + +class WXDLLIMPEXP_BASE wxIdleEvent : public wxEvent +{ +public: + wxIdleEvent() + : wxEvent(0, wxEVT_IDLE), + m_requestMore(false) + { } + wxIdleEvent(const wxIdleEvent& event) + : wxEvent(event), + m_requestMore(event.m_requestMore) + { } + + void RequestMore(bool needMore = true) { m_requestMore = needMore; } + bool MoreRequested() const { return m_requestMore; } + + virtual wxEvent *Clone() const { return new wxIdleEvent(*this); } + + // Specify how wxWidgets will send idle events: to + // all windows, or only to those which specify that they + // will process the events. + static void SetMode(wxIdleMode mode) { sm_idleMode = mode; } + + // Returns the idle event mode + static wxIdleMode GetMode() { return sm_idleMode; } + +protected: + bool m_requestMore; + static wxIdleMode sm_idleMode; + +private: + DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxIdleEvent) +}; + + +// Thread event + +class WXDLLIMPEXP_BASE wxThreadEvent : public wxEvent, + public wxEventAnyPayloadMixin +{ +public: + wxThreadEvent(wxEventType eventType = wxEVT_THREAD, int id = wxID_ANY) + : wxEvent(id, eventType) + { } + + wxThreadEvent(const wxThreadEvent& event) + : wxEvent(event), + wxEventAnyPayloadMixin(event) + { + // make sure our string member (which uses COW, aka refcounting) is not + // shared by other wxString instances: + SetString(GetString().Clone()); + } + + virtual wxEvent *Clone() const + { + return new wxThreadEvent(*this); + } + + // this is important to avoid that calling wxEventLoopBase::YieldFor thread events + // gets processed when this is unwanted: + virtual wxEventCategory GetEventCategory() const + { return wxEVT_CATEGORY_THREAD; } + +private: + DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxThreadEvent) +}; + + +// Asynchronous method call events: these event are processed by wxEvtHandler +// itself and result in a call to its Execute() method which simply calls the +// specified method. The difference with a simple method call is that this is +// done asynchronously, i.e. at some later time, instead of immediately when +// the event object is constructed. + +#ifdef wxHAS_CALL_AFTER + +// This is a base class used to process all method calls. +class wxAsyncMethodCallEvent : public wxEvent +{ +public: + wxAsyncMethodCallEvent(wxObject* object) + : wxEvent(wxID_ANY, wxEVT_ASYNC_METHOD_CALL) + { + SetEventObject(object); + } + + wxAsyncMethodCallEvent(const wxAsyncMethodCallEvent& other) + : wxEvent(other) + { + } + + virtual void Execute() = 0; +}; + +// This is a version for calling methods without parameters. +template +class wxAsyncMethodCallEvent0 : public wxAsyncMethodCallEvent +{ +public: + typedef T ObjectType; + typedef void (ObjectType::*MethodType)(); + + wxAsyncMethodCallEvent0(ObjectType* object, + MethodType method) + : wxAsyncMethodCallEvent(object), + m_object(object), + m_method(method) + { + } + + wxAsyncMethodCallEvent0(const wxAsyncMethodCallEvent0& other) + : wxAsyncMethodCallEvent(other), + m_object(other.m_object), + m_method(other.m_method) + { + } + + virtual wxEvent *Clone() const + { + return new wxAsyncMethodCallEvent0(*this); + } + + virtual void Execute() + { + (m_object->*m_method)(); + } + +private: + ObjectType* const m_object; + const MethodType m_method; +}; + +// This is a version for calling methods with a single parameter. +template +class wxAsyncMethodCallEvent1 : public wxAsyncMethodCallEvent +{ +public: + typedef T ObjectType; + typedef void (ObjectType::*MethodType)(T1 x1); + typedef typename wxRemoveRef::type ParamType1; + + wxAsyncMethodCallEvent1(ObjectType* object, + MethodType method, + const ParamType1& x1) + : wxAsyncMethodCallEvent(object), + m_object(object), + m_method(method), + m_param1(x1) + { + } + + wxAsyncMethodCallEvent1(const wxAsyncMethodCallEvent1& other) + : wxAsyncMethodCallEvent(other), + m_object(other.m_object), + m_method(other.m_method), + m_param1(other.m_param1) + { + } + + virtual wxEvent *Clone() const + { + return new wxAsyncMethodCallEvent1(*this); + } + + virtual void Execute() + { + (m_object->*m_method)(m_param1); + } + +private: + ObjectType* const m_object; + const MethodType m_method; + const ParamType1 m_param1; +}; + +// This is a version for calling methods with two parameters. +template +class wxAsyncMethodCallEvent2 : public wxAsyncMethodCallEvent +{ +public: + typedef T ObjectType; + typedef void (ObjectType::*MethodType)(T1 x1, T2 x2); + typedef typename wxRemoveRef::type ParamType1; + typedef typename wxRemoveRef::type ParamType2; + + wxAsyncMethodCallEvent2(ObjectType* object, + MethodType method, + const ParamType1& x1, + const ParamType2& x2) + : wxAsyncMethodCallEvent(object), + m_object(object), + m_method(method), + m_param1(x1), + m_param2(x2) + { + } + + wxAsyncMethodCallEvent2(const wxAsyncMethodCallEvent2& other) + : wxAsyncMethodCallEvent(other), + m_object(other.m_object), + m_method(other.m_method), + m_param1(other.m_param1), + m_param2(other.m_param2) + { + } + + virtual wxEvent *Clone() const + { + return new wxAsyncMethodCallEvent2(*this); + } + + virtual void Execute() + { + (m_object->*m_method)(m_param1, m_param2); + } + +private: + ObjectType* const m_object; + const MethodType m_method; + const ParamType1 m_param1; + const ParamType2 m_param2; +}; + +#endif // wxHAS_CALL_AFTER + #if wxUSE_GUI // Item or menu event class /* - wxEVT_COMMAND_BUTTON_CLICKED - wxEVT_COMMAND_CHECKBOX_CLICKED - wxEVT_COMMAND_CHOICE_SELECTED - wxEVT_COMMAND_LISTBOX_SELECTED - wxEVT_COMMAND_LISTBOX_DOUBLECLICKED - wxEVT_COMMAND_TEXT_UPDATED - wxEVT_COMMAND_TEXT_ENTER - wxEVT_COMMAND_MENU_SELECTED - wxEVT_COMMAND_SLIDER_UPDATED - wxEVT_COMMAND_RADIOBOX_SELECTED - wxEVT_COMMAND_RADIOBUTTON_SELECTED - wxEVT_COMMAND_SCROLLBAR_UPDATED - wxEVT_COMMAND_VLBOX_SELECTED - wxEVT_COMMAND_COMBOBOX_SELECTED - wxEVT_COMMAND_TOGGLEBUTTON_CLICKED + wxEVT_BUTTON + wxEVT_CHECKBOX + wxEVT_CHOICE + wxEVT_LISTBOX + wxEVT_LISTBOX_DCLICK + wxEVT_TEXT + wxEVT_TEXT_ENTER + wxEVT_MENU + wxEVT_SLIDER + wxEVT_RADIOBOX + wxEVT_RADIOBUTTON + wxEVT_SCROLLBAR + wxEVT_VLBOX + wxEVT_COMBOBOX + wxEVT_TOGGLEBUTTON */ -class WXDLLIMPEXP_CORE wxCommandEvent : public wxEvent +class WXDLLIMPEXP_CORE wxCommandEvent : public wxEvent, + public wxEventBasicPayloadMixin { public: wxCommandEvent(wxEventType commandType = wxEVT_NULL, int winid = 0); wxCommandEvent(const wxCommandEvent& event) : wxEvent(event), - m_cmdString(event.m_cmdString), - m_commandInt(event.m_commandInt), - m_extraLong(event.m_extraLong), + wxEventBasicPayloadMixin(event), m_clientData(event.m_clientData), m_clientObject(event.m_clientObject) - { } + { + // Because GetString() can retrieve the string text only on demand, we + // need to copy it explicitly. + if ( m_cmdString.empty() ) + m_cmdString = event.GetString(); + } // Set/Get client data from controls void SetClientData(void* clientData) { m_clientData = clientData; } @@ -1130,32 +1505,23 @@ public: void SetClientObject(wxClientData* clientObject) { m_clientObject = clientObject; } wxClientData *GetClientObject() const { return m_clientObject; } + // Note: this shadows wxEventBasicPayloadMixin::GetString(), because it does some + // GUI-specific hacks + wxString GetString() const; + // Get listbox selection if single-choice int GetSelection() const { return m_commandInt; } - // Set/Get listbox/choice selection string - void SetString(const wxString& s) { m_cmdString = s; } - wxString GetString() const; - // Get checkbox value bool IsChecked() const { return m_commandInt != 0; } // true if the listbox event was a selection. bool IsSelection() const { return (m_extraLong != 0); } - void SetExtraLong(long extraLong) { m_extraLong = extraLong; } - long GetExtraLong() const { return m_extraLong; } - - void SetInt(int i) { m_commandInt = i; } - int GetInt() const { return m_commandInt; } - virtual wxEvent *Clone() const { return new wxCommandEvent(*this); } virtual wxEventCategory GetEventCategory() const { return wxEVT_CATEGORY_USER_INPUT; } protected: - wxString m_cmdString; // String event argument - int m_commandInt; - long m_extraLong; // Additional information (e.g. select/deselect) void* m_clientData; // Arbitrary client data wxClientData* m_clientObject; // Arbitrary client object @@ -1195,44 +1561,6 @@ private: }; -// Thread event - -class WXDLLIMPEXP_CORE wxThreadEvent : public wxCommandEvent -{ -public: - wxThreadEvent(wxEventType eventType = wxEVT_COMMAND_THREAD, int id = wxID_ANY) - : wxCommandEvent(eventType, id) - { } - - wxThreadEvent(const wxThreadEvent& event) - : wxCommandEvent(event) - { - // make sure our string member (which uses COW, aka refcounting) is not - // shared by other wxString instances: - SetString(GetString().c_str()); - } - - 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; - } - - // this is important to avoid that calling wxEventLoopBase::YieldFor thread events - // gets processed when this is unwanted: - virtual wxEventCategory GetEventCategory() const - { return wxEVT_CATEGORY_THREAD; } - -private: - DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxThreadEvent) -}; - - - // Scroll event class, derived form wxCommandEvent. wxScrollEvents are // sent by wxSlider and wxScrollBar. /* @@ -1318,20 +1646,14 @@ private: wxEVT_LEFT_DCLICK wxEVT_MIDDLE_DCLICK wxEVT_RIGHT_DCLICK - wxEVT_NC_LEFT_DOWN - wxEVT_NC_LEFT_UP, - wxEVT_NC_MIDDLE_DOWN, - wxEVT_NC_MIDDLE_UP, - wxEVT_NC_RIGHT_DOWN, - wxEVT_NC_RIGHT_UP, - wxEVT_NC_MOTION, - wxEVT_NC_ENTER_WINDOW, - wxEVT_NC_LEAVE_WINDOW, - wxEVT_NC_LEFT_DCLICK, - wxEVT_NC_MIDDLE_DCLICK, - wxEVT_NC_RIGHT_DCLICK, */ +enum wxMouseWheelAxis +{ + wxMOUSE_WHEEL_VERTICAL, + wxMOUSE_WHEEL_HORIZONTAL +}; + class WXDLLIMPEXP_CORE wxMouseEvent : public wxEvent, public wxMouseState { @@ -1378,8 +1700,8 @@ public: bool LeftDClick() const { return (m_eventType == wxEVT_LEFT_DCLICK); } bool MiddleDClick() const { return (m_eventType == wxEVT_MIDDLE_DCLICK); } bool RightDClick() const { return (m_eventType == wxEVT_RIGHT_DCLICK); } - bool Aux1DClick() const { return (m_eventType == wxEVT_AUX1_UP); } - bool Aux2DClick() const { return (m_eventType == wxEVT_AUX2_UP); } + bool Aux1DClick() const { return (m_eventType == wxEVT_AUX1_DCLICK); } + bool Aux2DClick() const { return (m_eventType == wxEVT_AUX2_DCLICK); } // True if a button is down and the mouse is moving bool Dragging() const @@ -1419,10 +1741,10 @@ public: // should occur for each delta. int GetWheelDelta() const { return m_wheelDelta; } - // Gets the axis the wheel operation concerns, 0 being the y axis as on - // most mouse wheels, 1 is the x axis for things like MightyMouse scrolls - // or horizontal trackpad scrolling - int GetWheelAxis() const { return m_wheelAxis; } + // Gets the axis the wheel operation concerns; wxMOUSE_WHEEL_VERTICAL + // (most common case) or wxMOUSE_WHEEL_HORIZONTAL (for horizontal scrolling + // using e.g. a trackpad). + wxMouseWheelAxis GetWheelAxis() const { return m_wheelAxis; } // Returns the configured number of lines (or whatever) to be scrolled per // wheel action. Defaults to one. @@ -1444,7 +1766,7 @@ public: public: int m_clickCount; - int m_wheelAxis; + wxMouseWheelAxis m_wheelAxis; int m_wheelRotation; int m_wheelDelta; int m_linesPerAction; @@ -1482,7 +1804,7 @@ public: void SetCursor(const wxCursor& cursor) { m_cursor = cursor; } const wxCursor& GetCursor() const { return m_cursor; } - bool HasCursor() const { return m_cursor.Ok(); } + bool HasCursor() const { return m_cursor.IsOk(); } virtual wxEvent *Clone() const { return new wxSetCursorEvent(*this); } @@ -1519,7 +1841,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 @@ -1536,7 +1858,12 @@ class WXDLLIMPEXP_CORE wxKeyEvent : public wxEvent, { public: wxKeyEvent(wxEventType keyType = wxEVT_NULL); + + // Normal copy ctor and a ctor creating a new event for the same key as the + // given one but a different event type (this is used in implementation + // code only, do not use outside of the library). wxKeyEvent(const wxKeyEvent& evt); + wxKeyEvent(wxEventType eventType, const wxKeyEvent& evt); // get the key code: an ASCII7 char or an element of wxKeyCode enum int GetKeyCode() const { return (int)m_keyCode; } @@ -1558,24 +1885,38 @@ public: // Find the position of the event void GetPosition(wxCoord *xpos, wxCoord *ypos) const { - if (xpos) *xpos = m_x; - if (ypos) *ypos = m_y; + if (xpos) + *xpos = GetX(); + if (ypos) + *ypos = GetY(); } + // This version if provided only for backwards compatiblity, don't use. void GetPosition(long *xpos, long *ypos) const { - if (xpos) *xpos = (long)m_x; - if (ypos) *ypos = (long)m_y; + if (xpos) + *xpos = GetX(); + if (ypos) + *ypos = GetY(); } wxPoint GetPosition() const - { return wxPoint(m_x, m_y); } + { return wxPoint(GetX(), GetY()); } // Get X position - wxCoord GetX() const { return m_x; } + wxCoord GetX() const; // Get Y position - wxCoord GetY() const { return m_y; } + wxCoord GetY() const; + + // Can be called from wxEVT_CHAR_HOOK handler to allow generation of normal + // key events even though the event had been handled (by default they would + // not be generated in this case). + void DoAllowNextEvent() { m_allowNext = true; } + + // Return the value of the "allow next" flag, for internal use only. + bool IsNextEventAllowed() const { return m_allowNext; } + virtual wxEvent *Clone() const { return new wxKeyEvent(*this); } virtual wxEventCategory GetEventCategory() const { return wxEVT_CATEGORY_USER_INPUT; } @@ -1592,21 +1933,14 @@ public: // implicitly defined operator=() so need to do it this way: *static_cast(this) = evt; - m_x = evt.m_x; - m_y = evt.m_y; - - m_keyCode = evt.m_keyCode; - - m_rawCode = evt.m_rawCode; - m_rawFlags = evt.m_rawFlags; -#if wxUSE_UNICODE - m_uniChar = evt.m_uniChar; -#endif + DoAssignMembers(evt); } return *this; } public: + // Do not use these fields directly, they are initialized on demand, so + // call GetX() and GetY() or GetPosition() instead. wxCoord m_x, m_y; long m_keyCode; @@ -1623,6 +1957,46 @@ public: wxUint32 m_rawFlags; private: + // Set the event to propagate if necessary, i.e. if it's of wxEVT_CHAR_HOOK + // type. This is used by all ctors. + void InitPropagation() + { + if ( m_eventType == wxEVT_CHAR_HOOK ) + m_propagationLevel = wxEVENT_PROPAGATE_MAX; + + m_allowNext = false; + } + + // Copy only the event data present in this class, this is used by + // AssignKeyData() and copy ctor. + void DoAssignMembers(const wxKeyEvent& evt) + { + m_x = evt.m_x; + m_y = evt.m_y; + m_hasPosition = evt.m_hasPosition; + + m_keyCode = evt.m_keyCode; + + m_rawCode = evt.m_rawCode; + m_rawFlags = evt.m_rawFlags; +#if wxUSE_UNICODE + m_uniChar = evt.m_uniChar; +#endif + } + + // Initialize m_x and m_y using the current mouse cursor position if + // necessary. + void InitPositionIfNecessary() const; + + // If this flag is true, the normal key events should still be generated + // even if wxEVT_CHAR_HOOK had been handled. By default it is false as + // handling wxEVT_CHAR_HOOK suppresses all the subsequent events. + bool m_allowNext; + + // If true, m_x and m_y were already initialized. If false, try to get them + // when they're requested. + bool m_hasPosition; + DECLARE_DYNAMIC_CLASS(wxKeyEvent) }; @@ -1649,6 +2023,7 @@ public: { m_eventType = wxEVT_SIZING; m_id = id; } wxSize GetSize() const { return m_size; } + void SetSize(wxSize size) { m_size = size; } wxRect GetRect() const { return m_rect; } void SetRect(const wxRect& rect) { m_rect = rect; } @@ -1706,7 +2081,6 @@ private: /* wxEVT_PAINT wxEVT_NC_PAINT - wxEVT_PAINT_ICON */ #if wxDEBUG_LEVEL && (defined(__WXMSW__) || defined(__WXPM__)) @@ -2622,9 +2996,9 @@ private: // NOTE : under windows these events are *NOT* generated automatically // for a Rich Edit text control. /* -wxEVT_COMMAND_TEXT_COPY -wxEVT_COMMAND_TEXT_CUT -wxEVT_COMMAND_TEXT_PASTE +wxEVT_TEXT_COPY +wxEVT_TEXT_CUT +wxEVT_TEXT_PASTE */ class WXDLLIMPEXP_CORE wxClipboardTextEvent : public wxCommandEvent @@ -2679,59 +3053,6 @@ private: DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxContextMenuEvent) }; -#endif // wxUSE_GUI - -// Idle event -/* - wxEVT_IDLE - */ - -// Whether to always send idle events to windows, or -// to only send update events to those with the -// wxWS_EX_PROCESS_IDLE style. - -enum wxIdleMode -{ - // Send idle events to all windows - wxIDLE_PROCESS_ALL, - - // Send idle events to windows that have - // the wxWS_EX_PROCESS_IDLE flag specified - wxIDLE_PROCESS_SPECIFIED -}; - -class WXDLLIMPEXP_BASE wxIdleEvent : public wxEvent -{ -public: - wxIdleEvent() - : wxEvent(0, wxEVT_IDLE), - m_requestMore(false) - { } - wxIdleEvent(const wxIdleEvent& event) - : wxEvent(event), - m_requestMore(event.m_requestMore) - { } - - void RequestMore(bool needMore = true) { m_requestMore = needMore; } - bool MoreRequested() const { return m_requestMore; } - - virtual wxEvent *Clone() const { return new wxIdleEvent(*this); } - - // Specify how wxWidgets will send idle events: to - // all windows, or only to those which specify that they - // will process the events. - static void SetMode(wxIdleMode mode) { sm_idleMode = mode; } - - // Returns the idle event mode - static wxIdleMode GetMode() { return sm_idleMode; } - -protected: - bool m_requestMore; - static wxIdleMode sm_idleMode; - -private: - DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxIdleEvent) -}; /* TODO wxEVT_MOUSE_CAPTURE_CHANGED, @@ -2743,6 +3064,7 @@ private: wxEVT_COMPARE_ITEM */ +#endif // wxUSE_GUI // ============================================================================ @@ -2760,7 +3082,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 ), @@ -2888,7 +3213,7 @@ public: protected: // Init the hash table with the entries of the static event table. void InitHashTable(); - // Helper funtion of InitHashTable() to insert 1 entry into the hash table. + // Helper function of InitHashTable() to insert 1 entry into the hash table. void AddEntry(const wxEventTableEntry &entry); // Allocate and init with null pointers the base hash table. void AllocEventTypeTable(size_t size); @@ -2937,6 +3262,19 @@ public: bool IsUnlinked() const; + // Global event filters + // -------------------- + + // 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. + static void AddFilter(wxEventFilter* filter); + + // Remove a filter previously installed with AddFilter(). + static void RemoveFilter(wxEventFilter* filter); + // Event queuing and processing // ---------------------------- @@ -2953,6 +3291,20 @@ public: bool SafelyProcessEvent(wxEvent& event); // NOTE: uses ProcessEvent() + // This method tries to process the event in this event handler, including + // any preprocessing done by TryBefore() and all the handlers chained to + // it, but excluding the post-processing done in TryAfter(). + // + // It is meant to be called from ProcessEvent() only and is not virtual, + // additional event handlers can be hooked into the normal event processing + // logic using TryBefore() and TryAfter() hooks. + // + // You can also call it yourself to forward an event to another handler but + // without propagating it upwards if it's unhandled (this is usually + // unwanted when forwarding as the original handler would already do it if + // needed normally). + bool ProcessEventLocally(wxEvent& event); + // Schedule the given event to be processed later. It takes ownership of // the event pointer, i.e. it will be deleted later. This is safe to call // from multiple threads although you still need to ensure that wxString @@ -2983,6 +3335,46 @@ public: // NOTE: uses AddPendingEvent(); call only from secondary threads #endif +#ifdef wxHAS_CALL_AFTER + // Asynchronous method calls: these methods schedule the given method + // pointer for a later call (during the next idle event loop iteration). + // + // Notice that the method is called on this object itself, so the object + // CallAfter() is called on must have the correct dynamic type. + // + // These method can be used from another thread. + + template + void CallAfter(void (T::*method)()) + { + QueueEvent( + new wxAsyncMethodCallEvent0(static_cast(this), method) + ); + } + + // Notice that we use P1 and not T1 for the parameter to allow passing + // parameters that are convertible to the type taken by the method + // instead of being exactly the same, to be closer to the usual method call + // semantics. + template + void CallAfter(void (T::*method)(T1 x1), P1 x1) + { + QueueEvent( + new wxAsyncMethodCallEvent1( + static_cast(this), method, x1) + ); + } + + template + void CallAfter(void (T::*method)(T1 x1, T2 x2), P1 x1, P2 x2) + { + QueueEvent( + new wxAsyncMethodCallEvent2( + static_cast(this), method, x1, x2) + ); + } +#endif // wxHAS_CALL_AFTER + // Connecting and disconnecting // ---------------------------- @@ -3165,14 +3557,6 @@ public: void OnSinkDestroyed( wxEvtHandler *sink ); - // The method tries to process the event in this event handler. - // - // It is meant to be called from ProcessEvent() only and is not virtual, - // additional event handlers can be hooked into the normal event processing - // logic using TryBefore() and TryAfter() hooks. - bool ProcessEventHere(wxEvent& event); - - private: void DoBind(int winid, int lastId, @@ -3197,13 +3581,27 @@ protected: // validators. virtual bool TryBefore(wxEvent& event); + // This one is not a hook but just a helper which looks up the handler in + // this object itself. + // + // It is called from ProcessEventLocally() and normally shouldn't be called + // directly as doing it would ignore any chained event handlers + bool TryHereOnly(wxEvent& event); + + // Another helper which simply calls pre-processing hook and then tries to + // handle the event at this handler level. + bool TryBeforeAndHere(wxEvent& event) + { + return TryBefore(event) || TryHereOnly(event); + } + // 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 TryAfter(wxEvent& event); -#ifdef WXWIN_COMPATIBILITY_2_8 +#if WXWIN_COMPATIBILITY_2_8 // deprecated method: override TryBefore() instead of this one wxDEPRECATED_BUT_USED_INTERNALLY_INLINE( virtual bool TryValidator(wxEvent& WXUNUSED(event)), return false; ) @@ -3261,11 +3659,28 @@ private: // pass the event to wxTheApp instance, called from TryAfter() bool DoTryApp(wxEvent& event); + // try to process events in all handlers chained to this one + bool DoTryChain(wxEvent& event); + + // Head of the event filter linked list. + static wxEventFilter* ms_filterList; + DECLARE_DYNAMIC_CLASS_NO_COPY(wxEvtHandler) }; WX_DEFINE_ARRAY_WITH_DECL_PTR(wxEvtHandler *, wxEvtHandlerArray, class WXDLLIMPEXP_BASE); + +// Define an inline method of wxObjectEventFunctor which couldn't be defined +// before wxEvtHandler declaration: at least Sun CC refuses to compile function +// calls through pointer to member for forward-declared classes (see #12452). +inline void wxObjectEventFunctor::operator()(wxEvtHandler *handler, wxEvent& event) +{ + wxEvtHandler * const realHandler = m_handler ? m_handler : handler; + + (realHandler->*m_method)(event); +} + // ---------------------------------------------------------------------------- // wxEventConnectionRef represents all connections between two event handlers // and enables automatic disconnect when an event handler sink goes out of @@ -3338,11 +3753,14 @@ inline void wxQueueEvent(wxEvtHandler *dest, wxEvent *event) typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&); typedef void (wxEvtHandler::*wxIdleEventFunction)(wxIdleEvent&); +typedef void (wxEvtHandler::*wxThreadEventFunction)(wxThreadEvent&); #define wxEventHandler(func) \ wxEVENT_HANDLER_CAST(wxEventFunction, func) #define wxIdleEventHandler(func) \ wxEVENT_HANDLER_CAST(wxIdleEventFunction, func) +#define wxThreadEventHandler(func) \ + wxEVENT_HANDLER_CAST(wxThreadEventFunction, func) #if wxUSE_GUI @@ -3371,7 +3789,6 @@ protected: }; typedef void (wxEvtHandler::*wxCommandEventFunction)(wxCommandEvent&); -typedef void (wxEvtHandler::*wxThreadEventFunction)(wxThreadEvent&); typedef void (wxEvtHandler::*wxScrollEventFunction)(wxScrollEvent&); typedef void (wxEvtHandler::*wxScrollWinEventFunction)(wxScrollWinEvent&); typedef void (wxEvtHandler::*wxSizeEventFunction)(wxSizeEvent&); @@ -3411,8 +3828,6 @@ typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent& #define wxCommandEventHandler(func) \ wxEVENT_HANDLER_CAST(wxCommandEventFunction, func) -#define wxThreadEventHandler(func) \ - wxEVENT_HANDLER_CAST(wxThreadEventFunction, func) #define wxScrollEventHandler(func) \ wxEVENT_HANDLER_CAST(wxScrollEventFunction, func) #define wxScrollWinEventHandler(func) \ @@ -3490,20 +3905,20 @@ typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent& // N.B. In GNU-WIN32, you *have* to take the address of a member function // (use &) or the compiler crashes... -#define DECLARE_EVENT_TABLE() \ - private: \ - static const wxEventTableEntry sm_eventTableEntries[]; \ - protected: \ - static const wxEventTable sm_eventTable; \ - virtual const wxEventTable* GetEventTable() const; \ - static wxEventHashTable sm_eventHashTable; \ - virtual wxEventHashTable& GetEventHashTable() const; +#define wxDECLARE_EVENT_TABLE() \ + private: \ + static const wxEventTableEntry sm_eventTableEntries[]; \ + protected: \ + static const wxEventTable sm_eventTable; \ + virtual const wxEventTable* GetEventTable() const; \ + static wxEventHashTable sm_eventHashTable; \ + virtual wxEventHashTable& GetEventHashTable() const // N.B.: when building DLL with Borland C++ 5.5 compiler, you must initialize // sm_eventTable before using it in GetEventTable() or the compiler gives // E2233 (see http://groups.google.com/groups?selm=397dcc8a%241_2%40dnews) -#define BEGIN_EVENT_TABLE(theClass, baseClass) \ +#define wxBEGIN_EVENT_TABLE(theClass, baseClass) \ const wxEventTable theClass::sm_eventTable = \ { &baseClass::sm_eventTable, &theClass::sm_eventTableEntries[0] }; \ const wxEventTable *theClass::GetEventTable() const \ @@ -3513,7 +3928,7 @@ typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent& { return theClass::sm_eventHashTable; } \ const wxEventTableEntry theClass::sm_eventTableEntries[] = { \ -#define BEGIN_EVENT_TABLE_TEMPLATE1(theClass, baseClass, T1) \ +#define wxBEGIN_EVENT_TABLE_TEMPLATE1(theClass, baseClass, T1) \ template \ const wxEventTable theClass::sm_eventTable = \ { &baseClass::sm_eventTable, &theClass::sm_eventTableEntries[0] }; \ @@ -3528,7 +3943,7 @@ typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent& template \ const wxEventTableEntry theClass::sm_eventTableEntries[] = { \ -#define BEGIN_EVENT_TABLE_TEMPLATE2(theClass, baseClass, T1, T2) \ +#define wxBEGIN_EVENT_TABLE_TEMPLATE2(theClass, baseClass, T1, T2) \ template \ const wxEventTable theClass::sm_eventTable = \ { &baseClass::sm_eventTable, &theClass::sm_eventTableEntries[0] }; \ @@ -3543,7 +3958,7 @@ typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent& template \ const wxEventTableEntry theClass::sm_eventTableEntries[] = { \ -#define BEGIN_EVENT_TABLE_TEMPLATE3(theClass, baseClass, T1, T2, T3) \ +#define wxBEGIN_EVENT_TABLE_TEMPLATE3(theClass, baseClass, T1, T2, T3) \ template \ const wxEventTable theClass::sm_eventTable = \ { &baseClass::sm_eventTable, &theClass::sm_eventTableEntries[0] }; \ @@ -3558,7 +3973,7 @@ typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent& template \ const wxEventTableEntry theClass::sm_eventTableEntries[] = { \ -#define BEGIN_EVENT_TABLE_TEMPLATE4(theClass, baseClass, T1, T2, T3, T4) \ +#define wxBEGIN_EVENT_TABLE_TEMPLATE4(theClass, baseClass, T1, T2, T3, T4) \ template \ const wxEventTable theClass::sm_eventTable = \ { &baseClass::sm_eventTable, &theClass::sm_eventTableEntries[0] }; \ @@ -3573,7 +3988,7 @@ typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent& template \ const wxEventTableEntry theClass::sm_eventTableEntries[] = { \ -#define BEGIN_EVENT_TABLE_TEMPLATE5(theClass, baseClass, T1, T2, T3, T4, T5) \ +#define wxBEGIN_EVENT_TABLE_TEMPLATE5(theClass, baseClass, T1, T2, T3, T4, T5) \ template \ const wxEventTable theClass::sm_eventTable = \ { &baseClass::sm_eventTable, &theClass::sm_eventTableEntries[0] }; \ @@ -3588,7 +4003,7 @@ typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent& template \ const wxEventTableEntry theClass::sm_eventTableEntries[] = { \ -#define BEGIN_EVENT_TABLE_TEMPLATE7(theClass, baseClass, T1, T2, T3, T4, T5, T6, T7) \ +#define wxBEGIN_EVENT_TABLE_TEMPLATE7(theClass, baseClass, T1, T2, T3, T4, T5, T6, T7) \ template \ const wxEventTable theClass::sm_eventTable = \ { &baseClass::sm_eventTable, &theClass::sm_eventTableEntries[0] }; \ @@ -3603,7 +4018,7 @@ typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent& template \ const wxEventTableEntry theClass::sm_eventTableEntries[] = { \ -#define BEGIN_EVENT_TABLE_TEMPLATE8(theClass, baseClass, T1, T2, T3, T4, T5, T6, T7, T8) \ +#define wxBEGIN_EVENT_TABLE_TEMPLATE8(theClass, baseClass, T1, T2, T3, T4, T5, T6, T7, T8) \ template \ const wxEventTable theClass::sm_eventTable = \ { &baseClass::sm_eventTable, &theClass::sm_eventTableEntries[0] }; \ @@ -3618,7 +4033,8 @@ typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent& template \ const wxEventTableEntry theClass::sm_eventTableEntries[] = { \ -#define END_EVENT_TABLE() DECLARE_EVENT_TABLE_TERMINATOR() }; +#define wxEND_EVENT_TABLE() \ + wxDECLARE_EVENT_TABLE_TERMINATOR() }; /* * Event table macros @@ -3632,7 +4048,7 @@ typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent& // - id1, id2 ids of the first/last id // - fn the function (should be cast to the right type) #define wx__DECLARE_EVT2(evt, id1, id2, fn) \ - DECLARE_EVENT_TABLE_ENTRY(evt, id1, id2, fn, NULL), + wxDECLARE_EVENT_TABLE_ENTRY(evt, id1, id2, fn, NULL), #define wx__DECLARE_EVT1(evt, id, fn) \ wx__DECLARE_EVT2(evt, id, wxID_ANY, fn) #define wx__DECLARE_EVT0(evt, fn) \ @@ -3821,33 +4237,33 @@ typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent& #endif // WXWIN_COMPATIBILITY_2_6 // Convenience macros for commonly-used commands -#define EVT_CHECKBOX(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_CHECKBOX_CLICKED, winid, wxCommandEventHandler(func)) -#define EVT_CHOICE(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_CHOICE_SELECTED, winid, wxCommandEventHandler(func)) -#define EVT_LISTBOX(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_LISTBOX_SELECTED, winid, wxCommandEventHandler(func)) -#define EVT_LISTBOX_DCLICK(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, winid, wxCommandEventHandler(func)) -#define EVT_MENU(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_MENU_SELECTED, winid, wxCommandEventHandler(func)) -#define EVT_MENU_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_COMMAND_MENU_SELECTED, id1, id2, wxCommandEventHandler(func)) +#define EVT_CHECKBOX(winid, func) wx__DECLARE_EVT1(wxEVT_CHECKBOX, winid, wxCommandEventHandler(func)) +#define EVT_CHOICE(winid, func) wx__DECLARE_EVT1(wxEVT_CHOICE, winid, wxCommandEventHandler(func)) +#define EVT_LISTBOX(winid, func) wx__DECLARE_EVT1(wxEVT_LISTBOX, winid, wxCommandEventHandler(func)) +#define EVT_LISTBOX_DCLICK(winid, func) wx__DECLARE_EVT1(wxEVT_LISTBOX_DCLICK, winid, wxCommandEventHandler(func)) +#define EVT_MENU(winid, func) wx__DECLARE_EVT1(wxEVT_MENU, winid, wxCommandEventHandler(func)) +#define EVT_MENU_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_MENU, id1, id2, wxCommandEventHandler(func)) #if defined(__SMARTPHONE__) # define EVT_BUTTON(winid, func) EVT_MENU(winid, func) #else -# define EVT_BUTTON(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_BUTTON_CLICKED, winid, wxCommandEventHandler(func)) +# define EVT_BUTTON(winid, func) wx__DECLARE_EVT1(wxEVT_BUTTON, winid, wxCommandEventHandler(func)) #endif -#define EVT_SLIDER(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_SLIDER_UPDATED, winid, wxCommandEventHandler(func)) -#define EVT_RADIOBOX(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_RADIOBOX_SELECTED, winid, wxCommandEventHandler(func)) -#define EVT_RADIOBUTTON(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_RADIOBUTTON_SELECTED, winid, wxCommandEventHandler(func)) +#define EVT_SLIDER(winid, func) wx__DECLARE_EVT1(wxEVT_SLIDER, winid, wxCommandEventHandler(func)) +#define EVT_RADIOBOX(winid, func) wx__DECLARE_EVT1(wxEVT_RADIOBOX, winid, wxCommandEventHandler(func)) +#define EVT_RADIOBUTTON(winid, func) wx__DECLARE_EVT1(wxEVT_RADIOBUTTON, winid, wxCommandEventHandler(func)) // EVT_SCROLLBAR is now obsolete since we use EVT_COMMAND_SCROLL... events -#define EVT_SCROLLBAR(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_SCROLLBAR_UPDATED, winid, wxCommandEventHandler(func)) -#define EVT_VLBOX(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_VLBOX_SELECTED, winid, wxCommandEventHandler(func)) -#define EVT_COMBOBOX(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_COMBOBOX_SELECTED, winid, wxCommandEventHandler(func)) -#define EVT_TOOL(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_TOOL_CLICKED, winid, wxCommandEventHandler(func)) -#define EVT_TOOL_DROPDOWN(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED, winid, wxCommandEventHandler(func)) -#define EVT_TOOL_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_COMMAND_TOOL_CLICKED, id1, id2, wxCommandEventHandler(func)) -#define EVT_TOOL_RCLICKED(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_TOOL_RCLICKED, winid, wxCommandEventHandler(func)) -#define EVT_TOOL_RCLICKED_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_COMMAND_TOOL_RCLICKED, id1, id2, wxCommandEventHandler(func)) -#define EVT_TOOL_ENTER(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_TOOL_ENTER, winid, wxCommandEventHandler(func)) -#define EVT_CHECKLISTBOX(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, winid, wxCommandEventHandler(func)) -#define EVT_COMBOBOX_DROPDOWN(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_COMBOBOX_DROPDOWN, winid, wxCommandEventHandler(func)) -#define EVT_COMBOBOX_CLOSEUP(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_COMBOBOX_CLOSEUP, winid, wxCommandEventHandler(func)) +#define EVT_SCROLLBAR(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLLBAR, winid, wxCommandEventHandler(func)) +#define EVT_VLBOX(winid, func) wx__DECLARE_EVT1(wxEVT_VLBOX, winid, wxCommandEventHandler(func)) +#define EVT_COMBOBOX(winid, func) wx__DECLARE_EVT1(wxEVT_COMBOBOX, winid, wxCommandEventHandler(func)) +#define EVT_TOOL(winid, func) wx__DECLARE_EVT1(wxEVT_TOOL, winid, wxCommandEventHandler(func)) +#define EVT_TOOL_DROPDOWN(winid, func) wx__DECLARE_EVT1(wxEVT_TOOL_DROPDOWN, winid, wxCommandEventHandler(func)) +#define EVT_TOOL_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_TOOL, id1, id2, wxCommandEventHandler(func)) +#define EVT_TOOL_RCLICKED(winid, func) wx__DECLARE_EVT1(wxEVT_TOOL_RCLICKED, winid, wxCommandEventHandler(func)) +#define EVT_TOOL_RCLICKED_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_TOOL_RCLICKED, id1, id2, wxCommandEventHandler(func)) +#define EVT_TOOL_ENTER(winid, func) wx__DECLARE_EVT1(wxEVT_TOOL_ENTER, winid, wxCommandEventHandler(func)) +#define EVT_CHECKLISTBOX(winid, func) wx__DECLARE_EVT1(wxEVT_CHECKLISTBOX, winid, wxCommandEventHandler(func)) +#define EVT_COMBOBOX_DROPDOWN(winid, func) wx__DECLARE_EVT1(wxEVT_COMBOBOX_DROPDOWN, winid, wxCommandEventHandler(func)) +#define EVT_COMBOBOX_CLOSEUP(winid, func) wx__DECLARE_EVT1(wxEVT_COMBOBOX_CLOSEUP, winid, wxCommandEventHandler(func)) // Generic command events #define EVT_COMMAND_LEFT_CLICK(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_LEFT_CLICK, winid, wxCommandEventHandler(func)) @@ -3890,12 +4306,12 @@ typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent& #define EVT_COMMAND_CONTEXT_MENU(winid, func) wx__DECLARE_EVT1(wxEVT_CONTEXT_MENU, winid, wxContextMenuEventHandler(func)) // Clipboard text Events -#define EVT_TEXT_CUT(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_TEXT_CUT, winid, wxClipboardTextEventHandler(func)) -#define EVT_TEXT_COPY(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_TEXT_COPY, winid, wxClipboardTextEventHandler(func)) -#define EVT_TEXT_PASTE(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_TEXT_PASTE, winid, wxClipboardTextEventHandler(func)) +#define EVT_TEXT_CUT(winid, func) wx__DECLARE_EVT1(wxEVT_TEXT_CUT, winid, wxClipboardTextEventHandler(func)) +#define EVT_TEXT_COPY(winid, func) wx__DECLARE_EVT1(wxEVT_TEXT_COPY, winid, wxClipboardTextEventHandler(func)) +#define EVT_TEXT_PASTE(winid, func) wx__DECLARE_EVT1(wxEVT_TEXT_PASTE, winid, wxClipboardTextEventHandler(func)) // Thread events -#define EVT_THREAD(id, func) wx__DECLARE_EVT1(wxEVT_COMMAND_THREAD, id, wxThreadEventHandler(func)) +#define EVT_THREAD(id, func) wx__DECLARE_EVT1(wxEVT_THREAD, id, wxThreadEventHandler(func)) // ---------------------------------------------------------------------------- // Helper functions @@ -3927,12 +4343,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 @@ -3944,4 +4360,66 @@ WXDLLIMPEXP_CORE wxWindow* wxFindFocusDescendant(wxWindow* ancestor); #endif // wxUSE_GUI + +// ---------------------------------------------------------------------------- +// Compatibility macro aliases +// ---------------------------------------------------------------------------- + +// deprecated variants _not_ requiring a semicolon after them and without wx prefix +// (note that also some wx-prefixed macro do _not_ require a semicolon because +// it's not always possible to force the compire to require it) + +#define DECLARE_EVENT_TABLE_ENTRY(type, winid, idLast, fn, obj) \ + wxDECLARE_EVENT_TABLE_ENTRY(type, winid, idLast, fn, obj) +#define DECLARE_EVENT_TABLE_TERMINATOR() wxDECLARE_EVENT_TABLE_TERMINATOR() +#define DECLARE_EVENT_TABLE() wxDECLARE_EVENT_TABLE(); +#define BEGIN_EVENT_TABLE(a,b) wxBEGIN_EVENT_TABLE(a,b) +#define BEGIN_EVENT_TABLE_TEMPLATE1(a,b,c) wxBEGIN_EVENT_TABLE_TEMPLATE1(a,b,c) +#define BEGIN_EVENT_TABLE_TEMPLATE2(a,b,c,d) wxBEGIN_EVENT_TABLE_TEMPLATE2(a,b,c,d) +#define BEGIN_EVENT_TABLE_TEMPLATE3(a,b,c,d,e) wxBEGIN_EVENT_TABLE_TEMPLATE3(a,b,c,d,e) +#define BEGIN_EVENT_TABLE_TEMPLATE4(a,b,c,d,e,f) wxBEGIN_EVENT_TABLE_TEMPLATE4(a,b,c,d,e,f) +#define BEGIN_EVENT_TABLE_TEMPLATE5(a,b,c,d,e,f,g) wxBEGIN_EVENT_TABLE_TEMPLATE5(a,b,c,d,e,f,g) +#define BEGIN_EVENT_TABLE_TEMPLATE6(a,b,c,d,e,f,g,h) wxBEGIN_EVENT_TABLE_TEMPLATE6(a,b,c,d,e,f,g,h) +#define END_EVENT_TABLE() wxEND_EVENT_TABLE() + +// other obsolete event declaration/definition macros; we don't need them any longer +// but we keep them for compatibility as it doesn't cost us anything anyhow +#define BEGIN_DECLARE_EVENT_TYPES() +#define END_DECLARE_EVENT_TYPES() +#define DECLARE_EXPORTED_EVENT_TYPE(expdecl, name, value) \ + extern expdecl const wxEventType name; +#define DECLARE_EVENT_TYPE(name, value) \ + DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE, name, value) +#define DECLARE_LOCAL_EVENT_TYPE(name, value) \ + DECLARE_EXPORTED_EVENT_TYPE(wxEMPTY_PARAMETER_VALUE, name, value) +#define DEFINE_EVENT_TYPE(name) const wxEventType name = wxNewEventType(); +#define DEFINE_LOCAL_EVENT_TYPE(name) DEFINE_EVENT_TYPE(name) + +// alias for backward compatibility with 2.9.0: +#define wxEVT_COMMAND_THREAD wxEVT_THREAD +// other old wxEVT_COMMAND_* constants +#define wxEVT_COMMAND_BUTTON_CLICKED wxEVT_BUTTON +#define wxEVT_COMMAND_CHECKBOX_CLICKED wxEVT_CHECKBOX +#define wxEVT_COMMAND_CHOICE_SELECTED wxEVT_CHOICE +#define wxEVT_COMMAND_LISTBOX_SELECTED wxEVT_LISTBOX +#define wxEVT_COMMAND_LISTBOX_DOUBLECLICKED wxEVT_LISTBOX_DCLICK +#define wxEVT_COMMAND_CHECKLISTBOX_TOGGLED wxEVT_CHECKLISTBOX +#define wxEVT_COMMAND_MENU_SELECTED wxEVT_MENU +#define wxEVT_COMMAND_TOOL_CLICKED wxEVT_TOOL +#define wxEVT_COMMAND_SLIDER_UPDATED wxEVT_SLIDER +#define wxEVT_COMMAND_RADIOBOX_SELECTED wxEVT_RADIOBOX +#define wxEVT_COMMAND_RADIOBUTTON_SELECTED wxEVT_RADIOBUTTON +#define wxEVT_COMMAND_SCROLLBAR_UPDATED wxEVT_SCROLLBAR +#define wxEVT_COMMAND_VLBOX_SELECTED wxEVT_VLBOX +#define wxEVT_COMMAND_COMBOBOX_SELECTED wxEVT_COMBOBOX +#define wxEVT_COMMAND_TOOL_RCLICKED wxEVT_TOOL_RCLICKED +#define wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED wxEVT_TOOL_DROPDOWN +#define wxEVT_COMMAND_TOOL_ENTER wxEVT_TOOL_ENTER +#define wxEVT_COMMAND_COMBOBOX_DROPDOWN wxEVT_COMBOBOX_DROPDOWN +#define wxEVT_COMMAND_COMBOBOX_CLOSEUP wxEVT_COMBOBOX_CLOSEUP +#define wxEVT_COMMAND_TEXT_COPY wxEVT_TEXT_COPY +#define wxEVT_COMMAND_TEXT_CUT wxEVT_TEXT_CUT +#define wxEVT_COMMAND_TEXT_PASTE wxEVT_TEXT_PASTE +#define wxEVT_COMMAND_TEXT_UPDATED wxEVT_TEXT + #endif // _WX_EVENT_H_