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
];
217 wxTextCtrl
*m_textMsg
,
220 wxCheckBox
*m_buttons
[Btn_Max
];
221 wxTextCtrl
*m_labels
[Btn_Max
];
225 wxCheckBox
*m_chkNoDefault
,
228 DECLARE_EVENT_TABLE()
229 wxDECLARE_NO_COPY_CLASS(TestMessageBoxDialog
);
232 class TestDefaultActionDialog
: public wxDialog
235 TestDefaultActionDialog( wxWindow
*parent
);
237 void OnListBoxDClick(wxCommandEvent
& event
);
238 void OnCatchListBoxDClick(wxCommandEvent
& event
);
241 bool m_catchListBoxDClick
;
244 DECLARE_EVENT_TABLE()
248 #if USE_SETTINGS_DIALOG
249 // Property sheet dialog
250 class SettingsDialog
: public wxPropertySheetDialog
252 DECLARE_CLASS(SettingsDialog
)
254 SettingsDialog(wxWindow
* parent
, int dialogType
);
257 wxPanel
* CreateGeneralSettingsPage(wxWindow
* parent
);
258 wxPanel
* CreateAestheticSettingsPage(wxWindow
* parent
);
263 ID_SHOW_TOOLTIPS
= 100,
266 ID_LOAD_LAST_PROJECT
,
268 ID_APPLY_SETTINGS_TO
,
273 wxImageList
* m_imageList
;
275 DECLARE_EVENT_TABLE()
278 #endif // USE_SETTINGS_DIALOG
280 // Define a new frame type
281 class MyFrame
: public wxFrame
284 MyFrame(const wxString
& title
);
288 void MessageBox(wxCommandEvent
& event
);
289 void MessageBoxDialog(wxCommandEvent
& event
);
290 void MessageBoxInfo(wxCommandEvent
& event
);
291 #endif // wxUSE_MSGDLG
294 void ChooseColour(wxCommandEvent
& event
);
295 void GetColour(wxCommandEvent
& event
);
296 #endif // wxUSE_COLOURDLG
299 void ChooseFont(wxCommandEvent
& event
);
300 #endif // wxUSE_FONTDLG
303 void LogDialog(wxCommandEvent
& event
);
304 #endif // wxUSE_LOG_DIALOG
307 void SingleChoice(wxCommandEvent
& event
);
308 void MultiChoice(wxCommandEvent
& event
);
309 #endif // wxUSE_CHOICEDLG
311 void Rearrange(wxCommandEvent
& event
);
314 void TextEntry(wxCommandEvent
& event
);
315 void PasswordEntry(wxCommandEvent
& event
);
316 #endif // wxUSE_TEXTDLG
319 void NumericEntry(wxCommandEvent
& event
);
320 #endif // wxUSE_NUMBERDLG
323 void FileOpen(wxCommandEvent
& event
);
324 void FileOpen2(wxCommandEvent
& event
);
325 void FilesOpen(wxCommandEvent
& event
);
326 void FileSave(wxCommandEvent
& event
);
327 #endif // wxUSE_FILEDLG
329 #if USE_FILEDLG_GENERIC
330 void FileOpenGeneric(wxCommandEvent
& event
);
331 void FilesOpenGeneric(wxCommandEvent
& event
);
332 void FileSaveGeneric(wxCommandEvent
& event
);
333 #endif // USE_FILEDLG_GENERIC
336 void DirChoose(wxCommandEvent
& event
);
337 void DirChooseNew(wxCommandEvent
& event
);
338 #endif // wxUSE_DIRDLG
340 #if USE_DIRDLG_GENERIC
341 void GenericDirChoose(wxCommandEvent
& event
);
342 #endif // USE_DIRDLG_GENERIC
344 #if wxUSE_STARTUP_TIPS
345 void ShowTip(wxCommandEvent
& event
);
346 #endif // wxUSE_STARTUP_TIPS
348 #if USE_MODAL_PRESENTATION
349 void ModalDlg(wxCommandEvent
& event
);
350 #endif // USE_MODAL_PRESENTATION
351 void ModelessDlg(wxCommandEvent
& event
);
352 void DlgCenteredScreen(wxCommandEvent
& event
);
353 void DlgCenteredParent(wxCommandEvent
& event
);
354 void MiniFrame(wxCommandEvent
& event
);
355 void DlgOnTop(wxCommandEvent
& event
);
357 #if wxUSE_PROGRESSDLG
358 void ShowProgress(wxCommandEvent
& event
);
359 #endif // wxUSE_PROGRESSDLG
362 void ShowSimpleAboutDialog(wxCommandEvent
& event
);
363 void ShowFancyAboutDialog(wxCommandEvent
& event
);
364 void ShowFullAboutDialog(wxCommandEvent
& event
);
365 void ShowCustomAboutDialog(wxCommandEvent
& event
);
366 #endif // wxUSE_ABOUTDLG
369 void ShowBusyInfo(wxCommandEvent
& event
);
370 #endif // wxUSE_BUSYINFO
372 #if wxUSE_FINDREPLDLG
373 void ShowFindDialog(wxCommandEvent
& event
);
374 void ShowReplaceDialog(wxCommandEvent
& event
);
375 void OnFindDialog(wxFindDialogEvent
& event
);
376 #endif // wxUSE_FINDREPLDLG
378 #if USE_COLOURDLG_GENERIC
379 void ChooseColourGeneric(wxCommandEvent
& event
);
380 #endif // USE_COLOURDLG_GENERIC
382 #if USE_FONTDLG_GENERIC
383 void ChooseFontGeneric(wxCommandEvent
& event
);
384 #endif // USE_FONTDLG_GENERIC
386 void OnPropertySheet(wxCommandEvent
& event
);
388 void OnRequestUserAttention(wxCommandEvent
& event
);
389 #if wxUSE_NOTIFICATION_MESSAGE
390 void OnNotifMsgAuto(wxCommandEvent
& event
);
391 void OnNotifMsgShow(wxCommandEvent
& event
);
392 void OnNotifMsgHide(wxCommandEvent
& event
);
393 #endif // wxUSE_NOTIFICATION_MESSAGE
395 void OnStandardButtonsSizerDialog(wxCommandEvent
& event
);
397 void OnTestDefaultActionDialog(wxCommandEvent
& event
);
399 void OnExit(wxCommandEvent
& event
);
403 void DoDirChoose(int style
);
404 #endif // wxUSE_DIRDLG
406 #if USE_MODAL_PRESENTATION
407 MyModelessDialog
*m_dialog
;
408 #endif // USE_MODAL_PRESENTATION
410 #if wxUSE_FINDREPLDLG
411 wxFindReplaceData m_findData
;
413 wxFindReplaceDialog
*m_dlgFind
,
415 #endif // wxUSE_FINDREPLDLG
417 #if wxUSE_NOTIFICATION_MESSAGE
418 wxNotificationMessage
*m_notifMsg
;
419 #endif // wxUSE_NOTIFICATION_MESSAGE
421 wxColourData m_clrData
;
423 // just a window which we use to show the effect of font/colours selection
426 DECLARE_EVENT_TABLE()
429 class MyCanvas
: public wxScrolledWindow
432 MyCanvas(wxWindow
*parent
) : wxScrolledWindow(parent
, wxID_ANY
)
434 SetForegroundColour(*wxBLACK
);
435 SetBackgroundColour(*wxWHITE
);
436 SetFont(*wxNORMAL_FONT
);
440 void OnPaint(wxPaintEvent
& event
);
442 DECLARE_EVENT_TABLE()
449 DIALOGS_CHOOSE_COLOUR
= wxID_HIGHEST
,
451 DIALOGS_CHOOSE_COLOUR_GENERIC
,
453 DIALOGS_CHOOSE_FONT_GENERIC
,
455 DIALOGS_MESSAGE_DIALOG
,
456 DIALOGS_MESSAGE_BOX_WXINFO
,
457 DIALOGS_SINGLE_CHOICE
,
458 DIALOGS_MULTI_CHOICE
,
461 DIALOGS_PASSWORD_ENTRY
,
466 DIALOGS_FILE_OPEN_GENERIC
,
467 DIALOGS_FILES_OPEN_GENERIC
,
468 DIALOGS_FILE_SAVE_GENERIC
,
470 DIALOGS_DIRNEW_CHOOSE
,
471 DIALOGS_GENERIC_DIR_CHOOSE
,
477 DIALOGS_CENTRE_SCREEN
,
478 DIALOGS_CENTRE_PARENT
,
481 DIALOGS_MODELESS_BTN
,
483 DIALOGS_ABOUTDLG_SIMPLE
,
484 DIALOGS_ABOUTDLG_FANCY
,
485 DIALOGS_ABOUTDLG_FULL
,
486 DIALOGS_ABOUTDLG_CUSTOM
,
494 DIALOGS_PROPERTY_SHEET
,
495 DIALOGS_PROPERTY_SHEET_TOOLBOOK
,
496 DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
,
497 DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
,
498 DIALOGS_TEST_DEFAULT_ACTION