From d18d979371deb70dbea9027d5d5754db78bffbc2 Mon Sep 17 00:00:00 2001 From: New Pagodi Date: Wed, 22 May 2019 09:13:49 -0500 Subject: [PATCH] Improve checks in ScintillaWX::ModifyScrollBars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ScintillaWX::ModifyScrollBars method is used to ensure that the horizontal and vertical scrollbars are constantly up to date. It computes the needed max and page size for the scrollbars based on a combination of input data and internal state variables, compares the needed values with the scrollbar’s current max and page size, and updates the scrollbars if there is a difference. Because of the current logic used, the method will try to update the scroll bars in two cases where no updates are necessary. First, if a scrollbar is not visible (or if word wrapping is on for the horizontal scrollbar), ModifyScrollBars currently tries to set the max to 0. However on some platforms, such as windows, this call can fail and result in the max actually being set to 1. Consequently subsequent calls to ModifyScrollBars will assume the value should be 0 but detect the scrollbar’s max as 1 and try to update the value again. To avoid this, instead set the scrollbar’s page size to 1 more than the max. The second case is only for the horizontal scrollbar. Currently, the function updates the scrollbar whenever the position is not 0. There doesn’t seem to be any reason for this check, and so it has simply been removed. Closes https://github.com/wxWidgets/wxWidgets/pull/1327 --- src/stc/ScintillaWX.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/stc/ScintillaWX.cpp b/src/stc/ScintillaWX.cpp index 088c57f14c..9dcd59814c 100644 --- a/src/stc/ScintillaWX.cpp +++ b/src/stc/ScintillaWX.cpp @@ -395,7 +395,7 @@ bool ScintillaWX::ModifyScrollBars(int nMax, int nPage) { int vertEnd = nMax+1; if (!verticalScrollBarVisible) - vertEnd = 0; + nPage = vertEnd + 1; // Check the vertical scrollbar if (stc->m_vScrollBar == NULL) { // Use built-in scrollbar @@ -423,15 +423,15 @@ bool ScintillaWX::ModifyScrollBars(int nMax, int nPage) { int horizEnd = scrollWidth; if (horizEnd < 0) horizEnd = 0; + int pageWidth = static_cast(rcText.Width()); if (!horizontalScrollBarVisible || Wrapping()) - horizEnd = 0; - int pageWidth = wxRound(rcText.Width()); + pageWidth = horizEnd + 1; if (stc->m_hScrollBar == NULL) { // Use built-in scrollbar int sbMax = stc->GetScrollRange(wxHORIZONTAL); int sbThumb = stc->GetScrollThumb(wxHORIZONTAL); int sbPos = stc->GetScrollPos(wxHORIZONTAL); - if ((sbMax != horizEnd) || (sbThumb != pageWidth) || (sbPos != 0)) { + if ((sbMax != horizEnd) || (sbThumb != pageWidth)) { stc->SetScrollbar(wxHORIZONTAL, sbPos, pageWidth, horizEnd); modified = true; if (scrollWidth < pageWidth) { @@ -443,7 +443,7 @@ bool ScintillaWX::ModifyScrollBars(int nMax, int nPage) { int sbMax = stc->m_hScrollBar->GetRange(); int sbThumb = stc->m_hScrollBar->GetPageSize(); int sbPos = stc->m_hScrollBar->GetThumbPosition(); - if ((sbMax != horizEnd) || (sbThumb != pageWidth) || (sbPos != 0)) { + if ((sbMax != horizEnd) || (sbThumb != pageWidth)) { stc->m_hScrollBar->SetScrollbar(sbPos, pageWidth, horizEnd, pageWidth); modified = true; if (scrollWidth < pageWidth) {