corrected MSW-specific bug (in the sample, not the scrolling 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 | wxTAB_TRAVERSAL )
81 {
82 wxString choices[] =
83 {
84 "This",
85 "is one of my",
86 "really",
87 "wonderful",
88 "examples."
89 };
90
91 (void) new wxButton( this, -1, "wxButton", wxPoint(10,10) );
92
93 (void) new wxTextCtrl( this, -1, "wxTextCtrl", wxPoint(10,50) );
94
95 (void) new wxRadioButton( this, -1, "Disable", wxPoint(10,90) );
96
97 (void) new wxComboBox( this, -1, "This", wxPoint(10,130), wxDefaultSize, 5, choices );
98
99 (void) new wxRadioBox( this, -1, "This", wxPoint(10,200), wxDefaultSize, 5, choices );
100
101 SetBackgroundColour( *wxWHITE );
102 }
103
104 MyCanvas::~MyCanvas()
105 {
106 }
107
108 void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
109 {
110 wxPaintDC dc( this );
111 PrepareDC( dc );
112
113 dc.DrawText( "Some text", 110, 10 );
114
115 dc.DrawRectangle( 50, 30, 200, 200 );
116 }
117
118 // MyFrame
119
120 const int ID_QUIT = 108;
121 const int ID_ABOUT = 109;
122
123 IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
124
125 BEGIN_EVENT_TABLE(MyFrame,wxFrame)
126 EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
127 EVT_MENU (ID_QUIT, MyFrame::OnQuit)
128 END_EVENT_TABLE()
129
130 MyFrame::MyFrame()
131 : wxFrame( (wxFrame *)NULL, -1, "wxScrolledWindow sample",
132 wxPoint(20,20), wxSize(470,360) )
133 {
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 */
149 m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) );
150 m_canvas->SetScrollbars( 10, 10, 50, 100 );
151 }
152
153 void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
154 {
155 Close( TRUE );
156 }
157
158 void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
159 {
160 (void)wxMessageBox( "wxScroll demo\n"
161 "Robert Roebling (c) 1998",
162 "About wxScroll Demo", wxICON_INFORMATION | wxOK );
163 }
164
165 //-----------------------------------------------------------------------------
166 // MyApp
167 //-----------------------------------------------------------------------------
168
169 bool MyApp::OnInit()
170 {
171 wxFrame *frame = new MyFrame();
172 frame->Show( TRUE );
173
174 return TRUE;
175 }
176