]> git.saurik.com Git - wxWidgets.git/blob - samples/dialogs/dialogs.h
Rebaked using post-0.2.7 svn version of bakefile.
[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 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 private:
195 void OnApply(wxCommandEvent& event);
196 void OnClose(wxCommandEvent& event);
197 void OnUpdateLabelUI(wxUpdateUIEvent& event);
198 void OnUpdateNoDefaultUI(wxUpdateUIEvent& event);
199
200 enum
201 {
202 Btn_Yes,
203 Btn_No,
204 Btn_Ok,
205 Btn_Cancel,
206 Btn_Max
207 };
208
209 struct BtnInfo
210 {
211 int flag;
212 const char *name;
213 };
214
215 static const BtnInfo ms_btnInfo[Btn_Max];
216
217 wxTextCtrl *m_textMsg,
218 *m_textExtMsg;
219
220 wxCheckBox *m_buttons[Btn_Max];
221 wxTextCtrl *m_labels[Btn_Max];
222
223 wxRadioBox *m_icons;
224
225 wxCheckBox *m_chkNoDefault,
226 *m_chkCentre;
227
228 DECLARE_EVENT_TABLE()
229 wxDECLARE_NO_COPY_CLASS(TestMessageBoxDialog);
230 };
231
232 class TestDefaultActionDialog: public wxDialog
233 {
234 public:
235 TestDefaultActionDialog( wxWindow *parent );
236
237 void OnListBoxDClick(wxCommandEvent& event);
238 void OnCatchListBoxDClick(wxCommandEvent& event);
239
240 private:
241 bool m_catchListBoxDClick;
242
243 private:
244 DECLARE_EVENT_TABLE()
245 };
246
247
248 #if USE_SETTINGS_DIALOG
249 // Property sheet dialog
250 class SettingsDialog: public wxPropertySheetDialog
251 {
252 DECLARE_CLASS(SettingsDialog)
253 public:
254 SettingsDialog(wxWindow* parent, int dialogType);
255 ~SettingsDialog();
256
257 wxPanel* CreateGeneralSettingsPage(wxWindow* parent);
258 wxPanel* CreateAestheticSettingsPage(wxWindow* parent);
259
260 protected:
261
262 enum {
263 ID_SHOW_TOOLTIPS = 100,
264 ID_AUTO_SAVE,
265 ID_AUTO_SAVE_MINS,
266 ID_LOAD_LAST_PROJECT,
267
268 ID_APPLY_SETTINGS_TO,
269 ID_BACKGROUND_STYLE,
270 ID_FONT_SIZE
271 };
272
273 wxImageList* m_imageList;
274
275 DECLARE_EVENT_TABLE()
276 };
277
278 #endif // USE_SETTINGS_DIALOG
279
280 // Define a new frame type
281 class MyFrame: public wxFrame
282 {
283 public:
284 MyFrame(const wxString& title);
285 virtual ~MyFrame();
286
287 #if wxUSE_MSGDLG
288 void MessageBox(wxCommandEvent& event);
289 void MessageBoxDialog(wxCommandEvent& event);
290 void MessageBoxInfo(wxCommandEvent& event);
291 #endif // wxUSE_MSGDLG
292
293 #if wxUSE_COLOURDLG
294 void ChooseColour(wxCommandEvent& event);
295 void GetColour(wxCommandEvent& event);
296 #endif // wxUSE_COLOURDLG
297
298 #if wxUSE_FONTDLG
299 void ChooseFont(wxCommandEvent& event);
300 #endif // wxUSE_FONTDLG
301
302 #if wxUSE_LOG_DIALOG
303 void LogDialog(wxCommandEvent& event);
304 #endif // wxUSE_LOG_DIALOG
305
306 #if wxUSE_INFOBAR
307 void InfoBarSimple(wxCommandEvent& event);
308 void InfoBarAdvanced(wxCommandEvent& event);
309 #endif // wxUSE_INFOBAR
310
311 #if wxUSE_CHOICEDLG
312 void SingleChoice(wxCommandEvent& event);
313 void MultiChoice(wxCommandEvent& event);
314 #endif // wxUSE_CHOICEDLG
315
316 void Rearrange(wxCommandEvent& event);
317
318 #if wxUSE_TEXTDLG
319 void TextEntry(wxCommandEvent& event);
320 void PasswordEntry(wxCommandEvent& event);
321 #endif // wxUSE_TEXTDLG
322
323 #if wxUSE_NUMBERDLG
324 void NumericEntry(wxCommandEvent& event);
325 #endif // wxUSE_NUMBERDLG
326
327 #if wxUSE_FILEDLG
328 void FileOpen(wxCommandEvent& event);
329 void FileOpen2(wxCommandEvent& event);
330 void FilesOpen(wxCommandEvent& event);
331 void FileSave(wxCommandEvent& event);
332 #endif // wxUSE_FILEDLG
333
334 #if USE_FILEDLG_GENERIC
335 void FileOpenGeneric(wxCommandEvent& event);
336 void FilesOpenGeneric(wxCommandEvent& event);
337 void FileSaveGeneric(wxCommandEvent& event);
338 #endif // USE_FILEDLG_GENERIC
339
340 #if wxUSE_DIRDLG
341 void DirChoose(wxCommandEvent& event);
342 void DirChooseNew(wxCommandEvent& event);
343 #endif // wxUSE_DIRDLG
344
345 #if USE_DIRDLG_GENERIC
346 void GenericDirChoose(wxCommandEvent& event);
347 #endif // USE_DIRDLG_GENERIC
348
349 #if wxUSE_STARTUP_TIPS
350 void ShowTip(wxCommandEvent& event);
351 #endif // wxUSE_STARTUP_TIPS
352
353 #if USE_MODAL_PRESENTATION
354 void ModalDlg(wxCommandEvent& event);
355 #endif // USE_MODAL_PRESENTATION
356 void ModelessDlg(wxCommandEvent& event);
357 void DlgCenteredScreen(wxCommandEvent& event);
358 void DlgCenteredParent(wxCommandEvent& event);
359 void MiniFrame(wxCommandEvent& event);
360 void DlgOnTop(wxCommandEvent& event);
361
362 #if wxUSE_PROGRESSDLG
363 void ShowProgress(wxCommandEvent& event);
364 #endif // wxUSE_PROGRESSDLG
365
366 #if wxUSE_ABOUTDLG
367 void ShowSimpleAboutDialog(wxCommandEvent& event);
368 void ShowFancyAboutDialog(wxCommandEvent& event);
369 void ShowFullAboutDialog(wxCommandEvent& event);
370 void ShowCustomAboutDialog(wxCommandEvent& event);
371 #endif // wxUSE_ABOUTDLG
372
373 #if wxUSE_BUSYINFO
374 void ShowBusyInfo(wxCommandEvent& event);
375 #endif // wxUSE_BUSYINFO
376
377 #if wxUSE_FINDREPLDLG
378 void ShowFindDialog(wxCommandEvent& event);
379 void ShowReplaceDialog(wxCommandEvent& event);
380 void OnFindDialog(wxFindDialogEvent& event);
381 #endif // wxUSE_FINDREPLDLG
382
383 #if USE_COLOURDLG_GENERIC
384 void ChooseColourGeneric(wxCommandEvent& event);
385 #endif // USE_COLOURDLG_GENERIC
386
387 #if USE_FONTDLG_GENERIC
388 void ChooseFontGeneric(wxCommandEvent& event);
389 #endif // USE_FONTDLG_GENERIC
390
391 void OnPropertySheet(wxCommandEvent& event);
392
393 void OnRequestUserAttention(wxCommandEvent& event);
394 #if wxUSE_NOTIFICATION_MESSAGE
395 void OnNotifMsgAuto(wxCommandEvent& event);
396 void OnNotifMsgShow(wxCommandEvent& event);
397 void OnNotifMsgHide(wxCommandEvent& event);
398 #endif // wxUSE_NOTIFICATION_MESSAGE
399
400 void OnStandardButtonsSizerDialog(wxCommandEvent& event);
401
402 void OnTestDefaultActionDialog(wxCommandEvent& event);
403
404 void OnExit(wxCommandEvent& event);
405
406 private:
407 #if wxUSE_DIRDLG
408 void DoDirChoose(int style);
409 #endif // wxUSE_DIRDLG
410
411 #if USE_MODAL_PRESENTATION
412 MyModelessDialog *m_dialog;
413 #endif // USE_MODAL_PRESENTATION
414
415 #if wxUSE_FINDREPLDLG
416 wxFindReplaceData m_findData;
417
418 wxFindReplaceDialog *m_dlgFind,
419 *m_dlgReplace;
420 #endif // wxUSE_FINDREPLDLG
421
422 #if wxUSE_NOTIFICATION_MESSAGE
423 wxNotificationMessage *m_notifMsg;
424 #endif // wxUSE_NOTIFICATION_MESSAGE
425
426 wxColourData m_clrData;
427
428 // just a window which we use to show the effect of font/colours selection
429 wxWindow *m_canvas;
430
431 #if wxUSE_INFOBAR
432 void OnInfoBarRedo(wxCommandEvent& event);
433
434 wxInfoBar *m_infoBarSimple,
435 *m_infoBarAdvanced;
436 #endif // wxUSE_INFOBAR
437
438 DECLARE_EVENT_TABLE()
439 };
440
441 class MyCanvas: public wxScrolledWindow
442 {
443 public:
444 MyCanvas(wxWindow *parent) : wxScrolledWindow(parent, wxID_ANY)
445 {
446 SetForegroundColour(*wxBLACK);
447 SetBackgroundColour(*wxWHITE);
448 SetFont(*wxNORMAL_FONT);
449 }
450
451 private:
452 void OnPaint(wxPaintEvent& event);
453
454 DECLARE_EVENT_TABLE()
455 };
456
457
458 // Menu IDs
459 enum
460 {
461 DIALOGS_CHOOSE_COLOUR = wxID_HIGHEST,
462 DIALOGS_GET_COLOUR,
463 DIALOGS_CHOOSE_COLOUR_GENERIC,
464 DIALOGS_CHOOSE_FONT,
465 DIALOGS_CHOOSE_FONT_GENERIC,
466 DIALOGS_MESSAGE_BOX,
467 DIALOGS_MESSAGE_DIALOG,
468 DIALOGS_MESSAGE_BOX_WXINFO,
469 DIALOGS_SINGLE_CHOICE,
470 DIALOGS_MULTI_CHOICE,
471 DIALOGS_REARRANGE,
472 DIALOGS_TEXT_ENTRY,
473 DIALOGS_PASSWORD_ENTRY,
474 DIALOGS_FILE_OPEN,
475 DIALOGS_FILE_OPEN2,
476 DIALOGS_FILES_OPEN,
477 DIALOGS_FILE_SAVE,
478 DIALOGS_FILE_OPEN_GENERIC,
479 DIALOGS_FILES_OPEN_GENERIC,
480 DIALOGS_FILE_SAVE_GENERIC,
481 DIALOGS_DIR_CHOOSE,
482 DIALOGS_DIRNEW_CHOOSE,
483 DIALOGS_GENERIC_DIR_CHOOSE,
484 DIALOGS_TIP,
485 DIALOGS_NUM_ENTRY,
486 DIALOGS_LOG_DIALOG,
487 DIALOGS_INFOBAR_SIMPLE,
488 DIALOGS_INFOBAR_ADVANCED,
489 DIALOGS_MODAL,
490 DIALOGS_MODELESS,
491 DIALOGS_CENTRE_SCREEN,
492 DIALOGS_CENTRE_PARENT,
493 DIALOGS_MINIFRAME,
494 DIALOGS_ONTOP,
495 DIALOGS_MODELESS_BTN,
496 DIALOGS_PROGRESS,
497 DIALOGS_ABOUTDLG_SIMPLE,
498 DIALOGS_ABOUTDLG_FANCY,
499 DIALOGS_ABOUTDLG_FULL,
500 DIALOGS_ABOUTDLG_CUSTOM,
501 DIALOGS_BUSYINFO,
502 DIALOGS_FIND,
503 DIALOGS_REPLACE,
504 DIALOGS_REQUEST,
505 DIALOGS_NOTIFY_AUTO,
506 DIALOGS_NOTIFY_SHOW,
507 DIALOGS_NOTIFY_HIDE,
508 DIALOGS_PROPERTY_SHEET,
509 DIALOGS_PROPERTY_SHEET_TOOLBOOK,
510 DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK,
511 DIALOGS_STANDARD_BUTTON_SIZER_DIALOG,
512 DIALOGS_TEST_DEFAULT_ACTION
513 };
514
515 #endif
516