From e84bafdd3f3d2eb67e10a9bd3fbe600748962b6f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 24 Mar 2017 15:38:17 +0300 Subject: revolution in chat menus - common code moved to the core (Chat_CreateGCMenu, Chat_DestroyGCMenu); - ability added to any plugin to add its own items into any GC menu, not only to the protocol plugins to do that a plugin calls Chat_AddMenuItems and returns 0 to allow any other plugin to process menu hook --- plugins/Scriver/src/chat.h | 2 - plugins/Scriver/src/chat_tools.cpp | 88 ------------------------------------- plugins/Scriver/src/chat_window.cpp | 13 +++--- 3 files changed, 6 insertions(+), 97 deletions(-) (limited to 'plugins/Scriver/src') diff --git a/plugins/Scriver/src/chat.h b/plugins/Scriver/src/chat.h index fb21c082b8..54de98256a 100644 --- a/plugins/Scriver/src/chat.h +++ b/plugins/Scriver/src/chat.h @@ -84,8 +84,6 @@ char SM_GetStatusIndicator(SESSION_INFO *si, USERINFO *ui); // tools.c BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight, int bManyFix); wchar_t* my_strstri(const wchar_t* s1, const wchar_t* s2) ; -UINT CreateGCMenu(HWND hwndDlg, HMENU *hMenu, int iIndex, POINT pt, SESSION_INFO *si, wchar_t* pszUID, wchar_t* pszWordText); -void DestroyGCMenu(HMENU *hMenu, int iIndex); ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/plugins/Scriver/src/chat_tools.cpp b/plugins/Scriver/src/chat_tools.cpp index 050d4656c5..18511598f0 100644 --- a/plugins/Scriver/src/chat_tools.cpp +++ b/plugins/Scriver/src/chat_tools.cpp @@ -30,91 +30,3 @@ wchar_t* my_strstri(const wchar_t* s1, const wchar_t* s2) return nullptr; } - -UINT CreateGCMenu(HWND hwnd, HMENU *hMenu, int iIndex, POINT pt, SESSION_INFO *si, wchar_t* pszUID, wchar_t* pszWordText) -{ - GCMENUITEMS gcmi = { 0 }; - HMENU hSubMenu = 0; - - *hMenu = GetSubMenu(g_hMenu, iIndex); - gcmi.pszID = si->ptszID; - gcmi.pszModule = si->pszModule; - gcmi.pszUID = pszUID; - - if (iIndex == 1) { - int iLen = GetRichTextLength(hwnd, CP_ACP, FALSE); - - EnableMenuItem(*hMenu, IDM_CLEAR, MF_ENABLED); - EnableMenuItem(*hMenu, ID_COPYALL, MF_ENABLED); - if (!iLen) { - EnableMenuItem(*hMenu, ID_COPYALL, MF_BYCOMMAND | MF_GRAYED); - EnableMenuItem(*hMenu, IDM_CLEAR, MF_BYCOMMAND | MF_GRAYED); - } - - 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); - SetSearchEngineIcons(*hMenu, g_dat.hSearchEngineIconList); - } - else ModifyMenu(*hMenu, 4, MF_STRING | MF_GRAYED | MF_BYPOSITION, 4, TranslateT("No word to look up")); - gcmi.Type = MENU_ON_LOG; - } - else if (iIndex == 0) { - 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, ID_MESS, MF_STRING | MF_BYCOMMAND, ID_MESS, szTemp); - gcmi.Type = MENU_ON_NICKLIST; - } - - NotifyEventHooks(pci->hBuildMenuEvent, 0, (WPARAM)&gcmi); - - if (gcmi.nItems > 0) - AppendMenu(*hMenu, MF_SEPARATOR, 0, 0); - - for (int i = 0; i < gcmi.nItems; i++) { - wchar_t *ptszText = TranslateW(gcmi.Item[i].pszDesc); - DWORD dwState = gcmi.Item[i].bDisabled ? MF_GRAYED : 0; - - if (gcmi.Item[i].uType == MENU_NEWPOPUP) { - hSubMenu = CreateMenu(); - AppendMenu(*hMenu, dwState | MF_POPUP, (UINT_PTR)hSubMenu, ptszText); - } - else if (gcmi.Item[i].uType == MENU_POPUPHMENU) - AppendMenu(hSubMenu == 0 ? *hMenu : hSubMenu, dwState | MF_POPUP, gcmi.Item[i].dwID, ptszText); - else if (gcmi.Item[i].uType == MENU_POPUPITEM) - AppendMenu(hSubMenu == 0 ? *hMenu : hSubMenu, dwState | MF_STRING, gcmi.Item[i].dwID, ptszText); - else if (gcmi.Item[i].uType == MENU_POPUPCHECK) - AppendMenu(hSubMenu == 0 ? *hMenu : hSubMenu, dwState | MF_CHECKED | MF_STRING, gcmi.Item[i].dwID, ptszText); - else if (gcmi.Item[i].uType == MENU_POPUPSEPARATOR) - AppendMenu(hSubMenu == 0 ? *hMenu : hSubMenu, MF_SEPARATOR, 0, ptszText); - else if (gcmi.Item[i].uType == MENU_SEPARATOR) - AppendMenu(*hMenu, MF_SEPARATOR, 0, ptszText); - else if (gcmi.Item[i].uType == MENU_HMENU) - AppendMenu(*hMenu, dwState | MF_POPUP, gcmi.Item[i].dwID, ptszText); - else if (gcmi.Item[i].uType == MENU_ITEM) - AppendMenu(*hMenu, dwState | MF_STRING, gcmi.Item[i].dwID, ptszText); - else if (gcmi.Item[i].uType == MENU_CHECK) - AppendMenu(*hMenu, dwState | MF_CHECKED | MF_STRING, gcmi.Item[i].dwID, ptszText); - } - return TrackPopupMenu(*hMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwnd, nullptr); -} - -void DestroyGCMenu(HMENU *hMenu, int iIndex) -{ - MENUITEMINFO mii = { 0 }; - mii.cbSize = sizeof(mii); - mii.fMask = MIIM_SUBMENU; - while(GetMenuItemInfo(*hMenu, iIndex, TRUE, &mii)) - { - if (mii.hSubMenu != nullptr) - DestroyMenu(mii.hSubMenu); - RemoveMenu(*hMenu, iIndex, MF_BYPOSITION); - } -} diff --git a/plugins/Scriver/src/chat_window.cpp b/plugins/Scriver/src/chat_window.cpp index 699ff3518f..13a273c3ca 100644 --- a/plugins/Scriver/src/chat_window.cpp +++ b/plugins/Scriver/src/chat_window.cpp @@ -861,8 +861,8 @@ LRESULT CChatRoomDlg::WndProc_Log(UINT msg, WPARAM wParam, LPARAM lParam) SESSION_INFO *si = m_si; CHARRANGE all = { 0, -1 }; - HMENU hMenu = nullptr; - UINT uID = CreateGCMenu(m_log.GetHwnd(), &hMenu, 1, pt, si, nullptr, pszWord); + HMENU hMenu = GetSubMenu(g_hMenu, 1); + UINT uID = Chat_CreateGCMenu(m_log.GetHwnd(), hMenu, pt, si, nullptr, pszWord); inMenu = FALSE; switch (uID) { case 0: @@ -904,7 +904,7 @@ LRESULT CChatRoomDlg::WndProc_Log(UINT msg, WPARAM wParam, LPARAM lParam) DoEventHook(GC_USER_LOGMENU, nullptr, nullptr, uID); break; } - DestroyGCMenu(&hMenu, 5); + Chat_DestroyGCMenu(hMenu, 5); } break; @@ -950,14 +950,13 @@ LRESULT CChatRoomDlg::WndProc_Nicklist(UINT msg, WPARAM wParam, LPARAM lParam) USERINFO *ui = pci->SM_GetUserFromIndex(m_si->ptszID, m_si->pszModule, (int)item); if (ui) { - HMENU hMenu = 0; + HMENU hMenu = GetSubMenu(g_hMenu, 0); USERINFO uinew; - memcpy(&uinew, ui, sizeof(USERINFO)); if (hti.pt.x == -1 && hti.pt.y == -1) hti.pt.y += height - 4; ClientToScreen(m_nickList.GetHwnd(), &hti.pt); - UINT uID = CreateGCMenu(m_nickList.GetHwnd(), &hMenu, 0, hti.pt, m_si, uinew.pszUID, uinew.pszNick); + UINT uID = Chat_CreateGCMenu(m_nickList.GetHwnd(), hMenu, hti.pt, m_si, uinew.pszUID, uinew.pszNick); switch (uID) { case 0: @@ -971,7 +970,7 @@ LRESULT CChatRoomDlg::WndProc_Nicklist(UINT msg, WPARAM wParam, LPARAM lParam) DoEventHook(GC_USER_NICKLISTMENU, ui, nullptr, uID); break; } - DestroyGCMenu(&hMenu, 1); + Chat_DestroyGCMenu(hMenu, 1); return TRUE; } } -- cgit v1.2.3