From 1b6dc0a2fbae391a1a0dd784b914ba53464ae9f5 Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Fri, 1 Nov 2019 00:19:53 +0700 Subject: [PATCH] Add MSWGetFocusHWND to allow focus a subwindow Under MSW allow override which subwindow will be focused for composite windows which are implemented not as a set of wxControl (i.e. using only Windows native controls). --- include/wx/msw/private.h | 1 + include/wx/msw/window.h | 5 +++++ src/msw/window.cpp | 8 +++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/wx/msw/private.h b/include/wx/msw/private.h index f850b7b554..46dffa05a6 100644 --- a/include/wx/msw/private.h +++ b/include/wx/msw/private.h @@ -838,6 +838,7 @@ private: // --------------------------------------------------------------------------- #define GetHwnd() ((HWND)GetHWND()) +#define MSWGetFocusHwnd() ((HWND)MSWGetFocusHWND()) #define GetHwndOf(win) ((HWND)((win)->GetHWND())) // old name #define GetWinHwnd GetHwndOf diff --git a/include/wx/msw/window.h b/include/wx/msw/window.h index dd6c10a6b5..306cd814da 100644 --- a/include/wx/msw/window.h +++ b/include/wx/msw/window.h @@ -168,6 +168,11 @@ public: void AssociateHandle(WXWidget handle) wxOVERRIDE; void DissociateHandle() wxOVERRIDE; + // returns the handle of the focused window (i.e. in composite windows + // which can't be implemented via a set of wxControl's focus may be wanted + // by a subwindow instead of the main window) + virtual WXHWND MSWGetFocusHWND() const { return GetHWND(); } + // does this window have deferred position and/or size? bool IsSizeDeferred() const; diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 08028038b0..fd048e6e01 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -577,7 +577,7 @@ void wxWindowMSW::SetId(wxWindowID winid) void wxWindowMSW::SetFocus() { - HWND hWnd = GetHwnd(); + 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 = 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