1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart
5 // Modified by: ABX (2004) - adjustements for conditional building + new menu
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(__APPLE__)
13 #pragma implementation
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
28 #include "wx/datetime.h"
32 #include "wx/colordlg.h"
33 #endif // wxUSE_COLOURDLG
36 #include "wx/choicdlg.h"
37 #endif // wxUSE_CHOICEDLG
39 #if wxUSE_STARTUP_TIPS
40 #include "wx/tipdlg.h"
41 #endif // wxUSE_STARTUP_TIPS
44 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
45 #include <wx/datetime.h> // wxDateTime
48 #include "wx/progdlg.h"
49 #endif // wxUSE_PROGRESSDLG
52 #include "wx/busyinfo.h"
53 #endif // wxUSE_BUSYINFO
56 #include "wx/numdlg.h"
57 #endif // wxUSE_NUMBERDLG
60 #include "wx/filedlg.h"
61 #endif // wxUSE_FILEDLG
64 #include "wx/dirdlg.h"
65 #endif // wxUSE_DIRDLG
68 #include "wx/fontdlg.h"
69 #endif // wxUSE_FONTDLG
72 #include "wx/fdrepdlg.h"
73 #endif // wxUSE_FINDREPLDLG
77 #if USE_COLOURDLG_GENERIC
78 #include "wx/generic/colrdlgg.h"
79 #endif // USE_COLOURDLG_GENERIC
81 #if USE_DIRDLG_GENERIC
82 #include "wx/generic/dirdlgg.h"
83 #endif // USE_DIRDLG_GENERIC
85 #if USE_FILEDLG_GENERIC
86 #include "wx/generic/filedlgg.h"
87 #endif // USE_FILEDLG_GENERIC
89 #if USE_FONTDLG_GENERIC
90 #include "wx/generic/fontdlgg.h"
91 #endif // USE_FONTDLG_GENERIC
95 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
96 EVT_PAINT(MyCanvas::OnPaint
)
101 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
102 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
105 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
106 #endif // wxUSE_COLOURDLG
109 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
110 #endif // wxUSE_FONTDLG
113 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
114 #endif // wxUSE_LOG_DIALOG
117 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
118 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
119 #endif // wxUSE_TEXTDLG
122 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
123 #endif // wxUSE_NUMBERDLG
126 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
127 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
128 #endif // wxUSE_CHOICEDLG
131 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
132 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
133 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
134 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
135 #endif // wxUSE_FILEDLG
137 #if USE_FILEDLG_GENERIC
138 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC
, MyFrame::FileOpenGeneric
)
139 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC
, MyFrame::FilesOpenGeneric
)
140 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC
, MyFrame::FileSaveGeneric
)
141 #endif // USE_FILEDLG_GENERIC
144 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
145 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
146 #endif // wxUSE_DIRDLG
148 #if USE_MODAL_PRESENTATION
149 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
150 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
153 #if wxUSE_STARTUP_TIPS
154 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
155 #endif // wxUSE_STARTUP_TIPS
157 #if USE_FONTDLG_GENERIC
158 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
159 #endif // USE_FONTDLG_GENERIC
161 #if USE_DIRDLG_GENERIC
162 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
163 #endif // wxMSW || wxMAC
165 #if USE_COLOURDLG_GENERIC
166 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
167 #endif // USE_COLOURDLG_GENERIC
169 #if wxUSE_PROGRESSDLG
170 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
171 #endif // wxUSE_PROGRESSDLG
174 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
175 #endif // wxUSE_BUSYINFO
177 #if wxUSE_FINDREPLDLG
178 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
179 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
181 EVT_FIND(wxID_ANY
, MyFrame::OnFindDialog
)
182 EVT_FIND_NEXT(wxID_ANY
, MyFrame::OnFindDialog
)
183 EVT_FIND_REPLACE(wxID_ANY
, MyFrame::OnFindDialog
)
184 EVT_FIND_REPLACE_ALL(wxID_ANY
, MyFrame::OnFindDialog
)
185 EVT_FIND_CLOSE(wxID_ANY
, MyFrame::OnFindDialog
)
186 #endif // wxUSE_FINDREPLDLG
188 EVT_MENU(DIALOGS_REQUEST
, MyFrame::OnRequestUserAttention
)
190 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
193 #if USE_MODAL_PRESENTATION
195 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
196 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
199 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
200 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
201 EVT_CLOSE(MyModelessDialog::OnClose
)
204 #endif // USE_MODAL_PRESENTATION
206 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
208 // `Main program' equivalent, creating windows and returning main app frame
212 wxInitAllImageHandlers();
215 m_canvasTextColour
= wxColour(_T("BLACK"));
216 m_canvasFont
= *wxNORMAL_FONT
;
218 // Create the main frame window
219 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWidgets dialogs example"));
222 wxMenu
*file_menu
= new wxMenu
;
224 file_menu
->Append(DIALOGS_MESSAGE_BOX
, _T("&Message box\tCtrl-M"));
227 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
229 wxMenu
*choices_menu
= new wxMenu
;
232 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, _T("&Choose colour"));
233 #endif // wxUSE_COLOURDLG
236 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, _T("Choose &font"));
237 #endif // wxUSE_FONTDLG
240 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, _T("&Single choice\tCtrl-C"));
241 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, _T("M&ultiple choice\tCtrl-U"));
242 #endif // wxUSE_CHOICEDLG
244 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
245 choices_menu
->AppendSeparator();
246 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
248 #if USE_COLOURDLG_GENERIC
249 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, _T("&Choose colour (generic)"));
250 #endif // USE_COLOURDLG_GENERIC
252 #if USE_FONTDLG_GENERIC
253 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, _T("Choose &font (generic)"));
254 #endif // USE_FONTDLG_GENERIC
256 file_menu
->Append(wxID_ANY
,_T("&Choices and selectors"),choices_menu
);
257 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
260 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
262 wxMenu
*entry_menu
= new wxMenu
;
265 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, _T("Text &entry\tCtrl-E"));
266 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, _T("&Password entry\tCtrl-P"));
267 #endif // wxUSE_TEXTDLG
270 entry_menu
->Append(DIALOGS_NUM_ENTRY
, _T("&Numeric entry\tCtrl-N"));
271 #endif // wxUSE_NUMBERDLG
273 file_menu
->Append(wxID_ANY
,_T("&Entry dialogs"),entry_menu
);
275 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
280 wxMenu
*filedlg_menu
= new wxMenu
;
281 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, _T("&Open file\tCtrl-O"));
282 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, _T("&Second open file\tCtrl-2"));
283 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, _T("Open &files\tCtrl-Q"));
284 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, _T("Sa&ve file\tCtrl-S"));
286 #if USE_FILEDLG_GENERIC
287 filedlg_menu
->AppendSeparator();
288 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, _T("&Open file (generic)"));
289 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, _T("Open &files (generic)"));
290 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, _T("Sa&ve file (generic)"));
291 #endif // USE_FILEDLG_GENERIC
293 file_menu
->Append(wxID_ANY
,_T("&File operations"),filedlg_menu
);
295 #endif // wxUSE_FILEDLG
298 wxMenu
*dir_menu
= new wxMenu
;
300 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, _T("&Choose a directory\tCtrl-D"));
301 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
302 file_menu
->Append(wxID_ANY
,_T("&Directory operations"),dir_menu
);
304 #if USE_DIRDLG_GENERIC
305 dir_menu
->AppendSeparator();
306 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, _T("&Choose a directory (generic)"));
307 #endif // USE_DIRDLG_GENERIC
309 #endif // wxUSE_DIRDLG
312 #if wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
314 wxMenu
*info_menu
= new wxMenu
;
316 #if wxUSE_STARTUP_TIPS
317 info_menu
->Append(DIALOGS_TIP
, _T("&Tip of the day\tCtrl-T"));
318 #endif // wxUSE_STARTUP_TIPS
320 #if wxUSE_PROGRESSDLG
321 info_menu
->Append(DIALOGS_PROGRESS
, _T("Pro&gress dialog\tCtrl-G"));
322 #endif // wxUSE_PROGRESSDLG
325 info_menu
->Append(DIALOGS_BUSYINFO
, _T("&Busy info dialog\tCtrl-B"));
326 #endif // wxUSE_BUSYINFO
329 info_menu
->Append(DIALOGS_LOG_DIALOG
, _T("&Log dialog\tCtrl-L"));
330 #endif // wxUSE_LOG_DIALOG
332 file_menu
->Append(wxID_ANY
,_T("&Informative dialogs"),info_menu
);
334 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
337 #if wxUSE_FINDREPLDLG
338 wxMenu
*find_menu
= new wxMenu
;
339 find_menu
->AppendCheckItem(DIALOGS_FIND
, _T("&Find dialog\tCtrl-F"));
340 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, _T("Find and &replace dialog\tShift-Ctrl-F"));
341 file_menu
->Append(wxID_ANY
,_T("&Searching"),find_menu
);
342 #endif // wxUSE_FINDREPLDLG
344 #if USE_MODAL_PRESENTATION
345 wxMenu
*modal_menu
= new wxMenu
;
346 modal_menu
->Append(DIALOGS_MODAL
, _T("Mo&dal dialog\tCtrl-W"));
347 modal_menu
->AppendCheckItem(DIALOGS_MODELESS
, _T("Modeless &dialog\tCtrl-Z"));
348 file_menu
->Append(wxID_ANY
,_T("&Modal/Modeless"),modal_menu
);
349 #endif // USE_MODAL_PRESENTATION
351 file_menu
->Append(DIALOGS_REQUEST
, _T("&Request user attention\tCtrl-R"));
353 file_menu
->AppendSeparator();
354 file_menu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"));
356 wxMenuBar
*menu_bar
= new wxMenuBar
;
357 menu_bar
->Append(file_menu
, _T("&File"));
358 frame
->SetMenuBar(menu_bar
);
360 myCanvas
= new MyCanvas(frame
);
361 myCanvas
->SetBackgroundColour(*wxWHITE
);
363 frame
->Centre(wxBOTH
);
373 // My frame constructor
374 MyFrame::MyFrame(wxWindow
*parent
,
375 const wxString
& title
)
376 : wxFrame(parent
, wxID_ANY
, title
)
378 #if USE_MODAL_PRESENTATION
379 m_dialog
= (MyModelessDialog
*)NULL
;
380 #endif // USE_MODAL_PRESENTATION
382 #if wxUSE_FINDREPLDLG
388 m_clrData
.SetChooseFull(true);
389 for (int i
= 0; i
< 16; i
++)
391 m_clrData
.SetCustomColour(
394 (unsigned char)(i
*16),
395 (unsigned char)(i
*16),
396 (unsigned char)(i
*16)
400 #endif // wxUSE_COLOURDLG
404 #endif // wxUSE_STATUSBAR
408 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
410 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
412 wxColourDialog
dialog(this, &m_clrData
);
413 dialog
.SetTitle(_T("Choose the background colour"));
414 if (dialog
.ShowModal() == wxID_OK
)
416 m_clrData
= dialog
.GetColourData();
417 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
418 myCanvas
->ClearBackground();
422 #endif // wxUSE_COLOURDLG
424 #if USE_COLOURDLG_GENERIC
425 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
427 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
429 //FIXME:TODO:This has no effect...
430 m_clrData
.SetChooseFull(true);
432 for (int i
= 0; i
< 16; i
++)
435 (unsigned char)(i
*16),
436 (unsigned char)(i
*16),
437 (unsigned char)(i
*16)
439 m_clrData
.SetCustomColour(i
, colour
);
442 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &m_clrData
);
443 if (dialog
->ShowModal() == wxID_OK
)
445 m_clrData
= dialog
->GetColourData();
446 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
447 myCanvas
->ClearBackground();
452 #endif // USE_COLOURDLG_GENERIC
455 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
458 data
.SetInitialFont(wxGetApp().m_canvasFont
);
459 data
.SetColour(wxGetApp().m_canvasTextColour
);
461 // you might also do this:
463 // wxFontDialog dialog;
464 // if ( !dialog.Create(this, data) { ... error ... }
466 wxFontDialog
dialog(this, data
);
468 if (dialog
.ShowModal() == wxID_OK
)
470 wxFontData retData
= dialog
.GetFontData();
471 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
472 wxGetApp().m_canvasTextColour
= retData
.GetColour();
475 //else: cancelled by the user, don't change the font
477 #endif // wxUSE_FONTDLG
479 #if USE_FONTDLG_GENERIC
480 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
483 data
.SetInitialFont(wxGetApp().m_canvasFont
);
484 data
.SetColour(wxGetApp().m_canvasTextColour
);
486 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, &data
);
487 if (dialog
->ShowModal() == wxID_OK
)
489 wxFontData retData
= dialog
->GetFontData();
490 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
491 wxGetApp().m_canvasTextColour
= retData
.GetColour();
496 #endif // USE_FONTDLG_GENERIC
499 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
501 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
502 // being flushed -- test it
505 wxLogMessage(wxT("This is some message - everything is ok so far."));
506 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
507 wxLogWarning(wxT("And then something went wrong!"));
509 // and if ~wxBusyCursor doesn't do it, then call it manually
513 wxLogError(wxT("Intermediary error handler decided to abort."));
514 wxLogError(wxT("The top level caller detected an unrecoverable error."));
516 wxLog::FlushActive();
518 wxLogMessage(wxT("And this is the same dialog but with only one message."));
520 #endif // wxUSE_LOG_DIALOG
522 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
524 wxMessageDialog
dialog( NULL
, _T("This is a message box\nA long, long string to test out the message box properly"),
525 _T("Message box text"), wxNO_DEFAULT
|wxYES_NO
|wxCANCEL
|wxICON_INFORMATION
);
527 switch ( dialog
.ShowModal() )
530 wxLogStatus(wxT("You pressed \"Yes\""));
534 wxLogStatus(wxT("You pressed \"No\""));
538 wxLogStatus(wxT("You pressed \"Cancel\""));
542 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
547 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
549 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
550 _T("Even two rows of text."),
551 _T("Enter a number:"), _T("Numeric input test"),
558 msg
= _T("Invalid number entered or dialog cancelled.");
563 msg
.Printf(_T("You've entered %lu"), res
);
564 icon
= wxICON_INFORMATION
;
567 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
569 #endif // wxUSE_NUMBERDLG
572 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
574 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
575 _T("Password entry dialog"),
580 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
581 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
585 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
587 wxTextEntryDialog
dialog(this,
588 _T("This is a small sample\n")
589 _T("A long, long string to test out the text entrybox"),
590 _T("Please enter a string"),
594 if (dialog
.ShowModal() == wxID_OK
)
596 wxMessageBox(dialog
.GetValue(), _T("Got string"), wxOK
| wxICON_INFORMATION
, this);
599 #endif // wxUSE_TEXTDLG
602 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
604 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
606 wxSingleChoiceDialog
dialog(this,
607 _T("This is a small sample\n")
608 _T("A single-choice convenience dialog"),
609 _T("Please select a value"),
610 WXSIZEOF(choices
), choices
);
612 dialog
.SetSelection(2);
614 if (dialog
.ShowModal() == wxID_OK
)
616 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
621 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
623 const wxString choices
[] =
625 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
626 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
627 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
630 wxArrayInt selections
;
631 size_t count
= wxGetMultipleChoices(selections
,
632 _T("This is a small sample\n")
633 _T("A multi-choice convenience dialog"),
634 _T("Please select a value"),
635 WXSIZEOF(choices
), choices
,
640 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
641 for ( size_t n
= 0; n
< count
; n
++ )
643 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
644 (unsigned)n
, (unsigned)selections
[n
],
645 choices
[selections
[n
]].c_str());
649 //else: cancelled or nothing selected
651 #endif // wxUSE_CHOICEDLG
654 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
659 _T("Testing open file dialog"),
663 _T("C++ files (*.cpp)|*.cpp")
665 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
669 dialog
.SetDirectory(wxGetHomeDir());
671 if (dialog
.ShowModal() == wxID_OK
)
674 info
.Printf(_T("Full file name: %s\n")
677 dialog
.GetPath().c_str(),
678 dialog
.GetDirectory().c_str(),
679 dialog
.GetFilename().c_str());
680 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
685 // this shows how to take advantage of specifying a default extension in the
686 // call to wxFileSelector: it is remembered after each new call and the next
687 // one will use it by default
688 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
690 static wxString s_extDef
;
691 wxString path
= wxFileSelector(
692 _T("Select the file to load"),
693 wxEmptyString
, wxEmptyString
,
697 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
698 wxFileSelectorDefaultWildcardStr
,
699 wxFileSelectorDefaultWildcardStr
708 // it is just a sample, would use wxSplitPath in real program
709 s_extDef
= path
.AfterLast(_T('.'));
711 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
712 (const wxChar
*) path
, (const wxChar
*) s_extDef
);
715 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
719 _T("C++ files (*.cpp)|*.cpp");
723 _T("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
724 wxFileSelectorDefaultWildcardStr
,
725 wxFileSelectorDefaultWildcardStr
728 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
729 wxEmptyString
, wxEmptyString
, wildcards
,
732 if (dialog
.ShowModal() == wxID_OK
)
734 wxArrayString paths
, filenames
;
736 dialog
.GetPaths(paths
);
737 dialog
.GetFilenames(filenames
);
740 size_t count
= paths
.GetCount();
741 for ( size_t n
= 0; n
< count
; n
++ )
743 s
.Printf(_T("File %d: %s (%s)\n"),
744 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
748 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
751 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
756 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
758 wxFileDialog
dialog(this,
759 _T("Testing save file dialog"),
762 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
763 wxSAVE
|wxOVERWRITE_PROMPT
);
765 dialog
.SetFilterIndex(1);
767 if (dialog
.ShowModal() == wxID_OK
)
769 wxLogMessage(_T("%s, filter %d"),
770 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
773 #endif // wxUSE_FILEDLG
775 #if USE_FILEDLG_GENERIC
776 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
778 wxGenericFileDialog dialog
781 _T("Testing open file dialog"),
784 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
787 dialog
.SetDirectory(wxGetHomeDir());
789 if (dialog
.ShowModal() == wxID_OK
)
792 info
.Printf(_T("Full file name: %s\n")
795 dialog
.GetPath().c_str(),
796 dialog
.GetDirectory().c_str(),
797 dialog
.GetFilename().c_str());
798 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
803 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
805 wxString wildcards
= _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
806 wxGenericFileDialog
dialog(this, _T("Testing open multiple file dialog"),
807 wxEmptyString
, wxEmptyString
, wildcards
,
810 if (dialog
.ShowModal() == wxID_OK
)
812 wxArrayString paths
, filenames
;
814 dialog
.GetPaths(paths
);
815 dialog
.GetFilenames(filenames
);
818 size_t count
= paths
.GetCount();
819 for ( size_t n
= 0; n
< count
; n
++ )
821 s
.Printf(_T("File %d: %s (%s)\n"),
822 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
826 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
829 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
834 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
836 wxGenericFileDialog
dialog(this,
837 _T("Testing save file dialog"),
840 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
841 wxSAVE
|wxOVERWRITE_PROMPT
);
843 dialog
.SetFilterIndex(1);
845 if (dialog
.ShowModal() == wxID_OK
)
847 wxLogMessage(_T("%s, filter %d"),
848 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
851 #endif // USE_FILEDLG_GENERIC
854 void MyFrame::DoDirChoose(int style
)
856 // pass some initial dir to wxDirDialog
858 wxGetHomeDir(&dirHome
);
860 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
862 if (dialog
.ShowModal() == wxID_OK
)
864 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
868 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
870 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_NEW_DIR_BUTTON
);
873 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
875 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_NEW_DIR_BUTTON
);
877 #endif // wxUSE_DIRDLG
879 #if USE_DIRDLG_GENERIC
880 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
882 // pass some initial dir to wxDirDialog
884 wxGetHomeDir(&dirHome
);
886 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
888 if (dialog
.ShowModal() == wxID_OK
)
890 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
894 #endif // USE_DIRDLG_GENERIC
896 #if USE_MODAL_PRESENTATION
897 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
899 MyModalDialog
dlg(this);
903 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
905 bool show
= GetMenuBar()->IsChecked(event
.GetId());
911 m_dialog
= new MyModelessDialog(this);
914 m_dialog
->Show(true);
918 // If m_dialog is NULL, then possibly the system
919 // didn't report the checked menu item status correctly.
920 // It should be true just after the menu item was selected,
921 // if there was no modeless dialog yet.
923 wxASSERT( m_dialog
!= NULL
);
928 #endif // USE_MODAL_PRESENTATION
930 #if wxUSE_STARTUP_TIPS
931 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
933 static size_t s_index
= (size_t)-1;
935 if ( s_index
== (size_t)-1 )
939 // this is completely bogus, we don't know how many lines are there
940 // in the file, but who cares, it's a demo only...
941 s_index
= rand() % 5;
944 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
946 bool showAtStartup
= wxShowTip(this, tipProvider
);
950 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
951 wxOK
| wxICON_INFORMATION
, this);
954 s_index
= tipProvider
->GetCurrentTip();
957 #endif // wxUSE_STARTUP_TIPS
959 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
961 wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window"));
965 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
968 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
973 #if wxUSE_PROGRESSDLG
975 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
977 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
978 // check the performance
979 int countrandomnumbers
= 0, count
= 0;
980 wxTimeSpan
tsTest(0,0,0,250);
981 wxDateTime DT2
, DT1
= wxDateTime::UNow();
986 ++countrandomnumbers
;
987 if ( countrandomnumbers
== 1000 )
990 countrandomnumbers
= 0;
992 DT2
= wxDateTime::UNow();
993 wxTimeSpan ts
= DT2
.Subtract( DT1
);
994 if ( ts
.IsLongerThan( tsTest
) )
1000 const int max
= 40 * count
;
1002 static const int max
= 10;
1003 #endif // wxUSE_STOPWATCH && wxUSE_LONGLONG
1005 wxProgressDialog
dialog(_T("Progress dialog example"),
1006 _T("An informative message"),
1012 // wxPD_AUTO_HIDE | -- try this as well
1014 wxPD_ESTIMATED_TIME
|
1015 wxPD_REMAINING_TIME
|
1020 // each skip will move progress about quarter forward
1021 for ( int i
= 0; i
<= max
; i
= wxMin(i
+(skip
?int(max
/4):1), max
+1), skip
= false )
1023 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
1024 // do (almost) the same operations as we did for the performance test
1026 for ( int j
= 0; j
< 1000; j
++ )
1031 DT2
= wxDateTime::UNow();
1032 wxTimeSpan ts
= DT2
.Subtract( DT1
);
1033 if ( ts
.IsLongerThan( tsTest
) )
1047 msg
= _T("That's all, folks!");
1049 else if ( i
> max
/ 2 )
1051 msg
= _T("Only a half left (very long message)!");
1054 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
1055 if ( (i
% (max
/100)) == 0 ) // // only 100 updates, this makes it much faster
1057 cont
= dialog
.Update(i
, msg
, &skip
);
1060 cont
= dialog
.Update(i
, msg
, &skip
);
1065 if ( wxMessageBox(_T("Do you really want to cancel?"),
1066 _T("Progress dialog question"), // caption
1067 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
1077 wxLogStatus(wxT("Progress dialog aborted!"));
1081 wxLogStatus(wxT("Countdown from %d finished"), max
);
1085 #endif // wxUSE_PROGRESSDLG
1089 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
1091 wxWindowDisabler disableAll
;
1093 wxBusyInfo
info(_T("Working, please wait..."), this);
1095 for ( int i
= 0; i
< 18; i
++ )
1105 #endif // wxUSE_BUSYINFO
1107 #if wxUSE_FINDREPLDLG
1109 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
1113 delete m_dlgReplace
;
1114 m_dlgReplace
= NULL
;
1118 m_dlgReplace
= new wxFindReplaceDialog
1122 _T("Find and replace dialog"),
1126 m_dlgReplace
->Show(true);
1130 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
1139 m_dlgFind
= new wxFindReplaceDialog
1148 m_dlgFind
->Show(true);
1152 static wxString
DecodeFindDialogEventFlags(int flags
)
1155 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
1156 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
1157 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
1158 << _T("case sensitive");
1163 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
1165 wxEventType type
= event
.GetEventType();
1167 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
1169 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1170 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
1171 event
.GetFindString().c_str(),
1172 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1174 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
1175 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
1177 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1178 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
1179 event
.GetFindString().c_str(),
1180 event
.GetReplaceString().c_str(),
1181 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1183 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
1185 wxFindReplaceDialog
*dlg
= event
.GetDialog();
1189 if ( dlg
== m_dlgFind
)
1192 idMenu
= DIALOGS_FIND
;
1195 else if ( dlg
== m_dlgReplace
)
1197 txt
= _T("Replace");
1198 idMenu
= DIALOGS_REPLACE
;
1199 m_dlgReplace
= NULL
;
1203 txt
= _T("Unknown");
1206 wxFAIL_MSG( _T("unexpected event") );
1209 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1211 if ( idMenu
!= wxID_ANY
)
1213 GetMenuBar()->Check(idMenu
, false);
1220 wxLogError(wxT("Unknown find dialog event!"));
1224 #endif // wxUSE_FINDREPLDLG
1226 // ----------------------------------------------------------------------------
1228 // ----------------------------------------------------------------------------
1230 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1233 dc
.SetFont(wxGetApp().m_canvasFont
);
1234 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
1235 dc
.SetBackgroundMode(wxTRANSPARENT
);
1237 _T("wxWidgets common dialogs")
1238 #if !defined(__SMARTPHONE__)
1239 _T(" test application")
1244 #if USE_MODAL_PRESENTATION
1246 // ----------------------------------------------------------------------------
1248 // ----------------------------------------------------------------------------
1250 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1251 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modeless dialog")))
1253 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1255 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
1256 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, _T("Should be disabled"));
1259 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1260 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1264 sizerTop
->SetSizeHints(this);
1265 sizerTop
->Fit(this);
1268 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1270 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1271 wxOK
| wxICON_INFORMATION
, this);
1274 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1276 if ( event
.CanVeto() )
1278 wxMessageBox(_T("Use the menu item to close this dialog"),
1279 _T("Modeless dialog"),
1280 wxOK
| wxICON_INFORMATION
, this);
1286 // ----------------------------------------------------------------------------
1288 // ----------------------------------------------------------------------------
1290 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1291 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modal dialog")))
1293 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1295 m_btnModal
= new wxButton(this, wxID_ANY
, _T("&Modal dialog..."));
1296 m_btnModeless
= new wxButton(this, wxID_ANY
, _T("Mode&less dialog"));
1297 m_btnDelete
= new wxButton(this, wxID_ANY
, _T("&Delete button"));
1299 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
1300 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
1301 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
1302 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
1303 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
1307 sizerTop
->SetSizeHints(this);
1308 sizerTop
->Fit(this);
1310 m_btnModal
->SetFocus();
1311 m_btnModal
->SetDefault();
1314 void MyModalDialog::OnButton(wxCommandEvent
& event
)
1316 if ( event
.GetEventObject() == m_btnDelete
)
1321 m_btnDelete
->Disable();
1323 else if ( event
.GetEventObject() == m_btnModal
)
1326 wxGetTextFromUser(_T("Dummy prompt"),
1327 _T("Modal dialog called from dialog"),
1328 wxEmptyString
, this);
1330 wxMessageBox(_T("Modal dialog called from dialog"));
1331 #endif // wxUSE_TEXTDLG
1333 else if ( event
.GetEventObject() == m_btnModeless
)
1335 (new MyModelessDialog(this))->Show();
1343 #endif // USE_MODAL_PRESENTATION