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.

194 lines
8.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. /** The type of icon to show in the dialog box. */
  21. enum class MessageBoxIconType
  22. {
  23. NoIcon, /**< No icon will be shown on the dialog box. */
  24. QuestionIcon, /**< A question-mark icon, for dialog boxes that need the
  25. user to answer a question. */
  26. WarningIcon, /**< An exclamation mark to indicate that the dialog is a
  27. warning about something and shouldn't be ignored. */
  28. InfoIcon /**< An icon that indicates that the dialog box is just
  29. giving the user some information, which doesn't require
  30. a response from them. */
  31. };
  32. //==============================================================================
  33. /** Class used to create a set of options to pass to the AlertWindow and NativeMessageBox
  34. methods for showing dialog boxes.
  35. You can chain together a series of calls to this class's methods to create
  36. a set of whatever options you want to specify.
  37. E.g. @code
  38. AlertWindow::showAsync (MessageBoxOptions()
  39. .withIconType (MessageBoxIconType::InfoIcon)
  40. .withTitle ("A Title")
  41. .withMessage ("A message.")
  42. .withButton ("OK")
  43. .withButton ("Cancel")
  44. .withAssociatedComponent (myComp),
  45. myCallback);
  46. @endcode
  47. @tags{GUI}
  48. */
  49. class JUCE_API MessageBoxOptions
  50. {
  51. public:
  52. MessageBoxOptions() = default;
  53. MessageBoxOptions (const MessageBoxOptions&) = default;
  54. MessageBoxOptions& operator= (const MessageBoxOptions&) = default;
  55. //==============================================================================
  56. /** Sets the type of icon that should be used for the dialog box. */
  57. [[nodiscard]] MessageBoxOptions withIconType (MessageBoxIconType type) const { return withMember (*this, &MessageBoxOptions::iconType, type); }
  58. /** Sets the title of the dialog box. */
  59. [[nodiscard]] MessageBoxOptions withTitle (const String& boxTitle) const { return withMember (*this, &MessageBoxOptions::title, boxTitle); }
  60. /** Sets the message that should be displayed in the dialog box. */
  61. [[nodiscard]] MessageBoxOptions withMessage (const String& boxMessage) const { return withMember (*this, &MessageBoxOptions::message, boxMessage); }
  62. /** If the string passed in is not empty, this will add a button to the
  63. dialog box with the specified text.
  64. Generally up to 3 buttons are supported for dialog boxes, so adding any more
  65. than this may have no effect.
  66. */
  67. [[nodiscard]] MessageBoxOptions withButton (const String& text) const { auto copy = *this; copy.buttons.add (text); return copy; }
  68. /** The component that the dialog box should be associated with. */
  69. [[nodiscard]] MessageBoxOptions withAssociatedComponent (Component* component) const { return withMember (*this, &MessageBoxOptions::associatedComponent, component); }
  70. /** The component that will contain the message box (e.g. the AudioProcessorEditor in a plugin).
  71. This will only affect JUCE AlertWindows. It won't affect the drawing of native message boxes.
  72. This is mainly intended for use in AU plugins, where opening additional windows can be problematic.
  73. */
  74. [[nodiscard]] MessageBoxOptions withParentComponent (Component* component) const { return withMember (*this, &MessageBoxOptions::parentComponent, component); }
  75. //==============================================================================
  76. /** Returns the icon type of the dialog box.
  77. @see withIconType
  78. */
  79. MessageBoxIconType getIconType() const noexcept { return iconType; }
  80. /** Returns the title of the dialog box.
  81. @see withTitle
  82. */
  83. String getTitle() const { return title; }
  84. /** Returns the message of the dialog box.
  85. @see withMessage
  86. */
  87. String getMessage() const { return message; }
  88. /** Returns the number of buttons that have been added to the dialog box.
  89. @see withButtonText
  90. */
  91. int getNumButtons() const noexcept { return buttons.size(); }
  92. /** Returns the text that has been set for one of the buttons of the dialog box.
  93. @see withButtonText, getNumButtons
  94. */
  95. String getButtonText (int buttonIndex) const { return buttons[buttonIndex]; }
  96. /** Returns the component that the dialog box is associated with.
  97. @see withAssociatedComponent
  98. */
  99. Component* getAssociatedComponent() const noexcept { return associatedComponent; }
  100. /** Returns the component that will be used as the parent of the dialog box.
  101. @see withParentComponent
  102. */
  103. Component* getParentComponent() const noexcept { return parentComponent; }
  104. /** Creates options suitable for a message box with a single button.
  105. If no button text is supplied, "OK" will be used.
  106. */
  107. static MessageBoxOptions makeOptionsOk (MessageBoxIconType iconType,
  108. const String& title,
  109. const String& message,
  110. const String& buttonText = String(),
  111. Component* associatedComponent = nullptr);
  112. /** Creates options suitable for a message box with two buttons.
  113. If no button text is supplied, "OK" and "Cancel" will be used.
  114. */
  115. static MessageBoxOptions makeOptionsOkCancel (MessageBoxIconType iconType,
  116. const String& title,
  117. const String& message,
  118. const String& button1Text = String(),
  119. const String& button2Text = String(),
  120. Component* associatedComponent = nullptr);
  121. /** Creates options suitable for a message box with two buttons.
  122. If no button text is supplied, "Yes" and "No" will be used.
  123. */
  124. static MessageBoxOptions makeOptionsYesNo (MessageBoxIconType iconType,
  125. const String& title,
  126. const String& message,
  127. const String& button1Text = String(),
  128. const String& button2Text = String(),
  129. Component* associatedComponent = nullptr);
  130. /** Creates options suitable for a message box with three buttons.
  131. *
  132. If no button text is supplied, "Yes", "No", and "Cancel" will be used.
  133. */
  134. static MessageBoxOptions makeOptionsYesNoCancel (MessageBoxIconType iconType,
  135. const String& title,
  136. const String& message,
  137. const String& button1Text = String(),
  138. const String& button2Text = String(),
  139. const String& button3Text = String(),
  140. Component* associatedComponent = nullptr);
  141. private:
  142. //==============================================================================
  143. MessageBoxIconType iconType = MessageBoxIconType::InfoIcon;
  144. String title, message;
  145. StringArray buttons;
  146. WeakReference<Component> associatedComponent;
  147. WeakReference<Component> parentComponent;
  148. };
  149. } // namespace juce