1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart, Vadim Zeitlin, ABX
7 // Copyright: (c) Julian Smart
10 // Licence: wxWindows license
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 virtual bool OnInit();
122 virtual wxAppTraits
*CreateTraits() { return new MyAppTraits
; }
126 #if USE_MODAL_PRESENTATION
128 // A custom modeless dialog
129 class MyModelessDialog
: public wxDialog
132 MyModelessDialog(wxWindow
*parent
);
134 void OnButton(wxCommandEvent
& event
);
135 void OnClose(wxCloseEvent
& event
);
138 DECLARE_EVENT_TABLE()
141 // A custom modal dialog
142 class MyModalDialog
: public wxDialog
145 MyModalDialog(wxWindow
*parent
);
147 void OnButton(wxCommandEvent
& event
);
150 wxButton
*m_btnModal
,
154 DECLARE_EVENT_TABLE()
157 #endif // USE_MODAL_PRESENTATION
159 // A class demonstrating CreateStdDialogButtonSizer()
160 class StdButtonSizerDialog
: public wxDialog
163 StdButtonSizerDialog(wxWindow
*parent
);
165 void OnEvent(wxCommandEvent
& event
);
168 void EnableDisableControls();
170 wxCheckBox
*m_chkboxAffirmativeButton
;
171 wxRadioButton
*m_radiobtnOk
,
174 wxCheckBox
*m_chkboxDismissButton
;
175 wxRadioButton
*m_radiobtnClose
,
178 wxCheckBox
*m_chkboxApply
,
183 wxSizer
*m_buttonsSizer
;
185 DECLARE_EVENT_TABLE()
188 // Test harness for wxMessageDialog.
189 class TestMessageBoxDialog
: public wxDialog
192 TestMessageBoxDialog(wxWindow
*parent
);
195 void OnApply(wxCommandEvent
& event
);
196 void OnClose(wxCommandEvent
& event
);
197 void OnUpdateLabelUI(wxUpdateUIEvent
& event
);
198 void OnUpdateNoDefaultUI(wxUpdateUIEvent
& event
);
215 static const BtnInfo ms_btnInfo
[Btn_Max
];
228 wxTextCtrl
*m_textMsg
,
231 wxCheckBox
*m_buttons
[Btn_Max
];
232 wxTextCtrl
*m_labels
[Btn_Max
];
236 wxCheckBox
*m_chkNoDefault
,
239 DECLARE_EVENT_TABLE()
240 wxDECLARE_NO_COPY_CLASS(TestMessageBoxDialog
);
243 class TestDefaultActionDialog
: public wxDialog
246 TestDefaultActionDialog( wxWindow
*parent
);
248 void OnListBoxDClick(wxCommandEvent
& event
);
249 void OnCatchListBoxDClick(wxCommandEvent
& event
);
252 bool m_catchListBoxDClick
;
255 DECLARE_EVENT_TABLE()
259 #if USE_SETTINGS_DIALOG
260 // Property sheet dialog
261 class SettingsDialog
: public wxPropertySheetDialog
263 DECLARE_CLASS(SettingsDialog
)
265 SettingsDialog(wxWindow
* parent
, int dialogType
);
268 wxPanel
* CreateGeneralSettingsPage(wxWindow
* parent
);
269 wxPanel
* CreateAestheticSettingsPage(wxWindow
* parent
);
274 ID_SHOW_TOOLTIPS
= 100,
277 ID_LOAD_LAST_PROJECT
,
279 ID_APPLY_SETTINGS_TO
,
284 wxImageList
* m_imageList
;
286 DECLARE_EVENT_TABLE()
289 #endif // USE_SETTINGS_DIALOG
291 // Define a new frame type
292 class MyFrame
: public wxFrame
295 MyFrame(const wxString
& title
);
299 void MessageBox(wxCommandEvent
& event
);
300 void MessageBoxDialog(wxCommandEvent
& event
);
301 void MessageBoxInfo(wxCommandEvent
& event
);
302 void MessageBoxWindowModal(wxCommandEvent
& event
);
303 void MessageBoxWindowModalClosed(wxWindowModalDialogEvent
& event
);
304 #endif // wxUSE_MSGDLG
307 void ChooseColour(wxCommandEvent
& event
);
308 void GetColour(wxCommandEvent
& event
);
309 #endif // wxUSE_COLOURDLG
312 void ChooseFont(wxCommandEvent
& event
);
313 #endif // wxUSE_FONTDLG
316 void LogDialog(wxCommandEvent
& event
);
317 #endif // wxUSE_LOG_DIALOG
320 void InfoBarSimple(wxCommandEvent
& event
);
321 void InfoBarAdvanced(wxCommandEvent
& event
);
322 #endif // wxUSE_INFOBAR
325 void SingleChoice(wxCommandEvent
& event
);
326 void MultiChoice(wxCommandEvent
& event
);
327 #endif // wxUSE_CHOICEDLG
329 void Rearrange(wxCommandEvent
& event
);
332 void TextEntry(wxCommandEvent
& event
);
333 void PasswordEntry(wxCommandEvent
& event
);
334 #endif // wxUSE_TEXTDLG
337 void NumericEntry(wxCommandEvent
& event
);
338 #endif // wxUSE_NUMBERDLG
341 void FileOpen(wxCommandEvent
& event
);
342 void FileOpen2(wxCommandEvent
& event
);
343 void FilesOpen(wxCommandEvent
& event
);
344 void FileSave(wxCommandEvent
& event
);
345 #endif // wxUSE_FILEDLG
347 #if USE_FILEDLG_GENERIC
348 void FileOpenGeneric(wxCommandEvent
& event
);
349 void FilesOpenGeneric(wxCommandEvent
& event
);
350 void FileSaveGeneric(wxCommandEvent
& event
);
351 #endif // USE_FILEDLG_GENERIC
354 void DirChoose(wxCommandEvent
& event
);
355 void DirChooseNew(wxCommandEvent
& event
);
356 #endif // wxUSE_DIRDLG
358 #if USE_DIRDLG_GENERIC
359 void GenericDirChoose(wxCommandEvent
& event
);
360 #endif // USE_DIRDLG_GENERIC
362 #if wxUSE_STARTUP_TIPS
363 void ShowTip(wxCommandEvent
& event
);
364 #endif // wxUSE_STARTUP_TIPS
366 #if USE_MODAL_PRESENTATION
367 void ModalDlg(wxCommandEvent
& event
);
368 #endif // USE_MODAL_PRESENTATION
369 void ModelessDlg(wxCommandEvent
& event
);
370 void DlgCenteredScreen(wxCommandEvent
& event
);
371 void DlgCenteredParent(wxCommandEvent
& event
);
372 void MiniFrame(wxCommandEvent
& event
);
373 void DlgOnTop(wxCommandEvent
& event
);
375 #if wxUSE_PROGRESSDLG
376 void ShowProgress(wxCommandEvent
& event
);
377 #endif // wxUSE_PROGRESSDLG
380 void ShowSimpleAboutDialog(wxCommandEvent
& event
);
381 void ShowFancyAboutDialog(wxCommandEvent
& event
);
382 void ShowFullAboutDialog(wxCommandEvent
& event
);
383 void ShowCustomAboutDialog(wxCommandEvent
& event
);
384 #endif // wxUSE_ABOUTDLG
387 void ShowBusyInfo(wxCommandEvent
& event
);
388 #endif // wxUSE_BUSYINFO
390 #if wxUSE_FINDREPLDLG
391 void ShowFindDialog(wxCommandEvent
& event
);
392 void ShowReplaceDialog(wxCommandEvent
& event
);
393 void OnFindDialog(wxFindDialogEvent
& event
);
394 #endif // wxUSE_FINDREPLDLG
396 #if USE_COLOURDLG_GENERIC
397 void ChooseColourGeneric(wxCommandEvent
& event
);
398 #endif // USE_COLOURDLG_GENERIC
400 #if USE_FONTDLG_GENERIC
401 void ChooseFontGeneric(wxCommandEvent
& event
);
402 #endif // USE_FONTDLG_GENERIC
404 void OnPropertySheet(wxCommandEvent
& event
);
406 void OnRequestUserAttention(wxCommandEvent
& event
);
407 #if wxUSE_NOTIFICATION_MESSAGE
408 void OnNotifMsgAuto(wxCommandEvent
& event
);
409 void OnNotifMsgShow(wxCommandEvent
& event
);
410 void OnNotifMsgHide(wxCommandEvent
& event
);
411 #endif // wxUSE_NOTIFICATION_MESSAGE
413 void OnStandardButtonsSizerDialog(wxCommandEvent
& event
);
415 void OnTestDefaultActionDialog(wxCommandEvent
& event
);
417 void OnExit(wxCommandEvent
& event
);
421 void DoDirChoose(int style
);
422 #endif // wxUSE_DIRDLG
424 #if USE_MODAL_PRESENTATION
425 MyModelessDialog
*m_dialog
;
426 #endif // USE_MODAL_PRESENTATION
428 #if wxUSE_FINDREPLDLG
429 wxFindReplaceData m_findData
;
431 wxFindReplaceDialog
*m_dlgFind
,
433 #endif // wxUSE_FINDREPLDLG
435 #if wxUSE_NOTIFICATION_MESSAGE
436 wxNotificationMessage
*m_notifMsg
;
437 #endif // wxUSE_NOTIFICATION_MESSAGE
439 wxColourData m_clrData
;
441 // just a window which we use to show the effect of font/colours selection
445 void OnInfoBarRedo(wxCommandEvent
& event
);
447 wxInfoBar
*m_infoBarSimple
,
449 #endif // wxUSE_INFOBAR
451 DECLARE_EVENT_TABLE()
454 class MyCanvas
: public wxScrolledWindow
457 MyCanvas(wxWindow
*parent
) : wxScrolledWindow(parent
, wxID_ANY
)
459 SetForegroundColour(*wxBLACK
);
460 SetBackgroundColour(*wxWHITE
);
461 SetFont(*wxNORMAL_FONT
);
465 void OnPaint(wxPaintEvent
& event
);
467 DECLARE_EVENT_TABLE()
474 DIALOGS_CHOOSE_COLOUR
= wxID_HIGHEST
,
476 DIALOGS_CHOOSE_COLOUR_GENERIC
,
478 DIALOGS_CHOOSE_FONT_GENERIC
,
480 DIALOGS_MESSAGE_BOX_WINDOW_MODAL
,
481 DIALOGS_MESSAGE_DIALOG
,
482 DIALOGS_MESSAGE_BOX_WXINFO
,
483 DIALOGS_SINGLE_CHOICE
,
484 DIALOGS_MULTI_CHOICE
,
487 DIALOGS_PASSWORD_ENTRY
,
492 DIALOGS_FILE_OPEN_GENERIC
,
493 DIALOGS_FILES_OPEN_GENERIC
,
494 DIALOGS_FILE_SAVE_GENERIC
,
496 DIALOGS_DIRNEW_CHOOSE
,
497 DIALOGS_GENERIC_DIR_CHOOSE
,
501 DIALOGS_INFOBAR_SIMPLE
,
502 DIALOGS_INFOBAR_ADVANCED
,
505 DIALOGS_CENTRE_SCREEN
,
506 DIALOGS_CENTRE_PARENT
,
509 DIALOGS_MODELESS_BTN
,
511 DIALOGS_ABOUTDLG_SIMPLE
,
512 DIALOGS_ABOUTDLG_FANCY
,
513 DIALOGS_ABOUTDLG_FULL
,
514 DIALOGS_ABOUTDLG_CUSTOM
,
522 DIALOGS_PROPERTY_SHEET
,
523 DIALOGS_PROPERTY_SHEET_TOOLBOOK
,
524 DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
,
525 DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
,
526 DIALOGS_TEST_DEFAULT_ACTION