X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ad684023c5dc11e07170e2a030eec9f9b493f650..f8b1df0b15f843b8f47efb9bee38f1de0fa95020:/include/wx/event.h diff --git a/include/wx/event.h b/include/wx/event.h index 390c4484bb..3e5bc79873 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -23,15 +23,14 @@ #endif #include "wx/dynarray.h" +#include "wx/thread.h" +#include "wx/tracker.h" // ---------------------------------------------------------------------------- // forward declarations // ---------------------------------------------------------------------------- class WXDLLIMPEXP_FWD_BASE wxList; -#if wxUSE_THREADS - class WXDLLIMPEXP_FWD_BASE wxCriticalSection; -#endif #if wxUSE_GUI class WXDLLIMPEXP_FWD_CORE wxDC; class WXDLLIMPEXP_FWD_CORE wxMenu; @@ -779,7 +778,7 @@ public: virtual wxEvent *Clone() const { return new wxMouseEvent(*this); } - wxMouseEvent& operator=(const wxMouseEvent& event) { Assign(event); return *this; } + wxMouseEvent& operator=(const wxMouseEvent& event) { if (&event != this) Assign(event); return *this; } public: wxCoord m_x, m_y; @@ -941,22 +940,24 @@ public: // example) wxKeyEvent& operator=(const wxKeyEvent& evt) { - m_x = evt.m_x; - m_y = evt.m_y; - - m_keyCode = evt.m_keyCode; - - m_controlDown = evt.m_controlDown; - m_shiftDown = evt.m_shiftDown; - m_altDown = evt.m_altDown; - m_metaDown = evt.m_metaDown; - m_scanCode = evt.m_scanCode; - m_rawCode = evt.m_rawCode; - m_rawFlags = evt.m_rawFlags; + if (&evt != this) + { + m_x = evt.m_x; + m_y = evt.m_y; + + m_keyCode = evt.m_keyCode; + + m_controlDown = evt.m_controlDown; + m_shiftDown = evt.m_shiftDown; + m_altDown = evt.m_altDown; + m_metaDown = evt.m_metaDown; + m_scanCode = evt.m_scanCode; + m_rawCode = evt.m_rawCode; + m_rawFlags = evt.m_rawFlags; #if wxUSE_UNICODE - m_uniChar = evt.m_uniChar; + m_uniChar = evt.m_uniChar; #endif - + } return *this; } @@ -2257,11 +2258,44 @@ protected: DECLARE_NO_COPY_CLASS(wxEventHashTable) }; +// ---------------------------------------------------------------------------- +// wxEventConnectionRef: A class that represents all connections between two event +// handlers and enables automatic disconnect when an event handler sink goes +// out of scope. Each connection/disconnect increases/decreases ref count, and +// when zero the node goes out of scope. +// ---------------------------------------------------------------------------- + +struct wxEventConnectionRef : public wxTrackerNode { + + wxEventConnectionRef() : m_src(0), m_sink(0), m_refCount(0) { } + wxEventConnectionRef( wxEvtHandler *src, wxEvtHandler *sink ); + virtual ~wxEventConnectionRef(); + + // The sink is being destroyed + virtual void OnObjectDestroy( ); + virtual wxTrackerNodeType GetType( ){ return EventConnectionRef; } + + void IncRef( ) { m_refCount++; } + void DecRef( ); + +protected: + wxEvtHandler *m_src, *m_sink; + int m_refCount; + + friend class wxEvtHandler; + +private: + // It makes no sense to copy objects of this class + wxEventConnectionRef& operator = (const wxEventConnectionRef& WXUNUSED(other)) { wxFAIL; return *this; } +}; + + + // ---------------------------------------------------------------------------- // wxEvtHandler: the base class for all objects handling wxWidgets events // ---------------------------------------------------------------------------- -class WXDLLIMPEXP_BASE wxEvtHandler : public wxObject +class WXDLLIMPEXP_BASE wxEvtHandler : public wxObject, public wxTrackableBase { public: wxEvtHandler(); @@ -2359,12 +2393,9 @@ public: virtual bool SearchEventTable(wxEventTable& table, wxEvent& event); bool SearchDynamicEventTable( wxEvent& event ); -#if wxUSE_THREADS - void ClearEventLocker(); -#endif // wxUSE_THREADS - // Avoid problems at exit by cleaning up static hash table gracefully void ClearEventHashTable() { GetEventHashTable().Clear(); } + void OnSinkDestroyed( wxEvtHandler *sink ); private: static const wxEventTableEntry sm_eventTableEntries[]; @@ -2402,18 +2433,9 @@ protected: wxList* m_pendingEvents; #if wxUSE_THREADS -#if defined (__VISAGECPP__) - const wxCriticalSection& Lock() const { return m_eventsLocker; } - wxCriticalSection& Lock() { return m_eventsLocker; } - - wxCriticalSection m_eventsLocker; -# else - const wxCriticalSection& Lock() const { return *m_eventsLocker; } - wxCriticalSection& Lock() { return *m_eventsLocker; } - - wxCriticalSection* m_eventsLocker; -# endif -#endif + // critical section protecting m_pendingEvents + wxCriticalSection m_pendingEventsLock; +#endif // wxUSE_THREADS // Is event handler enabled? bool m_enabled; @@ -2440,6 +2462,9 @@ protected: virtual void DoSetClientData( void *data ); virtual void *DoGetClientData() const; + // Search tracker objects for event connection with this sink + wxEventConnectionRef *FindRefInTrackerList( wxEvtHandler *eventSink ); + private: DECLARE_DYNAMIC_CLASS_NO_COPY(wxEvtHandler) }; @@ -3008,8 +3033,9 @@ typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent& // Global data // ---------------------------------------------------------------------------- -// for pending event processing - notice that there is intentionally no -// WXDLLEXPORT here +// list containing event handlers with pending events for them +// +// notice that each event handler should occur at most once in this list extern WXDLLIMPEXP_BASE wxList *wxPendingEvents; #if wxUSE_THREADS extern WXDLLIMPEXP_BASE wxCriticalSection *wxPendingEventsLocker;