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