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.

137 lines
5.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 7 technical preview.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For the technical preview this file cannot be licensed commercially.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. /** The type of icon to show in the dialog box. */
  16. enum class MessageBoxIconType
  17. {
  18. NoIcon, /**< No icon will be shown on the dialog box. */
  19. QuestionIcon, /**< A question-mark icon, for dialog boxes that need the
  20. user to answer a question. */
  21. WarningIcon, /**< An exclamation mark to indicate that the dialog is a
  22. warning about something and shouldn't be ignored. */
  23. InfoIcon /**< An icon that indicates that the dialog box is just
  24. giving the user some information, which doesn't require
  25. a response from them. */
  26. };
  27. //==============================================================================
  28. /** Class used to create a set of options to pass to the AlertWindow and NativeMessageBox
  29. methods for showing dialog boxes.
  30. You can chain together a series of calls to this class's methods to create
  31. a set of whatever options you want to specify.
  32. E.g. @code
  33. AlertWindow::showAsync (MessageBoxOptions()
  34. .withIconType (MessageBoxIconType::InfoIcon)
  35. .withTitle ("A Title")
  36. .withMessage ("A message.")
  37. .withButton ("OK")
  38. .withButton ("Cancel")
  39. .withAssociatedComponent (myComp),
  40. myCallback);
  41. @endcode
  42. @tags{GUI}
  43. */
  44. class JUCE_API MessageBoxOptions
  45. {
  46. public:
  47. MessageBoxOptions() = default;
  48. MessageBoxOptions (const MessageBoxOptions&) = default;
  49. MessageBoxOptions& operator= (const MessageBoxOptions&) = default;
  50. //==============================================================================
  51. /** Sets the type of icon that should be used for the dialog box. */
  52. JUCE_NODISCARD MessageBoxOptions withIconType (MessageBoxIconType type) const { return with (*this, &MessageBoxOptions::iconType, type); }
  53. /** Sets the title of the dialog box. */
  54. JUCE_NODISCARD MessageBoxOptions withTitle (const String& boxTitle) const { return with (*this, &MessageBoxOptions::title, boxTitle); }
  55. /** Sets the message that should be displayed in the dialog box. */
  56. JUCE_NODISCARD MessageBoxOptions withMessage (const String& boxMessage) const { return with (*this, &MessageBoxOptions::message, boxMessage); }
  57. /** If the string passed in is not empty, this will add a button to the
  58. dialog box with the specified text.
  59. Generally up to 3 buttons are supported for dialog boxes, so adding any more
  60. than this may have no effect.
  61. */
  62. JUCE_NODISCARD MessageBoxOptions withButton (const String& text) const { auto copy = *this; copy.buttons.add (text); return copy; }
  63. /** The component that the dialog box should be associated with. */
  64. JUCE_NODISCARD MessageBoxOptions withAssociatedComponent (Component* component) const { return with (*this, &MessageBoxOptions::associatedComponent, component); }
  65. //==============================================================================
  66. /** Returns the icon type of the dialog box.
  67. @see withIconType
  68. */
  69. MessageBoxIconType getIconType() const noexcept { return iconType; }
  70. /** Returns the title of the dialog box.
  71. @see withTitle
  72. */
  73. String getTitle() const { return title; }
  74. /** Returns the message of the dialog box.
  75. @see withMessage
  76. */
  77. String getMessage() const { return message; }
  78. /** Returns the number of buttons that have been added to the dialog box.
  79. @see withButtonText
  80. */
  81. int getNumButtons() const noexcept { return buttons.size(); }
  82. /** Returns the text that has been set for one of the buttons of the dialog box.
  83. @see withButtonText, getNumButtons
  84. */
  85. String getButtonText (int buttonIndex) const { return buttons[buttonIndex]; }
  86. /** Returns the component that the dialog box is associated with.
  87. @see withAssociatedComponent
  88. */
  89. Component* getAssociatedComponent() const noexcept { return associatedComponent; }
  90. private:
  91. //==============================================================================
  92. template <typename Member, typename Item>
  93. static MessageBoxOptions with (MessageBoxOptions options, Member&& member, Item&& item)
  94. {
  95. options.*member = std::forward<Item> (item);
  96. return options;
  97. }
  98. //==============================================================================
  99. MessageBoxIconType iconType = MessageBoxIconType::InfoIcon;
  100. String title, message;
  101. StringArray buttons;
  102. WeakReference<Component> associatedComponent;
  103. };
  104. } // namespace juce