]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/splitter.cpp
don't show size grip when maximized
[wxWidgets.git] / src / generic / splitter.cpp
index 4aad72698ca22042235178ff6bae494010ea1d96..d958fa5e1a178c407cfe092bd4db7c59eb42bffe 100644 (file)
@@ -33,6 +33,7 @@
 #include "wx/dcscreen.h"
 #include "wx/settings.h"
 #include "wx/log.h"
+#include "wx/utils.h"
 
 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED)
 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING)
@@ -88,6 +89,13 @@ bool wxSplitterWindow::Create(wxWindow *parent, wxWindowID id,
     else
         m_borderSize = 0;
 
+#ifdef __WXMAC__
+    int major,minor;
+    wxGetOsVersion( &major, &minor );
+    if (major >= 10)
+        m_windowStyle |= wxSP_SASH_AQUA;
+#endif
+
     return TRUE;
 }
 
@@ -158,8 +166,8 @@ void wxSplitterWindow::OnIdle(wxIdleEvent& event)
 
 void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
 {
-    wxCoord x = (wxCoord)event.GetX(),
-            y = (wxCoord)event.GetY();
+    int x = (int)event.GetX(),
+        y = (int)event.GetY();
 
     // reset the cursor
 #ifdef __WXMOTIF__
@@ -213,11 +221,8 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
 
         // Obtain window size. We are only interested in the dimension the sash
         // splits up
-        int w, h;
-        GetClientSize(&w, &h);
-        int window_size = (m_splitMode == wxSPLIT_VERTICAL ? w : h );
-        int new_sash_position =
-            (int) ( m_splitMode == wxSPLIT_VERTICAL ? x : y );
+        int window_size = GetWindowSize();
+        int new_sash_position = m_splitMode == wxSPLIT_VERTICAL ? x : y;
 
         wxSplitterEvent eventSplitter(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED,
                                       this);
@@ -308,8 +313,7 @@ void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
 
         // Obtain window size. We are only interested in the dimension the sash
         // splits up
-        int new_sash_position =
-            (int) ( m_splitMode == wxSPLIT_VERTICAL ? x : y );
+        int new_sash_position = m_splitMode == wxSPLIT_VERTICAL ? x : y;
 
         wxSplitterEvent eventSplitter(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING,
                                       this);
@@ -389,42 +393,50 @@ void wxSplitterWindow::OnSize(wxSizeEvent& event)
     }
 
     bool iconized = FALSE;
-    wxFrame *frame = wxDynamicCast(parent, wxFrame);
-    if ( frame )
-        iconized = frame->IsIconized();
-    else
+
+    // wxMotif doesn't yet have a wxTopLevelWindow implementation
+#ifdef __WXMOTIF__
+    wxFrame *winTop = wxDynamicCast(parent, wxFrame);
+#else
+    wxTopLevelWindow *winTop = wxDynamicCast(parent, wxTopLevelWindow);
+#endif
+    if ( winTop )
     {
-        wxDialog *dialog = wxDynamicCast(parent, wxDialog);
-        if ( dialog )
-            iconized = dialog->IsIconized();
-        else
-            wxFAIL_MSG(wxT("should have a top level frame or dialog parent!"));
+        iconized = winTop->IsIconized();
     }
+#ifndef __WXMOTIF__
+    else
+    {
+        wxFAIL_MSG(wxT("should have a top level parent!"));
 
+        iconized = FALSE;
+    }
+#endif
+    
     if ( iconized )
     {
         event.Skip();
+
+        return;
     }
-    else
+
+    int cw, ch;
+    GetClientSize( &cw, &ch );
+    if ( m_windowTwo )
     {
-        int cw, ch;
-        GetClientSize( &cw, &ch );
-        if ( m_windowTwo )
+        if ( m_splitMode == wxSPLIT_VERTICAL )
         {
-            if ( m_splitMode == wxSPLIT_VERTICAL )
-            {
-                if ( m_sashPosition >= (cw - 5) )
-                    m_sashPosition = wxMax(10, cw - 40);
-            }
-            if ( m_splitMode == wxSPLIT_HORIZONTAL )
-            {
-                if ( m_sashPosition >= (ch - 5) )
-                    m_sashPosition = wxMax(10, ch - 40);
-            }
+            if ( m_sashPosition >= (cw - 5) )
+                m_sashPosition = wxMax(10, cw - 40);
+        }
+        else // m_splitMode == wxSPLIT_HORIZONTAL
+        {
+            if ( m_sashPosition >= (ch - 5) )
+                m_sashPosition = wxMax(10, ch - 40);
         }
-
-        SizeWindows();
     }
