1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
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 #include "wx/fdrepdlg.h"
37 #define wxTEST_GENERIC_DIALOGS_IN_MSW 0
39 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
40 #include <wx/generic/colrdlgg.h>
41 #include <wx/generic/fontdlgg.h>
44 #if !defined(__WXMSW__) || defined(wxUSE_DIRDLGG) && wxUSE_DIRDLGG
45 // New wxGenericDirCtrl
46 #include "wx/dirctrl.h"
53 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
54 EVT_PAINT(MyCanvas::OnPaint
)
57 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
58 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
59 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
60 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
61 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
62 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
63 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
64 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
65 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
66 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
67 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
68 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
69 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
70 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
71 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
72 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
73 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
74 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
75 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
76 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
77 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
78 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
81 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
82 #endif // wxUSE_PROGRESSDLG
84 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
85 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
87 EVT_FIND(-1, MyFrame::OnFindDialog
)
88 EVT_FIND_NEXT(-1, MyFrame::OnFindDialog
)
89 EVT_FIND_REPLACE(-1, MyFrame::OnFindDialog
)
90 EVT_FIND_REPLACE_ALL(-1, MyFrame::OnFindDialog
)
91 EVT_FIND_CLOSE(-1, MyFrame::OnFindDialog
)
92 #endif // wxUSE_FINDREPLDLG
93 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
95 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyFrame::OnButton
)
98 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
99 EVT_BUTTON(-1, MyModalDialog::OnButton
)
102 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
103 EVT_CLOSE(MyModelessDialog::OnClose
)
106 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
108 // `Main program' equivalent, creating windows and returning main app frame
111 #if defined(__WXGTK__) && defined(wxUSE_UNICODE)
112 wxConvCurrent
= &wxConvLibc
;
115 m_canvasTextColour
= wxColour("BLACK");
116 m_canvasFont
= *wxNORMAL_FONT
;
118 // Create the main frame window
119 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, (char *) "wxWindows dialogs example", wxPoint(20, 20), wxSize(400, 300));
122 wxMenu
*file_menu
= new wxMenu
;
124 file_menu
->Append(DIALOGS_CHOOSE_COLOUR
, "&Choose colour");
126 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
127 file_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, "Choose colour (&generic)");
130 file_menu
->AppendSeparator();
131 file_menu
->Append(DIALOGS_CHOOSE_FONT
, "Choose &font");
133 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
134 file_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, "Choose f&ont (generic)");
137 file_menu
->AppendSeparator();
138 file_menu
->Append(DIALOGS_LOG_DIALOG
, "&Log dialog\tCtrl-L");
139 file_menu
->Append(DIALOGS_MESSAGE_BOX
, "&Message box\tCtrl-M");
140 file_menu
->Append(DIALOGS_TEXT_ENTRY
, "Text &entry\tCtrl-E");
141 file_menu
->Append(DIALOGS_PASSWORD_ENTRY
, "&Password entry\tCtrl-P");
142 file_menu
->Append(DIALOGS_NUM_ENTRY
, "&Numeric entry\tCtrl-N");
143 file_menu
->Append(DIALOGS_SINGLE_CHOICE
, "&Single choice\tCtrl-C");
144 file_menu
->Append(DIALOGS_MULTI_CHOICE
, "M&ultiple choice\tCtrl-U");
145 file_menu
->AppendSeparator();
146 file_menu
->Append(DIALOGS_TIP
, "&Tip of the day\tCtrl-T");
147 file_menu
->AppendSeparator();
148 file_menu
->Append(DIALOGS_FILE_OPEN
, "&Open file\tCtrl-O");
149 file_menu
->Append(DIALOGS_FILE_OPEN2
, "&Second open file\tCtrl-2");
150 file_menu
->Append(DIALOGS_FILES_OPEN
, "Open &files\tCtrl-Q");
151 file_menu
->Append(DIALOGS_FILE_SAVE
, "Sa&ve file\tCtrl-S");
152 file_menu
->Append(DIALOGS_DIR_CHOOSE
, "&Choose a directory\tCtrl-D");
153 file_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, "&Choose a directory (generic implementation)");
154 #if wxUSE_PROGRESSDLG
155 file_menu
->Append(DIALOGS_PROGRESS
, "Pro&gress dialog\tCtrl-G");
156 #endif // wxUSE_PROGRESSDLG
157 #if wxUSE_FINDREPLDLG
158 file_menu
->Append(DIALOGS_FIND
, "&Find dialog\tCtrl-F");
159 file_menu
->Append(DIALOGS_REPLACE
, "Find and &replace dialog\tShift-Ctrl-F");
160 #endif // wxUSE_FINDREPLDLG
161 file_menu
->AppendSeparator();
162 file_menu
->Append(DIALOGS_MODAL
, "Mo&dal dialog\tCtrl-D");
163 file_menu
->Append(DIALOGS_MODELESS
, "Modeless &dialog\tCtrl-Z", "", TRUE
);
164 file_menu
->AppendSeparator();
165 file_menu
->Append(wxID_EXIT
, "E&xit\tAlt-X");
166 wxMenuBar
*menu_bar
= new wxMenuBar
;
167 menu_bar
->Append(file_menu
, "&File");
168 frame
->SetMenuBar(menu_bar
);
170 myCanvas
= new MyCanvas(frame
);
171 myCanvas
->SetBackgroundColour(*wxWHITE
);
173 frame
->Centre(wxBOTH
);
183 // My frame constructor
184 MyFrame::MyFrame(wxWindow
*parent
,
185 const wxString
& title
,
188 : wxFrame(parent
, -1, title
, pos
, size
)
190 m_dialog
= (MyModelessDialog
*)NULL
;
193 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
196 data
.SetChooseFull(TRUE
);
197 for (int i
= 0; i
< 16; i
++)
199 wxColour
colour(i
*16, i
*16, i
*16);
200 data
.SetCustomColour(i
, colour
);
203 wxColourDialog
*dialog
= new wxColourDialog(this, &data
);
204 dialog
->SetTitle("Choose the background colour");
205 if (dialog
->ShowModal() == wxID_OK
)
207 wxColourData retData
= dialog
->GetColourData();
208 wxColour col
= retData
.GetColour();
209 myCanvas
->SetBackgroundColour(col
);
216 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
219 data
.SetInitialFont(wxGetApp().m_canvasFont
);
220 data
.SetColour(wxGetApp().m_canvasTextColour
);
222 wxFontDialog
*dialog
= new wxFontDialog(this, &data
);
223 if (dialog
->ShowModal() == wxID_OK
)
225 wxFontData retData
= dialog
->GetFontData();
226 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
227 wxGetApp().m_canvasTextColour
= retData
.GetColour();
233 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
234 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
237 data
.SetChooseFull(TRUE
);
238 for (int i
= 0; i
< 16; i
++)
240 wxColour
colour(i
*16, i
*16, i
*16);
241 data
.SetCustomColour(i
, colour
);
244 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &data
);
245 if (dialog
->ShowModal() == wxID_OK
)
247 wxColourData retData
= dialog
->GetColourData();
248 wxColour col
= retData
.GetColour();
249 // wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
250 myCanvas
->SetBackgroundColour(col
);
257 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
260 data
.SetInitialFont(wxGetApp().m_canvasFont
);
261 data
.SetColour(wxGetApp().m_canvasTextColour
);
263 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, &data
);
264 if (dialog
->ShowModal() == wxID_OK
)
266 wxFontData retData
= dialog
->GetFontData();
267 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
268 wxGetApp().m_canvasTextColour
= retData
.GetColour();
273 #endif // wxTEST_GENERIC_DIALOGS_IN_MSW
275 void MyFrame::LogDialog(wxCommandEvent
& event
)
277 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
278 // being flushed -- test it
281 wxLogMessage("This is some message - everything is ok so far.");
282 wxLogMessage("Another message...\n... this one is on multiple lines");
283 wxLogWarning("And then something went wrong!");
285 // and if ~wxBusyCursor doesn't do it, then call it manually
289 wxLogError("Intermediary error handler decided to abort.");
290 wxLogError("The top level caller detected an unrecoverable error.");
292 wxLog::FlushActive();
294 wxLogMessage("And this is the same dialog but with only one message.");
297 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
299 wxMessageDialog
dialog( NULL
, "This is a message box\nA long, long string to test out the message box properly",
300 "Message box text", wxYES_NO
|wxCANCEL
|wxICON_INFORMATION
);
305 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
307 long res
= wxGetNumberFromUser( "This is some text, actually a lot of text.\n"
308 "Even two rows of text.",
309 "Enter a number:", "Numeric input test",
316 msg
= "Invalid number entered or dialog cancelled.";
321 msg
.Printf(_T("You've entered %lu"), res
);
322 icon
= wxICON_INFORMATION
;
325 wxMessageBox(msg
, "Numeric test result", wxOK
| icon
, this);
328 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
330 wxString pwd
= wxGetPasswordFromUser("Enter password:",
331 "Password entry dialog",
336 wxMessageBox(wxString::Format("Your password is '%s'", pwd
.c_str()),
337 "Got password", wxOK
| wxICON_INFORMATION
, this);
341 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
343 wxTextEntryDialog
dialog(this,
344 "This is a small sample\n"
345 "A long, long string to test out the text entrybox",
346 "Please enter a string",
350 if (dialog
.ShowModal() == wxID_OK
)
352 wxMessageDialog
dialog2(this, dialog
.GetValue(), "Got string");
357 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
359 const wxString choices
[] = { "One", "Two", "Three", "Four", "Five" } ;
362 wxSingleChoiceDialog
dialog(this, "This is a small sample\nA single-choice convenience dialog",
363 "Please select a value", n
, (const wxString
*)choices
);
365 dialog
.SetSelection(2);
367 if (dialog
.ShowModal() == wxID_OK
)
369 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), "Got string");
374 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
376 const wxString choices
[] = { "One", "Two", "Three", "Four", "Five" } ;
379 wxArrayInt selections
;
380 size_t count
= wxGetMultipleChoices(selections
,
381 "This is a small sample\n"
382 "A multi-choice convenience dialog",
383 "Please select a value",
384 n
, (const wxString
*)choices
,
389 msg
.Printf("You selected %u items:\n", count
);
390 for ( size_t n
= 0; n
< count
; n
++ )
392 msg
+= wxString::Format("\t%u: %u (%s)\n", n
, selections
[n
],
393 choices
[selections
[n
]].c_str());
397 //else: cancelled or nothing selected
400 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
402 wxFileDialog
dialog(this, "Testing open file dialog", "", "", "*.txt", 0);
404 if (dialog
.ShowModal() == wxID_OK
)
407 info
.Printf(_T("Full file name: %s\n")
410 dialog
.GetPath().c_str(),
411 dialog
.GetDirectory().c_str(),
412 dialog
.GetFilename().c_str());
413 wxMessageDialog
dialog2(this, info
, "Selected file");
418 // this shows how to take advantage of specifying a default extension in the
419 // call to wxFileSelector: it is remembered after each new call and the next
420 // one will use it by default
421 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
423 static wxString s_extDef
;
424 wxString path
= wxFileSelector(
425 _T("Select the file to load"),
428 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
436 // it is just a sample, would use wxSplitPath in real program
437 s_extDef
= path
.AfterLast(_T('.'));
439 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
440 (const wxChar
*) path
, (const wxChar
*) s_extDef
);
443 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
445 wxFileDialog
dialog(this, "Testing open multiple file dialog",
446 "", "", wxFileSelectorDefaultWildcardStr
,
449 if (dialog
.ShowModal() == wxID_OK
)
451 wxArrayString paths
, filenames
;
453 dialog
.GetPaths(paths
);
454 dialog
.GetFilenames(filenames
);
457 size_t count
= paths
.GetCount();
458 for ( size_t n
= 0; n
< count
; n
++ )
460 s
.Printf(_T("File %d: %s (%s)\n"),
461 n
, paths
[n
].c_str(), filenames
[n
].c_str());
466 wxMessageDialog
dialog2(this, msg
, "Selected files");
471 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
473 wxFileDialog
dialog(this, "Testing save file dialog", "", "myletter.txt",
474 "Text files (*.txt)|*.txt|Document files (*.doc)|*.doc",
475 wxSAVE
|wxOVERWRITE_PROMPT
);
477 if (dialog
.ShowModal() == wxID_OK
)
480 wxSprintf(buf
, _T("%s, filter %d"), (const wxChar
*)dialog
.GetPath(), dialog
.GetFilterIndex());
481 wxMessageDialog
dialog2(this, wxString(buf
), "Selected path");
486 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
488 // pass some initial dir to wxDirDialog
490 wxGetHomeDir(&dirHome
);
492 wxDirDialog
dialog(this, "Testing directory picker", dirHome
);
494 if (dialog
.ShowModal() == wxID_OK
)
496 wxMessageDialog
dialog2(this, dialog
.GetPath(), "Selected path");
501 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
503 #if !defined(__WXMSW__) || defined(wxUSE_DIRDLGG) && wxUSE_DIRDLGG
504 // pass some initial dir to wxDirDialog
506 wxGetHomeDir(&dirHome
);
508 wxGenericDirDialog
dialog(this, "Testing generic directory picker", dirHome
);
510 if (dialog
.ShowModal() == wxID_OK
)
512 wxMessageDialog
dialog2(this, dialog
.GetPath(), "Selected path");
516 wxLogError("Sorry, generic dir dialog not available:\n"
517 "set wxUSE_DIRDLGG to 1 and recompile");
521 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
523 MyModalDialog
dlg(this);
527 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
529 bool show
= GetMenuBar()->IsChecked(event
.GetId());
535 m_dialog
= new MyModelessDialog(this);
538 m_dialog
->Show(TRUE
);
546 void MyFrame::OnButton(wxCommandEvent
& WXUNUSED(event
))
548 wxMessageBox("Button pressed in modeless dialog", "Info",
549 wxOK
| wxICON_INFORMATION
, this);
552 void MyFrame::ShowTip(wxCommandEvent
& event
)
554 #if wxUSE_STARTUP_TIPS
555 static size_t s_index
= (size_t)-1;
557 if ( s_index
== (size_t)-1 )
561 // this is completely bogus, we don't know how many lines are there
562 // in the file, but who cares, it's a demo only...
563 s_index
= rand() % 5;
566 wxTipProvider
*tipProvider
= wxCreateFileTipProvider("tips.txt", s_index
);
568 bool showAtStartup
= wxShowTip(this, tipProvider
);
572 wxMessageBox("Will show tips on startup", "Tips dialog",
573 wxOK
| wxICON_INFORMATION
, this);
576 s_index
= tipProvider
->GetCurrentTip();
581 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
586 #if wxUSE_PROGRESSDLG
588 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
590 static const int max
= 10;
592 wxProgressDialog
dialog("Progress dialog example",
593 "An informative message",
599 wxPD_ESTIMATED_TIME
|
600 wxPD_REMAINING_TIME
);
603 for ( int i
= 0; i
<= max
&& cont
; i
++ )
608 cont
= dialog
.Update(i
, "That's all, folks!");
610 else if ( i
== max
/ 2 )
612 cont
= dialog
.Update(i
, "Only a half left (very long message)!");
616 cont
= dialog
.Update(i
);
622 wxLogStatus("Progress dialog aborted!");
626 wxLogStatus("Countdown from %d finished", max
);
630 #endif // wxUSE_PROGRESSDLG
632 #if wxUSE_FINDREPLDLG
634 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
636 wxFindReplaceDialog
*dialog
= new wxFindReplaceDialog
640 "Find and replace dialog",
646 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
648 wxFindReplaceDialog
*dialog
= new wxFindReplaceDialog
659 static wxString
DecodeFindDialogEventFlags(int flags
)
662 str
<< (flags
& wxFR_DOWN
? "down" : "up") << ", "
663 << (flags
& wxFR_WHOLEWORD
? "whole words only, " : "")
664 << (flags
& wxFR_MATCHCASE
? "" : "not ")
670 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
672 wxEventType type
= event
.GetEventType();
674 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
676 wxLogMessage("Find %s'%s' (flags: %s)",
677 type
== wxEVT_COMMAND_FIND_NEXT
? "next " : "",
678 event
.GetFindString().c_str(),
679 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
681 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
682 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
684 wxLogMessage("Replace %s'%s' with '%s' (flags: %s)",
685 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? "all " : "",
686 event
.GetFindString().c_str(),
687 event
.GetReplaceString().c_str(),
688 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
690 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
692 wxLogMessage("Find dialog is being closed.");
694 event
.GetDialog()->Destroy();
698 wxLogError("Unknown find dialog event!");
702 #endif // wxUSE_FINDREPLDLG
704 // ----------------------------------------------------------------------------
706 // ----------------------------------------------------------------------------
708 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
711 dc
.SetFont(wxGetApp().m_canvasFont
);
712 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
713 dc
.SetBackgroundMode(wxTRANSPARENT
);
714 dc
.DrawText("wxWindows common dialogs test application", 10, 10);
717 // ----------------------------------------------------------------------------
719 // ----------------------------------------------------------------------------
721 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
722 : wxDialog(parent
, -1, wxString("Modeless dialog"))
724 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
726 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, "Press me");
727 wxCheckBox
*check
= new wxCheckBox(this, -1, "Should be disabled");
730 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
731 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
736 sizerTop
->SetSizeHints(this);
740 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
742 if ( event
.CanVeto() )
744 wxMessageBox("Use the menu item to close this dialog",
746 wxOK
| wxICON_INFORMATION
, this);
752 // ----------------------------------------------------------------------------
754 // ----------------------------------------------------------------------------
756 MyModalDialog::MyModalDialog(wxWindow
*parent
)
757 : wxDialog(parent
, -1, wxString("Modal dialog"))
759 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
761 m_btnFocused
= new wxButton(this, -1, "Default button");
762 m_btnDelete
= new wxButton(this, -1, "&Delete button");
763 sizerTop
->Add(m_btnFocused
, 0, wxALIGN_CENTER
| wxALL
, 5);
764 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
769 sizerTop
->SetSizeHints(this);
772 m_btnFocused
->SetFocus();
773 m_btnFocused
->SetDefault();
776 void MyModalDialog::OnButton(wxCommandEvent
& event
)
778 if ( event
.GetEventObject() == m_btnDelete
)
783 m_btnDelete
->Disable();
785 else if ( event
.GetEventObject() == m_btnFocused
)
787 wxGetTextFromUser("Dummy prompt", "Modal dialog called from dialog",