diff options
author | George Hazan <ghazan@miranda.im> | 2016-11-02 18:30:41 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2016-11-02 18:30:50 +0300 |
commit | 2c5081fe7d0e6b155847c5ead1b32b4b42bfe4ae (patch) | |
tree | 27cadc2a6f39c3de5ff94fd8a0edf714936434c2 /src | |
parent | 2e8ebf3ad76d00ad32d4a492b32d360db87cb28e (diff) |
- common mouse hovering processing code moved to MIR_APP_DLL
- now all chats support mToolTip
Diffstat (limited to 'src')
-rw-r--r-- | src/core/stdmsg/src/chat_window.cpp | 86 | ||||
-rw-r--r-- | src/mir_app/src/chat_svc.cpp | 1 | ||||
-rw-r--r-- | src/mir_app/src/chat_tools.cpp | 155 | ||||
-rw-r--r-- | src/mir_app/src/mir_app.def | 1 | ||||
-rw-r--r-- | src/mir_app/src/mir_app64.def | 1 |
5 files changed, 159 insertions, 85 deletions
diff --git a/src/core/stdmsg/src/chat_window.cpp b/src/core/stdmsg/src/chat_window.cpp index e0bdf171c2..6dac99e58e 100644 --- a/src/core/stdmsg/src/chat_window.cpp +++ b/src/core/stdmsg/src/chat_window.cpp @@ -945,70 +945,6 @@ static LRESULT CALLBACK TabSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR return mir_callNextSubclass(hwnd, TabSubclassProc, msg, wParam, lParam); } -static void ProcessNickListHovering(HWND hwnd, int hoveredItem, SESSION_INFO *si) -{ - static int currentHovered = -1; - static HWND hwndToolTip = NULL; - static HWND oldParent = NULL; - - if (hoveredItem == currentHovered) - return; - - currentHovered = hoveredItem; - - if (oldParent != hwnd && hwndToolTip) { - SendMessage(hwndToolTip, TTM_DELTOOL, 0, 0); - DestroyWindow(hwndToolTip); - hwndToolTip = NULL; - } - if (hoveredItem == -1) { - SendMessage(hwndToolTip, TTM_ACTIVATE, 0, 0); - return; - } - - BOOL bNewTip = FALSE; - if (!hwndToolTip) { - hwndToolTip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, - WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, - CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, - hwnd, NULL, g_hInst, NULL); - bNewTip = TRUE; - } - - RECT clientRect; - GetClientRect(hwnd, &clientRect); - TOOLINFO ti = { sizeof(TOOLINFO) }; - ti.uFlags = TTF_SUBCLASS; - ti.hinst = g_hInst; - ti.hwnd = hwnd; - ti.uId = 1; - ti.rect = clientRect; - - wchar_t tszBuf[1024]; tszBuf[0] = 0; - USERINFO *ui = pci->SM_GetUserFromIndex(si->ptszID, si->pszModule, currentHovered); - if (ui) { - if (ProtoServiceExists(si->pszModule, MS_GC_PROTO_GETTOOLTIPTEXT)) { - wchar_t *p = (wchar_t*)CallProtoService(si->pszModule, MS_GC_PROTO_GETTOOLTIPTEXT, (WPARAM)si->ptszID, (LPARAM)ui->pszUID); - if (p != NULL) { - wcsncpy_s(tszBuf, p, _TRUNCATE); - mir_free(p); - } - } - - if (tszBuf[0] == 0) - mir_snwprintf(tszBuf, L"%s: %s\r\n%s: %s\r\n%s: %s", - TranslateT("Nickname"), ui->pszNick, - TranslateT("Unique ID"), ui->pszUID, - TranslateT("Status"), pci->TM_WordToString(si->pStatuses, ui->Status)); - - ti.lpszText = tszBuf; - } - - SendMessage(hwndToolTip, bNewTip ? TTM_ADDTOOL : TTM_UPDATETIPTEXT, 0, (LPARAM)&ti); - SendMessage(hwndToolTip, TTM_ACTIVATE, ti.lpszText != NULL, 0); - SendMessage(hwndToolTip, TTM_SETMAXTIPWIDTH, 0, 400); -} - static LRESULT CALLBACK NicklistSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { SESSION_INFO *si = (SESSION_INFO*)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA); @@ -1115,27 +1051,7 @@ static LRESULT CALLBACK NicklistSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, break; case WM_MOUSEMOVE: - POINT pt = { LOWORD(lParam), HIWORD(lParam) }; - RECT clientRect; - GetClientRect(hwnd, &clientRect); - BOOL bInClient = PtInRect(&clientRect, pt); - // Mouse capturing/releasing - if (bInClient && GetCapture() != hwnd) - SetCapture(hwnd); - else if (!bInClient) - ReleaseCapture(); - - if (bInClient) { - // hit test item under mouse - DWORD nItemUnderMouse = (DWORD)SendMessage(hwnd, LB_ITEMFROMPOINT, 0, lParam); - if (HIWORD(nItemUnderMouse) == 1) - nItemUnderMouse = (DWORD)(-1); - else - nItemUnderMouse &= 0xFFFF; - - ProcessNickListHovering(hwnd, (int)nItemUnderMouse, si); - } - else ProcessNickListHovering(hwnd, -1, NULL); + Chat_HoverMouse(si, hwnd, lParam, ServiceExists("mToolTip/HideTip")); break; } diff --git a/src/mir_app/src/chat_svc.cpp b/src/mir_app/src/chat_svc.cpp index cd6ca15c45..3ce6a8417d 100644 --- a/src/mir_app/src/chat_svc.cpp +++ b/src/mir_app/src/chat_svc.cpp @@ -239,6 +239,7 @@ EXTERN_C MIR_APP_DLL(int) Chat_NewSession( si->iLogFilterFlags = db_get_dw(NULL, CHAT_MODULE, "FilterFlags", 0x03E0);
si->bFilterEnabled = db_get_b(NULL, CHAT_MODULE, "FilterEnabled", 0);
si->bNicklistEnabled = db_get_b(NULL, CHAT_MODULE, "ShowNicklist", 1);
+ si->currentHovered = -1;
if (mi->bColor) {
si->iFG = 4;
diff --git a/src/mir_app/src/chat_tools.cpp b/src/mir_app/src/chat_tools.cpp index ec3ab03934..b50f2ba7ce 100644 --- a/src/mir_app/src/chat_tools.cpp +++ b/src/mir_app/src/chat_tools.cpp @@ -751,3 +751,158 @@ wchar_t* GetChatLogsFilename(SESSION_INFO *si, time_t tTime) return si->pszLogFileName;
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// process mouse - hovering for the nickname list.fires events so the protocol can
+// show the userinfo - tooltip.
+
+static void ProcessNickListHovering(HWND hwnd, int hoveredItem, SESSION_INFO *parentdat)
+{
+ static int currentHovered = -1;
+ static HWND hwndToolTip = NULL;
+ static HWND oldParent = NULL;
+
+ if (hoveredItem == currentHovered)
+ return;
+
+ currentHovered = hoveredItem;
+
+ if (oldParent != hwnd && hwndToolTip) {
+ SendMessage(hwndToolTip, TTM_DELTOOL, 0, 0);
+ DestroyWindow(hwndToolTip);
+ hwndToolTip = NULL;
+ }
+
+ if (hoveredItem == -1) {
+ SendMessage(hwndToolTip, TTM_ACTIVATE, 0, 0);
+ return;
+ }
+
+ bool bNewTip = false;
+ if (!hwndToolTip) {
+ bNewTip = true;
+ hwndToolTip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
+ WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
+ CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
+ hwnd, NULL, g_hInst, NULL);
+ }
+
+ RECT clientRect;
+ GetClientRect(hwnd, &clientRect);
+
+ TOOLINFO ti = { sizeof(ti) };
+ ti.uFlags = TTF_SUBCLASS;
+ ti.hinst = g_hInst;
+ ti.hwnd = hwnd;
+ ti.uId = 1;
+ ti.rect = clientRect;
+
+ wchar_t tszBuf[1024]; tszBuf[0] = 0;
+
+ USERINFO *ui1 = chatApi.SM_GetUserFromIndex(parentdat->ptszID, parentdat->pszModule, currentHovered);
+ if (ui1) {
+ if (ProtoServiceExists(parentdat->pszModule, MS_GC_PROTO_GETTOOLTIPTEXT)) {
+ wchar_t *p = (wchar_t*)CallProtoService(parentdat->pszModule, MS_GC_PROTO_GETTOOLTIPTEXT, (WPARAM)parentdat->ptszID, (LPARAM)ui1->pszUID);
+ if (p != NULL) {
+ wcsncpy_s(tszBuf, p, _TRUNCATE);
+ mir_free(p);
+ }
+ }
+
+ if (tszBuf[0] == 0)
+ mir_snwprintf(tszBuf, L"%s: %s\r\n%s: %s\r\n%s: %s",
+ TranslateT("Nickname"), ui1->pszNick,
+ TranslateT("Unique ID"), ui1->pszUID,
+ TranslateT("Status"), chatApi.TM_WordToString(parentdat->pStatuses, ui1->Status));
+ ti.lpszText = tszBuf;
+ }
+
+ SendMessage(hwndToolTip, bNewTip ? TTM_ADDTOOL : TTM_UPDATETIPTEXT, 0, (LPARAM)&ti);
+ SendMessage(hwndToolTip, TTM_ACTIVATE, (ti.lpszText != NULL), 0);
+ SendMessage(hwndToolTip, TTM_SETMAXTIPWIDTH, 0, 400);
+}
+
+static void CALLBACK ChatTimerProc(HWND hwnd, UINT, UINT_PTR idEvent, DWORD)
+{
+ SESSION_INFO *si = (SESSION_INFO*)idEvent;
+
+ POINT pt;
+ GetCursorPos(&pt);
+ ScreenToClient(hwnd, &pt);
+
+ DWORD nItemUnderMouse = (DWORD)SendMessage(hwnd, LB_ITEMFROMPOINT, 0, MAKELPARAM(pt.x, pt.y));
+ if (HIWORD(nItemUnderMouse) == 1)
+ nItemUnderMouse = (DWORD)(-1);
+ else
+ nItemUnderMouse &= 0xFFFF;
+ if (((int)nItemUnderMouse != si->currentHovered) || (nItemUnderMouse == -1)) {
+ KillTimer(hwnd, idEvent);
+ return;
+ }
+
+ USERINFO *ui1 = chatApi.SM_GetUserFromIndex(si->ptszID, si->pszModule, si->currentHovered);
+ if (ui1) {
+ wchar_t tszBuf[1024]; tszBuf[0] = 0;
+ if (ProtoServiceExists(si->pszModule, MS_GC_PROTO_GETTOOLTIPTEXT)) {
+ wchar_t *p = (wchar_t*)CallProtoService(si->pszModule, MS_GC_PROTO_GETTOOLTIPTEXT, (WPARAM)si->ptszID, (LPARAM)ui1->pszUID);
+ if (p) {
+ wcsncpy_s(tszBuf, p, _TRUNCATE);
+ mir_free(p);
+ }
+ }
+ if (tszBuf[0] == 0)
+ mir_snwprintf(tszBuf, L"<b>%s:</b>\t%s\n<b>%s:</b>\t%s\n<b>%s:</b>\t%s",
+ TranslateT("Nick"), ui1->pszNick,
+ TranslateT("Unique ID"), ui1->pszUID,
+ TranslateT("Status"), chatApi.TM_WordToString(si->pStatuses, ui1->Status));
+
+ CLCINFOTIP ti = { sizeof(ti) };
+ if (CallService("mToolTip/ShowTipW", (WPARAM)tszBuf, (LPARAM)&ti))
+ si->isToolTip = TRUE;
+ }
+ KillTimer(hwnd, idEvent);
+}
+
+MIR_APP_DLL(void) Chat_HoverMouse(SESSION_INFO *si, HWND hwnd, LPARAM lParam, bool bUseToolTip)
+{
+ RECT clientRect;
+ {
+ POINT pt = { LOWORD(lParam), HIWORD(lParam) };
+ GetClientRect(hwnd, &clientRect);
+ if (PtInRect(&clientRect, pt)) {
+ // hit test item under mouse
+ DWORD nItemUnderMouse = (DWORD)SendMessage(hwnd, LB_ITEMFROMPOINT, 0, lParam);
+ if (HIWORD(nItemUnderMouse) == 1)
+ nItemUnderMouse = (DWORD)(-1);
+ else
+ nItemUnderMouse &= 0xFFFF;
+
+ if (bUseToolTip) {
+ if ((int)nItemUnderMouse == si->currentHovered)
+ return;
+ si->currentHovered = (int)nItemUnderMouse;
+
+ KillTimer(hwnd, 1);
+
+ if (si->isToolTip) {
+ CallService("mToolTip/HideTip", 0, 0);
+ si->isToolTip = FALSE;
+ }
+
+ if (nItemUnderMouse != -1)
+ SetTimer(hwnd, (UINT_PTR)si, 450, ChatTimerProc);
+ }
+ else ProcessNickListHovering(hwnd, (int)nItemUnderMouse, si);
+ }
+ else {
+ if (bUseToolTip) {
+ KillTimer(hwnd, 1);
+ if (si->isToolTip) {
+ CallService("mToolTip/HideTip", 0, 0);
+ si->isToolTip = FALSE;
+ }
+ }
+ else ProcessNickListHovering(hwnd, -1, NULL);
+ }
+ }
+}
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index ba2397c37b..cb33d7d808 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -326,3 +326,4 @@ Font_RegisterW @326 Options_AddPage @327
Options_Open @328
Options_OpenPage @329
+Chat_HoverMouse @330
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index a1084ad408..6bf981dead 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -326,3 +326,4 @@ Font_RegisterW @326 Options_AddPage @327
Options_Open @328
Options_OpenPage @329
+Chat_HoverMouse @330
|