ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

predictivedialog.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef GUI_PREDICTIVEDIALOG_H
00024 #define GUI_PREDICTIVEDIALOG_H
00025 
00026 #include "gui/dialog.h"
00027 #include "common/str.h"
00028 #include "common/stream.h"
00029 
00030 namespace GUI {
00031 
00032 class EditTextWidget;
00033 class ButtonWidget;
00034 class PicButtonWidget;
00035 
00036 class PredictiveDialog : public GUI::Dialog {
00037 public:
00038     PredictiveDialog();
00039     ~PredictiveDialog();
00040 
00041     virtual void reflowLayout();
00042 
00043     virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data);
00044     virtual void handleKeyUp(Common::KeyState state);
00045     virtual void handleKeyDown(Common::KeyState state);
00046 
00047     const char *getResult() const { return _predictiveResult; }
00048 
00049 private:
00050     enum ButtonId {
00051         kButton1Act   = 0,
00052         kButton2Act   = 1,
00053         kButton3Act   = 2,
00054         kButton4Act   = 3,
00055         kButton5Act   = 4,
00056         kButton6Act   = 5,
00057         kButton7Act   = 6,
00058         kButton8Act   = 7,
00059         kButton9Act   = 8,
00060         kNextAct      = 9,
00061         kAddAct       = 10,
00062         kDelAct       = 11,
00063         kCancelAct    = 12,
00064         kOkAct        = 13,
00065         kModeAct      = 14,
00066         kButton0Act   = 15,
00067         kNoAct        = -1
00068     };
00069 
00070     enum {
00071         kButtonCount = kButton0Act + 1
00072     };
00073 
00074     enum {
00075         kRepeatDelay = 500
00076     };
00077 
00078     enum {
00079         kMaxLineLen = 80,
00080         kMaxWordLen = 24,
00081         kMaxWord = 50
00082     };
00083 
00084     struct Dict {
00085         Dict() : dictLine(nullptr), dictText(nullptr), dictActLine(nullptr),
00086                  dictLineCount(0), dictTextSize(0) {}
00087         ~Dict() { free(dictText); }
00088         char **dictLine;
00089         char *dictText;
00090         char *dictActLine; // using only for united dict...
00091         int32 dictLineCount;
00092         int32 dictTextSize;
00093         Common::String nameDict;
00094         Common::String defaultFilename;
00095     };
00096 
00097     uint8 countWordsInString(const char *const str);
00098     void bringWordtoTop(char *str, int wordnum);
00099     void loadDictionary(Common::SeekableReadStream *in, Dict &dict);
00100     void loadAllDictionary(Dict &dict);
00101     void addWordToDict();
00102     void addWord(Dict &dict, const Common::String &word, const Common::String &code);
00103     bool searchWord(const char *const where, const Common::String &whatCode);
00104     int binarySearch(const char *const *const dictLine, const Common::String &code, const int dictLineCount);
00105     bool matchWord();
00106     void processButton(ButtonId active);
00107     void pressEditText();
00108 
00109     void saveUserDictToFile();
00110 
00111     void mergeDicts();
00112 
00113     void updateHighLightedButton(ButtonId active);
00114 private:
00115     Dict _unitedDict;
00116     Dict _predictiveDict;
00117     Dict _userDict;
00118 
00119     int _mode;
00120     ButtonId _lastButton;
00121 
00122     bool _userDictHasChanged;
00123 
00124     int _wordNumber;
00125     uint8 _numMatchingWords;
00126     char _predictiveResult[40];
00127 
00128     Common::String _currentCode;
00129     Common::String _currentWord;
00130     Common::String _prefix;
00131 
00132     uint32 _curTime, _lastTime;
00133     ButtonId _lastPressedButton;
00134     ButtonId _curPressedButton;
00135 
00136     char _temp[kMaxWordLen + 1];
00137     int _repeatcount[kMaxWordLen];
00138 
00139     char *_memoryList[kMaxWord];
00140     int _numMemory;
00141 
00142     Common::String _search;
00143 
00144     bool _navigationWithKeys;
00145     bool _needRefresh;
00146 private:
00147     EditTextWidget *_editText;
00148     ButtonWidget   *_button[kButtonCount];
00149 };
00150 
00151 } // namespace GUI
00152 
00153 #endif


Generated on Sat Mar 16 2019 05:01:50 for ResidualVM by doxygen 1.7.1
curved edge   curved edge