]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/canvas/test/test.cpp
Added wxCanvasControl before anyone else would do
[wxWidgets.git] / contrib / samples / canvas / test / test.cpp
1 /*
2 * Program: canvas
3 *
4 * Author: Robert Roebling
5 *
6 * Copyright: (C) 1998, Robert Roebling
7 *
8 */
9 // For compilers that support precompilation, includes "wx/wx.h".
10 #include "wx/wxprec.h"
11
12 #ifdef __BORLANDC__
13 #pragma hdrstop
14 #endif
15
16 #ifndef WX_PRECOMP
17 #include "wx/wx.h"
18 #endif
19
20 #include <wx/image.h>
21 #include <wx/file.h>
22 #include <wx/timer.h>
23
24 #include "smile.xpm"
25
26 #include "wx/canvas/canvas.h"
27
28 // derived classes
29
30 class MyFrame;
31 class MyApp;
32
33 // MyFrame
34
35 class MyFrame: public wxFrame
36 {
37 public:
38 MyFrame();
39 ~MyFrame();
40
41 void OnAbout( wxCommandEvent &event );
42 void OnNewFrame( wxCommandEvent &event );
43 void OnQuit( wxCommandEvent &event );
44 void OnTimer( wxTimerEvent &event );
45
46 wxCanvas *m_canvas;
47 wxCanvasObject *m_co;
48 wxTimer *m_timer;
49
50 private:
51 DECLARE_DYNAMIC_CLASS(MyFrame)
52 DECLARE_EVENT_TABLE()
53 };
54
55 // MyApp
56
57 class MyApp: public wxApp
58 {
59 public:
60 virtual bool OnInit();
61 };
62
63 // main program
64
65 IMPLEMENT_APP(MyApp)
66
67 // MyFrame
68
69 const int ID_QUIT = 108;
70 const int ID_ABOUT = 109;
71
72 IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
73
74 BEGIN_EVENT_TABLE(MyFrame,wxFrame)
75 EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
76 EVT_MENU (ID_QUIT, MyFrame::OnQuit)
77 EVT_TIMER (-1, MyFrame::OnTimer)
78 END_EVENT_TABLE()
79
80 MyFrame::MyFrame()
81 : wxFrame( (wxFrame *)NULL, -1, "wxCanvas sample",
82 wxPoint(20,20), wxSize(470,360) )
83 {
84 wxMenu *file_menu = new wxMenu();
85 file_menu->Append( ID_ABOUT, "&About...");
86 file_menu->AppendSeparator();
87 file_menu->Append( ID_QUIT, "E&xit");
88
89 wxMenuBar *menu_bar = new wxMenuBar();
90 menu_bar->Append(file_menu, "&File");
91
92 SetMenuBar( menu_bar );
93
94 CreateStatusBar(2);
95 int widths[] = { -1, 100 };
96 SetStatusWidths( 2, widths );
97
98 m_canvas = new wxCanvas( this, -1, wxPoint(0,0), wxSize(10,10) );
99
100 m_canvas->SetArea( 400, 600 );
101
102 wxBitmap bitmap( smile_xpm );
103 wxImage image( bitmap );
104 m_co = new wxCanvasImage( image, 10, 50 );
105 m_canvas->Append( m_co );
106
107 m_canvas->Append( new wxCanvasImage( image, 80, 50 ) );
108
109 wxButton *button = new wxButton( m_canvas, -1, "Hello", wxPoint(130,50) );
110 m_canvas->Append( new wxCanvasControl( button ) );
111
112 m_timer = new wxTimer( this );
113 m_timer->Start( 150, FALSE );
114 }
115
116 MyFrame::~MyFrame()
117 {
118 delete m_timer;
119 }
120
121 void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
122 {
123 Close( TRUE );
124 }
125
126 void MyFrame::OnTimer( wxTimerEvent &WXUNUSED(event) )
127 {
128 m_co->Move( m_co->GetX()+1, m_co->GetY() );
129 wxWakeUpIdle();
130 }
131
132 void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
133 {
134 (void)wxMessageBox( "wxCanvas demo\n"
135 "Robert Roebling (c) 1998,2000",
136 "About wxCanvas Demo", wxICON_INFORMATION | wxOK );
137 }
138
139 //-----------------------------------------------------------------------------
140 // MyApp
141 //-----------------------------------------------------------------------------
142
143 bool MyApp::OnInit()
144 {
145 #if wxUSE_LIBPNG
146 wxImage::AddHandler( new wxPNGHandler );
147 #endif
148
149 wxFrame *frame = new MyFrame();
150 frame->Show( TRUE );
151
152 return TRUE;
153 }
154
155