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 --- src/mir_app/res/resource.rc | 2 +- src/mir_app/src/chat.h | 6 +-- src/mir_app/src/chat_tools.cpp | 93 +++++++++++++++++++++++++++++++++++++++ src/mir_app/src/mir_app.def | 3 ++ src/mir_app/src/mir_app64.def | 3 ++ src/mir_app/src/resource.h | 2 +- src/mir_app/src/searchresults.cpp | 2 +- src/mir_app/src/srmm_base.cpp | 4 -- 8 files changed, 103 insertions(+), 12 deletions(-) (limited to 'src/mir_app') diff --git a/src/mir_app/res/resource.rc b/src/mir_app/res/resource.rc index 28b3100092..113bde9218 100644 --- a/src/mir_app/res/resource.rc +++ b/src/mir_app/res/resource.rc @@ -1266,7 +1266,7 @@ BEGIN MENUITEM "&Add to list", IDC_ADD MENUITEM SEPARATOR MENUITEM "User &details", IDC_DETAILS - MENUITEM "Send &message", IDC_SENDMESSAGE + MENUITEM "Send &message", IDM_SENDMESSAGE END POPUP "Log" BEGIN diff --git a/src/mir_app/src/chat.h b/src/mir_app/src/chat.h index dee0182b12..cb7e26f97c 100644 --- a/src/mir_app/src/chat.h +++ b/src/mir_app/src/chat.h @@ -38,6 +38,7 @@ extern int g_cbSession, g_cbModuleInfo, g_iFontMode, g_iChatLang; extern wchar_t *g_szFontGroup; extern mir_cs csChat; +extern HCURSOR g_hCurHyperlinkHand; extern char* pLogIconBmpBits[14]; extern LIST g_arSessions; @@ -79,9 +80,6 @@ INT_PTR JoinChat(WPARAM wParam, LPARAM lParam); INT_PTR LeaveChat(WPARAM wParam, LPARAM lParam); int PrebuildContactMenu(WPARAM wParam, LPARAM lParam); -// colorchooser.c -void ColorChooser(SESSION_INFO *si, BOOL bFG, HWND hwndDlg, HWND hwndTarget, HWND hwndChooser); - // options.c int OptionsInit(void); int OptionsUnInit(void); @@ -106,8 +104,6 @@ int GetColorIndex(const char *pszModule, COLORREF cr); void CheckColorsInModule(const char *pszModule); int GetRichTextLength(HWND hwnd); bool IsHighlighted(SESSION_INFO *si, GCEVENT *pszText); -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); BOOL DoEventHook(SESSION_INFO *si, int iType, const USERINFO *pUser, const wchar_t* pszText, INT_PTR dwItem); BOOL IsEventSupported(int eventType); BOOL LogToFile(SESSION_INFO *si, GCEVENT *gce); diff --git a/src/mir_app/src/chat_tools.cpp b/src/mir_app/src/chat_tools.cpp index 3c861cd593..df67d45517 100644 --- a/src/mir_app/src/chat_tools.cpp +++ b/src/mir_app/src/chat_tools.cpp @@ -749,3 +749,96 @@ MIR_APP_DLL(wchar_t*) Chat_UnescapeTags(wchar_t *str_in) *d = 0; return str_in; } + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(void) Chat_AddMenuItems(HMENU hMenu, int nItems, const gc_item *Item) +{ + if (nItems > 0) + AppendMenu(hMenu, MF_SEPARATOR, 0, 0); + + HMENU hSubMenu = nullptr; + for (int i = 0; i < nItems; i++) { + wchar_t *ptszText = TranslateW(Item[i].pszDesc); + DWORD dwState = Item[i].bDisabled ? MF_GRAYED : 0; + + if (Item[i].uType == MENU_NEWPOPUP) { + hSubMenu = CreateMenu(); + AppendMenu(hMenu, dwState | MF_POPUP, (UINT_PTR)hSubMenu, ptszText); + } + else if (Item[i].uType == MENU_POPUPHMENU) + AppendMenu(hSubMenu == 0 ? hMenu : hSubMenu, dwState | MF_POPUP, Item[i].dwID, ptszText); + else if (Item[i].uType == MENU_POPUPITEM) + AppendMenu(hSubMenu == 0 ? hMenu : hSubMenu, dwState | MF_STRING, Item[i].dwID, ptszText); + else if (Item[i].uType == MENU_POPUPCHECK) + AppendMenu(hSubMenu == 0 ? hMenu : hSubMenu, dwState | MF_CHECKED | MF_STRING, Item[i].dwID, ptszText); + else if (Item[i].uType == MENU_POPUPSEPARATOR) + AppendMenu(hSubMenu == 0 ? hMenu : hSubMenu, MF_SEPARATOR, 0, ptszText); + else if (Item[i].uType == MENU_SEPARATOR) + AppendMenu(hMenu, MF_SEPARATOR, 0, ptszText); + else if (Item[i].uType == MENU_HMENU) + AppendMenu(hMenu, dwState | MF_POPUP, Item[i].dwID, ptszText); + else if (Item[i].uType == MENU_ITEM) + AppendMenu(hMenu, dwState | MF_STRING, Item[i].dwID, ptszText); + else if (Item[i].uType == MENU_CHECK) + AppendMenu(hMenu, dwState | MF_CHECKED | MF_STRING, Item[i].dwID, ptszText); + } +} + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(UINT) Chat_CreateGCMenu(HWND hwnd, HMENU hMenu, POINT pt, SESSION_INFO *si, const wchar_t *pszUID, const wchar_t *pszWordText) +{ + GCMENUITEMS gcmi = {}; + gcmi.pszID = si->ptszID; + gcmi.pszModule = si->pszModule; + gcmi.pszUID = (wchar_t*)pszUID; + gcmi.hMenu = hMenu; + + if (pszUID == nullptr) { + int iLen = GetRichTextLength(hwnd); + + EnableMenuItem(hMenu, IDM_CLEAR, MF_ENABLED); + EnableMenuItem(hMenu, IDM_COPYALL, MF_ENABLED); + if (!iLen) { + EnableMenuItem(hMenu, IDM_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); + } + 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, IDM_SENDMESSAGE, MF_STRING | MF_BYCOMMAND, IDM_SENDMESSAGE, szTemp); + gcmi.Type = MENU_ON_NICKLIST; + } + + NotifyEventHooks(chatApi.hBuildMenuEvent, 0, (WPARAM)&gcmi); + + return TrackPopupMenu(hMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwnd, nullptr); +} + +MIR_APP_DLL(void) Chat_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/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 1cca4f34e8..7af41520aa 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -436,3 +436,6 @@ Chat_UpdateOptions @418 NONAME ?WndProc_Nicklist@CSrmmBaseDialog@@UAEJIIJ@Z @439 NONAME ?onDblClick_List@CSrmmBaseDialog@@IAEXPAVCCtrlListBox@@@Z @440 NONAME ?OnDestroy@CSrmmBaseDialog@@MAEXXZ @441 NONAME +Chat_AddMenuItems @442 NONAME +Chat_DestroyGCMenu @443 NONAME +Chat_CreateGCMenu @444 NONAME diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 79a966ee14..01e2359241 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -436,3 +436,6 @@ Chat_UpdateOptions @418 NONAME ?WndProc_Nicklist@CSrmmBaseDialog@@UEAA_JI_K_J@Z @439 NONAME ?onDblClick_List@CSrmmBaseDialog@@IEAAXPEAVCCtrlListBox@@@Z @440 NONAME ?OnDestroy@CSrmmBaseDialog@@MEAAXXZ @441 NONAME +Chat_AddMenuItems @442 NONAME +Chat_DestroyGCMenu @443 NONAME +Chat_CreateGCMenu @444 NONAME diff --git a/src/mir_app/src/resource.h b/src/mir_app/src/resource.h index 30d9aed425..a224363be6 100644 --- a/src/mir_app/src/resource.h +++ b/src/mir_app/src/resource.h @@ -585,7 +585,7 @@ #define POPUP_GROUPHIDEOFFLINE 40006 #define POPUP_HIDEOFFLINEROOT 40007 #define POPUP_DISABLEGROUPS 40008 -#define IDC_SENDMESSAGE 40009 +#define IDM_SENDMESSAGE 40009 #define IDM_COPYALL 40011 #define IDM_SELECTALL 40012 #define IDM_CLEAR 40013 diff --git a/src/mir_app/src/searchresults.cpp b/src/mir_app/src/searchresults.cpp index 98ab3d797c..d5760e2121 100644 --- a/src/mir_app/src/searchresults.cpp +++ b/src/mir_app/src/searchresults.cpp @@ -367,7 +367,7 @@ void ShowMoreOptionsMenu(HWND hwndDlg, int x, int y) CallService(MS_USERINFO_SHOWDIALOG, hContact, 0); } break; - case IDC_SENDMESSAGE: + case IDM_SENDMESSAGE: { MCONTACT hContact = (MCONTACT)CallProtoServiceInt(0, lsr->szProto, PS_ADDTOLIST, PALF_TEMPORARY, (LPARAM)&lsr->psr); CallService(MS_MSG_SENDMESSAGE, hContact, 0); diff --git a/src/mir_app/src/srmm_base.cpp b/src/mir_app/src/srmm_base.cpp index 41ff060148..f5dd07a69e 100644 --- a/src/mir_app/src/srmm_base.cpp +++ b/src/mir_app/src/srmm_base.cpp @@ -26,8 +26,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "chat.h" #include -extern HCURSOR g_hCurHyperlinkHand; - CSrmmBaseDialog::CSrmmBaseDialog(HINSTANCE hInst, int idDialog, SESSION_INFO *si) : CDlgBase(hInst, idDialog), m_log(this, IDC_SRMM_LOG), @@ -157,8 +155,6 @@ static LRESULT CALLBACK stubMessageProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR return mir_callNextSubclass(hwnd, stubMessageProc, msg, wParam, lParam); } -///////////////////////////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////////////////////// // process mouse - hovering for the nickname list.fires events so the protocol can // show the userinfo - tooltip. -- cgit v1.2.3