OSDN Git Service

Change CopyData to CopyDefault with one argument, and rewrite
[xkeymacs/xkeymacs.git] / xkeymacs / profile.cpp
index 60f9f5e..ab168bb 100644 (file)
@@ -2,15 +2,15 @@
 //\r
 //////////////////////////////////////////////////////////////////////\r
 \r
-#include "stdafx.h"\r
+#include "profile.h"\r
+#include "imelist.h"\r
 #include "xkeymacs.h"\r
-#include "Profile.h"\r
-#include "MainFrm.h"\r
-#include "DotXkeymacs.h"\r
-#include <Imm.h>\r
-#include <Shlwapi.h>\r
+#include "dotxkeymacs.h"\r
+#include "mainfrm.h"\r
+#include "../xkeymacsdll/xkeymacsdll.h"\r
+#include "../xkeymacsdll/AppName.h"\r
+#include "../xkeymacsdll/Utils.h"\r
 #include <TlHelp32.h>\r
-#include <vector>\r
 \r
 #ifdef _DEBUG\r
 #undef THIS_FILE\r
@@ -18,463 +18,117 @@ static char THIS_FILE[]=__FILE__;
 #define new DEBUG_NEW\r
 #endif\r
 \r
-struct CommandTypeName\r
-{\r
-       int nType;\r
-       LPCTSTR szName;\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
-CONFIG CProfile::m_Config;\r
-TCHAR CProfile::m_szAppTitle[MAX_APP][WINDOW_TEXT_LENGTH];\r
+Config CProfile::m_Config;\r
+KeyString CProfile::m_KeyString(CProfile::Is106Keyboard() != FALSE);\r
+TCHAR CProfile::m_AppTitle[MAX_APP][WINDOW_TEXT_LENGTH];\r
 TASK_LIST CProfile::m_TaskList[MAX_TASKS];\r
 DWORD CProfile::m_dwTasks;\r
 \r
-enum { INITIAL_SIZE    = 51200 };\r
-enum { EXTEND_SIZE     = 25600 };\r
-\r
-void CProfile::Item2AppName(CString *const sz)\r
+void CProfile::LoadData()\r
 {\r
-       if (IsTheString(*sz, IDS_DEFAULT_TITLE)) {\r
-               sz->LoadString(IDS_DEFAULT);\r
-       }\r
-\r
-       if (IsTheString(*sz, IDS_DIALOG_TITLE)) {\r
-               sz->LoadString(IDS_DIALOG);\r
-       }\r
-\r
-       int nStart, nEnd, nCount;\r
-\r
-       nStart  = sz->ReverseFind(_T('(')) + 1;\r
-       nEnd    = sz->Find(_T(')'), nStart) - 1;\r
-       nCount  = (nEnd + 1) - nStart;\r
-       *sz             = sz->Mid(nStart, nCount);\r
+       CDotXkeymacs::Load();\r
+       LevelUp();\r
+       LoadRegistry();\r
 }\r
 \r
-int CProfile::IsNotSameString(CComboBox *const pApplication, const CString szListItem)\r
+void CProfile::SaveData()\r
 {\r
-       CString szItem, szList;\r
-       szList = szListItem;\r
-       Item2AppName(&szList);\r
-\r
-       for (int i = 0; i < pApplication->GetCount(); ++i) {\r
-               pApplication->GetLBText(i, szItem);\r
-               Item2AppName(&szItem);\r
-               if (!_tcsicmp(szItem, szList)) {\r
-                       return 0;\r
-               }\r
-       }\r
-\r
-       return 1;\r
+       DeleteAllRegistryData();\r
+       SaveRegistry();\r
+       SetDllData();\r
 }\r
 \r
-int CProfile::CountSeparator(const CString szMainString, const CString szSeparator)\r
+void CProfile::InitDllData()\r
 {\r
-       int index       = 0;\r
-       int counter     = 0;\r
-\r
-       while ((index = szMainString.Find(szSeparator, index)) != -1) {\r
-               ++index;\r
-               ++counter;\r
-       }\r
-\r
-       return counter;\r
+       LoadData();\r
+       SetDllData();\r
 }\r
 \r
-void CProfile::GetNthString(CString *const szAppName, const CString szWindowName, const CString szSeparator, int n)\r
+void CProfile::DeleteAllRegistryData()\r
 {\r
-       int index = -1;\r
-\r
-       while (--n) {\r
-               index = szWindowName.Find(szSeparator, index + 1);\r
-       }\r
-\r
-       int nStart;\r
-       if (index != -1) {\r
-               nStart = index + szSeparator.GetLength();\r
-       } else {\r
-               nStart = 0;\r
-       }\r
+       HKEY hkey = NULL;\r
+       if (RegOpenKeyEx(HKEY_CURRENT_USER, CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)), 0, KEY_ALL_ACCESS, &hkey) == ERROR_SUCCESS) {\r
+               // I am sure that I have to do only one time, but...\r
+               for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {\r
+                       DWORD dwIndex = 0;\r
+                       TCHAR szName[SUB_KEY_NAME_LENGTH] = {'\0'};\r
+                       DWORD dwName = sizeof(szName);\r
+                       FILETIME filetime;\r
 \r
-       int nEnd = szWindowName.Find(szSeparator, nStart);\r
-       if (nEnd == -1) {\r
-               nEnd = szWindowName.GetLength();\r
+                       while (RegEnumKeyEx(hkey, dwIndex++, szName, &dwName, NULL, NULL, NULL, &filetime) == ERROR_SUCCESS) {\r
+//                             RegDeleteKey(hkey, szName);\r
+                               SHDeleteKey(hkey, szName);\r
+                               ZeroMemory(szName, sizeof(szName));\r
+                               dwName = sizeof(szName);\r
+                       }\r
+               }\r
+               RegCloseKey(hkey);\r
        }\r
-\r
-       *szAppName = szWindowName.Mid(nStart, nEnd - nStart);\r
 }\r
 \r
-void CProfile::GetAppName(CString *const szAppName, LPCTSTR pWindowName)\r
+void CProfile::LevelUp()\r
 {\r
-       CString szWindowName(pWindowName);\r
-       CString szSeparator(MAKEINTRESOURCE(IDS_SEPARATE_WINDOWTITLE));\r
-       int nWord = CountSeparator(szWindowName, szSeparator) + 1;\r
-\r
-       while (nWord) {\r
-               GetNthString(szAppName, szWindowName, szSeparator, nWord);\r
-               if (szAppName->GetAt(0) == _T('[')\r
-                || szAppName->Find(_T('.'), 0) != -1           // for Microsoft Project\r
-                || szAppName->Find(_T(']'), 0) != -1) {        // for the file name like [foo - bar]\r
-                       --nWord;\r
-               } else {\r
-                       return;\r
+       int nCurrentLevel = AfxGetApp()->GetProfileInt(_T(""), _T("Level"), 0);\r
+       for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {\r
+               CString entry;\r
+               entry.Format(IDS_REG_ENTRY_APPLICATION, nAppID);\r
+               const CString appName = AfxGetApp()->GetProfileString(CString(MAKEINTRESOURCE(IDS_REG_SECTION_APPLICATION)), entry);\r
+               if (appName.IsEmpty())\r
+                       continue;\r
+               switch (nCurrentLevel) {\r
+               case 0:\r
+                       AddKeyBind2C_(appName, VK_LCONTROL);\r
+                       AddKeyBind2C_(appName, VK_RCONTROL);\r
+               // fall through\r
+               case 1:\r
+                       // Set kill-ring-max 1 if it is 0.\r
+                       if (!AfxGetApp()->GetProfileInt(appName, CString(MAKEINTRESOURCE(IDS_REG_ENTRY_KILL_RING_MAX)), 0))\r
+                               AfxGetApp()->WriteProfileInt(appName, CString(MAKEINTRESOURCE(IDS_REG_ENTRY_KILL_RING_MAX)), 1);\r
+               // fall through\r
+               case 2:\r
+                       {\r
+                               // Chaged a label from Enter to newline.\r
+                               const CString subKey = CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)) + _T("\\") + appName;\r
+                               const CString srcKey = subKey + _T("\\") + _T("Enter");\r
+                               const CString dstKey = subKey + _T("\\") + _T("newline");\r
+                               HKEY hDstKey = NULL;\r
+                               if (RegCreateKeyEx(HKEY_CURRENT_USER, dstKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hDstKey, NULL) == ERROR_SUCCESS) {\r
+                                       SHCopyKey(HKEY_CURRENT_USER, srcKey, hDstKey, NULL);\r
+                                       SHDeleteKey(HKEY_CURRENT_USER, srcKey);\r
+                                       RegCloseKey(hDstKey);\r
+                               }\r
+                       }\r
+               // fall through\r
+               case 3:\r
+                       // rename original function to remove IDS_REG_ORIGINAL_PREFIX\r
+                       for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID) {\r
+                               HKEY hKey = NULL;\r
+                               const CString subKey = CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)) + _T("\\") + appName + _T("\\") + CString(MAKEINTRESOURCE(IDS_REG_ORIGINAL_PREFIX)) + CDotXkeymacs::GetFunctionSymbol(nFuncID);\r
+                               if (RegOpenKeyEx(HKEY_CURRENT_USER, subKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {\r
+                                       // Use registry data\r
+                                       TCHAR szKeyBind[128];\r
+                                       DWORD dwKeyBind = sizeof(szKeyBind);\r
+                                       for (DWORD dwIndex = 0; RegEnumKeyEx(hKey, dwIndex, szKeyBind, &dwKeyBind, NULL, NULL, NULL, NULL) == ERROR_SUCCESS; ++dwIndex) {\r
+                                               int nType, nKey;\r
+                                               StringToKey(szKeyBind, nType, nKey);\r
+                                               SaveKeyBind(appName, CDotXkeymacs::GetFunctionSymbol(nFuncID), nType, nKey);\r
+                                               dwKeyBind = sizeof(szKeyBind);\r
+                                       }\r
+                                       RegCloseKey(hKey);\r
+                               }\r
+                       }\r
                }\r
        }\r
