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