summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-03-24 15:38:17 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-03-24 15:38:17 +0300
commite84bafdd3f3d2eb67e10a9bd3fbe600748962b6f (patch)
tree1b563061e473ef8bbe62b86821da21c319cca2c5 /src/core
parentaa55162ab85df5aa0ac6b87711bfee222b3222dd (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/core')
-rw-r--r--src/core/stdmsg/src/chat_util.cpp90
-rw-r--r--src/core/stdmsg/src/chat_window.cpp12
-rw-r--r--src/core/stdmsg/src/stdafx.h2
3 files changed, 6 insertions, 98 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);