- // is the left/upper pane too small?
- if ( newSashPosition < m_minimumPaneSize )
- return NULL;
-
- // is the right/lower pane too small?
- int w, h;
- GetClientSize(&w, &h);
-
- if ( m_splitMode == wxSPLIT_VERTICAL )
- {
- if ( w - newSashPosition < m_minimumPaneSize )
- return FALSE;
- }
- else // m_splitMode = wxSPLIT_HORIZONTAL
- {
- if ( h - newSashPosition < m_minimumPaneSize )
- return FALSE;
- }
-
- // it's ok to move sash
- return TRUE;
+ // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
+ const int UNSPLIT_THRESHOLD = 4;
+
+ if (newSashPosition <= UNSPLIT_THRESHOLD) // threshold top / left check
+ {
+ newSashPosition = 0;
+ return TRUE;
+ }
+
+ // Obtain relevant window dimension for bottom / right threshold check
+ int w, h;
+ GetClientSize(&w, &h);
+ int window_size = (m_splitMode == wxSPLIT_VERTICAL) ? w : h ;
+
+ if ( newSashPosition >= window_size - UNSPLIT_THRESHOLD )
+ {
+ newSashPosition = window_size;
+ return TRUE;
+ }
+
+ // If resultant pane would be too small, enlarge it.
+
+ // Check upper / left pane
+ if ( newSashPosition < m_minimumPaneSize )
+ newSashPosition = m_minimumPaneSize; // NB: don't return just yet
+
+ // Check lower / right pane (check even if sash was just adjusted)
+ if ( newSashPosition > window_size - m_minimumPaneSize )
+ newSashPosition = window_size - m_minimumPaneSize;
+
+ // If the result is out of bounds it means minimum size is too big, so
+ // split window in half as best compromise.
+ if (newSashPosition < 0 || newSashPosition > window_size)
+ newSashPosition = window_size / 2;
+ return TRUE;