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.

142 lines
5.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - 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 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-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. */
  48. class JUCE_API MessageBoxOptions
  49. {
  50. public:
  51. MessageBoxOptions() = default;
  52. MessageBoxOptions (const MessageBoxOptions&) = default;
  53. MessageBoxOptions& operator= (const MessageBoxOptions&) = default;
  54. //==============================================================================
  55. /** Sets the type of icon that should be used for the dialog box. */
  56. MessageBoxOptions withIconType (MessageBoxIconType type) const { return with (*this, &MessageBoxOptions::iconType, type); }
  57. /** Sets the title of the dialog box. */
  58. MessageBoxOptions withTitle (const String& boxTitle) const { return with (*this, &MessageBoxOptions::title, boxTitle); }
  59. /** Sets the message that should be displayed in the dialog box. */
  60. MessageBoxOptions withMessage (const String& boxMessage) const { return with (*this, &MessageBoxOptions::message, boxMessage); }
  61. /** If the string passed in is not empty, this will add a button to the
  62. dialog box with the specified text.
  63. Generally up to 3 buttons are supported for dialog boxes, so adding any more
  64. than this may have no effect.
  65. */
  66. MessageBoxOptions withButton (const String& text) const { auto copy = *this; copy.buttons.add (text); return copy; }
  67. /** The component that the dialog box should be associated with. */
  68. MessageBoxOptions withAssociatedComponent (Component* component) const { return with (*this, &MessageBoxOptions::associatedComponent, component); }
  69. //==============================================================================
  70. /** Returns the icon type of the dialog box.
  71. @see withIconType
  72. */
  73. MessageBoxIconType getIconType() const noexcept { return iconType; }
  74. /** Returns the title of the dialog box.
  75. @see withTitle
  76. */
  77. String getTitle() const { return title; }
  78. /** Returns the message of the dialog box.
  79. @see withMessage
  80. */
  81. String getMessage() const { return message; }
  82. /** Returns the number of buttons that have been added to the dialog box.
  83. @see withButtonText
  84. */
  85. int getNumButtons() const noexcept { return buttons.size(); }
  86. /** Returns the text that has been set for one of the buttons of the dialog box.
  87. @see withButtonText, getNumButtons
  88. */
  89. String getButtonText (int buttonIndex) const { return buttons[buttonIndex]; }
  90. /** Returns the component that the dialog box is associated with.
  91. @see withAssociatedComponent
  92. */
  93. Component* getAssociatedComponent() const noexcept { return associatedComponent; }
  94. private:
  95. //==============================================================================
  96. template <typename Member, typename Item>
  97. static MessageBoxOptions with (MessageBoxOptions options, Member&& member, Item&& item)
  98. {
  99. options.*member = std::forward<Item> (item);
  100. return options;
  101. }
  102. //==============================================================================
  103. MessageBoxIconType iconType = MessageBoxIconType::InfoIcon;
  104. String title, message;
  105. StringArray buttons;
  106. WeakReference<Component> associatedComponent;
  107. };
  108. } // namespace juce