2012-02-22 15:15:02 +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.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2012-02-22 15:15:02 +00:00
|
|
|
* 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.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2012-02-22 15:15:02 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gui/predictivedialog.h"
|
|
|
|
#include "gui/widget.h"
|
|
|
|
#include "gui/widgets/edittext.h"
|
|
|
|
#include "gui/gui-manager.h"
|
2016-01-24 02:06:47 +00:00
|
|
|
#include "gui/ThemeEval.h"
|
2012-02-22 15:15:02 +00:00
|
|
|
|
|
|
|
#include "common/config-manager.h"
|
|
|
|
#include "common/translation.h"
|
|
|
|
#include "common/events.h"
|
|
|
|
#include "common/debug.h"
|
|
|
|
#include "common/system.h"
|
|
|
|
#include "common/keyboard.h"
|
|
|
|
#include "common/file.h"
|
|
|
|
#include "common/savefile.h"
|
|
|
|
|
2017-11-14 23:01:32 +00:00
|
|
|
#if defined(__DS__) && defined(ENABLE_AGI)
|
2012-03-25 19:23:16 +00:00
|
|
|
#include "backends/platform/ds/arm9/source/wordcompletion.h"
|
|
|
|
#endif
|
|
|
|
|
2012-02-22 15:15:02 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kCancelCmd = 'CNCL',
|
|
|
|
kOkCmd = '__OK',
|
|
|
|
kBut1Cmd = 'BUT1',
|
|
|
|
kBut2Cmd = 'BUT2',
|
|
|
|
kBut3Cmd = 'BUT3',
|
|
|
|
kBut4Cmd = 'BUT4',
|
|
|
|
kBut5Cmd = 'BUT5',
|
|
|
|
kBut6Cmd = 'BUT6',
|
|
|
|
kBut7Cmd = 'BUT7',
|
|
|
|
kBut8Cmd = 'BUT8',
|
|
|
|
kBut9Cmd = 'BUT9',
|
|
|
|
kBut0Cmd = 'BUT0',
|
|
|
|
kNextCmd = 'NEXT',
|
|
|
|
kAddCmd = '_ADD',
|
|
|
|
kModeCmd = 'MODE',
|
|
|
|
kDelCmd = '_DEL',
|
|
|
|
kTestCmd = 'TEST'
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kModePre = 0,
|
|
|
|
kModeNum = 1,
|
|
|
|
kModeAbc = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
PredictiveDialog::PredictiveDialog() : Dialog("Predictive") {
|
2020-06-13 17:36:08 +00:00
|
|
|
new StaticTextWidget(this, "Predictive.Headline", Common::U32String("Enter Text"));
|
2012-02-22 15:15:02 +00:00
|
|
|
|
GUI: U32: Downscale changes of U32, fix review issues
This commit addresses a range of changes, within scummvm subproject.
- Audio files, like mididrv, remove U32String based name and identifier, because ASCII only.
- mididrv.cpp had some wrong format for warning messages, fix those
- Message dialogs were modified to use default arguments more often, but reverting back to the orignal to minimize changes.
- SetTooltip has a fake constructor that takes in a string, and use it.
- U32Format had some break statements missing, add those.
- RemapWidget: Use fake constructor for setLabel and setTooltip, to make minimal changes
- SDL: setting text in clipboard no longer uses SDL_iconv_string
- TTS: Override base class "say" with strings, so tts->say can be used with normal strings too.
- About dialog: fix incorrect code for u32string variables
- Fix some extra brackets
- Some buttons were incorrectly removed from using translated labels, revert those
- Message Dialog: Pass default and alt buttons as const references
- Saveload Dialog: Use translations in missing places, use const-references. Also, use translations in a correct manner.
- Use const references for tooltip in GraphicsWidget, EditTextWidget, error.cpp
- DomainEditTextWidget: Use U32String for text
2020-07-20 12:36:37 +00:00
|
|
|
_button[kCancelAct] = new ButtonWidget(this, "Predictive.Cancel", _("Cancel") , Common::U32String(""), kCancelCmd);
|
|
|
|
_button[kOkAct] = new ButtonWidget(this, "Predictive.OK", _("Ok") , Common::U32String(""), kOkCmd);
|
2020-05-30 14:50:46 +00:00
|
|
|
|
|
|
|
if (g_gui.useRTL()) {
|
2020-06-05 23:33:43 +00:00
|
|
|
/** If using RTL, swap the internal name of odd columns, to be flipped again when drawing.
|
2020-06-01 13:31:10 +00:00
|
|
|
We flip them back to orignal, because the keyboard layout stays the same in LTR & RTL.
|
|
|
|
The rest, like okButton, cancel, etc are all flipped.
|
2020-05-30 14:50:46 +00:00
|
|
|
*/
|
|
|
|
|
2020-06-13 17:36:08 +00:00
|
|
|
_button[kButton3Act] = new ButtonWidget(this, "Predictive.Button1", Common::U32String("3 def" ), Common::U32String(""), kBut3Cmd);
|
|
|
|
_button[kButton2Act] = new ButtonWidget(this, "Predictive.Button2", Common::U32String("2 abc" ), Common::U32String(""), kBut2Cmd);
|
|
|
|
_button[kButton1Act] = new ButtonWidget(this, "Predictive.Button3", Common::U32String("1 `-.&" ), Common::U32String(""), kBut1Cmd);
|
|
|
|
_button[kButton6Act] = new ButtonWidget(this, "Predictive.Button4", Common::U32String("6 mno" ), Common::U32String(""), kBut6Cmd);
|
|
|
|
_button[kButton5Act] = new ButtonWidget(this, "Predictive.Button5", Common::U32String("5 jkl" ), Common::U32String(""), kBut5Cmd);
|
|
|
|
_button[kButton4Act] = new ButtonWidget(this, "Predictive.Button6", Common::U32String("4 ghi" ), Common::U32String(""), kBut4Cmd);
|
|
|
|
_button[kButton9Act] = new ButtonWidget(this, "Predictive.Button7", Common::U32String("9 wxyz" ), Common::U32String(""), kBut9Cmd);
|
|
|
|
_button[kButton8Act] = new ButtonWidget(this, "Predictive.Button8", Common::U32String("8 tuv" ), Common::U32String(""), kBut8Cmd);
|
|
|
|
_button[kButton7Act] = new ButtonWidget(this, "Predictive.Button9", Common::U32String("7 pqrs" ), Common::U32String(""), kBut7Cmd);
|
|
|
|
_button[kButton0Act] = new ButtonWidget(this, "Predictive.Button0", Common::U32String("0" ), Common::U32String(""), kBut0Cmd);
|
2020-05-30 14:50:46 +00:00
|
|
|
} else {
|
2020-06-13 17:36:08 +00:00
|
|
|
_button[kButton1Act] = new ButtonWidget(this, "Predictive.Button1", Common::U32String("1 `-.&" ), Common::U32String(""), kBut1Cmd);
|
|
|
|
_button[kButton2Act] = new ButtonWidget(this, "Predictive.Button2", Common::U32String("2 abc" ), Common::U32String(""), kBut2Cmd);
|
|
|
|
_button[kButton3Act] = new ButtonWidget(this, "Predictive.Button3", Common::U32String("3 def" ), Common::U32String(""), kBut3Cmd);
|
|
|
|
_button[kButton4Act] = new ButtonWidget(this, "Predictive.Button4", Common::U32String("4 ghi" ), Common::U32String(""), kBut4Cmd);
|
|
|
|
_button[kButton5Act] = new ButtonWidget(this, "Predictive.Button5", Common::U32String("5 jkl" ), Common::U32String(""), kBut5Cmd);
|
|
|
|
_button[kButton6Act] = new ButtonWidget(this, "Predictive.Button6", Common::U32String("6 mno" ), Common::U32String(""), kBut6Cmd);
|
|
|
|
_button[kButton7Act] = new ButtonWidget(this, "Predictive.Button7", Common::U32String("7 pqrs" ), Common::U32String(""), kBut7Cmd);
|
|
|
|
_button[kButton8Act] = new ButtonWidget(this, "Predictive.Button8", Common::U32String("8 tuv" ), Common::U32String(""), kBut8Cmd);
|
|
|
|
_button[kButton9Act] = new ButtonWidget(this, "Predictive.Button9", Common::U32String("9 wxyz" ), Common::U32String(""), kBut9Cmd);
|
|
|
|
_button[kButton0Act] = new ButtonWidget(this, "Predictive.Button0", Common::U32String("0" ), Common::U32String(""), kBut0Cmd);
|
2020-05-30 14:50:46 +00:00
|
|
|
}
|
|
|
|
|
2016-01-24 01:37:07 +00:00
|
|
|
// I18N: You must leave "#" as is, only word 'next' is translatable
|
GUI: U32: Downscale changes of U32, fix review issues
This commit addresses a range of changes, within scummvm subproject.
- Audio files, like mididrv, remove U32String based name and identifier, because ASCII only.
- mididrv.cpp had some wrong format for warning messages, fix those
- Message dialogs were modified to use default arguments more often, but reverting back to the orignal to minimize changes.
- SetTooltip has a fake constructor that takes in a string, and use it.
- U32Format had some break statements missing, add those.
- RemapWidget: Use fake constructor for setLabel and setTooltip, to make minimal changes
- SDL: setting text in clipboard no longer uses SDL_iconv_string
- TTS: Override base class "say" with strings, so tts->say can be used with normal strings too.
- About dialog: fix incorrect code for u32string variables
- Fix some extra brackets
- Some buttons were incorrectly removed from using translated labels, revert those
- Message Dialog: Pass default and alt buttons as const references
- Saveload Dialog: Use translations in missing places, use const-references. Also, use translations in a correct manner.
- Use const references for tooltip in GraphicsWidget, EditTextWidget, error.cpp
- DomainEditTextWidget: Use U32String for text
2020-07-20 12:36:37 +00:00
|
|
|
_button[kNextAct] = new ButtonWidget(this, "Predictive.Next", _("# next") , Common::U32String(""), kNextCmd);
|
|
|
|
_button[kAddAct] = new ButtonWidget(this, "Predictive.Add", _("add") , Common::U32String(""), kAddCmd);
|
2016-01-24 02:35:18 +00:00
|
|
|
_button[kAddAct]->setEnabled(false);
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2016-01-24 01:37:07 +00:00
|
|
|
#ifndef DISABLE_FANCY_THEMES
|
2016-01-24 02:06:47 +00:00
|
|
|
if (g_gui.xmlEval()->getVar("Globals.Predictive.ShowDeletePic") == 1 && g_gui.theme()->supportsImages()) {
|
2016-01-24 02:35:18 +00:00
|
|
|
_button[kDelAct] = new PicButtonWidget(this, "Predictive.Delete", _("Delete char"), kDelCmd);
|
|
|
|
((PicButtonWidget *)_button[kDelAct])->useThemeTransparency(true);
|
2016-01-24 02:41:29 +00:00
|
|
|
((PicButtonWidget *)_button[kDelAct])->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageDelButton));
|
2016-01-24 02:06:47 +00:00
|
|
|
} else
|
2016-01-24 01:37:07 +00:00
|
|
|
#endif
|
GUI: U32: Downscale changes of U32, fix review issues
This commit addresses a range of changes, within scummvm subproject.
- Audio files, like mididrv, remove U32String based name and identifier, because ASCII only.
- mididrv.cpp had some wrong format for warning messages, fix those
- Message dialogs were modified to use default arguments more often, but reverting back to the orignal to minimize changes.
- SetTooltip has a fake constructor that takes in a string, and use it.
- U32Format had some break statements missing, add those.
- RemapWidget: Use fake constructor for setLabel and setTooltip, to make minimal changes
- SDL: setting text in clipboard no longer uses SDL_iconv_string
- TTS: Override base class "say" with strings, so tts->say can be used with normal strings too.
- About dialog: fix incorrect code for u32string variables
- Fix some extra brackets
- Some buttons were incorrectly removed from using translated labels, revert those
- Message Dialog: Pass default and alt buttons as const references
- Saveload Dialog: Use translations in missing places, use const-references. Also, use translations in a correct manner.
- Use const references for tooltip in GraphicsWidget, EditTextWidget, error.cpp
- DomainEditTextWidget: Use U32String for text
2020-07-20 12:36:37 +00:00
|
|
|
_button[kDelAct] = new ButtonWidget(this, "Predictive.Delete" , _("<") , Common::U32String(""), kDelCmd);
|
2016-01-24 01:37:07 +00:00
|
|
|
// I18N: Pre means 'Predictive', leave '*' as is
|
2020-06-13 16:42:25 +00:00
|
|
|
_button[kModeAct] = new ButtonWidget(this, "Predictive.Pre", _("* Pre"), Common::U32String(""), kModeCmd);
|
|
|
|
_editText = new EditTextWidget(this, "Predictive.Word", _search, Common::U32String(""), 0, 0);
|
2012-02-22 15:15:02 +00:00
|
|
|
|
|
|
|
_userDictHasChanged = false;
|
|
|
|
|
|
|
|
_predictiveDict.nameDict = "predictive_dictionary";
|
2016-01-24 02:14:09 +00:00
|
|
|
_predictiveDict.defaultFilename = "pred.dic";
|
2012-02-22 15:15:02 +00:00
|
|
|
|
|
|
|
_userDict.nameDict = "user_dictionary";
|
2016-01-24 02:14:09 +00:00
|
|
|
_userDict.defaultFilename = "user.dic";
|
2012-03-28 23:48:37 +00:00
|
|
|
|
2012-02-22 15:15:02 +00:00
|
|
|
if (!_predictiveDict.dictText) {
|
|
|
|
loadAllDictionary(_predictiveDict);
|
|
|
|
if (!_predictiveDict.dictText)
|
2016-01-24 02:10:13 +00:00
|
|
|
debug(5, "Predictive Dialog: pred.dic not loaded");
|
2012-02-22 15:15:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!_userDict.dictText) {
|
|
|
|
loadAllDictionary(_userDict);
|
|
|
|
if (!_userDict.dictText)
|
2016-01-24 02:10:13 +00:00
|
|
|
debug(5, "Predictive Dialog: user.dic not loaded");
|
2012-02-22 15:15:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mergeDicts();
|
|
|
|
|
|
|
|
memset(_repeatcount, 0, sizeof(_repeatcount));
|
|
|
|
|
|
|
|
_prefix.clear();
|
|
|
|
_currentCode.clear();
|
|
|
|
_currentWord.clear();
|
|
|
|
_wordNumber = 0;
|
|
|
|
_numMatchingWords = 0;
|
2013-10-01 22:06:58 +00:00
|
|
|
memset(_predictiveResult, 0, sizeof(_predictiveResult));
|
2012-03-28 23:48:37 +00:00
|
|
|
|
2016-01-24 02:35:18 +00:00
|
|
|
_lastButton = kNoAct;
|
2012-02-22 15:15:02 +00:00
|
|
|
_mode = kModePre;
|
|
|
|
|
|
|
|
_lastTime = 0;
|
|
|
|
_curTime = 0;
|
2016-01-24 02:35:18 +00:00
|
|
|
_lastPressedButton = kNoAct;
|
2012-02-22 15:15:02 +00:00
|
|
|
|
|
|
|
_memoryList[0] = _predictiveDict.dictText;
|
|
|
|
_memoryList[1] = _userDict.dictText;
|
|
|
|
_numMemory = 0;
|
|
|
|
|
2016-01-24 02:35:18 +00:00
|
|
|
_navigationWithKeys = false;
|
2016-06-01 09:18:17 +00:00
|
|
|
|
|
|
|
_curPressedButton = kNoAct;
|
|
|
|
_needRefresh = true;
|
2020-03-20 10:07:44 +00:00
|
|
|
_isPressed = false;
|
|
|
|
|
2012-02-22 15:15:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PredictiveDialog::~PredictiveDialog() {
|
|
|
|
for (int i = 0; i < _numMemory; i++) {
|
|
|
|
free(_memoryList[i]);
|
|
|
|
}
|
|
|
|
free(_userDict.dictLine);
|
|
|
|
free(_predictiveDict.dictLine);
|
|
|
|
free(_unitedDict.dictLine);
|
|
|
|
}
|
|
|
|
|
2016-01-24 02:06:47 +00:00
|
|
|
void PredictiveDialog::reflowLayout() {
|
|
|
|
#ifndef DISABLE_FANCY_THEMES
|
2016-01-24 02:35:18 +00:00
|
|
|
removeWidget(_button[kDelAct]);
|
2020-01-05 16:48:04 +00:00
|
|
|
_button[kDelAct]->setNext(nullptr);
|
2016-01-24 02:35:18 +00:00
|
|
|
delete _button[kDelAct];
|
|
|
|
_button[kDelAct] = nullptr;
|
2016-01-24 02:06:47 +00:00
|
|
|
|
|
|
|
if (g_gui.xmlEval()->getVar("Globals.Predictive.ShowDeletePic") == 1 && g_gui.theme()->supportsImages()) {
|
2016-01-24 02:35:18 +00:00
|
|
|
_button[kDelAct] = new PicButtonWidget(this, "Predictive.Delete", _("Delete char"), kDelCmd);
|
|
|
|
((PicButtonWidget *)_button[kDelAct])->useThemeTransparency(true);
|
2016-01-24 02:41:29 +00:00
|
|
|
((PicButtonWidget *)_button[kDelAct])->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageDelButton));
|
2016-01-24 02:06:47 +00:00
|
|
|
} else {
|
GUI: U32: Downscale changes of U32, fix review issues
This commit addresses a range of changes, within scummvm subproject.
- Audio files, like mididrv, remove U32String based name and identifier, because ASCII only.
- mididrv.cpp had some wrong format for warning messages, fix those
- Message dialogs were modified to use default arguments more often, but reverting back to the orignal to minimize changes.
- SetTooltip has a fake constructor that takes in a string, and use it.
- U32Format had some break statements missing, add those.
- RemapWidget: Use fake constructor for setLabel and setTooltip, to make minimal changes
- SDL: setting text in clipboard no longer uses SDL_iconv_string
- TTS: Override base class "say" with strings, so tts->say can be used with normal strings too.
- About dialog: fix incorrect code for u32string variables
- Fix some extra brackets
- Some buttons were incorrectly removed from using translated labels, revert those
- Message Dialog: Pass default and alt buttons as const references
- Saveload Dialog: Use translations in missing places, use const-references. Also, use translations in a correct manner.
- Use const references for tooltip in GraphicsWidget, EditTextWidget, error.cpp
- DomainEditTextWidget: Use U32String for text
2020-07-20 12:36:37 +00:00
|
|
|
_button[kDelAct] = new ButtonWidget(this, "Predictive.Delete" , _("<") , Common::U32String(""), kDelCmd);
|
2016-01-24 02:06:47 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Dialog::reflowLayout();
|
|
|
|
}
|
|
|
|
|
2012-02-22 15:15:02 +00:00
|
|
|
void PredictiveDialog::saveUserDictToFile() {
|
|
|
|
if (_userDictHasChanged) {
|
|
|
|
ConfMan.registerDefault("user_dictionary", "user.dic");
|
|
|
|
|
|
|
|
Common::OutSaveFile *file = g_system->getSavefileManager()->openForSaving(ConfMan.get("user_dictionary"));
|
|
|
|
|
|
|
|
for (int i = 0; i < _userDict.dictLineCount; i++) {
|
|
|
|
file->writeString(_userDict.dictLine[i]);
|
|
|
|
file->writeString("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
file->finalize();
|
|
|
|
delete file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-03 16:32:34 +00:00
|
|
|
void PredictiveDialog::handleKeyUp(Common::KeyState state) {
|
2016-01-24 02:35:18 +00:00
|
|
|
if (_curPressedButton != kNoAct && !_needRefresh) {
|
2016-04-13 12:02:33 +00:00
|
|
|
_button[_curPressedButton]->setUnpressedState();
|
2016-01-24 02:35:18 +00:00
|
|
|
processButton(_curPressedButton);
|
2012-05-03 16:32:34 +00:00
|
|
|
}
|
2020-03-20 10:07:44 +00:00
|
|
|
|
|
|
|
_isPressed = false;
|
2012-05-03 16:32:34 +00:00
|
|
|
}
|
|
|
|
|
2012-02-22 15:15:02 +00:00
|
|
|
void PredictiveDialog::handleKeyDown(Common::KeyState state) {
|
2020-03-20 10:07:44 +00:00
|
|
|
if (_isPressed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_isPressed = true;
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kNoAct;
|
2012-05-03 16:32:34 +00:00
|
|
|
_needRefresh = false;
|
2012-02-22 15:15:02 +00:00
|
|
|
|
2016-01-24 02:35:18 +00:00
|
|
|
if (getFocusWidget() == _editText) {
|
|
|
|
setFocusWidget(_button[kAddAct]);
|
2012-05-03 16:32:34 +00:00
|
|
|
}
|
|
|
|
|
2016-01-24 02:35:18 +00:00
|
|
|
if (_lastButton == kNoAct) {
|
|
|
|
_lastButton = kButton5Act;
|
2012-02-22 15:15:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (state.keycode) {
|
|
|
|
case Common::KEYCODE_ESCAPE:
|
|
|
|
saveUserDictToFile();
|
|
|
|
close();
|
|
|
|
return;
|
|
|
|
case Common::KEYCODE_LEFT:
|
2016-01-24 02:35:18 +00:00
|
|
|
_navigationWithKeys = true;
|
|
|
|
if (_lastButton == kButton1Act || _lastButton == kButton4Act || _lastButton == kButton7Act)
|
|
|
|
_curPressedButton = ButtonId(_lastButton + 2);
|
|
|
|
else if (_lastButton == kDelAct)
|
|
|
|
_curPressedButton = kButton1Act;
|
|
|
|
else if (_lastButton == kModeAct)
|
|
|
|
_curPressedButton = kNextAct;
|
|
|
|
else if (_lastButton == kNextAct)
|
|
|
|
_curPressedButton = kButton0Act;
|
|
|
|
else if (_lastButton == kAddAct)
|
|
|
|
_curPressedButton = kOkAct;
|
|
|
|
else if (_lastButton == kCancelAct)
|
|
|
|
_curPressedButton = kAddAct;
|
2012-02-22 15:15:02 +00:00
|
|
|
else
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = ButtonId(_lastButton - 1);
|
2012-05-03 16:32:34 +00:00
|
|
|
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2016-01-24 02:35:18 +00:00
|
|
|
if (_mode != kModeAbc && _lastButton == kCancelAct)
|
|
|
|
_curPressedButton = kOkAct;
|
2012-05-03 16:32:34 +00:00
|
|
|
|
|
|
|
_needRefresh = true;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case Common::KEYCODE_RIGHT:
|
2016-01-24 02:35:18 +00:00
|
|
|
_navigationWithKeys = true;
|
|
|
|
if (_lastButton == kButton3Act || _lastButton == kButton6Act || _lastButton == kButton9Act || _lastButton == kOkAct)
|
|
|
|
_curPressedButton = ButtonId(_lastButton - 2);
|
|
|
|
else if (_lastButton == kDelAct)
|
|
|
|
_curPressedButton = kButton3Act;
|
|
|
|
else if (_lastButton == kButton0Act)
|
|
|
|
_curPressedButton = kNextAct;
|
|
|
|
else if (_lastButton == kNextAct)
|
|
|
|
_curPressedButton = kModeAct;
|
|
|
|
else if (_lastButton == kAddAct)
|
|
|
|
_curPressedButton = kCancelAct;
|
|
|
|
else if (_lastButton == kOkAct)
|
|
|
|
_curPressedButton = kAddAct;
|
2012-02-22 15:15:02 +00:00
|
|
|
else
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = ButtonId(_lastButton + 1);
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2016-01-24 02:35:18 +00:00
|
|
|
if (_mode != kModeAbc && _lastButton == kOkAct)
|
|
|
|
_curPressedButton = kCancelAct;
|
2012-05-03 16:32:34 +00:00
|
|
|
_needRefresh = true;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case Common::KEYCODE_UP:
|
2016-01-24 02:35:18 +00:00
|
|
|
_navigationWithKeys = true;
|
|
|
|
if (_lastButton <= kButton3Act)
|
|
|
|
_curPressedButton = kDelAct;
|
|
|
|
else if (_lastButton == kDelAct)
|
|
|
|
_curPressedButton = kOkAct;
|
|
|
|
else if (_lastButton == kModeAct)
|
|
|
|
_curPressedButton = kButton7Act;
|
|
|
|
else if (_lastButton == kButton0Act)
|
|
|
|
_curPressedButton = kButton8Act;
|
|
|
|
else if (_lastButton == kNextAct)
|
|
|
|
_curPressedButton = kButton9Act;
|
|
|
|
else if (_lastButton == kAddAct)
|
|
|
|
_curPressedButton = kModeAct;
|
|
|
|
else if (_lastButton == kCancelAct)
|
|
|
|
_curPressedButton = kButton0Act;
|
|
|
|
else if (_lastButton == kOkAct)
|
|
|
|
_curPressedButton = kNextAct;
|
2012-02-22 15:15:02 +00:00
|
|
|
else
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = ButtonId(_lastButton - 3);
|
2012-05-03 16:32:34 +00:00
|
|
|
_needRefresh = true;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case Common::KEYCODE_DOWN:
|
2016-01-24 02:35:18 +00:00
|
|
|
_navigationWithKeys = true;
|
|
|
|
if (_lastButton == kDelAct)
|
|
|
|
_curPressedButton = kButton3Act;
|
|
|
|
else if (_lastButton == kButton7Act)
|
|
|
|
_curPressedButton = kModeAct;
|
|
|
|
else if (_lastButton == kButton8Act)
|
|
|
|
_curPressedButton = kButton0Act;
|
|
|
|
else if (_lastButton == kButton9Act)
|
|
|
|
_curPressedButton = kNextAct;
|
|
|
|
else if (_lastButton == kModeAct)
|
|
|
|
_curPressedButton = kAddAct;
|
|
|
|
else if (_lastButton == kButton0Act)
|
|
|
|
_curPressedButton = kCancelAct;
|
|
|
|
else if (_lastButton == kNextAct)
|
|
|
|
_curPressedButton = kOkAct;
|
|
|
|
else if (_lastButton == kAddAct || _lastButton == kCancelAct || _lastButton == kOkAct)
|
|
|
|
_curPressedButton = kDelAct;
|
2012-02-22 15:15:02 +00:00
|
|
|
else
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = ButtonId(_lastButton + 3);
|
2012-05-03 16:32:34 +00:00
|
|
|
|
2016-01-24 02:35:18 +00:00
|
|
|
if (_mode != kModeAbc && _lastButton == kModeAct)
|
|
|
|
_curPressedButton = kCancelAct;
|
2012-05-03 16:32:34 +00:00
|
|
|
|
|
|
|
_needRefresh = true;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case Common::KEYCODE_KP_ENTER:
|
2012-05-03 16:32:34 +00:00
|
|
|
case Common::KEYCODE_RETURN:
|
|
|
|
if (state.flags & Common::KBD_CTRL) {
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kOkAct;
|
2012-05-03 16:32:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-01-24 02:35:18 +00:00
|
|
|
if (_navigationWithKeys) {
|
2012-02-22 15:15:02 +00:00
|
|
|
// when the user has utilized arrow key navigation,
|
2016-01-24 02:35:18 +00:00
|
|
|
// interpret enter as 'click' on the _curPressedButton button
|
|
|
|
_curPressedButton = _lastButton;
|
2012-05-03 16:32:34 +00:00
|
|
|
_needRefresh = false;
|
2012-02-22 15:15:02 +00:00
|
|
|
} else {
|
|
|
|
// else it is a shortcut for 'Ok'
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kOkAct;
|
2012-02-22 15:15:02 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Common::KEYCODE_KP_PLUS:
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kAddAct;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case Common::KEYCODE_BACKSPACE:
|
|
|
|
case Common::KEYCODE_KP_MINUS:
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kDelAct;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case Common::KEYCODE_KP_DIVIDE:
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kNextAct;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case Common::KEYCODE_KP_MULTIPLY:
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kModeAct;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case Common::KEYCODE_KP0:
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kButton0Act;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case Common::KEYCODE_KP1:
|
|
|
|
case Common::KEYCODE_KP2:
|
|
|
|
case Common::KEYCODE_KP3:
|
|
|
|
case Common::KEYCODE_KP4:
|
|
|
|
case Common::KEYCODE_KP5:
|
|
|
|
case Common::KEYCODE_KP6:
|
|
|
|
case Common::KEYCODE_KP7:
|
|
|
|
case Common::KEYCODE_KP8:
|
|
|
|
case Common::KEYCODE_KP9:
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = ButtonId(state.keycode - Common::KEYCODE_KP1);
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Dialog::handleKeyDown(state);
|
|
|
|
}
|
|
|
|
|
2016-01-24 02:35:18 +00:00
|
|
|
if (_lastButton != _curPressedButton)
|
2016-04-13 12:02:33 +00:00
|
|
|
_button[_lastButton]->setUnpressedState();
|
2012-05-03 16:32:34 +00:00
|
|
|
|
2016-01-24 02:35:18 +00:00
|
|
|
if (_curPressedButton != kNoAct && !_needRefresh)
|
|
|
|
_button[_curPressedButton]->setPressedState();
|
2012-05-03 16:32:34 +00:00
|
|
|
else
|
2016-01-24 02:35:18 +00:00
|
|
|
updateHighLightedButton(_curPressedButton);
|
2012-05-03 16:32:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PredictiveDialog::updateHighLightedButton(ButtonId act) {
|
2016-01-24 02:35:18 +00:00
|
|
|
if (_curPressedButton != kNoAct) {
|
|
|
|
_button[_lastButton]->setHighLighted(false);
|
|
|
|
_lastButton = act;
|
|
|
|
_button[_lastButton]->setHighLighted(true);
|
2012-02-22 15:15:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-28 23:48:37 +00:00
|
|
|
void PredictiveDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kNoAct;
|
2012-02-22 15:15:02 +00:00
|
|
|
|
2016-01-24 02:35:18 +00:00
|
|
|
_navigationWithKeys = false;
|
2012-02-22 15:15:02 +00:00
|
|
|
|
2016-01-24 02:35:18 +00:00
|
|
|
if (_lastButton != kNoAct)
|
|
|
|
_button[_lastButton]->setHighLighted(false);
|
2012-05-03 16:32:34 +00:00
|
|
|
|
2012-02-22 15:15:02 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case kDelCmd:
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kDelAct;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case kNextCmd:
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kNextAct;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case kAddCmd:
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kAddAct;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case kModeCmd:
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kModeAct;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case kBut1Cmd:
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kButton1Act;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case kBut2Cmd:
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kButton2Act;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case kBut3Cmd:
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kButton3Act;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case kBut4Cmd:
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kButton4Act;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case kBut5Cmd:
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kButton5Act;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case kBut6Cmd:
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kButton6Act;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case kBut7Cmd:
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kButton7Act;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case kBut8Cmd:
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kButton8Act;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case kBut9Cmd:
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kButton9Act;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case kBut0Cmd:
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kButton0Act;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
case kCancelCmd:
|
|
|
|
saveUserDictToFile();
|
|
|
|
close();
|
2013-10-01 22:15:15 +00:00
|
|
|
// When we cancel the dialog no result should be returned. Thus, we
|
|
|
|
// will invalidate any result here.
|
|
|
|
_predictiveResult[0] = 0;
|
2012-02-22 15:15:02 +00:00
|
|
|
return;
|
|
|
|
case kOkCmd:
|
2016-01-24 02:35:18 +00:00
|
|
|
_curPressedButton = kOkAct;
|
2012-02-22 15:15:02 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Dialog::handleCommand(sender, cmd, data);
|
|
|
|
}
|
|
|
|
|
2016-01-24 02:35:18 +00:00
|
|
|
if (_curPressedButton != kNoAct) {
|
|
|
|
processButton(_curPressedButton);
|
2012-02-22 15:15:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-24 02:35:18 +00:00
|
|
|
void PredictiveDialog::processButton(ButtonId button) {
|
2012-03-29 00:00:25 +00:00
|
|
|
static const char *const buttonStr[] = {
|
2012-03-28 23:48:37 +00:00
|
|
|
"1", "2", "3",
|
|
|
|
"4", "5", "6",
|
|
|
|
"7", "8", "9",
|
|
|
|
"0"
|
|
|
|
};
|
|
|
|
|
2012-03-29 00:00:25 +00:00
|
|
|
static const char *const buttons[] = {
|
2012-03-28 23:48:37 +00:00
|
|
|
"'-.&", "abc", "def",
|
|
|
|
"ghi", "jkl", "mno",
|
|
|
|
"pqrs", "tuv", "wxyz",
|
|
|
|
"next", "add",
|
|
|
|
"<",
|
|
|
|
"Cancel", "OK",
|
2020-06-29 22:10:13 +00:00
|
|
|
"Pre", "(0) ", nullptr
|
2012-02-22 15:15:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (_mode == kModeAbc) {
|
2016-01-24 02:35:18 +00:00
|
|
|
if (button >= kButton1Act && button <= kButton9Act) {
|
2012-02-22 15:15:02 +00:00
|
|
|
if (!_lastTime)
|
|
|
|
_lastTime = g_system->getMillis();
|
2016-01-24 02:35:18 +00:00
|
|
|
if (_lastPressedButton == button) {
|
2012-02-22 15:15:02 +00:00
|
|
|
_curTime = g_system->getMillis();
|
2012-03-28 23:48:37 +00:00
|
|
|
if ((_curTime - _lastTime) < kRepeatDelay) {
|
2012-02-22 15:15:02 +00:00
|
|
|
button = kNextAct;
|
|
|
|
_lastTime = _curTime;
|
|
|
|
} else {
|
|
|
|
_lastTime = 0;
|
|
|
|
}
|
|
|
|
} else {
|
2016-01-24 02:35:18 +00:00
|
|
|
_lastPressedButton = button;
|
2012-02-22 15:15:02 +00:00
|
|
|
_lastTime = g_system->getMillis();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-24 02:35:18 +00:00
|
|
|
if (button >= kButton1Act) {
|
|
|
|
_lastButton = button;
|
|
|
|
if (button == kButton0Act && _mode != kModeNum) { // Space
|
2012-02-22 15:15:02 +00:00
|
|
|
// bring MRU word at the top of the list when changing words
|
|
|
|
if (_mode == kModePre && _unitedDict.dictActLine && _numMatchingWords > 1 && _wordNumber != 0)
|
|
|
|
bringWordtoTop(_unitedDict.dictActLine, _wordNumber);
|
|
|
|
|
|
|
|
strncpy(_temp, _currentWord.c_str(), _currentCode.size());
|
|
|
|
_temp[_currentCode.size()] = 0;
|
|
|
|
_prefix += _temp;
|
|
|
|
_prefix += " ";
|
|
|
|
_currentCode.clear();
|
|
|
|
_currentWord.clear();
|
|
|
|
_numMatchingWords = 0;
|
|
|
|
memset(_repeatcount, 0, sizeof(_repeatcount));
|
|
|
|
_lastTime = 0;
|
2016-01-24 02:35:18 +00:00
|
|
|
_lastPressedButton = kNoAct;
|
2012-02-22 15:15:02 +00:00
|
|
|
_curTime = 0;
|
2016-01-24 02:35:18 +00:00
|
|
|
} else if (button < kNextAct || button == kDelAct || button == kButton0Act) { // number or backspace
|
2012-02-22 15:15:02 +00:00
|
|
|
if (button == kDelAct) { // backspace
|
|
|
|
if (_currentCode.size()) {
|
|
|
|
_repeatcount[_currentCode.size() - 1] = 0;
|
|
|
|
_currentCode.deleteLastChar();
|
2012-03-29 00:07:02 +00:00
|
|
|
if (_currentCode.empty())
|
2012-02-22 15:15:02 +00:00
|
|
|
_currentWord.clear();
|
|
|
|
} else {
|
|
|
|
if (_prefix.size())
|
|
|
|
_prefix.deleteLastChar();
|
|
|
|
}
|
2012-03-25 22:29:19 +00:00
|
|
|
} else if (_prefix.size() + _currentCode.size() < kMaxWordLen - 1) { // don't overflow the dialog line
|
2016-01-24 02:35:18 +00:00
|
|
|
if (button == kButton0Act) { // zero
|
2012-02-22 15:15:02 +00:00
|
|
|
_currentCode += buttonStr[9];
|
|
|
|
} else {
|
|
|
|
_currentCode += buttonStr[button];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (_mode) {
|
|
|
|
case kModeNum:
|
|
|
|
_currentWord = _currentCode;
|
|
|
|
break;
|
|
|
|
case kModePre:
|
|
|
|
if (!matchWord() && _currentCode.size()) {
|
|
|
|
_currentCode.deleteLastChar();
|
|
|
|
matchWord();
|
|
|
|
}
|
|
|
|
_numMatchingWords = countWordsInString(_unitedDict.dictActLine);
|
|
|
|
break;
|
|
|
|
case kModeAbc:
|
2016-01-24 02:37:00 +00:00
|
|
|
for (uint x = 0; x < _currentCode.size(); x++)
|
2012-02-22 15:15:02 +00:00
|
|
|
if (_currentCode[x] >= '1')
|
|
|
|
_temp[x] = buttons[_currentCode[x] - '1'][_repeatcount[x]];
|
|
|
|
_temp[_currentCode.size()] = 0;
|
|
|
|
_currentWord = _temp;
|
2019-10-03 05:03:46 +00:00
|
|
|
default:
|
|
|
|
break;
|
2012-02-22 15:15:02 +00:00
|
|
|
}
|
|
|
|
} else if (button == kNextAct) { // next
|
|
|
|
if (_mode == kModePre) {
|
|
|
|
if (_unitedDict.dictActLine && _numMatchingWords > 1) {
|
|
|
|
_wordNumber = (_wordNumber + 1) % _numMatchingWords;
|
2012-03-25 22:29:19 +00:00
|
|
|
char tmp[kMaxLineLen];
|
|
|
|
strncpy(tmp, _unitedDict.dictActLine, kMaxLineLen);
|
|
|
|
tmp[kMaxLineLen - 1] = 0;
|
2012-02-22 15:15:02 +00:00
|
|
|
char *tok = strtok(tmp, " ");
|
|
|
|
for (uint8 i = 0; i <= _wordNumber; i++)
|
2020-01-05 16:48:04 +00:00
|
|
|
tok = strtok(nullptr, " ");
|
2012-03-28 23:48:37 +00:00
|
|
|
_currentWord = Common::String(tok, _currentCode.size());
|
|
|
|
}
|
|
|
|
} else if (_mode == kModeAbc) {
|
2016-01-24 02:37:00 +00:00
|
|
|
uint x = _currentCode.size();
|
2012-03-28 23:48:37 +00:00
|
|
|
if (x) {
|
|
|
|
if (_currentCode.lastChar() == '1' || _currentCode.lastChar() == '7' || _currentCode.lastChar() == '9')
|
|
|
|
_repeatcount[x - 1] = (_repeatcount[x - 1] + 1) % 4;
|
|
|
|
else
|
2012-02-22 15:15:02 +00:00
|
|
|
_repeatcount[x - 1] = (_repeatcount[x - 1] + 1) % 3;
|
|
|
|
|
2012-03-28 23:48:37 +00:00
|
|
|
if (_currentCode.lastChar() >= '1')
|
|
|
|
_currentWord.setChar(buttons[_currentCode[x - 1] - '1'][_repeatcount[x - 1]], x - 1);
|
2012-02-22 15:15:02 +00:00
|
|
|
}
|
2012-03-28 23:48:37 +00:00
|
|
|
}
|
2012-02-22 15:15:02 +00:00
|
|
|
} else if (button == kAddAct) { // add
|
|
|
|
if (_mode == kModeAbc)
|
|
|
|
addWordToDict();
|
|
|
|
else
|
2016-01-24 02:10:13 +00:00
|
|
|
debug(5, "Predictive Dialog: button Add doesn't work in this mode");
|
2012-02-22 15:15:02 +00:00
|
|
|
} else if (button == kOkAct) { // Ok
|
|
|
|
// bring MRU word at the top of the list when ok'ed out of the dialog
|
|
|
|
if (_mode == kModePre && _unitedDict.dictActLine && _numMatchingWords > 1 && _wordNumber != 0)
|
|
|
|
bringWordtoTop(_unitedDict.dictActLine, _wordNumber);
|
|
|
|
} else if (button == kModeAct) { // Mode
|
|
|
|
_mode++;
|
2016-01-24 02:35:18 +00:00
|
|
|
_button[kAddAct]->setEnabled(false);
|
2012-03-28 23:48:37 +00:00
|
|
|
if (_mode > kModeAbc) {
|
|
|
|
_mode = kModePre;
|
|
|
|
// I18N: Pre means 'Predictive', leave '*' as is
|
2020-07-01 18:01:48 +00:00
|
|
|
_button[kModeAct]->setLabel(_("* Pre"));
|
2012-03-28 23:48:37 +00:00
|
|
|
} else if (_mode == kModeNum) {
|
2012-03-29 00:23:44 +00:00
|
|
|
// I18N: 'Num' means Numbers
|
2020-07-01 18:01:48 +00:00
|
|
|
_button[kModeAct]->setLabel(_("* Num"));
|
2012-03-28 23:48:37 +00:00
|
|
|
} else {
|
2012-03-29 00:23:44 +00:00
|
|
|
// I18N: 'Abc' means Latin alphabet input
|
2020-07-01 18:01:48 +00:00
|
|
|
_button[kModeAct]->setLabel(_("* Abc"));
|
2016-01-24 02:35:18 +00:00
|
|
|
_button[kAddAct]->setEnabled(true);
|
2012-03-28 23:48:37 +00:00
|
|
|
}
|
2012-02-22 15:15:02 +00:00
|
|
|
|
|
|
|
// truncate current input at mode change
|
|
|
|
strncpy(_temp, _currentWord.c_str(), _currentCode.size());
|
|
|
|
_temp[_currentCode.size()] = 0;
|
|
|
|
_prefix += _temp;
|
|
|
|
_currentCode.clear();
|
|
|
|
_currentWord.clear();
|
|
|
|
memset(_repeatcount, 0, sizeof(_repeatcount));
|
2012-03-28 23:48:37 +00:00
|
|
|
|
2012-02-22 15:15:02 +00:00
|
|
|
_lastTime = 0;
|
2016-01-24 02:35:18 +00:00
|
|
|
_lastPressedButton = kNoAct;
|
2012-02-22 15:15:02 +00:00
|
|
|
_curTime = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pressEditText();
|
|
|
|
|
2012-03-28 23:48:37 +00:00
|
|
|
if (button == kOkAct)
|
|
|
|
close();
|
2012-05-03 16:32:34 +00:00
|
|
|
|
2016-01-24 01:37:07 +00:00
|
|
|
if (button == kCancelAct) {
|
|
|
|
saveUserDictToFile();
|
|
|
|
close();
|
|
|
|
}
|
2012-02-22 15:15:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PredictiveDialog::mergeDicts() {
|
|
|
|
_unitedDict.dictLineCount = _predictiveDict.dictLineCount + _userDict.dictLineCount;
|
2013-10-01 22:00:47 +00:00
|
|
|
_unitedDict.dictLine = (char **)calloc(_unitedDict.dictLineCount, sizeof(char *));
|
2012-02-22 15:15:02 +00:00
|
|
|
|
|
|
|
if (!_unitedDict.dictLine) {
|
2016-01-24 02:10:13 +00:00
|
|
|
debug(5, "Predictive Dialog: cannot allocate memory for united dic");
|
2012-02-22 15:15:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lenUserDictCode, lenPredictiveDictCode, lenCode;
|
|
|
|
int i, j, k;
|
|
|
|
i = j = k = 0;
|
|
|
|
|
|
|
|
while ((i < _userDict.dictLineCount) && (j < _predictiveDict.dictLineCount)) {
|
|
|
|
lenUserDictCode = strchr(_userDict.dictLine[i], ' ') - _userDict.dictLine[i];
|
|
|
|
lenPredictiveDictCode = strchr(_predictiveDict.dictLine[j], ' ') - _predictiveDict.dictLine[j];
|
|
|
|
lenCode = (lenUserDictCode >= lenPredictiveDictCode) ? lenUserDictCode : lenPredictiveDictCode;
|
|
|
|
if (strncmp(_userDict.dictLine[i], _predictiveDict.dictLine[j], lenCode) >= 0) {
|
|
|
|
_unitedDict.dictLine[k++] = _predictiveDict.dictLine[j++];
|
|
|
|
} else {
|
|
|
|
_unitedDict.dictLine[k++] = _userDict.dictLine[i++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (i < _userDict.dictLineCount) {
|
|
|
|
_unitedDict.dictLine[k++] = _userDict.dictLine[i++];
|
|
|
|
}
|
|
|
|
|
|
|
|
while (j < _predictiveDict.dictLineCount) {
|
|
|
|
_unitedDict.dictLine[k++] = _predictiveDict.dictLine[j++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-29 00:05:45 +00:00
|
|
|
uint8 PredictiveDialog::countWordsInString(const char *const str) {
|
2012-03-28 23:48:37 +00:00
|
|
|
// Count the number of (space separated) words in the given string.
|
2012-03-29 00:05:45 +00:00
|
|
|
const char *ptr;
|
2012-02-22 15:15:02 +00:00
|
|
|
|
|
|
|
if (!str)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ptr = strchr(str, ' ');
|
|
|
|
if (!ptr) {
|
2016-01-24 02:10:13 +00:00
|
|
|
debug(5, "Predictive Dialog: Invalid dictionary line");
|
2012-02-22 15:15:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8 num = 1;
|
|
|
|
ptr++;
|
|
|
|
while ((ptr = strchr(ptr, ' '))) {
|
|
|
|
ptr++;
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PredictiveDialog::bringWordtoTop(char *str, int wordnum) {
|
|
|
|
// This function reorders the words on the given pred.dic line
|
|
|
|
// by moving the word at position 'wordnum' to the front (that is, right behind
|
|
|
|
// right behind the numerical code word at the start of the line).
|
|
|
|
Common::Array<Common::String> words;
|
2012-03-25 22:29:19 +00:00
|
|
|
char buf[kMaxLineLen];
|
2012-02-22 15:15:02 +00:00
|
|
|
|
|
|
|
if (!str)
|
|
|
|
return;
|
2012-03-25 22:29:19 +00:00
|
|
|
strncpy(buf, str, kMaxLineLen);
|
|
|
|
buf[kMaxLineLen - 1] = 0;
|
2012-02-22 15:15:02 +00:00
|
|
|
char *word = strtok(buf, " ");
|
|
|
|
if (!word) {
|
2016-01-24 02:10:13 +00:00
|
|
|
debug(5, "Predictive Dialog: Invalid dictionary line");
|
2012-02-22 15:15:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
words.push_back(word);
|
2020-01-05 16:48:04 +00:00
|
|
|
while ((word = strtok(nullptr, " ")) != nullptr)
|
2012-02-22 15:15:02 +00:00
|
|
|
words.push_back(word);
|
|
|
|
words.insert_at(1, words.remove_at(wordnum + 1));
|
|
|
|
|
|
|
|
Common::String tmp;
|
|
|
|
for (uint8 i = 0; i < words.size(); i++)
|
2012-03-28 23:48:37 +00:00
|
|
|
tmp += words[i] + " ";
|
2012-02-22 15:15:02 +00:00
|
|
|
tmp.deleteLastChar();
|
|
|
|
memcpy(str, tmp.c_str(), strlen(str));
|
|
|
|
}
|
|
|
|
|
2012-03-29 00:05:45 +00:00
|
|
|
int PredictiveDialog::binarySearch(const char *const *const dictLine, const Common::String &code, const int dictLineCount) {
|
2012-02-22 15:15:02 +00:00
|
|
|
int hi = dictLineCount - 1;
|
|
|
|
int lo = 0;
|
|
|
|
int line = 0;
|
|
|
|
while (lo <= hi) {
|
|
|
|
line = (lo + hi) / 2;
|
|
|
|
int cmpVal = strncmp(dictLine[line], code.c_str(), code.size());
|
|
|
|
if (cmpVal > 0)
|
|
|
|
hi = line - 1;
|
|
|
|
else if (cmpVal < 0)
|
|
|
|
lo = line + 1;
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hi < lo) {
|
|
|
|
return -(lo + 1);
|
|
|
|
} else {
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PredictiveDialog::matchWord() {
|
2016-02-28 14:23:24 +00:00
|
|
|
// If there is no dictionary, then there is no match.
|
|
|
|
if (_unitedDict.dictLineCount <= 0)
|
|
|
|
return false;
|
|
|
|
|
2012-02-22 15:15:02 +00:00
|
|
|
// If no text has been entered, then there is no match.
|
|
|
|
if (_currentCode.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// If the currently entered text is too long, it cannot match anything.
|
2012-03-25 22:29:19 +00:00
|
|
|
if (_currentCode.size() > kMaxWordLen)
|
2012-02-22 15:15:02 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// The entries in the dictionary consist of a code, a space, and then
|
|
|
|
// a space-separated list of words matching this code.
|
2016-01-24 02:35:50 +00:00
|
|
|
// To exactly match a code, we therefore match the code plus the trailing
|
2012-02-22 15:15:02 +00:00
|
|
|
// space in the dictionary.
|
|
|
|
Common::String code = _currentCode + " ";
|
|
|
|
|
|
|
|
int line = binarySearch(_unitedDict.dictLine, code, _unitedDict.dictLineCount);
|
|
|
|
if (line < 0) {
|
|
|
|
line = -(line + 1);
|
2020-01-05 16:48:04 +00:00
|
|
|
_unitedDict.dictActLine = nullptr;
|
2012-02-22 15:15:02 +00:00
|
|
|
} else {
|
|
|
|
_unitedDict.dictActLine = _unitedDict.dictLine[line];
|
|
|
|
}
|
|
|
|
|
|
|
|
_currentWord.clear();
|
|
|
|
_wordNumber = 0;
|
|
|
|
if (0 == strncmp(_unitedDict.dictLine[line], _currentCode.c_str(), _currentCode.size())) {
|
2012-03-25 22:29:19 +00:00
|
|
|
char tmp[kMaxLineLen];
|
|
|
|
strncpy(tmp, _unitedDict.dictLine[line], kMaxLineLen);
|
|
|
|
tmp[kMaxLineLen - 1] = 0;
|
2013-11-02 23:12:49 +00:00
|
|
|
char *tok;
|
|
|
|
strtok(tmp, " ");
|
2020-01-05 16:48:04 +00:00
|
|
|
tok = strtok(nullptr, " ");
|
2012-02-22 15:15:02 +00:00
|
|
|
_currentWord = Common::String(tok, _currentCode.size());
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-29 00:05:45 +00:00
|
|
|
bool PredictiveDialog::searchWord(const char *const where, const Common::String &whatCode) {
|
|
|
|
const char *ptr = where;
|
2012-02-22 15:15:02 +00:00
|
|
|
ptr += whatCode.size();
|
|
|
|
|
2012-03-29 00:05:45 +00:00
|
|
|
const char *newPtr;
|
2012-02-22 15:15:02 +00:00
|
|
|
bool is = false;
|
2012-03-28 23:48:37 +00:00
|
|
|
while ((newPtr = strchr(ptr, ' '))) {
|
2012-02-22 15:15:02 +00:00
|
|
|
if (0 == strncmp(ptr, _currentWord.c_str(), newPtr - ptr)) {
|
|
|
|
is = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ptr = newPtr + 1;
|
|
|
|
}
|
|
|
|
if (!is) {
|
|
|
|
if (0 == strcmp(ptr, _currentWord.c_str())) {
|
|
|
|
is = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return is;
|
|
|
|
}
|
|
|
|
|
2012-03-28 23:53:09 +00:00
|
|
|
void PredictiveDialog::addWord(Dict &dict, const Common::String &word, const Common::String &code) {
|
2020-01-05 16:48:04 +00:00
|
|
|
char *newLine = nullptr;
|
2012-02-22 15:15:02 +00:00
|
|
|
Common::String tmpCode = code + ' ';
|
|
|
|
int line = binarySearch(dict.dictLine, tmpCode, dict.dictLineCount);
|
|
|
|
if (line >= 0) {
|
|
|
|
if (searchWord(dict.dictLine[line], tmpCode)) {
|
|
|
|
// if we found code and word, we should not insert/expands any word
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
// if we found the code, but did not find a word, we must
|
|
|
|
// EXPANDS the currnent line with new word
|
|
|
|
int oldLineSize = strlen(dict.dictLine[line]);
|
|
|
|
int newLineSize = oldLineSize + word.size() + 1;
|
|
|
|
|
|
|
|
newLine = (char *)malloc(newLineSize + 1);
|
|
|
|
|
|
|
|
char *ptr = newLine;
|
|
|
|
strncpy(ptr, dict.dictLine[line], oldLineSize);
|
|
|
|
ptr += oldLineSize;
|
|
|
|
Common::String tmp = ' ' + word + '\0';
|
|
|
|
strncpy(ptr, tmp.c_str(), tmp.size());
|
|
|
|
|
|
|
|
dict.dictLine[line] = newLine;
|
|
|
|
_memoryList[_numMemory++] = newLine;
|
|
|
|
|
|
|
|
if (dict.nameDict == "user_dictionary")
|
|
|
|
_userDictHasChanged = true;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else { // if we didn't find the code, we need to INSERT new line with code and word
|
|
|
|
if (dict.nameDict == "user_dictionary") {
|
2012-03-28 23:48:37 +00:00
|
|
|
// if we must INSERT new line(code and word) to user_dictionary, we need to
|
2012-02-22 15:15:02 +00:00
|
|
|
// check if there is a line that we want to INSERT in predictive dictionay
|
|
|
|
int predictLine = binarySearch(_predictiveDict.dictLine, tmpCode, _predictiveDict.dictLineCount);
|
2012-03-28 23:48:37 +00:00
|
|
|
if (predictLine >= 0) {
|
2012-02-22 15:15:02 +00:00
|
|
|
if (searchWord(_predictiveDict.dictLine[predictLine], tmpCode)) {
|
|
|
|
// if code and word is in predictive dictionary, we need to copy
|
|
|
|
// this line to user dictionary
|
|
|
|
int len = (predictLine == _predictiveDict.dictLineCount - 1) ? &_predictiveDict.dictText[_predictiveDict.dictTextSize] - _predictiveDict.dictLine[predictLine] :
|
2012-03-28 23:48:37 +00:00
|
|
|
_predictiveDict.dictLine[predictLine + 1] - _predictiveDict.dictLine[predictLine];
|
2012-02-22 15:15:02 +00:00
|
|
|
newLine = (char *)malloc(len);
|
|
|
|
strncpy(newLine, _predictiveDict.dictLine[predictLine], len);
|
|
|
|
} else {
|
|
|
|
// if there is no word in predictive dictionary, we need to copy to
|
|
|
|
// user dictionary mathed line + new word.
|
|
|
|
int len = (predictLine == _predictiveDict.dictLineCount - 1) ? &_predictiveDict.dictText[_predictiveDict.dictTextSize] - _predictiveDict.dictLine[predictLine] :
|
2012-03-28 23:48:37 +00:00
|
|
|
_predictiveDict.dictLine[predictLine + 1] - _predictiveDict.dictLine[predictLine];
|
2012-02-22 15:15:02 +00:00
|
|
|
newLine = (char *)malloc(len + word.size() + 1);
|
|
|
|
char *ptr = newLine;
|
|
|
|
strncpy(ptr, _predictiveDict.dictLine[predictLine], len);
|
|
|
|
ptr[len - 1] = ' ';
|
|
|
|
ptr += len;
|
|
|
|
strncpy(ptr, word.c_str(), word.size());
|
|
|
|
ptr[len + word.size()] = '\0';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// if we didnt find line in predictive dialog, we should copy to user dictionary
|
|
|
|
// code + word
|
|
|
|
Common::String tmp;
|
|
|
|
tmp = tmpCode + word + '\0';
|
|
|
|
newLine = (char *)malloc(tmp.size());
|
|
|
|
strncpy(newLine, tmp.c_str(), tmp.size());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// if want to insert line to different from user dictionary, we should copy to this
|
|
|
|
// dictionary code + word
|
|
|
|
Common::String tmp;
|
|
|
|
tmp = tmpCode + word + '\0';
|
|
|
|
newLine = (char *)malloc(tmp.size());
|
|
|
|
strncpy(newLine, tmp.c_str(), tmp.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// start from here are INSERTING new line to dictionaty ( dict )
|
2013-10-01 22:00:47 +00:00
|
|
|
char **newDictLine = (char **)calloc(dict.dictLineCount + 1, sizeof(char *));
|
2012-02-22 15:15:02 +00:00
|
|
|
if (!newDictLine) {
|
|
|
|
warning("Predictive Dialog: cannot allocate memory for index buffer");
|
2013-04-23 22:16:31 +00:00
|
|
|
|
|
|
|
free(newLine);
|
|
|
|
|
2012-02-22 15:15:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int k = 0;
|
|
|
|
bool inserted = false;
|
|
|
|
for (int i = 0; i < dict.dictLineCount; i++) {
|
|
|
|
uint lenPredictiveDictCode = strchr(dict.dictLine[i], ' ') - dict.dictLine[i];
|
|
|
|
uint lenCode = (lenPredictiveDictCode >= (code.size() - 1)) ? lenPredictiveDictCode : code.size() - 1;
|
|
|
|
if ((strncmp(dict.dictLine[i], code.c_str(), lenCode) > 0) && !inserted) {
|
|
|
|
newDictLine[k++] = newLine;
|
|
|
|
inserted = true;
|
|
|
|
}
|
|
|
|
if (k != (dict.dictLineCount + 1)) {
|
|
|
|
newDictLine[k++] = dict.dictLine[i];
|
|
|
|
}
|
|
|
|
}
|
2012-03-28 23:48:37 +00:00
|
|
|
if (!inserted)
|
2012-02-22 15:15:02 +00:00
|
|
|
newDictLine[k] = newLine;
|
|
|
|
|
|
|
|
_memoryList[_numMemory++] = newLine;
|
|
|
|
|
|
|
|
free(dict.dictLine);
|
|
|
|
dict.dictLineCount += 1;
|
2013-10-01 22:00:47 +00:00
|
|
|
dict.dictLine = (char **)calloc(dict.dictLineCount, sizeof(char *));
|
2012-02-22 15:15:02 +00:00
|
|
|
if (!dict.dictLine) {
|
|
|
|
warning("Predictive Dialog: cannot allocate memory for index buffer");
|
|
|
|
free(newDictLine);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < dict.dictLineCount; i++) {
|
|
|
|
dict.dictLine[i] = newDictLine[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dict.nameDict == "user_dictionary")
|
|
|
|
_userDictHasChanged = true;
|
|
|
|
|
|
|
|
free(newDictLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PredictiveDialog::addWordToDict() {
|
2012-03-25 22:29:19 +00:00
|
|
|
if (_numMemory < kMaxWord) {
|
2012-02-22 15:15:02 +00:00
|
|
|
addWord(_unitedDict, _currentWord, _currentCode);
|
2012-03-28 23:48:37 +00:00
|
|
|
addWord(_userDict, _currentWord, _currentCode);
|
2012-02-22 15:15:02 +00:00
|
|
|
} else {
|
|
|
|
warning("Predictive Dialog: You cannot add word to user dictionary...");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PredictiveDialog::loadDictionary(Common::SeekableReadStream *in, Dict &dict) {
|
|
|
|
int lines = 0;
|
|
|
|
|
|
|
|
uint32 time1 = g_system->getMillis();
|
|
|
|
|
|
|
|
dict.dictTextSize = in->size();
|
|
|
|
dict.dictText = (char *)malloc(dict.dictTextSize + 1);
|
|
|
|
|
|
|
|
if (!dict.dictText) {
|
|
|
|
warning("Predictive Dialog: Not enough memory to load the file user.dic");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
in->read(dict.dictText, dict.dictTextSize);
|
|
|
|
dict.dictText[dict.dictTextSize] = 0;
|
|
|
|
uint32 time2 = g_system->getMillis();
|
2016-01-24 02:10:13 +00:00
|
|
|
debug(5, "Predictive Dialog: Time to read %s: %d bytes, %d ms", ConfMan.get(dict.nameDict).c_str(), dict.dictTextSize, time2 - time1);
|
2012-02-22 15:15:02 +00:00
|
|
|
delete in;
|
|
|
|
|
|
|
|
char *ptr = dict.dictText;
|
|
|
|
lines = 1;
|
|
|
|
while ((ptr = strchr(ptr, '\n'))) {
|
|
|
|
lines++;
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
2013-10-01 22:00:47 +00:00
|
|
|
dict.dictLine = (char **)calloc(lines, sizeof(char *));
|
2020-01-05 16:48:04 +00:00
|
|
|
if (dict.dictLine == nullptr) {
|
2012-02-22 15:15:02 +00:00
|
|
|
warning("Predictive Dialog: Cannot allocate memory for line index buffer");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dict.dictLine[0] = dict.dictText;
|
|
|
|
ptr = dict.dictText;
|
|
|
|
int i = 1;
|
|
|
|
while ((ptr = strchr(ptr, '\n'))) {
|
|
|
|
*ptr = 0;
|
|
|
|
ptr++;
|
2017-11-14 23:01:32 +00:00
|
|
|
#if defined(__DS__) && defined(ENABLE_AGI)
|
2012-02-22 15:15:02 +00:00
|
|
|
// Pass the line on to the DS word list
|
|
|
|
DS::addAutoCompleteLine(dict.dictLine[i - 1]);
|
|
|
|
#endif
|
|
|
|
dict.dictLine[i++] = ptr;
|
|
|
|
}
|
|
|
|
if (dict.dictLine[lines - 1][0] == 0)
|
|
|
|
lines--;
|
|
|
|
|
|
|
|
dict.dictLineCount = lines;
|
2016-01-24 02:10:13 +00:00
|
|
|
debug(5, "Predictive Dialog: Loaded %d lines", dict.dictLineCount);
|
2012-02-22 15:15:02 +00:00
|
|
|
|
|
|
|
// FIXME: We use binary search on _predictiveDict.dictLine, yet we make no at_tempt
|
|
|
|
// to ever sort this array (except for the DS port). That seems risky, doesn't it?
|
|
|
|
|
2017-11-14 23:01:32 +00:00
|
|
|
#if defined(__DS__) && defined(ENABLE_AGI)
|
2012-02-22 15:15:02 +00:00
|
|
|
// Sort the DS word completion list, to allow for a binary chop later (in the ds backend)
|
|
|
|
DS::sortAutoCompleteWordList();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
uint32 time3 = g_system->getMillis();
|
2016-01-24 02:10:13 +00:00
|
|
|
debug(5, "Predictive Dialog: Time to parse %s: %d, total: %d", ConfMan.get(dict.nameDict).c_str(), time3 - time2, time3 - time1);
|
2012-02-22 15:15:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PredictiveDialog::loadAllDictionary(Dict &dict) {
|
2016-01-24 02:14:09 +00:00
|
|
|
ConfMan.registerDefault(dict.nameDict, dict.defaultFilename);
|
2012-02-22 15:15:02 +00:00
|
|
|
|
|
|
|
if (dict.nameDict == "predictive_dictionary") {
|
2012-03-28 23:50:52 +00:00
|
|
|
Common::File *inFile = new Common::File();
|
2012-02-22 15:15:02 +00:00
|
|
|
if (!inFile->open(ConfMan.get(dict.nameDict))) {
|
2016-01-24 02:14:09 +00:00
|
|
|
warning("Predictive Dialog: cannot read file: %s", dict.defaultFilename.c_str());
|
2016-02-28 14:04:11 +00:00
|
|
|
delete inFile;
|
2012-02-22 15:15:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
loadDictionary(inFile, dict);
|
|
|
|
} else {
|
|
|
|
Common::InSaveFile *inFile = g_system->getSavefileManager()->openForLoading(ConfMan.get(dict.nameDict));
|
|
|
|
if (!inFile) {
|
2016-01-24 02:14:09 +00:00
|
|
|
warning("Predictive Dialog: cannot read file: %s", dict.defaultFilename.c_str());
|
2012-02-22 15:15:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
loadDictionary(inFile, dict);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PredictiveDialog::pressEditText() {
|
|
|
|
Common::strlcpy(_predictiveResult, _prefix.c_str(), sizeof(_predictiveResult));
|
|
|
|
Common::strlcat(_predictiveResult, _currentWord.c_str(), sizeof(_predictiveResult));
|
2020-07-01 18:01:48 +00:00
|
|
|
_editText->setEditString(Common::convertToU32String(_predictiveResult));
|
2016-01-24 02:35:18 +00:00
|
|
|
//_editText->setCaretPos(_prefix.size() + _currentWord.size());
|
2018-01-06 13:40:02 +00:00
|
|
|
_editText->markAsDirty();
|
2012-02-22 15:15:02 +00:00
|
|
|
}
|
|
|
|
|
2012-03-25 19:23:16 +00:00
|
|
|
} // namespace GUI
|