]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/splitter.cpp
even GUI test should be console app
[wxWidgets.git] / src / generic / splitter.cpp
index 03422af4029837f0fd61314fbe64eedde0b98621..b8292304b187c3f3c564cf643d03544f4a06f0db 100644 (file)
     #include "wx/settings.h"
 #endif
 
+#ifdef __WXMAC__
+    #include "wx/mac/private.h"
+#endif
+
 #include "wx/renderer.h"
 
 #include "wx/splitter.h"
@@ -92,6 +96,10 @@ bool wxSplitterWindow::Create(wxWindow *parent, wxWindowID id,
 
     m_permitUnsplitAlways = (style & wxSP_PERMIT_UNSPLIT) != 0;
 
+    // don't erase the splitter background, it's pointless as we overwrite it
+    // anyhow
+    SetBackgroundStyle(wxBG_STYLE_CUSTOM);
+
     return true;
 }
 
@@ -109,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);
@@ -200,7 +210,7 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
     // following the mouse movement while it drags the sash, without it we only
     // draw the sash at the new position but only resize the windows when the
     // dragging is finished
-#ifdef __WXMAC__ && TARGET_API_MAC_OSX == 1
+#if defined( __WXMAC__ ) && TARGET_API_MAC_OSX == 1
     bool isLive = true ;
 #else
     bool isLive = (GetWindowStyleFlag() & wxSP_LIVE_UPDATE) != 0;
@@ -400,6 +410,8 @@ void wxSplitterWindow::OnSize(wxSizeEvent& event)
 
     if ( iconized )
     {
+        m_lastSize = wxSize(0,0);
+
         event.Skip();
 
         return;
@@ -411,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)
@@ -563,7 +598,7 @@ int wxSplitterWindow::AdjustSashPosition(int sashPos) const
         if ( minSize == -1 || m_minimumPaneSize > minSize )
             minSize = m_minimumPaneSize;
 
-        int maxSize = window_size - minSize - GetBorderSize();
+        int maxSize = window_size - minSize - GetBorderSize() - GetSashSize();
         if ( sashPos > maxSize )
             sashPos = maxSize;
     }
@@ -587,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;