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.

127 lines
4.5KB

  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. A button showing an underlined weblink, that will launch the link
  24. when it's clicked.
  25. @see Button
  26. @tags{GUI}
  27. */
  28. class JUCE_API HyperlinkButton : public Button
  29. {
  30. public:
  31. //==============================================================================
  32. /** Creates a HyperlinkButton.
  33. @param linkText the text that will be displayed in the button - this is
  34. also set as the Component's name, but the text can be
  35. changed later with the Button::getButtonText() method
  36. @param linkURL the URL to launch when the user clicks the button
  37. */
  38. HyperlinkButton (const String& linkText,
  39. const URL& linkURL);
  40. /** Creates a HyperlinkButton. */
  41. HyperlinkButton();
  42. /** Destructor. */
  43. ~HyperlinkButton();
  44. //==============================================================================
  45. /** Changes the font to use for the text.
  46. If resizeToMatchComponentHeight is true, the font's height will be adjusted
  47. to match the size of the component.
  48. */
  49. void setFont (const Font& newFont,
  50. bool resizeToMatchComponentHeight,
  51. Justification justificationType = Justification::horizontallyCentred);
  52. //==============================================================================
  53. /** A set of colour IDs to use to change the colour of various aspects of the link.
  54. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  55. methods.
  56. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  57. */
  58. enum ColourIds
  59. {
  60. textColourId = 0x1001f00, /**< The colour to use for the URL text. */
  61. };
  62. //==============================================================================
  63. /** Changes the URL that the button will trigger. */
  64. void setURL (const URL& newURL) noexcept;
  65. /** Returns the URL that the button will trigger. */
  66. const URL& getURL() const noexcept { return url; }
  67. //==============================================================================
  68. /** Resizes the button horizontally to fit snugly around the text.
  69. This won't affect the button's height.
  70. */
  71. void changeWidthToFitText();
  72. //==============================================================================
  73. /** Sets the style of justification to be used for positioning the text.
  74. (The default is Justification::centred)
  75. */
  76. void setJustificationType (Justification justification);
  77. /** Returns the type of justification, as set in setJustificationType(). */
  78. Justification getJustificationType() const noexcept { return justification; }
  79. protected:
  80. //==============================================================================
  81. /** @internal */
  82. void clicked() override;
  83. /** @internal */
  84. void colourChanged() override;
  85. /** @internal */
  86. void paintButton (Graphics&, bool isMouseOver, bool isButtonDown) override;
  87. private:
  88. //==============================================================================
  89. URL url;
  90. Font font;
  91. bool resizeFont;
  92. Justification justification;
  93. Font getFontToUse() const;
  94. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (HyperlinkButton)
  95. };
  96. } // namespace juce