summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-02-04 19:53:21 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-02-04 19:53:21 +0300
commit2a00f9bf6c008f2e908a34fe040b6ab342884a82 (patch)
tree0e680942c405bed5605b00f22839e1a2b140cc27
parentcf4bff42f8a3dbf18623d8df599849399a6165a7 (diff)
final fix for #2184
-rw-r--r--plugins/TabSRMM/src/chat_main.cpp2
-rw-r--r--plugins/TabSRMM/src/container.cpp47
-rw-r--r--plugins/TabSRMM/src/functions.h2
-rw-r--r--plugins/TabSRMM/src/hotkeyhandler.cpp10
-rw-r--r--plugins/TabSRMM/src/msgdialog.cpp2
-rw-r--r--plugins/TabSRMM/src/msgs.cpp65
-rw-r--r--plugins/TabSRMM/src/msgs.h8
-rw-r--r--plugins/TabSRMM/src/sendqueue.h1
8 files changed, 66 insertions, 71 deletions
diff --git a/plugins/TabSRMM/src/chat_main.cpp b/plugins/TabSRMM/src/chat_main.cpp
index 62f3d6bdf1..ecea5d89e5 100644
--- a/plugins/TabSRMM/src/chat_main.cpp
+++ b/plugins/TabSRMM/src/chat_main.cpp
@@ -211,7 +211,7 @@ void ShowRoom(TContainerData *pContainer, SESSION_INFO *si)
return;
if (si->pDlg != nullptr) {
- ActivateExistingTab(si->pDlg->m_pContainer, si->pDlg->GetHwnd());
+ si->pDlg->ActivateTab();
return;
}
diff --git a/plugins/TabSRMM/src/container.cpp b/plugins/TabSRMM/src/container.cpp
index 406322a214..d83419ae9f 100644
--- a/plugins/TabSRMM/src/container.cpp
+++ b/plugins/TabSRMM/src/container.cpp
@@ -95,6 +95,53 @@ TContainerData::~TContainerData()
}
/////////////////////////////////////////////////////////////////////////////////////////
+// this function searches and activates the tab belonging to the given message dialog
+
+void TContainerData::ActivateExistingTab(CMsgDialog *dat)
+{
+ if (dat == nullptr)
+ return;
+
+ NMHDR nmhdr = {};
+ nmhdr.code = TCN_SELCHANGE;
+ if (TabCtrl_GetItemCount(m_hwndTabs) > 1 && !m_flags.m_bDeferredTabSelect) {
+ TabCtrl_SetCurSel(m_hwndTabs, GetTabIndexFromHWND(m_hwndTabs, dat->GetHwnd()));
+ SendMessage(m_hwnd, WM_NOTIFY, 0, (LPARAM)&nmhdr); // just select the tab and let WM_NOTIFY do the rest
+ if (m_flags.m_bSideBar)
+ m_pSideBar->setActiveItem(dat, true);
+ }
+ if (!dat->isChat())
+ UpdateTitle(dat->m_hContact);
+ if (IsIconic(m_hwnd)) {
+ SendMessage(m_hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
+ SetForegroundWindow(m_hwnd);
+ }
+
+ // hide on close feature
+ if (!IsWindowVisible(m_hwnd)) {
+ WINDOWPLACEMENT wp = { 0 };
+ wp.length = sizeof(wp);
+ GetWindowPlacement(m_hwnd, &wp);
+
+ // all tabs must re-check the layout on activation because adding a tab while
+ // the container was hidden can make this necessary
+ BroadCastContainer(DM_CHECKSIZE, 0, 0);
+ if (wp.showCmd == SW_SHOWMAXIMIZED)
+ ShowWindow(m_hwnd, SW_SHOWMAXIMIZED);
+ else {
+ ShowWindow(m_hwnd, SW_SHOWNA);
+ SetForegroundWindow(m_hwnd);
+ }
+ SendMessage(m_hwndActive, WM_SIZE, 0, 0); // make sure the active tab resizes its layout properly
+ }
+ else if (GetForegroundWindow() != m_hwnd)
+ SetForegroundWindow(m_hwnd);
+
+ if (!dat->isChat())
+ SetFocus(dat->GetEntry().GetHwnd());
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
// calls the TabCtrl_AdjustRect to calculate the "real" client area of the tab.
// also checks for the option "hide tabs when only one tab open" and adjusts
// geometry if necessary
diff --git a/plugins/TabSRMM/src/functions.h b/plugins/TabSRMM/src/functions.h
index 25c7d4264b..235841d745 100644
--- a/plugins/TabSRMM/src/functions.h
+++ b/plugins/TabSRMM/src/functions.h
@@ -70,7 +70,7 @@ void TSAPI HandleMenuEntryFromhContact(MCONTACT iSelection);
* gneric msgwindow functions(creation, container management etc.)
*/
-HWND TSAPI CreateNewTabForContact(TContainerData *pContainer, MCONTACT hContact, bool bActivateTAb, bool bPopupContainer, bool bWantPopup, MEVENT hdbEvent = 0, bool bIsWchar = false, const char *pszInitialText = nullptr);
+void TSAPI CreateNewTabForContact(TContainerData *pContainer, MCONTACT hContact, bool bActivateTAb, bool bPopupContainer, bool bWantPopup, MEVENT hdbEvent = 0, bool bIsWchar = false, const char *pszInitialText = nullptr);
int TSAPI ActivateTabFromHWND(HWND hwndTab, HWND hwnd);
void TSAPI CreateImageList(bool bInitial);
diff --git a/plugins/TabSRMM/src/hotkeyhandler.cpp b/plugins/TabSRMM/src/hotkeyhandler.cpp
index 7cf463a8a9..9e9ee3f502 100644
--- a/plugins/TabSRMM/src/hotkeyhandler.cpp
+++ b/plugins/TabSRMM/src/hotkeyhandler.cpp
@@ -93,12 +93,10 @@ void TSAPI HandleMenuEntryFromhContact(MCONTACT hContact)
if (hContact == 0)
return;
- HWND hWnd = Srmm_FindWindow(hContact);
- if (hWnd && IsWindow(hWnd)) {
- TContainerData *pContainer = nullptr;
- SendMessage(hWnd, DM_QUERYCONTAINER, 0, (LPARAM)&pContainer);
- if (pContainer) {
- ActivateExistingTab(pContainer, hWnd);
+ auto *pDlg = Srmm_FindDialog(hContact);
+ if (pDlg && IsWindow(pDlg->GetHwnd())) {
+ if (TContainerData *pContainer = pDlg->m_pContainer) {
+ pDlg->ActivateTab();
pContainer->m_hwndSaved = nullptr;
SetForegroundWindow(pContainer->m_hwnd);
}
diff --git a/plugins/TabSRMM/src/msgdialog.cpp b/plugins/TabSRMM/src/msgdialog.cpp
index 7da67c41ea..a44bb25bb5 100644
--- a/plugins/TabSRMM/src/msgdialog.cpp
+++ b/plugins/TabSRMM/src/msgdialog.cpp
@@ -3270,7 +3270,7 @@ INT_PTR CMsgDialog::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
return 0;
case DM_ACTIVATEME: // the child window will activate itself
- ActivateExistingTab(m_pContainer, m_hwnd);
+ ActivateTab();
return 0;
case DM_QUERYCONTAINER: // container API support functions
diff --git a/plugins/TabSRMM/src/msgs.cpp b/plugins/TabSRMM/src/msgs.cpp
index 3bf9a38cb3..bdd5d3026d 100644
--- a/plugins/TabSRMM/src/msgs.cpp
+++ b/plugins/TabSRMM/src/msgs.cpp
@@ -257,73 +257,22 @@ int MyAvatarChanged(WPARAM wParam, LPARAM lParam)
}
/////////////////////////////////////////////////////////////////////////////////////////
-// tabbed mode support functions...
-// (C) by Nightwish
-//
-// this function searches and activates the tab belonging to the given hwnd (which is the
-// hwnd of a message dialog window)
-
-int TSAPI ActivateExistingTab(TContainerData *pContainer, HWND hwndChild)
-{
- CMsgDialog *dat = (CMsgDialog*)GetWindowLongPtr(hwndChild, GWLP_USERDATA); // needed to obtain the hContact for the message window
- if (!dat || !pContainer)
- return FALSE;
-
- NMHDR nmhdr = {};
- nmhdr.code = TCN_SELCHANGE;
- if (TabCtrl_GetItemCount(pContainer->m_hwndTabs) > 1 && !pContainer->m_flags.m_bDeferredTabSelect) {
- TabCtrl_SetCurSel(pContainer->m_hwndTabs, GetTabIndexFromHWND(pContainer->m_hwndTabs, hwndChild));
- SendMessage(pContainer->m_hwnd, WM_NOTIFY, 0, (LPARAM)&nmhdr); // just select the tab and let WM_NOTIFY do the rest
- }
- if (!dat->isChat())
- pContainer->UpdateTitle(dat->m_hContact);
- if (IsIconic(pContainer->m_hwnd)) {
- SendMessage(pContainer->m_hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
- SetForegroundWindow(pContainer->m_hwnd);
- }
-
- // hide on close feature
- if (!IsWindowVisible(pContainer->m_hwnd)) {
- WINDOWPLACEMENT wp = { 0 };
- wp.length = sizeof(wp);
- GetWindowPlacement(pContainer->m_hwnd, &wp);
-
- // all tabs must re-check the layout on activation because adding a tab while
- // the container was hidden can make this necessary
- pContainer->BroadCastContainer(DM_CHECKSIZE, 0, 0);
- if (wp.showCmd == SW_SHOWMAXIMIZED)
- ShowWindow(pContainer->m_hwnd, SW_SHOWMAXIMIZED);
- else {
- ShowWindow(pContainer->m_hwnd, SW_SHOWNA);
- SetForegroundWindow(pContainer->m_hwnd);
- }
- SendMessage(pContainer->m_hwndActive, WM_SIZE, 0, 0); // make sure the active tab resizes its layout properly
- }
- else if (GetForegroundWindow() != pContainer->m_hwnd)
- SetForegroundWindow(pContainer->m_hwnd);
-
- if (!dat->isChat())
- SetFocus(GetDlgItem(hwndChild, IDC_SRMM_MESSAGE));
- return TRUE;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
// this function creates and activates a new tab within the given container.
// bActivateTab: make the new tab the active one
// bPopupContainer: restore container if it was minimized, otherwise flash it...
-HWND TSAPI CreateNewTabForContact(TContainerData *pContainer, MCONTACT hContact, bool bActivateTab, bool bPopupContainer, bool bWantPopup, MEVENT hdbEvent, bool bIsUnicode, const char *pszInitialText)
+void TSAPI CreateNewTabForContact(TContainerData *pContainer, MCONTACT hContact, bool bActivateTab, bool bPopupContainer, bool bWantPopup, MEVENT hdbEvent, bool bIsUnicode, const char *pszInitialText)
{
if (Srmm_FindWindow(hContact) != nullptr) {
_DebugPopup(hContact, L"Warning: trying to create duplicate window");
- return nullptr;
+ return ;
}
// if we have a max # of tabs/container set and want to open something in the default container...
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 nullptr;
+ return;
char *szProto = Proto_GetBaseAccountName(hContact);
@@ -393,8 +342,6 @@ HWND TSAPI CreateNewTabForContact(TContainerData *pContainer, MCONTACT hContact,
pWindow->SetParent(pContainer->m_hwndTabs);
pWindow->Create();
- HWND hwndNew = pWindow->GetHwnd();
-
// switchbar support
if (pContainer->m_flags.m_bSideBar)
pContainer->m_pSideBar->addSession(pWindow, pContainer->m_iTabIndex);
@@ -416,8 +363,8 @@ HWND TSAPI CreateNewTabForContact(TContainerData *pContainer, MCONTACT hContact,
}
if (bActivateTab) {
- ActivateExistingTab(pContainer, hwndNew);
- SetFocus(hwndNew);
+ pWindow->ActivateTab();
+ SetFocus(pWindow->GetHwnd());
RedrawWindow(pContainer->m_hwnd, nullptr, nullptr, RDW_ERASENOW);
UpdateWindow(pContainer->m_hwnd);
if (GetForegroundWindow() != pContainer->m_hwnd && bPopupContainer == TRUE)
@@ -452,8 +399,6 @@ HWND 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 hwndNew; // return handle of the new dialog
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/plugins/TabSRMM/src/msgs.h b/plugins/TabSRMM/src/msgs.h
index f40792901b..cc4a3a94e8 100644
--- a/plugins/TabSRMM/src/msgs.h
+++ b/plugins/TabSRMM/src/msgs.h
@@ -105,6 +105,7 @@ struct TitleBtn {
class CContactCache;
class CMenuBar;
+class CMsgDialog;
class CProxyWindow;
class CSideBar;
class CTaskbarInteract;
@@ -265,6 +266,7 @@ struct TContainerData : public MZeroedObject
wchar_t m_wszName[CONTAINER_NAMELEN + 4]; // container name
wchar_t m_szRelThemeFile[MAX_PATH], m_szAbsThemeFile[MAX_PATH];
+ void ActivateExistingTab(CMsgDialog *dat);
void AdjustTabClientRect(RECT &rc);
void ApplySetting(bool fForceResize = false);
void BroadCastContainer(UINT message, WPARAM wParam, LPARAM lParam) const;
@@ -283,7 +285,7 @@ struct TContainerData : public MZeroedObject
void SetAeroMargins(void);
void SetIcon(CMsgDialog *pDlg, HICON hIcon);
void UpdateTabs(void);
- void UpdateTitle(MCONTACT, class CMsgDialog* = nullptr);
+ void UpdateTitle(MCONTACT, CMsgDialog* = nullptr);
void ClearMargins()
{ memset(&m_mOld, 0xfe, sizeof(m_mOld));
@@ -567,6 +569,10 @@ public:
__forceinline CCtrlRichEdit& GetEntry() { return m_message; }
+ __forceinline void ActivateTab() {
+ m_pContainer->ActivateExistingTab(this);
+ }
+
__forceinline CLogWindow* LOG() {
return ((CLogWindow *)m_pLog);
}
diff --git a/plugins/TabSRMM/src/sendqueue.h b/plugins/TabSRMM/src/sendqueue.h
index 46ac8716bc..beaf4acef7 100644
--- a/plugins/TabSRMM/src/sendqueue.h
+++ b/plugins/TabSRMM/src/sendqueue.h
@@ -107,7 +107,6 @@ private:
extern SendQueue *sendQueue;
-int TSAPI ActivateExistingTab(TContainerData *pContainer, HWND hwndChild);
void TSAPI HandleIconFeedback(CMsgDialog *dat, HICON iIcon);
#endif /* __SENDQUEUE_H */