-\r
-       *szAppName = szWindowName;\r
+       AfxGetApp()->WriteProfileInt(_T(""), _T("Level"), 4);\r
 }\r
 \r
-BOOL CALLBACK CProfile::EnumWindowsProc(const HWND hWnd, const LPARAM lParam)\r
+void CProfile::AddKeyBind2C_(LPCTSTR appName, BYTE bVk)\r
 {\r
-       CComboBox               *pApplication   = (CComboBox*)lParam;\r
-       PTASK_LIST              pTask                   = CProfile::m_TaskList;\r
-       \r
-       TCHAR szWindowName[WINDOW_TEXT_LENGTH];\r
-       TCHAR szClassName[CLASS_NAME_LENGTH];\r
-       WINDOWPLACEMENT wpl;\r
-       \r
-       wpl.length = sizeof(WINDOWPLACEMENT);\r
-       ::GetWindowText(hWnd, szWindowName, sizeof(szWindowName));\r
-       GetClassName(hWnd, szClassName, sizeof(szClassName));\r
-\r
-       CString szAppName;\r
-       // Get Process Name\r
-       DWORD dwProcessId = 0;\r
-       GetWindowThreadProcessId(hWnd, &dwProcessId);\r
-       DWORD i;\r
-       for (i = 0; i < CProfile::m_dwTasks; ++i) {\r
-               if (pTask[i].dwProcessId == dwProcessId) {\r
-\r
-                       // Get Application Name\r
-                       if (szWindowName[0] == '\0') {\r
-                               continue;\r
-                       }\r
-                       if (!_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_B2)), sizeof(pTask[i].ProcessName))) {\r
-                               szAppName.LoadString(IDS_BECKY);\r
-                       } else if (!_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_EXPLORER)), sizeof(pTask[i].ProcessName))) {\r
-                               szAppName.LoadString(IDS_PROGRAM_MANAGER);\r
-                       } else if (!_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_MSIMN)), sizeof(pTask[i].ProcessName))) {\r
-                               szAppName.LoadString(IDS_OUTLOOK_EXPRESS);\r
-                       } else if (!_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_PROJECT)), sizeof(pTask[i].ProcessName))\r
-                                       || !_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_EXCEL)), sizeof(pTask[i].ProcessName))\r
-                                       || !_tcsnicmp(pTask[i].ProcessName, _T("psp.exe"), sizeof(pTask[i].ProcessName))) {\r
-                               GetNthString(&szAppName, szWindowName, CString(MAKEINTRESOURCE(IDS_SEPARATE_WINDOWTITLE)), 1);\r
-                       } else if (!_tcsnicmp(pTask[i].ProcessName, _T("sakura.exe"), sizeof(pTask[i].ProcessName))) {\r
-                               GetNthString(&szAppName, szWindowName, CString(MAKEINTRESOURCE(IDS_SEPARATE_WINDOWTITLE)), 2);  // '.' is included, so...\r
-                       } else if (!_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_MSDN)), sizeof(pTask[i].ProcessName))) {\r
-                               szAppName = szWindowName;\r
-                       } else if (!_tcsnicmp(pTask[i].ProcessName, _T("devenv.exe"), sizeof(pTask[i].ProcessName))) {\r
-                               szAppName.Format(_T("Microsoft Visual Studio .NET"));\r
-                       } else if (!_tcsnicmp(pTask[i].ProcessName, _T("vb6.exe"), sizeof(pTask[i].ProcessName))) {\r
-                               szAppName.Format(_T("Microsoft Visual Basic"));\r
-                       } else if (!_tcsnicmp(pTask[i].ProcessName, _T("ssexp.exe"), sizeof(pTask[i].ProcessName))) {\r
-                               szAppName.LoadString(IDS_VISUAL_SOURCESAFE_EXPLORER);\r
-                       } else if (!_tcsnicmp(pTask[i].ProcessName, _T("sh.exe"), sizeof(pTask[i].ProcessName))) {\r
-                               szAppName.Format(_T("MKS Korn Shell"));\r
-                       } else if (!_tcsnicmp(pTask[i].ProcessName, _T("csh.exe"), sizeof(pTask[i].ProcessName))) {\r
-                               szAppName.Format(_T("C Shell"));\r
-                       } 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, szWindowName);\r
-                               GetAppName(&szAppName, szWindowName);\r
-                       }\r
+       int nComID;\r
+       for (nComID = 0; nComID < MAX_COMMAND; ++nComID)\r
+               if (Commands[nComID].fCommand == CCommands::C_)\r
                        break;\r
-               }\r
-       }\r
-       \r
-       \r
-       if ((IsWindowVisible(hWnd))                                                                     // Is visible?\r
-        && (GetWindow(hWnd, GW_OWNER) == NULL)                                         // Is top level window?\r
-        && (lstrlen(szWindowName) > 0)                                                         // Have caption?\r
-        && (pApplication->FindString(-1, szClassName) == CB_ERR)) {// Is not same string?\r
-               CString szListItem;\r
-               szListItem.Format(IDS_APPLICATION_LIST_ITEM, szAppName, pTask[i].ProcessName);\r
-               if (IsNotSameString(pApplication, szListItem)) {\r
-                       pApplication->AddString(szListItem);\r
-               }\r
-       }\r
-       return TRUE;\r
+       SaveKeyBind(appName, nComID, NONE, bVk);\r
 }\r
 \r
 void CProfile::LoadRegistry()\r
@@ -497,12 +151,12 @@ void CProfile::LoadRegistry()
                        bDialog = true;\r
                _tcsncpy_s(m_Config.szSpecialApp[nAppID], appName, _TRUNCATE);\r
                entry.LoadString(IDS_REG_ENTRY_APPLICATOIN_TITLE);\r
-               _tcsncpy_s(m_szAppTitle[nAppID], AfxGetApp()->GetProfileString(appName, entry), _TRUNCATE);\r
+               _tcsncpy_s(m_AppTitle[nAppID], AfxGetApp()->GetProfileString(appName, entry), _TRUNCATE);\r
                entry.LoadString(IDS_REG_ENTRY_WINDOW_TEXT);\r
                _tcsncpy_s(m_Config.szWindowText[nAppID], AfxGetApp()->GetProfileString(appName, entry, _T("*")), _TRUNCATE);\r
 \r
                const CString regApp = CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)) + _T("\\") + appName;\r
