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).
This commit is contained in:
Ilya Sinitsyn
2019-11-01 00:19:53 +07:00
parent 53c5ebedca
commit 1b6dc0a2fb
3 changed files with 11 additions and 3 deletions

View File

@@ -838,6 +838,7 @@ private:
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
#define GetHwnd() ((HWND)GetHWND()) #define GetHwnd() ((HWND)GetHWND())
#define MSWGetFocusHwnd() ((HWND)MSWGetFocusHWND())
#define GetHwndOf(win) ((HWND)((win)->GetHWND())) #define GetHwndOf(win) ((HWND)((win)->GetHWND()))
// old name // old name
#define GetWinHwnd GetHwndOf #define GetWinHwnd GetHwndOf

View File

@@ -168,6 +168,11 @@ public:
void AssociateHandle(WXWidget handle) wxOVERRIDE; void AssociateHandle(WXWidget handle) wxOVERRIDE;
void DissociateHandle() 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? // does this window have deferred position and/or size?
bool IsSizeDeferred() const; bool IsSizeDeferred() const;

View File

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