]> git.saurik.com Git - wxWidgets.git/commitdiff
Provided GetBestVirtualSize and DoGetBestSize implementations for
authorJulian Smart <julian@anthemion.co.uk>
Thu, 17 Mar 2005 21:21:45 +0000 (21:21 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Thu, 17 Mar 2005 21:21:45 +0000 (21:21 +0000)
generic and GTK+ wxScrolledWindow.

wxWindowBase::DoGetBestSize was returning a virtual size if there were child
controls, which was then used to set the scrolled window actual size.
Similarly, wxWindowBase::GetBestVirtualSize was returning
the actual window size; now we return the virtual size
for dimensions that have scrolling (e.g. vertical scrolling
direction), or the minimum/actual size for those that don't
(e.g. the maximum control width if there is no horizontal
scrolling).

This allows the scrolled window to be properly sized, whereas
before it would start off at the virtual size (giving
enormous layouts).

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32866 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/generic/scrolwin.h
include/wx/generic/splitter.h
include/wx/gtk/scrolwin.h
include/wx/gtk1/scrolwin.h
src/generic/scrlwing.cpp
src/generic/splitter.cpp
src/gtk/scrolwin.cpp
src/gtk1/scrolwin.cpp

index 698e8bd8244dcd99f9557c83167d51fbf937ff2c..91c76bbbf3a407b01167b2a0f737ade4e709f966 100644 (file)
@@ -71,6 +71,14 @@ public:
 
     virtual void DoSetVirtualSize(int x, int y);
 
+    // wxWindow's GetBestVirtualSize returns the actual window size,
+    // whereas we want to return the virtual size
+    virtual wxSize GetBestVirtualSize() const;
+
+    // Return the size best suited for the current window
+    // (this isn't a virtual size, this is a sensible size for the window)
+    virtual wxSize DoGetBestSize() const;
+
 #ifdef __WXMAC__
     virtual bool MacClipChildren() const { return true ; }
 #endif
index 12056cac563cbdb85bca13196c66d15198191504..2f70ea00e2cacb182d21efd3db5e896d0938d1ba 100644 (file)
@@ -138,7 +138,7 @@ public:
     bool IsSplit() const { return (m_windowTwo != NULL); }
 
     // Sets the sash size
-    void SetSashSize(int WXUNUSED(width)) { }
+    void SetSashSize(int width) { m_sashSize = width; }
 
     // Sets the border size
     void SetBorderSize(int WXUNUSED(width)) { }
@@ -283,6 +283,7 @@ protected:
     int         m_oldY;
     int         m_sashPosition; // Number of pixels from left or top
     double      m_sashGravity;
+    int         m_sashSize;
     wxSize      m_lastSize;
     int         m_requestedSashPosition;
     int         m_sashPositionCurrent; // while dragging
index ecbe811f13d213d4bf6c09e6be89b5c9ed83aa22..b74c39146cdcf4c862fc4a6e818fdfaa13b6c5a9 100644 (file)
@@ -68,6 +68,14 @@ public:
     // Set the scrolled area of the window.
     virtual void DoSetVirtualSize( int x, int y );
 
+    // wxWindow's GetBestVirtualSize returns the actual window size,
+    // whereas we want to return the virtual size
+    virtual wxSize GetBestVirtualSize() const;
+
+    // Return the size best suited for the current window
+    // (this isn't a virtual size, this is a sensible size for the window)
+    virtual wxSize DoGetBestSize() const;
+
     // Set the x, y scrolling increments.
     void SetScrollRate( int xstep, int ystep );
 
index ecbe811f13d213d4bf6c09e6be89b5c9ed83aa22..b74c39146cdcf4c862fc4a6e818fdfaa13b6c5a9 100644 (file)
@@ -68,6 +68,14 @@ public:
     // Set the scrolled area of the window.
     virtual void DoSetVirtualSize( int x, int y );
 
+    // wxWindow's GetBestVirtualSize returns the actual window size,
+    // whereas we want to return the virtual size
+    virtual wxSize GetBestVirtualSize() const;
+
+    // Return the size best suited for the current window
+    // (this isn't a virtual size, this is a sensible size for the window)
+    virtual wxSize DoGetBestSize() const;
+
     // Set the x, y scrolling increments.
     void SetScrollRate( int xstep, int ystep );
 
index 79b5717aecce5fd061ed3b4b7accaa2187645b13..4578f661933037ec4b1cac8dc855217d3ffb19ac 100644 (file)
@@ -1283,6 +1283,60 @@ void wxGenericScrolledWindow::DoSetVirtualSize(int x, int y)
         Layout();
 }
 
