add tests for the remaining message box flags (wxNO_DEFAULT and wxCENTRE)
[wxWidgets.git] / samples / dialogs / dialogs.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dialogs.h
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart
5 // Modified by: ABX (2004) - adjustementd for conditional building
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 /*
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
19 of MSW, MAC and OS2
20 */
21
22 #ifndef __DIALOGSH__
23 #define __DIALOGSH__
24
25 #ifdef __WXUNIVERSAL__
26 #define USE_WXUNIVERSAL 1
27 #else
28 #define USE_WXUNIVERSAL 0
29 #endif
30
31 #ifdef WXUSINGDLL
32 #define USE_DLL 1
33 #else
34 #define USE_DLL 0
35 #endif
36
37 #if defined(__WXWINCE__)
38 #define USE_WXWINCE 1
39 #else
40 #define USE_WXWINCE 0
41 #endif
42
43 #if defined(__WXMSW__) && !USE_WXWINCE
44 #define USE_WXMSW 1
45 #else
46 #define USE_WXMSW 0
47 #endif
48
49 #ifdef __WXMAC__
50 #define USE_WXMAC 1
51 #else
52 #define USE_WXMAC 0
53 #endif
54
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
57 #else
58 #define USE_WXMACFONTDLG 0
59 #endif
60
61 #ifdef __WXGTK__
62 #define USE_WXGTK 1
63 #else
64 #define USE_WXGTK 0
65 #endif
66
67 #ifdef __WXPM__
68 #define USE_WXPM 1
69 #else
70 #define USE_WXPM 0
71 #endif
72
73 #define USE_GENERIC_DIALOGS (!USE_WXUNIVERSAL && !USE_DLL)
74
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)
84
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
89 #else
90 #define USE_MODAL_PRESENTATION 1
91 #endif
92
93
94 // Turn USE_SETTINGS_DIALOG to 0 if supported
95 #if wxUSE_BOOKCTRL
96 #define USE_SETTINGS_DIALOG 1
97 #else
98 #define USE_SETTINGS_DIALOG 0
99 #endif
100
101
102 // Define a new application type
103 class MyApp: public wxApp
104 {
105 public:
106 bool OnInit();
107
108 wxFont m_canvasFont;
109 wxColour m_canvasTextColour;
110 };
111
112 #if USE_MODAL_PRESENTATION
113
114 // A custom modeless dialog
115 class MyModelessDialog : public wxDialog
116 {
117 public:
118 MyModelessDialog(wxWindow *parent);
119
120 void OnButton(wxCommandEvent& event);
121 void OnClose(wxCloseEvent& event);
122
123 private:
124 DECLARE_EVENT_TABLE()
125 };
126
127 // A custom modal dialog
128 class MyModalDialog : public wxDialog
129 {
130 public:
131 MyModalDialog(wxWindow *parent);
132
133 void OnButton(wxCommandEvent& event);
134
135 private:
136 wxButton *m_btnModal,
137 *m_btnModeless,
138 *m_btnDelete;
139
140 DECLARE_EVENT_TABLE()
141 };
142
143 #endif // USE_MODAL_PRESENTATION
144
145 // A class demonstrating CreateStdDialogButtonSizer()
146 class StdButtonSizerDialog : public wxDialog
147 {
148 public:
149 StdButtonSizerDialog(wxWindow *parent);
150
151 void OnEvent(wxCommandEvent& event);
152
153 private:
154 void EnableDisableControls();
155
156 wxCheckBox *m_chkboxAffirmativeButton;
157 wxRadioButton *m_radiobtnOk,
158 *m_radiobtnYes;
159
160 wxCheckBox *m_chkboxDismissButton;
161 wxRadioButton *m_radiobtnClose,
162 *m_radiobtnCancel;
163
164 wxCheckBox *m_chkboxApply,
165 *m_chkboxNo,
166 *m_chkboxHelp,
167 *m_chkboxNoDefault;
168
169 wxSizer *m_buttonsSizer;
170
171 DECLARE_EVENT_TABLE()
172 };
173
174 // Test harness for wxMessageDialog.
175 class TestMessageBoxDialog : public wxDialog
176 {
177 public:
178 TestMessageBoxDialog(wxWindow *parent);
179
180 private:
181 void OnApply(wxCommandEvent& event);
182 void OnClose(wxCommandEvent& event);
183 void OnUpdateLabelUI(wxUpdateUIEvent& event);
184 void OnUpdateNoDefaultUI(wxUpdateUIEvent& event);
185
186 enum
187 {
188 Btn_Yes,
189 Btn_No,
190 Btn_Ok,
191 Btn_Cancel,
192 Btn_Max
193 };
194
195 struct BtnInfo
196 {
197 int flag;
198 wxString name;
199 };
200
201 static BtnInfo ms_btnInfo[Btn_Max];
202
203 wxTextCtrl *m_textMsg,
204 *m_textExtMsg;
205
206 wxCheckBox *m_buttons[Btn_Max];
207 wxTextCtrl *m_labels[Btn_Max];
208
209 wxRadioBox *m_icons;
210
211 wxCheckBox *m_chkNoDefault,
212 *m_chkCentre;
213
214 DECLARE_EVENT_TABLE()
215 DECLARE_NO_COPY_CLASS(TestMessageBoxDialog)
216 };
217
218 class TestDefaultActionDialog: public wxDialog
219 {
220 public:
221 TestDefaultActionDialog( wxWindow *parent );
222
223 void OnListBoxDClick(wxCommandEvent& event);
224 void OnCatchListBoxDClick(wxCommandEvent& event);
225
226 private:
227 bool m_catchListBoxDClick;
228
229 private:
230 DECLARE_EVENT_TABLE()
231 };
232
233
234 #if USE_SETTINGS_DIALOG
235 // Property sheet dialog
236 class SettingsDialog: public wxPropertySheetDialog
237 {
238 DECLARE_CLASS(SettingsDialog)
239 public:
240 SettingsDialog(wxWindow* parent, int dialogType);
241 ~SettingsDialog();
242
243 wxPanel* CreateGeneralSettingsPage(wxWindow* parent);
244 wxPanel* CreateAestheticSettingsPage(wxWindow* parent);
245
246 protected:
247
248 enum {
249 ID_SHOW_TOOLTIPS = 100,
250 ID_AUTO_SAVE,
251 ID_AUTO_SAVE_MINS,
252 ID_LOAD_LAST_PROJECT,
253
254 ID_APPLY_SETTINGS_TO,
255 ID_BACKGROUND_STYLE,
256 ID_FONT_SIZE
257 };
258
259 wxImageList* m_imageList;
260
261 DECLARE_EVENT_TABLE()
262 };
263
264 #endif // USE_SETTINGS_DIALOG
265
266 // Define a new frame type
267 class MyFrame: public wxFrame
268 {
269 public:
270 MyFrame(wxWindow *parent, const wxString& title);
271 virtual ~MyFrame();
272
273 #if wxUSE_MSGDLG
274 void MessageBox(wxCommandEvent& event);
275 void MessageBoxDialog(wxCommandEvent& event);
276 void MessageBoxInfo(wxCommandEvent& event);
277 #endif // wxUSE_MSGDLG
278
279 #if wxUSE_COLOURDLG
280 void ChooseColour(wxCommandEvent& event);
281 void GetColour(wxCommandEvent& event);
282 #endif // wxUSE_COLOURDLG
283
284 #if wxUSE_FONTDLG
285 void ChooseFont(wxCommandEvent& event);
286 #endif // wxUSE_FONTDLG
287
288 #if wxUSE_LOG_DIALOG
289 void LogDialog(wxCommandEvent& event);
290 #endif // wxUSE_LOG_DIALOG
291
292 #if wxUSE_CHOICEDLG
293 void SingleChoice(wxCommandEvent& event);
294 void MultiChoice(wxCommandEvent& event);
295 #endif // wxUSE_CHOICEDLG
296
297 #if wxUSE_TEXTDLG
298 void TextEntry(wxCommandEvent& event);
299 void PasswordEntry(wxCommandEvent& event);
300 #endif // wxUSE_TEXTDLG
301
302 #if wxUSE_NUMBERDLG
303 void NumericEntry(wxCommandEvent& event);
304 #endif // wxUSE_NUMBERDLG
305
306 #if wxUSE_FILEDLG
307 void FileOpen(wxCommandEvent& event);
308 void FileOpen2(wxCommandEvent& event);
309 void FilesOpen(wxCommandEvent& event);
310 void FileSave(wxCommandEvent& event);
311 #endif // wxUSE_FILEDLG
312
313 #if USE_FILEDLG_GENERIC
314 void FileOpenGeneric(wxCommandEvent& event);
315 void FilesOpenGeneric(wxCommandEvent& event);
316 void FileSaveGeneric(wxCommandEvent& event);
317 #endif // USE_FILEDLG_GENERIC
318
319 #if wxUSE_DIRDLG
320 void DirChoose(wxCommandEvent& event);
321 void DirChooseNew(wxCommandEvent& event);
322 #endif // wxUSE_DIRDLG
323
324 #if USE_DIRDLG_GENERIC
325 void GenericDirChoose(wxCommandEvent& event);
326 #endif // USE_DIRDLG_GENERIC
327
328 #if wxUSE_STARTUP_TIPS
329 void ShowTip(wxCommandEvent& event);
330 #endif // wxUSE_STARTUP_TIPS
331
332 #if USE_MODAL_PRESENTATION
333 void ModalDlg(wxCommandEvent& event);
334 #endif // USE_MODAL_PRESENTATION
335 void ModelessDlg(wxCommandEvent& event);
336 void DlgCenteredScreen(wxCommandEvent& event);
337 void DlgCenteredParent(wxCommandEvent& event);
338 void MiniFrame(wxCommandEvent& event);
339 void DlgOnTop(wxCommandEvent& event);
340
341 #if wxUSE_PROGRESSDLG
342 void ShowProgress(wxCommandEvent& event);
343 #endif // wxUSE_PROGRESSDLG
344
345 #if wxUSE_ABOUTDLG
346 void ShowSimpleAboutDialog(wxCommandEvent& event);
347 void ShowFancyAboutDialog(wxCommandEvent& event);
348 void ShowFullAboutDialog(wxCommandEvent& event);
349 void ShowCustomAboutDialog(wxCommandEvent& event);
350 #endif // wxUSE_ABOUTDLG
351
352 #if wxUSE_BUSYINFO
353 void ShowBusyInfo(wxCommandEvent& event);
354 #endif // wxUSE_BUSYINFO
355
356 #if wxUSE_FINDREPLDLG
357 void ShowFindDialog(wxCommandEvent& event);
358 void ShowReplaceDialog(wxCommandEvent& event);
359 void OnFindDialog(wxFindDialogEvent& event);
360 #endif // wxUSE_FINDREPLDLG
361
362 #if USE_COLOURDLG_GENERIC
363 void ChooseColourGeneric(wxCommandEvent& event);
364 #endif // USE_COLOURDLG_GENERIC
365
366 #if USE_FONTDLG_GENERIC
367 void ChooseFontGeneric(wxCommandEvent& event);
368 #endif // USE_FONTDLG_GENERIC
369
370 void OnPropertySheet(wxCommandEvent& event);
371
372 void OnRequestUserAttention(wxCommandEvent& event);
373 #if wxUSE_NOTIFICATION_MESSAGE
374 void OnNotifMsgAuto(wxCommandEvent& event);
375 void OnNotifMsgShow(wxCommandEvent& event);
376 void OnNotifMsgHide(wxCommandEvent& event);
377 #endif // wxUSE_NOTIFICATION_MESSAGE
378
379 void OnStandardButtonsSizerDialog(wxCommandEvent& event);
380
381 void OnTestDefaultActionDialog(wxCommandEvent& event);
382
383 void OnExit(wxCommandEvent& event);
384
385 private:
386 #if wxUSE_DIRDLG
387 void DoDirChoose(int style);
388 #endif // wxUSE_DIRDLG
389
390 #if USE_MODAL_PRESENTATION
391 MyModelessDialog *m_dialog;
392 #endif // USE_MODAL_PRESENTATION
393
394 #if wxUSE_FINDREPLDLG
395 wxFindReplaceData m_findData;
396
397 wxFindReplaceDialog *m_dlgFind,
398 *m_dlgReplace;
399 #endif // wxUSE_FINDREPLDLG
400
401 #if wxUSE_NOTIFICATION_MESSAGE
402 wxNotificationMessage *m_notifMsg;
403 #endif // wxUSE_NOTIFICATION_MESSAGE
404
405 wxColourData m_clrData;
406
407 DECLARE_EVENT_TABLE()
408 };
409
410 class MyCanvas: public wxScrolledWindow
411 {
412 public:
413 MyCanvas(wxWindow *parent) :
414 wxScrolledWindow(parent,wxID_ANY,wxDefaultPosition,wxDefaultSize,wxNO_FULL_REPAINT_ON_RESIZE) { }
415
416 void OnPaint(wxPaintEvent& event);
417
418 DECLARE_EVENT_TABLE()
419 };
420
421
422 // Menu IDs
423 enum
424 {
425 DIALOGS_CHOOSE_COLOUR = wxID_HIGHEST,
426 DIALOGS_GET_COLOUR,
427 DIALOGS_CHOOSE_COLOUR_GENERIC,
428 DIALOGS_CHOOSE_FONT,
429 DIALOGS_CHOOSE_FONT_GENERIC,
430 DIALOGS_MESSAGE_BOX,
431 DIALOGS_MESSAGE_DIALOG,
432 DIALOGS_MESSAGE_BOX_WXINFO,
433 DIALOGS_SINGLE_CHOICE,
434 DIALOGS_MULTI_CHOICE,
435 DIALOGS_TEXT_ENTRY,
436 DIALOGS_PASSWORD_ENTRY,
437 DIALOGS_FILE_OPEN,
438 DIALOGS_FILE_OPEN2,
439 DIALOGS_FILES_OPEN,
440 DIALOGS_FILE_SAVE,
441 DIALOGS_FILE_OPEN_GENERIC,
442 DIALOGS_FILES_OPEN_GENERIC,
443 DIALOGS_FILE_SAVE_GENERIC,
444 DIALOGS_DIR_CHOOSE,
445 DIALOGS_DIRNEW_CHOOSE,
446 DIALOGS_GENERIC_DIR_CHOOSE,
447 DIALOGS_TIP,
448 DIALOGS_NUM_ENTRY,
449 DIALOGS_LOG_DIALOG,
450 DIALOGS_MODAL,
451 DIALOGS_MODELESS,
452 DIALOGS_CENTRE_SCREEN,
453 DIALOGS_CENTRE_PARENT,
454 DIALOGS_MINIFRAME,
455 DIALOGS_ONTOP,
456 DIALOGS_MODELESS_BTN,
457 DIALOGS_PROGRESS,
458 DIALOGS_ABOUTDLG_SIMPLE,
459 DIALOGS_ABOUTDLG_FANCY,
460 DIALOGS_ABOUTDLG_FULL,
461 DIALOGS_ABOUTDLG_CUSTOM,
462 DIALOGS_BUSYINFO,
463 DIALOGS_FIND,
464 DIALOGS_REPLACE,
465 DIALOGS_REQUEST,
466 DIALOGS_NOTIFY_AUTO,
467 DIALOGS_NOTIFY_SHOW,
468 DIALOGS_NOTIFY_HIDE,
469 DIALOGS_PROPERTY_SHEET,
470 DIALOGS_PROPERTY_SHEET_TOOLBOOK,
471 DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK,
472 DIALOGS_STANDARD_BUTTON_SIZER_DIALOG,
473 DIALOGS_TEST_DEFAULT_ACTION
474 };
475
476 #endif
477