#if defined( __WXMSW__ ) || defined( __WXMAC__)
EVT_SET_CURSOR(wxSplitterWindow::OnSetCursor)
#endif // wxMSW
-
- WX_EVENT_TABLE_CONTROL_CONTAINER(wxSplitterWindow)
END_EVENT_TABLE()
-WX_DELEGATE_TO_CONTROL_CONTAINER(wxSplitterWindow, wxWindow)
-
static bool IsLive(wxSplitterWindow* wnd)
{
// with wxSP_LIVE_UPDATE style the splitter windows are always resized
// allow TABbing from one window to the other
style |= wxTAB_TRAVERSAL;
- // we draw our border ourselves to blend the sash with it
- style &= ~wxBORDER_MASK;
- style |= wxBORDER_NONE;
-
-
if ( !wxWindow::Create(parent, id, pos, size, style, name) )
return false;
- if (size.x >= 0)
- m_lastSize.x = size.x;
- if (size.y >= 0)
- m_lastSize.y = size.y;
+ m_lastSize = GetClientSize();
m_permitUnsplitAlways = (style & wxSP_PERMIT_UNSPLIT) != 0;
void wxSplitterWindow::Init()
{
- WX_INIT_CONTROL_CONTAINER();
-
m_splitMode = wxSPLIT_VERTICAL;
m_permitUnsplitAlways = true;
m_windowOne = NULL;
m_oldX = 0;
m_oldY = 0;
m_sashStart = 0;
- m_sashPosition = m_requestedSashPosition = 0;
+ m_sashPosition = 0;
+ m_requestedSashPosition = INT_MAX;
m_sashGravity = 0.0;
- m_sashSize = -1; // -1 means use the native sash size
m_lastSize = wxSize(0,0);
- m_checkRequestedSashPosition = false;
m_minimumPaneSize = 0;
m_sashCursorWE = wxCursor(wxCURSOR_SIZEWE);
m_sashCursorNS = wxCursor(wxCURSOR_SIZENS);
void wxSplitterWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
{
wxPaintDC dc(this);
+#ifdef __WXOSX__
+ // as subpanels might have a transparent background we must erase the background
+ // at least on OSX, otherwise traces of the sash will remain
+ // test with: splitter sample->replace right window
+ dc.Clear();
+#endif
DrawSash(dc);
}
{
wxWindow::OnInternalIdle();
- // if this is the first idle time after a sash position has potentially
- // been set, allow SizeWindows to check for a requested size.
- if (!m_checkRequestedSashPosition)
+ // We may need to update the children sizes in two cases: either because
+ // we're in the middle of a live update as indicated by m_needUpdating or
+ // because we have a requested but not yet set sash position as indicated
+ // by m_requestedSashPosition having a valid value.
+ if ( m_needUpdating )
{
- m_checkRequestedSashPosition = true;
- SizeWindows();
- return; // it won't needUpdating in this case
+ m_needUpdating = false;
+ }
+ else if ( m_requestedSashPosition == INT_MAX )
+ {
+ // We don't need to resize the children.
+ return;
}
- if (m_needUpdating)
- SizeWindows();
+ SizeWindows();
}
void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
return;
}
- if ( m_windowTwo )
- {
- int w, h;
- GetClientSize(&w, &h);
+ const wxSize curSize = event.GetSize();
- int size = m_splitMode == wxSPLIT_VERTICAL ? w : h;
+ // Update the sash position if needed.
+ //
+ // Notice that we shouldn't do this if the sash position requested by user
+ // couldn't be set yet as it would never be taken into account at all if we
+ // modified it before this happens.
+ if ( m_windowTwo && m_requestedSashPosition == INT_MAX )
+ {
+ int size = m_splitMode == wxSPLIT_VERTICAL ? curSize.x : curSize.y;
int old_size = m_splitMode == wxSPLIT_VERTICAL ? m_lastSize.x : m_lastSize.y;
- if ( old_size != 0 )
+
+ // Don't do anything if the size didn't really change.
+ if ( size != old_size )
{
+ int newPosition = -1;
+
+ // Apply gravity if we use it.
int delta = (int) ( (size - old_size)*m_sashGravity );
if ( delta != 0 )
{
- int newPosition = m_sashPosition + delta;
+ newPosition = m_sashPosition + delta;
if( newPosition < m_minimumPaneSize )
newPosition = m_minimumPaneSize;
- SetSashPositionAndNotify(newPosition);
}
- }
- if ( m_sashPosition >= size - 5 )
- SetSashPositionAndNotify(wxMax(10, size - 40));
- m_lastSize = wxSize(w,h);
+ // Also check if the second window became too small.
+ newPosition = AdjustSashPosition(newPosition == -1
+ ? m_sashPosition
+ : newPosition);
+ if ( newPosition != m_sashPosition )
+ SetSashPositionAndNotify(newPosition);
+ }
}
+ m_lastSize = curSize;
+
SizeWindows();
}
return z >= hitMin && z <= hitMax;
}
+void wxSplitterWindow::SetSashInvisible(bool invisible)
+{
+ if ( IsSashInvisible() != invisible )
+ ToggleWindowStyle(wxSP_NOSASH);
+}
+
int wxSplitterWindow::GetSashSize() const
{
- return m_sashSize > -1 ? m_sashSize : wxRendererNative::Get().GetSplitterParams(this).widthSash;
+ return IsSashInvisible() ? 0 : GetDefaultSashSize();
+}
+
+int wxSplitterWindow::GetDefaultSashSize() const
+{
+ return wxRendererNative::Get().GetSplitterParams(this).widthSash;
}
int wxSplitterWindow::GetBorderSize() const
return;
// nor if we're configured to not show it
- if ( HasFlag(wxSP_NOSASH) )
+ if ( IsSashInvisible() )
return;
wxRendererNative::Get().DrawSplitterSash
void wxSplitterWindow::SizeWindows()
{
// check if we have delayed setting the real sash position
- if ( m_checkRequestedSashPosition && m_requestedSashPosition != INT_MAX )
+ if ( m_requestedSashPosition != INT_MAX )
{
int newSashPosition = ConvertSashPosition(m_requestedSashPosition);
if ( newSashPosition != m_sashPosition )
wxClientDC dc(this);
DrawSash(dc);
-
- SetNeedUpdating(false);
}
// Set pane for unsplit window
return false;
wxCHECK_MSG( window1 && window2, false,
- wxT("can not split with NULL window(s)") );
+ wxT("cannot split with NULL window(s)") );
wxCHECK_MSG( window1->GetParent() == this && window2->GetParent() == this, false,
wxT("windows in the splitter should have it as parent!") );
// 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 = position;
- m_checkRequestedSashPosition = false;
DoSetSashPosition(ConvertSashPosition(position));
// window is shown, if you know the overall size is correct.
void wxSplitterWindow::UpdateSize()
{
- m_checkRequestedSashPosition = true;
SizeWindows();
- m_checkRequestedSashPosition = false;
}
bool wxSplitterWindow::DoSendEvent(wxSplitterEvent& event)