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.

192 lines
7.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. A PropertyComponent that shows its value as editable text.
  23. @see PropertyComponent
  24. @tags{GUI}
  25. */
  26. class JUCE_API TextPropertyComponent : public PropertyComponent
  27. {
  28. protected:
  29. //==============================================================================
  30. /** Creates a text property component.
  31. @param propertyName The name of the property
  32. @param maxNumChars If not zero, then this specifies the maximum allowable length of
  33. the string. If zero, then the string will have no length limit.
  34. @param isMultiLine Sets whether the text editor allows carriage returns.
  35. @param isEditable Sets whether the text editor is editable. The default is true.
  36. @see TextEditor, setEditable
  37. */
  38. TextPropertyComponent (const String& propertyName,
  39. int maxNumChars,
  40. bool isMultiLine,
  41. bool isEditable = true);
  42. public:
  43. /** Creates a text property component.
  44. @param valueToControl The Value that is controlled by the TextPropertyComponent
  45. @param propertyName The name of the property
  46. @param maxNumChars If not zero, then this specifies the maximum allowable length of
  47. the string. If zero, then the string will have no length limit.
  48. @param isMultiLine Sets whether the text editor allows carriage returns.
  49. @param isEditable Sets whether the text editor is editable. The default is true.
  50. @see TextEditor, setEditable
  51. */
  52. TextPropertyComponent (const Value& valueToControl,
  53. const String& propertyName,
  54. int maxNumChars,
  55. bool isMultiLine,
  56. bool isEditable = true);
  57. /** Creates a text property component with a default value.
  58. @param valueToControl The ValueWithDefault that is controlled by the TextPropertyComponent.
  59. @param propertyName The name of the property
  60. @param maxNumChars If not zero, then this specifies the maximum allowable length of
  61. the string. If zero, then the string will have no length limit.
  62. @param isMultiLine Sets whether the text editor allows carriage returns.
  63. @param isEditable Sets whether the text editor is editable. The default is true.
  64. @see TextEditor, setEditable
  65. */
  66. TextPropertyComponent (ValueWithDefault& valueToControl,
  67. const String& propertyName,
  68. int maxNumChars,
  69. bool isMultiLine,
  70. bool isEditable = true);
  71. /** Destructor. */
  72. ~TextPropertyComponent() override;
  73. //==============================================================================
  74. /** Called when the user edits the text.
  75. Your subclass must use this callback to change the value of whatever item
  76. this property component represents.
  77. */
  78. virtual void setText (const String& newText);
  79. /** Returns the text that should be shown in the text editor. */
  80. virtual String getText() const;
  81. /** Returns the text that should be shown in the text editor as a Value object. */
  82. Value& getValue() const;
  83. //==============================================================================
  84. /** Returns true if the text editor allows carriage returns. */
  85. bool isTextEditorMultiLine() const noexcept { return isMultiLine; }
  86. //==============================================================================
  87. /** A set of colour IDs to use to change the colour of various aspects of the component.
  88. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  89. methods.
  90. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  91. */
  92. enum ColourIds
  93. {
  94. backgroundColourId = 0x100e401, /**< The colour to fill the background of the text area. */
  95. textColourId = 0x100e402, /**< The colour to use for the editable text. */
  96. outlineColourId = 0x100e403, /**< The colour to use to draw an outline around the text area. */
  97. };
  98. void colourChanged() override;
  99. //==============================================================================
  100. /** Used to receive callbacks for text changes */
  101. class JUCE_API Listener
  102. {
  103. public:
  104. /** Destructor. */
  105. virtual ~Listener() = default;
  106. /** Called when text has finished being entered (i.e. not per keypress) has changed. */
  107. virtual void textPropertyComponentChanged (TextPropertyComponent*) = 0;
  108. };
  109. /** Registers a listener to receive events when this button's state changes.
  110. If the listener is already registered, this will not register it again.
  111. @see removeListener
  112. */
  113. void addListener (Listener* newListener);
  114. /** Removes a previously-registered button listener
  115. @see addListener
  116. */
  117. void removeListener (Listener* listener);
  118. //==============================================================================
  119. /** Sets whether the text property component can have files dropped onto it by an external application.
  120. The default setting for this is true but you may want to disable this behaviour if you derive
  121. from this class and want your subclass to respond to the file drag.
  122. */
  123. void setInterestedInFileDrag (bool isInterested);
  124. /** Sets whether the text editor is editable. The default setting for this is true. */
  125. void setEditable (bool isEditable);
  126. //==============================================================================
  127. /** @internal */
  128. void refresh() override;
  129. /** @internal */
  130. virtual void textWasEdited();
  131. private:
  132. class RemapperValueSourceWithDefault;
  133. class LabelComp;
  134. friend class LabelComp;
  135. //==============================================================================
  136. void callListeners();
  137. void createEditor (int maxNumChars, bool isEditable);
  138. //==============================================================================
  139. bool isMultiLine;
  140. std::unique_ptr<LabelComp> textEditor;
  141. ListenerList<Listener> listenerList;
  142. WeakReference<ValueWithDefault> valueWithDefault;
  143. //==============================================================================
  144. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TextPropertyComponent)
  145. };
  146. } // namespace juce