/////////////////////////////////////////////////////////////////////////////
-// Name: splitter.cpp
+// Name: src/generic/splitter.cpp
// Purpose: wxSplitterWindow implementation
// Author: Julian Smart
// Modified by:
m_borderSize = 2;
m_sashPosition = m_requestedSashPosition = 0;
m_minimumPaneSize = 0;
- m_sashCursorWE = new wxCursor(wxCURSOR_SIZEWE);
- m_sashCursorNS = new wxCursor(wxCURSOR_SIZENS);
+ m_sashCursorWE = wxCursor(wxCURSOR_SIZEWE);
+ m_sashCursorNS = wxCursor(wxCURSOR_SIZENS);
m_sashTrackerPen = new wxPen(*wxBLACK, 2, wxSOLID);
m_lightShadowPen = (wxPen *) NULL;
m_mediumShadowPen = (wxPen *) NULL;
wxSplitterWindow::~wxSplitterWindow()
{
- delete m_sashCursorWE;
- delete m_sashCursorNS;
delete m_sashTrackerPen;
delete m_lightShadowPen;
delete m_darkShadowPen;
delete m_faceBrush;
}
+void wxSplitterWindow::SetResizeCursor()
+{
+ SetCursor(m_splitMode == wxSPLIT_VERTICAL ? m_sashCursorWE
+ : m_sashCursorNS);
+}
+
void wxSplitterWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
{
wxPaintDC dc(this);
// reset the cursor
#ifdef __WXMOTIF__
SetCursor(* wxSTANDARD_CURSOR);
-#endif
-#ifdef __WXMSW__
+#elif defined(__WXMSW__)
SetCursor(wxCursor());
#endif
if (GetWindowStyle() & wxSP_NOSASH)
return;
+ // with wxSP_LIVE_UPDATE style the splitter windows are always resized
+ // following the mouse movement while it drags the sash, without it we only
+ // draw the sash at the new position but only resize the windows when the
+ // dragging is finished
+ bool isLive = (GetWindowStyleFlag() & wxSP_LIVE_UPDATE) != 0;
+
if (event.LeftDown())
{
if ( SashHitTest(x, y) )
m_dragMode = wxSPLIT_DRAG_DRAGGING;
- if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE) == 0)
+ if ( !isLive )
{
+ // remember the initial sash position and draw the initial
+ // shadow sash
+ m_sashPositionCurrent = m_sashPosition;
+
DrawSashTracker(x, y);
}
m_oldX = x;
m_oldY = y;
- if ( m_splitMode == wxSPLIT_VERTICAL )
- {
- SetCursor(*m_sashCursorWE);
- }
- else
- {
- SetCursor(*m_sashCursorNS);
- }
+ SetResizeCursor();
return;
}
}
ReleaseMouse();
// Erase old tracker
- if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE) == 0)
+ if ( !isLive )
{
DrawSashTracker(m_oldX, m_oldY);
}
// mouse has moved
int diff = m_splitMode == wxSPLIT_VERTICAL ? x - m_oldX : y - m_oldY;
- int posSashNew = OnSashPositionChanging(m_sashPosition + diff);
+ int posSashOld = isLive ? m_sashPosition : m_sashPositionCurrent;
+ int posSashNew = OnSashPositionChanging(posSashOld + diff);
if ( posSashNew == -1 )
{
// change not allowed
m_windowOne = m_windowTwo;
m_windowTwo = (wxWindow *) NULL;
OnUnsplit(removedWindow);
- DoSetSashPosition(0);
+ SetSashPositionAndNotify(0);
}
else if ( posSashNew == GetWindowSize() )
{
wxWindow *removedWindow = m_windowTwo;
m_windowTwo = (wxWindow *) NULL;
OnUnsplit(removedWindow);
- DoSetSashPosition(0);
+ SetSashPositionAndNotify(0);
}
else
{
- DoSetSashPosition(posSashNew);
+ SetSashPositionAndNotify(posSashNew);
}
}
else
{
- DoSetSashPosition(posSashNew);
+ SetSashPositionAndNotify(posSashNew);
}
SizeWindows();
// Just change the cursor if required
if ( SashHitTest(x, y) )
{
- if ( m_splitMode == wxSPLIT_VERTICAL )
- {
- SetCursor(*m_sashCursorWE);
- }
- else
- {
- SetCursor(*m_sashCursorNS);
- }
+ SetResizeCursor();
}
#if defined(__WXGTK__) || defined(__WXMSW__)
else
#ifdef __WXMSW__
// Otherwise, the cursor sometimes reverts to the normal cursor
// during dragging.
- if ( m_splitMode == wxSPLIT_VERTICAL )
- {
- SetCursor(*m_sashCursorWE);
- }
- else
- {
- SetCursor(*m_sashCursorNS);
- }
+ SetResizeCursor();
#endif // __WXMSW__
int diff = m_splitMode == wxSPLIT_VERTICAL ? x - m_oldX : y - m_oldY;
- int posSashNew = OnSashPositionChanging(m_sashPosition + diff);
+ int posSashOld = isLive ? m_sashPosition : m_sashPositionCurrent;
+ int posSashNew = OnSashPositionChanging(posSashOld + diff);
if ( posSashNew == -1 )
{
// change not allowed
return;
// Erase old tracker
- if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE) == 0)
+ if ( !isLive )
{
DrawSashTracker(m_oldX, m_oldY);
}
#endif // __WXMSW__
// Draw new one
- if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE) == 0)
+ if ( !isLive )
{
+ m_sashPositionCurrent = posSashNew;
+
DrawSashTracker(m_oldX, m_oldY);
}
else
{
- DoSetSashPosition(posSashNew);
+ SetSashPositionAndNotify(posSashNew);
m_needUpdating = TRUE;
}
}
iconized = FALSE;
}
#endif
-
+
if ( iconized )
{
event.Skip();
if ( m_splitMode == wxSPLIT_VERTICAL )
{
if ( m_sashPosition >= (cw - 5) )
- DoSetSashPosition(wxMax(10, cw - 40));
+ SetSashPositionAndNotify(wxMax(10, cw - 40));
}
else // m_splitMode == wxSPLIT_HORIZONTAL
{
if ( m_sashPosition >= (ch - 5) )
- DoSetSashPosition(wxMax(10, ch - 40));
+ SetSashPositionAndNotify(wxMax(10, ch - 40));
}
}
return sashPos;
}
-void wxSplitterWindow::DoSetSashPosition(int sashPos)
+bool wxSplitterWindow::DoSetSashPosition(int sashPos)
{
int newSashPosition = AdjustSashPosition(sashPos);
- if ( newSashPosition != m_sashPosition )
- {
- m_sashPosition = newSashPosition;
+ if ( newSashPosition == m_sashPosition )
+ return FALSE;
+
+ m_sashPosition = newSashPosition;
+ return TRUE;
+}
+
+void wxSplitterWindow::SetSashPositionAndNotify(int sashPos)
+{
+ if ( DoSetSashPosition(sashPos) )
+ {
wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, this);
event.m_data.pos = m_sashPosition;
if ( GetWindow1() && !GetWindow2() )
{
- GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
+ GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
w - 2*GetBorderSize(), h - 2*GetBorderSize());
}
else if ( GetWindow1() && GetWindow2() )
// Set pane for unsplit window
void wxSplitterWindow::Initialize(wxWindow *window)
{
+ wxASSERT_MSG( window->GetParent() == this,
+ _T("windows in the splitter should have it as parent!") );
+
m_windowOne = window;
m_windowTwo = (wxWindow *) NULL;
DoSetSashPosition(0);
if ( IsSplit() )
return FALSE;
+ wxASSERT_MSG( window1->GetParent() == this && window2->GetParent() == this,
+ _T("windows in the splitter should have it as parent!") );
+
m_splitMode = mode;
m_windowOne = window1;
m_windowTwo = window2;