OSDN Git Service

Add a new class AppName to handle application names. This class
authorKazuhiro Fujieda <fujieda@users.sourceforge.jp>
Mon, 24 Oct 2011 06:23:56 +0000 (15:23 +0900)
committerKazuhiro Fujieda <fujieda@users.sourceforge.jp>
Tue, 3 Jan 2012 12:03:48 +0000 (21:03 +0900)
includes code derived from the work by co <cogood@gmail.com>

12 files changed:
Readme.txt
Readme_J.txt
xkeymacs/profile.cpp
xkeymacsdll/AppName.cpp [new file with mode: 0644]
xkeymacsdll/AppName.h [new file with mode: 0644]
xkeymacsdll/Commands.cpp
xkeymacsdll/Utils.cpp
xkeymacsdll/Utils.h
xkeymacsdll/xkeymacsdll-vc10.vcxproj
xkeymacsdll/xkeymacsdll-vc10.vcxproj.filters
xkeymacsdll/xkeymacsdll.cpp
xkeymacsdll/xkeymacsdll.h

index 2ef999a..e740ef2 100644 (file)
@@ -107,6 +107,7 @@ The following developers have the copyrights of their contributions.
 * Kazuhiro Fujieda <fujieda@users.sourceforge.jp>\r
 * Tomohiro Kashiwada <kikairoya@gmail.com>\r
 * Harold Bamford <hbamford@users.sourceforge.net>\r
+* co <cogood@gmail.com>\r
 \r
 License\r
 -------\r
index d008e6a..42a82f2 100644 (file)
@@ -112,6 +112,7 @@ XKeymacs 3.48
 * Kazuhiro Fujieda <fujieda@users.sourceforge.jp>\r
 * Tomohiro Kashiwada <kikairoya@gmail.com>\r
 * Harold Bamford <hbamford@users.sourceforge.net>\r
+* co <cogood@gmail.com>\r
 \r
 \83\89\83C\83Z\83\93\83X\r
 ----------\r
index b313d70..17716c9 100644 (file)
@@ -8,6 +8,7 @@
 #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
 \r
@@ -379,7 +380,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
                                appTitle.Format(_T("VIM"));\r
                        } else {\r
-                               CUtils::SetCorrectApplicationName(pTask[i].ProcessName, szWindowName);\r
+                               AppName::CorrectAppName(szWindowName, pTask[i].ProcessName);\r
                                GetAppTitle(appTitle, szWindowName);\r
                        }\r
                        break;\r
