X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/534b127cacf722be2aa99f86bde969f20e89c1dd..ff23892253768e3f122202222b144d8e435155b8:/src/common/event.cpp diff --git a/src/common/event.cpp b/src/common/event.cpp index 8492fd3ec0..31196f57c4 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -17,17 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) && !defined(__EMX__) -// Some older compilers (such as EMX) cannot handle -// #pragma interface/implementation correctly, iff -// #pragma implementation is used in _two_ translation -// units (as created by e.g. event.cpp compiled for -// libwx_base and event.cpp compiled for libwx_gui_core). -// So we must not use those pragmas for those compilers in -// such files. - #pragma implementation "event.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -44,6 +33,7 @@ #include "wx/control.h" #include "wx/utils.h" #include "wx/dc.h" + #include "wx/textctrl.h" #endif // wxUSE_GUI #endif @@ -120,7 +110,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 +127,7 @@ public: }; IMPLEMENT_DYNAMIC_CLASS(wxEventTableEntryModule, wxModule) #endif - + // ---------------------------------------------------------------------------- // global variables // ---------------------------------------------------------------------------- @@ -244,7 +234,7 @@ DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP) DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN) DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK) DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE) -DEFINE_EVENT_TYPE(wxEVT_SCROLL_ENDSCROLL) +DEFINE_EVENT_TYPE(wxEVT_SCROLL_CHANGED) // Scroll events from wxWindow DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP) @@ -264,6 +254,7 @@ DEFINE_EVENT_TYPE(wxEVT_MOVING) 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) @@ -380,8 +371,16 @@ wxEvent::wxEvent(const wxEvent &src) * */ +#ifdef __VISUALC__ + // 'this' : used in base member initializer list (for m_commandString) + #pragma warning(disable:4355) +#endif + 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 +392,26 @@ wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId) m_propagationLevel = wxEVENT_PROPAGATE_MAX; } +#ifdef __VISUALC__ + #pragma warning(default:4355) +#endif + +wxString wxCommandEvent::GetString() const +{ + if(m_eventType != wxEVT_COMMAND_TEXT_UPDATED || !m_eventObject) + return m_cmdString; + else + { +#if wxUSE_TEXTCTRL + wxTextCtrl *txt = wxDynamicCast(m_eventObject, wxTextCtrl); + if(txt) + return txt->GetValue(); + else +#endif // wxUSE_TEXTCTRL + return m_cmdString; + } +} + /* * UI update events */ @@ -759,7 +778,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; @@ -774,7 +793,7 @@ wxEventHashTable::~wxEventHashTable() m_previous->m_next = m_next; if (sm_first == this) sm_first = m_next; - + Clear(); } @@ -817,9 +836,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(); @@ -881,7 +900,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; @@ -1014,8 +1033,10 @@ wxEvtHandler::~wxEvtHandler() // Remove us from wxPendingEvents if necessary. if(wxPendingEventsLocker) wxENTER_CRIT_SECT(*wxPendingEventsLocker); - if ( wxPendingEvents ) { - wxPendingEvents->DeleteObject(this); + if ( wxPendingEvents ) + { + // Delete all occurences of this from the list of pending events + while (wxPendingEvents->DeleteObject(this)) { } // Do nothing } if(wxPendingEventsLocker) wxLEAVE_CRIT_SECT(*wxPendingEventsLocker); @@ -1045,7 +1066,7 @@ void wxEvtHandler::ClearEventLocker() delete m_eventsLocker; m_eventsLocker = NULL; #endif -}; +} #endif // wxUSE_THREADS @@ -1060,22 +1081,14 @@ void wxEvtHandler::AddPendingEvent(wxEvent& event) wxCHECK_RET( eventCopy, _T("events of this type aren't supposed to be posted") ); -#if defined(__VISAGECPP__) - wxENTER_CRIT_SECT( m_eventsLocker); -#else - wxENTER_CRIT_SECT( *m_eventsLocker); -#endif + wxENTER_CRIT_SECT( Lock() ); if ( !m_pendingEvents ) m_pendingEvents = new wxList; m_pendingEvents->Append(eventCopy); -#if defined(__VISAGECPP__) - wxLEAVE_CRIT_SECT( m_eventsLocker); -#else - wxLEAVE_CRIT_SECT( *m_eventsLocker); -#endif + wxLEAVE_CRIT_SECT( Lock() ); // 2) Add this event handler to list of event handlers that // have pending events. @@ -1100,41 +1113,33 @@ void wxEvtHandler::ProcessPendingEvents() 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 + wxENTER_CRIT_SECT( Lock() ); - wxList::compatibility_iterator node = m_pendingEvents->GetFirst(); - while ( node ) + // we 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 + size_t n = m_pendingEvents->size(); + for ( wxList::compatibility_iterator node = m_pendingEvents->GetFirst(); + node; + node = m_pendingEvents->GetFirst() ) { wxEvent *event = (wxEvent *)node->GetData(); + m_pendingEvents->Erase(node); - // In ProcessEvent, new events might get added and - // we can safely leave the crtical section here. -#if defined(__VISAGECPP__) - wxLEAVE_CRIT_SECT( m_eventsLocker); -#else - wxLEAVE_CRIT_SECT( *m_eventsLocker); -#endif + wxLEAVE_CRIT_SECT( Lock() ); + ProcessEvent(*event); delete event; -#if defined(__VISAGECPP__) - wxENTER_CRIT_SECT( m_eventsLocker); -#else - wxENTER_CRIT_SECT( *m_eventsLocker); -#endif - node = m_pendingEvents->GetFirst(); + wxENTER_CRIT_SECT( Lock() ); + + if ( !--n ) + break; } -#if defined(__VISAGECPP__) - wxLEAVE_CRIT_SECT( m_eventsLocker); -#else - wxLEAVE_CRIT_SECT( *m_eventsLocker); -#endif + wxLEAVE_CRIT_SECT( Lock() ); } /* @@ -1152,9 +1157,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); @@ -1304,7 +1309,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)) && @@ -1335,7 +1340,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 != 0)) + if ((event.GetEventType() == entry->m_eventType) && (entry->m_fn != 0)) { wxEvtHandler *handler = #if !WXWIN_COMPATIBILITY_EVENT_TYPES @@ -1354,7 +1359,7 @@ bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event ) } return false; -}; +} void wxEvtHandler::DoSetClientObject( wxClientData *data ) {