]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/sashwin.cpp
buttons now become default when they have focus
[wxWidgets.git] / src / generic / sashwin.cpp
index f64ebd1805624fb61e61156dde3c4421b61c600e..bcc734ffd91b5cde0944fa0c00db813da0c5e137 100644 (file)
@@ -8,7 +8,7 @@
 // Created:     01/02/97
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
 // Created:     01/02/97
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
-// Licence:    wxWindows license
+// Licence:     wxWindows license
 /////////////////////////////////////////////////////////////////////////////
 
 #ifdef __GNUG__
 /////////////////////////////////////////////////////////////////////////////
 
 #ifdef __GNUG__
 #include "wx/wx.h"
 #endif
 
 #include "wx/wx.h"
 #endif
 
+#if !wxUSE_SASH
+    #error "Thisfile requires wxUSE_SASH to be defined."
+#endif // wxUSE_SASH
+
 #include <math.h>
 #include <stdlib.h>
 
 #include "wx/string.h"
 #include "wx/dcscreen.h"
 #include "wx/sashwin.h"
 #include <math.h>
 #include <stdlib.h>
 
 #include "wx/string.h"
 #include "wx/dcscreen.h"
 #include "wx/sashwin.h"
+#include "wx/laywin.h"
 
 #if !USE_SHARED_LIBRARY
 IMPLEMENT_DYNAMIC_CLASS(wxSashWindow, wxWindow)
 
 #if !USE_SHARED_LIBRARY
 IMPLEMENT_DYNAMIC_CLASS(wxSashWindow, wxWindow)
@@ -59,8 +64,8 @@ wxSashWindow::wxSashWindow()
 
     m_minimumPaneSizeX = 0;
     m_minimumPaneSizeY = 0;
 
     m_minimumPaneSizeX = 0;
     m_minimumPaneSizeY = 0;