+
+    SizeWindows();
 }
 
 bool wxSplitterWindow::SashHitTest(int x, int y, int tolerance)
@@ -535,7 +547,7 @@ void wxSplitterWindow::DrawSash(wxDC& dc)
             else
                 dc.SetPen(*m_darkShadowPen);
             dc.DrawLine(m_sashPosition+m_sashSize-1, m_borderSize, m_sashPosition+m_sashSize-1, h-m_borderSize );
-            
+
             // Draw the top and bottom edges of the sash, if requested
             if (GetWindowStyle() & wxSP_FULLSASH)
             {
@@ -681,6 +693,63 @@ void wxSplitterWindow::DrawSashTracker(int x, int y)
     screenDC.SetBrush(wxNullBrush);
 }
 
+int wxSplitterWindow::GetWindowSize() const
+{
+    wxSize size = GetClientSize();
+
+    return m_splitMode == wxSPLIT_VERTICAL ? size.x : size.y;
+}
+
+int wxSplitterWindow::AdjustSashPosition(int sashPos) const
+{
+    int window_size = GetWindowSize();
+
+    // VZ: dirty fix, 20 is the initial window size under wxGTK, this is
+    //     going to be replaced with the correct Vaclav's code soon (FIXME)
+    if ( window_size <= 20 )
+    {
+        // don't do anything before the window has a valid size, otherwise we
+        // put the sash to 0 at the very beginning and it doesn't move from
+        // there any more
+        return sashPos;
+    }
+
+    wxWindow *win;
+
+    win = GetWindow1();
+    if ( win )
+    {
+        // the window shouldn't be smaller than its own minimal size nor
+        // smaller than the minimual pane size specified for this splitter
+        int minSize = m_splitMode == wxSPLIT_VERTICAL ? win->GetMinWidth()
+                                                      : win->GetMinHeight();
+
+        if ( minSize == -1 || m_minimumPaneSize > minSize )
+            minSize = m_minimumPaneSize;
+
+        minSize += GetBorderSize();
+
+        if ( sashPos < minSize )
+            sashPos = minSize;
+    }
+
+    win = GetWindow2();
+    if ( win )
+    {
+        int minSize = m_splitMode == wxSPLIT_VERTICAL ? win->GetMinWidth()
+                                                      : win->GetMinHeight();
+
+        if ( minSize == -1 || m_minimumPaneSize > minSize )
+            minSize = m_minimumPaneSize;
+
+        int maxSize = window_size - minSize - GetBorderSize();
+        if ( sashPos > maxSize )
+            sashPos = maxSize;
+    }
+
+    return sashPos;
+}
+
 // Position and size subwindows.
 // Note that the border size applies to each subwindow, not
 // including the edges next to the sash.
@@ -738,53 +807,47 @@ void wxSplitterWindow::Initialize(wxWindow *window)
 // Associates the given window with window 2, drawing the appropriate sash
 // and changing the split mode.
 // Does nothing and returns FALSE if the window is already split.
