dialogs.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: dialogs.h
  3. // Purpose: Common dialogs demo
  4. // Author: Julian Smart, Vadim Zeitlin, ABX
  5. // Created: 04/01/98
  6. // Copyright: (c) Julian Smart
  7. // (c) 2004 ABX
  8. // (c) Vadim Zeitlin
  9. // Licence: wxWindows licence
  10. /////////////////////////////////////////////////////////////////////////////
  11. /*
  12. This sample shows how to use the common dialogs available from wxWidgets.
  13. It also shows that generic implementations of common dialogs can be exchanged
  14. with native dialogs and can coexist in one application. The need for generic
  15. dialogs addition is recognized thanks to setup of below USE_*** setting. Their
  16. combinations reflects conditions of makefiles and project files to avoid unresolved
  17. references during linking. For now some generic dialogs are added in static builds
  18. of MSW, MAC and OS2
  19. */
  20. #ifndef __DIALOGSH__
  21. #define __DIALOGSH__
  22. #ifdef __WXUNIVERSAL__
  23. #define USE_WXUNIVERSAL 1
  24. #else
  25. #define USE_WXUNIVERSAL 0
  26. #endif
  27. #ifdef WXUSINGDLL
  28. #define USE_DLL 1
  29. #else
  30. #define USE_DLL 0
  31. #endif
  32. #if defined(__WXWINCE__)
  33. #define USE_WXWINCE 1
  34. #else
  35. #define USE_WXWINCE 0
  36. #endif
  37. #if defined(__WXMSW__) && !USE_WXWINCE
  38. #define USE_WXMSW 1
  39. #else
  40. #define USE_WXMSW 0
  41. #endif
  42. #ifdef __WXMAC__
  43. #define USE_WXMAC 1
  44. #else
  45. #define USE_WXMAC 0
  46. #endif
  47. #if USE_NATIVE_FONT_DIALOG_FOR_MACOSX
  48. #define USE_WXMACFONTDLG 1
  49. #else
  50. #define USE_WXMACFONTDLG 0
  51. #endif
  52. #ifdef __WXGTK__
  53. #define USE_WXGTK 1
  54. #else
  55. #define USE_WXGTK 0
  56. #endif
  57. #ifdef __WXPM__
  58. #define USE_WXPM 1
  59. #else
  60. #define USE_WXPM 0
  61. #endif
  62. #define USE_GENERIC_DIALOGS (!USE_WXUNIVERSAL && !USE_DLL)
  63. #define USE_COLOURDLG_GENERIC \
  64. ((USE_WXMSW || USE_WXMAC) && USE_GENERIC_DIALOGS && wxUSE_COLOURDLG)
  65. #define USE_DIRDLG_GENERIC \
  66. ((USE_WXMSW || USE_WXMAC) && USE_GENERIC_DIALOGS && wxUSE_DIRDLG)
  67. #define USE_FILEDLG_GENERIC \
  68. ((((USE_WXMSW || USE_WXMAC || USE_WXPM || USE_WXGTK) \
  69. && USE_GENERIC_DIALOGS) || USE_WXWINCE) && wxUSE_FILEDLG)
  70. #define USE_FONTDLG_GENERIC \
  71. ((USE_WXMSW || USE_WXMACFONTDLG || USE_WXPM) && USE_GENERIC_DIALOGS && wxUSE_FONTDLG)
  72. // Turn USE_MODAL_PRESENTATION to 0 if there is any reason for not presenting difference
  73. // between modal and modeless dialogs (ie. not implemented it in your port yet)
  74. #if defined(__SMARTPHONE__) || !wxUSE_BOOKCTRL
  75. #define USE_MODAL_PRESENTATION 0
  76. #else
  77. #define USE_MODAL_PRESENTATION 1
  78. #endif
  79. // Turn USE_SETTINGS_DIALOG to 0 if supported
  80. #if wxUSE_BOOKCTRL
  81. #define USE_SETTINGS_DIALOG 1
  82. #else
  83. #define USE_SETTINGS_DIALOG 0
  84. #endif
  85. #if wxUSE_LOG
  86. // Custom application traits class which we use to override the default log
  87. // target creation
  88. class MyAppTraits : public wxGUIAppTraits
  89. {
  90. public:
  91. virtual wxLog *CreateLogTarget();
  92. };
  93. #endif // wxUSE_LOG
  94. // Define a new application type
  95. class MyApp: public wxApp
  96. {
  97. public:
  98. MyApp() { m_startupProgressStyle = -1; }
  99. virtual bool OnInit();
  100. #if wxUSE_CMDLINE_PARSER
  101. virtual void OnInitCmdLine(wxCmdLineParser& parser);
  102. virtual bool OnCmdLineParsed(wxCmdLineParser& parser);
  103. #endif // wxUSE_CMDLINE_PARSER
  104. protected:
  105. #if wxUSE_LOG
  106. virtual wxAppTraits *CreateTraits() { return new MyAppTraits; }
  107. #endif // wxUSE_LOG
  108. private:
  109. // Flag set to a valid value if command line option "progress" is used,
  110. // this allows testing of wxProgressDialog before the main event loop is
  111. // started. If this option is not specified it is set to -1 by default
  112. // meaning that progress dialog shouldn't be shown at all.
  113. long m_startupProgressStyle;
  114. };
  115. #if USE_MODAL_PRESENTATION
  116. // A custom modeless dialog
  117. class MyModelessDialog : public wxDialog
  118. {
  119. public:
  120. MyModelessDialog(wxWindow *parent);
  121. void OnButton(wxCommandEvent& event);
  122. void OnClose(wxCloseEvent& event);
  123. private:
  124. wxDECLARE_EVENT_TABLE();
  125. };
  126. // A custom modal dialog
  127. class MyModalDialog : public wxDialog
  128. {
  129. public:
  130. MyModalDialog(wxWindow *parent);
  131. void OnButton(wxCommandEvent& event);
  132. private:
  133. wxButton *m_btnModal,
  134. *m_btnModeless,
  135. *m_btnDelete;
  136. wxDECLARE_EVENT_TABLE();
  137. };
  138. #endif // USE_MODAL_PRESENTATION
  139. // A class demonstrating CreateStdDialogButtonSizer()
  140. class StdButtonSizerDialog : public wxDialog
  141. {
  142. public:
  143. StdButtonSizerDialog(wxWindow *parent);
  144. void OnEvent(wxCommandEvent& event);
  145. private:
  146. void EnableDisableControls();
  147. wxCheckBox *m_chkboxAffirmativeButton;
  148. wxRadioButton *m_radiobtnOk,
  149. *m_radiobtnYes;
  150. wxCheckBox *m_chkboxDismissButton;
  151. wxRadioButton *m_radiobtnClose,
  152. *m_radiobtnCancel;
  153. wxCheckBox *m_chkboxApply,
  154. *m_chkboxNo,
  155. *m_chkboxHelp,
  156. *m_chkboxNoDefault;
  157. wxSizer *m_buttonsSizer;
  158. wxDECLARE_EVENT_TABLE();
  159. };
  160. // Test harness for wxMessageDialog.
  161. class TestMessageBoxDialog : public wxDialog
  162. {
  163. public:
  164. TestMessageBoxDialog(wxWindow *parent);
  165. bool Create();
  166. protected:
  167. wxString GetBoxTitle() { return m_textTitle->GetValue(); }
  168. wxString GetMessage() { return m_textMsg->GetValue(); }
  169. long GetStyle();
  170. void PrepareMessageDialog(wxMessageDialogBase &dlg);
  171. virtual void AddAdditionalTextOptions(wxSizer *WXUNUSED(sizer)) { }
  172. virtual void AddAdditionalFlags(wxSizer *WXUNUSED(sizer)) { }
  173. void OnApply(wxCommandEvent& event);
  174. void OnClose(wxCommandEvent& event);
  175. void OnUpdateLabelUI(wxUpdateUIEvent& event);
  176. void OnUpdateNoDefaultUI(wxUpdateUIEvent& event);
  177. private:
  178. enum
  179. {
  180. Btn_Yes,
  181. Btn_No,
  182. Btn_Ok,
  183. Btn_Cancel,
  184. Btn_Help,
  185. Btn_Max
  186. };
  187. struct BtnInfo
  188. {
  189. int flag;
  190. const char *name;
  191. };
  192. static const BtnInfo ms_btnInfo[Btn_Max];
  193. enum
  194. {
  195. MsgDlgIcon_No,
  196. MsgDlgIcon_None,
  197. MsgDlgIcon_Info,
  198. MsgDlgIcon_Question,
  199. MsgDlgIcon_Warning,
  200. MsgDlgIcon_Error,
  201. MsgDlgIcon_AuthNeeded,
  202. MsgDlgIcon_Max
  203. };
  204. wxTextCtrl *m_textTitle,
  205. *m_textMsg,
  206. *m_textExtMsg;
  207. wxCheckBox *m_buttons[Btn_Max];
  208. wxTextCtrl *m_labels[Btn_Max];
  209. wxRadioBox *m_icons;
  210. wxCheckBox *m_chkNoDefault,
  211. *m_chkCentre;
  212. wxDECLARE_EVENT_TABLE();
  213. wxDECLARE_NO_COPY_CLASS(TestMessageBoxDialog);
  214. };
  215. #if wxUSE_RICHMSGDLG
  216. class TestRichMessageDialog : public TestMessageBoxDialog
  217. {
  218. public:
  219. TestRichMessageDialog(wxWindow *parent);
  220. protected:
  221. // overrides method in base class
  222. virtual void AddAdditionalTextOptions(wxSizer *sizer);
  223. virtual void AddAdditionalFlags(wxSizer *sizer);
  224. void OnApply(wxCommandEvent& event);
  225. private:
  226. wxTextCtrl *m_textCheckBox;
  227. wxCheckBox *m_initialValueCheckBox;
  228. wxTextCtrl *m_textDetailed;
  229. wxDECLARE_EVENT_TABLE();
  230. };
  231. #endif // wxUSE_RICHMSGDLG
  232. class TestDefaultActionDialog: public wxDialog
  233. {
  234. public:
  235. TestDefaultActionDialog( wxWindow *parent );
  236. void OnListBoxDClick(wxCommandEvent& event);
  237. void OnDisableOK(wxCommandEvent& event);
  238. void OnDisableCancel(wxCommandEvent& event);
  239. void OnCatchListBoxDClick(wxCommandEvent& event);
  240. void OnTextEnter(wxCommandEvent& event);
  241. private:
  242. bool m_catchListBoxDClick;
  243. private:
  244. wxDECLARE_EVENT_TABLE();
  245. };
  246. #if USE_SETTINGS_DIALOG
  247. // Property sheet dialog
  248. class SettingsDialog: public wxPropertySheetDialog
  249. {
  250. DECLARE_CLASS(SettingsDialog)
  251. public:
  252. SettingsDialog(wxWindow* parent, int dialogType);
  253. ~SettingsDialog();
  254. wxPanel* CreateGeneralSettingsPage(wxWindow* parent);
  255. wxPanel* CreateAestheticSettingsPage(wxWindow* parent);
  256. protected:
  257. enum {
  258. ID_SHOW_TOOLTIPS = 100,
  259. ID_AUTO_SAVE,
  260. ID_AUTO_SAVE_MINS,
  261. ID_LOAD_LAST_PROJECT,
  262. ID_APPLY_SETTINGS_TO,
  263. ID_BACKGROUND_STYLE,
  264. ID_FONT_SIZE
  265. };
  266. wxImageList* m_imageList;
  267. DECLARE_EVENT_TABLE()
  268. };
  269. #endif // USE_SETTINGS_DIALOG
  270. // Define a new frame type
  271. class MyFrame: public wxFrame
  272. {
  273. public:
  274. MyFrame(const wxString& title);
  275. virtual ~MyFrame();
  276. #if wxUSE_MSGDLG
  277. void MessageBox(wxCommandEvent& event);
  278. void MessageBoxDialog(wxCommandEvent& event);
  279. void MessageBoxInfo(wxCommandEvent& event);
  280. void MessageBoxWindowModal(wxCommandEvent& event);
  281. void MessageBoxWindowModalClosed(wxWindowModalDialogEvent& event);
  282. #endif // wxUSE_MSGDLG
  283. #if wxUSE_RICHMSGDLG
  284. void RichMessageDialog(wxCommandEvent& event);
  285. #endif // wxUSE_RICHMSGDLG
  286. #if wxUSE_COLOURDLG
  287. void ChooseColour(wxCommandEvent& event);
  288. void GetColour(wxCommandEvent& event);
  289. #endif // wxUSE_COLOURDLG
  290. #if wxUSE_FONTDLG
  291. void ChooseFont(wxCommandEvent& event);
  292. #endif // wxUSE_FONTDLG
  293. #if wxUSE_LOG_DIALOG
  294. void LogDialog(wxCommandEvent& event);
  295. #endif // wxUSE_LOG_DIALOG
  296. #if wxUSE_INFOBAR
  297. void InfoBarSimple(wxCommandEvent& event);
  298. void InfoBarAdvanced(wxCommandEvent& event);
  299. #endif // wxUSE_INFOBAR
  300. #if wxUSE_CHOICEDLG
  301. void SingleChoice(wxCommandEvent& event);
  302. void MultiChoice(wxCommandEvent& event);
  303. #endif // wxUSE_CHOICEDLG
  304. void Rearrange(wxCommandEvent& event);
  305. #if wxUSE_TEXTDLG
  306. void LineEntry(wxCommandEvent& event);
  307. void TextEntry(wxCommandEvent& event);
  308. void PasswordEntry(wxCommandEvent& event);
  309. #endif // wxUSE_TEXTDLG
  310. #if wxUSE_NUMBERDLG
  311. void NumericEntry(wxCommandEvent& event);
  312. #endif // wxUSE_NUMBERDLG
  313. #if wxUSE_FILEDLG
  314. void FileOpen(wxCommandEvent& event);
  315. void FileOpen2(wxCommandEvent& event);
  316. void FilesOpen(wxCommandEvent& event);
  317. void FileSave(wxCommandEvent& event);
  318. #endif // wxUSE_FILEDLG
  319. #if USE_FILEDLG_GENERIC
  320. void FileOpenGeneric(wxCommandEvent& event);
  321. void FilesOpenGeneric(wxCommandEvent& event);
  322. void FileSaveGeneric(wxCommandEvent& event);
  323. #endif // USE_FILEDLG_GENERIC
  324. #if wxUSE_DIRDLG
  325. void DirChoose(wxCommandEvent& event);
  326. void DirChooseNew(wxCommandEvent& event);
  327. #endif // wxUSE_DIRDLG
  328. #if USE_DIRDLG_GENERIC
  329. void GenericDirChoose(wxCommandEvent& event);
  330. #endif // USE_DIRDLG_GENERIC
  331. #if wxUSE_STARTUP_TIPS
  332. void ShowTip(wxCommandEvent& event);
  333. #endif // wxUSE_STARTUP_TIPS
  334. #if USE_MODAL_PRESENTATION
  335. void ModalDlg(wxCommandEvent& event);
  336. #endif // USE_MODAL_PRESENTATION
  337. void ModelessDlg(wxCommandEvent& event);
  338. void DlgCenteredScreen(wxCommandEvent& event);
  339. void DlgCenteredParent(wxCommandEvent& event);
  340. void MiniFrame(wxCommandEvent& event);
  341. void DlgOnTop(wxCommandEvent& event);
  342. #if wxUSE_PROGRESSDLG
  343. void ShowProgress(wxCommandEvent& event);
  344. #endif // wxUSE_PROGRESSDLG
  345. #if wxUSE_ABOUTDLG
  346. void ShowSimpleAboutDialog(wxCommandEvent& event);
  347. void ShowFancyAboutDialog(wxCommandEvent& event);
  348. void ShowFullAboutDialog(wxCommandEvent& event);
  349. void ShowCustomAboutDialog(wxCommandEvent& event);
  350. #endif // wxUSE_ABOUTDLG
  351. #if wxUSE_BUSYINFO
  352. void ShowBusyInfo(wxCommandEvent& event);
  353. #endif // wxUSE_BUSYINFO
  354. #if wxUSE_FINDREPLDLG
  355. void ShowFindDialog(wxCommandEvent& event);
  356. void ShowReplaceDialog(wxCommandEvent& event);
  357. void OnFindDialog(wxFindDialogEvent& event);
  358. #endif // wxUSE_FINDREPLDLG
  359. #if USE_COLOURDLG_GENERIC
  360. void ChooseColourGeneric(wxCommandEvent& event);
  361. #endif // USE_COLOURDLG_GENERIC
  362. #if USE_FONTDLG_GENERIC
  363. void ChooseFontGeneric(wxCommandEvent& event);
  364. #endif // USE_FONTDLG_GENERIC
  365. void OnPropertySheet(wxCommandEvent& event);
  366. void OnRequestUserAttention(wxCommandEvent& event);
  367. #if wxUSE_NOTIFICATION_MESSAGE
  368. void OnNotifMsgAuto(wxCommandEvent& event);
  369. void OnNotifMsgShow(wxCommandEvent& event);
  370. void OnNotifMsgHide(wxCommandEvent& event);
  371. #endif // wxUSE_NOTIFICATION_MESSAGE
  372. #if wxUSE_RICHTOOLTIP
  373. void OnRichTipDialog(wxCommandEvent& event);
  374. #endif // wxUSE_RICHTOOLTIP
  375. void OnStandardButtonsSizerDialog(wxCommandEvent& event);
  376. void OnTestDefaultActionDialog(wxCommandEvent& event);
  377. void OnModalHook(wxCommandEvent& event);
  378. void OnExit(wxCommandEvent& event);
  379. private:
  380. #if wxUSE_DIRDLG
  381. void DoDirChoose(int style);
  382. #endif // wxUSE_DIRDLG
  383. #if USE_MODAL_PRESENTATION
  384. MyModelessDialog *m_dialog;
  385. #endif // USE_MODAL_PRESENTATION
  386. #if wxUSE_FINDREPLDLG
  387. wxFindReplaceData m_findData;
  388. wxFindReplaceDialog *m_dlgFind,
  389. *m_dlgReplace;
  390. #endif // wxUSE_FINDREPLDLG
  391. #if wxUSE_NOTIFICATION_MESSAGE
  392. wxNotificationMessage *m_notifMsg;
  393. #endif // wxUSE_NOTIFICATION_MESSAGE
  394. wxColourData m_clrData;
  395. // just a window which we use to show the effect of font/colours selection
  396. wxWindow *m_canvas;
  397. #if wxUSE_INFOBAR
  398. void OnInfoBarRedo(wxCommandEvent& event);
  399. wxInfoBar *m_infoBarSimple,
  400. *m_infoBarAdvanced;
  401. #endif // wxUSE_INFOBAR
  402. wxDECLARE_EVENT_TABLE();
  403. };
  404. class MyCanvas: public wxScrolledWindow
  405. {
  406. public:
  407. MyCanvas(wxWindow *parent) : wxScrolledWindow(parent, wxID_ANY)
  408. {
  409. SetForegroundColour(*wxBLACK);
  410. SetBackgroundColour(*wxWHITE);
  411. SetFont(*wxNORMAL_FONT);
  412. }
  413. private:
  414. void OnPaint(wxPaintEvent& event);
  415. wxDECLARE_EVENT_TABLE();
  416. };
  417. // Menu IDs
  418. enum
  419. {
  420. DIALOGS_CHOOSE_COLOUR = wxID_HIGHEST,
  421. DIALOGS_GET_COLOUR,
  422. DIALOGS_CHOOSE_COLOUR_GENERIC,
  423. DIALOGS_CHOOSE_FONT,
  424. DIALOGS_CHOOSE_FONT_GENERIC,
  425. DIALOGS_MESSAGE_BOX,
  426. DIALOGS_MESSAGE_BOX_WINDOW_MODAL,
  427. DIALOGS_MESSAGE_DIALOG,
  428. DIALOGS_MESSAGE_BOX_WXINFO,
  429. DIALOGS_RICH_MESSAGE_DIALOG,
  430. DIALOGS_SINGLE_CHOICE,
  431. DIALOGS_MULTI_CHOICE,
  432. DIALOGS_REARRANGE,
  433. DIALOGS_LINE_ENTRY,
  434. DIALOGS_TEXT_ENTRY,
  435. DIALOGS_PASSWORD_ENTRY,
  436. DIALOGS_FILE_OPEN,
  437. DIALOGS_FILE_OPEN2,
  438. DIALOGS_FILES_OPEN,
  439. DIALOGS_FILE_SAVE,
  440. DIALOGS_FILE_OPEN_GENERIC,
  441. DIALOGS_FILES_OPEN_GENERIC,
  442. DIALOGS_FILE_SAVE_GENERIC,
  443. DIALOGS_DIR_CHOOSE,
  444. DIALOGS_DIRNEW_CHOOSE,
  445. DIALOGS_GENERIC_DIR_CHOOSE,
  446. DIALOGS_TIP,
  447. DIALOGS_NUM_ENTRY,
  448. DIALOGS_LOG_DIALOG,
  449. DIALOGS_INFOBAR_SIMPLE,
  450. DIALOGS_INFOBAR_ADVANCED,
  451. DIALOGS_MODAL,
  452. DIALOGS_MODELESS,
  453. DIALOGS_CENTRE_SCREEN,
  454. DIALOGS_CENTRE_PARENT,
  455. DIALOGS_MINIFRAME,
  456. DIALOGS_ONTOP,
  457. DIALOGS_MODELESS_BTN,
  458. DIALOGS_PROGRESS,
  459. DIALOGS_ABOUTDLG_SIMPLE,
  460. DIALOGS_ABOUTDLG_FANCY,
  461. DIALOGS_ABOUTDLG_FULL,
  462. DIALOGS_ABOUTDLG_CUSTOM,
  463. DIALOGS_BUSYINFO,
  464. DIALOGS_FIND,
  465. DIALOGS_REPLACE,
  466. DIALOGS_REQUEST,
  467. DIALOGS_NOTIFY_AUTO,
  468. DIALOGS_NOTIFY_SHOW,
  469. DIALOGS_NOTIFY_HIDE,
  470. DIALOGS_RICHTIP_DIALOG,
  471. DIALOGS_PROPERTY_SHEET,
  472. DIALOGS_PROPERTY_SHEET_TOOLBOOK,
  473. DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK,
  474. DIALOGS_STANDARD_BUTTON_SIZER_DIALOG,
  475. DIALOGS_TEST_DEFAULT_ACTION,
  476. DIALOGS_MODAL_HOOK
  477. };
  478. #endif