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.1KB

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