1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart
5 // Modified by: ABX (2004) - adjustementd for conditional building
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
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 virtual bool OnInit();
120 wxColour m_canvasTextColour
;
124 virtual wxAppTraits
*CreateTraits() { return new MyAppTraits
; }
128 #if USE_MODAL_PRESENTATION
130 // A custom modeless dialog
131 class MyModelessDialog
: public wxDialog
134 MyModelessDialog(wxWindow
*parent
);
136 void OnButton(wxCommandEvent
& event
);
137 void OnClose(wxCloseEvent
& event
);
140 DECLARE_EVENT_TABLE()
143 // A custom modal dialog
144 class MyModalDialog
: public wxDialog
147 MyModalDialog(wxWindow
*parent
);
149 void OnButton(wxCommandEvent
& event
);
152 wxButton
*m_btnModal
,
156 DECLARE_EVENT_TABLE()
159 #endif // USE_MODAL_PRESENTATION
161 // A class demonstrating CreateStdDialogButtonSizer()
162 class StdButtonSizerDialog
: public wxDialog
165 StdButtonSizerDialog(wxWindow
*parent
);
167 void OnEvent(wxCommandEvent
& event
);
170 void EnableDisableControls();
172 wxCheckBox
*m_chkboxAffirmativeButton
;
173 wxRadioButton
*m_radiobtnOk
,
176 wxCheckBox
*m_chkboxDismissButton
;
177 wxRadioButton
*m_radiobtnClose
,
180 wxCheckBox
*m_chkboxApply
,
185 wxSizer
*m_buttonsSizer
;
187 DECLARE_EVENT_TABLE()
190 // Test harness for wxMessageDialog.
191 class TestMessageBoxDialog
: public wxDialog
194 TestMessageBoxDialog(wxWindow
*parent
);
197 void OnApply(wxCommandEvent
& event
);
198 void OnClose(wxCommandEvent
& event
);
199 void OnUpdateLabelUI(wxUpdateUIEvent
& event
);
200 void OnUpdateNoDefaultUI(wxUpdateUIEvent
& event
);
217 static const BtnInfo ms_btnInfo
[Btn_Max
];
219 wxTextCtrl
*m_textMsg
,
222 wxCheckBox
*m_buttons
[Btn_Max
];
223 wxTextCtrl
*m_labels
[Btn_Max
];
227 wxCheckBox
*m_chkNoDefault
,
230 DECLARE_EVENT_TABLE()
231 DECLARE_NO_COPY_CLASS(TestMessageBoxDialog
)
234 class TestDefaultActionDialog
: public wxDialog
237 TestDefaultActionDialog( wxWindow
*parent
);
239 void OnListBoxDClick(wxCommandEvent
& event
);
240 void OnCatchListBoxDClick(wxCommandEvent
& event
);
243 bool m_catchListBoxDClick
;
246 DECLARE_EVENT_TABLE()
250 #if USE_SETTINGS_DIALOG
251 // Property sheet dialog
252 class SettingsDialog
: public wxPropertySheetDialog
254 DECLARE_CLASS(SettingsDialog
)
256 SettingsDialog(wxWindow
* parent
, int dialogType
);
259 wxPanel
* CreateGeneralSettingsPage(wxWindow
* parent
);
260 wxPanel
* CreateAestheticSettingsPage(wxWindow
* parent
);
265 ID_SHOW_TOOLTIPS
= 100,
268 ID_LOAD_LAST_PROJECT
,
270 ID_APPLY_SETTINGS_TO
,
275 wxImageList
* m_imageList
;
277 DECLARE_EVENT_TABLE()
280 #endif // USE_SETTINGS_DIALOG
282 // Define a new frame type
283 class MyFrame
: public wxFrame
286 MyFrame(wxWindow
*parent
, const wxString
& title
);
290 void MessageBox(wxCommandEvent
& event
);
291 void MessageBoxDialog(wxCommandEvent
& event
);
292 void MessageBoxInfo(wxCommandEvent
& event
);
293 #endif // wxUSE_MSGDLG
296 void ChooseColour(wxCommandEvent
& event
);
297 void GetColour(wxCommandEvent
& event
);
298 #endif // wxUSE_COLOURDLG
301 void ChooseFont(wxCommandEvent
& event
);
302 #endif // wxUSE_FONTDLG
305 void LogDialog(wxCommandEvent
& event
);
306 #endif // wxUSE_LOG_DIALOG
309 void SingleChoice(wxCommandEvent
& event
);
310 void MultiChoice(wxCommandEvent
& event
);
311 #endif // wxUSE_CHOICEDLG
313 void Rearrange(wxCommandEvent
& event
);
316 void TextEntry(wxCommandEvent
& event
);
317 void PasswordEntry(wxCommandEvent
& event
);
318 #endif // wxUSE_TEXTDLG
321 void NumericEntry(wxCommandEvent
& event
);
322 #endif // wxUSE_NUMBERDLG
325 void FileOpen(wxCommandEvent
& event
);
326 void FileOpen2(wxCommandEvent
& event
);
327 void FilesOpen(wxCommandEvent
& event
);
328 void FileSave(wxCommandEvent
& event
);
329 #endif // wxUSE_FILEDLG
331 #if USE_FILEDLG_GENERIC
332 void FileOpenGeneric(wxCommandEvent
& event
);
333 void FilesOpenGeneric(wxCommandEvent
& event
);
334 void FileSaveGeneric(wxCommandEvent
& event
);
335 #endif // USE_FILEDLG_GENERIC
338 void DirChoose(wxCommandEvent
& event
);
339 void DirChooseNew(wxCommandEvent
& event
);
340 #endif // wxUSE_DIRDLG
342 #if USE_DIRDLG_GENERIC
343 void GenericDirChoose(wxCommandEvent
& event
);
344 #endif // USE_DIRDLG_GENERIC
346 #if wxUSE_STARTUP_TIPS
347 void ShowTip(wxCommandEvent
& event
);
348 #endif // wxUSE_STARTUP_TIPS
350 #if USE_MODAL_PRESENTATION
351 void ModalDlg(wxCommandEvent
& event
);
352 #endif // USE_MODAL_PRESENTATION
353 void ModelessDlg(wxCommandEvent
& event
);
354 void DlgCenteredScreen(wxCommandEvent
& event
);
355 void DlgCenteredParent(wxCommandEvent
& event
);
356 void MiniFrame(wxCommandEvent
& event
);
357 void DlgOnTop(wxCommandEvent
& event
);
359 #if wxUSE_PROGRESSDLG
360 void ShowProgress(wxCommandEvent
& event
);
361 #endif // wxUSE_PROGRESSDLG
364 void ShowSimpleAboutDialog(wxCommandEvent
& event
);
365 void ShowFancyAboutDialog(wxCommandEvent
& event
);
366 void ShowFullAboutDialog(wxCommandEvent
& event
);
367 void ShowCustomAboutDialog(wxCommandEvent
& event
);
368 #endif // wxUSE_ABOUTDLG
371 void ShowBusyInfo(wxCommandEvent
& event
);
372 #endif // wxUSE_BUSYINFO
374 #if wxUSE_FINDREPLDLG
375 void ShowFindDialog(wxCommandEvent
& event
);
376 void ShowReplaceDialog(wxCommandEvent
& event
);
377 void OnFindDialog(wxFindDialogEvent
& event
);
378 #endif // wxUSE_FINDREPLDLG
380 #if USE_COLOURDLG_GENERIC
381 void ChooseColourGeneric(wxCommandEvent
& event
);
382 #endif // USE_COLOURDLG_GENERIC
384 #if USE_FONTDLG_GENERIC
385 void ChooseFontGeneric(wxCommandEvent
& event
);
386 #endif // USE_FONTDLG_GENERIC
388 void OnPropertySheet(wxCommandEvent
& event
);
390 void OnRequestUserAttention(wxCommandEvent
& event
);
391 #if wxUSE_NOTIFICATION_MESSAGE
392 void OnNotifMsgAuto(wxCommandEvent
& event
);
393 void OnNotifMsgShow(wxCommandEvent
& event
);
394 void OnNotifMsgHide(wxCommandEvent
& event
);
395 #endif // wxUSE_NOTIFICATION_MESSAGE
397 void OnStandardButtonsSizerDialog(wxCommandEvent
& event
);
399 void OnTestDefaultActionDialog(wxCommandEvent
& event
);
401 void OnExit(wxCommandEvent
& event
);
405 void DoDirChoose(int style
);
406 #endif // wxUSE_DIRDLG
408 #if USE_MODAL_PRESENTATION
409 MyModelessDialog
*m_dialog
;
410 #endif // USE_MODAL_PRESENTATION
412 #if wxUSE_FINDREPLDLG
413 wxFindReplaceData m_findData
;
415 wxFindReplaceDialog
*m_dlgFind
,
417 #endif // wxUSE_FINDREPLDLG
419 #if wxUSE_NOTIFICATION_MESSAGE
420 wxNotificationMessage
*m_notifMsg
;
421 #endif // wxUSE_NOTIFICATION_MESSAGE
423 wxColourData m_clrData
;
425 DECLARE_EVENT_TABLE()
428 class MyCanvas
: public wxScrolledWindow
431 MyCanvas(wxWindow
*parent
) :
432 wxScrolledWindow(parent
,wxID_ANY
,wxDefaultPosition
,wxDefaultSize
,wxNO_FULL_REPAINT_ON_RESIZE
) { }
434 void OnPaint(wxPaintEvent
& event
);
436 DECLARE_EVENT_TABLE()
443 DIALOGS_CHOOSE_COLOUR
= wxID_HIGHEST
,
445 DIALOGS_CHOOSE_COLOUR_GENERIC
,
447 DIALOGS_CHOOSE_FONT_GENERIC
,
449 DIALOGS_MESSAGE_DIALOG
,
450 DIALOGS_MESSAGE_BOX_WXINFO
,
451 DIALOGS_SINGLE_CHOICE
,
452 DIALOGS_MULTI_CHOICE
,
455 DIALOGS_PASSWORD_ENTRY
,
460 DIALOGS_FILE_OPEN_GENERIC
,
461 DIALOGS_FILES_OPEN_GENERIC
,
462 DIALOGS_FILE_SAVE_GENERIC
,
464 DIALOGS_DIRNEW_CHOOSE
,
465 DIALOGS_GENERIC_DIR_CHOOSE
,
471 DIALOGS_CENTRE_SCREEN
,
472 DIALOGS_CENTRE_PARENT
,
475 DIALOGS_MODELESS_BTN
,
477 DIALOGS_ABOUTDLG_SIMPLE
,
478 DIALOGS_ABOUTDLG_FANCY
,
479 DIALOGS_ABOUTDLG_FULL
,
480 DIALOGS_ABOUTDLG_CUSTOM
,
488 DIALOGS_PROPERTY_SHEET
,
489 DIALOGS_PROPERTY_SHEET_TOOLBOOK
,
490 DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
,
491 DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
,
492 DIALOGS_TEST_DEFAULT_ACTION