-               for (int nComID = 1; nComID < MAX_COMMAND; ++nComID) {\r
+               for (BYTE nComID = 1; nComID < MAX_COMMAND; ++nComID) {\r
                        entry = CCommands::GetCommandName(nComID);\r
                        HKEY hKey;\r
                        const CString regKey = regApp + _T("\\") + entry;\r
@@ -511,17 +165,17 @@ void CProfile::LoadRegistry()
                                DWORD dwKeyBind = _countof(szKeyBind);\r
                                for (DWORD dwIndex = 0; RegEnumKeyEx(hKey, dwIndex, szKeyBind, &dwKeyBind, NULL, NULL, NULL, NULL) == ERROR_SUCCESS; ++dwIndex) {\r
                                        int nType, nKey;\r
-                                       ReadKeyBind(nType, nKey, szKeyBind);\r
+                                       StringToKey(szKeyBind, nType, nKey);\r
                                        m_Config.nCommandID[nAppID][nType][nKey] = nComID;\r
                                        dwKeyBind = _countof(szKeyBind);\r
                                }\r
                                RegCloseKey(hKey);\r
                        } else {\r
                                // Set the default assignment\r
-                               for (int i = 0; const int nKey = CCommands::GetDefaultCommandKey(nComID, i); ++i) {\r
+                               for (int i = 0; int nKey = CCommands::GetDefaultCommandKey(nComID, i); ++i) {\r
                                        if (CCommands::GetDefaultControlID(nComID, i) == IDC_CO2)\r
                                                continue;\r
-                                       const int nType = CCommands::GetDefaultCommandType(nComID, i);\r
+                                       int nType = CCommands::GetDefaultCommandType(nComID, i);\r
                                        m_Config.nCommandID[nAppID][nType][nKey] = nComID;\r
                                }\r
                        }\r
@@ -535,7 +189,7 @@ void CProfile::LoadRegistry()
                                DWORD dwKeyBind = _countof(szKeyBind);\r
                                for (DWORD dwIndex = 0; RegEnumKeyEx(hKey, dwIndex, szKeyBind, &dwKeyBind, NULL, NULL, NULL, NULL) == ERROR_SUCCESS; ++dwIndex) {\r
                                        int nType, nKey;\r
-                                       ReadKeyBind(nType, nKey, szKeyBind);\r
+                                       StringToKey(szKeyBind, nType, nKey);\r
                                        CDotXkeymacs::SetKey(nFuncID, nAppID, nType, nKey);\r
                                        dwKeyBind = _countof(szKeyBind);\r
                                }\r
@@ -544,19 +198,20 @@ void CProfile::LoadRegistry()
                }\r
 \r
                entry.LoadString(IDS_REG_ENTRY_KILL_RING_MAX);\r
-               m_Config.nKillRingMax[nAppID] = AfxGetApp()->GetProfileInt(appName, entry, 1);\r
+               int n = AfxGetApp()->GetProfileInt(appName, entry, 1);\r
+               m_Config.nKillRingMax[nAppID] = static_cast<BYTE>(n > 255 ? 255 : n);\r
                entry.LoadString(IDS_REG_ENTRY_USE_DIALOG_SETTING);\r
-               m_Config.bUseDialogSetting[nAppID] = AfxGetApp()->GetProfileInt(appName, entry, 1);\r
+               m_Config.bUseDialogSetting[nAppID] = static_cast<BYTE>(AfxGetApp()->GetProfileInt(appName, entry, 1));\r
                entry.LoadString(IDS_REG_ENTRY_DISABLE_XKEYMACS);\r
-               m_Config.nSettingStyle[nAppID] = AfxGetApp()->GetProfileInt(appName, entry, 0) ? SETTING_DISABLE : SETTING_SPECIFIC;\r
+               m_Config.nSettingStyle[nAppID] = static_cast<BYTE>(AfxGetApp()->GetProfileInt(appName, entry, 0) ? SETTING_DISABLE : SETTING_SPECIFIC);\r
                entry.LoadString(IDC_REG_ENTRY_IGNORE_META_CTRL);\r
-               m_Config.bIgnoreUndefinedMetaCtrl[nAppID] = AfxGetApp()->GetProfileInt(appName, entry, 0);\r
+               m_Config.bIgnoreUndefinedMetaCtrl[nAppID] = static_cast<BYTE>(AfxGetApp()->GetProfileInt(appName, entry, 0));\r
                entry.LoadString(IDC_REG_ENTRY_IGNORE_C_X);\r
-               m_Config.bIgnoreUndefinedC_x[nAppID] = AfxGetApp()->GetProfileInt(appName, entry, 0);\r
+               m_Config.bIgnoreUndefinedC_x[nAppID] = static_cast<BYTE>(AfxGetApp()->GetProfileInt(appName, entry, 0));\r
                entry.LoadString(IDC_REG_ENTRY_ENABLE_CUA);\r
-               m_Config.bEnableCUA[nAppID] = AfxGetApp()->GetProfileInt(appName, entry, 0);\r
+               m_Config.bEnableCUA[nAppID] = static_cast<BYTE>(AfxGetApp()->GetProfileInt(appName, entry, 0));\r
                entry.LoadString(IDS_REG_ENTRY_326_COMPATIBLE);\r
-               m_Config.b326Compatible[nAppID] = AfxGetApp()->GetProfileInt(appName, entry, 0);\r
+               m_Config.b326Compatible[nAppID] = static_cast<BYTE>(AfxGetApp()->GetProfileInt(appName, entry, 0));\r
        }\r
 }\r
 \r
@@ -564,68 +219,53 @@ void CProfile::SaveRegistry()
 {\r
        const CString section(MAKEINTRESOURCE(IDS_REG_SECTION_APPLICATION));    \r
        for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {\r
-               const LPCTSTR szAppName = m_Config.szSpecialApp[nAppID];\r
+               LPCTSTR appName = m_Config.szSpecialApp[nAppID];\r
                CString entry;\r
                entry.Format(IDS_REG_ENTRY_APPLICATION, nAppID);\r
-               if (!szAppName[0]) {\r
+               if (!appName[0]) {\r
                        if (!AfxGetApp()->GetProfileString(section, entry).IsEmpty())\r
                                AfxGetApp()->WriteProfileString(section, entry, _T(""));\r
                        continue;\r
                }\r
-               AfxGetApp()->WriteProfileString(section, entry, szAppName);\r
+               AfxGetApp()->WriteProfileString(section, entry, appName);\r
 \r
                entry.LoadString(IDS_REG_ENTRY_APPLICATOIN_TITLE);\r
-               CString appTitle = m_szAppTitle[nAppID];\r
+               CString appTitle = m_AppTitle[nAppID];\r
                appTitle.TrimLeft(_T(' '));\r
-               AfxGetApp()->WriteProfileString(szAppName, entry, appTitle);\r
+               AfxGetApp()->WriteProfileString(appName, entry, appTitle);\r
                entry.LoadString(IDS_REG_ENTRY_WINDOW_TEXT);\r
-               AfxGetApp()->WriteProfileString(szAppName, entry, m_Config.szWindowText[nAppID]);\r
+               AfxGetApp()->WriteProfileString(appName, entry, m_Config.szWindowText[nAppID]);\r
 \r
-               const CString regApp = CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)) + _T("\\") + szAppName;\r
                // Create all commands\r
                for (int nComID = 1; nComID < MAX_COMMAND; ++nComID)\r
-                       SaveCommand(szAppName, nComID);\r
+                       SaveKeyBind(appName, nComID, 0, 0);\r
                for (int nType = 0; nType < MAX_COMMAND_TYPE; ++nType)\r
                        for (int nKey = 0; nKey < MAX_KEY; ++nKey)\r
-                               SaveKeyBind(szAppName, m_Config.nCommandID[nAppID][nType][nKey], nType, nKey);\r
+                               SaveKeyBind(appName, m_Config.nCommandID[nAppID][nType][nKey], nType, nKey);\r
                for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID)\r
                        for (int nKeyID = 0; nKeyID < CDotXkeymacs::GetKeyNumber(nFuncID, nAppID); ++nKeyID) {\r
                                int nType, nKey;\r
                                CDotXkeymacs::GetKey(nFuncID, nAppID, nKeyID, &nType, &nKey);\r
-                               SaveKeyBind(szAppName, CDotXkeymacs::GetFunctionSymbol(nFuncID), nType, nKey);\r
+                               SaveKeyBind(appName, CDotXkeymacs::GetFunctionSymbol(nFuncID), nType, nKey);\r
                        }\r
 \r
                entry.LoadString(IDS_REG_ENTRY_KILL_RING_MAX);\r
-               AfxGetApp()->WriteProfileInt(szAppName, entry, m_Config.nKillRingMax[nAppID]);\r
+               AfxGetApp()->WriteProfileInt(appName, entry, m_Config.nKillRingMax[nAppID]);\r
                entry.LoadString(IDS_REG_ENTRY_USE_DIALOG_SETTING);\r
-               AfxGetApp()->WriteProfileInt(szAppName, entry, m_Config.bUseDialogSetting[nAppID]);\r
+               AfxGetApp()->WriteProfileInt(appName, entry, m_Config.bUseDialogSetting[nAppID]);\r
                entry.LoadString(IDS_REG_ENTRY_DISABLE_XKEYMACS);\r
-               AfxGetApp()->WriteProfileInt(szAppName, entry, m_Config.nSettingStyle[nAppID] == SETTING_DISABLE);\r
+               AfxGetApp()->WriteProfileInt(appName, entry, m_Config.nSettingStyle[nAppID] == SETTING_DISABLE);\r
                entry.LoadString(IDC_REG_ENTRY_IGNORE_META_CTRL);\r
-               AfxGetApp()->WriteProfileInt(szAppName, entry, m_Config.bIgnoreUndefinedMetaCtrl[nAppID]);\r
+               AfxGetApp()->WriteProfileInt(appName, entry, m_Config.bIgnoreUndefinedMetaCtrl[nAppID]);\r
                entry.LoadString(IDC_REG_ENTRY_IGNORE_C_X);\r
