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
*
*
* 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;
}

View File

@ -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"))

View File

@ -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
};

View File

@ -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

View File

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