]> git.saurik.com Git - wxWidgets.git/blob - samples/dialogs/dialogs.h
Fix crash in wxMSW wxProgressDialog without wxPD_APP_MODAL style.
[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 licence
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 protected:
121 #if wxUSE_LOG
122 virtual wxAppTraits *CreateTraits() { return new MyAppTraits; }
123 #endif // wxUSE_LOG
124 };
125
126 #if USE_MODAL_PRESENTATION
127
128 // A custom modeless dialog
129 class MyModelessDialog : public wxDialog
130 {
131 public:
132 MyModelessDialog(wxWindow *parent);
133
134 void OnButton(wxCommandEvent& event);
135 void OnClose(wxCloseEvent& event);
136
137 private:
138 DECLARE_EVENT_TABLE()
139 };
140
141 // A custom modal dialog
142 class MyModalDialog : public wxDialog
143 {
144 public:
145 MyModalDialog(wxWindow *parent);
146
147 void OnButton(wxCommandEvent& event);
148
149 private:
150 wxButton *m_btnModal,
151 *m_btnModeless,
152 *m_btnDelete;
153
154 DECLARE_EVENT_TABLE()
155 };
156
157 #endif // USE_MODAL_PRESENTATION
158
159 // A class demonstrating CreateStdDialogButtonSizer()
160 class StdButtonSizerDialog : public wxDialog
161 {
162 public:
163 StdButtonSizerDialog(wxWindow *parent);
164
165 void OnEvent(wxCommandEvent& event);
166
167 private:
168 void EnableDisableControls();
169
170 wxCheckBox *m_chkboxAffirmativeButton;
171 wxRadioButton *m_radiobtnOk,
172 *m_radiobtnYes;
173
174 wxCheckBox *m_chkboxDismissButton;
175 wxRadioButton *m_radiobtnClose,
176 *m_radiobtnCancel;
177
178 wxCheckBox *m_chkboxApply,
179 *m_chkboxNo,
180 *m_chkboxHelp,
181 *m_chkboxNoDefault;
182
183 wxSizer *m_buttonsSizer;
184
185 DECLARE_EVENT_TABLE()
186 };
187
188 // Test harness for wxMessageDialog.
189 class TestMessageBoxDialog : public wxDialog
190 {
191 public:
192 TestMessageBoxDialog(wxWindow *parent);
193
194 bool Create();
195
196 protected:
197 wxString GetMessage() { return m_textMsg->GetValue(); }
198 long GetStyle();
199
200 void PrepareMessageDialog(wxMessageDialogBase &dlg);
201
202 virtual void AddAdditionalTextOptions(wxSizer *WXUNUSED(sizer)) { }
203 virtual void AddAdditionalFlags(wxSizer *WXUNUSED(sizer)) { }
204
205 void OnApply(wxCommandEvent& event);
206 void OnClose(wxCommandEvent& event);
207 void OnUpdateLabelUI(wxUpdateUIEvent& event);
208 void OnUpdateNoDefaultUI(wxUpdateUIEvent& event);
209
210 private:
211 enum
212 {
213 Btn_Yes,
214 Btn_No,
215 Btn_Ok,
216 Btn_Cancel,
217 Btn_Max
218 };
219
220 struct BtnInfo
221 {
222 int flag;
223 const char *name;
224 };
225
226 static const BtnInfo ms_btnInfo[Btn_Max];
227
228 enum
229 {
230 MsgDlgIcon_No,
231 MsgDlgIcon_None,
232 MsgDlgIcon_Info,
233 MsgDlgIcon_Question,
234 MsgDlgIcon_Warning,
235 MsgDlgIcon_Error,
236 MsgDlgIcon_Max
237 };
238
239 wxTextCtrl *m_textMsg,
240 *m_textExtMsg;
241
242 wxCheckBox *m_buttons[Btn_Max];
243 wxTextCtrl *m_labels[Btn_Max];
244
245 wxRadioBox *m_icons;
246
247 wxCheckBox *m_chkNoDefault,
248 *m_chkCentre;
249
250 DECLARE_EVENT_TABLE()
251 wxDECLARE_NO_COPY_CLASS(TestMessageBoxDialog);
252 };
253
254 #if wxUSE_RICHMSGDLG
255 class TestRichMessageDialog : public TestMessageBoxDialog
256 {
257 public:
258 TestRichMessageDialog(wxWindow *parent);
259
260 protected:
261 // overrides method in base class
262 virtual void AddAdditionalTextOptions(wxSizer *sizer);
263 virtual void AddAdditionalFlags(wxSizer *sizer);
264
265 void OnApply(wxCommandEvent& event);
266
267 private:
268 wxTextCtrl *m_textCheckBox;
269 wxCheckBox *m_initialValueCheckBox;
270 wxTextCtrl *m_textDetailed;
271
272 DECLARE_EVENT_TABLE()
273 };
274 #endif // wxUSE_RICHMSGDLG
275
276 class TestDefaultActionDialog: public wxDialog
277 {
278 public:
279 TestDefaultActionDialog( wxWindow *parent );
280
281 void OnListBoxDClick(wxCommandEvent& event);
282 void OnCatchListBoxDClick(wxCommandEvent& event);
283
284 private:
285 bool m_catchListBoxDClick;
286
287 private:
288 DECLARE_EVENT_TABLE()
289 };
290
291
292 #if USE_SETTINGS_DIALOG
293 // Property sheet dialog
294 class SettingsDialog: public wxPropertySheetDialog
295 {
296 DECLARE_CLASS(SettingsDialog)
297 public:
298 SettingsDialog(wxWindow* parent, int dialogType);
299 ~SettingsDialog();
300
301 wxPanel* CreateGeneralSettingsPage(wxWindow* parent);
302 wxPanel* CreateAestheticSettingsPage(wxWindow* parent);
303
304 protected:
305
306 enum {
307 ID_SHOW_TOOLTIPS = 100,
308 ID_AUTO_SAVE,
309 ID_AUTO_SAVE_MINS,
310 ID_LOAD_LAST_PROJECT,
311
312 ID_APPLY_SETTINGS_TO,
313 ID_BACKGROUND_STYLE,
314 ID_FONT_SIZE
315 };
316
317 wxImageList* m_imageList;
318
319 DECLARE_EVENT_TABLE()
320 };
321
322 #endif // USE_SETTINGS_DIALOG
323
324 // Define a new frame type
325 class MyFrame: public wxFrame
326 {
327 public:
328 MyFrame(const wxString& title);
329 virtual ~MyFrame();
330
331 #if wxUSE_MSGDLG
332 void MessageBox(wxCommandEvent& event);
333 void MessageBoxDialog(wxCommandEvent& event);
334 void MessageBoxInfo(wxCommandEvent& event);
335 void MessageBoxWindowModal(wxCommandEvent& event);
336 void MessageBoxWindowModalClosed(wxWindowModalDialogEvent& event);
337 #endif // wxUSE_MSGDLG
338 #if wxUSE_RICHMSGDLG
339 void RichMessageDialog(wxCommandEvent& event);
340 #endif // wxUSE_RICHMSGDLG
341
342 #if wxUSE_COLOURDLG
343 void ChooseColour(wxCommandEvent& event);
344 void GetColour(wxCommandEvent& event);
345 #endif // wxUSE_COLOURDLG
346
347 #if wxUSE_FONTDLG
348 void ChooseFont(wxCommandEvent& event);
349 #endif // wxUSE_FONTDLG
350
351 #if wxUSE_LOG_DIALOG
352 void LogDialog(wxCommandEvent& event);
353 #endif // wxUSE_LOG_DIALOG
354
355 #if wxUSE_INFOBAR
356 void InfoBarSimple(wxCommandEvent& event);
357 void InfoBarAdvanced(wxCommandEvent& event);
358 #endif // wxUSE_INFOBAR
359
360 #if wxUSE_CHOICEDLG
361 void SingleChoice(wxCommandEvent& event);
362 void MultiChoice(wxCommandEvent& event);
363 #endif // wxUSE_CHOICEDLG
364
365 void Rearrange(wxCommandEvent& event);
366
367 #if wxUSE_TEXTDLG
368 void TextEntry(wxCommandEvent& event);
369 void PasswordEntry(wxCommandEvent& event);
370 #endif // wxUSE_TEXTDLG
371
372 #if wxUSE_NUMBERDLG
373 void NumericEntry(wxCommandEvent& event);
374 #endif // wxUSE_NUMBERDLG
375
376 #if wxUSE_FILEDLG
377 void FileOpen(wxCommandEvent& event);
378 void FileOpen2(wxCommandEvent& event);
379 void FilesOpen(wxCommandEvent& event);
380 void FileSave(wxCommandEvent& event);
381 #endif // wxUSE_FILEDLG
382
383 #if USE_FILEDLG_GENERIC
384 void FileOpenGeneric(wxCommandEvent& event);
385 void FilesOpenGeneric(wxCommandEvent& event);
386 void FileSaveGeneric(wxCommandEvent& event);
387 #endif // USE_FILEDLG_GENERIC
388
389 #if wxUSE_DIRDLG
390 void DirChoose(wxCommandEvent& event);
391 void DirChooseNew(wxCommandEvent& event);
392 #endif // wxUSE_DIRDLG
393
394 #if USE_DIRDLG_GENERIC
395 void GenericDirChoose(wxCommandEvent& event);
396 #endif // USE_DIRDLG_GENERIC
397
398 #if wxUSE_STARTUP_TIPS
399 void ShowTip(wxCommandEvent& event);
400 #endif // wxUSE_STARTUP_TIPS
401
402 #if USE_MODAL_PRESENTATION
403 void ModalDlg(wxCommandEvent& event);
404 #endif // USE_MODAL_PRESENTATION
405 void ModelessDlg(wxCommandEvent& event);
406 void DlgCenteredScreen(wxCommandEvent& event);
407 void DlgCenteredParent(wxCommandEvent& event);
408 void MiniFrame(wxCommandEvent& event);
409 void DlgOnTop(wxCommandEvent& event);
410
411 #if wxUSE_PROGRESSDLG
412 void ShowProgress(wxCommandEvent& event);
413 #endif // wxUSE_PROGRESSDLG
414
415 #if wxUSE_ABOUTDLG
416 void ShowSimpleAboutDialog(wxCommandEvent& event);
417 void ShowFancyAboutDialog(wxCommandEvent& event);
418 void ShowFullAboutDialog(wxCommandEvent& event);
419 void ShowCustomAboutDialog(wxCommandEvent& event);
420 #endif // wxUSE_ABOUTDLG
421
422 #if wxUSE_BUSYINFO
423 void ShowBusyInfo(wxCommandEvent& event);
424 #endif // wxUSE_BUSYINFO
425
426 #if wxUSE_FINDREPLDLG
427 void ShowFindDialog(wxCommandEvent& event);
428 void ShowReplaceDialog(wxCommandEvent& event);
429 void OnFindDialog(wxFindDialogEvent& event);
430 #endif // wxUSE_FINDREPLDLG
431
432 #if USE_COLOURDLG_GENERIC
433 void ChooseColourGeneric(wxCommandEvent& event);
434 #endif // USE_COLOURDLG_GENERIC
435
436 #if USE_FONTDLG_GENERIC
437 void ChooseFontGeneric(wxCommandEvent& event);
438 #endif // USE_FONTDLG_GENERIC
439
440 void OnPropertySheet(wxCommandEvent& event);
441
442 void OnRequestUserAttention(wxCommandEvent& event);
443 #if wxUSE_NOTIFICATION_MESSAGE
444 void OnNotifMsgAuto(wxCommandEvent& event);
445 void OnNotifMsgShow(wxCommandEvent& event);
446 void OnNotifMsgHide(wxCommandEvent& event);
447 #endif // wxUSE_NOTIFICATION_MESSAGE
448
449 void OnStandardButtonsSizerDialog(wxCommandEvent& event);
450
451 void OnTestDefaultActionDialog(wxCommandEvent& event);
452
453 void OnExit(wxCommandEvent& event);
454
455 private:
456 #if wxUSE_DIRDLG
457 void DoDirChoose(int style);
458 #endif // wxUSE_DIRDLG
459
460 #if USE_MODAL_PRESENTATION
461 MyModelessDialog *m_dialog;
462 #endif // USE_MODAL_PRESENTATION
463
464 #if wxUSE_FINDREPLDLG
465 wxFindReplaceData m_findData;
466
467 wxFindReplaceDialog *m_dlgFind,
468 *m_dlgReplace;
469 #endif // wxUSE_FINDREPLDLG
470
471 #if wxUSE_NOTIFICATION_MESSAGE
472 wxNotificationMessage *m_notifMsg;
473 #endif // wxUSE_NOTIFICATION_MESSAGE
474
475 wxColourData m_clrData;
476
477 // just a window which we use to show the effect of font/colours selection
478 wxWindow *m_canvas;
479
480 #if wxUSE_INFOBAR
481 void OnInfoBarRedo(wxCommandEvent& event);
482
483 wxInfoBar *m_infoBarSimple,
484 *m_infoBarAdvanced;
485 #endif // wxUSE_INFOBAR
486
487 DECLARE_EVENT_TABLE()
488 };
489
490 class MyCanvas: public wxScrolledWindow
491 {
492 public:
493 MyCanvas(wxWindow *parent) : wxScrolledWindow(parent, wxID_ANY)
494 {
495 SetForegroundColour(*wxBLACK);
496 SetBackgroundColour(*wxWHITE);
497 SetFont(*wxNORMAL_FONT);
498 }
499
500 private:
501 void OnPaint(wxPaintEvent& event);
502
503 DECLARE_EVENT_TABLE()
504 };
505
506
507 // Menu IDs
508 enum
509 {
510 DIALOGS_CHOOSE_COLOUR = wxID_HIGHEST,
511 DIALOGS_GET_COLOUR,
512 DIALOGS_CHOOSE_COLOUR_GENERIC,
513 DIALOGS_CHOOSE_FONT,
514 DIALOGS_CHOOSE_FONT_GENERIC,
515 DIALOGS_MESSAGE_BOX,
516 DIALOGS_MESSAGE_BOX_WINDOW_MODAL,
517 DIALOGS_MESSAGE_DIALOG,
518 DIALOGS_MESSAGE_BOX_WXINFO,
519 DIALOGS_RICH_MESSAGE_DIALOG,
520 DIALOGS_SINGLE_CHOICE,
521 DIALOGS_MULTI_CHOICE,
522 DIALOGS_REARRANGE,
523 DIALOGS_TEXT_ENTRY,
524 DIALOGS_PASSWORD_ENTRY,
525 DIALOGS_FILE_OPEN,
526 DIALOGS_FILE_OPEN2,
527 DIALOGS_FILES_OPEN,
528 DIALOGS_FILE_SAVE,
529 DIALOGS_FILE_OPEN_GENERIC,
530 DIALOGS_FILES_OPEN_GENERIC,
531 DIALOGS_FILE_SAVE_GENERIC,
532 DIALOGS_DIR_CHOOSE,
533 DIALOGS_DIRNEW_CHOOSE,
534 DIALOGS_GENERIC_DIR_CHOOSE,
535 DIALOGS_TIP,
536 DIALOGS_NUM_ENTRY,
537 DIALOGS_LOG_DIALOG,
538 DIALOGS_INFOBAR_SIMPLE,
539 DIALOGS_INFOBAR_ADVANCED,
540 DIALOGS_MODAL,
541 DIALOGS_MODELESS,
542 DIALOGS_CENTRE_SCREEN,
543 DIALOGS_CENTRE_PARENT,
544 DIALOGS_MINIFRAME,
545 DIALOGS_ONTOP,
546 DIALOGS_MODELESS_BTN,
547 DIALOGS_PROGRESS,
548 DIALOGS_ABOUTDLG_SIMPLE,
549 DIALOGS_ABOUTDLG_FANCY,
550 DIALOGS_ABOUTDLG_FULL,
551 DIALOGS_ABOUTDLG_CUSTOM,
552 DIALOGS_BUSYINFO,
553 DIALOGS_FIND,
554 DIALOGS_REPLACE,
555 DIALOGS_REQUEST,
556 DIALOGS_NOTIFY_AUTO,
557 DIALOGS_NOTIFY_SHOW,
558 DIALOGS_NOTIFY_HIDE,
559 DIALOGS_PROPERTY_SHEET,
560 DIALOGS_PROPERTY_SHEET_TOOLBOOK,
561 DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK,
562 DIALOGS_STANDARD_BUTTON_SIZER_DIALOG,
563 DIALOGS_TEST_DEFAULT_ACTION
564 };
565
566 #endif
567