Audio plugin host https://kx.studio/carla
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.

144 lines
5.8KB

  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. JUCE_NODISCARD MessageBoxOptions withIconType (MessageBoxIconType type) const { return with (*this, &MessageBoxOptions::iconType, type); }
  58. /** Sets the title of the dialog box. */
  59. JUCE_NODISCARD MessageBoxOptions withTitle (const String& boxTitle) const { return with (*this, &MessageBoxOptions::title, boxTitle); }
  60. /** Sets the message that should be displayed in the dialog box. */
  61. JUCE_NODISCARD MessageBoxOptions withMessage (const String& boxMessage) const { return with (*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. JUCE_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. JUCE_NODISCARD MessageBoxOptions withAssociatedComponent (Component* component) const { return with (*this, &MessageBoxOptions::associatedComponent, component); }
  70. //==============================================================================
  71. /** Returns the icon type of the dialog box.
  72. @see withIconType
  73. */
  74. MessageBoxIconType getIconType() const noexcept { return iconType; }
  75. /** Returns the title of the dialog box.
  76. @see withTitle
  77. */
  78. String getTitle() const { return title; }
  79. /** Returns the message of the dialog box.
  80. @see withMessage
  81. */
  82. String getMessage() const { return message; }
  83. /** Returns the number of buttons that have been added to the dialog box.
  84. @see withButtonText
  85. */
  86. int getNumButtons() const noexcept { return buttons.size(); }
  87. /** Returns the text that has been set for one of the buttons of the dialog box.
  88. @see withButtonText, getNumButtons
  89. */
  90. String getButtonText (int buttonIndex) const { return buttons[buttonIndex]; }
  91. /** Returns the component that the dialog box is associated with.
  92. @see withAssociatedComponent
  93. */
  94. Component* getAssociatedComponent() const noexcept { return associatedComponent; }
  95. private:
  96. //==============================================================================
  97. template <typename Member, typename Item>
  98. static MessageBoxOptions with (MessageBoxOptions options, Member&& member, Item&& item)
  99. {
  100. options.*member = std::forward<Item> (item);
  101. return options;
  102. }
  103. //==============================================================================
  104. MessageBoxIconType iconType = MessageBoxIconType::InfoIcon;
  105. String title, message;
  106. StringArray buttons;
  107. WeakReference<Component> associatedComponent;
  108. };
  109. } // namespace juce