summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-06-16 11:15:15 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-06-16 11:15:15 +0000
commitb8498167933905e7346b6db21ce7a14da95384de (patch)
treec5f0e7115513865d640d2e70b5c4f71313c88ac8
parent948f7a9e116fdd5c3adadca3f20a8c252e0d2b6a (diff)
fix for chat window autocomplete
closes bug #172 git-svn-id: http://svn.miranda-ng.org/main/trunk@4976 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--plugins/Scriver/src/chat/window.cpp172
-rw-r--r--plugins/TabSRMM/src/chat/window.cpp187
2 files changed, 186 insertions, 173 deletions
diff --git a/plugins/Scriver/src/chat/window.cpp b/plugins/Scriver/src/chat/window.cpp
index 9e0d9cfd69..46dd792806 100644
--- a/plugins/Scriver/src/chat/window.cpp
+++ b/plugins/Scriver/src/chat/window.cpp
@@ -213,9 +213,98 @@ static void MessageDialogResize(HWND hwndDlg, SESSION_INFO *si, int w, int h) {
RedrawWindow(GetDlgItem(hwndDlg,IDC_CHAT_MESSAGE), NULL, NULL, RDW_INVALIDATE);
}
+static void TabAutoComplete(HWND hwnd, MESSAGESUBDATA *dat, SESSION_INFO *si)
+{
+ LRESULT lResult = (LRESULT)SendMessage(hwnd, EM_GETSEL, 0, 0);
+ int start = LOWORD(lResult), end = HIWORD(lResult);
+ SendMessage(hwnd, EM_SETSEL, end, end);
+
+ GETTEXTEX gt = {0};
+ gt.codepage = 1200;
+ int iLen = GetRichTextLength(hwnd, gt.codepage, TRUE);
+ if (iLen <= 0)
+ return;
+
+ bool isTopic = false, isRoom = false;
+ TCHAR *pszName = NULL;
+ TCHAR* pszText = (TCHAR *)mir_alloc(iLen + 100 * sizeof(TCHAR));
+ gt.cb = iLen + 99 * sizeof(TCHAR);
+ gt.flags = GT_DEFAULT;
+
+ SendMessage(hwnd, EM_GETTEXTEX, (WPARAM)&gt, (LPARAM)pszText);
+ if (start > 1 && pszText[start-1] == ' ' && pszText[start-2] == ':')
+ start -= 2;
+
+ if (dat->szSearchResult != NULL) {
+ int cbResult = (int)_tcslen(dat->szSearchResult);
+ if (start >= cbResult && !_tcsncicmp(dat->szSearchResult, pszText+start-cbResult, cbResult)) {
+ start -= cbResult;
+ goto LBL_SkipEnd;
+ }
+ }
+
+ while (start > 0 && pszText[start-1] != ' ' && pszText[start-1] != 13 && pszText[start-1] != VK_TAB)
+ start--;
+
+LBL_SkipEnd:
+ while (end < iLen && pszText[end] != ' ' && pszText[end] != 13 && pszText[end-1] != VK_TAB)
+ end++;
+
+ if (pszText[start] == '#')
+ isRoom = true;
+ else {
+ int topicStart = start;
+ while ( topicStart >0 && (pszText[topicStart-1] == ' ' || pszText[topicStart-1] == 13 || pszText[topicStart-1] == VK_TAB))
+ topicStart--;
+ if (topicStart > 5 && _tcsstr(&pszText[topicStart-6], _T("/topic")) == &pszText[topicStart-6])
+ isTopic = true;
+ }
+
+ if ( dat->szSearchQuery == NULL) {
+ dat->szSearchQuery = (TCHAR*)mir_alloc( sizeof(TCHAR)*(end-start+1));
+ lstrcpyn(dat->szSearchQuery, pszText+start, end-start+1);
+ dat->szSearchResult = mir_tstrdup(dat->szSearchQuery);
+ dat->lastSession = NULL;
+ }
+
+ if (isTopic)
+ pszName = si->ptszTopic;
+ else if (isRoom) {
+ dat->lastSession = SM_FindSessionAutoComplete(si->pszModule, si, dat->lastSession, dat->szSearchQuery, dat->szSearchResult);
+ if (dat->lastSession != NULL) {
+ pszName = dat->lastSession->ptszName;
+ }
+ }
+ else pszName = UM_FindUserAutoComplete(si->pUsers, dat->szSearchQuery, dat->szSearchResult);
+
+ mir_free(pszText);
+ replaceStrT(dat->szSearchResult, NULL);
+
+ if (pszName == NULL) {
+ if (end != start) {
+ SendMessage(hwnd, EM_SETSEL, start, end);
+ SendMessage(hwnd, EM_REPLACESEL, FALSE, (LPARAM)dat->szSearchQuery);
+ }
+ replaceStrT(dat->szSearchQuery, NULL);
+ }
+ else {
+ dat->szSearchResult = mir_tstrdup(pszName);
+ if (end != start) {
+ ptrT szReplace;
+ if (!isRoom && !isTopic && g_Settings.AddColonToAutoComplete && start == 0) {
+ szReplace = (TCHAR *)mir_alloc((_tcslen(pszName) + 4) * sizeof(TCHAR));
+ _tcscpy(szReplace, pszName);
+ _tcscat(szReplace, _T(": "));
+ pszName = szReplace;
+ }
+ SendMessage(hwnd, EM_SETSEL, start, end);
+ SendMessage(hwnd, EM_REPLACESEL, FALSE, (LPARAM)pszName);
+ }
+ }
+}
+
static LRESULT CALLBACK MessageSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- static int start;
BOOL isShift = GetKeyState(VK_SHIFT) & 0x8000;
BOOL isCtrl = GetKeyState(VK_CONTROL) & 0x8000;
BOOL isAlt = GetKeyState(VK_MENU) & 0x8000;
@@ -279,87 +368,8 @@ static LRESULT CALLBACK MessageSubclassProc(HWND hwnd, UINT msg, WPARAM wParam,
}
if (wParam == VK_TAB && !isCtrl && !isShift) { //tab-autocomplete
- int iLen, end, topicStart;
- BOOL isTopic = FALSE;
- BOOL isRoom = FALSE;
- TCHAR* pszText = NULL;
- GETTEXTEX gt = {0};
- LRESULT lResult = (LRESULT)SendMessage(hwnd, EM_GETSEL, 0, 0);
-
SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
- start = LOWORD(lResult);
- end = HIWORD(lResult);
- SendMessage(hwnd, EM_SETSEL, end, end);
-
- gt.codepage = 1200;
- iLen = GetRichTextLength(hwnd, gt.codepage, TRUE);
- if (iLen >0) {
- TCHAR *pszName = NULL;
- pszText = (TCHAR *)mir_alloc(iLen + 100 * sizeof(TCHAR));
- gt.cb = iLen + 99 * sizeof(TCHAR);
- gt.flags = GT_DEFAULT;
-
- SendMessage(hwnd, EM_GETTEXTEX, (WPARAM)&gt, (LPARAM)pszText);
- if (start > 1 && pszText[start-1] == ' ' && pszText[start-2] == ':') {
- start--;
- }
- while ( start >0 && pszText[start-1] != ' ' && pszText[start-1] != 13 && pszText[start-1] != VK_TAB)
- start--;
- while (end < iLen && pszText[end] != ' ' && pszText[end] != 13 && pszText[end-1] != VK_TAB)
- end ++;
- if (pszText[start] == '#') {
- isRoom = TRUE;
- } else {
- topicStart = start;
- while ( topicStart >0 && (pszText[topicStart-1] == ' ' || pszText[topicStart-1] == 13 || pszText[topicStart-1] == VK_TAB))
- topicStart--;
- if (topicStart > 5 && _tcsstr(&pszText[topicStart-6], _T("/topic")) == &pszText[topicStart-6]) {
- isTopic = TRUE;
- }
- }
- if ( dat->szSearchQuery == NULL) {
- dat->szSearchQuery = (TCHAR *)mir_alloc( sizeof(TCHAR)*( end-start+1 ));
- lstrcpyn( dat->szSearchQuery, pszText+start, end-start+1);
- dat->szSearchResult = mir_tstrdup(dat->szSearchQuery);
- dat->lastSession = NULL;
- }
- if (isTopic) {
- pszName = Parentsi->ptszTopic;
- } else if (isRoom) {
- dat->lastSession = SM_FindSessionAutoComplete(Parentsi->pszModule, Parentsi, dat->lastSession, dat->szSearchQuery, dat->szSearchResult);
- if (dat->lastSession != NULL) {
- pszName = dat->lastSession->ptszName;
- }
- } else {
- pszName = UM_FindUserAutoComplete(Parentsi->pUsers, dat->szSearchQuery, dat->szSearchResult);
- }
- mir_free(pszText);
- pszText = NULL;
- mir_free(dat->szSearchResult);
- dat->szSearchResult = NULL;
- if (pszName == NULL) {
- if (end !=start) {
- SendMessage(hwnd, EM_SETSEL, start, end);
- SendMessage(hwnd, EM_REPLACESEL, FALSE, (LPARAM)dat->szSearchQuery);
- }
- mir_free(dat->szSearchQuery);
- dat->szSearchQuery = NULL;
- } else {
- dat->szSearchResult = mir_tstrdup(pszName);
- if (end !=start) {
- if (!isRoom && !isTopic && g_Settings.AddColonToAutoComplete && start == 0) {
- pszText = (TCHAR *)mir_alloc((_tcslen(pszName) + 4) * sizeof(TCHAR));
- _tcscpy(pszText, pszName);
- _tcscat(pszText, _T(": "));
- pszName = pszText;
- }
- SendMessage(hwnd, EM_SETSEL, start, end);
- SendMessage(hwnd, EM_REPLACESEL, FALSE, (LPARAM)pszName);
- }
- mir_free(pszText);
- }
- }
-
+ TabAutoComplete(hwnd, dat, Parentsi);
SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE);
return 0;
diff --git a/plugins/TabSRMM/src/chat/window.cpp b/plugins/TabSRMM/src/chat/window.cpp
index 6320547b24..7148f0cf84 100644
--- a/plugins/TabSRMM/src/chat/window.cpp
+++ b/plugins/TabSRMM/src/chat/window.cpp
@@ -532,11 +532,101 @@ static int RoomWndResize(HWND hwndDlg, LPARAM lParam, UTILRESIZECONTROL *urc)
return RD_ANCHORX_LEFT | RD_ANCHORY_TOP;
}
-
/*
* subclassing for the message input control (a richedit text control)
*/
+static bool TabAutoComplete(HWND hwnd, MESSAGESUBDATA *dat, SESSION_INFO *si)
+{
+ LRESULT lResult = (LRESULT)SendMessage(hwnd, EM_GETSEL, 0, 0);
+ int start = LOWORD(lResult), end = HIWORD(lResult);
+ SendMessage(hwnd, EM_SETSEL, end, end);
+
+ GETTEXTEX gt = {0};
+ gt.codepage = 1200;
+ gt.flags = GTL_DEFAULT | GTL_PRECISE;
+ int iLen = SendMessage(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)&gt, 0);
+ if (iLen <= 0)
+ return false;
+
+ bool isTopic = false, isRoom = false;
+ TCHAR *pszName = NULL;
+ TCHAR *pszText = (TCHAR*)Utils::safeMirCalloc((iLen + 10) * sizeof(TCHAR));
+
+ gt.flags = GT_DEFAULT;
+ gt.cb = (iLen + 9) * sizeof(TCHAR);
+ SendMessage(hwnd, EM_GETTEXTEX, (WPARAM)&gt, (LPARAM)pszText);
+
+ if (start > 1 && pszText[start-1] == ' ' && pszText[start-2] == ':')
+ start -= 2;
+
+ if (dat->szSearchResult != NULL) {
+ int cbResult = (int)_tcslen(dat->szSearchResult);
+ if (start >= cbResult && !_tcsncicmp(dat->szSearchResult, pszText+start-cbResult, cbResult)) {
+ start -= cbResult;
+ goto LBL_SkipEnd;
+ }
+ }
+
+ while(start > 0 && pszText[start-1] != ' ' && pszText[start-1] != 13 && pszText[start-1] != VK_TAB)
+ start--;
+
+LBL_SkipEnd:
+ while (end < iLen && pszText[end] != ' ' && pszText[end] != 13 && pszText[end-1] != VK_TAB)
+ end++;
+
+ if (pszText[start] == '#')
+ isRoom = TRUE;
+ else {
+ int topicStart = start;
+ while (topicStart > 0 && (pszText[topicStart-1] == ' ' || pszText[topicStart-1] == 13 || pszText[topicStart-1] == VK_TAB))
+ topicStart--;
+ if (topicStart > 5 && _tcsstr(&pszText[topicStart-6], _T("/topic")) == &pszText[topicStart-6])
+ isTopic = TRUE;
+ }
+ if (dat->szSearchQuery == NULL) {
+ size_t len = (end - start) + 1;
+ dat->szSearchQuery = (TCHAR*)Utils::safeMirAlloc(sizeof(TCHAR) * len);
+ wcsncpy(dat->szSearchQuery, pszText + start, len);
+ dat->szSearchQuery[len - 1] = 0;
+ dat->szSearchResult = mir_tstrdup(dat->szSearchQuery);
+ dat->lastSession = NULL;
+ }
+ if (isTopic)
+ pszName = si->ptszTopic;
+ else if (isRoom) {
+ dat->lastSession = SM_FindSessionAutoComplete(si->pszModule, si, dat->lastSession, dat->szSearchQuery, dat->szSearchResult);
+ if (dat->lastSession != NULL)
+ pszName = dat->lastSession->ptszName;
+ }
+ else pszName = UM_FindUserAutoComplete(si->pUsers, dat->szSearchQuery, dat->szSearchResult);
+
+ replaceStrT(dat->szSearchResult, NULL);
+
+ if (pszName != NULL) {
+ dat->szSearchResult = mir_tstrdup(pszName);
+ if (end != start) {
+ ptrT szReplace;
+ if (!isRoom && !isTopic && g_Settings.AddColonToAutoComplete && start == 0) {
+ szReplace = (TCHAR*)Utils::safeMirAlloc((wcslen(pszName) + 4) * sizeof(TCHAR));
+ wcscpy(szReplace, pszName);
+ wcscat(szReplace, L": ");
+ pszName = szReplace;
+ }
+ SendMessage(hwnd, EM_SETSEL, start, end);
+ SendMessage(hwnd, EM_REPLACESEL, TRUE, (LPARAM)pszName);
+ }
+ return true;
+ }
+
+ if (end != start) {
+ SendMessage(hwnd, EM_SETSEL, start, end);
+ SendMessage(hwnd, EM_REPLACESEL, TRUE, (LPARAM)dat->szSearchQuery);
+ }
+ replaceStrT(dat->szSearchQuery, NULL);
+ return false;
+}
+
static LRESULT CALLBACK MessageSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HWND hwndParent = GetParent(hwnd);
@@ -775,7 +865,7 @@ static LRESULT CALLBACK MessageSubclassProc(HWND hwnd, UINT msg, WPARAM wParam,
case VK_PRIOR:
case VK_NEXT:
case VK_HOME:
- case VK_END: {
+ case VK_END:
WPARAM wp = 0;
if (wParam == VK_UP)
@@ -794,7 +884,6 @@ static LRESULT CALLBACK MessageSubclassProc(HWND hwnd, UINT msg, WPARAM wParam,
SendMessage(GetDlgItem(hwndParent, IDC_CHAT_LOG), WM_VSCROLL, wp, 0);
return 0;
- }
}
}
@@ -843,95 +932,8 @@ static LRESULT CALLBACK MessageSubclassProc(HWND hwnd, UINT msg, WPARAM wParam,
return TRUE;
}
if (wParam == VK_TAB && !isCtrl && !isShift) { //tab-autocomplete
- int iLen, end, topicStart;
- BOOL isTopic = FALSE;
- BOOL isRoom = FALSE;
- wchar_t* pszText = NULL;
- GETTEXTEX gt = {0};
- LRESULT lResult = (LRESULT)SendMessage(hwnd, EM_GETSEL, 0, 0);
- bool fCompleted = false;
-
SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
- start = LOWORD(lResult);
- end = HIWORD(lResult);
- SendMessage(hwnd, EM_SETSEL, end, end);
-
- gt.codepage = 1200;
- gt.flags = GTL_DEFAULT | GTL_PRECISE;
-
- iLen = SendMessage(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)&gt, 0);
- if (iLen > 0) {
- wchar_t* pszName = NULL;
- pszText = reinterpret_cast<wchar_t*>(Utils::safeMirCalloc((iLen + 10) * sizeof(wchar_t)));
- gt.flags = GT_DEFAULT;
- gt.cb = (iLen + 9) * sizeof(wchar_t);
-
- SendMessage(hwnd, EM_GETTEXTEX, (WPARAM)&gt, (LPARAM)pszText);
-
- if (start > 1 && pszText[start-1] == ' ' && pszText[start-2] == ':')
- start--;
-
- while( start > 0 && pszText[start-1] != ' ' && pszText[start-1] != 13 && pszText[start-1] != VK_TAB)
- start--;
-
- while (end < iLen && pszText[end] != ' ' && pszText[end] != 13 && pszText[end-1] != VK_TAB)
- end ++;
-
- if (pszText[start] == '#')
- isRoom = TRUE;
- else {
- topicStart = (int)start;
- while ( topicStart >0 && (pszText[topicStart-1] == ' ' || pszText[topicStart-1] == 13 || pszText[topicStart-1] == VK_TAB))
- topicStart--;
- if (topicStart > 5 && _tcsstr(&pszText[topicStart-6], _T("/topic")) == &pszText[topicStart-6])
- isTopic = TRUE;
- }
- if (dat->szSearchQuery == NULL) {
- size_t len = (end - start) + 1;
- dat->szSearchQuery = reinterpret_cast<wchar_t*>(Utils::safeMirAlloc(sizeof(wchar_t) * len));
- wcsncpy( dat->szSearchQuery, pszText + start, len);
- dat->szSearchQuery[len - 1] = 0;
- dat->szSearchResult = mir_tstrdup(dat->szSearchQuery);
- dat->lastSession = NULL;
- }
- if (isTopic) {
- pszName = Parentsi->ptszTopic;
- } else if (isRoom) {
- dat->lastSession = SM_FindSessionAutoComplete(Parentsi->pszModule, Parentsi, dat->lastSession, dat->szSearchQuery, dat->szSearchResult);
- if (dat->lastSession != NULL)
- pszName = dat->lastSession->ptszName;
- } else
- pszName = UM_FindUserAutoComplete(Parentsi->pUsers, dat->szSearchQuery, dat->szSearchResult);
-
- mir_free(pszText);
- pszText = NULL;
- mir_free(dat->szSearchResult);
- dat->szSearchResult = 0;
- if (pszName == 0) {
- if ((int)end != (int)start) {
- SendMessage(hwnd, EM_SETSEL, start, end);
- SendMessage(hwnd, EM_REPLACESEL, TRUE, (LPARAM)dat->szSearchQuery);
- }
- mir_free(dat->szSearchQuery);
- dat->szSearchQuery = NULL;
- } else {
- pszText = 0;
- dat->szSearchResult = mir_tstrdup(pszName);
- if ((int)end != (int)start) {
- if (!isRoom && !isTopic && g_Settings.AddColonToAutoComplete && start == 0) {
- pszText = reinterpret_cast<wchar_t*>(Utils::safeMirAlloc((wcslen(pszName) + 4) * sizeof(wchar_t)));
- wcscpy(pszText, pszName);
- wcscat(pszText, L": ");
- pszName = pszText;
- }
- SendMessage(hwnd, EM_SETSEL, start, end);
- SendMessage(hwnd, EM_REPLACESEL, TRUE, (LPARAM)pszName);
- }
- if (pszText)
- mir_free(pszText);
- fCompleted = true;
- }
- }
+ bool fCompleted = TabAutoComplete(hwnd, dat, Parentsi);
SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE);
if (!fCompleted && !PluginConfig.m_AllowTab) {
@@ -941,7 +943,8 @@ static LRESULT CALLBACK MessageSubclassProc(HWND hwnd, UINT msg, WPARAM wParam,
SetFocus(GetDlgItem(mwdat->hwnd, IDC_CHAT_LOG));
}
return 0;
- } else if (wParam != VK_RIGHT && wParam != VK_LEFT) {
+ }
+ if (wParam != VK_RIGHT && wParam != VK_LEFT) {
mir_free(dat->szSearchQuery);
dat->szSearchQuery = NULL;
mir_free(dat->szSearchResult);