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 /plugins/TabSRMM | |
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 'plugins/TabSRMM')
-rw-r--r-- | plugins/TabSRMM/src/chat.h | 2 | ||||
-rw-r--r-- | plugins/TabSRMM/src/chat_main.cpp | 17 | ||||
-rw-r--r-- | plugins/TabSRMM/src/chat_tools.cpp | 98 | ||||
-rw-r--r-- | plugins/TabSRMM/src/chat_window.cpp | 21 |
4 files changed, 28 insertions, 110 deletions
diff --git a/plugins/TabSRMM/src/chat.h b/plugins/TabSRMM/src/chat.h index e9947ed8b3..e9f7b1ce0c 100644 --- a/plugins/TabSRMM/src/chat.h +++ b/plugins/TabSRMM/src/chat.h @@ -131,8 +131,6 @@ wchar_t* my_strstri(const wchar_t* s1, const wchar_t* s2); int GetRichTextLength(HWND hwnd);
bool IsHighlighted(SESSION_INFO *si, GCEVENT *pszText);
char GetIndicator(SESSION_INFO *si, LPCTSTR ptszNick, int *iNickIndex);
-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 Chat_SetFilters(SESSION_INFO *si);
void DoFlashAndSoundWorker(FLASH_PARAMS* p);
BOOL DoPopup(SESSION_INFO *si, GCEVENT* gce);
diff --git a/plugins/TabSRMM/src/chat_main.cpp b/plugins/TabSRMM/src/chat_main.cpp index 626c5aea5c..bbc0162b93 100644 --- a/plugins/TabSRMM/src/chat_main.cpp +++ b/plugins/TabSRMM/src/chat_main.cpp @@ -206,6 +206,22 @@ static void CheckUpdate() db_set_b(0, "Compatibility", "TabChatFonts", 3);
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static gc_item tabItems[] =
+{
+ { TranslateT("Highlight user..."), 20020, MENU_ITEM }
+};
+
+static int OnCreateGCMenu(WPARAM, LPARAM lParam)
+{
+ GCMENUITEMS *gcitems = (GCMENUITEMS*)lParam;
+ if (gcitems->Type == MENU_ON_NICKLIST)
+ Chat_AddMenuItems(gcitems->hMenu, _countof(tabItems), tabItems);
+
+ return 0;
+}
+
// load the module
int Chat_Load()
{
@@ -239,6 +255,7 @@ int Chat_Load() g_hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_MENU));
+ HookEvent(ME_GC_BUILDMENU, OnCreateGCMenu);
g_Settings.Highlight = new CMUCHighlight();
return 0;
}
diff --git a/plugins/TabSRMM/src/chat_tools.cpp b/plugins/TabSRMM/src/chat_tools.cpp index 99f121c538..a3fe2d7e42 100644 --- a/plugins/TabSRMM/src/chat_tools.cpp +++ b/plugins/TabSRMM/src/chat_tools.cpp @@ -503,104 +503,6 @@ BOOL LogToFile(SESSION_INFO *si, GCEVENT *gce) return oldLogToFile(si, gce); // call kernel method
}
-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 = { 0 };
- 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, nullptr);
- 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, nullptr);
- }
-
- 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
- wcsncpy_s(szTemp, TranslateT("&Message"), _TRUNCATE);
-
- if (mir_wstrlen(szTemp) > 40)
- wcsncpy_s(szTemp + 40, 4, L"...", _TRUNCATE);
- 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);
- }
-
- if (iIndex == 0) {
- AppendMenu(*hMenu, MF_SEPARATOR, 0, 0);
- int pos = GetMenuItemCount(*hMenu);
- InsertMenu(*hMenu, pos, MF_BYPOSITION, (UINT_PTR)20020, TranslateT("Highlight user..."));
- }
-
- return TrackPopupMenu(*hMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwndDlg, 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);
- }
-}
-
/*
* set all filters and notification config for a session
* uses per channel mask + filterbits, default config as backup
diff --git a/plugins/TabSRMM/src/chat_window.cpp b/plugins/TabSRMM/src/chat_window.cpp index e147e83d2f..d5aa212c48 100644 --- a/plugins/TabSRMM/src/chat_window.cpp +++ b/plugins/TabSRMM/src/chat_window.cpp @@ -1606,14 +1606,14 @@ LRESULT CChatRoomDlg::WndProc_Nicklist(UINT msg, WPARAM wParam, LPARAM lParam) USERINFO *ui = pci->SM_GetUserFromIndex(si->ptszID, si->pszModule, 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, si, uinew.pszUID, uinew.pszNick); + UINT uID = Chat_CreateGCMenu(m_nickList.GetHwnd(), hMenu, hti.pt, si, uinew.pszUID, uinew.pszNick); switch (uID) { case 0: break; @@ -1639,7 +1639,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; } } @@ -2174,8 +2174,8 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) } } - 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); @@ -2213,7 +2213,7 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) break; } - DestroyGCMenu(&hMenu, 5); + Chat_DestroyGCMenu(hMenu, 5); } } break; @@ -2248,8 +2248,8 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) // clicked a nick name if (g_Settings.bClickableNicks) { if (msg == WM_RBUTTONDOWN) { - HMENU hMenu = 0; - USERINFO uiNew; + HMENU hMenu = GetSubMenu(g_hMenu, 0); + for (USERINFO *ui = m_si->pUsers; ui; ui = ui->next) { if (mir_wstrcmp(ui->pszNick, tr.lpstrText)) continue; @@ -2257,8 +2257,9 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) pt.x = (short)LOWORD(((ENLINK*)lParam)->lParam); pt.y = (short)HIWORD(((ENLINK*)lParam)->lParam); ClientToScreen(((NMHDR*)lParam)->hwndFrom, &pt); + USERINFO uiNew; memcpy(&uiNew, ui, sizeof(USERINFO)); - UINT uID = CreateGCMenu(m_hwnd, &hMenu, 0, pt, m_si, uiNew.pszUID, uiNew.pszNick); + UINT uID = Chat_CreateGCMenu(m_hwnd, hMenu, pt, m_si, uiNew.pszUID, uiNew.pszNick); switch (uID) { case 0: break; @@ -2271,7 +2272,7 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) DoEventHook(GC_USER_NICKLISTMENU, ui, nullptr, (LPARAM)uID); break; } - DestroyGCMenu(&hMenu, 1); + Chat_DestroyGCMenu(hMenu, 1); return TRUE; } return TRUE; |