From c6a081ba610c5f5f298bc80c2ef28facb41dffae Mon Sep 17 00:00:00 2001 From: Angelo Castellani Date: Sat, 21 May 2011 15:06:36 -0400 Subject: Fixed listbox selection issue Clicking below the last item of a listbox would select the last item. Made it do nothing instead. --- src/gui/widgets/listbox.cpp | 15 ++++++++++++++- src/gui/widgets/listbox.h | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index d79d8d0c..570983ca 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -120,6 +120,18 @@ void ListBox::keyPressed(gcn::KeyEvent& keyEvent) // Don't do anything on scrollwheel. ScrollArea will deal with that. +void ListBox::mousePressed(gcn::MouseEvent &mouseEvent) +{ + if (mouseEvent.getButton() != gcn::MouseEvent::LEFT) + return; + + int y = std::max(0, mouseEvent.getY()); + if (y / (int)getRowHeight() < getListModel()->getNumberOfElements()) + setSelected(y / getRowHeight()); + else + setSelected(-1); +} + void ListBox::mouseWheelMovedUp(gcn::MouseEvent &mouseEvent) { } @@ -135,5 +147,6 @@ void ListBox::mouseDragged(gcn::MouseEvent &event) // Make list selection update on drag, but guard against negative y int y = std::max(0, event.getY()); - setSelected(y / getRowHeight()); + if (y / (int)getRowHeight() < getListModel()->getNumberOfElements()) + setSelected(y / getRowHeight()); } diff --git a/src/gui/widgets/listbox.h b/src/gui/widgets/listbox.h index 4984a3ce..61c564bb 100644 --- a/src/gui/widgets/listbox.h +++ b/src/gui/widgets/listbox.h @@ -66,6 +66,8 @@ class ListBox : public gcn::ListBox // Inherited from MouseListener + void mousePressed(gcn::MouseEvent& mouseEvent); + void mouseWheelMovedUp(gcn::MouseEvent& mouseEvent); void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent); -- cgit v1.2.3-70-g09d2