reworked vertical scrolling code to correspond better to what I think is correct (horizontal case is unchanged)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20596 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2003-05-12 08:35:53 +00:00
parent 0cf5de1133
commit be9b0663d9

View File

@@ -573,24 +573,29 @@ int wxScrollHelper::CalcScrollInc(wxScrollWinEvent& event)
} }
else else
{ {
if (m_yScrollPixelsPerLine > 0) if ( m_yScrollPixelsPerLine > 0 )
{ {
int w, h; if ( m_yScrollPosition + nScrollInc < 0 )
GetTargetSize(&w, &h); {
// As -ve as we can go
int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine; nScrollInc = -m_yScrollPosition;
int noPositions = (int) ( ((nMaxHeight - h)/(double)m_yScrollPixelsPerLine) + 0.5 ); }
if (noPositions < 0) else // check for the other bound
noPositions = 0; {
const int posMax = m_yScrollLines - m_yScrollLinesPerPage;
if ( (m_yScrollPosition + nScrollInc) < 0 ) if ( m_yScrollPosition + nScrollInc > posMax )
nScrollInc = -m_yScrollPosition; // As -ve as we can go {
else if ( (m_yScrollPosition + nScrollInc) > noPositions ) // As +ve as we can go
nScrollInc = noPositions - m_yScrollPosition; // As +ve as we can go nScrollInc = posMax - m_yScrollPosition;
}
}
} }
else else
{
// VZ: why do we do this? (FIXME)
m_targetWindow->Refresh(TRUE, GetRect()); m_targetWindow->Refresh(TRUE, GetRect());
} }
}
return nScrollInc; return nScrollInc;
} }
@@ -608,7 +613,14 @@ void wxScrollHelper::AdjustScrollbars()
int oldXScroll = m_xScrollPosition; int oldXScroll = m_xScrollPosition;
int oldYScroll = m_yScrollPosition; int oldYScroll = m_yScrollPosition;
do { // VZ: at least under Windows this loop is useless because when scrollbars
// [dis]appear we get a WM_SIZE resulting in another call to
// AdjustScrollbars() anyhow. As it doesn't seem to do any harm I leave
// it here for now but it would be better to ensure that all ports
// generate EVT_SIZE when scrollbars [dis]appear, emulating it if
// necessary, and remove it later
do
{
GetTargetSize(&w, 0); GetTargetSize(&w, 0);
if (m_xScrollPixelsPerLine == 0) if (m_xScrollPixelsPerLine == 0)
@@ -640,35 +652,54 @@ void wxScrollHelper::AdjustScrollbars()
GetTargetSize(0, &h); GetTargetSize(0, &h);
if (m_yScrollPixelsPerLine == 0) // scroll lines per page: if 0, no scrolling is needed
int linesPerPage;
if ( m_yScrollPixelsPerLine == 0 )
{ {
// scrolling is disabled
m_yScrollLines = 0; m_yScrollLines = 0;
m_yScrollPosition = 0; m_yScrollPosition = 0;
m_win->SetScrollbar (wxVERTICAL, 0, 0, 0, FALSE); linesPerPage = 0;
} }
else else // might need scrolling
{ {
m_yScrollLines = m_targetWindow->GetVirtualSize().GetHeight() / m_yScrollPixelsPerLine; int hVirt = m_targetWindow->GetVirtualSize().GetHeight();
m_yScrollLines = hVirt / m_yScrollPixelsPerLine;
// Calculate page size i.e. number of scroll units you get on the // Calculate page size i.e. number of scroll units you get on the
// current client window // current client window
int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 ); linesPerPage = h / m_yScrollPixelsPerLine;
if (noPagePositions < 1) noPagePositions = 1; if ( linesPerPage >= m_yScrollLines )
if ( noPagePositions > m_yScrollLines ) {
noPagePositions = m_yScrollLines; // we're big enough to not need scrolling
linesPerPage =
m_yScrollLines =
m_yScrollPosition = 0;
}
else // we do need a scrollbar
{
if ( linesPerPage < 1 )
linesPerPage = 1;
// Correct position if greater than extent of canvas minus // Correct position if greater than extent of canvas minus
// the visible portion of it or if below zero // the visible portion of it or if below zero
m_yScrollPosition = wxMin( m_yScrollLines - noPagePositions, m_yScrollPosition ); const int posMax = m_yScrollLines - linesPerPage;
m_yScrollPosition = wxMax( 0, m_yScrollPosition ); if ( m_yScrollPosition > posMax )
m_yScrollPosition = posMax;
m_win->SetScrollbar(wxVERTICAL, m_yScrollPosition, noPagePositions, m_yScrollLines); else if ( m_yScrollPosition < 0 )
// The amount by which we scroll when paging m_yScrollPosition = 0;
SetScrollPageSize(wxVERTICAL, noPagePositions); }
} }
// If a scrollbar (dis)appeared as a result of this, adjust them again. m_win->SetScrollbar(wxVERTICAL, m_yScrollPosition,
linesPerPage, m_yScrollLines);
// The amount by which we scroll when paging
SetScrollPageSize(wxVERTICAL, linesPerPage);
// If a scrollbar (dis)appeared as a result of this, adjust them again.
oldw = w; oldw = w;
oldh = h; oldh = h;