[Scummvm-cvs-logs] CVS: scummvm/gui ListWidget.cpp,1.12,1.13 ListWidget.h,1.9,1.10 ScrollBarWidget.cpp,1.6,1.7 ScrollBarWidget.h,1.4,1.5 dialog.cpp,1.30,1.31 dialog.h,1.17,1.18 widget.cpp,1.25,1.26 widget.h,1.23,1.24

Max Horn fingolfin at users.sourceforge.net
Sat Jul 27 07:17:02 CEST 2002


Update of /cvsroot/scummvm/scummvm/gui
In directory usw-pr-cvs1:/tmp/cvs-serv29336

Modified Files:
	ListWidget.cpp ListWidget.h ScrollBarWidget.cpp 
	ScrollBarWidget.h dialog.cpp dialog.h widget.cpp widget.h 
Log Message:
heaps of changes to NewGUI: mouseDown/Up events now count the clicks (so you can detect double/triple clicks); ListWidget sends a message if an item was double clicked or changed; you can abort editing in the ListWidget by pressing ESC; SaveLoadDialog will save when you double click and item, and when you finish editing an item by pressing return, will save

Index: ListWidget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/ListWidget.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- ListWidget.cpp	18 Jul 2002 20:26:35 -0000	1.12
+++ ListWidget.cpp	27 Jul 2002 14:16:02 -0000	1.13
@@ -25,18 +25,6 @@
 #include "newgui.h"
 
 
-/*
- * TODO:
- * - Abort changes when ESC is pressed or the selection changes
- * - When the editing of a string is ended by return, we might consider sending
- *   a message. Return means that the edit was confirmed. Hence the SaveDialog
- *   could immediatly do the save in a trivial fashion.
- * - Handle double clicks: either start editing of the selected item, or
- *   send a cmd to our target (i.e. as specified via setCmd or setDoubleCmd)
- *   This will allow a double click in the load dialog to immediatly load the game
- */
-
-
 // Height of one entry
 #define	LINE_HEIGHT		10
 
@@ -72,7 +60,7 @@
 	_scrollBar->recalc();
 }
 
-void ListWidget::handleMouseDown(int x, int y, int button)
+void ListWidget::handleMouseDown(int x, int y, int button, int clickCount)
 {
 	int oldSelectedItem = _selectedItem;
 
@@ -88,8 +76,18 @@
 	}
 }
 
-void ListWidget::handleKeyDown(char key, int modifiers)
+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 > 1 && (_selectedItem == (y - 2) / LINE_HEIGHT + _currentPos)) {
+		sendCommand(kListItemDoubleClickedCmd, _selectedItem);
+	}
+}
+
+bool ListWidget::handleKeyDown(char key, int modifiers)
 {
+	bool handled = true;
 	bool dirty = false;
 	int oldSelectedItem = _selectedItem;
 
@@ -99,15 +97,19 @@
 		_list[_selectedItem].deleteLastChar();
 
 		if (key == '\n' || key == '\r') {
-			// enter, exit editmode
+			// enter, confirm edit and exit editmode
 			_editMode = false;
 			dirty = true;
-		}
-		else if (_editMode && key == 8) {	// backspace
+			sendCommand(kListItemChangedCmd, _selectedItem);
+		} else if (key == 27) {
+			// ESC, abort edit and exit editmode
+			_editMode = false;
+			dirty = true;
+			_list[_selectedItem] = _backupString;
+		} else if (key == 8) {	// backspace
 			_list[_selectedItem].deleteLastChar();
 			dirty = true;
-		} else if (_editMode &&
-					// filter keystrokes
+		} else if (// filter keystrokes
 					( ( key >= 'a' && key <= 'z' )
 					|| ( key >= 'A' && key <= 'Z' )
 					|| ( key >= '0' && key <= '9' )
@@ -117,7 +119,8 @@
 
 			_list[_selectedItem] += key;
 			dirty = true;
-		}
+		} else
+			handled = false;
 
 	} else {
 		// not editmode
@@ -129,6 +132,7 @@
 				if ((_currentKeyDown != '\n' && _currentKeyDown != '\r')) {		// override continuous enter keydown
 					_editMode = true;
 					dirty = true;
+					_backupString = _list[_selectedItem];
 				}
 			}
 			break;