-    m_maximumPaneSizeX = 0;
-    m_maximumPaneSizeY = 0;
+    m_maximumPaneSizeX = 10000;
+    m_maximumPaneSizeY = 10000;
 }
 
 wxSashWindow::wxSashWindow(wxWindow *parent, wxWindowID id, const wxPoint& pos,
 }
 
 wxSashWindow::wxSashWindow(wxWindow *parent, wxWindowID id, const wxPoint& pos,
@@ -77,8 +82,8 @@ wxSashWindow::wxSashWindow(wxWindow *parent, wxWindowID id, const wxPoint& pos,
     m_extraBorderSize = 0;
     m_minimumPaneSizeX = 0;
     m_minimumPaneSizeY = 0;
     m_extraBorderSize = 0;
     m_minimumPaneSizeX = 0;
     m_minimumPaneSizeY = 0;
-    m_maximumPaneSizeX = 0;
-    m_maximumPaneSizeY = 0;
+    m_maximumPaneSizeX = 10000;
+    m_maximumPaneSizeY = 10000;
     m_sashCursorWE = new wxCursor(wxCURSOR_SIZEWE);
     m_sashCursorNS = new wxCursor(wxCURSOR_SIZENS);
 
     m_sashCursorWE = new wxCursor(wxCURSOR_SIZEWE);
     m_sashCursorNS = new wxCursor(wxCURSOR_SIZENS);
 
@@ -96,10 +101,8 @@ void wxSashWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
 {
     wxPaintDC dc(this);
 
 {
     wxPaintDC dc(this);
 
-#if 0
-    if ( m_borderSize > 0 )
-        DrawBorders(dc);
-#endif
+    //    if ( m_borderSize > 0 )
+    DrawBorders(dc);
 
     DrawSashes(dc);
 }
 
     DrawSashes(dc);
 }
@@ -111,17 +114,33 @@ void wxSashWindow::OnMouseEvent(wxMouseEvent& event)
 
     wxSashEdgePosition sashHit = SashHitTest(x, y);
 
 
     wxSashEdgePosition sashHit = SashHitTest(x, y);
 
+    // reset the cursor
+#ifdef __WXMOTIF__
+    SetCursor(* wxSTANDARD_CURSOR);
+#endif
+#ifdef __WXMSW__
+    SetCursor(wxCursor());
+#endif
+
        if (event.LeftDown())
        {
         if ( sashHit != wxSASH_NONE )
         {
        if (event.LeftDown())
        {
         if ( sashHit != wxSASH_NONE )
         {
-               CaptureMouse();
+            CaptureMouse();
 
            // Required for X to specify that
 
            // Required for X to specify that
-               // that we wish to draw on top of all windows
-               // - and we optimise by specifying the area
-               // for creating the overlap window.
-               wxScreenDC::StartDrawingOnTop(this);
+            // that we wish to draw on top of all windows
+            // - and we optimise by specifying the area
+            // for creating the overlap window.
+            // Find the first frame or dialog and use this to specify
+            // the area to draw on.
+            wxWindow* parent = this;
+
+            while (parent && !parent->IsKindOf(CLASSINFO(wxDialog)) &&
+                             !parent->IsKindOf(CLASSINFO(wxFrame)))
+              parent = parent->GetParent();
+
+            wxScreenDC::StartDrawingOnTop(parent);
 
             // We don't say we're dragging yet; we leave that
             // decision for the Dragging() branch, to ensure
 
             // We don't say we're dragging yet; we leave that
             // decision for the Dragging() branch, to ensure
@@ -139,8 +158,6 @@ void wxSashWindow::OnMouseEvent(wxMouseEvent& event)
         wxScreenDC::EndDrawingOnTop();
         m_dragMode = wxSASH_DRAG_NONE;
         m_draggingEdge = wxSASH_NONE;
         wxScreenDC::EndDrawingOnTop();
         m_dragMode = wxSASH_DRAG_NONE;
         m_draggingEdge = wxSASH_NONE;
-
-        SetCursor(*wxSTANDARD_CURSOR);
     }
        else if (event.LeftUp() && m_dragMode == wxSASH_DRAG_DRAGGING)
        {
     }
        else if (event.LeftUp() && m_dragMode == wxSASH_DRAG_DRAGGING)
        {
@@ -171,6 +188,8 @@ void wxSashWindow::OnMouseEvent(wxMouseEvent& event)
                 if (y > (yp + h))
                     status = wxSASH_STATUS_OUT_OF_RANGE;
                 int newHeight = (h - y);
                 if (y > (yp + h))
                     status = wxSASH_STATUS_OUT_OF_RANGE;
                 int newHeight = (h - y);
+               newHeight=wxMax(newHeight,m_minimumPaneSizeY);
+               newHeight=wxMin(newHeight,m_maximumPaneSizeY);
                 dragRect = wxRect(xp, (yp + h) - newHeight, w, newHeight);
                 break;
             }
                 dragRect = wxRect(xp, (yp + h) - newHeight, w, newHeight);
                 break;
             }
@@ -179,6 +198,8 @@ void wxSashWindow::OnMouseEvent(wxMouseEvent& event)
                 if (y < 0)
                     status = wxSASH_STATUS_OUT_OF_RANGE;
                 int newHeight = y;
                 if (y < 0)
                     status = wxSASH_STATUS_OUT_OF_RANGE;
                 int newHeight = y;
+               newHeight=wxMax(newHeight,m_minimumPaneSizeY);
+               newHeight=wxMin(newHeight,m_maximumPaneSizeY);
                 dragRect = wxRect(xp, yp, w, newHeight);
                 break;
             }
                 dragRect = wxRect(xp, yp, w, newHeight);
                 break;
             }
@@ -187,6 +208,8 @@ void wxSashWindow::OnMouseEvent(wxMouseEvent& event)
                 if (x > (xp + w))
                     status = wxSASH_STATUS_OUT_OF_RANGE;
                 int newWidth = (w - x);
                 if (x > (xp + w))
                     status = wxSASH_STATUS_OUT_OF_RANGE;
                 int newWidth = (w - x);
+               newWidth=wxMax(newWidth,m_minimumPaneSizeX);
+               newWidth=wxMin(newWidth,m_maximumPaneSizeX);
                 dragRect = wxRect((xp + w) - newWidth, yp, newWidth, h);
                 break;
             }
                 dragRect = wxRect((xp + w) - newWidth, yp, newWidth, h);
                 break;
             }
