aboutsummaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2006-06-24 13:21:46 +0000
committerWillem Jan Palenstijn2006-06-24 13:21:46 +0000
commite53c1af36231ccd9196fdfe33562d4ac1b54df69 (patch)
tree4733a8d1ff9fd9b06cbb6eb4d3f7ddc88d4dbe61 /gui
parent7409ae2fbb78f4bab17398a41f0ed1235ebcded0 (diff)
downloadscummvm-rg350-e53c1af36231ccd9196fdfe33562d4ac1b54df69.tar.gz
scummvm-rg350-e53c1af36231ccd9196fdfe33562d4ac1b54df69.tar.bz2
scummvm-rg350-e53c1af36231ccd9196fdfe33562d4ac1b54df69.zip
listwidget: handle clicking outside of the list more gracefully
svn-id: r23295
Diffstat (limited to 'gui')
-rw-r--r--gui/ListWidget.cpp25
-rw-r--r--gui/ListWidget.h1
2 files changed, 16 insertions, 10 deletions
diff --git a/gui/ListWidget.cpp b/gui/ListWidget.cpp
index fc0539182e..ca4e60cd30 100644
--- a/gui/ListWidget.cpp
+++ b/gui/ListWidget.cpp
@@ -144,12 +144,9 @@ void ListWidget::handleMouseDown(int x, int y, int button, int clickCount) {
return;
// First check whether the selection changed
- int newSelectedItem;
- newSelectedItem = findItem(x, y);
- if (newSelectedItem > (int)_list.size() - 1)
- newSelectedItem = -1;
+ int newSelectedItem = findItem(x, y);
- if (_selectedItem != newSelectedItem) {
+ if (_selectedItem != newSelectedItem && newSelectedItem != -1) {
if (_editMode)
abortEditMode();
_selectedItem = newSelectedItem;
@@ -157,15 +154,17 @@ void ListWidget::handleMouseDown(int x, int y, int button, int clickCount) {
}
// TODO: Determine where inside the string the user clicked and place the
- // caret accordingly. See _editScrollOffset and EditTextWidget::handleMouseDown.
+ // caret accordingly.
+ // See _editScrollOffset and EditTextWidget::handleMouseDown.
draw();
}
void ListWidget::handleMouseUp(int x, int y, int button, int clickCount) {
- // If this was a double click and the mouse is still over the selected item,
- // send the double click command
- if (clickCount == 2 && (_selectedItem == findItem(x, y))) {
+ // If this was a double click and the mouse is still over
+ // the selected item, send the double click command
+ if (clickCount == 2 && (_selectedItem == findItem(x, y)) &&
+ _selectedItem >= 0) {
sendCommand(kListItemDoubleClickedCmd, _selectedItem);
}
}
@@ -176,7 +175,13 @@ void ListWidget::handleMouseWheel(int x, int y, int direction) {
int ListWidget::findItem(int x, int y) const {
- return (y - _topPadding) / kLineHeight + _currentPos;
+ if (y < _topPadding) return -1;
+ int item = (y - _topPadding) / kLineHeight + _currentPos;
+ if (item >= _currentPos && item < _currentPos + _entriesPerPage &&
+ item < (int)_list.size())
+ return item;
+ else
+ return -1;
}
static int matchingCharsIgnoringCase(const char *x, const char *y, bool &stop) {
diff --git a/gui/ListWidget.h b/gui/ListWidget.h
index de3518f2ed..8ce6ede3de 100644
--- a/gui/ListWidget.h
+++ b/gui/ListWidget.h
@@ -104,6 +104,7 @@ public:
protected:
void drawWidget(bool hilite);
+ //! Finds the item at position (x,y). Returns -1 if there is no item there.
int findItem(int x, int y) const;
void scrollBarRecalc();