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.

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