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
This commit is contained in:
Vadim Zeitlin
2012-03-29 00:10:53 +00:00
parent 34326da778
commit 22930be86c
3 changed files with 5 additions and 18 deletions

View File

@@ -11,6 +11,7 @@
#ifndef _WX_GENERIC_LISTCTRL_H_ #ifndef _WX_GENERIC_LISTCTRL_H_
#define _WX_GENERIC_LISTCTRL_H_ #define _WX_GENERIC_LISTCTRL_H_
#include "wx/containr.h"
#include "wx/scrolwin.h" #include "wx/scrolwin.h"
#include "wx/textctrl.h" #include "wx/textctrl.h"
@@ -29,7 +30,7 @@ class WXDLLIMPEXP_FWD_CORE wxListMainWindow;
// wxListCtrl // wxListCtrl
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxGenericListCtrl: public wxListCtrlBase, class WXDLLIMPEXP_CORE wxGenericListCtrl: public wxNavigationEnabled<wxListCtrlBase>,
public wxScrollHelper public wxScrollHelper
{ {
public: public:
@@ -188,7 +189,6 @@ public:
#endif #endif
virtual bool ShouldInheritColours() const { return false; } virtual bool ShouldInheritColours() const { return false; }
virtual void SetFocus();
// implementation // implementation
// -------------- // --------------

View File

@@ -346,12 +346,14 @@ public:
virtual ~wxListHeaderWindow(); virtual ~wxListHeaderWindow();
// We never need focus as we don't have any keyboard interface.
virtual bool AcceptsFocus() const { return false; }
void DrawCurrent(); void DrawCurrent();
void AdjustDC( wxDC& dc ); void AdjustDC( wxDC& dc );
void OnPaint( wxPaintEvent &event ); void OnPaint( wxPaintEvent &event );
void OnMouse( wxMouseEvent &event ); void OnMouse( wxMouseEvent &event );
void OnSetFocus( wxFocusEvent &event );
// needs refresh // needs refresh
bool m_dirty; bool m_dirty;

View File

@@ -934,7 +934,6 @@ void wxListLineData::ReverseHighlight( void )
BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow) BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow)
EVT_PAINT (wxListHeaderWindow::OnPaint) EVT_PAINT (wxListHeaderWindow::OnPaint)
EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse) EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse)
EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus)
END_EVENT_TABLE() END_EVENT_TABLE()
void wxListHeaderWindow::Init() 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) bool wxListHeaderWindow::SendListEvent(wxEventType type, const wxPoint& pos)
{ {
wxWindow *parent = GetParent(); wxWindow *parent = GetParent();
@@ -5154,14 +5147,6 @@ void wxGenericListCtrl::DoScreenToClient( int *x, int *y ) const
wxListCtrlBase::DoScreenToClient(x, y); 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 wxSize wxGenericListCtrl::DoGetBestClientSize() const
{ {
// Something is better than nothing even if this is completely arbitrary. // Something is better than nothing even if this is completely arbitrary.