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
This commit is contained in:
Julian Smart 2005-03-17 21:21:45 +00:00
parent 50c06297bd
commit 844adaa47a
8 changed files with 190 additions and 2 deletions

View 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

View 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

View 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 );

View 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 );

View 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

View 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

View 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

View 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