]> git.saurik.com Git - wxWidgets.git/commitdiff
Make the initial sash position work in splitter sample.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 30 Oct 2011 19:48:44 +0000 (19:48 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 30 Oct 2011 19:48:44 +0000 (19:48 +0000)
The initial splitter size must be set correctly when using gravity with
wxSplitterWindow as otherwise the sash would jump on first resize -- which was
exactly what happened in the splitter sample.

Add a SetSize() call to the sample with the comment explaining why is it
needed and also actually make it stick as the cached last size was not updated
before the splitter was split before.

Closes #9821.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69599 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/splitter/splitter.cpp
src/generic/splitter.cpp

index cd05d8ab8839625c1d62336237b35c23b156cb1b..0ed8ae07f2f506d2a74b473545cc7fdde4d8efbd 100644 (file)
@@ -257,6 +257,12 @@ MyFrame::MyFrame()
     menuBar->Check(SPLIT_LIVE, true);
     m_splitter = new MySplitterWindow(this);
 
+    // If you use non-zero gravity you must initialize the splitter with its
+    // correct initial size, otherwise it will change the sash position by a
+    // huge amount when it's resized from its initial default size to its real
+    // size when the frame lays it out. This wouldn't be necessary if default
+    // zero gravity were used (although it would do no harm neither).
+    m_splitter->SetSize(GetClientSize());
     m_splitter->SetSashGravity(1.0);
 
 #if 1
index 5b0bd620a8acfa861b7928ec98a6e3e079aae8ea..8c03ba8ebd02c85e19be0f82bc839f9e435fee0c 100644 (file)
@@ -435,6 +435,8 @@ void wxSplitterWindow::OnSize(wxSizeEvent& event)
         return;
     }
 
+    const wxSize curSize = event.GetSize();
+
     // Update the sash position if needed.
     //
     // Notice that we shouldn't do this if the sash position requested by user
@@ -442,10 +444,7 @@ void wxSplitterWindow::OnSize(wxSizeEvent& event)
     // modified it before this happens.
     if ( m_windowTwo && m_requestedSashPosition == INT_MAX )
     {
-        int w, h;
-        GetClientSize(&w, &h);
-
-        int size = m_splitMode == wxSPLIT_VERTICAL ? w : h;
+        int size = m_splitMode == wxSPLIT_VERTICAL ? curSize.x : curSize.y;
 
         int old_size = m_splitMode == wxSPLIT_VERTICAL ? m_lastSize.x : m_lastSize.y;
 
@@ -468,6 +467,8 @@ void wxSplitterWindow::OnSize(wxSizeEvent& event)
         }
     }
 
+    m_lastSize = curSize;
+
     SizeWindows();
 }