Audio plugin host https://kx.studio/carla
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.

149 lines
5.6KB

  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. #ifndef JUCE_TEXTPROPERTYCOMPONENT_H_INCLUDED
  18. #define JUCE_TEXTPROPERTYCOMPONENT_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A PropertyComponent that shows its value as editable text.
  22. @see PropertyComponent
  23. */
  24. class JUCE_API TextPropertyComponent : public PropertyComponent
  25. {
  26. protected:
  27. //==============================================================================
  28. /** Creates a text property component.
  29. @param propertyName The name of the property
  30. @param maxNumChars If not zero, then this specifies the maximum allowable length of
  31. the string. If zero, then the string will have no length limit.
  32. @param isMultiLine isMultiLine sets whether the text editor allows carriage returns.
  33. @see TextEditor
  34. */
  35. TextPropertyComponent (const String& propertyName,
  36. int maxNumChars,
  37. bool isMultiLine);
  38. public:
  39. /** Creates a text property component.
  40. @param valueToControl The Value that is controlled by the TextPropertyCOmponent
  41. @param propertyName The name of the property
  42. @param maxNumChars If not zero, then this specifies the maximum allowable length of
  43. the string. If zero, then the string will have no length limit.
  44. @param isMultiLine isMultiLine sets whether the text editor allows carriage returns.
  45. @see TextEditor
  46. */
  47. TextPropertyComponent (const Value& valueToControl,
  48. const String& propertyName,
  49. int maxNumChars,
  50. bool isMultiLine);
  51. /** Destructor. */
  52. ~TextPropertyComponent();
  53. //==============================================================================
  54. /** Called when the user edits the text.
  55. Your subclass must use this callback to change the value of whatever item
  56. this property component represents.
  57. */
  58. virtual void setText (const String& newText);
  59. /** Returns the text that should be shown in the text editor. */
  60. virtual String getText() const;
  61. /** Returns the text that should be shown in the text editor as a Value object. */
  62. Value& getValue() const;
  63. //==============================================================================
  64. /** A set of colour IDs to use to change the colour of various aspects of the component.
  65. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  66. methods.
  67. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  68. */
  69. enum ColourIds
  70. {
  71. backgroundColourId = 0x100e401, /**< The colour to fill the background of the text area. */
  72. textColourId = 0x100e402, /**< The colour to use for the editable text. */
  73. outlineColourId = 0x100e403, /**< The colour to use to draw an outline around the text area. */
  74. };
  75. void colourChanged() override;
  76. //==============================================================================
  77. class JUCE_API Listener
  78. {
  79. public:
  80. /** Destructor. */
  81. virtual ~Listener() {}
  82. /** Called when text has finished being entered (i.e. not per keypress) has changed. */
  83. virtual void textPropertyComponentChanged (TextPropertyComponent*) = 0;
  84. };
  85. /** Registers a listener to receive events when this button's state changes.
  86. If the listener is already registered, this will not register it again.
  87. @see removeListener
  88. */
  89. void addListener (Listener* newListener);
  90. /** Removes a previously-registered button listener
  91. @see addListener
  92. */
  93. void removeListener (Listener* listener);
  94. //==============================================================================
  95. /** @internal */
  96. void refresh() override;
  97. /** @internal */
  98. virtual void textWasEdited();
  99. private:
  100. class LabelComp;
  101. friend class LabelComp;
  102. ScopedPointer<LabelComp> textEditor;
  103. ListenerList<Listener> listenerList;
  104. void callListeners();
  105. void createEditor (int maxNumChars, bool isMultiLine);
  106. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TextPropertyComponent)
  107. };
  108. #ifndef DOXYGEN
  109. /** This typedef is just for compatibility with old code and VC6 - newer code should use TextPropertyComponent::Listener instead. */
  110. typedef TextPropertyComponent::Listener TextPropertyComponentListener;
  111. #endif
  112. #endif // JUCE_TEXTPROPERTYCOMPONENT_H_INCLUDED