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.

223 lines
13KB

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