From da524ebacbe85dfb101ad5c4768a0cfb2ae386fe Mon Sep 17 00:00:00 2001 From: oneeyeman1 Date: Fri, 2 Aug 2019 18:52:12 -0500 Subject: [PATCH] Fix retrieving the size of item label in native MSW wxListCtrl Closes https://github.com/wxWidgets/wxWidgets/pull/1461 Closes #11355. --- samples/listctrl/listtest.cpp | 14 +++++++++----- src/msw/listctrl.cpp | 10 ++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index 3a7f73702e..9db79f91d2 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -1247,7 +1247,6 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event) { LogEvent(event, "OnListKeyDown"); event.Skip(); - return; } switch ( event.GetKeyCode() ) @@ -1325,10 +1324,15 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event) wxLogError("Failed to retrieve rect of item %ld column %d", item, subItem + 1); break; } - - wxLogMessage("Bounding rect of item %ld column %d is (%d, %d)-(%d, %d)", - item, subItem + 1, - r.x, r.y, r.x + r.width, r.y + r.height); + 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 ); } break; diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 9adb563fe7..b0e9b09cfc 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -1241,6 +1241,16 @@ bool wxListCtrl::GetSubItemRect(long item, long subItem, wxRect& rect, int code) { return false; } + if( code == wxLIST_RECT_LABEL ) + { + RECT rectIcon; + rectIcon.top = subItem; + rectIcon.left = LVIR_ICON; + if( !( ::SendMessageA(GetHwnd(), LVM_GETSUBITEMRECT, item, (LPARAM)&rectIcon) ) ) + return false; + else + rectWin.left = rectIcon.right; + } wxCopyRECTToRect(rectWin, rect);