]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | /* |
2 | * Program: wxTest | |
3 | * | |
4 | * Author: Robert Roebling | |
5 | * | |
6 | * Copyright: (C) 1997, GNU (Robert Roebling) | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | */ | |
22 | ||
23 | #ifdef __GNUG__ | |
24 | #pragma implementation "wxTest.h" | |
25 | #endif | |
26 | ||
27 | #include "wxTest.h" | |
28 | ||
29 | #include "folder.xpm" | |
30 | #include "list.xpm" | |
31 | ||
32 | //----------------------------------------------------------------------------- | |
33 | // main program | |
34 | //----------------------------------------------------------------------------- | |
35 | ||
36 | IMPLEMENT_APP(MyApp) | |
37 | ||
38 | //----------------------------------------------------------------------------- | |
39 | // MyDialog | |
40 | //----------------------------------------------------------------------------- | |
41 | ||
42 | const ID_RETURN = 100; | |
43 | const ID_HELLO = 101; | |
44 | ||
45 | const ID_CHECKBOX = 110; | |
46 | const ID_CHECKBOX_CHECK = 110; | |
47 | const ID_CHECKBOX_UNCHECK = 112; | |
48 | ||
49 | const ID_TEXTCTRL = 115; | |
50 | const ID_TEXTCTRL_SET = 116; | |
51 | const ID_TEXTCTRL_DEL = 117; | |
52 | ||
53 | const ID_CHOICE = 120; | |
54 | const ID_CHOICE_SEL_NUM = 121; | |
55 | const ID_CHOICE_SEL_STR = 122; | |
56 | const ID_CHOICE_CLEAR = 123; | |
57 | const ID_CHOICE_APPEND = 124; | |
58 | ||
59 | const ID_LISTBOX = 130; | |
60 | const ID_LISTBOX_SEL_NUM = 131; | |
61 | const ID_LISTBOX_SEL_STR = 132; | |
62 | const ID_LISTBOX_CLEAR = 133; | |
63 | const ID_LISTBOX_APPEND = 134; | |
64 | ||
65 | const ID_RADIOBOX = 130; | |
66 | const ID_RADIOBOX_SEL_NUM = 131; | |
67 | const ID_RADIOBOX_SEL_STR = 132; | |
68 | ||
69 | BEGIN_EVENT_TABLE(MyDialog,wxDialog) | |
70 | EVT_BUTTON (ID_RETURN, MyDialog::OnReturnButton) | |
71 | EVT_BUTTON (ID_HELLO, MyDialog::OnHelloButton) | |
72 | EVT_CHECKBOX (ID_CHECKBOX, MyDialog::OnCheckBox) | |
73 | EVT_BUTTON (ID_CHECKBOX_CHECK, MyDialog::OnCheckBoxButtons) | |
74 | EVT_BUTTON (ID_CHECKBOX_UNCHECK, MyDialog::OnCheckBoxButtons) | |
75 | EVT_TEXT (ID_TEXTCTRL, MyDialog::OnTextCtrl) | |
76 | EVT_BUTTON (ID_TEXTCTRL_SET, MyDialog::OnTextCtrlButtons) | |
77 | EVT_BUTTON (ID_TEXTCTRL_DEL, MyDialog::OnTextCtrlButtons) | |
78 | EVT_CHOICE (ID_CHOICE, MyDialog::OnChoice) | |
79 | EVT_BUTTON (ID_CHOICE_SEL_NUM, MyDialog::OnChoiceButtons) | |
80 | EVT_BUTTON (ID_CHOICE_SEL_STR, MyDialog::OnChoiceButtons) | |
81 | EVT_BUTTON (ID_CHOICE_CLEAR, MyDialog::OnChoiceButtons) | |
82 | EVT_BUTTON (ID_CHOICE_APPEND, MyDialog::OnChoiceButtons) | |
83 | EVT_LISTBOX (ID_LISTBOX, MyDialog::OnListBox) | |
84 | EVT_BUTTON (ID_LISTBOX_SEL_NUM, MyDialog::OnListBoxButtons) | |
85 | EVT_BUTTON (ID_LISTBOX_SEL_STR, MyDialog::OnListBoxButtons) | |
86 | EVT_BUTTON (ID_LISTBOX_CLEAR, MyDialog::OnListBoxButtons) | |
87 | EVT_BUTTON (ID_LISTBOX_APPEND, MyDialog::OnListBoxButtons) | |
88 | EVT_RADIOBOX (ID_RADIOBOX, MyDialog::OnRadioBox) | |
89 | EVT_BUTTON (ID_RADIOBOX_SEL_NUM, MyDialog::OnRadioBoxButtons) | |
90 | EVT_BUTTON (ID_RADIOBOX_SEL_STR, MyDialog::OnRadioBoxButtons) | |
91 | END_EVENT_TABLE() | |
92 | ||
93 | //----------------------------------------------------------------------------- | |
94 | ||
95 | IMPLEMENT_DYNAMIC_CLASS(MyDialog, wxDialog) | |
96 | ||
97 | MyDialog::MyDialog( wxWindow *parent ) : | |
98 | wxDialog( parent, -1, "TestDialog", wxPoint(20,100), wxSize(700,400), wxDIALOG_MODAL ) | |
99 | { | |
100 | m_text1 = NULL; | |
101 | m_text2 = NULL; | |
102 | ||
103 | (void)new wxStaticBox( this, -1, "CheckBox group", wxPoint(20,10), wxSize(140,180) ); | |
104 | m_checkbox = new wxCheckBox( this, ID_CHECKBOX, "CheckBox", wxPoint(40,35), wxSize(100,30) ); | |
105 | (void)new wxButton( this, ID_CHECKBOX_CHECK, "Check", wxPoint(40,85), wxSize(100,30) ); | |
106 | (void)new wxButton( this, ID_CHECKBOX_UNCHECK, "Uncheck", wxPoint(40,135), wxSize(100,30) ); | |
107 | ||
108 | (void)new wxStaticBox( this, -1, "TextCtrl group", wxPoint(20,200), wxSize(140,180) ); | |
109 | m_textctrl = new wxTextCtrl( this, ID_TEXTCTRL, "TextCtrl", wxPoint(40,35+190), wxSize(100,30) ); | |
110 | (void)new wxButton( this, ID_TEXTCTRL_SET, "Set 'Hi!'", wxPoint(40,85+190), wxSize(100,30) ); | |
111 | (void)new wxButton( this, ID_TEXTCTRL_DEL, "Delete", wxPoint(40,135+190), wxSize(100,30) ); | |
112 | ||
113 | wxString choices[4] = | |
114 | { | |
115 | "This", | |
116 | "is", | |
117 | "a", | |
118 | "wonderfull example." | |
119 | }; | |
120 | ||
121 | (void)new wxStaticBox( this, -1, "Choice group", wxPoint(180,10), wxSize(140,330) ); | |
122 | m_choice = new wxChoice( this, ID_CHOICE, wxPoint(200,35), wxSize(100,30), 4, choices ); | |
123 | (void)new wxButton( this, ID_CHOICE_SEL_NUM, "Select #2", wxPoint(200,130), wxSize(100,30) ); | |
124 | (void)new wxButton( this, ID_CHOICE_SEL_STR, "Select 'This'", wxPoint(200,180), wxSize(100,30) ); | |
125 | (void)new wxButton( this, ID_CHOICE_CLEAR, "Clear", wxPoint(200,230), wxSize(100,30) ); | |
126 | (void)new wxButton( this, ID_CHOICE_APPEND, "Append 'Hi!'", wxPoint(200,280), wxSize(100,30) ); | |
127 | ||
128 | (void)new wxStaticBox( this, 100, "ListBox group", wxPoint(340,10), wxSize(140,330) ); | |
129 | m_listbox = new wxListBox( this, ID_LISTBOX, wxPoint(360,35), wxSize(100,70), 4, choices ); | |
130 | (void)new wxButton( this, ID_LISTBOX_SEL_NUM, "Select #2", wxPoint(360,130), wxSize(100,30) ); | |
131 | (void)new wxButton( this, ID_LISTBOX_SEL_STR, "Select 'This'", wxPoint(360,180), wxSize(100,30) ); | |
132 | (void)new wxButton( this, ID_LISTBOX_CLEAR, "Clear", wxPoint(360,230), wxSize(100,30) ); | |
133 | (void)new wxButton( this, ID_LISTBOX_APPEND, "Append 'Hi!'", wxPoint(360,280), wxSize(100,30) ); | |
134 | ||
135 | (void)new wxStaticBox( this, -1, "RadioBox group", wxPoint(500,10), wxSize(180,230) ); | |
136 | m_radiobox = new wxRadioBox( this, ID_RADIOBOX, "Test", wxPoint(520,35), wxSize(-1,-1), 4, choices, | |
137 | 1, wxRA_VERTICAL ); | |
138 | ||
139 | (void)new wxButton( this, ID_HELLO, "wxScreenDC", wxPoint(540,280), wxSize(120,40) ); | |
140 | (void)new wxButton( this, ID_RETURN, "Return", wxPoint(540,340), wxSize(120,40) ); | |
141 | ||
142 | m_text1 = new wxStaticText( this, -1, "No event.", wxPoint(170,350), wxSize(300,-1) ); | |
143 | m_text2 = new wxStaticText( this, -1, "No information.", wxPoint(170,370), wxSize(300,-1) ); | |
144 | ||
145 | InitDialog(); | |
146 | }; | |
147 | ||
148 | void MyDialog::OnTextCtrl( wxCommandEvent &WXUNUSED(event) ) | |
149 | { | |
150 | }; | |
151 | ||
152 | void MyDialog::OnTextCtrlButtons( wxCommandEvent &event ) | |
153 | { | |
154 | switch (event.GetId()) | |
155 | { | |
156 | case ID_TEXTCTRL_SET: | |
157 | { | |
158 | m_textctrl->SetValue( "Hi!" ); | |
159 | break; | |
160 | }; | |
161 | case ID_TEXTCTRL_DEL: | |
162 | { | |
163 | m_textctrl->Delete(); | |
164 | break; | |
165 | }; | |
166 | }; | |
167 | }; | |
168 | ||
169 | void MyDialog::OnRadioBox( wxCommandEvent &event ) | |
170 | { | |
171 | if (!m_text1) return; | |
172 | m_text1->SetLabel( "RadioBox Event:"); | |
173 | wxString tmp = "RadioBox selection string is: "; | |
174 | tmp += event.GetString(); | |
175 | m_text2->SetLabel( tmp ); | |
176 | }; | |
177 | ||
178 | void MyDialog::OnRadioBoxButtons( wxCommandEvent &WXUNUSED(event) ) | |
179 | { | |
180 | }; | |
181 | ||
182 | void MyDialog::OnListBox( wxCommandEvent &event ) | |
183 | { | |
184 | if (!m_text1) return; | |
185 | m_text1->SetLabel( "ListBox Event:"); | |
186 | wxString tmp = "ListBox selection string is: "; | |
187 | tmp += event.GetString(); | |
188 | m_text2->SetLabel( tmp ); | |
189 | }; | |
190 | ||
191 | void MyDialog::OnListBoxButtons( wxCommandEvent &event ) | |
192 | { | |
193 | switch (event.GetId()) | |
194 | { | |
195 | case ID_LISTBOX_SEL_NUM: | |
196 | { | |
197 | m_listbox->SetSelection( 2 ); | |
198 | break; | |
199 | }; | |
200 | case ID_LISTBOX_SEL_STR: | |
201 | { | |
202 | m_listbox->SetStringSelection( "This" ); | |
203 | break; | |
204 | }; | |
205 | case ID_LISTBOX_CLEAR: | |
206 | { | |
207 | m_listbox->Clear(); | |
208 | break; | |
209 | }; | |
210 | case ID_LISTBOX_APPEND: | |
211 | { | |
212 | m_listbox->Append( "Hi!" ); | |
213 | break; | |
214 | }; | |
215 | }; | |
216 | }; | |
217 | ||
218 | void MyDialog::OnCheckBox( wxCommandEvent &event ) | |
219 | { | |
220 | if (!m_text1) return; | |
221 | m_text1->SetLabel( "CheckBox Event:"); | |
222 | wxString tmp = "Checkbox is "; | |
223 | if (event.Checked()) | |
224 | tmp += "checked."; | |
225 | else | |
226 | tmp += "unchecked."; | |
227 | m_text2->SetLabel( tmp ); | |
228 | }; | |
229 | ||
230 | void MyDialog::OnCheckBoxButtons( wxCommandEvent &event ) | |
231 | { | |
232 | switch (event.GetId()) | |
233 | { | |
234 | case ID_CHECKBOX_CHECK: | |
235 | { | |
236 | m_checkbox->SetValue( TRUE ); | |
237 | break; | |
238 | }; | |
239 | case ID_CHECKBOX_UNCHECK: | |
240 | { | |
241 | m_checkbox->SetValue( FALSE ); | |
242 | break; | |
243 | }; | |
244 | }; | |
245 | }; | |
246 | ||
247 | void MyDialog::OnChoice( wxCommandEvent &event ) | |
248 | { | |
249 | if (!m_text1) return; | |
250 | m_text1->SetLabel( "Choice Event:"); | |
251 | wxString tmp = "Choice selection string is: "; | |
252 | tmp += event.GetString(); | |
253 | m_text2->SetLabel( tmp ); | |
254 | }; | |
255 | ||
256 | void MyDialog::OnChoiceButtons( wxCommandEvent &event ) | |
257 | { | |
258 | switch (event.GetId()) | |
259 | { | |
260 | case ID_CHOICE_SEL_NUM: | |
261 | { | |
262 | m_choice->SetSelection( 2 ); | |
263 | break; | |
264 | }; | |
265 | case ID_CHOICE_SEL_STR: | |
266 | { | |
267 | m_choice->SetStringSelection( "This" ); | |
268 | break; | |
269 | }; | |
270 | case ID_CHOICE_CLEAR: | |
271 | { | |
272 | m_choice->Clear(); | |
273 | break; | |
274 | }; | |
275 | case ID_CHOICE_APPEND: | |
276 | { | |
277 | m_choice->Append( "Hi!" ); | |
278 | break; | |
279 | }; | |
280 | }; | |
281 | }; | |
282 | ||
283 | void MyDialog::OnReturnButton( wxCommandEvent &WXUNUSED(event) ) | |
284 | { | |
285 | EndModal( 1 ); | |
286 | }; | |
287 | ||
288 | void MyDialog::OnHelloButton( wxCommandEvent &WXUNUSED(event) ) | |
289 | { | |
290 | wxMessageDialog *dialog; | |
291 | dialog = new wxMessageDialog( this, "Now, I will paint on Screen.", "wxGTK" ); | |
292 | dialog->ShowModal(); | |
293 | delete dialog; | |
294 | ||
295 | wxScreenDC dc; | |
296 | dc.StartDrawingOnTop(); | |
297 | ||
298 | int w = wxSystemSettings::GetSystemMetric( wxSYS_SCREEN_X ); | |
299 | int h = wxSystemSettings::GetSystemMetric( wxSYS_SCREEN_Y ); | |
300 | ||
301 | dc.SetPen( *wxWHITE_PEN ); | |
302 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
303 | for (int i = 0; i < h; i += 3) dc.DrawLine( 0, i, w, i ); | |
304 | ||
305 | dialog = new wxMessageDialog( this, "Now, the stripes will disappear.", "wxGTK" ); | |
306 | dialog->ShowModal(); | |
307 | delete dialog; | |
308 | ||
309 | dc.EndDrawingOnTop(); | |
310 | }; | |
311 | ||
312 | //----------------------------------------------------------------------------- | |
313 | // MyCanvas | |
314 | //----------------------------------------------------------------------------- | |
315 | ||
316 | IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow) | |
317 | ||
318 | BEGIN_EVENT_TABLE(MyCanvas,wxScrolledWindow) | |
319 | EVT_BUTTON (100, MyDialog::OnReturnButton) | |
320 | EVT_PAINT (MyCanvas::OnPaint) | |
321 | END_EVENT_TABLE() | |
322 | ||
323 | MyCanvas::MyCanvas( wxWindow *parent, const wxWindowID id, const wxPoint &pos, const wxSize &size ) | |
324 | : wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER ) | |
325 | { | |
326 | my_bitmap = new wxBitmap( folder_xpm ); | |
327 | my_horse = new wxBitmap(); | |
328 | my_horse->LoadFile( "horse.png", 0 ); | |
329 | my_backstore = new wxBitmap( 150, 150 ); | |
330 | my_font = new wxFont( 20, wxROMAN, wxNORMAL, wxNORMAL ); | |
331 | m_isCreated = FALSE; | |
332 | ||
333 | SetBackgroundColour( wxColour("Wheat") ); | |
334 | }; | |
335 | ||
336 | MyCanvas::~MyCanvas(void) | |
337 | { | |
338 | delete my_bitmap; | |
339 | delete my_backstore; | |
340 | delete my_horse; | |
341 | delete my_font; | |
342 | }; | |
343 | ||
344 | void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) | |
345 | { | |
346 | wxPaintDC dc( this ); | |
347 | PrepareDC( dc ); | |
348 | ||
349 | wxMemoryDC memDC; | |
350 | memDC.SelectObject( *my_backstore ); | |
351 | memDC.SetBrush( *wxBLACK_BRUSH ); | |
352 | memDC.SetPen( *wxWHITE_PEN ); | |
353 | memDC.DrawRectangle( 0, 0, 150, 150 ); | |
354 | memDC.SetTextForeground( *wxWHITE ); | |
355 | memDC.DrawText( "This is a memory dc.", 10, 10 ); | |
356 | ||
357 | int vx = 0; | |
358 | int vy = 0; | |
359 | GetVirtualSize( &vx, &vy ); | |
360 | dc.DrawLine( 5, 5, vx-10, vy-10 ); | |
361 | dc.DrawLine( 10, 20, 100, 10 ); | |
362 | dc.DrawLine( 10, 20, 100, 50 ); | |
363 | dc.DrawLine( 10, 20, 100, 100 ); | |
364 | ||
365 | dc.SetPen( *wxWHITE_PEN ); | |
366 | dc.DrawLine( 80, 50, 180, 50 ); | |
367 | ||
368 | dc.SetFont( *my_font ); | |
369 | ||
370 | long x = 0; | |
371 | long y = 0; | |
372 | dc.GetTextExtent( "Hej, ho, hej, ho.", &x, &y ); | |
373 | ||
374 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
375 | dc.DrawRectangle( 80, 40, x, y ); | |
376 | ||
377 | dc.SetTextForeground( *wxGREEN ); | |
378 | dc.DrawText( "Hej, ho, hej, ho.", 80, 40 ); | |
379 | ||
380 | dc.SetTextForeground( *wxBLACK ); | |
381 | dc.SetFont( *wxNORMAL_FONT ); | |
382 | dc.DrawText( "Hej, ho, hej, ho. (NormalFont)", 80, 60 ); | |
383 | dc.SetFont( *wxSMALL_FONT ); | |
384 | dc.DrawText( "Hej, ho, hej, ho. (SmallFont)", 80, 80 ); | |
385 | dc.SetFont( *wxITALIC_FONT ); | |
386 | dc.DrawText( "Hej, ho, hej, ho. (ItalicFont)", 80, 100 ); | |
387 | ||
388 | dc.DrawBitmap( *my_bitmap, 30, 80, TRUE ); | |
389 | dc.DrawBitmap( *my_horse, 30, 120 ); | |
390 | ||
391 | dc.Blit( 200, 200, 150, 150, &memDC, 0, 0, 0 ); | |
392 | ||
393 | memDC.SelectObject( wxNullBitmap ); | |
394 | ||
395 | /* | |
396 | dc.SetBrush( *wxBLACK_BRUSH ); | |
397 | dc.DrawRectangle( 50, 50, 50, 50 ); | |
398 | dc.SetPen( *wxWHITE_PEN ); | |
399 | dc.DrawRectangle( 101, 50, 50, 50 ); | |
400 | dc.DrawRectangle( 50, 101, 50, 50 ); | |
401 | ||
402 | dc.SetBrush( *wxWHITE_BRUSH ); | |
403 | ||
404 | dc.SetPen( *wxWHITE_PEN ); | |
405 | dc.DrawRectangle( 70, 70, 2, 2 ); | |
406 | ||
407 | dc.SetPen( *wxRED_PEN ); | |
408 | dc.DrawRectangle( 72, 70, 2, 2 ); | |
409 | dc.DrawRectangle( 70, 72, 2, 2 ); | |
410 | ||
411 | ||
412 | dc.SetPen( *wxRED_PEN ); | |
413 | dc.DrawRectangle( 82, 80, 2, 2 ); | |
414 | dc.DrawRectangle( 80, 82, 2, 2 ); | |
415 | ||
416 | dc.SetPen( *wxWHITE_PEN ); | |
417 | dc.DrawRectangle( 80, 80, 2, 2 ); | |
418 | */ | |
419 | }; | |
420 | ||
421 | //----------------------------------------------------------------------------- | |
422 | // MyFrame | |
423 | //----------------------------------------------------------------------------- | |
424 | ||
425 | const ID_OPEN = 101; | |
426 | const ID_SAVE = 102; | |
427 | const ID_MSG = 103; | |
428 | const ID_FONT = 104; | |
429 | const ID_DLG = 105; | |
430 | const ID_QUIT = 108; | |
431 | const ID_ABOUT = 109; | |
432 | ||
433 | IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame ) | |
434 | ||
435 | BEGIN_EVENT_TABLE(MyFrame,wxFrame) | |
436 | EVT_SIZE (MyFrame::OnSize) | |
437 | EVT_MENU (ID_OPEN, MyFrame::OnOpenDialog) | |
438 | EVT_MENU (ID_FONT, MyFrame::OnFontDialog) | |
439 | EVT_MENU (ID_MSG, MyFrame::OnMsg) | |
440 | EVT_MENU (ID_DLG, MyFrame::OnDialog) | |
441 | EVT_MENU (ID_ABOUT, MyFrame::OnAbout) | |
442 | EVT_MENU (ID_QUIT, MyFrame::OnQuit) | |
443 | END_EVENT_TABLE() | |
444 | ||
445 | MyFrame::MyFrame(void) : | |
446 | wxFrame( NULL, -1, "Robert's Test application", wxPoint(20,20), wxSize(470,360) ) | |
447 | { | |
448 | wxMenu *file_menu = new wxMenu( "Test" ); | |
449 | file_menu->Append( ID_OPEN, "Open.."); | |
450 | file_menu->Append( ID_MSG, "MessageBox.."); | |
451 | file_menu->Append( ID_FONT, "FontDialog.."); | |
452 | file_menu->AppendSeparator(); | |
453 | file_menu->Append( ID_DLG, "TestDialog.."); | |
454 | file_menu->AppendSeparator(); | |
455 | file_menu->Append( ID_ABOUT, "About.."); | |
456 | file_menu->Append( ID_QUIT, "Exit"); | |
457 | ||
458 | wxMenuBar *menu_bar = new wxMenuBar(); | |
459 | menu_bar->Append(file_menu, "File"); | |
460 | menu_bar->Show( TRUE ); | |
461 | ||
462 | SetMenuBar( menu_bar ); | |
463 | ||
464 | CreateStatusBar( 2 ); | |
465 | ||
466 | SetStatusText( "wxGTK v0.12", 0 ); | |
467 | SetStatusText( "Copyright 1998 Robert Roebling.", 1 ); | |
468 | ||
469 | m_canvas = new MyCanvas( this, -1, wxPoint(2,62), wxSize(300-4,120-4) ); | |
470 | m_canvas->SetScrollbars( 10, 10, 50, 50 ); | |
471 | ||
472 | m_tb = new wxToolBarGTK( this, -1, wxPoint(2,60), wxSize(300-4,26) ); | |
473 | m_tb->SetMargins( 2, 2 ); | |
474 | ||
475 | wxBitmap *bm = new wxBitmap( list_xpm ); | |
476 | m_tb->AddTool( 0, *bm, wxNullBitmap, FALSE, -1, -1, NULL, "This is a button" ); | |
477 | bm = new wxBitmap( folder_xpm ); | |
478 | m_tb->AddTool( 0, *bm, wxNullBitmap, TRUE, -1, -1, NULL, "This is a toggle" ); | |
479 | ||
480 | m_tb->Layout(); | |
481 | m_tb->Show( TRUE ); | |
482 | ||
483 | // m_timer.Start( 1000, TRUE ); | |
484 | }; | |
485 | ||
486 | void MyFrame::OnSize( wxSizeEvent &WXUNUSED(event) ) | |
487 | { | |
488 | int x = 0; | |
489 | int y = 0; | |
490 | GetClientSize( &x, &y ); | |
491 | ||
492 | m_tb->SetSize( 1, 0, x-2, 42 ); | |
493 | m_canvas-> SetSize( 0, 42, x, y-42 ); | |
494 | }; | |
495 | ||
496 | void MyFrame::OnDialog( wxCommandEvent &WXUNUSED(event) ) | |
497 | { | |
498 | MyDialog dialog( this ); | |
499 | dialog.ShowModal(); | |
500 | }; | |
501 | ||
502 | void MyFrame::OnFontDialog( wxCommandEvent &WXUNUSED(event) ) | |
503 | { | |
504 | wxFontData data; | |
505 | data.SetInitialFont( wxSMALL_FONT ); | |
506 | data.SetColour( wxRED ); | |
507 | wxGenericFontDialog dialog( this, &data ); | |
508 | if (dialog.ShowModal() == wxID_OK) | |
509 | { | |
510 | wxFontData retData = dialog.GetFontData(); | |
511 | // do something | |
512 | }; | |
513 | }; | |
514 | ||
515 | void MyFrame::OnOpenDialog( wxCommandEvent &WXUNUSED(event) ) | |
516 | { | |
517 | wxFileDialog dialog(this, "Testing open file dialog", "", "", "*.txt", 0); | |
518 | if (dialog.ShowModal() == wxID_OK) | |
519 | { | |
520 | wxMessageDialog dialog2(this, dialog.GetPath(), "Selected path"); | |
521 | dialog2.ShowModal(); | |
522 | }; | |
523 | }; | |
524 | ||
525 | void MyFrame::OnMsg( wxCommandEvent &WXUNUSED(event) ) | |
526 | { | |
527 | wxMessageBox( "There once was a lady from Riga.", "TestBox.", wxYES_NO ); | |
528 | }; | |
529 | ||
530 | void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) ) | |
531 | { | |
532 | Close( TRUE ); | |
533 | }; | |
534 | ||
535 | void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) ) | |
536 | { | |
537 | wxDialog dialog( this, -1, "About wxGTK", wxPoint(100,100), wxSize(540,350), wxDIALOG_MODAL ); | |
538 | ||
539 | int w = 0; | |
540 | int h = 0; | |
541 | dialog.GetSize( &w, &h ); | |
542 | ||
543 | int x = 30; | |
544 | int y = 20; | |
545 | int step = 20; | |
546 | ||
547 | (void)new wxStaticBox( &dialog, -1, (const char*)NULL, wxPoint(10,10), wxSize(w-20,h-80) ); | |
548 | ||
549 | (void)new wxStaticText( &dialog, -1, "wxGTK v0.12", wxPoint(240,y) ); | |
550 | y += 2*step-10; | |
551 | ||
552 | (void)new wxStaticText( &dialog, -1, "Written by Robert Roebling, 1998. More information at:", wxPoint(x,y) ); | |
553 | y += step; | |
554 | (void)new wxStaticText( &dialog, -1, "http://www.freiburg.linux.de/~wxxt", wxPoint(x+50,y) ); | |
555 | y += 2*step; | |
556 | ||
557 | (void)new wxStaticText( &dialog, -1, | |
558 | "wxGTK is based on the wxWindows GUI-library written mainly by Julian Smart. See:", wxPoint(x,y) ); | |
559 | y += step; | |
560 | (void)new wxStaticText( &dialog, -1, "http://web.ukonline.co.uk/julian.smart/wxwin", wxPoint(x+50,y) ); | |
561 | y += 2*step; | |
562 | ||
563 | (void)new wxStaticText( &dialog, -1, "wxWindows Copyright: Less restrictive version of LGPL.", wxPoint(x,y) ); | |
564 | y += 2*step; | |
565 | (void)new wxStaticText( &dialog, -1, "For questions concerning wxGTK, you may mail to:", wxPoint(x,y) ); | |
566 | y += step; | |
567 | (void)new wxStaticText( &dialog, -1, "roebling@ruf.uni-freiburg.de", wxPoint(x+50,y) ); | |
568 | ||
569 | (void) new wxButton( &dialog, wxID_OK, "Return", wxPoint(w/2-40,h-50), wxSize(80,30) ); | |
570 | ||
571 | dialog.ShowModal(); | |
572 | }; | |
573 | ||
574 | //----------------------------------------------------------------------------- | |
575 | // MyApp | |
576 | //----------------------------------------------------------------------------- | |
577 | ||
578 | MyApp::MyApp(void) : | |
579 | wxApp( ) | |
580 | { | |
581 | }; | |
582 | ||
583 | bool MyApp::OnInit(void) | |
584 | { | |
585 | wxFrame *frame = new MyFrame(); | |
586 | frame->Show( TRUE ); | |
587 | ||
588 | return TRUE; | |
589 | }; | |
590 | ||
591 | ||
592 | ||
593 | ||
594 |