minor samples fixes

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1389 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 1999-01-12 23:51:13 +00:00
parent 73c700fdee
commit 1d5b7a0be4
5 changed files with 93 additions and 103 deletions

View File

@ -1,6 +1,6 @@
/* /*
* Program: image * Program: image
* *
* Author: Robert Roebling * Author: Robert Roebling
* *
* Copyright: (C) 1998, Robert Roebling * Copyright: (C) 1998, Robert Roebling
@ -29,47 +29,41 @@ class MyApp;
class MyCanvas: public wxScrolledWindow class MyCanvas: public wxScrolledWindow
{ {
DECLARE_DYNAMIC_CLASS(MyCanvas) public:
MyCanvas() {};
public:
MyCanvas(void) {};
MyCanvas( wxWindow *parent, wxWindowID, const wxPoint &pos, const wxSize &size ); MyCanvas( wxWindow *parent, wxWindowID, const wxPoint &pos, const wxSize &size );
~MyCanvas(void); ~MyCanvas();
void OnPaint( wxPaintEvent &event ); void OnPaint( wxPaintEvent &event );
wxBitmap *my_horse; wxBitmap *my_horse;
wxBitmap *my_square; wxBitmap *my_square;
DECLARE_EVENT_TABLE() DECLARE_DYNAMIC_CLASS(MyCanvas)
DECLARE_EVENT_TABLE()
}; };
// MyFrame // MyFrame
class MyFrame: public wxFrame class MyFrame: public wxFrame
{ {
DECLARE_DYNAMIC_CLASS(MyFrame) public:
MyFrame();
public:
MyFrame(void);
void OnSize( wxSizeEvent &event );
void OnAbout( wxCommandEvent &event ); void OnAbout( wxCommandEvent &event );
void OnQuit( wxCommandEvent &event ); void OnQuit( wxCommandEvent &event );
MyCanvas *m_canvas; MyCanvas *m_canvas;
DECLARE_EVENT_TABLE() DECLARE_DYNAMIC_CLASS(MyFrame)
DECLARE_EVENT_TABLE()
}; };
// MyApp // MyApp
class MyApp: public wxApp class MyApp: public wxApp
{ {
public: public:
virtual bool OnInit();
MyApp(void);
virtual bool OnInit(void);
}; };
// main program // main program
@ -80,17 +74,18 @@ IMPLEMENT_APP(MyApp)
IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow) IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow)
BEGIN_EVENT_TABLE(MyCanvas,wxScrolledWindow) BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
EVT_PAINT (MyCanvas::OnPaint) EVT_PAINT(MyCanvas::OnPaint)
END_EVENT_TABLE() END_EVENT_TABLE()
MyCanvas::MyCanvas( wxWindow *parent, const wxWindowID id, const wxPoint &pos, const wxSize &size ) MyCanvas::MyCanvas( wxWindow *parent, const wxWindowID id,
: wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER ) const wxPoint &pos, const wxSize &size )
: wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER )
{ {
SetBackgroundColour(* wxWHITE); SetBackgroundColour(* wxWHITE);
wxBitmap bitmap( 100, 100 ); wxBitmap bitmap( 100, 100 );
wxMemoryDC dc; wxMemoryDC dc;
dc.SelectObject( bitmap ); dc.SelectObject( bitmap );
dc.SetBrush( wxBrush( "orange", wxSOLID ) ); dc.SetBrush( wxBrush( "orange", wxSOLID ) );
@ -106,18 +101,18 @@ MyCanvas::MyCanvas( wxWindow *parent, const wxWindowID id, const wxPoint &pos, c
wxImage image( bitmap ); wxImage image( bitmap );
image.SaveFile( dir + wxString("test.png"), wxBITMAP_TYPE_PNG ); image.SaveFile( dir + wxString("test.png"), wxBITMAP_TYPE_PNG );
image.LoadFile( dir + wxString("horse.png"), wxBITMAP_TYPE_PNG ); image.LoadFile( dir + wxString("horse.png"), wxBITMAP_TYPE_PNG );
image.SetRGB( 0, 0, 250, 0, 0 ); image.SetRGB( 0, 0, 250, 0, 0 );
image.SetRGB( 1, 0, 100, 100, 100 ); image.SetRGB( 1, 0, 100, 100, 100 );
image.SetRGB( 2, 0, 250, 250, 250 ); image.SetRGB( 2, 0, 250, 250, 250 );
my_horse = new wxBitmap( image.ConvertToBitmap() ); my_horse = new wxBitmap( image.ConvertToBitmap() );
image.LoadFile( dir + wxString("test.png"), wxBITMAP_TYPE_PNG ); image.LoadFile( dir + wxString("test.png"), wxBITMAP_TYPE_PNG );
my_square = new wxBitmap( image.ConvertToBitmap() ); my_square = new wxBitmap( image.ConvertToBitmap() );
} }
MyCanvas::~MyCanvas(void) MyCanvas::~MyCanvas()
{ {
delete my_horse; delete my_horse;
delete my_square; delete my_square;
@ -130,12 +125,12 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
dc.DrawText( "Loaded image", 30, 100 ); dc.DrawText( "Loaded image", 30, 100 );
if (my_square->Ok()) dc.DrawBitmap( *my_square, 30, 120 ); if (my_square->Ok()) dc.DrawBitmap( *my_square, 30, 120 );
dc.DrawText( "Drawn directly", 150, 100 ); dc.DrawText( "Drawn directly", 150, 100 );
dc.SetBrush( wxBrush( "orange", wxSOLID ) ); dc.SetBrush( wxBrush( "orange", wxSOLID ) );
dc.SetPen( *wxWHITE_PEN ); dc.SetPen( *wxWHITE_PEN );
dc.DrawRectangle( 150, 120, 100, 100 ); dc.DrawRectangle( 150, 120, 100, 100 );
if (my_horse->Ok()) dc.DrawBitmap( *my_horse, 30, 240 ); if (my_horse->Ok()) dc.DrawBitmap( *my_horse, 30, 240 );
} }
@ -149,25 +144,25 @@ IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
BEGIN_EVENT_TABLE(MyFrame,wxFrame) BEGIN_EVENT_TABLE(MyFrame,wxFrame)
EVT_MENU (ID_ABOUT, MyFrame::OnAbout) EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
EVT_MENU (ID_QUIT, MyFrame::OnQuit) EVT_MENU (ID_QUIT, MyFrame::OnQuit)
EVT_SIZE (MyFrame::OnSize)
END_EVENT_TABLE() END_EVENT_TABLE()
MyFrame::MyFrame(void) : MyFrame::MyFrame()
wxFrame( (wxFrame *) NULL, -1, "wxImage sample", wxPoint(20,20), wxSize(470,360) ) : wxFrame( (wxFrame *)NULL, -1, "wxImage sample",
wxPoint(20,20), wxSize(470,360) )
{ {
wxMenu *file_menu = new wxMenu(); wxMenu *file_menu = new wxMenu();
file_menu->Append( ID_ABOUT, "About.."); file_menu->Append( ID_ABOUT, "About..");
file_menu->Append( ID_QUIT, "Exit"); file_menu->Append( ID_QUIT, "Exit");
wxMenuBar *menu_bar = new wxMenuBar(); wxMenuBar *menu_bar = new wxMenuBar();
menu_bar->Append(file_menu, "File"); menu_bar->Append(file_menu, "File");
SetMenuBar( menu_bar ); SetMenuBar( menu_bar );
CreateStatusBar(2); CreateStatusBar(2);
int widths[] = { -1, 100 }; int widths[] = { -1, 100 };
SetStatusWidths( 2, widths ); SetStatusWidths( 2, widths );
m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) ); m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) );
m_canvas->SetScrollbars( 10, 10, 50, 50 ); m_canvas->SetScrollbars( 10, 10, 50, 50 );
} }
@ -179,33 +174,22 @@ void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) ) void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
{ {
(void) wxMessageBox( "wxImage demo\nRobert Roebling (c) 1998", "About wxImage Demo", wxOK ); (void)wxMessageBox( "wxImage demo\n"
} "Robert Roebling (c) 1998",
"About wxImage Demo", wxICON_INFORMATION | wxOK );
void MyFrame::OnSize( wxSizeEvent &WXUNUSED(event) )
{
int w,h;
GetClientSize( &w, &h );
if (m_canvas)
m_canvas->SetSize( w, h );
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// MyApp // MyApp
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
MyApp::MyApp(void) : bool MyApp::OnInit()
wxApp( )
{
}
bool MyApp::OnInit(void)
{ {
wxImage::AddHandler( new wxPNGHandler ); wxImage::AddHandler( new wxPNGHandler );
wxFrame *frame = new MyFrame(); wxFrame *frame = new MyFrame();
frame->Show( TRUE ); frame->Show( TRUE );
return TRUE; return TRUE;
} }

View File

@ -97,18 +97,6 @@ bool MyApp::OnInit(void)
// Give it a status line // Give it a status line
frame->CreateStatusBar(2); 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"); wxMenuBar *menu_bar = wxResourceCreateMenuBar("menu1");
// Associate the menu bar with the frame // Associate the menu bar with the frame
@ -123,6 +111,12 @@ bool MyApp::OnInit(void)
return TRUE; return TRUE;
} }
MyApp::~MyApp()
{
delete dialog1;
delete menu1;
}
BEGIN_EVENT_TABLE(MyPanel, wxPanel) BEGIN_EVENT_TABLE(MyPanel, wxPanel)
EVT_LEFT_DOWN( MyPanel::OnClick) EVT_LEFT_DOWN( MyPanel::OnClick)
END_EVENT_TABLE() 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()); MyFrame *frame = (MyFrame*)(wxTheApp->GetTopWindow());
wxCommandEvent event; wxCommandEvent event;
frame->OnTest1( event ); frame->OnTestDialog( event );
} }
BEGIN_EVENT_TABLE(MyFrame, wxFrame) BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(RESOURCE_ABOUT, MyFrame::OnAbout)
EVT_MENU(RESOURCE_QUIT, MyFrame::OnQuit) EVT_MENU(RESOURCE_QUIT, MyFrame::OnQuit)
EVT_MENU(RESOURCE_TEST1, MyFrame::OnTest1) EVT_MENU(RESOURCE_TESTDIALOG, MyFrame::OnTestDialog)
END_EVENT_TABLE() END_EVENT_TABLE()
// Define my frame constructor // Define my frame constructor
@ -153,12 +148,19 @@ MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, c
panel = (wxWindow *) NULL; 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) ) void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) )
{ {
Close(TRUE); Close(TRUE);
} }
void MyFrame::OnTest1(wxCommandEvent& WXUNUSED(event) ) void MyFrame::OnTestDialog(wxCommandEvent& WXUNUSED(event) )
{ {
MyDialog *dialog = new MyDialog; MyDialog *dialog = new MyDialog;
if (dialog->LoadFromResource(this, "dialog1")) if (dialog->LoadFromResource(this, "dialog1"))

View File

@ -16,46 +16,55 @@
// Define a new application // Define a new application
class MyApp: public wxApp class MyApp: public wxApp
{ {
public: public:
MyApp(void) ; MyApp();
bool OnInit(void);
virtual bool OnInit();
virtual ~MyApp();
}; };
class MyPanel: public wxPanel class MyPanel: public wxPanel
{ {
public: public:
MyPanel( wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, MyPanel(wxWindow *parent, wxWindowID id, const wxPoint& pos,
int style, const wxString &name ); const wxSize& size, int style, const wxString &name);
void OnClick(wxMouseEvent &event); void OnClick(wxMouseEvent &event);
DECLARE_EVENT_TABLE() private:
DECLARE_EVENT_TABLE()
}; };
class MyFrame: public wxFrame class MyFrame: public wxFrame
{ {
public: public:
wxWindow *panel; MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title,
MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size); const wxPoint& pos, const wxSize& size);
bool OnClose(void); bool OnClose();
void OnQuit(wxCommandEvent& event); 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 class MyDialog : public wxDialog
{ {
public: public:
void OnOk(wxCommandEvent& event); void OnOk(wxCommandEvent& event);
void OnCancel(wxCommandEvent& event); void OnCancel(wxCommandEvent& event);
DECLARE_EVENT_TABLE() private:
DECLARE_EVENT_TABLE()
}; };
#define RESOURCE_QUIT 4 // the values should be the same as in menu.wxr file!
#define RESOURCE_TEST1 2 enum
{
/* RESOURCE_TESTDIALOG = 2,
#define RESOURCE_OK 1 RESOURCE_QUIT = 4,
#define RESOURCE_CANCEL 2 RESOURCE_ABOUT = 6
*/ };

View File

@ -164,7 +164,7 @@ END_EVENT_TABLE()
// Define my frame constructor // Define my frame constructor
MyFrame::MyFrame(wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos, MyFrame::MyFrame(wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos,
const wxSize& size, long style): 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); 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 MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{ {
// (void)wxMessageBox("wxWindows wxToolBar demo\n", "About wxToolBar"); (void)wxMessageBox("wxWindows toolbar sample", "About wxToolBar");
wxLogStatus("Started timer.");
m_timer.Start(500, TRUE);
} }
// Define the behaviour for the frame closing // Define the behaviour for the frame closing

View File

@ -45,9 +45,7 @@ public:
private: private:
wxTextCtrl* m_textWindow; wxTextCtrl* m_textWindow;
MyTimer m_timer; DECLARE_EVENT_TABLE()
DECLARE_EVENT_TABLE()
}; };
#define ID_TOOLBAR 500 #define ID_TOOLBAR 500