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.

259 lines
15KB

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