MyScrolledWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size );
~MyScrolledWindow(){};
void OnPaint( wxPaintEvent &event );
-
+ void OnSize( wxSizeEvent &event );
private:
MyCanvas *m_canvas;
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,
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 );
// 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
// 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
{
// 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
{