@@ -195,6 +218,8 @@ void wxSashWindow::OnMouseEvent(wxMouseEvent& event)
                 if (x < 0)
                     status = wxSASH_STATUS_OUT_OF_RANGE;
                 int newWidth = x;
                 if (x < 0)
                     status = wxSASH_STATUS_OUT_OF_RANGE;
                 int newWidth = x;
+               newWidth=wxMax(newWidth,m_minimumPaneSizeX);
+               newWidth=wxMin(newWidth,m_maximumPaneSizeX);
                 dragRect = wxRect(xp, yp, newWidth, h);
                 break;
             }
                 dragRect = wxRect(xp, yp, newWidth, h);
                 break;
             }
@@ -224,10 +249,6 @@ void wxSashWindow::OnMouseEvent(wxMouseEvent& event)
                        SetCursor(*m_sashCursorNS);
                 }
         }
                        SetCursor(*m_sashCursorNS);
                 }
         }
-        else
-        {
-           SetCursor(*wxSTANDARD_CURSOR);
-        }
        }
        else if ( event.Dragging() &&
               ((m_dragMode == wxSASH_DRAG_DRAGGING) || (m_dragMode == wxSASH_DRAG_LEFT_DOWN))
        }
        else if ( event.Dragging() &&
               ((m_dragMode == wxSASH_DRAG_DRAGGING) || (m_dragMode == wxSASH_DRAG_LEFT_DOWN))
@@ -310,7 +331,7 @@ wxSashEdgePosition wxSashWindow::SashHitTest(int x, int y, int WXUNUSED(toleranc
                 }
                 case wxSASH_LEFT:
                 {
                 }
                 case wxSASH_LEFT:
                 {
-                    if ((x >= GetEdgeMargin(position)) && (x >= 0))
+                    if ((x <= GetEdgeMargin(position)) && (x >= 0))
                         return wxSASH_LEFT;
                     break;
                 }
                         return wxSASH_LEFT;
                     break;
                 }
@@ -499,7 +520,7 @@ void wxSashWindow::DrawSashTracker(wxSashEdgePosition edge, int x, int y)
 
     wxPen sashTrackerPen(*wxBLACK, 2, wxSOLID);
 
 
     wxPen sashTrackerPen(*wxBLACK, 2, wxSOLID);
 
-    screenDC.SetLogicalFunction(wxXOR);
+    screenDC.SetLogicalFunction(wxINVERT);
     screenDC.SetPen(sashTrackerPen);
     screenDC.SetBrush(*wxTRANSPARENT_BRUSH);
 
     screenDC.SetPen(sashTrackerPen);
     screenDC.SetBrush(*wxTRANSPARENT_BRUSH);
 
@@ -519,9 +540,9 @@ void wxSashWindow::SizeWindows()
     int cw, ch;
     GetClientSize(&cw, &ch);
 
     int cw, ch;
     GetClientSize(&cw, &ch);
 
-    if (GetChildren()->Number() > 0)
+    if (GetChildren().Number() == 1)
     {
     {
-        wxWindow* child = (wxWindow*) (GetChildren()->First()->Data());
+        wxWindow* child = (wxWindow*) (GetChildren().First()->Data());
 
         int x = 0;
         int y = 0;
 
         int x = 0;
         int y = 0;
@@ -560,6 +581,16 @@ void wxSashWindow::SizeWindows()
 
         child->SetSize(x, y, width, height);
     }
 
         child->SetSize(x, y, width, height);
     }
+    else if (GetChildren().Number() > 1)
+    {
+        // Perhaps multiple children are themselves sash windows.
+        // TODO: this doesn't really work because the subwindows sizes/positions
+        // must be set to leave a gap for the parent's sash (hit-test and decorations).
+        // Perhaps we can allow for this within LayoutWindow, testing whether the parent
+        // is a sash window, and if so, allowing some space for the edges.
+        wxLayoutAlgorithm layout;
+        layout.LayoutWindow(this);
+    }
 
     wxClientDC dc(this);
     DrawBorders(dc);
 
     wxClientDC dc(this);
     DrawBorders(dc);