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
);
240 static const BtnInfo ms_btnInfo
[Btn_Max
];
253 wxTextCtrl
*m_textMsg
,
256 wxCheckBox
*m_buttons
[Btn_Max
];
257 wxTextCtrl
*m_labels
[Btn_Max
];
261 wxCheckBox
*m_chkNoDefault
,
264 DECLARE_EVENT_TABLE()
265 wxDECLARE_NO_COPY_CLASS(TestMessageBoxDialog
);
269 class TestRichMessageDialog
: public TestMessageBoxDialog
272 TestRichMessageDialog(wxWindow
*parent
);
275 // overrides method in base class
276 virtual void AddAdditionalTextOptions(wxSizer
*sizer
);
277 virtual void AddAdditionalFlags(wxSizer
*sizer
);
279 void OnApply(wxCommandEvent
& event
);
282 wxTextCtrl
*m_textCheckBox
;
283 wxCheckBox
*m_initialValueCheckBox
;
284 wxTextCtrl
*m_textDetailed
;
286 DECLARE_EVENT_TABLE()
288 #endif // wxUSE_RICHMSGDLG
290 class TestDefaultActionDialog
: public wxDialog
293 TestDefaultActionDialog( wxWindow
*parent
);
295 void OnListBoxDClick(wxCommandEvent
& event
);
296 void OnCatchListBoxDClick(wxCommandEvent
& event
);
299 bool m_catchListBoxDClick
;
302 DECLARE_EVENT_TABLE()
306 #if USE_SETTINGS_DIALOG
307 // Property sheet dialog
308 class SettingsDialog
: public wxPropertySheetDialog
310 DECLARE_CLASS(SettingsDialog
)
312 SettingsDialog(wxWindow
* parent
, int dialogType
);
315 wxPanel
* CreateGeneralSettingsPage(wxWindow
* parent
);
316 wxPanel
* CreateAestheticSettingsPage(wxWindow
* parent
);
321 ID_SHOW_TOOLTIPS
= 100,
324 ID_LOAD_LAST_PROJECT
,
326 ID_APPLY_SETTINGS_TO
,
331 wxImageList
* m_imageList
;
333 DECLARE_EVENT_TABLE()
336 #endif // USE_SETTINGS_DIALOG
338 // Define a new frame type
339 class MyFrame
: public wxFrame
342 MyFrame(const wxString
& title
);
346 void MessageBox(wxCommandEvent
& event
);
347 void MessageBoxDialog(wxCommandEvent
& event
);
348 void MessageBoxInfo(wxCommandEvent
& event
);
349 void MessageBoxWindowModal(wxCommandEvent
& event
);
350 void MessageBoxWindowModalClosed(wxWindowModalDialogEvent
& event
);
351 #endif // wxUSE_MSGDLG
353 void RichMessageDialog(wxCommandEvent
& event
);
354 #endif // wxUSE_RICHMSGDLG
357 void ChooseColour(wxCommandEvent
& event
);
358 void GetColour(wxCommandEvent
& event
);
359 #endif // wxUSE_COLOURDLG
362 void ChooseFont(wxCommandEvent
& event
);
363 #endif // wxUSE_FONTDLG
366 void LogDialog(wxCommandEvent
& event
);
367 #endif // wxUSE_LOG_DIALOG
370 void InfoBarSimple(wxCommandEvent
& event
);
371 void InfoBarAdvanced(wxCommandEvent
& event
);
372 #endif // wxUSE_INFOBAR
375 void SingleChoice(wxCommandEvent
& event
);
376 void MultiChoice(wxCommandEvent
& event
);
377 #endif // wxUSE_CHOICEDLG
379 void Rearrange(wxCommandEvent
& event
);
382 void TextEntry(wxCommandEvent
& event
);
383 void PasswordEntry(wxCommandEvent
& event
);
384 #endif // wxUSE_TEXTDLG
387 void NumericEntry(wxCommandEvent
& event
);
388 #endif // wxUSE_NUMBERDLG
391 void FileOpen(wxCommandEvent
& event
);
392 void FileOpen2(wxCommandEvent
& event
);
393 void FilesOpen(wxCommandEvent
& event
);
394 void FileSave(wxCommandEvent
& event
);
395 #endif // wxUSE_FILEDLG
397 #if USE_FILEDLG_GENERIC
398 void FileOpenGeneric(wxCommandEvent
& event
);
399 void FilesOpenGeneric(wxCommandEvent
& event
);
400 void FileSaveGeneric(wxCommandEvent
& event
);
401 #endif // USE_FILEDLG_GENERIC
404 void DirChoose(wxCommandEvent
& event
);
405 void DirChooseNew(wxCommandEvent
& event
);
406 #endif // wxUSE_DIRDLG
408 #if USE_DIRDLG_GENERIC
409 void GenericDirChoose(wxCommandEvent
& event
);
410 #endif // USE_DIRDLG_GENERIC
412 #if wxUSE_STARTUP_TIPS
413 void ShowTip(wxCommandEvent
& event
);
414 #endif // wxUSE_STARTUP_TIPS
416 #if USE_MODAL_PRESENTATION
417 void ModalDlg(wxCommandEvent
& event
);
418 #endif // USE_MODAL_PRESENTATION
419 void ModelessDlg(wxCommandEvent
& event
);
420 void DlgCenteredScreen(wxCommandEvent
& event
);
421 void DlgCenteredParent(wxCommandEvent
& event
);
422 void MiniFrame(wxCommandEvent
& event
);
423 void DlgOnTop(wxCommandEvent
& event
);
425 #if wxUSE_PROGRESSDLG
426 void ShowProgress(wxCommandEvent
& event
);
427 #endif // wxUSE_PROGRESSDLG
430 void ShowSimpleAboutDialog(wxCommandEvent
& event
);
431 void ShowFancyAboutDialog(wxCommandEvent
& event
);
432 void ShowFullAboutDialog(wxCommandEvent
& event
);
433 void ShowCustomAboutDialog(wxCommandEvent
& event
);
434 #endif // wxUSE_ABOUTDLG
437 void ShowBusyInfo(wxCommandEvent
& event
);
438 #endif // wxUSE_BUSYINFO
440 #if wxUSE_FINDREPLDLG
441 void ShowFindDialog(wxCommandEvent
& event
);
442 void ShowReplaceDialog(wxCommandEvent
& event
);
443 void OnFindDialog(wxFindDialogEvent
& event
);
444 #endif // wxUSE_FINDREPLDLG
446 #if USE_COLOURDLG_GENERIC
447 void ChooseColourGeneric(wxCommandEvent
& event
);
448 #endif // USE_COLOURDLG_GENERIC
450 #if USE_FONTDLG_GENERIC
451 void ChooseFontGeneric(wxCommandEvent
& event
);
452 #endif // USE_FONTDLG_GENERIC
454 void OnPropertySheet(wxCommandEvent
& event
);
456 void OnRequestUserAttention(wxCommandEvent
& event
);
457 #if wxUSE_NOTIFICATION_MESSAGE
458 void OnNotifMsgAuto(wxCommandEvent
& event
);
459 void OnNotifMsgShow(wxCommandEvent
& event
);
460 void OnNotifMsgHide(wxCommandEvent
& event
);
461 #endif // wxUSE_NOTIFICATION_MESSAGE
463 void OnStandardButtonsSizerDialog(wxCommandEvent
& event
);
465 void OnTestDefaultActionDialog(wxCommandEvent
& event
);
467 void OnExit(wxCommandEvent
& event
);
471 void DoDirChoose(int style
);
472 #endif // wxUSE_DIRDLG
474 #if USE_MODAL_PRESENTATION
475 MyModelessDialog
*m_dialog
;
476 #endif // USE_MODAL_PRESENTATION
478 #if wxUSE_FINDREPLDLG
479 wxFindReplaceData m_findData
;
481 wxFindReplaceDialog
*m_dlgFind
,
483 #endif // wxUSE_FINDREPLDLG
485 #if wxUSE_NOTIFICATION_MESSAGE
486 wxNotificationMessage
*m_notifMsg
;
487 #endif // wxUSE_NOTIFICATION_MESSAGE
489 wxColourData m_clrData
;
491 // just a window which we use to show the effect of font/colours selection
495 void OnInfoBarRedo(wxCommandEvent
& event
);
497 wxInfoBar
*m_infoBarSimple
,
499 #endif // wxUSE_INFOBAR
501 DECLARE_EVENT_TABLE()
504 class MyCanvas
: public wxScrolledWindow
507 MyCanvas(wxWindow
*parent
) : wxScrolledWindow(parent
, wxID_ANY
)
509 SetForegroundColour(*wxBLACK
);
510 SetBackgroundColour(*wxWHITE
);
511 SetFont(*wxNORMAL_FONT
);
515 void OnPaint(wxPaintEvent
& event
);
517 DECLARE_EVENT_TABLE()
524 DIALOGS_CHOOSE_COLOUR
= wxID_HIGHEST
,
526 DIALOGS_CHOOSE_COLOUR_GENERIC
,
528 DIALOGS_CHOOSE_FONT_GENERIC
,
530 DIALOGS_MESSAGE_BOX_WINDOW_MODAL
,
531 DIALOGS_MESSAGE_DIALOG
,
532 DIALOGS_MESSAGE_BOX_WXINFO
,
533 DIALOGS_RICH_MESSAGE_DIALOG
,
534 DIALOGS_SINGLE_CHOICE
,
535 DIALOGS_MULTI_CHOICE
,
538 DIALOGS_PASSWORD_ENTRY
,
543 DIALOGS_FILE_OPEN_GENERIC
,
544 DIALOGS_FILES_OPEN_GENERIC
,
545 DIALOGS_FILE_SAVE_GENERIC
,
547 DIALOGS_DIRNEW_CHOOSE
,
548 DIALOGS_GENERIC_DIR_CHOOSE
,
552 DIALOGS_INFOBAR_SIMPLE
,
553 DIALOGS_INFOBAR_ADVANCED
,
556 DIALOGS_CENTRE_SCREEN
,
557 DIALOGS_CENTRE_PARENT
,
560 DIALOGS_MODELESS_BTN
,
562 DIALOGS_ABOUTDLG_SIMPLE
,
563 DIALOGS_ABOUTDLG_FANCY
,
564 DIALOGS_ABOUTDLG_FULL
,
565 DIALOGS_ABOUTDLG_CUSTOM
,
573 DIALOGS_PROPERTY_SHEET
,
574 DIALOGS_PROPERTY_SHEET_TOOLBOOK
,
575 DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
,
576 DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
,
577 DIALOGS_TEST_DEFAULT_ACTION