From: Vadim Zeitlin Date: Thu, 29 Mar 2012 00:10:53 +0000 (+0000) Subject: Fix focus handling logic in generic wxListCtrl. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/22930be86cddbf792227bb471852c64b40f483f0 Fix focus handling logic in generic wxListCtrl. Don't override SetFocus() to set the focus to the main window, this isn't enough as we can be given the focus by the underlying toolkit itself, without our SetFocus() being called -- this happened in wxGTK when focus was changed from the keyboard using TAB and in this case it didn't get to the main window but remaining on the wxListCtrl itself meaning that keyboard input wasn't processed at all. Use wxNavigationEnabled<> now to ensure that OnSetFocus() and related methods do the right thing instead now. Also get rid of OnSetFocus() in wxListHeaderWindow, it's better to override AcceptsFocus() to return false to avoid getting focus in the first place. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71039 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/generic/listctrl.h b/include/wx/generic/listctrl.h index 4117b7a9d1..b34315b4f1 100644 --- a/include/wx/generic/listctrl.h +++ b/include/wx/generic/listctrl.h @@ -11,6 +11,7 @@ #ifndef _WX_GENERIC_LISTCTRL_H_ #define _WX_GENERIC_LISTCTRL_H_ +#include "wx/containr.h" #include "wx/scrolwin.h" #include "wx/textctrl.h" @@ -29,7 +30,7 @@ class WXDLLIMPEXP_FWD_CORE wxListMainWindow; // wxListCtrl //----------------------------------------------------------------------------- -class WXDLLIMPEXP_CORE wxGenericListCtrl: public wxListCtrlBase, +class WXDLLIMPEXP_CORE wxGenericListCtrl: public wxNavigationEnabled, public wxScrollHelper { public: @@ -188,7 +189,6 @@ public: #endif virtual bool ShouldInheritColours() const { return false; } - virtual void SetFocus(); // implementation // -------------- diff --git a/include/wx/generic/private/listctrl.h b/include/wx/generic/private/listctrl.h index 8b4a3db082..e39de04dbf 100644 --- a/include/wx/generic/private/listctrl.h +++ b/include/wx/generic/private/listctrl.h @@ -346,12 +346,14 @@ public: virtual ~wxListHeaderWindow(); + // We never need focus as we don't have any keyboard interface. + virtual bool AcceptsFocus() const { return false; } + void DrawCurrent(); void AdjustDC( wxDC& dc ); void OnPaint( wxPaintEvent &event ); void OnMouse( wxMouseEvent &event ); - void OnSetFocus( wxFocusEvent &event ); // needs refresh bool m_dirty; diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 2b1a22df1e..834eac9ac3 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -934,7 +934,6 @@ void wxListLineData::ReverseHighlight( void ) BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow) EVT_PAINT (wxListHeaderWindow::OnPaint) EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse) - EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus) END_EVENT_TABLE() void wxListHeaderWindow::Init() @@ -1341,12 +1340,6 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event ) } } -void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) -{ - m_owner->SetFocus(); - m_owner->Update(); -} - bool wxListHeaderWindow::SendListEvent(wxEventType type, const wxPoint& pos) { wxWindow *parent = GetParent(); @@ -5154,14 +5147,6 @@ void wxGenericListCtrl::DoScreenToClient( int *x, int *y ) const wxListCtrlBase::DoScreenToClient(x, y); } -void wxGenericListCtrl::SetFocus() -{ - // The test in window.cpp fails as we are a composite - // window, so it checks against "this", but not m_mainWin. - if ( DoFindFocus() != this ) - m_mainWin->SetFocus(); -} - wxSize wxGenericListCtrl::DoGetBestClientSize() const { // Something is better than nothing even if this is completely arbitrary.