Merge branch 'univ_listbox_fixtest' of https://github.com/Kvaz1r/wxWidgets

Fix wxListBox in wxUniv to pass HitTest and ClickNotOnItem unit tests.

See https://github.com/wxWidgets/wxWidgets/pull/2432
This commit is contained in:
Vadim Zeitlin 2021-07-17 20:41:50 +02:00
commit 8b0decdf9d
2 changed files with 17 additions and 63 deletions

View File

@ -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);

View File

@ -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
@ -1085,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);
}
}
@ -1124,16 +1112,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;
}
@ -1175,7 +1156,10 @@ bool wxListBox::PerformAction(const wxControlAction& action,
item = m_current;
if ( IsSelected(item) )
{
DoUnselect(item);
SendEvent(wxEVT_LISTBOX);
}
else
SelectAndNotify(item);
}
@ -1246,36 +1230,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)