aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gui/EditTextWidget.cpp26
-rw-r--r--gui/EditTextWidget.h5
-rw-r--r--gui/ListWidget.cpp16
-rw-r--r--gui/ListWidget.h4
-rw-r--r--gui/dialog.cpp14
-rw-r--r--gui/dialog.h4
-rw-r--r--gui/newgui.cpp24
-rw-r--r--gui/newgui.h6
-rw-r--r--gui/widget.h4
-rw-r--r--scumm/dialogs.cpp6
-rw-r--r--scumm/dialogs.h8
11 files changed, 52 insertions, 65 deletions
diff --git a/gui/EditTextWidget.cpp b/gui/EditTextWidget.cpp
index b10b44ce4d..e91aff4986 100644
--- a/gui/EditTextWidget.cpp
+++ b/gui/EditTextWidget.cpp
@@ -29,8 +29,6 @@ EditTextWidget::EditTextWidget(Dialog *boss, int x, int y, int w, int h, const S
_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE;
_type = kEditTextWidget;
- _currentKeyDown = 0;
-
_caretVisible = false;
_caretTime = 0;
}
@@ -54,7 +52,7 @@ void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount)
// a mouse click should place the caret.
}
-bool EditTextWidget::handleKeyDown(char key, int modifiers)
+bool EditTextWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers)
{
bool handled = true;
bool dirty = false;
@@ -63,7 +61,7 @@ bool EditTextWidget::handleKeyDown(char key, int modifiers)
if (_caretVisible)
drawCaret(true);
- switch (key) {
+ switch (keycode) {
case '\n': // enter/return
case '\r':
_boss->releaseFocus();
@@ -87,8 +85,8 @@ bool EditTextWidget::handleKeyDown(char key, int modifiers)
case 23: // end
break;
default:
- if (isalnum(key) || key == ' ' || key == '-' || key == '_') {
- _label += key;
+ if (isprint((char)ascii)) {
+ _label += (char)ascii;
dirty = true;
} else {
handled = false;
@@ -97,26 +95,10 @@ bool EditTextWidget::handleKeyDown(char key, int modifiers)
if (dirty)
draw();
-
-#ifndef _WIN32_WCE
-
- // not done on WinCE because keyboard is emulated and
- // keyup is not generated
-
- _currentKeyDown = key;
-
-#endif
return handled;
}
-bool EditTextWidget::handleKeyUp(char key, int modifiers)
-{
- if (key == _currentKeyDown)
- _currentKeyDown = 0;
- return true;
-}
-
void EditTextWidget::drawWidget(bool hilite)
{
NewGui *gui = _boss->getGui();
diff --git a/gui/EditTextWidget.h b/gui/EditTextWidget.h
index ecc5c2fe34..9795bc1012 100644
--- a/gui/EditTextWidget.h
+++ b/gui/EditTextWidget.h
@@ -30,7 +30,6 @@ class EditTextWidget : public StaticTextWidget {
typedef ScummVM::StringList StringList;
typedef ScummVM::String String;
protected:
- int _currentKeyDown;
String _backupString;
bool _caretVisible;
uint32 _caretTime;
@@ -39,9 +38,7 @@ public:
virtual void handleTickle();
virtual void handleMouseDown(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);
+ virtual bool handleKeyDown(uint16 ascii, int keycode, int modifiers);
virtual bool wantsFocus() { return true; };
diff --git a/gui/ListWidget.cpp b/gui/ListWidget.cpp
index 9a81800b19..3a1937d0fe 100644
--- a/gui/ListWidget.cpp
+++ b/gui/ListWidget.cpp
@@ -136,7 +136,7 @@ void ListWidget::handleMouseWheel(int x, int y, int direction)
_scrollBar->handleMouseWheel(x, y, direction);
}
-bool ListWidget::handleKeyDown(char key, int modifiers)
+bool ListWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers)
{
bool handled = true;
bool dirty = false;
@@ -147,7 +147,7 @@ bool ListWidget::handleKeyDown(char key, int modifiers)
if (_caretVisible)
drawCaret(true);
- switch (key) {
+ switch (keycode) {
case '\n': // enter/return
case '\r':
// enter, confirm edit and exit editmode
@@ -166,8 +166,8 @@ bool ListWidget::handleKeyDown(char key, int modifiers)
dirty = true;
break;
default:
- if (isalnum(key) || key == ' ' || key == '-' || key == '_') {
- _list[_selectedItem] += key;
+ if (isprint((char)ascii)) {
+ _list[_selectedItem] += (char)ascii;
dirty = true;
} else {
handled = false;
@@ -177,7 +177,7 @@ bool ListWidget::handleKeyDown(char key, int modifiers)
} else {
// not editmode
- switch (key) {
+ switch (keycode) {
case '\n': // enter
case '\r':
if (_selectedItem >= 0) {
@@ -234,16 +234,16 @@ bool ListWidget::handleKeyDown(char key, int modifiers)
// not done on WinCE because keyboard is emulated and
// keyup is not generated
- _currentKeyDown = key;
+ _currentKeyDown = keycode;
#endif
return handled;
}
-bool ListWidget::handleKeyUp(char key, int modifiers)
+bool ListWidget::handleKeyUp(uint16 ascii, int keycode, int modifiers)
{
- if (key == _currentKeyDown)
+ if (keycode == _currentKeyDown)
_currentKeyDown = 0;
return true;
}
diff --git a/gui/ListWidget.h b/gui/ListWidget.h
index a378414958..1d1cb6c626 100644
--- a/gui/ListWidget.h
+++ b/gui/ListWidget.h
@@ -74,8 +74,8 @@ public:
virtual void handleMouseDown(int x, int y, int button, int clickCount);
virtual void handleMouseUp(int x, int y, int button, int clickCount);
virtual void handleMouseWheel(int x, int y, int direction);
- virtual bool handleKeyDown(char key, int modifiers);
- virtual bool handleKeyUp(char key, int modifiers);
+ virtual bool handleKeyDown(uint16 ascii, int keycode, int modifiers);
+ virtual bool handleKeyUp(uint16 ascii, int keycode, int modifiers);
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
virtual bool wantsFocus() { return true; };
diff --git a/gui/dialog.cpp b/gui/dialog.cpp
index d2eb689d2e..6286bbfaf9 100644
--- a/gui/dialog.cpp
+++ b/gui/dialog.cpp
@@ -188,17 +188,17 @@ void Dialog::handleMouseWheel(int x, int y, int direction)
w->handleMouseWheel(x, y, direction);
}
-void Dialog::handleKeyDown(char key, int modifiers)
+void Dialog::handleKeyDown(uint16 ascii, int keycode, int modifiers)
{
if (_focusedWidget) {
- if (_focusedWidget->handleKeyDown(key, modifiers))
+ if (_focusedWidget->handleKeyDown(ascii, keycode, modifiers))
return;
} else {
// Hotkey handling
Widget *w = _firstWidget;
- key = toupper(key);
+ ascii = toupper(ascii);
while (w) {
- if (w->_type == kButtonWidget && key == toupper(((ButtonWidget *)w)->_hotkey)) {
+ if (w->_type == kButtonWidget && ascii == toupper(((ButtonWidget *)w)->_hotkey)) {
// We first send a mouseDown then a mouseUp.
// FIXME: insert a brief delay between both.
w->handleMouseDown(0, 0, 1, 1);
@@ -210,17 +210,17 @@ void Dialog::handleKeyDown(char key, int modifiers)
}
// ESC closes all dialogs by default
- if (key == 27)
+ if (keycode == 27)
close();
// TODO: tab/shift-tab should focus the next/previous focusable widget
}
-void Dialog::handleKeyUp(char key, int modifiers)
+void Dialog::handleKeyUp(uint16 ascii, int keycode, int modifiers)
{
// Focused widget recieves keyup events
if (_focusedWidget)
- _focusedWidget->handleKeyUp(key, modifiers);
+ _focusedWidget->handleKeyUp(ascii, keycode, modifiers);
}
void Dialog::handleMouseMoved(int x, int y, int button)
diff --git a/gui/dialog.h b/gui/dialog.h
index 2096e325e5..2468275e31 100644
--- a/gui/dialog.h
+++ b/gui/dialog.h
@@ -75,8 +75,8 @@ protected:
virtual void handleMouseDown(int x, int y, int button, int clickCount);
virtual void handleMouseUp(int x, int y, int button, int clickCount);
virtual void handleMouseWheel(int x, int y, int direction);
- virtual void handleKeyDown(char key, int modifiers);
- virtual void handleKeyUp(char key, int modifiers);
+ virtual void handleKeyDown(uint16 ascii, int keycode, int modifiers);
+ virtual void handleKeyUp(uint16 ascii, int keycode, int modifiers);
virtual void handleMouseMoved(int x, int y, int button);
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
diff --git a/gui/newgui.cpp b/gui/newgui.cpp
index 3b30f410bc..a30be8ad10 100644
--- a/gui/newgui.cpp
+++ b/gui/newgui.cpp
@@ -82,7 +82,7 @@ static byte guifont[] = {
// Constructor
NewGui::NewGui(OSystem *system) : _system(system), _screen(0), _needRedraw(false),
- _stateIsSaved(false), _currentKeyDown(0), _cursorAnimateCounter(0), _cursorAnimateTimer(0)
+ _stateIsSaved(false), _cursorAnimateCounter(0), _cursorAnimateTimer(0)
{
// Setup some default GUI colors.
// TODO - either use nicer values, or maybe make this configurable?
@@ -94,6 +94,9 @@ NewGui::NewGui(OSystem *system) : _system(system), _screen(0), _needRedraw(false
// Clear the cursor
memset(_cursor, 0xFF, sizeof(_cursor));
+
+ // Reset key repeat
+ _currentKeyDown.keycode = 0;
}
void NewGui::runLoop()
@@ -132,22 +135,23 @@ void NewGui::runLoop()
while (_system->poll_event(&event)) {
switch(event.event_code) {
case OSystem::EVENT_KEYDOWN:
- activeDialog->handleKeyDown((byte)event.kbd.ascii, event.kbd.flags);
+ activeDialog->handleKeyDown(event.kbd.ascii, event.kbd.keycode, event.kbd.flags);
#ifndef _WIN32_WCE
// init continuous event stream
// not done on WinCE because keyboard is emulated and
// keyup is not generated
- _currentKeyDown = event.kbd.ascii;
- _currentKeyDownFlags = event.kbd.flags;
+ _currentKeyDown.ascii = event.kbd.ascii;
+ _currentKeyDown.keycode = event.kbd.keycode;
+ _currentKeyDown.flags = event.kbd.flags;
_keyRepeatTime = time + kKeyRepeatInitialDelay;
#endif
break;
case OSystem::EVENT_KEYUP:
- activeDialog->handleKeyUp((byte)event.kbd.ascii, event.kbd.flags);
- if (event.kbd.ascii == _currentKeyDown)
+ activeDialog->handleKeyUp(event.kbd.ascii, event.kbd.keycode, event.kbd.flags);
+ if (event.kbd.keycode == _currentKeyDown.keycode)
// only stop firing events if it's the current key
- _currentKeyDown = 0;
+ _currentKeyDown.keycode = 0;
break;
case OSystem::EVENT_MOUSEMOVE:
_system->set_mouse_pos(event.mouse.x, event.mouse.y);
@@ -183,12 +187,12 @@ void NewGui::runLoop()
}
// check if event should be sent again (keydown)
- if (_currentKeyDown != 0)
+ if (_currentKeyDown.keycode != 0)
{
if (_keyRepeatTime < time)
{
// fire event
- activeDialog->handleKeyDown(_currentKeyDown, _currentKeyDownFlags);
+ activeDialog->handleKeyDown(_currentKeyDown.ascii, _currentKeyDown.keycode, _currentKeyDown.flags);
_keyRepeatTime = time + kKeyRepeatSustainDelay;
}
}
@@ -216,7 +220,7 @@ void NewGui::saveState()
// _screenPitch = _system->get_width();
_system->grab_overlay(_screen, _screenPitch);
- _currentKeyDown = 0;
+ _currentKeyDown.keycode = 0;
_lastClick.x = _lastClick.y = 0;
_lastClick.time = 0;
_lastClick.count = 0;
diff --git a/gui/newgui.h b/gui/newgui.h
index 1bd68ff0a3..25c22b8147 100644
--- a/gui/newgui.h
+++ b/gui/newgui.h
@@ -84,7 +84,11 @@ protected:
bool _stateIsSaved;
// for continuous events (keyDown)
- int _currentKeyDown, _currentKeyDownFlags;
+ struct {
+ uint16 ascii;
+ byte flags;
+ int keycode;
+ } _currentKeyDown;
uint32 _keyRepeatTime;
// position and time of last mouse click (used to detect double clicks)
diff --git a/gui/widget.h b/gui/widget.h
index aa74167f41..8330743703 100644
--- a/gui/widget.h
+++ b/gui/widget.h
@@ -110,8 +110,8 @@ public:
virtual void handleMouseLeft(int button) {}
virtual void handleMouseMoved(int x, int y, int button) {}
virtual void handleMouseWheel(int x, int y, int direction) {}
- 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 bool handleKeyDown(uint16 ascii, int keycode, int modifiers) { return false; } // Return true if the event was handled
+ virtual bool handleKeyUp(uint16 ascii, int keycode, int modifiers) { return false; } // Return true if the event was handled
virtual void handleTickle() {}
void draw();
void receivedFocus() { _hasFocus = true; receivedFocusWidget(); }
diff --git a/scumm/dialogs.cpp b/scumm/dialogs.cpp
index 69616a4e9d..b2a252c8f8 100644
--- a/scumm/dialogs.cpp
+++ b/scumm/dialogs.cpp
@@ -752,13 +752,13 @@ void KeysDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
}
}
-void KeysDialog::handleKeyDown(char key, int modifiers) {
+void KeysDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) {
if (modifiers == 0xff && _get_key_mapping) {
// GAPI key was selected
char selection[100];
- clearActionKey(key & 0xff);
- getAction(_actionSelected)->action_key = (key & 0xff);
+ clearActionKey(ascii & 0xff);
+ getAction(_actionSelected)->action_key = (ascii & 0xff);
sprintf(selection, "Associated key : %s", getGAPIKeyName((unsigned int)getAction(_actionSelected)->action_key));
_actionTitle->setLabel(queryCustomString(25));
_keyMapping->setLabel(selection);
diff --git a/scumm/dialogs.h b/scumm/dialogs.h
index 80b5fdb480..abe21082d2 100644
--- a/scumm/dialogs.h
+++ b/scumm/dialogs.h
@@ -118,12 +118,12 @@ public:
virtual void handleMouseDown(int x, int y, int button, int clickCount)
{ close(); }
- virtual void handleKeyDown(char key, int modifiers)
+ virtual void handleKeyDown(uint16 ascii, int keycode, int modifiers)
{
- if (key == ' ') // Close pause dialog if space key is pressed
+ if (ascii == ' ') // Close pause dialog if space key is pressed
close();
else
- ScummDialog::handleKeyDown(key, modifiers);
+ ScummDialog::handleKeyDown(ascii, keycode, modifiers);
}
protected:
void setInfoText (const String& message);
@@ -141,7 +141,7 @@ public:
KeysDialog(NewGui *gui, Scumm *scumm);
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
- virtual void handleKeyDown(char key, int modifiers);
+ virtual void handleKeyDown(uint16 ascii, int keycode, int modifiers);
protected: