]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/scroll/scroll.cpp
corrected conditional compilation
[wxWidgets.git] / samples / scroll / scroll.cpp
index 3567376359a8b2ff1f2c9270ea8c1c031f8d91a2..71d7b0e83c0c0ccb78dd5942d19b4e84230564e7 100644 (file)
@@ -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;
@@ -96,12 +99,13 @@ IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow)
 
 BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
   EVT_PAINT(                  MyCanvas::OnPaint)
-  EVT_LEFT_DOWN(              MyCanvas::OnMouseDown)
+  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,
@@ -113,6 +117,8 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
     (void) new wxButton( this, ID_MOVEBUTTON, "move button", wxPoint(150,10) );
     (void) new wxButton( this, ID_SCROLLWIN, "scroll win", wxPoint(250,10) );
 
+#if 0
+
     wxString choices[] =
     {
         "This",
@@ -121,15 +127,15 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
         "wonderful",
         "examples."
     };
-  
+
     m_button = new wxButton( this, ID_QUERYPOS, "Query position", wxPoint(10,110) );
-  
+
     (void) new wxTextCtrl( this, -1, "wxTextCtrl", wxPoint(10,150), wxSize(80,-1) );
-  
+
     (void) new wxRadioButton( this, -1, "Disable", wxPoint(10,190) );
-  
+
     (void) new wxComboBox( this, -1, "This", wxPoint(10,230), wxDefaultSize, 5, choices );
-  
+
     (void) new wxRadioBox( this, -1, "This", wxPoint(10,310), wxDefaultSize, 5, choices, 2, wxRA_SPECIFY_COLS );
 
     (void) new wxRadioBox( this, -1, "This", wxPoint(10,440), wxDefaultSize, 5, choices, 2, wxRA_SPECIFY_ROWS );
@@ -151,24 +157,31 @@ 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 );
+#endif
+
+    wxPanel *test = new wxPanel( this, -1, wxPoint(10, 10), wxSize(130,50), wxSIMPLE_BORDER | wxTAB_TRAVERSAL );
     test->SetBackgroundColour( "WHEAT" );
+
+#if 0
+
     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) );
     test2->SetCursor( wxCursor( wxCURSOR_NO_ENTRY ) );
 
-    SetBackgroundColour( "WHEAT" );
-  
+#endif
+
+    SetBackgroundColour( "BLUE" );
+
     SetCursor( wxCursor( wxCURSOR_IBEAM ) );
 }
 
@@ -178,10 +191,16 @@ MyCanvas::~MyCanvas()
 
 void MyCanvas::OnMouseDown( wxMouseEvent &event )
 {
-    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.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() )
+            wxLogMessage( "Error: LeftIsDown() should be TRUE if for LeftDown()" );
+    }
 }
 
 void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
@@ -192,7 +211,7 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
     dc.DrawText( "Press mouse button to test calculations!", 160, 50 );
 
     dc.DrawText( "Some text", 140, 140 );
-  
+
     dc.DrawRectangle( 100, 160, 200, 200 );
 }
 
@@ -241,14 +260,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()
@@ -258,6 +290,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");
 
@@ -272,20 +306,30 @@ MyFrame::MyFrame()
 
     m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(100,100) );
     m_canvas->SetScrollbars( 10, 10, 50, 100 );
-  
+#if 0
     m_log = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE );
     wxLog *old_log = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) );
     delete old_log;
-    
+#endif
     wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
-    
+
     topsizer->Add( m_canvas, 1, wxEXPAND );
-    topsizer->Add( m_log, 0, wxEXPAND );
+//  topsizer->Add( m_log, 0, wxEXPAND );
 
     SetAutoLayout( TRUE );
     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 );