From bae70808afbe0ca866d008090a8e3580342d16f3 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 25 Jul 2019 14:58:05 +0300 Subject: fixes #1920 (Scriver always scrolls its log to bottom when new message arrives) --- plugins/Scriver/src/msgdialog.cpp | 4 ---- plugins/Scriver/src/msglog.cpp | 47 ++++++++++++++++++++++++++------------- plugins/Scriver/src/msgs.h | 1 - plugins/Scriver/src/version.h | 2 +- 4 files changed, 33 insertions(+), 21 deletions(-) (limited to 'plugins/Scriver/src') diff --git a/plugins/Scriver/src/msgdialog.cpp b/plugins/Scriver/src/msgdialog.cpp index 25147078a3..a233adc74b 100644 --- a/plugins/Scriver/src/msgdialog.cpp +++ b/plugins/Scriver/src/msgdialog.cpp @@ -1361,10 +1361,6 @@ INT_PTR CSrmmWindow::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) } return TRUE; - case DM_SCROLLLOGTOBOTTOM: - ScrollToBottom(); - return 0; - case DM_REMAKELOG: m_lastEventType = -1; if (wParam == 0 || wParam == m_hContact) diff --git a/plugins/Scriver/src/msglog.cpp b/plugins/Scriver/src/msglog.cpp index 67de067e91..85862fe33a 100644 --- a/plugins/Scriver/src/msglog.cpp +++ b/plugins/Scriver/src/msglog.cpp @@ -660,7 +660,7 @@ void StreamInTestEvents(HWND hEditWnd, GlobalMessageData *gdat) delete dat; } -void CSrmmWindow::StreamInEvents(MEVENT hDbEventFirst, int count, int fAppend) +void CSrmmWindow::StreamInEvents(MEVENT hDbEventFirst, int count, int bAppend) { // IEVIew MOD Begin if (m_hwndIeview != nullptr) { @@ -672,7 +672,7 @@ void CSrmmWindow::StreamInEvents(MEVENT hDbEventFirst, int count, int fAppend) evt.hwnd = m_hwndIeview; evt.hContact = m_hContact; evt.pszProto = m_szProto; - if (!fAppend) { + if (!bAppend) { evt.iType = IEE_CLEAR_LOG; CallService(MS_IEVIEW_EVENT, 0, (LPARAM)&evt); } @@ -692,7 +692,7 @@ void CSrmmWindow::StreamInEvents(MEVENT hDbEventFirst, int count, int fAppend) // IEVIew MOD End CHARRANGE oldSel, sel; - m_log.SendMsg(EM_HIDESELECTION, TRUE, 0); + m_log.SendMsg(WM_SETREDRAW, FALSE, 0); m_log.SendMsg(EM_EXGETSEL, 0, (LPARAM)&oldSel); LogStreamData streamData = {}; @@ -701,7 +701,7 @@ void CSrmmWindow::StreamInEvents(MEVENT hDbEventFirst, int count, int fAppend) streamData.hDbEventLast = m_hDbEventLast; streamData.dlgDat = this; streamData.eventsToInsert = count; - streamData.isFirst = fAppend ? m_log.GetRichTextLength() == 0 : 1; + streamData.isFirst = bAppend ? m_log.GetRichTextLength() == 0 : 1; streamData.gdat = &g_dat; EDITSTREAM stream = {}; @@ -709,8 +709,20 @@ void CSrmmWindow::StreamInEvents(MEVENT hDbEventFirst, int count, int fAppend) stream.dwCookie = (DWORD_PTR)& streamData; sel.cpMin = 0; + POINT scrollPos; + bool bottomScroll = (GetFocus() != m_log.GetHwnd()); + if (bottomScroll && (GetWindowLongPtr(m_log.GetHwnd(), GWL_STYLE) & WS_VSCROLL)) { + SCROLLINFO si = {}; + si.cbSize = sizeof(si); + si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS; + GetScrollInfo(m_log.GetHwnd(), SB_VERT, &si); + bottomScroll = (si.nPos + (int)si.nPage) >= si.nMax; + } + if (!bottomScroll) + m_log.SendMsg(EM_GETSCROLLPOS, 0, (LPARAM)&scrollPos); + FINDTEXTEXA fi; - if (fAppend) { + if (bAppend) { GETTEXTLENGTHEX gtxl = { 0 }; gtxl.flags = GTL_DEFAULT | GTL_PRECISE | GTL_NUMCHARS; gtxl.codepage = 1200; @@ -728,10 +740,16 @@ void CSrmmWindow::StreamInEvents(MEVENT hDbEventFirst, int count, int fAppend) m_isMixed = 0; } - m_log.SendMsg(EM_STREAMIN, fAppend ? SFF_SELECTION | SF_RTF : SFF_SELECTION | SF_RTF, (LPARAM)&stream); - m_log.SendMsg(EM_EXSETSEL, 0, (LPARAM)&oldSel); - m_log.SendMsg(EM_HIDESELECTION, FALSE, 0); - + m_log.SendMsg(EM_STREAMIN, bAppend ? SFF_SELECTION | SF_RTF : SFF_SELECTION | SF_RTF, (LPARAM)&stream); + if (bottomScroll) { + sel.cpMin = sel.cpMax = -1; + m_log.SendMsg(EM_EXSETSEL, 0, (LPARAM)&sel); + } + else { + m_log.SendMsg(EM_EXSETSEL, 0, (LPARAM)&oldSel); + m_log.SendMsg(EM_SETSCROLLPOS, 0, (LPARAM)&scrollPos); + } + if (g_dat.smileyAddInstalled) { SMADD_RICHEDIT3 smre; smre.cbSize = sizeof(SMADD_RICHEDIT3); @@ -753,14 +771,13 @@ void CSrmmWindow::StreamInEvents(MEVENT hDbEventFirst, int count, int fAppend) CallService(MS_SMILEYADD_REPLACESMILEYS, 0, (LPARAM)&smre); } - int len = m_log.GetRichTextLength(); - m_log.SendMsg(EM_SETSEL, len - 1, len - 1); - - if (!fAppend) - m_log.SendMsg(WM_SETREDRAW, TRUE, 0); + m_log.SendMsg(WM_SETREDRAW, TRUE, 0); + if (bottomScroll) { + ScrollToBottom(); + RedrawWindow(m_log.GetHwnd(), nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW); + } m_hDbEventLast = streamData.hDbEventLast; - PostMessage(m_hwnd, DM_SCROLLLOGTOBOTTOM, 0, 0); } #define RTFPICTHEADERMAXSIZE 78 diff --git a/plugins/Scriver/src/msgs.h b/plugins/Scriver/src/msgs.h index 88189fb316..4139351b64 100644 --- a/plugins/Scriver/src/msgs.h +++ b/plugins/Scriver/src/msgs.h @@ -238,7 +238,6 @@ public: #define DM_OPTIONSAPPLIED (WM_USER+14) #define DM_APPENDTOLOG (WM_USER+17) #define DM_ERRORDECIDED (WM_USER+18) -#define DM_SCROLLLOGTOBOTTOM (WM_USER+19) #define DM_TYPING (WM_USER+20) #define DM_UPDATELASTMESSAGE (WM_USER+22) #define DM_USERNAMETOCLIP (WM_USER+23) diff --git a/plugins/Scriver/src/version.h b/plugins/Scriver/src/version.h index cd15f34cae..7d819ff22b 100644 --- a/plugins/Scriver/src/version.h +++ b/plugins/Scriver/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 3 #define __MINOR_VERSION 0 #define __RELEASE_NUM 1 -#define __BUILD_NUM 10 +#define __BUILD_NUM 11 #include -- cgit v1.2.3