-               AfxGetApp()->WriteProfileInt(szAppName, entry, m_Config.bIgnoreUndefinedC_x[nAppID]);\r
+               AfxGetApp()->WriteProfileInt(appName, entry, m_Config.bIgnoreUndefinedC_x[nAppID]);\r
                entry.LoadString(IDC_REG_ENTRY_ENABLE_CUA);\r
-               AfxGetApp()->WriteProfileInt(szAppName, entry, m_Config.bEnableCUA[nAppID]);\r
+               AfxGetApp()->WriteProfileInt(appName, entry, m_Config.bEnableCUA[nAppID]);\r
                entry.LoadString(IDS_REG_ENTRY_326_COMPATIBLE);\r
-               AfxGetApp()->WriteProfileInt(szAppName, entry, m_Config.b326Compatible[nAppID]);\r
+               AfxGetApp()->WriteProfileInt(appName, entry, m_Config.b326Compatible[nAppID]);\r
        }\r
 }\r
 \r
-void CProfile::LoadData()\r
-{\r
-       CDotXkeymacs::Load();\r
-       LevelUp();\r
-       LoadRegistry();\r
-}\r
-\r
-void CProfile::SaveData()\r
-{\r
-       DeleteAllRegistryData();\r
-       SaveRegistry();\r
-       SetDllData();\r
-}\r
-\r
 void CProfile::SetDllData()\r
 {\r
        memset(m_Config.nFunctionID, -1, sizeof(m_Config.nFunctionID));\r
@@ -638,7 +278,7 @@ void CProfile::SetDllData()
                        for (int nKey = 0; nKey < MAX_KEY; ++nKey)\r
                                if ((nType & CONTROLX) && m_Config.nCommandID[nAppID][nType][nKey])\r
                                        m_Config.nCommandID[nAppID][CONTROL]['X'] = 1; // C-x is available.\r
-               for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID)\r
+               for (BYTE nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID)\r
                        for (int nKeyID = 0; nKeyID < CDotXkeymacs::GetKeyNumber(nFuncID, nAppID); ++nKeyID) {\r
                                int nType, nKey;\r
                                CDotXkeymacs::GetKey(nFuncID, nAppID, nKeyID, &nType, &nKey);\r
@@ -647,7 +287,7 @@ void CProfile::SetDllData()
                                        m_Config.nCommandID[nAppID][CONTROL]['X'] = 1; // C-x is available.\r
                        }\r
        }\r
-       m_Config.b106Keyboard = Is106Keyboard();\r
+       m_Config.b106Keyboard = static_cast<BYTE>(Is106Keyboard());\r
        CXkeymacsDll::SetConfig(m_Config);\r
        CXkeymacsApp *pApp = static_cast<CXkeymacsApp *>(AfxGetApp());\r
        if (!pApp->IsWow64())\r
@@ -657,310 +297,54 @@ void CProfile::SetDllData()
        pApp->SendIPCMessage(XKEYMACS_RELOAD);\r
 }\r
 \r
-void CProfile::ReadKeyBind(int& nCommandType, int& nKey, const LPCTSTR szKeyBind)\r
-{\r
-       nCommandType = KeyBind2CommandType(szKeyBind);\r
-       nKey = KeyBind2Key(szKeyBind + _tcslen(CommandType2String(nCommandType)));\r
-}\r
-\r
-CString CProfile::WriteKeyBind(const int nType, const int nKey)\r
-{\r
-       CString szKeyBind;\r
-       szKeyBind.Format(_T("%s%s"), CommandType2String(nType), Key2String(nKey));\r
-       return szKeyBind;\r
-}\r
-\r
-int CProfile::KeyBind2CommandType(LPCTSTR szKeyBind)\r
-{\r
-       for (int nType = MAX_COMMAND_TYPE - 1; nType; --nType) {\r
-               if (IsCommandType(nType, szKeyBind)) {\r
-                       return nType;\r
-               }\r
-       }\r
-       return NONE;\r
-}\r
-\r
-int CProfile::KeyBind2Key(LPCTSTR szKey)\r
-{\r
-       for (int nKey = 1; nKey <= 0xff; ++nKey) {\r
-               if (!_tcscmp(szKey, Key2String(nKey))) {\r
-                       return nKey;\r
-               }\r
-       }\r
-       return 0;\r
-}\r
-\r
-LPCTSTR CProfile::CommandType2String(int nType)\r
-{\r
-       if (nType < 0 || sizeof(CommandTypes) / sizeof(CommandTypes[0]) <= nType) {\r
-               ASSERT(0);\r
-               nType = NONE;\r
-       }\r
-       return CommandTypes[nType].szName;\r
-}\r
-\r
-LPCTSTR CProfile::Key2String(int nKey)\r
+void CProfile::SaveKeyBind(LPCTSTR appName, int comID, int type, int key)\r
 {\r
-       if (CProfile::Is106Keyboard()) {\r
-               switch (nKey) {\r
-               case 0xBA:\r
-                       return _T(":");\r
-               case 0xBB:\r
-                       return _T(";");\r
-               case 0xC0:\r
-                       return _T("@");\r
-               case 0xDE:\r
-                       return _T("^");\r
-               default:\r
-                       break;\r
-               }\r
-       }\r
-\r
-       if (nKey < 0 || sizeof(KeyNames) / sizeof(KeyNames[0]) <= nKey) {\r
-               ASSERT(0);\r
-               nKey = 0;\r
-       }\r
-       return KeyNames[nKey].name;\r
-}\r
-\r
-BOOL CProfile::IsCommandType(const int nType, LPCTSTR szKeyBind)\r
-{\r
-       LPCTSTR szCommandType = CommandType2String(nType);\r
-\r
-       if (!_tcsnicmp(szKeyBind, szCommandType, _tcslen(szCommandType))) {\r
-               return TRUE;\r
-       }\r
-\r
-       return FALSE;\r
-}\r
-\r
-void CProfile::SaveKeyBind(const LPCSTR szAppName, const int nComID, const int nType, const int nKey)\r
-{\r
-       if (!nComID)\r
+       if (!comID)\r
                return;\r
-       const LPCSTR szComName = CCommands::GetCommandName(nComID);\r
-       if (!szComName[0])\r
+       LPCTSTR comName = CCommands::GetCommandName(comID);\r
+       if (!comName[0])\r
                return;\r
-       SaveKeyBind(szAppName, szComName, nType, nKey);\r
+       SaveKeyBind(appName, comName, type, key);\r
 }\r
 \r
-void CProfile::SaveKeyBind(const LPCSTR szAppName, const LPCSTR szComName, const int nType, const int nKey)\r
+void CProfile::SaveKeyBind(LPCTSTR appName, LPCTSTR comName, int type, int key)\r
 {\r
-       const CString szKeyBind = WriteKeyBind(nType, nKey);\r
-       CString szSubKey = CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)) + _T("\\") + szAppName + _T("\\") + szComName;\r
-       if (!szKeyBind.IsEmpty())\r
-               szSubKey += _T("\\") + szKeyBind;\r
+       CString subKey = CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)) + _T("\\") + appName + _T("\\") + comName;\r
+       CString s = KeyToString(type, key);\r
+       if (!s.IsEmpty())\r
+               subKey = subKey + _T("\\") + s;\r
        HKEY hKey = NULL;\r
-       if (RegCreateKeyEx(HKEY_CURRENT_USER, szSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL) == ERROR_SUCCESS)\r
+       if (RegCreateKeyEx(HKEY_CURRENT_USER, subKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL) == ERROR_SUCCESS)\r
                RegCloseKey(hKey);\r
 }\r
 \r
-void CProfile::SaveCommand(const LPCSTR szAppName, const int nComID)\r
+void CProfile::StringToKey(LPCTSTR str, int& type, int& key)\r
 {\r
-       SaveKeyBind(szAppName, nComID, 0, 0);\r
+       m_KeyString.ToKey(str, type, key);\r
 }\r
 \r
-void CProfile::AddKeyBind2C_(const LPCSTR szAppName, const BYTE bVk)\r
+CString CProfile::KeyToString(int type, int key)\r
 {\r
-       int nComID;\r
-       for (nComID = 0; nComID < MAX_COMMAND; ++nComID)\r
-               if (Commands[nComID].fCommand == CCommands::C_)\r
-                       break;\r
-       SaveKeyBind(szAppName, nComID, NONE, bVk);\r
+       return m_KeyString.ToString(type, key);\r
 }\r
 \r
