From 0bf223be44628bba44ce359f4b3bc92685098fd7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 27 Aug 2019 16:38:25 +0200 Subject: [PATCH] Return empty rect for wxLIST_RECT_ICON for subitems without icons It doesn't make sense to return anything else than an empty rectangle when querying the icon rectangle of the sub-items that can't show any icon. Also document this behaviour, just in case it's not obvious. --- interface/wx/listctrl.h | 5 +++++ src/msw/listctrl.cpp | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/interface/wx/listctrl.h b/interface/wx/listctrl.h index 6b9edb72d5..8ccaad95b1 100644 --- a/interface/wx/listctrl.h +++ b/interface/wx/listctrl.h @@ -756,6 +756,11 @@ public: @a code can be one of @c wxLIST_RECT_BOUNDS, @c wxLIST_RECT_ICON or @c wxLIST_RECT_LABEL. + Note that using @c wxLIST_RECT_ICON with any sub-item but the first one + isn't very useful as only the first sub-item can have an icon in + wxListCtrl. In this case, i.e. for @c subItem > 0, this function simply + returns an empty rectangle in @a rect. + @since 2.7.0 */ bool GetSubItemRect(long item, long subItem, wxRect& rect, diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 7e2512a7ad..d1508e1f39 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -1230,6 +1230,16 @@ bool wxListCtrl::GetSubItemRect(long item, long subItem, wxRect& rect, int code) break; case wxLIST_RECT_ICON: + // Only the first subitem can have an icon, so it doesn't make + // sense to query the native control for the other ones -- + // especially because it returns a nonsensical non-empty icon + // rectangle for them. + if ( subItem > 0 ) + { + rect = wxRect(); + return true; + } + codeWin = LVIR_ICON; break;