From 31fae888e1c8d04576299a988c5ab8508c8452bf Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 1 Jun 2018 21:59:27 +0300 Subject: fix for flashing in StdMsg, also fixes #1400 --- src/core/stdmsg/src/chat_manager.cpp | 10 +++++----- src/core/stdmsg/src/chat_window.cpp | 13 +++---------- src/core/stdmsg/src/msgdialog.cpp | 21 ++++++++------------- src/core/stdmsg/src/msgs.cpp | 23 ++++++++++++++++++++--- src/core/stdmsg/src/msgs.h | 8 +++++--- src/core/stdmsg/src/stdafx.h | 4 ++-- src/core/stdmsg/src/tabs.cpp | 13 ++++--------- 7 files changed, 47 insertions(+), 45 deletions(-) (limited to 'src/core/stdmsg') diff --git a/src/core/stdmsg/src/chat_manager.cpp b/src/core/stdmsg/src/chat_manager.cpp index 04b868e7e5..51ff5d245e 100644 --- a/src/core/stdmsg/src/chat_manager.cpp +++ b/src/core/stdmsg/src/chat_manager.cpp @@ -92,20 +92,20 @@ static void OnFlashHighlight(SESSION_INFO *si, int bInactive) return; if (!g_Settings.bTabsEnable && si->pDlg && g_Settings.bFlashWindowHighlight) - SetTimer(si->pDlg->GetHwnd(), TIMERID_FLASHWND, 900, nullptr); + si->pDlg->StartFlash(); if (g_Settings.bTabsEnable && si->pDlg) g_pTabDialog->SetMessageHighlight(si->pDlg); } static void OnFlashWindow(SESSION_INFO *si, int bInactive) { - if (!bInactive) + if (!bInactive || si->pDlg == nullptr) return; - if (!g_Settings.bTabsEnable && si->pDlg && g_Settings.bFlashWindow) - SetTimer(si->pDlg->GetHwnd(), TIMERID_FLASHWND, 900, nullptr); - if (g_Settings.bTabsEnable && si->pDlg) + if (g_Settings.bTabsEnable) g_pTabDialog->SetTabHighlight(si->pDlg); + else if (g_Settings.bFlashWindow) + si->pDlg->StartFlash(); } static BOOL DoTrayIcon(SESSION_INFO *si, GCEVENT *gce) diff --git a/src/core/stdmsg/src/chat_window.cpp b/src/core/stdmsg/src/chat_window.cpp index 46f2a522e8..7471f5e0c5 100644 --- a/src/core/stdmsg/src/chat_window.cpp +++ b/src/core/stdmsg/src/chat_window.cpp @@ -28,9 +28,8 @@ static wchar_t szTrimString[] = L":;,.!?\'\"><()[]- \r\n"; ///////////////////////////////////////////////////////////////////////////////////////// -CChatRoomDlg::CChatRoomDlg(CTabbedWindow *pContainer, SESSION_INFO *si) : - CSuper(IDD_CHANNEL, si), - m_pOwner(pContainer), +CChatRoomDlg::CChatRoomDlg(CTabbedWindow *pOwner, SESSION_INFO *si) : + CSuper(pOwner, IDD_CHANNEL, si), m_btnOk(this, IDOK), m_splitterX(this, IDC_SPLITTERX), @@ -100,8 +99,7 @@ void CChatRoomDlg::OnActivate() g_chatApi.SetActiveSession(m_si); UpdateStatusBar(); - if (KillTimer(m_hwnd, TIMERID_FLASHWND)) - FlashWindow(m_pOwner->GetHwnd(), FALSE); + StopFlash(); if (db_get_w(m_hContact, m_si->pszModule, "ApparentMode", 0) != 0) db_set_w(m_hContact, m_si->pszModule, "ApparentMode", 0); if (g_clistApi.pfnGetEvent(m_hContact, 0)) @@ -1102,11 +1100,6 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) } break; - case WM_TIMER: - if (wParam == TIMERID_FLASHWND) - FlashWindow(m_pOwner->GetHwnd(), TRUE); - break; - case WM_ACTIVATE: if (LOWORD(wParam) == WA_INACTIVE) { if (g_Settings.bTabsEnable) { diff --git a/src/core/stdmsg/src/msgdialog.cpp b/src/core/stdmsg/src/msgdialog.cpp index e12e853190..aac3471b28 100644 --- a/src/core/stdmsg/src/msgdialog.cpp +++ b/src/core/stdmsg/src/msgdialog.cpp @@ -85,12 +85,11 @@ static void SetEditorText(HWND hwnd, const wchar_t* txt) ///////////////////////////////////////////////////////////////////////////////////////// CSrmmWindow::CSrmmWindow(CTabbedWindow *pOwner, MCONTACT hContact) : - CSuper(IDD_MSG), + CSuper(pOwner, IDD_MSG), m_splitter(this, IDC_SPLITTERY), m_avatar(this, IDC_AVATAR), m_cmdList(20), - m_bNoActivate(g_dat.bDoNotStealFocus), - m_pOwner(pOwner) + m_bNoActivate(g_dat.bDoNotStealFocus) { m_hContact = hContact; @@ -242,7 +241,7 @@ void CSrmmWindow::OnInitDialog() if (m_bNoActivate) { SetWindowPos(m_hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW); - SetTimer(m_hwnd, TIMERID_FLASHWND, TIMEOUT_FLASHWND, nullptr); + StartFlash(); } else { SetWindowPos(m_hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); @@ -314,8 +313,7 @@ void CSrmmWindow::OnActivate() SetFocus(m_message.GetHwnd()); UpdateTitle(); UpdateLastMessage(); - if (KillTimer(m_hwnd, TIMERID_FLASHWND)) - FlashWindow(m_pOwner->GetHwnd(), FALSE); + StopFlash(); SendMessage(m_hwnd, DM_UPDATEWINICON, 0, 0); } @@ -1176,10 +1174,10 @@ INT_PTR CSrmmWindow::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS; GetScrollInfo(m_log.GetHwnd(), SB_VERT, &si); if ((si.nPos + (int)si.nPage + 5) < si.nMax) - SetTimer(m_hwnd, TIMERID_FLASHWND, TIMEOUT_FLASHWND, nullptr); + StartFlash(); } } - else SetTimer(m_hwnd, TIMERID_FLASHWND, TIMEOUT_FLASHWND, nullptr); + else StartFlash(); } } } @@ -1192,10 +1190,8 @@ INT_PTR CSrmmWindow::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_TIMER: if (wParam == TIMERID_FLASHWND) { - FlashWindow(m_pOwner->GetHwnd(), TRUE); if (m_nFlash > 2 * g_dat.nFlashMax) { - KillTimer(m_hwnd, TIMERID_FLASHWND); - FlashWindow(m_pOwner->GetHwnd(), FALSE); + StopFlash(); m_nFlash = 0; } m_nFlash++; @@ -1386,8 +1382,7 @@ INT_PTR CSrmmWindow::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS; GetScrollInfo((HWND)lParam, SB_VERT, &si); if ((si.nPos + (int)si.nPage + 5) >= si.nMax) - if (KillTimer(m_hwnd, TIMERID_FLASHWND)) - FlashWindow(m_pOwner->GetHwnd(), FALSE); + StopFlash(); } break; } diff --git a/src/core/stdmsg/src/msgs.cpp b/src/core/stdmsg/src/msgs.cpp index cdadeba179..46e2426657 100644 --- a/src/core/stdmsg/src/msgs.cpp +++ b/src/core/stdmsg/src/msgs.cpp @@ -24,9 +24,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ///////////////////////////////////////////////////////////////////////////////////////// -CMsgDialog::CMsgDialog(int iDialogId, SESSION_INFO *si) - : CSuper(g_plugin, iDialogId, si), - m_btnOk(this, IDOK) +CMsgDialog::CMsgDialog(CTabbedWindow *pOwner, int iDialogId, SESSION_INFO *si) : + CSuper(g_plugin, iDialogId, si), + m_btnOk(this, IDOK), + m_pOwner(pOwner) { m_autoClose = 0; m_forceResizable = true; @@ -49,6 +50,11 @@ INT_PTR CMsgDialog::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) OnActivate(); break; + case WM_TIMER: + if (wParam == TIMERID_FLASHWND) + FlashWindow(m_pOwner->GetHwnd(), TRUE); + break; + case WM_MOUSEACTIVATE: OnActivate(); SetFocus(m_message.GetHwnd()); @@ -58,6 +64,17 @@ INT_PTR CMsgDialog::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) return CSuper::DlgProc(uMsg, wParam, lParam); } +void CMsgDialog::StartFlash() +{ + ::SetTimer(m_hwnd, TIMERID_FLASHWND, 900, nullptr); +} + +void CMsgDialog::StopFlash() +{ + if (::KillTimer(m_hwnd, TIMERID_FLASHWND)) + ::FlashWindow(m_pOwner->GetHwnd(), FALSE); +} + ///////////////////////////////////////////////////////////////////////////////////////// int OnCheckPlugins(WPARAM, LPARAM); diff --git a/src/core/stdmsg/src/msgs.h b/src/core/stdmsg/src/msgs.h index 462d485ecb..7a9f280a6a 100644 --- a/src/core/stdmsg/src/msgs.h +++ b/src/core/stdmsg/src/msgs.h @@ -49,8 +49,9 @@ class CMsgDialog : public CSrmmBaseDialog protected: CCtrlButton m_btnOk; + CTabbedWindow *m_pOwner; - CMsgDialog(int idDialog, SESSION_INFO *si = nullptr); + CMsgDialog(CTabbedWindow *pOwner, int idDialog, SESSION_INFO *si = nullptr); virtual int GetImageId() const PURE; @@ -64,6 +65,9 @@ protected: public: void CloseTab() override; + void StartFlash(); + void StopFlash(); + __forceinline SESSION_INFO* getChat() const { return m_si; } }; @@ -117,7 +121,6 @@ public: HBITMAP m_avatarPic; wchar_t *m_wszInitialText; - CTabbedWindow *m_pOwner; public: CSrmmWindow(CTabbedWindow*, MCONTACT hContact); @@ -173,7 +176,6 @@ class CChatRoomDlg : public CMsgDialog CCtrlButton m_btnOk; CSplitter m_splitterX, m_splitterY; - CTabbedWindow *m_pOwner; int m_iSplitterX, m_iSplitterY; diff --git a/src/core/stdmsg/src/stdafx.h b/src/core/stdmsg/src/stdafx.h index c73b0314b0..805c39b4d0 100644 --- a/src/core/stdmsg/src/stdafx.h +++ b/src/core/stdmsg/src/stdafx.h @@ -166,8 +166,8 @@ public: void AddPage(SESSION_INFO*, int insertAt = -1); void FixTabIcons(CMsgDialog*); - void SetMessageHighlight(CChatRoomDlg*); - void SetTabHighlight(CChatRoomDlg*); + void SetMessageHighlight(CMsgDialog*); + void SetTabHighlight(CMsgDialog*); void TabClicked(); virtual void OnInitDialog() override; diff --git a/src/core/stdmsg/src/tabs.cpp b/src/core/stdmsg/src/tabs.cpp index f9e706c472..72c3a87a5a 100644 --- a/src/core/stdmsg/src/tabs.cpp +++ b/src/core/stdmsg/src/tabs.cpp @@ -337,7 +337,7 @@ void CTabbedWindow::SaveWindowPosition(bool bUpdateSession) } } -void CTabbedWindow::SetMessageHighlight(CChatRoomDlg *pDlg) +void CTabbedWindow::SetMessageHighlight(CMsgDialog *pDlg) { if (pDlg != nullptr) { if (m_tab.GetDlgIndex(pDlg) == -1) @@ -346,12 +346,12 @@ void CTabbedWindow::SetMessageHighlight(CChatRoomDlg *pDlg) pDlg->m_si->wState |= GC_EVENT_HIGHLIGHT; FixTabIcons(pDlg); if (g_Settings.bFlashWindowHighlight && GetActiveWindow() != m_hwnd && GetForegroundWindow() != m_hwnd) - SetTimer(m_hwnd, TIMERID_FLASHWND, 900, nullptr); + pDlg->StartFlash(); } else RedrawWindow(m_tab.GetHwnd(), nullptr, nullptr, RDW_INVALIDATE); } -void CTabbedWindow::SetTabHighlight(CChatRoomDlg *pDlg) +void CTabbedWindow::SetTabHighlight(CMsgDialog *pDlg) { if (pDlg != nullptr) { if (m_tab.GetDlgIndex(pDlg) == -1) @@ -359,7 +359,7 @@ void CTabbedWindow::SetTabHighlight(CChatRoomDlg *pDlg) FixTabIcons(pDlg); if (g_Settings.bFlashWindow && GetActiveWindow() != m_hwnd && GetForegroundWindow() != m_hwnd) - SetTimer(m_hwnd, TIMERID_FLASHWND, 900, nullptr); + pDlg->StartFlash(); } else RedrawWindow(m_tab.GetHwnd(), nullptr, nullptr, RDW_INVALIDATE); } @@ -541,11 +541,6 @@ INT_PTR CTabbedWindow::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) } break; - case WM_TIMER: - if (wParam == TIMERID_FLASHWND) - FlashWindow(m_hwnd, TRUE); - break; - case WM_MOVE: SaveWindowPosition(false); break; -- cgit v1.2.3