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:
@@ -142,9 +142,8 @@ public:
|
|||||||
// select the item which is diff items below the current one
|
// select the item which is diff items below the current one
|
||||||
void ChangeCurrent(int diff);
|
void ChangeCurrent(int diff);
|
||||||
|
|
||||||
// activate (i.e. send a LISTBOX_DOUBLECLICKED message) the specified or
|
// activate (i.e. send a LISTBOX_DOUBLECLICKED message) the specified item
|
||||||
// current (if -1) item
|
void Activate(int item);
|
||||||
void Activate(int item = -1);
|
|
||||||
|
|
||||||
// select or unselect the specified or current (if -1) item
|
// select or unselect the specified or current (if -1) item
|
||||||
void DoSelect(int item = -1, bool sel = true);
|
void DoSelect(int item = -1, bool sel = true);
|
||||||
|
@@ -58,15 +58,8 @@ public:
|
|||||||
const wxMouseEvent& event);
|
const wxMouseEvent& event);
|
||||||
|
|
||||||
protected:
|
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);
|
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);
|
bool IsValidIndex(const wxListBox *listbox, int item);
|
||||||
|
|
||||||
// init m_btnCapture and m_actionMouse
|
// init m_btnCapture and m_actionMouse
|
||||||
@@ -1085,27 +1078,22 @@ void wxListBox::DoSelect(int item, bool sel)
|
|||||||
|
|
||||||
void wxListBox::SelectAndNotify(int item)
|
void wxListBox::SelectAndNotify(int item)
|
||||||
{
|
{
|
||||||
DoSelect(item);
|
if ( item != -1 )
|
||||||
|
{
|
||||||
SendEvent(wxEVT_LISTBOX);
|
DoSelect(item);
|
||||||
|
SendEvent(wxEVT_LISTBOX);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxListBox::Activate(int item)
|
void wxListBox::Activate(int item)
|
||||||
{
|
{
|
||||||
if ( item != -1 )
|
if ( item != -1 )
|
||||||
|
{
|
||||||
SetCurrentItem(item);
|
SetCurrentItem(item);
|
||||||
else
|
if ( !(GetWindowStyle() & wxLB_MULTIPLE) )
|
||||||
item = m_current;
|
DeselectAll(item);
|
||||||
|
|
||||||
if ( !(GetWindowStyle() & wxLB_MULTIPLE) )
|
|
||||||
{
|
|
||||||
DeselectAll(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( item != -1 )
|
|
||||||
{
|
|
||||||
DoSelect(item);
|
DoSelect(item);
|
||||||
|
|
||||||
SendEvent(wxEVT_LISTBOX_DCLICK);
|
SendEvent(wxEVT_LISTBOX_DCLICK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1124,16 +1112,9 @@ int wxListBox::DoListHitTest(const wxPoint& point) const
|
|||||||
CalcUnscrolledPosition(0, point.y, NULL, &y);
|
CalcUnscrolledPosition(0, point.y, NULL, &y);
|
||||||
index = y / GetLineHeight();
|
index = y / GetLineHeight();
|
||||||
|
|
||||||
if ( index < 0 )
|
// mouse is above the first item or below the last item
|
||||||
{
|
if ( index < 0 || (unsigned int)index >= GetCount() )
|
||||||
// mouse is above the first item
|
return wxNOT_FOUND;
|
||||||
index = 0;
|
|
||||||
}
|
|
||||||
else if ( (unsigned int)index >= GetCount() )
|
|
||||||
{
|
|
||||||
// mouse is below the last item
|
|
||||||
index= GetCount() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
@@ -1175,7 +1156,10 @@ bool wxListBox::PerformAction(const wxControlAction& action,
|
|||||||
item = m_current;
|
item = m_current;
|
||||||
|
|
||||||
if ( IsSelected(item) )
|
if ( IsSelected(item) )
|
||||||
|
{
|
||||||
DoUnselect(item);
|
DoUnselect(item);
|
||||||
|
SendEvent(wxEVT_LISTBOX);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
SelectAndNotify(item);
|
SelectAndNotify(item);
|
||||||
}
|
}
|
||||||
@@ -1246,36 +1230,7 @@ wxStdListboxInputHandler::wxStdListboxInputHandler(wxInputHandler *handler,
|
|||||||
int wxStdListboxInputHandler::HitTest(const wxListBox *lbox,
|
int wxStdListboxInputHandler::HitTest(const wxListBox *lbox,
|
||||||
const wxMouseEvent& event)
|
const wxMouseEvent& event)
|
||||||
{
|
{
|
||||||
int item = HitTestUnsafe(lbox, event);
|
return lbox->HitTest(event.GetPosition());
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxStdListboxInputHandler::IsValidIndex(const wxListBox *lbox, int item)
|
bool wxStdListboxInputHandler::IsValidIndex(const wxListBox *lbox, int item)
|
||||||
|
Reference in New Issue
Block a user