-void CProfile::LevelUp()\r
+void CProfile::InitAppList(CProperties& cProperties)\r
 {\r
-       const int nDefalutLevel = 0;\r
-       const int nLatestLevel = 4;\r
-\r
-       CString szSection;\r
-       CString szEntry;\r
-       szEntry.Format(_T("Level"));\r
-\r
-       switch (AfxGetApp()->GetProfileInt(szSection, szEntry, nDefalutLevel)) {\r
-       case nDefalutLevel:\r
-               {\r
-                       for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {\r
-                               CString szEntry;\r
-                               szEntry.Format(IDS_REG_ENTRY_APPLICATION, nAppID);\r
-\r
-                               CString szApplicationName;\r
-                               szApplicationName = AfxGetApp()->GetProfileString(CString(MAKEINTRESOURCE(IDS_REG_SECTION_APPLICATION)), szEntry);\r
-                               if (szApplicationName.IsEmpty()) {\r
-                                       continue;\r
-                               }\r
-\r
-                               AddKeyBind2C_(szApplicationName, VK_LCONTROL);\r
-                               AddKeyBind2C_(szApplicationName, VK_RCONTROL);\r
-                       }\r
-               }\r
-               // Do NOT write break; here.\r
-       case 1:\r
-               {\r
-                       for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {\r
-                               CString szEntry;\r
-                               szEntry.Format(IDS_REG_ENTRY_APPLICATION, nAppID);\r
-\r
-                               CString szApplicationName;\r
-                               szApplicationName = AfxGetApp()->GetProfileString(CString(MAKEINTRESOURCE(IDS_REG_SECTION_APPLICATION)), szEntry);\r
-                               if (szApplicationName.IsEmpty()) {\r
-                                       continue;\r
-                               }\r
-\r
-                               // Set kill-ring-max 1 if it is 0.\r
-                               if (!AfxGetApp()->GetProfileInt(szApplicationName, CString(MAKEINTRESOURCE(IDS_REG_ENTRY_KILL_RING_MAX)), 0)) {\r
-                                       AfxGetApp()->WriteProfileInt(szApplicationName, CString(MAKEINTRESOURCE(IDS_REG_ENTRY_KILL_RING_MAX)), 1);\r
-                               }\r
-                       }\r
-               }\r
-               // Do NOT write break; here.\r
-       case 2:\r
-               {\r
-                       for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {\r
-                               CString szEntry;\r
-                               szEntry.Format(IDS_REG_ENTRY_APPLICATION, nAppID);\r
-\r
-                               CString szApplicationName;\r
-                               szApplicationName = AfxGetApp()->GetProfileString(CString(MAKEINTRESOURCE(IDS_REG_SECTION_APPLICATION)), szEntry);\r
-                               if (szApplicationName.IsEmpty()) {\r
-                                       continue;\r
-                               }\r
-\r
-                               // Chaged a label from Enter to newline.\r
-                               CString szSrcSubKey(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA));\r
-                               szSrcSubKey += _T("\\") + szApplicationName + _T("\\") + _T("Enter");\r
-                               CString szDestSubKey(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA));\r
-                               szDestSubKey += _T("\\") + szApplicationName + _T("\\") + _T("newline");\r
-                               HKEY hKeyDest = NULL;\r
-                               if (RegCreateKeyEx(HKEY_CURRENT_USER, szDestSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKeyDest, NULL) == ERROR_SUCCESS) {\r
-                                       SHCopyKey(HKEY_CURRENT_USER, szSrcSubKey, hKeyDest, NULL);\r
-                                       SHDeleteKey(HKEY_CURRENT_USER, szSrcSubKey);\r
-                                       RegCloseKey(hKeyDest);\r
-                               }\r
-                       }\r
-               }\r
-               // Do NOT write break; here.\r
-       case 3:\r
-               {\r
-                       for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {\r
-                               CString szEntry;\r
-                               szEntry.Format(IDS_REG_ENTRY_APPLICATION, nAppID);\r
-\r
-                               CString szApplicationName;\r
-                               szApplicationName = AfxGetApp()->GetProfileString(CString(MAKEINTRESOURCE(IDS_REG_SECTION_APPLICATION)), szEntry);\r
-                               if (szApplicationName.IsEmpty()) {\r
-                                       continue;\r
-                               }\r
-\r
-                               // rename original function to remove IDS_REG_ORIGINAL_PREFIX\r
-                               for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID) {\r
-                                       HKEY hKey = NULL;\r
-                                       CString szSubKey(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA));\r
-                                       szSubKey += _T("\\") + szApplicationName + _T("\\") + CString(MAKEINTRESOURCE(IDS_REG_ORIGINAL_PREFIX)) + CDotXkeymacs::GetFunctionSymbol(nFuncID);\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; RegEnumKeyEx(hKey, dwIndex, szKeyBind, &dwKeyBind, NULL, NULL, NULL, &ft) == ERROR_SUCCESS; ++dwIndex) {\r
-                                                       int nType, nKey;\r
-                                                       ReadKeyBind(nType, nKey, szKeyBind);\r
-                                                       SaveKeyBind(szApplicationName, CDotXkeymacs::GetFunctionSymbol(nFuncID), nType, nKey);\r
-\r
-                                                       memset(szKeyBind, 0, sizeof(szKeyBind));\r
-                                                       dwKeyBind = sizeof(szKeyBind);\r
-                                               }\r
-                                               RegCloseKey(hKey);\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-//     case 4:\r
-//             foo();\r
-//     ...\r
-//     case nLatestLevel-1:\r
-//             bar();\r
-               AfxGetApp()->WriteProfileInt(szSection, szEntry, nLatestLevel);\r
-               break;\r
-       default:\r
-               break;\r
-       }\r
-}\r
-\r
-void CProfile::InitDllData()\r
-{\r
-       LoadData();\r
-       SetDllData();\r
-}\r
-\r
-void CProfile::ClearData(const CString szCurrentApplication)\r
-{\r
-       for (int nAppID = 0; nAppID < MAX_APP; ++nAppID)\r
-               if (szCurrentApplication == m_Config.szSpecialApp[nAppID]) {\r
-                       ZeroMemory(m_Config.nCommandID[nAppID], sizeof(m_Config.nCommandID[nAppID]));\r
-                       ZeroMemory(m_Config.szSpecialApp[nAppID], CLASS_NAME_LENGTH);\r
-                       return;\r
-               }\r
-}\r
-\r
-// return count of saved settings\r
-int CProfile::GetSavedSettingCount()\r
-{\r
-       int nSavedSetting = 0;\r
-       for (int nAppID = 0; nAppID < MAX_APP; ++nAppID)\r
-               if (m_Config.szSpecialApp[nAppID][0])\r
-                       ++nSavedSetting;\r
-       return nSavedSetting;\r
-}\r
-\r
-void CProfile::InitApplicationList(CComboBox *const cApplicationList)\r
-{\r
-       cApplicationList->ResetContent();\r
-\r
        GetTaskList();\r
 \r
-       EnumWindows(EnumWindowsProc, (LPARAM)cApplicationList);\r
+       EnumWindows(EnumWindowsProc, reinterpret_cast<LPARAM>(&cProperties));\r
 \r
-       CString szListItem;\r
        for (int i = 0; i < MAX_APP; ++i) {\r
-               const LPCTSTR szAppName = m_Config.szSpecialApp[i];\r
-               const LPCTSTR szAppTitle = m_szAppTitle[i];\r
-               if (!szAppName[0] || !_tcscmp(szAppName, _T("IME")))\r
+               LPCTSTR appName = m_Config.szSpecialApp[i];\r
+               LPCTSTR appTitle = m_AppTitle[i];\r
+               if (!appName[0] || !_tcscmp(appName, _T("IME")))\r
+                       continue;\r
+               if (CString(MAKEINTRESOURCE(IDS_DEFAULT)) == appName ||\r
+                               CString(MAKEINTRESOURCE(IDS_DIALOG)) == appName)\r
                        continue;\r
-               szListItem.Format(IDS_APPLICATION_LIST_ITEM, szAppTitle, szAppName);\r
-               if (IsNotSameString(cApplicationList, szListItem) &&\r
-                               !IsDefault(szAppName) && !IsDialog(szAppName))\r
-                       cApplicationList->AddString(szListItem);\r
+               cProperties.AddItem(appTitle, appName);\r
        }\r
-\r
-       AddIMEInfo(cApplicationList);\r
-\r
-       // Add Dialog\r
-       cApplicationList->InsertString(0, CString(MAKEINTRESOURCE(IDS_DIALOG_TITLE)));\r
-\r
-       // Add Default\r
-       cApplicationList->InsertString( 0, CString(MAKEINTRESOURCE(IDS_DEFAULT_TITLE)));\r
-       cApplicationList->SelectString(-1, CString(MAKEINTRESOURCE(IDS_DEFAULT_TITLE)));\r
-}\r
-\r
-void CProfile::AddIMEInfo(CComboBox *cApplicationList)\r
-{\r
-       const UINT n = GetKeyboardLayoutList(0, NULL);\r
-       if (!n)\r
-               return;\r
-       std::vector<HKL> hkls(n);\r
-       GetKeyboardLayoutList(n, &hkls[0]);\r
-       TCHAR szFileName[MAX_PATH];\r
-       TCHAR szDescription[WINDOW_TEXT_LENGTH];\r
-       for (std::vector<HKL>::const_iterator p = hkls.begin(); p != hkls.end(); ++p)\r
-               if (ImmGetDescription(*p, szDescription, WINDOW_TEXT_LENGTH) &&\r
-                               ImmGetIMEFileName(*p, szFileName, MAX_PATH)) {\r
-                       CString item;\r
-                       item.Format(IDS_APPLICATION_LIST_ITEM, szDescription, szFileName);\r
-                       if (IsNotSameString(cApplicationList, item))\r
-                               cApplicationList->AddString(item);\r
-               }\r
+       AddIMEInfo(cProperties);\r
 }\r
 \r
 void CProfile::GetTaskList()\r
