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.

128 lines
4.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_HYPERLINKBUTTON_JUCEHEADER__
  19. #define __JUCE_HYPERLINKBUTTON_JUCEHEADER__
  20. #include "juce_Button.h"
  21. //==============================================================================
  22. /**
  23. A button showing an underlined weblink, that will launch the link
  24. when it's clicked.
  25. @see Button
  26. */
  27. class JUCE_API HyperlinkButton : public Button
  28. {
  29. public:
  30. //==============================================================================
  31. /** Creates a HyperlinkButton.
  32. @param linkText the text that will be displayed in the button - this is
  33. also set as the Component's name, but the text can be
  34. changed later with the Button::getButtonText() method
  35. @param linkURL the URL to launch when the user clicks the button
  36. */
  37. HyperlinkButton (const String& linkText,
  38. const URL& linkURL);
  39. /** Creates a HyperlinkButton. */
  40. HyperlinkButton();
  41. /** Destructor. */
  42. ~HyperlinkButton();
  43. //==============================================================================
  44. /** Changes the font to use for the text.
  45. If resizeToMatchComponentHeight is true, the font's height will be adjusted
  46. to match the size of the component.
  47. */
  48. void setFont (const Font& newFont,
  49. bool resizeToMatchComponentHeight,
  50. const Justification& justificationType = Justification::horizontallyCentred);
  51. //==============================================================================
  52. /** A set of colour IDs to use to change the colour of various aspects of the link.
  53. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  54. methods.
  55. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  56. */
  57. enum ColourIds
  58. {
  59. textColourId = 0x1001f00, /**< The colour to use for the URL text. */
  60. };
  61. //==============================================================================
  62. /** Changes the URL that the button will trigger. */
  63. void setURL (const URL& newURL) noexcept;
  64. /** Returns the URL that the button will trigger. */
  65. const URL& getURL() const noexcept { return url; }
  66. //==============================================================================
  67. /** Resizes the button horizontally to fit snugly around the text.
  68. This won't affect the button's height.
  69. */
  70. void changeWidthToFitText();
  71. //==============================================================================
  72. struct Ids
  73. {
  74. static const Identifier tagType, text, url;
  75. };
  76. void refreshFromValueTree (const ValueTree&, ComponentBuilder&);
  77. protected:
  78. //==============================================================================
  79. /** @internal */
  80. void clicked();
  81. /** @internal */
  82. void colourChanged();
  83. /** @internal */
  84. void paintButton (Graphics& g,
  85. bool isMouseOverButton,
  86. bool isButtonDown);
  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. #endif // __JUCE_HYPERLINKBUTTON_JUCEHEADER__