X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7acf6a921e69c3382706c2cfc35e826d08004231..88c139da4639cd25e4ad1298062e1e8b19ee29f1:/src/generic/scrlwing.cpp diff --git a/src/generic/scrlwing.cpp b/src/generic/scrlwing.cpp index 79b5717aec..be7802df03 100644 --- a/src/generic/scrlwing.cpp +++ b/src/generic/scrlwing.cpp @@ -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. @@ -18,10 +18,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "genscrolwin.h" -#endif - #ifdef __VMS #define XtDisplay XTDISPLAY #endif @@ -33,8 +29,6 @@ #pragma hdrstop #endif -#if !defined(__WXGTK__) || defined(__WXUNIVERSAL__) - #include "wx/utils.h" #include "wx/dcclient.h" @@ -63,8 +57,6 @@ #endif #endif -IMPLEMENT_CLASS(wxScrolledWindow, wxGenericScrolledWindow) - /* TODO PROPERTIES style wxHSCROLL | wxVSCROLL @@ -288,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 = @@ -313,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() @@ -365,7 +361,11 @@ void wxScrollHelper::SetScrollbars(int pixelsPerUnitX, // 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()); @@ -407,19 +407,12 @@ 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; +#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 @@ -642,8 +635,13 @@ void wxScrollHelper::AdjustScrollbars() // 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 @@ -755,7 +753,7 @@ void wxScrollHelper::AdjustScrollbars() 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 @@ -932,15 +930,6 @@ void wxScrollHelper::GetViewStart (int *x, int *y) const *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 ) @@ -957,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 // ---------------------------------------------------------------------------- @@ -967,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 ); } @@ -1229,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, @@ -1246,44 +1300,20 @@ bool wxGenericScrolledWindow::Create(wxWindow *parent, 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 @@ -1293,8 +1323,7 @@ void wxGenericScrolledWindow::OnPaint(wxPaintEvent& event) } #ifdef __WXMSW__ -WXLRESULT -wxGenericScrolledWindow::MSWWindowProc(WXUINT nMsg, +WXLRESULT wxScrolledWindow::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) { @@ -1313,6 +1342,3 @@ wxGenericScrolledWindow::MSWWindowProc(WXUINT nMsg, #endif // __WXMSW__ -#endif // !wxGTK - -// vi:sts=4:sw=4:et