[Scummvm-cvs-logs] SF.net SVN: scummvm: [23295] scummvm/trunk/gui

wjpalenstijn at users.sourceforge.net wjpalenstijn at users.sourceforge.net
Sat Jun 24 15:21:53 CEST 2006


Revision: 23295
Author:   wjpalenstijn
Date:     2006-06-24 06:21:46 -0700 (Sat, 24 Jun 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=23295&view=rev

Log Message:
-----------
listwidget: handle clicking outside of the list more gracefully

Modified Paths:
--------------
    scummvm/trunk/gui/ListWidget.cpp
    scummvm/trunk/gui/ListWidget.h
Modified: scummvm/trunk/gui/ListWidget.cpp
===================================================================
--- scummvm/trunk/gui/ListWidget.cpp	2006-06-24 12:45:31 UTC (rev 23294)
+++ scummvm/trunk/gui/ListWidget.cpp	2006-06-24 13:21:46 UTC (rev 23295)
@@ -144,12 +144,9 @@
 		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 @@
 	}
 
 	// 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 @@
 
 
 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) {

Modified: scummvm/trunk/gui/ListWidget.h
===================================================================
--- scummvm/trunk/gui/ListWidget.h	2006-06-24 12:45:31 UTC (rev 23294)
+++ scummvm/trunk/gui/ListWidget.h	2006-06-24 13:21:46 UTC (rev 23295)
@@ -104,6 +104,7 @@
 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();
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Scummvm-git-logs mailing list