aboutsummaryrefslogtreecommitdiff
path: root/gui/predictivedialog.cpp
diff options
context:
space:
mode:
authorJohannes Schickel2012-03-29 01:48:37 +0200
committerJohannes Schickel2012-03-29 01:50:00 +0200
commit15ff9380b5d9fcd0b39bbf5a3253e012039639e2 (patch)
tree6483aabf2946afef77c5590b3c9feaa97a118ccb /gui/predictivedialog.cpp
parent561a18b2bb14b0aafc57791dc036524b34208824 (diff)
downloadscummvm-rg350-15ff9380b5d9fcd0b39bbf5a3253e012039639e2.tar.gz
scummvm-rg350-15ff9380b5d9fcd0b39bbf5a3253e012039639e2.tar.bz2
scummvm-rg350-15ff9380b5d9fcd0b39bbf5a3253e012039639e2.zip
GUI: Formatting fixes in the PredictiveDialog code.
Diffstat (limited to 'gui/predictivedialog.cpp')
-rw-r--r--gui/predictivedialog.cpp133
1 files changed, 73 insertions, 60 deletions
diff --git a/gui/predictivedialog.cpp b/gui/predictivedialog.cpp
index d9c3a58e24..4d640c7104 100644
--- a/gui/predictivedialog.cpp
+++ b/gui/predictivedialog.cpp
@@ -71,21 +71,21 @@ enum {
PredictiveDialog::PredictiveDialog() : Dialog("Predictive") {
new StaticTextWidget(this, "Predictive.Headline", "Enter Text");
- new ButtonWidget(this, "Predictive.Cancel" , _("Cancel") , 0, kCancelCmd);
- new ButtonWidget(this, "Predictive.OK" , _("Ok") , 0, kOkCmd);
- new ButtonWidget(this, "Predictive.Button1", "1 `-.&" , 0, kBut1Cmd);
- new ButtonWidget(this, "Predictive.Button2", "2 abc" , 0, kBut2Cmd);
- new ButtonWidget(this, "Predictive.Button3", "3 def" , 0, kBut3Cmd);
- new ButtonWidget(this, "Predictive.Button4", "4 ghi" , 0, kBut4Cmd);
- new ButtonWidget(this, "Predictive.Button5", "5 jkl" , 0, kBut5Cmd);
- new ButtonWidget(this, "Predictive.Button6", "6 mno" , 0, kBut6Cmd);
- new ButtonWidget(this, "Predictive.Button7", "7 pqrs" , 0, kBut7Cmd);
- new ButtonWidget(this, "Predictive.Button8", "8 tuv" , 0, kBut8Cmd);
- new ButtonWidget(this, "Predictive.Button9", "9 wxyz" , 0, kBut9Cmd);
+ new ButtonWidget(this, "Predictive.Cancel" , _("Cancel"), 0, kCancelCmd);
+ new ButtonWidget(this, "Predictive.OK" , _("Ok") , 0, kOkCmd);
+ new ButtonWidget(this, "Predictive.Button1", "1 `-.&" , 0, kBut1Cmd);
+ new ButtonWidget(this, "Predictive.Button2", "2 abc" , 0, kBut2Cmd);
+ new ButtonWidget(this, "Predictive.Button3", "3 def" , 0, kBut3Cmd);
+ new ButtonWidget(this, "Predictive.Button4", "4 ghi" , 0, kBut4Cmd);
+ new ButtonWidget(this, "Predictive.Button5", "5 jkl" , 0, kBut5Cmd);
+ new ButtonWidget(this, "Predictive.Button6", "6 mno" , 0, kBut6Cmd);
+ new ButtonWidget(this, "Predictive.Button7", "7 pqrs" , 0, kBut7Cmd);
+ new ButtonWidget(this, "Predictive.Button8", "8 tuv" , 0, kBut8Cmd);
+ new ButtonWidget(this, "Predictive.Button9", "9 wxyz" , 0, kBut9Cmd);
new ButtonWidget(this, "Predictive.Button0", "0" , 0, kBut0Cmd);
// I18N: You must leave "#" as is, only word 'next' is translatable
- new ButtonWidget(this, "Predictive.Next" , _("# next") , 0, kNextCmd);
- _addBtn = new ButtonWidget(this, "Predictive.Add", _("add") , 0, kAddCmd);
+ new ButtonWidget(this, "Predictive.Next" , _("# next"), 0, kNextCmd);
+ _addBtn = new ButtonWidget(this, "Predictive.Add", _("add"), 0, kAddCmd);
_addBtn->setEnabled(false);
#ifndef DISABLE_FANCY_THEMES
@@ -93,7 +93,7 @@ PredictiveDialog::PredictiveDialog() : Dialog("Predictive") {
((PicButtonWidget *)_delbtn)->useThemeTransparency(true);
((PicButtonWidget *)_delbtn)->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageDelbtn));
#endif
- _delbtn = new ButtonWidget(this, "Predictive.Delete" , _("<") , 0, kDelCmd);
+ _delbtn = new ButtonWidget(this, "Predictive.Delete" , _("<"), 0, kDelCmd);
// I18N: Pre means 'Predictive', leave '*' as is
_modebutton = new ButtonWidget(this, "Predictive.Pre", _("* Pre"), 0, kModeCmd);
_edittext = new EditTextWidget(this, "Predictive.Word", _search, 0, 0, 0);
@@ -114,7 +114,7 @@ PredictiveDialog::PredictiveDialog() : Dialog("Predictive") {
_predictiveDict.dictLine = NULL;
_predictiveDict.dictText = NULL;
_predictiveDict.dictLineCount = 0;
-
+
if (!_predictiveDict.dictText) {
loadAllDictionary(_predictiveDict);
if (!_predictiveDict.dictText)
@@ -144,7 +144,7 @@ PredictiveDialog::PredictiveDialog() : Dialog("Predictive") {
_currentWord.clear();
_wordNumber = 0;
_numMatchingWords = 0;
-
+
_lastbutton = kNoAct;
_mode = kModePre;
@@ -310,7 +310,7 @@ void PredictiveDialog::handleKeyDown(Common::KeyState state) {
}
}
-void PredictiveDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
+void PredictiveDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
ButtonId act = kNoAct;
_navigationwithkeys = false;
@@ -376,24 +376,30 @@ void PredictiveDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 d
void PredictiveDialog::processBtnActive(ButtonId button) {
uint8 x;
- const char *buttonStr[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" };
+ const char *buttonStr[] = {
+ "1", "2", "3",
+ "4", "5", "6",
+ "7", "8", "9",
+ "0"
+ };
+
const char *buttons[] = {
- "'-.&", "abc", "def",
- "ghi", "jkl", "mno",
- "pqrs", "tuv", "wxyz",
- "next", "add",
- "<",
- "Cancel", "OK",
- "Pre", "(0) ", NULL
+ "'-.&", "abc", "def",
+ "ghi", "jkl", "mno",
+ "pqrs", "tuv", "wxyz",
+ "next", "add",
+ "<",
+ "Cancel", "OK",
+ "Pre", "(0) ", NULL
};
if (_mode == kModeAbc) {
- if (button >= kBtn1Act && button <= kBtn9Act ) {
+ if (button >= kBtn1Act && button <= kBtn9Act) {
if (!_lastTime)
_lastTime = g_system->getMillis();
if (_lastPressBtn == button) {
_curTime = g_system->getMillis();
- if((_curTime - _lastTime) < kRepeatDelay) {
+ if ((_curTime - _lastTime) < kRepeatDelay) {
button = kNextAct;
_lastTime = _curTime;
} else {
@@ -429,7 +435,7 @@ void PredictiveDialog::processBtnActive(ButtonId button) {
if (_currentCode.size()) {
_repeatcount[_currentCode.size() - 1] = 0;
_currentCode.deleteLastChar();
- if(_currentCode == Common::String(""))
+ if (_currentCode == Common::String(""))
_currentWord.clear();
} else {
if (_prefix.size())
@@ -471,20 +477,20 @@ void PredictiveDialog::processBtnActive(ButtonId button) {
char *tok = strtok(tmp, " ");
for (uint8 i = 0; i <= _wordNumber; i++)
tok = strtok(NULL, " ");
- _currentWord = Common::String(tok, _currentCode.size());
- }
- } else if (_mode == kModeAbc) {
- x = _currentCode.size();
- if (x) {
- if (_currentCode.lastChar() == '1' || _currentCode.lastChar() == '7' || _currentCode.lastChar() == '9')
- _repeatcount[x - 1] = (_repeatcount[x - 1] + 1) % 4;
- else
+ _currentWord = Common::String(tok, _currentCode.size());
+ }
+ } else if (_mode == kModeAbc) {
+ x = _currentCode.size();
+ if (x) {
+ if (_currentCode.lastChar() == '1' || _currentCode.lastChar() == '7' || _currentCode.lastChar() == '9')
+ _repeatcount[x - 1] = (_repeatcount[x - 1] + 1) % 4;
+ else
_repeatcount[x - 1] = (_repeatcount[x - 1] + 1) % 3;
- if (_currentCode.lastChar() >= '1')
- _currentWord.setChar(buttons[_currentCode[x - 1] - '1'][_repeatcount[x - 1]], x-1);
- }
+ if (_currentCode.lastChar() >= '1')
+ _currentWord.setChar(buttons[_currentCode[x - 1] - '1'][_repeatcount[x - 1]], x - 1);
}
+ }
} else if (button == kAddAct) { // add
if (_mode == kModeAbc)
addWordToDict();
@@ -494,17 +500,22 @@ void PredictiveDialog::processBtnActive(ButtonId button) {
// 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);
-
+
goto press;
} else if (button == kModeAct) { // Mode
_mode++;
_addBtn->setEnabled(false);
- if (_mode > kModeAbc) {
- _mode = kModePre;
- // I18N: Pre means 'Predictive', leave '*' as is
- _modebutton->setLabel("* Pre");
- // I18N: 'Num' means Numbers, 'Abc' means Latin alphabet input
- } else (_mode == kModeNum) ? _modebutton->setLabel("* Num") : (_modebutton->setLabel("* Abc"), _addBtn->setEnabled(true));
+ if (_mode > kModeAbc) {
+ _mode = kModePre;
+ // I18N: Pre means 'Predictive', leave '*' as is
+ _modebutton->setLabel("* Pre");
+ // I18N: 'Num' means Numbers, 'Abc' means Latin alphabet input
+ } else if (_mode == kModeNum) {
+ _modebutton->setLabel("* Num");
+ } else {
+ _modebutton->setLabel("* Abc");
+ _addBtn->setEnabled(true);
+ }
// truncate current input at mode change
strncpy(_temp, _currentWord.c_str(), _currentCode.size());
@@ -513,7 +524,7 @@ void PredictiveDialog::processBtnActive(ButtonId button) {
_currentCode.clear();
_currentWord.clear();
memset(_repeatcount, 0, sizeof(_repeatcount));
-
+
_lastTime = 0;
_lastPressBtn = kNoAct;
_curTime = 0;
@@ -525,14 +536,16 @@ void PredictiveDialog::processBtnActive(ButtonId button) {
press:
pressEditText();
- if (button == kOkAct) close();
+ if (button == kOkAct)
+ close();
}
void PredictiveDialog::handleTickle() {
- if (!_lastTime)
+ if (!_lastTime) {
if ((_curTime - _lastTime) > kRepeatDelay) {
_lastTime = 0;
}
+ }
}
void PredictiveDialog::mergeDicts() {
@@ -569,7 +582,7 @@ void PredictiveDialog::mergeDicts() {
}
uint8 PredictiveDialog::countWordsInString(char *str) {
- // Count the number of (space separated) words in the given string.
+ // Count the number of (space separated) words in the given string.
char *ptr;
if (!str)
@@ -614,7 +627,7 @@ void PredictiveDialog::bringWordtoTop(char *str, int wordnum) {
Common::String tmp;
for (uint8 i = 0; i < words.size(); i++)
- tmp += words[i] + " ";
+ tmp += words[i] + " ";
tmp.deleteLastChar();
memcpy(str, tmp.c_str(), strlen(str));
}
@@ -686,7 +699,7 @@ bool PredictiveDialog::searchWord(char *where, const String &whatCode) {
char *newPtr;
bool is = false;
- while((newPtr = strchr(ptr, ' '))) {
+ while ((newPtr = strchr(ptr, ' '))) {
if (0 == strncmp(ptr, _currentWord.c_str(), newPtr - ptr)) {
is = true;
break;
@@ -733,22 +746,22 @@ void PredictiveDialog::addWord(Dict &dict, const String &word, const String &cod
}
} else { // if we didn't find the code, we need to INSERT new line with code and word
if (dict.nameDict == "user_dictionary") {
- // if we must INSERT new line(code and word) to user_dictionary, we need to
+ // if we must INSERT new line(code and word) to user_dictionary, we need to
// check if there is a line that we want to INSERT in predictive dictionay
int predictLine = binarySearch(_predictiveDict.dictLine, tmpCode, _predictiveDict.dictLineCount);
- if (predictLine >= 0) {
+ if (predictLine >= 0) {
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] :
- _predictiveDict.dictLine[predictLine + 1] - _predictiveDict.dictLine[predictLine];
+ _predictiveDict.dictLine[predictLine + 1] - _predictiveDict.dictLine[predictLine];
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] :
- _predictiveDict.dictLine[predictLine + 1] - _predictiveDict.dictLine[predictLine];
+ _predictiveDict.dictLine[predictLine + 1] - _predictiveDict.dictLine[predictLine];
newLine = (char *)malloc(len + word.size() + 1);
char *ptr = newLine;
strncpy(ptr, _predictiveDict.dictLine[predictLine], len);
@@ -796,7 +809,7 @@ void PredictiveDialog::addWord(Dict &dict, const String &word, const String &cod
newDictLine[k++] = dict.dictLine[i];
}
}
- if (!inserted)
+ if (!inserted)
newDictLine[k] = newLine;
_memoryList[_numMemory++] = newLine;
@@ -823,7 +836,7 @@ void PredictiveDialog::addWord(Dict &dict, const String &word, const String &cod
void PredictiveDialog::addWordToDict() {
if (_numMemory < kMaxWord) {
addWord(_unitedDict, _currentWord, _currentCode);
- addWord(_userDict, _currentWord, _currentCode);
+ addWord(_userDict, _currentWord, _currentCode);
} else {
warning("Predictive Dialog: You cannot add word to user dictionary...");
}
@@ -845,7 +858,7 @@ void PredictiveDialog::loadDictionary(Common::SeekableReadStream *in, Dict &dict
in->read(dict.dictText, dict.dictTextSize);
dict.dictText[dict.dictTextSize] = 0;
uint32 time2 = g_system->getMillis();
- debug("Predictive Dialog: Time to read %s: %d bytes, %d ms", ConfMan.get(dict.nameDict).c_str(), dict.dictTextSize, time2-time1);
+ debug("Predictive Dialog: Time to read %s: %d bytes, %d ms", ConfMan.get(dict.nameDict).c_str(), dict.dictTextSize, time2 - time1);
delete in;
char *ptr = dict.dictText;
@@ -887,7 +900,7 @@ void PredictiveDialog::loadDictionary(Common::SeekableReadStream *in, Dict &dict
#endif
uint32 time3 = g_system->getMillis();
- debug("Predictive Dialog: Time to parse %s: %d, total: %d", ConfMan.get(dict.nameDict).c_str(), time3-time2, time3-time1);
+ debug("Predictive Dialog: Time to parse %s: %d, total: %d", ConfMan.get(dict.nameDict).c_str(), time3 - time2, time3 - time1);
}
void PredictiveDialog::loadAllDictionary(Dict &dict) {