Merge branch 'focus_hwnd'

Fix focus handling in wxMSW wxSpinCtrl: select all the text when it gets
focus as expected.

See https://github.com/wxWidgets/wxWidgets/pull/1627
This commit is contained in:
Vadim Zeitlin
2019-10-31 23:58:59 +01:00
4 changed files with 20 additions and 9 deletions

View File

@@ -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;

View File

@@ -168,6 +168,12 @@ public:
void AssociateHandle(WXWidget handle) wxOVERRIDE;
void DissociateHandle() wxOVERRIDE;
// returns the handle of the native window to focus when this wxWindow gets
// focus (i.e. in composite windows: by default, this is just the HWND for
// this window itself, but it can be overridden to return something
// different for composite controls
virtual WXHWND MSWGetFocusHWND() const { return GetHWND(); }
// does this window have deferred position and/or size?
bool IsSizeDeferred() const;

View File

@@ -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)

View File

@@ -577,7 +577,7 @@ void wxWindowMSW::SetId(wxWindowID winid)
void wxWindowMSW::SetFocus()
{
HWND hWnd = GetHwnd();
HWND hWnd = (HWND)MSWGetFocusHWND();
wxCHECK_RET( hWnd, wxT("can't set focus to invalid window") );
::SetLastError(0);
@@ -599,13 +599,15 @@ void wxWindowMSW::SetFocus()
void wxWindowMSW::SetFocusFromKbd()
{
HWND hWnd = (HWND)MSWGetFocusHWND();
// when the focus is given to the control with DLGC_HASSETSEL style from
// keyboard its contents should be entirely selected: this is what
// ::IsDialogMessage() does and so we should do it as well to provide the
// same LNF as the native programs
if ( ::SendMessage(GetHwnd(), WM_GETDLGCODE, 0, 0) & DLGC_HASSETSEL )
if ( ::SendMessage(hWnd, WM_GETDLGCODE, 0, 0) & DLGC_HASSETSEL )
{
::SendMessage(GetHwnd(), EM_SETSEL, 0, -1);
::SendMessage(hWnd, EM_SETSEL, 0, -1);
}
// do this after (maybe) setting the selection as like this when