+
+// ----------------------------------------------------------------------------
+// Autoscrolling example.
+// ----------------------------------------------------------------------------
+
+// this class uses the 'virtual' size attribute along with an internal
+// sizer to automatically set up scrollbars as needed
+
+class MyAutoScrollWindow : public wxScrolledWindow
+{
+private:
+
+ wxButton *m_button;
+
+public:
+
+ MyAutoScrollWindow( wxWindow *parent );
+
+ void OnResizeClick( wxCommandEvent &WXUNUSED( event ) );
+
+ DECLARE_EVENT_TABLE()
+};
+
+
+// ----------------------------------------------------------------------------
+// MyScrolledWindow classes: examples of wxScrolledWindow usage
+// ----------------------------------------------------------------------------
+
+// base class for both of them
+class MyScrolledWindowBase : public wxScrolledWindow
+{
+public:
+ MyScrolledWindowBase(wxWindow *parent)
+ : wxScrolledWindow(parent)
+ , m_nLines( 100 )
+ {
+ wxClientDC dc(this);
+ dc.GetTextExtent(_T("Line 17"), NULL, &m_hLine);
+ }
+
+protected:
+ // the height of one line on screen
+ wxCoord m_hLine;
+
+ // the number of lines we draw
+ size_t m_nLines;
+};
+
+// this class does "stupid" redrawing - it redraws everything each time
+// and sets the scrollbar extent directly.
+
+class MyScrolledWindowDumb : public MyScrolledWindowBase
+{
+public:
+ MyScrolledWindowDumb(wxWindow *parent) : MyScrolledWindowBase(parent)
+ {
+ // no horz scrolling
+ SetScrollbars(0, m_hLine, 0, m_nLines + 1, 0, 0, TRUE /* no refresh */);
+ }
+
+ virtual void OnDraw(wxDC& dc);
+};
+
+// this class does "smart" redrawing - only redraws the lines which must be
+// redrawn and sets the scroll rate and virtual size to affect the
+// scrollbars.
+//
+// Note that this class should produce identical results to the one above.
+
+class MyScrolledWindowSmart : public MyScrolledWindowBase
+{
+public:
+ MyScrolledWindowSmart(wxWindow *parent) : MyScrolledWindowBase(parent)
+ {
+ // no horz scrolling
+ SetScrollRate( 0, m_hLine );
+ SetVirtualSize( -1, ( m_nLines + 1 ) * m_hLine );
+ }
+
+ virtual void OnDraw(wxDC& dc);
+};
+
+
+// ----------------------------------------------------------------------------