fixes to handling of 0 and negative splitter position when splitting it initially
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14344 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -237,8 +237,13 @@ protected:
|
|||||||
|
|
||||||
// get either width or height depending on the split mode
|
// get either width or height depending on the split mode
|
||||||
int GetWindowSize() const;
|
int GetWindowSize() const;
|
||||||
|
|
||||||
// set m_sashPosition w/ safeguards
|
// convert the user specified sash position which may be > 0 (as is), < 0
|
||||||
|
// (specifying the size of the right pane) or 0 (use default) to the real
|
||||||
|
// position to be passed to DoSetSashPosition()
|
||||||
|
int ConvertSashPosition(int sashPos) const;
|
||||||
|
|
||||||
|
// set the real sash position, sashPos here must be positive
|
||||||
void DoSetSashPosition(int sashPos);
|
void DoSetSashPosition(int sashPos);
|
||||||
|
|
||||||
wxSplitMode m_splitMode;
|
wxSplitMode m_splitMode;
|
||||||
|
@@ -186,6 +186,7 @@ MyFrame::MyFrame()
|
|||||||
m_right->Show(FALSE);
|
m_right->Show(FALSE);
|
||||||
m_splitter->Initialize(m_left);
|
m_splitter->Initialize(m_left);
|
||||||
#else
|
#else
|
||||||
|
// you can also try -100
|
||||||
m_splitter->SplitVertically(m_left, m_right, 100);
|
m_splitter->SplitVertically(m_left, m_right, 100);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -210,6 +211,8 @@ void MyFrame::SplitHorizontal(wxCommandEvent& WXUNUSED(event) )
|
|||||||
m_left->Show(TRUE);
|
m_left->Show(TRUE);
|
||||||
m_right->Show(TRUE);
|
m_right->Show(TRUE);
|
||||||
m_splitter->SplitHorizontally( m_left, m_right );
|
m_splitter->SplitHorizontally( m_left, m_right );
|
||||||
|
|
||||||
|
SetStatusText(_T("Splitter split horizontally"), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFrame::SplitVertical(wxCommandEvent& WXUNUSED(event) )
|
void MyFrame::SplitVertical(wxCommandEvent& WXUNUSED(event) )
|
||||||
@@ -219,6 +222,8 @@ void MyFrame::SplitVertical(wxCommandEvent& WXUNUSED(event) )
|
|||||||
m_left->Show(TRUE);
|
m_left->Show(TRUE);
|
||||||
m_right->Show(TRUE);
|
m_right->Show(TRUE);
|
||||||
m_splitter->SplitVertically( m_left, m_right );
|
m_splitter->SplitVertically( m_left, m_right );
|
||||||
|
|
||||||
|
SetStatusText(_T("Splitter split vertically"), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFrame::Unsplit(wxCommandEvent& WXUNUSED(event) )
|
void MyFrame::Unsplit(wxCommandEvent& WXUNUSED(event) )
|
||||||
|
@@ -718,13 +718,17 @@ int wxSplitterWindow::AdjustSashPosition(int sashPos) const
|
|||||||
|
|
||||||
void wxSplitterWindow::DoSetSashPosition(int sashPos)
|
void wxSplitterWindow::DoSetSashPosition(int sashPos)
|
||||||
{
|
{
|
||||||
m_requestedSashPosition = sashPos;
|
int newSashPosition = AdjustSashPosition(sashPos);
|
||||||
m_sashPosition = sashPos == 0 ? 0 : AdjustSashPosition(sashPos);
|
|
||||||
|
|
||||||
wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, this);
|
if ( newSashPosition != m_sashPosition )
|
||||||
event.m_data.pos = m_sashPosition;
|
{
|
||||||
|
m_sashPosition = newSashPosition;
|
||||||
|
|
||||||
(void)DoSendEvent(event);
|
wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, this);
|
||||||
|
event.m_data.pos = m_sashPosition;
|
||||||
|
|
||||||
|
(void)DoSendEvent(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Position and size subwindows.
|
// Position and size subwindows.
|
||||||
@@ -732,8 +736,21 @@ void wxSplitterWindow::DoSetSashPosition(int sashPos)
|
|||||||
// including the edges next to the sash.
|
// including the edges next to the sash.
|
||||||
void wxSplitterWindow::SizeWindows()
|
void wxSplitterWindow::SizeWindows()
|
||||||
{
|
{
|
||||||
if ( m_requestedSashPosition != m_sashPosition )
|
// check if we have delayed setting the real sash position
|
||||||
DoSetSashPosition(m_requestedSashPosition);
|
if ( m_requestedSashPosition != INT_MAX )
|
||||||
|
{
|
||||||
|
int newSashPosition = ConvertSashPosition(m_requestedSashPosition);
|
||||||
|
if ( newSashPosition != m_sashPosition )
|
||||||
|
{
|
||||||
|
DoSetSashPosition(newSashPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( newSashPosition == m_sashPosition )
|
||||||
|
{
|
||||||
|
// don't update it any more
|
||||||
|
m_requestedSashPosition = INT_MAX;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int w, h;
|
int w, h;
|
||||||
GetClientSize(&w, &h);
|
GetClientSize(&w, &h);
|
||||||
@@ -794,32 +811,39 @@ bool wxSplitterWindow::DoSplit(wxSplitMode mode,
|
|||||||
if ( IsSplit() )
|
if ( IsSplit() )
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
int window_size = GetWindowSize();
|
|
||||||
|
|
||||||
m_splitMode = mode;
|
m_splitMode = mode;
|
||||||
m_windowOne = window1;
|
m_windowOne = window1;
|
||||||
m_windowTwo = window2;
|
m_windowTwo = window2;
|
||||||
|
|
||||||
if ( sashPosition > 0 )
|
// remember the sash position we want to set for later if we can't set it
|
||||||
{
|
// right now (e.g. because the window is too small)
|
||||||
DoSetSashPosition(sashPosition);
|
m_requestedSashPosition = sashPosition;
|
||||||
}
|
|
||||||
else if ( sashPosition < 0 )
|
DoSetSashPosition(ConvertSashPosition(sashPosition));
|
||||||
{
|
|
||||||
// It's negative so adding is subtracting
|
|
||||||
DoSetSashPosition(window_size + sashPosition);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// default
|
|
||||||
DoSetSashPosition(window_size/2);
|
|
||||||
}
|
|
||||||
|
|
||||||
SizeWindows();
|
SizeWindows();
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int wxSplitterWindow::ConvertSashPosition(int sashPosition) const
|
||||||
|
{
|
||||||
|
if ( sashPosition > 0 )
|
||||||
|
{
|
||||||
|
return sashPosition;
|
||||||
|
}
|
||||||
|
else if ( sashPosition < 0 )
|
||||||
|
{
|
||||||
|
// It's negative so adding is subtracting
|
||||||
|
return GetWindowSize() + sashPosition;
|
||||||
|
}
|
||||||
|
else // sashPosition == 0
|
||||||
|
{
|
||||||
|
// default, put it in the centre
|
||||||
|
return GetWindowSize() / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Remove the specified (or second) window from the view
|
// Remove the specified (or second) window from the view
|
||||||
// Doesn't actually delete the window.
|
// Doesn't actually delete the window.
|
||||||
bool wxSplitterWindow::Unsplit(wxWindow *toRemove)
|
bool wxSplitterWindow::Unsplit(wxWindow *toRemove)
|
||||||
|
Reference in New Issue
Block a user