choicdgg.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/generic/choicdgg.h
  3. // Purpose: Generic choice dialogs
  4. // Author: Julian Smart
  5. // Modified by: 03.11.00: VZ to add wxArrayString and multiple sel functions
  6. // Created: 01/02/97
  7. // Copyright: (c) wxWidgets team
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_GENERIC_CHOICDGG_H_
  11. #define _WX_GENERIC_CHOICDGG_H_
  12. #include "wx/dynarray.h"
  13. #include "wx/dialog.h"
  14. class WXDLLIMPEXP_FWD_CORE wxListBoxBase;
  15. // ----------------------------------------------------------------------------
  16. // some (ugly...) constants
  17. // ----------------------------------------------------------------------------
  18. #define wxCHOICE_HEIGHT 150
  19. #define wxCHOICE_WIDTH 200
  20. #ifdef __WXWINCE__
  21. #define wxCHOICEDLG_STYLE \
  22. (wxDEFAULT_DIALOG_STYLE | wxOK | wxCANCEL | wxCENTRE)
  23. #else
  24. #define wxCHOICEDLG_STYLE \
  25. (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE)
  26. #endif
  27. // ----------------------------------------------------------------------------
  28. // wxAnyChoiceDialog: a base class for dialogs containing a listbox
  29. // ----------------------------------------------------------------------------
  30. class WXDLLIMPEXP_CORE wxAnyChoiceDialog : public wxDialog
  31. {
  32. public:
  33. wxAnyChoiceDialog() { }
  34. wxAnyChoiceDialog(wxWindow *parent,
  35. const wxString& message,
  36. const wxString& caption,
  37. int n, const wxString *choices,
  38. long styleDlg = wxCHOICEDLG_STYLE,
  39. const wxPoint& pos = wxDefaultPosition,
  40. long styleLbox = wxLB_ALWAYS_SB)
  41. {
  42. (void)Create(parent, message, caption, n, choices,
  43. styleDlg, pos, styleLbox);
  44. }
  45. wxAnyChoiceDialog(wxWindow *parent,
  46. const wxString& message,
  47. const wxString& caption,
  48. const wxArrayString& choices,
  49. long styleDlg = wxCHOICEDLG_STYLE,
  50. const wxPoint& pos = wxDefaultPosition,
  51. long styleLbox = wxLB_ALWAYS_SB)
  52. {
  53. (void)Create(parent, message, caption, choices,
  54. styleDlg, pos, styleLbox);
  55. }
  56. bool Create(wxWindow *parent,
  57. const wxString& message,
  58. const wxString& caption,
  59. int n, const wxString *choices,
  60. long styleDlg = wxCHOICEDLG_STYLE,
  61. const wxPoint& pos = wxDefaultPosition,
  62. long styleLbox = wxLB_ALWAYS_SB);
  63. bool Create(wxWindow *parent,
  64. const wxString& message,
  65. const wxString& caption,
  66. const wxArrayString& choices,
  67. long styleDlg = wxCHOICEDLG_STYLE,
  68. const wxPoint& pos = wxDefaultPosition,
  69. long styleLbox = wxLB_ALWAYS_SB);
  70. protected:
  71. wxListBoxBase *m_listbox;
  72. virtual wxListBoxBase *CreateList(int n,
  73. const wxString *choices,
  74. long styleLbox);
  75. wxDECLARE_NO_COPY_CLASS(wxAnyChoiceDialog);
  76. };
  77. // ----------------------------------------------------------------------------
  78. // wxSingleChoiceDialog: a dialog with single selection listbox
  79. // ----------------------------------------------------------------------------
  80. class WXDLLIMPEXP_CORE wxSingleChoiceDialog : public wxAnyChoiceDialog
  81. {
  82. public:
  83. wxSingleChoiceDialog()
  84. {
  85. m_selection = -1;
  86. }
  87. wxSingleChoiceDialog(wxWindow *parent,
  88. const wxString& message,
  89. const wxString& caption,
  90. int n,
  91. const wxString *choices,
  92. void **clientData = NULL,
  93. long style = wxCHOICEDLG_STYLE,
  94. const wxPoint& pos = wxDefaultPosition)
  95. {
  96. Create(parent, message, caption, n, choices, clientData, style, pos);
  97. }
  98. wxSingleChoiceDialog(wxWindow *parent,
  99. const wxString& message,
  100. const wxString& caption,
  101. const wxArrayString& choices,
  102. void **clientData = NULL,
  103. long style = wxCHOICEDLG_STYLE,
  104. const wxPoint& pos = wxDefaultPosition)
  105. {
  106. Create(parent, message, caption, choices, clientData, style, pos);
  107. }
  108. bool Create(wxWindow *parent,
  109. const wxString& message,
  110. const wxString& caption,
  111. int n,
  112. const wxString *choices,
  113. void **clientData = NULL,
  114. long style = wxCHOICEDLG_STYLE,
  115. const wxPoint& pos = wxDefaultPosition);
  116. bool Create(wxWindow *parent,
  117. const wxString& message,
  118. const wxString& caption,
  119. const wxArrayString& choices,
  120. void **clientData = NULL,
  121. long style = wxCHOICEDLG_STYLE,
  122. const wxPoint& pos = wxDefaultPosition);
  123. void SetSelection(int sel);
  124. int GetSelection() const { return m_selection; }
  125. wxString GetStringSelection() const { return m_stringSelection; }
  126. void* GetSelectionData() const { return m_clientData; }
  127. #if WXWIN_COMPATIBILITY_2_8
  128. // Deprecated overloads taking "char**" client data.
  129. wxDEPRECATED_CONSTRUCTOR
  130. (
  131. wxSingleChoiceDialog(wxWindow *parent,
  132. const wxString& message,
  133. const wxString& caption,
  134. int n,
  135. const wxString *choices,
  136. char **clientData,
  137. long style = wxCHOICEDLG_STYLE,
  138. const wxPoint& pos = wxDefaultPosition)
  139. )
  140. {
  141. Create(parent, message, caption, n, choices,
  142. (void**)clientData, style, pos);
  143. }
  144. wxDEPRECATED_CONSTRUCTOR
  145. (
  146. wxSingleChoiceDialog(wxWindow *parent,
  147. const wxString& message,
  148. const wxString& caption,
  149. const wxArrayString& choices,
  150. char **clientData,
  151. long style = wxCHOICEDLG_STYLE,
  152. const wxPoint& pos = wxDefaultPosition)
  153. )
  154. {
  155. Create(parent, message, caption, choices,
  156. (void**)clientData, style, pos);
  157. }
  158. wxDEPRECATED_INLINE
  159. (
  160. bool Create(wxWindow *parent,
  161. const wxString& message,
  162. const wxString& caption,
  163. int n,
  164. const wxString *choices,
  165. char **clientData,
  166. long style = wxCHOICEDLG_STYLE,
  167. const wxPoint& pos = wxDefaultPosition),
  168. return Create(parent, message, caption, n, choices,
  169. (void**)clientData, style, pos);
  170. )
  171. wxDEPRECATED_INLINE
  172. (
  173. bool Create(wxWindow *parent,
  174. const wxString& message,
  175. const wxString& caption,
  176. const wxArrayString& choices,
  177. char **clientData,
  178. long style = wxCHOICEDLG_STYLE,
  179. const wxPoint& pos = wxDefaultPosition),
  180. return Create(parent, message, caption, choices,
  181. (void**)clientData, style, pos);
  182. )
  183. // NB: no need to make it return wxChar, it's untyped
  184. wxDEPRECATED_ACCESSOR
  185. (
  186. char* GetSelectionClientData() const,
  187. (char*)GetSelectionData()
  188. )
  189. #endif // WXWIN_COMPATIBILITY_2_8
  190. // implementation from now on
  191. void OnOK(wxCommandEvent& event);
  192. #ifndef __SMARTPHONE__
  193. void OnListBoxDClick(wxCommandEvent& event);
  194. #endif
  195. #ifdef __WXWINCE__
  196. void OnJoystickButtonDown(wxJoystickEvent& event);
  197. #endif
  198. protected:
  199. int m_selection;
  200. wxString m_stringSelection;
  201. void DoChoice();
  202. private:
  203. DECLARE_DYNAMIC_CLASS_NO_COPY(wxSingleChoiceDialog)
  204. DECLARE_EVENT_TABLE()
  205. };
  206. // ----------------------------------------------------------------------------
  207. // wxMultiChoiceDialog: a dialog with multi selection listbox
  208. // ----------------------------------------------------------------------------
  209. class WXDLLIMPEXP_CORE wxMultiChoiceDialog : public wxAnyChoiceDialog
  210. {
  211. public:
  212. wxMultiChoiceDialog() { }
  213. wxMultiChoiceDialog(wxWindow *parent,
  214. const wxString& message,
  215. const wxString& caption,
  216. int n,
  217. const wxString *choices,
  218. long style = wxCHOICEDLG_STYLE,
  219. const wxPoint& pos = wxDefaultPosition)
  220. {
  221. (void)Create(parent, message, caption, n, choices, style, pos);
  222. }
  223. wxMultiChoiceDialog(wxWindow *parent,
  224. const wxString& message,
  225. const wxString& caption,
  226. const wxArrayString& choices,
  227. long style = wxCHOICEDLG_STYLE,
  228. const wxPoint& pos = wxDefaultPosition)
  229. {
  230. (void)Create(parent, message, caption, choices, style, pos);
  231. }
  232. bool Create(wxWindow *parent,
  233. const wxString& message,
  234. const wxString& caption,
  235. int n,
  236. const wxString *choices,
  237. long style = wxCHOICEDLG_STYLE,
  238. const wxPoint& pos = wxDefaultPosition);
  239. bool Create(wxWindow *parent,
  240. const wxString& message,
  241. const wxString& caption,
  242. const wxArrayString& choices,
  243. long style = wxCHOICEDLG_STYLE,
  244. const wxPoint& pos = wxDefaultPosition);
  245. void SetSelections(const wxArrayInt& selections);
  246. wxArrayInt GetSelections() const { return m_selections; }
  247. // implementation from now on
  248. virtual bool TransferDataFromWindow();
  249. protected:
  250. #if wxUSE_CHECKLISTBOX
  251. virtual wxListBoxBase *CreateList(int n,
  252. const wxString *choices,
  253. long styleLbox);
  254. #endif // wxUSE_CHECKLISTBOX
  255. wxArrayInt m_selections;
  256. private:
  257. DECLARE_DYNAMIC_CLASS_NO_COPY(wxMultiChoiceDialog)
  258. };
  259. // ----------------------------------------------------------------------------
  260. // wrapper functions which can be used to get selection(s) from the user
  261. // ----------------------------------------------------------------------------
  262. // get the user selection as a string
  263. WXDLLIMPEXP_CORE wxString wxGetSingleChoice(const wxString& message,
  264. const wxString& caption,
  265. const wxArrayString& choices,
  266. wxWindow *parent = NULL,
  267. int x = wxDefaultCoord,
  268. int y = wxDefaultCoord,
  269. bool centre = true,
  270. int width = wxCHOICE_WIDTH,
  271. int height = wxCHOICE_HEIGHT,
  272. int initialSelection = 0);
  273. WXDLLIMPEXP_CORE wxString wxGetSingleChoice(const wxString& message,
  274. const wxString& caption,
  275. int n, const wxString *choices,
  276. wxWindow *parent = NULL,
  277. int x = wxDefaultCoord,
  278. int y = wxDefaultCoord,
  279. bool centre = true,
  280. int width = wxCHOICE_WIDTH,
  281. int height = wxCHOICE_HEIGHT,
  282. int initialSelection = 0);
  283. WXDLLIMPEXP_CORE wxString wxGetSingleChoice(const wxString& message,
  284. const wxString& caption,
  285. const wxArrayString& choices,
  286. int initialSelection,
  287. wxWindow *parent = NULL);
  288. WXDLLIMPEXP_CORE wxString wxGetSingleChoice(const wxString& message,
  289. const wxString& caption,
  290. int n, const wxString *choices,
  291. int initialSelection,
  292. wxWindow *parent = NULL);
  293. // Same as above but gets position in list of strings, instead of string,
  294. // or -1 if no selection
  295. WXDLLIMPEXP_CORE int wxGetSingleChoiceIndex(const wxString& message,
  296. const wxString& caption,
  297. const wxArrayString& choices,
  298. wxWindow *parent = NULL,
  299. int x = wxDefaultCoord,
  300. int y = wxDefaultCoord,
  301. bool centre = true,
  302. int width = wxCHOICE_WIDTH,
  303. int height = wxCHOICE_HEIGHT,
  304. int initialSelection = 0);
  305. WXDLLIMPEXP_CORE int wxGetSingleChoiceIndex(const wxString& message,
  306. const wxString& caption,
  307. int n, const wxString *choices,
  308. wxWindow *parent = NULL,
  309. int x = wxDefaultCoord,
  310. int y = wxDefaultCoord,
  311. bool centre = true,
  312. int width = wxCHOICE_WIDTH,
  313. int height = wxCHOICE_HEIGHT,
  314. int initialSelection = 0);
  315. WXDLLIMPEXP_CORE int wxGetSingleChoiceIndex(const wxString& message,
  316. const wxString& caption,
  317. const wxArrayString& choices,
  318. int initialSelection,
  319. wxWindow *parent = NULL);
  320. WXDLLIMPEXP_CORE int wxGetSingleChoiceIndex(const wxString& message,
  321. const wxString& caption,
  322. int n, const wxString *choices,
  323. int initialSelection,
  324. wxWindow *parent = NULL);
  325. // Return client data instead or NULL if canceled
  326. WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message,
  327. const wxString& caption,
  328. const wxArrayString& choices,
  329. void **client_data,
  330. wxWindow *parent = NULL,
  331. int x = wxDefaultCoord,
  332. int y = wxDefaultCoord,
  333. bool centre = true,
  334. int width = wxCHOICE_WIDTH,
  335. int height = wxCHOICE_HEIGHT,
  336. int initialSelection = 0);
  337. WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message,
  338. const wxString& caption,
  339. int n, const wxString *choices,
  340. void **client_data,
  341. wxWindow *parent = NULL,
  342. int x = wxDefaultCoord,
  343. int y = wxDefaultCoord,
  344. bool centre = true,
  345. int width = wxCHOICE_WIDTH,
  346. int height = wxCHOICE_HEIGHT,
  347. int initialSelection = 0);
  348. WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message,
  349. const wxString& caption,
  350. const wxArrayString& choices,
  351. void **client_data,
  352. int initialSelection,
  353. wxWindow *parent = NULL);
  354. WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message,
  355. const wxString& caption,
  356. int n, const wxString *choices,
  357. void **client_data,
  358. int initialSelection,
  359. wxWindow *parent = NULL);
  360. // fill the array with the indices of the chosen items, it will be empty
  361. // if no items were selected or Cancel was pressed - return the number of
  362. // selections or -1 if cancelled
  363. WXDLLIMPEXP_CORE int wxGetSelectedChoices(wxArrayInt& selections,
  364. const wxString& message,
  365. const wxString& caption,
  366. int n, const wxString *choices,
  367. wxWindow *parent = NULL,
  368. int x = wxDefaultCoord,
  369. int y = wxDefaultCoord,
  370. bool centre = true,
  371. int width = wxCHOICE_WIDTH,
  372. int height = wxCHOICE_HEIGHT);
  373. WXDLLIMPEXP_CORE int wxGetSelectedChoices(wxArrayInt& selections,
  374. const wxString& message,
  375. const wxString& caption,
  376. const wxArrayString& choices,
  377. wxWindow *parent = NULL,
  378. int x = wxDefaultCoord,
  379. int y = wxDefaultCoord,
  380. bool centre = true,
  381. int width = wxCHOICE_WIDTH,
  382. int height = wxCHOICE_HEIGHT);
  383. #if WXWIN_COMPATIBILITY_2_8
  384. // fill the array with the indices of the chosen items, it will be empty
  385. // if no items were selected or Cancel was pressed - return the number of
  386. // selections
  387. wxDEPRECATED( WXDLLIMPEXP_CORE size_t wxGetMultipleChoices(wxArrayInt& selections,
  388. const wxString& message,
  389. const wxString& caption,
  390. int n, const wxString *choices,
  391. wxWindow *parent = NULL,
  392. int x = wxDefaultCoord,
  393. int y = wxDefaultCoord,
  394. bool centre = true,
  395. int width = wxCHOICE_WIDTH,
  396. int height = wxCHOICE_HEIGHT) );
  397. wxDEPRECATED( WXDLLIMPEXP_CORE size_t wxGetMultipleChoices(wxArrayInt& selections,
  398. const wxString& message,
  399. const wxString& caption,
  400. const wxArrayString& choices,
  401. wxWindow *parent = NULL,
  402. int x = wxDefaultCoord,
  403. int y = wxDefaultCoord,
  404. bool centre = true,
  405. int width = wxCHOICE_WIDTH,
  406. int height = wxCHOICE_HEIGHT));
  407. #endif // WXWIN_COMPATIBILITY_2_8
  408. #endif // _WX_GENERIC_CHOICDGG_H_