refactored wxGTK scrolling: it has now fully-functioning wxScrollHelper and a lot of duplicate code was removed
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35875 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: generic/scrolwin.cpp
|
||||
// Purpose: wxGenericScrolledWindow implementation
|
||||
// Purpose: wxScrolledWindow implementation
|
||||
// Author: Julian Smart
|
||||
// Modified by: Vadim Zeitlin on 31.08.00: wxScrollHelper allows to implement.
|
||||
// Ron Lee on 10.4.02: virtual size / auto scrollbars et al.
|
||||
@@ -29,8 +29,6 @@
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if !defined(__WXGTK__) || defined(__WXUNIVERSAL__)
|
||||
|
||||
#include "wx/utils.h"
|
||||
#include "wx/dcclient.h"
|
||||
|
||||
@@ -59,8 +57,6 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
IMPLEMENT_CLASS(wxScrolledWindow, wxGenericScrolledWindow)
|
||||
|
||||
/*
|
||||
TODO PROPERTIES
|
||||
style wxHSCROLL | wxVSCROLL
|
||||
@@ -284,6 +280,8 @@ bool wxScrollHelperEvtHandler::ProcessEvent(wxEvent& event)
|
||||
|
||||
wxScrollHelper::wxScrollHelper(wxWindow *win)
|
||||
{
|
||||
wxASSERT_MSG( win, _T("associated window can't be NULL in wxScrollHelper") );
|
||||
|
||||
m_xScrollPixelsPerLine =
|
||||
m_yScrollPixelsPerLine =
|
||||
m_xScrollPosition =
|
||||
@@ -309,8 +307,10 @@ wxScrollHelper::wxScrollHelper(wxWindow *win)
|
||||
|
||||
m_handler = NULL;
|
||||
|
||||
if ( win )
|
||||
SetWindow(win);
|
||||
m_win = win;
|
||||
|
||||
// by default, the associated window is also the target window
|
||||
DoSetTargetWindow(win);
|
||||
}
|
||||
|
||||
wxScrollHelper::~wxScrollHelper()
|
||||
@@ -407,16 +407,6 @@ void wxScrollHelper::DeleteEvtHandler()
|
||||
}
|
||||
}
|
||||
|
||||
void wxScrollHelper::SetWindow(wxWindow *win)
|
||||
{
|
||||
wxCHECK_RET( win, _T("wxScrollHelper needs a window to scroll") );
|
||||
|
||||
m_win = win;
|
||||
|
||||
// by default, the associated window is also the target window
|
||||
DoSetTargetWindow(win);
|
||||
}
|
||||
|
||||
void wxScrollHelper::DoSetTargetWindow(wxWindow *target)
|
||||
{
|
||||
m_targetWindow = target;
|
||||
@@ -651,7 +641,7 @@ void wxScrollHelper::AdjustScrollbars()
|
||||
do
|
||||
{
|
||||
iterationCount ++;
|
||||
|
||||
|
||||
GetTargetSize(&w, 0);
|
||||
|
||||
// scroll lines per page: if 0, no scrolling is needed
|
||||
@@ -956,6 +946,71 @@ void wxScrollHelper::DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) co
|
||||
*yy = y + m_yScrollPosition * m_yScrollPixelsPerLine;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// geometry
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxScrollHelper::ScrollLayout()
|
||||
{
|
||||
if ( m_win->GetSizer() && m_targetWindow == m_win )
|
||||
{
|
||||
// If we're the scroll target, take into account the
|
||||
// virtual size and scrolled position of the window.
|
||||
|
||||
int x, y, w, h;
|
||||
CalcScrolledPosition(0,0, &x,&y);
|
||||
m_win->GetVirtualSize(&w, &h);
|
||||
m_win->GetSizer()->SetDimension(x, y, w, h);
|
||||
return true;
|
||||
}
|
||||
|
||||
// fall back to default for LayoutConstraints
|
||||
return m_win->wxWindow::Layout();
|
||||
}
|
||||
|
||||
void wxScrollHelper::ScrollDoSetVirtualSize(int x, int y)
|
||||
{
|
||||
m_win->wxWindow::DoSetVirtualSize( x, y );
|
||||
AdjustScrollbars();
|
||||
|
||||
if (m_win->GetAutoLayout())
|
||||
m_win->Layout();
|
||||
}
|
||||
|
||||
// wxWindow's GetBestVirtualSize returns the actual window size,
|
||||
// whereas we want to return the virtual size
|
||||
wxSize wxScrollHelper::ScrollGetBestVirtualSize() const
|
||||
{
|
||||
wxSize clientSize(m_win->GetClientSize());
|
||||
if ( m_win->GetSizer() )
|
||||
clientSize.IncTo(m_win->GetSizer()->CalcMin());
|
||||
|
||||
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
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -966,7 +1021,7 @@ void wxScrollHelper::HandleOnSize(wxSizeEvent& WXUNUSED(event))
|
||||
if ( m_targetWindow->GetAutoLayout() )
|
||||
{
|
||||
wxSize size = m_targetWindow->GetBestVirtualSize();
|
||||
|
||||
|
||||
// This will call ::Layout() and ::AdjustScrollbars()
|
||||
m_win->SetVirtualSize( size );
|
||||
}
|
||||
@@ -1228,16 +1283,16 @@ void wxScrollHelper::HandleOnMouseWheel(wxMouseEvent& event)
|
||||
#endif // wxUSE_MOUSEWHEEL
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxGenericScrolledWindow implementation
|
||||
// wxScrolledWindow implementation
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxGenericScrolledWindow, wxPanel)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxScrolledWindow, wxPanel)
|
||||
|
||||
BEGIN_EVENT_TABLE(wxGenericScrolledWindow, wxPanel)
|
||||
EVT_PAINT(wxGenericScrolledWindow::OnPaint)
|
||||
BEGIN_EVENT_TABLE(wxScrolledWindow, wxPanel)
|
||||
EVT_PAINT(wxScrolledWindow::OnPaint)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
bool wxGenericScrolledWindow::Create(wxWindow *parent,
|
||||
bool wxScrolledWindow::Create(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
const wxPoint& pos,
|
||||
const wxSize& size,
|
||||
@@ -1254,92 +1309,11 @@ bool wxGenericScrolledWindow::Create(wxWindow *parent,
|
||||
return ok;
|
||||
}
|
||||
|
||||
wxGenericScrolledWindow::~wxGenericScrolledWindow()
|
||||
wxScrolledWindow::~wxScrolledWindow()
|
||||
{
|
||||
}
|
||||
|
||||
bool wxGenericScrolledWindow::Layout()
|
||||
{
|
||||
if (GetSizer() && m_targetWindow == this)
|
||||
{
|
||||
// If we're the scroll target, take into account the
|
||||
// virtual size and scrolled position of the window.
|
||||
|
||||
int x, y, w, h;
|
||||
CalcScrolledPosition(0,0, &x,&y);
|
||||
GetVirtualSize(&w, &h);
|
||||
GetSizer()->SetDimension(x, y, w, h);
|
||||
return true;
|
||||
}
|
||||
|
||||
// fall back to default for LayoutConstraints
|
||||
return wxPanel::Layout();
|
||||
}
|
||||
|
||||
void wxGenericScrolledWindow::DoSetVirtualSize(int x, int y)
|
||||
{
|
||||
wxPanel::DoSetVirtualSize( x, y );
|
||||
AdjustScrollbars();
|
||||
|
||||
if (GetAutoLayout())
|
||||
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)
|
||||
void wxScrolledWindow::OnPaint(wxPaintEvent& event)
|
||||
{
|
||||
// the user code didn't really draw the window if we got here, so set this
|
||||
// flag to try to call OnDraw() later
|
||||
@@ -1349,8 +1323,7 @@ void wxGenericScrolledWindow::OnPaint(wxPaintEvent& event)
|
||||
}
|
||||
|
||||
#ifdef __WXMSW__
|
||||
WXLRESULT
|
||||
wxGenericScrolledWindow::MSWWindowProc(WXUINT nMsg,
|
||||
WXLRESULT wxScrolledWindow::MSWWindowProc(WXUINT nMsg,
|
||||
WXWPARAM wParam,
|
||||
WXLPARAM lParam)
|
||||
{
|
||||
@@ -1369,6 +1342,3 @@ wxGenericScrolledWindow::MSWWindowProc(WXUINT nMsg,
|
||||
|
||||
#endif // __WXMSW__
|
||||
|
||||
#endif // !wxGTK
|
||||
|
||||
// vi:sts=4:sw=4:et
|
||||
|
Reference in New Issue
Block a user