From 633d14f19afc80362a5d4872def663a5271c7225 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 4 May 2020 20:52:39 +0300 Subject: fixes #2381 (NewStory: add right-click menu for groupchats) --- include/m_chat_int.h | 3 +++ libs/win32/mir_app.lib | Bin 206020 -> 206244 bytes libs/win64/mir_app.lib | Bin 201662 -> 201862 bytes plugins/NewStory/src/history_array.cpp | 2 -- plugins/NewStory/src/history_control.cpp | 25 ++++++++++++++++++-- plugins/NewStory/src/history_control.h | 3 +++ plugins/NewStory/src/history_log.cpp | 2 ++ src/mir_app/src/chat.h | 1 - src/mir_app/src/chat_tools.cpp | 39 +++++-------------------------- src/mir_app/src/mir_app.def | 1 + src/mir_app/src/mir_app64.def | 1 + src/mir_app/src/srmm_base.cpp | 13 ++++++++++- src/mir_app/src/srmm_log_rtf.cpp | 19 ++++++++++++--- 13 files changed, 67 insertions(+), 42 deletions(-) diff --git a/include/m_chat_int.h b/include/m_chat_int.h index 24f368caf4..5319c96422 100644 --- a/include/m_chat_int.h +++ b/include/m_chat_int.h @@ -395,6 +395,9 @@ EXTERN_C MIR_APP_DLL(void) Chat_UpdateOptions(); // runs ME_GC_EVENT with the parameters passed EXTERN_C MIR_APP_DLL(BOOL) Chat_DoEventHook(SESSION_INFO *si, int iType, const USERINFO *pUser, const wchar_t* pszText, INT_PTR dwItem); +// creates custom popup menu for a group chat +EXTERN_C MIR_APP_DLL(UINT) Chat_CreateMenu(HWND hwnd, HMENU hMenu, POINT pt, SESSION_INFO *si, const wchar_t *pszUID); + // calculates width or height of a string EXTERN_C MIR_APP_DLL(int) Chat_GetTextPixelSize(const wchar_t *pszText, HFONT hFont, bool bWidth); diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib index 964fb0a997..2283dfc985 100644 Binary files a/libs/win32/mir_app.lib and b/libs/win32/mir_app.lib differ diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib index b483807a56..c886279092 100644 Binary files a/libs/win64/mir_app.lib and b/libs/win64/mir_app.lib differ diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp index 6f9de4be95..83c44da0e0 100644 --- a/plugins/NewStory/src/history_array.cpp +++ b/plugins/NewStory/src/history_array.cpp @@ -147,8 +147,6 @@ void HistoryArray::addChatEvent(SESSION_INFO *si, LOGINFO *lin) p.hContact = si->hContact; p.wtext = wszText.Detach(); p.bLoaded = true; - p.dbe.cbBlob = 1; - p.dbe.pBlob = (BYTE *)p.wtext; p.dbe.eventType = EVENTTYPE_MESSAGE; p.dbe.timestamp = lin->time; diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp index a965e7eb81..a616e9a6b7 100644 --- a/plugins/NewStory/src/history_control.cpp +++ b/plugins/NewStory/src/history_control.cpp @@ -37,6 +37,7 @@ struct NewstoryListData : public MZeroedObject HWND hwndEditBox; CTimer redrawTimer; + CSrmmBaseDialog *pMsgDlg = nullptr; void OnContextMenu(int index, POINT pt) { @@ -46,8 +47,18 @@ struct NewstoryListData : public MZeroedObject HMENU hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_CONTEXTMENU)); TranslateMenu(hMenu); - - int ret = TrackPopupMenu(GetSubMenu(hMenu, 0), TPM_RETURNCMD, pt.x, pt.y, 0, hwnd, nullptr); + + HMENU hSubMenu = GetSubMenu(hMenu, 0); + UINT ret; + if (pMsgDlg != nullptr && pMsgDlg->isChat()) { + EnableMenuItem(hSubMenu, 2, MF_BYPOSITION | MF_GRAYED); + + pMsgDlg->m_bInMenu = true; + ret = Chat_CreateMenu(hwnd, hSubMenu, pt, pMsgDlg->getChat(), nullptr); + pMsgDlg->m_bInMenu = false; + } + else ret = TrackPopupMenu(hSubMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwnd, nullptr); + switch(ret) { case ID_CONTEXT_COPY: SendMessage(hwnd, NSM_COPY, 0, 0); @@ -63,6 +74,12 @@ struct NewstoryListData : public MZeroedObject case ID_CONTEXT_SELECTALL: SendMessage(hwnd, NSM_SELECTITEMS, 0, items.getCount() - 1); break; + + default: + if (pMsgDlg != nullptr) { + PostMessage(pMsgDlg->GetHwnd(), WM_MOUSEACTIVATE, 0, 0); + Chat_DoEventHook(pMsgDlg->getChat(), GC_USER_LOGMENU, nullptr, nullptr, ret); + } } DestroyMenu(hMenu); @@ -660,6 +677,10 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM SendMessage(hwnd, NSM_SETCARET, data->items.getCount() - 1, 1); break; + case NSM_SET_SRMM: + data->pMsgDlg = (CSrmmBaseDialog *)lParam; + break; + case NSM_DELETE: if (IDYES == MessageBoxW(hwnd, TranslateW(wszDelete), _T(MODULETITLE), MB_YESNOCANCEL | MB_ICONQUESTION)) { db_set_safety_mode(false); diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h index c1ed6be620..46b1bb045f 100644 --- a/plugins/NewStory/src/history_control.h +++ b/plugins/NewStory/src/history_control.h @@ -74,6 +74,9 @@ enum NSM_SEEKEND, NSM_SEEKTIME, + // + NSM_SET_SRMM, // act inside SRMM dialog + NSM_LAST }; diff --git a/plugins/NewStory/src/history_log.cpp b/plugins/NewStory/src/history_log.cpp index d1d0f69b36..43d75a545a 100644 --- a/plugins/NewStory/src/history_log.cpp +++ b/plugins/NewStory/src/history_log.cpp @@ -13,6 +13,8 @@ public: void Attach() override { m_hwnd = ::CreateWindow(_T(NEWSTORYLIST_CLASS), L"NewStory", WS_VISIBLE | WS_CHILD | WS_TABSTOP, 0, 0, 300, 150, m_pDlg.GetHwnd(), 0, m_pDlg.GetInst(), 0); + + SendMessage(m_hwnd, NSM_SET_SRMM, 0, (LPARAM)&m_pDlg); } void Detach() override diff --git a/src/mir_app/src/chat.h b/src/mir_app/src/chat.h index 4685fa5685..81675c46ad 100644 --- a/src/mir_app/src/chat.h +++ b/src/mir_app/src/chat.h @@ -109,7 +109,6 @@ int LoadChatModule(void); void UnloadChatModule(void); // tools.c -UINT CreateGCMenu(HWND hwnd, HMENU hMenu, POINT pt, SESSION_INFO *si, const wchar_t *pszUID, const wchar_t *pszWordText); int DoRtfToTags(CMStringW &pszText, int iNumColors, COLORREF *pColors); wchar_t* RemoveFormatting(const wchar_t* pszText); BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight, int bManyFix); diff --git a/src/mir_app/src/chat_tools.cpp b/src/mir_app/src/chat_tools.cpp index 8602f59168..53b4a33700 100644 --- a/src/mir_app/src/chat_tools.cpp +++ b/src/mir_app/src/chat_tools.cpp @@ -753,44 +753,17 @@ MIR_APP_DLL(void) Chat_AddMenuItems(HMENU hMenu, int nItems, const gc_item *Item ///////////////////////////////////////////////////////////////////////////////////////// -UINT CreateGCMenu(HWND hwnd, HMENU hMenu, POINT pt, SESSION_INFO *si, const wchar_t *pszUID, const wchar_t *pszWordText) +MIR_APP_DLL(UINT) Chat_CreateMenu(HWND hwnd, HMENU hMenu, POINT pt, SESSION_INFO *si, const wchar_t *pszUID) { - GCMENUITEMS gcmi = {}; if (si) { + GCMENUITEMS gcmi = {}; gcmi.pszID = si->ptszID; gcmi.pszModule = si->pszModule; - } - gcmi.pszUID = (wchar_t*)pszUID; - gcmi.hMenu = hMenu; - - if (pszUID == nullptr) { - int flags = MF_BYPOSITION | (GetRichTextLength(hwnd) == 0 ? MF_GRAYED : MF_ENABLED); - EnableMenuItem(hMenu, 0, flags); - EnableMenuItem(hMenu, 2, flags); - - if (pszWordText && pszWordText[0]) { - wchar_t szMenuText[4096]; - mir_snwprintf(szMenuText, TranslateT("Look up '%s':"), pszWordText); - ModifyMenu(hMenu, 4, MF_STRING | MF_BYPOSITION, 4, szMenuText); - } - else ModifyMenu(hMenu, 4, MF_STRING | MF_GRAYED | MF_BYPOSITION, 4, TranslateT("No word to look up")); - gcmi.Type = MENU_ON_LOG; - } - else { - wchar_t szTemp[50]; - if (pszWordText) - mir_snwprintf(szTemp, TranslateT("&Message %s"), pszWordText); - else - mir_wstrncpy(szTemp, TranslateT("&Message"), _countof(szTemp) - 1); - - if (mir_wstrlen(szTemp) > 40) - mir_wstrncpy(szTemp + 40, L"...", 4); - ModifyMenu(hMenu, 0, MF_STRING | MF_BYPOSITION, IDM_SENDMESSAGE, szTemp); - gcmi.Type = MENU_ON_NICKLIST; - } - - if (si) + gcmi.pszUID = (wchar_t *)pszUID; + gcmi.hMenu = hMenu; + gcmi.Type = (pszUID == nullptr) ? MENU_ON_LOG : MENU_ON_NICKLIST; NotifyEventHooks(hevBuildMenuEvent, 0, (WPARAM)&gcmi); + } return TrackPopupMenu(hMenu, TPM_RETURNCMD | TPM_RIGHTBUTTON, pt.x, pt.y, 0, hwnd, nullptr); } diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 200a784b75..01161746cd 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -734,3 +734,4 @@ ProtoBroadcastAsync @814 NONAME ?getChat@CSrmmBaseDialog@@QBEPAUSESSION_INFO@@XZ @821 NONAME ?EventCursor@MDatabaseCommon@@UAGPAVEventCursorBase@DB@@IAAUDBEVENTINFO@@@Z @822 NONAME ?EventCursorRev@MDatabaseCommon@@UAGPAVEventCursorBase@DB@@IAAUDBEVENTINFO@@@Z @823 NONAME +Chat_CreateMenu @824 NONAME diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 50105e6a82..9ef8a4097a 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -734,3 +734,4 @@ ProtoBroadcastAsync @814 NONAME ?getChat@CSrmmBaseDialog@@QEBAPEAUSESSION_INFO@@XZ @821 NONAME ?EventCursor@MDatabaseCommon@@UEAAPEAVEventCursorBase@DB@@IAEAUDBEVENTINFO@@@Z @822 NONAME ?EventCursorRev@MDatabaseCommon@@UEAAPEAVEventCursorBase@DB@@IAEAUDBEVENTINFO@@@Z @823 NONAME +Chat_CreateMenu @824 NONAME diff --git a/src/mir_app/src/srmm_base.cpp b/src/mir_app/src/srmm_base.cpp index d835c3f8bf..323a336b70 100644 --- a/src/mir_app/src/srmm_base.cpp +++ b/src/mir_app/src/srmm_base.cpp @@ -84,7 +84,18 @@ void CSrmmBaseDialog::RunUserMenu(HWND hwndOwner, USERINFO *ui, const POINT &pt) USERINFO uinew; memcpy(&uinew, ui, sizeof(USERINFO)); - UINT uID = CreateGCMenu(hwndOwner, hSubMenu, pt, m_si, uinew.pszUID, uinew.pszNick); + + wchar_t szTemp[50]; + if (uinew.pszNick) + mir_snwprintf(szTemp, TranslateT("&Message %s"), uinew.pszNick); + else + mir_wstrncpy(szTemp, TranslateT("&Message"), _countof(szTemp) - 1); + + if (mir_wstrlen(szTemp) > 40) + mir_wstrncpy(szTemp + 40, L"...", 4); + ModifyMenu(hMenu, 0, MF_STRING | MF_BYPOSITION, IDM_SENDMESSAGE, szTemp); + + UINT uID = Chat_CreateMenu(hwndOwner, hSubMenu, pt, m_si, uinew.pszUID); switch (uID) { case 0: break; diff --git a/src/mir_app/src/srmm_log_rtf.cpp b/src/mir_app/src/srmm_log_rtf.cpp index f2f1fae8d6..a5132a9af0 100644 --- a/src/mir_app/src/srmm_log_rtf.cpp +++ b/src/mir_app/src/srmm_log_rtf.cpp @@ -278,7 +278,7 @@ INT_PTR CRtfLogWindow::WndProc(UINT msg, WPARAM wParam, LPARAM lParam) pt.y = GET_Y_LPARAM(lParam); } ptl = pt; - ScreenToClient(m_rtf.GetHwnd(), (LPPOINT)&ptl); + ScreenToClient(m_rtf.GetHwnd(), &ptl); { wchar_t *pszWord = (wchar_t *)_alloca(8192); pszWord[0] = '\0'; @@ -316,8 +316,22 @@ INT_PTR CRtfLogWindow::WndProc(UINT msg, WPARAM wParam, LPARAM lParam) HMENU hSubMenu = GetSubMenu(hMenu, 0); TranslateMenu(hSubMenu); m_pDlg.m_bInMenu = true; - UINT uID = CreateGCMenu(m_rtf.GetHwnd(), hSubMenu, pt, m_pDlg.m_si, nullptr, pszWord); + + int flags = MF_BYPOSITION | (GetRichTextLength(m_rtf.GetHwnd()) == 0 ? MF_GRAYED : MF_ENABLED); + EnableMenuItem(hSubMenu, 0, flags); + EnableMenuItem(hSubMenu, 2, flags); + + if (pszWord && pszWord[0]) { + wchar_t szMenuText[4096]; + mir_snwprintf(szMenuText, TranslateT("Look up '%s':"), pszWord); + ModifyMenu(hSubMenu, 4, MF_STRING | MF_BYPOSITION, 4, szMenuText); + } + else ModifyMenu(hSubMenu, 4, MF_STRING | MF_GRAYED | MF_BYPOSITION, 4, TranslateT("No word to look up")); + + UINT uID = Chat_CreateMenu(m_rtf.GetHwnd(), hSubMenu, pt, m_pDlg.m_si, nullptr); m_pDlg.m_bInMenu = false; + DestroyMenu(hMenu); + switch (uID) { case 0: PostMessage(m_pDlg.m_hwnd, WM_MOUSEACTIVATE, 0, 0); @@ -387,7 +401,6 @@ INT_PTR CRtfLogWindow::WndProc(UINT msg, WPARAM wParam, LPARAM lParam) Chat_DoEventHook(m_pDlg.m_si, GC_USER_LOGMENU, nullptr, nullptr, uID); break; } - DestroyMenu(hMenu); } return 0; } -- cgit v1.2.3