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
];
255 wxTextCtrl
*m_textTitle
,
259 wxCheckBox
*m_buttons
[Btn_Max
];
260 wxTextCtrl
*m_labels
[Btn_Max
];
264 wxCheckBox
*m_chkNoDefault
,
267 DECLARE_EVENT_TABLE()
268 wxDECLARE_NO_COPY_CLASS(TestMessageBoxDialog
);
272 class TestRichMessageDialog
: public TestMessageBoxDialog
275 TestRichMessageDialog(wxWindow
*parent
);
278 // overrides method in base class
279 virtual void AddAdditionalTextOptions(wxSizer
*sizer
);
280 virtual void AddAdditionalFlags(wxSizer
*sizer
);
282 void OnApply(wxCommandEvent
& event
);
285 wxTextCtrl
*m_textCheckBox
;
286 wxCheckBox
*m_initialValueCheckBox
;
287 wxTextCtrl
*m_textDetailed
;
289 DECLARE_EVENT_TABLE()
291 #endif // wxUSE_RICHMSGDLG
293 class TestDefaultActionDialog
: public wxDialog
296 TestDefaultActionDialog( wxWindow
*parent
);
298 void OnListBoxDClick(wxCommandEvent
& event
);
299 void OnDisableOK(wxCommandEvent
& event
);
300 void OnDisableCancel(wxCommandEvent
& event
);
301 void OnCatchListBoxDClick(wxCommandEvent
& event
);
302 void OnTextEnter(wxCommandEvent
& event
);
305 bool m_catchListBoxDClick
;
308 DECLARE_EVENT_TABLE()
312 #if USE_SETTINGS_DIALOG
313 // Property sheet dialog
314 class SettingsDialog
: public wxPropertySheetDialog
316 DECLARE_CLASS(SettingsDialog
)
318 SettingsDialog(wxWindow
* parent
, int dialogType
);
321 wxPanel
* CreateGeneralSettingsPage(wxWindow
* parent
);
322 wxPanel
* CreateAestheticSettingsPage(wxWindow
* parent
);
327 ID_SHOW_TOOLTIPS
= 100,
330 ID_LOAD_LAST_PROJECT
,
332 ID_APPLY_SETTINGS_TO
,
337 wxImageList
* m_imageList
;
339 DECLARE_EVENT_TABLE()
342 #endif // USE_SETTINGS_DIALOG
344 // Define a new frame type
345 class MyFrame
: public wxFrame
348 MyFrame(const wxString
& title
);
352 void MessageBox(wxCommandEvent
& event
);
353 void MessageBoxDialog(wxCommandEvent
& event
);
354 void MessageBoxInfo(wxCommandEvent
& event
);
355 void MessageBoxWindowModal(wxCommandEvent
& event
);
356 void MessageBoxWindowModalClosed(wxWindowModalDialogEvent
& event
);
357 #endif // wxUSE_MSGDLG
359 void RichMessageDialog(wxCommandEvent
& event
);
360 #endif // wxUSE_RICHMSGDLG
363 void ChooseColour(wxCommandEvent
& event
);
364 void GetColour(wxCommandEvent
& event
);
365 #endif // wxUSE_COLOURDLG
368 void ChooseFont(wxCommandEvent
& event
);
369 #endif // wxUSE_FONTDLG
372 void LogDialog(wxCommandEvent
& event
);
373 #endif // wxUSE_LOG_DIALOG
376 void InfoBarSimple(wxCommandEvent
& event
);
377 void InfoBarAdvanced(wxCommandEvent
& event
);
378 #endif // wxUSE_INFOBAR
381 void SingleChoice(wxCommandEvent
& event
);
382 void MultiChoice(wxCommandEvent
& event
);
383 #endif // wxUSE_CHOICEDLG
385 void Rearrange(wxCommandEvent
& event
);
388 void LineEntry(wxCommandEvent
& event
);
389 void TextEntry(wxCommandEvent
& event
);
390 void PasswordEntry(wxCommandEvent
& event
);
391 #endif // wxUSE_TEXTDLG
394 void NumericEntry(wxCommandEvent
& event
);
395 #endif // wxUSE_NUMBERDLG
398 void FileOpen(wxCommandEvent
& event
);
399 void FileOpen2(wxCommandEvent
& event
);
400 void FilesOpen(wxCommandEvent
& event
);
401 void FileSave(wxCommandEvent
& event
);
402 #endif // wxUSE_FILEDLG
404 #if USE_FILEDLG_GENERIC
405 void FileOpenGeneric(wxCommandEvent
& event
);
406 void FilesOpenGeneric(wxCommandEvent
& event
);
407 void FileSaveGeneric(wxCommandEvent
& event
);
408 #endif // USE_FILEDLG_GENERIC
411 void DirChoose(wxCommandEvent
& event
);
412 void DirChooseNew(wxCommandEvent
& event
);
413 #endif // wxUSE_DIRDLG
415 #if USE_DIRDLG_GENERIC
416 void GenericDirChoose(wxCommandEvent
& event
);
417 #endif // USE_DIRDLG_GENERIC
419 #if wxUSE_STARTUP_TIPS
420 void ShowTip(wxCommandEvent
& event
);
421 #endif // wxUSE_STARTUP_TIPS
423 #if USE_MODAL_PRESENTATION
424 void ModalDlg(wxCommandEvent
& event
);
425 #endif // USE_MODAL_PRESENTATION
426 void ModelessDlg(wxCommandEvent
& event
);
427 void DlgCenteredScreen(wxCommandEvent
& event
);
428 void DlgCenteredParent(wxCommandEvent
& event
);
429 void MiniFrame(wxCommandEvent
& event
);
430 void DlgOnTop(wxCommandEvent
& event
);
432 #if wxUSE_PROGRESSDLG
433 void ShowProgress(wxCommandEvent
& event
);
434 #endif // wxUSE_PROGRESSDLG
437 void ShowSimpleAboutDialog(wxCommandEvent
& event
);
438 void ShowFancyAboutDialog(wxCommandEvent
& event
);
439 void ShowFullAboutDialog(wxCommandEvent
& event
);
440 void ShowCustomAboutDialog(wxCommandEvent
& event
);
441 #endif // wxUSE_ABOUTDLG
444 void ShowBusyInfo(wxCommandEvent
& event
);
445 #endif // wxUSE_BUSYINFO
447 #if wxUSE_FINDREPLDLG
448 void ShowFindDialog(wxCommandEvent
& event
);
449 void ShowReplaceDialog(wxCommandEvent
& event
);
450 void OnFindDialog(wxFindDialogEvent
& event
);
451 #endif // wxUSE_FINDREPLDLG
453 #if USE_COLOURDLG_GENERIC
454 void ChooseColourGeneric(wxCommandEvent
& event
);
455 #endif // USE_COLOURDLG_GENERIC
457 #if USE_FONTDLG_GENERIC
458 void ChooseFontGeneric(wxCommandEvent
& event
);
459 #endif // USE_FONTDLG_GENERIC
461 void OnPropertySheet(wxCommandEvent
& event
);
463 void OnRequestUserAttention(wxCommandEvent
& event
);
464 #if wxUSE_NOTIFICATION_MESSAGE
465 void OnNotifMsgAuto(wxCommandEvent
& event
);
466 void OnNotifMsgShow(wxCommandEvent
& event
);
467 void OnNotifMsgHide(wxCommandEvent
& event
);
468 #endif // wxUSE_NOTIFICATION_MESSAGE
470 #if wxUSE_RICHTOOLTIP
471 void OnRichTipDialog(wxCommandEvent
& event
);
472 #endif // wxUSE_RICHTOOLTIP
474 void OnStandardButtonsSizerDialog(wxCommandEvent
& event
);
476 void OnTestDefaultActionDialog(wxCommandEvent
& event
);
478 void OnExit(wxCommandEvent
& event
);
482 void DoDirChoose(int style
);
483 #endif // wxUSE_DIRDLG
485 #if USE_MODAL_PRESENTATION
486 MyModelessDialog
*m_dialog
;
487 #endif // USE_MODAL_PRESENTATION
489 #if wxUSE_FINDREPLDLG
490 wxFindReplaceData m_findData
;
492 wxFindReplaceDialog
*m_dlgFind
,
494 #endif // wxUSE_FINDREPLDLG
496 #if wxUSE_NOTIFICATION_MESSAGE
497 wxNotificationMessage
*m_notifMsg
;
498 #endif // wxUSE_NOTIFICATION_MESSAGE
500 wxColourData m_clrData
;
502 // just a window which we use to show the effect of font/colours selection
506 void OnInfoBarRedo(wxCommandEvent
& event
);
508 wxInfoBar
*m_infoBarSimple
,
510 #endif // wxUSE_INFOBAR
512 DECLARE_EVENT_TABLE()
515 class MyCanvas
: public wxScrolledWindow
518 MyCanvas(wxWindow
*parent
) : wxScrolledWindow(parent
, wxID_ANY
)
520 SetForegroundColour(*wxBLACK
);
521 SetBackgroundColour(*wxWHITE
);
522 SetFont(*wxNORMAL_FONT
);
526 void OnPaint(wxPaintEvent
& event
);
528 DECLARE_EVENT_TABLE()
535 DIALOGS_CHOOSE_COLOUR
= wxID_HIGHEST
,
537 DIALOGS_CHOOSE_COLOUR_GENERIC
,
539 DIALOGS_CHOOSE_FONT_GENERIC
,
541 DIALOGS_MESSAGE_BOX_WINDOW_MODAL
,
542 DIALOGS_MESSAGE_DIALOG
,
543 DIALOGS_MESSAGE_BOX_WXINFO
,
544 DIALOGS_RICH_MESSAGE_DIALOG
,
545 DIALOGS_SINGLE_CHOICE
,
546 DIALOGS_MULTI_CHOICE
,
550 DIALOGS_PASSWORD_ENTRY
,
555 DIALOGS_FILE_OPEN_GENERIC
,
556 DIALOGS_FILES_OPEN_GENERIC
,
557 DIALOGS_FILE_SAVE_GENERIC
,
559 DIALOGS_DIRNEW_CHOOSE
,
560 DIALOGS_GENERIC_DIR_CHOOSE
,
564 DIALOGS_INFOBAR_SIMPLE
,
565 DIALOGS_INFOBAR_ADVANCED
,
568 DIALOGS_CENTRE_SCREEN
,
569 DIALOGS_CENTRE_PARENT
,
572 DIALOGS_MODELESS_BTN
,
574 DIALOGS_ABOUTDLG_SIMPLE
,
575 DIALOGS_ABOUTDLG_FANCY
,
576 DIALOGS_ABOUTDLG_FULL
,
577 DIALOGS_ABOUTDLG_CUSTOM
,
585 DIALOGS_RICHTIP_DIALOG
,
586 DIALOGS_PROPERTY_SHEET
,
587 DIALOGS_PROPERTY_SHEET_TOOLBOOK
,
588 DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
,
589 DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
,
590 DIALOGS_TEST_DEFAULT_ACTION