From bfde3d3e08dbddde566bee063bdc74c7ac12d210 Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Fri, 1 Nov 2019 00:27:43 +0700 Subject: [PATCH] Fix focus behaviour of the spin control under MSW Override MSWGetFocusHwnd for wxSpinCtrl to focus the right subwindow. So the correct window will be used in wxWindowMSW::SetFocusFromKbd and the spin controls content will be selected on TAB key. --- include/wx/msw/spinctrl.h | 3 ++- src/msw/spinctrl.cpp | 12 +++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/wx/msw/spinctrl.h b/include/wx/msw/spinctrl.h index 0e3f05c132..491d9d99bd 100644 --- a/include/wx/msw/spinctrl.h +++ b/include/wx/msw/spinctrl.h @@ -77,7 +77,6 @@ public: virtual int GetValue() const wxOVERRIDE; virtual void SetRange(int minVal, int maxVal) wxOVERRIDE; virtual bool SetFont(const wxFont &font) wxOVERRIDE; - virtual void SetFocus() wxOVERRIDE; virtual bool Enable(bool enable = true) wxOVERRIDE; virtual bool Show(bool show = true) wxOVERRIDE; @@ -115,6 +114,8 @@ public: virtual void SetLayoutDirection(wxLayoutDirection dir) wxOVERRIDE; + virtual WXHWND MSWGetFocusHWND() const wxOVERRIDE; + protected: virtual void DoGetPosition(int *x, int *y) const wxOVERRIDE; virtual void DoMoveWindow(int x, int y, int width, int height) wxOVERRIDE; diff --git a/src/msw/spinctrl.cpp b/src/msw/spinctrl.cpp index 11fa10ee83..321f6b11c5 100644 --- a/src/msw/spinctrl.cpp +++ b/src/msw/spinctrl.cpp @@ -522,6 +522,13 @@ void wxSpinCtrl::SetLayoutDirection(wxLayoutDirection dir) SetSize(-1, -1, -1, -1, wxSIZE_AUTO | wxSIZE_FORCE); } +WXHWND wxSpinCtrl::MSWGetFocusHWND() const +{ + // Return the buddy hwnd because it shuld be focused instead of the + // wxSpinCtrl itself. + return m_hwndBuddy; +} + // ---------------------------------------------------------------------------- // wxSpinButton methods // ---------------------------------------------------------------------------- @@ -653,11 +660,6 @@ bool wxSpinCtrl::Enable(bool enable) return true; } -void wxSpinCtrl::SetFocus() -{ - ::SetFocus(GetBuddyHwnd()); -} - #if wxUSE_TOOLTIPS void wxSpinCtrl::DoSetToolTip(wxToolTip *tip)