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/include/wx/msw/window.h b/include/wx/msw/window.h index dd6c10a6b5..2ee4558b94 100644 --- a/include/wx/msw/window.h +++ b/include/wx/msw/window.h @@ -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; 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) diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 08028038b0..8f683c5773 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 = (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