+// Adjust the scrollbars - new version.
+void wxScrollHelper::AdjustScrollbars()
+{
+#ifdef __WXMAC__
+ m_targetWindow->MacUpdateImmediately();
+#endif
+
+ int w, h;
+ GetTargetSize(&w, &h);
+
+ int oldXScroll = m_xScrollPosition;
+ int oldYScroll = m_yScrollPosition;
+
+ if (m_xScrollLines > 0)
+ {
+ // Calculate page size i.e. number of scroll units you get on the
+ // current client window
+ int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 );
+ if (noPagePositions < 1) noPagePositions = 1;
+ if ( noPagePositions > m_xScrollLines )
+ noPagePositions = m_xScrollLines;
+
+ // 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 );
+
+ m_targetWindow->SetScrollbar(wxHORIZONTAL, m_xScrollPosition, noPagePositions, m_xScrollLines);
+ // The amount by which we scroll when paging
+ SetScrollPageSize(wxHORIZONTAL, noPagePositions);
+ }
+ else
+ {
+ m_xScrollPosition = 0;
+ m_targetWindow->SetScrollbar (wxHORIZONTAL, 0, 0, 0, FALSE);
+ }
+
+ if (m_yScrollLines > 0)
+ {
+ // Calculate page size i.e. number of scroll units you get on the
+ // current client window
+ int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 );
+ if (noPagePositions < 1) noPagePositions = 1;
+ if ( noPagePositions > m_yScrollLines )
+ noPagePositions = m_yScrollLines;
+
+ // 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 );
+
+ m_targetWindow->SetScrollbar(wxVERTICAL, m_yScrollPosition, noPagePositions, m_yScrollLines);
+ // The amount by which we scroll when paging
+ SetScrollPageSize(wxVERTICAL, noPagePositions);
+ }
+ else
+ {
+ m_yScrollPosition = 0;
+ m_targetWindow->SetScrollbar (wxVERTICAL, 0, 0, 0, FALSE);
+ }
+
+ if (oldXScroll != m_xScrollPosition)
+ {
+ if (m_xScrollingEnabled)
+ m_targetWindow->ScrollWindow( m_xScrollPixelsPerLine * (oldXScroll-m_xScrollPosition), 0,
+ GetRect() );
+ else
+ m_targetWindow->Refresh(TRUE, GetRect());
+ }
+
+ if (oldYScroll != m_yScrollPosition)
+ {
+ if (m_yScrollingEnabled)
+ m_targetWindow->ScrollWindow( 0, m_yScrollPixelsPerLine * (oldYScroll-m_yScrollPosition),
+ GetRect() );
+ else
+ m_targetWindow->Refresh(TRUE, GetRect());
+ }
+
+#ifdef __WXMAC__
+ m_targetWindow->MacUpdateImmediately();
+#endif
+}
+
+void wxScrollHelper::DoPrepareDC(wxDC& dc)
+{
+ wxPoint pt = dc.GetDeviceOrigin();
+ dc.SetDeviceOrigin( pt.x - m_xScrollPosition * m_xScrollPixelsPerLine,
+ pt.y - m_yScrollPosition * m_yScrollPixelsPerLine );
+ dc.SetUserScale( m_scaleX, m_scaleY );
+}
+
+void wxScrollHelper::GetScrollPixelsPerUnit (int *x_unit, int *y_unit) const
+{
+ if ( x_unit )
+ *x_unit = m_xScrollPixelsPerLine;
+ if ( y_unit )
+ *y_unit = m_yScrollPixelsPerLine;
+}
+
+int wxScrollHelper::GetScrollPageSize(int orient) const