OSDN Git Service

Add declarations of index variables.
[xkeymacs/xkeymacs.git] / xkeymacs / profile.cpp
index 86aac6f..fc8d930 100644 (file)
@@ -8,8 +8,9 @@
 #include "MainFrm.h"\r
 #include "DotXkeymacs.h"\r
 #include <Imm.h>\r
-#include <Shlwapi.h>   // Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with Internet Explorer 4.0 or later). \r
-                                               // Windows 95/98/Me: Requires Windows 98 (or Windows 95 with Internet Explorer 4.0 or later). \r
+#include <Shlwapi.h>\r
+#include <TlHelp32.h>\r
+\r
 \r
 #ifdef _DEBUG\r
 #undef THIS_FILE\r
@@ -17,12 +18,296 @@ static char THIS_FILE[]=__FILE__;
 #define new DEBUG_NEW\r
 #endif\r
 \r
-\r
-CXkeymacsData CProfile::m_XkeymacsData[MAX_APP];\r
+struct CommandTypeName\r
+{\r
+       int nCommandType;\r
+       LPCTSTR szCommandTypeName;\r
+};\r
+\r
+static const CommandTypeName CommandTypes[] = {\r
+       {NONE,                                                  _T("")},\r
+       {SHIFT,                                                 _T("Shift+")},\r
+       {CONTROL,                                               _T("Ctrl+")},\r
+       {CONTROL+SHIFT,                                 _T("Ctrl+Shift+")},\r
+       {META,                                                  _T("Meta+")},\r
+       {META+SHIFT,                                    _T("Meta+Shift+")},\r
+       {CONTROL+META,                                  _T("Ctrl+Meta+")},\r
+       {CONTROL+META+SHIFT,                    _T("Ctrl+Meta+Shift+")},\r
+       {CONTROLX+NONE,                                 _T("Ctrl+X ")},\r
+       {CONTROLX+SHIFT,                                _T("Ctrl+X Shift+")},\r
+       {CONTROLX+CONTROL,                              _T("Ctrl+X Ctrl+")},\r
+       {CONTROLX+CONTROL+SHIFT,                _T("Ctrl+X Ctrl+Shift+")},\r
+       {CONTROLX+META,                                 _T("Ctrl+X Meta+")},\r
+       {CONTROLX+META+SHIFT,                   _T("Ctrl+X Meta+Shift+")},\r
+       {CONTROLX+CONTROL+META,                 _T("Ctrl+X Ctrl+Meta+")},\r
+       {CONTROLX+CONTROL+META+SHIFT,   _T("Ctrl+X Ctrl+Meta+Shift+")},\r
+};\r
+\r
+static const KeyName KeyNames[] = {\r
+       {0,                             _T("")},\r
+       {VK_LBUTTON,    _T("Left mouse button")},\r
+       {VK_RBUTTON,    _T("Right mouse button")},\r
+       {VK_CANCEL,             _T("Break")},\r
+       {VK_MBUTTON,    _T("Middle mouse button")},\r
+       {0x05,                  _T("X1 mouse button")}, // VK_XBUTTON1\r
+       {0x06,                  _T("X2 mouse button")}, // VK_XBUTTON2\r
+       {0x07,                  _T("Undefined")},\r
+       {VK_BACK,               _T("Backspace")},\r
+       {VK_TAB,                _T("Tab")},\r
+       {0x0a,                  _T("Reserved")},\r
+       {0x0b,                  _T("Reserved")},\r
+       {VK_CLEAR,              _T("Clear")},\r
+       {VK_RETURN,             _T("Enter")},\r
+       {0x0e,                  _T("Undefined")},\r
+       {0x0f,                  _T("Undefined")},\r
+       {VK_SHIFT,              _T("Shift")},\r
+       {VK_CONTROL,    _T("Ctrl")},\r
+       {VK_MENU,               _T("Alt")},\r
+       {VK_PAUSE,              _T("Pause")},\r
+       {VK_CAPITAL,    _T("Caps Lock")},\r
+       {VK_KANA,               _T("Kana")},    //      {VK_HANGUEL,    "Hanguel"},     {VK_HANGUL,             "Hangul"},\r
+       {0x16,                  _T("Undefined")},\r
+       {VK_JUNJA,              _T("Junja")},\r
+       {VK_FINAL,              _T("Final")},\r
+       {VK_KANJI,              _T("Kanji")},   //      {VK_HANJA,              "Hanja"},\r
+       {0x1a,                  _T("Undefined")},\r
+       {VK_ESCAPE,             _T("Esc")},\r
+       {VK_CONVERT,    _T("Convert")},         // \95Ï\8a·\r
+       {VK_NONCONVERT, _T("Nonconvert")},      // \96³\95Ï\8a·\r
+       {VK_ACCEPT,             _T("Accept")},\r
+       {VK_MODECHANGE, _T("Mode change")},\r
+       {VK_SPACE,              _T("Space")},\r
+       {VK_PRIOR,              _T("Page Up")},\r
+       {VK_NEXT,               _T("Page Down")},\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("Print Screen")},\r
+       {VK_INSERT,             _T("Ins")},\r
+       {VK_DELETE,             _T("Del")},\r
+       {VK_HELP,               _T("Help")},\r
+       {'0',                   _T("0")},\r
+       {'1',                   _T("1")},\r
+       {'2',                   _T("2")},\r
+       {'3',                   _T("3")},\r
+       {'4',                   _T("4")},\r
+       {'5',                   _T("5")},\r
+       {'6',                   _T("6")},\r
+       {'7',                   _T("7")},\r
+       {'8',                   _T("8")},\r
+       {'9',                   _T("9")},\r
+       {0x3a,                  _T("Undefined")},\r
+       {0x3b,                  _T("Undefined")},\r
+       {0x3c,                  _T("Undefined")},\r
+       {0x3d,                  _T("Undefined")},\r
+       {0x3e,                  _T("Undefined")},\r
+       {0x3f,                  _T("Undefined")},\r
+       {0x40,                  _T("Undefined")},\r
+       {'A',                   _T("A")},\r
+       {'B',                   _T("B")},\r
+       {'C',                   _T("C")},\r
+       {'D',                   _T("D")},\r
+       {'E',                   _T("E")},\r
+       {'F',                   _T("F")},\r
+       {'G',                   _T("G")},\r
+       {'H',                   _T("H")},\r
+       {'I',                   _T("I")},\r
+       {'J',                   _T("J")},\r
+       {'K',                   _T("K")},\r
+       {'L',                   _T("L")},\r
+       {'M',                   _T("M")},\r
+       {'N',                   _T("N")},\r
+       {'O',                   _T("O")},\r
+       {'P',                   _T("P")},\r
+       {'Q',                   _T("Q")},\r
+       {'R',                   _T("R")},\r
+       {'S',                   _T("S")},\r
+       {'T',                   _T("T")},\r
+       {'U',                   _T("U")},\r
+       {'V',                   _T("V")},\r
+       {'W',                   _T("W")},\r
+       {'X',                   _T("X")},\r
+       {'Y',                   _T("Y")},\r
+       {'Z',                   _T("Z")},\r
+       {VK_LWIN,               _T("Left Windows")},\r
+       {VK_RWIN,               _T("Right Windows")},\r
+       {VK_APPS,               _T("Application")},\r
+       {0x5e,                  _T("Reserved")},\r
+       {0x5f,                  _T("Sleep")},   // VK_SLEEP\r
+       {VK_NUMPAD0,    _T("Num 0")},\r
+       {VK_NUMPAD1,    _T("Num 1")},\r
+       {VK_NUMPAD2,    _T("Num 2")},\r
+       {VK_NUMPAD3,    _T("Num 3")},\r
+       {VK_NUMPAD4,    _T("Num 4")},\r
+       {VK_NUMPAD5,    _T("Num 5")},\r
+       {VK_NUMPAD6,    _T("Num 6")},\r
+       {VK_NUMPAD7,    _T("Num 7")},\r
+       {VK_NUMPAD8,    _T("Num 8")},\r
+       {VK_NUMPAD9,    _T("Num 9")},\r
+       {VK_MULTIPLY,   _T("Num *")},\r
+       {VK_ADD,                _T("Num +")},\r
+       {VK_SEPARATOR,  _T("Separator")},\r
+       {VK_SUBTRACT,   _T("Num -")},\r
+       {VK_DECIMAL,    _T("Num .")},\r
+       {VK_DIVIDE,             _T("Num /")},\r
+       {VK_F1,                 _T("F1")},\r
+       {VK_F2,                 _T("F2")},\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
+       {0x88,                  _T("Unassigned")},\r
+       {0x89,                  _T("Unassigned")},\r
+       {0x8a,                  _T("Unassigned")},\r
+       {0x8b,                  _T("Unassigned")},\r
+       {0x8c,                  _T("Unassigned")},\r
+       {0x8d,                  _T("Unassigned")},\r
+       {0x8e,                  _T("Unassigned")},\r
+       {0x8f,                  _T("Unassigned")},\r
+       {VK_NUMLOCK,    _T("Num Lock")},\r
+       {VK_SCROLL,             _T("Scroll Lock")},\r
+       {0x92,                  _T("OEM specific")},\r
+       {0x93,                  _T("OEM specific")},\r
+       {0x94,                  _T("OEM specific")},\r
+       {0x95,                  _T("OEM specific")},\r
+       {0x96,                  _T("OEM specific")},\r
+       {0x97,                  _T("Unassigned")},\r
+       {0x98,                  _T("Unassigned")},\r
+       {0x99,                  _T("Unassigned")},\r
+       {0x9a,                  _T("Unassigned")},\r
+       {0x9b,                  _T("Unassigned")},\r
+       {0x9c,                  _T("Unassigned")},\r
+       {0x9d,                  _T("Unassigned")},\r
+       {0x9e,                  _T("Unassigned")},\r
+       {0x9f,                  _T("Unassigned")},\r
+       {VK_LSHIFT,             _T("Left Shift")},\r
+       {VK_RSHIFT,             _T("Right Shift")},\r
+       {VK_LCONTROL,   _T("Left Ctrl")},\r
+       {VK_RCONTROL,   _T("Right Ctrl")},\r
+       {VK_LMENU,              _T("Left Alt")},\r
+       {VK_RMENU,              _T("Right Alt")},\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 Start")},           // 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("Next Track")},                      // VK_MEDIA_NEXT_TRACK\r
+       {0xb1,                  _T("Previous Track")},          // VK_MEDIA_PREV_TRACK\r
+       {0xb2,                  _T("Stop Media")},                      // VK_MEDIA_STOP\r
+       {0xb3,                  _T("Play/Pause Media")},        // VK_MEDIA_PLAY_PAUSE\r
+       {0xb4,                  _T("Start Mail")},                      // VK_LAUNCH_MAIL\r
+       {0xb5,                  _T("Select Media")},            // VK_LAUNCH_MEDIA_SELECT\r
+       {0xb6,                  _T("Start Application 1")},     // VK_LAUNCH_APP1\r
+       {0xb7,                  _T("Start Application 2")},     // VK_LAUNCH_APP2\r
+       {0xb8,                  _T("Reserved")},\r
+       {0xb9,                  _T("Reserved")},\r
+       {0xba,                  _T(";")},                                       // VK_OEM_1\r
+//     {0xba,                  _T(":")},                                       // VK_OEM_1             // for Japanese keyboard\r
+       {0xbb,                  _T("+")},                                       // VK_OEM_PLUS\r
+//     {0xbb,                  _T(";")},                                       // VK_OEM_PLUS  // for Japanese keyboard\r
+       {0xbc,                  _T(",")},                                       // VK_OEM_COMMA\r
+       {0xbd,                  _T("-")},                                       // VK_OEM_MINUS\r
+       {0xbe,                  _T(".")},                                       // VK_OEM_PERIOD\r
+       {0xbf,                  _T("/")},                                       // VK_OEM_2\r
+       {0xc0,                  _T("`")},                                       // VK_OEM_3\r
+//     {0xc0,                  _T("@")},                                       // VK_OEM_3             // for Japanese keyboard\r
+       {0xc1,                  _T("Reserved")},\r
+       {0xc2,                  _T("Reserved")},\r
+       {0xc3,                  _T("Reserved")},\r
+       {0xc4,                  _T("Reserved")},\r
+       {0xc5,                  _T("Reserved")},\r
+       {0xc6,                  _T("Reserved")},\r
+       {0xc7,                  _T("Reserved")},\r
+       {0xc8,                  _T("Reserved")},\r
+       {0xc9,                  _T("Reserved")},\r
+       {0xca,                  _T("Reserved")},\r
+       {0xcb,                  _T("Reserved")},\r
+       {0xcc,                  _T("Reserved")},\r
+       {0xcd,                  _T("Reserved")},\r
+       {0xce,                  _T("Reserved")},\r
+       {0xcf,                  _T("Reserved")},\r
+       {0xd0,                  _T("Reserved")},\r
+       {0xd1,                  _T("Reserved")},\r
+       {0xd2,                  _T("Reserved")},\r
+       {0xd3,                  _T("Reserved")},\r
+       {0xd4,                  _T("Reserved")},\r
+       {0xd5,                  _T("Reserved")},\r
+       {0xd6,                  _T("Reserved")},\r
+       {0xd7,                  _T("Reserved")},\r
+       {0xd8,                  _T("Unassigned")},\r
+       {0xd9,                  _T("Unassigned")},\r
+       {0xda,                  _T("Unassigned")},\r
+       {0xdb,                  _T("[")},                                       // VK_OEM_4\r
+       {0xdc,                  _T("Backslash")},                       // VK_OEM_5\r
+       {0xdd,                  _T("]")},                                       // VK_OEM_6\r
+       {0xde,                  _T("'")},                                       // VK_OEM_7\r
+       {0xdf,                  _T("OEM specific")},            // VK_OEM_8\r
+       {0xe0,                  _T("Reserved")},\r
+       {0xe1,                  _T("OEM specific")},\r
+       {0xe2,                  _T("Backslash for 106 keyboard")},      // VK_OEM_102\r
+       {0xe3,                  _T("OEM specific")},\r
+       {0xe4,                  _T("OEM specific")},\r
+       {0xe5,                  _T("Process")},                         // VK_PROCESSKEY\r
+       {0xe6,                  _T("OEM specific")},\r
+       {0xe7,                  _T("Packet")},  // VK_PACKET\r
+       {0xe8,                  _T("Unassigned")},\r
+       {0xe9,                  _T("OEM specific")},\r
+       {0xea,                  _T("OEM specific")},\r
+       {0xeb,                  _T("OEM specific")},\r
+       {0xec,                  _T("OEM specific")},\r
+       {0xed,                  _T("OEM specific")},\r
+       {0xee,                  _T("OEM specific")},\r
+       {0xef,                  _T("OEM specific")},\r
+       {0xf0,                  _T("Eisu")},                                    // \89p\90\94\r
+       {0xf1,                  _T("OEM specific")},\r
+       {0xf2,                  _T("Hiragana")},                                // \82Ð\82ç\82ª\82È\r
+       {0xf3,                  _T("Hankaku/Zenkaku 0xf3")},    // "\94¼\8ap/\91S\8ap"\r
+       {0xf4,                  _T("Hankaku/Zenkaku 0xf4")},    // "\94¼\8ap/\91S\8ap"\r
+       {0xf5,                  _T("OEM specific")},\r
+       {VK_ATTN,               _T("Attn")},\r
+       {VK_CRSEL,              _T("CrSel")},\r
+       {VK_EXSEL,              _T("ExSel")},\r
+       {VK_EREOF,              _T("Erace EOF")},\r
+       {VK_PLAY,               _T("Play")},\r
+       {VK_ZOOM,               _T("Zoom")},\r
+       {VK_NONAME,             _T("Noname")},\r
+       {VK_PA1,                _T("PA1")},\r
+       {VK_OEM_CLEAR,  _T("OEM Clear")},\r
+       {0xff,                  _T("Fn")},\r
+};\r
+\r
+CData CProfile::m_Data[MAX_APP];\r
 TASK_LIST CProfile::m_TaskList[MAX_TASKS];\r
 DWORD CProfile::m_dwTasks;\r
