]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/vscroll.cpp
why was this class made a wxControlContainer (rev. 1.7), this doesn't seem to make...
[wxWidgets.git] / src / generic / vscroll.cpp
index 609d6e0f52fb41ef74da72cce9b1d5dc1ee8f0b6..ec48cb9103c61f628f5e824df9052c25670195e1 100644 (file)
@@ -160,8 +160,22 @@ size_t wxVScrolledWindow::FindFirstFromBottom(size_t lineLast, bool full)
     return lineFirst;
 }
 
+void wxVScrolledWindow::RemoveScrollbar()
+{
+    m_lineFirst = 0;
+    m_nVisible = m_lineMax;
+    SetScrollbar(wxVERTICAL, 0, 0, 0);
+}
+
 void wxVScrolledWindow::UpdateScrollbar()
 {
+    // if there is nothing to scroll, remove the scrollbar
+    if ( !m_lineMax )
+    {
+        RemoveScrollbar();
+        return;
+    }
+
     // see how many lines can we fit on screen
     const wxCoord hWindow = GetClientSize().y;
 
@@ -189,8 +203,8 @@ void wxVScrolledWindow::UpdateScrollbar()
         if ( hAll < hWindow )
         {
             // we don't need scrollbar at all
-            m_lineFirst = 0;
-            SetScrollbar(wxVERTICAL, 0, 0, 0);
+            RemoveScrollbar();
+            return;
         }
     }
 
@@ -221,9 +235,16 @@ void wxVScrolledWindow::SetLineCount(size_t count)
     // and our estimate for their total height
     m_heightTotal = EstimateTotalHeight();
 
-    // recalculate the scrollbars parameters
-    m_lineFirst = 1;    // make sure it is != 0
-    ScrollToLine(0);
+    // ScrollToLine() will update the scrollbar itself if it changes the line
+    // we pass to it because it's out of [new] range
+    size_t oldScrollPos = m_lineFirst;
+    ScrollToLine(m_lineFirst);
+    if ( oldScrollPos == m_lineFirst )
+    {
+        // but if it didn't do it, we still need to update the scrollbar to
+        // reflect the changed number of lines ourselves
+        UpdateScrollbar();
+    }
 }
 
 void wxVScrolledWindow::RefreshLine(size_t line)
@@ -293,7 +314,7 @@ bool wxVScrolledWindow::Layout()
         // adjust the sizer dimensions/position taking into account the
         // virtual size and scrolled position of the window.
 
-        int w, h;
+        int w = 0, h = 0;
         GetVirtualSize(&w, &h);
 
         // x is always 0 so no variable needed