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