diff options
author | George Hazan <ghazan@miranda.im> | 2017-03-24 15:38:17 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-03-24 15:38:17 +0300 |
commit | e84bafdd3f3d2eb67e10a9bd3fbe600748962b6f (patch) | |
tree | 1b563061e473ef8bbe62b86821da21c319cca2c5 /src | |
parent | aa55162ab85df5aa0ac6b87711bfee222b3222dd (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/core/stdmsg/src/chat_util.cpp | 90 | ||||
-rw-r--r-- | src/core/stdmsg/src/chat_window.cpp | 12 | ||||
-rw-r--r-- | src/core/stdmsg/src/stdafx.h | 2 | ||||
-rw-r--r-- | src/mir_app/res/resource.rc | 2 | ||||
-rw-r--r-- | src/mir_app/src/chat.h | 6 | ||||
-rw-r--r-- | src/mir_app/src/chat_tools.cpp | 93 | ||||
-rw-r--r-- | src/mir_app/src/mir_app.def | 3 | ||||
-rw-r--r-- | src/mir_app/src/mir_app64.def | 3 | ||||
-rw-r--r-- | src/mir_app/src/resource.h | 2 | ||||
-rw-r--r-- | src/mir_app/src/searchresults.cpp | 2 | ||||
-rw-r--r-- | src/mir_app/src/srmm_base.cpp | 4 |
11 files changed, 109 insertions, 110 deletions
diff --git a/src/core/stdmsg/src/chat_util.cpp b/src/core/stdmsg/src/chat_util.cpp index 602c2c14c5..5dff47b878 100644 --- a/src/core/stdmsg/src/chat_util.cpp +++ b/src/core/stdmsg/src/chat_util.cpp @@ -187,96 +187,6 @@ void CheckColorsInModule(const char* pszModule) } } -UINT CreateGCMenu(HWND hwndDlg, HMENU *hMenu, int iIndex, POINT pt, SESSION_INFO *si, wchar_t* pszUID, wchar_t* pszWordText) -{ - HMENU hSubMenu = 0; - *hMenu = GetSubMenu(g_hMenu, iIndex); - TranslateMenu(*hMenu); - - GCMENUITEMS gcmi = {}; - gcmi.pszID = si->ptszID; - gcmi.pszModule = si->pszModule; - gcmi.pszUID = pszUID; - - if (iIndex == 1) { - int i = GetRichTextLength(GetDlgItem(hwndDlg, IDC_SRMM_LOG)); - - EnableMenuItem(*hMenu, ID_CLEARLOG, MF_ENABLED); - EnableMenuItem(*hMenu, ID_COPYALL, MF_ENABLED); - ModifyMenu(*hMenu, 4, MF_GRAYED | MF_BYPOSITION, 4, NULL); - if (!i) { - EnableMenuItem(*hMenu, ID_COPYALL, MF_BYCOMMAND | MF_GRAYED); - EnableMenuItem(*hMenu, ID_CLEARLOG, MF_BYCOMMAND | MF_GRAYED); - if (pszWordText && pszWordText[0]) - ModifyMenu(*hMenu, 4, MF_ENABLED | MF_BYPOSITION, 4, NULL); - } - - 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 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_wstrcpy(szTemp + 40, L"..."); - 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, hwndDlg, NULL); -} - -void DestroyGCMenu(HMENU *hMenu, int iIndex) -{ - MENUITEMINFO mii = {}; - mii.cbSize = sizeof(mii); - mii.fMask = MIIM_SUBMENU; - while (GetMenuItemInfo(*hMenu, iIndex, TRUE, &mii)) { - if (mii.hSubMenu != NULL) - DestroyMenu(mii.hSubMenu); - RemoveMenu(*hMenu, iIndex, MF_BYPOSITION); - } -} - void ValidateFilename(wchar_t *filename) { wchar_t *p1 = filename; diff --git a/src/core/stdmsg/src/chat_window.cpp b/src/core/stdmsg/src/chat_window.cpp index 96bef14272..bac422eb9a 100644 --- a/src/core/stdmsg/src/chat_window.cpp +++ b/src/core/stdmsg/src/chat_window.cpp @@ -1017,8 +1017,8 @@ LRESULT CChatRoomDlg::WndProc_Nicklist(UINT msg, WPARAM wParam, LPARAM lParam) hti.pt.y += height - 4; ClientToScreen(m_nickList.GetHwnd(), &hti.pt); - HMENU hMenu = 0; - UINT uID = CreateGCMenu(m_nickList.GetHwnd(), &hMenu, 0, hti.pt, m_si, uinew.pszUID, uinew.pszNick); + HMENU hMenu = GetSubMenu(g_hMenu, 0); + UINT uID = Chat_CreateGCMenu(m_nickList.GetHwnd(), hMenu, hti.pt, m_si, uinew.pszUID, uinew.pszNick); switch (uID) { case 0: break; @@ -1031,7 +1031,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; } } @@ -1254,8 +1254,8 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) } CHARRANGE all = { 0, -1 }; - HMENU hMenu = 0; - UINT uID = CreateGCMenu(m_hwnd, &hMenu, 1, pt, m_si, nullptr, pszWord); + HMENU hMenu = GetSubMenu(g_hMenu, 1); + UINT uID = Chat_CreateGCMenu(m_hwnd, hMenu, pt, m_si, nullptr, pszWord); switch (uID) { case 0: PostMessage(m_hwnd, WM_MOUSEACTIVATE, 0, 0); @@ -1303,7 +1303,7 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) DoEventHook(GC_USER_LOGMENU, nullptr, nullptr, uID); break; } - DestroyGCMenu(&hMenu, 5); + Chat_DestroyGCMenu(hMenu, 5); } break; diff --git a/src/core/stdmsg/src/stdafx.h b/src/core/stdmsg/src/stdafx.h index 08f35ac924..6ea8005aa1 100644 --- a/src/core/stdmsg/src/stdafx.h +++ b/src/core/stdmsg/src/stdafx.h @@ -147,8 +147,6 @@ void ShowRoom(SESSION_INFO *si); int GetColorIndex(const char* pszModule, COLORREF cr);
void CheckColorsInModule(const char* pszModule);
int GetRichTextLength(HWND hwnd);
-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);
void SetButtonsPos(HWND hwndDlg, bool bIsChat);
int RestoreWindowPosition(HWND hwnd, MCONTACT hContact, bool bHide);
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<SESSION_INFO> 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 <m_history.h> -extern HCURSOR g_hCurHyperlinkHand; - CSrmmBaseDialog::CSrmmBaseDialog(HINSTANCE hInst, int idDialog, SESSION_INFO *si) : CDlgBase(hInst, idDialog), m_log(this, IDC_SRMM_LOG), @@ -158,8 +156,6 @@ static LRESULT CALLBACK stubMessageProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR } ///////////////////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////////////////// // process mouse - hovering for the nickname list.fires events so the protocol can // show the userinfo - tooltip. |