diff --git a/xkeymacsdll/AppName.cpp b/xkeymacsdll/AppName.cpp
new file mode 100644 (file)
index 0000000..cd15f82
--- /dev/null
@@ -0,0 +1,174 @@
+#include "AppName.h"\r
+#include "Utils.h"\r
+#include <Imm.h>\r
+\r
+#pragma data_seg(".xkmcs")\r
+TCHAR AppName::m_FallbackIMEName[MAX_PATH] = _T("");\r
+#pragma data_seg()\r
+TCHAR AppName::m_AppName[MAX_PATH] = _T("");\r
+TCHAR AppName::m_IMEName[MAX_PATH] = _T("");\r
+bool AppName::m_Inited = false;\r
+bool AppName::m_IMEState = false;\r
+\r
+void AppName::Init()\r
+{\r
+       if (m_Inited)\r
+               return;\r
+       if (m_FallbackIMEName[0] == _T('\0')) {\r
+               // preserve the IME file name of the current TIF if it works as an Imm32 IME.\r
+               HKL hKL = GetKeyboardLayout(0);\r
+               if (!ImmIsIME(hKL) || !ImmGetIMEFileName(hKL, m_FallbackIMEName, MAX_PATH))\r
+                       _tcscpy_s(m_FallbackIMEName, _T("IME"));\r
+       }\r
+       TCHAR path[MAX_PATH];\r
+       GetModuleFileName(NULL, path, MAX_PATH);\r
+       CString s(path);\r
+       s.Delete(0, s.ReverseFind(_T('\\')) + 1);\r
+       _tcscpy_s(m_AppName, s);\r
+       TCHAR text[WINDOW_TEXT_LENGTH];\r
+       GetWindowText(GetForegroundWindow(), text, sizeof(text));\r
+       CorrectAppName(text, m_AppName);\r
+}\r
+\r
+LPCTSTR AppName::GetAppName()\r
+{\r
+       return m_IMEState ? m_IMEName : m_AppName;\r
+}\r
+\r
+void AppName::SetIMEState(bool on)\r
+{\r
+       m_IMEState = on;\r
+       if (!on)\r
+               return;\r
+       HKL hKL = GetKeyboardLayout(0);\r
+       if (ImmIsIME(hKL)) {\r
+               if (!ImmGetIMEFileName(hKL, m_IMEName, sizeof(m_IMEName)))\r
+                       _tcscpy_s(m_IMEName, _T("IME")); // TIP on TSF\r
+               return;\r
+       }\r
+       // ImmIsIME returns false if you use TSF aware applications with a TIF (aka IME).\r
+       // The following take the preserved IME file name of it.\r
+       _tcscpy_s(m_IMEName, m_FallbackIMEName);\r
+}\r
+\r
+// The code starting here is derived from work by co <cogood\81\97gmail.com>.\r
+void AppName::CorrectAppName(TCHAR (&text)[WINDOW_TEXT_LENGTH], TCHAR (&appName)[MAX_PATH])\r
+{\r
+       CString s(text);\r
+       if (IsConsole(appName)) {\r
+               RemovePrefixes(s);\r
+               int prev, sep;\r
+               for (prev = -1, sep = 0; (sep = s.Find(_T(" - "), sep)) >= 0; prev = sep, sep += 3)\r
+                       ;\r
+               if (prev >= 0) {\r
+                       s.Delete(0, prev + 3);\r
+                       ConsoleAppName(s, appName);\r
+                       _tcscpy_s(text, s);\r
+                       return;\r
+               }\r
+               if (IsCmdExe(s)) {\r
+                       _tcscpy_s(appName, "cmd.exe");\r
+                       _tcscpy_s(text, s);\r
+                       return;\r
+               }\r
+               if (s.Find(_T("Cygwin Bash Shell")) == 0 ||\r
+                               s[0] == _T('~') || s[0] == _T('/')) {\r
+                       _tcscpy_s(appName, _T("bash.exe"));\r
+                       _tcscpy_s(text, _T("Cygwin Bash Shell"));\r
+               } else if (s.Find(_T("MKS Korn Shell")) == 0 || s.Find(_T("cat")) == 0) {\r
+                       _tcscpy_s(appName, _T("sh.exe"));\r
+               } else if (s.Find(_T(":/"), 1) == 1 || s.Find(_T(":\\"), 1) == 1) {\r
+                       _tcscpy_s(appName, _T("csh.exe"));\r
+                       _tcscpy_s(text, "C Shell");\r
+               } else {\r
+                       ConsoleAppName(s, appName);\r
+                       _tcscpy_s(text, s);\r
+               }\r
+       } else if (!_tcsicmp(appName, _T("javaw.exe"))) {\r
+               if (s.Find(_T(" - Eclipse Platform")) || s == _T("Find/Replace"))\r
+                       _tcscpy_s(appName, "eclipse.exe");\r
+               else if (s.Find(_T("BlueJ")))\r
+                       _tcscpy_s(appName, "bluej.exe");\r
+               else if (s.Find(_T("JUDE")))\r
+                       _tcscpy_s(appName, "jude.exe");\r
+       }\r
+}\r
+\r
+bool AppName::IsConsole()\r
+{\r
+       return IsConsole(m_AppName);\r
+}\r
+\r
+bool AppName::IsConsole(LPCTSTR appName)\r
+{\r
+       LPCTSTR names[] = {\r
+               "conhost.exe",\r
+               "conime.exe",\r
+               "csh.exe",\r
+               "cmd.exe",\r
+               "bash.exe",\r
+               "ftp.exe",\r
+               "sh.exe",\r
+               "telnet.exe",\r
+       };\r
+       if (!appName[0])\r
+               return true;\r
+       for (int i = 0; i < _countof(names); ++i)\r
+               if (!_tcsicmp(appName, names[i]))\r
+                       return true;\r
+       return false;\r
+}\r
+\r
+bool AppName::IsCmdExe(const CString& text)\r
+{\r
+       LPCTSTR prompts[] = {\r
+               _T("command prompt"),\r
+               _T("\83R\83}\83\93\83\83v\83\8d\83\93\83v\83g"),\r
+               _T("system32\\cmd.exe"),\r
+               _T("syswow64\\cmd.exe")\r
+       };\r
+       for (int i = 0; i < _countof(prompts); ++i)\r
+               if (text.Right(_tcslen(prompts[i])).CompareNoCase(prompts[i]) == 0)\r
+                       return true;\r
+       return false;\r
+}\r
+\r
+void AppName::ConsoleAppName(CString& text, TCHAR (&appName)[MAX_PATH])\r
+{\r
+       int endQuote = text.Find(_T('"'), 1);\r
+       int space = text.Find(_T(' '), 1);\r
+       if (text[0] == _T('"') && endQuote > 0)\r
+               text = text.Mid(1, endQuote - 1); // A string surrounded by " is a command name.\r
+       else if (space >= 0)\r
+               text = text.Left(space + 1); // The first token is a command name.\r
+       int backSlash = text.ReverseFind(_T('\\')); // remove its directory.\r
+       if (backSlash >= 0)\r
+               text.Delete(0, backSlash + 1);\r
+       _tcsncpy_s(appName,\r
+               text.Right(4).CompareNoCase(_T(".exe")) == 0\r
+               ? text : text + _T(".exe"), _TRUNCATE);\r
+}\r
+\r
+void AppName::RemovePrefixes(CString& text)\r
+{\r
+       LPCTSTR prefixes[] = {\r
+               _T("\94Í\88Í\8ew\92è "), // via the edit menu\r
+               _T("\83X\83N\83\8d\81[\83\8b "), // via the edit menu\r
+               _T("\91I\91ð "), // via QuickEdit\r
+               _T("\8aÇ\97\9d\8eÒ: "), // remove it last\r
+               _T("Mark "),\r
+               _T("Scroll "),\r
+               _T("Select "),\r
+               _T("Administrator: "),\r
+       };\r
+       for (int i = 0; i < _countof(prefixes); ++i)\r
+               if (text.Find(prefixes[i]) == 0)\r
+                       text.Delete(0, static_cast<int>(_tcslen(prefixes[i])));\r
+}\r
+// The derived code ends here.\r
+\r
+bool AppName::Match(LPCTSTR name)\r
+{\r
+       LPCTSTR names[1] = { name };\r
+       return Match(names);\r
+}\r
diff --git a/xkeymacsdll/AppName.h b/xkeymacsdll/AppName.h
new file mode 100644 (file)
index 0000000..3f9c6e9
--- /dev/null
@@ -0,0 +1,31 @@
+#pragma once\r
+\r
+#include "defs.h"\r
+\r
+class AFX_EXT_CLASS AppName\r
+{\r
+public:\r
+       static void Init();\r
+       static LPCTSTR GetAppName();\r
+       static void SetIMEState(bool on);\r
+       static void CorrectAppName(TCHAR (&text)[WINDOW_TEXT_LENGTH], TCHAR (&appName)[MAX_PATH]);\r
+       static bool IsConsole();\r
+       static bool Match(LPCTSTR name);\r
+       template<size_t size> static bool Match(LPCTSTR (&names)[size])\r
+       {\r
+               for (int i = 0; i < size; ++i)\r
+                       if (!_tcsicmp(m_AppName, names[i]))\r
+                               return true;\r
+               return false;\r
+       }\r
+private:\r
+       static TCHAR m_AppName[MAX_PATH];\r
+       static TCHAR m_IMEName[MAX_PATH];\r
+       static TCHAR m_FallbackIMEName[MAX_PATH];\r
+       static bool m_Inited;\r
+       static bool m_IMEState;\r
+       static void ConsoleAppName(CString& text, TCHAR (&appName)[MAX_PATH]);\r
+       static void RemovePrefixes(CString& text);\r
+       static bool IsCmdExe(const CString& text);\r
+       static bool IsConsole(LPCTSTR appName);\r
+};\r
index 9914e93..ba11f47 100644 (file)
@@ -1005,7 +1005,7 @@ int CCommands::SaveBuffersKillEmacs()
                }\r
        }\r
 \r
-       if (CUtils::IsConsole()) {\r
+       if (AppName::IsConsole()) {\r
                SystemMenu(CMD_CLOSE);\r
        } else if (CUtils::IsExplorer()) {\r
                ReleaseKey(VK_CONTROL);\r
@@ -1023,7 +1023,7 @@ int CCommands::SaveBuffersKillEmacs()
 int CCommands::IconifyOrDeiconifyFrame()\r
 {\r
        ClearNumericArgument();\r
-       if (CUtils::IsConsole()) {\r
+       if (AppName::IsConsole()) {\r
                SystemMenu(CMD_MINIMIZE);\r
        } else {\r
                AdKduAu(VK_SPACE, 'N');\r
index 1c1c61b..2d628b6 100644 (file)
@@ -6,10 +6,11 @@
 #include "defs.h"\r
 #include "../xkeymacs/resource.h"\r
 #include <Imm.h>\r
-#pragma data_seg(".xkmcs")\r
-TCHAR CUtils::m_szApplicationName[MAX_PATH] = {'\0'};\r
-TCHAR CUtils::m_szIMEName[MAX_PATH] = _T("IME");       // IDS_IME_FILE_NAME\r
-#pragma data_seg()\r
+\r
+bool CUtils::IsConsole()\r
+{\r
+       return AppName::IsConsole();\r
+}\r
 \r
 BOOL CUtils::GetFindDialogTitle(CString *szDialogTitle)\r
 {\r
@@ -50,344 +51,164 @@ BOOL CUtils::IsFindDialog()
 \r
 BOOL CUtils::IsXkeymacs()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("xkeymacs.exe")) || !_tcsicmp(m_szApplicationName, _T("xkeymacs64.exe"));\r
+       LPCTSTR names[] = {\r
+               _T("xkeymacs.exe"),\r
+               _T("xkeymacs64.exe"),\r
+       };\r
+       return AppName::Match(names);\r
 }\r
 \r
 BOOL CUtils::IsChrome()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("chrome.exe"));\r
+       return AppName::Match(_T("chrome.exe"));\r
 }\r
 \r
 BOOL CUtils::IsAstecX()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("astecx.exe"));\r
+       return AppName::Match(_T("astecx.exe"));\r
 }\r
 \r
 BOOL CUtils::IsBecky()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("b2.exe"));\r
