X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/307f16e829979a22bf00b699b5b2e852cd4eb59e..ce6d2511f82aafc78aba320018c868f826ab172b:/samples/scroll/scroll.cpp diff --git a/samples/scroll/scroll.cpp b/samples/scroll/scroll.cpp index 0d20a0aed6..8f5cba310c 100644 --- a/samples/scroll/scroll.cpp +++ b/samples/scroll/scroll.cpp @@ -43,6 +43,7 @@ public: void OnDeleteButton( wxCommandEvent &event ); void OnMoveButton( wxCommandEvent &event ); void OnScrollWin( wxCommandEvent &event ); + void OnMouseDown( wxMouseEvent &event ); wxButton *m_button; @@ -95,6 +96,7 @@ IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow) BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) 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) @@ -122,7 +124,7 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id, 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) ); @@ -149,17 +151,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) ); @@ -174,20 +176,49 @@ 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( """wxButton"" position %d %d", pt.x, pt.y ); - if ((pt.x == 10) && (pt.y == 110)) - wxLogMessage( "-> Correct." ); - else - wxLogMessage( "-> Incorrect." ); + 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 10,70..." ); - (void) new wxButton( this, ID_NEWBUTTON, "new button", wxPoint(10,70), wxSize(80,25) ); + 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 ) @@ -204,7 +235,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) ) @@ -215,18 +250,6 @@ void MyCanvas::OnScrollWin( wxCommandEvent &WXUNUSED(event) ) Scroll( -1, y+2 ); } -void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) -{ - wxPaintDC dc( this ); - PrepareDC( dc ); - - dc.DrawText( "Some text", 140, 140 ); - - dc.DrawRectangle( 10, 70, 80, 25 ); - - dc.DrawRectangle( 100, 160, 200, 200 ); -} - // MyFrame const int ID_QUIT = 108;