+// ----------------------------------------------------------------------------
+// geometry
+// ----------------------------------------------------------------------------
+
+bool wxScrollHelper::ScrollLayout()
+{
+    if ( m_win->GetSizer() && m_targetWindow == m_win )
+    {
+        // If we're the scroll target, take into account the
+        // virtual size and scrolled position of the window.
+
+        int x = 0, y = 0, w = 0, h = 0;
+        CalcScrolledPosition(0,0, &x,&y);
+        m_win->GetVirtualSize(&w, &h);
+        m_win->GetSizer()->SetDimension(x, y, w, h);
+        return true;
+    }
+
+    // fall back to default for LayoutConstraints
+    return m_win->wxWindow::Layout();
+}
+
+void wxScrollHelper::ScrollDoSetVirtualSize(int x, int y)
+{
+    m_win->wxWindow::DoSetVirtualSize( x, y );
+    AdjustScrollbars();
+
+    if (m_win->GetAutoLayout())
+        m_win->Layout();
+}
+
+// wxWindow's GetBestVirtualSize returns the actual window size,
+// whereas we want to return the virtual size
+wxSize wxScrollHelper::ScrollGetBestVirtualSize() const
+{
+    wxSize clientSize(m_win->GetClientSize());
+    if ( m_win->GetSizer() )
+        clientSize.IncTo(m_win->GetSizer()->CalcMin());
+
+    return clientSize;
+}
+
+// return the window best size from the given best virtual size
+wxSize
+wxScrollHelper::ScrollGetWindowSizeForVirtualSize(const wxSize& size) const
+{
+    // Only use the content to set the window size in the direction
+    // where there's no scrolling; otherwise we're going to get a huge
+    // window in the direction in which scrolling is enabled
+    int ppuX, ppuY;
+    GetScrollPixelsPerUnit(&ppuX, &ppuY);
+
+    wxSize minSize = m_win->GetMinSize();
+    if ( !minSize.IsFullySpecified() )
+        minSize = m_win->GetSize();
+
+    wxSize best(size);
+    if (ppuX > 0)
+        best.x = minSize.x;
+    if (ppuY > 0)
+        best.y = minSize.y;
+
+    return best;
+}
+