Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

juce_NativeMessageBox.h 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. This class contains some static methods for showing native alert windows.
  23. @tags{GUI}
  24. */
  25. class NativeMessageBox
  26. {
  27. public:
  28. #if JUCE_MODAL_LOOPS_PERMITTED
  29. /** Shows a dialog box that just has a message and a single 'ok' button to close it.
  30. The box is shown modally, and the method will block until the user has clicked its
  31. button (or pressed the escape or return keys).
  32. @param iconType the type of icon to show.
  33. @param title the headline to show at the top of the box.
  34. @param message a longer, more descriptive message to show underneath the title.
  35. @param associatedComponent if this is non-null, it specifies the component that the
  36. alert window should be associated with. Depending on the look
  37. and feel, this might be used for positioning of the alert window.
  38. */
  39. static void JUCE_CALLTYPE showMessageBox (MessageBoxIconType iconType,
  40. const String& title,
  41. const String& message,
  42. Component* associatedComponent = nullptr);
  43. /** Shows a dialog box using the specified options.
  44. The box is shown modally, and the method will block until the user dismisses it.
  45. @param options the options to use when creating the dialog.
  46. @returns the index of the button that was clicked.
  47. @see MessageBoxOptions
  48. */
  49. static int JUCE_CALLTYPE show (const MessageBoxOptions& options);
  50. #endif
  51. /** Shows a dialog box using the specified options.
  52. The box will be displayed and placed into a modal state, but this method will return
  53. immediately, and the callback will be invoked later when the user dismisses the box.
  54. @param options the options to use when creating the dialog.
  55. @param callback if this is non-null, the callback will receive a call to its
  56. modalStateFinished() when the box is dismissed with the index of the
  57. button that was clicked as its argument.
  58. The callback object will be owned and deleted by the system, so make sure
  59. that it works safely and doesn't keep any references to objects that might
  60. be deleted before it gets called.
  61. @see MessageBoxOptions
  62. */
  63. static void JUCE_CALLTYPE showAsync (const MessageBoxOptions& options,
  64. ModalComponentManager::Callback* callback);
  65. /** Shows a dialog box using the specified options.
  66. The box will be displayed and placed into a modal state, but this method will return
  67. immediately, and the callback will be invoked later when the user dismisses the box.
  68. @param options the options to use when creating the dialog.
  69. @param callback if this is non-null, the callback will be called when the box is
  70. dismissed with the index of the button that was clicked as its argument.
  71. @see MessageBoxOptions
  72. */
  73. static void JUCE_CALLTYPE showAsync (const MessageBoxOptions& options,
  74. std::function<void (int)> callback);
  75. /** Shows a dialog box that just has a message and a single 'ok' button to close it.
  76. The box will be displayed and placed into a modal state, but this method will return
  77. immediately, and the callback will be invoked later when the user dismisses the box.
  78. @param iconType the type of icon to show.
  79. @param title the headline to show at the top of the box.
  80. @param message a longer, more descriptive message to show underneath the title.
  81. @param associatedComponent if this is non-null, it specifies the component that the
  82. alert window should be associated with. Depending on the look
  83. and feel, this might be used for positioning of the alert window.
  84. @param callback if this is non-null, the callback will receive a call to its
  85. modalStateFinished() when the box is dismissed. The callback object
  86. will be owned and deleted by the system, so make sure that it works
  87. safely and doesn't keep any references to objects that might be deleted
  88. before it gets called. You can use the ModalCallbackFunction to easily
  89. pass in a lambda for this parameter.
  90. @see ModalCallbackFunction
  91. */
  92. static void JUCE_CALLTYPE showMessageBoxAsync (MessageBoxIconType iconType,
  93. const String& title,
  94. const String& message,
  95. Component* associatedComponent = nullptr,
  96. ModalComponentManager::Callback* callback = nullptr);
  97. /** Shows a dialog box with two buttons.
  98. Ideal for ok/cancel or yes/no choices. The return key can also be used
  99. to trigger the first button, and the escape key for the second button.
  100. If the callback parameter is null and modal loops are enabled, the box is shown modally,
  101. and the method will block until the user has clicked the button (or pressed the escape or
  102. return keys). If the callback parameter is non-null, the box will be displayed and placed
  103. into a modal state, but this method will return immediately, and the callback will be invoked
  104. later when the user dismisses the box.
  105. @param iconType the type of icon to show.
  106. @param title the headline to show at the top of the box.
  107. @param message a longer, more descriptive message to show underneath the title.
  108. @param associatedComponent if this is non-null, it specifies the component that the
  109. alert window should be associated with. Depending on the look
  110. and feel, this might be used for positioning of the alert window.
  111. @param callback if this is non-null, the box will be launched asynchronously,
  112. returning immediately, and the callback will receive a call to its
  113. modalStateFinished() when the box is dismissed, with its parameter
  114. being 1 if the ok button was pressed, or 0 for cancel, The callback object
  115. will be owned and deleted by the system, so make sure that it works
  116. safely and doesn't keep any references to objects that might be deleted
  117. before it gets called. You can use the ModalCallbackFunction to easily
  118. pass in a lambda for this parameter.
  119. @returns true if button 1 was clicked, false if it was button 2. If the callback parameter
  120. is not null, the method always returns false, and the user's choice is delivered
  121. later by the callback.
  122. @see ModalCallbackFunction
  123. */
  124. static bool JUCE_CALLTYPE showOkCancelBox (MessageBoxIconType iconType,
  125. const String& title,
  126. const String& message,
  127. #if JUCE_MODAL_LOOPS_PERMITTED
  128. Component* associatedComponent = nullptr,
  129. ModalComponentManager::Callback* callback = nullptr);
  130. #else
  131. Component* associatedComponent,
  132. ModalComponentManager::Callback* callback);
  133. #endif
  134. /** Shows a dialog box with three buttons.
  135. Ideal for yes/no/cancel boxes.
  136. The escape key can be used to trigger the third button.
  137. If the callback parameter is null and modal loops are enabled, the box is shown modally,
  138. and the method will block until the user has clicked the button (or pressed the escape or
  139. return keys). If the callback parameter is non-null, the box will be displayed and placed
  140. into a modal state, but this method will return immediately, and the callback will be invoked
  141. later when the user dismisses the box.
  142. @param iconType the type of icon to show.
  143. @param title the headline to show at the top of the box.
  144. @param message a longer, more descriptive message to show underneath the title.
  145. @param associatedComponent if this is non-null, it specifies the component that the
  146. alert window should be associated with. Depending on the look
  147. and feel, this might be used for positioning of the alert window.
  148. @param callback if this is non-null, the box will be launched asynchronously,
  149. returning immediately, and the callback will receive a call to its
  150. modalStateFinished() when the box is dismissed, with its parameter
  151. being 1 if the "yes" button was pressed, 2 for the "no" button, or 0
  152. if it was cancelled, The callback object will be owned and deleted by the
  153. system, so make sure that it works safely and doesn't keep any references
  154. to objects that might be deleted before it gets called. You can use the
  155. ModalCallbackFunction to easily pass in a lambda for this parameter.
  156. @returns If the callback parameter has been set, this returns 0. Otherwise, it returns one
  157. of the following values:
  158. - 0 if 'cancel' was pressed
  159. - 1 if 'yes' was pressed
  160. - 2 if 'no' was pressed
  161. @see ModalCallbackFunction
  162. */
  163. static int JUCE_CALLTYPE showYesNoCancelBox (MessageBoxIconType iconType,
  164. const String& title,
  165. const String& message,
  166. #if JUCE_MODAL_LOOPS_PERMITTED
  167. Component* associatedComponent = nullptr,
  168. ModalComponentManager::Callback* callback = nullptr);
  169. #else
  170. Component* associatedComponent,
  171. ModalComponentManager::Callback* callback);
  172. #endif
  173. /** Shows a dialog box with two buttons.
  174. Ideal for yes/no boxes.
  175. The escape key can be used to trigger the no button.
  176. If the callback parameter is null and modal loops are enabled, the box is shown modally,
  177. and the method will block until the user has clicked the button (or pressed the escape or
  178. return keys). If the callback parameter is non-null, the box will be displayed and placed
  179. into a modal state, but this method will return immediately, and the callback will be invoked
  180. later when the user dismisses the box.
  181. @param iconType the type of icon to show.
  182. @param title the headline to show at the top of the box.
  183. @param message a longer, more descriptive message to show underneath the title.
  184. @param associatedComponent if this is non-null, it specifies the component that the
  185. alert window should be associated with. Depending on the look
  186. and feel, this might be used for positioning of the alert window.
  187. @param callback if this is non-null, the box will be launched asynchronously,
  188. returning immediately, and the callback will receive a call to its
  189. modalStateFinished() when the box is dismissed, with its parameter
  190. being 1 if the "yes" button was pressed or 0 for the "no" button was
  191. pressed. The callback object will be owned and deleted by the
  192. system, so make sure that it works safely and doesn't keep any references
  193. to objects that might be deleted before it gets called. You can use the
  194. ModalCallbackFunction to easily pass in a lambda for this parameter.
  195. @returns If the callback parameter has been set, this returns 0. Otherwise, it returns one
  196. of the following values:
  197. - 0 if 'no' was pressed
  198. - 1 if 'yes' was pressed
  199. @see ModalCallbackFunction
  200. */
  201. static int JUCE_CALLTYPE showYesNoBox (MessageBoxIconType iconType,
  202. const String& title,
  203. const String& message,
  204. #if JUCE_MODAL_LOOPS_PERMITTED
  205. Component* associatedComponent = nullptr,
  206. ModalComponentManager::Callback* callback = nullptr);
  207. #else
  208. Component* associatedComponent,
  209. ModalComponentManager::Callback* callback);
  210. #endif
  211. private:
  212. NativeMessageBox() = delete;
  213. JUCE_DECLARE_NON_COPYABLE (NativeMessageBox)
  214. };
  215. } // namespace juce