]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/splitter.cpp
wxDropSource should have def ctor
[wxWidgets.git] / src / generic / splitter.cpp
index 4360b6c9b9e1a07467a01ffe850044a3f0061d66..f806238232c59104802fade4d575b2c43acd3750 100644 (file)
@@ -32,8 +32,8 @@
 #include "wx/splitter.h"
 #include "wx/dcscreen.h"
 #include "wx/settings.h"
+#include "wx/log.h"
 
-#if !USE_SHARED_LIBRARY
 IMPLEMENT_DYNAMIC_CLASS(wxSplitterWindow, wxWindow)
 IMPLEMENT_DYNAMIC_CLASS(wxSplitterEvent, wxCommandEvent)
 
@@ -43,6 +43,8 @@ BEGIN_EVENT_TABLE(wxSplitterWindow, wxWindow)
     EVT_IDLE(wxSplitterWindow::OnIdle)
     EVT_MOUSE_EVENTS(wxSplitterWindow::OnMouseEvent)
 
+    EVT_SET_CURSOR(wxSplitterWindow::OnSetCursor)
+
     EVT_SPLITTER_SASH_POS_CHANGED(-1, wxSplitterWindow::OnSashPosChanged)
     // NB: we borrow OnSashPosChanged for purposes of
     // EVT_SPLITTER_SASH_POS_CHANGING since default implementation is identical
@@ -50,7 +52,6 @@ BEGIN_EVENT_TABLE(wxSplitterWindow, wxWindow)
     EVT_SPLITTER_DCLICK(-1,           wxSplitterWindow::OnDoubleClick)
     EVT_SPLITTER_UNSPLIT(-1,          wxSplitterWindow::OnUnsplitEvent)
 END_EVENT_TABLE()
-#endif
 
 wxSplitterWindow::wxSplitterWindow()
 {
@@ -164,8 +165,8 @@ void wxSplitterWindow::OnIdle(wxIdleEvent& WXUNUSED(event))
 
 void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
 {
-    long x = event.GetX();
-    long y = event.GetY();
+    wxCoord x = (wxCoord)event.GetX(),
+            y = (wxCoord)event.GetY();
 
     // reset the cursor
 #ifdef __WXMOTIF__
@@ -185,12 +186,21 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
             m_dragMode = wxSPLIT_DRAG_DRAGGING;
 
             if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE) == 0)
-           {
-               DrawSashTracker(x, y);
-           }
+            {
+                DrawSashTracker(x, y);
+            }
 
             m_oldX = x;
             m_oldY = y;
+
+            if ( m_splitMode == wxSPLIT_VERTICAL )
+            {
+                SetCursor(*m_sashCursorWE);
+            }
+            else
+            {
+                SetCursor(*m_sashCursorNS);
+            }
             return;
         }
     }
@@ -202,9 +212,9 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
 
         // Erase old tracker
         if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE) == 0)
-       {
+        {
             DrawSashTracker(m_oldX, m_oldY);
-       }
+        }
 
         // Obtain window size. We are only interested in the dimension the sash
         // splits up
@@ -227,8 +237,7 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
             }
         }
 
-        if ( m_permitUnsplitAlways
-                || m_minimumPaneSize == 0 )
+        if ( m_permitUnsplitAlways || m_minimumPaneSize == 0 )
         {
             // Deal with possible unsplit scenarios
             if ( new_sash_position == 0 )
@@ -259,6 +268,7 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
         }
 
         SizeWindows();
+        m_needUpdating = FALSE;
     }  // left up && dragging
     else if (event.Moving() && !event.Dragging())
     {
@@ -274,16 +284,37 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
                     SetCursor(*m_sashCursorNS);
                 }
         }
-#ifdef __WXGTK__
+#if defined(__WXGTK__) || defined(__WXMSW__)
         else
         {
+            // We must set the normal cursor in MSW, because
+            // if the child window doesn't have a cursor, the
+            // parent's (splitter window) will be used, and this
+            // must be the standard cursor.
+            wxLogDebug("wxSplitterWindow: Setting to standard cursor");
+
             // where else do we unset the cursor?
             SetCursor(* wxSTANDARD_CURSOR);
         }
 #endif // __WXGTK__
