[Scummvm-cvs-logs] CVS: scummvm/gui dialog.cpp,1.43,1.44 dialog.h,1.28,1.29

Max Horn fingolfin at users.sourceforge.net
Sat Dec 25 15:21:01 CET 2004


Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21478

Modified Files:
	dialog.cpp dialog.h 
Log Message:
Fix bug #1091189 (GUI: Launcher List/Edit game interaction)

Index: dialog.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.cpp,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- dialog.cpp	6 Jan 2004 12:45:29 -0000	1.43
+++ dialog.cpp	25 Dec 2004 23:20:37 -0000	1.44
@@ -36,6 +36,11 @@
  * ...
  */
 
+Dialog::Dialog(int x, int y, int w, int h)
+	: GuiObject(x, y, w, h),
+	  _mouseWidget(0), _focusedWidget(0), _clickedWidget(0), _visible(false) {
+}
+
 Dialog::~Dialog() {
 	delete _firstWidget;
 	_firstWidget = 0;
@@ -114,15 +119,12 @@
 void Dialog::handleMouseDown(int x, int y, int button, int clickCount) {
 	Widget *w;
 	w = findWidget(x, y);
+	
+	_clickedWidget = w;
 
 	// If the click occured inside a widget which is not the currently
 	// focused one, change the focus to that widget.
-	// TODO: use the wantsFocus() method to objects, so that only fields
-	// that want it get the focus (like edit fields, list field...)
-	// However, right now we "abuse" the focus also for the click&drag
-	// behaviour of buttons. This should probably be changed by adding
-	// a nother field, e.g. _clickedWidget or _dragWidget.
-	if (w && w != _focusedWidget) {
+	if (w && w != _focusedWidget && w->wantsFocus()) {
 		// The focus will change. Tell the old focused widget (if any)
 		// that it lost the focus.
 		releaseFocus();
@@ -134,27 +136,28 @@
 		_focusedWidget = w;
 	}
 
-	if (w && w == _focusedWidget)
-		_focusedWidget->handleMouseDown(x - (_focusedWidget->getAbsX() - _x), y - (_focusedWidget->getAbsY() - _y), button, clickCount);
+	if (w)
+		w->handleMouseDown(x - (w->getAbsX() - _x), y - (w->getAbsY() - _y), button, clickCount);
 }
 
 void Dialog::handleMouseUp(int x, int y, int button, int clickCount) {
 	Widget *w;
 
+	w = findWidget(x, y);
+
 	if (_focusedWidget) {
-		w = _focusedWidget;
+		//w = _focusedWidget;
 		
 		// Lose focus on mouseup unless the widget requested to retain the focus
 		if (! (_focusedWidget->getFlags() & WIDGET_RETAIN_FOCUS )) {
 			releaseFocus();
 		}
-
-	} else {
-		w = findWidget(x, y);
 	}
 
-	if (w)
+	if (w && w == _clickedWidget)
 		w->handleMouseUp(x - (w->getAbsX() - _x), y - (w->getAbsY() - _y), button, clickCount);
+
+	_clickedWidget = 0;
 }
 
 void Dialog::handleMouseWheel(int x, int y, int direction) {
@@ -211,7 +214,10 @@
 void Dialog::handleMouseMoved(int x, int y, int button) {
 	Widget *w;
 	
-	if (_focusedWidget) {
+	//if (!button)
+	//	_clickedWidget = 0;
+	
+	if (_focusedWidget && !_clickedWidget) {
 		w = _focusedWidget;
 		int wx = w->getAbsX() - _x;
 		int wy = w->getAbsY() - _y;
@@ -220,6 +226,8 @@
 		// (but to no other items).
 		bool mouseInFocusedWidget = (x >= wx && x < wx + w->_w && y >= wy && y < wy + w->_h);
 		if (mouseInFocusedWidget && _mouseWidget != w) {
+			if (_mouseWidget)
+				_mouseWidget->handleMouseLeft(button);
 			_mouseWidget = w;
 			w->handleMouseEntered(button);
 		} else if (!mouseInFocusedWidget && _mouseWidget == w) {
@@ -231,6 +239,12 @@
 	}
 
 	w = findWidget(x, y);
+	
+	// While a "drag" is in process (i.e. mouse is moved while a button is pressed),
+	// only deal with the widget in which the click originated.
+	if (_clickedWidget && w != _clickedWidget) {
+		w = 0;
+	}
 
 	if (_mouseWidget != w) {
 		if (_mouseWidget)
@@ -240,11 +254,9 @@
 		_mouseWidget = w;
 	} 
 
-	if (!w || !(w->getFlags() & WIDGET_TRACK_MOUSE)) {
-		return;
+	if (w && (w->getFlags() & WIDGET_TRACK_MOUSE)) {
+		w->handleMouseMoved(x - (w->getAbsX() - _x), y - (w->getAbsY() - _y), button);
 	}
-
-	w->handleMouseMoved(x - (w->getAbsX() - _x), y - (w->getAbsY() - _y), button);
 }
 
 void Dialog::handleTickle() {

Index: dialog.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- dialog.h	13 Mar 2004 13:03:25 -0000	1.28
+++ dialog.h	25 Dec 2004 23:20:37 -0000	1.29
@@ -41,16 +41,14 @@
 protected:
 	Widget	*_mouseWidget;
 	Widget  *_focusedWidget;
+	Widget  *_clickedWidget;
 	bool	_visible;
 
 private:
 	int		_result;
 
 public:
-	Dialog(int x, int y, int w, int h)
-		: GuiObject(x, y, w, h),
-		  _mouseWidget(0), _focusedWidget(0), _visible(false) {
-	}
+	Dialog(int x, int y, int w, int h);
 	virtual ~Dialog();
 
 	virtual int runModal();





More information about the Scummvm-git-logs mailing list