X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3da17724b6a873579628356a92ade9c41f07d5a3..ff67d5860d2177ad5d4f66c13bb748ef975af88d:/samples/scroll/scroll.cpp diff --git a/samples/scroll/scroll.cpp b/samples/scroll/scroll.cpp index 8f5cba310c..b190de4637 100644 --- a/samples/scroll/scroll.cpp +++ b/samples/scroll/scroll.cpp @@ -44,6 +44,7 @@ public: void OnMoveButton( wxCommandEvent &event ); void OnScrollWin( wxCommandEvent &event ); void OnMouseDown( wxMouseEvent &event ); + void OnScroll( wxScrollWinEvent &event ); wxButton *m_button; @@ -60,6 +61,8 @@ public: void OnAbout( wxCommandEvent &event ); void OnQuit( wxCommandEvent &event ); + void OnDeleteAll( wxCommandEvent &event ); + void OnInsertNew( wxCommandEvent &event ); MyCanvas *m_canvas; wxTextCtrl *m_log; @@ -102,6 +105,7 @@ BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) EVT_BUTTON( ID_DELBUTTON, MyCanvas::OnDeleteButton) EVT_BUTTON( ID_MOVEBUTTON, MyCanvas::OnMoveButton) EVT_BUTTON( ID_SCROLLWIN, MyCanvas::OnScrollWin) + EVT_SCROLLWIN( MyCanvas::OnScroll) END_EVENT_TABLE() MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id, @@ -184,12 +188,9 @@ void MyCanvas::OnMouseDown( wxMouseEvent &event ) int x,y; CalcUnscrolledPosition( pt.x, pt.y, &x, &y ); wxLogMessage( "Mouse down event at: %d %d, scrolled: %d %d", pt.x, pt.y, x, y ); - } - - if (event.LeftIsDown() && - event.LeftDown()) - { - wxLogMessage( "Error: both LeftDown() and LeftIsDown() are TRUE!" ); + + if ( !event.LeftIsDown() ) + wxLogMessage( "Error: LeftIsDown() should be TRUE if for LeftDown()" ); } } @@ -250,14 +251,27 @@ void MyCanvas::OnScrollWin( wxCommandEvent &WXUNUSED(event) ) Scroll( -1, y+2 ); } +void MyCanvas::OnScroll( wxScrollWinEvent &event ) +{ + if (( event.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE )) + { + wxLogMessage( "Thumb released; position: %u", event.GetPosition() ); + } + event.Skip(); +} + // MyFrame const int ID_QUIT = 108; const int ID_ABOUT = 109; +const int ID_DELETE_ALL = 110; +const int ID_INSERT_NEW = 111; IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame ) BEGIN_EVENT_TABLE(MyFrame,wxFrame) + EVT_MENU (ID_DELETE_ALL, MyFrame::OnDeleteAll) + EVT_MENU (ID_INSERT_NEW, MyFrame::OnInsertNew) EVT_MENU (ID_ABOUT, MyFrame::OnAbout) EVT_MENU (ID_QUIT, MyFrame::OnQuit) END_EVENT_TABLE() @@ -267,6 +281,8 @@ MyFrame::MyFrame() wxPoint(20,20), wxSize(470,500) ) { wxMenu *file_menu = new wxMenu(); + file_menu->Append( ID_DELETE_ALL, "Delete all"); + file_menu->Append( ID_INSERT_NEW, "Insert new"); file_menu->Append( ID_ABOUT, "&About.."); file_menu->Append( ID_QUIT, "E&xit\tAlt-X"); @@ -295,6 +311,16 @@ MyFrame::MyFrame() SetSizer( topsizer ); } +void MyFrame::OnDeleteAll( wxCommandEvent &WXUNUSED(event) ) +{ + m_canvas->DestroyChildren(); +} + +void MyFrame::OnInsertNew( wxCommandEvent &WXUNUSED(event) ) +{ + (void)new wxButton( m_canvas, -1, "Hello", wxPoint(100,100) ); +} + void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) ) { Close( TRUE );