#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;
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;
// 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;
}
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();
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[];
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;
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)
};
// 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;