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.

206 lines
12KB

  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. #pragma once
  20. //==============================================================================
  21. /**
  22. This class contains some static methods for showing native alert windows.
  23. */
  24. class NativeMessageBox
  25. {
  26. public:
  27. /** Shows a dialog box that just has a message and a single 'ok' button to close it.
  28. The box is shown modally, and the method will block until the user has clicked its
  29. button (or pressed the escape or return keys).
  30. @param iconType the type of icon to show
  31. @param title the headline to show at the top of the box
  32. @param message a longer, more descriptive message to show underneath the title
  33. @param associatedComponent if this is non-null, it specifies the component that the
  34. alert window should be associated with. Depending on the look
  35. and feel, this might be used for positioning of the alert window.
  36. */
  37. #if JUCE_MODAL_LOOPS_PERMITTED
  38. static void JUCE_CALLTYPE showMessageBox (AlertWindow::AlertIconType iconType,
  39. const String& title,
  40. const String& message,
  41. Component* associatedComponent = nullptr);
  42. #endif
  43. /** Shows a dialog box that just has a message and a single 'ok' button to close it.
  44. The box will be displayed and placed into a modal state, but this method will return
  45. immediately, and the callback will be invoked later when the user dismisses the box.
  46. @param iconType the type of icon to show
  47. @param title the headline to show at the top of the box
  48. @param message a longer, more descriptive message to show underneath the title
  49. @param associatedComponent if this is non-null, it specifies the component that the
  50. alert window should be associated with. Depending on the look
  51. and feel, this might be used for positioning of the alert window.
  52. @param callback if this is non-null, the callback will receive a call to its
  53. modalStateFinished() when the box is dismissed. The callback object
  54. will be owned and deleted by the system, so make sure that it works
  55. safely and doesn't keep any references to objects that might be deleted
  56. before it gets called.
  57. */
  58. static void JUCE_CALLTYPE showMessageBoxAsync (AlertWindow::AlertIconType iconType,
  59. const String& title,
  60. const String& message,
  61. Component* associatedComponent = nullptr,
  62. ModalComponentManager::Callback* callback = nullptr);
  63. /** Shows a dialog box with two buttons.
  64. Ideal for ok/cancel or yes/no choices. The return key can also be used
  65. to trigger the first button, and the escape key for the second button.
  66. If the callback parameter is null, the box is shown modally, and the method will
  67. block until the user has clicked the button (or pressed the escape or return keys).
  68. If the callback parameter is non-null, the box will be displayed and placed into a
  69. modal state, but this method will return immediately, and the callback will be invoked
  70. later when the user dismisses the box.
  71. @param iconType the type of icon to show
  72. @param title the headline to show at the top of the box
  73. @param message a longer, more descriptive message to show underneath the title
  74. @param associatedComponent if this is non-null, it specifies the component that the
  75. alert window should be associated with. Depending on the look
  76. and feel, this might be used for positioning of the alert window.
  77. @param callback if this is non-null, the box will be launched asynchronously,
  78. returning immediately, and the callback will receive a call to its
  79. modalStateFinished() when the box is dismissed, with its parameter
  80. being 1 if the ok button was pressed, or 0 for cancel, 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. @returns true if button 1 was clicked, false if it was button 2. If the callback parameter
  85. is not null, the method always returns false, and the user's choice is delivered
  86. later by the callback.
  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.
  119. @returns If the callback parameter has been set, this returns 0. Otherwise, it returns one
  120. of the following values:
  121. - 0 if 'cancel' was pressed
  122. - 1 if 'yes' was pressed
  123. - 2 if 'no' was pressed
  124. */
  125. static int JUCE_CALLTYPE showYesNoCancelBox (AlertWindow::AlertIconType iconType,
  126. const String& title,
  127. const String& message,
  128. #if JUCE_MODAL_LOOPS_PERMITTED
  129. Component* associatedComponent = nullptr,
  130. ModalComponentManager::Callback* callback = nullptr);
  131. #else
  132. Component* associatedComponent,
  133. ModalComponentManager::Callback* callback);
  134. #endif
  135. /** Shows a dialog box with two buttons.
  136. Ideal for yes/no boxes.
  137. The escape key can be used to trigger the no button.
  138. If the callback parameter is null, the box is shown modally, and the method will
  139. block until the user has clicked the button (or pressed the escape or return keys).
  140. If the callback parameter is non-null, the box will be displayed and placed into a
  141. modal state, but this method will return immediately, and the callback will be invoked
  142. later when the user dismisses the box.
  143. @param iconType the type of icon to show
  144. @param title the headline to show at the top of the box
  145. @param message a longer, more descriptive message to show underneath the title
  146. @param associatedComponent if this is non-null, it specifies the component that the
  147. alert window should be associated with. Depending on the look
  148. and feel, this might be used for positioning of the alert window.
  149. @param callback if this is non-null, the box will be launched asynchronously,
  150. returning immediately, and the callback will receive a call to its
  151. modalStateFinished() when the box is dismissed, with its parameter
  152. being 1 if the "yes" button was pressed or 0 for the "no" button was
  153. pressed. The callback object will be owned and deleted by the
  154. system, so make sure that it works safely and doesn't keep any references
  155. to objects that might be deleted before it gets called.
  156. @returns If the callback parameter has been set, this returns 0. Otherwise, it returns one
  157. of the following values:
  158. - 0 if 'no' was pressed
  159. - 1 if 'yes' was pressed
  160. */
  161. static int JUCE_CALLTYPE showYesNoBox (AlertWindow::AlertIconType iconType,
  162. const String& title,
  163. const String& message,
  164. #if JUCE_MODAL_LOOPS_PERMITTED
  165. Component* associatedComponent = nullptr,
  166. ModalComponentManager::Callback* callback = nullptr);
  167. #else
  168. Component* associatedComponent,
  169. ModalComponentManager::Callback* callback);
  170. #endif
  171. private:
  172. NativeMessageBox() JUCE_DELETED_FUNCTION;
  173. JUCE_DECLARE_NON_COPYABLE (NativeMessageBox)
  174. };