2008-07-03 22:38:19 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-29 16:18:43 +00:00
|
|
|
#include "common/scummsys.h"
|
|
|
|
|
2008-09-30 13:51:01 +00:00
|
|
|
#ifdef ENABLE_VKEYBD
|
|
|
|
|
2009-01-20 16:00:36 +00:00
|
|
|
#include "backends/vkeybd/virtual-keyboard.h"
|
|
|
|
|
2008-08-07 16:38:39 +00:00
|
|
|
#include "backends/vkeybd/virtual-keyboard-gui.h"
|
|
|
|
#include "backends/vkeybd/virtual-keyboard-parser.h"
|
2008-08-15 17:53:18 +00:00
|
|
|
#include "backends/vkeybd/keycode-descriptions.h"
|
2008-08-17 12:11:34 +00:00
|
|
|
#include "common/config-manager.h"
|
2011-04-28 20:59:22 +00:00
|
|
|
#include "common/textconsole.h"
|
Merged revisions 33452-33453,33455-33459,33463-33464,33466-33471,33473-33474,33478,33490,33492,33495-33496,33509-33512,33518-33519,33522-33527,33529-33530,33537,33541,33544,33546,33550,33552-33554,33556,33558,33561-33562,33565,33568,33570,33574,33576,33578-33581,33584-33587,33590,33596,33604-33611,33614-33615,33617-33618,33620-33621,33623,33626-33627,33632-33633,33635,33637,33639-33640,33642-33645,33648,33654-33655,33664,33667-33670,33673-33674,33678,33682,33686-33691,33693,33696,33698,33700,33703,33708,33710,33712-33714,33716,33719,33721-33723,33725-33727,33729-33730,33733,33736,33742,33754,33756,33758,33761,33763,33766,33777,33781-33788,33790,33792-33793,33795,33797,33805,33807-33812,33815-33817,33819,33822,33826,33829,33837,33839,33844,33847,33858-33861,33864,33871-33873,33875,33877-33879,33886,33889-33892,33894,33896,33900,33902-33903,33919,33928,33930,33932-33936,33938-33940,33942-33943,33948,33950,33953,33967,33973,33976,33978,33980,33985,33991,33993,33999-34000,34006,34009,34011,34013,34015,34019,34021-34023,34025,34027-34028,34030,34032-34034,34036,34038-34039,34041,34046-34048,34050-34055,34057,34059-34065,34067,34072,34074,34076,34078-34081,34084,34086-34087,34089-34090,34093,34096-34102,34104,34107,34113,34116,34119,34122,34124,34126,34128,34131-34132,34135,34138,34141,34144,34146,34149,34152-34154,34156-34157,34160,34163-34164,34169,34173,34179-34194,34196-34198,34200-34201,34205-34206,34208-34217,34219-34225,34227-34228,34234-34237,34239-34249,34251-34279,34281-34284,34286-34288,34290-34320,34323-34324,34326,34328-34329,34332,34334,34336,34338-34340,34343-34353,34356-34357,34359-34371,34373,34375,34378,34381-34382,34384-34385,34389-34391,34393-34394,34396-34397,34399-34405,34407-34409,34411,34413,34415,34417-34420,34423-34426,34428-34438,34440-34454,34456-34458,34460,34462-34469,34472,34474,34479-34481,34483-34498,34501-34505,34508,34511-34518,34520-34524,34526-34563,34566-34569,34571-34590,34592,34595-34599,34602-34603,34605,34613-34615,34617,34619-34624,34627-34628,34630-34639,34642-34649 via svnmerge from
https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk
svn-id: r34654
2008-09-26 21:53:08 +00:00
|
|
|
#include "common/unzip.h"
|
2008-07-03 22:38:19 +00:00
|
|
|
|
2008-08-15 17:53:18 +00:00
|
|
|
#define KEY_START_CHAR ('[')
|
|
|
|
#define KEY_END_CHAR (']')
|
|
|
|
|
2008-07-07 15:42:26 +00:00
|
|
|
namespace Common {
|
2008-07-03 22:38:19 +00:00
|
|
|
|
2008-07-31 10:54:13 +00:00
|
|
|
VirtualKeyboard::VirtualKeyboard() : _currentMode(0) {
|
2008-07-03 22:38:19 +00:00
|
|
|
assert(g_system);
|
|
|
|
_system = g_system;
|
|
|
|
|
|
|
|
_parser = new VirtualKeyboardParser(this);
|
2008-07-30 13:47:54 +00:00
|
|
|
_kbdGUI = new VirtualKeyboardGUI(this);
|
2008-08-15 01:21:29 +00:00
|
|
|
_submitKeys = _loaded = false;
|
2009-01-20 18:31:35 +00:00
|
|
|
_fileArchive = 0;
|
2008-07-03 22:38:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VirtualKeyboard::~VirtualKeyboard() {
|
2008-07-30 13:47:54 +00:00
|
|
|
deleteEvents();
|
|
|
|
delete _kbdGUI;
|
2008-07-04 17:55:19 +00:00
|
|
|
delete _parser;
|
2009-01-20 18:31:35 +00:00
|
|
|
delete _fileArchive;
|
2008-07-04 17:55:19 +00:00
|
|
|
}
|
|
|
|
|
2008-07-30 13:47:54 +00:00
|
|
|
void VirtualKeyboard::deleteEvents() {
|
2012-01-03 00:56:43 +00:00
|
|
|
for (ModeMap::iterator it_m = _modes.begin(); it_m != _modes.end(); ++it_m) {
|
|
|
|
VKEventMap &evt = it_m->_value.events;
|
|
|
|
for (VKEventMap::iterator it_e = evt.begin(); it_e != evt.end(); ++it_e)
|
2008-07-30 13:47:54 +00:00
|
|
|
delete it_e->_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-04 17:55:19 +00:00
|
|
|
void VirtualKeyboard::reset() {
|
2008-07-30 13:47:54 +00:00
|
|
|
deleteEvents();
|
2008-07-04 17:55:19 +00:00
|
|
|
_modes.clear();
|
|
|
|
_initialMode = _currentMode = 0;
|
2011-04-14 12:34:28 +00:00
|
|
|
_hAlignment = kAlignCenter;
|
2008-07-04 17:55:19 +00:00
|
|
|
_vAlignment = kAlignBottom;
|
|
|
|
_keyQueue.clear();
|
2008-07-30 13:47:54 +00:00
|
|
|
_loaded = false;
|
|
|
|
_kbdGUI->reset();
|
2008-07-03 22:38:19 +00:00
|
|
|
}
|
|
|
|
|
2009-06-20 11:48:42 +00:00
|
|
|
bool VirtualKeyboard::openPack(const String &packName, const FSNode &node) {
|
|
|
|
if (node.getChild(packName + ".xml").exists()) {
|
|
|
|
_fileArchive = new FSDirectory(node, 1);
|
2009-01-20 18:31:35 +00:00
|
|
|
|
2008-07-03 22:38:19 +00:00
|
|
|
// uncompressed keyboard pack
|
2009-06-20 11:48:42 +00:00
|
|
|
if (!_parser->loadFile(node.getChild(packName + ".xml"))) {
|
|
|
|
delete _fileArchive;
|
|
|
|
_fileArchive = 0;
|
2008-07-03 22:38:19 +00:00
|
|
|
return false;
|
2009-06-20 11:48:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2009-06-20 11:48:42 +00:00
|
|
|
if (node.getChild(packName + ".zip").exists()) {
|
|
|
|
// compressed keyboard pack
|
2010-02-13 11:56:30 +00:00
|
|
|
_fileArchive = makeZipArchive(node.getChild(packName + ".zip"));
|
|
|
|
if (_fileArchive && _fileArchive->hasFile(packName + ".xml")) {
|
2009-06-20 11:48:42 +00:00
|
|
|
if (!_parser->loadStream(_fileArchive->createReadStreamForMember(packName + ".xml"))) {
|
|
|
|
delete _fileArchive;
|
|
|
|
_fileArchive = 0;
|
2008-07-03 22:38:19 +00:00
|
|
|
return false;
|
2009-06-20 11:48:42 +00:00
|
|
|
}
|
2008-07-03 22:38:19 +00:00
|
|
|
} else {
|
2014-04-16 13:48:21 +00:00
|
|
|
warning("Could not find %s.xml file in %s.zip virtual keyboard pack", packName.c_str(), packName.c_str());
|
2009-06-20 11:48:42 +00:00
|
|
|
delete _fileArchive;
|
|
|
|
_fileArchive = 0;
|
2008-07-03 22:38:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-06-20 11:48:42 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VirtualKeyboard::loadKeyboardPack(const String &packName) {
|
|
|
|
_kbdGUI->initSize(_system->getOverlayWidth(), _system->getOverlayHeight());
|
|
|
|
|
|
|
|
delete _fileArchive;
|
|
|
|
_fileArchive = 0;
|
|
|
|
_loaded = false;
|
|
|
|
|
|
|
|
bool opened = false;
|
|
|
|
if (ConfMan.hasKey("vkeybdpath"))
|
|
|
|
opened = openPack(packName, FSNode(ConfMan.get("vkeybdpath")));
|
|
|
|
else if (ConfMan.hasKey("extrapath"))
|
|
|
|
opened = openPack(packName, FSNode(ConfMan.get("extrapath")));
|
|
|
|
|
|
|
|
// fallback to the current dir
|
|
|
|
if (!opened)
|
|
|
|
opened = openPack(packName, FSNode("."));
|
|
|
|
|
|
|
|
if (opened) {
|
|
|
|
_parser->setParseMode(VirtualKeyboardParser::kParseFull);
|
|
|
|
_loaded = _parser->parse();
|
|
|
|
|
|
|
|
if (_loaded) {
|
2014-04-16 13:48:21 +00:00
|
|
|
debug("Virtual keyboard pack '%s' loaded successfully", packName.c_str());
|
2009-06-20 11:48:42 +00:00
|
|
|
} else {
|
2014-04-16 13:48:21 +00:00
|
|
|
warning("Error parsing the virtual keyboard pack '%s'", packName.c_str());
|
2009-06-20 11:48:42 +00:00
|
|
|
|
|
|
|
delete _fileArchive;
|
|
|
|
_fileArchive = 0;
|
|
|
|
}
|
2008-07-03 22:38:19 +00:00
|
|
|
} else {
|
2014-04-16 13:48:21 +00:00
|
|
|
warning("Virtual keyboard disabled due to missing pack file");
|
2008-07-03 22:38:19 +00:00
|
|
|
}
|
|
|
|
|
2008-07-07 21:10:58 +00:00
|
|
|
return _loaded;
|
2008-07-03 22:38:19 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 17:38:48 +00:00
|
|
|
bool VirtualKeyboard::checkModeResolutions() {
|
2008-08-29 21:10:10 +00:00
|
|
|
_parser->setParseMode(VirtualKeyboardParser::kParseCheckResolutions);
|
2008-07-09 11:30:49 +00:00
|
|
|
_loaded = _parser->parse();
|
2009-01-20 17:38:48 +00:00
|
|
|
if (_currentMode)
|
|
|
|
_kbdGUI->initMode(_currentMode);
|
2008-07-09 11:30:49 +00:00
|
|
|
return _loaded;
|
2008-07-08 15:03:39 +00:00
|
|
|
}
|
|
|
|
|
2008-08-29 21:10:10 +00:00
|
|
|
String VirtualKeyboard::findArea(int16 x, int16 y) {
|
2008-07-08 15:03:39 +00:00
|
|
|
return _currentMode->imageMap.findMapArea(x, y);
|
|
|
|
}
|
|
|
|
|
2012-01-03 00:25:16 +00:00
|
|
|
void VirtualKeyboard::processAreaClick(const String &area) {
|
2009-01-20 17:38:48 +00:00
|
|
|
if (!_currentMode->events.contains(area))
|
|
|
|
return;
|
|
|
|
|
2008-08-29 21:10:10 +00:00
|
|
|
VKEvent *evt = _currentMode->events[area];
|
2008-07-08 15:03:39 +00:00
|
|
|
|
2008-07-30 13:47:54 +00:00
|
|
|
switch (evt->type) {
|
2009-01-20 17:38:48 +00:00
|
|
|
case kVKEventKey:
|
2008-07-04 17:55:19 +00:00
|
|
|
// add virtual keypress to queue
|
2012-01-03 00:25:16 +00:00
|
|
|
_keyQueue.insertKey(*(KeyState *)evt->data);
|
2008-07-26 20:35:46 +00:00
|
|
|
break;
|
2008-08-29 21:10:10 +00:00
|
|
|
case kVKEventModifier:
|
2012-01-03 00:25:16 +00:00
|
|
|
_keyQueue.toggleFlags(*(byte *)(evt->data));
|
2008-07-04 17:55:19 +00:00
|
|
|
break;
|
2008-08-29 21:10:10 +00:00
|
|
|
case kVKEventSwitchMode:
|
2008-07-04 17:55:19 +00:00
|
|
|
// switch to new mode
|
2008-08-15 01:21:29 +00:00
|
|
|
switchMode((char *)evt->data);
|
2008-07-31 10:54:13 +00:00
|
|
|
_keyQueue.clearFlags();
|
2008-07-04 17:55:19 +00:00
|
|
|
break;
|
2008-08-29 21:10:10 +00:00
|
|
|
case kVKEventSubmit:
|
2008-08-15 01:21:29 +00:00
|
|
|
close(true);
|
|
|
|
break;
|
2008-08-29 21:10:10 +00:00
|
|
|
case kVKEventCancel:
|
2008-08-15 01:21:29 +00:00
|
|
|
close(false);
|
|
|
|
break;
|
2008-08-29 21:10:10 +00:00
|
|
|
case kVKEventClear:
|
2008-08-15 19:41:34 +00:00
|
|
|
_keyQueue.clear();
|
|
|
|
break;
|
2008-08-29 21:10:10 +00:00
|
|
|
case kVKEventDelete:
|
2008-08-15 01:21:29 +00:00
|
|
|
_keyQueue.deleteKey();
|
|
|
|
break;
|
2008-08-29 21:10:10 +00:00
|
|
|
case kVKEventMoveLeft:
|
2008-08-15 01:21:29 +00:00
|
|
|
_keyQueue.moveLeft();
|
|
|
|
break;
|
2008-08-29 21:10:10 +00:00
|
|
|
case kVKEventMoveRight:
|
2008-08-15 01:21:29 +00:00
|
|
|
_keyQueue.moveRight();
|
2008-07-04 17:55:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-07-03 22:38:19 +00:00
|
|
|
|
2008-07-07 14:30:11 +00:00
|
|
|
void VirtualKeyboard::switchMode(Mode *newMode) {
|
2008-07-31 17:26:03 +00:00
|
|
|
_kbdGUI->initMode(newMode);
|
2008-07-07 14:30:11 +00:00
|
|
|
_currentMode = newMode;
|
|
|
|
}
|
|
|
|
|
2010-01-25 02:08:28 +00:00
|
|
|
void VirtualKeyboard::switchMode(const String &newMode) {
|
2008-07-07 14:30:11 +00:00
|
|
|
if (!_modes.contains(newMode)) {
|
2014-04-16 13:48:21 +00:00
|
|
|
warning("Virtual keyboard mode '%s' unknown", newMode.c_str());
|
2009-01-20 17:38:48 +00:00
|
|
|
} else {
|
|
|
|
switchMode(&_modes[newMode]);
|
2008-07-07 14:30:11 +00:00
|
|
|
}
|
2008-07-04 17:55:19 +00:00
|
|
|
}
|
|
|
|
|
2008-07-30 13:47:54 +00:00
|
|
|
void VirtualKeyboard::handleMouseDown(int16 x, int16 y) {
|
|
|
|
_areaDown = findArea(x, y);
|
|
|
|
if (_areaDown.empty())
|
|
|
|
_kbdGUI->startDrag(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualKeyboard::handleMouseUp(int16 x, int16 y) {
|
|
|
|
if (!_areaDown.empty() && _areaDown == findArea(x, y)) {
|
|
|
|
processAreaClick(_areaDown);
|
|
|
|
_areaDown.clear();
|
|
|
|
}
|
|
|
|
_kbdGUI->endDrag();
|
|
|
|
}
|
|
|
|
|
2008-07-04 17:55:19 +00:00
|
|
|
void VirtualKeyboard::show() {
|
2008-07-09 11:30:49 +00:00
|
|
|
if (!_loaded) {
|
2014-04-16 13:48:21 +00:00
|
|
|
debug(1, "VirtualKeyboard::show() - Virtual keyboard not loaded");
|
2008-08-17 12:11:34 +00:00
|
|
|
return;
|
2009-01-20 17:38:48 +00:00
|
|
|
} else {
|
|
|
|
_kbdGUI->checkScreenChanged();
|
2008-07-09 11:30:49 +00:00
|
|
|
}
|
2008-07-03 22:38:19 +00:00
|
|
|
|
2008-08-17 12:11:34 +00:00
|
|
|
switchMode(_initialMode);
|
2008-07-30 13:47:54 +00:00
|
|
|
_kbdGUI->run();
|
2008-07-09 13:33:36 +00:00
|
|
|
|
2008-08-15 01:21:29 +00:00
|
|
|
if (_submitKeys) {
|
|
|
|
EventManager *eventMan = _system->getEventManager();
|
|
|
|
assert(eventMan);
|
|
|
|
|
|
|
|
// push keydown & keyup events into the event manager
|
2008-08-29 21:10:10 +00:00
|
|
|
Event evt;
|
2008-08-15 01:21:29 +00:00
|
|
|
evt.synthetic = false;
|
|
|
|
while (!_keyQueue.empty()) {
|
|
|
|
evt.kbd = _keyQueue.pop();
|
2008-08-29 21:10:10 +00:00
|
|
|
evt.type = EVENT_KEYDOWN;
|
2008-08-15 01:21:29 +00:00
|
|
|
eventMan->pushEvent(evt);
|
2008-08-29 21:10:10 +00:00
|
|
|
evt.type = EVENT_KEYUP;
|
2008-08-15 01:21:29 +00:00
|
|
|
eventMan->pushEvent(evt);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_keyQueue.clear();
|
2008-07-09 13:33:36 +00:00
|
|
|
}
|
2008-07-03 22:38:19 +00:00
|
|
|
}
|
|
|
|
|
2008-08-15 01:21:29 +00:00
|
|
|
void VirtualKeyboard::close(bool submit) {
|
|
|
|
_submitKeys = submit;
|
|
|
|
_kbdGUI->close();
|
2008-07-11 20:10:14 +00:00
|
|
|
}
|
|
|
|
|
2009-05-24 15:17:42 +00:00
|
|
|
bool VirtualKeyboard::isDisplaying() {
|
2008-07-30 13:47:54 +00:00
|
|
|
return _kbdGUI->isDisplaying();
|
2008-07-11 20:10:14 +00:00
|
|
|
}
|
|
|
|
|
2008-07-30 13:47:54 +00:00
|
|
|
VirtualKeyboard::KeyPressQueue::KeyPressQueue() {
|
|
|
|
_keyPos = _keys.end();
|
2008-07-26 20:35:46 +00:00
|
|
|
_strPos = 0;
|
2008-08-14 19:20:25 +00:00
|
|
|
_strChanged = false;
|
2008-08-15 17:53:18 +00:00
|
|
|
_flags = 0;
|
2008-07-26 20:35:46 +00:00
|
|
|
}
|
|
|
|
|
2008-07-31 10:54:13 +00:00
|
|
|
void VirtualKeyboard::KeyPressQueue::toggleFlags(byte fl) {
|
2008-08-15 17:53:18 +00:00
|
|
|
_flags ^= fl;
|
|
|
|
_flagsStr.clear();
|
|
|
|
if (_flags) {
|
|
|
|
_flagsStr = KEY_START_CHAR;
|
|
|
|
if (_flags & KBD_CTRL)
|
|
|
|
_flagsStr += "Ctrl+";
|
|
|
|
if (_flags & KBD_ALT)
|
|
|
|
_flagsStr += "Alt+";
|
|
|
|
if (_flags & KBD_SHIFT)
|
|
|
|
_flagsStr += "Shift+";
|
|
|
|
}
|
2008-07-31 10:54:13 +00:00
|
|
|
_strChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualKeyboard::KeyPressQueue::clearFlags() {
|
2008-08-15 17:53:18 +00:00
|
|
|
_flags = 0;
|
|
|
|
_flagsStr.clear();
|
2008-07-31 10:54:13 +00:00
|
|
|
_strChanged = true;
|
|
|
|
}
|
|
|
|
|
2008-07-30 13:47:54 +00:00
|
|
|
void VirtualKeyboard::KeyPressQueue::insertKey(KeyState key) {
|
2008-07-31 10:54:13 +00:00
|
|
|
_strChanged = true;
|
2008-08-15 17:53:18 +00:00
|
|
|
key.flags ^= _flags;
|
2008-08-29 21:10:10 +00:00
|
|
|
if ((key.keycode >= KEYCODE_a) && (key.keycode <= KEYCODE_z))
|
|
|
|
key.ascii = (key.flags & KBD_SHIFT) ? key.keycode - 32 : key.keycode;
|
2008-07-31 10:54:13 +00:00
|
|
|
clearFlags();
|
|
|
|
|
2008-07-26 20:35:46 +00:00
|
|
|
String keyStr;
|
2008-08-15 17:53:18 +00:00
|
|
|
if (key.flags & KBD_CTRL) keyStr += "Ctrl+";
|
|
|
|
if (key.flags & KBD_ALT) keyStr += "Alt+";
|
|
|
|
|
|
|
|
if (key.ascii >= 32 && key.ascii <= 255) {
|
2008-07-26 20:35:46 +00:00
|
|
|
if (key.flags & KBD_SHIFT && (key.ascii < 65 || key.ascii > 90))
|
|
|
|
keyStr += "Shift+";
|
|
|
|
keyStr += (char)key.ascii;
|
2008-08-15 17:53:18 +00:00
|
|
|
} else {
|
|
|
|
if (key.flags & KBD_SHIFT) keyStr += "Shift+";
|
|
|
|
if (key.keycode >= 0 && key.keycode < keycodeDescTableSize)
|
|
|
|
keyStr += keycodeDescTable[key.keycode];
|
2008-07-26 20:35:46 +00:00
|
|
|
}
|
|
|
|
|
2008-08-15 17:53:18 +00:00
|
|
|
if (keyStr.empty()) keyStr += "???";
|
|
|
|
|
|
|
|
_keysStr.insertChar(KEY_START_CHAR, _strPos++);
|
2008-07-26 20:35:46 +00:00
|
|
|
const char *k = keyStr.c_str();
|
|
|
|
while (char ch = *k++)
|
2008-08-15 17:53:18 +00:00
|
|
|
_keysStr.insertChar(ch, _strPos++);
|
|
|
|
_keysStr.insertChar(KEY_END_CHAR, _strPos++);
|
2008-07-26 20:35:46 +00:00
|
|
|
|
|
|
|
VirtualKeyPress kp;
|
|
|
|
kp.key = key;
|
2008-08-15 17:53:18 +00:00
|
|
|
kp.strLen = keyStr.size() + 2;
|
2008-07-26 20:35:46 +00:00
|
|
|
_keys.insert(_keyPos, kp);
|
|
|
|
}
|
|
|
|
|
2008-07-30 13:47:54 +00:00
|
|
|
void VirtualKeyboard::KeyPressQueue::deleteKey() {
|
2008-07-26 20:35:46 +00:00
|
|
|
if (_keyPos == _keys.begin())
|
|
|
|
return;
|
2012-01-03 00:56:43 +00:00
|
|
|
KeyPressList::iterator it = _keyPos;
|
2008-07-26 20:35:46 +00:00
|
|
|
it--;
|
|
|
|
_strPos -= it->strLen;
|
2009-09-30 16:16:53 +00:00
|
|
|
while ((it->strLen)-- > 0)
|
2008-08-15 17:53:18 +00:00
|
|
|
_keysStr.deleteChar(_strPos);
|
2008-07-26 20:35:46 +00:00
|
|
|
_keys.erase(it);
|
2008-08-15 21:00:54 +00:00
|
|
|
_strChanged = true;
|
2008-07-26 20:35:46 +00:00
|
|
|
}
|
|
|
|
|
2008-07-30 13:47:54 +00:00
|
|
|
void VirtualKeyboard::KeyPressQueue::moveLeft() {
|
2008-07-26 20:35:46 +00:00
|
|
|
if (_keyPos == _keys.begin())
|
|
|
|
return;
|
|
|
|
_keyPos--;
|
|
|
|
_strPos -= _keyPos->strLen;
|
2008-08-15 21:00:54 +00:00
|
|
|
_strChanged = true;
|
2008-07-26 20:35:46 +00:00
|
|
|
}
|
|
|
|
|
2008-07-30 13:47:54 +00:00
|
|
|
void VirtualKeyboard::KeyPressQueue::moveRight() {
|
|
|
|
if (_keyPos == _keys.end())
|
2008-07-26 20:35:46 +00:00
|
|
|
return;
|
|
|
|
_strPos += _keyPos->strLen;
|
2008-07-30 13:47:54 +00:00
|
|
|
_keyPos++;
|
2008-08-15 21:00:54 +00:00
|
|
|
_strChanged = true;
|
2008-07-26 20:35:46 +00:00
|
|
|
}
|
|
|
|
|
2008-07-30 13:47:54 +00:00
|
|
|
KeyState VirtualKeyboard::KeyPressQueue::pop() {
|
|
|
|
bool front = (_keyPos == _keys.begin());
|
|
|
|
VirtualKeyPress kp = *(_keys.begin());
|
2008-07-26 20:35:46 +00:00
|
|
|
_keys.pop_front();
|
2008-07-30 13:47:54 +00:00
|
|
|
|
|
|
|
if (front)
|
|
|
|
_keyPos = _keys.begin();
|
|
|
|
else
|
|
|
|
_strPos -= kp.strLen;
|
|
|
|
|
|
|
|
while (kp.strLen-- > 0)
|
2008-08-15 17:53:18 +00:00
|
|
|
_keysStr.deleteChar(0);
|
2008-07-30 13:47:54 +00:00
|
|
|
|
|
|
|
return kp.key;
|
2008-07-26 20:35:46 +00:00
|
|
|
}
|
|
|
|
|
2008-07-30 13:47:54 +00:00
|
|
|
void VirtualKeyboard::KeyPressQueue::clear() {
|
2008-07-26 20:35:46 +00:00
|
|
|
_keys.clear();
|
2008-07-30 13:47:54 +00:00
|
|
|
_keyPos = _keys.end();
|
2008-08-15 17:53:18 +00:00
|
|
|
_keysStr.clear();
|
2008-07-26 20:35:46 +00:00
|
|
|
_strPos = 0;
|
2008-08-22 10:47:36 +00:00
|
|
|
clearFlags();
|
2008-08-15 19:41:34 +00:00
|
|
|
_strChanged = true;
|
2008-07-26 20:35:46 +00:00
|
|
|
}
|
|
|
|
|
2009-05-24 15:17:42 +00:00
|
|
|
bool VirtualKeyboard::KeyPressQueue::empty() {
|
2008-07-26 20:35:46 +00:00
|
|
|
return _keys.empty();
|
|
|
|
}
|
|
|
|
|
2009-01-20 17:38:48 +00:00
|
|
|
String VirtualKeyboard::KeyPressQueue::getString() {
|
2008-08-15 17:53:18 +00:00
|
|
|
if (_keysStr.empty())
|
|
|
|
return _flagsStr;
|
|
|
|
if (_flagsStr.empty())
|
|
|
|
return _keysStr;
|
|
|
|
if (_strPos == _keysStr.size())
|
|
|
|
return _keysStr + _flagsStr;
|
|
|
|
|
|
|
|
uint len = _keysStr.size() + _flagsStr.size();
|
|
|
|
char *str = new char[len];
|
|
|
|
memcpy(str, _keysStr.c_str(), _strPos);
|
|
|
|
memcpy(str + _strPos, _flagsStr.c_str(), _flagsStr.size());
|
|
|
|
memcpy(str + _strPos + _flagsStr.size(), _keysStr.c_str() + _strPos, _keysStr.size() - _strPos);
|
|
|
|
String ret(str, len);
|
|
|
|
delete[] str;
|
|
|
|
return ret;
|
2008-07-31 10:54:13 +00:00
|
|
|
}
|
|
|
|
|
2008-07-31 17:26:03 +00:00
|
|
|
uint VirtualKeyboard::KeyPressQueue::getInsertIndex() {
|
2008-08-15 17:53:18 +00:00
|
|
|
return _strPos + _flagsStr.size();
|
2008-07-31 17:26:03 +00:00
|
|
|
}
|
|
|
|
|
2008-07-31 10:54:13 +00:00
|
|
|
bool VirtualKeyboard::KeyPressQueue::hasStringChanged() {
|
|
|
|
bool ret = _strChanged;
|
|
|
|
_strChanged = false;
|
|
|
|
return ret;
|
2008-07-26 20:35:46 +00:00
|
|
|
}
|
|
|
|
|
2009-10-04 21:26:33 +00:00
|
|
|
} // End of namespace Common
|
2008-09-30 13:51:01 +00:00
|
|
|
|
|
|
|
#endif // #ifdef ENABLE_VKEYBD
|