From a2f37a9ed5b35748e3f75214efc456c0666efd01 Mon Sep 17 00:00:00 2001 From: Kvaz1r Date: Wed, 31 Jul 2019 18:17:25 +0300 Subject: [PATCH] Fix client coordinates mapping for wxSpinCtrl in wxMSW Add MSWDoClientToScreen() and MSWDoScreenToClient() helpers and use them with the correct HWND in DoClientToScreen() and DoScreenToClient() overridden in wxSpinCtrl, i.e. the HWND of the "buddy" text control and not the spin button, which is the main HWND of this control. This notably fixes wxSpinCtrl::GetScreenPosition() which returned the position of the spin button. Closes https://github.com/wxWidgets/wxWidgets/pull/1454 Closes #18455. --- include/wx/msw/spinctrl.h | 2 ++ include/wx/msw/window.h | 2 ++ src/msw/spinctrl.cpp | 10 ++++++++++ src/msw/window.cpp | 20 ++++++++++++++++---- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/include/wx/msw/spinctrl.h b/include/wx/msw/spinctrl.h index 612ca4bba2..8d7476344b 100644 --- a/include/wx/msw/spinctrl.h +++ b/include/wx/msw/spinctrl.h @@ -120,6 +120,8 @@ protected: virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const wxOVERRIDE; virtual void DoGetSize(int *width, int *height) const wxOVERRIDE; virtual void DoGetClientSize(int *x, int *y) const wxOVERRIDE; + virtual void DoClientToScreen(int *x, int *y) const wxOVERRIDE; + virtual void DoScreenToClient(int *x, int *y) const wxOVERRIDE; #if wxUSE_TOOLTIPS virtual void DoSetToolTip( wxToolTip *tip ) wxOVERRIDE; #endif // wxUSE_TOOLTIPS diff --git a/include/wx/msw/window.h b/include/wx/msw/window.h index 35df830c3f..b9b911bf7e 100644 --- a/include/wx/msw/window.h +++ b/include/wx/msw/window.h @@ -621,6 +621,8 @@ protected: int *descent = NULL, int *externalLeading = NULL, const wxFont *font = NULL) const wxOVERRIDE; + static void MSWDoClientToScreen( WXHWND hWnd, int *x, int *y ); + static void MSWDoScreenToClient( WXHWND hWnd, int *x, int *y ); virtual void DoClientToScreen( int *x, int *y ) const wxOVERRIDE; virtual void DoScreenToClient( int *x, int *y ) const wxOVERRIDE; virtual void DoGetPosition( int *x, int *y ) const wxOVERRIDE; diff --git a/src/msw/spinctrl.cpp b/src/msw/spinctrl.cpp index 6c794fb47a..6c37d792db 100644 --- a/src/msw/spinctrl.cpp +++ b/src/msw/spinctrl.cpp @@ -846,4 +846,14 @@ void wxSpinCtrl::DoGetPosition(int *x, int *y) const *x = wxMin(xBuddy, xText); } +void wxSpinCtrl::DoScreenToClient(int *x, int *y) const +{ + wxWindow::MSWDoScreenToClient(GetBuddyHwnd(), x, y); +} + +void wxSpinCtrl::DoClientToScreen(int *x, int *y) const +{ + wxWindow::MSWDoClientToScreen(GetBuddyHwnd(), x, y); +} + #endif // wxUSE_SPINCTRL diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 2d5f51c671..68255d7c09 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -1951,7 +1951,8 @@ void wxWindowMSW::DoGetPosition(int *x, int *y) const *y = pos.y; } -void wxWindowMSW::DoScreenToClient(int *x, int *y) const +/* static */ +void wxWindowMSW::MSWDoScreenToClient(WXHWND hWnd, int *x, int *y) { POINT pt; if ( x ) @@ -1959,7 +1960,7 @@ void wxWindowMSW::DoScreenToClient(int *x, int *y) const if ( y ) pt.y = *y; - ::ScreenToClient(GetHwnd(), &pt); + ::ScreenToClient(hWnd, &pt); if ( x ) *x = pt.x; @@ -1967,7 +1968,8 @@ void wxWindowMSW::DoScreenToClient(int *x, int *y) const *y = pt.y; } -void wxWindowMSW::DoClientToScreen(int *x, int *y) const +/* static */ +void wxWindowMSW::MSWDoClientToScreen(WXHWND hWnd, int *x, int *y) { POINT pt; if ( x ) @@ -1975,7 +1977,7 @@ void wxWindowMSW::DoClientToScreen(int *x, int *y) const if ( y ) pt.y = *y; - ::ClientToScreen(GetHwnd(), &pt); + ::ClientToScreen(hWnd, &pt); if ( x ) *x = pt.x; @@ -1983,6 +1985,16 @@ void wxWindowMSW::DoClientToScreen(int *x, int *y) const *y = pt.y; } +void wxWindowMSW::DoScreenToClient(int *x, int *y) const +{ + MSWDoScreenToClient(GetHwnd(), x, y); +} + +void wxWindowMSW::DoClientToScreen(int *x, int *y) const +{ + MSWDoClientToScreen(GetHwnd(), x, y); +} + bool wxWindowMSW::DoMoveSibling(WXHWND hwnd, int x, int y, int width, int height) {