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 b3cbec7140..899d3e3ec1 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 @@ -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)