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.

112 lines
4.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. //==============================================================================
  19. /**
  20. A button showing an underlined weblink, that will launch the link
  21. when it's clicked.
  22. @see Button
  23. */
  24. class JUCE_API HyperlinkButton : public Button
  25. {
  26. public:
  27. //==============================================================================
  28. /** Creates a HyperlinkButton.
  29. @param linkText the text that will be displayed in the button - this is
  30. also set as the Component's name, but the text can be
  31. changed later with the Button::getButtonText() method
  32. @param linkURL the URL to launch when the user clicks the button
  33. */
  34. HyperlinkButton (const String& linkText,
  35. const URL& linkURL);
  36. /** Creates a HyperlinkButton. */
  37. HyperlinkButton();
  38. /** Destructor. */
  39. ~HyperlinkButton();
  40. //==============================================================================
  41. /** Changes the font to use for the text.
  42. If resizeToMatchComponentHeight is true, the font's height will be adjusted
  43. to match the size of the component.
  44. */
  45. void setFont (const Font& newFont,
  46. bool resizeToMatchComponentHeight,
  47. Justification justificationType = Justification::horizontallyCentred);
  48. //==============================================================================
  49. /** A set of colour IDs to use to change the colour of various aspects of the link.
  50. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  51. methods.
  52. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  53. */
  54. enum ColourIds
  55. {
  56. textColourId = 0x1001f00, /**< The colour to use for the URL text. */
  57. };
  58. //==============================================================================
  59. /** Changes the URL that the button will trigger. */
  60. void setURL (const URL& newURL) noexcept;
  61. /** Returns the URL that the button will trigger. */
  62. const URL& getURL() const noexcept { return url; }
  63. //==============================================================================
  64. /** Resizes the button horizontally to fit snugly around the text.
  65. This won't affect the button's height.
  66. */
  67. void changeWidthToFitText();
  68. protected:
  69. //==============================================================================
  70. /** @internal */
  71. void clicked() override;
  72. /** @internal */
  73. void colourChanged() override;
  74. /** @internal */
  75. void paintButton (Graphics&, bool isMouseOver, bool isButtonDown) override;
  76. private:
  77. //==============================================================================
  78. URL url;
  79. Font font;
  80. bool resizeFont;
  81. Justification justification;
  82. Font getFontToUse() const;
  83. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (HyperlinkButton)
  84. };