+       return AppName::Match(_T("b2.exe"));\r
 }\r
 \r
 BOOL CUtils::IsEmacs()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("Emacs.exe"));\r
+       return AppName::Match(_T("Emacs.exe"));\r
 }\r
 \r
 BOOL CUtils::IsExplorer()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("explorer.exe"));\r
+       return AppName::Match(_T("explorer.exe"));\r
 }\r
 \r
 BOOL CUtils::IsHidemaru()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("hidemaru.exe"));\r
+       return AppName::Match(_T("hidemaru.exe"));\r
 }\r
 \r
 BOOL CUtils::IsInternetExplorer()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("iexplore.exe"));\r
+       return AppName::Match(_T("iexplore.exe"));\r
 }\r
 \r
 BOOL CUtils::IsLotus123()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("123w.exe"));\r
+       return AppName::Match(_T("123w.exe"));\r
 }\r
 \r
 BOOL CUtils::IsLotusNotes()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("nlnotes.exe"));\r
+       return AppName::Match(_T("nlnotes.exe"));\r
 }\r
 \r
 BOOL CUtils::IsLotusWordPro()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("wordpro.exe"));\r
+       return AppName::Match(_T("wordpro.exe"));\r
 }\r
 \r
 BOOL CUtils::IsMeadow()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("Meadow.exe"))\r
-               || !_tcsicmp(m_szApplicationName, _T("Meadow95.exe"))\r
-               || !_tcsicmp(m_szApplicationName, _T("MeadowNT.exe"));\r
+       LPCTSTR names[] = {\r
+               _T("Meadow.exe"),\r
+               _T("Meadow95.exe"),\r
+               _T("MeadowNT.exe"),\r
+       };\r
+       return AppName::Match(names);\r
 }\r
 \r
 BOOL CUtils::IsMicrosoftFrontPage()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("frontpg.exe"));\r
+       return AppName::Match(_T("frontpg.exe"));\r
 }\r
 \r
 BOOL CUtils::IsMicrosoftWord()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("winword.exe"));\r
+       return AppName::Match(_T("winword.exe"));\r
 }\r
 \r
 BOOL CUtils::IsMozilla()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("mozilla.exe"))\r
-               || !_tcsicmp(m_szApplicationName, _T("firefox.exe"));\r
+       LPCTSTR names[] = {\r
+               _T("mozilla.exe"),\r
+               _T("firefox.exe"),\r
+       };\r
+       return AppName::Match(names);\r
 }\r
 \r
 BOOL CUtils::IsMuleForWin32()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("mule.exe"))\r
-               || !_tcsicmp(m_szApplicationName, _T("mulent.exe"))\r
-               || !_tcsicmp(m_szApplicationName, _T("mulecd.exe"));\r
+       LPCTSTR names[] = {\r
+               _T("mule.exe"),\r
+               _T("mulent.exe"),\r
+               _T("mulecd.exe"),\r
+       };\r
+       return AppName::Match(names);\r
 }\r
 \r
 BOOL CUtils::IsNetscape()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("netscp6.exe"))\r
-               || !_tcsicmp(m_szApplicationName, _T("netscp.exe"));\r
+       LPCTSTR names[] = {\r
+               _T("netscp6.exe"),\r
+               _T("netscp.exe"),\r
+       };\r
+       return AppName::Match(names);\r
 }\r
 \r
 BOOL CUtils::IsNotepad()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("notepad.exe"));\r
+       return AppName::Match(_T("notepad.exe"));\r
 }\r
 \r
 BOOL CUtils::IsNotepadPP()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("notepad++.exe"));\r
+       return AppName::Match(_T("notepad++.exe"));\r
 }\r
 \r
 BOOL CUtils::IsOpera()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("opera.exe"));\r
+       return AppName::Match(_T("opera.exe"));\r
 }\r
 \r
 BOOL CUtils::IsOutlook()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("outlook.exe"));\r
+       return AppName::Match(_T("outlook.exe"));\r
 }\r
 \r
 BOOL CUtils::IsOutlookExpress()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("msimn.exe"));\r
+       return AppName::Match(_T("msimn.exe"));\r
 }\r
 \r
 BOOL CUtils::IsSakuraEditor()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("sakura.exe"));\r
+       return AppName::Match(_T("sakura.exe"));\r
 }\r
 \r
 BOOL CUtils::IsTeraTermPro()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("ttermpro.exe"));\r
+       return AppName::Match(_T("ttermpro.exe"));\r
 }\r
 \r
 BOOL CUtils::IsVisualCpp()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("msdev.exe"));\r
+       return AppName::Match(_T("msdev.exe"));\r
 }\r
 \r
 BOOL CUtils::IsWordpad()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("wordpad.exe"));\r
+       return AppName::Match(_T("wordpad.exe"));\r
 }\r
 \r
 BOOL CUtils::IsXWin()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("XWin.exe"));\r
+       return AppName::Match(_T("XWin.exe"));\r
 }\r
 \r
 BOOL CUtils::IsXyzzy()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("xyzzy.exe"));\r
