]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/splitter.cpp
Move code removing "-psn_xxx" command line arguments to common code.
[wxWidgets.git] / src / generic / splitter.cpp
index f4a4107e30a5beed6fa3a76d05691a3df278c182..826b92a7d808d71c42587edd245bbceed4186dc3 100644 (file)
@@ -4,7 +4,6 @@
 // Author:      Julian Smart
 // Modified by:
 // Created:     01/02/97
-// RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 #include <stdlib.h>
 
-wxDEFINE_EVENT( wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, wxSplitterEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING, wxSplitterEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_SPLITTER_DOUBLECLICKED, wxSplitterEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_SPLITTER_UNSPLIT, wxSplitterEvent );
+wxDEFINE_EVENT( wxEVT_SPLITTER_SASH_POS_CHANGED, wxSplitterEvent );
+wxDEFINE_EVENT( wxEVT_SPLITTER_SASH_POS_CHANGING, wxSplitterEvent );
+wxDEFINE_EVENT( wxEVT_SPLITTER_DOUBLECLICKED, wxSplitterEvent );
+wxDEFINE_EVENT( wxEVT_SPLITTER_UNSPLIT, wxSplitterEvent );
 
 IMPLEMENT_DYNAMIC_CLASS(wxSplitterWindow, wxWindow)
 
@@ -293,7 +292,7 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
                 m_windowOne = m_windowTwo;
                 m_windowTwo = NULL;
                 OnUnsplit(removedWindow);
-                wxSplitterEvent eventUnsplit(wxEVT_COMMAND_SPLITTER_UNSPLIT, this);
+                wxSplitterEvent eventUnsplit(wxEVT_SPLITTER_UNSPLIT, this);
                 eventUnsplit.m_data.win = removedWindow;
                 (void)DoSendEvent(eventUnsplit);
                 SetSashPositionAndNotify(0);
@@ -304,7 +303,7 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
                 wxWindow *removedWindow = m_windowTwo;
                 m_windowTwo = NULL;
                 OnUnsplit(removedWindow);
-                wxSplitterEvent eventUnsplit(wxEVT_COMMAND_SPLITTER_UNSPLIT, this);
+                wxSplitterEvent eventUnsplit(wxEVT_SPLITTER_UNSPLIT, this);
                 eventUnsplit.m_data.win = removedWindow;
                 (void)DoSendEvent(eventUnsplit);
                 SetSashPositionAndNotify(0);
@@ -451,20 +450,23 @@ void wxSplitterWindow::OnSize(wxSizeEvent& event)
         // 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);
             }
 
             // Also check if the second window became too small.
-            int adjustedPosition = AdjustSashPosition(m_sashPosition);
-            if ( adjustedPosition != m_sashPosition )
-                SetSashPositionAndNotify(adjustedPosition);
+            newPosition = AdjustSashPosition(newPosition == -1
+                                                 ? m_sashPosition
+                                                 : newPosition);
+            if ( newPosition != m_sashPosition )
+                SetSashPositionAndNotify(newPosition);
         }
     }
 
@@ -481,19 +483,29 @@ void wxSplitterWindow::SetSashGravity(double gravity)
     m_sashGravity = gravity;
 }
 
-bool wxSplitterWindow::SashHitTest(int x, int y, int tolerance)
+bool wxSplitterWindow::SashHitTest(int x, int y)
 {
     if ( m_windowTwo == NULL || m_sashPosition == 0)
         return false; // No sash
 
     int z = m_splitMode == wxSPLIT_VERTICAL ? x : y;
-    int hitMin = m_sashPosition - tolerance;
-    int hitMax = m_sashPosition + GetSashSize() + tolerance;
+    int hitMax = m_sashPosition + GetSashSize() - 1;
 
-    return z >=  hitMin && z <= hitMax;
+    return z >= m_sashPosition && z <= hitMax;
+}
+
+void wxSplitterWindow::SetSashInvisible(bool invisible)
+{
+    if ( IsSashInvisible() != invisible )
+        ToggleWindowStyle(wxSP_NOSASH);
 }
 
 int wxSplitterWindow::GetSashSize() const
+{
+    return IsSashInvisible() ? 0 : GetDefaultSashSize();
+}
+
+int wxSplitterWindow::GetDefaultSashSize() const
 {
     return wxRendererNative::Get().GetSplitterParams(this).widthSash;
 }
@@ -519,7 +531,7 @@ void wxSplitterWindow::DrawSash(wxDC& dc)
         return;
 
     // nor if we're configured to not show it
-    if ( HasFlag(wxSP_NOSASH) )
+    if ( IsSashInvisible() )
         return;
 
     wxRendererNative::Get().DrawSplitterSash
@@ -639,7 +651,7 @@ void wxSplitterWindow::SetSashPositionAndNotify(int sashPos)
     // must generate a CHANGED event at the end of resizing
     DoSetSashPosition(sashPos);
 
-    wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, this);
+    wxSplitterEvent event(wxEVT_SPLITTER_SASH_POS_CHANGED, this);
     event.m_data.pos = m_sashPosition;
 
     (void)DoSendEvent(event);
@@ -975,7 +987,7 @@ int wxSplitterWindow::OnSashPositionChanging(int newSashPosition)
     //
     // FIXME: shouldn't we do it before the adjustments above so as to ensure
     //        that the sash position is always reasonable?
-    wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING, this);
+    wxSplitterEvent event(wxEVT_SPLITTER_SASH_POS_CHANGING, this);
     event.m_data.pos = newSashPosition;
 
     if ( !DoSendEvent(event) )
@@ -999,7 +1011,7 @@ void wxSplitterWindow::OnDoubleClickSash(int x, int y)
     wxCHECK_RET(m_windowTwo, wxT("splitter: no window to remove"));
 
     // new code should handle events instead of using the virtual functions
-    wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED, this);
+    wxSplitterEvent event(wxEVT_SPLITTER_DOUBLECLICKED, this);
     event.m_data.pt.x = x;
     event.m_data.pt.y = y;
     if ( DoSendEvent(event) )
@@ -1009,7 +1021,7 @@ void wxSplitterWindow::OnDoubleClickSash(int x, int y)
             wxWindow* win = m_windowTwo;
             if ( Unsplit(win) )
             {
-                wxSplitterEvent unsplitEvent(wxEVT_COMMAND_SPLITTER_UNSPLIT, this);
+                wxSplitterEvent unsplitEvent(wxEVT_SPLITTER_UNSPLIT, this);
                 unsplitEvent.m_data.win = win;
                 (void)DoSendEvent(unsplitEvent);
             }
@@ -1033,7 +1045,7 @@ void wxSplitterWindow::OnSetCursor(wxSetCursorEvent& event)
     // and like this we explicitly say that our cursor should not be used for
     // children windows which overlap us
 
-    if ( SashHitTest(event.GetX(), event.GetY(), 0) )
+    if ( SashHitTest(event.GetX(), event.GetY()) )
     {
         // default processing is ok
         event.Skip();