X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ed673c6a48b3479beac60a93ff8f44611e44415f..f1567cddead054974c4a079ed8ee2c798ef998dc:/samples/scroll/scroll.cpp diff --git a/samples/scroll/scroll.cpp b/samples/scroll/scroll.cpp index 67c936293b..c16f08b042 100644 --- a/samples/scroll/scroll.cpp +++ b/samples/scroll/scroll.cpp @@ -38,10 +38,13 @@ public: MyCanvas( wxWindow *parent, wxWindowID, const wxPoint &pos, const wxSize &size ); ~MyCanvas(); void OnPaint( wxPaintEvent &event ); + void OnQueryPosition( wxCommandEvent &event ); void OnAddButton( wxCommandEvent &event ); void OnDeleteButton( wxCommandEvent &event ); void OnMoveButton( wxCommandEvent &event ); void OnScrollWin( wxCommandEvent &event ); + void OnMouseDown( wxMouseEvent &event ); + void OnScroll( wxScrollWinEvent &event ); wxButton *m_button; @@ -58,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; @@ -84,6 +89,7 @@ IMPLEMENT_APP(MyApp) #define ID_DELBUTTON 2 #define ID_MOVEBUTTON 3 #define ID_SCROLLWIN 4 +#define ID_QUERYPOS 5 #define ID_NEWBUTTON 10 @@ -92,11 +98,14 @@ IMPLEMENT_APP(MyApp) IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow) BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) - EVT_PAINT( MyCanvas::OnPaint) + EVT_PAINT( MyCanvas::OnPaint) + EVT_MOUSE_EVENTS( MyCanvas::OnMouseDown) + EVT_BUTTON( ID_QUERYPOS, MyCanvas::OnQueryPosition) EVT_BUTTON( ID_ADDBUTTON, MyCanvas::OnAddButton) 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, @@ -117,9 +126,9 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id, "examples." }; - m_button = new wxButton( this, -1, "wxButton", wxPoint(10,110) ); + m_button = new wxButton( this, ID_QUERYPOS, "Query position", wxPoint(10,110) ); - (void) new wxTextCtrl( this, -1, "wxTextCtrl", wxPoint(10,150) ); + (void) new wxTextCtrl( this, -1, "wxTextCtrl", wxPoint(10,150), wxSize(80,-1) ); (void) new wxRadioButton( this, -1, "Disable", wxPoint(10,190) ); @@ -146,17 +155,17 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id, (void) new wxListBox( this, -1, wxPoint(260,280), wxSize(120,120), 5, choices, wxLB_ALWAYS_SB ); - wxWindow *test = new wxWindow( this, -1, wxPoint(10, 530), wxSize(130,120), wxSIMPLE_BORDER | wxTAB_TRAVERSAL ); + wxPanel *test = new wxPanel( this, -1, wxPoint(10, 530), wxSize(130,120), wxSIMPLE_BORDER | wxTAB_TRAVERSAL ); test->SetBackgroundColour( "WHEAT" ); wxButton *test2 = new wxButton( test, -1, "Hallo", wxPoint(10,10) ); - test = new wxWindow( this, -1, wxPoint(160, 530), wxSize(130,120), wxSUNKEN_BORDER | wxTAB_TRAVERSAL ); + test = new wxPanel( this, -1, wxPoint(160, 530), wxSize(130,120), wxSUNKEN_BORDER | wxTAB_TRAVERSAL ); test->SetBackgroundColour( "WHEAT" ); test->SetCursor( wxCursor( wxCURSOR_NO_ENTRY ) ); test2 = new wxButton( test, -1, "Hallo", wxPoint(10,10) ); test2->SetCursor( wxCursor( wxCURSOR_PENCIL ) ); - test = new wxWindow( this, -1, wxPoint(310, 530), wxSize(130,120), wxRAISED_BORDER | wxTAB_TRAVERSAL ); + test = new wxPanel( this, -1, wxPoint(310, 530), wxSize(130,120), wxRAISED_BORDER | wxTAB_TRAVERSAL ); test->SetBackgroundColour( "WHEAT" ); test->SetCursor( wxCursor( wxCURSOR_PENCIL ) ); test2 = new wxButton( test, -1, "Hallo", wxPoint(10,10) ); @@ -171,15 +180,54 @@ MyCanvas::~MyCanvas() { } +void MyCanvas::OnMouseDown( wxMouseEvent &event ) +{ + if (event.LeftDown()) + { + wxPoint pt( event.GetPosition() ); + 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!" ); + } +} + +void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) +{ + wxPaintDC dc( this ); + PrepareDC( dc ); + + dc.DrawText( "Press mouse button to test calculations!", 160, 50 ); + + dc.DrawText( "Some text", 140, 140 ); + + dc.DrawRectangle( 100, 160, 200, 200 ); +} + +void MyCanvas::OnQueryPosition( wxCommandEvent &WXUNUSED(event) ) +{ + wxPoint pt( m_button->GetPosition() ); + wxLogMessage( "Position of ""Query position"" is %d %d", pt.x, pt.y ); + pt = ClientToScreen( pt ); + wxLogMessage( "Position of ""Query position"" on screen is %d %d", pt.x, pt.y ); +} + void MyCanvas::OnAddButton( wxCommandEvent &WXUNUSED(event) ) { - wxLogMessage( "Inserting button at position 50,50" ); - (void) new wxButton( this, ID_NEWBUTTON, "new button", wxPoint(50,50) ); + wxLogMessage( "Inserting button at position 10,70..." ); + wxButton *button = new wxButton( this, ID_NEWBUTTON, "new button", wxPoint(10,70), wxSize(80,25) ); + wxPoint pt( button->GetPosition() ); + wxLogMessage( "-> Position after inserting %d %d", pt.x, pt.y ); } void MyCanvas::OnDeleteButton( wxCommandEvent &event ) { - wxLogMessage( "deleting button inserted with ""add button""" ); + wxLogMessage( "Deleting button inserted with ""Add button""..." ); wxWindow *win = FindWindow( ID_NEWBUTTON ); if (win) win->Destroy(); @@ -191,7 +239,11 @@ void MyCanvas::OnMoveButton( wxCommandEvent &event ) { wxLogMessage( "Moving button 10 pixels downward.." ); wxWindow *win = FindWindow( event.GetId() ); - win->Move( -1, win->GetPosition().y + 10 ); + wxPoint pt( win->GetPosition() ); + wxLogMessage( "-> Position before move is %d %d", pt.x, pt.y ); + win->Move( -1, pt.y + 10 ); + pt = win->GetPosition(); + wxLogMessage( "-> Position after move is %d %d", pt.x, pt.y ); } void MyCanvas::OnScrollWin( wxCommandEvent &WXUNUSED(event) ) @@ -202,24 +254,27 @@ void MyCanvas::OnScrollWin( wxCommandEvent &WXUNUSED(event) ) Scroll( -1, y+2 ); } -void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) +void MyCanvas::OnScroll( wxScrollWinEvent &event ) { - wxPaintDC dc( this ); - PrepareDC( dc ); - - dc.DrawText( "Some text", 140, 140 ); - - dc.DrawRectangle( 100, 160, 200, 200 ); + 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() @@ -229,6 +284,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"); @@ -257,6 +314,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 );