The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

239 lines
14KB

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