fixed wxScrolledWindow best size calculation: compute something (this was broken after 2.8) and don't use current size in computation; also removed now-unused ScrollGetWindowSizeForVirtualSize() method to simplify the code

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50877 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2007-12-21 22:47:55 +00:00
parent 8a6a997fb0
commit 7d616e99ed
3 changed files with 45 additions and 39 deletions

View File

@@ -196,7 +196,6 @@ protected:
bool ScrollLayout(); bool ScrollLayout();
void ScrollDoSetVirtualSize(int x, int y); void ScrollDoSetVirtualSize(int x, int y);
wxSize ScrollGetBestVirtualSize() const; wxSize ScrollGetBestVirtualSize() const;
wxSize ScrollGetWindowSizeForVirtualSize(const wxSize& size) const;
// change just the target window (unlike SetWindow which changes m_win as // change just the target window (unlike SetWindow which changes m_win as
// well) // well)
@@ -246,10 +245,7 @@ public: \
virtual void DoSetVirtualSize(int x, int y) \ virtual void DoSetVirtualSize(int x, int y) \
{ ScrollDoSetVirtualSize(x, y); } \ { ScrollDoSetVirtualSize(x, y); } \
virtual wxSize GetBestVirtualSize() const \ virtual wxSize GetBestVirtualSize() const \
{ return ScrollGetBestVirtualSize(); } \ { return ScrollGetBestVirtualSize(); }
protected: \
virtual wxSize GetWindowSizeForVirtualSize(const wxSize& size) const \
{ return ScrollGetWindowSizeForVirtualSize(size); }
// include the declaration of wxScrollHelperNative if needed // include the declaration of wxScrollHelperNative if needed
#if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__) #if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
@@ -298,6 +294,8 @@ public:
WX_FORWARD_TO_SCROLL_HELPER() WX_FORWARD_TO_SCROLL_HELPER()
protected: protected:
virtual wxSize DoGetBestSize() const;
// this is needed for wxEVT_PAINT processing hack described in // this is needed for wxEVT_PAINT processing hack described in
// wxScrollHelperEvtHandler::ProcessEvent() // wxScrollHelperEvtHandler::ProcessEvent()
void OnPaint(wxPaintEvent& event); void OnPaint(wxPaintEvent& event);

View File

@@ -1518,14 +1518,6 @@ protected:
// same size as it would have after a call to Fit() // same size as it would have after a call to Fit()
virtual wxSize DoGetBestSize() const; virtual wxSize DoGetBestSize() const;
// called from DoGetBestSize() to convert best virtual size (returned by
// the window sizer) to the best size for the window itself; this is
// overridden at wxScrolledWindow level to clump down virtual size to real
virtual wxSize GetWindowSizeForVirtualSize(const wxSize& size) const
{
return size;
}
// this is the virtual function to be overriden in any derived class which // this is the virtual function to be overriden in any derived class which
// wants to change how SetSize() or Move() works - it is called by all // wants to change how SetSize() or Move() works - it is called by all
// versions of these functions in the base class // versions of these functions in the base class

View File

@@ -35,10 +35,9 @@
#include "wx/utils.h" #include "wx/utils.h"
#include "wx/panel.h" #include "wx/panel.h"
#include "wx/dcclient.h" #include "wx/dcclient.h"
#if wxUSE_TIMER #include "wx/timer.h"
#include "wx/timer.h"
#endif
#include "wx/sizer.h" #include "wx/sizer.h"
#include "wx/settings.h"
#endif #endif
#ifdef __WXMAC__ #ifdef __WXMAC__
@@ -1059,29 +1058,6 @@ wxSize wxScrollHelper::ScrollGetBestVirtualSize() const
return clientSize; return clientSize;
} }
// return the window best size from the given best virtual size
wxSize
wxScrollHelper::ScrollGetWindowSizeForVirtualSize(const wxSize& size) const
{
// 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 = m_win->GetMinSize();
if ( !minSize.IsFullySpecified() )
minSize = m_win->GetSize();
wxSize best(size);
if (ppuX > 0)
best.x = minSize.x;
if (ppuY > 0)
best.y = minSize.y;
return best;
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// event handlers // event handlers
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -1470,6 +1446,46 @@ void wxScrolledWindow::OnPaint(wxPaintEvent& event)
event.Skip(); event.Skip();
} }
wxSize wxScrolledWindow::DoGetBestSize() const
{
// NB: We don't do this in WX_FORWARD_TO_SCROLL_HELPER, because not
// all scrollable windows should behave like this, only those that
// contain children controls within scrollable area
// (i.e., wxScrolledWindow) and other some scrollable windows may
// have different DoGetBestSize() implementation (e.g. wxTreeCtrl).
wxSize best = wxPanel::DoGetBestSize();
if ( GetAutoLayout() )
{
// 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);
// NB: This code used to use *current* size if min size wasn't
// specified, presumably to get some reasonable (i.e., larger than
// minimal) size. But that's a wrong thing to do in GetBestSize(),
// so we use minimal size as specified. If the app needs some
// minimal size for its scrolled window, it should set it and put
// the window into sizer as expandable so that it can use all space
// available to it.
//
// See also http://svn.wxwidgets.org/viewvc/wx?view=rev&revision=45864
wxSize minSize = GetMinSize();
if ( ppuX > 0 )
best.x = minSize.x + wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
if ( ppuY > 0 )
best.y = minSize.y + wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y);
}
return best;
}
#ifdef __WXMSW__ #ifdef __WXMSW__
WXLRESULT wxScrolledWindow::MSWWindowProc(WXUINT nMsg, WXLRESULT wxScrolledWindow::MSWWindowProc(WXUINT nMsg,
WXWPARAM wParam, WXWPARAM wParam,