diff --git a/include/wx/univ/listbox.h b/include/wx/univ/listbox.h index f4bc78cad4..4f8c063ca4 100644 --- a/include/wx/univ/listbox.h +++ b/include/wx/univ/listbox.h @@ -116,6 +116,8 @@ protected: void **clientData, wxClientDataType type) wxOVERRIDE; + virtual int DoListHitTest(const wxPoint& point) const wxOVERRIDE; + // universal wxComboBox implementation internally uses wxListBox friend class WXDLLIMPEXP_FWD_CORE wxComboBox; diff --git a/src/univ/listbox.cpp b/src/univ/listbox.cpp index 0255933781..441cd646d7 100644 --- a/src/univ/listbox.cpp +++ b/src/univ/listbox.cpp @@ -1112,6 +1112,34 @@ void wxListBox::Activate(int item) } } +// ---------------------------------------------------------------------------- +// hittest +// ---------------------------------------------------------------------------- + +int wxListBox::DoListHitTest(const wxPoint& point) const +{ + if ( !GetClientRect().Contains(point) ) + return wxNOT_FOUND; + + int y, index; + + 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; + } + + return index; +} + // ---------------------------------------------------------------------------- // input handling // ----------------------------------------------------------------------------