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.

119 lines
4.2KB

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