ScummVM API documentation
predictivedialog.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef GUI_PREDICTIVEDIALOG_H
23#define GUI_PREDICTIVEDIALOG_H
24
25#include "gui/dialog.h"
26#include "common/str.h"
27#include "common/stream.h"
28
29namespace GUI {
30
31class EditTextWidget;
32class ButtonWidget;
33class PicButtonWidget;
34
36public:
38 ~PredictiveDialog() override;
39
40 void reflowLayout() override;
41
42 void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) override;
43 void handleKeyUp(Common::KeyState state) override;
44 void handleKeyDown(Common::KeyState state) override;
45
46 const char *getResult() const { return _predictiveResult; }
47
48private:
49 enum ButtonId {
50 kButton1Act = 0,
51 kButton2Act = 1,
52 kButton3Act = 2,
53 kButton4Act = 3,
54 kButton5Act = 4,
55 kButton6Act = 5,
56 kButton7Act = 6,
57 kButton8Act = 7,
58 kButton9Act = 8,
59 kNextAct = 9,
60 kAddAct = 10,
61 kDelAct = 11,
62 kCancelAct = 12,
63 kOkAct = 13,
64 kModeAct = 14,
65 kButton0Act = 15,
66 kNoAct = -1
67 };
68
69 enum {
70 kButtonCount = kButton0Act + 1
71 };
72
73 enum {
74 kRepeatDelay = 500
75 };
76
77 enum {
78 kMaxLineLen = 80,
79 kMaxWordLen = 24,
80 kMaxWord = 50
81 };
82
83 struct Dict {
84 Dict() : dictLine(nullptr), dictText(nullptr), dictActLine(nullptr),
85 dictLineCount(0), dictTextSize(0) {}
86 ~Dict() { free(dictText); }
87 char **dictLine;
88 char *dictText;
89 char *dictActLine; // using only for united dict...
90 int32 dictLineCount;
91 int32 dictTextSize;
92 Common::String nameDict;
93 Common::String defaultFilename;
94 };
95
96 uint8 countWordsInString(const char *const str);
97 void bringWordtoTop(char *str, int wordnum);
98 void loadDictionary(Common::SeekableReadStream *in, Dict &dict);
99 void loadAllDictionary(Dict &dict);
100 void addWordToDict();
101 void addWord(Dict &dict, const Common::String &word, const Common::String &code);
102 bool searchWord(const char *const where, const Common::String &whatCode);
103 int binarySearch(const char *const *const dictLine, const Common::String &code, const int dictLineCount);
104 bool matchWord();
105 void processButton(ButtonId active);
106 void pressEditText();
107
108 void saveUserDictToFile();
109
110 void mergeDicts();
111
112 void updateHighLightedButton(ButtonId active);
113private:
114 Dict _unitedDict;
115 Dict _predictiveDict;
116 Dict _userDict;
117
118 int _mode;
119 ButtonId _lastButton;
120
121 bool _userDictHasChanged;
122
123 int _wordNumber;
124 uint8 _numMatchingWords;
125 char _predictiveResult[40];
126
127 Common::String _currentCode;
128 Common::String _currentWord;
129 Common::String _prefix;
130
131 uint32 _curTime, _lastTime;
132 ButtonId _lastPressedButton;
133 ButtonId _curPressedButton;
134
135 char _temp[kMaxWordLen + 1];
136 int _repeatcount[kMaxWordLen];
137
138 char *_memoryList[kMaxWord];
139 int _numMemory;
140
141 Common::String _search;
142
143 bool _navigationWithKeys;
144 bool _needRefresh;
145 bool _isPressed;
146
147private:
148 EditTextWidget *_editText;
149 ButtonWidget *_button[kButtonCount];
150};
151
152} // namespace GUI
153
154#endif
Definition: stream.h:745
Definition: str.h:59
Definition: widget.h:241
Definition: object.h:40
Definition: dialog.h:49
Definition: edittext.h:32
Definition: predictivedialog.h:35
Definition: keyboard.h:294