Improve checks in ScintillaWX::ModifyScrollBars

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
This commit is contained in:
New Pagodi 2019-05-22 09:13:49 -05:00 committed by Vadim Zeitlin
parent 629e52da5e
commit d18d979371

View File

@ -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<int>(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) {