@@ -983,137 +367,178 @@ void CProfile::GetTaskList()
        CloseHandle(hProcessSnap);\r
 }\r
 \r
-// return application index\r
-// and update setting style\r
-// if there is NOT the application in the data, this function takes care of it.\r
-int CProfile::GetApplicationIndex(const CString szApplicationName, const BOOL bSaveAndValidate, int *const nSettingStyle)\r
+BOOL CALLBACK CProfile::EnumWindowsProc(HWND hWnd, LPARAM lParam)\r
 {\r
-       if (!bSaveAndValidate) // SetDialogData\r
-               *nSettingStyle = SETTING_UNDEFINED;\r
-       int nAppID = GetAppID(szApplicationName);\r
-       if (nAppID == MAX_APP) {\r
-               if (bSaveAndValidate) { // GetDialogData\r
-                       for (nAppID = 0; nAppID < MAX_APP; ++nAppID)\r
-                               if (!m_Config.szSpecialApp[nAppID][0]) {\r
-                                       _tcsncpy_s(m_Config.szSpecialApp[nAppID], szApplicationName, _TRUNCATE);\r
-                                       break;\r
-                               }\r
-                       if (nAppID == MAX_APP)\r
-                               return nAppID;\r
-               } else { // SetDialogData\r
-                       for (nAppID = 0; nAppID < MAX_APP; ++nAppID)\r
-                               if (IsDefault(m_Config.szSpecialApp[nAppID])) {\r
-                                       *nSettingStyle = SETTING_DEFAULT;\r
-                                       break;\r
-                               }\r
-                       if (nAppID == MAX_APP)\r
-                               return nAppID;\r
+       CProperties *pProperties = reinterpret_cast<CProperties*>(lParam);\r
+       PTASK_LIST pTask = CProfile::m_TaskList;\r
+       \r
+       TCHAR szWindowName[WINDOW_TEXT_LENGTH];\r
+       TCHAR szClassName[CLASS_NAME_LENGTH];\r
+       WINDOWPLACEMENT wpl;\r
+       \r
+       wpl.length = sizeof(WINDOWPLACEMENT);\r
+       ::GetWindowText(hWnd, szWindowName, sizeof(szWindowName));\r
+       GetClassName(hWnd, szClassName, sizeof(szClassName));\r
+\r
+       CString appTitle;\r
+       // Get Process Name\r
+       DWORD dwProcessId = 0;\r
+       GetWindowThreadProcessId(hWnd, &dwProcessId);\r
+       DWORD i;\r
+       for (i = 0; i < CProfile::m_dwTasks; ++i) {\r
+               if (pTask[i].dwProcessId == dwProcessId) {\r
+\r
+                       // Get Application Name\r
+                       if (szWindowName[0] == '\0') {\r
+                               continue;\r
+                       }\r
+                       if (!_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_B2)), sizeof(pTask[i].ProcessName))) {\r
+                               appTitle.LoadString(IDS_BECKY);\r
+                       } else if (!_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_EXPLORER)), sizeof(pTask[i].ProcessName))) {\r
+                               appTitle.LoadString(IDS_PROGRAM_MANAGER);\r
+                       } else if (!_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_MSIMN)), sizeof(pTask[i].ProcessName))) {\r
+                               appTitle.LoadString(IDS_OUTLOOK_EXPRESS);\r
+                       } else if (!_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_PROJECT)), sizeof(pTask[i].ProcessName))\r
+                                       || !_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_EXCEL)), sizeof(pTask[i].ProcessName))\r
+                                       || !_tcsnicmp(pTask[i].ProcessName, _T("psp.exe"), sizeof(pTask[i].ProcessName))) {\r
+                               GetAppTitle(appTitle, szWindowName, 1);\r
+                       } else if (!_tcsnicmp(pTask[i].ProcessName, _T("sakura.exe"), sizeof(pTask[i].ProcessName))) {\r
+                               GetAppTitle(appTitle, szWindowName, 2); // '.' is included, so...\r
+                       } else if (!_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_MSDN)), sizeof(pTask[i].ProcessName))) {\r
+                               appTitle = szWindowName;\r
+                       } else if (!_tcsnicmp(pTask[i].ProcessName, _T("devenv.exe"), sizeof(pTask[i].ProcessName))) {\r
+                               appTitle.Format(_T("Microsoft Visual Studio .NET"));\r
+                       } else if (!_tcsnicmp(pTask[i].ProcessName, _T("vb6.exe"), sizeof(pTask[i].ProcessName))) {\r
+                               appTitle.Format(_T("Microsoft Visual Basic"));\r
+                       } else if (!_tcsnicmp(pTask[i].ProcessName, _T("ssexp.exe"), sizeof(pTask[i].ProcessName))) {\r
+                               appTitle.LoadString(IDS_VISUAL_SOURCESAFE_EXPLORER);\r
+                       } else if (!_tcsnicmp(pTask[i].ProcessName, _T("sh.exe"), sizeof(pTask[i].ProcessName))) {\r
+                               appTitle.Format(_T("MKS Korn Shell"));\r
+                       } else if (!_tcsnicmp(pTask[i].ProcessName, _T("csh.exe"), sizeof(pTask[i].ProcessName))) {\r
+                               appTitle.Format(_T("C Shell"));\r
+                       } else if (!_tcsnicmp(pTask[i].ProcessName, _T("vim.exe"), sizeof(pTask[i].ProcessName))) {\r
+                               appTitle.Format(_T("VIM"));\r
+                       } else {\r
+                               AppName::CorrectAppName(szWindowName, pTask[i].ProcessName);\r
+                               GetAppTitle(appTitle, szWindowName);\r
+                       }\r
+                       break;\r
                }\r
        }\r
-       if (bSaveAndValidate) // GetDialogData\r
-               m_Config.nSettingStyle[nAppID] = *nSettingStyle;\r
-       else { // SetDialogData\r
-               if (*nSettingStyle == SETTING_UNDEFINED) // It means that *nSettingStyle != SETTING_DEFAULT.\r
-                       *nSettingStyle = m_Config.nSettingStyle[nAppID];\r
+       \r
+       if (IsWindowVisible(hWnd) && // Is visible?\r
+                       GetWindow(hWnd, GW_OWNER) == NULL && // Is top level window?\r
+                       lstrlen(szWindowName) > 0) { // Have caption?\r
+               pProperties->AddItem(appTitle, pTask[i].ProcessName);\r
        }\r
-       return nAppID;\r
+       return TRUE;\r
 }\r
 \r
-BOOL CProfile::Is106Keyboard()\r
+// This function returns the nth string in a window name separated by " - ".\r
+// If there aren't a sufficient number of strings, it returns the last string\r
+// appropriate for the title.\r
+bool CProfile::GetAppTitle(CString& appTitle, const CString& windowName, int nth)\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
+       const CString sep(MAKEINTRESOURCE(IDS_SEPARATE_WINDOWTITLE));\r
+       int nSep = windowName.Find(sep);\r
+       if (nSep < 0) {\r
+               appTitle = windowName;\r
+               return false;\r
        }\r
-\r
-       return keyboard == JAPANESE_KEYBOARD;\r
+       if (GetAppTitle(appTitle, windowName.Right(windowName.GetLength() - nSep - sep.GetLength()), --nth) ||\r
+                       !nth || nth > 0 && appTitle.GetAt(0) != _T('[') && appTitle.FindOneOf(_T(".]")) == -1)\r
+               return true;\r
+       appTitle = windowName.Left(nSep);\r
+       return false;\r
 }\r
 \r
-BOOL CProfile::IsTheString(const CString sz, const UINT nID)\r
+void CProfile::AddIMEInfo(CProperties& cProperties)\r
 {\r
-       return sz == CString(MAKEINTRESOURCE(nID));\r
+       IMEList imeList;\r
+       for (IMEListIterator p = imeList.begin(); p != imeList.end(); ++p)\r
+               cProperties.AddItem(p->szDescription, p->szFileName);\r
 }\r
 \r
