1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart
5 // Modified by: ABX (2004) - adjustementd for conditional building
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 #include "wx/progdlg.h"
45 #endif // wxUSE_PROGRESSDLG
48 #include "wx/busyinfo.h"
49 #endif // wxUSE_BUSYINFO
52 #include "wx/numdlg.h"
53 #endif // wxUSE_NUMBERDLG
56 #include "wx/filedlg.h"
57 #endif // wxUSE_FILEDLG
60 #include "wx/dirdlg.h"
61 #endif // wxUSE_DIRDLG
64 #include "wx/fontdlg.h"
65 #endif // wxUSE_FONTDLG
68 #include "wx/fdrepdlg.h"
69 #endif // wxUSE_FINDREPLDLG
73 #if USE_COLOURDLG_GENERIC
74 #include "wx/generic/colrdlgg.h"
75 #endif // USE_COLOURDLG_GENERIC
77 #if USE_FONTDLG_GENERIC
78 #include "wx/generic/fontdlgg.h"
79 #endif // USE_FONTDLG_GENERIC
81 #if USE_DIRDLG_GENERIC
82 #include "wx/generic/dirdlgg.h"
83 #endif // USE_DIRDLG_GENERIC
87 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
88 EVT_PAINT(MyCanvas::OnPaint
)
93 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
94 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
97 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
98 #endif // wxUSE_COLOURDLG
101 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
102 #endif // wxUSE_FONTDLG
105 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
106 #endif // wxUSE_LOG_DIALOG
109 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
110 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
111 #endif // wxUSE_TEXTDLG
114 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
115 #endif // wxUSE_NUMBERDLG
118 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
119 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
120 #endif // wxUSE_CHOICEDLG
123 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
124 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
125 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
126 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
127 #endif // wxUSE_FILEDLG
130 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
131 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
132 #endif // wxUSE_DIRDLG
134 #if USE_MODAL_PRESENTATION
135 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
136 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
139 #if wxUSE_STARTUP_TIPS
140 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
141 #endif // wxUSE_STARTUP_TIPS
143 #if USE_FONTDLG_GENERIC
144 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
145 #endif // USE_FONTDLG_GENERIC
147 #if USE_DIRDLG_GENERIC
148 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
149 #endif // wxMSW || wxMAC
151 #if USE_COLOURDLG_GENERIC
152 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
153 #endif // USE_COLOURDLG_GENERIC
155 #if wxUSE_PROGRESSDLG
156 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
157 #endif // wxUSE_PROGRESSDLG
160 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
161 #endif // wxUSE_BUSYINFO
163 #if wxUSE_FINDREPLDLG
164 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
165 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
167 EVT_FIND(wxID_ANY
, MyFrame::OnFindDialog
)
168 EVT_FIND_NEXT(wxID_ANY
, MyFrame::OnFindDialog
)
169 EVT_FIND_REPLACE(wxID_ANY
, MyFrame::OnFindDialog
)
170 EVT_FIND_REPLACE_ALL(wxID_ANY
, MyFrame::OnFindDialog
)
171 EVT_FIND_CLOSE(wxID_ANY
, MyFrame::OnFindDialog
)
172 #endif // wxUSE_FINDREPLDLG
174 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
177 #if USE_MODAL_PRESENTATION
179 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
180 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
183 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
184 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
185 EVT_CLOSE(MyModelessDialog::OnClose
)
188 #endif // USE_MODAL_PRESENTATION
190 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
192 // `Main program' equivalent, creating windows and returning main app frame
196 wxInitAllImageHandlers();
199 #if defined(__WXGTK__) && defined(wxUSE_UNICODE)
200 wxConvCurrent
= &wxConvLibc
;
203 m_canvasTextColour
= wxColour(_T("BLACK"));
204 m_canvasFont
= *wxNORMAL_FONT
;
206 // Create the main frame window
207 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWidgets dialogs example"));
210 wxMenu
*file_menu
= new wxMenu
;
212 file_menu
->Append(DIALOGS_MESSAGE_BOX
, _T("&Message box\tCtrl-M"));
215 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
217 wxMenu
*choices_menu
= new wxMenu
;
220 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, _T("&Choose colour"));
221 #endif // wxUSE_COLOURDLG
223 #if USE_COLOURDLG_GENERIC
224 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, _T("&Choose colour (generic)"));
225 #endif // USE_COLOURDLG_GENERIC
228 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, _T("Choose &font"));
229 #endif // wxUSE_FONTDLG
231 #if USE_FONTDLG_GENERIC
232 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, _T("Choose &font (generic)"));
233 #endif // USE_FONTDLG_GENERIC
236 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, _T("&Single choice\tCtrl-C"));
237 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, _T("M&ultiple choice\tCtrl-U"));
238 #endif // wxUSE_CHOICEDLG
240 file_menu
->Append(wxID_ANY
,_T("Choices and selectors"),choices_menu
);
242 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
245 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
247 wxMenu
*entry_menu
= new wxMenu
;
250 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, _T("Text &entry\tCtrl-E"));
251 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, _T("&Password entry\tCtrl-P"));
252 #endif // wxUSE_TEXTDLG
255 entry_menu
->Append(DIALOGS_NUM_ENTRY
, _T("&Numeric entry\tCtrl-N"));
256 #endif // wxUSE_NUMBERDLG
258 file_menu
->Append(wxID_ANY
,_T("Entry dialogs"),entry_menu
);
260 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
265 wxMenu
*filedlg_menu
= new wxMenu
;
266 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, _T("&Open file\tCtrl-O"));
267 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, _T("&Second open file\tCtrl-2"));
268 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, _T("Open &files\tCtrl-Q"));
269 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, _T("Sa&ve file\tCtrl-S"));
270 file_menu
->Append(wxID_ANY
,_T("File operations"),filedlg_menu
);
272 #endif // wxUSE_FILEDLG
275 wxMenu
*dir_menu
= new wxMenu
;
277 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, _T("&Choose a directory\tCtrl-D"));
279 #if USE_DIRDLG_GENERIC
280 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, _T("&Choose a directory (generic)"));
281 #endif // USE_DIRDLG_GENERIC
283 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
284 file_menu
->Append(wxID_ANY
,_T("Directory operations"),dir_menu
);
286 #endif // wxUSE_DIRDLG
289 #if wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
291 wxMenu
*info_menu
= new wxMenu
;
293 #if wxUSE_STARTUP_TIPS
294 info_menu
->Append(DIALOGS_TIP
, _T("&Tip of the day\tCtrl-T"));
295 #endif // wxUSE_STARTUP_TIPS
297 #if wxUSE_PROGRESSDLG
298 info_menu
->Append(DIALOGS_PROGRESS
, _T("Pro&gress dialog\tCtrl-G"));
299 #endif // wxUSE_PROGRESSDLG
302 info_menu
->Append(DIALOGS_BUSYINFO
, _T("&Busy info dialog\tCtrl-B"));
303 #endif // wxUSE_BUSYINFO
306 info_menu
->Append(DIALOGS_LOG_DIALOG
, _T("&Log dialog\tCtrl-L"));
307 #endif // wxUSE_LOG_DIALOG
309 file_menu
->Append(wxID_ANY
,_T("Informative dialogs"),info_menu
);
311 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
314 #if wxUSE_FINDREPLDLG
315 wxMenu
*find_menu
= new wxMenu
;
316 find_menu
->AppendCheckItem(DIALOGS_FIND
, _T("&Find dialog\tCtrl-F"));
317 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, _T("Find and &replace dialog\tShift-Ctrl-F"));
318 file_menu
->Append(wxID_ANY
,_T("Searching"),find_menu
);
319 #endif // wxUSE_FINDREPLDLG
321 #if USE_MODAL_PRESENTATION
322 wxMenu
*modal_menu
= new wxMenu
;
323 modal_menu
->Append(DIALOGS_MODAL
, _T("Mo&dal dialog\tCtrl-W"));
324 modal_menu
->AppendCheckItem(DIALOGS_MODELESS
, _T("Modeless &dialog\tCtrl-Z"));
325 file_menu
->Append(wxID_ANY
,_T("Modal/Modeless"),modal_menu
);
326 #endif // USE_MODAL_PRESENTATION
328 file_menu
->AppendSeparator();
329 file_menu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"));
331 #if !defined( __SMARTPHONE__ )
332 wxMenuBar
*menu_bar
= new wxMenuBar
;
333 menu_bar
->Append(file_menu
, _T("&File"));
334 frame
->SetMenuBar(menu_bar
);
336 frame
->SetRightMenu(wxID_ANY
, _T("Menu"), file_menu
);
337 #endif // __SMARTPHONE__
339 myCanvas
= new MyCanvas(frame
);
340 myCanvas
->SetBackgroundColour(*wxWHITE
);
342 frame
->Centre(wxBOTH
);
352 // My frame constructor
353 MyFrame::MyFrame(wxWindow
*parent
,
354 const wxString
& title
)
355 : wxFrame(parent
, wxID_ANY
, title
)
357 #if USE_MODAL_PRESENTATION
358 m_dialog
= (MyModelessDialog
*)NULL
;
359 #endif // USE_MODAL_PRESENTATION
361 #if wxUSE_FINDREPLDLG
367 m_clrData
.SetChooseFull(true);
368 for (int i
= 0; i
< 16; i
++)
370 m_clrData
.SetCustomColour(i
, wxColour(i
*16, i
*16, i
*16));
372 #endif // wxUSE_COLOURDLG
376 #endif // wxUSE_STATUSBAR
380 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
382 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
384 wxColourDialog
dialog(this, &m_clrData
);
385 dialog
.SetTitle(_T("Choose the background colour"));
386 if (dialog
.ShowModal() == wxID_OK
)
388 m_clrData
= dialog
.GetColourData();
389 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
390 myCanvas
->ClearBackground();
394 #endif // wxUSE_COLOURDLG
397 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
400 data
.SetInitialFont(wxGetApp().m_canvasFont
);
401 data
.SetColour(wxGetApp().m_canvasTextColour
);
403 // you might also do this:
405 // wxFontDialog dialog;
406 // if ( !dialog.Create(this, data) { ... error ... }
408 wxFontDialog
dialog(this, data
);
410 if (dialog
.ShowModal() == wxID_OK
)
412 wxFontData retData
= dialog
.GetFontData();
413 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
414 wxGetApp().m_canvasTextColour
= retData
.GetColour();
417 //else: cancelled by the user, don't change the font
419 #endif // wxUSE_FONTDLG
421 #if USE_COLOURDLG_GENERIC
422 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
425 data
.SetChooseFull(true);
426 for (int i
= 0; i
< 16; i
++)
428 wxColour
colour(i
*16, i
*16, i
*16);
429 data
.SetCustomColour(i
, colour
);
432 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &data
);
433 if (dialog
->ShowModal() == wxID_OK
)
435 wxColourData retData
= dialog
->GetColourData();
436 wxColour col
= retData
.GetColour();
437 // wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
438 myCanvas
->SetBackgroundColour(col
);
439 myCanvas
->ClearBackground();
444 #endif // USE_COLOURDLG_GENERIC
446 #if USE_FONTDLG_GENERIC
447 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
450 data
.SetInitialFont(wxGetApp().m_canvasFont
);
451 data
.SetColour(wxGetApp().m_canvasTextColour
);
453 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, &data
);
454 if (dialog
->ShowModal() == wxID_OK
)
456 wxFontData retData
= dialog
->GetFontData();
457 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
458 wxGetApp().m_canvasTextColour
= retData
.GetColour();
463 #endif // USE_FONTDLG_GENERIC
465 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
467 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
468 // being flushed -- test it
471 wxLogMessage(wxT("This is some message - everything is ok so far."));
472 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
473 wxLogWarning(wxT("And then something went wrong!"));
475 // and if ~wxBusyCursor doesn't do it, then call it manually
479 wxLogError(wxT("Intermediary error handler decided to abort."));
480 wxLogError(wxT("The top level caller detected an unrecoverable error."));
482 wxLog::FlushActive();
484 wxLogMessage(wxT("And this is the same dialog but with only one message."));
487 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
489 wxMessageDialog
dialog( NULL
, _T("This is a message box\nA long, long string to test out the message box properly"),
490 _T("Message box text"), wxNO_DEFAULT
|wxYES_NO
|wxCANCEL
|wxICON_INFORMATION
);
492 switch ( dialog
.ShowModal() )
495 wxLogStatus(wxT("You pressed \"Yes\""));
499 wxLogStatus(wxT("You pressed \"No\""));
503 wxLogStatus(wxT("You pressed \"Cancel\""));
507 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
512 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
514 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
515 _T("Even two rows of text."),
516 _T("Enter a number:"), _T("Numeric input test"),
523 msg
= _T("Invalid number entered or dialog cancelled.");
528 msg
.Printf(_T("You've entered %lu"), res
);
529 icon
= wxICON_INFORMATION
;
532 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
534 #endif // wxUSE_NUMBERDLG
537 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
539 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
540 _T("Password entry dialog"),
545 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
546 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
550 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
552 wxTextEntryDialog
dialog(this,
553 _T("This is a small sample\n")
554 _T("A long, long string to test out the text entrybox"),
555 _T("Please enter a string"),
559 if (dialog
.ShowModal() == wxID_OK
)
561 wxMessageDialog
dialog2(this, dialog
.GetValue(), _T("Got string"));
565 #endif // wxUSE_TEXTDLG
568 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
570 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
572 wxSingleChoiceDialog
dialog(this,
573 _T("This is a small sample\n")
574 _T("A single-choice convenience dialog"),
575 _T("Please select a value"),
576 WXSIZEOF(choices
), choices
);
578 dialog
.SetSelection(2);
580 if (dialog
.ShowModal() == wxID_OK
)
582 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
587 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
589 const wxString choices
[] =
591 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
592 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
593 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
596 wxArrayInt selections
;
597 size_t count
= wxGetMultipleChoices(selections
,
598 _T("This is a small sample\n")
599 _T("A multi-choice convenience dialog"),
600 _T("Please select a value"),
601 WXSIZEOF(choices
), choices
,
606 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
607 for ( size_t n
= 0; n
< count
; n
++ )
609 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
610 (unsigned)n
, (unsigned)selections
[n
],
611 choices
[selections
[n
]].c_str());
615 //else: cancelled or nothing selected
617 #endif // wxUSE_CHOICEDLG
620 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
625 _T("Testing open file dialog"),
629 _T("C++ files (*.cpp)|*.cpp")
631 _T("C++ files (*.h;*.cpp)|*.h;*.cpp")
635 dialog
.SetDirectory(wxGetHomeDir());
637 if (dialog
.ShowModal() == wxID_OK
)
640 info
.Printf(_T("Full file name: %s\n")
643 dialog
.GetPath().c_str(),
644 dialog
.GetDirectory().c_str(),
645 dialog
.GetFilename().c_str());
646 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
651 // this shows how to take advantage of specifying a default extension in the
652 // call to wxFileSelector: it is remembered after each new call and the next
653 // one will use it by default
654 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
656 static wxString s_extDef
;
657 wxString path
= wxFileSelector(
658 _T("Select the file to load"),
659 wxEmptyString
, wxEmptyString
,
661 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
669 // it is just a sample, would use wxSplitPath in real program
670 s_extDef
= path
.AfterLast(_T('.'));
672 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
673 (const wxChar
*) path
, (const wxChar
*) s_extDef
);
676 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
680 _T("C++ files (*.cpp)|*.cpp");
682 _T("All files (*.*)|*.*|C++ files (*.h;*.cpp)|*.h;*.cpp");
684 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
685 wxEmptyString
, wxEmptyString
, wildcards
,
688 if (dialog
.ShowModal() == wxID_OK
)
690 wxArrayString paths
, filenames
;
692 dialog
.GetPaths(paths
);
693 dialog
.GetFilenames(filenames
);
696 size_t count
= paths
.GetCount();
697 for ( size_t n
= 0; n
< count
; n
++ )
699 s
.Printf(_T("File %d: %s (%s)\n"),
700 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
704 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
707 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
712 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
714 wxFileDialog
dialog(this,
715 _T("Testing save file dialog"),
718 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
719 wxSAVE
|wxOVERWRITE_PROMPT
);
721 dialog
.SetFilterIndex(1);
723 if (dialog
.ShowModal() == wxID_OK
)
725 wxLogMessage(_T("%s, filter %d"),
726 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
729 #endif // wxUSE_FILEDLG
732 void MyFrame::DoDirChoose(int style
)
734 // pass some initial dir to wxDirDialog
736 wxGetHomeDir(&dirHome
);
738 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
740 if (dialog
.ShowModal() == wxID_OK
)
742 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
746 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
748 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_NEW_DIR_BUTTON
);
751 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
753 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_NEW_DIR_BUTTON
);
755 #endif // wxUSE_DIRDLG
757 #if USE_DIRDLG_GENERIC
758 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
760 // pass some initial dir to wxDirDialog
762 wxGetHomeDir(&dirHome
);
764 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
766 if (dialog
.ShowModal() == wxID_OK
)
768 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
772 #endif // USE_DIRDLG_GENERIC
774 #if USE_MODAL_PRESENTATION
775 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
777 MyModalDialog
dlg(this);
781 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
783 bool show
= GetMenuBar()->IsChecked(event
.GetId());
789 m_dialog
= new MyModelessDialog(this);
792 m_dialog
->Show(true);
799 #endif // USE_MODAL_PRESENTATION
801 #if wxUSE_STARTUP_TIPS
802 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
804 static size_t s_index
= (size_t)-1;
806 if ( s_index
== (size_t)-1 )
810 // this is completely bogus, we don't know how many lines are there
811 // in the file, but who cares, it's a demo only...
812 s_index
= rand() % 5;
815 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
817 bool showAtStartup
= wxShowTip(this, tipProvider
);
821 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
822 wxOK
| wxICON_INFORMATION
, this);
825 s_index
= tipProvider
->GetCurrentTip();
828 #endif // wxUSE_STARTUP_TIPS
830 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
835 #if wxUSE_PROGRESSDLG
837 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
839 static const int max
= 10;
841 wxProgressDialog
dialog(_T("Progress dialog example"),
842 _T("An informative message"),
847 // wxPD_AUTO_HIDE | -- try this as well
849 wxPD_ESTIMATED_TIME
|
850 wxPD_REMAINING_TIME
);
853 for ( int i
= 0; i
<= max
; i
++ )
858 cont
= dialog
.Update(i
, _T("That's all, folks!"));
860 else if ( i
== max
/ 2 )
862 cont
= dialog
.Update(i
, _T("Only a half left (very long message)!"));
866 cont
= dialog
.Update(i
);
871 if ( wxMessageBox(_T("Do you really want to cancel?"),
872 _T("Progress dialog question"), // caption
873 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
882 wxLogStatus(wxT("Progress dialog aborted!"));
886 wxLogStatus(wxT("Countdown from %d finished"), max
);
890 #endif // wxUSE_PROGRESSDLG
894 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
896 wxWindowDisabler disableAll
;
898 wxBusyInfo
info(_T("Working, please wait..."), this);
900 for ( int i
= 0; i
< 18; i
++ )
910 #endif // wxUSE_BUSYINFO
912 #if wxUSE_FINDREPLDLG
914 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
923 m_dlgReplace
= new wxFindReplaceDialog
927 _T("Find and replace dialog"),
931 m_dlgReplace
->Show(true);
935 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
944 m_dlgFind
= new wxFindReplaceDialog
953 m_dlgFind
->Show(true);
957 static wxString
DecodeFindDialogEventFlags(int flags
)
960 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
961 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
962 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
963 << _T("case sensitive");
968 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
970 wxEventType type
= event
.GetEventType();
972 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
974 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
975 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
976 event
.GetFindString().c_str(),
977 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
979 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
980 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
982 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
983 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
984 event
.GetFindString().c_str(),
985 event
.GetReplaceString().c_str(),
986 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
988 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
990 wxFindReplaceDialog
*dlg
= event
.GetDialog();
994 if ( dlg
== m_dlgFind
)
997 idMenu
= DIALOGS_FIND
;
1000 else if ( dlg
== m_dlgReplace
)
1002 txt
= _T("Replace");
1003 idMenu
= DIALOGS_REPLACE
;
1004 m_dlgReplace
= NULL
;
1008 txt
= _T("Unknown");
1011 wxFAIL_MSG( _T("unexpected event") );
1014 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1016 if ( idMenu
!= wxID_ANY
)
1018 GetMenuBar()->Check(idMenu
, false);
1025 wxLogError(wxT("Unknown find dialog event!"));
1029 #endif // wxUSE_FINDREPLDLG
1031 // ----------------------------------------------------------------------------
1033 // ----------------------------------------------------------------------------
1035 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1038 dc
.SetFont(wxGetApp().m_canvasFont
);
1039 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
1040 dc
.SetBackgroundMode(wxTRANSPARENT
);
1041 dc
.DrawText(_T("wxWidgets common dialogs test application"), 10, 10);
1044 // ----------------------------------------------------------------------------
1046 // ----------------------------------------------------------------------------
1048 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1049 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modeless dialog")))
1051 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1053 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
1054 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, _T("Should be disabled"));
1057 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1058 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1062 sizerTop
->SetSizeHints(this);
1063 sizerTop
->Fit(this);
1066 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1068 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1069 wxOK
| wxICON_INFORMATION
, this);
1072 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1074 if ( event
.CanVeto() )
1076 wxMessageBox(_T("Use the menu item to close this dialog"),
1077 _T("Modeless dialog"),
1078 wxOK
| wxICON_INFORMATION
, this);
1084 // ----------------------------------------------------------------------------
1086 // ----------------------------------------------------------------------------
1088 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1089 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modal dialog")))
1091 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1093 m_btnModal
= new wxButton(this, wxID_ANY
, _T("&Modal dialog..."));
1094 m_btnModeless
= new wxButton(this, wxID_ANY
, _T("Mode&less dialog"));
1095 m_btnDelete
= new wxButton(this, wxID_ANY
, _T("&Delete button"));
1097 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
1098 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
1099 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
1100 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
1101 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
1105 sizerTop
->SetSizeHints(this);
1106 sizerTop
->Fit(this);
1108 m_btnModal
->SetFocus();
1109 m_btnModal
->SetDefault();
1112 void MyModalDialog::OnButton(wxCommandEvent
& event
)
1114 if ( event
.GetEventObject() == m_btnDelete
)
1119 m_btnDelete
->Disable();
1121 else if ( event
.GetEventObject() == m_btnModal
)
1124 wxGetTextFromUser(_T("Dummy prompt"),
1125 _T("Modal dialog called from dialog"),
1126 wxEmptyString
, this);
1128 wxMessageBox(_T("Modal dialog called from dialog"));
1129 #endif // wxUSE_TEXTDLG
1131 else if ( event
.GetEventObject() == m_btnModeless
)
1133 (new MyModelessDialog(this))->Show();