+void wxScrollHelper::GetViewStart (int *x, int *y) const
+{
+ if ( x )
+ *x = m_xScrollPosition;
+ if ( y )
+ *y = m_yScrollPosition;
+}
+
+void wxScrollHelper::CalcScrolledPosition(int x, int y, int *xx, int *yy) const
+{
+ if ( xx )
+ *xx = x - m_xScrollPosition * m_xScrollPixelsPerLine;
+ if ( yy )
+ *yy = y - m_yScrollPosition * m_yScrollPixelsPerLine;
+}
+
+void wxScrollHelper::CalcUnscrolledPosition(int x, int y, int *xx, int *yy) const
+{
+ if ( xx )
+ *xx = x + m_xScrollPosition * m_xScrollPixelsPerLine;
+ if ( yy )
+ *yy = y + m_yScrollPosition * m_yScrollPixelsPerLine;
+}
+
+// ----------------------------------------------------------------------------
+// event handlers
+// ----------------------------------------------------------------------------
+
+// Default OnSize resets scrollbars, if any
+void wxScrollHelper::HandleOnSize(wxSizeEvent& WXUNUSED(event))
+{
+#if wxUSE_CONSTRAINTS
+ if ( m_targetWindow->GetAutoLayout() )
+ m_targetWindow->Layout();
+#endif
+
+ AdjustScrollbars();
+}
+
+// This calls OnDraw, having adjusted the origin according to the current
+// scroll position
+void wxScrollHelper::HandleOnPaint(wxPaintEvent& WXUNUSED(event))
+{
+ wxPaintDC dc(m_targetWindow);
+ DoPrepareDC(dc);
+
+ OnDraw(dc);
+}
+
+// kbd handling: notice that we use OnChar() and not OnKeyDown() for
+// compatibility here - if we used OnKeyDown(), the programs which process
+// arrows themselves in their OnChar() would never get the message and like
+// this they always have the priority
+void wxScrollHelper::HandleOnChar(wxKeyEvent& event)
+{
+ int stx, sty, // view origin
+ szx, szy, // view size (total)
+ clix, cliy; // view size (on screen)
+
+ GetViewStart(&stx, &sty);
+ GetTargetSize(&clix, &cliy);
+ GetVirtualSize(&szx, &szy);
+
+ if( m_xScrollPixelsPerLine )
+ {
+ clix /= m_xScrollPixelsPerLine;
+ szx /= m_xScrollPixelsPerLine;
+ }
+ else
+ {
+ clix = 0;
+ szx = -1;
+ }
+ if( m_yScrollPixelsPerLine )
+ {
+ cliy /= m_yScrollPixelsPerLine;
+ szy /= m_yScrollPixelsPerLine;
+ }
+ else
+ {
+ cliy = 0;
+ szy = -1;
+ }
+
+ int dsty;
+ switch ( event.KeyCode() )
+ {
+ case WXK_PAGEUP:
+ case WXK_PRIOR:
+ dsty = sty - (5 * cliy / 6);
+ Scroll(-1, (dsty == -1) ? 0 : dsty);
+ break;
+
+ case WXK_PAGEDOWN:
+ case WXK_NEXT:
+ Scroll(-1, sty + (5 * cliy / 6));
+ break;
+
+ case WXK_HOME:
+ Scroll(0, event.ControlDown() ? 0 : -1);
+ break;
+
+ case WXK_END:
+ Scroll(szx - clix, event.ControlDown() ? szy - cliy : -1);
+ break;
+
+ case WXK_UP:
+ Scroll(-1, sty - 1);
+ break;
+
+ case WXK_DOWN:
+ Scroll(-1, sty + 1);
+ break;
+
+ case WXK_LEFT:
+ Scroll(stx - 1, -1);
+ break;
+
+ case WXK_RIGHT:
+ Scroll(stx + 1, -1);
+ break;
+
+ default:
+ // not for us
+ event.Skip();
+ }
+}
+
+// ----------------------------------------------------------------------------
+// autoscroll stuff: these functions deal with sending fake scroll events when
+// a captured mouse is being held outside the window
+// ----------------------------------------------------------------------------
+
+bool wxScrollHelper::SendAutoScrollEvents(wxScrollWinEvent& event) const
+{
+ // only send the event if the window is scrollable in this direction
+ wxWindow *win = (wxWindow *)event.GetEventObject();
+ return win->HasScrollbar(event.GetOrientation());
+}
+
+void wxScrollHelper::StopAutoScrolling()
+{
+ if ( m_timerAutoScroll )
+ {
+ delete m_timerAutoScroll;
+ m_timerAutoScroll = (wxTimer *)NULL;
+ }
+}
+
+void wxScrollHelper::HandleOnMouseEnter(wxMouseEvent& event)
+{
+ StopAutoScrolling();
+
+ event.Skip();
+}
+
+void wxScrollHelper::HandleOnMouseLeave(wxMouseEvent& event)