-}\r
-\r
-LPCTSTR const CUtils::GetApplicationName()\r
-{\r
-       return m_szApplicationName;\r
-}\r
-\r
-void CUtils::FairConsoleApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText)\r
-{\r
-       if (IsFindDialog()) {\r
-               return;\r
-       }\r
-\r
-       if (*szWindowText == '"' && _tcschr(szWindowText+1, _T('"'))) {         // "foo bar" -> foo bar\r
-               int len = _tcschr(szWindowText+1, _T('"')) - szWindowText - 1;  // length of "foo bar"\r
-               memmove(szWindowText, szWindowText + 1, len);\r
-               memset(szWindowText + len, 0, WINDOW_TEXT_LENGTH - len);\r
-       } else if (_tcschr(szWindowText, _T(' '))) {    // foo bar -> foo\r
-               LPTSTR p = _tcschr(szWindowText, _T(' '));\r
-               memset(p, 0, WINDOW_TEXT_LENGTH - (p - szWindowText));\r
-       }\r
-\r
-       memset(szApplicationName, 0, MAX_PATH);\r
-       _stprintf_s(szApplicationName, MAX_PATH, _T("%s"), szWindowText);\r
-\r
-       static LPCTSTR const szExe = _T(".exe");\r
-       if (_tcsnicmp(szApplicationName + _tcslen(szApplicationName) - _tcslen(szExe), szExe, _tcslen(szExe))) {\r
-               _tcscat_s(szApplicationName, MAX_PATH, szExe);\r
-       }\r
-}\r
-\r
-// Set real application name in the szApplicationName.\r
-void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText)\r
-{\r
-       if (IsConsole(szApplicationName)) {\r
-               int i = 0;\r
-               static LPCTSTR const szPromptName[] = {_T("Command Prompt"), _T("Mark Command Prompt"), _T("Select Command Prompt"), _T("MS-DOS Prompt"),\r
-                                                                                          _T("Visual Studio .NET Command Prompt"), _T("Visual Studio .NET 2003 Command Prompt"),\r
-                                                                                          _T("\83R\83}\83\93\83\83v\83\8d\83\93\83v\83g"), _T("\94Í\88Í\8ew\92è \83R\83}\83\93\83\83v\83\8d\83\93\83v\83g"), _T("\91I\91ð \83R\83}\83\93\83\83v\83\8d\83\93\83v\83g"), _T("MS-DOS \83v\83\8d\83\93\83v\83g"),\r
-                                                                                          _T("Visual Studio .NET \83R\83}\83\93\83\83v\83\8d\83\93\83v\83g"), _T("Visual Studio .NET 2003 \83R\83}\83\93\83\83v\83\8d\83\93\83v\83g")};\r
-               static LPCTSTR const szPromptPath[] = {_T("system32\\cmd.exe")};        // WindowText of Command Prompt is sometimes this style. But MS-DOS Prompt's is always MS-DOS Prompt.\r
-               static LPCTSTR const szSeparator = _T(" - ");\r
-\r
-               for (i = 0; i < sizeof(szPromptName) / sizeof(szPromptName[0]); ++i) {\r
-                       if (!_tcsicmp(szWindowText, szPromptName[i])) { // "Command Prompt"\r
-                               return;\r
-                       }\r
-\r
-                       TCHAR sz[WINDOW_TEXT_LENGTH] = {'\0'};\r
-                       _stprintf_s(sz, _T("%s%s"), szPromptName[i], szSeparator);\r
-\r
-                       if (!_tcsnicmp(szWindowText, sz, _tcslen(sz))) {        // "Command Promp - foo"\r
-                               _tcscpy_s(szWindowText, WINDOW_TEXT_LENGTH, szWindowText + _tcslen(sz));\r
-                               FairConsoleApplicationName(szApplicationName, szWindowText);\r
-                               return;\r
-                       }\r
-               }\r
-\r
-               for (i = 0; i < sizeof(szPromptPath) / sizeof(szPromptPath[0]); ++i) {\r
-                       TCHAR lower[WINDOW_TEXT_LENGTH] = {'\0'};\r
-                       _tcscpy_s(lower, szWindowText);\r
-                       _tcslwr_s(lower);\r
-\r
-                       if (_tcsstr(lower, szPromptPath[i])) {\r
-                               TCHAR sz[WINDOW_TEXT_LENGTH] = {'\0'};\r
-                               _stprintf_s(sz, _T("%s%s"), szPromptPath[i], szSeparator);\r
-\r
-                               if (_tcsstr(lower, sz)) {                               // "X:\WINNT\system32\cmd.exe - foo"\r
-                                       _tcscpy_s(szWindowText, WINDOW_TEXT_LENGTH, _tcsstr(lower, sz) + _tcslen(sz));\r
-                                       FairConsoleApplicationName(szApplicationName, szWindowText);\r
-                                       return;\r
-                               } else {                                                                        // "X:\WINNT\system32\cmd.exe"\r
-                                       return;\r
-                               }\r
-                       }\r
-               }\r
-\r
-               LPTSTR newName = NULL, newText = NULL;\r
-               if (!_tcsicmp(szWindowText, _T("Cygwin Bash Shell"))\r
-                || (*szWindowText == _T('~'))\r
-                || (*szWindowText == _T('/'))) {                                               // Bash\r
-                       newName = _T("bash.exe");\r
-                       newText = _T("bash");\r
-               } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 8, _T(" - pdksh"))) {\r
-                       newName = _T("pdksh.exe");\r
-                       newText = _T("pdksh");\r
-               } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 7, _T(" - tcsh"))) {\r
-                       newName = _T("tcsh.exe");\r
-                       newText = _T("tcsh");\r
-               } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 6, _T(" - zsh"))) {\r
-                       newName = _T("zsh.exe");\r
-                       newText = _T("zsh");\r
-               } else if (!_tcsnicmp(szWindowText, _T("MKS Korn Shell"), 14)\r
-                               || !_tcsnicmp(szWindowText, _T("cat"), 3)) {\r
-                       newName = _T("sh.exe");\r
-                       newText = _T("MKS Korn Shell");\r
-               } else if (!_tcsnicmp(szWindowText + 1, _T(":/"), 2)\r
-                               || !_tcsnicmp(szWindowText + 1, _T(":\\"), 2)) {\r
-                       newName = _T("csh.exe");\r
-                       newText = _T("C Shell");\r
-               } else if (_tcsstr(szWindowText, _T(" - VIM"))) {\r
-                       newName = _T("vim.exe");\r
-                       newText = _T("VIM");\r
-               } else if (_tcsstr(szWindowText, _T(" - Poderosa"))) {\r
-                       newName = _T("Poderosa.exe");\r
-                       newText = _T("Poderosa");\r
-               } else {                                                                                        // unknown console application\r
-                       FairConsoleApplicationName(szApplicationName, szWindowText);\r
-               }\r
-               if (newName) {\r
-                       memset(szApplicationName, 0, MAX_PATH);\r
-                       _tcscpy_s(szApplicationName, MAX_PATH, newName);\r
-                       memset(szWindowText, 0, WINDOW_TEXT_LENGTH);\r
-                       _tcscpy_s(szWindowText, WINDOW_TEXT_LENGTH, newText);\r
-               }\r
-       } else if (IsJavaW(szApplicationName)) {\r
-               LPTSTR newName = NULL;\r
-               if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 19, _T(" - Eclipse Platform"))) {\r
-                       newName = _T("eclipse.exe");\r
-               } else if (!_tcsicmp(szWindowText, _T("BlueJ"))\r
-                           || !_tcsnicmp(szWindowText, _T("BlueJ: "), 7)) {\r
-                       newName = _T("bluej.exe");\r
-               } else if (!_tcsicmp(szWindowText, _T("JUDE"))\r
-                           || !_tcsnicmp(szWindowText, _T("JUDE - "), 7)) {\r
-                       newName = _T("jude.exe");\r
-               }\r
-               if (newName) {\r
-                       memset(szApplicationName, 0, MAX_PATH);\r
-                       _tcscpy_s(szApplicationName, MAX_PATH, newName);\r
-               }\r
-       }\r
-       return;\r
-}\r
-\r
-void CUtils::SetApplicationName(BOOL bImeComposition)\r
-{\r
-//     CUtils::Log(_T("SetApplicationName: start"));\r
-\r
-       memset(m_szApplicationName, 0, sizeof(m_szApplicationName));\r
-\r
-       if (_tcscmp(m_szIMEName, _T("IME")) == 0) {     // IDS_IME_FILE_NAME\r
-               HKL hKL = GetKeyboardLayout(0);\r
-               if (ImmIsIME(hKL)) {\r
-                       if (!ImmGetIMEFileName(hKL, m_szIMEName, sizeof(m_szIMEName))) {\r
-                               _tcsncpy_s(m_szIMEName, _T("IME"), _TRUNCATE);  // IDS_IME_FILE_NAME\r
-                       }\r
-//                     CUtils::Log(_T("SetApplicationName: m_szIMEName == %s"), m_szIMEName);\r
-               }\r
-       }\r
-\r
-       if (bImeComposition) {\r
-//             CUtils::Log(_T("SetApplicationName: bImeComposition"));\r
-\r
-               HKL hKL = GetKeyboardLayout(0);\r
-               if (ImmIsIME(hKL)) {\r
-                       if (!ImmGetIMEFileName(hKL, m_szApplicationName, sizeof(m_szApplicationName))) {\r
-                               _tcsncpy_s(m_szApplicationName, m_szIMEName, _TRUNCATE);\r
-                       }\r
-                       _tcsncpy_s(m_szIMEName, m_szApplicationName, sizeof(m_szIMEName));\r
-               } else {\r
-                       // ImmIsIME return 0 on Word2002, Excel2002, etc. with IME2002, so...\r
-                       // _tcsncpy(m_szApplicationName, _T("imjp81.ime"), sizeof(m_szApplicationName));\r
-                       _tcsncpy_s(m_szApplicationName, m_szIMEName, _TRUNCATE);\r
-               }\r
-       } else {\r
-//             CUtils::Log(_T("SetApplicationName: appication (%s)"), m_szApplicationName);\r
-\r
-               GetModuleFileName(NULL, m_szApplicationName, sizeof(m_szApplicationName));\r
-               CString szFn(m_szApplicationName);\r
-               szFn.Delete(0, szFn.ReverseFind(_T('\\')) + 1);\r
-               ZeroMemory(m_szApplicationName, sizeof(m_szApplicationName));\r
-               _tcscpy_s(m_szApplicationName, szFn);\r
-\r
-//             CUtils::Log(_T("SetApplicationName: appication [%s]"), m_szApplicationName);\r
-\r
-               if (IsConsole()) {\r
-//                     CUtils::Log(_T("SetApplicationName: console"));\r
-\r
-                       memset(m_szApplicationName, 0, sizeof(m_szApplicationName));\r
-                       _tcscpy_s(m_szApplicationName, _T("CMD.exe"));\r
-                       TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};\r
-                       GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));\r
-                       SetCorrectApplicationName(m_szApplicationName, szWindowText);\r
-               } else if (IsJavaW()) {\r
-                       TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};\r
-                       GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));\r
-                       SetCorrectApplicationName(m_szApplicationName, szWindowText);\r
-               }\r
-               if (!_tcsicmp(m_szApplicationName, _T("Cygwin.exe"))) {\r
-//                     CUtils::Log(_T("SetApplicationName: cygwin"));\r
-\r
-                       memset(m_szApplicationName, 0, sizeof(m_szApplicationName));\r
-                       _tcscpy_s(m_szApplicationName, _T("bash.exe"));\r
-               }\r
-//             CUtils::Log(_T("name: %s"), m_szApplicationName);\r
-       }\r
+       return AppName::Match(_T("xyzzy.exe"));\r
 }\r
 \r
 BOOL CUtils::OpenClipboard()\r
