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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sun Jun 7 15:04:16 CEST 2009


Revision: 41334
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41334&view=rev
Author:   fingolfin
Date:     2009-06-07 13:04:16 +0000 (Sun, 07 Jun 2009)

Log Message:
-----------
Fix for bug #2802492 (GUI: search query causes game list scrollbar glitches)

Modified Paths:
--------------
    scummvm/trunk/gui/ListWidget.cpp
    scummvm/trunk/gui/ListWidget.h

Modified: scummvm/trunk/gui/ListWidget.cpp
===================================================================
--- scummvm/trunk/gui/ListWidget.cpp	2009-06-07 13:04:03 UTC (rev 41333)
+++ scummvm/trunk/gui/ListWidget.cpp	2009-06-07 13:04:16 UTC (rev 41334)
@@ -107,11 +107,14 @@
 void ListWidget::setSelected(int item) {
 	assert(item >= -1 && item < (int)_list.size());
 
+	// We only have to do something if the widget is enabled and the selection actually changes
 	if (isEnabled() && _selectedItem != item) {
 		if (_editMode)
 			abortEditMode();
 
 		_selectedItem = item;
+
+		// Notify clients that the selection changed.
 		sendCommand(kListSelectionChangedCmd, _selectedItem);
 
 		_currentPos = _selectedItem - _entriesPerPage / 2;
@@ -123,14 +126,13 @@
 void ListWidget::setList(const StringList &list) {
 	if (_editMode && _caretVisible)
 		drawCaret(true);
-	int size = list.size();
-	_dataList = list;
 
 	// Copy everything
+	_dataList = list;
 	_list = list;
-	_filter = "";
-	setFilter(_filter, false);
+	_filter.clear();
 
+	int size = list.size();
 	if (_currentPos >= size)
 		_currentPos = size - 1;
 	if (_currentPos < 0)
@@ -543,10 +545,11 @@
 }
 
 void ListWidget::setFilter(const String &filter, bool redraw) {
-	String filt;
+	// FIXME: This method does not deal correctly with edit mode!
+	// Until we fix that, let's make sure it isn't called while editing takes place
+	assert(!_editMode);
 
-	filt = filter;
-
+	String filt = filter;
 	filt.toLowercase();
 
 	if (_filter == filt) // Filter was not changed
@@ -554,20 +557,22 @@
 
 	_filter = filt;
 
-	if (_filter == "") {
+	if (_filter.empty()) {
+		// No filter -> display everything
 		_list = _dataList;
 	} else {
+		// Restrict the list to everything which contains _filter as a substring,
+		// ignoring case.
 		String tmp;
 		int n = 0;
 
 		_list.clear();
-	
 		_listIndex.clear();
 
-		for (StringList::iterator i = _dataList.begin(); i != _dataList.end(); ++i, n++) {
+		for (StringList::iterator i = _dataList.begin(); i != _dataList.end(); ++i, ++n) {
 			tmp = *i;
 			tmp.toLowercase();
-			if (tmp.contains(_filter.c_str())) {
+			if (tmp.contains(_filter)) {
 				_list.push_back(*i);
 				_listIndex.push_back(n);
 			}
@@ -579,8 +584,18 @@
 
 	if (redraw) {
 		scrollBarRecalc();
-
-		draw();
+		// Redraw the whole dialog. This is annoying, as this might be rather
+		// expensive when really only the list widget and its scroll bar area
+		// to be redrawn. However, since the scrollbar might change its
+		// visibility status, and the list its width, we cannot just redraw
+		// the two.
+		// TODO: A more efficient (and elegant?) way to handle this would be to
+		// introduce a kind of "BoxWidget" or "GroupWidget" which defines a
+		// rectangular region and subwidgets can be placed within it.
+		// Such a widget could also (optionally) draw a border (or even different
+		// kinds of borders) around the objects it groups; and also a 'title'
+		// (I am borrowing these "ideas" from the NSBox class in Cocoa :).
+		_boss->draw();
 	}
 }
 

Modified: scummvm/trunk/gui/ListWidget.h
===================================================================
--- scummvm/trunk/gui/ListWidget.h	2009-06-07 13:04:03 UTC (rev 41333)
+++ scummvm/trunk/gui/ListWidget.h	2009-06-07 13:04:16 UTC (rev 41334)
@@ -90,7 +90,7 @@
 	void setList(const StringList &list);
 	void append(const String &s);
 	const StringList &getList()	const			{ return _dataList; }
-	int getSelected() const						{ return (_filter == "" || _selectedItem == -1) ? _selectedItem : _listIndex[_selectedItem]; }
+	int getSelected() const						{ return (_filter.empty() || _selectedItem == -1) ? _selectedItem : _listIndex[_selectedItem]; }
 	void setSelected(int item);
 	const String &getSelectedString() const		{ return _list[_selectedItem]; }
 	void setNumberingMode(NumberingMode numberingMode)	{ _numberingMode = numberingMode; }


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