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
GetBoxTitle() { return m_textTitle
->GetValue(); }
212 wxString
GetMessage() { return m_textMsg
->GetValue(); }
215 void PrepareMessageDialog(wxMessageDialogBase
&dlg
);
217 virtual void AddAdditionalTextOptions(wxSizer
*WXUNUSED(sizer
)) { }
218 virtual void AddAdditionalFlags(wxSizer
*WXUNUSED(sizer
)) { }
220 void OnApply(wxCommandEvent
& event
);
221 void OnClose(wxCommandEvent
& event
);
222 void OnUpdateLabelUI(wxUpdateUIEvent
& event
);
223 void OnUpdateNoDefaultUI(wxUpdateUIEvent
& event
);
242 static const BtnInfo ms_btnInfo
[Btn_Max
];
252 MsgDlgIcon_AuthNeeded
,
256 wxTextCtrl
*m_textTitle
,
260 wxCheckBox
*m_buttons
[Btn_Max
];
261 wxTextCtrl
*m_labels
[Btn_Max
];
265 wxCheckBox
*m_chkNoDefault
,
268 DECLARE_EVENT_TABLE()
269 wxDECLARE_NO_COPY_CLASS(TestMessageBoxDialog
);
273 class TestRichMessageDialog
: public TestMessageBoxDialog
276 TestRichMessageDialog(wxWindow
*parent
);
279 // overrides method in base class
280 virtual void AddAdditionalTextOptions(wxSizer
*sizer
);
281 virtual void AddAdditionalFlags(wxSizer
*sizer
);
283 void OnApply(wxCommandEvent
& event
);
286 wxTextCtrl
*m_textCheckBox
;
287 wxCheckBox
*m_initialValueCheckBox
;
288 wxTextCtrl
*m_textDetailed
;
290 DECLARE_EVENT_TABLE()
292 #endif // wxUSE_RICHMSGDLG
294 class TestDefaultActionDialog
: public wxDialog
297 TestDefaultActionDialog( wxWindow
*parent
);
299 void OnListBoxDClick(wxCommandEvent
& event
);
300 void OnDisableOK(wxCommandEvent
& event
);
301 void OnDisableCancel(wxCommandEvent
& event
);
302 void OnCatchListBoxDClick(wxCommandEvent
& event
);
303 void OnTextEnter(wxCommandEvent
& event
);
306 bool m_catchListBoxDClick
;
309 DECLARE_EVENT_TABLE()
313 #if USE_SETTINGS_DIALOG
314 // Property sheet dialog
315 class SettingsDialog
: public wxPropertySheetDialog
317 DECLARE_CLASS(SettingsDialog
)
319 SettingsDialog(wxWindow
* parent
, int dialogType
);
322 wxPanel
* CreateGeneralSettingsPage(wxWindow
* parent
);
323 wxPanel
* CreateAestheticSettingsPage(wxWindow
* parent
);
328 ID_SHOW_TOOLTIPS
= 100,
331 ID_LOAD_LAST_PROJECT
,
333 ID_APPLY_SETTINGS_TO
,
338 wxImageList
* m_imageList
;
340 DECLARE_EVENT_TABLE()
343 #endif // USE_SETTINGS_DIALOG
345 // Define a new frame type
346 class MyFrame
: public wxFrame
349 MyFrame(const wxString
& title
);
353 void MessageBox(wxCommandEvent
& event
);
354 void MessageBoxDialog(wxCommandEvent
& event
);
355 void MessageBoxInfo(wxCommandEvent
& event
);
356 void MessageBoxWindowModal(wxCommandEvent
& event
);
357 void MessageBoxWindowModalClosed(wxWindowModalDialogEvent
& event
);
358 #endif // wxUSE_MSGDLG
360 void RichMessageDialog(wxCommandEvent
& event
);
361 #endif // wxUSE_RICHMSGDLG
364 void ChooseColour(wxCommandEvent
& event
);
365 void GetColour(wxCommandEvent
& event
);
366 #endif // wxUSE_COLOURDLG
369 void ChooseFont(wxCommandEvent
& event
);
370 #endif // wxUSE_FONTDLG
373 void LogDialog(wxCommandEvent
& event
);
374 #endif // wxUSE_LOG_DIALOG
377 void InfoBarSimple(wxCommandEvent
& event
);
378 void InfoBarAdvanced(wxCommandEvent
& event
);
379 #endif // wxUSE_INFOBAR
382 void SingleChoice(wxCommandEvent
& event
);
383 void MultiChoice(wxCommandEvent
& event
);
384 #endif // wxUSE_CHOICEDLG
386 void Rearrange(wxCommandEvent
& event
);
389 void LineEntry(wxCommandEvent
& event
);
390 void TextEntry(wxCommandEvent
& event
);
391 void PasswordEntry(wxCommandEvent
& event
);
392 #endif // wxUSE_TEXTDLG
395 void NumericEntry(wxCommandEvent
& event
);
396 #endif // wxUSE_NUMBERDLG
399 void FileOpen(wxCommandEvent
& event
);
400 void FileOpen2(wxCommandEvent
& event
);
401 void FilesOpen(wxCommandEvent
& event
);
402 void FileSave(wxCommandEvent
& event
);
403 #endif // wxUSE_FILEDLG
405 #if USE_FILEDLG_GENERIC
406 void FileOpenGeneric(wxCommandEvent
& event
);
407 void FilesOpenGeneric(wxCommandEvent
& event
);
408 void FileSaveGeneric(wxCommandEvent
& event
);
409 #endif // USE_FILEDLG_GENERIC
412 void DirChoose(wxCommandEvent
& event
);
413 void DirChooseNew(wxCommandEvent
& event
);
414 #endif // wxUSE_DIRDLG
416 #if USE_DIRDLG_GENERIC
417 void GenericDirChoose(wxCommandEvent
& event
);
418 #endif // USE_DIRDLG_GENERIC
420 #if wxUSE_STARTUP_TIPS
421 void ShowTip(wxCommandEvent
& event
);
422 #endif // wxUSE_STARTUP_TIPS
424 #if USE_MODAL_PRESENTATION
425 void ModalDlg(wxCommandEvent
& event
);
426 #endif // USE_MODAL_PRESENTATION
427 void ModelessDlg(wxCommandEvent
& event
);
428 void DlgCenteredScreen(wxCommandEvent
& event
);
429 void DlgCenteredParent(wxCommandEvent
& event
);
430 void MiniFrame(wxCommandEvent
& event
);
431 void DlgOnTop(wxCommandEvent
& event
);
433 #if wxUSE_PROGRESSDLG
434 void ShowProgress(wxCommandEvent
& event
);
435 #endif // wxUSE_PROGRESSDLG
438 void ShowSimpleAboutDialog(wxCommandEvent
& event
);
439 void ShowFancyAboutDialog(wxCommandEvent
& event
);
440 void ShowFullAboutDialog(wxCommandEvent
& event
);
441 void ShowCustomAboutDialog(wxCommandEvent
& event
);
442 #endif // wxUSE_ABOUTDLG
445 void ShowBusyInfo(wxCommandEvent
& event
);
446 #endif // wxUSE_BUSYINFO
448 #if wxUSE_FINDREPLDLG
449 void ShowFindDialog(wxCommandEvent
& event
);
450 void ShowReplaceDialog(wxCommandEvent
& event
);
451 void OnFindDialog(wxFindDialogEvent
& event
);
452 #endif // wxUSE_FINDREPLDLG
454 #if USE_COLOURDLG_GENERIC
455 void ChooseColourGeneric(wxCommandEvent
& event
);
456 #endif // USE_COLOURDLG_GENERIC
458 #if USE_FONTDLG_GENERIC
459 void ChooseFontGeneric(wxCommandEvent
& event
);
460 #endif // USE_FONTDLG_GENERIC
462 void OnPropertySheet(wxCommandEvent
& event
);
464 void OnRequestUserAttention(wxCommandEvent
& event
);
465 #if wxUSE_NOTIFICATION_MESSAGE
466 void OnNotifMsgAuto(wxCommandEvent
& event
);
467 void OnNotifMsgShow(wxCommandEvent
& event
);
468 void OnNotifMsgHide(wxCommandEvent
& event
);
469 #endif // wxUSE_NOTIFICATION_MESSAGE
471 #if wxUSE_RICHTOOLTIP
472 void OnRichTipDialog(wxCommandEvent
& event
);
473 #endif // wxUSE_RICHTOOLTIP
475 void OnStandardButtonsSizerDialog(wxCommandEvent
& event
);
477 void OnTestDefaultActionDialog(wxCommandEvent
& event
);
478 void OnModalHook(wxCommandEvent
& event
);
480 void OnExit(wxCommandEvent
& event
);
484 void DoDirChoose(int style
);
485 #endif // wxUSE_DIRDLG
487 #if USE_MODAL_PRESENTATION
488 MyModelessDialog
*m_dialog
;
489 #endif // USE_MODAL_PRESENTATION
491 #if wxUSE_FINDREPLDLG
492 wxFindReplaceData m_findData
;
494 wxFindReplaceDialog
*m_dlgFind
,
496 #endif // wxUSE_FINDREPLDLG
498 #if wxUSE_NOTIFICATION_MESSAGE
499 wxNotificationMessage
*m_notifMsg
;
500 #endif // wxUSE_NOTIFICATION_MESSAGE
502 wxColourData m_clrData
;
504 // just a window which we use to show the effect of font/colours selection
508 void OnInfoBarRedo(wxCommandEvent
& event
);
510 wxInfoBar
*m_infoBarSimple
,
512 #endif // wxUSE_INFOBAR
514 DECLARE_EVENT_TABLE()
517 class MyCanvas
: public wxScrolledWindow
520 MyCanvas(wxWindow
*parent
) : wxScrolledWindow(parent
, wxID_ANY
)
522 SetForegroundColour(*wxBLACK
);
523 SetBackgroundColour(*wxWHITE
);
524 SetFont(*wxNORMAL_FONT
);
528 void OnPaint(wxPaintEvent
& event
);
530 DECLARE_EVENT_TABLE()
537 DIALOGS_CHOOSE_COLOUR
= wxID_HIGHEST
,
539 DIALOGS_CHOOSE_COLOUR_GENERIC
,
541 DIALOGS_CHOOSE_FONT_GENERIC
,
543 DIALOGS_MESSAGE_BOX_WINDOW_MODAL
,
544 DIALOGS_MESSAGE_DIALOG
,
545 DIALOGS_MESSAGE_BOX_WXINFO
,
546 DIALOGS_RICH_MESSAGE_DIALOG
,
547 DIALOGS_SINGLE_CHOICE
,
548 DIALOGS_MULTI_CHOICE
,
552 DIALOGS_PASSWORD_ENTRY
,
557 DIALOGS_FILE_OPEN_GENERIC
,
558 DIALOGS_FILES_OPEN_GENERIC
,
559 DIALOGS_FILE_SAVE_GENERIC
,
561 DIALOGS_DIRNEW_CHOOSE
,
562 DIALOGS_GENERIC_DIR_CHOOSE
,
566 DIALOGS_INFOBAR_SIMPLE
,
567 DIALOGS_INFOBAR_ADVANCED
,
570 DIALOGS_CENTRE_SCREEN
,
571 DIALOGS_CENTRE_PARENT
,
574 DIALOGS_MODELESS_BTN
,
576 DIALOGS_ABOUTDLG_SIMPLE
,
577 DIALOGS_ABOUTDLG_FANCY
,
578 DIALOGS_ABOUTDLG_FULL
,
579 DIALOGS_ABOUTDLG_CUSTOM
,
587 DIALOGS_RICHTIP_DIALOG
,
588 DIALOGS_PROPERTY_SHEET
,
589 DIALOGS_PROPERTY_SHEET_TOOLBOOK
,
590 DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
,
591 DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
,
592 DIALOGS_TEST_DEFAULT_ACTION
,