Move IsMatchWindowText from CXkeymacsDll to CUtils and rewrite it.
return AppName::IsConsole();\r
}\r
\r
+int CUtils::GetWindowTextType(const CString& text)\r
+{\r
+ int len = text.GetAllocLength();\r
+ if (len >= 3 && text[0] == _T('*') && text[len - 1] == _T('*'))\r
+ return IDS_WINDOW_TEXT_MATCH;\r
+ else if (len >= 2 && text[0] != _T('*') && text[len - 1] == _T('*'))\r
+ return IDS_WINDOW_TEXT_MATCH_FORWARD;\r
+ else if (len >= 2 && text[0] == _T('*') && text[len - 1] != _T('*'))\r
+ return IDS_WINDOW_TEXT_MATCH_BACKWARD;\r
+ else if (len > 0 && text[0] != _T('*') && text[len - 1] != _T('*'))\r
+ return IDS_WINDOW_TEXT_MATCH_FULL;\r
+ return IDS_WINDOW_TEXT_IGNORE;\r
+}\r
+\r
+bool CUtils::IsMatchWindowText(const CString& text)\r
+{\r
+ int len = text.GetLength();\r
+ TCHAR buf[WINDOW_TEXT_LENGTH];\r
+ GetWindowText(GetForegroundWindow(), buf, sizeof(buf));\r
+ CString current(buf);\r
+ switch (GetWindowTextType(text)) {\r
+ case IDS_WINDOW_TEXT_MATCH: // *foo*\r
+ return current.Find(text.Mid(1, len - 2)) >= 0;\r
+ case IDS_WINDOW_TEXT_MATCH_FORWARD: // foo*\r
+ return current.Left(len - 1) == text.Left(len - 1);\r
+ case IDS_WINDOW_TEXT_MATCH_BACKWARD: // *foo\r
+ return current.Right(len - 1) == text.Right(len - 1);\r
+ case IDS_WINDOW_TEXT_MATCH_FULL: // foo\r
+ return current == text;\r
+ }\r
+ return true;\r
+}\r
+\r
BOOL CUtils::GetFindDialogTitle(CString *szDialogTitle)\r
{\r
{\r
return AppName::Match(_T("thunderbird.exe"));\r
}\r
\r
-int CUtils::GetWindowTextType(CString strWindowText)\r
-{\r
- int nWindowTextType = IDS_WINDOW_TEXT_IGNORE;\r
-\r
- if (3 <= strWindowText.GetLength()\r
- && strWindowText.Find(_T('*')) == 0\r
- && strWindowText.ReverseFind(_T('*')) == strWindowText.GetLength() - 1) {\r
- nWindowTextType = IDS_WINDOW_TEXT_MATCH;\r
- } else if (2 <= strWindowText.GetLength()\r
- && strWindowText.Find(_T('*')) != 0\r
- && strWindowText.ReverseFind(_T('*')) == strWindowText.GetLength() - 1) {\r
- nWindowTextType = IDS_WINDOW_TEXT_MATCH_FORWARD;\r
- } else if (2 <= strWindowText.GetLength()\r
- && strWindowText.Find(_T('*')) == 0\r
- && strWindowText.ReverseFind(_T('*')) != strWindowText.GetLength() - 1) {\r
- nWindowTextType = IDS_WINDOW_TEXT_MATCH_BACKWARD;\r
- } else if (!strWindowText.IsEmpty()\r
- && strWindowText.Find(_T('*')) != 0\r
- && strWindowText.ReverseFind(_T('*')) != strWindowText.GetLength() - 1) {\r
- nWindowTextType = IDS_WINDOW_TEXT_MATCH_FULL;\r
- }\r
-\r
- return nWindowTextType;\r
-}\r
-\r
BOOL CUtils::IsLunascape()\r
{\r
return AppName::Match(_T("Luna.exe"));\r
{\r
public:\r
static bool IsConsole();\r
+ static int GetWindowTextType(const CString& text);\r
+ static bool IsMatchWindowText(const CString& text);\r
static BOOL GetFindDialogTitle(CString *szDialogTitle);\r
static BOOL IsAtok();\r
static BOOL IsLunascape();\r
- static int GetWindowTextType(CString strWindowText);\r
static BOOL IsThunderbird();\r
static BOOL IsOpenJane();\r
static BOOL IsVisualSlickEdit();\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
+ if (_tcsnicmp(m_Config.szSpecialApp[m_nAppID], AppName::GetAppName(), 0xF) || // PROCESSENTRY32 has only 0xF bytes of Name\r
+ !CUtils::IsMatchWindowText(m_Config.szWindowText[m_nAppID])) {\r
m_nAppID = -1;\r
for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {\r
- if (_tcsnicmp(m_Config.szSpecialApp[nAppID], AppName::GetAppName(), 0xF) || !IsMatchWindowText(m_Config.szWindowText[nAppID]))\r
+ if (_tcsnicmp(m_Config.szSpecialApp[nAppID], AppName::GetAppName(), 0xF) ||\r
+ !CUtils::IsMatchWindowText(m_Config.szWindowText[nAppID]))\r
continue;\r
if (m_nAppID < 0)\r
m_nAppID = nAppID;\r
}\r
}\r
\r
-BOOL CXkeymacsDll::IsMatchWindowText(CString szWindowText)\r
-{\r
- BOOL bIsMatchWindowText = TRUE;\r
-\r
- TCHAR szCurrentWindowText[WINDOW_TEXT_LENGTH] = {'\0'};\r
- GetWindowText(GetForegroundWindow(), szCurrentWindowText, sizeof(szCurrentWindowText));\r
-\r
- switch (CUtils::GetWindowTextType(szWindowText)) {\r
- case IDS_WINDOW_TEXT_MATCH: // *foo*\r
- szWindowText.Delete(0); // Delete first '*'\r
- szWindowText.Delete(szWindowText.GetLength() - 1); // Delete last '*'\r
- bIsMatchWindowText = 0 <= CString(szCurrentWindowText).Find(szWindowText);\r
- break;\r
- case IDS_WINDOW_TEXT_MATCH_FORWARD: // foo*\r
- szWindowText.Delete(szWindowText.GetLength() - 1); // Delete last '*'\r
- bIsMatchWindowText = 0 == CString(szCurrentWindowText).Find(szWindowText);\r
- break;\r
- case IDS_WINDOW_TEXT_MATCH_BACKWARD: // *foo\r
- szWindowText.Delete(0); // Delete first '*'\r
- bIsMatchWindowText = 0 <= CString(szCurrentWindowText).Find(szWindowText, CString(szCurrentWindowText).GetLength() - szWindowText.GetLength());\r
- break;\r
- case IDS_WINDOW_TEXT_MATCH_FULL: // foo\r
- bIsMatchWindowText = szWindowText == CString(szCurrentWindowText);\r
- break;\r
- case IDS_WINDOW_TEXT_IGNORE: // *\r
- bIsMatchWindowText = TRUE;\r
- break;\r
- }\r
-// CUtils::Log(_T("IsMatchWindowText: %d, _%s_, _%s_"), bIsMatchWindowText, szCurrentWindowText, szWindowText);\r
- return bIsMatchWindowText;\r
-}\r
-\r
void CXkeymacsDll::SetAccelerate(int nAccelerate)\r
{\r
m_nAccelerate = nAccelerate;\r
static KeyBind ParseKey(LPCTSTR& def);\r
static BOOL IsShift(TCHAR nAscii);\r
static BYTE a2v(TCHAR nAscii);\r
- static BOOL IsMatchWindowText(CString szWindowText);\r
static int m_nAccelerate;\r
static int m_nKeyboardSpeed;\r
static HCURSOR m_hCurrentCursor;\r