]> git.saurik.com Git - wxWidgets.git/blob - samples/dialogs/dialogs.cpp
wxPyCallback needs to derive from wxEvtHandler now since the
[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(
392 i,
393 wxColour(
394 (unsigned char)(i*16),
395 (unsigned char)(i*16),
396 (unsigned char)(i*16)
397 )
398 );
399 }
400 #endif // wxUSE_COLOURDLG
401
402 #if wxUSE_STATUSBAR
403 CreateStatusBar();
404 #endif // wxUSE_STATUSBAR
405 }
406
407 #if wxUSE_COLOURDLG
408 void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event) )
409 {
410 m_clrData.SetColour(myCanvas->GetBackgroundColour());
411
412 wxColourDialog dialog(this, &m_clrData);
413 dialog.SetTitle(_T("Choose the background colour"));
414 if (dialog.ShowModal() == wxID_OK)
415 {
416 m_clrData = dialog.GetColourData();
417 myCanvas->SetBackgroundColour(m_clrData.GetColour());
418 myCanvas->ClearBackground();
419 myCanvas->Refresh();
420 }
421 }
422 #endif // wxUSE_COLOURDLG
423
424 #if USE_COLOURDLG_GENERIC
425 void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event))
426 {
427 m_clrData.SetColour(myCanvas->GetBackgroundColour());
428
429 //FIXME:TODO:This has no effect...
430 m_clrData.SetChooseFull(true);
431
432 for (int i = 0; i < 16; i++)
433 {
434 wxColour colour(
435 (unsigned char)(i*16),
436 (unsigned char)(i*16),
437 (unsigned char)(i*16)
438 );
439 m_clrData.SetCustomColour(i, colour);
440 }
441
442 wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &m_clrData);
443 if (dialog->ShowModal() == wxID_OK)
444 {
445 m_clrData = dialog->GetColourData();
446 myCanvas->SetBackgroundColour(m_clrData.GetColour());
447 myCanvas->ClearBackground();
448 myCanvas->Refresh();
449 }
450 dialog->Destroy();
451 }
452 #endif // USE_COLOURDLG_GENERIC
453
454 #if wxUSE_FONTDLG
455 void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
456 {
457 wxFontData data;
458 data.SetInitialFont(wxGetApp().m_canvasFont);
459 data.SetColour(wxGetApp().m_canvasTextColour);
460
461 // you might also do this:
462 //
463 // wxFontDialog dialog;
464 // if ( !dialog.Create(this, data) { ... error ... }
465 //
466 wxFontDialog dialog(this, data);
467
468 if (dialog.ShowModal() == wxID_OK)
469 {
470 wxFontData retData = dialog.GetFontData();
471 wxGetApp().m_canvasFont = retData.GetChosenFont();
472 wxGetApp().m_canvasTextColour = retData.GetColour();
473 myCanvas->Refresh();
474 }
475 //else: cancelled by the user, don't change the font
476 }
477 #endif // wxUSE_FONTDLG
478
479 #if USE_FONTDLG_GENERIC
480 void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) )
481 {
482 wxFontData data;
483 data.SetInitialFont(wxGetApp().m_canvasFont);
484 data.SetColour(wxGetApp().m_canvasTextColour);
485
486 wxGenericFontDialog *dialog = new wxGenericFontDialog(this, &data);
487 if (dialog->ShowModal() == wxID_OK)
488 {
489 wxFontData retData = dialog->GetFontData();
490 wxGetApp().m_canvasFont = retData.GetChosenFont();
491 wxGetApp().m_canvasTextColour = retData.GetColour();
492 myCanvas->Refresh();
493 }
494 dialog->Destroy();
495 }
496 #endif // USE_FONTDLG_GENERIC
497
498 #if wxUSE_LOG_DIALOG
499 void MyFrame::LogDialog(wxCommandEvent& WXUNUSED(event))
500 {
501 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
502 // being flushed -- test it
503 {
504 wxBusyCursor bc;
505 wxLogMessage(wxT("This is some message - everything is ok so far."));
506 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
507 wxLogWarning(wxT("And then something went wrong!"));
508
509 // and if ~wxBusyCursor doesn't do it, then call it manually
510 wxYield();
511 }
512
513 wxLogError(wxT("Intermediary error handler decided to abort."));
514 wxLogError(wxT("The top level caller detected an unrecoverable error."));
515
516 wxLog::FlushActive();
517
518 wxLogMessage(wxT("And this is the same dialog but with only one message."));
519 }
520 #endif // wxUSE_LOG_DIALOG
521
522 void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) )
523 {
524 wxMessageDialog dialog( NULL, _T("This is a message box\nA long, long string to test out the message box properly"),
525 _T("Message box text"), wxNO_DEFAULT|wxYES_NO|wxCANCEL|wxICON_INFORMATION);
526
527 switch ( dialog.ShowModal() )
528 {
529 case wxID_YES:
530 wxLogStatus(wxT("You pressed \"Yes\""));
531 break;
532
533 case wxID_NO:
534 wxLogStatus(wxT("You pressed \"No\""));
535 break;
536
537 case wxID_CANCEL:
538 wxLogStatus(wxT("You pressed \"Cancel\""));
539 break;
540
541 default:
542 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
543 }
544 }
545
546 #if wxUSE_NUMBERDLG
547 void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event) )
548 {
549 long res = wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
550 _T("Even two rows of text."),
551 _T("Enter a number:"), _T("Numeric input test"),
552 50, 0, 100, this );
553
554 wxString msg;
555 int icon;
556 if ( res == -1 )
557 {
558 msg = _T("Invalid number entered or dialog cancelled.");
559 icon = wxICON_HAND;
560 }
561 else
562 {
563 msg.Printf(_T("You've entered %lu"), res );
564 icon = wxICON_INFORMATION;
565 }
566
567 wxMessageBox(msg, _T("Numeric test result"), wxOK | icon, this);
568 }
569 #endif // wxUSE_NUMBERDLG
570
571 #if wxUSE_TEXTDLG
572 void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event))
573 {
574 wxString pwd = wxGetPasswordFromUser(_T("Enter password:"),
575 _T("Password entry dialog"),
576 wxEmptyString,
577 this);
578 if ( !pwd.empty() )
579 {
580 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd.c_str()),
581 _T("Got password"), wxOK | wxICON_INFORMATION, this);
582 }
583 }
584
585 void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event))
586 {
587 wxTextEntryDialog dialog(this,
588 _T("This is a small sample\n")
589 _T("A long, long string to test out the text entrybox"),
590 _T("Please enter a string"),
591 _T("Default value"),
592 wxOK | wxCANCEL);
593
594 if (dialog.ShowModal() == wxID_OK)
595 {
596 wxMessageBox(dialog.GetValue(), _T("Got string"), wxOK | wxICON_INFORMATION, this);
597 }
598 }
599 #endif // wxUSE_TEXTDLG
600
601 #if wxUSE_CHOICEDLG
602 void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) )
603 {
604 const wxString choices[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
605
606 wxSingleChoiceDialog dialog(this,
607 _T("This is a small sample\n")
608 _T("A single-choice convenience dialog"),
609 _T("Please select a value"),
610 WXSIZEOF(choices), choices);
611
612 dialog.SetSelection(2);
613
614 if (dialog.ShowModal() == wxID_OK)
615 {
616 wxMessageDialog dialog2(this, dialog.GetStringSelection(), _T("Got string"));
617 dialog2.ShowModal();
618 }
619 }
620
621 void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) )
622 {
623 const wxString choices[] =
624 {
625 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
626 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
627 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
628 };
629
630 wxArrayInt selections;
631 size_t count = wxGetMultipleChoices(selections,
632 _T("This is a small sample\n")
633 _T("A multi-choice convenience dialog"),
634 _T("Please select a value"),
635 WXSIZEOF(choices), choices,
636 this);
637 if ( count )
638 {
639 wxString msg;
640 msg.Printf(wxT("You selected %u items:\n"), (unsigned)count);
641 for ( size_t n = 0; n < count; n++ )
642 {
643 msg += wxString::Format(wxT("\t%u: %u (%s)\n"),
644 (unsigned)n, (unsigned)selections[n],
645 choices[selections[n]].c_str());
646 }
647 wxLogMessage(msg);
648 }
649 //else: cancelled or nothing selected
650 }
651 #endif // wxUSE_CHOICEDLG
652
653 #if wxUSE_FILEDLG
654 void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
655 {
656 wxFileDialog dialog
657 (
658 this,
659 _T("Testing open file dialog"),
660 wxEmptyString,
661 wxEmptyString,
662 #ifdef __WXMOTIF__
663 _T("C++ files (*.cpp)|*.cpp")
664 #else
665 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
666 #endif
667 );
668
669 dialog.SetDirectory(wxGetHomeDir());
670
671 if (dialog.ShowModal() == wxID_OK)
672 {
673 wxString info;
674 info.Printf(_T("Full file name: %s\n")
675 _T("Path: %s\n")
676 _T("Name: %s"),
677 dialog.GetPath().c_str(),
678 dialog.GetDirectory().c_str(),
679 dialog.GetFilename().c_str());
680 wxMessageDialog dialog2(this, info, _T("Selected file"));
681 dialog2.ShowModal();
682 }
683 }
684
685 // this shows how to take advantage of specifying a default extension in the
686 // call to wxFileSelector: it is remembered after each new call and the next
687 // one will use it by default
688 void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) )
689 {
690 static wxString s_extDef;
691 wxString path = wxFileSelector(
692 _T("Select the file to load"),
693 wxEmptyString, wxEmptyString,
694 s_extDef,
695 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
696 wxCHANGE_DIR,
697 this
698 );
699
700 if ( !path )
701 return;
702
703 // it is just a sample, would use wxSplitPath in real program
704 s_extDef = path.AfterLast(_T('.'));
705
706 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
707 (const wxChar*) path, (const wxChar*) s_extDef);
708 }
709
710 void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) )
711 {
712 wxString wildcards =
713 #ifdef __WXMOTIF__
714 _T("C++ files (*.cpp)|*.cpp");
715 #else
716 _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
717 #endif
718 wxFileDialog dialog(this, _T("Testing open multiple file dialog"),
719 wxEmptyString, wxEmptyString, wildcards,
720 wxMULTIPLE);
721
722 if (dialog.ShowModal() == wxID_OK)
723 {
724 wxArrayString paths, filenames;
725
726 dialog.GetPaths(paths);
727 dialog.GetFilenames(filenames);
728
729 wxString msg, s;
730 size_t count = paths.GetCount();
731 for ( size_t n = 0; n < count; n++ )
732 {
733 s.Printf(_T("File %d: %s (%s)\n"),
734 (int)n, paths[n].c_str(), filenames[n].c_str());
735
736 msg += s;
737 }
738 s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex());
739 msg += s;
740
741 wxMessageDialog dialog2(this, msg, _T("Selected files"));
742 dialog2.ShowModal();
743 }
744 }
745
746 void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) )
747 {
748 wxFileDialog dialog(this,
749 _T("Testing save file dialog"),
750 wxEmptyString,
751 _T("myletter.doc"),
752 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
753 wxSAVE|wxOVERWRITE_PROMPT);
754
755 dialog.SetFilterIndex(1);
756
757 if (dialog.ShowModal() == wxID_OK)
758 {
759 wxLogMessage(_T("%s, filter %d"),
760 dialog.GetPath().c_str(), dialog.GetFilterIndex());
761 }
762 }
763 #endif // wxUSE_FILEDLG
764
765 #if USE_FILEDLG_GENERIC
766 void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) )
767 {
768 wxGenericFileDialog dialog
769 (
770 this,
771 _T("Testing open file dialog"),
772 wxEmptyString,
773 wxEmptyString,
774 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
775 );
776
777 dialog.SetDirectory(wxGetHomeDir());
778
779 if (dialog.ShowModal() == wxID_OK)
780 {
781 wxString info;
782 info.Printf(_T("Full file name: %s\n")
783 _T("Path: %s\n")
784 _T("Name: %s"),
785 dialog.GetPath().c_str(),
786 dialog.GetDirectory().c_str(),
787 dialog.GetFilename().c_str());
788 wxMessageDialog dialog2(this, info, _T("Selected file"));
789 dialog2.ShowModal();
790 }
791 }
792
793 void MyFrame::FilesOpenGeneric(wxCommandEvent& WXUNUSED(event) )
794 {
795 wxString wildcards = _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
796 wxGenericFileDialog dialog(this, _T("Testing open multiple file dialog"),
797 wxEmptyString, wxEmptyString, wildcards,
798 wxMULTIPLE);
799
800 if (dialog.ShowModal() == wxID_OK)
801 {
802 wxArrayString paths, filenames;
803
804 dialog.GetPaths(paths);
805 dialog.GetFilenames(filenames);
806
807 wxString msg, s;
808 size_t count = paths.GetCount();
809 for ( size_t n = 0; n < count; n++ )
810 {
811 s.Printf(_T("File %d: %s (%s)\n"),
812 (int)n, paths[n].c_str(), filenames[n].c_str());
813
814 msg += s;
815 }
816 s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex());
817 msg += s;
818
819 wxMessageDialog dialog2(this, msg, _T("Selected files"));
820 dialog2.ShowModal();
821 }
822 }
823
824 void MyFrame::FileSaveGeneric(wxCommandEvent& WXUNUSED(event) )
825 {
826 wxGenericFileDialog dialog(this,
827 _T("Testing save file dialog"),
828 wxEmptyString,
829 _T("myletter.doc"),
830 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
831 wxSAVE|wxOVERWRITE_PROMPT);
832
833 dialog.SetFilterIndex(1);
834
835 if (dialog.ShowModal() == wxID_OK)
836 {
837 wxLogMessage(_T("%s, filter %d"),
838 dialog.GetPath().c_str(), dialog.GetFilterIndex());
839 }
840 }
841 #endif // USE_FILEDLG_GENERIC
842
843 #if wxUSE_DIRDLG
844 void MyFrame::DoDirChoose(int style)
845 {
846 // pass some initial dir to wxDirDialog
847 wxString dirHome;
848 wxGetHomeDir(&dirHome);
849
850 wxDirDialog dialog(this, _T("Testing directory picker"), dirHome, style);
851
852 if (dialog.ShowModal() == wxID_OK)
853 {
854 wxLogMessage(_T("Selected path: %s"), dialog.GetPath().c_str());
855 }
856 }
857
858 void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) )
859 {
860 DoDirChoose(wxDD_DEFAULT_STYLE & ~wxDD_NEW_DIR_BUTTON);
861 }
862
863 void MyFrame::DirChooseNew(wxCommandEvent& WXUNUSED(event) )
864 {
865 DoDirChoose(wxDD_DEFAULT_STYLE | wxDD_NEW_DIR_BUTTON);
866 }
867 #endif // wxUSE_DIRDLG
868
869 #if USE_DIRDLG_GENERIC
870 void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) )
871 {
872 // pass some initial dir to wxDirDialog
873 wxString dirHome;
874 wxGetHomeDir(&dirHome);
875
876 wxGenericDirDialog dialog(this, _T("Testing generic directory picker"), dirHome);
877
878 if (dialog.ShowModal() == wxID_OK)
879 {
880 wxMessageDialog dialog2(this, dialog.GetPath(), _T("Selected path"));
881 dialog2.ShowModal();
882 }
883 }
884 #endif // USE_DIRDLG_GENERIC
885
886 #if USE_MODAL_PRESENTATION
887 void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event))
888 {
889 MyModalDialog dlg(this);
890 dlg.ShowModal();
891 }
892
893 void MyFrame::ModelessDlg(wxCommandEvent& event)
894 {
895 bool show = GetMenuBar()->IsChecked(event.GetId());
896
897 if ( show )
898 {
899 if ( !m_dialog )
900 {
901 m_dialog = new MyModelessDialog(this);
902 }
903
904 m_dialog->Show(true);
905 }
906 else // hide
907 {
908 // If m_dialog is NULL, then possibly the system
909 // didn't report the checked menu item status correctly.
910 // It should be true just after the menu item was selected,
911 // if there was no modeless dialog yet.
912
913 wxASSERT( m_dialog != NULL );
914 if (m_dialog)
915 m_dialog->Hide();
916 }
917 }
918 #endif // USE_MODAL_PRESENTATION
919
920 #if wxUSE_STARTUP_TIPS
921 void MyFrame::ShowTip(wxCommandEvent& WXUNUSED(event))
922 {
923 static size_t s_index = (size_t)-1;
924
925 if ( s_index == (size_t)-1 )
926 {
927 srand(time(NULL));
928
929 // this is completely bogus, we don't know how many lines are there
930 // in the file, but who cares, it's a demo only...
931 s_index = rand() % 5;
932 }
933
934 wxTipProvider *tipProvider = wxCreateFileTipProvider(_T("tips.txt"), s_index);
935
936 bool showAtStartup = wxShowTip(this, tipProvider);
937
938 if ( showAtStartup )
939 {
940 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
941 wxOK | wxICON_INFORMATION, this);
942 }
943
944 s_index = tipProvider->GetCurrentTip();
945 delete tipProvider;
946 }
947 #endif // wxUSE_STARTUP_TIPS
948
949 void MyFrame::OnRequestUserAttention(wxCommandEvent& WXUNUSED(event))
950 {
951 wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window"));
952
953 wxSleep(3);
954
955 RequestUserAttention(wxUSER_ATTENTION_ERROR);
956 }
957
958 void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) )
959 {
960 Close(true);
961 }
962
963 #if wxUSE_PROGRESSDLG
964
965 void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
966 {
967 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
968 // check the performance
969 int countrandomnumbers = 0, count = 0;
970 wxTimeSpan tsTest(0,0,0,250);
971 wxDateTime DT2, DT1 = wxDateTime::UNow();
972 srand(0);
973 while(1)
974 {
975 rand();
976 ++countrandomnumbers;
977 if ( countrandomnumbers == 1000 )
978 {
979 srand(0);
980 countrandomnumbers = 0;
981 ++count;
982 DT2 = wxDateTime::UNow();
983 wxTimeSpan ts = DT2.Subtract( DT1 );
984 if ( ts.IsLongerThan( tsTest ) )
985 {
986 break;
987 }
988 }
989 }
990 const int max = 40 * count;
991 #else
992 static const int max = 10;
993 #endif // wxUSE_STOPWATCH && wxUSE_LONGLONG
994
995 wxProgressDialog dialog(_T("Progress dialog example"),
996 _T("An informative message"),
997 max, // range
998 this, // parent
999 wxPD_CAN_ABORT |
1000 wxPD_CAN_SKIP |
1001 wxPD_APP_MODAL |
1002 // wxPD_AUTO_HIDE | -- try this as well
1003 wxPD_ELAPSED_TIME |
1004 wxPD_ESTIMATED_TIME |
1005 wxPD_REMAINING_TIME |
1006 wxPD_SMOOTH);
1007
1008 bool cont = true;
1009 bool skip = false;
1010 // each skip will move progress about quarter forward
1011 for ( int i = 0; i <= max; i = wxMin(i+(skip?int(max/4):1), max+1), skip = false )
1012 {
1013 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
1014 // do (almost) the same operations as we did for the performance test
1015 srand(0);
1016 for ( int j = 0; j < 1000; j++ )
1017 {
1018 rand();
1019 if ( j == 999 )
1020 {
1021 DT2 = wxDateTime::UNow();
1022 wxTimeSpan ts = DT2.Subtract( DT1 );
1023 if ( ts.IsLongerThan( tsTest ) )
1024 {
1025 // nothing to do
1026 }
1027 }
1028 }
1029 #else
1030 wxSleep(1);
1031 #endif
1032
1033 wxString msg;
1034
1035 if ( i == max )
1036 {
1037 msg = _T("That's all, folks!");
1038 }
1039 else if ( i > max / 2 )
1040 {
1041 msg = _T("Only a half left (very long message)!");
1042 }
1043
1044 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
1045 if ( (i % (max/100)) == 0 ) // // only 100 updates, this makes it much faster
1046 {
1047 cont = dialog.Update(i, msg, &skip);
1048 }
1049 #else
1050 cont = dialog.Update(i, msg, &skip);
1051 #endif
1052
1053 if ( !cont )
1054 {
1055 if ( wxMessageBox(_T("Do you really want to cancel?"),
1056 _T("Progress dialog question"), // caption
1057 wxYES_NO | wxICON_QUESTION) == wxYES )
1058 break;
1059
1060 cont = true;
1061 dialog.Resume();
1062 }
1063 }
1064
1065 if ( !cont )
1066 {
1067 wxLogStatus(wxT("Progress dialog aborted!"));
1068 }
1069 else
1070 {
1071 wxLogStatus(wxT("Countdown from %d finished"), max);
1072 }
1073 }
1074
1075 #endif // wxUSE_PROGRESSDLG
1076
1077 #if wxUSE_BUSYINFO
1078
1079 void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event))
1080 {
1081 wxWindowDisabler disableAll;
1082
1083 wxBusyInfo info(_T("Working, please wait..."), this);
1084
1085 for ( int i = 0; i < 18; i++ )
1086 {
1087 //wxUsleep(100);
1088 wxTheApp->Yield();
1089 }
1090
1091 wxSleep(2);
1092 //wxWakeUpIdle();
1093 }
1094
1095 #endif // wxUSE_BUSYINFO
1096
1097 #if wxUSE_FINDREPLDLG
1098
1099 void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) )
1100 {
1101 if ( m_dlgReplace )
1102 {
1103 delete m_dlgReplace;
1104 m_dlgReplace = NULL;
1105 }
1106 else
1107 {
1108 m_dlgReplace = new wxFindReplaceDialog
1109 (
1110 this,
1111 &m_findData,
1112 _T("Find and replace dialog"),
1113 wxFR_REPLACEDIALOG
1114 );
1115
1116 m_dlgReplace->Show(true);
1117 }
1118 }
1119
1120 void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) )
1121 {
1122 if ( m_dlgFind )
1123 {
1124 delete m_dlgFind;
1125 m_dlgFind = NULL;
1126 }
1127 else
1128 {
1129 m_dlgFind = new wxFindReplaceDialog
1130 (
1131 this,
1132 &m_findData,
1133 _T("Find dialog"),
1134 // just for testing
1135 wxFR_NOWHOLEWORD
1136 );
1137
1138 m_dlgFind->Show(true);
1139 }
1140 }
1141
1142 static wxString DecodeFindDialogEventFlags(int flags)
1143 {
1144 wxString str;
1145 str << (flags & wxFR_DOWN ? _T("down") : _T("up")) << _T(", ")
1146 << (flags & wxFR_WHOLEWORD ? _T("whole words only, ") : _T(""))
1147 << (flags & wxFR_MATCHCASE ? _T("") : _T("not "))
1148 << _T("case sensitive");
1149
1150 return str;
1151 }
1152
1153 void MyFrame::OnFindDialog(wxFindDialogEvent& event)
1154 {
1155 wxEventType type = event.GetEventType();
1156
1157 if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT )
1158 {
1159 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1160 type == wxEVT_COMMAND_FIND_NEXT ? wxT("next ") : wxT(""),
1161 event.GetFindString().c_str(),
1162 DecodeFindDialogEventFlags(event.GetFlags()).c_str());
1163 }
1164 else if ( type == wxEVT_COMMAND_FIND_REPLACE ||
1165 type == wxEVT_COMMAND_FIND_REPLACE_ALL )
1166 {
1167 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1168 type == wxEVT_COMMAND_FIND_REPLACE_ALL ? _T("all ") : wxT(""),
1169 event.GetFindString().c_str(),
1170 event.GetReplaceString().c_str(),
1171 DecodeFindDialogEventFlags(event.GetFlags()).c_str());
1172 }
1173 else if ( type == wxEVT_COMMAND_FIND_CLOSE )
1174 {
1175 wxFindReplaceDialog *dlg = event.GetDialog();
1176
1177 int idMenu;
1178 const wxChar *txt;
1179 if ( dlg == m_dlgFind )
1180 {
1181 txt = _T("Find");
1182 idMenu = DIALOGS_FIND;
1183 m_dlgFind = NULL;
1184 }
1185 else if ( dlg == m_dlgReplace )
1186 {
1187 txt = _T("Replace");
1188 idMenu = DIALOGS_REPLACE;
1189 m_dlgReplace = NULL;
1190 }
1191 else
1192 {
1193 txt = _T("Unknown");
1194 idMenu = wxID_ANY;
1195
1196 wxFAIL_MSG( _T("unexpected event") );
1197 }
1198
1199 wxLogMessage(wxT("%s dialog is being closed."), txt);
1200
1201 if ( idMenu != wxID_ANY )
1202 {
1203 GetMenuBar()->Check(idMenu, false);
1204 }
1205
1206 dlg->Destroy();
1207 }
1208 else
1209 {
1210 wxLogError(wxT("Unknown find dialog event!"));
1211 }
1212 }
1213
1214 #endif // wxUSE_FINDREPLDLG
1215
1216 // ----------------------------------------------------------------------------
1217 // MyCanvas
1218 // ----------------------------------------------------------------------------
1219
1220 void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
1221 {
1222 wxPaintDC dc(this);
1223 dc.SetFont(wxGetApp().m_canvasFont);
1224 dc.SetTextForeground(wxGetApp().m_canvasTextColour);
1225 dc.SetBackgroundMode(wxTRANSPARENT);
1226 dc.DrawText(
1227 _T("wxWidgets common dialogs")
1228 #if !defined(__SMARTPHONE__)
1229 _T(" test application")
1230 #endif
1231 , 10, 10);
1232 }
1233
1234 #if USE_MODAL_PRESENTATION
1235
1236 // ----------------------------------------------------------------------------
1237 // MyModelessDialog
1238 // ----------------------------------------------------------------------------
1239
1240 MyModelessDialog::MyModelessDialog(wxWindow *parent)
1241 : wxDialog(parent, wxID_ANY, wxString(_T("Modeless dialog")))
1242 {
1243 wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
1244
1245 wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, _T("Press me"));
1246 wxCheckBox *check = new wxCheckBox(this, wxID_ANY, _T("Should be disabled"));
1247 check->Disable();
1248
1249 sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5);
1250 sizerTop->Add(check, 1, wxEXPAND | wxALL, 5);
1251
1252 SetSizer(sizerTop);
1253
1254 sizerTop->SetSizeHints(this);
1255 sizerTop->Fit(this);
1256 }
1257
1258 void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event))
1259 {
1260 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1261 wxOK | wxICON_INFORMATION, this);
1262 }
1263
1264 void MyModelessDialog::OnClose(wxCloseEvent& event)
1265 {
1266 if ( event.CanVeto() )
1267 {
1268 wxMessageBox(_T("Use the menu item to close this dialog"),
1269 _T("Modeless dialog"),
1270 wxOK | wxICON_INFORMATION, this);
1271
1272 event.Veto();
1273 }
1274 }
1275
1276 // ----------------------------------------------------------------------------
1277 // MyModalDialog
1278 // ----------------------------------------------------------------------------
1279
1280 MyModalDialog::MyModalDialog(wxWindow *parent)
1281 : wxDialog(parent, wxID_ANY, wxString(_T("Modal dialog")))
1282 {
1283 wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
1284
1285 m_btnModal = new wxButton(this, wxID_ANY, _T("&Modal dialog..."));
1286 m_btnModeless = new wxButton(this, wxID_ANY, _T("Mode&less dialog"));
1287 m_btnDelete = new wxButton(this, wxID_ANY, _T("&Delete button"));
1288
1289 wxButton *btnOk = new wxButton(this, wxID_CANCEL, _T("&Close"));
1290 sizerTop->Add(m_btnModal, 0, wxALIGN_CENTER | wxALL, 5);
1291 sizerTop->Add(m_btnModeless, 0, wxALIGN_CENTER | wxALL, 5);
1292 sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5);
1293 sizerTop->Add(btnOk, 0, wxALIGN_CENTER | wxALL, 5);
1294
1295 SetSizer(sizerTop);
1296
1297 sizerTop->SetSizeHints(this);
1298 sizerTop->Fit(this);
1299
1300 m_btnModal->SetFocus();
1301 m_btnModal->SetDefault();
1302 }
1303
1304 void MyModalDialog::OnButton(wxCommandEvent& event)
1305 {
1306 if ( event.GetEventObject() == m_btnDelete )
1307 {
1308 delete m_btnModal;
1309 m_btnModal = NULL;
1310
1311 m_btnDelete->Disable();
1312 }
1313 else if ( event.GetEventObject() == m_btnModal )
1314 {
1315 #if wxUSE_TEXTDLG
1316 wxGetTextFromUser(_T("Dummy prompt"),
1317 _T("Modal dialog called from dialog"),
1318 wxEmptyString, this);
1319 #else
1320 wxMessageBox(_T("Modal dialog called from dialog"));
1321 #endif // wxUSE_TEXTDLG
1322 }
1323 else if ( event.GetEventObject() == m_btnModeless )
1324 {
1325 (new MyModelessDialog(this))->Show();
1326 }
1327 else
1328 {
1329 event.Skip();
1330 }
1331 }
1332
1333 #endif // USE_MODAL_PRESENTATION
1334