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.

140 lines
5.0KB

  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. class HyperlinkButtonHandler : public ButtonHandler
  19. {
  20. public:
  21. HyperlinkButtonHandler()
  22. : ButtonHandler ("Hyperlink Button", "HyperlinkButton", typeid (HyperlinkButton), 150, 24)
  23. {
  24. registerColour (HyperlinkButton::textColourId, "text", "textCol");
  25. }
  26. Component* createNewComponent (JucerDocument*)
  27. {
  28. HyperlinkButton* hb = new HyperlinkButton ("new hyperlink", URL ("http://www.rawmaterialsoftware.com/juce"));
  29. setNeedsButtonListener (hb, false);
  30. return hb;
  31. }
  32. void getEditableProperties (Component* component, JucerDocument& document, Array <PropertyComponent*>& properties)
  33. {
  34. HyperlinkButton* const hb = (HyperlinkButton*) component;
  35. ButtonHandler::getEditableProperties (component, document, properties);
  36. properties.add (new HyperlinkURLProperty (hb, document));
  37. addColourProperties (component, document, properties);
  38. }
  39. XmlElement* createXmlFor (Component* comp, const ComponentLayout* layout)
  40. {
  41. HyperlinkButton* const hb = (HyperlinkButton*) comp;
  42. XmlElement* const e = ButtonHandler::createXmlFor (comp, layout);
  43. e->setAttribute ("url", hb->getURL().toString (false));
  44. return e;
  45. }
  46. bool restoreFromXml (const XmlElement& xml, Component* comp, const ComponentLayout* layout)
  47. {
  48. HyperlinkButton* const hb = (HyperlinkButton*) comp;
  49. if (! ButtonHandler::restoreFromXml (xml, comp, layout))
  50. return false;
  51. hb->setURL (URL (xml.getStringAttribute ("url", hb->getURL().toString (false))));
  52. return true;
  53. }
  54. String getCreationParameters (Component* comp)
  55. {
  56. HyperlinkButton* const hb = dynamic_cast <HyperlinkButton*> (comp);
  57. return quotedString (hb->getButtonText())
  58. + ",\nURL ("
  59. + quotedString (hb->getURL().toString (false))
  60. + ")";
  61. }
  62. void fillInCreationCode (GeneratedCode& code, Component* component, const String& memberVariableName)
  63. {
  64. ButtonHandler::fillInCreationCode (code, component, memberVariableName);
  65. code.constructorCode << getColourIntialisationCode (component, memberVariableName)
  66. << '\n';
  67. }
  68. private:
  69. //==============================================================================
  70. class HyperlinkURLProperty : public ComponentTextProperty <HyperlinkButton>
  71. {
  72. public:
  73. HyperlinkURLProperty (HyperlinkButton* comp, JucerDocument& doc)
  74. : ComponentTextProperty <HyperlinkButton> ("URL", 512, false, comp, doc)
  75. {}
  76. void setText (const String& newText)
  77. {
  78. document.perform (new HyperlinkURLChangeAction (component, *document.getComponentLayout(), URL (newText)),
  79. "Change hyperlink URL");
  80. }
  81. String getText() const
  82. {
  83. return component->getURL().toString (false);
  84. }
  85. private:
  86. class HyperlinkURLChangeAction : public ComponentUndoableAction <HyperlinkButton>
  87. {
  88. public:
  89. HyperlinkURLChangeAction (HyperlinkButton* const comp, ComponentLayout& layout, const URL& newState_)
  90. : ComponentUndoableAction <HyperlinkButton> (comp, layout),
  91. newState (newState_)
  92. {
  93. oldState = comp->getURL();
  94. }
  95. bool perform()
  96. {
  97. showCorrectTab();
  98. getComponent()->setURL (newState);
  99. changed();
  100. return true;
  101. }
  102. bool undo()
  103. {
  104. showCorrectTab();
  105. getComponent()->setURL (oldState);
  106. changed();
  107. return true;
  108. }
  109. URL newState, oldState;
  110. };
  111. };
  112. };