From 853f4764c074d072153cfe4cb5dc628b73c894cd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Oct 2011 19:48:44 +0000 Subject: [PATCH] Make the initial sash position work in splitter sample. 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 | 6 ++++++ src/generic/splitter.cpp | 9 +++++---- 2 files changed, 11 insertions(+), 4 deletions(-) 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(); } -- 2.47.2