From: Vadim Zeitlin Date: Tue, 12 Jan 1999 23:51:13 +0000 (+0000) Subject: minor samples fixes X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/1d5b7a0be4977b291d37d582717d99d7afd24f33 minor samples fixes git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1389 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/samples/image/image.cpp b/samples/image/image.cpp index 12ca058f16..d944c5c757 100644 --- a/samples/image/image.cpp +++ b/samples/image/image.cpp @@ -1,6 +1,6 @@ /* * Program: image - * + * * Author: Robert Roebling * * Copyright: (C) 1998, Robert Roebling @@ -29,47 +29,41 @@ class MyApp; class MyCanvas: public wxScrolledWindow { - DECLARE_DYNAMIC_CLASS(MyCanvas) - - public: - - MyCanvas(void) {}; +public: + MyCanvas() {}; MyCanvas( wxWindow *parent, wxWindowID, const wxPoint &pos, const wxSize &size ); - ~MyCanvas(void); + ~MyCanvas(); void OnPaint( wxPaintEvent &event ); - + wxBitmap *my_horse; wxBitmap *my_square; - - DECLARE_EVENT_TABLE() + + DECLARE_DYNAMIC_CLASS(MyCanvas) + DECLARE_EVENT_TABLE() }; // MyFrame class MyFrame: public wxFrame { - DECLARE_DYNAMIC_CLASS(MyFrame) +public: + MyFrame(); - public: - - MyFrame(void); - void OnSize( wxSizeEvent &event ); void OnAbout( wxCommandEvent &event ); void OnQuit( wxCommandEvent &event ); - + MyCanvas *m_canvas; - - DECLARE_EVENT_TABLE() + + DECLARE_DYNAMIC_CLASS(MyFrame) + DECLARE_EVENT_TABLE() }; // MyApp class MyApp: public wxApp { - public: - - MyApp(void); - virtual bool OnInit(void); +public: + virtual bool OnInit(); }; // main program @@ -80,17 +74,18 @@ IMPLEMENT_APP(MyApp) IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow) -BEGIN_EVENT_TABLE(MyCanvas,wxScrolledWindow) - EVT_PAINT (MyCanvas::OnPaint) +BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) + EVT_PAINT(MyCanvas::OnPaint) END_EVENT_TABLE() -MyCanvas::MyCanvas( wxWindow *parent, const wxWindowID id, const wxPoint &pos, const wxSize &size ) - : wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER ) +MyCanvas::MyCanvas( wxWindow *parent, const wxWindowID id, + const wxPoint &pos, const wxSize &size ) + : wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER ) { SetBackgroundColour(* wxWHITE); wxBitmap bitmap( 100, 100 ); - + wxMemoryDC dc; dc.SelectObject( bitmap ); dc.SetBrush( wxBrush( "orange", wxSOLID ) ); @@ -106,18 +101,18 @@ MyCanvas::MyCanvas( wxWindow *parent, const wxWindowID id, const wxPoint &pos, c wxImage image( bitmap ); image.SaveFile( dir + wxString("test.png"), wxBITMAP_TYPE_PNG ); - + image.LoadFile( dir + wxString("horse.png"), wxBITMAP_TYPE_PNG ); image.SetRGB( 0, 0, 250, 0, 0 ); image.SetRGB( 1, 0, 100, 100, 100 ); image.SetRGB( 2, 0, 250, 250, 250 ); my_horse = new wxBitmap( image.ConvertToBitmap() ); - + image.LoadFile( dir + wxString("test.png"), wxBITMAP_TYPE_PNG ); my_square = new wxBitmap( image.ConvertToBitmap() ); } -MyCanvas::~MyCanvas(void) +MyCanvas::~MyCanvas() { delete my_horse; delete my_square; @@ -130,12 +125,12 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) dc.DrawText( "Loaded image", 30, 100 ); if (my_square->Ok()) dc.DrawBitmap( *my_square, 30, 120 ); - + dc.DrawText( "Drawn directly", 150, 100 ); dc.SetBrush( wxBrush( "orange", wxSOLID ) ); dc.SetPen( *wxWHITE_PEN ); dc.DrawRectangle( 150, 120, 100, 100 ); - + if (my_horse->Ok()) dc.DrawBitmap( *my_horse, 30, 240 ); } @@ -149,25 +144,25 @@ IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame ) BEGIN_EVENT_TABLE(MyFrame,wxFrame) EVT_MENU (ID_ABOUT, MyFrame::OnAbout) EVT_MENU (ID_QUIT, MyFrame::OnQuit) - EVT_SIZE (MyFrame::OnSize) END_EVENT_TABLE() -MyFrame::MyFrame(void) : - wxFrame( (wxFrame *) NULL, -1, "wxImage sample", wxPoint(20,20), wxSize(470,360) ) +MyFrame::MyFrame() + : wxFrame( (wxFrame *)NULL, -1, "wxImage sample", + wxPoint(20,20), wxSize(470,360) ) { wxMenu *file_menu = new wxMenu(); file_menu->Append( ID_ABOUT, "About.."); file_menu->Append( ID_QUIT, "Exit"); - + wxMenuBar *menu_bar = new wxMenuBar(); menu_bar->Append(file_menu, "File"); SetMenuBar( menu_bar ); - + CreateStatusBar(2); int widths[] = { -1, 100 }; SetStatusWidths( 2, widths ); - + m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) ); m_canvas->SetScrollbars( 10, 10, 50, 50 ); } @@ -179,33 +174,22 @@ void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) ) void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) ) { - (void) wxMessageBox( "wxImage demo\nRobert Roebling (c) 1998", "About wxImage Demo", wxOK ); -} - -void MyFrame::OnSize( wxSizeEvent &WXUNUSED(event) ) -{ - int w,h; - GetClientSize( &w, &h ); - if (m_canvas) - m_canvas->SetSize( w, h ); + (void)wxMessageBox( "wxImage demo\n" + "Robert Roebling (c) 1998", + "About wxImage Demo", wxICON_INFORMATION | wxOK ); } //----------------------------------------------------------------------------- // MyApp //----------------------------------------------------------------------------- -MyApp::MyApp(void) : - wxApp( ) -{ -} - -bool MyApp::OnInit(void) +bool MyApp::OnInit() { wxImage::AddHandler( new wxPNGHandler ); - + wxFrame *frame = new MyFrame(); frame->Show( TRUE ); - + return TRUE; } diff --git a/samples/resource/resource.cpp b/samples/resource/resource.cpp index 19aab9edca..836cf563a4 100644 --- a/samples/resource/resource.cpp +++ b/samples/resource/resource.cpp @@ -97,18 +97,6 @@ bool MyApp::OnInit(void) // Give it a status line frame->CreateStatusBar(2); -/* - // Make a menubar - wxMenu *file_menu = new wxMenu; - - file_menu->Append(RESOURCE_TEST1, "&Dialog box test", "Test dialog box resource"); - file_menu->Append(RESOURCE_QUIT, "E&xit", "Quit program"); - - wxMenuBar *menu_bar = new wxMenuBar; - - menu_bar->Append(file_menu, "&File"); -*/ - wxMenuBar *menu_bar = wxResourceCreateMenuBar("menu1"); // Associate the menu bar with the frame @@ -123,6 +111,12 @@ bool MyApp::OnInit(void) return TRUE; } +MyApp::~MyApp() +{ + delete dialog1; + delete menu1; +} + BEGIN_EVENT_TABLE(MyPanel, wxPanel) EVT_LEFT_DOWN( MyPanel::OnClick) END_EVENT_TABLE() @@ -133,17 +127,18 @@ MyPanel::MyPanel( wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxS { } -void MyPanel::OnClick( wxMouseEvent &WXUNUSED(event) ) +void MyPanel::OnClick( wxMouseEvent &WXUNUSED(event2) ) { MyFrame *frame = (MyFrame*)(wxTheApp->GetTopWindow()); wxCommandEvent event; - frame->OnTest1( event ); + frame->OnTestDialog( event ); } BEGIN_EVENT_TABLE(MyFrame, wxFrame) + EVT_MENU(RESOURCE_ABOUT, MyFrame::OnAbout) EVT_MENU(RESOURCE_QUIT, MyFrame::OnQuit) - EVT_MENU(RESOURCE_TEST1, MyFrame::OnTest1) + EVT_MENU(RESOURCE_TESTDIALOG, MyFrame::OnTestDialog) END_EVENT_TABLE() // Define my frame constructor @@ -153,12 +148,19 @@ MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, c panel = (wxWindow *) NULL; } +void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) ) +{ + wxMessageBox("wxWindows resource sample.\n" + "(c) Julian Smart", "About wxWindows sample", + wxICON_INFORMATION | wxOK); +} + void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) ) { Close(TRUE); } -void MyFrame::OnTest1(wxCommandEvent& WXUNUSED(event) ) +void MyFrame::OnTestDialog(wxCommandEvent& WXUNUSED(event) ) { MyDialog *dialog = new MyDialog; if (dialog->LoadFromResource(this, "dialog1")) diff --git a/samples/resource/resource.h b/samples/resource/resource.h index 9111d6caf0..714d982ffd 100644 --- a/samples/resource/resource.h +++ b/samples/resource/resource.h @@ -16,46 +16,55 @@ // Define a new application class MyApp: public wxApp { - public: - MyApp(void) ; - bool OnInit(void); +public: + MyApp(); + + virtual bool OnInit(); + + virtual ~MyApp(); }; class MyPanel: public wxPanel { - public: - MyPanel( wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, - int style, const wxString &name ); +public: + MyPanel(wxWindow *parent, wxWindowID id, const wxPoint& pos, + const wxSize& size, int style, const wxString &name); void OnClick(wxMouseEvent &event); - - DECLARE_EVENT_TABLE() + +private: + DECLARE_EVENT_TABLE() }; class MyFrame: public wxFrame { - public: - wxWindow *panel; - MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size); - bool OnClose(void); +public: + MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, + const wxPoint& pos, const wxSize& size); + bool OnClose(); void OnQuit(wxCommandEvent& event); - void OnTest1(wxCommandEvent& event); + void OnAbout(wxCommandEvent& event); + void OnTestDialog(wxCommandEvent& event); + + wxWindow *panel; - DECLARE_EVENT_TABLE() +private: + DECLARE_EVENT_TABLE() }; class MyDialog : public wxDialog { - public: +public: void OnOk(wxCommandEvent& event); void OnCancel(wxCommandEvent& event); - - DECLARE_EVENT_TABLE() + +private: + DECLARE_EVENT_TABLE() }; -#define RESOURCE_QUIT 4 -#define RESOURCE_TEST1 2 - -/* -#define RESOURCE_OK 1 -#define RESOURCE_CANCEL 2 -*/ +// the values should be the same as in menu.wxr file! +enum +{ + RESOURCE_TESTDIALOG = 2, + RESOURCE_QUIT = 4, + RESOURCE_ABOUT = 6 +}; diff --git a/samples/toolbar/test.cpp b/samples/toolbar/test.cpp index 2403237fc0..cd661ac65c 100644 --- a/samples/toolbar/test.cpp +++ b/samples/toolbar/test.cpp @@ -164,7 +164,7 @@ END_EVENT_TABLE() // Define my frame constructor MyFrame::MyFrame(wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style): - wxFrame(parent, id, title, pos, size, style), m_timer(this) + wxFrame(parent, id, title, pos, size, style) { m_textWindow = new wxTextCtrl(this, -1, "", wxPoint(0, 0), wxSize(-1, -1), wxTE_MULTILINE); } @@ -176,10 +176,7 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { -// (void)wxMessageBox("wxWindows wxToolBar demo\n", "About wxToolBar"); - wxLogStatus("Started timer."); - - m_timer.Start(500, TRUE); + (void)wxMessageBox("wxWindows toolbar sample", "About wxToolBar"); } // Define the behaviour for the frame closing diff --git a/samples/toolbar/test.h b/samples/toolbar/test.h index dcea766cb8..63da855c34 100644 --- a/samples/toolbar/test.h +++ b/samples/toolbar/test.h @@ -45,9 +45,7 @@ public: private: wxTextCtrl* m_textWindow; - MyTimer m_timer; - -DECLARE_EVENT_TABLE() + DECLARE_EVENT_TABLE() }; #define ID_TOOLBAR 500