]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/splitter.cpp
delete children in ~wxWindow dtor and not in the base class ~wxWindowNative as it...
[wxWidgets.git] / src / generic / splitter.cpp
index 8f21f6cb0bd2138bd195c56793bd2e31da5a142a..b8292304b187c3f3c564cf643d03544f4a06f0db 100644 (file)
@@ -117,6 +117,8 @@ void wxSplitterWindow::Init()
     m_firstX = 0;
     m_firstY = 0;
     m_sashPosition = m_requestedSashPosition = 0;
+    m_sashGravity = 0.0;
+    m_lastSize = wxSize(0,0);
     m_checkRequestedSashPosition = false;
     m_minimumPaneSize = 0;
     m_sashCursorWE = wxCursor(wxCURSOR_SIZEWE);
@@ -408,6 +410,8 @@ void wxSplitterWindow::OnSize(wxSizeEvent& event)
 
     if ( iconized )
     {
+        m_lastSize = wxSize(0,0);
+
         event.Skip();
 
         return;
@@ -419,13 +423,36 @@ void wxSplitterWindow::OnSize(wxSizeEvent& event)
         GetClientSize(&w, &h);
 
         int size = m_splitMode == wxSPLIT_VERTICAL ? w : h;
+
+        int old_size = m_splitMode == wxSPLIT_VERTICAL ? m_lastSize.x : m_lastSize.y;
+        if ( old_size != 0 )
+        {
+            int delta = (int) ( (size - old_size)*m_sashGravity );
+            if ( delta != 0 )
+            {
+                int newPosition = m_sashPosition + delta;
+                if( newPosition < m_minimumPaneSize )
+                    newPosition = m_minimumPaneSize;
+                SetSashPositionAndNotify(newPosition);
+            }
+        }
+
         if ( m_sashPosition >= size - 5 )
             SetSashPositionAndNotify(wxMax(10, size - 40));
+        m_lastSize = wxSize(w,h);
     }
 
     SizeWindows();
 }
 
+void wxSplitterWindow::SetSashGravity(double gravity)
+{
+    wxCHECK_RET( gravity >= 0. && gravity <= 1.,
+                    _T("invalid gravity value") );
+
+    m_sashGravity = gravity;
+}
+
 bool wxSplitterWindow::SashHitTest(int x, int y, int tolerance)
 {
     if ( m_windowTwo == NULL || m_sashPosition == 0)
@@ -595,7 +622,7 @@ void wxSplitterWindow::SetSashPositionAndNotify(int sashPos)
 {
     // we must reset the request here, otherwise the sash would be stuck at
     // old position if the user attempted to move the sash after invalid
-    // (e.g. smaller than minsize) sash position was requested using 
+    // (e.g. smaller than minsize) sash position was requested using
     // SetSashPosition():
     m_requestedSashPosition = INT_MAX;