From 252551fd2696a4180011bcbae4c17dfceccaf205 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 10 Dec 2022 18:26:48 +0000 Subject: [PATCH] Add wxMapWindowPoints() private helper function This allows to avoid having to use casts from RECT to POINT in the rest of the code by encapsulating this cast, and the comment explaining it, in this function only. No real changes. --- include/wx/msw/private.h | 15 +++++++++++++++ src/msw/msgdlg.cpp | 5 +---- src/msw/notebook.cpp | 2 +- src/msw/treectrl.cpp | 2 +- src/msw/window.cpp | 7 ++++--- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/include/wx/msw/private.h b/include/wx/msw/private.h index 96362e4a1b..4e954904b5 100644 --- a/include/wx/msw/private.h +++ b/include/wx/msw/private.h @@ -386,6 +386,21 @@ inline RECT wxGetClientRect(HWND hwnd) return rect; } +// Call MapWindowPoints() on a RECT: because a RECT is (intentionally) laid out +// as 2 consecutive POINTs, the cast below is valid but we still prefer to hide +// it in this function instead of writing it out in the rest of the code. +inline void wxMapWindowPoints(HWND hwndFrom, HWND hwndTo, RECT* rc) +{ + ::MapWindowPoints(hwndFrom, hwndTo, reinterpret_cast(rc), 2); +} + +// For consistency also provide an overload taking a POINT, even if this one is +// even more trivial. +inline void wxMapWindowPoints(HWND hwndFrom, HWND hwndTo, POINT* pt) +{ + ::MapWindowPoints(hwndFrom, hwndTo, pt, 1); +} + // --------------------------------------------------------------------------- // small helper classes // --------------------------------------------------------------------------- diff --git a/src/msw/msgdlg.cpp b/src/msw/msgdlg.cpp index b239fd9024..f6103b7c16 100644 --- a/src/msw/msgdlg.cpp +++ b/src/msw/msgdlg.cpp @@ -87,10 +87,7 @@ wxMessageDialogMap& HookMap() void ScreenRectToClient(HWND hwnd, RECT& rc) { // map from desktop (i.e. screen) coordinates to ones of this window - // - // notice that a RECT is laid out as 2 consecutive POINTs so the cast is - // valid - ::MapWindowPoints(HWND_DESKTOP, hwnd, reinterpret_cast(&rc), 2); + wxMapWindowPoints(HWND_DESKTOP, hwnd, &rc); } // set window position to the given rect diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index caf75fa698..79617d4530 100644 --- a/src/msw/notebook.cpp +++ b/src/msw/notebook.cpp @@ -1195,7 +1195,7 @@ bool wxNotebook::MSWPrintChild(WXHDC hDC, wxWindow *child) // map rect to the coords of the window we're drawing in if ( child ) - ::MapWindowPoints(GetHwnd(), GetHwndOf(child), (POINT *)&rc, 2); + wxMapWindowPoints(GetHwnd(), GetHwndOf(child), &rc); // If we're using a solid colour (for example if we've switched off // theming for this notebook), paint it diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index 83b5cf33a9..5c4cfbd408 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -3660,7 +3660,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) POINT point; point.x = GET_X_LPARAM(pos); point.y = GET_Y_LPARAM(pos); - ::MapWindowPoints(HWND_DESKTOP, GetHwnd(), &point, 1); + wxMapWindowPoints(HWND_DESKTOP, GetHwnd(), &point); int htFlags = 0; wxTreeItemId item = HitTest(wxPoint(point.x, point.y), htFlags); diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 07f150afe8..ec87aa140c 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -1950,8 +1950,9 @@ void wxWindowMSW::DoGetPosition(int *x, int *y) const { // In RTL mode, we want the logical left x-coordinate, // which would be the physical right x-coordinate. - ::MapWindowPoints(nullptr, parent ? GetHwndOf(parent) : HWND_DESKTOP, - (LPPOINT)&rect, 2); + wxMapWindowPoints(HWND_DESKTOP, + parent ? GetHwndOf(parent) : HWND_DESKTOP, + &rect); } pos.x = rect.left; @@ -5456,7 +5457,7 @@ wxWindowMSW::MSWGetBgBrushForChild(WXHDC hDC, wxWindowMSW *child) // uses RTL layout, which is exactly what we need here as the child // window origin is its _right_ top corner in this case and not the // left one. - ::MapWindowPoints(nullptr, GetHwnd(), (POINT *)&rc, 2); + wxMapWindowPoints(HWND_DESKTOP, GetHwnd(), &rc); int x = rc.left, y = rc.top;