+// wxWindow's GetBestVirtualSize returns the actual window size,
+// whereas we want to return the virtual size
+wxSize wxGenericScrolledWindow::GetBestVirtualSize() const
+{
+    wxSize  clientSize( GetClientSize() );
+    if (GetSizer())
+    {
+        wxSize minSize( GetSizer()->CalcMin() );
+
+        return wxSize( wxMax( clientSize.x, minSize.x ), wxMax( clientSize.y, minSize.y ) );
+    }
+    else
+        return clientSize;
+}
+
+// return the size best suited for the current window
+// (this isn't a virtual size, this is a sensible size for the window)
+wxSize wxGenericScrolledWindow::DoGetBestSize() const
+{
+    wxSize best;
+
+    if ( GetSizer() )
+    {
+        wxSize b = GetSizer()->GetMinSize();
+
+        // Only use the content to set the window size in the direction
+        // where there's no scrolling; otherwise we're going to get a huge
+        // window in the direction in which scrolling is enabled
+        int ppuX, ppuY;
+        GetScrollPixelsPerUnit(& ppuX, & ppuY);
+
+        wxSize minSize;
+        if ( GetMinSize().IsFullySpecified() )
+            minSize = GetMinSize();
+        else
+            minSize = GetSize();
+
+        if (ppuX > 0)
+            b.x = minSize.x;
+        if (ppuY > 0)
+            b.y = minSize.y;
+        best = b;
+    }
+    else
+        return wxWindow::DoGetBestSize();
+
+    // Add any difference between size and client size
+    wxSize diff = GetSize() - GetClientSize();
+    best.x += wxMax(0, diff.x);
+    best.y += wxMax(0, diff.y);
+
+    return best;
+}
+
 void wxGenericScrolledWindow::OnPaint(wxPaintEvent& event)
 {
     // the user code didn't really draw the window if we got here, so set this
index d39356302cad962f8f42fc7299190a1f4509ca3e..0c04fde00056bc7864366d336f353a1ea1402ca4 100644 (file)
@@ -122,6 +122,7 @@ void wxSplitterWindow::Init()
     m_firstY = 0;
     m_sashPosition = m_requestedSashPosition = 0;
     m_sashGravity = 0.0;
+    m_sashSize = -1; // -1 means use the native sash size
     m_lastSize = wxSize(0,0);
     m_checkRequestedSashPosition = false;
     m_minimumPaneSize = 0;
@@ -471,7 +472,7 @@ bool wxSplitterWindow::SashHitTest(int x, int y, int tolerance)
 
 int wxSplitterWindow::GetSashSize() const
 {
-    return wxRendererNative::Get().GetSplitterParams(this).widthSash;
+    return m_sashSize > -1 ? m_sashSize : wxRendererNative::Get().GetSplitterParams(this).widthSash;
 }
 
 int wxSplitterWindow::GetBorderSize() const
index df019190897bbd93e368ae33b6b655c4c4bb517a..484aa181832fc513bb625e99d5bcbffc7621ddd0 100644 (file)
@@ -329,6 +329,60 @@ void wxScrolledWindow::DoSetVirtualSize( int x, int y )
         Layout();
 }
 
