Modify the code related to it.
Remove CDotXkeymacs and CFunctionDefinition.
--- /dev/null
+#include "FuncDefs.h"\r
+#include "../xkeymacsdll/CmdTable.h"\r
+#include "../xkeymacsdll/xkeymacsdll.h"\r
+\r
+int FuncDefs::m_NumOfDefs;\r
+TCHAR FuncDefs::m_Names[MAX_FUNCTION][SUB_KEY_NAME_LENGTH];\r
+TCHAR FuncDefs::m_StrDefs[MAX_FUNCTION][MAX_DEFINITION];\r
+KeyBind FuncDefs::m_Defs[MAX_FUNCTION][MAX_DEFINITION];\r
+\r
+void FuncDefs::Load()\r
+{\r
+ Clear();\r
+ LoadFiles();\r
+ ParseDefs();\r
+}\r
+\r
+int FuncDefs::GetID(LPCTSTR name)\r
+{\r
+ for (int i = 0; i < m_NumOfDefs; ++i)\r
+ if (!_tcscmp(m_Names[i], name))\r
+ return i;\r
+ return -1;\r
+}\r
+\r
+LPCTSTR FuncDefs::GetName(int id)\r
+{\r
+ return m_Names[id];\r
+}\r
+\r
+int FuncDefs::GetNumOfDefs()\r
+{\r
+ return m_NumOfDefs;\r
+}\r
+\r
+LPCTSTR FuncDefs::GetStrDef(int id)\r
+{\r
+ return m_StrDefs[id];\r
+}\r
+\r
+KeyBind (*FuncDefs::GetDefs())[MAX_DEFINITION]\r
+{\r
+ return m_Defs;\r
+}\r
+\r
+void FuncDefs::Clear()\r
+{\r
+ m_NumOfDefs = 0;\r
+ ZeroMemory(m_Names, sizeof(m_Names));\r
+ ZeroMemory(m_StrDefs, sizeof(m_StrDefs));\r
+ ZeroMemory(m_Defs, sizeof(m_Defs));\r
+}\r
+\r
+void FuncDefs::LoadFiles()\r
+{\r
+ const TCHAR ext[] = _T("xkeymacs");\r
+ TCHAR mfname[MAX_PATH], drive[_MAX_DRIVE], dir[_MAX_DIR], etc[_MAX_DIR];\r
+ if (GetModuleFileName(NULL, mfname, MAX_PATH) == 0) // no such case\r
+ return;\r
+ _tsplitpath_s(mfname, drive, _MAX_DRIVE, dir, _MAX_DIR, NULL, 0, NULL, 0);\r
+ _tmakepath_s(etc, drive, dir, _T("etc"), NULL);\r
+ for (int i = 0; i < 3; i++) {\r
+ TCHAR fname[_MAX_FNAME];\r
+ TCHAR file[MAX_PATH];\r
+ switch (i) {\r
+ case 0:\r
+ if (!GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SENGLANGUAGE, fname, _MAX_FNAME))\r
+ continue;\r
+ MoveOldFile(drive, dir, fname, ext);\r
+ _tmakepath_s(file, NULL, etc, fname, ext);\r
+ LoadFile(file);\r
+ break;\r
+ case 1:\r
+ _tcscpy_s(fname, _T("dot"));\r
+ MoveOldFile(drive, dir, fname, ext);\r
+ _tmakepath_s(file, NULL, etc, fname, ext);\r
+ LoadFile(file);\r
+ break;\r
+ case 2:\r
+ TCHAR appdata[MAX_PATH];\r
+ if (!SHGetSpecialFolderPath(NULL, appdata, CSIDL_APPDATA, TRUE))\r
+ continue;\r
+ _tmakepath_s(file, NULL, appdata, fname, ext);\r
+ LoadFile(file);\r
+ break;\r
+ }\r
+ }\r
+}\r
+\r
+// This function moves files in the installed directory used by 3.22 or older under 'etc'.\r
+void FuncDefs::MoveOldFile(LPCTSTR drive, LPCTSTR dir, LPCTSTR fname, LPCTSTR ext)\r
+{\r
+ TCHAR old[MAX_PATH];\r
+ _tmakepath_s(old, drive, dir, fname, ext);\r
+ if (!PathFileExists(old))\r
+ return;\r
+ TCHAR etc[MAX_PATH];\r
+ _tmakepath_s(etc, drive, dir, _T("etc"), NULL);\r
+ if (!PathFileExists(etc) && !CreateDirectory(etc, NULL) ||\r
+ !PathIsDirectory(etc)) // a normal file 'etc' exists\r
+ return;\r
+ TCHAR newpath[MAX_PATH];\r
+ _tmakepath_s(newpath, NULL, etc, fname, ext);\r
+ if (MoveFile(old, newpath))\r
+ return;\r
+ // move an old file under 'etc' as a backup file.\r
+ TCHAR backup[_MAX_FNAME] = _T("~");\r
+ _tcscat_s(backup, fname);\r
+ _tmakepath_s(newpath, NULL, etc, backup, ext);\r
+ MoveFile(old, newpath);\r
+ return;\r
+}\r
+\r
+void FuncDefs::LoadFile(LPCTSTR file)\r
+{\r
+ FILE *fp;\r
+ TCHAR buf[7 + SUB_KEY_NAME_LENGTH + 1 + MAX_DEFINITION + 3]; // (fset 'sym def)\n\0\r
+ if (_tfopen_s(&fp, file, "r") != 0)\r
+ return;\r
+ while (_fgetts(buf, _countof(buf), fp)) {\r
+ if (_tcslen(buf) < _tcslen(_T("(fset 'a [])")) || _tcsncmp(buf, _T("(fset "), 6))\r
+ continue;\r
+ LPTSTR space = _tcschr(buf + 7, _T(' '));\r
+ if (!space)\r
+ continue;\r
+ *space = 0;\r
+ LPCTSTR name = buf + 7;\r
+ LPTSTR def = space + 1;\r
+ if (_tcslen(name) > SUB_KEY_NAME_LENGTH - 1 || _tcslen(def) > MAX_DEFINITION - 1)\r
+ continue;\r
+ int id = GetID(name);\r
+ if (id < 0) {\r
+ if (m_NumOfDefs == MAX_FUNCTION || CheckOverride(name))\r
+ continue;\r
+ id = m_NumOfDefs++;\r
+ }\r
+ LPTSTR last = def + _tcslen(def) - 1;\r
+ if (*last == _T('\n'))\r
+ *last-- = 0;\r
+ if (*last == _T(')'))\r
+ *last = 0;\r
+ _tcscpy_s(m_Names[id], name);\r
+ _tcscpy_s(m_StrDefs[id], def);\r
+ }\r
+ fclose(fp);\r
+}\r
+\r
+bool FuncDefs::CheckOverride(LPCTSTR name)\r
+{\r
+ for (int i = 0; i < MAX_COMMAND; i++)\r
+ if (!_tcscmp(name, CmdTable::Name(i)))\r
+ return true;\r
+ return false;\r
+}\r
+\r
+static const struct {\r
+ LPCTSTR name;\r
+ int id;\r
+} Modifiers[] = {\r
+// { _T("A-"), ALT },\r
+ { _T("C-"), CONTROL},\r
+// { _T("H-"), HYPER },\r
+ { _T("M-"), META },\r
+ { _T("S-"), SHIFT },\r
+// { _T("s-"), SUPER },\r
+ { _T("Ctrl+"), WIN_CTRL },\r
+ { _T("Alt+"), WIN_ALT },\r
+ { _T("Win+"), WIN_WIN },\r
+};\r
+static const int MAX_MODIFIER = _countof(Modifiers);\r
+\r
+static const struct {\r
+ BYTE bVk;\r
+ LPCTSTR name;\r
+} KeyNames[] = {\r
+// { VK_LBUTTON, _T("mouse-1") }, // does not work well\r
+// { VK_RBUTTON, _T("mouse-3") }, // does not work well\r
+ { VK_CANCEL, _T("break") },\r
+// { VK_MBUTTON, _T("mouse-2") }, // does not work well\r
+ { VK_BACK, _T("backspace") },\r
+ { VK_TAB, _T("tab") },\r
+ { VK_RETURN, _T("return") },\r
+ { VK_CAPITAL, _T("capslock") },\r
+ { VK_KANA, _T("kana") },\r
+ { VK_KANJI, _T("kanji") },\r
+ { VK_ESCAPE, _T("escape") },\r
+ { VK_CONVERT, _T("convert") },\r
+ { VK_NONCONVERT, _T("nonconvert") },\r
+// { VK_SPACE, _T("SPC") }, // [? ]\r
+ { VK_PRIOR, _T("prior") },\r
+ { VK_NEXT, _T("next") },\r
+ { VK_END, _T("end") },\r
+ { VK_HOME, _T("home") },\r
+ { VK_LEFT, _T("left") },\r
+ { VK_UP, _T("up") },\r
+ { VK_RIGHT, _T("right") },\r
+ { VK_DOWN, _T("down") },\r
+ { VK_SELECT, _T("select") },\r
+ { VK_PRINT, _T("print") },\r
+ { VK_EXECUTE, _T("execute") },\r
+ { VK_SNAPSHOT, _T("printscreen") }, // work as print\r
+ { VK_INSERT, _T("insert") },\r
+ { VK_DELETE, _T("delete") },\r
+ { VK_LWIN, _T("lwindow") },\r
+ { VK_RWIN, _T("rwindow") },\r
+ { VK_APPS, _T("apps") },\r
+ { VK_SLEEP, _T("sleep") },\r
+ { VK_NUMPAD0, _T("kp-0") },\r
+ { VK_NUMPAD1, _T("kp-1") },\r
+ { VK_NUMPAD2, _T("kp-2") },\r
+ { VK_NUMPAD3, _T("kp-3") },\r
+ { VK_NUMPAD4, _T("kp-4") },\r
+ { VK_NUMPAD5, _T("kp-5") },\r
+ { VK_NUMPAD6, _T("kp-6") },\r
+ { VK_NUMPAD7, _T("kp-7") },\r
+ { VK_NUMPAD8, _T("kp-8") },\r
+ { VK_NUMPAD9, _T("kp-9") },\r
+ { VK_MULTIPLY, _T("kp-multiply") },\r
+ { VK_ADD, _T("kp-add") },\r
+ { VK_SUBTRACT, _T("kp-subtract") },\r
+ { VK_DECIMAL, _T("kp-decimal") },\r
+ { VK_DIVIDE, _T("kp-divide") },\r
+// { VK_F1, _T("f1") }, // FIXME\r
+// { VK_F2, _T("f2") }, // Move at the end of definition of function keys to keep away confliction f1/f2 and f1?/f2? by _tcsncmp() i.e. strncmp()\r
+ { VK_F3, _T("f3") },\r
+ { VK_F4, _T("f4") },\r
+ { VK_F5, _T("f5") },\r
+ { VK_F6, _T("f6") },\r
+ { VK_F7, _T("f7") },\r
+ { VK_F8, _T("f8") },\r
+ { VK_F9, _T("f9") },\r
+ { VK_F10, _T("f10") },\r
+ { VK_F11, _T("f11") },\r
+ { VK_F12, _T("f12") },\r
+ { VK_F13, _T("f13") },\r
+ { VK_F14, _T("f14") },\r
+ { VK_F15, _T("f15") },\r
+ { VK_F16, _T("f16") },\r
+ { VK_F17, _T("f17") },\r
+ { VK_F18, _T("f18") },\r
+ { VK_F19, _T("f19") },\r
+ { VK_F20, _T("f20") },\r
+ { VK_F21, _T("f21") },\r
+ { VK_F22, _T("f22") },\r
+ { VK_F23, _T("f23") },\r
+ { VK_F24, _T("f24") },\r
+ { VK_F1, _T("f1") },\r
+ { VK_F2, _T("f2") },\r
+ { VK_NUMLOCK, _T("kp-numlock") },\r
+ { VK_SCROLL, _T("scroll") },\r
+ { 0xa6, _T("browser-back") }, // VK_BROWSER_BACK\r
+ { 0xa7, _T("browser-forward") }, // VK_BROWSER_FORWARD\r
+ { 0xa8, _T("browser-refresh") }, // VK_BROWSER_REFRESH\r
+ { 0xa9, _T("browser-stop") }, // VK_BROWSER_STOP\r
+ { 0xaa, _T("browser-search") }, // VK_BROWSER_SEARCH\r
+ { 0xab, _T("browser-favorites") }, // VK_BROWSER_FAVORITES\r
+ { 0xac, _T("browser-home") }, // VK_BROWSER_HOME\r
+ { 0xad, _T("volume-mute") }, // VK_VOLUME_MUTE\r
+ { 0xae, _T("volume-down") }, // VK_VOLUME_DOWN\r
+ { 0xaf, _T("volume-up") }, // VK_VOLUME_UP\r
+ { 0xb0, _T("media-next-track") }, // VK_MEDIA_NEXT_TRACK\r
+ { 0xb1, _T("media-prev-track") }, // VK_MEDIA_PREV_TRACK\r
+ { 0xb2, _T("media-stop") }, // VK_MEDIA_STOP\r
+ { 0xb3, _T("media-play-pause") }, // VK_MEDIA_PLAY_PAUSE\r
+ { 0xb4, _T("launch-mail") }, // VK_LAUNCH_MAIL\r
+ { 0xb5, _T("launch-media-select") }, // VK_LAUNCH_MEDIA_SELECT\r
+ { 0xb6, _T("launch-1") }, // VK_LAUNCH_APP1\r
+ { 0xb7, _T("launch-2") }, // VK_LAUNCH_APP2\r
+};\r
+static const int MAX_KEYNAME = _countof(KeyNames);\r
+\r
+void FuncDefs::ParseDefs()\r
+{\r
+ for (int i = 0; i < m_NumOfDefs; i++) {\r
+ LPCTSTR def = m_StrDefs[i];\r
+ KeyBind *p = m_Defs[i];\r
+ LPCTSTR last = def + _tcslen(def) - 1;\r
+ if (*def == _T('"') && *last == _T('"')) {\r
+ ++def; // skip '"'\r
+ while (def < last)\r
+ *p++ = ParseKey(def);\r
+ } else if (*def == _T('[') && *last == _T(']')) {\r
+ while (++def < last) { // skip '[', ']', and ' '\r
+ if (*def == _T('?')) { // [?f ?o ?o]\r
+ *p++ = ParseKey(++def);\r
+ continue;\r
+ }\r
+ // [VK]\r
+ for (int i = 0; i < MAX_KEYNAME; ++i) {\r
+ size_t keylen = _tcslen(KeyNames[i].name);\r
+ if (!_tcsncmp(def, KeyNames[i].name, keylen)) {\r
+ KeyBind keybind = {NONE, KeyNames[i].bVk};\r
+ *p++ = keybind;\r
+ def += keylen;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+KeyBind FuncDefs::ParseKey(LPCTSTR& def)\r
+{\r
+ KeyBind keybind = {NONE};\r
+ if (*def == _T('\\')) { // set modifiers\r
+ ++def;\r
+ LOOP:\r
+ for (int i = 0; i < MAX_MODIFIER; ++i) {\r
+ size_t len = _tcslen(Modifiers[i].name);\r
+ if (!_tcsncmp(def, Modifiers[i].name, len)) {\r
+ keybind.nType |= Modifiers[i].id;\r
+ def += len;\r
+ goto LOOP;\r
+ }\r
+ }\r
+ }\r
+ int i = 0;\r
+ for (; i < MAX_KEYNAME; ++i) {\r
+ size_t len = _tcslen(KeyNames[i].name);\r
+ if (!_tcsncmp(def, KeyNames[i].name, len)) {\r
+ def += len;\r
+ break;\r
+ }\r
+ }\r
+ if (i < MAX_KEYNAME) {\r
+ keybind.bVk = KeyNames[i].bVk;\r
+ return keybind;\r
+ }\r
+ SHORT r = CXkeymacsDll::ConvVkey(*def++, 0);\r
+ if (r & (1 << 8) && !(keybind.nType & (WIN_CTRL | WIN_ALT | WIN_WIN)))\r
+ keybind.nType |= SHIFT;\r
+ keybind.bVk = static_cast<BYTE>(r);\r
+ return keybind;\r
+}\r
--- /dev/null
+#pragma once\r
+#include "../xkeymacsdll/defs.h"\r
+\r
+class FuncDefs\r
+{\r
+public:\r
+ static void Load();\r
+ static int GetID(LPCTSTR name);\r
+ static LPCTSTR GetName(int id);\r
+ static int GetNumOfDefs();\r
+ static LPCTSTR GetStrDef(int id);\r
+ static KeyBind (*GetDefs())[MAX_DEFINITION];\r
+private:\r
+ static int m_NumOfDefs;\r
+ static TCHAR m_Names[MAX_FUNCTION][SUB_KEY_NAME_LENGTH];\r
+ static TCHAR m_StrDefs[MAX_FUNCTION][MAX_DEFINITION];\r
+ static KeyBind m_Defs[MAX_FUNCTION][MAX_DEFINITION];\r
+ static void Clear();\r
+ static void LoadFiles();\r
+ static void MoveOldFile(LPCTSTR drive, LPCTSTR dir, LPCTSTR fname, LPCTSTR ext);\r
+ static void LoadFile(LPCTSTR file);\r
+ static bool CheckOverride(LPCTSTR name);\r
+ static void ParseDefs();\r
+ static KeyBind ParseKey(LPCTSTR& def);\r
+};\r
+\r
+++ /dev/null
-// DotXkeymacs.cpp: implementation of the CDotXkeymacs class.\r
-//\r
-//////////////////////////////////////////////////////////////////////\r
-\r
-#include "dotxkeymacs.h"\r
-#include "resource.h"\r
-#include "../xkeymacsdll/FunctionDefinition.h"\r
-#include <Shlobj.h>\r
-#include <Shlwapi.h>\r
-\r
-#ifdef _DEBUG\r
-#undef THIS_FILE\r
-static char THIS_FILE[]=__FILE__;\r
-#define new DEBUG_NEW\r
-#endif\r
-\r
-struct Language\r
-{\r
- WORD wLanguage;\r
- LPCTSTR szLanguage;\r
-};\r
-\r
-static const Language Languages[] = {\r
- { 0x0001, _T("Arabic") },\r
- { 0x0004, _T("Chinese") },\r
- { 0x0009, _T("English") },\r
- { 0x0401, _T("Arabic (Saudi Arabia)") },\r
- { 0x0402, _T("Bulgarian") },\r
- { 0x0403, _T("Catalan") },\r
- { 0x0404, _T("Chinese (Taiwan)") },\r
- { 0x0405, _T("Czech") },\r
- { 0x0406, _T("Danish") },\r
- { 0x0407, _T("German (Germany)") },\r
- { 0x0408, _T("Greek") },\r
- { 0x0409, _T("English (United States)") },\r
- { 0x040A, _T("Spanish (Traditional Sort)") },\r
- { 0x040B, _T("Finnish") },\r
- { 0x040C, _T("French (France)") },\r
- { 0x040D, _T("Hebrew") },\r
- { 0x040E, _T("Hungarian") },\r
- { 0x040F, _T("Icelandic") },\r
- { 0x0410, _T("Italian (Italy)") },\r
- { 0x0411, _T("Japanese") },\r
- { 0x0412, _T("Korean") },\r
- { 0x0413, _T("Dutch (Netherlands)") },\r
- { 0x0414, _T("Norwegian (Bokmal)") },\r
- { 0x0415, _T("Polish") },\r
- { 0x0416, _T("Portuguese (Brazil)") },\r
- { 0x0417, _T("Rhaeto-Romanic") },\r
- { 0x0418, _T("Romanian") },\r
- { 0x0419, _T("Russian") },\r
- { 0x041A, _T("Croatian") },\r
- { 0x041B, _T("Slovak") },\r
- { 0x041C, _T("Albanian") },\r
- { 0x041D, _T("Swedish") },\r
- { 0x041E, _T("Thai") },\r
- { 0x041F, _T("Turkish") },\r
- { 0x0420, _T("Urdu") },\r
- { 0x0421, _T("Indonesian") },\r
- { 0x0422, _T("Ukrainian") },\r
- { 0x0423, _T("Belarusian") },\r
- { 0x0424, _T("Slovenian") },\r
- { 0x0425, _T("Estonian") },\r
- { 0x0426, _T("Latvian") },\r
- { 0x0427, _T("Lithuanian") },\r
- { 0x0428, _T("Tajik") },\r
- { 0x0429, _T("Farsi") },\r
- { 0x042A, _T("Vietnamese") },\r
- { 0x042B, _T("Armenian") },\r
- { 0x042C, _T("Azeri (Latin)") },\r
- { 0x042D, _T("Basque") },\r
- { 0x042E, _T("Sorbian") },\r
- { 0x042F, _T("Macedonian (FYROM)") },\r
- { 0x0430, _T("Sutu") },\r
- { 0x0431, _T("Tsonga") },\r
- { 0x0432, _T("Tswana") },\r
- { 0x0434, _T("Xhosa") },\r
- { 0x0435, _T("Zulu") },\r
- { 0x0436, _T("Afrikaans") },\r
- { 0x0437, _T("Georgian") },\r
- { 0x0438, _T("Faeroese") },\r
- { 0x0439, _T("Hindi") },\r
- { 0x043A, _T("Maltese") },\r
- { 0x043C, _T("Gaelic") },\r
- { 0x043D, _T("Yiddish") },\r
- { 0x043E, _T("Malay (Malaysia)") },\r
- { 0x043F, _T("Kazakh") },\r
- { 0x0440, _T("Kyrgyz") },\r
- { 0x0441, _T("Swahili") },\r
- { 0x0442, _T("Turkmen") },\r
- { 0x0443, _T("Uzbek (Latin)") },\r
- { 0x0444, _T("Tatar") },\r
- { 0x0445, _T("Bengali") },\r
- { 0x0446, _T("Punjabi") },\r
- { 0x0447, _T("Gujarati") },\r
- { 0x0448, _T("Oriya") },\r
- { 0x0449, _T("Tamil") },\r
- { 0x044A, _T("Telugu") },\r
- { 0x044B, _T("Kannada") },\r
- { 0x044C, _T("Malayalam") },\r
- { 0x044D, _T("Assamese") },\r
- { 0x044E, _T("Marathi") },\r
- { 0x044F, _T("Sanskrit") },\r
- { 0x0450, _T("Mongolian") },\r
- { 0x0456, _T("Galician") },\r
- { 0x0457, _T("Konkani") },\r
- { 0x0458, _T("Manipuri") },\r
- { 0x0459, _T("Sindhi") },\r
- { 0x045A, _T("Syriac") },\r
- { 0x045B, _T("Sinhalese") },\r
- { 0x045C, _T("Cherokee") },\r
- { 0x045D, _T("Inuktitut") },\r
- { 0x045E, _T("Amharic") },\r
- { 0x045F, _T("Tamazight (Berber/Arabic)") },\r
- { 0x0460, _T("Kashmiri (Arabic)") },\r
- { 0x0461, _T("Nepali") },\r
- { 0x0462, _T("Frisian") },\r
- { 0x0463, _T("Pashto") },\r
- { 0x0464, _T("Filipino") },\r
- { 0x0465, _T("Dhivehi") },\r
- { 0x0466, _T("Edo") },\r
- { 0x0467, _T("Fulfulde") },\r
- { 0x0468, _T("Hausa") },\r
- { 0x0469, _T("Ibibio") },\r
- { 0x046A, _T("Yoruba") },\r
- { 0x0470, _T("Igbo") },\r
- { 0x0471, _T("Kanuri") },\r
- { 0x0472, _T("Oromo") },\r
- { 0x0473, _T("Tigrigna (Ethiopia)") },\r
- { 0x0475, _T("Hawaiian") },\r
- { 0x0476, _T("Latin") },\r
- { 0x0477, _T("Somali") },\r
- { 0x0478, _T("Yi") },\r
- { 0x0801, _T("Arabic (Iraq)") },\r
- { 0x0804, _T("Chinese (PRC)") },\r
- { 0x0807, _T("German (Switzerland)") },\r
- { 0x0809, _T("English (United Kingdom)") },\r
- { 0x080A, _T("Spanish (Mexico)") },\r
- { 0x080C, _T("French (Belgium)") },\r
- { 0x0810, _T("Italian (Switzerland)") },\r
- { 0x0813, _T("Dutch (Belgium)") },\r
- { 0x0814, _T("Norwegian (Nynorsk)") },\r
- { 0x0816, _T("Portuguese (Portugal)") },\r
- { 0x0818, _T("Romanian (Moldova)") },\r
- { 0x0819, _T("Russian (Moldova)") },\r
- { 0x081A, _T("Serbian (Latin)") },\r
- { 0x081D, _T("Swedish (Finland)") },\r
- { 0x082C, _T("Azeri (Cyrillic)") },\r
- { 0x0843, _T("Uzbek (Cyrillic)") },\r
- { 0x085F, _T("Tamazight (Latin)") },\r
- { 0x0873, _T("Tigrigna (Eritrea)") },\r
- { 0x0C01, _T("Arabic (Egypt)") },\r
- { 0x0C04, _T("Chinese (Hong Kong SAR)") },\r
- { 0x0C07, _T("German (Austria)") },\r
- { 0x0C09, _T("English (Australia)") },\r
- { 0x0C0A, _T("Spanish (International Sort)") },\r
- { 0x0C0C, _T("French (Canada)") },\r
- { 0x0C1A, _T("Serbian (Cyrillic)") },\r
- { 0x1001, _T("Arabic (Libya)") },\r
- { 0x1004, _T("Chinese (Singapore)") },\r
- { 0x1007, _T("German (Luxembourg)") },\r
- { 0x1009, _T("English (Canada)") },\r
- { 0x100A, _T("Spanish (Guatemala)") },\r
- { 0x100C, _T("French (Switzerland)") },\r
- { 0x1401, _T("Arabic (Algeria)") },\r
- { 0x1407, _T("German (Liechtenstein)") },\r
- { 0x1409, _T("English (New Zealand)") },\r
- { 0x140A, _T("Spanish (Costa Rica)") },\r
- { 0x140C, _T("French (Luxembourg)") },\r
- { 0x1801, _T("Arabic (Morocco)") },\r
- { 0x1809, _T("English (Ireland)") },\r
- { 0x180A, _T("Spanish (Panama)") },\r
- { 0x1C01, _T("Arabic (Tunisia)") },\r
- { 0x1C09, _T("English (South Africa)") },\r
- { 0x1C0A, _T("Spanish (Dominican Republic)") },\r
- { 0x2001, _T("Arabic (Oman)") },\r
- { 0x2009, _T("English (Jamaica)") },\r
- { 0x200A, _T("Spanish (Venezuela)") },\r
- { 0x2401, _T("Arabic (Yemen)") },\r
- { 0x240A, _T("Spanish (Colombia)") },\r
- { 0x2801, _T("Arabic (Syria)") },\r
- { 0x2809, _T("English (Belize)") },\r
- { 0x280A, _T("Spanish (Peru)") },\r
- { 0x2C01, _T("Arabic (Jordan)") },\r
- { 0x2C09, _T("English (Trinidad)") },\r
- { 0x2C0A, _T("Spanish (Argentina)") },\r
- { 0x3001, _T("Arabic (Lebanon)") },\r
- { 0x300A, _T("Spanish (Ecuador)") },\r
- { 0x3401, _T("Arabic (Kuwait)") },\r
- { 0x340A, _T("Spanish (Chile)") },\r
- { 0x3801, _T("Arabic (U.A.E.)") },\r
- { 0x380A, _T("Spanish (Uruguay)") },\r
- { 0x3C01, _T("Arabic (Bahrain)") },\r
- { 0x3C0A, _T("Spanish (Paraguay)") },\r
- { 0x4001, _T("Arabic (Qatar)") },\r
- { 0x400A, _T("Spanish (Bolivia)") },\r
- { 0x440A, _T("Spanish (El Salvador)") },\r
- { 0x480A, _T("Spanish (Honduras)") },\r
- { 0x4C0A, _T("Spanish (Nicaragua)") },\r
- { 0x500A, _T("Spanish (Puerto Rico)") },\r
-};\r
- \r
-CObList CDotXkeymacs::m_oFunctionDefinition;\r
-int CDotXkeymacs::m_nIndex[MAX_APP][MAX_COMMAND_TYPE][MAX_KEY] = {'\0'};\r
-const TCHAR CDotXkeymacs::m_szExt[] = _T("xkeymacs");\r
-\r
-void CDotXkeymacs::Load(LPCTSTR lpszFileName)\r
-{\r
- CStdioFile oDotXkeymacs;\r
- if (oDotXkeymacs.Open(lpszFileName, CFile::modeRead | CFile::shareDenyWrite | CFile::typeText)) {\r
- CString szRead;\r
- while (oDotXkeymacs.ReadString(szRead)) {\r
- if (IsFunctionDefinition(szRead)) {\r
- CFunctionDefinition *pFunctionDefinition = new CFunctionDefinition(GetSymbol(szRead), GetDefinition(szRead));\r
-\r
- // Delete a listed definition which has the same symbol as a new one.\r
- for (POSITION currentPos, pos = m_oFunctionDefinition.GetHeadPosition(); (currentPos = pos) != NULL; ) {\r
- CFunctionDefinition *pCurrentDefinition = (CFunctionDefinition *)m_oFunctionDefinition.GetNext(pos);\r
-\r
- if (pCurrentDefinition->GetSymbol() == pFunctionDefinition->GetSymbol()) {\r
- CFunctionDefinition *pOverwritten = (CFunctionDefinition *)m_oFunctionDefinition.GetAt(currentPos);\r
- m_oFunctionDefinition.RemoveAt(currentPos);\r
- delete pOverwritten;\r
- }\r
- }\r
-\r
- m_oFunctionDefinition.AddTail((CObject *)pFunctionDefinition);\r
- }\r
- }\r
- }\r
-}\r
-\r
-void CDotXkeymacs::LoadMainData(LPCTSTR lpszFileName)\r
-{\r
- TCHAR szModuleFileName[MAX_PATH] = {'\0'};\r
- TCHAR szDrive[_MAX_DRIVE] = {'\0'};\r
- TCHAR szDir[_MAX_DIR] = {'\0'};\r
-\r
- if (GetModuleFileName(NULL, szModuleFileName, sizeof(szModuleFileName))) {\r
- _tsplitpath_s(szModuleFileName, szDrive, _MAX_DRIVE, szDir, _MAX_DIR, NULL, 0, NULL, 0);\r
- }\r
-\r
- TCHAR szOldPath[MAX_PATH] = {'\0'}; // This path is used by XKeymacs 3.22 and earlier\r
- _tmakepath_s(szOldPath, szDrive, szDir, lpszFileName, m_szExt);\r
-\r
- PathAppend(szDir, _T("etc"));\r
- TCHAR szPath[MAX_PATH] = {'\0'};\r
- _tmakepath_s(szPath, szDrive, szDir, lpszFileName, m_szExt);\r
-\r
- if (_trename(szOldPath, szPath)) { // try to move old file as backup when rename returns an error because files exist in both directorys\r
- TCHAR szBackupPath[MAX_PATH] = {'\0'};\r
- TCHAR szBackupFlag[_MAX_FNAME] = _T("~");\r
- _tcscat_s(szBackupFlag, lpszFileName);\r
- _tmakepath_s(szBackupPath, szDrive, szDir, szBackupFlag, m_szExt);\r
- (void)_trename(szOldPath, szBackupPath); // do nothing when a backup file has existed already\r
- }\r
-\r
- Load(szPath);\r
-}\r
-\r
-void CDotXkeymacs::LoadUserData(LPCTSTR lpszFileName)\r
-{\r
- TCHAR szPath[MAX_PATH] = {'\0'};\r
- if (SHGetSpecialFolderPath(NULL, szPath, CSIDL_APPDATA, TRUE)) {\r
- _tmakepath_s(szPath, NULL, szPath, lpszFileName, m_szExt);\r
- Load(szPath);\r
- }\r
-}\r
-\r
-void CDotXkeymacs::Load()\r
-{\r
- static LPCTSTR szFileName = _T("dot");\r
-\r
- ClearFunctionDefinition();\r
- LoadMainData(GetLanguage()); // just for localization\r
- LoadMainData(szFileName);\r
- LoadUserData(szFileName); // overwrite main data\r
-}\r
-\r
-BOOL CDotXkeymacs::IsFunctionDefinition(CString szFunctionDefinition)\r
-{\r
- return !_tcsncmp(szFunctionDefinition, CString(MAKEINTRESOURCE(IDS_FSET)), _tcslen(CString(MAKEINTRESOURCE(IDS_FSET))));\r
-}\r
-\r
-CString CDotXkeymacs::GetSymbol(CString szFunctionDefinition)\r
-{\r
- const int nFirst = _tcslen(CString(MAKEINTRESOURCE(IDS_FSET))) + _tcslen(_T("'"));\r
- return szFunctionDefinition.Mid(nFirst, szFunctionDefinition.Find(_T(' '), nFirst) - nFirst);\r
-}\r
-\r
-CString CDotXkeymacs::GetDefinition(CString szFunctionDefinition)\r
-{\r
- const int nFirst = szFunctionDefinition.Find(_T(' '), _tcslen(CString(MAKEINTRESOURCE(IDS_FSET)))) + _tcslen(_T("'"));\r
- return szFunctionDefinition.Mid(nFirst, szFunctionDefinition.GetLength() - nFirst - _tcslen(_T(")")));\r
-}\r
-\r
-void CDotXkeymacs::ClearFunctionDefinition()\r
-{\r
- while (!m_oFunctionDefinition.IsEmpty()) {\r
- CFunctionDefinition *pFunctionDefinition = (CFunctionDefinition *)m_oFunctionDefinition.GetHead();\r
- delete pFunctionDefinition;\r
- pFunctionDefinition = NULL;\r
- m_oFunctionDefinition.RemoveHead();\r
- }\r
- memset(m_nIndex, -1, sizeof(m_nIndex));\r
-}\r
-\r
-int CDotXkeymacs::GetFunctionNumber()\r
-{\r
- return m_oFunctionDefinition.GetCount();\r
-}\r
-\r
-CString CDotXkeymacs::GetFunctionSymbol(int nIndex)\r
-{\r
- if (nIndex < 0 || m_oFunctionDefinition.GetCount() <= nIndex) {\r
- return CString();\r
- }\r
-\r
- if (CFunctionDefinition *pFunctionDefinition = (CFunctionDefinition *)m_oFunctionDefinition.GetAt(m_oFunctionDefinition.FindIndex(nIndex))) {\r
- return pFunctionDefinition->GetSymbol();\r
- }\r
- return CString();\r
-}\r
-\r
-CString CDotXkeymacs::GetFunctionDefinition(int nIndex)\r
-{\r
- if (nIndex < 0 || m_oFunctionDefinition.GetCount() <= nIndex) {\r
- return CString();\r
- }\r
-\r
- if (CFunctionDefinition *pFunctionDefinition = (CFunctionDefinition *)m_oFunctionDefinition.GetAt(m_oFunctionDefinition.FindIndex(nIndex))) {\r
- return pFunctionDefinition->GetDefinition();\r
- }\r
- return CString();\r
-}\r
-\r
-CString CDotXkeymacs::GetFunctionDefinition(CString szSymbol)\r
-{\r
- for (POSITION pos = m_oFunctionDefinition.GetHeadPosition(); pos;) {\r
- CFunctionDefinition *pFunctionDefinition = (CFunctionDefinition *)m_oFunctionDefinition.GetNext(pos);\r
- if (!pFunctionDefinition->GetSymbol().Compare(szSymbol)) {\r
- return pFunctionDefinition->GetDefinition();\r
- }\r
- }\r
-\r
- return CString(_T("Undefined Command"));\r
-}\r
-\r
-void CDotXkeymacs::ClearKey(int nIndex, int nAppID)\r
-{\r
- if (nIndex < 0 || m_oFunctionDefinition.GetCount() <= nIndex) {\r
- return;\r
- }\r
-\r
- if (CFunctionDefinition *pFunctionDefinition = (CFunctionDefinition *)m_oFunctionDefinition.GetAt(m_oFunctionDefinition.FindIndex(nIndex))) {\r
- pFunctionDefinition->ClearKey(nAppID);\r
- }\r
-\r
- for (int nType = 0; nType < MAX_COMMAND_TYPE; ++nType) {\r
- for (int nKey = 0; nKey < MAX_KEY; ++nKey) {\r
- if (m_nIndex[nAppID][nType][nKey] == nIndex) {\r
- m_nIndex[nAppID][nType][nKey] = -1;\r
- }\r
- }\r
- }\r
-}\r
-\r
-void CDotXkeymacs::SetKey(int nIndex, int nAppID, int nType, int nKey)\r
-{\r
- if (nIndex < 0 || m_oFunctionDefinition.GetCount() <= nIndex) {\r
- return;\r
- }\r
-\r
- if (CFunctionDefinition *pFunctionDefinition = (CFunctionDefinition *)m_oFunctionDefinition.GetAt(m_oFunctionDefinition.FindIndex(nIndex))) {\r
- pFunctionDefinition->SetKey(nAppID, nType, nKey);\r
- m_nIndex[nAppID][nType][nKey] = nIndex;\r
- }\r
-}\r
-\r
-int CDotXkeymacs::GetIndex(CString szSymbol)\r
-{\r
- int nIndex = 0;\r
- for (nIndex = 0; nIndex < m_oFunctionDefinition.GetCount(); ++nIndex) {\r
- CFunctionDefinition *pFunctionDefinition = (CFunctionDefinition *)m_oFunctionDefinition.GetAt(m_oFunctionDefinition.FindIndex(nIndex));\r
- if (!pFunctionDefinition->GetSymbol().Compare(szSymbol)) {\r
- return nIndex;\r
- }\r
- }\r
- return -1;\r
-}\r
-\r
-int CDotXkeymacs::GetKeyNumber(int nIndex, int nAppID)\r
-{\r
- if (nIndex < 0 || m_oFunctionDefinition.GetCount() <= nIndex) {\r
- return 0;\r
- }\r
-\r
- CFunctionDefinition *pFunctionDefinition = (CFunctionDefinition *)m_oFunctionDefinition.GetAt(m_oFunctionDefinition.FindIndex(nIndex));\r
- return pFunctionDefinition->GetKeyNumber(nAppID);\r
-}\r
-\r
-void CDotXkeymacs::GetKey(int nIndex, int nAppID, int nKeyID, int *pCommandType, int *pKey)\r
-{\r
- if (nIndex < 0 || m_oFunctionDefinition.GetCount() <= nIndex) {\r
- return;\r
- }\r
-\r
- CFunctionDefinition *pFunctionDefinition = (CFunctionDefinition *)m_oFunctionDefinition.GetAt(m_oFunctionDefinition.FindIndex(nIndex));\r
- pFunctionDefinition->GetKey(nAppID, nKeyID, pCommandType, pKey);\r
-}\r
-\r
-int CDotXkeymacs::GetIndex(int nAppID, int nType, int nKey)\r
-{\r
- return m_nIndex[nAppID][nType][nKey];\r
-}\r
-\r
-void CDotXkeymacs::RemoveKey(const int nIndex, const int nAppID, const int nType, const int nKey)\r
-{\r
- if (nIndex < 0 || m_oFunctionDefinition.GetCount() <= nIndex) {\r
- return;\r
- }\r
-\r
- CFunctionDefinition *pFunctionDefinition = (CFunctionDefinition *)m_oFunctionDefinition.GetAt(m_oFunctionDefinition.FindIndex(nIndex));\r
- if (pFunctionDefinition) {\r
- pFunctionDefinition->RemoveKey(nAppID, nType, nKey);\r
- }\r
-}\r
-\r
-void CDotXkeymacs::RemoveKey(const int nAppID, const int nType, const int nKey)\r
-{\r
- for (int nIndex = 0; nIndex < m_oFunctionDefinition.GetCount(); ++nIndex) {\r
- RemoveKey(nIndex, nAppID, nType, nKey);\r
- }\r
-}\r
-\r
-LPCTSTR CDotXkeymacs::GetLanguage()\r
-{\r
- LPCTSTR szLanguage = _T("unknown");\r
-\r
- TCHAR lptstrFilename[MAX_PATH] = {'\0'};\r
- TCHAR windir[MAX_PATH] = "";\r
- size_t len;\r
- _tgetenv_s(&len, windir, _T("windir"));\r
- _tmakepath_s(lptstrFilename, NULL, windir, _T("explorer"), _T("exe"));\r
- DWORD dwLen = GetFileVersionInfoSize(lptstrFilename, NULL);\r
-\r
- if (dwLen) {\r
- LPVOID lpData = malloc(dwLen);\r
-\r
- if (lpData && GetFileVersionInfo(lptstrFilename, NULL, dwLen, lpData)) {\r
- struct Translate {\r
- WORD wLanguage;\r
- WORD wCodePage;\r
- } *lpTranslate;\r
- UINT cbTranslate = 0;\r
-\r
- if (VerQueryValue(lpData, _T("\\VarFileInfo\\Translation"), (LPVOID*)&lpTranslate, &cbTranslate) && sizeof(Translate) <= cbTranslate) {\r
- for (int i = 0; i < _countof(Languages); ++i) {\r
- if (Languages[i].wLanguage == lpTranslate->wLanguage) {\r
- szLanguage = Languages[i].szLanguage;\r
- break;\r
- }\r
- }\r
- }\r
- }\r
-\r
- free(lpData);\r
- }\r
-\r
- return szLanguage;\r
-}\r
+++ /dev/null
-// DotXkeymacs.h: interface for the CDotXkeymacs class.\r
-//\r
-//////////////////////////////////////////////////////////////////////\r
-\r
-#if !defined(AFX_DOTXKEYMACS_H__0538C427_5733_47DA_B2C6_2E957EEFC59D__INCLUDED_)\r
-#define AFX_DOTXKEYMACS_H__0538C427_5733_47DA_B2C6_2E957EEFC59D__INCLUDED_\r
-\r
-#if _MSC_VER > 1000\r
-#pragma once\r
-#endif // _MSC_VER > 1000\r
-\r
-#include "../xkeymacsdll/defs.h"\r
-\r
-class CDotXkeymacs \r
-{\r
-public:\r
- static void RemoveKey(const int nAppID, const int nType, const int nKey);\r
- static void RemoveKey(const int nIndex, const int nAppID, const int nType, const int nKey);\r
- static CString GetFunctionDefinition(int nIndex);\r
- static int GetIndex(int nAppID, int nType, int nKey);\r
- static void GetKey(int nIndex, int nAppID, int nKeyID, int *pCommandType, int *pKey);\r
- static int GetKeyNumber(int nIndex, int nAppID);\r
- static int GetIndex(CString szSymbol);\r
- static void SetKey(int nIndex, int nAppID, int nType, int nKey);\r
- static void ClearKey(int nIndex, int nAppID);\r
- static CString GetFunctionDefinition(CString szSymbol);\r
- static CString GetFunctionSymbol(int nIndex);\r
- static int GetFunctionNumber();\r
- static void Load();\r
-\r
-private:\r
- static LPCTSTR GetLanguage();\r
- static const TCHAR m_szExt[];\r
- static int m_nIndex[MAX_APP][MAX_COMMAND_TYPE][MAX_KEY];\r
- static void ClearFunctionDefinition();\r
- static CString GetDefinition(CString szFunctionDefinition);\r
- static CString GetSymbol(CString szFunctionDefinition);\r
- static BOOL IsFunctionDefinition(CString szFunctionDefinition);\r
- static CObList m_oFunctionDefinition;\r
- static void LoadUserData(LPCTSTR lpszFileName);\r
- static void LoadMainData(LPCTSTR lpszFileName);\r
- static void Load(LPCTSTR lpszFileName);\r
-};\r
-\r
-#endif // !defined(AFX_DOTXKEYMACS_H__0538C427_5733_47DA_B2C6_2E957EEFC59D__INCLUDED_)\r
\r
#include "profile.h"\r
#include "xkeymacs.h"\r
-#include "dotxkeymacs.h"\r
+#include "FuncDefs.h"\r
#include "mainfrm.h"\r
#include "../xkeymacsdll/xkeymacsdll.h"\r
#include "../xkeymacsdll/Utils.h"\r
\r
void CProfile::LoadData()\r
{\r
- CDotXkeymacs::Load();\r
+ FuncDefs::Load();\r
LevelUp();\r
LoadRegistry();\r
}\r
// fall through\r
case 3:\r
// rename original function to remove IDS_REG_ORIGINAL_PREFIX\r
- for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID) {\r
+ for (int nFuncID = 0; nFuncID < FuncDefs::GetNumOfDefs(); ++nFuncID) {\r
HKEY hKey = NULL;\r
- const CString subKey = CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)) + _T("\\") + appName + _T("\\") + CString(MAKEINTRESOURCE(IDS_REG_ORIGINAL_PREFIX)) + CDotXkeymacs::GetFunctionSymbol(nFuncID);\r
+ const CString subKey = CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)) + _T("\\") + appName + _T("\\") + CString(MAKEINTRESOURCE(IDS_REG_ORIGINAL_PREFIX)) + FuncDefs::GetName(nFuncID);\r
if (RegOpenKeyEx(HKEY_CURRENT_USER, subKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {\r
- // Use registry data\r
TCHAR szKeyBind[128];\r
DWORD dwKeyBind = sizeof(szKeyBind);\r
for (DWORD dwIndex = 0; RegEnumKeyEx(hKey, dwIndex, szKeyBind, &dwKeyBind, NULL, NULL, NULL, NULL) == ERROR_SUCCESS; ++dwIndex) {\r
int nType, nKey;\r
StringToKey(szKeyBind, nType, nKey);\r
- SaveKeyBind(appName, CDotXkeymacs::GetFunctionSymbol(nFuncID), nType, nKey);\r
+ SaveKeyBind(appName, FuncDefs::GetName(nFuncID), nType, nKey);\r
dwKeyBind = sizeof(szKeyBind);\r
}\r
RegCloseKey(hKey);\r
}\r
}\r
}\r
- for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID) {\r
+ memset(appConfig.FuncID, -1, sizeof(appConfig.FuncID));\r
+ for (int nFuncID = 0; nFuncID < FuncDefs::GetNumOfDefs(); ++nFuncID) {\r
HKEY hKey;\r
- const CString regKey = regApp + _T("\\") + CDotXkeymacs::GetFunctionSymbol(nFuncID);\r
+ CString regKey = regApp + _T("\\") + FuncDefs::GetName(nFuncID);\r
if (RegOpenKeyEx(HKEY_CURRENT_USER, regKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {\r
- CDotXkeymacs::ClearKey(nFuncID, nAppID);\r
TCHAR szKeyBind[128];\r
DWORD dwKeyBind = _countof(szKeyBind);\r
for (DWORD dwIndex = 0; RegEnumKeyEx(hKey, dwIndex, szKeyBind, &dwKeyBind, NULL, NULL, NULL, NULL) == ERROR_SUCCESS; ++dwIndex) {\r
int nType, nKey;\r
StringToKey(szKeyBind, nType, nKey);\r
- CDotXkeymacs::SetKey(nFuncID, nAppID, nType, nKey);\r
+ appConfig.FuncID[nType][nKey] = static_cast<char>(nFuncID);\r
dwKeyBind = _countof(szKeyBind);\r
}\r
RegCloseKey(hKey);\r
for (int nComID = 1; nComID < MAX_COMMAND; ++nComID)\r
SaveKeyBind(appName, nComID, 0, 0);\r
for (int nType = 0; nType < MAX_COMMAND_TYPE; ++nType)\r
- for (int nKey = 0; nKey < MAX_KEY; ++nKey)\r
+ for (int nKey = 0; nKey < MAX_KEY; ++nKey) {\r
SaveKeyBind(appName, appConfig.CmdID[nType][nKey], nType, nKey);\r
- for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID)\r
- for (int nKeyID = 0; nKeyID < CDotXkeymacs::GetKeyNumber(nFuncID, nAppID); ++nKeyID) {\r
- int nType, nKey;\r
- CDotXkeymacs::GetKey(nFuncID, nAppID, nKeyID, &nType, &nKey);\r
- SaveKeyBind(appName, CDotXkeymacs::GetFunctionSymbol(nFuncID), nType, nKey);\r
+ int id = appConfig.FuncID[nType][nKey];\r
+ if (id >= 0)\r
+ SaveKeyBind(appName, FuncDefs::GetName(id), nType, nKey);\r
}\r
\r
entry.LoadString(IDS_REG_ENTRY_KILL_RING_MAX);\r
\r
void CProfile::SetDllData()\r
{\r
- for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID)\r
- _tcscpy_s(m_Config.FuncDefs[nFuncID], CDotXkeymacs::GetFunctionDefinition(nFuncID));\r
+ memcpy(m_Config.FuncDefs, FuncDefs::GetDefs(), sizeof(m_Config.FuncDefs));\r
for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {\r
AppConfig& appConfig = m_Config.AppConfig[nAppID];\r
appConfig.CmdID[CONTROL]['X'] = 0; // C-x is unassigned.\r
for (int nType = 0; nType < MAX_COMMAND_TYPE; ++nType)\r
for (int nKey = 0; nKey < MAX_KEY; ++nKey)\r
- if ((nType & CONTROLX) && appConfig.CmdID[nType][nKey])\r
- appConfig.CmdID[CONTROL]['X'] = 1; // C-x is available.\r
- memset(appConfig.FuncID, -1, sizeof(appConfig.FuncID));\r
- for (BYTE nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID)\r
- for (int nKeyID = 0; nKeyID < CDotXkeymacs::GetKeyNumber(nFuncID, nAppID); ++nKeyID) {\r
- int nType, nKey;\r
- CDotXkeymacs::GetKey(nFuncID, nAppID, nKeyID, &nType, &nKey);\r
- appConfig.FuncID[nType][nKey] = nFuncID;\r
- if (nType & CONTROLX)\r
+ if ((nType & CONTROLX) && (appConfig.CmdID[nType][nKey] || appConfig.FuncID[nType][nKey] >= 0))\r
appConfig.CmdID[CONTROL]['X'] = 1; // C-x is available.\r
- }\r
}\r
m_Config.Is106Keyboard = Is106Keyboard();\r
CXkeymacsDll::SetConfig(m_Config);\r
m_Config.AppConfig[nAppID].CmdID[nType][nKey] = static_cast<BYTE>(nComID);\r
}\r
\r
+int CProfile::GetFuncID(int nAppID, int nType, int nKey)\r
+{\r
+ return m_Config.AppConfig[nAppID].FuncID[nType][nKey];\r
+}\r
+\r
+void CProfile::SetFuncID(int nAppID, int nType, int nKey, int nFuncID)\r
+{\r
+ m_Config.AppConfig[nAppID].FuncID[nType][nKey] = static_cast<BYTE>(nFuncID);\r
+}\r
+\r
bool CProfile::GetUseDialogSetting(int nAppID)\r
{\r
return m_Config.AppConfig[nAppID].UseDialogSetting;\r
static void SetAppTitle(int nAppID, const CString& appTitle);\r
static int GetCmdID(int nAppID, int nType, int nKey);\r
static void SetCmdID(int nAppID, int nType, int nKey, int nComID);\r
+ static int GetFuncID(int nAppID, int nType, int nKey);\r
+ static void SetFuncID(int nAppID, int nType, int nKey, int nFuncID);\r
static bool GetUseDialogSetting(int nAppID);\r
static void SetUseDialogSetting(int nAppID, bool setting);\r
static void SetEnableCUA(int nAppID, bool enable);\r
#include "propertiesadvanced.h"\r
#include "resource.h"\r
#include "profile.h"\r
-#include "dotxkeymacs.h"\r
+#include "FuncDefs.h"\r
\r
#ifdef _DEBUG\r
#define new DEBUG_NEW\r
{\r
for (const int *c = CmdTable::Categories(); *c; ++c)\r
m_cCategory.InsertString(-1, CString(MAKEINTRESOURCE(*c)));\r
-\r
- if (CDotXkeymacs::GetFunctionNumber())\r
+ if (FuncDefs::GetNumOfDefs())\r
m_cCategory.InsertString(-1, CString(MAKEINTRESOURCE(IDS_ORIGINAL)));\r
-\r
m_cCategory.SetCurSel(0);\r
}\r
\r
{\r
m_cCommands.ResetContent();\r
\r
- CString szCategory;\r
- m_cCategory.GetLBText(m_cCategory.GetCurSel(), szCategory);\r
- if (szCategory.Compare(CString(MAKEINTRESOURCE(IDS_ORIGINAL)))) {\r
- for (int nComID = 1; nComID < MAX_COMMAND; ++nComID) {\r
- CString szCommandName = CmdTable::Name(nComID);\r
- if (szCommandName.IsEmpty()) {\r
- break;\r
- }\r
-\r
- if (szCategory == CString(MAKEINTRESOURCE(CmdTable::CategoryID(nComID)))) {\r
- m_cCommands.AddString(szCommandName);\r
- }\r
- }\r
+ CString category;\r
+ m_cCategory.GetLBText(m_cCategory.GetCurSel(), category);\r
+ if (category.Compare(CString(MAKEINTRESOURCE(IDS_ORIGINAL)))) {\r
+ for (int cmd = 1; cmd < MAX_COMMAND; ++cmd)\r
+ if (category == CString(MAKEINTRESOURCE(CmdTable::CategoryID(cmd))))\r
+ m_cCommands.AddString(CmdTable::Name(cmd));\r
} else {\r
- for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID) {\r
- BOOL bOriginal = TRUE;\r
- for (int nComID = 1; nComID < MAX_COMMAND; ++nComID) {\r
- CString szCommandName = CmdTable::Name(nComID);\r
- if (szCommandName.IsEmpty()) {\r
- break;\r
- }\r
-\r
- if (szCommandName == CDotXkeymacs::GetFunctionSymbol(nFuncID)) {\r
- bOriginal = FALSE; // overwriting build-in keybindings\r
- break;\r
- }\r
- }\r
- if (bOriginal) {\r
- m_cCommands.AddString(CDotXkeymacs::GetFunctionSymbol(nFuncID));\r
- }\r
- }\r
+ for (int nFuncID = 0; nFuncID < FuncDefs::GetNumOfDefs(); ++nFuncID)\r
+ m_cCommands.AddString(FuncDefs::GetName(nFuncID));\r
}\r
\r
m_cCommands.SetCurSel(0);\r
m_cCurrentKeys.ResetContent();\r
m_cRemove.EnableWindow(FALSE);\r
\r
- CString szCategory;\r
- m_cCategory.GetLBText(m_cCategory.GetCurSel(), szCategory);\r
+ CString category;\r
+ m_cCategory.GetLBText(m_cCategory.GetCurSel(), category);\r
+ CString name;\r
+ m_cCommands.GetText(m_cCommands.GetCurSel(), name);\r
\r
- CString szCurrentCommandName;\r
- m_cCommands.GetText(m_cCommands.GetCurSel(), szCurrentCommandName);\r
-\r
- if (szCategory.Compare(CString(MAKEINTRESOURCE(IDS_ORIGINAL)))) {\r
- for (int nType = 0; nType < MAX_COMMAND_TYPE; ++nType) {\r
- for (int nKey = 0; nKey < MAX_KEY; ++nKey) {\r
- if (CmdTable::Name(CProfile::GetCmdID(m_nAppID, nType, nKey)) == szCurrentCommandName) {\r
- m_cCurrentKeys.AddString(CProfile::KeyToString(nType, nKey));\r
- }\r
- }\r
+ if (category.Compare(CString(MAKEINTRESOURCE(IDS_ORIGINAL)))) {\r
+ for (int type = 0; type < MAX_COMMAND_TYPE; ++type) {\r
+ for (int key = 0; key < MAX_KEY; ++key)\r
+ if (!_tcscmp(CmdTable::Name(CProfile::GetCmdID(m_nAppID, type, key)), name))\r
+ m_cCurrentKeys.AddString(CProfile::KeyToString(type, key));\r
}\r
-\r
- CString szCommandName;\r
- for (int nComID = 0; nComID < MAX_COMMAND; ++nComID) {\r
- szCommandName = CmdTable::Name(nComID);\r
- if (szCommandName.IsEmpty()) {\r
- break;\r
- }\r
- if (szCommandName == szCurrentCommandName) {\r
- m_nCommandID = nComID;\r
+ for (int cmd = 0; cmd < MAX_COMMAND; ++cmd) {\r
+ if (!_tcscmp(CmdTable::Name(cmd), name)) {\r
+ m_nCommandID = cmd;\r
break;\r
}\r
}\r
-\r
m_cDescription.SetWindowText(CString(MAKEINTRESOURCE(CmdTable::DescriptionID(m_nCommandID))));\r
-\r
- // overwrite by original command's description if needed\r
- for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID) {\r
- if (szCommandName == CDotXkeymacs::GetFunctionSymbol(nFuncID)) {\r
- m_cDescription.SetWindowText(CDotXkeymacs::GetFunctionDefinition(szCurrentCommandName));\r
- break;\r
- }\r
- }\r
} else {\r
- const int nIndex = CDotXkeymacs::GetIndex(szCurrentCommandName);\r
- for (int nKeyID = 0; nKeyID < CDotXkeymacs::GetKeyNumber(nIndex, m_nAppID); ++nKeyID) {\r
- int nType = 0;\r
- int nKey = 0;\r
- CDotXkeymacs::GetKey(nIndex, m_nAppID, nKeyID, &nType, &nKey);\r
- m_cCurrentKeys.AddString(CProfile::KeyToString(nType, nKey));\r
+ int id = FuncDefs::GetID(name);\r
+ if (id < 0)\r
+ return;\r
+ for (int type = 0; type < MAX_COMMAND_TYPE; ++type) {\r
+ for (int key = 0; key < MAX_KEY; ++key)\r
+ if (CProfile::GetFuncID(m_nAppID, type, key) == id)\r
+ m_cCurrentKeys.AddString(CProfile::KeyToString(type, key));\r
}\r
-\r
- m_cDescription.SetWindowText(CDotXkeymacs::GetFunctionDefinition(szCurrentCommandName));\r
+ m_cDescription.SetWindowText(FuncDefs::GetStrDef(id));\r
}\r
}\r
\r
// Remove Current Setting\r
CProfile::SetCmdID(m_nAppID, m_nAssignCommandType, m_nAssignKey, 0);\r
SetCmdID(m_nAssignCommandType, m_nAssignKey, 0);\r
- CDotXkeymacs::RemoveKey(m_nAppID, m_nAssignCommandType, m_nAssignKey);\r
+ CProfile::SetFuncID(m_nAppID, m_nAssignCommandType, m_nAssignKey, -1);\r
\r
// Assign New Setting\r
CString item = CProfile::KeyToString(m_nAssignCommandType, m_nAssignKey);\r
if (m_cCurrentKeys.FindString(-1, item) == LB_ERR) { // This key bind has not assignd to the same command yet.\r
- CString szCategory;\r
- m_cCategory.GetLBText(m_cCategory.GetCurSel(), szCategory);\r
-\r
- if (szCategory.Compare(CString(MAKEINTRESOURCE(IDS_ORIGINAL)))) {\r
+ CString category;\r
+ m_cCategory.GetLBText(m_cCategory.GetCurSel(), category);\r
+ if (category.Compare(CString(MAKEINTRESOURCE(IDS_ORIGINAL)))) {\r
CProfile::SetCmdID(m_nAppID, m_nAssignCommandType, m_nAssignKey, m_nCommandID);\r
SetCmdID(m_nAssignCommandType, m_nAssignKey, m_nCommandID);\r
} else {\r
- CString szCurrentCommandName;\r
- m_cCommands.GetText(m_cCommands.GetCurSel(), szCurrentCommandName);\r
- CDotXkeymacs::SetKey(CDotXkeymacs::GetIndex(szCurrentCommandName), m_nAppID, m_nAssignCommandType, m_nAssignKey);\r
+ CString name;\r
+ m_cCommands.GetText(m_cCommands.GetCurSel(), name);\r
+ int id = FuncDefs::GetID(name);\r
+ if (id >= 0)\r
+ CProfile::SetFuncID(m_nAppID, m_nAssignCommandType, m_nAssignKey, id);\r
}\r
m_cCurrentKeys.AddString(item);\r
}\r
\r
void CPropertiesAdvanced::OnRemove() \r
{\r
- CString szCategory;\r
- m_cCategory.GetLBText(m_cCategory.GetCurSel(), szCategory);\r
+ CString category;\r
+ m_cCategory.GetLBText(m_cCategory.GetCurSel(), category);\r
\r
- if (szCategory.Compare(CString(MAKEINTRESOURCE(IDS_ORIGINAL)))) {\r
+ if (category.Compare(CString(MAKEINTRESOURCE(IDS_ORIGINAL)))) {\r
CProfile::SetCmdID(m_nAppID, m_nRemoveCommandType, m_nRemoveKey, 0);\r
SetCmdID(m_nRemoveCommandType, m_nRemoveKey, 0);\r
- } else {\r
- CString szCurrentCommandName;\r
- m_cCommands.GetText(m_cCommands.GetCurSel(), szCurrentCommandName);\r
- CDotXkeymacs::RemoveKey(CDotXkeymacs::GetIndex(szCurrentCommandName), m_nAppID, m_nRemoveCommandType, m_nRemoveKey);\r
- }\r
+ } else\r
+ CProfile::SetFuncID(m_nAppID, m_nRemoveCommandType, m_nRemoveKey, -1);\r
\r
m_cCurrentKeys.DeleteString(m_cCurrentKeys.GetCurSel());\r
m_cRemove.EnableWindow(FALSE);\r
\r
void CPropertiesAdvanced::SetNewKey()\r
{\r
- UINT nType = NONE;\r
+ UINT type = NONE;\r
if (m_bC_x)\r
- nType |= CONTROLX;\r
+ type |= CONTROLX;\r
if (IsCtrlDown())\r
- nType |= CONTROL;\r
+ type |= CONTROL;\r
if (IsMetaDown())\r
- nType |= META;\r
+ type |= META;\r
if (IsShiftDown())\r
- nType |= SHIFT;\r
- m_nAssignCommandType = nType;\r
+ type |= SHIFT;\r
+ m_nAssignCommandType = type;\r
\r
- CString newKey = CProfile::KeyToString(nType, m_nAssignKey);\r
+ const CString newKey = CProfile::KeyToString(type, m_nAssignKey);\r
if (m_pNewKey)\r
m_pNewKey->SetWindowText(newKey);\r
-\r
- if (m_pAssign) {\r
- BOOL bEnable = TRUE;\r
- if (m_pCurrentKeys\r
- && m_pCurrentKeys->FindString(-1, newKey) != LB_ERR) { // This key bind is already assigned.\r
- bEnable = FALSE;\r
- }\r
- m_pAssign->EnableWindow(bEnable);\r
- }\r
-\r
+ if (m_pAssign)\r
+ m_pAssign->EnableWindow(!m_pCurrentKeys || m_pCurrentKeys->FindString(-1, newKey) == LB_ERR); // this key isn't bound;\r
if (m_pCurrentlyAssigned) {\r
- CString szCurrentlyAssigned(_T("Currently assigned to:\n"));\r
-\r
- if (m_nCommandIDs[m_nAssignCommandType][m_nAssignKey] || CDotXkeymacs::GetIndex(m_nAppID, m_nAssignCommandType, m_nAssignKey) == -1) {\r
- szCurrentlyAssigned += CmdTable::Name(m_nCommandIDs[m_nAssignCommandType][m_nAssignKey]);\r
- } else {\r
- szCurrentlyAssigned += CDotXkeymacs::GetFunctionSymbol(CDotXkeymacs::GetIndex(m_nAppID, m_nAssignCommandType, m_nAssignKey));\r
- }\r
- m_pCurrentlyAssigned->SetWindowText(szCurrentlyAssigned);\r
+ CString assigned(_T("Currently assigned to:\n"));\r
+ if (m_nCommandIDs[m_nAssignCommandType][m_nAssignKey] || CProfile::GetFuncID(m_nAppID, m_nAssignCommandType, m_nAssignKey) == -1)\r
+ assigned += CmdTable::Name(m_nCommandIDs[m_nAssignCommandType][m_nAssignKey]);\r
+ else\r
+ assigned += FuncDefs::GetName(CProfile::GetFuncID(m_nAppID, m_nAssignCommandType, m_nAssignKey));\r
+ m_pCurrentlyAssigned->SetWindowText(assigned);\r
}\r
}\r
\r
-void CPropertiesAdvanced::SetCmdID(int nType, int nKey, int nComID)\r
+void CPropertiesAdvanced::SetCmdID(int type, int key, int cmd)\r
{\r
- m_nCommandIDs[nType][nKey] = nComID;\r
-\r
- // Set C-x if it is needed.\r
- if ((nType & CONTROLX)) {\r
- // Get CommandID of C-x.\r
- int nCommandIDofC_x;\r
- for (nCommandIDofC_x = 0; nCommandIDofC_x < MAX_COMMAND; ++nCommandIDofC_x) {\r
- if (!_tcsicmp(CmdTable::Name(nCommandIDofC_x), _T("C-x"))) {\r
- break;\r
- }\r
- }\r
-\r
- if (nComID) {\r
- m_nCommandIDs[CONTROL]['X'] = nCommandIDofC_x;\r
- } else {\r
- for (int i = 0; i < MAX_COMMAND_TYPE; ++i) { // i is command-type.\r
- if (!(i & CONTROLX)) {\r
- continue;\r
- }\r
- for (int j = 0; j < MAX_KEY; ++j) { // j is key.\r
- if (m_nCommandIDs[i][j]) {\r
- m_nCommandIDs[CONTROL]['X'] = nCommandIDofC_x; // needless\r
- return;\r
- }\r
- }\r
- }\r
- m_nCommandIDs[CONTROL]['X'] = 0;\r
- }\r
+ m_nCommandIDs[type][key] = cmd;\r
+ if (!(type & CONTROLX))\r
+ return;\r
+ // Make C-x enable or disable.\r
+ if (cmd)\r
+ m_nCommandIDs[CONTROL]['X'] = 1;\r
+ else {\r
+ m_nCommandIDs[CONTROL]['X'] = 0;\r
+ for (int i = 0; i < MAX_COMMAND_TYPE; ++i)\r
+ for (int j = 0; j < MAX_KEY; ++j)\r
+ if ((i & CONTROLX) && m_nCommandIDs[i][j])\r
+ m_nCommandIDs[CONTROL]['X'] = 1;\r
}\r
}\r
\r
void CPropertiesAdvanced::InitCommandIDs()\r
{\r
- for (int nType = 0; nType < MAX_COMMAND_TYPE; ++nType) {\r
- for (int nKey = 0; nKey < MAX_KEY; ++nKey) {\r
- SetCmdID(nType, nKey, CProfile::GetCmdID(m_nAppID, nType, nKey));\r
- }\r
- }\r
+ for (int type = 0; type < MAX_COMMAND_TYPE; ++type)\r
+ for (int key = 0; key < MAX_KEY; ++key)\r
+ SetCmdID(type, key, CProfile::GetCmdID(m_nAppID, type, key));\r
}\r
\r
void CPropertiesAdvanced::OnCX() \r
\r
void CPropertiesAdvanced::OnKillfocusNewKey() \r
{\r
- if (m_hKeyboardHook) {\r
+ if (m_hKeyboardHook)\r
::UnhookWindowsHookEx(m_hKeyboardHook);\r
- }\r
m_hKeyboardHook = NULL;\r
}\r
\r
\r
BOOL CPropertiesAdvanced::IsFooDown(CString szCommandName)\r
{\r
- for (int nKey = 0; nKey < MAX_KEY; ++nKey) {\r
- if (CmdTable::Name(CProfile::GetCmdID(0, NONE, nKey)) == szCommandName) { // FIXME\r
- if (GetKeyState(nKey) < 0) {\r
+ for (int key = 0; key < MAX_KEY; ++key) {\r
+ if (CmdTable::Name(CProfile::GetCmdID(0, NONE, key)) == szCommandName) { // FIXME\r
+ if (GetKeyState(key) < 0) {\r
return TRUE;\r
}\r
}\r
#include "propertiesbasic.h"\r
#include "resource.h"\r
#include "profile.h"\r
-#include "dotxkeymacs.h"\r
\r
#ifdef _DEBUG\r
#define new DEBUG_NEW\r
return;\r
if (IsDlgButtonChecked(bind.nControlID)) {\r
CProfile::SetCmdID(appID, bind.nType, bind.bVk, cmdID);\r
- CDotXkeymacs::RemoveKey(appID, bind.nType, bind.bVk);\r
+ CProfile::SetFuncID(appID, bind.nType, bind.bVk, -1);\r
} else if (bind.nControlID != IDC_CO2)\r
CProfile::SetCmdID(appID, bind.nType, bind.bVk, 0);\r
}\r
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>\r
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>\r
</ClCompile>\r
- <ClCompile Include="dotxkeymacs.cpp">\r
+ <ClCompile Include="FuncDefs.cpp">\r
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>\r
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>\r
</ClCompile>\r
<ClInclude Include="109keyboard.h" />\r
<ClInclude Include="about.h" />\r
<ClInclude Include="AppList.h" />\r
- <ClInclude Include="dotxkeymacs.h" />\r
+ <ClInclude Include="FuncDefs.h" />\r
<ClInclude Include="imelist.h" />\r
<ClInclude Include="key.h" />\r
<ClInclude Include="keyboardlayout.h" />\r
<ClCompile Include="109keyboard.cpp">\r
<Filter>Source Files</Filter>\r
</ClCompile>\r
- <ClCompile Include="dotxkeymacs.cpp">\r
- <Filter>Source Files</Filter>\r
- </ClCompile>\r
<ClCompile Include="key.cpp">\r
<Filter>Source Files</Filter>\r
</ClCompile>\r
<ClCompile Include="AppList.cpp">\r
<Filter>Source Files</Filter>\r
</ClCompile>\r
+ <ClCompile Include="FuncDefs.cpp">\r
+ <Filter>Source Files</Filter>\r
+ </ClCompile>\r
</ItemGroup>\r
<ItemGroup>\r
<ClInclude Include="104keyboard.h">\r
<ClInclude Include="109keyboard.h">\r
<Filter>Header Files</Filter>\r
</ClInclude>\r
- <ClInclude Include="dotxkeymacs.h">\r
- <Filter>Header Files</Filter>\r
- </ClInclude>\r
<ClInclude Include="key.h">\r
<Filter>Header Files</Filter>\r
</ClInclude>\r
<ClInclude Include="AppList.h">\r
<Filter>Header Files</Filter>\r
</ClInclude>\r
+ <ClInclude Include="FuncDefs.h">\r
+ <Filter>Header Files</Filter>\r
+ </ClInclude>\r
</ItemGroup>\r
<ItemGroup>\r
<ResourceCompile Include="xkeymacs.rc">\r
+++ /dev/null
-// FunctionDefinition.cpp: implementation of the CFunctionDefinition class.\r
-//\r
-//////////////////////////////////////////////////////////////////////\r
-\r
-#include "FunctionDefinition.h"\r
-#include "Utils.h"\r
-\r
-CFunctionDefinition::CFunctionDefinition(CString szSymbol, CString szDefinition)\r
-{\r
- SetSymbol(szSymbol);\r
- SetDefinition(szDefinition);\r
-}\r
-\r
-void CFunctionDefinition::SetSymbol(CString szSymbol)\r
-{\r
- m_szSymbol = szSymbol;\r
-}\r
-\r
-void CFunctionDefinition::SetDefinition(CString szDefinition)\r
-{\r
- m_szDefinition = szDefinition;\r
-}\r
-\r
-CString CFunctionDefinition::GetSymbol()\r
-{\r
- return m_szSymbol;\r
-}\r
-\r
-CString CFunctionDefinition::GetDefinition()\r
-{\r
- return m_szDefinition;\r
-}\r
-\r
-void CFunctionDefinition::ClearKey(int nAppID)\r
-{\r
- if (nAppID < 0 || MAX_APP <= nAppID) {\r
- return;\r
- }\r
-\r
- while (!m_oKey[nAppID].IsEmpty()) {\r
- KeyBind *pKeyBind = (KeyBind *)m_oKey[nAppID].GetHead();\r
- delete pKeyBind;\r
- pKeyBind = NULL;\r
- m_oKey[nAppID].RemoveHead();\r
- }\r
-}\r
-\r
-void CFunctionDefinition::SetKey(int nAppID, int nType, int nKey)\r
-{\r
- if (nAppID < 0 || MAX_APP <= nAppID) {\r
- return;\r
- }\r
-\r
- try {\r
- KeyBind *pKeyBind = new KeyBind;\r
-\r
- if (pKeyBind) {\r
- pKeyBind->nType = nType;\r
- pKeyBind->bVk = (BYTE)nKey;\r
- pKeyBind->nControlID = 0;\r
-\r
- m_oKey[nAppID].AddTail((CObject *)pKeyBind);\r
- }\r
- }\r
- catch (CMemoryException* e) {\r
- e->Delete();\r
-// CUtils::Log("CFunctionDefinition::SetKey: 'new' threw an exception");\r
- }\r
-}\r
-\r
-int CFunctionDefinition::GetKeyNumber(int nAppID)\r
-{\r
- if (nAppID < 0 || MAX_APP <= nAppID) {\r
- return 0;\r
- }\r
-\r
- return m_oKey[nAppID].GetCount();\r
-}\r
-\r
-void CFunctionDefinition::GetKey(int nAppID, int nKeyID, int *pCommandType, int *pKey)\r
-{\r
- *pCommandType = 0;\r
- *pKey = 0;\r
-\r
- if (nAppID < 0 || MAX_APP <= nAppID) {\r
- return;\r
- }\r
- if (nKeyID < 0 || m_oKey[nAppID].GetCount() <= nKeyID) {\r
- return;\r
- }\r
-\r
- KeyBind *pKeyBind = (KeyBind *)m_oKey[nAppID].GetAt(m_oKey[nAppID].FindIndex(nKeyID));\r
- *pCommandType = pKeyBind->nType;\r
- *pKey = pKeyBind->bVk;\r
-}\r
-\r
-void CFunctionDefinition::RemoveKey(int nAppID, int nType, int nKey)\r
-{\r
- if (nAppID < 0 || MAX_APP <= nAppID) {\r
- return;\r
- }\r
-\r
- for (POSITION pos = m_oKey[nAppID].GetHeadPosition(); pos; ) {\r
- POSITION currentPos = pos;\r
- KeyBind *pKeyBind = (KeyBind *)m_oKey[nAppID].GetNext(pos);\r
- if (pKeyBind->nType == nType && pKeyBind->bVk == nKey) {\r
- delete pKeyBind;\r
- pKeyBind = NULL;\r
- m_oKey[nAppID].RemoveAt(currentPos);\r
- break;\r
- }\r
- }\r
-}\r
+++ /dev/null
-// FunctionDefinition.h: interface for the CFunctionDefinition class.\r
-//\r
-//////////////////////////////////////////////////////////////////////\r
-\r
-#if !defined(AFX_FUNCTIONDEFINITION_H__22E7286C_E86F_4964_896F_28A66E94A7A2__INCLUDED_)\r
-#define AFX_FUNCTIONDEFINITION_H__22E7286C_E86F_4964_896F_28A66E94A7A2__INCLUDED_\r
-\r
-#if _MSC_VER > 1000\r
-#pragma once\r
-#endif // _MSC_VER > 1000\r
-\r
-#include "defs.h"\r
-\r
-class AFX_EXT_CLASS CFunctionDefinition\r
-{\r
-public:\r
- void RemoveKey(int nAppID, int nType, int nKey);\r
- void GetKey(int nAppID, int nKeyID, int *pCommandType, int *pKey);\r
- int GetKeyNumber(int nAppID);\r
- void SetKey(int nAppID, int nType, int nKey);\r
- void ClearKey(int nAppID);\r
- CString GetDefinition();\r
- CString GetSymbol();\r
- void SetDefinition(CString szDefinition);\r
- void SetSymbol(CString szSymbol);\r
- CFunctionDefinition(CString szSymbol, CString szDefinition);\r
-\r
-private:\r
- CObList m_oKey[MAX_APP];\r
- CString m_szDefinition;\r
- CString m_szSymbol;\r
-};\r
-\r
-#endif // !defined(AFX_FUNCTIONDEFINITION_H__22E7286C_E86F_4964_896F_28A66E94A7A2__INCLUDED_)\r
\r
struct Config {\r
AppConfig AppConfig[MAX_APP];\r
- TCHAR FuncDefs[MAX_FUNCTION][MAX_DEFINITION];\r
+ KeyBind FuncDefs[MAX_FUNCTION][MAX_DEFINITION];\r
bool Is106Keyboard;\r
};\r
\r
<ClCompile Include="CmdTable.cpp" />\r
<ClCompile Include="CmdTableData.cpp" />\r
<ClCompile Include="Commands.cpp" />\r
- <ClCompile Include="FunctionDefinition.cpp" />\r
<ClCompile Include="KbdMacro.cpp" />\r
<ClCompile Include="StdAfx.cpp">\r
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>\r
<ClInclude Include="CmdTable.h" />\r
<ClInclude Include="Commands.h" />\r
<ClInclude Include="defs.h" />\r
- <ClInclude Include="FunctionDefinition.h" />\r
<ClInclude Include="ipc.h" />\r
<ClInclude Include="KbdMacro.h" />\r
<ClInclude Include="resource.h" />\r
<ClCompile Include="AppName.cpp">\r
<Filter>Source Files</Filter>\r
</ClCompile>\r
- <ClCompile Include="FunctionDefinition.cpp">\r
- <Filter>Source Files</Filter>\r
- </ClCompile>\r
<ClCompile Include="CmdTable.cpp">\r
<Filter>Source Files</Filter>\r
</ClCompile>\r
<ClInclude Include="Commands.h">\r
<Filter>Header Files</Filter>\r
</ClInclude>\r
- <ClInclude Include="FunctionDefinition.h">\r
- <Filter>Header Files</Filter>\r
- </ClInclude>\r
<ClInclude Include="resource.h">\r
<Filter>Header Files</Filter>\r
</ClInclude>\r
static char THIS_FILE[] = __FILE__;\r
#endif\r
\r
-struct Modifier {\r
- LPCTSTR name;\r
- int id;\r
-};\r
-\r
-static const Modifier Modifiers[] = {\r
-// { _T("A-"), ALT },\r
- { _T("C-"), CONTROL},\r
-// { _T("H-"), HYPER },\r
- { _T("M-"), META },\r
- { _T("S-"), SHIFT },\r
-// { _T("s-"), SUPER },\r
- { _T("Ctrl+"), WIN_CTRL },\r
- { _T("Alt+"), WIN_ALT },\r
- { _T("Win+"), WIN_WIN },\r
-};\r
-static const int MAX_MODIFIER = _countof(Modifiers);\r
-\r
-static const struct {\r
- BYTE bVk;\r
- LPCTSTR name;\r
-} KeyNames[] = {\r
-// { VK_LBUTTON, _T("mouse-1") }, // does not work well\r
-// { VK_RBUTTON, _T("mouse-3") }, // does not work well\r
- { VK_CANCEL, _T("break") },\r
-// { VK_MBUTTON, _T("mouse-2") }, // does not work well\r
- { VK_BACK, _T("backspace") },\r
- { VK_TAB, _T("tab") },\r
- { VK_RETURN, _T("return") },\r
- { VK_CAPITAL, _T("capslock") },\r
- { VK_KANA, _T("kana") },\r
- { VK_KANJI, _T("kanji") },\r
- { VK_ESCAPE, _T("escape") },\r
- { VK_CONVERT, _T("convert") },\r
- { VK_NONCONVERT, _T("nonconvert") },\r
-// { VK_SPACE, _T("SPC") }, // [? ]\r
- { VK_PRIOR, _T("prior") },\r
- { VK_NEXT, _T("next") },\r
- { VK_END, _T("end") },\r
- { VK_HOME, _T("home") },\r
- { VK_LEFT, _T("left") },\r
- { VK_UP, _T("up") },\r
- { VK_RIGHT, _T("right") },\r
- { VK_DOWN, _T("down") },\r
- { VK_SELECT, _T("select") },\r
- { VK_PRINT, _T("print") },\r
- { VK_EXECUTE, _T("execute") },\r
- { VK_SNAPSHOT, _T("printscreen") }, // work as print\r
- { VK_INSERT, _T("insert") },\r
- { VK_DELETE, _T("delete") },\r
- { VK_LWIN, _T("lwindow") },\r
- { VK_RWIN, _T("rwindow") },\r
- { VK_APPS, _T("apps") },\r
- { VK_SLEEP, _T("sleep") },\r
- { VK_NUMPAD0, _T("kp-0") },\r
- { VK_NUMPAD1, _T("kp-1") },\r
- { VK_NUMPAD2, _T("kp-2") },\r
- { VK_NUMPAD3, _T("kp-3") },\r
- { VK_NUMPAD4, _T("kp-4") },\r
- { VK_NUMPAD5, _T("kp-5") },\r
- { VK_NUMPAD6, _T("kp-6") },\r
- { VK_NUMPAD7, _T("kp-7") },\r
- { VK_NUMPAD8, _T("kp-8") },\r
- { VK_NUMPAD9, _T("kp-9") },\r
- { VK_MULTIPLY, _T("kp-multiply") },\r
- { VK_ADD, _T("kp-add") },\r
- { VK_SUBTRACT, _T("kp-subtract") },\r
- { VK_DECIMAL, _T("kp-decimal") },\r
- { VK_DIVIDE, _T("kp-divide") },\r
-// { VK_F1, _T("f1") }, // FIXME\r
-// { VK_F2, _T("f2") }, // Move at the end of definition of function keys to keep away confliction f1/f2 and f1?/f2? by _tcsncmp() i.e. strncmp()\r
- { VK_F3, _T("f3") },\r
- { VK_F4, _T("f4") },\r
- { VK_F5, _T("f5") },\r
- { VK_F6, _T("f6") },\r
- { VK_F7, _T("f7") },\r
- { VK_F8, _T("f8") },\r
- { VK_F9, _T("f9") },\r
- { VK_F10, _T("f10") },\r
- { VK_F11, _T("f11") },\r
- { VK_F12, _T("f12") },\r
- { VK_F13, _T("f13") },\r
- { VK_F14, _T("f14") },\r
- { VK_F15, _T("f15") },\r
- { VK_F16, _T("f16") },\r
- { VK_F17, _T("f17") },\r
- { VK_F18, _T("f18") },\r
- { VK_F19, _T("f19") },\r
- { VK_F20, _T("f20") },\r
- { VK_F21, _T("f21") },\r
- { VK_F22, _T("f22") },\r
- { VK_F23, _T("f23") },\r
- { VK_F24, _T("f24") },\r
- { VK_F1, _T("f1") },\r
- { VK_F2, _T("f2") },\r
- { VK_NUMLOCK, _T("kp-numlock") },\r
- { VK_SCROLL, _T("scroll") },\r
- { 0xa6, _T("browser-back") }, // VK_BROWSER_BACK\r
- { 0xa7, _T("browser-forward") }, // VK_BROWSER_FORWARD\r
- { 0xa8, _T("browser-refresh") }, // VK_BROWSER_REFRESH\r
- { 0xa9, _T("browser-stop") }, // VK_BROWSER_STOP\r
- { 0xaa, _T("browser-search") }, // VK_BROWSER_SEARCH\r
- { 0xab, _T("browser-favorites") }, // VK_BROWSER_FAVORITES\r
- { 0xac, _T("browser-home") }, // VK_BROWSER_HOME\r
- { 0xad, _T("volume-mute") }, // VK_VOLUME_MUTE\r
- { 0xae, _T("volume-down") }, // VK_VOLUME_DOWN\r
- { 0xaf, _T("volume-up") }, // VK_VOLUME_UP\r
- { 0xb0, _T("media-next-track") }, // VK_MEDIA_NEXT_TRACK\r
- { 0xb1, _T("media-prev-track") }, // VK_MEDIA_PREV_TRACK\r
- { 0xb2, _T("media-stop") }, // VK_MEDIA_STOP\r
- { 0xb3, _T("media-play-pause") }, // VK_MEDIA_PLAY_PAUSE\r
- { 0xb4, _T("launch-mail") }, // VK_LAUNCH_MAIL\r
- { 0xb5, _T("launch-media-select") }, // VK_LAUNCH_MEDIA_SELECT\r
- { 0xb6, _T("launch-1") }, // VK_LAUNCH_APP1\r
- { 0xb7, _T("launch-2") }, // VK_LAUNCH_APP2\r
-};\r
-static const int MAX_KEYNAME = _countof(KeyNames);\r
-\r
static AFX_EXTENSION_MODULE XkeymacsdllDLL = { NULL, NULL };\r
\r
static HINSTANCE g_hDllInst = NULL;\r
bCherryOneShotModifier = FALSE;\r
\r
int id = m_FuncID[nType][nKey];\r
- if (0 <= id && id < MAX_FUNCTION && m_Config.FuncDefs[id][0]) {\r
+ if (0 <= id && id < MAX_FUNCTION) {\r
CallFunction(id);\r
CCommands::Reset(GOTO_HOOK);\r
goto HOOK;\r
{\r
if (id < 0 || id >= MAX_FUNCTION)\r
return;\r
- LPCTSTR def = m_Config.FuncDefs[id];\r
- if (!def[0])\r
- return;\r
- std::vector<KeyBind> keybinds;\r
- LPCTSTR last = def + _tcslen(def) - 1;\r
- if (*def == _T('"') && *last == _T('"')) {\r
- ++def; // skip '"'\r
- while (def < last)\r
- keybinds.push_back(ParseKey(def));\r
- } else if (*def == _T('[') && *last == _T(']')) {\r
- while (++def < last) { // skip '[', ']', and ' '\r
- if (*def == _T('?')) { // [?f ?o ?o]\r
- keybinds.push_back(ParseKey(++def));\r
- continue;\r
- }\r
- // [VK]\r
- for (int i = 0; i < MAX_KEYNAME; ++i) {\r
- size_t keylen = _tcslen(KeyNames[i].name);\r
- if (!_tcsncmp(def, KeyNames[i].name, keylen)) {\r
- KeyBind keybind = {NONE, KeyNames[i].bVk};\r
- keybinds.push_back(keybind);\r
- def += keylen;\r
- break;\r
- }\r
- }\r
- }\r
- } else\r
- return;\r
-\r
BOOL bM_x = FALSE;\r
TCHAR szPath[MAX_PATH] = {'\0'};\r
unsigned int index = 0;\r
BOOL bInitialized = FALSE;\r
UINT before = GetModifierState(FALSE);\r
\r
- for (std::vector<KeyBind>::const_iterator p = keybinds.begin(); p != keybinds.end(); ++p) {\r
+ for (KeyBind *p = m_Config.FuncDefs[id]; p->bVk; ++p) {\r
int nType = p->nType;\r
BYTE bVk = p->bVk;\r
int (*fCommand)() = nType < MAX_COMMAND_TYPE ? CmdTable::Command(m_CmdID[nType][bVk]) : NULL;\r
if (nType & SHIFT)\r
DepressKey(VK_SHIFT);\r
Kdu(bVk);\r
- int nNextType = (p + 1) != keybinds.end() ? (p + 1)->nType : 0;\r
+ int nNextType = (p + 1)->nType;\r
if (nType & SHIFT && !(nNextType & SHIFT))\r
ReleaseKey(VK_SHIFT);\r
if (nType & WIN_ALT && !(nNextType & WIN_ALT))\r
return;\r
}\r
\r
-KeyBind CXkeymacsDll::ParseKey(LPCTSTR& def)\r
-{\r
- KeyBind keybind = {NONE};\r
- if (*def == _T('\\')) { // set modifiers\r
- ++def;\r
- LOOP:\r
- for (int i = 0; i < MAX_MODIFIER; ++i) {\r
- size_t len = _tcslen(Modifiers[i].name);\r
- if (!_tcsncmp(def, Modifiers[i].name, len)) {\r
- keybind.nType |= Modifiers[i].id;\r
- def += len;\r
- goto LOOP;\r
- }\r
- }\r
- }\r
- int i = 0;\r
- for (; i < MAX_KEYNAME; ++i) {\r
- size_t len = _tcslen(KeyNames[i].name);\r
- if (!_tcsncmp(def, KeyNames[i].name, len)) {\r
- def += len;\r
- break;\r
- }\r
- }\r
- if (i < MAX_KEYNAME) {\r
- keybind.bVk = KeyNames[i].bVk;\r
- return keybind;\r
- }\r
- SHORT r = ConvVkey(*def++, 0);\r
- if (r & (1 << 8) && !(keybind.nType & (WIN_CTRL | WIN_ALT | WIN_WIN)))\r
- keybind.nType |= SHIFT;\r
- keybind.bVk = static_cast<BYTE>(r);\r
- return keybind;\r
-}\r
-\r
SHORT CXkeymacsDll::ConvVkey(SHORT in, int mode)\r
{\r
HKL h = GetKeyboardLayout(0);\r
static bool Get326Compatible();\r
static bool Is106Keyboard();\r
static void SetKbMacro(KbdMacro* kbdMacro);\r
+ static SHORT ConvVkey(SHORT in, int mode);\r
static int GetAccelerate(void);\r
static void SetAccelerate(int nAccelerate);\r
static void SetKeyboardSpeed(int nKeyboardSpeed);\r
static CList<CClipboardSnap *, CClipboardSnap *> m_oKillRing;\r
static int m_nKillRing;\r
static KbdMacro* m_kbdMacro;\r
- static void CallFunction(int nFuncID);\r
- static KeyBind ParseKey(LPCTSTR& def);\r
- static SHORT ConvVkey(SHORT in, int mode);\r
+ static void CallFunction(int id);\r
static int m_nAccelerate;\r
static int m_nKeyboardSpeed;\r
static HCURSOR m_hCurrentCursor;\r