a bit of debug code
[wxWidgets.git] / samples / scroll / scroll.cpp
1 /*
2 * Program: scroll
3 *
4 * Author: Robert Roebling
5 *
6 * Copyright: (C) 1998, Robert Roebling
7 *
8 */
9
10 // For compilers that support precompilation, includes "wx/wx.h".
11 #include "wx/wxprec.h"
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16
17 #ifndef WX_PRECOMP
18 #include "wx/wx.h"
19 #endif
20
21 #include "wx/image.h"
22
23 // derived classes
24
25 class MyFrame;
26 class MyApp;
27
28 // MyCanvas
29
30 class MyCanvas: public wxScrolledWindow
31 {
32 public:
33 MyCanvas() {};
34 MyCanvas( wxWindow *parent, wxWindowID, const wxPoint &pos, const wxSize &size );
35 ~MyCanvas();
36 void OnPaint( wxPaintEvent &event );
37
38 DECLARE_DYNAMIC_CLASS(MyCanvas)
39 DECLARE_EVENT_TABLE()
40 };
41
42 // MyFrame
43
44 class MyFrame: public wxFrame
45 {
46 public:
47 MyFrame();
48
49 void OnAbout( wxCommandEvent &event );
50 void OnQuit( wxCommandEvent &event );
51
52 MyCanvas *m_canvas;
53
54 DECLARE_DYNAMIC_CLASS(MyFrame)
55 DECLARE_EVENT_TABLE()
56 };
57
58 // MyApp
59
60 class MyApp: public wxApp
61 {
62 public:
63 virtual bool OnInit();
64 };
65
66 // main program
67
68 IMPLEMENT_APP(MyApp)
69
70 // MyCanvas
71
72 IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow)
73
74 BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
75 EVT_PAINT(MyCanvas::OnPaint)
76 END_EVENT_TABLE()
77
78 MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
79 const wxPoint &pos, const wxSize &size )
80 : wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER )
81 {
82
83 // (void) new wxButton( this, -1, "wxButton", wxPoint(10,10) );
84
85 // (void) new wxTextCtrl( this, -1, "wxTextCtrl", wxPoint(10,50) );
86
87 (void) new wxRadioButton( this, -1, "Disable", wxPoint(10,90) );
88
89 wxString choices[] =
90 {
91 "This",
92 "is one of my",
93 "really",
94 "wonderful",
95 "examples."
96 };
97
98 // (void) new wxComboBox( this, -1, "This", wxPoint(10,130), wxDefaultSize, 5, choices );
99
100 // (void) new wxRadioBox( this, -1, "This", wxPoint(10,200), wxDefaultSize, 5, choices );
101 }
102
103 MyCanvas::~MyCanvas()
104 {
105 }
106
107 void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
108 {
109 return;
110
111 wxPaintDC dc( this );
112 PrepareDC( dc );
113
114 dc.DrawText( "Some text", 10, 10 );
115
116 dc.DrawRectangle( 50, 30, 200, 200 );
117 }
118
119 // MyFrame
120
121 const int ID_QUIT = 108;
122 const int ID_ABOUT = 109;
123
124 IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
125
126 BEGIN_EVENT_TABLE(MyFrame,wxFrame)
127 EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
128 EVT_MENU (ID_QUIT, MyFrame::OnQuit)
129 END_EVENT_TABLE()
130
131 MyFrame::MyFrame()
132 : wxFrame( (wxFrame *)NULL, -1, "wxScrolledWindow sample",
133 wxPoint(20,20), wxSize(470,360) )
134 {
135 wxMenu *file_menu = new wxMenu();
136 file_menu->Append( ID_ABOUT, "&About..");
137 file_menu->Append( ID_QUIT, "E&xit\tAlt-X");
138
139 wxMenuBar *menu_bar = new wxMenuBar();
140 menu_bar->Append(file_menu, "&File");
141
142 SetMenuBar( menu_bar );
143
144 CreateStatusBar(2);
145 int widths[] = { -1, 100 };
146 SetStatusWidths( 2, widths );
147
148 m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) );
149 m_canvas->SetScrollbars( 10, 10, 50, 100 );
150 }
151
152 void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
153 {
154 Close( TRUE );
155 }
156
157 void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
158 {
159 (void)wxMessageBox( "wxScroll demo\n"
160 "Robert Roebling (c) 1998",
161 "About wxScroll Demo", wxICON_INFORMATION | wxOK );
162 }
163
164 //-----------------------------------------------------------------------------
165 // MyApp
166 //-----------------------------------------------------------------------------
167
168 bool MyApp::OnInit()
169 {
170 wxFrame *frame = new MyFrame();
171 frame->Show( TRUE );
172
173 return TRUE;
174 }
175