From 75134c752eedc5c6c25fab04c4762cd60acd567c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 6 Aug 2019 00:02:35 +0200 Subject: [PATCH] Prettify the changes of the previous commit Use switch over enum value instead of consecutive ifs. Don't duplicate wxGetListCtrlSubItemRect() code, just call it instead. See https://github.com/wxWidgets/wxWidgets/pull/1461 --- samples/listctrl/listtest.cpp | 26 ++++++++++++++++++-------- src/msw/listctrl.cpp | 15 +++++++++------ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index 9db79f91d2..80be50908b 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -1324,15 +1324,25 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event) wxLogError("Failed to retrieve rect of item %ld column %d", item, subItem + 1); break; } - wxString message = "Bounding rect of %s item %ld column %d is (%d, %d)-(%d, %d)"; + wxString part; - if( code == wxLIST_RECT_BOUNDS ) - part = "subitem"; - if( code == wxLIST_RECT_ICON ) - part = "icon"; - if( code == wxLIST_RECT_LABEL ) - part = "label"; - wxLogMessage( message, part, item, subItem + 1, r.x, r.y, r.x + r.width, r.y + r.height ); + switch ( code ) + { + case wxLIST_RECT_BOUNDS: + part = "total rectangle"; + break; + + case wxLIST_RECT_ICON: + part = "icon"; + break; + + case wxLIST_RECT_LABEL: + part = "label"; + break; + } + + wxLogMessage("Bounding rect of the %s of the item %ld column %d is (%d, %d)-(%d, %d)", + part, item, subItem + 1, r.x, r.y, r.x + r.width, r.y + r.height); } break; diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index b0e9b09cfc..386a7d1a4e 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -1241,15 +1241,18 @@ bool wxListCtrl::GetSubItemRect(long item, long subItem, wxRect& rect, int code) { return false; } - if( code == wxLIST_RECT_LABEL ) + + // Although LVIR_LABEL exists, it returns the same results as LVIR_BOUNDS + // and not just the label rectangle as would be expected, so account for + // the icon ourselves in this case. + if ( code == wxLIST_RECT_LABEL ) { RECT rectIcon; - rectIcon.top = subItem; - rectIcon.left = LVIR_ICON; - if( !( ::SendMessageA(GetHwnd(), LVM_GETSUBITEMRECT, item, (LPARAM)&rectIcon) ) ) + if ( !wxGetListCtrlSubItemRect(GetHwnd(), item, subItem, LVIR_ICON, + rectIcon) ) return false; - else - rectWin.left = rectIcon.right; + + rectWin.left = rectIcon.right; } wxCopyRECTToRect(rectWin, rect);