ok, it does work - it's just that wxGTK doesn't
[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 wxString msg;
369 msg.Printf("You selected %u items:\n", count);
370 for ( size_t n = 0; n < count; n++ )
371 {
372 msg += wxString::Format("\t%u: %u (%s)\n", n, selections[n],
373 choices[selections[n]].c_str());
374 }
375 wxLogMessage(msg);
376 }
377 //else: cancelled or nothing selected
378 }
379
380 void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
381 {
382 wxFileDialog dialog(this, "Testing open file dialog", "", "", "*.txt", 0);
383
384 if (dialog.ShowModal() == wxID_OK)
385 {
386 wxString info;
387 info.Printf(_T("Full file name: %s\n")
388 _T("Path: %s\n")
389 _T("Name: %s"),
390 dialog.GetPath().c_str(),
391 dialog.GetDirectory().c_str(),
392 dialog.GetFilename().c_str());
393 wxMessageDialog dialog2(this, info, "Selected file");
394 dialog2.ShowModal();
395 }
396 }
397
398 // this shows how to take advantage of specifying a default extension in the
399 // call to wxFileSelector: it is remembered after each new call and the next
400 // one will use it by default
401 void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) )
402 {
403 static wxString s_extDef;
404 wxString path = wxFileSelector(
405 _T("Select the file to load"),
406 _T(""), _T(""),
407 s_extDef,
408 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
409 0,
410 this
411 );
412
413 if ( !path )
414 return;
415
416 // it is just a sample, would use wxSplitPath in real program
417 s_extDef = path.AfterLast(_T('.'));
418
419 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
420 (const wxChar*) path, (const wxChar*) s_extDef);
421 }
422
423 void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) )
424 {
425 wxFileDialog dialog(this, "Testing open multiple file dialog",
426 "", "", wxFileSelectorDefaultWildcardStr,
427 wxMULTIPLE);
428
429 if (dialog.ShowModal() == wxID_OK)
430 {
431 wxArrayString paths, filenames;
432
433 dialog.GetPaths(paths);
434 dialog.GetFilenames(filenames);
435
436 wxString msg, s;
437 size_t count = paths.GetCount();
438 for ( size_t n = 0; n < count; n++ )
439 {
440 s.Printf(_T("File %d: %s (%s)\n"),
441 n, paths[n].c_str(), filenames[n].c_str());
442
443 msg += s;
444 }
445
446 wxMessageDialog dialog2(this, msg, "Selected files");
447 dialog2.ShowModal();
448 }
449 }
450
451 void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) )
452 {
453 wxFileDialog dialog(this, "Testing save file dialog", "", "myletter.txt",
454 "Text files (*.txt)|*.txt|Document files (*.doc)|*.doc",
455 wxSAVE|wxOVERWRITE_PROMPT);
456
457 if (dialog.ShowModal() == wxID_OK)
458 {
459 wxChar buf[400];
460 wxSprintf(buf, _T("%s, filter %d"), (const wxChar*)dialog.GetPath(), dialog.GetFilterIndex());
461 wxMessageDialog dialog2(this, wxString(buf), "Selected path");
462 dialog2.ShowModal();
463 }
464 }
465
466 void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) )
467 {
468 // pass some initial dir to wxDirDialog
469 wxString dirHome;
470 wxGetHomeDir(&dirHome);
471
472 wxDirDialog dialog(this, "Testing directory picker", dirHome);
473
474 if (dialog.ShowModal() == wxID_OK)
475 {
476 wxMessageDialog dialog2(this, dialog.GetPath(), "Selected path");
477 dialog2.ShowModal();
478 }
479 }
480
481 void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) )
482 {
483 // pass some initial dir to wxDirDialog
484 wxString dirHome;
485 wxGetHomeDir(&dirHome);
486
487 wxGenericDirDialog dialog(this, "Testing generic directory picker", dirHome);
488
489 if (dialog.ShowModal() == wxID_OK)
490 {
491 wxMessageDialog dialog2(this, dialog.GetPath(), "Selected path");
492 dialog2.ShowModal();
493 }
494 }
495
496 void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event))
497 {
498 MyModalDialog dlg(this);
499 dlg.ShowModal();
500 }
501
502 void MyFrame::ModelessDlg(wxCommandEvent& event)
503 {
504 bool show = GetMenuBar()->IsChecked(event.GetId());
505
506 if ( show )
507 {
508 if ( !m_dialog )
509 {
510 m_dialog = new MyModelessDialog(this);
511 }
512
513 m_dialog->Show(TRUE);
514 }
515 else // hide
516 {
517 m_dialog->Hide();
518 }
519 }
520
521 void MyFrame::OnButton(wxCommandEvent& WXUNUSED(event))
522 {
523 wxMessageBox("Button pressed in modeless dialog", "Info",
524 wxOK | wxICON_INFORMATION, this);
525 }
526
527 void MyFrame::ShowTip(wxCommandEvent& event)
528 {
529 #if wxUSE_STARTUP_TIPS
530 static size_t s_index = (size_t)-1;
531
532 if ( s_index == (size_t)-1 )
533 {
534 srand(time(NULL));
535
536 // this is completely bogus, we don't know how many lines are there
537 // in the file, but who cares, it's a demo only...
538 s_index = rand() % 5;
539 }
540
541 wxTipProvider *tipProvider = wxCreateFileTipProvider("tips.txt", s_index);
542
543 bool showAtStartup = wxShowTip(this, tipProvider);
544
545 if ( showAtStartup )
546 {
547 wxMessageBox("Will show tips on startup", "Tips dialog",
548 wxOK | wxICON_INFORMATION, this);
549 }
550
551 s_index = tipProvider->GetCurrentTip();
552 delete tipProvider;
553 #endif
554 }
555
556 void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) )
557 {
558 Close(TRUE);
559 }
560
561 #if wxUSE_PROGRESSDLG
562
563 void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
564 {
565 static const int max = 10;
566
567 wxProgressDialog dialog("Progress dialog example",
568 "An informative message",
569 max, // range
570 this, // parent
571 wxPD_CAN_ABORT |
572 wxPD_APP_MODAL |
573 wxPD_ELAPSED_TIME |
574 wxPD_ESTIMATED_TIME |
575 wxPD_REMAINING_TIME);
576
577 bool cont = TRUE;
578 for ( int i = 0; i <= max && cont; i++ )
579 {
580 wxSleep(1);
581 if ( i == max )
582 {
583 cont = dialog.Update(i, "That's all, folks!");
584 }
585 else if ( i == max / 2 )
586 {
587 cont = dialog.Update(i, "Only a half left (very long message)!");
588 }
589 else
590 {
591 cont = dialog.Update(i);
592 }
593 }
594
595 if ( !cont )
596 {
597 wxLogStatus("Progress dialog aborted!");
598 }
599 else
600 {
601 wxLogStatus("Countdown from %d finished", max);
602 }
603 }
604
605 #endif // wxUSE_PROGRESSDLG
606
607 // ----------------------------------------------------------------------------
608 // MyCanvas
609 // ----------------------------------------------------------------------------
610
611 void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
612 {
613 wxPaintDC dc(this);
614 dc.SetFont(wxGetApp().m_canvasFont);
615 dc.SetTextForeground(wxGetApp().m_canvasTextColour);
616 dc.SetBackgroundMode(wxTRANSPARENT);
617 dc.DrawText("wxWindows common dialogs test application", 10, 10);
618 }
619
620 // ----------------------------------------------------------------------------
621 // MyModelessDialog
622 // ----------------------------------------------------------------------------
623
624 MyModelessDialog::MyModelessDialog(wxWindow *parent)
625 : wxDialog(parent, -1, wxString("Modeless dialog"))
626 {
627 wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
628
629 wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, "Press me");
630 wxCheckBox *check = new wxCheckBox(this, -1, "Should be disabled");
631 check->Disable();
632
633 sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5);
634 sizerTop->Add(check, 1, wxEXPAND | wxALL, 5);
635
636 SetAutoLayout(TRUE);
637 SetSizer(sizerTop);
638
639 sizerTop->SetSizeHints(this);
640 sizerTop->Fit(this);
641 }
642
643 void MyModelessDialog::OnClose(wxCloseEvent& event)
644 {
645 if ( event.CanVeto() )
646 {
647 wxMessageBox("Use the menu item to close this dialog",
648 "Modeless dialog",
649 wxOK | wxICON_INFORMATION, this);
650
651 event.Veto();
652 }
653 }
654
655 // ----------------------------------------------------------------------------
656 // MyModalDialog
657 // ----------------------------------------------------------------------------
658
659 MyModalDialog::MyModalDialog(wxWindow *parent)
660 : wxDialog(parent, -1, wxString("Modal dialog"))
661 {
662 wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
663
664 m_btnFocused = new wxButton(this, -1, "Default button");
665 m_btnDelete = new wxButton(this, -1, "&Delete button");
666 sizerTop->Add(m_btnFocused, 0, wxALIGN_CENTER | wxALL, 5);
667 sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5);
668
669 SetAutoLayout(TRUE);
670 SetSizer(sizerTop);
671
672 sizerTop->SetSizeHints(this);
673 sizerTop->Fit(this);
674
675 m_btnFocused->SetFocus();
676 m_btnFocused->SetDefault();
677 }
678
679 void MyModalDialog::OnButton(wxCommandEvent& event)
680 {
681 if ( event.GetEventObject() == m_btnDelete )
682 {
683 delete m_btnFocused;
684 m_btnFocused = NULL;
685
686 m_btnDelete->Disable();
687 }
688 else if ( event.GetEventObject() == m_btnFocused )
689 {
690 wxGetTextFromUser("Dummy prompt", "Modal dialog called from dialog",
691 "", this);
692 }
693 else
694 {
695 event.Skip();
696 }
697 }