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 #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_DIRDLG_GENERIC
78 #include "wx/generic/dirdlgg.h"
79 #endif // USE_DIRDLG_GENERIC
81 #if USE_FILEDLG_GENERIC
82 #include "wx/generic/filedlgg.h"
83 #endif // USE_FILEDLG_GENERIC
85 #if USE_FONTDLG_GENERIC
86 #include "wx/generic/fontdlgg.h"
87 #endif // USE_FONTDLG_GENERIC
91 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
92 EVT_PAINT(MyCanvas::OnPaint
)
97 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
98 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
101 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
102 #endif // wxUSE_COLOURDLG
105 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
106 #endif // wxUSE_FONTDLG
109 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
110 #endif // wxUSE_LOG_DIALOG
113 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
114 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
115 #endif // wxUSE_TEXTDLG
118 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
119 #endif // wxUSE_NUMBERDLG
122 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
123 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
124 #endif // wxUSE_CHOICEDLG
127 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
128 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
129 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
130 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
131 #endif // wxUSE_FILEDLG
133 #if USE_FILEDLG_GENERIC
134 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC
, MyFrame::FileOpenGeneric
)
135 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC
, MyFrame::FilesOpenGeneric
)
136 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC
, MyFrame::FileSaveGeneric
)
137 #endif // USE_FILEDLG_GENERIC
140 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
141 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
142 #endif // wxUSE_DIRDLG
144 #if USE_MODAL_PRESENTATION
145 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
146 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
149 #if wxUSE_STARTUP_TIPS
150 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
151 #endif // wxUSE_STARTUP_TIPS
153 #if USE_FONTDLG_GENERIC
154 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
155 #endif // USE_FONTDLG_GENERIC
157 #if USE_DIRDLG_GENERIC
158 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
159 #endif // wxMSW || wxMAC
161 #if USE_COLOURDLG_GENERIC
162 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
163 #endif // USE_COLOURDLG_GENERIC
165 #if wxUSE_PROGRESSDLG
166 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
167 #endif // wxUSE_PROGRESSDLG
170 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
171 #endif // wxUSE_BUSYINFO
173 #if wxUSE_FINDREPLDLG
174 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
175 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
177 EVT_FIND(wxID_ANY
, MyFrame::OnFindDialog
)
178 EVT_FIND_NEXT(wxID_ANY
, MyFrame::OnFindDialog
)
179 EVT_FIND_REPLACE(wxID_ANY
, MyFrame::OnFindDialog
)
180 EVT_FIND_REPLACE_ALL(wxID_ANY
, MyFrame::OnFindDialog
)
181 EVT_FIND_CLOSE(wxID_ANY
, MyFrame::OnFindDialog
)
182 #endif // wxUSE_FINDREPLDLG
184 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
187 #if USE_MODAL_PRESENTATION
189 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
190 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
193 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
194 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
195 EVT_CLOSE(MyModelessDialog::OnClose
)
198 #endif // USE_MODAL_PRESENTATION
200 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
202 // `Main program' equivalent, creating windows and returning main app frame
206 wxInitAllImageHandlers();
209 m_canvasTextColour
= wxColour(_T("BLACK"));
210 m_canvasFont
= *wxNORMAL_FONT
;
212 // Create the main frame window
213 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWidgets dialogs example"));
216 wxMenu
*file_menu
= new wxMenu
;
218 file_menu
->Append(DIALOGS_MESSAGE_BOX
, _T("&Message box\tCtrl-M"));
221 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
223 wxMenu
*choices_menu
= new wxMenu
;
226 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, _T("&Choose colour"));
227 #endif // wxUSE_COLOURDLG
230 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, _T("Choose &font"));
231 #endif // wxUSE_FONTDLG
234 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, _T("&Single choice\tCtrl-C"));
235 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, _T("M&ultiple choice\tCtrl-U"));
236 #endif // wxUSE_CHOICEDLG
238 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
239 choices_menu
->AppendSeparator();
240 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
242 #if USE_COLOURDLG_GENERIC
243 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, _T("&Choose colour (generic)"));
244 #endif // USE_COLOURDLG_GENERIC
246 #if USE_FONTDLG_GENERIC
247 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, _T("Choose &font (generic)"));
248 #endif // USE_FONTDLG_GENERIC
250 file_menu
->Append(wxID_ANY
,_T("&Choices and selectors"),choices_menu
);
251 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
254 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
256 wxMenu
*entry_menu
= new wxMenu
;
259 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, _T("Text &entry\tCtrl-E"));
260 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, _T("&Password entry\tCtrl-P"));
261 #endif // wxUSE_TEXTDLG
264 entry_menu
->Append(DIALOGS_NUM_ENTRY
, _T("&Numeric entry\tCtrl-N"));
265 #endif // wxUSE_NUMBERDLG
267 file_menu
->Append(wxID_ANY
,_T("&Entry dialogs"),entry_menu
);
269 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
274 wxMenu
*filedlg_menu
= new wxMenu
;
275 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, _T("&Open file\tCtrl-O"));
276 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, _T("&Second open file\tCtrl-2"));
277 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, _T("Open &files\tCtrl-Q"));
278 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, _T("Sa&ve file\tCtrl-S"));
280 #if USE_FILEDLG_GENERIC
281 filedlg_menu
->AppendSeparator();
282 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, _T("&Open file (generic)"));
283 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, _T("Open &files (generic)"));
284 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, _T("Sa&ve file (generic)"));
285 #endif // USE_FILEDLG_GENERIC
287 file_menu
->Append(wxID_ANY
,_T("&File operations"),filedlg_menu
);
289 #endif // wxUSE_FILEDLG
292 wxMenu
*dir_menu
= new wxMenu
;
294 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, _T("&Choose a directory\tCtrl-D"));
295 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
296 file_menu
->Append(wxID_ANY
,_T("&Directory operations"),dir_menu
);
298 #if USE_DIRDLG_GENERIC
299 dir_menu
->AppendSeparator();
300 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, _T("&Choose a directory (generic)"));
301 #endif // USE_DIRDLG_GENERIC
303 #endif // wxUSE_DIRDLG
306 #if wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
308 wxMenu
*info_menu
= new wxMenu
;
310 #if wxUSE_STARTUP_TIPS
311 info_menu
->Append(DIALOGS_TIP
, _T("&Tip of the day\tCtrl-T"));
312 #endif // wxUSE_STARTUP_TIPS
314 #if wxUSE_PROGRESSDLG
315 info_menu
->Append(DIALOGS_PROGRESS
, _T("Pro&gress dialog\tCtrl-G"));
316 #endif // wxUSE_PROGRESSDLG
319 info_menu
->Append(DIALOGS_BUSYINFO
, _T("&Busy info dialog\tCtrl-B"));
320 #endif // wxUSE_BUSYINFO
323 info_menu
->Append(DIALOGS_LOG_DIALOG
, _T("&Log dialog\tCtrl-L"));
324 #endif // wxUSE_LOG_DIALOG
326 file_menu
->Append(wxID_ANY
,_T("&Informative dialogs"),info_menu
);
328 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
331 #if wxUSE_FINDREPLDLG
332 wxMenu
*find_menu
= new wxMenu
;
333 find_menu
->AppendCheckItem(DIALOGS_FIND
, _T("&Find dialog\tCtrl-F"));
334 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, _T("Find and &replace dialog\tShift-Ctrl-F"));
335 file_menu
->Append(wxID_ANY
,_T("&Searching"),find_menu
);
336 #endif // wxUSE_FINDREPLDLG
338 #if USE_MODAL_PRESENTATION
339 wxMenu
*modal_menu
= new wxMenu
;
340 modal_menu
->Append(DIALOGS_MODAL
, _T("Mo&dal dialog\tCtrl-W"));
341 modal_menu
->AppendCheckItem(DIALOGS_MODELESS
, _T("Modeless &dialog\tCtrl-Z"));
342 file_menu
->Append(wxID_ANY
,_T("&Modal/Modeless"),modal_menu
);
343 #endif // USE_MODAL_PRESENTATION
345 file_menu
->AppendSeparator();
346 file_menu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"));
348 wxMenuBar
*menu_bar
= new wxMenuBar
;
349 menu_bar
->Append(file_menu
, _T("&File"));
350 frame
->SetMenuBar(menu_bar
);
352 myCanvas
= new MyCanvas(frame
);
353 myCanvas
->SetBackgroundColour(*wxWHITE
);
355 frame
->Centre(wxBOTH
);
365 // My frame constructor
366 MyFrame::MyFrame(wxWindow
*parent
,
367 const wxString
& title
)
368 : wxFrame(parent
, wxID_ANY
, title
)
370 #if USE_MODAL_PRESENTATION
371 m_dialog
= (MyModelessDialog
*)NULL
;
372 #endif // USE_MODAL_PRESENTATION
374 #if wxUSE_FINDREPLDLG
380 m_clrData
.SetChooseFull(true);
381 for (int i
= 0; i
< 16; i
++)
383 m_clrData
.SetCustomColour(i
, wxColour(i
*16, i
*16, i
*16));
385 #endif // wxUSE_COLOURDLG
389 #endif // wxUSE_STATUSBAR
393 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
395 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
397 wxColourDialog
dialog(this, &m_clrData
);
398 dialog
.SetTitle(_T("Choose the background colour"));
399 if (dialog
.ShowModal() == wxID_OK
)
401 m_clrData
= dialog
.GetColourData();
402 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
403 myCanvas
->ClearBackground();
407 #endif // wxUSE_COLOURDLG
410 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
413 data
.SetInitialFont(wxGetApp().m_canvasFont
);
414 data
.SetColour(wxGetApp().m_canvasTextColour
);
416 // you might also do this:
418 // wxFontDialog dialog;
419 // if ( !dialog.Create(this, data) { ... error ... }
421 wxFontDialog
dialog(this, data
);
423 if (dialog
.ShowModal() == wxID_OK
)
425 wxFontData retData
= dialog
.GetFontData();
426 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
427 wxGetApp().m_canvasTextColour
= retData
.GetColour();
430 //else: cancelled by the user, don't change the font
432 #endif // wxUSE_FONTDLG
434 #if USE_COLOURDLG_GENERIC
435 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
438 data
.SetChooseFull(true);
439 for (int i
= 0; i
< 16; i
++)
441 wxColour
colour(i
*16, i
*16, i
*16);
442 data
.SetCustomColour(i
, colour
);
445 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &data
);
446 if (dialog
->ShowModal() == wxID_OK
)
448 wxColourData retData
= dialog
->GetColourData();
449 wxColour col
= retData
.GetColour();
450 // wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
451 myCanvas
->SetBackgroundColour(col
);
452 myCanvas
->ClearBackground();
457 #endif // USE_COLOURDLG_GENERIC
459 #if USE_FONTDLG_GENERIC
460 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
463 data
.SetInitialFont(wxGetApp().m_canvasFont
);
464 data
.SetColour(wxGetApp().m_canvasTextColour
);
466 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, &data
);
467 if (dialog
->ShowModal() == wxID_OK
)
469 wxFontData retData
= dialog
->GetFontData();
470 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
471 wxGetApp().m_canvasTextColour
= retData
.GetColour();
476 #endif // USE_FONTDLG_GENERIC
479 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
481 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
482 // being flushed -- test it
485 wxLogMessage(wxT("This is some message - everything is ok so far."));
486 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
487 wxLogWarning(wxT("And then something went wrong!"));
489 // and if ~wxBusyCursor doesn't do it, then call it manually
493 wxLogError(wxT("Intermediary error handler decided to abort."));
494 wxLogError(wxT("The top level caller detected an unrecoverable error."));
496 wxLog::FlushActive();
498 wxLogMessage(wxT("And this is the same dialog but with only one message."));
500 #endif // wxUSE_LOG_DIALOG
502 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
504 wxMessageDialog
dialog( NULL
, _T("This is a message box\nA long, long string to test out the message box properly"),
505 _T("Message box text"), wxNO_DEFAULT
|wxYES_NO
|wxCANCEL
|wxICON_INFORMATION
);
507 switch ( dialog
.ShowModal() )
510 wxLogStatus(wxT("You pressed \"Yes\""));
514 wxLogStatus(wxT("You pressed \"No\""));
518 wxLogStatus(wxT("You pressed \"Cancel\""));
522 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
527 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
529 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
530 _T("Even two rows of text."),
531 _T("Enter a number:"), _T("Numeric input test"),
538 msg
= _T("Invalid number entered or dialog cancelled.");
543 msg
.Printf(_T("You've entered %lu"), res
);
544 icon
= wxICON_INFORMATION
;
547 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
549 #endif // wxUSE_NUMBERDLG
552 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
554 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
555 _T("Password entry dialog"),
560 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
561 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
565 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
567 wxTextEntryDialog
dialog(this,
568 _T("This is a small sample\n")
569 _T("A long, long string to test out the text entrybox"),
570 _T("Please enter a string"),
574 if (dialog
.ShowModal() == wxID_OK
)
576 wxMessageBox(dialog
.GetValue(), _T("Got string"), wxOK
| wxICON_INFORMATION
, this);
579 #endif // wxUSE_TEXTDLG
582 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
584 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
586 wxSingleChoiceDialog
dialog(this,
587 _T("This is a small sample\n")
588 _T("A single-choice convenience dialog"),
589 _T("Please select a value"),
590 WXSIZEOF(choices
), choices
);
592 dialog
.SetSelection(2);
594 if (dialog
.ShowModal() == wxID_OK
)
596 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
601 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
603 const wxString choices
[] =
605 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
606 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
607 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
610 wxArrayInt selections
;
611 size_t count
= wxGetMultipleChoices(selections
,
612 _T("This is a small sample\n")
613 _T("A multi-choice convenience dialog"),
614 _T("Please select a value"),
615 WXSIZEOF(choices
), choices
,
620 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
621 for ( size_t n
= 0; n
< count
; n
++ )
623 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
624 (unsigned)n
, (unsigned)selections
[n
],
625 choices
[selections
[n
]].c_str());
629 //else: cancelled or nothing selected
631 #endif // wxUSE_CHOICEDLG
634 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
639 _T("Testing open file dialog"),
643 _T("C++ files (*.cpp)|*.cpp")
645 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
649 dialog
.SetDirectory(wxGetHomeDir());
651 if (dialog
.ShowModal() == wxID_OK
)
654 info
.Printf(_T("Full file name: %s\n")
657 dialog
.GetPath().c_str(),
658 dialog
.GetDirectory().c_str(),
659 dialog
.GetFilename().c_str());
660 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
665 // this shows how to take advantage of specifying a default extension in the
666 // call to wxFileSelector: it is remembered after each new call and the next
667 // one will use it by default
668 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
670 static wxString s_extDef
;
671 wxString path
= wxFileSelector(
672 _T("Select the file to load"),
673 wxEmptyString
, wxEmptyString
,
675 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
683 // it is just a sample, would use wxSplitPath in real program
684 s_extDef
= path
.AfterLast(_T('.'));
686 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
687 (const wxChar
*) path
, (const wxChar
*) s_extDef
);
690 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
694 _T("C++ files (*.cpp)|*.cpp");
696 _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
698 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
699 wxEmptyString
, wxEmptyString
, wildcards
,
702 if (dialog
.ShowModal() == wxID_OK
)
704 wxArrayString paths
, filenames
;
706 dialog
.GetPaths(paths
);
707 dialog
.GetFilenames(filenames
);
710 size_t count
= paths
.GetCount();
711 for ( size_t n
= 0; n
< count
; n
++ )
713 s
.Printf(_T("File %d: %s (%s)\n"),
714 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
718 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
721 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
726 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
728 wxFileDialog
dialog(this,
729 _T("Testing save file dialog"),
732 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
733 wxSAVE
|wxOVERWRITE_PROMPT
);
735 dialog
.SetFilterIndex(1);
737 if (dialog
.ShowModal() == wxID_OK
)
739 wxLogMessage(_T("%s, filter %d"),
740 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
743 #endif // wxUSE_FILEDLG
745 #if USE_FILEDLG_GENERIC
746 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
748 wxGenericFileDialog dialog
751 _T("Testing open file dialog"),
754 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
757 dialog
.SetDirectory(wxGetHomeDir());
759 if (dialog
.ShowModal() == wxID_OK
)
762 info
.Printf(_T("Full file name: %s\n")
765 dialog
.GetPath().c_str(),
766 dialog
.GetDirectory().c_str(),
767 dialog
.GetFilename().c_str());
768 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
773 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
775 wxString wildcards
= _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
776 wxGenericFileDialog
dialog(this, _T("Testing open multiple file dialog"),
777 wxEmptyString
, wxEmptyString
, wildcards
,
780 if (dialog
.ShowModal() == wxID_OK
)
782 wxArrayString paths
, filenames
;
784 dialog
.GetPaths(paths
);
785 dialog
.GetFilenames(filenames
);
788 size_t count
= paths
.GetCount();
789 for ( size_t n
= 0; n
< count
; n
++ )
791 s
.Printf(_T("File %d: %s (%s)\n"),
792 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
796 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
799 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
804 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
806 wxGenericFileDialog
dialog(this,
807 _T("Testing save file dialog"),
810 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
811 wxSAVE
|wxOVERWRITE_PROMPT
);
813 dialog
.SetFilterIndex(1);
815 if (dialog
.ShowModal() == wxID_OK
)
817 wxLogMessage(_T("%s, filter %d"),
818 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
821 #endif // USE_FILEDLG_GENERIC
824 void MyFrame::DoDirChoose(int style
)
826 // pass some initial dir to wxDirDialog
828 wxGetHomeDir(&dirHome
);
830 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
832 if (dialog
.ShowModal() == wxID_OK
)
834 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
838 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
840 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_NEW_DIR_BUTTON
);
843 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
845 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_NEW_DIR_BUTTON
);
847 #endif // wxUSE_DIRDLG
849 #if USE_DIRDLG_GENERIC
850 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
852 // pass some initial dir to wxDirDialog
854 wxGetHomeDir(&dirHome
);
856 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
858 if (dialog
.ShowModal() == wxID_OK
)
860 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
864 #endif // USE_DIRDLG_GENERIC
866 #if USE_MODAL_PRESENTATION
867 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
869 MyModalDialog
dlg(this);
873 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
875 bool show
= GetMenuBar()->IsChecked(event
.GetId());
881 m_dialog
= new MyModelessDialog(this);
884 m_dialog
->Show(true);
891 #endif // USE_MODAL_PRESENTATION
893 #if wxUSE_STARTUP_TIPS
894 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
896 static size_t s_index
= (size_t)-1;
898 if ( s_index
== (size_t)-1 )
902 // this is completely bogus, we don't know how many lines are there
903 // in the file, but who cares, it's a demo only...
904 s_index
= rand() % 5;
907 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
909 bool showAtStartup
= wxShowTip(this, tipProvider
);
913 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
914 wxOK
| wxICON_INFORMATION
, this);
917 s_index
= tipProvider
->GetCurrentTip();
920 #endif // wxUSE_STARTUP_TIPS
922 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
927 #if wxUSE_PROGRESSDLG
929 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
931 static const int max
= 10;
933 wxProgressDialog
dialog(_T("Progress dialog example"),
934 _T("An informative message"),
939 // wxPD_AUTO_HIDE | -- try this as well
941 wxPD_ESTIMATED_TIME
|
942 wxPD_REMAINING_TIME
);
945 for ( int i
= 0; i
<= max
; i
++ )
950 cont
= dialog
.Update(i
, _T("That's all, folks!"));
952 else if ( i
== max
/ 2 )
954 cont
= dialog
.Update(i
, _T("Only a half left (very long message)!"));
958 cont
= dialog
.Update(i
);
963 if ( wxMessageBox(_T("Do you really want to cancel?"),
964 _T("Progress dialog question"), // caption
965 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
974 wxLogStatus(wxT("Progress dialog aborted!"));
978 wxLogStatus(wxT("Countdown from %d finished"), max
);
982 #endif // wxUSE_PROGRESSDLG
986 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
988 wxWindowDisabler disableAll
;
990 wxBusyInfo
info(_T("Working, please wait..."), this);
992 for ( int i
= 0; i
< 18; i
++ )
1002 #endif // wxUSE_BUSYINFO
1004 #if wxUSE_FINDREPLDLG
1006 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
1010 delete m_dlgReplace
;
1011 m_dlgReplace
= NULL
;
1015 m_dlgReplace
= new wxFindReplaceDialog
1019 _T("Find and replace dialog"),
1023 m_dlgReplace
->Show(true);
1027 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
1036 m_dlgFind
= new wxFindReplaceDialog
1045 m_dlgFind
->Show(true);
1049 static wxString
DecodeFindDialogEventFlags(int flags
)
1052 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
1053 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
1054 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
1055 << _T("case sensitive");
1060 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
1062 wxEventType type
= event
.GetEventType();
1064 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
1066 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1067 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
1068 event
.GetFindString().c_str(),
1069 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1071 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
1072 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
1074 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1075 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
1076 event
.GetFindString().c_str(),
1077 event
.GetReplaceString().c_str(),
1078 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1080 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
1082 wxFindReplaceDialog
*dlg
= event
.GetDialog();
1086 if ( dlg
== m_dlgFind
)
1089 idMenu
= DIALOGS_FIND
;
1092 else if ( dlg
== m_dlgReplace
)
1094 txt
= _T("Replace");
1095 idMenu
= DIALOGS_REPLACE
;
1096 m_dlgReplace
= NULL
;
1100 txt
= _T("Unknown");
1103 wxFAIL_MSG( _T("unexpected event") );
1106 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1108 if ( idMenu
!= wxID_ANY
)
1110 GetMenuBar()->Check(idMenu
, false);
1117 wxLogError(wxT("Unknown find dialog event!"));
1121 #endif // wxUSE_FINDREPLDLG
1123 // ----------------------------------------------------------------------------
1125 // ----------------------------------------------------------------------------
1127 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1130 dc
.SetFont(wxGetApp().m_canvasFont
);
1131 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
1132 dc
.SetBackgroundMode(wxTRANSPARENT
);
1134 _T("wxWidgets common dialogs")
1135 #if !defined(__SMARTPHONE__)
1136 _T(" test application")
1141 #if USE_MODAL_PRESENTATION
1143 // ----------------------------------------------------------------------------
1145 // ----------------------------------------------------------------------------
1147 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1148 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modeless dialog")))
1150 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1152 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
1153 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, _T("Should be disabled"));
1156 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1157 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1161 sizerTop
->SetSizeHints(this);
1162 sizerTop
->Fit(this);
1165 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1167 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1168 wxOK
| wxICON_INFORMATION
, this);
1171 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1173 if ( event
.CanVeto() )
1175 wxMessageBox(_T("Use the menu item to close this dialog"),
1176 _T("Modeless dialog"),
1177 wxOK
| wxICON_INFORMATION
, this);
1183 // ----------------------------------------------------------------------------
1185 // ----------------------------------------------------------------------------
1187 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1188 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modal dialog")))
1190 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1192 m_btnModal
= new wxButton(this, wxID_ANY
, _T("&Modal dialog..."));
1193 m_btnModeless
= new wxButton(this, wxID_ANY
, _T("Mode&less dialog"));
1194 m_btnDelete
= new wxButton(this, wxID_ANY
, _T("&Delete button"));
1196 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
1197 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
1198 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
1199 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
1200 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
1204 sizerTop
->SetSizeHints(this);
1205 sizerTop
->Fit(this);
1207 m_btnModal
->SetFocus();
1208 m_btnModal
->SetDefault();
1211 void MyModalDialog::OnButton(wxCommandEvent
& event
)
1213 if ( event
.GetEventObject() == m_btnDelete
)
1218 m_btnDelete
->Disable();
1220 else if ( event
.GetEventObject() == m_btnModal
)
1223 wxGetTextFromUser(_T("Dummy prompt"),
1224 _T("Modal dialog called from dialog"),
1225 wxEmptyString
, this);
1227 wxMessageBox(_T("Modal dialog called from dialog"));
1228 #endif // wxUSE_TEXTDLG
1230 else if ( event
.GetEventObject() == m_btnModeless
)
1232 (new MyModelessDialog(this))->Show();
1240 #endif // USE_MODAL_PRESENTATION