X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3bad8c39260b8bda7762b4aacd49346b46064a2a..e62b7692622880d48b62f555c1e356883232956c:/include/wx/event.h diff --git a/include/wx/event.h b/include/wx/event.h index 87a1a6a304..1dcdf333dc 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -4,7 +4,6 @@ // Author: Julian Smart // Modified by: // Created: 01/02/97 -// RCS-ID: $Id$ // Copyright: (c) wxWidgets team // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -986,6 +985,9 @@ public: m_propagationLevel = propagationLevel; } + // This method is for internal use only and allows to get the object that + // is propagating this event upwards the window hierarchy, if any. + wxEvtHandler* GetPropagatedFrom() const { return m_propagatedFrom; } // This is for internal use only and is only called by // wxEvtHandler::ProcessEvent() to check whether it's the first time this @@ -1056,6 +1058,10 @@ protected: // the parent window (if any) int m_propagationLevel; + // The object that the event is being propagated from, initially NULL and + // only set by wxPropagateOnce. + wxEvtHandler* m_propagatedFrom; + bool m_skipped; bool m_isCommandEvent; @@ -1075,7 +1081,7 @@ protected: wxEvent& operator=(const wxEvent&); // for derived classes operator=() private: - // it needs to access our m_propagationLevel + // It needs to access our m_propagationLevel and m_propagatedFrom fields. friend class WXDLLIMPEXP_FWD_BASE wxPropagateOnce; // and this one needs to access our m_handlerToProcessOnlyIn @@ -1109,26 +1115,35 @@ private: }; /* - * Another one to temporarily lower propagation level. + * Helper used to indicate that an event is propagated upwards the window + * hierarchy by the given window. */ class WXDLLIMPEXP_BASE wxPropagateOnce { public: - wxPropagateOnce(wxEvent& event) : m_event(event) + // The handler argument should normally be non-NULL to allow the parent + // event handler to know that it's being used to process an event coming + // from the child, it's only NULL by default for backwards compatibility. + wxPropagateOnce(wxEvent& event, wxEvtHandler* handler = NULL) + : m_event(event), + m_propagatedFromOld(event.m_propagatedFrom) { wxASSERT_MSG( m_event.m_propagationLevel > 0, wxT("shouldn't be used unless ShouldPropagate()!") ); m_event.m_propagationLevel--; + m_event.m_propagatedFrom = handler; } ~wxPropagateOnce() { + m_event.m_propagatedFrom = m_propagatedFromOld; m_event.m_propagationLevel++; } private: wxEvent& m_event; + wxEvtHandler* const m_propagatedFromOld; wxDECLARE_NO_COPY_CLASS(wxPropagateOnce); }; @@ -1454,6 +1469,39 @@ private: const ParamType2 m_param2; }; +// This is a version for calling any functors +template +class wxAsyncMethodCallEventFunctor : public wxAsyncMethodCallEvent +{ +public: + typedef T FunctorType; + + wxAsyncMethodCallEventFunctor(wxObject *object, const FunctorType& fn) + : wxAsyncMethodCallEvent(object), + m_fn(fn) + { + } + + wxAsyncMethodCallEventFunctor(const wxAsyncMethodCallEventFunctor& other) + : wxAsyncMethodCallEvent(other), + m_fn(other.m_fn) + { + } + + virtual wxEvent *Clone() const + { + return new wxAsyncMethodCallEventFunctor(*this); + } + + virtual void Execute() + { + m_fn(); + } + +private: + FunctorType m_fn; +}; + #endif // wxHAS_CALL_AFTER @@ -1747,9 +1795,13 @@ public: wxMouseWheelAxis GetWheelAxis() const { return m_wheelAxis; } // Returns the configured number of lines (or whatever) to be scrolled per - // wheel action. Defaults to one. + // wheel action. Defaults to three. int GetLinesPerAction() const { return m_linesPerAction; } + // Returns the configured number of columns (or whatever) to be scrolled per + // wheel action. Defaults to three. + int GetColumnsPerAction() const { return m_columnsPerAction; } + // Is the system set to do page scrolling? bool IsPageScroll() const { return ((unsigned int)m_linesPerAction == UINT_MAX); } @@ -1770,6 +1822,7 @@ public: int m_wheelRotation; int m_wheelDelta; int m_linesPerAction; + int m_columnsPerAction; protected: void Assign(const wxMouseEvent& evt); @@ -3373,6 +3426,12 @@ public: static_cast(this), method, x1, x2) ); } + + template + void CallAfter(const T& fn) + { + QueueEvent(new wxAsyncMethodCallEventFunctor(this, fn)); + } #endif // wxHAS_CALL_AFTER