From d647d8a558d28af796f4e396dd71e852b856a131 Mon Sep 17 00:00:00 2001 From: Lauri Nurmi Date: Mon, 10 Feb 2025 09:39:11 +0200 Subject: [PATCH] Add subitem support to wxGenericListCtrl::HitTest() See #25153. (cherry picked from commit 580df3d670fa2ee0430588b9a4bc124403b15f86) --- docs/changes.txt | 1 + interface/wx/listctrl.h | 7 ++++--- src/generic/listctrl.cpp | 19 ++++++++++++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 1e62b4833c..9dce1b3fb4 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -275,6 +275,7 @@ All (GUI): - Fix multiple bugs in wxStaticText::Wrap() (#23339). - Recognize "current" and "pressed" in wxBitmapButton XRC handler (#25114). - Fix wrong row parameter in wxEVT_GRID_ROW_MOVE events (Tony Kennedy). +- Add subitem support to wxGenericListCtrl::HitTest() (Lauri Nurmi, #25153). - Fix WX_GL_COMPAT_PROFILE spelling (#24964). wxGTK: diff --git a/interface/wx/listctrl.h b/interface/wx/listctrl.h index 6897fcf9cf..5cbffab8e3 100644 --- a/interface/wx/listctrl.h +++ b/interface/wx/listctrl.h @@ -884,9 +884,10 @@ public: If @a ptrSubItem is not @NULL and the wxListCtrl is in the report mode the subitem (or column) number will also be provided. - This feature is only available in version 2.7.0 or higher and is currently only - implemented under wxMSW and requires at least comctl32.dll of version 4.70 on - the host system or the value stored in @a ptrSubItem will be always -1. + This feature is available since version 3.2.7 in the generic control; + in earlier versions the value stored in @a ptrSubItem will be always -1. + Under wxMSW, the feature is available since version 2.7.0, and requires + at least comctl32.dll of version 4.70 on the host system. To compile this feature into wxWidgets library you need to have access to commctrl.h of version 4.70 that is provided by Microsoft. diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 5d4d0a653a..692dcd3bd6 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -5557,9 +5557,26 @@ long wxGenericListCtrl::FindItem( long WXUNUSED(start), const wxPoint& pt, long wxGenericListCtrl::HitTest(const wxPoint& point, int& flags, long *col) const { - // TODO: sub item hit testing if ( col ) + { *col = -1; + if ( InReportView() ) + { + const wxPoint unscrolled = CalcUnscrolledPosition( point ); + + for ( int c = 0, wsum = 0, cols = GetColumnCount(); + c < cols; + ++c ) + { + wsum += GetColumnWidth(c); + if ( wsum > unscrolled.x ) + { + *col = c; + break; + } + } + } + } return m_mainWin->HitTest( (int)point.x, (int)point.y, flags ); }