X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/74c57d1ff65edd1da6f4f8d30be55db47f6d27a7..f0834140313212fc54d09e28d21a95476d6545f2:/src/generic/splitter.cpp diff --git a/src/generic/splitter.cpp b/src/generic/splitter.cpp index 448d795d35..c5d099a54c 100644 --- a/src/generic/splitter.cpp +++ b/src/generic/splitter.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: splitter.cpp +// Name: src/generic/splitter.cpp // Purpose: wxSplitterWindow implementation // Author: Julian Smart // Modified by: @@ -21,19 +21,22 @@ #endif #ifndef WX_PRECOMP + #include "wx/string.h" + #include "wx/utils.h" + #include "wx/log.h" + + #include "wx/dcscreen.h" + #include "wx/window.h" #include "wx/dialog.h" #include "wx/frame.h" -#endif -#include + #include "wx/settings.h" +#endif -#include "wx/string.h" #include "wx/splitter.h" -#include "wx/dcscreen.h" -#include "wx/settings.h" -#include "wx/log.h" -#include "wx/utils.h" + +#include DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED) DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING) @@ -107,12 +110,12 @@ void wxSplitterWindow::Init() m_oldY = 0; m_firstX = 0; m_firstY = 0; - m_sashSize = 7; - m_borderSize = 2; + m_sashSize = 3; + m_borderSize = 0; 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; @@ -121,9 +124,6 @@ void wxSplitterWindow::Init() m_facePen = (wxPen *) NULL; m_hilightPen = (wxPen *) NULL; - m_borderSize = 0; - m_sashSize = 3; - InitColours(); m_needUpdating = FALSE; @@ -131,8 +131,6 @@ void wxSplitterWindow::Init() wxSplitterWindow::~wxSplitterWindow() { - delete m_sashCursorWE; - delete m_sashCursorNS; delete m_sashTrackerPen; delete m_lightShadowPen; delete m_darkShadowPen; @@ -142,6 +140,12 @@ wxSplitterWindow::~wxSplitterWindow() delete m_faceBrush; } +void wxSplitterWindow::SetResizeCursor() +{ + SetCursor(m_splitMode == wxSPLIT_VERTICAL ? m_sashCursorWE + : m_sashCursorNS); +} + void wxSplitterWindow::OnPaint(wxPaintEvent& WXUNUSED(event)) { wxPaintDC dc(this); @@ -165,16 +169,21 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event) y = (int)event.GetY(); // reset the cursor -#ifdef __WXMOTIF__ +#if defined( __WXMOTIF__ ) || defined( __WXGTK__ ) || defined( __WXMAC__ ) 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) ) @@ -183,22 +192,19 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event) 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; } } @@ -208,8 +214,14 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event) m_dragMode = wxSPLIT_DRAG_NONE; ReleaseMouse(); + // exit if unsplit after doubleclick + if ( !IsSplit() ) + { + return; + } + // Erase old tracker - if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE) == 0) + if ( !isLive ) { DrawSashTracker(m_oldX, m_oldY); } @@ -219,7 +231,8 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event) // 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 @@ -236,7 +249,7 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event) m_windowOne = m_windowTwo; m_windowTwo = (wxWindow *) NULL; OnUnsplit(removedWindow); - DoSetSashPosition(0); + SetSashPositionAndNotify(0); } else if ( posSashNew == GetWindowSize() ) { @@ -244,16 +257,16 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event) 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(); @@ -263,16 +276,9 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event) // 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__) +#if defined(__WXGTK__) || defined(__WXMSW__) || defined(__WXMAC__) else { // We must set the normal cursor in MSW, because @@ -287,22 +293,21 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event) } else if (event.Dragging() && (m_dragMode == wxSPLIT_DRAG_DRAGGING)) { -#ifdef __WXMSW__ +#if defined( __WXMSW__ ) || defined( __WXMAC__ ) // 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; + if ( !diff ) + { + // nothing to do, mouse didn't really move far enough + return; + } - int posSashNew = OnSashPositionChanging(m_sashPosition + diff); + int posSashOld = isLive ? m_sashPosition : m_sashPositionCurrent; + int posSashNew = OnSashPositionChanging(posSashOld + diff); if ( posSashNew == -1 ) { // change not allowed @@ -313,7 +318,7 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event) return; // Erase old tracker - if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE) == 0) + if ( !isLive ) { DrawSashTracker(m_oldX, m_oldY); } @@ -341,13 +346,15 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event) #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; } } @@ -388,7 +395,7 @@ void wxSplitterWindow::OnSize(wxSizeEvent& event) iconized = FALSE; } #endif - + if ( iconized ) { event.Skip(); @@ -403,12 +410,12 @@ void wxSplitterWindow::OnSize(wxSizeEvent& event) 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)); } } @@ -536,7 +543,7 @@ void wxSplitterWindow::DrawSash(wxDC& dc) dc.DrawLine(m_sashPosition+1, h-m_borderSize-1, m_sashPosition+m_sashSize-1, h-m_borderSize-1); } } - else + else // wxSPLIT_HORIZONTAL { dc.SetPen(*m_facePen); if (HasFlag( wxSP_SASH_AQUA )) @@ -576,12 +583,12 @@ void wxSplitterWindow::DrawSash(wxDC& dc) } } } - else + else // !wxSP_3DSASH { + dc.SetPen(*wxTRANSPARENT_PEN); + dc.SetBrush(*m_faceBrush); if ( m_splitMode == wxSPLIT_VERTICAL ) { - dc.SetPen(*wxBLACK_PEN); - dc.SetBrush(*wxBLACK_BRUSH); int h1 = h-1; int y1 = 0; if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER && (GetWindowStyleFlag() & wxSP_3DBORDER) != wxSP_3DBORDER ) @@ -592,10 +599,8 @@ void wxSplitterWindow::DrawSash(wxDC& dc) } dc.DrawRectangle(m_sashPosition, y1, m_sashSize, h1); } - else + else // wxSPLIT_HORIZONTAL { - dc.SetPen(*wxBLACK_PEN); - dc.SetBrush(*wxBLACK_BRUSH); int w1 = w-1; int x1 = 0; if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER && (GetWindowStyleFlag() & wxSP_3DBORDER) != wxSP_3DBORDER ) @@ -606,7 +611,6 @@ void wxSplitterWindow::DrawSash(wxDC& dc) } dc.DrawRectangle(x1, m_sashPosition, w1, m_sashSize); } - } dc.SetPen(wxNullPen); @@ -716,14 +720,22 @@ int wxSplitterWindow::AdjustSashPosition(int sashPos) const 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; @@ -745,7 +757,8 @@ void wxSplitterWindow::SizeWindows() DoSetSashPosition(newSashPosition); } - if ( newSashPosition == m_sashPosition ) + if ( newSashPosition <= m_sashPosition + && newSashPosition >= m_sashPosition - GetBorderSize() ) { // don't update it any more m_requestedSashPosition = INT_MAX; @@ -757,7 +770,7 @@ void wxSplitterWindow::SizeWindows() if ( GetWindow1() && !GetWindow2() ) { - GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(), + GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(), w - 2*GetBorderSize(), h - 2*GetBorderSize()); } else if ( GetWindow1() && GetWindow2() ) @@ -796,6 +809,9 @@ void wxSplitterWindow::SizeWindows() // Set pane for unsplit window void wxSplitterWindow::Initialize(wxWindow *window) { + wxASSERT_MSG( window && window->GetParent() == this, + _T("windows in the splitter should have it as parent!") ); + m_windowOne = window; m_windowTwo = (wxWindow *) NULL; DoSetSashPosition(0); @@ -811,6 +827,12 @@ bool wxSplitterWindow::DoSplit(wxSplitMode mode, if ( IsSplit() ) return FALSE; + wxCHECK_MSG( window1 && window2, FALSE, + _T("can not split with NULL window(s)") ); + + wxCHECK_MSG( window1->GetParent() == this && window2->GetParent() == this, FALSE, + _T("windows in the splitter should have it as parent!") ); + m_splitMode = mode; m_windowOne = window1; m_windowTwo = window2;