From: Vadim Zeitlin Date: Wed, 28 Jan 2009 13:41:43 +0000 (+0000) Subject: fix remaining cases of wxWindow::ProcessEvent() calls; add convenient ProcessWindowEv... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/3b7fa2069b9f69c9da5783e04c7a935927eb403f fix remaining cases of wxWindow::ProcessEvent() calls; add convenient ProcessWindowEvent() wrapper and document it; also document this (incompatible) change itself git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58480 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index 240cf9af50..9bfdfdc586 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -119,6 +119,10 @@ Changes in behaviour which may result in compilation errors need to review them as wxDC doesn't have any virtual methods any longer and uses delegation instead of inheritance to present different behaviours. +- wxWindow::ProcessEvent() has been made protected to prevent wrongly using it + instead of correct GetEventHandler()->ProcessEvent(). New ProcessWindowEvent() + was added for convenience. + - Return type of wxString::operator[] and wxString::iterator::operator* is no longer wxChar (i.e. char or wchar_t), but wxUniChar. This is not a problem in vast majority of cases because of conversion operators, but it can break diff --git a/include/wx/window.h b/include/wx/window.h index 3454055f9a..ba5f596d78 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -806,6 +806,13 @@ public: // be there) bool RemoveEventHandler(wxEvtHandler *handler); + // Process an event by calling GetEventHandler()->ProcessEvent(): this + // is a straightforward replacement for ProcessEvent() itself which + // shouldn't be used directly with windows as it doesn't take into + // account any event handlers associated with the window + bool ProcessWindowEvent(wxEvent& event) + { return GetEventHandler()->ProcessEvent(event); } + // Process an event by calling GetEventHandler()->ProcessEvent() and // handling any exceptions thrown by event handlers. It's mostly useful // when processing wx events when called from C code (e.g. in GTK+ diff --git a/interface/wx/window.h b/interface/wx/window.h index d1844645bc..c0503b5ee3 100644 --- a/interface/wx/window.h +++ b/interface/wx/window.h @@ -1650,9 +1650,21 @@ public: @code GetEventHandler()->SafelyProcessEvent(event); @endcode + + @see ProcessWindowEvent() */ bool HandleWindowEvent(wxEvent& event) const; + /** + Convenient wrapper for ProcessEvent(). + + This is the same as writing @code GetEventHandler()->ProcessEvent(event); + @endcode but more convenient. Notice that ProcessEvent() itself can't + be called for wxWindow objects as it ignores the event handlers + associated with the window, use this function instead. + */ + bool ProcessWindowEvent(wxEvent& event); + /** Removes and returns the top-most event handler on the event handler stack. @@ -3052,14 +3064,18 @@ protected: //@{ /** - This function is public in wxEvtHandler but is protected in wxWindow because - for wxWindows you should always use this function on the pointer returned - by GetEventHandler() and not on the wxWindow object itself. + These functions are public in wxEvtHandler but protected in wxWindow + because for wxWindows you should always use this function on the + pointer returned by GetEventHandler() and not on the wxWindow object + itself. + + For convenience, a ProcessWindowEvent() method is provided as a synonym + for @code GetEventHandler()->ProcessEvent() @endcode. Note that it's still possible to call these functions directly on the - wxWindow object (e.g. downcasting it to wxEvtHandler) but doing that - will create subtle bugs when windows with event handlers pushed on them - are involved. + wxWindow object (e.g. casting it to wxEvtHandler) but doing that will + create subtle bugs when windows with event handlers pushed on them are + involved. */ virtual bool ProcessEvent(wxEvent& event); bool SafelyProcessEvent(wxEvent& event); diff --git a/src/common/popupcmn.cpp b/src/common/popupcmn.cpp index 1638ce5760..a0480aea56 100644 --- a/src/common/popupcmn.cpp +++ b/src/common/popupcmn.cpp @@ -464,7 +464,7 @@ void wxPopupComboWindow::OnDismiss() void wxPopupComboWindow::OnKeyDown(wxKeyEvent& event) { - m_combo->ProcessEvent(event); + m_combo->ProcessWindowEvent(event); } #endif // wxUSE_COMBOBOX && defined(__WXUNIVERSAL__) diff --git a/src/generic/mdig.cpp b/src/generic/mdig.cpp index bc81b3c8d1..3326c0592c 100644 --- a/src/generic/mdig.cpp +++ b/src/generic/mdig.cpp @@ -372,7 +372,7 @@ bool wxGenericMDIParentFrame::ProcessEvent(wxEvent& event) m_childHandler = m_currentChild; wxON_BLOCK_EXIT_NULL(m_childHandler); - if ( m_currentChild->ProcessEvent(event) ) + if ( m_currentChild->ProcessWindowEvent(event) ) return true; } } diff --git a/src/generic/notebook.cpp b/src/generic/notebook.cpp index 29b5a4137d..0d2a77c6e0 100644 --- a/src/generic/notebook.cpp +++ b/src/generic/notebook.cpp @@ -565,15 +565,17 @@ void wxNotebook::OnSetFocus(wxFocusEvent& event) void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) { - if ( event.IsWindowChange() ) { + if ( event.IsWindowChange() ) + { // change pages AdvanceSelection(event.GetDirection()); } else { // pass to the parent - if ( GetParent() ) { + if ( GetParent() ) + { event.SetCurrentFocus(this); - GetParent()->ProcessEvent(event); + GetParent()->ProcessWindowEvent(event); } } } diff --git a/src/univ/combobox.cpp b/src/univ/combobox.cpp index 80ff466793..4b4953f462 100644 --- a/src/univ/combobox.cpp +++ b/src/univ/combobox.cpp @@ -185,7 +185,7 @@ void wxComboListBox::OnLeftUp(wxMouseEvent& event) wxCommandEvent evt(wxEVT_COMMAND_COMBOBOX_SELECTED,m_combo->GetId()); evt.SetInt(wxListBox::GetSelection()); evt.SetEventObject(m_combo); - m_combo->ProcessEvent(evt); + m_combo->ProcessWindowEvent(evt); event.Skip(); }