/////////////////////////////////////////////////////////////////////////////
// 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.
// headers
// ----------------------------------------------------------------------------
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
- #pragma implementation "genscrolwin.h"
-#endif
-
#ifdef __VMS
#define XtDisplay XTDISPLAY
#endif
#pragma hdrstop
#endif
-#if !defined(__WXGTK__) || defined(__WXUNIVERSAL__)
-
#include "wx/utils.h"
#include "wx/dcclient.h"
#ifdef __WXMSW__
#include <windows.h> // for DLGC_WANTARROWS
+ #include "wx/msw/winundef.h"
#endif
#ifdef __WXMOTIF__
#endif
#endif
-IMPLEMENT_CLASS(wxScrolledWindow, wxGenericScrolledWindow)
-
/*
TODO PROPERTIES
style wxHSCROLL | wxVSCROLL
wxScrollHelper::wxScrollHelper(wxWindow *win)
{
+ wxASSERT_MSG( win, _T("associated window can't be NULL in wxScrollHelper") );
+
m_xScrollPixelsPerLine =
m_yScrollPixelsPerLine =
m_xScrollPosition =
m_handler = NULL;
- if ( win )
- SetWindow(win);
+ m_win = win;
+
+ // by default, the associated window is also the target window
+ DoSetTargetWindow(win);
}
wxScrollHelper::~wxScrollHelper()
// The above should arguably be deprecated, this however we still need.
- m_targetWindow->SetVirtualSize( w, h );
+ // take care not to set 0 virtual size, 0 means that we don't have any
+ // scrollbars and hence we should use the real size instead of the virtual
+ // one which is indicated by using wxDefaultCoord
+ m_targetWindow->SetVirtualSize( w ? w : wxDefaultCoord,
+ h ? h : wxDefaultCoord);
if (do_refresh && !noRefresh)
m_targetWindow->Refresh(true, GetScrollRect());
}
}
-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;
+#ifdef __WXMAC__
+ target->MacSetClipChildren( true ) ;
+#endif
// install the event handler which will intercept the events we're
// interested in (but only do it for our real window, not the target window
// it here for now but it would be better to ensure that all ports
// generate EVT_SIZE when scrollbars [dis]appear, emulating it if
// necessary, and remove it later
+ // JACS: Stop potential infinite loop by limiting number of iterations
+ int iterationCount = 0;
+ const int iterationMax = 5;
do
{
+ iterationCount ++;
+
GetTargetSize(&w, 0);
// scroll lines per page: if 0, no scrolling is needed
oldh = h;
GetTargetSize( &w, &h );
- } while ( w != oldw || h != oldh );
+ } while ( (w != oldw || h != oldh) && (iterationCount < iterationMax) );
#ifdef __WXMOTIF__
// Sorry, some Motif-specific code to implement a backing pixmap
*y = m_yScrollPosition;
}
-#if WXWIN_COMPATIBILITY_2_2
-
-void wxScrollHelper::ViewStart(int *x, int *y) const
-{
- GetViewStart( x, y );
-}
-
-#endif // WXWIN_COMPATIBILITY_2_2
-
void wxScrollHelper::DoCalcScrolledPosition(int x, int y, int *xx, int *yy) const
{
if ( xx )
*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
// ----------------------------------------------------------------------------
if ( m_targetWindow->GetAutoLayout() )
{
wxSize size = m_targetWindow->GetBestVirtualSize();
-
+
// This will call ::Layout() and ::AdjustScrollbars()
m_win->SetVirtualSize( size );
}
#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,
const wxString& name)
{
m_targetWindow = this;
+#ifdef __WXMAC__
+ MacSetClipChildren( true ) ;
+#endif
bool ok = wxPanel::Create(parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, name);
return ok;
}
-wxGenericScrolledWindow::~wxGenericScrolledWindow()
-{
-}
-
-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)
+wxScrolledWindow::~wxScrolledWindow()
{
- wxPanel::DoSetVirtualSize( x, y );
- AdjustScrollbars();
-
- if (GetAutoLayout())
- Layout();
}
-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
}
#ifdef __WXMSW__
-WXLRESULT
-wxGenericScrolledWindow::MSWWindowProc(WXUINT nMsg,
+WXLRESULT wxScrolledWindow::MSWWindowProc(WXUINT nMsg,
WXWPARAM wParam,
WXLPARAM lParam)
{
#endif // __WXMSW__
-#endif // !wxGTK
-
-// vi:sts=4:sw=4:et