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.

juce_TextPropertyComponent.h 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - 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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-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 ValueTreePropertyWithDefault 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 (const ValueTreePropertyWithDefault& valueToControl,
  67. const String& propertyName,
  68. int maxNumChars,
  69. bool isMultiLine,
  70. bool isEditable = true);
  71. ~TextPropertyComponent() override;
  72. //==============================================================================
  73. /** Called when the user edits the text.
  74. Your subclass must use this callback to change the value of whatever item
  75. this property component represents.
  76. */
  77. virtual void setText (const String& newText);
  78. /** Returns the text that should be shown in the text editor. */
  79. virtual String getText() const;
  80. /** Returns the text that should be shown in the text editor as a Value object. */
  81. Value& getValue() const;
  82. //==============================================================================
  83. /** Returns true if the text editor allows carriage returns. */
  84. bool isTextEditorMultiLine() const noexcept { return isMultiLine; }
  85. //==============================================================================
  86. /** A set of colour IDs to use to change the colour of various aspects of the component.
  87. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  88. methods.
  89. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  90. */
  91. enum ColourIds
  92. {
  93. backgroundColourId = 0x100e401, /**< The colour to fill the background of the text area. */
  94. textColourId = 0x100e402, /**< The colour to use for the editable text. */
  95. outlineColourId = 0x100e403, /**< The colour to use to draw an outline around the text area. */
  96. };
  97. void colourChanged() override;
  98. //==============================================================================
  99. /** Used to receive callbacks for text changes */
  100. class JUCE_API Listener
  101. {
  102. public:
  103. /** Destructor. */
  104. virtual ~Listener() = default;
  105. /** Called when text has finished being entered (i.e. not per keypress) has changed. */
  106. virtual void textPropertyComponentChanged (TextPropertyComponent*) = 0;
  107. };
  108. /** Registers a listener to receive events when this button's state changes.
  109. If the listener is already registered, this will not register it again.
  110. @see removeListener
  111. */
  112. void addListener (Listener* newListener);
  113. /** Removes a previously-registered button listener
  114. @see addListener
  115. */
  116. void removeListener (Listener* listener);
  117. //==============================================================================
  118. /** Sets whether the text property component can have files dropped onto it by an external application.
  119. The default setting for this is true but you may want to disable this behaviour if you derive
  120. from this class and want your subclass to respond to the file drag.
  121. */
  122. void setInterestedInFileDrag (bool isInterested);
  123. /** Sets whether the text editor is editable. The default setting for this is true. */
  124. void setEditable (bool isEditable);
  125. //==============================================================================
  126. /** @internal */
  127. void refresh() override;
  128. /** @internal */
  129. virtual void textWasEdited();
  130. private:
  131. //==============================================================================
  132. void callListeners();
  133. void createEditor (int maxNumChars, bool isEditable);
  134. //==============================================================================
  135. class LabelComp;
  136. const bool isMultiLine;
  137. ValueTreePropertyWithDefault value;
  138. std::unique_ptr<LabelComp> textEditor;
  139. ListenerList<Listener> listenerList;
  140. //==============================================================================
  141. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TextPropertyComponent)
  142. };
  143. } // namespace juce