-// if sz is "Default", return TRUE\r
-BOOL CProfile::IsDefault(const CString sz)\r
+void CProfile::ClearData(LPCTSTR appName)\r
 {\r
-       return IsTheString(sz, IDS_DEFAULT);\r
+       int n = GetAppID(appName);\r
+       if (n == MAX_APP)\r
+               return;\r
+       ZeroMemory(m_Config.nCommandID[n], sizeof(m_Config.nCommandID[n]));\r
+       ZeroMemory(m_Config.szSpecialApp[n], CLASS_NAME_LENGTH);\r
 }\r
 \r
-// if sz is "Dialog", return TRUE\r
-BOOL CProfile::IsDialog(const CString sz)\r
+void CProfile::CopyDefault(LPCTSTR appName)\r
 {\r
-       return IsTheString(sz, IDS_DIALOG);\r
+       int dst = AssignAppID(appName);\r
+       int src = DefaultAppID();\r
+       if (src == MAX_APP || dst == MAX_APP)\r
+               return;\r
+       SetSettingStyle(dst, SETTING_SPECIFIC);\r
+\r
+#define CopyMember(member) CopyMemory(&m_Config. ## member ## [dst], &m_Config. ## member ## [src], sizeof(m_Config. ## member ## [src]))\r
+       CopyMember(b326Compatible);\r
+       CopyMember(nFunctionID);\r
+       CopyMember(bEnableCUA);\r
+       CopyMember(bUseDialogSetting);\r
+       CopyMember(bIgnoreUndefinedC_x);\r
+       CopyMember(bIgnoreUndefinedMetaCtrl);\r
+       CopyMember(nKillRingMax);\r
+       CopyMember(nCommandID);\r
+#undef CopyMember\r
 }\r
 \r
-void CProfile::GetApplicationTitle(CComboBox *const cApplicationList, CString &rList, const int nIndex)\r
+int CProfile::AssignAppID(LPCTSTR appName)\r
 {\r
-       if (0 <= nIndex) {\r
-               cApplicationList->GetLBText(nIndex, rList);\r
-       } else {\r
-               cApplicationList->GetWindowText(rList);\r
-       }\r
+       int nAppID = GetAppID(appName);\r
+       if (nAppID != MAX_APP)\r
+               return nAppID;\r
+       for (nAppID = 0; nAppID < MAX_APP; ++nAppID)\r
+               if (!m_Config.szSpecialApp[nAppID][0]) {\r
+                       _tcsncpy_s(m_Config.szSpecialApp[nAppID], appName, _TRUNCATE);\r
+                       return nAppID;\r
+               }\r
+       return nAppID;\r
+}\r
 \r
-       if (IsTheString(rList, IDS_DEFAULT_TITLE)) {\r
-               rList.LoadString(IDS_DEFAULT);\r
-       }\r
+int CProfile::DefaultAppID()\r
+{\r
+       const CString name(MAKEINTRESOURCE(IDS_DEFAULT));\r
+       for(int nAppID = 0; nAppID < MAX_APP; ++nAppID)\r
+               if (name == m_Config.szSpecialApp[nAppID])\r
+                       return nAppID;\r
+       return MAX_APP;\r
+}\r
 \r
-       if (IsTheString(rList, IDS_DIALOG_TITLE)) {\r
-               rList.LoadString(IDS_DIALOG);\r
-       }\r
+int CProfile::GetAppID(LPCTSTR appName)\r
+{\r
+       int nAppID = 0;\r
+       for (nAppID = 0; nAppID < MAX_APP; ++nAppID)\r
+               if (!_tcscmp(appName, m_Config.szSpecialApp[nAppID]))\r
+                       break;\r
+       return nAppID;\r
+}\r
 \r
-       return;\r
+int CProfile::GetSettingStyle(int nAppID)\r
+{\r
+       if (nAppID == MAX_APP)\r
+               return SETTING_DEFAULT;\r
+       return m_Config.nSettingStyle[nAppID];\r
 }\r
 \r
-void CProfile::UpdateApplicationTitle(CComboBox *const cApplicationList, const CString szCurrentApplication, const int nAppID, const BOOL bSaveAndValidate)\r
+void CProfile::SetSettingStyle(int nAppID, int nSettingStyle)\r
 {\r
-       static CString szApplicationTitle;\r
-       if (bSaveAndValidate) { // GetDialogData\r
-               if (!CProfile::IsDefault(szCurrentApplication))\r
-                       _tcsncpy_s(m_szAppTitle[nAppID], szApplicationTitle, _TRUNCATE);\r
-               szApplicationTitle.Empty();\r
-       } else { // SetDialogData\r
-               CString szListItem;\r
-               CProfile::GetApplicationTitle(cApplicationList, szListItem);\r
-               const int nEndTitle = szListItem.ReverseFind(_T('('));\r
-               if (nEndTitle > 0)\r
-                       szApplicationTitle = szListItem.Left(nEndTitle);\r
-       }\r
+       if (nAppID == MAX_APP)\r
+               return;\r
+       m_Config.nSettingStyle[nAppID] = static_cast<BYTE>(nSettingStyle);\r
 }\r
 \r
-void CProfile::SetCommandID(const int nAppID, const int nType, const int nKey, int nComID)\r
+void CProfile::SetAppTitle(int nAppID, const CString& appTitle)\r
 {\r
-       if (nKey == 0xf0 && Commands[nComID].fCommand == CCommands::C_)\r
-               // Change CommandID C_Eisu\r
-               for (nComID = 1; nComID < MAX_COMMAND; ++nComID)\r
-                       if (Commands[nComID].fCommand == CCommands::C_Eisu)\r
-                               break;\r
-       m_Config.nCommandID[nAppID][nType][nKey] = nComID;\r
+       _tcsncpy_s(m_AppTitle[nAppID], appTitle, _TRUNCATE);\r
 }\r
 \r
-int CProfile::GetCommandID(const int nAppID, const int nType, const int nKey)\r
+int CProfile::GetCommandID(int nAppID, int nType, int nKey)\r
 {\r
        int nComID = m_Config.nCommandID[nAppID][nType][nKey];\r
        if (nKey == 0xf0 && Commands[nComID].fCommand == CCommands::C_Eisu)\r
@@ -1124,108 +549,89 @@ int CProfile::GetCommandID(const int nAppID, const int nType, const int nKey)
        return nComID;\r
 }\r
 \r
-void CProfile::SetKillRingMax(const int nAppID, const int nKillRingMax)\r
+void CProfile::SetCommandID(int nAppID, int nType, int nKey, int nComID)\r
 {\r
-       m_Config.nKillRingMax[nAppID] = nKillRingMax;\r
+       if (nKey == 0xf0 && Commands[nComID].fCommand == CCommands::C_)\r
+               // Change CommandID C_Eisu\r
+               for (nComID = 1; nComID < MAX_COMMAND; ++nComID)\r
+                       if (Commands[nComID].fCommand == CCommands::C_Eisu)\r
+                               break;\r
+       m_Config.nCommandID[nAppID][nType][nKey] = static_cast<BYTE>(nComID);\r
 }\r
 \r
-int CProfile::GetKillRingMax(const int nAppID)\r
+BOOL CProfile::GetUseDialogSetting(int nAppID)\r
 {\r
-       return m_Config.nKillRingMax[nAppID];\r
+       return m_Config.bUseDialogSetting[nAppID];\r
 }\r
 \r
-void CProfile::SetUseDialogSetting(const int nAppID, const BOOL bUseDialogSetting)\r
+void CProfile::SetUseDialogSetting(int nAppID, BOOL bUseDialogSetting)\r
 {\r
-       m_Config.bUseDialogSetting[nAppID] = bUseDialogSetting;\r
+       m_Config.bUseDialogSetting[nAppID] = static_cast<BYTE>(bUseDialogSetting);\r
 }\r
 \r
-BOOL CProfile::GetUseDialogSetting(const int nAppID)\r
+BOOL CProfile::GetEnableCUA(int nAppID)\r
 {\r
-       return m_Config.bUseDialogSetting[nAppID];\r
+       return m_Config.bEnableCUA[nAppID];\r
 }\r
 \r
-void CProfile::SetWindowText(const int nAppID, const CString szWindowText)\r
+void CProfile::SetEnableCUA(int nAppID, BOOL bEnableCUA)\r
 {\r
-       if (CUtils::GetWindowTextType(szWindowText) == IDS_WINDOW_TEXT_IGNORE)\r
-               _tcscpy_s(m_Config.szWindowText[nAppID], _T("*"));\r
-       else\r
-               _tcsncpy_s(m_Config.szWindowText[nAppID], szWindowText, _TRUNCATE);\r
+       m_Config.bEnableCUA[nAppID] = static_cast<BYTE>(bEnableCUA);\r
 }\r
 \r
