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.

124 lines
3.8KB

  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 TextPropLabel : public Label
  19. {
  20. public:
  21. TextPropLabel (TextPropertyComponent& owner_,
  22. const int maxChars_, const bool isMultiline_)
  23. : Label (String::empty, String::empty),
  24. owner (owner_),
  25. maxChars (maxChars_),
  26. isMultiline (isMultiline_)
  27. {
  28. setEditable (true, true, false);
  29. setColour (backgroundColourId, findColour (ComboBox::backgroundColourId));
  30. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  31. }
  32. TextEditor* createEditorComponent()
  33. {
  34. TextEditor* const textEditor = Label::createEditorComponent();
  35. textEditor->setInputRestrictions (maxChars);
  36. if (isMultiline)
  37. {
  38. textEditor->setMultiLine (true, true);
  39. textEditor->setReturnKeyStartsNewLine (true);
  40. }
  41. return textEditor;
  42. }
  43. void textWasEdited()
  44. {
  45. owner.textWasEdited();
  46. }
  47. private:
  48. TextPropertyComponent& owner;
  49. int maxChars;
  50. bool isMultiline;
  51. };
  52. //==============================================================================
  53. TextPropertyComponent::TextPropertyComponent (const String& name,
  54. const int maxNumChars,
  55. const bool isMultiLine)
  56. : PropertyComponent (name)
  57. {
  58. createEditor (maxNumChars, isMultiLine);
  59. }
  60. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  61. const String& name,
  62. const int maxNumChars,
  63. const bool isMultiLine)
  64. : PropertyComponent (name)
  65. {
  66. createEditor (maxNumChars, isMultiLine);
  67. textEditor->getTextValue().referTo (valueToControl);
  68. }
  69. TextPropertyComponent::~TextPropertyComponent()
  70. {
  71. }
  72. void TextPropertyComponent::setText (const String& newText)
  73. {
  74. textEditor->setText (newText, true);
  75. }
  76. String TextPropertyComponent::getText() const
  77. {
  78. return textEditor->getText();
  79. }
  80. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  81. {
  82. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  83. if (isMultiLine)
  84. {
  85. textEditor->setJustificationType (Justification::topLeft);
  86. preferredHeight = 120;
  87. }
  88. }
  89. void TextPropertyComponent::refresh()
  90. {
  91. textEditor->setText (getText(), false);
  92. }
  93. void TextPropertyComponent::textWasEdited()
  94. {
  95. const String newText (textEditor->getText());
  96. if (getText() != newText)
  97. setText (newText);
  98. }