From 00c63cfd3a49f06afea595fabeb9fef89a2a03d4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 27 Sep 2015 14:44:08 +0200 Subject: [PATCH] Really get rid of warnings in casts to WPARAM in wxMSW wxListCtrl Finally really fix the problem with an explicit cast to WPARAM needed to fix the warning for MinGW but provoking a warning with MSVC: this cast was added in 612bbde52f394e5bbb57131834f1bceba172a190, reverted in 77cfdec054792a9d1b90d15e5e3861a2f0291d7c and added back in 36e5a9a7c437ff0b811159c445393833012bbc5c and so we were back to having warnings in MSVC 64 bit builds. Work around them by defining NO_ITEM constant differently for MinGW and MSVC to satisfy both of them. --- src/msw/listctrl.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 67edd145b1..afcf3f5dde 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -54,6 +54,18 @@ #define NMLVFINDITEM NM_FINDITEM #endif +// MinGW headers lack casts to WPARAM inside several ListView_XXX() macros, so +// add them to suppress the warnings about implicit conversions/truncation. +// However do not add them for MSVC as it has casts not only to WPARAM but +// actually to int first, and then to WPARAM, and casting to WPARAM here would +// result in warnings when casting 64 bit WPARAM to 32 bit int inside the +// macros in Win64 builds. +#ifdef __MINGW32__ + #define NO_ITEM (static_cast(-1)) +#else + #define NO_ITEM (-1) +#endif + // ---------------------------------------------------------------------------- // private functions // ---------------------------------------------------------------------------- @@ -1337,10 +1349,7 @@ void wxListCtrl::AssignImageList(wxImageList *imageList, int which) wxSize wxListCtrl::MSWGetBestViewRect(int x, int y) const { - // The cast is necessary to suppress a MinGW warning due to a missing cast - // to WPARAM in the definition of ListView_ApproximateViewRect() in its - // own headers (this was the case up to at least MinGW 4.8). - const DWORD rc = ListView_ApproximateViewRect(GetHwnd(), x, y, (WPARAM)-1); + const DWORD rc = ListView_ApproximateViewRect(GetHwnd(), x, y, NO_ITEM); wxSize size(LOWORD(rc), HIWORD(rc)); @@ -2738,12 +2747,8 @@ static void HandleItemPaint(LPNMLVCUSTOMDRAW pLVCD, HFONT hfont) } // same thing for CDIS_FOCUS (except simpler as there is only one of them) - // - // NB: cast is needed to work around the bug in mingw32 headers which don't - // have it inside ListView_GetNextItem() itself (unlike SDK ones) if ( ::GetFocus() == hwndList && - ListView_GetNextItem( - hwndList, static_cast(-1), LVNI_FOCUSED) == item ) + ListView_GetNextItem(hwndList, NO_ITEM, LVNI_FOCUSED) == item ) { nmcd.uItemState |= CDIS_FOCUS; }