// 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;
m_right->Show(FALSE);
m_splitter->Initialize(m_left);
#else
+ // you can also try -100
m_splitter->SplitVertically(m_left, m_right, 100);
#endif
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) )
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) )
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.
// 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);
if ( IsSplit() )
return FALSE;
- int window_size = GetWindowSize();
-
m_splitMode = mode;
m_windowOne = window1;
m_windowTwo = window2;
+ // 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 )
{
- DoSetSashPosition(sashPosition);
+ return sashPosition;
}
else if ( sashPosition < 0 )
{
// It's negative so adding is subtracting
- DoSetSashPosition(window_size + sashPosition);
+ return GetWindowSize() + sashPosition;
}
- else
+ else // sashPosition == 0
{
- // default
- DoSetSashPosition(window_size/2);
+ // default, put it in the centre
+ return GetWindowSize() / 2;
}
-
- SizeWindows();
-
- return TRUE;
}
// Remove the specified (or second) window from the view