X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ed673c6a48b3479beac60a93ff8f44611e44415f..ce6d2511f82aafc78aba320018c868f826ab172b:/samples/scroll/scroll.cpp?ds=sidebyside diff --git a/samples/scroll/scroll.cpp b/samples/scroll/scroll.cpp index 67c936293b..8f5cba310c 100644 --- a/samples/scroll/scroll.cpp +++ b/samples/scroll/scroll.cpp @@ -38,10 +38,12 @@ 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 ); wxButton *m_button; @@ -84,6 +86,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,7 +95,9 @@ 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) @@ -117,9 +122,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 +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) ); @@ -171,15 +176,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 +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) ) @@ -202,16 +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( 100, 160, 200, 200 ); -} - // MyFrame const int ID_QUIT = 108;