From 844adaa47ae9928450affcaaee0209cb36b9c30a Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Thu, 17 Mar 2005 21:21:45 +0000 Subject: [PATCH] Provided GetBestVirtualSize and DoGetBestSize implementations for 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 | 8 ++++++ include/wx/generic/splitter.h | 3 +- include/wx/gtk/scrolwin.h | 8 ++++++ include/wx/gtk1/scrolwin.h | 8 ++++++ src/generic/scrlwing.cpp | 54 +++++++++++++++++++++++++++++++++++ src/generic/splitter.cpp | 3 +- src/gtk/scrolwin.cpp | 54 +++++++++++++++++++++++++++++++++++ src/gtk1/scrolwin.cpp | 54 +++++++++++++++++++++++++++++++++++ 8 files changed, 190 insertions(+), 2 deletions(-) diff --git a/include/wx/generic/scrolwin.h b/include/wx/generic/scrolwin.h index 698e8bd824..91c76bbbf3 100644 --- a/include/wx/generic/scrolwin.h +++ b/include/wx/generic/scrolwin.h @@ -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 diff --git a/include/wx/generic/splitter.h b/include/wx/generic/splitter.h index 12056cac56..2f70ea00e2 100644 --- a/include/wx/generic/splitter.h +++ b/include/wx/generic/splitter.h @@ -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 diff --git a/include/wx/gtk/scrolwin.h b/include/wx/gtk/scrolwin.h index ecbe811f13..b74c39146c 100644 --- a/include/wx/gtk/scrolwin.h +++ b/include/wx/gtk/scrolwin.h @@ -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 ); diff --git a/include/wx/gtk1/scrolwin.h b/include/wx/gtk1/scrolwin.h index ecbe811f13..b74c39146c 100644 --- a/include/wx/gtk1/scrolwin.h +++ b/include/wx/gtk1/scrolwin.h @@ -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 ); diff --git a/src/generic/scrlwing.cpp b/src/generic/scrlwing.cpp index 79b5717aec..4578f66193 100644 --- a/src/generic/scrlwing.cpp +++ b/src/generic/scrlwing.cpp @@ -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 diff --git a/src/generic/splitter.cpp b/src/generic/splitter.cpp index d39356302c..0c04fde000 100644 --- a/src/generic/splitter.cpp +++ b/src/generic/splitter.cpp @@ -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 diff --git a/src/gtk/scrolwin.cpp b/src/gtk/scrolwin.cpp index df01919089..484aa18183 100644 --- a/src/gtk/scrolwin.cpp +++ b/src/gtk/scrolwin.cpp @@ -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 diff --git a/src/gtk1/scrolwin.cpp b/src/gtk1/scrolwin.cpp index df01919089..484aa18183 100644 --- a/src/gtk1/scrolwin.cpp +++ b/src/gtk1/scrolwin.cpp @@ -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 -- 2.45.2