Modified OnSashPositionChange to resize the window to minimum pane

size if the selected position would result in a too-small pane.
Edge-detection logic (which closes a split) moved from OnMouseEvent to
OnSashPositionChange.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2422 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Unknown (BV)
1999-05-12 03:03:26 +00:00
parent a9ac0bea5b
commit 4c0130922b

View File

@@ -140,10 +140,11 @@ void wxSplitterWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
DrawSash(dc); DrawSash(dc);
} }
void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event) void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
{ {
long x, y; long x = event.GetX();
event.Position(&x, &y); long y = event.GetY();
// reset the cursor // reset the cursor
#ifdef __WXMOTIF__ #ifdef __WXMOTIF__
@@ -186,24 +187,27 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
// Erase old tracker // Erase old tracker
DrawSashTracker(m_oldX, m_oldY); DrawSashTracker(m_oldX, m_oldY);
// Obtain window size. We are only interested in the dimension the sash
// splits up
int w, h; int w, h;
GetClientSize(&w, &h); GetClientSize(&w, &h);
if ( m_splitMode == wxSPLIT_VERTICAL ) int window_size = (m_splitMode == wxSPLIT_VERTICAL ? w : h );
{ int new_sash_position =
if ( !OnSashPositionChange(x) ) (int) ( m_splitMode == wxSPLIT_VERTICAL ? x : y );
if ( !OnSashPositionChange(new_sash_position) )
return; return;
if ( x <= 4 ) if ( new_sash_position == 0 )
{ {
// We remove the first window from the view // We remove the first window from the view
wxWindow *removedWindow = m_windowOne; wxWindow *removedWindow = m_windowOne;
m_windowOne = m_windowTwo; m_windowOne = m_windowTwo;
m_windowTwo = (wxWindow *) NULL; m_windowTwo = (wxWindow *) NULL;
OnUnsplit(removedWindow); OnUnsplit(removedWindow);
m_sashPosition = 0; m_sashPosition = 0;
} }
else if ( x >= (w - 4) ) else if ( new_sash_position == window_size )
{ {
// We remove the second window from the view // We remove the second window from the view
wxWindow *removedWindow = m_windowTwo; wxWindow *removedWindow = m_windowTwo;
@@ -213,37 +217,8 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
} }
else else
{ {
m_sashPosition = x; m_sashPosition = new_sash_position;
} }
}
else // m_splitMode == wxSPLIT_VERTICAL
{
if ( !OnSashPositionChange(y) )
return;
if ( y <= 4 )
{
// We remove the first window from the view
wxWindow *removedWindow = m_windowOne;
m_windowOne = m_windowTwo;
m_windowTwo = (wxWindow *) NULL;
OnUnsplit(removedWindow);
m_sashPosition = 0;
}
else if ( y >= (h - 4) )
{
// We remove the second window from the view
wxWindow *removedWindow = m_windowTwo;
m_windowTwo = (wxWindow *) NULL;
OnUnsplit(removedWindow);
m_sashPosition = 0;
}
else
{
m_sashPosition = y;
}
} // m_splitMode == wxSPLIT_VERTICAL
SizeWindows(); SizeWindows();
} // left up && dragging } // left up && dragging
else if (event.Moving() && !event.Dragging()) else if (event.Moving() && !event.Dragging())
@@ -669,28 +644,42 @@ void wxSplitterWindow::SetSashPosition(int position, bool redraw)
} }
} }
bool wxSplitterWindow::OnSashPositionChange(int newSashPosition) bool wxSplitterWindow::OnSashPositionChange(int& newSashPosition)
{ {
// is the left/upper pane too small? // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
if ( newSashPosition < m_minimumPaneSize ) const int UNSPLIT_THRESHOLD = 4;
return NULL;
// is the right/lower pane too small? if (newSashPosition <= UNSPLIT_THRESHOLD) // threshold top / left check
{
newSashPosition = 0;
return TRUE;
}
// Obtain relevant window dimension for bottom / right threshold check
int w, h; int w, h;
GetClientSize(&w, &h); GetClientSize(&w, &h);
int window_size = (m_splitMode == wxSPLIT_VERTICAL) ? w : h ;
if ( m_splitMode == wxSPLIT_VERTICAL ) if ( newSashPosition >= window_size - UNSPLIT_THRESHOLD )
{ {
if ( w - newSashPosition < m_minimumPaneSize ) newSashPosition = window_size;
return FALSE; return TRUE;
}
else // m_splitMode = wxSPLIT_HORIZONTAL
{
if ( h - newSashPosition < m_minimumPaneSize )
return FALSE;
} }
// it's ok to move sash // 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; return TRUE;
} }