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