@@ -472,106 +293,85 @@ BOOL CUtils::IsDefaultIgnoreApplication()
 \r
 BOOL CUtils::IsDWFM()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("dwfm.exe"));\r
+       return AppName::Match(_T("dwfm.exe"));\r
 }\r
 \r
 BOOL CUtils::IsK2Editor()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("K2Editor.exe"));\r
+       return AppName::Match(_T("K2Editor.exe"));\r
 }\r
 \r
 BOOL CUtils::IsEggExplorer()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("EggExp.exe"));\r
+       return AppName::Match(_T("EggExp.exe"));\r
 }\r
 \r
 BOOL CUtils::IsDirector()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("Director.exe"));\r
+       return AppName::Match(_T("Director.exe"));\r
 }\r
 \r
 BOOL CUtils::IsExcel()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("Excel.exe"));\r
+       return AppName::Match(_T("Excel.exe"));\r
 }\r
 \r
 BOOL CUtils::IsFireworks()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("Fireworks 4.exe"))\r
-               || !_tcsicmp(m_szApplicationName, _T("Fireworks.exe"));\r
+       LPCTSTR names[] = {\r
+               _T("Fireworks 4.exe"),\r
+               _T("Fireworks.exe"),\r
+       };\r
+       return AppName::Match(names);\r
 }\r
 \r
 BOOL CUtils::IsDreamweaver()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("Dreamweaver.exe"));\r
+       return AppName::Match(_T("Dreamweaver.exe"));\r
 }\r
 \r
 BOOL CUtils::IsFlash()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("Flash.exe"));\r
+       return AppName::Match(_T("Flash.exe"));\r
 }\r
 \r
 BOOL CUtils::IsPhotoshop()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("Photoshp.exe"));\r
+       return AppName::Match(_T("Photoshp.exe"));\r
 }\r
 \r
 BOOL CUtils::IsIllustrator()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("Illustrator.exe"));\r
+       return AppName::Match(_T("Illustrator.exe"));\r
 }\r
 \r
 BOOL CUtils::IsMicrosoftPowerPoint()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("PowerPnt.exe"));\r
+       return AppName::Match(_T("PowerPnt.exe"));\r
 }\r
 \r
 BOOL CUtils::IsReget()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("Regetdx.exe"))\r
-               || !_tcsicmp(m_szApplicationName, _T("Regetjr.exe"));\r
+       LPCTSTR names[] = {\r
+               _T("Regetdx.exe"),\r
+               _T("Regetjr.exe"),\r
+       };\r
+       return AppName::Match(names);\r
 }\r
 \r
 BOOL CUtils::IsPaint()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("mspaint.exe"));\r
