- // Correct position if greater than extent of canvas minus
- // the visible portion of it or if below zero
- m_yScrollPosition = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition );
- m_yScrollPosition = wxMax( 0, m_yScrollPosition );
+ if ( m_yScrollPixelsPerLine == 0 )
+ {
+ // scrolling is disabled
+ m_yScrollLines = 0;
+ m_yScrollPosition = 0;
+ linesPerPage = 0;
+ }
+ else // might need scrolling
+ {
+ int hVirt = m_targetWindow->GetVirtualSize().GetHeight();
+ m_yScrollLines = hVirt / m_yScrollPixelsPerLine;
+
+ // Calculate page size i.e. number of scroll units you get on the
+ // current client window
+ linesPerPage = h / m_yScrollPixelsPerLine;
+ if ( linesPerPage >= 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
+ // the visible portion of it or if below zero
+ const int posMax = m_yScrollLines - linesPerPage;
+ if ( m_yScrollPosition > posMax )
+ m_yScrollPosition = posMax;
+ else if ( m_yScrollPosition < 0 )
+ m_yScrollPosition = 0;
+ }
+ }
+
+ m_win->SetScrollbar(wxVERTICAL, m_yScrollPosition,
+ linesPerPage, m_yScrollLines);