From 14511a8bec20e5f322513e746c1281cb86d453e2 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 23 Aug 2021 00:16:32 +0200 Subject: [PATCH 1/4] Fix selection on right click in generic wxListCtrl Right clicking item always selected it, which made it possible to have multiple selected items even in a single-selection control. Restore HighlightAll(false) erroneously removed by fedc80eee3 (Improve selection and focus events generation in wxGenericLisCtrl, 2020-09-06) to fix this and restore the correct old behaviour. Note that even in multiple selection mode right clicking a previously unselected item should still clear the selection, as it does it in the other GTK programs (and also under MSW). --- src/generic/listctrl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 81fe66ca8a..da822d8512 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -2682,6 +2682,7 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) // Multi-selections should not be cleared if a selected item is clicked. if (!IsHighlighted(current)) { + HighlightAll(false); ChangeCurrent(current); HighlightOnly(m_current); } From a90dd434f7286b9f134adc416344a97946f9c120 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 23 Aug 2021 00:21:21 +0200 Subject: [PATCH 2/4] Remove misleading word from the listctrl sample log message It was surprising to see "right double click" for a right click. --- samples/listctrl/listtest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index f2615a01b9..edae453f8b 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -1465,7 +1465,7 @@ void MyListCtrl::OnRightClick(wxMouseEvent& event) default: where = "not clear exactly where on"; break; } - wxLogMessage("Right double click %s item %ld, subitem %ld", + wxLogMessage("Right click %s item %ld, subitem %ld", where, item, subitem); } From 0e9e6aaf3a3a1a34425896df394a815a2391803a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 23 Aug 2021 00:24:24 +0200 Subject: [PATCH 3/4] Set "subitem" argument of HitTest() to -1 in generic wxListCtrl Sub-item hit testing is still not implemented, but at least initialize the output parameter to the documented value instead of leaving some junk in it. --- src/generic/listctrl.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index da822d8512..bae4eba6bf 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -5544,9 +5544,12 @@ long wxGenericListCtrl::FindItem( long WXUNUSED(start), const wxPoint& pt, return m_mainWin->FindItem( pt ); } -// TODO: sub item hit testing -long wxGenericListCtrl::HitTest(const wxPoint& point, int& flags, long *) const +long wxGenericListCtrl::HitTest(const wxPoint& point, int& flags, long *col) const { + // TODO: sub item hit testing + if ( col ) + *col = -1; + return m_mainWin->HitTest( (int)point.x, (int)point.y, flags ); } From cb6d67bab435fc1e2e1d55f4ee290c8bfeeebf0c Mon Sep 17 00:00:00 2001 From: AliKet Date: Mon, 23 Aug 2021 01:59:07 +0200 Subject: [PATCH 4/4] Reset selection on right click in a more efficient way Instead of using HighlightAll(), use the second argument of HighlightOnly() to remove selection from the previous current item. --- src/generic/listctrl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index bae4eba6bf..ab337f337f 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -2682,9 +2682,9 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) // Multi-selections should not be cleared if a selected item is clicked. if (!IsHighlighted(current)) { - HighlightAll(false); + size_t oldCurrent = m_current; ChangeCurrent(current); - HighlightOnly(m_current); + HighlightOnly(m_current, oldCurrent); } SendNotify( current, wxEVT_LIST_ITEM_RIGHT_CLICK, event.GetPosition() );