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 5.9KB

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