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