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.

113 lines
4.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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_JUCEHEADER__
  18. #define __JUCE_TEXTPROPERTYCOMPONENT_JUCEHEADER__
  19. #include "juce_PropertyComponent.h"
  20. #include "../widgets/juce_Label.h"
  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. The maxNumChars is used to set the length of string allowable, and isMultiLine
  32. sets whether the text editor allows carriage returns.
  33. @see TextEditor
  34. */
  35. TextPropertyComponent (const String& propertyName,
  36. int maxNumChars,
  37. bool isMultiLine);
  38. public:
  39. /** Creates a text property component.
  40. The maxNumChars is used to set the length of string allowable, and isMultiLine
  41. sets whether the text editor allows carriage returns.
  42. @see TextEditor
  43. */
  44. TextPropertyComponent (const Value& valueToControl,
  45. const String& propertyName,
  46. int maxNumChars,
  47. bool isMultiLine);
  48. /** Destructor. */
  49. ~TextPropertyComponent();
  50. //==============================================================================
  51. /** Called when the user edits the text.
  52. Your subclass must use this callback to change the value of whatever item
  53. this property component represents.
  54. */
  55. virtual void setText (const String& newText);
  56. /** Returns the text that should be shown in the text editor. */
  57. virtual String getText() 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. //==============================================================================
  71. /** @internal */
  72. void refresh();
  73. private:
  74. ScopedPointer<Label> textEditor;
  75. class LabelComp;
  76. friend class LabelComp;
  77. void textWasEdited();
  78. void createEditor (int maxNumChars, bool isMultiLine);
  79. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TextPropertyComponent)
  80. };
  81. #endif // __JUCE_TEXTPROPERTYCOMPONENT_JUCEHEADER__