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.

215 lines
12KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - 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 this technical preview, this file is not subject to commercial licensing.
  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. /** Shows a dialog box that just has a message and a single 'ok' button to close it.
  24. The box is shown modally, and the method will block until the user has clicked its
  25. button (or pressed the escape or return keys).
  26. @param iconType the type of icon to show
  27. @param title the headline to show at the top of the box
  28. @param message a longer, more descriptive message to show underneath the title
  29. @param associatedComponent if this is non-null, it specifies the component that the
  30. alert window should be associated with. Depending on the look
  31. and feel, this might be used for positioning of the alert window.
  32. */
  33. #if JUCE_MODAL_LOOPS_PERMITTED
  34. static void JUCE_CALLTYPE showMessageBox (AlertWindow::AlertIconType iconType,
  35. const String& title,
  36. const String& message,
  37. Component* associatedComponent = nullptr);
  38. #endif
  39. /** Shows a dialog box that just has a message and a single 'ok' button to close it.
  40. The box will be displayed and placed into a modal state, but this method will return
  41. immediately, and the callback will be invoked later when the user dismisses the box.
  42. @param iconType the type of icon to show
  43. @param title the headline to show at the top of the box
  44. @param message a longer, more descriptive message to show underneath the title
  45. @param associatedComponent if this is non-null, it specifies the component that the
  46. alert window should be associated with. Depending on the look
  47. and feel, this might be used for positioning of the alert window.
  48. @param callback if this is non-null, the callback will receive a call to its
  49. modalStateFinished() when the box is dismissed. The callback object
  50. will be owned and deleted by the system, so make sure that it works
  51. safely and doesn't keep any references to objects that might be deleted
  52. before it gets called. You can use the ModalCallbackFunction to easily
  53. pass in a lambda for this parameter.
  54. @see ModalCallbackFunction
  55. */
  56. static void JUCE_CALLTYPE showMessageBoxAsync (AlertWindow::AlertIconType iconType,
  57. const String& title,
  58. const String& message,
  59. Component* associatedComponent = nullptr,
  60. ModalComponentManager::Callback* callback = nullptr);
  61. /** Shows a dialog box with two buttons.
  62. Ideal for ok/cancel or yes/no choices. The return key can also be used
  63. to trigger the first button, and the escape key for the second button.
  64. If the callback parameter is null, the box is shown modally, and the method will
  65. block until the user has clicked the button (or pressed the escape or return keys).
  66. If the callback parameter is non-null, the box will be displayed and placed into a
  67. modal state, but this method will return immediately, and the callback will be invoked
  68. later when the user dismisses the box.
  69. @param iconType the type of icon to show
  70. @param title the headline to show at the top of the box
  71. @param message a longer, more descriptive message to show underneath the title
  72. @param associatedComponent if this is non-null, it specifies the component that the
  73. alert window should be associated with. Depending on the look
  74. and feel, this might be used for positioning of the alert window.
  75. @param callback if this is non-null, the box will be launched asynchronously,
  76. returning immediately, and the callback will receive a call to its
  77. modalStateFinished() when the box is dismissed, with its parameter
  78. being 1 if the ok button was pressed, or 0 for cancel, The callback object
  79. will be owned and deleted by the system, so make sure that it works
  80. safely and doesn't keep any references to objects that might be deleted
  81. before it gets called. You can use the ModalCallbackFunction to easily
  82. pass in a lambda for this parameter.
  83. @returns true if button 1 was clicked, false if it was button 2. If the callback parameter
  84. is not null, the method always returns false, and the user's choice is delivered
  85. later by the callback.
  86. @see ModalCallbackFunction
  87. */
  88. static bool JUCE_CALLTYPE showOkCancelBox (AlertWindow::AlertIconType iconType,
  89. const String& title,
  90. const String& message,
  91. #if JUCE_MODAL_LOOPS_PERMITTED
  92. Component* associatedComponent = nullptr,
  93. ModalComponentManager::Callback* callback = nullptr);
  94. #else
  95. Component* associatedComponent,
  96. ModalComponentManager::Callback* callback);
  97. #endif
  98. /** Shows a dialog box with three buttons.
  99. Ideal for yes/no/cancel boxes.
  100. The escape key can be used to trigger the third button.
  101. If the callback parameter is null, the box is shown modally, and the method will
  102. block until the user has clicked the button (or pressed the escape or return keys).
  103. If the callback parameter is non-null, the box will be displayed and placed into a
  104. modal state, but this method will return immediately, and the callback will be invoked
  105. later when the user dismisses the box.
  106. @param iconType the type of icon to show
  107. @param title the headline to show at the top of the box
  108. @param message a longer, more descriptive message to show underneath the title
  109. @param associatedComponent if this is non-null, it specifies the component that the
  110. alert window should be associated with. Depending on the look
  111. and feel, this might be used for positioning of the alert window.
  112. @param callback if this is non-null, the box will be launched asynchronously,
  113. returning immediately, and the callback will receive a call to its
  114. modalStateFinished() when the box is dismissed, with its parameter
  115. being 1 if the "yes" button was pressed, 2 for the "no" button, or 0
  116. if it was cancelled, The callback object will be owned and deleted by the
  117. system, so make sure that it works safely and doesn't keep any references
  118. to objects that might be deleted before it gets called. You can use the
  119. ModalCallbackFunction to easily pass in a lambda for this parameter.
  120. @returns If the callback parameter has been set, this returns 0. Otherwise, it returns one
  121. of the following values:
  122. - 0 if 'cancel' was pressed
  123. - 1 if 'yes' was pressed
  124. - 2 if 'no' was pressed
  125. @see ModalCallbackFunction
  126. */
  127. static int JUCE_CALLTYPE showYesNoCancelBox (AlertWindow::AlertIconType iconType,
  128. const String& title,
  129. const String& message,
  130. #if JUCE_MODAL_LOOPS_PERMITTED
  131. Component* associatedComponent = nullptr,
  132. ModalComponentManager::Callback* callback = nullptr);
  133. #else
  134. Component* associatedComponent,
  135. ModalComponentManager::Callback* callback);
  136. #endif
  137. /** Shows a dialog box with two buttons.
  138. Ideal for yes/no boxes.
  139. The escape key can be used to trigger the no button.
  140. If the callback parameter is null, the box is shown modally, and the method will
  141. block until the user has clicked the button (or pressed the escape or return keys).
  142. If the callback parameter is non-null, the box will be displayed and placed into a
  143. modal state, but this method will return immediately, and the callback will be invoked
  144. later when the user dismisses the box.
  145. @param iconType the type of icon to show
  146. @param title the headline to show at the top of the box
  147. @param message a longer, more descriptive message to show underneath the title
  148. @param associatedComponent if this is non-null, it specifies the component that the
  149. alert window should be associated with. Depending on the look
  150. and feel, this might be used for positioning of the alert window.
  151. @param callback if this is non-null, the box will be launched asynchronously,
  152. returning immediately, and the callback will receive a call to its
  153. modalStateFinished() when the box is dismissed, with its parameter
  154. being 1 if the "yes" button was pressed or 0 for the "no" button was
  155. pressed. The callback object will be owned and deleted by the
  156. system, so make sure that it works safely and doesn't keep any references
  157. to objects that might be deleted before it gets called. You can use the
  158. ModalCallbackFunction to easily pass in a lambda for this parameter.
  159. @returns If the callback parameter has been set, this returns 0. Otherwise, it returns one
  160. of the following values:
  161. - 0 if 'no' was pressed
  162. - 1 if 'yes' was pressed
  163. @see ModalCallbackFunction
  164. */
  165. static int JUCE_CALLTYPE showYesNoBox (AlertWindow::AlertIconType iconType,
  166. const String& title,
  167. const String& message,
  168. #if JUCE_MODAL_LOOPS_PERMITTED
  169. Component* associatedComponent = nullptr,
  170. ModalComponentManager::Callback* callback = nullptr);
  171. #else
  172. Component* associatedComponent,
  173. ModalComponentManager::Callback* callback);
  174. #endif
  175. private:
  176. NativeMessageBox() = delete;
  177. JUCE_DECLARE_NON_COPYABLE (NativeMessageBox)
  178. };
  179. } // namespace juce