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:
parent
689fceb7a7
commit
74c57d1ff6
@ -237,8 +237,13 @@ protected:
|
||||
|
||||
// get either width or height depending on the split mode
|
||||
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);
|
||||
|
||||
wxSplitMode m_splitMode;
|
||||
|
@ -186,6 +186,7 @@ MyFrame::MyFrame()
|
||||
m_right->Show(FALSE);
|
||||
m_splitter->Initialize(m_left);
|
||||
#else
|
||||
// you can also try -100
|
||||
m_splitter->SplitVertically(m_left, m_right, 100);
|
||||
#endif
|
||||
|
||||
@ -210,6 +211,8 @@ void MyFrame::SplitHorizontal(wxCommandEvent& WXUNUSED(event) )
|
||||
m_left->Show(TRUE);
|
||||
m_right->Show(TRUE);
|
||||
m_splitter->SplitHorizontally( m_left, m_right );
|
||||
|
||||
SetStatusText(_T("Splitter split horizontally"), 1);
|
||||
}
|
||||
|
||||
void MyFrame::SplitVertical(wxCommandEvent& WXUNUSED(event) )
|
||||
@ -219,6 +222,8 @@ void MyFrame::SplitVertical(wxCommandEvent& WXUNUSED(event) )
|
||||
m_left->Show(TRUE);
|
||||
m_right->Show(TRUE);
|
||||
m_splitter->SplitVertically( m_left, m_right );
|
||||
|
||||
SetStatusText(_T("Splitter split vertically"), 1);
|
||||
}
|
||||
|
||||
void MyFrame::Unsplit(wxCommandEvent& WXUNUSED(event) )
|
||||
|
@ -718,13 +718,17 @@ int wxSplitterWindow::AdjustSashPosition(int sashPos) const
|
||||
|
||||
void wxSplitterWindow::DoSetSashPosition(int sashPos)
|
||||
{
|
||||
m_requestedSashPosition = sashPos;
|
||||
m_sashPosition = sashPos == 0 ? 0 : AdjustSashPosition(sashPos);
|
||||
int newSashPosition = AdjustSashPosition(sashPos);
|
||||
|
||||
wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, this);
|
||||
event.m_data.pos = m_sashPosition;
|
||||
if ( newSashPosition != 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.
|
||||
@ -732,8 +736,21 @@ void wxSplitterWindow::DoSetSashPosition(int sashPos)
|
||||
// including the edges next to the sash.
|
||||
void wxSplitterWindow::SizeWindows()
|
||||
{
|
||||
if ( m_requestedSashPosition != m_sashPosition )
|
||||
DoSetSashPosition(m_requestedSashPosition);
|
||||
// check if we have delayed setting the real sash position
|
||||
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;
|
||||
GetClientSize(&w, &h);
|
||||
@ -794,32 +811,39 @@ bool wxSplitterWindow::DoSplit(wxSplitMode mode,
|
||||
if ( IsSplit() )
|
||||
return FALSE;
|
||||
|
||||
int window_size = GetWindowSize();
|
||||
|
||||
m_splitMode = mode;
|
||||
m_windowOne = window1;
|
||||
m_windowTwo = window2;
|
||||
|
||||
if ( sashPosition > 0 )
|
||||
{
|
||||
DoSetSashPosition(sashPosition);
|
||||
}
|
||||
else if ( sashPosition < 0 )
|
||||
{
|
||||
// It's negative so adding is subtracting
|
||||
DoSetSashPosition(window_size + sashPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
// default
|
||||
DoSetSashPosition(window_size/2);
|
||||
}
|
||||
// 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)
|
||||
m_requestedSashPosition = sashPosition;
|
||||
|
||||
DoSetSashPosition(ConvertSashPosition(sashPosition));
|
||||
|
||||
SizeWindows();
|
||||
|
||||
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
|
||||
// Doesn't actually delete the window.
|
||||
bool wxSplitterWindow::Unsplit(wxWindow *toRemove)
|
||||
|
Loading…
Reference in New Issue
Block a user