+
+        m_needUpdating = FALSE;
     }
     else if (event.Dragging() && (m_dragMode == wxSPLIT_DRAG_DRAGGING))
     {
+#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);
+        }
+#endif
+
         // Obtain window size. We are only interested in the dimension the sash
         // splits up
         int new_sash_position =
@@ -304,9 +335,9 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
 
         // Erase old tracker
         if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE) == 0)
-       {
+        {
             DrawSashTracker(m_oldX, m_oldY);
-       }
+        }
 
         if (m_splitMode == wxSPLIT_VERTICAL)
             x = new_sash_position;
@@ -335,14 +366,14 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
 
         // Draw new one
         if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE) == 0)
-       {
+        {
             DrawSashTracker(m_oldX, m_oldY);
-       }
-       else
-       {
+        }
+        else
+        {
             m_sashPosition = new_sash_position;
-           m_needUpdating = TRUE;
-       }
+            m_needUpdating = TRUE;
+        }
     }
     else if ( event.LeftDClick() )
     {
@@ -424,8 +455,6 @@ bool wxSplitterWindow::SashHitTest(int x, int y, int tolerance)
         else
             return FALSE;
     }
-
-    return FALSE;
 }
 
 // Draw 3D effect borders
@@ -492,14 +521,14 @@ void wxSplitterWindow::DrawSash(wxDC& dc)
             dc.SetBrush(*wxTRANSPARENT_BRUSH);
 
             dc.SetPen(*m_lightShadowPen);
-                       int xShadow = m_borderSize ? m_borderSize - 1 : 0 ;
+                        int xShadow = m_borderSize ? m_borderSize - 1 : 0 ;
             dc.DrawLine(m_sashPosition, xShadow , m_sashPosition, h-m_borderSize);
 
             dc.SetPen(*m_hilightPen);
             dc.DrawLine(m_sashPosition+1, m_borderSize - 2, m_sashPosition+1, h - m_borderSize+2);
 
             dc.SetPen(*m_mediumShadowPen);
-                       int yMedium = m_borderSize ? h-m_borderSize+1 : h ;
+                        int yMedium = m_borderSize ? h-m_borderSize+1 : h ;
             dc.DrawLine(m_sashPosition+m_sashSize-2, xShadow, m_sashPosition+m_sashSize-2, yMedium);
 
             dc.SetPen(*m_darkShadowPen);
@@ -651,8 +680,8 @@ void wxSplitterWindow::SizeWindows()
         }
     }
     wxClientDC dc(this);
-       if ( m_borderSize > 0 )
-               DrawBorders(dc);
+    if ( m_borderSize > 0 )
+        DrawBorders(dc);
     DrawSash(dc);
 }
 
@@ -893,8 +922,7 @@ void wxSplitterWindow::OnDoubleClick(wxSplitterEvent& event)
     // for compatibility, call the virtual function
     OnDoubleClickSash(event.GetX(), event.GetY());
 
-    if ( GetMinimumPaneSize() == 0
-        || m_permitUnsplitAlways)
+    if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways )
     {
         Unsplit();
     }
@@ -904,8 +932,27 @@ void wxSplitterWindow::OnUnsplitEvent(wxSplitterEvent& event)
 {
     wxWindow *win = event.GetWindowBeingRemoved();
 
+    // do it before calling OnUnsplit() which may delete the window
+    win->Show(FALSE);
+
     // for compatibility, call the virtual function
     OnUnsplit(win);
+}
 
-    win->Show(FALSE);
+void wxSplitterWindow::OnSetCursor(wxSetCursorEvent& event)
+{
+    // this is currently called (and needed) under MSW only...
+#ifdef __WXMSW__
+
+    // if we don't do it, the resizing cursor might be set for child window:
+    // 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()) )
+    {
+        // default processing is ok
+        event.Skip();
+    }
+    //else: do nothing, in particular, don't call Skip()
+#endif // wxMSW
 }