Skip to content

Commit

Permalink
Merge branch 'fix-vlistbox-out-of-range' of https://github.com/wsu-cb…
Browse files Browse the repository at this point in the history
…/wxWidgets

Prevent scrolling beyond specified range.

See wxWidgets#24278.
  • Loading branch information
vadz committed Feb 3, 2024
2 parents 42839de + 95054f3 commit 36583f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/generic/vlbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,19 @@ void wxVListBox::OnKeyDown(wxKeyEvent& event)

case WXK_PAGEDOWN:
case WXK_NUMPAD_PAGEDOWN:
{
size_t oldBegin = GetVisibleBegin();
PageDown();
current = GetVisibleBegin();
if (GetVisibleBegin() > oldBegin)
{
current = GetVisibleBegin();
}
else
{
current = GetRowCount() - 1;
}
break;
}

case WXK_PAGEUP:
case WXK_NUMPAD_PAGEUP:
Expand Down
8 changes: 4 additions & 4 deletions src/generic/vscroll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,15 @@ size_t wxVarScrollHelperBase::GetNewScrollPosition(wxScrollWinEvent& event) cons
}
else if ( evtType == wxEVT_SCROLLWIN_BOTTOM )
{
return m_unitMax;
return m_unitMax - 1;
}
else if ( evtType == wxEVT_SCROLLWIN_LINEUP )
{
return m_unitFirst ? m_unitFirst - 1 : 0;
}
else if ( evtType == wxEVT_SCROLLWIN_LINEDOWN )
{
return m_unitFirst + 1;
return wxMin(m_unitFirst + 1, m_unitMax - 1);
}
else if ( evtType == wxEVT_SCROLLWIN_PAGEUP )
{
Expand All @@ -352,9 +352,9 @@ size_t wxVarScrollHelperBase::GetNewScrollPosition(wxScrollWinEvent& event) cons
{
// And page down should do at least as much as line down.
if ( GetVisibleEnd() )
return wxMax(GetVisibleEnd() - 1, m_unitFirst + 1);
return wxMax(GetVisibleEnd() - 1, wxMin(m_unitFirst + 1, m_unitMax - 1));
else
return wxMax(GetVisibleEnd(), m_unitFirst + 1);
return wxMax(GetVisibleEnd(), wxMin(m_unitFirst + 1, m_unitMax - 1));
}
else if ( evtType == wxEVT_SCROLLWIN_THUMBRELEASE )
{
Expand Down

0 comments on commit 36583f1

Please sign in to comment.