1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart, Vadim Zeitlin, ABX
6 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 This sample shows how to use the common dialogs available from wxWidgets.
14 It also shows that generic implementations of common dialogs can be exchanged
15 with native dialogs and can coexist in one application. The need for generic
16 dialogs addition is recognized thanks to setup of below USE_*** setting. Their
17 combinations reflects conditions of makefiles and project files to avoid unresolved
18 references during linking. For now some generic dialogs are added in static builds
25 #ifdef __WXUNIVERSAL__
26 #define USE_WXUNIVERSAL 1
28 #define USE_WXUNIVERSAL 0
37 #if defined(__WXWINCE__)
43 #if defined(__WXMSW__) && !USE_WXWINCE
55 #if defined(__WXMAC_OSX__) && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2) && USE_NATIVE_FONT_DIALOG_FOR_MACOSX
56 #define USE_WXMACFONTDLG 1
58 #define USE_WXMACFONTDLG 0
73 #define USE_GENERIC_DIALOGS (!USE_WXUNIVERSAL && !USE_DLL)
75 #define USE_COLOURDLG_GENERIC \
76 ((USE_WXMSW || USE_WXMAC) && USE_GENERIC_DIALOGS && wxUSE_COLOURDLG)
77 #define USE_DIRDLG_GENERIC \
78 ((USE_WXMSW || USE_WXMAC) && USE_GENERIC_DIALOGS && wxUSE_DIRDLG)
79 #define USE_FILEDLG_GENERIC \
80 ((((USE_WXMSW || USE_WXMAC || USE_WXPM || USE_WXGTK) \
81 && USE_GENERIC_DIALOGS) || USE_WXWINCE) && wxUSE_FILEDLG)
82 #define USE_FONTDLG_GENERIC \
83 ((USE_WXMSW || USE_WXMACFONTDLG || USE_WXPM) && USE_GENERIC_DIALOGS && wxUSE_FONTDLG)
85 // Turn USE_MODAL_PRESENTATION to 0 if there is any reason for not presenting difference
86 // between modal and modeless dialogs (ie. not implemented it in your port yet)
87 #if defined(__SMARTPHONE__) || !wxUSE_BOOKCTRL
88 #define USE_MODAL_PRESENTATION 0
90 #define USE_MODAL_PRESENTATION 1
94 // Turn USE_SETTINGS_DIALOG to 0 if supported
96 #define USE_SETTINGS_DIALOG 1
98 #define USE_SETTINGS_DIALOG 0
103 // Custom application traits class which we use to override the default log
105 class MyAppTraits
: public wxGUIAppTraits
108 virtual wxLog
*CreateLogTarget();
113 // Define a new application type
114 class MyApp
: public wxApp
117 MyApp() { m_startupProgressStyle
= -1; }
119 virtual bool OnInit();
121 #if wxUSE_CMDLINE_PARSER
122 virtual void OnInitCmdLine(wxCmdLineParser
& parser
);
123 virtual bool OnCmdLineParsed(wxCmdLineParser
& parser
);
124 #endif // wxUSE_CMDLINE_PARSER
128 virtual wxAppTraits
*CreateTraits() { return new MyAppTraits
; }
132 // Flag set to a valid value if command line option "progress" is used,
133 // this allows testing of wxProgressDialog before the main event loop is
134 // started. If this option is not specified it is set to -1 by default
135 // meaning that progress dialog shouldn't be shown at all.
136 long m_startupProgressStyle
;
139 #if USE_MODAL_PRESENTATION
141 // A custom modeless dialog
142 class MyModelessDialog
: public wxDialog
145 MyModelessDialog(wxWindow
*parent
);
147 void OnButton(wxCommandEvent
& event
);
148 void OnClose(wxCloseEvent
& event
);
151 DECLARE_EVENT_TABLE()
154 // A custom modal dialog
155 class MyModalDialog
: public wxDialog
158 MyModalDialog(wxWindow
*parent
);
160 void OnButton(wxCommandEvent
& event
);
163 wxButton
*m_btnModal
,
167 DECLARE_EVENT_TABLE()
170 #endif // USE_MODAL_PRESENTATION
172 // A class demonstrating CreateStdDialogButtonSizer()
173 class StdButtonSizerDialog
: public wxDialog
176 StdButtonSizerDialog(wxWindow
*parent
);
178 void OnEvent(wxCommandEvent
& event
);
181 void EnableDisableControls();
183 wxCheckBox
*m_chkboxAffirmativeButton
;
184 wxRadioButton
*m_radiobtnOk
,
187 wxCheckBox
*m_chkboxDismissButton
;
188 wxRadioButton
*m_radiobtnClose
,
191 wxCheckBox
*m_chkboxApply
,
196 wxSizer
*m_buttonsSizer
;
198 DECLARE_EVENT_TABLE()
201 // Test harness for wxMessageDialog.
202 class TestMessageBoxDialog
: public wxDialog
205 TestMessageBoxDialog(wxWindow
*parent
);
210 wxString
GetBoxTitle() { return m_textTitle
->GetValue(); }
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
];
251 MsgDlgIcon_AuthNeeded
,
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
);
477 void OnModalHook(wxCommandEvent
& event
);
479 void OnExit(wxCommandEvent
& event
);
483 void DoDirChoose(int style
);
484 #endif // wxUSE_DIRDLG
486 #if USE_MODAL_PRESENTATION
487 MyModelessDialog
*m_dialog
;
488 #endif // USE_MODAL_PRESENTATION
490 #if wxUSE_FINDREPLDLG
491 wxFindReplaceData m_findData
;
493 wxFindReplaceDialog
*m_dlgFind
,
495 #endif // wxUSE_FINDREPLDLG
497 #if wxUSE_NOTIFICATION_MESSAGE
498 wxNotificationMessage
*m_notifMsg
;
499 #endif // wxUSE_NOTIFICATION_MESSAGE
501 wxColourData m_clrData
;
503 // just a window which we use to show the effect of font/colours selection
507 void OnInfoBarRedo(wxCommandEvent
& event
);
509 wxInfoBar
*m_infoBarSimple
,
511 #endif // wxUSE_INFOBAR
513 DECLARE_EVENT_TABLE()
516 class MyCanvas
: public wxScrolledWindow
519 MyCanvas(wxWindow
*parent
) : wxScrolledWindow(parent
, wxID_ANY
)
521 SetForegroundColour(*wxBLACK
);
522 SetBackgroundColour(*wxWHITE
);
523 SetFont(*wxNORMAL_FONT
);
527 void OnPaint(wxPaintEvent
& event
);
529 DECLARE_EVENT_TABLE()
536 DIALOGS_CHOOSE_COLOUR
= wxID_HIGHEST
,
538 DIALOGS_CHOOSE_COLOUR_GENERIC
,
540 DIALOGS_CHOOSE_FONT_GENERIC
,
542 DIALOGS_MESSAGE_BOX_WINDOW_MODAL
,
543 DIALOGS_MESSAGE_DIALOG
,
544 DIALOGS_MESSAGE_BOX_WXINFO
,
545 DIALOGS_RICH_MESSAGE_DIALOG
,
546 DIALOGS_SINGLE_CHOICE
,
547 DIALOGS_MULTI_CHOICE
,
551 DIALOGS_PASSWORD_ENTRY
,
556 DIALOGS_FILE_OPEN_GENERIC
,
557 DIALOGS_FILES_OPEN_GENERIC
,
558 DIALOGS_FILE_SAVE_GENERIC
,
560 DIALOGS_DIRNEW_CHOOSE
,
561 DIALOGS_GENERIC_DIR_CHOOSE
,
565 DIALOGS_INFOBAR_SIMPLE
,
566 DIALOGS_INFOBAR_ADVANCED
,
569 DIALOGS_CENTRE_SCREEN
,
570 DIALOGS_CENTRE_PARENT
,
573 DIALOGS_MODELESS_BTN
,
575 DIALOGS_ABOUTDLG_SIMPLE
,
576 DIALOGS_ABOUTDLG_FANCY
,
577 DIALOGS_ABOUTDLG_FULL
,
578 DIALOGS_ABOUTDLG_CUSTOM
,
586 DIALOGS_RICHTIP_DIALOG
,
587 DIALOGS_PROPERTY_SHEET
,
588 DIALOGS_PROPERTY_SHEET_TOOLBOOK
,
589 DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
,
590 DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
,
591 DIALOGS_TEST_DEFAULT_ACTION
,