]>
Commit | Line | Data |
---|---|---|
ecab4dba RR |
1 | /* |
2 | * Program: scrollsub | |
3 | * | |
4 | * Author: Robert Roebling | |
5 | * | |
6 | * Copyright: (C) 1999, 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 | #include "wx/listctrl.h" | |
23 | #include "wx/sizer.h" | |
24 | #include "wx/log.h" | |
25 | ||
26 | ||
27 | // derived classes | |
28 | ||
29 | class MyFrame; | |
30 | class MyScrolledWindow; | |
31 | class MyCanvas; | |
32 | class MyApp; | |
33 | ||
34 | // MyScrolledWindow | |
35 | ||
36 | class MyScrolledWindow: public wxScrolledWindow | |
37 | { | |
38 | public: | |
39 | MyScrolledWindow() {} | |
40 | MyScrolledWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size ); | |
41 | ~MyScrolledWindow(); | |
42 | void OnPaint( wxPaintEvent &event ); | |
43 | ||
44 | private: | |
45 | MyCanvas *m_canvas; | |
46 | ||
47 | DECLARE_DYNAMIC_CLASS(MyScrolledWindow) | |
48 | DECLARE_EVENT_TABLE() | |
49 | }; | |
50 | ||
51 | // MyCanvas | |
52 | ||
53 | class MyCanvas: public wxPanel | |
54 | { | |
55 | public: | |
56 | MyCanvas() {} | |
57 | MyCanvas( wxScrolledWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size ); | |
58 | ~MyCanvas(); | |
59 | void OnPaint( wxPaintEvent &event ); | |
60 | ||
61 | private: | |
62 | wxScrolledWindow *m_owner; | |
63 | ||
64 | DECLARE_DYNAMIC_CLASS(MyCanvas) | |
65 | DECLARE_EVENT_TABLE() | |
66 | }; | |
67 | ||
68 | // MyFrame | |
69 | ||
70 | class MyFrame: public wxFrame | |
71 | { | |
72 | public: | |
73 | MyFrame(); | |
74 | ||
75 | void OnAbout( wxCommandEvent &event ); | |
76 | void OnQuit( wxCommandEvent &event ); | |
77 | ||
78 | wxScrolledWindow *m_scrolled; | |
79 | wxTextCtrl *m_log; | |
80 | ||
81 | private: | |
82 | DECLARE_DYNAMIC_CLASS(MyFrame) | |
83 | DECLARE_EVENT_TABLE() | |
84 | }; | |
85 | ||
86 | // MyApp | |
87 | ||
88 | class MyApp: public wxApp | |
89 | { | |
90 | public: | |
91 | virtual bool OnInit(); | |
92 | }; | |
93 | ||
94 | // main program | |
95 | ||
96 | IMPLEMENT_APP(MyApp) | |
97 | ||
98 | // MyScrolledWindow | |
99 | ||
100 | IMPLEMENT_DYNAMIC_CLASS(MyScrolledWindow, wxScrolledWindow) | |
101 | ||
102 | BEGIN_EVENT_TABLE(MyScrolledWindow, wxScrolledWindow) | |
103 | EVT_PAINT( MyScrolledWindow::OnPaint) | |
104 | END_EVENT_TABLE() | |
105 | ||
106 | MyScrolledWindow::MyScrolledWindow( wxWindow *parent, wxWindowID id, | |
107 | const wxPoint &pos, const wxSize &size ) | |
108 | : wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER, "test canvas" ) | |
109 | { | |
110 | m_canvas = new MyCanvas( this, -1, wxDefaultPosition, wxDefaultSize ); | |
111 | ||
112 | SetTargetWindow( m_canvas ); | |
113 | ||
114 | SetBackgroundColour( "WHEAT" ); | |
115 | ||
116 | SetCursor( wxCursor( wxCURSOR_HAND ) ); | |
117 | ||
118 | ||
119 | wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL ); | |
120 | ||
121 | topsizer->Add( m_canvas, 1, wxEXPAND|wxALL, 30 ); | |
122 | ||
123 | SetAutoLayout( TRUE ); | |
124 | SetSizer( topsizer ); | |
125 | } | |
126 | ||
127 | MyScrolledWindow::~MyScrolledWindow() | |
128 | { | |
129 | } | |
130 | ||
131 | void MyScrolledWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) | |
132 | { | |
133 | wxPaintDC dc( this ); | |
134 | ||
135 | wxSize size( GetClientSize() ); | |
136 | ||
137 | long w,h; | |
138 | dc.GetTextExtent( wxT("Headline"), &w, &h ); | |
139 | ||
140 | dc.DrawText( wxT("Headline"), long (size.x / 2 - w / 2), 10 ); | |
141 | } | |
142 | ||
143 | // MyCanvas | |
144 | ||
145 | IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxPanel) | |
146 | ||
147 | BEGIN_EVENT_TABLE(MyCanvas, wxPanel) | |
148 | EVT_PAINT( MyCanvas::OnPaint) | |
149 | END_EVENT_TABLE() | |
150 | ||
151 | MyCanvas::MyCanvas( wxScrolledWindow *parent, wxWindowID id, | |
152 | const wxPoint &pos, const wxSize &size ) | |
153 | : wxPanel( parent, id, pos, size, wxSUNKEN_BORDER, "test canvas" ) | |
154 | { | |
155 | m_owner = parent; | |
156 | ||
157 | (void)new wxButton( this, -1, "Hallo I", wxPoint(20,20), wxSize(100,30) ); | |
158 | (void)new wxButton( this, -1, "Hallo II", wxPoint(220,20), wxSize(100,30) ); | |
159 | ||
160 | SetBackgroundColour( *wxWHITE ); | |
161 | ||
162 | SetCursor( wxCursor( wxCURSOR_IBEAM ) ); | |
163 | } | |
164 | ||
165 | MyCanvas::~MyCanvas() | |
166 | { | |
167 | } | |
168 | ||
169 | void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) | |
170 | { | |
171 | wxPaintDC dc( this ); | |
172 | m_owner->PrepareDC( dc ); | |
173 | ||
76db86e7 RR |
174 | dc.SetPen( *wxBLACK_PEN ); |
175 | ||
ecab4dba | 176 | dc.DrawText( "Some text", 140, 140 ); |
76db86e7 | 177 | |
ecab4dba RR |
178 | dc.DrawRectangle( 100, 160, 200, 200 ); |
179 | ||
180 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
181 | ||
182 | dc.DrawRectangle( 10, 10, 480, 980 ); | |
183 | } | |
184 | ||
185 | ||
186 | // MyFrame | |
187 | ||
188 | const int ID_QUIT = 108; | |
189 | const int ID_ABOUT = 109; | |
190 | ||
191 | IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame ) | |
192 | ||
193 | BEGIN_EVENT_TABLE(MyFrame,wxFrame) | |
194 | EVT_MENU (ID_ABOUT, MyFrame::OnAbout) | |
195 | EVT_MENU (ID_QUIT, MyFrame::OnQuit) | |
196 | END_EVENT_TABLE() | |
197 | ||
198 | MyFrame::MyFrame() | |
199 | : wxFrame( (wxFrame *)NULL, -1, "wxScrolledWindow sample", | |
200 | wxPoint(20,20), wxSize(470,500) ) | |
201 | { | |
202 | wxMenu *file_menu = new wxMenu(); | |
203 | file_menu->Append( ID_ABOUT, "&About.."); | |
204 | file_menu->Append( ID_QUIT, "E&xit\tAlt-X"); | |
205 | ||
206 | wxMenuBar *menu_bar = new wxMenuBar(); | |
207 | menu_bar->Append(file_menu, "&File"); | |
208 | ||
209 | SetMenuBar( menu_bar ); | |
210 | ||
211 | CreateStatusBar(2); | |
212 | int widths[] = { -1, 100 }; | |
213 | SetStatusWidths( 2, widths ); | |
214 | ||
215 | m_scrolled = new MyScrolledWindow( this, -1, wxPoint(0,0), wxSize(100,100) ); | |
216 | m_scrolled->SetScrollbars( 10, 10, 50, 100 ); | |
217 | ||
218 | m_log = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE ); | |
219 | wxLog *old_log = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) ); | |
220 | delete old_log; | |
221 | ||
222 | wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL ); | |
223 | ||
224 | topsizer->Add( m_scrolled, 1, wxEXPAND ); | |
225 | topsizer->Add( m_log, 0, wxEXPAND ); | |
226 | ||
227 | SetAutoLayout( TRUE ); | |
228 | SetSizer( topsizer ); | |
229 | } | |
230 | ||
231 | void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) ) | |
232 | { | |
233 | Close( TRUE ); | |
234 | } | |
235 | ||
236 | void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) ) | |
237 | { | |
238 | (void)wxMessageBox( "wxScroll demo II\n" | |
239 | "Robert Roebling (c) 1998", | |
240 | "About wxScroll II Demo", wxICON_INFORMATION | wxOK ); | |
241 | } | |
242 | ||
243 | //----------------------------------------------------------------------------- | |
244 | // MyApp | |
245 | //----------------------------------------------------------------------------- | |
246 | ||
247 | bool MyApp::OnInit() | |
248 | { | |
249 | wxFrame *frame = new MyFrame(); | |
250 | frame->Show( TRUE ); | |
251 | ||
252 | return TRUE; | |
253 | } | |
254 |