From: Vadim Zeitlin Date: Wed, 24 Aug 2011 11:48:18 +0000 (+0000) Subject: Try harder to set the requester splitter position in wxSplitterWindow. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/aaa801d1ddd97cba5a5e4d097b18bfef8c2933b6 Try harder to set the requester splitter position in wxSplitterWindow. The code in wxSplitterWindow tried to remember the requested position and set the real sash position to it later, even if the initial window size was too small to allow for it, but it didn't work because the requested position was forgotten after the first size event, even though it was quite possible that this event didn't really change the window size from the initial, small, one. Try to make this more robust by ignoring the size events which don't really change the window size. Also set m_lastSize correctly initially. Now setting the sash position does work even if the splitter itself is inside nested sizers (which results in many size events). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68876 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/generic/splitter.cpp b/src/generic/splitter.cpp index 03abc8baa5..ab5285ba34 100644 --- a/src/generic/splitter.cpp +++ b/src/generic/splitter.cpp @@ -93,10 +93,7 @@ bool wxSplitterWindow::Create(wxWindow *parent, wxWindowID id, if ( !wxWindow::Create(parent, id, pos, size, style, name) ) return false; - if (size.x >= 0) - m_lastSize.x = size.x; - if (size.y >= 0) - m_lastSize.y = size.y; + m_lastSize = GetClientSize(); m_permitUnsplitAlways = (style & wxSP_PERMIT_UNSPLIT) != 0; @@ -442,16 +439,22 @@ void wxSplitterWindow::OnSize(wxSizeEvent& event) 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 ) + + // Don't do anything if the size didn't really change. In particular, + // it is important that we don't reset our sash position because it's + // out of current range in this case as otherwise the really requested + // position would be lost and never set. Wait until we get a real size + // event with our non-initial size to do it. + if ( size == old_size ) + return; + + int delta = (int) ( (size - old_size)*m_sashGravity ); + if ( delta != 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); - } + int newPosition = m_sashPosition + delta; + if( newPosition < m_minimumPaneSize ) + newPosition = m_minimumPaneSize; + SetSashPositionAndNotify(newPosition); } if ( m_sashPosition >= size - 5 )