]>
Commit | Line | Data |
---|---|---|
fdd3ed7a RR |
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 ) | |
de1c750f | 80 | : wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER | wxTAB_TRAVERSAL ) |
fdd3ed7a | 81 | { |
fdd3ed7a RR |
82 | wxString choices[] = |
83 | { | |
84 | "This", | |
85 | "is one of my", | |
86 | "really", | |
87 | "wonderful", | |
88 | "examples." | |
89 | }; | |
90 | ||
eb082a08 RR |
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 ); | |
fdd3ed7a | 98 | |
de1c750f | 99 | (void) new wxRadioBox( this, -1, "This", wxPoint(10,200), wxDefaultSize, 5, choices ); |
eb082a08 RR |
100 | |
101 | SetBackgroundColour( *wxWHITE ); | |
fdd3ed7a RR |
102 | } |
103 | ||
104 | MyCanvas::~MyCanvas() | |
105 | { | |
106 | } | |
107 | ||
108 | void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) | |
109 | { | |
ba2a0103 RR |
110 | return; |
111 | ||
fdd3ed7a RR |
112 | wxPaintDC dc( this ); |
113 | PrepareDC( dc ); | |
114 | ||
115 | dc.DrawText( "Some text", 10, 10 ); | |
116 | ||
117 | dc.DrawRectangle( 50, 30, 200, 200 ); | |
118 | } | |
119 | ||
120 | // MyFrame | |
121 | ||
122 | const int ID_QUIT = 108; | |
123 | const int ID_ABOUT = 109; | |
124 | ||
125 | IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame ) | |
126 | ||
127 | BEGIN_EVENT_TABLE(MyFrame,wxFrame) | |
128 | EVT_MENU (ID_ABOUT, MyFrame::OnAbout) | |
129 | EVT_MENU (ID_QUIT, MyFrame::OnQuit) | |
130 | END_EVENT_TABLE() | |
131 | ||
132 | MyFrame::MyFrame() | |
133 | : wxFrame( (wxFrame *)NULL, -1, "wxScrolledWindow sample", | |
134 | wxPoint(20,20), wxSize(470,360) ) | |
135 | { | |
eb082a08 | 136 | /* |
fdd3ed7a RR |
137 | wxMenu *file_menu = new wxMenu(); |
138 | file_menu->Append( ID_ABOUT, "&About.."); | |
139 | file_menu->Append( ID_QUIT, "E&xit\tAlt-X"); | |
140 | ||
141 | wxMenuBar *menu_bar = new wxMenuBar(); | |
142 | menu_bar->Append(file_menu, "&File"); | |
143 | ||
144 | SetMenuBar( menu_bar ); | |
145 | ||
146 | CreateStatusBar(2); | |
147 | int widths[] = { -1, 100 }; | |
148 | SetStatusWidths( 2, widths ); | |
149 | ||
eb082a08 | 150 | */ |
fdd3ed7a RR |
151 | m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) ); |
152 | m_canvas->SetScrollbars( 10, 10, 50, 100 ); | |
153 | } | |
154 | ||
155 | void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) ) | |
156 | { | |
157 | Close( TRUE ); | |
158 | } | |
159 | ||
160 | void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) ) | |
161 | { | |
162 | (void)wxMessageBox( "wxScroll demo\n" | |
163 | "Robert Roebling (c) 1998", | |
164 | "About wxScroll Demo", wxICON_INFORMATION | wxOK ); | |
165 | } | |
166 | ||
167 | //----------------------------------------------------------------------------- | |
168 | // MyApp | |
169 | //----------------------------------------------------------------------------- | |
170 | ||
171 | bool MyApp::OnInit() | |
172 | { | |
173 | wxFrame *frame = new MyFrame(); | |
174 | frame->Show( TRUE ); | |
175 | ||
176 | return TRUE; | |
177 | } | |
178 |