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 #if defined(__WXGTK__) && defined(wxUSE_UNICODE)
210 wxConvCurrent
= &wxConvLibc
;
213 m_canvasTextColour
= wxColour(_T("BLACK"));
214 m_canvasFont
= *wxNORMAL_FONT
;
216 // Create the main frame window
217 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWidgets dialogs example"));
220 wxMenu
*file_menu
= new wxMenu
;
222 file_menu
->Append(DIALOGS_MESSAGE_BOX
, _T("&Message box\tCtrl-M"));
225 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
227 wxMenu
*choices_menu
= new wxMenu
;
230 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, _T("&Choose colour"));
231 #endif // wxUSE_COLOURDLG
234 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, _T("Choose &font"));
235 #endif // wxUSE_FONTDLG
238 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, _T("&Single choice\tCtrl-C"));
239 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, _T("M&ultiple choice\tCtrl-U"));
240 #endif // wxUSE_CHOICEDLG
242 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
243 choices_menu
->AppendSeparator();
244 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
246 #if USE_COLOURDLG_GENERIC
247 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, _T("&Choose colour (generic)"));
248 #endif // USE_COLOURDLG_GENERIC
250 #if USE_FONTDLG_GENERIC
251 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, _T("Choose &font (generic)"));
252 #endif // USE_FONTDLG_GENERIC
254 file_menu
->Append(wxID_ANY
,_T("Choices and selectors"),choices_menu
);
256 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
259 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
261 wxMenu
*entry_menu
= new wxMenu
;
264 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, _T("Text &entry\tCtrl-E"));
265 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, _T("&Password entry\tCtrl-P"));
266 #endif // wxUSE_TEXTDLG
269 entry_menu
->Append(DIALOGS_NUM_ENTRY
, _T("&Numeric entry\tCtrl-N"));
270 #endif // wxUSE_NUMBERDLG
272 file_menu
->Append(wxID_ANY
,_T("Entry dialogs"),entry_menu
);
274 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
279 wxMenu
*filedlg_menu
= new wxMenu
;
280 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, _T("&Open file\tCtrl-O"));
281 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, _T("&Second open file\tCtrl-2"));
282 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, _T("Open &files\tCtrl-Q"));
283 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, _T("Sa&ve file\tCtrl-S"));
285 #if USE_FILEDLG_GENERIC
286 filedlg_menu
->AppendSeparator();
287 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, _T("&Open file (generic)"));
288 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, _T("Open &files (generic)"));
289 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, _T("Sa&ve file (generic)"));
290 #endif // USE_FILEDLG_GENERIC
292 file_menu
->Append(wxID_ANY
,_T("File operations"),filedlg_menu
);
294 #endif // wxUSE_FILEDLG
297 wxMenu
*dir_menu
= new wxMenu
;
299 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, _T("&Choose a directory\tCtrl-D"));
300 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
301 file_menu
->Append(wxID_ANY
,_T("Directory operations"),dir_menu
);
303 #if USE_DIRDLG_GENERIC
304 dir_menu
->AppendSeparator();
305 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, _T("&Choose a directory (generic)"));
306 #endif // USE_DIRDLG_GENERIC
308 #endif // wxUSE_DIRDLG
311 #if wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
313 wxMenu
*info_menu
= new wxMenu
;
315 #if wxUSE_STARTUP_TIPS
316 info_menu
->Append(DIALOGS_TIP
, _T("&Tip of the day\tCtrl-T"));
317 #endif // wxUSE_STARTUP_TIPS
319 #if wxUSE_PROGRESSDLG
320 info_menu
->Append(DIALOGS_PROGRESS
, _T("Pro&gress dialog\tCtrl-G"));
321 #endif // wxUSE_PROGRESSDLG
324 info_menu
->Append(DIALOGS_BUSYINFO
, _T("&Busy info dialog\tCtrl-B"));
325 #endif // wxUSE_BUSYINFO
328 info_menu
->Append(DIALOGS_LOG_DIALOG
, _T("&Log dialog\tCtrl-L"));
329 #endif // wxUSE_LOG_DIALOG
331 file_menu
->Append(wxID_ANY
,_T("Informative dialogs"),info_menu
);
333 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
336 #if wxUSE_FINDREPLDLG
337 wxMenu
*find_menu
= new wxMenu
;
338 find_menu
->AppendCheckItem(DIALOGS_FIND
, _T("&Find dialog\tCtrl-F"));
339 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, _T("Find and &replace dialog\tShift-Ctrl-F"));
340 file_menu
->Append(wxID_ANY
,_T("Searching"),find_menu
);
341 #endif // wxUSE_FINDREPLDLG
343 #if USE_MODAL_PRESENTATION
344 wxMenu
*modal_menu
= new wxMenu
;
345 modal_menu
->Append(DIALOGS_MODAL
, _T("Mo&dal dialog\tCtrl-W"));
346 modal_menu
->AppendCheckItem(DIALOGS_MODELESS
, _T("Modeless &dialog\tCtrl-Z"));
347 file_menu
->Append(wxID_ANY
,_T("Modal/Modeless"),modal_menu
);
348 #endif // USE_MODAL_PRESENTATION
350 file_menu
->AppendSeparator();
351 file_menu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"));
353 wxMenuBar
*menu_bar
= new wxMenuBar
;
354 menu_bar
->Append(file_menu
, _T("&File"));
355 frame
->SetMenuBar(menu_bar
);
357 myCanvas
= new MyCanvas(frame
);
358 myCanvas
->SetBackgroundColour(*wxWHITE
);
360 frame
->Centre(wxBOTH
);
370 // My frame constructor
371 MyFrame::MyFrame(wxWindow
*parent
,
372 const wxString
& title
)
373 : wxFrame(parent
, wxID_ANY
, title
)
375 #if USE_MODAL_PRESENTATION
376 m_dialog
= (MyModelessDialog
*)NULL
;
377 #endif // USE_MODAL_PRESENTATION
379 #if wxUSE_FINDREPLDLG
385 m_clrData
.SetChooseFull(true);
386 for (int i
= 0; i
< 16; i
++)
388 m_clrData
.SetCustomColour(i
, wxColour(i
*16, i
*16, i
*16));
390 #endif // wxUSE_COLOURDLG
394 #endif // wxUSE_STATUSBAR
398 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
400 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
402 wxColourDialog
dialog(this, &m_clrData
);
403 dialog
.SetTitle(_T("Choose the background colour"));
404 if (dialog
.ShowModal() == wxID_OK
)
406 m_clrData
= dialog
.GetColourData();
407 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
408 myCanvas
->ClearBackground();
412 #endif // wxUSE_COLOURDLG
415 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
418 data
.SetInitialFont(wxGetApp().m_canvasFont
);
419 data
.SetColour(wxGetApp().m_canvasTextColour
);
421 // you might also do this:
423 // wxFontDialog dialog;
424 // if ( !dialog.Create(this, data) { ... error ... }
426 wxFontDialog
dialog(this, data
);
428 if (dialog
.ShowModal() == wxID_OK
)
430 wxFontData retData
= dialog
.GetFontData();
431 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
432 wxGetApp().m_canvasTextColour
= retData
.GetColour();
435 //else: cancelled by the user, don't change the font
437 #endif // wxUSE_FONTDLG
439 #if USE_COLOURDLG_GENERIC
440 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
443 data
.SetChooseFull(true);
444 for (int i
= 0; i
< 16; i
++)
446 wxColour
colour(i
*16, i
*16, i
*16);
447 data
.SetCustomColour(i
, colour
);
450 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &data
);
451 if (dialog
->ShowModal() == wxID_OK
)
453 wxColourData retData
= dialog
->GetColourData();
454 wxColour col
= retData
.GetColour();
455 // wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
456 myCanvas
->SetBackgroundColour(col
);
457 myCanvas
->ClearBackground();
462 #endif // USE_COLOURDLG_GENERIC
464 #if USE_FONTDLG_GENERIC
465 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
468 data
.SetInitialFont(wxGetApp().m_canvasFont
);
469 data
.SetColour(wxGetApp().m_canvasTextColour
);
471 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, &data
);
472 if (dialog
->ShowModal() == wxID_OK
)
474 wxFontData retData
= dialog
->GetFontData();
475 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
476 wxGetApp().m_canvasTextColour
= retData
.GetColour();
481 #endif // USE_FONTDLG_GENERIC
483 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
485 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
486 // being flushed -- test it
489 wxLogMessage(wxT("This is some message - everything is ok so far."));
490 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
491 wxLogWarning(wxT("And then something went wrong!"));
493 // and if ~wxBusyCursor doesn't do it, then call it manually
497 wxLogError(wxT("Intermediary error handler decided to abort."));
498 wxLogError(wxT("The top level caller detected an unrecoverable error."));
500 wxLog::FlushActive();
502 wxLogMessage(wxT("And this is the same dialog but with only one message."));
505 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
507 wxMessageDialog
dialog( NULL
, _T("This is a message box\nA long, long string to test out the message box properly"),
508 _T("Message box text"), wxNO_DEFAULT
|wxYES_NO
|wxCANCEL
|wxICON_INFORMATION
);
510 switch ( dialog
.ShowModal() )
513 wxLogStatus(wxT("You pressed \"Yes\""));
517 wxLogStatus(wxT("You pressed \"No\""));
521 wxLogStatus(wxT("You pressed \"Cancel\""));
525 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
530 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
532 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
533 _T("Even two rows of text."),
534 _T("Enter a number:"), _T("Numeric input test"),
541 msg
= _T("Invalid number entered or dialog cancelled.");
546 msg
.Printf(_T("You've entered %lu"), res
);
547 icon
= wxICON_INFORMATION
;
550 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
552 #endif // wxUSE_NUMBERDLG
555 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
557 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
558 _T("Password entry dialog"),
563 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
564 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
568 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
570 wxTextEntryDialog
dialog(this,
571 _T("This is a small sample\n")
572 _T("A long, long string to test out the text entrybox"),
573 _T("Please enter a string"),
577 if (dialog
.ShowModal() == wxID_OK
)
579 wxMessageDialog
dialog2(this, dialog
.GetValue(), _T("Got string"));
583 #endif // wxUSE_TEXTDLG
586 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
588 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
590 wxSingleChoiceDialog
dialog(this,
591 _T("This is a small sample\n")
592 _T("A single-choice convenience dialog"),
593 _T("Please select a value"),
594 WXSIZEOF(choices
), choices
);
596 dialog
.SetSelection(2);
598 if (dialog
.ShowModal() == wxID_OK
)
600 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
605 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
607 const wxString choices
[] =
609 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
610 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
611 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
614 wxArrayInt selections
;
615 size_t count
= wxGetMultipleChoices(selections
,
616 _T("This is a small sample\n")
617 _T("A multi-choice convenience dialog"),
618 _T("Please select a value"),
619 WXSIZEOF(choices
), choices
,
624 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
625 for ( size_t n
= 0; n
< count
; n
++ )
627 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
628 (unsigned)n
, (unsigned)selections
[n
],
629 choices
[selections
[n
]].c_str());
633 //else: cancelled or nothing selected
635 #endif // wxUSE_CHOICEDLG
638 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
643 _T("Testing open file dialog"),
647 _T("C++ files (*.cpp)|*.cpp")
649 _T("C++ files (*.h;*.cpp)|*.h;*.cpp")
653 dialog
.SetDirectory(wxGetHomeDir());
655 if (dialog
.ShowModal() == wxID_OK
)
658 info
.Printf(_T("Full file name: %s\n")
661 dialog
.GetPath().c_str(),
662 dialog
.GetDirectory().c_str(),
663 dialog
.GetFilename().c_str());
664 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
669 // this shows how to take advantage of specifying a default extension in the
670 // call to wxFileSelector: it is remembered after each new call and the next
671 // one will use it by default
672 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
674 static wxString s_extDef
;
675 wxString path
= wxFileSelector(
676 _T("Select the file to load"),
677 wxEmptyString
, wxEmptyString
,
679 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
687 // it is just a sample, would use wxSplitPath in real program
688 s_extDef
= path
.AfterLast(_T('.'));
690 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
691 (const wxChar
*) path
, (const wxChar
*) s_extDef
);
694 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
698 _T("C++ files (*.cpp)|*.cpp");
700 _T("All files (*.*)|*.*|C++ files (*.h;*.cpp)|*.h;*.cpp");
702 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
703 wxEmptyString
, wxEmptyString
, wildcards
,
706 if (dialog
.ShowModal() == wxID_OK
)
708 wxArrayString paths
, filenames
;
710 dialog
.GetPaths(paths
);
711 dialog
.GetFilenames(filenames
);
714 size_t count
= paths
.GetCount();
715 for ( size_t n
= 0; n
< count
; n
++ )
717 s
.Printf(_T("File %d: %s (%s)\n"),
718 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
722 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
725 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
730 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
732 wxFileDialog
dialog(this,
733 _T("Testing save file dialog"),
736 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
737 wxSAVE
|wxOVERWRITE_PROMPT
);
739 dialog
.SetFilterIndex(1);
741 if (dialog
.ShowModal() == wxID_OK
)
743 wxLogMessage(_T("%s, filter %d"),
744 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
747 #endif // wxUSE_FILEDLG
749 #if USE_FILEDLG_GENERIC
750 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
752 wxGenericFileDialog dialog
755 _T("Testing open file dialog"),
758 _T("C++ files (*.h;*.cpp)|*.h;*.cpp")
761 dialog
.SetDirectory(wxGetHomeDir());
763 if (dialog
.ShowModal() == wxID_OK
)
766 info
.Printf(_T("Full file name: %s\n")
769 dialog
.GetPath().c_str(),
770 dialog
.GetDirectory().c_str(),
771 dialog
.GetFilename().c_str());
772 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
777 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
779 wxString wildcards
= _T("All files (*.*)|*.*|C++ files (*.h;*.cpp)|*.h;*.cpp");
780 wxGenericFileDialog
dialog(this, _T("Testing open multiple file dialog"),
781 wxEmptyString
, wxEmptyString
, wildcards
,
784 if (dialog
.ShowModal() == wxID_OK
)
786 wxArrayString paths
, filenames
;
788 dialog
.GetPaths(paths
);
789 dialog
.GetFilenames(filenames
);
792 size_t count
= paths
.GetCount();
793 for ( size_t n
= 0; n
< count
; n
++ )
795 s
.Printf(_T("File %d: %s (%s)\n"),
796 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
800 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
803 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
808 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
810 wxGenericFileDialog
dialog(this,
811 _T("Testing save file dialog"),
814 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
815 wxSAVE
|wxOVERWRITE_PROMPT
);
817 dialog
.SetFilterIndex(1);
819 if (dialog
.ShowModal() == wxID_OK
)
821 wxLogMessage(_T("%s, filter %d"),
822 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
825 #endif // USE_FILEDLG_GENERIC
828 void MyFrame::DoDirChoose(int style
)
830 // pass some initial dir to wxDirDialog
832 wxGetHomeDir(&dirHome
);
834 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
836 if (dialog
.ShowModal() == wxID_OK
)
838 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
842 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
844 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_NEW_DIR_BUTTON
);
847 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
849 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_NEW_DIR_BUTTON
);
851 #endif // wxUSE_DIRDLG
853 #if USE_DIRDLG_GENERIC
854 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
856 // pass some initial dir to wxDirDialog
858 wxGetHomeDir(&dirHome
);
860 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
862 if (dialog
.ShowModal() == wxID_OK
)
864 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
868 #endif // USE_DIRDLG_GENERIC
870 #if USE_MODAL_PRESENTATION
871 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
873 MyModalDialog
dlg(this);
877 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
879 bool show
= GetMenuBar()->IsChecked(event
.GetId());
885 m_dialog
= new MyModelessDialog(this);
888 m_dialog
->Show(true);
895 #endif // USE_MODAL_PRESENTATION
897 #if wxUSE_STARTUP_TIPS
898 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
900 static size_t s_index
= (size_t)-1;
902 if ( s_index
== (size_t)-1 )
906 // this is completely bogus, we don't know how many lines are there
907 // in the file, but who cares, it's a demo only...
908 s_index
= rand() % 5;
911 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
913 bool showAtStartup
= wxShowTip(this, tipProvider
);
917 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
918 wxOK
| wxICON_INFORMATION
, this);
921 s_index
= tipProvider
->GetCurrentTip();
924 #endif // wxUSE_STARTUP_TIPS
926 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
931 #if wxUSE_PROGRESSDLG
933 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
935 static const int max
= 10;
937 wxProgressDialog
dialog(_T("Progress dialog example"),
938 _T("An informative message"),
943 // wxPD_AUTO_HIDE | -- try this as well
945 wxPD_ESTIMATED_TIME
|
946 wxPD_REMAINING_TIME
);
949 for ( int i
= 0; i
<= max
; i
++ )
954 cont
= dialog
.Update(i
, _T("That's all, folks!"));
956 else if ( i
== max
/ 2 )
958 cont
= dialog
.Update(i
, _T("Only a half left (very long message)!"));
962 cont
= dialog
.Update(i
);
967 if ( wxMessageBox(_T("Do you really want to cancel?"),
968 _T("Progress dialog question"), // caption
969 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
978 wxLogStatus(wxT("Progress dialog aborted!"));
982 wxLogStatus(wxT("Countdown from %d finished"), max
);
986 #endif // wxUSE_PROGRESSDLG
990 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
992 wxWindowDisabler disableAll
;
994 wxBusyInfo
info(_T("Working, please wait..."), this);
996 for ( int i
= 0; i
< 18; i
++ )
1006 #endif // wxUSE_BUSYINFO
1008 #if wxUSE_FINDREPLDLG
1010 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
1014 delete m_dlgReplace
;
1015 m_dlgReplace
= NULL
;
1019 m_dlgReplace
= new wxFindReplaceDialog
1023 _T("Find and replace dialog"),
1027 m_dlgReplace
->Show(true);
1031 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
1040 m_dlgFind
= new wxFindReplaceDialog
1049 m_dlgFind
->Show(true);
1053 static wxString
DecodeFindDialogEventFlags(int flags
)
1056 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
1057 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
1058 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
1059 << _T("case sensitive");
1064 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
1066 wxEventType type
= event
.GetEventType();
1068 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
1070 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1071 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
1072 event
.GetFindString().c_str(),
1073 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1075 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
1076 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
1078 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1079 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
1080 event
.GetFindString().c_str(),
1081 event
.GetReplaceString().c_str(),
1082 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1084 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
1086 wxFindReplaceDialog
*dlg
= event
.GetDialog();
1090 if ( dlg
== m_dlgFind
)
1093 idMenu
= DIALOGS_FIND
;
1096 else if ( dlg
== m_dlgReplace
)
1098 txt
= _T("Replace");
1099 idMenu
= DIALOGS_REPLACE
;
1100 m_dlgReplace
= NULL
;
1104 txt
= _T("Unknown");
1107 wxFAIL_MSG( _T("unexpected event") );
1110 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1112 if ( idMenu
!= wxID_ANY
)
1114 GetMenuBar()->Check(idMenu
, false);
1121 wxLogError(wxT("Unknown find dialog event!"));
1125 #endif // wxUSE_FINDREPLDLG
1127 // ----------------------------------------------------------------------------
1129 // ----------------------------------------------------------------------------
1131 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1134 dc
.SetFont(wxGetApp().m_canvasFont
);
1135 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
1136 dc
.SetBackgroundMode(wxTRANSPARENT
);
1137 dc
.DrawText(_T("wxWidgets common dialogs test application"), 10, 10);
1140 // ----------------------------------------------------------------------------
1142 // ----------------------------------------------------------------------------
1144 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1145 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modeless dialog")))
1147 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1149 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
1150 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, _T("Should be disabled"));
1153 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1154 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1158 sizerTop
->SetSizeHints(this);
1159 sizerTop
->Fit(this);
1162 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1164 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1165 wxOK
| wxICON_INFORMATION
, this);
1168 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1170 if ( event
.CanVeto() )
1172 wxMessageBox(_T("Use the menu item to close this dialog"),
1173 _T("Modeless dialog"),
1174 wxOK
| wxICON_INFORMATION
, this);
1180 // ----------------------------------------------------------------------------
1182 // ----------------------------------------------------------------------------
1184 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1185 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modal dialog")))
1187 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1189 m_btnModal
= new wxButton(this, wxID_ANY
, _T("&Modal dialog..."));
1190 m_btnModeless
= new wxButton(this, wxID_ANY
, _T("Mode&less dialog"));
1191 m_btnDelete
= new wxButton(this, wxID_ANY
, _T("&Delete button"));
1193 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
1194 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
1195 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
1196 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
1197 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
1201 sizerTop
->SetSizeHints(this);
1202 sizerTop
->Fit(this);
1204 m_btnModal
->SetFocus();
1205 m_btnModal
->SetDefault();
1208 void MyModalDialog::OnButton(wxCommandEvent
& event
)
1210 if ( event
.GetEventObject() == m_btnDelete
)
1215 m_btnDelete
->Disable();
1217 else if ( event
.GetEventObject() == m_btnModal
)
1220 wxGetTextFromUser(_T("Dummy prompt"),
1221 _T("Modal dialog called from dialog"),
1222 wxEmptyString
, this);
1224 wxMessageBox(_T("Modal dialog called from dialog"));
1225 #endif // wxUSE_TEXTDLG
1227 else if ( event
.GetEventObject() == m_btnModeless
)
1229 (new MyModelessDialog(this))->Show();