From c376d80f4090ca681e91a96b6947ce299e5a950c Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Tue, 8 Mar 2005 22:37:46 +0000 Subject: [PATCH] Override OnSize in the scrollsub sample to disable sizer and scrollarea interferance. Made some code in wxScrolledWindow slightly clearer and removed a hack for something that shouldn't happen any more. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32688 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/scrollsub/scrollsub.cpp | 19 +++++++++++++++++-- src/generic/scrlwing.cpp | 19 +++++++------------ src/gtk/scrolwin.cpp | 17 +++++------------ src/gtk1/scrolwin.cpp | 17 +++++------------ 4 files changed, 34 insertions(+), 38 deletions(-) diff --git a/samples/scrollsub/scrollsub.cpp b/samples/scrollsub/scrollsub.cpp index 4891f67dab..71e4ba8b01 100644 --- a/samples/scrollsub/scrollsub.cpp +++ b/samples/scrollsub/scrollsub.cpp @@ -40,7 +40,7 @@ public: MyScrolledWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size ); ~MyScrolledWindow(){}; void OnPaint( wxPaintEvent &event ); - + void OnSize( wxSizeEvent &event ); private: MyCanvas *m_canvas; @@ -141,7 +141,8 @@ IMPLEMENT_APP(MyApp) IMPLEMENT_DYNAMIC_CLASS(MyScrolledWindow, wxScrolledWindow) BEGIN_EVENT_TABLE(MyScrolledWindow, wxScrolledWindow) - EVT_PAINT( MyScrolledWindow::OnPaint) + EVT_PAINT( MyScrolledWindow::OnPaint) + EVT_SIZE( MyScrolledWindow::OnSize) END_EVENT_TABLE() MyScrolledWindow::MyScrolledWindow( wxWindow *parent, wxWindowID id, @@ -177,6 +178,20 @@ MyScrolledWindow::MyScrolledWindow( wxWindow *parent, wxWindowID id, SetSizer( mainsizer ); } +void MyScrolledWindow::OnSize( wxSizeEvent &WXUNUSED(event) ) +{ + // We need to override OnSize so that our scrolled + // window a) does call Layout() to use sizers for + // positioning the controls but b) does not query + // the sizer for their size and use that for setting + // the scrollable area as set that ourselves by + // calling SetScrollbar() further down. + + Layout(); + + AdjustScrollbars(); +} + void MyScrolledWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) { wxPaintDC dc( this ); diff --git a/src/generic/scrlwing.cpp b/src/generic/scrlwing.cpp index c78ebc0fa7..6cdef7f64e 100644 --- a/src/generic/scrlwing.cpp +++ b/src/generic/scrlwing.cpp @@ -963,22 +963,17 @@ void wxScrollHelper::DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) co // Default OnSize resets scrollbars, if any void wxScrollHelper::HandleOnSize(wxSizeEvent& WXUNUSED(event)) { - if( m_win->GetAutoLayout() || m_targetWindow->GetAutoLayout() ) + if ( m_targetWindow->GetAutoLayout() ) { - if ( m_targetWindow != m_win ) - m_targetWindow->FitInside(); - - m_win->FitInside(); - - // FIXME: Something is really weird here... This should be - // called by FitInside above (and apparently is), yet the - // scrollsub sample will get the scrollbar wrong if resized - // quickly. This masks the bug, but is surely not the right - // answer at all. - AdjustScrollbars(); + wxSize size = m_targetWindow->GetBestVirtualSize(); + + // This will call ::Layout() and ::AdjustScrollbars() + SetVirtualSize( size ); } else + { AdjustScrollbars(); + } } // This calls OnDraw, having adjusted the origin according to the current diff --git a/src/gtk/scrolwin.cpp b/src/gtk/scrolwin.cpp index afd8aa4951..df01919089 100644 --- a/src/gtk/scrolwin.cpp +++ b/src/gtk/scrolwin.cpp @@ -852,19 +852,12 @@ bool wxScrolledWindow::Layout() // Default OnSize resets scrollbars, if any void wxScrolledWindow::OnSize(wxSizeEvent& WXUNUSED(event)) { - if( GetAutoLayout() || m_targetWindow->GetAutoLayout() ) + if ( m_targetWindow->GetAutoLayout() ) { - if( m_targetWindow != this ) - m_targetWindow->FitInside(); - - FitInside(); - - // FIXME: Something is really weird here... This should be - // called by FitInside above (and apparently is), yet the - // scrollsub sample will get the scrollbar wrong if resized - // quickly. This masks the bug, but is surely not the right - // answer at all. - AdjustScrollbars(); + wxSize size = m_targetWindow->GetBestVirtualSize(); + + // This will call ::Layout() and ::AdjustScrollbars() + SetVirtualSize( size ); } else { diff --git a/src/gtk1/scrolwin.cpp b/src/gtk1/scrolwin.cpp index afd8aa4951..df01919089 100644 --- a/src/gtk1/scrolwin.cpp +++ b/src/gtk1/scrolwin.cpp @@ -852,19 +852,12 @@ bool wxScrolledWindow::Layout() // Default OnSize resets scrollbars, if any void wxScrolledWindow::OnSize(wxSizeEvent& WXUNUSED(event)) { - if( GetAutoLayout() || m_targetWindow->GetAutoLayout() ) + if ( m_targetWindow->GetAutoLayout() ) { - if( m_targetWindow != this ) - m_targetWindow->FitInside(); - - FitInside(); - - // FIXME: Something is really weird here... This should be - // called by FitInside above (and apparently is), yet the - // scrollsub sample will get the scrollbar wrong if resized - // quickly. This masks the bug, but is surely not the right - // answer at all. - AdjustScrollbars(); + wxSize size = m_targetWindow->GetBestVirtualSize(); + + // This will call ::Layout() and ::AdjustScrollbars() + SetVirtualSize( size ); } else {