X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3e89999c1a31a2328ed50e39376f4a1d6be628dd..b9efe021b554fa3967d1442cf758435c5cd5ae8f:/src/common/event.cpp?ds=sidebyside diff --git a/src/common/event.cpp b/src/common/event.cpp index 44215d1ffc..ae6acd1979 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 // ---------------------------------------------------------------------------- @@ -244,7 +245,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 +265,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) @@ -338,7 +340,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.). * @@ -380,8 +382,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 +403,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 */ @@ -417,23 +447,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 +592,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 +615,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 +638,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 +663,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 +685,6 @@ bool wxMouseEvent::ButtonIsDown(int but) const case wxMOUSE_BTN_RIGHT: return RightIsDown(); } - - return false; } int wxMouseEvent::GetButton() const @@ -769,7 +789,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 +804,7 @@ wxEventHashTable::~wxEventHashTable() m_previous->m_next = m_next; if (sm_first == this) sm_first = m_next; - + Clear(); } @@ -827,9 +847,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 +911,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; @@ -1024,8 +1044,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); @@ -1070,22 +1092,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. @@ -1105,41 +1119,38 @@ void wxEvtHandler::AddPendingEvent(wxEvent& event) void wxEvtHandler::ProcessPendingEvents() { -#if defined(__VISAGECPP__) - wxENTER_CRIT_SECT( m_eventsLocker); -#else - wxENTER_CRIT_SECT( *m_eventsLocker); -#endif - - wxList::compatibility_iterator node = m_pendingEvents->GetFirst(); - while ( node ) + // this method is only called by wxApp if this handler does have 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 + // 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() ); } /* @@ -1157,9 +1168,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 +1320,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 +1351,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