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
)
96 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
97 EVT_BUTTON(-1, MyModalDialog::OnButton
)
100 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
101 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
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
;
195 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
198 data
.SetChooseFull(TRUE
);
199 for (int i
= 0; i
< 16; i
++)
201 wxColour
colour(i
*16, i
*16, i
*16);
202 data
.SetCustomColour(i
, colour
);
205 wxColourDialog
*dialog
= new wxColourDialog(this, &data
);
206 dialog
->SetTitle("Choose the background colour");
207 if (dialog
->ShowModal() == wxID_OK
)
209 wxColourData retData
= dialog
->GetColourData();
210 wxColour col
= retData
.GetColour();
211 myCanvas
->SetBackgroundColour(col
);
218 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
221 data
.SetInitialFont(wxGetApp().m_canvasFont
);
222 data
.SetColour(wxGetApp().m_canvasTextColour
);
224 wxFontDialog
*dialog
= new wxFontDialog(this, &data
);
225 if (dialog
->ShowModal() == wxID_OK
)
227 wxFontData retData
= dialog
->GetFontData();
228 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
229 wxGetApp().m_canvasTextColour
= retData
.GetColour();
235 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
236 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
239 data
.SetChooseFull(TRUE
);
240 for (int i
= 0; i
< 16; i
++)
242 wxColour
colour(i
*16, i
*16, i
*16);
243 data
.SetCustomColour(i
, colour
);
246 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &data
);
247 if (dialog
->ShowModal() == wxID_OK
)
249 wxColourData retData
= dialog
->GetColourData();
250 wxColour col
= retData
.GetColour();
251 // wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
252 myCanvas
->SetBackgroundColour(col
);
259 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
262 data
.SetInitialFont(wxGetApp().m_canvasFont
);
263 data
.SetColour(wxGetApp().m_canvasTextColour
);
265 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, &data
);
266 if (dialog
->ShowModal() == wxID_OK
)
268 wxFontData retData
= dialog
->GetFontData();
269 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
270 wxGetApp().m_canvasTextColour
= retData
.GetColour();
275 #endif // wxTEST_GENERIC_DIALOGS_IN_MSW
277 void MyFrame::LogDialog(wxCommandEvent
& event
)
279 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
280 // being flushed -- test it
283 wxLogMessage(wxT("This is some message - everything is ok so far."));
284 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
285 wxLogWarning(wxT("And then something went wrong!"));
287 // and if ~wxBusyCursor doesn't do it, then call it manually
291 wxLogError(wxT("Intermediary error handler decided to abort."));
292 wxLogError(wxT("The top level caller detected an unrecoverable error."));
294 wxLog::FlushActive();
296 wxLogMessage(wxT("And this is the same dialog but with only one message."));
299 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
301 wxMessageDialog
dialog( NULL
, "This is a message box\nA long, long string to test out the message box properly",
302 "Message box text", wxYES_NO
|wxCANCEL
|wxICON_INFORMATION
);
307 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
309 long res
= wxGetNumberFromUser( "This is some text, actually a lot of text.\n"
310 "Even two rows of text.",
311 "Enter a number:", "Numeric input test",
318 msg
= "Invalid number entered or dialog cancelled.";
323 msg
.Printf(_T("You've entered %lu"), res
);
324 icon
= wxICON_INFORMATION
;
327 wxMessageBox(msg
, "Numeric test result", wxOK
| icon
, this);
330 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
332 wxString pwd
= wxGetPasswordFromUser("Enter password:",
333 "Password entry dialog",
338 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
339 "Got password", wxOK
| wxICON_INFORMATION
, this);
343 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
345 wxTextEntryDialog
dialog(this,
346 "This is a small sample\n"
347 "A long, long string to test out the text entrybox",
348 "Please enter a string",
352 if (dialog
.ShowModal() == wxID_OK
)
354 wxMessageDialog
dialog2(this, dialog
.GetValue(), "Got string");
359 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
361 const wxString choices
[] = { "One", "Two", "Three", "Four", "Five" } ;
364 wxSingleChoiceDialog
dialog(this, "This is a small sample\nA single-choice convenience dialog",
365 "Please select a value", n
, (const wxString
*)choices
);
367 dialog
.SetSelection(2);
369 if (dialog
.ShowModal() == wxID_OK
)
371 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), "Got string");
376 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
378 const wxString choices
[] = { "One", "Two", "Three", "Four", "Five" } ;
381 wxArrayInt selections
;
382 size_t count
= wxGetMultipleChoices(selections
,
383 "This is a small sample\n"
384 "A multi-choice convenience dialog",
385 "Please select a value",
386 n
, (const wxString
*)choices
,
391 msg
.Printf(wxT("You selected %u items:\n"), count
);
392 for ( size_t n
= 0; n
< count
; n
++ )
394 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"), n
, selections
[n
],
395 choices
[selections
[n
]].c_str());
399 //else: cancelled or nothing selected
402 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
404 wxFileDialog
dialog(this, "Testing open file dialog",
406 "C++ files (*.h;*.cpp)|*.h;*.cpp");
408 if (dialog
.ShowModal() == wxID_OK
)
411 info
.Printf(_T("Full file name: %s\n")
414 dialog
.GetPath().c_str(),
415 dialog
.GetDirectory().c_str(),
416 dialog
.GetFilename().c_str());
417 wxMessageDialog
dialog2(this, info
, "Selected file");
422 // this shows how to take advantage of specifying a default extension in the
423 // call to wxFileSelector: it is remembered after each new call and the next
424 // one will use it by default
425 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
427 static wxString s_extDef
;
428 wxString path
= wxFileSelector(
429 _T("Select the file to load"),
432 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
440 // it is just a sample, would use wxSplitPath in real program
441 s_extDef
= path
.AfterLast(_T('.'));
443 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
444 (const wxChar
*) path
, (const wxChar
*) s_extDef
);
447 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
449 wxFileDialog
dialog(this, "Testing open multiple file dialog",
450 "", "", wxFileSelectorDefaultWildcardStr
,
453 if (dialog
.ShowModal() == wxID_OK
)
455 wxArrayString paths
, filenames
;
457 dialog
.GetPaths(paths
);
458 dialog
.GetFilenames(filenames
);
461 size_t count
= paths
.GetCount();
462 for ( size_t n
= 0; n
< count
; n
++ )
464 s
.Printf(_T("File %d: %s (%s)\n"),
465 n
, paths
[n
].c_str(), filenames
[n
].c_str());
470 wxMessageDialog
dialog2(this, msg
, "Selected files");
475 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
477 wxFileDialog
dialog(this, "Testing save file dialog", "", "myletter.txt",
478 "Text files (*.txt)|*.txt|Document files (*.doc)|*.doc",
479 wxSAVE
|wxOVERWRITE_PROMPT
);
481 if (dialog
.ShowModal() == wxID_OK
)
484 wxSprintf(buf
, _T("%s, filter %d"), (const wxChar
*)dialog
.GetPath(), dialog
.GetFilterIndex());
485 wxMessageDialog
dialog2(this, wxString(buf
), "Selected path");
490 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
492 // pass some initial dir to wxDirDialog
494 wxGetHomeDir(&dirHome
);
496 wxDirDialog
dialog(this, "Testing directory picker", dirHome
);
498 if (dialog
.ShowModal() == wxID_OK
)
500 wxMessageDialog
dialog2(this, dialog
.GetPath(), "Selected path");
505 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
507 #if !defined(__WXMSW__) || defined(wxUSE_DIRDLGG) && wxUSE_DIRDLGG
508 // pass some initial dir to wxDirDialog
510 wxGetHomeDir(&dirHome
);
512 wxGenericDirDialog
dialog(this, "Testing generic directory picker", dirHome
);
514 if (dialog
.ShowModal() == wxID_OK
)
516 wxMessageDialog
dialog2(this, dialog
.GetPath(), "Selected path");
520 wxLogError(wxT("Sorry, generic dir dialog not available:\n")
521 wxT("set wxUSE_DIRDLGG to 1 and recompile"));
525 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
527 MyModalDialog
dlg(this);
531 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
533 bool show
= GetMenuBar()->IsChecked(event
.GetId());
539 m_dialog
= new MyModelessDialog(this);
542 m_dialog
->Show(TRUE
);
550 void MyFrame::ShowTip(wxCommandEvent
& event
)
552 #if wxUSE_STARTUP_TIPS
553 static size_t s_index
= (size_t)-1;
555 if ( s_index
== (size_t)-1 )
559 // this is completely bogus, we don't know how many lines are there
560 // in the file, but who cares, it's a demo only...
561 s_index
= rand() % 5;
564 wxTipProvider
*tipProvider
= wxCreateFileTipProvider("tips.txt", s_index
);
566 bool showAtStartup
= wxShowTip(this, tipProvider
);
570 wxMessageBox("Will show tips on startup", "Tips dialog",
571 wxOK
| wxICON_INFORMATION
, this);
574 s_index
= tipProvider
->GetCurrentTip();
579 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
584 #if wxUSE_PROGRESSDLG
586 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
588 static const int max
= 10;
590 wxProgressDialog
dialog("Progress dialog example",
591 "An informative message",
597 wxPD_ESTIMATED_TIME
|
598 wxPD_REMAINING_TIME
);
601 for ( int i
= 0; i
<= max
&& cont
; i
++ )
606 cont
= dialog
.Update(i
, "That's all, folks!");
608 else if ( i
== max
/ 2 )
610 cont
= dialog
.Update(i
, "Only a half left (very long message)!");
614 cont
= dialog
.Update(i
);
620 wxLogStatus(wxT("Progress dialog aborted!"));
624 wxLogStatus(wxT("Countdown from %d finished"), max
);
628 #endif // wxUSE_PROGRESSDLG
630 #if wxUSE_FINDREPLDLG
632 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
634 wxFindReplaceDialog
*dialog
= new wxFindReplaceDialog
638 "Find and replace dialog",
644 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
646 wxFindReplaceDialog
*dialog
= new wxFindReplaceDialog
657 static wxString
DecodeFindDialogEventFlags(int flags
)
660 str
<< (flags
& wxFR_DOWN
? "down" : "up") << ", "
661 << (flags
& wxFR_WHOLEWORD
? "whole words only, " : "")
662 << (flags
& wxFR_MATCHCASE
? "" : "not ")
668 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
670 wxEventType type
= event
.GetEventType();
672 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
674 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
675 type
== wxEVT_COMMAND_FIND_NEXT
? "next " : "",
676 event
.GetFindString().c_str(),
677 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
679 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
680 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
682 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
683 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? "all " : "",
684 event
.GetFindString().c_str(),
685 event
.GetReplaceString().c_str(),
686 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
688 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
690 wxLogMessage(wxT("Find dialog is being closed."));
692 event
.GetDialog()->Destroy();
696 wxLogError(wxT("Unknown find dialog event!"));
700 #endif // wxUSE_FINDREPLDLG
702 // ----------------------------------------------------------------------------
704 // ----------------------------------------------------------------------------
706 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
709 dc
.SetFont(wxGetApp().m_canvasFont
);
710 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
711 dc
.SetBackgroundMode(wxTRANSPARENT
);
712 dc
.DrawText("wxWindows common dialogs test application", 10, 10);
715 // ----------------------------------------------------------------------------
717 // ----------------------------------------------------------------------------
719 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
720 : wxDialog(parent
, -1, wxString("Modeless dialog"))
722 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
724 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, "Press me");
725 wxCheckBox
*check
= new wxCheckBox(this, -1, "Should be disabled");
728 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
729 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
734 sizerTop
->SetSizeHints(this);
738 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
740 wxMessageBox("Button pressed in modeless dialog", "Info",
741 wxOK
| wxICON_INFORMATION
, this);
744 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
746 if ( event
.CanVeto() )
748 wxMessageBox("Use the menu item to close this dialog",
750 wxOK
| wxICON_INFORMATION
, this);
756 // ----------------------------------------------------------------------------
758 // ----------------------------------------------------------------------------
760 MyModalDialog::MyModalDialog(wxWindow
*parent
)
761 : wxDialog(parent
, -1, wxString("Modal dialog"))
763 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
765 m_btnFocused
= new wxButton(this, -1, "Default button");
766 m_btnDelete
= new wxButton(this, -1, "&Delete button");
767 sizerTop
->Add(m_btnFocused
, 0, wxALIGN_CENTER
| wxALL
, 5);
768 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
773 sizerTop
->SetSizeHints(this);
776 m_btnFocused
->SetFocus();
777 m_btnFocused
->SetDefault();
780 void MyModalDialog::OnButton(wxCommandEvent
& event
)
782 if ( event
.GetEventObject() == m_btnDelete
)
787 m_btnDelete
->Disable();
789 else if ( event
.GetEventObject() == m_btnFocused
)
791 wxGetTextFromUser("Dummy prompt", "Modal dialog called from dialog",