-}\r
-\r
-BOOL CUtils::IsConsole()\r
-{\r
-//     Log(_T("_%s_"), m_szApplicationName);\r
-       return !m_szApplicationName[0]\r
-               || !_tcsicmp(m_szApplicationName, _T("xkeymacs.exe"))\r
-               || !_tcsicmp(m_szApplicationName, _T("conhost.exe"))\r
-               || !_tcsicmp(m_szApplicationName, _T("conime.exe"))\r
-               || !_tcsicmp(m_szApplicationName, _T("csh.exe"))\r
-               || !_tcsicmp(m_szApplicationName, _T("WINOA386.MOD"))\r
-               || !_tcsicmp(m_szApplicationName, _T("CMD.exe"))\r
-               || !_tcsicmp(m_szApplicationName, _T("bash.exe"))\r
-               || !_tcsicmp(m_szApplicationName, _T("ftp.exe"))\r
-               || !_tcsicmp(m_szApplicationName, _T("sh.exe"))\r
-               || !_tcsicmp(m_szApplicationName, _T("telnet.exe"));\r
-}\r
-\r
-BOOL CUtils::IsConsole(LPCTSTR szApplicationName)\r
-{\r
-       return !_tcsicmp(szApplicationName, _T("WINOA386.MOD"))\r
-               || !_tcsicmp(szApplicationName, _T("CMD.exe"));\r
-}\r
-\r
-BOOL CUtils::IsJavaW(LPCTSTR szApplicationName)\r
-{\r
-       return !_tcsicmp(szApplicationName, _T("javaw.exe"));\r
+       return AppName::Match(_T("mspaint.exe"));\r
 }\r
 \r
 BOOL CUtils::IsSleipnir()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("Sleipnir.exe"));\r
+       return AppName::Match(_T("Sleipnir.exe"));\r
 }\r
 \r
 BOOL CUtils::IsBash()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("bash.exe"));\r
+       return AppName::Match(_T("bash.exe"));\r
 }\r
 \r
 static void invalid_parameter_handler(const wchar_t*, const wchar_t*, const wchar_t*, unsigned int, uintptr_t)\r
@@ -599,20 +399,21 @@ void CUtils::Log(LPCTSTR fmt, ...)
 #endif\r
        } else\r
                _tcscpy_s(path, _T("c:\\xkeylog.txt"));\r
+\r
        FILE *fp;\r
        _tfopen_s(&fp, path, _T("a"));\r
-       _ftprintf(fp, _T("%8d: %s\t%s\n"), n++, m_szApplicationName, log);\r
+       _ftprintf(fp, _T("%8d: %s\t%s\n"), n++, AppName::GetAppName(), log);\r
        fclose(fp);\r
 }\r
 \r
 BOOL CUtils::IsSh()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("sh.exe"));\r
+       return AppName::Match(_T("sh.exe"));\r
 }\r
 \r
 BOOL CUtils::IsCsh()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("csh.exe"));\r
+       return AppName::Match(_T("csh.exe"));\r
 }\r
 \r
 BOOL CUtils::IsVisualStudio()\r
@@ -626,17 +427,17 @@ BOOL CUtils::IsVisualStudio()
 \r
 BOOL CUtils::IsAccess()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("MSACCESS.EXE"));\r
+       return AppName::Match(_T("MSACCESS.EXE"));\r
 }\r
 \r
 BOOL CUtils::IsProject()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("WINPROJ.EXE"));\r
+       return AppName::Match(_T("WINPROJ.EXE"));\r
 }\r
 \r
 BOOL CUtils::IsVisualBasic()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("VB6.EXE"));\r
+       return AppName::Match(_T("VB6.EXE"));\r
 }\r
 \r
 BOOL CUtils::IsVisualBasicEditor()\r
@@ -664,18 +465,7 @@ BOOL CUtils::IsVisualBasicEditor()
 \r
 BOOL CUtils::IsEclipse()\r
 {\r
-       if (!_tcsicmp(m_szApplicationName, _T("eclipse.exe")))\r
-               return TRUE;\r
-\r
-       TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};\r
-       GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));\r
-\r
-       LPCTSTR szEclipse = _T(" - Eclipse Platform");\r
-       LPCTSTR szFind = _T("Find/Replace");\r
-\r
-       return IsJavaW()\r
-               && (_tcslen(szEclipse) < _tcslen(szWindowText) && !_tcsicmp(szWindowText + _tcslen(szWindowText) - _tcslen(szEclipse), szEclipse)\r
-                || _tcslen(szFind) == _tcslen(szWindowText) && !_tcsicmp(szWindowText, szFind));\r
+       return AppName::Match(_T("eclipse.exe"));\r
 }\r
 \r
 BOOL CUtils::IsDialog()\r
@@ -689,32 +479,32 @@ BOOL CUtils::IsDialog()
 \r
 BOOL CUtils::IsEudora()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("Eudora.exe"));\r
+       return AppName::Match(_T("Eudora.exe"));\r
 }\r
 \r
 BOOL CUtils::IsCodeWarrior()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("IDE.exe"));\r
+       return AppName::Match(_T("IDE.exe"));\r
 }\r
 \r
 BOOL CUtils::IseMemoPad()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("eMemoPad.exe"));\r
+       return AppName::Match(_T("eMemoPad.exe"));\r
 }\r
 \r
 BOOL CUtils::IsStoryEditor()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("STRYEDIT.EXE"));\r
+       return AppName::Match(_T("STRYEDIT.EXE"));\r
 }\r
 \r
 BOOL CUtils::IsNami2000()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("Nami2000.exe"));\r
+       return AppName::Match(_T("Nami2000.exe"));\r
 }\r
 \r
 BOOL CUtils::IsCorelDRAW()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("CorelDrw.exe"));\r
+       return AppName::Match(_T("CorelDrw.exe"));\r
 }\r
 \r
 // If Clipboard data is empty, return true.\r
@@ -743,107 +533,111 @@ BOOL CUtils::IsTOForEOF()
 \r
 BOOL CUtils::IsHusen()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("husen.exe"));\r
+       return AppName::Match(_T("husen.exe"));\r
 }\r
 \r
 BOOL CUtils::IsAdobeReader()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("AcroRd32.exe"));\r
+       return AppName::Match(_T("AcroRd32.exe"));\r
 }\r
 \r
 BOOL CUtils::IsOpenOffice()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("soffice.exe"))\r
-               || !_tcsicmp(m_szApplicationName, _T("soffice.bin"));\r
+       LPCTSTR names[] = {\r
+               _T("soffice.exe"),\r
+               _T("soffice.bin"),\r
+       };\r
+       return AppName::Match(names);\r
 }\r
 \r
 BOOL CUtils::IsTuruKameMail()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("TuruKame.exe"));\r
+       return AppName::Match(_T("TuruKame.exe"));\r
 }\r
 \r
 BOOL CUtils::IsOedit()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("oedit.exe"));\r
+       return AppName::Match(_T("oedit.exe"));\r
 }\r
 \r
 BOOL CUtils::IsAutla()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("Autla.exe"));\r
+       return AppName::Match(_T("Autla.exe"));\r
 }\r
 \r
 BOOL CUtils::IsShuriken()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("JsvMail.exe"));\r
+       return AppName::Match(_T("JsvMail.exe"));\r
 }\r
 \r
 BOOL CUtils::IsEdLeaf()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("edleaf.exe"));\r
