X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f8a7dd5f4162313d76ae2e2df46740f3a9e49071..ff46415213f7435aa64ab4f5b7dfdbb7b31f3796:/include/wx/event.h diff --git a/include/wx/event.h b/include/wx/event.h index 225da47b42..e7536eb9ce 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -27,6 +27,7 @@ #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" @@ -995,6 +996,11 @@ public: 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 ShouldProcessHereOnly() const { return m_processHereOnly; } + protected: wxObject* m_eventObject; wxEventType m_eventType; @@ -1019,6 +1025,11 @@ protected: // once for this event bool m_wasProcessed; + // this flag is used by ProcessEventLocally() to prevent ProcessEvent() + // from doing its usual stuff and force it to just call TryHere() instead, + // see the comment there explaining why is this needed + bool m_processHereOnly; + protected: wxEvent(const wxEvent&); // for implementing Clone() wxEvent& operator=(const wxEvent&); // for derived classes operator=() @@ -1027,6 +1038,10 @@ private: // it needs to access our m_propagationLevel friend class WXDLLIMPEXP_FWD_BASE wxPropagateOnce; + // and this one needs to access our m_processHereOnly + friend class WXDLLIMPEXP_FWD_BASE wxEventProcessHereOnly; + + DECLARE_ABSTRACT_CLASS(wxEvent) }; @@ -1078,6 +1093,32 @@ private: wxDECLARE_NO_COPY_CLASS(wxPropagateOnce); }; +// A helper used by ProcessEventLocally() to restrict the event processing +// to this handler only. +class WXDLLIMPEXP_BASE wxEventProcessHereOnly +{ +public: + wxEventProcessHereOnly(wxEvent& event) : m_event(event) + { + // This would be unexpected and would also restore the wrong value in + // this class dtor so if even does happen legitimately we'd need to + // store the value in ctor and restore it in dtor. + wxASSERT_MSG( !m_event.m_processHereOnly, + "shouldn't be used twice for the same event" ); + + m_event.m_processHereOnly = true; + } + + ~wxEventProcessHereOnly() + { + m_event.m_processHereOnly = false; + } + +private: + wxEvent& m_event; + + wxDECLARE_NO_COPY_CLASS(wxEventProcessHereOnly); +}; #if wxUSE_GUI @@ -1203,6 +1244,10 @@ 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 @@ -1215,6 +1260,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) }; @@ -2944,6 +3006,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 @@ -3156,14 +3232,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, @@ -3188,6 +3256,12 @@ 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 called from ProcessEventLocally() and normally + // shouldn't be called directly as doing it would ignore any chained event + // handlers + bool TryHere(wxEvent& 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 // @@ -3252,6 +3326,9 @@ 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); + DECLARE_DYNAMIC_CLASS_NO_COPY(wxEvtHandler) };