X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3e89999c1a31a2328ed50e39376f4a1d6be628dd..d20834167ebc75da9d79fefbd3d1134ad9c8f65a:/src/common/event.cpp diff --git a/src/common/event.cpp b/src/common/event.cpp index 44215d1ffc..5c65c985af 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -44,6 +44,7 @@ #include "wx/control.h" #include "wx/utils.h" #include "wx/dc.h" + #include "wx/textctrl.h" #endif // wxUSE_GUI #endif @@ -120,7 +121,7 @@ wxEventHashTable wxEvtHandler::sm_eventHashTable(wxEvtHandler::sm_eventTable); 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 @@ -137,7 +138,7 @@ public: }; IMPLEMENT_DYNAMIC_CLASS(wxEventTableEntryModule, wxModule) #endif - + // ---------------------------------------------------------------------------- // global variables // ---------------------------------------------------------------------------- @@ -338,7 +339,7 @@ int wxNewEventType() // ---------------------------------------------------------------------------- /* - * General wxWindows events, covering + * General wxWidgets events, covering * all interesting things that might happen (button clicking, resizing, * setting text in widgets, etc.). * @@ -382,6 +383,9 @@ wxEvent::wxEvent(const wxEvent &src) wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId) : wxEvent(theId, commandType) +#if WXWIN_COMPATIBILITY_2_4 + , m_commandString(this) +#endif { m_clientData = (char *) NULL; m_clientObject = (wxClientData *) NULL; @@ -393,6 +397,20 @@ wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId) m_propagationLevel = wxEVENT_PROPAGATE_MAX; } +wxString wxCommandEvent::GetString() const +{ + if(m_eventType != wxEVT_COMMAND_TEXT_UPDATED || !m_eventObject) + return m_cmdString; + else + { + wxTextCtrl *txt = wxDynamicCast(m_eventObject, wxTextCtrl); + if(txt) + return txt->GetValue(); + else + return m_cmdString; + } +} + /* * UI update events */ @@ -417,23 +435,23 @@ bool wxUpdateUIEvent::CanUpdate(wxWindowBase *win) if (sm_updateInterval == -1) return false; - else if (sm_updateInterval == 0) + + if (sm_updateInterval == 0) return true; - else - { + #if wxUSE_STOPWATCH && wxUSE_LONGLONG - wxLongLong now = wxGetLocalTimeMillis(); - if (now > (sm_lastUpdate + sm_updateInterval)) - { - return true; - } -#else - // If we don't have wxStopWatch or wxLongLong, we - // should err on the safe side and update now anyway. + wxLongLong now = wxGetLocalTimeMillis(); + if (now > (sm_lastUpdate + sm_updateInterval)) + { return true; -#endif } + return false; +#else + // If we don't have wxStopWatch or wxLongLong, we + // should err on the safe side and update now anyway. + return true; +#endif } // Reset the update time to provide a delay until the next @@ -562,8 +580,6 @@ bool wxMouseEvent::ButtonDClick(int but) const case wxMOUSE_BTN_RIGHT: return RightDClick(); } - - return false; } // return true if was a button down event @@ -587,8 +603,6 @@ bool wxMouseEvent::ButtonDown(int but) const case wxMOUSE_BTN_RIGHT: return RightDown(); } - - return false; } // return true if was a button up event @@ -612,8 +626,6 @@ bool wxMouseEvent::ButtonUp(int but) const case wxMOUSE_BTN_RIGHT: return RightUp(); } - - return false; } // return true if the given button is currently changing state @@ -639,8 +651,6 @@ bool wxMouseEvent::Button(int but) const case wxMOUSE_BTN_RIGHT: return RightDown() || RightUp() || RightDClick(); } - - return false; } bool wxMouseEvent::ButtonIsDown(int but) const @@ -663,8 +673,6 @@ bool wxMouseEvent::ButtonIsDown(int but) const case wxMOUSE_BTN_RIGHT: return RightIsDown(); } - - return false; } int wxMouseEvent::GetButton() const @@ -769,7 +777,7 @@ wxEventHashTable::wxEventHashTable(const wxEventTable &table) m_rebuildHash(true) { AllocEventTypeTable(EVENT_TYPE_TABLE_INIT_SIZE); - + m_next = sm_first; if (m_next) m_next->m_previous = this; @@ -784,7 +792,7 @@ wxEventHashTable::~wxEventHashTable() m_previous->m_next = m_next; if (sm_first == this) sm_first = m_next; - + Clear(); } @@ -827,9 +835,9 @@ bool wxEventHashTable::HandleEvent(wxEvent &event, wxEvtHandler *self) InitHashTable(); m_rebuildHash = false; } - + if (!m_eventTypeTable) - return FALSE; + return false; // Find all entries for the given event type. wxEventType eventType = event.GetEventType(); @@ -891,7 +899,7 @@ void wxEventHashTable::AddEntry(const wxEventTableEntry &entry) // This might happen 'accidentally' as the app is exiting if (!m_eventTypeTable) return; - + EventTypeTablePointer *peTTnode = &m_eventTypeTable[entry.m_eventType % m_size]; EventTypeTablePointer eTTnode = *peTTnode; @@ -1105,12 +1113,20 @@ void wxEvtHandler::AddPendingEvent(wxEvent& event) void wxEvtHandler::ProcessPendingEvents() { + // this method is only called by wxApp if this handler does have pending + // events + wxCHECK_RET( m_pendingEvents, + wxT("Please call wxApp::ProcessPendingEvents() instead") ); + #if defined(__VISAGECPP__) wxENTER_CRIT_SECT( m_eventsLocker); #else wxENTER_CRIT_SECT( *m_eventsLocker); #endif + // remember last event to process during this iteration + wxList::compatibility_iterator lastPendingNode = m_pendingEvents->GetLast(); + wxList::compatibility_iterator node = m_pendingEvents->GetFirst(); while ( node ) { @@ -1132,6 +1148,13 @@ void wxEvtHandler::ProcessPendingEvents() wxENTER_CRIT_SECT( *m_eventsLocker); #endif + // leave the loop once we have processed all events that were present + // at the start of ProcessPendingEvents because otherwise we could get + // into infinite loop if the pending event handler execution resulted + // in another event being posted + if ( node == lastPendingNode ) + break; + node = m_pendingEvents->GetFirst(); } @@ -1157,9 +1180,9 @@ wxEvtHandler::ProcessEventIfMatches(const wxEventTableEntryBase& entry, // the event table (meaning "any") or the event id matches the id // specified in the event table either exactly or by falling into // range between first and last - if ((tableId1 == -1) || - (tableId2 == -1 && tableId1 == event.GetId()) || - (tableId2 != -1 && + if ((tableId1 == wxID_ANY) || + (tableId2 == wxID_ANY && tableId1 == event.GetId()) || + (tableId2 != wxID_ANY && (event.GetId() >= tableId1 && event.GetId() <= tableId2))) { event.Skip(false); @@ -1309,7 +1332,7 @@ bool wxEvtHandler::Disconnect( int id, int lastId, wxEventType eventType, #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES if ((entry->m_id == id) && - ((entry->m_lastId == lastId) || (lastId == -1)) && + ((entry->m_lastId == lastId) || (lastId == wxID_ANY)) && ((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) && ((entry->m_fn == func) || (func == (wxObjectEventFunction)NULL)) && ((entry->m_eventSink == eventSink) || (eventSink == (wxEvtHandler*)NULL)) && @@ -1340,7 +1363,7 @@ bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event ) wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData(); #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES - if ((event.m_eventType == entry->m_eventType) && entry->m_fn) + if ((event.GetEventType() == entry->m_eventType) && (entry->m_fn != 0)) { wxEvtHandler *handler = #if !WXWIN_COMPATIBILITY_EVENT_TYPES