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,64 +187,38 @@ 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 =
(int) ( m_splitMode == wxSPLIT_VERTICAL ? x : y );
if ( !OnSashPositionChange(new_sash_position) )
return;
if ( new_sash_position == 0 )
{ {
if ( !OnSashPositionChange(x) ) // We remove the first window from the view
return; wxWindow *removedWindow = m_windowOne;
m_windowOne = m_windowTwo;
if ( x <= 4 ) m_windowTwo = (wxWindow *) NULL;
{ OnUnsplit(removedWindow);
// We remove the first window from the view m_sashPosition = 0;
wxWindow *removedWindow = m_windowOne;
m_windowOne = m_windowTwo;
m_windowTwo = (wxWindow *) NULL;
OnUnsplit(removedWindow);
m_sashPosition = 0;
}
else if ( x >= (w - 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 = x;
}
} }
else // m_splitMode == wxSPLIT_VERTICAL else if ( new_sash_position == window_size )
{ {
if ( !OnSashPositionChange(y) ) // We remove the second window from the view
return; wxWindow *removedWindow = m_windowTwo;
m_windowTwo = (wxWindow *) NULL;
if ( y <= 4 ) OnUnsplit(removedWindow);
{ m_sashPosition = 0;
// We remove the first window from the view }
wxWindow *removedWindow = m_windowOne; else
m_windowOne = m_windowTwo; {
m_windowTwo = (wxWindow *) NULL; m_sashPosition = new_sash_position;
}
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,29 +644,43 @@ 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
int w, h; {
GetClientSize(&w, &h); newSashPosition = 0;
return TRUE;
}
if ( m_splitMode == wxSPLIT_VERTICAL ) // Obtain relevant window dimension for bottom / right threshold check
{ int w, h;
if ( w - newSashPosition < m_minimumPaneSize ) GetClientSize(&w, &h);
return FALSE; int window_size = (m_splitMode == wxSPLIT_VERTICAL) ? w : h ;
}
else // m_splitMode = wxSPLIT_HORIZONTAL
{
if ( h - newSashPosition < m_minimumPaneSize )
return FALSE;
}
// it's ok to move sash if ( newSashPosition >= window_size - UNSPLIT_THRESHOLD )
return TRUE; {
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;
} }
// Called when the sash is double-clicked. // Called when the sash is double-clicked.