added wxGetMultiChoice() (which refuses to work for some reason - will fix
[wxWidgets.git] / samples / dialogs / dialogs.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dialogs.cpp
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
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/colordlg.h"
29 #include "wx/filedlg.h"
30 #include "wx/dirdlg.h"
31 #include "wx/fontdlg.h"
32 #include "wx/choicdlg.h"
33 #include "wx/tipdlg.h"
34 #include "wx/progdlg.h"
35
36 // New wxGenericDirCtrl
37 #include "wx/dirctrl.h"
38
39 #define wxTEST_GENERIC_DIALOGS_IN_MSW 0
40
41 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
42 #include <wx/generic/colrdlgg.h>
43 #include <wx/generic/fontdlgg.h>
44 #endif
45
46 #include "dialogs.h"
47
48 IMPLEMENT_APP(MyApp)
49
50 BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
51 EVT_PAINT(MyCanvas::OnPaint)
52 END_EVENT_TABLE()
53
54 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
55 EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour)
56 EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont)
57 EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog)
58 EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox)
59 EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry)
60 EVT_MENU(DIALOGS_PASSWORD_ENTRY, MyFrame::PasswordEntry)
61 EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry)
62 EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice)
63 EVT_MENU(DIALOGS_MULTI_CHOICE, MyFrame::MultiChoice)
64 EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen)
65 EVT_MENU(DIALOGS_FILE_OPEN2, MyFrame::FileOpen2)
66 EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen)
67 EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave)
68 EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose)
69 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE, MyFrame::GenericDirChoose)
70 EVT_MENU(DIALOGS_MODAL, MyFrame::ModalDlg)
71 EVT_MENU(DIALOGS_MODELESS, MyFrame::ModelessDlg)
72 EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip)
73 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
74 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric)
75 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric)
76 #endif
77 #if wxUSE_PROGRESSDLG
78 EVT_MENU(DIALOGS_PROGRESS, MyFrame::ShowProgress)
79 #endif
80 EVT_MENU(wxID_EXIT, MyFrame::OnExit)
81
82 EVT_BUTTON(DIALOGS_MODELESS_BTN, MyFrame::OnButton)
83 END_EVENT_TABLE()
84
85 BEGIN_EVENT_TABLE(MyModalDialog, wxDialog)
86 EVT_BUTTON(-1, MyModalDialog::OnButton)
87 END_EVENT_TABLE()
88
89 BEGIN_EVENT_TABLE(MyModelessDialog, wxDialog)
90 EVT_CLOSE(MyModelessDialog::OnClose)
91 END_EVENT_TABLE()
92
93 MyCanvas *myCanvas = (MyCanvas *) NULL;
94
95 // `Main program' equivalent, creating windows and returning main app frame
96 bool MyApp::OnInit()
97 {
98 #if defined(__WXGTK__) && defined(wxUSE_UNICODE)
99 wxConvCurrent = &wxConvLibc;
100 #endif
101
102 m_canvasTextColour = wxColour("BLACK");
103 m_canvasFont = *wxNORMAL_FONT;
104
105 // Create the main frame window
106 MyFrame *frame = new MyFrame((wxFrame *) NULL, (char *) "wxWindows dialogs example", wxPoint(20, 20), wxSize(400, 300));
107
108 // Make a menubar
109 wxMenu *file_menu = new wxMenu;
110
111 file_menu->Append(DIALOGS_CHOOSE_COLOUR, "&Choose colour");
112
113 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
114 file_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, "Choose colour (&generic)");
115 #endif
116
117 file_menu->AppendSeparator();
118 file_menu->Append(DIALOGS_CHOOSE_FONT, "Choose &font");
119
120 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
121 file_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, "Choose f&ont (generic)");
122
123 #endif
124 file_menu->AppendSeparator();
125 file_menu->Append(DIALOGS_LOG_DIALOG, "&Log dialog\tCtrl-L");
126 file_menu->Append(DIALOGS_MESSAGE_BOX, "&Message box\tCtrl-M");
127 file_menu->Append(DIALOGS_TEXT_ENTRY, "Text &entry\tCtrl-E");
128 file_menu->Append(DIALOGS_PASSWORD_ENTRY, "&Password entry\tCtrl-P");
129 file_menu->Append(DIALOGS_NUM_ENTRY, "&Numeric entry\tCtrl-N");
130 file_menu->Append(DIALOGS_SINGLE_CHOICE, "&Single choice\tCtrl-C");
131 file_menu->Append(DIALOGS_MULTI_CHOICE, "M&ultiple choice\tCtrl-U");
132 file_menu->AppendSeparator();
133 file_menu->Append(DIALOGS_TIP, "&Tip of the day\tCtrl-T");
134 file_menu->AppendSeparator();
135 file_menu->Append(DIALOGS_FILE_OPEN, "&Open file\tCtrl-O");
136 file_menu->Append(DIALOGS_FILE_OPEN2, "&Second open file\tCtrl-2");
137 file_menu->Append(DIALOGS_FILES_OPEN, "Open &files\tCtrl-Q");
138 file_menu->Append(DIALOGS_FILE_SAVE, "Sa&ve file\tCtrl-S");
139 file_menu->Append(DIALOGS_DIR_CHOOSE, "&Choose a directory\tCtrl-D");
140 file_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE, "&Choose a directory (generic implementation)");
141 #if wxUSE_PROGRESSDLG
142 file_menu->Append(DIALOGS_PROGRESS, "Pro&gress dialog\tCtrl-G");
143 #endif // wxUSE_PROGRESSDLG
144 file_menu->AppendSeparator();
145 file_menu->Append(DIALOGS_MODAL, "Mo&dal dialog\tCtrl-F");
146 file_menu->Append(DIALOGS_MODELESS, "Modeless &dialog\tCtrl-Z", "", TRUE);
147 file_menu->AppendSeparator();
148 file_menu->Append(wxID_EXIT, "E&xit\tAlt-X");
149 wxMenuBar *menu_bar = new wxMenuBar;
150 menu_bar->Append(file_menu, "&File");
151 frame->SetMenuBar(menu_bar);
152
153 myCanvas = new MyCanvas(frame);
154 myCanvas->SetBackgroundColour(*wxWHITE);
155
156 frame->Centre(wxBOTH);
157
158 // Show the frame
159 frame->Show(TRUE);
160
161 SetTopWindow(frame);
162
163 return TRUE;
164 }
165
166 // My frame constructor
167 MyFrame::MyFrame(wxWindow *parent,
168 const wxString& title,
169 const wxPoint& pos,
170 const wxSize& size)
171 : wxFrame(parent, -1, title, pos, size)
172 {
173 m_dialog = (MyModelessDialog *)NULL;
174 }
175
176 void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event) )
177 {
178 wxColourData data;
179 data.SetChooseFull(TRUE);
180 for (int i = 0; i < 16; i++)
181 {
182 wxColour colour(i*16, i*16, i*16);
183 data.SetCustomColour(i, colour);
184 }
185
186 wxColourDialog *dialog = new wxColourDialog(this, &data);
187 dialog->SetTitle("Choose the background colour");
188 if (dialog->ShowModal() == wxID_OK)
189 {
190 wxColourData retData = dialog->GetColourData();
191 wxColour col = retData.GetColour();
192 myCanvas->SetBackgroundColour(col);
193 myCanvas->Clear();
194 myCanvas->Refresh();
195 }
196 dialog->Destroy();
197 }
198
199 void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
200 {
201 wxFontData data;
202 data.SetInitialFont(wxGetApp().m_canvasFont);
203 data.SetColour(wxGetApp().m_canvasTextColour);
204
205 wxFontDialog *dialog = new wxFontDialog(this, &data);
206 if (dialog->ShowModal() == wxID_OK)
207 {
208 wxFontData retData = dialog->GetFontData();
209 wxGetApp().m_canvasFont = retData.GetChosenFont();
210 wxGetApp().m_canvasTextColour = retData.GetColour();
211 myCanvas->Refresh();
212 }
213 dialog->Destroy();
214 }
215
216 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
217 void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event))
218 {
219 wxColourData data;
220 data.SetChooseFull(TRUE);
221 for (int i = 0; i < 16; i++)
222 {
223 wxColour colour(i*16, i*16, i*16);
224 data.SetCustomColour(i, colour);
225 }
226
227 wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &data);
228 if (dialog->ShowModal() == wxID_OK)
229 {
230 wxColourData retData = dialog->GetColourData();
231 wxColour col = retData.GetColour();
232 // wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
233 myCanvas->SetBackgroundColour(col);
234 myCanvas->Clear();
235 myCanvas->Refresh();
236 }
237 dialog->Destroy();
238 }
239
240 void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) )
241 {
242 wxFontData data;
243 data.SetInitialFont(wxGetApp().m_canvasFont);
244 data.SetColour(wxGetApp().m_canvasTextColour);
245
246 wxGenericFontDialog *dialog = new wxGenericFontDialog(this, &data);
247 if (dialog->ShowModal() == wxID_OK)
248 {
249 wxFontData retData = dialog->GetFontData();
250 wxGetApp().m_canvasFont = retData.GetChosenFont();
251 wxGetApp().m_canvasTextColour = retData.GetColour();
252 myCanvas->Refresh();
253 }
254 dialog->Destroy();
255 }
256 #endif // wxTEST_GENERIC_DIALOGS_IN_MSW
257
258 void MyFrame::LogDialog(wxCommandEvent& event)
259 {
260 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
261 // being flushed -- test it
262 {
263 wxBusyCursor bc;
264 wxLogMessage("This is some message - everything is ok so far.");
265 wxLogMessage("Another message...\n... this one is on multiple lines");
266 wxLogWarning("And then something went wrong!");
267 }
268
269 wxLogError("Intermediary error handler decided to abort.");
270 wxLogError("The top level caller detected an unrecoverable error.");
271
272 wxLog::FlushActive();
273
274 wxLogMessage("And this is the same dialog but with only one message.");
275 }
276
277 void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) )
278 {
279 wxMessageDialog dialog( NULL, "This is a message box\nA long, long string to test out the message box properly",
280 "Message box text", wxYES_NO|wxCANCEL|wxICON_INFORMATION);
281
282 dialog.ShowModal();
283 }
284
285 void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event) )
286 {
287 long res = wxGetNumberFromUser( "This is some text, actually a lot of text.\n"
288 "Even two rows of text.",
289 "Enter a number:", "Numeric input test",
290 50, 0, 100, this );
291
292 wxString msg;
293 int icon;
294 if ( res == -1 )
295 {
296 msg = "Invalid number entered or dialog cancelled.";
297 icon = wxICON_HAND;
298 }
299 else
300 {
301 msg.Printf(_T("You've entered %lu"), res );
302 icon = wxICON_INFORMATION;
303 }
304
305 wxMessageBox(msg, "Numeric test result", wxOK | icon, this);
306 }
307
308 void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event))
309 {
310 wxString pwd = wxGetPasswordFromUser("Enter password:",
311 "Password entry dialog",
312 "",
313 this);
314 if ( !!pwd )
315 {
316 wxMessageBox(wxString::Format("Your password is '%s'", pwd.c_str()),
317 "Got password", wxOK | wxICON_INFORMATION, this);
318 }
319 }
320
321 void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event))
322 {
323 wxTextEntryDialog dialog(this,
324 "This is a small sample\n"
325 "A long, long string to test out the text entrybox",
326 "Please enter a string",
327 "Default value",
328 wxOK | wxCANCEL);
329
330 if (dialog.ShowModal() == wxID_OK)
331 {
332 wxMessageDialog dialog2(this, dialog.GetValue(), "Got string");
333 dialog2.ShowModal();
334 }
335 }
336
337 void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) )
338 {
339 const wxString choices[] = { "One", "Two", "Three", "Four", "Five" } ;
340 int n = 5;
341
342 wxSingleChoiceDialog dialog(this, "This is a small sample\nA single-choice convenience dialog",
343 "Please select a value", n, (const wxString *)choices);
344
345 dialog.SetSelection(2);
346
347 if (dialog.ShowModal() == wxID_OK)
348 {
349 wxMessageDialog dialog2(this, dialog.GetStringSelection(), "Got string");
350 dialog2.ShowModal();
351 }
352 }
353
354 void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) )
355 {
356 const wxString choices[] = { "One", "Two", "Three", "Four", "Five" } ;
357 int n = 5;
358
359 wxArrayInt selections;
360 size_t count = wxGetMultipleChoices(selections,
361 "This is a small sample\n"
362 "A multi-choice convenience dialog",
363 "Please select a value",
364 n, (const wxString *)choices,
365 this);
366 if ( count )
367 {
368 wxLogMessage("You selected %u items:", count);
369 for ( size_t n = 0; n < count; n++ )
370 {
371 wxLogMessage("\t%u: %u (%s)", n, selections[n],
372 choices[selections[n]].c_str());
373 }
374 }
375 //else: cancelled or nothing selected
376 }
377
378 void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
379 {
380 wxFileDialog dialog(this, "Testing open file dialog", "", "", "*.txt", 0);
381
382 if (dialog.ShowModal() == wxID_OK)
383 {
384 wxString info;
385 info.Printf(_T("Full file name: %s\n")
386 _T("Path: %s\n")
387 _T("Name: %s"),
388 dialog.GetPath().c_str(),
389 dialog.GetDirectory().c_str(),
390 dialog.GetFilename().c_str());
391 wxMessageDialog dialog2(this, info, "Selected file");
392 dialog2.ShowModal();
393 }
394 }
395
396 // this shows how to take advantage of specifying a default extension in the
397 // call to wxFileSelector: it is remembered after each new call and the next
398 // one will use it by default
399 void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) )
400 {
401 static wxString s_extDef;
402 wxString path = wxFileSelector(
403 _T("Select the file to load"),
404 _T(""), _T(""),
405 s_extDef,
406 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
407 0,
408 this
409 );
410
411 if ( !path )
412 return;
413
414 // it is just a sample, would use wxSplitPath in real program
415 s_extDef = path.AfterLast(_T('.'));
416
417 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
418 (const wxChar*) path, (const wxChar*) s_extDef);
419 }
420
421 void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) )
422 {
423 wxFileDialog dialog(this, "Testing open multiple file dialog",
424 "", "", wxFileSelectorDefaultWildcardStr,
425 wxMULTIPLE);
426
427 if (dialog.ShowModal() == wxID_OK)
428 {
429 wxArrayString paths, filenames;
430
431 dialog.GetPaths(paths);
432 dialog.GetFilenames(filenames);
433
434 wxString msg, s;
435 size_t count = paths.GetCount();
436 for ( size_t n = 0; n < count; n++ )
437 {
438 s.Printf(_T("File %d: %s (%s)\n"),
439 n, paths[n].c_str(), filenames[n].c_str());
440
441 msg += s;
442 }
443
444 wxMessageDialog dialog2(this, msg, "Selected files");
445 dialog2.ShowModal();
446 }
447 }
448
449 void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) )
450 {
451 wxFileDialog dialog(this, "Testing save file dialog", "", "myletter.txt",
452 "Text files (*.txt)|*.txt|Document files (*.doc)|*.doc",
453 wxSAVE|wxOVERWRITE_PROMPT);
454
455 if (dialog.ShowModal() == wxID_OK)
456 {
457 wxChar buf[400];
458 wxSprintf(buf, _T("%s, filter %d"), (const wxChar*)dialog.GetPath(), dialog.GetFilterIndex());
459 wxMessageDialog dialog2(this, wxString(buf), "Selected path");
460 dialog2.ShowModal();
461 }
462 }
463
464 void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) )
465 {
466 // pass some initial dir to wxDirDialog
467 wxString dirHome;
468 wxGetHomeDir(&dirHome);
469
470 wxDirDialog dialog(this, "Testing directory picker", dirHome);
471
472 if (dialog.ShowModal() == wxID_OK)
473 {
474 wxMessageDialog dialog2(this, dialog.GetPath(), "Selected path");
475 dialog2.ShowModal();
476 }
477 }
478
479 void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) )
480 {
481 // pass some initial dir to wxDirDialog
482 wxString dirHome;
483 wxGetHomeDir(&dirHome);
484
485 wxGenericDirDialog dialog(this, "Testing generic directory picker", dirHome);
486
487 if (dialog.ShowModal() == wxID_OK)
488 {
489 wxMessageDialog dialog2(this, dialog.GetPath(), "Selected path");
490 dialog2.ShowModal();
491 }
492 }
493
494 void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event))
495 {
496 MyModalDialog dlg(this);
497 dlg.ShowModal();
498 }
499
500 void MyFrame::ModelessDlg(wxCommandEvent& event)
501 {
502 bool show = GetMenuBar()->IsChecked(event.GetId());
503
504 if ( show )
505 {
506 if ( !m_dialog )
507 {
508 m_dialog = new MyModelessDialog(this);
509 }
510
511 m_dialog->Show(TRUE);
512 }
513 else // hide
514 {
515 m_dialog->Hide();
516 }
517 }
518
519 void MyFrame::OnButton(wxCommandEvent& WXUNUSED(event))
520 {
521 wxMessageBox("Button pressed in modeless dialog", "Info",
522 wxOK | wxICON_INFORMATION, this);
523 }
524
525 void MyFrame::ShowTip(wxCommandEvent& event)
526 {
527 #if wxUSE_STARTUP_TIPS
528 static size_t s_index = (size_t)-1;
529
530 if ( s_index == (size_t)-1 )
531 {
532 srand(time(NULL));
533
534 // this is completely bogus, we don't know how many lines are there
535 // in the file, but who cares, it's a demo only...
536 s_index = rand() % 5;
537 }
538
539 wxTipProvider *tipProvider = wxCreateFileTipProvider("tips.txt", s_index);
540
541 bool showAtStartup = wxShowTip(this, tipProvider);
542
543 if ( showAtStartup )
544 {
545 wxMessageBox("Will show tips on startup", "Tips dialog",
546 wxOK | wxICON_INFORMATION, this);
547 }
548
549 s_index = tipProvider->GetCurrentTip();
550 delete tipProvider;
551 #endif
552 }
553
554 void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) )
555 {
556 Close(TRUE);
557 }
558
559 #if wxUSE_PROGRESSDLG
560
561 void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
562 {
563 static const int max = 10;
564
565 wxProgressDialog dialog("Progress dialog example",
566 "An informative message",
567 max, // range
568 this, // parent
569 wxPD_CAN_ABORT |
570 wxPD_APP_MODAL |
571 wxPD_ELAPSED_TIME |
572 wxPD_ESTIMATED_TIME |
573 wxPD_REMAINING_TIME);
574
575 bool cont = TRUE;
576 for ( int i = 0; i <= max && cont; i++ )
577 {
578 wxSleep(1);
579 if ( i == max )
580 {
581 cont = dialog.Update(i, "That's all, folks!");
582 }
583 else if ( i == max / 2 )
584 {
585 cont = dialog.Update(i, "Only a half left (very long message)!");
586 }
587 else
588 {
589 cont = dialog.Update(i);
590 }
591 }
592
593 if ( !cont )
594 {
595 wxLogStatus("Progress dialog aborted!");
596 }
597 else
598 {
599 wxLogStatus("Countdown from %d finished", max);
600 }
601 }
602
603 #endif // wxUSE_PROGRESSDLG
604
605 // ----------------------------------------------------------------------------
606 // MyCanvas
607 // ----------------------------------------------------------------------------
608
609 void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
610 {
611 wxPaintDC dc(this);
612 dc.SetFont(wxGetApp().m_canvasFont);
613 dc.SetTextForeground(wxGetApp().m_canvasTextColour);
614 dc.SetBackgroundMode(wxTRANSPARENT);
615 dc.DrawText("wxWindows common dialogs test application", 10, 10);
616 }
617
618 // ----------------------------------------------------------------------------
619 // MyModelessDialog
620 // ----------------------------------------------------------------------------
621
622 MyModelessDialog::MyModelessDialog(wxWindow *parent)
623 : wxDialog(parent, -1, wxString("Modeless dialog"))
624 {
625 wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
626
627 wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, "Press me");
628 wxCheckBox *check = new wxCheckBox(this, -1, "Should be disabled");
629 check->Disable();
630
631 sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5);
632 sizerTop->Add(check, 1, wxEXPAND | wxALL, 5);
633
634 SetAutoLayout(TRUE);
635 SetSizer(sizerTop);
636
637 sizerTop->SetSizeHints(this);
638 sizerTop->Fit(this);
639 }
640
641 void MyModelessDialog::OnClose(wxCloseEvent& event)
642 {
643 if ( event.CanVeto() )
644 {
645 wxMessageBox("Use the menu item to close this dialog",
646 "Modeless dialog",
647 wxOK | wxICON_INFORMATION, this);
648
649 event.Veto();
650 }
651 }
652
653 // ----------------------------------------------------------------------------
654 // MyModalDialog
655 // ----------------------------------------------------------------------------
656
657 MyModalDialog::MyModalDialog(wxWindow *parent)
658 : wxDialog(parent, -1, wxString("Modal dialog"))
659 {
660 wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
661
662 m_btnFocused = new wxButton(this, -1, "Default button");
663 m_btnDelete = new wxButton(this, -1, "&Delete button");
664 sizerTop->Add(m_btnFocused, 0, wxALIGN_CENTER | wxALL, 5);
665 sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5);
666
667 SetAutoLayout(TRUE);
668 SetSizer(sizerTop);
669
670 sizerTop->SetSizeHints(this);
671 sizerTop->Fit(this);
672
673 m_btnFocused->SetFocus();
674 m_btnFocused->SetDefault();
675 }
676
677 void MyModalDialog::OnButton(wxCommandEvent& event)
678 {
679 if ( event.GetEventObject() == m_btnDelete )
680 {
681 delete m_btnFocused;
682 m_btnFocused = NULL;
683
684 m_btnDelete->Disable();
685 }
686 else if ( event.GetEventObject() == m_btnFocused )
687 {
688 wxGetTextFromUser("Dummy prompt", "Modal dialog called from dialog",
689 "", this);
690 }
691 else
692 {
693 event.Skip();
694 }
695 }