X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b46b1d59d6f69ad80dcf5955375578a6504d100a..6af984df34c71bc14648a7b5bf1ad3c3cd07fc05:/src/common/event.cpp diff --git a/src/common/event.cpp b/src/common/event.cpp index 68a17045f2..0b196d5d72 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -25,6 +25,7 @@ #endif #include "wx/event.h" +#include "wx/evtloop.h" #ifndef WX_PRECOMP #include "wx/list.h" @@ -34,6 +35,7 @@ #include "wx/module.h" #if wxUSE_GUI + #include "wx/window.h" #include "wx/control.h" #include "wx/dc.h" #include "wx/textctrl.h" @@ -107,22 +109,26 @@ const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] = { DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL, 0, 0, (wxObjectEventFunction)NULL, NULL) }; -#ifdef __WXDEBUG__ -// Clear up event hash table contents or we can get problems -// when C++ is cleaning up the static object +// wxUSE_MEMORY_TRACING considers memory freed from the static objects dtors +// leaked, so we need to manually clean up all event tables before checking for +// the memory leaks when using it, however this breaks re-initializing the +// library (i.e. repeated calls to wxInitialize/wxUninitialize) because the +// event tables won't be rebuilt the next time, so disable this by default +#if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING + class wxEventTableEntryModule: public wxModule { -DECLARE_DYNAMIC_CLASS(wxEventTableEntryModule) public: - wxEventTableEntryModule() {} - bool OnInit() { return true; } - void OnExit() - { - wxEventHashTable::ClearAll(); - } + wxEventTableEntryModule() { } + virtual bool OnInit() { return true; } + virtual void OnExit() { wxEventHashTable::ClearAll(); } + + DECLARE_DYNAMIC_CLASS(wxEventTableEntryModule) }; + IMPLEMENT_DYNAMIC_CLASS(wxEventTableEntryModule, wxModule) -#endif + +#endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING // ---------------------------------------------------------------------------- // global variables @@ -192,6 +198,12 @@ DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS) DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS) DEFINE_EVENT_TYPE(wxEVT_CHILD_FOCUS) DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL) +DEFINE_EVENT_TYPE(wxEVT_AUX1_DOWN) +DEFINE_EVENT_TYPE(wxEVT_AUX1_UP) +DEFINE_EVENT_TYPE(wxEVT_AUX1_DCLICK) +DEFINE_EVENT_TYPE(wxEVT_AUX2_DOWN) +DEFINE_EVENT_TYPE(wxEVT_AUX2_UP) +DEFINE_EVENT_TYPE(wxEVT_AUX2_DCLICK) // Non-client mouse events DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN) @@ -246,12 +258,13 @@ DEFINE_EVENT_TYPE(wxEVT_SIZE) DEFINE_EVENT_TYPE(wxEVT_SIZING) DEFINE_EVENT_TYPE(wxEVT_MOVE) DEFINE_EVENT_TYPE(wxEVT_MOVING) +DEFINE_EVENT_TYPE(wxEVT_MOVE_START) +DEFINE_EVENT_TYPE(wxEVT_MOVE_END) DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW) DEFINE_EVENT_TYPE(wxEVT_END_SESSION) DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION) DEFINE_EVENT_TYPE(wxEVT_HIBERNATE) DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP) -DEFINE_EVENT_TYPE(wxEVT_POWER) DEFINE_EVENT_TYPE(wxEVT_ACTIVATE) DEFINE_EVENT_TYPE(wxEVT_CREATE) DEFINE_EVENT_TYPE(wxEVT_DESTROY) @@ -506,15 +519,23 @@ wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType, wxMouseEvent::wxMouseEvent(wxEventType commandType) { m_eventType = commandType; - m_metaDown = false; - m_altDown = false; - m_controlDown = false; - m_shiftDown = false; - m_leftDown = false; - m_rightDown = false; - m_middleDown = false; + m_x = 0; m_y = 0; + + m_leftDown = false; + m_middleDown = false; + m_rightDown = false; + m_aux1Down = false; + m_aux2Down = false; + + m_controlDown = false; + m_shiftDown = false; + m_altDown = false; + m_metaDown = false; + + m_clickCount = -1; + m_wheelRotation = 0; m_wheelDelta = 0; m_linesPerAction = 0; @@ -531,6 +552,8 @@ void wxMouseEvent::Assign(const wxMouseEvent& event) m_leftDown = event.m_leftDown; m_middleDown = event.m_middleDown; m_rightDown = event.m_rightDown; + m_aux1Down = event.m_aux1Down; + m_aux2Down = event.m_aux2Down; m_controlDown = event.m_controlDown; m_shiftDown = event.m_shiftDown; @@ -553,7 +576,8 @@ bool wxMouseEvent::ButtonDClick(int but) const // fall through case wxMOUSE_BTN_ANY: - return (LeftDClick() || MiddleDClick() || RightDClick()); + return (LeftDClick() || MiddleDClick() || RightDClick() || + Aux1DClick() || Aux2DClick()); case wxMOUSE_BTN_LEFT: return LeftDClick(); @@ -563,6 +587,12 @@ bool wxMouseEvent::ButtonDClick(int but) const case wxMOUSE_BTN_RIGHT: return RightDClick(); + + case wxMOUSE_BTN_AUX1: + return Aux1DClick(); + + case wxMOUSE_BTN_AUX2: + return Aux2DClick(); } } @@ -576,7 +606,8 @@ bool wxMouseEvent::ButtonDown(int but) const // fall through case wxMOUSE_BTN_ANY: - return (LeftDown() || MiddleDown() || RightDown()); + return (LeftDown() || MiddleDown() || RightDown() || + Aux1Down() || Aux2Down()); case wxMOUSE_BTN_LEFT: return LeftDown(); @@ -586,6 +617,12 @@ bool wxMouseEvent::ButtonDown(int but) const case wxMOUSE_BTN_RIGHT: return RightDown(); + + case wxMOUSE_BTN_AUX1: + return Aux1Down(); + + case wxMOUSE_BTN_AUX2: + return Aux2Down(); } } @@ -599,7 +636,8 @@ bool wxMouseEvent::ButtonUp(int but) const // fall through case wxMOUSE_BTN_ANY: - return (LeftUp() || MiddleUp() || RightUp()); + return (LeftUp() || MiddleUp() || RightUp() || + Aux1Up() || Aux2Up()); case wxMOUSE_BTN_LEFT: return LeftUp(); @@ -609,6 +647,12 @@ bool wxMouseEvent::ButtonUp(int but) const case wxMOUSE_BTN_RIGHT: return RightUp(); + + case wxMOUSE_BTN_AUX1: + return Aux1Up(); + + case wxMOUSE_BTN_AUX2: + return Aux2Up(); } } @@ -634,6 +678,12 @@ bool wxMouseEvent::Button(int but) const case wxMOUSE_BTN_RIGHT: return RightDown() || RightUp() || RightDClick(); + + case wxMOUSE_BTN_AUX1: + return Aux1Down() || Aux1Up() || Aux1DClick(); + + case wxMOUSE_BTN_AUX2: + return Aux2Down() || Aux2Up() || Aux2DClick(); } } @@ -646,7 +696,7 @@ bool wxMouseEvent::ButtonIsDown(int but) const // fall through case wxMOUSE_BTN_ANY: - return LeftIsDown() || MiddleIsDown() || RightIsDown(); + return LeftIsDown() || MiddleIsDown() || RightIsDown() || Aux1Down() || Aux2Down(); case wxMOUSE_BTN_LEFT: return LeftIsDown(); @@ -656,12 +706,18 @@ bool wxMouseEvent::ButtonIsDown(int but) const case wxMOUSE_BTN_RIGHT: return RightIsDown(); + + case wxMOUSE_BTN_AUX1: + return Aux1IsDown(); + + case wxMOUSE_BTN_AUX2: + return Aux2IsDown(); } } int wxMouseEvent::GetButton() const { - for ( int i = 1; i <= 3; i++ ) + for ( int i = 1; i < wxMOUSE_BTN_MAX; i++ ) { if ( Button(i) ) { @@ -801,25 +857,20 @@ wxEventHashTable::~wxEventHashTable() void wxEventHashTable::Clear() { - size_t i; - for(i = 0; i < m_size; i++) + for ( size_t i = 0; i < m_size; i++ ) { EventTypeTablePointer eTTnode = m_eventTypeTable[i]; - if (eTTnode) - { - delete eTTnode; - } + delete eTTnode; } - // Necessary in order to not invoke the - // overloaded delete operator when statics are cleaned up - if (m_eventTypeTable) - delete[] m_eventTypeTable; - + delete[] m_eventTypeTable; m_eventTypeTable = NULL; + m_size = 0; } +#if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING + // Clear all tables void wxEventHashTable::ClearAll() { @@ -831,6 +882,8 @@ void wxEventHashTable::ClearAll() } } +#endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING + bool wxEventHashTable::HandleEvent(wxEvent &event, wxEvtHandler *self) { if (m_rebuildHash) @@ -992,7 +1045,7 @@ wxEvtHandler::wxEvtHandler() m_eventsLocker = new wxCriticalSection; # endif #endif - + // no client data (yet) m_clientData = NULL; m_clientDataType = wxClientData_None; @@ -1055,7 +1108,7 @@ wxEvtHandler::~wxEvtHandler() #if wxUSE_THREADS -bool wxEvtHandler::ProcessThreadEvent(wxEvent& event) +bool wxEvtHandler::ProcessThreadEvent(const wxEvent& event) { // check that we are really in a child thread wxASSERT_MSG( !wxThread::IsMain(), @@ -1076,7 +1129,7 @@ void wxEvtHandler::ClearEventLocker() #endif // wxUSE_THREADS -void wxEvtHandler::AddPendingEvent(wxEvent& event) +void wxEvtHandler::AddPendingEvent(const wxEvent& event) { // 1) Add event to list of pending events of this event handler @@ -1118,7 +1171,7 @@ void wxEvtHandler::ProcessPendingEvents() // pending events wxCHECK_RET( m_pendingEvents, wxT("Please call wxApp::ProcessPendingEvents() instead") ); - + wxENTER_CRIT_SECT( Lock() ); // we leave the loop once we have processed all events that were present at @@ -1251,8 +1304,10 @@ bool wxEvtHandler::ProcessEvent(wxEvent& event) // Try going down the event handler chain if ( GetNextHandler() ) { - if ( GetNextHandler()->ProcessEvent(event) ) - return true; + // notice that we shouldn't let the parent have the event even if the + // next handler does not process it because it will have already passed + // it to the parent in this case + return GetNextHandler()->ProcessEvent(event); } // Finally propagate the event upwards the window chain and/or to the @@ -1260,6 +1315,42 @@ bool wxEvtHandler::ProcessEvent(wxEvent& event) return TryParent(event); } +bool wxEvtHandler::SafelyProcessEvent(wxEvent& event) +{ +#if wxUSE_EXCEPTIONS + try + { +#endif + return ProcessEvent(event); +#if wxUSE_EXCEPTIONS + } + catch ( ... ) + { + wxEventLoopBase *loop = wxEventLoopBase::GetActive(); + try + { + if ( !wxTheApp || !wxTheApp->OnExceptionInMainLoop() ) + { + if ( loop ) + loop->Exit(); + } + //else: continue running current event loop + + return false; + } + catch ( ... ) + { + // OnExceptionInMainLoop() threw, possibly rethrowing the same + // exception again: very good, but we still need Exit() to + // be called + if ( loop ) + loop->Exit(); + throw; + } + } +#endif // wxUSE_EXCEPTIONS +} + bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event) { @@ -1459,7 +1550,7 @@ wxEventBlocker::wxEventBlocker(wxWindow *win, wxEventType type) wxEventBlocker::~wxEventBlocker() { wxEvtHandler *popped = m_window->PopEventHandler(false); - wxCHECK_RET(popped == this, + wxCHECK_RET(popped == this, wxT("Don't push other event handlers into a window managed by wxEventBlocker!")); }