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.

156 lines
5.9KB

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