1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart, Vadim Zeitlin, ABX
7 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
14 This sample shows how to use the common dialogs available from wxWidgets.
15 It also shows that generic implementations of common dialogs can be exchanged
16 with native dialogs and can coexist in one application. The need for generic
17 dialogs addition is recognized thanks to setup of below USE_*** setting. Their
18 combinations reflects conditions of makefiles and project files to avoid unresolved
19 references during linking. For now some generic dialogs are added in static builds
26 #ifdef __WXUNIVERSAL__
27 #define USE_WXUNIVERSAL 1
29 #define USE_WXUNIVERSAL 0
38 #if defined(__WXWINCE__)
44 #if defined(__WXMSW__) && !USE_WXWINCE
56 #if defined(__WXMAC_OSX__) && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2) && USE_NATIVE_FONT_DIALOG_FOR_MACOSX
57 #define USE_WXMACFONTDLG 1
59 #define USE_WXMACFONTDLG 0
74 #define USE_GENERIC_DIALOGS (!USE_WXUNIVERSAL && !USE_DLL)
76 #define USE_COLOURDLG_GENERIC \
77 ((USE_WXMSW || USE_WXMAC) && USE_GENERIC_DIALOGS && wxUSE_COLOURDLG)
78 #define USE_DIRDLG_GENERIC \
79 ((USE_WXMSW || USE_WXMAC) && USE_GENERIC_DIALOGS && wxUSE_DIRDLG)
80 #define USE_FILEDLG_GENERIC \
81 ((((USE_WXMSW || USE_WXMAC || USE_WXPM || USE_WXGTK) \
82 && USE_GENERIC_DIALOGS) || USE_WXWINCE) && wxUSE_FILEDLG)
83 #define USE_FONTDLG_GENERIC \
84 ((USE_WXMSW || USE_WXMACFONTDLG || USE_WXPM) && USE_GENERIC_DIALOGS && wxUSE_FONTDLG)
86 // Turn USE_MODAL_PRESENTATION to 0 if there is any reason for not presenting difference
87 // between modal and modeless dialogs (ie. not implemented it in your port yet)
88 #if defined(__SMARTPHONE__) || !wxUSE_BOOKCTRL
89 #define USE_MODAL_PRESENTATION 0
91 #define USE_MODAL_PRESENTATION 1
95 // Turn USE_SETTINGS_DIALOG to 0 if supported
97 #define USE_SETTINGS_DIALOG 1
99 #define USE_SETTINGS_DIALOG 0
104 // Custom application traits class which we use to override the default log
106 class MyAppTraits
: public wxGUIAppTraits
109 virtual wxLog
*CreateLogTarget();
114 // Define a new application type
115 class MyApp
: public wxApp
118 MyApp() { m_startupProgressStyle
= -1; }
120 virtual bool OnInit();
122 #if wxUSE_CMDLINE_PARSER
123 virtual void OnInitCmdLine(wxCmdLineParser
& parser
);
124 virtual bool OnCmdLineParsed(wxCmdLineParser
& parser
);
125 #endif // wxUSE_CMDLINE_PARSER
129 virtual wxAppTraits
*CreateTraits() { return new MyAppTraits
; }
133 // Flag set to a valid value if command line option "progress" is used,
134 // this allows testing of wxProgressDialog before the main event loop is
135 // started. If this option is not specified it is set to -1 by default
136 // meaning that progress dialog shouldn't be shown at all.
137 long m_startupProgressStyle
;
140 #if USE_MODAL_PRESENTATION
142 // A custom modeless dialog
143 class MyModelessDialog
: public wxDialog
146 MyModelessDialog(wxWindow
*parent
);
148 void OnButton(wxCommandEvent
& event
);
149 void OnClose(wxCloseEvent
& event
);
152 DECLARE_EVENT_TABLE()
155 // A custom modal dialog
156 class MyModalDialog
: public wxDialog
159 MyModalDialog(wxWindow
*parent
);
161 void OnButton(wxCommandEvent
& event
);
164 wxButton
*m_btnModal
,
168 DECLARE_EVENT_TABLE()
171 #endif // USE_MODAL_PRESENTATION
173 // A class demonstrating CreateStdDialogButtonSizer()
174 class StdButtonSizerDialog
: public wxDialog
177 StdButtonSizerDialog(wxWindow
*parent
);
179 void OnEvent(wxCommandEvent
& event
);
182 void EnableDisableControls();
184 wxCheckBox
*m_chkboxAffirmativeButton
;
185 wxRadioButton
*m_radiobtnOk
,
188 wxCheckBox
*m_chkboxDismissButton
;
189 wxRadioButton
*m_radiobtnClose
,
192 wxCheckBox
*m_chkboxApply
,
197 wxSizer
*m_buttonsSizer
;
199 DECLARE_EVENT_TABLE()
202 // Test harness for wxMessageDialog.
203 class TestMessageBoxDialog
: public wxDialog
206 TestMessageBoxDialog(wxWindow
*parent
);
211 wxString
GetMessage() { return m_textMsg
->GetValue(); }
214 void PrepareMessageDialog(wxMessageDialogBase
&dlg
);
216 virtual void AddAdditionalTextOptions(wxSizer
*WXUNUSED(sizer
)) { }
217 virtual void AddAdditionalFlags(wxSizer
*WXUNUSED(sizer
)) { }
219 void OnApply(wxCommandEvent
& event
);
220 void OnClose(wxCommandEvent
& event
);
221 void OnUpdateLabelUI(wxUpdateUIEvent
& event
);
222 void OnUpdateNoDefaultUI(wxUpdateUIEvent
& event
);
241 static const BtnInfo ms_btnInfo
[Btn_Max
];
254 wxTextCtrl
*m_textMsg
,
257 wxCheckBox
*m_buttons
[Btn_Max
];
258 wxTextCtrl
*m_labels
[Btn_Max
];
262 wxCheckBox
*m_chkNoDefault
,
265 DECLARE_EVENT_TABLE()
266 wxDECLARE_NO_COPY_CLASS(TestMessageBoxDialog
);
270 class TestRichMessageDialog
: public TestMessageBoxDialog
273 TestRichMessageDialog(wxWindow
*parent
);
276 // overrides method in base class
277 virtual void AddAdditionalTextOptions(wxSizer
*sizer
);
278 virtual void AddAdditionalFlags(wxSizer
*sizer
);
280 void OnApply(wxCommandEvent
& event
);
283 wxTextCtrl
*m_textCheckBox
;
284 wxCheckBox
*m_initialValueCheckBox
;
285 wxTextCtrl
*m_textDetailed
;
287 DECLARE_EVENT_TABLE()
289 #endif // wxUSE_RICHMSGDLG
291 class TestDefaultActionDialog
: public wxDialog
294 TestDefaultActionDialog( wxWindow
*parent
);
296 void OnListBoxDClick(wxCommandEvent
& event
);
297 void OnDisableOK(wxCommandEvent
& event
);
298 void OnDisableCancel(wxCommandEvent
& event
);
299 void OnCatchListBoxDClick(wxCommandEvent
& event
);
300 void OnTextEnter(wxCommandEvent
& event
);
303 bool m_catchListBoxDClick
;
306 DECLARE_EVENT_TABLE()
310 #if USE_SETTINGS_DIALOG
311 // Property sheet dialog
312 class SettingsDialog
: public wxPropertySheetDialog
314 DECLARE_CLASS(SettingsDialog
)
316 SettingsDialog(wxWindow
* parent
, int dialogType
);
319 wxPanel
* CreateGeneralSettingsPage(wxWindow
* parent
);
320 wxPanel
* CreateAestheticSettingsPage(wxWindow
* parent
);
325 ID_SHOW_TOOLTIPS
= 100,
328 ID_LOAD_LAST_PROJECT
,
330 ID_APPLY_SETTINGS_TO
,
335 wxImageList
* m_imageList
;
337 DECLARE_EVENT_TABLE()
340 #endif // USE_SETTINGS_DIALOG
342 // Define a new frame type
343 class MyFrame
: public wxFrame
346 MyFrame(const wxString
& title
);
350 void MessageBox(wxCommandEvent
& event
);
351 void MessageBoxDialog(wxCommandEvent
& event
);
352 void MessageBoxInfo(wxCommandEvent
& event
);
353 void MessageBoxWindowModal(wxCommandEvent
& event
);
354 void MessageBoxWindowModalClosed(wxWindowModalDialogEvent
& event
);
355 #endif // wxUSE_MSGDLG
357 void RichMessageDialog(wxCommandEvent
& event
);
358 #endif // wxUSE_RICHMSGDLG
361 void ChooseColour(wxCommandEvent
& event
);
362 void GetColour(wxCommandEvent
& event
);
363 #endif // wxUSE_COLOURDLG
366 void ChooseFont(wxCommandEvent
& event
);
367 #endif // wxUSE_FONTDLG
370 void LogDialog(wxCommandEvent
& event
);
371 #endif // wxUSE_LOG_DIALOG
374 void InfoBarSimple(wxCommandEvent
& event
);
375 void InfoBarAdvanced(wxCommandEvent
& event
);
376 #endif // wxUSE_INFOBAR
379 void SingleChoice(wxCommandEvent
& event
);
380 void MultiChoice(wxCommandEvent
& event
);
381 #endif // wxUSE_CHOICEDLG
383 void Rearrange(wxCommandEvent
& event
);
386 void LineEntry(wxCommandEvent
& event
);
387 void TextEntry(wxCommandEvent
& event
);
388 void PasswordEntry(wxCommandEvent
& event
);
389 #endif // wxUSE_TEXTDLG
392 void NumericEntry(wxCommandEvent
& event
);
393 #endif // wxUSE_NUMBERDLG
396 void FileOpen(wxCommandEvent
& event
);
397 void FileOpen2(wxCommandEvent
& event
);
398 void FilesOpen(wxCommandEvent
& event
);
399 void FileSave(wxCommandEvent
& event
);
400 #endif // wxUSE_FILEDLG
402 #if USE_FILEDLG_GENERIC
403 void FileOpenGeneric(wxCommandEvent
& event
);
404 void FilesOpenGeneric(wxCommandEvent
& event
);
405 void FileSaveGeneric(wxCommandEvent
& event
);
406 #endif // USE_FILEDLG_GENERIC
409 void DirChoose(wxCommandEvent
& event
);
410 void DirChooseNew(wxCommandEvent
& event
);
411 #endif // wxUSE_DIRDLG
413 #if USE_DIRDLG_GENERIC
414 void GenericDirChoose(wxCommandEvent
& event
);
415 #endif // USE_DIRDLG_GENERIC
417 #if wxUSE_STARTUP_TIPS
418 void ShowTip(wxCommandEvent
& event
);
419 #endif // wxUSE_STARTUP_TIPS
421 #if USE_MODAL_PRESENTATION
422 void ModalDlg(wxCommandEvent
& event
);
423 #endif // USE_MODAL_PRESENTATION
424 void ModelessDlg(wxCommandEvent
& event
);
425 void DlgCenteredScreen(wxCommandEvent
& event
);
426 void DlgCenteredParent(wxCommandEvent
& event
);
427 void MiniFrame(wxCommandEvent
& event
);
428 void DlgOnTop(wxCommandEvent
& event
);
430 #if wxUSE_PROGRESSDLG
431 void ShowProgress(wxCommandEvent
& event
);
432 #endif // wxUSE_PROGRESSDLG
435 void ShowSimpleAboutDialog(wxCommandEvent
& event
);
436 void ShowFancyAboutDialog(wxCommandEvent
& event
);
437 void ShowFullAboutDialog(wxCommandEvent
& event
);
438 void ShowCustomAboutDialog(wxCommandEvent
& event
);
439 #endif // wxUSE_ABOUTDLG
442 void ShowBusyInfo(wxCommandEvent
& event
);
443 #endif // wxUSE_BUSYINFO
445 #if wxUSE_FINDREPLDLG
446 void ShowFindDialog(wxCommandEvent
& event
);
447 void ShowReplaceDialog(wxCommandEvent
& event
);
448 void OnFindDialog(wxFindDialogEvent
& event
);
449 #endif // wxUSE_FINDREPLDLG
451 #if USE_COLOURDLG_GENERIC
452 void ChooseColourGeneric(wxCommandEvent
& event
);
453 #endif // USE_COLOURDLG_GENERIC
455 #if USE_FONTDLG_GENERIC
456 void ChooseFontGeneric(wxCommandEvent
& event
);
457 #endif // USE_FONTDLG_GENERIC
459 void OnPropertySheet(wxCommandEvent
& event
);
461 void OnRequestUserAttention(wxCommandEvent
& event
);
462 #if wxUSE_NOTIFICATION_MESSAGE
463 void OnNotifMsgAuto(wxCommandEvent
& event
);
464 void OnNotifMsgShow(wxCommandEvent
& event
);
465 void OnNotifMsgHide(wxCommandEvent
& event
);
466 #endif // wxUSE_NOTIFICATION_MESSAGE
468 void OnStandardButtonsSizerDialog(wxCommandEvent
& event
);
470 void OnTestDefaultActionDialog(wxCommandEvent
& event
);
472 void OnExit(wxCommandEvent
& event
);
476 void DoDirChoose(int style
);
477 #endif // wxUSE_DIRDLG
479 #if USE_MODAL_PRESENTATION
480 MyModelessDialog
*m_dialog
;
481 #endif // USE_MODAL_PRESENTATION
483 #if wxUSE_FINDREPLDLG
484 wxFindReplaceData m_findData
;
486 wxFindReplaceDialog
*m_dlgFind
,
488 #endif // wxUSE_FINDREPLDLG
490 #if wxUSE_NOTIFICATION_MESSAGE
491 wxNotificationMessage
*m_notifMsg
;
492 #endif // wxUSE_NOTIFICATION_MESSAGE
494 wxColourData m_clrData
;
496 // just a window which we use to show the effect of font/colours selection
500 void OnInfoBarRedo(wxCommandEvent
& event
);
502 wxInfoBar
*m_infoBarSimple
,
504 #endif // wxUSE_INFOBAR
506 DECLARE_EVENT_TABLE()
509 class MyCanvas
: public wxScrolledWindow
512 MyCanvas(wxWindow
*parent
) : wxScrolledWindow(parent
, wxID_ANY
)
514 SetForegroundColour(*wxBLACK
);
515 SetBackgroundColour(*wxWHITE
);
516 SetFont(*wxNORMAL_FONT
);
520 void OnPaint(wxPaintEvent
& event
);
522 DECLARE_EVENT_TABLE()
529 DIALOGS_CHOOSE_COLOUR
= wxID_HIGHEST
,
531 DIALOGS_CHOOSE_COLOUR_GENERIC
,
533 DIALOGS_CHOOSE_FONT_GENERIC
,
535 DIALOGS_MESSAGE_BOX_WINDOW_MODAL
,
536 DIALOGS_MESSAGE_DIALOG
,
537 DIALOGS_MESSAGE_BOX_WXINFO
,
538 DIALOGS_RICH_MESSAGE_DIALOG
,
539 DIALOGS_SINGLE_CHOICE
,
540 DIALOGS_MULTI_CHOICE
,
544 DIALOGS_PASSWORD_ENTRY
,
549 DIALOGS_FILE_OPEN_GENERIC
,
550 DIALOGS_FILES_OPEN_GENERIC
,
551 DIALOGS_FILE_SAVE_GENERIC
,
553 DIALOGS_DIRNEW_CHOOSE
,
554 DIALOGS_GENERIC_DIR_CHOOSE
,
558 DIALOGS_INFOBAR_SIMPLE
,
559 DIALOGS_INFOBAR_ADVANCED
,
562 DIALOGS_CENTRE_SCREEN
,
563 DIALOGS_CENTRE_PARENT
,
566 DIALOGS_MODELESS_BTN
,
568 DIALOGS_ABOUTDLG_SIMPLE
,
569 DIALOGS_ABOUTDLG_FANCY
,
570 DIALOGS_ABOUTDLG_FULL
,
571 DIALOGS_ABOUTDLG_CUSTOM
,
579 DIALOGS_PROPERTY_SHEET
,
580 DIALOGS_PROPERTY_SHEET_TOOLBOOK
,
581 DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
,
582 DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
,
583 DIALOGS_TEST_DEFAULT_ACTION