+       return AppName::Match(_T("edleaf.exe"));\r
 }\r
 \r
 BOOL CUtils::IsJmEditor()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("JmEdit.exe"))\r
-               || !_tcsicmp(m_szApplicationName, _T("JmEdit2.exe"));\r
+       LPCTSTR names[] = {\r
+               _T("JmEdit.exe"),\r
+               _T("JmEdit2.exe"),\r
+       };\r
+       return AppName::Match(names);\r
 }\r
 \r
 BOOL CUtils::IsDana()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("Dana.exe"));\r
+       return AppName::Match(_T("Dana.exe"));\r
 }\r
 \r
 BOOL CUtils::IsIPMessenger()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("ipmsg.exe"));\r
+       return AppName::Match(_T("ipmsg.exe"));\r
 }\r
 \r
 BOOL CUtils::IsezHTML()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("ezhtml.exe"));\r
+       return AppName::Match(_T("ezhtml.exe"));\r
 }\r
 \r
 BOOL CUtils::IsTcsh()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("tcsh.exe"));\r
+       return AppName::Match(_T("tcsh.exe"));\r
 }\r
 \r
 BOOL CUtils::IsZsh()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("zsh.exe"));\r
+       return AppName::Match(_T("zsh.exe"));\r
 }\r
 \r
 BOOL CUtils::IsPdksh()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("pdksh.exe"));\r
+       return AppName::Match(_T("pdksh.exe"));\r
 }\r
 \r
 BOOL CUtils::IsFirefox()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("firefox.exe"));\r
+       return AppName::Match(_T("firefox.exe"));\r
 }\r
 \r
 BOOL CUtils::IsPHPEditor()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("php_editor.exe"));\r
+       return AppName::Match(_T("php_editor.exe"));\r
 }\r
 \r
 BOOL CUtils::IsTeraPad()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("TeraPad.exe"));\r
+       return AppName::Match(_T("TeraPad.exe"));\r
 }\r
 \r
 BOOL CUtils::IsLispWorksPersonalEdition()\r
 {\r
-       CString szLispWorks(_T("lispworks-personal-"));\r
-       return !_tcsnicmp(m_szApplicationName, szLispWorks, szLispWorks.GetLength());\r
-\r
-//     return !_tcsicmp(m_szApplicationName, _T("lispworks-personal-4300.exe"));\r
+       TCHAR prefix[] = _T("lispworks-personal-");\r
+       return !_tcsnicmp(AppName::GetAppName(), prefix, _countof(prefix));\r
 }\r
 \r
 BOOL CUtils::IsBorlandCppBuilder()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("bcb.exe"));\r
+       return AppName::Match(_T("bcb.exe"));\r
 }\r
 \r
 BOOL CUtils::Run(CString szCommandLine, BOOL isWait)\r
@@ -870,27 +664,27 @@ BOOL CUtils::Run(CString szCommandLine, BOOL isWait)
 \r
 BOOL CUtils::IsJavaW()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("javaw.exe"));\r
+       return AppName::Match(_T("javaw.exe"));\r
 }\r
 \r
 BOOL CUtils::IsMSDN()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("hh.exe"));\r
+       return AppName::Match(_T("hh.exe"));\r
 }\r
 \r
 BOOL CUtils::IsVisualSlickEdit()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("vs.exe"));\r
+       return AppName::Match(_T("vs.exe"));\r
 }\r
 \r
 BOOL CUtils::IsOpenJane()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("Jane2ch.exe"));\r
+       return AppName::Match(_T("Jane2ch.exe"));\r
 }\r
 \r
 BOOL CUtils::IsThunderbird()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("thunderbird.exe"));\r
+       return AppName::Match(_T("thunderbird.exe"));\r
 }\r
 \r
 int CUtils::GetWindowTextType(CString strWindowText)\r
@@ -920,10 +714,11 @@ int CUtils::GetWindowTextType(CString strWindowText)
 \r
 BOOL CUtils::IsLunascape()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("Luna.exe"));\r
+       return AppName::Match(_T("Luna.exe"));\r
 }\r
 \r
 BOOL CUtils::IsAtok()\r
 {\r
-       return !_tcsnicmp(m_szApplicationName, _T("ATOK"), 4) && !_tcsnicmp(m_szApplicationName + _tcslen(m_szApplicationName) - 4, _T(".IME"), 4);\r
+       LPCTSTR name = AppName::GetAppName();\r
+       return !_tcsnicmp(name, _T("ATOK"), 4) && !_tcsicmp(name + _tcslen(name) - 4, _T(".IME"));\r
 }\r
index 7d66134..ef40e07 100644 (file)
@@ -9,9 +9,13 @@
 #pragma once\r
 #endif // _MSC_VER > 1000\r
 \r
+#include "AppName.h"\r
+\r
 class AFX_EXT_CLASS CUtils  \r
 {\r
 public:\r
+       static bool IsConsole();\r
+       static BOOL GetFindDialogTitle(CString *szDialogTitle);\r
        static BOOL IsAtok();\r
        static BOOL IsLunascape();\r
        static int GetWindowTextType(CString strWindowText);\r
@@ -61,10 +65,8 @@ public:
        static BOOL IsCsh();\r
        static BOOL IsSh();\r
        static BOOL IsBash();\r
-       static void SetCorrectApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText);\r
        static void Log(LPCTSTR fmt, ...);\r
        static BOOL IsSleipnir();\r
-       static BOOL IsConsole();\r
        static BOOL IsPaint();\r
        static BOOL IsReget();\r
        static BOOL IsMicrosoftPowerPoint();\r
@@ -83,8 +85,6 @@ public:
        static BOOL IsEmacs();\r
        static BOOL SetClipboardText(const CString& text);\r
        static BOOL GetClipboardText(CString& text);\r
-       static void SetApplicationName(BOOL bImeComposition);\r
-       static LPCTSTR const GetApplicationName();\r
        static BOOL IsXyzzy();\r
        static BOOL IsWordpad();\r
        static BOOL IsVisualCpp();\r
@@ -111,15 +111,8 @@ public:
        static BOOL IsAstecX();\r
        static BOOL IsXkeymacs();\r
        static BOOL IsChrome();\r
-       static BOOL GetFindDialogTitle(CString *szDialogTitle);\r
-\r
 private:\r
        static BOOL IsTOForEOF();\r
-       static void FairConsoleApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText);\r
-       static BOOL IsConsole(LPCTSTR szApplicationName);\r
-       static BOOL IsJavaW(LPCTSTR szApplicationName);\r
-       static TCHAR m_szIMEName[MAX_PATH];\r
-       static TCHAR m_szApplicationName[MAX_PATH];\r
 };\r
 \r
 #endif // !defined(AFX_UTILS_H__D64BCD3F_F2E2_41F7_AD58_0F32E2D46942__INCLUDED_)\r
index 523f669..ab4851b 100644 (file)
     </ResourceCompile>\r
   </ItemDefinitionGroup>\r
   <ItemGroup>\r