+// wxWindow's GetBestVirtualSize returns the actual window size,
+// whereas we want to return the virtual size
+wxSize wxScrolledWindow::GetBestVirtualSize() const
+{
+    wxSize  clientSize( GetClientSize() );
+    if (GetSizer())
+    {
+        wxSize minSize( GetSizer()->CalcMin() );
+
+        return wxSize( wxMax( clientSize.x, minSize.x ), wxMax( clientSize.y, minSize.y ) );
+    }
+    else
+        return clientSize;
+}
+
+// return the size best suited for the current window
+// (this isn't a virtual size, this is a sensible size for the window)
+wxSize wxScrolledWindow::DoGetBestSize() const
+{
+    wxSize best;
+
+    if ( GetSizer() )
+    {
+        wxSize b = GetSizer()->GetMinSize();
+
+        // Only use the content to set the window size in the direction
+        // where there's no scrolling; otherwise we're going to get a huge
+        // window in the direction in which scrolling is enabled
+        int ppuX, ppuY;
+        GetScrollPixelsPerUnit(& ppuX, & ppuY);
+
+        wxSize minSize;
+        if ( GetMinSize().IsFullySpecified() )
+            minSize = GetMinSize();
+        else
+            minSize = GetSize();
+
+        if (ppuX > 0)
+            b.x = minSize.x;
+        if (ppuY > 0)
+            b.y = minSize.y;
+        best = b;
+    }
+    else
+        return wxWindow::DoGetBestSize();
+
+    // Add any difference between size and client size
+    wxSize diff = GetSize() - GetClientSize();
+    best.x += wxMax(0, diff.x);
+    best.y += wxMax(0, diff.y);
+
+    return best;
+}
+
 /*
  * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line)
  * noUnitsX/noUnitsY:        : no. units per scrollbar
index df019190897bbd93e368ae33b6b655c4c4bb517a..484aa181832fc513bb625e99d5bcbffc7621ddd0 100644 (file)
@@ -329,6 +329,60 @@ void wxScrolledWindow::DoSetVirtualSize( int x, int y )
         Layout();
 }
 
+// wxWindow's GetBestVirtualSize returns the actual window size,
+// whereas we want to return the virtual size
+wxSize wxScrolledWindow::GetBestVirtualSize() const
+{
+    wxSize  clientSize( GetClientSize() );
+    if (GetSizer())
+    {
+        wxSize minSize( GetSizer()->CalcMin() );
+
+        return wxSize( wxMax( clientSize.x, minSize.x ), wxMax( clientSize.y, minSize.y ) );
+    }
+    else
+        return clientSize;
+}
+
+// return the size best suited for the current window
+// (this isn't a virtual size, this is a sensible size for the window)
+wxSize wxScrolledWindow::DoGetBestSize() const
+{
+    wxSize best;
+
+    if ( GetSizer() )
+    {
+        wxSize b = GetSizer()->GetMinSize();
+
+        // Only use the content to set the window size in the direction
+        // where there's no scrolling; otherwise we're going to get a huge
+        // window in the direction in which scrolling is enabled
+        int ppuX, ppuY;
+        GetScrollPixelsPerUnit(& ppuX, & ppuY);
+
+        wxSize minSize;
+        if ( GetMinSize().IsFullySpecified() )
+            minSize = GetMinSize();
+        else
+            minSize = GetSize();
+
+        if (ppuX > 0)
+            b.x = minSize.x;
+        if (ppuY > 0)
+            b.y = minSize.y;
+        best = b;
+    }
+    else
+        return wxWindow::DoGetBestSize();
+
+    // Add any difference between size and client size
+    wxSize diff = GetSize() - GetClientSize();
+    best.x += wxMax(0, diff.x);
+    best.y += wxMax(0, diff.y);
+
+    return best;
+}
+
 /*
  * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line)
  * noUnitsX/noUnitsY:        : no. units per scrollbar