diff --git a/samples/splitter/splitter.cpp b/samples/splitter/splitter.cpp index cd05d8ab88..0ed8ae07f2 100644 --- a/samples/splitter/splitter.cpp +++ b/samples/splitter/splitter.cpp @@ -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 diff --git a/src/generic/splitter.cpp b/src/generic/splitter.cpp index 5b0bd620a8..8c03ba8ebd 100644 --- a/src/generic/splitter.cpp +++ b/src/generic/splitter.cpp @@ -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(); }