summaryrefslogtreecommitdiff
path: root/src/gui/widgets/listbox.cpp
diff options
context:
space:
mode:
authorAngelo Castellani <udp.castellani@gmail.com>2011-05-21 15:06:36 -0400
committerStefan Dombrowski <stefan@uni-bonn.de>2011-05-23 00:08:18 +0200
commitc6a081ba610c5f5f298bc80c2ef28facb41dffae (patch)
treeee74a1e145d7caf4debcaf31e789cfcc566eddea /src/gui/widgets/listbox.cpp
parent144c8e85b20602a1f9dd341cc29b726adfac7690 (diff)
downloadmana-client-c6a081ba610c5f5f298bc80c2ef28facb41dffae.tar.gz
mana-client-c6a081ba610c5f5f298bc80c2ef28facb41dffae.tar.bz2
mana-client-c6a081ba610c5f5f298bc80c2ef28facb41dffae.tar.xz
mana-client-c6a081ba610c5f5f298bc80c2ef28facb41dffae.zip
Fixed listbox selection issue
Clicking below the last item of a listbox would select the last item. Made it do nothing instead.
Diffstat (limited to 'src/gui/widgets/listbox.cpp')
-rw-r--r--src/gui/widgets/listbox.cpp15
1 files changed, 14 insertions, 1 deletions
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());
}