-bool wxSplitterWindow::SplitVertically(wxWindow *window1, wxWindow *window2, int sashPosition)
+bool wxSplitterWindow::DoSplit(wxSplitMode mode,
+                               wxWindow *window1, wxWindow *window2,
+                               int sashPosition)
 {
     if ( IsSplit() )
         return FALSE;
 
-    int w, h;
-    GetClientSize(&w, &h);
+    int window_size = GetWindowSize();
 
-    m_splitMode = wxSPLIT_VERTICAL;
+    m_splitMode = mode;
     m_windowOne = window1;
     m_windowTwo = window2;
-    if ( sashPosition > 0 )
-        m_sashPosition = sashPosition;
-    else if ( sashPosition < 0 )
-        m_sashPosition = w + sashPosition;   // It's negative so adding is subtracting
-    else    // default
-        m_sashPosition = w/2;
-
-    SizeWindows();
-
-    return TRUE;
-}
-
-bool wxSplitterWindow::SplitHorizontally(wxWindow *window1, wxWindow *window2, int sashPosition)
-{
-    if ( IsSplit() )
-        return FALSE;
-
-    int w, h;
-    GetClientSize(&w, &h);
 
-    m_splitMode = wxSPLIT_HORIZONTAL;
-    m_windowOne = window1;
-    m_windowTwo = window2;
     if ( sashPosition > 0 )
+    {
         m_sashPosition = sashPosition;
+    }
     else if ( sashPosition < 0 )
-        m_sashPosition = h + sashPosition; // It's negative so adding is subtracting
-    else    // default
-        m_sashPosition = h/2;
+    {
+        // It's negative so adding is subtracting
+        m_sashPosition = window_size + sashPosition;
+    }
+    else
+    {
+        // default
+        m_sashPosition = window_size/2;
+    }
+
+    // don't do it initially, i.e. when creating the window because it doesn't
+    // have a proper size yet and AdjustSashPosition() would happily set the
+    // sash position to 0!
+    if ( window_size > 0 )
+    {
+        m_sashPosition = AdjustSashPosition(m_sashPosition);
+    }
 
     SizeWindows();
 
     return TRUE;
 }
 
-
 // Remove the specified (or second) window from the view
 // Doesn't actually delete the window.
 bool wxSplitterWindow::Unsplit(wxWindow *toRemove)
@@ -846,7 +909,7 @@ bool wxSplitterWindow::ReplaceWindow(wxWindow *winOld, wxWindow *winNew)
 
 void wxSplitterWindow::SetSashPosition(int position, bool redraw)
 {
-    m_sashPosition = position;
+    m_sashPosition = AdjustSashPosition(position);
 
     if ( redraw )
     {
@@ -866,20 +929,20 @@ void wxSplitterWindow::InitColours()
 
     // Shadow colours
 #ifndef __WIN16__
-    wxColour faceColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
+    wxColour faceColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
     m_facePen = new wxPen(faceColour, 1, wxSOLID);
     m_faceBrush = new wxBrush(faceColour, wxSOLID);
 
-    wxColour mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW));
+    wxColour mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW));
     m_mediumShadowPen = new wxPen(mediumShadowColour, 1, wxSOLID);
 
-    wxColour darkShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DDKSHADOW));
+    wxColour darkShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW));
     m_darkShadowPen = new wxPen(darkShadowColour, 1, wxSOLID);
 
-    wxColour lightShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT));
+    wxColour lightShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT));
     m_lightShadowPen = new wxPen(lightShadowColour, 1, wxSOLID);
 
-    wxColour hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT));
+    wxColour hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT));
     m_hilightPen = new wxPen(hilightColour, 1, wxSOLID);
 #else
     m_facePen = new wxPen("LIGHT GREY", 1, wxSOLID);
@@ -911,9 +974,7 @@ void wxSplitterWindow::OnSashPosChanged(wxSplitterEvent& event)
     int newSashPosition = event.GetSashPosition();
 
     // Obtain relevant window dimension for bottom / right threshold check
-    int w, h;
-    GetClientSize(&w, &h);
-    int window_size = (m_splitMode == wxSPLIT_VERTICAL) ? w : h ;
+    int window_size = GetWindowSize();
 
     bool unsplit_scenario = FALSE;
     if ( m_permitUnsplitAlways
@@ -937,10 +998,7 @@ void wxSplitterWindow::OnSashPosChanged(wxSplitterEvent& event)
     if ( !unsplit_scenario )
     {
         // If resultant pane would be too small, enlarge it
-        if ( newSashPosition < m_minimumPaneSize )
-            newSashPosition = m_minimumPaneSize;
-        if ( newSashPosition > window_size - m_minimumPaneSize )
-            newSashPosition = window_size - m_minimumPaneSize;
+        newSashPosition = AdjustSashPosition(newSashPosition);
     }
 
     // If the result is out of bounds it means minimum size is too big,