-ScanCode_t CProfile::m_CurrentScanCodeMap[MAX_HKEY_TYPE][4][256];\r
-ScanCode_t CProfile::m_ScanCodeMap[MAX_HKEY_TYPE][4][256];\r
 \r
 enum { INITIAL_SIZE    = 51200 };\r
 enum { EXTEND_SIZE     = 25600 };\r
@@ -123,7 +408,7 @@ BOOL CALLBACK CProfile::EnumWindowsProc(const HWND hWnd, const LPARAM lParam)
        CComboBox               *pApplication   = (CComboBox*)lParam;\r
        PTASK_LIST              pTask                   = CProfile::m_TaskList;\r
        \r
-       TCHAR szWindowName[WINDOW_NAME_LENGTH];\r
+       TCHAR szWindowName[WINDOW_TEXT_LENGTH];\r
        TCHAR szClassName[CLASS_NAME_LENGTH];\r
        WINDOWPLACEMENT wpl;\r
        \r
@@ -135,7 +420,8 @@ BOOL CALLBACK CProfile::EnumWindowsProc(const HWND hWnd, const LPARAM lParam)
        // Get Process Name\r
        DWORD dwProcessId = 0;\r
        GetWindowThreadProcessId(hWnd, &dwProcessId);\r
-       for (DWORD i = 0; i < CProfile::m_dwTasks; ++i) {\r
+       DWORD i;\r
+       for (i = 0; i < CProfile::m_dwTasks; ++i) {\r
                if (pTask[i].dwProcessId == dwProcessId) {\r
 \r
                        // Get Application Name\r
@@ -169,7 +455,7 @@ BOOL CALLBACK CProfile::EnumWindowsProc(const HWND hWnd, const LPARAM lParam)
                        } else if (!_tcsnicmp(pTask[i].ProcessName, _T("vim.exe"), sizeof(pTask[i].ProcessName))) {\r
                                szAppName.Format(_T("VIM"));\r
                        } else {\r
-                               CUtils::SetCorrectApplicationName(pTask[i].ProcessName, sizeof(pTask[i].ProcessName), szWindowName, sizeof(szWindowName));\r
+                               CUtils::SetCorrectApplicationName(pTask[i].ProcessName, szWindowName);\r
                                GetAppName(&szAppName, szWindowName);\r
                        }\r
                        break;\r
@@ -190,330 +476,204 @@ BOOL CALLBACK CProfile::EnumWindowsProc(const HWND hWnd, const LPARAM lParam)
        return TRUE;\r
 }\r
 \r
-       \r
-//////////////////////////////////////////////////////////////////////\r
-// Construction/Destruction\r
-//////////////////////////////////////////////////////////////////////\r
-\r
-CProfile::CProfile()\r
-{\r
-\r
-}\r
-\r
-CProfile::~CProfile()\r
-{\r
-\r
-}\r
-\r
-// This method initializes data in the registry, or retrieves and validates registry data.\r
-// bSaveAndValidate specifies a flag that indicates \r
-// whether registry data is being initialized (FALSE) or data is being retrieved (TRUE). \r
-void CProfile::UpdateRegistryData(const BOOL bSaveAndValidate)\r
-{\r
-       CString szEntry;\r
-       CString szApplicationName;\r
-       CString szApplicationTitle;\r
-       CString szWindowText;\r
-       CString szWindowTextType;\r
-\r
-       BOOL bUseDialogSetting = FALSE;\r
-\r
-       for (int nApplicationID = 0; nApplicationID < MAX_APP; ++nApplicationID) {\r
-               // application name\r
-               CString szSection(MAKEINTRESOURCE(IDS_REG_SECTION_APPLICATION));\r
-               szEntry.Format(IDS_REG_ENTRY_APPLICATION, nApplicationID);\r
-               if (bSaveAndValidate) { // retrieve\r
-                       m_XkeymacsData[nApplicationID].ClearAll();\r
-                       szApplicationName = AfxGetApp()->GetProfileString(szSection, szEntry);\r
-                       if (szApplicationName.IsEmpty()) {\r
-                               if (nApplicationID) {\r
-                                       if (!bUseDialogSetting) {\r
-                                               szApplicationName.LoadString(IDS_DIALOG);\r
-                                               bUseDialogSetting = TRUE;\r
-                                       } else {\r
-                                               continue;\r
-                                       }\r
-                               } else {\r
-                                       szApplicationName.LoadString(IDS_DEFAULT);\r
+struct {\r
+       int type;\r
+       CString cstr;\r
+} WindowTextTypes[] = {\r
+       { IDS_WINDOW_TEXT_MATCH, CString(MAKEINTRESOURCE(IDS_WINDOW_TEXT_MATCH)) },\r
+       { IDS_WINDOW_TEXT_MATCH_FORWARD, CString(MAKEINTRESOURCE(IDS_WINDOW_TEXT_MATCH_FORWARD)) },\r
+       { IDS_WINDOW_TEXT_MATCH_BACKWARD, CString(MAKEINTRESOURCE(IDS_WINDOW_TEXT_MATCH_BACKWARD)) },\r
+};\r
+\r
+inline int WindowTextType(const CString& cstr) {\r
+       for (int i = 0; i < _countof(WindowTextTypes); i++)\r
+               if (WindowTextTypes[i].cstr == cstr)\r
+                       return WindowTextTypes[i].type;\r
+       return IDS_WINDOW_TEXT_IGNORE;\r
+}\r
+\r
+void CProfile::LoadRegistory()\r
+{\r
+       bool bDialog = false;\r
+       const CString section(MAKEINTRESOURCE(IDS_REG_SECTION_APPLICATION));    \r
+       for (int nAppID = 0; nAppID < MAX_APP; nAppID++) {\r
+               CString entry;\r
+               entry.Format(IDS_REG_ENTRY_APPLICATION, nAppID);\r
+               CString appName = AfxGetApp()->GetProfileString(section, entry);\r
+               if (appName.IsEmpty())  {\r
+                       if (nAppID) {\r
+                               if (bDialog)\r
+                                       continue;\r
+                               appName.LoadString(IDS_DIALOG);\r
+                               bDialog = true;\r
+                       } else\r
+                               appName.LoadString(IDS_DEFAULT);\r
+               } else if (appName == CString(MAKEINTRESOURCE(IDS_DIALOG)))\r
+                       bDialog = true;\r
+               m_Data[nAppID].SetApplicationName(appName);\r
+\r
+               entry.LoadString(IDS_REG_ENTRY_APPLICATOIN_TITLE);\r
+               m_Data[nAppID].SetApplicationTitle(AfxGetApp()->GetProfileString(appName, entry));\r
+               entry.LoadString(IDS_REG_ENTRY_WINDOW_TEXT);\r
+               m_Data[nAppID].SetWindowText(AfxGetApp()->GetProfileString(appName, entry, _T("*")));\r
+               entry.LoadString(IDS_REG_ENTRY_WINDOW_TEXT_TYPE);\r
+               m_Data[nAppID].SetWindowTextType(WindowTextType(AfxGetApp()->GetProfileString(appName, entry)));\r
+\r
+               CString regApp(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA));\r
+               regApp += _T("\\") + appName;\r
+               for (int nCommandID = 1; nCommandID < MAX_COMMAND; nCommandID++) {\r
+                       entry = CCommands::GetCommandName(nCommandID);\r
+                       HKEY hKey;\r
+                       const CString& regKey = regApp + _T("\\") + entry;\r
+                       if (RegOpenKeyEx(HKEY_CURRENT_USER, regKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {\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 nCommandType, nKey;\r
+                                       ReadKeyBind(&nCommandType, &nKey, szKeyBind);\r
+                                       m_Data[nAppID].SetCommandID(nCommandType, nKey, nCommandID);\r
+                                       dwKeyBind = _countof(szKeyBind);\r
                                }\r
+                               RegCloseKey(hKey);\r
                        } else {\r
-                               if (szApplicationName == CString(MAKEINTRESOURCE(IDS_DIALOG))) {\r
-                                       bUseDialogSetting = TRUE;\r
+                               // Set the default assignment\r
+                               for (int i = 0; const int nKey = CCommands::GetDefaultCommandKey(nCommandID, i); i++) {\r
+                                       if (CCommands::GetDefaultControlID(nCommandID, i) == IDC_CO2)\r
+                                               continue;\r
+                                       const int nCommandType = CCommands::GetDefaultCommandType(nCommandID, i);\r
+                                       m_Data[nAppID].SetCommandID(nCommandType, nKey, nCommandID);\r
                                }\r
                        }\r
-                       m_XkeymacsData[nApplicationID].SetApplicationName(szApplicationName);\r
-               } else {                                // initialize\r
-                       szApplicationName = m_XkeymacsData[nApplicationID].GetApplicationName();\r
-                       if (szApplicationName.IsEmpty()) {\r
-                               continue;\r
-                       }\r
-                       AfxGetApp()->WriteProfileString(szSection, szEntry, szApplicationName);\r
-               }\r
-\r
-               // application title\r
-               szEntry.LoadString(IDS_REG_ENTRY_APPLICATOIN_TITLE);\r
-               if (bSaveAndValidate) { // retrieve\r
-                       szApplicationTitle = AfxGetApp()->GetProfileString(szApplicationName, szEntry);\r
-                       m_XkeymacsData[nApplicationID].SetApplicationTitle(szApplicationTitle);\r
-               } else {                                // initialize\r
-                       szApplicationTitle = m_XkeymacsData[nApplicationID].GetApplicationTitle();\r
-                       while (!szApplicationTitle.IsEmpty() && szApplicationTitle.GetAt(0) == _T(' ')) {\r
-                               szApplicationTitle.Delete(0);\r
-                       }\r
-                       AfxGetApp()->WriteProfileString(szApplicationName, szEntry, szApplicationTitle);\r
-               }\r
-\r
-               // window text\r
-               szEntry.LoadString(IDS_REG_ENTRY_WINDOW_TEXT);\r
-               if (bSaveAndValidate) { // retrieve\r
-                       szWindowText = AfxGetApp()->GetProfileString(szApplicationName, szEntry, _T("*"));\r
-                       if (szWindowText.IsEmpty()) {\r
-                               szWindowText = _T('*');\r
-                       }\r
-                       m_XkeymacsData[nApplicationID].SetWindowText(szWindowText);\r
-               } else {                                // initialize\r
-                       szWindowText = m_XkeymacsData[nApplicationID].GetWindowText();\r
-                       AfxGetApp()->WriteProfileString(szApplicationName, szEntry, szWindowText);\r
-               }\r
-\r
-               // window text type\r
-               szEntry.LoadString(IDS_REG_ENTRY_WINDOW_TEXT_TYPE);\r
-               if (bSaveAndValidate) { // retrieve\r
-                       szWindowTextType = AfxGetApp()->GetProfileString(szApplicationName, szEntry);\r
-\r
-                       int nWindowTextType = IDS_WINDOW_TEXT_IGNORE;\r
-                       if (szWindowTextType == CString(MAKEINTRESOURCE(IDS_WINDOW_TEXT_MATCH))) {\r
-                               nWindowTextType = IDS_WINDOW_TEXT_MATCH;\r
-                       } else if (szWindowTextType == CString(MAKEINTRESOURCE(IDS_WINDOW_TEXT_MATCH_FORWARD))) {\r
-                               nWindowTextType = IDS_WINDOW_TEXT_MATCH_FORWARD;\r
-                       } else if (szWindowTextType == CString(MAKEINTRESOURCE(IDS_WINDOW_TEXT_MATCH_BACKWARD))) {\r
-                               nWindowTextType = IDS_WINDOW_TEXT_MATCH_BACKWARD;\r
-                       } else if (szWindowTextType == CString(MAKEINTRESOURCE(IDS_WINDOW_TEXT_MATCH_FULL))) {\r
-                               nWindowTextType = IDS_WINDOW_TEXT_MATCH_FULL;\r
-                       }\r
-\r
-                       m_XkeymacsData[nApplicationID].SetWindowTextType(nWindowTextType);\r
-               } else {                                // initialize\r
-                       szWindowTextType.LoadString(m_XkeymacsData[nApplicationID].GetWindowTextType());\r
-                       AfxGetApp()->WriteProfileString(szApplicationName, szEntry, szWindowTextType);\r
                }\r
-\r
-               // on/off\r
-               if (bSaveAndValidate) { // retrieve\r
-                       for (int nCommandID = 1; nCommandID < sizeof(Commands) / sizeof(Commands[0]); ++nCommandID) {\r
-                               szEntry = CXkeymacsData::GetCommandName(nCommandID);\r
-                               if (szEntry.IsEmpty()) {\r
-                                       break;\r
-                               }\r
-\r
-                               HKEY hKey = NULL;\r
-                               CString szSubKey(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA));\r
-                               szSubKey += _T("\\") + szApplicationName + _T("\\") + szEntry;\r
-                               if (RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {\r
-                                       // Use registry data\r
-                                       TCHAR szKeyBind[128] = {'\0'};\r
-                                       DWORD dwKeyBind = sizeof(szKeyBind);\r
-                                       FILETIME ft = {'\0'};   // not use\r
-                                       for (DWORD dwIndex = 0;\r
-                                                RegEnumKeyEx(hKey, dwIndex, szKeyBind, &dwKeyBind, NULL, NULL, NULL, &ft) == ERROR_SUCCESS;\r
-                                                ++dwIndex) {\r
-                                               int nCommandType = 0;\r
-                                               int nKey = 0;\r
-                                               ReadKeyBind(&nCommandType, &nKey, szKeyBind);\r
-                                               m_XkeymacsData[nApplicationID].SetCommandID(nCommandType, nKey, nCommandID);\r
-\r
-//                                             if (nCommandType == CONTROL && nKey == 'D') {\r
-//                                                     CUtils::Log("GetProfileInt(at ibeam cursor only): %s, %s", szSubKey, szKeyBind);\r
-//                                             }\r
-                                               const CString szSection = szSubKey.Right(szSubKey.GetLength() - CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)).GetLength() - _tcslen(_T("\\"))) + _T("\\") + szKeyBind;\r
-                                               const BOOL bAtIbeamCursorOnly = AfxGetApp()->GetProfileInt(szSection, CString(MAKEINTRESOURCE(IDS_REG_ENTRY_AT_IBEAM_CURSOR_ONLY)), FALSE);\r
-                                               m_XkeymacsData[nApplicationID].SetAtIbeamCursorOnly(nCommandType, nKey, bAtIbeamCursorOnly);\r
-\r
-                                               memset(szKeyBind, 0, sizeof(szKeyBind));\r
-                                               dwKeyBind = sizeof(szKeyBind);\r
-                                       }\r
-                                       RegCloseKey(hKey);\r
-                               } else {\r
-                                       // Use default setting\r
-                                       for (int i = 0; ; ++i) {\r
-                                               if (CXkeymacsData::GetDefaultControlID(nCommandID, i) == IDC_CO2) {\r
-                                                       continue;\r
-                                               }\r
-\r
-                                               int nCommandType = CXkeymacsData::GetDefaultCommandType(nCommandID, i);\r
-                                               int nKey = CXkeymacsData::GetDefaultCommandKey(nCommandID, i);\r
-                                               if (nKey == 0) {\r
-                                                       break;\r
-                                               }\r
-                                               m_XkeymacsData[nApplicationID].SetCommandID(nCommandType, nKey, nCommandID);\r
-                                               m_XkeymacsData[nApplicationID].SetAtIbeamCursorOnly(nCommandType, nKey, FALSE);\r
-                                       }\r
-                               }\r
-                       }\r
-                       for (int nFunctionID = 0; nFunctionID < CDotXkeymacs::GetFunctionNumber(); ++nFunctionID) {\r
-                               HKEY hKey = NULL;\r
-                               CString szSubKey(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA));\r
-                               szSubKey += _T("\\") + szApplicationName + _T("\\") + CDotXkeymacs::GetFunctionSymbol(nFunctionID);\r
-                               if (RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {\r
-                                       // Use registry data\r
-                                       CDotXkeymacs::ClearKey(nFunctionID, nApplicationID);\r
-                                       TCHAR szKeyBind[128] = {'\0'};\r
-                                       DWORD dwKeyBind = sizeof(szKeyBind);\r
-                                       FILETIME ft = {'\0'};   // not use\r
-                                       for (DWORD dwIndex = 0; RegEnumKeyEx(hKey, dwIndex, szKeyBind, &dwKeyBind, NULL, NULL, NULL, &ft) == ERROR_SUCCESS; ++dwIndex) {\r
-                                               int nCommandType = 0;\r
-                                               int nKey = 0;\r
-                                               ReadKeyBind(&nCommandType, &nKey, szKeyBind);\r
-                                               CDotXkeymacs::SetKey(nFunctionID, nApplicationID, nCommandType, nKey);\r
-\r
-                                               memset(szKeyBind, 0, sizeof(szKeyBind));\r
-                                               dwKeyBind = sizeof(szKeyBind);\r
-                                       }\r
-                                       RegCloseKey(hKey);\r
-                               }\r
-                       }\r
-               } else {                                // initialize\r
-                       // create all commands\r
-                       for (int nCommandID = 1; nCommandID < sizeof(Commands) / sizeof(Commands[0]); ++nCommandID) {\r
-                               szEntry = CXkeymacsData::GetCommandName(nCommandID);\r
-                               if (szEntry.IsEmpty()) {\r
-                                       break;\r
-                               }\r
-\r
-                               SaveCommand(szApplicationName, nCommandID);\r
-                       }\r
-                       for (int nCommandType = 0; nCommandType < MAX_COMMAND_TYPE; ++nCommandType) {\r
-                               for (int nKey = 0; nKey < MAX_KEY; ++nKey) {\r
-                                       int nCommandID = m_XkeymacsData[nApplicationID].GetCommandID(nCommandType, nKey);\r
-                                       SaveKeyBind(szApplicationName, nCommandID, nCommandType, nKey);\r
-                               }\r
-                       }\r
-                       for (int nFunctionID = 0; nFunctionID < CDotXkeymacs::GetFunctionNumber(); ++nFunctionID) {\r
-                               for (int nKeyID = 0; nKeyID < CDotXkeymacs::GetKeyNumber(nFunctionID, nApplicationID); ++nKeyID) {\r
-                                       int nCommandType = 0;\r
-                                       int nKey = 0;\r
-                                       CDotXkeymacs::GetKey(nFunctionID, nApplicationID, nKeyID, &nCommandType, &nKey);\r
-                                       SaveKeyBind(szApplicationName, CDotXkeymacs::GetFunctionSymbol(nFunctionID), nCommandType, nKey);\r
+               for (int nFunctionID = 0; nFunctionID < CDotXkeymacs::GetFunctionNumber(); nFunctionID++) {\r
+                       HKEY hKey;\r
+                       const CString regKey = regApp + _T("\\") + CDotXkeymacs::GetFunctionSymbol(nFunctionID);\r
+                       if (RegOpenKeyEx(HKEY_CURRENT_USER, regKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {\r
+                               CDotXkeymacs::ClearKey(nFunctionID, 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 nCommandType, nKey;\r
+                                       ReadKeyBind(&nCommandType, &nKey, szKeyBind);\r
+                                       CDotXkeymacs::SetKey(nFunctionID, nAppID, nCommandType, nKey);\r
+                                       dwKeyBind = _countof(szKeyBind);\r
                                }\r
+                               RegCloseKey(hKey);\r
                        }\r
                }\r
 \r
-               // kill-ring-max\r
-               szEntry.LoadString(IDS_REG_ENTRY_KILL_RING_MAX);\r
-               if (bSaveAndValidate) { // retrieve\r
-                       int nKillRingMax = AfxGetApp()->GetProfileInt(szApplicationName, szEntry, 1);\r
-                       m_XkeymacsData[nApplicationID].SetKillRingMax(nKillRingMax);\r
-               } else {                                // initialize\r
-                       int nKillRingMax = m_XkeymacsData[nApplicationID].GetKillRingMax();\r
-                       AfxGetApp()->WriteProfileInt(szApplicationName, szEntry, nKillRingMax);\r
-               }\r
-\r
-               // Use Dialog Setting\r
-               szEntry.LoadString(IDS_REG_ENTRY_USE_DIALOG_SETTING);\r
-               if (bSaveAndValidate) { // retrieve\r
-                       BOOL bUseDialogSetting = AfxGetApp()->GetProfileInt(szApplicationName,szEntry, 1);\r
-                       m_XkeymacsData[nApplicationID].SetUseDialogSetting(bUseDialogSetting);\r
-               } else {                                // initialize\r
-                       BOOL bUseDialogSetting = m_XkeymacsData[nApplicationID].GetUseDialogSetting();\r
-                       AfxGetApp()->WriteProfileInt(szApplicationName, szEntry, bUseDialogSetting);\r
+               entry.LoadString(IDS_REG_ENTRY_KILL_RING_MAX);\r
+               m_Data[nAppID].SetKillRingMax(AfxGetApp()->GetProfileInt(appName, entry, 1));\r
+               entry.LoadString(IDS_REG_ENTRY_USE_DIALOG_SETTING);\r
+               m_Data[nAppID].SetUseDialogSetting(AfxGetApp()->GetProfileInt(appName, entry, 1));\r
+               entry.LoadString(IDS_REG_ENTRY_DISABLE_XKEYMACS);\r
+               m_Data[nAppID].SetSettingStyle(AfxGetApp()->GetProfileInt(appName, entry, 0) ? SETTING_DISABLE : SETTING_SPECIFIC);\r
+               entry.LoadString(IDC_REG_ENTRY_IGNORE_META_CTRL);\r
+               m_Data[nAppID].SetIgnoreUndefinedMetaCtrl(AfxGetApp()->GetProfileInt(appName, entry, 0));\r
+               entry.LoadString(IDC_REG_ENTRY_IGNORE_C_X);\r
+               m_Data[nAppID].SetIgnoreUndefinedC_x(AfxGetApp()->GetProfileInt(appName, entry, 0));\r
+               entry.LoadString(IDC_REG_ENTRY_ENABLE_CUA);\r
+               m_Data[nAppID].SetEnableCUA(AfxGetApp()->GetProfileInt(appName, entry, 0));\r
+               entry.LoadString(IDS_REG_ENTRY_326_COMPATIBLE);\r
+               m_Data[nAppID].Set326Compatible(AfxGetApp()->GetProfileInt(appName, entry, 0));\r
+       }\r
+}\r
+\r
+void CProfile::SaveRegistory()\r
+{\r
+       const CString section(MAKEINTRESOURCE(IDS_REG_SECTION_APPLICATION));    \r
+       for (int nAppID = 0; nAppID < MAX_APP; nAppID++) {\r
+               const CString& appName = m_Data[nAppID].GetApplicationName();\r
+               CString entry;\r
+               entry.Format(IDS_REG_ENTRY_APPLICATION, nAppID);\r
+               if (appName.IsEmpty()) {\r
+                       if (!AfxGetApp()->GetProfileString(section, entry).IsEmpty())\r
+                               AfxGetApp()->WriteProfileString(section, entry, _T(""));\r
+                       continue;\r
                }\r
-\r
-               // Setting Style\r
-               szEntry.LoadString(IDS_REG_ENTRY_DISABLE_XKEYMACS);\r
-               if (bSaveAndValidate) { // retrieve\r
-                       int nSettingStyle = SETTING_SPECIFIC;\r
-                       if (AfxGetApp()->GetProfileInt(szApplicationName, szEntry, 0) != 0) {\r
-                               nSettingStyle = SETTING_DISABLE;\r
-                       }\r
-                       m_XkeymacsData[nApplicationID].SetSettingStyle(nSettingStyle);\r
-               } else {                                // initialize\r
-                       BOOL bDisableXkeymacs = FALSE;\r
-                       if (m_XkeymacsData[nApplicationID].GetSettingStyle() == SETTING_DISABLE) {\r
-                               bDisableXkeymacs = TRUE;\r
+               AfxGetApp()->WriteProfileString(section, entry, appName);\r
+\r
+               entry.LoadString(IDS_REG_ENTRY_APPLICATOIN_TITLE);\r
+               CString appTitle = m_Data[nAppID].GetApplicationTitle();\r
+               appTitle.TrimLeft(_T(' '));\r
+               AfxGetApp()->WriteProfileString(appName, entry, appTitle);\r
+               entry.LoadString(IDS_REG_ENTRY_WINDOW_TEXT);\r
+               AfxGetApp()->WriteProfileString(appName, entry, m_Data[nAppID].GetWindowText());\r
+               entry.LoadString(IDS_REG_ENTRY_WINDOW_TEXT_TYPE);\r
+               AfxGetApp()->WriteProfileString(appName, entry, CString(MAKEINTRESOURCE(m_Data[nAppID].GetWindowTextType())));\r
+\r
+               CString regApp(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA));\r
+               regApp += _T("\\") + appName;\r
+               // Create all commands\r
+               for (int nCommandID = 1; nCommandID < MAX_COMMAND; nCommandID++)\r
+                       SaveCommand(appName, nCommandID);\r
+               for (int nCommandType = 0; nCommandType < MAX_COMMAND_TYPE; nCommandType++)\r
+                       for (int nKey = 0; nKey < MAX_KEY; nKey++)\r
+                               SaveKeyBind(appName, m_Data[nAppID].GetCommandID(nCommandType, nKey), nCommandType, nKey);\r
+               for (int nFunctionID = 0; nFunctionID < CDotXkeymacs::GetFunctionNumber(); nFunctionID++)\r
+                       for (int nKeyID = 0; nKeyID < CDotXkeymacs::GetKeyNumber(nFunctionID, nAppID); nKeyID++) {\r
+                               int nCommandType, nKey;\r
+                               CDotXkeymacs::GetKey(nFunctionID, nAppID, nKeyID, &nCommandType, &nKey);\r
+                               SaveKeyBind(appName, CDotXkeymacs::GetFunctionSymbol(nFunctionID), nCommandType, nKey);\r
                        }\r
-                       AfxGetApp()->WriteProfileInt(szApplicationName, szEntry, bDisableXkeymacs);\r
-               }\r
-\r
-               // Ignore Meta Ctrl+? when it is undefined.\r
-               szEntry.LoadString(IDC_REG_ENTRY_IGNORE_META_CTRL);\r
-               if (bSaveAndValidate) { // retrieve\r
-                       m_XkeymacsData[nApplicationID].SetIgnoreUndefinedMetaCtrl(AfxGetApp()->GetProfileInt(szApplicationName, szEntry, 0));\r
-               } else {                                // initialize\r
-                       AfxGetApp()->WriteProfileInt(szApplicationName, szEntry, m_XkeymacsData[nApplicationID].GetIgnoreUndefinedMetaCtrl());\r
-               }\r
 \r
-               // Ignore C-x ? when it is undefined.\r
-               szEntry.LoadString(IDC_REG_ENTRY_IGNORE_C_X);\r
-               if (bSaveAndValidate) { // retrieve\r
-                       m_XkeymacsData[nApplicationID].SetIgnoreUndefinedC_x(AfxGetApp()->GetProfileInt(szApplicationName, szEntry, 0));\r
-               } else {                                // initialize\r
-                       AfxGetApp()->WriteProfileInt(szApplicationName, szEntry, m_XkeymacsData[nApplicationID].GetIgnoreUndefinedC_x());\r
-               }\r
-\r
-               // Enable CUA-mode\r
-               szEntry.LoadString(IDC_REG_ENTRY_ENABLE_CUA);\r
-               if (bSaveAndValidate) { // retrieve\r
-                       m_XkeymacsData[nApplicationID].SetEnableCUA(AfxGetApp()->GetProfileInt(szApplicationName, szEntry, 0));\r
-               } else {                                // initialize\r
-                       AfxGetApp()->WriteProfileInt(szApplicationName, szEntry, m_XkeymacsData[nApplicationID].GetEnableCUA());\r
-               }\r
-\r
-               // Version 3.26 compatible mode\r
-               szEntry.LoadString(IDS_REG_ENTRY_326_COMPATIBLE);\r
-               if (bSaveAndValidate) { // retrieve\r
-                       m_XkeymacsData[nApplicationID].Set326Compatible(AfxGetApp()->GetProfileInt(szApplicationName, szEntry, 0));\r
-               } else {                                // initialize\r
-                       AfxGetApp()->WriteProfileInt(szApplicationName, szEntry, m_XkeymacsData[nApplicationID].Get326Compatible());\r
-               }\r
+               entry.LoadString(IDS_REG_ENTRY_KILL_RING_MAX);\r
+               AfxGetApp()->WriteProfileInt(appName, entry, m_Data[nAppID].GetKillRingMax());\r
+               entry.LoadString(IDS_REG_ENTRY_USE_DIALOG_SETTING);\r
+               AfxGetApp()->WriteProfileInt(appName, entry, m_Data[nAppID].GetUseDialogSetting());\r
+               entry.LoadString(IDS_REG_ENTRY_DISABLE_XKEYMACS);\r
+               AfxGetApp()->WriteProfileInt(appName, entry, m_Data[nAppID].GetSettingStyle() == SETTING_DISABLE);\r
+               entry.LoadString(IDC_REG_ENTRY_IGNORE_META_CTRL);\r
+               AfxGetApp()->WriteProfileInt(appName, entry, m_Data[nAppID].GetIgnoreUndefinedMetaCtrl());\r
+               entry.LoadString(IDC_REG_ENTRY_IGNORE_C_X);\r
+               AfxGetApp()->WriteProfileInt(appName, entry, m_Data[nAppID].GetIgnoreUndefinedC_x());\r
+               entry.LoadString(IDC_REG_ENTRY_ENABLE_CUA);\r
+               AfxGetApp()->WriteProfileInt(appName, entry, m_Data[nAppID].GetEnableCUA());\r
+               entry.LoadString(IDS_REG_ENTRY_326_COMPATIBLE);\r
+               AfxGetApp()->WriteProfileInt(appName, entry, m_Data[nAppID].Get326Compatible());\r
        }\r
 }\r
 \r
-void CProfile::LoadRegistryData()\r
+void CProfile::LoadData()\r
 {\r
        CDotXkeymacs::Load();\r
        LevelUp();\r
-       UpdateRegistryData(TRUE);\r
+       LoadRegistory();\r
 }\r
 \r
-void CProfile::SaveRegistryData()\r
+void CProfile::SaveData()\r
 {\r
        DeleteAllRegistryData();\r
-       UpdateRegistryData(FALSE);\r
+       SaveRegistory();\r
        SetDllData();\r
 }\r
 \r
 void CProfile::SetDllData()\r
 {\r
-       CMainFrame *pMainFrame = (CMainFrame*)AfxGetMainWnd();\r
-\r
-       pMainFrame->m_pXkeymacsDll->ClearFunctionDefinition();\r
+       CXkeymacsDll::ClearFunctionDefinition();\r
        for (int nFunctionID = 0; nFunctionID < CDotXkeymacs::GetFunctionNumber(); ++nFunctionID) {\r
-               pMainFrame->m_pXkeymacsDll->SetFunctionDefinition(nFunctionID, CDotXkeymacs::GetFunctionDefinition(nFunctionID));\r
+               CXkeymacsDll::SetFunctionDefinition(nFunctionID, CDotXkeymacs::GetFunctionDefinition(nFunctionID));\r
        }\r
 \r
        for (int nApplicationID = 0; nApplicationID < MAX_APP; ++nApplicationID) {\r
 \r
-               CString szApplicationName = m_XkeymacsData[nApplicationID].GetApplicationName();\r
+               CString szApplicationName = m_Data[nApplicationID].GetApplicationName();\r
 \r
                if (szApplicationName.IsEmpty()) {\r
-                       pMainFrame->m_pXkeymacsDll->Clear(nApplicationID);\r
+                       CXkeymacsDll::Clear(nApplicationID);\r
                        continue;\r
                }\r
 \r
-               pMainFrame->m_pXkeymacsDll->SetApplicationName(nApplicationID, szApplicationName);\r
-               pMainFrame->m_pXkeymacsDll->SetWindowText(nApplicationID, m_XkeymacsData[nApplicationID].GetWindowText());\r
-               pMainFrame->m_pXkeymacsDll->SetCommandID(nApplicationID, CONTROL, 'X', 0);\r
-               pMainFrame->m_pXkeymacsDll->SetAtIbeamCursorOnly(nApplicationID, CONTROL, 'X', FALSE);\r
+               CXkeymacsDll::SetApplicationName(nApplicationID, szApplicationName);\r
+               CXkeymacsDll::SetWindowText(nApplicationID, m_Data[nApplicationID].GetWindowText());\r
+               CXkeymacsDll::SetCommandID(nApplicationID, CONTROL, 'X', 0);\r
 \r
                for (int nCommandType = 0; nCommandType < MAX_COMMAND_TYPE; ++nCommandType) {\r
                        for (int nKey = 0; nKey < MAX_KEY; ++nKey) {\r
-                               const int nCommandID = m_XkeymacsData[nApplicationID].GetCommandID(nCommandType, nKey);\r
-                               pMainFrame->m_pXkeymacsDll->SetCommandID(nApplicationID, nCommandType, nKey, nCommandID);\r
-                               const BOOL bAtIbeamCursorOnly = m_XkeymacsData[nApplicationID].GetAtIbeamCursorOnly(nCommandType, nKey);\r
-                               pMainFrame->m_pXkeymacsDll->SetAtIbeamCursorOnly(nApplicationID, nCommandType, nKey, bAtIbeamCursorOnly);\r
+                               const int nCommandID = m_Data[nApplicationID].GetCommandID(nCommandType, nKey);\r
+                               CXkeymacsDll::SetCommandID(nApplicationID, nCommandType, nKey, nCommandID);\r
                                if ((nCommandType & CONTROLX) && nCommandID) {\r
-                                       pMainFrame->m_pXkeymacsDll->SetCommandID(nApplicationID, CONTROL, 'X', 1);                      // Commands[1] is C-x\r
-                                       pMainFrame->m_pXkeymacsDll->SetAtIbeamCursorOnly(nApplicationID, CONTROL, 'X', bAtIbeamCursorOnly);\r
+                                       CXkeymacsDll::SetCommandID(nApplicationID, CONTROL, 'X', 1);                    // Commands[1] is C-x\r
                                }\r
                        }\r
                }\r
@@ -523,23 +683,27 @@ void CProfile::SetDllData()
                                int nCommandType = 0;\r
                                int nKey = 0;\r
                                CDotXkeymacs::GetKey(nFunctionID, nApplicationID, nKeyID, &nCommandType, &nKey);\r
-                               pMainFrame->m_pXkeymacsDll->SetFunctionKey(nFunctionID, nApplicationID, nCommandType, nKey);\r
+                               CXkeymacsDll::SetFunctionKey(nFunctionID, nApplicationID, nCommandType, nKey);\r
                                if (nCommandType & CONTROLX) {\r
-                                       pMainFrame->m_pXkeymacsDll->SetCommandID(nApplicationID, CONTROL, 'X', 1);                      // Commands[1] is C-x\r
-                                       const BOOL bAtIbeamCursorOnly = m_XkeymacsData[nApplicationID].GetAtIbeamCursorOnly(nCommandType, nKey);\r
-                                       pMainFrame->m_pXkeymacsDll->SetAtIbeamCursorOnly(nApplicationID, CONTROL, 'X', bAtIbeamCursorOnly);\r
+                                       CXkeymacsDll::SetCommandID(nApplicationID, CONTROL, 'X', 1);                    // Commands[1] is C-x\r
                                }\r
                        }\r
                }\r
 \r
-               pMainFrame->m_pXkeymacsDll->SetKillRingMax(nApplicationID, m_XkeymacsData[nApplicationID].GetKillRingMax());\r
-               pMainFrame->m_pXkeymacsDll->SetUseDialogSetting(nApplicationID, m_XkeymacsData[nApplicationID].GetUseDialogSetting());\r
-               pMainFrame->m_pXkeymacsDll->SetSettingStyle(nApplicationID, m_XkeymacsData[nApplicationID].GetSettingStyle());\r
-               pMainFrame->m_pXkeymacsDll->SetIgnoreUndefinedMetaCtrl(nApplicationID, m_XkeymacsData[nApplicationID].GetIgnoreUndefinedMetaCtrl());\r
-               pMainFrame->m_pXkeymacsDll->SetIgnoreUndefinedC_x(nApplicationID, m_XkeymacsData[nApplicationID].GetIgnoreUndefinedC_x());\r
-               pMainFrame->m_pXkeymacsDll->SetEnableCUA(nApplicationID, m_XkeymacsData[nApplicationID].GetEnableCUA());\r
-               pMainFrame->m_pXkeymacsDll->Set326Compatible(nApplicationID, m_XkeymacsData[nApplicationID].Get326Compatible());\r
+               CXkeymacsDll::SetKillRingMax(nApplicationID, m_Data[nApplicationID].GetKillRingMax());\r
+               CXkeymacsDll::SetUseDialogSetting(nApplicationID, m_Data[nApplicationID].GetUseDialogSetting());\r
+               CXkeymacsDll::SetSettingStyle(nApplicationID, m_Data[nApplicationID].GetSettingStyle());\r
+               CXkeymacsDll::SetIgnoreUndefinedMetaCtrl(nApplicationID, m_Data[nApplicationID].GetIgnoreUndefinedMetaCtrl());\r
+               CXkeymacsDll::SetIgnoreUndefinedC_x(nApplicationID, m_Data[nApplicationID].GetIgnoreUndefinedC_x());\r
+               CXkeymacsDll::SetEnableCUA(nApplicationID, m_Data[nApplicationID].GetEnableCUA());\r
+               CXkeymacsDll::Set326Compatible(nApplicationID, m_Data[nApplicationID].Get326Compatible());\r
        }\r
+       CXkeymacsApp *pApp = static_cast<CXkeymacsApp *>(AfxGetApp());\r
+       if (!pApp->IsWow64())\r
+               return;\r
+       if (!CXkeymacsDll::SaveConfig())\r
+               return;\r
+       pApp->SendIPCMessage(XKEYMACS_RELOAD);\r
 }\r
 \r
 void CProfile::ReadKeyBind(int *const pnCommandType, int *const pnKey, LPCTSTR szKeyBind)\r
@@ -567,7 +731,7 @@ int CProfile::KeyBind2CommandType(LPCTSTR szKeyBind)
 \r
 int CProfile::KeyBind2Key(LPCTSTR szKey)\r
 {\r
-       for (int nKey = 1; nKey < 0xff; ++nKey) {\r
+       for (int nKey = 1; nKey <= 0xff; ++nKey) {\r
                if (!_tcscmp(szKey, Key2String(nKey))) {\r
                        return nKey;\r
                }\r
@@ -625,7 +789,7 @@ void CProfile::SaveKeyBind(const CString szApplicationName, const int nCommandID
                return;\r
        }\r
 \r
-       CString szCommandName = CXkeymacsData::GetCommandName(nCommandID);\r
+       CString szCommandName = CCommands::GetCommandName(nCommandID);\r
        if (szCommandName.IsEmpty()) {\r
                return;\r
        }\r
@@ -655,7 +819,8 @@ void CProfile::SaveCommand(const CString szApplicationName, const int nCommandID
 \r
 void CProfile::AddKeyBind2C_(const CString szApplicationName, const BYTE bVk)\r
 {\r
-       for (int nCommandID = 0; nCommandID < sizeof(Commands) / sizeof(Commands[0]); ++nCommandID) {\r
+       int nCommandID;\r
+       for (nCommandID = 0; nCommandID < MAX_COMMAND; ++nCommandID) {\r
                if (Commands[nCommandID].fCommand == CCommands::C_) {\r
                        break;\r
                }\r
@@ -673,7 +838,6 @@ void CProfile::LevelUp()
        CString szEntry;\r
        szEntry.Format(_T("Level"));\r
 \r
-//     const int nCurrentLevel = AfxGetApp()->GetProfileInt(szSection, szEntry, nDefalutLevel);\r
        switch (AfxGetApp()->GetProfileInt(szSection, szEntry, nDefalutLevel)) {\r
        case nDefalutLevel:\r
                {\r
@@ -787,19 +951,20 @@ void CProfile::LevelUp()
 \r
 void CProfile::InitDllData()\r
 {\r
-       LoadRegistryData();\r
+       LoadData();\r
        SetDllData();\r
 }\r
 \r
 void CProfile::ClearData(const CString szCurrentApplication)\r
 {\r
-       for (int nApplicationID = 0; nApplicationID < MAX_APP; ++nApplicationID) {\r
-               if (m_XkeymacsData[nApplicationID].GetApplicationName() == szCurrentApplication) {\r
+       int nApplicationID;\r
+       for (nApplicationID = 0; nApplicationID < MAX_APP; ++nApplicationID) {\r
+               if (m_Data[nApplicationID].GetApplicationName() == szCurrentApplication) {\r
                        break;\r
                }\r
        }\r
        if (nApplicationID < MAX_APP) {\r
-               m_XkeymacsData[nApplicationID].ClearAll();\r
+               m_Data[nApplicationID].ClearAll();\r
        }\r
 }\r
 \r
@@ -810,7 +975,7 @@ int CProfile::GetSavedSettingCount()
 \r
        for (int nApplicationID = 0; nApplicationID < MAX_APP; ++nApplicationID) {\r
                CString szApplicationName;\r
-               szApplicationName = m_XkeymacsData[nApplicationID].GetApplicationName();\r
+               szApplicationName = m_Data[nApplicationID].GetApplicationName();\r
                if (!szApplicationName.IsEmpty()) {\r
                        ++nSavedSetting;\r
                }\r
@@ -823,13 +988,13 @@ void CProfile::InitApplicationList(CComboBox *const cApplicationList)
 {\r
        cApplicationList->ResetContent();\r
 \r
-       m_dwTasks = GetTaskList(m_TaskList, MAX_TASKS);\r
+       GetTaskList();\r
 \r
        EnumWindows(EnumWindowsProc, (LPARAM)cApplicationList);\r
 \r
        for (int i = 0; i < MAX_APP; ++i) {\r
-               CString szApplicationName       = m_XkeymacsData[i].GetApplicationName();\r
-               CString szApplicationTitle      = m_XkeymacsData[i].GetApplicationTitle();\r
+               CString szApplicationName       = m_Data[i].GetApplicationName();\r
+               CString szApplicationTitle      = m_Data[i].GetApplicationTitle();\r
 \r
                CString szListItem;\r
                szListItem.Format(IDS_APPLICATION_LIST_ITEM, szApplicationTitle, szApplicationName);\r
@@ -886,209 +1051,24 @@ void CProfile::InitApplicationList(CComboBox *const cApplicationList)
        cApplicationList->SelectString(-1, CString(MAKEINTRESOURCE(IDS_DEFAULT_TITLE)));\r
 }\r
 \r
-DWORD CProfile::GetTaskList(PTASK_LIST pTask, const DWORD dwNumTasks)\r
+void CProfile::GetTaskList()\r
 {\r
-       for (int i = 0; i < MAX_TASKS; ++i) {\r
-               ZeroMemory(&pTask[i], sizeof(PTASK_LIST));\r
-       }\r
-\r
-       OSVERSIONINFO verInfo = {0};\r
-       verInfo.dwOSVersionInfoSize = sizeof (verInfo);\r
-       GetVersionEx(&verInfo);\r
-       if (verInfo.dwPlatformId == VER_PLATFORM_WIN32_NT\r
-        && verInfo.dwMajorVersion < 5) {\r
-               return GetTaskListNT(pTask, dwNumTasks);\r
-       }\r
-\r
-       HMODULE hKernel = GetModuleHandle(_T("KERNEL32.DLL"));\r
-       if (!hKernel) {\r
-               return 0;\r
-       }\r
-\r
-       CREATESNAPSHOT pCreateToolhelp32Snapshot = (CREATESNAPSHOT)GetProcAddress(hKernel, "CreateToolhelp32Snapshot");\r
-       if (!pCreateToolhelp32Snapshot) {\r
-               return 0;\r
-       }\r
-\r
-       PROCESSWALK pProcess32First = (PROCESSWALK)GetProcAddress(hKernel, "Process32First");\r
-       if (!pProcess32First) {\r
-               return 0;\r
-       }\r
-\r
-       PROCESSWALK pProcess32Next = (PROCESSWALK)GetProcAddress(hKernel, "Process32Next");\r
-       if (!pProcess32Next) {\r
-               return 0;\r
-       }\r
+       ZeroMemory(m_TaskList, sizeof(m_TaskList));\r
 \r
-       HANDLE hProcessSnap = pCreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);\r
-       if (hProcessSnap == (HANDLE)-1) {\r
-               return 0;\r
-       }\r
+       HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);\r
+       if (hProcessSnap == (HANDLE)-1)\r
+               return;\r
 \r
-       DWORD dwTaskCount = 0;\r
+       m_dwTasks = 0;\r
        PROCESSENTRY32 processEntry32 = {sizeof(PROCESSENTRY32)};\r
-       if (pProcess32First(hProcessSnap, &processEntry32)) {\r
+       if (Process32First(hProcessSnap, &processEntry32)) {\r
                do {\r
-                       LPTSTR pCurChar = NULL;\r
-                       for (pCurChar = processEntry32.szExeFile + lstrlen(processEntry32.szExeFile); *pCurChar != _T('\\') && pCurChar != processEntry32.szExeFile; --pCurChar) {\r
-                               ;\r
-                       }\r
-                       if (*pCurChar == _T('\\')) {\r
-                               ++pCurChar;\r
-                       }\r
-\r
-                       lstrcpy(pTask->ProcessName, pCurChar);\r
-                       pTask->dwProcessId = processEntry32.th32ProcessID;\r
-\r
-                       ++dwTaskCount;\r
-                       ++pTask;\r
-               } while (dwTaskCount < dwNumTasks && pProcess32Next(hProcessSnap, &processEntry32));\r
+                       lstrcpy(m_TaskList[m_dwTasks].ProcessName, processEntry32.szExeFile);\r
+                       m_TaskList[m_dwTasks++].dwProcessId = processEntry32.th32ProcessID;\r
+               } while (m_dwTasks < MAX_TASKS && Process32Next(hProcessSnap, &processEntry32));\r
        }\r
 \r
        CloseHandle(hProcessSnap);\r
-       return dwTaskCount;\r
-}\r
-\r
-LPBYTE CProfile::GetCounters()\r
-{\r
-       LANGID lid = MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL);\r
-       CString szSubKey;\r
-       szSubKey.Format(CString(MAKEINTRESOURCE(IDS_REGSUBKEY_PERF)), lid);\r
-       HKEY hKey = NULL;\r
-       if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szSubKey, 0, KEY_READ, &hKey) != ERROR_SUCCESS) {\r
-               return NULL;\r
-       }\r
-\r
-       DWORD dwSize = 0;\r
-       if (RegQueryValueEx(hKey, CString(MAKEINTRESOURCE(IDS_REGSUBKEY_COUNTERS)), NULL, NULL, NULL, &dwSize) != ERROR_SUCCESS) {\r
-               RegCloseKey(hKey);\r
-               return NULL;\r
-       }\r
-       LPBYTE pCounters = (LPBYTE) calloc(dwSize, sizeof(BYTE));\r
-       if (pCounters == NULL) {\r
-               RegCloseKey(hKey);\r
-               return NULL;\r
-       }\r
-       if (RegQueryValueEx(hKey, CString(MAKEINTRESOURCE(IDS_REGSUBKEY_COUNTERS)), NULL, NULL, pCounters, &dwSize) != ERROR_SUCCESS) {\r
-               RegCloseKey(hKey);\r
-               free(pCounters);\r
-               return NULL;\r
-       }\r
-       RegCloseKey(hKey);\r
-       return pCounters;\r
-}\r
-\r
-BOOL CProfile::GetProcessInfo(CString *const szProcessName, DWORD *const dwProcessId)\r
-{\r
-       LPBYTE pCounters = GetCounters();\r
-       if (!pCounters) {\r
-               return FALSE;\r
-       }\r
-       LPTSTR pTopOfString = (LPTSTR)pCounters;\r
-       while (*pTopOfString) {\r
-               if (_tcsicmp(pTopOfString, CString(MAKEINTRESOURCE(IDS_PROCESS))) == 0) {\r
-                       for (LPTSTR p2 = pTopOfString - 2; _istdigit(*p2); --p2) {\r
-                               ;\r
-                       }\r
-                       szProcessName->Format(_T("%s"), p2 + 1);        // 230\r
-               } else if (_tcsicmp(pTopOfString, CString(MAKEINTRESOURCE(IDS_PROCESSID))) == 0) {\r
-                       for (LPTSTR p2 = pTopOfString - 2; _istdigit(*p2); --p2) {\r
-                               ;\r
-                       }\r
-                       *dwProcessId = _ttol(p2 + 1);                   // 784\r
-               }\r
-               pTopOfString += (_tcslen(pTopOfString) + 1);\r
-       }\r
-       free(pCounters);\r
-       return TRUE;\r
-}\r
-\r
-PPERF_DATA_BLOCK CProfile::GetPerformanceData(const CString szProcessName)\r
-{\r
-       DWORD dwSize = INITIAL_SIZE;\r
-       PPERF_DATA_BLOCK pPerformanceData = (PPERF_DATA_BLOCK) calloc(dwSize, sizeof(BYTE));\r
-       if (pPerformanceData == NULL) {\r
-               return NULL;\r
-       }\r
-\r
-       for (;;) {\r
-               switch (RegQueryValueEx(HKEY_PERFORMANCE_DATA, szProcessName, NULL, NULL, (LPBYTE)pPerformanceData, &dwSize)) {\r
-               case ERROR_SUCCESS:\r
-                       if (0 < dwSize\r
-                        && pPerformanceData->Signature[0] == (WCHAR)'P'\r
-                        && pPerformanceData->Signature[1] == (WCHAR)'E'\r
-                        && pPerformanceData->Signature[2] == (WCHAR)'R'\r
-                        && pPerformanceData->Signature[3] == (WCHAR)'F') {\r
-                               return pPerformanceData;\r
-                       }\r
-               case ERROR_MORE_DATA:\r
-                       dwSize += EXTEND_SIZE;\r
-                       pPerformanceData = (PPERF_DATA_BLOCK) realloc(pPerformanceData, dwSize);\r
-                       if (!pPerformanceData) {\r
-                               return NULL;\r
-                       }\r
-                       memset(pPerformanceData, 0, dwSize);\r
-                       break;\r
-               default:\r
-                       free(pPerformanceData);\r
-                       return NULL;\r
-               }\r
-       }\r
-}\r
-\r
-// Add running application's names to the list\r
-// only for _Windows NT_\r
-DWORD CProfile::GetTaskListNT(PTASK_LIST pTask, DWORD dwNumTasks)\r
-{\r
-       CString szProcessName;\r
-       DWORD dwProcessIdTitle = 0;\r
-       if (!GetProcessInfo(&szProcessName, &dwProcessIdTitle)) {\r
-               return dwNumTasks;\r
-       }\r
-\r
-       PPERF_DATA_BLOCK pPerformanceData = GetPerformanceData(szProcessName);\r
-       if (!pPerformanceData) {\r
-               return dwNumTasks;\r
-       }\r
-\r
-       PPERF_OBJECT_TYPE pObj = (PPERF_OBJECT_TYPE) ((DWORD)pPerformanceData + pPerformanceData->HeaderLength);\r
-       PPERF_COUNTER_DEFINITION pCounterDef = (PPERF_COUNTER_DEFINITION) ((DWORD)pObj + pObj->HeaderLength);\r
-       DWORD dwProcessIdCounter = 0;\r
-       for (DWORD i = 0; i < pObj->NumCounters; ++i) {\r
-               if (pCounterDef->CounterNameTitleIndex == dwProcessIdTitle) {\r
-                       dwProcessIdCounter = pCounterDef->CounterOffset;\r
-                       break;\r
-               }\r
-               ++pCounterDef;\r
-       }\r
-\r
-       dwNumTasks = min(dwNumTasks - 1, (DWORD)pObj->NumInstances);\r
-       PPERF_INSTANCE_DEFINITION pInst = (PPERF_INSTANCE_DEFINITION) ((DWORD)pObj + pObj->DefinitionLength);\r
-       for (i = 0; i < dwNumTasks; ++i) {\r
-               LPCWSTR pProcessName = (LPCWSTR) ((DWORD)pInst + pInst->NameOffset);\r
-\r
-               CHAR szProcessName[MAX_PATH] = {'\0'};\r
-               if (!WideCharToMultiByte(CP_ACP, 0, pProcessName, -1, szProcessName, sizeof(szProcessName), NULL, NULL)) {\r
-                       _tcscpy(pTask->ProcessName, CString(MAKEINTRESOURCE(IDS_UNKNOWN_TASK)));\r
-               }\r
-\r
-               if (_tcslen(szProcessName)+4 <= sizeof(pTask->ProcessName)) {\r
-                       _tcscpy(pTask->ProcessName, szProcessName);\r
-                       _tcscat(pTask->ProcessName, CString(MAKEINTRESOURCE(IDS_EXTENSION_EXECUTABLE)));\r
-               }\r
-\r
-               PPERF_COUNTER_BLOCK pCounter = (PPERF_COUNTER_BLOCK) ((DWORD)pInst + pInst->ByteLength);\r
-               pTask->dwProcessId = *((LPDWORD) ((DWORD)pCounter + dwProcessIdCounter));\r
-               if (pTask->dwProcessId == 0) {\r
-                       pTask->dwProcessId = (DWORD) -2;\r
-               }\r
-\r
-               ++pTask;\r
-               pInst = (PPERF_INSTANCE_DEFINITION) ((DWORD)pCounter + pCounter->ByteLength);\r
-       }\r
-\r
-       free(pPerformanceData);\r
-       return dwNumTasks;\r
 }\r
 \r
 // return application index\r
@@ -1105,9 +1085,9 @@ int CProfile::GetApplicationIndex(const CString szApplicationName, const BOOL bS
        if (nApplicationID == MAX_APP) {\r
                if (bSaveAndValidate) { // GetDialogData\r
                        for (nApplicationID = 0; nApplicationID < MAX_APP; ++nApplicationID) {\r
-                               CString sz = m_XkeymacsData[nApplicationID].GetApplicationName();\r
+                               CString sz = m_Data[nApplicationID].GetApplicationName();\r
                                if (sz.IsEmpty()) {\r
-                                       m_XkeymacsData[nApplicationID].SetApplicationName(szApplicationName);\r
+                                       m_Data[nApplicationID].SetApplicationName(szApplicationName);\r
                                        break;\r
                                }\r
                        }\r
@@ -1116,7 +1096,7 @@ int CProfile::GetApplicationIndex(const CString szApplicationName, const BOOL bS
                        }\r
                } else {                                // SetDialogData\r
                        for (nApplicationID = 0; nApplicationID < MAX_APP; ++nApplicationID) {\r
-                               if (IsDefault(m_XkeymacsData[nApplicationID].GetApplicationName())) {\r
+                               if (IsDefault(m_Data[nApplicationID].GetApplicationName())) {\r
                                        *nSettingStyle = SETTING_DEFAULT;\r
                                        break;\r
                                }\r
@@ -1128,16 +1108,48 @@ int CProfile::GetApplicationIndex(const CString szApplicationName, const BOOL bS
        }\r
 \r
        if (bSaveAndValidate) { // GetDialogData\r
-               m_XkeymacsData[nApplicationID].SetSettingStyle(*nSettingStyle);\r
+               m_Data[nApplicationID].SetSettingStyle(*nSettingStyle);\r
        } else {                                // SetDialogData\r
                if (*nSettingStyle == SETTING_UNDEFINED) {      // It means that *nSettingStyle != SETTING_DEFAULT.\r
-                       *nSettingStyle = m_XkeymacsData[nApplicationID].GetSettingStyle();\r
+                       *nSettingStyle = m_Data[nApplicationID].GetSettingStyle();\r
                }\r
        }\r
 \r
        return nApplicationID;\r
 }\r
 \r
+BOOL CProfile::Is106Keyboard()\r
+{\r
+       static KEYBOARD_TYPE keyboard = UNKNOWN_KEYBOARD;\r
+\r
+       if (keyboard == UNKNOWN_KEYBOARD) {\r
+               OSVERSIONINFO verInfo = {0};\r
+               verInfo.dwOSVersionInfoSize = sizeof (verInfo);\r
+               GetVersionEx(&verInfo);\r
+\r
+               DWORD subtype = 0;\r
+               DWORD cbData = sizeof(subtype);\r
+\r
+               if (verInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {\r
+                       HKEY hKey = NULL;\r
+                       CString szSubKey(_T("SYSTEM\\CurrentControlSet\\Services\\i8042prt\\Parameters"));\r
+                       if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szSubKey, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) {\r
+                               static const CString szValueName(_T("OverrideKeyboardSubtype"));\r
+                               if (RegQueryValueEx(hKey, szValueName, NULL, NULL, (LPBYTE)&subtype, &cbData) != ERROR_SUCCESS) {\r
+                                       subtype = 0;\r
+                               }\r
+                               RegCloseKey(hKey);\r
+                       }\r
+               } else if (verInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {\r
+                       subtype = GetPrivateProfileInt(_T("keyboard"), _T("subtype"), 0, _T("system.ini"));\r
+               }\r
+\r
+               keyboard = (subtype & 0x02) ? JAPANESE_KEYBOARD : ENGLISH_KEYBOARD;\r
+       }\r
+\r
+       return keyboard == JAPANESE_KEYBOARD;\r
+}\r
+\r
 BOOL CProfile::IsTheString(const CString sz, const UINT nID)\r
 {\r
        return sz == CString(MAKEINTRESOURCE(nID));\r
@@ -1179,7 +1191,7 @@ void CProfile::UpdateApplicationTitle(CComboBox *const cApplicationList, const C
        static CString szApplicationTitle;\r
        if (bSaveAndValidate) { // GetDialogData\r
                if (!CProfile::IsDefault(szCurrentApplication)) {\r
-                       m_XkeymacsData[nApplicationID].SetApplicationTitle(szApplicationTitle);\r
+                       m_Data[nApplicationID].SetApplicationTitle(szApplicationTitle);\r
                }\r
                szApplicationTitle.Empty();\r
        } else {                                // SetDialogData\r
@@ -1196,21 +1208,21 @@ void CProfile::SetCommandID(const int nApplicationID, const int nCommandType, co
 {\r
        if (nKey == 0xf0 && Commands[nCommandID].fCommand == CCommands::C_) {\r
                // Change CommandID C_Eisu\r
-               for (nCommandID = 1; nCommandID < sizeof(Commands) / sizeof(Commands[0]); ++nCommandID) {\r
+               for (nCommandID = 1; nCommandID < MAX_COMMAND; ++nCommandID) {\r
                        if (Commands[nCommandID].fCommand == CCommands::C_Eisu) {\r
                                break;\r
                        }\r
                }\r
        }\r
-       m_XkeymacsData[nApplicationID].SetCommandID(nCommandType, nKey, nCommandID);\r
+       m_Data[nApplicationID].SetCommandID(nCommandType, nKey, nCommandID);\r
 }\r
 \r
 int CProfile::GetCommandID(const int nApplicationID, const int nCommandType, const int nKey)\r
 {\r
-       int nCommandID = m_XkeymacsData[nApplicationID].GetCommandID(nCommandType, nKey);\r
+       int nCommandID = m_Data[nApplicationID].GetCommandID(nCommandType, nKey);\r
        if (nKey == 0xf0 && Commands[nCommandID].fCommand == CCommands::C_Eisu) {\r
                // Change CommandID C_\r
-               for (nCommandID = 1; nCommandID < sizeof(Commands) / sizeof(Commands[0]); ++nCommandID) {\r
+               for (nCommandID = 1; nCommandID < MAX_COMMAND; ++nCommandID) {\r
                        if (Commands[nCommandID].fCommand == CCommands::C_) {\r
                                break;\r
                        }\r
@@ -1221,32 +1233,32 @@ int CProfile::GetCommandID(const int nApplicationID, const int nCommandType, con
 \r
 void CProfile::SetKillRingMax(const int nApplicationID, const int nKillRingMax)\r
 {\r
-       m_XkeymacsData[nApplicationID].SetKillRingMax(nKillRingMax);\r
+       m_Data[nApplicationID].SetKillRingMax(nKillRingMax);\r
 }\r
 \r
 int CProfile::GetKillRingMax(const int nApplicationID)\r
 {\r
-       return m_XkeymacsData[nApplicationID].GetKillRingMax();\r
+       return m_Data[nApplicationID].GetKillRingMax();\r
 }\r
 \r
 void CProfile::SetUseDialogSetting(const int nApplicationID, const BOOL bUseDialogSetting)\r
 {\r
-       m_XkeymacsData[nApplicationID].SetUseDialogSetting(bUseDialogSetting);\r
+       m_Data[nApplicationID].SetUseDialogSetting(bUseDialogSetting);\r
 }\r
 \r
 BOOL CProfile::GetUseDialogSetting(const int nApplicationID)\r
 {\r
-       return m_XkeymacsData[nApplicationID].GetUseDialogSetting();\r
+       return m_Data[nApplicationID].GetUseDialogSetting();\r
 }\r
 \r
 void CProfile::SetWindowText(const int nApplicationID, const CString szWindowText)\r
 {\r
-       m_XkeymacsData[nApplicationID].SetWindowText(szWindowText);\r
+       m_Data[nApplicationID].SetWindowText(szWindowText);\r
 }\r
 \r
 CString CProfile::GetWindowText(const int nApplicationID)\r
 {\r
-       return m_XkeymacsData[nApplicationID].GetWindowText();\r
+       return m_Data[nApplicationID].GetWindowText();\r
 }\r
 \r
 void CProfile::DeleteAllRegistryData()\r
@@ -1294,17 +1306,17 @@ void CProfile::CopyData(const CString szDestinationApplication, const CString sz
        int nDestinationApplication = GetApplicationIndex(szDestinationApplication, TRUE, &nSettingStyle);\r
        int nSourceApplication = GetApplicationIndex(szSourceApplication);\r
 \r
-       CString szApplicationName = m_XkeymacsData[nDestinationApplication].GetApplicationName();\r
-       CString szApplicationTitle = m_XkeymacsData[nDestinationApplication].GetApplicationTitle();\r
-       CString szWindowText = m_XkeymacsData[nDestinationApplication].GetWindowText();\r
-       int nWindowTextType = m_XkeymacsData[nDestinationApplication].GetWindowTextType();\r
+       CString szApplicationName = m_Data[nDestinationApplication].GetApplicationName();\r
+       CString szApplicationTitle = m_Data[nDestinationApplication].GetApplicationTitle();\r
+       CString szWindowText = m_Data[nDestinationApplication].GetWindowText();\r
+       int nWindowTextType = m_Data[nDestinationApplication].GetWindowTextType();\r
 \r
-       m_XkeymacsData[nDestinationApplication] = m_XkeymacsData[nSourceApplication];\r
+       m_Data[nDestinationApplication] = m_Data[nSourceApplication];\r
 \r
-       m_XkeymacsData[nDestinationApplication].SetApplicationName(szApplicationName);\r
-       m_XkeymacsData[nDestinationApplication].SetApplicationTitle(szApplicationTitle);\r
-       m_XkeymacsData[nDestinationApplication].SetWindowText(szWindowText);\r
-       m_XkeymacsData[nDestinationApplication].SetWindowTextType(nWindowTextType);\r
+       m_Data[nDestinationApplication].SetApplicationName(szApplicationName);\r
+       m_Data[nDestinationApplication].SetApplicationTitle(szApplicationTitle);\r
+       m_Data[nDestinationApplication].SetWindowText(szWindowText);\r
+       m_Data[nDestinationApplication].SetWindowTextType(nWindowTextType);\r
 }\r
 \r
 // return application index\r
@@ -1313,256 +1325,13 @@ int CProfile::GetApplicationIndex(const CString szApplicationName)
 {\r
        int nApplicationID = 0;\r
        for (nApplicationID = 0; nApplicationID < MAX_APP; ++nApplicationID) {\r
-               if (m_XkeymacsData[nApplicationID].GetApplicationName() == szApplicationName) {\r
+               if (m_Data[nApplicationID].GetApplicationName() == szApplicationName) {\r
                        break;\r
                }\r
        }\r
        return nApplicationID;\r
 }\r
 \r
-BOOL CProfile::Is106Keyboard()\r
-{\r
-       static KEYBOARD_TYPE keyboard = UNKNOWN_KEYBOARD;\r
-\r
-       if (keyboard == UNKNOWN_KEYBOARD) {\r
-               OSVERSIONINFO verInfo = {0};\r
-               verInfo.dwOSVersionInfoSize = sizeof (verInfo);\r
-               GetVersionEx(&verInfo);\r
-\r
-               DWORD subtype = 0;\r
-               DWORD cbData = sizeof(subtype);\r
-\r
-               if (verInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {\r
-                       HKEY hKey = NULL;\r
-                       CString szSubKey(_T("SYSTEM\\CurrentControlSet\\Services\\i8042prt\\Parameters"));\r
-                       if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szSubKey, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) {\r
-                               static const CString szValueName(_T("OverrideKeyboardSubtype"));\r
-                               if (RegQueryValueEx(hKey, szValueName, NULL, NULL, (LPBYTE)&subtype, &cbData) != ERROR_SUCCESS) {\r
-                                       subtype = 0;\r
-                               }\r
-                               RegCloseKey(hKey);\r
-                       }\r
-               } else if (verInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {\r
-                       subtype = GetPrivateProfileInt(_T("keyboard"), _T("subtype"), 0, _T("system.ini"));\r
-               }\r
-\r
-               keyboard = (subtype & 0x02) ? JAPANESE_KEYBOARD : ENGLISH_KEYBOARD;\r
-       }\r
-\r
-       return keyboard == JAPANESE_KEYBOARD;\r
-}\r
-\r
-void CProfile::LoadScanCodeMap(const HKEY_TYPE hkeyType)\r
-{\r
-       memset(m_ScanCodeMap[hkeyType], 0, sizeof(m_ScanCodeMap[hkeyType]));\r
-       memset(m_CurrentScanCodeMap[hkeyType], 0, sizeof(m_CurrentScanCodeMap[hkeyType]));\r
-\r
-       CString szSubKey;\r
-       CString szValueName;\r
-       HKEY hKey = HKEY_LOCAL_MACHINE;\r
-       if (IsNT()) {\r
-               switch (hkeyType) {\r
-               case CURRENT_USER:\r
-                       hKey = HKEY_CURRENT_USER;\r
-                       szSubKey.LoadString(IDS_REGSUBKEY_KEYBOARD_LAYOUT);\r
-                       break;\r
-               case LOCAL_MACHINE:\r
-                       szSubKey.LoadString(IDS_REGSUBKEY_KEYBOARD_LAYOUT_ANY_USER);\r
-                       break;\r
-               default:\r
-                       return;\r
-               }\r
-               szValueName.LoadString(IDS_SCANCODE_MAP);\r
-       } else if (Is9x()) {\r
-               szSubKey.LoadString(IDS_REGSUBKEY_KEY_REMAP);\r
-               szValueName.LoadString(IDS_0);\r
-       } else {\r
-               return;\r
-       }\r
-\r
-       HKEY hkResult = NULL;\r
-       if (RegOpenKeyEx(hKey, szSubKey, 0, KEY_QUERY_VALUE, &hkResult) == ERROR_SUCCESS) {\r
-               // get data size\r
-               DWORD dwType = REG_BINARY;\r
-               DWORD dwData = 0;\r
-               RegQueryValueEx(hkResult, szValueName, NULL, &dwType, NULL, &dwData);\r
-\r
-               // get data\r
-               LPBYTE lpData = new BYTE[dwData];\r
-               if (lpData) {\r
-                       RegQueryValueEx(hkResult, szValueName, NULL, &dwType, lpData, &dwData);\r
-               }\r
-               RegCloseKey(hkResult);\r
-\r
-               if (IsNT()) {\r
-                       if (lpData && dwData) {\r
-                               DWORD offset = 0;\r
-                               offset += 8;    // skip Version Information and Flags\r
-                               DWORD *pdwMappings = (DWORD *)(lpData + offset);\r
-                               offset += 4;    // skip Number of Mappings\r
-                               DWORD *pdwNullTerminator = (DWORD *)(lpData + dwData - 4);\r
-\r
-                               if (4 * *pdwMappings + 12 != dwData) {\r
-                                       // illegal data\r
-                               } else if (*pdwNullTerminator != 0) {\r
-                                       // illegal data\r
-                               } else {\r
-                                       while (offset < dwData - 4) {\r
-                                               ScanCodeMapping_t *pScanCodeMapping = (ScanCodeMapping_t *)(lpData + offset);\r
-                                               offset += 4;    // go to next data\r
-\r
-                                               m_CurrentScanCodeMap[hkeyType][PrefixedScanCode2ID(pScanCodeMapping->original.nPrefixedScanCode)][pScanCodeMapping->original.nScanCode].nPrefixedScanCode = pScanCodeMapping->current.nPrefixedScanCode;\r
-                                               m_CurrentScanCodeMap[hkeyType][PrefixedScanCode2ID(pScanCodeMapping->original.nPrefixedScanCode)][pScanCodeMapping->original.nScanCode].nScanCode = pScanCodeMapping->current.nScanCode;\r
-                                               m_ScanCodeMap[hkeyType][PrefixedScanCode2ID(pScanCodeMapping->original.nPrefixedScanCode)][pScanCodeMapping->original.nScanCode].nPrefixedScanCode = pScanCodeMapping->current.nPrefixedScanCode;\r
-                                               m_ScanCodeMap[hkeyType][PrefixedScanCode2ID(pScanCodeMapping->original.nPrefixedScanCode)][pScanCodeMapping->original.nScanCode].nScanCode = pScanCodeMapping->current.nScanCode;\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-               delete[] lpData;\r
-               lpData = NULL;\r
-       }\r
-}\r
-\r
-int CProfile::LostKeyWarning(const HKEY_TYPE hkeyType)\r
-{\r
-       if (!ChangedKeyboardLayout(hkeyType)) {\r
-               return IDOK;\r
-       }\r
-\r
-       CString szLostKeysList;\r
-\r
-       for (int nPrefixedScanCodeID = 0; nPrefixedScanCodeID < 3; ++nPrefixedScanCodeID) {\r
-               for (int nScanCode = 0; nScanCode < 256; ++nScanCode) {\r
-                       if (m_ScanCodeMap[hkeyType][nPrefixedScanCodeID][nScanCode].nScanCode) {\r
-                               BOOL lostKey = TRUE;\r
-\r
-                               for (int i = 0; i < 3 && lostKey; ++i) {\r
-                                       for (int j = 0; j < 256 && lostKey; ++j) {\r
-                                               if (m_ScanCodeMap[hkeyType][i][j].nPrefixedScanCode == nPrefixedScanCodeID\r
-                                                && m_ScanCodeMap[hkeyType][i][j].nScanCode == nScanCode) {\r
-                                                       lostKey = FALSE;\r
-                                               }\r
-                                       }\r
-                               }\r
-\r
-                               if (lostKey) {\r
-                                       for (int i = 0; i < sizeof(KeyboardLayouts)/sizeof(KeyboardLayouts[0]); ++i) {\r
-                                               if (KeyboardLayouts[i].scancode.nScanCode == nScanCode\r
-                                                       && KeyboardLayouts[i].scancode.nPrefixedScanCode == nPrefixedScanCodeID) {\r
-                                                       CString szLostKey;\r
-                                                       szLostKey.Format(IDS_ERR_LOST_KEY, CString(MAKEINTRESOURCE(GetToolTipID(KeyboardLayouts[i].nToolTipID))));\r
-                                                       szLostKeysList += szLostKey;\r
-                                                       break;\r
-                                               }\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-\r
-       if (szLostKeysList.IsEmpty()) {\r
-               return IDOK;\r
-       }\r
-\r
-       return AfxMessageBox(szLostKeysList, MB_OKCANCEL | MB_ICONEXCLAMATION);\r
-}\r
-\r
-void CProfile::SaveScanCodeMap(const HKEY_TYPE hkeyType)\r
-{\r
-       CString szSubKey;\r
-       CString szValueName;\r
-       HKEY hKey = HKEY_LOCAL_MACHINE;\r
-       if (IsNT()) {\r
-               switch (hkeyType) {\r
-               case CURRENT_USER:\r
-                       hKey = HKEY_CURRENT_USER;\r
-                       szSubKey.LoadString(IDS_REGSUBKEY_KEYBOARD_LAYOUT);\r
-                       break;\r
-               case LOCAL_MACHINE:\r
-                       szSubKey.LoadString(IDS_REGSUBKEY_KEYBOARD_LAYOUT_ANY_USER);\r
-                       break;\r
-               default:\r
-                       return;\r
-               }\r
-               szValueName.LoadString(IDS_SCANCODE_MAP);\r
-       } else if (Is9x()) {\r
-               szSubKey.LoadString(IDS_REGSUBKEY_KEY_REMAP);\r
-               szValueName.LoadString(IDS_0);\r
-       } else {\r
-               return;\r
-       }\r
-\r
-       HKEY hkResult = NULL;\r
-       if (RegCreateKeyEx(hKey, szSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hkResult, NULL) == ERROR_SUCCESS) {\r
-               if (IsNT()) {\r
-                       DWORD cbData = GetScanCodeLength(hkeyType);\r
-                       if (cbData <= 16) {\r
-                               RegDeleteValue(hkResult, szValueName);\r
-                       } else {\r
-                               LPBYTE lpData = new BYTE[cbData];\r
-                               memset(lpData, 0, sizeof(BYTE) * cbData);\r
-\r
-                               {\r
-                                       DWORD dwMappings = (cbData - 12) / 4;\r
-                                       memmove(lpData + 8, &dwMappings, 4);\r
-                               }\r
-\r
-                               int offset = 12;\r
-                               for (int nPrefixedScanCodeID = 0; nPrefixedScanCodeID < 3; ++nPrefixedScanCodeID) {\r
-                                       for (int nScanCode = 0; nScanCode < 256; ++nScanCode) {\r
-                                               if (m_ScanCodeMap[hkeyType][nPrefixedScanCodeID][nScanCode].nScanCode) {\r
-                                                       ScanCodeMapping_t sScanCodeMapping = {'\0'};\r
-                                                       sScanCodeMapping.original.nPrefixedScanCode = PrefixedScanCodeID2Code(nPrefixedScanCodeID);\r
-                                                       sScanCodeMapping.original.nScanCode = (BYTE)nScanCode;\r
-                                                       sScanCodeMapping.current.nPrefixedScanCode = m_ScanCodeMap[hkeyType][nPrefixedScanCodeID][nScanCode].nPrefixedScanCode;\r
-                                                       sScanCodeMapping.current.nScanCode = m_ScanCodeMap[hkeyType][nPrefixedScanCodeID][nScanCode].nScanCode;\r
-                                                       memcpy(lpData + offset, &sScanCodeMapping, sizeof(sScanCodeMapping));\r
-                                                       offset += sizeof(sScanCodeMapping);\r
-                                               }\r
-                                       }\r
-                               }\r
-                               RegSetValueEx(hkResult, szValueName, 0, REG_BINARY, lpData, cbData);\r
-\r
-                               delete[] lpData;\r
-                               lpData = NULL;\r
-                       }\r
-               }\r
-               RegCloseKey(hkResult);\r
-       }\r
-\r
-       // Do you want to restart computer?\r
-       if (ChangedKeyboardLayout(hkeyType)) {\r
-               if (AfxMessageBox(CString(MAKEINTRESOURCE(IDS_RESTART_OR_NOT)), MB_YESNO | MB_ICONQUESTION) == IDYES) {\r
-                       RestartComputer();\r
-               }\r
-       }\r
-}\r
-\r
-// Return True if Windows 95, Windows 98, or Windows Me. \r
-BOOL CProfile::Is9x()\r
-{\r
-       OSVERSIONINFO info = {sizeof(OSVERSIONINFO)};\r
-       GetVersionEx(&info);\r
-\r
-       if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {\r
-               return TRUE;\r
-       }\r
-       return FALSE;\r
-}\r
-\r
-// Return True if Windows NT 4.0, Windows 2000, Windows XP, Windows 2003 or Windows Vista.\r
-BOOL CProfile::IsNT()\r
-{\r
-       OSVERSIONINFO info = {sizeof(OSVERSIONINFO)};\r
-       GetVersionEx(&info);\r
-\r
-       if (info.dwPlatformId == VER_PLATFORM_WIN32_NT) {\r
-               return TRUE;\r
-       }\r
-       return FALSE;\r
-}\r
-\r
 // Return True if Windows Vista or later.\r
 BOOL CProfile::IsVistaOrLater()\r
 {\r
@@ -1584,205 +1353,28 @@ void CProfile::RestartComputer()
        ExitWindowsEx(EWX_REBOOT, 0);\r
 }\r
 \r
-int CProfile::GetControlID(const ScanCode_t scancode, const BOOL bBase)\r
-{\r
-       for (int i = 0; ; ++i) {\r
-               if (KeyboardLayouts[i].scancode.nPrefixedScanCode == scancode.nPrefixedScanCode\r
-                && KeyboardLayouts[i].scancode.nScanCode == scancode.nScanCode) {\r
-                       if (bBase) {\r
-                               return KeyboardLayouts[i].nBaseControlID;\r
-                       } else {\r
-                               return KeyboardLayouts[i].nCurrentControlID;\r
-                       }\r
-               }\r
-       }\r
-       return 0;\r
-}\r
-\r
-int CProfile::GetBaseControlID(const ScanCode_t scancode)\r
-{\r
-       return GetControlID(scancode, TRUE);\r
-}\r
-\r
-int CProfile::GetCurrentControlID(const ScanCode_t scancode)\r
-{\r
-       return GetControlID(scancode, FALSE);\r
-}\r
-\r
-BOOL CProfile::GetScanCodeMap(const HKEY_TYPE hkeyType, const ScanCode_t original, ScanCode_t *const current)\r
-{\r
-       if (!current) {\r
-               return FALSE;\r
-       }\r
-       *current = m_ScanCodeMap[hkeyType][PrefixedScanCode2ID(original.nPrefixedScanCode)][original.nScanCode];\r
-       return 0 < current->nScanCode;\r
-}\r
-\r
-void CProfile::SetScanCodeMap(const HKEY_TYPE hkeyType, const ScanCodeMapping_t ScanCodeMappeing)\r
-{\r
-       m_ScanCodeMap[hkeyType][PrefixedScanCode2ID(ScanCodeMappeing.original.nPrefixedScanCode)][ScanCodeMappeing.original.nScanCode] = ScanCodeMappeing.current;\r
-}\r
-\r
-int CProfile::PrefixedScanCode2ID(const BYTE nPrefixedScanCode)\r
-{\r
-       int nID = 0;\r
-\r
-       switch (nPrefixedScanCode) {\r
-       case 0x00:\r
-               nID = 0;\r
-               break;\r
-       case 0xe0:\r
-               nID = 1;\r
-               break;\r
-       case 0xe1:\r
-               nID = 2;\r
-               break;\r
-       default:\r
-               // invalid scan code\r
-               nID = 3;\r
-               break;\r
-       }\r
-\r
-       return nID;\r
-}\r
-\r
-BYTE CProfile::PrefixedScanCodeID2Code(const int nPrefixedScanCodeID)\r
-{\r
-       BYTE nCode = 0;\r
-\r
-       switch (nPrefixedScanCodeID) {\r
-       case 0:\r
-               nCode = 0x00;\r
-               break;\r
-       case 1:\r
-               nCode = 0xe0;\r
-               break;\r
-       case 2:\r
-               nCode = 0xe1;\r
-               break;\r
-       default:\r
-               ASSERT(0);\r
-               break;\r
-       }\r
-\r
-       return nCode;\r
-}\r
-\r
-DWORD CProfile::GetScanCodeLength(const HKEY_TYPE hkeyType)\r
-{\r
-       DWORD dwScanCodeLength = 0;\r
-       dwScanCodeLength += 4;  // Header: Version Information\r
-       dwScanCodeLength += 4;  // Header: Flags\r
-       dwScanCodeLength += 4;  // Header: Number of Mappings\r
-       for (int nPrefixedScanCodeID = 0; nPrefixedScanCodeID < 3; ++nPrefixedScanCodeID) {\r
-               for (int nScanCode = 0; nScanCode < 256; ++nScanCode) {\r
-                       if (m_ScanCodeMap[hkeyType][nPrefixedScanCodeID][nScanCode].nScanCode) {\r
-                               dwScanCodeLength += 4;  // Individual Mappings\r
-                       }\r
-               }\r
-       }\r
-       dwScanCodeLength += 4;  // Null Terminator (0x00000000)\r
-       return dwScanCodeLength;\r
-}\r
-\r
-BOOL CProfile::ChangedKeyboardLayout(const HKEY_TYPE hkeyType)\r
-{\r
-       for (int nPrefixedScanCodeID = 0; nPrefixedScanCodeID < 3; ++nPrefixedScanCodeID) {\r
-               for (int nScanCode = 0; nScanCode < 256; ++nScanCode) {\r
-                       if (m_ScanCodeMap[hkeyType][nPrefixedScanCodeID][nScanCode].nPrefixedScanCode   != m_CurrentScanCodeMap[hkeyType][nPrefixedScanCodeID][nScanCode].nPrefixedScanCode\r
-                        || m_ScanCodeMap[hkeyType][nPrefixedScanCodeID][nScanCode].nScanCode                   != m_CurrentScanCodeMap[hkeyType][nPrefixedScanCodeID][nScanCode].nScanCode) {\r
-                               return TRUE;\r
-                       }\r
-               }\r
-       }\r
-\r
-       return FALSE;\r
-}\r
-\r
-void CProfile::SetDraggingCursor()\r
-{\r
-       HCURSOR hCursor = (HCURSOR)LoadImage(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDC_DRAG_CURSOR),\r
-                                                                                IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED);\r
-       SetCursor(hCursor);\r
-}\r
-\r
-void CProfile::SetNormalCursor()\r
-{\r
-       HCURSOR hCursor = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(IDC_ARROW),\r
-                                                                                IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED);\r
-       SetCursor(hCursor);\r
-}\r
-\r
-void CProfile::SetNoCursor()\r
-{\r
-       HCURSOR hCursor = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(IDC_NO),\r
-                                                                                IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED);\r
-       SetCursor(hCursor);\r
-}\r
-\r
-int CProfile::GetToolTipID(int nToolTipID)\r
-{\r
-       if (Is106Keyboard()) {\r
-               switch (nToolTipID) {\r
-               case IDS_EQUAL:                 // ^\r
-                       nToolTipID = IDS_CARET;\r
-                       break;\r
-               case IDS_SQUARE_BRA:    // @\r
-                       nToolTipID = IDS_AT_MARK;\r
-                       break;\r
-               case IDS_SQUARE_CKET:   // [\r
-                       nToolTipID = IDS_SQUARE_BRA;\r
-                       break;\r
-               case IDS_QUOTE:                 // :\r
-                       nToolTipID = IDS_COLON;\r
-                       break;\r
-               case IDS_BACK_QUOTE:    // Hankaku/Zenkaku\r
-                       nToolTipID = IDS_HANKAKU;\r
-                       break;\r
-               case IDS_BACKSLASH:             // ]\r
-                       nToolTipID = IDS_SQUARE_CKET;\r
-                       break;\r
-               }\r
-       }\r
-\r
-       return nToolTipID;\r
-}\r
-\r
-KeyboardLayout_t* CProfile::GetKeyboardLayouts(const int nKey)\r
-{\r
-       for (int i = 0; i < sizeof(KeyboardLayouts) / sizeof(KeyboardLayouts[0]); ++i) {\r
-               if (KeyboardLayouts[i].nBaseControlID == nKey\r
-                || KeyboardLayouts[i].nCurrentControlID == nKey) {\r
-                       return &KeyboardLayouts[i];\r
-               }\r
-       }\r
-       return NULL;\r
-}\r
-\r
 BOOL CProfile::AdjustTokenPrivileges(LPCTSTR lpName)\r
 {\r
        BOOL rc = TRUE;\r
 \r
-       if (IsNT()) {\r
-               HANDLE hToken;\r
-               if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) {\r
-                       LUID luid;\r
-                       if (LookupPrivilegeValue(NULL, lpName, &luid)) {\r
-                               TOKEN_PRIVILEGES tp;\r
-                               tp.PrivilegeCount = 1;\r
-                               tp.Privileges[0].Luid = luid;\r
-                               tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;\r
-\r
-                               if (!::AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) {\r
-                                       rc = FALSE;\r
-                               }\r
-                       } else {\r
+       HANDLE hToken;\r
+       if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) {\r
+               LUID luid;\r
+               if (LookupPrivilegeValue(NULL, lpName, &luid)) {\r
+                       TOKEN_PRIVILEGES tp;\r
+                       tp.PrivilegeCount = 1;\r
+                       tp.Privileges[0].Luid = luid;\r
+                       tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;\r
+\r
+                       if (!::AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) {\r
                                rc = FALSE;\r
                        }\r
-                       CloseHandle(hToken);\r
                } else {\r
                        rc = FALSE;\r
                }\r
+               CloseHandle(hToken);\r
+       } else {\r
+               rc = FALSE;\r
        }\r
 \r
        return rc;\r
@@ -1792,16 +1384,14 @@ BOOL CProfile::DiableTokenPrivileges()
 {\r
        BOOL rc = TRUE;\r
 \r
-       if (IsNT()) {\r
-               HANDLE hToken;\r
-               if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) {\r
-                       if (!::AdjustTokenPrivileges(hToken, TRUE, NULL, NULL, NULL, NULL)) {\r
-                               rc = FALSE;\r
-                       }\r
-                       CloseHandle(hToken);\r
-               } else {\r
+       HANDLE hToken;\r
+       if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) {\r
+               if (!::AdjustTokenPrivileges(hToken, TRUE, NULL, NULL, NULL, NULL)) {\r
                        rc = FALSE;\r
                }\r
+               CloseHandle(hToken);\r
+       } else {\r
+               rc = FALSE;\r
        }\r
 \r
        return rc;\r
@@ -1843,12 +1433,12 @@ void CProfile::ImportProperties()
 \r
 BOOL CProfile::GetEnableCUA(const int nApplicationID)\r
 {\r
-       return m_XkeymacsData[nApplicationID].GetEnableCUA();\r
+       return m_Data[nApplicationID].GetEnableCUA();\r
 }\r
 \r
 void CProfile::SetEnableCUA(const int nApplicationID, const BOOL bEnableCUA)\r
 {\r
-       m_XkeymacsData[nApplicationID].SetEnableCUA(bEnableCUA);\r
+       m_Data[nApplicationID].SetEnableCUA(bEnableCUA);\r
 }\r
 \r
 int CProfile::GetKeyboardSpeed()\r