The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

146 lines
5.4KB

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