msgdlg.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: msgdlg.h
  3. // Purpose: interface of wxMessageDialog
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. Default message box caption string.
  9. */
  10. const char wxMessageBoxCaptionStr[] = "Message";
  11. /**
  12. @class wxMessageDialog
  13. This class represents a dialog that shows a single or multi-line message,
  14. with a choice of OK, Yes, No and Cancel buttons.
  15. @beginStyleTable
  16. @style{wxOK}
  17. Puts an Ok button in the message box. May be combined with @c wxCANCEL.
  18. @style{wxCANCEL}
  19. Puts a Cancel button in the message box. Must be combined with
  20. either @c wxOK or @c wxYES_NO.
  21. @style{wxYES_NO}
  22. Puts Yes and No buttons in the message box. It is recommended to always
  23. use @c wxCANCEL with this style as otherwise the message box won't have
  24. a close button under wxMSW and the user will be forced to answer it.
  25. @style{wxHELP}
  26. Puts a Help button to the message box. This button can have special
  27. appearance or be specially positioned if its label is not changed from
  28. the default one. Notice that using this button is not supported when
  29. showing a message box from non-main thread in wxOSX/Cocoa and it is not
  30. supported in wxOSX/Carbon at all. Available since wxWidgets 2.9.3.
  31. @style{wxNO_DEFAULT}
  32. Makes the "No" button default, can only be used with @c wxYES_NO.
  33. @style{wxCANCEL_DEFAULT}
  34. Makes the "Cancel" button default, can only be used with @c wxCANCEL.
  35. This style is currently not supported (and ignored) in wxOSX.
  36. @style{wxYES_DEFAULT}
  37. Makes the "Yes" button default, this is the default behaviour and
  38. this flag exists solely for symmetry with @c wxNO_DEFAULT.
  39. @style{wxOK_DEFAULT}
  40. Makes the "OK" button default, this is the default behaviour and
  41. this flag exists solely for symmetry with @c wxCANCEL_DEFAULT.
  42. @style{wxICON_NONE}
  43. Displays no icon in the dialog if possible (an icon might still be
  44. displayed if the current platform mandates its use). This style may be
  45. used to prevent the dialog from using the default icon based on @c
  46. wxYES_NO presence as explained in @c wxICON_QUESTION and @c
  47. wxICON_INFORMATION documentation below.
  48. @style{wxICON_EXCLAMATION}
  49. Displays an exclamation, or warning, icon in the dialog.
  50. @style{wxICON_ERROR}
  51. Displays an error icon in the dialog.
  52. @style{wxICON_HAND}
  53. Displays an error symbol, this is a MSW-inspired synonym for @c wxICON_ERROR.
  54. @style{wxICON_QUESTION}
  55. Displays a question mark symbol. This icon is automatically used
  56. with @c wxYES_NO so it's usually unnecessary to specify it explicitly.
  57. This style is not supported for message dialogs under wxMSW when a task
  58. dialog is used to implement them (i.e. when running under Windows Vista
  59. or later) because <a href="http://msdn.microsoft.com/en-us/library/aa511273.aspx">Microsoft
  60. guidelines</a> indicate that no icon should be used for routine
  61. confirmations. If it is specified, no icon will be displayed.
  62. @style{wxICON_INFORMATION}
  63. Displays an information symbol. This icon is used by default if
  64. @c wxYES_NO is not given so it is usually unnecessary to specify it
  65. explicitly.
  66. @style{wxICON_AUTH_NEEDED}
  67. Displays an authentication needed symbol. This style is only supported
  68. for message dialogs under wxMSW when a task dialog is used to implement
  69. them (i.e. when running under Windows Vista or later). In other cases
  70. the default icon selection logic will be used. Note this can be
  71. combined with other styles to provide a fallback. For instance, using
  72. wxICON_AUTH_NEEDED | wxICON_QUESTION will show a shield symbol on
  73. Windows Vista or above and a question symbol on other platforms.
  74. Available since wxWidgets 2.9.5
  75. @style{wxSTAY_ON_TOP}
  76. Makes the message box stay on top of all other windows and not only
  77. just its parent (currently implemented only under MSW and GTK).
  78. @style{wxCENTRE}
  79. Centre the message box on its parent or on the screen if parent is not
  80. specified.
  81. Setting this style under MSW makes no differences as the dialog is
  82. always centered on the parent.
  83. @endStyleTable
  84. @library{wxcore}
  85. @category{cmndlg}
  86. @see @ref overview_cmndlg_msg
  87. @see wxRichMessageDialog
  88. */
  89. class wxMessageDialog : public wxDialog
  90. {
  91. public:
  92. /**
  93. Helper class allowing to use either stock id or string labels.
  94. This class should never be used explicitly and is not really part of
  95. wxWidgets API but rather is just an implementation helper allowing the
  96. methods such as SetYesNoLabels() and SetOKCancelLabels() below to be
  97. callable with either stock ids (e.g. ::wxID_CLOSE) or strings
  98. ("&Close").
  99. */
  100. class ButtonLabel
  101. {
  102. public:
  103. /// Construct the label from a stock id.
  104. ButtonLabel(int stockId);
  105. /// Construct the label from the specified string.
  106. ButtonLabel(const wxString& label);
  107. /**
  108. Return the associated label as string.
  109. Get the string label, whether it was originally specified directly
  110. or as a stock id -- this is only useful for platforms without native
  111. stock items id support
  112. */
  113. wxString GetAsString() const;
  114. /**
  115. Return the stock id or wxID_NONE if this is not a stock label.
  116. */
  117. int GetStockId() const;
  118. };
  119. /**
  120. Constructor specifying the message box properties.
  121. Use ShowModal() to show the dialog.
  122. @a style may be a bit list of the identifiers described above.
  123. Notice that not all styles are compatible: only one of @c wxOK and
  124. @c wxYES_NO may be specified (and one of them must be specified) and at
  125. most one default button style can be used and it is only valid if the
  126. corresponding button is shown in the message box.
  127. @param parent
  128. Parent window.
  129. @param message
  130. Message to show in the dialog.
  131. @param caption
  132. The dialog title.
  133. @param style
  134. Combination of style flags described above.
  135. @param pos
  136. Dialog position (ignored under MSW).
  137. */
  138. wxMessageDialog(wxWindow* parent, const wxString& message,
  139. const wxString& caption = wxMessageBoxCaptionStr,
  140. long style = wxOK | wxCENTRE,
  141. const wxPoint& pos = wxDefaultPosition);
  142. /**
  143. Sets the extended message for the dialog: this message is usually an
  144. extension of the short message specified in the constructor or set with
  145. SetMessage().
  146. If it is set, the main message appears highlighted -- if supported --
  147. and this message appears beneath it in normal font. On the platforms
  148. which don't support extended messages, it is simply appended to the
  149. normal message with an empty line separating them.
  150. @since 2.9.0
  151. */
  152. virtual void SetExtendedMessage(const wxString& extendedMessage);
  153. /**
  154. Sets the label for the Help button.
  155. Please see the remarks in SetYesNoLabels() documentation.
  156. Notice that changing the label of the help button resets its special
  157. status (if any, this depends on the platform) and it will be treated
  158. just like another button in this case.
  159. @since 2.9.3
  160. */
  161. virtual bool SetHelpLabel(const ButtonLabel& help);
  162. /**
  163. Sets the message shown by the dialog.
  164. @since 2.9.0
  165. */
  166. virtual void SetMessage(const wxString& message);
  167. /**
  168. Overrides the default labels of the OK and Cancel buttons.
  169. Please see the remarks in SetYesNoLabels() documentation.
  170. @since 2.9.0
  171. */
  172. virtual bool SetOKCancelLabels(const ButtonLabel& ok,
  173. const ButtonLabel& cancel);
  174. /**
  175. Overrides the default label of the OK button.
  176. Please see the remarks in SetYesNoLabels() documentation.
  177. @since 2.9.0
  178. */
  179. virtual bool SetOKLabel(const ButtonLabel& ok);
  180. /**
  181. Overrides the default labels of the Yes, No and Cancel buttons.
  182. Please see the remarks in SetYesNoLabels() documentation.
  183. @since 2.9.0
  184. */
  185. virtual bool SetYesNoCancelLabels(const ButtonLabel& yes,
  186. const ButtonLabel& no,
  187. const ButtonLabel& cancel);
  188. /**
  189. Overrides the default labels of the Yes and No buttons.
  190. The arguments of this function can be either strings or one of the
  191. standard identifiers, such as @c wxID_APPLY or @c wxID_OPEN. Notice
  192. that even if the label is specified as an identifier, the return value
  193. of the dialog ShowModal() method still remains one of @c wxID_OK, @c
  194. wxID_CANCEL, @c wxID_YES or @c wxID_NO values, i.e. this identifier
  195. changes only the label appearance but not the return code generated by
  196. the button. It is possible to mix stock identifiers and string labels
  197. in the same function call, for example:
  198. @code
  199. wxMessageDialog dlg(...);
  200. dlg.SetYesNoLabels(wxID_SAVE, _("&Don't save"));
  201. @endcode
  202. Also notice that this function is not currently available on all
  203. platforms (although as of wxWidgets 2.9.0 it is implemented in all
  204. major ports), so it may return @false to indicate that the labels
  205. couldn't be changed. If it returns @true, the labels were set
  206. successfully.
  207. Typically, if the function was used successfully, the main dialog
  208. message may need to be changed, e.g.:
  209. @code
  210. wxMessageDialog dlg(...);
  211. if ( dlg.SetYesNoLabels(_("&Quit"), _("&Don't quit")) )
  212. dlg.SetMessage(_("What do you want to do?"));
  213. else // buttons have standard "Yes"/"No" values, so rephrase the question
  214. dlg.SetMessage(_("Do you really want to quit?"));
  215. @endcode
  216. @since 2.9.0
  217. */
  218. virtual bool SetYesNoLabels(const ButtonLabel& yes, const ButtonLabel& no);
  219. /**
  220. Shows the dialog, returning one of wxID_OK, wxID_CANCEL, wxID_YES,
  221. wxID_NO or wxID_HELP.
  222. Notice that this method returns the identifier of the button which was
  223. clicked unlike wxMessageBox() function.
  224. */
  225. virtual int ShowModal();
  226. wxString GetCaption() const;
  227. wxString GetMessage() const;
  228. wxString GetExtendedMessage() const;
  229. long GetMessageDialogStyle() const;
  230. bool HasCustomLabels() const;
  231. wxString GetYesLabel() const;
  232. wxString GetNoLabel() const;
  233. wxString GetOKLabel() const;
  234. wxString GetCancelLabel() const;
  235. wxString GetHelpLabel() const;
  236. long GetEffectiveIcon() const;
  237. };
  238. // ============================================================================
  239. // Global functions/macros
  240. // ============================================================================
  241. /** @addtogroup group_funcmacro_dialog */
  242. //@{
  243. /**
  244. Show a general purpose message dialog.
  245. This is a convenient function which is usually used instead of using
  246. wxMessageDialog directly. Notice however that some of the features, such as
  247. extended text and custom labels for the message box buttons, are not
  248. provided by this function but only by wxMessageDialog.
  249. The return value is one of: @c wxYES, @c wxNO, @c wxCANCEL, @c wxOK or @c
  250. wxHELP (notice that this return value is @b different from the return value
  251. of wxMessageDialog::ShowModal()).
  252. For example:
  253. @code
  254. int answer = wxMessageBox("Quit program?", "Confirm",
  255. wxYES_NO | wxCANCEL, main_frame);
  256. if (answer == wxYES)
  257. main_frame->Close();
  258. @endcode
  259. @a message may contain newline characters, in which case the message will
  260. be split into separate lines, to cater for large messages.
  261. @param message
  262. Message to show in the dialog.
  263. @param caption
  264. The dialog title.
  265. @param parent
  266. Parent window.
  267. @param style
  268. Combination of style flags described in wxMessageDialog documentation.
  269. @param x
  270. Horizontal dialog position (ignored under MSW). Use ::wxDefaultCoord
  271. for @a x and @a y to let the system position the window.
  272. @param y
  273. Vertical dialog position (ignored under MSW).
  274. @header{wx/msgdlg.h}
  275. */
  276. int wxMessageBox(const wxString& message,
  277. const wxString& caption = wxMessageBoxCaptionStr,
  278. int style = wxOK | wxCENTRE,
  279. wxWindow* parent = NULL,
  280. int x = wxDefaultCoord,
  281. int y = wxDefaultCoord);
  282. //@}