+ wxPaintDC dc( this );
+ PrepareDC( dc );
+
+ dc.DrawText( _T("Press mouse button to test calculations!"), 160, 50 );
+
+ dc.DrawText( _T("Some text"), 140, 140 );
+
+ dc.DrawRectangle( 100, 160, 200, 200 );
+}
+
+void MyCanvas::OnQueryPosition( wxCommandEvent &WXUNUSED(event) )
+{
+ wxPoint pt( m_button->GetPosition() );
+ wxLogMessage( wxT("Position of \"Query position\" is %d %d"), pt.x, pt.y );
+ pt = ClientToScreen( pt );
+ wxLogMessage( wxT("Position of \"Query position\" on screen is %d %d"), pt.x, pt.y );
+}
+
+void MyCanvas::OnAddButton( wxCommandEvent &WXUNUSED(event) )
+{
+ wxLogMessage( wxT("Inserting button at position 10,70...") );
+ wxButton *button = new wxButton( this, ID_NEWBUTTON, wxT("new button"), wxPoint(10,70), wxSize(80,25) );
+ wxPoint pt( button->GetPosition() );
+ wxLogMessage( wxT("-> Position after inserting %d %d"), pt.x, pt.y );
+}
+
+void MyCanvas::OnDeleteButton( wxCommandEvent &WXUNUSED(event) )
+{
+ wxLogMessage( wxT("Deleting button inserted with \"Add button\"...") );
+ wxWindow *win = FindWindow( ID_NEWBUTTON );
+ if (win)
+ win->Destroy();
+ else
+ wxLogMessage( wxT("-> No window with id = ID_NEWBUTTON found.") );
+}
+
+void MyCanvas::OnMoveButton( wxCommandEvent &event )
+{
+ wxLogMessage( wxT("Moving button 10 pixels downward..") );
+ wxWindow *win = FindWindow( event.GetId() );
+ wxPoint pt( win->GetPosition() );
+ wxLogMessage( wxT("-> Position before move is %d %d"), pt.x, pt.y );
+ win->Move( -1, pt.y + 10 );
+ pt = win->GetPosition();
+ wxLogMessage( wxT("-> Position after move is %d %d"), pt.x, pt.y );
+}
+
+void MyCanvas::OnScrollWin( wxCommandEvent &WXUNUSED(event) )
+{
+ wxLogMessage( wxT("Scrolling 2 units up.\nThe white square and the controls should move equally!") );
+ int x,y;
+ GetViewStart( &x, &y );
+ Scroll( -1, y+2 );
+}
+
+// MyAutoScrollWindow
+
+const long ID_RESIZEBUTTON = wxNewId();
+const wxSize SMALL_BUTTON( 100, 50 );
+const wxSize LARGE_BUTTON( 300, 100 );
+
+BEGIN_EVENT_TABLE( MyAutoScrollWindow, wxScrolledWindow)
+ EVT_BUTTON( ID_RESIZEBUTTON, MyAutoScrollWindow::OnResizeClick)
+END_EVENT_TABLE()
+
+MyAutoScrollWindow::MyAutoScrollWindow( wxWindow *parent )
+ : wxScrolledWindow( parent )
+{
+ SetBackgroundColour( wxT("GREEN") );
+
+ // Set the rate we'd like for scrolling.
+
+ SetScrollRate( 5, 5 );
+
+ // Populate a sizer with a 'resizing' button and some
+ // other static decoration
+
+ wxFlexGridSizer *innersizer = new wxFlexGridSizer( 2, 2 );
+
+ m_button = new wxButton( this,
+ ID_RESIZEBUTTON,
+ _T("Press me"),
+ wxDefaultPosition,
+ SMALL_BUTTON );
+
+ // We need to do this here, because wxADJUST_MINSIZE below
+ // will cause the initial size to be ignored for Best/Min size.
+ // It would be nice to fix the sizers to handle this a little
+ // more cleanly.
+
+ m_button->SetSizeHints( SMALL_BUTTON.GetWidth(), SMALL_BUTTON.GetHeight() );
+
+ innersizer->Add( m_button,
+ 0,
+ wxALIGN_CENTER | wxALL | wxADJUST_MINSIZE,
+ 20 );
+
+ innersizer->Add( new wxStaticText( this, -1, _T("This is just") ),
+ 0,
+ wxALIGN_CENTER );
+
+ innersizer->Add( new wxStaticText( this, -1, _T("some decoration") ),
+ 0,
+ wxALIGN_CENTER );
+
+ innersizer->Add( new wxStaticText( this, -1, _T("for you to scroll...") ),
+ 0,
+ wxALIGN_CENTER );
+
+ // Then use the sizer to set the scrolled region size.
+
+ SetSizer( innersizer );
+}
+
+void MyAutoScrollWindow::OnResizeClick( wxCommandEvent &WXUNUSED( event ) )
+{
+ // Arbitrarily resize the button to change the minimum size of
+ // the (scrolled) sizer.
+
+ if( m_button->GetSize() == SMALL_BUTTON )
+ m_button->SetSizeHints( LARGE_BUTTON.GetWidth(), LARGE_BUTTON.GetHeight() );
+ else
+ m_button->SetSizeHints( SMALL_BUTTON.GetWidth(), SMALL_BUTTON.GetHeight() );
+
+ // Force update layout and scrollbars, since nothing we do here
+ // necessarily generates a size event which would do it for us.