+    <ClCompile Include="AppName.cpp" />\r
     <ClCompile Include="ClipboardFormatSnap.cpp" />\r
     <ClCompile Include="ClipboardSnap.cpp" />\r
     <ClCompile Include="Commands.cpp" />\r
     <None Include="xkeymacsdll.def" />\r
   </ItemGroup>\r
   <ItemGroup>\r
+    <ClInclude Include="AppName.h" />\r
     <ClInclude Include="ClipboardFormatSnap.h" />\r
     <ClInclude Include="ClipboardSnap.h" />\r
     <ClInclude Include="Commands.h" />\r
index 2c85f6c..8327235 100644 (file)
@@ -39,6 +39,9 @@
     <ClCompile Include="KbdMacro.cpp">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="AppName.cpp">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <None Include="xkeymacsdll.def">\r
@@ -82,6 +85,9 @@
     <ClInclude Include="KbdMacro.h">\r
       <Filter>Header Files</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="AppName.h">\r
+      <Filter>Header Files</Filter>\r
+    </ClInclude>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ResourceCompile Include="xkeymacsdll.rc">\r
index d1ef4fd..ce7b7e1 100644 (file)
@@ -360,20 +360,20 @@ LRESULT CALLBACK CXkeymacsDll::CallWndProc(int nCode, WPARAM wParam, LPARAM lPar
                const CWPSTRUCT *cwps = reinterpret_cast<CWPSTRUCT *>(lParam);\r
                switch (cwps->message) {\r
                case WM_IME_STARTCOMPOSITION:\r
-                       InitKeyboardProc(TRUE);\r
+                       InitKeyboardProc(true);\r
                        break;\r
                case WM_IME_ENDCOMPOSITION:\r
-                       InitKeyboardProc(FALSE);\r
+                       InitKeyboardProc(false);\r
                        break;\r
                case WM_SETFOCUS:\r
                        if (cwps->hwnd == GetForegroundWindow()) {\r
-                               InitKeyboardProc(FALSE);\r
+                               InitKeyboardProc(false);\r
                                ShowKeyboardHookState();\r
                        }\r
                        break;\r
                case WM_NCACTIVATE:\r
                        if (cwps->wParam && cwps->hwnd == GetForegroundWindow()) {\r
-                               InitKeyboardProc(FALSE);\r
+                               InitKeyboardProc(false);\r
                                ShowKeyboardHookState();\r
                        }\r
                        break;\r
@@ -390,7 +390,7 @@ LRESULT CALLBACK CXkeymacsDll::CallWndRetProc(int nCode, WPARAM wParam, LPARAM l
                switch (cwprets->message) {\r
                case WM_SETTEXT:\r
                        if (cwprets->hwnd == GetForegroundWindow())\r
-                               InitKeyboardProc(FALSE);\r
+                               InitKeyboardProc(false);\r
                        break;\r
                case WM_SETCURSOR:\r
                        DoSetCursor();\r
@@ -407,10 +407,10 @@ LRESULT CALLBACK CXkeymacsDll::GetMsgProc(int nCode, WPARAM wParam, LPARAM lPara
                const MSG *msg = reinterpret_cast<MSG *>(lParam);\r
                switch (msg->message) {\r
                case WM_IME_STARTCOMPOSITION:\r
-                       InitKeyboardProc(TRUE);\r
+                       InitKeyboardProc(true);\r
                        break;\r
                case WM_IME_ENDCOMPOSITION:\r
-                       InitKeyboardProc(FALSE);\r
+                       InitKeyboardProc(false);\r
                        break;\r
                }\r
        }\r
@@ -424,20 +424,22 @@ LRESULT CALLBACK CXkeymacsDll::ShellProc(int nCode, WPARAM wParam, LPARAM lParam
                TCHAR className[CLASS_NAME_LENGTH];\r
                GetClassName(reinterpret_cast<HWND>(wParam), className, CLASS_NAME_LENGTH);\r
                if (!_tcsicmp(className, _T("ConsoleWindowClass"))) {\r
-                       InitKeyboardProc(FALSE);\r
+                       InitKeyboardProc(false);\r
                        ShowKeyboardHookState();\r
                }\r
        }\r
        return CallNextHookEx(NULL, nCode, wParam, lParam);\r
 }\r
 \r
-void CXkeymacsDll::InitKeyboardProc(BOOL bImeComposition)\r
+void CXkeymacsDll::InitKeyboardProc(bool imeState)\r
 {\r
-       CUtils::SetApplicationName(bImeComposition);\r
-       if (_tcsnicmp(m_Config.szSpecialApp[m_nAppID], CUtils::GetApplicationName(), 0xF) || !IsMatchWindowText(m_Config.szWindowText[m_nAppID])) {     // PROCESSENTRY32 has only 0xF bytes of Name\r
+       AppName::Init();\r
+       AppName::SetIMEState(imeState);\r
+\r
+       if (_tcsnicmp(m_Config.szSpecialApp[m_nAppID], AppName::GetAppName(), 0xF) || !IsMatchWindowText(m_Config.szWindowText[m_nAppID])) {    // PROCESSENTRY32 has only 0xF bytes of Name\r
                m_nAppID = -1;\r
                for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {\r
-                       if (_tcsnicmp(m_Config.szSpecialApp[nAppID], CUtils::GetApplicationName(), 0xF) || !IsMatchWindowText(m_Config.szWindowText[nAppID]))\r
+                       if (_tcsnicmp(m_Config.szSpecialApp[nAppID], AppName::GetAppName(), 0xF) || !IsMatchWindowText(m_Config.szWindowText[nAppID]))\r
                                continue;\r
                        if (m_nAppID < 0)\r
                                m_nAppID = nAppID;\r
@@ -455,7 +457,7 @@ void CXkeymacsDll::InitKeyboardProc(BOOL bImeComposition)
        }\r
        if (m_Config.nSettingStyle[m_nAppID] != SETTING_DISABLE &&\r
                        (_tcsicmp(m_Config.szSpecialApp[m_nAppID], _T("Default")) || !CUtils::IsDefaultIgnoreApplication()) &&\r
-                       !bImeComposition && CUtils::IsDialog() && m_Config.bUseDialogSetting[m_nAppID])\r
+                       !imeState && CUtils::IsDialog() && m_Config.bUseDialogSetting[m_nAppID])\r
                // Use Dialog Setting\r
                m_nAppID = GetAppID(_T("Dialog"), m_nAppID);\r
 \r
index 2e01eb4..0bea514 100644 (file)
@@ -66,7 +66,7 @@ private:
        static LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam);\r
        static LRESULT CALLBACK ShellProc(int nCode, WPARAM wParam, LPARAM lParam);\r
        static int m_nAppID;\r
-       static void InitKeyboardProc(BOOL bImeComposition);\r
+       static void InitKeyboardProc(bool imeState);\r
        static int GetAppID(LPCSTR szName, int fallback);\r
        static BOOL m_bRightShift;\r
        static BOOL m_bRightControl;\r