@@ -156,6 +160,8 @@
 		case 23:	// end
 			_selectedItem = _list.size() - 1;
 			break;
+		default:
+			handled = false;
 		}
 
 		scrollToCurrent();
@@ -174,9 +180,11 @@
 	}
 
 	_currentKeyDown = key;
+	
+	return handled;
 }
 
-void ListWidget::handleKeyUp(char key, int modifiers)
+bool ListWidget::handleKeyUp(char key, int modifiers)
 {
 	if (key == _currentKeyDown)
 		_currentKeyDown = 0;

Index: ListWidget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/ListWidget.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- ListWidget.h	18 Jul 2002 20:26:35 -0000	1.9
+++ ListWidget.h	27 Jul 2002 14:16:02 -0000	1.10
@@ -32,9 +32,16 @@
 	kListNumberingOne	= 1
 };
 
+// Some special commands
+enum {
+	kListItemDoubleClickedCmd	= 'LIdb',	// 'data' will be item index
+	kListItemChangedCmd			= 'LIch',	// 'data' will be item index
+};
+
 /* ListWidget */
 class ListWidget : public Widget, public CommandReceiver, public CommandSender {
 	typedef ScummVM::StringList StringList;
+	typedef ScummVM::String String;
 protected:
 	StringList		_list;
 	bool			_editable;
@@ -45,6 +52,7 @@
 	int				_selectedItem;
 	ScrollBarWidget	*_scrollBar;
 	int				_currentKeyDown;
+	String			_backupString;
 public:
 	ListWidget(Dialog *boss, int x, int y, int w, int h);
 	virtual ~ListWidget();
@@ -55,9 +63,10 @@
 	const ScummVM::String& getSelectedString() const	{ return _list[_selectedItem]; }
 	void setNumberingMode(int numberingMode)	{ _numberingMode = numberingMode; }
 	
-	virtual void handleMouseDown(int x, int y, int button);
-	virtual void handleKeyDown(char key, int modifiers);
-	virtual void handleKeyUp(char key, int modifiers);
+	virtual void handleMouseDown(int x, int y, int button, int clickCount);
+	virtual void handleMouseUp(int x, int y, int button, int clickCount);
+	virtual bool handleKeyDown(char key, int modifiers);
+	virtual bool handleKeyUp(char key, int modifiers);
 	virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
 
 	void scrollBarRecalc();

Index: ScrollBarWidget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/ScrollBarWidget.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- ScrollBarWidget.cpp	18 Jul 2002 20:26:35 -0000	1.6
+++ ScrollBarWidget.cpp	27 Jul 2002 14:16:02 -0000	1.7
@@ -26,7 +26,7 @@
 
 /*
  * TODO:
- * - Auto-repeat: if one clicks & holds on one of the arrows, then after a
+ * - Auto-repeat: if user clicks & holds on one of the arrows, then after a
  *   brief delay, it should start to contiously scroll
  * - Allow for a horizontal scrollbar, too?
  * - If there are less items than fit on one pages, no scrolling can be done
@@ -70,7 +70,7 @@
 
 }
 
-void ScrollBarWidget::handleMouseDown(int x, int y, int button)
+void ScrollBarWidget::handleMouseDown(int x, int y, int button, int clickCount)
 {
 	int old_pos = _currentPos;
 
@@ -95,7 +95,7 @@
 	checkBounds(old_pos);
 }
 
-void ScrollBarWidget::handleMouseUp(int x, int y, int button)
+void ScrollBarWidget::handleMouseUp(int x, int y, int button, int clickCount)
 {
 	if (_draggingPart != kNoPart)
 		_draggingPart = kNoPart;

Index: ScrollBarWidget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/ScrollBarWidget.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- ScrollBarWidget.h	13 Jul 2002 22:41:29 -0000	1.4
+++ ScrollBarWidget.h	27 Jul 2002 14:16:02 -0000	1.5
@@ -59,8 +59,8 @@
 public:
 	ScrollBarWidget(Dialog *boss, int x, int y, int w, int h);
 
-	void handleMouseDown(int x, int y, int button);
-	void handleMouseUp(int x, int y, int button);
+	void handleMouseDown(int x, int y, int button, int clickCount);
+	void handleMouseUp(int x, int y, int button, int clickCount);
 	void handleMouseMoved(int x, int y, int button);
 	void handleMouseEntered(int button)	{ setFlags(WIDGET_HILITED); }
 	void handleMouseLeft(int button)	{ clearFlags(WIDGET_HILITED); _part = kNoPart; draw(); }

Index: dialog.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.cpp,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- dialog.cpp	27 Jul 2002 13:27:34 -0000	1.30
+++ dialog.cpp	27 Jul 2002 14:16:02 -0000	1.31
@@ -93,7 +93,7 @@
 	}
 }
 
-void Dialog::handleMouseDown(int x, int y, int button)
+void Dialog::handleMouseDown(int x, int y, int button, int clickCount)
 {
 	Widget *w;
 	w = findWidget(x, y);
@@ -112,10 +112,10 @@
 	}
 
 	if (_focusedWidget)
-		_focusedWidget->handleMouseDown(x - _focusedWidget->_x, y - _focusedWidget->_y, button);
+		_focusedWidget->handleMouseDown(x - _focusedWidget->_x, y - _focusedWidget->_y, button, clickCount);
 }
 
-void Dialog::handleMouseUp(int x, int y, int button)
+void Dialog::handleMouseUp(int x, int y, int button, int clickCount)
 {
 	Widget *w;
 	
@@ -133,17 +133,14 @@
 	}
 
 	if (w)
-		w->handleMouseUp(x - w->_x, y - w->_y, button);
+		w->handleMouseUp(x - w->_x, y - w->_y, button, clickCount);
 }
 
 void Dialog::handleKeyDown(char key, int modifiers)
 {
-	// ESC closes all dialogs by default
-	if (key == 27)
-		close();
-	
 	if (_focusedWidget) {
-		_focusedWidget->handleKeyDown(key, modifiers);
+		if (_focusedWidget->handleKeyDown(key, modifiers))
+			return;
 	} else {
 		// Hotkey handling
 		Widget *w = _firstWidget;
@@ -152,13 +149,17 @@
 			if (w->_type == kButtonWidget && key == toupper(((ButtonWidget *)w)->_hotkey)) {
 				// We first send a mouseDown then a mouseUp.
 				// FIXME: insert a brief delay between both.
-				w->handleMouseDown(0, 0, 1);
-				w->handleMouseUp(0, 0, 1);
-				break;
+				w->handleMouseDown(0, 0, 1, 1);
+				w->handleMouseUp(0, 0, 1, 1);
+				return;
 			}
 			w = w->_next;
 		}
 	}
+
+	// ESC closes all dialogs by default
+	if (key == 27)
+		close();
 }
 
 void Dialog::handleKeyUp(char key, int modifiers)
@@ -303,6 +304,7 @@
 void SaveLoadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data)
 {
 	switch (cmd) {
+	case kListItemChangedCmd:
 	case kSaveCmd:
 		if (_savegameList->getSelected() > 0 && !_savegameList->getSelectedString().isEmpty()) {
 			Scumm *s = _gui->getScumm();
@@ -313,6 +315,7 @@
 			close();
 		}
 		break;
+	case kListItemDoubleClickedCmd:
 	case kLoadCmd:
 		if (_savegameList->getSelected() > 0 && !_savegameList->getSelectedString().isEmpty()) {
 			Scumm *s = _gui->getScumm();

Index: dialog.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- dialog.h	27 Jul 2002 00:05:46 -0000	1.17
+++ dialog.h	27 Jul 2002 14:16:02 -0000	1.18
@@ -60,8 +60,8 @@
 	virtual void draw();
 
 	virtual void handleTickle(); // Called periodically (in every guiloop() )
-	virtual void handleMouseDown(int x, int y, int button);
-	virtual void handleMouseUp(int x, int y, int button);
+	virtual void handleMouseDown(int x, int y, int button, int clickCount);
+	virtual void handleMouseUp(int x, int y, int button, int clickCount);
 	virtual void handleKeyDown(char key, int modifiers);
 	virtual void handleKeyUp(char key, int modifiers);
 	virtual void handleMouseMoved(int x, int y, int button);
@@ -116,7 +116,7 @@
 public:
 	PauseDialog(NewGui *gui);
 
-	virtual void handleMouseDown(int x, int y, int button)
+	virtual void handleMouseDown(int x, int y, int button, int clickCount)
 		{ close(); }
 	virtual void handleKeyDown(char key, int modifiers)
 		{

Index: widget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- widget.cpp	27 Jul 2002 00:36:09 -0000	1.25
+++ widget.cpp	27 Jul 2002 14:16:02 -0000	1.26
@@ -140,7 +140,7 @@
 	}
 }
 
-void ButtonWidget::handleMouseUp(int x, int y, int button)
+void ButtonWidget::handleMouseUp(int x, int y, int button, int clickCount)
 {
 	if (_flags & WIDGET_ENABLED && x >= 0 && x < _w && y >= 0 && y < _h)
 		sendCommand(_cmd, 0);
@@ -168,7 +168,7 @@
 	_type = kCheckboxWidget;
 }
 
-void CheckboxWidget::handleMouseDown(int x, int y, int button)
+void CheckboxWidget::handleMouseDown(int x, int y, int button, int clickCount)
 {
 	if (_flags & WIDGET_ENABLED) {
 		_state = !_state;
@@ -221,7 +221,7 @@
 	}
 }
 
-void SliderWidget::handleMouseDown(int x, int y, int button) {
+void SliderWidget::handleMouseDown(int x, int y, int button, int clickCount) {
 	
 	if (_flags & WIDGET_ENABLED) {
 		int barx;
@@ -234,7 +234,7 @@
 	}
 }
 
-void SliderWidget::handleMouseUp(int x, int y, int button) {
+void SliderWidget::handleMouseUp(int x, int y, int button, int clickCount) {
 
 	if ((_flags & WIDGET_ENABLED) && _isDragging) {
 		sendCommand(_cmd, _value);

Index: widget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- widget.h	27 Jul 2002 00:36:09 -0000	1.23
+++ widget.h	27 Jul 2002 14:16:02 -0000	1.24
@@ -90,13 +90,13 @@
 	Widget(Dialog *boss, int x, int y, int w, int h);
 	virtual ~Widget() {}
 
-	virtual void handleMouseDown(int x, int y, int button) {}
-	virtual void handleMouseUp(int x, int y, int button) {}
+	virtual void handleMouseDown(int x, int y, int button, int clickCount) {}
+	virtual void handleMouseUp(int x, int y, int button, int clickCount) {}
 	virtual void handleMouseEntered(int button) {}
 	virtual void handleMouseLeft(int button) {}
 	virtual void handleMouseMoved(int x, int y, int button) {}
-	virtual void handleKeyDown(char key, int modifiers) {}
-	virtual void handleKeyUp(char key, int modifiers) {}
+	virtual bool handleKeyDown(char key, int modifiers) { return false; }	// Return true if the event was handled
+	virtual bool handleKeyUp(char key, int modifiers) { return false; }	// Return true if the event was handled
 	virtual void handleTickle() {}
 	void draw();
 	void receivedFocus() { _hasFocus = true; receivedFocusWidget(); }
@@ -146,7 +146,7 @@
 	void setCmd(uint32 cmd)					{ _cmd = cmd; }
 	uint32 getCmd() const					{ return _cmd; }
 
-	void handleMouseUp(int x, int y, int button);
+	void handleMouseUp(int x, int y, int button, int clickCount);
 	void handleMouseEntered(int button)	{ setFlags(WIDGET_HILITED); draw(); }
 	void handleMouseLeft(int button)	{ clearFlags(WIDGET_HILITED); draw(); }
 };
@@ -160,7 +160,7 @@
 	void setState(bool state)	{ _state = state; }
 	bool getState() const		{ return _state; }
 
-	void handleMouseDown(int x, int y, int button);
+	void handleMouseDown(int x, int y, int button, int clickCount);
 	virtual void handleMouseEntered(int button)	{}
 	virtual void handleMouseLeft(int button)	{}
 
@@ -185,8 +185,8 @@
 	int getMaxValue() const		{ return _valueMax; }
 
 	void handleMouseMoved(int x, int y, int button);
-	void handleMouseDown(int x, int y, int button);
-	void handleMouseUp(int x, int y, int button);
+	void handleMouseDown(int x, int y, int button, int clickCount);
+	void handleMouseUp(int x, int y, int button, int clickCount);
 
 protected:
 	void drawWidget(bool hilite);





More information about the Scummvm-git-logs mailing list