diff options
author | George Hazan <george.hazan@gmail.com> | 2023-06-19 17:54:32 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-06-19 17:54:32 +0300 |
commit | 1c3bbb283ca5f0d25658e190c4c41a4667f71ff2 (patch) | |
tree | 892c6964b7d7c4bd572fbdb9dc8736605471d6c6 | |
parent | 7c711561aa5a124b51df2c1cba138eb518e6aad6 (diff) |
nick search went to core
-rw-r--r-- | include/m_srmm_int.h | 3 | ||||
-rw-r--r-- | plugins/Scriver/src/msgdialog.cpp | 49 | ||||
-rw-r--r-- | plugins/Scriver/src/msgs.h | 1 | ||||
-rw-r--r-- | plugins/TabSRMM/src/msgdialog.cpp | 57 | ||||
-rw-r--r-- | plugins/TabSRMM/src/msgdlgother.cpp | 8 | ||||
-rw-r--r-- | plugins/TabSRMM/src/msgs.h | 2 | ||||
-rw-r--r-- | src/mir_app/src/srmm_base.cpp | 38 |
7 files changed, 45 insertions, 113 deletions
diff --git a/include/m_srmm_int.h b/include/m_srmm_int.h index 6fe11774e2..567b153555 100644 --- a/include/m_srmm_int.h +++ b/include/m_srmm_int.h @@ -268,6 +268,9 @@ protected: const USERINFO* m_pUserTyping = nullptr;
CCtrlListBox m_nickList;
+ int m_iNickSearch = -1;
+ CMStringW m_wszNickSearch;
+
CCtrlButton m_btnColor, m_btnBkColor, m_btnOk;
CCtrlButton m_btnBold, m_btnItalic, m_btnUnderline;
CCtrlButton m_btnHistory, m_btnChannelMgr, m_btnNickList, m_btnFilter;
diff --git a/plugins/Scriver/src/msgdialog.cpp b/plugins/Scriver/src/msgdialog.cpp index 4188ef3b2c..c69bf8a266 100644 --- a/plugins/Scriver/src/msgdialog.cpp +++ b/plugins/Scriver/src/msgdialog.cpp @@ -868,55 +868,6 @@ LRESULT CMsgDialog::WndProc_Nicklist(UINT msg, WPARAM wParam, LPARAM lParam) }
}
break;
-
- case WM_KEYDOWN:
- if (wParam == VK_ESCAPE || wParam == VK_UP || wParam == VK_DOWN || wParam == VK_NEXT || wParam == VK_PRIOR || wParam == VK_TAB || wParam == VK_HOME || wParam == VK_END)
- m_wszSearch[0] = 0;
- break;
-
- case WM_CHAR:
- case WM_UNICHAR:
- /*
- * simple incremental search for the user (nick) - list control
- * typing esc or movement keys will clear the current search string
- */
- if (wParam == 27 && m_wszSearch[0]) { // escape - reset everything
- m_wszSearch[0] = 0;
- break;
- }
- else if (wParam == '\b' && m_wszSearch[0]) // backspace
- m_wszSearch[mir_wstrlen(m_wszSearch) - 1] = '\0';
- else if (wParam < ' ')
- break;
- else {
- wchar_t szNew[2];
- szNew[0] = (wchar_t)wParam;
- szNew[1] = '\0';
- if (mir_wstrlen(m_wszSearch) >= _countof(m_wszSearch) - 2) {
- MessageBeep(MB_OK);
- break;
- }
- mir_wstrcat(m_wszSearch, szNew);
- }
- if (m_wszSearch[0]) {
- // iterate over the (sorted) list of nicknames and search for the
- // string we have
- int iItems = m_nickList.GetCount();
- for (int i = 0; i < iItems; i++) {
- if (auto *ui = (USERINFO*)m_nickList.GetItemData(i)) {
- if (!wcsnicmp(ui->pszNick, m_wszSearch, mir_wstrlen(m_wszSearch))) {
- m_nickList.SetCurSel(i);
- InvalidateRect(m_nickList.GetHwnd(), nullptr, FALSE);
- return 0;
- }
- }
- }
-
- MessageBeep(MB_OK);
- m_wszSearch[mir_wstrlen(m_wszSearch) - 1] = '\0';
- return 0;
- }
- break;
}
return CSuper::WndProc_Nicklist(msg, wParam, lParam);
diff --git a/plugins/Scriver/src/msgs.h b/plugins/Scriver/src/msgs.h index e2b200c13f..936da01f5d 100644 --- a/plugins/Scriver/src/msgs.h +++ b/plugins/Scriver/src/msgs.h @@ -98,7 +98,6 @@ class CMsgDialog : public CSrmmBaseDialog // autocomplete
void TabAutoComplete(void);
- wchar_t m_wszSearch[255];
wchar_t *m_wszSearchQuery, *m_wszSearchResult;
SESSION_INFO *m_pLastSession;
diff --git a/plugins/TabSRMM/src/msgdialog.cpp b/plugins/TabSRMM/src/msgdialog.cpp index a93a455a2a..02b5eb8de5 100644 --- a/plugins/TabSRMM/src/msgdialog.cpp +++ b/plugins/TabSRMM/src/msgdialog.cpp @@ -1976,63 +1976,6 @@ LRESULT CMsgDialog::WndProc_Nicklist(UINT msg, WPARAM wParam, LPARAM lParam) PostMessage(m_hwnd, WM_CLOSE, 0, 1);
return TRUE;
}
-
- if (wParam == VK_ESCAPE || wParam == VK_UP || wParam == VK_DOWN || wParam == VK_NEXT || wParam == VK_PRIOR || wParam == VK_TAB || wParam == VK_HOME || wParam == VK_END) {
- m_wszSearch[0] = 0;
- m_iSearchItem = -1;
- }
- break;
-
- case WM_SETFOCUS:
- case WM_KILLFOCUS:
- m_wszSearch[0] = 0;
- m_iSearchItem = -1;
- break;
-
- case WM_CHAR:
- case WM_UNICHAR:
- // simple incremental search for the user (nick) - list control
- // typing esc or movement keys will clear the current search string
- if (wParam == 27 && m_wszSearch[0]) { // escape - reset everything
- m_wszSearch[0] = 0;
- m_iSearchItem = -1;
- break;
- }
- if (wParam == '\b' && m_wszSearch[0]) // backspace
- m_wszSearch[mir_wstrlen(m_wszSearch) - 1] = '\0';
- else if (wParam < ' ')
- break;
- else {
- if (mir_wstrlen(m_wszSearch) >= _countof(m_wszSearch) - 2) {
- MessageBeep(MB_OK);
- break;
- }
- wchar_t szNew[2];
- szNew[0] = (wchar_t)wParam;
- szNew[1] = '\0';
- mir_wstrcat(m_wszSearch, szNew);
- }
- if (m_wszSearch[0]) {
- // iterate over the (sorted) list of nicknames and search for the
- // string we have
- int i, iItems = m_nickList.SendMsg(LB_GETCOUNT, 0, 0);
- for (i = 0; i < iItems; i++) {
- if (auto *ui = (USERINFO *)m_nickList.GetItemData(i)) {
- if (!wcsnicmp(ui->pszNick, m_wszSearch, mir_wstrlen(m_wszSearch))) {
- m_nickList.SendMsg(LB_SETSEL, FALSE, -1);
- m_nickList.SendMsg(LB_SETSEL, TRUE, i);
- m_iSearchItem = i;
- InvalidateRect(m_nickList.GetHwnd(), nullptr, FALSE);
- return 0;
- }
- }
- }
- if (i == iItems) {
- MessageBeep(MB_OK);
- m_wszSearch[mir_wstrlen(m_wszSearch) - 1] = '\0';
- return 0;
- }
- }
break;
}
diff --git a/plugins/TabSRMM/src/msgdlgother.cpp b/plugins/TabSRMM/src/msgdlgother.cpp index 52b26b29b8..7942e378cb 100644 --- a/plugins/TabSRMM/src/msgdlgother.cpp +++ b/plugins/TabSRMM/src/msgdlgother.cpp @@ -501,14 +501,14 @@ void CMsgDialog::DrawNickList(USERINFO *ui, DRAWITEMSTRUCT *dis) }
SIZE sz;
- if (m_iSearchItem != -1 && m_iSearchItem == index && m_wszSearch[0]) {
+ if (m_iNickSearch != -1 && m_iNickSearch == index && !m_wszNickSearch.IsEmpty()) {
COLORREF clr_orig = GetTextColor(dis->hDC);
- GetTextExtentPoint32(dis->hDC, ui->pszNick, (int)mir_wstrlen(m_wszSearch), &sz);
+ GetTextExtentPoint32(dis->hDC, ui->pszNick, m_wszNickSearch.GetLength(), &sz);
SetTextColor(dis->hDC, RGB(250, 250, 0));
- TextOut(dis->hDC, x_offset, (dis->rcItem.top + dis->rcItem.bottom - sz.cy) / 2, ui->pszNick, (int)mir_wstrlen(m_wszSearch));
+ TextOut(dis->hDC, x_offset, (dis->rcItem.top + dis->rcItem.bottom - sz.cy) / 2, ui->pszNick, m_wszNickSearch.GetLength());
SetTextColor(dis->hDC, clr_orig);
x_offset += sz.cx;
- TextOut(dis->hDC, x_offset, (dis->rcItem.top + dis->rcItem.bottom - sz.cy) / 2, ui->pszNick + mir_wstrlen(m_wszSearch), int(mir_wstrlen(ui->pszNick) - mir_wstrlen(m_wszSearch)));
+ TextOut(dis->hDC, x_offset, (dis->rcItem.top + dis->rcItem.bottom - sz.cy) / 2, ui->pszNick + m_wszNickSearch.GetLength(), int(mir_wstrlen(ui->pszNick) - m_wszNickSearch.GetLength()));
}
else {
GetTextExtentPoint32(dis->hDC, ui->pszNick, (int)mir_wstrlen(ui->pszNick), &sz);
diff --git a/plugins/TabSRMM/src/msgs.h b/plugins/TabSRMM/src/msgs.h index 9d8c96b839..9305fd8ace 100644 --- a/plugins/TabSRMM/src/msgs.h +++ b/plugins/TabSRMM/src/msgs.h @@ -553,9 +553,7 @@ public: bool TabAutoComplete();
HWND m_hwndFilter;
- int m_iSearchItem;
BOOL m_iSavedSpaces;
- wchar_t m_wszSearch[255];
wchar_t *m_wszSearchQuery, *m_wszSearchResult;
SESSION_INFO *m_pLastSession;
diff --git a/src/mir_app/src/srmm_base.cpp b/src/mir_app/src/srmm_base.cpp index 39cc182ea2..0696dbbe4c 100644 --- a/src/mir_app/src/srmm_base.cpp +++ b/src/mir_app/src/srmm_base.cpp @@ -482,6 +482,44 @@ LRESULT CSrmmBaseDialog::WndProc_Nicklist(UINT msg, WPARAM wParam, LPARAM lParam if (auto *ui = (USERINFO *)m_nickList.GetItemData(index))
Chat_DoEventHook(m_si, GC_USER_PRIVMESS, ui, nullptr, 0);
}
+
+ if (wParam == VK_ESCAPE || wParam == VK_UP || wParam == VK_DOWN || wParam == VK_NEXT || wParam == VK_PRIOR || wParam == VK_TAB || wParam == VK_HOME || wParam == VK_END) {
+ m_wszNickSearch.Empty();
+ m_iNickSearch = -1;
+ }
+ break;
+
+
+ case WM_SETFOCUS:
+ case WM_KILLFOCUS:
+ m_wszNickSearch.Empty();
+ m_iNickSearch = -1;
+ break;
+
+ case WM_CHAR:
+ case WM_UNICHAR:
+ // simple incremental search for the user (nick) - list control
+ // typing esc or movement keys will clear the current search string
+ if (wParam == 27 && !m_wszNickSearch.IsEmpty()) { // escape - reset everything
+ m_wszNickSearch.Empty();
+ m_iNickSearch = -1;
+ break;
+ }
+ if (wParam == '\b' && !m_wszNickSearch.IsEmpty()) // backspace
+ m_wszNickSearch.Truncate(m_wszNickSearch.GetLength() - 1);
+ else if (wParam < ' ')
+ break;
+ else
+ m_wszNickSearch.AppendChar((wchar_t)wParam);
+
+ if (!m_wszNickSearch.IsEmpty()) {
+ m_iNickSearch = m_nickList.SendMsg(LB_FINDSTRING, -1, LPARAM(m_wszNickSearch.c_str()));
+ if (m_iNickSearch == LB_ERR) {
+ MessageBeep(MB_OK);
+ m_wszNickSearch.Truncate(m_wszNickSearch.GetLength() - 1);
+ return 0;
+ }
+ }
break;
}
|