From 81c4c58099694dec4a7234b6c6028d478f08262f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 20 Sep 2024 15:55:30 +0300 Subject: fixes #4686 (tabSRMM: group chat windows to use the same activation options like the private chats do) --- plugins/TabSRMM/src/chat_main.cpp | 132 +++------------------------------- plugins/TabSRMM/src/chat_options.cpp | 1 - plugins/TabSRMM/src/chat_tools.cpp | 15 ++-- plugins/TabSRMM/src/container.cpp | 25 ++----- plugins/TabSRMM/src/functions.h | 13 +++- plugins/TabSRMM/src/hotkeyhandler.cpp | 11 ++- plugins/TabSRMM/src/msgs.cpp | 38 +++++++--- plugins/TabSRMM/src/msgs.h | 2 +- plugins/TabSRMM/src/srmm.cpp | 1 - 9 files changed, 70 insertions(+), 168 deletions(-) (limited to 'plugins/TabSRMM') diff --git a/plugins/TabSRMM/src/chat_main.cpp b/plugins/TabSRMM/src/chat_main.cpp index fd0fd38494..8c53bc0fb4 100644 --- a/plugins/TabSRMM/src/chat_main.cpp +++ b/plugins/TabSRMM/src/chat_main.cpp @@ -198,132 +198,20 @@ static void CheckUpdate() void ShowRoom(TContainerData *pContainer, SESSION_INFO *si) { - if (si == nullptr) - return; - - if (si->pDlg != nullptr) { - si->pDlg->ActivateTab(); - return; - } - - wchar_t szName[CONTAINER_NAMELEN + 2]; szName[0] = 0; - - if (pContainer == nullptr) - if (si->pDlg != nullptr) - pContainer = si->pDlg->m_pContainer; - - if (pContainer == nullptr) { - GetContainerNameForContact(si->hContact, szName, CONTAINER_NAMELEN); - if (!g_plugin.bOpenInDefault && !mir_wstrcmp(szName, L"default")) - wcsncpy_s(szName, L"Chat Rooms", _TRUNCATE); - szName[CONTAINER_NAMELEN] = 0; - pContainer = FindContainerByName(szName); - } - - if (pContainer == nullptr) - pContainer = CreateContainer(szName, FALSE, si->hContact); - if (pContainer == nullptr) - return; // smth went wrong, nothing to do here - - MCONTACT hContact = si->hContact; - if (Srmm_FindWindow(hContact) != nullptr) - return; - - if (hContact != 0 && M.GetByte("limittabs", 0) && !wcsncmp(pContainer->m_wszName, L"default", 6)) - if ((pContainer = FindMatchingContainer(L"default")) == nullptr) - if ((pContainer = CreateContainer(L"default", CNT_CREATEFLAG_CLONED, hContact)) == nullptr) - return; - - wchar_t *contactName = Clist_GetContactDisplayName(hContact); - - // cut nickname if larger than x chars... - wchar_t newcontactname[128]; - if (mir_wstrlen(contactName) > 0) { - if (M.GetByte("cuttitle", 0)) - CutContactName(contactName, newcontactname, _countof(newcontactname)); - else - wcsncpy_s(newcontactname, contactName, _TRUNCATE); - } - else wcsncpy_s(newcontactname, L"_U_", _TRUNCATE); - - // hide the active tab - if (pContainer->m_hwndActive) - ShowWindow(pContainer->m_hwndActive, SW_HIDE); - - int iTabIndex_wanted = M.GetDword(hContact, "tabindex", pContainer->m_iChilds * 100); - int iCount = TabCtrl_GetItemCount(pContainer->m_hwndTabs); - - pContainer->m_iTabIndex = iCount; - if (iCount > 0) { - for (int i = iCount - 1; i >= 0; i--) { - HWND hwnd = GetTabWindow(pContainer->m_hwndTabs, i); - CMsgDialog *dat = (CMsgDialog *)GetWindowLongPtr(hwnd, GWLP_USERDATA); - if (dat) { - int relPos = M.GetDword(dat->m_hContact, "tabindex", i * 100); - if (iTabIndex_wanted <= relPos) - pContainer->m_iTabIndex = i; - } - } - } - - TCITEM item = {}; - item.pszText = newcontactname; - item.mask = TCIF_TEXT | TCIF_IMAGE; - int iTabId = TabCtrl_InsertItem(pContainer->m_hwndTabs, pContainer->m_iTabIndex, &item); - - SendMessage(pContainer->m_hwndTabs, EM_REFRESHWITHOUTCLIP, 0, 0); - TabCtrl_SetCurSel(pContainer->m_hwndTabs, iTabId); - pContainer->m_iChilds++; - - CMsgDialog *pDlg = new CMsgDialog(si); - pDlg->m_iTabID = iTabId; - pDlg->m_pContainer = pContainer; - pDlg->SetParent(pContainer->m_hwndTabs); - pDlg->Create(); - - HWND hwndNew = pDlg->GetHwnd(); - item.lParam = (LPARAM)hwndNew; - TabCtrl_SetItem(pContainer->m_hwndTabs, iTabId, &item); - - if (pContainer->cfg.flags.m_bSideBar) - pContainer->m_pSideBar->addSession(pDlg, pContainer->m_iTabIndex); - - SendMessage(pContainer->m_hwnd, WM_SIZE, 0, 0); - // if the container is minimized, then pop it up... - if (IsIconic(pContainer->m_hwnd)) { - SendMessage(pContainer->m_hwnd, WM_SYSCOMMAND, SC_RESTORE, 0); - SetFocus(pContainer->m_hwndActive); - } - - if (g_plugin.bHideOnClose && !IsWindowVisible(pContainer->m_hwnd)) { - WINDOWPLACEMENT wp = { 0 }; - wp.length = sizeof(wp); - GetWindowPlacement(pContainer->m_hwnd, &wp); - - pContainer->BroadCastContainer(DM_CHECKSIZE, 0, 0); // make sure all tabs will re-check layout on activation - if (wp.showCmd == SW_SHOWMAXIMIZED) - ShowWindow(pContainer->m_hwnd, SW_SHOWMAXIMIZED); - else { - ShowWindow(pContainer->m_hwnd, SW_SHOWNORMAL); - } - SendMessage(pContainer->m_hwndActive, WM_SIZE, 0, 0); - SetFocus(hwndNew); - } - else { - SetFocus(hwndNew); - RedrawWindow(pContainer->m_hwnd, nullptr, nullptr, RDW_INVALIDATE); - UpdateWindow(pContainer->m_hwnd); - if (GetForegroundWindow() != pContainer->m_hwnd) - SetForegroundWindow(pContainer->m_hwnd); - } - - if (IsWinVer7Plus() && PluginConfig.m_useAeroPeek && CSkin::m_skinEnabled && !M.GetByte("forceAeroPeek", 0)) - CWarning::show(CWarning::WARN_AEROPEEK_SKIN, MB_ICONWARNING | MB_OK); + if (si) + AutoCreateWindow(pContainer, si->hContact, 0); } static void stubShowRoom(SESSION_INFO *si) { - ShowRoom(nullptr, si); + if (!si) + return; + + // when a group chat window is popped up from dblclick, we always activate it + if (si->pDlg) + si->pDlg->ActivateTab(); + else + AutoCreateWindow(nullptr, si->hContact, 0, true); } static MODULEINFO* MM_CreateModule() diff --git a/plugins/TabSRMM/src/chat_options.cpp b/plugins/TabSRMM/src/chat_options.cpp index df55931612..01018d63b3 100644 --- a/plugins/TabSRMM/src/chat_options.cpp +++ b/plugins/TabSRMM/src/chat_options.cpp @@ -506,7 +506,6 @@ public: treeCheck.AddOption(pwszSection, LPGENW("Flash window when someone speaks"), Chat::bFlashWindow); treeCheck.AddOption(pwszSection, LPGENW("Flash window when a word is highlighted"), Chat::bFlashWindowHighlight); treeCheck.AddOption(pwszSection, LPGENW("Create tabs or windows for highlight events"), g_plugin.bCreateWindowOnHighlight); - treeCheck.AddOption(pwszSection, LPGENW("Activate chat window on highlight"), g_plugin.bAnnoyingHighlight); treeCheck.AddOption(pwszSection, LPGENW("Show list of users in the chat room"), Chat::bShowNicklist); treeCheck.AddOption(pwszSection, LPGENW("Colorize nicknames in member list (you need to adjust colors)"), g_plugin.bColorizeNicks); treeCheck.AddOption(pwszSection, LPGENW("Show topic as status message on the contact list"), Chat::bTopicOnClist); diff --git a/plugins/TabSRMM/src/chat_tools.cpp b/plugins/TabSRMM/src/chat_tools.cpp index 6794116bda..e09c6ff4a0 100644 --- a/plugins/TabSRMM/src/chat_tools.cpp +++ b/plugins/TabSRMM/src/chat_tools.cpp @@ -223,17 +223,12 @@ BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight if (Chat::bFlashWindowHighlight && bInactive) bMustFlash = true; - bMustAutoswitch = true; + bMustAutoswitch = g_plugin.bAutoSwitchTabs; if (g_plugin.bCreateWindowOnHighlight && dat == nullptr) { - Clist_ContactDoubleClicked(si->hContact); - bActiveTab = true; - bInactive = bMustAutoswitch = bMustFlash = false; - } - - if (dat && g_plugin.bAnnoyingHighlight && bInactive && dat->m_pContainer->m_hwnd != GetForegroundWindow()) { - bActiveTab = true; - bInactive = bMustAutoswitch = bMustFlash = false; - dat->ActivateTab(); + ShowRoom(0, si); + dat = si->pDlg; + bInactive = (dat) ? !dat->IsActive() : true; + bMustFlash = false; } } else { diff --git a/plugins/TabSRMM/src/container.cpp b/plugins/TabSRMM/src/container.cpp index f155dc4bba..c51ea191c2 100644 --- a/plugins/TabSRMM/src/container.cpp +++ b/plugins/TabSRMM/src/container.cpp @@ -2292,7 +2292,7 @@ int TSAPI ActivateTabFromHWND(HWND hwndTab, HWND hwnd) ///////////////////////////////////////////////////////////////////////////////////////// -void TSAPI AutoCreateWindow(MCONTACT hContact, MEVENT hDbEvent) +CMsgDialog* TSAPI AutoCreateWindow(TContainerData *pContainer, MCONTACT hContact, MEVENT hDbEvent, bool bActivate) { wchar_t szName[CONTAINER_NAMELEN + 1]; GetContainerNameForContact(hContact, szName, CONTAINER_NAMELEN); @@ -2315,16 +2315,15 @@ void TSAPI AutoCreateWindow(MCONTACT hContact, MEVENT hDbEvent) } if (bAllowAutoCreate && (g_plugin.bAutoPopup || g_plugin.bAutoTabs)) { + if (pContainer == nullptr) + pContainer = FindContainerByName(szName); + if (g_plugin.bAutoPopup) { - TContainerData *pContainer = FindContainerByName(szName); if (pContainer == nullptr) pContainer = CreateContainer(szName, 0, hContact); - if (pContainer) - CreateNewTabForContact(pContainer, hContact, true, true, false); - return; + return CreateNewTabForContact(pContainer, hContact, true, true); } - TContainerData *pContainer = FindContainerByName(szName); if (pContainer != nullptr) if (M.GetByte("limittabs", 0) && !wcsncmp(pContainer->m_wszName, L"default", 6)) pContainer = FindMatchingContainer(L"default"); @@ -2332,20 +2331,10 @@ void TSAPI AutoCreateWindow(MCONTACT hContact, MEVENT hDbEvent) if (pContainer == nullptr && g_plugin.bAutoContainer) pContainer = CreateContainer(szName, CNT_CREATEFLAG_MINIMIZED, hContact); - if (pContainer != nullptr) { - CreateNewTabForContact(pContainer, hContact, false, g_plugin.bPopupContainer, true, hDbEvent); - return; - } + return CreateNewTabForContact(pContainer, hContact, bActivate, g_plugin.bPopupContainer, hDbEvent); } - // no window created, simply add an unread event to contact list - DBEVENTINFO dbei = {}; - db_event_get(hDbEvent, &dbei); - - if (!(dbei.flags & DBEF_READ)) { - AddUnreadContact(hContact); - Srmm_AddEvent(hContact, hDbEvent); - } + return nullptr; } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/plugins/TabSRMM/src/functions.h b/plugins/TabSRMM/src/functions.h index 4e2dc6daf0..062d7ac829 100644 --- a/plugins/TabSRMM/src/functions.h +++ b/plugins/TabSRMM/src/functions.h @@ -48,7 +48,15 @@ LONG_PTR CALLBACK HotkeyHandlerDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP * gneric msgwindow functions(creation, container management etc.) */ -void TSAPI CreateNewTabForContact(TContainerData *pContainer, MCONTACT hContact, bool bActivateTAb, bool bPopupContainer, bool bWantPopup, MEVENT hdbEvent = 0, bool bIsWchar = false, const char *pszInitialText = nullptr); +CMsgDialog* TSAPI CreateNewTabForContact( + TContainerData *pContainer, + MCONTACT hContact, + bool bActivateTAb, + bool bPopupContainer, + MEVENT hdbEvent = 0, + bool bIsWchar = false, + const char *pszInitialText = nullptr); + int TSAPI ActivateTabFromHWND(HWND hwndTab, HWND hwnd); void TSAPI CreateImageList(bool bInitial); @@ -56,13 +64,14 @@ TContainerData* TSAPI FindMatchingContainer(const wchar_t *szName); TContainerData* TSAPI CreateContainer(const wchar_t *name, int iTemp, MCONTACT hContactFrom); TContainerData* TSAPI FindContainerByName(const wchar_t *name); +CMsgDialog* TSAPI AutoCreateWindow(TContainerData*, MCONTACT, MEVENT, bool bActivate = false); + int TSAPI GetTabIndexFromHWND(HWND hwndTab, HWND hwnd); HWND TSAPI GetTabWindow(HWND hwndTab, int idx); int TSAPI GetTabItemFromMouse(HWND hwndTab, POINT *pt); void TSAPI CloseOtherTabs(HWND hwndTab, CMsgDialog &dat); int TSAPI ActivateTabFromHWND(HWND hwndTab, HWND hwnd); -void TSAPI AutoCreateWindow(MCONTACT, MEVENT); void TSAPI CloseAllContainers(); void TSAPI DeleteContainer(int iIndex); void TSAPI RenameContainer(int iIndex, const wchar_t *newName); diff --git a/plugins/TabSRMM/src/hotkeyhandler.cpp b/plugins/TabSRMM/src/hotkeyhandler.cpp index c7caef5c92..706a3d6192 100644 --- a/plugins/TabSRMM/src/hotkeyhandler.cpp +++ b/plugins/TabSRMM/src/hotkeyhandler.cpp @@ -225,7 +225,14 @@ LONG_PTR CALLBACK HotkeyHandlerDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP break; case DM_CREATECONTAINER: - AutoCreateWindow(wParam, lParam); + if (!AutoCreateWindow(0, wParam, lParam)) { + // no window created, simply add an unread event to contact list + DB::EventInfo dbei(lParam, false); + if (dbei && !(dbei.flags & DBEF_READ)) { + AddUnreadContact(wParam); + Srmm_AddEvent(wParam, lParam); + } + } break; case DM_DOCREATETAB: @@ -244,7 +251,7 @@ LONG_PTR CALLBACK HotkeyHandlerDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP if (szProto != nullptr && Contact::IsGroupChat(lParam, szProto)) ShowRoom((TContainerData*)wParam, SM_FindSessionByHCONTACT(lParam)); else - CreateNewTabForContact((TContainerData*)wParam, lParam, true, true, false); + CreateNewTabForContact((TContainerData*)wParam, lParam, true, true); } } } diff --git a/plugins/TabSRMM/src/msgs.cpp b/plugins/TabSRMM/src/msgs.cpp index e02f0035fd..50a897dc0c 100644 --- a/plugins/TabSRMM/src/msgs.cpp +++ b/plugins/TabSRMM/src/msgs.cpp @@ -115,7 +115,7 @@ static INT_PTR ReadMessageCommand(WPARAM, LPARAM lParam) if (pContainer == nullptr) pContainer = CreateContainer(szName, FALSE, hContact); if (pContainer) - CreateNewTabForContact(pContainer, hContact, true, true, false, 0); + CreateNewTabForContact(pContainer, hContact, true, true, 0); } return 0; } @@ -164,7 +164,7 @@ INT_PTR SendMessageCommand_Worker(MCONTACT hContact, LPCSTR pszMsg, bool isWchar if (pContainer == nullptr) pContainer = CreateContainer(szName, FALSE, hContact); if (pContainer) - CreateNewTabForContact(pContainer, hContact, true, true, false, 0, isWchar, pszMsg); + CreateNewTabForContact(pContainer, hContact, true, true, 0, isWchar, pszMsg); } return 0; } @@ -245,23 +245,33 @@ int MyAvatarChanged(WPARAM wParam, LPARAM lParam) // bActivateTab: make the new tab the active one // bPopupContainer: restore container if it was minimized, otherwise flash it... -void TSAPI CreateNewTabForContact(TContainerData *pContainer, MCONTACT hContact, bool bActivateTab, bool bPopupContainer, bool bWantPopup, MEVENT hdbEvent, bool bIsUnicode, const char *pszInitialText) +CMsgDialog* TSAPI CreateNewTabForContact( + TContainerData *pContainer, + MCONTACT hContact, + bool bActivateTab, + bool bPopupContainer, + MEVENT hdbEvent, + bool bIsUnicode, + const char *pszInitialText) { + if (pContainer == nullptr) + return nullptr; + if (hContact == 0) { _DebugPopup(hContact, L"Warning: trying to create a window for empty contact"); - return; + return nullptr; } if (Srmm_FindWindow(hContact) != nullptr) { _DebugPopup(hContact, L"Warning: trying to create duplicate window"); - return ; + return nullptr; } // if we have a max # of tabs/container set and want to open something in the default container... if (M.GetByte("limittabs", 0) && !wcsncmp(pContainer->m_wszName, L"default", 6)) if ((pContainer = FindMatchingContainer(L"default")) == nullptr) if ((pContainer = CreateContainer(L"default", CNT_CREATEFLAG_CLONED, hContact)) == nullptr) - return; + return nullptr; char *szProto = Proto_GetBaseAccountName(hContact); @@ -298,7 +308,7 @@ void TSAPI CreateNewTabForContact(TContainerData *pContainer, MCONTACT hContact, if (iCount > 0) { for (int i = iCount - 1; i >= 0; i--) { HWND hwnd = GetTabWindow(pContainer->m_hwndTabs, i); - CMsgDialog *dat = (CMsgDialog*)GetWindowLongPtr(hwnd, GWLP_USERDATA); + CMsgDialog *dat = (CMsgDialog *)GetWindowLongPtr(hwnd, GWLP_USERDATA); if (dat) { int relPos = M.GetDword(dat->m_hContact, "tabindex", i * 100); if (iTabIndex_wanted <= relPos) @@ -317,17 +327,21 @@ void TSAPI CreateNewTabForContact(TContainerData *pContainer, MCONTACT hContact, SendMessage(pContainer->m_hwndTabs, EM_REFRESHWITHOUTCLIP, 0, 0); if (bActivateTab) TabCtrl_SetCurSel(pContainer->m_hwndTabs, iTabId); - - CMsgDialog *pWindow = new CMsgDialog(IDD_MSGSPLITNEW, hContact); + + CMsgDialog *pWindow; + if (Contact::IsGroupChat(hContact)) + pWindow = new CMsgDialog(Chat_Find(hContact, szProto)); + else + pWindow = new CMsgDialog(IDD_MSGSPLITNEW, hContact); pWindow->m_iTabID = iTabId; pWindow->m_pContainer = pContainer; pContainer->m_iChilds++; pWindow->m_bActivate = bActivateTab; - pWindow->m_bWantPopup = bWantPopup; + pWindow->m_bWantPopup = !bActivateTab; pWindow->m_hDbEventFirst = hdbEvent; if (pszInitialText) - pWindow->wszInitialText = (bIsUnicode) ? mir_wstrdup((const wchar_t*)pszInitialText) : mir_a2u(pszInitialText); + pWindow->wszInitialText = (bIsUnicode) ? mir_wstrdup((const wchar_t *)pszInitialText) : mir_a2u(pszInitialText); pWindow->SetParent(pContainer->m_hwndTabs); pWindow->Create(); @@ -388,6 +402,8 @@ void TSAPI CreateNewTabForContact(TContainerData *pContainer, MCONTACT hContact, if (ServiceExists(MS_HPP_EG_EVENT) && ServiceExists(MS_IEVIEW_EVENT) && db_get_b(0, "HistoryPlusPlus", "IEViewAPI", 0)) if (IDYES == CWarning::show(CWarning::WARN_HPP_APICHECK, MB_ICONWARNING | MB_YESNO)) db_set_b(0, "HistoryPlusPlus", "IEViewAPI", 0); + + return pWindow; } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/plugins/TabSRMM/src/msgs.h b/plugins/TabSRMM/src/msgs.h index 106ae689b6..acc98e2e62 100644 --- a/plugins/TabSRMM/src/msgs.h +++ b/plugins/TabSRMM/src/msgs.h @@ -1041,7 +1041,7 @@ struct CMPlugin : public PLUGIN // chat settings CMOption bOpenInDefault, bCreateWindowOnHighlight, bBBCodeInPopups; - CMOption bLogClassicIndicators, bAlternativeSorting, bAnnoyingHighlight; + CMOption bLogClassicIndicators, bAlternativeSorting; CMOption bLogSymbols, bClassicIndicators, bClickableNicks, bColorizeNicks, bColorizeNicksInLog; CMOption bScaleIcons, bNewLineAfterNames; diff --git a/plugins/TabSRMM/src/srmm.cpp b/plugins/TabSRMM/src/srmm.cpp index f594448dbf..228b8e936d 100644 --- a/plugins/TabSRMM/src/srmm.cpp +++ b/plugins/TabSRMM/src/srmm.cpp @@ -90,7 +90,6 @@ CMPlugin::CMPlugin() : bClassicIndicators(CHAT_MODULE, "ClassicIndicators", false), bLogClassicIndicators(CHAT_MODULE, "LogClassicIndicators", false), bAlternativeSorting(CHAT_MODULE, "AlternativeSorting", true), - bAnnoyingHighlight(CHAT_MODULE, "AnnoyingHighlight", false), bLogSymbols(CHAT_MODULE, "LogSymbols", true), bClickableNicks(CHAT_MODULE, "ClickableNicks", true), bColorizeNicks(CHAT_MODULE, "ColorizeNicks", true), -- cgit v1.2.3