-CString CProfile::GetWindowText(const int nAppID)\r
+int CProfile::GetKillRingMax(int nAppID)\r
 {\r
-       return m_Config.szWindowText[nAppID];\r
+       return m_Config.nKillRingMax[nAppID];\r
 }\r
 \r
-void CProfile::DeleteAllRegistryData()\r
+void CProfile::SetKillRingMax(int nAppID, int nKillRingMax)\r
 {\r
-       HKEY hkey = NULL;\r
-       if (RegOpenKeyEx(HKEY_CURRENT_USER, CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)), 0, KEY_ALL_ACCESS, &hkey) == ERROR_SUCCESS) {\r
-               // I am sure that I have to do only one time, but...\r
-               for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {\r
-                       DWORD dwIndex = 0;\r
-                       TCHAR szName[SUB_KEY_NAME_LENGTH] = {'\0'};\r
-                       DWORD dwName = sizeof(szName);\r
-                       FILETIME filetime;\r
-\r
-                       while (RegEnumKeyEx(hkey, dwIndex++, szName, &dwName, NULL, NULL, NULL, &filetime) == ERROR_SUCCESS) {\r
-//                             RegDeleteKey(hkey, szName);\r
-                               SHDeleteKey(hkey, szName);\r
-                               ZeroMemory(szName, sizeof(szName));\r
-                               dwName = sizeof(szName);\r
-                       }\r
-               }\r
-               RegCloseKey(hkey);\r
-       }\r
+       m_Config.nKillRingMax[nAppID] = static_cast<BYTE>(nKillRingMax > 255 ? 255 : nKillRingMax);\r
 }\r
 \r
-int CProfile::GetCurrentApplicationID(CComboBox *const cApplicationList, const CString szCurrentApplication)\r
+LPCTSTR CProfile::GetWindowText(int nAppID)\r
 {\r
-       int nCounter = cApplicationList->GetCount();\r
-       CString szListItem;\r
-       int nCurSel = cApplicationList->GetCurSel();\r
-\r
-       for (int i = 0; i < nCounter; ++i) {\r
-               cApplicationList->SetCurSel(i);\r
-               CProfile::GetApplicationTitle(cApplicationList, szListItem);\r
-               if (szListItem.Find(szCurrentApplication) != -1) {\r
-                       cApplicationList->SetCurSel(nCurSel);\r
-                       return i;\r
-               }\r
-       }\r
-       return -1;\r
+       return m_Config.szWindowText[nAppID];\r
 }\r
 \r
-void CProfile::CopyData(const CString szDstApp, const CString szSrcApp)\r
+void CProfile::SetWindowText(int nAppID, const CString& text)\r
 {\r
-       int nSettingStyle = SETTING_SPECIFIC;\r
-       const int nDstApp = GetApplicationIndex(szDstApp, TRUE, &nSettingStyle);\r
-       const int nSrcApp = GetAppID(szSrcApp);\r
-\r
-#define CopyMember(member) CopyMemory(&m_Config. ## member ## [nDstApp], &m_Config. ## member ## [nSrcApp], sizeof(m_Config. ## member ## [nSrcApp]))\r
-       CopyMember(b326Compatible);\r
-       CopyMember(nFunctionID);\r
-       CopyMember(bEnableCUA);\r
-       CopyMember(bUseDialogSetting);\r
-       CopyMember(bIgnoreUndefinedC_x);\r
-       CopyMember(bIgnoreUndefinedMetaCtrl);\r
-       CopyMember(nKillRingMax);\r
-       CopyMember(nCommandID);\r
-#undef CopyMember\r
+       _tcsncpy_s(m_Config.szWindowText[nAppID],\r
+               CUtils::GetWindowTextType(text) == IDS_WINDOW_TEXT_IGNORE ? _T("*") : text, _TRUNCATE);\r
 }\r
 \r
-// return application index\r
-// if there is NOT the application in the data, return MAX_APP\r
-int CProfile::GetAppID(const LPCSTR szAppName)\r
+BOOL CProfile::Is106Keyboard()\r
 {\r
-       int nAppID = 0;\r
-       for (nAppID = 0; nAppID < MAX_APP; ++nAppID)\r
-               if (!_tcscmp(szAppName, m_Config.szSpecialApp[nAppID]))\r
-                       break;\r
-       return nAppID;\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
+                       const 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
-// Return True if Windows Vista or later.\r
 BOOL CProfile::IsVistaOrLater()\r
 {\r
        OSVERSIONINFO info = {sizeof(OSVERSIONINFO)};\r
@@ -1246,6 +652,40 @@ void CProfile::RestartComputer()
        ExitWindowsEx(EWX_REBOOT, 0);\r
 }\r
 \r
+void CProfile::ImportProperties()\r
+{\r
+       if (!AdjustTokenPrivileges(SE_RESTORE_NAME)) {\r
+               return;\r
+       }\r
+\r
+       CFileDialog oFileOpenDialog(TRUE, _T("reg"), _T("xkeymacs"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, CString(MAKEINTRESOURCE(IDS_REGISTRATION_FILTER)));\r
+       if (oFileOpenDialog.DoModal() == IDOK) {\r
+               CString szCommandLine;\r
+               szCommandLine.Format(_T("regedit \"%s\""), oFileOpenDialog.GetPathName());\r
+               CUtils::Run(szCommandLine, TRUE);       // regedit "x:\xkeymacs.reg"\r
+       }\r
+\r
+       DiableTokenPrivileges();\r
+       return;\r
+}\r
+\r
+void CProfile::ExportProperties()\r
+{\r
+       if (!AdjustTokenPrivileges(SE_BACKUP_NAME)) {\r
+               return;\r
+       }\r
+\r
+       CFileDialog oFileOpenDialog(FALSE, _T("reg"), _T("xkeymacs"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, CString(MAKEINTRESOURCE(IDS_REGISTRATION_FILTER)));\r
+       if (oFileOpenDialog.DoModal() == IDOK) {\r
+               CString szCommandLine;\r
+               szCommandLine.Format(_T("regedit /e \"%s\" HKEY_CURRENT_USER\\%s"), oFileOpenDialog.GetPathName(), CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)));\r
+               CUtils::Run(szCommandLine, TRUE);       // regedit /e "x:\xkeymacs.reg" HKEY_CURRENT_USER\Software\Oishi\XKeymacs2\r
+       }\r
+\r
+       DiableTokenPrivileges();\r
+       return;\r
+}\r
+\r
 BOOL CProfile::AdjustTokenPrivileges(LPCTSTR lpName)\r
 {\r
        BOOL rc = TRUE;\r
@@ -1290,50 +730,6 @@ BOOL CProfile::DiableTokenPrivileges()
        return rc;\r
 }\r
 \r
-void CProfile::ExportProperties()\r
-{\r
-       if (!AdjustTokenPrivileges(SE_BACKUP_NAME)) {\r
-               return;\r
-       }\r
-\r
-       CFileDialog oFileOpenDialog(FALSE, _T("reg"), _T("xkeymacs"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, CString(MAKEINTRESOURCE(IDS_REGISTRATION_FILTER)));\r
-       if (oFileOpenDialog.DoModal() == IDOK) {\r
-               CString szCommandLine;\r
-               szCommandLine.Format(_T("regedit /e \"%s\" HKEY_CURRENT_USER\\%s"), oFileOpenDialog.GetPathName(), CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)));\r
-               CUtils::Run(szCommandLine, TRUE);       // regedit /e "x:\xkeymacs.reg" HKEY_CURRENT_USER\Software\Oishi\XKeymacs2\r
-       }\r
-\r
-       DiableTokenPrivileges();\r
-       return;\r
-}\r
-\r
-void CProfile::ImportProperties()\r
-{\r
-       if (!AdjustTokenPrivileges(SE_RESTORE_NAME)) {\r
-               return;\r
-       }\r
-\r
-       CFileDialog oFileOpenDialog(TRUE, _T("reg"), _T("xkeymacs"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, CString(MAKEINTRESOURCE(IDS_REGISTRATION_FILTER)));\r
-       if (oFileOpenDialog.DoModal() == IDOK) {\r
-               CString szCommandLine;\r
-               szCommandLine.Format(_T("regedit \"%s\""), oFileOpenDialog.GetPathName());\r
-               CUtils::Run(szCommandLine, TRUE);       // regedit "x:\xkeymacs.reg"\r
-       }\r
-\r
-       DiableTokenPrivileges();\r
-       return;\r
-}\r
-\r
-BOOL CProfile::GetEnableCUA(const int nAppID)\r
-{\r
-       return m_Config.bEnableCUA[nAppID];\r
-}\r
-\r
-void CProfile::SetEnableCUA(const int nAppID, const BOOL bEnableCUA)\r
-{\r
-       m_Config.bEnableCUA[nAppID] = bEnableCUA;\r
-}\r
-\r
 int CProfile::GetKeyboardSpeed()\r
 {\r
        int nKeyboardSpeed = 31; // default value of Windows\r