- m_xScrollPosition = x_pos;
- SetScrollPos (wxHORIZONTAL, x_pos, TRUE);
+ m_xScrollPosition = x_pos;
+
+ // Calculate page size i.e. number of scroll units you get on the
+ // current client window
+ int noPagePositions = (int) ( (w/(float)m_xScrollPixelsPerLine) + 0.5 );
+ if (noPagePositions < 1) noPagePositions = 1;
+
+ // Correct position if greater than extent of canvas minus
+ // the visible portion of it or if below zero
+ m_xScrollPosition = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition );
+ m_xScrollPosition = wxMax( 0, m_xScrollPosition );
+
+ SetScrollPos( wxHORIZONTAL, m_xScrollPosition, TRUE );