choicdlg.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: choicdlg.h
  3. // Purpose: interface of wx[Multi|Single]ChoiceDialog
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. Default width of the choice dialog.
  9. */
  10. #define wxCHOICE_WIDTH 150
  11. /**
  12. Default height of the choice dialog.
  13. */
  14. #define wxCHOICE_HEIGHT 200
  15. /**
  16. Default style of the choice dialog.
  17. @remarks wxRESIZE_BORDER is not used under WinCE.
  18. */
  19. #define wxCHOICEDLG_STYLE (wxDEFAULT_DIALOG_STYLE | wxOK | wxCANCEL | wxCENTRE | wxRESIZE_BORDER)
  20. /**
  21. @class wxMultiChoiceDialog
  22. This class represents a dialog that shows a list of strings, and allows the
  23. user to select one or more.
  24. @beginStyleTable
  25. @style{wxOK}
  26. Show an OK button.
  27. @style{wxCANCEL}
  28. Show a Cancel button.
  29. @style{wxCENTRE}
  30. Centre the message. Not Windows.
  31. @endStyleTable
  32. @library{wxbase}
  33. @category{cmndlg}
  34. @see @ref overview_cmndlg_multichoice, wxSingleChoiceDialog
  35. */
  36. class wxMultiChoiceDialog : public wxDialog
  37. {
  38. public:
  39. //@{
  40. /**
  41. Constructor taking an array of wxString choices.
  42. @param parent
  43. Parent window.
  44. @param message
  45. Message to show on the dialog.
  46. @param caption
  47. The dialog caption.
  48. @param n
  49. The number of choices.
  50. @param choices
  51. An array of strings, or a string list, containing the choices.
  52. @param style
  53. A dialog style (bitlist) containing flags chosen from standard
  54. dialog styles and the ones listed in the class documentation. The
  55. default value is equivalent to wxDEFAULT_DIALOG_STYLE |
  56. wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE.
  57. @param pos
  58. Dialog position. Not Windows.
  59. @remarks Use ShowModal() to show the dialog.
  60. @beginWxPerlOnly
  61. Not supported by wxPerl.
  62. @endWxPerlOnly
  63. */
  64. wxMultiChoiceDialog(wxWindow* parent, const wxString& message,
  65. const wxString& caption,
  66. int n, const wxString* choices,
  67. long style = wxCHOICEDLG_STYLE,
  68. const wxPoint& pos = wxDefaultPosition);
  69. /**
  70. Constructor taking an array of wxString choices.
  71. @param parent
  72. Parent window.
  73. @param message
  74. Message to show on the dialog.
  75. @param caption
  76. The dialog caption.
  77. @param choices
  78. An array of strings, or a string list, containing the choices.
  79. @param style
  80. A dialog style (bitlist) containing flags chosen from standard
  81. dialog styles and the ones listed in the class documentation. The
  82. default value is equivalent to wxDEFAULT_DIALOG_STYLE |
  83. wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE.
  84. @param pos
  85. Dialog position. Not Windows.
  86. @remarks Use ShowModal() to show the dialog.
  87. @beginWxPerlOnly
  88. Use an array reference for the @a choices parameter.
  89. @endWxPerlOnly
  90. */
  91. wxMultiChoiceDialog(wxWindow* parent,
  92. const wxString& message,
  93. const wxString& caption,
  94. const wxArrayString& choices,
  95. long style = wxCHOICEDLG_STYLE,
  96. const wxPoint& pos = wxDefaultPosition);
  97. //@}
  98. /**
  99. Returns array with indexes of selected items.
  100. */
  101. wxArrayInt GetSelections() const;
  102. /**
  103. Sets selected items from the array of selected items' indexes.
  104. */
  105. void SetSelections(const wxArrayInt& selections);
  106. /**
  107. Shows the dialog, returning either wxID_OK or wxID_CANCEL.
  108. */
  109. int ShowModal();
  110. };
  111. /**
  112. @class wxSingleChoiceDialog
  113. This class represents a dialog that shows a list of strings, and allows the
  114. user to select one. Double-clicking on a list item is equivalent to
  115. single-clicking and then pressing OK.
  116. @beginStyleTable
  117. @style{wxOK}
  118. Show an OK button.
  119. @style{wxCANCEL}
  120. Show a Cancel button.
  121. @style{wxCENTRE}
  122. Centre the message. Not Windows.
  123. @endStyleTable
  124. @library{wxbase}
  125. @category{cmndlg}
  126. @see @ref overview_cmndlg_singlechoice, wxMultiChoiceDialog
  127. */
  128. class wxSingleChoiceDialog : public wxDialog
  129. {
  130. public:
  131. //@{
  132. /**
  133. Constructor, taking an array of wxString choices and optional client
  134. data.
  135. @param parent
  136. Parent window.
  137. @param message
  138. Message to show on the dialog.
  139. @param caption
  140. The dialog caption.
  141. @param n
  142. The number of choices.
  143. @param choices
  144. An array of strings, or a string list, containing the choices.
  145. @param clientData
  146. An array of client data to be associated with the items. See
  147. GetSelectionData().
  148. @param style
  149. A dialog style (bitlist) containing flags chosen from standard
  150. dialog styles and the ones listed in the class documentation. The
  151. default value is equivalent to wxDEFAULT_DIALOG_STYLE |
  152. wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE.
  153. @param pos
  154. Dialog position. Not Windows.
  155. @remarks Use ShowModal() to show the dialog.
  156. @beginWxPerlOnly
  157. Not supported by wxPerl.
  158. @endWxPerlOnly
  159. */
  160. wxSingleChoiceDialog(wxWindow* parent, const wxString& message,
  161. const wxString& caption,
  162. int n, const wxString* choices,
  163. void** clientData = NULL,
  164. long style = wxCHOICEDLG_STYLE,
  165. const wxPoint& pos = wxDefaultPosition);
  166. /**
  167. Constructor, taking an array of wxString choices and optional client
  168. data.
  169. @param parent
  170. Parent window.
  171. @param message
  172. Message to show on the dialog.
  173. @param caption
  174. The dialog caption.
  175. @param choices
  176. An array of strings, or a string list, containing the choices.
  177. @param clientData
  178. An array of client data to be associated with the items. See
  179. GetSelectionData().
  180. @param style
  181. A dialog style (bitlist) containing flags chosen from standard
  182. dialog styles and the ones listed in the class documentation. The
  183. default value is equivalent to wxDEFAULT_DIALOG_STYLE |
  184. wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE.
  185. @param pos
  186. Dialog position. Not Windows.
  187. @remarks Use ShowModal() to show the dialog.
  188. @beginWxPerlOnly
  189. Use an array reference for the @a choices parameter.
  190. @endWxPerlOnly
  191. */
  192. wxSingleChoiceDialog(wxWindow* parent,
  193. const wxString& message,
  194. const wxString& caption,
  195. const wxArrayString& choices,
  196. void** clientData = NULL,
  197. long style = wxCHOICEDLG_STYLE,
  198. const wxPoint& pos = wxDefaultPosition);
  199. //@}
  200. /**
  201. Returns the index of selected item.
  202. */
  203. int GetSelection() const;
  204. /**
  205. Returns the client data associated with the selection.
  206. @since 2.9.4
  207. */
  208. void* GetSelectionData() const;
  209. /**
  210. Returns the selected string.
  211. */
  212. wxString GetStringSelection() const;
  213. /**
  214. Sets the index of the initially selected item.
  215. */
  216. void SetSelection(int selection);
  217. /**
  218. Shows the dialog, returning either wxID_OK or wxID_CANCEL.
  219. */
  220. int ShowModal();
  221. };
  222. // ============================================================================
  223. // Global functions/macros
  224. // ============================================================================
  225. /** @addtogroup group_funcmacro_dialog */
  226. //@{
  227. /**
  228. Same as wxGetSingleChoice() but returns the index representing the
  229. selected string. If the user pressed cancel, -1 is returned.
  230. @header{wx/choicdlg.h}
  231. @beginWxPerlOnly
  232. Use an array reference for the @a aChoices parameter.
  233. @endWxPerlOnly
  234. */
  235. int wxGetSingleChoiceIndex(const wxString& message,
  236. const wxString& caption,
  237. const wxArrayString& aChoices,
  238. wxWindow* parent = NULL,
  239. int x = wxDefaultCoord,
  240. int y = wxDefaultCoord,
  241. bool centre = true,
  242. int width = wxCHOICE_WIDTH,
  243. int height = wxCHOICE_HEIGHT,
  244. int initialSelection = 0);
  245. int wxGetSingleChoiceIndex(const wxString& message,
  246. const wxString& caption,
  247. int n,
  248. const wxString& choices[],
  249. wxWindow* parent = NULL,
  250. int x = wxDefaultCoord,
  251. int y = wxDefaultCoord,
  252. bool centre = true,
  253. int width = wxCHOICE_WIDTH,
  254. int height = wxCHOICE_HEIGHT,
  255. int initialSelection = 0);
  256. int wxGetSingleChoiceIndex(const wxString& message,
  257. const wxString& caption,
  258. const wxArrayString& choices,
  259. int initialSelection,
  260. wxWindow *parent = NULL);
  261. int wxGetSingleChoiceIndex(const wxString& message,
  262. const wxString& caption,
  263. int n, const wxString *choices,
  264. int initialSelection,
  265. wxWindow *parent = NULL);
  266. //@}
  267. /** @addtogroup group_funcmacro_dialog */
  268. //@{
  269. /**
  270. Pops up a dialog box containing a message, OK/Cancel buttons and a
  271. single-selection listbox. The user may choose an item and press OK to
  272. return a string or Cancel to return the empty string. Use
  273. wxGetSingleChoiceIndex() if empty string is a valid choice and if you want
  274. to be able to detect pressing Cancel reliably.
  275. You may pass the list of strings to choose from either using @c choices
  276. which is an array of @a n strings for the listbox or by using a single
  277. @c aChoices parameter of type wxArrayString.
  278. If @c centre is @true, the message text (which may include new line
  279. characters) is centred; if @false, the message is left-justified.
  280. @header{wx/choicdlg.h}
  281. @beginWxPerlOnly
  282. Use an array reference for the @a choices parameter.
  283. @endWxPerlOnly
  284. */
  285. wxString wxGetSingleChoice(const wxString& message,
  286. const wxString& caption,
  287. const wxArrayString& aChoices,
  288. wxWindow* parent = NULL,
  289. int x = wxDefaultCoord,
  290. int y = wxDefaultCoord,
  291. bool centre = true,
  292. int width = wxCHOICE_WIDTH,
  293. int height = wxCHOICE_HEIGHT,
  294. int initialSelection = 0);
  295. wxString wxGetSingleChoice(const wxString& message,
  296. const wxString& caption,
  297. int n,
  298. const wxString& choices[],
  299. wxWindow* parent = NULL,
  300. int x = wxDefaultCoord,
  301. int y = wxDefaultCoord,
  302. bool centre = true,
  303. int width = wxCHOICE_WIDTH,
  304. int height = wxCHOICE_HEIGHT,
  305. int initialSelection = 0);
  306. wxString wxGetSingleChoice(const wxString& message,
  307. const wxString& caption,
  308. const wxArrayString& choices,
  309. int initialSelection,
  310. wxWindow *parent = NULL);
  311. wxString wxGetSingleChoice(const wxString& message,
  312. const wxString& caption,
  313. int n, const wxString *choices,
  314. int initialSelection,
  315. wxWindow *parent = NULL);
  316. //@}
  317. /** @addtogroup group_funcmacro_dialog */
  318. //@{
  319. /**
  320. Same as wxGetSingleChoice but takes an array of client data pointers
  321. corresponding to the strings, and returns one of these pointers or @NULL
  322. if Cancel was pressed. The @c client_data array must have the same number
  323. of elements as @c choices or @c aChoices!
  324. @header{wx/choicdlg.h}
  325. @beginWxPerlOnly
  326. Use an array reference for the @a aChoices and @a client_data parameters.
  327. @endWxPerlOnly
  328. */
  329. wxString wxGetSingleChoiceData(const wxString& message,
  330. const wxString& caption,
  331. const wxArrayString& aChoices,
  332. const wxString& client_data[],
  333. wxWindow* parent = NULL,
  334. int x = wxDefaultCoord,
  335. int y = wxDefaultCoord,
  336. bool centre = true,
  337. int width = wxCHOICE_WIDTH,
  338. int height = wxCHOICE_HEIGHT,
  339. int initialSelection = 0);
  340. wxString wxGetSingleChoiceData(const wxString& message,
  341. const wxString& caption,
  342. int n,
  343. const wxString& choices[],
  344. const wxString& client_data[],
  345. wxWindow* parent = NULL,
  346. int x = wxDefaultCoord,
  347. int y = wxDefaultCoord,
  348. bool centre = true,
  349. int width = wxCHOICE_WIDTH,
  350. int height = wxCHOICE_HEIGHT,
  351. int initialSelection = 0);
  352. void* wxGetSingleChoiceData(const wxString& message,
  353. const wxString& caption,
  354. const wxArrayString& choices,
  355. void **client_data,
  356. int initialSelection,
  357. wxWindow *parent = NULL);
  358. void* wxGetSingleChoiceData(const wxString& message,
  359. const wxString& caption,
  360. int n, const wxString *choices,
  361. void **client_data,
  362. int initialSelection,
  363. wxWindow *parent = NULL);
  364. //@}
  365. /** @addtogroup group_funcmacro_dialog */
  366. //@{
  367. /**
  368. Pops up a dialog box containing a message, OK/Cancel buttons and a
  369. multiple-selection listbox. The user may choose an arbitrary (including 0)
  370. number of items in the listbox whose indices will be returned in
  371. @c selections array. The initial contents of this array will be used to
  372. select the items when the dialog is shown. If the user cancels the dialog,
  373. the function returns -1 and @c selections array is left unchanged.
  374. You may pass the list of strings to choose from either using @c choices
  375. which is an array of @a n strings for the listbox or by using a single
  376. @c aChoices parameter of type wxArrayString.
  377. If @c centre is @true, the message text (which may include new line
  378. characters) is centred; if @false, the message is left-justified.
  379. @header{wx/choicdlg.h}
  380. @beginWxPerlOnly
  381. Use an array reference for the @a choices parameter.
  382. In wxPerl there is no @a selections parameter; the function
  383. returns an array containing the user selections.
  384. @endWxPerlOnly
  385. */
  386. int wxGetSelectedChoices(wxArrayInt& selections,
  387. const wxString& message,
  388. const wxString& caption,
  389. const wxArrayString& aChoices,
  390. wxWindow* parent = NULL,
  391. int x = wxDefaultCoord,
  392. int y = wxDefaultCoord,
  393. bool centre = true,
  394. int width = wxCHOICE_WIDTH,
  395. int height = wxCHOICE_HEIGHT);
  396. int wxGetSelectedChoices(wxArrayInt& selections,
  397. const wxString& message,
  398. const wxString& caption,
  399. int n,
  400. const wxString& 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. //@}