From c3452053965f484e419ac755682562b088f47ad2 Mon Sep 17 00:00:00 2001 From: Kvaz1r Date: Tue, 13 Jul 2021 11:11:39 +0300 Subject: [PATCH 1/3] Fix wxListBox HitTest in wxUniv --- src/univ/listbox.cpp | 51 ++++---------------------------------------- 1 file changed, 4 insertions(+), 47 deletions(-) diff --git a/src/univ/listbox.cpp b/src/univ/listbox.cpp index b3cbec7140..0471a87290 100644 --- a/src/univ/listbox.cpp +++ b/src/univ/listbox.cpp @@ -58,15 +58,8 @@ public: const wxMouseEvent& event); protected: - // return the item under mouse, 0 if the mouse is above the listbox or - // GetCount() if it is below it int HitTest(const wxListBox *listbox, const wxMouseEvent& event); - // parts of HitTest(): first finds the pseudo (because not in range) index - // of the item and the second one adjusts it if necessary - that is if the - // third one returns false - int HitTestUnsafe(const wxListBox *listbox, const wxMouseEvent& event); - int FixItemIndex(const wxListBox *listbox, int item); bool IsValidIndex(const wxListBox *listbox, int item); // init m_btnCapture and m_actionMouse @@ -1124,16 +1117,9 @@ int wxListBox::DoListHitTest(const wxPoint& point) const CalcUnscrolledPosition(0, point.y, NULL, &y); index = y / GetLineHeight(); - if ( index < 0 ) - { - // mouse is above the first item - index = 0; - } - else if ( (unsigned int)index >= GetCount() ) - { - // mouse is below the last item - index= GetCount() - 1; - } + // mouse is above the first item or below the last item + if ( index < 0 || (unsigned int)index >= GetCount() ) + return wxNOT_FOUND; return index; } @@ -1246,36 +1232,7 @@ wxStdListboxInputHandler::wxStdListboxInputHandler(wxInputHandler *handler, int wxStdListboxInputHandler::HitTest(const wxListBox *lbox, const wxMouseEvent& event) { - int item = HitTestUnsafe(lbox, event); - - return FixItemIndex(lbox, item); -} - -int wxStdListboxInputHandler::HitTestUnsafe(const wxListBox *lbox, - const wxMouseEvent& event) -{ - wxPoint pt = event.GetPosition(); - pt -= lbox->GetClientAreaOrigin(); - int y; - lbox->CalcUnscrolledPosition(0, pt.y, NULL, &y); - return y / lbox->GetLineHeight(); -} - -int wxStdListboxInputHandler::FixItemIndex(const wxListBox *lbox, - int item) -{ - if ( item < 0 ) - { - // mouse is above the first item - item = 0; - } - else if ( (unsigned int)item >= lbox->GetCount() ) - { - // mouse is below the last item - item = lbox->GetCount() - 1; - } - - return item; + return lbox->HitTest(event.GetPosition()); } bool wxStdListboxInputHandler::IsValidIndex(const wxListBox *lbox, int item) From 0a241d2dfcdf59ed7c2dad522906fc1bceaa04fe Mon Sep 17 00:00:00 2001 From: Kvaz1r Date: Tue, 13 Jul 2021 11:37:46 +0300 Subject: [PATCH 2/3] Don't send events for non-item --- include/wx/univ/listbox.h | 5 ++--- src/univ/listbox.cpp | 21 ++++++++------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/include/wx/univ/listbox.h b/include/wx/univ/listbox.h index cbd2819bbe..3e4ccd26ca 100644 --- a/include/wx/univ/listbox.h +++ b/include/wx/univ/listbox.h @@ -142,9 +142,8 @@ public: // select the item which is diff items below the current one void ChangeCurrent(int diff); - // activate (i.e. send a LISTBOX_DOUBLECLICKED message) the specified or - // current (if -1) item - void Activate(int item = -1); + // activate (i.e. send a LISTBOX_DOUBLECLICKED message) the specified item + void Activate(int item); // select or unselect the specified or current (if -1) item void DoSelect(int item = -1, bool sel = true); diff --git a/src/univ/listbox.cpp b/src/univ/listbox.cpp index 0471a87290..b5bbb997c6 100644 --- a/src/univ/listbox.cpp +++ b/src/univ/listbox.cpp @@ -1078,27 +1078,22 @@ void wxListBox::DoSelect(int item, bool sel) void wxListBox::SelectAndNotify(int item) { - DoSelect(item); - - SendEvent(wxEVT_LISTBOX); + if( item != -1 ) + { + DoSelect(item); + SendEvent(wxEVT_LISTBOX); + } } void wxListBox::Activate(int item) { if ( item != -1 ) + { SetCurrentItem(item); - else - item = m_current; + if ( !(GetWindowStyle() & wxLB_MULTIPLE) ) + DeselectAll(item); - if ( !(GetWindowStyle() & wxLB_MULTIPLE) ) - { - DeselectAll(item); - } - - if ( item != -1 ) - { DoSelect(item); - SendEvent(wxEVT_LISTBOX_DCLICK); } } From 1e680157a9469e0316e578bc8f21163c85b453ed Mon Sep 17 00:00:00 2001 From: Kvaz1r Date: Sat, 17 Jul 2021 20:48:31 +0300 Subject: [PATCH 3/3] Send event on toggle deselecting --- src/univ/listbox.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/univ/listbox.cpp b/src/univ/listbox.cpp index b5bbb997c6..899d3e3ec1 100644 --- a/src/univ/listbox.cpp +++ b/src/univ/listbox.cpp @@ -1078,7 +1078,7 @@ void wxListBox::DoSelect(int item, bool sel) void wxListBox::SelectAndNotify(int item) { - if( item != -1 ) + if ( item != -1 ) { DoSelect(item); SendEvent(wxEVT_LISTBOX); @@ -1156,7 +1156,10 @@ bool wxListBox::PerformAction(const wxControlAction& action, item = m_current; if ( IsSelected(item) ) + { DoUnselect(item); + SendEvent(wxEVT_LISTBOX); + } else SelectAndNotify(item); }