]> git.saurik.com Git - wxWidgets.git/blob - samples/dialogs/dialogs.cpp
no reference to wxFont - you've got to be kidding! :)
[wxWidgets.git] / samples / dialogs / dialogs.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dialogs.cpp
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart
5 // Modified by: ABX (2004) - adjustements for conditional building + new menu
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(__APPLE__)
13 #pragma implementation
14 #pragma interface
15 #endif
16
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
19
20 #ifdef __BORLANDC__
21 #pragma hdrstop
22 #endif
23
24 #ifndef WX_PRECOMP
25 #include "wx/wx.h"
26 #endif
27
28 #include "wx/datetime.h"
29 #include "wx/image.h"
30
31 #if wxUSE_COLOURDLG
32 #include "wx/colordlg.h"
33 #endif // wxUSE_COLOURDLG
34
35 #if wxUSE_CHOICEDLG
36 #include "wx/choicdlg.h"
37 #endif // wxUSE_CHOICEDLG
38
39 #if wxUSE_STARTUP_TIPS
40 #include "wx/tipdlg.h"
41 #endif // wxUSE_STARTUP_TIPS
42
43 #if wxUSE_PROGRESSDLG
44 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
45 #include <wx/datetime.h> // wxDateTime
46 #endif
47
48 #include "wx/progdlg.h"
49 #endif // wxUSE_PROGRESSDLG
50
51 #if wxUSE_BUSYINFO
52 #include "wx/busyinfo.h"
53 #endif // wxUSE_BUSYINFO
54
55 #if wxUSE_NUMBERDLG
56 #include "wx/numdlg.h"
57 #endif // wxUSE_NUMBERDLG
58
59 #if wxUSE_FILEDLG
60 #include "wx/filedlg.h"
61 #endif // wxUSE_FILEDLG
62
63 #if wxUSE_DIRDLG
64 #include "wx/dirdlg.h"
65 #endif // wxUSE_DIRDLG
66
67 #if wxUSE_FONTDLG
68 #include "wx/fontdlg.h"
69 #endif // wxUSE_FONTDLG
70
71 #if wxUSE_FINDREPLDLG
72 #include "wx/fdrepdlg.h"
73 #endif // wxUSE_FINDREPLDLG
74
75 #include "dialogs.h"
76
77 #if USE_COLOURDLG_GENERIC
78 #include "wx/generic/colrdlgg.h"
79 #endif // USE_COLOURDLG_GENERIC
80
81 #if USE_DIRDLG_GENERIC
82 #include "wx/generic/dirdlgg.h"
83 #endif // USE_DIRDLG_GENERIC
84
85 #if USE_FILEDLG_GENERIC
86 #include "wx/generic/filedlgg.h"
87 #endif // USE_FILEDLG_GENERIC
88
89 #if USE_FONTDLG_GENERIC
90 #include "wx/generic/fontdlgg.h"
91 #endif // USE_FONTDLG_GENERIC
92
93 IMPLEMENT_APP(MyApp)
94
95 BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
96 EVT_PAINT(MyCanvas::OnPaint)
97 END_EVENT_TABLE()
98
99
100
101 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
102 EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox)
103
104 #if wxUSE_COLOURDLG
105 EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour)
106 #endif // wxUSE_COLOURDLG
107
108 #if wxUSE_FONTDLG
109 EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont)
110 #endif // wxUSE_FONTDLG
111
112 #if wxUSE_LOG_DIALOG
113 EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog)
114 #endif // wxUSE_LOG_DIALOG
115
116 #if wxUSE_TEXTDLG
117 EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry)
118 EVT_MENU(DIALOGS_PASSWORD_ENTRY, MyFrame::PasswordEntry)
119 #endif // wxUSE_TEXTDLG
120
121 #if wxUSE_NUMBERDLG
122 EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry)
123 #endif // wxUSE_NUMBERDLG
124
125 #if wxUSE_CHOICEDLG
126 EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice)
127 EVT_MENU(DIALOGS_MULTI_CHOICE, MyFrame::MultiChoice)
128 #endif // wxUSE_CHOICEDLG
129
130 #if wxUSE_FILEDLG
131 EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen)
132 EVT_MENU(DIALOGS_FILE_OPEN2, MyFrame::FileOpen2)
133 EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen)
134 EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave)
135 #endif // wxUSE_FILEDLG
136
137 #if USE_FILEDLG_GENERIC
138 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC, MyFrame::FileOpenGeneric)
139 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC, MyFrame::FilesOpenGeneric)
140 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC, MyFrame::FileSaveGeneric)
141 #endif // USE_FILEDLG_GENERIC
142
143 #if wxUSE_DIRDLG
144 EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose)
145 EVT_MENU(DIALOGS_DIRNEW_CHOOSE, MyFrame::DirChooseNew)
146 #endif // wxUSE_DIRDLG
147
148 #if USE_MODAL_PRESENTATION
149 EVT_MENU(DIALOGS_MODAL, MyFrame::ModalDlg)
150 EVT_MENU(DIALOGS_MODELESS, MyFrame::ModelessDlg)
151 #endif // USE_MODAL
152
153 #if wxUSE_STARTUP_TIPS
154 EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip)
155 #endif // wxUSE_STARTUP_TIPS
156
157 #if USE_FONTDLG_GENERIC
158 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric)
159 #endif // USE_FONTDLG_GENERIC
160
161 #if USE_DIRDLG_GENERIC
162 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE, MyFrame::GenericDirChoose)
163 #endif // wxMSW || wxMAC
164
165 #if USE_COLOURDLG_GENERIC
166 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric)
167 #endif // USE_COLOURDLG_GENERIC
168
169 #if wxUSE_PROGRESSDLG
170 EVT_MENU(DIALOGS_PROGRESS, MyFrame::ShowProgress)
171 #endif // wxUSE_PROGRESSDLG
172
173 #if wxUSE_BUSYINFO
174 EVT_MENU(DIALOGS_BUSYINFO, MyFrame::ShowBusyInfo)
175 #endif // wxUSE_BUSYINFO
176
177 #if wxUSE_FINDREPLDLG
178 EVT_MENU(DIALOGS_FIND, MyFrame::ShowFindDialog)
179 EVT_MENU(DIALOGS_REPLACE, MyFrame::ShowReplaceDialog)
180
181 EVT_FIND(wxID_ANY, MyFrame::OnFindDialog)
182 EVT_FIND_NEXT(wxID_ANY, MyFrame::OnFindDialog)
183 EVT_FIND_REPLACE(wxID_ANY, MyFrame::OnFindDialog)
184 EVT_FIND_REPLACE_ALL(wxID_ANY, MyFrame::OnFindDialog)
185 EVT_FIND_CLOSE(wxID_ANY, MyFrame::OnFindDialog)
186 #endif // wxUSE_FINDREPLDLG
187
188 EVT_MENU(DIALOGS_REQUEST, MyFrame::OnRequestUserAttention)
189
190 EVT_MENU(wxID_EXIT, MyFrame::OnExit)
191 END_EVENT_TABLE()
192
193 #if USE_MODAL_PRESENTATION
194
195 BEGIN_EVENT_TABLE(MyModalDialog, wxDialog)
196 EVT_BUTTON(wxID_ANY, MyModalDialog::OnButton)
197 END_EVENT_TABLE()
198
199 BEGIN_EVENT_TABLE(MyModelessDialog, wxDialog)
200 EVT_BUTTON(DIALOGS_MODELESS_BTN, MyModelessDialog::OnButton)
201 EVT_CLOSE(MyModelessDialog::OnClose)
202 END_EVENT_TABLE()
203
204 #endif // USE_MODAL_PRESENTATION
205
206 MyCanvas *myCanvas = (MyCanvas *) NULL;
207
208 // `Main program' equivalent, creating windows and returning main app frame
209 bool MyApp::OnInit()
210 {
211 #if wxUSE_IMAGE
212 wxInitAllImageHandlers();
213 #endif
214
215 m_canvasTextColour = wxColour(_T("BLACK"));
216 m_canvasFont = *wxNORMAL_FONT;
217
218 // Create the main frame window
219 MyFrame *frame = new MyFrame((wxFrame *) NULL, _T("wxWidgets dialogs example"));
220
221 // Make a menubar
222 wxMenu *file_menu = new wxMenu;
223
224 file_menu->Append(DIALOGS_MESSAGE_BOX, _T("&Message box\tCtrl-M"));
225
226
227 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
228
229 wxMenu *choices_menu = new wxMenu;
230
231 #if wxUSE_COLOURDLG
232 choices_menu->Append(DIALOGS_CHOOSE_COLOUR, _T("&Choose colour"));
233 #endif // wxUSE_COLOURDLG
234
235 #if wxUSE_FONTDLG
236 choices_menu->Append(DIALOGS_CHOOSE_FONT, _T("Choose &font"));
237 #endif // wxUSE_FONTDLG
238
239 #if wxUSE_CHOICEDLG
240 choices_menu->Append(DIALOGS_SINGLE_CHOICE, _T("&Single choice\tCtrl-C"));
241 choices_menu->Append(DIALOGS_MULTI_CHOICE, _T("M&ultiple choice\tCtrl-U"));
242 #endif // wxUSE_CHOICEDLG
243
244 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
245 choices_menu->AppendSeparator();
246 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
247
248 #if USE_COLOURDLG_GENERIC
249 choices_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, _T("&Choose colour (generic)"));
250 #endif // USE_COLOURDLG_GENERIC
251
252 #if USE_FONTDLG_GENERIC
253 choices_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, _T("Choose &font (generic)"));
254 #endif // USE_FONTDLG_GENERIC
255
256 file_menu->Append(wxID_ANY,_T("&Choices and selectors"),choices_menu);
257 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
258
259
260 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
261
262 wxMenu *entry_menu = new wxMenu;
263
264 #if wxUSE_TEXTDLG
265 entry_menu->Append(DIALOGS_TEXT_ENTRY, _T("Text &entry\tCtrl-E"));
266 entry_menu->Append(DIALOGS_PASSWORD_ENTRY, _T("&Password entry\tCtrl-P"));
267 #endif // wxUSE_TEXTDLG
268
269 #if wxUSE_NUMBERDLG
270 entry_menu->Append(DIALOGS_NUM_ENTRY, _T("&Numeric entry\tCtrl-N"));
271 #endif // wxUSE_NUMBERDLG
272
273 file_menu->Append(wxID_ANY,_T("&Entry dialogs"),entry_menu);
274
275 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
276
277
278 #if wxUSE_FILEDLG
279
280 wxMenu *filedlg_menu = new wxMenu;
281 filedlg_menu->Append(DIALOGS_FILE_OPEN, _T("&Open file\tCtrl-O"));
282 filedlg_menu->Append(DIALOGS_FILE_OPEN2, _T("&Second open file\tCtrl-2"));
283 filedlg_menu->Append(DIALOGS_FILES_OPEN, _T("Open &files\tCtrl-Q"));
284 filedlg_menu->Append(DIALOGS_FILE_SAVE, _T("Sa&ve file\tCtrl-S"));
285
286 #if USE_FILEDLG_GENERIC
287 filedlg_menu->AppendSeparator();
288 filedlg_menu->Append(DIALOGS_FILE_OPEN_GENERIC, _T("&Open file (generic)"));
289 filedlg_menu->Append(DIALOGS_FILES_OPEN_GENERIC, _T("Open &files (generic)"));
290 filedlg_menu->Append(DIALOGS_FILE_SAVE_GENERIC, _T("Sa&ve file (generic)"));
291 #endif // USE_FILEDLG_GENERIC
292
293 file_menu->Append(wxID_ANY,_T("&File operations"),filedlg_menu);
294
295 #endif // wxUSE_FILEDLG
296
297 #if wxUSE_DIRDLG
298 wxMenu *dir_menu = new wxMenu;
299
300 dir_menu->Append(DIALOGS_DIR_CHOOSE, _T("&Choose a directory\tCtrl-D"));
301 dir_menu->Append(DIALOGS_DIRNEW_CHOOSE, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
302 file_menu->Append(wxID_ANY,_T("&Directory operations"),dir_menu);
303
304 #if USE_DIRDLG_GENERIC
305 dir_menu->AppendSeparator();
306 dir_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE, _T("&Choose a directory (generic)"));
307 #endif // USE_DIRDLG_GENERIC
308
309 #endif // wxUSE_DIRDLG
310
311
312 #if wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
313
314 wxMenu *info_menu = new wxMenu;
315
316 #if wxUSE_STARTUP_TIPS
317 info_menu->Append(DIALOGS_TIP, _T("&Tip of the day\tCtrl-T"));
318 #endif // wxUSE_STARTUP_TIPS
319
320 #if wxUSE_PROGRESSDLG
321 info_menu->Append(DIALOGS_PROGRESS, _T("Pro&gress dialog\tCtrl-G"));
322 #endif // wxUSE_PROGRESSDLG
323
324 #if wxUSE_BUSYINFO
325 info_menu->Append(DIALOGS_BUSYINFO, _T("&Busy info dialog\tCtrl-B"));
326 #endif // wxUSE_BUSYINFO
327
328 #if wxUSE_LOG_DIALOG
329 info_menu->Append(DIALOGS_LOG_DIALOG, _T("&Log dialog\tCtrl-L"));
330 #endif // wxUSE_LOG_DIALOG
331
332 file_menu->Append(wxID_ANY,_T("&Informative dialogs"),info_menu);
333
334 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
335
336
337 #if wxUSE_FINDREPLDLG
338 wxMenu *find_menu = new wxMenu;
339 find_menu->AppendCheckItem(DIALOGS_FIND, _T("&Find dialog\tCtrl-F"));
340 find_menu->AppendCheckItem(DIALOGS_REPLACE, _T("Find and &replace dialog\tShift-Ctrl-F"));
341 file_menu->Append(wxID_ANY,_T("&Searching"),find_menu);
342 #endif // wxUSE_FINDREPLDLG
343
344 #if USE_MODAL_PRESENTATION
345 wxMenu *modal_menu = new wxMenu;
346 modal_menu->Append(DIALOGS_MODAL, _T("Mo&dal dialog\tCtrl-W"));
347 modal_menu->AppendCheckItem(DIALOGS_MODELESS, _T("Modeless &dialog\tCtrl-Z"));
348 file_menu->Append(wxID_ANY,_T("&Modal/Modeless"),modal_menu);
349 #endif // USE_MODAL_PRESENTATION
350
351 file_menu->Append(DIALOGS_REQUEST, _T("&Request user attention\tCtrl-R"));
352
353 file_menu->AppendSeparator();
354 file_menu->Append(wxID_EXIT, _T("E&xit\tAlt-X"));
355
356 wxMenuBar *menu_bar = new wxMenuBar;
357 menu_bar->Append(file_menu, _T("&File"));
358 frame->SetMenuBar(menu_bar);
359
360 myCanvas = new MyCanvas(frame);
361 myCanvas->SetBackgroundColour(*wxWHITE);
362
363 frame->Centre(wxBOTH);
364
365 // Show the frame
366 frame->Show(true);
367
368 SetTopWindow(frame);
369
370 return true;
371 }
372
373 // My frame constructor
374 MyFrame::MyFrame(wxWindow *parent,
375 const wxString& title)
376 : wxFrame(parent, wxID_ANY, title)
377 {
378 #if USE_MODAL_PRESENTATION
379 m_dialog = (MyModelessDialog *)NULL;
380 #endif // USE_MODAL_PRESENTATION
381
382 #if wxUSE_FINDREPLDLG
383 m_dlgFind =
384 m_dlgReplace = NULL;
385 #endif
386
387 #if wxUSE_COLOURDLG
388 m_clrData.SetChooseFull(true);
389 for (int i = 0; i < 16; i++)
390 {
391 m_clrData.SetCustomColour(i, wxColour(i*16, i*16, i*16));
392 }
393 #endif // wxUSE_COLOURDLG
394
395 #if wxUSE_STATUSBAR
396 CreateStatusBar();
397 #endif // wxUSE_STATUSBAR
398 }
399
400 #if wxUSE_COLOURDLG
401 void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event) )
402 {
403 m_clrData.SetColour(myCanvas->GetBackgroundColour());
404
405 wxColourDialog dialog(this, &m_clrData);
406 dialog.SetTitle(_T("Choose the background colour"));
407 if (dialog.ShowModal() == wxID_OK)
408 {
409 m_clrData = dialog.GetColourData();
410 myCanvas->SetBackgroundColour(m_clrData.GetColour());
411 myCanvas->ClearBackground();
412 myCanvas->Refresh();
413 }
414 }
415 #endif // wxUSE_COLOURDLG
416
417 #if wxUSE_FONTDLG
418 void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
419 {
420 wxFontData data;
421 data.SetInitialFont(wxGetApp().m_canvasFont);
422 data.SetColour(wxGetApp().m_canvasTextColour);
423
424 // you might also do this:
425 //
426 // wxFontDialog dialog;
427 // if ( !dialog.Create(this, data) { ... error ... }
428 //
429 wxFontDialog dialog(this, data);
430
431 if (dialog.ShowModal() == wxID_OK)
432 {
433 wxFontData retData = dialog.GetFontData();
434 wxGetApp().m_canvasFont = retData.GetChosenFont();
435 wxGetApp().m_canvasTextColour = retData.GetColour();
436 myCanvas->Refresh();
437 }
438 //else: cancelled by the user, don't change the font
439 }
440 #endif // wxUSE_FONTDLG
441
442 #if USE_COLOURDLG_GENERIC
443 void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event))
444 {
445 wxColourData data;
446 data.SetChooseFull(true);
447 for (int i = 0; i < 16; i++)
448 {
449 wxColour colour(i*16, i*16, i*16);
450 data.SetCustomColour(i, colour);
451 }
452
453 wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &data);
454 if (dialog->ShowModal() == wxID_OK)
455 {
456 wxColourData retData = dialog->GetColourData();
457 wxColour col = retData.GetColour();
458 // wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
459 myCanvas->SetBackgroundColour(col);
460 myCanvas->ClearBackground();
461 myCanvas->Refresh();
462 }
463 dialog->Destroy();
464 }
465 #endif // USE_COLOURDLG_GENERIC
466
467 #if USE_FONTDLG_GENERIC
468 void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) )
469 {
470 wxFontData data;
471 data.SetInitialFont(wxGetApp().m_canvasFont);
472 data.SetColour(wxGetApp().m_canvasTextColour);
473
474 wxGenericFontDialog *dialog = new wxGenericFontDialog(this, &data);
475 if (dialog->ShowModal() == wxID_OK)
476 {
477 wxFontData retData = dialog->GetFontData();
478 wxGetApp().m_canvasFont = retData.GetChosenFont();
479 wxGetApp().m_canvasTextColour = retData.GetColour();
480 myCanvas->Refresh();
481 }
482 dialog->Destroy();
483 }
484 #endif // USE_FONTDLG_GENERIC
485
486 #if wxUSE_LOG_DIALOG
487 void MyFrame::LogDialog(wxCommandEvent& WXUNUSED(event))
488 {
489 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
490 // being flushed -- test it
491 {
492 wxBusyCursor bc;
493 wxLogMessage(wxT("This is some message - everything is ok so far."));
494 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
495 wxLogWarning(wxT("And then something went wrong!"));
496
497 // and if ~wxBusyCursor doesn't do it, then call it manually
498 wxYield();
499 }
500
501 wxLogError(wxT("Intermediary error handler decided to abort."));
502 wxLogError(wxT("The top level caller detected an unrecoverable error."));
503
504 wxLog::FlushActive();
505
506 wxLogMessage(wxT("And this is the same dialog but with only one message."));
507 }
508 #endif // wxUSE_LOG_DIALOG
509
510 void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) )
511 {
512 wxMessageDialog dialog( NULL, _T("This is a message box\nA long, long string to test out the message box properly"),
513 _T("Message box text"), wxNO_DEFAULT|wxYES_NO|wxCANCEL|wxICON_INFORMATION);
514
515 switch ( dialog.ShowModal() )
516 {
517 case wxID_YES:
518 wxLogStatus(wxT("You pressed \"Yes\""));
519 break;
520
521 case wxID_NO:
522 wxLogStatus(wxT("You pressed \"No\""));
523 break;
524
525 case wxID_CANCEL:
526 wxLogStatus(wxT("You pressed \"Cancel\""));
527 break;
528
529 default:
530 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
531 }
532 }
533
534 #if wxUSE_NUMBERDLG
535 void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event) )
536 {
537 long res = wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
538 _T("Even two rows of text."),
539 _T("Enter a number:"), _T("Numeric input test"),
540 50, 0, 100, this );
541
542 wxString msg;
543 int icon;
544 if ( res == -1 )
545 {
546 msg = _T("Invalid number entered or dialog cancelled.");
547 icon = wxICON_HAND;
548 }
549 else
550 {
551 msg.Printf(_T("You've entered %lu"), res );
552 icon = wxICON_INFORMATION;
553 }
554
555 wxMessageBox(msg, _T("Numeric test result"), wxOK | icon, this);
556 }
557 #endif // wxUSE_NUMBERDLG
558
559 #if wxUSE_TEXTDLG
560 void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event))
561 {
562 wxString pwd = wxGetPasswordFromUser(_T("Enter password:"),
563 _T("Password entry dialog"),
564 wxEmptyString,
565 this);
566 if ( !!pwd )
567 {
568 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd.c_str()),
569 _T("Got password"), wxOK | wxICON_INFORMATION, this);
570 }
571 }
572
573 void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event))
574 {
575 wxTextEntryDialog dialog(this,
576 _T("This is a small sample\n")
577 _T("A long, long string to test out the text entrybox"),
578 _T("Please enter a string"),
579 _T("Default value"),
580 wxOK | wxCANCEL);
581
582 if (dialog.ShowModal() == wxID_OK)
583 {
584 wxMessageBox(dialog.GetValue(), _T("Got string"), wxOK | wxICON_INFORMATION, this);
585 }
586 }
587 #endif // wxUSE_TEXTDLG
588
589 #if wxUSE_CHOICEDLG
590 void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) )
591 {
592 const wxString choices[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
593
594 wxSingleChoiceDialog dialog(this,
595 _T("This is a small sample\n")
596 _T("A single-choice convenience dialog"),
597 _T("Please select a value"),
598 WXSIZEOF(choices), choices);
599
600 dialog.SetSelection(2);
601
602 if (dialog.ShowModal() == wxID_OK)
603 {
604 wxMessageDialog dialog2(this, dialog.GetStringSelection(), _T("Got string"));
605 dialog2.ShowModal();
606 }
607 }
608
609 void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) )
610 {
611 const wxString choices[] =
612 {
613 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
614 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
615 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
616 };
617
618 wxArrayInt selections;
619 size_t count = wxGetMultipleChoices(selections,
620 _T("This is a small sample\n")
621 _T("A multi-choice convenience dialog"),
622 _T("Please select a value"),
623 WXSIZEOF(choices), choices,
624 this);
625 if ( count )
626 {
627 wxString msg;
628 msg.Printf(wxT("You selected %u items:\n"), (unsigned)count);
629 for ( size_t n = 0; n < count; n++ )
630 {
631 msg += wxString::Format(wxT("\t%u: %u (%s)\n"),
632 (unsigned)n, (unsigned)selections[n],
633 choices[selections[n]].c_str());
634 }
635 wxLogMessage(msg);
636 }
637 //else: cancelled or nothing selected
638 }
639 #endif // wxUSE_CHOICEDLG
640
641 #if wxUSE_FILEDLG
642 void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
643 {
644 wxFileDialog dialog
645 (
646 this,
647 _T("Testing open file dialog"),
648 wxEmptyString,
649 wxEmptyString,
650 #ifdef __WXMOTIF__
651 _T("C++ files (*.cpp)|*.cpp")
652 #else
653 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
654 #endif
655 );
656
657 dialog.SetDirectory(wxGetHomeDir());
658
659 if (dialog.ShowModal() == wxID_OK)
660 {
661 wxString info;
662 info.Printf(_T("Full file name: %s\n")
663 _T("Path: %s\n")
664 _T("Name: %s"),
665 dialog.GetPath().c_str(),
666 dialog.GetDirectory().c_str(),
667 dialog.GetFilename().c_str());
668 wxMessageDialog dialog2(this, info, _T("Selected file"));
669 dialog2.ShowModal();
670 }
671 }
672
673 // this shows how to take advantage of specifying a default extension in the
674 // call to wxFileSelector: it is remembered after each new call and the next
675 // one will use it by default
676 void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) )
677 {
678 static wxString s_extDef;
679 wxString path = wxFileSelector(
680 _T("Select the file to load"),
681 wxEmptyString, wxEmptyString,
682 s_extDef,
683 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
684 wxCHANGE_DIR,
685 this
686 );
687
688 if ( !path )
689 return;
690
691 // it is just a sample, would use wxSplitPath in real program
692 s_extDef = path.AfterLast(_T('.'));
693
694 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
695 (const wxChar*) path, (const wxChar*) s_extDef);
696 }
697
698 void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) )
699 {
700 wxString wildcards =
701 #ifdef __WXMOTIF__
702 _T("C++ files (*.cpp)|*.cpp");
703 #else
704 _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
705 #endif
706 wxFileDialog dialog(this, _T("Testing open multiple file dialog"),
707 wxEmptyString, wxEmptyString, wildcards,
708 wxMULTIPLE);
709
710 if (dialog.ShowModal() == wxID_OK)
711 {
712 wxArrayString paths, filenames;
713
714 dialog.GetPaths(paths);
715 dialog.GetFilenames(filenames);
716
717 wxString msg, s;
718 size_t count = paths.GetCount();
719 for ( size_t n = 0; n < count; n++ )
720 {
721 s.Printf(_T("File %d: %s (%s)\n"),
722 (int)n, paths[n].c_str(), filenames[n].c_str());
723
724 msg += s;
725 }
726 s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex());
727 msg += s;
728
729 wxMessageDialog dialog2(this, msg, _T("Selected files"));
730 dialog2.ShowModal();
731 }
732 }
733
734 void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) )
735 {
736 wxFileDialog dialog(this,
737 _T("Testing save file dialog"),
738 wxEmptyString,
739 _T("myletter.doc"),
740 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
741 wxSAVE|wxOVERWRITE_PROMPT);
742
743 dialog.SetFilterIndex(1);
744
745 if (dialog.ShowModal() == wxID_OK)
746 {
747 wxLogMessage(_T("%s, filter %d"),
748 dialog.GetPath().c_str(), dialog.GetFilterIndex());
749 }
750 }
751 #endif // wxUSE_FILEDLG
752
753 #if USE_FILEDLG_GENERIC
754 void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) )
755 {
756 wxGenericFileDialog dialog
757 (
758 this,
759 _T("Testing open file dialog"),
760 wxEmptyString,
761 wxEmptyString,
762 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
763 );
764
765 dialog.SetDirectory(wxGetHomeDir());
766
767 if (dialog.ShowModal() == wxID_OK)
768 {
769 wxString info;
770 info.Printf(_T("Full file name: %s\n")
771 _T("Path: %s\n")
772 _T("Name: %s"),
773 dialog.GetPath().c_str(),
774 dialog.GetDirectory().c_str(),
775 dialog.GetFilename().c_str());
776 wxMessageDialog dialog2(this, info, _T("Selected file"));
777 dialog2.ShowModal();
778 }
779 }
780
781 void MyFrame::FilesOpenGeneric(wxCommandEvent& WXUNUSED(event) )
782 {
783 wxString wildcards = _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
784 wxGenericFileDialog dialog(this, _T("Testing open multiple file dialog"),
785 wxEmptyString, wxEmptyString, wildcards,
786 wxMULTIPLE);
787
788 if (dialog.ShowModal() == wxID_OK)
789 {
790 wxArrayString paths, filenames;
791
792 dialog.GetPaths(paths);
793 dialog.GetFilenames(filenames);
794
795 wxString msg, s;
796 size_t count = paths.GetCount();
797 for ( size_t n = 0; n < count; n++ )
798 {
799 s.Printf(_T("File %d: %s (%s)\n"),
800 (int)n, paths[n].c_str(), filenames[n].c_str());
801
802 msg += s;
803 }
804 s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex());
805 msg += s;
806
807 wxMessageDialog dialog2(this, msg, _T("Selected files"));
808 dialog2.ShowModal();
809 }
810 }
811
812 void MyFrame::FileSaveGeneric(wxCommandEvent& WXUNUSED(event) )
813 {
814 wxGenericFileDialog dialog(this,
815 _T("Testing save file dialog"),
816 wxEmptyString,
817 _T("myletter.doc"),
818 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
819 wxSAVE|wxOVERWRITE_PROMPT);
820
821 dialog.SetFilterIndex(1);
822
823 if (dialog.ShowModal() == wxID_OK)
824 {
825 wxLogMessage(_T("%s, filter %d"),
826 dialog.GetPath().c_str(), dialog.GetFilterIndex());
827 }
828 }
829 #endif // USE_FILEDLG_GENERIC
830
831 #if wxUSE_DIRDLG
832 void MyFrame::DoDirChoose(int style)
833 {
834 // pass some initial dir to wxDirDialog
835 wxString dirHome;
836 wxGetHomeDir(&dirHome);
837
838 wxDirDialog dialog(this, _T("Testing directory picker"), dirHome, style);
839
840 if (dialog.ShowModal() == wxID_OK)
841 {
842 wxLogMessage(_T("Selected path: %s"), dialog.GetPath().c_str());
843 }
844 }
845
846 void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) )
847 {
848 DoDirChoose(wxDD_DEFAULT_STYLE & ~wxDD_NEW_DIR_BUTTON);
849 }
850
851 void MyFrame::DirChooseNew(wxCommandEvent& WXUNUSED(event) )
852 {
853 DoDirChoose(wxDD_DEFAULT_STYLE | wxDD_NEW_DIR_BUTTON);
854 }
855 #endif // wxUSE_DIRDLG
856
857 #if USE_DIRDLG_GENERIC
858 void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) )
859 {
860 // pass some initial dir to wxDirDialog
861 wxString dirHome;
862 wxGetHomeDir(&dirHome);
863
864 wxGenericDirDialog dialog(this, _T("Testing generic directory picker"), dirHome);
865
866 if (dialog.ShowModal() == wxID_OK)
867 {
868 wxMessageDialog dialog2(this, dialog.GetPath(), _T("Selected path"));
869 dialog2.ShowModal();
870 }
871 }
872 #endif // USE_DIRDLG_GENERIC
873
874 #if USE_MODAL_PRESENTATION
875 void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event))
876 {
877 MyModalDialog dlg(this);
878 dlg.ShowModal();
879 }
880
881 void MyFrame::ModelessDlg(wxCommandEvent& event)
882 {
883 bool show = GetMenuBar()->IsChecked(event.GetId());
884
885 if ( show )
886 {
887 if ( !m_dialog )
888 {
889 m_dialog = new MyModelessDialog(this);
890 }
891
892 m_dialog->Show(true);
893 }
894 else // hide
895 {
896 m_dialog->Hide();
897 }
898 }
899 #endif // USE_MODAL_PRESENTATION
900
901 #if wxUSE_STARTUP_TIPS
902 void MyFrame::ShowTip(wxCommandEvent& WXUNUSED(event))
903 {
904 static size_t s_index = (size_t)-1;
905
906 if ( s_index == (size_t)-1 )
907 {
908 srand(time(NULL));
909
910 // this is completely bogus, we don't know how many lines are there
911 // in the file, but who cares, it's a demo only...
912 s_index = rand() % 5;
913 }
914
915 wxTipProvider *tipProvider = wxCreateFileTipProvider(_T("tips.txt"), s_index);
916
917 bool showAtStartup = wxShowTip(this, tipProvider);
918
919 if ( showAtStartup )
920 {
921 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
922 wxOK | wxICON_INFORMATION, this);
923 }
924
925 s_index = tipProvider->GetCurrentTip();
926 delete tipProvider;
927 }
928 #endif // wxUSE_STARTUP_TIPS
929
930 void MyFrame::OnRequestUserAttention(wxCommandEvent& WXUNUSED(event))
931 {
932 wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window"));
933
934 wxSleep(3);
935
936 RequestUserAttention(wxUSER_ATTENTION_ERROR);
937 }
938
939 void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) )
940 {
941 Close(true);
942 }
943
944 #if wxUSE_PROGRESSDLG
945
946 void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
947 {
948 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
949 // check the performance
950 int countrandomnumbers = 0, count = 0;
951 wxTimeSpan tsTest(0,0,0,250);
952 wxDateTime DT2, DT1 = wxDateTime::UNow();
953 srand(0);
954 while(1)
955 {
956 rand();
957 ++countrandomnumbers;
958 if ( countrandomnumbers == 1000 )
959 {
960 srand(0);
961 countrandomnumbers = 0;
962 ++count;
963 DT2 = wxDateTime::UNow();
964 wxTimeSpan ts = DT2.Subtract( DT1 );
965 if ( ts.IsLongerThan( tsTest ) )
966 {
967 break;
968 }
969 }
970 }
971 const int max = 40 * count;
972 #else
973 static const int max = 10;
974 #endif // wxUSE_STOPWATCH && wxUSE_LONGLONG
975
976 wxProgressDialog dialog(_T("Progress dialog example"),
977 _T("An informative message"),
978 max, // range
979 this, // parent
980 wxPD_CAN_ABORT |
981 wxPD_APP_MODAL |
982 // wxPD_AUTO_HIDE | -- try this as well
983 wxPD_ELAPSED_TIME |
984 wxPD_ESTIMATED_TIME |
985 wxPD_REMAINING_TIME);
986
987 bool cont = true;
988 for ( int i = 0; i <= max; i++ )
989 {
990 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
991 // do (almost) the same operations as we did for the performance test
992 srand(0);
993 for ( int j = 0; j < 1000; j++ )
994 {
995 rand();
996 if ( j == 999 )
997 {
998 DT2 = wxDateTime::UNow();
999 wxTimeSpan ts = DT2.Subtract( DT1 );
1000 if ( ts.IsLongerThan( tsTest ) )
1001 {
1002 // nothing to do
1003 }
1004 }
1005 }
1006 #else
1007 wxSleep(1);
1008 #endif
1009 if ( i == max )
1010 {
1011 cont = dialog.Update(i, _T("That's all, folks!"));
1012 }
1013 else if ( i == max / 2 )
1014 {
1015 cont = dialog.Update(i, _T("Only a half left (very long message)!"));
1016 }
1017 else
1018 {
1019 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
1020 if ( (i % (max/100)) == 0 ) // // only 100 updates, this makes it much faster
1021 {
1022 cont = dialog.Update(i);
1023 }
1024 #else
1025 cont = dialog.Update(i);
1026 #endif
1027 }
1028 if ( !cont )
1029 {
1030 if ( wxMessageBox(_T("Do you really want to cancel?"),
1031 _T("Progress dialog question"), // caption
1032 wxYES_NO | wxICON_QUESTION) == wxYES )
1033 break;
1034
1035 cont = true;
1036 dialog.Resume();
1037 }
1038 }
1039
1040 if ( !cont )
1041 {
1042 wxLogStatus(wxT("Progress dialog aborted!"));
1043 }
1044 else
1045 {
1046 wxLogStatus(wxT("Countdown from %d finished"), max);
1047 }
1048 }
1049
1050 #endif // wxUSE_PROGRESSDLG
1051
1052 #if wxUSE_BUSYINFO
1053
1054 void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event))
1055 {
1056 wxWindowDisabler disableAll;
1057
1058 wxBusyInfo info(_T("Working, please wait..."), this);
1059
1060 for ( int i = 0; i < 18; i++ )
1061 {
1062 //wxUsleep(100);
1063 wxTheApp->Yield();
1064 }
1065
1066 wxSleep(2);
1067 //wxWakeUpIdle();
1068 }
1069
1070 #endif // wxUSE_BUSYINFO
1071
1072 #if wxUSE_FINDREPLDLG
1073
1074 void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) )
1075 {
1076 if ( m_dlgReplace )
1077 {
1078 delete m_dlgReplace;
1079 m_dlgReplace = NULL;
1080 }
1081 else
1082 {
1083 m_dlgReplace = new wxFindReplaceDialog
1084 (
1085 this,
1086 &m_findData,
1087 _T("Find and replace dialog"),
1088 wxFR_REPLACEDIALOG
1089 );
1090
1091 m_dlgReplace->Show(true);
1092 }
1093 }
1094
1095 void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) )
1096 {
1097 if ( m_dlgFind )
1098 {
1099 delete m_dlgFind;
1100 m_dlgFind = NULL;
1101 }
1102 else
1103 {
1104 m_dlgFind = new wxFindReplaceDialog
1105 (
1106 this,
1107 &m_findData,
1108 _T("Find dialog"),
1109 // just for testing
1110 wxFR_NOWHOLEWORD
1111 );
1112
1113 m_dlgFind->Show(true);
1114 }
1115 }
1116
1117 static wxString DecodeFindDialogEventFlags(int flags)
1118 {
1119 wxString str;
1120 str << (flags & wxFR_DOWN ? _T("down") : _T("up")) << _T(", ")
1121 << (flags & wxFR_WHOLEWORD ? _T("whole words only, ") : _T(""))
1122 << (flags & wxFR_MATCHCASE ? _T("") : _T("not "))
1123 << _T("case sensitive");
1124
1125 return str;
1126 }
1127
1128 void MyFrame::OnFindDialog(wxFindDialogEvent& event)
1129 {
1130 wxEventType type = event.GetEventType();
1131
1132 if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT )
1133 {
1134 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1135 type == wxEVT_COMMAND_FIND_NEXT ? wxT("next ") : wxT(""),
1136 event.GetFindString().c_str(),
1137 DecodeFindDialogEventFlags(event.GetFlags()).c_str());
1138 }
1139 else if ( type == wxEVT_COMMAND_FIND_REPLACE ||
1140 type == wxEVT_COMMAND_FIND_REPLACE_ALL )
1141 {
1142 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1143 type == wxEVT_COMMAND_FIND_REPLACE_ALL ? _T("all ") : wxT(""),
1144 event.GetFindString().c_str(),
1145 event.GetReplaceString().c_str(),
1146 DecodeFindDialogEventFlags(event.GetFlags()).c_str());
1147 }
1148 else if ( type == wxEVT_COMMAND_FIND_CLOSE )
1149 {
1150 wxFindReplaceDialog *dlg = event.GetDialog();
1151
1152 int idMenu;
1153 const wxChar *txt;
1154 if ( dlg == m_dlgFind )
1155 {
1156 txt = _T("Find");
1157 idMenu = DIALOGS_FIND;
1158 m_dlgFind = NULL;
1159 }
1160 else if ( dlg == m_dlgReplace )
1161 {
1162 txt = _T("Replace");
1163 idMenu = DIALOGS_REPLACE;
1164 m_dlgReplace = NULL;
1165 }
1166 else
1167 {
1168 txt = _T("Unknown");
1169 idMenu = wxID_ANY;
1170
1171 wxFAIL_MSG( _T("unexpected event") );
1172 }
1173
1174 wxLogMessage(wxT("%s dialog is being closed."), txt);
1175
1176 if ( idMenu != wxID_ANY )
1177 {
1178 GetMenuBar()->Check(idMenu, false);
1179 }
1180
1181 dlg->Destroy();
1182 }
1183 else
1184 {
1185 wxLogError(wxT("Unknown find dialog event!"));
1186 }
1187 }
1188
1189 #endif // wxUSE_FINDREPLDLG
1190
1191 // ----------------------------------------------------------------------------
1192 // MyCanvas
1193 // ----------------------------------------------------------------------------
1194
1195 void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
1196 {
1197 wxPaintDC dc(this);
1198 dc.SetFont(wxGetApp().m_canvasFont);
1199 dc.SetTextForeground(wxGetApp().m_canvasTextColour);
1200 dc.SetBackgroundMode(wxTRANSPARENT);
1201 dc.DrawText(
1202 _T("wxWidgets common dialogs")
1203 #if !defined(__SMARTPHONE__)
1204 _T(" test application")
1205 #endif
1206 , 10, 10);
1207 }
1208
1209 #if USE_MODAL_PRESENTATION
1210
1211 // ----------------------------------------------------------------------------
1212 // MyModelessDialog
1213 // ----------------------------------------------------------------------------
1214
1215 MyModelessDialog::MyModelessDialog(wxWindow *parent)
1216 : wxDialog(parent, wxID_ANY, wxString(_T("Modeless dialog")))
1217 {
1218 wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
1219
1220 wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, _T("Press me"));
1221 wxCheckBox *check = new wxCheckBox(this, wxID_ANY, _T("Should be disabled"));
1222 check->Disable();
1223
1224 sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5);
1225 sizerTop->Add(check, 1, wxEXPAND | wxALL, 5);
1226
1227 SetSizer(sizerTop);
1228
1229 sizerTop->SetSizeHints(this);
1230 sizerTop->Fit(this);
1231 }
1232
1233 void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event))
1234 {
1235 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1236 wxOK | wxICON_INFORMATION, this);
1237 }
1238
1239 void MyModelessDialog::OnClose(wxCloseEvent& event)
1240 {
1241 if ( event.CanVeto() )
1242 {
1243 wxMessageBox(_T("Use the menu item to close this dialog"),
1244 _T("Modeless dialog"),
1245 wxOK | wxICON_INFORMATION, this);
1246
1247 event.Veto();
1248 }
1249 }
1250
1251 // ----------------------------------------------------------------------------
1252 // MyModalDialog
1253 // ----------------------------------------------------------------------------
1254
1255 MyModalDialog::MyModalDialog(wxWindow *parent)
1256 : wxDialog(parent, wxID_ANY, wxString(_T("Modal dialog")))
1257 {
1258 wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
1259
1260 m_btnModal = new wxButton(this, wxID_ANY, _T("&Modal dialog..."));
1261 m_btnModeless = new wxButton(this, wxID_ANY, _T("Mode&less dialog"));
1262 m_btnDelete = new wxButton(this, wxID_ANY, _T("&Delete button"));
1263
1264 wxButton *btnOk = new wxButton(this, wxID_CANCEL, _T("&Close"));
1265 sizerTop->Add(m_btnModal, 0, wxALIGN_CENTER | wxALL, 5);
1266 sizerTop->Add(m_btnModeless, 0, wxALIGN_CENTER | wxALL, 5);
1267 sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5);
1268 sizerTop->Add(btnOk, 0, wxALIGN_CENTER | wxALL, 5);
1269
1270 SetSizer(sizerTop);
1271
1272 sizerTop->SetSizeHints(this);
1273 sizerTop->Fit(this);
1274
1275 m_btnModal->SetFocus();
1276 m_btnModal->SetDefault();
1277 }
1278
1279 void MyModalDialog::OnButton(wxCommandEvent& event)
1280 {
1281 if ( event.GetEventObject() == m_btnDelete )
1282 {
1283 delete m_btnModal;
1284 m_btnModal = NULL;
1285
1286 m_btnDelete->Disable();
1287 }
1288 else if ( event.GetEventObject() == m_btnModal )
1289 {
1290 #if wxUSE_TEXTDLG
1291 wxGetTextFromUser(_T("Dummy prompt"),
1292 _T("Modal dialog called from dialog"),
1293 wxEmptyString, this);
1294 #else
1295 wxMessageBox(_T("Modal dialog called from dialog"));
1296 #endif // wxUSE_TEXTDLG
1297 }
1298 else if ( event.GetEventObject() == m_btnModeless )
1299 {
1300 (new MyModelessDialog(this))->Show();
1301 }
1302 else
1303 {
1304 event.Skip();
1305 }
1306 }
1307
1308 #endif // USE_MODAL_PRESENTATION
1309